]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.5-201301311811.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.5-201301311811.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 ecf87b1..f0c8483 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/map.h b/arch/arm/include/asm/mach/map.h
1541 index 195ac2f..2272f0d 100644
1542 --- a/arch/arm/include/asm/mach/map.h
1543 +++ b/arch/arm/include/asm/mach/map.h
1544 @@ -34,6 +34,9 @@ struct map_desc {
1545 #define MT_MEMORY_ITCM 13
1546 #define MT_MEMORY_SO 14
1547 #define MT_MEMORY_DMA_READY 15
1548 +#define MT_MEMORY_R 16
1549 +#define MT_MEMORY_RW 17
1550 +#define MT_MEMORY_RX 18
1551
1552 #ifdef CONFIG_MMU
1553 extern void iotable_init(struct map_desc *, int);
1554 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1555 index 53426c6..c7baff3 100644
1556 --- a/arch/arm/include/asm/outercache.h
1557 +++ b/arch/arm/include/asm/outercache.h
1558 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1559 #endif
1560 void (*set_debug)(unsigned long);
1561 void (*resume)(void);
1562 -};
1563 +} __no_const;
1564
1565 #ifdef CONFIG_OUTER_CACHE
1566
1567 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1568 index 812a494..71fc0b6 100644
1569 --- a/arch/arm/include/asm/page.h
1570 +++ b/arch/arm/include/asm/page.h
1571 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1572 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1573 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1574 unsigned long vaddr, struct vm_area_struct *vma);
1575 -};
1576 +} __no_const;
1577
1578 #ifdef MULTI_USER
1579 extern struct cpu_user_fns cpu_user;
1580 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1581 index 943504f..1ad2de8 100644
1582 --- a/arch/arm/include/asm/pgalloc.h
1583 +++ b/arch/arm/include/asm/pgalloc.h
1584 @@ -22,7 +22,7 @@
1585
1586 #ifdef CONFIG_MMU
1587
1588 -#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1589 +#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_PXNTABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1590 #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
1591
1592 #ifdef CONFIG_ARM_LPAE
1593 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1594 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1595 }
1596
1597 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1598 +{
1599 + pud_populate(mm, pud, pmd);
1600 +}
1601 +
1602 #else /* !CONFIG_ARM_LPAE */
1603
1604 /*
1605 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1607 #define pmd_free(mm, pmd) do { } while (0)
1608 #define pud_populate(mm,pmd,pte) BUG()
1609 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1610
1611 #endif /* CONFIG_ARM_LPAE */
1612
1613 @@ -126,6 +132,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1614 __free_page(pte);
1615 }
1616
1617 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1618 +{
1619 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1620 + pmdp[0] = __pmd(pmdval);
1621 +#ifndef CONFIG_ARM_LPAE
1622 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1623 +#endif
1624 + flush_pmd_entry(pmdp);
1625 +}
1626 +
1627 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1628 pmdval_t prot)
1629 {
1630 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1631 index 5cfba15..d437dc2 100644
1632 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1633 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1634 @@ -20,12 +20,15 @@
1635 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1636 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1637 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1638 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1639 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1640 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1641 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1642 +
1643 /*
1644 * - section
1645 */
1646 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1647 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1648 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1649 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1650 @@ -37,6 +40,7 @@
1651 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1652 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1653 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1654 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1655
1656 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1657 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1658 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1659 index d795282..d82ff13 100644
1660 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1661 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1662 @@ -32,6 +32,7 @@
1663 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1664 #define PMD_BIT4 (_AT(pmdval_t, 0))
1665 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1666 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1667
1668 /*
1669 * - section
1670 @@ -41,9 +42,11 @@
1671 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1672 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1673 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1674 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1675 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1676 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1677 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1678 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1679 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1680
1681 /*
1682 @@ -66,6 +69,7 @@
1683 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1684 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1685 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1686 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1687 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1688
1689 /*
1690 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1691 index b249035..4ab204b 100644
1692 --- a/arch/arm/include/asm/pgtable-3level.h
1693 +++ b/arch/arm/include/asm/pgtable-3level.h
1694 @@ -73,6 +73,7 @@
1695 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1696 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1697 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1698 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1699 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1700 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1701 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1702 @@ -80,6 +81,7 @@
1703 /*
1704 * To be used in assembly code with the upper page attributes.
1705 */
1706 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1707 #define L_PTE_XN_HIGH (1 << (54 - 32))
1708 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1709
1710 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1711 index 08c1231..6a2d6b0 100644
1712 --- a/arch/arm/include/asm/pgtable.h
1713 +++ b/arch/arm/include/asm/pgtable.h
1714 @@ -30,6 +30,9 @@
1715 #include <asm/pgtable-2level.h>
1716 #endif
1717
1718 +#define ktla_ktva(addr) (addr)
1719 +#define ktva_ktla(addr) (addr)
1720 +
1721 /*
1722 * Just any arbitrary offset to the start of the vmalloc VM area: the
1723 * current 8MB value just means that there will be a 8MB "hole" after the
1724 @@ -53,6 +56,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1725 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1726 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1727
1728 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1729 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1730 +
1731 +#ifdef CONFIG_PAX_KERNEXEC
1732 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1733 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1734 +#else
1735 +static inline unsigned long pax_open_kernel(void) { return 0; }
1736 +static inline unsigned long pax_close_kernel(void) { return 0; }
1737 +#endif
1738 +
1739 /*
1740 * This is the lowest virtual address we can permit any user space
1741 * mapping to be mapped at. This is particularly important for
1742 @@ -73,23 +87,23 @@ extern pgprot_t pgprot_kernel;
1743
1744 #define _MOD_PROT(p, b) __pgprot(pgprot_val(p) | (b))
1745
1746 -#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_RDONLY)
1747 -#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN)
1748 -#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER)
1749 -#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1750 -#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1751 -#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1752 -#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1753 +#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY)
1754 +#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1755 +#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_PXN)
1756 +#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1757 +#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1758 +#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1759 +#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1760 #define PAGE_KERNEL _MOD_PROT(pgprot_kernel, L_PTE_XN)
1761 #define PAGE_KERNEL_EXEC pgprot_kernel
1762
1763 -#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN)
1764 -#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN)
1765 -#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER)
1766 -#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1767 -#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1768 -#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1769 -#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1770 +#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1771 +#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1772 +#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_PXN)
1773 +#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1774 +#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1775 +#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1776 +#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1777
1778 #define __pgprot_modify(prot,mask,bits) \
1779 __pgprot((pgprot_val(prot) & ~(mask)) | (bits))
1780 @@ -242,7 +256,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1781
1782 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1783 {
1784 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1785 + const pteval_t mask = L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY | L_PTE_USER;
1786 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1787 return pte;
1788 }
1789 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1790 index f3628fb..a0672dd 100644
1791 --- a/arch/arm/include/asm/proc-fns.h
1792 +++ b/arch/arm/include/asm/proc-fns.h
1793 @@ -75,7 +75,7 @@ extern struct processor {
1794 unsigned int suspend_size;
1795 void (*do_suspend)(void *);
1796 void (*do_resume)(void *);
1797 -} processor;
1798 +} __do_const processor;
1799
1800 #ifndef MULTI_CPU
1801 extern void cpu_proc_init(void);
1802 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1803 index 2e3be16..4dc90fc 100644
1804 --- a/arch/arm/include/asm/smp.h
1805 +++ b/arch/arm/include/asm/smp.h
1806 @@ -106,7 +106,7 @@ struct smp_operations {
1807 int (*cpu_disable)(unsigned int cpu);
1808 #endif
1809 #endif
1810 -};
1811 +} __no_const;
1812
1813 /*
1814 * set platform specific SMP operations
1815 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1816 index 8477b4c..801a6a9 100644
1817 --- a/arch/arm/include/asm/thread_info.h
1818 +++ b/arch/arm/include/asm/thread_info.h
1819 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1820 #define TIF_SYSCALL_TRACE 8
1821 #define TIF_SYSCALL_AUDIT 9
1822 #define TIF_SYSCALL_TRACEPOINT 10
1823 +
1824 +/* within 8 bits of TIF_SYSCALL_TRACE
1825 + to meet flexible second operand requirements
1826 +*/
1827 +#define TIF_GRSEC_SETXID 11
1828 +
1829 #define TIF_USING_IWMMXT 17
1830 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1831 #define TIF_RESTORE_SIGMASK 20
1832 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1833 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1834 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1835 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1836 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1837
1838 /* Checks for any syscall work in entry-common.S */
1839 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1840 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1841 + _TIF_GRSEC_SETXID)
1842
1843 /*
1844 * Change these and you break ASM code in entry-common.S
1845 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1846 index 7e1f760..1af891c 100644
1847 --- a/arch/arm/include/asm/uaccess.h
1848 +++ b/arch/arm/include/asm/uaccess.h
1849 @@ -22,6 +22,8 @@
1850 #define VERIFY_READ 0
1851 #define VERIFY_WRITE 1
1852
1853 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1854 +
1855 /*
1856 * The exception table consists of pairs of addresses: the first is the
1857 * address of an instruction that is allowed to fault, and the second is
1858 @@ -418,8 +420,23 @@ do { \
1859
1860
1861 #ifdef CONFIG_MMU
1862 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1863 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1864 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1865 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1866 +
1867 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1868 +{
1869 + if (!__builtin_constant_p(n))
1870 + check_object_size(to, n, false);
1871 + return ___copy_from_user(to, from, n);
1872 +}
1873 +
1874 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1875 +{
1876 + if (!__builtin_constant_p(n))
1877 + check_object_size(from, n, true);
1878 + return ___copy_to_user(to, from, n);
1879 +}
1880 +
1881 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1882 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1883 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1884 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1885
1886 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1887 {
1888 + if ((long)n < 0)
1889 + return n;
1890 +
1891 if (access_ok(VERIFY_READ, from, n))
1892 n = __copy_from_user(to, from, n);
1893 else /* security hole - plug it */
1894 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1895
1896 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1897 {
1898 + if ((long)n < 0)
1899 + return n;
1900 +
1901 if (access_ok(VERIFY_WRITE, to, n))
1902 n = __copy_to_user(to, from, n);
1903 return n;
1904 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1905 index 96ee092..37f1844 100644
1906 --- a/arch/arm/include/uapi/asm/ptrace.h
1907 +++ b/arch/arm/include/uapi/asm/ptrace.h
1908 @@ -73,7 +73,7 @@
1909 * ARMv7 groups of PSR bits
1910 */
1911 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1912 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1913 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1914 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1915 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1916
1917 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1918 index 60d3b73..9168db0 100644
1919 --- a/arch/arm/kernel/armksyms.c
1920 +++ b/arch/arm/kernel/armksyms.c
1921 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1922 #ifdef CONFIG_MMU
1923 EXPORT_SYMBOL(copy_page);
1924
1925 -EXPORT_SYMBOL(__copy_from_user);
1926 -EXPORT_SYMBOL(__copy_to_user);
1927 +EXPORT_SYMBOL(___copy_from_user);
1928 +EXPORT_SYMBOL(___copy_to_user);
1929 EXPORT_SYMBOL(__clear_user);
1930
1931 EXPORT_SYMBOL(__get_user_1);
1932 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1933 index 4eee351..e247728 100644
1934 --- a/arch/arm/kernel/head.S
1935 +++ b/arch/arm/kernel/head.S
1936 @@ -52,7 +52,9 @@
1937 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1938
1939 .macro pgtbl, rd, phys
1940 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1941 + mov \rd, #TEXT_OFFSET
1942 + sub \rd, #PG_DIR_SIZE
1943 + add \rd, \rd, \phys
1944 .endm
1945
1946 /*
1947 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1948 index 1e9be5d..b9a75e1 100644
1949 --- a/arch/arm/kernel/module.c
1950 +++ b/arch/arm/kernel/module.c
1951 @@ -37,12 +37,35 @@
1952 #endif
1953
1954 #ifdef CONFIG_MMU
1955 -void *module_alloc(unsigned long size)
1956 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1957 {
1958 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1959 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1960 + GFP_KERNEL, prot, -1,
1961 __builtin_return_address(0));
1962 }
1963 +
1964 +void *module_alloc(unsigned long size)
1965 +{
1966 +
1967 +#ifdef CONFIG_PAX_KERNEXEC
1968 + return __module_alloc(size, PAGE_KERNEL);
1969 +#else
1970 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1971 +#endif
1972 +
1973 +}
1974 +
1975 +#ifdef CONFIG_PAX_KERNEXEC
1976 +void module_free_exec(struct module *mod, void *module_region)
1977 +{
1978 + module_free(mod, module_region);
1979 +}
1980 +
1981 +void *module_alloc_exec(unsigned long size)
1982 +{
1983 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1984 +}
1985 +#endif
1986 #endif
1987
1988 int
1989 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1990 index 90084a6..bf4bcfb 100644
1991 --- a/arch/arm/kernel/process.c
1992 +++ b/arch/arm/kernel/process.c
1993 @@ -28,7 +28,6 @@
1994 #include <linux/tick.h>
1995 #include <linux/utsname.h>
1996 #include <linux/uaccess.h>
1997 -#include <linux/random.h>
1998 #include <linux/hw_breakpoint.h>
1999 #include <linux/cpuidle.h>
2000 #include <linux/leds.h>
2001 @@ -256,9 +255,10 @@ void machine_power_off(void)
2002 machine_shutdown();
2003 if (pm_power_off)
2004 pm_power_off();
2005 + BUG();
2006 }
2007
2008 -void machine_restart(char *cmd)
2009 +__noreturn void machine_restart(char *cmd)
2010 {
2011 machine_shutdown();
2012
2013 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2014 return 0;
2015 }
2016
2017 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2018 -{
2019 - unsigned long range_end = mm->brk + 0x02000000;
2020 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2021 -}
2022 -
2023 #ifdef CONFIG_MMU
2024 /*
2025 * The vectors page is always readable from user space for the
2026 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2027 index 739db3a..7f4a272 100644
2028 --- a/arch/arm/kernel/ptrace.c
2029 +++ b/arch/arm/kernel/ptrace.c
2030 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2031 PTRACE_SYSCALL_EXIT,
2032 };
2033
2034 +#ifdef CONFIG_GRKERNSEC_SETXID
2035 +extern void gr_delayed_cred_worker(void);
2036 +#endif
2037 +
2038 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2039 enum ptrace_syscall_dir dir)
2040 {
2041 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2042
2043 current_thread_info()->syscall = scno;
2044
2045 +#ifdef CONFIG_GRKERNSEC_SETXID
2046 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2047 + gr_delayed_cred_worker();
2048 +#endif
2049 +
2050 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2051 return scno;
2052
2053 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2054 index da1d1aa..5aaf182 100644
2055 --- a/arch/arm/kernel/setup.c
2056 +++ b/arch/arm/kernel/setup.c
2057 @@ -99,19 +99,19 @@ EXPORT_SYMBOL(elf_hwcap);
2058
2059
2060 #ifdef MULTI_CPU
2061 -struct processor processor __read_mostly;
2062 +struct processor processor;
2063 #endif
2064 #ifdef MULTI_TLB
2065 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2066 +struct cpu_tlb_fns cpu_tlb __read_only;
2067 #endif
2068 #ifdef MULTI_USER
2069 -struct cpu_user_fns cpu_user __read_mostly;
2070 +struct cpu_user_fns cpu_user __read_only;
2071 #endif
2072 #ifdef MULTI_CACHE
2073 -struct cpu_cache_fns cpu_cache __read_mostly;
2074 +struct cpu_cache_fns cpu_cache __read_only;
2075 #endif
2076 #ifdef CONFIG_OUTER_CACHE
2077 -struct outer_cache_fns outer_cache __read_mostly;
2078 +struct outer_cache_fns outer_cache __read_only;
2079 EXPORT_SYMBOL(outer_cache);
2080 #endif
2081
2082 @@ -455,7 +455,7 @@ static void __init setup_processor(void)
2083 __cpu_architecture = __get_cpu_architecture();
2084
2085 #ifdef MULTI_CPU
2086 - processor = *list->proc;
2087 + memcpy((void *)&processor, list->proc, sizeof processor);
2088 #endif
2089 #ifdef MULTI_TLB
2090 cpu_tlb = *list->tlb;
2091 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2092 index fbc8b26..000ded0 100644
2093 --- a/arch/arm/kernel/smp.c
2094 +++ b/arch/arm/kernel/smp.c
2095 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2096
2097 static DECLARE_COMPLETION(cpu_running);
2098
2099 -static struct smp_operations smp_ops;
2100 +static struct smp_operations smp_ops __read_only;
2101
2102 void __init smp_set_ops(struct smp_operations *ops)
2103 {
2104 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2105 index b0179b8..b54c6c1 100644
2106 --- a/arch/arm/kernel/traps.c
2107 +++ b/arch/arm/kernel/traps.c
2108 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2109 static int die_owner = -1;
2110 static unsigned int die_nest_count;
2111
2112 +extern void gr_handle_kernel_exploit(void);
2113 +
2114 static unsigned long oops_begin(void)
2115 {
2116 int cpu;
2117 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2118 panic("Fatal exception in interrupt");
2119 if (panic_on_oops)
2120 panic("Fatal exception");
2121 +
2122 + gr_handle_kernel_exploit();
2123 +
2124 if (signr)
2125 do_exit(signr);
2126 }
2127 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2128 index 36ff15b..75d9e9d 100644
2129 --- a/arch/arm/kernel/vmlinux.lds.S
2130 +++ b/arch/arm/kernel/vmlinux.lds.S
2131 @@ -8,7 +8,11 @@
2132 #include <asm/thread_info.h>
2133 #include <asm/memory.h>
2134 #include <asm/page.h>
2135 -
2136 +
2137 +#ifdef CONFIG_PAX_KERNEXEC
2138 +#include <asm/pgtable.h>
2139 +#endif
2140 +
2141 #define PROC_INFO \
2142 . = ALIGN(4); \
2143 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2144 @@ -90,6 +94,11 @@ SECTIONS
2145 _text = .;
2146 HEAD_TEXT
2147 }
2148 +
2149 +#ifdef CONFIG_PAX_KERNEXEC
2150 + . = ALIGN(1<<SECTION_SHIFT);
2151 +#endif
2152 +
2153 .text : { /* Real text segment */
2154 _stext = .; /* Text and read-only data */
2155 __exception_text_start = .;
2156 @@ -133,6 +142,10 @@ SECTIONS
2157
2158 _etext = .; /* End of text and rodata section */
2159
2160 +#ifdef CONFIG_PAX_KERNEXEC
2161 + . = ALIGN(1<<SECTION_SHIFT);
2162 +#endif
2163 +
2164 #ifndef CONFIG_XIP_KERNEL
2165 . = ALIGN(PAGE_SIZE);
2166 __init_begin = .;
2167 @@ -192,6 +205,11 @@ SECTIONS
2168 . = PAGE_OFFSET + TEXT_OFFSET;
2169 #else
2170 __init_end = .;
2171 +
2172 +#ifdef CONFIG_PAX_KERNEXEC
2173 + . = ALIGN(1<<SECTION_SHIFT);
2174 +#endif
2175 +
2176 . = ALIGN(THREAD_SIZE);
2177 __data_loc = .;
2178 #endif
2179 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2180 index 66a477a..bee61d3 100644
2181 --- a/arch/arm/lib/copy_from_user.S
2182 +++ b/arch/arm/lib/copy_from_user.S
2183 @@ -16,7 +16,7 @@
2184 /*
2185 * Prototype:
2186 *
2187 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2188 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2189 *
2190 * Purpose:
2191 *
2192 @@ -84,11 +84,11 @@
2193
2194 .text
2195
2196 -ENTRY(__copy_from_user)
2197 +ENTRY(___copy_from_user)
2198
2199 #include "copy_template.S"
2200
2201 -ENDPROC(__copy_from_user)
2202 +ENDPROC(___copy_from_user)
2203
2204 .pushsection .fixup,"ax"
2205 .align 0
2206 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2207 index 6ee2f67..d1cce76 100644
2208 --- a/arch/arm/lib/copy_page.S
2209 +++ b/arch/arm/lib/copy_page.S
2210 @@ -10,6 +10,7 @@
2211 * ASM optimised string functions
2212 */
2213 #include <linux/linkage.h>
2214 +#include <linux/const.h>
2215 #include <asm/assembler.h>
2216 #include <asm/asm-offsets.h>
2217 #include <asm/cache.h>
2218 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2219 index d066df6..df28194 100644
2220 --- a/arch/arm/lib/copy_to_user.S
2221 +++ b/arch/arm/lib/copy_to_user.S
2222 @@ -16,7 +16,7 @@
2223 /*
2224 * Prototype:
2225 *
2226 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2227 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2228 *
2229 * Purpose:
2230 *
2231 @@ -88,11 +88,11 @@
2232 .text
2233
2234 ENTRY(__copy_to_user_std)
2235 -WEAK(__copy_to_user)
2236 +WEAK(___copy_to_user)
2237
2238 #include "copy_template.S"
2239
2240 -ENDPROC(__copy_to_user)
2241 +ENDPROC(___copy_to_user)
2242 ENDPROC(__copy_to_user_std)
2243
2244 .pushsection .fixup,"ax"
2245 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2246 index 0dc5385..45833ef 100644
2247 --- a/arch/arm/lib/delay.c
2248 +++ b/arch/arm/lib/delay.c
2249 @@ -28,12 +28,14 @@
2250 /*
2251 * Default to the loop-based delay implementation.
2252 */
2253 -struct arm_delay_ops arm_delay_ops = {
2254 +static struct arm_delay_ops arm_loop_delay_ops = {
2255 .delay = __loop_delay,
2256 .const_udelay = __loop_const_udelay,
2257 .udelay = __loop_udelay,
2258 };
2259
2260 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2261 +
2262 static const struct delay_timer *delay_timer;
2263 static bool delay_calibrated;
2264
2265 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2266 __timer_const_udelay(usecs * UDELAY_MULT);
2267 }
2268
2269 +static struct arm_delay_ops arm_timer_delay_ops = {
2270 + .delay = __timer_delay,
2271 + .const_udelay = __timer_const_udelay,
2272 + .udelay = __timer_udelay,
2273 +};
2274 +
2275 void __init register_current_timer_delay(const struct delay_timer *timer)
2276 {
2277 if (!delay_calibrated) {
2278 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2279 delay_timer = timer;
2280 lpj_fine = timer->freq / HZ;
2281 loops_per_jiffy = lpj_fine;
2282 - arm_delay_ops.delay = __timer_delay;
2283 - arm_delay_ops.const_udelay = __timer_const_udelay;
2284 - arm_delay_ops.udelay = __timer_udelay;
2285 + arm_delay_ops = &arm_timer_delay_ops;
2286 delay_calibrated = true;
2287 } else {
2288 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2289 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2290 index 025f742..8432b08 100644
2291 --- a/arch/arm/lib/uaccess_with_memcpy.c
2292 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2293 @@ -104,7 +104,7 @@ out:
2294 }
2295
2296 unsigned long
2297 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2298 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2299 {
2300 /*
2301 * This test is stubbed out of the main function above to keep
2302 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2303 index 2c6c218..2b87c2d 100644
2304 --- a/arch/arm/mach-kirkwood/common.c
2305 +++ b/arch/arm/mach-kirkwood/common.c
2306 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2307 clk_gate_ops.disable(hw);
2308 }
2309
2310 -static struct clk_ops clk_gate_fn_ops;
2311 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2312 +{
2313 + return clk_gate_ops.is_enabled(hw);
2314 +}
2315 +
2316 +static struct clk_ops clk_gate_fn_ops = {
2317 + .enable = clk_gate_fn_enable,
2318 + .disable = clk_gate_fn_disable,
2319 + .is_enabled = clk_gate_fn_is_enabled,
2320 +};
2321
2322 static struct clk __init *clk_register_gate_fn(struct device *dev,
2323 const char *name,
2324 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2325 gate_fn->fn_en = fn_en;
2326 gate_fn->fn_dis = fn_dis;
2327
2328 - /* ops is the gate ops, but with our enable/disable functions */
2329 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2330 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2331 - clk_gate_fn_ops = clk_gate_ops;
2332 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2333 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2334 - }
2335 -
2336 clk = clk_register(dev, &gate_fn->gate.hw);
2337
2338 if (IS_ERR(clk))
2339 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2340 index d95f727..12f10dd 100644
2341 --- a/arch/arm/mach-omap2/board-n8x0.c
2342 +++ b/arch/arm/mach-omap2/board-n8x0.c
2343 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2344 }
2345 #endif
2346
2347 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2348 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2349 .late_init = n8x0_menelaus_late_init,
2350 };
2351
2352 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2353 index 87cc6d0..fd4f248 100644
2354 --- a/arch/arm/mach-omap2/omap_hwmod.c
2355 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2356 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2357 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2358 struct omap_hwmod_rst_info *ohri);
2359 int (*init_clkdm)(struct omap_hwmod *oh);
2360 -};
2361 +} __no_const;
2362
2363 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2364 -static struct omap_hwmod_soc_ops soc_ops;
2365 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2366
2367 /* omap_hwmod_list contains all registered struct omap_hwmods */
2368 static LIST_HEAD(omap_hwmod_list);
2369 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2370 index 5dbf13f..9be36fd 100644
2371 --- a/arch/arm/mm/fault.c
2372 +++ b/arch/arm/mm/fault.c
2373 @@ -25,6 +25,7 @@
2374 #include <asm/system_misc.h>
2375 #include <asm/system_info.h>
2376 #include <asm/tlbflush.h>
2377 +#include <asm/sections.h>
2378
2379 #include "fault.h"
2380
2381 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2382 if (fixup_exception(regs))
2383 return;
2384
2385 +#ifdef CONFIG_PAX_KERNEXEC
2386 + if (fsr & FSR_WRITE) {
2387 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2388 + if (current->signal->curr_ip)
2389 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2390 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2391 + else
2392 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2393 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2394 + }
2395 + }
2396 +#endif
2397 +
2398 /*
2399 * No handler, we'll have to terminate things with extreme prejudice.
2400 */
2401 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2402 }
2403 #endif
2404
2405 +#ifdef CONFIG_PAX_PAGEEXEC
2406 + if (fsr & FSR_LNX_PF) {
2407 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2408 + do_group_exit(SIGKILL);
2409 + }
2410 +#endif
2411 +
2412 tsk->thread.address = addr;
2413 tsk->thread.error_code = fsr;
2414 tsk->thread.trap_no = 14;
2415 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2416 }
2417 #endif /* CONFIG_MMU */
2418
2419 +#ifdef CONFIG_PAX_PAGEEXEC
2420 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2421 +{
2422 + long i;
2423 +
2424 + printk(KERN_ERR "PAX: bytes at PC: ");
2425 + for (i = 0; i < 20; i++) {
2426 + unsigned char c;
2427 + if (get_user(c, (__force unsigned char __user *)pc+i))
2428 + printk(KERN_CONT "?? ");
2429 + else
2430 + printk(KERN_CONT "%02x ", c);
2431 + }
2432 + printk("\n");
2433 +
2434 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2435 + for (i = -1; i < 20; i++) {
2436 + unsigned long c;
2437 + if (get_user(c, (__force unsigned long __user *)sp+i))
2438 + printk(KERN_CONT "???????? ");
2439 + else
2440 + printk(KERN_CONT "%08lx ", c);
2441 + }
2442 + printk("\n");
2443 +}
2444 +#endif
2445 +
2446 /*
2447 * First Level Translation Fault Handler
2448 *
2449 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2450 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2451 struct siginfo info;
2452
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2455 + if (current->signal->curr_ip)
2456 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2457 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2458 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2459 + else
2460 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2461 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2462 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2463 + goto die;
2464 + }
2465 +#endif
2466 +
2467 +#ifdef CONFIG_PAX_REFCOUNT
2468 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2469 + unsigned int bkpt;
2470 +
2471 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2472 + current->thread.error_code = ifsr;
2473 + current->thread.trap_no = 0;
2474 + pax_report_refcount_overflow(regs);
2475 + fixup_exception(regs);
2476 + return;
2477 + }
2478 + }
2479 +#endif
2480 +
2481 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2482 return;
2483
2484 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2485 inf->name, ifsr, addr);
2486
2487 +die:
2488 info.si_signo = inf->sig;
2489 info.si_errno = 0;
2490 info.si_code = inf->code;
2491 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2492 index cf08bdf..f1a0383 100644
2493 --- a/arch/arm/mm/fault.h
2494 +++ b/arch/arm/mm/fault.h
2495 @@ -3,6 +3,7 @@
2496
2497 /*
2498 * Fault status register encodings. We steal bit 31 for our own purposes.
2499 + * Set when the FSR value is from an instruction fault.
2500 */
2501 #define FSR_LNX_PF (1 << 31)
2502 #define FSR_WRITE (1 << 11)
2503 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2504 }
2505 #endif
2506
2507 +/* valid for LPAE and !LPAE */
2508 +static inline int is_xn_fault(unsigned int fsr)
2509 +{
2510 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2511 +}
2512 +
2513 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2514 unsigned long search_exception_table(unsigned long addr);
2515
2516 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2517 index ad722f1..46b670e 100644
2518 --- a/arch/arm/mm/init.c
2519 +++ b/arch/arm/mm/init.c
2520 @@ -734,9 +734,43 @@ void __init mem_init(void)
2521
2522 void free_initmem(void)
2523 {
2524 +
2525 +#ifdef CONFIG_PAX_KERNEXEC
2526 + unsigned long addr;
2527 + pgd_t *pgd;
2528 + pud_t *pud;
2529 + pmd_t *pmd;
2530 +#endif
2531 +
2532 #ifdef CONFIG_HAVE_TCM
2533 extern char __tcm_start, __tcm_end;
2534 +#endif
2535
2536 +#ifdef CONFIG_PAX_KERNEXEC
2537 + /* make pages tables, etc before .text NX */
2538 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2539 + pgd = pgd_offset_k(addr);
2540 + pud = pud_offset(pgd, addr);
2541 + pmd = pmd_offset(pud, addr);
2542 + __pmd_update(pmd, PMD_SECT_XN);
2543 + }
2544 + /* make init NX */
2545 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2546 + pgd = pgd_offset_k(addr);
2547 + pud = pud_offset(pgd, addr);
2548 + pmd = pmd_offset(pud, addr);
2549 + __pmd_update(pmd, PMD_SECT_XN);
2550 + }
2551 + /* make kernel code/rodata read-only */
2552 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2553 + pgd = pgd_offset_k(addr);
2554 + pud = pud_offset(pgd, addr);
2555 + pmd = pmd_offset(pud, addr);
2556 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2557 + }
2558 +#endif
2559 +
2560 +#ifdef CONFIG_HAVE_TCM
2561 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2562 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2563 __phys_to_pfn(__pa(&__tcm_end)),
2564 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2565 index ce8cb19..b9fe4d7 100644
2566 --- a/arch/arm/mm/mmap.c
2567 +++ b/arch/arm/mm/mmap.c
2568 @@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2569 unsigned long start_addr;
2570 int do_align = 0;
2571 int aliasing = cache_is_vipt_aliasing();
2572 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2573
2574 /*
2575 * We only need to do colour alignment if either the I or D
2576 @@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2577 if (len > TASK_SIZE)
2578 return -ENOMEM;
2579
2580 +#ifdef CONFIG_PAX_RANDMMAP
2581 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2582 +#endif
2583 +
2584 if (addr) {
2585 if (do_align)
2586 addr = COLOUR_ALIGN(addr, pgoff);
2587 @@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2588 addr = PAGE_ALIGN(addr);
2589
2590 vma = find_vma(mm, addr);
2591 - if (TASK_SIZE - len >= addr &&
2592 - (!vma || addr + len <= vma->vm_start))
2593 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2594 return addr;
2595 }
2596 if (len > mm->cached_hole_size) {
2597 - start_addr = addr = mm->free_area_cache;
2598 + start_addr = addr = mm->free_area_cache;
2599 } else {
2600 - start_addr = addr = mm->mmap_base;
2601 - mm->cached_hole_size = 0;
2602 + start_addr = addr = mm->mmap_base;
2603 + mm->cached_hole_size = 0;
2604 }
2605
2606 full_search:
2607 @@ -124,14 +128,14 @@ full_search:
2608 * Start a new search - just in case we missed
2609 * some holes.
2610 */
2611 - if (start_addr != TASK_UNMAPPED_BASE) {
2612 - start_addr = addr = TASK_UNMAPPED_BASE;
2613 + if (start_addr != mm->mmap_base) {
2614 + start_addr = addr = mm->mmap_base;
2615 mm->cached_hole_size = 0;
2616 goto full_search;
2617 }
2618 return -ENOMEM;
2619 }
2620 - if (!vma || addr + len <= vma->vm_start) {
2621 + if (check_heap_stack_gap(vma, addr, len, offset)) {
2622 /*
2623 * Remember the place where we stopped the search:
2624 */
2625 @@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2626 unsigned long addr = addr0;
2627 int do_align = 0;
2628 int aliasing = cache_is_vipt_aliasing();
2629 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2630
2631 /*
2632 * We only need to do colour alignment if either the I or D
2633 @@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2634 return addr;
2635 }
2636
2637 +#ifdef CONFIG_PAX_RANDMMAP
2638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2639 +#endif
2640 +
2641 /* requesting a specific address */
2642 if (addr) {
2643 if (do_align)
2644 @@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2645 else
2646 addr = PAGE_ALIGN(addr);
2647 vma = find_vma(mm, addr);
2648 - if (TASK_SIZE - len >= addr &&
2649 - (!vma || addr + len <= vma->vm_start))
2650 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2651 return addr;
2652 }
2653
2654 @@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2655 /* make sure it can fit in the remaining address space */
2656 if (addr > len) {
2657 vma = find_vma(mm, addr-len);
2658 - if (!vma || addr <= vma->vm_start)
2659 + if (check_heap_stack_gap(vma, addr - len, len, offset))
2660 /* remember the address as a hint for next time */
2661 return (mm->free_area_cache = addr-len);
2662 }
2663 @@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2664 goto bottomup;
2665
2666 addr = mm->mmap_base - len;
2667 - if (do_align)
2668 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2669
2670 do {
2671 + if (do_align)
2672 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2673 /*
2674 * Lookup failure means no vma is above this address,
2675 * else if new region fits below vma->vm_start,
2676 * return with success:
2677 */
2678 vma = find_vma(mm, addr);
2679 - if (!vma || addr+len <= vma->vm_start)
2680 + if (check_heap_stack_gap(vma, addr, len, offset))
2681 /* remember the address as a hint for next time */
2682 return (mm->free_area_cache = addr);
2683
2684 @@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2685 mm->cached_hole_size = vma->vm_start - addr;
2686
2687 /* try just below the current vma->vm_start */
2688 - addr = vma->vm_start - len;
2689 - if (do_align)
2690 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2691 - } while (len < vma->vm_start);
2692 + addr = skip_heap_stack_gap(vma, len, offset);
2693 + } while (!IS_ERR_VALUE(addr));
2694
2695 bottomup:
2696 /*
2697 @@ -266,10 +272,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2698
2699 if (mmap_is_legacy()) {
2700 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2701 +
2702 +#ifdef CONFIG_PAX_RANDMMAP
2703 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2704 + mm->mmap_base += mm->delta_mmap;
2705 +#endif
2706 +
2707 mm->get_unmapped_area = arch_get_unmapped_area;
2708 mm->unmap_area = arch_unmap_area;
2709 } else {
2710 mm->mmap_base = mmap_base(random_factor);
2711 +
2712 +#ifdef CONFIG_PAX_RANDMMAP
2713 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2714 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2715 +#endif
2716 +
2717 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2718 mm->unmap_area = arch_unmap_area_topdown;
2719 }
2720 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2721 index 99b47b9..ede7824 100644
2722 --- a/arch/arm/mm/mmu.c
2723 +++ b/arch/arm/mm/mmu.c
2724 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2725 [MT_UNCACHED] = {
2726 .prot_pte = PROT_PTE_DEVICE,
2727 .prot_l1 = PMD_TYPE_TABLE,
2728 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2729 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2730 .domain = DOMAIN_IO,
2731 },
2732 [MT_CACHECLEAN] = {
2733 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2734 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2735 .domain = DOMAIN_KERNEL,
2736 },
2737 #ifndef CONFIG_ARM_LPAE
2738 [MT_MINICLEAN] = {
2739 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2740 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2741 .domain = DOMAIN_KERNEL,
2742 },
2743 #endif
2744 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2745 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2746 .domain = DOMAIN_KERNEL,
2747 },
2748 + [MT_MEMORY_R] = {
2749 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2750 + .prot_l1 = PMD_TYPE_TABLE,
2751 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2752 + .domain = DOMAIN_KERNEL,
2753 + },
2754 + [MT_MEMORY_RW] = {
2755 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2756 + .prot_l1 = PMD_TYPE_TABLE,
2757 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2758 + .domain = DOMAIN_KERNEL,
2759 + },
2760 + [MT_MEMORY_RX] = {
2761 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2762 + .prot_l1 = PMD_TYPE_TABLE,
2763 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2764 + .domain = DOMAIN_KERNEL,
2765 + },
2766 [MT_ROM] = {
2767 - .prot_sect = PMD_TYPE_SECT,
2768 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2769 .domain = DOMAIN_KERNEL,
2770 },
2771 [MT_MEMORY_NONCACHED] = {
2772 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2773 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2774 L_PTE_XN,
2775 .prot_l1 = PMD_TYPE_TABLE,
2776 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2777 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2778 .domain = DOMAIN_KERNEL,
2779 },
2780 [MT_MEMORY_ITCM] = {
2781 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2782 * from SVC mode and no access from userspace.
2783 */
2784 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2785 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2786 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2787 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2788 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2789 #endif
2790 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2791 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2792 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2793 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2794 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2795 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2796 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2797 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2798 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2799 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2800 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2801 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2802 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2803 @@ -503,6 +529,12 @@ static void __init build_mem_type_table(void)
2804 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2805 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2806 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2807 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2808 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2809 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2810 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2811 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2812 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2813 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2814 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2815 mem_types[MT_ROM].prot_sect |= cp->pmd;
2816 @@ -1198,8 +1230,37 @@ static void __init map_lowmem(void)
2817 map.pfn = __phys_to_pfn(start);
2818 map.virtual = __phys_to_virt(start);
2819 map.length = end - start;
2820 - map.type = MT_MEMORY;
2821
2822 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2823 + struct map_desc kernel;
2824 + struct map_desc initmap;
2825 +
2826 + /* when freeing initmem we will make this RW */
2827 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2828 + initmap.virtual = (unsigned long)__init_begin;
2829 + initmap.length = _sdata - __init_begin;
2830 + initmap.type = MT_MEMORY;
2831 + create_mapping(&initmap);
2832 +
2833 + /* when freeing initmem we will make this RX */
2834 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2835 + kernel.virtual = (unsigned long)_stext;
2836 + kernel.length = __init_begin - _stext;
2837 + kernel.type = MT_MEMORY;
2838 + create_mapping(&kernel);
2839 +
2840 + if (map.virtual < (unsigned long)_stext) {
2841 + map.length = (unsigned long)_stext - map.virtual;
2842 + map.type = MT_MEMORY;
2843 + create_mapping(&map);
2844 + }
2845 +
2846 + map.pfn = __phys_to_pfn(__pa(_sdata));
2847 + map.virtual = (unsigned long)_sdata;
2848 + map.length = end - __pa(_sdata);
2849 + }
2850 +
2851 + map.type = MT_MEMORY_RW;
2852 create_mapping(&map);
2853 }
2854 }
2855 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2856 index ec63e4a..62aa5f1d 100644
2857 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2858 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2859 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2860 value in bridge_virt_base */
2861 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2862 const int win);
2863 -};
2864 +} __no_const;
2865
2866 /*
2867 * Information needed to setup one address mapping.
2868 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2869 index f5144cd..71f6d1f 100644
2870 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2871 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2872 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2873 int (*started)(unsigned ch);
2874 int (*flush)(unsigned ch);
2875 int (*stop)(unsigned ch);
2876 -};
2877 +} __no_const;
2878
2879 extern void *samsung_dmadev_get_ops(void);
2880 extern void *s3c_dma_get_ops(void);
2881 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2882 index c3a58a1..78fbf54 100644
2883 --- a/arch/avr32/include/asm/cache.h
2884 +++ b/arch/avr32/include/asm/cache.h
2885 @@ -1,8 +1,10 @@
2886 #ifndef __ASM_AVR32_CACHE_H
2887 #define __ASM_AVR32_CACHE_H
2888
2889 +#include <linux/const.h>
2890 +
2891 #define L1_CACHE_SHIFT 5
2892 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2893 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2894
2895 /*
2896 * Memory returned by kmalloc() may be used for DMA, so we must make
2897 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2898 index e2c3287..6c4f98c 100644
2899 --- a/arch/avr32/include/asm/elf.h
2900 +++ b/arch/avr32/include/asm/elf.h
2901 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2902 the loader. We need to make sure that it is out of the way of the program
2903 that it will "exec", and that there is sufficient room for the brk. */
2904
2905 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2906 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2907
2908 +#ifdef CONFIG_PAX_ASLR
2909 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2910 +
2911 +#define PAX_DELTA_MMAP_LEN 15
2912 +#define PAX_DELTA_STACK_LEN 15
2913 +#endif
2914
2915 /* This yields a mask that user programs can use to figure out what
2916 instruction set this CPU supports. This could be done in user space,
2917 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2918 index 479330b..53717a8 100644
2919 --- a/arch/avr32/include/asm/kmap_types.h
2920 +++ b/arch/avr32/include/asm/kmap_types.h
2921 @@ -2,9 +2,9 @@
2922 #define __ASM_AVR32_KMAP_TYPES_H
2923
2924 #ifdef CONFIG_DEBUG_HIGHMEM
2925 -# define KM_TYPE_NR 29
2926 +# define KM_TYPE_NR 30
2927 #else
2928 -# define KM_TYPE_NR 14
2929 +# define KM_TYPE_NR 15
2930 #endif
2931
2932 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2933 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2934 index b2f2d2d..d1c85cb 100644
2935 --- a/arch/avr32/mm/fault.c
2936 +++ b/arch/avr32/mm/fault.c
2937 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2938
2939 int exception_trace = 1;
2940
2941 +#ifdef CONFIG_PAX_PAGEEXEC
2942 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2943 +{
2944 + unsigned long i;
2945 +
2946 + printk(KERN_ERR "PAX: bytes at PC: ");
2947 + for (i = 0; i < 20; i++) {
2948 + unsigned char c;
2949 + if (get_user(c, (unsigned char *)pc+i))
2950 + printk(KERN_CONT "???????? ");
2951 + else
2952 + printk(KERN_CONT "%02x ", c);
2953 + }
2954 + printk("\n");
2955 +}
2956 +#endif
2957 +
2958 /*
2959 * This routine handles page faults. It determines the address and the
2960 * problem, and then passes it off to one of the appropriate routines.
2961 @@ -174,6 +191,16 @@ bad_area:
2962 up_read(&mm->mmap_sem);
2963
2964 if (user_mode(regs)) {
2965 +
2966 +#ifdef CONFIG_PAX_PAGEEXEC
2967 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2968 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2969 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2970 + do_group_exit(SIGKILL);
2971 + }
2972 + }
2973 +#endif
2974 +
2975 if (exception_trace && printk_ratelimit())
2976 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2977 "sp %08lx ecr %lu\n",
2978 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2979 index 568885a..f8008df 100644
2980 --- a/arch/blackfin/include/asm/cache.h
2981 +++ b/arch/blackfin/include/asm/cache.h
2982 @@ -7,6 +7,7 @@
2983 #ifndef __ARCH_BLACKFIN_CACHE_H
2984 #define __ARCH_BLACKFIN_CACHE_H
2985
2986 +#include <linux/const.h>
2987 #include <linux/linkage.h> /* for asmlinkage */
2988
2989 /*
2990 @@ -14,7 +15,7 @@
2991 * Blackfin loads 32 bytes for cache
2992 */
2993 #define L1_CACHE_SHIFT 5
2994 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2995 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2996 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2997
2998 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2999 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3000 index aea2718..3639a60 100644
3001 --- a/arch/cris/include/arch-v10/arch/cache.h
3002 +++ b/arch/cris/include/arch-v10/arch/cache.h
3003 @@ -1,8 +1,9 @@
3004 #ifndef _ASM_ARCH_CACHE_H
3005 #define _ASM_ARCH_CACHE_H
3006
3007 +#include <linux/const.h>
3008 /* Etrax 100LX have 32-byte cache-lines. */
3009 -#define L1_CACHE_BYTES 32
3010 #define L1_CACHE_SHIFT 5
3011 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3012
3013 #endif /* _ASM_ARCH_CACHE_H */
3014 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3015 index 7caf25d..ee65ac5 100644
3016 --- a/arch/cris/include/arch-v32/arch/cache.h
3017 +++ b/arch/cris/include/arch-v32/arch/cache.h
3018 @@ -1,11 +1,12 @@
3019 #ifndef _ASM_CRIS_ARCH_CACHE_H
3020 #define _ASM_CRIS_ARCH_CACHE_H
3021
3022 +#include <linux/const.h>
3023 #include <arch/hwregs/dma.h>
3024
3025 /* A cache-line is 32 bytes. */
3026 -#define L1_CACHE_BYTES 32
3027 #define L1_CACHE_SHIFT 5
3028 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3029
3030 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3031
3032 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3033 index b86329d..6709906 100644
3034 --- a/arch/frv/include/asm/atomic.h
3035 +++ b/arch/frv/include/asm/atomic.h
3036 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3037 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3038 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3039
3040 +#define atomic64_read_unchecked(v) atomic64_read(v)
3041 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3042 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3043 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3044 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3045 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3046 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3047 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3048 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3049 +
3050 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3051 {
3052 int c, old;
3053 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3054 index 2797163..c2a401d 100644
3055 --- a/arch/frv/include/asm/cache.h
3056 +++ b/arch/frv/include/asm/cache.h
3057 @@ -12,10 +12,11 @@
3058 #ifndef __ASM_CACHE_H
3059 #define __ASM_CACHE_H
3060
3061 +#include <linux/const.h>
3062
3063 /* bytes per L1 cache line */
3064 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3065 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3066 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3067
3068 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3069 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3070 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3071 index 43901f2..0d8b865 100644
3072 --- a/arch/frv/include/asm/kmap_types.h
3073 +++ b/arch/frv/include/asm/kmap_types.h
3074 @@ -2,6 +2,6 @@
3075 #ifndef _ASM_KMAP_TYPES_H
3076 #define _ASM_KMAP_TYPES_H
3077
3078 -#define KM_TYPE_NR 17
3079 +#define KM_TYPE_NR 18
3080
3081 #endif
3082 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3083 index 385fd30..3aaf4fe 100644
3084 --- a/arch/frv/mm/elf-fdpic.c
3085 +++ b/arch/frv/mm/elf-fdpic.c
3086 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3087 {
3088 struct vm_area_struct *vma;
3089 unsigned long limit;
3090 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3091
3092 if (len > TASK_SIZE)
3093 return -ENOMEM;
3094 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3095 if (addr) {
3096 addr = PAGE_ALIGN(addr);
3097 vma = find_vma(current->mm, addr);
3098 - if (TASK_SIZE - len >= addr &&
3099 - (!vma || addr + len <= vma->vm_start))
3100 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3101 goto success;
3102 }
3103
3104 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3105 for (; vma; vma = vma->vm_next) {
3106 if (addr > limit)
3107 break;
3108 - if (addr + len <= vma->vm_start)
3109 + if (check_heap_stack_gap(vma, addr, len, offset))
3110 goto success;
3111 addr = vma->vm_end;
3112 }
3113 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3114 for (; vma; vma = vma->vm_next) {
3115 if (addr > limit)
3116 break;
3117 - if (addr + len <= vma->vm_start)
3118 + if (check_heap_stack_gap(vma, addr, len, offset))
3119 goto success;
3120 addr = vma->vm_end;
3121 }
3122 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3123 index f4ca594..adc72fd6 100644
3124 --- a/arch/hexagon/include/asm/cache.h
3125 +++ b/arch/hexagon/include/asm/cache.h
3126 @@ -21,9 +21,11 @@
3127 #ifndef __ASM_CACHE_H
3128 #define __ASM_CACHE_H
3129
3130 +#include <linux/const.h>
3131 +
3132 /* Bytes per L1 cache line */
3133 -#define L1_CACHE_SHIFT (5)
3134 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3135 +#define L1_CACHE_SHIFT 5
3136 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3137
3138 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3139 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3140 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3141 index 6e6fe18..a6ae668 100644
3142 --- a/arch/ia64/include/asm/atomic.h
3143 +++ b/arch/ia64/include/asm/atomic.h
3144 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3145 #define atomic64_inc(v) atomic64_add(1, (v))
3146 #define atomic64_dec(v) atomic64_sub(1, (v))
3147
3148 +#define atomic64_read_unchecked(v) atomic64_read(v)
3149 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3150 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3151 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3152 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3153 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3154 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3155 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3156 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3157 +
3158 /* Atomic operations are already serializing */
3159 #define smp_mb__before_atomic_dec() barrier()
3160 #define smp_mb__after_atomic_dec() barrier()
3161 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3162 index 988254a..e1ee885 100644
3163 --- a/arch/ia64/include/asm/cache.h
3164 +++ b/arch/ia64/include/asm/cache.h
3165 @@ -1,6 +1,7 @@
3166 #ifndef _ASM_IA64_CACHE_H
3167 #define _ASM_IA64_CACHE_H
3168
3169 +#include <linux/const.h>
3170
3171 /*
3172 * Copyright (C) 1998-2000 Hewlett-Packard Co
3173 @@ -9,7 +10,7 @@
3174
3175 /* Bytes per L1 (data) cache line. */
3176 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3177 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3178 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3179
3180 #ifdef CONFIG_SMP
3181 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3182 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3183 index b5298eb..67c6e62 100644
3184 --- a/arch/ia64/include/asm/elf.h
3185 +++ b/arch/ia64/include/asm/elf.h
3186 @@ -42,6 +42,13 @@
3187 */
3188 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3189
3190 +#ifdef CONFIG_PAX_ASLR
3191 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3192 +
3193 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3194 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3195 +#endif
3196 +
3197 #define PT_IA_64_UNWIND 0x70000001
3198
3199 /* IA-64 relocations: */
3200 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3201 index 96a8d92..617a1cf 100644
3202 --- a/arch/ia64/include/asm/pgalloc.h
3203 +++ b/arch/ia64/include/asm/pgalloc.h
3204 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3205 pgd_val(*pgd_entry) = __pa(pud);
3206 }
3207
3208 +static inline void
3209 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3210 +{
3211 + pgd_populate(mm, pgd_entry, pud);
3212 +}
3213 +
3214 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3215 {
3216 return quicklist_alloc(0, GFP_KERNEL, NULL);
3217 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3218 pud_val(*pud_entry) = __pa(pmd);
3219 }
3220
3221 +static inline void
3222 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3223 +{
3224 + pud_populate(mm, pud_entry, pmd);
3225 +}
3226 +
3227 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3228 {
3229 return quicklist_alloc(0, GFP_KERNEL, NULL);
3230 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3231 index 815810c..d60bd4c 100644
3232 --- a/arch/ia64/include/asm/pgtable.h
3233 +++ b/arch/ia64/include/asm/pgtable.h
3234 @@ -12,7 +12,7 @@
3235 * David Mosberger-Tang <davidm@hpl.hp.com>
3236 */
3237
3238 -
3239 +#include <linux/const.h>
3240 #include <asm/mman.h>
3241 #include <asm/page.h>
3242 #include <asm/processor.h>
3243 @@ -142,6 +142,17 @@
3244 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3245 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3246 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3247 +
3248 +#ifdef CONFIG_PAX_PAGEEXEC
3249 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3250 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3251 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3252 +#else
3253 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3254 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3255 +# define PAGE_COPY_NOEXEC PAGE_COPY
3256 +#endif
3257 +
3258 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3259 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3260 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3261 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3262 index 54ff557..70c88b7 100644
3263 --- a/arch/ia64/include/asm/spinlock.h
3264 +++ b/arch/ia64/include/asm/spinlock.h
3265 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3266 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3267
3268 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3269 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3270 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3271 }
3272
3273 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3274 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3275 index 449c8c0..50cdf87 100644
3276 --- a/arch/ia64/include/asm/uaccess.h
3277 +++ b/arch/ia64/include/asm/uaccess.h
3278 @@ -42,6 +42,8 @@
3279 #include <asm/pgtable.h>
3280 #include <asm/io.h>
3281
3282 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3283 +
3284 /*
3285 * For historical reasons, the following macros are grossly misnamed:
3286 */
3287 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3288 static inline unsigned long
3289 __copy_to_user (void __user *to, const void *from, unsigned long count)
3290 {
3291 + if (count > INT_MAX)
3292 + return count;
3293 +
3294 + if (!__builtin_constant_p(count))
3295 + check_object_size(from, count, true);
3296 +
3297 return __copy_user(to, (__force void __user *) from, count);
3298 }
3299
3300 static inline unsigned long
3301 __copy_from_user (void *to, const void __user *from, unsigned long count)
3302 {
3303 + if (count > INT_MAX)
3304 + return count;
3305 +
3306 + if (!__builtin_constant_p(count))
3307 + check_object_size(to, count, false);
3308 +
3309 return __copy_user((__force void __user *) to, from, count);
3310 }
3311
3312 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3313 ({ \
3314 void __user *__cu_to = (to); \
3315 const void *__cu_from = (from); \
3316 - long __cu_len = (n); \
3317 + unsigned long __cu_len = (n); \
3318 \
3319 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3320 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3321 + if (!__builtin_constant_p(n)) \
3322 + check_object_size(__cu_from, __cu_len, true); \
3323 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3324 + } \
3325 __cu_len; \
3326 })
3327
3328 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3329 ({ \
3330 void *__cu_to = (to); \
3331 const void __user *__cu_from = (from); \
3332 - long __cu_len = (n); \
3333 + unsigned long __cu_len = (n); \
3334 \
3335 __chk_user_ptr(__cu_from); \
3336 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3337 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3338 + if (!__builtin_constant_p(n)) \
3339 + check_object_size(__cu_to, __cu_len, false); \
3340 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3341 + } \
3342 __cu_len; \
3343 })
3344
3345 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3346 index 24603be..948052d 100644
3347 --- a/arch/ia64/kernel/module.c
3348 +++ b/arch/ia64/kernel/module.c
3349 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3350 void
3351 module_free (struct module *mod, void *module_region)
3352 {
3353 - if (mod && mod->arch.init_unw_table &&
3354 - module_region == mod->module_init) {
3355 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3356 unw_remove_unwind_table(mod->arch.init_unw_table);
3357 mod->arch.init_unw_table = NULL;
3358 }
3359 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3360 }
3361
3362 static inline int
3363 +in_init_rx (const struct module *mod, uint64_t addr)
3364 +{
3365 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3366 +}
3367 +
3368 +static inline int
3369 +in_init_rw (const struct module *mod, uint64_t addr)
3370 +{
3371 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3372 +}
3373 +
3374 +static inline int
3375 in_init (const struct module *mod, uint64_t addr)
3376 {
3377 - return addr - (uint64_t) mod->module_init < mod->init_size;
3378 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3379 +}
3380 +
3381 +static inline int
3382 +in_core_rx (const struct module *mod, uint64_t addr)
3383 +{
3384 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3385 +}
3386 +
3387 +static inline int
3388 +in_core_rw (const struct module *mod, uint64_t addr)
3389 +{
3390 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3391 }
3392
3393 static inline int
3394 in_core (const struct module *mod, uint64_t addr)
3395 {
3396 - return addr - (uint64_t) mod->module_core < mod->core_size;
3397 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3398 }
3399
3400 static inline int
3401 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3402 break;
3403
3404 case RV_BDREL:
3405 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3406 + if (in_init_rx(mod, val))
3407 + val -= (uint64_t) mod->module_init_rx;
3408 + else if (in_init_rw(mod, val))
3409 + val -= (uint64_t) mod->module_init_rw;
3410 + else if (in_core_rx(mod, val))
3411 + val -= (uint64_t) mod->module_core_rx;
3412 + else if (in_core_rw(mod, val))
3413 + val -= (uint64_t) mod->module_core_rw;
3414 break;
3415
3416 case RV_LTV:
3417 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3418 * addresses have been selected...
3419 */
3420 uint64_t gp;
3421 - if (mod->core_size > MAX_LTOFF)
3422 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3423 /*
3424 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3425 * at the end of the module.
3426 */
3427 - gp = mod->core_size - MAX_LTOFF / 2;
3428 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3429 else
3430 - gp = mod->core_size / 2;
3431 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3432 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3433 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3434 mod->arch.gp = gp;
3435 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3436 }
3437 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3438 index d9439ef..d0cac6b 100644
3439 --- a/arch/ia64/kernel/sys_ia64.c
3440 +++ b/arch/ia64/kernel/sys_ia64.c
3441 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3442 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3443 struct mm_struct *mm = current->mm;
3444 struct vm_area_struct *vma;
3445 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3446
3447 if (len > RGN_MAP_LIMIT)
3448 return -ENOMEM;
3449 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3450 if (REGION_NUMBER(addr) == RGN_HPAGE)
3451 addr = 0;
3452 #endif
3453 +
3454 +#ifdef CONFIG_PAX_RANDMMAP
3455 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3456 + addr = mm->free_area_cache;
3457 + else
3458 +#endif
3459 +
3460 if (!addr)
3461 addr = mm->free_area_cache;
3462
3463 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3464 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3465 /* At this point: (!vma || addr < vma->vm_end). */
3466 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3467 - if (start_addr != TASK_UNMAPPED_BASE) {
3468 + if (start_addr != mm->mmap_base) {
3469 /* Start a new search --- just in case we missed some holes. */
3470 - addr = TASK_UNMAPPED_BASE;
3471 + addr = mm->mmap_base;
3472 goto full_search;
3473 }
3474 return -ENOMEM;
3475 }
3476 - if (!vma || addr + len <= vma->vm_start) {
3477 + if (check_heap_stack_gap(vma, addr, len, offset)) {
3478 /* Remember the address where we stopped this search: */
3479 mm->free_area_cache = addr + len;
3480 return addr;
3481 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3482 index c64460b..4d250a6 100644
3483 --- a/arch/ia64/kernel/topology.c
3484 +++ b/arch/ia64/kernel/topology.c
3485 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3486 return NOTIFY_OK;
3487 }
3488
3489 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
3490 +static struct notifier_block cache_cpu_notifier =
3491 {
3492 .notifier_call = cache_cpu_callback
3493 };
3494 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3495 index 0ccb28f..8992469 100644
3496 --- a/arch/ia64/kernel/vmlinux.lds.S
3497 +++ b/arch/ia64/kernel/vmlinux.lds.S
3498 @@ -198,7 +198,7 @@ SECTIONS {
3499 /* Per-cpu data: */
3500 . = ALIGN(PERCPU_PAGE_SIZE);
3501 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3502 - __phys_per_cpu_start = __per_cpu_load;
3503 + __phys_per_cpu_start = per_cpu_load;
3504 /*
3505 * ensure percpu data fits
3506 * into percpu page size
3507 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3508 index 6cf0341..d352594 100644
3509 --- a/arch/ia64/mm/fault.c
3510 +++ b/arch/ia64/mm/fault.c
3511 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3512 return pte_present(pte);
3513 }
3514
3515 +#ifdef CONFIG_PAX_PAGEEXEC
3516 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3517 +{
3518 + unsigned long i;
3519 +
3520 + printk(KERN_ERR "PAX: bytes at PC: ");
3521 + for (i = 0; i < 8; i++) {
3522 + unsigned int c;
3523 + if (get_user(c, (unsigned int *)pc+i))
3524 + printk(KERN_CONT "???????? ");
3525 + else
3526 + printk(KERN_CONT "%08x ", c);
3527 + }
3528 + printk("\n");
3529 +}
3530 +#endif
3531 +
3532 # define VM_READ_BIT 0
3533 # define VM_WRITE_BIT 1
3534 # define VM_EXEC_BIT 2
3535 @@ -149,8 +166,21 @@ retry:
3536 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3537 goto bad_area;
3538
3539 - if ((vma->vm_flags & mask) != mask)
3540 + if ((vma->vm_flags & mask) != mask) {
3541 +
3542 +#ifdef CONFIG_PAX_PAGEEXEC
3543 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3544 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3545 + goto bad_area;
3546 +
3547 + up_read(&mm->mmap_sem);
3548 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3549 + do_group_exit(SIGKILL);
3550 + }
3551 +#endif
3552 +
3553 goto bad_area;
3554 + }
3555
3556 /*
3557 * If for any reason at all we couldn't handle the fault, make
3558 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3559 index 5ca674b..127c3cb 100644
3560 --- a/arch/ia64/mm/hugetlbpage.c
3561 +++ b/arch/ia64/mm/hugetlbpage.c
3562 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3563 unsigned long pgoff, unsigned long flags)
3564 {
3565 struct vm_area_struct *vmm;
3566 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3567
3568 if (len > RGN_MAP_LIMIT)
3569 return -ENOMEM;
3570 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3571 /* At this point: (!vmm || addr < vmm->vm_end). */
3572 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3573 return -ENOMEM;
3574 - if (!vmm || (addr + len) <= vmm->vm_start)
3575 + if (check_heap_stack_gap(vmm, addr, len, offset))
3576 return addr;
3577 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3578 }
3579 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3580 index 082e383..fb7be80 100644
3581 --- a/arch/ia64/mm/init.c
3582 +++ b/arch/ia64/mm/init.c
3583 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3584 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3585 vma->vm_end = vma->vm_start + PAGE_SIZE;
3586 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3587 +
3588 +#ifdef CONFIG_PAX_PAGEEXEC
3589 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3590 + vma->vm_flags &= ~VM_EXEC;
3591 +
3592 +#ifdef CONFIG_PAX_MPROTECT
3593 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3594 + vma->vm_flags &= ~VM_MAYEXEC;
3595 +#endif
3596 +
3597 + }
3598 +#endif
3599 +
3600 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3601 down_write(&current->mm->mmap_sem);
3602 if (insert_vm_struct(current->mm, vma)) {
3603 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3604 index 40b3ee9..8c2c112 100644
3605 --- a/arch/m32r/include/asm/cache.h
3606 +++ b/arch/m32r/include/asm/cache.h
3607 @@ -1,8 +1,10 @@
3608 #ifndef _ASM_M32R_CACHE_H
3609 #define _ASM_M32R_CACHE_H
3610
3611 +#include <linux/const.h>
3612 +
3613 /* L1 cache line size */
3614 #define L1_CACHE_SHIFT 4
3615 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3616 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3617
3618 #endif /* _ASM_M32R_CACHE_H */
3619 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3620 index 82abd15..d95ae5d 100644
3621 --- a/arch/m32r/lib/usercopy.c
3622 +++ b/arch/m32r/lib/usercopy.c
3623 @@ -14,6 +14,9 @@
3624 unsigned long
3625 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3626 {
3627 + if ((long)n < 0)
3628 + return n;
3629 +
3630 prefetch(from);
3631 if (access_ok(VERIFY_WRITE, to, n))
3632 __copy_user(to,from,n);
3633 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3634 unsigned long
3635 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3636 {
3637 + if ((long)n < 0)
3638 + return n;
3639 +
3640 prefetchw(to);
3641 if (access_ok(VERIFY_READ, from, n))
3642 __copy_user_zeroing(to,from,n);
3643 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3644 index 0395c51..5f26031 100644
3645 --- a/arch/m68k/include/asm/cache.h
3646 +++ b/arch/m68k/include/asm/cache.h
3647 @@ -4,9 +4,11 @@
3648 #ifndef __ARCH_M68K_CACHE_H
3649 #define __ARCH_M68K_CACHE_H
3650
3651 +#include <linux/const.h>
3652 +
3653 /* bytes per L1 cache line */
3654 #define L1_CACHE_SHIFT 4
3655 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3656 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3657
3658 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3659
3660 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3661 index 4efe96a..60e8699 100644
3662 --- a/arch/microblaze/include/asm/cache.h
3663 +++ b/arch/microblaze/include/asm/cache.h
3664 @@ -13,11 +13,12 @@
3665 #ifndef _ASM_MICROBLAZE_CACHE_H
3666 #define _ASM_MICROBLAZE_CACHE_H
3667
3668 +#include <linux/const.h>
3669 #include <asm/registers.h>
3670
3671 #define L1_CACHE_SHIFT 5
3672 /* word-granular cache in microblaze */
3673 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3674 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3675
3676 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3677
3678 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3679 index 01cc6ba..bcb7a5d 100644
3680 --- a/arch/mips/include/asm/atomic.h
3681 +++ b/arch/mips/include/asm/atomic.h
3682 @@ -21,6 +21,10 @@
3683 #include <asm/cmpxchg.h>
3684 #include <asm/war.h>
3685
3686 +#ifdef CONFIG_GENERIC_ATOMIC64
3687 +#include <asm-generic/atomic64.h>
3688 +#endif
3689 +
3690 #define ATOMIC_INIT(i) { (i) }
3691
3692 /*
3693 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3694 */
3695 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3696
3697 +#define atomic64_read_unchecked(v) atomic64_read(v)
3698 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3699 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3700 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3701 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3702 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3703 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3704 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3705 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3706 +
3707 #endif /* CONFIG_64BIT */
3708
3709 /*
3710 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3711 index b4db69f..8f3b093 100644
3712 --- a/arch/mips/include/asm/cache.h
3713 +++ b/arch/mips/include/asm/cache.h
3714 @@ -9,10 +9,11 @@
3715 #ifndef _ASM_CACHE_H
3716 #define _ASM_CACHE_H
3717
3718 +#include <linux/const.h>
3719 #include <kmalloc.h>
3720
3721 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3722 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3723 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3724
3725 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3726 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3727 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3728 index 455c0ac..ad65fbe 100644
3729 --- a/arch/mips/include/asm/elf.h
3730 +++ b/arch/mips/include/asm/elf.h
3731 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3732 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3733 #endif
3734
3735 +#ifdef CONFIG_PAX_ASLR
3736 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3737 +
3738 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3739 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3740 +#endif
3741 +
3742 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3743 struct linux_binprm;
3744 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3745 int uses_interp);
3746
3747 -struct mm_struct;
3748 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3749 -#define arch_randomize_brk arch_randomize_brk
3750 -
3751 #endif /* _ASM_ELF_H */
3752 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3753 index c1f6afa..38cc6e9 100644
3754 --- a/arch/mips/include/asm/exec.h
3755 +++ b/arch/mips/include/asm/exec.h
3756 @@ -12,6 +12,6 @@
3757 #ifndef _ASM_EXEC_H
3758 #define _ASM_EXEC_H
3759
3760 -extern unsigned long arch_align_stack(unsigned long sp);
3761 +#define arch_align_stack(x) ((x) & ~0xfUL)
3762
3763 #endif /* _ASM_EXEC_H */
3764 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3765 index da9bd7d..91aa7ab 100644
3766 --- a/arch/mips/include/asm/page.h
3767 +++ b/arch/mips/include/asm/page.h
3768 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3769 #ifdef CONFIG_CPU_MIPS32
3770 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3771 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3772 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3773 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3774 #else
3775 typedef struct { unsigned long long pte; } pte_t;
3776 #define pte_val(x) ((x).pte)
3777 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3778 index 881d18b..cea38bc 100644
3779 --- a/arch/mips/include/asm/pgalloc.h
3780 +++ b/arch/mips/include/asm/pgalloc.h
3781 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3782 {
3783 set_pud(pud, __pud((unsigned long)pmd));
3784 }
3785 +
3786 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3787 +{
3788 + pud_populate(mm, pud, pmd);
3789 +}
3790 #endif
3791
3792 /*
3793 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3794 index 18806a5..141ffcf 100644
3795 --- a/arch/mips/include/asm/thread_info.h
3796 +++ b/arch/mips/include/asm/thread_info.h
3797 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3798 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3799 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3800 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3801 +/* li takes a 32bit immediate */
3802 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3803 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3804
3805 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3806 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3807 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3808 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3809 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3810 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3811 +
3812 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3813
3814 /* work to do in syscall_trace_leave() */
3815 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3816 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3817
3818 /* work to do on interrupt/exception return */
3819 #define _TIF_WORK_MASK \
3820 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3821 /* work to do on any return to u-space */
3822 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3823 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3824
3825 #endif /* __KERNEL__ */
3826
3827 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3828 index 9fdd8bc..4bd7f1a 100644
3829 --- a/arch/mips/kernel/binfmt_elfn32.c
3830 +++ b/arch/mips/kernel/binfmt_elfn32.c
3831 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3832 #undef ELF_ET_DYN_BASE
3833 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3834
3835 +#ifdef CONFIG_PAX_ASLR
3836 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3837 +
3838 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3839 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3840 +#endif
3841 +
3842 #include <asm/processor.h>
3843 #include <linux/module.h>
3844 #include <linux/elfcore.h>
3845 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3846 index ff44823..97f8906 100644
3847 --- a/arch/mips/kernel/binfmt_elfo32.c
3848 +++ b/arch/mips/kernel/binfmt_elfo32.c
3849 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3850 #undef ELF_ET_DYN_BASE
3851 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3852
3853 +#ifdef CONFIG_PAX_ASLR
3854 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3855 +
3856 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3857 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3858 +#endif
3859 +
3860 #include <asm/processor.h>
3861
3862 /*
3863 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3864 index 69b17a9..9db82f9 100644
3865 --- a/arch/mips/kernel/process.c
3866 +++ b/arch/mips/kernel/process.c
3867 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3868 out:
3869 return pc;
3870 }
3871 -
3872 -/*
3873 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3874 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3875 - */
3876 -unsigned long arch_align_stack(unsigned long sp)
3877 -{
3878 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3879 - sp -= get_random_int() & ~PAGE_MASK;
3880 -
3881 - return sp & ALMASK;
3882 -}
3883 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3884 index 4812c6d..2069554 100644
3885 --- a/arch/mips/kernel/ptrace.c
3886 +++ b/arch/mips/kernel/ptrace.c
3887 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3888 return arch;
3889 }
3890
3891 +#ifdef CONFIG_GRKERNSEC_SETXID
3892 +extern void gr_delayed_cred_worker(void);
3893 +#endif
3894 +
3895 /*
3896 * Notification of system call entry/exit
3897 * - triggered by current->work.syscall_trace
3898 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3899 /* do the secure computing check first */
3900 secure_computing_strict(regs->regs[2]);
3901
3902 +#ifdef CONFIG_GRKERNSEC_SETXID
3903 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3904 + gr_delayed_cred_worker();
3905 +#endif
3906 +
3907 if (!(current->ptrace & PT_PTRACED))
3908 goto out;
3909
3910 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3911 index 374f66e..1c882a0 100644
3912 --- a/arch/mips/kernel/scall32-o32.S
3913 +++ b/arch/mips/kernel/scall32-o32.S
3914 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3915
3916 stack_done:
3917 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3918 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3919 + li t1, _TIF_SYSCALL_WORK
3920 and t0, t1
3921 bnez t0, syscall_trace_entry # -> yes
3922
3923 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3924 index 169de6a..f594a89 100644
3925 --- a/arch/mips/kernel/scall64-64.S
3926 +++ b/arch/mips/kernel/scall64-64.S
3927 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3928
3929 sd a3, PT_R26(sp) # save a3 for syscall restarting
3930
3931 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3932 + li t1, _TIF_SYSCALL_WORK
3933 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3934 and t0, t1, t0
3935 bnez t0, syscall_trace_entry
3936 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3937 index 86ec03f..1235baf 100644
3938 --- a/arch/mips/kernel/scall64-n32.S
3939 +++ b/arch/mips/kernel/scall64-n32.S
3940 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3941
3942 sd a3, PT_R26(sp) # save a3 for syscall restarting
3943
3944 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3945 + li t1, _TIF_SYSCALL_WORK
3946 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3947 and t0, t1, t0
3948 bnez t0, n32_syscall_trace_entry
3949 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3950 index 53c2d72..3734584 100644
3951 --- a/arch/mips/kernel/scall64-o32.S
3952 +++ b/arch/mips/kernel/scall64-o32.S
3953 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3954 PTR 4b, bad_stack
3955 .previous
3956
3957 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3958 + li t1, _TIF_SYSCALL_WORK
3959 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3960 and t0, t1, t0
3961 bnez t0, trace_a_syscall
3962 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3963 index ddcec1e..c7f983e 100644
3964 --- a/arch/mips/mm/fault.c
3965 +++ b/arch/mips/mm/fault.c
3966 @@ -27,6 +27,23 @@
3967 #include <asm/highmem.h> /* For VMALLOC_END */
3968 #include <linux/kdebug.h>
3969
3970 +#ifdef CONFIG_PAX_PAGEEXEC
3971 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3972 +{
3973 + unsigned long i;
3974 +
3975 + printk(KERN_ERR "PAX: bytes at PC: ");
3976 + for (i = 0; i < 5; i++) {
3977 + unsigned int c;
3978 + if (get_user(c, (unsigned int *)pc+i))
3979 + printk(KERN_CONT "???????? ");
3980 + else
3981 + printk(KERN_CONT "%08x ", c);
3982 + }
3983 + printk("\n");
3984 +}
3985 +#endif
3986 +
3987 /*
3988 * This routine handles page faults. It determines the address,
3989 * and the problem, and then passes it off to one of the appropriate
3990 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3991 index 302d779..573314a 100644
3992 --- a/arch/mips/mm/mmap.c
3993 +++ b/arch/mips/mm/mmap.c
3994 @@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3995 struct vm_area_struct *vma;
3996 unsigned long addr = addr0;
3997 int do_color_align;
3998 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3999
4000 if (unlikely(len > TASK_SIZE))
4001 return -ENOMEM;
4002 @@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4003 do_color_align = 1;
4004
4005 /* requesting a specific address */
4006 +
4007 +#ifdef CONFIG_PAX_RANDMMAP
4008 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4009 +#endif
4010 +
4011 if (addr) {
4012 if (do_color_align)
4013 addr = COLOUR_ALIGN(addr, pgoff);
4014 @@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4015 addr = PAGE_ALIGN(addr);
4016
4017 vma = find_vma(mm, addr);
4018 - if (TASK_SIZE - len >= addr &&
4019 - (!vma || addr + len <= vma->vm_start))
4020 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4021 return addr;
4022 }
4023
4024 @@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4025 /* At this point: (!vma || addr < vma->vm_end). */
4026 if (TASK_SIZE - len < addr)
4027 return -ENOMEM;
4028 - if (!vma || addr + len <= vma->vm_start)
4029 + if (check_heap_stack_gap(vmm, addr, len, offset))
4030 return addr;
4031 addr = vma->vm_end;
4032 if (do_color_align)
4033 @@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4034 /* make sure it can fit in the remaining address space */
4035 if (likely(addr > len)) {
4036 vma = find_vma(mm, addr - len);
4037 - if (!vma || addr <= vma->vm_start) {
4038 + if (check_heap_stack_gap(vmm, addr - len, len, offset))
4039 /* cache the address as a hint for next time */
4040 return mm->free_area_cache = addr - len;
4041 }
4042 @@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4043 goto bottomup;
4044
4045 addr = mm->mmap_base - len;
4046 - if (do_color_align)
4047 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4048
4049 do {
4050 + if (do_color_align)
4051 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4052 /*
4053 * Lookup failure means no vma is above this address,
4054 * else if new region fits below vma->vm_start,
4055 * return with success:
4056 */
4057 vma = find_vma(mm, addr);
4058 - if (likely(!vma || addr + len <= vma->vm_start)) {
4059 + if (check_heap_stack_gap(vmm, addr, len, offset)) {
4060 /* cache the address as a hint for next time */
4061 return mm->free_area_cache = addr;
4062 }
4063 @@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4064 mm->cached_hole_size = vma->vm_start - addr;
4065
4066 /* try just below the current vma->vm_start */
4067 - addr = vma->vm_start - len;
4068 - if (do_color_align)
4069 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4070 - } while (likely(len < vma->vm_start));
4071 + addr = skip_heap_stack_gap(vma, len, offset);
4072 + } while (!IS_ERR_VALUE(addr));
4073
4074 bottomup:
4075 /*
4076 @@ -242,30 +245,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4077 mm->unmap_area = arch_unmap_area_topdown;
4078 }
4079 }
4080 -
4081 -static inline unsigned long brk_rnd(void)
4082 -{
4083 - unsigned long rnd = get_random_int();
4084 -
4085 - rnd = rnd << PAGE_SHIFT;
4086 - /* 8MB for 32bit, 256MB for 64bit */
4087 - if (TASK_IS_32BIT_ADDR)
4088 - rnd = rnd & 0x7ffffful;
4089 - else
4090 - rnd = rnd & 0xffffffful;
4091 -
4092 - return rnd;
4093 -}
4094 -
4095 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4096 -{
4097 - unsigned long base = mm->brk;
4098 - unsigned long ret;
4099 -
4100 - ret = PAGE_ALIGN(base + brk_rnd());
4101 -
4102 - if (ret < mm->brk)
4103 - return mm->brk;
4104 -
4105 - return ret;
4106 -}
4107 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4108 index 967d144..db12197 100644
4109 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4110 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4111 @@ -11,12 +11,14 @@
4112 #ifndef _ASM_PROC_CACHE_H
4113 #define _ASM_PROC_CACHE_H
4114
4115 +#include <linux/const.h>
4116 +
4117 /* L1 cache */
4118
4119 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4120 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4121 -#define L1_CACHE_BYTES 16 /* bytes per entry */
4122 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4123 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4124 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4125
4126 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4127 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4128 index bcb5df2..84fabd2 100644
4129 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4130 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4131 @@ -16,13 +16,15 @@
4132 #ifndef _ASM_PROC_CACHE_H
4133 #define _ASM_PROC_CACHE_H
4134
4135 +#include <linux/const.h>
4136 +
4137 /*
4138 * L1 cache
4139 */
4140 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4141 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4142 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4143 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4144 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4145 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4146
4147 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4148 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4149 index 4ce7a01..449202a 100644
4150 --- a/arch/openrisc/include/asm/cache.h
4151 +++ b/arch/openrisc/include/asm/cache.h
4152 @@ -19,11 +19,13 @@
4153 #ifndef __ASM_OPENRISC_CACHE_H
4154 #define __ASM_OPENRISC_CACHE_H
4155
4156 +#include <linux/const.h>
4157 +
4158 /* FIXME: How can we replace these with values from the CPU...
4159 * they shouldn't be hard-coded!
4160 */
4161
4162 -#define L1_CACHE_BYTES 16
4163 #define L1_CACHE_SHIFT 4
4164 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4165
4166 #endif /* __ASM_OPENRISC_CACHE_H */
4167 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4168 index af9cf30..2aae9b2 100644
4169 --- a/arch/parisc/include/asm/atomic.h
4170 +++ b/arch/parisc/include/asm/atomic.h
4171 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4172
4173 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4174
4175 +#define atomic64_read_unchecked(v) atomic64_read(v)
4176 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4177 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4178 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4179 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4180 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4181 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4182 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4183 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4184 +
4185 #endif /* !CONFIG_64BIT */
4186
4187
4188 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4189 index 47f11c7..3420df2 100644
4190 --- a/arch/parisc/include/asm/cache.h
4191 +++ b/arch/parisc/include/asm/cache.h
4192 @@ -5,6 +5,7 @@
4193 #ifndef __ARCH_PARISC_CACHE_H
4194 #define __ARCH_PARISC_CACHE_H
4195
4196 +#include <linux/const.h>
4197
4198 /*
4199 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4200 @@ -15,13 +16,13 @@
4201 * just ruin performance.
4202 */
4203 #ifdef CONFIG_PA20
4204 -#define L1_CACHE_BYTES 64
4205 #define L1_CACHE_SHIFT 6
4206 #else
4207 -#define L1_CACHE_BYTES 32
4208 #define L1_CACHE_SHIFT 5
4209 #endif
4210
4211 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4212 +
4213 #ifndef __ASSEMBLY__
4214
4215 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4216 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4217 index 19f6cb1..6c78cf2 100644
4218 --- a/arch/parisc/include/asm/elf.h
4219 +++ b/arch/parisc/include/asm/elf.h
4220 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4221
4222 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4223
4224 +#ifdef CONFIG_PAX_ASLR
4225 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4226 +
4227 +#define PAX_DELTA_MMAP_LEN 16
4228 +#define PAX_DELTA_STACK_LEN 16
4229 +#endif
4230 +
4231 /* This yields a mask that user programs can use to figure out what
4232 instruction set this CPU supports. This could be done in user space,
4233 but it's not easy, and we've already done it here. */
4234 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4235 index fc987a1..6e068ef 100644
4236 --- a/arch/parisc/include/asm/pgalloc.h
4237 +++ b/arch/parisc/include/asm/pgalloc.h
4238 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4239 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4240 }
4241
4242 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4243 +{
4244 + pgd_populate(mm, pgd, pmd);
4245 +}
4246 +
4247 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4248 {
4249 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4250 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4251 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4252 #define pmd_free(mm, x) do { } while (0)
4253 #define pgd_populate(mm, pmd, pte) BUG()
4254 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4255
4256 #endif
4257
4258 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4259 index ee99f23..802b0a1 100644
4260 --- a/arch/parisc/include/asm/pgtable.h
4261 +++ b/arch/parisc/include/asm/pgtable.h
4262 @@ -212,6 +212,17 @@ struct vm_area_struct;
4263 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4264 #define PAGE_COPY PAGE_EXECREAD
4265 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4266 +
4267 +#ifdef CONFIG_PAX_PAGEEXEC
4268 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4269 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4270 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4271 +#else
4272 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4273 +# define PAGE_COPY_NOEXEC PAGE_COPY
4274 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4275 +#endif
4276 +
4277 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4278 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4279 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4280 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4281 index 4ba2c93..f5e3974 100644
4282 --- a/arch/parisc/include/asm/uaccess.h
4283 +++ b/arch/parisc/include/asm/uaccess.h
4284 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4285 const void __user *from,
4286 unsigned long n)
4287 {
4288 - int sz = __compiletime_object_size(to);
4289 + size_t sz = __compiletime_object_size(to);
4290 int ret = -EFAULT;
4291
4292 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4293 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4294 ret = __copy_from_user(to, from, n);
4295 else
4296 copy_from_user_overflow();
4297 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4298 index 5e34ccf..672bc9c 100644
4299 --- a/arch/parisc/kernel/module.c
4300 +++ b/arch/parisc/kernel/module.c
4301 @@ -98,16 +98,38 @@
4302
4303 /* three functions to determine where in the module core
4304 * or init pieces the location is */
4305 +static inline int in_init_rx(struct module *me, void *loc)
4306 +{
4307 + return (loc >= me->module_init_rx &&
4308 + loc < (me->module_init_rx + me->init_size_rx));
4309 +}
4310 +
4311 +static inline int in_init_rw(struct module *me, void *loc)
4312 +{
4313 + return (loc >= me->module_init_rw &&
4314 + loc < (me->module_init_rw + me->init_size_rw));
4315 +}
4316 +
4317 static inline int in_init(struct module *me, void *loc)
4318 {
4319 - return (loc >= me->module_init &&
4320 - loc <= (me->module_init + me->init_size));
4321 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4322 +}
4323 +
4324 +static inline int in_core_rx(struct module *me, void *loc)
4325 +{
4326 + return (loc >= me->module_core_rx &&
4327 + loc < (me->module_core_rx + me->core_size_rx));
4328 +}
4329 +
4330 +static inline int in_core_rw(struct module *me, void *loc)
4331 +{
4332 + return (loc >= me->module_core_rw &&
4333 + loc < (me->module_core_rw + me->core_size_rw));
4334 }
4335
4336 static inline int in_core(struct module *me, void *loc)
4337 {
4338 - return (loc >= me->module_core &&
4339 - loc <= (me->module_core + me->core_size));
4340 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4341 }
4342
4343 static inline int in_local(struct module *me, void *loc)
4344 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4345 }
4346
4347 /* align things a bit */
4348 - me->core_size = ALIGN(me->core_size, 16);
4349 - me->arch.got_offset = me->core_size;
4350 - me->core_size += gots * sizeof(struct got_entry);
4351 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4352 + me->arch.got_offset = me->core_size_rw;
4353 + me->core_size_rw += gots * sizeof(struct got_entry);
4354
4355 - me->core_size = ALIGN(me->core_size, 16);
4356 - me->arch.fdesc_offset = me->core_size;
4357 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4358 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4359 + me->arch.fdesc_offset = me->core_size_rw;
4360 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4361
4362 me->arch.got_max = gots;
4363 me->arch.fdesc_max = fdescs;
4364 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4365
4366 BUG_ON(value == 0);
4367
4368 - got = me->module_core + me->arch.got_offset;
4369 + got = me->module_core_rw + me->arch.got_offset;
4370 for (i = 0; got[i].addr; i++)
4371 if (got[i].addr == value)
4372 goto out;
4373 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4374 #ifdef CONFIG_64BIT
4375 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4376 {
4377 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4378 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4379
4380 if (!value) {
4381 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4382 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4383
4384 /* Create new one */
4385 fdesc->addr = value;
4386 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4387 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4388 return (Elf_Addr)fdesc;
4389 }
4390 #endif /* CONFIG_64BIT */
4391 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4392
4393 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4394 end = table + sechdrs[me->arch.unwind_section].sh_size;
4395 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4396 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4397
4398 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4399 me->arch.unwind_section, table, end, gp);
4400 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4401 index f76c108..92bad82 100644
4402 --- a/arch/parisc/kernel/sys_parisc.c
4403 +++ b/arch/parisc/kernel/sys_parisc.c
4404 @@ -33,9 +33,11 @@
4405 #include <linux/utsname.h>
4406 #include <linux/personality.h>
4407
4408 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4409 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4410 + unsigned long flags)
4411 {
4412 struct vm_area_struct *vma;
4413 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4414
4415 addr = PAGE_ALIGN(addr);
4416
4417 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4418 /* At this point: (!vma || addr < vma->vm_end). */
4419 if (TASK_SIZE - len < addr)
4420 return -ENOMEM;
4421 - if (!vma || addr + len <= vma->vm_start)
4422 + if (check_heap_stack_gap(vma, addr, len, offset))
4423 return addr;
4424 addr = vma->vm_end;
4425 }
4426 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4427 return offset & 0x3FF000;
4428 }
4429
4430 -static unsigned long get_shared_area(struct address_space *mapping,
4431 - unsigned long addr, unsigned long len, unsigned long pgoff)
4432 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4433 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4434 {
4435 struct vm_area_struct *vma;
4436 int offset = mapping ? get_offset(mapping) : 0;
4437 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4438
4439 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4440
4441 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4442 /* At this point: (!vma || addr < vma->vm_end). */
4443 if (TASK_SIZE - len < addr)
4444 return -ENOMEM;
4445 - if (!vma || addr + len <= vma->vm_start)
4446 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
4447 return addr;
4448 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4449 if (addr < vma->vm_end) /* handle wraparound */
4450 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4451 if (flags & MAP_FIXED)
4452 return addr;
4453 if (!addr)
4454 - addr = TASK_UNMAPPED_BASE;
4455 + addr = current->mm->mmap_base;
4456
4457 if (filp) {
4458 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4459 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4460 } else if(flags & MAP_SHARED) {
4461 - addr = get_shared_area(NULL, addr, len, pgoff);
4462 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4463 } else {
4464 - addr = get_unshared_area(addr, len);
4465 + addr = get_unshared_area(filp, addr, len, flags);
4466 }
4467 return addr;
4468 }
4469 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4470 index 45ba99f..8e22c33 100644
4471 --- a/arch/parisc/kernel/traps.c
4472 +++ b/arch/parisc/kernel/traps.c
4473 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4474
4475 down_read(&current->mm->mmap_sem);
4476 vma = find_vma(current->mm,regs->iaoq[0]);
4477 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4478 - && (vma->vm_flags & VM_EXEC)) {
4479 -
4480 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4481 fault_address = regs->iaoq[0];
4482 fault_space = regs->iasq[0];
4483
4484 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4485 index 18162ce..94de376 100644
4486 --- a/arch/parisc/mm/fault.c
4487 +++ b/arch/parisc/mm/fault.c
4488 @@ -15,6 +15,7 @@
4489 #include <linux/sched.h>
4490 #include <linux/interrupt.h>
4491 #include <linux/module.h>
4492 +#include <linux/unistd.h>
4493
4494 #include <asm/uaccess.h>
4495 #include <asm/traps.h>
4496 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4497 static unsigned long
4498 parisc_acctyp(unsigned long code, unsigned int inst)
4499 {
4500 - if (code == 6 || code == 16)
4501 + if (code == 6 || code == 7 || code == 16)
4502 return VM_EXEC;
4503
4504 switch (inst & 0xf0000000) {
4505 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4506 }
4507 #endif
4508
4509 +#ifdef CONFIG_PAX_PAGEEXEC
4510 +/*
4511 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4512 + *
4513 + * returns 1 when task should be killed
4514 + * 2 when rt_sigreturn trampoline was detected
4515 + * 3 when unpatched PLT trampoline was detected
4516 + */
4517 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4518 +{
4519 +
4520 +#ifdef CONFIG_PAX_EMUPLT
4521 + int err;
4522 +
4523 + do { /* PaX: unpatched PLT emulation */
4524 + unsigned int bl, depwi;
4525 +
4526 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4527 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4528 +
4529 + if (err)
4530 + break;
4531 +
4532 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4533 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4534 +
4535 + err = get_user(ldw, (unsigned int *)addr);
4536 + err |= get_user(bv, (unsigned int *)(addr+4));
4537 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4538 +
4539 + if (err)
4540 + break;
4541 +
4542 + if (ldw == 0x0E801096U &&
4543 + bv == 0xEAC0C000U &&
4544 + ldw2 == 0x0E881095U)
4545 + {
4546 + unsigned int resolver, map;
4547 +
4548 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4549 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4550 + if (err)
4551 + break;
4552 +
4553 + regs->gr[20] = instruction_pointer(regs)+8;
4554 + regs->gr[21] = map;
4555 + regs->gr[22] = resolver;
4556 + regs->iaoq[0] = resolver | 3UL;
4557 + regs->iaoq[1] = regs->iaoq[0] + 4;
4558 + return 3;
4559 + }
4560 + }
4561 + } while (0);
4562 +#endif
4563 +
4564 +#ifdef CONFIG_PAX_EMUTRAMP
4565 +
4566 +#ifndef CONFIG_PAX_EMUSIGRT
4567 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4568 + return 1;
4569 +#endif
4570 +
4571 + do { /* PaX: rt_sigreturn emulation */
4572 + unsigned int ldi1, ldi2, bel, nop;
4573 +
4574 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4575 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4576 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4577 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4578 +
4579 + if (err)
4580 + break;
4581 +
4582 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4583 + ldi2 == 0x3414015AU &&
4584 + bel == 0xE4008200U &&
4585 + nop == 0x08000240U)
4586 + {
4587 + regs->gr[25] = (ldi1 & 2) >> 1;
4588 + regs->gr[20] = __NR_rt_sigreturn;
4589 + regs->gr[31] = regs->iaoq[1] + 16;
4590 + regs->sr[0] = regs->iasq[1];
4591 + regs->iaoq[0] = 0x100UL;
4592 + regs->iaoq[1] = regs->iaoq[0] + 4;
4593 + regs->iasq[0] = regs->sr[2];
4594 + regs->iasq[1] = regs->sr[2];
4595 + return 2;
4596 + }
4597 + } while (0);
4598 +#endif
4599 +
4600 + return 1;
4601 +}
4602 +
4603 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4604 +{
4605 + unsigned long i;
4606 +
4607 + printk(KERN_ERR "PAX: bytes at PC: ");
4608 + for (i = 0; i < 5; i++) {
4609 + unsigned int c;
4610 + if (get_user(c, (unsigned int *)pc+i))
4611 + printk(KERN_CONT "???????? ");
4612 + else
4613 + printk(KERN_CONT "%08x ", c);
4614 + }
4615 + printk("\n");
4616 +}
4617 +#endif
4618 +
4619 int fixup_exception(struct pt_regs *regs)
4620 {
4621 const struct exception_table_entry *fix;
4622 @@ -192,8 +303,33 @@ good_area:
4623
4624 acc_type = parisc_acctyp(code,regs->iir);
4625
4626 - if ((vma->vm_flags & acc_type) != acc_type)
4627 + if ((vma->vm_flags & acc_type) != acc_type) {
4628 +
4629 +#ifdef CONFIG_PAX_PAGEEXEC
4630 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4631 + (address & ~3UL) == instruction_pointer(regs))
4632 + {
4633 + up_read(&mm->mmap_sem);
4634 + switch (pax_handle_fetch_fault(regs)) {
4635 +
4636 +#ifdef CONFIG_PAX_EMUPLT
4637 + case 3:
4638 + return;
4639 +#endif
4640 +
4641 +#ifdef CONFIG_PAX_EMUTRAMP
4642 + case 2:
4643 + return;
4644 +#endif
4645 +
4646 + }
4647 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4648 + do_group_exit(SIGKILL);
4649 + }
4650 +#endif
4651 +
4652 goto bad_area;
4653 + }
4654
4655 /*
4656 * If for any reason at all we couldn't handle the fault, make
4657 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4658 index e3b1d41..8e81edf 100644
4659 --- a/arch/powerpc/include/asm/atomic.h
4660 +++ b/arch/powerpc/include/asm/atomic.h
4661 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4662 return t1;
4663 }
4664
4665 +#define atomic64_read_unchecked(v) atomic64_read(v)
4666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674 +
4675 #endif /* __powerpc64__ */
4676
4677 #endif /* __KERNEL__ */
4678 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4679 index 9e495c9..b6878e5 100644
4680 --- a/arch/powerpc/include/asm/cache.h
4681 +++ b/arch/powerpc/include/asm/cache.h
4682 @@ -3,6 +3,7 @@
4683
4684 #ifdef __KERNEL__
4685
4686 +#include <linux/const.h>
4687
4688 /* bytes per L1 cache line */
4689 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4690 @@ -22,7 +23,7 @@
4691 #define L1_CACHE_SHIFT 7
4692 #endif
4693
4694 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4695 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4696
4697 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4698
4699 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4700 index 6abf0a1..459d0f1 100644
4701 --- a/arch/powerpc/include/asm/elf.h
4702 +++ b/arch/powerpc/include/asm/elf.h
4703 @@ -28,8 +28,19 @@
4704 the loader. We need to make sure that it is out of the way of the program
4705 that it will "exec", and that there is sufficient room for the brk. */
4706
4707 -extern unsigned long randomize_et_dyn(unsigned long base);
4708 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4709 +#define ELF_ET_DYN_BASE (0x20000000)
4710 +
4711 +#ifdef CONFIG_PAX_ASLR
4712 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4713 +
4714 +#ifdef __powerpc64__
4715 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4716 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4717 +#else
4718 +#define PAX_DELTA_MMAP_LEN 15
4719 +#define PAX_DELTA_STACK_LEN 15
4720 +#endif
4721 +#endif
4722
4723 /*
4724 * Our registers are always unsigned longs, whether we're a 32 bit
4725 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4726 (0x7ff >> (PAGE_SHIFT - 12)) : \
4727 (0x3ffff >> (PAGE_SHIFT - 12)))
4728
4729 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4730 -#define arch_randomize_brk arch_randomize_brk
4731 -
4732 -
4733 #ifdef CONFIG_SPU_BASE
4734 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4735 #define NT_SPU 1
4736 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4737 index 8196e9c..d83a9f3 100644
4738 --- a/arch/powerpc/include/asm/exec.h
4739 +++ b/arch/powerpc/include/asm/exec.h
4740 @@ -4,6 +4,6 @@
4741 #ifndef _ASM_POWERPC_EXEC_H
4742 #define _ASM_POWERPC_EXEC_H
4743
4744 -extern unsigned long arch_align_stack(unsigned long sp);
4745 +#define arch_align_stack(x) ((x) & ~0xfUL)
4746
4747 #endif /* _ASM_POWERPC_EXEC_H */
4748 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4749 index 5acabbd..7ea14fa 100644
4750 --- a/arch/powerpc/include/asm/kmap_types.h
4751 +++ b/arch/powerpc/include/asm/kmap_types.h
4752 @@ -10,7 +10,7 @@
4753 * 2 of the License, or (at your option) any later version.
4754 */
4755
4756 -#define KM_TYPE_NR 16
4757 +#define KM_TYPE_NR 17
4758
4759 #endif /* __KERNEL__ */
4760 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4761 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4762 index 8565c25..2865190 100644
4763 --- a/arch/powerpc/include/asm/mman.h
4764 +++ b/arch/powerpc/include/asm/mman.h
4765 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4766 }
4767 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4768
4769 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4770 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4771 {
4772 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4773 }
4774 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4775 index f072e97..b436dee 100644
4776 --- a/arch/powerpc/include/asm/page.h
4777 +++ b/arch/powerpc/include/asm/page.h
4778 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4779 * and needs to be executable. This means the whole heap ends
4780 * up being executable.
4781 */
4782 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4783 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4784 +#define VM_DATA_DEFAULT_FLAGS32 \
4785 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4786 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4787
4788 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4789 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4790 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4791 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4792 #endif
4793
4794 +#define ktla_ktva(addr) (addr)
4795 +#define ktva_ktla(addr) (addr)
4796 +
4797 /*
4798 * Use the top bit of the higher-level page table entries to indicate whether
4799 * the entries we point to contain hugepages. This works because we know that
4800 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4801 index cd915d6..c10cee8 100644
4802 --- a/arch/powerpc/include/asm/page_64.h
4803 +++ b/arch/powerpc/include/asm/page_64.h
4804 @@ -154,15 +154,18 @@ do { \
4805 * stack by default, so in the absence of a PT_GNU_STACK program header
4806 * we turn execute permission off.
4807 */
4808 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4809 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4810 +#define VM_STACK_DEFAULT_FLAGS32 \
4811 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4812 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4813
4814 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4815 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4816
4817 +#ifndef CONFIG_PAX_PAGEEXEC
4818 #define VM_STACK_DEFAULT_FLAGS \
4819 (is_32bit_task() ? \
4820 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4821 +#endif
4822
4823 #include <asm-generic/getorder.h>
4824
4825 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4826 index 292725c..f87ae14 100644
4827 --- a/arch/powerpc/include/asm/pgalloc-64.h
4828 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4829 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4830 #ifndef CONFIG_PPC_64K_PAGES
4831
4832 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4833 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4834
4835 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4836 {
4837 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4838 pud_set(pud, (unsigned long)pmd);
4839 }
4840
4841 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4842 +{
4843 + pud_populate(mm, pud, pmd);
4844 +}
4845 +
4846 #define pmd_populate(mm, pmd, pte_page) \
4847 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4848 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4849 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4850 #else /* CONFIG_PPC_64K_PAGES */
4851
4852 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4853 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4854
4855 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4856 pte_t *pte)
4857 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4858 index a9cbd3b..3b67efa 100644
4859 --- a/arch/powerpc/include/asm/pgtable.h
4860 +++ b/arch/powerpc/include/asm/pgtable.h
4861 @@ -2,6 +2,7 @@
4862 #define _ASM_POWERPC_PGTABLE_H
4863 #ifdef __KERNEL__
4864
4865 +#include <linux/const.h>
4866 #ifndef __ASSEMBLY__
4867 #include <asm/processor.h> /* For TASK_SIZE */
4868 #include <asm/mmu.h>
4869 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4870 index 4aad413..85d86bf 100644
4871 --- a/arch/powerpc/include/asm/pte-hash32.h
4872 +++ b/arch/powerpc/include/asm/pte-hash32.h
4873 @@ -21,6 +21,7 @@
4874 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4875 #define _PAGE_USER 0x004 /* usermode access allowed */
4876 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4877 +#define _PAGE_EXEC _PAGE_GUARDED
4878 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4879 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4880 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4881 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4882 index d24c141..b60696e 100644
4883 --- a/arch/powerpc/include/asm/reg.h
4884 +++ b/arch/powerpc/include/asm/reg.h
4885 @@ -215,6 +215,7 @@
4886 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4887 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4888 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4889 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4890 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4891 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4892 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4893 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4894 index 406b7b9..af63426 100644
4895 --- a/arch/powerpc/include/asm/thread_info.h
4896 +++ b/arch/powerpc/include/asm/thread_info.h
4897 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
4898 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
4899 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
4900 #define TIF_SINGLESTEP 8 /* singlestepping active */
4901 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
4902 #define TIF_SECCOMP 10 /* secure computing */
4903 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
4904 #define TIF_NOERROR 12 /* Force successful syscall return */
4905 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
4906 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
4907 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
4908 for stack store? */
4909 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
4910 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
4911 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
4912
4913 /* as above, but as bit values */
4914 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
4915 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
4916 #define _TIF_UPROBE (1<<TIF_UPROBE)
4917 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
4918 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
4919 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
4920 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
4921 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
4922 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
4923 + _TIF_GRSEC_SETXID)
4924
4925 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
4926 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
4927 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
4928 index 4db4959..335e00c 100644
4929 --- a/arch/powerpc/include/asm/uaccess.h
4930 +++ b/arch/powerpc/include/asm/uaccess.h
4931 @@ -13,6 +13,8 @@
4932 #define VERIFY_READ 0
4933 #define VERIFY_WRITE 1
4934
4935 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4936 +
4937 /*
4938 * The fs value determines whether argument validity checking should be
4939 * performed or not. If get_fs() == USER_DS, checking is performed, with
4940 @@ -318,52 +320,6 @@ do { \
4941 extern unsigned long __copy_tofrom_user(void __user *to,
4942 const void __user *from, unsigned long size);
4943
4944 -#ifndef __powerpc64__
4945 -
4946 -static inline unsigned long copy_from_user(void *to,
4947 - const void __user *from, unsigned long n)
4948 -{
4949 - unsigned long over;
4950 -
4951 - if (access_ok(VERIFY_READ, from, n))
4952 - return __copy_tofrom_user((__force void __user *)to, from, n);
4953 - if ((unsigned long)from < TASK_SIZE) {
4954 - over = (unsigned long)from + n - TASK_SIZE;
4955 - return __copy_tofrom_user((__force void __user *)to, from,
4956 - n - over) + over;
4957 - }
4958 - return n;
4959 -}
4960 -
4961 -static inline unsigned long copy_to_user(void __user *to,
4962 - const void *from, unsigned long n)
4963 -{
4964 - unsigned long over;
4965 -
4966 - if (access_ok(VERIFY_WRITE, to, n))
4967 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4968 - if ((unsigned long)to < TASK_SIZE) {
4969 - over = (unsigned long)to + n - TASK_SIZE;
4970 - return __copy_tofrom_user(to, (__force void __user *)from,
4971 - n - over) + over;
4972 - }
4973 - return n;
4974 -}
4975 -
4976 -#else /* __powerpc64__ */
4977 -
4978 -#define __copy_in_user(to, from, size) \
4979 - __copy_tofrom_user((to), (from), (size))
4980 -
4981 -extern unsigned long copy_from_user(void *to, const void __user *from,
4982 - unsigned long n);
4983 -extern unsigned long copy_to_user(void __user *to, const void *from,
4984 - unsigned long n);
4985 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4986 - unsigned long n);
4987 -
4988 -#endif /* __powerpc64__ */
4989 -
4990 static inline unsigned long __copy_from_user_inatomic(void *to,
4991 const void __user *from, unsigned long n)
4992 {
4993 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4994 if (ret == 0)
4995 return 0;
4996 }
4997 +
4998 + if (!__builtin_constant_p(n))
4999 + check_object_size(to, n, false);
5000 +
5001 return __copy_tofrom_user((__force void __user *)to, from, n);
5002 }
5003
5004 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5005 if (ret == 0)
5006 return 0;
5007 }
5008 +
5009 + if (!__builtin_constant_p(n))
5010 + check_object_size(from, n, true);
5011 +
5012 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5013 }
5014
5015 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5016 return __copy_to_user_inatomic(to, from, size);
5017 }
5018
5019 +#ifndef __powerpc64__
5020 +
5021 +static inline unsigned long __must_check copy_from_user(void *to,
5022 + const void __user *from, unsigned long n)
5023 +{
5024 + unsigned long over;
5025 +
5026 + if ((long)n < 0)
5027 + return n;
5028 +
5029 + if (access_ok(VERIFY_READ, from, n)) {
5030 + if (!__builtin_constant_p(n))
5031 + check_object_size(to, n, false);
5032 + return __copy_tofrom_user((__force void __user *)to, from, n);
5033 + }
5034 + if ((unsigned long)from < TASK_SIZE) {
5035 + over = (unsigned long)from + n - TASK_SIZE;
5036 + if (!__builtin_constant_p(n - over))
5037 + check_object_size(to, n - over, false);
5038 + return __copy_tofrom_user((__force void __user *)to, from,
5039 + n - over) + over;
5040 + }
5041 + return n;
5042 +}
5043 +
5044 +static inline unsigned long __must_check copy_to_user(void __user *to,
5045 + const void *from, unsigned long n)
5046 +{
5047 + unsigned long over;
5048 +
5049 + if ((long)n < 0)
5050 + return n;
5051 +
5052 + if (access_ok(VERIFY_WRITE, to, n)) {
5053 + if (!__builtin_constant_p(n))
5054 + check_object_size(from, n, true);
5055 + return __copy_tofrom_user(to, (__force void __user *)from, n);
5056 + }
5057 + if ((unsigned long)to < TASK_SIZE) {
5058 + over = (unsigned long)to + n - TASK_SIZE;
5059 + if (!__builtin_constant_p(n))
5060 + check_object_size(from, n - over, true);
5061 + return __copy_tofrom_user(to, (__force void __user *)from,
5062 + n - over) + over;
5063 + }
5064 + return n;
5065 +}
5066 +
5067 +#else /* __powerpc64__ */
5068 +
5069 +#define __copy_in_user(to, from, size) \
5070 + __copy_tofrom_user((to), (from), (size))
5071 +
5072 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5073 +{
5074 + if ((long)n < 0 || n > INT_MAX)
5075 + return n;
5076 +
5077 + if (!__builtin_constant_p(n))
5078 + check_object_size(to, n, false);
5079 +
5080 + if (likely(access_ok(VERIFY_READ, from, n)))
5081 + n = __copy_from_user(to, from, n);
5082 + else
5083 + memset(to, 0, n);
5084 + return n;
5085 +}
5086 +
5087 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5088 +{
5089 + if ((long)n < 0 || n > INT_MAX)
5090 + return n;
5091 +
5092 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
5093 + if (!__builtin_constant_p(n))
5094 + check_object_size(from, n, true);
5095 + n = __copy_to_user(to, from, n);
5096 + }
5097 + return n;
5098 +}
5099 +
5100 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
5101 + unsigned long n);
5102 +
5103 +#endif /* __powerpc64__ */
5104 +
5105 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5106
5107 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5108 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5109 index 4684e33..acc4d19e 100644
5110 --- a/arch/powerpc/kernel/exceptions-64e.S
5111 +++ b/arch/powerpc/kernel/exceptions-64e.S
5112 @@ -715,6 +715,7 @@ storage_fault_common:
5113 std r14,_DAR(r1)
5114 std r15,_DSISR(r1)
5115 addi r3,r1,STACK_FRAME_OVERHEAD
5116 + bl .save_nvgprs
5117 mr r4,r14
5118 mr r5,r15
5119 ld r14,PACA_EXGEN+EX_R14(r13)
5120 @@ -723,8 +724,7 @@ storage_fault_common:
5121 cmpdi r3,0
5122 bne- 1f
5123 b .ret_from_except_lite
5124 -1: bl .save_nvgprs
5125 - mr r5,r3
5126 +1: mr r5,r3
5127 addi r3,r1,STACK_FRAME_OVERHEAD
5128 ld r4,_DAR(r1)
5129 bl .bad_page_fault
5130 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5131 index 10b658a..e542888 100644
5132 --- a/arch/powerpc/kernel/exceptions-64s.S
5133 +++ b/arch/powerpc/kernel/exceptions-64s.S
5134 @@ -1013,10 +1013,10 @@ handle_page_fault:
5135 11: ld r4,_DAR(r1)
5136 ld r5,_DSISR(r1)
5137 addi r3,r1,STACK_FRAME_OVERHEAD
5138 + bl .save_nvgprs
5139 bl .do_page_fault
5140 cmpdi r3,0
5141 beq+ 12f
5142 - bl .save_nvgprs
5143 mr r5,r3
5144 addi r3,r1,STACK_FRAME_OVERHEAD
5145 lwz r4,_DAR(r1)
5146 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5147 index 2e3200c..72095ce 100644
5148 --- a/arch/powerpc/kernel/module_32.c
5149 +++ b/arch/powerpc/kernel/module_32.c
5150 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5151 me->arch.core_plt_section = i;
5152 }
5153 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5154 - printk("Module doesn't contain .plt or .init.plt sections.\n");
5155 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5156 return -ENOEXEC;
5157 }
5158
5159 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5160
5161 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5162 /* Init, or core PLT? */
5163 - if (location >= mod->module_core
5164 - && location < mod->module_core + mod->core_size)
5165 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5166 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5167 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5168 - else
5169 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5170 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5171 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5172 + else {
5173 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5174 + return ~0UL;
5175 + }
5176
5177 /* Find this entry, or if that fails, the next avail. entry */
5178 while (entry->jump[0]) {
5179 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5180 index ba48233..16ac31d 100644
5181 --- a/arch/powerpc/kernel/process.c
5182 +++ b/arch/powerpc/kernel/process.c
5183 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5184 * Lookup NIP late so we have the best change of getting the
5185 * above info out without failing
5186 */
5187 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5188 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5189 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5190 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5191 #endif
5192 show_stack(current, (unsigned long *) regs->gpr[1]);
5193 if (!user_mode(regs))
5194 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5195 newsp = stack[0];
5196 ip = stack[STACK_FRAME_LR_SAVE];
5197 if (!firstframe || ip != lr) {
5198 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5199 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5200 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5201 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5202 - printk(" (%pS)",
5203 + printk(" (%pA)",
5204 (void *)current->ret_stack[curr_frame].ret);
5205 curr_frame--;
5206 }
5207 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5208 struct pt_regs *regs = (struct pt_regs *)
5209 (sp + STACK_FRAME_OVERHEAD);
5210 lr = regs->link;
5211 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5212 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5213 regs->trap, (void *)regs->nip, (void *)lr);
5214 firstframe = 1;
5215 }
5216 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5217 mtspr(SPRN_CTRLT, ctrl);
5218 }
5219 #endif /* CONFIG_PPC64 */
5220 -
5221 -unsigned long arch_align_stack(unsigned long sp)
5222 -{
5223 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5224 - sp -= get_random_int() & ~PAGE_MASK;
5225 - return sp & ~0xf;
5226 -}
5227 -
5228 -static inline unsigned long brk_rnd(void)
5229 -{
5230 - unsigned long rnd = 0;
5231 -
5232 - /* 8MB for 32bit, 1GB for 64bit */
5233 - if (is_32bit_task())
5234 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5235 - else
5236 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5237 -
5238 - return rnd << PAGE_SHIFT;
5239 -}
5240 -
5241 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5242 -{
5243 - unsigned long base = mm->brk;
5244 - unsigned long ret;
5245 -
5246 -#ifdef CONFIG_PPC_STD_MMU_64
5247 - /*
5248 - * If we are using 1TB segments and we are allowed to randomise
5249 - * the heap, we can put it above 1TB so it is backed by a 1TB
5250 - * segment. Otherwise the heap will be in the bottom 1TB
5251 - * which always uses 256MB segments and this may result in a
5252 - * performance penalty.
5253 - */
5254 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5255 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5256 -#endif
5257 -
5258 - ret = PAGE_ALIGN(base + brk_rnd());
5259 -
5260 - if (ret < mm->brk)
5261 - return mm->brk;
5262 -
5263 - return ret;
5264 -}
5265 -
5266 -unsigned long randomize_et_dyn(unsigned long base)
5267 -{
5268 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5269 -
5270 - if (ret < base)
5271 - return base;
5272 -
5273 - return ret;
5274 -}
5275 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5276 index 79d8e56..38ffcbb 100644
5277 --- a/arch/powerpc/kernel/ptrace.c
5278 +++ b/arch/powerpc/kernel/ptrace.c
5279 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5280 return ret;
5281 }
5282
5283 +#ifdef CONFIG_GRKERNSEC_SETXID
5284 +extern void gr_delayed_cred_worker(void);
5285 +#endif
5286 +
5287 /*
5288 * We must return the syscall number to actually look up in the table.
5289 * This can be -1L to skip running any syscall at all.
5290 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5291
5292 secure_computing_strict(regs->gpr[0]);
5293
5294 +#ifdef CONFIG_GRKERNSEC_SETXID
5295 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5296 + gr_delayed_cred_worker();
5297 +#endif
5298 +
5299 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5300 tracehook_report_syscall_entry(regs))
5301 /*
5302 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5303 {
5304 int step;
5305
5306 +#ifdef CONFIG_GRKERNSEC_SETXID
5307 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5308 + gr_delayed_cred_worker();
5309 +#endif
5310 +
5311 audit_syscall_exit(regs);
5312
5313 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5314 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5315 index 804e323..79181c1 100644
5316 --- a/arch/powerpc/kernel/signal_32.c
5317 +++ b/arch/powerpc/kernel/signal_32.c
5318 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5319 /* Save user registers on the stack */
5320 frame = &rt_sf->uc.uc_mcontext;
5321 addr = frame;
5322 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5323 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5324 if (save_user_regs(regs, frame, 0, 1))
5325 goto badframe;
5326 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5327 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5328 index d183f87..1867f1a 100644
5329 --- a/arch/powerpc/kernel/signal_64.c
5330 +++ b/arch/powerpc/kernel/signal_64.c
5331 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5332 current->thread.fpscr.val = 0;
5333
5334 /* Set up to return from userspace. */
5335 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5336 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5337 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5338 } else {
5339 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5340 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5341 index 3251840..3f7c77a 100644
5342 --- a/arch/powerpc/kernel/traps.c
5343 +++ b/arch/powerpc/kernel/traps.c
5344 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5345 return flags;
5346 }
5347
5348 +extern void gr_handle_kernel_exploit(void);
5349 +
5350 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5351 int signr)
5352 {
5353 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5354 panic("Fatal exception in interrupt");
5355 if (panic_on_oops)
5356 panic("Fatal exception");
5357 +
5358 + gr_handle_kernel_exploit();
5359 +
5360 do_exit(signr);
5361 }
5362
5363 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5364 index 1b2076f..835e4be 100644
5365 --- a/arch/powerpc/kernel/vdso.c
5366 +++ b/arch/powerpc/kernel/vdso.c
5367 @@ -34,6 +34,7 @@
5368 #include <asm/firmware.h>
5369 #include <asm/vdso.h>
5370 #include <asm/vdso_datapage.h>
5371 +#include <asm/mman.h>
5372
5373 #include "setup.h"
5374
5375 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5376 vdso_base = VDSO32_MBASE;
5377 #endif
5378
5379 - current->mm->context.vdso_base = 0;
5380 + current->mm->context.vdso_base = ~0UL;
5381
5382 /* vDSO has a problem and was disabled, just don't "enable" it for the
5383 * process
5384 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5385 vdso_base = get_unmapped_area(NULL, vdso_base,
5386 (vdso_pages << PAGE_SHIFT) +
5387 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5388 - 0, 0);
5389 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5390 if (IS_ERR_VALUE(vdso_base)) {
5391 rc = vdso_base;
5392 goto fail_mmapsem;
5393 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5394 index 5eea6f3..5d10396 100644
5395 --- a/arch/powerpc/lib/usercopy_64.c
5396 +++ b/arch/powerpc/lib/usercopy_64.c
5397 @@ -9,22 +9,6 @@
5398 #include <linux/module.h>
5399 #include <asm/uaccess.h>
5400
5401 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5402 -{
5403 - if (likely(access_ok(VERIFY_READ, from, n)))
5404 - n = __copy_from_user(to, from, n);
5405 - else
5406 - memset(to, 0, n);
5407 - return n;
5408 -}
5409 -
5410 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5411 -{
5412 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5413 - n = __copy_to_user(to, from, n);
5414 - return n;
5415 -}
5416 -
5417 unsigned long copy_in_user(void __user *to, const void __user *from,
5418 unsigned long n)
5419 {
5420 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5421 return n;
5422 }
5423
5424 -EXPORT_SYMBOL(copy_from_user);
5425 -EXPORT_SYMBOL(copy_to_user);
5426 EXPORT_SYMBOL(copy_in_user);
5427
5428 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5429 index 0a6b283..7674925 100644
5430 --- a/arch/powerpc/mm/fault.c
5431 +++ b/arch/powerpc/mm/fault.c
5432 @@ -32,6 +32,10 @@
5433 #include <linux/perf_event.h>
5434 #include <linux/magic.h>
5435 #include <linux/ratelimit.h>
5436 +#include <linux/slab.h>
5437 +#include <linux/pagemap.h>
5438 +#include <linux/compiler.h>
5439 +#include <linux/unistd.h>
5440
5441 #include <asm/firmware.h>
5442 #include <asm/page.h>
5443 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5444 }
5445 #endif
5446
5447 +#ifdef CONFIG_PAX_PAGEEXEC
5448 +/*
5449 + * PaX: decide what to do with offenders (regs->nip = fault address)
5450 + *
5451 + * returns 1 when task should be killed
5452 + */
5453 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5454 +{
5455 + return 1;
5456 +}
5457 +
5458 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5459 +{
5460 + unsigned long i;
5461 +
5462 + printk(KERN_ERR "PAX: bytes at PC: ");
5463 + for (i = 0; i < 5; i++) {
5464 + unsigned int c;
5465 + if (get_user(c, (unsigned int __user *)pc+i))
5466 + printk(KERN_CONT "???????? ");
5467 + else
5468 + printk(KERN_CONT "%08x ", c);
5469 + }
5470 + printk("\n");
5471 +}
5472 +#endif
5473 +
5474 /*
5475 * Check whether the instruction at regs->nip is a store using
5476 * an update addressing form which will update r1.
5477 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5478 * indicate errors in DSISR but can validly be set in SRR1.
5479 */
5480 if (trap == 0x400)
5481 - error_code &= 0x48200000;
5482 + error_code &= 0x58200000;
5483 else
5484 is_write = error_code & DSISR_ISSTORE;
5485 #else
5486 @@ -367,7 +398,7 @@ good_area:
5487 * "undefined". Of those that can be set, this is the only
5488 * one which seems bad.
5489 */
5490 - if (error_code & 0x10000000)
5491 + if (error_code & DSISR_GUARDED)
5492 /* Guarded storage error. */
5493 goto bad_area;
5494 #endif /* CONFIG_8xx */
5495 @@ -382,7 +413,7 @@ good_area:
5496 * processors use the same I/D cache coherency mechanism
5497 * as embedded.
5498 */
5499 - if (error_code & DSISR_PROTFAULT)
5500 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5501 goto bad_area;
5502 #endif /* CONFIG_PPC_STD_MMU */
5503
5504 @@ -465,6 +496,23 @@ bad_area:
5505 bad_area_nosemaphore:
5506 /* User mode accesses cause a SIGSEGV */
5507 if (user_mode(regs)) {
5508 +
5509 +#ifdef CONFIG_PAX_PAGEEXEC
5510 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5511 +#ifdef CONFIG_PPC_STD_MMU
5512 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5513 +#else
5514 + if (is_exec && regs->nip == address) {
5515 +#endif
5516 + switch (pax_handle_fetch_fault(regs)) {
5517 + }
5518 +
5519 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5520 + do_group_exit(SIGKILL);
5521 + }
5522 + }
5523 +#endif
5524 +
5525 _exception(SIGSEGV, regs, code, address);
5526 return 0;
5527 }
5528 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5529 index 67a42ed..1c7210c 100644
5530 --- a/arch/powerpc/mm/mmap_64.c
5531 +++ b/arch/powerpc/mm/mmap_64.c
5532 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5533 */
5534 if (mmap_is_legacy()) {
5535 mm->mmap_base = TASK_UNMAPPED_BASE;
5536 +
5537 +#ifdef CONFIG_PAX_RANDMMAP
5538 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5539 + mm->mmap_base += mm->delta_mmap;
5540 +#endif
5541 +
5542 mm->get_unmapped_area = arch_get_unmapped_area;
5543 mm->unmap_area = arch_unmap_area;
5544 } else {
5545 mm->mmap_base = mmap_base();
5546 +
5547 +#ifdef CONFIG_PAX_RANDMMAP
5548 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5549 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5550 +#endif
5551 +
5552 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5553 mm->unmap_area = arch_unmap_area_topdown;
5554 }
5555 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5556 index 5829d2a..af84242 100644
5557 --- a/arch/powerpc/mm/slice.c
5558 +++ b/arch/powerpc/mm/slice.c
5559 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5560 if ((mm->task_size - len) < addr)
5561 return 0;
5562 vma = find_vma(mm, addr);
5563 - return (!vma || (addr + len) <= vma->vm_start);
5564 + return check_heap_stack_gap(vma, addr, len, 0);
5565 }
5566
5567 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5568 @@ -272,7 +272,7 @@ full_search:
5569 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5570 continue;
5571 }
5572 - if (!vma || addr + len <= vma->vm_start) {
5573 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5574 /*
5575 * Remember the place where we stopped the search:
5576 */
5577 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5578 }
5579 }
5580
5581 - addr = mm->mmap_base;
5582 - while (addr > len) {
5583 + if (mm->mmap_base < len)
5584 + addr = -ENOMEM;
5585 + else
5586 + addr = mm->mmap_base - len;
5587 +
5588 + while (!IS_ERR_VALUE(addr)) {
5589 /* Go down by chunk size */
5590 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5591 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5592
5593 /* Check for hit with different page size */
5594 mask = slice_range_to_mask(addr, len);
5595 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5596 * return with success:
5597 */
5598 vma = find_vma(mm, addr);
5599 - if (!vma || (addr + len) <= vma->vm_start) {
5600 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5601 /* remember the address as a hint for next time */
5602 if (use_cache)
5603 mm->free_area_cache = addr;
5604 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5605 mm->cached_hole_size = vma->vm_start - addr;
5606
5607 /* try just below the current vma->vm_start */
5608 - addr = vma->vm_start;
5609 + addr = skip_heap_stack_gap(vma, len, 0);
5610 }
5611
5612 /*
5613 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5614 if (fixed && addr > (mm->task_size - len))
5615 return -EINVAL;
5616
5617 +#ifdef CONFIG_PAX_RANDMMAP
5618 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5619 + addr = 0;
5620 +#endif
5621 +
5622 /* If hint, make sure it matches our alignment restrictions */
5623 if (!fixed && addr) {
5624 addr = _ALIGN_UP(addr, 1ul << pshift);
5625 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5626 index c797832..ce575c8 100644
5627 --- a/arch/s390/include/asm/atomic.h
5628 +++ b/arch/s390/include/asm/atomic.h
5629 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5630 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5631 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5632
5633 +#define atomic64_read_unchecked(v) atomic64_read(v)
5634 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5635 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5636 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5637 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5638 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5639 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5640 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5641 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5642 +
5643 #define smp_mb__before_atomic_dec() smp_mb()
5644 #define smp_mb__after_atomic_dec() smp_mb()
5645 #define smp_mb__before_atomic_inc() smp_mb()
5646 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5647 index 4d7ccac..d03d0ad 100644
5648 --- a/arch/s390/include/asm/cache.h
5649 +++ b/arch/s390/include/asm/cache.h
5650 @@ -9,8 +9,10 @@
5651 #ifndef __ARCH_S390_CACHE_H
5652 #define __ARCH_S390_CACHE_H
5653
5654 -#define L1_CACHE_BYTES 256
5655 +#include <linux/const.h>
5656 +
5657 #define L1_CACHE_SHIFT 8
5658 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5659 #define NET_SKB_PAD 32
5660
5661 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5662 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5663 index 178ff96..8c93bd1 100644
5664 --- a/arch/s390/include/asm/elf.h
5665 +++ b/arch/s390/include/asm/elf.h
5666 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5667 the loader. We need to make sure that it is out of the way of the program
5668 that it will "exec", and that there is sufficient room for the brk. */
5669
5670 -extern unsigned long randomize_et_dyn(unsigned long base);
5671 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5672 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5673 +
5674 +#ifdef CONFIG_PAX_ASLR
5675 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5676 +
5677 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5678 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5679 +#endif
5680
5681 /* This yields a mask that user programs can use to figure out what
5682 instruction set this CPU supports. */
5683 @@ -210,9 +216,6 @@ struct linux_binprm;
5684 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5685 int arch_setup_additional_pages(struct linux_binprm *, int);
5686
5687 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5688 -#define arch_randomize_brk arch_randomize_brk
5689 -
5690 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5691
5692 #endif
5693 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5694 index c4a93d6..4d2a9b4 100644
5695 --- a/arch/s390/include/asm/exec.h
5696 +++ b/arch/s390/include/asm/exec.h
5697 @@ -7,6 +7,6 @@
5698 #ifndef __ASM_EXEC_H
5699 #define __ASM_EXEC_H
5700
5701 -extern unsigned long arch_align_stack(unsigned long sp);
5702 +#define arch_align_stack(x) ((x) & ~0xfUL)
5703
5704 #endif /* __ASM_EXEC_H */
5705 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5706 index 34268df..ea97318 100644
5707 --- a/arch/s390/include/asm/uaccess.h
5708 +++ b/arch/s390/include/asm/uaccess.h
5709 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5710 copy_to_user(void __user *to, const void *from, unsigned long n)
5711 {
5712 might_fault();
5713 +
5714 + if ((long)n < 0)
5715 + return n;
5716 +
5717 if (access_ok(VERIFY_WRITE, to, n))
5718 n = __copy_to_user(to, from, n);
5719 return n;
5720 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5721 static inline unsigned long __must_check
5722 __copy_from_user(void *to, const void __user *from, unsigned long n)
5723 {
5724 + if ((long)n < 0)
5725 + return n;
5726 +
5727 if (__builtin_constant_p(n) && (n <= 256))
5728 return uaccess.copy_from_user_small(n, from, to);
5729 else
5730 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5731 static inline unsigned long __must_check
5732 copy_from_user(void *to, const void __user *from, unsigned long n)
5733 {
5734 - unsigned int sz = __compiletime_object_size(to);
5735 + size_t sz = __compiletime_object_size(to);
5736
5737 might_fault();
5738 - if (unlikely(sz != -1 && sz < n)) {
5739 +
5740 + if ((long)n < 0)
5741 + return n;
5742 +
5743 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5744 copy_from_user_overflow();
5745 return n;
5746 }
5747 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5748 index 4610dea..cf0af21 100644
5749 --- a/arch/s390/kernel/module.c
5750 +++ b/arch/s390/kernel/module.c
5751 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5752
5753 /* Increase core size by size of got & plt and set start
5754 offsets for got and plt. */
5755 - me->core_size = ALIGN(me->core_size, 4);
5756 - me->arch.got_offset = me->core_size;
5757 - me->core_size += me->arch.got_size;
5758 - me->arch.plt_offset = me->core_size;
5759 - me->core_size += me->arch.plt_size;
5760 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5761 + me->arch.got_offset = me->core_size_rw;
5762 + me->core_size_rw += me->arch.got_size;
5763 + me->arch.plt_offset = me->core_size_rx;
5764 + me->core_size_rx += me->arch.plt_size;
5765 return 0;
5766 }
5767
5768 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5769 if (info->got_initialized == 0) {
5770 Elf_Addr *gotent;
5771
5772 - gotent = me->module_core + me->arch.got_offset +
5773 + gotent = me->module_core_rw + me->arch.got_offset +
5774 info->got_offset;
5775 *gotent = val;
5776 info->got_initialized = 1;
5777 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5778 else if (r_type == R_390_GOTENT ||
5779 r_type == R_390_GOTPLTENT)
5780 *(unsigned int *) loc =
5781 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5782 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5783 else if (r_type == R_390_GOT64 ||
5784 r_type == R_390_GOTPLT64)
5785 *(unsigned long *) loc = val;
5786 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5787 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5788 if (info->plt_initialized == 0) {
5789 unsigned int *ip;
5790 - ip = me->module_core + me->arch.plt_offset +
5791 + ip = me->module_core_rx + me->arch.plt_offset +
5792 info->plt_offset;
5793 #ifndef CONFIG_64BIT
5794 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5795 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5796 val - loc + 0xffffUL < 0x1ffffeUL) ||
5797 (r_type == R_390_PLT32DBL &&
5798 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5799 - val = (Elf_Addr) me->module_core +
5800 + val = (Elf_Addr) me->module_core_rx +
5801 me->arch.plt_offset +
5802 info->plt_offset;
5803 val += rela->r_addend - loc;
5804 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5805 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5806 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5807 val = val + rela->r_addend -
5808 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5809 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5810 if (r_type == R_390_GOTOFF16)
5811 *(unsigned short *) loc = val;
5812 else if (r_type == R_390_GOTOFF32)
5813 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5814 break;
5815 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5816 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5817 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5818 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5819 rela->r_addend - loc;
5820 if (r_type == R_390_GOTPC)
5821 *(unsigned int *) loc = val;
5822 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5823 index cd31ad4..201c5a3 100644
5824 --- a/arch/s390/kernel/process.c
5825 +++ b/arch/s390/kernel/process.c
5826 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5827 }
5828 return 0;
5829 }
5830 -
5831 -unsigned long arch_align_stack(unsigned long sp)
5832 -{
5833 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5834 - sp -= get_random_int() & ~PAGE_MASK;
5835 - return sp & ~0xf;
5836 -}
5837 -
5838 -static inline unsigned long brk_rnd(void)
5839 -{
5840 - /* 8MB for 32bit, 1GB for 64bit */
5841 - if (is_32bit_task())
5842 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5843 - else
5844 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5845 -}
5846 -
5847 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5848 -{
5849 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5850 -
5851 - if (ret < mm->brk)
5852 - return mm->brk;
5853 - return ret;
5854 -}
5855 -
5856 -unsigned long randomize_et_dyn(unsigned long base)
5857 -{
5858 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5859 -
5860 - if (!(current->flags & PF_RANDOMIZE))
5861 - return base;
5862 - if (ret < base)
5863 - return base;
5864 - return ret;
5865 -}
5866 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5867 index c59a5ef..3fae59c 100644
5868 --- a/arch/s390/mm/mmap.c
5869 +++ b/arch/s390/mm/mmap.c
5870 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5871 */
5872 if (mmap_is_legacy()) {
5873 mm->mmap_base = TASK_UNMAPPED_BASE;
5874 +
5875 +#ifdef CONFIG_PAX_RANDMMAP
5876 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5877 + mm->mmap_base += mm->delta_mmap;
5878 +#endif
5879 +
5880 mm->get_unmapped_area = arch_get_unmapped_area;
5881 mm->unmap_area = arch_unmap_area;
5882 } else {
5883 mm->mmap_base = mmap_base();
5884 +
5885 +#ifdef CONFIG_PAX_RANDMMAP
5886 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5887 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5888 +#endif
5889 +
5890 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5891 mm->unmap_area = arch_unmap_area_topdown;
5892 }
5893 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5894 */
5895 if (mmap_is_legacy()) {
5896 mm->mmap_base = TASK_UNMAPPED_BASE;
5897 +
5898 +#ifdef CONFIG_PAX_RANDMMAP
5899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5900 + mm->mmap_base += mm->delta_mmap;
5901 +#endif
5902 +
5903 mm->get_unmapped_area = s390_get_unmapped_area;
5904 mm->unmap_area = arch_unmap_area;
5905 } else {
5906 mm->mmap_base = mmap_base();
5907 +
5908 +#ifdef CONFIG_PAX_RANDMMAP
5909 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5910 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5911 +#endif
5912 +
5913 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
5914 mm->unmap_area = arch_unmap_area_topdown;
5915 }
5916 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
5917 index ae3d59f..f65f075 100644
5918 --- a/arch/score/include/asm/cache.h
5919 +++ b/arch/score/include/asm/cache.h
5920 @@ -1,7 +1,9 @@
5921 #ifndef _ASM_SCORE_CACHE_H
5922 #define _ASM_SCORE_CACHE_H
5923
5924 +#include <linux/const.h>
5925 +
5926 #define L1_CACHE_SHIFT 4
5927 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5928 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5929
5930 #endif /* _ASM_SCORE_CACHE_H */
5931 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5932 index f9f3cd5..58ff438 100644
5933 --- a/arch/score/include/asm/exec.h
5934 +++ b/arch/score/include/asm/exec.h
5935 @@ -1,6 +1,6 @@
5936 #ifndef _ASM_SCORE_EXEC_H
5937 #define _ASM_SCORE_EXEC_H
5938
5939 -extern unsigned long arch_align_stack(unsigned long sp);
5940 +#define arch_align_stack(x) (x)
5941
5942 #endif /* _ASM_SCORE_EXEC_H */
5943 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5944 index 637970c..0b6556b 100644
5945 --- a/arch/score/kernel/process.c
5946 +++ b/arch/score/kernel/process.c
5947 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5948
5949 return task_pt_regs(task)->cp0_epc;
5950 }
5951 -
5952 -unsigned long arch_align_stack(unsigned long sp)
5953 -{
5954 - return sp;
5955 -}
5956 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5957 index ef9e555..331bd29 100644
5958 --- a/arch/sh/include/asm/cache.h
5959 +++ b/arch/sh/include/asm/cache.h
5960 @@ -9,10 +9,11 @@
5961 #define __ASM_SH_CACHE_H
5962 #ifdef __KERNEL__
5963
5964 +#include <linux/const.h>
5965 #include <linux/init.h>
5966 #include <cpu/cache.h>
5967
5968 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5969 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5970
5971 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5972
5973 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5974 index afeb710..e8366ef 100644
5975 --- a/arch/sh/mm/mmap.c
5976 +++ b/arch/sh/mm/mmap.c
5977 @@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5978 struct vm_area_struct *vma;
5979 unsigned long start_addr;
5980 int do_colour_align;
5981 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5982
5983 if (flags & MAP_FIXED) {
5984 /* We do not accept a shared mapping if it would violate
5985 @@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5986 addr = PAGE_ALIGN(addr);
5987
5988 vma = find_vma(mm, addr);
5989 - if (TASK_SIZE - len >= addr &&
5990 - (!vma || addr + len <= vma->vm_start))
5991 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5992 return addr;
5993 }
5994
5995 @@ -106,7 +106,7 @@ full_search:
5996 }
5997 return -ENOMEM;
5998 }
5999 - if (likely(!vma || addr + len <= vma->vm_start)) {
6000 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6001 /*
6002 * Remember the place where we stopped the search:
6003 */
6004 @@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6005 struct mm_struct *mm = current->mm;
6006 unsigned long addr = addr0;
6007 int do_colour_align;
6008 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6009
6010 if (flags & MAP_FIXED) {
6011 /* We do not accept a shared mapping if it would violate
6012 @@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6013 addr = PAGE_ALIGN(addr);
6014
6015 vma = find_vma(mm, addr);
6016 - if (TASK_SIZE - len >= addr &&
6017 - (!vma || addr + len <= vma->vm_start))
6018 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6019 return addr;
6020 }
6021
6022 @@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6023 /* make sure it can fit in the remaining address space */
6024 if (likely(addr > len)) {
6025 vma = find_vma(mm, addr-len);
6026 - if (!vma || addr <= vma->vm_start) {
6027 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6028 /* remember the address as a hint for next time */
6029 return (mm->free_area_cache = addr-len);
6030 }
6031 @@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6032 if (unlikely(mm->mmap_base < len))
6033 goto bottomup;
6034
6035 - addr = mm->mmap_base-len;
6036 - if (do_colour_align)
6037 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6038 + addr = mm->mmap_base - len;
6039
6040 do {
6041 + if (do_colour_align)
6042 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6043 /*
6044 * Lookup failure means no vma is above this address,
6045 * else if new region fits below vma->vm_start,
6046 * return with success:
6047 */
6048 vma = find_vma(mm, addr);
6049 - if (likely(!vma || addr+len <= vma->vm_start)) {
6050 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6051 /* remember the address as a hint for next time */
6052 return (mm->free_area_cache = addr);
6053 }
6054 @@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6055 mm->cached_hole_size = vma->vm_start - addr;
6056
6057 /* try just below the current vma->vm_start */
6058 - addr = vma->vm_start-len;
6059 - if (do_colour_align)
6060 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6061 - } while (likely(len < vma->vm_start));
6062 + addr = skip_heap_stack_gap(vma, len, offset);
6063 + } while (!IS_ERR_VALUE(addr));
6064
6065 bottomup:
6066 /*
6067 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6068 index be56a24..443328f 100644
6069 --- a/arch/sparc/include/asm/atomic_64.h
6070 +++ b/arch/sparc/include/asm/atomic_64.h
6071 @@ -14,18 +14,40 @@
6072 #define ATOMIC64_INIT(i) { (i) }
6073
6074 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6075 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6076 +{
6077 + return v->counter;
6078 +}
6079 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6080 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6081 +{
6082 + return v->counter;
6083 +}
6084
6085 #define atomic_set(v, i) (((v)->counter) = i)
6086 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6087 +{
6088 + v->counter = i;
6089 +}
6090 #define atomic64_set(v, i) (((v)->counter) = i)
6091 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6092 +{
6093 + v->counter = i;
6094 +}
6095
6096 extern void atomic_add(int, atomic_t *);
6097 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6098 extern void atomic64_add(long, atomic64_t *);
6099 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6100 extern void atomic_sub(int, atomic_t *);
6101 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6102 extern void atomic64_sub(long, atomic64_t *);
6103 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6104
6105 extern int atomic_add_ret(int, atomic_t *);
6106 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6107 extern long atomic64_add_ret(long, atomic64_t *);
6108 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6109 extern int atomic_sub_ret(int, atomic_t *);
6110 extern long atomic64_sub_ret(long, atomic64_t *);
6111
6112 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6113 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6114
6115 #define atomic_inc_return(v) atomic_add_ret(1, v)
6116 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6117 +{
6118 + return atomic_add_ret_unchecked(1, v);
6119 +}
6120 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6121 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6122 +{
6123 + return atomic64_add_ret_unchecked(1, v);
6124 +}
6125
6126 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6127 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6128
6129 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6130 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6131 +{
6132 + return atomic_add_ret_unchecked(i, v);
6133 +}
6134 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6135 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6136 +{
6137 + return atomic64_add_ret_unchecked(i, v);
6138 +}
6139
6140 /*
6141 * atomic_inc_and_test - increment and test
6142 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6143 * other cases.
6144 */
6145 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6146 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6147 +{
6148 + return atomic_inc_return_unchecked(v) == 0;
6149 +}
6150 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6151
6152 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6153 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6154 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6155
6156 #define atomic_inc(v) atomic_add(1, v)
6157 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6158 +{
6159 + atomic_add_unchecked(1, v);
6160 +}
6161 #define atomic64_inc(v) atomic64_add(1, v)
6162 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6163 +{
6164 + atomic64_add_unchecked(1, v);
6165 +}
6166
6167 #define atomic_dec(v) atomic_sub(1, v)
6168 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6169 +{
6170 + atomic_sub_unchecked(1, v);
6171 +}
6172 #define atomic64_dec(v) atomic64_sub(1, v)
6173 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6174 +{
6175 + atomic64_sub_unchecked(1, v);
6176 +}
6177
6178 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6179 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6180
6181 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6182 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6183 +{
6184 + return cmpxchg(&v->counter, old, new);
6185 +}
6186 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6187 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6188 +{
6189 + return xchg(&v->counter, new);
6190 +}
6191
6192 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6193 {
6194 - int c, old;
6195 + int c, old, new;
6196 c = atomic_read(v);
6197 for (;;) {
6198 - if (unlikely(c == (u)))
6199 + if (unlikely(c == u))
6200 break;
6201 - old = atomic_cmpxchg((v), c, c + (a));
6202 +
6203 + asm volatile("addcc %2, %0, %0\n"
6204 +
6205 +#ifdef CONFIG_PAX_REFCOUNT
6206 + "tvs %%icc, 6\n"
6207 +#endif
6208 +
6209 + : "=r" (new)
6210 + : "0" (c), "ir" (a)
6211 + : "cc");
6212 +
6213 + old = atomic_cmpxchg(v, c, new);
6214 if (likely(old == c))
6215 break;
6216 c = old;
6217 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6218 #define atomic64_cmpxchg(v, o, n) \
6219 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6220 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6221 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6222 +{
6223 + return xchg(&v->counter, new);
6224 +}
6225
6226 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6227 {
6228 - long c, old;
6229 + long c, old, new;
6230 c = atomic64_read(v);
6231 for (;;) {
6232 - if (unlikely(c == (u)))
6233 + if (unlikely(c == u))
6234 break;
6235 - old = atomic64_cmpxchg((v), c, c + (a));
6236 +
6237 + asm volatile("addcc %2, %0, %0\n"
6238 +
6239 +#ifdef CONFIG_PAX_REFCOUNT
6240 + "tvs %%xcc, 6\n"
6241 +#endif
6242 +
6243 + : "=r" (new)
6244 + : "0" (c), "ir" (a)
6245 + : "cc");
6246 +
6247 + old = atomic64_cmpxchg(v, c, new);
6248 if (likely(old == c))
6249 break;
6250 c = old;
6251 }
6252 - return c != (u);
6253 + return c != u;
6254 }
6255
6256 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6257 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6258 index 5bb6991..5c2132e 100644
6259 --- a/arch/sparc/include/asm/cache.h
6260 +++ b/arch/sparc/include/asm/cache.h
6261 @@ -7,10 +7,12 @@
6262 #ifndef _SPARC_CACHE_H
6263 #define _SPARC_CACHE_H
6264
6265 +#include <linux/const.h>
6266 +
6267 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6268
6269 #define L1_CACHE_SHIFT 5
6270 -#define L1_CACHE_BYTES 32
6271 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6272
6273 #ifdef CONFIG_SPARC32
6274 #define SMP_CACHE_BYTES_SHIFT 5
6275 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6276 index ac74a2c..a9e58af 100644
6277 --- a/arch/sparc/include/asm/elf_32.h
6278 +++ b/arch/sparc/include/asm/elf_32.h
6279 @@ -114,6 +114,13 @@ typedef struct {
6280
6281 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6282
6283 +#ifdef CONFIG_PAX_ASLR
6284 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6285 +
6286 +#define PAX_DELTA_MMAP_LEN 16
6287 +#define PAX_DELTA_STACK_LEN 16
6288 +#endif
6289 +
6290 /* This yields a mask that user programs can use to figure out what
6291 instruction set this cpu supports. This can NOT be done in userspace
6292 on Sparc. */
6293 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6294 index 370ca1e..d4f4a98 100644
6295 --- a/arch/sparc/include/asm/elf_64.h
6296 +++ b/arch/sparc/include/asm/elf_64.h
6297 @@ -189,6 +189,13 @@ typedef struct {
6298 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6299 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6300
6301 +#ifdef CONFIG_PAX_ASLR
6302 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6303 +
6304 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6305 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6306 +#endif
6307 +
6308 extern unsigned long sparc64_elf_hwcap;
6309 #define ELF_HWCAP sparc64_elf_hwcap
6310
6311 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6312 index 9b1c36d..209298b 100644
6313 --- a/arch/sparc/include/asm/pgalloc_32.h
6314 +++ b/arch/sparc/include/asm/pgalloc_32.h
6315 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6316 }
6317
6318 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6319 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6320
6321 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6322 unsigned long address)
6323 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6324 index bcfe063..b333142 100644
6325 --- a/arch/sparc/include/asm/pgalloc_64.h
6326 +++ b/arch/sparc/include/asm/pgalloc_64.h
6327 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6328 }
6329
6330 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6331 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6332
6333 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6334 {
6335 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6336 index 6fc1348..390c50a 100644
6337 --- a/arch/sparc/include/asm/pgtable_32.h
6338 +++ b/arch/sparc/include/asm/pgtable_32.h
6339 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6340 #define PAGE_SHARED SRMMU_PAGE_SHARED
6341 #define PAGE_COPY SRMMU_PAGE_COPY
6342 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6343 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6344 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6345 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6346 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6347
6348 /* Top-level page directory - dummy used by init-mm.
6349 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6350
6351 /* xwr */
6352 #define __P000 PAGE_NONE
6353 -#define __P001 PAGE_READONLY
6354 -#define __P010 PAGE_COPY
6355 -#define __P011 PAGE_COPY
6356 +#define __P001 PAGE_READONLY_NOEXEC
6357 +#define __P010 PAGE_COPY_NOEXEC
6358 +#define __P011 PAGE_COPY_NOEXEC
6359 #define __P100 PAGE_READONLY
6360 #define __P101 PAGE_READONLY
6361 #define __P110 PAGE_COPY
6362 #define __P111 PAGE_COPY
6363
6364 #define __S000 PAGE_NONE
6365 -#define __S001 PAGE_READONLY
6366 -#define __S010 PAGE_SHARED
6367 -#define __S011 PAGE_SHARED
6368 +#define __S001 PAGE_READONLY_NOEXEC
6369 +#define __S010 PAGE_SHARED_NOEXEC
6370 +#define __S011 PAGE_SHARED_NOEXEC
6371 #define __S100 PAGE_READONLY
6372 #define __S101 PAGE_READONLY
6373 #define __S110 PAGE_SHARED
6374 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6375 index 79da178..c2eede8 100644
6376 --- a/arch/sparc/include/asm/pgtsrmmu.h
6377 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6378 @@ -115,6 +115,11 @@
6379 SRMMU_EXEC | SRMMU_REF)
6380 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6381 SRMMU_EXEC | SRMMU_REF)
6382 +
6383 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6384 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6385 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6386 +
6387 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6388 SRMMU_DIRTY | SRMMU_REF)
6389
6390 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6391 index 9689176..63c18ea 100644
6392 --- a/arch/sparc/include/asm/spinlock_64.h
6393 +++ b/arch/sparc/include/asm/spinlock_64.h
6394 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6395
6396 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6397
6398 -static void inline arch_read_lock(arch_rwlock_t *lock)
6399 +static inline void arch_read_lock(arch_rwlock_t *lock)
6400 {
6401 unsigned long tmp1, tmp2;
6402
6403 __asm__ __volatile__ (
6404 "1: ldsw [%2], %0\n"
6405 " brlz,pn %0, 2f\n"
6406 -"4: add %0, 1, %1\n"
6407 +"4: addcc %0, 1, %1\n"
6408 +
6409 +#ifdef CONFIG_PAX_REFCOUNT
6410 +" tvs %%icc, 6\n"
6411 +#endif
6412 +
6413 " cas [%2], %0, %1\n"
6414 " cmp %0, %1\n"
6415 " bne,pn %%icc, 1b\n"
6416 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6417 " .previous"
6418 : "=&r" (tmp1), "=&r" (tmp2)
6419 : "r" (lock)
6420 - : "memory");
6421 + : "memory", "cc");
6422 }
6423
6424 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6425 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6426 {
6427 int tmp1, tmp2;
6428
6429 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6430 "1: ldsw [%2], %0\n"
6431 " brlz,a,pn %0, 2f\n"
6432 " mov 0, %0\n"
6433 -" add %0, 1, %1\n"
6434 +" addcc %0, 1, %1\n"
6435 +
6436 +#ifdef CONFIG_PAX_REFCOUNT
6437 +" tvs %%icc, 6\n"
6438 +#endif
6439 +
6440 " cas [%2], %0, %1\n"
6441 " cmp %0, %1\n"
6442 " bne,pn %%icc, 1b\n"
6443 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6444 return tmp1;
6445 }
6446
6447 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6448 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6449 {
6450 unsigned long tmp1, tmp2;
6451
6452 __asm__ __volatile__(
6453 "1: lduw [%2], %0\n"
6454 -" sub %0, 1, %1\n"
6455 +" subcc %0, 1, %1\n"
6456 +
6457 +#ifdef CONFIG_PAX_REFCOUNT
6458 +" tvs %%icc, 6\n"
6459 +#endif
6460 +
6461 " cas [%2], %0, %1\n"
6462 " cmp %0, %1\n"
6463 " bne,pn %%xcc, 1b\n"
6464 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6465 : "memory");
6466 }
6467
6468 -static void inline arch_write_lock(arch_rwlock_t *lock)
6469 +static inline void arch_write_lock(arch_rwlock_t *lock)
6470 {
6471 unsigned long mask, tmp1, tmp2;
6472
6473 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6474 : "memory");
6475 }
6476
6477 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6478 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6479 {
6480 __asm__ __volatile__(
6481 " stw %%g0, [%0]"
6482 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6483 : "memory");
6484 }
6485
6486 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6487 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6488 {
6489 unsigned long mask, tmp1, tmp2, result;
6490
6491 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6492 index 25849ae..924c54b 100644
6493 --- a/arch/sparc/include/asm/thread_info_32.h
6494 +++ b/arch/sparc/include/asm/thread_info_32.h
6495 @@ -49,6 +49,8 @@ struct thread_info {
6496 unsigned long w_saved;
6497
6498 struct restart_block restart_block;
6499 +
6500 + unsigned long lowest_stack;
6501 };
6502
6503 /*
6504 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6505 index a3fe4dc..cae132a 100644
6506 --- a/arch/sparc/include/asm/thread_info_64.h
6507 +++ b/arch/sparc/include/asm/thread_info_64.h
6508 @@ -63,6 +63,8 @@ struct thread_info {
6509 struct pt_regs *kern_una_regs;
6510 unsigned int kern_una_insn;
6511
6512 + unsigned long lowest_stack;
6513 +
6514 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6515 };
6516
6517 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6518 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6519 /* flag bit 6 is available */
6520 #define TIF_32BIT 7 /* 32-bit binary */
6521 -/* flag bit 8 is available */
6522 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6523 #define TIF_SECCOMP 9 /* secure computing */
6524 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6525 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6526 +
6527 /* NOTE: Thread flags >= 12 should be ones we have no interest
6528 * in using in assembly, else we can't use the mask as
6529 * an immediate value in instructions such as andcc.
6530 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6531 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6532 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6533 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6534 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6535
6536 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6537 _TIF_DO_NOTIFY_RESUME_MASK | \
6538 _TIF_NEED_RESCHED)
6539 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6540
6541 +#define _TIF_WORK_SYSCALL \
6542 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6543 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6544 +
6545 +
6546 /*
6547 * Thread-synchronous status.
6548 *
6549 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6550 index 0167d26..9acd8ed 100644
6551 --- a/arch/sparc/include/asm/uaccess.h
6552 +++ b/arch/sparc/include/asm/uaccess.h
6553 @@ -1,5 +1,13 @@
6554 #ifndef ___ASM_SPARC_UACCESS_H
6555 #define ___ASM_SPARC_UACCESS_H
6556 +
6557 +#ifdef __KERNEL__
6558 +#ifndef __ASSEMBLY__
6559 +#include <linux/types.h>
6560 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6561 +#endif
6562 +#endif
6563 +
6564 #if defined(__sparc__) && defined(__arch64__)
6565 #include <asm/uaccess_64.h>
6566 #else
6567 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6568 index 53a28dd..50c38c3 100644
6569 --- a/arch/sparc/include/asm/uaccess_32.h
6570 +++ b/arch/sparc/include/asm/uaccess_32.h
6571 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6572
6573 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6574 {
6575 - if (n && __access_ok((unsigned long) to, n))
6576 + if ((long)n < 0)
6577 + return n;
6578 +
6579 + if (n && __access_ok((unsigned long) to, n)) {
6580 + if (!__builtin_constant_p(n))
6581 + check_object_size(from, n, true);
6582 return __copy_user(to, (__force void __user *) from, n);
6583 - else
6584 + } else
6585 return n;
6586 }
6587
6588 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6589 {
6590 + if ((long)n < 0)
6591 + return n;
6592 +
6593 + if (!__builtin_constant_p(n))
6594 + check_object_size(from, n, true);
6595 +
6596 return __copy_user(to, (__force void __user *) from, n);
6597 }
6598
6599 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6600 {
6601 - if (n && __access_ok((unsigned long) from, n))
6602 + if ((long)n < 0)
6603 + return n;
6604 +
6605 + if (n && __access_ok((unsigned long) from, n)) {
6606 + if (!__builtin_constant_p(n))
6607 + check_object_size(to, n, false);
6608 return __copy_user((__force void __user *) to, from, n);
6609 - else
6610 + } else
6611 return n;
6612 }
6613
6614 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6615 {
6616 + if ((long)n < 0)
6617 + return n;
6618 +
6619 return __copy_user((__force void __user *) to, from, n);
6620 }
6621
6622 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6623 index 73083e1..2bc62a6 100644
6624 --- a/arch/sparc/include/asm/uaccess_64.h
6625 +++ b/arch/sparc/include/asm/uaccess_64.h
6626 @@ -10,6 +10,7 @@
6627 #include <linux/compiler.h>
6628 #include <linux/string.h>
6629 #include <linux/thread_info.h>
6630 +#include <linux/kernel.h>
6631 #include <asm/asi.h>
6632 #include <asm/spitfire.h>
6633 #include <asm-generic/uaccess-unaligned.h>
6634 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6635 static inline unsigned long __must_check
6636 copy_from_user(void *to, const void __user *from, unsigned long size)
6637 {
6638 - unsigned long ret = ___copy_from_user(to, from, size);
6639 + unsigned long ret;
6640
6641 + if ((long)size < 0 || size > INT_MAX)
6642 + return size;
6643 +
6644 + if (!__builtin_constant_p(size))
6645 + check_object_size(to, size, false);
6646 +
6647 + ret = ___copy_from_user(to, from, size);
6648 if (unlikely(ret))
6649 ret = copy_from_user_fixup(to, from, size);
6650
6651 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6652 static inline unsigned long __must_check
6653 copy_to_user(void __user *to, const void *from, unsigned long size)
6654 {
6655 - unsigned long ret = ___copy_to_user(to, from, size);
6656 + unsigned long ret;
6657
6658 + if ((long)size < 0 || size > INT_MAX)
6659 + return size;
6660 +
6661 + if (!__builtin_constant_p(size))
6662 + check_object_size(from, size, true);
6663 +
6664 + ret = ___copy_to_user(to, from, size);
6665 if (unlikely(ret))
6666 ret = copy_to_user_fixup(to, from, size);
6667 return ret;
6668 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6669 index 6cf591b..b49e65a 100644
6670 --- a/arch/sparc/kernel/Makefile
6671 +++ b/arch/sparc/kernel/Makefile
6672 @@ -3,7 +3,7 @@
6673 #
6674
6675 asflags-y := -ansi
6676 -ccflags-y := -Werror
6677 +#ccflags-y := -Werror
6678
6679 extra-y := head_$(BITS).o
6680
6681 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6682 index 487bffb..955a925 100644
6683 --- a/arch/sparc/kernel/process_32.c
6684 +++ b/arch/sparc/kernel/process_32.c
6685 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6686
6687 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6688 r->psr, r->pc, r->npc, r->y, print_tainted());
6689 - printk("PC: <%pS>\n", (void *) r->pc);
6690 + printk("PC: <%pA>\n", (void *) r->pc);
6691 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6692 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6693 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6694 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6695 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6696 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6697 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6698 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6699
6700 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6701 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6702 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6703 rw = (struct reg_window32 *) fp;
6704 pc = rw->ins[7];
6705 printk("[%08lx : ", pc);
6706 - printk("%pS ] ", (void *) pc);
6707 + printk("%pA ] ", (void *) pc);
6708 fp = rw->ins[6];
6709 } while (++count < 16);
6710 printk("\n");
6711 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6712 index c6e0c29..052832b 100644
6713 --- a/arch/sparc/kernel/process_64.c
6714 +++ b/arch/sparc/kernel/process_64.c
6715 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6716 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6717 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6718 if (regs->tstate & TSTATE_PRIV)
6719 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6720 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6721 }
6722
6723 void show_regs(struct pt_regs *regs)
6724 {
6725 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6726 regs->tpc, regs->tnpc, regs->y, print_tainted());
6727 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6728 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6729 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6730 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6731 regs->u_regs[3]);
6732 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6733 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6734 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6735 regs->u_regs[15]);
6736 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6737 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6738 show_regwindow(regs);
6739 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6740 }
6741 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6742 ((tp && tp->task) ? tp->task->pid : -1));
6743
6744 if (gp->tstate & TSTATE_PRIV) {
6745 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6746 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6747 (void *) gp->tpc,
6748 (void *) gp->o7,
6749 (void *) gp->i7,
6750 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6751 index 7ff45e4..a58f271 100644
6752 --- a/arch/sparc/kernel/ptrace_64.c
6753 +++ b/arch/sparc/kernel/ptrace_64.c
6754 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6755 return ret;
6756 }
6757
6758 +#ifdef CONFIG_GRKERNSEC_SETXID
6759 +extern void gr_delayed_cred_worker(void);
6760 +#endif
6761 +
6762 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6763 {
6764 int ret = 0;
6765 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6766 /* do the secure computing check first */
6767 secure_computing_strict(regs->u_regs[UREG_G1]);
6768
6769 +#ifdef CONFIG_GRKERNSEC_SETXID
6770 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6771 + gr_delayed_cred_worker();
6772 +#endif
6773 +
6774 if (test_thread_flag(TIF_SYSCALL_TRACE))
6775 ret = tracehook_report_syscall_entry(regs);
6776
6777 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6778
6779 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6780 {
6781 +#ifdef CONFIG_GRKERNSEC_SETXID
6782 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6783 + gr_delayed_cred_worker();
6784 +#endif
6785 +
6786 audit_syscall_exit(regs);
6787
6788 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6789 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6790 index 0c9b31b..55a8ba6 100644
6791 --- a/arch/sparc/kernel/sys_sparc_32.c
6792 +++ b/arch/sparc/kernel/sys_sparc_32.c
6793 @@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6794 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6795 {
6796 struct vm_area_struct * vmm;
6797 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6798
6799 if (flags & MAP_FIXED) {
6800 /* We do not accept a shared mapping if it would violate
6801 @@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6802 if (len > TASK_SIZE - PAGE_SIZE)
6803 return -ENOMEM;
6804 if (!addr)
6805 - addr = TASK_UNMAPPED_BASE;
6806 + addr = current->mm->mmap_base;
6807
6808 if (flags & MAP_SHARED)
6809 addr = COLOUR_ALIGN(addr);
6810 @@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6811 /* At this point: (!vmm || addr < vmm->vm_end). */
6812 if (TASK_SIZE - PAGE_SIZE - len < addr)
6813 return -ENOMEM;
6814 - if (!vmm || addr + len <= vmm->vm_start)
6815 + if (check_heap_stack_gap(vmm, addr, len, offset))
6816 return addr;
6817 addr = vmm->vm_end;
6818 if (flags & MAP_SHARED)
6819 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6820 index 878ef3d..609e41f 100644
6821 --- a/arch/sparc/kernel/sys_sparc_64.c
6822 +++ b/arch/sparc/kernel/sys_sparc_64.c
6823 @@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6824 unsigned long task_size = TASK_SIZE;
6825 unsigned long start_addr;
6826 int do_color_align;
6827 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6828
6829 if (flags & MAP_FIXED) {
6830 /* We do not accept a shared mapping if it would violate
6831 * cache aliasing constraints.
6832 */
6833 - if ((flags & MAP_SHARED) &&
6834 + if ((filp || (flags & MAP_SHARED)) &&
6835 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6836 return -EINVAL;
6837 return addr;
6838 @@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6839 if (filp || (flags & MAP_SHARED))
6840 do_color_align = 1;
6841
6842 +#ifdef CONFIG_PAX_RANDMMAP
6843 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6844 +#endif
6845 +
6846 if (addr) {
6847 if (do_color_align)
6848 addr = COLOUR_ALIGN(addr, pgoff);
6849 @@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6850 addr = PAGE_ALIGN(addr);
6851
6852 vma = find_vma(mm, addr);
6853 - if (task_size - len >= addr &&
6854 - (!vma || addr + len <= vma->vm_start))
6855 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6856 return addr;
6857 }
6858
6859 if (len > mm->cached_hole_size) {
6860 - start_addr = addr = mm->free_area_cache;
6861 + start_addr = addr = mm->free_area_cache;
6862 } else {
6863 - start_addr = addr = TASK_UNMAPPED_BASE;
6864 + start_addr = addr = mm->mmap_base;
6865 mm->cached_hole_size = 0;
6866 }
6867
6868 @@ -157,14 +161,14 @@ full_search:
6869 vma = find_vma(mm, VA_EXCLUDE_END);
6870 }
6871 if (unlikely(task_size < addr)) {
6872 - if (start_addr != TASK_UNMAPPED_BASE) {
6873 - start_addr = addr = TASK_UNMAPPED_BASE;
6874 + if (start_addr != mm->mmap_base) {
6875 + start_addr = addr = mm->mmap_base;
6876 mm->cached_hole_size = 0;
6877 goto full_search;
6878 }
6879 return -ENOMEM;
6880 }
6881 - if (likely(!vma || addr + len <= vma->vm_start)) {
6882 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6883 /*
6884 * Remember the place where we stopped the search:
6885 */
6886 @@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6887 unsigned long task_size = STACK_TOP32;
6888 unsigned long addr = addr0;
6889 int do_color_align;
6890 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6891
6892 /* This should only ever run for 32-bit processes. */
6893 BUG_ON(!test_thread_flag(TIF_32BIT));
6894 @@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6895 /* We do not accept a shared mapping if it would violate
6896 * cache aliasing constraints.
6897 */
6898 - if ((flags & MAP_SHARED) &&
6899 + if ((filp || (flags & MAP_SHARED)) &&
6900 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6901 return -EINVAL;
6902 return addr;
6903 @@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6904 addr = PAGE_ALIGN(addr);
6905
6906 vma = find_vma(mm, addr);
6907 - if (task_size - len >= addr &&
6908 - (!vma || addr + len <= vma->vm_start))
6909 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6910 return addr;
6911 }
6912
6913 @@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6914 /* make sure it can fit in the remaining address space */
6915 if (likely(addr > len)) {
6916 vma = find_vma(mm, addr-len);
6917 - if (!vma || addr <= vma->vm_start) {
6918 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6919 /* remember the address as a hint for next time */
6920 return (mm->free_area_cache = addr-len);
6921 }
6922 @@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6923 if (unlikely(mm->mmap_base < len))
6924 goto bottomup;
6925
6926 - addr = mm->mmap_base-len;
6927 - if (do_color_align)
6928 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6929 + addr = mm->mmap_base - len;
6930
6931 do {
6932 + if (do_color_align)
6933 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6934 /*
6935 * Lookup failure means no vma is above this address,
6936 * else if new region fits below vma->vm_start,
6937 * return with success:
6938 */
6939 vma = find_vma(mm, addr);
6940 - if (likely(!vma || addr+len <= vma->vm_start)) {
6941 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6942 /* remember the address as a hint for next time */
6943 return (mm->free_area_cache = addr);
6944 }
6945 @@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6946 mm->cached_hole_size = vma->vm_start - addr;
6947
6948 /* try just below the current vma->vm_start */
6949 - addr = vma->vm_start-len;
6950 - if (do_color_align)
6951 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6952 - } while (likely(len < vma->vm_start));
6953 + addr = skip_heap_stack_gap(vma, len, offset);
6954 + } while (!IS_ERR_VALUE(addr));
6955
6956 bottomup:
6957 /*
6958 @@ -373,6 +375,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6959 gap == RLIM_INFINITY ||
6960 sysctl_legacy_va_layout) {
6961 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6962 +
6963 +#ifdef CONFIG_PAX_RANDMMAP
6964 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6965 + mm->mmap_base += mm->delta_mmap;
6966 +#endif
6967 +
6968 mm->get_unmapped_area = arch_get_unmapped_area;
6969 mm->unmap_area = arch_unmap_area;
6970 } else {
6971 @@ -385,6 +393,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6972 gap = (task_size / 6 * 5);
6973
6974 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6975 +
6976 +#ifdef CONFIG_PAX_RANDMMAP
6977 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6978 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6979 +#endif
6980 +
6981 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6982 mm->unmap_area = arch_unmap_area_topdown;
6983 }
6984 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6985 index bf23477..b7425a6 100644
6986 --- a/arch/sparc/kernel/syscalls.S
6987 +++ b/arch/sparc/kernel/syscalls.S
6988 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6989 #endif
6990 .align 32
6991 1: ldx [%g6 + TI_FLAGS], %l5
6992 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6993 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6994 be,pt %icc, rtrap
6995 nop
6996 call syscall_trace_leave
6997 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
6998
6999 srl %i5, 0, %o5 ! IEU1
7000 srl %i2, 0, %o2 ! IEU0 Group
7001 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7002 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7003 bne,pn %icc, linux_syscall_trace32 ! CTI
7004 mov %i0, %l5 ! IEU1
7005 call %l7 ! CTI Group brk forced
7006 @@ -212,7 +212,7 @@ linux_sparc_syscall:
7007
7008 mov %i3, %o3 ! IEU1
7009 mov %i4, %o4 ! IEU0 Group
7010 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7011 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7012 bne,pn %icc, linux_syscall_trace ! CTI Group
7013 mov %i0, %l5 ! IEU0
7014 2: call %l7 ! CTI Group brk forced
7015 @@ -228,7 +228,7 @@ ret_sys_call:
7016
7017 cmp %o0, -ERESTART_RESTARTBLOCK
7018 bgeu,pn %xcc, 1f
7019 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7020 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7021 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7022
7023 2:
7024 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7025 index a5785ea..405c5f7 100644
7026 --- a/arch/sparc/kernel/traps_32.c
7027 +++ b/arch/sparc/kernel/traps_32.c
7028 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7029 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7030 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7031
7032 +extern void gr_handle_kernel_exploit(void);
7033 +
7034 void die_if_kernel(char *str, struct pt_regs *regs)
7035 {
7036 static int die_counter;
7037 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7038 count++ < 30 &&
7039 (((unsigned long) rw) >= PAGE_OFFSET) &&
7040 !(((unsigned long) rw) & 0x7)) {
7041 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
7042 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
7043 (void *) rw->ins[7]);
7044 rw = (struct reg_window32 *)rw->ins[6];
7045 }
7046 }
7047 printk("Instruction DUMP:");
7048 instruction_dump ((unsigned long *) regs->pc);
7049 - if(regs->psr & PSR_PS)
7050 + if(regs->psr & PSR_PS) {
7051 + gr_handle_kernel_exploit();
7052 do_exit(SIGKILL);
7053 + }
7054 do_exit(SIGSEGV);
7055 }
7056
7057 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7058 index b66a779..8e8d66c 100644
7059 --- a/arch/sparc/kernel/traps_64.c
7060 +++ b/arch/sparc/kernel/traps_64.c
7061 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7062 i + 1,
7063 p->trapstack[i].tstate, p->trapstack[i].tpc,
7064 p->trapstack[i].tnpc, p->trapstack[i].tt);
7065 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7066 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7067 }
7068 }
7069
7070 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7071
7072 lvl -= 0x100;
7073 if (regs->tstate & TSTATE_PRIV) {
7074 +
7075 +#ifdef CONFIG_PAX_REFCOUNT
7076 + if (lvl == 6)
7077 + pax_report_refcount_overflow(regs);
7078 +#endif
7079 +
7080 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7081 die_if_kernel(buffer, regs);
7082 }
7083 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7084 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7085 {
7086 char buffer[32];
7087 -
7088 +
7089 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7090 0, lvl, SIGTRAP) == NOTIFY_STOP)
7091 return;
7092
7093 +#ifdef CONFIG_PAX_REFCOUNT
7094 + if (lvl == 6)
7095 + pax_report_refcount_overflow(regs);
7096 +#endif
7097 +
7098 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7099
7100 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7101 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7102 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7103 printk("%s" "ERROR(%d): ",
7104 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7105 - printk("TPC<%pS>\n", (void *) regs->tpc);
7106 + printk("TPC<%pA>\n", (void *) regs->tpc);
7107 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7108 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7109 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7110 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7111 smp_processor_id(),
7112 (type & 0x1) ? 'I' : 'D',
7113 regs->tpc);
7114 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7115 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7116 panic("Irrecoverable Cheetah+ parity error.");
7117 }
7118
7119 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7120 smp_processor_id(),
7121 (type & 0x1) ? 'I' : 'D',
7122 regs->tpc);
7123 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7124 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7125 }
7126
7127 struct sun4v_error_entry {
7128 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7129
7130 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7131 regs->tpc, tl);
7132 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7133 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7134 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7135 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7136 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7137 (void *) regs->u_regs[UREG_I7]);
7138 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7139 "pte[%lx] error[%lx]\n",
7140 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7141
7142 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7143 regs->tpc, tl);
7144 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7145 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7146 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7147 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7148 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7149 (void *) regs->u_regs[UREG_I7]);
7150 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7151 "pte[%lx] error[%lx]\n",
7152 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7153 fp = (unsigned long)sf->fp + STACK_BIAS;
7154 }
7155
7156 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7157 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7158 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7159 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7160 int index = tsk->curr_ret_stack;
7161 if (tsk->ret_stack && index >= graph) {
7162 pc = tsk->ret_stack[index - graph].ret;
7163 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7164 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7165 graph++;
7166 }
7167 }
7168 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7169 return (struct reg_window *) (fp + STACK_BIAS);
7170 }
7171
7172 +extern void gr_handle_kernel_exploit(void);
7173 +
7174 void die_if_kernel(char *str, struct pt_regs *regs)
7175 {
7176 static int die_counter;
7177 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7178 while (rw &&
7179 count++ < 30 &&
7180 kstack_valid(tp, (unsigned long) rw)) {
7181 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
7182 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
7183 (void *) rw->ins[7]);
7184
7185 rw = kernel_stack_up(rw);
7186 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7187 }
7188 user_instruction_dump ((unsigned int __user *) regs->tpc);
7189 }
7190 - if (regs->tstate & TSTATE_PRIV)
7191 + if (regs->tstate & TSTATE_PRIV) {
7192 + gr_handle_kernel_exploit();
7193 do_exit(SIGKILL);
7194 + }
7195 do_exit(SIGSEGV);
7196 }
7197 EXPORT_SYMBOL(die_if_kernel);
7198 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7199 index 8201c25e..072a2a7 100644
7200 --- a/arch/sparc/kernel/unaligned_64.c
7201 +++ b/arch/sparc/kernel/unaligned_64.c
7202 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7203 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7204
7205 if (__ratelimit(&ratelimit)) {
7206 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7207 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7208 regs->tpc, (void *) regs->tpc);
7209 }
7210 }
7211 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7212 index 8410065f2..4fd4ca22 100644
7213 --- a/arch/sparc/lib/Makefile
7214 +++ b/arch/sparc/lib/Makefile
7215 @@ -2,7 +2,7 @@
7216 #
7217
7218 asflags-y := -ansi -DST_DIV0=0x02
7219 -ccflags-y := -Werror
7220 +#ccflags-y := -Werror
7221
7222 lib-$(CONFIG_SPARC32) += ashrdi3.o
7223 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7224 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7225 index 85c233d..68500e0 100644
7226 --- a/arch/sparc/lib/atomic_64.S
7227 +++ b/arch/sparc/lib/atomic_64.S
7228 @@ -17,7 +17,12 @@
7229 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7230 BACKOFF_SETUP(%o2)
7231 1: lduw [%o1], %g1
7232 - add %g1, %o0, %g7
7233 + addcc %g1, %o0, %g7
7234 +
7235 +#ifdef CONFIG_PAX_REFCOUNT
7236 + tvs %icc, 6
7237 +#endif
7238 +
7239 cas [%o1], %g1, %g7
7240 cmp %g1, %g7
7241 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7242 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7243 2: BACKOFF_SPIN(%o2, %o3, 1b)
7244 ENDPROC(atomic_add)
7245
7246 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7247 + BACKOFF_SETUP(%o2)
7248 +1: lduw [%o1], %g1
7249 + add %g1, %o0, %g7
7250 + cas [%o1], %g1, %g7
7251 + cmp %g1, %g7
7252 + bne,pn %icc, 2f
7253 + nop
7254 + retl
7255 + nop
7256 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7257 +ENDPROC(atomic_add_unchecked)
7258 +
7259 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7260 BACKOFF_SETUP(%o2)
7261 1: lduw [%o1], %g1
7262 - sub %g1, %o0, %g7
7263 + subcc %g1, %o0, %g7
7264 +
7265 +#ifdef CONFIG_PAX_REFCOUNT
7266 + tvs %icc, 6
7267 +#endif
7268 +
7269 cas [%o1], %g1, %g7
7270 cmp %g1, %g7
7271 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7272 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7273 2: BACKOFF_SPIN(%o2, %o3, 1b)
7274 ENDPROC(atomic_sub)
7275
7276 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7277 + BACKOFF_SETUP(%o2)
7278 +1: lduw [%o1], %g1
7279 + sub %g1, %o0, %g7
7280 + cas [%o1], %g1, %g7
7281 + cmp %g1, %g7
7282 + bne,pn %icc, 2f
7283 + nop
7284 + retl
7285 + nop
7286 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7287 +ENDPROC(atomic_sub_unchecked)
7288 +
7289 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7290 BACKOFF_SETUP(%o2)
7291 1: lduw [%o1], %g1
7292 - add %g1, %o0, %g7
7293 + addcc %g1, %o0, %g7
7294 +
7295 +#ifdef CONFIG_PAX_REFCOUNT
7296 + tvs %icc, 6
7297 +#endif
7298 +
7299 cas [%o1], %g1, %g7
7300 cmp %g1, %g7
7301 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7302 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7303 2: BACKOFF_SPIN(%o2, %o3, 1b)
7304 ENDPROC(atomic_add_ret)
7305
7306 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7307 + BACKOFF_SETUP(%o2)
7308 +1: lduw [%o1], %g1
7309 + addcc %g1, %o0, %g7
7310 + cas [%o1], %g1, %g7
7311 + cmp %g1, %g7
7312 + bne,pn %icc, 2f
7313 + add %g7, %o0, %g7
7314 + sra %g7, 0, %o0
7315 + retl
7316 + nop
7317 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7318 +ENDPROC(atomic_add_ret_unchecked)
7319 +
7320 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7321 BACKOFF_SETUP(%o2)
7322 1: lduw [%o1], %g1
7323 - sub %g1, %o0, %g7
7324 + subcc %g1, %o0, %g7
7325 +
7326 +#ifdef CONFIG_PAX_REFCOUNT
7327 + tvs %icc, 6
7328 +#endif
7329 +
7330 cas [%o1], %g1, %g7
7331 cmp %g1, %g7
7332 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7333 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7334 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7335 BACKOFF_SETUP(%o2)
7336 1: ldx [%o1], %g1
7337 - add %g1, %o0, %g7
7338 + addcc %g1, %o0, %g7
7339 +
7340 +#ifdef CONFIG_PAX_REFCOUNT
7341 + tvs %xcc, 6
7342 +#endif
7343 +
7344 casx [%o1], %g1, %g7
7345 cmp %g1, %g7
7346 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7347 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7348 2: BACKOFF_SPIN(%o2, %o3, 1b)
7349 ENDPROC(atomic64_add)
7350
7351 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7352 + BACKOFF_SETUP(%o2)
7353 +1: ldx [%o1], %g1
7354 + addcc %g1, %o0, %g7
7355 + casx [%o1], %g1, %g7
7356 + cmp %g1, %g7
7357 + bne,pn %xcc, 2f
7358 + nop
7359 + retl
7360 + nop
7361 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7362 +ENDPROC(atomic64_add_unchecked)
7363 +
7364 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7365 BACKOFF_SETUP(%o2)
7366 1: ldx [%o1], %g1
7367 - sub %g1, %o0, %g7
7368 + subcc %g1, %o0, %g7
7369 +
7370 +#ifdef CONFIG_PAX_REFCOUNT
7371 + tvs %xcc, 6
7372 +#endif
7373 +
7374 casx [%o1], %g1, %g7
7375 cmp %g1, %g7
7376 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7377 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7378 2: BACKOFF_SPIN(%o2, %o3, 1b)
7379 ENDPROC(atomic64_sub)
7380
7381 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7382 + BACKOFF_SETUP(%o2)
7383 +1: ldx [%o1], %g1
7384 + subcc %g1, %o0, %g7
7385 + casx [%o1], %g1, %g7
7386 + cmp %g1, %g7
7387 + bne,pn %xcc, 2f
7388 + nop
7389 + retl
7390 + nop
7391 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7392 +ENDPROC(atomic64_sub_unchecked)
7393 +
7394 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7395 BACKOFF_SETUP(%o2)
7396 1: ldx [%o1], %g1
7397 - add %g1, %o0, %g7
7398 + addcc %g1, %o0, %g7
7399 +
7400 +#ifdef CONFIG_PAX_REFCOUNT
7401 + tvs %xcc, 6
7402 +#endif
7403 +
7404 casx [%o1], %g1, %g7
7405 cmp %g1, %g7
7406 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7407 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7408 2: BACKOFF_SPIN(%o2, %o3, 1b)
7409 ENDPROC(atomic64_add_ret)
7410
7411 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7412 + BACKOFF_SETUP(%o2)
7413 +1: ldx [%o1], %g1
7414 + addcc %g1, %o0, %g7
7415 + casx [%o1], %g1, %g7
7416 + cmp %g1, %g7
7417 + bne,pn %xcc, 2f
7418 + add %g7, %o0, %g7
7419 + mov %g7, %o0
7420 + retl
7421 + nop
7422 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7423 +ENDPROC(atomic64_add_ret_unchecked)
7424 +
7425 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7426 BACKOFF_SETUP(%o2)
7427 1: ldx [%o1], %g1
7428 - sub %g1, %o0, %g7
7429 + subcc %g1, %o0, %g7
7430 +
7431 +#ifdef CONFIG_PAX_REFCOUNT
7432 + tvs %xcc, 6
7433 +#endif
7434 +
7435 casx [%o1], %g1, %g7
7436 cmp %g1, %g7
7437 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7438 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7439 index 0c4e35e..745d3e4 100644
7440 --- a/arch/sparc/lib/ksyms.c
7441 +++ b/arch/sparc/lib/ksyms.c
7442 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7443
7444 /* Atomic counter implementation. */
7445 EXPORT_SYMBOL(atomic_add);
7446 +EXPORT_SYMBOL(atomic_add_unchecked);
7447 EXPORT_SYMBOL(atomic_add_ret);
7448 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7449 EXPORT_SYMBOL(atomic_sub);
7450 +EXPORT_SYMBOL(atomic_sub_unchecked);
7451 EXPORT_SYMBOL(atomic_sub_ret);
7452 EXPORT_SYMBOL(atomic64_add);
7453 +EXPORT_SYMBOL(atomic64_add_unchecked);
7454 EXPORT_SYMBOL(atomic64_add_ret);
7455 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7456 EXPORT_SYMBOL(atomic64_sub);
7457 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7458 EXPORT_SYMBOL(atomic64_sub_ret);
7459 EXPORT_SYMBOL(atomic64_dec_if_positive);
7460
7461 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7462 index 30c3ecc..736f015 100644
7463 --- a/arch/sparc/mm/Makefile
7464 +++ b/arch/sparc/mm/Makefile
7465 @@ -2,7 +2,7 @@
7466 #
7467
7468 asflags-y := -ansi
7469 -ccflags-y := -Werror
7470 +#ccflags-y := -Werror
7471
7472 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7473 obj-y += fault_$(BITS).o
7474 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7475 index e98bfda..ea8d221 100644
7476 --- a/arch/sparc/mm/fault_32.c
7477 +++ b/arch/sparc/mm/fault_32.c
7478 @@ -21,6 +21,9 @@
7479 #include <linux/perf_event.h>
7480 #include <linux/interrupt.h>
7481 #include <linux/kdebug.h>
7482 +#include <linux/slab.h>
7483 +#include <linux/pagemap.h>
7484 +#include <linux/compiler.h>
7485
7486 #include <asm/page.h>
7487 #include <asm/pgtable.h>
7488 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7489 return safe_compute_effective_address(regs, insn);
7490 }
7491
7492 +#ifdef CONFIG_PAX_PAGEEXEC
7493 +#ifdef CONFIG_PAX_DLRESOLVE
7494 +static void pax_emuplt_close(struct vm_area_struct *vma)
7495 +{
7496 + vma->vm_mm->call_dl_resolve = 0UL;
7497 +}
7498 +
7499 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7500 +{
7501 + unsigned int *kaddr;
7502 +
7503 + vmf->page = alloc_page(GFP_HIGHUSER);
7504 + if (!vmf->page)
7505 + return VM_FAULT_OOM;
7506 +
7507 + kaddr = kmap(vmf->page);
7508 + memset(kaddr, 0, PAGE_SIZE);
7509 + kaddr[0] = 0x9DE3BFA8U; /* save */
7510 + flush_dcache_page(vmf->page);
7511 + kunmap(vmf->page);
7512 + return VM_FAULT_MAJOR;
7513 +}
7514 +
7515 +static const struct vm_operations_struct pax_vm_ops = {
7516 + .close = pax_emuplt_close,
7517 + .fault = pax_emuplt_fault
7518 +};
7519 +
7520 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7521 +{
7522 + int ret;
7523 +
7524 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7525 + vma->vm_mm = current->mm;
7526 + vma->vm_start = addr;
7527 + vma->vm_end = addr + PAGE_SIZE;
7528 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7529 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7530 + vma->vm_ops = &pax_vm_ops;
7531 +
7532 + ret = insert_vm_struct(current->mm, vma);
7533 + if (ret)
7534 + return ret;
7535 +
7536 + ++current->mm->total_vm;
7537 + return 0;
7538 +}
7539 +#endif
7540 +
7541 +/*
7542 + * PaX: decide what to do with offenders (regs->pc = fault address)
7543 + *
7544 + * returns 1 when task should be killed
7545 + * 2 when patched PLT trampoline was detected
7546 + * 3 when unpatched PLT trampoline was detected
7547 + */
7548 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7549 +{
7550 +
7551 +#ifdef CONFIG_PAX_EMUPLT
7552 + int err;
7553 +
7554 + do { /* PaX: patched PLT emulation #1 */
7555 + unsigned int sethi1, sethi2, jmpl;
7556 +
7557 + err = get_user(sethi1, (unsigned int *)regs->pc);
7558 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7559 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7560 +
7561 + if (err)
7562 + break;
7563 +
7564 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7565 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7566 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7567 + {
7568 + unsigned int addr;
7569 +
7570 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7571 + addr = regs->u_regs[UREG_G1];
7572 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7573 + regs->pc = addr;
7574 + regs->npc = addr+4;
7575 + return 2;
7576 + }
7577 + } while (0);
7578 +
7579 + do { /* PaX: patched PLT emulation #2 */
7580 + unsigned int ba;
7581 +
7582 + err = get_user(ba, (unsigned int *)regs->pc);
7583 +
7584 + if (err)
7585 + break;
7586 +
7587 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7588 + unsigned int addr;
7589 +
7590 + if ((ba & 0xFFC00000U) == 0x30800000U)
7591 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7592 + else
7593 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7594 + regs->pc = addr;
7595 + regs->npc = addr+4;
7596 + return 2;
7597 + }
7598 + } while (0);
7599 +
7600 + do { /* PaX: patched PLT emulation #3 */
7601 + unsigned int sethi, bajmpl, nop;
7602 +
7603 + err = get_user(sethi, (unsigned int *)regs->pc);
7604 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7605 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7606 +
7607 + if (err)
7608 + break;
7609 +
7610 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7611 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7612 + nop == 0x01000000U)
7613 + {
7614 + unsigned int addr;
7615 +
7616 + addr = (sethi & 0x003FFFFFU) << 10;
7617 + regs->u_regs[UREG_G1] = addr;
7618 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7619 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7620 + else
7621 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7622 + regs->pc = addr;
7623 + regs->npc = addr+4;
7624 + return 2;
7625 + }
7626 + } while (0);
7627 +
7628 + do { /* PaX: unpatched PLT emulation step 1 */
7629 + unsigned int sethi, ba, nop;
7630 +
7631 + err = get_user(sethi, (unsigned int *)regs->pc);
7632 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7633 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7634 +
7635 + if (err)
7636 + break;
7637 +
7638 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7639 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7640 + nop == 0x01000000U)
7641 + {
7642 + unsigned int addr, save, call;
7643 +
7644 + if ((ba & 0xFFC00000U) == 0x30800000U)
7645 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7646 + else
7647 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7648 +
7649 + err = get_user(save, (unsigned int *)addr);
7650 + err |= get_user(call, (unsigned int *)(addr+4));
7651 + err |= get_user(nop, (unsigned int *)(addr+8));
7652 + if (err)
7653 + break;
7654 +
7655 +#ifdef CONFIG_PAX_DLRESOLVE
7656 + if (save == 0x9DE3BFA8U &&
7657 + (call & 0xC0000000U) == 0x40000000U &&
7658 + nop == 0x01000000U)
7659 + {
7660 + struct vm_area_struct *vma;
7661 + unsigned long call_dl_resolve;
7662 +
7663 + down_read(&current->mm->mmap_sem);
7664 + call_dl_resolve = current->mm->call_dl_resolve;
7665 + up_read(&current->mm->mmap_sem);
7666 + if (likely(call_dl_resolve))
7667 + goto emulate;
7668 +
7669 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7670 +
7671 + down_write(&current->mm->mmap_sem);
7672 + if (current->mm->call_dl_resolve) {
7673 + call_dl_resolve = current->mm->call_dl_resolve;
7674 + up_write(&current->mm->mmap_sem);
7675 + if (vma)
7676 + kmem_cache_free(vm_area_cachep, vma);
7677 + goto emulate;
7678 + }
7679 +
7680 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7681 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7682 + up_write(&current->mm->mmap_sem);
7683 + if (vma)
7684 + kmem_cache_free(vm_area_cachep, vma);
7685 + return 1;
7686 + }
7687 +
7688 + if (pax_insert_vma(vma, call_dl_resolve)) {
7689 + up_write(&current->mm->mmap_sem);
7690 + kmem_cache_free(vm_area_cachep, vma);
7691 + return 1;
7692 + }
7693 +
7694 + current->mm->call_dl_resolve = call_dl_resolve;
7695 + up_write(&current->mm->mmap_sem);
7696 +
7697 +emulate:
7698 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7699 + regs->pc = call_dl_resolve;
7700 + regs->npc = addr+4;
7701 + return 3;
7702 + }
7703 +#endif
7704 +
7705 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7706 + if ((save & 0xFFC00000U) == 0x05000000U &&
7707 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7708 + nop == 0x01000000U)
7709 + {
7710 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7711 + regs->u_regs[UREG_G2] = addr + 4;
7712 + addr = (save & 0x003FFFFFU) << 10;
7713 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7714 + regs->pc = addr;
7715 + regs->npc = addr+4;
7716 + return 3;
7717 + }
7718 + }
7719 + } while (0);
7720 +
7721 + do { /* PaX: unpatched PLT emulation step 2 */
7722 + unsigned int save, call, nop;
7723 +
7724 + err = get_user(save, (unsigned int *)(regs->pc-4));
7725 + err |= get_user(call, (unsigned int *)regs->pc);
7726 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7727 + if (err)
7728 + break;
7729 +
7730 + if (save == 0x9DE3BFA8U &&
7731 + (call & 0xC0000000U) == 0x40000000U &&
7732 + nop == 0x01000000U)
7733 + {
7734 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7735 +
7736 + regs->u_regs[UREG_RETPC] = regs->pc;
7737 + regs->pc = dl_resolve;
7738 + regs->npc = dl_resolve+4;
7739 + return 3;
7740 + }
7741 + } while (0);
7742 +#endif
7743 +
7744 + return 1;
7745 +}
7746 +
7747 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7748 +{
7749 + unsigned long i;
7750 +
7751 + printk(KERN_ERR "PAX: bytes at PC: ");
7752 + for (i = 0; i < 8; i++) {
7753 + unsigned int c;
7754 + if (get_user(c, (unsigned int *)pc+i))
7755 + printk(KERN_CONT "???????? ");
7756 + else
7757 + printk(KERN_CONT "%08x ", c);
7758 + }
7759 + printk("\n");
7760 +}
7761 +#endif
7762 +
7763 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7764 int text_fault)
7765 {
7766 @@ -230,6 +504,24 @@ good_area:
7767 if (!(vma->vm_flags & VM_WRITE))
7768 goto bad_area;
7769 } else {
7770 +
7771 +#ifdef CONFIG_PAX_PAGEEXEC
7772 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7773 + up_read(&mm->mmap_sem);
7774 + switch (pax_handle_fetch_fault(regs)) {
7775 +
7776 +#ifdef CONFIG_PAX_EMUPLT
7777 + case 2:
7778 + case 3:
7779 + return;
7780 +#endif
7781 +
7782 + }
7783 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7784 + do_group_exit(SIGKILL);
7785 + }
7786 +#endif
7787 +
7788 /* Allow reads even for write-only mappings */
7789 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7790 goto bad_area;
7791 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7792 index 097aee7..5ca6697 100644
7793 --- a/arch/sparc/mm/fault_64.c
7794 +++ b/arch/sparc/mm/fault_64.c
7795 @@ -21,6 +21,9 @@
7796 #include <linux/kprobes.h>
7797 #include <linux/kdebug.h>
7798 #include <linux/percpu.h>
7799 +#include <linux/slab.h>
7800 +#include <linux/pagemap.h>
7801 +#include <linux/compiler.h>
7802
7803 #include <asm/page.h>
7804 #include <asm/pgtable.h>
7805 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7806 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7807 regs->tpc);
7808 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7809 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7810 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7811 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7812 dump_stack();
7813 unhandled_fault(regs->tpc, current, regs);
7814 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7815 show_regs(regs);
7816 }
7817
7818 +#ifdef CONFIG_PAX_PAGEEXEC
7819 +#ifdef CONFIG_PAX_DLRESOLVE
7820 +static void pax_emuplt_close(struct vm_area_struct *vma)
7821 +{
7822 + vma->vm_mm->call_dl_resolve = 0UL;
7823 +}
7824 +
7825 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7826 +{
7827 + unsigned int *kaddr;
7828 +
7829 + vmf->page = alloc_page(GFP_HIGHUSER);
7830 + if (!vmf->page)
7831 + return VM_FAULT_OOM;
7832 +
7833 + kaddr = kmap(vmf->page);
7834 + memset(kaddr, 0, PAGE_SIZE);
7835 + kaddr[0] = 0x9DE3BFA8U; /* save */
7836 + flush_dcache_page(vmf->page);
7837 + kunmap(vmf->page);
7838 + return VM_FAULT_MAJOR;
7839 +}
7840 +
7841 +static const struct vm_operations_struct pax_vm_ops = {
7842 + .close = pax_emuplt_close,
7843 + .fault = pax_emuplt_fault
7844 +};
7845 +
7846 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7847 +{
7848 + int ret;
7849 +
7850 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7851 + vma->vm_mm = current->mm;
7852 + vma->vm_start = addr;
7853 + vma->vm_end = addr + PAGE_SIZE;
7854 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7855 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7856 + vma->vm_ops = &pax_vm_ops;
7857 +
7858 + ret = insert_vm_struct(current->mm, vma);
7859 + if (ret)
7860 + return ret;
7861 +
7862 + ++current->mm->total_vm;
7863 + return 0;
7864 +}
7865 +#endif
7866 +
7867 +/*
7868 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7869 + *
7870 + * returns 1 when task should be killed
7871 + * 2 when patched PLT trampoline was detected
7872 + * 3 when unpatched PLT trampoline was detected
7873 + */
7874 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7875 +{
7876 +
7877 +#ifdef CONFIG_PAX_EMUPLT
7878 + int err;
7879 +
7880 + do { /* PaX: patched PLT emulation #1 */
7881 + unsigned int sethi1, sethi2, jmpl;
7882 +
7883 + err = get_user(sethi1, (unsigned int *)regs->tpc);
7884 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
7885 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
7886 +
7887 + if (err)
7888 + break;
7889 +
7890 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7891 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7892 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7893 + {
7894 + unsigned long addr;
7895 +
7896 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7897 + addr = regs->u_regs[UREG_G1];
7898 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7899 +
7900 + if (test_thread_flag(TIF_32BIT))
7901 + addr &= 0xFFFFFFFFUL;
7902 +
7903 + regs->tpc = addr;
7904 + regs->tnpc = addr+4;
7905 + return 2;
7906 + }
7907 + } while (0);
7908 +
7909 + do { /* PaX: patched PLT emulation #2 */
7910 + unsigned int ba;
7911 +
7912 + err = get_user(ba, (unsigned int *)regs->tpc);
7913 +
7914 + if (err)
7915 + break;
7916 +
7917 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7918 + unsigned long addr;
7919 +
7920 + if ((ba & 0xFFC00000U) == 0x30800000U)
7921 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7922 + else
7923 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7924 +
7925 + if (test_thread_flag(TIF_32BIT))
7926 + addr &= 0xFFFFFFFFUL;
7927 +
7928 + regs->tpc = addr;
7929 + regs->tnpc = addr+4;
7930 + return 2;
7931 + }
7932 + } while (0);
7933 +
7934 + do { /* PaX: patched PLT emulation #3 */
7935 + unsigned int sethi, bajmpl, nop;
7936 +
7937 + err = get_user(sethi, (unsigned int *)regs->tpc);
7938 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
7939 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7940 +
7941 + if (err)
7942 + break;
7943 +
7944 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7945 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7946 + nop == 0x01000000U)
7947 + {
7948 + unsigned long addr;
7949 +
7950 + addr = (sethi & 0x003FFFFFU) << 10;
7951 + regs->u_regs[UREG_G1] = addr;
7952 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7953 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7954 + else
7955 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7956 +
7957 + if (test_thread_flag(TIF_32BIT))
7958 + addr &= 0xFFFFFFFFUL;
7959 +
7960 + regs->tpc = addr;
7961 + regs->tnpc = addr+4;
7962 + return 2;
7963 + }
7964 + } while (0);
7965 +
7966 + do { /* PaX: patched PLT emulation #4 */
7967 + unsigned int sethi, mov1, call, mov2;
7968 +
7969 + err = get_user(sethi, (unsigned int *)regs->tpc);
7970 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7971 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7972 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7973 +
7974 + if (err)
7975 + break;
7976 +
7977 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7978 + mov1 == 0x8210000FU &&
7979 + (call & 0xC0000000U) == 0x40000000U &&
7980 + mov2 == 0x9E100001U)
7981 + {
7982 + unsigned long addr;
7983 +
7984 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7985 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7986 +
7987 + if (test_thread_flag(TIF_32BIT))
7988 + addr &= 0xFFFFFFFFUL;
7989 +
7990 + regs->tpc = addr;
7991 + regs->tnpc = addr+4;
7992 + return 2;
7993 + }
7994 + } while (0);
7995 +
7996 + do { /* PaX: patched PLT emulation #5 */
7997 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7998 +
7999 + err = get_user(sethi, (unsigned int *)regs->tpc);
8000 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8001 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8002 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8003 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8004 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8005 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8006 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8007 +
8008 + if (err)
8009 + break;
8010 +
8011 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8012 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8013 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8014 + (or1 & 0xFFFFE000U) == 0x82106000U &&
8015 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8016 + sllx == 0x83287020U &&
8017 + jmpl == 0x81C04005U &&
8018 + nop == 0x01000000U)
8019 + {
8020 + unsigned long addr;
8021 +
8022 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8023 + regs->u_regs[UREG_G1] <<= 32;
8024 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8025 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8026 + regs->tpc = addr;
8027 + regs->tnpc = addr+4;
8028 + return 2;
8029 + }
8030 + } while (0);
8031 +
8032 + do { /* PaX: patched PLT emulation #6 */
8033 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8034 +
8035 + err = get_user(sethi, (unsigned int *)regs->tpc);
8036 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8037 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8038 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8039 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
8040 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8041 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8042 +
8043 + if (err)
8044 + break;
8045 +
8046 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8047 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8048 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8049 + sllx == 0x83287020U &&
8050 + (or & 0xFFFFE000U) == 0x8A116000U &&
8051 + jmpl == 0x81C04005U &&
8052 + nop == 0x01000000U)
8053 + {
8054 + unsigned long addr;
8055 +
8056 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8057 + regs->u_regs[UREG_G1] <<= 32;
8058 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8059 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8060 + regs->tpc = addr;
8061 + regs->tnpc = addr+4;
8062 + return 2;
8063 + }
8064 + } while (0);
8065 +
8066 + do { /* PaX: unpatched PLT emulation step 1 */
8067 + unsigned int sethi, ba, nop;
8068 +
8069 + err = get_user(sethi, (unsigned int *)regs->tpc);
8070 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8071 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8072 +
8073 + if (err)
8074 + break;
8075 +
8076 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8077 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8078 + nop == 0x01000000U)
8079 + {
8080 + unsigned long addr;
8081 + unsigned int save, call;
8082 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8083 +
8084 + if ((ba & 0xFFC00000U) == 0x30800000U)
8085 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8086 + else
8087 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8088 +
8089 + if (test_thread_flag(TIF_32BIT))
8090 + addr &= 0xFFFFFFFFUL;
8091 +
8092 + err = get_user(save, (unsigned int *)addr);
8093 + err |= get_user(call, (unsigned int *)(addr+4));
8094 + err |= get_user(nop, (unsigned int *)(addr+8));
8095 + if (err)
8096 + break;
8097 +
8098 +#ifdef CONFIG_PAX_DLRESOLVE
8099 + if (save == 0x9DE3BFA8U &&
8100 + (call & 0xC0000000U) == 0x40000000U &&
8101 + nop == 0x01000000U)
8102 + {
8103 + struct vm_area_struct *vma;
8104 + unsigned long call_dl_resolve;
8105 +
8106 + down_read(&current->mm->mmap_sem);
8107 + call_dl_resolve = current->mm->call_dl_resolve;
8108 + up_read(&current->mm->mmap_sem);
8109 + if (likely(call_dl_resolve))
8110 + goto emulate;
8111 +
8112 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8113 +
8114 + down_write(&current->mm->mmap_sem);
8115 + if (current->mm->call_dl_resolve) {
8116 + call_dl_resolve = current->mm->call_dl_resolve;
8117 + up_write(&current->mm->mmap_sem);
8118 + if (vma)
8119 + kmem_cache_free(vm_area_cachep, vma);
8120 + goto emulate;
8121 + }
8122 +
8123 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8124 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8125 + up_write(&current->mm->mmap_sem);
8126 + if (vma)
8127 + kmem_cache_free(vm_area_cachep, vma);
8128 + return 1;
8129 + }
8130 +
8131 + if (pax_insert_vma(vma, call_dl_resolve)) {
8132 + up_write(&current->mm->mmap_sem);
8133 + kmem_cache_free(vm_area_cachep, vma);
8134 + return 1;
8135 + }
8136 +
8137 + current->mm->call_dl_resolve = call_dl_resolve;
8138 + up_write(&current->mm->mmap_sem);
8139 +
8140 +emulate:
8141 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8142 + regs->tpc = call_dl_resolve;
8143 + regs->tnpc = addr+4;
8144 + return 3;
8145 + }
8146 +#endif
8147 +
8148 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8149 + if ((save & 0xFFC00000U) == 0x05000000U &&
8150 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8151 + nop == 0x01000000U)
8152 + {
8153 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8154 + regs->u_regs[UREG_G2] = addr + 4;
8155 + addr = (save & 0x003FFFFFU) << 10;
8156 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8157 +
8158 + if (test_thread_flag(TIF_32BIT))
8159 + addr &= 0xFFFFFFFFUL;
8160 +
8161 + regs->tpc = addr;
8162 + regs->tnpc = addr+4;
8163 + return 3;
8164 + }
8165 +
8166 + /* PaX: 64-bit PLT stub */
8167 + err = get_user(sethi1, (unsigned int *)addr);
8168 + err |= get_user(sethi2, (unsigned int *)(addr+4));
8169 + err |= get_user(or1, (unsigned int *)(addr+8));
8170 + err |= get_user(or2, (unsigned int *)(addr+12));
8171 + err |= get_user(sllx, (unsigned int *)(addr+16));
8172 + err |= get_user(add, (unsigned int *)(addr+20));
8173 + err |= get_user(jmpl, (unsigned int *)(addr+24));
8174 + err |= get_user(nop, (unsigned int *)(addr+28));
8175 + if (err)
8176 + break;
8177 +
8178 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8179 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8180 + (or1 & 0xFFFFE000U) == 0x88112000U &&
8181 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8182 + sllx == 0x89293020U &&
8183 + add == 0x8A010005U &&
8184 + jmpl == 0x89C14000U &&
8185 + nop == 0x01000000U)
8186 + {
8187 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8188 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8189 + regs->u_regs[UREG_G4] <<= 32;
8190 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8191 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8192 + regs->u_regs[UREG_G4] = addr + 24;
8193 + addr = regs->u_regs[UREG_G5];
8194 + regs->tpc = addr;
8195 + regs->tnpc = addr+4;
8196 + return 3;
8197 + }
8198 + }
8199 + } while (0);
8200 +
8201 +#ifdef CONFIG_PAX_DLRESOLVE
8202 + do { /* PaX: unpatched PLT emulation step 2 */
8203 + unsigned int save, call, nop;
8204 +
8205 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8206 + err |= get_user(call, (unsigned int *)regs->tpc);
8207 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8208 + if (err)
8209 + break;
8210 +
8211 + if (save == 0x9DE3BFA8U &&
8212 + (call & 0xC0000000U) == 0x40000000U &&
8213 + nop == 0x01000000U)
8214 + {
8215 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8216 +
8217 + if (test_thread_flag(TIF_32BIT))
8218 + dl_resolve &= 0xFFFFFFFFUL;
8219 +
8220 + regs->u_regs[UREG_RETPC] = regs->tpc;
8221 + regs->tpc = dl_resolve;
8222 + regs->tnpc = dl_resolve+4;
8223 + return 3;
8224 + }
8225 + } while (0);
8226 +#endif
8227 +
8228 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8229 + unsigned int sethi, ba, nop;
8230 +
8231 + err = get_user(sethi, (unsigned int *)regs->tpc);
8232 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8233 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8234 +
8235 + if (err)
8236 + break;
8237 +
8238 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8239 + (ba & 0xFFF00000U) == 0x30600000U &&
8240 + nop == 0x01000000U)
8241 + {
8242 + unsigned long addr;
8243 +
8244 + addr = (sethi & 0x003FFFFFU) << 10;
8245 + regs->u_regs[UREG_G1] = addr;
8246 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8247 +
8248 + if (test_thread_flag(TIF_32BIT))
8249 + addr &= 0xFFFFFFFFUL;
8250 +
8251 + regs->tpc = addr;
8252 + regs->tnpc = addr+4;
8253 + return 2;
8254 + }
8255 + } while (0);
8256 +
8257 +#endif
8258 +
8259 + return 1;
8260 +}
8261 +
8262 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8263 +{
8264 + unsigned long i;
8265 +
8266 + printk(KERN_ERR "PAX: bytes at PC: ");
8267 + for (i = 0; i < 8; i++) {
8268 + unsigned int c;
8269 + if (get_user(c, (unsigned int *)pc+i))
8270 + printk(KERN_CONT "???????? ");
8271 + else
8272 + printk(KERN_CONT "%08x ", c);
8273 + }
8274 + printk("\n");
8275 +}
8276 +#endif
8277 +
8278 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8279 {
8280 struct mm_struct *mm = current->mm;
8281 @@ -341,6 +804,29 @@ retry:
8282 if (!vma)
8283 goto bad_area;
8284
8285 +#ifdef CONFIG_PAX_PAGEEXEC
8286 + /* PaX: detect ITLB misses on non-exec pages */
8287 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8288 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8289 + {
8290 + if (address != regs->tpc)
8291 + goto good_area;
8292 +
8293 + up_read(&mm->mmap_sem);
8294 + switch (pax_handle_fetch_fault(regs)) {
8295 +
8296 +#ifdef CONFIG_PAX_EMUPLT
8297 + case 2:
8298 + case 3:
8299 + return;
8300 +#endif
8301 +
8302 + }
8303 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8304 + do_group_exit(SIGKILL);
8305 + }
8306 +#endif
8307 +
8308 /* Pure DTLB misses do not tell us whether the fault causing
8309 * load/store/atomic was a write or not, it only says that there
8310 * was no match. So in such a case we (carefully) read the
8311 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8312 index f76f83d..ee0d859 100644
8313 --- a/arch/sparc/mm/hugetlbpage.c
8314 +++ b/arch/sparc/mm/hugetlbpage.c
8315 @@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8316 struct vm_area_struct * vma;
8317 unsigned long task_size = TASK_SIZE;
8318 unsigned long start_addr;
8319 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8320
8321 if (test_thread_flag(TIF_32BIT))
8322 task_size = STACK_TOP32;
8323 @@ -67,7 +68,7 @@ full_search:
8324 }
8325 return -ENOMEM;
8326 }
8327 - if (likely(!vma || addr + len <= vma->vm_start)) {
8328 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8329 /*
8330 * Remember the place where we stopped the search:
8331 */
8332 @@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8333 struct vm_area_struct *vma;
8334 struct mm_struct *mm = current->mm;
8335 unsigned long addr = addr0;
8336 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8337
8338 /* This should only ever run for 32-bit processes. */
8339 BUG_ON(!test_thread_flag(TIF_32BIT));
8340 @@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8341 /* make sure it can fit in the remaining address space */
8342 if (likely(addr > len)) {
8343 vma = find_vma(mm, addr-len);
8344 - if (!vma || addr <= vma->vm_start) {
8345 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8346 /* remember the address as a hint for next time */
8347 return (mm->free_area_cache = addr-len);
8348 }
8349 @@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8350 if (unlikely(mm->mmap_base < len))
8351 goto bottomup;
8352
8353 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8354 + addr = mm->mmap_base - len;
8355
8356 do {
8357 + addr &= HPAGE_MASK;
8358 /*
8359 * Lookup failure means no vma is above this address,
8360 * else if new region fits below vma->vm_start,
8361 * return with success:
8362 */
8363 vma = find_vma(mm, addr);
8364 - if (likely(!vma || addr+len <= vma->vm_start)) {
8365 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8366 /* remember the address as a hint for next time */
8367 return (mm->free_area_cache = addr);
8368 }
8369 @@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8370 mm->cached_hole_size = vma->vm_start - addr;
8371
8372 /* try just below the current vma->vm_start */
8373 - addr = (vma->vm_start-len) & HPAGE_MASK;
8374 - } while (likely(len < vma->vm_start));
8375 + addr = skip_heap_stack_gap(vma, len, offset);
8376 + } while (!IS_ERR_VALUE(addr));
8377
8378 bottomup:
8379 /*
8380 @@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8381 struct mm_struct *mm = current->mm;
8382 struct vm_area_struct *vma;
8383 unsigned long task_size = TASK_SIZE;
8384 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8385
8386 if (test_thread_flag(TIF_32BIT))
8387 task_size = STACK_TOP32;
8388 @@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8389 if (addr) {
8390 addr = ALIGN(addr, HPAGE_SIZE);
8391 vma = find_vma(mm, addr);
8392 - if (task_size - len >= addr &&
8393 - (!vma || addr + len <= vma->vm_start))
8394 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8395 return addr;
8396 }
8397 if (mm->get_unmapped_area == arch_get_unmapped_area)
8398 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8399 index f4500c6..889656c 100644
8400 --- a/arch/tile/include/asm/atomic_64.h
8401 +++ b/arch/tile/include/asm/atomic_64.h
8402 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8403
8404 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8405
8406 +#define atomic64_read_unchecked(v) atomic64_read(v)
8407 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8408 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8409 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8410 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8411 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8412 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8413 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8414 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8415 +
8416 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8417 #define smp_mb__before_atomic_dec() smp_mb()
8418 #define smp_mb__after_atomic_dec() smp_mb()
8419 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8420 index a9a5299..0fce79e 100644
8421 --- a/arch/tile/include/asm/cache.h
8422 +++ b/arch/tile/include/asm/cache.h
8423 @@ -15,11 +15,12 @@
8424 #ifndef _ASM_TILE_CACHE_H
8425 #define _ASM_TILE_CACHE_H
8426
8427 +#include <linux/const.h>
8428 #include <arch/chip.h>
8429
8430 /* bytes per L1 data cache line */
8431 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8432 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8433 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8434
8435 /* bytes per L2 cache line */
8436 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8437 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8438 index 9ab078a..d6635c2 100644
8439 --- a/arch/tile/include/asm/uaccess.h
8440 +++ b/arch/tile/include/asm/uaccess.h
8441 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8442 const void __user *from,
8443 unsigned long n)
8444 {
8445 - int sz = __compiletime_object_size(to);
8446 + size_t sz = __compiletime_object_size(to);
8447
8448 - if (likely(sz == -1 || sz >= n))
8449 + if (likely(sz == (size_t)-1 || sz >= n))
8450 n = _copy_from_user(to, from, n);
8451 else
8452 copy_from_user_overflow();
8453 diff --git a/arch/um/Makefile b/arch/um/Makefile
8454 index 133f7de..1d6f2f1 100644
8455 --- a/arch/um/Makefile
8456 +++ b/arch/um/Makefile
8457 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8458 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8459 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8460
8461 +ifdef CONSTIFY_PLUGIN
8462 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8463 +endif
8464 +
8465 #This will adjust *FLAGS accordingly to the platform.
8466 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8467
8468 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8469 index 19e1bdd..3665b77 100644
8470 --- a/arch/um/include/asm/cache.h
8471 +++ b/arch/um/include/asm/cache.h
8472 @@ -1,6 +1,7 @@
8473 #ifndef __UM_CACHE_H
8474 #define __UM_CACHE_H
8475
8476 +#include <linux/const.h>
8477
8478 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8479 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8480 @@ -12,6 +13,6 @@
8481 # define L1_CACHE_SHIFT 5
8482 #endif
8483
8484 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8485 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8486
8487 #endif
8488 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8489 index 2e0a6b1..a64d0f5 100644
8490 --- a/arch/um/include/asm/kmap_types.h
8491 +++ b/arch/um/include/asm/kmap_types.h
8492 @@ -8,6 +8,6 @@
8493
8494 /* No more #include "asm/arch/kmap_types.h" ! */
8495
8496 -#define KM_TYPE_NR 14
8497 +#define KM_TYPE_NR 15
8498
8499 #endif
8500 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8501 index 5ff53d9..5850cdf 100644
8502 --- a/arch/um/include/asm/page.h
8503 +++ b/arch/um/include/asm/page.h
8504 @@ -14,6 +14,9 @@
8505 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8506 #define PAGE_MASK (~(PAGE_SIZE-1))
8507
8508 +#define ktla_ktva(addr) (addr)
8509 +#define ktva_ktla(addr) (addr)
8510 +
8511 #ifndef __ASSEMBLY__
8512
8513 struct page;
8514 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8515 index 0032f92..cd151e0 100644
8516 --- a/arch/um/include/asm/pgtable-3level.h
8517 +++ b/arch/um/include/asm/pgtable-3level.h
8518 @@ -58,6 +58,7 @@
8519 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8520 #define pud_populate(mm, pud, pmd) \
8521 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8522 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8523
8524 #ifdef CONFIG_64BIT
8525 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8526 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8527 index b6d699c..df7ac1d 100644
8528 --- a/arch/um/kernel/process.c
8529 +++ b/arch/um/kernel/process.c
8530 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8531 return 2;
8532 }
8533
8534 -/*
8535 - * Only x86 and x86_64 have an arch_align_stack().
8536 - * All other arches have "#define arch_align_stack(x) (x)"
8537 - * in their asm/system.h
8538 - * As this is included in UML from asm-um/system-generic.h,
8539 - * we can use it to behave as the subarch does.
8540 - */
8541 -#ifndef arch_align_stack
8542 -unsigned long arch_align_stack(unsigned long sp)
8543 -{
8544 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8545 - sp -= get_random_int() % 8192;
8546 - return sp & ~0xf;
8547 -}
8548 -#endif
8549 -
8550 unsigned long get_wchan(struct task_struct *p)
8551 {
8552 unsigned long stack_page, sp, ip;
8553 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8554 index ad8f795..2c7eec6 100644
8555 --- a/arch/unicore32/include/asm/cache.h
8556 +++ b/arch/unicore32/include/asm/cache.h
8557 @@ -12,8 +12,10 @@
8558 #ifndef __UNICORE_CACHE_H__
8559 #define __UNICORE_CACHE_H__
8560
8561 -#define L1_CACHE_SHIFT (5)
8562 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8563 +#include <linux/const.h>
8564 +
8565 +#define L1_CACHE_SHIFT 5
8566 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8567
8568 /*
8569 * Memory returned by kmalloc() may be used for DMA, so we must make
8570 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8571 index 46c3bff..da289d1 100644
8572 --- a/arch/x86/Kconfig
8573 +++ b/arch/x86/Kconfig
8574 @@ -241,7 +241,7 @@ config X86_HT
8575
8576 config X86_32_LAZY_GS
8577 def_bool y
8578 - depends on X86_32 && !CC_STACKPROTECTOR
8579 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8580
8581 config ARCH_HWEIGHT_CFLAGS
8582 string
8583 @@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8584
8585 config X86_MSR
8586 tristate "/dev/cpu/*/msr - Model-specific register support"
8587 + depends on !GRKERNSEC_KMEM
8588 ---help---
8589 This device gives privileged processes access to the x86
8590 Model-Specific Registers (MSRs). It is a character device with
8591 @@ -1056,7 +1057,7 @@ choice
8592
8593 config NOHIGHMEM
8594 bool "off"
8595 - depends on !X86_NUMAQ
8596 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8597 ---help---
8598 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8599 However, the address space of 32-bit x86 processors is only 4
8600 @@ -1093,7 +1094,7 @@ config NOHIGHMEM
8601
8602 config HIGHMEM4G
8603 bool "4GB"
8604 - depends on !X86_NUMAQ
8605 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8606 ---help---
8607 Select this if you have a 32-bit processor and between 1 and 4
8608 gigabytes of physical RAM.
8609 @@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8610 hex
8611 default 0xB0000000 if VMSPLIT_3G_OPT
8612 default 0x80000000 if VMSPLIT_2G
8613 - default 0x78000000 if VMSPLIT_2G_OPT
8614 + default 0x70000000 if VMSPLIT_2G_OPT
8615 default 0x40000000 if VMSPLIT_1G
8616 default 0xC0000000
8617 depends on X86_32
8618 @@ -1548,6 +1549,7 @@ config SECCOMP
8619
8620 config CC_STACKPROTECTOR
8621 bool "Enable -fstack-protector buffer overflow detection"
8622 + depends on X86_64 || !PAX_MEMORY_UDEREF
8623 ---help---
8624 This option turns on the -fstack-protector GCC feature. This
8625 feature puts, at the beginning of functions, a canary value on
8626 @@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8627 config PHYSICAL_START
8628 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8629 default "0x1000000"
8630 + range 0x400000 0x40000000
8631 ---help---
8632 This gives the physical address where the kernel is loaded.
8633
8634 @@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8635 config PHYSICAL_ALIGN
8636 hex "Alignment value to which kernel should be aligned" if X86_32
8637 default "0x1000000"
8638 + range 0x400000 0x1000000 if PAX_KERNEXEC
8639 range 0x2000 0x1000000
8640 ---help---
8641 This value puts the alignment restrictions on physical address
8642 @@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8643 Say N if you want to disable CPU hotplug.
8644
8645 config COMPAT_VDSO
8646 - def_bool y
8647 + def_bool n
8648 prompt "Compat VDSO support"
8649 depends on X86_32 || IA32_EMULATION
8650 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
8651 ---help---
8652 Map the 32-bit VDSO to the predictable old-style address too.
8653
8654 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8655 index f3b86d0..17fd30f 100644
8656 --- a/arch/x86/Kconfig.cpu
8657 +++ b/arch/x86/Kconfig.cpu
8658 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8659
8660 config X86_F00F_BUG
8661 def_bool y
8662 - depends on M586MMX || M586TSC || M586 || M486 || M386
8663 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8664
8665 config X86_INVD_BUG
8666 def_bool y
8667 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8668
8669 config X86_ALIGNMENT_16
8670 def_bool y
8671 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8672 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8673
8674 config X86_INTEL_USERCOPY
8675 def_bool y
8676 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8677 # generates cmov.
8678 config X86_CMOV
8679 def_bool y
8680 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8681 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8682
8683 config X86_MINIMUM_CPU_FAMILY
8684 int
8685 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8686 index b322f12..652d0d9 100644
8687 --- a/arch/x86/Kconfig.debug
8688 +++ b/arch/x86/Kconfig.debug
8689 @@ -84,7 +84,7 @@ config X86_PTDUMP
8690 config DEBUG_RODATA
8691 bool "Write protect kernel read-only data structures"
8692 default y
8693 - depends on DEBUG_KERNEL
8694 + depends on DEBUG_KERNEL && BROKEN
8695 ---help---
8696 Mark the kernel read-only data as write-protected in the pagetables,
8697 in order to catch accidental (and incorrect) writes to such const
8698 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8699
8700 config DEBUG_SET_MODULE_RONX
8701 bool "Set loadable kernel module data as NX and text as RO"
8702 - depends on MODULES
8703 + depends on MODULES && BROKEN
8704 ---help---
8705 This option helps catch unintended modifications to loadable
8706 kernel module's text and read-only data. It also prevents execution
8707 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8708
8709 config DEBUG_STRICT_USER_COPY_CHECKS
8710 bool "Strict copy size checks"
8711 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8712 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8713 ---help---
8714 Enabling this option turns a certain set of sanity checks for user
8715 copy operations into compile time failures.
8716 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8717 index 05afcca..b6ecb51 100644
8718 --- a/arch/x86/Makefile
8719 +++ b/arch/x86/Makefile
8720 @@ -50,6 +50,7 @@ else
8721 UTS_MACHINE := x86_64
8722 CHECKFLAGS += -D__x86_64__ -m64
8723
8724 + biarch := $(call cc-option,-m64)
8725 KBUILD_AFLAGS += -m64
8726 KBUILD_CFLAGS += -m64
8727
8728 @@ -229,3 +230,12 @@ define archhelp
8729 echo ' FDARGS="..." arguments for the booted kernel'
8730 echo ' FDINITRD=file initrd for the booted kernel'
8731 endef
8732 +
8733 +define OLD_LD
8734 +
8735 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8736 +*** Please upgrade your binutils to 2.18 or newer
8737 +endef
8738 +
8739 +archprepare:
8740 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8741 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8742 index ccce0ed..fd9da25 100644
8743 --- a/arch/x86/boot/Makefile
8744 +++ b/arch/x86/boot/Makefile
8745 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8746 $(call cc-option, -fno-stack-protector) \
8747 $(call cc-option, -mpreferred-stack-boundary=2)
8748 KBUILD_CFLAGS += $(call cc-option, -m32)
8749 +ifdef CONSTIFY_PLUGIN
8750 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8751 +endif
8752 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8753 GCOV_PROFILE := n
8754
8755 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8756 index 878e4b9..20537ab 100644
8757 --- a/arch/x86/boot/bitops.h
8758 +++ b/arch/x86/boot/bitops.h
8759 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8760 u8 v;
8761 const u32 *p = (const u32 *)addr;
8762
8763 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8764 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8765 return v;
8766 }
8767
8768 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8769
8770 static inline void set_bit(int nr, void *addr)
8771 {
8772 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8773 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8774 }
8775
8776 #endif /* BOOT_BITOPS_H */
8777 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8778 index 18997e5..83d9c67 100644
8779 --- a/arch/x86/boot/boot.h
8780 +++ b/arch/x86/boot/boot.h
8781 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8782 static inline u16 ds(void)
8783 {
8784 u16 seg;
8785 - asm("movw %%ds,%0" : "=rm" (seg));
8786 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8787 return seg;
8788 }
8789
8790 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8791 static inline int memcmp(const void *s1, const void *s2, size_t len)
8792 {
8793 u8 diff;
8794 - asm("repe; cmpsb; setnz %0"
8795 + asm volatile("repe; cmpsb; setnz %0"
8796 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8797 return diff;
8798 }
8799 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8800 index 8a84501..b2d165f 100644
8801 --- a/arch/x86/boot/compressed/Makefile
8802 +++ b/arch/x86/boot/compressed/Makefile
8803 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8804 KBUILD_CFLAGS += $(cflags-y)
8805 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8806 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8807 +ifdef CONSTIFY_PLUGIN
8808 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8809 +endif
8810
8811 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8812 GCOV_PROFILE := n
8813 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8814 index e87b0ca..2bce457 100644
8815 --- a/arch/x86/boot/compressed/eboot.c
8816 +++ b/arch/x86/boot/compressed/eboot.c
8817 @@ -144,7 +144,6 @@ again:
8818 *addr = max_addr;
8819 }
8820
8821 -free_pool:
8822 efi_call_phys1(sys_table->boottime->free_pool, map);
8823
8824 fail:
8825 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8826 if (i == map_size / desc_size)
8827 status = EFI_NOT_FOUND;
8828
8829 -free_pool:
8830 efi_call_phys1(sys_table->boottime->free_pool, map);
8831 fail:
8832 return status;
8833 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8834 index aa4aaf1..6656f2f 100644
8835 --- a/arch/x86/boot/compressed/head_32.S
8836 +++ b/arch/x86/boot/compressed/head_32.S
8837 @@ -116,7 +116,7 @@ preferred_addr:
8838 notl %eax
8839 andl %eax, %ebx
8840 #else
8841 - movl $LOAD_PHYSICAL_ADDR, %ebx
8842 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8843 #endif
8844
8845 /* Target address to relocate to for decompression */
8846 @@ -202,7 +202,7 @@ relocated:
8847 * and where it was actually loaded.
8848 */
8849 movl %ebp, %ebx
8850 - subl $LOAD_PHYSICAL_ADDR, %ebx
8851 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8852 jz 2f /* Nothing to be done if loaded at compiled addr. */
8853 /*
8854 * Process relocations.
8855 @@ -210,8 +210,7 @@ relocated:
8856
8857 1: subl $4, %edi
8858 movl (%edi), %ecx
8859 - testl %ecx, %ecx
8860 - jz 2f
8861 + jecxz 2f
8862 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8863 jmp 1b
8864 2:
8865 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8866 index 2c4b171..e1fa5b1 100644
8867 --- a/arch/x86/boot/compressed/head_64.S
8868 +++ b/arch/x86/boot/compressed/head_64.S
8869 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8870 notl %eax
8871 andl %eax, %ebx
8872 #else
8873 - movl $LOAD_PHYSICAL_ADDR, %ebx
8874 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8875 #endif
8876
8877 /* Target address to relocate to for decompression */
8878 @@ -273,7 +273,7 @@ preferred_addr:
8879 notq %rax
8880 andq %rax, %rbp
8881 #else
8882 - movq $LOAD_PHYSICAL_ADDR, %rbp
8883 + movq $____LOAD_PHYSICAL_ADDR, %rbp
8884 #endif
8885
8886 /* Target address to relocate to for decompression */
8887 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
8888 index 88f7ff6..ed695dd 100644
8889 --- a/arch/x86/boot/compressed/misc.c
8890 +++ b/arch/x86/boot/compressed/misc.c
8891 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
8892 case PT_LOAD:
8893 #ifdef CONFIG_RELOCATABLE
8894 dest = output;
8895 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
8896 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
8897 #else
8898 dest = (void *)(phdr->p_paddr);
8899 #endif
8900 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
8901 error("Destination address too large");
8902 #endif
8903 #ifndef CONFIG_RELOCATABLE
8904 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
8905 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
8906 error("Wrong destination address");
8907 #endif
8908
8909 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8910 index 4d3ff03..e4972ff 100644
8911 --- a/arch/x86/boot/cpucheck.c
8912 +++ b/arch/x86/boot/cpucheck.c
8913 @@ -74,7 +74,7 @@ static int has_fpu(void)
8914 u16 fcw = -1, fsw = -1;
8915 u32 cr0;
8916
8917 - asm("movl %%cr0,%0" : "=r" (cr0));
8918 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
8919 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8920 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8921 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8922 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8923 {
8924 u32 f0, f1;
8925
8926 - asm("pushfl ; "
8927 + asm volatile("pushfl ; "
8928 "pushfl ; "
8929 "popl %0 ; "
8930 "movl %0,%1 ; "
8931 @@ -115,7 +115,7 @@ static void get_flags(void)
8932 set_bit(X86_FEATURE_FPU, cpu.flags);
8933
8934 if (has_eflag(X86_EFLAGS_ID)) {
8935 - asm("cpuid"
8936 + asm volatile("cpuid"
8937 : "=a" (max_intel_level),
8938 "=b" (cpu_vendor[0]),
8939 "=d" (cpu_vendor[1]),
8940 @@ -124,7 +124,7 @@ static void get_flags(void)
8941
8942 if (max_intel_level >= 0x00000001 &&
8943 max_intel_level <= 0x0000ffff) {
8944 - asm("cpuid"
8945 + asm volatile("cpuid"
8946 : "=a" (tfms),
8947 "=c" (cpu.flags[4]),
8948 "=d" (cpu.flags[0])
8949 @@ -136,7 +136,7 @@ static void get_flags(void)
8950 cpu.model += ((tfms >> 16) & 0xf) << 4;
8951 }
8952
8953 - asm("cpuid"
8954 + asm volatile("cpuid"
8955 : "=a" (max_amd_level)
8956 : "a" (0x80000000)
8957 : "ebx", "ecx", "edx");
8958 @@ -144,7 +144,7 @@ static void get_flags(void)
8959 if (max_amd_level >= 0x80000001 &&
8960 max_amd_level <= 0x8000ffff) {
8961 u32 eax = 0x80000001;
8962 - asm("cpuid"
8963 + asm volatile("cpuid"
8964 : "+a" (eax),
8965 "=c" (cpu.flags[6]),
8966 "=d" (cpu.flags[1])
8967 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8968 u32 ecx = MSR_K7_HWCR;
8969 u32 eax, edx;
8970
8971 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8972 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8973 eax &= ~(1 << 15);
8974 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8975 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8976
8977 get_flags(); /* Make sure it really did something */
8978 err = check_flags();
8979 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8980 u32 ecx = MSR_VIA_FCR;
8981 u32 eax, edx;
8982
8983 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8984 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8985 eax |= (1<<1)|(1<<7);
8986 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8987 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8988
8989 set_bit(X86_FEATURE_CX8, cpu.flags);
8990 err = check_flags();
8991 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8992 u32 eax, edx;
8993 u32 level = 1;
8994
8995 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8996 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8997 - asm("cpuid"
8998 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8999 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9000 + asm volatile("cpuid"
9001 : "+a" (level), "=d" (cpu.flags[0])
9002 : : "ecx", "ebx");
9003 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9004 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9005
9006 err = check_flags();
9007 }
9008 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9009 index 8c132a6..13e5c96 100644
9010 --- a/arch/x86/boot/header.S
9011 +++ b/arch/x86/boot/header.S
9012 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9013 # single linked list of
9014 # struct setup_data
9015
9016 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9017 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9018
9019 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9020 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9021 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9022 +#else
9023 #define VO_INIT_SIZE (VO__end - VO__text)
9024 +#endif
9025 #if ZO_INIT_SIZE > VO_INIT_SIZE
9026 #define INIT_SIZE ZO_INIT_SIZE
9027 #else
9028 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9029 index db75d07..8e6d0af 100644
9030 --- a/arch/x86/boot/memory.c
9031 +++ b/arch/x86/boot/memory.c
9032 @@ -19,7 +19,7 @@
9033
9034 static int detect_memory_e820(void)
9035 {
9036 - int count = 0;
9037 + unsigned int count = 0;
9038 struct biosregs ireg, oreg;
9039 struct e820entry *desc = boot_params.e820_map;
9040 static struct e820entry buf; /* static so it is zeroed */
9041 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9042 index 11e8c6e..fdbb1ed 100644
9043 --- a/arch/x86/boot/video-vesa.c
9044 +++ b/arch/x86/boot/video-vesa.c
9045 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9046
9047 boot_params.screen_info.vesapm_seg = oreg.es;
9048 boot_params.screen_info.vesapm_off = oreg.di;
9049 + boot_params.screen_info.vesapm_size = oreg.cx;
9050 }
9051
9052 /*
9053 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9054 index 43eda28..5ab5fdb 100644
9055 --- a/arch/x86/boot/video.c
9056 +++ b/arch/x86/boot/video.c
9057 @@ -96,7 +96,7 @@ static void store_mode_params(void)
9058 static unsigned int get_entry(void)
9059 {
9060 char entry_buf[4];
9061 - int i, len = 0;
9062 + unsigned int i, len = 0;
9063 int key;
9064 unsigned int v;
9065
9066 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9067 index 5b577d5..3c1fed4 100644
9068 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
9069 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9070 @@ -8,6 +8,8 @@
9071 * including this sentence is retained in full.
9072 */
9073
9074 +#include <asm/alternative-asm.h>
9075 +
9076 .extern crypto_ft_tab
9077 .extern crypto_it_tab
9078 .extern crypto_fl_tab
9079 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9080 je B192; \
9081 leaq 32(r9),r9;
9082
9083 +#define ret pax_force_retaddr 0, 1; ret
9084 +
9085 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9086 movq r1,r2; \
9087 movq r3,r4; \
9088 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9089 index 3470624..201259d 100644
9090 --- a/arch/x86/crypto/aesni-intel_asm.S
9091 +++ b/arch/x86/crypto/aesni-intel_asm.S
9092 @@ -31,6 +31,7 @@
9093
9094 #include <linux/linkage.h>
9095 #include <asm/inst.h>
9096 +#include <asm/alternative-asm.h>
9097
9098 #ifdef __x86_64__
9099 .data
9100 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9101 pop %r14
9102 pop %r13
9103 pop %r12
9104 + pax_force_retaddr 0, 1
9105 ret
9106 +ENDPROC(aesni_gcm_dec)
9107
9108
9109 /*****************************************************************************
9110 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9111 pop %r14
9112 pop %r13
9113 pop %r12
9114 + pax_force_retaddr 0, 1
9115 ret
9116 +ENDPROC(aesni_gcm_enc)
9117
9118 #endif
9119
9120 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
9121 pxor %xmm1, %xmm0
9122 movaps %xmm0, (TKEYP)
9123 add $0x10, TKEYP
9124 + pax_force_retaddr_bts
9125 ret
9126
9127 .align 4
9128 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
9129 shufps $0b01001110, %xmm2, %xmm1
9130 movaps %xmm1, 0x10(TKEYP)
9131 add $0x20, TKEYP
9132 + pax_force_retaddr_bts
9133 ret
9134
9135 .align 4
9136 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
9137
9138 movaps %xmm0, (TKEYP)
9139 add $0x10, TKEYP
9140 + pax_force_retaddr_bts
9141 ret
9142
9143 .align 4
9144 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
9145 pxor %xmm1, %xmm2
9146 movaps %xmm2, (TKEYP)
9147 add $0x10, TKEYP
9148 + pax_force_retaddr_bts
9149 ret
9150
9151 /*
9152 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9153 #ifndef __x86_64__
9154 popl KEYP
9155 #endif
9156 + pax_force_retaddr 0, 1
9157 ret
9158 +ENDPROC(aesni_set_key)
9159
9160 /*
9161 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9162 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9163 popl KLEN
9164 popl KEYP
9165 #endif
9166 + pax_force_retaddr 0, 1
9167 ret
9168 +ENDPROC(aesni_enc)
9169
9170 /*
9171 * _aesni_enc1: internal ABI
9172 @@ -1959,6 +1972,7 @@ _aesni_enc1:
9173 AESENC KEY STATE
9174 movaps 0x70(TKEYP), KEY
9175 AESENCLAST KEY STATE
9176 + pax_force_retaddr_bts
9177 ret
9178
9179 /*
9180 @@ -2067,6 +2081,7 @@ _aesni_enc4:
9181 AESENCLAST KEY STATE2
9182 AESENCLAST KEY STATE3
9183 AESENCLAST KEY STATE4
9184 + pax_force_retaddr_bts
9185 ret
9186
9187 /*
9188 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9189 popl KLEN
9190 popl KEYP
9191 #endif
9192 + pax_force_retaddr 0, 1
9193 ret
9194 +ENDPROC(aesni_dec)
9195
9196 /*
9197 * _aesni_dec1: internal ABI
9198 @@ -2146,6 +2163,7 @@ _aesni_dec1:
9199 AESDEC KEY STATE
9200 movaps 0x70(TKEYP), KEY
9201 AESDECLAST KEY STATE
9202 + pax_force_retaddr_bts
9203 ret
9204
9205 /*
9206 @@ -2254,6 +2272,7 @@ _aesni_dec4:
9207 AESDECLAST KEY STATE2
9208 AESDECLAST KEY STATE3
9209 AESDECLAST KEY STATE4
9210 + pax_force_retaddr_bts
9211 ret
9212
9213 /*
9214 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9215 popl KEYP
9216 popl LEN
9217 #endif
9218 + pax_force_retaddr 0, 1
9219 ret
9220 +ENDPROC(aesni_ecb_enc)
9221
9222 /*
9223 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9224 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9225 popl KEYP
9226 popl LEN
9227 #endif
9228 + pax_force_retaddr 0, 1
9229 ret
9230 +ENDPROC(aesni_ecb_dec)
9231
9232 /*
9233 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9234 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9235 popl LEN
9236 popl IVP
9237 #endif
9238 + pax_force_retaddr 0, 1
9239 ret
9240 +ENDPROC(aesni_cbc_enc)
9241
9242 /*
9243 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9244 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9245 popl LEN
9246 popl IVP
9247 #endif
9248 + pax_force_retaddr 0, 1
9249 ret
9250 +ENDPROC(aesni_cbc_dec)
9251
9252 #ifdef __x86_64__
9253 .align 16
9254 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9255 mov $1, TCTR_LOW
9256 MOVQ_R64_XMM TCTR_LOW INC
9257 MOVQ_R64_XMM CTR TCTR_LOW
9258 + pax_force_retaddr_bts
9259 ret
9260
9261 /*
9262 @@ -2554,6 +2582,7 @@ _aesni_inc:
9263 .Linc_low:
9264 movaps CTR, IV
9265 PSHUFB_XMM BSWAP_MASK IV
9266 + pax_force_retaddr_bts
9267 ret
9268
9269 /*
9270 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9271 .Lctr_enc_ret:
9272 movups IV, (IVP)
9273 .Lctr_enc_just_ret:
9274 + pax_force_retaddr 0, 1
9275 ret
9276 +ENDPROC(aesni_ctr_enc)
9277 #endif
9278 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9279 index 391d245..67f35c2 100644
9280 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9281 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9282 @@ -20,6 +20,8 @@
9283 *
9284 */
9285
9286 +#include <asm/alternative-asm.h>
9287 +
9288 .file "blowfish-x86_64-asm.S"
9289 .text
9290
9291 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9292 jnz __enc_xor;
9293
9294 write_block();
9295 + pax_force_retaddr 0, 1
9296 ret;
9297 __enc_xor:
9298 xor_block();
9299 + pax_force_retaddr 0, 1
9300 ret;
9301
9302 .align 8
9303 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9304
9305 movq %r11, %rbp;
9306
9307 + pax_force_retaddr 0, 1
9308 ret;
9309
9310 /**********************************************************************
9311 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9312
9313 popq %rbx;
9314 popq %rbp;
9315 + pax_force_retaddr 0, 1
9316 ret;
9317
9318 __enc_xor4:
9319 @@ -349,6 +355,7 @@ __enc_xor4:
9320
9321 popq %rbx;
9322 popq %rbp;
9323 + pax_force_retaddr 0, 1
9324 ret;
9325
9326 .align 8
9327 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9328 popq %rbx;
9329 popq %rbp;
9330
9331 + pax_force_retaddr 0, 1
9332 ret;
9333
9334 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9335 index 0b33743..7a56206 100644
9336 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9337 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9338 @@ -20,6 +20,8 @@
9339 *
9340 */
9341
9342 +#include <asm/alternative-asm.h>
9343 +
9344 .file "camellia-x86_64-asm_64.S"
9345 .text
9346
9347 @@ -229,12 +231,14 @@ __enc_done:
9348 enc_outunpack(mov, RT1);
9349
9350 movq RRBP, %rbp;
9351 + pax_force_retaddr 0, 1
9352 ret;
9353
9354 __enc_xor:
9355 enc_outunpack(xor, RT1);
9356
9357 movq RRBP, %rbp;
9358 + pax_force_retaddr 0, 1
9359 ret;
9360
9361 .global camellia_dec_blk;
9362 @@ -275,6 +279,7 @@ __dec_rounds16:
9363 dec_outunpack();
9364
9365 movq RRBP, %rbp;
9366 + pax_force_retaddr 0, 1
9367 ret;
9368
9369 /**********************************************************************
9370 @@ -468,6 +473,7 @@ __enc2_done:
9371
9372 movq RRBP, %rbp;
9373 popq %rbx;
9374 + pax_force_retaddr 0, 1
9375 ret;
9376
9377 __enc2_xor:
9378 @@ -475,6 +481,7 @@ __enc2_xor:
9379
9380 movq RRBP, %rbp;
9381 popq %rbx;
9382 + pax_force_retaddr 0, 1
9383 ret;
9384
9385 .global camellia_dec_blk_2way;
9386 @@ -517,4 +524,5 @@ __dec2_rounds16:
9387
9388 movq RRBP, %rbp;
9389 movq RXOR, %rbx;
9390 + pax_force_retaddr 0, 1
9391 ret;
9392 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9393 index a41a3aa..bdf5753 100644
9394 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9395 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9396 @@ -23,6 +23,8 @@
9397 *
9398 */
9399
9400 +#include <asm/alternative-asm.h>
9401 +
9402 .file "cast5-avx-x86_64-asm_64.S"
9403
9404 .extern cast5_s1
9405 @@ -293,6 +295,7 @@ __skip_enc:
9406 leaq 3*(2*4*4)(%r11), %rax;
9407 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9408
9409 + pax_force_retaddr 0, 1
9410 ret;
9411
9412 __enc_xor16:
9413 @@ -303,6 +306,7 @@ __enc_xor16:
9414 leaq 3*(2*4*4)(%r11), %rax;
9415 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9416
9417 + pax_force_retaddr 0, 1
9418 ret;
9419
9420 .align 16
9421 @@ -369,6 +373,7 @@ __dec_tail:
9422 leaq 3*(2*4*4)(%r11), %rax;
9423 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9424
9425 + pax_force_retaddr 0, 1
9426 ret;
9427
9428 __skip_dec:
9429 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9430 index 218d283..819e6da 100644
9431 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9432 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9433 @@ -23,6 +23,8 @@
9434 *
9435 */
9436
9437 +#include <asm/alternative-asm.h>
9438 +
9439 .file "cast6-avx-x86_64-asm_64.S"
9440
9441 .extern cast6_s1
9442 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9443 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9444 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9445
9446 + pax_force_retaddr 0, 1
9447 ret;
9448
9449 __enc_xor8:
9450 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9451 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9452
9453 + pax_force_retaddr 0, 1
9454 ret;
9455
9456 .align 16
9457 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9458 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9459 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9460
9461 + pax_force_retaddr 0, 1
9462 ret;
9463 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9464 index 6214a9b..1f4fc9a 100644
9465 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9466 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9467 @@ -1,3 +1,5 @@
9468 +#include <asm/alternative-asm.h>
9469 +
9470 # enter ECRYPT_encrypt_bytes
9471 .text
9472 .p2align 5
9473 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9474 add %r11,%rsp
9475 mov %rdi,%rax
9476 mov %rsi,%rdx
9477 + pax_force_retaddr 0, 1
9478 ret
9479 # bytesatleast65:
9480 ._bytesatleast65:
9481 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9482 add %r11,%rsp
9483 mov %rdi,%rax
9484 mov %rsi,%rdx
9485 + pax_force_retaddr
9486 ret
9487 # enter ECRYPT_ivsetup
9488 .text
9489 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9490 add %r11,%rsp
9491 mov %rdi,%rax
9492 mov %rsi,%rdx
9493 + pax_force_retaddr
9494 ret
9495 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9496 index 504106b..4e50951 100644
9497 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9498 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9499 @@ -24,6 +24,8 @@
9500 *
9501 */
9502
9503 +#include <asm/alternative-asm.h>
9504 +
9505 .file "serpent-avx-x86_64-asm_64.S"
9506 .text
9507
9508 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9509 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9510 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9511
9512 + pax_force_retaddr
9513 ret;
9514
9515 __enc_xor8:
9516 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9517 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9518
9519 + pax_force_retaddr
9520 ret;
9521
9522 .align 8
9523 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9524 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9525 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9526
9527 + pax_force_retaddr
9528 ret;
9529 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9530 index 3ee1ff0..cbc568b 100644
9531 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9532 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9533 @@ -24,6 +24,8 @@
9534 *
9535 */
9536
9537 +#include <asm/alternative-asm.h>
9538 +
9539 .file "serpent-sse2-x86_64-asm_64.S"
9540 .text
9541
9542 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9543 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9544 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9545
9546 + pax_force_retaddr
9547 ret;
9548
9549 __enc_xor8:
9550 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9551 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9552
9553 + pax_force_retaddr
9554 ret;
9555
9556 .align 8
9557 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9558 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9559 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9560
9561 + pax_force_retaddr
9562 ret;
9563 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9564 index 49d6987..df66bd4 100644
9565 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9566 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9567 @@ -28,6 +28,8 @@
9568 * (at your option) any later version.
9569 */
9570
9571 +#include <asm/alternative-asm.h>
9572 +
9573 #define CTX %rdi // arg1
9574 #define BUF %rsi // arg2
9575 #define CNT %rdx // arg3
9576 @@ -104,6 +106,7 @@
9577 pop %r12
9578 pop %rbp
9579 pop %rbx
9580 + pax_force_retaddr 0, 1
9581 ret
9582
9583 .size \name, .-\name
9584 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9585 index 1585abb..4a9af16 100644
9586 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9587 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9588 @@ -23,6 +23,8 @@
9589 *
9590 */
9591
9592 +#include <asm/alternative-asm.h>
9593 +
9594 .file "twofish-avx-x86_64-asm_64.S"
9595 .text
9596
9597 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9598 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9599 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9600
9601 + pax_force_retaddr
9602 ret;
9603
9604 __enc_xor8:
9605 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9606 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9607
9608 + pax_force_retaddr
9609 ret;
9610
9611 .align 8
9612 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9613 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9614 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9615
9616 + pax_force_retaddr
9617 ret;
9618 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9619 index 5b012a2..36d5364 100644
9620 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9621 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9622 @@ -20,6 +20,8 @@
9623 *
9624 */
9625
9626 +#include <asm/alternative-asm.h>
9627 +
9628 .file "twofish-x86_64-asm-3way.S"
9629 .text
9630
9631 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9632 popq %r13;
9633 popq %r14;
9634 popq %r15;
9635 + pax_force_retaddr 0, 1
9636 ret;
9637
9638 __enc_xor3:
9639 @@ -271,6 +274,7 @@ __enc_xor3:
9640 popq %r13;
9641 popq %r14;
9642 popq %r15;
9643 + pax_force_retaddr 0, 1
9644 ret;
9645
9646 .global twofish_dec_blk_3way
9647 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9648 popq %r13;
9649 popq %r14;
9650 popq %r15;
9651 + pax_force_retaddr 0, 1
9652 ret;
9653
9654 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9655 index 7bcf3fc..f53832f 100644
9656 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9657 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9658 @@ -21,6 +21,7 @@
9659 .text
9660
9661 #include <asm/asm-offsets.h>
9662 +#include <asm/alternative-asm.h>
9663
9664 #define a_offset 0
9665 #define b_offset 4
9666 @@ -268,6 +269,7 @@ twofish_enc_blk:
9667
9668 popq R1
9669 movq $1,%rax
9670 + pax_force_retaddr 0, 1
9671 ret
9672
9673 twofish_dec_blk:
9674 @@ -319,4 +321,5 @@ twofish_dec_blk:
9675
9676 popq R1
9677 movq $1,%rax
9678 + pax_force_retaddr 0, 1
9679 ret
9680 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9681 index 07b3a68..bd2a388 100644
9682 --- a/arch/x86/ia32/ia32_aout.c
9683 +++ b/arch/x86/ia32/ia32_aout.c
9684 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9685 unsigned long dump_start, dump_size;
9686 struct user32 dump;
9687
9688 + memset(&dump, 0, sizeof(dump));
9689 +
9690 fs = get_fs();
9691 set_fs(KERNEL_DS);
9692 has_dumped = 1;
9693 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9694 index efc6a95..95abfe2 100644
9695 --- a/arch/x86/ia32/ia32_signal.c
9696 +++ b/arch/x86/ia32/ia32_signal.c
9697 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9698 }
9699 seg = get_fs();
9700 set_fs(KERNEL_DS);
9701 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9702 - (stack_t __force __user *) &uoss, regs->sp);
9703 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9704 + (stack_t __force_user *) &uoss, regs->sp);
9705 set_fs(seg);
9706 if (ret >= 0 && uoss_ptr) {
9707 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9708 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9709 sp -= frame_size;
9710 /* Align the stack pointer according to the i386 ABI,
9711 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9712 - sp = ((sp + 4) & -16ul) - 4;
9713 + sp = ((sp - 12) & -16ul) - 4;
9714 return (void __user *) sp;
9715 }
9716
9717 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9718 * These are actually not used anymore, but left because some
9719 * gdb versions depend on them as a marker.
9720 */
9721 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9722 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9723 } put_user_catch(err);
9724
9725 if (err)
9726 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9727 0xb8,
9728 __NR_ia32_rt_sigreturn,
9729 0x80cd,
9730 - 0,
9731 + 0
9732 };
9733
9734 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9735 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9736
9737 if (ka->sa.sa_flags & SA_RESTORER)
9738 restorer = ka->sa.sa_restorer;
9739 + else if (current->mm->context.vdso)
9740 + /* Return stub is in 32bit vsyscall page */
9741 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9742 else
9743 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9744 - rt_sigreturn);
9745 + restorer = &frame->retcode;
9746 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9747
9748 /*
9749 * Not actually used anymore, but left because some gdb
9750 * versions need it.
9751 */
9752 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9753 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9754 } put_user_catch(err);
9755
9756 err |= copy_siginfo_to_user32(&frame->info, info);
9757 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9758 index 076745f..ae8f6cb 100644
9759 --- a/arch/x86/ia32/ia32entry.S
9760 +++ b/arch/x86/ia32/ia32entry.S
9761 @@ -15,8 +15,10 @@
9762 #include <asm/irqflags.h>
9763 #include <asm/asm.h>
9764 #include <asm/smap.h>
9765 +#include <asm/pgtable.h>
9766 #include <linux/linkage.h>
9767 #include <linux/err.h>
9768 +#include <asm/alternative-asm.h>
9769
9770 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9771 #include <linux/elf-em.h>
9772 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9773 ENDPROC(native_irq_enable_sysexit)
9774 #endif
9775
9776 + .macro pax_enter_kernel_user
9777 + pax_set_fptr_mask
9778 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9779 + call pax_enter_kernel_user
9780 +#endif
9781 + .endm
9782 +
9783 + .macro pax_exit_kernel_user
9784 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9785 + call pax_exit_kernel_user
9786 +#endif
9787 +#ifdef CONFIG_PAX_RANDKSTACK
9788 + pushq %rax
9789 + pushq %r11
9790 + call pax_randomize_kstack
9791 + popq %r11
9792 + popq %rax
9793 +#endif
9794 + .endm
9795 +
9796 +.macro pax_erase_kstack
9797 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9798 + call pax_erase_kstack
9799 +#endif
9800 +.endm
9801 +
9802 /*
9803 * 32bit SYSENTER instruction entry.
9804 *
9805 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9806 CFI_REGISTER rsp,rbp
9807 SWAPGS_UNSAFE_STACK
9808 movq PER_CPU_VAR(kernel_stack), %rsp
9809 - addq $(KERNEL_STACK_OFFSET),%rsp
9810 - /*
9811 - * No need to follow this irqs on/off section: the syscall
9812 - * disabled irqs, here we enable it straight after entry:
9813 - */
9814 - ENABLE_INTERRUPTS(CLBR_NONE)
9815 movl %ebp,%ebp /* zero extension */
9816 pushq_cfi $__USER32_DS
9817 /*CFI_REL_OFFSET ss,0*/
9818 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9819 CFI_REL_OFFSET rsp,0
9820 pushfq_cfi
9821 /*CFI_REL_OFFSET rflags,0*/
9822 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9823 - CFI_REGISTER rip,r10
9824 + orl $X86_EFLAGS_IF,(%rsp)
9825 + GET_THREAD_INFO(%r11)
9826 + movl TI_sysenter_return(%r11), %r11d
9827 + CFI_REGISTER rip,r11
9828 pushq_cfi $__USER32_CS
9829 /*CFI_REL_OFFSET cs,0*/
9830 movl %eax, %eax
9831 - pushq_cfi %r10
9832 + pushq_cfi %r11
9833 CFI_REL_OFFSET rip,0
9834 pushq_cfi %rax
9835 cld
9836 SAVE_ARGS 0,1,0
9837 + pax_enter_kernel_user
9838 +
9839 +#ifdef CONFIG_PAX_RANDKSTACK
9840 + pax_erase_kstack
9841 +#endif
9842 +
9843 + /*
9844 + * No need to follow this irqs on/off section: the syscall
9845 + * disabled irqs, here we enable it straight after entry:
9846 + */
9847 + ENABLE_INTERRUPTS(CLBR_NONE)
9848 /* no need to do an access_ok check here because rbp has been
9849 32bit zero extended */
9850 +
9851 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9852 + mov $PAX_USER_SHADOW_BASE,%r11
9853 + add %r11,%rbp
9854 +#endif
9855 +
9856 ASM_STAC
9857 1: movl (%rbp),%ebp
9858 _ASM_EXTABLE(1b,ia32_badarg)
9859 ASM_CLAC
9860 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9861 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9862 + GET_THREAD_INFO(%r11)
9863 + orl $TS_COMPAT,TI_status(%r11)
9864 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9865 CFI_REMEMBER_STATE
9866 jnz sysenter_tracesys
9867 cmpq $(IA32_NR_syscalls-1),%rax
9868 @@ -162,12 +204,15 @@ sysenter_do_call:
9869 sysenter_dispatch:
9870 call *ia32_sys_call_table(,%rax,8)
9871 movq %rax,RAX-ARGOFFSET(%rsp)
9872 + GET_THREAD_INFO(%r11)
9873 DISABLE_INTERRUPTS(CLBR_NONE)
9874 TRACE_IRQS_OFF
9875 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9876 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9877 jnz sysexit_audit
9878 sysexit_from_sys_call:
9879 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9880 + pax_exit_kernel_user
9881 + pax_erase_kstack
9882 + andl $~TS_COMPAT,TI_status(%r11)
9883 /* clear IF, that popfq doesn't enable interrupts early */
9884 andl $~0x200,EFLAGS-R11(%rsp)
9885 movl RIP-R11(%rsp),%edx /* User %eip */
9886 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
9887 movl %eax,%esi /* 2nd arg: syscall number */
9888 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
9889 call __audit_syscall_entry
9890 +
9891 + pax_erase_kstack
9892 +
9893 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
9894 cmpq $(IA32_NR_syscalls-1),%rax
9895 ja ia32_badsys
9896 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
9897 .endm
9898
9899 .macro auditsys_exit exit
9900 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9901 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9902 jnz ia32_ret_from_sys_call
9903 TRACE_IRQS_ON
9904 sti
9905 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
9906 1: setbe %al /* 1 if error, 0 if not */
9907 movzbl %al,%edi /* zero-extend that into %edi */
9908 call __audit_syscall_exit
9909 + GET_THREAD_INFO(%r11)
9910 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
9911 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
9912 cli
9913 TRACE_IRQS_OFF
9914 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9915 + testl %edi,TI_flags(%r11)
9916 jz \exit
9917 CLEAR_RREGS -ARGOFFSET
9918 jmp int_with_check
9919 @@ -237,7 +286,7 @@ sysexit_audit:
9920
9921 sysenter_tracesys:
9922 #ifdef CONFIG_AUDITSYSCALL
9923 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9924 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9925 jz sysenter_auditsys
9926 #endif
9927 SAVE_REST
9928 @@ -249,6 +298,9 @@ sysenter_tracesys:
9929 RESTORE_REST
9930 cmpq $(IA32_NR_syscalls-1),%rax
9931 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
9932 +
9933 + pax_erase_kstack
9934 +
9935 jmp sysenter_do_call
9936 CFI_ENDPROC
9937 ENDPROC(ia32_sysenter_target)
9938 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
9939 ENTRY(ia32_cstar_target)
9940 CFI_STARTPROC32 simple
9941 CFI_SIGNAL_FRAME
9942 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
9943 + CFI_DEF_CFA rsp,0
9944 CFI_REGISTER rip,rcx
9945 /*CFI_REGISTER rflags,r11*/
9946 SWAPGS_UNSAFE_STACK
9947 movl %esp,%r8d
9948 CFI_REGISTER rsp,r8
9949 movq PER_CPU_VAR(kernel_stack),%rsp
9950 + SAVE_ARGS 8*6,0,0
9951 + pax_enter_kernel_user
9952 +
9953 +#ifdef CONFIG_PAX_RANDKSTACK
9954 + pax_erase_kstack
9955 +#endif
9956 +
9957 /*
9958 * No need to follow this irqs on/off section: the syscall
9959 * disabled irqs and here we enable it straight after entry:
9960 */
9961 ENABLE_INTERRUPTS(CLBR_NONE)
9962 - SAVE_ARGS 8,0,0
9963 movl %eax,%eax /* zero extension */
9964 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
9965 movq %rcx,RIP-ARGOFFSET(%rsp)
9966 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
9967 /* no need to do an access_ok check here because r8 has been
9968 32bit zero extended */
9969 /* hardware stack frame is complete now */
9970 +
9971 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9972 + mov $PAX_USER_SHADOW_BASE,%r11
9973 + add %r11,%r8
9974 +#endif
9975 +
9976 ASM_STAC
9977 1: movl (%r8),%r9d
9978 _ASM_EXTABLE(1b,ia32_badarg)
9979 ASM_CLAC
9980 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9981 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9982 + GET_THREAD_INFO(%r11)
9983 + orl $TS_COMPAT,TI_status(%r11)
9984 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9985 CFI_REMEMBER_STATE
9986 jnz cstar_tracesys
9987 cmpq $IA32_NR_syscalls-1,%rax
9988 @@ -319,12 +384,15 @@ cstar_do_call:
9989 cstar_dispatch:
9990 call *ia32_sys_call_table(,%rax,8)
9991 movq %rax,RAX-ARGOFFSET(%rsp)
9992 + GET_THREAD_INFO(%r11)
9993 DISABLE_INTERRUPTS(CLBR_NONE)
9994 TRACE_IRQS_OFF
9995 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9996 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9997 jnz sysretl_audit
9998 sysretl_from_sys_call:
9999 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10000 + pax_exit_kernel_user
10001 + pax_erase_kstack
10002 + andl $~TS_COMPAT,TI_status(%r11)
10003 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10004 movl RIP-ARGOFFSET(%rsp),%ecx
10005 CFI_REGISTER rip,rcx
10006 @@ -352,7 +420,7 @@ sysretl_audit:
10007
10008 cstar_tracesys:
10009 #ifdef CONFIG_AUDITSYSCALL
10010 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10011 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10012 jz cstar_auditsys
10013 #endif
10014 xchgl %r9d,%ebp
10015 @@ -366,6 +434,9 @@ cstar_tracesys:
10016 xchgl %ebp,%r9d
10017 cmpq $(IA32_NR_syscalls-1),%rax
10018 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10019 +
10020 + pax_erase_kstack
10021 +
10022 jmp cstar_do_call
10023 END(ia32_cstar_target)
10024
10025 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10026 CFI_REL_OFFSET rip,RIP-RIP
10027 PARAVIRT_ADJUST_EXCEPTION_FRAME
10028 SWAPGS
10029 - /*
10030 - * No need to follow this irqs on/off section: the syscall
10031 - * disabled irqs and here we enable it straight after entry:
10032 - */
10033 - ENABLE_INTERRUPTS(CLBR_NONE)
10034 movl %eax,%eax
10035 pushq_cfi %rax
10036 cld
10037 /* note the registers are not zero extended to the sf.
10038 this could be a problem. */
10039 SAVE_ARGS 0,1,0
10040 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10041 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10042 + pax_enter_kernel_user
10043 +
10044 +#ifdef CONFIG_PAX_RANDKSTACK
10045 + pax_erase_kstack
10046 +#endif
10047 +
10048 + /*
10049 + * No need to follow this irqs on/off section: the syscall
10050 + * disabled irqs and here we enable it straight after entry:
10051 + */
10052 + ENABLE_INTERRUPTS(CLBR_NONE)
10053 + GET_THREAD_INFO(%r11)
10054 + orl $TS_COMPAT,TI_status(%r11)
10055 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10056 jnz ia32_tracesys
10057 cmpq $(IA32_NR_syscalls-1),%rax
10058 ja ia32_badsys
10059 @@ -442,6 +520,9 @@ ia32_tracesys:
10060 RESTORE_REST
10061 cmpq $(IA32_NR_syscalls-1),%rax
10062 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10063 +
10064 + pax_erase_kstack
10065 +
10066 jmp ia32_do_call
10067 END(ia32_syscall)
10068
10069 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10070 index 86d68d1..f9960fe 100644
10071 --- a/arch/x86/ia32/sys_ia32.c
10072 +++ b/arch/x86/ia32/sys_ia32.c
10073 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10074 */
10075 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10076 {
10077 - typeof(ubuf->st_uid) uid = 0;
10078 - typeof(ubuf->st_gid) gid = 0;
10079 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
10080 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
10081 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10082 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10083 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10084 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10085 mm_segment_t old_fs = get_fs();
10086
10087 set_fs(KERNEL_DS);
10088 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10089 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10090 set_fs(old_fs);
10091 if (put_compat_timespec(&t, interval))
10092 return -EFAULT;
10093 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10094 mm_segment_t old_fs = get_fs();
10095
10096 set_fs(KERNEL_DS);
10097 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10098 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10099 set_fs(old_fs);
10100 if (!ret) {
10101 switch (_NSIG_WORDS) {
10102 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10103 if (copy_siginfo_from_user32(&info, uinfo))
10104 return -EFAULT;
10105 set_fs(KERNEL_DS);
10106 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10107 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10108 set_fs(old_fs);
10109 return ret;
10110 }
10111 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10112 return -EFAULT;
10113
10114 set_fs(KERNEL_DS);
10115 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10116 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10117 count);
10118 set_fs(old_fs);
10119
10120 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10121 index 372231c..a5aa1a1 100644
10122 --- a/arch/x86/include/asm/alternative-asm.h
10123 +++ b/arch/x86/include/asm/alternative-asm.h
10124 @@ -18,6 +18,45 @@
10125 .endm
10126 #endif
10127
10128 +#ifdef KERNEXEC_PLUGIN
10129 + .macro pax_force_retaddr_bts rip=0
10130 + btsq $63,\rip(%rsp)
10131 + .endm
10132 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10133 + .macro pax_force_retaddr rip=0, reload=0
10134 + btsq $63,\rip(%rsp)
10135 + .endm
10136 + .macro pax_force_fptr ptr
10137 + btsq $63,\ptr
10138 + .endm
10139 + .macro pax_set_fptr_mask
10140 + .endm
10141 +#endif
10142 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10143 + .macro pax_force_retaddr rip=0, reload=0
10144 + .if \reload
10145 + pax_set_fptr_mask
10146 + .endif
10147 + orq %r10,\rip(%rsp)
10148 + .endm
10149 + .macro pax_force_fptr ptr
10150 + orq %r10,\ptr
10151 + .endm
10152 + .macro pax_set_fptr_mask
10153 + movabs $0x8000000000000000,%r10
10154 + .endm
10155 +#endif
10156 +#else
10157 + .macro pax_force_retaddr rip=0, reload=0
10158 + .endm
10159 + .macro pax_force_fptr ptr
10160 + .endm
10161 + .macro pax_force_retaddr_bts rip=0
10162 + .endm
10163 + .macro pax_set_fptr_mask
10164 + .endm
10165 +#endif
10166 +
10167 .macro altinstruction_entry orig alt feature orig_len alt_len
10168 .long \orig - .
10169 .long \alt - .
10170 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10171 index 58ed6d9..f1cbe58 100644
10172 --- a/arch/x86/include/asm/alternative.h
10173 +++ b/arch/x86/include/asm/alternative.h
10174 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10175 ".pushsection .discard,\"aw\",@progbits\n" \
10176 DISCARD_ENTRY(1) \
10177 ".popsection\n" \
10178 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10179 + ".pushsection .altinstr_replacement, \"a\"\n" \
10180 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10181 ".popsection"
10182
10183 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10184 DISCARD_ENTRY(1) \
10185 DISCARD_ENTRY(2) \
10186 ".popsection\n" \
10187 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10188 + ".pushsection .altinstr_replacement, \"a\"\n" \
10189 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10190 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10191 ".popsection"
10192 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10193 index 3388034..ba52312 100644
10194 --- a/arch/x86/include/asm/apic.h
10195 +++ b/arch/x86/include/asm/apic.h
10196 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10197
10198 #ifdef CONFIG_X86_LOCAL_APIC
10199
10200 -extern unsigned int apic_verbosity;
10201 +extern int apic_verbosity;
10202 extern int local_apic_timer_c2_ok;
10203
10204 extern int disable_apic;
10205 @@ -391,7 +391,7 @@ struct apic {
10206 */
10207 int (*x86_32_numa_cpu_node)(int cpu);
10208 #endif
10209 -};
10210 +} __do_const;
10211
10212 /*
10213 * Pointer to the local APIC driver in use on this system (there's
10214 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10215 index 20370c6..a2eb9b0 100644
10216 --- a/arch/x86/include/asm/apm.h
10217 +++ b/arch/x86/include/asm/apm.h
10218 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10219 __asm__ __volatile__(APM_DO_ZERO_SEGS
10220 "pushl %%edi\n\t"
10221 "pushl %%ebp\n\t"
10222 - "lcall *%%cs:apm_bios_entry\n\t"
10223 + "lcall *%%ss:apm_bios_entry\n\t"
10224 "setc %%al\n\t"
10225 "popl %%ebp\n\t"
10226 "popl %%edi\n\t"
10227 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10228 __asm__ __volatile__(APM_DO_ZERO_SEGS
10229 "pushl %%edi\n\t"
10230 "pushl %%ebp\n\t"
10231 - "lcall *%%cs:apm_bios_entry\n\t"
10232 + "lcall *%%ss:apm_bios_entry\n\t"
10233 "setc %%bl\n\t"
10234 "popl %%ebp\n\t"
10235 "popl %%edi\n\t"
10236 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10237 index b6c3b82..b4c077a 100644
10238 --- a/arch/x86/include/asm/atomic.h
10239 +++ b/arch/x86/include/asm/atomic.h
10240 @@ -22,7 +22,18 @@
10241 */
10242 static inline int atomic_read(const atomic_t *v)
10243 {
10244 - return (*(volatile int *)&(v)->counter);
10245 + return (*(volatile const int *)&(v)->counter);
10246 +}
10247 +
10248 +/**
10249 + * atomic_read_unchecked - read atomic variable
10250 + * @v: pointer of type atomic_unchecked_t
10251 + *
10252 + * Atomically reads the value of @v.
10253 + */
10254 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10255 +{
10256 + return (*(volatile const int *)&(v)->counter);
10257 }
10258
10259 /**
10260 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10261 }
10262
10263 /**
10264 + * atomic_set_unchecked - set atomic variable
10265 + * @v: pointer of type atomic_unchecked_t
10266 + * @i: required value
10267 + *
10268 + * Atomically sets the value of @v to @i.
10269 + */
10270 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10271 +{
10272 + v->counter = i;
10273 +}
10274 +
10275 +/**
10276 * atomic_add - add integer to atomic variable
10277 * @i: integer value to add
10278 * @v: pointer of type atomic_t
10279 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10280 */
10281 static inline void atomic_add(int i, atomic_t *v)
10282 {
10283 - asm volatile(LOCK_PREFIX "addl %1,%0"
10284 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10285 +
10286 +#ifdef CONFIG_PAX_REFCOUNT
10287 + "jno 0f\n"
10288 + LOCK_PREFIX "subl %1,%0\n"
10289 + "int $4\n0:\n"
10290 + _ASM_EXTABLE(0b, 0b)
10291 +#endif
10292 +
10293 + : "+m" (v->counter)
10294 + : "ir" (i));
10295 +}
10296 +
10297 +/**
10298 + * atomic_add_unchecked - add integer to atomic variable
10299 + * @i: integer value to add
10300 + * @v: pointer of type atomic_unchecked_t
10301 + *
10302 + * Atomically adds @i to @v.
10303 + */
10304 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10305 +{
10306 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10307 : "+m" (v->counter)
10308 : "ir" (i));
10309 }
10310 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10311 */
10312 static inline void atomic_sub(int i, atomic_t *v)
10313 {
10314 - asm volatile(LOCK_PREFIX "subl %1,%0"
10315 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10316 +
10317 +#ifdef CONFIG_PAX_REFCOUNT
10318 + "jno 0f\n"
10319 + LOCK_PREFIX "addl %1,%0\n"
10320 + "int $4\n0:\n"
10321 + _ASM_EXTABLE(0b, 0b)
10322 +#endif
10323 +
10324 + : "+m" (v->counter)
10325 + : "ir" (i));
10326 +}
10327 +
10328 +/**
10329 + * atomic_sub_unchecked - subtract integer from atomic variable
10330 + * @i: integer value to subtract
10331 + * @v: pointer of type atomic_unchecked_t
10332 + *
10333 + * Atomically subtracts @i from @v.
10334 + */
10335 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10336 +{
10337 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10338 : "+m" (v->counter)
10339 : "ir" (i));
10340 }
10341 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10342 {
10343 unsigned char c;
10344
10345 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10346 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10347 +
10348 +#ifdef CONFIG_PAX_REFCOUNT
10349 + "jno 0f\n"
10350 + LOCK_PREFIX "addl %2,%0\n"
10351 + "int $4\n0:\n"
10352 + _ASM_EXTABLE(0b, 0b)
10353 +#endif
10354 +
10355 + "sete %1\n"
10356 : "+m" (v->counter), "=qm" (c)
10357 : "ir" (i) : "memory");
10358 return c;
10359 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10360 */
10361 static inline void atomic_inc(atomic_t *v)
10362 {
10363 - asm volatile(LOCK_PREFIX "incl %0"
10364 + asm volatile(LOCK_PREFIX "incl %0\n"
10365 +
10366 +#ifdef CONFIG_PAX_REFCOUNT
10367 + "jno 0f\n"
10368 + LOCK_PREFIX "decl %0\n"
10369 + "int $4\n0:\n"
10370 + _ASM_EXTABLE(0b, 0b)
10371 +#endif
10372 +
10373 + : "+m" (v->counter));
10374 +}
10375 +
10376 +/**
10377 + * atomic_inc_unchecked - increment atomic variable
10378 + * @v: pointer of type atomic_unchecked_t
10379 + *
10380 + * Atomically increments @v by 1.
10381 + */
10382 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10383 +{
10384 + asm volatile(LOCK_PREFIX "incl %0\n"
10385 : "+m" (v->counter));
10386 }
10387
10388 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10389 */
10390 static inline void atomic_dec(atomic_t *v)
10391 {
10392 - asm volatile(LOCK_PREFIX "decl %0"
10393 + asm volatile(LOCK_PREFIX "decl %0\n"
10394 +
10395 +#ifdef CONFIG_PAX_REFCOUNT
10396 + "jno 0f\n"
10397 + LOCK_PREFIX "incl %0\n"
10398 + "int $4\n0:\n"
10399 + _ASM_EXTABLE(0b, 0b)
10400 +#endif
10401 +
10402 + : "+m" (v->counter));
10403 +}
10404 +
10405 +/**
10406 + * atomic_dec_unchecked - decrement atomic variable
10407 + * @v: pointer of type atomic_unchecked_t
10408 + *
10409 + * Atomically decrements @v by 1.
10410 + */
10411 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10412 +{
10413 + asm volatile(LOCK_PREFIX "decl %0\n"
10414 : "+m" (v->counter));
10415 }
10416
10417 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10418 {
10419 unsigned char c;
10420
10421 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10422 + asm volatile(LOCK_PREFIX "decl %0\n"
10423 +
10424 +#ifdef CONFIG_PAX_REFCOUNT
10425 + "jno 0f\n"
10426 + LOCK_PREFIX "incl %0\n"
10427 + "int $4\n0:\n"
10428 + _ASM_EXTABLE(0b, 0b)
10429 +#endif
10430 +
10431 + "sete %1\n"
10432 : "+m" (v->counter), "=qm" (c)
10433 : : "memory");
10434 return c != 0;
10435 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10436 {
10437 unsigned char c;
10438
10439 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10440 + asm volatile(LOCK_PREFIX "incl %0\n"
10441 +
10442 +#ifdef CONFIG_PAX_REFCOUNT
10443 + "jno 0f\n"
10444 + LOCK_PREFIX "decl %0\n"
10445 + "int $4\n0:\n"
10446 + _ASM_EXTABLE(0b, 0b)
10447 +#endif
10448 +
10449 + "sete %1\n"
10450 + : "+m" (v->counter), "=qm" (c)
10451 + : : "memory");
10452 + return c != 0;
10453 +}
10454 +
10455 +/**
10456 + * atomic_inc_and_test_unchecked - increment and test
10457 + * @v: pointer of type atomic_unchecked_t
10458 + *
10459 + * Atomically increments @v by 1
10460 + * and returns true if the result is zero, or false for all
10461 + * other cases.
10462 + */
10463 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10464 +{
10465 + unsigned char c;
10466 +
10467 + asm volatile(LOCK_PREFIX "incl %0\n"
10468 + "sete %1\n"
10469 : "+m" (v->counter), "=qm" (c)
10470 : : "memory");
10471 return c != 0;
10472 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10473 {
10474 unsigned char c;
10475
10476 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10477 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10478 +
10479 +#ifdef CONFIG_PAX_REFCOUNT
10480 + "jno 0f\n"
10481 + LOCK_PREFIX "subl %2,%0\n"
10482 + "int $4\n0:\n"
10483 + _ASM_EXTABLE(0b, 0b)
10484 +#endif
10485 +
10486 + "sets %1\n"
10487 : "+m" (v->counter), "=qm" (c)
10488 : "ir" (i) : "memory");
10489 return c;
10490 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10491 goto no_xadd;
10492 #endif
10493 /* Modern 486+ processor */
10494 - return i + xadd(&v->counter, i);
10495 + return i + xadd_check_overflow(&v->counter, i);
10496
10497 #ifdef CONFIG_M386
10498 no_xadd: /* Legacy 386 processor */
10499 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10500 }
10501
10502 /**
10503 + * atomic_add_return_unchecked - add integer and return
10504 + * @i: integer value to add
10505 + * @v: pointer of type atomic_unchecked_t
10506 + *
10507 + * Atomically adds @i to @v and returns @i + @v
10508 + */
10509 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10510 +{
10511 +#ifdef CONFIG_M386
10512 + int __i;
10513 + unsigned long flags;
10514 + if (unlikely(boot_cpu_data.x86 <= 3))
10515 + goto no_xadd;
10516 +#endif
10517 + /* Modern 486+ processor */
10518 + return i + xadd(&v->counter, i);
10519 +
10520 +#ifdef CONFIG_M386
10521 +no_xadd: /* Legacy 386 processor */
10522 + raw_local_irq_save(flags);
10523 + __i = atomic_read_unchecked(v);
10524 + atomic_set_unchecked(v, i + __i);
10525 + raw_local_irq_restore(flags);
10526 + return i + __i;
10527 +#endif
10528 +}
10529 +
10530 +/**
10531 * atomic_sub_return - subtract integer and return
10532 * @v: pointer of type atomic_t
10533 * @i: integer value to subtract
10534 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10535 }
10536
10537 #define atomic_inc_return(v) (atomic_add_return(1, v))
10538 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10539 +{
10540 + return atomic_add_return_unchecked(1, v);
10541 +}
10542 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10543
10544 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10545 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10546 return cmpxchg(&v->counter, old, new);
10547 }
10548
10549 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10550 +{
10551 + return cmpxchg(&v->counter, old, new);
10552 +}
10553 +
10554 static inline int atomic_xchg(atomic_t *v, int new)
10555 {
10556 return xchg(&v->counter, new);
10557 }
10558
10559 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10560 +{
10561 + return xchg(&v->counter, new);
10562 +}
10563 +
10564 /**
10565 * __atomic_add_unless - add unless the number is already a given value
10566 * @v: pointer of type atomic_t
10567 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10568 */
10569 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10570 {
10571 - int c, old;
10572 + int c, old, new;
10573 c = atomic_read(v);
10574 for (;;) {
10575 - if (unlikely(c == (u)))
10576 + if (unlikely(c == u))
10577 break;
10578 - old = atomic_cmpxchg((v), c, c + (a));
10579 +
10580 + asm volatile("addl %2,%0\n"
10581 +
10582 +#ifdef CONFIG_PAX_REFCOUNT
10583 + "jno 0f\n"
10584 + "subl %2,%0\n"
10585 + "int $4\n0:\n"
10586 + _ASM_EXTABLE(0b, 0b)
10587 +#endif
10588 +
10589 + : "=r" (new)
10590 + : "0" (c), "ir" (a));
10591 +
10592 + old = atomic_cmpxchg(v, c, new);
10593 if (likely(old == c))
10594 break;
10595 c = old;
10596 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10597 }
10598
10599 /**
10600 + * atomic_inc_not_zero_hint - increment if not null
10601 + * @v: pointer of type atomic_t
10602 + * @hint: probable value of the atomic before the increment
10603 + *
10604 + * This version of atomic_inc_not_zero() gives a hint of probable
10605 + * value of the atomic. This helps processor to not read the memory
10606 + * before doing the atomic read/modify/write cycle, lowering
10607 + * number of bus transactions on some arches.
10608 + *
10609 + * Returns: 0 if increment was not done, 1 otherwise.
10610 + */
10611 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10612 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10613 +{
10614 + int val, c = hint, new;
10615 +
10616 + /* sanity test, should be removed by compiler if hint is a constant */
10617 + if (!hint)
10618 + return __atomic_add_unless(v, 1, 0);
10619 +
10620 + do {
10621 + asm volatile("incl %0\n"
10622 +
10623 +#ifdef CONFIG_PAX_REFCOUNT
10624 + "jno 0f\n"
10625 + "decl %0\n"
10626 + "int $4\n0:\n"
10627 + _ASM_EXTABLE(0b, 0b)
10628 +#endif
10629 +
10630 + : "=r" (new)
10631 + : "0" (c));
10632 +
10633 + val = atomic_cmpxchg(v, c, new);
10634 + if (val == c)
10635 + return 1;
10636 + c = val;
10637 + } while (c);
10638 +
10639 + return 0;
10640 +}
10641 +
10642 +/**
10643 * atomic_inc_short - increment of a short integer
10644 * @v: pointer to type int
10645 *
10646 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10647 #endif
10648
10649 /* These are x86-specific, used by some header files */
10650 -#define atomic_clear_mask(mask, addr) \
10651 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10652 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10653 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10654 +{
10655 + asm volatile(LOCK_PREFIX "andl %1,%0"
10656 + : "+m" (v->counter)
10657 + : "r" (~(mask))
10658 + : "memory");
10659 +}
10660
10661 -#define atomic_set_mask(mask, addr) \
10662 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10663 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10664 - : "memory")
10665 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10666 +{
10667 + asm volatile(LOCK_PREFIX "andl %1,%0"
10668 + : "+m" (v->counter)
10669 + : "r" (~(mask))
10670 + : "memory");
10671 +}
10672 +
10673 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10674 +{
10675 + asm volatile(LOCK_PREFIX "orl %1,%0"
10676 + : "+m" (v->counter)
10677 + : "r" (mask)
10678 + : "memory");
10679 +}
10680 +
10681 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10682 +{
10683 + asm volatile(LOCK_PREFIX "orl %1,%0"
10684 + : "+m" (v->counter)
10685 + : "r" (mask)
10686 + : "memory");
10687 +}
10688
10689 /* Atomic operations are already serializing on x86 */
10690 #define smp_mb__before_atomic_dec() barrier()
10691 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10692 index b154de7..aadebd8 100644
10693 --- a/arch/x86/include/asm/atomic64_32.h
10694 +++ b/arch/x86/include/asm/atomic64_32.h
10695 @@ -12,6 +12,14 @@ typedef struct {
10696 u64 __aligned(8) counter;
10697 } atomic64_t;
10698
10699 +#ifdef CONFIG_PAX_REFCOUNT
10700 +typedef struct {
10701 + u64 __aligned(8) counter;
10702 +} atomic64_unchecked_t;
10703 +#else
10704 +typedef atomic64_t atomic64_unchecked_t;
10705 +#endif
10706 +
10707 #define ATOMIC64_INIT(val) { (val) }
10708
10709 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10710 @@ -37,21 +45,31 @@ typedef struct {
10711 ATOMIC64_DECL_ONE(sym##_386)
10712
10713 ATOMIC64_DECL_ONE(add_386);
10714 +ATOMIC64_DECL_ONE(add_unchecked_386);
10715 ATOMIC64_DECL_ONE(sub_386);
10716 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10717 ATOMIC64_DECL_ONE(inc_386);
10718 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10719 ATOMIC64_DECL_ONE(dec_386);
10720 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10721 #endif
10722
10723 #define alternative_atomic64(f, out, in...) \
10724 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10725
10726 ATOMIC64_DECL(read);
10727 +ATOMIC64_DECL(read_unchecked);
10728 ATOMIC64_DECL(set);
10729 +ATOMIC64_DECL(set_unchecked);
10730 ATOMIC64_DECL(xchg);
10731 ATOMIC64_DECL(add_return);
10732 +ATOMIC64_DECL(add_return_unchecked);
10733 ATOMIC64_DECL(sub_return);
10734 +ATOMIC64_DECL(sub_return_unchecked);
10735 ATOMIC64_DECL(inc_return);
10736 +ATOMIC64_DECL(inc_return_unchecked);
10737 ATOMIC64_DECL(dec_return);
10738 +ATOMIC64_DECL(dec_return_unchecked);
10739 ATOMIC64_DECL(dec_if_positive);
10740 ATOMIC64_DECL(inc_not_zero);
10741 ATOMIC64_DECL(add_unless);
10742 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10743 }
10744
10745 /**
10746 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10747 + * @p: pointer to type atomic64_unchecked_t
10748 + * @o: expected value
10749 + * @n: new value
10750 + *
10751 + * Atomically sets @v to @n if it was equal to @o and returns
10752 + * the old value.
10753 + */
10754 +
10755 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10756 +{
10757 + return cmpxchg64(&v->counter, o, n);
10758 +}
10759 +
10760 +/**
10761 * atomic64_xchg - xchg atomic64 variable
10762 * @v: pointer to type atomic64_t
10763 * @n: value to assign
10764 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10765 }
10766
10767 /**
10768 + * atomic64_set_unchecked - set atomic64 variable
10769 + * @v: pointer to type atomic64_unchecked_t
10770 + * @n: value to assign
10771 + *
10772 + * Atomically sets the value of @v to @n.
10773 + */
10774 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10775 +{
10776 + unsigned high = (unsigned)(i >> 32);
10777 + unsigned low = (unsigned)i;
10778 + alternative_atomic64(set, /* no output */,
10779 + "S" (v), "b" (low), "c" (high)
10780 + : "eax", "edx", "memory");
10781 +}
10782 +
10783 +/**
10784 * atomic64_read - read atomic64 variable
10785 * @v: pointer to type atomic64_t
10786 *
10787 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10788 }
10789
10790 /**
10791 + * atomic64_read_unchecked - read atomic64 variable
10792 + * @v: pointer to type atomic64_unchecked_t
10793 + *
10794 + * Atomically reads the value of @v and returns it.
10795 + */
10796 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10797 +{
10798 + long long r;
10799 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10800 + return r;
10801 + }
10802 +
10803 +/**
10804 * atomic64_add_return - add and return
10805 * @i: integer value to add
10806 * @v: pointer to type atomic64_t
10807 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10808 return i;
10809 }
10810
10811 +/**
10812 + * atomic64_add_return_unchecked - add and return
10813 + * @i: integer value to add
10814 + * @v: pointer to type atomic64_unchecked_t
10815 + *
10816 + * Atomically adds @i to @v and returns @i + *@v
10817 + */
10818 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10819 +{
10820 + alternative_atomic64(add_return_unchecked,
10821 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10822 + ASM_NO_INPUT_CLOBBER("memory"));
10823 + return i;
10824 +}
10825 +
10826 /*
10827 * Other variants with different arithmetic operators:
10828 */
10829 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10830 return a;
10831 }
10832
10833 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10834 +{
10835 + long long a;
10836 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10837 + "S" (v) : "memory", "ecx");
10838 + return a;
10839 +}
10840 +
10841 static inline long long atomic64_dec_return(atomic64_t *v)
10842 {
10843 long long a;
10844 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10845 }
10846
10847 /**
10848 + * atomic64_add_unchecked - add integer to atomic64 variable
10849 + * @i: integer value to add
10850 + * @v: pointer to type atomic64_unchecked_t
10851 + *
10852 + * Atomically adds @i to @v.
10853 + */
10854 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10855 +{
10856 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10857 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10858 + ASM_NO_INPUT_CLOBBER("memory"));
10859 + return i;
10860 +}
10861 +
10862 +/**
10863 * atomic64_sub - subtract the atomic64 variable
10864 * @i: integer value to subtract
10865 * @v: pointer to type atomic64_t
10866 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10867 index 0e1cbfc..5623683 100644
10868 --- a/arch/x86/include/asm/atomic64_64.h
10869 +++ b/arch/x86/include/asm/atomic64_64.h
10870 @@ -18,7 +18,19 @@
10871 */
10872 static inline long atomic64_read(const atomic64_t *v)
10873 {
10874 - return (*(volatile long *)&(v)->counter);
10875 + return (*(volatile const long *)&(v)->counter);
10876 +}
10877 +
10878 +/**
10879 + * atomic64_read_unchecked - read atomic64 variable
10880 + * @v: pointer of type atomic64_unchecked_t
10881 + *
10882 + * Atomically reads the value of @v.
10883 + * Doesn't imply a read memory barrier.
10884 + */
10885 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10886 +{
10887 + return (*(volatile const long *)&(v)->counter);
10888 }
10889
10890 /**
10891 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
10892 }
10893
10894 /**
10895 + * atomic64_set_unchecked - set atomic64 variable
10896 + * @v: pointer to type atomic64_unchecked_t
10897 + * @i: required value
10898 + *
10899 + * Atomically sets the value of @v to @i.
10900 + */
10901 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10902 +{
10903 + v->counter = i;
10904 +}
10905 +
10906 +/**
10907 * atomic64_add - add integer to atomic64 variable
10908 * @i: integer value to add
10909 * @v: pointer to type atomic64_t
10910 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
10911 */
10912 static inline void atomic64_add(long i, atomic64_t *v)
10913 {
10914 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
10915 +
10916 +#ifdef CONFIG_PAX_REFCOUNT
10917 + "jno 0f\n"
10918 + LOCK_PREFIX "subq %1,%0\n"
10919 + "int $4\n0:\n"
10920 + _ASM_EXTABLE(0b, 0b)
10921 +#endif
10922 +
10923 + : "=m" (v->counter)
10924 + : "er" (i), "m" (v->counter));
10925 +}
10926 +
10927 +/**
10928 + * atomic64_add_unchecked - add integer to atomic64 variable
10929 + * @i: integer value to add
10930 + * @v: pointer to type atomic64_unchecked_t
10931 + *
10932 + * Atomically adds @i to @v.
10933 + */
10934 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
10935 +{
10936 asm volatile(LOCK_PREFIX "addq %1,%0"
10937 : "=m" (v->counter)
10938 : "er" (i), "m" (v->counter));
10939 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
10940 */
10941 static inline void atomic64_sub(long i, atomic64_t *v)
10942 {
10943 - asm volatile(LOCK_PREFIX "subq %1,%0"
10944 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
10945 +
10946 +#ifdef CONFIG_PAX_REFCOUNT
10947 + "jno 0f\n"
10948 + LOCK_PREFIX "addq %1,%0\n"
10949 + "int $4\n0:\n"
10950 + _ASM_EXTABLE(0b, 0b)
10951 +#endif
10952 +
10953 + : "=m" (v->counter)
10954 + : "er" (i), "m" (v->counter));
10955 +}
10956 +
10957 +/**
10958 + * atomic64_sub_unchecked - subtract the atomic64 variable
10959 + * @i: integer value to subtract
10960 + * @v: pointer to type atomic64_unchecked_t
10961 + *
10962 + * Atomically subtracts @i from @v.
10963 + */
10964 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
10965 +{
10966 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
10967 : "=m" (v->counter)
10968 : "er" (i), "m" (v->counter));
10969 }
10970 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10971 {
10972 unsigned char c;
10973
10974 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
10975 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
10976 +
10977 +#ifdef CONFIG_PAX_REFCOUNT
10978 + "jno 0f\n"
10979 + LOCK_PREFIX "addq %2,%0\n"
10980 + "int $4\n0:\n"
10981 + _ASM_EXTABLE(0b, 0b)
10982 +#endif
10983 +
10984 + "sete %1\n"
10985 : "=m" (v->counter), "=qm" (c)
10986 : "er" (i), "m" (v->counter) : "memory");
10987 return c;
10988 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10989 */
10990 static inline void atomic64_inc(atomic64_t *v)
10991 {
10992 + asm volatile(LOCK_PREFIX "incq %0\n"
10993 +
10994 +#ifdef CONFIG_PAX_REFCOUNT
10995 + "jno 0f\n"
10996 + LOCK_PREFIX "decq %0\n"
10997 + "int $4\n0:\n"
10998 + _ASM_EXTABLE(0b, 0b)
10999 +#endif
11000 +
11001 + : "=m" (v->counter)
11002 + : "m" (v->counter));
11003 +}
11004 +
11005 +/**
11006 + * atomic64_inc_unchecked - increment atomic64 variable
11007 + * @v: pointer to type atomic64_unchecked_t
11008 + *
11009 + * Atomically increments @v by 1.
11010 + */
11011 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11012 +{
11013 asm volatile(LOCK_PREFIX "incq %0"
11014 : "=m" (v->counter)
11015 : "m" (v->counter));
11016 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11017 */
11018 static inline void atomic64_dec(atomic64_t *v)
11019 {
11020 - asm volatile(LOCK_PREFIX "decq %0"
11021 + asm volatile(LOCK_PREFIX "decq %0\n"
11022 +
11023 +#ifdef CONFIG_PAX_REFCOUNT
11024 + "jno 0f\n"
11025 + LOCK_PREFIX "incq %0\n"
11026 + "int $4\n0:\n"
11027 + _ASM_EXTABLE(0b, 0b)
11028 +#endif
11029 +
11030 + : "=m" (v->counter)
11031 + : "m" (v->counter));
11032 +}
11033 +
11034 +/**
11035 + * atomic64_dec_unchecked - decrement atomic64 variable
11036 + * @v: pointer to type atomic64_t
11037 + *
11038 + * Atomically decrements @v by 1.
11039 + */
11040 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11041 +{
11042 + asm volatile(LOCK_PREFIX "decq %0\n"
11043 : "=m" (v->counter)
11044 : "m" (v->counter));
11045 }
11046 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11047 {
11048 unsigned char c;
11049
11050 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
11051 + asm volatile(LOCK_PREFIX "decq %0\n"
11052 +
11053 +#ifdef CONFIG_PAX_REFCOUNT
11054 + "jno 0f\n"
11055 + LOCK_PREFIX "incq %0\n"
11056 + "int $4\n0:\n"
11057 + _ASM_EXTABLE(0b, 0b)
11058 +#endif
11059 +
11060 + "sete %1\n"
11061 : "=m" (v->counter), "=qm" (c)
11062 : "m" (v->counter) : "memory");
11063 return c != 0;
11064 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11065 {
11066 unsigned char c;
11067
11068 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
11069 + asm volatile(LOCK_PREFIX "incq %0\n"
11070 +
11071 +#ifdef CONFIG_PAX_REFCOUNT
11072 + "jno 0f\n"
11073 + LOCK_PREFIX "decq %0\n"
11074 + "int $4\n0:\n"
11075 + _ASM_EXTABLE(0b, 0b)
11076 +#endif
11077 +
11078 + "sete %1\n"
11079 : "=m" (v->counter), "=qm" (c)
11080 : "m" (v->counter) : "memory");
11081 return c != 0;
11082 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11083 {
11084 unsigned char c;
11085
11086 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11087 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
11088 +
11089 +#ifdef CONFIG_PAX_REFCOUNT
11090 + "jno 0f\n"
11091 + LOCK_PREFIX "subq %2,%0\n"
11092 + "int $4\n0:\n"
11093 + _ASM_EXTABLE(0b, 0b)
11094 +#endif
11095 +
11096 + "sets %1\n"
11097 : "=m" (v->counter), "=qm" (c)
11098 : "er" (i), "m" (v->counter) : "memory");
11099 return c;
11100 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11101 */
11102 static inline long atomic64_add_return(long i, atomic64_t *v)
11103 {
11104 + return i + xadd_check_overflow(&v->counter, i);
11105 +}
11106 +
11107 +/**
11108 + * atomic64_add_return_unchecked - add and return
11109 + * @i: integer value to add
11110 + * @v: pointer to type atomic64_unchecked_t
11111 + *
11112 + * Atomically adds @i to @v and returns @i + @v
11113 + */
11114 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11115 +{
11116 return i + xadd(&v->counter, i);
11117 }
11118
11119 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11120 }
11121
11122 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11123 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11124 +{
11125 + return atomic64_add_return_unchecked(1, v);
11126 +}
11127 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11128
11129 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11130 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11131 return cmpxchg(&v->counter, old, new);
11132 }
11133
11134 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11135 +{
11136 + return cmpxchg(&v->counter, old, new);
11137 +}
11138 +
11139 static inline long atomic64_xchg(atomic64_t *v, long new)
11140 {
11141 return xchg(&v->counter, new);
11142 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11143 */
11144 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11145 {
11146 - long c, old;
11147 + long c, old, new;
11148 c = atomic64_read(v);
11149 for (;;) {
11150 - if (unlikely(c == (u)))
11151 + if (unlikely(c == u))
11152 break;
11153 - old = atomic64_cmpxchg((v), c, c + (a));
11154 +
11155 + asm volatile("add %2,%0\n"
11156 +
11157 +#ifdef CONFIG_PAX_REFCOUNT
11158 + "jno 0f\n"
11159 + "sub %2,%0\n"
11160 + "int $4\n0:\n"
11161 + _ASM_EXTABLE(0b, 0b)
11162 +#endif
11163 +
11164 + : "=r" (new)
11165 + : "0" (c), "ir" (a));
11166 +
11167 + old = atomic64_cmpxchg(v, c, new);
11168 if (likely(old == c))
11169 break;
11170 c = old;
11171 }
11172 - return c != (u);
11173 + return c != u;
11174 }
11175
11176 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11177 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11178 index 6dfd019..0c6699f 100644
11179 --- a/arch/x86/include/asm/bitops.h
11180 +++ b/arch/x86/include/asm/bitops.h
11181 @@ -40,7 +40,7 @@
11182 * a mask operation on a byte.
11183 */
11184 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11185 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11186 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11187 #define CONST_MASK(nr) (1 << ((nr) & 7))
11188
11189 /**
11190 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11191 index b13fe63..0dab13a 100644
11192 --- a/arch/x86/include/asm/boot.h
11193 +++ b/arch/x86/include/asm/boot.h
11194 @@ -11,10 +11,15 @@
11195 #include <asm/pgtable_types.h>
11196
11197 /* Physical address where kernel should be loaded. */
11198 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11199 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11200 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11201 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11202
11203 +#ifndef __ASSEMBLY__
11204 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
11205 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11206 +#endif
11207 +
11208 /* Minimum kernel alignment, as a power of two */
11209 #ifdef CONFIG_X86_64
11210 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11211 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11212 index 48f99f1..d78ebf9 100644
11213 --- a/arch/x86/include/asm/cache.h
11214 +++ b/arch/x86/include/asm/cache.h
11215 @@ -5,12 +5,13 @@
11216
11217 /* L1 cache line size */
11218 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11219 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11220 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11221
11222 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11223 +#define __read_only __attribute__((__section__(".data..read_only")))
11224
11225 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11226 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11227 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11228
11229 #ifdef CONFIG_X86_VSMP
11230 #ifdef CONFIG_SMP
11231 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11232 index 9863ee3..4a1f8e1 100644
11233 --- a/arch/x86/include/asm/cacheflush.h
11234 +++ b/arch/x86/include/asm/cacheflush.h
11235 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11236 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11237
11238 if (pg_flags == _PGMT_DEFAULT)
11239 - return -1;
11240 + return ~0UL;
11241 else if (pg_flags == _PGMT_WC)
11242 return _PAGE_CACHE_WC;
11243 else if (pg_flags == _PGMT_UC_MINUS)
11244 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11245 index 46fc474..b02b0f9 100644
11246 --- a/arch/x86/include/asm/checksum_32.h
11247 +++ b/arch/x86/include/asm/checksum_32.h
11248 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11249 int len, __wsum sum,
11250 int *src_err_ptr, int *dst_err_ptr);
11251
11252 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11253 + int len, __wsum sum,
11254 + int *src_err_ptr, int *dst_err_ptr);
11255 +
11256 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11257 + int len, __wsum sum,
11258 + int *src_err_ptr, int *dst_err_ptr);
11259 +
11260 /*
11261 * Note: when you get a NULL pointer exception here this means someone
11262 * passed in an incorrect kernel address to one of these functions.
11263 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11264 int *err_ptr)
11265 {
11266 might_sleep();
11267 - return csum_partial_copy_generic((__force void *)src, dst,
11268 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11269 len, sum, err_ptr, NULL);
11270 }
11271
11272 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11273 {
11274 might_sleep();
11275 if (access_ok(VERIFY_WRITE, dst, len))
11276 - return csum_partial_copy_generic(src, (__force void *)dst,
11277 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11278 len, sum, NULL, err_ptr);
11279
11280 if (len)
11281 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11282 index 8d871ea..c1a0dc9 100644
11283 --- a/arch/x86/include/asm/cmpxchg.h
11284 +++ b/arch/x86/include/asm/cmpxchg.h
11285 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11286 __compiletime_error("Bad argument size for cmpxchg");
11287 extern void __xadd_wrong_size(void)
11288 __compiletime_error("Bad argument size for xadd");
11289 +extern void __xadd_check_overflow_wrong_size(void)
11290 + __compiletime_error("Bad argument size for xadd_check_overflow");
11291 extern void __add_wrong_size(void)
11292 __compiletime_error("Bad argument size for add");
11293 +extern void __add_check_overflow_wrong_size(void)
11294 + __compiletime_error("Bad argument size for add_check_overflow");
11295
11296 /*
11297 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11298 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11299 __ret; \
11300 })
11301
11302 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11303 + ({ \
11304 + __typeof__ (*(ptr)) __ret = (arg); \
11305 + switch (sizeof(*(ptr))) { \
11306 + case __X86_CASE_L: \
11307 + asm volatile (lock #op "l %0, %1\n" \
11308 + "jno 0f\n" \
11309 + "mov %0,%1\n" \
11310 + "int $4\n0:\n" \
11311 + _ASM_EXTABLE(0b, 0b) \
11312 + : "+r" (__ret), "+m" (*(ptr)) \
11313 + : : "memory", "cc"); \
11314 + break; \
11315 + case __X86_CASE_Q: \
11316 + asm volatile (lock #op "q %q0, %1\n" \
11317 + "jno 0f\n" \
11318 + "mov %0,%1\n" \
11319 + "int $4\n0:\n" \
11320 + _ASM_EXTABLE(0b, 0b) \
11321 + : "+r" (__ret), "+m" (*(ptr)) \
11322 + : : "memory", "cc"); \
11323 + break; \
11324 + default: \
11325 + __ ## op ## _check_overflow_wrong_size(); \
11326 + } \
11327 + __ret; \
11328 + })
11329 +
11330 /*
11331 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11332 * Since this is generally used to protect other memory information, we
11333 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11334 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11335 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11336
11337 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11338 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11339 +
11340 #define __add(ptr, inc, lock) \
11341 ({ \
11342 __typeof__ (*(ptr)) __ret = (inc); \
11343 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11344 index 8c297aa..7a90f03 100644
11345 --- a/arch/x86/include/asm/cpufeature.h
11346 +++ b/arch/x86/include/asm/cpufeature.h
11347 @@ -205,7 +205,7 @@
11348 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11349 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11350 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11351 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11352 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11353 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11354 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11355 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11356 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11357 ".section .discard,\"aw\",@progbits\n"
11358 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11359 ".previous\n"
11360 - ".section .altinstr_replacement,\"ax\"\n"
11361 + ".section .altinstr_replacement,\"a\"\n"
11362 "3: movb $1,%0\n"
11363 "4:\n"
11364 ".previous\n"
11365 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11366 index 8bf1c06..f723dfd 100644
11367 --- a/arch/x86/include/asm/desc.h
11368 +++ b/arch/x86/include/asm/desc.h
11369 @@ -4,6 +4,7 @@
11370 #include <asm/desc_defs.h>
11371 #include <asm/ldt.h>
11372 #include <asm/mmu.h>
11373 +#include <asm/pgtable.h>
11374
11375 #include <linux/smp.h>
11376 #include <linux/percpu.h>
11377 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11378
11379 desc->type = (info->read_exec_only ^ 1) << 1;
11380 desc->type |= info->contents << 2;
11381 + desc->type |= info->seg_not_present ^ 1;
11382
11383 desc->s = 1;
11384 desc->dpl = 0x3;
11385 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11386 }
11387
11388 extern struct desc_ptr idt_descr;
11389 -extern gate_desc idt_table[];
11390 extern struct desc_ptr nmi_idt_descr;
11391 -extern gate_desc nmi_idt_table[];
11392 -
11393 -struct gdt_page {
11394 - struct desc_struct gdt[GDT_ENTRIES];
11395 -} __attribute__((aligned(PAGE_SIZE)));
11396 -
11397 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11398 +extern gate_desc idt_table[256];
11399 +extern gate_desc nmi_idt_table[256];
11400
11401 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11402 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11403 {
11404 - return per_cpu(gdt_page, cpu).gdt;
11405 + return cpu_gdt_table[cpu];
11406 }
11407
11408 #ifdef CONFIG_X86_64
11409 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11410 unsigned long base, unsigned dpl, unsigned flags,
11411 unsigned short seg)
11412 {
11413 - gate->a = (seg << 16) | (base & 0xffff);
11414 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11415 + gate->gate.offset_low = base;
11416 + gate->gate.seg = seg;
11417 + gate->gate.reserved = 0;
11418 + gate->gate.type = type;
11419 + gate->gate.s = 0;
11420 + gate->gate.dpl = dpl;
11421 + gate->gate.p = 1;
11422 + gate->gate.offset_high = base >> 16;
11423 }
11424
11425 #endif
11426 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11427
11428 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11429 {
11430 + pax_open_kernel();
11431 memcpy(&idt[entry], gate, sizeof(*gate));
11432 + pax_close_kernel();
11433 }
11434
11435 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11436 {
11437 + pax_open_kernel();
11438 memcpy(&ldt[entry], desc, 8);
11439 + pax_close_kernel();
11440 }
11441
11442 static inline void
11443 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11444 default: size = sizeof(*gdt); break;
11445 }
11446
11447 + pax_open_kernel();
11448 memcpy(&gdt[entry], desc, size);
11449 + pax_close_kernel();
11450 }
11451
11452 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11453 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11454
11455 static inline void native_load_tr_desc(void)
11456 {
11457 + pax_open_kernel();
11458 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11459 + pax_close_kernel();
11460 }
11461
11462 static inline void native_load_gdt(const struct desc_ptr *dtr)
11463 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11464 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11465 unsigned int i;
11466
11467 + pax_open_kernel();
11468 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11469 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11470 + pax_close_kernel();
11471 }
11472
11473 #define _LDT_empty(info) \
11474 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11475 }
11476
11477 #ifdef CONFIG_X86_64
11478 -static inline void set_nmi_gate(int gate, void *addr)
11479 +static inline void set_nmi_gate(int gate, const void *addr)
11480 {
11481 gate_desc s;
11482
11483 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11484 }
11485 #endif
11486
11487 -static inline void _set_gate(int gate, unsigned type, void *addr,
11488 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11489 unsigned dpl, unsigned ist, unsigned seg)
11490 {
11491 gate_desc s;
11492 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11493 * Pentium F0 0F bugfix can have resulted in the mapped
11494 * IDT being write-protected.
11495 */
11496 -static inline void set_intr_gate(unsigned int n, void *addr)
11497 +static inline void set_intr_gate(unsigned int n, const void *addr)
11498 {
11499 BUG_ON((unsigned)n > 0xFF);
11500 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11501 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11502 /*
11503 * This routine sets up an interrupt gate at directory privilege level 3.
11504 */
11505 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11506 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11507 {
11508 BUG_ON((unsigned)n > 0xFF);
11509 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11510 }
11511
11512 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11513 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11514 {
11515 BUG_ON((unsigned)n > 0xFF);
11516 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11517 }
11518
11519 -static inline void set_trap_gate(unsigned int n, void *addr)
11520 +static inline void set_trap_gate(unsigned int n, const void *addr)
11521 {
11522 BUG_ON((unsigned)n > 0xFF);
11523 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11524 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11525 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11526 {
11527 BUG_ON((unsigned)n > 0xFF);
11528 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11529 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11530 }
11531
11532 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11533 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11534 {
11535 BUG_ON((unsigned)n > 0xFF);
11536 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11537 }
11538
11539 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11540 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11541 {
11542 BUG_ON((unsigned)n > 0xFF);
11543 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11544 }
11545
11546 +#ifdef CONFIG_X86_32
11547 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11548 +{
11549 + struct desc_struct d;
11550 +
11551 + if (likely(limit))
11552 + limit = (limit - 1UL) >> PAGE_SHIFT;
11553 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11554 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11555 +}
11556 +#endif
11557 +
11558 #endif /* _ASM_X86_DESC_H */
11559 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11560 index 278441f..b95a174 100644
11561 --- a/arch/x86/include/asm/desc_defs.h
11562 +++ b/arch/x86/include/asm/desc_defs.h
11563 @@ -31,6 +31,12 @@ struct desc_struct {
11564 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11565 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11566 };
11567 + struct {
11568 + u16 offset_low;
11569 + u16 seg;
11570 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11571 + unsigned offset_high: 16;
11572 + } gate;
11573 };
11574 } __attribute__((packed));
11575
11576 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11577 index 3778256..c5d4fce 100644
11578 --- a/arch/x86/include/asm/e820.h
11579 +++ b/arch/x86/include/asm/e820.h
11580 @@ -69,7 +69,7 @@ struct e820map {
11581 #define ISA_START_ADDRESS 0xa0000
11582 #define ISA_END_ADDRESS 0x100000
11583
11584 -#define BIOS_BEGIN 0x000a0000
11585 +#define BIOS_BEGIN 0x000c0000
11586 #define BIOS_END 0x00100000
11587
11588 #define BIOS_ROM_BASE 0xffe00000
11589 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11590 index 5939f44..f8845f6 100644
11591 --- a/arch/x86/include/asm/elf.h
11592 +++ b/arch/x86/include/asm/elf.h
11593 @@ -243,7 +243,25 @@ extern int force_personality32;
11594 the loader. We need to make sure that it is out of the way of the program
11595 that it will "exec", and that there is sufficient room for the brk. */
11596
11597 +#ifdef CONFIG_PAX_SEGMEXEC
11598 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11599 +#else
11600 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11601 +#endif
11602 +
11603 +#ifdef CONFIG_PAX_ASLR
11604 +#ifdef CONFIG_X86_32
11605 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11606 +
11607 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11608 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11609 +#else
11610 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11611 +
11612 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11613 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11614 +#endif
11615 +#endif
11616
11617 /* This yields a mask that user programs can use to figure out what
11618 instruction set this CPU supports. This could be done in user space,
11619 @@ -296,16 +314,12 @@ do { \
11620
11621 #define ARCH_DLINFO \
11622 do { \
11623 - if (vdso_enabled) \
11624 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11625 - (unsigned long)current->mm->context.vdso); \
11626 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11627 } while (0)
11628
11629 #define ARCH_DLINFO_X32 \
11630 do { \
11631 - if (vdso_enabled) \
11632 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11633 - (unsigned long)current->mm->context.vdso); \
11634 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11635 } while (0)
11636
11637 #define AT_SYSINFO 32
11638 @@ -320,7 +334,7 @@ else \
11639
11640 #endif /* !CONFIG_X86_32 */
11641
11642 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11643 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11644
11645 #define VDSO_ENTRY \
11646 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11647 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11648 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11649 #define compat_arch_setup_additional_pages syscall32_setup_pages
11650
11651 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11652 -#define arch_randomize_brk arch_randomize_brk
11653 -
11654 /*
11655 * True on X86_32 or when emulating IA32 on X86_64
11656 */
11657 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11658 index 75ce3f4..882e801 100644
11659 --- a/arch/x86/include/asm/emergency-restart.h
11660 +++ b/arch/x86/include/asm/emergency-restart.h
11661 @@ -13,6 +13,6 @@ enum reboot_type {
11662
11663 extern enum reboot_type reboot_type;
11664
11665 -extern void machine_emergency_restart(void);
11666 +extern void machine_emergency_restart(void) __noreturn;
11667
11668 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11669 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11670 index 41ab26e..a88c9e6 100644
11671 --- a/arch/x86/include/asm/fpu-internal.h
11672 +++ b/arch/x86/include/asm/fpu-internal.h
11673 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11674 ({ \
11675 int err; \
11676 asm volatile(ASM_STAC "\n" \
11677 - "1:" #insn "\n\t" \
11678 + "1:" \
11679 + __copyuser_seg \
11680 + #insn "\n\t" \
11681 "2: " ASM_CLAC "\n" \
11682 ".section .fixup,\"ax\"\n" \
11683 "3: movl $-1,%[err]\n" \
11684 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11685 "emms\n\t" /* clear stack tags */
11686 "fildl %P[addr]", /* set F?P to defined value */
11687 X86_FEATURE_FXSAVE_LEAK,
11688 - [addr] "m" (tsk->thread.fpu.has_fpu));
11689 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11690
11691 return fpu_restore_checking(&tsk->thread.fpu);
11692 }
11693 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11694 index f373046..02653e2 100644
11695 --- a/arch/x86/include/asm/futex.h
11696 +++ b/arch/x86/include/asm/futex.h
11697 @@ -12,6 +12,7 @@
11698 #include <asm/smap.h>
11699
11700 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11701 + typecheck(u32 __user *, uaddr); \
11702 asm volatile("\t" ASM_STAC "\n" \
11703 "1:\t" insn "\n" \
11704 "2:\t" ASM_CLAC "\n" \
11705 @@ -20,15 +21,16 @@
11706 "\tjmp\t2b\n" \
11707 "\t.previous\n" \
11708 _ASM_EXTABLE(1b, 3b) \
11709 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11710 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11711 : "i" (-EFAULT), "0" (oparg), "1" (0))
11712
11713 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11714 + typecheck(u32 __user *, uaddr); \
11715 asm volatile("\t" ASM_STAC "\n" \
11716 "1:\tmovl %2, %0\n" \
11717 "\tmovl\t%0, %3\n" \
11718 "\t" insn "\n" \
11719 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11720 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11721 "\tjnz\t1b\n" \
11722 "3:\t" ASM_CLAC "\n" \
11723 "\t.section .fixup,\"ax\"\n" \
11724 @@ -38,7 +40,7 @@
11725 _ASM_EXTABLE(1b, 4b) \
11726 _ASM_EXTABLE(2b, 4b) \
11727 : "=&a" (oldval), "=&r" (ret), \
11728 - "+m" (*uaddr), "=&r" (tem) \
11729 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11730 : "r" (oparg), "i" (-EFAULT), "1" (0))
11731
11732 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11733 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11734
11735 switch (op) {
11736 case FUTEX_OP_SET:
11737 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11738 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11739 break;
11740 case FUTEX_OP_ADD:
11741 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11742 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11743 uaddr, oparg);
11744 break;
11745 case FUTEX_OP_OR:
11746 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11747 return -EFAULT;
11748
11749 asm volatile("\t" ASM_STAC "\n"
11750 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11751 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11752 "2:\t" ASM_CLAC "\n"
11753 "\t.section .fixup, \"ax\"\n"
11754 "3:\tmov %3, %0\n"
11755 "\tjmp 2b\n"
11756 "\t.previous\n"
11757 _ASM_EXTABLE(1b, 3b)
11758 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11759 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11760 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11761 : "memory"
11762 );
11763 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11764 index eb92a6e..b98b2f4 100644
11765 --- a/arch/x86/include/asm/hw_irq.h
11766 +++ b/arch/x86/include/asm/hw_irq.h
11767 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11768 extern void enable_IO_APIC(void);
11769
11770 /* Statistics */
11771 -extern atomic_t irq_err_count;
11772 -extern atomic_t irq_mis_count;
11773 +extern atomic_unchecked_t irq_err_count;
11774 +extern atomic_unchecked_t irq_mis_count;
11775
11776 /* EISA */
11777 extern void eisa_set_level_irq(unsigned int irq);
11778 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11779 index d8e8eef..15b1179 100644
11780 --- a/arch/x86/include/asm/io.h
11781 +++ b/arch/x86/include/asm/io.h
11782 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11783 return ioremap_nocache(offset, size);
11784 }
11785
11786 -extern void iounmap(volatile void __iomem *addr);
11787 +extern void iounmap(const volatile void __iomem *addr);
11788
11789 extern void set_iounmap_nonlazy(void);
11790
11791 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11792
11793 #include <linux/vmalloc.h>
11794
11795 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11796 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11797 +{
11798 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11799 +}
11800 +
11801 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11802 +{
11803 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11804 +}
11805 +
11806 /*
11807 * Convert a virtual cached pointer to an uncached pointer
11808 */
11809 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11810 index bba3cf8..06bc8da 100644
11811 --- a/arch/x86/include/asm/irqflags.h
11812 +++ b/arch/x86/include/asm/irqflags.h
11813 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11814 sti; \
11815 sysexit
11816
11817 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11818 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11819 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11820 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11821 +
11822 #else
11823 #define INTERRUPT_RETURN iret
11824 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11825 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11826 index d3ddd17..c9fb0cc 100644
11827 --- a/arch/x86/include/asm/kprobes.h
11828 +++ b/arch/x86/include/asm/kprobes.h
11829 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11830 #define RELATIVEJUMP_SIZE 5
11831 #define RELATIVECALL_OPCODE 0xe8
11832 #define RELATIVE_ADDR_SIZE 4
11833 -#define MAX_STACK_SIZE 64
11834 -#define MIN_STACK_SIZE(ADDR) \
11835 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11836 - THREAD_SIZE - (unsigned long)(ADDR))) \
11837 - ? (MAX_STACK_SIZE) \
11838 - : (((unsigned long)current_thread_info()) + \
11839 - THREAD_SIZE - (unsigned long)(ADDR)))
11840 +#define MAX_STACK_SIZE 64UL
11841 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11842
11843 #define flush_insn_slot(p) do { } while (0)
11844
11845 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11846 index b2e11f4..f293e2e 100644
11847 --- a/arch/x86/include/asm/kvm_host.h
11848 +++ b/arch/x86/include/asm/kvm_host.h
11849 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
11850 int (*check_intercept)(struct kvm_vcpu *vcpu,
11851 struct x86_instruction_info *info,
11852 enum x86_intercept_stage stage);
11853 -};
11854 +} __do_const;
11855
11856 struct kvm_arch_async_pf {
11857 u32 token;
11858 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11859 index c8bed0d..85c03fd 100644
11860 --- a/arch/x86/include/asm/local.h
11861 +++ b/arch/x86/include/asm/local.h
11862 @@ -10,33 +10,97 @@ typedef struct {
11863 atomic_long_t a;
11864 } local_t;
11865
11866 +typedef struct {
11867 + atomic_long_unchecked_t a;
11868 +} local_unchecked_t;
11869 +
11870 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11871
11872 #define local_read(l) atomic_long_read(&(l)->a)
11873 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11874 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11875 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11876
11877 static inline void local_inc(local_t *l)
11878 {
11879 - asm volatile(_ASM_INC "%0"
11880 + asm volatile(_ASM_INC "%0\n"
11881 +
11882 +#ifdef CONFIG_PAX_REFCOUNT
11883 + "jno 0f\n"
11884 + _ASM_DEC "%0\n"
11885 + "int $4\n0:\n"
11886 + _ASM_EXTABLE(0b, 0b)
11887 +#endif
11888 +
11889 + : "+m" (l->a.counter));
11890 +}
11891 +
11892 +static inline void local_inc_unchecked(local_unchecked_t *l)
11893 +{
11894 + asm volatile(_ASM_INC "%0\n"
11895 : "+m" (l->a.counter));
11896 }
11897
11898 static inline void local_dec(local_t *l)
11899 {
11900 - asm volatile(_ASM_DEC "%0"
11901 + asm volatile(_ASM_DEC "%0\n"
11902 +
11903 +#ifdef CONFIG_PAX_REFCOUNT
11904 + "jno 0f\n"
11905 + _ASM_INC "%0\n"
11906 + "int $4\n0:\n"
11907 + _ASM_EXTABLE(0b, 0b)
11908 +#endif
11909 +
11910 + : "+m" (l->a.counter));
11911 +}
11912 +
11913 +static inline void local_dec_unchecked(local_unchecked_t *l)
11914 +{
11915 + asm volatile(_ASM_DEC "%0\n"
11916 : "+m" (l->a.counter));
11917 }
11918
11919 static inline void local_add(long i, local_t *l)
11920 {
11921 - asm volatile(_ASM_ADD "%1,%0"
11922 + asm volatile(_ASM_ADD "%1,%0\n"
11923 +
11924 +#ifdef CONFIG_PAX_REFCOUNT
11925 + "jno 0f\n"
11926 + _ASM_SUB "%1,%0\n"
11927 + "int $4\n0:\n"
11928 + _ASM_EXTABLE(0b, 0b)
11929 +#endif
11930 +
11931 + : "+m" (l->a.counter)
11932 + : "ir" (i));
11933 +}
11934 +
11935 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
11936 +{
11937 + asm volatile(_ASM_ADD "%1,%0\n"
11938 : "+m" (l->a.counter)
11939 : "ir" (i));
11940 }
11941
11942 static inline void local_sub(long i, local_t *l)
11943 {
11944 - asm volatile(_ASM_SUB "%1,%0"
11945 + asm volatile(_ASM_SUB "%1,%0\n"
11946 +
11947 +#ifdef CONFIG_PAX_REFCOUNT
11948 + "jno 0f\n"
11949 + _ASM_ADD "%1,%0\n"
11950 + "int $4\n0:\n"
11951 + _ASM_EXTABLE(0b, 0b)
11952 +#endif
11953 +
11954 + : "+m" (l->a.counter)
11955 + : "ir" (i));
11956 +}
11957 +
11958 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
11959 +{
11960 + asm volatile(_ASM_SUB "%1,%0\n"
11961 : "+m" (l->a.counter)
11962 : "ir" (i));
11963 }
11964 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
11965 {
11966 unsigned char c;
11967
11968 - asm volatile(_ASM_SUB "%2,%0; sete %1"
11969 + asm volatile(_ASM_SUB "%2,%0\n"
11970 +
11971 +#ifdef CONFIG_PAX_REFCOUNT
11972 + "jno 0f\n"
11973 + _ASM_ADD "%2,%0\n"
11974 + "int $4\n0:\n"
11975 + _ASM_EXTABLE(0b, 0b)
11976 +#endif
11977 +
11978 + "sete %1\n"
11979 : "+m" (l->a.counter), "=qm" (c)
11980 : "ir" (i) : "memory");
11981 return c;
11982 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
11983 {
11984 unsigned char c;
11985
11986 - asm volatile(_ASM_DEC "%0; sete %1"
11987 + asm volatile(_ASM_DEC "%0\n"
11988 +
11989 +#ifdef CONFIG_PAX_REFCOUNT
11990 + "jno 0f\n"
11991 + _ASM_INC "%0\n"
11992 + "int $4\n0:\n"
11993 + _ASM_EXTABLE(0b, 0b)
11994 +#endif
11995 +
11996 + "sete %1\n"
11997 : "+m" (l->a.counter), "=qm" (c)
11998 : : "memory");
11999 return c != 0;
12000 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12001 {
12002 unsigned char c;
12003
12004 - asm volatile(_ASM_INC "%0; sete %1"
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 + "sete %1\n"
12015 : "+m" (l->a.counter), "=qm" (c)
12016 : : "memory");
12017 return c != 0;
12018 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12019 {
12020 unsigned char c;
12021
12022 - asm volatile(_ASM_ADD "%2,%0; sets %1"
12023 + asm volatile(_ASM_ADD "%2,%0\n"
12024 +
12025 +#ifdef CONFIG_PAX_REFCOUNT
12026 + "jno 0f\n"
12027 + _ASM_SUB "%2,%0\n"
12028 + "int $4\n0:\n"
12029 + _ASM_EXTABLE(0b, 0b)
12030 +#endif
12031 +
12032 + "sets %1\n"
12033 : "+m" (l->a.counter), "=qm" (c)
12034 : "ir" (i) : "memory");
12035 return c;
12036 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12037 #endif
12038 /* Modern 486+ processor */
12039 __i = i;
12040 - asm volatile(_ASM_XADD "%0, %1;"
12041 + asm volatile(_ASM_XADD "%0, %1\n"
12042 +
12043 +#ifdef CONFIG_PAX_REFCOUNT
12044 + "jno 0f\n"
12045 + _ASM_MOV "%0,%1\n"
12046 + "int $4\n0:\n"
12047 + _ASM_EXTABLE(0b, 0b)
12048 +#endif
12049 +
12050 : "+r" (i), "+m" (l->a.counter)
12051 : : "memory");
12052 return i + __i;
12053 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12054 #endif
12055 }
12056
12057 +/**
12058 + * local_add_return_unchecked - add and return
12059 + * @i: integer value to add
12060 + * @l: pointer to type local_unchecked_t
12061 + *
12062 + * Atomically adds @i to @l and returns @i + @l
12063 + */
12064 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12065 +{
12066 + long __i;
12067 +#ifdef CONFIG_M386
12068 + unsigned long flags;
12069 + if (unlikely(boot_cpu_data.x86 <= 3))
12070 + goto no_xadd;
12071 +#endif
12072 + /* Modern 486+ processor */
12073 + __i = i;
12074 + asm volatile(_ASM_XADD "%0, %1\n"
12075 + : "+r" (i), "+m" (l->a.counter)
12076 + : : "memory");
12077 + return i + __i;
12078 +
12079 +#ifdef CONFIG_M386
12080 +no_xadd: /* Legacy 386 processor */
12081 + local_irq_save(flags);
12082 + __i = local_read_unchecked(l);
12083 + local_set_unchecked(l, i + __i);
12084 + local_irq_restore(flags);
12085 + return i + __i;
12086 +#endif
12087 +}
12088 +
12089 static inline long local_sub_return(long i, local_t *l)
12090 {
12091 return local_add_return(-i, l);
12092 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12093
12094 #define local_cmpxchg(l, o, n) \
12095 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12096 +#define local_cmpxchg_unchecked(l, o, n) \
12097 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
12098 /* Always has a lock prefix */
12099 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12100
12101 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12102 index 593e51d..fa69c9a 100644
12103 --- a/arch/x86/include/asm/mman.h
12104 +++ b/arch/x86/include/asm/mman.h
12105 @@ -5,4 +5,14 @@
12106
12107 #include <asm-generic/mman.h>
12108
12109 +#ifdef __KERNEL__
12110 +#ifndef __ASSEMBLY__
12111 +#ifdef CONFIG_X86_32
12112 +#define arch_mmap_check i386_mmap_check
12113 +int i386_mmap_check(unsigned long addr, unsigned long len,
12114 + unsigned long flags);
12115 +#endif
12116 +#endif
12117 +#endif
12118 +
12119 #endif /* _ASM_X86_MMAN_H */
12120 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12121 index 5f55e69..e20bfb1 100644
12122 --- a/arch/x86/include/asm/mmu.h
12123 +++ b/arch/x86/include/asm/mmu.h
12124 @@ -9,7 +9,7 @@
12125 * we put the segment information here.
12126 */
12127 typedef struct {
12128 - void *ldt;
12129 + struct desc_struct *ldt;
12130 int size;
12131
12132 #ifdef CONFIG_X86_64
12133 @@ -18,7 +18,19 @@ typedef struct {
12134 #endif
12135
12136 struct mutex lock;
12137 - void *vdso;
12138 + unsigned long vdso;
12139 +
12140 +#ifdef CONFIG_X86_32
12141 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12142 + unsigned long user_cs_base;
12143 + unsigned long user_cs_limit;
12144 +
12145 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12146 + cpumask_t cpu_user_cs_mask;
12147 +#endif
12148 +
12149 +#endif
12150 +#endif
12151 } mm_context_t;
12152
12153 #ifdef CONFIG_SMP
12154 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12155 index cdbf367..adb37ac 100644
12156 --- a/arch/x86/include/asm/mmu_context.h
12157 +++ b/arch/x86/include/asm/mmu_context.h
12158 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12159
12160 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12161 {
12162 +
12163 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12164 + unsigned int i;
12165 + pgd_t *pgd;
12166 +
12167 + pax_open_kernel();
12168 + pgd = get_cpu_pgd(smp_processor_id());
12169 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12170 + set_pgd_batched(pgd+i, native_make_pgd(0));
12171 + pax_close_kernel();
12172 +#endif
12173 +
12174 #ifdef CONFIG_SMP
12175 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12176 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12177 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12178 struct task_struct *tsk)
12179 {
12180 unsigned cpu = smp_processor_id();
12181 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12182 + int tlbstate = TLBSTATE_OK;
12183 +#endif
12184
12185 if (likely(prev != next)) {
12186 #ifdef CONFIG_SMP
12187 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12188 + tlbstate = this_cpu_read(cpu_tlbstate.state);
12189 +#endif
12190 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12191 this_cpu_write(cpu_tlbstate.active_mm, next);
12192 #endif
12193 cpumask_set_cpu(cpu, mm_cpumask(next));
12194
12195 /* Re-load page tables */
12196 +#ifdef CONFIG_PAX_PER_CPU_PGD
12197 + pax_open_kernel();
12198 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12199 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12200 + pax_close_kernel();
12201 + load_cr3(get_cpu_pgd(cpu));
12202 +#else
12203 load_cr3(next->pgd);
12204 +#endif
12205
12206 /* stop flush ipis for the previous mm */
12207 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12208 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12209 */
12210 if (unlikely(prev->context.ldt != next->context.ldt))
12211 load_LDT_nolock(&next->context);
12212 - }
12213 +
12214 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12215 + if (!(__supported_pte_mask & _PAGE_NX)) {
12216 + smp_mb__before_clear_bit();
12217 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12218 + smp_mb__after_clear_bit();
12219 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12220 + }
12221 +#endif
12222 +
12223 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12224 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12225 + prev->context.user_cs_limit != next->context.user_cs_limit))
12226 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12227 #ifdef CONFIG_SMP
12228 + else if (unlikely(tlbstate != TLBSTATE_OK))
12229 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12230 +#endif
12231 +#endif
12232 +
12233 + }
12234 else {
12235 +
12236 +#ifdef CONFIG_PAX_PER_CPU_PGD
12237 + pax_open_kernel();
12238 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12239 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12240 + pax_close_kernel();
12241 + load_cr3(get_cpu_pgd(cpu));
12242 +#endif
12243 +
12244 +#ifdef CONFIG_SMP
12245 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12246 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12247
12248 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12249 * tlb flush IPI delivery. We must reload CR3
12250 * to make sure to use no freed page tables.
12251 */
12252 +
12253 +#ifndef CONFIG_PAX_PER_CPU_PGD
12254 load_cr3(next->pgd);
12255 +#endif
12256 +
12257 load_LDT_nolock(&next->context);
12258 +
12259 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12260 + if (!(__supported_pte_mask & _PAGE_NX))
12261 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12262 +#endif
12263 +
12264 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12265 +#ifdef CONFIG_PAX_PAGEEXEC
12266 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12267 +#endif
12268 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12269 +#endif
12270 +
12271 }
12272 +#endif
12273 }
12274 -#endif
12275 }
12276
12277 #define activate_mm(prev, next) \
12278 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12279 index 9eae775..c914fea 100644
12280 --- a/arch/x86/include/asm/module.h
12281 +++ b/arch/x86/include/asm/module.h
12282 @@ -5,6 +5,7 @@
12283
12284 #ifdef CONFIG_X86_64
12285 /* X86_64 does not define MODULE_PROC_FAMILY */
12286 +#define MODULE_PROC_FAMILY ""
12287 #elif defined CONFIG_M386
12288 #define MODULE_PROC_FAMILY "386 "
12289 #elif defined CONFIG_M486
12290 @@ -59,8 +60,20 @@
12291 #error unknown processor family
12292 #endif
12293
12294 -#ifdef CONFIG_X86_32
12295 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12296 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12297 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12298 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12299 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12300 +#else
12301 +#define MODULE_PAX_KERNEXEC ""
12302 #endif
12303
12304 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12305 +#define MODULE_PAX_UDEREF "UDEREF "
12306 +#else
12307 +#define MODULE_PAX_UDEREF ""
12308 +#endif
12309 +
12310 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12311 +
12312 #endif /* _ASM_X86_MODULE_H */
12313 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12314 index 320f7bb..e89f8f8 100644
12315 --- a/arch/x86/include/asm/page_64_types.h
12316 +++ b/arch/x86/include/asm/page_64_types.h
12317 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12318
12319 /* duplicated to the one in bootmem.h */
12320 extern unsigned long max_pfn;
12321 -extern unsigned long phys_base;
12322 +extern const unsigned long phys_base;
12323
12324 extern unsigned long __phys_addr(unsigned long);
12325 #define __phys_reloc_hide(x) (x)
12326 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12327 index a0facf3..c017b15 100644
12328 --- a/arch/x86/include/asm/paravirt.h
12329 +++ b/arch/x86/include/asm/paravirt.h
12330 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12331 val);
12332 }
12333
12334 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12335 +{
12336 + pgdval_t val = native_pgd_val(pgd);
12337 +
12338 + if (sizeof(pgdval_t) > sizeof(long))
12339 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12340 + val, (u64)val >> 32);
12341 + else
12342 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12343 + val);
12344 +}
12345 +
12346 static inline void pgd_clear(pgd_t *pgdp)
12347 {
12348 set_pgd(pgdp, __pgd(0));
12349 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12350 pv_mmu_ops.set_fixmap(idx, phys, flags);
12351 }
12352
12353 +#ifdef CONFIG_PAX_KERNEXEC
12354 +static inline unsigned long pax_open_kernel(void)
12355 +{
12356 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12357 +}
12358 +
12359 +static inline unsigned long pax_close_kernel(void)
12360 +{
12361 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12362 +}
12363 +#else
12364 +static inline unsigned long pax_open_kernel(void) { return 0; }
12365 +static inline unsigned long pax_close_kernel(void) { return 0; }
12366 +#endif
12367 +
12368 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12369
12370 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12371 @@ -929,7 +956,7 @@ extern void default_banner(void);
12372
12373 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12374 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12375 -#define PARA_INDIRECT(addr) *%cs:addr
12376 +#define PARA_INDIRECT(addr) *%ss:addr
12377 #endif
12378
12379 #define INTERRUPT_RETURN \
12380 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12381 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12382 CLBR_NONE, \
12383 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12384 +
12385 +#define GET_CR0_INTO_RDI \
12386 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12387 + mov %rax,%rdi
12388 +
12389 +#define SET_RDI_INTO_CR0 \
12390 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12391 +
12392 +#define GET_CR3_INTO_RDI \
12393 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12394 + mov %rax,%rdi
12395 +
12396 +#define SET_RDI_INTO_CR3 \
12397 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12398 +
12399 #endif /* CONFIG_X86_32 */
12400
12401 #endif /* __ASSEMBLY__ */
12402 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12403 index 142236e..57cf5ea 100644
12404 --- a/arch/x86/include/asm/paravirt_types.h
12405 +++ b/arch/x86/include/asm/paravirt_types.h
12406 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12407 struct paravirt_callee_save make_pud;
12408
12409 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12410 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12411 #endif /* PAGETABLE_LEVELS == 4 */
12412 #endif /* PAGETABLE_LEVELS >= 3 */
12413
12414 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12415 an mfn. We can tell which is which from the index. */
12416 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12417 phys_addr_t phys, pgprot_t flags);
12418 +
12419 +#ifdef CONFIG_PAX_KERNEXEC
12420 + unsigned long (*pax_open_kernel)(void);
12421 + unsigned long (*pax_close_kernel)(void);
12422 +#endif
12423 +
12424 };
12425
12426 struct arch_spinlock;
12427 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12428 index b4389a4..7024269 100644
12429 --- a/arch/x86/include/asm/pgalloc.h
12430 +++ b/arch/x86/include/asm/pgalloc.h
12431 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12432 pmd_t *pmd, pte_t *pte)
12433 {
12434 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12435 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12436 +}
12437 +
12438 +static inline void pmd_populate_user(struct mm_struct *mm,
12439 + pmd_t *pmd, pte_t *pte)
12440 +{
12441 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12442 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12443 }
12444
12445 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12446
12447 #ifdef CONFIG_X86_PAE
12448 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12449 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12450 +{
12451 + pud_populate(mm, pudp, pmd);
12452 +}
12453 #else /* !CONFIG_X86_PAE */
12454 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12455 {
12456 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12457 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12458 }
12459 +
12460 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12461 +{
12462 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12463 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12464 +}
12465 #endif /* CONFIG_X86_PAE */
12466
12467 #if PAGETABLE_LEVELS > 3
12468 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12469 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12470 }
12471
12472 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12473 +{
12474 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12475 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12476 +}
12477 +
12478 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12479 {
12480 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12481 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12482 index f2b489c..4f7e2e5 100644
12483 --- a/arch/x86/include/asm/pgtable-2level.h
12484 +++ b/arch/x86/include/asm/pgtable-2level.h
12485 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12486
12487 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12488 {
12489 + pax_open_kernel();
12490 *pmdp = pmd;
12491 + pax_close_kernel();
12492 }
12493
12494 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12495 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12496 index 4cc9f2b..5fd9226 100644
12497 --- a/arch/x86/include/asm/pgtable-3level.h
12498 +++ b/arch/x86/include/asm/pgtable-3level.h
12499 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12500
12501 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12502 {
12503 + pax_open_kernel();
12504 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12505 + pax_close_kernel();
12506 }
12507
12508 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12509 {
12510 + pax_open_kernel();
12511 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12512 + pax_close_kernel();
12513 }
12514
12515 /*
12516 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12517 index a1f780d..5f38ced4 100644
12518 --- a/arch/x86/include/asm/pgtable.h
12519 +++ b/arch/x86/include/asm/pgtable.h
12520 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12521
12522 #ifndef __PAGETABLE_PUD_FOLDED
12523 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12524 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12525 #define pgd_clear(pgd) native_pgd_clear(pgd)
12526 #endif
12527
12528 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12529
12530 #define arch_end_context_switch(prev) do {} while(0)
12531
12532 +#define pax_open_kernel() native_pax_open_kernel()
12533 +#define pax_close_kernel() native_pax_close_kernel()
12534 #endif /* CONFIG_PARAVIRT */
12535
12536 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12537 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12538 +
12539 +#ifdef CONFIG_PAX_KERNEXEC
12540 +static inline unsigned long native_pax_open_kernel(void)
12541 +{
12542 + unsigned long cr0;
12543 +
12544 + preempt_disable();
12545 + barrier();
12546 + cr0 = read_cr0() ^ X86_CR0_WP;
12547 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
12548 + write_cr0(cr0);
12549 + return cr0 ^ X86_CR0_WP;
12550 +}
12551 +
12552 +static inline unsigned long native_pax_close_kernel(void)
12553 +{
12554 + unsigned long cr0;
12555 +
12556 + cr0 = read_cr0() ^ X86_CR0_WP;
12557 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
12558 + write_cr0(cr0);
12559 + barrier();
12560 + preempt_enable_no_resched();
12561 + return cr0 ^ X86_CR0_WP;
12562 +}
12563 +#else
12564 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12565 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12566 +#endif
12567 +
12568 /*
12569 * The following only work if pte_present() is true.
12570 * Undefined behaviour if not..
12571 */
12572 +static inline int pte_user(pte_t pte)
12573 +{
12574 + return pte_val(pte) & _PAGE_USER;
12575 +}
12576 +
12577 static inline int pte_dirty(pte_t pte)
12578 {
12579 return pte_flags(pte) & _PAGE_DIRTY;
12580 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12581 return pte_clear_flags(pte, _PAGE_RW);
12582 }
12583
12584 +static inline pte_t pte_mkread(pte_t pte)
12585 +{
12586 + return __pte(pte_val(pte) | _PAGE_USER);
12587 +}
12588 +
12589 static inline pte_t pte_mkexec(pte_t pte)
12590 {
12591 - return pte_clear_flags(pte, _PAGE_NX);
12592 +#ifdef CONFIG_X86_PAE
12593 + if (__supported_pte_mask & _PAGE_NX)
12594 + return pte_clear_flags(pte, _PAGE_NX);
12595 + else
12596 +#endif
12597 + return pte_set_flags(pte, _PAGE_USER);
12598 +}
12599 +
12600 +static inline pte_t pte_exprotect(pte_t pte)
12601 +{
12602 +#ifdef CONFIG_X86_PAE
12603 + if (__supported_pte_mask & _PAGE_NX)
12604 + return pte_set_flags(pte, _PAGE_NX);
12605 + else
12606 +#endif
12607 + return pte_clear_flags(pte, _PAGE_USER);
12608 }
12609
12610 static inline pte_t pte_mkdirty(pte_t pte)
12611 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12612 #endif
12613
12614 #ifndef __ASSEMBLY__
12615 +
12616 +#ifdef CONFIG_PAX_PER_CPU_PGD
12617 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12618 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12619 +{
12620 + return cpu_pgd[cpu];
12621 +}
12622 +#endif
12623 +
12624 #include <linux/mm_types.h>
12625
12626 static inline int pte_none(pte_t pte)
12627 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12628
12629 static inline int pgd_bad(pgd_t pgd)
12630 {
12631 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12632 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12633 }
12634
12635 static inline int pgd_none(pgd_t pgd)
12636 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12637 * pgd_offset() returns a (pgd_t *)
12638 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12639 */
12640 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12641 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12642 +
12643 +#ifdef CONFIG_PAX_PER_CPU_PGD
12644 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12645 +#endif
12646 +
12647 /*
12648 * a shortcut which implies the use of the kernel's pgd, instead
12649 * of a process's
12650 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12651 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12652 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12653
12654 +#ifdef CONFIG_X86_32
12655 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12656 +#else
12657 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12658 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12659 +
12660 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12661 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12662 +#else
12663 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12664 +#endif
12665 +
12666 +#endif
12667 +
12668 #ifndef __ASSEMBLY__
12669
12670 extern int direct_gbpages;
12671 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12672 * dst and src can be on the same page, but the range must not overlap,
12673 * and must not cross a page boundary.
12674 */
12675 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12676 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12677 {
12678 - memcpy(dst, src, count * sizeof(pgd_t));
12679 + pax_open_kernel();
12680 + while (count--)
12681 + *dst++ = *src++;
12682 + pax_close_kernel();
12683 }
12684
12685 +#ifdef CONFIG_PAX_PER_CPU_PGD
12686 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12687 +#endif
12688 +
12689 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12690 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12691 +#else
12692 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12693 +#endif
12694
12695 #include <asm-generic/pgtable.h>
12696 #endif /* __ASSEMBLY__ */
12697 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12698 index 8faa215..a8a17ea 100644
12699 --- a/arch/x86/include/asm/pgtable_32.h
12700 +++ b/arch/x86/include/asm/pgtable_32.h
12701 @@ -25,9 +25,6 @@
12702 struct mm_struct;
12703 struct vm_area_struct;
12704
12705 -extern pgd_t swapper_pg_dir[1024];
12706 -extern pgd_t initial_page_table[1024];
12707 -
12708 static inline void pgtable_cache_init(void) { }
12709 static inline void check_pgt_cache(void) { }
12710 void paging_init(void);
12711 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12712 # include <asm/pgtable-2level.h>
12713 #endif
12714
12715 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12716 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12717 +#ifdef CONFIG_X86_PAE
12718 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12719 +#endif
12720 +
12721 #if defined(CONFIG_HIGHPTE)
12722 #define pte_offset_map(dir, address) \
12723 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12724 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12725 /* Clear a kernel PTE and flush it from the TLB */
12726 #define kpte_clear_flush(ptep, vaddr) \
12727 do { \
12728 + pax_open_kernel(); \
12729 pte_clear(&init_mm, (vaddr), (ptep)); \
12730 + pax_close_kernel(); \
12731 __flush_tlb_one((vaddr)); \
12732 } while (0)
12733
12734 @@ -75,6 +80,9 @@ do { \
12735
12736 #endif /* !__ASSEMBLY__ */
12737
12738 +#define HAVE_ARCH_UNMAPPED_AREA
12739 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12740 +
12741 /*
12742 * kern_addr_valid() is (1) for FLATMEM and (0) for
12743 * SPARSEMEM and DISCONTIGMEM
12744 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12745 index ed5903b..c7fe163 100644
12746 --- a/arch/x86/include/asm/pgtable_32_types.h
12747 +++ b/arch/x86/include/asm/pgtable_32_types.h
12748 @@ -8,7 +8,7 @@
12749 */
12750 #ifdef CONFIG_X86_PAE
12751 # include <asm/pgtable-3level_types.h>
12752 -# define PMD_SIZE (1UL << PMD_SHIFT)
12753 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12754 # define PMD_MASK (~(PMD_SIZE - 1))
12755 #else
12756 # include <asm/pgtable-2level_types.h>
12757 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12758 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12759 #endif
12760
12761 +#ifdef CONFIG_PAX_KERNEXEC
12762 +#ifndef __ASSEMBLY__
12763 +extern unsigned char MODULES_EXEC_VADDR[];
12764 +extern unsigned char MODULES_EXEC_END[];
12765 +#endif
12766 +#include <asm/boot.h>
12767 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12768 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12769 +#else
12770 +#define ktla_ktva(addr) (addr)
12771 +#define ktva_ktla(addr) (addr)
12772 +#endif
12773 +
12774 #define MODULES_VADDR VMALLOC_START
12775 #define MODULES_END VMALLOC_END
12776 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12777 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12778 index 47356f9..deb94a2 100644
12779 --- a/arch/x86/include/asm/pgtable_64.h
12780 +++ b/arch/x86/include/asm/pgtable_64.h
12781 @@ -16,10 +16,14 @@
12782
12783 extern pud_t level3_kernel_pgt[512];
12784 extern pud_t level3_ident_pgt[512];
12785 +extern pud_t level3_vmalloc_start_pgt[512];
12786 +extern pud_t level3_vmalloc_end_pgt[512];
12787 +extern pud_t level3_vmemmap_pgt[512];
12788 +extern pud_t level2_vmemmap_pgt[512];
12789 extern pmd_t level2_kernel_pgt[512];
12790 extern pmd_t level2_fixmap_pgt[512];
12791 -extern pmd_t level2_ident_pgt[512];
12792 -extern pgd_t init_level4_pgt[];
12793 +extern pmd_t level2_ident_pgt[512*2];
12794 +extern pgd_t init_level4_pgt[512];
12795
12796 #define swapper_pg_dir init_level4_pgt
12797
12798 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12799
12800 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12801 {
12802 + pax_open_kernel();
12803 *pmdp = pmd;
12804 + pax_close_kernel();
12805 }
12806
12807 static inline void native_pmd_clear(pmd_t *pmd)
12808 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12809
12810 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12811 {
12812 + pax_open_kernel();
12813 *pudp = pud;
12814 + pax_close_kernel();
12815 }
12816
12817 static inline void native_pud_clear(pud_t *pud)
12818 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12819
12820 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12821 {
12822 + pax_open_kernel();
12823 + *pgdp = pgd;
12824 + pax_close_kernel();
12825 +}
12826 +
12827 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12828 +{
12829 *pgdp = pgd;
12830 }
12831
12832 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12833 index 766ea16..5b96cb3 100644
12834 --- a/arch/x86/include/asm/pgtable_64_types.h
12835 +++ b/arch/x86/include/asm/pgtable_64_types.h
12836 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12837 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12838 #define MODULES_END _AC(0xffffffffff000000, UL)
12839 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12840 +#define MODULES_EXEC_VADDR MODULES_VADDR
12841 +#define MODULES_EXEC_END MODULES_END
12842 +
12843 +#define ktla_ktva(addr) (addr)
12844 +#define ktva_ktla(addr) (addr)
12845
12846 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12847 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12848 index ec8a1fc..7ccb593 100644
12849 --- a/arch/x86/include/asm/pgtable_types.h
12850 +++ b/arch/x86/include/asm/pgtable_types.h
12851 @@ -16,13 +16,12 @@
12852 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12853 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12854 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12855 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12856 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12857 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12858 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12859 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12860 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12861 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12862 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12863 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12864 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12865 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12866
12867 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12868 @@ -40,7 +39,6 @@
12869 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12870 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12871 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12872 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12873 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12874 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
12875 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
12876 @@ -57,8 +55,10 @@
12877
12878 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
12879 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
12880 -#else
12881 +#elif defined(CONFIG_KMEMCHECK)
12882 #define _PAGE_NX (_AT(pteval_t, 0))
12883 +#else
12884 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
12885 #endif
12886
12887 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
12888 @@ -96,6 +96,9 @@
12889 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
12890 _PAGE_ACCESSED)
12891
12892 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
12893 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
12894 +
12895 #define __PAGE_KERNEL_EXEC \
12896 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
12897 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
12898 @@ -106,7 +109,7 @@
12899 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
12900 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
12901 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
12902 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
12903 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
12904 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
12905 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
12906 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
12907 @@ -168,8 +171,8 @@
12908 * bits are combined, this will alow user to access the high address mapped
12909 * VDSO in the presence of CONFIG_COMPAT_VDSO
12910 */
12911 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
12912 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
12913 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12914 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12915 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
12916 #endif
12917
12918 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
12919 {
12920 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
12921 }
12922 +#endif
12923
12924 +#if PAGETABLE_LEVELS == 3
12925 +#include <asm-generic/pgtable-nopud.h>
12926 +#endif
12927 +
12928 +#if PAGETABLE_LEVELS == 2
12929 +#include <asm-generic/pgtable-nopmd.h>
12930 +#endif
12931 +
12932 +#ifndef __ASSEMBLY__
12933 #if PAGETABLE_LEVELS > 3
12934 typedef struct { pudval_t pud; } pud_t;
12935
12936 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
12937 return pud.pud;
12938 }
12939 #else
12940 -#include <asm-generic/pgtable-nopud.h>
12941 -
12942 static inline pudval_t native_pud_val(pud_t pud)
12943 {
12944 return native_pgd_val(pud.pgd);
12945 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
12946 return pmd.pmd;
12947 }
12948 #else
12949 -#include <asm-generic/pgtable-nopmd.h>
12950 -
12951 static inline pmdval_t native_pmd_val(pmd_t pmd)
12952 {
12953 return native_pgd_val(pmd.pud.pgd);
12954 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
12955
12956 extern pteval_t __supported_pte_mask;
12957 extern void set_nx(void);
12958 -extern int nx_enabled;
12959
12960 #define pgprot_writecombine pgprot_writecombine
12961 extern pgprot_t pgprot_writecombine(pgprot_t prot);
12962 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
12963 index ad1fc85..0b15fe1 100644
12964 --- a/arch/x86/include/asm/processor.h
12965 +++ b/arch/x86/include/asm/processor.h
12966 @@ -289,7 +289,7 @@ struct tss_struct {
12967
12968 } ____cacheline_aligned;
12969
12970 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
12971 +extern struct tss_struct init_tss[NR_CPUS];
12972
12973 /*
12974 * Save the original ist values for checking stack pointers during debugging
12975 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
12976 */
12977 #define TASK_SIZE PAGE_OFFSET
12978 #define TASK_SIZE_MAX TASK_SIZE
12979 +
12980 +#ifdef CONFIG_PAX_SEGMEXEC
12981 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
12982 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
12983 +#else
12984 #define STACK_TOP TASK_SIZE
12985 -#define STACK_TOP_MAX STACK_TOP
12986 +#endif
12987 +
12988 +#define STACK_TOP_MAX TASK_SIZE
12989
12990 #define INIT_THREAD { \
12991 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
12992 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12993 .vm86_info = NULL, \
12994 .sysenter_cs = __KERNEL_CS, \
12995 .io_bitmap_ptr = NULL, \
12996 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
12997 */
12998 #define INIT_TSS { \
12999 .x86_tss = { \
13000 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13001 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13002 .ss0 = __KERNEL_DS, \
13003 .ss1 = __KERNEL_CS, \
13004 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13005 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13006 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13007
13008 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13009 -#define KSTK_TOP(info) \
13010 -({ \
13011 - unsigned long *__ptr = (unsigned long *)(info); \
13012 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13013 -})
13014 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13015
13016 /*
13017 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13018 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13019 #define task_pt_regs(task) \
13020 ({ \
13021 struct pt_regs *__regs__; \
13022 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13023 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13024 __regs__ - 1; \
13025 })
13026
13027 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13028 /*
13029 * User space process size. 47bits minus one guard page.
13030 */
13031 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13032 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13033
13034 /* This decides where the kernel will search for a free chunk of vm
13035 * space during mmap's.
13036 */
13037 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13038 - 0xc0000000 : 0xFFFFe000)
13039 + 0xc0000000 : 0xFFFFf000)
13040
13041 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13042 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13043 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13044 #define STACK_TOP_MAX TASK_SIZE_MAX
13045
13046 #define INIT_THREAD { \
13047 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13048 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13049 }
13050
13051 #define INIT_TSS { \
13052 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13053 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13054 }
13055
13056 /*
13057 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13058 */
13059 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13060
13061 +#ifdef CONFIG_PAX_SEGMEXEC
13062 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13063 +#endif
13064 +
13065 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13066
13067 /* Get/set a process' ability to use the timestamp counter instruction */
13068 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13069 #define cpu_has_amd_erratum(x) (false)
13070 #endif /* CONFIG_CPU_SUP_AMD */
13071
13072 -extern unsigned long arch_align_stack(unsigned long sp);
13073 +#define arch_align_stack(x) ((x) & ~0xfUL)
13074 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13075
13076 void default_idle(void);
13077 bool set_pm_idle_to_default(void);
13078
13079 -void stop_this_cpu(void *dummy);
13080 +void stop_this_cpu(void *dummy) __noreturn;
13081
13082 #endif /* _ASM_X86_PROCESSOR_H */
13083 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13084 index 19f16eb..b50624b 100644
13085 --- a/arch/x86/include/asm/ptrace.h
13086 +++ b/arch/x86/include/asm/ptrace.h
13087 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13088 }
13089
13090 /*
13091 - * user_mode_vm(regs) determines whether a register set came from user mode.
13092 + * user_mode(regs) determines whether a register set came from user mode.
13093 * This is true if V8086 mode was enabled OR if the register set was from
13094 * protected mode with RPL-3 CS value. This tricky test checks that with
13095 * one comparison. Many places in the kernel can bypass this full check
13096 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13097 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13098 + * be used.
13099 */
13100 -static inline int user_mode(struct pt_regs *regs)
13101 +static inline int user_mode_novm(struct pt_regs *regs)
13102 {
13103 #ifdef CONFIG_X86_32
13104 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13105 #else
13106 - return !!(regs->cs & 3);
13107 + return !!(regs->cs & SEGMENT_RPL_MASK);
13108 #endif
13109 }
13110
13111 -static inline int user_mode_vm(struct pt_regs *regs)
13112 +static inline int user_mode(struct pt_regs *regs)
13113 {
13114 #ifdef CONFIG_X86_32
13115 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13116 USER_RPL;
13117 #else
13118 - return user_mode(regs);
13119 + return user_mode_novm(regs);
13120 #endif
13121 }
13122
13123 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13124 #ifdef CONFIG_X86_64
13125 static inline bool user_64bit_mode(struct pt_regs *regs)
13126 {
13127 + unsigned long cs = regs->cs & 0xffff;
13128 #ifndef CONFIG_PARAVIRT
13129 /*
13130 * On non-paravirt systems, this is the only long mode CPL 3
13131 * selector. We do not allow long mode selectors in the LDT.
13132 */
13133 - return regs->cs == __USER_CS;
13134 + return cs == __USER_CS;
13135 #else
13136 /* Headers are too twisted for this to go in paravirt.h. */
13137 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13138 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13139 #endif
13140 }
13141 #endif
13142 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13143 index fe1ec5b..dc5c3fe 100644
13144 --- a/arch/x86/include/asm/realmode.h
13145 +++ b/arch/x86/include/asm/realmode.h
13146 @@ -22,16 +22,14 @@ struct real_mode_header {
13147 #endif
13148 /* APM/BIOS reboot */
13149 u32 machine_real_restart_asm;
13150 -#ifdef CONFIG_X86_64
13151 u32 machine_real_restart_seg;
13152 -#endif
13153 };
13154
13155 /* This must match data at trampoline_32/64.S */
13156 struct trampoline_header {
13157 #ifdef CONFIG_X86_32
13158 u32 start;
13159 - u16 gdt_pad;
13160 + u16 boot_cs;
13161 u16 gdt_limit;
13162 u32 gdt_base;
13163 #else
13164 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13165 index a82c4f1..f9c9696 100644
13166 --- a/arch/x86/include/asm/reboot.h
13167 +++ b/arch/x86/include/asm/reboot.h
13168 @@ -6,12 +6,12 @@
13169 struct pt_regs;
13170
13171 struct machine_ops {
13172 - void (*restart)(char *cmd);
13173 - void (*halt)(void);
13174 - void (*power_off)(void);
13175 + void (* __noreturn restart)(char *cmd);
13176 + void (* __noreturn halt)(void);
13177 + void (* __noreturn power_off)(void);
13178 void (*shutdown)(void);
13179 void (*crash_shutdown)(struct pt_regs *);
13180 - void (*emergency_restart)(void);
13181 + void (* __noreturn emergency_restart)(void);
13182 };
13183
13184 extern struct machine_ops machine_ops;
13185 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13186 index 2dbe4a7..ce1db00 100644
13187 --- a/arch/x86/include/asm/rwsem.h
13188 +++ b/arch/x86/include/asm/rwsem.h
13189 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13190 {
13191 asm volatile("# beginning down_read\n\t"
13192 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13193 +
13194 +#ifdef CONFIG_PAX_REFCOUNT
13195 + "jno 0f\n"
13196 + LOCK_PREFIX _ASM_DEC "(%1)\n"
13197 + "int $4\n0:\n"
13198 + _ASM_EXTABLE(0b, 0b)
13199 +#endif
13200 +
13201 /* adds 0x00000001 */
13202 " jns 1f\n"
13203 " call call_rwsem_down_read_failed\n"
13204 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13205 "1:\n\t"
13206 " mov %1,%2\n\t"
13207 " add %3,%2\n\t"
13208 +
13209 +#ifdef CONFIG_PAX_REFCOUNT
13210 + "jno 0f\n"
13211 + "sub %3,%2\n"
13212 + "int $4\n0:\n"
13213 + _ASM_EXTABLE(0b, 0b)
13214 +#endif
13215 +
13216 " jle 2f\n\t"
13217 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13218 " jnz 1b\n\t"
13219 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13220 long tmp;
13221 asm volatile("# beginning down_write\n\t"
13222 LOCK_PREFIX " xadd %1,(%2)\n\t"
13223 +
13224 +#ifdef CONFIG_PAX_REFCOUNT
13225 + "jno 0f\n"
13226 + "mov %1,(%2)\n"
13227 + "int $4\n0:\n"
13228 + _ASM_EXTABLE(0b, 0b)
13229 +#endif
13230 +
13231 /* adds 0xffff0001, returns the old value */
13232 " test %1,%1\n\t"
13233 /* was the count 0 before? */
13234 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13235 long tmp;
13236 asm volatile("# beginning __up_read\n\t"
13237 LOCK_PREFIX " xadd %1,(%2)\n\t"
13238 +
13239 +#ifdef CONFIG_PAX_REFCOUNT
13240 + "jno 0f\n"
13241 + "mov %1,(%2)\n"
13242 + "int $4\n0:\n"
13243 + _ASM_EXTABLE(0b, 0b)
13244 +#endif
13245 +
13246 /* subtracts 1, returns the old value */
13247 " jns 1f\n\t"
13248 " call call_rwsem_wake\n" /* expects old value in %edx */
13249 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13250 long tmp;
13251 asm volatile("# beginning __up_write\n\t"
13252 LOCK_PREFIX " xadd %1,(%2)\n\t"
13253 +
13254 +#ifdef CONFIG_PAX_REFCOUNT
13255 + "jno 0f\n"
13256 + "mov %1,(%2)\n"
13257 + "int $4\n0:\n"
13258 + _ASM_EXTABLE(0b, 0b)
13259 +#endif
13260 +
13261 /* subtracts 0xffff0001, returns the old value */
13262 " jns 1f\n\t"
13263 " call call_rwsem_wake\n" /* expects old value in %edx */
13264 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13265 {
13266 asm volatile("# beginning __downgrade_write\n\t"
13267 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13268 +
13269 +#ifdef CONFIG_PAX_REFCOUNT
13270 + "jno 0f\n"
13271 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13272 + "int $4\n0:\n"
13273 + _ASM_EXTABLE(0b, 0b)
13274 +#endif
13275 +
13276 /*
13277 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13278 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13279 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13280 */
13281 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13282 {
13283 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13284 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13285 +
13286 +#ifdef CONFIG_PAX_REFCOUNT
13287 + "jno 0f\n"
13288 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13289 + "int $4\n0:\n"
13290 + _ASM_EXTABLE(0b, 0b)
13291 +#endif
13292 +
13293 : "+m" (sem->count)
13294 : "er" (delta));
13295 }
13296 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13297 */
13298 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13299 {
13300 - return delta + xadd(&sem->count, delta);
13301 + return delta + xadd_check_overflow(&sem->count, delta);
13302 }
13303
13304 #endif /* __KERNEL__ */
13305 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13306 index c48a950..c6d7468 100644
13307 --- a/arch/x86/include/asm/segment.h
13308 +++ b/arch/x86/include/asm/segment.h
13309 @@ -64,10 +64,15 @@
13310 * 26 - ESPFIX small SS
13311 * 27 - per-cpu [ offset to per-cpu data area ]
13312 * 28 - stack_canary-20 [ for stack protector ]
13313 - * 29 - unused
13314 - * 30 - unused
13315 + * 29 - PCI BIOS CS
13316 + * 30 - PCI BIOS DS
13317 * 31 - TSS for double fault handler
13318 */
13319 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13320 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13321 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13322 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13323 +
13324 #define GDT_ENTRY_TLS_MIN 6
13325 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13326
13327 @@ -79,6 +84,8 @@
13328
13329 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13330
13331 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13332 +
13333 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13334
13335 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13336 @@ -104,6 +111,12 @@
13337 #define __KERNEL_STACK_CANARY 0
13338 #endif
13339
13340 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13341 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13342 +
13343 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13344 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13345 +
13346 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13347
13348 /*
13349 @@ -141,7 +154,7 @@
13350 */
13351
13352 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13353 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13354 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13355
13356
13357 #else
13358 @@ -165,6 +178,8 @@
13359 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13360 #define __USER32_DS __USER_DS
13361
13362 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13363 +
13364 #define GDT_ENTRY_TSS 8 /* needs two entries */
13365 #define GDT_ENTRY_LDT 10 /* needs two entries */
13366 #define GDT_ENTRY_TLS_MIN 12
13367 @@ -185,6 +200,7 @@
13368 #endif
13369
13370 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13371 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13372 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13373 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13374 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13375 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13376 {
13377 unsigned long __limit;
13378 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13379 - return __limit + 1;
13380 + return __limit;
13381 }
13382
13383 #endif /* !__ASSEMBLY__ */
13384 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13385 index 4f19a15..e04d86f 100644
13386 --- a/arch/x86/include/asm/smp.h
13387 +++ b/arch/x86/include/asm/smp.h
13388 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13389 /* cpus sharing the last level cache: */
13390 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13391 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13392 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13393 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13394
13395 static inline struct cpumask *cpu_sibling_mask(int cpu)
13396 {
13397 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13398 extern int safe_smp_processor_id(void);
13399
13400 #elif defined(CONFIG_X86_64_SMP)
13401 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13402 -
13403 -#define stack_smp_processor_id() \
13404 -({ \
13405 - struct thread_info *ti; \
13406 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13407 - ti->cpu; \
13408 -})
13409 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13410 +#define stack_smp_processor_id() raw_smp_processor_id()
13411 #define safe_smp_processor_id() smp_processor_id()
13412
13413 #endif
13414 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13415 index 33692ea..350a534 100644
13416 --- a/arch/x86/include/asm/spinlock.h
13417 +++ b/arch/x86/include/asm/spinlock.h
13418 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13419 static inline void arch_read_lock(arch_rwlock_t *rw)
13420 {
13421 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13422 +
13423 +#ifdef CONFIG_PAX_REFCOUNT
13424 + "jno 0f\n"
13425 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13426 + "int $4\n0:\n"
13427 + _ASM_EXTABLE(0b, 0b)
13428 +#endif
13429 +
13430 "jns 1f\n"
13431 "call __read_lock_failed\n\t"
13432 "1:\n"
13433 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13434 static inline void arch_write_lock(arch_rwlock_t *rw)
13435 {
13436 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13437 +
13438 +#ifdef CONFIG_PAX_REFCOUNT
13439 + "jno 0f\n"
13440 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13441 + "int $4\n0:\n"
13442 + _ASM_EXTABLE(0b, 0b)
13443 +#endif
13444 +
13445 "jz 1f\n"
13446 "call __write_lock_failed\n\t"
13447 "1:\n"
13448 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13449
13450 static inline void arch_read_unlock(arch_rwlock_t *rw)
13451 {
13452 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13453 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13454 +
13455 +#ifdef CONFIG_PAX_REFCOUNT
13456 + "jno 0f\n"
13457 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13458 + "int $4\n0:\n"
13459 + _ASM_EXTABLE(0b, 0b)
13460 +#endif
13461 +
13462 :"+m" (rw->lock) : : "memory");
13463 }
13464
13465 static inline void arch_write_unlock(arch_rwlock_t *rw)
13466 {
13467 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13468 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13469 +
13470 +#ifdef CONFIG_PAX_REFCOUNT
13471 + "jno 0f\n"
13472 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13473 + "int $4\n0:\n"
13474 + _ASM_EXTABLE(0b, 0b)
13475 +#endif
13476 +
13477 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13478 }
13479
13480 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13481 index 6a99859..03cb807 100644
13482 --- a/arch/x86/include/asm/stackprotector.h
13483 +++ b/arch/x86/include/asm/stackprotector.h
13484 @@ -47,7 +47,7 @@
13485 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13486 */
13487 #define GDT_STACK_CANARY_INIT \
13488 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13489 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13490
13491 /*
13492 * Initialize the stackprotector canary value.
13493 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13494
13495 static inline void load_stack_canary_segment(void)
13496 {
13497 -#ifdef CONFIG_X86_32
13498 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13499 asm volatile ("mov %0, %%gs" : : "r" (0));
13500 #endif
13501 }
13502 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13503 index 70bbe39..4ae2bd4 100644
13504 --- a/arch/x86/include/asm/stacktrace.h
13505 +++ b/arch/x86/include/asm/stacktrace.h
13506 @@ -11,28 +11,20 @@
13507
13508 extern int kstack_depth_to_print;
13509
13510 -struct thread_info;
13511 +struct task_struct;
13512 struct stacktrace_ops;
13513
13514 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13515 - unsigned long *stack,
13516 - unsigned long bp,
13517 - const struct stacktrace_ops *ops,
13518 - void *data,
13519 - unsigned long *end,
13520 - int *graph);
13521 +typedef unsigned long walk_stack_t(struct task_struct *task,
13522 + void *stack_start,
13523 + unsigned long *stack,
13524 + unsigned long bp,
13525 + const struct stacktrace_ops *ops,
13526 + void *data,
13527 + unsigned long *end,
13528 + int *graph);
13529
13530 -extern unsigned long
13531 -print_context_stack(struct thread_info *tinfo,
13532 - unsigned long *stack, unsigned long bp,
13533 - const struct stacktrace_ops *ops, void *data,
13534 - unsigned long *end, int *graph);
13535 -
13536 -extern unsigned long
13537 -print_context_stack_bp(struct thread_info *tinfo,
13538 - unsigned long *stack, unsigned long bp,
13539 - const struct stacktrace_ops *ops, void *data,
13540 - unsigned long *end, int *graph);
13541 +extern walk_stack_t print_context_stack;
13542 +extern walk_stack_t print_context_stack_bp;
13543
13544 /* Generic stack tracer with callbacks */
13545
13546 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13547 void (*address)(void *data, unsigned long address, int reliable);
13548 /* On negative return stop dumping */
13549 int (*stack)(void *data, char *name);
13550 - walk_stack_t walk_stack;
13551 + walk_stack_t *walk_stack;
13552 };
13553
13554 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13555 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13556 index 4ec45b3..a4f0a8a 100644
13557 --- a/arch/x86/include/asm/switch_to.h
13558 +++ b/arch/x86/include/asm/switch_to.h
13559 @@ -108,7 +108,7 @@ do { \
13560 "call __switch_to\n\t" \
13561 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13562 __switch_canary \
13563 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13564 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13565 "movq %%rax,%%rdi\n\t" \
13566 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13567 "jnz ret_from_fork\n\t" \
13568 @@ -119,7 +119,7 @@ do { \
13569 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13570 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13571 [_tif_fork] "i" (_TIF_FORK), \
13572 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13573 + [thread_info] "m" (current_tinfo), \
13574 [current_task] "m" (current_task) \
13575 __switch_canary_iparam \
13576 : "memory", "cc" __EXTRA_CLOBBER)
13577 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13578 index 2d946e6..e453ec4 100644
13579 --- a/arch/x86/include/asm/thread_info.h
13580 +++ b/arch/x86/include/asm/thread_info.h
13581 @@ -10,6 +10,7 @@
13582 #include <linux/compiler.h>
13583 #include <asm/page.h>
13584 #include <asm/types.h>
13585 +#include <asm/percpu.h>
13586
13587 /*
13588 * low level task data that entry.S needs immediate access to
13589 @@ -24,7 +25,6 @@ struct exec_domain;
13590 #include <linux/atomic.h>
13591
13592 struct thread_info {
13593 - struct task_struct *task; /* main task structure */
13594 struct exec_domain *exec_domain; /* execution domain */
13595 __u32 flags; /* low level flags */
13596 __u32 status; /* thread synchronous flags */
13597 @@ -34,19 +34,13 @@ struct thread_info {
13598 mm_segment_t addr_limit;
13599 struct restart_block restart_block;
13600 void __user *sysenter_return;
13601 -#ifdef CONFIG_X86_32
13602 - unsigned long previous_esp; /* ESP of the previous stack in
13603 - case of nested (IRQ) stacks
13604 - */
13605 - __u8 supervisor_stack[0];
13606 -#endif
13607 + unsigned long lowest_stack;
13608 unsigned int sig_on_uaccess_error:1;
13609 unsigned int uaccess_err:1; /* uaccess failed */
13610 };
13611
13612 -#define INIT_THREAD_INFO(tsk) \
13613 +#define INIT_THREAD_INFO \
13614 { \
13615 - .task = &tsk, \
13616 .exec_domain = &default_exec_domain, \
13617 .flags = 0, \
13618 .cpu = 0, \
13619 @@ -57,7 +51,7 @@ struct thread_info {
13620 }, \
13621 }
13622
13623 -#define init_thread_info (init_thread_union.thread_info)
13624 +#define init_thread_info (init_thread_union.stack)
13625 #define init_stack (init_thread_union.stack)
13626
13627 #else /* !__ASSEMBLY__ */
13628 @@ -98,6 +92,7 @@ struct thread_info {
13629 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13630 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13631 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13632 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13633
13634 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13635 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13636 @@ -122,17 +117,18 @@ struct thread_info {
13637 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13638 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13639 #define _TIF_X32 (1 << TIF_X32)
13640 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13641
13642 /* work to do in syscall_trace_enter() */
13643 #define _TIF_WORK_SYSCALL_ENTRY \
13644 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13645 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13646 - _TIF_NOHZ)
13647 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13648
13649 /* work to do in syscall_trace_leave() */
13650 #define _TIF_WORK_SYSCALL_EXIT \
13651 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13652 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13653 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13654
13655 /* work to do on interrupt/exception return */
13656 #define _TIF_WORK_MASK \
13657 @@ -143,7 +139,7 @@ struct thread_info {
13658 /* work to do on any return to user space */
13659 #define _TIF_ALLWORK_MASK \
13660 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13661 - _TIF_NOHZ)
13662 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13663
13664 /* Only used for 64 bit */
13665 #define _TIF_DO_NOTIFY_MASK \
13666 @@ -159,45 +155,40 @@ struct thread_info {
13667
13668 #define PREEMPT_ACTIVE 0x10000000
13669
13670 -#ifdef CONFIG_X86_32
13671 -
13672 -#define STACK_WARN (THREAD_SIZE/8)
13673 -/*
13674 - * macros/functions for gaining access to the thread information structure
13675 - *
13676 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13677 - */
13678 -#ifndef __ASSEMBLY__
13679 -
13680 -
13681 -/* how to get the current stack pointer from C */
13682 -register unsigned long current_stack_pointer asm("esp") __used;
13683 -
13684 -/* how to get the thread information struct from C */
13685 -static inline struct thread_info *current_thread_info(void)
13686 -{
13687 - return (struct thread_info *)
13688 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13689 -}
13690 -
13691 -#else /* !__ASSEMBLY__ */
13692 -
13693 +#ifdef __ASSEMBLY__
13694 /* how to get the thread information struct from ASM */
13695 #define GET_THREAD_INFO(reg) \
13696 - movl $-THREAD_SIZE, reg; \
13697 - andl %esp, reg
13698 + mov PER_CPU_VAR(current_tinfo), reg
13699
13700 /* use this one if reg already contains %esp */
13701 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13702 - andl $-THREAD_SIZE, reg
13703 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13704 +#else
13705 +/* how to get the thread information struct from C */
13706 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13707 +
13708 +static __always_inline struct thread_info *current_thread_info(void)
13709 +{
13710 + return this_cpu_read_stable(current_tinfo);
13711 +}
13712 +#endif
13713 +
13714 +#ifdef CONFIG_X86_32
13715 +
13716 +#define STACK_WARN (THREAD_SIZE/8)
13717 +/*
13718 + * macros/functions for gaining access to the thread information structure
13719 + *
13720 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13721 + */
13722 +#ifndef __ASSEMBLY__
13723 +
13724 +/* how to get the current stack pointer from C */
13725 +register unsigned long current_stack_pointer asm("esp") __used;
13726
13727 #endif
13728
13729 #else /* X86_32 */
13730
13731 -#include <asm/percpu.h>
13732 -#define KERNEL_STACK_OFFSET (5*8)
13733 -
13734 /*
13735 * macros/functions for gaining access to the thread information structure
13736 * preempt_count needs to be 1 initially, until the scheduler is functional.
13737 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13738 #ifndef __ASSEMBLY__
13739 DECLARE_PER_CPU(unsigned long, kernel_stack);
13740
13741 -static inline struct thread_info *current_thread_info(void)
13742 -{
13743 - struct thread_info *ti;
13744 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13745 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13746 - return ti;
13747 -}
13748 -
13749 -#else /* !__ASSEMBLY__ */
13750 -
13751 -/* how to get the thread information struct from ASM */
13752 -#define GET_THREAD_INFO(reg) \
13753 - movq PER_CPU_VAR(kernel_stack),reg ; \
13754 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13755 -
13756 -/*
13757 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13758 - * a certain register (to be used in assembler memory operands).
13759 - */
13760 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13761 -
13762 +/* how to get the current stack pointer from C */
13763 +register unsigned long current_stack_pointer asm("rsp") __used;
13764 #endif
13765
13766 #endif /* !X86_32 */
13767 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13768 extern void arch_task_cache_init(void);
13769 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13770 extern void arch_release_task_struct(struct task_struct *tsk);
13771 +
13772 +#define __HAVE_THREAD_FUNCTIONS
13773 +#define task_thread_info(task) (&(task)->tinfo)
13774 +#define task_stack_page(task) ((task)->stack)
13775 +#define setup_thread_stack(p, org) do {} while (0)
13776 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13777 +
13778 #endif
13779 #endif /* _ASM_X86_THREAD_INFO_H */
13780 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13781 index 7ccf8d1..7cdca12 100644
13782 --- a/arch/x86/include/asm/uaccess.h
13783 +++ b/arch/x86/include/asm/uaccess.h
13784 @@ -7,6 +7,7 @@
13785 #include <linux/compiler.h>
13786 #include <linux/thread_info.h>
13787 #include <linux/string.h>
13788 +#include <linux/sched.h>
13789 #include <asm/asm.h>
13790 #include <asm/page.h>
13791 #include <asm/smap.h>
13792 @@ -14,6 +15,8 @@
13793 #define VERIFY_READ 0
13794 #define VERIFY_WRITE 1
13795
13796 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
13797 +
13798 /*
13799 * The fs value determines whether argument validity checking should be
13800 * performed or not. If get_fs() == USER_DS, checking is performed, with
13801 @@ -29,7 +32,12 @@
13802
13803 #define get_ds() (KERNEL_DS)
13804 #define get_fs() (current_thread_info()->addr_limit)
13805 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13806 +void __set_fs(mm_segment_t x);
13807 +void set_fs(mm_segment_t x);
13808 +#else
13809 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13810 +#endif
13811
13812 #define segment_eq(a, b) ((a).seg == (b).seg)
13813
13814 @@ -77,8 +85,33 @@
13815 * checks that the pointer is in the user space range - after calling
13816 * this function, memory access functions may still return -EFAULT.
13817 */
13818 -#define access_ok(type, addr, size) \
13819 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13820 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13821 +#define access_ok(type, addr, size) \
13822 +({ \
13823 + long __size = size; \
13824 + unsigned long __addr = (unsigned long)addr; \
13825 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13826 + unsigned long __end_ao = __addr + __size - 1; \
13827 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13828 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13829 + while(__addr_ao <= __end_ao) { \
13830 + char __c_ao; \
13831 + __addr_ao += PAGE_SIZE; \
13832 + if (__size > PAGE_SIZE) \
13833 + cond_resched(); \
13834 + if (__get_user(__c_ao, (char __user *)__addr)) \
13835 + break; \
13836 + if (type != VERIFY_WRITE) { \
13837 + __addr = __addr_ao; \
13838 + continue; \
13839 + } \
13840 + if (__put_user(__c_ao, (char __user *)__addr)) \
13841 + break; \
13842 + __addr = __addr_ao; \
13843 + } \
13844 + } \
13845 + __ret_ao; \
13846 +})
13847
13848 /*
13849 * The exception table consists of pairs of addresses relative to the
13850 @@ -189,13 +222,21 @@ extern int __get_user_bad(void);
13851 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13852 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13853
13854 -
13855 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13856 +#define __copyuser_seg "gs;"
13857 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13858 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13859 +#else
13860 +#define __copyuser_seg
13861 +#define __COPYUSER_SET_ES
13862 +#define __COPYUSER_RESTORE_ES
13863 +#endif
13864
13865 #ifdef CONFIG_X86_32
13866 #define __put_user_asm_u64(x, addr, err, errret) \
13867 asm volatile(ASM_STAC "\n" \
13868 - "1: movl %%eax,0(%2)\n" \
13869 - "2: movl %%edx,4(%2)\n" \
13870 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13871 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13872 "3: " ASM_CLAC "\n" \
13873 ".section .fixup,\"ax\"\n" \
13874 "4: movl %3,%0\n" \
13875 @@ -208,8 +249,8 @@ extern int __get_user_bad(void);
13876
13877 #define __put_user_asm_ex_u64(x, addr) \
13878 asm volatile(ASM_STAC "\n" \
13879 - "1: movl %%eax,0(%1)\n" \
13880 - "2: movl %%edx,4(%1)\n" \
13881 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13882 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13883 "3: " ASM_CLAC "\n" \
13884 _ASM_EXTABLE_EX(1b, 2b) \
13885 _ASM_EXTABLE_EX(2b, 3b) \
13886 @@ -261,7 +302,7 @@ extern void __put_user_8(void);
13887 __typeof__(*(ptr)) __pu_val; \
13888 __chk_user_ptr(ptr); \
13889 might_fault(); \
13890 - __pu_val = x; \
13891 + __pu_val = (x); \
13892 switch (sizeof(*(ptr))) { \
13893 case 1: \
13894 __put_user_x(1, __pu_val, ptr, __ret_pu); \
13895 @@ -383,7 +424,7 @@ do { \
13896
13897 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13898 asm volatile(ASM_STAC "\n" \
13899 - "1: mov"itype" %2,%"rtype"1\n" \
13900 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
13901 "2: " ASM_CLAC "\n" \
13902 ".section .fixup,\"ax\"\n" \
13903 "3: mov %3,%0\n" \
13904 @@ -391,7 +432,7 @@ do { \
13905 " jmp 2b\n" \
13906 ".previous\n" \
13907 _ASM_EXTABLE(1b, 3b) \
13908 - : "=r" (err), ltype(x) \
13909 + : "=r" (err), ltype (x) \
13910 : "m" (__m(addr)), "i" (errret), "0" (err))
13911
13912 #define __get_user_size_ex(x, ptr, size) \
13913 @@ -416,7 +457,7 @@ do { \
13914 } while (0)
13915
13916 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
13917 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
13918 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
13919 "2:\n" \
13920 _ASM_EXTABLE_EX(1b, 2b) \
13921 : ltype(x) : "m" (__m(addr)))
13922 @@ -433,13 +474,24 @@ do { \
13923 int __gu_err; \
13924 unsigned long __gu_val; \
13925 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
13926 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
13927 + (x) = (__typeof__(*(ptr)))__gu_val; \
13928 __gu_err; \
13929 })
13930
13931 /* FIXME: this hack is definitely wrong -AK */
13932 struct __large_struct { unsigned long buf[100]; };
13933 -#define __m(x) (*(struct __large_struct __user *)(x))
13934 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13935 +#define ____m(x) \
13936 +({ \
13937 + unsigned long ____x = (unsigned long)(x); \
13938 + if (____x < PAX_USER_SHADOW_BASE) \
13939 + ____x += PAX_USER_SHADOW_BASE; \
13940 + (void __user *)____x; \
13941 +})
13942 +#else
13943 +#define ____m(x) (x)
13944 +#endif
13945 +#define __m(x) (*(struct __large_struct __user *)____m(x))
13946
13947 /*
13948 * Tell gcc we read from memory instead of writing: this is because
13949 @@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
13950 */
13951 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13952 asm volatile(ASM_STAC "\n" \
13953 - "1: mov"itype" %"rtype"1,%2\n" \
13954 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
13955 "2: " ASM_CLAC "\n" \
13956 ".section .fixup,\"ax\"\n" \
13957 "3: mov %3,%0\n" \
13958 @@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
13959 ".previous\n" \
13960 _ASM_EXTABLE(1b, 3b) \
13961 : "=r"(err) \
13962 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
13963 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
13964
13965 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
13966 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
13967 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
13968 "2:\n" \
13969 _ASM_EXTABLE_EX(1b, 2b) \
13970 : : ltype(x), "m" (__m(addr)))
13971 @@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
13972 * On error, the variable @x is set to zero.
13973 */
13974
13975 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13976 +#define __get_user(x, ptr) get_user((x), (ptr))
13977 +#else
13978 #define __get_user(x, ptr) \
13979 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
13980 +#endif
13981
13982 /**
13983 * __put_user: - Write a simple value into user space, with less checking.
13984 @@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
13985 * Returns zero on success, or -EFAULT on error.
13986 */
13987
13988 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13989 +#define __put_user(x, ptr) put_user((x), (ptr))
13990 +#else
13991 #define __put_user(x, ptr) \
13992 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
13993 +#endif
13994
13995 #define __get_user_unaligned __get_user
13996 #define __put_user_unaligned __put_user
13997 @@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
13998 #define get_user_ex(x, ptr) do { \
13999 unsigned long __gue_val; \
14000 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14001 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
14002 + (x) = (__typeof__(*(ptr)))__gue_val; \
14003 } while (0)
14004
14005 #ifdef CONFIG_X86_WP_WORKS_OK
14006 @@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14007 extern __must_check long strlen_user(const char __user *str);
14008 extern __must_check long strnlen_user(const char __user *str, long n);
14009
14010 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14011 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14012 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14013 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14014
14015 /*
14016 * movsl can be slow when source and dest are not both 8-byte aligned
14017 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14018 index 7f760a9..00f93c0 100644
14019 --- a/arch/x86/include/asm/uaccess_32.h
14020 +++ b/arch/x86/include/asm/uaccess_32.h
14021 @@ -11,15 +11,15 @@
14022 #include <asm/page.h>
14023
14024 unsigned long __must_check __copy_to_user_ll
14025 - (void __user *to, const void *from, unsigned long n);
14026 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14027 unsigned long __must_check __copy_from_user_ll
14028 - (void *to, const void __user *from, unsigned long n);
14029 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14030 unsigned long __must_check __copy_from_user_ll_nozero
14031 - (void *to, const void __user *from, unsigned long n);
14032 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14033 unsigned long __must_check __copy_from_user_ll_nocache
14034 - (void *to, const void __user *from, unsigned long n);
14035 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14036 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14037 - (void *to, const void __user *from, unsigned long n);
14038 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14039
14040 /**
14041 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14042 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14043 static __always_inline unsigned long __must_check
14044 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14045 {
14046 + if ((long)n < 0)
14047 + return n;
14048 +
14049 if (__builtin_constant_p(n)) {
14050 unsigned long ret;
14051
14052 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14053 return ret;
14054 }
14055 }
14056 + if (!__builtin_constant_p(n))
14057 + check_object_size(from, n, true);
14058 return __copy_to_user_ll(to, from, n);
14059 }
14060
14061 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14062 __copy_to_user(void __user *to, const void *from, unsigned long n)
14063 {
14064 might_fault();
14065 +
14066 return __copy_to_user_inatomic(to, from, n);
14067 }
14068
14069 static __always_inline unsigned long
14070 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14071 {
14072 + if ((long)n < 0)
14073 + return n;
14074 +
14075 /* Avoid zeroing the tail if the copy fails..
14076 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14077 * but as the zeroing behaviour is only significant when n is not
14078 @@ -137,6 +146,10 @@ static __always_inline unsigned long
14079 __copy_from_user(void *to, const void __user *from, unsigned long n)
14080 {
14081 might_fault();
14082 +
14083 + if ((long)n < 0)
14084 + return n;
14085 +
14086 if (__builtin_constant_p(n)) {
14087 unsigned long ret;
14088
14089 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
14090 return ret;
14091 }
14092 }
14093 + if (!__builtin_constant_p(n))
14094 + check_object_size(to, n, false);
14095 return __copy_from_user_ll(to, from, n);
14096 }
14097
14098 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14099 const void __user *from, unsigned long n)
14100 {
14101 might_fault();
14102 +
14103 + if ((long)n < 0)
14104 + return n;
14105 +
14106 if (__builtin_constant_p(n)) {
14107 unsigned long ret;
14108
14109 @@ -181,15 +200,19 @@ static __always_inline unsigned long
14110 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14111 unsigned long n)
14112 {
14113 - return __copy_from_user_ll_nocache_nozero(to, from, n);
14114 + if ((long)n < 0)
14115 + return n;
14116 +
14117 + return __copy_from_user_ll_nocache_nozero(to, from, n);
14118 }
14119
14120 -unsigned long __must_check copy_to_user(void __user *to,
14121 - const void *from, unsigned long n);
14122 -unsigned long __must_check _copy_from_user(void *to,
14123 - const void __user *from,
14124 - unsigned long n);
14125 -
14126 +extern void copy_to_user_overflow(void)
14127 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14128 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14129 +#else
14130 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14131 +#endif
14132 +;
14133
14134 extern void copy_from_user_overflow(void)
14135 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14136 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
14137 #endif
14138 ;
14139
14140 -static inline unsigned long __must_check copy_from_user(void *to,
14141 - const void __user *from,
14142 - unsigned long n)
14143 +/**
14144 + * copy_to_user: - Copy a block of data into user space.
14145 + * @to: Destination address, in user space.
14146 + * @from: Source address, in kernel space.
14147 + * @n: Number of bytes to copy.
14148 + *
14149 + * Context: User context only. This function may sleep.
14150 + *
14151 + * Copy data from kernel space to user space.
14152 + *
14153 + * Returns number of bytes that could not be copied.
14154 + * On success, this will be zero.
14155 + */
14156 +static inline unsigned long __must_check
14157 +copy_to_user(void __user *to, const void *from, unsigned long n)
14158 {
14159 - int sz = __compiletime_object_size(to);
14160 + size_t sz = __compiletime_object_size(from);
14161
14162 - if (likely(sz == -1 || sz >= n))
14163 - n = _copy_from_user(to, from, n);
14164 - else
14165 + if (unlikely(sz != (size_t)-1 && sz < n))
14166 + copy_to_user_overflow();
14167 + else if (access_ok(VERIFY_WRITE, to, n))
14168 + n = __copy_to_user(to, from, n);
14169 + return n;
14170 +}
14171 +
14172 +/**
14173 + * copy_from_user: - Copy a block of data from user space.
14174 + * @to: Destination address, in kernel space.
14175 + * @from: Source address, in user space.
14176 + * @n: Number of bytes to copy.
14177 + *
14178 + * Context: User context only. This function may sleep.
14179 + *
14180 + * Copy data from user space to kernel space.
14181 + *
14182 + * Returns number of bytes that could not be copied.
14183 + * On success, this will be zero.
14184 + *
14185 + * If some data could not be copied, this function will pad the copied
14186 + * data to the requested size using zero bytes.
14187 + */
14188 +static inline unsigned long __must_check
14189 +copy_from_user(void *to, const void __user *from, unsigned long n)
14190 +{
14191 + size_t sz = __compiletime_object_size(to);
14192 +
14193 + if (unlikely(sz != (size_t)-1 && sz < n))
14194 copy_from_user_overflow();
14195 -
14196 + else if (access_ok(VERIFY_READ, from, n))
14197 + n = __copy_from_user(to, from, n);
14198 + else if ((long)n > 0) {
14199 + if (!__builtin_constant_p(n))
14200 + check_object_size(to, n, false);
14201 + memset(to, 0, n);
14202 + }
14203 return n;
14204 }
14205
14206 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14207 index 142810c..4389299 100644
14208 --- a/arch/x86/include/asm/uaccess_64.h
14209 +++ b/arch/x86/include/asm/uaccess_64.h
14210 @@ -10,6 +10,9 @@
14211 #include <asm/alternative.h>
14212 #include <asm/cpufeature.h>
14213 #include <asm/page.h>
14214 +#include <asm/pgtable.h>
14215 +
14216 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
14217
14218 /*
14219 * Copy To/From Userspace
14220 @@ -17,13 +20,13 @@
14221
14222 /* Handles exceptions in both to and from, but doesn't do access_ok */
14223 __must_check unsigned long
14224 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14225 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14226 __must_check unsigned long
14227 -copy_user_generic_string(void *to, const void *from, unsigned len);
14228 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14229 __must_check unsigned long
14230 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14231 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14232
14233 -static __always_inline __must_check unsigned long
14234 +static __always_inline __must_check __size_overflow(3) unsigned long
14235 copy_user_generic(void *to, const void *from, unsigned len)
14236 {
14237 unsigned ret;
14238 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
14239 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14240 "=d" (len)),
14241 "1" (to), "2" (from), "3" (len)
14242 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14243 + : "memory", "rcx", "r8", "r9", "r11");
14244 return ret;
14245 }
14246
14247 +static __always_inline __must_check unsigned long
14248 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14249 +static __always_inline __must_check unsigned long
14250 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14251 __must_check unsigned long
14252 -_copy_to_user(void __user *to, const void *from, unsigned len);
14253 -__must_check unsigned long
14254 -_copy_from_user(void *to, const void __user *from, unsigned len);
14255 -__must_check unsigned long
14256 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14257 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14258 +
14259 +extern void copy_to_user_overflow(void)
14260 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14261 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14262 +#else
14263 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14264 +#endif
14265 +;
14266 +
14267 +extern void copy_from_user_overflow(void)
14268 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14269 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14270 +#else
14271 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14272 +#endif
14273 +;
14274
14275 static inline unsigned long __must_check copy_from_user(void *to,
14276 const void __user *from,
14277 unsigned long n)
14278 {
14279 - int sz = __compiletime_object_size(to);
14280 -
14281 might_fault();
14282 - if (likely(sz == -1 || sz >= n))
14283 - n = _copy_from_user(to, from, n);
14284 -#ifdef CONFIG_DEBUG_VM
14285 - else
14286 - WARN(1, "Buffer overflow detected!\n");
14287 -#endif
14288 +
14289 + if (access_ok(VERIFY_READ, from, n))
14290 + n = __copy_from_user(to, from, n);
14291 + else if (n < INT_MAX) {
14292 + if (!__builtin_constant_p(n))
14293 + check_object_size(to, n, false);
14294 + memset(to, 0, n);
14295 + }
14296 return n;
14297 }
14298
14299 static __always_inline __must_check
14300 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14301 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14302 {
14303 might_fault();
14304
14305 - return _copy_to_user(dst, src, size);
14306 + if (access_ok(VERIFY_WRITE, dst, size))
14307 + size = __copy_to_user(dst, src, size);
14308 + return size;
14309 }
14310
14311 static __always_inline __must_check
14312 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14313 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14314 {
14315 - int ret = 0;
14316 + size_t sz = __compiletime_object_size(dst);
14317 + unsigned ret = 0;
14318
14319 might_fault();
14320 - if (!__builtin_constant_p(size))
14321 - return copy_user_generic(dst, (__force void *)src, size);
14322 +
14323 + if (size > INT_MAX)
14324 + return size;
14325 +
14326 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14327 + if (!__access_ok(VERIFY_READ, src, size))
14328 + return size;
14329 +#endif
14330 +
14331 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14332 + copy_from_user_overflow();
14333 + return size;
14334 + }
14335 +
14336 + if (!__builtin_constant_p(size)) {
14337 + check_object_size(dst, size, false);
14338 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14339 + }
14340 switch (size) {
14341 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14342 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14343 ret, "b", "b", "=q", 1);
14344 return ret;
14345 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14346 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14347 ret, "w", "w", "=r", 2);
14348 return ret;
14349 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14350 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14351 ret, "l", "k", "=r", 4);
14352 return ret;
14353 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14354 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14355 ret, "q", "", "=r", 8);
14356 return ret;
14357 case 10:
14358 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14359 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14360 ret, "q", "", "=r", 10);
14361 if (unlikely(ret))
14362 return ret;
14363 __get_user_asm(*(u16 *)(8 + (char *)dst),
14364 - (u16 __user *)(8 + (char __user *)src),
14365 + (const u16 __user *)(8 + (const char __user *)src),
14366 ret, "w", "w", "=r", 2);
14367 return ret;
14368 case 16:
14369 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14370 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14371 ret, "q", "", "=r", 16);
14372 if (unlikely(ret))
14373 return ret;
14374 __get_user_asm(*(u64 *)(8 + (char *)dst),
14375 - (u64 __user *)(8 + (char __user *)src),
14376 + (const u64 __user *)(8 + (const char __user *)src),
14377 ret, "q", "", "=r", 8);
14378 return ret;
14379 default:
14380 - return copy_user_generic(dst, (__force void *)src, size);
14381 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14382 }
14383 }
14384
14385 static __always_inline __must_check
14386 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14387 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14388 {
14389 - int ret = 0;
14390 + size_t sz = __compiletime_object_size(src);
14391 + unsigned ret = 0;
14392
14393 might_fault();
14394 - if (!__builtin_constant_p(size))
14395 - return copy_user_generic((__force void *)dst, src, size);
14396 +
14397 + if (size > INT_MAX)
14398 + return size;
14399 +
14400 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14401 + if (!__access_ok(VERIFY_WRITE, dst, size))
14402 + return size;
14403 +#endif
14404 +
14405 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14406 + copy_to_user_overflow();
14407 + return size;
14408 + }
14409 +
14410 + if (!__builtin_constant_p(size)) {
14411 + check_object_size(src, size, true);
14412 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14413 + }
14414 switch (size) {
14415 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14416 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14417 ret, "b", "b", "iq", 1);
14418 return ret;
14419 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14420 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14421 ret, "w", "w", "ir", 2);
14422 return ret;
14423 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14424 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14425 ret, "l", "k", "ir", 4);
14426 return ret;
14427 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14428 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14429 ret, "q", "", "er", 8);
14430 return ret;
14431 case 10:
14432 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14433 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14434 ret, "q", "", "er", 10);
14435 if (unlikely(ret))
14436 return ret;
14437 asm("":::"memory");
14438 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14439 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14440 ret, "w", "w", "ir", 2);
14441 return ret;
14442 case 16:
14443 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14444 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14445 ret, "q", "", "er", 16);
14446 if (unlikely(ret))
14447 return ret;
14448 asm("":::"memory");
14449 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14450 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14451 ret, "q", "", "er", 8);
14452 return ret;
14453 default:
14454 - return copy_user_generic((__force void *)dst, src, size);
14455 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14456 }
14457 }
14458
14459 static __always_inline __must_check
14460 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14461 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14462 {
14463 - int ret = 0;
14464 + unsigned ret = 0;
14465
14466 might_fault();
14467 +
14468 + if (size > INT_MAX)
14469 + return size;
14470 +
14471 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14472 + if (!__access_ok(VERIFY_READ, src, size))
14473 + return size;
14474 + if (!__access_ok(VERIFY_WRITE, dst, size))
14475 + return size;
14476 +#endif
14477 +
14478 if (!__builtin_constant_p(size))
14479 - return copy_user_generic((__force void *)dst,
14480 - (__force void *)src, size);
14481 + return copy_user_generic((__force_kernel void *)____m(dst),
14482 + (__force_kernel const void *)____m(src), size);
14483 switch (size) {
14484 case 1: {
14485 u8 tmp;
14486 - __get_user_asm(tmp, (u8 __user *)src,
14487 + __get_user_asm(tmp, (const u8 __user *)src,
14488 ret, "b", "b", "=q", 1);
14489 if (likely(!ret))
14490 __put_user_asm(tmp, (u8 __user *)dst,
14491 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14492 }
14493 case 2: {
14494 u16 tmp;
14495 - __get_user_asm(tmp, (u16 __user *)src,
14496 + __get_user_asm(tmp, (const u16 __user *)src,
14497 ret, "w", "w", "=r", 2);
14498 if (likely(!ret))
14499 __put_user_asm(tmp, (u16 __user *)dst,
14500 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14501
14502 case 4: {
14503 u32 tmp;
14504 - __get_user_asm(tmp, (u32 __user *)src,
14505 + __get_user_asm(tmp, (const u32 __user *)src,
14506 ret, "l", "k", "=r", 4);
14507 if (likely(!ret))
14508 __put_user_asm(tmp, (u32 __user *)dst,
14509 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14510 }
14511 case 8: {
14512 u64 tmp;
14513 - __get_user_asm(tmp, (u64 __user *)src,
14514 + __get_user_asm(tmp, (const u64 __user *)src,
14515 ret, "q", "", "=r", 8);
14516 if (likely(!ret))
14517 __put_user_asm(tmp, (u64 __user *)dst,
14518 @@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14519 return ret;
14520 }
14521 default:
14522 - return copy_user_generic((__force void *)dst,
14523 - (__force void *)src, size);
14524 + return copy_user_generic((__force_kernel void *)____m(dst),
14525 + (__force_kernel const void *)____m(src), size);
14526 }
14527 }
14528
14529 static __must_check __always_inline int
14530 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14531 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14532 {
14533 - return copy_user_generic(dst, (__force const void *)src, size);
14534 + if (size > INT_MAX)
14535 + return size;
14536 +
14537 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14538 + if (!__access_ok(VERIFY_READ, src, size))
14539 + return size;
14540 +#endif
14541 +
14542 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14543 }
14544
14545 -static __must_check __always_inline int
14546 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14547 +static __must_check __always_inline unsigned long
14548 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14549 {
14550 - return copy_user_generic((__force void *)dst, src, size);
14551 + if (size > INT_MAX)
14552 + return size;
14553 +
14554 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14555 + if (!__access_ok(VERIFY_WRITE, dst, size))
14556 + return size;
14557 +#endif
14558 +
14559 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14560 }
14561
14562 -extern long __copy_user_nocache(void *dst, const void __user *src,
14563 - unsigned size, int zerorest);
14564 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14565 + unsigned long size, int zerorest) __size_overflow(3);
14566
14567 -static inline int
14568 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14569 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14570 {
14571 might_sleep();
14572 +
14573 + if (size > INT_MAX)
14574 + return size;
14575 +
14576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14577 + if (!__access_ok(VERIFY_READ, src, size))
14578 + return size;
14579 +#endif
14580 +
14581 return __copy_user_nocache(dst, src, size, 1);
14582 }
14583
14584 -static inline int
14585 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14586 - unsigned size)
14587 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14588 + unsigned long size)
14589 {
14590 + if (size > INT_MAX)
14591 + return size;
14592 +
14593 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14594 + if (!__access_ok(VERIFY_READ, src, size))
14595 + return size;
14596 +#endif
14597 +
14598 return __copy_user_nocache(dst, src, size, 0);
14599 }
14600
14601 -unsigned long
14602 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14603 +extern unsigned long
14604 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14605
14606 #endif /* _ASM_X86_UACCESS_64_H */
14607 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14608 index 5b238981..77fdd78 100644
14609 --- a/arch/x86/include/asm/word-at-a-time.h
14610 +++ b/arch/x86/include/asm/word-at-a-time.h
14611 @@ -11,7 +11,7 @@
14612 * and shift, for example.
14613 */
14614 struct word_at_a_time {
14615 - const unsigned long one_bits, high_bits;
14616 + unsigned long one_bits, high_bits;
14617 };
14618
14619 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14620 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14621 index 0415cda..b43d877 100644
14622 --- a/arch/x86/include/asm/xsave.h
14623 +++ b/arch/x86/include/asm/xsave.h
14624 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14625 return -EFAULT;
14626
14627 __asm__ __volatile__(ASM_STAC "\n"
14628 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14629 + "1:"
14630 + __copyuser_seg
14631 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14632 "2: " ASM_CLAC "\n"
14633 ".section .fixup,\"ax\"\n"
14634 "3: movl $-1,%[err]\n"
14635 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14636 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14637 {
14638 int err;
14639 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14640 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14641 u32 lmask = mask;
14642 u32 hmask = mask >> 32;
14643
14644 __asm__ __volatile__(ASM_STAC "\n"
14645 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14646 + "1:"
14647 + __copyuser_seg
14648 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14649 "2: " ASM_CLAC "\n"
14650 ".section .fixup,\"ax\"\n"
14651 "3: movl $-1,%[err]\n"
14652 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14653 index 91ce48f..a48ea05 100644
14654 --- a/arch/x86/kernel/Makefile
14655 +++ b/arch/x86/kernel/Makefile
14656 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14657 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14658 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14659 obj-y += probe_roms.o
14660 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14661 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14662 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14663 obj-y += syscall_$(BITS).o
14664 obj-$(CONFIG_X86_64) += vsyscall_64.o
14665 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14666 index e651f7a..c995dc4 100644
14667 --- a/arch/x86/kernel/acpi/boot.c
14668 +++ b/arch/x86/kernel/acpi/boot.c
14669 @@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14670 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14671
14672 if (!acpi_noirq)
14673 - x86_init.pci.init = pci_acpi_init;
14674 + *(void **)&x86_init.pci.init = pci_acpi_init;
14675
14676 return 0;
14677 }
14678 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14679 index 11676cf..a8cf3ec 100644
14680 --- a/arch/x86/kernel/acpi/sleep.c
14681 +++ b/arch/x86/kernel/acpi/sleep.c
14682 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14683 #else /* CONFIG_64BIT */
14684 #ifdef CONFIG_SMP
14685 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14686 +
14687 + pax_open_kernel();
14688 early_gdt_descr.address =
14689 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14690 + pax_close_kernel();
14691 +
14692 initial_gs = per_cpu_offset(smp_processor_id());
14693 #endif
14694 initial_code = (unsigned long)wakeup_long64;
14695 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14696 index 13ab720..95d5442 100644
14697 --- a/arch/x86/kernel/acpi/wakeup_32.S
14698 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14699 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14700 # and restore the stack ... but you need gdt for this to work
14701 movl saved_context_esp, %esp
14702
14703 - movl %cs:saved_magic, %eax
14704 - cmpl $0x12345678, %eax
14705 + cmpl $0x12345678, saved_magic
14706 jne bogus_magic
14707
14708 # jump to place where we left off
14709 - movl saved_eip, %eax
14710 - jmp *%eax
14711 + jmp *(saved_eip)
14712
14713 bogus_magic:
14714 jmp bogus_magic
14715 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14716 index ef5ccca..bd83949 100644
14717 --- a/arch/x86/kernel/alternative.c
14718 +++ b/arch/x86/kernel/alternative.c
14719 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14720 */
14721 for (a = start; a < end; a++) {
14722 instr = (u8 *)&a->instr_offset + a->instr_offset;
14723 +
14724 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14725 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14726 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14727 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14728 +#endif
14729 +
14730 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14731 BUG_ON(a->replacementlen > a->instrlen);
14732 BUG_ON(a->instrlen > sizeof(insnbuf));
14733 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14734 for (poff = start; poff < end; poff++) {
14735 u8 *ptr = (u8 *)poff + *poff;
14736
14737 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14738 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14739 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14740 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14741 +#endif
14742 +
14743 if (!*poff || ptr < text || ptr >= text_end)
14744 continue;
14745 /* turn DS segment override prefix into lock prefix */
14746 - if (*ptr == 0x3e)
14747 + if (*ktla_ktva(ptr) == 0x3e)
14748 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14749 }
14750 mutex_unlock(&text_mutex);
14751 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14752 for (poff = start; poff < end; poff++) {
14753 u8 *ptr = (u8 *)poff + *poff;
14754
14755 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14756 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14757 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14758 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14759 +#endif
14760 +
14761 if (!*poff || ptr < text || ptr >= text_end)
14762 continue;
14763 /* turn lock prefix into DS segment override prefix */
14764 - if (*ptr == 0xf0)
14765 + if (*ktla_ktva(ptr) == 0xf0)
14766 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14767 }
14768 mutex_unlock(&text_mutex);
14769 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14770
14771 BUG_ON(p->len > MAX_PATCH_LEN);
14772 /* prep the buffer with the original instructions */
14773 - memcpy(insnbuf, p->instr, p->len);
14774 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14775 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14776 (unsigned long)p->instr, p->len);
14777
14778 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14779 if (!uniproc_patched || num_possible_cpus() == 1)
14780 free_init_pages("SMP alternatives",
14781 (unsigned long)__smp_locks,
14782 - (unsigned long)__smp_locks_end);
14783 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14784 #endif
14785
14786 apply_paravirt(__parainstructions, __parainstructions_end);
14787 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14788 * instructions. And on the local CPU you need to be protected again NMI or MCE
14789 * handlers seeing an inconsistent instruction while you patch.
14790 */
14791 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14792 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14793 size_t len)
14794 {
14795 unsigned long flags;
14796 local_irq_save(flags);
14797 - memcpy(addr, opcode, len);
14798 +
14799 + pax_open_kernel();
14800 + memcpy(ktla_ktva(addr), opcode, len);
14801 sync_core();
14802 + pax_close_kernel();
14803 +
14804 local_irq_restore(flags);
14805 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14806 that causes hangs on some VIA CPUs. */
14807 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14808 */
14809 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14810 {
14811 - unsigned long flags;
14812 - char *vaddr;
14813 + unsigned char *vaddr = ktla_ktva(addr);
14814 struct page *pages[2];
14815 - int i;
14816 + size_t i;
14817
14818 if (!core_kernel_text((unsigned long)addr)) {
14819 - pages[0] = vmalloc_to_page(addr);
14820 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14821 + pages[0] = vmalloc_to_page(vaddr);
14822 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14823 } else {
14824 - pages[0] = virt_to_page(addr);
14825 + pages[0] = virt_to_page(vaddr);
14826 WARN_ON(!PageReserved(pages[0]));
14827 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14828 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14829 }
14830 BUG_ON(!pages[0]);
14831 - local_irq_save(flags);
14832 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14833 - if (pages[1])
14834 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14835 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14836 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14837 - clear_fixmap(FIX_TEXT_POKE0);
14838 - if (pages[1])
14839 - clear_fixmap(FIX_TEXT_POKE1);
14840 - local_flush_tlb();
14841 - sync_core();
14842 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14843 - that causes hangs on some VIA CPUs. */
14844 + text_poke_early(addr, opcode, len);
14845 for (i = 0; i < len; i++)
14846 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14847 - local_irq_restore(flags);
14848 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14849 return addr;
14850 }
14851
14852 diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14853 index e663112..21938a3 100644
14854 --- a/arch/x86/kernel/amd_gart_64.c
14855 +++ b/arch/x86/kernel/amd_gart_64.c
14856 @@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14857
14858 flush_gart();
14859 dma_ops = &gart_dma_ops;
14860 - x86_platform.iommu_shutdown = gart_iommu_shutdown;
14861 + *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14862 swiotlb = 0;
14863
14864 return 0;
14865 diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14866 index d5fd66f..6119b16 100644
14867 --- a/arch/x86/kernel/aperture_64.c
14868 +++ b/arch/x86/kernel/aperture_64.c
14869 @@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14870
14871 iommu_detected = 1;
14872 gart_iommu_aperture = 1;
14873 - x86_init.iommu.iommu_init = gart_iommu_init;
14874 + *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14875
14876 ctl = read_pci_config(bus, slot, 3,
14877 AMD64_GARTAPERTURECTL);
14878 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14879 index b17416e..be6e5dc 100644
14880 --- a/arch/x86/kernel/apic/apic.c
14881 +++ b/arch/x86/kernel/apic/apic.c
14882 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14883 /*
14884 * Debug level, exported for io_apic.c
14885 */
14886 -unsigned int apic_verbosity;
14887 +int apic_verbosity;
14888
14889 int pic_mode;
14890
14891 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14892 apic_write(APIC_ESR, 0);
14893 v1 = apic_read(APIC_ESR);
14894 ack_APIC_irq();
14895 - atomic_inc(&irq_err_count);
14896 + atomic_inc_unchecked(&irq_err_count);
14897
14898 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14899 smp_processor_id(), v0 , v1);
14900 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14901 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14902 /* Should happen once for each apic */
14903 WARN_ON((*drv)->eoi_write == eoi_write);
14904 - (*drv)->eoi_write = eoi_write;
14905 + pax_open_kernel();
14906 + *(void **)&(*drv)->eoi_write = eoi_write;
14907 + pax_close_kernel();
14908 }
14909 }
14910
14911 diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
14912 index a65829a..6ddc249 100644
14913 --- a/arch/x86/kernel/apic/apic_numachip.c
14914 +++ b/arch/x86/kernel/apic/apic_numachip.c
14915 @@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
14916 if (!numachip_system)
14917 return 0;
14918
14919 - x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14920 + *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14921
14922 map_csrs();
14923
14924 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14925 index 1817fa9..7bff097 100644
14926 --- a/arch/x86/kernel/apic/io_apic.c
14927 +++ b/arch/x86/kernel/apic/io_apic.c
14928 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14929 }
14930 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14931
14932 -void lock_vector_lock(void)
14933 +void lock_vector_lock(void) __acquires(vector_lock)
14934 {
14935 /* Used to the online set of cpus does not change
14936 * during assign_irq_vector.
14937 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14938 raw_spin_lock(&vector_lock);
14939 }
14940
14941 -void unlock_vector_lock(void)
14942 +void unlock_vector_lock(void) __releases(vector_lock)
14943 {
14944 raw_spin_unlock(&vector_lock);
14945 }
14946 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14947 ack_APIC_irq();
14948 }
14949
14950 -atomic_t irq_mis_count;
14951 +atomic_unchecked_t irq_mis_count;
14952
14953 #ifdef CONFIG_GENERIC_PENDING_IRQ
14954 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14955 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
14956 * at the cpu.
14957 */
14958 if (!(v & (1 << (i & 0x1f)))) {
14959 - atomic_inc(&irq_mis_count);
14960 + atomic_inc_unchecked(&irq_mis_count);
14961
14962 eoi_ioapic_irq(irq, cfg);
14963 }
14964 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
14965 index d661ee9..512c0a1 100644
14966 --- a/arch/x86/kernel/apic/numaq_32.c
14967 +++ b/arch/x86/kernel/apic/numaq_32.c
14968 @@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
14969 early_get_smp_config();
14970
14971 if (found_numaq) {
14972 - x86_init.mpparse.mpc_record = numaq_mpc_record;
14973 - x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
14974 - x86_init.mpparse.mpc_apic_id = mpc_apic_id;
14975 - x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
14976 - x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
14977 - x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
14978 - x86_init.timers.tsc_pre_init = numaq_tsc_init;
14979 - x86_init.pci.init = pci_numaq_init;
14980 + *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
14981 + *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
14982 + *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
14983 + *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
14984 + *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
14985 + *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
14986 + *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
14987 + *(void **)&x86_init.pci.init = pci_numaq_init;
14988 }
14989 }
14990
14991 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
14992 index 8cfade9..8ea7b51 100644
14993 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
14994 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
14995 @@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
14996 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
14997 pnodeid = early_get_pnodeid();
14998 early_get_apic_pnode_shift();
14999 - x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15000 - x86_platform.nmi_init = uv_nmi_init;
15001 + *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15002 + *(void **)&x86_platform.nmi_init = uv_nmi_init;
15003 if (!strcmp(oem_table_id, "UVL"))
15004 uv_system_type = UV_LEGACY_APIC;
15005 else if (!strcmp(oem_table_id, "UVX"))
15006 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15007 index d65464e..1035d31 100644
15008 --- a/arch/x86/kernel/apm_32.c
15009 +++ b/arch/x86/kernel/apm_32.c
15010 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15011 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15012 * even though they are called in protected mode.
15013 */
15014 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15015 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15016 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15017
15018 static const char driver_version[] = "1.16ac"; /* no spaces */
15019 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15020 BUG_ON(cpu != 0);
15021 gdt = get_cpu_gdt_table(cpu);
15022 save_desc_40 = gdt[0x40 / 8];
15023 +
15024 + pax_open_kernel();
15025 gdt[0x40 / 8] = bad_bios_desc;
15026 + pax_close_kernel();
15027
15028 apm_irq_save(flags);
15029 APM_DO_SAVE_SEGS;
15030 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15031 &call->esi);
15032 APM_DO_RESTORE_SEGS;
15033 apm_irq_restore(flags);
15034 +
15035 + pax_open_kernel();
15036 gdt[0x40 / 8] = save_desc_40;
15037 + pax_close_kernel();
15038 +
15039 put_cpu();
15040
15041 return call->eax & 0xff;
15042 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15043 BUG_ON(cpu != 0);
15044 gdt = get_cpu_gdt_table(cpu);
15045 save_desc_40 = gdt[0x40 / 8];
15046 +
15047 + pax_open_kernel();
15048 gdt[0x40 / 8] = bad_bios_desc;
15049 + pax_close_kernel();
15050
15051 apm_irq_save(flags);
15052 APM_DO_SAVE_SEGS;
15053 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15054 &call->eax);
15055 APM_DO_RESTORE_SEGS;
15056 apm_irq_restore(flags);
15057 +
15058 + pax_open_kernel();
15059 gdt[0x40 / 8] = save_desc_40;
15060 + pax_close_kernel();
15061 +
15062 put_cpu();
15063 return error;
15064 }
15065 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15066 * code to that CPU.
15067 */
15068 gdt = get_cpu_gdt_table(0);
15069 +
15070 + pax_open_kernel();
15071 set_desc_base(&gdt[APM_CS >> 3],
15072 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15073 set_desc_base(&gdt[APM_CS_16 >> 3],
15074 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15075 set_desc_base(&gdt[APM_DS >> 3],
15076 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15077 + pax_close_kernel();
15078
15079 proc_create("apm", 0, NULL, &apm_file_ops);
15080
15081 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15082 index 2861082..6d4718e 100644
15083 --- a/arch/x86/kernel/asm-offsets.c
15084 +++ b/arch/x86/kernel/asm-offsets.c
15085 @@ -33,6 +33,8 @@ void common(void) {
15086 OFFSET(TI_status, thread_info, status);
15087 OFFSET(TI_addr_limit, thread_info, addr_limit);
15088 OFFSET(TI_preempt_count, thread_info, preempt_count);
15089 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15090 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15091
15092 BLANK();
15093 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15094 @@ -53,8 +55,26 @@ void common(void) {
15095 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15096 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15097 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15098 +
15099 +#ifdef CONFIG_PAX_KERNEXEC
15100 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15101 #endif
15102
15103 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15104 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15105 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15106 +#ifdef CONFIG_X86_64
15107 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15108 +#endif
15109 +#endif
15110 +
15111 +#endif
15112 +
15113 + BLANK();
15114 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15115 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15116 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15117 +
15118 #ifdef CONFIG_XEN
15119 BLANK();
15120 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15121 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15122 index 1b4754f..fbb4227 100644
15123 --- a/arch/x86/kernel/asm-offsets_64.c
15124 +++ b/arch/x86/kernel/asm-offsets_64.c
15125 @@ -76,6 +76,7 @@ int main(void)
15126 BLANK();
15127 #undef ENTRY
15128
15129 + DEFINE(TSS_size, sizeof(struct tss_struct));
15130 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15131 BLANK();
15132
15133 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15134 index a0e067d..9c7db16 100644
15135 --- a/arch/x86/kernel/cpu/Makefile
15136 +++ b/arch/x86/kernel/cpu/Makefile
15137 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15138 CFLAGS_REMOVE_perf_event.o = -pg
15139 endif
15140
15141 -# Make sure load_percpu_segment has no stackprotector
15142 -nostackp := $(call cc-option, -fno-stack-protector)
15143 -CFLAGS_common.o := $(nostackp)
15144 -
15145 obj-y := intel_cacheinfo.o scattered.o topology.o
15146 obj-y += proc.o capflags.o powerflags.o common.o
15147 obj-y += vmware.o hypervisor.o mshyperv.o
15148 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15149 index 1b7d165..b9e2627 100644
15150 --- a/arch/x86/kernel/cpu/amd.c
15151 +++ b/arch/x86/kernel/cpu/amd.c
15152 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15153 unsigned int size)
15154 {
15155 /* AMD errata T13 (order #21922) */
15156 - if ((c->x86 == 6)) {
15157 + if (c->x86 == 6) {
15158 /* Duron Rev A0 */
15159 if (c->x86_model == 3 && c->x86_mask == 0)
15160 size = 64;
15161 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15162 index 7505f7b..d59dac0 100644
15163 --- a/arch/x86/kernel/cpu/common.c
15164 +++ b/arch/x86/kernel/cpu/common.c
15165 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15166
15167 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15168
15169 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15170 -#ifdef CONFIG_X86_64
15171 - /*
15172 - * We need valid kernel segments for data and code in long mode too
15173 - * IRET will check the segment types kkeil 2000/10/28
15174 - * Also sysret mandates a special GDT layout
15175 - *
15176 - * TLS descriptors are currently at a different place compared to i386.
15177 - * Hopefully nobody expects them at a fixed place (Wine?)
15178 - */
15179 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15180 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15181 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15182 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15183 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15184 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15185 -#else
15186 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15187 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15188 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15189 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15190 - /*
15191 - * Segments used for calling PnP BIOS have byte granularity.
15192 - * They code segments and data segments have fixed 64k limits,
15193 - * the transfer segment sizes are set at run time.
15194 - */
15195 - /* 32-bit code */
15196 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15197 - /* 16-bit code */
15198 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15199 - /* 16-bit data */
15200 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15201 - /* 16-bit data */
15202 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15203 - /* 16-bit data */
15204 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15205 - /*
15206 - * The APM segments have byte granularity and their bases
15207 - * are set at run time. All have 64k limits.
15208 - */
15209 - /* 32-bit code */
15210 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15211 - /* 16-bit code */
15212 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15213 - /* data */
15214 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15215 -
15216 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15217 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15218 - GDT_STACK_CANARY_INIT
15219 -#endif
15220 -} };
15221 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15222 -
15223 static int __init x86_xsave_setup(char *s)
15224 {
15225 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15226 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15227 {
15228 struct desc_ptr gdt_descr;
15229
15230 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15231 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15232 gdt_descr.size = GDT_SIZE - 1;
15233 load_gdt(&gdt_descr);
15234 /* Reload the per-cpu base */
15235 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15236 /* Filter out anything that depends on CPUID levels we don't have */
15237 filter_cpuid_features(c, true);
15238
15239 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15240 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15241 +#endif
15242 +
15243 /* If the model name is still unset, do table lookup. */
15244 if (!c->x86_model_id[0]) {
15245 const char *p;
15246 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15247 }
15248 __setup("clearcpuid=", setup_disablecpuid);
15249
15250 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15251 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15252 +
15253 #ifdef CONFIG_X86_64
15254 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15255 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15256 - (unsigned long) nmi_idt_table };
15257 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15258
15259 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15260 irq_stack_union) __aligned(PAGE_SIZE);
15261 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15262 EXPORT_PER_CPU_SYMBOL(current_task);
15263
15264 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15265 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15266 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15267 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15268
15269 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15270 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15271 {
15272 memset(regs, 0, sizeof(struct pt_regs));
15273 regs->fs = __KERNEL_PERCPU;
15274 - regs->gs = __KERNEL_STACK_CANARY;
15275 + savesegment(gs, regs->gs);
15276
15277 return regs;
15278 }
15279 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15280 int i;
15281
15282 cpu = stack_smp_processor_id();
15283 - t = &per_cpu(init_tss, cpu);
15284 + t = init_tss + cpu;
15285 oist = &per_cpu(orig_ist, cpu);
15286
15287 #ifdef CONFIG_NUMA
15288 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15289 switch_to_new_gdt(cpu);
15290 loadsegment(fs, 0);
15291
15292 - load_idt((const struct desc_ptr *)&idt_descr);
15293 + load_idt(&idt_descr);
15294
15295 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15296 syscall_init();
15297 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15298 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15299 barrier();
15300
15301 - x86_configure_nx();
15302 if (cpu != 0)
15303 enable_x2apic();
15304
15305 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15306 {
15307 int cpu = smp_processor_id();
15308 struct task_struct *curr = current;
15309 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15310 + struct tss_struct *t = init_tss + cpu;
15311 struct thread_struct *thread = &curr->thread;
15312
15313 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15314 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15315 index 198e019..867575e 100644
15316 --- a/arch/x86/kernel/cpu/intel.c
15317 +++ b/arch/x86/kernel/cpu/intel.c
15318 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15319 * Update the IDT descriptor and reload the IDT so that
15320 * it uses the read-only mapped virtual address.
15321 */
15322 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15323 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15324 load_idt(&idt_descr);
15325 }
15326 #endif
15327 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15328 index 93c5451..3887433 100644
15329 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15330 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15331 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15332 };
15333
15334 #ifdef CONFIG_AMD_NB
15335 +static struct attribute *default_attrs_amd_nb[] = {
15336 + &type.attr,
15337 + &level.attr,
15338 + &coherency_line_size.attr,
15339 + &physical_line_partition.attr,
15340 + &ways_of_associativity.attr,
15341 + &number_of_sets.attr,
15342 + &size.attr,
15343 + &shared_cpu_map.attr,
15344 + &shared_cpu_list.attr,
15345 + NULL,
15346 + NULL,
15347 + NULL,
15348 + NULL
15349 +};
15350 +
15351 static struct attribute ** __cpuinit amd_l3_attrs(void)
15352 {
15353 static struct attribute **attrs;
15354 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15355
15356 n = ARRAY_SIZE(default_attrs);
15357
15358 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15359 - n += 2;
15360 -
15361 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15362 - n += 1;
15363 -
15364 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15365 - if (attrs == NULL)
15366 - return attrs = default_attrs;
15367 -
15368 - for (n = 0; default_attrs[n]; n++)
15369 - attrs[n] = default_attrs[n];
15370 + attrs = default_attrs_amd_nb;
15371
15372 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15373 attrs[n++] = &cache_disable_0.attr;
15374 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15375 .default_attrs = default_attrs,
15376 };
15377
15378 +#ifdef CONFIG_AMD_NB
15379 +static struct kobj_type ktype_cache_amd_nb = {
15380 + .sysfs_ops = &sysfs_ops,
15381 + .default_attrs = default_attrs_amd_nb,
15382 +};
15383 +#endif
15384 +
15385 static struct kobj_type ktype_percpu_entry = {
15386 .sysfs_ops = &sysfs_ops,
15387 };
15388 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15389 return retval;
15390 }
15391
15392 +#ifdef CONFIG_AMD_NB
15393 + amd_l3_attrs();
15394 +#endif
15395 +
15396 for (i = 0; i < num_cache_leaves; i++) {
15397 + struct kobj_type *ktype;
15398 +
15399 this_object = INDEX_KOBJECT_PTR(cpu, i);
15400 this_object->cpu = cpu;
15401 this_object->index = i;
15402
15403 this_leaf = CPUID4_INFO_IDX(cpu, i);
15404
15405 - ktype_cache.default_attrs = default_attrs;
15406 + ktype = &ktype_cache;
15407 #ifdef CONFIG_AMD_NB
15408 if (this_leaf->base.nb)
15409 - ktype_cache.default_attrs = amd_l3_attrs();
15410 + ktype = &ktype_cache_amd_nb;
15411 #endif
15412 retval = kobject_init_and_add(&(this_object->kobj),
15413 - &ktype_cache,
15414 + ktype,
15415 per_cpu(ici_cache_kobject, cpu),
15416 "index%1lu", i);
15417 if (unlikely(retval)) {
15418 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15419 index 46cbf86..55c7292 100644
15420 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15421 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15422 @@ -45,6 +45,7 @@
15423 #include <asm/processor.h>
15424 #include <asm/mce.h>
15425 #include <asm/msr.h>
15426 +#include <asm/local.h>
15427
15428 #include "mce-internal.h"
15429
15430 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15431 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15432 m->cs, m->ip);
15433
15434 - if (m->cs == __KERNEL_CS)
15435 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15436 print_symbol("{%s}", m->ip);
15437 pr_cont("\n");
15438 }
15439 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15440
15441 #define PANIC_TIMEOUT 5 /* 5 seconds */
15442
15443 -static atomic_t mce_paniced;
15444 +static atomic_unchecked_t mce_paniced;
15445
15446 static int fake_panic;
15447 -static atomic_t mce_fake_paniced;
15448 +static atomic_unchecked_t mce_fake_paniced;
15449
15450 /* Panic in progress. Enable interrupts and wait for final IPI */
15451 static void wait_for_panic(void)
15452 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15453 /*
15454 * Make sure only one CPU runs in machine check panic
15455 */
15456 - if (atomic_inc_return(&mce_paniced) > 1)
15457 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15458 wait_for_panic();
15459 barrier();
15460
15461 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15462 console_verbose();
15463 } else {
15464 /* Don't log too much for fake panic */
15465 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15466 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15467 return;
15468 }
15469 /* First print corrected ones that are still unlogged */
15470 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15471 * might have been modified by someone else.
15472 */
15473 rmb();
15474 - if (atomic_read(&mce_paniced))
15475 + if (atomic_read_unchecked(&mce_paniced))
15476 wait_for_panic();
15477 if (!monarch_timeout)
15478 goto out;
15479 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15480 }
15481
15482 /* Call the installed machine check handler for this CPU setup. */
15483 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15484 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15485 unexpected_machine_check;
15486
15487 /*
15488 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15489 return;
15490 }
15491
15492 + pax_open_kernel();
15493 machine_check_vector = do_machine_check;
15494 + pax_close_kernel();
15495
15496 __mcheck_cpu_init_generic();
15497 __mcheck_cpu_init_vendor(c);
15498 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15499 */
15500
15501 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15502 -static int mce_chrdev_open_count; /* #times opened */
15503 +static local_t mce_chrdev_open_count; /* #times opened */
15504 static int mce_chrdev_open_exclu; /* already open exclusive? */
15505
15506 static int mce_chrdev_open(struct inode *inode, struct file *file)
15507 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15508 spin_lock(&mce_chrdev_state_lock);
15509
15510 if (mce_chrdev_open_exclu ||
15511 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15512 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15513 spin_unlock(&mce_chrdev_state_lock);
15514
15515 return -EBUSY;
15516 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15517
15518 if (file->f_flags & O_EXCL)
15519 mce_chrdev_open_exclu = 1;
15520 - mce_chrdev_open_count++;
15521 + local_inc(&mce_chrdev_open_count);
15522
15523 spin_unlock(&mce_chrdev_state_lock);
15524
15525 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15526 {
15527 spin_lock(&mce_chrdev_state_lock);
15528
15529 - mce_chrdev_open_count--;
15530 + local_dec(&mce_chrdev_open_count);
15531 mce_chrdev_open_exclu = 0;
15532
15533 spin_unlock(&mce_chrdev_state_lock);
15534 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15535 return NOTIFY_OK;
15536 }
15537
15538 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15539 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15540 .notifier_call = mce_cpu_callback,
15541 };
15542
15543 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15544 static void mce_reset(void)
15545 {
15546 cpu_missing = 0;
15547 - atomic_set(&mce_fake_paniced, 0);
15548 + atomic_set_unchecked(&mce_fake_paniced, 0);
15549 atomic_set(&mce_executing, 0);
15550 atomic_set(&mce_callin, 0);
15551 atomic_set(&global_nwo, 0);
15552 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15553 index 2d5454c..51987eb 100644
15554 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15555 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15556 @@ -11,6 +11,7 @@
15557 #include <asm/processor.h>
15558 #include <asm/mce.h>
15559 #include <asm/msr.h>
15560 +#include <asm/pgtable.h>
15561
15562 /* By default disabled */
15563 int mce_p5_enabled __read_mostly;
15564 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15565 if (!cpu_has(c, X86_FEATURE_MCE))
15566 return;
15567
15568 + pax_open_kernel();
15569 machine_check_vector = pentium_machine_check;
15570 + pax_close_kernel();
15571 /* Make sure the vector pointer is visible before we enable MCEs: */
15572 wmb();
15573
15574 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15575 index 2d7998f..17c9de1 100644
15576 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15577 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15578 @@ -10,6 +10,7 @@
15579 #include <asm/processor.h>
15580 #include <asm/mce.h>
15581 #include <asm/msr.h>
15582 +#include <asm/pgtable.h>
15583
15584 /* Machine check handler for WinChip C6: */
15585 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15586 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15587 {
15588 u32 lo, hi;
15589
15590 + pax_open_kernel();
15591 machine_check_vector = winchip_machine_check;
15592 + pax_close_kernel();
15593 /* Make sure the vector pointer is visible before we enable MCEs: */
15594 wmb();
15595
15596 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15597 index 6b96110..0da73eb 100644
15598 --- a/arch/x86/kernel/cpu/mtrr/main.c
15599 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15600 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15601 u64 size_or_mask, size_and_mask;
15602 static bool mtrr_aps_delayed_init;
15603
15604 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15605 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15606
15607 const struct mtrr_ops *mtrr_if;
15608
15609 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15610 index df5e41f..816c719 100644
15611 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15612 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15613 @@ -25,7 +25,7 @@ struct mtrr_ops {
15614 int (*validate_add_page)(unsigned long base, unsigned long size,
15615 unsigned int type);
15616 int (*have_wrcomb)(void);
15617 -};
15618 +} __do_const;
15619
15620 extern int generic_get_free_region(unsigned long base, unsigned long size,
15621 int replace_reg);
15622 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15623 index d18b2b8..d3b834c 100644
15624 --- a/arch/x86/kernel/cpu/perf_event.c
15625 +++ b/arch/x86/kernel/cpu/perf_event.c
15626 @@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15627 if (idx > GDT_ENTRIES)
15628 return 0;
15629
15630 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15631 + desc = get_cpu_gdt_table(smp_processor_id());
15632 }
15633
15634 return get_desc_base(desc + idx);
15635 @@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15636 break;
15637
15638 perf_callchain_store(entry, frame.return_address);
15639 - fp = frame.next_frame;
15640 + fp = (const void __force_user *)frame.next_frame;
15641 }
15642 }
15643
15644 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15645 index 324bb52..1a93d85 100644
15646 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15647 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15648 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15649 * v2 and above have a perf capabilities MSR
15650 */
15651 if (version > 1) {
15652 - u64 capabilities;
15653 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15654
15655 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15656 - x86_pmu.intel_cap.capabilities = capabilities;
15657 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15658 + x86_pmu.intel_cap.capabilities = capabilities;
15659 }
15660
15661 intel_ds_init();
15662 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15663 index d22d0c4..088eb6f 100644
15664 --- a/arch/x86/kernel/cpu/vmware.c
15665 +++ b/arch/x86/kernel/cpu/vmware.c
15666 @@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15667 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15668
15669 if (ebx != UINT_MAX)
15670 - x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15671 + *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15672 else
15673 printk(KERN_WARNING
15674 "Failed to get TSC freq from the hypervisor\n");
15675 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15676 index 13ad899..f642b9a 100644
15677 --- a/arch/x86/kernel/crash.c
15678 +++ b/arch/x86/kernel/crash.c
15679 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15680 {
15681 #ifdef CONFIG_X86_32
15682 struct pt_regs fixed_regs;
15683 -#endif
15684
15685 -#ifdef CONFIG_X86_32
15686 - if (!user_mode_vm(regs)) {
15687 + if (!user_mode(regs)) {
15688 crash_fixup_ss_esp(&fixed_regs, regs);
15689 regs = &fixed_regs;
15690 }
15691 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15692 index 37250fe..bf2ec74 100644
15693 --- a/arch/x86/kernel/doublefault_32.c
15694 +++ b/arch/x86/kernel/doublefault_32.c
15695 @@ -11,7 +11,7 @@
15696
15697 #define DOUBLEFAULT_STACKSIZE (1024)
15698 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15699 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15700 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15701
15702 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15703
15704 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15705 unsigned long gdt, tss;
15706
15707 store_gdt(&gdt_desc);
15708 - gdt = gdt_desc.address;
15709 + gdt = (unsigned long)gdt_desc.address;
15710
15711 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15712
15713 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15714 /* 0x2 bit is always set */
15715 .flags = X86_EFLAGS_SF | 0x2,
15716 .sp = STACK_START,
15717 - .es = __USER_DS,
15718 + .es = __KERNEL_DS,
15719 .cs = __KERNEL_CS,
15720 .ss = __KERNEL_DS,
15721 - .ds = __USER_DS,
15722 + .ds = __KERNEL_DS,
15723 .fs = __KERNEL_PERCPU,
15724
15725 .__cr3 = __pa_nodebug(swapper_pg_dir),
15726 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15727 index ae42418b..787c16b 100644
15728 --- a/arch/x86/kernel/dumpstack.c
15729 +++ b/arch/x86/kernel/dumpstack.c
15730 @@ -2,6 +2,9 @@
15731 * Copyright (C) 1991, 1992 Linus Torvalds
15732 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15733 */
15734 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15735 +#define __INCLUDED_BY_HIDESYM 1
15736 +#endif
15737 #include <linux/kallsyms.h>
15738 #include <linux/kprobes.h>
15739 #include <linux/uaccess.h>
15740 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15741 static void
15742 print_ftrace_graph_addr(unsigned long addr, void *data,
15743 const struct stacktrace_ops *ops,
15744 - struct thread_info *tinfo, int *graph)
15745 + struct task_struct *task, int *graph)
15746 {
15747 - struct task_struct *task;
15748 unsigned long ret_addr;
15749 int index;
15750
15751 if (addr != (unsigned long)return_to_handler)
15752 return;
15753
15754 - task = tinfo->task;
15755 index = task->curr_ret_stack;
15756
15757 if (!task->ret_stack || index < *graph)
15758 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15759 static inline void
15760 print_ftrace_graph_addr(unsigned long addr, void *data,
15761 const struct stacktrace_ops *ops,
15762 - struct thread_info *tinfo, int *graph)
15763 + struct task_struct *task, int *graph)
15764 { }
15765 #endif
15766
15767 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15768 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15769 */
15770
15771 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15772 - void *p, unsigned int size, void *end)
15773 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15774 {
15775 - void *t = tinfo;
15776 if (end) {
15777 if (p < end && p >= (end-THREAD_SIZE))
15778 return 1;
15779 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15780 }
15781
15782 unsigned long
15783 -print_context_stack(struct thread_info *tinfo,
15784 +print_context_stack(struct task_struct *task, void *stack_start,
15785 unsigned long *stack, unsigned long bp,
15786 const struct stacktrace_ops *ops, void *data,
15787 unsigned long *end, int *graph)
15788 {
15789 struct stack_frame *frame = (struct stack_frame *)bp;
15790
15791 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15792 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15793 unsigned long addr;
15794
15795 addr = *stack;
15796 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15797 } else {
15798 ops->address(data, addr, 0);
15799 }
15800 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15801 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15802 }
15803 stack++;
15804 }
15805 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15806 EXPORT_SYMBOL_GPL(print_context_stack);
15807
15808 unsigned long
15809 -print_context_stack_bp(struct thread_info *tinfo,
15810 +print_context_stack_bp(struct task_struct *task, void *stack_start,
15811 unsigned long *stack, unsigned long bp,
15812 const struct stacktrace_ops *ops, void *data,
15813 unsigned long *end, int *graph)
15814 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15815 struct stack_frame *frame = (struct stack_frame *)bp;
15816 unsigned long *ret_addr = &frame->return_address;
15817
15818 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15819 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15820 unsigned long addr = *ret_addr;
15821
15822 if (!__kernel_text_address(addr))
15823 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15824 ops->address(data, addr, 1);
15825 frame = frame->next_frame;
15826 ret_addr = &frame->return_address;
15827 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15828 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15829 }
15830
15831 return (unsigned long)frame;
15832 @@ -189,7 +188,7 @@ void dump_stack(void)
15833
15834 bp = stack_frame(current, NULL);
15835 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15836 - current->pid, current->comm, print_tainted(),
15837 + task_pid_nr(current), current->comm, print_tainted(),
15838 init_utsname()->release,
15839 (int)strcspn(init_utsname()->version, " "),
15840 init_utsname()->version);
15841 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15842 }
15843 EXPORT_SYMBOL_GPL(oops_begin);
15844
15845 +extern void gr_handle_kernel_exploit(void);
15846 +
15847 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15848 {
15849 if (regs && kexec_should_crash(current))
15850 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15851 panic("Fatal exception in interrupt");
15852 if (panic_on_oops)
15853 panic("Fatal exception");
15854 - do_exit(signr);
15855 +
15856 + gr_handle_kernel_exploit();
15857 +
15858 + do_group_exit(signr);
15859 }
15860
15861 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15862 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15863 print_modules();
15864 show_regs(regs);
15865 #ifdef CONFIG_X86_32
15866 - if (user_mode_vm(regs)) {
15867 + if (user_mode(regs)) {
15868 sp = regs->sp;
15869 ss = regs->ss & 0xffff;
15870 } else {
15871 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15872 unsigned long flags = oops_begin();
15873 int sig = SIGSEGV;
15874
15875 - if (!user_mode_vm(regs))
15876 + if (!user_mode(regs))
15877 report_bug(regs->ip, regs);
15878
15879 if (__die(str, regs, err))
15880 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15881 index 1038a41..db2c12b 100644
15882 --- a/arch/x86/kernel/dumpstack_32.c
15883 +++ b/arch/x86/kernel/dumpstack_32.c
15884 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15885 bp = stack_frame(task, regs);
15886
15887 for (;;) {
15888 - struct thread_info *context;
15889 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15890
15891 - context = (struct thread_info *)
15892 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15893 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15894 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15895
15896 - stack = (unsigned long *)context->previous_esp;
15897 - if (!stack)
15898 + if (stack_start == task_stack_page(task))
15899 break;
15900 + stack = *(unsigned long **)stack_start;
15901 if (ops->stack(data, "IRQ") < 0)
15902 break;
15903 touch_nmi_watchdog();
15904 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
15905 {
15906 int i;
15907
15908 - __show_regs(regs, !user_mode_vm(regs));
15909 + __show_regs(regs, !user_mode(regs));
15910
15911 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
15912 TASK_COMM_LEN, current->comm, task_pid_nr(current),
15913 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
15914 * When in-kernel, we also print out the stack and code at the
15915 * time of the fault..
15916 */
15917 - if (!user_mode_vm(regs)) {
15918 + if (!user_mode(regs)) {
15919 unsigned int code_prologue = code_bytes * 43 / 64;
15920 unsigned int code_len = code_bytes;
15921 unsigned char c;
15922 u8 *ip;
15923 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
15924
15925 pr_emerg("Stack:\n");
15926 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
15927
15928 pr_emerg("Code:");
15929
15930 - ip = (u8 *)regs->ip - code_prologue;
15931 + ip = (u8 *)regs->ip - code_prologue + cs_base;
15932 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
15933 /* try starting at IP */
15934 - ip = (u8 *)regs->ip;
15935 + ip = (u8 *)regs->ip + cs_base;
15936 code_len = code_len - code_prologue + 1;
15937 }
15938 for (i = 0; i < code_len; i++, ip++) {
15939 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
15940 pr_cont(" Bad EIP value.");
15941 break;
15942 }
15943 - if (ip == (u8 *)regs->ip)
15944 + if (ip == (u8 *)regs->ip + cs_base)
15945 pr_cont(" <%02x>", c);
15946 else
15947 pr_cont(" %02x", c);
15948 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
15949 {
15950 unsigned short ud2;
15951
15952 + ip = ktla_ktva(ip);
15953 if (ip < PAGE_OFFSET)
15954 return 0;
15955 if (probe_kernel_address((unsigned short *)ip, ud2))
15956 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
15957
15958 return ud2 == 0x0b0f;
15959 }
15960 +
15961 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15962 +void pax_check_alloca(unsigned long size)
15963 +{
15964 + unsigned long sp = (unsigned long)&sp, stack_left;
15965 +
15966 + /* all kernel stacks are of the same size */
15967 + stack_left = sp & (THREAD_SIZE - 1);
15968 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15969 +}
15970 +EXPORT_SYMBOL(pax_check_alloca);
15971 +#endif
15972 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
15973 index b653675..51cc8c0 100644
15974 --- a/arch/x86/kernel/dumpstack_64.c
15975 +++ b/arch/x86/kernel/dumpstack_64.c
15976 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15977 unsigned long *irq_stack_end =
15978 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
15979 unsigned used = 0;
15980 - struct thread_info *tinfo;
15981 int graph = 0;
15982 unsigned long dummy;
15983 + void *stack_start;
15984
15985 if (!task)
15986 task = current;
15987 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15988 * current stack address. If the stacks consist of nested
15989 * exceptions
15990 */
15991 - tinfo = task_thread_info(task);
15992 for (;;) {
15993 char *id;
15994 unsigned long *estack_end;
15995 +
15996 estack_end = in_exception_stack(cpu, (unsigned long)stack,
15997 &used, &id);
15998
15999 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16000 if (ops->stack(data, id) < 0)
16001 break;
16002
16003 - bp = ops->walk_stack(tinfo, stack, bp, ops,
16004 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16005 data, estack_end, &graph);
16006 ops->stack(data, "<EOE>");
16007 /*
16008 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16009 * second-to-last pointer (index -2 to end) in the
16010 * exception stack:
16011 */
16012 + if ((u16)estack_end[-1] != __KERNEL_DS)
16013 + goto out;
16014 stack = (unsigned long *) estack_end[-2];
16015 continue;
16016 }
16017 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16018 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16019 if (ops->stack(data, "IRQ") < 0)
16020 break;
16021 - bp = ops->walk_stack(tinfo, stack, bp,
16022 + bp = ops->walk_stack(task, irq_stack, stack, bp,
16023 ops, data, irq_stack_end, &graph);
16024 /*
16025 * We link to the next stack (which would be
16026 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16027 /*
16028 * This handles the process stack:
16029 */
16030 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16031 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16032 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16033 +out:
16034 put_cpu();
16035 }
16036 EXPORT_SYMBOL(dump_trace);
16037 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16038 {
16039 int i;
16040 unsigned long sp;
16041 - const int cpu = smp_processor_id();
16042 + const int cpu = raw_smp_processor_id();
16043 struct task_struct *cur = current;
16044
16045 sp = regs->sp;
16046 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16047
16048 return ud2 == 0x0b0f;
16049 }
16050 +
16051 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16052 +void pax_check_alloca(unsigned long size)
16053 +{
16054 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16055 + unsigned cpu, used;
16056 + char *id;
16057 +
16058 + /* check the process stack first */
16059 + stack_start = (unsigned long)task_stack_page(current);
16060 + stack_end = stack_start + THREAD_SIZE;
16061 + if (likely(stack_start <= sp && sp < stack_end)) {
16062 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
16063 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16064 + return;
16065 + }
16066 +
16067 + cpu = get_cpu();
16068 +
16069 + /* check the irq stacks */
16070 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16071 + stack_start = stack_end - IRQ_STACK_SIZE;
16072 + if (stack_start <= sp && sp < stack_end) {
16073 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16074 + put_cpu();
16075 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16076 + return;
16077 + }
16078 +
16079 + /* check the exception stacks */
16080 + used = 0;
16081 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16082 + stack_start = stack_end - EXCEPTION_STKSZ;
16083 + if (stack_end && stack_start <= sp && sp < stack_end) {
16084 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16085 + put_cpu();
16086 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16087 + return;
16088 + }
16089 +
16090 + put_cpu();
16091 +
16092 + /* unknown stack */
16093 + BUG();
16094 +}
16095 +EXPORT_SYMBOL(pax_check_alloca);
16096 +#endif
16097 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16098 index 9b9f18b..9fcaa04 100644
16099 --- a/arch/x86/kernel/early_printk.c
16100 +++ b/arch/x86/kernel/early_printk.c
16101 @@ -7,6 +7,7 @@
16102 #include <linux/pci_regs.h>
16103 #include <linux/pci_ids.h>
16104 #include <linux/errno.h>
16105 +#include <linux/sched.h>
16106 #include <asm/io.h>
16107 #include <asm/processor.h>
16108 #include <asm/fcntl.h>
16109 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16110 index cf8639b..98fcee6 100644
16111 --- a/arch/x86/kernel/entry_32.S
16112 +++ b/arch/x86/kernel/entry_32.S
16113 @@ -177,13 +177,153 @@
16114 /*CFI_REL_OFFSET gs, PT_GS*/
16115 .endm
16116 .macro SET_KERNEL_GS reg
16117 +
16118 +#ifdef CONFIG_CC_STACKPROTECTOR
16119 movl $(__KERNEL_STACK_CANARY), \reg
16120 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16121 + movl $(__USER_DS), \reg
16122 +#else
16123 + xorl \reg, \reg
16124 +#endif
16125 +
16126 movl \reg, %gs
16127 .endm
16128
16129 #endif /* CONFIG_X86_32_LAZY_GS */
16130
16131 -.macro SAVE_ALL
16132 +.macro pax_enter_kernel
16133 +#ifdef CONFIG_PAX_KERNEXEC
16134 + call pax_enter_kernel
16135 +#endif
16136 +.endm
16137 +
16138 +.macro pax_exit_kernel
16139 +#ifdef CONFIG_PAX_KERNEXEC
16140 + call pax_exit_kernel
16141 +#endif
16142 +.endm
16143 +
16144 +#ifdef CONFIG_PAX_KERNEXEC
16145 +ENTRY(pax_enter_kernel)
16146 +#ifdef CONFIG_PARAVIRT
16147 + pushl %eax
16148 + pushl %ecx
16149 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16150 + mov %eax, %esi
16151 +#else
16152 + mov %cr0, %esi
16153 +#endif
16154 + bts $16, %esi
16155 + jnc 1f
16156 + mov %cs, %esi
16157 + cmp $__KERNEL_CS, %esi
16158 + jz 3f
16159 + ljmp $__KERNEL_CS, $3f
16160 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16161 +2:
16162 +#ifdef CONFIG_PARAVIRT
16163 + mov %esi, %eax
16164 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16165 +#else
16166 + mov %esi, %cr0
16167 +#endif
16168 +3:
16169 +#ifdef CONFIG_PARAVIRT
16170 + popl %ecx
16171 + popl %eax
16172 +#endif
16173 + ret
16174 +ENDPROC(pax_enter_kernel)
16175 +
16176 +ENTRY(pax_exit_kernel)
16177 +#ifdef CONFIG_PARAVIRT
16178 + pushl %eax
16179 + pushl %ecx
16180 +#endif
16181 + mov %cs, %esi
16182 + cmp $__KERNEXEC_KERNEL_CS, %esi
16183 + jnz 2f
16184 +#ifdef CONFIG_PARAVIRT
16185 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16186 + mov %eax, %esi
16187 +#else
16188 + mov %cr0, %esi
16189 +#endif
16190 + btr $16, %esi
16191 + ljmp $__KERNEL_CS, $1f
16192 +1:
16193 +#ifdef CONFIG_PARAVIRT
16194 + mov %esi, %eax
16195 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16196 +#else
16197 + mov %esi, %cr0
16198 +#endif
16199 +2:
16200 +#ifdef CONFIG_PARAVIRT
16201 + popl %ecx
16202 + popl %eax
16203 +#endif
16204 + ret
16205 +ENDPROC(pax_exit_kernel)
16206 +#endif
16207 +
16208 +.macro pax_erase_kstack
16209 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16210 + call pax_erase_kstack
16211 +#endif
16212 +.endm
16213 +
16214 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16215 +/*
16216 + * ebp: thread_info
16217 + */
16218 +ENTRY(pax_erase_kstack)
16219 + pushl %edi
16220 + pushl %ecx
16221 + pushl %eax
16222 +
16223 + mov TI_lowest_stack(%ebp), %edi
16224 + mov $-0xBEEF, %eax
16225 + std
16226 +
16227 +1: mov %edi, %ecx
16228 + and $THREAD_SIZE_asm - 1, %ecx
16229 + shr $2, %ecx
16230 + repne scasl
16231 + jecxz 2f
16232 +
16233 + cmp $2*16, %ecx
16234 + jc 2f
16235 +
16236 + mov $2*16, %ecx
16237 + repe scasl
16238 + jecxz 2f
16239 + jne 1b
16240 +
16241 +2: cld
16242 + mov %esp, %ecx
16243 + sub %edi, %ecx
16244 +
16245 + cmp $THREAD_SIZE_asm, %ecx
16246 + jb 3f
16247 + ud2
16248 +3:
16249 +
16250 + shr $2, %ecx
16251 + rep stosl
16252 +
16253 + mov TI_task_thread_sp0(%ebp), %edi
16254 + sub $128, %edi
16255 + mov %edi, TI_lowest_stack(%ebp)
16256 +
16257 + popl %eax
16258 + popl %ecx
16259 + popl %edi
16260 + ret
16261 +ENDPROC(pax_erase_kstack)
16262 +#endif
16263 +
16264 +.macro __SAVE_ALL _DS
16265 cld
16266 PUSH_GS
16267 pushl_cfi %fs
16268 @@ -206,7 +346,7 @@
16269 CFI_REL_OFFSET ecx, 0
16270 pushl_cfi %ebx
16271 CFI_REL_OFFSET ebx, 0
16272 - movl $(__USER_DS), %edx
16273 + movl $\_DS, %edx
16274 movl %edx, %ds
16275 movl %edx, %es
16276 movl $(__KERNEL_PERCPU), %edx
16277 @@ -214,6 +354,15 @@
16278 SET_KERNEL_GS %edx
16279 .endm
16280
16281 +.macro SAVE_ALL
16282 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16283 + __SAVE_ALL __KERNEL_DS
16284 + pax_enter_kernel
16285 +#else
16286 + __SAVE_ALL __USER_DS
16287 +#endif
16288 +.endm
16289 +
16290 .macro RESTORE_INT_REGS
16291 popl_cfi %ebx
16292 CFI_RESTORE ebx
16293 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16294 popfl_cfi
16295 jmp syscall_exit
16296 CFI_ENDPROC
16297 -END(ret_from_fork)
16298 +ENDPROC(ret_from_fork)
16299
16300 ENTRY(ret_from_kernel_thread)
16301 CFI_STARTPROC
16302 @@ -344,7 +493,15 @@ ret_from_intr:
16303 andl $SEGMENT_RPL_MASK, %eax
16304 #endif
16305 cmpl $USER_RPL, %eax
16306 +
16307 +#ifdef CONFIG_PAX_KERNEXEC
16308 + jae resume_userspace
16309 +
16310 + pax_exit_kernel
16311 + jmp resume_kernel
16312 +#else
16313 jb resume_kernel # not returning to v8086 or userspace
16314 +#endif
16315
16316 ENTRY(resume_userspace)
16317 LOCKDEP_SYS_EXIT
16318 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16319 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16320 # int/exception return?
16321 jne work_pending
16322 - jmp restore_all
16323 -END(ret_from_exception)
16324 + jmp restore_all_pax
16325 +ENDPROC(ret_from_exception)
16326
16327 #ifdef CONFIG_PREEMPT
16328 ENTRY(resume_kernel)
16329 @@ -372,7 +529,7 @@ need_resched:
16330 jz restore_all
16331 call preempt_schedule_irq
16332 jmp need_resched
16333 -END(resume_kernel)
16334 +ENDPROC(resume_kernel)
16335 #endif
16336 CFI_ENDPROC
16337 /*
16338 @@ -406,30 +563,45 @@ sysenter_past_esp:
16339 /*CFI_REL_OFFSET cs, 0*/
16340 /*
16341 * Push current_thread_info()->sysenter_return to the stack.
16342 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16343 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16344 */
16345 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16346 + pushl_cfi $0
16347 CFI_REL_OFFSET eip, 0
16348
16349 pushl_cfi %eax
16350 SAVE_ALL
16351 + GET_THREAD_INFO(%ebp)
16352 + movl TI_sysenter_return(%ebp),%ebp
16353 + movl %ebp,PT_EIP(%esp)
16354 ENABLE_INTERRUPTS(CLBR_NONE)
16355
16356 /*
16357 * Load the potential sixth argument from user stack.
16358 * Careful about security.
16359 */
16360 + movl PT_OLDESP(%esp),%ebp
16361 +
16362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16363 + mov PT_OLDSS(%esp),%ds
16364 +1: movl %ds:(%ebp),%ebp
16365 + push %ss
16366 + pop %ds
16367 +#else
16368 cmpl $__PAGE_OFFSET-3,%ebp
16369 jae syscall_fault
16370 ASM_STAC
16371 1: movl (%ebp),%ebp
16372 ASM_CLAC
16373 +#endif
16374 +
16375 movl %ebp,PT_EBP(%esp)
16376 _ASM_EXTABLE(1b,syscall_fault)
16377
16378 GET_THREAD_INFO(%ebp)
16379
16380 +#ifdef CONFIG_PAX_RANDKSTACK
16381 + pax_erase_kstack
16382 +#endif
16383 +
16384 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16385 jnz sysenter_audit
16386 sysenter_do_call:
16387 @@ -444,12 +616,24 @@ sysenter_do_call:
16388 testl $_TIF_ALLWORK_MASK, %ecx
16389 jne sysexit_audit
16390 sysenter_exit:
16391 +
16392 +#ifdef CONFIG_PAX_RANDKSTACK
16393 + pushl_cfi %eax
16394 + movl %esp, %eax
16395 + call pax_randomize_kstack
16396 + popl_cfi %eax
16397 +#endif
16398 +
16399 + pax_erase_kstack
16400 +
16401 /* if something modifies registers it must also disable sysexit */
16402 movl PT_EIP(%esp), %edx
16403 movl PT_OLDESP(%esp), %ecx
16404 xorl %ebp,%ebp
16405 TRACE_IRQS_ON
16406 1: mov PT_FS(%esp), %fs
16407 +2: mov PT_DS(%esp), %ds
16408 +3: mov PT_ES(%esp), %es
16409 PTGS_TO_GS
16410 ENABLE_INTERRUPTS_SYSEXIT
16411
16412 @@ -466,6 +650,9 @@ sysenter_audit:
16413 movl %eax,%edx /* 2nd arg: syscall number */
16414 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16415 call __audit_syscall_entry
16416 +
16417 + pax_erase_kstack
16418 +
16419 pushl_cfi %ebx
16420 movl PT_EAX(%esp),%eax /* reload syscall number */
16421 jmp sysenter_do_call
16422 @@ -491,10 +678,16 @@ sysexit_audit:
16423
16424 CFI_ENDPROC
16425 .pushsection .fixup,"ax"
16426 -2: movl $0,PT_FS(%esp)
16427 +4: movl $0,PT_FS(%esp)
16428 + jmp 1b
16429 +5: movl $0,PT_DS(%esp)
16430 + jmp 1b
16431 +6: movl $0,PT_ES(%esp)
16432 jmp 1b
16433 .popsection
16434 - _ASM_EXTABLE(1b,2b)
16435 + _ASM_EXTABLE(1b,4b)
16436 + _ASM_EXTABLE(2b,5b)
16437 + _ASM_EXTABLE(3b,6b)
16438 PTGS_TO_GS_EX
16439 ENDPROC(ia32_sysenter_target)
16440
16441 @@ -509,6 +702,11 @@ ENTRY(system_call)
16442 pushl_cfi %eax # save orig_eax
16443 SAVE_ALL
16444 GET_THREAD_INFO(%ebp)
16445 +
16446 +#ifdef CONFIG_PAX_RANDKSTACK
16447 + pax_erase_kstack
16448 +#endif
16449 +
16450 # system call tracing in operation / emulation
16451 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16452 jnz syscall_trace_entry
16453 @@ -527,6 +725,15 @@ syscall_exit:
16454 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16455 jne syscall_exit_work
16456
16457 +restore_all_pax:
16458 +
16459 +#ifdef CONFIG_PAX_RANDKSTACK
16460 + movl %esp, %eax
16461 + call pax_randomize_kstack
16462 +#endif
16463 +
16464 + pax_erase_kstack
16465 +
16466 restore_all:
16467 TRACE_IRQS_IRET
16468 restore_all_notrace:
16469 @@ -583,14 +790,34 @@ ldt_ss:
16470 * compensating for the offset by changing to the ESPFIX segment with
16471 * a base address that matches for the difference.
16472 */
16473 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16474 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16475 mov %esp, %edx /* load kernel esp */
16476 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16477 mov %dx, %ax /* eax: new kernel esp */
16478 sub %eax, %edx /* offset (low word is 0) */
16479 +#ifdef CONFIG_SMP
16480 + movl PER_CPU_VAR(cpu_number), %ebx
16481 + shll $PAGE_SHIFT_asm, %ebx
16482 + addl $cpu_gdt_table, %ebx
16483 +#else
16484 + movl $cpu_gdt_table, %ebx
16485 +#endif
16486 shr $16, %edx
16487 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16488 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16489 +
16490 +#ifdef CONFIG_PAX_KERNEXEC
16491 + mov %cr0, %esi
16492 + btr $16, %esi
16493 + mov %esi, %cr0
16494 +#endif
16495 +
16496 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16497 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16498 +
16499 +#ifdef CONFIG_PAX_KERNEXEC
16500 + bts $16, %esi
16501 + mov %esi, %cr0
16502 +#endif
16503 +
16504 pushl_cfi $__ESPFIX_SS
16505 pushl_cfi %eax /* new kernel esp */
16506 /* Disable interrupts, but do not irqtrace this section: we
16507 @@ -619,20 +846,18 @@ work_resched:
16508 movl TI_flags(%ebp), %ecx
16509 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16510 # than syscall tracing?
16511 - jz restore_all
16512 + jz restore_all_pax
16513 testb $_TIF_NEED_RESCHED, %cl
16514 jnz work_resched
16515
16516 work_notifysig: # deal with pending signals and
16517 # notify-resume requests
16518 + movl %esp, %eax
16519 #ifdef CONFIG_VM86
16520 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16521 - movl %esp, %eax
16522 jne work_notifysig_v86 # returning to kernel-space or
16523 # vm86-space
16524 1:
16525 -#else
16526 - movl %esp, %eax
16527 #endif
16528 TRACE_IRQS_ON
16529 ENABLE_INTERRUPTS(CLBR_NONE)
16530 @@ -653,7 +878,7 @@ work_notifysig_v86:
16531 movl %eax, %esp
16532 jmp 1b
16533 #endif
16534 -END(work_pending)
16535 +ENDPROC(work_pending)
16536
16537 # perform syscall exit tracing
16538 ALIGN
16539 @@ -661,11 +886,14 @@ syscall_trace_entry:
16540 movl $-ENOSYS,PT_EAX(%esp)
16541 movl %esp, %eax
16542 call syscall_trace_enter
16543 +
16544 + pax_erase_kstack
16545 +
16546 /* What it returned is what we'll actually use. */
16547 cmpl $(NR_syscalls), %eax
16548 jnae syscall_call
16549 jmp syscall_exit
16550 -END(syscall_trace_entry)
16551 +ENDPROC(syscall_trace_entry)
16552
16553 # perform syscall exit tracing
16554 ALIGN
16555 @@ -678,21 +906,25 @@ syscall_exit_work:
16556 movl %esp, %eax
16557 call syscall_trace_leave
16558 jmp resume_userspace
16559 -END(syscall_exit_work)
16560 +ENDPROC(syscall_exit_work)
16561 CFI_ENDPROC
16562
16563 RING0_INT_FRAME # can't unwind into user space anyway
16564 syscall_fault:
16565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16566 + push %ss
16567 + pop %ds
16568 +#endif
16569 ASM_CLAC
16570 GET_THREAD_INFO(%ebp)
16571 movl $-EFAULT,PT_EAX(%esp)
16572 jmp resume_userspace
16573 -END(syscall_fault)
16574 +ENDPROC(syscall_fault)
16575
16576 syscall_badsys:
16577 movl $-ENOSYS,PT_EAX(%esp)
16578 jmp resume_userspace
16579 -END(syscall_badsys)
16580 +ENDPROC(syscall_badsys)
16581 CFI_ENDPROC
16582 /*
16583 * End of kprobes section
16584 @@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
16585 CFI_ENDPROC
16586 ENDPROC(ptregs_clone)
16587
16588 + ALIGN;
16589 +ENTRY(kernel_execve)
16590 + CFI_STARTPROC
16591 + pushl_cfi %ebp
16592 + sub $PT_OLDSS+4,%esp
16593 + pushl_cfi %edi
16594 + pushl_cfi %ecx
16595 + pushl_cfi %eax
16596 + lea 3*4(%esp),%edi
16597 + mov $PT_OLDSS/4+1,%ecx
16598 + xorl %eax,%eax
16599 + rep stosl
16600 + popl_cfi %eax
16601 + popl_cfi %ecx
16602 + popl_cfi %edi
16603 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
16604 + pushl_cfi %esp
16605 + call sys_execve
16606 + add $4,%esp
16607 + CFI_ADJUST_CFA_OFFSET -4
16608 + GET_THREAD_INFO(%ebp)
16609 + test %eax,%eax
16610 + jz syscall_exit
16611 + add $PT_OLDSS+4,%esp
16612 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
16613 + popl_cfi %ebp
16614 + ret
16615 + CFI_ENDPROC
16616 +ENDPROC(kernel_execve)
16617 +
16618 .macro FIXUP_ESPFIX_STACK
16619 /*
16620 * Switch back for ESPFIX stack to the normal zerobased stack
16621 @@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
16622 * normal stack and adjusts ESP with the matching offset.
16623 */
16624 /* fixup the stack */
16625 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16626 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16627 +#ifdef CONFIG_SMP
16628 + movl PER_CPU_VAR(cpu_number), %ebx
16629 + shll $PAGE_SHIFT_asm, %ebx
16630 + addl $cpu_gdt_table, %ebx
16631 +#else
16632 + movl $cpu_gdt_table, %ebx
16633 +#endif
16634 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16635 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16636 shl $16, %eax
16637 addl %esp, %eax /* the adjusted stack pointer */
16638 pushl_cfi $__KERNEL_DS
16639 @@ -826,7 +1095,7 @@ vector=vector+1
16640 .endr
16641 2: jmp common_interrupt
16642 .endr
16643 -END(irq_entries_start)
16644 +ENDPROC(irq_entries_start)
16645
16646 .previous
16647 END(interrupt)
16648 @@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
16649 pushl_cfi $do_coprocessor_error
16650 jmp error_code
16651 CFI_ENDPROC
16652 -END(coprocessor_error)
16653 +ENDPROC(coprocessor_error)
16654
16655 ENTRY(simd_coprocessor_error)
16656 RING0_INT_FRAME
16657 @@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
16658 #endif
16659 jmp error_code
16660 CFI_ENDPROC
16661 -END(simd_coprocessor_error)
16662 +ENDPROC(simd_coprocessor_error)
16663
16664 ENTRY(device_not_available)
16665 RING0_INT_FRAME
16666 @@ -908,18 +1177,18 @@ ENTRY(device_not_available)
16667 pushl_cfi $do_device_not_available
16668 jmp error_code
16669 CFI_ENDPROC
16670 -END(device_not_available)
16671 +ENDPROC(device_not_available)
16672
16673 #ifdef CONFIG_PARAVIRT
16674 ENTRY(native_iret)
16675 iret
16676 _ASM_EXTABLE(native_iret, iret_exc)
16677 -END(native_iret)
16678 +ENDPROC(native_iret)
16679
16680 ENTRY(native_irq_enable_sysexit)
16681 sti
16682 sysexit
16683 -END(native_irq_enable_sysexit)
16684 +ENDPROC(native_irq_enable_sysexit)
16685 #endif
16686
16687 ENTRY(overflow)
16688 @@ -929,7 +1198,7 @@ ENTRY(overflow)
16689 pushl_cfi $do_overflow
16690 jmp error_code
16691 CFI_ENDPROC
16692 -END(overflow)
16693 +ENDPROC(overflow)
16694
16695 ENTRY(bounds)
16696 RING0_INT_FRAME
16697 @@ -938,7 +1207,7 @@ ENTRY(bounds)
16698 pushl_cfi $do_bounds
16699 jmp error_code
16700 CFI_ENDPROC
16701 -END(bounds)
16702 +ENDPROC(bounds)
16703
16704 ENTRY(invalid_op)
16705 RING0_INT_FRAME
16706 @@ -947,7 +1216,7 @@ ENTRY(invalid_op)
16707 pushl_cfi $do_invalid_op
16708 jmp error_code
16709 CFI_ENDPROC
16710 -END(invalid_op)
16711 +ENDPROC(invalid_op)
16712
16713 ENTRY(coprocessor_segment_overrun)
16714 RING0_INT_FRAME
16715 @@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
16716 pushl_cfi $do_coprocessor_segment_overrun
16717 jmp error_code
16718 CFI_ENDPROC
16719 -END(coprocessor_segment_overrun)
16720 +ENDPROC(coprocessor_segment_overrun)
16721
16722 ENTRY(invalid_TSS)
16723 RING0_EC_FRAME
16724 @@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
16725 pushl_cfi $do_invalid_TSS
16726 jmp error_code
16727 CFI_ENDPROC
16728 -END(invalid_TSS)
16729 +ENDPROC(invalid_TSS)
16730
16731 ENTRY(segment_not_present)
16732 RING0_EC_FRAME
16733 @@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
16734 pushl_cfi $do_segment_not_present
16735 jmp error_code
16736 CFI_ENDPROC
16737 -END(segment_not_present)
16738 +ENDPROC(segment_not_present)
16739
16740 ENTRY(stack_segment)
16741 RING0_EC_FRAME
16742 @@ -980,7 +1249,7 @@ ENTRY(stack_segment)
16743 pushl_cfi $do_stack_segment
16744 jmp error_code
16745 CFI_ENDPROC
16746 -END(stack_segment)
16747 +ENDPROC(stack_segment)
16748
16749 ENTRY(alignment_check)
16750 RING0_EC_FRAME
16751 @@ -988,7 +1257,7 @@ ENTRY(alignment_check)
16752 pushl_cfi $do_alignment_check
16753 jmp error_code
16754 CFI_ENDPROC
16755 -END(alignment_check)
16756 +ENDPROC(alignment_check)
16757
16758 ENTRY(divide_error)
16759 RING0_INT_FRAME
16760 @@ -997,7 +1266,7 @@ ENTRY(divide_error)
16761 pushl_cfi $do_divide_error
16762 jmp error_code
16763 CFI_ENDPROC
16764 -END(divide_error)
16765 +ENDPROC(divide_error)
16766
16767 #ifdef CONFIG_X86_MCE
16768 ENTRY(machine_check)
16769 @@ -1007,7 +1276,7 @@ ENTRY(machine_check)
16770 pushl_cfi machine_check_vector
16771 jmp error_code
16772 CFI_ENDPROC
16773 -END(machine_check)
16774 +ENDPROC(machine_check)
16775 #endif
16776
16777 ENTRY(spurious_interrupt_bug)
16778 @@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
16779 pushl_cfi $do_spurious_interrupt_bug
16780 jmp error_code
16781 CFI_ENDPROC
16782 -END(spurious_interrupt_bug)
16783 +ENDPROC(spurious_interrupt_bug)
16784 /*
16785 * End of kprobes section
16786 */
16787 @@ -1120,7 +1389,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16788
16789 ENTRY(mcount)
16790 ret
16791 -END(mcount)
16792 +ENDPROC(mcount)
16793
16794 ENTRY(ftrace_caller)
16795 cmpl $0, function_trace_stop
16796 @@ -1153,7 +1422,7 @@ ftrace_graph_call:
16797 .globl ftrace_stub
16798 ftrace_stub:
16799 ret
16800 -END(ftrace_caller)
16801 +ENDPROC(ftrace_caller)
16802
16803 ENTRY(ftrace_regs_caller)
16804 pushf /* push flags before compare (in cs location) */
16805 @@ -1254,7 +1523,7 @@ trace:
16806 popl %ecx
16807 popl %eax
16808 jmp ftrace_stub
16809 -END(mcount)
16810 +ENDPROC(mcount)
16811 #endif /* CONFIG_DYNAMIC_FTRACE */
16812 #endif /* CONFIG_FUNCTION_TRACER */
16813
16814 @@ -1272,7 +1541,7 @@ ENTRY(ftrace_graph_caller)
16815 popl %ecx
16816 popl %eax
16817 ret
16818 -END(ftrace_graph_caller)
16819 +ENDPROC(ftrace_graph_caller)
16820
16821 .globl return_to_handler
16822 return_to_handler:
16823 @@ -1328,15 +1597,18 @@ error_code:
16824 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16825 REG_TO_PTGS %ecx
16826 SET_KERNEL_GS %ecx
16827 - movl $(__USER_DS), %ecx
16828 + movl $(__KERNEL_DS), %ecx
16829 movl %ecx, %ds
16830 movl %ecx, %es
16831 +
16832 + pax_enter_kernel
16833 +
16834 TRACE_IRQS_OFF
16835 movl %esp,%eax # pt_regs pointer
16836 call *%edi
16837 jmp ret_from_exception
16838 CFI_ENDPROC
16839 -END(page_fault)
16840 +ENDPROC(page_fault)
16841
16842 /*
16843 * Debug traps and NMI can happen at the one SYSENTER instruction
16844 @@ -1379,7 +1651,7 @@ debug_stack_correct:
16845 call do_debug
16846 jmp ret_from_exception
16847 CFI_ENDPROC
16848 -END(debug)
16849 +ENDPROC(debug)
16850
16851 /*
16852 * NMI is doubly nasty. It can happen _while_ we're handling
16853 @@ -1417,6 +1689,9 @@ nmi_stack_correct:
16854 xorl %edx,%edx # zero error code
16855 movl %esp,%eax # pt_regs pointer
16856 call do_nmi
16857 +
16858 + pax_exit_kernel
16859 +
16860 jmp restore_all_notrace
16861 CFI_ENDPROC
16862
16863 @@ -1453,12 +1728,15 @@ nmi_espfix_stack:
16864 FIXUP_ESPFIX_STACK # %eax == %esp
16865 xorl %edx,%edx # zero error code
16866 call do_nmi
16867 +
16868 + pax_exit_kernel
16869 +
16870 RESTORE_REGS
16871 lss 12+4(%esp), %esp # back to espfix stack
16872 CFI_ADJUST_CFA_OFFSET -24
16873 jmp irq_return
16874 CFI_ENDPROC
16875 -END(nmi)
16876 +ENDPROC(nmi)
16877
16878 ENTRY(int3)
16879 RING0_INT_FRAME
16880 @@ -1471,14 +1749,14 @@ ENTRY(int3)
16881 call do_int3
16882 jmp ret_from_exception
16883 CFI_ENDPROC
16884 -END(int3)
16885 +ENDPROC(int3)
16886
16887 ENTRY(general_protection)
16888 RING0_EC_FRAME
16889 pushl_cfi $do_general_protection
16890 jmp error_code
16891 CFI_ENDPROC
16892 -END(general_protection)
16893 +ENDPROC(general_protection)
16894
16895 #ifdef CONFIG_KVM_GUEST
16896 ENTRY(async_page_fault)
16897 @@ -1487,7 +1765,7 @@ ENTRY(async_page_fault)
16898 pushl_cfi $do_async_page_fault
16899 jmp error_code
16900 CFI_ENDPROC
16901 -END(async_page_fault)
16902 +ENDPROC(async_page_fault)
16903 #endif
16904
16905 /*
16906 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16907 index 1328fe4..cb03298 100644
16908 --- a/arch/x86/kernel/entry_64.S
16909 +++ b/arch/x86/kernel/entry_64.S
16910 @@ -59,6 +59,8 @@
16911 #include <asm/rcu.h>
16912 #include <asm/smap.h>
16913 #include <linux/err.h>
16914 +#include <asm/pgtable.h>
16915 +#include <asm/alternative-asm.h>
16916
16917 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16918 #include <linux/elf-em.h>
16919 @@ -80,8 +82,9 @@
16920 #ifdef CONFIG_DYNAMIC_FTRACE
16921
16922 ENTRY(function_hook)
16923 + pax_force_retaddr
16924 retq
16925 -END(function_hook)
16926 +ENDPROC(function_hook)
16927
16928 /* skip is set if stack has been adjusted */
16929 .macro ftrace_caller_setup skip=0
16930 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16931 #endif
16932
16933 GLOBAL(ftrace_stub)
16934 + pax_force_retaddr
16935 retq
16936 -END(ftrace_caller)
16937 +ENDPROC(ftrace_caller)
16938
16939 ENTRY(ftrace_regs_caller)
16940 /* Save the current flags before compare (in SS location)*/
16941 @@ -191,7 +195,7 @@ ftrace_restore_flags:
16942 popfq
16943 jmp ftrace_stub
16944
16945 -END(ftrace_regs_caller)
16946 +ENDPROC(ftrace_regs_caller)
16947
16948
16949 #else /* ! CONFIG_DYNAMIC_FTRACE */
16950 @@ -212,6 +216,7 @@ ENTRY(function_hook)
16951 #endif
16952
16953 GLOBAL(ftrace_stub)
16954 + pax_force_retaddr
16955 retq
16956
16957 trace:
16958 @@ -225,12 +230,13 @@ trace:
16959 #endif
16960 subq $MCOUNT_INSN_SIZE, %rdi
16961
16962 + pax_force_fptr ftrace_trace_function
16963 call *ftrace_trace_function
16964
16965 MCOUNT_RESTORE_FRAME
16966
16967 jmp ftrace_stub
16968 -END(function_hook)
16969 +ENDPROC(function_hook)
16970 #endif /* CONFIG_DYNAMIC_FTRACE */
16971 #endif /* CONFIG_FUNCTION_TRACER */
16972
16973 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
16974
16975 MCOUNT_RESTORE_FRAME
16976
16977 + pax_force_retaddr
16978 retq
16979 -END(ftrace_graph_caller)
16980 +ENDPROC(ftrace_graph_caller)
16981
16982 GLOBAL(return_to_handler)
16983 subq $24, %rsp
16984 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
16985 movq 8(%rsp), %rdx
16986 movq (%rsp), %rax
16987 addq $24, %rsp
16988 + pax_force_fptr %rdi
16989 jmp *%rdi
16990 +ENDPROC(return_to_handler)
16991 #endif
16992
16993
16994 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
16995 ENDPROC(native_usergs_sysret64)
16996 #endif /* CONFIG_PARAVIRT */
16997
16998 + .macro ljmpq sel, off
16999 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17000 + .byte 0x48; ljmp *1234f(%rip)
17001 + .pushsection .rodata
17002 + .align 16
17003 + 1234: .quad \off; .word \sel
17004 + .popsection
17005 +#else
17006 + pushq $\sel
17007 + pushq $\off
17008 + lretq
17009 +#endif
17010 + .endm
17011 +
17012 + .macro pax_enter_kernel
17013 + pax_set_fptr_mask
17014 +#ifdef CONFIG_PAX_KERNEXEC
17015 + call pax_enter_kernel
17016 +#endif
17017 + .endm
17018 +
17019 + .macro pax_exit_kernel
17020 +#ifdef CONFIG_PAX_KERNEXEC
17021 + call pax_exit_kernel
17022 +#endif
17023 + .endm
17024 +
17025 +#ifdef CONFIG_PAX_KERNEXEC
17026 +ENTRY(pax_enter_kernel)
17027 + pushq %rdi
17028 +
17029 +#ifdef CONFIG_PARAVIRT
17030 + PV_SAVE_REGS(CLBR_RDI)
17031 +#endif
17032 +
17033 + GET_CR0_INTO_RDI
17034 + bts $16,%rdi
17035 + jnc 3f
17036 + mov %cs,%edi
17037 + cmp $__KERNEL_CS,%edi
17038 + jnz 2f
17039 +1:
17040 +
17041 +#ifdef CONFIG_PARAVIRT
17042 + PV_RESTORE_REGS(CLBR_RDI)
17043 +#endif
17044 +
17045 + popq %rdi
17046 + pax_force_retaddr
17047 + retq
17048 +
17049 +2: ljmpq __KERNEL_CS,1f
17050 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
17051 +4: SET_RDI_INTO_CR0
17052 + jmp 1b
17053 +ENDPROC(pax_enter_kernel)
17054 +
17055 +ENTRY(pax_exit_kernel)
17056 + pushq %rdi
17057 +
17058 +#ifdef CONFIG_PARAVIRT
17059 + PV_SAVE_REGS(CLBR_RDI)
17060 +#endif
17061 +
17062 + mov %cs,%rdi
17063 + cmp $__KERNEXEC_KERNEL_CS,%edi
17064 + jz 2f
17065 +1:
17066 +
17067 +#ifdef CONFIG_PARAVIRT
17068 + PV_RESTORE_REGS(CLBR_RDI);
17069 +#endif
17070 +
17071 + popq %rdi
17072 + pax_force_retaddr
17073 + retq
17074 +
17075 +2: GET_CR0_INTO_RDI
17076 + btr $16,%rdi
17077 + ljmpq __KERNEL_CS,3f
17078 +3: SET_RDI_INTO_CR0
17079 + jmp 1b
17080 +ENDPROC(pax_exit_kernel)
17081 +#endif
17082 +
17083 + .macro pax_enter_kernel_user
17084 + pax_set_fptr_mask
17085 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17086 + call pax_enter_kernel_user
17087 +#endif
17088 + .endm
17089 +
17090 + .macro pax_exit_kernel_user
17091 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17092 + call pax_exit_kernel_user
17093 +#endif
17094 +#ifdef CONFIG_PAX_RANDKSTACK
17095 + pushq %rax
17096 + call pax_randomize_kstack
17097 + popq %rax
17098 +#endif
17099 + .endm
17100 +
17101 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17102 +ENTRY(pax_enter_kernel_user)
17103 + pushq %rdi
17104 + pushq %rbx
17105 +
17106 +#ifdef CONFIG_PARAVIRT
17107 + PV_SAVE_REGS(CLBR_RDI)
17108 +#endif
17109 +
17110 + GET_CR3_INTO_RDI
17111 + mov %rdi,%rbx
17112 + add $__START_KERNEL_map,%rbx
17113 + sub phys_base(%rip),%rbx
17114 +
17115 +#ifdef CONFIG_PARAVIRT
17116 + pushq %rdi
17117 + cmpl $0, pv_info+PARAVIRT_enabled
17118 + jz 1f
17119 + i = 0
17120 + .rept USER_PGD_PTRS
17121 + mov i*8(%rbx),%rsi
17122 + mov $0,%sil
17123 + lea i*8(%rbx),%rdi
17124 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17125 + i = i + 1
17126 + .endr
17127 + jmp 2f
17128 +1:
17129 +#endif
17130 +
17131 + i = 0
17132 + .rept USER_PGD_PTRS
17133 + movb $0,i*8(%rbx)
17134 + i = i + 1
17135 + .endr
17136 +
17137 +#ifdef CONFIG_PARAVIRT
17138 +2: popq %rdi
17139 +#endif
17140 + SET_RDI_INTO_CR3
17141 +
17142 +#ifdef CONFIG_PAX_KERNEXEC
17143 + GET_CR0_INTO_RDI
17144 + bts $16,%rdi
17145 + SET_RDI_INTO_CR0
17146 +#endif
17147 +
17148 +#ifdef CONFIG_PARAVIRT
17149 + PV_RESTORE_REGS(CLBR_RDI)
17150 +#endif
17151 +
17152 + popq %rbx
17153 + popq %rdi
17154 + pax_force_retaddr
17155 + retq
17156 +ENDPROC(pax_enter_kernel_user)
17157 +
17158 +ENTRY(pax_exit_kernel_user)
17159 + push %rdi
17160 +
17161 +#ifdef CONFIG_PARAVIRT
17162 + pushq %rbx
17163 + PV_SAVE_REGS(CLBR_RDI)
17164 +#endif
17165 +
17166 +#ifdef CONFIG_PAX_KERNEXEC
17167 + GET_CR0_INTO_RDI
17168 + btr $16,%rdi
17169 + SET_RDI_INTO_CR0
17170 +#endif
17171 +
17172 + GET_CR3_INTO_RDI
17173 + add $__START_KERNEL_map,%rdi
17174 + sub phys_base(%rip),%rdi
17175 +
17176 +#ifdef CONFIG_PARAVIRT
17177 + cmpl $0, pv_info+PARAVIRT_enabled
17178 + jz 1f
17179 + mov %rdi,%rbx
17180 + i = 0
17181 + .rept USER_PGD_PTRS
17182 + mov i*8(%rbx),%rsi
17183 + mov $0x67,%sil
17184 + lea i*8(%rbx),%rdi
17185 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17186 + i = i + 1
17187 + .endr
17188 + jmp 2f
17189 +1:
17190 +#endif
17191 +
17192 + i = 0
17193 + .rept USER_PGD_PTRS
17194 + movb $0x67,i*8(%rdi)
17195 + i = i + 1
17196 + .endr
17197 +
17198 +#ifdef CONFIG_PARAVIRT
17199 +2: PV_RESTORE_REGS(CLBR_RDI)
17200 + popq %rbx
17201 +#endif
17202 +
17203 + popq %rdi
17204 + pax_force_retaddr
17205 + retq
17206 +ENDPROC(pax_exit_kernel_user)
17207 +#endif
17208 +
17209 +.macro pax_erase_kstack
17210 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17211 + call pax_erase_kstack
17212 +#endif
17213 +.endm
17214 +
17215 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17216 +ENTRY(pax_erase_kstack)
17217 + pushq %rdi
17218 + pushq %rcx
17219 + pushq %rax
17220 + pushq %r11
17221 +
17222 + GET_THREAD_INFO(%r11)
17223 + mov TI_lowest_stack(%r11), %rdi
17224 + mov $-0xBEEF, %rax
17225 + std
17226 +
17227 +1: mov %edi, %ecx
17228 + and $THREAD_SIZE_asm - 1, %ecx
17229 + shr $3, %ecx
17230 + repne scasq
17231 + jecxz 2f
17232 +
17233 + cmp $2*8, %ecx
17234 + jc 2f
17235 +
17236 + mov $2*8, %ecx
17237 + repe scasq
17238 + jecxz 2f
17239 + jne 1b
17240 +
17241 +2: cld
17242 + mov %esp, %ecx
17243 + sub %edi, %ecx
17244 +
17245 + cmp $THREAD_SIZE_asm, %rcx
17246 + jb 3f
17247 + ud2
17248 +3:
17249 +
17250 + shr $3, %ecx
17251 + rep stosq
17252 +
17253 + mov TI_task_thread_sp0(%r11), %rdi
17254 + sub $256, %rdi
17255 + mov %rdi, TI_lowest_stack(%r11)
17256 +
17257 + popq %r11
17258 + popq %rax
17259 + popq %rcx
17260 + popq %rdi
17261 + pax_force_retaddr
17262 + ret
17263 +ENDPROC(pax_erase_kstack)
17264 +#endif
17265
17266 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17267 #ifdef CONFIG_TRACE_IRQFLAGS
17268 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17269 .endm
17270
17271 .macro UNFAKE_STACK_FRAME
17272 - addq $8*6, %rsp
17273 - CFI_ADJUST_CFA_OFFSET -(6*8)
17274 + addq $8*6 + ARG_SKIP, %rsp
17275 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17276 .endm
17277
17278 /*
17279 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17280 movq %rsp, %rsi
17281
17282 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17283 - testl $3, CS-RBP(%rsi)
17284 + testb $3, CS-RBP(%rsi)
17285 je 1f
17286 SWAPGS
17287 /*
17288 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17289 movq_cfi r15, R15+16
17290 movq %r11, 8(%rsp) /* return address */
17291 FIXUP_TOP_OF_STACK %r11, 16
17292 + pax_force_retaddr
17293 ret
17294 CFI_ENDPROC
17295 -END(save_rest)
17296 +ENDPROC(save_rest)
17297
17298 /* save complete stack frame */
17299 .pushsection .kprobes.text, "ax"
17300 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17301 js 1f /* negative -> in kernel */
17302 SWAPGS
17303 xorl %ebx,%ebx
17304 -1: ret
17305 +1: pax_force_retaddr_bts
17306 + ret
17307 CFI_ENDPROC
17308 -END(save_paranoid)
17309 +ENDPROC(save_paranoid)
17310 .popsection
17311
17312 /*
17313 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17314
17315 RESTORE_REST
17316
17317 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17318 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17319 jz 1f
17320
17321 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17322 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17323 RESTORE_REST
17324 jmp int_ret_from_sys_call
17325 CFI_ENDPROC
17326 -END(ret_from_fork)
17327 +ENDPROC(ret_from_fork)
17328
17329 /*
17330 * System call entry. Up to 6 arguments in registers are supported.
17331 @@ -608,7 +886,7 @@ END(ret_from_fork)
17332 ENTRY(system_call)
17333 CFI_STARTPROC simple
17334 CFI_SIGNAL_FRAME
17335 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17336 + CFI_DEF_CFA rsp,0
17337 CFI_REGISTER rip,rcx
17338 /*CFI_REGISTER rflags,r11*/
17339 SWAPGS_UNSAFE_STACK
17340 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17341
17342 movq %rsp,PER_CPU_VAR(old_rsp)
17343 movq PER_CPU_VAR(kernel_stack),%rsp
17344 + SAVE_ARGS 8*6,0
17345 + pax_enter_kernel_user
17346 +
17347 +#ifdef CONFIG_PAX_RANDKSTACK
17348 + pax_erase_kstack
17349 +#endif
17350 +
17351 /*
17352 * No need to follow this irqs off/on section - it's straight
17353 * and short:
17354 */
17355 ENABLE_INTERRUPTS(CLBR_NONE)
17356 - SAVE_ARGS 8,0
17357 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17358 movq %rcx,RIP-ARGOFFSET(%rsp)
17359 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17360 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17361 + GET_THREAD_INFO(%rcx)
17362 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17363 jnz tracesys
17364 system_call_fastpath:
17365 #if __SYSCALL_MASK == ~0
17366 @@ -640,7 +925,7 @@ system_call_fastpath:
17367 cmpl $__NR_syscall_max,%eax
17368 #endif
17369 ja badsys
17370 - movq %r10,%rcx
17371 + movq R10-ARGOFFSET(%rsp),%rcx
17372 call *sys_call_table(,%rax,8) # XXX: rip relative
17373 movq %rax,RAX-ARGOFFSET(%rsp)
17374 /*
17375 @@ -654,10 +939,13 @@ sysret_check:
17376 LOCKDEP_SYS_EXIT
17377 DISABLE_INTERRUPTS(CLBR_NONE)
17378 TRACE_IRQS_OFF
17379 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17380 + GET_THREAD_INFO(%rcx)
17381 + movl TI_flags(%rcx),%edx
17382 andl %edi,%edx
17383 jnz sysret_careful
17384 CFI_REMEMBER_STATE
17385 + pax_exit_kernel_user
17386 + pax_erase_kstack
17387 /*
17388 * sysretq will re-enable interrupts:
17389 */
17390 @@ -709,14 +997,18 @@ badsys:
17391 * jump back to the normal fast path.
17392 */
17393 auditsys:
17394 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17395 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17396 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17397 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17398 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17399 movq %rax,%rsi /* 2nd arg: syscall number */
17400 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17401 call __audit_syscall_entry
17402 +
17403 + pax_erase_kstack
17404 +
17405 LOAD_ARGS 0 /* reload call-clobbered registers */
17406 + pax_set_fptr_mask
17407 jmp system_call_fastpath
17408
17409 /*
17410 @@ -737,7 +1029,7 @@ sysret_audit:
17411 /* Do syscall tracing */
17412 tracesys:
17413 #ifdef CONFIG_AUDITSYSCALL
17414 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17415 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17416 jz auditsys
17417 #endif
17418 SAVE_REST
17419 @@ -745,12 +1037,16 @@ tracesys:
17420 FIXUP_TOP_OF_STACK %rdi
17421 movq %rsp,%rdi
17422 call syscall_trace_enter
17423 +
17424 + pax_erase_kstack
17425 +
17426 /*
17427 * Reload arg registers from stack in case ptrace changed them.
17428 * We don't reload %rax because syscall_trace_enter() returned
17429 * the value it wants us to use in the table lookup.
17430 */
17431 LOAD_ARGS ARGOFFSET, 1
17432 + pax_set_fptr_mask
17433 RESTORE_REST
17434 #if __SYSCALL_MASK == ~0
17435 cmpq $__NR_syscall_max,%rax
17436 @@ -759,7 +1055,7 @@ tracesys:
17437 cmpl $__NR_syscall_max,%eax
17438 #endif
17439 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17440 - movq %r10,%rcx /* fixup for C */
17441 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17442 call *sys_call_table(,%rax,8)
17443 movq %rax,RAX-ARGOFFSET(%rsp)
17444 /* Use IRET because user could have changed frame */
17445 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17446 andl %edi,%edx
17447 jnz int_careful
17448 andl $~TS_COMPAT,TI_status(%rcx)
17449 - jmp retint_swapgs
17450 + pax_exit_kernel_user
17451 + pax_erase_kstack
17452 + jmp retint_swapgs_pax
17453
17454 /* Either reschedule or signal or syscall exit tracking needed. */
17455 /* First do a reschedule test. */
17456 @@ -826,7 +1124,7 @@ int_restore_rest:
17457 TRACE_IRQS_OFF
17458 jmp int_with_check
17459 CFI_ENDPROC
17460 -END(system_call)
17461 +ENDPROC(system_call)
17462
17463 /*
17464 * Certain special system calls that need to save a complete full stack frame.
17465 @@ -842,7 +1140,7 @@ ENTRY(\label)
17466 call \func
17467 jmp ptregscall_common
17468 CFI_ENDPROC
17469 -END(\label)
17470 +ENDPROC(\label)
17471 .endm
17472
17473 PTREGSCALL stub_clone, sys_clone, %r8
17474 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17475 movq_cfi_restore R12+8, r12
17476 movq_cfi_restore RBP+8, rbp
17477 movq_cfi_restore RBX+8, rbx
17478 + pax_force_retaddr
17479 ret $REST_SKIP /* pop extended registers */
17480 CFI_ENDPROC
17481 -END(ptregscall_common)
17482 +ENDPROC(ptregscall_common)
17483
17484 ENTRY(stub_execve)
17485 CFI_STARTPROC
17486 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17487 RESTORE_REST
17488 jmp int_ret_from_sys_call
17489 CFI_ENDPROC
17490 -END(stub_execve)
17491 +ENDPROC(stub_execve)
17492
17493 /*
17494 * sigreturn is special because it needs to restore all registers on return.
17495 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17496 RESTORE_REST
17497 jmp int_ret_from_sys_call
17498 CFI_ENDPROC
17499 -END(stub_rt_sigreturn)
17500 +ENDPROC(stub_rt_sigreturn)
17501
17502 #ifdef CONFIG_X86_X32_ABI
17503 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17504 @@ -962,7 +1261,7 @@ vector=vector+1
17505 2: jmp common_interrupt
17506 .endr
17507 CFI_ENDPROC
17508 -END(irq_entries_start)
17509 +ENDPROC(irq_entries_start)
17510
17511 .previous
17512 END(interrupt)
17513 @@ -982,6 +1281,16 @@ END(interrupt)
17514 subq $ORIG_RAX-RBP, %rsp
17515 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17516 SAVE_ARGS_IRQ
17517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17518 + testb $3, CS(%rdi)
17519 + jnz 1f
17520 + pax_enter_kernel
17521 + jmp 2f
17522 +1: pax_enter_kernel_user
17523 +2:
17524 +#else
17525 + pax_enter_kernel
17526 +#endif
17527 call \func
17528 .endm
17529
17530 @@ -1014,7 +1323,7 @@ ret_from_intr:
17531
17532 exit_intr:
17533 GET_THREAD_INFO(%rcx)
17534 - testl $3,CS-ARGOFFSET(%rsp)
17535 + testb $3,CS-ARGOFFSET(%rsp)
17536 je retint_kernel
17537
17538 /* Interrupt came from user space */
17539 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17540 * The iretq could re-enable interrupts:
17541 */
17542 DISABLE_INTERRUPTS(CLBR_ANY)
17543 + pax_exit_kernel_user
17544 +retint_swapgs_pax:
17545 TRACE_IRQS_IRETQ
17546 SWAPGS
17547 jmp restore_args
17548
17549 retint_restore_args: /* return to kernel space */
17550 DISABLE_INTERRUPTS(CLBR_ANY)
17551 + pax_exit_kernel
17552 + pax_force_retaddr (RIP-ARGOFFSET)
17553 /*
17554 * The iretq could re-enable interrupts:
17555 */
17556 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17557 #endif
17558
17559 CFI_ENDPROC
17560 -END(common_interrupt)
17561 +ENDPROC(common_interrupt)
17562 /*
17563 * End of kprobes section
17564 */
17565 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17566 interrupt \do_sym
17567 jmp ret_from_intr
17568 CFI_ENDPROC
17569 -END(\sym)
17570 +ENDPROC(\sym)
17571 .endm
17572
17573 #ifdef CONFIG_SMP
17574 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17575 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17576 call error_entry
17577 DEFAULT_FRAME 0
17578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17579 + testb $3, CS(%rsp)
17580 + jnz 1f
17581 + pax_enter_kernel
17582 + jmp 2f
17583 +1: pax_enter_kernel_user
17584 +2:
17585 +#else
17586 + pax_enter_kernel
17587 +#endif
17588 movq %rsp,%rdi /* pt_regs pointer */
17589 xorl %esi,%esi /* no error code */
17590 call \do_sym
17591 jmp error_exit /* %ebx: no swapgs flag */
17592 CFI_ENDPROC
17593 -END(\sym)
17594 +ENDPROC(\sym)
17595 .endm
17596
17597 .macro paranoidzeroentry sym do_sym
17598 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17599 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17600 call save_paranoid
17601 TRACE_IRQS_OFF
17602 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17603 + testb $3, CS(%rsp)
17604 + jnz 1f
17605 + pax_enter_kernel
17606 + jmp 2f
17607 +1: pax_enter_kernel_user
17608 +2:
17609 +#else
17610 + pax_enter_kernel
17611 +#endif
17612 movq %rsp,%rdi /* pt_regs pointer */
17613 xorl %esi,%esi /* no error code */
17614 call \do_sym
17615 jmp paranoid_exit /* %ebx: no swapgs flag */
17616 CFI_ENDPROC
17617 -END(\sym)
17618 +ENDPROC(\sym)
17619 .endm
17620
17621 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17622 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17623 .macro paranoidzeroentry_ist sym do_sym ist
17624 ENTRY(\sym)
17625 INTR_FRAME
17626 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17627 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17628 call save_paranoid
17629 TRACE_IRQS_OFF_DEBUG
17630 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17631 + testb $3, CS(%rsp)
17632 + jnz 1f
17633 + pax_enter_kernel
17634 + jmp 2f
17635 +1: pax_enter_kernel_user
17636 +2:
17637 +#else
17638 + pax_enter_kernel
17639 +#endif
17640 movq %rsp,%rdi /* pt_regs pointer */
17641 xorl %esi,%esi /* no error code */
17642 +#ifdef CONFIG_SMP
17643 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17644 + lea init_tss(%r12), %r12
17645 +#else
17646 + lea init_tss(%rip), %r12
17647 +#endif
17648 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17649 call \do_sym
17650 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17651 jmp paranoid_exit /* %ebx: no swapgs flag */
17652 CFI_ENDPROC
17653 -END(\sym)
17654 +ENDPROC(\sym)
17655 .endm
17656
17657 .macro errorentry sym do_sym
17658 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17659 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17660 call error_entry
17661 DEFAULT_FRAME 0
17662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17663 + testb $3, CS(%rsp)
17664 + jnz 1f
17665 + pax_enter_kernel
17666 + jmp 2f
17667 +1: pax_enter_kernel_user
17668 +2:
17669 +#else
17670 + pax_enter_kernel
17671 +#endif
17672 movq %rsp,%rdi /* pt_regs pointer */
17673 movq ORIG_RAX(%rsp),%rsi /* get error code */
17674 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17675 call \do_sym
17676 jmp error_exit /* %ebx: no swapgs flag */
17677 CFI_ENDPROC
17678 -END(\sym)
17679 +ENDPROC(\sym)
17680 .endm
17681
17682 /* error code is on the stack already */
17683 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17684 call save_paranoid
17685 DEFAULT_FRAME 0
17686 TRACE_IRQS_OFF
17687 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17688 + testb $3, CS(%rsp)
17689 + jnz 1f
17690 + pax_enter_kernel
17691 + jmp 2f
17692 +1: pax_enter_kernel_user
17693 +2:
17694 +#else
17695 + pax_enter_kernel
17696 +#endif
17697 movq %rsp,%rdi /* pt_regs pointer */
17698 movq ORIG_RAX(%rsp),%rsi /* get error code */
17699 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17700 call \do_sym
17701 jmp paranoid_exit /* %ebx: no swapgs flag */
17702 CFI_ENDPROC
17703 -END(\sym)
17704 +ENDPROC(\sym)
17705 .endm
17706
17707 zeroentry divide_error do_divide_error
17708 @@ -1310,9 +1679,10 @@ gs_change:
17709 2: mfence /* workaround */
17710 SWAPGS
17711 popfq_cfi
17712 + pax_force_retaddr
17713 ret
17714 CFI_ENDPROC
17715 -END(native_load_gs_index)
17716 +ENDPROC(native_load_gs_index)
17717
17718 _ASM_EXTABLE(gs_change,bad_gs)
17719 .section .fixup,"ax"
17720 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17721 CFI_DEF_CFA_REGISTER rsp
17722 CFI_ADJUST_CFA_OFFSET -8
17723 decl PER_CPU_VAR(irq_count)
17724 + pax_force_retaddr
17725 ret
17726 CFI_ENDPROC
17727 -END(call_softirq)
17728 +ENDPROC(call_softirq)
17729
17730 #ifdef CONFIG_XEN
17731 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17732 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17733 decl PER_CPU_VAR(irq_count)
17734 jmp error_exit
17735 CFI_ENDPROC
17736 -END(xen_do_hypervisor_callback)
17737 +ENDPROC(xen_do_hypervisor_callback)
17738
17739 /*
17740 * Hypervisor uses this for application faults while it executes.
17741 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17742 SAVE_ALL
17743 jmp error_exit
17744 CFI_ENDPROC
17745 -END(xen_failsafe_callback)
17746 +ENDPROC(xen_failsafe_callback)
17747
17748 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17749 xen_hvm_callback_vector xen_evtchn_do_upcall
17750 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17751 TRACE_IRQS_OFF_DEBUG
17752 testl %ebx,%ebx /* swapgs needed? */
17753 jnz paranoid_restore
17754 - testl $3,CS(%rsp)
17755 + testb $3,CS(%rsp)
17756 jnz paranoid_userspace
17757 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17758 + pax_exit_kernel
17759 + TRACE_IRQS_IRETQ 0
17760 + SWAPGS_UNSAFE_STACK
17761 + RESTORE_ALL 8
17762 + pax_force_retaddr_bts
17763 + jmp irq_return
17764 +#endif
17765 paranoid_swapgs:
17766 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17767 + pax_exit_kernel_user
17768 +#else
17769 + pax_exit_kernel
17770 +#endif
17771 TRACE_IRQS_IRETQ 0
17772 SWAPGS_UNSAFE_STACK
17773 RESTORE_ALL 8
17774 jmp irq_return
17775 paranoid_restore:
17776 + pax_exit_kernel
17777 TRACE_IRQS_IRETQ_DEBUG 0
17778 RESTORE_ALL 8
17779 + pax_force_retaddr_bts
17780 jmp irq_return
17781 paranoid_userspace:
17782 GET_THREAD_INFO(%rcx)
17783 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17784 TRACE_IRQS_OFF
17785 jmp paranoid_userspace
17786 CFI_ENDPROC
17787 -END(paranoid_exit)
17788 +ENDPROC(paranoid_exit)
17789
17790 /*
17791 * Exception entry point. This expects an error code/orig_rax on the stack.
17792 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17793 movq_cfi r14, R14+8
17794 movq_cfi r15, R15+8
17795 xorl %ebx,%ebx
17796 - testl $3,CS+8(%rsp)
17797 + testb $3,CS+8(%rsp)
17798 je error_kernelspace
17799 error_swapgs:
17800 SWAPGS
17801 error_sti:
17802 TRACE_IRQS_OFF
17803 + pax_force_retaddr_bts
17804 ret
17805
17806 /*
17807 @@ -1585,7 +1972,7 @@ bstep_iret:
17808 movq %rcx,RIP+8(%rsp)
17809 jmp error_swapgs
17810 CFI_ENDPROC
17811 -END(error_entry)
17812 +ENDPROC(error_entry)
17813
17814
17815 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17816 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17817 jnz retint_careful
17818 jmp retint_swapgs
17819 CFI_ENDPROC
17820 -END(error_exit)
17821 +ENDPROC(error_exit)
17822
17823 /*
17824 * Test if a given stack is an NMI stack or not.
17825 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17826 * If %cs was not the kernel segment, then the NMI triggered in user
17827 * space, which means it is definitely not nested.
17828 */
17829 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17830 + je 1f
17831 cmpl $__KERNEL_CS, 16(%rsp)
17832 jne first_nmi
17833 -
17834 +1:
17835 /*
17836 * Check the special variable on the stack to see if NMIs are
17837 * executing.
17838 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
17839 */
17840 movq %cr2, %r12
17841
17842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17843 + testb $3, CS(%rsp)
17844 + jnz 1f
17845 + pax_enter_kernel
17846 + jmp 2f
17847 +1: pax_enter_kernel_user
17848 +2:
17849 +#else
17850 + pax_enter_kernel
17851 +#endif
17852 +
17853 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17854 movq %rsp,%rdi
17855 movq $-1,%rsi
17856 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
17857 testl %ebx,%ebx /* swapgs needed? */
17858 jnz nmi_restore
17859 nmi_swapgs:
17860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17861 + pax_exit_kernel_user
17862 +#else
17863 + pax_exit_kernel
17864 +#endif
17865 SWAPGS_UNSAFE_STACK
17866 + RESTORE_ALL 8
17867 + /* Clear the NMI executing stack variable */
17868 + movq $0, 10*8(%rsp)
17869 + jmp irq_return
17870 nmi_restore:
17871 + pax_exit_kernel
17872 RESTORE_ALL 8
17873 + pax_force_retaddr_bts
17874 /* Clear the NMI executing stack variable */
17875 movq $0, 10*8(%rsp)
17876 jmp irq_return
17877 CFI_ENDPROC
17878 -END(nmi)
17879 +ENDPROC(nmi)
17880
17881 ENTRY(ignore_sysret)
17882 CFI_STARTPROC
17883 mov $-ENOSYS,%eax
17884 sysret
17885 CFI_ENDPROC
17886 -END(ignore_sysret)
17887 +ENDPROC(ignore_sysret)
17888
17889 /*
17890 * End of kprobes section
17891 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17892 index 1d41402..af9a46a 100644
17893 --- a/arch/x86/kernel/ftrace.c
17894 +++ b/arch/x86/kernel/ftrace.c
17895 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17896 {
17897 unsigned char replaced[MCOUNT_INSN_SIZE];
17898
17899 + ip = ktla_ktva(ip);
17900 +
17901 /*
17902 * Note: Due to modules and __init, code can
17903 * disappear and change, we need to protect against faulting
17904 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17905 unsigned char old[MCOUNT_INSN_SIZE], *new;
17906 int ret;
17907
17908 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17909 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17910 new = ftrace_call_replace(ip, (unsigned long)func);
17911
17912 /* See comment above by declaration of modifying_ftrace_code */
17913 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17914 /* Also update the regs callback function */
17915 if (!ret) {
17916 ip = (unsigned long)(&ftrace_regs_call);
17917 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17918 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17919 new = ftrace_call_replace(ip, (unsigned long)func);
17920 ret = ftrace_modify_code(ip, old, new);
17921 }
17922 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17923 * kernel identity mapping to modify code.
17924 */
17925 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17926 - ip = (unsigned long)__va(__pa(ip));
17927 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17928
17929 return probe_kernel_write((void *)ip, val, size);
17930 }
17931 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17932 unsigned char replaced[MCOUNT_INSN_SIZE];
17933 unsigned char brk = BREAKPOINT_INSTRUCTION;
17934
17935 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17936 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17937 return -EFAULT;
17938
17939 /* Make sure it is what we expect it to be */
17940 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
17941 return ret;
17942
17943 fail_update:
17944 - probe_kernel_write((void *)ip, &old_code[0], 1);
17945 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
17946 goto out;
17947 }
17948
17949 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
17950 {
17951 unsigned char code[MCOUNT_INSN_SIZE];
17952
17953 + ip = ktla_ktva(ip);
17954 +
17955 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
17956 return -EFAULT;
17957
17958 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
17959 index c18f59d..69ddbc4 100644
17960 --- a/arch/x86/kernel/head32.c
17961 +++ b/arch/x86/kernel/head32.c
17962 @@ -18,20 +18,20 @@
17963 #include <asm/io_apic.h>
17964 #include <asm/bios_ebda.h>
17965 #include <asm/tlbflush.h>
17966 +#include <asm/boot.h>
17967
17968 static void __init i386_default_early_setup(void)
17969 {
17970 /* Initialize 32bit specific setup functions */
17971 - x86_init.resources.reserve_resources = i386_reserve_resources;
17972 - x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
17973 + *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
17974 + *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
17975
17976 reserve_ebda_region();
17977 }
17978
17979 void __init i386_start_kernel(void)
17980 {
17981 - memblock_reserve(__pa_symbol(&_text),
17982 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
17983 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
17984
17985 #ifdef CONFIG_BLK_DEV_INITRD
17986 /* Reserve INITRD */
17987 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
17988 index 4dac2f6..bc6a335 100644
17989 --- a/arch/x86/kernel/head_32.S
17990 +++ b/arch/x86/kernel/head_32.S
17991 @@ -26,6 +26,12 @@
17992 /* Physical address */
17993 #define pa(X) ((X) - __PAGE_OFFSET)
17994
17995 +#ifdef CONFIG_PAX_KERNEXEC
17996 +#define ta(X) (X)
17997 +#else
17998 +#define ta(X) ((X) - __PAGE_OFFSET)
17999 +#endif
18000 +
18001 /*
18002 * References to members of the new_cpu_data structure.
18003 */
18004 @@ -55,11 +61,7 @@
18005 * and small than max_low_pfn, otherwise will waste some page table entries
18006 */
18007
18008 -#if PTRS_PER_PMD > 1
18009 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18010 -#else
18011 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18012 -#endif
18013 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18014
18015 /* Number of possible pages in the lowmem region */
18016 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18017 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18018 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18019
18020 /*
18021 + * Real beginning of normal "text" segment
18022 + */
18023 +ENTRY(stext)
18024 +ENTRY(_stext)
18025 +
18026 +/*
18027 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18028 * %esi points to the real-mode code as a 32-bit pointer.
18029 * CS and DS must be 4 GB flat segments, but we don't depend on
18030 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18031 * can.
18032 */
18033 __HEAD
18034 +
18035 +#ifdef CONFIG_PAX_KERNEXEC
18036 + jmp startup_32
18037 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18038 +.fill PAGE_SIZE-5,1,0xcc
18039 +#endif
18040 +
18041 ENTRY(startup_32)
18042 movl pa(stack_start),%ecx
18043
18044 @@ -106,6 +121,59 @@ ENTRY(startup_32)
18045 2:
18046 leal -__PAGE_OFFSET(%ecx),%esp
18047
18048 +#ifdef CONFIG_SMP
18049 + movl $pa(cpu_gdt_table),%edi
18050 + movl $__per_cpu_load,%eax
18051 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18052 + rorl $16,%eax
18053 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18054 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18055 + movl $__per_cpu_end - 1,%eax
18056 + subl $__per_cpu_start,%eax
18057 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18058 +#endif
18059 +
18060 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18061 + movl $NR_CPUS,%ecx
18062 + movl $pa(cpu_gdt_table),%edi
18063 +1:
18064 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18065 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18066 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18067 + addl $PAGE_SIZE_asm,%edi
18068 + loop 1b
18069 +#endif
18070 +
18071 +#ifdef CONFIG_PAX_KERNEXEC
18072 + movl $pa(boot_gdt),%edi
18073 + movl $__LOAD_PHYSICAL_ADDR,%eax
18074 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18075 + rorl $16,%eax
18076 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18077 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18078 + rorl $16,%eax
18079 +
18080 + ljmp $(__BOOT_CS),$1f
18081 +1:
18082 +
18083 + movl $NR_CPUS,%ecx
18084 + movl $pa(cpu_gdt_table),%edi
18085 + addl $__PAGE_OFFSET,%eax
18086 +1:
18087 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18088 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18089 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18090 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18091 + rorl $16,%eax
18092 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18093 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18094 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18095 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18096 + rorl $16,%eax
18097 + addl $PAGE_SIZE_asm,%edi
18098 + loop 1b
18099 +#endif
18100 +
18101 /*
18102 * Clear BSS first so that there are no surprises...
18103 */
18104 @@ -196,8 +264,11 @@ ENTRY(startup_32)
18105 movl %eax, pa(max_pfn_mapped)
18106
18107 /* Do early initialization of the fixmap area */
18108 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18109 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18110 +#ifdef CONFIG_COMPAT_VDSO
18111 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18112 +#else
18113 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18114 +#endif
18115 #else /* Not PAE */
18116
18117 page_pde_offset = (__PAGE_OFFSET >> 20);
18118 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18119 movl %eax, pa(max_pfn_mapped)
18120
18121 /* Do early initialization of the fixmap area */
18122 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18123 - movl %eax,pa(initial_page_table+0xffc)
18124 +#ifdef CONFIG_COMPAT_VDSO
18125 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18126 +#else
18127 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18128 +#endif
18129 #endif
18130
18131 #ifdef CONFIG_PARAVIRT
18132 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18133 cmpl $num_subarch_entries, %eax
18134 jae bad_subarch
18135
18136 - movl pa(subarch_entries)(,%eax,4), %eax
18137 - subl $__PAGE_OFFSET, %eax
18138 - jmp *%eax
18139 + jmp *pa(subarch_entries)(,%eax,4)
18140
18141 bad_subarch:
18142 WEAK(lguest_entry)
18143 @@ -256,10 +328,10 @@ WEAK(xen_entry)
18144 __INITDATA
18145
18146 subarch_entries:
18147 - .long default_entry /* normal x86/PC */
18148 - .long lguest_entry /* lguest hypervisor */
18149 - .long xen_entry /* Xen hypervisor */
18150 - .long default_entry /* Moorestown MID */
18151 + .long ta(default_entry) /* normal x86/PC */
18152 + .long ta(lguest_entry) /* lguest hypervisor */
18153 + .long ta(xen_entry) /* Xen hypervisor */
18154 + .long ta(default_entry) /* Moorestown MID */
18155 num_subarch_entries = (. - subarch_entries) / 4
18156 .previous
18157 #else
18158 @@ -316,6 +388,7 @@ default_entry:
18159 movl pa(mmu_cr4_features),%eax
18160 movl %eax,%cr4
18161
18162 +#ifdef CONFIG_X86_PAE
18163 testb $X86_CR4_PAE, %al # check if PAE is enabled
18164 jz 6f
18165
18166 @@ -344,6 +417,9 @@ default_entry:
18167 /* Make changes effective */
18168 wrmsr
18169
18170 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18171 +#endif
18172 +
18173 6:
18174
18175 /*
18176 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18177 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18178 movl %eax,%ss # after changing gdt.
18179
18180 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
18181 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18182 movl %eax,%ds
18183 movl %eax,%es
18184
18185 movl $(__KERNEL_PERCPU), %eax
18186 movl %eax,%fs # set this cpu's percpu
18187
18188 +#ifdef CONFIG_CC_STACKPROTECTOR
18189 movl $(__KERNEL_STACK_CANARY),%eax
18190 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18191 + movl $(__USER_DS),%eax
18192 +#else
18193 + xorl %eax,%eax
18194 +#endif
18195 movl %eax,%gs
18196
18197 xorl %eax,%eax # Clear LDT
18198 @@ -526,8 +608,11 @@ setup_once:
18199 * relocation. Manually set base address in stack canary
18200 * segment descriptor.
18201 */
18202 - movl $gdt_page,%eax
18203 + movl $cpu_gdt_table,%eax
18204 movl $stack_canary,%ecx
18205 +#ifdef CONFIG_SMP
18206 + addl $__per_cpu_load,%ecx
18207 +#endif
18208 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18209 shrl $16, %ecx
18210 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18211 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18212 /* This is global to keep gas from relaxing the jumps */
18213 ENTRY(early_idt_handler)
18214 cld
18215 - cmpl $2,%ss:early_recursion_flag
18216 + cmpl $1,%ss:early_recursion_flag
18217 je hlt_loop
18218 incl %ss:early_recursion_flag
18219
18220 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18221 pushl (20+6*4)(%esp) /* trapno */
18222 pushl $fault_msg
18223 call printk
18224 -#endif
18225 call dump_stack
18226 +#endif
18227 hlt_loop:
18228 hlt
18229 jmp hlt_loop
18230 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18231 /* This is the default interrupt "handler" :-) */
18232 ALIGN
18233 ignore_int:
18234 - cld
18235 #ifdef CONFIG_PRINTK
18236 + cmpl $2,%ss:early_recursion_flag
18237 + je hlt_loop
18238 + incl %ss:early_recursion_flag
18239 + cld
18240 pushl %eax
18241 pushl %ecx
18242 pushl %edx
18243 @@ -626,9 +714,6 @@ ignore_int:
18244 movl $(__KERNEL_DS),%eax
18245 movl %eax,%ds
18246 movl %eax,%es
18247 - cmpl $2,early_recursion_flag
18248 - je hlt_loop
18249 - incl early_recursion_flag
18250 pushl 16(%esp)
18251 pushl 24(%esp)
18252 pushl 32(%esp)
18253 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18254 /*
18255 * BSS section
18256 */
18257 -__PAGE_ALIGNED_BSS
18258 - .align PAGE_SIZE
18259 #ifdef CONFIG_X86_PAE
18260 +.section .initial_pg_pmd,"a",@progbits
18261 initial_pg_pmd:
18262 .fill 1024*KPMDS,4,0
18263 #else
18264 +.section .initial_page_table,"a",@progbits
18265 ENTRY(initial_page_table)
18266 .fill 1024,4,0
18267 #endif
18268 +.section .initial_pg_fixmap,"a",@progbits
18269 initial_pg_fixmap:
18270 .fill 1024,4,0
18271 +.section .empty_zero_page,"a",@progbits
18272 ENTRY(empty_zero_page)
18273 .fill 4096,1,0
18274 +.section .swapper_pg_dir,"a",@progbits
18275 ENTRY(swapper_pg_dir)
18276 +#ifdef CONFIG_X86_PAE
18277 + .fill 4,8,0
18278 +#else
18279 .fill 1024,4,0
18280 +#endif
18281 +
18282 +/*
18283 + * The IDT has to be page-aligned to simplify the Pentium
18284 + * F0 0F bug workaround.. We have a special link segment
18285 + * for this.
18286 + */
18287 +.section .idt,"a",@progbits
18288 +ENTRY(idt_table)
18289 + .fill 256,8,0
18290
18291 /*
18292 * This starts the data section.
18293 */
18294 #ifdef CONFIG_X86_PAE
18295 -__PAGE_ALIGNED_DATA
18296 - /* Page-aligned for the benefit of paravirt? */
18297 - .align PAGE_SIZE
18298 +.section .initial_page_table,"a",@progbits
18299 ENTRY(initial_page_table)
18300 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18301 # if KPMDS == 3
18302 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18303 # error "Kernel PMDs should be 1, 2 or 3"
18304 # endif
18305 .align PAGE_SIZE /* needs to be page-sized too */
18306 +
18307 +#ifdef CONFIG_PAX_PER_CPU_PGD
18308 +ENTRY(cpu_pgd)
18309 + .rept NR_CPUS
18310 + .fill 4,8,0
18311 + .endr
18312 +#endif
18313 +
18314 #endif
18315
18316 .data
18317 .balign 4
18318 ENTRY(stack_start)
18319 - .long init_thread_union+THREAD_SIZE
18320 + .long init_thread_union+THREAD_SIZE-8
18321
18322 __INITRODATA
18323 int_msg:
18324 @@ -736,7 +843,7 @@ fault_msg:
18325 * segment size, and 32-bit linear address value:
18326 */
18327
18328 - .data
18329 +.section .rodata,"a",@progbits
18330 .globl boot_gdt_descr
18331 .globl idt_descr
18332
18333 @@ -745,7 +852,7 @@ fault_msg:
18334 .word 0 # 32 bit align gdt_desc.address
18335 boot_gdt_descr:
18336 .word __BOOT_DS+7
18337 - .long boot_gdt - __PAGE_OFFSET
18338 + .long pa(boot_gdt)
18339
18340 .word 0 # 32-bit align idt_desc.address
18341 idt_descr:
18342 @@ -756,7 +863,7 @@ idt_descr:
18343 .word 0 # 32 bit align gdt_desc.address
18344 ENTRY(early_gdt_descr)
18345 .word GDT_ENTRIES*8-1
18346 - .long gdt_page /* Overwritten for secondary CPUs */
18347 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18348
18349 /*
18350 * The boot_gdt must mirror the equivalent in setup.S and is
18351 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18352 .align L1_CACHE_BYTES
18353 ENTRY(boot_gdt)
18354 .fill GDT_ENTRY_BOOT_CS,8,0
18355 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18356 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18357 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18358 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18359 +
18360 + .align PAGE_SIZE_asm
18361 +ENTRY(cpu_gdt_table)
18362 + .rept NR_CPUS
18363 + .quad 0x0000000000000000 /* NULL descriptor */
18364 + .quad 0x0000000000000000 /* 0x0b reserved */
18365 + .quad 0x0000000000000000 /* 0x13 reserved */
18366 + .quad 0x0000000000000000 /* 0x1b reserved */
18367 +
18368 +#ifdef CONFIG_PAX_KERNEXEC
18369 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18370 +#else
18371 + .quad 0x0000000000000000 /* 0x20 unused */
18372 +#endif
18373 +
18374 + .quad 0x0000000000000000 /* 0x28 unused */
18375 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18376 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18377 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18378 + .quad 0x0000000000000000 /* 0x4b reserved */
18379 + .quad 0x0000000000000000 /* 0x53 reserved */
18380 + .quad 0x0000000000000000 /* 0x5b reserved */
18381 +
18382 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18383 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18384 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18385 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18386 +
18387 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18388 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18389 +
18390 + /*
18391 + * Segments used for calling PnP BIOS have byte granularity.
18392 + * The code segments and data segments have fixed 64k limits,
18393 + * the transfer segment sizes are set at run time.
18394 + */
18395 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18396 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18397 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18398 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18399 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18400 +
18401 + /*
18402 + * The APM segments have byte granularity and their bases
18403 + * are set at run time. All have 64k limits.
18404 + */
18405 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18406 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18407 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18408 +
18409 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18410 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18411 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18412 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18413 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18414 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18415 +
18416 + /* Be sure this is zeroed to avoid false validations in Xen */
18417 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18418 + .endr
18419 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18420 index 94bf9cc..400455a 100644
18421 --- a/arch/x86/kernel/head_64.S
18422 +++ b/arch/x86/kernel/head_64.S
18423 @@ -20,6 +20,8 @@
18424 #include <asm/processor-flags.h>
18425 #include <asm/percpu.h>
18426 #include <asm/nops.h>
18427 +#include <asm/cpufeature.h>
18428 +#include <asm/alternative-asm.h>
18429
18430 #ifdef CONFIG_PARAVIRT
18431 #include <asm/asm-offsets.h>
18432 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18433 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18434 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18435 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18436 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18437 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18438 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18439 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18440 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18441 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18442
18443 .text
18444 __HEAD
18445 @@ -88,35 +96,23 @@ startup_64:
18446 */
18447 addq %rbp, init_level4_pgt + 0(%rip)
18448 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18449 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18450 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18451 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18452 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18453
18454 addq %rbp, level3_ident_pgt + 0(%rip)
18455 +#ifndef CONFIG_XEN
18456 + addq %rbp, level3_ident_pgt + 8(%rip)
18457 +#endif
18458
18459 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18460 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18461 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18462 +
18463 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18464 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18465
18466 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18467 -
18468 - /* Add an Identity mapping if I am above 1G */
18469 - leaq _text(%rip), %rdi
18470 - andq $PMD_PAGE_MASK, %rdi
18471 -
18472 - movq %rdi, %rax
18473 - shrq $PUD_SHIFT, %rax
18474 - andq $(PTRS_PER_PUD - 1), %rax
18475 - jz ident_complete
18476 -
18477 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18478 - leaq level3_ident_pgt(%rip), %rbx
18479 - movq %rdx, 0(%rbx, %rax, 8)
18480 -
18481 - movq %rdi, %rax
18482 - shrq $PMD_SHIFT, %rax
18483 - andq $(PTRS_PER_PMD - 1), %rax
18484 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18485 - leaq level2_spare_pgt(%rip), %rbx
18486 - movq %rdx, 0(%rbx, %rax, 8)
18487 -ident_complete:
18488 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18489
18490 /*
18491 * Fixup the kernel text+data virtual addresses. Note that
18492 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18493 * after the boot processor executes this code.
18494 */
18495
18496 - /* Enable PAE mode and PGE */
18497 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18498 + /* Enable PAE mode and PSE/PGE */
18499 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18500 movq %rax, %cr4
18501
18502 /* Setup early boot stage 4 level pagetables. */
18503 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18504 movl $MSR_EFER, %ecx
18505 rdmsr
18506 btsl $_EFER_SCE, %eax /* Enable System Call */
18507 - btl $20,%edi /* No Execute supported? */
18508 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18509 jnc 1f
18510 btsl $_EFER_NX, %eax
18511 + leaq init_level4_pgt(%rip), %rdi
18512 +#ifndef CONFIG_EFI
18513 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18514 +#endif
18515 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18516 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18517 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18518 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18519 1: wrmsr /* Make changes effective */
18520
18521 /* Setup cr0 */
18522 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18523 * jump. In addition we need to ensure %cs is set so we make this
18524 * a far return.
18525 */
18526 + pax_set_fptr_mask
18527 movq initial_code(%rip),%rax
18528 pushq $0 # fake return address to stop unwinder
18529 pushq $__KERNEL_CS # set correct cs
18530 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18531 bad_address:
18532 jmp bad_address
18533
18534 - .section ".init.text","ax"
18535 + __INIT
18536 .globl early_idt_handlers
18537 early_idt_handlers:
18538 # 104(%rsp) %rflags
18539 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18540 addq $16,%rsp # drop vector number and error code
18541 decl early_recursion_flag(%rip)
18542 INTERRUPT_RETURN
18543 + .previous
18544
18545 + __INITDATA
18546 .balign 4
18547 early_recursion_flag:
18548 .long 0
18549 + .previous
18550
18551 + .section .rodata,"a",@progbits
18552 #ifdef CONFIG_EARLY_PRINTK
18553 early_idt_msg:
18554 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18555 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18556 #endif /* CONFIG_EARLY_PRINTK */
18557 .previous
18558
18559 + .section .rodata,"a",@progbits
18560 #define NEXT_PAGE(name) \
18561 .balign PAGE_SIZE; \
18562 ENTRY(name)
18563 @@ -372,7 +382,6 @@ ENTRY(name)
18564 i = i + 1 ; \
18565 .endr
18566
18567 - .data
18568 /*
18569 * This default setting generates an ident mapping at address 0x100000
18570 * and a mapping for the kernel that precisely maps virtual address
18571 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18572 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18573 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18574 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18575 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18576 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18577 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18578 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18579 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18580 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18581 .org init_level4_pgt + L4_START_KERNEL*8, 0
18582 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18583 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18584
18585 +#ifdef CONFIG_PAX_PER_CPU_PGD
18586 +NEXT_PAGE(cpu_pgd)
18587 + .rept NR_CPUS
18588 + .fill 512,8,0
18589 + .endr
18590 +#endif
18591 +
18592 NEXT_PAGE(level3_ident_pgt)
18593 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18594 +#ifdef CONFIG_XEN
18595 .fill 511,8,0
18596 +#else
18597 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18598 + .fill 510,8,0
18599 +#endif
18600 +
18601 +NEXT_PAGE(level3_vmalloc_start_pgt)
18602 + .fill 512,8,0
18603 +
18604 +NEXT_PAGE(level3_vmalloc_end_pgt)
18605 + .fill 512,8,0
18606 +
18607 +NEXT_PAGE(level3_vmemmap_pgt)
18608 + .fill L3_VMEMMAP_START,8,0
18609 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18610
18611 NEXT_PAGE(level3_kernel_pgt)
18612 .fill L3_START_KERNEL,8,0
18613 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18614 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18615 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18616
18617 +NEXT_PAGE(level2_vmemmap_pgt)
18618 + .fill 512,8,0
18619 +
18620 NEXT_PAGE(level2_fixmap_pgt)
18621 - .fill 506,8,0
18622 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18623 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18624 - .fill 5,8,0
18625 + .fill 507,8,0
18626 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18627 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18628 + .fill 4,8,0
18629
18630 -NEXT_PAGE(level1_fixmap_pgt)
18631 +NEXT_PAGE(level1_vsyscall_pgt)
18632 .fill 512,8,0
18633
18634 -NEXT_PAGE(level2_ident_pgt)
18635 - /* Since I easily can, map the first 1G.
18636 + /* Since I easily can, map the first 2G.
18637 * Don't set NX because code runs from these pages.
18638 */
18639 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18640 +NEXT_PAGE(level2_ident_pgt)
18641 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18642
18643 NEXT_PAGE(level2_kernel_pgt)
18644 /*
18645 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18646 * If you want to increase this then increase MODULES_VADDR
18647 * too.)
18648 */
18649 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18650 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18651 -
18652 -NEXT_PAGE(level2_spare_pgt)
18653 - .fill 512, 8, 0
18654 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18655
18656 #undef PMDS
18657 #undef NEXT_PAGE
18658
18659 - .data
18660 + .align PAGE_SIZE
18661 +ENTRY(cpu_gdt_table)
18662 + .rept NR_CPUS
18663 + .quad 0x0000000000000000 /* NULL descriptor */
18664 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18665 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18666 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18667 + .quad 0x00cffb000000ffff /* __USER32_CS */
18668 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18669 + .quad 0x00affb000000ffff /* __USER_CS */
18670 +
18671 +#ifdef CONFIG_PAX_KERNEXEC
18672 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18673 +#else
18674 + .quad 0x0 /* unused */
18675 +#endif
18676 +
18677 + .quad 0,0 /* TSS */
18678 + .quad 0,0 /* LDT */
18679 + .quad 0,0,0 /* three TLS descriptors */
18680 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18681 + /* asm/segment.h:GDT_ENTRIES must match this */
18682 +
18683 + /* zero the remaining page */
18684 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18685 + .endr
18686 +
18687 .align 16
18688 .globl early_gdt_descr
18689 early_gdt_descr:
18690 .word GDT_ENTRIES*8-1
18691 early_gdt_descr_base:
18692 - .quad INIT_PER_CPU_VAR(gdt_page)
18693 + .quad cpu_gdt_table
18694
18695 ENTRY(phys_base)
18696 /* This must match the first entry in level2_kernel_pgt */
18697 .quad 0x0000000000000000
18698
18699 #include "../../x86/xen/xen-head.S"
18700 -
18701 - .section .bss, "aw", @nobits
18702 +
18703 + .section .rodata,"a",@progbits
18704 .align L1_CACHE_BYTES
18705 ENTRY(idt_table)
18706 - .skip IDT_ENTRIES * 16
18707 + .fill 512,8,0
18708
18709 .align L1_CACHE_BYTES
18710 ENTRY(nmi_idt_table)
18711 - .skip IDT_ENTRIES * 16
18712 + .fill 512,8,0
18713
18714 __PAGE_ALIGNED_BSS
18715 .align PAGE_SIZE
18716 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18717 index 9c3bd4a..e1d9b35 100644
18718 --- a/arch/x86/kernel/i386_ksyms_32.c
18719 +++ b/arch/x86/kernel/i386_ksyms_32.c
18720 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18721 EXPORT_SYMBOL(cmpxchg8b_emu);
18722 #endif
18723
18724 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18725 +
18726 /* Networking helper routines. */
18727 EXPORT_SYMBOL(csum_partial_copy_generic);
18728 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18729 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18730
18731 EXPORT_SYMBOL(__get_user_1);
18732 EXPORT_SYMBOL(__get_user_2);
18733 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18734
18735 EXPORT_SYMBOL(csum_partial);
18736 EXPORT_SYMBOL(empty_zero_page);
18737 +
18738 +#ifdef CONFIG_PAX_KERNEXEC
18739 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18740 +#endif
18741 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18742 index 675a050..95febfd 100644
18743 --- a/arch/x86/kernel/i387.c
18744 +++ b/arch/x86/kernel/i387.c
18745 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18746 static inline bool interrupted_user_mode(void)
18747 {
18748 struct pt_regs *regs = get_irq_regs();
18749 - return regs && user_mode_vm(regs);
18750 + return regs && user_mode(regs);
18751 }
18752
18753 /*
18754 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18755 index 9a5c460..dc4374d 100644
18756 --- a/arch/x86/kernel/i8259.c
18757 +++ b/arch/x86/kernel/i8259.c
18758 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18759 "spurious 8259A interrupt: IRQ%d.\n", irq);
18760 spurious_irq_mask |= irqmask;
18761 }
18762 - atomic_inc(&irq_err_count);
18763 + atomic_inc_unchecked(&irq_err_count);
18764 /*
18765 * Theoretically we do not have to handle this IRQ,
18766 * but in Linux this does not cause problems and is
18767 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18768 index 8c96897..be66bfa 100644
18769 --- a/arch/x86/kernel/ioport.c
18770 +++ b/arch/x86/kernel/ioport.c
18771 @@ -6,6 +6,7 @@
18772 #include <linux/sched.h>
18773 #include <linux/kernel.h>
18774 #include <linux/capability.h>
18775 +#include <linux/security.h>
18776 #include <linux/errno.h>
18777 #include <linux/types.h>
18778 #include <linux/ioport.h>
18779 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18780
18781 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18782 return -EINVAL;
18783 +#ifdef CONFIG_GRKERNSEC_IO
18784 + if (turn_on && grsec_disable_privio) {
18785 + gr_handle_ioperm();
18786 + return -EPERM;
18787 + }
18788 +#endif
18789 if (turn_on && !capable(CAP_SYS_RAWIO))
18790 return -EPERM;
18791
18792 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18793 * because the ->io_bitmap_max value must match the bitmap
18794 * contents:
18795 */
18796 - tss = &per_cpu(init_tss, get_cpu());
18797 + tss = init_tss + get_cpu();
18798
18799 if (turn_on)
18800 bitmap_clear(t->io_bitmap_ptr, from, num);
18801 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18802 return -EINVAL;
18803 /* Trying to gain more privileges? */
18804 if (level > old) {
18805 +#ifdef CONFIG_GRKERNSEC_IO
18806 + if (grsec_disable_privio) {
18807 + gr_handle_iopl();
18808 + return -EPERM;
18809 + }
18810 +#endif
18811 if (!capable(CAP_SYS_RAWIO))
18812 return -EPERM;
18813 }
18814 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18815 index e4595f1..ee3bfb8 100644
18816 --- a/arch/x86/kernel/irq.c
18817 +++ b/arch/x86/kernel/irq.c
18818 @@ -18,7 +18,7 @@
18819 #include <asm/mce.h>
18820 #include <asm/hw_irq.h>
18821
18822 -atomic_t irq_err_count;
18823 +atomic_unchecked_t irq_err_count;
18824
18825 /* Function pointer for generic interrupt vector handling */
18826 void (*x86_platform_ipi_callback)(void) = NULL;
18827 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18828 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18829 seq_printf(p, " Machine check polls\n");
18830 #endif
18831 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18832 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18833 #if defined(CONFIG_X86_IO_APIC)
18834 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18835 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18836 #endif
18837 return 0;
18838 }
18839 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18840
18841 u64 arch_irq_stat(void)
18842 {
18843 - u64 sum = atomic_read(&irq_err_count);
18844 + u64 sum = atomic_read_unchecked(&irq_err_count);
18845
18846 #ifdef CONFIG_X86_IO_APIC
18847 - sum += atomic_read(&irq_mis_count);
18848 + sum += atomic_read_unchecked(&irq_mis_count);
18849 #endif
18850 return sum;
18851 }
18852 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18853 index 344faf8..355f60d 100644
18854 --- a/arch/x86/kernel/irq_32.c
18855 +++ b/arch/x86/kernel/irq_32.c
18856 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18857 __asm__ __volatile__("andl %%esp,%0" :
18858 "=r" (sp) : "0" (THREAD_SIZE - 1));
18859
18860 - return sp < (sizeof(struct thread_info) + STACK_WARN);
18861 + return sp < STACK_WARN;
18862 }
18863
18864 static void print_stack_overflow(void)
18865 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18866 * per-CPU IRQ handling contexts (thread information and stack)
18867 */
18868 union irq_ctx {
18869 - struct thread_info tinfo;
18870 - u32 stack[THREAD_SIZE/sizeof(u32)];
18871 + unsigned long previous_esp;
18872 + u32 stack[THREAD_SIZE/sizeof(u32)];
18873 } __attribute__((aligned(THREAD_SIZE)));
18874
18875 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18876 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18877 static inline int
18878 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18879 {
18880 - union irq_ctx *curctx, *irqctx;
18881 + union irq_ctx *irqctx;
18882 u32 *isp, arg1, arg2;
18883
18884 - curctx = (union irq_ctx *) current_thread_info();
18885 irqctx = __this_cpu_read(hardirq_ctx);
18886
18887 /*
18888 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18889 * handler) we can't do that and just have to keep using the
18890 * current stack (which is the irq stack already after all)
18891 */
18892 - if (unlikely(curctx == irqctx))
18893 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18894 return 0;
18895
18896 /* build the stack frame on the IRQ stack */
18897 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18898 - irqctx->tinfo.task = curctx->tinfo.task;
18899 - irqctx->tinfo.previous_esp = current_stack_pointer;
18900 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18901 + irqctx->previous_esp = current_stack_pointer;
18902
18903 - /* Copy the preempt_count so that the [soft]irq checks work. */
18904 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18905 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18906 + __set_fs(MAKE_MM_SEG(0));
18907 +#endif
18908
18909 if (unlikely(overflow))
18910 call_on_stack(print_stack_overflow, isp);
18911 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18912 : "0" (irq), "1" (desc), "2" (isp),
18913 "D" (desc->handle_irq)
18914 : "memory", "cc", "ecx");
18915 +
18916 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18917 + __set_fs(current_thread_info()->addr_limit);
18918 +#endif
18919 +
18920 return 1;
18921 }
18922
18923 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18924 */
18925 void __cpuinit irq_ctx_init(int cpu)
18926 {
18927 - union irq_ctx *irqctx;
18928 -
18929 if (per_cpu(hardirq_ctx, cpu))
18930 return;
18931
18932 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18933 - THREADINFO_GFP,
18934 - THREAD_SIZE_ORDER));
18935 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18936 - irqctx->tinfo.cpu = cpu;
18937 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18938 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18939 -
18940 - per_cpu(hardirq_ctx, cpu) = irqctx;
18941 -
18942 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18943 - THREADINFO_GFP,
18944 - THREAD_SIZE_ORDER));
18945 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18946 - irqctx->tinfo.cpu = cpu;
18947 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18948 -
18949 - per_cpu(softirq_ctx, cpu) = irqctx;
18950 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18951 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18952 +
18953 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18954 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18955
18956 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18957 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18958 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
18959 asmlinkage void do_softirq(void)
18960 {
18961 unsigned long flags;
18962 - struct thread_info *curctx;
18963 union irq_ctx *irqctx;
18964 u32 *isp;
18965
18966 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
18967 local_irq_save(flags);
18968
18969 if (local_softirq_pending()) {
18970 - curctx = current_thread_info();
18971 irqctx = __this_cpu_read(softirq_ctx);
18972 - irqctx->tinfo.task = curctx->task;
18973 - irqctx->tinfo.previous_esp = current_stack_pointer;
18974 + irqctx->previous_esp = current_stack_pointer;
18975
18976 /* build the stack frame on the softirq stack */
18977 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18978 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18979 +
18980 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18981 + __set_fs(MAKE_MM_SEG(0));
18982 +#endif
18983
18984 call_on_stack(__do_softirq, isp);
18985 +
18986 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18987 + __set_fs(current_thread_info()->addr_limit);
18988 +#endif
18989 +
18990 /*
18991 * Shouldn't happen, we returned above if in_interrupt():
18992 */
18993 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
18994 if (unlikely(!desc))
18995 return false;
18996
18997 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18998 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18999 if (unlikely(overflow))
19000 print_stack_overflow();
19001 desc->handle_irq(irq, desc);
19002 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19003 index d04d3ec..ea4b374 100644
19004 --- a/arch/x86/kernel/irq_64.c
19005 +++ b/arch/x86/kernel/irq_64.c
19006 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19007 u64 estack_top, estack_bottom;
19008 u64 curbase = (u64)task_stack_page(current);
19009
19010 - if (user_mode_vm(regs))
19011 + if (user_mode(regs))
19012 return;
19013
19014 if (regs->sp >= curbase + sizeof(struct thread_info) +
19015 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19016 index dc1404b..bbc43e7 100644
19017 --- a/arch/x86/kernel/kdebugfs.c
19018 +++ b/arch/x86/kernel/kdebugfs.c
19019 @@ -27,7 +27,7 @@ struct setup_data_node {
19020 u32 len;
19021 };
19022
19023 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19024 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19025 size_t count, loff_t *ppos)
19026 {
19027 struct setup_data_node *node = file->private_data;
19028 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19029 index 836f832..a8bda67 100644
19030 --- a/arch/x86/kernel/kgdb.c
19031 +++ b/arch/x86/kernel/kgdb.c
19032 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19033 #ifdef CONFIG_X86_32
19034 switch (regno) {
19035 case GDB_SS:
19036 - if (!user_mode_vm(regs))
19037 + if (!user_mode(regs))
19038 *(unsigned long *)mem = __KERNEL_DS;
19039 break;
19040 case GDB_SP:
19041 - if (!user_mode_vm(regs))
19042 + if (!user_mode(regs))
19043 *(unsigned long *)mem = kernel_stack_pointer(regs);
19044 break;
19045 case GDB_GS:
19046 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19047 bp->attr.bp_addr = breakinfo[breakno].addr;
19048 bp->attr.bp_len = breakinfo[breakno].len;
19049 bp->attr.bp_type = breakinfo[breakno].type;
19050 - info->address = breakinfo[breakno].addr;
19051 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19052 + info->address = ktla_ktva(breakinfo[breakno].addr);
19053 + else
19054 + info->address = breakinfo[breakno].addr;
19055 info->len = breakinfo[breakno].len;
19056 info->type = breakinfo[breakno].type;
19057 val = arch_install_hw_breakpoint(bp);
19058 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19059 case 'k':
19060 /* clear the trace bit */
19061 linux_regs->flags &= ~X86_EFLAGS_TF;
19062 - atomic_set(&kgdb_cpu_doing_single_step, -1);
19063 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19064
19065 /* set the trace bit if we're stepping */
19066 if (remcomInBuffer[0] == 's') {
19067 linux_regs->flags |= X86_EFLAGS_TF;
19068 - atomic_set(&kgdb_cpu_doing_single_step,
19069 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19070 raw_smp_processor_id());
19071 }
19072
19073 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19074
19075 switch (cmd) {
19076 case DIE_DEBUG:
19077 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19078 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19079 if (user_mode(regs))
19080 return single_step_cont(regs, args);
19081 break;
19082 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19083 #endif /* CONFIG_DEBUG_RODATA */
19084
19085 bpt->type = BP_BREAKPOINT;
19086 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19087 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19088 BREAK_INSTR_SIZE);
19089 if (err)
19090 return err;
19091 - err = probe_kernel_write((char *)bpt->bpt_addr,
19092 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19093 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19094 #ifdef CONFIG_DEBUG_RODATA
19095 if (!err)
19096 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19097 return -EBUSY;
19098 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19099 BREAK_INSTR_SIZE);
19100 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19101 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19102 if (err)
19103 return err;
19104 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19105 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19106 if (mutex_is_locked(&text_mutex))
19107 goto knl_write;
19108 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19109 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19110 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19111 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19112 goto knl_write;
19113 return err;
19114 knl_write:
19115 #endif /* CONFIG_DEBUG_RODATA */
19116 - return probe_kernel_write((char *)bpt->bpt_addr,
19117 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19118 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19119 }
19120
19121 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19122 index c5e410e..ed5a7f0 100644
19123 --- a/arch/x86/kernel/kprobes-opt.c
19124 +++ b/arch/x86/kernel/kprobes-opt.c
19125 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19126 * Verify if the address gap is in 2GB range, because this uses
19127 * a relative jump.
19128 */
19129 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19130 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19131 if (abs(rel) > 0x7fffffff)
19132 return -ERANGE;
19133
19134 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19135 op->optinsn.size = ret;
19136
19137 /* Copy arch-dep-instance from template */
19138 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19139 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19140
19141 /* Set probe information */
19142 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19143
19144 /* Set probe function call */
19145 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19146 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19147
19148 /* Set returning jmp instruction at the tail of out-of-line buffer */
19149 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19150 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19151 (u8 *)op->kp.addr + op->optinsn.size);
19152
19153 flush_icache_range((unsigned long) buf,
19154 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19155 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19156
19157 /* Backup instructions which will be replaced by jump address */
19158 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19159 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19160 RELATIVE_ADDR_SIZE);
19161
19162 insn_buf[0] = RELATIVEJUMP_OPCODE;
19163 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19164 /* This kprobe is really able to run optimized path. */
19165 op = container_of(p, struct optimized_kprobe, kp);
19166 /* Detour through copied instructions */
19167 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19168 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19169 if (!reenter)
19170 reset_current_kprobe();
19171 preempt_enable_no_resched();
19172 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19173 index 57916c0..9e0b9d0 100644
19174 --- a/arch/x86/kernel/kprobes.c
19175 +++ b/arch/x86/kernel/kprobes.c
19176 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19177 s32 raddr;
19178 } __attribute__((packed)) *insn;
19179
19180 - insn = (struct __arch_relative_insn *)from;
19181 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
19182 +
19183 + pax_open_kernel();
19184 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19185 insn->op = op;
19186 + pax_close_kernel();
19187 }
19188
19189 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19190 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19191 kprobe_opcode_t opcode;
19192 kprobe_opcode_t *orig_opcodes = opcodes;
19193
19194 - if (search_exception_tables((unsigned long)opcodes))
19195 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19196 return 0; /* Page fault may occur on this address. */
19197
19198 retry:
19199 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19200 * for the first byte, we can recover the original instruction
19201 * from it and kp->opcode.
19202 */
19203 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19204 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19205 buf[0] = kp->opcode;
19206 - return (unsigned long)buf;
19207 + return ktva_ktla((unsigned long)buf);
19208 }
19209
19210 /*
19211 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19212 /* Another subsystem puts a breakpoint, failed to recover */
19213 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19214 return 0;
19215 + pax_open_kernel();
19216 memcpy(dest, insn.kaddr, insn.length);
19217 + pax_close_kernel();
19218
19219 #ifdef CONFIG_X86_64
19220 if (insn_rip_relative(&insn)) {
19221 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19222 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19223 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19224 disp = (u8 *) dest + insn_offset_displacement(&insn);
19225 + pax_open_kernel();
19226 *(s32 *) disp = (s32) newdisp;
19227 + pax_close_kernel();
19228 }
19229 #endif
19230 return insn.length;
19231 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19232 * nor set current_kprobe, because it doesn't use single
19233 * stepping.
19234 */
19235 - regs->ip = (unsigned long)p->ainsn.insn;
19236 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19237 preempt_enable_no_resched();
19238 return;
19239 }
19240 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19241 regs->flags &= ~X86_EFLAGS_IF;
19242 /* single step inline if the instruction is an int3 */
19243 if (p->opcode == BREAKPOINT_INSTRUCTION)
19244 - regs->ip = (unsigned long)p->addr;
19245 + regs->ip = ktla_ktva((unsigned long)p->addr);
19246 else
19247 - regs->ip = (unsigned long)p->ainsn.insn;
19248 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19249 }
19250
19251 /*
19252 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19253 setup_singlestep(p, regs, kcb, 0);
19254 return 1;
19255 }
19256 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19257 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19258 /*
19259 * The breakpoint instruction was removed right
19260 * after we hit it. Another cpu has removed
19261 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19262 " movq %rax, 152(%rsp)\n"
19263 RESTORE_REGS_STRING
19264 " popfq\n"
19265 +#ifdef KERNEXEC_PLUGIN
19266 + " btsq $63,(%rsp)\n"
19267 +#endif
19268 #else
19269 " pushf\n"
19270 SAVE_REGS_STRING
19271 @@ -788,7 +798,7 @@ static void __kprobes
19272 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19273 {
19274 unsigned long *tos = stack_addr(regs);
19275 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19276 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19277 unsigned long orig_ip = (unsigned long)p->addr;
19278 kprobe_opcode_t *insn = p->ainsn.insn;
19279
19280 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19281 struct die_args *args = data;
19282 int ret = NOTIFY_DONE;
19283
19284 - if (args->regs && user_mode_vm(args->regs))
19285 + if (args->regs && user_mode(args->regs))
19286 return ret;
19287
19288 switch (val) {
19289 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19290 index 4180a87..4678e4f 100644
19291 --- a/arch/x86/kernel/kvm.c
19292 +++ b/arch/x86/kernel/kvm.c
19293 @@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19294 pv_info.paravirt_enabled = 1;
19295
19296 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19297 - pv_cpu_ops.io_delay = kvm_io_delay;
19298 + *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19299
19300 #ifdef CONFIG_X86_IO_APIC
19301 no_timer_check = 1;
19302 @@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19303 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19304 spin_lock_init(&async_pf_sleepers[i].lock);
19305 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19306 - x86_init.irqs.trap_init = kvm_apf_trap_init;
19307 + *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19308
19309 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19310 has_steal_clock = 1;
19311 - pv_time_ops.steal_clock = kvm_steal_clock;
19312 + *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19313 }
19314
19315 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19316 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19317
19318 #ifdef CONFIG_SMP
19319 - smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19320 + *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19321 register_cpu_notifier(&kvm_cpu_notifier);
19322 #else
19323 kvm_guest_cpu_init();
19324 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19325 index f1b42b3..27ac4e7 100644
19326 --- a/arch/x86/kernel/kvmclock.c
19327 +++ b/arch/x86/kernel/kvmclock.c
19328 @@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19329
19330 if (kvm_register_clock("boot clock"))
19331 return;
19332 - pv_time_ops.sched_clock = kvm_clock_read;
19333 - x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19334 - x86_platform.get_wallclock = kvm_get_wallclock;
19335 - x86_platform.set_wallclock = kvm_set_wallclock;
19336 + *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19337 + *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19338 + *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19339 + *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19340 #ifdef CONFIG_X86_LOCAL_APIC
19341 - x86_cpuinit.early_percpu_clock_init =
19342 + *(void **)&x86_cpuinit.early_percpu_clock_init =
19343 kvm_setup_secondary_clock;
19344 #endif
19345 - x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19346 - x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19347 - machine_ops.shutdown = kvm_shutdown;
19348 + *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19349 + *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19350 + *(void **)&machine_ops.shutdown = kvm_shutdown;
19351 #ifdef CONFIG_KEXEC
19352 - machine_ops.crash_shutdown = kvm_crash_shutdown;
19353 + *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19354 #endif
19355 kvm_get_preset_lpj();
19356 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19357 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19358 index ebc9873..1b9724b 100644
19359 --- a/arch/x86/kernel/ldt.c
19360 +++ b/arch/x86/kernel/ldt.c
19361 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19362 if (reload) {
19363 #ifdef CONFIG_SMP
19364 preempt_disable();
19365 - load_LDT(pc);
19366 + load_LDT_nolock(pc);
19367 if (!cpumask_equal(mm_cpumask(current->mm),
19368 cpumask_of(smp_processor_id())))
19369 smp_call_function(flush_ldt, current->mm, 1);
19370 preempt_enable();
19371 #else
19372 - load_LDT(pc);
19373 + load_LDT_nolock(pc);
19374 #endif
19375 }
19376 if (oldsize) {
19377 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19378 return err;
19379
19380 for (i = 0; i < old->size; i++)
19381 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19382 + write_ldt_entry(new->ldt, i, old->ldt + i);
19383 return 0;
19384 }
19385
19386 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19387 retval = copy_ldt(&mm->context, &old_mm->context);
19388 mutex_unlock(&old_mm->context.lock);
19389 }
19390 +
19391 + if (tsk == current) {
19392 + mm->context.vdso = 0;
19393 +
19394 +#ifdef CONFIG_X86_32
19395 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19396 + mm->context.user_cs_base = 0UL;
19397 + mm->context.user_cs_limit = ~0UL;
19398 +
19399 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19400 + cpus_clear(mm->context.cpu_user_cs_mask);
19401 +#endif
19402 +
19403 +#endif
19404 +#endif
19405 +
19406 + }
19407 +
19408 return retval;
19409 }
19410
19411 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19412 }
19413 }
19414
19415 +#ifdef CONFIG_PAX_SEGMEXEC
19416 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19417 + error = -EINVAL;
19418 + goto out_unlock;
19419 + }
19420 +#endif
19421 +
19422 fill_ldt(&ldt, &ldt_info);
19423 if (oldmode)
19424 ldt.avl = 0;
19425 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19426 index 5b19e4d..6476a76 100644
19427 --- a/arch/x86/kernel/machine_kexec_32.c
19428 +++ b/arch/x86/kernel/machine_kexec_32.c
19429 @@ -26,7 +26,7 @@
19430 #include <asm/cacheflush.h>
19431 #include <asm/debugreg.h>
19432
19433 -static void set_idt(void *newidt, __u16 limit)
19434 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19435 {
19436 struct desc_ptr curidt;
19437
19438 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19439 }
19440
19441
19442 -static void set_gdt(void *newgdt, __u16 limit)
19443 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19444 {
19445 struct desc_ptr curgdt;
19446
19447 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19448 }
19449
19450 control_page = page_address(image->control_code_page);
19451 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19452 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19453
19454 relocate_kernel_ptr = control_page;
19455 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19456 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19457 index 3544aed..01ddc1c 100644
19458 --- a/arch/x86/kernel/microcode_intel.c
19459 +++ b/arch/x86/kernel/microcode_intel.c
19460 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19461
19462 static int get_ucode_user(void *to, const void *from, size_t n)
19463 {
19464 - return copy_from_user(to, from, n);
19465 + return copy_from_user(to, (const void __force_user *)from, n);
19466 }
19467
19468 static enum ucode_state
19469 request_microcode_user(int cpu, const void __user *buf, size_t size)
19470 {
19471 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19472 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19473 }
19474
19475 static void microcode_fini_cpu(int cpu)
19476 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19477 index 216a4d7..b328f09 100644
19478 --- a/arch/x86/kernel/module.c
19479 +++ b/arch/x86/kernel/module.c
19480 @@ -43,15 +43,60 @@ do { \
19481 } while (0)
19482 #endif
19483
19484 -void *module_alloc(unsigned long size)
19485 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19486 {
19487 - if (PAGE_ALIGN(size) > MODULES_LEN)
19488 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19489 return NULL;
19490 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19491 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19492 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19493 -1, __builtin_return_address(0));
19494 }
19495
19496 +void *module_alloc(unsigned long size)
19497 +{
19498 +
19499 +#ifdef CONFIG_PAX_KERNEXEC
19500 + return __module_alloc(size, PAGE_KERNEL);
19501 +#else
19502 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19503 +#endif
19504 +
19505 +}
19506 +
19507 +#ifdef CONFIG_PAX_KERNEXEC
19508 +#ifdef CONFIG_X86_32
19509 +void *module_alloc_exec(unsigned long size)
19510 +{
19511 + struct vm_struct *area;
19512 +
19513 + if (size == 0)
19514 + return NULL;
19515 +
19516 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19517 + return area ? area->addr : NULL;
19518 +}
19519 +EXPORT_SYMBOL(module_alloc_exec);
19520 +
19521 +void module_free_exec(struct module *mod, void *module_region)
19522 +{
19523 + vunmap(module_region);
19524 +}
19525 +EXPORT_SYMBOL(module_free_exec);
19526 +#else
19527 +void module_free_exec(struct module *mod, void *module_region)
19528 +{
19529 + module_free(mod, module_region);
19530 +}
19531 +EXPORT_SYMBOL(module_free_exec);
19532 +
19533 +void *module_alloc_exec(unsigned long size)
19534 +{
19535 + return __module_alloc(size, PAGE_KERNEL_RX);
19536 +}
19537 +EXPORT_SYMBOL(module_alloc_exec);
19538 +#endif
19539 +#endif
19540 +
19541 #ifdef CONFIG_X86_32
19542 int apply_relocate(Elf32_Shdr *sechdrs,
19543 const char *strtab,
19544 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19545 unsigned int i;
19546 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19547 Elf32_Sym *sym;
19548 - uint32_t *location;
19549 + uint32_t *plocation, location;
19550
19551 DEBUGP("Applying relocate section %u to %u\n",
19552 relsec, sechdrs[relsec].sh_info);
19553 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19554 /* This is where to make the change */
19555 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19556 - + rel[i].r_offset;
19557 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19558 + location = (uint32_t)plocation;
19559 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19560 + plocation = ktla_ktva((void *)plocation);
19561 /* This is the symbol it is referring to. Note that all
19562 undefined symbols have been resolved. */
19563 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19564 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19565 switch (ELF32_R_TYPE(rel[i].r_info)) {
19566 case R_386_32:
19567 /* We add the value into the location given */
19568 - *location += sym->st_value;
19569 + pax_open_kernel();
19570 + *plocation += sym->st_value;
19571 + pax_close_kernel();
19572 break;
19573 case R_386_PC32:
19574 /* Add the value, subtract its position */
19575 - *location += sym->st_value - (uint32_t)location;
19576 + pax_open_kernel();
19577 + *plocation += sym->st_value - location;
19578 + pax_close_kernel();
19579 break;
19580 default:
19581 pr_err("%s: Unknown relocation: %u\n",
19582 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19583 case R_X86_64_NONE:
19584 break;
19585 case R_X86_64_64:
19586 + pax_open_kernel();
19587 *(u64 *)loc = val;
19588 + pax_close_kernel();
19589 break;
19590 case R_X86_64_32:
19591 + pax_open_kernel();
19592 *(u32 *)loc = val;
19593 + pax_close_kernel();
19594 if (val != *(u32 *)loc)
19595 goto overflow;
19596 break;
19597 case R_X86_64_32S:
19598 + pax_open_kernel();
19599 *(s32 *)loc = val;
19600 + pax_close_kernel();
19601 if ((s64)val != *(s32 *)loc)
19602 goto overflow;
19603 break;
19604 case R_X86_64_PC32:
19605 val -= (u64)loc;
19606 + pax_open_kernel();
19607 *(u32 *)loc = val;
19608 + pax_close_kernel();
19609 +
19610 #if 0
19611 if ((s64)val != *(s32 *)loc)
19612 goto overflow;
19613 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
19614 index a7c5661..4929502 100644
19615 --- a/arch/x86/kernel/msr.c
19616 +++ b/arch/x86/kernel/msr.c
19617 @@ -174,6 +174,9 @@ static int msr_open(struct inode *inode, struct file *file)
19618 unsigned int cpu;
19619 struct cpuinfo_x86 *c;
19620
19621 + if (!capable(CAP_SYS_RAWIO))
19622 + return -EPERM;
19623 +
19624 cpu = iminor(file->f_path.dentry->d_inode);
19625 if (cpu >= nr_cpu_ids || !cpu_online(cpu))
19626 return -ENXIO; /* No such CPU */
19627 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19628 index f84f5c5..e27e54b 100644
19629 --- a/arch/x86/kernel/nmi.c
19630 +++ b/arch/x86/kernel/nmi.c
19631 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19632 dotraplinkage notrace __kprobes void
19633 do_nmi(struct pt_regs *regs, long error_code)
19634 {
19635 +
19636 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19637 + if (!user_mode(regs)) {
19638 + unsigned long cs = regs->cs & 0xFFFF;
19639 + unsigned long ip = ktva_ktla(regs->ip);
19640 +
19641 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19642 + regs->ip = ip;
19643 + }
19644 +#endif
19645 +
19646 nmi_nesting_preprocess(regs);
19647
19648 nmi_enter();
19649 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19650 index 676b8c7..870ba04 100644
19651 --- a/arch/x86/kernel/paravirt-spinlocks.c
19652 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19653 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19654 arch_spin_lock(lock);
19655 }
19656
19657 -struct pv_lock_ops pv_lock_ops = {
19658 +struct pv_lock_ops pv_lock_ops __read_only = {
19659 #ifdef CONFIG_SMP
19660 .spin_is_locked = __ticket_spin_is_locked,
19661 .spin_is_contended = __ticket_spin_is_contended,
19662 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19663 index 17fff18..0f5f957 100644
19664 --- a/arch/x86/kernel/paravirt.c
19665 +++ b/arch/x86/kernel/paravirt.c
19666 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19667 {
19668 return x;
19669 }
19670 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19671 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19672 +#endif
19673
19674 void __init default_banner(void)
19675 {
19676 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19677 if (opfunc == NULL)
19678 /* If there's no function, patch it with a ud2a (BUG) */
19679 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19680 - else if (opfunc == _paravirt_nop)
19681 + else if (opfunc == (void *)_paravirt_nop)
19682 /* If the operation is a nop, then nop the callsite */
19683 ret = paravirt_patch_nop();
19684
19685 /* identity functions just return their single argument */
19686 - else if (opfunc == _paravirt_ident_32)
19687 + else if (opfunc == (void *)_paravirt_ident_32)
19688 ret = paravirt_patch_ident_32(insnbuf, len);
19689 - else if (opfunc == _paravirt_ident_64)
19690 + else if (opfunc == (void *)_paravirt_ident_64)
19691 ret = paravirt_patch_ident_64(insnbuf, len);
19692 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19693 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19694 + ret = paravirt_patch_ident_64(insnbuf, len);
19695 +#endif
19696
19697 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19698 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19699 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19700 if (insn_len > len || start == NULL)
19701 insn_len = len;
19702 else
19703 - memcpy(insnbuf, start, insn_len);
19704 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19705
19706 return insn_len;
19707 }
19708 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19709 preempt_enable();
19710 }
19711
19712 -struct pv_info pv_info = {
19713 +struct pv_info pv_info __read_only = {
19714 .name = "bare hardware",
19715 .paravirt_enabled = 0,
19716 .kernel_rpl = 0,
19717 @@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19718 .steal_clock = native_steal_clock,
19719 };
19720
19721 -struct pv_irq_ops pv_irq_ops = {
19722 +struct pv_irq_ops pv_irq_ops __read_only = {
19723 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19724 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19725 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19726 @@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19727 #endif
19728 };
19729
19730 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19731 +#ifdef CONFIG_X86_32
19732 +#ifdef CONFIG_X86_PAE
19733 +/* 64-bit pagetable entries */
19734 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19735 +#else
19736 /* 32-bit pagetable entries */
19737 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19738 +#endif
19739 #else
19740 /* 64-bit pagetable entries */
19741 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19742 #endif
19743
19744 -struct pv_mmu_ops pv_mmu_ops = {
19745 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19746
19747 .read_cr2 = native_read_cr2,
19748 .write_cr2 = native_write_cr2,
19749 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19750 .make_pud = PTE_IDENT,
19751
19752 .set_pgd = native_set_pgd,
19753 + .set_pgd_batched = native_set_pgd_batched,
19754 #endif
19755 #endif /* PAGETABLE_LEVELS >= 3 */
19756
19757 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19758 },
19759
19760 .set_fixmap = native_set_fixmap,
19761 +
19762 +#ifdef CONFIG_PAX_KERNEXEC
19763 + .pax_open_kernel = native_pax_open_kernel,
19764 + .pax_close_kernel = native_pax_close_kernel,
19765 +#endif
19766 +
19767 };
19768
19769 EXPORT_SYMBOL_GPL(pv_time_ops);
19770 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19771 index 299d493..79c13dd 100644
19772 --- a/arch/x86/kernel/pci-calgary_64.c
19773 +++ b/arch/x86/kernel/pci-calgary_64.c
19774 @@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19775 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19776 specified_table_size);
19777
19778 - x86_init.iommu.iommu_init = calgary_iommu_init;
19779 + *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19780 }
19781 return calgary_found;
19782
19783 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19784 index 35ccf75..7a15747 100644
19785 --- a/arch/x86/kernel/pci-iommu_table.c
19786 +++ b/arch/x86/kernel/pci-iommu_table.c
19787 @@ -2,7 +2,7 @@
19788 #include <asm/iommu_table.h>
19789 #include <linux/string.h>
19790 #include <linux/kallsyms.h>
19791 -
19792 +#include <linux/sched.h>
19793
19794 #define DEBUG 1
19795
19796 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19797 index b644e1c..4a6d379 100644
19798 --- a/arch/x86/kernel/process.c
19799 +++ b/arch/x86/kernel/process.c
19800 @@ -36,7 +36,8 @@
19801 * section. Since TSS's are completely CPU-local, we want them
19802 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19803 */
19804 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19805 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19806 +EXPORT_SYMBOL(init_tss);
19807
19808 #ifdef CONFIG_X86_64
19809 static DEFINE_PER_CPU(unsigned char, is_idle);
19810 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19811 task_xstate_cachep =
19812 kmem_cache_create("task_xstate", xstate_size,
19813 __alignof__(union thread_xstate),
19814 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19815 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19816 }
19817
19818 /*
19819 @@ -105,7 +106,7 @@ void exit_thread(void)
19820 unsigned long *bp = t->io_bitmap_ptr;
19821
19822 if (bp) {
19823 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19824 + struct tss_struct *tss = init_tss + get_cpu();
19825
19826 t->io_bitmap_ptr = NULL;
19827 clear_thread_flag(TIF_IO_BITMAP);
19828 @@ -136,7 +137,7 @@ void show_regs_common(void)
19829 board = dmi_get_system_info(DMI_BOARD_NAME);
19830
19831 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19832 - current->pid, current->comm, print_tainted(),
19833 + task_pid_nr(current), current->comm, print_tainted(),
19834 init_utsname()->release,
19835 (int)strcspn(init_utsname()->version, " "),
19836 init_utsname()->version,
19837 @@ -149,6 +150,9 @@ void flush_thread(void)
19838 {
19839 struct task_struct *tsk = current;
19840
19841 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19842 + loadsegment(gs, 0);
19843 +#endif
19844 flush_ptrace_hw_breakpoint(tsk);
19845 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19846 drop_init_fpu(tsk);
19847 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19848 void exit_idle(void)
19849 {
19850 /* idle loop has pid 0 */
19851 - if (current->pid)
19852 + if (task_pid_nr(current))
19853 return;
19854 __exit_idle();
19855 }
19856 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19857
19858 return ret;
19859 }
19860 -void stop_this_cpu(void *dummy)
19861 +__noreturn void stop_this_cpu(void *dummy)
19862 {
19863 local_irq_disable();
19864 /*
19865 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19866 }
19867 early_param("idle", idle_setup);
19868
19869 -unsigned long arch_align_stack(unsigned long sp)
19870 +#ifdef CONFIG_PAX_RANDKSTACK
19871 +void pax_randomize_kstack(struct pt_regs *regs)
19872 {
19873 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19874 - sp -= get_random_int() % 8192;
19875 - return sp & ~0xf;
19876 -}
19877 + struct thread_struct *thread = &current->thread;
19878 + unsigned long time;
19879
19880 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19881 -{
19882 - unsigned long range_end = mm->brk + 0x02000000;
19883 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19884 -}
19885 + if (!randomize_va_space)
19886 + return;
19887 +
19888 + if (v8086_mode(regs))
19889 + return;
19890
19891 + rdtscl(time);
19892 +
19893 + /* P4 seems to return a 0 LSB, ignore it */
19894 +#ifdef CONFIG_MPENTIUM4
19895 + time &= 0x3EUL;
19896 + time <<= 2;
19897 +#elif defined(CONFIG_X86_64)
19898 + time &= 0xFUL;
19899 + time <<= 4;
19900 +#else
19901 + time &= 0x1FUL;
19902 + time <<= 3;
19903 +#endif
19904 +
19905 + thread->sp0 ^= time;
19906 + load_sp0(init_tss + smp_processor_id(), thread);
19907 +
19908 +#ifdef CONFIG_X86_64
19909 + this_cpu_write(kernel_stack, thread->sp0);
19910 +#endif
19911 +}
19912 +#endif
19913 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19914 index 44e0bff..5ceb99c 100644
19915 --- a/arch/x86/kernel/process_32.c
19916 +++ b/arch/x86/kernel/process_32.c
19917 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19918 unsigned long thread_saved_pc(struct task_struct *tsk)
19919 {
19920 return ((unsigned long *)tsk->thread.sp)[3];
19921 +//XXX return tsk->thread.eip;
19922 }
19923
19924 void __show_regs(struct pt_regs *regs, int all)
19925 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19926 unsigned long sp;
19927 unsigned short ss, gs;
19928
19929 - if (user_mode_vm(regs)) {
19930 + if (user_mode(regs)) {
19931 sp = regs->sp;
19932 ss = regs->ss & 0xffff;
19933 - gs = get_user_gs(regs);
19934 } else {
19935 sp = kernel_stack_pointer(regs);
19936 savesegment(ss, ss);
19937 - savesegment(gs, gs);
19938 }
19939 + gs = get_user_gs(regs);
19940
19941 show_regs_common();
19942
19943 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19944 (u16)regs->cs, regs->ip, regs->flags,
19945 - smp_processor_id());
19946 + raw_smp_processor_id());
19947 print_symbol("EIP is at %s\n", regs->ip);
19948
19949 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19950 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19951 unsigned long arg,
19952 struct task_struct *p, struct pt_regs *regs)
19953 {
19954 - struct pt_regs *childregs = task_pt_regs(p);
19955 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
19956 struct task_struct *tsk;
19957 int err;
19958
19959 p->thread.sp = (unsigned long) childregs;
19960 p->thread.sp0 = (unsigned long) (childregs+1);
19961 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19962
19963 if (unlikely(!regs)) {
19964 /* kernel thread */
19965 memset(childregs, 0, sizeof(struct pt_regs));
19966 p->thread.ip = (unsigned long) ret_from_kernel_thread;
19967 - task_user_gs(p) = __KERNEL_STACK_CANARY;
19968 - childregs->ds = __USER_DS;
19969 - childregs->es = __USER_DS;
19970 + savesegment(gs, childregs->gs);
19971 + childregs->ds = __KERNEL_DS;
19972 + childregs->es = __KERNEL_DS;
19973 childregs->fs = __KERNEL_PERCPU;
19974 childregs->bx = sp; /* function */
19975 childregs->bp = arg;
19976 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19977 struct thread_struct *prev = &prev_p->thread,
19978 *next = &next_p->thread;
19979 int cpu = smp_processor_id();
19980 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
19981 + struct tss_struct *tss = init_tss + cpu;
19982 fpu_switch_t fpu;
19983
19984 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
19985 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19986 */
19987 lazy_save_gs(prev->gs);
19988
19989 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19990 + __set_fs(task_thread_info(next_p)->addr_limit);
19991 +#endif
19992 +
19993 /*
19994 * Load the per-thread Thread-Local Storage descriptor.
19995 */
19996 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19997 */
19998 arch_end_context_switch(next_p);
19999
20000 + this_cpu_write(current_task, next_p);
20001 + this_cpu_write(current_tinfo, &next_p->tinfo);
20002 +
20003 /*
20004 * Restore %gs if needed (which is common)
20005 */
20006 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20007
20008 switch_fpu_finish(next_p, fpu);
20009
20010 - this_cpu_write(current_task, next_p);
20011 -
20012 return prev_p;
20013 }
20014
20015 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20016 } while (count++ < 16);
20017 return 0;
20018 }
20019 -
20020 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20021 index 16c6365..5d32218 100644
20022 --- a/arch/x86/kernel/process_64.c
20023 +++ b/arch/x86/kernel/process_64.c
20024 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20025 struct pt_regs *childregs;
20026 struct task_struct *me = current;
20027
20028 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20029 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20030 childregs = task_pt_regs(p);
20031 p->thread.sp = (unsigned long) childregs;
20032 p->thread.usersp = me->thread.usersp;
20033 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20034 set_tsk_thread_flag(p, TIF_FORK);
20035 p->fpu_counter = 0;
20036 p->thread.io_bitmap_ptr = NULL;
20037 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20038 struct thread_struct *prev = &prev_p->thread;
20039 struct thread_struct *next = &next_p->thread;
20040 int cpu = smp_processor_id();
20041 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20042 + struct tss_struct *tss = init_tss + cpu;
20043 unsigned fsindex, gsindex;
20044 fpu_switch_t fpu;
20045
20046 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20047 prev->usersp = this_cpu_read(old_rsp);
20048 this_cpu_write(old_rsp, next->usersp);
20049 this_cpu_write(current_task, next_p);
20050 + this_cpu_write(current_tinfo, &next_p->tinfo);
20051
20052 - this_cpu_write(kernel_stack,
20053 - (unsigned long)task_stack_page(next_p) +
20054 - THREAD_SIZE - KERNEL_STACK_OFFSET);
20055 + this_cpu_write(kernel_stack, next->sp0);
20056
20057 /*
20058 * Now maybe reload the debug registers and handle I/O bitmaps
20059 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20060 if (!p || p == current || p->state == TASK_RUNNING)
20061 return 0;
20062 stack = (unsigned long)task_stack_page(p);
20063 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20064 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20065 return 0;
20066 fp = *(u64 *)(p->thread.sp);
20067 do {
20068 - if (fp < (unsigned long)stack ||
20069 - fp >= (unsigned long)stack+THREAD_SIZE)
20070 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20071 return 0;
20072 ip = *(u64 *)(fp+8);
20073 if (!in_sched_functions(ip))
20074 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20075 index 974b67e..12cb2b5 100644
20076 --- a/arch/x86/kernel/ptrace.c
20077 +++ b/arch/x86/kernel/ptrace.c
20078 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20079 {
20080 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20081 unsigned long sp = (unsigned long)&regs->sp;
20082 - struct thread_info *tinfo;
20083
20084 - if (context == (sp & ~(THREAD_SIZE - 1)))
20085 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20086 return sp;
20087
20088 - tinfo = (struct thread_info *)context;
20089 - if (tinfo->previous_esp)
20090 - return tinfo->previous_esp;
20091 + sp = *(unsigned long *)context;
20092 + if (sp)
20093 + return sp;
20094
20095 return (unsigned long)regs;
20096 }
20097 @@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20098 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20099 {
20100 int i;
20101 - int dr7 = 0;
20102 + unsigned long dr7 = 0;
20103 struct arch_hw_breakpoint *info;
20104
20105 for (i = 0; i < HBP_NUM; i++) {
20106 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20107 unsigned long addr, unsigned long data)
20108 {
20109 int ret;
20110 - unsigned long __user *datap = (unsigned long __user *)data;
20111 + unsigned long __user *datap = (__force unsigned long __user *)data;
20112
20113 switch (request) {
20114 /* read the word at location addr in the USER area. */
20115 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20116 if ((int) addr < 0)
20117 return -EIO;
20118 ret = do_get_thread_area(child, addr,
20119 - (struct user_desc __user *)data);
20120 + (__force struct user_desc __user *) data);
20121 break;
20122
20123 case PTRACE_SET_THREAD_AREA:
20124 if ((int) addr < 0)
20125 return -EIO;
20126 ret = do_set_thread_area(child, addr,
20127 - (struct user_desc __user *)data, 0);
20128 + (__force struct user_desc __user *) data, 0);
20129 break;
20130 #endif
20131
20132 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20133
20134 #ifdef CONFIG_X86_64
20135
20136 -static struct user_regset x86_64_regsets[] __read_mostly = {
20137 +static struct user_regset x86_64_regsets[] = {
20138 [REGSET_GENERAL] = {
20139 .core_note_type = NT_PRSTATUS,
20140 .n = sizeof(struct user_regs_struct) / sizeof(long),
20141 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20142 #endif /* CONFIG_X86_64 */
20143
20144 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20145 -static struct user_regset x86_32_regsets[] __read_mostly = {
20146 +static struct user_regset x86_32_regsets[] = {
20147 [REGSET_GENERAL] = {
20148 .core_note_type = NT_PRSTATUS,
20149 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20150 @@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20151 */
20152 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20153
20154 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20155 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20156 {
20157 #ifdef CONFIG_X86_64
20158 - x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20159 + *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20160 #endif
20161 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20162 - x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20163 + *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20164 #endif
20165 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20166 }
20167 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20168 memset(info, 0, sizeof(*info));
20169 info->si_signo = SIGTRAP;
20170 info->si_code = si_code;
20171 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20172 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20173 }
20174
20175 void user_single_step_siginfo(struct task_struct *tsk,
20176 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20177 # define IS_IA32 0
20178 #endif
20179
20180 +#ifdef CONFIG_GRKERNSEC_SETXID
20181 +extern void gr_delayed_cred_worker(void);
20182 +#endif
20183 +
20184 /*
20185 * We must return the syscall number to actually look up in the table.
20186 * This can be -1L to skip running any syscall at all.
20187 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20188
20189 rcu_user_exit();
20190
20191 +#ifdef CONFIG_GRKERNSEC_SETXID
20192 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20193 + gr_delayed_cred_worker();
20194 +#endif
20195 +
20196 /*
20197 * If we stepped into a sysenter/syscall insn, it trapped in
20198 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20199 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20200 */
20201 rcu_user_exit();
20202
20203 +#ifdef CONFIG_GRKERNSEC_SETXID
20204 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20205 + gr_delayed_cred_worker();
20206 +#endif
20207 +
20208 audit_syscall_exit(regs);
20209
20210 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20211 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20212 index 42eb330..139955c 100644
20213 --- a/arch/x86/kernel/pvclock.c
20214 +++ b/arch/x86/kernel/pvclock.c
20215 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20216 return pv_tsc_khz;
20217 }
20218
20219 -static atomic64_t last_value = ATOMIC64_INIT(0);
20220 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20221
20222 void pvclock_resume(void)
20223 {
20224 - atomic64_set(&last_value, 0);
20225 + atomic64_set_unchecked(&last_value, 0);
20226 }
20227
20228 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20229 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20230 * updating at the same time, and one of them could be slightly behind,
20231 * making the assumption that last_value always go forward fail to hold.
20232 */
20233 - last = atomic64_read(&last_value);
20234 + last = atomic64_read_unchecked(&last_value);
20235 do {
20236 if (ret < last)
20237 return last;
20238 - last = atomic64_cmpxchg(&last_value, last, ret);
20239 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20240 } while (unlikely(last != ret));
20241
20242 return ret;
20243 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20244 index 4e8ba39..e0186b3 100644
20245 --- a/arch/x86/kernel/reboot.c
20246 +++ b/arch/x86/kernel/reboot.c
20247 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20248 EXPORT_SYMBOL(pm_power_off);
20249
20250 static const struct desc_ptr no_idt = {};
20251 -static int reboot_mode;
20252 +static unsigned short reboot_mode;
20253 enum reboot_type reboot_type = BOOT_ACPI;
20254 int reboot_force;
20255
20256 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20257
20258 void __noreturn machine_real_restart(unsigned int type)
20259 {
20260 +
20261 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20262 + struct desc_struct *gdt;
20263 +#endif
20264 +
20265 local_irq_disable();
20266
20267 /*
20268 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20269
20270 /* Jump to the identity-mapped low memory code */
20271 #ifdef CONFIG_X86_32
20272 - asm volatile("jmpl *%0" : :
20273 +
20274 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20275 + gdt = get_cpu_gdt_table(smp_processor_id());
20276 + pax_open_kernel();
20277 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20278 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20279 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20280 + loadsegment(ds, __KERNEL_DS);
20281 + loadsegment(es, __KERNEL_DS);
20282 + loadsegment(ss, __KERNEL_DS);
20283 +#endif
20284 +#ifdef CONFIG_PAX_KERNEXEC
20285 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20286 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20287 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20288 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20289 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20290 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20291 +#endif
20292 + pax_close_kernel();
20293 +#endif
20294 +
20295 + asm volatile("ljmpl *%0" : :
20296 "rm" (real_mode_header->machine_real_restart_asm),
20297 "a" (type));
20298 #else
20299 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20300 * try to force a triple fault and then cycle between hitting the keyboard
20301 * controller and doing that
20302 */
20303 -static void native_machine_emergency_restart(void)
20304 +static void __noreturn native_machine_emergency_restart(void)
20305 {
20306 int i;
20307 int attempt = 0;
20308 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20309 #endif
20310 }
20311
20312 -static void __machine_emergency_restart(int emergency)
20313 +static void __noreturn __machine_emergency_restart(int emergency)
20314 {
20315 reboot_emergency = emergency;
20316 machine_ops.emergency_restart();
20317 }
20318
20319 -static void native_machine_restart(char *__unused)
20320 +static void __noreturn native_machine_restart(char *__unused)
20321 {
20322 pr_notice("machine restart\n");
20323
20324 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20325 __machine_emergency_restart(0);
20326 }
20327
20328 -static void native_machine_halt(void)
20329 +static void __noreturn native_machine_halt(void)
20330 {
20331 /* Stop other cpus and apics */
20332 machine_shutdown();
20333 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20334 stop_this_cpu(NULL);
20335 }
20336
20337 -static void native_machine_power_off(void)
20338 +static void __noreturn native_machine_power_off(void)
20339 {
20340 if (pm_power_off) {
20341 if (!reboot_force)
20342 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20343 }
20344 /* A fallback in case there is no PM info available */
20345 tboot_shutdown(TB_SHUTDOWN_HALT);
20346 + unreachable();
20347 }
20348
20349 struct machine_ops machine_ops = {
20350 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20351 index 7a6f3b3..bed145d7 100644
20352 --- a/arch/x86/kernel/relocate_kernel_64.S
20353 +++ b/arch/x86/kernel/relocate_kernel_64.S
20354 @@ -11,6 +11,7 @@
20355 #include <asm/kexec.h>
20356 #include <asm/processor-flags.h>
20357 #include <asm/pgtable_types.h>
20358 +#include <asm/alternative-asm.h>
20359
20360 /*
20361 * Must be relocatable PIC code callable as a C function
20362 @@ -160,13 +161,14 @@ identity_mapped:
20363 xorq %rbp, %rbp
20364 xorq %r8, %r8
20365 xorq %r9, %r9
20366 - xorq %r10, %r9
20367 + xorq %r10, %r10
20368 xorq %r11, %r11
20369 xorq %r12, %r12
20370 xorq %r13, %r13
20371 xorq %r14, %r14
20372 xorq %r15, %r15
20373
20374 + pax_force_retaddr 0, 1
20375 ret
20376
20377 1:
20378 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20379 index 86c524c..bae70c5 100644
20380 --- a/arch/x86/kernel/setup.c
20381 +++ b/arch/x86/kernel/setup.c
20382 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20383
20384 switch (data->type) {
20385 case SETUP_E820_EXT:
20386 - parse_e820_ext(data);
20387 + parse_e820_ext((struct setup_data __force_kernel *)data);
20388 break;
20389 case SETUP_DTB:
20390 add_dtb(pa_data);
20391 @@ -708,7 +708,7 @@ static void __init trim_bios_range(void)
20392 * area (640->1Mb) as ram even though it is not.
20393 * take them out.
20394 */
20395 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20396 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20397
20398 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20399 }
20400 @@ -832,14 +832,14 @@ void __init setup_arch(char **cmdline_p)
20401
20402 if (!boot_params.hdr.root_flags)
20403 root_mountflags &= ~MS_RDONLY;
20404 - init_mm.start_code = (unsigned long) _text;
20405 - init_mm.end_code = (unsigned long) _etext;
20406 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20407 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20408 init_mm.end_data = (unsigned long) _edata;
20409 init_mm.brk = _brk_end;
20410
20411 - code_resource.start = virt_to_phys(_text);
20412 - code_resource.end = virt_to_phys(_etext)-1;
20413 - data_resource.start = virt_to_phys(_etext);
20414 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20415 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20416 + data_resource.start = virt_to_phys(_sdata);
20417 data_resource.end = virt_to_phys(_edata)-1;
20418 bss_resource.start = virt_to_phys(&__bss_start);
20419 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20420 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20421 index 5cdff03..5810740 100644
20422 --- a/arch/x86/kernel/setup_percpu.c
20423 +++ b/arch/x86/kernel/setup_percpu.c
20424 @@ -21,19 +21,17 @@
20425 #include <asm/cpu.h>
20426 #include <asm/stackprotector.h>
20427
20428 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20429 +#ifdef CONFIG_SMP
20430 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20431 EXPORT_PER_CPU_SYMBOL(cpu_number);
20432 +#endif
20433
20434 -#ifdef CONFIG_X86_64
20435 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20436 -#else
20437 -#define BOOT_PERCPU_OFFSET 0
20438 -#endif
20439
20440 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20441 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20442
20443 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20444 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20445 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20446 };
20447 EXPORT_SYMBOL(__per_cpu_offset);
20448 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20449 {
20450 #ifdef CONFIG_X86_32
20451 struct desc_struct gdt;
20452 + unsigned long base = per_cpu_offset(cpu);
20453
20454 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20455 - 0x2 | DESCTYPE_S, 0x8);
20456 - gdt.s = 1;
20457 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20458 + 0x83 | DESCTYPE_S, 0xC);
20459 write_gdt_entry(get_cpu_gdt_table(cpu),
20460 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20461 #endif
20462 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20463 /* alrighty, percpu areas up and running */
20464 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20465 for_each_possible_cpu(cpu) {
20466 +#ifdef CONFIG_CC_STACKPROTECTOR
20467 +#ifdef CONFIG_X86_32
20468 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20469 +#endif
20470 +#endif
20471 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20472 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20473 per_cpu(cpu_number, cpu) = cpu;
20474 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20475 */
20476 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20477 #endif
20478 +#ifdef CONFIG_CC_STACKPROTECTOR
20479 +#ifdef CONFIG_X86_32
20480 + if (!cpu)
20481 + per_cpu(stack_canary.canary, cpu) = canary;
20482 +#endif
20483 +#endif
20484 /*
20485 * Up to this point, the boot CPU has been using .init.data
20486 * area. Reload any changed state for the boot CPU.
20487 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20488 index 70b27ee..fcf827f 100644
20489 --- a/arch/x86/kernel/signal.c
20490 +++ b/arch/x86/kernel/signal.c
20491 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20492 * Align the stack pointer according to the i386 ABI,
20493 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20494 */
20495 - sp = ((sp + 4) & -16ul) - 4;
20496 + sp = ((sp - 12) & -16ul) - 4;
20497 #else /* !CONFIG_X86_32 */
20498 sp = round_down(sp, 16) - 8;
20499 #endif
20500 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20501 }
20502
20503 if (current->mm->context.vdso)
20504 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20505 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20506 else
20507 - restorer = &frame->retcode;
20508 + restorer = (void __user *)&frame->retcode;
20509 if (ka->sa.sa_flags & SA_RESTORER)
20510 restorer = ka->sa.sa_restorer;
20511
20512 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20513 * reasons and because gdb uses it as a signature to notice
20514 * signal handler stack frames.
20515 */
20516 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20517 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20518
20519 if (err)
20520 return -EFAULT;
20521 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20522 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20523
20524 /* Set up to return from userspace. */
20525 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20526 + if (current->mm->context.vdso)
20527 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20528 + else
20529 + restorer = (void __user *)&frame->retcode;
20530 if (ka->sa.sa_flags & SA_RESTORER)
20531 restorer = ka->sa.sa_restorer;
20532 put_user_ex(restorer, &frame->pretcode);
20533 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20534 * reasons and because gdb uses it as a signature to notice
20535 * signal handler stack frames.
20536 */
20537 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20538 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20539 } put_user_catch(err);
20540
20541 err |= copy_siginfo_to_user(&frame->info, info);
20542 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20543 index f3e2ec8..ad5287a 100644
20544 --- a/arch/x86/kernel/smpboot.c
20545 +++ b/arch/x86/kernel/smpboot.c
20546 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20547 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20548 (THREAD_SIZE + task_stack_page(idle))) - 1);
20549 per_cpu(current_task, cpu) = idle;
20550 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20551
20552 #ifdef CONFIG_X86_32
20553 /* Stack for startup_32 can be just as for start_secondary onwards */
20554 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20555 #else
20556 clear_tsk_thread_flag(idle, TIF_FORK);
20557 initial_gs = per_cpu_offset(cpu);
20558 - per_cpu(kernel_stack, cpu) =
20559 - (unsigned long)task_stack_page(idle) -
20560 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20561 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20562 #endif
20563 +
20564 + pax_open_kernel();
20565 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20566 + pax_close_kernel();
20567 +
20568 initial_code = (unsigned long)start_secondary;
20569 stack_start = idle->thread.sp;
20570
20571 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20572 /* the FPU context is blank, nobody can own it */
20573 __cpu_disable_lazy_restore(cpu);
20574
20575 +#ifdef CONFIG_PAX_PER_CPU_PGD
20576 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20577 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20578 + KERNEL_PGD_PTRS);
20579 +#endif
20580 +
20581 + /* the FPU context is blank, nobody can own it */
20582 + __cpu_disable_lazy_restore(cpu);
20583 +
20584 err = do_boot_cpu(apicid, cpu, tidle);
20585 if (err) {
20586 pr_debug("do_boot_cpu failed %d\n", err);
20587 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20588 index 9b4d51d..5d28b58 100644
20589 --- a/arch/x86/kernel/step.c
20590 +++ b/arch/x86/kernel/step.c
20591 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20592 struct desc_struct *desc;
20593 unsigned long base;
20594
20595 - seg &= ~7UL;
20596 + seg >>= 3;
20597
20598 mutex_lock(&child->mm->context.lock);
20599 - if (unlikely((seg >> 3) >= child->mm->context.size))
20600 + if (unlikely(seg >= child->mm->context.size))
20601 addr = -1L; /* bogus selector, access would fault */
20602 else {
20603 desc = child->mm->context.ldt + seg;
20604 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20605 addr += base;
20606 }
20607 mutex_unlock(&child->mm->context.lock);
20608 - }
20609 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20610 + addr = ktla_ktva(addr);
20611
20612 return addr;
20613 }
20614 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20615 unsigned char opcode[15];
20616 unsigned long addr = convert_ip_to_linear(child, regs);
20617
20618 + if (addr == -EINVAL)
20619 + return 0;
20620 +
20621 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20622 for (i = 0; i < copied; i++) {
20623 switch (opcode[i]) {
20624 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20625 new file mode 100644
20626 index 0000000..26bb1af
20627 --- /dev/null
20628 +++ b/arch/x86/kernel/sys_i386_32.c
20629 @@ -0,0 +1,249 @@
20630 +/*
20631 + * This file contains various random system calls that
20632 + * have a non-standard calling sequence on the Linux/i386
20633 + * platform.
20634 + */
20635 +
20636 +#include <linux/errno.h>
20637 +#include <linux/sched.h>
20638 +#include <linux/mm.h>
20639 +#include <linux/fs.h>
20640 +#include <linux/smp.h>
20641 +#include <linux/sem.h>
20642 +#include <linux/msg.h>
20643 +#include <linux/shm.h>
20644 +#include <linux/stat.h>
20645 +#include <linux/syscalls.h>
20646 +#include <linux/mman.h>
20647 +#include <linux/file.h>
20648 +#include <linux/utsname.h>
20649 +#include <linux/ipc.h>
20650 +
20651 +#include <linux/uaccess.h>
20652 +#include <linux/unistd.h>
20653 +
20654 +#include <asm/syscalls.h>
20655 +
20656 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20657 +{
20658 + unsigned long pax_task_size = TASK_SIZE;
20659 +
20660 +#ifdef CONFIG_PAX_SEGMEXEC
20661 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20662 + pax_task_size = SEGMEXEC_TASK_SIZE;
20663 +#endif
20664 +
20665 + if (len > pax_task_size || addr > pax_task_size - len)
20666 + return -EINVAL;
20667 +
20668 + return 0;
20669 +}
20670 +
20671 +unsigned long
20672 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20673 + unsigned long len, unsigned long pgoff, unsigned long flags)
20674 +{
20675 + struct mm_struct *mm = current->mm;
20676 + struct vm_area_struct *vma;
20677 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20678 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20679 +
20680 +#ifdef CONFIG_PAX_SEGMEXEC
20681 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20682 + pax_task_size = SEGMEXEC_TASK_SIZE;
20683 +#endif
20684 +
20685 + pax_task_size -= PAGE_SIZE;
20686 +
20687 + if (len > pax_task_size)
20688 + return -ENOMEM;
20689 +
20690 + if (flags & MAP_FIXED)
20691 + return addr;
20692 +
20693 +#ifdef CONFIG_PAX_RANDMMAP
20694 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20695 +#endif
20696 +
20697 + if (addr) {
20698 + addr = PAGE_ALIGN(addr);
20699 + if (pax_task_size - len >= addr) {
20700 + vma = find_vma(mm, addr);
20701 + if (check_heap_stack_gap(vma, addr, len, offset))
20702 + return addr;
20703 + }
20704 + }
20705 + if (len > mm->cached_hole_size) {
20706 + start_addr = addr = mm->free_area_cache;
20707 + } else {
20708 + start_addr = addr = mm->mmap_base;
20709 + mm->cached_hole_size = 0;
20710 + }
20711 +
20712 +#ifdef CONFIG_PAX_PAGEEXEC
20713 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20714 + start_addr = 0x00110000UL;
20715 +
20716 +#ifdef CONFIG_PAX_RANDMMAP
20717 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20718 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20719 +#endif
20720 +
20721 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20722 + start_addr = addr = mm->mmap_base;
20723 + else
20724 + addr = start_addr;
20725 + }
20726 +#endif
20727 +
20728 +full_search:
20729 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20730 + /* At this point: (!vma || addr < vma->vm_end). */
20731 + if (pax_task_size - len < addr) {
20732 + /*
20733 + * Start a new search - just in case we missed
20734 + * some holes.
20735 + */
20736 + if (start_addr != mm->mmap_base) {
20737 + start_addr = addr = mm->mmap_base;
20738 + mm->cached_hole_size = 0;
20739 + goto full_search;
20740 + }
20741 + return -ENOMEM;
20742 + }
20743 + if (check_heap_stack_gap(vma, addr, len, offset))
20744 + break;
20745 + if (addr + mm->cached_hole_size < vma->vm_start)
20746 + mm->cached_hole_size = vma->vm_start - addr;
20747 + addr = vma->vm_end;
20748 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20749 + start_addr = addr = mm->mmap_base;
20750 + mm->cached_hole_size = 0;
20751 + goto full_search;
20752 + }
20753 + }
20754 +
20755 + /*
20756 + * Remember the place where we stopped the search:
20757 + */
20758 + mm->free_area_cache = addr + len;
20759 + return addr;
20760 +}
20761 +
20762 +unsigned long
20763 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20764 + const unsigned long len, const unsigned long pgoff,
20765 + const unsigned long flags)
20766 +{
20767 + struct vm_area_struct *vma;
20768 + struct mm_struct *mm = current->mm;
20769 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20770 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20771 +
20772 +#ifdef CONFIG_PAX_SEGMEXEC
20773 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20774 + pax_task_size = SEGMEXEC_TASK_SIZE;
20775 +#endif
20776 +
20777 + pax_task_size -= PAGE_SIZE;
20778 +
20779 + /* requested length too big for entire address space */
20780 + if (len > pax_task_size)
20781 + return -ENOMEM;
20782 +
20783 + if (flags & MAP_FIXED)
20784 + return addr;
20785 +
20786 +#ifdef CONFIG_PAX_PAGEEXEC
20787 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20788 + goto bottomup;
20789 +#endif
20790 +
20791 +#ifdef CONFIG_PAX_RANDMMAP
20792 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20793 +#endif
20794 +
20795 + /* requesting a specific address */
20796 + if (addr) {
20797 + addr = PAGE_ALIGN(addr);
20798 + if (pax_task_size - len >= addr) {
20799 + vma = find_vma(mm, addr);
20800 + if (check_heap_stack_gap(vma, addr, len, offset))
20801 + return addr;
20802 + }
20803 + }
20804 +
20805 + /* check if free_area_cache is useful for us */
20806 + if (len <= mm->cached_hole_size) {
20807 + mm->cached_hole_size = 0;
20808 + mm->free_area_cache = mm->mmap_base;
20809 + }
20810 +
20811 + /* either no address requested or can't fit in requested address hole */
20812 + addr = mm->free_area_cache;
20813 +
20814 + /* make sure it can fit in the remaining address space */
20815 + if (addr > len) {
20816 + vma = find_vma(mm, addr-len);
20817 + if (check_heap_stack_gap(vma, addr - len, len, offset))
20818 + /* remember the address as a hint for next time */
20819 + return (mm->free_area_cache = addr-len);
20820 + }
20821 +
20822 + if (mm->mmap_base < len)
20823 + goto bottomup;
20824 +
20825 + addr = mm->mmap_base-len;
20826 +
20827 + do {
20828 + /*
20829 + * Lookup failure means no vma is above this address,
20830 + * else if new region fits below vma->vm_start,
20831 + * return with success:
20832 + */
20833 + vma = find_vma(mm, addr);
20834 + if (check_heap_stack_gap(vma, addr, len, offset))
20835 + /* remember the address as a hint for next time */
20836 + return (mm->free_area_cache = addr);
20837 +
20838 + /* remember the largest hole we saw so far */
20839 + if (addr + mm->cached_hole_size < vma->vm_start)
20840 + mm->cached_hole_size = vma->vm_start - addr;
20841 +
20842 + /* try just below the current vma->vm_start */
20843 + addr = skip_heap_stack_gap(vma, len, offset);
20844 + } while (!IS_ERR_VALUE(addr));
20845 +
20846 +bottomup:
20847 + /*
20848 + * A failed mmap() very likely causes application failure,
20849 + * so fall back to the bottom-up function here. This scenario
20850 + * can happen with large stack limits and large mmap()
20851 + * allocations.
20852 + */
20853 +
20854 +#ifdef CONFIG_PAX_SEGMEXEC
20855 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20856 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20857 + else
20858 +#endif
20859 +
20860 + mm->mmap_base = TASK_UNMAPPED_BASE;
20861 +
20862 +#ifdef CONFIG_PAX_RANDMMAP
20863 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20864 + mm->mmap_base += mm->delta_mmap;
20865 +#endif
20866 +
20867 + mm->free_area_cache = mm->mmap_base;
20868 + mm->cached_hole_size = ~0UL;
20869 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20870 + /*
20871 + * Restore the topdown base:
20872 + */
20873 + mm->mmap_base = base;
20874 + mm->free_area_cache = base;
20875 + mm->cached_hole_size = ~0UL;
20876 +
20877 + return addr;
20878 +}
20879 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20880 index b4d3c39..d699d77 100644
20881 --- a/arch/x86/kernel/sys_x86_64.c
20882 +++ b/arch/x86/kernel/sys_x86_64.c
20883 @@ -95,8 +95,8 @@ out:
20884 return error;
20885 }
20886
20887 -static void find_start_end(unsigned long flags, unsigned long *begin,
20888 - unsigned long *end)
20889 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20890 + unsigned long *begin, unsigned long *end)
20891 {
20892 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20893 unsigned long new_begin;
20894 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20895 *begin = new_begin;
20896 }
20897 } else {
20898 - *begin = TASK_UNMAPPED_BASE;
20899 + *begin = mm->mmap_base;
20900 *end = TASK_SIZE;
20901 }
20902 }
20903 @@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20904 struct vm_area_struct *vma;
20905 unsigned long start_addr;
20906 unsigned long begin, end;
20907 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20908
20909 if (flags & MAP_FIXED)
20910 return addr;
20911
20912 - find_start_end(flags, &begin, &end);
20913 + find_start_end(mm, flags, &begin, &end);
20914
20915 if (len > end)
20916 return -ENOMEM;
20917
20918 +#ifdef CONFIG_PAX_RANDMMAP
20919 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20920 +#endif
20921 +
20922 if (addr) {
20923 addr = PAGE_ALIGN(addr);
20924 vma = find_vma(mm, addr);
20925 - if (end - len >= addr &&
20926 - (!vma || addr + len <= vma->vm_start))
20927 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20928 return addr;
20929 }
20930 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20931 @@ -172,7 +176,7 @@ full_search:
20932 }
20933 return -ENOMEM;
20934 }
20935 - if (!vma || addr + len <= vma->vm_start) {
20936 + if (check_heap_stack_gap(vma, addr, len, offset)) {
20937 /*
20938 * Remember the place where we stopped the search:
20939 */
20940 @@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20941 {
20942 struct vm_area_struct *vma;
20943 struct mm_struct *mm = current->mm;
20944 - unsigned long addr = addr0, start_addr;
20945 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20946 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20947
20948 /* requested length too big for entire address space */
20949 if (len > TASK_SIZE)
20950 @@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20951 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20952 goto bottomup;
20953
20954 +#ifdef CONFIG_PAX_RANDMMAP
20955 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20956 +#endif
20957 +
20958 /* requesting a specific address */
20959 if (addr) {
20960 addr = PAGE_ALIGN(addr);
20961 - vma = find_vma(mm, addr);
20962 - if (TASK_SIZE - len >= addr &&
20963 - (!vma || addr + len <= vma->vm_start))
20964 - return addr;
20965 + if (TASK_SIZE - len >= addr) {
20966 + vma = find_vma(mm, addr);
20967 + if (check_heap_stack_gap(vma, addr, len, offset))
20968 + return addr;
20969 + }
20970 }
20971
20972 /* check if free_area_cache is useful for us */
20973 @@ -240,7 +250,7 @@ try_again:
20974 * return with success:
20975 */
20976 vma = find_vma(mm, addr);
20977 - if (!vma || addr+len <= vma->vm_start)
20978 + if (check_heap_stack_gap(vma, addr, len, offset))
20979 /* remember the address as a hint for next time */
20980 return mm->free_area_cache = addr;
20981
20982 @@ -249,8 +259,8 @@ try_again:
20983 mm->cached_hole_size = vma->vm_start - addr;
20984
20985 /* try just below the current vma->vm_start */
20986 - addr = vma->vm_start-len;
20987 - } while (len < vma->vm_start);
20988 + addr = skip_heap_stack_gap(vma, len, offset);
20989 + } while (!IS_ERR_VALUE(addr));
20990
20991 fail:
20992 /*
20993 @@ -270,13 +280,21 @@ bottomup:
20994 * can happen with large stack limits and large mmap()
20995 * allocations.
20996 */
20997 + mm->mmap_base = TASK_UNMAPPED_BASE;
20998 +
20999 +#ifdef CONFIG_PAX_RANDMMAP
21000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21001 + mm->mmap_base += mm->delta_mmap;
21002 +#endif
21003 +
21004 + mm->free_area_cache = mm->mmap_base;
21005 mm->cached_hole_size = ~0UL;
21006 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21007 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21008 /*
21009 * Restore the topdown base:
21010 */
21011 - mm->free_area_cache = mm->mmap_base;
21012 + mm->mmap_base = base;
21013 + mm->free_area_cache = base;
21014 mm->cached_hole_size = ~0UL;
21015
21016 return addr;
21017 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21018 index f84fe00..93fe08f 100644
21019 --- a/arch/x86/kernel/tboot.c
21020 +++ b/arch/x86/kernel/tboot.c
21021 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21022
21023 void tboot_shutdown(u32 shutdown_type)
21024 {
21025 - void (*shutdown)(void);
21026 + void (* __noreturn shutdown)(void);
21027
21028 if (!tboot_enabled())
21029 return;
21030 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21031
21032 switch_to_tboot_pt();
21033
21034 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21035 + shutdown = (void *)tboot->shutdown_entry;
21036 shutdown();
21037
21038 /* should not reach here */
21039 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21040 return 0;
21041 }
21042
21043 -static atomic_t ap_wfs_count;
21044 +static atomic_unchecked_t ap_wfs_count;
21045
21046 static int tboot_wait_for_aps(int num_aps)
21047 {
21048 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21049 {
21050 switch (action) {
21051 case CPU_DYING:
21052 - atomic_inc(&ap_wfs_count);
21053 + atomic_inc_unchecked(&ap_wfs_count);
21054 if (num_online_cpus() == 1)
21055 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21056 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21057 return NOTIFY_BAD;
21058 break;
21059 }
21060 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21061
21062 tboot_create_trampoline();
21063
21064 - atomic_set(&ap_wfs_count, 0);
21065 + atomic_set_unchecked(&ap_wfs_count, 0);
21066 register_hotcpu_notifier(&tboot_cpu_notifier);
21067
21068 acpi_os_set_prepare_sleep(&tboot_sleep);
21069 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21070 index 24d3c91..d06b473 100644
21071 --- a/arch/x86/kernel/time.c
21072 +++ b/arch/x86/kernel/time.c
21073 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21074 {
21075 unsigned long pc = instruction_pointer(regs);
21076
21077 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21078 + if (!user_mode(regs) && in_lock_functions(pc)) {
21079 #ifdef CONFIG_FRAME_POINTER
21080 - return *(unsigned long *)(regs->bp + sizeof(long));
21081 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21082 #else
21083 unsigned long *sp =
21084 (unsigned long *)kernel_stack_pointer(regs);
21085 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21086 * or above a saved flags. Eflags has bits 22-31 zero,
21087 * kernel addresses don't.
21088 */
21089 +
21090 +#ifdef CONFIG_PAX_KERNEXEC
21091 + return ktla_ktva(sp[0]);
21092 +#else
21093 if (sp[0] >> 22)
21094 return sp[0];
21095 if (sp[1] >> 22)
21096 return sp[1];
21097 #endif
21098 +
21099 +#endif
21100 }
21101 return pc;
21102 }
21103 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21104 index 9d9d2f9..cad418a 100644
21105 --- a/arch/x86/kernel/tls.c
21106 +++ b/arch/x86/kernel/tls.c
21107 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21108 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21109 return -EINVAL;
21110
21111 +#ifdef CONFIG_PAX_SEGMEXEC
21112 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21113 + return -EINVAL;
21114 +#endif
21115 +
21116 set_tls_desc(p, idx, &info, 1);
21117
21118 return 0;
21119 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21120
21121 if (kbuf)
21122 info = kbuf;
21123 - else if (__copy_from_user(infobuf, ubuf, count))
21124 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21125 return -EFAULT;
21126 else
21127 info = infobuf;
21128 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21129 index 8276dc6..4ca48a2 100644
21130 --- a/arch/x86/kernel/traps.c
21131 +++ b/arch/x86/kernel/traps.c
21132 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21133
21134 /* Do we ignore FPU interrupts ? */
21135 char ignore_fpu_irq;
21136 -
21137 -/*
21138 - * The IDT has to be page-aligned to simplify the Pentium
21139 - * F0 0F bug workaround.
21140 - */
21141 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21142 #endif
21143
21144 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21145 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21146 }
21147
21148 static int __kprobes
21149 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21150 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21151 struct pt_regs *regs, long error_code)
21152 {
21153 #ifdef CONFIG_X86_32
21154 - if (regs->flags & X86_VM_MASK) {
21155 + if (v8086_mode(regs)) {
21156 /*
21157 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21158 * On nmi (interrupt 2), do_trap should not be called.
21159 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21160 return -1;
21161 }
21162 #endif
21163 - if (!user_mode(regs)) {
21164 + if (!user_mode_novm(regs)) {
21165 if (!fixup_exception(regs)) {
21166 tsk->thread.error_code = error_code;
21167 tsk->thread.trap_nr = trapnr;
21168 +
21169 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21170 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21171 + str = "PAX: suspicious stack segment fault";
21172 +#endif
21173 +
21174 die(str, regs, error_code);
21175 }
21176 +
21177 +#ifdef CONFIG_PAX_REFCOUNT
21178 + if (trapnr == 4)
21179 + pax_report_refcount_overflow(regs);
21180 +#endif
21181 +
21182 return 0;
21183 }
21184
21185 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21186 }
21187
21188 static void __kprobes
21189 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21190 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21191 long error_code, siginfo_t *info)
21192 {
21193 struct task_struct *tsk = current;
21194 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21195 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21196 printk_ratelimit()) {
21197 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21198 - tsk->comm, tsk->pid, str,
21199 + tsk->comm, task_pid_nr(tsk), str,
21200 regs->ip, regs->sp, error_code);
21201 print_vma_addr(" in ", regs->ip);
21202 pr_cont("\n");
21203 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21204 conditional_sti(regs);
21205
21206 #ifdef CONFIG_X86_32
21207 - if (regs->flags & X86_VM_MASK) {
21208 + if (v8086_mode(regs)) {
21209 local_irq_enable();
21210 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21211 goto exit;
21212 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21213 #endif
21214
21215 tsk = current;
21216 - if (!user_mode(regs)) {
21217 + if (!user_mode_novm(regs)) {
21218 if (fixup_exception(regs))
21219 goto exit;
21220
21221 tsk->thread.error_code = error_code;
21222 tsk->thread.trap_nr = X86_TRAP_GP;
21223 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21224 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21225 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21226 +
21227 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21228 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21229 + die("PAX: suspicious general protection fault", regs, error_code);
21230 + else
21231 +#endif
21232 +
21233 die("general protection fault", regs, error_code);
21234 + }
21235 goto exit;
21236 }
21237
21238 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21239 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21240 + struct mm_struct *mm = tsk->mm;
21241 + unsigned long limit;
21242 +
21243 + down_write(&mm->mmap_sem);
21244 + limit = mm->context.user_cs_limit;
21245 + if (limit < TASK_SIZE) {
21246 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21247 + up_write(&mm->mmap_sem);
21248 + return;
21249 + }
21250 + up_write(&mm->mmap_sem);
21251 + }
21252 +#endif
21253 +
21254 tsk->thread.error_code = error_code;
21255 tsk->thread.trap_nr = X86_TRAP_GP;
21256
21257 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21258 /* It's safe to allow irq's after DR6 has been saved */
21259 preempt_conditional_sti(regs);
21260
21261 - if (regs->flags & X86_VM_MASK) {
21262 + if (v8086_mode(regs)) {
21263 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21264 X86_TRAP_DB);
21265 preempt_conditional_cli(regs);
21266 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21267 * We already checked v86 mode above, so we can check for kernel mode
21268 * by just checking the CPL of CS.
21269 */
21270 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21271 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21272 tsk->thread.debugreg6 &= ~DR_STEP;
21273 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21274 regs->flags &= ~X86_EFLAGS_TF;
21275 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21276 return;
21277 conditional_sti(regs);
21278
21279 - if (!user_mode_vm(regs))
21280 + if (!user_mode(regs))
21281 {
21282 if (!fixup_exception(regs)) {
21283 task->thread.error_code = error_code;
21284 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21285 index aafa555..a04691a 100644
21286 --- a/arch/x86/kernel/uprobes.c
21287 +++ b/arch/x86/kernel/uprobes.c
21288 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21289 int ret = NOTIFY_DONE;
21290
21291 /* We are only interested in userspace traps */
21292 - if (regs && !user_mode_vm(regs))
21293 + if (regs && !user_mode(regs))
21294 return NOTIFY_DONE;
21295
21296 switch (val) {
21297 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21298 index b9242ba..50c5edd 100644
21299 --- a/arch/x86/kernel/verify_cpu.S
21300 +++ b/arch/x86/kernel/verify_cpu.S
21301 @@ -20,6 +20,7 @@
21302 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21303 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21304 * arch/x86/kernel/head_32.S: processor startup
21305 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21306 *
21307 * verify_cpu, returns the status of longmode and SSE in register %eax.
21308 * 0: Success 1: Failure
21309 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21310 index 5c9687b..5f857d3 100644
21311 --- a/arch/x86/kernel/vm86_32.c
21312 +++ b/arch/x86/kernel/vm86_32.c
21313 @@ -43,6 +43,7 @@
21314 #include <linux/ptrace.h>
21315 #include <linux/audit.h>
21316 #include <linux/stddef.h>
21317 +#include <linux/grsecurity.h>
21318
21319 #include <asm/uaccess.h>
21320 #include <asm/io.h>
21321 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21322 do_exit(SIGSEGV);
21323 }
21324
21325 - tss = &per_cpu(init_tss, get_cpu());
21326 + tss = init_tss + get_cpu();
21327 current->thread.sp0 = current->thread.saved_sp0;
21328 current->thread.sysenter_cs = __KERNEL_CS;
21329 load_sp0(tss, &current->thread);
21330 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21331 struct task_struct *tsk;
21332 int tmp, ret = -EPERM;
21333
21334 +#ifdef CONFIG_GRKERNSEC_VM86
21335 + if (!capable(CAP_SYS_RAWIO)) {
21336 + gr_handle_vm86();
21337 + goto out;
21338 + }
21339 +#endif
21340 +
21341 tsk = current;
21342 if (tsk->thread.saved_sp0)
21343 goto out;
21344 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21345 int tmp, ret;
21346 struct vm86plus_struct __user *v86;
21347
21348 +#ifdef CONFIG_GRKERNSEC_VM86
21349 + if (!capable(CAP_SYS_RAWIO)) {
21350 + gr_handle_vm86();
21351 + ret = -EPERM;
21352 + goto out;
21353 + }
21354 +#endif
21355 +
21356 tsk = current;
21357 switch (cmd) {
21358 case VM86_REQUEST_IRQ:
21359 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21360 tsk->thread.saved_fs = info->regs32->fs;
21361 tsk->thread.saved_gs = get_user_gs(info->regs32);
21362
21363 - tss = &per_cpu(init_tss, get_cpu());
21364 + tss = init_tss + get_cpu();
21365 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21366 if (cpu_has_sep)
21367 tsk->thread.sysenter_cs = 0;
21368 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21369 goto cannot_handle;
21370 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21371 goto cannot_handle;
21372 - intr_ptr = (unsigned long __user *) (i << 2);
21373 + intr_ptr = (__force unsigned long __user *) (i << 2);
21374 if (get_user(segoffs, intr_ptr))
21375 goto cannot_handle;
21376 if ((segoffs >> 16) == BIOSSEG)
21377 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21378 index 22a1530..8fbaaad 100644
21379 --- a/arch/x86/kernel/vmlinux.lds.S
21380 +++ b/arch/x86/kernel/vmlinux.lds.S
21381 @@ -26,6 +26,13 @@
21382 #include <asm/page_types.h>
21383 #include <asm/cache.h>
21384 #include <asm/boot.h>
21385 +#include <asm/segment.h>
21386 +
21387 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21388 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21389 +#else
21390 +#define __KERNEL_TEXT_OFFSET 0
21391 +#endif
21392
21393 #undef i386 /* in case the preprocessor is a 32bit one */
21394
21395 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21396
21397 PHDRS {
21398 text PT_LOAD FLAGS(5); /* R_E */
21399 +#ifdef CONFIG_X86_32
21400 + module PT_LOAD FLAGS(5); /* R_E */
21401 +#endif
21402 +#ifdef CONFIG_XEN
21403 + rodata PT_LOAD FLAGS(5); /* R_E */
21404 +#else
21405 + rodata PT_LOAD FLAGS(4); /* R__ */
21406 +#endif
21407 data PT_LOAD FLAGS(6); /* RW_ */
21408 -#ifdef CONFIG_X86_64
21409 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21410 #ifdef CONFIG_SMP
21411 percpu PT_LOAD FLAGS(6); /* RW_ */
21412 #endif
21413 + text.init PT_LOAD FLAGS(5); /* R_E */
21414 + text.exit PT_LOAD FLAGS(5); /* R_E */
21415 init PT_LOAD FLAGS(7); /* RWE */
21416 -#endif
21417 note PT_NOTE FLAGS(0); /* ___ */
21418 }
21419
21420 SECTIONS
21421 {
21422 #ifdef CONFIG_X86_32
21423 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21424 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21425 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21426 #else
21427 - . = __START_KERNEL;
21428 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21429 + . = __START_KERNEL;
21430 #endif
21431
21432 /* Text and read-only data */
21433 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21434 - _text = .;
21435 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21436 /* bootstrapping code */
21437 +#ifdef CONFIG_X86_32
21438 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21439 +#else
21440 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21441 +#endif
21442 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21443 + _text = .;
21444 HEAD_TEXT
21445 #ifdef CONFIG_X86_32
21446 . = ALIGN(PAGE_SIZE);
21447 @@ -108,13 +128,48 @@ SECTIONS
21448 IRQENTRY_TEXT
21449 *(.fixup)
21450 *(.gnu.warning)
21451 - /* End of text section */
21452 - _etext = .;
21453 } :text = 0x9090
21454
21455 - NOTES :text :note
21456 + . += __KERNEL_TEXT_OFFSET;
21457
21458 - EXCEPTION_TABLE(16) :text = 0x9090
21459 +#ifdef CONFIG_X86_32
21460 + . = ALIGN(PAGE_SIZE);
21461 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21462 +
21463 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21464 + MODULES_EXEC_VADDR = .;
21465 + BYTE(0)
21466 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21467 + . = ALIGN(HPAGE_SIZE) - 1;
21468 + MODULES_EXEC_END = .;
21469 +#endif
21470 +
21471 + } :module
21472 +#endif
21473 +
21474 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21475 + /* End of text section */
21476 + BYTE(0)
21477 + _etext = . - __KERNEL_TEXT_OFFSET;
21478 + }
21479 +
21480 +#ifdef CONFIG_X86_32
21481 + . = ALIGN(PAGE_SIZE);
21482 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21483 + *(.idt)
21484 + . = ALIGN(PAGE_SIZE);
21485 + *(.empty_zero_page)
21486 + *(.initial_pg_fixmap)
21487 + *(.initial_pg_pmd)
21488 + *(.initial_page_table)
21489 + *(.swapper_pg_dir)
21490 + } :rodata
21491 +#endif
21492 +
21493 + . = ALIGN(PAGE_SIZE);
21494 + NOTES :rodata :note
21495 +
21496 + EXCEPTION_TABLE(16) :rodata
21497
21498 #if defined(CONFIG_DEBUG_RODATA)
21499 /* .text should occupy whole number of pages */
21500 @@ -126,16 +181,20 @@ SECTIONS
21501
21502 /* Data */
21503 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21504 +
21505 +#ifdef CONFIG_PAX_KERNEXEC
21506 + . = ALIGN(HPAGE_SIZE);
21507 +#else
21508 + . = ALIGN(PAGE_SIZE);
21509 +#endif
21510 +
21511 /* Start of data section */
21512 _sdata = .;
21513
21514 /* init_task */
21515 INIT_TASK_DATA(THREAD_SIZE)
21516
21517 -#ifdef CONFIG_X86_32
21518 - /* 32 bit has nosave before _edata */
21519 NOSAVE_DATA
21520 -#endif
21521
21522 PAGE_ALIGNED_DATA(PAGE_SIZE)
21523
21524 @@ -176,12 +235,19 @@ SECTIONS
21525 #endif /* CONFIG_X86_64 */
21526
21527 /* Init code and data - will be freed after init */
21528 - . = ALIGN(PAGE_SIZE);
21529 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21530 + BYTE(0)
21531 +
21532 +#ifdef CONFIG_PAX_KERNEXEC
21533 + . = ALIGN(HPAGE_SIZE);
21534 +#else
21535 + . = ALIGN(PAGE_SIZE);
21536 +#endif
21537 +
21538 __init_begin = .; /* paired with __init_end */
21539 - }
21540 + } :init.begin
21541
21542 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21543 +#ifdef CONFIG_SMP
21544 /*
21545 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21546 * output PHDR, so the next output section - .init.text - should
21547 @@ -190,12 +256,27 @@ SECTIONS
21548 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21549 #endif
21550
21551 - INIT_TEXT_SECTION(PAGE_SIZE)
21552 -#ifdef CONFIG_X86_64
21553 - :init
21554 -#endif
21555 + . = ALIGN(PAGE_SIZE);
21556 + init_begin = .;
21557 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21558 + VMLINUX_SYMBOL(_sinittext) = .;
21559 + INIT_TEXT
21560 + VMLINUX_SYMBOL(_einittext) = .;
21561 + . = ALIGN(PAGE_SIZE);
21562 + } :text.init
21563
21564 - INIT_DATA_SECTION(16)
21565 + /*
21566 + * .exit.text is discard at runtime, not link time, to deal with
21567 + * references from .altinstructions and .eh_frame
21568 + */
21569 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21570 + EXIT_TEXT
21571 + . = ALIGN(16);
21572 + } :text.exit
21573 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21574 +
21575 + . = ALIGN(PAGE_SIZE);
21576 + INIT_DATA_SECTION(16) :init
21577
21578 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21579 __x86_cpu_dev_start = .;
21580 @@ -257,19 +338,12 @@ SECTIONS
21581 }
21582
21583 . = ALIGN(8);
21584 - /*
21585 - * .exit.text is discard at runtime, not link time, to deal with
21586 - * references from .altinstructions and .eh_frame
21587 - */
21588 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21589 - EXIT_TEXT
21590 - }
21591
21592 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21593 EXIT_DATA
21594 }
21595
21596 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21597 +#ifndef CONFIG_SMP
21598 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21599 #endif
21600
21601 @@ -288,16 +362,10 @@ SECTIONS
21602 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21603 __smp_locks = .;
21604 *(.smp_locks)
21605 - . = ALIGN(PAGE_SIZE);
21606 __smp_locks_end = .;
21607 + . = ALIGN(PAGE_SIZE);
21608 }
21609
21610 -#ifdef CONFIG_X86_64
21611 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21612 - NOSAVE_DATA
21613 - }
21614 -#endif
21615 -
21616 /* BSS */
21617 . = ALIGN(PAGE_SIZE);
21618 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21619 @@ -313,6 +381,7 @@ SECTIONS
21620 __brk_base = .;
21621 . += 64 * 1024; /* 64k alignment slop space */
21622 *(.brk_reservation) /* areas brk users have reserved */
21623 + . = ALIGN(HPAGE_SIZE);
21624 __brk_limit = .;
21625 }
21626
21627 @@ -339,13 +408,12 @@ SECTIONS
21628 * for the boot processor.
21629 */
21630 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21631 -INIT_PER_CPU(gdt_page);
21632 INIT_PER_CPU(irq_stack_union);
21633
21634 /*
21635 * Build-time check on the image size:
21636 */
21637 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21638 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21639 "kernel image bigger than KERNEL_IMAGE_SIZE");
21640
21641 #ifdef CONFIG_SMP
21642 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21643 index 992f890..0ab1aae 100644
21644 --- a/arch/x86/kernel/vsmp_64.c
21645 +++ b/arch/x86/kernel/vsmp_64.c
21646 @@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21647 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21648 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21649 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21650 - pv_init_ops.patch = vsmp_patch;
21651 + *(void **)&pv_init_ops.patch = vsmp_patch;
21652 ctl &= ~(1 << 4);
21653 }
21654 writel(ctl, address + 4);
21655 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21656 static void vsmp_apic_post_init(void)
21657 {
21658 /* need to update phys_pkg_id */
21659 - apic->phys_pkg_id = apicid_phys_pkg_id;
21660 - apic->vector_allocation_domain = fill_vector_allocation_domain;
21661 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21662 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21663 }
21664
21665 void __init vsmp_init(void)
21666 @@ -227,7 +227,7 @@ void __init vsmp_init(void)
21667 if (!is_vsmp_box())
21668 return;
21669
21670 - x86_platform.apic_post_init = vsmp_apic_post_init;
21671 + *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21672
21673 vsmp_cap_cpus();
21674
21675 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21676 index 3a3e8c9..1af9465 100644
21677 --- a/arch/x86/kernel/vsyscall_64.c
21678 +++ b/arch/x86/kernel/vsyscall_64.c
21679 @@ -56,15 +56,13 @@
21680 DEFINE_VVAR(int, vgetcpu_mode);
21681 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21682
21683 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21684 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21685
21686 static int __init vsyscall_setup(char *str)
21687 {
21688 if (str) {
21689 if (!strcmp("emulate", str))
21690 vsyscall_mode = EMULATE;
21691 - else if (!strcmp("native", str))
21692 - vsyscall_mode = NATIVE;
21693 else if (!strcmp("none", str))
21694 vsyscall_mode = NONE;
21695 else
21696 @@ -315,8 +313,7 @@ done:
21697 return true;
21698
21699 sigsegv:
21700 - force_sig(SIGSEGV, current);
21701 - return true;
21702 + do_group_exit(SIGKILL);
21703 }
21704
21705 /*
21706 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21707 extern char __vvar_page;
21708 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21709
21710 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21711 - vsyscall_mode == NATIVE
21712 - ? PAGE_KERNEL_VSYSCALL
21713 - : PAGE_KERNEL_VVAR);
21714 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21715 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21716 (unsigned long)VSYSCALL_START);
21717
21718 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21719 index 1330dd1..d220b99 100644
21720 --- a/arch/x86/kernel/x8664_ksyms_64.c
21721 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21722 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21723 EXPORT_SYMBOL(copy_user_generic_unrolled);
21724 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21725 EXPORT_SYMBOL(__copy_user_nocache);
21726 -EXPORT_SYMBOL(_copy_from_user);
21727 -EXPORT_SYMBOL(_copy_to_user);
21728
21729 EXPORT_SYMBOL(copy_page);
21730 EXPORT_SYMBOL(clear_page);
21731 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21732 index ada87a3..afea76d 100644
21733 --- a/arch/x86/kernel/xsave.c
21734 +++ b/arch/x86/kernel/xsave.c
21735 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21736 {
21737 int err;
21738
21739 + buf = (struct xsave_struct __user *)____m(buf);
21740 if (use_xsave())
21741 err = xsave_user(buf);
21742 else if (use_fxsr())
21743 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21744 */
21745 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21746 {
21747 + buf = (void __user *)____m(buf);
21748 if (use_xsave()) {
21749 if ((unsigned long)buf % 64 || fx_only) {
21750 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21751 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21752 index ec79e77..420f5cc 100644
21753 --- a/arch/x86/kvm/cpuid.c
21754 +++ b/arch/x86/kvm/cpuid.c
21755 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21756 struct kvm_cpuid2 *cpuid,
21757 struct kvm_cpuid_entry2 __user *entries)
21758 {
21759 - int r;
21760 + int r, i;
21761
21762 r = -E2BIG;
21763 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21764 goto out;
21765 r = -EFAULT;
21766 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21767 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21768 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21769 goto out;
21770 + for (i = 0; i < cpuid->nent; ++i) {
21771 + struct kvm_cpuid_entry2 cpuid_entry;
21772 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21773 + goto out;
21774 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21775 + }
21776 vcpu->arch.cpuid_nent = cpuid->nent;
21777 kvm_apic_set_version(vcpu);
21778 kvm_x86_ops->cpuid_update(vcpu);
21779 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21780 struct kvm_cpuid2 *cpuid,
21781 struct kvm_cpuid_entry2 __user *entries)
21782 {
21783 - int r;
21784 + int r, i;
21785
21786 r = -E2BIG;
21787 if (cpuid->nent < vcpu->arch.cpuid_nent)
21788 goto out;
21789 r = -EFAULT;
21790 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21791 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21792 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21793 goto out;
21794 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21795 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21796 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21797 + goto out;
21798 + }
21799 return 0;
21800
21801 out:
21802 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21803 index bba39bf..296540a 100644
21804 --- a/arch/x86/kvm/emulate.c
21805 +++ b/arch/x86/kvm/emulate.c
21806 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21807
21808 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21809 do { \
21810 + unsigned long _tmp; \
21811 __asm__ __volatile__ ( \
21812 _PRE_EFLAGS("0", "4", "2") \
21813 _op _suffix " %"_x"3,%1; " \
21814 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21815 /* Raw emulation: instruction has two explicit operands. */
21816 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21817 do { \
21818 - unsigned long _tmp; \
21819 - \
21820 switch ((ctxt)->dst.bytes) { \
21821 case 2: \
21822 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21823 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21824
21825 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21826 do { \
21827 - unsigned long _tmp; \
21828 switch ((ctxt)->dst.bytes) { \
21829 case 1: \
21830 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21831 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21832 index 43e9fad..3b7c059 100644
21833 --- a/arch/x86/kvm/lapic.c
21834 +++ b/arch/x86/kvm/lapic.c
21835 @@ -55,7 +55,7 @@
21836 #define APIC_BUS_CYCLE_NS 1
21837
21838 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21839 -#define apic_debug(fmt, arg...)
21840 +#define apic_debug(fmt, arg...) do {} while (0)
21841
21842 #define APIC_LVT_NUM 6
21843 /* 14 is the version for Xeon and Pentium 8.4.8*/
21844 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21845 index 714e2c0..3f7a086 100644
21846 --- a/arch/x86/kvm/paging_tmpl.h
21847 +++ b/arch/x86/kvm/paging_tmpl.h
21848 @@ -208,7 +208,7 @@ retry_walk:
21849 if (unlikely(kvm_is_error_hva(host_addr)))
21850 goto error;
21851
21852 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21853 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21854 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21855 goto error;
21856 walker->ptep_user[walker->level - 1] = ptep_user;
21857 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21858 index d017df3..61ae42e 100644
21859 --- a/arch/x86/kvm/svm.c
21860 +++ b/arch/x86/kvm/svm.c
21861 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21862 int cpu = raw_smp_processor_id();
21863
21864 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21865 +
21866 + pax_open_kernel();
21867 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21868 + pax_close_kernel();
21869 +
21870 load_TR_desc();
21871 }
21872
21873 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21874 #endif
21875 #endif
21876
21877 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21878 + __set_fs(current_thread_info()->addr_limit);
21879 +#endif
21880 +
21881 reload_tss(vcpu);
21882
21883 local_irq_disable();
21884 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21885 index f858159..4ab7dba 100644
21886 --- a/arch/x86/kvm/vmx.c
21887 +++ b/arch/x86/kvm/vmx.c
21888 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21889 struct desc_struct *descs;
21890
21891 descs = (void *)gdt->address;
21892 +
21893 + pax_open_kernel();
21894 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21895 + pax_close_kernel();
21896 +
21897 load_TR_desc();
21898 }
21899
21900 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21901 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21902 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21903
21904 +#ifdef CONFIG_PAX_PER_CPU_PGD
21905 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21906 +#endif
21907 +
21908 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21909 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21910 vmx->loaded_vmcs->cpu = cpu;
21911 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21912 if (!cpu_has_vmx_flexpriority())
21913 flexpriority_enabled = 0;
21914
21915 - if (!cpu_has_vmx_tpr_shadow())
21916 - kvm_x86_ops->update_cr8_intercept = NULL;
21917 + if (!cpu_has_vmx_tpr_shadow()) {
21918 + pax_open_kernel();
21919 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21920 + pax_close_kernel();
21921 + }
21922
21923 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21924 kvm_disable_largepages();
21925 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21926
21927 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21928 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21929 +
21930 +#ifndef CONFIG_PAX_PER_CPU_PGD
21931 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21932 +#endif
21933
21934 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21935 #ifdef CONFIG_X86_64
21936 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21937 native_store_idt(&dt);
21938 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21939
21940 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21941 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21942
21943 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21944 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21945 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21946 "jmp 2f \n\t"
21947 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21948 "2: "
21949 +
21950 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21951 + "ljmp %[cs],$3f\n\t"
21952 + "3: "
21953 +#endif
21954 +
21955 /* Save guest registers, load host registers, keep flags */
21956 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
21957 "pop %0 \n\t"
21958 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21959 #endif
21960 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
21961 [wordsize]"i"(sizeof(ulong))
21962 +
21963 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21964 + ,[cs]"i"(__KERNEL_CS)
21965 +#endif
21966 +
21967 : "cc", "memory"
21968 #ifdef CONFIG_X86_64
21969 , "rax", "rbx", "rdi", "rsi"
21970 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21971 if (debugctlmsr)
21972 update_debugctlmsr(debugctlmsr);
21973
21974 -#ifndef CONFIG_X86_64
21975 +#ifdef CONFIG_X86_32
21976 /*
21977 * The sysexit path does not restore ds/es, so we must set them to
21978 * a reasonable value ourselves.
21979 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21980 * may be executed in interrupt context, which saves and restore segments
21981 * around it, nullifying its effect.
21982 */
21983 - loadsegment(ds, __USER_DS);
21984 - loadsegment(es, __USER_DS);
21985 + loadsegment(ds, __KERNEL_DS);
21986 + loadsegment(es, __KERNEL_DS);
21987 + loadsegment(ss, __KERNEL_DS);
21988 +
21989 +#ifdef CONFIG_PAX_KERNEXEC
21990 + loadsegment(fs, __KERNEL_PERCPU);
21991 +#endif
21992 +
21993 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21994 + __set_fs(current_thread_info()->addr_limit);
21995 +#endif
21996 +
21997 #endif
21998
21999 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22000 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22001 index 4f76417..93429b5 100644
22002 --- a/arch/x86/kvm/x86.c
22003 +++ b/arch/x86/kvm/x86.c
22004 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22005 {
22006 struct kvm *kvm = vcpu->kvm;
22007 int lm = is_long_mode(vcpu);
22008 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22009 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22010 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22011 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22012 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22013 : kvm->arch.xen_hvm_config.blob_size_32;
22014 u32 page_num = data & ~PAGE_MASK;
22015 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22016 if (n < msr_list.nmsrs)
22017 goto out;
22018 r = -EFAULT;
22019 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22020 + goto out;
22021 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22022 num_msrs_to_save * sizeof(u32)))
22023 goto out;
22024 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22025 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22026 struct kvm_interrupt *irq)
22027 {
22028 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22029 + if (irq->irq >= KVM_NR_INTERRUPTS)
22030 return -EINVAL;
22031 if (irqchip_in_kernel(vcpu->kvm))
22032 return -ENXIO;
22033 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22034 kvm_mmu_set_mmio_spte_mask(mask);
22035 }
22036
22037 -int kvm_arch_init(void *opaque)
22038 +int kvm_arch_init(const void *opaque)
22039 {
22040 int r;
22041 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22042 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22043 index 642d880..5dd034e 100644
22044 --- a/arch/x86/lguest/boot.c
22045 +++ b/arch/x86/lguest/boot.c
22046 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22047
22048 static void set_lguest_basic_apic_ops(void)
22049 {
22050 - apic->read = lguest_apic_read;
22051 - apic->write = lguest_apic_write;
22052 - apic->icr_read = lguest_apic_icr_read;
22053 - apic->icr_write = lguest_apic_icr_write;
22054 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22055 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22056 + *(void **)&apic->read = lguest_apic_read;
22057 + *(void **)&apic->write = lguest_apic_write;
22058 + *(void **)&apic->icr_read = lguest_apic_icr_read;
22059 + *(void **)&apic->icr_write = lguest_apic_icr_write;
22060 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22061 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22062 };
22063 #endif
22064
22065 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22066 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22067 * Launcher to reboot us.
22068 */
22069 -static void lguest_restart(char *reason)
22070 +static __noreturn void lguest_restart(char *reason)
22071 {
22072 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22073 + BUG();
22074 }
22075
22076 /*G:050
22077 @@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22078 pv_irq_ops.safe_halt = lguest_safe_halt;
22079
22080 /* Setup operations */
22081 - pv_init_ops.patch = lguest_patch;
22082 + *(void **)&pv_init_ops.patch = lguest_patch;
22083
22084 /* Intercepts of various CPU instructions */
22085 - pv_cpu_ops.load_gdt = lguest_load_gdt;
22086 - pv_cpu_ops.cpuid = lguest_cpuid;
22087 - pv_cpu_ops.load_idt = lguest_load_idt;
22088 - pv_cpu_ops.iret = lguest_iret;
22089 - pv_cpu_ops.load_sp0 = lguest_load_sp0;
22090 - pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22091 - pv_cpu_ops.set_ldt = lguest_set_ldt;
22092 - pv_cpu_ops.load_tls = lguest_load_tls;
22093 - pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22094 - pv_cpu_ops.clts = lguest_clts;
22095 - pv_cpu_ops.read_cr0 = lguest_read_cr0;
22096 - pv_cpu_ops.write_cr0 = lguest_write_cr0;
22097 - pv_cpu_ops.read_cr4 = lguest_read_cr4;
22098 - pv_cpu_ops.write_cr4 = lguest_write_cr4;
22099 - pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22100 - pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22101 - pv_cpu_ops.wbinvd = lguest_wbinvd;
22102 - pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22103 - pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22104 + *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22105 + *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22106 + *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22107 + *(void **)&pv_cpu_ops.iret = lguest_iret;
22108 + *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22109 + *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22110 + *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22111 + *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22112 + *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22113 + *(void **)&pv_cpu_ops.clts = lguest_clts;
22114 + *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22115 + *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22116 + *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22117 + *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22118 + *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22119 + *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22120 + *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22121 + *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22122 + *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22123
22124 /* Pagetable management */
22125 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22126 @@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22127 set_lguest_basic_apic_ops();
22128 #endif
22129
22130 - x86_init.resources.memory_setup = lguest_memory_setup;
22131 - x86_init.irqs.intr_init = lguest_init_IRQ;
22132 - x86_init.timers.timer_init = lguest_time_init;
22133 - x86_platform.calibrate_tsc = lguest_tsc_khz;
22134 - x86_platform.get_wallclock = lguest_get_wallclock;
22135 + *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22136 + *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22137 + *(void **)&x86_init.timers.timer_init = lguest_time_init;
22138 + *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22139 + *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22140
22141 /*
22142 * Now is a good time to look at the implementations of these functions
22143 @@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22144 * routine.
22145 */
22146 pm_power_off = lguest_power_off;
22147 - machine_ops.restart = lguest_restart;
22148 + *(void **)&machine_ops.restart = lguest_restart;
22149
22150 /*
22151 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22152 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22153 index 00933d5..3a64af9 100644
22154 --- a/arch/x86/lib/atomic64_386_32.S
22155 +++ b/arch/x86/lib/atomic64_386_32.S
22156 @@ -48,6 +48,10 @@ BEGIN(read)
22157 movl (v), %eax
22158 movl 4(v), %edx
22159 RET_ENDP
22160 +BEGIN(read_unchecked)
22161 + movl (v), %eax
22162 + movl 4(v), %edx
22163 +RET_ENDP
22164 #undef v
22165
22166 #define v %esi
22167 @@ -55,6 +59,10 @@ BEGIN(set)
22168 movl %ebx, (v)
22169 movl %ecx, 4(v)
22170 RET_ENDP
22171 +BEGIN(set_unchecked)
22172 + movl %ebx, (v)
22173 + movl %ecx, 4(v)
22174 +RET_ENDP
22175 #undef v
22176
22177 #define v %esi
22178 @@ -70,6 +78,20 @@ RET_ENDP
22179 BEGIN(add)
22180 addl %eax, (v)
22181 adcl %edx, 4(v)
22182 +
22183 +#ifdef CONFIG_PAX_REFCOUNT
22184 + jno 0f
22185 + subl %eax, (v)
22186 + sbbl %edx, 4(v)
22187 + int $4
22188 +0:
22189 + _ASM_EXTABLE(0b, 0b)
22190 +#endif
22191 +
22192 +RET_ENDP
22193 +BEGIN(add_unchecked)
22194 + addl %eax, (v)
22195 + adcl %edx, 4(v)
22196 RET_ENDP
22197 #undef v
22198
22199 @@ -77,6 +99,24 @@ RET_ENDP
22200 BEGIN(add_return)
22201 addl (v), %eax
22202 adcl 4(v), %edx
22203 +
22204 +#ifdef CONFIG_PAX_REFCOUNT
22205 + into
22206 +1234:
22207 + _ASM_EXTABLE(1234b, 2f)
22208 +#endif
22209 +
22210 + movl %eax, (v)
22211 + movl %edx, 4(v)
22212 +
22213 +#ifdef CONFIG_PAX_REFCOUNT
22214 +2:
22215 +#endif
22216 +
22217 +RET_ENDP
22218 +BEGIN(add_return_unchecked)
22219 + addl (v), %eax
22220 + adcl 4(v), %edx
22221 movl %eax, (v)
22222 movl %edx, 4(v)
22223 RET_ENDP
22224 @@ -86,6 +126,20 @@ RET_ENDP
22225 BEGIN(sub)
22226 subl %eax, (v)
22227 sbbl %edx, 4(v)
22228 +
22229 +#ifdef CONFIG_PAX_REFCOUNT
22230 + jno 0f
22231 + addl %eax, (v)
22232 + adcl %edx, 4(v)
22233 + int $4
22234 +0:
22235 + _ASM_EXTABLE(0b, 0b)
22236 +#endif
22237 +
22238 +RET_ENDP
22239 +BEGIN(sub_unchecked)
22240 + subl %eax, (v)
22241 + sbbl %edx, 4(v)
22242 RET_ENDP
22243 #undef v
22244
22245 @@ -96,6 +150,27 @@ BEGIN(sub_return)
22246 sbbl $0, %edx
22247 addl (v), %eax
22248 adcl 4(v), %edx
22249 +
22250 +#ifdef CONFIG_PAX_REFCOUNT
22251 + into
22252 +1234:
22253 + _ASM_EXTABLE(1234b, 2f)
22254 +#endif
22255 +
22256 + movl %eax, (v)
22257 + movl %edx, 4(v)
22258 +
22259 +#ifdef CONFIG_PAX_REFCOUNT
22260 +2:
22261 +#endif
22262 +
22263 +RET_ENDP
22264 +BEGIN(sub_return_unchecked)
22265 + negl %edx
22266 + negl %eax
22267 + sbbl $0, %edx
22268 + addl (v), %eax
22269 + adcl 4(v), %edx
22270 movl %eax, (v)
22271 movl %edx, 4(v)
22272 RET_ENDP
22273 @@ -105,6 +180,20 @@ RET_ENDP
22274 BEGIN(inc)
22275 addl $1, (v)
22276 adcl $0, 4(v)
22277 +
22278 +#ifdef CONFIG_PAX_REFCOUNT
22279 + jno 0f
22280 + subl $1, (v)
22281 + sbbl $0, 4(v)
22282 + int $4
22283 +0:
22284 + _ASM_EXTABLE(0b, 0b)
22285 +#endif
22286 +
22287 +RET_ENDP
22288 +BEGIN(inc_unchecked)
22289 + addl $1, (v)
22290 + adcl $0, 4(v)
22291 RET_ENDP
22292 #undef v
22293
22294 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22295 movl 4(v), %edx
22296 addl $1, %eax
22297 adcl $0, %edx
22298 +
22299 +#ifdef CONFIG_PAX_REFCOUNT
22300 + into
22301 +1234:
22302 + _ASM_EXTABLE(1234b, 2f)
22303 +#endif
22304 +
22305 + movl %eax, (v)
22306 + movl %edx, 4(v)
22307 +
22308 +#ifdef CONFIG_PAX_REFCOUNT
22309 +2:
22310 +#endif
22311 +
22312 +RET_ENDP
22313 +BEGIN(inc_return_unchecked)
22314 + movl (v), %eax
22315 + movl 4(v), %edx
22316 + addl $1, %eax
22317 + adcl $0, %edx
22318 movl %eax, (v)
22319 movl %edx, 4(v)
22320 RET_ENDP
22321 @@ -123,6 +232,20 @@ RET_ENDP
22322 BEGIN(dec)
22323 subl $1, (v)
22324 sbbl $0, 4(v)
22325 +
22326 +#ifdef CONFIG_PAX_REFCOUNT
22327 + jno 0f
22328 + addl $1, (v)
22329 + adcl $0, 4(v)
22330 + int $4
22331 +0:
22332 + _ASM_EXTABLE(0b, 0b)
22333 +#endif
22334 +
22335 +RET_ENDP
22336 +BEGIN(dec_unchecked)
22337 + subl $1, (v)
22338 + sbbl $0, 4(v)
22339 RET_ENDP
22340 #undef v
22341
22342 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22343 movl 4(v), %edx
22344 subl $1, %eax
22345 sbbl $0, %edx
22346 +
22347 +#ifdef CONFIG_PAX_REFCOUNT
22348 + into
22349 +1234:
22350 + _ASM_EXTABLE(1234b, 2f)
22351 +#endif
22352 +
22353 + movl %eax, (v)
22354 + movl %edx, 4(v)
22355 +
22356 +#ifdef CONFIG_PAX_REFCOUNT
22357 +2:
22358 +#endif
22359 +
22360 +RET_ENDP
22361 +BEGIN(dec_return_unchecked)
22362 + movl (v), %eax
22363 + movl 4(v), %edx
22364 + subl $1, %eax
22365 + sbbl $0, %edx
22366 movl %eax, (v)
22367 movl %edx, 4(v)
22368 RET_ENDP
22369 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22370 adcl %edx, %edi
22371 addl (v), %eax
22372 adcl 4(v), %edx
22373 +
22374 +#ifdef CONFIG_PAX_REFCOUNT
22375 + into
22376 +1234:
22377 + _ASM_EXTABLE(1234b, 2f)
22378 +#endif
22379 +
22380 cmpl %eax, %ecx
22381 je 3f
22382 1:
22383 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22384 1:
22385 addl $1, %eax
22386 adcl $0, %edx
22387 +
22388 +#ifdef CONFIG_PAX_REFCOUNT
22389 + into
22390 +1234:
22391 + _ASM_EXTABLE(1234b, 2f)
22392 +#endif
22393 +
22394 movl %eax, (v)
22395 movl %edx, 4(v)
22396 movl $1, %eax
22397 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22398 movl 4(v), %edx
22399 subl $1, %eax
22400 sbbl $0, %edx
22401 +
22402 +#ifdef CONFIG_PAX_REFCOUNT
22403 + into
22404 +1234:
22405 + _ASM_EXTABLE(1234b, 1f)
22406 +#endif
22407 +
22408 js 1f
22409 movl %eax, (v)
22410 movl %edx, 4(v)
22411 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22412 index f5cc9eb..51fa319 100644
22413 --- a/arch/x86/lib/atomic64_cx8_32.S
22414 +++ b/arch/x86/lib/atomic64_cx8_32.S
22415 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22416 CFI_STARTPROC
22417
22418 read64 %ecx
22419 + pax_force_retaddr
22420 ret
22421 CFI_ENDPROC
22422 ENDPROC(atomic64_read_cx8)
22423
22424 +ENTRY(atomic64_read_unchecked_cx8)
22425 + CFI_STARTPROC
22426 +
22427 + read64 %ecx
22428 + pax_force_retaddr
22429 + ret
22430 + CFI_ENDPROC
22431 +ENDPROC(atomic64_read_unchecked_cx8)
22432 +
22433 ENTRY(atomic64_set_cx8)
22434 CFI_STARTPROC
22435
22436 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22437 cmpxchg8b (%esi)
22438 jne 1b
22439
22440 + pax_force_retaddr
22441 ret
22442 CFI_ENDPROC
22443 ENDPROC(atomic64_set_cx8)
22444
22445 +ENTRY(atomic64_set_unchecked_cx8)
22446 + CFI_STARTPROC
22447 +
22448 +1:
22449 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22450 + * are atomic on 586 and newer */
22451 + cmpxchg8b (%esi)
22452 + jne 1b
22453 +
22454 + pax_force_retaddr
22455 + ret
22456 + CFI_ENDPROC
22457 +ENDPROC(atomic64_set_unchecked_cx8)
22458 +
22459 ENTRY(atomic64_xchg_cx8)
22460 CFI_STARTPROC
22461
22462 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22463 cmpxchg8b (%esi)
22464 jne 1b
22465
22466 + pax_force_retaddr
22467 ret
22468 CFI_ENDPROC
22469 ENDPROC(atomic64_xchg_cx8)
22470
22471 -.macro addsub_return func ins insc
22472 -ENTRY(atomic64_\func\()_return_cx8)
22473 +.macro addsub_return func ins insc unchecked=""
22474 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22475 CFI_STARTPROC
22476 SAVE ebp
22477 SAVE ebx
22478 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22479 movl %edx, %ecx
22480 \ins\()l %esi, %ebx
22481 \insc\()l %edi, %ecx
22482 +
22483 +.ifb \unchecked
22484 +#ifdef CONFIG_PAX_REFCOUNT
22485 + into
22486 +2:
22487 + _ASM_EXTABLE(2b, 3f)
22488 +#endif
22489 +.endif
22490 +
22491 LOCK_PREFIX
22492 cmpxchg8b (%ebp)
22493 jne 1b
22494 -
22495 -10:
22496 movl %ebx, %eax
22497 movl %ecx, %edx
22498 +
22499 +.ifb \unchecked
22500 +#ifdef CONFIG_PAX_REFCOUNT
22501 +3:
22502 +#endif
22503 +.endif
22504 +
22505 RESTORE edi
22506 RESTORE esi
22507 RESTORE ebx
22508 RESTORE ebp
22509 + pax_force_retaddr
22510 ret
22511 CFI_ENDPROC
22512 -ENDPROC(atomic64_\func\()_return_cx8)
22513 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22514 .endm
22515
22516 addsub_return add add adc
22517 addsub_return sub sub sbb
22518 +addsub_return add add adc _unchecked
22519 +addsub_return sub sub sbb _unchecked
22520
22521 -.macro incdec_return func ins insc
22522 -ENTRY(atomic64_\func\()_return_cx8)
22523 +.macro incdec_return func ins insc unchecked=""
22524 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22525 CFI_STARTPROC
22526 SAVE ebx
22527
22528 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22529 movl %edx, %ecx
22530 \ins\()l $1, %ebx
22531 \insc\()l $0, %ecx
22532 +
22533 +.ifb \unchecked
22534 +#ifdef CONFIG_PAX_REFCOUNT
22535 + into
22536 +2:
22537 + _ASM_EXTABLE(2b, 3f)
22538 +#endif
22539 +.endif
22540 +
22541 LOCK_PREFIX
22542 cmpxchg8b (%esi)
22543 jne 1b
22544
22545 -10:
22546 movl %ebx, %eax
22547 movl %ecx, %edx
22548 +
22549 +.ifb \unchecked
22550 +#ifdef CONFIG_PAX_REFCOUNT
22551 +3:
22552 +#endif
22553 +.endif
22554 +
22555 RESTORE ebx
22556 + pax_force_retaddr
22557 ret
22558 CFI_ENDPROC
22559 -ENDPROC(atomic64_\func\()_return_cx8)
22560 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22561 .endm
22562
22563 incdec_return inc add adc
22564 incdec_return dec sub sbb
22565 +incdec_return inc add adc _unchecked
22566 +incdec_return dec sub sbb _unchecked
22567
22568 ENTRY(atomic64_dec_if_positive_cx8)
22569 CFI_STARTPROC
22570 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22571 movl %edx, %ecx
22572 subl $1, %ebx
22573 sbb $0, %ecx
22574 +
22575 +#ifdef CONFIG_PAX_REFCOUNT
22576 + into
22577 +1234:
22578 + _ASM_EXTABLE(1234b, 2f)
22579 +#endif
22580 +
22581 js 2f
22582 LOCK_PREFIX
22583 cmpxchg8b (%esi)
22584 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22585 movl %ebx, %eax
22586 movl %ecx, %edx
22587 RESTORE ebx
22588 + pax_force_retaddr
22589 ret
22590 CFI_ENDPROC
22591 ENDPROC(atomic64_dec_if_positive_cx8)
22592 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22593 movl %edx, %ecx
22594 addl %ebp, %ebx
22595 adcl %edi, %ecx
22596 +
22597 +#ifdef CONFIG_PAX_REFCOUNT
22598 + into
22599 +1234:
22600 + _ASM_EXTABLE(1234b, 3f)
22601 +#endif
22602 +
22603 LOCK_PREFIX
22604 cmpxchg8b (%esi)
22605 jne 1b
22606 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22607 CFI_ADJUST_CFA_OFFSET -8
22608 RESTORE ebx
22609 RESTORE ebp
22610 + pax_force_retaddr
22611 ret
22612 4:
22613 cmpl %edx, 4(%esp)
22614 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22615 xorl %ecx, %ecx
22616 addl $1, %ebx
22617 adcl %edx, %ecx
22618 +
22619 +#ifdef CONFIG_PAX_REFCOUNT
22620 + into
22621 +1234:
22622 + _ASM_EXTABLE(1234b, 3f)
22623 +#endif
22624 +
22625 LOCK_PREFIX
22626 cmpxchg8b (%esi)
22627 jne 1b
22628 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22629 movl $1, %eax
22630 3:
22631 RESTORE ebx
22632 + pax_force_retaddr
22633 ret
22634 CFI_ENDPROC
22635 ENDPROC(atomic64_inc_not_zero_cx8)
22636 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22637 index 2af5df3..62b1a5a 100644
22638 --- a/arch/x86/lib/checksum_32.S
22639 +++ b/arch/x86/lib/checksum_32.S
22640 @@ -29,7 +29,8 @@
22641 #include <asm/dwarf2.h>
22642 #include <asm/errno.h>
22643 #include <asm/asm.h>
22644 -
22645 +#include <asm/segment.h>
22646 +
22647 /*
22648 * computes a partial checksum, e.g. for TCP/UDP fragments
22649 */
22650 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22651
22652 #define ARGBASE 16
22653 #define FP 12
22654 -
22655 -ENTRY(csum_partial_copy_generic)
22656 +
22657 +ENTRY(csum_partial_copy_generic_to_user)
22658 CFI_STARTPROC
22659 +
22660 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22661 + pushl_cfi %gs
22662 + popl_cfi %es
22663 + jmp csum_partial_copy_generic
22664 +#endif
22665 +
22666 +ENTRY(csum_partial_copy_generic_from_user)
22667 +
22668 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22669 + pushl_cfi %gs
22670 + popl_cfi %ds
22671 +#endif
22672 +
22673 +ENTRY(csum_partial_copy_generic)
22674 subl $4,%esp
22675 CFI_ADJUST_CFA_OFFSET 4
22676 pushl_cfi %edi
22677 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22678 jmp 4f
22679 SRC(1: movw (%esi), %bx )
22680 addl $2, %esi
22681 -DST( movw %bx, (%edi) )
22682 +DST( movw %bx, %es:(%edi) )
22683 addl $2, %edi
22684 addw %bx, %ax
22685 adcl $0, %eax
22686 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22687 SRC(1: movl (%esi), %ebx )
22688 SRC( movl 4(%esi), %edx )
22689 adcl %ebx, %eax
22690 -DST( movl %ebx, (%edi) )
22691 +DST( movl %ebx, %es:(%edi) )
22692 adcl %edx, %eax
22693 -DST( movl %edx, 4(%edi) )
22694 +DST( movl %edx, %es:4(%edi) )
22695
22696 SRC( movl 8(%esi), %ebx )
22697 SRC( movl 12(%esi), %edx )
22698 adcl %ebx, %eax
22699 -DST( movl %ebx, 8(%edi) )
22700 +DST( movl %ebx, %es:8(%edi) )
22701 adcl %edx, %eax
22702 -DST( movl %edx, 12(%edi) )
22703 +DST( movl %edx, %es:12(%edi) )
22704
22705 SRC( movl 16(%esi), %ebx )
22706 SRC( movl 20(%esi), %edx )
22707 adcl %ebx, %eax
22708 -DST( movl %ebx, 16(%edi) )
22709 +DST( movl %ebx, %es:16(%edi) )
22710 adcl %edx, %eax
22711 -DST( movl %edx, 20(%edi) )
22712 +DST( movl %edx, %es:20(%edi) )
22713
22714 SRC( movl 24(%esi), %ebx )
22715 SRC( movl 28(%esi), %edx )
22716 adcl %ebx, %eax
22717 -DST( movl %ebx, 24(%edi) )
22718 +DST( movl %ebx, %es:24(%edi) )
22719 adcl %edx, %eax
22720 -DST( movl %edx, 28(%edi) )
22721 +DST( movl %edx, %es:28(%edi) )
22722
22723 lea 32(%esi), %esi
22724 lea 32(%edi), %edi
22725 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22726 shrl $2, %edx # This clears CF
22727 SRC(3: movl (%esi), %ebx )
22728 adcl %ebx, %eax
22729 -DST( movl %ebx, (%edi) )
22730 +DST( movl %ebx, %es:(%edi) )
22731 lea 4(%esi), %esi
22732 lea 4(%edi), %edi
22733 dec %edx
22734 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22735 jb 5f
22736 SRC( movw (%esi), %cx )
22737 leal 2(%esi), %esi
22738 -DST( movw %cx, (%edi) )
22739 +DST( movw %cx, %es:(%edi) )
22740 leal 2(%edi), %edi
22741 je 6f
22742 shll $16,%ecx
22743 SRC(5: movb (%esi), %cl )
22744 -DST( movb %cl, (%edi) )
22745 +DST( movb %cl, %es:(%edi) )
22746 6: addl %ecx, %eax
22747 adcl $0, %eax
22748 7:
22749 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22750
22751 6001:
22752 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22753 - movl $-EFAULT, (%ebx)
22754 + movl $-EFAULT, %ss:(%ebx)
22755
22756 # zero the complete destination - computing the rest
22757 # is too much work
22758 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22759
22760 6002:
22761 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22762 - movl $-EFAULT,(%ebx)
22763 + movl $-EFAULT,%ss:(%ebx)
22764 jmp 5000b
22765
22766 .previous
22767
22768 + pushl_cfi %ss
22769 + popl_cfi %ds
22770 + pushl_cfi %ss
22771 + popl_cfi %es
22772 popl_cfi %ebx
22773 CFI_RESTORE ebx
22774 popl_cfi %esi
22775 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22776 popl_cfi %ecx # equivalent to addl $4,%esp
22777 ret
22778 CFI_ENDPROC
22779 -ENDPROC(csum_partial_copy_generic)
22780 +ENDPROC(csum_partial_copy_generic_to_user)
22781
22782 #else
22783
22784 /* Version for PentiumII/PPro */
22785
22786 #define ROUND1(x) \
22787 + nop; nop; nop; \
22788 SRC(movl x(%esi), %ebx ) ; \
22789 addl %ebx, %eax ; \
22790 - DST(movl %ebx, x(%edi) ) ;
22791 + DST(movl %ebx, %es:x(%edi)) ;
22792
22793 #define ROUND(x) \
22794 + nop; nop; nop; \
22795 SRC(movl x(%esi), %ebx ) ; \
22796 adcl %ebx, %eax ; \
22797 - DST(movl %ebx, x(%edi) ) ;
22798 + DST(movl %ebx, %es:x(%edi)) ;
22799
22800 #define ARGBASE 12
22801 -
22802 -ENTRY(csum_partial_copy_generic)
22803 +
22804 +ENTRY(csum_partial_copy_generic_to_user)
22805 CFI_STARTPROC
22806 +
22807 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22808 + pushl_cfi %gs
22809 + popl_cfi %es
22810 + jmp csum_partial_copy_generic
22811 +#endif
22812 +
22813 +ENTRY(csum_partial_copy_generic_from_user)
22814 +
22815 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22816 + pushl_cfi %gs
22817 + popl_cfi %ds
22818 +#endif
22819 +
22820 +ENTRY(csum_partial_copy_generic)
22821 pushl_cfi %ebx
22822 CFI_REL_OFFSET ebx, 0
22823 pushl_cfi %edi
22824 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22825 subl %ebx, %edi
22826 lea -1(%esi),%edx
22827 andl $-32,%edx
22828 - lea 3f(%ebx,%ebx), %ebx
22829 + lea 3f(%ebx,%ebx,2), %ebx
22830 testl %esi, %esi
22831 jmp *%ebx
22832 1: addl $64,%esi
22833 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22834 jb 5f
22835 SRC( movw (%esi), %dx )
22836 leal 2(%esi), %esi
22837 -DST( movw %dx, (%edi) )
22838 +DST( movw %dx, %es:(%edi) )
22839 leal 2(%edi), %edi
22840 je 6f
22841 shll $16,%edx
22842 5:
22843 SRC( movb (%esi), %dl )
22844 -DST( movb %dl, (%edi) )
22845 +DST( movb %dl, %es:(%edi) )
22846 6: addl %edx, %eax
22847 adcl $0, %eax
22848 7:
22849 .section .fixup, "ax"
22850 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22851 - movl $-EFAULT, (%ebx)
22852 + movl $-EFAULT, %ss:(%ebx)
22853 # zero the complete destination (computing the rest is too much work)
22854 movl ARGBASE+8(%esp),%edi # dst
22855 movl ARGBASE+12(%esp),%ecx # len
22856 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22857 rep; stosb
22858 jmp 7b
22859 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22860 - movl $-EFAULT, (%ebx)
22861 + movl $-EFAULT, %ss:(%ebx)
22862 jmp 7b
22863 .previous
22864
22865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22866 + pushl_cfi %ss
22867 + popl_cfi %ds
22868 + pushl_cfi %ss
22869 + popl_cfi %es
22870 +#endif
22871 +
22872 popl_cfi %esi
22873 CFI_RESTORE esi
22874 popl_cfi %edi
22875 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22876 CFI_RESTORE ebx
22877 ret
22878 CFI_ENDPROC
22879 -ENDPROC(csum_partial_copy_generic)
22880 +ENDPROC(csum_partial_copy_generic_to_user)
22881
22882 #undef ROUND
22883 #undef ROUND1
22884 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22885 index f2145cf..cea889d 100644
22886 --- a/arch/x86/lib/clear_page_64.S
22887 +++ b/arch/x86/lib/clear_page_64.S
22888 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22889 movl $4096/8,%ecx
22890 xorl %eax,%eax
22891 rep stosq
22892 + pax_force_retaddr
22893 ret
22894 CFI_ENDPROC
22895 ENDPROC(clear_page_c)
22896 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22897 movl $4096,%ecx
22898 xorl %eax,%eax
22899 rep stosb
22900 + pax_force_retaddr
22901 ret
22902 CFI_ENDPROC
22903 ENDPROC(clear_page_c_e)
22904 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22905 leaq 64(%rdi),%rdi
22906 jnz .Lloop
22907 nop
22908 + pax_force_retaddr
22909 ret
22910 CFI_ENDPROC
22911 .Lclear_page_end:
22912 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22913
22914 #include <asm/cpufeature.h>
22915
22916 - .section .altinstr_replacement,"ax"
22917 + .section .altinstr_replacement,"a"
22918 1: .byte 0xeb /* jmp <disp8> */
22919 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22920 2: .byte 0xeb /* jmp <disp8> */
22921 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22922 index 1e572c5..2a162cd 100644
22923 --- a/arch/x86/lib/cmpxchg16b_emu.S
22924 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22925 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22926
22927 popf
22928 mov $1, %al
22929 + pax_force_retaddr
22930 ret
22931
22932 not_same:
22933 popf
22934 xor %al,%al
22935 + pax_force_retaddr
22936 ret
22937
22938 CFI_ENDPROC
22939 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22940 index 6b34d04..dccb07f 100644
22941 --- a/arch/x86/lib/copy_page_64.S
22942 +++ b/arch/x86/lib/copy_page_64.S
22943 @@ -9,6 +9,7 @@ copy_page_c:
22944 CFI_STARTPROC
22945 movl $4096/8,%ecx
22946 rep movsq
22947 + pax_force_retaddr
22948 ret
22949 CFI_ENDPROC
22950 ENDPROC(copy_page_c)
22951 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22952
22953 ENTRY(copy_page)
22954 CFI_STARTPROC
22955 - subq $2*8,%rsp
22956 - CFI_ADJUST_CFA_OFFSET 2*8
22957 + subq $3*8,%rsp
22958 + CFI_ADJUST_CFA_OFFSET 3*8
22959 movq %rbx,(%rsp)
22960 CFI_REL_OFFSET rbx, 0
22961 movq %r12,1*8(%rsp)
22962 CFI_REL_OFFSET r12, 1*8
22963 + movq %r13,2*8(%rsp)
22964 + CFI_REL_OFFSET r13, 2*8
22965
22966 movl $(4096/64)-5,%ecx
22967 .p2align 4
22968 @@ -37,7 +40,7 @@ ENTRY(copy_page)
22969 movq 16 (%rsi), %rdx
22970 movq 24 (%rsi), %r8
22971 movq 32 (%rsi), %r9
22972 - movq 40 (%rsi), %r10
22973 + movq 40 (%rsi), %r13
22974 movq 48 (%rsi), %r11
22975 movq 56 (%rsi), %r12
22976
22977 @@ -48,7 +51,7 @@ ENTRY(copy_page)
22978 movq %rdx, 16 (%rdi)
22979 movq %r8, 24 (%rdi)
22980 movq %r9, 32 (%rdi)
22981 - movq %r10, 40 (%rdi)
22982 + movq %r13, 40 (%rdi)
22983 movq %r11, 48 (%rdi)
22984 movq %r12, 56 (%rdi)
22985
22986 @@ -67,7 +70,7 @@ ENTRY(copy_page)
22987 movq 16 (%rsi), %rdx
22988 movq 24 (%rsi), %r8
22989 movq 32 (%rsi), %r9
22990 - movq 40 (%rsi), %r10
22991 + movq 40 (%rsi), %r13
22992 movq 48 (%rsi), %r11
22993 movq 56 (%rsi), %r12
22994
22995 @@ -76,7 +79,7 @@ ENTRY(copy_page)
22996 movq %rdx, 16 (%rdi)
22997 movq %r8, 24 (%rdi)
22998 movq %r9, 32 (%rdi)
22999 - movq %r10, 40 (%rdi)
23000 + movq %r13, 40 (%rdi)
23001 movq %r11, 48 (%rdi)
23002 movq %r12, 56 (%rdi)
23003
23004 @@ -89,8 +92,11 @@ ENTRY(copy_page)
23005 CFI_RESTORE rbx
23006 movq 1*8(%rsp),%r12
23007 CFI_RESTORE r12
23008 - addq $2*8,%rsp
23009 - CFI_ADJUST_CFA_OFFSET -2*8
23010 + movq 2*8(%rsp),%r13
23011 + CFI_RESTORE r13
23012 + addq $3*8,%rsp
23013 + CFI_ADJUST_CFA_OFFSET -3*8
23014 + pax_force_retaddr
23015 ret
23016 .Lcopy_page_end:
23017 CFI_ENDPROC
23018 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
23019
23020 #include <asm/cpufeature.h>
23021
23022 - .section .altinstr_replacement,"ax"
23023 + .section .altinstr_replacement,"a"
23024 1: .byte 0xeb /* jmp <disp8> */
23025 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23026 2:
23027 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23028 index a30ca15..d25fab6 100644
23029 --- a/arch/x86/lib/copy_user_64.S
23030 +++ b/arch/x86/lib/copy_user_64.S
23031 @@ -18,6 +18,7 @@
23032 #include <asm/alternative-asm.h>
23033 #include <asm/asm.h>
23034 #include <asm/smap.h>
23035 +#include <asm/pgtable.h>
23036
23037 /*
23038 * By placing feature2 after feature1 in altinstructions section, we logically
23039 @@ -31,7 +32,7 @@
23040 .byte 0xe9 /* 32bit jump */
23041 .long \orig-1f /* by default jump to orig */
23042 1:
23043 - .section .altinstr_replacement,"ax"
23044 + .section .altinstr_replacement,"a"
23045 2: .byte 0xe9 /* near jump with 32bit immediate */
23046 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23047 3: .byte 0xe9 /* near jump with 32bit immediate */
23048 @@ -70,47 +71,20 @@
23049 #endif
23050 .endm
23051
23052 -/* Standard copy_to_user with segment limit checking */
23053 -ENTRY(_copy_to_user)
23054 - CFI_STARTPROC
23055 - GET_THREAD_INFO(%rax)
23056 - movq %rdi,%rcx
23057 - addq %rdx,%rcx
23058 - jc bad_to_user
23059 - cmpq TI_addr_limit(%rax),%rcx
23060 - ja bad_to_user
23061 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23062 - copy_user_generic_unrolled,copy_user_generic_string, \
23063 - copy_user_enhanced_fast_string
23064 - CFI_ENDPROC
23065 -ENDPROC(_copy_to_user)
23066 -
23067 -/* Standard copy_from_user with segment limit checking */
23068 -ENTRY(_copy_from_user)
23069 - CFI_STARTPROC
23070 - GET_THREAD_INFO(%rax)
23071 - movq %rsi,%rcx
23072 - addq %rdx,%rcx
23073 - jc bad_from_user
23074 - cmpq TI_addr_limit(%rax),%rcx
23075 - ja bad_from_user
23076 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23077 - copy_user_generic_unrolled,copy_user_generic_string, \
23078 - copy_user_enhanced_fast_string
23079 - CFI_ENDPROC
23080 -ENDPROC(_copy_from_user)
23081 -
23082 .section .fixup,"ax"
23083 /* must zero dest */
23084 ENTRY(bad_from_user)
23085 bad_from_user:
23086 CFI_STARTPROC
23087 + testl %edx,%edx
23088 + js bad_to_user
23089 movl %edx,%ecx
23090 xorl %eax,%eax
23091 rep
23092 stosb
23093 bad_to_user:
23094 movl %edx,%eax
23095 + pax_force_retaddr
23096 ret
23097 CFI_ENDPROC
23098 ENDPROC(bad_from_user)
23099 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23100 jz 17f
23101 1: movq (%rsi),%r8
23102 2: movq 1*8(%rsi),%r9
23103 -3: movq 2*8(%rsi),%r10
23104 +3: movq 2*8(%rsi),%rax
23105 4: movq 3*8(%rsi),%r11
23106 5: movq %r8,(%rdi)
23107 6: movq %r9,1*8(%rdi)
23108 -7: movq %r10,2*8(%rdi)
23109 +7: movq %rax,2*8(%rdi)
23110 8: movq %r11,3*8(%rdi)
23111 9: movq 4*8(%rsi),%r8
23112 10: movq 5*8(%rsi),%r9
23113 -11: movq 6*8(%rsi),%r10
23114 +11: movq 6*8(%rsi),%rax
23115 12: movq 7*8(%rsi),%r11
23116 13: movq %r8,4*8(%rdi)
23117 14: movq %r9,5*8(%rdi)
23118 -15: movq %r10,6*8(%rdi)
23119 +15: movq %rax,6*8(%rdi)
23120 16: movq %r11,7*8(%rdi)
23121 leaq 64(%rsi),%rsi
23122 leaq 64(%rdi),%rdi
23123 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23124 jnz 21b
23125 23: xor %eax,%eax
23126 ASM_CLAC
23127 + pax_force_retaddr
23128 ret
23129
23130 .section .fixup,"ax"
23131 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23132 movsb
23133 4: xorl %eax,%eax
23134 ASM_CLAC
23135 + pax_force_retaddr
23136 ret
23137
23138 .section .fixup,"ax"
23139 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23140 movsb
23141 2: xorl %eax,%eax
23142 ASM_CLAC
23143 + pax_force_retaddr
23144 ret
23145
23146 .section .fixup,"ax"
23147 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23148 index 6a4f43c..f5f9e26 100644
23149 --- a/arch/x86/lib/copy_user_nocache_64.S
23150 +++ b/arch/x86/lib/copy_user_nocache_64.S
23151 @@ -8,6 +8,7 @@
23152
23153 #include <linux/linkage.h>
23154 #include <asm/dwarf2.h>
23155 +#include <asm/alternative-asm.h>
23156
23157 #define FIX_ALIGNMENT 1
23158
23159 @@ -16,6 +17,7 @@
23160 #include <asm/thread_info.h>
23161 #include <asm/asm.h>
23162 #include <asm/smap.h>
23163 +#include <asm/pgtable.h>
23164
23165 .macro ALIGN_DESTINATION
23166 #ifdef FIX_ALIGNMENT
23167 @@ -49,6 +51,15 @@
23168 */
23169 ENTRY(__copy_user_nocache)
23170 CFI_STARTPROC
23171 +
23172 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23173 + mov $PAX_USER_SHADOW_BASE,%rcx
23174 + cmp %rcx,%rsi
23175 + jae 1f
23176 + add %rcx,%rsi
23177 +1:
23178 +#endif
23179 +
23180 ASM_STAC
23181 cmpl $8,%edx
23182 jb 20f /* less then 8 bytes, go to byte copy loop */
23183 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23184 jz 17f
23185 1: movq (%rsi),%r8
23186 2: movq 1*8(%rsi),%r9
23187 -3: movq 2*8(%rsi),%r10
23188 +3: movq 2*8(%rsi),%rax
23189 4: movq 3*8(%rsi),%r11
23190 5: movnti %r8,(%rdi)
23191 6: movnti %r9,1*8(%rdi)
23192 -7: movnti %r10,2*8(%rdi)
23193 +7: movnti %rax,2*8(%rdi)
23194 8: movnti %r11,3*8(%rdi)
23195 9: movq 4*8(%rsi),%r8
23196 10: movq 5*8(%rsi),%r9
23197 -11: movq 6*8(%rsi),%r10
23198 +11: movq 6*8(%rsi),%rax
23199 12: movq 7*8(%rsi),%r11
23200 13: movnti %r8,4*8(%rdi)
23201 14: movnti %r9,5*8(%rdi)
23202 -15: movnti %r10,6*8(%rdi)
23203 +15: movnti %rax,6*8(%rdi)
23204 16: movnti %r11,7*8(%rdi)
23205 leaq 64(%rsi),%rsi
23206 leaq 64(%rdi),%rdi
23207 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23208 23: xorl %eax,%eax
23209 ASM_CLAC
23210 sfence
23211 + pax_force_retaddr
23212 ret
23213
23214 .section .fixup,"ax"
23215 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23216 index 2419d5f..953ee51 100644
23217 --- a/arch/x86/lib/csum-copy_64.S
23218 +++ b/arch/x86/lib/csum-copy_64.S
23219 @@ -9,6 +9,7 @@
23220 #include <asm/dwarf2.h>
23221 #include <asm/errno.h>
23222 #include <asm/asm.h>
23223 +#include <asm/alternative-asm.h>
23224
23225 /*
23226 * Checksum copy with exception handling.
23227 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23228 CFI_RESTORE rbp
23229 addq $7*8, %rsp
23230 CFI_ADJUST_CFA_OFFSET -7*8
23231 + pax_force_retaddr 0, 1
23232 ret
23233 CFI_RESTORE_STATE
23234
23235 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23236 index 25b7ae8..169fafc 100644
23237 --- a/arch/x86/lib/csum-wrappers_64.c
23238 +++ b/arch/x86/lib/csum-wrappers_64.c
23239 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23240 len -= 2;
23241 }
23242 }
23243 - isum = csum_partial_copy_generic((__force const void *)src,
23244 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23245 dst, len, isum, errp, NULL);
23246 if (unlikely(*errp))
23247 goto out_err;
23248 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23249 }
23250
23251 *errp = 0;
23252 - return csum_partial_copy_generic(src, (void __force *)dst,
23253 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23254 len, isum, NULL, errp);
23255 }
23256 EXPORT_SYMBOL(csum_partial_copy_to_user);
23257 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23258 index 156b9c8..b144132 100644
23259 --- a/arch/x86/lib/getuser.S
23260 +++ b/arch/x86/lib/getuser.S
23261 @@ -34,17 +34,40 @@
23262 #include <asm/thread_info.h>
23263 #include <asm/asm.h>
23264 #include <asm/smap.h>
23265 +#include <asm/segment.h>
23266 +#include <asm/pgtable.h>
23267 +#include <asm/alternative-asm.h>
23268 +
23269 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23270 +#define __copyuser_seg gs;
23271 +#else
23272 +#define __copyuser_seg
23273 +#endif
23274
23275 .text
23276 ENTRY(__get_user_1)
23277 CFI_STARTPROC
23278 +
23279 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23280 GET_THREAD_INFO(%_ASM_DX)
23281 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23282 jae bad_get_user
23283 ASM_STAC
23284 -1: movzb (%_ASM_AX),%edx
23285 +
23286 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23287 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23288 + cmp %_ASM_DX,%_ASM_AX
23289 + jae 1234f
23290 + add %_ASM_DX,%_ASM_AX
23291 +1234:
23292 +#endif
23293 +
23294 +#endif
23295 +
23296 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23297 xor %eax,%eax
23298 ASM_CLAC
23299 + pax_force_retaddr
23300 ret
23301 CFI_ENDPROC
23302 ENDPROC(__get_user_1)
23303 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23304 ENTRY(__get_user_2)
23305 CFI_STARTPROC
23306 add $1,%_ASM_AX
23307 +
23308 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23309 jc bad_get_user
23310 GET_THREAD_INFO(%_ASM_DX)
23311 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23312 jae bad_get_user
23313 ASM_STAC
23314 -2: movzwl -1(%_ASM_AX),%edx
23315 +
23316 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23317 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23318 + cmp %_ASM_DX,%_ASM_AX
23319 + jae 1234f
23320 + add %_ASM_DX,%_ASM_AX
23321 +1234:
23322 +#endif
23323 +
23324 +#endif
23325 +
23326 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23327 xor %eax,%eax
23328 ASM_CLAC
23329 + pax_force_retaddr
23330 ret
23331 CFI_ENDPROC
23332 ENDPROC(__get_user_2)
23333 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23334 ENTRY(__get_user_4)
23335 CFI_STARTPROC
23336 add $3,%_ASM_AX
23337 +
23338 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23339 jc bad_get_user
23340 GET_THREAD_INFO(%_ASM_DX)
23341 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23342 jae bad_get_user
23343 ASM_STAC
23344 -3: mov -3(%_ASM_AX),%edx
23345 +
23346 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23347 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23348 + cmp %_ASM_DX,%_ASM_AX
23349 + jae 1234f
23350 + add %_ASM_DX,%_ASM_AX
23351 +1234:
23352 +#endif
23353 +
23354 +#endif
23355 +
23356 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23357 xor %eax,%eax
23358 ASM_CLAC
23359 + pax_force_retaddr
23360 ret
23361 CFI_ENDPROC
23362 ENDPROC(__get_user_4)
23363 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23364 GET_THREAD_INFO(%_ASM_DX)
23365 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23366 jae bad_get_user
23367 +
23368 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23369 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23370 + cmp %_ASM_DX,%_ASM_AX
23371 + jae 1234f
23372 + add %_ASM_DX,%_ASM_AX
23373 +1234:
23374 +#endif
23375 +
23376 ASM_STAC
23377 4: movq -7(%_ASM_AX),%_ASM_DX
23378 xor %eax,%eax
23379 ASM_CLAC
23380 + pax_force_retaddr
23381 ret
23382 CFI_ENDPROC
23383 ENDPROC(__get_user_8)
23384 @@ -101,6 +162,7 @@ bad_get_user:
23385 xor %edx,%edx
23386 mov $(-EFAULT),%_ASM_AX
23387 ASM_CLAC
23388 + pax_force_retaddr
23389 ret
23390 CFI_ENDPROC
23391 END(bad_get_user)
23392 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23393 index 54fcffe..7be149e 100644
23394 --- a/arch/x86/lib/insn.c
23395 +++ b/arch/x86/lib/insn.c
23396 @@ -20,8 +20,10 @@
23397
23398 #ifdef __KERNEL__
23399 #include <linux/string.h>
23400 +#include <asm/pgtable_types.h>
23401 #else
23402 #include <string.h>
23403 +#define ktla_ktva(addr) addr
23404 #endif
23405 #include <asm/inat.h>
23406 #include <asm/insn.h>
23407 @@ -53,8 +55,8 @@
23408 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23409 {
23410 memset(insn, 0, sizeof(*insn));
23411 - insn->kaddr = kaddr;
23412 - insn->next_byte = kaddr;
23413 + insn->kaddr = ktla_ktva(kaddr);
23414 + insn->next_byte = ktla_ktva(kaddr);
23415 insn->x86_64 = x86_64 ? 1 : 0;
23416 insn->opnd_bytes = 4;
23417 if (x86_64)
23418 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23419 index 05a95e7..326f2fa 100644
23420 --- a/arch/x86/lib/iomap_copy_64.S
23421 +++ b/arch/x86/lib/iomap_copy_64.S
23422 @@ -17,6 +17,7 @@
23423
23424 #include <linux/linkage.h>
23425 #include <asm/dwarf2.h>
23426 +#include <asm/alternative-asm.h>
23427
23428 /*
23429 * override generic version in lib/iomap_copy.c
23430 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23431 CFI_STARTPROC
23432 movl %edx,%ecx
23433 rep movsd
23434 + pax_force_retaddr
23435 ret
23436 CFI_ENDPROC
23437 ENDPROC(__iowrite32_copy)
23438 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23439 index 1c273be..da9cc0e 100644
23440 --- a/arch/x86/lib/memcpy_64.S
23441 +++ b/arch/x86/lib/memcpy_64.S
23442 @@ -33,6 +33,7 @@
23443 rep movsq
23444 movl %edx, %ecx
23445 rep movsb
23446 + pax_force_retaddr
23447 ret
23448 .Lmemcpy_e:
23449 .previous
23450 @@ -49,6 +50,7 @@
23451 movq %rdi, %rax
23452 movq %rdx, %rcx
23453 rep movsb
23454 + pax_force_retaddr
23455 ret
23456 .Lmemcpy_e_e:
23457 .previous
23458 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23459 */
23460 movq 0*8(%rsi), %r8
23461 movq 1*8(%rsi), %r9
23462 - movq 2*8(%rsi), %r10
23463 + movq 2*8(%rsi), %rcx
23464 movq 3*8(%rsi), %r11
23465 leaq 4*8(%rsi), %rsi
23466
23467 movq %r8, 0*8(%rdi)
23468 movq %r9, 1*8(%rdi)
23469 - movq %r10, 2*8(%rdi)
23470 + movq %rcx, 2*8(%rdi)
23471 movq %r11, 3*8(%rdi)
23472 leaq 4*8(%rdi), %rdi
23473 jae .Lcopy_forward_loop
23474 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23475 subq $0x20, %rdx
23476 movq -1*8(%rsi), %r8
23477 movq -2*8(%rsi), %r9
23478 - movq -3*8(%rsi), %r10
23479 + movq -3*8(%rsi), %rcx
23480 movq -4*8(%rsi), %r11
23481 leaq -4*8(%rsi), %rsi
23482 movq %r8, -1*8(%rdi)
23483 movq %r9, -2*8(%rdi)
23484 - movq %r10, -3*8(%rdi)
23485 + movq %rcx, -3*8(%rdi)
23486 movq %r11, -4*8(%rdi)
23487 leaq -4*8(%rdi), %rdi
23488 jae .Lcopy_backward_loop
23489 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23490 */
23491 movq 0*8(%rsi), %r8
23492 movq 1*8(%rsi), %r9
23493 - movq -2*8(%rsi, %rdx), %r10
23494 + movq -2*8(%rsi, %rdx), %rcx
23495 movq -1*8(%rsi, %rdx), %r11
23496 movq %r8, 0*8(%rdi)
23497 movq %r9, 1*8(%rdi)
23498 - movq %r10, -2*8(%rdi, %rdx)
23499 + movq %rcx, -2*8(%rdi, %rdx)
23500 movq %r11, -1*8(%rdi, %rdx)
23501 + pax_force_retaddr
23502 retq
23503 .p2align 4
23504 .Lless_16bytes:
23505 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23506 movq -1*8(%rsi, %rdx), %r9
23507 movq %r8, 0*8(%rdi)
23508 movq %r9, -1*8(%rdi, %rdx)
23509 + pax_force_retaddr
23510 retq
23511 .p2align 4
23512 .Lless_8bytes:
23513 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23514 movl -4(%rsi, %rdx), %r8d
23515 movl %ecx, (%rdi)
23516 movl %r8d, -4(%rdi, %rdx)
23517 + pax_force_retaddr
23518 retq
23519 .p2align 4
23520 .Lless_3bytes:
23521 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23522 movb %cl, (%rdi)
23523
23524 .Lend:
23525 + pax_force_retaddr
23526 retq
23527 CFI_ENDPROC
23528 ENDPROC(memcpy)
23529 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23530 index ee16461..c39c199 100644
23531 --- a/arch/x86/lib/memmove_64.S
23532 +++ b/arch/x86/lib/memmove_64.S
23533 @@ -61,13 +61,13 @@ ENTRY(memmove)
23534 5:
23535 sub $0x20, %rdx
23536 movq 0*8(%rsi), %r11
23537 - movq 1*8(%rsi), %r10
23538 + movq 1*8(%rsi), %rcx
23539 movq 2*8(%rsi), %r9
23540 movq 3*8(%rsi), %r8
23541 leaq 4*8(%rsi), %rsi
23542
23543 movq %r11, 0*8(%rdi)
23544 - movq %r10, 1*8(%rdi)
23545 + movq %rcx, 1*8(%rdi)
23546 movq %r9, 2*8(%rdi)
23547 movq %r8, 3*8(%rdi)
23548 leaq 4*8(%rdi), %rdi
23549 @@ -81,10 +81,10 @@ ENTRY(memmove)
23550 4:
23551 movq %rdx, %rcx
23552 movq -8(%rsi, %rdx), %r11
23553 - lea -8(%rdi, %rdx), %r10
23554 + lea -8(%rdi, %rdx), %r9
23555 shrq $3, %rcx
23556 rep movsq
23557 - movq %r11, (%r10)
23558 + movq %r11, (%r9)
23559 jmp 13f
23560 .Lmemmove_end_forward:
23561
23562 @@ -95,14 +95,14 @@ ENTRY(memmove)
23563 7:
23564 movq %rdx, %rcx
23565 movq (%rsi), %r11
23566 - movq %rdi, %r10
23567 + movq %rdi, %r9
23568 leaq -8(%rsi, %rdx), %rsi
23569 leaq -8(%rdi, %rdx), %rdi
23570 shrq $3, %rcx
23571 std
23572 rep movsq
23573 cld
23574 - movq %r11, (%r10)
23575 + movq %r11, (%r9)
23576 jmp 13f
23577
23578 /*
23579 @@ -127,13 +127,13 @@ ENTRY(memmove)
23580 8:
23581 subq $0x20, %rdx
23582 movq -1*8(%rsi), %r11
23583 - movq -2*8(%rsi), %r10
23584 + movq -2*8(%rsi), %rcx
23585 movq -3*8(%rsi), %r9
23586 movq -4*8(%rsi), %r8
23587 leaq -4*8(%rsi), %rsi
23588
23589 movq %r11, -1*8(%rdi)
23590 - movq %r10, -2*8(%rdi)
23591 + movq %rcx, -2*8(%rdi)
23592 movq %r9, -3*8(%rdi)
23593 movq %r8, -4*8(%rdi)
23594 leaq -4*8(%rdi), %rdi
23595 @@ -151,11 +151,11 @@ ENTRY(memmove)
23596 * Move data from 16 bytes to 31 bytes.
23597 */
23598 movq 0*8(%rsi), %r11
23599 - movq 1*8(%rsi), %r10
23600 + movq 1*8(%rsi), %rcx
23601 movq -2*8(%rsi, %rdx), %r9
23602 movq -1*8(%rsi, %rdx), %r8
23603 movq %r11, 0*8(%rdi)
23604 - movq %r10, 1*8(%rdi)
23605 + movq %rcx, 1*8(%rdi)
23606 movq %r9, -2*8(%rdi, %rdx)
23607 movq %r8, -1*8(%rdi, %rdx)
23608 jmp 13f
23609 @@ -167,9 +167,9 @@ ENTRY(memmove)
23610 * Move data from 8 bytes to 15 bytes.
23611 */
23612 movq 0*8(%rsi), %r11
23613 - movq -1*8(%rsi, %rdx), %r10
23614 + movq -1*8(%rsi, %rdx), %r9
23615 movq %r11, 0*8(%rdi)
23616 - movq %r10, -1*8(%rdi, %rdx)
23617 + movq %r9, -1*8(%rdi, %rdx)
23618 jmp 13f
23619 10:
23620 cmpq $4, %rdx
23621 @@ -178,9 +178,9 @@ ENTRY(memmove)
23622 * Move data from 4 bytes to 7 bytes.
23623 */
23624 movl (%rsi), %r11d
23625 - movl -4(%rsi, %rdx), %r10d
23626 + movl -4(%rsi, %rdx), %r9d
23627 movl %r11d, (%rdi)
23628 - movl %r10d, -4(%rdi, %rdx)
23629 + movl %r9d, -4(%rdi, %rdx)
23630 jmp 13f
23631 11:
23632 cmp $2, %rdx
23633 @@ -189,9 +189,9 @@ ENTRY(memmove)
23634 * Move data from 2 bytes to 3 bytes.
23635 */
23636 movw (%rsi), %r11w
23637 - movw -2(%rsi, %rdx), %r10w
23638 + movw -2(%rsi, %rdx), %r9w
23639 movw %r11w, (%rdi)
23640 - movw %r10w, -2(%rdi, %rdx)
23641 + movw %r9w, -2(%rdi, %rdx)
23642 jmp 13f
23643 12:
23644 cmp $1, %rdx
23645 @@ -202,6 +202,7 @@ ENTRY(memmove)
23646 movb (%rsi), %r11b
23647 movb %r11b, (%rdi)
23648 13:
23649 + pax_force_retaddr
23650 retq
23651 CFI_ENDPROC
23652
23653 @@ -210,6 +211,7 @@ ENTRY(memmove)
23654 /* Forward moving data. */
23655 movq %rdx, %rcx
23656 rep movsb
23657 + pax_force_retaddr
23658 retq
23659 .Lmemmove_end_forward_efs:
23660 .previous
23661 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23662 index 2dcb380..963660a 100644
23663 --- a/arch/x86/lib/memset_64.S
23664 +++ b/arch/x86/lib/memset_64.S
23665 @@ -30,6 +30,7 @@
23666 movl %edx,%ecx
23667 rep stosb
23668 movq %r9,%rax
23669 + pax_force_retaddr
23670 ret
23671 .Lmemset_e:
23672 .previous
23673 @@ -52,6 +53,7 @@
23674 movq %rdx,%rcx
23675 rep stosb
23676 movq %r9,%rax
23677 + pax_force_retaddr
23678 ret
23679 .Lmemset_e_e:
23680 .previous
23681 @@ -59,7 +61,7 @@
23682 ENTRY(memset)
23683 ENTRY(__memset)
23684 CFI_STARTPROC
23685 - movq %rdi,%r10
23686 + movq %rdi,%r11
23687
23688 /* expand byte value */
23689 movzbl %sil,%ecx
23690 @@ -117,7 +119,8 @@ ENTRY(__memset)
23691 jnz .Lloop_1
23692
23693 .Lende:
23694 - movq %r10,%rax
23695 + movq %r11,%rax
23696 + pax_force_retaddr
23697 ret
23698
23699 CFI_RESTORE_STATE
23700 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23701 index c9f2d9b..e7fd2c0 100644
23702 --- a/arch/x86/lib/mmx_32.c
23703 +++ b/arch/x86/lib/mmx_32.c
23704 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23705 {
23706 void *p;
23707 int i;
23708 + unsigned long cr0;
23709
23710 if (unlikely(in_interrupt()))
23711 return __memcpy(to, from, len);
23712 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23713 kernel_fpu_begin();
23714
23715 __asm__ __volatile__ (
23716 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23717 - " prefetch 64(%0)\n"
23718 - " prefetch 128(%0)\n"
23719 - " prefetch 192(%0)\n"
23720 - " prefetch 256(%0)\n"
23721 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23722 + " prefetch 64(%1)\n"
23723 + " prefetch 128(%1)\n"
23724 + " prefetch 192(%1)\n"
23725 + " prefetch 256(%1)\n"
23726 "2: \n"
23727 ".section .fixup, \"ax\"\n"
23728 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23729 + "3: \n"
23730 +
23731 +#ifdef CONFIG_PAX_KERNEXEC
23732 + " movl %%cr0, %0\n"
23733 + " movl %0, %%eax\n"
23734 + " andl $0xFFFEFFFF, %%eax\n"
23735 + " movl %%eax, %%cr0\n"
23736 +#endif
23737 +
23738 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23739 +
23740 +#ifdef CONFIG_PAX_KERNEXEC
23741 + " movl %0, %%cr0\n"
23742 +#endif
23743 +
23744 " jmp 2b\n"
23745 ".previous\n"
23746 _ASM_EXTABLE(1b, 3b)
23747 - : : "r" (from));
23748 + : "=&r" (cr0) : "r" (from) : "ax");
23749
23750 for ( ; i > 5; i--) {
23751 __asm__ __volatile__ (
23752 - "1: prefetch 320(%0)\n"
23753 - "2: movq (%0), %%mm0\n"
23754 - " movq 8(%0), %%mm1\n"
23755 - " movq 16(%0), %%mm2\n"
23756 - " movq 24(%0), %%mm3\n"
23757 - " movq %%mm0, (%1)\n"
23758 - " movq %%mm1, 8(%1)\n"
23759 - " movq %%mm2, 16(%1)\n"
23760 - " movq %%mm3, 24(%1)\n"
23761 - " movq 32(%0), %%mm0\n"
23762 - " movq 40(%0), %%mm1\n"
23763 - " movq 48(%0), %%mm2\n"
23764 - " movq 56(%0), %%mm3\n"
23765 - " movq %%mm0, 32(%1)\n"
23766 - " movq %%mm1, 40(%1)\n"
23767 - " movq %%mm2, 48(%1)\n"
23768 - " movq %%mm3, 56(%1)\n"
23769 + "1: prefetch 320(%1)\n"
23770 + "2: movq (%1), %%mm0\n"
23771 + " movq 8(%1), %%mm1\n"
23772 + " movq 16(%1), %%mm2\n"
23773 + " movq 24(%1), %%mm3\n"
23774 + " movq %%mm0, (%2)\n"
23775 + " movq %%mm1, 8(%2)\n"
23776 + " movq %%mm2, 16(%2)\n"
23777 + " movq %%mm3, 24(%2)\n"
23778 + " movq 32(%1), %%mm0\n"
23779 + " movq 40(%1), %%mm1\n"
23780 + " movq 48(%1), %%mm2\n"
23781 + " movq 56(%1), %%mm3\n"
23782 + " movq %%mm0, 32(%2)\n"
23783 + " movq %%mm1, 40(%2)\n"
23784 + " movq %%mm2, 48(%2)\n"
23785 + " movq %%mm3, 56(%2)\n"
23786 ".section .fixup, \"ax\"\n"
23787 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23788 + "3:\n"
23789 +
23790 +#ifdef CONFIG_PAX_KERNEXEC
23791 + " movl %%cr0, %0\n"
23792 + " movl %0, %%eax\n"
23793 + " andl $0xFFFEFFFF, %%eax\n"
23794 + " movl %%eax, %%cr0\n"
23795 +#endif
23796 +
23797 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23798 +
23799 +#ifdef CONFIG_PAX_KERNEXEC
23800 + " movl %0, %%cr0\n"
23801 +#endif
23802 +
23803 " jmp 2b\n"
23804 ".previous\n"
23805 _ASM_EXTABLE(1b, 3b)
23806 - : : "r" (from), "r" (to) : "memory");
23807 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23808
23809 from += 64;
23810 to += 64;
23811 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23812 static void fast_copy_page(void *to, void *from)
23813 {
23814 int i;
23815 + unsigned long cr0;
23816
23817 kernel_fpu_begin();
23818
23819 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23820 * but that is for later. -AV
23821 */
23822 __asm__ __volatile__(
23823 - "1: prefetch (%0)\n"
23824 - " prefetch 64(%0)\n"
23825 - " prefetch 128(%0)\n"
23826 - " prefetch 192(%0)\n"
23827 - " prefetch 256(%0)\n"
23828 + "1: prefetch (%1)\n"
23829 + " prefetch 64(%1)\n"
23830 + " prefetch 128(%1)\n"
23831 + " prefetch 192(%1)\n"
23832 + " prefetch 256(%1)\n"
23833 "2: \n"
23834 ".section .fixup, \"ax\"\n"
23835 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23836 + "3: \n"
23837 +
23838 +#ifdef CONFIG_PAX_KERNEXEC
23839 + " movl %%cr0, %0\n"
23840 + " movl %0, %%eax\n"
23841 + " andl $0xFFFEFFFF, %%eax\n"
23842 + " movl %%eax, %%cr0\n"
23843 +#endif
23844 +
23845 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23846 +
23847 +#ifdef CONFIG_PAX_KERNEXEC
23848 + " movl %0, %%cr0\n"
23849 +#endif
23850 +
23851 " jmp 2b\n"
23852 ".previous\n"
23853 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23854 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23855
23856 for (i = 0; i < (4096-320)/64; i++) {
23857 __asm__ __volatile__ (
23858 - "1: prefetch 320(%0)\n"
23859 - "2: movq (%0), %%mm0\n"
23860 - " movntq %%mm0, (%1)\n"
23861 - " movq 8(%0), %%mm1\n"
23862 - " movntq %%mm1, 8(%1)\n"
23863 - " movq 16(%0), %%mm2\n"
23864 - " movntq %%mm2, 16(%1)\n"
23865 - " movq 24(%0), %%mm3\n"
23866 - " movntq %%mm3, 24(%1)\n"
23867 - " movq 32(%0), %%mm4\n"
23868 - " movntq %%mm4, 32(%1)\n"
23869 - " movq 40(%0), %%mm5\n"
23870 - " movntq %%mm5, 40(%1)\n"
23871 - " movq 48(%0), %%mm6\n"
23872 - " movntq %%mm6, 48(%1)\n"
23873 - " movq 56(%0), %%mm7\n"
23874 - " movntq %%mm7, 56(%1)\n"
23875 + "1: prefetch 320(%1)\n"
23876 + "2: movq (%1), %%mm0\n"
23877 + " movntq %%mm0, (%2)\n"
23878 + " movq 8(%1), %%mm1\n"
23879 + " movntq %%mm1, 8(%2)\n"
23880 + " movq 16(%1), %%mm2\n"
23881 + " movntq %%mm2, 16(%2)\n"
23882 + " movq 24(%1), %%mm3\n"
23883 + " movntq %%mm3, 24(%2)\n"
23884 + " movq 32(%1), %%mm4\n"
23885 + " movntq %%mm4, 32(%2)\n"
23886 + " movq 40(%1), %%mm5\n"
23887 + " movntq %%mm5, 40(%2)\n"
23888 + " movq 48(%1), %%mm6\n"
23889 + " movntq %%mm6, 48(%2)\n"
23890 + " movq 56(%1), %%mm7\n"
23891 + " movntq %%mm7, 56(%2)\n"
23892 ".section .fixup, \"ax\"\n"
23893 - "3: movw $0x05EB, 1b\n" /* jmp on 5 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 $0x05EB, 1b\n" /* jmp on 5 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), "r" (to) : "memory");
23912 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23913
23914 from += 64;
23915 to += 64;
23916 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23917 static void fast_copy_page(void *to, void *from)
23918 {
23919 int i;
23920 + unsigned long cr0;
23921
23922 kernel_fpu_begin();
23923
23924 __asm__ __volatile__ (
23925 - "1: prefetch (%0)\n"
23926 - " prefetch 64(%0)\n"
23927 - " prefetch 128(%0)\n"
23928 - " prefetch 192(%0)\n"
23929 - " prefetch 256(%0)\n"
23930 + "1: prefetch (%1)\n"
23931 + " prefetch 64(%1)\n"
23932 + " prefetch 128(%1)\n"
23933 + " prefetch 192(%1)\n"
23934 + " prefetch 256(%1)\n"
23935 "2: \n"
23936 ".section .fixup, \"ax\"\n"
23937 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23938 + "3: \n"
23939 +
23940 +#ifdef CONFIG_PAX_KERNEXEC
23941 + " movl %%cr0, %0\n"
23942 + " movl %0, %%eax\n"
23943 + " andl $0xFFFEFFFF, %%eax\n"
23944 + " movl %%eax, %%cr0\n"
23945 +#endif
23946 +
23947 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23948 +
23949 +#ifdef CONFIG_PAX_KERNEXEC
23950 + " movl %0, %%cr0\n"
23951 +#endif
23952 +
23953 " jmp 2b\n"
23954 ".previous\n"
23955 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23956 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23957
23958 for (i = 0; i < 4096/64; i++) {
23959 __asm__ __volatile__ (
23960 - "1: prefetch 320(%0)\n"
23961 - "2: movq (%0), %%mm0\n"
23962 - " movq 8(%0), %%mm1\n"
23963 - " movq 16(%0), %%mm2\n"
23964 - " movq 24(%0), %%mm3\n"
23965 - " movq %%mm0, (%1)\n"
23966 - " movq %%mm1, 8(%1)\n"
23967 - " movq %%mm2, 16(%1)\n"
23968 - " movq %%mm3, 24(%1)\n"
23969 - " movq 32(%0), %%mm0\n"
23970 - " movq 40(%0), %%mm1\n"
23971 - " movq 48(%0), %%mm2\n"
23972 - " movq 56(%0), %%mm3\n"
23973 - " movq %%mm0, 32(%1)\n"
23974 - " movq %%mm1, 40(%1)\n"
23975 - " movq %%mm2, 48(%1)\n"
23976 - " movq %%mm3, 56(%1)\n"
23977 + "1: prefetch 320(%1)\n"
23978 + "2: movq (%1), %%mm0\n"
23979 + " movq 8(%1), %%mm1\n"
23980 + " movq 16(%1), %%mm2\n"
23981 + " movq 24(%1), %%mm3\n"
23982 + " movq %%mm0, (%2)\n"
23983 + " movq %%mm1, 8(%2)\n"
23984 + " movq %%mm2, 16(%2)\n"
23985 + " movq %%mm3, 24(%2)\n"
23986 + " movq 32(%1), %%mm0\n"
23987 + " movq 40(%1), %%mm1\n"
23988 + " movq 48(%1), %%mm2\n"
23989 + " movq 56(%1), %%mm3\n"
23990 + " movq %%mm0, 32(%2)\n"
23991 + " movq %%mm1, 40(%2)\n"
23992 + " movq %%mm2, 48(%2)\n"
23993 + " movq %%mm3, 56(%2)\n"
23994 ".section .fixup, \"ax\"\n"
23995 - "3: movw $0x05EB, 1b\n" /* jmp on 5 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 $0x05EB, 1b\n" /* jmp on 5 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)
24014 - : : "r" (from), "r" (to) : "memory");
24015 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24016
24017 from += 64;
24018 to += 64;
24019 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24020 index f6d13ee..aca5f0b 100644
24021 --- a/arch/x86/lib/msr-reg.S
24022 +++ b/arch/x86/lib/msr-reg.S
24023 @@ -3,6 +3,7 @@
24024 #include <asm/dwarf2.h>
24025 #include <asm/asm.h>
24026 #include <asm/msr.h>
24027 +#include <asm/alternative-asm.h>
24028
24029 #ifdef CONFIG_X86_64
24030 /*
24031 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24032 CFI_STARTPROC
24033 pushq_cfi %rbx
24034 pushq_cfi %rbp
24035 - movq %rdi, %r10 /* Save pointer */
24036 + movq %rdi, %r9 /* Save pointer */
24037 xorl %r11d, %r11d /* Return value */
24038 movl (%rdi), %eax
24039 movl 4(%rdi), %ecx
24040 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24041 movl 28(%rdi), %edi
24042 CFI_REMEMBER_STATE
24043 1: \op
24044 -2: movl %eax, (%r10)
24045 +2: movl %eax, (%r9)
24046 movl %r11d, %eax /* Return value */
24047 - movl %ecx, 4(%r10)
24048 - movl %edx, 8(%r10)
24049 - movl %ebx, 12(%r10)
24050 - movl %ebp, 20(%r10)
24051 - movl %esi, 24(%r10)
24052 - movl %edi, 28(%r10)
24053 + movl %ecx, 4(%r9)
24054 + movl %edx, 8(%r9)
24055 + movl %ebx, 12(%r9)
24056 + movl %ebp, 20(%r9)
24057 + movl %esi, 24(%r9)
24058 + movl %edi, 28(%r9)
24059 popq_cfi %rbp
24060 popq_cfi %rbx
24061 + pax_force_retaddr
24062 ret
24063 3:
24064 CFI_RESTORE_STATE
24065 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24066 index fc6ba17..04471c5 100644
24067 --- a/arch/x86/lib/putuser.S
24068 +++ b/arch/x86/lib/putuser.S
24069 @@ -16,7 +16,9 @@
24070 #include <asm/errno.h>
24071 #include <asm/asm.h>
24072 #include <asm/smap.h>
24073 -
24074 +#include <asm/segment.h>
24075 +#include <asm/pgtable.h>
24076 +#include <asm/alternative-asm.h>
24077
24078 /*
24079 * __put_user_X
24080 @@ -30,57 +32,125 @@
24081 * as they get called from within inline assembly.
24082 */
24083
24084 -#define ENTER CFI_STARTPROC ; \
24085 - GET_THREAD_INFO(%_ASM_BX)
24086 -#define EXIT ASM_CLAC ; \
24087 - ret ; \
24088 +#define ENTER CFI_STARTPROC
24089 +#define EXIT ASM_CLAC ; \
24090 + pax_force_retaddr ; \
24091 + ret ; \
24092 CFI_ENDPROC
24093
24094 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24095 +#define _DEST %_ASM_CX,%_ASM_BX
24096 +#else
24097 +#define _DEST %_ASM_CX
24098 +#endif
24099 +
24100 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24101 +#define __copyuser_seg gs;
24102 +#else
24103 +#define __copyuser_seg
24104 +#endif
24105 +
24106 .text
24107 ENTRY(__put_user_1)
24108 ENTER
24109 +
24110 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24111 + GET_THREAD_INFO(%_ASM_BX)
24112 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24113 jae bad_put_user
24114 ASM_STAC
24115 -1: movb %al,(%_ASM_CX)
24116 +
24117 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24118 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24119 + cmp %_ASM_BX,%_ASM_CX
24120 + jb 1234f
24121 + xor %ebx,%ebx
24122 +1234:
24123 +#endif
24124 +
24125 +#endif
24126 +
24127 +1: __copyuser_seg movb %al,(_DEST)
24128 xor %eax,%eax
24129 EXIT
24130 ENDPROC(__put_user_1)
24131
24132 ENTRY(__put_user_2)
24133 ENTER
24134 +
24135 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24136 + GET_THREAD_INFO(%_ASM_BX)
24137 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24138 sub $1,%_ASM_BX
24139 cmp %_ASM_BX,%_ASM_CX
24140 jae bad_put_user
24141 ASM_STAC
24142 -2: movw %ax,(%_ASM_CX)
24143 +
24144 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24145 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24146 + cmp %_ASM_BX,%_ASM_CX
24147 + jb 1234f
24148 + xor %ebx,%ebx
24149 +1234:
24150 +#endif
24151 +
24152 +#endif
24153 +
24154 +2: __copyuser_seg movw %ax,(_DEST)
24155 xor %eax,%eax
24156 EXIT
24157 ENDPROC(__put_user_2)
24158
24159 ENTRY(__put_user_4)
24160 ENTER
24161 +
24162 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24163 + GET_THREAD_INFO(%_ASM_BX)
24164 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24165 sub $3,%_ASM_BX
24166 cmp %_ASM_BX,%_ASM_CX
24167 jae bad_put_user
24168 ASM_STAC
24169 -3: movl %eax,(%_ASM_CX)
24170 +
24171 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24172 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24173 + cmp %_ASM_BX,%_ASM_CX
24174 + jb 1234f
24175 + xor %ebx,%ebx
24176 +1234:
24177 +#endif
24178 +
24179 +#endif
24180 +
24181 +3: __copyuser_seg movl %eax,(_DEST)
24182 xor %eax,%eax
24183 EXIT
24184 ENDPROC(__put_user_4)
24185
24186 ENTRY(__put_user_8)
24187 ENTER
24188 +
24189 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24190 + GET_THREAD_INFO(%_ASM_BX)
24191 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24192 sub $7,%_ASM_BX
24193 cmp %_ASM_BX,%_ASM_CX
24194 jae bad_put_user
24195 ASM_STAC
24196 -4: mov %_ASM_AX,(%_ASM_CX)
24197 +
24198 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24199 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24200 + cmp %_ASM_BX,%_ASM_CX
24201 + jb 1234f
24202 + xor %ebx,%ebx
24203 +1234:
24204 +#endif
24205 +
24206 +#endif
24207 +
24208 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
24209 #ifdef CONFIG_X86_32
24210 -5: movl %edx,4(%_ASM_CX)
24211 +5: __copyuser_seg movl %edx,4(_DEST)
24212 #endif
24213 xor %eax,%eax
24214 EXIT
24215 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24216 index 1cad221..de671ee 100644
24217 --- a/arch/x86/lib/rwlock.S
24218 +++ b/arch/x86/lib/rwlock.S
24219 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24220 FRAME
24221 0: LOCK_PREFIX
24222 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24223 +
24224 +#ifdef CONFIG_PAX_REFCOUNT
24225 + jno 1234f
24226 + LOCK_PREFIX
24227 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24228 + int $4
24229 +1234:
24230 + _ASM_EXTABLE(1234b, 1234b)
24231 +#endif
24232 +
24233 1: rep; nop
24234 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24235 jne 1b
24236 LOCK_PREFIX
24237 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24238 +
24239 +#ifdef CONFIG_PAX_REFCOUNT
24240 + jno 1234f
24241 + LOCK_PREFIX
24242 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24243 + int $4
24244 +1234:
24245 + _ASM_EXTABLE(1234b, 1234b)
24246 +#endif
24247 +
24248 jnz 0b
24249 ENDFRAME
24250 + pax_force_retaddr
24251 ret
24252 CFI_ENDPROC
24253 END(__write_lock_failed)
24254 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24255 FRAME
24256 0: LOCK_PREFIX
24257 READ_LOCK_SIZE(inc) (%__lock_ptr)
24258 +
24259 +#ifdef CONFIG_PAX_REFCOUNT
24260 + jno 1234f
24261 + LOCK_PREFIX
24262 + READ_LOCK_SIZE(dec) (%__lock_ptr)
24263 + int $4
24264 +1234:
24265 + _ASM_EXTABLE(1234b, 1234b)
24266 +#endif
24267 +
24268 1: rep; nop
24269 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24270 js 1b
24271 LOCK_PREFIX
24272 READ_LOCK_SIZE(dec) (%__lock_ptr)
24273 +
24274 +#ifdef CONFIG_PAX_REFCOUNT
24275 + jno 1234f
24276 + LOCK_PREFIX
24277 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24278 + int $4
24279 +1234:
24280 + _ASM_EXTABLE(1234b, 1234b)
24281 +#endif
24282 +
24283 js 0b
24284 ENDFRAME
24285 + pax_force_retaddr
24286 ret
24287 CFI_ENDPROC
24288 END(__read_lock_failed)
24289 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24290 index 5dff5f0..cadebf4 100644
24291 --- a/arch/x86/lib/rwsem.S
24292 +++ b/arch/x86/lib/rwsem.S
24293 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24294 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24295 CFI_RESTORE __ASM_REG(dx)
24296 restore_common_regs
24297 + pax_force_retaddr
24298 ret
24299 CFI_ENDPROC
24300 ENDPROC(call_rwsem_down_read_failed)
24301 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24302 movq %rax,%rdi
24303 call rwsem_down_write_failed
24304 restore_common_regs
24305 + pax_force_retaddr
24306 ret
24307 CFI_ENDPROC
24308 ENDPROC(call_rwsem_down_write_failed)
24309 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24310 movq %rax,%rdi
24311 call rwsem_wake
24312 restore_common_regs
24313 -1: ret
24314 +1: pax_force_retaddr
24315 + ret
24316 CFI_ENDPROC
24317 ENDPROC(call_rwsem_wake)
24318
24319 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24320 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24321 CFI_RESTORE __ASM_REG(dx)
24322 restore_common_regs
24323 + pax_force_retaddr
24324 ret
24325 CFI_ENDPROC
24326 ENDPROC(call_rwsem_downgrade_wake)
24327 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24328 index a63efd6..ccecad8 100644
24329 --- a/arch/x86/lib/thunk_64.S
24330 +++ b/arch/x86/lib/thunk_64.S
24331 @@ -8,6 +8,7 @@
24332 #include <linux/linkage.h>
24333 #include <asm/dwarf2.h>
24334 #include <asm/calling.h>
24335 +#include <asm/alternative-asm.h>
24336
24337 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24338 .macro THUNK name, func, put_ret_addr_in_rdi=0
24339 @@ -41,5 +42,6 @@
24340 SAVE_ARGS
24341 restore:
24342 RESTORE_ARGS
24343 + pax_force_retaddr
24344 ret
24345 CFI_ENDPROC
24346 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24347 index 98f6d6b6..d27f045 100644
24348 --- a/arch/x86/lib/usercopy_32.c
24349 +++ b/arch/x86/lib/usercopy_32.c
24350 @@ -42,11 +42,13 @@ do { \
24351 int __d0; \
24352 might_fault(); \
24353 __asm__ __volatile__( \
24354 + __COPYUSER_SET_ES \
24355 ASM_STAC "\n" \
24356 "0: rep; stosl\n" \
24357 " movl %2,%0\n" \
24358 "1: rep; stosb\n" \
24359 "2: " ASM_CLAC "\n" \
24360 + __COPYUSER_RESTORE_ES \
24361 ".section .fixup,\"ax\"\n" \
24362 "3: lea 0(%2,%0,4),%0\n" \
24363 " jmp 2b\n" \
24364 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24365
24366 #ifdef CONFIG_X86_INTEL_USERCOPY
24367 static unsigned long
24368 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24369 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24370 {
24371 int d0, d1;
24372 __asm__ __volatile__(
24373 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24374 " .align 2,0x90\n"
24375 "3: movl 0(%4), %%eax\n"
24376 "4: movl 4(%4), %%edx\n"
24377 - "5: movl %%eax, 0(%3)\n"
24378 - "6: movl %%edx, 4(%3)\n"
24379 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24380 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24381 "7: movl 8(%4), %%eax\n"
24382 "8: movl 12(%4),%%edx\n"
24383 - "9: movl %%eax, 8(%3)\n"
24384 - "10: movl %%edx, 12(%3)\n"
24385 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24386 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24387 "11: movl 16(%4), %%eax\n"
24388 "12: movl 20(%4), %%edx\n"
24389 - "13: movl %%eax, 16(%3)\n"
24390 - "14: movl %%edx, 20(%3)\n"
24391 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24392 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24393 "15: movl 24(%4), %%eax\n"
24394 "16: movl 28(%4), %%edx\n"
24395 - "17: movl %%eax, 24(%3)\n"
24396 - "18: movl %%edx, 28(%3)\n"
24397 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24398 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24399 "19: movl 32(%4), %%eax\n"
24400 "20: movl 36(%4), %%edx\n"
24401 - "21: movl %%eax, 32(%3)\n"
24402 - "22: movl %%edx, 36(%3)\n"
24403 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24404 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24405 "23: movl 40(%4), %%eax\n"
24406 "24: movl 44(%4), %%edx\n"
24407 - "25: movl %%eax, 40(%3)\n"
24408 - "26: movl %%edx, 44(%3)\n"
24409 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24410 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24411 "27: movl 48(%4), %%eax\n"
24412 "28: movl 52(%4), %%edx\n"
24413 - "29: movl %%eax, 48(%3)\n"
24414 - "30: movl %%edx, 52(%3)\n"
24415 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24416 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24417 "31: movl 56(%4), %%eax\n"
24418 "32: movl 60(%4), %%edx\n"
24419 - "33: movl %%eax, 56(%3)\n"
24420 - "34: movl %%edx, 60(%3)\n"
24421 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24422 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24423 " addl $-64, %0\n"
24424 " addl $64, %4\n"
24425 " addl $64, %3\n"
24426 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24427 " shrl $2, %0\n"
24428 " andl $3, %%eax\n"
24429 " cld\n"
24430 + __COPYUSER_SET_ES
24431 "99: rep; movsl\n"
24432 "36: movl %%eax, %0\n"
24433 "37: rep; movsb\n"
24434 "100:\n"
24435 + __COPYUSER_RESTORE_ES
24436 ".section .fixup,\"ax\"\n"
24437 "101: lea 0(%%eax,%0,4),%0\n"
24438 " jmp 100b\n"
24439 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24440 }
24441
24442 static unsigned long
24443 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24444 +{
24445 + int d0, d1;
24446 + __asm__ __volatile__(
24447 + " .align 2,0x90\n"
24448 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24449 + " cmpl $67, %0\n"
24450 + " jbe 3f\n"
24451 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24452 + " .align 2,0x90\n"
24453 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24454 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24455 + "5: movl %%eax, 0(%3)\n"
24456 + "6: movl %%edx, 4(%3)\n"
24457 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24458 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24459 + "9: movl %%eax, 8(%3)\n"
24460 + "10: movl %%edx, 12(%3)\n"
24461 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24462 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24463 + "13: movl %%eax, 16(%3)\n"
24464 + "14: movl %%edx, 20(%3)\n"
24465 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24466 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24467 + "17: movl %%eax, 24(%3)\n"
24468 + "18: movl %%edx, 28(%3)\n"
24469 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24470 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24471 + "21: movl %%eax, 32(%3)\n"
24472 + "22: movl %%edx, 36(%3)\n"
24473 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24474 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24475 + "25: movl %%eax, 40(%3)\n"
24476 + "26: movl %%edx, 44(%3)\n"
24477 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24478 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24479 + "29: movl %%eax, 48(%3)\n"
24480 + "30: movl %%edx, 52(%3)\n"
24481 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24482 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24483 + "33: movl %%eax, 56(%3)\n"
24484 + "34: movl %%edx, 60(%3)\n"
24485 + " addl $-64, %0\n"
24486 + " addl $64, %4\n"
24487 + " addl $64, %3\n"
24488 + " cmpl $63, %0\n"
24489 + " ja 1b\n"
24490 + "35: movl %0, %%eax\n"
24491 + " shrl $2, %0\n"
24492 + " andl $3, %%eax\n"
24493 + " cld\n"
24494 + "99: rep; "__copyuser_seg" movsl\n"
24495 + "36: movl %%eax, %0\n"
24496 + "37: rep; "__copyuser_seg" movsb\n"
24497 + "100:\n"
24498 + ".section .fixup,\"ax\"\n"
24499 + "101: lea 0(%%eax,%0,4),%0\n"
24500 + " jmp 100b\n"
24501 + ".previous\n"
24502 + _ASM_EXTABLE(1b,100b)
24503 + _ASM_EXTABLE(2b,100b)
24504 + _ASM_EXTABLE(3b,100b)
24505 + _ASM_EXTABLE(4b,100b)
24506 + _ASM_EXTABLE(5b,100b)
24507 + _ASM_EXTABLE(6b,100b)
24508 + _ASM_EXTABLE(7b,100b)
24509 + _ASM_EXTABLE(8b,100b)
24510 + _ASM_EXTABLE(9b,100b)
24511 + _ASM_EXTABLE(10b,100b)
24512 + _ASM_EXTABLE(11b,100b)
24513 + _ASM_EXTABLE(12b,100b)
24514 + _ASM_EXTABLE(13b,100b)
24515 + _ASM_EXTABLE(14b,100b)
24516 + _ASM_EXTABLE(15b,100b)
24517 + _ASM_EXTABLE(16b,100b)
24518 + _ASM_EXTABLE(17b,100b)
24519 + _ASM_EXTABLE(18b,100b)
24520 + _ASM_EXTABLE(19b,100b)
24521 + _ASM_EXTABLE(20b,100b)
24522 + _ASM_EXTABLE(21b,100b)
24523 + _ASM_EXTABLE(22b,100b)
24524 + _ASM_EXTABLE(23b,100b)
24525 + _ASM_EXTABLE(24b,100b)
24526 + _ASM_EXTABLE(25b,100b)
24527 + _ASM_EXTABLE(26b,100b)
24528 + _ASM_EXTABLE(27b,100b)
24529 + _ASM_EXTABLE(28b,100b)
24530 + _ASM_EXTABLE(29b,100b)
24531 + _ASM_EXTABLE(30b,100b)
24532 + _ASM_EXTABLE(31b,100b)
24533 + _ASM_EXTABLE(32b,100b)
24534 + _ASM_EXTABLE(33b,100b)
24535 + _ASM_EXTABLE(34b,100b)
24536 + _ASM_EXTABLE(35b,100b)
24537 + _ASM_EXTABLE(36b,100b)
24538 + _ASM_EXTABLE(37b,100b)
24539 + _ASM_EXTABLE(99b,101b)
24540 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24541 + : "1"(to), "2"(from), "0"(size)
24542 + : "eax", "edx", "memory");
24543 + return size;
24544 +}
24545 +
24546 +static unsigned long __size_overflow(3)
24547 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24548 {
24549 int d0, d1;
24550 __asm__ __volatile__(
24551 " .align 2,0x90\n"
24552 - "0: movl 32(%4), %%eax\n"
24553 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24554 " cmpl $67, %0\n"
24555 " jbe 2f\n"
24556 - "1: movl 64(%4), %%eax\n"
24557 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24558 " .align 2,0x90\n"
24559 - "2: movl 0(%4), %%eax\n"
24560 - "21: movl 4(%4), %%edx\n"
24561 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24562 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24563 " movl %%eax, 0(%3)\n"
24564 " movl %%edx, 4(%3)\n"
24565 - "3: movl 8(%4), %%eax\n"
24566 - "31: movl 12(%4),%%edx\n"
24567 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24568 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24569 " movl %%eax, 8(%3)\n"
24570 " movl %%edx, 12(%3)\n"
24571 - "4: movl 16(%4), %%eax\n"
24572 - "41: movl 20(%4), %%edx\n"
24573 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24574 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24575 " movl %%eax, 16(%3)\n"
24576 " movl %%edx, 20(%3)\n"
24577 - "10: movl 24(%4), %%eax\n"
24578 - "51: movl 28(%4), %%edx\n"
24579 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24580 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24581 " movl %%eax, 24(%3)\n"
24582 " movl %%edx, 28(%3)\n"
24583 - "11: movl 32(%4), %%eax\n"
24584 - "61: movl 36(%4), %%edx\n"
24585 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24586 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24587 " movl %%eax, 32(%3)\n"
24588 " movl %%edx, 36(%3)\n"
24589 - "12: movl 40(%4), %%eax\n"
24590 - "71: movl 44(%4), %%edx\n"
24591 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24592 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24593 " movl %%eax, 40(%3)\n"
24594 " movl %%edx, 44(%3)\n"
24595 - "13: movl 48(%4), %%eax\n"
24596 - "81: movl 52(%4), %%edx\n"
24597 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24598 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24599 " movl %%eax, 48(%3)\n"
24600 " movl %%edx, 52(%3)\n"
24601 - "14: movl 56(%4), %%eax\n"
24602 - "91: movl 60(%4), %%edx\n"
24603 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24604 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24605 " movl %%eax, 56(%3)\n"
24606 " movl %%edx, 60(%3)\n"
24607 " addl $-64, %0\n"
24608 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24609 " shrl $2, %0\n"
24610 " andl $3, %%eax\n"
24611 " cld\n"
24612 - "6: rep; movsl\n"
24613 + "6: rep; "__copyuser_seg" movsl\n"
24614 " movl %%eax,%0\n"
24615 - "7: rep; movsb\n"
24616 + "7: rep; "__copyuser_seg" movsb\n"
24617 "8:\n"
24618 ".section .fixup,\"ax\"\n"
24619 "9: lea 0(%%eax,%0,4),%0\n"
24620 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24621 * hyoshiok@miraclelinux.com
24622 */
24623
24624 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24625 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24626 const void __user *from, unsigned long size)
24627 {
24628 int d0, d1;
24629
24630 __asm__ __volatile__(
24631 " .align 2,0x90\n"
24632 - "0: movl 32(%4), %%eax\n"
24633 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24634 " cmpl $67, %0\n"
24635 " jbe 2f\n"
24636 - "1: movl 64(%4), %%eax\n"
24637 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24638 " .align 2,0x90\n"
24639 - "2: movl 0(%4), %%eax\n"
24640 - "21: movl 4(%4), %%edx\n"
24641 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24642 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24643 " movnti %%eax, 0(%3)\n"
24644 " movnti %%edx, 4(%3)\n"
24645 - "3: movl 8(%4), %%eax\n"
24646 - "31: movl 12(%4),%%edx\n"
24647 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24648 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24649 " movnti %%eax, 8(%3)\n"
24650 " movnti %%edx, 12(%3)\n"
24651 - "4: movl 16(%4), %%eax\n"
24652 - "41: movl 20(%4), %%edx\n"
24653 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24654 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24655 " movnti %%eax, 16(%3)\n"
24656 " movnti %%edx, 20(%3)\n"
24657 - "10: movl 24(%4), %%eax\n"
24658 - "51: movl 28(%4), %%edx\n"
24659 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24660 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24661 " movnti %%eax, 24(%3)\n"
24662 " movnti %%edx, 28(%3)\n"
24663 - "11: movl 32(%4), %%eax\n"
24664 - "61: movl 36(%4), %%edx\n"
24665 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24666 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24667 " movnti %%eax, 32(%3)\n"
24668 " movnti %%edx, 36(%3)\n"
24669 - "12: movl 40(%4), %%eax\n"
24670 - "71: movl 44(%4), %%edx\n"
24671 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24672 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24673 " movnti %%eax, 40(%3)\n"
24674 " movnti %%edx, 44(%3)\n"
24675 - "13: movl 48(%4), %%eax\n"
24676 - "81: movl 52(%4), %%edx\n"
24677 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24678 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24679 " movnti %%eax, 48(%3)\n"
24680 " movnti %%edx, 52(%3)\n"
24681 - "14: movl 56(%4), %%eax\n"
24682 - "91: movl 60(%4), %%edx\n"
24683 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24684 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24685 " movnti %%eax, 56(%3)\n"
24686 " movnti %%edx, 60(%3)\n"
24687 " addl $-64, %0\n"
24688 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24689 " shrl $2, %0\n"
24690 " andl $3, %%eax\n"
24691 " cld\n"
24692 - "6: rep; movsl\n"
24693 + "6: rep; "__copyuser_seg" movsl\n"
24694 " movl %%eax,%0\n"
24695 - "7: rep; movsb\n"
24696 + "7: rep; "__copyuser_seg" movsb\n"
24697 "8:\n"
24698 ".section .fixup,\"ax\"\n"
24699 "9: lea 0(%%eax,%0,4),%0\n"
24700 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24701 return size;
24702 }
24703
24704 -static unsigned long __copy_user_intel_nocache(void *to,
24705 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24706 const void __user *from, unsigned long size)
24707 {
24708 int d0, d1;
24709
24710 __asm__ __volatile__(
24711 " .align 2,0x90\n"
24712 - "0: movl 32(%4), %%eax\n"
24713 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24714 " cmpl $67, %0\n"
24715 " jbe 2f\n"
24716 - "1: movl 64(%4), %%eax\n"
24717 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24718 " .align 2,0x90\n"
24719 - "2: movl 0(%4), %%eax\n"
24720 - "21: movl 4(%4), %%edx\n"
24721 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24722 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24723 " movnti %%eax, 0(%3)\n"
24724 " movnti %%edx, 4(%3)\n"
24725 - "3: movl 8(%4), %%eax\n"
24726 - "31: movl 12(%4),%%edx\n"
24727 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24728 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24729 " movnti %%eax, 8(%3)\n"
24730 " movnti %%edx, 12(%3)\n"
24731 - "4: movl 16(%4), %%eax\n"
24732 - "41: movl 20(%4), %%edx\n"
24733 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24734 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24735 " movnti %%eax, 16(%3)\n"
24736 " movnti %%edx, 20(%3)\n"
24737 - "10: movl 24(%4), %%eax\n"
24738 - "51: movl 28(%4), %%edx\n"
24739 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24740 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24741 " movnti %%eax, 24(%3)\n"
24742 " movnti %%edx, 28(%3)\n"
24743 - "11: movl 32(%4), %%eax\n"
24744 - "61: movl 36(%4), %%edx\n"
24745 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24746 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24747 " movnti %%eax, 32(%3)\n"
24748 " movnti %%edx, 36(%3)\n"
24749 - "12: movl 40(%4), %%eax\n"
24750 - "71: movl 44(%4), %%edx\n"
24751 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24752 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24753 " movnti %%eax, 40(%3)\n"
24754 " movnti %%edx, 44(%3)\n"
24755 - "13: movl 48(%4), %%eax\n"
24756 - "81: movl 52(%4), %%edx\n"
24757 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24758 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24759 " movnti %%eax, 48(%3)\n"
24760 " movnti %%edx, 52(%3)\n"
24761 - "14: movl 56(%4), %%eax\n"
24762 - "91: movl 60(%4), %%edx\n"
24763 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24764 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24765 " movnti %%eax, 56(%3)\n"
24766 " movnti %%edx, 60(%3)\n"
24767 " addl $-64, %0\n"
24768 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24769 " shrl $2, %0\n"
24770 " andl $3, %%eax\n"
24771 " cld\n"
24772 - "6: rep; movsl\n"
24773 + "6: rep; "__copyuser_seg" movsl\n"
24774 " movl %%eax,%0\n"
24775 - "7: rep; movsb\n"
24776 + "7: rep; "__copyuser_seg" movsb\n"
24777 "8:\n"
24778 ".section .fixup,\"ax\"\n"
24779 "9: lea 0(%%eax,%0,4),%0\n"
24780 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24781 */
24782 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24783 unsigned long size);
24784 -unsigned long __copy_user_intel(void __user *to, const void *from,
24785 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24786 + unsigned long size);
24787 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24788 unsigned long size);
24789 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24790 const void __user *from, unsigned long size);
24791 #endif /* CONFIG_X86_INTEL_USERCOPY */
24792
24793 /* Generic arbitrary sized copy. */
24794 -#define __copy_user(to, from, size) \
24795 +#define __copy_user(to, from, size, prefix, set, restore) \
24796 do { \
24797 int __d0, __d1, __d2; \
24798 __asm__ __volatile__( \
24799 + set \
24800 " cmp $7,%0\n" \
24801 " jbe 1f\n" \
24802 " movl %1,%0\n" \
24803 " negl %0\n" \
24804 " andl $7,%0\n" \
24805 " subl %0,%3\n" \
24806 - "4: rep; movsb\n" \
24807 + "4: rep; "prefix"movsb\n" \
24808 " movl %3,%0\n" \
24809 " shrl $2,%0\n" \
24810 " andl $3,%3\n" \
24811 " .align 2,0x90\n" \
24812 - "0: rep; movsl\n" \
24813 + "0: rep; "prefix"movsl\n" \
24814 " movl %3,%0\n" \
24815 - "1: rep; movsb\n" \
24816 + "1: rep; "prefix"movsb\n" \
24817 "2:\n" \
24818 + restore \
24819 ".section .fixup,\"ax\"\n" \
24820 "5: addl %3,%0\n" \
24821 " jmp 2b\n" \
24822 @@ -538,14 +650,14 @@ do { \
24823 " negl %0\n" \
24824 " andl $7,%0\n" \
24825 " subl %0,%3\n" \
24826 - "4: rep; movsb\n" \
24827 + "4: rep; "__copyuser_seg"movsb\n" \
24828 " movl %3,%0\n" \
24829 " shrl $2,%0\n" \
24830 " andl $3,%3\n" \
24831 " .align 2,0x90\n" \
24832 - "0: rep; movsl\n" \
24833 + "0: rep; "__copyuser_seg"movsl\n" \
24834 " movl %3,%0\n" \
24835 - "1: rep; movsb\n" \
24836 + "1: rep; "__copyuser_seg"movsb\n" \
24837 "2:\n" \
24838 ".section .fixup,\"ax\"\n" \
24839 "5: addl %3,%0\n" \
24840 @@ -629,9 +741,9 @@ survive:
24841 #endif
24842 stac();
24843 if (movsl_is_ok(to, from, n))
24844 - __copy_user(to, from, n);
24845 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24846 else
24847 - n = __copy_user_intel(to, from, n);
24848 + n = __generic_copy_to_user_intel(to, from, n);
24849 clac();
24850 return n;
24851 }
24852 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24853 {
24854 stac();
24855 if (movsl_is_ok(to, from, n))
24856 - __copy_user(to, from, n);
24857 + __copy_user(to, from, n, __copyuser_seg, "", "");
24858 else
24859 - n = __copy_user_intel((void __user *)to,
24860 - (const void *)from, n);
24861 + n = __generic_copy_from_user_intel(to, from, n);
24862 clac();
24863 return n;
24864 }
24865 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24866 if (n > 64 && cpu_has_xmm2)
24867 n = __copy_user_intel_nocache(to, from, n);
24868 else
24869 - __copy_user(to, from, n);
24870 + __copy_user(to, from, n, __copyuser_seg, "", "");
24871 #else
24872 - __copy_user(to, from, n);
24873 + __copy_user(to, from, n, __copyuser_seg, "", "");
24874 #endif
24875 clac();
24876 return n;
24877 }
24878 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24879
24880 -/**
24881 - * copy_to_user: - Copy a block of data into user space.
24882 - * @to: Destination address, in user space.
24883 - * @from: Source address, in kernel space.
24884 - * @n: Number of bytes to copy.
24885 - *
24886 - * Context: User context only. This function may sleep.
24887 - *
24888 - * Copy data from kernel space to user space.
24889 - *
24890 - * Returns number of bytes that could not be copied.
24891 - * On success, this will be zero.
24892 - */
24893 -unsigned long
24894 -copy_to_user(void __user *to, const void *from, unsigned long n)
24895 -{
24896 - if (access_ok(VERIFY_WRITE, to, n))
24897 - n = __copy_to_user(to, from, n);
24898 - return n;
24899 -}
24900 -EXPORT_SYMBOL(copy_to_user);
24901 -
24902 -/**
24903 - * copy_from_user: - Copy a block of data from user space.
24904 - * @to: Destination address, in kernel space.
24905 - * @from: Source address, in user space.
24906 - * @n: Number of bytes to copy.
24907 - *
24908 - * Context: User context only. This function may sleep.
24909 - *
24910 - * Copy data from user space to kernel space.
24911 - *
24912 - * Returns number of bytes that could not be copied.
24913 - * On success, this will be zero.
24914 - *
24915 - * If some data could not be copied, this function will pad the copied
24916 - * data to the requested size using zero bytes.
24917 - */
24918 -unsigned long
24919 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24920 -{
24921 - if (access_ok(VERIFY_READ, from, n))
24922 - n = __copy_from_user(to, from, n);
24923 - else
24924 - memset(to, 0, n);
24925 - return n;
24926 -}
24927 -EXPORT_SYMBOL(_copy_from_user);
24928 -
24929 void copy_from_user_overflow(void)
24930 {
24931 WARN(1, "Buffer overflow detected!\n");
24932 }
24933 EXPORT_SYMBOL(copy_from_user_overflow);
24934 +
24935 +void copy_to_user_overflow(void)
24936 +{
24937 + WARN(1, "Buffer overflow detected!\n");
24938 +}
24939 +EXPORT_SYMBOL(copy_to_user_overflow);
24940 +
24941 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24942 +void __set_fs(mm_segment_t x)
24943 +{
24944 + switch (x.seg) {
24945 + case 0:
24946 + loadsegment(gs, 0);
24947 + break;
24948 + case TASK_SIZE_MAX:
24949 + loadsegment(gs, __USER_DS);
24950 + break;
24951 + case -1UL:
24952 + loadsegment(gs, __KERNEL_DS);
24953 + break;
24954 + default:
24955 + BUG();
24956 + }
24957 + return;
24958 +}
24959 +EXPORT_SYMBOL(__set_fs);
24960 +
24961 +void set_fs(mm_segment_t x)
24962 +{
24963 + current_thread_info()->addr_limit = x;
24964 + __set_fs(x);
24965 +}
24966 +EXPORT_SYMBOL(set_fs);
24967 +#endif
24968 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
24969 index 05928aa..b33dea1 100644
24970 --- a/arch/x86/lib/usercopy_64.c
24971 +++ b/arch/x86/lib/usercopy_64.c
24972 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
24973 _ASM_EXTABLE(0b,3b)
24974 _ASM_EXTABLE(1b,2b)
24975 : [size8] "=&c"(size), [dst] "=&D" (__d0)
24976 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
24977 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
24978 [zero] "r" (0UL), [eight] "r" (8UL));
24979 clac();
24980 return size;
24981 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
24982 }
24983 EXPORT_SYMBOL(clear_user);
24984
24985 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
24986 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
24987 {
24988 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24989 - return copy_user_generic((__force void *)to, (__force void *)from, len);
24990 - }
24991 - return len;
24992 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
24993 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
24994 + return len;
24995 }
24996 EXPORT_SYMBOL(copy_in_user);
24997
24998 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
24999 * it is not necessary to optimize tail handling.
25000 */
25001 unsigned long
25002 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25003 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25004 {
25005 char c;
25006 unsigned zero_len;
25007 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25008 clac();
25009 return len;
25010 }
25011 +
25012 +void copy_from_user_overflow(void)
25013 +{
25014 + WARN(1, "Buffer overflow detected!\n");
25015 +}
25016 +EXPORT_SYMBOL(copy_from_user_overflow);
25017 +
25018 +void copy_to_user_overflow(void)
25019 +{
25020 + WARN(1, "Buffer overflow detected!\n");
25021 +}
25022 +EXPORT_SYMBOL(copy_to_user_overflow);
25023 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25024 index 903ec1e..c4166b2 100644
25025 --- a/arch/x86/mm/extable.c
25026 +++ b/arch/x86/mm/extable.c
25027 @@ -6,12 +6,24 @@
25028 static inline unsigned long
25029 ex_insn_addr(const struct exception_table_entry *x)
25030 {
25031 - return (unsigned long)&x->insn + x->insn;
25032 + unsigned long reloc = 0;
25033 +
25034 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25035 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25036 +#endif
25037 +
25038 + return (unsigned long)&x->insn + x->insn + reloc;
25039 }
25040 static inline unsigned long
25041 ex_fixup_addr(const struct exception_table_entry *x)
25042 {
25043 - return (unsigned long)&x->fixup + x->fixup;
25044 + unsigned long reloc = 0;
25045 +
25046 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25047 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25048 +#endif
25049 +
25050 + return (unsigned long)&x->fixup + x->fixup + reloc;
25051 }
25052
25053 int fixup_exception(struct pt_regs *regs)
25054 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25055 unsigned long new_ip;
25056
25057 #ifdef CONFIG_PNPBIOS
25058 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25059 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25060 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25061 extern u32 pnp_bios_is_utter_crap;
25062 pnp_bios_is_utter_crap = 1;
25063 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25064 i += 4;
25065 p->fixup -= i;
25066 i += 4;
25067 +
25068 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25069 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25070 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25071 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25072 +#endif
25073 +
25074 }
25075 }
25076
25077 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25078 index 8e13ecb..831f2d0 100644
25079 --- a/arch/x86/mm/fault.c
25080 +++ b/arch/x86/mm/fault.c
25081 @@ -13,12 +13,19 @@
25082 #include <linux/perf_event.h> /* perf_sw_event */
25083 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25084 #include <linux/prefetch.h> /* prefetchw */
25085 +#include <linux/unistd.h>
25086 +#include <linux/compiler.h>
25087
25088 #include <asm/traps.h> /* dotraplinkage, ... */
25089 #include <asm/pgalloc.h> /* pgd_*(), ... */
25090 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25091 #include <asm/fixmap.h> /* VSYSCALL_START */
25092 #include <asm/rcu.h> /* exception_enter(), ... */
25093 +#include <asm/tlbflush.h>
25094 +
25095 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25096 +#include <asm/stacktrace.h>
25097 +#endif
25098
25099 /*
25100 * Page fault error code bits:
25101 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25102 int ret = 0;
25103
25104 /* kprobe_running() needs smp_processor_id() */
25105 - if (kprobes_built_in() && !user_mode_vm(regs)) {
25106 + if (kprobes_built_in() && !user_mode(regs)) {
25107 preempt_disable();
25108 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25109 ret = 1;
25110 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25111 return !instr_lo || (instr_lo>>1) == 1;
25112 case 0x00:
25113 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25114 - if (probe_kernel_address(instr, opcode))
25115 + if (user_mode(regs)) {
25116 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25117 + return 0;
25118 + } else if (probe_kernel_address(instr, opcode))
25119 return 0;
25120
25121 *prefetch = (instr_lo == 0xF) &&
25122 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25123 while (instr < max_instr) {
25124 unsigned char opcode;
25125
25126 - if (probe_kernel_address(instr, opcode))
25127 + if (user_mode(regs)) {
25128 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25129 + break;
25130 + } else if (probe_kernel_address(instr, opcode))
25131 break;
25132
25133 instr++;
25134 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25135 force_sig_info(si_signo, &info, tsk);
25136 }
25137
25138 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25139 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25140 +#endif
25141 +
25142 +#ifdef CONFIG_PAX_EMUTRAMP
25143 +static int pax_handle_fetch_fault(struct pt_regs *regs);
25144 +#endif
25145 +
25146 +#ifdef CONFIG_PAX_PAGEEXEC
25147 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25148 +{
25149 + pgd_t *pgd;
25150 + pud_t *pud;
25151 + pmd_t *pmd;
25152 +
25153 + pgd = pgd_offset(mm, address);
25154 + if (!pgd_present(*pgd))
25155 + return NULL;
25156 + pud = pud_offset(pgd, address);
25157 + if (!pud_present(*pud))
25158 + return NULL;
25159 + pmd = pmd_offset(pud, address);
25160 + if (!pmd_present(*pmd))
25161 + return NULL;
25162 + return pmd;
25163 +}
25164 +#endif
25165 +
25166 DEFINE_SPINLOCK(pgd_lock);
25167 LIST_HEAD(pgd_list);
25168
25169 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25170 for (address = VMALLOC_START & PMD_MASK;
25171 address >= TASK_SIZE && address < FIXADDR_TOP;
25172 address += PMD_SIZE) {
25173 +
25174 +#ifdef CONFIG_PAX_PER_CPU_PGD
25175 + unsigned long cpu;
25176 +#else
25177 struct page *page;
25178 +#endif
25179
25180 spin_lock(&pgd_lock);
25181 +
25182 +#ifdef CONFIG_PAX_PER_CPU_PGD
25183 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25184 + pgd_t *pgd = get_cpu_pgd(cpu);
25185 + pmd_t *ret;
25186 +#else
25187 list_for_each_entry(page, &pgd_list, lru) {
25188 + pgd_t *pgd = page_address(page);
25189 spinlock_t *pgt_lock;
25190 pmd_t *ret;
25191
25192 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25193 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25194
25195 spin_lock(pgt_lock);
25196 - ret = vmalloc_sync_one(page_address(page), address);
25197 +#endif
25198 +
25199 + ret = vmalloc_sync_one(pgd, address);
25200 +
25201 +#ifndef CONFIG_PAX_PER_CPU_PGD
25202 spin_unlock(pgt_lock);
25203 +#endif
25204
25205 if (!ret)
25206 break;
25207 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25208 * an interrupt in the middle of a task switch..
25209 */
25210 pgd_paddr = read_cr3();
25211 +
25212 +#ifdef CONFIG_PAX_PER_CPU_PGD
25213 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25214 +#endif
25215 +
25216 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25217 if (!pmd_k)
25218 return -1;
25219 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25220 * happen within a race in page table update. In the later
25221 * case just flush:
25222 */
25223 +
25224 +#ifdef CONFIG_PAX_PER_CPU_PGD
25225 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25226 + pgd = pgd_offset_cpu(smp_processor_id(), address);
25227 +#else
25228 pgd = pgd_offset(current->active_mm, address);
25229 +#endif
25230 +
25231 pgd_ref = pgd_offset_k(address);
25232 if (pgd_none(*pgd_ref))
25233 return -1;
25234 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25235 static int is_errata100(struct pt_regs *regs, unsigned long address)
25236 {
25237 #ifdef CONFIG_X86_64
25238 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25239 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25240 return 1;
25241 #endif
25242 return 0;
25243 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25244 }
25245
25246 static const char nx_warning[] = KERN_CRIT
25247 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25248 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25249
25250 static void
25251 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25252 @@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25253 if (!oops_may_print())
25254 return;
25255
25256 - if (error_code & PF_INSTR) {
25257 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25258 unsigned int level;
25259
25260 pte_t *pte = lookup_address(address, &level);
25261
25262 if (pte && pte_present(*pte) && !pte_exec(*pte))
25263 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25264 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25265 }
25266
25267 +#ifdef CONFIG_PAX_KERNEXEC
25268 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25269 + if (current->signal->curr_ip)
25270 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25271 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
25272 + else
25273 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25274 + current->comm, task_pid_nr(current), current_uid(), current_euid());
25275 + }
25276 +#endif
25277 +
25278 printk(KERN_ALERT "BUG: unable to handle kernel ");
25279 if (address < PAGE_SIZE)
25280 printk(KERN_CONT "NULL pointer dereference");
25281 @@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25282 }
25283 #endif
25284
25285 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25286 + if (pax_is_fetch_fault(regs, error_code, address)) {
25287 +
25288 +#ifdef CONFIG_PAX_EMUTRAMP
25289 + switch (pax_handle_fetch_fault(regs)) {
25290 + case 2:
25291 + return;
25292 + }
25293 +#endif
25294 +
25295 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25296 + do_group_exit(SIGKILL);
25297 + }
25298 +#endif
25299 +
25300 if (unlikely(show_unhandled_signals))
25301 show_signal_msg(regs, error_code, address, tsk);
25302
25303 @@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25304 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25305 printk(KERN_ERR
25306 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25307 - tsk->comm, tsk->pid, address);
25308 + tsk->comm, task_pid_nr(tsk), address);
25309 code = BUS_MCEERR_AR;
25310 }
25311 #endif
25312 @@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25313 return 1;
25314 }
25315
25316 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25317 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25318 +{
25319 + pte_t *pte;
25320 + pmd_t *pmd;
25321 + spinlock_t *ptl;
25322 + unsigned char pte_mask;
25323 +
25324 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25325 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25326 + return 0;
25327 +
25328 + /* PaX: it's our fault, let's handle it if we can */
25329 +
25330 + /* PaX: take a look at read faults before acquiring any locks */
25331 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25332 + /* instruction fetch attempt from a protected page in user mode */
25333 + up_read(&mm->mmap_sem);
25334 +
25335 +#ifdef CONFIG_PAX_EMUTRAMP
25336 + switch (pax_handle_fetch_fault(regs)) {
25337 + case 2:
25338 + return 1;
25339 + }
25340 +#endif
25341 +
25342 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25343 + do_group_exit(SIGKILL);
25344 + }
25345 +
25346 + pmd = pax_get_pmd(mm, address);
25347 + if (unlikely(!pmd))
25348 + return 0;
25349 +
25350 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25351 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25352 + pte_unmap_unlock(pte, ptl);
25353 + return 0;
25354 + }
25355 +
25356 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25357 + /* write attempt to a protected page in user mode */
25358 + pte_unmap_unlock(pte, ptl);
25359 + return 0;
25360 + }
25361 +
25362 +#ifdef CONFIG_SMP
25363 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25364 +#else
25365 + if (likely(address > get_limit(regs->cs)))
25366 +#endif
25367 + {
25368 + set_pte(pte, pte_mkread(*pte));
25369 + __flush_tlb_one(address);
25370 + pte_unmap_unlock(pte, ptl);
25371 + up_read(&mm->mmap_sem);
25372 + return 1;
25373 + }
25374 +
25375 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25376 +
25377 + /*
25378 + * PaX: fill DTLB with user rights and retry
25379 + */
25380 + __asm__ __volatile__ (
25381 + "orb %2,(%1)\n"
25382 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25383 +/*
25384 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25385 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25386 + * page fault when examined during a TLB load attempt. this is true not only
25387 + * for PTEs holding a non-present entry but also present entries that will
25388 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25389 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25390 + * for our target pages since their PTEs are simply not in the TLBs at all.
25391 +
25392 + * the best thing in omitting it is that we gain around 15-20% speed in the
25393 + * fast path of the page fault handler and can get rid of tracing since we
25394 + * can no longer flush unintended entries.
25395 + */
25396 + "invlpg (%0)\n"
25397 +#endif
25398 + __copyuser_seg"testb $0,(%0)\n"
25399 + "xorb %3,(%1)\n"
25400 + :
25401 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25402 + : "memory", "cc");
25403 + pte_unmap_unlock(pte, ptl);
25404 + up_read(&mm->mmap_sem);
25405 + return 1;
25406 +}
25407 +#endif
25408 +
25409 /*
25410 * Handle a spurious fault caused by a stale TLB entry.
25411 *
25412 @@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
25413 static inline int
25414 access_error(unsigned long error_code, struct vm_area_struct *vma)
25415 {
25416 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25417 + return 1;
25418 +
25419 if (error_code & PF_WRITE) {
25420 /* write, present and write, not present: */
25421 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25422 @@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25423 if (error_code & PF_USER)
25424 return false;
25425
25426 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25427 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25428 return false;
25429
25430 return true;
25431 @@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25432 {
25433 struct vm_area_struct *vma;
25434 struct task_struct *tsk;
25435 - unsigned long address;
25436 struct mm_struct *mm;
25437 int fault;
25438 int write = error_code & PF_WRITE;
25439 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25440 (write ? FAULT_FLAG_WRITE : 0);
25441
25442 - tsk = current;
25443 - mm = tsk->mm;
25444 -
25445 /* Get the faulting address: */
25446 - address = read_cr2();
25447 + unsigned long address = read_cr2();
25448 +
25449 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25450 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25451 + if (!search_exception_tables(regs->ip)) {
25452 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25453 + bad_area_nosemaphore(regs, error_code, address);
25454 + return;
25455 + }
25456 + if (address < PAX_USER_SHADOW_BASE) {
25457 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25458 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25459 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25460 + } else
25461 + address -= PAX_USER_SHADOW_BASE;
25462 + }
25463 +#endif
25464 +
25465 + tsk = current;
25466 + mm = tsk->mm;
25467
25468 /*
25469 * Detect and handle instructions that would cause a page fault for
25470 @@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25471 * User-mode registers count as a user access even for any
25472 * potential system fault or CPU buglet:
25473 */
25474 - if (user_mode_vm(regs)) {
25475 + if (user_mode(regs)) {
25476 local_irq_enable();
25477 error_code |= PF_USER;
25478 } else {
25479 @@ -1151,6 +1358,11 @@ retry:
25480 might_sleep();
25481 }
25482
25483 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25484 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25485 + return;
25486 +#endif
25487 +
25488 vma = find_vma(mm, address);
25489 if (unlikely(!vma)) {
25490 bad_area(regs, error_code, address);
25491 @@ -1162,18 +1374,24 @@ retry:
25492 bad_area(regs, error_code, address);
25493 return;
25494 }
25495 - if (error_code & PF_USER) {
25496 - /*
25497 - * Accessing the stack below %sp is always a bug.
25498 - * The large cushion allows instructions like enter
25499 - * and pusha to work. ("enter $65535, $31" pushes
25500 - * 32 pointers and then decrements %sp by 65535.)
25501 - */
25502 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25503 - bad_area(regs, error_code, address);
25504 - return;
25505 - }
25506 + /*
25507 + * Accessing the stack below %sp is always a bug.
25508 + * The large cushion allows instructions like enter
25509 + * and pusha to work. ("enter $65535, $31" pushes
25510 + * 32 pointers and then decrements %sp by 65535.)
25511 + */
25512 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25513 + bad_area(regs, error_code, address);
25514 + return;
25515 }
25516 +
25517 +#ifdef CONFIG_PAX_SEGMEXEC
25518 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25519 + bad_area(regs, error_code, address);
25520 + return;
25521 + }
25522 +#endif
25523 +
25524 if (unlikely(expand_stack(vma, address))) {
25525 bad_area(regs, error_code, address);
25526 return;
25527 @@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25528 __do_page_fault(regs, error_code);
25529 exception_exit(regs);
25530 }
25531 +
25532 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25533 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25534 +{
25535 + struct mm_struct *mm = current->mm;
25536 + unsigned long ip = regs->ip;
25537 +
25538 + if (v8086_mode(regs))
25539 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25540 +
25541 +#ifdef CONFIG_PAX_PAGEEXEC
25542 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25543 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25544 + return true;
25545 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25546 + return true;
25547 + return false;
25548 + }
25549 +#endif
25550 +
25551 +#ifdef CONFIG_PAX_SEGMEXEC
25552 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25553 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25554 + return true;
25555 + return false;
25556 + }
25557 +#endif
25558 +
25559 + return false;
25560 +}
25561 +#endif
25562 +
25563 +#ifdef CONFIG_PAX_EMUTRAMP
25564 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25565 +{
25566 + int err;
25567 +
25568 + do { /* PaX: libffi trampoline emulation */
25569 + unsigned char mov, jmp;
25570 + unsigned int addr1, addr2;
25571 +
25572 +#ifdef CONFIG_X86_64
25573 + if ((regs->ip + 9) >> 32)
25574 + break;
25575 +#endif
25576 +
25577 + err = get_user(mov, (unsigned char __user *)regs->ip);
25578 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25579 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25580 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25581 +
25582 + if (err)
25583 + break;
25584 +
25585 + if (mov == 0xB8 && jmp == 0xE9) {
25586 + regs->ax = addr1;
25587 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25588 + return 2;
25589 + }
25590 + } while (0);
25591 +
25592 + do { /* PaX: gcc trampoline emulation #1 */
25593 + unsigned char mov1, mov2;
25594 + unsigned short jmp;
25595 + unsigned int addr1, addr2;
25596 +
25597 +#ifdef CONFIG_X86_64
25598 + if ((regs->ip + 11) >> 32)
25599 + break;
25600 +#endif
25601 +
25602 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25603 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25604 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25605 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25606 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25607 +
25608 + if (err)
25609 + break;
25610 +
25611 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25612 + regs->cx = addr1;
25613 + regs->ax = addr2;
25614 + regs->ip = addr2;
25615 + return 2;
25616 + }
25617 + } while (0);
25618 +
25619 + do { /* PaX: gcc trampoline emulation #2 */
25620 + unsigned char mov, jmp;
25621 + unsigned int addr1, addr2;
25622 +
25623 +#ifdef CONFIG_X86_64
25624 + if ((regs->ip + 9) >> 32)
25625 + break;
25626 +#endif
25627 +
25628 + err = get_user(mov, (unsigned char __user *)regs->ip);
25629 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25630 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25631 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25632 +
25633 + if (err)
25634 + break;
25635 +
25636 + if (mov == 0xB9 && jmp == 0xE9) {
25637 + regs->cx = addr1;
25638 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25639 + return 2;
25640 + }
25641 + } while (0);
25642 +
25643 + return 1; /* PaX in action */
25644 +}
25645 +
25646 +#ifdef CONFIG_X86_64
25647 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25648 +{
25649 + int err;
25650 +
25651 + do { /* PaX: libffi trampoline emulation */
25652 + unsigned short mov1, mov2, jmp1;
25653 + unsigned char stcclc, jmp2;
25654 + unsigned long addr1, addr2;
25655 +
25656 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25657 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25658 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25659 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25660 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25661 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25662 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25663 +
25664 + if (err)
25665 + break;
25666 +
25667 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25668 + regs->r11 = addr1;
25669 + regs->r10 = addr2;
25670 + if (stcclc == 0xF8)
25671 + regs->flags &= ~X86_EFLAGS_CF;
25672 + else
25673 + regs->flags |= X86_EFLAGS_CF;
25674 + regs->ip = addr1;
25675 + return 2;
25676 + }
25677 + } while (0);
25678 +
25679 + do { /* PaX: gcc trampoline emulation #1 */
25680 + unsigned short mov1, mov2, jmp1;
25681 + unsigned char jmp2;
25682 + unsigned int addr1;
25683 + unsigned long addr2;
25684 +
25685 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25686 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25687 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25688 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25689 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25690 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25691 +
25692 + if (err)
25693 + break;
25694 +
25695 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25696 + regs->r11 = addr1;
25697 + regs->r10 = addr2;
25698 + regs->ip = addr1;
25699 + return 2;
25700 + }
25701 + } while (0);
25702 +
25703 + do { /* PaX: gcc trampoline emulation #2 */
25704 + unsigned short mov1, mov2, jmp1;
25705 + unsigned char jmp2;
25706 + unsigned long addr1, addr2;
25707 +
25708 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25709 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25710 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25711 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25712 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25713 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25714 +
25715 + if (err)
25716 + break;
25717 +
25718 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25719 + regs->r11 = addr1;
25720 + regs->r10 = addr2;
25721 + regs->ip = addr1;
25722 + return 2;
25723 + }
25724 + } while (0);
25725 +
25726 + return 1; /* PaX in action */
25727 +}
25728 +#endif
25729 +
25730 +/*
25731 + * PaX: decide what to do with offenders (regs->ip = fault address)
25732 + *
25733 + * returns 1 when task should be killed
25734 + * 2 when gcc trampoline was detected
25735 + */
25736 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25737 +{
25738 + if (v8086_mode(regs))
25739 + return 1;
25740 +
25741 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25742 + return 1;
25743 +
25744 +#ifdef CONFIG_X86_32
25745 + return pax_handle_fetch_fault_32(regs);
25746 +#else
25747 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25748 + return pax_handle_fetch_fault_32(regs);
25749 + else
25750 + return pax_handle_fetch_fault_64(regs);
25751 +#endif
25752 +}
25753 +#endif
25754 +
25755 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25756 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25757 +{
25758 + long i;
25759 +
25760 + printk(KERN_ERR "PAX: bytes at PC: ");
25761 + for (i = 0; i < 20; i++) {
25762 + unsigned char c;
25763 + if (get_user(c, (unsigned char __force_user *)pc+i))
25764 + printk(KERN_CONT "?? ");
25765 + else
25766 + printk(KERN_CONT "%02x ", c);
25767 + }
25768 + printk("\n");
25769 +
25770 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25771 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25772 + unsigned long c;
25773 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25774 +#ifdef CONFIG_X86_32
25775 + printk(KERN_CONT "???????? ");
25776 +#else
25777 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25778 + printk(KERN_CONT "???????? ???????? ");
25779 + else
25780 + printk(KERN_CONT "???????????????? ");
25781 +#endif
25782 + } else {
25783 +#ifdef CONFIG_X86_64
25784 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25785 + printk(KERN_CONT "%08x ", (unsigned int)c);
25786 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25787 + } else
25788 +#endif
25789 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25790 + }
25791 + }
25792 + printk("\n");
25793 +}
25794 +#endif
25795 +
25796 +/**
25797 + * probe_kernel_write(): safely attempt to write to a location
25798 + * @dst: address to write to
25799 + * @src: pointer to the data that shall be written
25800 + * @size: size of the data chunk
25801 + *
25802 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25803 + * happens, handle that and return -EFAULT.
25804 + */
25805 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25806 +{
25807 + long ret;
25808 + mm_segment_t old_fs = get_fs();
25809 +
25810 + set_fs(KERNEL_DS);
25811 + pagefault_disable();
25812 + pax_open_kernel();
25813 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25814 + pax_close_kernel();
25815 + pagefault_enable();
25816 + set_fs(old_fs);
25817 +
25818 + return ret ? -EFAULT : 0;
25819 +}
25820 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25821 index dd74e46..7d26398 100644
25822 --- a/arch/x86/mm/gup.c
25823 +++ b/arch/x86/mm/gup.c
25824 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25825 addr = start;
25826 len = (unsigned long) nr_pages << PAGE_SHIFT;
25827 end = start + len;
25828 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25829 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25830 (void __user *)start, len)))
25831 return 0;
25832
25833 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25834 index 6f31ee5..8ee4164 100644
25835 --- a/arch/x86/mm/highmem_32.c
25836 +++ b/arch/x86/mm/highmem_32.c
25837 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25838 idx = type + KM_TYPE_NR*smp_processor_id();
25839 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25840 BUG_ON(!pte_none(*(kmap_pte-idx)));
25841 +
25842 + pax_open_kernel();
25843 set_pte(kmap_pte-idx, mk_pte(page, prot));
25844 + pax_close_kernel();
25845 +
25846 arch_flush_lazy_mmu_mode();
25847
25848 return (void *)vaddr;
25849 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25850 index 937bff5..a354c44 100644
25851 --- a/arch/x86/mm/hugetlbpage.c
25852 +++ b/arch/x86/mm/hugetlbpage.c
25853 @@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25854 struct hstate *h = hstate_file(file);
25855 struct mm_struct *mm = current->mm;
25856 struct vm_area_struct *vma;
25857 - unsigned long start_addr;
25858 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25859 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25860 +
25861 +#ifdef CONFIG_PAX_SEGMEXEC
25862 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25863 + pax_task_size = SEGMEXEC_TASK_SIZE;
25864 +#endif
25865 +
25866 + pax_task_size -= PAGE_SIZE;
25867
25868 if (len > mm->cached_hole_size) {
25869 - start_addr = mm->free_area_cache;
25870 + start_addr = mm->free_area_cache;
25871 } else {
25872 - start_addr = TASK_UNMAPPED_BASE;
25873 - mm->cached_hole_size = 0;
25874 + start_addr = mm->mmap_base;
25875 + mm->cached_hole_size = 0;
25876 }
25877
25878 full_search:
25879 @@ -290,26 +298,27 @@ full_search:
25880
25881 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25882 /* At this point: (!vma || addr < vma->vm_end). */
25883 - if (TASK_SIZE - len < addr) {
25884 + if (pax_task_size - len < addr) {
25885 /*
25886 * Start a new search - just in case we missed
25887 * some holes.
25888 */
25889 - if (start_addr != TASK_UNMAPPED_BASE) {
25890 - start_addr = TASK_UNMAPPED_BASE;
25891 + if (start_addr != mm->mmap_base) {
25892 + start_addr = mm->mmap_base;
25893 mm->cached_hole_size = 0;
25894 goto full_search;
25895 }
25896 return -ENOMEM;
25897 }
25898 - if (!vma || addr + len <= vma->vm_start) {
25899 - mm->free_area_cache = addr + len;
25900 - return addr;
25901 - }
25902 + if (check_heap_stack_gap(vma, addr, len, offset))
25903 + break;
25904 if (addr + mm->cached_hole_size < vma->vm_start)
25905 mm->cached_hole_size = vma->vm_start - addr;
25906 addr = ALIGN(vma->vm_end, huge_page_size(h));
25907 }
25908 +
25909 + mm->free_area_cache = addr + len;
25910 + return addr;
25911 }
25912
25913 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25914 @@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25915 struct mm_struct *mm = current->mm;
25916 struct vm_area_struct *vma;
25917 unsigned long base = mm->mmap_base;
25918 - unsigned long addr = addr0;
25919 + unsigned long addr;
25920 unsigned long largest_hole = mm->cached_hole_size;
25921 - unsigned long start_addr;
25922 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25923
25924 /* don't allow allocations above current base */
25925 if (mm->free_area_cache > base)
25926 @@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25927 largest_hole = 0;
25928 mm->free_area_cache = base;
25929 }
25930 -try_again:
25931 - start_addr = mm->free_area_cache;
25932
25933 /* make sure it can fit in the remaining address space */
25934 if (mm->free_area_cache < len)
25935 goto fail;
25936
25937 /* either no address requested or can't fit in requested address hole */
25938 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
25939 + addr = mm->free_area_cache - len;
25940 do {
25941 + addr &= huge_page_mask(h);
25942 /*
25943 * Lookup failure means no vma is above this address,
25944 * i.e. return with success:
25945 @@ -350,10 +358,10 @@ try_again:
25946 if (!vma)
25947 return addr;
25948
25949 - if (addr + len <= vma->vm_start) {
25950 + if (check_heap_stack_gap(vma, addr, len, offset)) {
25951 /* remember the address as a hint for next time */
25952 - mm->cached_hole_size = largest_hole;
25953 - return (mm->free_area_cache = addr);
25954 + mm->cached_hole_size = largest_hole;
25955 + return (mm->free_area_cache = addr);
25956 } else if (mm->free_area_cache == vma->vm_end) {
25957 /* pull free_area_cache down to the first hole */
25958 mm->free_area_cache = vma->vm_start;
25959 @@ -362,29 +370,34 @@ try_again:
25960
25961 /* remember the largest hole we saw so far */
25962 if (addr + largest_hole < vma->vm_start)
25963 - largest_hole = vma->vm_start - addr;
25964 + largest_hole = vma->vm_start - addr;
25965
25966 /* try just below the current vma->vm_start */
25967 - addr = (vma->vm_start - len) & huge_page_mask(h);
25968 - } while (len <= vma->vm_start);
25969 + addr = skip_heap_stack_gap(vma, len, offset);
25970 + } while (!IS_ERR_VALUE(addr));
25971
25972 fail:
25973 /*
25974 - * if hint left us with no space for the requested
25975 - * mapping then try again:
25976 - */
25977 - if (start_addr != base) {
25978 - mm->free_area_cache = base;
25979 - largest_hole = 0;
25980 - goto try_again;
25981 - }
25982 - /*
25983 * A failed mmap() very likely causes application failure,
25984 * so fall back to the bottom-up function here. This scenario
25985 * can happen with large stack limits and large mmap()
25986 * allocations.
25987 */
25988 - mm->free_area_cache = TASK_UNMAPPED_BASE;
25989 +
25990 +#ifdef CONFIG_PAX_SEGMEXEC
25991 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25992 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
25993 + else
25994 +#endif
25995 +
25996 + mm->mmap_base = TASK_UNMAPPED_BASE;
25997 +
25998 +#ifdef CONFIG_PAX_RANDMMAP
25999 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26000 + mm->mmap_base += mm->delta_mmap;
26001 +#endif
26002 +
26003 + mm->free_area_cache = mm->mmap_base;
26004 mm->cached_hole_size = ~0UL;
26005 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26006 len, pgoff, flags);
26007 @@ -392,6 +405,7 @@ fail:
26008 /*
26009 * Restore the topdown base:
26010 */
26011 + mm->mmap_base = base;
26012 mm->free_area_cache = base;
26013 mm->cached_hole_size = ~0UL;
26014
26015 @@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26016 struct hstate *h = hstate_file(file);
26017 struct mm_struct *mm = current->mm;
26018 struct vm_area_struct *vma;
26019 + unsigned long pax_task_size = TASK_SIZE;
26020 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26021
26022 if (len & ~huge_page_mask(h))
26023 return -EINVAL;
26024 - if (len > TASK_SIZE)
26025 +
26026 +#ifdef CONFIG_PAX_SEGMEXEC
26027 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26028 + pax_task_size = SEGMEXEC_TASK_SIZE;
26029 +#endif
26030 +
26031 + pax_task_size -= PAGE_SIZE;
26032 +
26033 + if (len > pax_task_size)
26034 return -ENOMEM;
26035
26036 if (flags & MAP_FIXED) {
26037 @@ -420,8 +444,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26038 if (addr) {
26039 addr = ALIGN(addr, huge_page_size(h));
26040 vma = find_vma(mm, addr);
26041 - if (TASK_SIZE - len >= addr &&
26042 - (!vma || addr + len <= vma->vm_start))
26043 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26044 return addr;
26045 }
26046 if (mm->get_unmapped_area == arch_get_unmapped_area)
26047 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26048 index d7aea41..0fc945b 100644
26049 --- a/arch/x86/mm/init.c
26050 +++ b/arch/x86/mm/init.c
26051 @@ -4,6 +4,7 @@
26052 #include <linux/swap.h>
26053 #include <linux/memblock.h>
26054 #include <linux/bootmem.h> /* for max_low_pfn */
26055 +#include <linux/tboot.h>
26056
26057 #include <asm/cacheflush.h>
26058 #include <asm/e820.h>
26059 @@ -16,6 +17,8 @@
26060 #include <asm/tlb.h>
26061 #include <asm/proto.h>
26062 #include <asm/dma.h> /* for MAX_DMA_PFN */
26063 +#include <asm/desc.h>
26064 +#include <asm/bios_ebda.h>
26065
26066 unsigned long __initdata pgt_buf_start;
26067 unsigned long __meminitdata pgt_buf_end;
26068 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26069 {
26070 int i;
26071 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26072 - unsigned long start = 0, good_end;
26073 + unsigned long start = 0x100000, good_end;
26074 phys_addr_t base;
26075
26076 for (i = 0; i < nr_range; i++) {
26077 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26078 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26079 * mmio resources as well as potential bios/acpi data regions.
26080 */
26081 +
26082 +#ifdef CONFIG_GRKERNSEC_KMEM
26083 +static unsigned int ebda_start __read_only;
26084 +static unsigned int ebda_end __read_only;
26085 +#endif
26086 +
26087 int devmem_is_allowed(unsigned long pagenr)
26088 {
26089 - if (pagenr < 256)
26090 +#ifdef CONFIG_GRKERNSEC_KMEM
26091 + /* allow BDA */
26092 + if (!pagenr)
26093 return 1;
26094 + /* allow EBDA */
26095 + if (pagenr >= ebda_start && pagenr < ebda_end)
26096 + return 1;
26097 + /* if tboot is in use, allow access to its hardcoded serial log range */
26098 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26099 + return 1;
26100 +#else
26101 + if (!pagenr)
26102 + return 1;
26103 +#ifdef CONFIG_VM86
26104 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26105 + return 1;
26106 +#endif
26107 +#endif
26108 +
26109 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26110 + return 1;
26111 +#ifdef CONFIG_GRKERNSEC_KMEM
26112 + /* throw out everything else below 1MB */
26113 + if (pagenr <= 256)
26114 + return 0;
26115 +#endif
26116 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26117 return 0;
26118 if (!page_is_ram(pagenr))
26119 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26120 #endif
26121 }
26122
26123 +#ifdef CONFIG_GRKERNSEC_KMEM
26124 +static inline void gr_init_ebda(void)
26125 +{
26126 + unsigned int ebda_addr;
26127 + unsigned int ebda_size = 0;
26128 +
26129 + ebda_addr = get_bios_ebda();
26130 + if (ebda_addr) {
26131 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26132 + ebda_size <<= 10;
26133 + }
26134 + if (ebda_addr && ebda_size) {
26135 + ebda_start = ebda_addr >> PAGE_SHIFT;
26136 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26137 + } else {
26138 + ebda_start = 0x9f000 >> PAGE_SHIFT;
26139 + ebda_end = 0xa0000 >> PAGE_SHIFT;
26140 + }
26141 +}
26142 +#else
26143 +static inline void gr_init_ebda(void) { }
26144 +#endif
26145 +
26146 void free_initmem(void)
26147 {
26148 +#ifdef CONFIG_PAX_KERNEXEC
26149 +#ifdef CONFIG_X86_32
26150 + /* PaX: limit KERNEL_CS to actual size */
26151 + unsigned long addr, limit;
26152 + struct desc_struct d;
26153 + int cpu;
26154 +#else
26155 + pgd_t *pgd;
26156 + pud_t *pud;
26157 + pmd_t *pmd;
26158 + unsigned long addr, end;
26159 +#endif
26160 +#endif
26161 +
26162 + gr_init_ebda();
26163 +
26164 +#ifdef CONFIG_PAX_KERNEXEC
26165 +#ifdef CONFIG_X86_32
26166 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26167 + limit = (limit - 1UL) >> PAGE_SHIFT;
26168 +
26169 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26170 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26171 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26172 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26173 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26174 + }
26175 +
26176 + /* PaX: make KERNEL_CS read-only */
26177 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26178 + if (!paravirt_enabled())
26179 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26180 +/*
26181 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26182 + pgd = pgd_offset_k(addr);
26183 + pud = pud_offset(pgd, addr);
26184 + pmd = pmd_offset(pud, addr);
26185 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26186 + }
26187 +*/
26188 +#ifdef CONFIG_X86_PAE
26189 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26190 +/*
26191 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26192 + pgd = pgd_offset_k(addr);
26193 + pud = pud_offset(pgd, addr);
26194 + pmd = pmd_offset(pud, addr);
26195 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26196 + }
26197 +*/
26198 +#endif
26199 +
26200 +#ifdef CONFIG_MODULES
26201 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26202 +#endif
26203 +
26204 +#else
26205 + /* PaX: make kernel code/rodata read-only, rest non-executable */
26206 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26207 + pgd = pgd_offset_k(addr);
26208 + pud = pud_offset(pgd, addr);
26209 + pmd = pmd_offset(pud, addr);
26210 + if (!pmd_present(*pmd))
26211 + continue;
26212 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26213 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26214 + else
26215 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26216 + }
26217 +
26218 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26219 + end = addr + KERNEL_IMAGE_SIZE;
26220 + for (; addr < end; addr += PMD_SIZE) {
26221 + pgd = pgd_offset_k(addr);
26222 + pud = pud_offset(pgd, addr);
26223 + pmd = pmd_offset(pud, addr);
26224 + if (!pmd_present(*pmd))
26225 + continue;
26226 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26227 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26228 + }
26229 +#endif
26230 +
26231 + flush_tlb_all();
26232 +#endif
26233 +
26234 free_init_pages("unused kernel memory",
26235 (unsigned long)(&__init_begin),
26236 (unsigned long)(&__init_end));
26237 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26238 index 11a5800..4bd9977 100644
26239 --- a/arch/x86/mm/init_32.c
26240 +++ b/arch/x86/mm/init_32.c
26241 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26242 }
26243
26244 /*
26245 - * Creates a middle page table and puts a pointer to it in the
26246 - * given global directory entry. This only returns the gd entry
26247 - * in non-PAE compilation mode, since the middle layer is folded.
26248 - */
26249 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
26250 -{
26251 - pud_t *pud;
26252 - pmd_t *pmd_table;
26253 -
26254 -#ifdef CONFIG_X86_PAE
26255 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26256 - if (after_bootmem)
26257 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26258 - else
26259 - pmd_table = (pmd_t *)alloc_low_page();
26260 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26261 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26262 - pud = pud_offset(pgd, 0);
26263 - BUG_ON(pmd_table != pmd_offset(pud, 0));
26264 -
26265 - return pmd_table;
26266 - }
26267 -#endif
26268 - pud = pud_offset(pgd, 0);
26269 - pmd_table = pmd_offset(pud, 0);
26270 -
26271 - return pmd_table;
26272 -}
26273 -
26274 -/*
26275 * Create a page table and place a pointer to it in a middle page
26276 * directory entry:
26277 */
26278 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26279 page_table = (pte_t *)alloc_low_page();
26280
26281 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26282 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26283 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26284 +#else
26285 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26286 +#endif
26287 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26288 }
26289
26290 return pte_offset_kernel(pmd, 0);
26291 }
26292
26293 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26294 +{
26295 + pud_t *pud;
26296 + pmd_t *pmd_table;
26297 +
26298 + pud = pud_offset(pgd, 0);
26299 + pmd_table = pmd_offset(pud, 0);
26300 +
26301 + return pmd_table;
26302 +}
26303 +
26304 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26305 {
26306 int pgd_idx = pgd_index(vaddr);
26307 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26308 int pgd_idx, pmd_idx;
26309 unsigned long vaddr;
26310 pgd_t *pgd;
26311 + pud_t *pud;
26312 pmd_t *pmd;
26313 pte_t *pte = NULL;
26314
26315 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26316 pgd = pgd_base + pgd_idx;
26317
26318 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26319 - pmd = one_md_table_init(pgd);
26320 - pmd = pmd + pmd_index(vaddr);
26321 + pud = pud_offset(pgd, vaddr);
26322 + pmd = pmd_offset(pud, vaddr);
26323 +
26324 +#ifdef CONFIG_X86_PAE
26325 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26326 +#endif
26327 +
26328 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26329 pmd++, pmd_idx++) {
26330 pte = page_table_kmap_check(one_page_table_init(pmd),
26331 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26332 }
26333 }
26334
26335 -static inline int is_kernel_text(unsigned long addr)
26336 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26337 {
26338 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26339 - return 1;
26340 - return 0;
26341 + if ((start > ktla_ktva((unsigned long)_etext) ||
26342 + end <= ktla_ktva((unsigned long)_stext)) &&
26343 + (start > ktla_ktva((unsigned long)_einittext) ||
26344 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26345 +
26346 +#ifdef CONFIG_ACPI_SLEEP
26347 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26348 +#endif
26349 +
26350 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26351 + return 0;
26352 + return 1;
26353 }
26354
26355 /*
26356 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26357 unsigned long last_map_addr = end;
26358 unsigned long start_pfn, end_pfn;
26359 pgd_t *pgd_base = swapper_pg_dir;
26360 - int pgd_idx, pmd_idx, pte_ofs;
26361 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26362 unsigned long pfn;
26363 pgd_t *pgd;
26364 + pud_t *pud;
26365 pmd_t *pmd;
26366 pte_t *pte;
26367 unsigned pages_2m, pages_4k;
26368 @@ -280,8 +281,13 @@ repeat:
26369 pfn = start_pfn;
26370 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26371 pgd = pgd_base + pgd_idx;
26372 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26373 - pmd = one_md_table_init(pgd);
26374 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26375 + pud = pud_offset(pgd, 0);
26376 + pmd = pmd_offset(pud, 0);
26377 +
26378 +#ifdef CONFIG_X86_PAE
26379 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26380 +#endif
26381
26382 if (pfn >= end_pfn)
26383 continue;
26384 @@ -293,14 +299,13 @@ repeat:
26385 #endif
26386 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26387 pmd++, pmd_idx++) {
26388 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26389 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26390
26391 /*
26392 * Map with big pages if possible, otherwise
26393 * create normal page tables:
26394 */
26395 if (use_pse) {
26396 - unsigned int addr2;
26397 pgprot_t prot = PAGE_KERNEL_LARGE;
26398 /*
26399 * first pass will use the same initial
26400 @@ -310,11 +315,7 @@ repeat:
26401 __pgprot(PTE_IDENT_ATTR |
26402 _PAGE_PSE);
26403
26404 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26405 - PAGE_OFFSET + PAGE_SIZE-1;
26406 -
26407 - if (is_kernel_text(addr) ||
26408 - is_kernel_text(addr2))
26409 + if (is_kernel_text(address, address + PMD_SIZE))
26410 prot = PAGE_KERNEL_LARGE_EXEC;
26411
26412 pages_2m++;
26413 @@ -331,7 +332,7 @@ repeat:
26414 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26415 pte += pte_ofs;
26416 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26417 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26418 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26419 pgprot_t prot = PAGE_KERNEL;
26420 /*
26421 * first pass will use the same initial
26422 @@ -339,7 +340,7 @@ repeat:
26423 */
26424 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26425
26426 - if (is_kernel_text(addr))
26427 + if (is_kernel_text(address, address + PAGE_SIZE))
26428 prot = PAGE_KERNEL_EXEC;
26429
26430 pages_4k++;
26431 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26432
26433 pud = pud_offset(pgd, va);
26434 pmd = pmd_offset(pud, va);
26435 - if (!pmd_present(*pmd))
26436 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26437 break;
26438
26439 pte = pte_offset_kernel(pmd, va);
26440 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26441
26442 static void __init pagetable_init(void)
26443 {
26444 - pgd_t *pgd_base = swapper_pg_dir;
26445 -
26446 - permanent_kmaps_init(pgd_base);
26447 + permanent_kmaps_init(swapper_pg_dir);
26448 }
26449
26450 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26451 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26452 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26453
26454 /* user-defined highmem size */
26455 @@ -731,6 +730,12 @@ void __init mem_init(void)
26456
26457 pci_iommu_alloc();
26458
26459 +#ifdef CONFIG_PAX_PER_CPU_PGD
26460 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26461 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26462 + KERNEL_PGD_PTRS);
26463 +#endif
26464 +
26465 #ifdef CONFIG_FLATMEM
26466 BUG_ON(!mem_map);
26467 #endif
26468 @@ -757,7 +762,7 @@ void __init mem_init(void)
26469 reservedpages++;
26470
26471 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26472 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26473 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26474 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26475
26476 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26477 @@ -798,10 +803,10 @@ void __init mem_init(void)
26478 ((unsigned long)&__init_end -
26479 (unsigned long)&__init_begin) >> 10,
26480
26481 - (unsigned long)&_etext, (unsigned long)&_edata,
26482 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26483 + (unsigned long)&_sdata, (unsigned long)&_edata,
26484 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26485
26486 - (unsigned long)&_text, (unsigned long)&_etext,
26487 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26488 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26489
26490 /*
26491 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26492 if (!kernel_set_to_readonly)
26493 return;
26494
26495 + start = ktla_ktva(start);
26496 pr_debug("Set kernel text: %lx - %lx for read write\n",
26497 start, start+size);
26498
26499 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26500 if (!kernel_set_to_readonly)
26501 return;
26502
26503 + start = ktla_ktva(start);
26504 pr_debug("Set kernel text: %lx - %lx for read only\n",
26505 start, start+size);
26506
26507 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26508 unsigned long start = PFN_ALIGN(_text);
26509 unsigned long size = PFN_ALIGN(_etext) - start;
26510
26511 + start = ktla_ktva(start);
26512 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26513 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26514 size >> 10);
26515 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26516 index 3baff25..8b37564 100644
26517 --- a/arch/x86/mm/init_64.c
26518 +++ b/arch/x86/mm/init_64.c
26519 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26520 * around without checking the pgd every time.
26521 */
26522
26523 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26524 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26525 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26526
26527 int force_personality32;
26528 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26529
26530 for (address = start; address <= end; address += PGDIR_SIZE) {
26531 const pgd_t *pgd_ref = pgd_offset_k(address);
26532 +
26533 +#ifdef CONFIG_PAX_PER_CPU_PGD
26534 + unsigned long cpu;
26535 +#else
26536 struct page *page;
26537 +#endif
26538
26539 if (pgd_none(*pgd_ref))
26540 continue;
26541
26542 spin_lock(&pgd_lock);
26543 +
26544 +#ifdef CONFIG_PAX_PER_CPU_PGD
26545 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26546 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26547 +#else
26548 list_for_each_entry(page, &pgd_list, lru) {
26549 pgd_t *pgd;
26550 spinlock_t *pgt_lock;
26551 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26552 /* the pgt_lock only for Xen */
26553 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26554 spin_lock(pgt_lock);
26555 +#endif
26556
26557 if (pgd_none(*pgd))
26558 set_pgd(pgd, *pgd_ref);
26559 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26560 BUG_ON(pgd_page_vaddr(*pgd)
26561 != pgd_page_vaddr(*pgd_ref));
26562
26563 +#ifndef CONFIG_PAX_PER_CPU_PGD
26564 spin_unlock(pgt_lock);
26565 +#endif
26566 +
26567 }
26568 spin_unlock(&pgd_lock);
26569 }
26570 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26571 {
26572 if (pgd_none(*pgd)) {
26573 pud_t *pud = (pud_t *)spp_getpage();
26574 - pgd_populate(&init_mm, pgd, pud);
26575 + pgd_populate_kernel(&init_mm, pgd, pud);
26576 if (pud != pud_offset(pgd, 0))
26577 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26578 pud, pud_offset(pgd, 0));
26579 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26580 {
26581 if (pud_none(*pud)) {
26582 pmd_t *pmd = (pmd_t *) spp_getpage();
26583 - pud_populate(&init_mm, pud, pmd);
26584 + pud_populate_kernel(&init_mm, pud, pmd);
26585 if (pmd != pmd_offset(pud, 0))
26586 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26587 pmd, pmd_offset(pud, 0));
26588 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26589 pmd = fill_pmd(pud, vaddr);
26590 pte = fill_pte(pmd, vaddr);
26591
26592 + pax_open_kernel();
26593 set_pte(pte, new_pte);
26594 + pax_close_kernel();
26595
26596 /*
26597 * It's enough to flush this one mapping.
26598 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26599 pgd = pgd_offset_k((unsigned long)__va(phys));
26600 if (pgd_none(*pgd)) {
26601 pud = (pud_t *) spp_getpage();
26602 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26603 - _PAGE_USER));
26604 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26605 }
26606 pud = pud_offset(pgd, (unsigned long)__va(phys));
26607 if (pud_none(*pud)) {
26608 pmd = (pmd_t *) spp_getpage();
26609 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26610 - _PAGE_USER));
26611 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26612 }
26613 pmd = pmd_offset(pud, phys);
26614 BUG_ON(!pmd_none(*pmd));
26615 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26616 if (pfn >= pgt_buf_top)
26617 panic("alloc_low_page: ran out of memory");
26618
26619 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26620 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26621 clear_page(adr);
26622 *phys = pfn * PAGE_SIZE;
26623 return adr;
26624 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26625
26626 phys = __pa(virt);
26627 left = phys & (PAGE_SIZE - 1);
26628 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26629 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26630 adr = (void *)(((unsigned long)adr) | left);
26631
26632 return adr;
26633 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26634 unmap_low_page(pmd);
26635
26636 spin_lock(&init_mm.page_table_lock);
26637 - pud_populate(&init_mm, pud, __va(pmd_phys));
26638 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26639 spin_unlock(&init_mm.page_table_lock);
26640 }
26641 __flush_tlb_all();
26642 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26643 unmap_low_page(pud);
26644
26645 spin_lock(&init_mm.page_table_lock);
26646 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26647 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26648 spin_unlock(&init_mm.page_table_lock);
26649 pgd_changed = true;
26650 }
26651 @@ -691,6 +705,12 @@ void __init mem_init(void)
26652
26653 pci_iommu_alloc();
26654
26655 +#ifdef CONFIG_PAX_PER_CPU_PGD
26656 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26657 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26658 + KERNEL_PGD_PTRS);
26659 +#endif
26660 +
26661 /* clear_bss() already clear the empty_zero_page */
26662
26663 reservedpages = 0;
26664 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26665 static struct vm_area_struct gate_vma = {
26666 .vm_start = VSYSCALL_START,
26667 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26668 - .vm_page_prot = PAGE_READONLY_EXEC,
26669 - .vm_flags = VM_READ | VM_EXEC
26670 + .vm_page_prot = PAGE_READONLY,
26671 + .vm_flags = VM_READ
26672 };
26673
26674 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26675 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26676
26677 const char *arch_vma_name(struct vm_area_struct *vma)
26678 {
26679 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26680 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26681 return "[vdso]";
26682 if (vma == &gate_vma)
26683 return "[vsyscall]";
26684 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26685 index 7b179b4..6bd1777 100644
26686 --- a/arch/x86/mm/iomap_32.c
26687 +++ b/arch/x86/mm/iomap_32.c
26688 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26689 type = kmap_atomic_idx_push();
26690 idx = type + KM_TYPE_NR * smp_processor_id();
26691 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26692 +
26693 + pax_open_kernel();
26694 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26695 + pax_close_kernel();
26696 +
26697 arch_flush_lazy_mmu_mode();
26698
26699 return (void *)vaddr;
26700 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26701 index 78fe3f1..2f9433c 100644
26702 --- a/arch/x86/mm/ioremap.c
26703 +++ b/arch/x86/mm/ioremap.c
26704 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26705 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26706 int is_ram = page_is_ram(pfn);
26707
26708 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26709 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26710 return NULL;
26711 WARN_ON_ONCE(is_ram);
26712 }
26713 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26714 *
26715 * Caller must ensure there is only one unmapping for the same pointer.
26716 */
26717 -void iounmap(volatile void __iomem *addr)
26718 +void iounmap(const volatile void __iomem *addr)
26719 {
26720 struct vm_struct *p, *o;
26721
26722 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26723
26724 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26725 if (page_is_ram(start >> PAGE_SHIFT))
26726 +#ifdef CONFIG_HIGHMEM
26727 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26728 +#endif
26729 return __va(phys);
26730
26731 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26732 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26733 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26734
26735 static __initdata int after_paging_init;
26736 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26737 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26738
26739 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26740 {
26741 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26742 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26743
26744 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26745 - memset(bm_pte, 0, sizeof(bm_pte));
26746 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26747 + pmd_populate_user(&init_mm, pmd, bm_pte);
26748
26749 /*
26750 * The boot-ioremap range spans multiple pmds, for which
26751 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26752 index d87dd6d..bf3fa66 100644
26753 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26754 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26755 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26756 * memory (e.g. tracked pages)? For now, we need this to avoid
26757 * invoking kmemcheck for PnP BIOS calls.
26758 */
26759 - if (regs->flags & X86_VM_MASK)
26760 + if (v8086_mode(regs))
26761 return false;
26762 - if (regs->cs != __KERNEL_CS)
26763 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26764 return false;
26765
26766 pte = kmemcheck_pte_lookup(address);
26767 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26768 index 845df68..1d8d29f 100644
26769 --- a/arch/x86/mm/mmap.c
26770 +++ b/arch/x86/mm/mmap.c
26771 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26772 * Leave an at least ~128 MB hole with possible stack randomization.
26773 */
26774 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26775 -#define MAX_GAP (TASK_SIZE/6*5)
26776 +#define MAX_GAP (pax_task_size/6*5)
26777
26778 static int mmap_is_legacy(void)
26779 {
26780 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26781 return rnd << PAGE_SHIFT;
26782 }
26783
26784 -static unsigned long mmap_base(void)
26785 +static unsigned long mmap_base(struct mm_struct *mm)
26786 {
26787 unsigned long gap = rlimit(RLIMIT_STACK);
26788 + unsigned long pax_task_size = TASK_SIZE;
26789 +
26790 +#ifdef CONFIG_PAX_SEGMEXEC
26791 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26792 + pax_task_size = SEGMEXEC_TASK_SIZE;
26793 +#endif
26794
26795 if (gap < MIN_GAP)
26796 gap = MIN_GAP;
26797 else if (gap > MAX_GAP)
26798 gap = MAX_GAP;
26799
26800 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26801 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26802 }
26803
26804 /*
26805 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26806 * does, but not when emulating X86_32
26807 */
26808 -static unsigned long mmap_legacy_base(void)
26809 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26810 {
26811 - if (mmap_is_ia32())
26812 + if (mmap_is_ia32()) {
26813 +
26814 +#ifdef CONFIG_PAX_SEGMEXEC
26815 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26816 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26817 + else
26818 +#endif
26819 +
26820 return TASK_UNMAPPED_BASE;
26821 - else
26822 + } else
26823 return TASK_UNMAPPED_BASE + mmap_rnd();
26824 }
26825
26826 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26827 void arch_pick_mmap_layout(struct mm_struct *mm)
26828 {
26829 if (mmap_is_legacy()) {
26830 - mm->mmap_base = mmap_legacy_base();
26831 + mm->mmap_base = mmap_legacy_base(mm);
26832 +
26833 +#ifdef CONFIG_PAX_RANDMMAP
26834 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26835 + mm->mmap_base += mm->delta_mmap;
26836 +#endif
26837 +
26838 mm->get_unmapped_area = arch_get_unmapped_area;
26839 mm->unmap_area = arch_unmap_area;
26840 } else {
26841 - mm->mmap_base = mmap_base();
26842 + mm->mmap_base = mmap_base(mm);
26843 +
26844 +#ifdef CONFIG_PAX_RANDMMAP
26845 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26846 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26847 +#endif
26848 +
26849 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26850 mm->unmap_area = arch_unmap_area_topdown;
26851 }
26852 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26853 index dc0b727..f612039 100644
26854 --- a/arch/x86/mm/mmio-mod.c
26855 +++ b/arch/x86/mm/mmio-mod.c
26856 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26857 break;
26858 default:
26859 {
26860 - unsigned char *ip = (unsigned char *)instptr;
26861 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26862 my_trace->opcode = MMIO_UNKNOWN_OP;
26863 my_trace->width = 0;
26864 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26865 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26866 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26867 void __iomem *addr)
26868 {
26869 - static atomic_t next_id;
26870 + static atomic_unchecked_t next_id;
26871 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26872 /* These are page-unaligned. */
26873 struct mmiotrace_map map = {
26874 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26875 .private = trace
26876 },
26877 .phys = offset,
26878 - .id = atomic_inc_return(&next_id)
26879 + .id = atomic_inc_return_unchecked(&next_id)
26880 };
26881 map.map_id = trace->id;
26882
26883 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26884 ioremap_trace_core(offset, size, addr);
26885 }
26886
26887 -static void iounmap_trace_core(volatile void __iomem *addr)
26888 +static void iounmap_trace_core(const volatile void __iomem *addr)
26889 {
26890 struct mmiotrace_map map = {
26891 .phys = 0,
26892 @@ -328,7 +328,7 @@ not_enabled:
26893 }
26894 }
26895
26896 -void mmiotrace_iounmap(volatile void __iomem *addr)
26897 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26898 {
26899 might_sleep();
26900 if (is_enabled()) /* recheck and proper locking in *_core() */
26901 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26902 index b008656..773eac2 100644
26903 --- a/arch/x86/mm/pageattr-test.c
26904 +++ b/arch/x86/mm/pageattr-test.c
26905 @@ -36,7 +36,7 @@ enum {
26906
26907 static int pte_testbit(pte_t pte)
26908 {
26909 - return pte_flags(pte) & _PAGE_UNUSED1;
26910 + return pte_flags(pte) & _PAGE_CPA_TEST;
26911 }
26912
26913 struct split_state {
26914 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26915 index a718e0d..77419bc 100644
26916 --- a/arch/x86/mm/pageattr.c
26917 +++ b/arch/x86/mm/pageattr.c
26918 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26919 */
26920 #ifdef CONFIG_PCI_BIOS
26921 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26922 - pgprot_val(forbidden) |= _PAGE_NX;
26923 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26924 #endif
26925
26926 /*
26927 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26928 * Does not cover __inittext since that is gone later on. On
26929 * 64bit we do not enforce !NX on the low mapping
26930 */
26931 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
26932 - pgprot_val(forbidden) |= _PAGE_NX;
26933 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26934 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26935
26936 +#ifdef CONFIG_DEBUG_RODATA
26937 /*
26938 * The .rodata section needs to be read-only. Using the pfn
26939 * catches all aliases.
26940 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26941 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26942 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26943 pgprot_val(forbidden) |= _PAGE_RW;
26944 +#endif
26945
26946 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26947 /*
26948 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26949 }
26950 #endif
26951
26952 +#ifdef CONFIG_PAX_KERNEXEC
26953 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
26954 + pgprot_val(forbidden) |= _PAGE_RW;
26955 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26956 + }
26957 +#endif
26958 +
26959 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
26960
26961 return prot;
26962 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
26963 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
26964 {
26965 /* change init_mm */
26966 + pax_open_kernel();
26967 set_pte_atomic(kpte, pte);
26968 +
26969 #ifdef CONFIG_X86_32
26970 if (!SHARED_KERNEL_PMD) {
26971 +
26972 +#ifdef CONFIG_PAX_PER_CPU_PGD
26973 + unsigned long cpu;
26974 +#else
26975 struct page *page;
26976 +#endif
26977
26978 +#ifdef CONFIG_PAX_PER_CPU_PGD
26979 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26980 + pgd_t *pgd = get_cpu_pgd(cpu);
26981 +#else
26982 list_for_each_entry(page, &pgd_list, lru) {
26983 - pgd_t *pgd;
26984 + pgd_t *pgd = (pgd_t *)page_address(page);
26985 +#endif
26986 +
26987 pud_t *pud;
26988 pmd_t *pmd;
26989
26990 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
26991 + pgd += pgd_index(address);
26992 pud = pud_offset(pgd, address);
26993 pmd = pmd_offset(pud, address);
26994 set_pte_atomic((pte_t *)pmd, pte);
26995 }
26996 }
26997 #endif
26998 + pax_close_kernel();
26999 }
27000
27001 static int
27002 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27003 index 0eb572e..92f5c1e 100644
27004 --- a/arch/x86/mm/pat.c
27005 +++ b/arch/x86/mm/pat.c
27006 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27007
27008 if (!entry) {
27009 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27010 - current->comm, current->pid, start, end - 1);
27011 + current->comm, task_pid_nr(current), start, end - 1);
27012 return -EINVAL;
27013 }
27014
27015 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27016
27017 while (cursor < to) {
27018 if (!devmem_is_allowed(pfn)) {
27019 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27020 - current->comm, from, to - 1);
27021 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27022 + current->comm, from, to - 1, cursor);
27023 return 0;
27024 }
27025 cursor += PAGE_SIZE;
27026 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27027 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27028 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27029 "for [mem %#010Lx-%#010Lx]\n",
27030 - current->comm, current->pid,
27031 + current->comm, task_pid_nr(current),
27032 cattr_name(flags),
27033 base, (unsigned long long)(base + size-1));
27034 return -EINVAL;
27035 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27036 flags = lookup_memtype(paddr);
27037 if (want_flags != flags) {
27038 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27039 - current->comm, current->pid,
27040 + current->comm, task_pid_nr(current),
27041 cattr_name(want_flags),
27042 (unsigned long long)paddr,
27043 (unsigned long long)(paddr + size - 1),
27044 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27045 free_memtype(paddr, paddr + size);
27046 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27047 " for [mem %#010Lx-%#010Lx], got %s\n",
27048 - current->comm, current->pid,
27049 + current->comm, task_pid_nr(current),
27050 cattr_name(want_flags),
27051 (unsigned long long)paddr,
27052 (unsigned long long)(paddr + size - 1),
27053 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27054 index 9f0614d..92ae64a 100644
27055 --- a/arch/x86/mm/pf_in.c
27056 +++ b/arch/x86/mm/pf_in.c
27057 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27058 int i;
27059 enum reason_type rv = OTHERS;
27060
27061 - p = (unsigned char *)ins_addr;
27062 + p = (unsigned char *)ktla_ktva(ins_addr);
27063 p += skip_prefix(p, &prf);
27064 p += get_opcode(p, &opcode);
27065
27066 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27067 struct prefix_bits prf;
27068 int i;
27069
27070 - p = (unsigned char *)ins_addr;
27071 + p = (unsigned char *)ktla_ktva(ins_addr);
27072 p += skip_prefix(p, &prf);
27073 p += get_opcode(p, &opcode);
27074
27075 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27076 struct prefix_bits prf;
27077 int i;
27078
27079 - p = (unsigned char *)ins_addr;
27080 + p = (unsigned char *)ktla_ktva(ins_addr);
27081 p += skip_prefix(p, &prf);
27082 p += get_opcode(p, &opcode);
27083
27084 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27085 struct prefix_bits prf;
27086 int i;
27087
27088 - p = (unsigned char *)ins_addr;
27089 + p = (unsigned char *)ktla_ktva(ins_addr);
27090 p += skip_prefix(p, &prf);
27091 p += get_opcode(p, &opcode);
27092 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27093 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27094 struct prefix_bits prf;
27095 int i;
27096
27097 - p = (unsigned char *)ins_addr;
27098 + p = (unsigned char *)ktla_ktva(ins_addr);
27099 p += skip_prefix(p, &prf);
27100 p += get_opcode(p, &opcode);
27101 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27102 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27103 index 8573b83..4f3ed7e 100644
27104 --- a/arch/x86/mm/pgtable.c
27105 +++ b/arch/x86/mm/pgtable.c
27106 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27107 list_del(&page->lru);
27108 }
27109
27110 -#define UNSHARED_PTRS_PER_PGD \
27111 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27112 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27113 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27114
27115 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27116 +{
27117 + unsigned int count = USER_PGD_PTRS;
27118
27119 + while (count--)
27120 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27121 +}
27122 +#endif
27123 +
27124 +#ifdef CONFIG_PAX_PER_CPU_PGD
27125 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27126 +{
27127 + unsigned int count = USER_PGD_PTRS;
27128 +
27129 + while (count--) {
27130 + pgd_t pgd;
27131 +
27132 +#ifdef CONFIG_X86_64
27133 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27134 +#else
27135 + pgd = *src++;
27136 +#endif
27137 +
27138 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27139 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27140 +#endif
27141 +
27142 + *dst++ = pgd;
27143 + }
27144 +
27145 +}
27146 +#endif
27147 +
27148 +#ifdef CONFIG_X86_64
27149 +#define pxd_t pud_t
27150 +#define pyd_t pgd_t
27151 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27152 +#define pxd_free(mm, pud) pud_free((mm), (pud))
27153 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27154 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
27155 +#define PYD_SIZE PGDIR_SIZE
27156 +#else
27157 +#define pxd_t pmd_t
27158 +#define pyd_t pud_t
27159 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27160 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
27161 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27162 +#define pyd_offset(mm, address) pud_offset((mm), (address))
27163 +#define PYD_SIZE PUD_SIZE
27164 +#endif
27165 +
27166 +#ifdef CONFIG_PAX_PER_CPU_PGD
27167 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27168 +static inline void pgd_dtor(pgd_t *pgd) {}
27169 +#else
27170 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27171 {
27172 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27173 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27174 pgd_list_del(pgd);
27175 spin_unlock(&pgd_lock);
27176 }
27177 +#endif
27178
27179 /*
27180 * List of all pgd's needed for non-PAE so it can invalidate entries
27181 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27182 * -- wli
27183 */
27184
27185 -#ifdef CONFIG_X86_PAE
27186 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27187 /*
27188 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27189 * updating the top-level pagetable entries to guarantee the
27190 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27191 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27192 * and initialize the kernel pmds here.
27193 */
27194 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27195 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27196
27197 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27198 {
27199 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27200 */
27201 flush_tlb_mm(mm);
27202 }
27203 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27204 +#define PREALLOCATED_PXDS USER_PGD_PTRS
27205 #else /* !CONFIG_X86_PAE */
27206
27207 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27208 -#define PREALLOCATED_PMDS 0
27209 +#define PREALLOCATED_PXDS 0
27210
27211 #endif /* CONFIG_X86_PAE */
27212
27213 -static void free_pmds(pmd_t *pmds[])
27214 +static void free_pxds(pxd_t *pxds[])
27215 {
27216 int i;
27217
27218 - for(i = 0; i < PREALLOCATED_PMDS; i++)
27219 - if (pmds[i])
27220 - free_page((unsigned long)pmds[i]);
27221 + for(i = 0; i < PREALLOCATED_PXDS; i++)
27222 + if (pxds[i])
27223 + free_page((unsigned long)pxds[i]);
27224 }
27225
27226 -static int preallocate_pmds(pmd_t *pmds[])
27227 +static int preallocate_pxds(pxd_t *pxds[])
27228 {
27229 int i;
27230 bool failed = false;
27231
27232 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27233 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27234 - if (pmd == NULL)
27235 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27236 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27237 + if (pxd == NULL)
27238 failed = true;
27239 - pmds[i] = pmd;
27240 + pxds[i] = pxd;
27241 }
27242
27243 if (failed) {
27244 - free_pmds(pmds);
27245 + free_pxds(pxds);
27246 return -ENOMEM;
27247 }
27248
27249 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27250 * preallocate which never got a corresponding vma will need to be
27251 * freed manually.
27252 */
27253 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27254 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27255 {
27256 int i;
27257
27258 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27259 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27260 pgd_t pgd = pgdp[i];
27261
27262 if (pgd_val(pgd) != 0) {
27263 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27264 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27265
27266 - pgdp[i] = native_make_pgd(0);
27267 + set_pgd(pgdp + i, native_make_pgd(0));
27268
27269 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27270 - pmd_free(mm, pmd);
27271 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27272 + pxd_free(mm, pxd);
27273 }
27274 }
27275 }
27276
27277 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27278 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27279 {
27280 - pud_t *pud;
27281 + pyd_t *pyd;
27282 unsigned long addr;
27283 int i;
27284
27285 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27286 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27287 return;
27288
27289 - pud = pud_offset(pgd, 0);
27290 +#ifdef CONFIG_X86_64
27291 + pyd = pyd_offset(mm, 0L);
27292 +#else
27293 + pyd = pyd_offset(pgd, 0L);
27294 +#endif
27295
27296 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27297 - i++, pud++, addr += PUD_SIZE) {
27298 - pmd_t *pmd = pmds[i];
27299 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27300 + i++, pyd++, addr += PYD_SIZE) {
27301 + pxd_t *pxd = pxds[i];
27302
27303 if (i >= KERNEL_PGD_BOUNDARY)
27304 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27305 - sizeof(pmd_t) * PTRS_PER_PMD);
27306 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27307 + sizeof(pxd_t) * PTRS_PER_PMD);
27308
27309 - pud_populate(mm, pud, pmd);
27310 + pyd_populate(mm, pyd, pxd);
27311 }
27312 }
27313
27314 pgd_t *pgd_alloc(struct mm_struct *mm)
27315 {
27316 pgd_t *pgd;
27317 - pmd_t *pmds[PREALLOCATED_PMDS];
27318 + pxd_t *pxds[PREALLOCATED_PXDS];
27319
27320 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27321
27322 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27323
27324 mm->pgd = pgd;
27325
27326 - if (preallocate_pmds(pmds) != 0)
27327 + if (preallocate_pxds(pxds) != 0)
27328 goto out_free_pgd;
27329
27330 if (paravirt_pgd_alloc(mm) != 0)
27331 - goto out_free_pmds;
27332 + goto out_free_pxds;
27333
27334 /*
27335 * Make sure that pre-populating the pmds is atomic with
27336 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27337 spin_lock(&pgd_lock);
27338
27339 pgd_ctor(mm, pgd);
27340 - pgd_prepopulate_pmd(mm, pgd, pmds);
27341 + pgd_prepopulate_pxd(mm, pgd, pxds);
27342
27343 spin_unlock(&pgd_lock);
27344
27345 return pgd;
27346
27347 -out_free_pmds:
27348 - free_pmds(pmds);
27349 +out_free_pxds:
27350 + free_pxds(pxds);
27351 out_free_pgd:
27352 free_page((unsigned long)pgd);
27353 out:
27354 @@ -295,7 +356,7 @@ out:
27355
27356 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27357 {
27358 - pgd_mop_up_pmds(mm, pgd);
27359 + pgd_mop_up_pxds(mm, pgd);
27360 pgd_dtor(pgd);
27361 paravirt_pgd_free(mm, pgd);
27362 free_page((unsigned long)pgd);
27363 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27364 index a69bcb8..19068ab 100644
27365 --- a/arch/x86/mm/pgtable_32.c
27366 +++ b/arch/x86/mm/pgtable_32.c
27367 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27368 return;
27369 }
27370 pte = pte_offset_kernel(pmd, vaddr);
27371 +
27372 + pax_open_kernel();
27373 if (pte_val(pteval))
27374 set_pte_at(&init_mm, vaddr, pte, pteval);
27375 else
27376 pte_clear(&init_mm, vaddr, pte);
27377 + pax_close_kernel();
27378
27379 /*
27380 * It's enough to flush this one mapping.
27381 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27382 index 410531d..0f16030 100644
27383 --- a/arch/x86/mm/setup_nx.c
27384 +++ b/arch/x86/mm/setup_nx.c
27385 @@ -5,8 +5,10 @@
27386 #include <asm/pgtable.h>
27387 #include <asm/proto.h>
27388
27389 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27390 static int disable_nx __cpuinitdata;
27391
27392 +#ifndef CONFIG_PAX_PAGEEXEC
27393 /*
27394 * noexec = on|off
27395 *
27396 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27397 return 0;
27398 }
27399 early_param("noexec", noexec_setup);
27400 +#endif
27401 +
27402 +#endif
27403
27404 void __cpuinit x86_configure_nx(void)
27405 {
27406 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27407 if (cpu_has_nx && !disable_nx)
27408 __supported_pte_mask |= _PAGE_NX;
27409 else
27410 +#endif
27411 __supported_pte_mask &= ~_PAGE_NX;
27412 }
27413
27414 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27415 index 60f926c..a710970 100644
27416 --- a/arch/x86/mm/tlb.c
27417 +++ b/arch/x86/mm/tlb.c
27418 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27419 BUG();
27420 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27421 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27422 +
27423 +#ifndef CONFIG_PAX_PER_CPU_PGD
27424 load_cr3(swapper_pg_dir);
27425 +#endif
27426 +
27427 }
27428 }
27429 EXPORT_SYMBOL_GPL(leave_mm);
27430 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27431 index 877b9a1..a8ecf42 100644
27432 --- a/arch/x86/net/bpf_jit.S
27433 +++ b/arch/x86/net/bpf_jit.S
27434 @@ -9,6 +9,7 @@
27435 */
27436 #include <linux/linkage.h>
27437 #include <asm/dwarf2.h>
27438 +#include <asm/alternative-asm.h>
27439
27440 /*
27441 * Calling convention :
27442 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27443 jle bpf_slow_path_word
27444 mov (SKBDATA,%rsi),%eax
27445 bswap %eax /* ntohl() */
27446 + pax_force_retaddr
27447 ret
27448
27449 sk_load_half:
27450 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27451 jle bpf_slow_path_half
27452 movzwl (SKBDATA,%rsi),%eax
27453 rol $8,%ax # ntohs()
27454 + pax_force_retaddr
27455 ret
27456
27457 sk_load_byte:
27458 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27459 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27460 jle bpf_slow_path_byte
27461 movzbl (SKBDATA,%rsi),%eax
27462 + pax_force_retaddr
27463 ret
27464
27465 /**
27466 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27467 movzbl (SKBDATA,%rsi),%ebx
27468 and $15,%bl
27469 shl $2,%bl
27470 + pax_force_retaddr
27471 ret
27472
27473 /* rsi contains offset and can be scratched */
27474 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27475 js bpf_error
27476 mov -12(%rbp),%eax
27477 bswap %eax
27478 + pax_force_retaddr
27479 ret
27480
27481 bpf_slow_path_half:
27482 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27483 mov -12(%rbp),%ax
27484 rol $8,%ax
27485 movzwl %ax,%eax
27486 + pax_force_retaddr
27487 ret
27488
27489 bpf_slow_path_byte:
27490 bpf_slow_path_common(1)
27491 js bpf_error
27492 movzbl -12(%rbp),%eax
27493 + pax_force_retaddr
27494 ret
27495
27496 bpf_slow_path_byte_msh:
27497 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27498 and $15,%al
27499 shl $2,%al
27500 xchg %eax,%ebx
27501 + pax_force_retaddr
27502 ret
27503
27504 #define sk_negative_common(SIZE) \
27505 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27506 sk_negative_common(4)
27507 mov (%rax), %eax
27508 bswap %eax
27509 + pax_force_retaddr
27510 ret
27511
27512 bpf_slow_path_half_neg:
27513 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27514 mov (%rax),%ax
27515 rol $8,%ax
27516 movzwl %ax,%eax
27517 + pax_force_retaddr
27518 ret
27519
27520 bpf_slow_path_byte_neg:
27521 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27522 .globl sk_load_byte_negative_offset
27523 sk_negative_common(1)
27524 movzbl (%rax), %eax
27525 + pax_force_retaddr
27526 ret
27527
27528 bpf_slow_path_byte_msh_neg:
27529 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27530 and $15,%al
27531 shl $2,%al
27532 xchg %eax,%ebx
27533 + pax_force_retaddr
27534 ret
27535
27536 bpf_error:
27537 @@ -197,4 +210,5 @@ bpf_error:
27538 xor %eax,%eax
27539 mov -8(%rbp),%rbx
27540 leaveq
27541 + pax_force_retaddr
27542 ret
27543 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27544 index 520d2bd..b895ef4 100644
27545 --- a/arch/x86/net/bpf_jit_comp.c
27546 +++ b/arch/x86/net/bpf_jit_comp.c
27547 @@ -11,6 +11,7 @@
27548 #include <asm/cacheflush.h>
27549 #include <linux/netdevice.h>
27550 #include <linux/filter.h>
27551 +#include <linux/random.h>
27552
27553 /*
27554 * Conventions :
27555 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27556 return ptr + len;
27557 }
27558
27559 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27560 +#define MAX_INSTR_CODE_SIZE 96
27561 +#else
27562 +#define MAX_INSTR_CODE_SIZE 64
27563 +#endif
27564 +
27565 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27566
27567 #define EMIT1(b1) EMIT(b1, 1)
27568 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27569 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27570 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27571 +
27572 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27573 +/* original constant will appear in ecx */
27574 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27575 +do { \
27576 + /* mov ecx, randkey */ \
27577 + EMIT1(0xb9); \
27578 + EMIT(_key, 4); \
27579 + /* xor ecx, randkey ^ off */ \
27580 + EMIT2(0x81, 0xf1); \
27581 + EMIT((_key) ^ (_off), 4); \
27582 +} while (0)
27583 +
27584 +#define EMIT1_off32(b1, _off) \
27585 +do { \
27586 + switch (b1) { \
27587 + case 0x05: /* add eax, imm32 */ \
27588 + case 0x2d: /* sub eax, imm32 */ \
27589 + case 0x25: /* and eax, imm32 */ \
27590 + case 0x0d: /* or eax, imm32 */ \
27591 + case 0xb8: /* mov eax, imm32 */ \
27592 + case 0x3d: /* cmp eax, imm32 */ \
27593 + case 0xa9: /* test eax, imm32 */ \
27594 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27595 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27596 + break; \
27597 + case 0xbb: /* mov ebx, imm32 */ \
27598 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27599 + /* mov ebx, ecx */ \
27600 + EMIT2(0x89, 0xcb); \
27601 + break; \
27602 + case 0xbe: /* mov esi, imm32 */ \
27603 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27604 + /* mov esi, ecx */ \
27605 + EMIT2(0x89, 0xce); \
27606 + break; \
27607 + case 0xe9: /* jmp rel imm32 */ \
27608 + EMIT1(b1); \
27609 + EMIT(_off, 4); \
27610 + /* prevent fall-through, we're not called if off = 0 */ \
27611 + EMIT(0xcccccccc, 4); \
27612 + EMIT(0xcccccccc, 4); \
27613 + break; \
27614 + default: \
27615 + EMIT1(b1); \
27616 + EMIT(_off, 4); \
27617 + } \
27618 +} while (0)
27619 +
27620 +#define EMIT2_off32(b1, b2, _off) \
27621 +do { \
27622 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27623 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27624 + EMIT(randkey, 4); \
27625 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27626 + EMIT((_off) - randkey, 4); \
27627 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27628 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27629 + /* imul eax, ecx */ \
27630 + EMIT3(0x0f, 0xaf, 0xc1); \
27631 + } else { \
27632 + EMIT2(b1, b2); \
27633 + EMIT(_off, 4); \
27634 + } \
27635 +} while (0)
27636 +#else
27637 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27638 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27639 +#endif
27640
27641 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27642 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27643 @@ -89,6 +164,24 @@ do { \
27644 #define X86_JBE 0x76
27645 #define X86_JA 0x77
27646
27647 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27648 +#define APPEND_FLOW_VERIFY() \
27649 +do { \
27650 + /* mov ecx, randkey */ \
27651 + EMIT1(0xb9); \
27652 + EMIT(randkey, 4); \
27653 + /* cmp ecx, randkey */ \
27654 + EMIT2(0x81, 0xf9); \
27655 + EMIT(randkey, 4); \
27656 + /* jz after 8 int 3s */ \
27657 + EMIT2(0x74, 0x08); \
27658 + EMIT(0xcccccccc, 4); \
27659 + EMIT(0xcccccccc, 4); \
27660 +} while (0)
27661 +#else
27662 +#define APPEND_FLOW_VERIFY() do { } while (0)
27663 +#endif
27664 +
27665 #define EMIT_COND_JMP(op, offset) \
27666 do { \
27667 if (is_near(offset)) \
27668 @@ -96,6 +189,7 @@ do { \
27669 else { \
27670 EMIT2(0x0f, op + 0x10); \
27671 EMIT(offset, 4); /* jxx .+off32 */ \
27672 + APPEND_FLOW_VERIFY(); \
27673 } \
27674 } while (0)
27675
27676 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27677 set_fs(old_fs);
27678 }
27679
27680 +struct bpf_jit_work {
27681 + struct work_struct work;
27682 + void *image;
27683 +};
27684 +
27685 #define CHOOSE_LOAD_FUNC(K, func) \
27686 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27687
27688 void bpf_jit_compile(struct sk_filter *fp)
27689 {
27690 - u8 temp[64];
27691 + u8 temp[MAX_INSTR_CODE_SIZE];
27692 u8 *prog;
27693 unsigned int proglen, oldproglen = 0;
27694 int ilen, i;
27695 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27696 unsigned int *addrs;
27697 const struct sock_filter *filter = fp->insns;
27698 int flen = fp->len;
27699 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27700 + unsigned int randkey;
27701 +#endif
27702
27703 if (!bpf_jit_enable)
27704 return;
27705 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27706 if (addrs == NULL)
27707 return;
27708
27709 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27710 + if (!fp->work)
27711 + goto out;
27712 +
27713 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27714 + randkey = get_random_int();
27715 +#endif
27716 +
27717 /* Before first pass, make a rough estimation of addrs[]
27718 - * each bpf instruction is translated to less than 64 bytes
27719 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27720 */
27721 for (proglen = 0, i = 0; i < flen; i++) {
27722 - proglen += 64;
27723 + proglen += MAX_INSTR_CODE_SIZE;
27724 addrs[i] = proglen;
27725 }
27726 cleanup_addr = proglen; /* epilogue address */
27727 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27728 case BPF_S_ALU_MUL_K: /* A *= K */
27729 if (is_imm8(K))
27730 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27731 - else {
27732 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27733 - EMIT(K, 4);
27734 - }
27735 + else
27736 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27737 break;
27738 case BPF_S_ALU_DIV_X: /* A /= X; */
27739 seen |= SEEN_XREG;
27740 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27741 break;
27742 case BPF_S_ALU_MOD_K: /* A %= K; */
27743 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27744 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27745 + DILUTE_CONST_SEQUENCE(K, randkey);
27746 +#else
27747 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27748 +#endif
27749 EMIT2(0xf7, 0xf1); /* div %ecx */
27750 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27751 break;
27752 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27753 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27754 + DILUTE_CONST_SEQUENCE(K, randkey);
27755 + // imul rax, rcx
27756 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27757 +#else
27758 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27759 EMIT(K, 4);
27760 +#endif
27761 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27762 break;
27763 case BPF_S_ALU_AND_X:
27764 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27765 if (is_imm8(K)) {
27766 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27767 } else {
27768 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27769 - EMIT(K, 4);
27770 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27771 }
27772 } else {
27773 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27774 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27775 break;
27776 default:
27777 /* hmm, too complex filter, give up with jit compiler */
27778 - goto out;
27779 + goto error;
27780 }
27781 ilen = prog - temp;
27782 if (image) {
27783 if (unlikely(proglen + ilen > oldproglen)) {
27784 pr_err("bpb_jit_compile fatal error\n");
27785 - kfree(addrs);
27786 - module_free(NULL, image);
27787 - return;
27788 + module_free_exec(NULL, image);
27789 + goto error;
27790 }
27791 + pax_open_kernel();
27792 memcpy(image + proglen, temp, ilen);
27793 + pax_close_kernel();
27794 }
27795 proglen += ilen;
27796 addrs[i] = proglen;
27797 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27798 break;
27799 }
27800 if (proglen == oldproglen) {
27801 - image = module_alloc(max_t(unsigned int,
27802 - proglen,
27803 - sizeof(struct work_struct)));
27804 + image = module_alloc_exec(proglen);
27805 if (!image)
27806 - goto out;
27807 + goto error;
27808 }
27809 oldproglen = proglen;
27810 }
27811 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27812 bpf_flush_icache(image, image + proglen);
27813
27814 fp->bpf_func = (void *)image;
27815 - }
27816 + } else
27817 +error:
27818 + kfree(fp->work);
27819 +
27820 out:
27821 kfree(addrs);
27822 return;
27823 @@ -686,18 +805,20 @@ out:
27824
27825 static void jit_free_defer(struct work_struct *arg)
27826 {
27827 - module_free(NULL, arg);
27828 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27829 + kfree(arg);
27830 }
27831
27832 /* run from softirq, we must use a work_struct to call
27833 - * module_free() from process context
27834 + * module_free_exec() from process context
27835 */
27836 void bpf_jit_free(struct sk_filter *fp)
27837 {
27838 if (fp->bpf_func != sk_run_filter) {
27839 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27840 + struct work_struct *work = &fp->work->work;
27841
27842 INIT_WORK(work, jit_free_defer);
27843 + fp->work->image = fp->bpf_func;
27844 schedule_work(work);
27845 }
27846 }
27847 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27848 index d6aa6e8..266395a 100644
27849 --- a/arch/x86/oprofile/backtrace.c
27850 +++ b/arch/x86/oprofile/backtrace.c
27851 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27852 struct stack_frame_ia32 *fp;
27853 unsigned long bytes;
27854
27855 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27856 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27857 if (bytes != sizeof(bufhead))
27858 return NULL;
27859
27860 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27861 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27862
27863 oprofile_add_trace(bufhead[0].return_address);
27864
27865 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27866 struct stack_frame bufhead[2];
27867 unsigned long bytes;
27868
27869 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27870 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27871 if (bytes != sizeof(bufhead))
27872 return NULL;
27873
27874 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27875 {
27876 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27877
27878 - if (!user_mode_vm(regs)) {
27879 + if (!user_mode(regs)) {
27880 unsigned long stack = kernel_stack_pointer(regs);
27881 if (depth)
27882 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27883 diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27884 index 192397c..5ba6f9e 100644
27885 --- a/arch/x86/pci/acpi.c
27886 +++ b/arch/x86/pci/acpi.c
27887 @@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27888 acpi_irq_penalty_init();
27889 pcibios_enable_irq = acpi_pci_irq_enable;
27890 pcibios_disable_irq = acpi_pci_irq_disable;
27891 - x86_init.pci.init_irq = x86_init_noop;
27892 + *(void **)&x86_init.pci.init_irq = x86_init_noop;
27893
27894 if (pci_routeirq) {
27895 /*
27896 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27897 index e14a2ff..3fd6b58 100644
27898 --- a/arch/x86/pci/mrst.c
27899 +++ b/arch/x86/pci/mrst.c
27900 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27901 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27902 pci_mmcfg_late_init();
27903 pcibios_enable_irq = mrst_pci_irq_enable;
27904 - pci_root_ops = pci_mrst_ops;
27905 + pax_open_kernel();
27906 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27907 + pax_close_kernel();
27908 pci_soc_mode = 1;
27909 /* Continue with standard init */
27910 return 1;
27911 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27912 index da8fe05..7ee6704 100644
27913 --- a/arch/x86/pci/pcbios.c
27914 +++ b/arch/x86/pci/pcbios.c
27915 @@ -79,50 +79,93 @@ union bios32 {
27916 static struct {
27917 unsigned long address;
27918 unsigned short segment;
27919 -} bios32_indirect = { 0, __KERNEL_CS };
27920 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27921
27922 /*
27923 * Returns the entry point for the given service, NULL on error
27924 */
27925
27926 -static unsigned long bios32_service(unsigned long service)
27927 +static unsigned long __devinit bios32_service(unsigned long service)
27928 {
27929 unsigned char return_code; /* %al */
27930 unsigned long address; /* %ebx */
27931 unsigned long length; /* %ecx */
27932 unsigned long entry; /* %edx */
27933 unsigned long flags;
27934 + struct desc_struct d, *gdt;
27935
27936 local_irq_save(flags);
27937 - __asm__("lcall *(%%edi); cld"
27938 +
27939 + gdt = get_cpu_gdt_table(smp_processor_id());
27940 +
27941 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27942 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27943 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27944 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27945 +
27946 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27947 : "=a" (return_code),
27948 "=b" (address),
27949 "=c" (length),
27950 "=d" (entry)
27951 : "0" (service),
27952 "1" (0),
27953 - "D" (&bios32_indirect));
27954 + "D" (&bios32_indirect),
27955 + "r"(__PCIBIOS_DS)
27956 + : "memory");
27957 +
27958 + pax_open_kernel();
27959 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
27960 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
27961 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
27962 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
27963 + pax_close_kernel();
27964 +
27965 local_irq_restore(flags);
27966
27967 switch (return_code) {
27968 - case 0:
27969 - return address + entry;
27970 - case 0x80: /* Not present */
27971 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27972 - return 0;
27973 - default: /* Shouldn't happen */
27974 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27975 - service, return_code);
27976 + case 0: {
27977 + int cpu;
27978 + unsigned char flags;
27979 +
27980 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
27981 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
27982 + printk(KERN_WARNING "bios32_service: not valid\n");
27983 return 0;
27984 + }
27985 + address = address + PAGE_OFFSET;
27986 + length += 16UL; /* some BIOSs underreport this... */
27987 + flags = 4;
27988 + if (length >= 64*1024*1024) {
27989 + length >>= PAGE_SHIFT;
27990 + flags |= 8;
27991 + }
27992 +
27993 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27994 + gdt = get_cpu_gdt_table(cpu);
27995 + pack_descriptor(&d, address, length, 0x9b, flags);
27996 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27997 + pack_descriptor(&d, address, length, 0x93, flags);
27998 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27999 + }
28000 + return entry;
28001 + }
28002 + case 0x80: /* Not present */
28003 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28004 + return 0;
28005 + default: /* Shouldn't happen */
28006 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28007 + service, return_code);
28008 + return 0;
28009 }
28010 }
28011
28012 static struct {
28013 unsigned long address;
28014 unsigned short segment;
28015 -} pci_indirect = { 0, __KERNEL_CS };
28016 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28017
28018 -static int pci_bios_present;
28019 +static int pci_bios_present __read_only;
28020
28021 static int __devinit check_pcibios(void)
28022 {
28023 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28024 unsigned long flags, pcibios_entry;
28025
28026 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28027 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28028 + pci_indirect.address = pcibios_entry;
28029
28030 local_irq_save(flags);
28031 - __asm__(
28032 - "lcall *(%%edi); cld\n\t"
28033 + __asm__("movw %w6, %%ds\n\t"
28034 + "lcall *%%ss:(%%edi); cld\n\t"
28035 + "push %%ss\n\t"
28036 + "pop %%ds\n\t"
28037 "jc 1f\n\t"
28038 "xor %%ah, %%ah\n"
28039 "1:"
28040 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28041 "=b" (ebx),
28042 "=c" (ecx)
28043 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28044 - "D" (&pci_indirect)
28045 + "D" (&pci_indirect),
28046 + "r" (__PCIBIOS_DS)
28047 : "memory");
28048 local_irq_restore(flags);
28049
28050 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28051
28052 switch (len) {
28053 case 1:
28054 - __asm__("lcall *(%%esi); cld\n\t"
28055 + __asm__("movw %w6, %%ds\n\t"
28056 + "lcall *%%ss:(%%esi); cld\n\t"
28057 + "push %%ss\n\t"
28058 + "pop %%ds\n\t"
28059 "jc 1f\n\t"
28060 "xor %%ah, %%ah\n"
28061 "1:"
28062 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28063 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28064 "b" (bx),
28065 "D" ((long)reg),
28066 - "S" (&pci_indirect));
28067 + "S" (&pci_indirect),
28068 + "r" (__PCIBIOS_DS));
28069 /*
28070 * Zero-extend the result beyond 8 bits, do not trust the
28071 * BIOS having done it:
28072 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28073 *value &= 0xff;
28074 break;
28075 case 2:
28076 - __asm__("lcall *(%%esi); cld\n\t"
28077 + __asm__("movw %w6, %%ds\n\t"
28078 + "lcall *%%ss:(%%esi); cld\n\t"
28079 + "push %%ss\n\t"
28080 + "pop %%ds\n\t"
28081 "jc 1f\n\t"
28082 "xor %%ah, %%ah\n"
28083 "1:"
28084 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28085 : "1" (PCIBIOS_READ_CONFIG_WORD),
28086 "b" (bx),
28087 "D" ((long)reg),
28088 - "S" (&pci_indirect));
28089 + "S" (&pci_indirect),
28090 + "r" (__PCIBIOS_DS));
28091 /*
28092 * Zero-extend the result beyond 16 bits, do not trust the
28093 * BIOS having done it:
28094 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28095 *value &= 0xffff;
28096 break;
28097 case 4:
28098 - __asm__("lcall *(%%esi); cld\n\t"
28099 + __asm__("movw %w6, %%ds\n\t"
28100 + "lcall *%%ss:(%%esi); cld\n\t"
28101 + "push %%ss\n\t"
28102 + "pop %%ds\n\t"
28103 "jc 1f\n\t"
28104 "xor %%ah, %%ah\n"
28105 "1:"
28106 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28107 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28108 "b" (bx),
28109 "D" ((long)reg),
28110 - "S" (&pci_indirect));
28111 + "S" (&pci_indirect),
28112 + "r" (__PCIBIOS_DS));
28113 break;
28114 }
28115
28116 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28117
28118 switch (len) {
28119 case 1:
28120 - __asm__("lcall *(%%esi); cld\n\t"
28121 + __asm__("movw %w6, %%ds\n\t"
28122 + "lcall *%%ss:(%%esi); cld\n\t"
28123 + "push %%ss\n\t"
28124 + "pop %%ds\n\t"
28125 "jc 1f\n\t"
28126 "xor %%ah, %%ah\n"
28127 "1:"
28128 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28129 "c" (value),
28130 "b" (bx),
28131 "D" ((long)reg),
28132 - "S" (&pci_indirect));
28133 + "S" (&pci_indirect),
28134 + "r" (__PCIBIOS_DS));
28135 break;
28136 case 2:
28137 - __asm__("lcall *(%%esi); cld\n\t"
28138 + __asm__("movw %w6, %%ds\n\t"
28139 + "lcall *%%ss:(%%esi); cld\n\t"
28140 + "push %%ss\n\t"
28141 + "pop %%ds\n\t"
28142 "jc 1f\n\t"
28143 "xor %%ah, %%ah\n"
28144 "1:"
28145 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28146 "c" (value),
28147 "b" (bx),
28148 "D" ((long)reg),
28149 - "S" (&pci_indirect));
28150 + "S" (&pci_indirect),
28151 + "r" (__PCIBIOS_DS));
28152 break;
28153 case 4:
28154 - __asm__("lcall *(%%esi); cld\n\t"
28155 + __asm__("movw %w6, %%ds\n\t"
28156 + "lcall *%%ss:(%%esi); cld\n\t"
28157 + "push %%ss\n\t"
28158 + "pop %%ds\n\t"
28159 "jc 1f\n\t"
28160 "xor %%ah, %%ah\n"
28161 "1:"
28162 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28163 "c" (value),
28164 "b" (bx),
28165 "D" ((long)reg),
28166 - "S" (&pci_indirect));
28167 + "S" (&pci_indirect),
28168 + "r" (__PCIBIOS_DS));
28169 break;
28170 }
28171
28172 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28173
28174 DBG("PCI: Fetching IRQ routing table... ");
28175 __asm__("push %%es\n\t"
28176 + "movw %w8, %%ds\n\t"
28177 "push %%ds\n\t"
28178 "pop %%es\n\t"
28179 - "lcall *(%%esi); cld\n\t"
28180 + "lcall *%%ss:(%%esi); cld\n\t"
28181 "pop %%es\n\t"
28182 + "push %%ss\n\t"
28183 + "pop %%ds\n"
28184 "jc 1f\n\t"
28185 "xor %%ah, %%ah\n"
28186 "1:"
28187 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28188 "1" (0),
28189 "D" ((long) &opt),
28190 "S" (&pci_indirect),
28191 - "m" (opt)
28192 + "m" (opt),
28193 + "r" (__PCIBIOS_DS)
28194 : "memory");
28195 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28196 if (ret & 0xff00)
28197 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28198 {
28199 int ret;
28200
28201 - __asm__("lcall *(%%esi); cld\n\t"
28202 + __asm__("movw %w5, %%ds\n\t"
28203 + "lcall *%%ss:(%%esi); cld\n\t"
28204 + "push %%ss\n\t"
28205 + "pop %%ds\n"
28206 "jc 1f\n\t"
28207 "xor %%ah, %%ah\n"
28208 "1:"
28209 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28210 : "0" (PCIBIOS_SET_PCI_HW_INT),
28211 "b" ((dev->bus->number << 8) | dev->devfn),
28212 "c" ((irq << 8) | (pin + 10)),
28213 - "S" (&pci_indirect));
28214 + "S" (&pci_indirect),
28215 + "r" (__PCIBIOS_DS));
28216 return !(ret & 0xff00);
28217 }
28218 EXPORT_SYMBOL(pcibios_set_irq_routing);
28219 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28220 index 56ab749..3cb792a 100644
28221 --- a/arch/x86/pci/xen.c
28222 +++ b/arch/x86/pci/xen.c
28223 @@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28224 #endif
28225
28226 #ifdef CONFIG_PCI_MSI
28227 - x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28228 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28229 - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28230 + *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28231 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28232 + *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28233 #endif
28234 return 0;
28235 }
28236 @@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28237 #endif
28238
28239 #ifdef CONFIG_PCI_MSI
28240 - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28241 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28242 + *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28243 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28244 #endif
28245 return 0;
28246 }
28247 @@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28248 int irq;
28249
28250 #ifdef CONFIG_PCI_MSI
28251 - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28252 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28253 - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28254 + *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28255 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28256 + *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28257 #endif
28258 xen_setup_acpi_sci();
28259 __acpi_register_gsi = acpi_register_gsi_xen;
28260 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28261 index ad44391..acef4b5 100644
28262 --- a/arch/x86/platform/efi/efi.c
28263 +++ b/arch/x86/platform/efi/efi.c
28264 @@ -738,8 +738,8 @@ void __init efi_init(void)
28265 }
28266 #ifdef CONFIG_X86_32
28267 if (efi_is_native()) {
28268 - x86_platform.get_wallclock = efi_get_time;
28269 - x86_platform.set_wallclock = efi_set_rtc_mmss;
28270 + *(void **)&x86_platform.get_wallclock = efi_get_time;
28271 + *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28272 }
28273 #endif
28274
28275 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28276 index 40e4469..1ab536e 100644
28277 --- a/arch/x86/platform/efi/efi_32.c
28278 +++ b/arch/x86/platform/efi/efi_32.c
28279 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28280 {
28281 struct desc_ptr gdt_descr;
28282
28283 +#ifdef CONFIG_PAX_KERNEXEC
28284 + struct desc_struct d;
28285 +#endif
28286 +
28287 local_irq_save(efi_rt_eflags);
28288
28289 load_cr3(initial_page_table);
28290 __flush_tlb_all();
28291
28292 +#ifdef CONFIG_PAX_KERNEXEC
28293 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28294 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28295 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28296 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28297 +#endif
28298 +
28299 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28300 gdt_descr.size = GDT_SIZE - 1;
28301 load_gdt(&gdt_descr);
28302 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28303 {
28304 struct desc_ptr gdt_descr;
28305
28306 +#ifdef CONFIG_PAX_KERNEXEC
28307 + struct desc_struct d;
28308 +
28309 + memset(&d, 0, sizeof d);
28310 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28311 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28312 +#endif
28313 +
28314 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28315 gdt_descr.size = GDT_SIZE - 1;
28316 load_gdt(&gdt_descr);
28317 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28318 index fbe66e6..eae5e38 100644
28319 --- a/arch/x86/platform/efi/efi_stub_32.S
28320 +++ b/arch/x86/platform/efi/efi_stub_32.S
28321 @@ -6,7 +6,9 @@
28322 */
28323
28324 #include <linux/linkage.h>
28325 +#include <linux/init.h>
28326 #include <asm/page_types.h>
28327 +#include <asm/segment.h>
28328
28329 /*
28330 * efi_call_phys(void *, ...) is a function with variable parameters.
28331 @@ -20,7 +22,7 @@
28332 * service functions will comply with gcc calling convention, too.
28333 */
28334
28335 -.text
28336 +__INIT
28337 ENTRY(efi_call_phys)
28338 /*
28339 * 0. The function can only be called in Linux kernel. So CS has been
28340 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28341 * The mapping of lower virtual memory has been created in prelog and
28342 * epilog.
28343 */
28344 - movl $1f, %edx
28345 - subl $__PAGE_OFFSET, %edx
28346 - jmp *%edx
28347 +#ifdef CONFIG_PAX_KERNEXEC
28348 + movl $(__KERNEXEC_EFI_DS), %edx
28349 + mov %edx, %ds
28350 + mov %edx, %es
28351 + mov %edx, %ss
28352 + addl $2f,(1f)
28353 + ljmp *(1f)
28354 +
28355 +__INITDATA
28356 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28357 +.previous
28358 +
28359 +2:
28360 + subl $2b,(1b)
28361 +#else
28362 + jmp 1f-__PAGE_OFFSET
28363 1:
28364 +#endif
28365
28366 /*
28367 * 2. Now on the top of stack is the return
28368 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28369 * parameter 2, ..., param n. To make things easy, we save the return
28370 * address of efi_call_phys in a global variable.
28371 */
28372 - popl %edx
28373 - movl %edx, saved_return_addr
28374 - /* get the function pointer into ECX*/
28375 - popl %ecx
28376 - movl %ecx, efi_rt_function_ptr
28377 - movl $2f, %edx
28378 - subl $__PAGE_OFFSET, %edx
28379 - pushl %edx
28380 + popl (saved_return_addr)
28381 + popl (efi_rt_function_ptr)
28382
28383 /*
28384 * 3. Clear PG bit in %CR0.
28385 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28386 /*
28387 * 5. Call the physical function.
28388 */
28389 - jmp *%ecx
28390 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28391
28392 -2:
28393 /*
28394 * 6. After EFI runtime service returns, control will return to
28395 * following instruction. We'd better readjust stack pointer first.
28396 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28397 movl %cr0, %edx
28398 orl $0x80000000, %edx
28399 movl %edx, %cr0
28400 - jmp 1f
28401 -1:
28402 +
28403 /*
28404 * 8. Now restore the virtual mode from flat mode by
28405 * adding EIP with PAGE_OFFSET.
28406 */
28407 - movl $1f, %edx
28408 - jmp *%edx
28409 +#ifdef CONFIG_PAX_KERNEXEC
28410 + movl $(__KERNEL_DS), %edx
28411 + mov %edx, %ds
28412 + mov %edx, %es
28413 + mov %edx, %ss
28414 + ljmp $(__KERNEL_CS),$1f
28415 +#else
28416 + jmp 1f+__PAGE_OFFSET
28417 +#endif
28418 1:
28419
28420 /*
28421 * 9. Balance the stack. And because EAX contain the return value,
28422 * we'd better not clobber it.
28423 */
28424 - leal efi_rt_function_ptr, %edx
28425 - movl (%edx), %ecx
28426 - pushl %ecx
28427 + pushl (efi_rt_function_ptr)
28428
28429 /*
28430 - * 10. Push the saved return address onto the stack and return.
28431 + * 10. Return to the saved return address.
28432 */
28433 - leal saved_return_addr, %edx
28434 - movl (%edx), %ecx
28435 - pushl %ecx
28436 - ret
28437 + jmpl *(saved_return_addr)
28438 ENDPROC(efi_call_phys)
28439 .previous
28440
28441 -.data
28442 +__INITDATA
28443 saved_return_addr:
28444 .long 0
28445 efi_rt_function_ptr:
28446 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28447 index 4c07cca..2c8427d 100644
28448 --- a/arch/x86/platform/efi/efi_stub_64.S
28449 +++ b/arch/x86/platform/efi/efi_stub_64.S
28450 @@ -7,6 +7,7 @@
28451 */
28452
28453 #include <linux/linkage.h>
28454 +#include <asm/alternative-asm.h>
28455
28456 #define SAVE_XMM \
28457 mov %rsp, %rax; \
28458 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28459 call *%rdi
28460 addq $32, %rsp
28461 RESTORE_XMM
28462 + pax_force_retaddr 0, 1
28463 ret
28464 ENDPROC(efi_call0)
28465
28466 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28467 call *%rdi
28468 addq $32, %rsp
28469 RESTORE_XMM
28470 + pax_force_retaddr 0, 1
28471 ret
28472 ENDPROC(efi_call1)
28473
28474 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28475 call *%rdi
28476 addq $32, %rsp
28477 RESTORE_XMM
28478 + pax_force_retaddr 0, 1
28479 ret
28480 ENDPROC(efi_call2)
28481
28482 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28483 call *%rdi
28484 addq $32, %rsp
28485 RESTORE_XMM
28486 + pax_force_retaddr 0, 1
28487 ret
28488 ENDPROC(efi_call3)
28489
28490 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28491 call *%rdi
28492 addq $32, %rsp
28493 RESTORE_XMM
28494 + pax_force_retaddr 0, 1
28495 ret
28496 ENDPROC(efi_call4)
28497
28498 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28499 call *%rdi
28500 addq $48, %rsp
28501 RESTORE_XMM
28502 + pax_force_retaddr 0, 1
28503 ret
28504 ENDPROC(efi_call5)
28505
28506 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28507 call *%rdi
28508 addq $48, %rsp
28509 RESTORE_XMM
28510 + pax_force_retaddr 0, 1
28511 ret
28512 ENDPROC(efi_call6)
28513 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28514 index fd41a92..bc8091d 100644
28515 --- a/arch/x86/platform/mrst/mrst.c
28516 +++ b/arch/x86/platform/mrst/mrst.c
28517 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28518 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28519 int sfi_mrtc_num;
28520
28521 -static void mrst_power_off(void)
28522 +static __noreturn void mrst_power_off(void)
28523 {
28524 + BUG();
28525 }
28526
28527 -static void mrst_reboot(void)
28528 +static __noreturn void mrst_reboot(void)
28529 {
28530 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28531 + BUG();
28532 }
28533
28534 /* parse all the mtimer info to a static mtimer array */
28535 @@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28536 case MRST_TIMER_APBT_ONLY:
28537 break;
28538 case MRST_TIMER_LAPIC_APBT:
28539 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28540 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28541 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28542 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28543 break;
28544 default:
28545 if (!boot_cpu_has(X86_FEATURE_ARAT))
28546 break;
28547 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28548 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28549 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28550 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28551 return;
28552 }
28553 /* we need at least one APB timer */
28554 @@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28555 */
28556 void __init x86_mrst_early_setup(void)
28557 {
28558 - x86_init.resources.probe_roms = x86_init_noop;
28559 - x86_init.resources.reserve_resources = x86_init_noop;
28560 + *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28561 + *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28562
28563 - x86_init.timers.timer_init = mrst_time_init;
28564 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
28565 + *(void **)&x86_init.timers.timer_init = mrst_time_init;
28566 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28567
28568 - x86_init.irqs.pre_vector_init = x86_init_noop;
28569 + *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28570
28571 - x86_init.oem.arch_setup = mrst_arch_setup;
28572 + *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28573
28574 - x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28575 + *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28576
28577 - x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28578 - x86_platform.i8042_detect = mrst_i8042_detect;
28579 - x86_init.timers.wallclock_init = mrst_rtc_init;
28580 - x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28581 + *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28582 + *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28583 + *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28584 + *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28585
28586 - x86_init.pci.init = pci_mrst_init;
28587 - x86_init.pci.fixup_irqs = x86_init_noop;
28588 + *(void **)&x86_init.pci.init = pci_mrst_init;
28589 + *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28590
28591 legacy_pic = &null_legacy_pic;
28592
28593 /* Moorestown specific power_off/restart method */
28594 pm_power_off = mrst_power_off;
28595 - machine_ops.emergency_restart = mrst_reboot;
28596 + *(void **)&machine_ops.emergency_restart = mrst_reboot;
28597
28598 /* Avoid searching for BIOS MP tables */
28599 - x86_init.mpparse.find_smp_config = x86_init_noop;
28600 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28601 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28602 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28603 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28604 }
28605
28606 diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28607 index 225bd0f..22e8086 100644
28608 --- a/arch/x86/platform/mrst/vrtc.c
28609 +++ b/arch/x86/platform/mrst/vrtc.c
28610 @@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28611
28612 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28613 vrtc_paddr);
28614 - x86_platform.get_wallclock = vrtc_get_time;
28615 - x86_platform.set_wallclock = vrtc_set_mmss;
28616 + *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28617 + *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28618 }
28619
28620 /*
28621 diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28622 index 2737608..0d62cc2 100644
28623 --- a/arch/x86/platform/olpc/olpc.c
28624 +++ b/arch/x86/platform/olpc/olpc.c
28625 @@ -395,7 +395,7 @@ static int __init olpc_init(void)
28626 * XO-1 only. */
28627 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28628 !cs5535_has_vsa2())
28629 - x86_init.pci.arch_init = pci_olpc_init;
28630 + *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28631 #endif
28632
28633 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28634 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28635 index d6ee929..3637cb5 100644
28636 --- a/arch/x86/platform/olpc/olpc_dt.c
28637 +++ b/arch/x86/platform/olpc/olpc_dt.c
28638 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28639 return res;
28640 }
28641
28642 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28643 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28644 .nextprop = olpc_dt_nextprop,
28645 .getproplen = olpc_dt_getproplen,
28646 .getproperty = olpc_dt_getproperty,
28647 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28648 index 218cdb1..c1178eb 100644
28649 --- a/arch/x86/power/cpu.c
28650 +++ b/arch/x86/power/cpu.c
28651 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28652 static void fix_processor_context(void)
28653 {
28654 int cpu = smp_processor_id();
28655 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28656 + struct tss_struct *t = init_tss + cpu;
28657
28658 set_tss_desc(cpu, t); /*
28659 * This just modifies memory; should not be
28660 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28661 */
28662
28663 #ifdef CONFIG_X86_64
28664 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28665 -
28666 syscall_init(); /* This sets MSR_*STAR and related */
28667 #endif
28668 load_TR_desc(); /* This does ltr */
28669 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28670 index cbca565..bae7133 100644
28671 --- a/arch/x86/realmode/init.c
28672 +++ b/arch/x86/realmode/init.c
28673 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28674 __va(real_mode_header->trampoline_header);
28675
28676 #ifdef CONFIG_X86_32
28677 - trampoline_header->start = __pa(startup_32_smp);
28678 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28679 +
28680 +#ifdef CONFIG_PAX_KERNEXEC
28681 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28682 +#endif
28683 +
28684 + trampoline_header->boot_cs = __BOOT_CS;
28685 trampoline_header->gdt_limit = __BOOT_DS + 7;
28686 trampoline_header->gdt_base = __pa(boot_gdt);
28687 #else
28688 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28689 index 8869287..d577672 100644
28690 --- a/arch/x86/realmode/rm/Makefile
28691 +++ b/arch/x86/realmode/rm/Makefile
28692 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28693 $(call cc-option, -fno-unit-at-a-time)) \
28694 $(call cc-option, -fno-stack-protector) \
28695 $(call cc-option, -mpreferred-stack-boundary=2)
28696 +ifdef CONSTIFY_PLUGIN
28697 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28698 +endif
28699 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28700 GCOV_PROFILE := n
28701 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28702 index a28221d..93c40f1 100644
28703 --- a/arch/x86/realmode/rm/header.S
28704 +++ b/arch/x86/realmode/rm/header.S
28705 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28706 #endif
28707 /* APM/BIOS reboot */
28708 .long pa_machine_real_restart_asm
28709 -#ifdef CONFIG_X86_64
28710 +#ifdef CONFIG_X86_32
28711 + .long __KERNEL_CS
28712 +#else
28713 .long __KERNEL32_CS
28714 #endif
28715 END(real_mode_header)
28716 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28717 index c1b2791..f9e31c7 100644
28718 --- a/arch/x86/realmode/rm/trampoline_32.S
28719 +++ b/arch/x86/realmode/rm/trampoline_32.S
28720 @@ -25,6 +25,12 @@
28721 #include <asm/page_types.h>
28722 #include "realmode.h"
28723
28724 +#ifdef CONFIG_PAX_KERNEXEC
28725 +#define ta(X) (X)
28726 +#else
28727 +#define ta(X) (pa_ ## X)
28728 +#endif
28729 +
28730 .text
28731 .code16
28732
28733 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28734
28735 cli # We should be safe anyway
28736
28737 - movl tr_start, %eax # where we need to go
28738 -
28739 movl $0xA5A5A5A5, trampoline_status
28740 # write marker for master knows we're running
28741
28742 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28743 movw $1, %dx # protected mode (PE) bit
28744 lmsw %dx # into protected mode
28745
28746 - ljmpl $__BOOT_CS, $pa_startup_32
28747 + ljmpl *(trampoline_header)
28748
28749 .section ".text32","ax"
28750 .code32
28751 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28752 .balign 8
28753 GLOBAL(trampoline_header)
28754 tr_start: .space 4
28755 - tr_gdt_pad: .space 2
28756 + tr_boot_cs: .space 2
28757 tr_gdt: .space 6
28758 END(trampoline_header)
28759
28760 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28761 index bb360dc..3e5945f 100644
28762 --- a/arch/x86/realmode/rm/trampoline_64.S
28763 +++ b/arch/x86/realmode/rm/trampoline_64.S
28764 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28765 wrmsr
28766
28767 # Enable paging and in turn activate Long Mode
28768 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28769 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28770 movl %eax, %cr0
28771
28772 /*
28773 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28774 index 5a1847d..deccb30 100644
28775 --- a/arch/x86/tools/relocs.c
28776 +++ b/arch/x86/tools/relocs.c
28777 @@ -12,10 +12,13 @@
28778 #include <regex.h>
28779 #include <tools/le_byteshift.h>
28780
28781 +#include "../../../include/generated/autoconf.h"
28782 +
28783 static void die(char *fmt, ...);
28784
28785 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28786 static Elf32_Ehdr ehdr;
28787 +static Elf32_Phdr *phdr;
28788 static unsigned long reloc_count, reloc_idx;
28789 static unsigned long *relocs;
28790 static unsigned long reloc16_count, reloc16_idx;
28791 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28792 }
28793 }
28794
28795 +static void read_phdrs(FILE *fp)
28796 +{
28797 + unsigned int i;
28798 +
28799 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28800 + if (!phdr) {
28801 + die("Unable to allocate %d program headers\n",
28802 + ehdr.e_phnum);
28803 + }
28804 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28805 + die("Seek to %d failed: %s\n",
28806 + ehdr.e_phoff, strerror(errno));
28807 + }
28808 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28809 + die("Cannot read ELF program headers: %s\n",
28810 + strerror(errno));
28811 + }
28812 + for(i = 0; i < ehdr.e_phnum; i++) {
28813 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28814 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28815 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28816 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28817 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28818 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28819 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28820 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28821 + }
28822 +
28823 +}
28824 +
28825 static void read_shdrs(FILE *fp)
28826 {
28827 - int i;
28828 + unsigned int i;
28829 Elf32_Shdr shdr;
28830
28831 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28832 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28833
28834 static void read_strtabs(FILE *fp)
28835 {
28836 - int i;
28837 + unsigned int i;
28838 for (i = 0; i < ehdr.e_shnum; i++) {
28839 struct section *sec = &secs[i];
28840 if (sec->shdr.sh_type != SHT_STRTAB) {
28841 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28842
28843 static void read_symtabs(FILE *fp)
28844 {
28845 - int i,j;
28846 + unsigned int i,j;
28847 for (i = 0; i < ehdr.e_shnum; i++) {
28848 struct section *sec = &secs[i];
28849 if (sec->shdr.sh_type != SHT_SYMTAB) {
28850 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28851 }
28852
28853
28854 -static void read_relocs(FILE *fp)
28855 +static void read_relocs(FILE *fp, int use_real_mode)
28856 {
28857 - int i,j;
28858 + unsigned int i,j;
28859 + uint32_t base;
28860 +
28861 for (i = 0; i < ehdr.e_shnum; i++) {
28862 struct section *sec = &secs[i];
28863 if (sec->shdr.sh_type != SHT_REL) {
28864 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28865 die("Cannot read symbol table: %s\n",
28866 strerror(errno));
28867 }
28868 + base = 0;
28869 +
28870 +#ifdef CONFIG_X86_32
28871 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28872 + if (phdr[j].p_type != PT_LOAD )
28873 + continue;
28874 + 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)
28875 + continue;
28876 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28877 + break;
28878 + }
28879 +#endif
28880 +
28881 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28882 Elf32_Rel *rel = &sec->reltab[j];
28883 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28884 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28885 rel->r_info = elf32_to_cpu(rel->r_info);
28886 }
28887 }
28888 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28889
28890 static void print_absolute_symbols(void)
28891 {
28892 - int i;
28893 + unsigned int i;
28894 printf("Absolute symbols\n");
28895 printf(" Num: Value Size Type Bind Visibility Name\n");
28896 for (i = 0; i < ehdr.e_shnum; i++) {
28897 struct section *sec = &secs[i];
28898 char *sym_strtab;
28899 - int j;
28900 + unsigned int j;
28901
28902 if (sec->shdr.sh_type != SHT_SYMTAB) {
28903 continue;
28904 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28905
28906 static void print_absolute_relocs(void)
28907 {
28908 - int i, printed = 0;
28909 + unsigned int i, printed = 0;
28910
28911 for (i = 0; i < ehdr.e_shnum; i++) {
28912 struct section *sec = &secs[i];
28913 struct section *sec_applies, *sec_symtab;
28914 char *sym_strtab;
28915 Elf32_Sym *sh_symtab;
28916 - int j;
28917 + unsigned int j;
28918 if (sec->shdr.sh_type != SHT_REL) {
28919 continue;
28920 }
28921 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28922 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28923 int use_real_mode)
28924 {
28925 - int i;
28926 + unsigned int i;
28927 /* Walk through the relocations */
28928 for (i = 0; i < ehdr.e_shnum; i++) {
28929 char *sym_strtab;
28930 Elf32_Sym *sh_symtab;
28931 struct section *sec_applies, *sec_symtab;
28932 - int j;
28933 + unsigned int j;
28934 struct section *sec = &secs[i];
28935
28936 if (sec->shdr.sh_type != SHT_REL) {
28937 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28938 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28939 r_type = ELF32_R_TYPE(rel->r_info);
28940
28941 + if (!use_real_mode) {
28942 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28943 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28944 + continue;
28945 +
28946 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28947 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28948 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28949 + continue;
28950 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28951 + continue;
28952 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28953 + continue;
28954 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28955 + continue;
28956 +#endif
28957 + }
28958 +
28959 shn_abs = sym->st_shndx == SHN_ABS;
28960
28961 switch (r_type) {
28962 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
28963
28964 static void emit_relocs(int as_text, int use_real_mode)
28965 {
28966 - int i;
28967 + unsigned int i;
28968 /* Count how many relocations I have and allocate space for them. */
28969 reloc_count = 0;
28970 walk_relocs(count_reloc, use_real_mode);
28971 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
28972 fname, strerror(errno));
28973 }
28974 read_ehdr(fp);
28975 + read_phdrs(fp);
28976 read_shdrs(fp);
28977 read_strtabs(fp);
28978 read_symtabs(fp);
28979 - read_relocs(fp);
28980 + read_relocs(fp, use_real_mode);
28981 if (show_absolute_syms) {
28982 print_absolute_symbols();
28983 return 0;
28984 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
28985 index fd14be1..e3c79c0 100644
28986 --- a/arch/x86/vdso/Makefile
28987 +++ b/arch/x86/vdso/Makefile
28988 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
28989 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
28990 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
28991
28992 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28993 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28994 GCOV_PROFILE := n
28995
28996 #
28997 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
28998 index 0faad64..39ef157 100644
28999 --- a/arch/x86/vdso/vdso32-setup.c
29000 +++ b/arch/x86/vdso/vdso32-setup.c
29001 @@ -25,6 +25,7 @@
29002 #include <asm/tlbflush.h>
29003 #include <asm/vdso.h>
29004 #include <asm/proto.h>
29005 +#include <asm/mman.h>
29006
29007 enum {
29008 VDSO_DISABLED = 0,
29009 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29010 void enable_sep_cpu(void)
29011 {
29012 int cpu = get_cpu();
29013 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29014 + struct tss_struct *tss = init_tss + cpu;
29015
29016 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29017 put_cpu();
29018 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29019 gate_vma.vm_start = FIXADDR_USER_START;
29020 gate_vma.vm_end = FIXADDR_USER_END;
29021 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29022 - gate_vma.vm_page_prot = __P101;
29023 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29024
29025 return 0;
29026 }
29027 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29028 if (compat)
29029 addr = VDSO_HIGH_BASE;
29030 else {
29031 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29032 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29033 if (IS_ERR_VALUE(addr)) {
29034 ret = addr;
29035 goto up_fail;
29036 }
29037 }
29038
29039 - current->mm->context.vdso = (void *)addr;
29040 + current->mm->context.vdso = addr;
29041
29042 if (compat_uses_vma || !compat) {
29043 /*
29044 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29045 }
29046
29047 current_thread_info()->sysenter_return =
29048 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29049 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29050
29051 up_fail:
29052 if (ret)
29053 - current->mm->context.vdso = NULL;
29054 + current->mm->context.vdso = 0;
29055
29056 up_write(&mm->mmap_sem);
29057
29058 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29059
29060 const char *arch_vma_name(struct vm_area_struct *vma)
29061 {
29062 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29063 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29064 return "[vdso]";
29065 +
29066 +#ifdef CONFIG_PAX_SEGMEXEC
29067 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29068 + return "[vdso]";
29069 +#endif
29070 +
29071 return NULL;
29072 }
29073
29074 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29075 * Check to see if the corresponding task was created in compat vdso
29076 * mode.
29077 */
29078 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29079 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29080 return &gate_vma;
29081 return NULL;
29082 }
29083 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29084 index 00aaf04..4a26505 100644
29085 --- a/arch/x86/vdso/vma.c
29086 +++ b/arch/x86/vdso/vma.c
29087 @@ -16,8 +16,6 @@
29088 #include <asm/vdso.h>
29089 #include <asm/page.h>
29090
29091 -unsigned int __read_mostly vdso_enabled = 1;
29092 -
29093 extern char vdso_start[], vdso_end[];
29094 extern unsigned short vdso_sync_cpuid;
29095
29096 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29097 * unaligned here as a result of stack start randomization.
29098 */
29099 addr = PAGE_ALIGN(addr);
29100 - addr = align_addr(addr, NULL, ALIGN_VDSO);
29101
29102 return addr;
29103 }
29104 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29105 unsigned size)
29106 {
29107 struct mm_struct *mm = current->mm;
29108 - unsigned long addr;
29109 + unsigned long addr = 0;
29110 int ret;
29111
29112 - if (!vdso_enabled)
29113 - return 0;
29114 -
29115 down_write(&mm->mmap_sem);
29116 +
29117 +#ifdef CONFIG_PAX_RANDMMAP
29118 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29119 +#endif
29120 +
29121 addr = vdso_addr(mm->start_stack, size);
29122 + addr = align_addr(addr, NULL, ALIGN_VDSO);
29123 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29124 if (IS_ERR_VALUE(addr)) {
29125 ret = addr;
29126 goto up_fail;
29127 }
29128
29129 - current->mm->context.vdso = (void *)addr;
29130 + mm->context.vdso = addr;
29131
29132 ret = install_special_mapping(mm, addr, size,
29133 VM_READ|VM_EXEC|
29134 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29135 pages);
29136 - if (ret) {
29137 - current->mm->context.vdso = NULL;
29138 - goto up_fail;
29139 - }
29140 + if (ret)
29141 + mm->context.vdso = 0;
29142
29143 up_fail:
29144 up_write(&mm->mmap_sem);
29145 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29146 vdsox32_size);
29147 }
29148 #endif
29149 -
29150 -static __init int vdso_setup(char *s)
29151 -{
29152 - vdso_enabled = simple_strtoul(s, NULL, 0);
29153 - return 0;
29154 -}
29155 -__setup("vdso=", vdso_setup);
29156 diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29157 index 7005ced..530d6eb 100644
29158 --- a/arch/x86/xen/apic.c
29159 +++ b/arch/x86/xen/apic.c
29160 @@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29161
29162 void __init xen_init_apic(void)
29163 {
29164 - x86_io_apic_ops.read = xen_io_apic_read;
29165 + *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29166 }
29167 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29168 index 586d838..9181904 100644
29169 --- a/arch/x86/xen/enlighten.c
29170 +++ b/arch/x86/xen/enlighten.c
29171 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29172
29173 struct shared_info xen_dummy_shared_info;
29174
29175 -void *xen_initial_gdt;
29176 -
29177 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29178 __read_mostly int xen_have_vector_callback;
29179 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29180 @@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29181 {
29182 unsigned long va = dtr->address;
29183 unsigned int size = dtr->size + 1;
29184 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29185 - unsigned long frames[pages];
29186 + unsigned long frames[65536 / PAGE_SIZE];
29187 int f;
29188
29189 /*
29190 @@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29191 {
29192 unsigned long va = dtr->address;
29193 unsigned int size = dtr->size + 1;
29194 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29195 - unsigned long frames[pages];
29196 + unsigned long frames[65536 / PAGE_SIZE];
29197 int f;
29198
29199 /*
29200 @@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29201
29202 static void set_xen_basic_apic_ops(void)
29203 {
29204 - apic->read = xen_apic_read;
29205 - apic->write = xen_apic_write;
29206 - apic->icr_read = xen_apic_icr_read;
29207 - apic->icr_write = xen_apic_icr_write;
29208 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
29209 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29210 - apic->set_apic_id = xen_set_apic_id;
29211 - apic->get_apic_id = xen_get_apic_id;
29212 + *(void **)&apic->read = xen_apic_read;
29213 + *(void **)&apic->write = xen_apic_write;
29214 + *(void **)&apic->icr_read = xen_apic_icr_read;
29215 + *(void **)&apic->icr_write = xen_apic_icr_write;
29216 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29217 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29218 + *(void **)&apic->set_apic_id = xen_set_apic_id;
29219 + *(void **)&apic->get_apic_id = xen_get_apic_id;
29220
29221 #ifdef CONFIG_SMP
29222 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29223 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29224 - apic->send_IPI_mask = xen_send_IPI_mask;
29225 - apic->send_IPI_all = xen_send_IPI_all;
29226 - apic->send_IPI_self = xen_send_IPI_self;
29227 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29228 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29229 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29230 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29231 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29232 #endif
29233 }
29234
29235 @@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29236 #endif
29237 };
29238
29239 -static void xen_reboot(int reason)
29240 +static __noreturn void xen_reboot(int reason)
29241 {
29242 struct sched_shutdown r = { .reason = reason };
29243
29244 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29245 - BUG();
29246 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29247 + BUG();
29248 }
29249
29250 -static void xen_restart(char *msg)
29251 +static __noreturn void xen_restart(char *msg)
29252 {
29253 xen_reboot(SHUTDOWN_reboot);
29254 }
29255
29256 -static void xen_emergency_restart(void)
29257 +static __noreturn void xen_emergency_restart(void)
29258 {
29259 xen_reboot(SHUTDOWN_reboot);
29260 }
29261
29262 -static void xen_machine_halt(void)
29263 +static __noreturn void xen_machine_halt(void)
29264 {
29265 xen_reboot(SHUTDOWN_poweroff);
29266 }
29267
29268 -static void xen_machine_power_off(void)
29269 +static __noreturn void xen_machine_power_off(void)
29270 {
29271 if (pm_power_off)
29272 pm_power_off();
29273 @@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29274 */
29275 static void __init xen_setup_stackprotector(void)
29276 {
29277 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29278 - pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29279 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29280 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29281
29282 setup_stack_canary_segment(0);
29283 switch_to_new_gdt(0);
29284
29285 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29286 - pv_cpu_ops.load_gdt = xen_load_gdt;
29287 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29288 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29289 }
29290
29291 /* First C function to be called on Xen boot */
29292 @@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29293
29294 /* Install Xen paravirt ops */
29295 pv_info = xen_info;
29296 - pv_init_ops = xen_init_ops;
29297 - pv_cpu_ops = xen_cpu_ops;
29298 - pv_apic_ops = xen_apic_ops;
29299 + memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29300 + memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29301 + memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29302
29303 - x86_init.resources.memory_setup = xen_memory_setup;
29304 - x86_init.oem.arch_setup = xen_arch_setup;
29305 - x86_init.oem.banner = xen_banner;
29306 + *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29307 + *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29308 + *(void **)&x86_init.oem.banner = xen_banner;
29309
29310 xen_init_time_ops();
29311
29312 @@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29313 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29314
29315 /* Work out if we support NX */
29316 - x86_configure_nx();
29317 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29318 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29319 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29320 + unsigned l, h;
29321 +
29322 + __supported_pte_mask |= _PAGE_NX;
29323 + rdmsr(MSR_EFER, l, h);
29324 + l |= EFER_NX;
29325 + wrmsr(MSR_EFER, l, h);
29326 + }
29327 +#endif
29328
29329 xen_setup_features();
29330
29331 @@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29332 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29333 }
29334
29335 - machine_ops = xen_machine_ops;
29336 -
29337 - /*
29338 - * The only reliable way to retain the initial address of the
29339 - * percpu gdt_page is to remember it here, so we can go and
29340 - * mark it RW later, when the initial percpu area is freed.
29341 - */
29342 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29343 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29344
29345 xen_smp_init();
29346
29347 @@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29348 add_preferred_console("tty", 0, NULL);
29349 add_preferred_console("hvc", 0, NULL);
29350 if (pci_xen)
29351 - x86_init.pci.arch_init = pci_xen_init;
29352 + *(void **)&x86_init.pci.arch_init = pci_xen_init;
29353 } else {
29354 const struct dom0_vga_console_info *info =
29355 (void *)((char *)xen_start_info +
29356 @@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29357 xen_acpi_sleep_register();
29358
29359 /* Avoid searching for BIOS MP tables */
29360 - x86_init.mpparse.find_smp_config = x86_init_noop;
29361 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29362 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29363 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29364 }
29365 #ifdef CONFIG_PCI
29366 /* PCI BIOS service won't work from a PV guest. */
29367 @@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29368 xen_hvm_smp_init();
29369 register_cpu_notifier(&xen_hvm_cpu_notifier);
29370 xen_unplug_emulated_devices();
29371 - x86_init.irqs.intr_init = xen_init_IRQ;
29372 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29373 xen_hvm_init_time_ops();
29374 xen_hvm_init_mmu_ops();
29375 }
29376 diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29377 index 01a4dc0..3ca0cc9 100644
29378 --- a/arch/x86/xen/irq.c
29379 +++ b/arch/x86/xen/irq.c
29380 @@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29381 void __init xen_init_irq_ops(void)
29382 {
29383 pv_irq_ops = xen_irq_ops;
29384 - x86_init.irqs.intr_init = xen_init_IRQ;
29385 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29386 }
29387 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29388 index dcf5f2d..5f72fe7 100644
29389 --- a/arch/x86/xen/mmu.c
29390 +++ b/arch/x86/xen/mmu.c
29391 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29392 /* L3_k[510] -> level2_kernel_pgt
29393 * L3_i[511] -> level2_fixmap_pgt */
29394 convert_pfn_mfn(level3_kernel_pgt);
29395 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29396 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29397 + convert_pfn_mfn(level3_vmemmap_pgt);
29398
29399 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29400 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29401 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29402 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29403 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29404 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29405 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29406 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29407 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29408 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29409 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29410 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29411 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29412 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29413
29414 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29415 pv_mmu_ops.set_pud = xen_set_pud;
29416 #if PAGETABLE_LEVELS == 4
29417 pv_mmu_ops.set_pgd = xen_set_pgd;
29418 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29419 #endif
29420
29421 /* This will work as long as patching hasn't happened yet
29422 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29423 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29424 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29425 .set_pgd = xen_set_pgd_hyper,
29426 + .set_pgd_batched = xen_set_pgd_hyper,
29427
29428 .alloc_pud = xen_alloc_pmd_init,
29429 .release_pud = xen_release_pmd_init,
29430 @@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29431
29432 void __init xen_init_mmu_ops(void)
29433 {
29434 - x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29435 - x86_init.paging.pagetable_init = xen_pagetable_init;
29436 + *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29437 + *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29438 pv_mmu_ops = xen_mmu_ops;
29439
29440 memset(dummy_mapping, 0xff, PAGE_SIZE);
29441 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29442 index 353c50f..a0b9b0d 100644
29443 --- a/arch/x86/xen/smp.c
29444 +++ b/arch/x86/xen/smp.c
29445 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29446 {
29447 BUG_ON(smp_processor_id() != 0);
29448 native_smp_prepare_boot_cpu();
29449 -
29450 - /* We've switched to the "real" per-cpu gdt, so make sure the
29451 - old memory can be recycled */
29452 - make_lowmem_page_readwrite(xen_initial_gdt);
29453 -
29454 xen_filter_cpu_maps();
29455 xen_setup_vcpu_info_placement();
29456 }
29457 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29458 gdt = get_cpu_gdt_table(cpu);
29459
29460 ctxt->flags = VGCF_IN_KERNEL;
29461 - ctxt->user_regs.ds = __USER_DS;
29462 - ctxt->user_regs.es = __USER_DS;
29463 + ctxt->user_regs.ds = __KERNEL_DS;
29464 + ctxt->user_regs.es = __KERNEL_DS;
29465 ctxt->user_regs.ss = __KERNEL_DS;
29466 #ifdef CONFIG_X86_32
29467 ctxt->user_regs.fs = __KERNEL_PERCPU;
29468 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29469 + savesegment(gs, ctxt->user_regs.gs);
29470 #else
29471 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29472 #endif
29473 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29474 int rc;
29475
29476 per_cpu(current_task, cpu) = idle;
29477 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29478 #ifdef CONFIG_X86_32
29479 irq_ctx_init(cpu);
29480 #else
29481 clear_tsk_thread_flag(idle, TIF_FORK);
29482 - per_cpu(kernel_stack, cpu) =
29483 - (unsigned long)task_stack_page(idle) -
29484 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29485 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29486 #endif
29487 xen_setup_runstate_info(cpu);
29488 xen_setup_timer(cpu);
29489 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29490
29491 void __init xen_smp_init(void)
29492 {
29493 - smp_ops = xen_smp_ops;
29494 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29495 xen_fill_possible_map();
29496 xen_init_spinlocks();
29497 }
29498 @@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29499 {
29500 if (!xen_have_vector_callback)
29501 return;
29502 - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29503 - smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29504 - smp_ops.cpu_up = xen_hvm_cpu_up;
29505 - smp_ops.cpu_die = xen_hvm_cpu_die;
29506 - smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29507 - smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29508 + *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29509 + *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29510 + *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29511 + *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29512 + *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29513 + *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29514 }
29515 diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29516 index 83e866d..ef60385 100644
29517 --- a/arch/x86/xen/spinlock.c
29518 +++ b/arch/x86/xen/spinlock.c
29519 @@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29520 {
29521 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29522
29523 - pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29524 - pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29525 - pv_lock_ops.spin_lock = xen_spin_lock;
29526 - pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29527 - pv_lock_ops.spin_trylock = xen_spin_trylock;
29528 - pv_lock_ops.spin_unlock = xen_spin_unlock;
29529 + *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29530 + *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29531 + *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29532 + *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29533 + *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29534 + *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29535 }
29536
29537 #ifdef CONFIG_XEN_DEBUG_FS
29538 diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29539 index 0296a95..3c51a2d 100644
29540 --- a/arch/x86/xen/time.c
29541 +++ b/arch/x86/xen/time.c
29542 @@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29543
29544 void __init xen_init_time_ops(void)
29545 {
29546 - pv_time_ops = xen_time_ops;
29547 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29548
29549 - x86_init.timers.timer_init = xen_time_init;
29550 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
29551 - x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29552 + *(void **)&x86_init.timers.timer_init = xen_time_init;
29553 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29554 + *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29555
29556 - x86_platform.calibrate_tsc = xen_tsc_khz;
29557 - x86_platform.get_wallclock = xen_get_wallclock;
29558 - x86_platform.set_wallclock = xen_set_wallclock;
29559 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29560 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29561 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29562 }
29563
29564 #ifdef CONFIG_XEN_PVHVM
29565 @@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29566 return;
29567 }
29568
29569 - pv_time_ops = xen_time_ops;
29570 - x86_init.timers.setup_percpu_clockev = xen_time_init;
29571 - x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29572 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29573 + *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29574 + *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29575
29576 - x86_platform.calibrate_tsc = xen_tsc_khz;
29577 - x86_platform.get_wallclock = xen_get_wallclock;
29578 - x86_platform.set_wallclock = xen_set_wallclock;
29579 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29580 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29581 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29582 }
29583 #endif
29584 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29585 index f9643fc..602e8af 100644
29586 --- a/arch/x86/xen/xen-asm_32.S
29587 +++ b/arch/x86/xen/xen-asm_32.S
29588 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29589 ESP_OFFSET=4 # bytes pushed onto stack
29590
29591 /*
29592 - * Store vcpu_info pointer for easy access. Do it this way to
29593 - * avoid having to reload %fs
29594 + * Store vcpu_info pointer for easy access.
29595 */
29596 #ifdef CONFIG_SMP
29597 - GET_THREAD_INFO(%eax)
29598 - movl TI_cpu(%eax), %eax
29599 - movl __per_cpu_offset(,%eax,4), %eax
29600 - mov xen_vcpu(%eax), %eax
29601 + push %fs
29602 + mov $(__KERNEL_PERCPU), %eax
29603 + mov %eax, %fs
29604 + mov PER_CPU_VAR(xen_vcpu), %eax
29605 + pop %fs
29606 #else
29607 movl xen_vcpu, %eax
29608 #endif
29609 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29610 index 7faed58..ba4427c 100644
29611 --- a/arch/x86/xen/xen-head.S
29612 +++ b/arch/x86/xen/xen-head.S
29613 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29614 #ifdef CONFIG_X86_32
29615 mov %esi,xen_start_info
29616 mov $init_thread_union+THREAD_SIZE,%esp
29617 +#ifdef CONFIG_SMP
29618 + movl $cpu_gdt_table,%edi
29619 + movl $__per_cpu_load,%eax
29620 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29621 + rorl $16,%eax
29622 + movb %al,__KERNEL_PERCPU + 4(%edi)
29623 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29624 + movl $__per_cpu_end - 1,%eax
29625 + subl $__per_cpu_start,%eax
29626 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29627 +#endif
29628 #else
29629 mov %rsi,xen_start_info
29630 mov $init_thread_union+THREAD_SIZE,%rsp
29631 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29632 index a95b417..b6dbd0b 100644
29633 --- a/arch/x86/xen/xen-ops.h
29634 +++ b/arch/x86/xen/xen-ops.h
29635 @@ -10,8 +10,6 @@
29636 extern const char xen_hypervisor_callback[];
29637 extern const char xen_failsafe_callback[];
29638
29639 -extern void *xen_initial_gdt;
29640 -
29641 struct trap_info;
29642 void xen_copy_trap_info(struct trap_info *traps);
29643
29644 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29645 index 525bd3d..ef888b1 100644
29646 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29647 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29648 @@ -119,9 +119,9 @@
29649 ----------------------------------------------------------------------*/
29650
29651 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29652 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29653 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29654 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29655 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29656
29657 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29658 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29659 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29660 index 2f33760..835e50a 100644
29661 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29662 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29663 @@ -11,6 +11,7 @@
29664 #ifndef _XTENSA_CORE_H
29665 #define _XTENSA_CORE_H
29666
29667 +#include <linux/const.h>
29668
29669 /****************************************************************************
29670 Parameters Useful for Any Code, USER or PRIVILEGED
29671 @@ -112,9 +113,9 @@
29672 ----------------------------------------------------------------------*/
29673
29674 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29675 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29676 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29677 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29678 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29679
29680 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29681 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29682 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29683 index af00795..2bb8105 100644
29684 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29685 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29686 @@ -11,6 +11,7 @@
29687 #ifndef _XTENSA_CORE_CONFIGURATION_H
29688 #define _XTENSA_CORE_CONFIGURATION_H
29689
29690 +#include <linux/const.h>
29691
29692 /****************************************************************************
29693 Parameters Useful for Any Code, USER or PRIVILEGED
29694 @@ -118,9 +119,9 @@
29695 ----------------------------------------------------------------------*/
29696
29697 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29698 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29699 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29700 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29701 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29702
29703 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29704 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29705 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29706 index 58916af..9cb880b 100644
29707 --- a/block/blk-iopoll.c
29708 +++ b/block/blk-iopoll.c
29709 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29710 }
29711 EXPORT_SYMBOL(blk_iopoll_complete);
29712
29713 -static void blk_iopoll_softirq(struct softirq_action *h)
29714 +static void blk_iopoll_softirq(void)
29715 {
29716 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29717 int rearm = 0, budget = blk_iopoll_budget;
29718 diff --git a/block/blk-map.c b/block/blk-map.c
29719 index 623e1cd..ca1e109 100644
29720 --- a/block/blk-map.c
29721 +++ b/block/blk-map.c
29722 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29723 if (!len || !kbuf)
29724 return -EINVAL;
29725
29726 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29727 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29728 if (do_copy)
29729 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29730 else
29731 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29732 index 467c8de..4bddc6d 100644
29733 --- a/block/blk-softirq.c
29734 +++ b/block/blk-softirq.c
29735 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29736 * Softirq action handler - move entries to local list and loop over them
29737 * while passing them to the queue registered handler.
29738 */
29739 -static void blk_done_softirq(struct softirq_action *h)
29740 +static void blk_done_softirq(void)
29741 {
29742 struct list_head *cpu_list, local_list;
29743
29744 diff --git a/block/bsg.c b/block/bsg.c
29745 index ff64ae3..593560c 100644
29746 --- a/block/bsg.c
29747 +++ b/block/bsg.c
29748 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29749 struct sg_io_v4 *hdr, struct bsg_device *bd,
29750 fmode_t has_write_perm)
29751 {
29752 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29753 + unsigned char *cmdptr;
29754 +
29755 if (hdr->request_len > BLK_MAX_CDB) {
29756 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29757 if (!rq->cmd)
29758 return -ENOMEM;
29759 - }
29760 + cmdptr = rq->cmd;
29761 + } else
29762 + cmdptr = tmpcmd;
29763
29764 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29765 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29766 hdr->request_len))
29767 return -EFAULT;
29768
29769 + if (cmdptr != rq->cmd)
29770 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29771 +
29772 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29773 if (blk_verify_command(rq->cmd, has_write_perm))
29774 return -EPERM;
29775 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29776 index 7c668c8..db3521c 100644
29777 --- a/block/compat_ioctl.c
29778 +++ b/block/compat_ioctl.c
29779 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29780 err |= __get_user(f->spec1, &uf->spec1);
29781 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29782 err |= __get_user(name, &uf->name);
29783 - f->name = compat_ptr(name);
29784 + f->name = (void __force_kernel *)compat_ptr(name);
29785 if (err) {
29786 err = -EFAULT;
29787 goto out;
29788 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29789 index 6296b40..417c00f 100644
29790 --- a/block/partitions/efi.c
29791 +++ b/block/partitions/efi.c
29792 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29793 if (!gpt)
29794 return NULL;
29795
29796 + if (!le32_to_cpu(gpt->num_partition_entries))
29797 + return NULL;
29798 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29799 + if (!pte)
29800 + return NULL;
29801 +
29802 count = le32_to_cpu(gpt->num_partition_entries) *
29803 le32_to_cpu(gpt->sizeof_partition_entry);
29804 - if (!count)
29805 - return NULL;
29806 - pte = kzalloc(count, GFP_KERNEL);
29807 - if (!pte)
29808 - return NULL;
29809 -
29810 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29811 (u8 *) pte,
29812 count) < count) {
29813 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29814 index 9a87daa..fb17486 100644
29815 --- a/block/scsi_ioctl.c
29816 +++ b/block/scsi_ioctl.c
29817 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29818 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29819 struct sg_io_hdr *hdr, fmode_t mode)
29820 {
29821 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29822 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29823 + unsigned char *cmdptr;
29824 +
29825 + if (rq->cmd != rq->__cmd)
29826 + cmdptr = rq->cmd;
29827 + else
29828 + cmdptr = tmpcmd;
29829 +
29830 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29831 return -EFAULT;
29832 +
29833 + if (cmdptr != rq->cmd)
29834 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29835 +
29836 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29837 return -EPERM;
29838
29839 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29840 int err;
29841 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29842 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29843 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29844 + unsigned char *cmdptr;
29845
29846 if (!sic)
29847 return -EINVAL;
29848 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29849 */
29850 err = -EFAULT;
29851 rq->cmd_len = cmdlen;
29852 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29853 +
29854 + if (rq->cmd != rq->__cmd)
29855 + cmdptr = rq->cmd;
29856 + else
29857 + cmdptr = tmpcmd;
29858 +
29859 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29860 goto error;
29861
29862 + if (rq->cmd != cmdptr)
29863 + memcpy(rq->cmd, cmdptr, cmdlen);
29864 +
29865 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29866 goto error;
29867
29868 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29869 index 7bdd61b..afec999 100644
29870 --- a/crypto/cryptd.c
29871 +++ b/crypto/cryptd.c
29872 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29873
29874 struct cryptd_blkcipher_request_ctx {
29875 crypto_completion_t complete;
29876 -};
29877 +} __no_const;
29878
29879 struct cryptd_hash_ctx {
29880 struct crypto_shash *child;
29881 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29882
29883 struct cryptd_aead_request_ctx {
29884 crypto_completion_t complete;
29885 -};
29886 +} __no_const;
29887
29888 static void cryptd_queue_worker(struct work_struct *work);
29889
29890 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29891 index e6defd8..c26a225 100644
29892 --- a/drivers/acpi/apei/cper.c
29893 +++ b/drivers/acpi/apei/cper.c
29894 @@ -38,12 +38,12 @@
29895 */
29896 u64 cper_next_record_id(void)
29897 {
29898 - static atomic64_t seq;
29899 + static atomic64_unchecked_t seq;
29900
29901 - if (!atomic64_read(&seq))
29902 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29903 + if (!atomic64_read_unchecked(&seq))
29904 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29905
29906 - return atomic64_inc_return(&seq);
29907 + return atomic64_inc_return_unchecked(&seq);
29908 }
29909 EXPORT_SYMBOL_GPL(cper_next_record_id);
29910
29911 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29912 index 7586544..636a2f0 100644
29913 --- a/drivers/acpi/ec_sys.c
29914 +++ b/drivers/acpi/ec_sys.c
29915 @@ -12,6 +12,7 @@
29916 #include <linux/acpi.h>
29917 #include <linux/debugfs.h>
29918 #include <linux/module.h>
29919 +#include <linux/uaccess.h>
29920 #include "internal.h"
29921
29922 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29923 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29924 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29925 */
29926 unsigned int size = EC_SPACE_SIZE;
29927 - u8 *data = (u8 *) buf;
29928 + u8 data;
29929 loff_t init_off = *off;
29930 int err = 0;
29931
29932 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29933 size = count;
29934
29935 while (size) {
29936 - err = ec_read(*off, &data[*off - init_off]);
29937 + err = ec_read(*off, &data);
29938 if (err)
29939 return err;
29940 + if (put_user(data, &buf[*off - init_off]))
29941 + return -EFAULT;
29942 *off += 1;
29943 size--;
29944 }
29945 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29946
29947 unsigned int size = count;
29948 loff_t init_off = *off;
29949 - u8 *data = (u8 *) buf;
29950 int err = 0;
29951
29952 if (*off >= EC_SPACE_SIZE)
29953 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29954 }
29955
29956 while (size) {
29957 - u8 byte_write = data[*off - init_off];
29958 + u8 byte_write;
29959 + if (get_user(byte_write, &buf[*off - init_off]))
29960 + return -EFAULT;
29961 err = ec_write(*off, byte_write);
29962 if (err)
29963 return err;
29964 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
29965 index 27adb09..1ed412d 100644
29966 --- a/drivers/acpi/proc.c
29967 +++ b/drivers/acpi/proc.c
29968 @@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
29969 size_t count, loff_t * ppos)
29970 {
29971 struct list_head *node, *next;
29972 - char strbuf[5];
29973 - char str[5] = "";
29974 - unsigned int len = count;
29975 + char strbuf[5] = {0};
29976
29977 - if (len > 4)
29978 - len = 4;
29979 - if (len < 0)
29980 + if (count > 4)
29981 + count = 4;
29982 + if (copy_from_user(strbuf, buffer, count))
29983 return -EFAULT;
29984 -
29985 - if (copy_from_user(strbuf, buffer, len))
29986 - return -EFAULT;
29987 - strbuf[len] = '\0';
29988 - sscanf(strbuf, "%s", str);
29989 + strbuf[count] = '\0';
29990
29991 mutex_lock(&acpi_device_lock);
29992 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
29993 @@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
29994 if (!dev->wakeup.flags.valid)
29995 continue;
29996
29997 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
29998 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
29999 if (device_can_wakeup(&dev->dev)) {
30000 bool enable = !device_may_wakeup(&dev->dev);
30001 device_set_wakeup_enable(&dev->dev, enable);
30002 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30003 index bd4e5dc..0497b66 100644
30004 --- a/drivers/acpi/processor_driver.c
30005 +++ b/drivers/acpi/processor_driver.c
30006 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30007 return 0;
30008 #endif
30009
30010 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30011 + BUG_ON(pr->id >= nr_cpu_ids);
30012
30013 /*
30014 * Buggy BIOS check
30015 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30016 index c8ac4fe..631818e 100644
30017 --- a/drivers/ata/libata-core.c
30018 +++ b/drivers/ata/libata-core.c
30019 @@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30020 struct ata_port *ap;
30021 unsigned int tag;
30022
30023 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30024 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30025 ap = qc->ap;
30026
30027 qc->flags = 0;
30028 @@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30029 struct ata_port *ap;
30030 struct ata_link *link;
30031
30032 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30033 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30034 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30035 ap = qc->ap;
30036 link = qc->dev->link;
30037 @@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30038 return;
30039
30040 spin_lock(&lock);
30041 + pax_open_kernel();
30042
30043 for (cur = ops->inherits; cur; cur = cur->inherits) {
30044 void **inherit = (void **)cur;
30045 @@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30046 if (IS_ERR(*pp))
30047 *pp = NULL;
30048
30049 - ops->inherits = NULL;
30050 + *(struct ata_port_operations **)&ops->inherits = NULL;
30051
30052 + pax_close_kernel();
30053 spin_unlock(&lock);
30054 }
30055
30056 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30057 index 371fd2c..0836c78 100644
30058 --- a/drivers/ata/pata_arasan_cf.c
30059 +++ b/drivers/ata/pata_arasan_cf.c
30060 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30061 /* Handle platform specific quirks */
30062 if (pdata->quirk) {
30063 if (pdata->quirk & CF_BROKEN_PIO) {
30064 - ap->ops->set_piomode = NULL;
30065 + pax_open_kernel();
30066 + *(void **)&ap->ops->set_piomode = NULL;
30067 + pax_close_kernel();
30068 ap->pio_mask = 0;
30069 }
30070 if (pdata->quirk & CF_BROKEN_MWDMA)
30071 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30072 index f9b983a..887b9d8 100644
30073 --- a/drivers/atm/adummy.c
30074 +++ b/drivers/atm/adummy.c
30075 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30076 vcc->pop(vcc, skb);
30077 else
30078 dev_kfree_skb_any(skb);
30079 - atomic_inc(&vcc->stats->tx);
30080 + atomic_inc_unchecked(&vcc->stats->tx);
30081
30082 return 0;
30083 }
30084 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30085 index ff7bb8a..568fc0b 100644
30086 --- a/drivers/atm/ambassador.c
30087 +++ b/drivers/atm/ambassador.c
30088 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30089 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30090
30091 // VC layer stats
30092 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30093 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30094
30095 // free the descriptor
30096 kfree (tx_descr);
30097 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30098 dump_skb ("<<<", vc, skb);
30099
30100 // VC layer stats
30101 - atomic_inc(&atm_vcc->stats->rx);
30102 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30103 __net_timestamp(skb);
30104 // end of our responsibility
30105 atm_vcc->push (atm_vcc, skb);
30106 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30107 } else {
30108 PRINTK (KERN_INFO, "dropped over-size frame");
30109 // should we count this?
30110 - atomic_inc(&atm_vcc->stats->rx_drop);
30111 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30112 }
30113
30114 } else {
30115 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30116 }
30117
30118 if (check_area (skb->data, skb->len)) {
30119 - atomic_inc(&atm_vcc->stats->tx_err);
30120 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30121 return -ENOMEM; // ?
30122 }
30123
30124 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30125 index b22d71c..d6e1049 100644
30126 --- a/drivers/atm/atmtcp.c
30127 +++ b/drivers/atm/atmtcp.c
30128 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30129 if (vcc->pop) vcc->pop(vcc,skb);
30130 else dev_kfree_skb(skb);
30131 if (dev_data) return 0;
30132 - atomic_inc(&vcc->stats->tx_err);
30133 + atomic_inc_unchecked(&vcc->stats->tx_err);
30134 return -ENOLINK;
30135 }
30136 size = skb->len+sizeof(struct atmtcp_hdr);
30137 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30138 if (!new_skb) {
30139 if (vcc->pop) vcc->pop(vcc,skb);
30140 else dev_kfree_skb(skb);
30141 - atomic_inc(&vcc->stats->tx_err);
30142 + atomic_inc_unchecked(&vcc->stats->tx_err);
30143 return -ENOBUFS;
30144 }
30145 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30146 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30147 if (vcc->pop) vcc->pop(vcc,skb);
30148 else dev_kfree_skb(skb);
30149 out_vcc->push(out_vcc,new_skb);
30150 - atomic_inc(&vcc->stats->tx);
30151 - atomic_inc(&out_vcc->stats->rx);
30152 + atomic_inc_unchecked(&vcc->stats->tx);
30153 + atomic_inc_unchecked(&out_vcc->stats->rx);
30154 return 0;
30155 }
30156
30157 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30158 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30159 read_unlock(&vcc_sklist_lock);
30160 if (!out_vcc) {
30161 - atomic_inc(&vcc->stats->tx_err);
30162 + atomic_inc_unchecked(&vcc->stats->tx_err);
30163 goto done;
30164 }
30165 skb_pull(skb,sizeof(struct atmtcp_hdr));
30166 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30167 __net_timestamp(new_skb);
30168 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30169 out_vcc->push(out_vcc,new_skb);
30170 - atomic_inc(&vcc->stats->tx);
30171 - atomic_inc(&out_vcc->stats->rx);
30172 + atomic_inc_unchecked(&vcc->stats->tx);
30173 + atomic_inc_unchecked(&out_vcc->stats->rx);
30174 done:
30175 if (vcc->pop) vcc->pop(vcc,skb);
30176 else dev_kfree_skb(skb);
30177 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30178 index 81e44f7..498ea36 100644
30179 --- a/drivers/atm/eni.c
30180 +++ b/drivers/atm/eni.c
30181 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30182 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30183 vcc->dev->number);
30184 length = 0;
30185 - atomic_inc(&vcc->stats->rx_err);
30186 + atomic_inc_unchecked(&vcc->stats->rx_err);
30187 }
30188 else {
30189 length = ATM_CELL_SIZE-1; /* no HEC */
30190 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30191 size);
30192 }
30193 eff = length = 0;
30194 - atomic_inc(&vcc->stats->rx_err);
30195 + atomic_inc_unchecked(&vcc->stats->rx_err);
30196 }
30197 else {
30198 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30199 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30200 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30201 vcc->dev->number,vcc->vci,length,size << 2,descr);
30202 length = eff = 0;
30203 - atomic_inc(&vcc->stats->rx_err);
30204 + atomic_inc_unchecked(&vcc->stats->rx_err);
30205 }
30206 }
30207 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30208 @@ -767,7 +767,7 @@ rx_dequeued++;
30209 vcc->push(vcc,skb);
30210 pushed++;
30211 }
30212 - atomic_inc(&vcc->stats->rx);
30213 + atomic_inc_unchecked(&vcc->stats->rx);
30214 }
30215 wake_up(&eni_dev->rx_wait);
30216 }
30217 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30218 PCI_DMA_TODEVICE);
30219 if (vcc->pop) vcc->pop(vcc,skb);
30220 else dev_kfree_skb_irq(skb);
30221 - atomic_inc(&vcc->stats->tx);
30222 + atomic_inc_unchecked(&vcc->stats->tx);
30223 wake_up(&eni_dev->tx_wait);
30224 dma_complete++;
30225 }
30226 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30227 index 86fed1b..6dc4721 100644
30228 --- a/drivers/atm/firestream.c
30229 +++ b/drivers/atm/firestream.c
30230 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30231 }
30232 }
30233
30234 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30235 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30236
30237 fs_dprintk (FS_DEBUG_TXMEM, "i");
30238 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30239 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30240 #endif
30241 skb_put (skb, qe->p1 & 0xffff);
30242 ATM_SKB(skb)->vcc = atm_vcc;
30243 - atomic_inc(&atm_vcc->stats->rx);
30244 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30245 __net_timestamp(skb);
30246 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30247 atm_vcc->push (atm_vcc, skb);
30248 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30249 kfree (pe);
30250 }
30251 if (atm_vcc)
30252 - atomic_inc(&atm_vcc->stats->rx_drop);
30253 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30254 break;
30255 case 0x1f: /* Reassembly abort: no buffers. */
30256 /* Silently increment error counter. */
30257 if (atm_vcc)
30258 - atomic_inc(&atm_vcc->stats->rx_drop);
30259 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30260 break;
30261 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30262 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30263 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30264 index 361f5ae..7fc552d 100644
30265 --- a/drivers/atm/fore200e.c
30266 +++ b/drivers/atm/fore200e.c
30267 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30268 #endif
30269 /* check error condition */
30270 if (*entry->status & STATUS_ERROR)
30271 - atomic_inc(&vcc->stats->tx_err);
30272 + atomic_inc_unchecked(&vcc->stats->tx_err);
30273 else
30274 - atomic_inc(&vcc->stats->tx);
30275 + atomic_inc_unchecked(&vcc->stats->tx);
30276 }
30277 }
30278
30279 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30280 if (skb == NULL) {
30281 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30282
30283 - atomic_inc(&vcc->stats->rx_drop);
30284 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30285 return -ENOMEM;
30286 }
30287
30288 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30289
30290 dev_kfree_skb_any(skb);
30291
30292 - atomic_inc(&vcc->stats->rx_drop);
30293 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30294 return -ENOMEM;
30295 }
30296
30297 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30298
30299 vcc->push(vcc, skb);
30300 - atomic_inc(&vcc->stats->rx);
30301 + atomic_inc_unchecked(&vcc->stats->rx);
30302
30303 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30304
30305 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30306 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30307 fore200e->atm_dev->number,
30308 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30309 - atomic_inc(&vcc->stats->rx_err);
30310 + atomic_inc_unchecked(&vcc->stats->rx_err);
30311 }
30312 }
30313
30314 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30315 goto retry_here;
30316 }
30317
30318 - atomic_inc(&vcc->stats->tx_err);
30319 + atomic_inc_unchecked(&vcc->stats->tx_err);
30320
30321 fore200e->tx_sat++;
30322 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30323 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30324 index b182c2f..1c6fa8a 100644
30325 --- a/drivers/atm/he.c
30326 +++ b/drivers/atm/he.c
30327 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30328
30329 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30330 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30331 - atomic_inc(&vcc->stats->rx_drop);
30332 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30333 goto return_host_buffers;
30334 }
30335
30336 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30337 RBRQ_LEN_ERR(he_dev->rbrq_head)
30338 ? "LEN_ERR" : "",
30339 vcc->vpi, vcc->vci);
30340 - atomic_inc(&vcc->stats->rx_err);
30341 + atomic_inc_unchecked(&vcc->stats->rx_err);
30342 goto return_host_buffers;
30343 }
30344
30345 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30346 vcc->push(vcc, skb);
30347 spin_lock(&he_dev->global_lock);
30348
30349 - atomic_inc(&vcc->stats->rx);
30350 + atomic_inc_unchecked(&vcc->stats->rx);
30351
30352 return_host_buffers:
30353 ++pdus_assembled;
30354 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30355 tpd->vcc->pop(tpd->vcc, tpd->skb);
30356 else
30357 dev_kfree_skb_any(tpd->skb);
30358 - atomic_inc(&tpd->vcc->stats->tx_err);
30359 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30360 }
30361 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30362 return;
30363 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30364 vcc->pop(vcc, skb);
30365 else
30366 dev_kfree_skb_any(skb);
30367 - atomic_inc(&vcc->stats->tx_err);
30368 + atomic_inc_unchecked(&vcc->stats->tx_err);
30369 return -EINVAL;
30370 }
30371
30372 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30373 vcc->pop(vcc, skb);
30374 else
30375 dev_kfree_skb_any(skb);
30376 - atomic_inc(&vcc->stats->tx_err);
30377 + atomic_inc_unchecked(&vcc->stats->tx_err);
30378 return -EINVAL;
30379 }
30380 #endif
30381 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30382 vcc->pop(vcc, skb);
30383 else
30384 dev_kfree_skb_any(skb);
30385 - atomic_inc(&vcc->stats->tx_err);
30386 + atomic_inc_unchecked(&vcc->stats->tx_err);
30387 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30388 return -ENOMEM;
30389 }
30390 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30391 vcc->pop(vcc, skb);
30392 else
30393 dev_kfree_skb_any(skb);
30394 - atomic_inc(&vcc->stats->tx_err);
30395 + atomic_inc_unchecked(&vcc->stats->tx_err);
30396 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30397 return -ENOMEM;
30398 }
30399 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30400 __enqueue_tpd(he_dev, tpd, cid);
30401 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30402
30403 - atomic_inc(&vcc->stats->tx);
30404 + atomic_inc_unchecked(&vcc->stats->tx);
30405
30406 return 0;
30407 }
30408 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30409 index 7d01c2a..4e3ac01 100644
30410 --- a/drivers/atm/horizon.c
30411 +++ b/drivers/atm/horizon.c
30412 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30413 {
30414 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30415 // VC layer stats
30416 - atomic_inc(&vcc->stats->rx);
30417 + atomic_inc_unchecked(&vcc->stats->rx);
30418 __net_timestamp(skb);
30419 // end of our responsibility
30420 vcc->push (vcc, skb);
30421 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30422 dev->tx_iovec = NULL;
30423
30424 // VC layer stats
30425 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30426 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30427
30428 // free the skb
30429 hrz_kfree_skb (skb);
30430 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30431 index 8974bd2..b856f85 100644
30432 --- a/drivers/atm/idt77252.c
30433 +++ b/drivers/atm/idt77252.c
30434 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30435 else
30436 dev_kfree_skb(skb);
30437
30438 - atomic_inc(&vcc->stats->tx);
30439 + atomic_inc_unchecked(&vcc->stats->tx);
30440 }
30441
30442 atomic_dec(&scq->used);
30443 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30444 if ((sb = dev_alloc_skb(64)) == NULL) {
30445 printk("%s: Can't allocate buffers for aal0.\n",
30446 card->name);
30447 - atomic_add(i, &vcc->stats->rx_drop);
30448 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30449 break;
30450 }
30451 if (!atm_charge(vcc, sb->truesize)) {
30452 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30453 card->name);
30454 - atomic_add(i - 1, &vcc->stats->rx_drop);
30455 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30456 dev_kfree_skb(sb);
30457 break;
30458 }
30459 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30460 ATM_SKB(sb)->vcc = vcc;
30461 __net_timestamp(sb);
30462 vcc->push(vcc, sb);
30463 - atomic_inc(&vcc->stats->rx);
30464 + atomic_inc_unchecked(&vcc->stats->rx);
30465
30466 cell += ATM_CELL_PAYLOAD;
30467 }
30468 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30469 "(CDC: %08x)\n",
30470 card->name, len, rpp->len, readl(SAR_REG_CDC));
30471 recycle_rx_pool_skb(card, rpp);
30472 - atomic_inc(&vcc->stats->rx_err);
30473 + atomic_inc_unchecked(&vcc->stats->rx_err);
30474 return;
30475 }
30476 if (stat & SAR_RSQE_CRC) {
30477 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30478 recycle_rx_pool_skb(card, rpp);
30479 - atomic_inc(&vcc->stats->rx_err);
30480 + atomic_inc_unchecked(&vcc->stats->rx_err);
30481 return;
30482 }
30483 if (skb_queue_len(&rpp->queue) > 1) {
30484 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30485 RXPRINTK("%s: Can't alloc RX skb.\n",
30486 card->name);
30487 recycle_rx_pool_skb(card, rpp);
30488 - atomic_inc(&vcc->stats->rx_err);
30489 + atomic_inc_unchecked(&vcc->stats->rx_err);
30490 return;
30491 }
30492 if (!atm_charge(vcc, skb->truesize)) {
30493 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30494 __net_timestamp(skb);
30495
30496 vcc->push(vcc, skb);
30497 - atomic_inc(&vcc->stats->rx);
30498 + atomic_inc_unchecked(&vcc->stats->rx);
30499
30500 return;
30501 }
30502 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30503 __net_timestamp(skb);
30504
30505 vcc->push(vcc, skb);
30506 - atomic_inc(&vcc->stats->rx);
30507 + atomic_inc_unchecked(&vcc->stats->rx);
30508
30509 if (skb->truesize > SAR_FB_SIZE_3)
30510 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30511 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30512 if (vcc->qos.aal != ATM_AAL0) {
30513 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30514 card->name, vpi, vci);
30515 - atomic_inc(&vcc->stats->rx_drop);
30516 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30517 goto drop;
30518 }
30519
30520 if ((sb = dev_alloc_skb(64)) == NULL) {
30521 printk("%s: Can't allocate buffers for AAL0.\n",
30522 card->name);
30523 - atomic_inc(&vcc->stats->rx_err);
30524 + atomic_inc_unchecked(&vcc->stats->rx_err);
30525 goto drop;
30526 }
30527
30528 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30529 ATM_SKB(sb)->vcc = vcc;
30530 __net_timestamp(sb);
30531 vcc->push(vcc, sb);
30532 - atomic_inc(&vcc->stats->rx);
30533 + atomic_inc_unchecked(&vcc->stats->rx);
30534
30535 drop:
30536 skb_pull(queue, 64);
30537 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30538
30539 if (vc == NULL) {
30540 printk("%s: NULL connection in send().\n", card->name);
30541 - atomic_inc(&vcc->stats->tx_err);
30542 + atomic_inc_unchecked(&vcc->stats->tx_err);
30543 dev_kfree_skb(skb);
30544 return -EINVAL;
30545 }
30546 if (!test_bit(VCF_TX, &vc->flags)) {
30547 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30548 - atomic_inc(&vcc->stats->tx_err);
30549 + atomic_inc_unchecked(&vcc->stats->tx_err);
30550 dev_kfree_skb(skb);
30551 return -EINVAL;
30552 }
30553 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30554 break;
30555 default:
30556 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30557 - atomic_inc(&vcc->stats->tx_err);
30558 + atomic_inc_unchecked(&vcc->stats->tx_err);
30559 dev_kfree_skb(skb);
30560 return -EINVAL;
30561 }
30562
30563 if (skb_shinfo(skb)->nr_frags != 0) {
30564 printk("%s: No scatter-gather yet.\n", card->name);
30565 - atomic_inc(&vcc->stats->tx_err);
30566 + atomic_inc_unchecked(&vcc->stats->tx_err);
30567 dev_kfree_skb(skb);
30568 return -EINVAL;
30569 }
30570 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30571
30572 err = queue_skb(card, vc, skb, oam);
30573 if (err) {
30574 - atomic_inc(&vcc->stats->tx_err);
30575 + atomic_inc_unchecked(&vcc->stats->tx_err);
30576 dev_kfree_skb(skb);
30577 return err;
30578 }
30579 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30580 skb = dev_alloc_skb(64);
30581 if (!skb) {
30582 printk("%s: Out of memory in send_oam().\n", card->name);
30583 - atomic_inc(&vcc->stats->tx_err);
30584 + atomic_inc_unchecked(&vcc->stats->tx_err);
30585 return -ENOMEM;
30586 }
30587 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30588 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30589 index 96cce6d..62c3ec5 100644
30590 --- a/drivers/atm/iphase.c
30591 +++ b/drivers/atm/iphase.c
30592 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30593 status = (u_short) (buf_desc_ptr->desc_mode);
30594 if (status & (RX_CER | RX_PTE | RX_OFL))
30595 {
30596 - atomic_inc(&vcc->stats->rx_err);
30597 + atomic_inc_unchecked(&vcc->stats->rx_err);
30598 IF_ERR(printk("IA: bad packet, dropping it");)
30599 if (status & RX_CER) {
30600 IF_ERR(printk(" cause: packet CRC error\n");)
30601 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30602 len = dma_addr - buf_addr;
30603 if (len > iadev->rx_buf_sz) {
30604 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30605 - atomic_inc(&vcc->stats->rx_err);
30606 + atomic_inc_unchecked(&vcc->stats->rx_err);
30607 goto out_free_desc;
30608 }
30609
30610 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30611 ia_vcc = INPH_IA_VCC(vcc);
30612 if (ia_vcc == NULL)
30613 {
30614 - atomic_inc(&vcc->stats->rx_err);
30615 + atomic_inc_unchecked(&vcc->stats->rx_err);
30616 atm_return(vcc, skb->truesize);
30617 dev_kfree_skb_any(skb);
30618 goto INCR_DLE;
30619 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30620 if ((length > iadev->rx_buf_sz) || (length >
30621 (skb->len - sizeof(struct cpcs_trailer))))
30622 {
30623 - atomic_inc(&vcc->stats->rx_err);
30624 + atomic_inc_unchecked(&vcc->stats->rx_err);
30625 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30626 length, skb->len);)
30627 atm_return(vcc, skb->truesize);
30628 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30629
30630 IF_RX(printk("rx_dle_intr: skb push");)
30631 vcc->push(vcc,skb);
30632 - atomic_inc(&vcc->stats->rx);
30633 + atomic_inc_unchecked(&vcc->stats->rx);
30634 iadev->rx_pkt_cnt++;
30635 }
30636 INCR_DLE:
30637 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30638 {
30639 struct k_sonet_stats *stats;
30640 stats = &PRIV(_ia_dev[board])->sonet_stats;
30641 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30642 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30643 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30644 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30645 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30646 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30647 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30648 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30649 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30650 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30651 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30652 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30653 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30654 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30655 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30656 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30657 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30658 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30659 }
30660 ia_cmds.status = 0;
30661 break;
30662 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30663 if ((desc == 0) || (desc > iadev->num_tx_desc))
30664 {
30665 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30666 - atomic_inc(&vcc->stats->tx);
30667 + atomic_inc_unchecked(&vcc->stats->tx);
30668 if (vcc->pop)
30669 vcc->pop(vcc, skb);
30670 else
30671 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30672 ATM_DESC(skb) = vcc->vci;
30673 skb_queue_tail(&iadev->tx_dma_q, skb);
30674
30675 - atomic_inc(&vcc->stats->tx);
30676 + atomic_inc_unchecked(&vcc->stats->tx);
30677 iadev->tx_pkt_cnt++;
30678 /* Increment transaction counter */
30679 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30680
30681 #if 0
30682 /* add flow control logic */
30683 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30684 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30685 if (iavcc->vc_desc_cnt > 10) {
30686 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30687 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30688 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30689 index 68c7588..7036683 100644
30690 --- a/drivers/atm/lanai.c
30691 +++ b/drivers/atm/lanai.c
30692 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30693 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30694 lanai_endtx(lanai, lvcc);
30695 lanai_free_skb(lvcc->tx.atmvcc, skb);
30696 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30697 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30698 }
30699
30700 /* Try to fill the buffer - don't call unless there is backlog */
30701 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30702 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30703 __net_timestamp(skb);
30704 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30705 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30706 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30707 out:
30708 lvcc->rx.buf.ptr = end;
30709 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30710 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30711 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30712 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30713 lanai->stats.service_rxnotaal5++;
30714 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30715 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30716 return 0;
30717 }
30718 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30719 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30720 int bytes;
30721 read_unlock(&vcc_sklist_lock);
30722 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30723 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30724 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30725 lvcc->stats.x.aal5.service_trash++;
30726 bytes = (SERVICE_GET_END(s) * 16) -
30727 (((unsigned long) lvcc->rx.buf.ptr) -
30728 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30729 }
30730 if (s & SERVICE_STREAM) {
30731 read_unlock(&vcc_sklist_lock);
30732 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30733 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30734 lvcc->stats.x.aal5.service_stream++;
30735 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30736 "PDU on VCI %d!\n", lanai->number, vci);
30737 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30738 return 0;
30739 }
30740 DPRINTK("got rx crc error on vci %d\n", vci);
30741 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30742 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30743 lvcc->stats.x.aal5.service_rxcrc++;
30744 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30745 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30746 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30747 index 1c70c45..300718d 100644
30748 --- a/drivers/atm/nicstar.c
30749 +++ b/drivers/atm/nicstar.c
30750 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30751 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30752 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30753 card->index);
30754 - atomic_inc(&vcc->stats->tx_err);
30755 + atomic_inc_unchecked(&vcc->stats->tx_err);
30756 dev_kfree_skb_any(skb);
30757 return -EINVAL;
30758 }
30759 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30760 if (!vc->tx) {
30761 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30762 card->index);
30763 - atomic_inc(&vcc->stats->tx_err);
30764 + atomic_inc_unchecked(&vcc->stats->tx_err);
30765 dev_kfree_skb_any(skb);
30766 return -EINVAL;
30767 }
30768 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30769 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30770 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30771 card->index);
30772 - atomic_inc(&vcc->stats->tx_err);
30773 + atomic_inc_unchecked(&vcc->stats->tx_err);
30774 dev_kfree_skb_any(skb);
30775 return -EINVAL;
30776 }
30777
30778 if (skb_shinfo(skb)->nr_frags != 0) {
30779 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30780 - atomic_inc(&vcc->stats->tx_err);
30781 + atomic_inc_unchecked(&vcc->stats->tx_err);
30782 dev_kfree_skb_any(skb);
30783 return -EINVAL;
30784 }
30785 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30786 }
30787
30788 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30789 - atomic_inc(&vcc->stats->tx_err);
30790 + atomic_inc_unchecked(&vcc->stats->tx_err);
30791 dev_kfree_skb_any(skb);
30792 return -EIO;
30793 }
30794 - atomic_inc(&vcc->stats->tx);
30795 + atomic_inc_unchecked(&vcc->stats->tx);
30796
30797 return 0;
30798 }
30799 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30800 printk
30801 ("nicstar%d: Can't allocate buffers for aal0.\n",
30802 card->index);
30803 - atomic_add(i, &vcc->stats->rx_drop);
30804 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30805 break;
30806 }
30807 if (!atm_charge(vcc, sb->truesize)) {
30808 RXPRINTK
30809 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30810 card->index);
30811 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30812 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30813 dev_kfree_skb_any(sb);
30814 break;
30815 }
30816 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30817 ATM_SKB(sb)->vcc = vcc;
30818 __net_timestamp(sb);
30819 vcc->push(vcc, sb);
30820 - atomic_inc(&vcc->stats->rx);
30821 + atomic_inc_unchecked(&vcc->stats->rx);
30822 cell += ATM_CELL_PAYLOAD;
30823 }
30824
30825 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30826 if (iovb == NULL) {
30827 printk("nicstar%d: Out of iovec buffers.\n",
30828 card->index);
30829 - atomic_inc(&vcc->stats->rx_drop);
30830 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30831 recycle_rx_buf(card, skb);
30832 return;
30833 }
30834 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30835 small or large buffer itself. */
30836 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30837 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30838 - atomic_inc(&vcc->stats->rx_err);
30839 + atomic_inc_unchecked(&vcc->stats->rx_err);
30840 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30841 NS_MAX_IOVECS);
30842 NS_PRV_IOVCNT(iovb) = 0;
30843 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30844 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30845 card->index);
30846 which_list(card, skb);
30847 - atomic_inc(&vcc->stats->rx_err);
30848 + atomic_inc_unchecked(&vcc->stats->rx_err);
30849 recycle_rx_buf(card, skb);
30850 vc->rx_iov = NULL;
30851 recycle_iov_buf(card, iovb);
30852 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30853 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30854 card->index);
30855 which_list(card, skb);
30856 - atomic_inc(&vcc->stats->rx_err);
30857 + atomic_inc_unchecked(&vcc->stats->rx_err);
30858 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30859 NS_PRV_IOVCNT(iovb));
30860 vc->rx_iov = NULL;
30861 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30862 printk(" - PDU size mismatch.\n");
30863 else
30864 printk(".\n");
30865 - atomic_inc(&vcc->stats->rx_err);
30866 + atomic_inc_unchecked(&vcc->stats->rx_err);
30867 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30868 NS_PRV_IOVCNT(iovb));
30869 vc->rx_iov = NULL;
30870 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30871 /* skb points to a small buffer */
30872 if (!atm_charge(vcc, skb->truesize)) {
30873 push_rxbufs(card, skb);
30874 - atomic_inc(&vcc->stats->rx_drop);
30875 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30876 } else {
30877 skb_put(skb, len);
30878 dequeue_sm_buf(card, skb);
30879 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30880 ATM_SKB(skb)->vcc = vcc;
30881 __net_timestamp(skb);
30882 vcc->push(vcc, skb);
30883 - atomic_inc(&vcc->stats->rx);
30884 + atomic_inc_unchecked(&vcc->stats->rx);
30885 }
30886 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30887 struct sk_buff *sb;
30888 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30889 if (len <= NS_SMBUFSIZE) {
30890 if (!atm_charge(vcc, sb->truesize)) {
30891 push_rxbufs(card, sb);
30892 - atomic_inc(&vcc->stats->rx_drop);
30893 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30894 } else {
30895 skb_put(sb, len);
30896 dequeue_sm_buf(card, sb);
30897 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30898 ATM_SKB(sb)->vcc = vcc;
30899 __net_timestamp(sb);
30900 vcc->push(vcc, sb);
30901 - atomic_inc(&vcc->stats->rx);
30902 + atomic_inc_unchecked(&vcc->stats->rx);
30903 }
30904
30905 push_rxbufs(card, skb);
30906 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30907
30908 if (!atm_charge(vcc, skb->truesize)) {
30909 push_rxbufs(card, skb);
30910 - atomic_inc(&vcc->stats->rx_drop);
30911 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30912 } else {
30913 dequeue_lg_buf(card, skb);
30914 #ifdef NS_USE_DESTRUCTORS
30915 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30916 ATM_SKB(skb)->vcc = vcc;
30917 __net_timestamp(skb);
30918 vcc->push(vcc, skb);
30919 - atomic_inc(&vcc->stats->rx);
30920 + atomic_inc_unchecked(&vcc->stats->rx);
30921 }
30922
30923 push_rxbufs(card, sb);
30924 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30925 printk
30926 ("nicstar%d: Out of huge buffers.\n",
30927 card->index);
30928 - atomic_inc(&vcc->stats->rx_drop);
30929 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30930 recycle_iovec_rx_bufs(card,
30931 (struct iovec *)
30932 iovb->data,
30933 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30934 card->hbpool.count++;
30935 } else
30936 dev_kfree_skb_any(hb);
30937 - atomic_inc(&vcc->stats->rx_drop);
30938 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30939 } else {
30940 /* Copy the small buffer to the huge buffer */
30941 sb = (struct sk_buff *)iov->iov_base;
30942 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30943 #endif /* NS_USE_DESTRUCTORS */
30944 __net_timestamp(hb);
30945 vcc->push(vcc, hb);
30946 - atomic_inc(&vcc->stats->rx);
30947 + atomic_inc_unchecked(&vcc->stats->rx);
30948 }
30949 }
30950
30951 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30952 index 1853a45..cf2426d 100644
30953 --- a/drivers/atm/solos-pci.c
30954 +++ b/drivers/atm/solos-pci.c
30955 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30956 }
30957 atm_charge(vcc, skb->truesize);
30958 vcc->push(vcc, skb);
30959 - atomic_inc(&vcc->stats->rx);
30960 + atomic_inc_unchecked(&vcc->stats->rx);
30961 break;
30962
30963 case PKT_STATUS:
30964 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30965 vcc = SKB_CB(oldskb)->vcc;
30966
30967 if (vcc) {
30968 - atomic_inc(&vcc->stats->tx);
30969 + atomic_inc_unchecked(&vcc->stats->tx);
30970 solos_pop(vcc, oldskb);
30971 } else
30972 dev_kfree_skb_irq(oldskb);
30973 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30974 index 0215934..ce9f5b1 100644
30975 --- a/drivers/atm/suni.c
30976 +++ b/drivers/atm/suni.c
30977 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30978
30979
30980 #define ADD_LIMITED(s,v) \
30981 - atomic_add((v),&stats->s); \
30982 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30983 + atomic_add_unchecked((v),&stats->s); \
30984 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30985
30986
30987 static void suni_hz(unsigned long from_timer)
30988 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30989 index 5120a96..e2572bd 100644
30990 --- a/drivers/atm/uPD98402.c
30991 +++ b/drivers/atm/uPD98402.c
30992 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30993 struct sonet_stats tmp;
30994 int error = 0;
30995
30996 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30997 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30998 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30999 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31000 if (zero && !error) {
31001 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31002
31003
31004 #define ADD_LIMITED(s,v) \
31005 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31006 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31007 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31008 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31009 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31010 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31011
31012
31013 static void stat_event(struct atm_dev *dev)
31014 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31015 if (reason & uPD98402_INT_PFM) stat_event(dev);
31016 if (reason & uPD98402_INT_PCO) {
31017 (void) GET(PCOCR); /* clear interrupt cause */
31018 - atomic_add(GET(HECCT),
31019 + atomic_add_unchecked(GET(HECCT),
31020 &PRIV(dev)->sonet_stats.uncorr_hcs);
31021 }
31022 if ((reason & uPD98402_INT_RFO) &&
31023 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31024 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31025 uPD98402_INT_LOS),PIMR); /* enable them */
31026 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31027 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31028 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31029 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31030 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31031 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31032 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31033 return 0;
31034 }
31035
31036 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31037 index abe4e20..83c4727 100644
31038 --- a/drivers/atm/zatm.c
31039 +++ b/drivers/atm/zatm.c
31040 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31041 }
31042 if (!size) {
31043 dev_kfree_skb_irq(skb);
31044 - if (vcc) atomic_inc(&vcc->stats->rx_err);
31045 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31046 continue;
31047 }
31048 if (!atm_charge(vcc,skb->truesize)) {
31049 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31050 skb->len = size;
31051 ATM_SKB(skb)->vcc = vcc;
31052 vcc->push(vcc,skb);
31053 - atomic_inc(&vcc->stats->rx);
31054 + atomic_inc_unchecked(&vcc->stats->rx);
31055 }
31056 zout(pos & 0xffff,MTA(mbx));
31057 #if 0 /* probably a stupid idea */
31058 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31059 skb_queue_head(&zatm_vcc->backlog,skb);
31060 break;
31061 }
31062 - atomic_inc(&vcc->stats->tx);
31063 + atomic_inc_unchecked(&vcc->stats->tx);
31064 wake_up(&zatm_vcc->tx_wait);
31065 }
31066
31067 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31068 index 147d1a4..d0fd4b0 100644
31069 --- a/drivers/base/devtmpfs.c
31070 +++ b/drivers/base/devtmpfs.c
31071 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31072 if (!thread)
31073 return 0;
31074
31075 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31076 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31077 if (err)
31078 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31079 else
31080 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31081 index e6ee5e8..98ad7fc 100644
31082 --- a/drivers/base/power/wakeup.c
31083 +++ b/drivers/base/power/wakeup.c
31084 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31085 * They need to be modified together atomically, so it's better to use one
31086 * atomic variable to hold them both.
31087 */
31088 -static atomic_t combined_event_count = ATOMIC_INIT(0);
31089 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31090
31091 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31092 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31093
31094 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31095 {
31096 - unsigned int comb = atomic_read(&combined_event_count);
31097 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
31098
31099 *cnt = (comb >> IN_PROGRESS_BITS);
31100 *inpr = comb & MAX_IN_PROGRESS;
31101 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31102 ws->start_prevent_time = ws->last_time;
31103
31104 /* Increment the counter of events in progress. */
31105 - cec = atomic_inc_return(&combined_event_count);
31106 + cec = atomic_inc_return_unchecked(&combined_event_count);
31107
31108 trace_wakeup_source_activate(ws->name, cec);
31109 }
31110 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31111 * Increment the counter of registered wakeup events and decrement the
31112 * couter of wakeup events in progress simultaneously.
31113 */
31114 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31115 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31116 trace_wakeup_source_deactivate(ws->name, cec);
31117
31118 split_counters(&cnt, &inpr);
31119 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31120 index ca83f96..69d4ea9 100644
31121 --- a/drivers/block/cciss.c
31122 +++ b/drivers/block/cciss.c
31123 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31124 int err;
31125 u32 cp;
31126
31127 + memset(&arg64, 0, sizeof(arg64));
31128 +
31129 err = 0;
31130 err |=
31131 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31132 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31133 while (!list_empty(&h->reqQ)) {
31134 c = list_entry(h->reqQ.next, CommandList_struct, list);
31135 /* can't do anything if fifo is full */
31136 - if ((h->access.fifo_full(h))) {
31137 + if ((h->access->fifo_full(h))) {
31138 dev_warn(&h->pdev->dev, "fifo full\n");
31139 break;
31140 }
31141 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31142 h->Qdepth--;
31143
31144 /* Tell the controller execute command */
31145 - h->access.submit_command(h, c);
31146 + h->access->submit_command(h, c);
31147
31148 /* Put job onto the completed Q */
31149 addQ(&h->cmpQ, c);
31150 @@ -3443,17 +3445,17 @@ startio:
31151
31152 static inline unsigned long get_next_completion(ctlr_info_t *h)
31153 {
31154 - return h->access.command_completed(h);
31155 + return h->access->command_completed(h);
31156 }
31157
31158 static inline int interrupt_pending(ctlr_info_t *h)
31159 {
31160 - return h->access.intr_pending(h);
31161 + return h->access->intr_pending(h);
31162 }
31163
31164 static inline long interrupt_not_for_us(ctlr_info_t *h)
31165 {
31166 - return ((h->access.intr_pending(h) == 0) ||
31167 + return ((h->access->intr_pending(h) == 0) ||
31168 (h->interrupts_enabled == 0));
31169 }
31170
31171 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31172 u32 a;
31173
31174 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31175 - return h->access.command_completed(h);
31176 + return h->access->command_completed(h);
31177
31178 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31179 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31180 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31181 trans_support & CFGTBL_Trans_use_short_tags);
31182
31183 /* Change the access methods to the performant access methods */
31184 - h->access = SA5_performant_access;
31185 + h->access = &SA5_performant_access;
31186 h->transMethod = CFGTBL_Trans_Performant;
31187
31188 return;
31189 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31190 if (prod_index < 0)
31191 return -ENODEV;
31192 h->product_name = products[prod_index].product_name;
31193 - h->access = *(products[prod_index].access);
31194 + h->access = products[prod_index].access;
31195
31196 if (cciss_board_disabled(h)) {
31197 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31198 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31199 }
31200
31201 /* make sure the board interrupts are off */
31202 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31203 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31204 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31205 if (rc)
31206 goto clean2;
31207 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31208 * fake ones to scoop up any residual completions.
31209 */
31210 spin_lock_irqsave(&h->lock, flags);
31211 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31212 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31213 spin_unlock_irqrestore(&h->lock, flags);
31214 free_irq(h->intr[h->intr_mode], h);
31215 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31216 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31217 dev_info(&h->pdev->dev, "Board READY.\n");
31218 dev_info(&h->pdev->dev,
31219 "Waiting for stale completions to drain.\n");
31220 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31221 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31222 msleep(10000);
31223 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31224 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31225
31226 rc = controller_reset_failed(h->cfgtable);
31227 if (rc)
31228 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31229 cciss_scsi_setup(h);
31230
31231 /* Turn the interrupts on so we can service requests */
31232 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31233 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31234
31235 /* Get the firmware version */
31236 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31237 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31238 kfree(flush_buf);
31239 if (return_code != IO_OK)
31240 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31241 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31242 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31243 free_irq(h->intr[h->intr_mode], h);
31244 }
31245
31246 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31247 index 7fda30e..eb5dfe0 100644
31248 --- a/drivers/block/cciss.h
31249 +++ b/drivers/block/cciss.h
31250 @@ -101,7 +101,7 @@ struct ctlr_info
31251 /* information about each logical volume */
31252 drive_info_struct *drv[CISS_MAX_LUN];
31253
31254 - struct access_method access;
31255 + struct access_method *access;
31256
31257 /* queue and queue Info */
31258 struct list_head reqQ;
31259 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31260 index 9125bbe..eede5c8 100644
31261 --- a/drivers/block/cpqarray.c
31262 +++ b/drivers/block/cpqarray.c
31263 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31264 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31265 goto Enomem4;
31266 }
31267 - hba[i]->access.set_intr_mask(hba[i], 0);
31268 + hba[i]->access->set_intr_mask(hba[i], 0);
31269 if (request_irq(hba[i]->intr, do_ida_intr,
31270 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31271 {
31272 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31273 add_timer(&hba[i]->timer);
31274
31275 /* Enable IRQ now that spinlock and rate limit timer are set up */
31276 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31277 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31278
31279 for(j=0; j<NWD; j++) {
31280 struct gendisk *disk = ida_gendisk[i][j];
31281 @@ -694,7 +694,7 @@ DBGINFO(
31282 for(i=0; i<NR_PRODUCTS; i++) {
31283 if (board_id == products[i].board_id) {
31284 c->product_name = products[i].product_name;
31285 - c->access = *(products[i].access);
31286 + c->access = products[i].access;
31287 break;
31288 }
31289 }
31290 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31291 hba[ctlr]->intr = intr;
31292 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31293 hba[ctlr]->product_name = products[j].product_name;
31294 - hba[ctlr]->access = *(products[j].access);
31295 + hba[ctlr]->access = products[j].access;
31296 hba[ctlr]->ctlr = ctlr;
31297 hba[ctlr]->board_id = board_id;
31298 hba[ctlr]->pci_dev = NULL; /* not PCI */
31299 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31300
31301 while((c = h->reqQ) != NULL) {
31302 /* Can't do anything if we're busy */
31303 - if (h->access.fifo_full(h) == 0)
31304 + if (h->access->fifo_full(h) == 0)
31305 return;
31306
31307 /* Get the first entry from the request Q */
31308 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31309 h->Qdepth--;
31310
31311 /* Tell the controller to do our bidding */
31312 - h->access.submit_command(h, c);
31313 + h->access->submit_command(h, c);
31314
31315 /* Get onto the completion Q */
31316 addQ(&h->cmpQ, c);
31317 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31318 unsigned long flags;
31319 __u32 a,a1;
31320
31321 - istat = h->access.intr_pending(h);
31322 + istat = h->access->intr_pending(h);
31323 /* Is this interrupt for us? */
31324 if (istat == 0)
31325 return IRQ_NONE;
31326 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31327 */
31328 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31329 if (istat & FIFO_NOT_EMPTY) {
31330 - while((a = h->access.command_completed(h))) {
31331 + while((a = h->access->command_completed(h))) {
31332 a1 = a; a &= ~3;
31333 if ((c = h->cmpQ) == NULL)
31334 {
31335 @@ -1449,11 +1449,11 @@ static int sendcmd(
31336 /*
31337 * Disable interrupt
31338 */
31339 - info_p->access.set_intr_mask(info_p, 0);
31340 + info_p->access->set_intr_mask(info_p, 0);
31341 /* Make sure there is room in the command FIFO */
31342 /* Actually it should be completely empty at this time. */
31343 for (i = 200000; i > 0; i--) {
31344 - temp = info_p->access.fifo_full(info_p);
31345 + temp = info_p->access->fifo_full(info_p);
31346 if (temp != 0) {
31347 break;
31348 }
31349 @@ -1466,7 +1466,7 @@ DBG(
31350 /*
31351 * Send the cmd
31352 */
31353 - info_p->access.submit_command(info_p, c);
31354 + info_p->access->submit_command(info_p, c);
31355 complete = pollcomplete(ctlr);
31356
31357 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31358 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31359 * we check the new geometry. Then turn interrupts back on when
31360 * we're done.
31361 */
31362 - host->access.set_intr_mask(host, 0);
31363 + host->access->set_intr_mask(host, 0);
31364 getgeometry(ctlr);
31365 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31366 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31367
31368 for(i=0; i<NWD; i++) {
31369 struct gendisk *disk = ida_gendisk[ctlr][i];
31370 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31371 /* Wait (up to 2 seconds) for a command to complete */
31372
31373 for (i = 200000; i > 0; i--) {
31374 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31375 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31376 if (done == 0) {
31377 udelay(10); /* a short fixed delay */
31378 } else
31379 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31380 index be73e9d..7fbf140 100644
31381 --- a/drivers/block/cpqarray.h
31382 +++ b/drivers/block/cpqarray.h
31383 @@ -99,7 +99,7 @@ struct ctlr_info {
31384 drv_info_t drv[NWD];
31385 struct proc_dir_entry *proc;
31386
31387 - struct access_method access;
31388 + struct access_method *access;
31389
31390 cmdlist_t *reqQ;
31391 cmdlist_t *cmpQ;
31392 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31393 index b953cc7..e3dc580 100644
31394 --- a/drivers/block/drbd/drbd_int.h
31395 +++ b/drivers/block/drbd/drbd_int.h
31396 @@ -735,7 +735,7 @@ struct drbd_request;
31397 struct drbd_epoch {
31398 struct list_head list;
31399 unsigned int barrier_nr;
31400 - atomic_t epoch_size; /* increased on every request added. */
31401 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31402 atomic_t active; /* increased on every req. added, and dec on every finished. */
31403 unsigned long flags;
31404 };
31405 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31406 void *int_dig_in;
31407 void *int_dig_vv;
31408 wait_queue_head_t seq_wait;
31409 - atomic_t packet_seq;
31410 + atomic_unchecked_t packet_seq;
31411 unsigned int peer_seq;
31412 spinlock_t peer_seq_lock;
31413 unsigned int minor;
31414 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31415
31416 static inline void drbd_tcp_cork(struct socket *sock)
31417 {
31418 - int __user val = 1;
31419 + int val = 1;
31420 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31421 - (char __user *)&val, sizeof(val));
31422 + (char __force_user *)&val, sizeof(val));
31423 }
31424
31425 static inline void drbd_tcp_uncork(struct socket *sock)
31426 {
31427 - int __user val = 0;
31428 + int val = 0;
31429 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31430 - (char __user *)&val, sizeof(val));
31431 + (char __force_user *)&val, sizeof(val));
31432 }
31433
31434 static inline void drbd_tcp_nodelay(struct socket *sock)
31435 {
31436 - int __user val = 1;
31437 + int val = 1;
31438 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31439 - (char __user *)&val, sizeof(val));
31440 + (char __force_user *)&val, sizeof(val));
31441 }
31442
31443 static inline void drbd_tcp_quickack(struct socket *sock)
31444 {
31445 - int __user val = 2;
31446 + int val = 2;
31447 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31448 - (char __user *)&val, sizeof(val));
31449 + (char __force_user *)&val, sizeof(val));
31450 }
31451
31452 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31453 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31454 index f55683a..2101b96 100644
31455 --- a/drivers/block/drbd/drbd_main.c
31456 +++ b/drivers/block/drbd/drbd_main.c
31457 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31458 p.sector = sector;
31459 p.block_id = block_id;
31460 p.blksize = blksize;
31461 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31462 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31463
31464 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31465 return false;
31466 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31467
31468 p.sector = cpu_to_be64(req->sector);
31469 p.block_id = (unsigned long)req;
31470 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31471 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31472
31473 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31474
31475 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31476 atomic_set(&mdev->unacked_cnt, 0);
31477 atomic_set(&mdev->local_cnt, 0);
31478 atomic_set(&mdev->net_cnt, 0);
31479 - atomic_set(&mdev->packet_seq, 0);
31480 + atomic_set_unchecked(&mdev->packet_seq, 0);
31481 atomic_set(&mdev->pp_in_use, 0);
31482 atomic_set(&mdev->pp_in_use_by_net, 0);
31483 atomic_set(&mdev->rs_sect_in, 0);
31484 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31485 mdev->receiver.t_state);
31486
31487 /* no need to lock it, I'm the only thread alive */
31488 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31489 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31490 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31491 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31492 mdev->al_writ_cnt =
31493 mdev->bm_writ_cnt =
31494 mdev->read_cnt =
31495 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31496 index edb490a..ecd69da 100644
31497 --- a/drivers/block/drbd/drbd_nl.c
31498 +++ b/drivers/block/drbd/drbd_nl.c
31499 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31500 module_put(THIS_MODULE);
31501 }
31502
31503 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31504 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31505
31506 static unsigned short *
31507 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31508 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31509 cn_reply->id.idx = CN_IDX_DRBD;
31510 cn_reply->id.val = CN_VAL_DRBD;
31511
31512 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31513 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31514 cn_reply->ack = 0; /* not used here. */
31515 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31516 (int)((char *)tl - (char *)reply->tag_list);
31517 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31518 cn_reply->id.idx = CN_IDX_DRBD;
31519 cn_reply->id.val = CN_VAL_DRBD;
31520
31521 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31522 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31523 cn_reply->ack = 0; /* not used here. */
31524 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31525 (int)((char *)tl - (char *)reply->tag_list);
31526 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31527 cn_reply->id.idx = CN_IDX_DRBD;
31528 cn_reply->id.val = CN_VAL_DRBD;
31529
31530 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31531 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31532 cn_reply->ack = 0; // not used here.
31533 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31534 (int)((char*)tl - (char*)reply->tag_list);
31535 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31536 cn_reply->id.idx = CN_IDX_DRBD;
31537 cn_reply->id.val = CN_VAL_DRBD;
31538
31539 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31540 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31541 cn_reply->ack = 0; /* not used here. */
31542 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31543 (int)((char *)tl - (char *)reply->tag_list);
31544 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31545 index c74ca2d..860c819 100644
31546 --- a/drivers/block/drbd/drbd_receiver.c
31547 +++ b/drivers/block/drbd/drbd_receiver.c
31548 @@ -898,7 +898,7 @@ retry:
31549 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31550 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31551
31552 - atomic_set(&mdev->packet_seq, 0);
31553 + atomic_set_unchecked(&mdev->packet_seq, 0);
31554 mdev->peer_seq = 0;
31555
31556 if (drbd_send_protocol(mdev) == -1)
31557 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31558 do {
31559 next_epoch = NULL;
31560
31561 - epoch_size = atomic_read(&epoch->epoch_size);
31562 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31563
31564 switch (ev & ~EV_CLEANUP) {
31565 case EV_PUT:
31566 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31567 rv = FE_DESTROYED;
31568 } else {
31569 epoch->flags = 0;
31570 - atomic_set(&epoch->epoch_size, 0);
31571 + atomic_set_unchecked(&epoch->epoch_size, 0);
31572 /* atomic_set(&epoch->active, 0); is already zero */
31573 if (rv == FE_STILL_LIVE)
31574 rv = FE_RECYCLED;
31575 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31576 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31577 drbd_flush(mdev);
31578
31579 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31580 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31581 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31582 if (epoch)
31583 break;
31584 }
31585
31586 epoch = mdev->current_epoch;
31587 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31588 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31589
31590 D_ASSERT(atomic_read(&epoch->active) == 0);
31591 D_ASSERT(epoch->flags == 0);
31592 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31593 }
31594
31595 epoch->flags = 0;
31596 - atomic_set(&epoch->epoch_size, 0);
31597 + atomic_set_unchecked(&epoch->epoch_size, 0);
31598 atomic_set(&epoch->active, 0);
31599
31600 spin_lock(&mdev->epoch_lock);
31601 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31602 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31603 list_add(&epoch->list, &mdev->current_epoch->list);
31604 mdev->current_epoch = epoch;
31605 mdev->epochs++;
31606 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31607 spin_unlock(&mdev->peer_seq_lock);
31608
31609 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31610 - atomic_inc(&mdev->current_epoch->epoch_size);
31611 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31612 return drbd_drain_block(mdev, data_size);
31613 }
31614
31615 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31616
31617 spin_lock(&mdev->epoch_lock);
31618 e->epoch = mdev->current_epoch;
31619 - atomic_inc(&e->epoch->epoch_size);
31620 + atomic_inc_unchecked(&e->epoch->epoch_size);
31621 atomic_inc(&e->epoch->active);
31622 spin_unlock(&mdev->epoch_lock);
31623
31624 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31625 D_ASSERT(list_empty(&mdev->done_ee));
31626
31627 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31628 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31629 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31630 D_ASSERT(list_empty(&mdev->current_epoch->list));
31631 }
31632
31633 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31634 index 54046e5..7759c55 100644
31635 --- a/drivers/block/loop.c
31636 +++ b/drivers/block/loop.c
31637 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31638 mm_segment_t old_fs = get_fs();
31639
31640 set_fs(get_ds());
31641 - bw = file->f_op->write(file, buf, len, &pos);
31642 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31643 set_fs(old_fs);
31644 if (likely(bw == len))
31645 return 0;
31646 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31647 index d620b44..587561e 100644
31648 --- a/drivers/cdrom/cdrom.c
31649 +++ b/drivers/cdrom/cdrom.c
31650 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31651 ENSURE(reset, CDC_RESET);
31652 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31653 cdi->mc_flags = 0;
31654 - cdo->n_minors = 0;
31655 cdi->options = CDO_USE_FFLAGS;
31656
31657 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31658 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31659 else
31660 cdi->cdda_method = CDDA_OLD;
31661
31662 - if (!cdo->generic_packet)
31663 - cdo->generic_packet = cdrom_dummy_generic_packet;
31664 + if (!cdo->generic_packet) {
31665 + pax_open_kernel();
31666 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31667 + pax_close_kernel();
31668 + }
31669
31670 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31671 mutex_lock(&cdrom_mutex);
31672 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31673 if (cdi->exit)
31674 cdi->exit(cdi);
31675
31676 - cdi->ops->n_minors--;
31677 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31678 }
31679
31680 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31681 index 75d485a..2809958 100644
31682 --- a/drivers/cdrom/gdrom.c
31683 +++ b/drivers/cdrom/gdrom.c
31684 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31685 .audio_ioctl = gdrom_audio_ioctl,
31686 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31687 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31688 - .n_minors = 1,
31689 };
31690
31691 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31692 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31693 index 72bedad..8181ce1 100644
31694 --- a/drivers/char/Kconfig
31695 +++ b/drivers/char/Kconfig
31696 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31697
31698 config DEVKMEM
31699 bool "/dev/kmem virtual device support"
31700 - default y
31701 + default n
31702 + depends on !GRKERNSEC_KMEM
31703 help
31704 Say Y here if you want to support the /dev/kmem device. The
31705 /dev/kmem device is rarely used, but can be used for certain
31706 @@ -581,6 +582,7 @@ config DEVPORT
31707 bool
31708 depends on !M68K
31709 depends on ISA || PCI
31710 + depends on !GRKERNSEC_KMEM
31711 default y
31712
31713 source "drivers/s390/char/Kconfig"
31714 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31715 index 2e04433..22afc64 100644
31716 --- a/drivers/char/agp/frontend.c
31717 +++ b/drivers/char/agp/frontend.c
31718 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31719 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31720 return -EFAULT;
31721
31722 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31723 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31724 return -EFAULT;
31725
31726 client = agp_find_client_by_pid(reserve.pid);
31727 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31728 index 21cb980..f15107c 100644
31729 --- a/drivers/char/genrtc.c
31730 +++ b/drivers/char/genrtc.c
31731 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31732 switch (cmd) {
31733
31734 case RTC_PLL_GET:
31735 + memset(&pll, 0, sizeof(pll));
31736 if (get_rtc_pll(&pll))
31737 return -EINVAL;
31738 else
31739 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31740 index dfd7876..c0b0885 100644
31741 --- a/drivers/char/hpet.c
31742 +++ b/drivers/char/hpet.c
31743 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31744 }
31745
31746 static int
31747 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31748 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31749 struct hpet_info *info)
31750 {
31751 struct hpet_timer __iomem *timer;
31752 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31753 index a0c84bb..9edcf60 100644
31754 --- a/drivers/char/ipmi/ipmi_msghandler.c
31755 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31756 @@ -420,7 +420,7 @@ struct ipmi_smi {
31757 struct proc_dir_entry *proc_dir;
31758 char proc_dir_name[10];
31759
31760 - atomic_t stats[IPMI_NUM_STATS];
31761 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31762
31763 /*
31764 * run_to_completion duplicate of smb_info, smi_info
31765 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31766
31767
31768 #define ipmi_inc_stat(intf, stat) \
31769 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31770 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31771 #define ipmi_get_stat(intf, stat) \
31772 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31773 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31774
31775 static int is_lan_addr(struct ipmi_addr *addr)
31776 {
31777 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31778 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31779 init_waitqueue_head(&intf->waitq);
31780 for (i = 0; i < IPMI_NUM_STATS; i++)
31781 - atomic_set(&intf->stats[i], 0);
31782 + atomic_set_unchecked(&intf->stats[i], 0);
31783
31784 intf->proc_dir = NULL;
31785
31786 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31787 index 32a6c7e..f6966a9 100644
31788 --- a/drivers/char/ipmi/ipmi_si_intf.c
31789 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31790 @@ -275,7 +275,7 @@ struct smi_info {
31791 unsigned char slave_addr;
31792
31793 /* Counters and things for the proc filesystem. */
31794 - atomic_t stats[SI_NUM_STATS];
31795 + atomic_unchecked_t stats[SI_NUM_STATS];
31796
31797 struct task_struct *thread;
31798
31799 @@ -284,9 +284,9 @@ struct smi_info {
31800 };
31801
31802 #define smi_inc_stat(smi, stat) \
31803 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31804 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31805 #define smi_get_stat(smi, stat) \
31806 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31807 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31808
31809 #define SI_MAX_PARMS 4
31810
31811 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31812 atomic_set(&new_smi->req_events, 0);
31813 new_smi->run_to_completion = 0;
31814 for (i = 0; i < SI_NUM_STATS; i++)
31815 - atomic_set(&new_smi->stats[i], 0);
31816 + atomic_set_unchecked(&new_smi->stats[i], 0);
31817
31818 new_smi->interrupt_disabled = 1;
31819 atomic_set(&new_smi->stop_operation, 0);
31820 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31821 index 0537903..121c699 100644
31822 --- a/drivers/char/mem.c
31823 +++ b/drivers/char/mem.c
31824 @@ -18,6 +18,7 @@
31825 #include <linux/raw.h>
31826 #include <linux/tty.h>
31827 #include <linux/capability.h>
31828 +#include <linux/security.h>
31829 #include <linux/ptrace.h>
31830 #include <linux/device.h>
31831 #include <linux/highmem.h>
31832 @@ -37,6 +38,10 @@
31833
31834 #define DEVPORT_MINOR 4
31835
31836 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31837 +extern const struct file_operations grsec_fops;
31838 +#endif
31839 +
31840 static inline unsigned long size_inside_page(unsigned long start,
31841 unsigned long size)
31842 {
31843 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31844
31845 while (cursor < to) {
31846 if (!devmem_is_allowed(pfn)) {
31847 +#ifdef CONFIG_GRKERNSEC_KMEM
31848 + gr_handle_mem_readwrite(from, to);
31849 +#else
31850 printk(KERN_INFO
31851 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31852 current->comm, from, to);
31853 +#endif
31854 return 0;
31855 }
31856 cursor += PAGE_SIZE;
31857 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31858 }
31859 return 1;
31860 }
31861 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31862 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31863 +{
31864 + return 0;
31865 +}
31866 #else
31867 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31868 {
31869 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31870
31871 while (count > 0) {
31872 unsigned long remaining;
31873 + char *temp;
31874
31875 sz = size_inside_page(p, count);
31876
31877 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31878 if (!ptr)
31879 return -EFAULT;
31880
31881 - remaining = copy_to_user(buf, ptr, sz);
31882 +#ifdef CONFIG_PAX_USERCOPY
31883 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31884 + if (!temp) {
31885 + unxlate_dev_mem_ptr(p, ptr);
31886 + return -ENOMEM;
31887 + }
31888 + memcpy(temp, ptr, sz);
31889 +#else
31890 + temp = ptr;
31891 +#endif
31892 +
31893 + remaining = copy_to_user(buf, temp, sz);
31894 +
31895 +#ifdef CONFIG_PAX_USERCOPY
31896 + kfree(temp);
31897 +#endif
31898 +
31899 unxlate_dev_mem_ptr(p, ptr);
31900 if (remaining)
31901 return -EFAULT;
31902 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31903 size_t count, loff_t *ppos)
31904 {
31905 unsigned long p = *ppos;
31906 - ssize_t low_count, read, sz;
31907 + ssize_t low_count, read, sz, err = 0;
31908 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31909 - int err = 0;
31910
31911 read = 0;
31912 if (p < (unsigned long) high_memory) {
31913 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31914 }
31915 #endif
31916 while (low_count > 0) {
31917 + char *temp;
31918 +
31919 sz = size_inside_page(p, low_count);
31920
31921 /*
31922 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31923 */
31924 kbuf = xlate_dev_kmem_ptr((char *)p);
31925
31926 - if (copy_to_user(buf, kbuf, sz))
31927 +#ifdef CONFIG_PAX_USERCOPY
31928 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31929 + if (!temp)
31930 + return -ENOMEM;
31931 + memcpy(temp, kbuf, sz);
31932 +#else
31933 + temp = kbuf;
31934 +#endif
31935 +
31936 + err = copy_to_user(buf, temp, sz);
31937 +
31938 +#ifdef CONFIG_PAX_USERCOPY
31939 + kfree(temp);
31940 +#endif
31941 +
31942 + if (err)
31943 return -EFAULT;
31944 buf += sz;
31945 p += sz;
31946 @@ -833,6 +880,9 @@ static const struct memdev {
31947 #ifdef CONFIG_CRASH_DUMP
31948 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31949 #endif
31950 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31951 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31952 +#endif
31953 };
31954
31955 static int memory_open(struct inode *inode, struct file *filp)
31956 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31957 index 9df78e2..01ba9ae 100644
31958 --- a/drivers/char/nvram.c
31959 +++ b/drivers/char/nvram.c
31960 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
31961
31962 spin_unlock_irq(&rtc_lock);
31963
31964 - if (copy_to_user(buf, contents, tmp - contents))
31965 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
31966 return -EFAULT;
31967
31968 *ppos = i;
31969 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
31970 index 21721d2..4e98777 100644
31971 --- a/drivers/char/pcmcia/synclink_cs.c
31972 +++ b/drivers/char/pcmcia/synclink_cs.c
31973 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31974
31975 if (debug_level >= DEBUG_LEVEL_INFO)
31976 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
31977 - __FILE__,__LINE__, info->device_name, port->count);
31978 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
31979
31980 - WARN_ON(!port->count);
31981 + WARN_ON(!atomic_read(&port->count));
31982
31983 if (tty_port_close_start(port, tty, filp) == 0)
31984 goto cleanup;
31985 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31986 cleanup:
31987 if (debug_level >= DEBUG_LEVEL_INFO)
31988 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
31989 - tty->driver->name, port->count);
31990 + tty->driver->name, atomic_read(&port->count));
31991 }
31992
31993 /* Wait until the transmitter is empty.
31994 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31995
31996 if (debug_level >= DEBUG_LEVEL_INFO)
31997 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
31998 - __FILE__,__LINE__,tty->driver->name, port->count);
31999 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32000
32001 /* If port is closing, signal caller to try again */
32002 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32003 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32004 goto cleanup;
32005 }
32006 spin_lock(&port->lock);
32007 - port->count++;
32008 + atomic_inc(&port->count);
32009 spin_unlock(&port->lock);
32010 spin_unlock_irqrestore(&info->netlock, flags);
32011
32012 - if (port->count == 1) {
32013 + if (atomic_read(&port->count) == 1) {
32014 /* 1st open on this device, init hardware */
32015 retval = startup(info, tty);
32016 if (retval < 0)
32017 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32018 unsigned short new_crctype;
32019
32020 /* return error if TTY interface open */
32021 - if (info->port.count)
32022 + if (atomic_read(&info->port.count))
32023 return -EBUSY;
32024
32025 switch (encoding)
32026 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32027
32028 /* arbitrate between network and tty opens */
32029 spin_lock_irqsave(&info->netlock, flags);
32030 - if (info->port.count != 0 || info->netcount != 0) {
32031 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32032 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32033 spin_unlock_irqrestore(&info->netlock, flags);
32034 return -EBUSY;
32035 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32036 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32037
32038 /* return error if TTY interface open */
32039 - if (info->port.count)
32040 + if (atomic_read(&info->port.count))
32041 return -EBUSY;
32042
32043 if (cmd != SIOCWANDEV)
32044 diff --git a/drivers/char/random.c b/drivers/char/random.c
32045 index b86eae9..b9c2ed7 100644
32046 --- a/drivers/char/random.c
32047 +++ b/drivers/char/random.c
32048 @@ -272,8 +272,13 @@
32049 /*
32050 * Configuration information
32051 */
32052 +#ifdef CONFIG_GRKERNSEC_RANDNET
32053 +#define INPUT_POOL_WORDS 512
32054 +#define OUTPUT_POOL_WORDS 128
32055 +#else
32056 #define INPUT_POOL_WORDS 128
32057 #define OUTPUT_POOL_WORDS 32
32058 +#endif
32059 #define SEC_XFER_SIZE 512
32060 #define EXTRACT_SIZE 10
32061
32062 @@ -313,10 +318,17 @@ static struct poolinfo {
32063 int poolwords;
32064 int tap1, tap2, tap3, tap4, tap5;
32065 } poolinfo_table[] = {
32066 +#ifdef CONFIG_GRKERNSEC_RANDNET
32067 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32068 + { 512, 411, 308, 208, 104, 1 },
32069 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32070 + { 128, 103, 76, 51, 25, 1 },
32071 +#else
32072 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32073 { 128, 103, 76, 51, 25, 1 },
32074 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32075 { 32, 26, 20, 14, 7, 1 },
32076 +#endif
32077 #if 0
32078 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32079 { 2048, 1638, 1231, 819, 411, 1 },
32080 @@ -437,6 +449,7 @@ struct entropy_store {
32081 int entropy_count;
32082 int entropy_total;
32083 unsigned int initialized:1;
32084 + bool last_data_init;
32085 __u8 last_data[EXTRACT_SIZE];
32086 };
32087
32088 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32089 input_rotate += i ? 7 : 14;
32090 }
32091
32092 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32093 - ACCESS_ONCE(r->add_ptr) = i;
32094 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32095 + ACCESS_ONCE_RW(r->add_ptr) = i;
32096 smp_wmb();
32097
32098 if (out)
32099 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32100 ssize_t ret = 0, i;
32101 __u8 tmp[EXTRACT_SIZE];
32102
32103 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32104 + if (fips_enabled && !r->last_data_init)
32105 + nbytes += EXTRACT_SIZE;
32106 +
32107 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32108 xfer_secondary_pool(r, nbytes);
32109 nbytes = account(r, nbytes, min, reserved);
32110 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32111 if (fips_enabled) {
32112 unsigned long flags;
32113
32114 +
32115 + /* prime last_data value if need be, per fips 140-2 */
32116 + if (!r->last_data_init) {
32117 + spin_lock_irqsave(&r->lock, flags);
32118 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
32119 + r->last_data_init = true;
32120 + nbytes -= EXTRACT_SIZE;
32121 + spin_unlock_irqrestore(&r->lock, flags);
32122 + extract_buf(r, tmp);
32123 + }
32124 +
32125 spin_lock_irqsave(&r->lock, flags);
32126 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32127 panic("Hardware RNG duplicated output!\n");
32128 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32129
32130 extract_buf(r, tmp);
32131 i = min_t(int, nbytes, EXTRACT_SIZE);
32132 - if (copy_to_user(buf, tmp, i)) {
32133 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32134 ret = -EFAULT;
32135 break;
32136 }
32137 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32138
32139 r->entropy_count = 0;
32140 r->entropy_total = 0;
32141 + r->last_data_init = false;
32142 mix_pool_bytes(r, &now, sizeof(now), NULL);
32143 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32144 if (!arch_get_random_long(&rv))
32145 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32146 #include <linux/sysctl.h>
32147
32148 static int min_read_thresh = 8, min_write_thresh;
32149 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32150 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32151 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32152 static char sysctl_bootid[16];
32153
32154 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32155 index 9b4f011..b7e0a1a 100644
32156 --- a/drivers/char/sonypi.c
32157 +++ b/drivers/char/sonypi.c
32158 @@ -54,6 +54,7 @@
32159
32160 #include <asm/uaccess.h>
32161 #include <asm/io.h>
32162 +#include <asm/local.h>
32163
32164 #include <linux/sonypi.h>
32165
32166 @@ -490,7 +491,7 @@ static struct sonypi_device {
32167 spinlock_t fifo_lock;
32168 wait_queue_head_t fifo_proc_list;
32169 struct fasync_struct *fifo_async;
32170 - int open_count;
32171 + local_t open_count;
32172 int model;
32173 struct input_dev *input_jog_dev;
32174 struct input_dev *input_key_dev;
32175 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32176 static int sonypi_misc_release(struct inode *inode, struct file *file)
32177 {
32178 mutex_lock(&sonypi_device.lock);
32179 - sonypi_device.open_count--;
32180 + local_dec(&sonypi_device.open_count);
32181 mutex_unlock(&sonypi_device.lock);
32182 return 0;
32183 }
32184 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32185 {
32186 mutex_lock(&sonypi_device.lock);
32187 /* Flush input queue on first open */
32188 - if (!sonypi_device.open_count)
32189 + if (!local_read(&sonypi_device.open_count))
32190 kfifo_reset(&sonypi_device.fifo);
32191 - sonypi_device.open_count++;
32192 + local_inc(&sonypi_device.open_count);
32193 mutex_unlock(&sonypi_device.lock);
32194
32195 return 0;
32196 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32197 index 93211df..c7805f7 100644
32198 --- a/drivers/char/tpm/tpm.c
32199 +++ b/drivers/char/tpm/tpm.c
32200 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32201 chip->vendor.req_complete_val)
32202 goto out_recv;
32203
32204 - if ((status == chip->vendor.req_canceled)) {
32205 + if (status == chip->vendor.req_canceled) {
32206 dev_err(chip->dev, "Operation Canceled\n");
32207 rc = -ECANCELED;
32208 goto out;
32209 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32210 index 56051d0..11cf3b7 100644
32211 --- a/drivers/char/tpm/tpm_acpi.c
32212 +++ b/drivers/char/tpm/tpm_acpi.c
32213 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32214 virt = acpi_os_map_memory(start, len);
32215 if (!virt) {
32216 kfree(log->bios_event_log);
32217 + log->bios_event_log = NULL;
32218 printk("%s: ERROR - Unable to map memory\n", __func__);
32219 return -EIO;
32220 }
32221
32222 - memcpy_fromio(log->bios_event_log, virt, len);
32223 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32224
32225 acpi_os_unmap_memory(virt, len);
32226 return 0;
32227 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32228 index 84ddc55..1d32f1e 100644
32229 --- a/drivers/char/tpm/tpm_eventlog.c
32230 +++ b/drivers/char/tpm/tpm_eventlog.c
32231 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32232 event = addr;
32233
32234 if ((event->event_type == 0 && event->event_size == 0) ||
32235 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32236 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32237 return NULL;
32238
32239 return addr;
32240 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32241 return NULL;
32242
32243 if ((event->event_type == 0 && event->event_size == 0) ||
32244 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32245 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32246 return NULL;
32247
32248 (*pos)++;
32249 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32250 int i;
32251
32252 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32253 - seq_putc(m, data[i]);
32254 + if (!seq_putc(m, data[i]))
32255 + return -EFAULT;
32256
32257 return 0;
32258 }
32259 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32260 index 8ab9c3d..c3e65d3 100644
32261 --- a/drivers/char/virtio_console.c
32262 +++ b/drivers/char/virtio_console.c
32263 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32264 if (to_user) {
32265 ssize_t ret;
32266
32267 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32268 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32269 if (ret)
32270 return -EFAULT;
32271 } else {
32272 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32273 if (!port_has_data(port) && !port->host_connected)
32274 return 0;
32275
32276 - return fill_readbuf(port, ubuf, count, true);
32277 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32278 }
32279
32280 static int wait_port_writable(struct port *port, bool nonblock)
32281 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32282 index e164c55..3aabb50 100644
32283 --- a/drivers/edac/edac_pci_sysfs.c
32284 +++ b/drivers/edac/edac_pci_sysfs.c
32285 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32286 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32287 static int edac_pci_poll_msec = 1000; /* one second workq period */
32288
32289 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32290 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32291 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32292 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32293
32294 static struct kobject *edac_pci_top_main_kobj;
32295 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32296 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32297 edac_printk(KERN_CRIT, EDAC_PCI,
32298 "Signaled System Error on %s\n",
32299 pci_name(dev));
32300 - atomic_inc(&pci_nonparity_count);
32301 + atomic_inc_unchecked(&pci_nonparity_count);
32302 }
32303
32304 if (status & (PCI_STATUS_PARITY)) {
32305 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32306 "Master Data Parity Error on %s\n",
32307 pci_name(dev));
32308
32309 - atomic_inc(&pci_parity_count);
32310 + atomic_inc_unchecked(&pci_parity_count);
32311 }
32312
32313 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32314 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32315 "Detected Parity Error on %s\n",
32316 pci_name(dev));
32317
32318 - atomic_inc(&pci_parity_count);
32319 + atomic_inc_unchecked(&pci_parity_count);
32320 }
32321 }
32322
32323 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32324 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32325 "Signaled System Error on %s\n",
32326 pci_name(dev));
32327 - atomic_inc(&pci_nonparity_count);
32328 + atomic_inc_unchecked(&pci_nonparity_count);
32329 }
32330
32331 if (status & (PCI_STATUS_PARITY)) {
32332 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32333 "Master Data Parity Error on "
32334 "%s\n", pci_name(dev));
32335
32336 - atomic_inc(&pci_parity_count);
32337 + atomic_inc_unchecked(&pci_parity_count);
32338 }
32339
32340 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32341 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32342 "Detected Parity Error on %s\n",
32343 pci_name(dev));
32344
32345 - atomic_inc(&pci_parity_count);
32346 + atomic_inc_unchecked(&pci_parity_count);
32347 }
32348 }
32349 }
32350 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32351 if (!check_pci_errors)
32352 return;
32353
32354 - before_count = atomic_read(&pci_parity_count);
32355 + before_count = atomic_read_unchecked(&pci_parity_count);
32356
32357 /* scan all PCI devices looking for a Parity Error on devices and
32358 * bridges.
32359 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32360 /* Only if operator has selected panic on PCI Error */
32361 if (edac_pci_get_panic_on_pe()) {
32362 /* If the count is different 'after' from 'before' */
32363 - if (before_count != atomic_read(&pci_parity_count))
32364 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32365 panic("EDAC: PCI Parity Error");
32366 }
32367 }
32368 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32369 index 8c87a5e..a19cbd7 100644
32370 --- a/drivers/edac/mce_amd.h
32371 +++ b/drivers/edac/mce_amd.h
32372 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32373 struct amd_decoder_ops {
32374 bool (*dc_mce)(u16, u8);
32375 bool (*ic_mce)(u16, u8);
32376 -};
32377 +} __no_const;
32378
32379 void amd_report_gart_errors(bool);
32380 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32381 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32382 index 57ea7f4..789e3c3 100644
32383 --- a/drivers/firewire/core-card.c
32384 +++ b/drivers/firewire/core-card.c
32385 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32386
32387 void fw_core_remove_card(struct fw_card *card)
32388 {
32389 - struct fw_card_driver dummy_driver = dummy_driver_template;
32390 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32391
32392 card->driver->update_phy_reg(card, 4,
32393 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32394 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32395 index f8d2287..5aaf4db 100644
32396 --- a/drivers/firewire/core-cdev.c
32397 +++ b/drivers/firewire/core-cdev.c
32398 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32399 int ret;
32400
32401 if ((request->channels == 0 && request->bandwidth == 0) ||
32402 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32403 - request->bandwidth < 0)
32404 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32405 return -EINVAL;
32406
32407 r = kmalloc(sizeof(*r), GFP_KERNEL);
32408 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32409 index 28a94c7..58da63a 100644
32410 --- a/drivers/firewire/core-transaction.c
32411 +++ b/drivers/firewire/core-transaction.c
32412 @@ -38,6 +38,7 @@
32413 #include <linux/timer.h>
32414 #include <linux/types.h>
32415 #include <linux/workqueue.h>
32416 +#include <linux/sched.h>
32417
32418 #include <asm/byteorder.h>
32419
32420 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32421 index 515a42c..5ecf3ba 100644
32422 --- a/drivers/firewire/core.h
32423 +++ b/drivers/firewire/core.h
32424 @@ -111,6 +111,7 @@ struct fw_card_driver {
32425
32426 int (*stop_iso)(struct fw_iso_context *ctx);
32427 };
32428 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32429
32430 void fw_card_initialize(struct fw_card *card,
32431 const struct fw_card_driver *driver, struct device *device);
32432 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32433 index fd3ae62..669efe3 100644
32434 --- a/drivers/firmware/dmi_scan.c
32435 +++ b/drivers/firmware/dmi_scan.c
32436 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32437 }
32438 }
32439 else {
32440 - /*
32441 - * no iounmap() for that ioremap(); it would be a no-op, but
32442 - * it's so early in setup that sucker gets confused into doing
32443 - * what it shouldn't if we actually call it.
32444 - */
32445 p = dmi_ioremap(0xF0000, 0x10000);
32446 if (p == NULL)
32447 goto error;
32448 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32449 if (buf == NULL)
32450 return -1;
32451
32452 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32453 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32454
32455 iounmap(buf);
32456 return 0;
32457 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32458 index d10c987..ebe5400 100644
32459 --- a/drivers/firmware/efivars.c
32460 +++ b/drivers/firmware/efivars.c
32461 @@ -1234,9 +1234,9 @@ efivars_init(void)
32462 return -ENOMEM;
32463 }
32464
32465 - ops.get_variable = efi.get_variable;
32466 - ops.set_variable = efi.set_variable;
32467 - ops.get_next_variable = efi.get_next_variable;
32468 + *(void **)&ops.get_variable = efi.get_variable;
32469 + *(void **)&ops.set_variable = efi.set_variable;
32470 + *(void **)&ops.get_next_variable = efi.get_next_variable;
32471 error = register_efivars(&__efivars, &ops, efi_kobj);
32472 if (error)
32473 goto err_put;
32474 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32475 index 82d5c20..44a7177 100644
32476 --- a/drivers/gpio/gpio-vr41xx.c
32477 +++ b/drivers/gpio/gpio-vr41xx.c
32478 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32479 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32480 maskl, pendl, maskh, pendh);
32481
32482 - atomic_inc(&irq_err_count);
32483 + atomic_inc_unchecked(&irq_err_count);
32484
32485 return -EINVAL;
32486 }
32487 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32488 index 1227adf..f2301c2 100644
32489 --- a/drivers/gpu/drm/drm_crtc_helper.c
32490 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32491 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32492 struct drm_crtc *tmp;
32493 int crtc_mask = 1;
32494
32495 - WARN(!crtc, "checking null crtc?\n");
32496 + BUG_ON(!crtc);
32497
32498 dev = crtc->dev;
32499
32500 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32501 index be174ca..0bcbb71 100644
32502 --- a/drivers/gpu/drm/drm_drv.c
32503 +++ b/drivers/gpu/drm/drm_drv.c
32504 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32505 /**
32506 * Copy and IOCTL return string to user space
32507 */
32508 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32509 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32510 {
32511 int len;
32512
32513 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32514 return -ENODEV;
32515
32516 atomic_inc(&dev->ioctl_count);
32517 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32518 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32519 ++file_priv->ioctl_count;
32520
32521 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32522 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32523 index 133b413..fd68225 100644
32524 --- a/drivers/gpu/drm/drm_fops.c
32525 +++ b/drivers/gpu/drm/drm_fops.c
32526 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32527 }
32528
32529 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32530 - atomic_set(&dev->counts[i], 0);
32531 + atomic_set_unchecked(&dev->counts[i], 0);
32532
32533 dev->sigdata.lock = NULL;
32534
32535 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32536 if (drm_device_is_unplugged(dev))
32537 return -ENODEV;
32538
32539 - if (!dev->open_count++)
32540 + if (local_inc_return(&dev->open_count) == 1)
32541 need_setup = 1;
32542 mutex_lock(&dev->struct_mutex);
32543 old_mapping = dev->dev_mapping;
32544 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32545 retcode = drm_open_helper(inode, filp, dev);
32546 if (retcode)
32547 goto err_undo;
32548 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32549 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32550 if (need_setup) {
32551 retcode = drm_setup(dev);
32552 if (retcode)
32553 @@ -164,7 +164,7 @@ err_undo:
32554 iput(container_of(dev->dev_mapping, struct inode, i_data));
32555 dev->dev_mapping = old_mapping;
32556 mutex_unlock(&dev->struct_mutex);
32557 - dev->open_count--;
32558 + local_dec(&dev->open_count);
32559 return retcode;
32560 }
32561 EXPORT_SYMBOL(drm_open);
32562 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32563
32564 mutex_lock(&drm_global_mutex);
32565
32566 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32567 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32568
32569 if (dev->driver->preclose)
32570 dev->driver->preclose(dev, file_priv);
32571 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32572 * Begin inline drm_release
32573 */
32574
32575 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32576 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32577 task_pid_nr(current),
32578 (long)old_encode_dev(file_priv->minor->device),
32579 - dev->open_count);
32580 + local_read(&dev->open_count));
32581
32582 /* Release any auth tokens that might point to this file_priv,
32583 (do that under the drm_global_mutex) */
32584 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32585 * End inline drm_release
32586 */
32587
32588 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32589 - if (!--dev->open_count) {
32590 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32591 + if (local_dec_and_test(&dev->open_count)) {
32592 if (atomic_read(&dev->ioctl_count)) {
32593 DRM_ERROR("Device busy: %d\n",
32594 atomic_read(&dev->ioctl_count));
32595 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32596 index f731116..629842c 100644
32597 --- a/drivers/gpu/drm/drm_global.c
32598 +++ b/drivers/gpu/drm/drm_global.c
32599 @@ -36,7 +36,7 @@
32600 struct drm_global_item {
32601 struct mutex mutex;
32602 void *object;
32603 - int refcount;
32604 + atomic_t refcount;
32605 };
32606
32607 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32608 @@ -49,7 +49,7 @@ void drm_global_init(void)
32609 struct drm_global_item *item = &glob[i];
32610 mutex_init(&item->mutex);
32611 item->object = NULL;
32612 - item->refcount = 0;
32613 + atomic_set(&item->refcount, 0);
32614 }
32615 }
32616
32617 @@ -59,7 +59,7 @@ void drm_global_release(void)
32618 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32619 struct drm_global_item *item = &glob[i];
32620 BUG_ON(item->object != NULL);
32621 - BUG_ON(item->refcount != 0);
32622 + BUG_ON(atomic_read(&item->refcount) != 0);
32623 }
32624 }
32625
32626 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32627 void *object;
32628
32629 mutex_lock(&item->mutex);
32630 - if (item->refcount == 0) {
32631 + if (atomic_read(&item->refcount) == 0) {
32632 item->object = kzalloc(ref->size, GFP_KERNEL);
32633 if (unlikely(item->object == NULL)) {
32634 ret = -ENOMEM;
32635 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32636 goto out_err;
32637
32638 }
32639 - ++item->refcount;
32640 + atomic_inc(&item->refcount);
32641 ref->object = item->object;
32642 object = item->object;
32643 mutex_unlock(&item->mutex);
32644 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32645 struct drm_global_item *item = &glob[ref->global_type];
32646
32647 mutex_lock(&item->mutex);
32648 - BUG_ON(item->refcount == 0);
32649 + BUG_ON(atomic_read(&item->refcount) == 0);
32650 BUG_ON(ref->object != item->object);
32651 - if (--item->refcount == 0) {
32652 + if (atomic_dec_and_test(&item->refcount)) {
32653 ref->release(ref);
32654 item->object = NULL;
32655 }
32656 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32657 index d4b20ce..77a8d41 100644
32658 --- a/drivers/gpu/drm/drm_info.c
32659 +++ b/drivers/gpu/drm/drm_info.c
32660 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32661 struct drm_local_map *map;
32662 struct drm_map_list *r_list;
32663
32664 - /* Hardcoded from _DRM_FRAME_BUFFER,
32665 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32666 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32667 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32668 + static const char * const types[] = {
32669 + [_DRM_FRAME_BUFFER] = "FB",
32670 + [_DRM_REGISTERS] = "REG",
32671 + [_DRM_SHM] = "SHM",
32672 + [_DRM_AGP] = "AGP",
32673 + [_DRM_SCATTER_GATHER] = "SG",
32674 + [_DRM_CONSISTENT] = "PCI",
32675 + [_DRM_GEM] = "GEM" };
32676 const char *type;
32677 int i;
32678
32679 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32680 map = r_list->map;
32681 if (!map)
32682 continue;
32683 - if (map->type < 0 || map->type > 5)
32684 + if (map->type >= ARRAY_SIZE(types))
32685 type = "??";
32686 else
32687 type = types[map->type];
32688 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32689 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32690 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32691 vma->vm_flags & VM_IO ? 'i' : '-',
32692 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32693 + 0);
32694 +#else
32695 vma->vm_pgoff);
32696 +#endif
32697
32698 #if defined(__i386__)
32699 pgprot = pgprot_val(vma->vm_page_prot);
32700 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32701 index 2f4c434..764794b 100644
32702 --- a/drivers/gpu/drm/drm_ioc32.c
32703 +++ b/drivers/gpu/drm/drm_ioc32.c
32704 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32705 request = compat_alloc_user_space(nbytes);
32706 if (!access_ok(VERIFY_WRITE, request, nbytes))
32707 return -EFAULT;
32708 - list = (struct drm_buf_desc *) (request + 1);
32709 + list = (struct drm_buf_desc __user *) (request + 1);
32710
32711 if (__put_user(count, &request->count)
32712 || __put_user(list, &request->list))
32713 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32714 request = compat_alloc_user_space(nbytes);
32715 if (!access_ok(VERIFY_WRITE, request, nbytes))
32716 return -EFAULT;
32717 - list = (struct drm_buf_pub *) (request + 1);
32718 + list = (struct drm_buf_pub __user *) (request + 1);
32719
32720 if (__put_user(count, &request->count)
32721 || __put_user(list, &request->list))
32722 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32723 index 23dd975..63e9801 100644
32724 --- a/drivers/gpu/drm/drm_ioctl.c
32725 +++ b/drivers/gpu/drm/drm_ioctl.c
32726 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32727 stats->data[i].value =
32728 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32729 else
32730 - stats->data[i].value = atomic_read(&dev->counts[i]);
32731 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32732 stats->data[i].type = dev->types[i];
32733 }
32734
32735 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32736 index d752c96..fe08455 100644
32737 --- a/drivers/gpu/drm/drm_lock.c
32738 +++ b/drivers/gpu/drm/drm_lock.c
32739 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32740 if (drm_lock_take(&master->lock, lock->context)) {
32741 master->lock.file_priv = file_priv;
32742 master->lock.lock_time = jiffies;
32743 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32744 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32745 break; /* Got lock */
32746 }
32747
32748 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32749 return -EINVAL;
32750 }
32751
32752 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32753 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32754
32755 if (drm_lock_free(&master->lock, lock->context)) {
32756 /* FIXME: Should really bail out here. */
32757 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32758 index c236fd2..6b5f2e7 100644
32759 --- a/drivers/gpu/drm/drm_stub.c
32760 +++ b/drivers/gpu/drm/drm_stub.c
32761 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32762
32763 drm_device_set_unplugged(dev);
32764
32765 - if (dev->open_count == 0) {
32766 + if (local_read(&dev->open_count) == 0) {
32767 drm_put_dev(dev);
32768 }
32769 mutex_unlock(&drm_global_mutex);
32770 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32771 index 004ecdf..db1f6e0 100644
32772 --- a/drivers/gpu/drm/i810/i810_dma.c
32773 +++ b/drivers/gpu/drm/i810/i810_dma.c
32774 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32775 dma->buflist[vertex->idx],
32776 vertex->discard, vertex->used);
32777
32778 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32779 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32780 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32781 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32782 sarea_priv->last_enqueue = dev_priv->counter - 1;
32783 sarea_priv->last_dispatch = (int)hw_status[5];
32784
32785 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32786 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32787 mc->last_render);
32788
32789 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32790 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32791 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32792 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32793 sarea_priv->last_enqueue = dev_priv->counter - 1;
32794 sarea_priv->last_dispatch = (int)hw_status[5];
32795
32796 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32797 index 6e0acad..93c8289 100644
32798 --- a/drivers/gpu/drm/i810/i810_drv.h
32799 +++ b/drivers/gpu/drm/i810/i810_drv.h
32800 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32801 int page_flipping;
32802
32803 wait_queue_head_t irq_queue;
32804 - atomic_t irq_received;
32805 - atomic_t irq_emitted;
32806 + atomic_unchecked_t irq_received;
32807 + atomic_unchecked_t irq_emitted;
32808
32809 int front_offset;
32810 } drm_i810_private_t;
32811 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32812 index da21b11..14c8749 100644
32813 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32814 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32815 @@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32816 I915_READ(GTIMR));
32817 }
32818 seq_printf(m, "Interrupts received: %d\n",
32819 - atomic_read(&dev_priv->irq_received));
32820 + atomic_read_unchecked(&dev_priv->irq_received));
32821 for_each_ring(ring, dev_priv, i) {
32822 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32823 seq_printf(m,
32824 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32825 index 61ae104..f8a4bc1 100644
32826 --- a/drivers/gpu/drm/i915/i915_dma.c
32827 +++ b/drivers/gpu/drm/i915/i915_dma.c
32828 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32829 bool can_switch;
32830
32831 spin_lock(&dev->count_lock);
32832 - can_switch = (dev->open_count == 0);
32833 + can_switch = (local_read(&dev->open_count) == 0);
32834 spin_unlock(&dev->count_lock);
32835 return can_switch;
32836 }
32837 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32838 index 92f1750..3beba74 100644
32839 --- a/drivers/gpu/drm/i915/i915_drv.h
32840 +++ b/drivers/gpu/drm/i915/i915_drv.h
32841 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32842
32843 struct resource mch_res;
32844
32845 - atomic_t irq_received;
32846 + atomic_unchecked_t irq_received;
32847
32848 /* protects the irq masks */
32849 spinlock_t irq_lock;
32850 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32851 * will be page flipped away on the next vblank. When it
32852 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32853 */
32854 - atomic_t pending_flip;
32855 + atomic_unchecked_t pending_flip;
32856 };
32857
32858 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32859 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32860 struct drm_i915_private *dev_priv, unsigned port);
32861 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32862 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32863 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32864 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32865 {
32866 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32867 }
32868 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32869 index 67036e9..b9f1357 100644
32870 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32871 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32872 @@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32873 i915_gem_clflush_object(obj);
32874
32875 if (obj->base.pending_write_domain)
32876 - flips |= atomic_read(&obj->pending_flip);
32877 + flips |= atomic_read_unchecked(&obj->pending_flip);
32878
32879 flush_domains |= obj->base.write_domain;
32880 }
32881 @@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32882
32883 static int
32884 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32885 - int count)
32886 + unsigned int count)
32887 {
32888 - int i;
32889 + unsigned int i;
32890
32891 for (i = 0; i < count; i++) {
32892 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32893 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32894 index dc29ace..137d83a 100644
32895 --- a/drivers/gpu/drm/i915/i915_irq.c
32896 +++ b/drivers/gpu/drm/i915/i915_irq.c
32897 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32898 u32 pipe_stats[I915_MAX_PIPES];
32899 bool blc_event;
32900
32901 - atomic_inc(&dev_priv->irq_received);
32902 + atomic_inc_unchecked(&dev_priv->irq_received);
32903
32904 while (true) {
32905 iir = I915_READ(VLV_IIR);
32906 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32907 irqreturn_t ret = IRQ_NONE;
32908 int i;
32909
32910 - atomic_inc(&dev_priv->irq_received);
32911 + atomic_inc_unchecked(&dev_priv->irq_received);
32912
32913 /* disable master interrupt before clearing iir */
32914 de_ier = I915_READ(DEIER);
32915 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32916 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32917 u32 hotplug_mask;
32918
32919 - atomic_inc(&dev_priv->irq_received);
32920 + atomic_inc_unchecked(&dev_priv->irq_received);
32921
32922 /* disable master interrupt before clearing iir */
32923 de_ier = I915_READ(DEIER);
32924 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32925 {
32926 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32927
32928 - atomic_set(&dev_priv->irq_received, 0);
32929 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32930
32931 I915_WRITE(HWSTAM, 0xeffe);
32932
32933 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
32934 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32935 int pipe;
32936
32937 - atomic_set(&dev_priv->irq_received, 0);
32938 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32939
32940 /* VLV magic */
32941 I915_WRITE(VLV_IMR, 0);
32942 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
32943 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32944 int pipe;
32945
32946 - atomic_set(&dev_priv->irq_received, 0);
32947 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32948
32949 for_each_pipe(pipe)
32950 I915_WRITE(PIPESTAT(pipe), 0);
32951 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
32952 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
32953 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
32954
32955 - atomic_inc(&dev_priv->irq_received);
32956 + atomic_inc_unchecked(&dev_priv->irq_received);
32957
32958 iir = I915_READ16(IIR);
32959 if (iir == 0)
32960 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
32961 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32962 int pipe;
32963
32964 - atomic_set(&dev_priv->irq_received, 0);
32965 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32966
32967 if (I915_HAS_HOTPLUG(dev)) {
32968 I915_WRITE(PORT_HOTPLUG_EN, 0);
32969 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
32970 };
32971 int pipe, ret = IRQ_NONE;
32972
32973 - atomic_inc(&dev_priv->irq_received);
32974 + atomic_inc_unchecked(&dev_priv->irq_received);
32975
32976 iir = I915_READ(IIR);
32977 do {
32978 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
32979 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32980 int pipe;
32981
32982 - atomic_set(&dev_priv->irq_received, 0);
32983 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32984
32985 I915_WRITE(PORT_HOTPLUG_EN, 0);
32986 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
32987 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
32988 int irq_received;
32989 int ret = IRQ_NONE, pipe;
32990
32991 - atomic_inc(&dev_priv->irq_received);
32992 + atomic_inc_unchecked(&dev_priv->irq_received);
32993
32994 iir = I915_READ(IIR);
32995
32996 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
32997 index 4d3c7c6..eaac87b 100644
32998 --- a/drivers/gpu/drm/i915/intel_display.c
32999 +++ b/drivers/gpu/drm/i915/intel_display.c
33000 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33001
33002 wait_event(dev_priv->pending_flip_queue,
33003 atomic_read(&dev_priv->mm.wedged) ||
33004 - atomic_read(&obj->pending_flip) == 0);
33005 + atomic_read_unchecked(&obj->pending_flip) == 0);
33006
33007 /* Big Hammer, we also need to ensure that any pending
33008 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33009 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33010
33011 obj = work->old_fb_obj;
33012
33013 - atomic_clear_mask(1 << intel_crtc->plane,
33014 - &obj->pending_flip.counter);
33015 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33016 wake_up(&dev_priv->pending_flip_queue);
33017
33018 queue_work(dev_priv->wq, &work->work);
33019 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33020 /* Block clients from rendering to the new back buffer until
33021 * the flip occurs and the object is no longer visible.
33022 */
33023 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33024 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33025 atomic_inc(&intel_crtc->unpin_work_count);
33026
33027 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33028 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33029
33030 cleanup_pending:
33031 atomic_dec(&intel_crtc->unpin_work_count);
33032 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33033 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33034 drm_gem_object_unreference(&work->old_fb_obj->base);
33035 drm_gem_object_unreference(&obj->base);
33036 mutex_unlock(&dev->struct_mutex);
33037 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33038 index 54558a0..2d97005 100644
33039 --- a/drivers/gpu/drm/mga/mga_drv.h
33040 +++ b/drivers/gpu/drm/mga/mga_drv.h
33041 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33042 u32 clear_cmd;
33043 u32 maccess;
33044
33045 - atomic_t vbl_received; /**< Number of vblanks received. */
33046 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33047 wait_queue_head_t fence_queue;
33048 - atomic_t last_fence_retired;
33049 + atomic_unchecked_t last_fence_retired;
33050 u32 next_fence_to_post;
33051
33052 unsigned int fb_cpp;
33053 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33054 index 598c281..60d590e 100644
33055 --- a/drivers/gpu/drm/mga/mga_irq.c
33056 +++ b/drivers/gpu/drm/mga/mga_irq.c
33057 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33058 if (crtc != 0)
33059 return 0;
33060
33061 - return atomic_read(&dev_priv->vbl_received);
33062 + return atomic_read_unchecked(&dev_priv->vbl_received);
33063 }
33064
33065
33066 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33067 /* VBLANK interrupt */
33068 if (status & MGA_VLINEPEN) {
33069 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33070 - atomic_inc(&dev_priv->vbl_received);
33071 + atomic_inc_unchecked(&dev_priv->vbl_received);
33072 drm_handle_vblank(dev, 0);
33073 handled = 1;
33074 }
33075 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33076 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33077 MGA_WRITE(MGA_PRIMEND, prim_end);
33078
33079 - atomic_inc(&dev_priv->last_fence_retired);
33080 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33081 DRM_WAKEUP(&dev_priv->fence_queue);
33082 handled = 1;
33083 }
33084 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33085 * using fences.
33086 */
33087 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33088 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33089 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33090 - *sequence) <= (1 << 23)));
33091
33092 *sequence = cur_fence;
33093 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33094 index 09fdef2..57f5c3b 100644
33095 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33096 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33097 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33098 struct bit_table {
33099 const char id;
33100 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33101 -};
33102 +} __no_const;
33103
33104 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33105
33106 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33107 index a101699..a163f0a 100644
33108 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33109 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33110 @@ -80,7 +80,7 @@ struct nouveau_drm {
33111 struct drm_global_reference mem_global_ref;
33112 struct ttm_bo_global_ref bo_global_ref;
33113 struct ttm_bo_device bdev;
33114 - atomic_t validate_sequence;
33115 + atomic_unchecked_t validate_sequence;
33116 int (*move)(struct nouveau_channel *,
33117 struct ttm_buffer_object *,
33118 struct ttm_mem_reg *, struct ttm_mem_reg *);
33119 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33120 index cdb83ac..27f0a16 100644
33121 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33122 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33123 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33124 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33125 struct nouveau_channel *);
33126 u32 (*read)(struct nouveau_channel *);
33127 -};
33128 +} __no_const;
33129
33130 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33131
33132 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33133 index 5e2f521..0d21436 100644
33134 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33135 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33136 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33137 int trycnt = 0;
33138 int ret, i;
33139
33140 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33141 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33142 retry:
33143 if (++trycnt > 100000) {
33144 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33145 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33146 index 6f0ac64..9c2dfb4 100644
33147 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33148 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33149 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33150 bool can_switch;
33151
33152 spin_lock(&dev->count_lock);
33153 - can_switch = (dev->open_count == 0);
33154 + can_switch = (local_read(&dev->open_count) == 0);
33155 spin_unlock(&dev->count_lock);
33156 return can_switch;
33157 }
33158 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33159 index 9f6f55c..30e3a29 100644
33160 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
33161 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33162 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33163 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33164 evo->object->oclass->ofuncs =
33165 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33166 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33167 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33168 - evo->object->oclass->ofuncs->rd08 =
33169 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33170 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33171 + *(void**)&evo->object->oclass->ofuncs->rd08 =
33172 ioremap(pci_resource_start(dev->pdev, 0) +
33173 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33174 return 0;
33175 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33176 index b562b59..9d725a8 100644
33177 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
33178 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33179 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33180 }
33181
33182 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33183 - struct dp_train_func func = {
33184 + static struct dp_train_func func = {
33185 .link_set = nv50_sor_dp_link_set,
33186 .train_set = nv50_sor_dp_train_set,
33187 .train_adj = nv50_sor_dp_train_adj
33188 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33189 index c402fca..f1d694b 100644
33190 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
33191 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33192 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33193 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33194
33195 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33196 - struct dp_train_func func = {
33197 + static struct dp_train_func func = {
33198 .link_set = nvd0_sor_dp_link_set,
33199 .train_set = nvd0_sor_dp_train_set,
33200 .train_adj = nvd0_sor_dp_train_adj
33201 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33202 index d4660cf..70dbe65 100644
33203 --- a/drivers/gpu/drm/r128/r128_cce.c
33204 +++ b/drivers/gpu/drm/r128/r128_cce.c
33205 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33206
33207 /* GH: Simple idle check.
33208 */
33209 - atomic_set(&dev_priv->idle_count, 0);
33210 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33211
33212 /* We don't support anything other than bus-mastering ring mode,
33213 * but the ring can be in either AGP or PCI space for the ring
33214 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33215 index 930c71b..499aded 100644
33216 --- a/drivers/gpu/drm/r128/r128_drv.h
33217 +++ b/drivers/gpu/drm/r128/r128_drv.h
33218 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33219 int is_pci;
33220 unsigned long cce_buffers_offset;
33221
33222 - atomic_t idle_count;
33223 + atomic_unchecked_t idle_count;
33224
33225 int page_flipping;
33226 int current_page;
33227 u32 crtc_offset;
33228 u32 crtc_offset_cntl;
33229
33230 - atomic_t vbl_received;
33231 + atomic_unchecked_t vbl_received;
33232
33233 u32 color_fmt;
33234 unsigned int front_offset;
33235 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33236 index 2ea4f09..d391371 100644
33237 --- a/drivers/gpu/drm/r128/r128_irq.c
33238 +++ b/drivers/gpu/drm/r128/r128_irq.c
33239 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33240 if (crtc != 0)
33241 return 0;
33242
33243 - return atomic_read(&dev_priv->vbl_received);
33244 + return atomic_read_unchecked(&dev_priv->vbl_received);
33245 }
33246
33247 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33248 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33249 /* VBLANK interrupt */
33250 if (status & R128_CRTC_VBLANK_INT) {
33251 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33252 - atomic_inc(&dev_priv->vbl_received);
33253 + atomic_inc_unchecked(&dev_priv->vbl_received);
33254 drm_handle_vblank(dev, 0);
33255 return IRQ_HANDLED;
33256 }
33257 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33258 index 19bb7e6..de7e2a2 100644
33259 --- a/drivers/gpu/drm/r128/r128_state.c
33260 +++ b/drivers/gpu/drm/r128/r128_state.c
33261 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33262
33263 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33264 {
33265 - if (atomic_read(&dev_priv->idle_count) == 0)
33266 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33267 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33268 else
33269 - atomic_set(&dev_priv->idle_count, 0);
33270 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33271 }
33272
33273 #endif
33274 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33275 index 5a82b6b..9e69c73 100644
33276 --- a/drivers/gpu/drm/radeon/mkregtable.c
33277 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33278 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33279 regex_t mask_rex;
33280 regmatch_t match[4];
33281 char buf[1024];
33282 - size_t end;
33283 + long end;
33284 int len;
33285 int done = 0;
33286 int r;
33287 unsigned o;
33288 struct offset *offset;
33289 char last_reg_s[10];
33290 - int last_reg;
33291 + unsigned long last_reg;
33292
33293 if (regcomp
33294 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33295 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33296 index ad4c973..aa27bcb 100644
33297 --- a/drivers/gpu/drm/radeon/radeon_device.c
33298 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33299 @@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33300 bool can_switch;
33301
33302 spin_lock(&dev->count_lock);
33303 - can_switch = (dev->open_count == 0);
33304 + can_switch = (local_read(&dev->open_count) == 0);
33305 spin_unlock(&dev->count_lock);
33306 return can_switch;
33307 }
33308 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33309 index a1b59ca..86f2d44 100644
33310 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33311 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33312 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33313
33314 /* SW interrupt */
33315 wait_queue_head_t swi_queue;
33316 - atomic_t swi_emitted;
33317 + atomic_unchecked_t swi_emitted;
33318 int vblank_crtc;
33319 uint32_t irq_enable_reg;
33320 uint32_t r500_disp_irq_reg;
33321 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33322 index c180df8..cd80dd2d 100644
33323 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33324 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33325 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33326 request = compat_alloc_user_space(sizeof(*request));
33327 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33328 || __put_user(req32.param, &request->param)
33329 - || __put_user((void __user *)(unsigned long)req32.value,
33330 + || __put_user((unsigned long)req32.value,
33331 &request->value))
33332 return -EFAULT;
33333
33334 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33335 index e771033..a0bc6b3 100644
33336 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33337 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33338 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33339 unsigned int ret;
33340 RING_LOCALS;
33341
33342 - atomic_inc(&dev_priv->swi_emitted);
33343 - ret = atomic_read(&dev_priv->swi_emitted);
33344 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33345 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33346
33347 BEGIN_RING(4);
33348 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33349 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33350 drm_radeon_private_t *dev_priv =
33351 (drm_radeon_private_t *) dev->dev_private;
33352
33353 - atomic_set(&dev_priv->swi_emitted, 0);
33354 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33355 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33356
33357 dev->max_vblank_count = 0x001fffff;
33358 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33359 index 8e9057b..af6dacb 100644
33360 --- a/drivers/gpu/drm/radeon/radeon_state.c
33361 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33362 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33363 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33364 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33365
33366 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33367 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33368 sarea_priv->nbox * sizeof(depth_boxes[0])))
33369 return -EFAULT;
33370
33371 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33372 {
33373 drm_radeon_private_t *dev_priv = dev->dev_private;
33374 drm_radeon_getparam_t *param = data;
33375 - int value;
33376 + int value = 0;
33377
33378 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33379
33380 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33381 index 5ebe1b3..1ed9426 100644
33382 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33383 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33384 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33385 }
33386 if (unlikely(ttm_vm_ops == NULL)) {
33387 ttm_vm_ops = vma->vm_ops;
33388 - radeon_ttm_vm_ops = *ttm_vm_ops;
33389 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33390 + pax_open_kernel();
33391 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33392 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33393 + pax_close_kernel();
33394 }
33395 vma->vm_ops = &radeon_ttm_vm_ops;
33396 return 0;
33397 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33398 index 5706d2a..17aedaa 100644
33399 --- a/drivers/gpu/drm/radeon/rs690.c
33400 +++ b/drivers/gpu/drm/radeon/rs690.c
33401 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33402 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33403 rdev->pm.sideport_bandwidth.full)
33404 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33405 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33406 + read_delay_latency.full = dfixed_const(800 * 1000);
33407 read_delay_latency.full = dfixed_div(read_delay_latency,
33408 rdev->pm.igp_sideport_mclk);
33409 + a.full = dfixed_const(370);
33410 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33411 } else {
33412 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33413 rdev->pm.k8_bandwidth.full)
33414 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33415 index bd2a3b4..122d9ad 100644
33416 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33417 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33418 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33419 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33420 struct shrink_control *sc)
33421 {
33422 - static atomic_t start_pool = ATOMIC_INIT(0);
33423 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33424 unsigned i;
33425 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33426 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33427 struct ttm_page_pool *pool;
33428 int shrink_pages = sc->nr_to_scan;
33429
33430 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33431 index 893a650..6190d3b 100644
33432 --- a/drivers/gpu/drm/via/via_drv.h
33433 +++ b/drivers/gpu/drm/via/via_drv.h
33434 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33435 typedef uint32_t maskarray_t[5];
33436
33437 typedef struct drm_via_irq {
33438 - atomic_t irq_received;
33439 + atomic_unchecked_t irq_received;
33440 uint32_t pending_mask;
33441 uint32_t enable_mask;
33442 wait_queue_head_t irq_queue;
33443 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33444 struct timeval last_vblank;
33445 int last_vblank_valid;
33446 unsigned usec_per_vblank;
33447 - atomic_t vbl_received;
33448 + atomic_unchecked_t vbl_received;
33449 drm_via_state_t hc_state;
33450 char pci_buf[VIA_PCI_BUF_SIZE];
33451 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33452 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33453 index ac98964..5dbf512 100644
33454 --- a/drivers/gpu/drm/via/via_irq.c
33455 +++ b/drivers/gpu/drm/via/via_irq.c
33456 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33457 if (crtc != 0)
33458 return 0;
33459
33460 - return atomic_read(&dev_priv->vbl_received);
33461 + return atomic_read_unchecked(&dev_priv->vbl_received);
33462 }
33463
33464 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33465 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33466
33467 status = VIA_READ(VIA_REG_INTERRUPT);
33468 if (status & VIA_IRQ_VBLANK_PENDING) {
33469 - atomic_inc(&dev_priv->vbl_received);
33470 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33471 + atomic_inc_unchecked(&dev_priv->vbl_received);
33472 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33473 do_gettimeofday(&cur_vblank);
33474 if (dev_priv->last_vblank_valid) {
33475 dev_priv->usec_per_vblank =
33476 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33477 dev_priv->last_vblank = cur_vblank;
33478 dev_priv->last_vblank_valid = 1;
33479 }
33480 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33481 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33482 DRM_DEBUG("US per vblank is: %u\n",
33483 dev_priv->usec_per_vblank);
33484 }
33485 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33486
33487 for (i = 0; i < dev_priv->num_irqs; ++i) {
33488 if (status & cur_irq->pending_mask) {
33489 - atomic_inc(&cur_irq->irq_received);
33490 + atomic_inc_unchecked(&cur_irq->irq_received);
33491 DRM_WAKEUP(&cur_irq->irq_queue);
33492 handled = 1;
33493 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33494 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33495 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33496 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33497 masks[irq][4]));
33498 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33499 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33500 } else {
33501 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33502 (((cur_irq_sequence =
33503 - atomic_read(&cur_irq->irq_received)) -
33504 + atomic_read_unchecked(&cur_irq->irq_received)) -
33505 *sequence) <= (1 << 23)));
33506 }
33507 *sequence = cur_irq_sequence;
33508 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33509 }
33510
33511 for (i = 0; i < dev_priv->num_irqs; ++i) {
33512 - atomic_set(&cur_irq->irq_received, 0);
33513 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33514 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33515 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33516 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33517 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33518 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33519 case VIA_IRQ_RELATIVE:
33520 irqwait->request.sequence +=
33521 - atomic_read(&cur_irq->irq_received);
33522 + atomic_read_unchecked(&cur_irq->irq_received);
33523 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33524 case VIA_IRQ_ABSOLUTE:
33525 break;
33526 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33527 index 88a179e..57fe50481c 100644
33528 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33529 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33530 @@ -263,7 +263,7 @@ struct vmw_private {
33531 * Fencing and IRQs.
33532 */
33533
33534 - atomic_t marker_seq;
33535 + atomic_unchecked_t marker_seq;
33536 wait_queue_head_t fence_queue;
33537 wait_queue_head_t fifo_queue;
33538 int fence_queue_waiters; /* Protected by hw_mutex */
33539 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33540 index 3eb1486..0a47ee9 100644
33541 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33542 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33543 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33544 (unsigned int) min,
33545 (unsigned int) fifo->capabilities);
33546
33547 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33548 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33549 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33550 vmw_marker_queue_init(&fifo->marker_queue);
33551 return vmw_fifo_send_fence(dev_priv, &dummy);
33552 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33553 if (reserveable)
33554 iowrite32(bytes, fifo_mem +
33555 SVGA_FIFO_RESERVED);
33556 - return fifo_mem + (next_cmd >> 2);
33557 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33558 } else {
33559 need_bounce = true;
33560 }
33561 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33562
33563 fm = vmw_fifo_reserve(dev_priv, bytes);
33564 if (unlikely(fm == NULL)) {
33565 - *seqno = atomic_read(&dev_priv->marker_seq);
33566 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33567 ret = -ENOMEM;
33568 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33569 false, 3*HZ);
33570 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33571 }
33572
33573 do {
33574 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33575 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33576 } while (*seqno == 0);
33577
33578 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33579 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33580 index 4640adb..e1384ed 100644
33581 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33582 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33583 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33584 * emitted. Then the fence is stale and signaled.
33585 */
33586
33587 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33588 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33589 > VMW_FENCE_WRAP);
33590
33591 return ret;
33592 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33593
33594 if (fifo_idle)
33595 down_read(&fifo_state->rwsem);
33596 - signal_seq = atomic_read(&dev_priv->marker_seq);
33597 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33598 ret = 0;
33599
33600 for (;;) {
33601 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33602 index 8a8725c..afed796 100644
33603 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33604 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33605 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33606 while (!vmw_lag_lt(queue, us)) {
33607 spin_lock(&queue->lock);
33608 if (list_empty(&queue->head))
33609 - seqno = atomic_read(&dev_priv->marker_seq);
33610 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33611 else {
33612 marker = list_first_entry(&queue->head,
33613 struct vmw_marker, head);
33614 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33615 index 52146db..ae33762 100644
33616 --- a/drivers/hid/hid-core.c
33617 +++ b/drivers/hid/hid-core.c
33618 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33619
33620 int hid_add_device(struct hid_device *hdev)
33621 {
33622 - static atomic_t id = ATOMIC_INIT(0);
33623 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33624 int ret;
33625
33626 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33627 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33628 /* XXX hack, any other cleaner solution after the driver core
33629 * is converted to allow more than 20 bytes as the device name? */
33630 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33631 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33632 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33633
33634 hid_debug_register(hdev, dev_name(&hdev->dev));
33635 ret = device_add(&hdev->dev);
33636 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33637 index eec3291..8ed706b 100644
33638 --- a/drivers/hid/hid-wiimote-debug.c
33639 +++ b/drivers/hid/hid-wiimote-debug.c
33640 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33641 else if (size == 0)
33642 return -EIO;
33643
33644 - if (copy_to_user(u, buf, size))
33645 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33646 return -EFAULT;
33647
33648 *off += size;
33649 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33650 index 14599e2..711c965 100644
33651 --- a/drivers/hid/usbhid/hiddev.c
33652 +++ b/drivers/hid/usbhid/hiddev.c
33653 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33654 break;
33655
33656 case HIDIOCAPPLICATION:
33657 - if (arg < 0 || arg >= hid->maxapplication)
33658 + if (arg >= hid->maxapplication)
33659 break;
33660
33661 for (i = 0; i < hid->maxcollection; i++)
33662 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33663 index f4c3d28..82f45a9 100644
33664 --- a/drivers/hv/channel.c
33665 +++ b/drivers/hv/channel.c
33666 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33667 int ret = 0;
33668 int t;
33669
33670 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33671 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33672 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33673 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33674
33675 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33676 if (ret)
33677 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33678 index 3648f8f..30ef30d 100644
33679 --- a/drivers/hv/hv.c
33680 +++ b/drivers/hv/hv.c
33681 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33682 u64 output_address = (output) ? virt_to_phys(output) : 0;
33683 u32 output_address_hi = output_address >> 32;
33684 u32 output_address_lo = output_address & 0xFFFFFFFF;
33685 - void *hypercall_page = hv_context.hypercall_page;
33686 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33687
33688 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33689 "=a"(hv_status_lo) : "d" (control_hi),
33690 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33691 index d8d1fad..b91caf7 100644
33692 --- a/drivers/hv/hyperv_vmbus.h
33693 +++ b/drivers/hv/hyperv_vmbus.h
33694 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33695 struct vmbus_connection {
33696 enum vmbus_connect_state conn_state;
33697
33698 - atomic_t next_gpadl_handle;
33699 + atomic_unchecked_t next_gpadl_handle;
33700
33701 /*
33702 * Represents channel interrupts. Each bit position represents a
33703 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33704 index 8e1a9ec..4687821 100644
33705 --- a/drivers/hv/vmbus_drv.c
33706 +++ b/drivers/hv/vmbus_drv.c
33707 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33708 {
33709 int ret = 0;
33710
33711 - static atomic_t device_num = ATOMIC_INIT(0);
33712 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33713
33714 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33715 - atomic_inc_return(&device_num));
33716 + atomic_inc_return_unchecked(&device_num));
33717
33718 child_device_obj->device.bus = &hv_bus;
33719 child_device_obj->device.parent = &hv_acpi_dev->dev;
33720 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33721 index 07a0c1a..0cac334 100644
33722 --- a/drivers/hwmon/sht15.c
33723 +++ b/drivers/hwmon/sht15.c
33724 @@ -169,7 +169,7 @@ struct sht15_data {
33725 int supply_uV;
33726 bool supply_uV_valid;
33727 struct work_struct update_supply_work;
33728 - atomic_t interrupt_handled;
33729 + atomic_unchecked_t interrupt_handled;
33730 };
33731
33732 /**
33733 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33734 return ret;
33735
33736 gpio_direction_input(data->pdata->gpio_data);
33737 - atomic_set(&data->interrupt_handled, 0);
33738 + atomic_set_unchecked(&data->interrupt_handled, 0);
33739
33740 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33741 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33742 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33743 /* Only relevant if the interrupt hasn't occurred. */
33744 - if (!atomic_read(&data->interrupt_handled))
33745 + if (!atomic_read_unchecked(&data->interrupt_handled))
33746 schedule_work(&data->read_work);
33747 }
33748 ret = wait_event_timeout(data->wait_queue,
33749 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33750
33751 /* First disable the interrupt */
33752 disable_irq_nosync(irq);
33753 - atomic_inc(&data->interrupt_handled);
33754 + atomic_inc_unchecked(&data->interrupt_handled);
33755 /* Then schedule a reading work struct */
33756 if (data->state != SHT15_READING_NOTHING)
33757 schedule_work(&data->read_work);
33758 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33759 * If not, then start the interrupt again - care here as could
33760 * have gone low in meantime so verify it hasn't!
33761 */
33762 - atomic_set(&data->interrupt_handled, 0);
33763 + atomic_set_unchecked(&data->interrupt_handled, 0);
33764 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33765 /* If still not occurred or another handler was scheduled */
33766 if (gpio_get_value(data->pdata->gpio_data)
33767 - || atomic_read(&data->interrupt_handled))
33768 + || atomic_read_unchecked(&data->interrupt_handled))
33769 return;
33770 }
33771
33772 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33773 index 378fcb5..5e91fa8 100644
33774 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33775 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33776 @@ -43,7 +43,7 @@
33777 extern struct i2c_adapter amd756_smbus;
33778
33779 static struct i2c_adapter *s4882_adapter;
33780 -static struct i2c_algorithm *s4882_algo;
33781 +static i2c_algorithm_no_const *s4882_algo;
33782
33783 /* Wrapper access functions for multiplexed SMBus */
33784 static DEFINE_MUTEX(amd756_lock);
33785 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33786 index 29015eb..af2d8e9 100644
33787 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33788 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33789 @@ -41,7 +41,7 @@
33790 extern struct i2c_adapter *nforce2_smbus;
33791
33792 static struct i2c_adapter *s4985_adapter;
33793 -static struct i2c_algorithm *s4985_algo;
33794 +static i2c_algorithm_no_const *s4985_algo;
33795
33796 /* Wrapper access functions for multiplexed SMBus */
33797 static DEFINE_MUTEX(nforce2_lock);
33798 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33799 index 8126824..55a2798 100644
33800 --- a/drivers/ide/ide-cd.c
33801 +++ b/drivers/ide/ide-cd.c
33802 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33803 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33804 if ((unsigned long)buf & alignment
33805 || blk_rq_bytes(rq) & q->dma_pad_mask
33806 - || object_is_on_stack(buf))
33807 + || object_starts_on_stack(buf))
33808 drive->dma = 0;
33809 }
33810 }
33811 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33812 index 394fea2..c833880 100644
33813 --- a/drivers/infiniband/core/cm.c
33814 +++ b/drivers/infiniband/core/cm.c
33815 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33816
33817 struct cm_counter_group {
33818 struct kobject obj;
33819 - atomic_long_t counter[CM_ATTR_COUNT];
33820 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33821 };
33822
33823 struct cm_counter_attribute {
33824 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33825 struct ib_mad_send_buf *msg = NULL;
33826 int ret;
33827
33828 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33829 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33830 counter[CM_REQ_COUNTER]);
33831
33832 /* Quick state check to discard duplicate REQs. */
33833 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33834 if (!cm_id_priv)
33835 return;
33836
33837 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33838 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33839 counter[CM_REP_COUNTER]);
33840 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33841 if (ret)
33842 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33843 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33844 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33845 spin_unlock_irq(&cm_id_priv->lock);
33846 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33847 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33848 counter[CM_RTU_COUNTER]);
33849 goto out;
33850 }
33851 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33852 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33853 dreq_msg->local_comm_id);
33854 if (!cm_id_priv) {
33855 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33856 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33857 counter[CM_DREQ_COUNTER]);
33858 cm_issue_drep(work->port, work->mad_recv_wc);
33859 return -EINVAL;
33860 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33861 case IB_CM_MRA_REP_RCVD:
33862 break;
33863 case IB_CM_TIMEWAIT:
33864 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33865 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33866 counter[CM_DREQ_COUNTER]);
33867 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33868 goto unlock;
33869 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33870 cm_free_msg(msg);
33871 goto deref;
33872 case IB_CM_DREQ_RCVD:
33873 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33874 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33875 counter[CM_DREQ_COUNTER]);
33876 goto unlock;
33877 default:
33878 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33879 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33880 cm_id_priv->msg, timeout)) {
33881 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33882 - atomic_long_inc(&work->port->
33883 + atomic_long_inc_unchecked(&work->port->
33884 counter_group[CM_RECV_DUPLICATES].
33885 counter[CM_MRA_COUNTER]);
33886 goto out;
33887 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33888 break;
33889 case IB_CM_MRA_REQ_RCVD:
33890 case IB_CM_MRA_REP_RCVD:
33891 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33892 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33893 counter[CM_MRA_COUNTER]);
33894 /* fall through */
33895 default:
33896 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33897 case IB_CM_LAP_IDLE:
33898 break;
33899 case IB_CM_MRA_LAP_SENT:
33900 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33901 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33902 counter[CM_LAP_COUNTER]);
33903 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33904 goto unlock;
33905 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33906 cm_free_msg(msg);
33907 goto deref;
33908 case IB_CM_LAP_RCVD:
33909 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33910 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33911 counter[CM_LAP_COUNTER]);
33912 goto unlock;
33913 default:
33914 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33915 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33916 if (cur_cm_id_priv) {
33917 spin_unlock_irq(&cm.lock);
33918 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33919 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33920 counter[CM_SIDR_REQ_COUNTER]);
33921 goto out; /* Duplicate message. */
33922 }
33923 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33924 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33925 msg->retries = 1;
33926
33927 - atomic_long_add(1 + msg->retries,
33928 + atomic_long_add_unchecked(1 + msg->retries,
33929 &port->counter_group[CM_XMIT].counter[attr_index]);
33930 if (msg->retries)
33931 - atomic_long_add(msg->retries,
33932 + atomic_long_add_unchecked(msg->retries,
33933 &port->counter_group[CM_XMIT_RETRIES].
33934 counter[attr_index]);
33935
33936 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
33937 }
33938
33939 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
33940 - atomic_long_inc(&port->counter_group[CM_RECV].
33941 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
33942 counter[attr_id - CM_ATTR_ID_OFFSET]);
33943
33944 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
33945 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
33946 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
33947
33948 return sprintf(buf, "%ld\n",
33949 - atomic_long_read(&group->counter[cm_attr->index]));
33950 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
33951 }
33952
33953 static const struct sysfs_ops cm_counter_ops = {
33954 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
33955 index 176c8f9..2627b62 100644
33956 --- a/drivers/infiniband/core/fmr_pool.c
33957 +++ b/drivers/infiniband/core/fmr_pool.c
33958 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
33959
33960 struct task_struct *thread;
33961
33962 - atomic_t req_ser;
33963 - atomic_t flush_ser;
33964 + atomic_unchecked_t req_ser;
33965 + atomic_unchecked_t flush_ser;
33966
33967 wait_queue_head_t force_wait;
33968 };
33969 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33970 struct ib_fmr_pool *pool = pool_ptr;
33971
33972 do {
33973 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
33974 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
33975 ib_fmr_batch_release(pool);
33976
33977 - atomic_inc(&pool->flush_ser);
33978 + atomic_inc_unchecked(&pool->flush_ser);
33979 wake_up_interruptible(&pool->force_wait);
33980
33981 if (pool->flush_function)
33982 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33983 }
33984
33985 set_current_state(TASK_INTERRUPTIBLE);
33986 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
33987 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
33988 !kthread_should_stop())
33989 schedule();
33990 __set_current_state(TASK_RUNNING);
33991 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
33992 pool->dirty_watermark = params->dirty_watermark;
33993 pool->dirty_len = 0;
33994 spin_lock_init(&pool->pool_lock);
33995 - atomic_set(&pool->req_ser, 0);
33996 - atomic_set(&pool->flush_ser, 0);
33997 + atomic_set_unchecked(&pool->req_ser, 0);
33998 + atomic_set_unchecked(&pool->flush_ser, 0);
33999 init_waitqueue_head(&pool->force_wait);
34000
34001 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34002 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34003 }
34004 spin_unlock_irq(&pool->pool_lock);
34005
34006 - serial = atomic_inc_return(&pool->req_ser);
34007 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34008 wake_up_process(pool->thread);
34009
34010 if (wait_event_interruptible(pool->force_wait,
34011 - atomic_read(&pool->flush_ser) - serial >= 0))
34012 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34013 return -EINTR;
34014
34015 return 0;
34016 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34017 } else {
34018 list_add_tail(&fmr->list, &pool->dirty_list);
34019 if (++pool->dirty_len >= pool->dirty_watermark) {
34020 - atomic_inc(&pool->req_ser);
34021 + atomic_inc_unchecked(&pool->req_ser);
34022 wake_up_process(pool->thread);
34023 }
34024 }
34025 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34026 index afd8179..598063f 100644
34027 --- a/drivers/infiniband/hw/cxgb4/mem.c
34028 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34029 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34030 int err;
34031 struct fw_ri_tpte tpt;
34032 u32 stag_idx;
34033 - static atomic_t key;
34034 + static atomic_unchecked_t key;
34035
34036 if (c4iw_fatal_error(rdev))
34037 return -EIO;
34038 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34039 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34040 rdev->stats.stag.max = rdev->stats.stag.cur;
34041 mutex_unlock(&rdev->stats.lock);
34042 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34043 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34044 }
34045 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34046 __func__, stag_state, type, pdid, stag_idx);
34047 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34048 index 79b3dbc..96e5fcc 100644
34049 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34050 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34051 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34052 struct ib_atomic_eth *ateth;
34053 struct ipath_ack_entry *e;
34054 u64 vaddr;
34055 - atomic64_t *maddr;
34056 + atomic64_unchecked_t *maddr;
34057 u64 sdata;
34058 u32 rkey;
34059 u8 next;
34060 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34061 IB_ACCESS_REMOTE_ATOMIC)))
34062 goto nack_acc_unlck;
34063 /* Perform atomic OP and save result. */
34064 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34065 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34066 sdata = be64_to_cpu(ateth->swap_data);
34067 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34068 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34069 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34070 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34071 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34072 be64_to_cpu(ateth->compare_data),
34073 sdata);
34074 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34075 index 1f95bba..9530f87 100644
34076 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34077 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34078 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34079 unsigned long flags;
34080 struct ib_wc wc;
34081 u64 sdata;
34082 - atomic64_t *maddr;
34083 + atomic64_unchecked_t *maddr;
34084 enum ib_wc_status send_status;
34085
34086 /*
34087 @@ -382,11 +382,11 @@ again:
34088 IB_ACCESS_REMOTE_ATOMIC)))
34089 goto acc_err;
34090 /* Perform atomic OP and save result. */
34091 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34092 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34093 sdata = wqe->wr.wr.atomic.compare_add;
34094 *(u64 *) sqp->s_sge.sge.vaddr =
34095 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34096 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34097 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34098 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34099 sdata, wqe->wr.wr.atomic.swap);
34100 goto send_comp;
34101 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34102 index 748db2d..5f75cc3 100644
34103 --- a/drivers/infiniband/hw/nes/nes.c
34104 +++ b/drivers/infiniband/hw/nes/nes.c
34105 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34106 LIST_HEAD(nes_adapter_list);
34107 static LIST_HEAD(nes_dev_list);
34108
34109 -atomic_t qps_destroyed;
34110 +atomic_unchecked_t qps_destroyed;
34111
34112 static unsigned int ee_flsh_adapter;
34113 static unsigned int sysfs_nonidx_addr;
34114 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34115 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34116 struct nes_adapter *nesadapter = nesdev->nesadapter;
34117
34118 - atomic_inc(&qps_destroyed);
34119 + atomic_inc_unchecked(&qps_destroyed);
34120
34121 /* Free the control structures */
34122
34123 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34124 index 33cc589..3bd6538 100644
34125 --- a/drivers/infiniband/hw/nes/nes.h
34126 +++ b/drivers/infiniband/hw/nes/nes.h
34127 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34128 extern unsigned int wqm_quanta;
34129 extern struct list_head nes_adapter_list;
34130
34131 -extern atomic_t cm_connects;
34132 -extern atomic_t cm_accepts;
34133 -extern atomic_t cm_disconnects;
34134 -extern atomic_t cm_closes;
34135 -extern atomic_t cm_connecteds;
34136 -extern atomic_t cm_connect_reqs;
34137 -extern atomic_t cm_rejects;
34138 -extern atomic_t mod_qp_timouts;
34139 -extern atomic_t qps_created;
34140 -extern atomic_t qps_destroyed;
34141 -extern atomic_t sw_qps_destroyed;
34142 +extern atomic_unchecked_t cm_connects;
34143 +extern atomic_unchecked_t cm_accepts;
34144 +extern atomic_unchecked_t cm_disconnects;
34145 +extern atomic_unchecked_t cm_closes;
34146 +extern atomic_unchecked_t cm_connecteds;
34147 +extern atomic_unchecked_t cm_connect_reqs;
34148 +extern atomic_unchecked_t cm_rejects;
34149 +extern atomic_unchecked_t mod_qp_timouts;
34150 +extern atomic_unchecked_t qps_created;
34151 +extern atomic_unchecked_t qps_destroyed;
34152 +extern atomic_unchecked_t sw_qps_destroyed;
34153 extern u32 mh_detected;
34154 extern u32 mh_pauses_sent;
34155 extern u32 cm_packets_sent;
34156 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34157 extern u32 cm_packets_received;
34158 extern u32 cm_packets_dropped;
34159 extern u32 cm_packets_retrans;
34160 -extern atomic_t cm_listens_created;
34161 -extern atomic_t cm_listens_destroyed;
34162 +extern atomic_unchecked_t cm_listens_created;
34163 +extern atomic_unchecked_t cm_listens_destroyed;
34164 extern u32 cm_backlog_drops;
34165 -extern atomic_t cm_loopbacks;
34166 -extern atomic_t cm_nodes_created;
34167 -extern atomic_t cm_nodes_destroyed;
34168 -extern atomic_t cm_accel_dropped_pkts;
34169 -extern atomic_t cm_resets_recvd;
34170 -extern atomic_t pau_qps_created;
34171 -extern atomic_t pau_qps_destroyed;
34172 +extern atomic_unchecked_t cm_loopbacks;
34173 +extern atomic_unchecked_t cm_nodes_created;
34174 +extern atomic_unchecked_t cm_nodes_destroyed;
34175 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34176 +extern atomic_unchecked_t cm_resets_recvd;
34177 +extern atomic_unchecked_t pau_qps_created;
34178 +extern atomic_unchecked_t pau_qps_destroyed;
34179
34180 extern u32 int_mod_timer_init;
34181 extern u32 int_mod_cq_depth_256;
34182 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34183 index cfaacaf..fa0722e 100644
34184 --- a/drivers/infiniband/hw/nes/nes_cm.c
34185 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34186 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34187 u32 cm_packets_retrans;
34188 u32 cm_packets_created;
34189 u32 cm_packets_received;
34190 -atomic_t cm_listens_created;
34191 -atomic_t cm_listens_destroyed;
34192 +atomic_unchecked_t cm_listens_created;
34193 +atomic_unchecked_t cm_listens_destroyed;
34194 u32 cm_backlog_drops;
34195 -atomic_t cm_loopbacks;
34196 -atomic_t cm_nodes_created;
34197 -atomic_t cm_nodes_destroyed;
34198 -atomic_t cm_accel_dropped_pkts;
34199 -atomic_t cm_resets_recvd;
34200 +atomic_unchecked_t cm_loopbacks;
34201 +atomic_unchecked_t cm_nodes_created;
34202 +atomic_unchecked_t cm_nodes_destroyed;
34203 +atomic_unchecked_t cm_accel_dropped_pkts;
34204 +atomic_unchecked_t cm_resets_recvd;
34205
34206 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34207 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34208 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34209
34210 static struct nes_cm_core *g_cm_core;
34211
34212 -atomic_t cm_connects;
34213 -atomic_t cm_accepts;
34214 -atomic_t cm_disconnects;
34215 -atomic_t cm_closes;
34216 -atomic_t cm_connecteds;
34217 -atomic_t cm_connect_reqs;
34218 -atomic_t cm_rejects;
34219 +atomic_unchecked_t cm_connects;
34220 +atomic_unchecked_t cm_accepts;
34221 +atomic_unchecked_t cm_disconnects;
34222 +atomic_unchecked_t cm_closes;
34223 +atomic_unchecked_t cm_connecteds;
34224 +atomic_unchecked_t cm_connect_reqs;
34225 +atomic_unchecked_t cm_rejects;
34226
34227 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34228 {
34229 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34230 kfree(listener);
34231 listener = NULL;
34232 ret = 0;
34233 - atomic_inc(&cm_listens_destroyed);
34234 + atomic_inc_unchecked(&cm_listens_destroyed);
34235 } else {
34236 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34237 }
34238 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34239 cm_node->rem_mac);
34240
34241 add_hte_node(cm_core, cm_node);
34242 - atomic_inc(&cm_nodes_created);
34243 + atomic_inc_unchecked(&cm_nodes_created);
34244
34245 return cm_node;
34246 }
34247 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34248 }
34249
34250 atomic_dec(&cm_core->node_cnt);
34251 - atomic_inc(&cm_nodes_destroyed);
34252 + atomic_inc_unchecked(&cm_nodes_destroyed);
34253 nesqp = cm_node->nesqp;
34254 if (nesqp) {
34255 nesqp->cm_node = NULL;
34256 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34257
34258 static void drop_packet(struct sk_buff *skb)
34259 {
34260 - atomic_inc(&cm_accel_dropped_pkts);
34261 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34262 dev_kfree_skb_any(skb);
34263 }
34264
34265 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34266 {
34267
34268 int reset = 0; /* whether to send reset in case of err.. */
34269 - atomic_inc(&cm_resets_recvd);
34270 + atomic_inc_unchecked(&cm_resets_recvd);
34271 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34272 " refcnt=%d\n", cm_node, cm_node->state,
34273 atomic_read(&cm_node->ref_count));
34274 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34275 rem_ref_cm_node(cm_node->cm_core, cm_node);
34276 return NULL;
34277 }
34278 - atomic_inc(&cm_loopbacks);
34279 + atomic_inc_unchecked(&cm_loopbacks);
34280 loopbackremotenode->loopbackpartner = cm_node;
34281 loopbackremotenode->tcp_cntxt.rcv_wscale =
34282 NES_CM_DEFAULT_RCV_WND_SCALE;
34283 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34284 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34285 else {
34286 rem_ref_cm_node(cm_core, cm_node);
34287 - atomic_inc(&cm_accel_dropped_pkts);
34288 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34289 dev_kfree_skb_any(skb);
34290 }
34291 break;
34292 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34293
34294 if ((cm_id) && (cm_id->event_handler)) {
34295 if (issue_disconn) {
34296 - atomic_inc(&cm_disconnects);
34297 + atomic_inc_unchecked(&cm_disconnects);
34298 cm_event.event = IW_CM_EVENT_DISCONNECT;
34299 cm_event.status = disconn_status;
34300 cm_event.local_addr = cm_id->local_addr;
34301 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34302 }
34303
34304 if (issue_close) {
34305 - atomic_inc(&cm_closes);
34306 + atomic_inc_unchecked(&cm_closes);
34307 nes_disconnect(nesqp, 1);
34308
34309 cm_id->provider_data = nesqp;
34310 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34311
34312 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34313 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34314 - atomic_inc(&cm_accepts);
34315 + atomic_inc_unchecked(&cm_accepts);
34316
34317 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34318 netdev_refcnt_read(nesvnic->netdev));
34319 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34320 struct nes_cm_core *cm_core;
34321 u8 *start_buff;
34322
34323 - atomic_inc(&cm_rejects);
34324 + atomic_inc_unchecked(&cm_rejects);
34325 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34326 loopback = cm_node->loopbackpartner;
34327 cm_core = cm_node->cm_core;
34328 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34329 ntohl(cm_id->local_addr.sin_addr.s_addr),
34330 ntohs(cm_id->local_addr.sin_port));
34331
34332 - atomic_inc(&cm_connects);
34333 + atomic_inc_unchecked(&cm_connects);
34334 nesqp->active_conn = 1;
34335
34336 /* cache the cm_id in the qp */
34337 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34338 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34339 return err;
34340 }
34341 - atomic_inc(&cm_listens_created);
34342 + atomic_inc_unchecked(&cm_listens_created);
34343 }
34344
34345 cm_id->add_ref(cm_id);
34346 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34347
34348 if (nesqp->destroyed)
34349 return;
34350 - atomic_inc(&cm_connecteds);
34351 + atomic_inc_unchecked(&cm_connecteds);
34352 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34353 " local port 0x%04X. jiffies = %lu.\n",
34354 nesqp->hwqp.qp_id,
34355 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34356
34357 cm_id->add_ref(cm_id);
34358 ret = cm_id->event_handler(cm_id, &cm_event);
34359 - atomic_inc(&cm_closes);
34360 + atomic_inc_unchecked(&cm_closes);
34361 cm_event.event = IW_CM_EVENT_CLOSE;
34362 cm_event.status = 0;
34363 cm_event.provider_data = cm_id->provider_data;
34364 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34365 return;
34366 cm_id = cm_node->cm_id;
34367
34368 - atomic_inc(&cm_connect_reqs);
34369 + atomic_inc_unchecked(&cm_connect_reqs);
34370 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34371 cm_node, cm_id, jiffies);
34372
34373 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34374 return;
34375 cm_id = cm_node->cm_id;
34376
34377 - atomic_inc(&cm_connect_reqs);
34378 + atomic_inc_unchecked(&cm_connect_reqs);
34379 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34380 cm_node, cm_id, jiffies);
34381
34382 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34383 index 3ba7be3..c81f6ff 100644
34384 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34385 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34386 @@ -40,8 +40,8 @@
34387 #include "nes.h"
34388 #include "nes_mgt.h"
34389
34390 -atomic_t pau_qps_created;
34391 -atomic_t pau_qps_destroyed;
34392 +atomic_unchecked_t pau_qps_created;
34393 +atomic_unchecked_t pau_qps_destroyed;
34394
34395 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34396 {
34397 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34398 {
34399 struct sk_buff *skb;
34400 unsigned long flags;
34401 - atomic_inc(&pau_qps_destroyed);
34402 + atomic_inc_unchecked(&pau_qps_destroyed);
34403
34404 /* Free packets that have not yet been forwarded */
34405 /* Lock is acquired by skb_dequeue when removing the skb */
34406 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34407 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34408 skb_queue_head_init(&nesqp->pau_list);
34409 spin_lock_init(&nesqp->pau_lock);
34410 - atomic_inc(&pau_qps_created);
34411 + atomic_inc_unchecked(&pau_qps_created);
34412 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34413 }
34414
34415 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34416 index 0564be7..f68b0f1 100644
34417 --- a/drivers/infiniband/hw/nes/nes_nic.c
34418 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34419 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34420 target_stat_values[++index] = mh_detected;
34421 target_stat_values[++index] = mh_pauses_sent;
34422 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34423 - target_stat_values[++index] = atomic_read(&cm_connects);
34424 - target_stat_values[++index] = atomic_read(&cm_accepts);
34425 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34426 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34427 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34428 - target_stat_values[++index] = atomic_read(&cm_rejects);
34429 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34430 - target_stat_values[++index] = atomic_read(&qps_created);
34431 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34432 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34433 - target_stat_values[++index] = atomic_read(&cm_closes);
34434 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34435 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34436 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34437 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34438 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34439 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34440 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34441 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34442 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34443 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34444 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34445 target_stat_values[++index] = cm_packets_sent;
34446 target_stat_values[++index] = cm_packets_bounced;
34447 target_stat_values[++index] = cm_packets_created;
34448 target_stat_values[++index] = cm_packets_received;
34449 target_stat_values[++index] = cm_packets_dropped;
34450 target_stat_values[++index] = cm_packets_retrans;
34451 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34452 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34453 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34454 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34455 target_stat_values[++index] = cm_backlog_drops;
34456 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34457 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34458 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34459 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34460 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34461 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34462 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34463 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34464 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34465 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34466 target_stat_values[++index] = nesadapter->free_4kpbl;
34467 target_stat_values[++index] = nesadapter->free_256pbl;
34468 target_stat_values[++index] = int_mod_timer_init;
34469 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34470 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34471 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34472 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34473 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34474 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34475 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34476 }
34477
34478 /**
34479 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34480 index 07e4fba..685f041 100644
34481 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34482 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34483 @@ -46,9 +46,9 @@
34484
34485 #include <rdma/ib_umem.h>
34486
34487 -atomic_t mod_qp_timouts;
34488 -atomic_t qps_created;
34489 -atomic_t sw_qps_destroyed;
34490 +atomic_unchecked_t mod_qp_timouts;
34491 +atomic_unchecked_t qps_created;
34492 +atomic_unchecked_t sw_qps_destroyed;
34493
34494 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34495
34496 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34497 if (init_attr->create_flags)
34498 return ERR_PTR(-EINVAL);
34499
34500 - atomic_inc(&qps_created);
34501 + atomic_inc_unchecked(&qps_created);
34502 switch (init_attr->qp_type) {
34503 case IB_QPT_RC:
34504 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34505 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34506 struct iw_cm_event cm_event;
34507 int ret = 0;
34508
34509 - atomic_inc(&sw_qps_destroyed);
34510 + atomic_inc_unchecked(&sw_qps_destroyed);
34511 nesqp->destroyed = 1;
34512
34513 /* Blow away the connection if it exists. */
34514 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34515 index 4d11575..3e890e5 100644
34516 --- a/drivers/infiniband/hw/qib/qib.h
34517 +++ b/drivers/infiniband/hw/qib/qib.h
34518 @@ -51,6 +51,7 @@
34519 #include <linux/completion.h>
34520 #include <linux/kref.h>
34521 #include <linux/sched.h>
34522 +#include <linux/slab.h>
34523
34524 #include "qib_common.h"
34525 #include "qib_verbs.h"
34526 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34527 index da739d9..da1c7f4 100644
34528 --- a/drivers/input/gameport/gameport.c
34529 +++ b/drivers/input/gameport/gameport.c
34530 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34531 */
34532 static void gameport_init_port(struct gameport *gameport)
34533 {
34534 - static atomic_t gameport_no = ATOMIC_INIT(0);
34535 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34536
34537 __module_get(THIS_MODULE);
34538
34539 mutex_init(&gameport->drv_mutex);
34540 device_initialize(&gameport->dev);
34541 dev_set_name(&gameport->dev, "gameport%lu",
34542 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34543 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34544 gameport->dev.bus = &gameport_bus;
34545 gameport->dev.release = gameport_release_port;
34546 if (gameport->parent)
34547 diff --git a/drivers/input/input.c b/drivers/input/input.c
34548 index 53a0dde..abffda7 100644
34549 --- a/drivers/input/input.c
34550 +++ b/drivers/input/input.c
34551 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34552 */
34553 int input_register_device(struct input_dev *dev)
34554 {
34555 - static atomic_t input_no = ATOMIC_INIT(0);
34556 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34557 struct input_handler *handler;
34558 unsigned int packet_size;
34559 const char *path;
34560 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34561 dev->setkeycode = input_default_setkeycode;
34562
34563 dev_set_name(&dev->dev, "input%ld",
34564 - (unsigned long) atomic_inc_return(&input_no) - 1);
34565 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34566
34567 error = device_add(&dev->dev);
34568 if (error)
34569 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34570 index 04c69af..5f92d00 100644
34571 --- a/drivers/input/joystick/sidewinder.c
34572 +++ b/drivers/input/joystick/sidewinder.c
34573 @@ -30,6 +30,7 @@
34574 #include <linux/kernel.h>
34575 #include <linux/module.h>
34576 #include <linux/slab.h>
34577 +#include <linux/sched.h>
34578 #include <linux/init.h>
34579 #include <linux/input.h>
34580 #include <linux/gameport.h>
34581 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34582 index 83811e4..0822b90 100644
34583 --- a/drivers/input/joystick/xpad.c
34584 +++ b/drivers/input/joystick/xpad.c
34585 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34586
34587 static int xpad_led_probe(struct usb_xpad *xpad)
34588 {
34589 - static atomic_t led_seq = ATOMIC_INIT(0);
34590 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34591 long led_no;
34592 struct xpad_led *led;
34593 struct led_classdev *led_cdev;
34594 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34595 if (!led)
34596 return -ENOMEM;
34597
34598 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34599 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34600
34601 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34602 led->xpad = xpad;
34603 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34604 index 4c842c3..590b0bf 100644
34605 --- a/drivers/input/mousedev.c
34606 +++ b/drivers/input/mousedev.c
34607 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34608
34609 spin_unlock_irq(&client->packet_lock);
34610
34611 - if (copy_to_user(buffer, data, count))
34612 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34613 return -EFAULT;
34614
34615 return count;
34616 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34617 index d0f7533..fb8215b 100644
34618 --- a/drivers/input/serio/serio.c
34619 +++ b/drivers/input/serio/serio.c
34620 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34621 */
34622 static void serio_init_port(struct serio *serio)
34623 {
34624 - static atomic_t serio_no = ATOMIC_INIT(0);
34625 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34626
34627 __module_get(THIS_MODULE);
34628
34629 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34630 mutex_init(&serio->drv_mutex);
34631 device_initialize(&serio->dev);
34632 dev_set_name(&serio->dev, "serio%ld",
34633 - (long)atomic_inc_return(&serio_no) - 1);
34634 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34635 serio->dev.bus = &serio_bus;
34636 serio->dev.release = serio_release_port;
34637 serio->dev.groups = serio_device_attr_groups;
34638 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34639 index 81837b0..d7470e8 100644
34640 --- a/drivers/iommu/amd_iommu_init.c
34641 +++ b/drivers/iommu/amd_iommu_init.c
34642 @@ -1888,7 +1888,7 @@ static int __init state_next(void)
34643 case IOMMU_ACPI_FINISHED:
34644 early_enable_iommus();
34645 register_syscore_ops(&amd_iommu_syscore_ops);
34646 - x86_platform.iommu_shutdown = disable_iommus;
34647 + *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34648 init_state = IOMMU_ENABLED;
34649 break;
34650 case IOMMU_ENABLED:
34651 @@ -2030,7 +2030,7 @@ int __init amd_iommu_detect(void)
34652
34653 amd_iommu_detected = true;
34654 iommu_detected = 1;
34655 - x86_init.iommu.iommu_init = amd_iommu_init;
34656 + *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34657
34658 return 0;
34659 }
34660 diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34661 index 86e2f4a..d1cec5d 100644
34662 --- a/drivers/iommu/dmar.c
34663 +++ b/drivers/iommu/dmar.c
34664 @@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34665
34666 #ifdef CONFIG_X86
34667 if (ret)
34668 - x86_init.iommu.iommu_init = intel_iommu_init;
34669 + *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34670 #endif
34671 }
34672 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34673 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34674 index c679867..6e2e34d 100644
34675 --- a/drivers/isdn/capi/capi.c
34676 +++ b/drivers/isdn/capi/capi.c
34677 @@ -83,8 +83,8 @@ struct capiminor {
34678
34679 struct capi20_appl *ap;
34680 u32 ncci;
34681 - atomic_t datahandle;
34682 - atomic_t msgid;
34683 + atomic_unchecked_t datahandle;
34684 + atomic_unchecked_t msgid;
34685
34686 struct tty_port port;
34687 int ttyinstop;
34688 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34689 capimsg_setu16(s, 2, mp->ap->applid);
34690 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34691 capimsg_setu8 (s, 5, CAPI_RESP);
34692 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34693 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34694 capimsg_setu32(s, 8, mp->ncci);
34695 capimsg_setu16(s, 12, datahandle);
34696 }
34697 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34698 mp->outbytes -= len;
34699 spin_unlock_bh(&mp->outlock);
34700
34701 - datahandle = atomic_inc_return(&mp->datahandle);
34702 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34703 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34704 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34705 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34706 capimsg_setu16(skb->data, 2, mp->ap->applid);
34707 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34708 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34709 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34710 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34711 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34712 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34713 capimsg_setu16(skb->data, 16, len); /* Data length */
34714 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34715 index 67abf3f..076b3a6 100644
34716 --- a/drivers/isdn/gigaset/interface.c
34717 +++ b/drivers/isdn/gigaset/interface.c
34718 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34719 }
34720 tty->driver_data = cs;
34721
34722 - ++cs->port.count;
34723 + atomic_inc(&cs->port.count);
34724
34725 - if (cs->port.count == 1) {
34726 + if (atomic_read(&cs->port.count) == 1) {
34727 tty_port_tty_set(&cs->port, tty);
34728 tty->low_latency = 1;
34729 }
34730 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34731
34732 if (!cs->connected)
34733 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34734 - else if (!cs->port.count)
34735 + else if (!atomic_read(&cs->port.count))
34736 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34737 - else if (!--cs->port.count)
34738 + else if (!atomic_dec_return(&cs->port.count))
34739 tty_port_tty_set(&cs->port, NULL);
34740
34741 mutex_unlock(&cs->mutex);
34742 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34743 index 821f7ac..28d4030 100644
34744 --- a/drivers/isdn/hardware/avm/b1.c
34745 +++ b/drivers/isdn/hardware/avm/b1.c
34746 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34747 }
34748 if (left) {
34749 if (t4file->user) {
34750 - if (copy_from_user(buf, dp, left))
34751 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34752 return -EFAULT;
34753 } else {
34754 memcpy(buf, dp, left);
34755 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34756 }
34757 if (left) {
34758 if (config->user) {
34759 - if (copy_from_user(buf, dp, left))
34760 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34761 return -EFAULT;
34762 } else {
34763 memcpy(buf, dp, left);
34764 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34765 index b817809..409caff 100644
34766 --- a/drivers/isdn/i4l/isdn_tty.c
34767 +++ b/drivers/isdn/i4l/isdn_tty.c
34768 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34769
34770 #ifdef ISDN_DEBUG_MODEM_OPEN
34771 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34772 - port->count);
34773 + atomic_read(&port->count));
34774 #endif
34775 - port->count++;
34776 + atomic_inc(&port->count);
34777 port->tty = tty;
34778 /*
34779 * Start up serial port
34780 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34781 #endif
34782 return;
34783 }
34784 - if ((tty->count == 1) && (port->count != 1)) {
34785 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34786 /*
34787 * Uh, oh. tty->count is 1, which means that the tty
34788 * structure will be freed. Info->count should always
34789 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34790 * serial port won't be shutdown.
34791 */
34792 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34793 - "info->count is %d\n", port->count);
34794 - port->count = 1;
34795 + "info->count is %d\n", atomic_read(&port->count));
34796 + atomic_set(&port->count, 1);
34797 }
34798 - if (--port->count < 0) {
34799 + if (atomic_dec_return(&port->count) < 0) {
34800 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34801 - info->line, port->count);
34802 - port->count = 0;
34803 + info->line, atomic_read(&port->count));
34804 + atomic_set(&port->count, 0);
34805 }
34806 - if (port->count) {
34807 + if (atomic_read(&port->count)) {
34808 #ifdef ISDN_DEBUG_MODEM_OPEN
34809 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34810 #endif
34811 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34812 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34813 return;
34814 isdn_tty_shutdown(info);
34815 - port->count = 0;
34816 + atomic_set(&port->count, 0);
34817 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34818 port->tty = NULL;
34819 wake_up_interruptible(&port->open_wait);
34820 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34821 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34822 modem_info *info = &dev->mdm.info[i];
34823
34824 - if (info->port.count == 0)
34825 + if (atomic_read(&info->port.count) == 0)
34826 continue;
34827 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34828 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34829 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34830 index e74df7c..03a03ba 100644
34831 --- a/drivers/isdn/icn/icn.c
34832 +++ b/drivers/isdn/icn/icn.c
34833 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34834 if (count > len)
34835 count = len;
34836 if (user) {
34837 - if (copy_from_user(msg, buf, count))
34838 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34839 return -EFAULT;
34840 } else
34841 memcpy(msg, buf, count);
34842 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34843 index b5fdcb7..5b6c59f 100644
34844 --- a/drivers/lguest/core.c
34845 +++ b/drivers/lguest/core.c
34846 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34847 * it's worked so far. The end address needs +1 because __get_vm_area
34848 * allocates an extra guard page, so we need space for that.
34849 */
34850 +
34851 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34852 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34853 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34854 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34855 +#else
34856 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34857 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34858 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34859 +#endif
34860 +
34861 if (!switcher_vma) {
34862 err = -ENOMEM;
34863 printk("lguest: could not map switcher pages high\n");
34864 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34865 * Now the Switcher is mapped at the right address, we can't fail!
34866 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34867 */
34868 - memcpy(switcher_vma->addr, start_switcher_text,
34869 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34870 end_switcher_text - start_switcher_text);
34871
34872 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34873 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34874 index 4af12e1..0e89afe 100644
34875 --- a/drivers/lguest/x86/core.c
34876 +++ b/drivers/lguest/x86/core.c
34877 @@ -59,7 +59,7 @@ static struct {
34878 /* Offset from where switcher.S was compiled to where we've copied it */
34879 static unsigned long switcher_offset(void)
34880 {
34881 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34882 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34883 }
34884
34885 /* This cpu's struct lguest_pages. */
34886 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34887 * These copies are pretty cheap, so we do them unconditionally: */
34888 /* Save the current Host top-level page directory.
34889 */
34890 +
34891 +#ifdef CONFIG_PAX_PER_CPU_PGD
34892 + pages->state.host_cr3 = read_cr3();
34893 +#else
34894 pages->state.host_cr3 = __pa(current->mm->pgd);
34895 +#endif
34896 +
34897 /*
34898 * Set up the Guest's page tables to see this CPU's pages (and no
34899 * other CPU's pages).
34900 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34901 * compiled-in switcher code and the high-mapped copy we just made.
34902 */
34903 for (i = 0; i < IDT_ENTRIES; i++)
34904 - default_idt_entries[i] += switcher_offset();
34905 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34906
34907 /*
34908 * Set up the Switcher's per-cpu areas.
34909 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34910 * it will be undisturbed when we switch. To change %cs and jump we
34911 * need this structure to feed to Intel's "lcall" instruction.
34912 */
34913 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34914 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34915 lguest_entry.segment = LGUEST_CS;
34916
34917 /*
34918 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34919 index 40634b0..4f5855e 100644
34920 --- a/drivers/lguest/x86/switcher_32.S
34921 +++ b/drivers/lguest/x86/switcher_32.S
34922 @@ -87,6 +87,7 @@
34923 #include <asm/page.h>
34924 #include <asm/segment.h>
34925 #include <asm/lguest.h>
34926 +#include <asm/processor-flags.h>
34927
34928 // We mark the start of the code to copy
34929 // It's placed in .text tho it's never run here
34930 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
34931 // Changes type when we load it: damn Intel!
34932 // For after we switch over our page tables
34933 // That entry will be read-only: we'd crash.
34934 +
34935 +#ifdef CONFIG_PAX_KERNEXEC
34936 + mov %cr0, %edx
34937 + xor $X86_CR0_WP, %edx
34938 + mov %edx, %cr0
34939 +#endif
34940 +
34941 movl $(GDT_ENTRY_TSS*8), %edx
34942 ltr %dx
34943
34944 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
34945 // Let's clear it again for our return.
34946 // The GDT descriptor of the Host
34947 // Points to the table after two "size" bytes
34948 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
34949 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
34950 // Clear "used" from type field (byte 5, bit 2)
34951 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
34952 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
34953 +
34954 +#ifdef CONFIG_PAX_KERNEXEC
34955 + mov %cr0, %eax
34956 + xor $X86_CR0_WP, %eax
34957 + mov %eax, %cr0
34958 +#endif
34959
34960 // Once our page table's switched, the Guest is live!
34961 // The Host fades as we run this final step.
34962 @@ -295,13 +309,12 @@ deliver_to_host:
34963 // I consulted gcc, and it gave
34964 // These instructions, which I gladly credit:
34965 leal (%edx,%ebx,8), %eax
34966 - movzwl (%eax),%edx
34967 - movl 4(%eax), %eax
34968 - xorw %ax, %ax
34969 - orl %eax, %edx
34970 + movl 4(%eax), %edx
34971 + movw (%eax), %dx
34972 // Now the address of the handler's in %edx
34973 // We call it now: its "iret" drops us home.
34974 - jmp *%edx
34975 + ljmp $__KERNEL_CS, $1f
34976 +1: jmp *%edx
34977
34978 // Every interrupt can come to us here
34979 // But we must truly tell each apart.
34980 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
34981 index 7155945..4bcc562 100644
34982 --- a/drivers/md/bitmap.c
34983 +++ b/drivers/md/bitmap.c
34984 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
34985 chunk_kb ? "KB" : "B");
34986 if (bitmap->storage.file) {
34987 seq_printf(seq, ", file: ");
34988 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
34989 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
34990 }
34991
34992 seq_printf(seq, "\n");
34993 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
34994 index a651d52..82f8a95 100644
34995 --- a/drivers/md/dm-ioctl.c
34996 +++ b/drivers/md/dm-ioctl.c
34997 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
34998 cmd == DM_LIST_VERSIONS_CMD)
34999 return 0;
35000
35001 - if ((cmd == DM_DEV_CREATE_CMD)) {
35002 + if (cmd == DM_DEV_CREATE_CMD) {
35003 if (!*param->name) {
35004 DMWARN("name not supplied when creating device");
35005 return -EINVAL;
35006 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35007 index fd61f98..8050783 100644
35008 --- a/drivers/md/dm-raid1.c
35009 +++ b/drivers/md/dm-raid1.c
35010 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35011
35012 struct mirror {
35013 struct mirror_set *ms;
35014 - atomic_t error_count;
35015 + atomic_unchecked_t error_count;
35016 unsigned long error_type;
35017 struct dm_dev *dev;
35018 sector_t offset;
35019 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35020 struct mirror *m;
35021
35022 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35023 - if (!atomic_read(&m->error_count))
35024 + if (!atomic_read_unchecked(&m->error_count))
35025 return m;
35026
35027 return NULL;
35028 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35029 * simple way to tell if a device has encountered
35030 * errors.
35031 */
35032 - atomic_inc(&m->error_count);
35033 + atomic_inc_unchecked(&m->error_count);
35034
35035 if (test_and_set_bit(error_type, &m->error_type))
35036 return;
35037 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35038 struct mirror *m = get_default_mirror(ms);
35039
35040 do {
35041 - if (likely(!atomic_read(&m->error_count)))
35042 + if (likely(!atomic_read_unchecked(&m->error_count)))
35043 return m;
35044
35045 if (m-- == ms->mirror)
35046 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35047 {
35048 struct mirror *default_mirror = get_default_mirror(m->ms);
35049
35050 - return !atomic_read(&default_mirror->error_count);
35051 + return !atomic_read_unchecked(&default_mirror->error_count);
35052 }
35053
35054 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35055 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35056 */
35057 if (likely(region_in_sync(ms, region, 1)))
35058 m = choose_mirror(ms, bio->bi_sector);
35059 - else if (m && atomic_read(&m->error_count))
35060 + else if (m && atomic_read_unchecked(&m->error_count))
35061 m = NULL;
35062
35063 if (likely(m))
35064 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35065 }
35066
35067 ms->mirror[mirror].ms = ms;
35068 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35069 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35070 ms->mirror[mirror].error_type = 0;
35071 ms->mirror[mirror].offset = offset;
35072
35073 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35074 */
35075 static char device_status_char(struct mirror *m)
35076 {
35077 - if (!atomic_read(&(m->error_count)))
35078 + if (!atomic_read_unchecked(&(m->error_count)))
35079 return 'A';
35080
35081 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35082 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35083 index e2f87653..f279abe 100644
35084 --- a/drivers/md/dm-stripe.c
35085 +++ b/drivers/md/dm-stripe.c
35086 @@ -20,7 +20,7 @@ struct stripe {
35087 struct dm_dev *dev;
35088 sector_t physical_start;
35089
35090 - atomic_t error_count;
35091 + atomic_unchecked_t error_count;
35092 };
35093
35094 struct stripe_c {
35095 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35096 kfree(sc);
35097 return r;
35098 }
35099 - atomic_set(&(sc->stripe[i].error_count), 0);
35100 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35101 }
35102
35103 ti->private = sc;
35104 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35105 DMEMIT("%d ", sc->stripes);
35106 for (i = 0; i < sc->stripes; i++) {
35107 DMEMIT("%s ", sc->stripe[i].dev->name);
35108 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35109 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35110 'D' : 'A';
35111 }
35112 buffer[i] = '\0';
35113 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35114 */
35115 for (i = 0; i < sc->stripes; i++)
35116 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35117 - atomic_inc(&(sc->stripe[i].error_count));
35118 - if (atomic_read(&(sc->stripe[i].error_count)) <
35119 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35120 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35121 DM_IO_ERROR_THRESHOLD)
35122 schedule_work(&sc->trigger_event);
35123 }
35124 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35125 index fa29557..d24a5b7 100644
35126 --- a/drivers/md/dm-table.c
35127 +++ b/drivers/md/dm-table.c
35128 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35129 if (!dev_size)
35130 return 0;
35131
35132 - if ((start >= dev_size) || (start + len > dev_size)) {
35133 + if ((start >= dev_size) || (len > dev_size - start)) {
35134 DMWARN("%s: %s too small for target: "
35135 "start=%llu, len=%llu, dev_size=%llu",
35136 dm_device_name(ti->table->md), bdevname(bdev, b),
35137 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35138 index 693e149..b7e0fde 100644
35139 --- a/drivers/md/dm-thin-metadata.c
35140 +++ b/drivers/md/dm-thin-metadata.c
35141 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35142 {
35143 pmd->info.tm = pmd->tm;
35144 pmd->info.levels = 2;
35145 - pmd->info.value_type.context = pmd->data_sm;
35146 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35147 pmd->info.value_type.size = sizeof(__le64);
35148 pmd->info.value_type.inc = data_block_inc;
35149 pmd->info.value_type.dec = data_block_dec;
35150 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35151
35152 pmd->bl_info.tm = pmd->tm;
35153 pmd->bl_info.levels = 1;
35154 - pmd->bl_info.value_type.context = pmd->data_sm;
35155 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35156 pmd->bl_info.value_type.size = sizeof(__le64);
35157 pmd->bl_info.value_type.inc = data_block_inc;
35158 pmd->bl_info.value_type.dec = data_block_dec;
35159 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35160 index 77e6eff..913d695 100644
35161 --- a/drivers/md/dm.c
35162 +++ b/drivers/md/dm.c
35163 @@ -182,9 +182,9 @@ struct mapped_device {
35164 /*
35165 * Event handling.
35166 */
35167 - atomic_t event_nr;
35168 + atomic_unchecked_t event_nr;
35169 wait_queue_head_t eventq;
35170 - atomic_t uevent_seq;
35171 + atomic_unchecked_t uevent_seq;
35172 struct list_head uevent_list;
35173 spinlock_t uevent_lock; /* Protect access to uevent_list */
35174
35175 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35176 rwlock_init(&md->map_lock);
35177 atomic_set(&md->holders, 1);
35178 atomic_set(&md->open_count, 0);
35179 - atomic_set(&md->event_nr, 0);
35180 - atomic_set(&md->uevent_seq, 0);
35181 + atomic_set_unchecked(&md->event_nr, 0);
35182 + atomic_set_unchecked(&md->uevent_seq, 0);
35183 INIT_LIST_HEAD(&md->uevent_list);
35184 spin_lock_init(&md->uevent_lock);
35185
35186 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35187
35188 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35189
35190 - atomic_inc(&md->event_nr);
35191 + atomic_inc_unchecked(&md->event_nr);
35192 wake_up(&md->eventq);
35193 }
35194
35195 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35196
35197 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35198 {
35199 - return atomic_add_return(1, &md->uevent_seq);
35200 + return atomic_add_return_unchecked(1, &md->uevent_seq);
35201 }
35202
35203 uint32_t dm_get_event_nr(struct mapped_device *md)
35204 {
35205 - return atomic_read(&md->event_nr);
35206 + return atomic_read_unchecked(&md->event_nr);
35207 }
35208
35209 int dm_wait_event(struct mapped_device *md, int event_nr)
35210 {
35211 return wait_event_interruptible(md->eventq,
35212 - (event_nr != atomic_read(&md->event_nr)));
35213 + (event_nr != atomic_read_unchecked(&md->event_nr)));
35214 }
35215
35216 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35217 diff --git a/drivers/md/md.c b/drivers/md/md.c
35218 index 6120071..31d9be2 100644
35219 --- a/drivers/md/md.c
35220 +++ b/drivers/md/md.c
35221 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35222 * start build, activate spare
35223 */
35224 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35225 -static atomic_t md_event_count;
35226 +static atomic_unchecked_t md_event_count;
35227 void md_new_event(struct mddev *mddev)
35228 {
35229 - atomic_inc(&md_event_count);
35230 + atomic_inc_unchecked(&md_event_count);
35231 wake_up(&md_event_waiters);
35232 }
35233 EXPORT_SYMBOL_GPL(md_new_event);
35234 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35235 */
35236 static void md_new_event_inintr(struct mddev *mddev)
35237 {
35238 - atomic_inc(&md_event_count);
35239 + atomic_inc_unchecked(&md_event_count);
35240 wake_up(&md_event_waiters);
35241 }
35242
35243 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35244 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35245 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35246 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35247 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35248 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35249
35250 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35251 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35252 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35253 else
35254 sb->resync_offset = cpu_to_le64(0);
35255
35256 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35257 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35258
35259 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35260 sb->size = cpu_to_le64(mddev->dev_sectors);
35261 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35262 static ssize_t
35263 errors_show(struct md_rdev *rdev, char *page)
35264 {
35265 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35266 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35267 }
35268
35269 static ssize_t
35270 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35271 char *e;
35272 unsigned long n = simple_strtoul(buf, &e, 10);
35273 if (*buf && (*e == 0 || *e == '\n')) {
35274 - atomic_set(&rdev->corrected_errors, n);
35275 + atomic_set_unchecked(&rdev->corrected_errors, n);
35276 return len;
35277 }
35278 return -EINVAL;
35279 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35280 rdev->sb_loaded = 0;
35281 rdev->bb_page = NULL;
35282 atomic_set(&rdev->nr_pending, 0);
35283 - atomic_set(&rdev->read_errors, 0);
35284 - atomic_set(&rdev->corrected_errors, 0);
35285 + atomic_set_unchecked(&rdev->read_errors, 0);
35286 + atomic_set_unchecked(&rdev->corrected_errors, 0);
35287
35288 INIT_LIST_HEAD(&rdev->same_set);
35289 init_waitqueue_head(&rdev->blocked_wait);
35290 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35291
35292 spin_unlock(&pers_lock);
35293 seq_printf(seq, "\n");
35294 - seq->poll_event = atomic_read(&md_event_count);
35295 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35296 return 0;
35297 }
35298 if (v == (void*)2) {
35299 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35300 return error;
35301
35302 seq = file->private_data;
35303 - seq->poll_event = atomic_read(&md_event_count);
35304 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35305 return error;
35306 }
35307
35308 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35309 /* always allow read */
35310 mask = POLLIN | POLLRDNORM;
35311
35312 - if (seq->poll_event != atomic_read(&md_event_count))
35313 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35314 mask |= POLLERR | POLLPRI;
35315 return mask;
35316 }
35317 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35318 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35319 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35320 (int)part_stat_read(&disk->part0, sectors[1]) -
35321 - atomic_read(&disk->sync_io);
35322 + atomic_read_unchecked(&disk->sync_io);
35323 /* sync IO will cause sync_io to increase before the disk_stats
35324 * as sync_io is counted when a request starts, and
35325 * disk_stats is counted when it completes.
35326 diff --git a/drivers/md/md.h b/drivers/md/md.h
35327 index af443ab..0f93be3 100644
35328 --- a/drivers/md/md.h
35329 +++ b/drivers/md/md.h
35330 @@ -94,13 +94,13 @@ struct md_rdev {
35331 * only maintained for arrays that
35332 * support hot removal
35333 */
35334 - atomic_t read_errors; /* number of consecutive read errors that
35335 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35336 * we have tried to ignore.
35337 */
35338 struct timespec last_read_error; /* monotonic time since our
35339 * last read error
35340 */
35341 - atomic_t corrected_errors; /* number of corrected read errors,
35342 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35343 * for reporting to userspace and storing
35344 * in superblock.
35345 */
35346 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35347
35348 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35349 {
35350 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35351 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35352 }
35353
35354 struct md_personality
35355 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35356 index 1cbfc6b..56e1dbb 100644
35357 --- a/drivers/md/persistent-data/dm-space-map.h
35358 +++ b/drivers/md/persistent-data/dm-space-map.h
35359 @@ -60,6 +60,7 @@ struct dm_space_map {
35360 int (*root_size)(struct dm_space_map *sm, size_t *result);
35361 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35362 };
35363 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35364
35365 /*----------------------------------------------------------------*/
35366
35367 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35368 index a0f7309..5599dbc 100644
35369 --- a/drivers/md/raid1.c
35370 +++ b/drivers/md/raid1.c
35371 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35372 if (r1_sync_page_io(rdev, sect, s,
35373 bio->bi_io_vec[idx].bv_page,
35374 READ) != 0)
35375 - atomic_add(s, &rdev->corrected_errors);
35376 + atomic_add_unchecked(s, &rdev->corrected_errors);
35377 }
35378 sectors -= s;
35379 sect += s;
35380 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35381 test_bit(In_sync, &rdev->flags)) {
35382 if (r1_sync_page_io(rdev, sect, s,
35383 conf->tmppage, READ)) {
35384 - atomic_add(s, &rdev->corrected_errors);
35385 + atomic_add_unchecked(s, &rdev->corrected_errors);
35386 printk(KERN_INFO
35387 "md/raid1:%s: read error corrected "
35388 "(%d sectors at %llu on %s)\n",
35389 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35390 index c9acbd7..386cd3e 100644
35391 --- a/drivers/md/raid10.c
35392 +++ b/drivers/md/raid10.c
35393 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35394 /* The write handler will notice the lack of
35395 * R10BIO_Uptodate and record any errors etc
35396 */
35397 - atomic_add(r10_bio->sectors,
35398 + atomic_add_unchecked(r10_bio->sectors,
35399 &conf->mirrors[d].rdev->corrected_errors);
35400
35401 /* for reconstruct, we always reschedule after a read.
35402 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35403 {
35404 struct timespec cur_time_mon;
35405 unsigned long hours_since_last;
35406 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35407 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35408
35409 ktime_get_ts(&cur_time_mon);
35410
35411 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35412 * overflowing the shift of read_errors by hours_since_last.
35413 */
35414 if (hours_since_last >= 8 * sizeof(read_errors))
35415 - atomic_set(&rdev->read_errors, 0);
35416 + atomic_set_unchecked(&rdev->read_errors, 0);
35417 else
35418 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35419 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35420 }
35421
35422 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35423 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35424 return;
35425
35426 check_decay_read_errors(mddev, rdev);
35427 - atomic_inc(&rdev->read_errors);
35428 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35429 + atomic_inc_unchecked(&rdev->read_errors);
35430 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35431 char b[BDEVNAME_SIZE];
35432 bdevname(rdev->bdev, b);
35433
35434 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35435 "md/raid10:%s: %s: Raid device exceeded "
35436 "read_error threshold [cur %d:max %d]\n",
35437 mdname(mddev), b,
35438 - atomic_read(&rdev->read_errors), max_read_errors);
35439 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35440 printk(KERN_NOTICE
35441 "md/raid10:%s: %s: Failing raid device\n",
35442 mdname(mddev), b);
35443 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35444 sect +
35445 choose_data_offset(r10_bio, rdev)),
35446 bdevname(rdev->bdev, b));
35447 - atomic_add(s, &rdev->corrected_errors);
35448 + atomic_add_unchecked(s, &rdev->corrected_errors);
35449 }
35450
35451 rdev_dec_pending(rdev, mddev);
35452 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35453 index a450268..c4168a9 100644
35454 --- a/drivers/md/raid5.c
35455 +++ b/drivers/md/raid5.c
35456 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35457 mdname(conf->mddev), STRIPE_SECTORS,
35458 (unsigned long long)s,
35459 bdevname(rdev->bdev, b));
35460 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35461 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35462 clear_bit(R5_ReadError, &sh->dev[i].flags);
35463 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35464 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35465 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35466
35467 - if (atomic_read(&rdev->read_errors))
35468 - atomic_set(&rdev->read_errors, 0);
35469 + if (atomic_read_unchecked(&rdev->read_errors))
35470 + atomic_set_unchecked(&rdev->read_errors, 0);
35471 } else {
35472 const char *bdn = bdevname(rdev->bdev, b);
35473 int retry = 0;
35474 int set_bad = 0;
35475
35476 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35477 - atomic_inc(&rdev->read_errors);
35478 + atomic_inc_unchecked(&rdev->read_errors);
35479 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35480 printk_ratelimited(
35481 KERN_WARNING
35482 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35483 mdname(conf->mddev),
35484 (unsigned long long)s,
35485 bdn);
35486 - } else if (atomic_read(&rdev->read_errors)
35487 + } else if (atomic_read_unchecked(&rdev->read_errors)
35488 > conf->max_nr_stripes)
35489 printk(KERN_WARNING
35490 "md/raid:%s: Too many read errors, failing device %s.\n",
35491 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35492 index d33101a..6b13069 100644
35493 --- a/drivers/media/dvb-core/dvbdev.c
35494 +++ b/drivers/media/dvb-core/dvbdev.c
35495 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35496 const struct dvb_device *template, void *priv, int type)
35497 {
35498 struct dvb_device *dvbdev;
35499 - struct file_operations *dvbdevfops;
35500 + file_operations_no_const *dvbdevfops;
35501 struct device *clsdev;
35502 int minor;
35503 int id;
35504 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35505 index 404f63a..4796533 100644
35506 --- a/drivers/media/dvb-frontends/dib3000.h
35507 +++ b/drivers/media/dvb-frontends/dib3000.h
35508 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35509 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35510 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35511 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35512 -};
35513 +} __no_const;
35514
35515 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35516 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35517 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35518 index 3aa6856..435ad25 100644
35519 --- a/drivers/media/pci/cx88/cx88-alsa.c
35520 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35521 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35522 * Only boards with eeprom and byte 1 at eeprom=1 have it
35523 */
35524
35525 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35526 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35527 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35528 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35529 {0, }
35530 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35531 index feff57e..66a2c67 100644
35532 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35533 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35534 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35535 .subvendor = _subvend, .subdevice = _subdev, \
35536 .driver_data = (unsigned long)&_driverdata }
35537
35538 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35539 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35540 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35541 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35542 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35543 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35544 index 96a13ed..6df45b4 100644
35545 --- a/drivers/media/pci/ngene/ngene-cards.c
35546 +++ b/drivers/media/pci/ngene/ngene-cards.c
35547 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35548
35549 /****************************************************************************/
35550
35551 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35552 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35553 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35554 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35555 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35556 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35557 index a3b1a34..71ce0e3 100644
35558 --- a/drivers/media/platform/omap/omap_vout.c
35559 +++ b/drivers/media/platform/omap/omap_vout.c
35560 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35561 OMAP_VIDEO2,
35562 };
35563
35564 -static struct videobuf_queue_ops video_vbq_ops;
35565 /* Variables configurable through module params*/
35566 static u32 video1_numbuffers = 3;
35567 static u32 video2_numbuffers = 3;
35568 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35569 {
35570 struct videobuf_queue *q;
35571 struct omap_vout_device *vout = NULL;
35572 + static struct videobuf_queue_ops video_vbq_ops = {
35573 + .buf_setup = omap_vout_buffer_setup,
35574 + .buf_prepare = omap_vout_buffer_prepare,
35575 + .buf_release = omap_vout_buffer_release,
35576 + .buf_queue = omap_vout_buffer_queue,
35577 + };
35578
35579 vout = video_drvdata(file);
35580 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35581 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35582 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35583
35584 q = &vout->vbq;
35585 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35586 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35587 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35588 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35589 spin_lock_init(&vout->vbq_lock);
35590
35591 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35592 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35593 index 02194c0..36d69c1 100644
35594 --- a/drivers/media/platform/timblogiw.c
35595 +++ b/drivers/media/platform/timblogiw.c
35596 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35597
35598 /* Platform device functions */
35599
35600 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35601 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35602 .vidioc_querycap = timblogiw_querycap,
35603 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35604 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35605 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35606 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35607 };
35608
35609 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35610 +static struct v4l2_file_operations timblogiw_fops = {
35611 .owner = THIS_MODULE,
35612 .open = timblogiw_open,
35613 .release = timblogiw_close,
35614 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35615 index 697a421..16c5a5f 100644
35616 --- a/drivers/media/radio/radio-cadet.c
35617 +++ b/drivers/media/radio/radio-cadet.c
35618 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35619 unsigned char readbuf[RDS_BUFFER];
35620 int i = 0;
35621
35622 + if (count > RDS_BUFFER)
35623 + return -EFAULT;
35624 mutex_lock(&dev->lock);
35625 if (dev->rdsstat == 0)
35626 cadet_start_rds(dev);
35627 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35628 while (i < count && dev->rdsin != dev->rdsout)
35629 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35630
35631 - if (i && copy_to_user(data, readbuf, i))
35632 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35633 i = -EFAULT;
35634 unlock:
35635 mutex_unlock(&dev->lock);
35636 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35637 index 3940bb0..fb3952a 100644
35638 --- a/drivers/media/usb/dvb-usb/cxusb.c
35639 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35640 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35641
35642 struct dib0700_adapter_state {
35643 int (*set_param_save) (struct dvb_frontend *);
35644 -};
35645 +} __no_const;
35646
35647 static int dib7070_set_param_override(struct dvb_frontend *fe)
35648 {
35649 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35650 index 9382895..ac8093c 100644
35651 --- a/drivers/media/usb/dvb-usb/dw2102.c
35652 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35653 @@ -95,7 +95,7 @@ struct su3000_state {
35654
35655 struct s6x0_state {
35656 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35657 -};
35658 +} __no_const;
35659
35660 /* debug */
35661 static int dvb_usb_dw2102_debug;
35662 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35663 index fb69baa..cf7ad22 100644
35664 --- a/drivers/message/fusion/mptbase.c
35665 +++ b/drivers/message/fusion/mptbase.c
35666 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35667 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35668 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35669
35670 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35671 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35672 +#else
35673 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35674 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35675 +#endif
35676 +
35677 /*
35678 * Rounding UP to nearest 4-kB boundary here...
35679 */
35680 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35681 index 551262e..7551198 100644
35682 --- a/drivers/message/fusion/mptsas.c
35683 +++ b/drivers/message/fusion/mptsas.c
35684 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35685 return 0;
35686 }
35687
35688 +static inline void
35689 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35690 +{
35691 + if (phy_info->port_details) {
35692 + phy_info->port_details->rphy = rphy;
35693 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35694 + ioc->name, rphy));
35695 + }
35696 +
35697 + if (rphy) {
35698 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35699 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35700 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35701 + ioc->name, rphy, rphy->dev.release));
35702 + }
35703 +}
35704 +
35705 /* no mutex */
35706 static void
35707 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35708 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35709 return NULL;
35710 }
35711
35712 -static inline void
35713 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35714 -{
35715 - if (phy_info->port_details) {
35716 - phy_info->port_details->rphy = rphy;
35717 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35718 - ioc->name, rphy));
35719 - }
35720 -
35721 - if (rphy) {
35722 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35723 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35724 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35725 - ioc->name, rphy, rphy->dev.release));
35726 - }
35727 -}
35728 -
35729 static inline struct sas_port *
35730 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35731 {
35732 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35733 index 0c3ced7..1fe34ec 100644
35734 --- a/drivers/message/fusion/mptscsih.c
35735 +++ b/drivers/message/fusion/mptscsih.c
35736 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35737
35738 h = shost_priv(SChost);
35739
35740 - if (h) {
35741 - if (h->info_kbuf == NULL)
35742 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35743 - return h->info_kbuf;
35744 - h->info_kbuf[0] = '\0';
35745 + if (!h)
35746 + return NULL;
35747
35748 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35749 - h->info_kbuf[size-1] = '\0';
35750 - }
35751 + if (h->info_kbuf == NULL)
35752 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35753 + return h->info_kbuf;
35754 + h->info_kbuf[0] = '\0';
35755 +
35756 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35757 + h->info_kbuf[size-1] = '\0';
35758
35759 return h->info_kbuf;
35760 }
35761 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35762 index 8001aa6..b137580 100644
35763 --- a/drivers/message/i2o/i2o_proc.c
35764 +++ b/drivers/message/i2o/i2o_proc.c
35765 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35766 "Array Controller Device"
35767 };
35768
35769 -static char *chtostr(char *tmp, u8 *chars, int n)
35770 -{
35771 - tmp[0] = 0;
35772 - return strncat(tmp, (char *)chars, n);
35773 -}
35774 -
35775 static int i2o_report_query_status(struct seq_file *seq, int block_status,
35776 char *group)
35777 {
35778 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35779 } *result;
35780
35781 i2o_exec_execute_ddm_table ddm_table;
35782 - char tmp[28 + 1];
35783
35784 result = kmalloc(sizeof(*result), GFP_KERNEL);
35785 if (!result)
35786 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35787
35788 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
35789 seq_printf(seq, "%-#8x", ddm_table.module_id);
35790 - seq_printf(seq, "%-29s",
35791 - chtostr(tmp, ddm_table.module_name_version, 28));
35792 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
35793 seq_printf(seq, "%9d ", ddm_table.data_size);
35794 seq_printf(seq, "%8d", ddm_table.code_size);
35795
35796 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35797
35798 i2o_driver_result_table *result;
35799 i2o_driver_store_table *dst;
35800 - char tmp[28 + 1];
35801
35802 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
35803 if (result == NULL)
35804 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35805
35806 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
35807 seq_printf(seq, "%-#8x", dst->module_id);
35808 - seq_printf(seq, "%-29s",
35809 - chtostr(tmp, dst->module_name_version, 28));
35810 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
35811 + seq_printf(seq, "%-.28s", dst->module_name_version);
35812 + seq_printf(seq, "%-.8s", dst->date);
35813 seq_printf(seq, "%8d ", dst->module_size);
35814 seq_printf(seq, "%8d ", dst->mpb_size);
35815 seq_printf(seq, "0x%04x", dst->module_flags);
35816 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35817 // == (allow) 512d bytes (max)
35818 static u16 *work16 = (u16 *) work32;
35819 int token;
35820 - char tmp[16 + 1];
35821
35822 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
35823
35824 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35825 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
35826 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
35827 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
35828 - seq_printf(seq, "Vendor info : %s\n",
35829 - chtostr(tmp, (u8 *) (work32 + 2), 16));
35830 - seq_printf(seq, "Product info : %s\n",
35831 - chtostr(tmp, (u8 *) (work32 + 6), 16));
35832 - seq_printf(seq, "Description : %s\n",
35833 - chtostr(tmp, (u8 *) (work32 + 10), 16));
35834 - seq_printf(seq, "Product rev. : %s\n",
35835 - chtostr(tmp, (u8 *) (work32 + 14), 8));
35836 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
35837 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
35838 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
35839 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
35840
35841 seq_printf(seq, "Serial number : ");
35842 print_serial_number(seq, (u8 *) (work32 + 16),
35843 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35844 u8 pad[256]; // allow up to 256 byte (max) serial number
35845 } result;
35846
35847 - char tmp[24 + 1];
35848 -
35849 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
35850
35851 if (token < 0) {
35852 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35853 }
35854
35855 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
35856 - seq_printf(seq, "Module name : %s\n",
35857 - chtostr(tmp, result.module_name, 24));
35858 - seq_printf(seq, "Module revision : %s\n",
35859 - chtostr(tmp, result.module_rev, 8));
35860 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
35861 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
35862
35863 seq_printf(seq, "Serial number : ");
35864 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
35865 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35866 u8 instance_number[4];
35867 } result;
35868
35869 - char tmp[64 + 1];
35870 -
35871 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
35872
35873 if (token < 0) {
35874 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35875 return 0;
35876 }
35877
35878 - seq_printf(seq, "Device name : %s\n",
35879 - chtostr(tmp, result.device_name, 64));
35880 - seq_printf(seq, "Service name : %s\n",
35881 - chtostr(tmp, result.service_name, 64));
35882 - seq_printf(seq, "Physical name : %s\n",
35883 - chtostr(tmp, result.physical_location, 64));
35884 - seq_printf(seq, "Instance number : %s\n",
35885 - chtostr(tmp, result.instance_number, 4));
35886 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
35887 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
35888 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
35889 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
35890
35891 return 0;
35892 }
35893 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
35894 index a8c08f3..155fe3d 100644
35895 --- a/drivers/message/i2o/iop.c
35896 +++ b/drivers/message/i2o/iop.c
35897 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
35898
35899 spin_lock_irqsave(&c->context_list_lock, flags);
35900
35901 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
35902 - atomic_inc(&c->context_list_counter);
35903 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
35904 + atomic_inc_unchecked(&c->context_list_counter);
35905
35906 - entry->context = atomic_read(&c->context_list_counter);
35907 + entry->context = atomic_read_unchecked(&c->context_list_counter);
35908
35909 list_add(&entry->list, &c->context_list);
35910
35911 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
35912
35913 #if BITS_PER_LONG == 64
35914 spin_lock_init(&c->context_list_lock);
35915 - atomic_set(&c->context_list_counter, 0);
35916 + atomic_set_unchecked(&c->context_list_counter, 0);
35917 INIT_LIST_HEAD(&c->context_list);
35918 #endif
35919
35920 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35921 index 965c480..71f2db9 100644
35922 --- a/drivers/mfd/janz-cmodio.c
35923 +++ b/drivers/mfd/janz-cmodio.c
35924 @@ -13,6 +13,7 @@
35925
35926 #include <linux/kernel.h>
35927 #include <linux/module.h>
35928 +#include <linux/slab.h>
35929 #include <linux/init.h>
35930 #include <linux/pci.h>
35931 #include <linux/interrupt.h>
35932 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
35933 index 3aa9a96..59cf685 100644
35934 --- a/drivers/misc/kgdbts.c
35935 +++ b/drivers/misc/kgdbts.c
35936 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
35937 char before[BREAK_INSTR_SIZE];
35938 char after[BREAK_INSTR_SIZE];
35939
35940 - probe_kernel_read(before, (char *)kgdbts_break_test,
35941 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
35942 BREAK_INSTR_SIZE);
35943 init_simple_test();
35944 ts.tst = plant_and_detach_test;
35945 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
35946 /* Activate test with initial breakpoint */
35947 if (!is_early)
35948 kgdb_breakpoint();
35949 - probe_kernel_read(after, (char *)kgdbts_break_test,
35950 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
35951 BREAK_INSTR_SIZE);
35952 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
35953 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
35954 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35955 index 4a87e5c..76bdf5c 100644
35956 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
35957 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35958 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35959 * the lid is closed. This leads to interrupts as soon as a little move
35960 * is done.
35961 */
35962 - atomic_inc(&lis3->count);
35963 + atomic_inc_unchecked(&lis3->count);
35964
35965 wake_up_interruptible(&lis3->misc_wait);
35966 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35967 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35968 if (lis3->pm_dev)
35969 pm_runtime_get_sync(lis3->pm_dev);
35970
35971 - atomic_set(&lis3->count, 0);
35972 + atomic_set_unchecked(&lis3->count, 0);
35973 return 0;
35974 }
35975
35976 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35977 add_wait_queue(&lis3->misc_wait, &wait);
35978 while (true) {
35979 set_current_state(TASK_INTERRUPTIBLE);
35980 - data = atomic_xchg(&lis3->count, 0);
35981 + data = atomic_xchg_unchecked(&lis3->count, 0);
35982 if (data)
35983 break;
35984
35985 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35986 struct lis3lv02d, miscdev);
35987
35988 poll_wait(file, &lis3->misc_wait, wait);
35989 - if (atomic_read(&lis3->count))
35990 + if (atomic_read_unchecked(&lis3->count))
35991 return POLLIN | POLLRDNORM;
35992 return 0;
35993 }
35994 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
35995 index c439c82..1f20f57 100644
35996 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
35997 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
35998 @@ -297,7 +297,7 @@ struct lis3lv02d {
35999 struct input_polled_dev *idev; /* input device */
36000 struct platform_device *pdev; /* platform device */
36001 struct regulator_bulk_data regulators[2];
36002 - atomic_t count; /* interrupt count after last read */
36003 + atomic_unchecked_t count; /* interrupt count after last read */
36004 union axis_conversion ac; /* hw -> logical axis */
36005 int mapped_btns[3];
36006
36007 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36008 index 2f30bad..c4c13d0 100644
36009 --- a/drivers/misc/sgi-gru/gruhandles.c
36010 +++ b/drivers/misc/sgi-gru/gruhandles.c
36011 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36012 unsigned long nsec;
36013
36014 nsec = CLKS2NSEC(clks);
36015 - atomic_long_inc(&mcs_op_statistics[op].count);
36016 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36017 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36018 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36019 if (mcs_op_statistics[op].max < nsec)
36020 mcs_op_statistics[op].max = nsec;
36021 }
36022 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36023 index 950dbe9..eeef0f8 100644
36024 --- a/drivers/misc/sgi-gru/gruprocfs.c
36025 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36026 @@ -32,9 +32,9 @@
36027
36028 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36029
36030 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36031 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36032 {
36033 - unsigned long val = atomic_long_read(v);
36034 + unsigned long val = atomic_long_read_unchecked(v);
36035
36036 seq_printf(s, "%16lu %s\n", val, id);
36037 }
36038 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36039
36040 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36041 for (op = 0; op < mcsop_last; op++) {
36042 - count = atomic_long_read(&mcs_op_statistics[op].count);
36043 - total = atomic_long_read(&mcs_op_statistics[op].total);
36044 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36045 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36046 max = mcs_op_statistics[op].max;
36047 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36048 count ? total / count : 0, max);
36049 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36050 index 5c3ce24..4915ccb 100644
36051 --- a/drivers/misc/sgi-gru/grutables.h
36052 +++ b/drivers/misc/sgi-gru/grutables.h
36053 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36054 * GRU statistics.
36055 */
36056 struct gru_stats_s {
36057 - atomic_long_t vdata_alloc;
36058 - atomic_long_t vdata_free;
36059 - atomic_long_t gts_alloc;
36060 - atomic_long_t gts_free;
36061 - atomic_long_t gms_alloc;
36062 - atomic_long_t gms_free;
36063 - atomic_long_t gts_double_allocate;
36064 - atomic_long_t assign_context;
36065 - atomic_long_t assign_context_failed;
36066 - atomic_long_t free_context;
36067 - atomic_long_t load_user_context;
36068 - atomic_long_t load_kernel_context;
36069 - atomic_long_t lock_kernel_context;
36070 - atomic_long_t unlock_kernel_context;
36071 - atomic_long_t steal_user_context;
36072 - atomic_long_t steal_kernel_context;
36073 - atomic_long_t steal_context_failed;
36074 - atomic_long_t nopfn;
36075 - atomic_long_t asid_new;
36076 - atomic_long_t asid_next;
36077 - atomic_long_t asid_wrap;
36078 - atomic_long_t asid_reuse;
36079 - atomic_long_t intr;
36080 - atomic_long_t intr_cbr;
36081 - atomic_long_t intr_tfh;
36082 - atomic_long_t intr_spurious;
36083 - atomic_long_t intr_mm_lock_failed;
36084 - atomic_long_t call_os;
36085 - atomic_long_t call_os_wait_queue;
36086 - atomic_long_t user_flush_tlb;
36087 - atomic_long_t user_unload_context;
36088 - atomic_long_t user_exception;
36089 - atomic_long_t set_context_option;
36090 - atomic_long_t check_context_retarget_intr;
36091 - atomic_long_t check_context_unload;
36092 - atomic_long_t tlb_dropin;
36093 - atomic_long_t tlb_preload_page;
36094 - atomic_long_t tlb_dropin_fail_no_asid;
36095 - atomic_long_t tlb_dropin_fail_upm;
36096 - atomic_long_t tlb_dropin_fail_invalid;
36097 - atomic_long_t tlb_dropin_fail_range_active;
36098 - atomic_long_t tlb_dropin_fail_idle;
36099 - atomic_long_t tlb_dropin_fail_fmm;
36100 - atomic_long_t tlb_dropin_fail_no_exception;
36101 - atomic_long_t tfh_stale_on_fault;
36102 - atomic_long_t mmu_invalidate_range;
36103 - atomic_long_t mmu_invalidate_page;
36104 - atomic_long_t flush_tlb;
36105 - atomic_long_t flush_tlb_gru;
36106 - atomic_long_t flush_tlb_gru_tgh;
36107 - atomic_long_t flush_tlb_gru_zero_asid;
36108 + atomic_long_unchecked_t vdata_alloc;
36109 + atomic_long_unchecked_t vdata_free;
36110 + atomic_long_unchecked_t gts_alloc;
36111 + atomic_long_unchecked_t gts_free;
36112 + atomic_long_unchecked_t gms_alloc;
36113 + atomic_long_unchecked_t gms_free;
36114 + atomic_long_unchecked_t gts_double_allocate;
36115 + atomic_long_unchecked_t assign_context;
36116 + atomic_long_unchecked_t assign_context_failed;
36117 + atomic_long_unchecked_t free_context;
36118 + atomic_long_unchecked_t load_user_context;
36119 + atomic_long_unchecked_t load_kernel_context;
36120 + atomic_long_unchecked_t lock_kernel_context;
36121 + atomic_long_unchecked_t unlock_kernel_context;
36122 + atomic_long_unchecked_t steal_user_context;
36123 + atomic_long_unchecked_t steal_kernel_context;
36124 + atomic_long_unchecked_t steal_context_failed;
36125 + atomic_long_unchecked_t nopfn;
36126 + atomic_long_unchecked_t asid_new;
36127 + atomic_long_unchecked_t asid_next;
36128 + atomic_long_unchecked_t asid_wrap;
36129 + atomic_long_unchecked_t asid_reuse;
36130 + atomic_long_unchecked_t intr;
36131 + atomic_long_unchecked_t intr_cbr;
36132 + atomic_long_unchecked_t intr_tfh;
36133 + atomic_long_unchecked_t intr_spurious;
36134 + atomic_long_unchecked_t intr_mm_lock_failed;
36135 + atomic_long_unchecked_t call_os;
36136 + atomic_long_unchecked_t call_os_wait_queue;
36137 + atomic_long_unchecked_t user_flush_tlb;
36138 + atomic_long_unchecked_t user_unload_context;
36139 + atomic_long_unchecked_t user_exception;
36140 + atomic_long_unchecked_t set_context_option;
36141 + atomic_long_unchecked_t check_context_retarget_intr;
36142 + atomic_long_unchecked_t check_context_unload;
36143 + atomic_long_unchecked_t tlb_dropin;
36144 + atomic_long_unchecked_t tlb_preload_page;
36145 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36146 + atomic_long_unchecked_t tlb_dropin_fail_upm;
36147 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
36148 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
36149 + atomic_long_unchecked_t tlb_dropin_fail_idle;
36150 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
36151 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36152 + atomic_long_unchecked_t tfh_stale_on_fault;
36153 + atomic_long_unchecked_t mmu_invalidate_range;
36154 + atomic_long_unchecked_t mmu_invalidate_page;
36155 + atomic_long_unchecked_t flush_tlb;
36156 + atomic_long_unchecked_t flush_tlb_gru;
36157 + atomic_long_unchecked_t flush_tlb_gru_tgh;
36158 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36159
36160 - atomic_long_t copy_gpa;
36161 - atomic_long_t read_gpa;
36162 + atomic_long_unchecked_t copy_gpa;
36163 + atomic_long_unchecked_t read_gpa;
36164
36165 - atomic_long_t mesq_receive;
36166 - atomic_long_t mesq_receive_none;
36167 - atomic_long_t mesq_send;
36168 - atomic_long_t mesq_send_failed;
36169 - atomic_long_t mesq_noop;
36170 - atomic_long_t mesq_send_unexpected_error;
36171 - atomic_long_t mesq_send_lb_overflow;
36172 - atomic_long_t mesq_send_qlimit_reached;
36173 - atomic_long_t mesq_send_amo_nacked;
36174 - atomic_long_t mesq_send_put_nacked;
36175 - atomic_long_t mesq_page_overflow;
36176 - atomic_long_t mesq_qf_locked;
36177 - atomic_long_t mesq_qf_noop_not_full;
36178 - atomic_long_t mesq_qf_switch_head_failed;
36179 - atomic_long_t mesq_qf_unexpected_error;
36180 - atomic_long_t mesq_noop_unexpected_error;
36181 - atomic_long_t mesq_noop_lb_overflow;
36182 - atomic_long_t mesq_noop_qlimit_reached;
36183 - atomic_long_t mesq_noop_amo_nacked;
36184 - atomic_long_t mesq_noop_put_nacked;
36185 - atomic_long_t mesq_noop_page_overflow;
36186 + atomic_long_unchecked_t mesq_receive;
36187 + atomic_long_unchecked_t mesq_receive_none;
36188 + atomic_long_unchecked_t mesq_send;
36189 + atomic_long_unchecked_t mesq_send_failed;
36190 + atomic_long_unchecked_t mesq_noop;
36191 + atomic_long_unchecked_t mesq_send_unexpected_error;
36192 + atomic_long_unchecked_t mesq_send_lb_overflow;
36193 + atomic_long_unchecked_t mesq_send_qlimit_reached;
36194 + atomic_long_unchecked_t mesq_send_amo_nacked;
36195 + atomic_long_unchecked_t mesq_send_put_nacked;
36196 + atomic_long_unchecked_t mesq_page_overflow;
36197 + atomic_long_unchecked_t mesq_qf_locked;
36198 + atomic_long_unchecked_t mesq_qf_noop_not_full;
36199 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
36200 + atomic_long_unchecked_t mesq_qf_unexpected_error;
36201 + atomic_long_unchecked_t mesq_noop_unexpected_error;
36202 + atomic_long_unchecked_t mesq_noop_lb_overflow;
36203 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
36204 + atomic_long_unchecked_t mesq_noop_amo_nacked;
36205 + atomic_long_unchecked_t mesq_noop_put_nacked;
36206 + atomic_long_unchecked_t mesq_noop_page_overflow;
36207
36208 };
36209
36210 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36211 tghop_invalidate, mcsop_last};
36212
36213 struct mcs_op_statistic {
36214 - atomic_long_t count;
36215 - atomic_long_t total;
36216 + atomic_long_unchecked_t count;
36217 + atomic_long_unchecked_t total;
36218 unsigned long max;
36219 };
36220
36221 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36222
36223 #define STAT(id) do { \
36224 if (gru_options & OPT_STATS) \
36225 - atomic_long_inc(&gru_stats.id); \
36226 + atomic_long_inc_unchecked(&gru_stats.id); \
36227 } while (0)
36228
36229 #ifdef CONFIG_SGI_GRU_DEBUG
36230 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36231 index c862cd4..0d176fe 100644
36232 --- a/drivers/misc/sgi-xp/xp.h
36233 +++ b/drivers/misc/sgi-xp/xp.h
36234 @@ -288,7 +288,7 @@ struct xpc_interface {
36235 xpc_notify_func, void *);
36236 void (*received) (short, int, void *);
36237 enum xp_retval (*partid_to_nasids) (short, void *);
36238 -};
36239 +} __no_const;
36240
36241 extern struct xpc_interface xpc_interface;
36242
36243 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36244 index b94d5f7..7f494c5 100644
36245 --- a/drivers/misc/sgi-xp/xpc.h
36246 +++ b/drivers/misc/sgi-xp/xpc.h
36247 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
36248 void (*received_payload) (struct xpc_channel *, void *);
36249 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36250 };
36251 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36252
36253 /* struct xpc_partition act_state values (for XPC HB) */
36254
36255 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36256 /* found in xpc_main.c */
36257 extern struct device *xpc_part;
36258 extern struct device *xpc_chan;
36259 -extern struct xpc_arch_operations xpc_arch_ops;
36260 +extern xpc_arch_operations_no_const xpc_arch_ops;
36261 extern int xpc_disengage_timelimit;
36262 extern int xpc_disengage_timedout;
36263 extern int xpc_activate_IRQ_rcvd;
36264 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36265 index d971817..33bdca5 100644
36266 --- a/drivers/misc/sgi-xp/xpc_main.c
36267 +++ b/drivers/misc/sgi-xp/xpc_main.c
36268 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36269 .notifier_call = xpc_system_die,
36270 };
36271
36272 -struct xpc_arch_operations xpc_arch_ops;
36273 +xpc_arch_operations_no_const xpc_arch_ops;
36274
36275 /*
36276 * Timer function to enforce the timelimit on the partition disengage.
36277 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36278
36279 if (((die_args->trapnr == X86_TRAP_MF) ||
36280 (die_args->trapnr == X86_TRAP_XF)) &&
36281 - !user_mode_vm(die_args->regs))
36282 + !user_mode(die_args->regs))
36283 xpc_die_deactivate();
36284
36285 break;
36286 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36287 index a0e1720..ee63d0b 100644
36288 --- a/drivers/mmc/core/mmc_ops.c
36289 +++ b/drivers/mmc/core/mmc_ops.c
36290 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36291 void *data_buf;
36292 int is_on_stack;
36293
36294 - is_on_stack = object_is_on_stack(buf);
36295 + is_on_stack = object_starts_on_stack(buf);
36296 if (is_on_stack) {
36297 /*
36298 * dma onto stack is unsafe/nonportable, but callers to this
36299 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36300 index 53b8fd9..615b462 100644
36301 --- a/drivers/mmc/host/dw_mmc.h
36302 +++ b/drivers/mmc/host/dw_mmc.h
36303 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36304 int (*parse_dt)(struct dw_mci *host);
36305 int (*setup_bus)(struct dw_mci *host,
36306 struct device_node *slot_np, u8 bus_width);
36307 -};
36308 +} __do_const;
36309 #endif /* _DW_MMC_H_ */
36310 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36311 index a4eb8b5..8c0628f 100644
36312 --- a/drivers/mtd/devices/doc2000.c
36313 +++ b/drivers/mtd/devices/doc2000.c
36314 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36315
36316 /* The ECC will not be calculated correctly if less than 512 is written */
36317 /* DBB-
36318 - if (len != 0x200 && eccbuf)
36319 + if (len != 0x200)
36320 printk(KERN_WARNING
36321 "ECC needs a full sector write (adr: %lx size %lx)\n",
36322 (long) to, (long) len);
36323 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36324 index e706a23..b3d262f 100644
36325 --- a/drivers/mtd/nand/denali.c
36326 +++ b/drivers/mtd/nand/denali.c
36327 @@ -26,6 +26,7 @@
36328 #include <linux/pci.h>
36329 #include <linux/mtd/mtd.h>
36330 #include <linux/module.h>
36331 +#include <linux/slab.h>
36332
36333 #include "denali.h"
36334
36335 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36336 index 51b9d6a..52af9a7 100644
36337 --- a/drivers/mtd/nftlmount.c
36338 +++ b/drivers/mtd/nftlmount.c
36339 @@ -24,6 +24,7 @@
36340 #include <asm/errno.h>
36341 #include <linux/delay.h>
36342 #include <linux/slab.h>
36343 +#include <linux/sched.h>
36344 #include <linux/mtd/mtd.h>
36345 #include <linux/mtd/nand.h>
36346 #include <linux/mtd/nftl.h>
36347 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36348 index 203ff9d..0968ca8 100644
36349 --- a/drivers/net/ethernet/8390/ax88796.c
36350 +++ b/drivers/net/ethernet/8390/ax88796.c
36351 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36352 if (ax->plat->reg_offsets)
36353 ei_local->reg_offset = ax->plat->reg_offsets;
36354 else {
36355 + resource_size_t _mem_size = mem_size;
36356 + do_div(_mem_size, 0x18);
36357 ei_local->reg_offset = ax->reg_offsets;
36358 for (ret = 0; ret < 0x18; ret++)
36359 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36360 + ax->reg_offsets[ret] = _mem_size * ret;
36361 }
36362
36363 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36364 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36365 index 9c5ea6c..eaad276 100644
36366 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36367 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36368 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36369 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36370 {
36371 /* RX_MODE controlling object */
36372 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36373 + bnx2x_init_rx_mode_obj(bp);
36374
36375 /* multicast configuration controlling object */
36376 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36377 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36378 index 614981c..11216c7 100644
36379 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36380 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36381 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36382 return rc;
36383 }
36384
36385 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36386 - struct bnx2x_rx_mode_obj *o)
36387 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36388 {
36389 if (CHIP_IS_E1x(bp)) {
36390 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36391 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36392 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36393 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36394 } else {
36395 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36396 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36397 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36398 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36399 }
36400 }
36401
36402 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36403 index acf2fe4..efb96df 100644
36404 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36405 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36406 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36407
36408 /********************* RX MODE ****************/
36409
36410 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36411 - struct bnx2x_rx_mode_obj *o);
36412 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36413
36414 /**
36415 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36416 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36417 index d9308c32..d87b824 100644
36418 --- a/drivers/net/ethernet/broadcom/tg3.h
36419 +++ b/drivers/net/ethernet/broadcom/tg3.h
36420 @@ -140,6 +140,7 @@
36421 #define CHIPREV_ID_5750_A0 0x4000
36422 #define CHIPREV_ID_5750_A1 0x4001
36423 #define CHIPREV_ID_5750_A3 0x4003
36424 +#define CHIPREV_ID_5750_C1 0x4201
36425 #define CHIPREV_ID_5750_C2 0x4202
36426 #define CHIPREV_ID_5752_A0_HW 0x5000
36427 #define CHIPREV_ID_5752_A0 0x6000
36428 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36429 index 8cffcdf..aadf043 100644
36430 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36431 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36432 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36433 */
36434 struct l2t_skb_cb {
36435 arp_failure_handler_func arp_failure_handler;
36436 -};
36437 +} __no_const;
36438
36439 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36440
36441 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36442 index f879e92..726f20f 100644
36443 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36444 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36445 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36446 for (i=0; i<ETH_ALEN; i++) {
36447 tmp.addr[i] = dev->dev_addr[i];
36448 }
36449 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36450 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36451 break;
36452
36453 case DE4X5_SET_HWADDR: /* Set the hardware address */
36454 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36455 spin_lock_irqsave(&lp->lock, flags);
36456 memcpy(&statbuf, &lp->pktStats, ioc->len);
36457 spin_unlock_irqrestore(&lp->lock, flags);
36458 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36459 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36460 return -EFAULT;
36461 break;
36462 }
36463 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36464 index d1b6cc5..cde0d97 100644
36465 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36466 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36467 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36468
36469 if (wrapped)
36470 newacc += 65536;
36471 - ACCESS_ONCE(*acc) = newacc;
36472 + ACCESS_ONCE_RW(*acc) = newacc;
36473 }
36474
36475 void be_parse_stats(struct be_adapter *adapter)
36476 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36477 index 74d749e..eefb1bd 100644
36478 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36479 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36480 @@ -31,6 +31,8 @@
36481 #include <linux/netdevice.h>
36482 #include <linux/phy.h>
36483 #include <linux/platform_device.h>
36484 +#include <linux/interrupt.h>
36485 +#include <linux/irqreturn.h>
36486 #include <net/ip.h>
36487
36488 #include "ftgmac100.h"
36489 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36490 index b901a01..1ff32ee 100644
36491 --- a/drivers/net/ethernet/faraday/ftmac100.c
36492 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36493 @@ -31,6 +31,8 @@
36494 #include <linux/module.h>
36495 #include <linux/netdevice.h>
36496 #include <linux/platform_device.h>
36497 +#include <linux/interrupt.h>
36498 +#include <linux/irqreturn.h>
36499
36500 #include "ftmac100.h"
36501
36502 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36503 index d929131..aed108f 100644
36504 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36505 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36506 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36507 /* store the new cycle speed */
36508 adapter->cycle_speed = cycle_speed;
36509
36510 - ACCESS_ONCE(adapter->base_incval) = incval;
36511 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36512 smp_mb();
36513
36514 /* grab the ptp lock */
36515 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36516 index c2e420a..26a75e0 100644
36517 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36518 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36519 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36520 struct __vxge_hw_fifo *fifo;
36521 struct vxge_hw_fifo_config *config;
36522 u32 txdl_size, txdl_per_memblock;
36523 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36524 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36525 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36526 + };
36527 +
36528 struct __vxge_hw_virtualpath *vpath;
36529
36530 if ((vp == NULL) || (attr == NULL)) {
36531 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36532 goto exit;
36533 }
36534
36535 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36536 -
36537 fifo->mempool =
36538 __vxge_hw_mempool_create(vpath->hldev,
36539 fifo->config->memblock_size,
36540 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36541 index 927aa33..a6c2518 100644
36542 --- a/drivers/net/ethernet/realtek/r8169.c
36543 +++ b/drivers/net/ethernet/realtek/r8169.c
36544 @@ -747,22 +747,22 @@ struct rtl8169_private {
36545 struct mdio_ops {
36546 void (*write)(struct rtl8169_private *, int, int);
36547 int (*read)(struct rtl8169_private *, int);
36548 - } mdio_ops;
36549 + } __no_const mdio_ops;
36550
36551 struct pll_power_ops {
36552 void (*down)(struct rtl8169_private *);
36553 void (*up)(struct rtl8169_private *);
36554 - } pll_power_ops;
36555 + } __no_const pll_power_ops;
36556
36557 struct jumbo_ops {
36558 void (*enable)(struct rtl8169_private *);
36559 void (*disable)(struct rtl8169_private *);
36560 - } jumbo_ops;
36561 + } __no_const jumbo_ops;
36562
36563 struct csi_ops {
36564 void (*write)(struct rtl8169_private *, int, int);
36565 u32 (*read)(struct rtl8169_private *, int);
36566 - } csi_ops;
36567 + } __no_const csi_ops;
36568
36569 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36570 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36571 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36572 index 0767043f..08c2553 100644
36573 --- a/drivers/net/ethernet/sfc/ptp.c
36574 +++ b/drivers/net/ethernet/sfc/ptp.c
36575 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36576 (u32)((u64)ptp->start.dma_addr >> 32));
36577
36578 /* Clear flag that signals MC ready */
36579 - ACCESS_ONCE(*start) = 0;
36580 + ACCESS_ONCE_RW(*start) = 0;
36581 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36582 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36583
36584 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36585 index 0c74a70..3bc6f68 100644
36586 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36587 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36588 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36589
36590 writel(value, ioaddr + MMC_CNTRL);
36591
36592 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36593 - MMC_CNTRL, value);
36594 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36595 +// MMC_CNTRL, value);
36596 }
36597
36598 /* To mask all all interrupts.*/
36599 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36600 index 5fd6f46..ee1f265 100644
36601 --- a/drivers/net/hyperv/hyperv_net.h
36602 +++ b/drivers/net/hyperv/hyperv_net.h
36603 @@ -101,7 +101,7 @@ struct rndis_device {
36604
36605 enum rndis_device_state state;
36606 bool link_state;
36607 - atomic_t new_req_id;
36608 + atomic_unchecked_t new_req_id;
36609
36610 spinlock_t request_lock;
36611 struct list_head req_list;
36612 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36613 index 928148c..d83298e 100644
36614 --- a/drivers/net/hyperv/rndis_filter.c
36615 +++ b/drivers/net/hyperv/rndis_filter.c
36616 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36617 * template
36618 */
36619 set = &rndis_msg->msg.set_req;
36620 - set->req_id = atomic_inc_return(&dev->new_req_id);
36621 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36622
36623 /* Add to the request list */
36624 spin_lock_irqsave(&dev->request_lock, flags);
36625 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36626
36627 /* Setup the rndis set */
36628 halt = &request->request_msg.msg.halt_req;
36629 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36630 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36631
36632 /* Ignore return since this msg is optional. */
36633 rndis_filter_send_request(dev, request);
36634 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36635 index 7d39add..037e1da 100644
36636 --- a/drivers/net/ieee802154/fakehard.c
36637 +++ b/drivers/net/ieee802154/fakehard.c
36638 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36639 phy->transmit_power = 0xbf;
36640
36641 dev->netdev_ops = &fake_ops;
36642 - dev->ml_priv = &fake_mlme;
36643 + dev->ml_priv = (void *)&fake_mlme;
36644
36645 priv = netdev_priv(dev);
36646 priv->phy = phy;
36647 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36648 index 0f0f9ce..0ca5819 100644
36649 --- a/drivers/net/macvtap.c
36650 +++ b/drivers/net/macvtap.c
36651 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36652 return NOTIFY_DONE;
36653 }
36654
36655 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36656 +static struct notifier_block macvtap_notifier_block = {
36657 .notifier_call = macvtap_device_event,
36658 };
36659
36660 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36661 index daec9b0..6428fcb 100644
36662 --- a/drivers/net/phy/mdio-bitbang.c
36663 +++ b/drivers/net/phy/mdio-bitbang.c
36664 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36665 struct mdiobb_ctrl *ctrl = bus->priv;
36666
36667 module_put(ctrl->ops->owner);
36668 + mdiobus_unregister(bus);
36669 mdiobus_free(bus);
36670 }
36671 EXPORT_SYMBOL(free_mdio_bitbang);
36672 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36673 index eb3f5ce..d773730 100644
36674 --- a/drivers/net/ppp/ppp_generic.c
36675 +++ b/drivers/net/ppp/ppp_generic.c
36676 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36677 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36678 struct ppp_stats stats;
36679 struct ppp_comp_stats cstats;
36680 - char *vers;
36681
36682 switch (cmd) {
36683 case SIOCGPPPSTATS:
36684 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36685 break;
36686
36687 case SIOCGPPPVER:
36688 - vers = PPP_VERSION;
36689 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36690 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36691 break;
36692 err = 0;
36693 break;
36694 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36695 index ad86660..9fd0884 100644
36696 --- a/drivers/net/team/team.c
36697 +++ b/drivers/net/team/team.c
36698 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36699 return NOTIFY_DONE;
36700 }
36701
36702 -static struct notifier_block team_notifier_block __read_mostly = {
36703 +static struct notifier_block team_notifier_block = {
36704 .notifier_call = team_device_event,
36705 };
36706
36707 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36708 index 0873cdc..ddb178e 100644
36709 --- a/drivers/net/tun.c
36710 +++ b/drivers/net/tun.c
36711 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36712 }
36713
36714 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36715 - unsigned long arg, int ifreq_len)
36716 + unsigned long arg, size_t ifreq_len)
36717 {
36718 struct tun_file *tfile = file->private_data;
36719 struct tun_struct *tun;
36720 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36721 int vnet_hdr_sz;
36722 int ret;
36723
36724 + if (ifreq_len > sizeof ifr)
36725 + return -EFAULT;
36726 +
36727 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36728 if (copy_from_user(&ifr, argp, ifreq_len))
36729 return -EFAULT;
36730 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36731 index 605a4ba..a883dd1 100644
36732 --- a/drivers/net/usb/hso.c
36733 +++ b/drivers/net/usb/hso.c
36734 @@ -71,7 +71,7 @@
36735 #include <asm/byteorder.h>
36736 #include <linux/serial_core.h>
36737 #include <linux/serial.h>
36738 -
36739 +#include <asm/local.h>
36740
36741 #define MOD_AUTHOR "Option Wireless"
36742 #define MOD_DESCRIPTION "USB High Speed Option driver"
36743 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36744 struct urb *urb;
36745
36746 urb = serial->rx_urb[0];
36747 - if (serial->port.count > 0) {
36748 + if (atomic_read(&serial->port.count) > 0) {
36749 count = put_rxbuf_data(urb, serial);
36750 if (count == -1)
36751 return;
36752 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36753 DUMP1(urb->transfer_buffer, urb->actual_length);
36754
36755 /* Anyone listening? */
36756 - if (serial->port.count == 0)
36757 + if (atomic_read(&serial->port.count) == 0)
36758 return;
36759
36760 if (status == 0) {
36761 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36762 tty_port_tty_set(&serial->port, tty);
36763
36764 /* check for port already opened, if not set the termios */
36765 - serial->port.count++;
36766 - if (serial->port.count == 1) {
36767 + if (atomic_inc_return(&serial->port.count) == 1) {
36768 serial->rx_state = RX_IDLE;
36769 /* Force default termio settings */
36770 _hso_serial_set_termios(tty, NULL);
36771 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36772 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36773 if (result) {
36774 hso_stop_serial_device(serial->parent);
36775 - serial->port.count--;
36776 + atomic_dec(&serial->port.count);
36777 kref_put(&serial->parent->ref, hso_serial_ref_free);
36778 }
36779 } else {
36780 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36781
36782 /* reset the rts and dtr */
36783 /* do the actual close */
36784 - serial->port.count--;
36785 + atomic_dec(&serial->port.count);
36786
36787 - if (serial->port.count <= 0) {
36788 - serial->port.count = 0;
36789 + if (atomic_read(&serial->port.count) <= 0) {
36790 + atomic_set(&serial->port.count, 0);
36791 tty_port_tty_set(&serial->port, NULL);
36792 if (!usb_gone)
36793 hso_stop_serial_device(serial->parent);
36794 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36795
36796 /* the actual setup */
36797 spin_lock_irqsave(&serial->serial_lock, flags);
36798 - if (serial->port.count)
36799 + if (atomic_read(&serial->port.count))
36800 _hso_serial_set_termios(tty, old);
36801 else
36802 tty->termios = *old;
36803 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
36804 D1("Pending read interrupt on port %d\n", i);
36805 spin_lock(&serial->serial_lock);
36806 if (serial->rx_state == RX_IDLE &&
36807 - serial->port.count > 0) {
36808 + atomic_read(&serial->port.count) > 0) {
36809 /* Setup and send a ctrl req read on
36810 * port i */
36811 if (!serial->rx_urb_filled[0]) {
36812 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
36813 /* Start all serial ports */
36814 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36815 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36816 - if (dev2ser(serial_table[i])->port.count) {
36817 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
36818 result =
36819 hso_start_serial_device(serial_table[i], GFP_NOIO);
36820 hso_kick_transmit(dev2ser(serial_table[i]));
36821 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36822 index 8d78253..bebbb68 100644
36823 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36824 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36825 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36826 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36827 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36828
36829 - ACCESS_ONCE(ads->ds_link) = i->link;
36830 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36831 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
36832 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36833
36834 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36835 ctl6 = SM(i->keytype, AR_EncrType);
36836 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36837
36838 if ((i->is_first || i->is_last) &&
36839 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36840 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36841 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36842 | set11nTries(i->rates, 1)
36843 | set11nTries(i->rates, 2)
36844 | set11nTries(i->rates, 3)
36845 | (i->dur_update ? AR_DurUpdateEna : 0)
36846 | SM(0, AR_BurstDur);
36847
36848 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36849 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36850 | set11nRate(i->rates, 1)
36851 | set11nRate(i->rates, 2)
36852 | set11nRate(i->rates, 3);
36853 } else {
36854 - ACCESS_ONCE(ads->ds_ctl2) = 0;
36855 - ACCESS_ONCE(ads->ds_ctl3) = 0;
36856 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36857 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36858 }
36859
36860 if (!i->is_first) {
36861 - ACCESS_ONCE(ads->ds_ctl0) = 0;
36862 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36863 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36864 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36865 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36866 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36867 return;
36868 }
36869
36870 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36871 break;
36872 }
36873
36874 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36875 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36876 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36877 | SM(i->txpower, AR_XmitPower)
36878 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36879 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36880 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36881 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36882
36883 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36884 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36885 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36886 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36887
36888 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36889 return;
36890
36891 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36892 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36893 | set11nPktDurRTSCTS(i->rates, 1);
36894
36895 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36896 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36897 | set11nPktDurRTSCTS(i->rates, 3);
36898
36899 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36900 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36901 | set11nRateFlags(i->rates, 1)
36902 | set11nRateFlags(i->rates, 2)
36903 | set11nRateFlags(i->rates, 3)
36904 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36905 index 301bf72..3f5654f 100644
36906 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36907 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36908 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36909 (i->qcu << AR_TxQcuNum_S) | desc_len;
36910
36911 checksum += val;
36912 - ACCESS_ONCE(ads->info) = val;
36913 + ACCESS_ONCE_RW(ads->info) = val;
36914
36915 checksum += i->link;
36916 - ACCESS_ONCE(ads->link) = i->link;
36917 + ACCESS_ONCE_RW(ads->link) = i->link;
36918
36919 checksum += i->buf_addr[0];
36920 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36921 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36922 checksum += i->buf_addr[1];
36923 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36924 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36925 checksum += i->buf_addr[2];
36926 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36927 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36928 checksum += i->buf_addr[3];
36929 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36930 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36931
36932 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36933 - ACCESS_ONCE(ads->ctl3) = val;
36934 + ACCESS_ONCE_RW(ads->ctl3) = val;
36935 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36936 - ACCESS_ONCE(ads->ctl5) = val;
36937 + ACCESS_ONCE_RW(ads->ctl5) = val;
36938 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36939 - ACCESS_ONCE(ads->ctl7) = val;
36940 + ACCESS_ONCE_RW(ads->ctl7) = val;
36941 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36942 - ACCESS_ONCE(ads->ctl9) = val;
36943 + ACCESS_ONCE_RW(ads->ctl9) = val;
36944
36945 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36946 - ACCESS_ONCE(ads->ctl10) = checksum;
36947 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
36948
36949 if (i->is_first || i->is_last) {
36950 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36951 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36952 | set11nTries(i->rates, 1)
36953 | set11nTries(i->rates, 2)
36954 | set11nTries(i->rates, 3)
36955 | (i->dur_update ? AR_DurUpdateEna : 0)
36956 | SM(0, AR_BurstDur);
36957
36958 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36959 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36960 | set11nRate(i->rates, 1)
36961 | set11nRate(i->rates, 2)
36962 | set11nRate(i->rates, 3);
36963 } else {
36964 - ACCESS_ONCE(ads->ctl13) = 0;
36965 - ACCESS_ONCE(ads->ctl14) = 0;
36966 + ACCESS_ONCE_RW(ads->ctl13) = 0;
36967 + ACCESS_ONCE_RW(ads->ctl14) = 0;
36968 }
36969
36970 ads->ctl20 = 0;
36971 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36972
36973 ctl17 = SM(i->keytype, AR_EncrType);
36974 if (!i->is_first) {
36975 - ACCESS_ONCE(ads->ctl11) = 0;
36976 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36977 - ACCESS_ONCE(ads->ctl15) = 0;
36978 - ACCESS_ONCE(ads->ctl16) = 0;
36979 - ACCESS_ONCE(ads->ctl17) = ctl17;
36980 - ACCESS_ONCE(ads->ctl18) = 0;
36981 - ACCESS_ONCE(ads->ctl19) = 0;
36982 + ACCESS_ONCE_RW(ads->ctl11) = 0;
36983 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36984 + ACCESS_ONCE_RW(ads->ctl15) = 0;
36985 + ACCESS_ONCE_RW(ads->ctl16) = 0;
36986 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36987 + ACCESS_ONCE_RW(ads->ctl18) = 0;
36988 + ACCESS_ONCE_RW(ads->ctl19) = 0;
36989 return;
36990 }
36991
36992 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36993 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36994 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36995 | SM(i->txpower, AR_XmitPower)
36996 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36997 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36998 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36999 ctl12 |= SM(val, AR_PAPRDChainMask);
37000
37001 - ACCESS_ONCE(ads->ctl12) = ctl12;
37002 - ACCESS_ONCE(ads->ctl17) = ctl17;
37003 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37004 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37005
37006 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37007 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37008 | set11nPktDurRTSCTS(i->rates, 1);
37009
37010 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37011 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37012 | set11nPktDurRTSCTS(i->rates, 3);
37013
37014 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37015 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37016 | set11nRateFlags(i->rates, 1)
37017 | set11nRateFlags(i->rates, 2)
37018 | set11nRateFlags(i->rates, 3)
37019 | SM(i->rtscts_rate, AR_RTSCTSRate);
37020
37021 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37022 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37023 }
37024
37025 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37026 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37027 index dbc1b7a..67e2ca2 100644
37028 --- a/drivers/net/wireless/ath/ath9k/hw.h
37029 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37030 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37031
37032 /* ANI */
37033 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37034 -};
37035 +} __no_const;
37036
37037 /**
37038 * struct ath_hw_ops - callbacks used by hardware code and driver code
37039 @@ -687,7 +687,7 @@ struct ath_hw_ops {
37040 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37041 struct ath_hw_antcomb_conf *antconf);
37042 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37043 -};
37044 +} __no_const;
37045
37046 struct ath_nf_limits {
37047 s16 max;
37048 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37049 index 71ced17..cd82b12 100644
37050 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37051 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37052 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37053 struct net_device *ndev,
37054 const struct brcmf_event_msg *e,
37055 void *data);
37056 -};
37057 +} __no_const;
37058
37059 /* basic structure of scan request */
37060 struct brcmf_cfg80211_scan_req {
37061 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37062 struct brcmf_cfg80211_iscan_eloop {
37063 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37064 (struct brcmf_cfg80211_info *cfg);
37065 -};
37066 +} __no_const;
37067
37068 /* dongle iscan controller */
37069 struct brcmf_cfg80211_iscan_ctrl {
37070 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37071 index e252acb..6ad1e65 100644
37072 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37073 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37074 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37075 */
37076 if (il3945_mod_params.disable_hw_scan) {
37077 D_INFO("Disabling hw_scan\n");
37078 - il3945_mac_ops.hw_scan = NULL;
37079 + pax_open_kernel();
37080 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37081 + pax_close_kernel();
37082 }
37083
37084 D_INFO("*** LOAD DRIVER ***\n");
37085 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37086 index 1a98fa3..51e6661 100644
37087 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37088 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37089 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37090 {
37091 struct iwl_priv *priv = file->private_data;
37092 char buf[64];
37093 - int buf_size;
37094 + size_t buf_size;
37095 u32 offset, len;
37096
37097 memset(buf, 0, sizeof(buf));
37098 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37099 struct iwl_priv *priv = file->private_data;
37100
37101 char buf[8];
37102 - int buf_size;
37103 + size_t buf_size;
37104 u32 reset_flag;
37105
37106 memset(buf, 0, sizeof(buf));
37107 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37108 {
37109 struct iwl_priv *priv = file->private_data;
37110 char buf[8];
37111 - int buf_size;
37112 + size_t buf_size;
37113 int ht40;
37114
37115 memset(buf, 0, sizeof(buf));
37116 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37117 {
37118 struct iwl_priv *priv = file->private_data;
37119 char buf[8];
37120 - int buf_size;
37121 + size_t buf_size;
37122 int value;
37123
37124 memset(buf, 0, sizeof(buf));
37125 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37126 {
37127 struct iwl_priv *priv = file->private_data;
37128 char buf[8];
37129 - int buf_size;
37130 + size_t buf_size;
37131 int clear;
37132
37133 memset(buf, 0, sizeof(buf));
37134 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37135 {
37136 struct iwl_priv *priv = file->private_data;
37137 char buf[8];
37138 - int buf_size;
37139 + size_t buf_size;
37140 int trace;
37141
37142 memset(buf, 0, sizeof(buf));
37143 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37144 {
37145 struct iwl_priv *priv = file->private_data;
37146 char buf[8];
37147 - int buf_size;
37148 + size_t buf_size;
37149 int missed;
37150
37151 memset(buf, 0, sizeof(buf));
37152 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37153
37154 struct iwl_priv *priv = file->private_data;
37155 char buf[8];
37156 - int buf_size;
37157 + size_t buf_size;
37158 int plcp;
37159
37160 memset(buf, 0, sizeof(buf));
37161 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37162
37163 struct iwl_priv *priv = file->private_data;
37164 char buf[8];
37165 - int buf_size;
37166 + size_t buf_size;
37167 int flush;
37168
37169 memset(buf, 0, sizeof(buf));
37170 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37171
37172 struct iwl_priv *priv = file->private_data;
37173 char buf[8];
37174 - int buf_size;
37175 + size_t buf_size;
37176 int rts;
37177
37178 if (!priv->cfg->ht_params)
37179 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37180 {
37181 struct iwl_priv *priv = file->private_data;
37182 char buf[8];
37183 - int buf_size;
37184 + size_t buf_size;
37185
37186 memset(buf, 0, sizeof(buf));
37187 buf_size = min(count, sizeof(buf) - 1);
37188 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37189 struct iwl_priv *priv = file->private_data;
37190 u32 event_log_flag;
37191 char buf[8];
37192 - int buf_size;
37193 + size_t buf_size;
37194
37195 /* check that the interface is up */
37196 if (!iwl_is_ready(priv))
37197 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37198 struct iwl_priv *priv = file->private_data;
37199 char buf[8];
37200 u32 calib_disabled;
37201 - int buf_size;
37202 + size_t buf_size;
37203
37204 memset(buf, 0, sizeof(buf));
37205 buf_size = min(count, sizeof(buf) - 1);
37206 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37207 index fe0fffd..b4c5724 100644
37208 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37209 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37210 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37211 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37212
37213 char buf[8];
37214 - int buf_size;
37215 + size_t buf_size;
37216 u32 reset_flag;
37217
37218 memset(buf, 0, sizeof(buf));
37219 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37220 {
37221 struct iwl_trans *trans = file->private_data;
37222 char buf[8];
37223 - int buf_size;
37224 + size_t buf_size;
37225 int csr;
37226
37227 memset(buf, 0, sizeof(buf));
37228 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37229 index 429ca32..f86236b 100644
37230 --- a/drivers/net/wireless/mac80211_hwsim.c
37231 +++ b/drivers/net/wireless/mac80211_hwsim.c
37232 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37233 return -EINVAL;
37234
37235 if (fake_hw_scan) {
37236 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37237 - mac80211_hwsim_ops.sw_scan_start = NULL;
37238 - mac80211_hwsim_ops.sw_scan_complete = NULL;
37239 + pax_open_kernel();
37240 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37241 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37242 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37243 + pax_close_kernel();
37244 }
37245
37246 spin_lock_init(&hwsim_radio_lock);
37247 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37248 index bd1f0cb..db85ab0 100644
37249 --- a/drivers/net/wireless/rndis_wlan.c
37250 +++ b/drivers/net/wireless/rndis_wlan.c
37251 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37252
37253 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37254
37255 - if (rts_threshold < 0 || rts_threshold > 2347)
37256 + if (rts_threshold > 2347)
37257 rts_threshold = 2347;
37258
37259 tmp = cpu_to_le32(rts_threshold);
37260 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37261 index 0751b35..246ba3e 100644
37262 --- a/drivers/net/wireless/rt2x00/rt2x00.h
37263 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
37264 @@ -398,7 +398,7 @@ struct rt2x00_intf {
37265 * for hardware which doesn't support hardware
37266 * sequence counting.
37267 */
37268 - atomic_t seqno;
37269 + atomic_unchecked_t seqno;
37270 };
37271
37272 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37273 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37274 index e488b94..14b6a0c 100644
37275 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37276 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37277 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37278 * sequence counter given by mac80211.
37279 */
37280 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37281 - seqno = atomic_add_return(0x10, &intf->seqno);
37282 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37283 else
37284 - seqno = atomic_read(&intf->seqno);
37285 + seqno = atomic_read_unchecked(&intf->seqno);
37286
37287 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37288 hdr->seq_ctrl |= cpu_to_le16(seqno);
37289 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37290 index e2750a1..797e179 100644
37291 --- a/drivers/net/wireless/ti/wl1251/sdio.c
37292 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
37293 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37294
37295 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37296
37297 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37298 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37299 + pax_open_kernel();
37300 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37301 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37302 + pax_close_kernel();
37303
37304 wl1251_info("using dedicated interrupt line");
37305 } else {
37306 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37307 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37308 + pax_open_kernel();
37309 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37310 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37311 + pax_close_kernel();
37312
37313 wl1251_info("using SDIO interrupt");
37314 }
37315 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37316 index dadf1db..d9db7a7 100644
37317 --- a/drivers/net/wireless/ti/wl12xx/main.c
37318 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37319 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37320 sizeof(wl->conf.mem));
37321
37322 /* read data preparation is only needed by wl127x */
37323 - wl->ops->prepare_read = wl127x_prepare_read;
37324 + pax_open_kernel();
37325 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37326 + pax_close_kernel();
37327
37328 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37329 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37330 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37331 sizeof(wl->conf.mem));
37332
37333 /* read data preparation is only needed by wl127x */
37334 - wl->ops->prepare_read = wl127x_prepare_read;
37335 + pax_open_kernel();
37336 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37337 + pax_close_kernel();
37338
37339 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37340 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37341 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37342 index a39682a..1e8220c 100644
37343 --- a/drivers/net/wireless/ti/wl18xx/main.c
37344 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37345 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37346 }
37347
37348 if (!checksum_param) {
37349 - wl18xx_ops.set_rx_csum = NULL;
37350 - wl18xx_ops.init_vif = NULL;
37351 + pax_open_kernel();
37352 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37353 + *(void **)&wl18xx_ops.init_vif = NULL;
37354 + pax_close_kernel();
37355 }
37356
37357 /* Enable 11a Band only if we have 5G antennas */
37358 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37359 index d93b2b6..ae50401 100644
37360 --- a/drivers/oprofile/buffer_sync.c
37361 +++ b/drivers/oprofile/buffer_sync.c
37362 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37363 if (cookie == NO_COOKIE)
37364 offset = pc;
37365 if (cookie == INVALID_COOKIE) {
37366 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37367 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37368 offset = pc;
37369 }
37370 if (cookie != last_cookie) {
37371 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37372 /* add userspace sample */
37373
37374 if (!mm) {
37375 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37376 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37377 return 0;
37378 }
37379
37380 cookie = lookup_dcookie(mm, s->eip, &offset);
37381
37382 if (cookie == INVALID_COOKIE) {
37383 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37384 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37385 return 0;
37386 }
37387
37388 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37389 /* ignore backtraces if failed to add a sample */
37390 if (state == sb_bt_start) {
37391 state = sb_bt_ignore;
37392 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37393 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37394 }
37395 }
37396 release_mm(mm);
37397 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37398 index c0cc4e7..44d4e54 100644
37399 --- a/drivers/oprofile/event_buffer.c
37400 +++ b/drivers/oprofile/event_buffer.c
37401 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37402 }
37403
37404 if (buffer_pos == buffer_size) {
37405 - atomic_inc(&oprofile_stats.event_lost_overflow);
37406 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37407 return;
37408 }
37409
37410 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37411 index ed2c3ec..deda85a 100644
37412 --- a/drivers/oprofile/oprof.c
37413 +++ b/drivers/oprofile/oprof.c
37414 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37415 if (oprofile_ops.switch_events())
37416 return;
37417
37418 - atomic_inc(&oprofile_stats.multiplex_counter);
37419 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37420 start_switch_worker();
37421 }
37422
37423 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37424 index 917d28e..d62d981 100644
37425 --- a/drivers/oprofile/oprofile_stats.c
37426 +++ b/drivers/oprofile/oprofile_stats.c
37427 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37428 cpu_buf->sample_invalid_eip = 0;
37429 }
37430
37431 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37432 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37433 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37434 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37435 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37436 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37437 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37438 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37439 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37440 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37441 }
37442
37443
37444 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37445 index 38b6fc0..b5cbfce 100644
37446 --- a/drivers/oprofile/oprofile_stats.h
37447 +++ b/drivers/oprofile/oprofile_stats.h
37448 @@ -13,11 +13,11 @@
37449 #include <linux/atomic.h>
37450
37451 struct oprofile_stat_struct {
37452 - atomic_t sample_lost_no_mm;
37453 - atomic_t sample_lost_no_mapping;
37454 - atomic_t bt_lost_no_mapping;
37455 - atomic_t event_lost_overflow;
37456 - atomic_t multiplex_counter;
37457 + atomic_unchecked_t sample_lost_no_mm;
37458 + atomic_unchecked_t sample_lost_no_mapping;
37459 + atomic_unchecked_t bt_lost_no_mapping;
37460 + atomic_unchecked_t event_lost_overflow;
37461 + atomic_unchecked_t multiplex_counter;
37462 };
37463
37464 extern struct oprofile_stat_struct oprofile_stats;
37465 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37466 index 849357c..b83c1e0 100644
37467 --- a/drivers/oprofile/oprofilefs.c
37468 +++ b/drivers/oprofile/oprofilefs.c
37469 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37470
37471
37472 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37473 - char const *name, atomic_t *val)
37474 + char const *name, atomic_unchecked_t *val)
37475 {
37476 return __oprofilefs_create_file(sb, root, name,
37477 &atomic_ro_fops, 0444, val);
37478 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37479 index 3f56bc0..707d642 100644
37480 --- a/drivers/parport/procfs.c
37481 +++ b/drivers/parport/procfs.c
37482 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37483
37484 *ppos += len;
37485
37486 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37487 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37488 }
37489
37490 #ifdef CONFIG_PARPORT_1284
37491 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37492
37493 *ppos += len;
37494
37495 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37496 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37497 }
37498 #endif /* IEEE1284.3 support. */
37499
37500 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37501 index a6a71c4..c91097b 100644
37502 --- a/drivers/pci/hotplug/cpcihp_generic.c
37503 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37504 @@ -73,7 +73,6 @@ static u16 port;
37505 static unsigned int enum_bit;
37506 static u8 enum_mask;
37507
37508 -static struct cpci_hp_controller_ops generic_hpc_ops;
37509 static struct cpci_hp_controller generic_hpc;
37510
37511 static int __init validate_parameters(void)
37512 @@ -139,6 +138,10 @@ static int query_enum(void)
37513 return ((value & enum_mask) == enum_mask);
37514 }
37515
37516 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37517 + .query_enum = query_enum,
37518 +};
37519 +
37520 static int __init cpcihp_generic_init(void)
37521 {
37522 int status;
37523 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37524 pci_dev_put(dev);
37525
37526 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37527 - generic_hpc_ops.query_enum = query_enum;
37528 generic_hpc.ops = &generic_hpc_ops;
37529
37530 status = cpci_hp_register_controller(&generic_hpc);
37531 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37532 index 6bf8d2a..9711ce0 100644
37533 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37534 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37535 @@ -59,7 +59,6 @@
37536 /* local variables */
37537 static bool debug;
37538 static bool poll;
37539 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37540 static struct cpci_hp_controller zt5550_hpc;
37541
37542 /* Primary cPCI bus bridge device */
37543 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37544 return 0;
37545 }
37546
37547 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37548 + .query_enum = zt5550_hc_query_enum,
37549 +};
37550 +
37551 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37552 {
37553 int status;
37554 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37555 dbg("returned from zt5550_hc_config");
37556
37557 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37558 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37559 zt5550_hpc.ops = &zt5550_hpc_ops;
37560 if(!poll) {
37561 zt5550_hpc.irq = hc_dev->irq;
37562 zt5550_hpc.irq_flags = IRQF_SHARED;
37563 zt5550_hpc.dev_id = hc_dev;
37564
37565 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37566 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37567 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37568 + pax_open_kernel();
37569 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37570 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37571 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37572 + pax_open_kernel();
37573 } else {
37574 info("using ENUM# polling mode");
37575 }
37576 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37577 index 76ba8a1..20ca857 100644
37578 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37579 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37580 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37581
37582 void compaq_nvram_init (void __iomem *rom_start)
37583 {
37584 +
37585 +#ifndef CONFIG_PAX_KERNEXEC
37586 if (rom_start) {
37587 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37588 }
37589 +#endif
37590 +
37591 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37592
37593 /* initialize our int15 lock */
37594 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37595 index 449f257..0731e96 100644
37596 --- a/drivers/pci/pcie/aspm.c
37597 +++ b/drivers/pci/pcie/aspm.c
37598 @@ -27,9 +27,9 @@
37599 #define MODULE_PARAM_PREFIX "pcie_aspm."
37600
37601 /* Note: those are not register definitions */
37602 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37603 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37604 -#define ASPM_STATE_L1 (4) /* L1 state */
37605 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37606 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37607 +#define ASPM_STATE_L1 (4U) /* L1 state */
37608 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37609 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37610
37611 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37612 index ec909af..e7517f3 100644
37613 --- a/drivers/pci/probe.c
37614 +++ b/drivers/pci/probe.c
37615 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37616 struct pci_bus_region region;
37617 bool bar_too_big = false, bar_disabled = false;
37618
37619 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37620 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37621
37622 /* No printks while decoding is disabled! */
37623 if (!dev->mmio_always_on) {
37624 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37625 index 9b8505c..f00870a 100644
37626 --- a/drivers/pci/proc.c
37627 +++ b/drivers/pci/proc.c
37628 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37629 static int __init pci_proc_init(void)
37630 {
37631 struct pci_dev *dev = NULL;
37632 +
37633 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37634 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37635 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37636 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37637 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37638 +#endif
37639 +#else
37640 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37641 +#endif
37642 proc_create("devices", 0, proc_bus_pci_dir,
37643 &proc_bus_pci_dev_operations);
37644 proc_initialized = 1;
37645 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37646 index 75dd651..2af4c9a 100644
37647 --- a/drivers/platform/x86/thinkpad_acpi.c
37648 +++ b/drivers/platform/x86/thinkpad_acpi.c
37649 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37650 return 0;
37651 }
37652
37653 -void static hotkey_mask_warn_incomplete_mask(void)
37654 +static void hotkey_mask_warn_incomplete_mask(void)
37655 {
37656 /* log only what the user can fix... */
37657 const u32 wantedmask = hotkey_driver_mask &
37658 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37659 }
37660 }
37661
37662 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37663 - struct tp_nvram_state *newn,
37664 - const u32 event_mask)
37665 -{
37666 -
37667 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37668 do { \
37669 if ((event_mask & (1 << __scancode)) && \
37670 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37671 tpacpi_hotkey_send_key(__scancode); \
37672 } while (0)
37673
37674 - void issue_volchange(const unsigned int oldvol,
37675 - const unsigned int newvol)
37676 - {
37677 - unsigned int i = oldvol;
37678 +static void issue_volchange(const unsigned int oldvol,
37679 + const unsigned int newvol,
37680 + const u32 event_mask)
37681 +{
37682 + unsigned int i = oldvol;
37683
37684 - while (i > newvol) {
37685 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37686 - i--;
37687 - }
37688 - while (i < newvol) {
37689 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37690 - i++;
37691 - }
37692 + while (i > newvol) {
37693 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37694 + i--;
37695 }
37696 + while (i < newvol) {
37697 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37698 + i++;
37699 + }
37700 +}
37701
37702 - void issue_brightnesschange(const unsigned int oldbrt,
37703 - const unsigned int newbrt)
37704 - {
37705 - unsigned int i = oldbrt;
37706 +static void issue_brightnesschange(const unsigned int oldbrt,
37707 + const unsigned int newbrt,
37708 + const u32 event_mask)
37709 +{
37710 + unsigned int i = oldbrt;
37711
37712 - while (i > newbrt) {
37713 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37714 - i--;
37715 - }
37716 - while (i < newbrt) {
37717 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37718 - i++;
37719 - }
37720 + while (i > newbrt) {
37721 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37722 + i--;
37723 + }
37724 + while (i < newbrt) {
37725 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37726 + i++;
37727 }
37728 +}
37729
37730 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37731 + struct tp_nvram_state *newn,
37732 + const u32 event_mask)
37733 +{
37734 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37735 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37736 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37737 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37738 oldn->volume_level != newn->volume_level) {
37739 /* recently muted, or repeated mute keypress, or
37740 * multiple presses ending in mute */
37741 - issue_volchange(oldn->volume_level, newn->volume_level);
37742 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37743 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37744 }
37745 } else {
37746 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37747 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37748 }
37749 if (oldn->volume_level != newn->volume_level) {
37750 - issue_volchange(oldn->volume_level, newn->volume_level);
37751 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37752 } else if (oldn->volume_toggle != newn->volume_toggle) {
37753 /* repeated vol up/down keypress at end of scale ? */
37754 if (newn->volume_level == 0)
37755 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37756 /* handle brightness */
37757 if (oldn->brightness_level != newn->brightness_level) {
37758 issue_brightnesschange(oldn->brightness_level,
37759 - newn->brightness_level);
37760 + newn->brightness_level,
37761 + event_mask);
37762 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37763 /* repeated key presses that didn't change state */
37764 if (newn->brightness_level == 0)
37765 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37766 && !tp_features.bright_unkfw)
37767 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37768 }
37769 +}
37770
37771 #undef TPACPI_COMPARE_KEY
37772 #undef TPACPI_MAY_SEND_KEY
37773 -}
37774
37775 /*
37776 * Polling driver
37777 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37778 index 769d265..a3a05ca 100644
37779 --- a/drivers/pnp/pnpbios/bioscalls.c
37780 +++ b/drivers/pnp/pnpbios/bioscalls.c
37781 @@ -58,7 +58,7 @@ do { \
37782 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37783 } while(0)
37784
37785 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37786 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37787 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37788
37789 /*
37790 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37791
37792 cpu = get_cpu();
37793 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37794 +
37795 + pax_open_kernel();
37796 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37797 + pax_close_kernel();
37798
37799 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37800 spin_lock_irqsave(&pnp_bios_lock, flags);
37801 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37802 :"memory");
37803 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37804
37805 + pax_open_kernel();
37806 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37807 + pax_close_kernel();
37808 +
37809 put_cpu();
37810
37811 /* If we get here and this is set then the PnP BIOS faulted on us. */
37812 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37813 return status;
37814 }
37815
37816 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37817 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37818 {
37819 int i;
37820
37821 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37822 pnp_bios_callpoint.offset = header->fields.pm16offset;
37823 pnp_bios_callpoint.segment = PNP_CS16;
37824
37825 + pax_open_kernel();
37826 +
37827 for_each_possible_cpu(i) {
37828 struct desc_struct *gdt = get_cpu_gdt_table(i);
37829 if (!gdt)
37830 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37831 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37832 (unsigned long)__va(header->fields.pm16dseg));
37833 }
37834 +
37835 + pax_close_kernel();
37836 }
37837 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37838 index b0ecacb..7c9da2e 100644
37839 --- a/drivers/pnp/resource.c
37840 +++ b/drivers/pnp/resource.c
37841 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37842 return 1;
37843
37844 /* check if the resource is valid */
37845 - if (*irq < 0 || *irq > 15)
37846 + if (*irq > 15)
37847 return 0;
37848
37849 /* check if the resource is reserved */
37850 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37851 return 1;
37852
37853 /* check if the resource is valid */
37854 - if (*dma < 0 || *dma == 4 || *dma > 7)
37855 + if (*dma == 4 || *dma > 7)
37856 return 0;
37857
37858 /* check if the resource is reserved */
37859 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
37860 index 7df7c5f..bd48c47 100644
37861 --- a/drivers/power/pda_power.c
37862 +++ b/drivers/power/pda_power.c
37863 @@ -37,7 +37,11 @@ static int polling;
37864
37865 #ifdef CONFIG_USB_OTG_UTILS
37866 static struct usb_phy *transceiver;
37867 -static struct notifier_block otg_nb;
37868 +static int otg_handle_notification(struct notifier_block *nb,
37869 + unsigned long event, void *unused);
37870 +static struct notifier_block otg_nb = {
37871 + .notifier_call = otg_handle_notification
37872 +};
37873 #endif
37874
37875 static struct regulator *ac_draw;
37876 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
37877
37878 #ifdef CONFIG_USB_OTG_UTILS
37879 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
37880 - otg_nb.notifier_call = otg_handle_notification;
37881 ret = usb_register_notifier(transceiver, &otg_nb);
37882 if (ret) {
37883 dev_err(dev, "failure to register otg notifier\n");
37884 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37885 index 8d53174..04c65de 100644
37886 --- a/drivers/regulator/max8660.c
37887 +++ b/drivers/regulator/max8660.c
37888 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37889 max8660->shadow_regs[MAX8660_OVER1] = 5;
37890 } else {
37891 /* Otherwise devices can be toggled via software */
37892 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
37893 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
37894 + pax_open_kernel();
37895 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37896 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37897 + pax_close_kernel();
37898 }
37899
37900 /*
37901 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37902 index 1fa6381..f58834e 100644
37903 --- a/drivers/regulator/mc13892-regulator.c
37904 +++ b/drivers/regulator/mc13892-regulator.c
37905 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37906 }
37907 mc13xxx_unlock(mc13892);
37908
37909 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37910 + pax_open_kernel();
37911 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37912 = mc13892_vcam_set_mode;
37913 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37914 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37915 = mc13892_vcam_get_mode;
37916 + pax_close_kernel();
37917
37918 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
37919 ARRAY_SIZE(mc13892_regulators));
37920 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
37921 index cace6d3..f623fda 100644
37922 --- a/drivers/rtc/rtc-dev.c
37923 +++ b/drivers/rtc/rtc-dev.c
37924 @@ -14,6 +14,7 @@
37925 #include <linux/module.h>
37926 #include <linux/rtc.h>
37927 #include <linux/sched.h>
37928 +#include <linux/grsecurity.h>
37929 #include "rtc-core.h"
37930
37931 static dev_t rtc_devt;
37932 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
37933 if (copy_from_user(&tm, uarg, sizeof(tm)))
37934 return -EFAULT;
37935
37936 + gr_log_timechange();
37937 +
37938 return rtc_set_time(rtc, &tm);
37939
37940 case RTC_PIE_ON:
37941 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
37942 index 4ad7e36..d004679 100644
37943 --- a/drivers/scsi/bfa/bfa.h
37944 +++ b/drivers/scsi/bfa/bfa.h
37945 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
37946 u32 *end);
37947 int cpe_vec_q0;
37948 int rme_vec_q0;
37949 -};
37950 +} __no_const;
37951 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37952
37953 struct bfa_faa_cbfn_s {
37954 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37955 index e693af6..2e525b6 100644
37956 --- a/drivers/scsi/bfa/bfa_fcpim.h
37957 +++ b/drivers/scsi/bfa/bfa_fcpim.h
37958 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
37959
37960 struct bfa_itn_s {
37961 bfa_isr_func_t isr;
37962 -};
37963 +} __no_const;
37964
37965 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37966 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37967 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37968 index 23a90e7..9cf04ee 100644
37969 --- a/drivers/scsi/bfa/bfa_ioc.h
37970 +++ b/drivers/scsi/bfa/bfa_ioc.h
37971 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37972 bfa_ioc_disable_cbfn_t disable_cbfn;
37973 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37974 bfa_ioc_reset_cbfn_t reset_cbfn;
37975 -};
37976 +} __no_const;
37977
37978 /*
37979 * IOC event notification mechanism.
37980 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37981 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37982 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37983 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37984 -};
37985 +} __no_const;
37986
37987 /*
37988 * Queue element to wait for room in request queue. FIFO order is
37989 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37990 index 593085a..47aa999 100644
37991 --- a/drivers/scsi/hosts.c
37992 +++ b/drivers/scsi/hosts.c
37993 @@ -42,7 +42,7 @@
37994 #include "scsi_logging.h"
37995
37996
37997 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37998 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37999
38000
38001 static void scsi_host_cls_release(struct device *dev)
38002 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38003 * subtract one because we increment first then return, but we need to
38004 * know what the next host number was before increment
38005 */
38006 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38007 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38008 shost->dma_channel = 0xff;
38009
38010 /* These three are default values which can be overridden */
38011 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38012 index 4217e49..9c77e3e 100644
38013 --- a/drivers/scsi/hpsa.c
38014 +++ b/drivers/scsi/hpsa.c
38015 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38016 unsigned long flags;
38017
38018 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38019 - return h->access.command_completed(h, q);
38020 + return h->access->command_completed(h, q);
38021
38022 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38023 a = rq->head[rq->current_entry];
38024 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38025 while (!list_empty(&h->reqQ)) {
38026 c = list_entry(h->reqQ.next, struct CommandList, list);
38027 /* can't do anything if fifo is full */
38028 - if ((h->access.fifo_full(h))) {
38029 + if ((h->access->fifo_full(h))) {
38030 dev_warn(&h->pdev->dev, "fifo full\n");
38031 break;
38032 }
38033 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38034
38035 /* Tell the controller execute command */
38036 spin_unlock_irqrestore(&h->lock, flags);
38037 - h->access.submit_command(h, c);
38038 + h->access->submit_command(h, c);
38039 spin_lock_irqsave(&h->lock, flags);
38040 }
38041 spin_unlock_irqrestore(&h->lock, flags);
38042 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38043
38044 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38045 {
38046 - return h->access.command_completed(h, q);
38047 + return h->access->command_completed(h, q);
38048 }
38049
38050 static inline bool interrupt_pending(struct ctlr_info *h)
38051 {
38052 - return h->access.intr_pending(h);
38053 + return h->access->intr_pending(h);
38054 }
38055
38056 static inline long interrupt_not_for_us(struct ctlr_info *h)
38057 {
38058 - return (h->access.intr_pending(h) == 0) ||
38059 + return (h->access->intr_pending(h) == 0) ||
38060 (h->interrupts_enabled == 0);
38061 }
38062
38063 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38064 if (prod_index < 0)
38065 return -ENODEV;
38066 h->product_name = products[prod_index].product_name;
38067 - h->access = *(products[prod_index].access);
38068 + h->access = products[prod_index].access;
38069
38070 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38071 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38072 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38073
38074 assert_spin_locked(&lockup_detector_lock);
38075 remove_ctlr_from_lockup_detector_list(h);
38076 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38077 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38078 spin_lock_irqsave(&h->lock, flags);
38079 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38080 spin_unlock_irqrestore(&h->lock, flags);
38081 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38082 }
38083
38084 /* make sure the board interrupts are off */
38085 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38086 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38087
38088 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38089 goto clean2;
38090 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38091 * fake ones to scoop up any residual completions.
38092 */
38093 spin_lock_irqsave(&h->lock, flags);
38094 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38095 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38096 spin_unlock_irqrestore(&h->lock, flags);
38097 free_irqs(h);
38098 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38099 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38100 dev_info(&h->pdev->dev, "Board READY.\n");
38101 dev_info(&h->pdev->dev,
38102 "Waiting for stale completions to drain.\n");
38103 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38104 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38105 msleep(10000);
38106 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38107 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38108
38109 rc = controller_reset_failed(h->cfgtable);
38110 if (rc)
38111 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38112 }
38113
38114 /* Turn the interrupts on so we can service requests */
38115 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38116 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38117
38118 hpsa_hba_inquiry(h);
38119 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38120 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38121 * To write all data in the battery backed cache to disks
38122 */
38123 hpsa_flush_cache(h);
38124 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38125 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38126 hpsa_free_irqs_and_disable_msix(h);
38127 }
38128
38129 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38130 return;
38131 }
38132 /* Change the access methods to the performant access methods */
38133 - h->access = SA5_performant_access;
38134 + h->access = &SA5_performant_access;
38135 h->transMethod = CFGTBL_Trans_Performant;
38136 }
38137
38138 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38139 index 9816479..c5d4e97 100644
38140 --- a/drivers/scsi/hpsa.h
38141 +++ b/drivers/scsi/hpsa.h
38142 @@ -79,7 +79,7 @@ struct ctlr_info {
38143 unsigned int msix_vector;
38144 unsigned int msi_vector;
38145 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38146 - struct access_method access;
38147 + struct access_method *access;
38148
38149 /* queue and queue Info */
38150 struct list_head reqQ;
38151 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38152 index c772d8d..35c362c 100644
38153 --- a/drivers/scsi/libfc/fc_exch.c
38154 +++ b/drivers/scsi/libfc/fc_exch.c
38155 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
38156 u16 pool_max_index;
38157
38158 struct {
38159 - atomic_t no_free_exch;
38160 - atomic_t no_free_exch_xid;
38161 - atomic_t xid_not_found;
38162 - atomic_t xid_busy;
38163 - atomic_t seq_not_found;
38164 - atomic_t non_bls_resp;
38165 + atomic_unchecked_t no_free_exch;
38166 + atomic_unchecked_t no_free_exch_xid;
38167 + atomic_unchecked_t xid_not_found;
38168 + atomic_unchecked_t xid_busy;
38169 + atomic_unchecked_t seq_not_found;
38170 + atomic_unchecked_t non_bls_resp;
38171 } stats;
38172 };
38173
38174 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38175 /* allocate memory for exchange */
38176 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38177 if (!ep) {
38178 - atomic_inc(&mp->stats.no_free_exch);
38179 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38180 goto out;
38181 }
38182 memset(ep, 0, sizeof(*ep));
38183 @@ -786,7 +786,7 @@ out:
38184 return ep;
38185 err:
38186 spin_unlock_bh(&pool->lock);
38187 - atomic_inc(&mp->stats.no_free_exch_xid);
38188 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38189 mempool_free(ep, mp->ep_pool);
38190 return NULL;
38191 }
38192 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38193 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38194 ep = fc_exch_find(mp, xid);
38195 if (!ep) {
38196 - atomic_inc(&mp->stats.xid_not_found);
38197 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38198 reject = FC_RJT_OX_ID;
38199 goto out;
38200 }
38201 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38202 ep = fc_exch_find(mp, xid);
38203 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38204 if (ep) {
38205 - atomic_inc(&mp->stats.xid_busy);
38206 + atomic_inc_unchecked(&mp->stats.xid_busy);
38207 reject = FC_RJT_RX_ID;
38208 goto rel;
38209 }
38210 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38211 }
38212 xid = ep->xid; /* get our XID */
38213 } else if (!ep) {
38214 - atomic_inc(&mp->stats.xid_not_found);
38215 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38216 reject = FC_RJT_RX_ID; /* XID not found */
38217 goto out;
38218 }
38219 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38220 } else {
38221 sp = &ep->seq;
38222 if (sp->id != fh->fh_seq_id) {
38223 - atomic_inc(&mp->stats.seq_not_found);
38224 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38225 if (f_ctl & FC_FC_END_SEQ) {
38226 /*
38227 * Update sequence_id based on incoming last
38228 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38229
38230 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38231 if (!ep) {
38232 - atomic_inc(&mp->stats.xid_not_found);
38233 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38234 goto out;
38235 }
38236 if (ep->esb_stat & ESB_ST_COMPLETE) {
38237 - atomic_inc(&mp->stats.xid_not_found);
38238 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38239 goto rel;
38240 }
38241 if (ep->rxid == FC_XID_UNKNOWN)
38242 ep->rxid = ntohs(fh->fh_rx_id);
38243 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38244 - atomic_inc(&mp->stats.xid_not_found);
38245 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38246 goto rel;
38247 }
38248 if (ep->did != ntoh24(fh->fh_s_id) &&
38249 ep->did != FC_FID_FLOGI) {
38250 - atomic_inc(&mp->stats.xid_not_found);
38251 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38252 goto rel;
38253 }
38254 sof = fr_sof(fp);
38255 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38256 sp->ssb_stat |= SSB_ST_RESP;
38257 sp->id = fh->fh_seq_id;
38258 } else if (sp->id != fh->fh_seq_id) {
38259 - atomic_inc(&mp->stats.seq_not_found);
38260 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38261 goto rel;
38262 }
38263
38264 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38265 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38266
38267 if (!sp)
38268 - atomic_inc(&mp->stats.xid_not_found);
38269 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38270 else
38271 - atomic_inc(&mp->stats.non_bls_resp);
38272 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38273
38274 fc_frame_free(fp);
38275 }
38276 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38277
38278 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38279 mp = ema->mp;
38280 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38281 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38282 st->fc_no_free_exch_xid +=
38283 - atomic_read(&mp->stats.no_free_exch_xid);
38284 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38285 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38286 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38287 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38288 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38289 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38290 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38291 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38292 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38293 }
38294 }
38295 EXPORT_SYMBOL(fc_exch_update_stats);
38296 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38297 index bdb81cd..d3c7c2c 100644
38298 --- a/drivers/scsi/libsas/sas_ata.c
38299 +++ b/drivers/scsi/libsas/sas_ata.c
38300 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38301 .postreset = ata_std_postreset,
38302 .error_handler = ata_std_error_handler,
38303 .post_internal_cmd = sas_ata_post_internal,
38304 - .qc_defer = ata_std_qc_defer,
38305 + .qc_defer = ata_std_qc_defer,
38306 .qc_prep = ata_noop_qc_prep,
38307 .qc_issue = sas_ata_qc_issue,
38308 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38309 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38310 index 69b5993..1ac9dce 100644
38311 --- a/drivers/scsi/lpfc/lpfc.h
38312 +++ b/drivers/scsi/lpfc/lpfc.h
38313 @@ -424,7 +424,7 @@ struct lpfc_vport {
38314 struct dentry *debug_nodelist;
38315 struct dentry *vport_debugfs_root;
38316 struct lpfc_debugfs_trc *disc_trc;
38317 - atomic_t disc_trc_cnt;
38318 + atomic_unchecked_t disc_trc_cnt;
38319 #endif
38320 uint8_t stat_data_enabled;
38321 uint8_t stat_data_blocked;
38322 @@ -840,8 +840,8 @@ struct lpfc_hba {
38323 struct timer_list fabric_block_timer;
38324 unsigned long bit_flags;
38325 #define FABRIC_COMANDS_BLOCKED 0
38326 - atomic_t num_rsrc_err;
38327 - atomic_t num_cmd_success;
38328 + atomic_unchecked_t num_rsrc_err;
38329 + atomic_unchecked_t num_cmd_success;
38330 unsigned long last_rsrc_error_time;
38331 unsigned long last_ramp_down_time;
38332 unsigned long last_ramp_up_time;
38333 @@ -877,7 +877,7 @@ struct lpfc_hba {
38334
38335 struct dentry *debug_slow_ring_trc;
38336 struct lpfc_debugfs_trc *slow_ring_trc;
38337 - atomic_t slow_ring_trc_cnt;
38338 + atomic_unchecked_t slow_ring_trc_cnt;
38339 /* iDiag debugfs sub-directory */
38340 struct dentry *idiag_root;
38341 struct dentry *idiag_pci_cfg;
38342 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38343 index f63f5ff..de29189 100644
38344 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38345 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38346 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38347
38348 #include <linux/debugfs.h>
38349
38350 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38351 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38352 static unsigned long lpfc_debugfs_start_time = 0L;
38353
38354 /* iDiag */
38355 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38356 lpfc_debugfs_enable = 0;
38357
38358 len = 0;
38359 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38360 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38361 (lpfc_debugfs_max_disc_trc - 1);
38362 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38363 dtp = vport->disc_trc + i;
38364 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38365 lpfc_debugfs_enable = 0;
38366
38367 len = 0;
38368 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38369 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38370 (lpfc_debugfs_max_slow_ring_trc - 1);
38371 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38372 dtp = phba->slow_ring_trc + i;
38373 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38374 !vport || !vport->disc_trc)
38375 return;
38376
38377 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38378 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38379 (lpfc_debugfs_max_disc_trc - 1);
38380 dtp = vport->disc_trc + index;
38381 dtp->fmt = fmt;
38382 dtp->data1 = data1;
38383 dtp->data2 = data2;
38384 dtp->data3 = data3;
38385 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38386 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38387 dtp->jif = jiffies;
38388 #endif
38389 return;
38390 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38391 !phba || !phba->slow_ring_trc)
38392 return;
38393
38394 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38395 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38396 (lpfc_debugfs_max_slow_ring_trc - 1);
38397 dtp = phba->slow_ring_trc + index;
38398 dtp->fmt = fmt;
38399 dtp->data1 = data1;
38400 dtp->data2 = data2;
38401 dtp->data3 = data3;
38402 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38403 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38404 dtp->jif = jiffies;
38405 #endif
38406 return;
38407 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38408 "slow_ring buffer\n");
38409 goto debug_failed;
38410 }
38411 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38412 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38413 memset(phba->slow_ring_trc, 0,
38414 (sizeof(struct lpfc_debugfs_trc) *
38415 lpfc_debugfs_max_slow_ring_trc));
38416 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38417 "buffer\n");
38418 goto debug_failed;
38419 }
38420 - atomic_set(&vport->disc_trc_cnt, 0);
38421 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38422
38423 snprintf(name, sizeof(name), "discovery_trace");
38424 vport->debug_disc_trc =
38425 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38426 index 7dc4218..3436f08 100644
38427 --- a/drivers/scsi/lpfc/lpfc_init.c
38428 +++ b/drivers/scsi/lpfc/lpfc_init.c
38429 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38430 "misc_register returned with status %d", error);
38431
38432 if (lpfc_enable_npiv) {
38433 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38434 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38435 + pax_open_kernel();
38436 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38437 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38438 + pax_close_kernel();
38439 }
38440 lpfc_transport_template =
38441 fc_attach_transport(&lpfc_transport_functions);
38442 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38443 index 7f45ac9..cf62eda 100644
38444 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38445 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38446 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38447 uint32_t evt_posted;
38448
38449 spin_lock_irqsave(&phba->hbalock, flags);
38450 - atomic_inc(&phba->num_rsrc_err);
38451 + atomic_inc_unchecked(&phba->num_rsrc_err);
38452 phba->last_rsrc_error_time = jiffies;
38453
38454 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38455 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38456 unsigned long flags;
38457 struct lpfc_hba *phba = vport->phba;
38458 uint32_t evt_posted;
38459 - atomic_inc(&phba->num_cmd_success);
38460 + atomic_inc_unchecked(&phba->num_cmd_success);
38461
38462 if (vport->cfg_lun_queue_depth <= queue_depth)
38463 return;
38464 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38465 unsigned long num_rsrc_err, num_cmd_success;
38466 int i;
38467
38468 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38469 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38470 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38471 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38472
38473 /*
38474 * The error and success command counters are global per
38475 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38476 }
38477 }
38478 lpfc_destroy_vport_work_array(phba, vports);
38479 - atomic_set(&phba->num_rsrc_err, 0);
38480 - atomic_set(&phba->num_cmd_success, 0);
38481 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38482 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38483 }
38484
38485 /**
38486 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38487 }
38488 }
38489 lpfc_destroy_vport_work_array(phba, vports);
38490 - atomic_set(&phba->num_rsrc_err, 0);
38491 - atomic_set(&phba->num_cmd_success, 0);
38492 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38493 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38494 }
38495
38496 /**
38497 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38498 index af763ea..41904f7 100644
38499 --- a/drivers/scsi/pmcraid.c
38500 +++ b/drivers/scsi/pmcraid.c
38501 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38502 res->scsi_dev = scsi_dev;
38503 scsi_dev->hostdata = res;
38504 res->change_detected = 0;
38505 - atomic_set(&res->read_failures, 0);
38506 - atomic_set(&res->write_failures, 0);
38507 + atomic_set_unchecked(&res->read_failures, 0);
38508 + atomic_set_unchecked(&res->write_failures, 0);
38509 rc = 0;
38510 }
38511 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38512 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38513
38514 /* If this was a SCSI read/write command keep count of errors */
38515 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38516 - atomic_inc(&res->read_failures);
38517 + atomic_inc_unchecked(&res->read_failures);
38518 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38519 - atomic_inc(&res->write_failures);
38520 + atomic_inc_unchecked(&res->write_failures);
38521
38522 if (!RES_IS_GSCSI(res->cfg_entry) &&
38523 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38524 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38525 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38526 * hrrq_id assigned here in queuecommand
38527 */
38528 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38529 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38530 pinstance->num_hrrq;
38531 cmd->cmd_done = pmcraid_io_done;
38532
38533 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38534 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38535 * hrrq_id assigned here in queuecommand
38536 */
38537 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38538 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38539 pinstance->num_hrrq;
38540
38541 if (request_size) {
38542 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38543
38544 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38545 /* add resources only after host is added into system */
38546 - if (!atomic_read(&pinstance->expose_resources))
38547 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38548 return;
38549
38550 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38551 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38552 init_waitqueue_head(&pinstance->reset_wait_q);
38553
38554 atomic_set(&pinstance->outstanding_cmds, 0);
38555 - atomic_set(&pinstance->last_message_id, 0);
38556 - atomic_set(&pinstance->expose_resources, 0);
38557 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38558 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38559
38560 INIT_LIST_HEAD(&pinstance->free_res_q);
38561 INIT_LIST_HEAD(&pinstance->used_res_q);
38562 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38563 /* Schedule worker thread to handle CCN and take care of adding and
38564 * removing devices to OS
38565 */
38566 - atomic_set(&pinstance->expose_resources, 1);
38567 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38568 schedule_work(&pinstance->worker_q);
38569 return rc;
38570
38571 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38572 index e1d150f..6c6df44 100644
38573 --- a/drivers/scsi/pmcraid.h
38574 +++ b/drivers/scsi/pmcraid.h
38575 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38576 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38577
38578 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38579 - atomic_t last_message_id;
38580 + atomic_unchecked_t last_message_id;
38581
38582 /* configuration table */
38583 struct pmcraid_config_table *cfg_table;
38584 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38585 atomic_t outstanding_cmds;
38586
38587 /* should add/delete resources to mid-layer now ?*/
38588 - atomic_t expose_resources;
38589 + atomic_unchecked_t expose_resources;
38590
38591
38592
38593 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38594 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38595 };
38596 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38597 - atomic_t read_failures; /* count of failed READ commands */
38598 - atomic_t write_failures; /* count of failed WRITE commands */
38599 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38600 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38601
38602 /* To indicate add/delete/modify during CCN */
38603 u8 change_detected;
38604 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38605 index 83d7984..a27d947 100644
38606 --- a/drivers/scsi/qla2xxx/qla_attr.c
38607 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38608 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38609 return 0;
38610 }
38611
38612 -struct fc_function_template qla2xxx_transport_functions = {
38613 +fc_function_template_no_const qla2xxx_transport_functions = {
38614
38615 .show_host_node_name = 1,
38616 .show_host_port_name = 1,
38617 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38618 .bsg_timeout = qla24xx_bsg_timeout,
38619 };
38620
38621 -struct fc_function_template qla2xxx_transport_vport_functions = {
38622 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38623
38624 .show_host_node_name = 1,
38625 .show_host_port_name = 1,
38626 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38627 index 6acb397..d86e3e0 100644
38628 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38629 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38630 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38631 struct device_attribute;
38632 extern struct device_attribute *qla2x00_host_attrs[];
38633 struct fc_function_template;
38634 -extern struct fc_function_template qla2xxx_transport_functions;
38635 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38636 +extern fc_function_template_no_const qla2xxx_transport_functions;
38637 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38638 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38639 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38640 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38641 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38642 index f4b1fc8..a1ce4dd 100644
38643 --- a/drivers/scsi/qla2xxx/qla_os.c
38644 +++ b/drivers/scsi/qla2xxx/qla_os.c
38645 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38646 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38647 /* Ok, a 64bit DMA mask is applicable. */
38648 ha->flags.enable_64bit_addressing = 1;
38649 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38650 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38651 + pax_open_kernel();
38652 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38653 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38654 + pax_close_kernel();
38655 return;
38656 }
38657 }
38658 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38659 index 329d553..f20d31d 100644
38660 --- a/drivers/scsi/qla4xxx/ql4_def.h
38661 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38662 @@ -273,7 +273,7 @@ struct ddb_entry {
38663 * (4000 only) */
38664 atomic_t relogin_timer; /* Max Time to wait for
38665 * relogin to complete */
38666 - atomic_t relogin_retry_count; /* Num of times relogin has been
38667 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38668 * retried */
38669 uint32_t default_time2wait; /* Default Min time between
38670 * relogins (+aens) */
38671 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38672 index fbc546e..c7d1b48 100644
38673 --- a/drivers/scsi/qla4xxx/ql4_os.c
38674 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38675 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38676 */
38677 if (!iscsi_is_session_online(cls_sess)) {
38678 /* Reset retry relogin timer */
38679 - atomic_inc(&ddb_entry->relogin_retry_count);
38680 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38681 DEBUG2(ql4_printk(KERN_INFO, ha,
38682 "%s: index[%d] relogin timed out-retrying"
38683 " relogin (%d), retry (%d)\n", __func__,
38684 ddb_entry->fw_ddb_index,
38685 - atomic_read(&ddb_entry->relogin_retry_count),
38686 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38687 ddb_entry->default_time2wait + 4));
38688 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38689 atomic_set(&ddb_entry->retry_relogin_timer,
38690 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38691
38692 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38693 atomic_set(&ddb_entry->relogin_timer, 0);
38694 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38695 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38696 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38697 ddb_entry->default_relogin_timeout =
38698 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38699 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38700 index 2c0d0ec..4e8681a 100644
38701 --- a/drivers/scsi/scsi.c
38702 +++ b/drivers/scsi/scsi.c
38703 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38704 unsigned long timeout;
38705 int rtn = 0;
38706
38707 - atomic_inc(&cmd->device->iorequest_cnt);
38708 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38709
38710 /* check if the device is still usable */
38711 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38712 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38713 index 9032e91..7a805d0 100644
38714 --- a/drivers/scsi/scsi_lib.c
38715 +++ b/drivers/scsi/scsi_lib.c
38716 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38717 shost = sdev->host;
38718 scsi_init_cmd_errh(cmd);
38719 cmd->result = DID_NO_CONNECT << 16;
38720 - atomic_inc(&cmd->device->iorequest_cnt);
38721 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38722
38723 /*
38724 * SCSI request completion path will do scsi_device_unbusy(),
38725 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38726
38727 INIT_LIST_HEAD(&cmd->eh_entry);
38728
38729 - atomic_inc(&cmd->device->iodone_cnt);
38730 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38731 if (cmd->result)
38732 - atomic_inc(&cmd->device->ioerr_cnt);
38733 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38734
38735 disposition = scsi_decide_disposition(cmd);
38736 if (disposition != SUCCESS &&
38737 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38738 index 931a7d9..0c2a754 100644
38739 --- a/drivers/scsi/scsi_sysfs.c
38740 +++ b/drivers/scsi/scsi_sysfs.c
38741 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38742 char *buf) \
38743 { \
38744 struct scsi_device *sdev = to_scsi_device(dev); \
38745 - unsigned long long count = atomic_read(&sdev->field); \
38746 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38747 return snprintf(buf, 20, "0x%llx\n", count); \
38748 } \
38749 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38750 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38751 index 84a1fdf..693b0d6 100644
38752 --- a/drivers/scsi/scsi_tgt_lib.c
38753 +++ b/drivers/scsi/scsi_tgt_lib.c
38754 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38755 int err;
38756
38757 dprintk("%lx %u\n", uaddr, len);
38758 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38759 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38760 if (err) {
38761 /*
38762 * TODO: need to fixup sg_tablesize, max_segment_size,
38763 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38764 index e894ca7..de9d7660 100644
38765 --- a/drivers/scsi/scsi_transport_fc.c
38766 +++ b/drivers/scsi/scsi_transport_fc.c
38767 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38768 * Netlink Infrastructure
38769 */
38770
38771 -static atomic_t fc_event_seq;
38772 +static atomic_unchecked_t fc_event_seq;
38773
38774 /**
38775 * fc_get_event_number - Obtain the next sequential FC event number
38776 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
38777 u32
38778 fc_get_event_number(void)
38779 {
38780 - return atomic_add_return(1, &fc_event_seq);
38781 + return atomic_add_return_unchecked(1, &fc_event_seq);
38782 }
38783 EXPORT_SYMBOL(fc_get_event_number);
38784
38785 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
38786 {
38787 int error;
38788
38789 - atomic_set(&fc_event_seq, 0);
38790 + atomic_set_unchecked(&fc_event_seq, 0);
38791
38792 error = transport_class_register(&fc_host_class);
38793 if (error)
38794 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38795 char *cp;
38796
38797 *val = simple_strtoul(buf, &cp, 0);
38798 - if ((*cp && (*cp != '\n')) || (*val < 0))
38799 + if (*cp && (*cp != '\n'))
38800 return -EINVAL;
38801 /*
38802 * Check for overflow; dev_loss_tmo is u32
38803 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38804 index 31969f2..2b348f0 100644
38805 --- a/drivers/scsi/scsi_transport_iscsi.c
38806 +++ b/drivers/scsi/scsi_transport_iscsi.c
38807 @@ -79,7 +79,7 @@ struct iscsi_internal {
38808 struct transport_container session_cont;
38809 };
38810
38811 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38812 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38813 static struct workqueue_struct *iscsi_eh_timer_workq;
38814
38815 static DEFINE_IDA(iscsi_sess_ida);
38816 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38817 int err;
38818
38819 ihost = shost->shost_data;
38820 - session->sid = atomic_add_return(1, &iscsi_session_nr);
38821 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38822
38823 if (target_id == ISCSI_MAX_TARGET) {
38824 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38825 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
38826 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38827 ISCSI_TRANSPORT_VERSION);
38828
38829 - atomic_set(&iscsi_session_nr, 0);
38830 + atomic_set_unchecked(&iscsi_session_nr, 0);
38831
38832 err = class_register(&iscsi_transport_class);
38833 if (err)
38834 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38835 index 21a045e..ec89e03 100644
38836 --- a/drivers/scsi/scsi_transport_srp.c
38837 +++ b/drivers/scsi/scsi_transport_srp.c
38838 @@ -33,7 +33,7 @@
38839 #include "scsi_transport_srp_internal.h"
38840
38841 struct srp_host_attrs {
38842 - atomic_t next_port_id;
38843 + atomic_unchecked_t next_port_id;
38844 };
38845 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38846
38847 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38848 struct Scsi_Host *shost = dev_to_shost(dev);
38849 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38850
38851 - atomic_set(&srp_host->next_port_id, 0);
38852 + atomic_set_unchecked(&srp_host->next_port_id, 0);
38853 return 0;
38854 }
38855
38856 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38857 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38858 rport->roles = ids->roles;
38859
38860 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38861 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38862 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38863
38864 transport_setup_device(&rport->dev);
38865 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
38866 index a45e12a..d9120cb 100644
38867 --- a/drivers/scsi/sd.c
38868 +++ b/drivers/scsi/sd.c
38869 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
38870 sdkp->disk = gd;
38871 sdkp->index = index;
38872 atomic_set(&sdkp->openers, 0);
38873 - atomic_set(&sdkp->device->ioerr_cnt, 0);
38874 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
38875
38876 if (!sdp->request_queue->rq_timeout) {
38877 if (sdp->type != TYPE_MOD)
38878 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38879 index be2c9a6..275525c 100644
38880 --- a/drivers/scsi/sg.c
38881 +++ b/drivers/scsi/sg.c
38882 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38883 sdp->disk->disk_name,
38884 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38885 NULL,
38886 - (char *)arg);
38887 + (char __user *)arg);
38888 case BLKTRACESTART:
38889 return blk_trace_startstop(sdp->device->request_queue, 1);
38890 case BLKTRACESTOP:
38891 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38892 index 84c2861..ece0a31 100644
38893 --- a/drivers/spi/spi.c
38894 +++ b/drivers/spi/spi.c
38895 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
38896 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38897
38898 /* portable code must never pass more than 32 bytes */
38899 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38900 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38901
38902 static u8 *buf;
38903
38904 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38905 index 34afc16..ffe44dd 100644
38906 --- a/drivers/staging/octeon/ethernet-rx.c
38907 +++ b/drivers/staging/octeon/ethernet-rx.c
38908 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38909 /* Increment RX stats for virtual ports */
38910 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38911 #ifdef CONFIG_64BIT
38912 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38913 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38914 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38915 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38916 #else
38917 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38918 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38919 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38920 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38921 #endif
38922 }
38923 netif_receive_skb(skb);
38924 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38925 dev->name);
38926 */
38927 #ifdef CONFIG_64BIT
38928 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38929 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38930 #else
38931 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38932 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38933 #endif
38934 dev_kfree_skb_irq(skb);
38935 }
38936 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38937 index 683bedc..86dba9a 100644
38938 --- a/drivers/staging/octeon/ethernet.c
38939 +++ b/drivers/staging/octeon/ethernet.c
38940 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38941 * since the RX tasklet also increments it.
38942 */
38943 #ifdef CONFIG_64BIT
38944 - atomic64_add(rx_status.dropped_packets,
38945 - (atomic64_t *)&priv->stats.rx_dropped);
38946 + atomic64_add_unchecked(rx_status.dropped_packets,
38947 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38948 #else
38949 - atomic_add(rx_status.dropped_packets,
38950 - (atomic_t *)&priv->stats.rx_dropped);
38951 + atomic_add_unchecked(rx_status.dropped_packets,
38952 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
38953 #endif
38954 }
38955
38956 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
38957 index a2b7e03..aaf3630 100644
38958 --- a/drivers/staging/ramster/tmem.c
38959 +++ b/drivers/staging/ramster/tmem.c
38960 @@ -50,25 +50,25 @@
38961 * A tmem host implementation must use this function to register callbacks
38962 * for memory allocation.
38963 */
38964 -static struct tmem_hostops tmem_hostops;
38965 +static struct tmem_hostops *tmem_hostops;
38966
38967 static void tmem_objnode_tree_init(void);
38968
38969 void tmem_register_hostops(struct tmem_hostops *m)
38970 {
38971 tmem_objnode_tree_init();
38972 - tmem_hostops = *m;
38973 + tmem_hostops = m;
38974 }
38975
38976 /*
38977 * A tmem host implementation must use this function to register
38978 * callbacks for a page-accessible memory (PAM) implementation.
38979 */
38980 -static struct tmem_pamops tmem_pamops;
38981 +static struct tmem_pamops *tmem_pamops;
38982
38983 void tmem_register_pamops(struct tmem_pamops *m)
38984 {
38985 - tmem_pamops = *m;
38986 + tmem_pamops = m;
38987 }
38988
38989 /*
38990 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
38991 obj->pampd_count = 0;
38992 #ifdef CONFIG_RAMSTER
38993 if (tmem_pamops.new_obj != NULL)
38994 - (*tmem_pamops.new_obj)(obj);
38995 + (tmem_pamops->new_obj)(obj);
38996 #endif
38997 SET_SENTINEL(obj, OBJ);
38998
38999 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39000 rbnode = rb_next(rbnode);
39001 tmem_pampd_destroy_all_in_obj(obj, true);
39002 tmem_obj_free(obj, hb);
39003 - (*tmem_hostops.obj_free)(obj, pool);
39004 + (tmem_hostops->obj_free)(obj, pool);
39005 }
39006 spin_unlock(&hb->lock);
39007 }
39008 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39009 ASSERT_SENTINEL(obj, OBJ);
39010 BUG_ON(obj->pool == NULL);
39011 ASSERT_SENTINEL(obj->pool, POOL);
39012 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39013 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39014 if (unlikely(objnode == NULL))
39015 goto out;
39016 objnode->obj = obj;
39017 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39018 ASSERT_SENTINEL(pool, POOL);
39019 objnode->obj->objnode_count--;
39020 objnode->obj = NULL;
39021 - (*tmem_hostops.objnode_free)(objnode, pool);
39022 + (tmem_hostops->objnode_free)(objnode, pool);
39023 }
39024
39025 /*
39026 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39027 void *old_pampd = *(void **)slot;
39028 *(void **)slot = new_pampd;
39029 if (!no_free)
39030 - (*tmem_pamops.free)(old_pampd, obj->pool,
39031 + (tmem_pamops->free)(old_pampd, obj->pool,
39032 NULL, 0, false);
39033 ret = new_pampd;
39034 }
39035 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39036 if (objnode->slots[i]) {
39037 if (ht == 1) {
39038 obj->pampd_count--;
39039 - (*tmem_pamops.free)(objnode->slots[i],
39040 + (tmem_pamops->free)(objnode->slots[i],
39041 obj->pool, NULL, 0, true);
39042 objnode->slots[i] = NULL;
39043 continue;
39044 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39045 return;
39046 if (obj->objnode_tree_height == 0) {
39047 obj->pampd_count--;
39048 - (*tmem_pamops.free)(obj->objnode_tree_root,
39049 + (tmem_pamops->free)(obj->objnode_tree_root,
39050 obj->pool, NULL, 0, true);
39051 } else {
39052 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39053 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39054 obj->objnode_tree_root = NULL;
39055 #ifdef CONFIG_RAMSTER
39056 if (tmem_pamops.free_obj != NULL)
39057 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39058 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39059 #endif
39060 }
39061
39062 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39063 /* if found, is a dup put, flush the old one */
39064 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39065 BUG_ON(pampd_del != pampd);
39066 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39067 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39068 if (obj->pampd_count == 0) {
39069 objnew = obj;
39070 objfound = NULL;
39071 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39072 pampd = NULL;
39073 }
39074 } else {
39075 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39076 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
39077 if (unlikely(obj == NULL)) {
39078 ret = -ENOMEM;
39079 goto out;
39080 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39081 if (unlikely(ret == -ENOMEM))
39082 /* may have partially built objnode tree ("stump") */
39083 goto delete_and_free;
39084 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39085 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39086 goto out;
39087
39088 delete_and_free:
39089 (void)tmem_pampd_delete_from_obj(obj, index);
39090 if (pampd)
39091 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39092 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39093 if (objnew) {
39094 tmem_obj_free(objnew, hb);
39095 - (*tmem_hostops.obj_free)(objnew, pool);
39096 + (tmem_hostops->obj_free)(objnew, pool);
39097 }
39098 out:
39099 spin_unlock(&hb->lock);
39100 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39101 if (pampd != NULL) {
39102 BUG_ON(obj == NULL);
39103 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39104 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39105 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39106 } else if (delete) {
39107 BUG_ON(obj == NULL);
39108 (void)tmem_pampd_delete_from_obj(obj, index);
39109 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39110 int ret = 0;
39111
39112 if (!is_ephemeral(pool))
39113 - new_pampd = (*tmem_pamops.repatriate_preload)(
39114 + new_pampd = (tmem_pamops->repatriate_preload)(
39115 old_pampd, pool, oidp, index, &intransit);
39116 if (intransit)
39117 ret = -EAGAIN;
39118 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39119 /* must release the hb->lock else repatriate can't sleep */
39120 spin_unlock(&hb->lock);
39121 if (!intransit)
39122 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39123 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39124 oidp, index, free, data);
39125 if (ret == -EAGAIN) {
39126 /* rare I think, but should cond_resched()??? */
39127 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39128 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39129 /* if we bug here, pamops wasn't properly set up for ramster */
39130 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39131 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39132 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39133 out:
39134 spin_unlock(&hb->lock);
39135 return ret;
39136 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39137 if (free) {
39138 if (obj->pampd_count == 0) {
39139 tmem_obj_free(obj, hb);
39140 - (*tmem_hostops.obj_free)(obj, pool);
39141 + (tmem_hostops->obj_free)(obj, pool);
39142 obj = NULL;
39143 }
39144 }
39145 if (free)
39146 - ret = (*tmem_pamops.get_data_and_free)(
39147 + ret = (tmem_pamops->get_data_and_free)(
39148 data, sizep, raw, pampd, pool, oidp, index);
39149 else
39150 - ret = (*tmem_pamops.get_data)(
39151 + ret = (tmem_pamops->get_data)(
39152 data, sizep, raw, pampd, pool, oidp, index);
39153 if (ret < 0)
39154 goto out;
39155 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39156 pampd = tmem_pampd_delete_from_obj(obj, index);
39157 if (pampd == NULL)
39158 goto out;
39159 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39160 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39161 if (obj->pampd_count == 0) {
39162 tmem_obj_free(obj, hb);
39163 - (*tmem_hostops.obj_free)(obj, pool);
39164 + (tmem_hostops->obj_free)(obj, pool);
39165 }
39166 ret = 0;
39167
39168 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39169 goto out;
39170 tmem_pampd_destroy_all_in_obj(obj, false);
39171 tmem_obj_free(obj, hb);
39172 - (*tmem_hostops.obj_free)(obj, pool);
39173 + (tmem_hostops->obj_free)(obj, pool);
39174 ret = 0;
39175
39176 out:
39177 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39178 index dc23395..cf7e9b1 100644
39179 --- a/drivers/staging/rtl8712/rtl871x_io.h
39180 +++ b/drivers/staging/rtl8712/rtl871x_io.h
39181 @@ -108,7 +108,7 @@ struct _io_ops {
39182 u8 *pmem);
39183 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39184 u8 *pmem);
39185 -};
39186 +} __no_const;
39187
39188 struct io_req {
39189 struct list_head list;
39190 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39191 index 180c963..1f18377 100644
39192 --- a/drivers/staging/sbe-2t3e3/netdev.c
39193 +++ b/drivers/staging/sbe-2t3e3/netdev.c
39194 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39195 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39196
39197 if (rlen)
39198 - if (copy_to_user(data, &resp, rlen))
39199 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39200 return -EFAULT;
39201
39202 return 0;
39203 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39204 index c66b8b3..a4a035b 100644
39205 --- a/drivers/staging/usbip/vhci.h
39206 +++ b/drivers/staging/usbip/vhci.h
39207 @@ -83,7 +83,7 @@ struct vhci_hcd {
39208 unsigned resuming:1;
39209 unsigned long re_timeout;
39210
39211 - atomic_t seqnum;
39212 + atomic_unchecked_t seqnum;
39213
39214 /*
39215 * NOTE:
39216 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39217 index 620d1be..1cd6711 100644
39218 --- a/drivers/staging/usbip/vhci_hcd.c
39219 +++ b/drivers/staging/usbip/vhci_hcd.c
39220 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39221 return;
39222 }
39223
39224 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39225 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39226 if (priv->seqnum == 0xffff)
39227 dev_info(&urb->dev->dev, "seqnum max\n");
39228
39229 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39230 return -ENOMEM;
39231 }
39232
39233 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39234 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39235 if (unlink->seqnum == 0xffff)
39236 pr_info("seqnum max\n");
39237
39238 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39239 vdev->rhport = rhport;
39240 }
39241
39242 - atomic_set(&vhci->seqnum, 0);
39243 + atomic_set_unchecked(&vhci->seqnum, 0);
39244 spin_lock_init(&vhci->lock);
39245
39246 hcd->power_budget = 0; /* no limit */
39247 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39248 index f0eaf04..5a82e06 100644
39249 --- a/drivers/staging/usbip/vhci_rx.c
39250 +++ b/drivers/staging/usbip/vhci_rx.c
39251 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39252 if (!urb) {
39253 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39254 pr_info("max seqnum %d\n",
39255 - atomic_read(&the_controller->seqnum));
39256 + atomic_read_unchecked(&the_controller->seqnum));
39257 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39258 return;
39259 }
39260 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39261 index 67b1b88..6392fe9 100644
39262 --- a/drivers/staging/vt6655/hostap.c
39263 +++ b/drivers/staging/vt6655/hostap.c
39264 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39265 *
39266 */
39267
39268 +static net_device_ops_no_const apdev_netdev_ops;
39269 +
39270 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39271 {
39272 PSDevice apdev_priv;
39273 struct net_device *dev = pDevice->dev;
39274 int ret;
39275 - const struct net_device_ops apdev_netdev_ops = {
39276 - .ndo_start_xmit = pDevice->tx_80211,
39277 - };
39278
39279 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39280
39281 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39282 *apdev_priv = *pDevice;
39283 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39284
39285 + /* only half broken now */
39286 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39287 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39288
39289 pDevice->apdev->type = ARPHRD_IEEE80211;
39290 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39291 index 0a73d40..6fda560 100644
39292 --- a/drivers/staging/vt6656/hostap.c
39293 +++ b/drivers/staging/vt6656/hostap.c
39294 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39295 *
39296 */
39297
39298 +static net_device_ops_no_const apdev_netdev_ops;
39299 +
39300 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39301 {
39302 PSDevice apdev_priv;
39303 struct net_device *dev = pDevice->dev;
39304 int ret;
39305 - const struct net_device_ops apdev_netdev_ops = {
39306 - .ndo_start_xmit = pDevice->tx_80211,
39307 - };
39308
39309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39310
39311 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39312 *apdev_priv = *pDevice;
39313 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39314
39315 + /* only half broken now */
39316 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39317 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39318
39319 pDevice->apdev->type = ARPHRD_IEEE80211;
39320 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39321 index 56c8e60..1920c63 100644
39322 --- a/drivers/staging/zcache/tmem.c
39323 +++ b/drivers/staging/zcache/tmem.c
39324 @@ -39,7 +39,7 @@
39325 * A tmem host implementation must use this function to register callbacks
39326 * for memory allocation.
39327 */
39328 -static struct tmem_hostops tmem_hostops;
39329 +static tmem_hostops_no_const tmem_hostops;
39330
39331 static void tmem_objnode_tree_init(void);
39332
39333 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39334 * A tmem host implementation must use this function to register
39335 * callbacks for a page-accessible memory (PAM) implementation
39336 */
39337 -static struct tmem_pamops tmem_pamops;
39338 +static tmem_pamops_no_const tmem_pamops;
39339
39340 void tmem_register_pamops(struct tmem_pamops *m)
39341 {
39342 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39343 index 0d4aa82..f7832d4 100644
39344 --- a/drivers/staging/zcache/tmem.h
39345 +++ b/drivers/staging/zcache/tmem.h
39346 @@ -180,6 +180,7 @@ struct tmem_pamops {
39347 void (*new_obj)(struct tmem_obj *);
39348 int (*replace_in_obj)(void *, struct tmem_obj *);
39349 };
39350 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39351 extern void tmem_register_pamops(struct tmem_pamops *m);
39352
39353 /* memory allocation methods provided by the host implementation */
39354 @@ -189,6 +190,7 @@ struct tmem_hostops {
39355 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39356 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39357 };
39358 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39359 extern void tmem_register_hostops(struct tmem_hostops *m);
39360
39361 /* core tmem accessor functions */
39362 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39363 index 13fe16c..cbdc39a 100644
39364 --- a/drivers/target/target_core_transport.c
39365 +++ b/drivers/target/target_core_transport.c
39366 @@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39367 spin_lock_init(&dev->se_port_lock);
39368 spin_lock_init(&dev->se_tmr_lock);
39369 spin_lock_init(&dev->qf_cmd_lock);
39370 - atomic_set(&dev->dev_ordered_id, 0);
39371 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39372
39373 se_dev_set_default_attribs(dev, dev_limits);
39374
39375 @@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39376 * Used to determine when ORDERED commands should go from
39377 * Dormant to Active status.
39378 */
39379 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39380 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39381 smp_mb__after_atomic_inc();
39382 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39383 cmd->se_ordered_id, cmd->sam_task_attr,
39384 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39385 index 0a6a0bc..5501b06 100644
39386 --- a/drivers/tty/cyclades.c
39387 +++ b/drivers/tty/cyclades.c
39388 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39389 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39390 info->port.count);
39391 #endif
39392 - info->port.count++;
39393 + atomic_inc(&info->port.count);
39394 #ifdef CY_DEBUG_COUNT
39395 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39396 - current->pid, info->port.count);
39397 + current->pid, atomic_read(&info->port.count));
39398 #endif
39399
39400 /*
39401 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39402 for (j = 0; j < cy_card[i].nports; j++) {
39403 info = &cy_card[i].ports[j];
39404
39405 - if (info->port.count) {
39406 + if (atomic_read(&info->port.count)) {
39407 /* XXX is the ldisc num worth this? */
39408 struct tty_struct *tty;
39409 struct tty_ldisc *ld;
39410 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39411 index 13ee53b..418d164 100644
39412 --- a/drivers/tty/hvc/hvc_console.c
39413 +++ b/drivers/tty/hvc/hvc_console.c
39414 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39415
39416 spin_lock_irqsave(&hp->port.lock, flags);
39417 /* Check and then increment for fast path open. */
39418 - if (hp->port.count++ > 0) {
39419 + if (atomic_inc_return(&hp->port.count) > 1) {
39420 spin_unlock_irqrestore(&hp->port.lock, flags);
39421 hvc_kick();
39422 return 0;
39423 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39424
39425 spin_lock_irqsave(&hp->port.lock, flags);
39426
39427 - if (--hp->port.count == 0) {
39428 + if (atomic_dec_return(&hp->port.count) == 0) {
39429 spin_unlock_irqrestore(&hp->port.lock, flags);
39430 /* We are done with the tty pointer now. */
39431 tty_port_tty_set(&hp->port, NULL);
39432 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39433 */
39434 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39435 } else {
39436 - if (hp->port.count < 0)
39437 + if (atomic_read(&hp->port.count) < 0)
39438 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39439 - hp->vtermno, hp->port.count);
39440 + hp->vtermno, atomic_read(&hp->port.count));
39441 spin_unlock_irqrestore(&hp->port.lock, flags);
39442 }
39443 }
39444 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39445 * open->hangup case this can be called after the final close so prevent
39446 * that from happening for now.
39447 */
39448 - if (hp->port.count <= 0) {
39449 + if (atomic_read(&hp->port.count) <= 0) {
39450 spin_unlock_irqrestore(&hp->port.lock, flags);
39451 return;
39452 }
39453
39454 - hp->port.count = 0;
39455 + atomic_set(&hp->port.count, 0);
39456 spin_unlock_irqrestore(&hp->port.lock, flags);
39457 tty_port_tty_set(&hp->port, NULL);
39458
39459 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39460 return -EPIPE;
39461
39462 /* FIXME what's this (unprotected) check for? */
39463 - if (hp->port.count <= 0)
39464 + if (atomic_read(&hp->port.count) <= 0)
39465 return -EIO;
39466
39467 spin_lock_irqsave(&hp->lock, flags);
39468 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39469 index cab5c7a..4cc66ea 100644
39470 --- a/drivers/tty/hvc/hvcs.c
39471 +++ b/drivers/tty/hvc/hvcs.c
39472 @@ -83,6 +83,7 @@
39473 #include <asm/hvcserver.h>
39474 #include <asm/uaccess.h>
39475 #include <asm/vio.h>
39476 +#include <asm/local.h>
39477
39478 /*
39479 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39480 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39481
39482 spin_lock_irqsave(&hvcsd->lock, flags);
39483
39484 - if (hvcsd->port.count > 0) {
39485 + if (atomic_read(&hvcsd->port.count) > 0) {
39486 spin_unlock_irqrestore(&hvcsd->lock, flags);
39487 printk(KERN_INFO "HVCS: vterm state unchanged. "
39488 "The hvcs device node is still in use.\n");
39489 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39490 }
39491 }
39492
39493 - hvcsd->port.count = 0;
39494 + atomic_set(&hvcsd->port.count, 0);
39495 hvcsd->port.tty = tty;
39496 tty->driver_data = hvcsd;
39497
39498 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39499 unsigned long flags;
39500
39501 spin_lock_irqsave(&hvcsd->lock, flags);
39502 - hvcsd->port.count++;
39503 + atomic_inc(&hvcsd->port.count);
39504 hvcsd->todo_mask |= HVCS_SCHED_READ;
39505 spin_unlock_irqrestore(&hvcsd->lock, flags);
39506
39507 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39508 hvcsd = tty->driver_data;
39509
39510 spin_lock_irqsave(&hvcsd->lock, flags);
39511 - if (--hvcsd->port.count == 0) {
39512 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39513
39514 vio_disable_interrupts(hvcsd->vdev);
39515
39516 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39517
39518 free_irq(irq, hvcsd);
39519 return;
39520 - } else if (hvcsd->port.count < 0) {
39521 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39522 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39523 " is missmanaged.\n",
39524 - hvcsd->vdev->unit_address, hvcsd->port.count);
39525 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39526 }
39527
39528 spin_unlock_irqrestore(&hvcsd->lock, flags);
39529 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39530
39531 spin_lock_irqsave(&hvcsd->lock, flags);
39532 /* Preserve this so that we know how many kref refs to put */
39533 - temp_open_count = hvcsd->port.count;
39534 + temp_open_count = atomic_read(&hvcsd->port.count);
39535
39536 /*
39537 * Don't kref put inside the spinlock because the destruction
39538 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39539 tty->driver_data = NULL;
39540 hvcsd->port.tty = NULL;
39541
39542 - hvcsd->port.count = 0;
39543 + atomic_set(&hvcsd->port.count, 0);
39544
39545 /* This will drop any buffered data on the floor which is OK in a hangup
39546 * scenario. */
39547 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39548 * the middle of a write operation? This is a crummy place to do this
39549 * but we want to keep it all in the spinlock.
39550 */
39551 - if (hvcsd->port.count <= 0) {
39552 + if (atomic_read(&hvcsd->port.count) <= 0) {
39553 spin_unlock_irqrestore(&hvcsd->lock, flags);
39554 return -ENODEV;
39555 }
39556 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39557 {
39558 struct hvcs_struct *hvcsd = tty->driver_data;
39559
39560 - if (!hvcsd || hvcsd->port.count <= 0)
39561 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39562 return 0;
39563
39564 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39565 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39566 index 160f0ad..588b853 100644
39567 --- a/drivers/tty/ipwireless/tty.c
39568 +++ b/drivers/tty/ipwireless/tty.c
39569 @@ -29,6 +29,7 @@
39570 #include <linux/tty_driver.h>
39571 #include <linux/tty_flip.h>
39572 #include <linux/uaccess.h>
39573 +#include <asm/local.h>
39574
39575 #include "tty.h"
39576 #include "network.h"
39577 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39578 mutex_unlock(&tty->ipw_tty_mutex);
39579 return -ENODEV;
39580 }
39581 - if (tty->port.count == 0)
39582 + if (atomic_read(&tty->port.count) == 0)
39583 tty->tx_bytes_queued = 0;
39584
39585 - tty->port.count++;
39586 + atomic_inc(&tty->port.count);
39587
39588 tty->port.tty = linux_tty;
39589 linux_tty->driver_data = tty;
39590 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39591
39592 static void do_ipw_close(struct ipw_tty *tty)
39593 {
39594 - tty->port.count--;
39595 -
39596 - if (tty->port.count == 0) {
39597 + if (atomic_dec_return(&tty->port.count) == 0) {
39598 struct tty_struct *linux_tty = tty->port.tty;
39599
39600 if (linux_tty != NULL) {
39601 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39602 return;
39603
39604 mutex_lock(&tty->ipw_tty_mutex);
39605 - if (tty->port.count == 0) {
39606 + if (atomic_read(&tty->port.count) == 0) {
39607 mutex_unlock(&tty->ipw_tty_mutex);
39608 return;
39609 }
39610 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39611 return;
39612 }
39613
39614 - if (!tty->port.count) {
39615 + if (!atomic_read(&tty->port.count)) {
39616 mutex_unlock(&tty->ipw_tty_mutex);
39617 return;
39618 }
39619 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39620 return -ENODEV;
39621
39622 mutex_lock(&tty->ipw_tty_mutex);
39623 - if (!tty->port.count) {
39624 + if (!atomic_read(&tty->port.count)) {
39625 mutex_unlock(&tty->ipw_tty_mutex);
39626 return -EINVAL;
39627 }
39628 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39629 if (!tty)
39630 return -ENODEV;
39631
39632 - if (!tty->port.count)
39633 + if (!atomic_read(&tty->port.count))
39634 return -EINVAL;
39635
39636 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39637 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39638 if (!tty)
39639 return 0;
39640
39641 - if (!tty->port.count)
39642 + if (!atomic_read(&tty->port.count))
39643 return 0;
39644
39645 return tty->tx_bytes_queued;
39646 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39647 if (!tty)
39648 return -ENODEV;
39649
39650 - if (!tty->port.count)
39651 + if (!atomic_read(&tty->port.count))
39652 return -EINVAL;
39653
39654 return get_control_lines(tty);
39655 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39656 if (!tty)
39657 return -ENODEV;
39658
39659 - if (!tty->port.count)
39660 + if (!atomic_read(&tty->port.count))
39661 return -EINVAL;
39662
39663 return set_control_lines(tty, set, clear);
39664 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39665 if (!tty)
39666 return -ENODEV;
39667
39668 - if (!tty->port.count)
39669 + if (!atomic_read(&tty->port.count))
39670 return -EINVAL;
39671
39672 /* FIXME: Exactly how is the tty object locked here .. */
39673 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39674 * are gone */
39675 mutex_lock(&ttyj->ipw_tty_mutex);
39676 }
39677 - while (ttyj->port.count)
39678 + while (atomic_read(&ttyj->port.count))
39679 do_ipw_close(ttyj);
39680 ipwireless_disassociate_network_ttys(network,
39681 ttyj->channel_idx);
39682 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39683 index 56e616b..9d9f10a 100644
39684 --- a/drivers/tty/moxa.c
39685 +++ b/drivers/tty/moxa.c
39686 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39687 }
39688
39689 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39690 - ch->port.count++;
39691 + atomic_inc(&ch->port.count);
39692 tty->driver_data = ch;
39693 tty_port_tty_set(&ch->port, tty);
39694 mutex_lock(&ch->port.mutex);
39695 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39696 index 1e8e8ce..a9efc93 100644
39697 --- a/drivers/tty/n_gsm.c
39698 +++ b/drivers/tty/n_gsm.c
39699 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39700 kref_init(&dlci->ref);
39701 mutex_init(&dlci->mutex);
39702 dlci->fifo = &dlci->_fifo;
39703 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39704 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39705 kfree(dlci);
39706 return NULL;
39707 }
39708 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39709 struct gsm_dlci *dlci = tty->driver_data;
39710 struct tty_port *port = &dlci->port;
39711
39712 - port->count++;
39713 + atomic_inc(&port->count);
39714 dlci_get(dlci);
39715 dlci_get(dlci->gsm->dlci[0]);
39716 mux_get(dlci->gsm);
39717 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39718 index 8c0b7b4..e88f052 100644
39719 --- a/drivers/tty/n_tty.c
39720 +++ b/drivers/tty/n_tty.c
39721 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39722 {
39723 *ops = tty_ldisc_N_TTY;
39724 ops->owner = NULL;
39725 - ops->refcount = ops->flags = 0;
39726 + atomic_set(&ops->refcount, 0);
39727 + ops->flags = 0;
39728 }
39729 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39730 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39731 index 8cf8d0a..4ef9ed0 100644
39732 --- a/drivers/tty/pty.c
39733 +++ b/drivers/tty/pty.c
39734 @@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39735 panic("Couldn't register Unix98 pts driver");
39736
39737 /* Now create the /dev/ptmx special device */
39738 + pax_open_kernel();
39739 tty_default_fops(&ptmx_fops);
39740 - ptmx_fops.open = ptmx_open;
39741 + *(void **)&ptmx_fops.open = ptmx_open;
39742 + pax_close_kernel();
39743
39744 cdev_init(&ptmx_cdev, &ptmx_fops);
39745 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39746 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39747 index 9700d34..df7520c 100644
39748 --- a/drivers/tty/rocket.c
39749 +++ b/drivers/tty/rocket.c
39750 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39751 tty->driver_data = info;
39752 tty_port_tty_set(port, tty);
39753
39754 - if (port->count++ == 0) {
39755 + if (atomic_inc_return(&port->count) == 1) {
39756 atomic_inc(&rp_num_ports_open);
39757
39758 #ifdef ROCKET_DEBUG_OPEN
39759 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39760 #endif
39761 }
39762 #ifdef ROCKET_DEBUG_OPEN
39763 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
39764 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
39765 #endif
39766
39767 /*
39768 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
39769 spin_unlock_irqrestore(&info->port.lock, flags);
39770 return;
39771 }
39772 - if (info->port.count)
39773 + if (atomic_read(&info->port.count))
39774 atomic_dec(&rp_num_ports_open);
39775 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
39776 spin_unlock_irqrestore(&info->port.lock, flags);
39777 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39778 index 1002054..dd644a8 100644
39779 --- a/drivers/tty/serial/kgdboc.c
39780 +++ b/drivers/tty/serial/kgdboc.c
39781 @@ -24,8 +24,9 @@
39782 #define MAX_CONFIG_LEN 40
39783
39784 static struct kgdb_io kgdboc_io_ops;
39785 +static struct kgdb_io kgdboc_io_ops_console;
39786
39787 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39788 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39789 static int configured = -1;
39790
39791 static char config[MAX_CONFIG_LEN];
39792 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
39793 kgdboc_unregister_kbd();
39794 if (configured == 1)
39795 kgdb_unregister_io_module(&kgdboc_io_ops);
39796 + else if (configured == 2)
39797 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
39798 }
39799
39800 static int configure_kgdboc(void)
39801 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
39802 int err;
39803 char *cptr = config;
39804 struct console *cons;
39805 + int is_console = 0;
39806
39807 err = kgdboc_option_setup(config);
39808 if (err || !strlen(config) || isspace(config[0]))
39809 goto noconfig;
39810
39811 err = -ENODEV;
39812 - kgdboc_io_ops.is_console = 0;
39813 kgdb_tty_driver = NULL;
39814
39815 kgdboc_use_kms = 0;
39816 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
39817 int idx;
39818 if (cons->device && cons->device(cons, &idx) == p &&
39819 idx == tty_line) {
39820 - kgdboc_io_ops.is_console = 1;
39821 + is_console = 1;
39822 break;
39823 }
39824 cons = cons->next;
39825 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
39826 kgdb_tty_line = tty_line;
39827
39828 do_register:
39829 - err = kgdb_register_io_module(&kgdboc_io_ops);
39830 + if (is_console) {
39831 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
39832 + configured = 2;
39833 + } else {
39834 + err = kgdb_register_io_module(&kgdboc_io_ops);
39835 + configured = 1;
39836 + }
39837 if (err)
39838 goto noconfig;
39839
39840 @@ -205,8 +214,6 @@ do_register:
39841 if (err)
39842 goto nmi_con_failed;
39843
39844 - configured = 1;
39845 -
39846 return 0;
39847
39848 nmi_con_failed:
39849 @@ -223,7 +230,7 @@ noconfig:
39850 static int __init init_kgdboc(void)
39851 {
39852 /* Already configured? */
39853 - if (configured == 1)
39854 + if (configured >= 1)
39855 return 0;
39856
39857 return configure_kgdboc();
39858 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39859 if (config[len - 1] == '\n')
39860 config[len - 1] = '\0';
39861
39862 - if (configured == 1)
39863 + if (configured >= 1)
39864 cleanup_kgdboc();
39865
39866 /* Go and configure with the new params. */
39867 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
39868 .post_exception = kgdboc_post_exp_handler,
39869 };
39870
39871 +static struct kgdb_io kgdboc_io_ops_console = {
39872 + .name = "kgdboc",
39873 + .read_char = kgdboc_get_char,
39874 + .write_char = kgdboc_put_char,
39875 + .pre_exception = kgdboc_pre_exp_handler,
39876 + .post_exception = kgdboc_post_exp_handler,
39877 + .is_console = 1
39878 +};
39879 +
39880 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39881 /* This is only available if kgdboc is a built in for early debugging */
39882 static int __init kgdboc_early_init(char *opt)
39883 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
39884 index 7f04717..0f3794f 100644
39885 --- a/drivers/tty/serial/samsung.c
39886 +++ b/drivers/tty/serial/samsung.c
39887 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
39888 }
39889 }
39890
39891 +static int s3c64xx_serial_startup(struct uart_port *port);
39892 static int s3c24xx_serial_startup(struct uart_port *port)
39893 {
39894 struct s3c24xx_uart_port *ourport = to_ourport(port);
39895 int ret;
39896
39897 + /* Startup sequence is different for s3c64xx and higher SoC's */
39898 + if (s3c24xx_serial_has_interrupt_mask(port))
39899 + return s3c64xx_serial_startup(port);
39900 +
39901 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
39902 port->mapbase, port->membase);
39903
39904 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
39905 /* setup info for port */
39906 port->dev = &platdev->dev;
39907
39908 - /* Startup sequence is different for s3c64xx and higher SoC's */
39909 - if (s3c24xx_serial_has_interrupt_mask(port))
39910 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
39911 -
39912 port->uartclk = 1;
39913
39914 if (cfg->uart_flags & UPF_CONS_FLOW) {
39915 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
39916 index 0fcfd98..8244fce 100644
39917 --- a/drivers/tty/serial/serial_core.c
39918 +++ b/drivers/tty/serial/serial_core.c
39919 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
39920 uart_flush_buffer(tty);
39921 uart_shutdown(tty, state);
39922 spin_lock_irqsave(&port->lock, flags);
39923 - port->count = 0;
39924 + atomic_set(&port->count, 0);
39925 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
39926 spin_unlock_irqrestore(&port->lock, flags);
39927 tty_port_tty_set(port, NULL);
39928 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39929 goto end;
39930 }
39931
39932 - port->count++;
39933 + atomic_inc(&port->count);
39934 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
39935 retval = -ENXIO;
39936 goto err_dec_count;
39937 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39938 /*
39939 * Make sure the device is in D0 state.
39940 */
39941 - if (port->count == 1)
39942 + if (atomic_read(&port->count) == 1)
39943 uart_change_pm(state, 0);
39944
39945 /*
39946 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39947 end:
39948 return retval;
39949 err_dec_count:
39950 - port->count--;
39951 + atomic_inc(&port->count);
39952 mutex_unlock(&port->mutex);
39953 goto end;
39954 }
39955 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
39956 index 70e3a52..5742052 100644
39957 --- a/drivers/tty/synclink.c
39958 +++ b/drivers/tty/synclink.c
39959 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39960
39961 if (debug_level >= DEBUG_LEVEL_INFO)
39962 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
39963 - __FILE__,__LINE__, info->device_name, info->port.count);
39964 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39965
39966 if (tty_port_close_start(&info->port, tty, filp) == 0)
39967 goto cleanup;
39968 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39969 cleanup:
39970 if (debug_level >= DEBUG_LEVEL_INFO)
39971 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
39972 - tty->driver->name, info->port.count);
39973 + tty->driver->name, atomic_read(&info->port.count));
39974
39975 } /* end of mgsl_close() */
39976
39977 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
39978
39979 mgsl_flush_buffer(tty);
39980 shutdown(info);
39981 -
39982 - info->port.count = 0;
39983 +
39984 + atomic_set(&info->port.count, 0);
39985 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39986 info->port.tty = NULL;
39987
39988 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39989
39990 if (debug_level >= DEBUG_LEVEL_INFO)
39991 printk("%s(%d):block_til_ready before block on %s count=%d\n",
39992 - __FILE__,__LINE__, tty->driver->name, port->count );
39993 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39994
39995 spin_lock_irqsave(&info->irq_spinlock, flags);
39996 if (!tty_hung_up_p(filp)) {
39997 extra_count = true;
39998 - port->count--;
39999 + atomic_dec(&port->count);
40000 }
40001 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40002 port->blocked_open++;
40003 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40004
40005 if (debug_level >= DEBUG_LEVEL_INFO)
40006 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40007 - __FILE__,__LINE__, tty->driver->name, port->count );
40008 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40009
40010 tty_unlock(tty);
40011 schedule();
40012 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40013
40014 /* FIXME: Racy on hangup during close wait */
40015 if (extra_count)
40016 - port->count++;
40017 + atomic_inc(&port->count);
40018 port->blocked_open--;
40019
40020 if (debug_level >= DEBUG_LEVEL_INFO)
40021 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40022 - __FILE__,__LINE__, tty->driver->name, port->count );
40023 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40024
40025 if (!retval)
40026 port->flags |= ASYNC_NORMAL_ACTIVE;
40027 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40028
40029 if (debug_level >= DEBUG_LEVEL_INFO)
40030 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40031 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40032 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40033
40034 /* If port is closing, signal caller to try again */
40035 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40036 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40037 spin_unlock_irqrestore(&info->netlock, flags);
40038 goto cleanup;
40039 }
40040 - info->port.count++;
40041 + atomic_inc(&info->port.count);
40042 spin_unlock_irqrestore(&info->netlock, flags);
40043
40044 - if (info->port.count == 1) {
40045 + if (atomic_read(&info->port.count) == 1) {
40046 /* 1st open on this device, init hardware */
40047 retval = startup(info);
40048 if (retval < 0)
40049 @@ -3451,8 +3451,8 @@ cleanup:
40050 if (retval) {
40051 if (tty->count == 1)
40052 info->port.tty = NULL; /* tty layer will release tty struct */
40053 - if(info->port.count)
40054 - info->port.count--;
40055 + if (atomic_read(&info->port.count))
40056 + atomic_dec(&info->port.count);
40057 }
40058
40059 return retval;
40060 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40061 unsigned short new_crctype;
40062
40063 /* return error if TTY interface open */
40064 - if (info->port.count)
40065 + if (atomic_read(&info->port.count))
40066 return -EBUSY;
40067
40068 switch (encoding)
40069 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40070
40071 /* arbitrate between network and tty opens */
40072 spin_lock_irqsave(&info->netlock, flags);
40073 - if (info->port.count != 0 || info->netcount != 0) {
40074 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40075 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40076 spin_unlock_irqrestore(&info->netlock, flags);
40077 return -EBUSY;
40078 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40079 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40080
40081 /* return error if TTY interface open */
40082 - if (info->port.count)
40083 + if (atomic_read(&info->port.count))
40084 return -EBUSY;
40085
40086 if (cmd != SIOCWANDEV)
40087 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40088 index b38e954..ce45b38 100644
40089 --- a/drivers/tty/synclink_gt.c
40090 +++ b/drivers/tty/synclink_gt.c
40091 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40092 tty->driver_data = info;
40093 info->port.tty = tty;
40094
40095 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40096 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40097
40098 /* If port is closing, signal caller to try again */
40099 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40100 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40101 mutex_unlock(&info->port.mutex);
40102 goto cleanup;
40103 }
40104 - info->port.count++;
40105 + atomic_inc(&info->port.count);
40106 spin_unlock_irqrestore(&info->netlock, flags);
40107
40108 - if (info->port.count == 1) {
40109 + if (atomic_read(&info->port.count) == 1) {
40110 /* 1st open on this device, init hardware */
40111 retval = startup(info);
40112 if (retval < 0) {
40113 @@ -716,8 +716,8 @@ cleanup:
40114 if (retval) {
40115 if (tty->count == 1)
40116 info->port.tty = NULL; /* tty layer will release tty struct */
40117 - if(info->port.count)
40118 - info->port.count--;
40119 + if(atomic_read(&info->port.count))
40120 + atomic_dec(&info->port.count);
40121 }
40122
40123 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40124 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40125
40126 if (sanity_check(info, tty->name, "close"))
40127 return;
40128 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40129 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40130
40131 if (tty_port_close_start(&info->port, tty, filp) == 0)
40132 goto cleanup;
40133 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40134 tty_port_close_end(&info->port, tty);
40135 info->port.tty = NULL;
40136 cleanup:
40137 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40138 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40139 }
40140
40141 static void hangup(struct tty_struct *tty)
40142 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40143 shutdown(info);
40144
40145 spin_lock_irqsave(&info->port.lock, flags);
40146 - info->port.count = 0;
40147 + atomic_set(&info->port.count, 0);
40148 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40149 info->port.tty = NULL;
40150 spin_unlock_irqrestore(&info->port.lock, flags);
40151 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40152 unsigned short new_crctype;
40153
40154 /* return error if TTY interface open */
40155 - if (info->port.count)
40156 + if (atomic_read(&info->port.count))
40157 return -EBUSY;
40158
40159 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40160 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40161
40162 /* arbitrate between network and tty opens */
40163 spin_lock_irqsave(&info->netlock, flags);
40164 - if (info->port.count != 0 || info->netcount != 0) {
40165 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40166 DBGINFO(("%s hdlc_open busy\n", dev->name));
40167 spin_unlock_irqrestore(&info->netlock, flags);
40168 return -EBUSY;
40169 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40170 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40171
40172 /* return error if TTY interface open */
40173 - if (info->port.count)
40174 + if (atomic_read(&info->port.count))
40175 return -EBUSY;
40176
40177 if (cmd != SIOCWANDEV)
40178 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40179 if (port == NULL)
40180 continue;
40181 spin_lock(&port->lock);
40182 - if ((port->port.count || port->netcount) &&
40183 + if ((atomic_read(&port->port.count) || port->netcount) &&
40184 port->pending_bh && !port->bh_running &&
40185 !port->bh_requested) {
40186 DBGISR(("%s bh queued\n", port->device_name));
40187 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40188 spin_lock_irqsave(&info->lock, flags);
40189 if (!tty_hung_up_p(filp)) {
40190 extra_count = true;
40191 - port->count--;
40192 + atomic_dec(&port->count);
40193 }
40194 spin_unlock_irqrestore(&info->lock, flags);
40195 port->blocked_open++;
40196 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40197 remove_wait_queue(&port->open_wait, &wait);
40198
40199 if (extra_count)
40200 - port->count++;
40201 + atomic_inc(&port->count);
40202 port->blocked_open--;
40203
40204 if (!retval)
40205 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40206 index f17d9f3..27a041b 100644
40207 --- a/drivers/tty/synclinkmp.c
40208 +++ b/drivers/tty/synclinkmp.c
40209 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40210
40211 if (debug_level >= DEBUG_LEVEL_INFO)
40212 printk("%s(%d):%s open(), old ref count = %d\n",
40213 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40214 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40215
40216 /* If port is closing, signal caller to try again */
40217 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40218 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40219 spin_unlock_irqrestore(&info->netlock, flags);
40220 goto cleanup;
40221 }
40222 - info->port.count++;
40223 + atomic_inc(&info->port.count);
40224 spin_unlock_irqrestore(&info->netlock, flags);
40225
40226 - if (info->port.count == 1) {
40227 + if (atomic_read(&info->port.count) == 1) {
40228 /* 1st open on this device, init hardware */
40229 retval = startup(info);
40230 if (retval < 0)
40231 @@ -797,8 +797,8 @@ cleanup:
40232 if (retval) {
40233 if (tty->count == 1)
40234 info->port.tty = NULL; /* tty layer will release tty struct */
40235 - if(info->port.count)
40236 - info->port.count--;
40237 + if(atomic_read(&info->port.count))
40238 + atomic_dec(&info->port.count);
40239 }
40240
40241 return retval;
40242 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40243
40244 if (debug_level >= DEBUG_LEVEL_INFO)
40245 printk("%s(%d):%s close() entry, count=%d\n",
40246 - __FILE__,__LINE__, info->device_name, info->port.count);
40247 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40248
40249 if (tty_port_close_start(&info->port, tty, filp) == 0)
40250 goto cleanup;
40251 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40252 cleanup:
40253 if (debug_level >= DEBUG_LEVEL_INFO)
40254 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40255 - tty->driver->name, info->port.count);
40256 + tty->driver->name, atomic_read(&info->port.count));
40257 }
40258
40259 /* Called by tty_hangup() when a hangup is signaled.
40260 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40261 shutdown(info);
40262
40263 spin_lock_irqsave(&info->port.lock, flags);
40264 - info->port.count = 0;
40265 + atomic_set(&info->port.count, 0);
40266 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40267 info->port.tty = NULL;
40268 spin_unlock_irqrestore(&info->port.lock, flags);
40269 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40270 unsigned short new_crctype;
40271
40272 /* return error if TTY interface open */
40273 - if (info->port.count)
40274 + if (atomic_read(&info->port.count))
40275 return -EBUSY;
40276
40277 switch (encoding)
40278 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40279
40280 /* arbitrate between network and tty opens */
40281 spin_lock_irqsave(&info->netlock, flags);
40282 - if (info->port.count != 0 || info->netcount != 0) {
40283 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40284 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40285 spin_unlock_irqrestore(&info->netlock, flags);
40286 return -EBUSY;
40287 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40288 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40289
40290 /* return error if TTY interface open */
40291 - if (info->port.count)
40292 + if (atomic_read(&info->port.count))
40293 return -EBUSY;
40294
40295 if (cmd != SIOCWANDEV)
40296 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40297 * do not request bottom half processing if the
40298 * device is not open in a normal mode.
40299 */
40300 - if ( port && (port->port.count || port->netcount) &&
40301 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40302 port->pending_bh && !port->bh_running &&
40303 !port->bh_requested ) {
40304 if ( debug_level >= DEBUG_LEVEL_ISR )
40305 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40306
40307 if (debug_level >= DEBUG_LEVEL_INFO)
40308 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40309 - __FILE__,__LINE__, tty->driver->name, port->count );
40310 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40311
40312 spin_lock_irqsave(&info->lock, flags);
40313 if (!tty_hung_up_p(filp)) {
40314 extra_count = true;
40315 - port->count--;
40316 + atomic_dec(&port->count);
40317 }
40318 spin_unlock_irqrestore(&info->lock, flags);
40319 port->blocked_open++;
40320 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40321
40322 if (debug_level >= DEBUG_LEVEL_INFO)
40323 printk("%s(%d):%s block_til_ready() count=%d\n",
40324 - __FILE__,__LINE__, tty->driver->name, port->count );
40325 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40326
40327 tty_unlock(tty);
40328 schedule();
40329 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40330 remove_wait_queue(&port->open_wait, &wait);
40331
40332 if (extra_count)
40333 - port->count++;
40334 + atomic_inc(&port->count);
40335 port->blocked_open--;
40336
40337 if (debug_level >= DEBUG_LEVEL_INFO)
40338 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40339 - __FILE__,__LINE__, tty->driver->name, port->count );
40340 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40341
40342 if (!retval)
40343 port->flags |= ASYNC_NORMAL_ACTIVE;
40344 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40345 index 16ee6ce..bfcac57 100644
40346 --- a/drivers/tty/sysrq.c
40347 +++ b/drivers/tty/sysrq.c
40348 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40349 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40350 size_t count, loff_t *ppos)
40351 {
40352 - if (count) {
40353 + if (count && capable(CAP_SYS_ADMIN)) {
40354 char c;
40355
40356 if (get_user(c, buf))
40357 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40358 index 2ea176b..2877bc8 100644
40359 --- a/drivers/tty/tty_io.c
40360 +++ b/drivers/tty/tty_io.c
40361 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40362
40363 void tty_default_fops(struct file_operations *fops)
40364 {
40365 - *fops = tty_fops;
40366 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40367 }
40368
40369 /*
40370 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40371 index 0f2a2c5..471e228 100644
40372 --- a/drivers/tty/tty_ldisc.c
40373 +++ b/drivers/tty/tty_ldisc.c
40374 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40375 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40376 struct tty_ldisc_ops *ldo = ld->ops;
40377
40378 - ldo->refcount--;
40379 + atomic_dec(&ldo->refcount);
40380 module_put(ldo->owner);
40381 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40382
40383 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40384 spin_lock_irqsave(&tty_ldisc_lock, flags);
40385 tty_ldiscs[disc] = new_ldisc;
40386 new_ldisc->num = disc;
40387 - new_ldisc->refcount = 0;
40388 + atomic_set(&new_ldisc->refcount, 0);
40389 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40390
40391 return ret;
40392 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40393 return -EINVAL;
40394
40395 spin_lock_irqsave(&tty_ldisc_lock, flags);
40396 - if (tty_ldiscs[disc]->refcount)
40397 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40398 ret = -EBUSY;
40399 else
40400 tty_ldiscs[disc] = NULL;
40401 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40402 if (ldops) {
40403 ret = ERR_PTR(-EAGAIN);
40404 if (try_module_get(ldops->owner)) {
40405 - ldops->refcount++;
40406 + atomic_inc(&ldops->refcount);
40407 ret = ldops;
40408 }
40409 }
40410 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40411 unsigned long flags;
40412
40413 spin_lock_irqsave(&tty_ldisc_lock, flags);
40414 - ldops->refcount--;
40415 + atomic_dec(&ldops->refcount);
40416 module_put(ldops->owner);
40417 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40418 }
40419 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40420 index d7bdd8d..feaef30 100644
40421 --- a/drivers/tty/tty_port.c
40422 +++ b/drivers/tty/tty_port.c
40423 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40424 unsigned long flags;
40425
40426 spin_lock_irqsave(&port->lock, flags);
40427 - port->count = 0;
40428 + atomic_set(&port->count, 0);
40429 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40430 if (port->tty) {
40431 set_bit(TTY_IO_ERROR, &port->tty->flags);
40432 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40433 /* The port lock protects the port counts */
40434 spin_lock_irqsave(&port->lock, flags);
40435 if (!tty_hung_up_p(filp))
40436 - port->count--;
40437 + atomic_dec(&port->count);
40438 port->blocked_open++;
40439 spin_unlock_irqrestore(&port->lock, flags);
40440
40441 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40442 we must not mess that up further */
40443 spin_lock_irqsave(&port->lock, flags);
40444 if (!tty_hung_up_p(filp))
40445 - port->count++;
40446 + atomic_inc(&port->count);
40447 port->blocked_open--;
40448 if (retval == 0)
40449 port->flags |= ASYNC_NORMAL_ACTIVE;
40450 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40451 return 0;
40452 }
40453
40454 - if (tty->count == 1 && port->count != 1) {
40455 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40456 printk(KERN_WARNING
40457 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40458 - port->count);
40459 - port->count = 1;
40460 + atomic_read(&port->count));
40461 + atomic_set(&port->count, 1);
40462 }
40463 - if (--port->count < 0) {
40464 + if (atomic_dec_return(&port->count) < 0) {
40465 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40466 - port->count);
40467 - port->count = 0;
40468 + atomic_read(&port->count));
40469 + atomic_set(&port->count, 0);
40470 }
40471
40472 - if (port->count) {
40473 + if (atomic_read(&port->count)) {
40474 spin_unlock_irqrestore(&port->lock, flags);
40475 if (port->ops->drop)
40476 port->ops->drop(port);
40477 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40478 {
40479 spin_lock_irq(&port->lock);
40480 if (!tty_hung_up_p(filp))
40481 - ++port->count;
40482 + atomic_inc(&port->count);
40483 spin_unlock_irq(&port->lock);
40484 tty_port_tty_set(port, tty);
40485
40486 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40487 index 681765b..d3ccdf2 100644
40488 --- a/drivers/tty/vt/keyboard.c
40489 +++ b/drivers/tty/vt/keyboard.c
40490 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40491 kbd->kbdmode == VC_OFF) &&
40492 value != KVAL(K_SAK))
40493 return; /* SAK is allowed even in raw mode */
40494 +
40495 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40496 + {
40497 + void *func = fn_handler[value];
40498 + if (func == fn_show_state || func == fn_show_ptregs ||
40499 + func == fn_show_mem)
40500 + return;
40501 + }
40502 +#endif
40503 +
40504 fn_handler[value](vc);
40505 }
40506
40507 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40508 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40509 return -EFAULT;
40510
40511 - if (!capable(CAP_SYS_TTY_CONFIG))
40512 - perm = 0;
40513 -
40514 switch (cmd) {
40515 case KDGKBENT:
40516 /* Ensure another thread doesn't free it under us */
40517 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40518 spin_unlock_irqrestore(&kbd_event_lock, flags);
40519 return put_user(val, &user_kbe->kb_value);
40520 case KDSKBENT:
40521 + if (!capable(CAP_SYS_TTY_CONFIG))
40522 + perm = 0;
40523 +
40524 if (!perm)
40525 return -EPERM;
40526 if (!i && v == K_NOSUCHMAP) {
40527 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40528 int i, j, k;
40529 int ret;
40530
40531 - if (!capable(CAP_SYS_TTY_CONFIG))
40532 - perm = 0;
40533 -
40534 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40535 if (!kbs) {
40536 ret = -ENOMEM;
40537 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40538 kfree(kbs);
40539 return ((p && *p) ? -EOVERFLOW : 0);
40540 case KDSKBSENT:
40541 + if (!capable(CAP_SYS_TTY_CONFIG))
40542 + perm = 0;
40543 +
40544 if (!perm) {
40545 ret = -EPERM;
40546 goto reterr;
40547 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40548 index 5110f36..8dc0a74 100644
40549 --- a/drivers/uio/uio.c
40550 +++ b/drivers/uio/uio.c
40551 @@ -25,6 +25,7 @@
40552 #include <linux/kobject.h>
40553 #include <linux/cdev.h>
40554 #include <linux/uio_driver.h>
40555 +#include <asm/local.h>
40556
40557 #define UIO_MAX_DEVICES (1U << MINORBITS)
40558
40559 @@ -32,10 +33,10 @@ struct uio_device {
40560 struct module *owner;
40561 struct device *dev;
40562 int minor;
40563 - atomic_t event;
40564 + atomic_unchecked_t event;
40565 struct fasync_struct *async_queue;
40566 wait_queue_head_t wait;
40567 - int vma_count;
40568 + local_t vma_count;
40569 struct uio_info *info;
40570 struct kobject *map_dir;
40571 struct kobject *portio_dir;
40572 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40573 struct device_attribute *attr, char *buf)
40574 {
40575 struct uio_device *idev = dev_get_drvdata(dev);
40576 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40577 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40578 }
40579
40580 static struct device_attribute uio_class_attributes[] = {
40581 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40582 {
40583 struct uio_device *idev = info->uio_dev;
40584
40585 - atomic_inc(&idev->event);
40586 + atomic_inc_unchecked(&idev->event);
40587 wake_up_interruptible(&idev->wait);
40588 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40589 }
40590 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40591 }
40592
40593 listener->dev = idev;
40594 - listener->event_count = atomic_read(&idev->event);
40595 + listener->event_count = atomic_read_unchecked(&idev->event);
40596 filep->private_data = listener;
40597
40598 if (idev->info->open) {
40599 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40600 return -EIO;
40601
40602 poll_wait(filep, &idev->wait, wait);
40603 - if (listener->event_count != atomic_read(&idev->event))
40604 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40605 return POLLIN | POLLRDNORM;
40606 return 0;
40607 }
40608 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40609 do {
40610 set_current_state(TASK_INTERRUPTIBLE);
40611
40612 - event_count = atomic_read(&idev->event);
40613 + event_count = atomic_read_unchecked(&idev->event);
40614 if (event_count != listener->event_count) {
40615 if (copy_to_user(buf, &event_count, count))
40616 retval = -EFAULT;
40617 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40618 static void uio_vma_open(struct vm_area_struct *vma)
40619 {
40620 struct uio_device *idev = vma->vm_private_data;
40621 - idev->vma_count++;
40622 + local_inc(&idev->vma_count);
40623 }
40624
40625 static void uio_vma_close(struct vm_area_struct *vma)
40626 {
40627 struct uio_device *idev = vma->vm_private_data;
40628 - idev->vma_count--;
40629 + local_dec(&idev->vma_count);
40630 }
40631
40632 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40633 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40634 idev->owner = owner;
40635 idev->info = info;
40636 init_waitqueue_head(&idev->wait);
40637 - atomic_set(&idev->event, 0);
40638 + atomic_set_unchecked(&idev->event, 0);
40639
40640 ret = uio_get_minor(idev);
40641 if (ret)
40642 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40643 index b7eb86a..36d28af 100644
40644 --- a/drivers/usb/atm/cxacru.c
40645 +++ b/drivers/usb/atm/cxacru.c
40646 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40647 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40648 if (ret < 2)
40649 return -EINVAL;
40650 - if (index < 0 || index > 0x7f)
40651 + if (index > 0x7f)
40652 return -EINVAL;
40653 pos += tmp;
40654
40655 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40656 index 35f10bf..6a38a0b 100644
40657 --- a/drivers/usb/atm/usbatm.c
40658 +++ b/drivers/usb/atm/usbatm.c
40659 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40660 if (printk_ratelimit())
40661 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40662 __func__, vpi, vci);
40663 - atomic_inc(&vcc->stats->rx_err);
40664 + atomic_inc_unchecked(&vcc->stats->rx_err);
40665 return;
40666 }
40667
40668 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40669 if (length > ATM_MAX_AAL5_PDU) {
40670 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40671 __func__, length, vcc);
40672 - atomic_inc(&vcc->stats->rx_err);
40673 + atomic_inc_unchecked(&vcc->stats->rx_err);
40674 goto out;
40675 }
40676
40677 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40678 if (sarb->len < pdu_length) {
40679 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40680 __func__, pdu_length, sarb->len, vcc);
40681 - atomic_inc(&vcc->stats->rx_err);
40682 + atomic_inc_unchecked(&vcc->stats->rx_err);
40683 goto out;
40684 }
40685
40686 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40687 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40688 __func__, vcc);
40689 - atomic_inc(&vcc->stats->rx_err);
40690 + atomic_inc_unchecked(&vcc->stats->rx_err);
40691 goto out;
40692 }
40693
40694 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40695 if (printk_ratelimit())
40696 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40697 __func__, length);
40698 - atomic_inc(&vcc->stats->rx_drop);
40699 + atomic_inc_unchecked(&vcc->stats->rx_drop);
40700 goto out;
40701 }
40702
40703 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40704
40705 vcc->push(vcc, skb);
40706
40707 - atomic_inc(&vcc->stats->rx);
40708 + atomic_inc_unchecked(&vcc->stats->rx);
40709 out:
40710 skb_trim(sarb, 0);
40711 }
40712 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40713 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40714
40715 usbatm_pop(vcc, skb);
40716 - atomic_inc(&vcc->stats->tx);
40717 + atomic_inc_unchecked(&vcc->stats->tx);
40718
40719 skb = skb_dequeue(&instance->sndqueue);
40720 }
40721 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40722 if (!left--)
40723 return sprintf(page,
40724 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40725 - atomic_read(&atm_dev->stats.aal5.tx),
40726 - atomic_read(&atm_dev->stats.aal5.tx_err),
40727 - atomic_read(&atm_dev->stats.aal5.rx),
40728 - atomic_read(&atm_dev->stats.aal5.rx_err),
40729 - atomic_read(&atm_dev->stats.aal5.rx_drop));
40730 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40731 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40732 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40733 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40734 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40735
40736 if (!left--) {
40737 if (instance->disconnected)
40738 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40739 index f460de3..95ba1f6 100644
40740 --- a/drivers/usb/core/devices.c
40741 +++ b/drivers/usb/core/devices.c
40742 @@ -126,7 +126,7 @@ static const char format_endpt[] =
40743 * time it gets called.
40744 */
40745 static struct device_connect_event {
40746 - atomic_t count;
40747 + atomic_unchecked_t count;
40748 wait_queue_head_t wait;
40749 } device_event = {
40750 .count = ATOMIC_INIT(1),
40751 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40752
40753 void usbfs_conn_disc_event(void)
40754 {
40755 - atomic_add(2, &device_event.count);
40756 + atomic_add_unchecked(2, &device_event.count);
40757 wake_up(&device_event.wait);
40758 }
40759
40760 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
40761
40762 poll_wait(file, &device_event.wait, wait);
40763
40764 - event_count = atomic_read(&device_event.count);
40765 + event_count = atomic_read_unchecked(&device_event.count);
40766 if (file->f_version != event_count) {
40767 file->f_version = event_count;
40768 return POLLIN | POLLRDNORM;
40769 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
40770 index f034716..aed0368 100644
40771 --- a/drivers/usb/core/hcd.c
40772 +++ b/drivers/usb/core/hcd.c
40773 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40774 */
40775 usb_get_urb(urb);
40776 atomic_inc(&urb->use_count);
40777 - atomic_inc(&urb->dev->urbnum);
40778 + atomic_inc_unchecked(&urb->dev->urbnum);
40779 usbmon_urb_submit(&hcd->self, urb);
40780
40781 /* NOTE requirements on root-hub callers (usbfs and the hub
40782 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40783 urb->hcpriv = NULL;
40784 INIT_LIST_HEAD(&urb->urb_list);
40785 atomic_dec(&urb->use_count);
40786 - atomic_dec(&urb->dev->urbnum);
40787 + atomic_dec_unchecked(&urb->dev->urbnum);
40788 if (atomic_read(&urb->reject))
40789 wake_up(&usb_kill_urb_queue);
40790 usb_put_urb(urb);
40791 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
40792 index 818e4a0..0fc9589 100644
40793 --- a/drivers/usb/core/sysfs.c
40794 +++ b/drivers/usb/core/sysfs.c
40795 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
40796 struct usb_device *udev;
40797
40798 udev = to_usb_device(dev);
40799 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
40800 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
40801 }
40802 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
40803
40804 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
40805 index cd8fb44..17fbe0c 100644
40806 --- a/drivers/usb/core/usb.c
40807 +++ b/drivers/usb/core/usb.c
40808 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
40809 set_dev_node(&dev->dev, dev_to_node(bus->controller));
40810 dev->state = USB_STATE_ATTACHED;
40811 dev->lpm_disable_count = 1;
40812 - atomic_set(&dev->urbnum, 0);
40813 + atomic_set_unchecked(&dev->urbnum, 0);
40814
40815 INIT_LIST_HEAD(&dev->ep0.urb_list);
40816 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
40817 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
40818 index 4bfa78a..902bfbd 100644
40819 --- a/drivers/usb/early/ehci-dbgp.c
40820 +++ b/drivers/usb/early/ehci-dbgp.c
40821 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
40822
40823 #ifdef CONFIG_KGDB
40824 static struct kgdb_io kgdbdbgp_io_ops;
40825 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
40826 +static struct kgdb_io kgdbdbgp_io_ops_console;
40827 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
40828 #else
40829 #define dbgp_kgdb_mode (0)
40830 #endif
40831 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
40832 .write_char = kgdbdbgp_write_char,
40833 };
40834
40835 +static struct kgdb_io kgdbdbgp_io_ops_console = {
40836 + .name = "kgdbdbgp",
40837 + .read_char = kgdbdbgp_read_char,
40838 + .write_char = kgdbdbgp_write_char,
40839 + .is_console = 1
40840 +};
40841 +
40842 static int kgdbdbgp_wait_time;
40843
40844 static int __init kgdbdbgp_parse_config(char *str)
40845 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
40846 ptr++;
40847 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
40848 }
40849 - kgdb_register_io_module(&kgdbdbgp_io_ops);
40850 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
40851 + if (early_dbgp_console.index != -1)
40852 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
40853 + else
40854 + kgdb_register_io_module(&kgdbdbgp_io_ops);
40855
40856 return 0;
40857 }
40858 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
40859 index f173952..83d6ec0 100644
40860 --- a/drivers/usb/gadget/u_serial.c
40861 +++ b/drivers/usb/gadget/u_serial.c
40862 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40863 spin_lock_irq(&port->port_lock);
40864
40865 /* already open? Great. */
40866 - if (port->port.count) {
40867 + if (atomic_read(&port->port.count)) {
40868 status = 0;
40869 - port->port.count++;
40870 + atomic_inc(&port->port.count);
40871
40872 /* currently opening/closing? wait ... */
40873 } else if (port->openclose) {
40874 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40875 tty->driver_data = port;
40876 port->port.tty = tty;
40877
40878 - port->port.count = 1;
40879 + atomic_set(&port->port.count, 1);
40880 port->openclose = false;
40881
40882 /* if connected, start the I/O stream */
40883 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40884
40885 spin_lock_irq(&port->port_lock);
40886
40887 - if (port->port.count != 1) {
40888 - if (port->port.count == 0)
40889 + if (atomic_read(&port->port.count) != 1) {
40890 + if (atomic_read(&port->port.count) == 0)
40891 WARN_ON(1);
40892 else
40893 - --port->port.count;
40894 + atomic_dec(&port->port.count);
40895 goto exit;
40896 }
40897
40898 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40899 * and sleep if necessary
40900 */
40901 port->openclose = true;
40902 - port->port.count = 0;
40903 + atomic_set(&port->port.count, 0);
40904
40905 gser = port->port_usb;
40906 if (gser && gser->disconnect)
40907 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
40908 int cond;
40909
40910 spin_lock_irq(&port->port_lock);
40911 - cond = (port->port.count == 0) && !port->openclose;
40912 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
40913 spin_unlock_irq(&port->port_lock);
40914 return cond;
40915 }
40916 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
40917 /* if it's already open, start I/O ... and notify the serial
40918 * protocol about open/close status (connect/disconnect).
40919 */
40920 - if (port->port.count) {
40921 + if (atomic_read(&port->port.count)) {
40922 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
40923 gs_start_io(port);
40924 if (gser->connect)
40925 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
40926
40927 port->port_usb = NULL;
40928 gser->ioport = NULL;
40929 - if (port->port.count > 0 || port->openclose) {
40930 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
40931 wake_up_interruptible(&port->drain_wait);
40932 if (port->port.tty)
40933 tty_hangup(port->port.tty);
40934 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
40935
40936 /* finally, free any unused/unusable I/O buffers */
40937 spin_lock_irqsave(&port->port_lock, flags);
40938 - if (port->port.count == 0 && !port->openclose)
40939 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
40940 gs_buf_free(&port->port_write_buf);
40941 gs_free_requests(gser->out, &port->read_pool, NULL);
40942 gs_free_requests(gser->out, &port->read_queue, NULL);
40943 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
40944 index 5f3bcd3..bfca43f 100644
40945 --- a/drivers/usb/serial/console.c
40946 +++ b/drivers/usb/serial/console.c
40947 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
40948
40949 info->port = port;
40950
40951 - ++port->port.count;
40952 + atomic_inc(&port->port.count);
40953 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
40954 if (serial->type->set_termios) {
40955 /*
40956 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
40957 }
40958 /* Now that any required fake tty operations are completed restore
40959 * the tty port count */
40960 - --port->port.count;
40961 + atomic_dec(&port->port.count);
40962 /* The console is special in terms of closing the device so
40963 * indicate this port is now acting as a system console. */
40964 port->port.console = 1;
40965 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
40966 free_tty:
40967 kfree(tty);
40968 reset_open_count:
40969 - port->port.count = 0;
40970 + atomic_set(&port->port.count, 0);
40971 usb_autopm_put_interface(serial->interface);
40972 error_get_interface:
40973 usb_serial_put(serial);
40974 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
40975 index d6bea3e..60b250e 100644
40976 --- a/drivers/usb/wusbcore/wa-hc.h
40977 +++ b/drivers/usb/wusbcore/wa-hc.h
40978 @@ -192,7 +192,7 @@ struct wahc {
40979 struct list_head xfer_delayed_list;
40980 spinlock_t xfer_list_lock;
40981 struct work_struct xfer_work;
40982 - atomic_t xfer_id_count;
40983 + atomic_unchecked_t xfer_id_count;
40984 };
40985
40986
40987 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
40988 INIT_LIST_HEAD(&wa->xfer_delayed_list);
40989 spin_lock_init(&wa->xfer_list_lock);
40990 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
40991 - atomic_set(&wa->xfer_id_count, 1);
40992 + atomic_set_unchecked(&wa->xfer_id_count, 1);
40993 }
40994
40995 /**
40996 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
40997 index 57c01ab..8a05959 100644
40998 --- a/drivers/usb/wusbcore/wa-xfer.c
40999 +++ b/drivers/usb/wusbcore/wa-xfer.c
41000 @@ -296,7 +296,7 @@ out:
41001 */
41002 static void wa_xfer_id_init(struct wa_xfer *xfer)
41003 {
41004 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41005 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41006 }
41007
41008 /*
41009 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41010 index dedaf81..b0f11ab 100644
41011 --- a/drivers/vhost/vhost.c
41012 +++ b/drivers/vhost/vhost.c
41013 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41014 return 0;
41015 }
41016
41017 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41018 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41019 {
41020 struct file *eventfp, *filep = NULL;
41021 bool pollstart = false, pollstop = false;
41022 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41023 index 0fefa84..7a9d581 100644
41024 --- a/drivers/video/aty/aty128fb.c
41025 +++ b/drivers/video/aty/aty128fb.c
41026 @@ -149,7 +149,7 @@ enum {
41027 };
41028
41029 /* Must match above enum */
41030 -static char * const r128_family[] __devinitconst = {
41031 +static const char * const r128_family[] __devinitconst = {
41032 "AGP",
41033 "PCI",
41034 "PRO AGP",
41035 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41036 index 5c3960d..15cf8fc 100644
41037 --- a/drivers/video/fbcmap.c
41038 +++ b/drivers/video/fbcmap.c
41039 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41040 rc = -ENODEV;
41041 goto out;
41042 }
41043 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41044 - !info->fbops->fb_setcmap)) {
41045 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41046 rc = -EINVAL;
41047 goto out1;
41048 }
41049 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41050 index 3ff0105..7589d98 100644
41051 --- a/drivers/video/fbmem.c
41052 +++ b/drivers/video/fbmem.c
41053 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41054 image->dx += image->width + 8;
41055 }
41056 } else if (rotate == FB_ROTATE_UD) {
41057 - for (x = 0; x < num && image->dx >= 0; x++) {
41058 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41059 info->fbops->fb_imageblit(info, image);
41060 image->dx -= image->width + 8;
41061 }
41062 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41063 image->dy += image->height + 8;
41064 }
41065 } else if (rotate == FB_ROTATE_CCW) {
41066 - for (x = 0; x < num && image->dy >= 0; x++) {
41067 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41068 info->fbops->fb_imageblit(info, image);
41069 image->dy -= image->height + 8;
41070 }
41071 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41072 return -EFAULT;
41073 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41074 return -EINVAL;
41075 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41076 + if (con2fb.framebuffer >= FB_MAX)
41077 return -EINVAL;
41078 if (!registered_fb[con2fb.framebuffer])
41079 request_module("fb%d", con2fb.framebuffer);
41080 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41081 index 7672d2e..b56437f 100644
41082 --- a/drivers/video/i810/i810_accel.c
41083 +++ b/drivers/video/i810/i810_accel.c
41084 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41085 }
41086 }
41087 printk("ringbuffer lockup!!!\n");
41088 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41089 i810_report_error(mmio);
41090 par->dev_flags |= LOCKUP;
41091 info->pixmap.scan_align = 1;
41092 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41093 index 3c14e43..eafa544 100644
41094 --- a/drivers/video/logo/logo_linux_clut224.ppm
41095 +++ b/drivers/video/logo/logo_linux_clut224.ppm
41096 @@ -1,1604 +1,1123 @@
41097 P3
41098 -# Standard 224-color Linux logo
41099 80 80
41100 255
41101 - 0 0 0 0 0 0 0 0 0 0 0 0
41102 - 0 0 0 0 0 0 0 0 0 0 0 0
41103 - 0 0 0 0 0 0 0 0 0 0 0 0
41104 - 0 0 0 0 0 0 0 0 0 0 0 0
41105 - 0 0 0 0 0 0 0 0 0 0 0 0
41106 - 0 0 0 0 0 0 0 0 0 0 0 0
41107 - 0 0 0 0 0 0 0 0 0 0 0 0
41108 - 0 0 0 0 0 0 0 0 0 0 0 0
41109 - 0 0 0 0 0 0 0 0 0 0 0 0
41110 - 6 6 6 6 6 6 10 10 10 10 10 10
41111 - 10 10 10 6 6 6 6 6 6 6 6 6
41112 - 0 0 0 0 0 0 0 0 0 0 0 0
41113 - 0 0 0 0 0 0 0 0 0 0 0 0
41114 - 0 0 0 0 0 0 0 0 0 0 0 0
41115 - 0 0 0 0 0 0 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 0 0 0 0 0 0 0 0 0
41119 - 0 0 0 0 0 0 0 0 0 0 0 0
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 0 0 0
41123 - 0 0 0 0 0 0 0 0 0 0 0 0
41124 - 0 0 0 0 0 0 0 0 0 0 0 0
41125 - 0 0 0 0 0 0 0 0 0 0 0 0
41126 - 0 0 0 0 0 0 0 0 0 0 0 0
41127 - 0 0 0 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 0 0 0
41129 - 0 0 0 6 6 6 10 10 10 14 14 14
41130 - 22 22 22 26 26 26 30 30 30 34 34 34
41131 - 30 30 30 30 30 30 26 26 26 18 18 18
41132 - 14 14 14 10 10 10 6 6 6 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 0 0 0
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 0 0 0
41140 - 0 0 0 0 0 0 0 0 0 0 0 0
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 1 0 0 1 0 0 0
41143 - 0 0 0 0 0 0 0 0 0 0 0 0
41144 - 0 0 0 0 0 0 0 0 0 0 0 0
41145 - 0 0 0 0 0 0 0 0 0 0 0 0
41146 - 0 0 0 0 0 0 0 0 0 0 0 0
41147 - 0 0 0 0 0 0 0 0 0 0 0 0
41148 - 0 0 0 0 0 0 0 0 0 0 0 0
41149 - 6 6 6 14 14 14 26 26 26 42 42 42
41150 - 54 54 54 66 66 66 78 78 78 78 78 78
41151 - 78 78 78 74 74 74 66 66 66 54 54 54
41152 - 42 42 42 26 26 26 18 18 18 10 10 10
41153 - 6 6 6 0 0 0 0 0 0 0 0 0
41154 - 0 0 0 0 0 0 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 0 0 0
41157 - 0 0 0 0 0 0 0 0 0 0 0 0
41158 - 0 0 0 0 0 0 0 0 0 0 0 0
41159 - 0 0 0 0 0 0 0 0 0 0 0 0
41160 - 0 0 0 0 0 0 0 0 0 0 0 0
41161 - 0 0 0 0 0 0 0 0 0 0 0 0
41162 - 0 0 1 0 0 0 0 0 0 0 0 0
41163 - 0 0 0 0 0 0 0 0 0 0 0 0
41164 - 0 0 0 0 0 0 0 0 0 0 0 0
41165 - 0 0 0 0 0 0 0 0 0 0 0 0
41166 - 0 0 0 0 0 0 0 0 0 0 0 0
41167 - 0 0 0 0 0 0 0 0 0 0 0 0
41168 - 0 0 0 0 0 0 0 0 0 10 10 10
41169 - 22 22 22 42 42 42 66 66 66 86 86 86
41170 - 66 66 66 38 38 38 38 38 38 22 22 22
41171 - 26 26 26 34 34 34 54 54 54 66 66 66
41172 - 86 86 86 70 70 70 46 46 46 26 26 26
41173 - 14 14 14 6 6 6 0 0 0 0 0 0
41174 - 0 0 0 0 0 0 0 0 0 0 0 0
41175 - 0 0 0 0 0 0 0 0 0 0 0 0
41176 - 0 0 0 0 0 0 0 0 0 0 0 0
41177 - 0 0 0 0 0 0 0 0 0 0 0 0
41178 - 0 0 0 0 0 0 0 0 0 0 0 0
41179 - 0 0 0 0 0 0 0 0 0 0 0 0
41180 - 0 0 0 0 0 0 0 0 0 0 0 0
41181 - 0 0 0 0 0 0 0 0 0 0 0 0
41182 - 0 0 1 0 0 1 0 0 1 0 0 0
41183 - 0 0 0 0 0 0 0 0 0 0 0 0
41184 - 0 0 0 0 0 0 0 0 0 0 0 0
41185 - 0 0 0 0 0 0 0 0 0 0 0 0
41186 - 0 0 0 0 0 0 0 0 0 0 0 0
41187 - 0 0 0 0 0 0 0 0 0 0 0 0
41188 - 0 0 0 0 0 0 10 10 10 26 26 26
41189 - 50 50 50 82 82 82 58 58 58 6 6 6
41190 - 2 2 6 2 2 6 2 2 6 2 2 6
41191 - 2 2 6 2 2 6 2 2 6 2 2 6
41192 - 6 6 6 54 54 54 86 86 86 66 66 66
41193 - 38 38 38 18 18 18 6 6 6 0 0 0
41194 - 0 0 0 0 0 0 0 0 0 0 0 0
41195 - 0 0 0 0 0 0 0 0 0 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 0 0 0
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 0 0 0 0 0 0
41201 - 0 0 0 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 0 0 0 0 0 0 0 0 0
41203 - 0 0 0 0 0 0 0 0 0 0 0 0
41204 - 0 0 0 0 0 0 0 0 0 0 0 0
41205 - 0 0 0 0 0 0 0 0 0 0 0 0
41206 - 0 0 0 0 0 0 0 0 0 0 0 0
41207 - 0 0 0 0 0 0 0 0 0 0 0 0
41208 - 0 0 0 6 6 6 22 22 22 50 50 50
41209 - 78 78 78 34 34 34 2 2 6 2 2 6
41210 - 2 2 6 2 2 6 2 2 6 2 2 6
41211 - 2 2 6 2 2 6 2 2 6 2 2 6
41212 - 2 2 6 2 2 6 6 6 6 70 70 70
41213 - 78 78 78 46 46 46 22 22 22 6 6 6
41214 - 0 0 0 0 0 0 0 0 0 0 0 0
41215 - 0 0 0 0 0 0 0 0 0 0 0 0
41216 - 0 0 0 0 0 0 0 0 0 0 0 0
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
41221 - 0 0 0 0 0 0 0 0 0 0 0 0
41222 - 0 0 1 0 0 1 0 0 1 0 0 0
41223 - 0 0 0 0 0 0 0 0 0 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 0 0 0
41226 - 0 0 0 0 0 0 0 0 0 0 0 0
41227 - 0 0 0 0 0 0 0 0 0 0 0 0
41228 - 6 6 6 18 18 18 42 42 42 82 82 82
41229 - 26 26 26 2 2 6 2 2 6 2 2 6
41230 - 2 2 6 2 2 6 2 2 6 2 2 6
41231 - 2 2 6 2 2 6 2 2 6 14 14 14
41232 - 46 46 46 34 34 34 6 6 6 2 2 6
41233 - 42 42 42 78 78 78 42 42 42 18 18 18
41234 - 6 6 6 0 0 0 0 0 0 0 0 0
41235 - 0 0 0 0 0 0 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 1 0 0 0 0 0 1 0 0 0
41243 - 0 0 0 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 0 0 0 0 0 0 0 0 0
41248 - 10 10 10 30 30 30 66 66 66 58 58 58
41249 - 2 2 6 2 2 6 2 2 6 2 2 6
41250 - 2 2 6 2 2 6 2 2 6 2 2 6
41251 - 2 2 6 2 2 6 2 2 6 26 26 26
41252 - 86 86 86 101 101 101 46 46 46 10 10 10
41253 - 2 2 6 58 58 58 70 70 70 34 34 34
41254 - 10 10 10 0 0 0 0 0 0 0 0 0
41255 - 0 0 0 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 0 0 0
41261 - 0 0 0 0 0 0 0 0 0 0 0 0
41262 - 0 0 1 0 0 1 0 0 1 0 0 0
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 0 0 0
41267 - 0 0 0 0 0 0 0 0 0 0 0 0
41268 - 14 14 14 42 42 42 86 86 86 10 10 10
41269 - 2 2 6 2 2 6 2 2 6 2 2 6
41270 - 2 2 6 2 2 6 2 2 6 2 2 6
41271 - 2 2 6 2 2 6 2 2 6 30 30 30
41272 - 94 94 94 94 94 94 58 58 58 26 26 26
41273 - 2 2 6 6 6 6 78 78 78 54 54 54
41274 - 22 22 22 6 6 6 0 0 0 0 0 0
41275 - 0 0 0 0 0 0 0 0 0 0 0 0
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 0 0 0
41280 - 0 0 0 0 0 0 0 0 0 0 0 0
41281 - 0 0 0 0 0 0 0 0 0 0 0 0
41282 - 0 0 0 0 0 0 0 0 0 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 0 0 0
41284 - 0 0 0 0 0 0 0 0 0 0 0 0
41285 - 0 0 0 0 0 0 0 0 0 0 0 0
41286 - 0 0 0 0 0 0 0 0 0 0 0 0
41287 - 0 0 0 0 0 0 0 0 0 6 6 6
41288 - 22 22 22 62 62 62 62 62 62 2 2 6
41289 - 2 2 6 2 2 6 2 2 6 2 2 6
41290 - 2 2 6 2 2 6 2 2 6 2 2 6
41291 - 2 2 6 2 2 6 2 2 6 26 26 26
41292 - 54 54 54 38 38 38 18 18 18 10 10 10
41293 - 2 2 6 2 2 6 34 34 34 82 82 82
41294 - 38 38 38 14 14 14 0 0 0 0 0 0
41295 - 0 0 0 0 0 0 0 0 0 0 0 0
41296 - 0 0 0 0 0 0 0 0 0 0 0 0
41297 - 0 0 0 0 0 0 0 0 0 0 0 0
41298 - 0 0 0 0 0 0 0 0 0 0 0 0
41299 - 0 0 0 0 0 0 0 0 0 0 0 0
41300 - 0 0 0 0 0 0 0 0 0 0 0 0
41301 - 0 0 0 0 0 0 0 0 0 0 0 0
41302 - 0 0 0 0 0 1 0 0 1 0 0 0
41303 - 0 0 0 0 0 0 0 0 0 0 0 0
41304 - 0 0 0 0 0 0 0 0 0 0 0 0
41305 - 0 0 0 0 0 0 0 0 0 0 0 0
41306 - 0 0 0 0 0 0 0 0 0 0 0 0
41307 - 0 0 0 0 0 0 0 0 0 6 6 6
41308 - 30 30 30 78 78 78 30 30 30 2 2 6
41309 - 2 2 6 2 2 6 2 2 6 2 2 6
41310 - 2 2 6 2 2 6 2 2 6 2 2 6
41311 - 2 2 6 2 2 6 2 2 6 10 10 10
41312 - 10 10 10 2 2 6 2 2 6 2 2 6
41313 - 2 2 6 2 2 6 2 2 6 78 78 78
41314 - 50 50 50 18 18 18 6 6 6 0 0 0
41315 - 0 0 0 0 0 0 0 0 0 0 0 0
41316 - 0 0 0 0 0 0 0 0 0 0 0 0
41317 - 0 0 0 0 0 0 0 0 0 0 0 0
41318 - 0 0 0 0 0 0 0 0 0 0 0 0
41319 - 0 0 0 0 0 0 0 0 0 0 0 0
41320 - 0 0 0 0 0 0 0 0 0 0 0 0
41321 - 0 0 0 0 0 0 0 0 0 0 0 0
41322 - 0 0 1 0 0 0 0 0 0 0 0 0
41323 - 0 0 0 0 0 0 0 0 0 0 0 0
41324 - 0 0 0 0 0 0 0 0 0 0 0 0
41325 - 0 0 0 0 0 0 0 0 0 0 0 0
41326 - 0 0 0 0 0 0 0 0 0 0 0 0
41327 - 0 0 0 0 0 0 0 0 0 10 10 10
41328 - 38 38 38 86 86 86 14 14 14 2 2 6
41329 - 2 2 6 2 2 6 2 2 6 2 2 6
41330 - 2 2 6 2 2 6 2 2 6 2 2 6
41331 - 2 2 6 2 2 6 2 2 6 2 2 6
41332 - 2 2 6 2 2 6 2 2 6 2 2 6
41333 - 2 2 6 2 2 6 2 2 6 54 54 54
41334 - 66 66 66 26 26 26 6 6 6 0 0 0
41335 - 0 0 0 0 0 0 0 0 0 0 0 0
41336 - 0 0 0 0 0 0 0 0 0 0 0 0
41337 - 0 0 0 0 0 0 0 0 0 0 0 0
41338 - 0 0 0 0 0 0 0 0 0 0 0 0
41339 - 0 0 0 0 0 0 0 0 0 0 0 0
41340 - 0 0 0 0 0 0 0 0 0 0 0 0
41341 - 0 0 0 0 0 0 0 0 0 0 0 0
41342 - 0 0 0 0 0 1 0 0 1 0 0 0
41343 - 0 0 0 0 0 0 0 0 0 0 0 0
41344 - 0 0 0 0 0 0 0 0 0 0 0 0
41345 - 0 0 0 0 0 0 0 0 0 0 0 0
41346 - 0 0 0 0 0 0 0 0 0 0 0 0
41347 - 0 0 0 0 0 0 0 0 0 14 14 14
41348 - 42 42 42 82 82 82 2 2 6 2 2 6
41349 - 2 2 6 6 6 6 10 10 10 2 2 6
41350 - 2 2 6 2 2 6 2 2 6 2 2 6
41351 - 2 2 6 2 2 6 2 2 6 6 6 6
41352 - 14 14 14 10 10 10 2 2 6 2 2 6
41353 - 2 2 6 2 2 6 2 2 6 18 18 18
41354 - 82 82 82 34 34 34 10 10 10 0 0 0
41355 - 0 0 0 0 0 0 0 0 0 0 0 0
41356 - 0 0 0 0 0 0 0 0 0 0 0 0
41357 - 0 0 0 0 0 0 0 0 0 0 0 0
41358 - 0 0 0 0 0 0 0 0 0 0 0 0
41359 - 0 0 0 0 0 0 0 0 0 0 0 0
41360 - 0 0 0 0 0 0 0 0 0 0 0 0
41361 - 0 0 0 0 0 0 0 0 0 0 0 0
41362 - 0 0 1 0 0 0 0 0 0 0 0 0
41363 - 0 0 0 0 0 0 0 0 0 0 0 0
41364 - 0 0 0 0 0 0 0 0 0 0 0 0
41365 - 0 0 0 0 0 0 0 0 0 0 0 0
41366 - 0 0 0 0 0 0 0 0 0 0 0 0
41367 - 0 0 0 0 0 0 0 0 0 14 14 14
41368 - 46 46 46 86 86 86 2 2 6 2 2 6
41369 - 6 6 6 6 6 6 22 22 22 34 34 34
41370 - 6 6 6 2 2 6 2 2 6 2 2 6
41371 - 2 2 6 2 2 6 18 18 18 34 34 34
41372 - 10 10 10 50 50 50 22 22 22 2 2 6
41373 - 2 2 6 2 2 6 2 2 6 10 10 10
41374 - 86 86 86 42 42 42 14 14 14 0 0 0
41375 - 0 0 0 0 0 0 0 0 0 0 0 0
41376 - 0 0 0 0 0 0 0 0 0 0 0 0
41377 - 0 0 0 0 0 0 0 0 0 0 0 0
41378 - 0 0 0 0 0 0 0 0 0 0 0 0
41379 - 0 0 0 0 0 0 0 0 0 0 0 0
41380 - 0 0 0 0 0 0 0 0 0 0 0 0
41381 - 0 0 0 0 0 0 0 0 0 0 0 0
41382 - 0 0 1 0 0 1 0 0 1 0 0 0
41383 - 0 0 0 0 0 0 0 0 0 0 0 0
41384 - 0 0 0 0 0 0 0 0 0 0 0 0
41385 - 0 0 0 0 0 0 0 0 0 0 0 0
41386 - 0 0 0 0 0 0 0 0 0 0 0 0
41387 - 0 0 0 0 0 0 0 0 0 14 14 14
41388 - 46 46 46 86 86 86 2 2 6 2 2 6
41389 - 38 38 38 116 116 116 94 94 94 22 22 22
41390 - 22 22 22 2 2 6 2 2 6 2 2 6
41391 - 14 14 14 86 86 86 138 138 138 162 162 162
41392 -154 154 154 38 38 38 26 26 26 6 6 6
41393 - 2 2 6 2 2 6 2 2 6 2 2 6
41394 - 86 86 86 46 46 46 14 14 14 0 0 0
41395 - 0 0 0 0 0 0 0 0 0 0 0 0
41396 - 0 0 0 0 0 0 0 0 0 0 0 0
41397 - 0 0 0 0 0 0 0 0 0 0 0 0
41398 - 0 0 0 0 0 0 0 0 0 0 0 0
41399 - 0 0 0 0 0 0 0 0 0 0 0 0
41400 - 0 0 0 0 0 0 0 0 0 0 0 0
41401 - 0 0 0 0 0 0 0 0 0 0 0 0
41402 - 0 0 0 0 0 0 0 0 0 0 0 0
41403 - 0 0 0 0 0 0 0 0 0 0 0 0
41404 - 0 0 0 0 0 0 0 0 0 0 0 0
41405 - 0 0 0 0 0 0 0 0 0 0 0 0
41406 - 0 0 0 0 0 0 0 0 0 0 0 0
41407 - 0 0 0 0 0 0 0 0 0 14 14 14
41408 - 46 46 46 86 86 86 2 2 6 14 14 14
41409 -134 134 134 198 198 198 195 195 195 116 116 116
41410 - 10 10 10 2 2 6 2 2 6 6 6 6
41411 -101 98 89 187 187 187 210 210 210 218 218 218
41412 -214 214 214 134 134 134 14 14 14 6 6 6
41413 - 2 2 6 2 2 6 2 2 6 2 2 6
41414 - 86 86 86 50 50 50 18 18 18 6 6 6
41415 - 0 0 0 0 0 0 0 0 0 0 0 0
41416 - 0 0 0 0 0 0 0 0 0 0 0 0
41417 - 0 0 0 0 0 0 0 0 0 0 0 0
41418 - 0 0 0 0 0 0 0 0 0 0 0 0
41419 - 0 0 0 0 0 0 0 0 0 0 0 0
41420 - 0 0 0 0 0 0 0 0 0 0 0 0
41421 - 0 0 0 0 0 0 0 0 1 0 0 0
41422 - 0 0 1 0 0 1 0 0 1 0 0 0
41423 - 0 0 0 0 0 0 0 0 0 0 0 0
41424 - 0 0 0 0 0 0 0 0 0 0 0 0
41425 - 0 0 0 0 0 0 0 0 0 0 0 0
41426 - 0 0 0 0 0 0 0 0 0 0 0 0
41427 - 0 0 0 0 0 0 0 0 0 14 14 14
41428 - 46 46 46 86 86 86 2 2 6 54 54 54
41429 -218 218 218 195 195 195 226 226 226 246 246 246
41430 - 58 58 58 2 2 6 2 2 6 30 30 30
41431 -210 210 210 253 253 253 174 174 174 123 123 123
41432 -221 221 221 234 234 234 74 74 74 2 2 6
41433 - 2 2 6 2 2 6 2 2 6 2 2 6
41434 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41445 - 0 0 0 0 0 0 0 0 0 0 0 0
41446 - 0 0 0 0 0 0 0 0 0 0 0 0
41447 - 0 0 0 0 0 0 0 0 0 14 14 14
41448 - 46 46 46 82 82 82 2 2 6 106 106 106
41449 -170 170 170 26 26 26 86 86 86 226 226 226
41450 -123 123 123 10 10 10 14 14 14 46 46 46
41451 -231 231 231 190 190 190 6 6 6 70 70 70
41452 - 90 90 90 238 238 238 158 158 158 2 2 6
41453 - 2 2 6 2 2 6 2 2 6 2 2 6
41454 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
41462 - 0 0 1 0 0 1 0 0 1 0 0 0
41463 - 0 0 0 0 0 0 0 0 0 0 0 0
41464 - 0 0 0 0 0 0 0 0 0 0 0 0
41465 - 0 0 0 0 0 0 0 0 0 0 0 0
41466 - 0 0 0 0 0 0 0 0 0 0 0 0
41467 - 0 0 0 0 0 0 0 0 0 14 14 14
41468 - 42 42 42 86 86 86 6 6 6 116 116 116
41469 -106 106 106 6 6 6 70 70 70 149 149 149
41470 -128 128 128 18 18 18 38 38 38 54 54 54
41471 -221 221 221 106 106 106 2 2 6 14 14 14
41472 - 46 46 46 190 190 190 198 198 198 2 2 6
41473 - 2 2 6 2 2 6 2 2 6 2 2 6
41474 - 74 74 74 62 62 62 22 22 22 6 6 6
41475 - 0 0 0 0 0 0 0 0 0 0 0 0
41476 - 0 0 0 0 0 0 0 0 0 0 0 0
41477 - 0 0 0 0 0 0 0 0 0 0 0 0
41478 - 0 0 0 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 0 0 0 0 0 0 0 0 0
41481 - 0 0 0 0 0 0 0 0 1 0 0 0
41482 - 0 0 1 0 0 0 0 0 1 0 0 0
41483 - 0 0 0 0 0 0 0 0 0 0 0 0
41484 - 0 0 0 0 0 0 0 0 0 0 0 0
41485 - 0 0 0 0 0 0 0 0 0 0 0 0
41486 - 0 0 0 0 0 0 0 0 0 0 0 0
41487 - 0 0 0 0 0 0 0 0 0 14 14 14
41488 - 42 42 42 94 94 94 14 14 14 101 101 101
41489 -128 128 128 2 2 6 18 18 18 116 116 116
41490 -118 98 46 121 92 8 121 92 8 98 78 10
41491 -162 162 162 106 106 106 2 2 6 2 2 6
41492 - 2 2 6 195 195 195 195 195 195 6 6 6
41493 - 2 2 6 2 2 6 2 2 6 2 2 6
41494 - 74 74 74 62 62 62 22 22 22 6 6 6
41495 - 0 0 0 0 0 0 0 0 0 0 0 0
41496 - 0 0 0 0 0 0 0 0 0 0 0 0
41497 - 0 0 0 0 0 0 0 0 0 0 0 0
41498 - 0 0 0 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 0 0 0 0 0 0
41501 - 0 0 0 0 0 0 0 0 1 0 0 1
41502 - 0 0 1 0 0 0 0 0 1 0 0 0
41503 - 0 0 0 0 0 0 0 0 0 0 0 0
41504 - 0 0 0 0 0 0 0 0 0 0 0 0
41505 - 0 0 0 0 0 0 0 0 0 0 0 0
41506 - 0 0 0 0 0 0 0 0 0 0 0 0
41507 - 0 0 0 0 0 0 0 0 0 10 10 10
41508 - 38 38 38 90 90 90 14 14 14 58 58 58
41509 -210 210 210 26 26 26 54 38 6 154 114 10
41510 -226 170 11 236 186 11 225 175 15 184 144 12
41511 -215 174 15 175 146 61 37 26 9 2 2 6
41512 - 70 70 70 246 246 246 138 138 138 2 2 6
41513 - 2 2 6 2 2 6 2 2 6 2 2 6
41514 - 70 70 70 66 66 66 26 26 26 6 6 6
41515 - 0 0 0 0 0 0 0 0 0 0 0 0
41516 - 0 0 0 0 0 0 0 0 0 0 0 0
41517 - 0 0 0 0 0 0 0 0 0 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 0 0 0 0 0 0 0 0 0
41521 - 0 0 0 0 0 0 0 0 0 0 0 0
41522 - 0 0 0 0 0 0 0 0 0 0 0 0
41523 - 0 0 0 0 0 0 0 0 0 0 0 0
41524 - 0 0 0 0 0 0 0 0 0 0 0 0
41525 - 0 0 0 0 0 0 0 0 0 0 0 0
41526 - 0 0 0 0 0 0 0 0 0 0 0 0
41527 - 0 0 0 0 0 0 0 0 0 10 10 10
41528 - 38 38 38 86 86 86 14 14 14 10 10 10
41529 -195 195 195 188 164 115 192 133 9 225 175 15
41530 -239 182 13 234 190 10 232 195 16 232 200 30
41531 -245 207 45 241 208 19 232 195 16 184 144 12
41532 -218 194 134 211 206 186 42 42 42 2 2 6
41533 - 2 2 6 2 2 6 2 2 6 2 2 6
41534 - 50 50 50 74 74 74 30 30 30 6 6 6
41535 - 0 0 0 0 0 0 0 0 0 0 0 0
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 0 0 0 0 0 0 0 0 0 0 0 0
41541 - 0 0 0 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 0 0 0 0 0 0 0 0 0
41543 - 0 0 0 0 0 0 0 0 0 0 0 0
41544 - 0 0 0 0 0 0 0 0 0 0 0 0
41545 - 0 0 0 0 0 0 0 0 0 0 0 0
41546 - 0 0 0 0 0 0 0 0 0 0 0 0
41547 - 0 0 0 0 0 0 0 0 0 10 10 10
41548 - 34 34 34 86 86 86 14 14 14 2 2 6
41549 -121 87 25 192 133 9 219 162 10 239 182 13
41550 -236 186 11 232 195 16 241 208 19 244 214 54
41551 -246 218 60 246 218 38 246 215 20 241 208 19
41552 -241 208 19 226 184 13 121 87 25 2 2 6
41553 - 2 2 6 2 2 6 2 2 6 2 2 6
41554 - 50 50 50 82 82 82 34 34 34 10 10 10
41555 - 0 0 0 0 0 0 0 0 0 0 0 0
41556 - 0 0 0 0 0 0 0 0 0 0 0 0
41557 - 0 0 0 0 0 0 0 0 0 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 0 0 0 0 0 0 0 0 0 0 0 0
41561 - 0 0 0 0 0 0 0 0 0 0 0 0
41562 - 0 0 0 0 0 0 0 0 0 0 0 0
41563 - 0 0 0 0 0 0 0 0 0 0 0 0
41564 - 0 0 0 0 0 0 0 0 0 0 0 0
41565 - 0 0 0 0 0 0 0 0 0 0 0 0
41566 - 0 0 0 0 0 0 0 0 0 0 0 0
41567 - 0 0 0 0 0 0 0 0 0 10 10 10
41568 - 34 34 34 82 82 82 30 30 30 61 42 6
41569 -180 123 7 206 145 10 230 174 11 239 182 13
41570 -234 190 10 238 202 15 241 208 19 246 218 74
41571 -246 218 38 246 215 20 246 215 20 246 215 20
41572 -226 184 13 215 174 15 184 144 12 6 6 6
41573 - 2 2 6 2 2 6 2 2 6 2 2 6
41574 - 26 26 26 94 94 94 42 42 42 14 14 14
41575 - 0 0 0 0 0 0 0 0 0 0 0 0
41576 - 0 0 0 0 0 0 0 0 0 0 0 0
41577 - 0 0 0 0 0 0 0 0 0 0 0 0
41578 - 0 0 0 0 0 0 0 0 0 0 0 0
41579 - 0 0 0 0 0 0 0 0 0 0 0 0
41580 - 0 0 0 0 0 0 0 0 0 0 0 0
41581 - 0 0 0 0 0 0 0 0 0 0 0 0
41582 - 0 0 0 0 0 0 0 0 0 0 0 0
41583 - 0 0 0 0 0 0 0 0 0 0 0 0
41584 - 0 0 0 0 0 0 0 0 0 0 0 0
41585 - 0 0 0 0 0 0 0 0 0 0 0 0
41586 - 0 0 0 0 0 0 0 0 0 0 0 0
41587 - 0 0 0 0 0 0 0 0 0 10 10 10
41588 - 30 30 30 78 78 78 50 50 50 104 69 6
41589 -192 133 9 216 158 10 236 178 12 236 186 11
41590 -232 195 16 241 208 19 244 214 54 245 215 43
41591 -246 215 20 246 215 20 241 208 19 198 155 10
41592 -200 144 11 216 158 10 156 118 10 2 2 6
41593 - 2 2 6 2 2 6 2 2 6 2 2 6
41594 - 6 6 6 90 90 90 54 54 54 18 18 18
41595 - 6 6 6 0 0 0 0 0 0 0 0 0
41596 - 0 0 0 0 0 0 0 0 0 0 0 0
41597 - 0 0 0 0 0 0 0 0 0 0 0 0
41598 - 0 0 0 0 0 0 0 0 0 0 0 0
41599 - 0 0 0 0 0 0 0 0 0 0 0 0
41600 - 0 0 0 0 0 0 0 0 0 0 0 0
41601 - 0 0 0 0 0 0 0 0 0 0 0 0
41602 - 0 0 0 0 0 0 0 0 0 0 0 0
41603 - 0 0 0 0 0 0 0 0 0 0 0 0
41604 - 0 0 0 0 0 0 0 0 0 0 0 0
41605 - 0 0 0 0 0 0 0 0 0 0 0 0
41606 - 0 0 0 0 0 0 0 0 0 0 0 0
41607 - 0 0 0 0 0 0 0 0 0 10 10 10
41608 - 30 30 30 78 78 78 46 46 46 22 22 22
41609 -137 92 6 210 162 10 239 182 13 238 190 10
41610 -238 202 15 241 208 19 246 215 20 246 215 20
41611 -241 208 19 203 166 17 185 133 11 210 150 10
41612 -216 158 10 210 150 10 102 78 10 2 2 6
41613 - 6 6 6 54 54 54 14 14 14 2 2 6
41614 - 2 2 6 62 62 62 74 74 74 30 30 30
41615 - 10 10 10 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 0 0 0
41622 - 0 0 0 0 0 0 0 0 0 0 0 0
41623 - 0 0 0 0 0 0 0 0 0 0 0 0
41624 - 0 0 0 0 0 0 0 0 0 0 0 0
41625 - 0 0 0 0 0 0 0 0 0 0 0 0
41626 - 0 0 0 0 0 0 0 0 0 0 0 0
41627 - 0 0 0 0 0 0 0 0 0 10 10 10
41628 - 34 34 34 78 78 78 50 50 50 6 6 6
41629 - 94 70 30 139 102 15 190 146 13 226 184 13
41630 -232 200 30 232 195 16 215 174 15 190 146 13
41631 -168 122 10 192 133 9 210 150 10 213 154 11
41632 -202 150 34 182 157 106 101 98 89 2 2 6
41633 - 2 2 6 78 78 78 116 116 116 58 58 58
41634 - 2 2 6 22 22 22 90 90 90 46 46 46
41635 - 18 18 18 6 6 6 0 0 0 0 0 0
41636 - 0 0 0 0 0 0 0 0 0 0 0 0
41637 - 0 0 0 0 0 0 0 0 0 0 0 0
41638 - 0 0 0 0 0 0 0 0 0 0 0 0
41639 - 0 0 0 0 0 0 0 0 0 0 0 0
41640 - 0 0 0 0 0 0 0 0 0 0 0 0
41641 - 0 0 0 0 0 0 0 0 0 0 0 0
41642 - 0 0 0 0 0 0 0 0 0 0 0 0
41643 - 0 0 0 0 0 0 0 0 0 0 0 0
41644 - 0 0 0 0 0 0 0 0 0 0 0 0
41645 - 0 0 0 0 0 0 0 0 0 0 0 0
41646 - 0 0 0 0 0 0 0 0 0 0 0 0
41647 - 0 0 0 0 0 0 0 0 0 10 10 10
41648 - 38 38 38 86 86 86 50 50 50 6 6 6
41649 -128 128 128 174 154 114 156 107 11 168 122 10
41650 -198 155 10 184 144 12 197 138 11 200 144 11
41651 -206 145 10 206 145 10 197 138 11 188 164 115
41652 -195 195 195 198 198 198 174 174 174 14 14 14
41653 - 2 2 6 22 22 22 116 116 116 116 116 116
41654 - 22 22 22 2 2 6 74 74 74 70 70 70
41655 - 30 30 30 10 10 10 0 0 0 0 0 0
41656 - 0 0 0 0 0 0 0 0 0 0 0 0
41657 - 0 0 0 0 0 0 0 0 0 0 0 0
41658 - 0 0 0 0 0 0 0 0 0 0 0 0
41659 - 0 0 0 0 0 0 0 0 0 0 0 0
41660 - 0 0 0 0 0 0 0 0 0 0 0 0
41661 - 0 0 0 0 0 0 0 0 0 0 0 0
41662 - 0 0 0 0 0 0 0 0 0 0 0 0
41663 - 0 0 0 0 0 0 0 0 0 0 0 0
41664 - 0 0 0 0 0 0 0 0 0 0 0 0
41665 - 0 0 0 0 0 0 0 0 0 0 0 0
41666 - 0 0 0 0 0 0 0 0 0 0 0 0
41667 - 0 0 0 0 0 0 6 6 6 18 18 18
41668 - 50 50 50 101 101 101 26 26 26 10 10 10
41669 -138 138 138 190 190 190 174 154 114 156 107 11
41670 -197 138 11 200 144 11 197 138 11 192 133 9
41671 -180 123 7 190 142 34 190 178 144 187 187 187
41672 -202 202 202 221 221 221 214 214 214 66 66 66
41673 - 2 2 6 2 2 6 50 50 50 62 62 62
41674 - 6 6 6 2 2 6 10 10 10 90 90 90
41675 - 50 50 50 18 18 18 6 6 6 0 0 0
41676 - 0 0 0 0 0 0 0 0 0 0 0 0
41677 - 0 0 0 0 0 0 0 0 0 0 0 0
41678 - 0 0 0 0 0 0 0 0 0 0 0 0
41679 - 0 0 0 0 0 0 0 0 0 0 0 0
41680 - 0 0 0 0 0 0 0 0 0 0 0 0
41681 - 0 0 0 0 0 0 0 0 0 0 0 0
41682 - 0 0 0 0 0 0 0 0 0 0 0 0
41683 - 0 0 0 0 0 0 0 0 0 0 0 0
41684 - 0 0 0 0 0 0 0 0 0 0 0 0
41685 - 0 0 0 0 0 0 0 0 0 0 0 0
41686 - 0 0 0 0 0 0 0 0 0 0 0 0
41687 - 0 0 0 0 0 0 10 10 10 34 34 34
41688 - 74 74 74 74 74 74 2 2 6 6 6 6
41689 -144 144 144 198 198 198 190 190 190 178 166 146
41690 -154 121 60 156 107 11 156 107 11 168 124 44
41691 -174 154 114 187 187 187 190 190 190 210 210 210
41692 -246 246 246 253 253 253 253 253 253 182 182 182
41693 - 6 6 6 2 2 6 2 2 6 2 2 6
41694 - 2 2 6 2 2 6 2 2 6 62 62 62
41695 - 74 74 74 34 34 34 14 14 14 0 0 0
41696 - 0 0 0 0 0 0 0 0 0 0 0 0
41697 - 0 0 0 0 0 0 0 0 0 0 0 0
41698 - 0 0 0 0 0 0 0 0 0 0 0 0
41699 - 0 0 0 0 0 0 0 0 0 0 0 0
41700 - 0 0 0 0 0 0 0 0 0 0 0 0
41701 - 0 0 0 0 0 0 0 0 0 0 0 0
41702 - 0 0 0 0 0 0 0 0 0 0 0 0
41703 - 0 0 0 0 0 0 0 0 0 0 0 0
41704 - 0 0 0 0 0 0 0 0 0 0 0 0
41705 - 0 0 0 0 0 0 0 0 0 0 0 0
41706 - 0 0 0 0 0 0 0 0 0 0 0 0
41707 - 0 0 0 10 10 10 22 22 22 54 54 54
41708 - 94 94 94 18 18 18 2 2 6 46 46 46
41709 -234 234 234 221 221 221 190 190 190 190 190 190
41710 -190 190 190 187 187 187 187 187 187 190 190 190
41711 -190 190 190 195 195 195 214 214 214 242 242 242
41712 -253 253 253 253 253 253 253 253 253 253 253 253
41713 - 82 82 82 2 2 6 2 2 6 2 2 6
41714 - 2 2 6 2 2 6 2 2 6 14 14 14
41715 - 86 86 86 54 54 54 22 22 22 6 6 6
41716 - 0 0 0 0 0 0 0 0 0 0 0 0
41717 - 0 0 0 0 0 0 0 0 0 0 0 0
41718 - 0 0 0 0 0 0 0 0 0 0 0 0
41719 - 0 0 0 0 0 0 0 0 0 0 0 0
41720 - 0 0 0 0 0 0 0 0 0 0 0 0
41721 - 0 0 0 0 0 0 0 0 0 0 0 0
41722 - 0 0 0 0 0 0 0 0 0 0 0 0
41723 - 0 0 0 0 0 0 0 0 0 0 0 0
41724 - 0 0 0 0 0 0 0 0 0 0 0 0
41725 - 0 0 0 0 0 0 0 0 0 0 0 0
41726 - 0 0 0 0 0 0 0 0 0 0 0 0
41727 - 6 6 6 18 18 18 46 46 46 90 90 90
41728 - 46 46 46 18 18 18 6 6 6 182 182 182
41729 -253 253 253 246 246 246 206 206 206 190 190 190
41730 -190 190 190 190 190 190 190 190 190 190 190 190
41731 -206 206 206 231 231 231 250 250 250 253 253 253
41732 -253 253 253 253 253 253 253 253 253 253 253 253
41733 -202 202 202 14 14 14 2 2 6 2 2 6
41734 - 2 2 6 2 2 6 2 2 6 2 2 6
41735 - 42 42 42 86 86 86 42 42 42 18 18 18
41736 - 6 6 6 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 0 0 0
41742 - 0 0 0 0 0 0 0 0 0 0 0 0
41743 - 0 0 0 0 0 0 0 0 0 0 0 0
41744 - 0 0 0 0 0 0 0 0 0 0 0 0
41745 - 0 0 0 0 0 0 0 0 0 0 0 0
41746 - 0 0 0 0 0 0 0 0 0 6 6 6
41747 - 14 14 14 38 38 38 74 74 74 66 66 66
41748 - 2 2 6 6 6 6 90 90 90 250 250 250
41749 -253 253 253 253 253 253 238 238 238 198 198 198
41750 -190 190 190 190 190 190 195 195 195 221 221 221
41751 -246 246 246 253 253 253 253 253 253 253 253 253
41752 -253 253 253 253 253 253 253 253 253 253 253 253
41753 -253 253 253 82 82 82 2 2 6 2 2 6
41754 - 2 2 6 2 2 6 2 2 6 2 2 6
41755 - 2 2 6 78 78 78 70 70 70 34 34 34
41756 - 14 14 14 6 6 6 0 0 0 0 0 0
41757 - 0 0 0 0 0 0 0 0 0 0 0 0
41758 - 0 0 0 0 0 0 0 0 0 0 0 0
41759 - 0 0 0 0 0 0 0 0 0 0 0 0
41760 - 0 0 0 0 0 0 0 0 0 0 0 0
41761 - 0 0 0 0 0 0 0 0 0 0 0 0
41762 - 0 0 0 0 0 0 0 0 0 0 0 0
41763 - 0 0 0 0 0 0 0 0 0 0 0 0
41764 - 0 0 0 0 0 0 0 0 0 0 0 0
41765 - 0 0 0 0 0 0 0 0 0 0 0 0
41766 - 0 0 0 0 0 0 0 0 0 14 14 14
41767 - 34 34 34 66 66 66 78 78 78 6 6 6
41768 - 2 2 6 18 18 18 218 218 218 253 253 253
41769 -253 253 253 253 253 253 253 253 253 246 246 246
41770 -226 226 226 231 231 231 246 246 246 253 253 253
41771 -253 253 253 253 253 253 253 253 253 253 253 253
41772 -253 253 253 253 253 253 253 253 253 253 253 253
41773 -253 253 253 178 178 178 2 2 6 2 2 6
41774 - 2 2 6 2 2 6 2 2 6 2 2 6
41775 - 2 2 6 18 18 18 90 90 90 62 62 62
41776 - 30 30 30 10 10 10 0 0 0 0 0 0
41777 - 0 0 0 0 0 0 0 0 0 0 0 0
41778 - 0 0 0 0 0 0 0 0 0 0 0 0
41779 - 0 0 0 0 0 0 0 0 0 0 0 0
41780 - 0 0 0 0 0 0 0 0 0 0 0 0
41781 - 0 0 0 0 0 0 0 0 0 0 0 0
41782 - 0 0 0 0 0 0 0 0 0 0 0 0
41783 - 0 0 0 0 0 0 0 0 0 0 0 0
41784 - 0 0 0 0 0 0 0 0 0 0 0 0
41785 - 0 0 0 0 0 0 0 0 0 0 0 0
41786 - 0 0 0 0 0 0 10 10 10 26 26 26
41787 - 58 58 58 90 90 90 18 18 18 2 2 6
41788 - 2 2 6 110 110 110 253 253 253 253 253 253
41789 -253 253 253 253 253 253 253 253 253 253 253 253
41790 -250 250 250 253 253 253 253 253 253 253 253 253
41791 -253 253 253 253 253 253 253 253 253 253 253 253
41792 -253 253 253 253 253 253 253 253 253 253 253 253
41793 -253 253 253 231 231 231 18 18 18 2 2 6
41794 - 2 2 6 2 2 6 2 2 6 2 2 6
41795 - 2 2 6 2 2 6 18 18 18 94 94 94
41796 - 54 54 54 26 26 26 10 10 10 0 0 0
41797 - 0 0 0 0 0 0 0 0 0 0 0 0
41798 - 0 0 0 0 0 0 0 0 0 0 0 0
41799 - 0 0 0 0 0 0 0 0 0 0 0 0
41800 - 0 0 0 0 0 0 0 0 0 0 0 0
41801 - 0 0 0 0 0 0 0 0 0 0 0 0
41802 - 0 0 0 0 0 0 0 0 0 0 0 0
41803 - 0 0 0 0 0 0 0 0 0 0 0 0
41804 - 0 0 0 0 0 0 0 0 0 0 0 0
41805 - 0 0 0 0 0 0 0 0 0 0 0 0
41806 - 0 0 0 6 6 6 22 22 22 50 50 50
41807 - 90 90 90 26 26 26 2 2 6 2 2 6
41808 - 14 14 14 195 195 195 250 250 250 253 253 253
41809 -253 253 253 253 253 253 253 253 253 253 253 253
41810 -253 253 253 253 253 253 253 253 253 253 253 253
41811 -253 253 253 253 253 253 253 253 253 253 253 253
41812 -253 253 253 253 253 253 253 253 253 253 253 253
41813 -250 250 250 242 242 242 54 54 54 2 2 6
41814 - 2 2 6 2 2 6 2 2 6 2 2 6
41815 - 2 2 6 2 2 6 2 2 6 38 38 38
41816 - 86 86 86 50 50 50 22 22 22 6 6 6
41817 - 0 0 0 0 0 0 0 0 0 0 0 0
41818 - 0 0 0 0 0 0 0 0 0 0 0 0
41819 - 0 0 0 0 0 0 0 0 0 0 0 0
41820 - 0 0 0 0 0 0 0 0 0 0 0 0
41821 - 0 0 0 0 0 0 0 0 0 0 0 0
41822 - 0 0 0 0 0 0 0 0 0 0 0 0
41823 - 0 0 0 0 0 0 0 0 0 0 0 0
41824 - 0 0 0 0 0 0 0 0 0 0 0 0
41825 - 0 0 0 0 0 0 0 0 0 0 0 0
41826 - 6 6 6 14 14 14 38 38 38 82 82 82
41827 - 34 34 34 2 2 6 2 2 6 2 2 6
41828 - 42 42 42 195 195 195 246 246 246 253 253 253
41829 -253 253 253 253 253 253 253 253 253 250 250 250
41830 -242 242 242 242 242 242 250 250 250 253 253 253
41831 -253 253 253 253 253 253 253 253 253 253 253 253
41832 -253 253 253 250 250 250 246 246 246 238 238 238
41833 -226 226 226 231 231 231 101 101 101 6 6 6
41834 - 2 2 6 2 2 6 2 2 6 2 2 6
41835 - 2 2 6 2 2 6 2 2 6 2 2 6
41836 - 38 38 38 82 82 82 42 42 42 14 14 14
41837 - 6 6 6 0 0 0 0 0 0 0 0 0
41838 - 0 0 0 0 0 0 0 0 0 0 0 0
41839 - 0 0 0 0 0 0 0 0 0 0 0 0
41840 - 0 0 0 0 0 0 0 0 0 0 0 0
41841 - 0 0 0 0 0 0 0 0 0 0 0 0
41842 - 0 0 0 0 0 0 0 0 0 0 0 0
41843 - 0 0 0 0 0 0 0 0 0 0 0 0
41844 - 0 0 0 0 0 0 0 0 0 0 0 0
41845 - 0 0 0 0 0 0 0 0 0 0 0 0
41846 - 10 10 10 26 26 26 62 62 62 66 66 66
41847 - 2 2 6 2 2 6 2 2 6 6 6 6
41848 - 70 70 70 170 170 170 206 206 206 234 234 234
41849 -246 246 246 250 250 250 250 250 250 238 238 238
41850 -226 226 226 231 231 231 238 238 238 250 250 250
41851 -250 250 250 250 250 250 246 246 246 231 231 231
41852 -214 214 214 206 206 206 202 202 202 202 202 202
41853 -198 198 198 202 202 202 182 182 182 18 18 18
41854 - 2 2 6 2 2 6 2 2 6 2 2 6
41855 - 2 2 6 2 2 6 2 2 6 2 2 6
41856 - 2 2 6 62 62 62 66 66 66 30 30 30
41857 - 10 10 10 0 0 0 0 0 0 0 0 0
41858 - 0 0 0 0 0 0 0 0 0 0 0 0
41859 - 0 0 0 0 0 0 0 0 0 0 0 0
41860 - 0 0 0 0 0 0 0 0 0 0 0 0
41861 - 0 0 0 0 0 0 0 0 0 0 0 0
41862 - 0 0 0 0 0 0 0 0 0 0 0 0
41863 - 0 0 0 0 0 0 0 0 0 0 0 0
41864 - 0 0 0 0 0 0 0 0 0 0 0 0
41865 - 0 0 0 0 0 0 0 0 0 0 0 0
41866 - 14 14 14 42 42 42 82 82 82 18 18 18
41867 - 2 2 6 2 2 6 2 2 6 10 10 10
41868 - 94 94 94 182 182 182 218 218 218 242 242 242
41869 -250 250 250 253 253 253 253 253 253 250 250 250
41870 -234 234 234 253 253 253 253 253 253 253 253 253
41871 -253 253 253 253 253 253 253 253 253 246 246 246
41872 -238 238 238 226 226 226 210 210 210 202 202 202
41873 -195 195 195 195 195 195 210 210 210 158 158 158
41874 - 6 6 6 14 14 14 50 50 50 14 14 14
41875 - 2 2 6 2 2 6 2 2 6 2 2 6
41876 - 2 2 6 6 6 6 86 86 86 46 46 46
41877 - 18 18 18 6 6 6 0 0 0 0 0 0
41878 - 0 0 0 0 0 0 0 0 0 0 0 0
41879 - 0 0 0 0 0 0 0 0 0 0 0 0
41880 - 0 0 0 0 0 0 0 0 0 0 0 0
41881 - 0 0 0 0 0 0 0 0 0 0 0 0
41882 - 0 0 0 0 0 0 0 0 0 0 0 0
41883 - 0 0 0 0 0 0 0 0 0 0 0 0
41884 - 0 0 0 0 0 0 0 0 0 0 0 0
41885 - 0 0 0 0 0 0 0 0 0 6 6 6
41886 - 22 22 22 54 54 54 70 70 70 2 2 6
41887 - 2 2 6 10 10 10 2 2 6 22 22 22
41888 -166 166 166 231 231 231 250 250 250 253 253 253
41889 -253 253 253 253 253 253 253 253 253 250 250 250
41890 -242 242 242 253 253 253 253 253 253 253 253 253
41891 -253 253 253 253 253 253 253 253 253 253 253 253
41892 -253 253 253 253 253 253 253 253 253 246 246 246
41893 -231 231 231 206 206 206 198 198 198 226 226 226
41894 - 94 94 94 2 2 6 6 6 6 38 38 38
41895 - 30 30 30 2 2 6 2 2 6 2 2 6
41896 - 2 2 6 2 2 6 62 62 62 66 66 66
41897 - 26 26 26 10 10 10 0 0 0 0 0 0
41898 - 0 0 0 0 0 0 0 0 0 0 0 0
41899 - 0 0 0 0 0 0 0 0 0 0 0 0
41900 - 0 0 0 0 0 0 0 0 0 0 0 0
41901 - 0 0 0 0 0 0 0 0 0 0 0 0
41902 - 0 0 0 0 0 0 0 0 0 0 0 0
41903 - 0 0 0 0 0 0 0 0 0 0 0 0
41904 - 0 0 0 0 0 0 0 0 0 0 0 0
41905 - 0 0 0 0 0 0 0 0 0 10 10 10
41906 - 30 30 30 74 74 74 50 50 50 2 2 6
41907 - 26 26 26 26 26 26 2 2 6 106 106 106
41908 -238 238 238 253 253 253 253 253 253 253 253 253
41909 -253 253 253 253 253 253 253 253 253 253 253 253
41910 -253 253 253 253 253 253 253 253 253 253 253 253
41911 -253 253 253 253 253 253 253 253 253 253 253 253
41912 -253 253 253 253 253 253 253 253 253 253 253 253
41913 -253 253 253 246 246 246 218 218 218 202 202 202
41914 -210 210 210 14 14 14 2 2 6 2 2 6
41915 - 30 30 30 22 22 22 2 2 6 2 2 6
41916 - 2 2 6 2 2 6 18 18 18 86 86 86
41917 - 42 42 42 14 14 14 0 0 0 0 0 0
41918 - 0 0 0 0 0 0 0 0 0 0 0 0
41919 - 0 0 0 0 0 0 0 0 0 0 0 0
41920 - 0 0 0 0 0 0 0 0 0 0 0 0
41921 - 0 0 0 0 0 0 0 0 0 0 0 0
41922 - 0 0 0 0 0 0 0 0 0 0 0 0
41923 - 0 0 0 0 0 0 0 0 0 0 0 0
41924 - 0 0 0 0 0 0 0 0 0 0 0 0
41925 - 0 0 0 0 0 0 0 0 0 14 14 14
41926 - 42 42 42 90 90 90 22 22 22 2 2 6
41927 - 42 42 42 2 2 6 18 18 18 218 218 218
41928 -253 253 253 253 253 253 253 253 253 253 253 253
41929 -253 253 253 253 253 253 253 253 253 253 253 253
41930 -253 253 253 253 253 253 253 253 253 253 253 253
41931 -253 253 253 253 253 253 253 253 253 253 253 253
41932 -253 253 253 253 253 253 253 253 253 253 253 253
41933 -253 253 253 253 253 253 250 250 250 221 221 221
41934 -218 218 218 101 101 101 2 2 6 14 14 14
41935 - 18 18 18 38 38 38 10 10 10 2 2 6
41936 - 2 2 6 2 2 6 2 2 6 78 78 78
41937 - 58 58 58 22 22 22 6 6 6 0 0 0
41938 - 0 0 0 0 0 0 0 0 0 0 0 0
41939 - 0 0 0 0 0 0 0 0 0 0 0 0
41940 - 0 0 0 0 0 0 0 0 0 0 0 0
41941 - 0 0 0 0 0 0 0 0 0 0 0 0
41942 - 0 0 0 0 0 0 0 0 0 0 0 0
41943 - 0 0 0 0 0 0 0 0 0 0 0 0
41944 - 0 0 0 0 0 0 0 0 0 0 0 0
41945 - 0 0 0 0 0 0 6 6 6 18 18 18
41946 - 54 54 54 82 82 82 2 2 6 26 26 26
41947 - 22 22 22 2 2 6 123 123 123 253 253 253
41948 -253 253 253 253 253 253 253 253 253 253 253 253
41949 -253 253 253 253 253 253 253 253 253 253 253 253
41950 -253 253 253 253 253 253 253 253 253 253 253 253
41951 -253 253 253 253 253 253 253 253 253 253 253 253
41952 -253 253 253 253 253 253 253 253 253 253 253 253
41953 -253 253 253 253 253 253 253 253 253 250 250 250
41954 -238 238 238 198 198 198 6 6 6 38 38 38
41955 - 58 58 58 26 26 26 38 38 38 2 2 6
41956 - 2 2 6 2 2 6 2 2 6 46 46 46
41957 - 78 78 78 30 30 30 10 10 10 0 0 0
41958 - 0 0 0 0 0 0 0 0 0 0 0 0
41959 - 0 0 0 0 0 0 0 0 0 0 0 0
41960 - 0 0 0 0 0 0 0 0 0 0 0 0
41961 - 0 0 0 0 0 0 0 0 0 0 0 0
41962 - 0 0 0 0 0 0 0 0 0 0 0 0
41963 - 0 0 0 0 0 0 0 0 0 0 0 0
41964 - 0 0 0 0 0 0 0 0 0 0 0 0
41965 - 0 0 0 0 0 0 10 10 10 30 30 30
41966 - 74 74 74 58 58 58 2 2 6 42 42 42
41967 - 2 2 6 22 22 22 231 231 231 253 253 253
41968 -253 253 253 253 253 253 253 253 253 253 253 253
41969 -253 253 253 253 253 253 253 253 253 250 250 250
41970 -253 253 253 253 253 253 253 253 253 253 253 253
41971 -253 253 253 253 253 253 253 253 253 253 253 253
41972 -253 253 253 253 253 253 253 253 253 253 253 253
41973 -253 253 253 253 253 253 253 253 253 253 253 253
41974 -253 253 253 246 246 246 46 46 46 38 38 38
41975 - 42 42 42 14 14 14 38 38 38 14 14 14
41976 - 2 2 6 2 2 6 2 2 6 6 6 6
41977 - 86 86 86 46 46 46 14 14 14 0 0 0
41978 - 0 0 0 0 0 0 0 0 0 0 0 0
41979 - 0 0 0 0 0 0 0 0 0 0 0 0
41980 - 0 0 0 0 0 0 0 0 0 0 0 0
41981 - 0 0 0 0 0 0 0 0 0 0 0 0
41982 - 0 0 0 0 0 0 0 0 0 0 0 0
41983 - 0 0 0 0 0 0 0 0 0 0 0 0
41984 - 0 0 0 0 0 0 0 0 0 0 0 0
41985 - 0 0 0 6 6 6 14 14 14 42 42 42
41986 - 90 90 90 18 18 18 18 18 18 26 26 26
41987 - 2 2 6 116 116 116 253 253 253 253 253 253
41988 -253 253 253 253 253 253 253 253 253 253 253 253
41989 -253 253 253 253 253 253 250 250 250 238 238 238
41990 -253 253 253 253 253 253 253 253 253 253 253 253
41991 -253 253 253 253 253 253 253 253 253 253 253 253
41992 -253 253 253 253 253 253 253 253 253 253 253 253
41993 -253 253 253 253 253 253 253 253 253 253 253 253
41994 -253 253 253 253 253 253 94 94 94 6 6 6
41995 - 2 2 6 2 2 6 10 10 10 34 34 34
41996 - 2 2 6 2 2 6 2 2 6 2 2 6
41997 - 74 74 74 58 58 58 22 22 22 6 6 6
41998 - 0 0 0 0 0 0 0 0 0 0 0 0
41999 - 0 0 0 0 0 0 0 0 0 0 0 0
42000 - 0 0 0 0 0 0 0 0 0 0 0 0
42001 - 0 0 0 0 0 0 0 0 0 0 0 0
42002 - 0 0 0 0 0 0 0 0 0 0 0 0
42003 - 0 0 0 0 0 0 0 0 0 0 0 0
42004 - 0 0 0 0 0 0 0 0 0 0 0 0
42005 - 0 0 0 10 10 10 26 26 26 66 66 66
42006 - 82 82 82 2 2 6 38 38 38 6 6 6
42007 - 14 14 14 210 210 210 253 253 253 253 253 253
42008 -253 253 253 253 253 253 253 253 253 253 253 253
42009 -253 253 253 253 253 253 246 246 246 242 242 242
42010 -253 253 253 253 253 253 253 253 253 253 253 253
42011 -253 253 253 253 253 253 253 253 253 253 253 253
42012 -253 253 253 253 253 253 253 253 253 253 253 253
42013 -253 253 253 253 253 253 253 253 253 253 253 253
42014 -253 253 253 253 253 253 144 144 144 2 2 6
42015 - 2 2 6 2 2 6 2 2 6 46 46 46
42016 - 2 2 6 2 2 6 2 2 6 2 2 6
42017 - 42 42 42 74 74 74 30 30 30 10 10 10
42018 - 0 0 0 0 0 0 0 0 0 0 0 0
42019 - 0 0 0 0 0 0 0 0 0 0 0 0
42020 - 0 0 0 0 0 0 0 0 0 0 0 0
42021 - 0 0 0 0 0 0 0 0 0 0 0 0
42022 - 0 0 0 0 0 0 0 0 0 0 0 0
42023 - 0 0 0 0 0 0 0 0 0 0 0 0
42024 - 0 0 0 0 0 0 0 0 0 0 0 0
42025 - 6 6 6 14 14 14 42 42 42 90 90 90
42026 - 26 26 26 6 6 6 42 42 42 2 2 6
42027 - 74 74 74 250 250 250 253 253 253 253 253 253
42028 -253 253 253 253 253 253 253 253 253 253 253 253
42029 -253 253 253 253 253 253 242 242 242 242 242 242
42030 -253 253 253 253 253 253 253 253 253 253 253 253
42031 -253 253 253 253 253 253 253 253 253 253 253 253
42032 -253 253 253 253 253 253 253 253 253 253 253 253
42033 -253 253 253 253 253 253 253 253 253 253 253 253
42034 -253 253 253 253 253 253 182 182 182 2 2 6
42035 - 2 2 6 2 2 6 2 2 6 46 46 46
42036 - 2 2 6 2 2 6 2 2 6 2 2 6
42037 - 10 10 10 86 86 86 38 38 38 10 10 10
42038 - 0 0 0 0 0 0 0 0 0 0 0 0
42039 - 0 0 0 0 0 0 0 0 0 0 0 0
42040 - 0 0 0 0 0 0 0 0 0 0 0 0
42041 - 0 0 0 0 0 0 0 0 0 0 0 0
42042 - 0 0 0 0 0 0 0 0 0 0 0 0
42043 - 0 0 0 0 0 0 0 0 0 0 0 0
42044 - 0 0 0 0 0 0 0 0 0 0 0 0
42045 - 10 10 10 26 26 26 66 66 66 82 82 82
42046 - 2 2 6 22 22 22 18 18 18 2 2 6
42047 -149 149 149 253 253 253 253 253 253 253 253 253
42048 -253 253 253 253 253 253 253 253 253 253 253 253
42049 -253 253 253 253 253 253 234 234 234 242 242 242
42050 -253 253 253 253 253 253 253 253 253 253 253 253
42051 -253 253 253 253 253 253 253 253 253 253 253 253
42052 -253 253 253 253 253 253 253 253 253 253 253 253
42053 -253 253 253 253 253 253 253 253 253 253 253 253
42054 -253 253 253 253 253 253 206 206 206 2 2 6
42055 - 2 2 6 2 2 6 2 2 6 38 38 38
42056 - 2 2 6 2 2 6 2 2 6 2 2 6
42057 - 6 6 6 86 86 86 46 46 46 14 14 14
42058 - 0 0 0 0 0 0 0 0 0 0 0 0
42059 - 0 0 0 0 0 0 0 0 0 0 0 0
42060 - 0 0 0 0 0 0 0 0 0 0 0 0
42061 - 0 0 0 0 0 0 0 0 0 0 0 0
42062 - 0 0 0 0 0 0 0 0 0 0 0 0
42063 - 0 0 0 0 0 0 0 0 0 0 0 0
42064 - 0 0 0 0 0 0 0 0 0 6 6 6
42065 - 18 18 18 46 46 46 86 86 86 18 18 18
42066 - 2 2 6 34 34 34 10 10 10 6 6 6
42067 -210 210 210 253 253 253 253 253 253 253 253 253
42068 -253 253 253 253 253 253 253 253 253 253 253 253
42069 -253 253 253 253 253 253 234 234 234 242 242 242
42070 -253 253 253 253 253 253 253 253 253 253 253 253
42071 -253 253 253 253 253 253 253 253 253 253 253 253
42072 -253 253 253 253 253 253 253 253 253 253 253 253
42073 -253 253 253 253 253 253 253 253 253 253 253 253
42074 -253 253 253 253 253 253 221 221 221 6 6 6
42075 - 2 2 6 2 2 6 6 6 6 30 30 30
42076 - 2 2 6 2 2 6 2 2 6 2 2 6
42077 - 2 2 6 82 82 82 54 54 54 18 18 18
42078 - 6 6 6 0 0 0 0 0 0 0 0 0
42079 - 0 0 0 0 0 0 0 0 0 0 0 0
42080 - 0 0 0 0 0 0 0 0 0 0 0 0
42081 - 0 0 0 0 0 0 0 0 0 0 0 0
42082 - 0 0 0 0 0 0 0 0 0 0 0 0
42083 - 0 0 0 0 0 0 0 0 0 0 0 0
42084 - 0 0 0 0 0 0 0 0 0 10 10 10
42085 - 26 26 26 66 66 66 62 62 62 2 2 6
42086 - 2 2 6 38 38 38 10 10 10 26 26 26
42087 -238 238 238 253 253 253 253 253 253 253 253 253
42088 -253 253 253 253 253 253 253 253 253 253 253 253
42089 -253 253 253 253 253 253 231 231 231 238 238 238
42090 -253 253 253 253 253 253 253 253 253 253 253 253
42091 -253 253 253 253 253 253 253 253 253 253 253 253
42092 -253 253 253 253 253 253 253 253 253 253 253 253
42093 -253 253 253 253 253 253 253 253 253 253 253 253
42094 -253 253 253 253 253 253 231 231 231 6 6 6
42095 - 2 2 6 2 2 6 10 10 10 30 30 30
42096 - 2 2 6 2 2 6 2 2 6 2 2 6
42097 - 2 2 6 66 66 66 58 58 58 22 22 22
42098 - 6 6 6 0 0 0 0 0 0 0 0 0
42099 - 0 0 0 0 0 0 0 0 0 0 0 0
42100 - 0 0 0 0 0 0 0 0 0 0 0 0
42101 - 0 0 0 0 0 0 0 0 0 0 0 0
42102 - 0 0 0 0 0 0 0 0 0 0 0 0
42103 - 0 0 0 0 0 0 0 0 0 0 0 0
42104 - 0 0 0 0 0 0 0 0 0 10 10 10
42105 - 38 38 38 78 78 78 6 6 6 2 2 6
42106 - 2 2 6 46 46 46 14 14 14 42 42 42
42107 -246 246 246 253 253 253 253 253 253 253 253 253
42108 -253 253 253 253 253 253 253 253 253 253 253 253
42109 -253 253 253 253 253 253 231 231 231 242 242 242
42110 -253 253 253 253 253 253 253 253 253 253 253 253
42111 -253 253 253 253 253 253 253 253 253 253 253 253
42112 -253 253 253 253 253 253 253 253 253 253 253 253
42113 -253 253 253 253 253 253 253 253 253 253 253 253
42114 -253 253 253 253 253 253 234 234 234 10 10 10
42115 - 2 2 6 2 2 6 22 22 22 14 14 14
42116 - 2 2 6 2 2 6 2 2 6 2 2 6
42117 - 2 2 6 66 66 66 62 62 62 22 22 22
42118 - 6 6 6 0 0 0 0 0 0 0 0 0
42119 - 0 0 0 0 0 0 0 0 0 0 0 0
42120 - 0 0 0 0 0 0 0 0 0 0 0 0
42121 - 0 0 0 0 0 0 0 0 0 0 0 0
42122 - 0 0 0 0 0 0 0 0 0 0 0 0
42123 - 0 0 0 0 0 0 0 0 0 0 0 0
42124 - 0 0 0 0 0 0 6 6 6 18 18 18
42125 - 50 50 50 74 74 74 2 2 6 2 2 6
42126 - 14 14 14 70 70 70 34 34 34 62 62 62
42127 -250 250 250 253 253 253 253 253 253 253 253 253
42128 -253 253 253 253 253 253 253 253 253 253 253 253
42129 -253 253 253 253 253 253 231 231 231 246 246 246
42130 -253 253 253 253 253 253 253 253 253 253 253 253
42131 -253 253 253 253 253 253 253 253 253 253 253 253
42132 -253 253 253 253 253 253 253 253 253 253 253 253
42133 -253 253 253 253 253 253 253 253 253 253 253 253
42134 -253 253 253 253 253 253 234 234 234 14 14 14
42135 - 2 2 6 2 2 6 30 30 30 2 2 6
42136 - 2 2 6 2 2 6 2 2 6 2 2 6
42137 - 2 2 6 66 66 66 62 62 62 22 22 22
42138 - 6 6 6 0 0 0 0 0 0 0 0 0
42139 - 0 0 0 0 0 0 0 0 0 0 0 0
42140 - 0 0 0 0 0 0 0 0 0 0 0 0
42141 - 0 0 0 0 0 0 0 0 0 0 0 0
42142 - 0 0 0 0 0 0 0 0 0 0 0 0
42143 - 0 0 0 0 0 0 0 0 0 0 0 0
42144 - 0 0 0 0 0 0 6 6 6 18 18 18
42145 - 54 54 54 62 62 62 2 2 6 2 2 6
42146 - 2 2 6 30 30 30 46 46 46 70 70 70
42147 -250 250 250 253 253 253 253 253 253 253 253 253
42148 -253 253 253 253 253 253 253 253 253 253 253 253
42149 -253 253 253 253 253 253 231 231 231 246 246 246
42150 -253 253 253 253 253 253 253 253 253 253 253 253
42151 -253 253 253 253 253 253 253 253 253 253 253 253
42152 -253 253 253 253 253 253 253 253 253 253 253 253
42153 -253 253 253 253 253 253 253 253 253 253 253 253
42154 -253 253 253 253 253 253 226 226 226 10 10 10
42155 - 2 2 6 6 6 6 30 30 30 2 2 6
42156 - 2 2 6 2 2 6 2 2 6 2 2 6
42157 - 2 2 6 66 66 66 58 58 58 22 22 22
42158 - 6 6 6 0 0 0 0 0 0 0 0 0
42159 - 0 0 0 0 0 0 0 0 0 0 0 0
42160 - 0 0 0 0 0 0 0 0 0 0 0 0
42161 - 0 0 0 0 0 0 0 0 0 0 0 0
42162 - 0 0 0 0 0 0 0 0 0 0 0 0
42163 - 0 0 0 0 0 0 0 0 0 0 0 0
42164 - 0 0 0 0 0 0 6 6 6 22 22 22
42165 - 58 58 58 62 62 62 2 2 6 2 2 6
42166 - 2 2 6 2 2 6 30 30 30 78 78 78
42167 -250 250 250 253 253 253 253 253 253 253 253 253
42168 -253 253 253 253 253 253 253 253 253 253 253 253
42169 -253 253 253 253 253 253 231 231 231 246 246 246
42170 -253 253 253 253 253 253 253 253 253 253 253 253
42171 -253 253 253 253 253 253 253 253 253 253 253 253
42172 -253 253 253 253 253 253 253 253 253 253 253 253
42173 -253 253 253 253 253 253 253 253 253 253 253 253
42174 -253 253 253 253 253 253 206 206 206 2 2 6
42175 - 22 22 22 34 34 34 18 14 6 22 22 22
42176 - 26 26 26 18 18 18 6 6 6 2 2 6
42177 - 2 2 6 82 82 82 54 54 54 18 18 18
42178 - 6 6 6 0 0 0 0 0 0 0 0 0
42179 - 0 0 0 0 0 0 0 0 0 0 0 0
42180 - 0 0 0 0 0 0 0 0 0 0 0 0
42181 - 0 0 0 0 0 0 0 0 0 0 0 0
42182 - 0 0 0 0 0 0 0 0 0 0 0 0
42183 - 0 0 0 0 0 0 0 0 0 0 0 0
42184 - 0 0 0 0 0 0 6 6 6 26 26 26
42185 - 62 62 62 106 106 106 74 54 14 185 133 11
42186 -210 162 10 121 92 8 6 6 6 62 62 62
42187 -238 238 238 253 253 253 253 253 253 253 253 253
42188 -253 253 253 253 253 253 253 253 253 253 253 253
42189 -253 253 253 253 253 253 231 231 231 246 246 246
42190 -253 253 253 253 253 253 253 253 253 253 253 253
42191 -253 253 253 253 253 253 253 253 253 253 253 253
42192 -253 253 253 253 253 253 253 253 253 253 253 253
42193 -253 253 253 253 253 253 253 253 253 253 253 253
42194 -253 253 253 253 253 253 158 158 158 18 18 18
42195 - 14 14 14 2 2 6 2 2 6 2 2 6
42196 - 6 6 6 18 18 18 66 66 66 38 38 38
42197 - 6 6 6 94 94 94 50 50 50 18 18 18
42198 - 6 6 6 0 0 0 0 0 0 0 0 0
42199 - 0 0 0 0 0 0 0 0 0 0 0 0
42200 - 0 0 0 0 0 0 0 0 0 0 0 0
42201 - 0 0 0 0 0 0 0 0 0 0 0 0
42202 - 0 0 0 0 0 0 0 0 0 0 0 0
42203 - 0 0 0 0 0 0 0 0 0 6 6 6
42204 - 10 10 10 10 10 10 18 18 18 38 38 38
42205 - 78 78 78 142 134 106 216 158 10 242 186 14
42206 -246 190 14 246 190 14 156 118 10 10 10 10
42207 - 90 90 90 238 238 238 253 253 253 253 253 253
42208 -253 253 253 253 253 253 253 253 253 253 253 253
42209 -253 253 253 253 253 253 231 231 231 250 250 250
42210 -253 253 253 253 253 253 253 253 253 253 253 253
42211 -253 253 253 253 253 253 253 253 253 253 253 253
42212 -253 253 253 253 253 253 253 253 253 253 253 253
42213 -253 253 253 253 253 253 253 253 253 246 230 190
42214 -238 204 91 238 204 91 181 142 44 37 26 9
42215 - 2 2 6 2 2 6 2 2 6 2 2 6
42216 - 2 2 6 2 2 6 38 38 38 46 46 46
42217 - 26 26 26 106 106 106 54 54 54 18 18 18
42218 - 6 6 6 0 0 0 0 0 0 0 0 0
42219 - 0 0 0 0 0 0 0 0 0 0 0 0
42220 - 0 0 0 0 0 0 0 0 0 0 0 0
42221 - 0 0 0 0 0 0 0 0 0 0 0 0
42222 - 0 0 0 0 0 0 0 0 0 0 0 0
42223 - 0 0 0 6 6 6 14 14 14 22 22 22
42224 - 30 30 30 38 38 38 50 50 50 70 70 70
42225 -106 106 106 190 142 34 226 170 11 242 186 14
42226 -246 190 14 246 190 14 246 190 14 154 114 10
42227 - 6 6 6 74 74 74 226 226 226 253 253 253
42228 -253 253 253 253 253 253 253 253 253 253 253 253
42229 -253 253 253 253 253 253 231 231 231 250 250 250
42230 -253 253 253 253 253 253 253 253 253 253 253 253
42231 -253 253 253 253 253 253 253 253 253 253 253 253
42232 -253 253 253 253 253 253 253 253 253 253 253 253
42233 -253 253 253 253 253 253 253 253 253 228 184 62
42234 -241 196 14 241 208 19 232 195 16 38 30 10
42235 - 2 2 6 2 2 6 2 2 6 2 2 6
42236 - 2 2 6 6 6 6 30 30 30 26 26 26
42237 -203 166 17 154 142 90 66 66 66 26 26 26
42238 - 6 6 6 0 0 0 0 0 0 0 0 0
42239 - 0 0 0 0 0 0 0 0 0 0 0 0
42240 - 0 0 0 0 0 0 0 0 0 0 0 0
42241 - 0 0 0 0 0 0 0 0 0 0 0 0
42242 - 0 0 0 0 0 0 0 0 0 0 0 0
42243 - 6 6 6 18 18 18 38 38 38 58 58 58
42244 - 78 78 78 86 86 86 101 101 101 123 123 123
42245 -175 146 61 210 150 10 234 174 13 246 186 14
42246 -246 190 14 246 190 14 246 190 14 238 190 10
42247 -102 78 10 2 2 6 46 46 46 198 198 198
42248 -253 253 253 253 253 253 253 253 253 253 253 253
42249 -253 253 253 253 253 253 234 234 234 242 242 242
42250 -253 253 253 253 253 253 253 253 253 253 253 253
42251 -253 253 253 253 253 253 253 253 253 253 253 253
42252 -253 253 253 253 253 253 253 253 253 253 253 253
42253 -253 253 253 253 253 253 253 253 253 224 178 62
42254 -242 186 14 241 196 14 210 166 10 22 18 6
42255 - 2 2 6 2 2 6 2 2 6 2 2 6
42256 - 2 2 6 2 2 6 6 6 6 121 92 8
42257 -238 202 15 232 195 16 82 82 82 34 34 34
42258 - 10 10 10 0 0 0 0 0 0 0 0 0
42259 - 0 0 0 0 0 0 0 0 0 0 0 0
42260 - 0 0 0 0 0 0 0 0 0 0 0 0
42261 - 0 0 0 0 0 0 0 0 0 0 0 0
42262 - 0 0 0 0 0 0 0 0 0 0 0 0
42263 - 14 14 14 38 38 38 70 70 70 154 122 46
42264 -190 142 34 200 144 11 197 138 11 197 138 11
42265 -213 154 11 226 170 11 242 186 14 246 190 14
42266 -246 190 14 246 190 14 246 190 14 246 190 14
42267 -225 175 15 46 32 6 2 2 6 22 22 22
42268 -158 158 158 250 250 250 253 253 253 253 253 253
42269 -253 253 253 253 253 253 253 253 253 253 253 253
42270 -253 253 253 253 253 253 253 253 253 253 253 253
42271 -253 253 253 253 253 253 253 253 253 253 253 253
42272 -253 253 253 253 253 253 253 253 253 253 253 253
42273 -253 253 253 250 250 250 242 242 242 224 178 62
42274 -239 182 13 236 186 11 213 154 11 46 32 6
42275 - 2 2 6 2 2 6 2 2 6 2 2 6
42276 - 2 2 6 2 2 6 61 42 6 225 175 15
42277 -238 190 10 236 186 11 112 100 78 42 42 42
42278 - 14 14 14 0 0 0 0 0 0 0 0 0
42279 - 0 0 0 0 0 0 0 0 0 0 0 0
42280 - 0 0 0 0 0 0 0 0 0 0 0 0
42281 - 0 0 0 0 0 0 0 0 0 0 0 0
42282 - 0 0 0 0 0 0 0 0 0 6 6 6
42283 - 22 22 22 54 54 54 154 122 46 213 154 11
42284 -226 170 11 230 174 11 226 170 11 226 170 11
42285 -236 178 12 242 186 14 246 190 14 246 190 14
42286 -246 190 14 246 190 14 246 190 14 246 190 14
42287 -241 196 14 184 144 12 10 10 10 2 2 6
42288 - 6 6 6 116 116 116 242 242 242 253 253 253
42289 -253 253 253 253 253 253 253 253 253 253 253 253
42290 -253 253 253 253 253 253 253 253 253 253 253 253
42291 -253 253 253 253 253 253 253 253 253 253 253 253
42292 -253 253 253 253 253 253 253 253 253 253 253 253
42293 -253 253 253 231 231 231 198 198 198 214 170 54
42294 -236 178 12 236 178 12 210 150 10 137 92 6
42295 - 18 14 6 2 2 6 2 2 6 2 2 6
42296 - 6 6 6 70 47 6 200 144 11 236 178 12
42297 -239 182 13 239 182 13 124 112 88 58 58 58
42298 - 22 22 22 6 6 6 0 0 0 0 0 0
42299 - 0 0 0 0 0 0 0 0 0 0 0 0
42300 - 0 0 0 0 0 0 0 0 0 0 0 0
42301 - 0 0 0 0 0 0 0 0 0 0 0 0
42302 - 0 0 0 0 0 0 0 0 0 10 10 10
42303 - 30 30 30 70 70 70 180 133 36 226 170 11
42304 -239 182 13 242 186 14 242 186 14 246 186 14
42305 -246 190 14 246 190 14 246 190 14 246 190 14
42306 -246 190 14 246 190 14 246 190 14 246 190 14
42307 -246 190 14 232 195 16 98 70 6 2 2 6
42308 - 2 2 6 2 2 6 66 66 66 221 221 221
42309 -253 253 253 253 253 253 253 253 253 253 253 253
42310 -253 253 253 253 253 253 253 253 253 253 253 253
42311 -253 253 253 253 253 253 253 253 253 253 253 253
42312 -253 253 253 253 253 253 253 253 253 253 253 253
42313 -253 253 253 206 206 206 198 198 198 214 166 58
42314 -230 174 11 230 174 11 216 158 10 192 133 9
42315 -163 110 8 116 81 8 102 78 10 116 81 8
42316 -167 114 7 197 138 11 226 170 11 239 182 13
42317 -242 186 14 242 186 14 162 146 94 78 78 78
42318 - 34 34 34 14 14 14 6 6 6 0 0 0
42319 - 0 0 0 0 0 0 0 0 0 0 0 0
42320 - 0 0 0 0 0 0 0 0 0 0 0 0
42321 - 0 0 0 0 0 0 0 0 0 0 0 0
42322 - 0 0 0 0 0 0 0 0 0 6 6 6
42323 - 30 30 30 78 78 78 190 142 34 226 170 11
42324 -239 182 13 246 190 14 246 190 14 246 190 14
42325 -246 190 14 246 190 14 246 190 14 246 190 14
42326 -246 190 14 246 190 14 246 190 14 246 190 14
42327 -246 190 14 241 196 14 203 166 17 22 18 6
42328 - 2 2 6 2 2 6 2 2 6 38 38 38
42329 -218 218 218 253 253 253 253 253 253 253 253 253
42330 -253 253 253 253 253 253 253 253 253 253 253 253
42331 -253 253 253 253 253 253 253 253 253 253 253 253
42332 -253 253 253 253 253 253 253 253 253 253 253 253
42333 -250 250 250 206 206 206 198 198 198 202 162 69
42334 -226 170 11 236 178 12 224 166 10 210 150 10
42335 -200 144 11 197 138 11 192 133 9 197 138 11
42336 -210 150 10 226 170 11 242 186 14 246 190 14
42337 -246 190 14 246 186 14 225 175 15 124 112 88
42338 - 62 62 62 30 30 30 14 14 14 6 6 6
42339 - 0 0 0 0 0 0 0 0 0 0 0 0
42340 - 0 0 0 0 0 0 0 0 0 0 0 0
42341 - 0 0 0 0 0 0 0 0 0 0 0 0
42342 - 0 0 0 0 0 0 0 0 0 10 10 10
42343 - 30 30 30 78 78 78 174 135 50 224 166 10
42344 -239 182 13 246 190 14 246 190 14 246 190 14
42345 -246 190 14 246 190 14 246 190 14 246 190 14
42346 -246 190 14 246 190 14 246 190 14 246 190 14
42347 -246 190 14 246 190 14 241 196 14 139 102 15
42348 - 2 2 6 2 2 6 2 2 6 2 2 6
42349 - 78 78 78 250 250 250 253 253 253 253 253 253
42350 -253 253 253 253 253 253 253 253 253 253 253 253
42351 -253 253 253 253 253 253 253 253 253 253 253 253
42352 -253 253 253 253 253 253 253 253 253 253 253 253
42353 -250 250 250 214 214 214 198 198 198 190 150 46
42354 -219 162 10 236 178 12 234 174 13 224 166 10
42355 -216 158 10 213 154 11 213 154 11 216 158 10
42356 -226 170 11 239 182 13 246 190 14 246 190 14
42357 -246 190 14 246 190 14 242 186 14 206 162 42
42358 -101 101 101 58 58 58 30 30 30 14 14 14
42359 - 6 6 6 0 0 0 0 0 0 0 0 0
42360 - 0 0 0 0 0 0 0 0 0 0 0 0
42361 - 0 0 0 0 0 0 0 0 0 0 0 0
42362 - 0 0 0 0 0 0 0 0 0 10 10 10
42363 - 30 30 30 74 74 74 174 135 50 216 158 10
42364 -236 178 12 246 190 14 246 190 14 246 190 14
42365 -246 190 14 246 190 14 246 190 14 246 190 14
42366 -246 190 14 246 190 14 246 190 14 246 190 14
42367 -246 190 14 246 190 14 241 196 14 226 184 13
42368 - 61 42 6 2 2 6 2 2 6 2 2 6
42369 - 22 22 22 238 238 238 253 253 253 253 253 253
42370 -253 253 253 253 253 253 253 253 253 253 253 253
42371 -253 253 253 253 253 253 253 253 253 253 253 253
42372 -253 253 253 253 253 253 253 253 253 253 253 253
42373 -253 253 253 226 226 226 187 187 187 180 133 36
42374 -216 158 10 236 178 12 239 182 13 236 178 12
42375 -230 174 11 226 170 11 226 170 11 230 174 11
42376 -236 178 12 242 186 14 246 190 14 246 190 14
42377 -246 190 14 246 190 14 246 186 14 239 182 13
42378 -206 162 42 106 106 106 66 66 66 34 34 34
42379 - 14 14 14 6 6 6 0 0 0 0 0 0
42380 - 0 0 0 0 0 0 0 0 0 0 0 0
42381 - 0 0 0 0 0 0 0 0 0 0 0 0
42382 - 0 0 0 0 0 0 0 0 0 6 6 6
42383 - 26 26 26 70 70 70 163 133 67 213 154 11
42384 -236 178 12 246 190 14 246 190 14 246 190 14
42385 -246 190 14 246 190 14 246 190 14 246 190 14
42386 -246 190 14 246 190 14 246 190 14 246 190 14
42387 -246 190 14 246 190 14 246 190 14 241 196 14
42388 -190 146 13 18 14 6 2 2 6 2 2 6
42389 - 46 46 46 246 246 246 253 253 253 253 253 253
42390 -253 253 253 253 253 253 253 253 253 253 253 253
42391 -253 253 253 253 253 253 253 253 253 253 253 253
42392 -253 253 253 253 253 253 253 253 253 253 253 253
42393 -253 253 253 221 221 221 86 86 86 156 107 11
42394 -216 158 10 236 178 12 242 186 14 246 186 14
42395 -242 186 14 239 182 13 239 182 13 242 186 14
42396 -242 186 14 246 186 14 246 190 14 246 190 14
42397 -246 190 14 246 190 14 246 190 14 246 190 14
42398 -242 186 14 225 175 15 142 122 72 66 66 66
42399 - 30 30 30 10 10 10 0 0 0 0 0 0
42400 - 0 0 0 0 0 0 0 0 0 0 0 0
42401 - 0 0 0 0 0 0 0 0 0 0 0 0
42402 - 0 0 0 0 0 0 0 0 0 6 6 6
42403 - 26 26 26 70 70 70 163 133 67 210 150 10
42404 -236 178 12 246 190 14 246 190 14 246 190 14
42405 -246 190 14 246 190 14 246 190 14 246 190 14
42406 -246 190 14 246 190 14 246 190 14 246 190 14
42407 -246 190 14 246 190 14 246 190 14 246 190 14
42408 -232 195 16 121 92 8 34 34 34 106 106 106
42409 -221 221 221 253 253 253 253 253 253 253 253 253
42410 -253 253 253 253 253 253 253 253 253 253 253 253
42411 -253 253 253 253 253 253 253 253 253 253 253 253
42412 -253 253 253 253 253 253 253 253 253 253 253 253
42413 -242 242 242 82 82 82 18 14 6 163 110 8
42414 -216 158 10 236 178 12 242 186 14 246 190 14
42415 -246 190 14 246 190 14 246 190 14 246 190 14
42416 -246 190 14 246 190 14 246 190 14 246 190 14
42417 -246 190 14 246 190 14 246 190 14 246 190 14
42418 -246 190 14 246 190 14 242 186 14 163 133 67
42419 - 46 46 46 18 18 18 6 6 6 0 0 0
42420 - 0 0 0 0 0 0 0 0 0 0 0 0
42421 - 0 0 0 0 0 0 0 0 0 0 0 0
42422 - 0 0 0 0 0 0 0 0 0 10 10 10
42423 - 30 30 30 78 78 78 163 133 67 210 150 10
42424 -236 178 12 246 186 14 246 190 14 246 190 14
42425 -246 190 14 246 190 14 246 190 14 246 190 14
42426 -246 190 14 246 190 14 246 190 14 246 190 14
42427 -246 190 14 246 190 14 246 190 14 246 190 14
42428 -241 196 14 215 174 15 190 178 144 253 253 253
42429 -253 253 253 253 253 253 253 253 253 253 253 253
42430 -253 253 253 253 253 253 253 253 253 253 253 253
42431 -253 253 253 253 253 253 253 253 253 253 253 253
42432 -253 253 253 253 253 253 253 253 253 218 218 218
42433 - 58 58 58 2 2 6 22 18 6 167 114 7
42434 -216 158 10 236 178 12 246 186 14 246 190 14
42435 -246 190 14 246 190 14 246 190 14 246 190 14
42436 -246 190 14 246 190 14 246 190 14 246 190 14
42437 -246 190 14 246 190 14 246 190 14 246 190 14
42438 -246 190 14 246 186 14 242 186 14 190 150 46
42439 - 54 54 54 22 22 22 6 6 6 0 0 0
42440 - 0 0 0 0 0 0 0 0 0 0 0 0
42441 - 0 0 0 0 0 0 0 0 0 0 0 0
42442 - 0 0 0 0 0 0 0 0 0 14 14 14
42443 - 38 38 38 86 86 86 180 133 36 213 154 11
42444 -236 178 12 246 186 14 246 190 14 246 190 14
42445 -246 190 14 246 190 14 246 190 14 246 190 14
42446 -246 190 14 246 190 14 246 190 14 246 190 14
42447 -246 190 14 246 190 14 246 190 14 246 190 14
42448 -246 190 14 232 195 16 190 146 13 214 214 214
42449 -253 253 253 253 253 253 253 253 253 253 253 253
42450 -253 253 253 253 253 253 253 253 253 253 253 253
42451 -253 253 253 253 253 253 253 253 253 253 253 253
42452 -253 253 253 250 250 250 170 170 170 26 26 26
42453 - 2 2 6 2 2 6 37 26 9 163 110 8
42454 -219 162 10 239 182 13 246 186 14 246 190 14
42455 -246 190 14 246 190 14 246 190 14 246 190 14
42456 -246 190 14 246 190 14 246 190 14 246 190 14
42457 -246 190 14 246 190 14 246 190 14 246 190 14
42458 -246 186 14 236 178 12 224 166 10 142 122 72
42459 - 46 46 46 18 18 18 6 6 6 0 0 0
42460 - 0 0 0 0 0 0 0 0 0 0 0 0
42461 - 0 0 0 0 0 0 0 0 0 0 0 0
42462 - 0 0 0 0 0 0 6 6 6 18 18 18
42463 - 50 50 50 109 106 95 192 133 9 224 166 10
42464 -242 186 14 246 190 14 246 190 14 246 190 14
42465 -246 190 14 246 190 14 246 190 14 246 190 14
42466 -246 190 14 246 190 14 246 190 14 246 190 14
42467 -246 190 14 246 190 14 246 190 14 246 190 14
42468 -242 186 14 226 184 13 210 162 10 142 110 46
42469 -226 226 226 253 253 253 253 253 253 253 253 253
42470 -253 253 253 253 253 253 253 253 253 253 253 253
42471 -253 253 253 253 253 253 253 253 253 253 253 253
42472 -198 198 198 66 66 66 2 2 6 2 2 6
42473 - 2 2 6 2 2 6 50 34 6 156 107 11
42474 -219 162 10 239 182 13 246 186 14 246 190 14
42475 -246 190 14 246 190 14 246 190 14 246 190 14
42476 -246 190 14 246 190 14 246 190 14 246 190 14
42477 -246 190 14 246 190 14 246 190 14 242 186 14
42478 -234 174 13 213 154 11 154 122 46 66 66 66
42479 - 30 30 30 10 10 10 0 0 0 0 0 0
42480 - 0 0 0 0 0 0 0 0 0 0 0 0
42481 - 0 0 0 0 0 0 0 0 0 0 0 0
42482 - 0 0 0 0 0 0 6 6 6 22 22 22
42483 - 58 58 58 154 121 60 206 145 10 234 174 13
42484 -242 186 14 246 186 14 246 190 14 246 190 14
42485 -246 190 14 246 190 14 246 190 14 246 190 14
42486 -246 190 14 246 190 14 246 190 14 246 190 14
42487 -246 190 14 246 190 14 246 190 14 246 190 14
42488 -246 186 14 236 178 12 210 162 10 163 110 8
42489 - 61 42 6 138 138 138 218 218 218 250 250 250
42490 -253 253 253 253 253 253 253 253 253 250 250 250
42491 -242 242 242 210 210 210 144 144 144 66 66 66
42492 - 6 6 6 2 2 6 2 2 6 2 2 6
42493 - 2 2 6 2 2 6 61 42 6 163 110 8
42494 -216 158 10 236 178 12 246 190 14 246 190 14
42495 -246 190 14 246 190 14 246 190 14 246 190 14
42496 -246 190 14 246 190 14 246 190 14 246 190 14
42497 -246 190 14 239 182 13 230 174 11 216 158 10
42498 -190 142 34 124 112 88 70 70 70 38 38 38
42499 - 18 18 18 6 6 6 0 0 0 0 0 0
42500 - 0 0 0 0 0 0 0 0 0 0 0 0
42501 - 0 0 0 0 0 0 0 0 0 0 0 0
42502 - 0 0 0 0 0 0 6 6 6 22 22 22
42503 - 62 62 62 168 124 44 206 145 10 224 166 10
42504 -236 178 12 239 182 13 242 186 14 242 186 14
42505 -246 186 14 246 190 14 246 190 14 246 190 14
42506 -246 190 14 246 190 14 246 190 14 246 190 14
42507 -246 190 14 246 190 14 246 190 14 246 190 14
42508 -246 190 14 236 178 12 216 158 10 175 118 6
42509 - 80 54 7 2 2 6 6 6 6 30 30 30
42510 - 54 54 54 62 62 62 50 50 50 38 38 38
42511 - 14 14 14 2 2 6 2 2 6 2 2 6
42512 - 2 2 6 2 2 6 2 2 6 2 2 6
42513 - 2 2 6 6 6 6 80 54 7 167 114 7
42514 -213 154 11 236 178 12 246 190 14 246 190 14
42515 -246 190 14 246 190 14 246 190 14 246 190 14
42516 -246 190 14 242 186 14 239 182 13 239 182 13
42517 -230 174 11 210 150 10 174 135 50 124 112 88
42518 - 82 82 82 54 54 54 34 34 34 18 18 18
42519 - 6 6 6 0 0 0 0 0 0 0 0 0
42520 - 0 0 0 0 0 0 0 0 0 0 0 0
42521 - 0 0 0 0 0 0 0 0 0 0 0 0
42522 - 0 0 0 0 0 0 6 6 6 18 18 18
42523 - 50 50 50 158 118 36 192 133 9 200 144 11
42524 -216 158 10 219 162 10 224 166 10 226 170 11
42525 -230 174 11 236 178 12 239 182 13 239 182 13
42526 -242 186 14 246 186 14 246 190 14 246 190 14
42527 -246 190 14 246 190 14 246 190 14 246 190 14
42528 -246 186 14 230 174 11 210 150 10 163 110 8
42529 -104 69 6 10 10 10 2 2 6 2 2 6
42530 - 2 2 6 2 2 6 2 2 6 2 2 6
42531 - 2 2 6 2 2 6 2 2 6 2 2 6
42532 - 2 2 6 2 2 6 2 2 6 2 2 6
42533 - 2 2 6 6 6 6 91 60 6 167 114 7
42534 -206 145 10 230 174 11 242 186 14 246 190 14
42535 -246 190 14 246 190 14 246 186 14 242 186 14
42536 -239 182 13 230 174 11 224 166 10 213 154 11
42537 -180 133 36 124 112 88 86 86 86 58 58 58
42538 - 38 38 38 22 22 22 10 10 10 6 6 6
42539 - 0 0 0 0 0 0 0 0 0 0 0 0
42540 - 0 0 0 0 0 0 0 0 0 0 0 0
42541 - 0 0 0 0 0 0 0 0 0 0 0 0
42542 - 0 0 0 0 0 0 0 0 0 14 14 14
42543 - 34 34 34 70 70 70 138 110 50 158 118 36
42544 -167 114 7 180 123 7 192 133 9 197 138 11
42545 -200 144 11 206 145 10 213 154 11 219 162 10
42546 -224 166 10 230 174 11 239 182 13 242 186 14
42547 -246 186 14 246 186 14 246 186 14 246 186 14
42548 -239 182 13 216 158 10 185 133 11 152 99 6
42549 -104 69 6 18 14 6 2 2 6 2 2 6
42550 - 2 2 6 2 2 6 2 2 6 2 2 6
42551 - 2 2 6 2 2 6 2 2 6 2 2 6
42552 - 2 2 6 2 2 6 2 2 6 2 2 6
42553 - 2 2 6 6 6 6 80 54 7 152 99 6
42554 -192 133 9 219 162 10 236 178 12 239 182 13
42555 -246 186 14 242 186 14 239 182 13 236 178 12
42556 -224 166 10 206 145 10 192 133 9 154 121 60
42557 - 94 94 94 62 62 62 42 42 42 22 22 22
42558 - 14 14 14 6 6 6 0 0 0 0 0 0
42559 - 0 0 0 0 0 0 0 0 0 0 0 0
42560 - 0 0 0 0 0 0 0 0 0 0 0 0
42561 - 0 0 0 0 0 0 0 0 0 0 0 0
42562 - 0 0 0 0 0 0 0 0 0 6 6 6
42563 - 18 18 18 34 34 34 58 58 58 78 78 78
42564 -101 98 89 124 112 88 142 110 46 156 107 11
42565 -163 110 8 167 114 7 175 118 6 180 123 7
42566 -185 133 11 197 138 11 210 150 10 219 162 10
42567 -226 170 11 236 178 12 236 178 12 234 174 13
42568 -219 162 10 197 138 11 163 110 8 130 83 6
42569 - 91 60 6 10 10 10 2 2 6 2 2 6
42570 - 18 18 18 38 38 38 38 38 38 38 38 38
42571 - 38 38 38 38 38 38 38 38 38 38 38 38
42572 - 38 38 38 38 38 38 26 26 26 2 2 6
42573 - 2 2 6 6 6 6 70 47 6 137 92 6
42574 -175 118 6 200 144 11 219 162 10 230 174 11
42575 -234 174 13 230 174 11 219 162 10 210 150 10
42576 -192 133 9 163 110 8 124 112 88 82 82 82
42577 - 50 50 50 30 30 30 14 14 14 6 6 6
42578 - 0 0 0 0 0 0 0 0 0 0 0 0
42579 - 0 0 0 0 0 0 0 0 0 0 0 0
42580 - 0 0 0 0 0 0 0 0 0 0 0 0
42581 - 0 0 0 0 0 0 0 0 0 0 0 0
42582 - 0 0 0 0 0 0 0 0 0 0 0 0
42583 - 6 6 6 14 14 14 22 22 22 34 34 34
42584 - 42 42 42 58 58 58 74 74 74 86 86 86
42585 -101 98 89 122 102 70 130 98 46 121 87 25
42586 -137 92 6 152 99 6 163 110 8 180 123 7
42587 -185 133 11 197 138 11 206 145 10 200 144 11
42588 -180 123 7 156 107 11 130 83 6 104 69 6
42589 - 50 34 6 54 54 54 110 110 110 101 98 89
42590 - 86 86 86 82 82 82 78 78 78 78 78 78
42591 - 78 78 78 78 78 78 78 78 78 78 78 78
42592 - 78 78 78 82 82 82 86 86 86 94 94 94
42593 -106 106 106 101 101 101 86 66 34 124 80 6
42594 -156 107 11 180 123 7 192 133 9 200 144 11
42595 -206 145 10 200 144 11 192 133 9 175 118 6
42596 -139 102 15 109 106 95 70 70 70 42 42 42
42597 - 22 22 22 10 10 10 0 0 0 0 0 0
42598 - 0 0 0 0 0 0 0 0 0 0 0 0
42599 - 0 0 0 0 0 0 0 0 0 0 0 0
42600 - 0 0 0 0 0 0 0 0 0 0 0 0
42601 - 0 0 0 0 0 0 0 0 0 0 0 0
42602 - 0 0 0 0 0 0 0 0 0 0 0 0
42603 - 0 0 0 0 0 0 6 6 6 10 10 10
42604 - 14 14 14 22 22 22 30 30 30 38 38 38
42605 - 50 50 50 62 62 62 74 74 74 90 90 90
42606 -101 98 89 112 100 78 121 87 25 124 80 6
42607 -137 92 6 152 99 6 152 99 6 152 99 6
42608 -138 86 6 124 80 6 98 70 6 86 66 30
42609 -101 98 89 82 82 82 58 58 58 46 46 46
42610 - 38 38 38 34 34 34 34 34 34 34 34 34
42611 - 34 34 34 34 34 34 34 34 34 34 34 34
42612 - 34 34 34 34 34 34 38 38 38 42 42 42
42613 - 54 54 54 82 82 82 94 86 76 91 60 6
42614 -134 86 6 156 107 11 167 114 7 175 118 6
42615 -175 118 6 167 114 7 152 99 6 121 87 25
42616 -101 98 89 62 62 62 34 34 34 18 18 18
42617 - 6 6 6 0 0 0 0 0 0 0 0 0
42618 - 0 0 0 0 0 0 0 0 0 0 0 0
42619 - 0 0 0 0 0 0 0 0 0 0 0 0
42620 - 0 0 0 0 0 0 0 0 0 0 0 0
42621 - 0 0 0 0 0 0 0 0 0 0 0 0
42622 - 0 0 0 0 0 0 0 0 0 0 0 0
42623 - 0 0 0 0 0 0 0 0 0 0 0 0
42624 - 0 0 0 6 6 6 6 6 6 10 10 10
42625 - 18 18 18 22 22 22 30 30 30 42 42 42
42626 - 50 50 50 66 66 66 86 86 86 101 98 89
42627 -106 86 58 98 70 6 104 69 6 104 69 6
42628 -104 69 6 91 60 6 82 62 34 90 90 90
42629 - 62 62 62 38 38 38 22 22 22 14 14 14
42630 - 10 10 10 10 10 10 10 10 10 10 10 10
42631 - 10 10 10 10 10 10 6 6 6 10 10 10
42632 - 10 10 10 10 10 10 10 10 10 14 14 14
42633 - 22 22 22 42 42 42 70 70 70 89 81 66
42634 - 80 54 7 104 69 6 124 80 6 137 92 6
42635 -134 86 6 116 81 8 100 82 52 86 86 86
42636 - 58 58 58 30 30 30 14 14 14 6 6 6
42637 - 0 0 0 0 0 0 0 0 0 0 0 0
42638 - 0 0 0 0 0 0 0 0 0 0 0 0
42639 - 0 0 0 0 0 0 0 0 0 0 0 0
42640 - 0 0 0 0 0 0 0 0 0 0 0 0
42641 - 0 0 0 0 0 0 0 0 0 0 0 0
42642 - 0 0 0 0 0 0 0 0 0 0 0 0
42643 - 0 0 0 0 0 0 0 0 0 0 0 0
42644 - 0 0 0 0 0 0 0 0 0 0 0 0
42645 - 0 0 0 6 6 6 10 10 10 14 14 14
42646 - 18 18 18 26 26 26 38 38 38 54 54 54
42647 - 70 70 70 86 86 86 94 86 76 89 81 66
42648 - 89 81 66 86 86 86 74 74 74 50 50 50
42649 - 30 30 30 14 14 14 6 6 6 0 0 0
42650 - 0 0 0 0 0 0 0 0 0 0 0 0
42651 - 0 0 0 0 0 0 0 0 0 0 0 0
42652 - 0 0 0 0 0 0 0 0 0 0 0 0
42653 - 6 6 6 18 18 18 34 34 34 58 58 58
42654 - 82 82 82 89 81 66 89 81 66 89 81 66
42655 - 94 86 66 94 86 76 74 74 74 50 50 50
42656 - 26 26 26 14 14 14 6 6 6 0 0 0
42657 - 0 0 0 0 0 0 0 0 0 0 0 0
42658 - 0 0 0 0 0 0 0 0 0 0 0 0
42659 - 0 0 0 0 0 0 0 0 0 0 0 0
42660 - 0 0 0 0 0 0 0 0 0 0 0 0
42661 - 0 0 0 0 0 0 0 0 0 0 0 0
42662 - 0 0 0 0 0 0 0 0 0 0 0 0
42663 - 0 0 0 0 0 0 0 0 0 0 0 0
42664 - 0 0 0 0 0 0 0 0 0 0 0 0
42665 - 0 0 0 0 0 0 0 0 0 0 0 0
42666 - 6 6 6 6 6 6 14 14 14 18 18 18
42667 - 30 30 30 38 38 38 46 46 46 54 54 54
42668 - 50 50 50 42 42 42 30 30 30 18 18 18
42669 - 10 10 10 0 0 0 0 0 0 0 0 0
42670 - 0 0 0 0 0 0 0 0 0 0 0 0
42671 - 0 0 0 0 0 0 0 0 0 0 0 0
42672 - 0 0 0 0 0 0 0 0 0 0 0 0
42673 - 0 0 0 6 6 6 14 14 14 26 26 26
42674 - 38 38 38 50 50 50 58 58 58 58 58 58
42675 - 54 54 54 42 42 42 30 30 30 18 18 18
42676 - 10 10 10 0 0 0 0 0 0 0 0 0
42677 - 0 0 0 0 0 0 0 0 0 0 0 0
42678 - 0 0 0 0 0 0 0 0 0 0 0 0
42679 - 0 0 0 0 0 0 0 0 0 0 0 0
42680 - 0 0 0 0 0 0 0 0 0 0 0 0
42681 - 0 0 0 0 0 0 0 0 0 0 0 0
42682 - 0 0 0 0 0 0 0 0 0 0 0 0
42683 - 0 0 0 0 0 0 0 0 0 0 0 0
42684 - 0 0 0 0 0 0 0 0 0 0 0 0
42685 - 0 0 0 0 0 0 0 0 0 0 0 0
42686 - 0 0 0 0 0 0 0 0 0 6 6 6
42687 - 6 6 6 10 10 10 14 14 14 18 18 18
42688 - 18 18 18 14 14 14 10 10 10 6 6 6
42689 - 0 0 0 0 0 0 0 0 0 0 0 0
42690 - 0 0 0 0 0 0 0 0 0 0 0 0
42691 - 0 0 0 0 0 0 0 0 0 0 0 0
42692 - 0 0 0 0 0 0 0 0 0 0 0 0
42693 - 0 0 0 0 0 0 0 0 0 6 6 6
42694 - 14 14 14 18 18 18 22 22 22 22 22 22
42695 - 18 18 18 14 14 14 10 10 10 6 6 6
42696 - 0 0 0 0 0 0 0 0 0 0 0 0
42697 - 0 0 0 0 0 0 0 0 0 0 0 0
42698 - 0 0 0 0 0 0 0 0 0 0 0 0
42699 - 0 0 0 0 0 0 0 0 0 0 0 0
42700 - 0 0 0 0 0 0 0 0 0 0 0 0
42701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42714 +4 4 4 4 4 4
42715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42728 +4 4 4 4 4 4
42729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42742 +4 4 4 4 4 4
42743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42756 +4 4 4 4 4 4
42757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42770 +4 4 4 4 4 4
42771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42784 +4 4 4 4 4 4
42785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42789 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
42790 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
42791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42794 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
42795 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42796 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
42797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42798 +4 4 4 4 4 4
42799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42803 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
42804 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
42805 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42808 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
42809 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
42810 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
42811 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42812 +4 4 4 4 4 4
42813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42817 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
42818 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
42819 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42822 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
42823 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
42824 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
42825 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
42826 +4 4 4 4 4 4
42827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42830 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
42831 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
42832 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
42833 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
42834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42835 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42836 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
42837 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
42838 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
42839 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
42840 +4 4 4 4 4 4
42841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42844 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
42845 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
42846 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
42847 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
42848 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42849 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
42850 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
42851 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
42852 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
42853 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
42854 +4 4 4 4 4 4
42855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42858 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
42859 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
42860 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
42861 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
42862 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42863 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
42864 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
42865 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
42866 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
42867 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
42868 +4 4 4 4 4 4
42869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42871 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
42872 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
42873 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
42874 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
42875 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
42876 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
42877 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
42878 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
42879 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
42880 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
42881 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
42882 +4 4 4 4 4 4
42883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42885 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
42886 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
42887 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
42888 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
42889 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
42890 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
42891 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
42892 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
42893 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
42894 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
42895 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
42896 +4 4 4 4 4 4
42897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42899 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
42900 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
42901 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
42902 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
42903 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
42904 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
42905 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
42906 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
42907 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
42908 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
42909 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42910 +4 4 4 4 4 4
42911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42913 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
42914 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
42915 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
42916 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
42917 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
42918 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
42919 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
42920 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
42921 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
42922 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
42923 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
42924 +4 4 4 4 4 4
42925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42926 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
42927 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
42928 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
42929 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
42930 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
42931 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
42932 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
42933 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
42934 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
42935 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
42936 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
42937 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
42938 +4 4 4 4 4 4
42939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42940 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
42941 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
42942 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
42943 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42944 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
42945 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
42946 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
42947 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
42948 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
42949 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
42950 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
42951 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
42952 +0 0 0 4 4 4
42953 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42954 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
42955 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
42956 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
42957 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
42958 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
42959 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
42960 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
42961 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
42962 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
42963 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
42964 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
42965 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
42966 +2 0 0 0 0 0
42967 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
42968 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
42969 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
42970 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
42971 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
42972 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
42973 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
42974 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
42975 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
42976 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
42977 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
42978 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
42979 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
42980 +37 38 37 0 0 0
42981 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42982 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
42983 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
42984 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
42985 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
42986 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
42987 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
42988 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
42989 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
42990 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
42991 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
42992 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
42993 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
42994 +85 115 134 4 0 0
42995 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
42996 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
42997 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
42998 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
42999 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43000 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43001 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43002 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43003 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43004 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43005 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43006 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43007 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43008 +60 73 81 4 0 0
43009 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43010 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43011 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43012 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43013 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43014 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43015 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43016 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43017 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43018 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43019 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43020 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43021 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43022 +16 19 21 4 0 0
43023 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43024 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43025 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43026 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43027 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43028 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43029 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43030 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43031 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43032 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43033 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43034 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43035 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43036 +4 0 0 4 3 3
43037 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43038 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43039 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43041 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43042 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43043 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43044 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43045 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43046 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43047 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43048 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43049 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43050 +3 2 2 4 4 4
43051 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43052 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43053 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43054 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43055 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43056 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43057 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43058 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43059 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43060 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43061 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43062 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43063 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43064 +4 4 4 4 4 4
43065 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43066 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43067 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43068 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43069 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43070 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43071 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43072 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43073 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43074 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43075 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43076 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43077 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43078 +4 4 4 4 4 4
43079 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43080 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43081 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43082 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43083 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43084 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43085 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43086 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43087 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43088 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43089 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43090 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43091 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43092 +5 5 5 5 5 5
43093 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43094 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43095 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43096 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43097 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43098 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43099 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43100 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43101 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43102 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43103 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43104 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43105 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43106 +5 5 5 4 4 4
43107 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43108 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43109 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43110 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43111 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43112 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43113 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43114 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43115 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43116 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43117 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43118 +4 0 0 4 0 0 5 5 5 5 5 5 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
43121 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43122 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43123 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43124 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43125 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43126 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43127 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43128 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43129 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43130 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43131 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43132 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43134 +4 4 4 4 4 4
43135 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43136 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43137 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43138 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43139 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43140 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43141 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43142 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43143 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43144 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43145 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43148 +4 4 4 4 4 4
43149 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43150 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43151 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43152 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43153 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43154 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43155 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43156 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43157 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43158 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43159 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43160 +4 4 4 4 4 4 4 4 4 4 4 4 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
43163 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43164 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43165 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43166 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43167 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43168 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43169 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43170 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43171 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43172 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43173 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43174 +4 4 4 4 4 4 4 4 4 4 4 4 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
43177 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43178 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43179 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43180 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43181 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43182 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43183 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43184 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43185 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43186 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43187 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43188 +4 4 4 4 4 4 4 4 4 4 4 4 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
43191 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43192 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43193 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43194 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43195 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43196 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43197 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43198 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43199 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43200 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43201 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43202 +4 4 4 4 4 4 4 4 4 4 4 4 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
43205 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43206 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43207 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43208 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43209 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43210 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43211 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43212 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43213 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43214 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43215 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43216 +4 4 4 4 4 4 4 4 4 4 4 4 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
43219 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43220 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43221 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43222 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43223 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43224 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43225 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43226 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43227 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43228 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43229 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43230 +4 4 4 4 4 4 4 4 4 4 4 4 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
43233 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43234 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43235 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43236 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43237 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43238 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43239 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43240 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43241 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43242 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43243 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43244 +4 4 4 4 4 4 4 4 4 4 4 4 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
43247 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43248 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43249 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43250 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43251 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43252 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43253 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43254 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43255 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43256 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43257 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43258 +4 4 4 4 4 4 4 4 4 4 4 4 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
43261 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43262 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43263 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43264 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43265 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43266 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43267 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43268 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43269 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43270 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43271 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43272 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
43275 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43276 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43277 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43278 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43279 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43280 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43281 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43282 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43283 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43284 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43285 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43288 +4 4 4 4 4 4
43289 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43290 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43291 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43292 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43293 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43294 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43295 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43296 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43297 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43298 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43299 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43302 +4 4 4 4 4 4
43303 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43304 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43305 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43306 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43307 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43308 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43309 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43310 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43311 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43312 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43313 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43316 +4 4 4 4 4 4
43317 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43318 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43319 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43320 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43321 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43322 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43323 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43324 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43325 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43326 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43327 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43330 +4 4 4 4 4 4
43331 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43332 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43333 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43334 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43335 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43336 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43337 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43338 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43339 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43340 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43341 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43344 +4 4 4 4 4 4
43345 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43346 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43347 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43348 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43349 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43350 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43351 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43352 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43353 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43354 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43355 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43358 +4 4 4 4 4 4
43359 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43360 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43361 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43362 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43363 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43364 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43365 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43366 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43367 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43368 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43369 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43372 +4 4 4 4 4 4
43373 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43374 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43375 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43376 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43377 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43378 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43379 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43380 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43381 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43382 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43383 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43386 +4 4 4 4 4 4
43387 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43388 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43389 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43390 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43391 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43392 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43393 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43394 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43395 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43396 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43397 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43400 +4 4 4 4 4 4
43401 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43402 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43403 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43404 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43405 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43406 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43407 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43408 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43409 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43410 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43411 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43414 +4 4 4 4 4 4
43415 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43416 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43417 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43418 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43419 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43420 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43421 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43422 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43423 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43424 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43425 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43428 +4 4 4 4 4 4
43429 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43430 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43431 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43432 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43433 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43434 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43435 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43436 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43437 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43438 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43439 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43442 +4 4 4 4 4 4
43443 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43444 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43445 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43446 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43447 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43448 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43449 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43450 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43451 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43452 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43453 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43456 +4 4 4 4 4 4
43457 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43458 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43459 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43460 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43461 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43462 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43463 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43464 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43465 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43466 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43467 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43470 +4 4 4 4 4 4
43471 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43472 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43473 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43474 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43475 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43476 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43477 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43478 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43479 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43480 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43481 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43484 +4 4 4 4 4 4
43485 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43486 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43487 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43488 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43489 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43490 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43491 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43492 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43493 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43494 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43495 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43498 +4 4 4 4 4 4
43499 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43500 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43501 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43502 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43503 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43504 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43505 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43506 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43507 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43508 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43509 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43512 +4 4 4 4 4 4
43513 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43514 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43515 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43516 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43517 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43518 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43519 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43520 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43521 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43522 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
43525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43526 +4 4 4 4 4 4
43527 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43528 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43529 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43530 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43531 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43532 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43533 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43534 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43535 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43536 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
43539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43540 +4 4 4 4 4 4
43541 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43542 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43543 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43544 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43545 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43546 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43547 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43548 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43549 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43550 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43554 +4 4 4 4 4 4
43555 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43556 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43557 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43558 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43559 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43560 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43561 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43562 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43563 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43564 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43568 +4 4 4 4 4 4
43569 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43570 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43571 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43572 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43573 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43574 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43575 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43576 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43577 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
43581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43582 +4 4 4 4 4 4
43583 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43584 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43585 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43586 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43587 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43588 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43589 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43590 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43591 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
43595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43596 +4 4 4 4 4 4
43597 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43598 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43599 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43600 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43601 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43602 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43603 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43604 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43605 +4 0 0 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43610 +4 4 4 4 4 4
43611 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43612 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43613 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43614 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43615 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43616 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43617 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43618 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43619 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43624 +4 4 4 4 4 4
43625 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43626 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43627 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43628 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43629 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43630 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43631 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43632 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43633 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43638 +4 4 4 4 4 4
43639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43640 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43641 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43642 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43643 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43644 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43645 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43646 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43647 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43652 +4 4 4 4 4 4
43653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43654 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43655 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43656 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43657 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43658 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43659 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43660 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43661 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43666 +4 4 4 4 4 4
43667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43668 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43669 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43670 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43671 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43672 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43673 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43674 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43675 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43680 +4 4 4 4 4 4
43681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43684 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43685 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43686 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43687 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43688 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43689 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43694 +4 4 4 4 4 4
43695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43698 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43699 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43700 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43701 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43703 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43708 +4 4 4 4 4 4
43709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43713 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43714 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43715 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43717 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43722 +4 4 4 4 4 4
43723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43727 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43728 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43729 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43731 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43736 +4 4 4 4 4 4
43737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43741 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43742 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43743 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43745 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43750 +4 4 4 4 4 4
43751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43755 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
43756 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43757 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43759 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764 +4 4 4 4 4 4
43765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43769 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
43770 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
43771 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43773 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778 +4 4 4 4 4 4
43779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43783 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
43784 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
43785 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43787 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792 +4 4 4 4 4 4
43793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43797 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
43798 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
43799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43801 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43806 +4 4 4 4 4 4
43807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43811 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43812 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
43813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43815 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43820 +4 4 4 4 4 4
43821 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
43822 index 86d449e..af6a7f7 100644
43823 --- a/drivers/video/udlfb.c
43824 +++ b/drivers/video/udlfb.c
43825 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
43826 dlfb_urb_completion(urb);
43827
43828 error:
43829 - atomic_add(bytes_sent, &dev->bytes_sent);
43830 - atomic_add(bytes_identical, &dev->bytes_identical);
43831 - atomic_add(width*height*2, &dev->bytes_rendered);
43832 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43833 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43834 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
43835 end_cycles = get_cycles();
43836 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43837 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43838 >> 10)), /* Kcycles */
43839 &dev->cpu_kcycles_used);
43840
43841 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
43842 dlfb_urb_completion(urb);
43843
43844 error:
43845 - atomic_add(bytes_sent, &dev->bytes_sent);
43846 - atomic_add(bytes_identical, &dev->bytes_identical);
43847 - atomic_add(bytes_rendered, &dev->bytes_rendered);
43848 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43849 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43850 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43851 end_cycles = get_cycles();
43852 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43853 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43854 >> 10)), /* Kcycles */
43855 &dev->cpu_kcycles_used);
43856 }
43857 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
43858 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43859 struct dlfb_data *dev = fb_info->par;
43860 return snprintf(buf, PAGE_SIZE, "%u\n",
43861 - atomic_read(&dev->bytes_rendered));
43862 + atomic_read_unchecked(&dev->bytes_rendered));
43863 }
43864
43865 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43866 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43867 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43868 struct dlfb_data *dev = fb_info->par;
43869 return snprintf(buf, PAGE_SIZE, "%u\n",
43870 - atomic_read(&dev->bytes_identical));
43871 + atomic_read_unchecked(&dev->bytes_identical));
43872 }
43873
43874 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43875 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43876 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43877 struct dlfb_data *dev = fb_info->par;
43878 return snprintf(buf, PAGE_SIZE, "%u\n",
43879 - atomic_read(&dev->bytes_sent));
43880 + atomic_read_unchecked(&dev->bytes_sent));
43881 }
43882
43883 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43884 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43885 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43886 struct dlfb_data *dev = fb_info->par;
43887 return snprintf(buf, PAGE_SIZE, "%u\n",
43888 - atomic_read(&dev->cpu_kcycles_used));
43889 + atomic_read_unchecked(&dev->cpu_kcycles_used));
43890 }
43891
43892 static ssize_t edid_show(
43893 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
43894 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43895 struct dlfb_data *dev = fb_info->par;
43896
43897 - atomic_set(&dev->bytes_rendered, 0);
43898 - atomic_set(&dev->bytes_identical, 0);
43899 - atomic_set(&dev->bytes_sent, 0);
43900 - atomic_set(&dev->cpu_kcycles_used, 0);
43901 + atomic_set_unchecked(&dev->bytes_rendered, 0);
43902 + atomic_set_unchecked(&dev->bytes_identical, 0);
43903 + atomic_set_unchecked(&dev->bytes_sent, 0);
43904 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43905
43906 return count;
43907 }
43908 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
43909 index 2f8f82d..191de37 100644
43910 --- a/drivers/video/uvesafb.c
43911 +++ b/drivers/video/uvesafb.c
43912 @@ -19,6 +19,7 @@
43913 #include <linux/io.h>
43914 #include <linux/mutex.h>
43915 #include <linux/slab.h>
43916 +#include <linux/moduleloader.h>
43917 #include <video/edid.h>
43918 #include <video/uvesafb.h>
43919 #ifdef CONFIG_X86
43920 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
43921 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43922 par->pmi_setpal = par->ypan = 0;
43923 } else {
43924 +
43925 +#ifdef CONFIG_PAX_KERNEXEC
43926 +#ifdef CONFIG_MODULES
43927 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43928 +#endif
43929 + if (!par->pmi_code) {
43930 + par->pmi_setpal = par->ypan = 0;
43931 + return 0;
43932 + }
43933 +#endif
43934 +
43935 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43936 + task->t.regs.edi);
43937 +
43938 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43939 + pax_open_kernel();
43940 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43941 + pax_close_kernel();
43942 +
43943 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43944 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43945 +#else
43946 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43947 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43948 +#endif
43949 +
43950 printk(KERN_INFO "uvesafb: protected mode interface info at "
43951 "%04x:%04x\n",
43952 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43953 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
43954 par->ypan = ypan;
43955
43956 if (par->pmi_setpal || par->ypan) {
43957 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
43958 if (__supported_pte_mask & _PAGE_NX) {
43959 par->pmi_setpal = par->ypan = 0;
43960 printk(KERN_WARNING "uvesafb: NX protection is actively."
43961 "We have better not to use the PMI.\n");
43962 - } else {
43963 + } else
43964 +#endif
43965 uvesafb_vbe_getpmi(task, par);
43966 - }
43967 }
43968 #else
43969 /* The protected mode interface is not available on non-x86. */
43970 @@ -1838,6 +1862,11 @@ out:
43971 if (par->vbe_modes)
43972 kfree(par->vbe_modes);
43973
43974 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43975 + if (par->pmi_code)
43976 + module_free_exec(NULL, par->pmi_code);
43977 +#endif
43978 +
43979 framebuffer_release(info);
43980 return err;
43981 }
43982 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
43983 kfree(par->vbe_state_orig);
43984 if (par->vbe_state_saved)
43985 kfree(par->vbe_state_saved);
43986 +
43987 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43988 + if (par->pmi_code)
43989 + module_free_exec(NULL, par->pmi_code);
43990 +#endif
43991 +
43992 }
43993
43994 framebuffer_release(info);
43995 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
43996 index 501b340..86bd4cf 100644
43997 --- a/drivers/video/vesafb.c
43998 +++ b/drivers/video/vesafb.c
43999 @@ -9,6 +9,7 @@
44000 */
44001
44002 #include <linux/module.h>
44003 +#include <linux/moduleloader.h>
44004 #include <linux/kernel.h>
44005 #include <linux/errno.h>
44006 #include <linux/string.h>
44007 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44008 static int vram_total __initdata; /* Set total amount of memory */
44009 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44010 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44011 -static void (*pmi_start)(void) __read_mostly;
44012 -static void (*pmi_pal) (void) __read_mostly;
44013 +static void (*pmi_start)(void) __read_only;
44014 +static void (*pmi_pal) (void) __read_only;
44015 static int depth __read_mostly;
44016 static int vga_compat __read_mostly;
44017 /* --------------------------------------------------------------------- */
44018 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44019 unsigned int size_vmode;
44020 unsigned int size_remap;
44021 unsigned int size_total;
44022 + void *pmi_code = NULL;
44023
44024 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44025 return -ENODEV;
44026 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44027 size_remap = size_total;
44028 vesafb_fix.smem_len = size_remap;
44029
44030 -#ifndef __i386__
44031 - screen_info.vesapm_seg = 0;
44032 -#endif
44033 -
44034 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44035 printk(KERN_WARNING
44036 "vesafb: cannot reserve video memory at 0x%lx\n",
44037 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44038 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44039 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44040
44041 +#ifdef __i386__
44042 +
44043 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44044 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
44045 + if (!pmi_code)
44046 +#elif !defined(CONFIG_PAX_KERNEXEC)
44047 + if (0)
44048 +#endif
44049 +
44050 +#endif
44051 + screen_info.vesapm_seg = 0;
44052 +
44053 if (screen_info.vesapm_seg) {
44054 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44055 - screen_info.vesapm_seg,screen_info.vesapm_off);
44056 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44057 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44058 }
44059
44060 if (screen_info.vesapm_seg < 0xc000)
44061 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44062
44063 if (ypan || pmi_setpal) {
44064 unsigned short *pmi_base;
44065 +
44066 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44067 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44068 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44069 +
44070 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44071 + pax_open_kernel();
44072 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44073 +#else
44074 + pmi_code = pmi_base;
44075 +#endif
44076 +
44077 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44078 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44079 +
44080 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44081 + pmi_start = ktva_ktla(pmi_start);
44082 + pmi_pal = ktva_ktla(pmi_pal);
44083 + pax_close_kernel();
44084 +#endif
44085 +
44086 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44087 if (pmi_base[3]) {
44088 printk(KERN_INFO "vesafb: pmi: ports = ");
44089 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44090 info->node, info->fix.id);
44091 return 0;
44092 err:
44093 +
44094 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44095 + module_free_exec(NULL, pmi_code);
44096 +#endif
44097 +
44098 if (info->screen_base)
44099 iounmap(info->screen_base);
44100 framebuffer_release(info);
44101 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44102 index 88714ae..16c2e11 100644
44103 --- a/drivers/video/via/via_clock.h
44104 +++ b/drivers/video/via/via_clock.h
44105 @@ -56,7 +56,7 @@ struct via_clock {
44106
44107 void (*set_engine_pll_state)(u8 state);
44108 void (*set_engine_pll)(struct via_pll_config config);
44109 -};
44110 +} __no_const;
44111
44112
44113 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44114 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44115 index 6b1b7e1..b2fa4d5 100644
44116 --- a/drivers/virtio/virtio_mmio.c
44117 +++ b/drivers/virtio/virtio_mmio.c
44118 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44119
44120 resources[0].end = memparse(device, &str) - 1;
44121
44122 - processed = sscanf(str, "@%lli:%u%n:%d%n",
44123 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
44124 &base, &resources[1].start, &consumed,
44125 &vm_cmdline_id, &consumed);
44126
44127 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44128 index fef20db..d28b1ab 100644
44129 --- a/drivers/xen/xenfs/xenstored.c
44130 +++ b/drivers/xen/xenfs/xenstored.c
44131 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44132 static int xsd_kva_open(struct inode *inode, struct file *file)
44133 {
44134 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44135 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44136 + NULL);
44137 +#else
44138 xen_store_interface);
44139 +#endif
44140 +
44141 if (!file->private_data)
44142 return -ENOMEM;
44143 return 0;
44144 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44145 index 890bed5..17ae73e 100644
44146 --- a/fs/9p/vfs_inode.c
44147 +++ b/fs/9p/vfs_inode.c
44148 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44149 void
44150 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44151 {
44152 - char *s = nd_get_link(nd);
44153 + const char *s = nd_get_link(nd);
44154
44155 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44156 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44157 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44158 index 0efd152..b5802ad 100644
44159 --- a/fs/Kconfig.binfmt
44160 +++ b/fs/Kconfig.binfmt
44161 @@ -89,7 +89,7 @@ config HAVE_AOUT
44162
44163 config BINFMT_AOUT
44164 tristate "Kernel support for a.out and ECOFF binaries"
44165 - depends on HAVE_AOUT
44166 + depends on HAVE_AOUT && BROKEN
44167 ---help---
44168 A.out (Assembler.OUTput) is a set of formats for libraries and
44169 executables used in the earliest versions of UNIX. Linux used
44170 diff --git a/fs/aio.c b/fs/aio.c
44171 index 71f613c..9d01f1f 100644
44172 --- a/fs/aio.c
44173 +++ b/fs/aio.c
44174 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44175 size += sizeof(struct io_event) * nr_events;
44176 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44177
44178 - if (nr_pages < 0)
44179 + if (nr_pages <= 0)
44180 return -EINVAL;
44181
44182 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44183 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44184 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44185 {
44186 ssize_t ret;
44187 + struct iovec iovstack;
44188
44189 #ifdef CONFIG_COMPAT
44190 if (compat)
44191 ret = compat_rw_copy_check_uvector(type,
44192 (struct compat_iovec __user *)kiocb->ki_buf,
44193 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44194 + kiocb->ki_nbytes, 1, &iovstack,
44195 &kiocb->ki_iovec);
44196 else
44197 #endif
44198 ret = rw_copy_check_uvector(type,
44199 (struct iovec __user *)kiocb->ki_buf,
44200 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44201 + kiocb->ki_nbytes, 1, &iovstack,
44202 &kiocb->ki_iovec);
44203 if (ret < 0)
44204 goto out;
44205 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44206 if (ret < 0)
44207 goto out;
44208
44209 + if (kiocb->ki_iovec == &iovstack) {
44210 + kiocb->ki_inline_vec = iovstack;
44211 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
44212 + }
44213 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44214 kiocb->ki_cur_seg = 0;
44215 /* ki_nbytes/left now reflect bytes instead of segs */
44216 diff --git a/fs/attr.c b/fs/attr.c
44217 index cce7df5..eaa2731 100644
44218 --- a/fs/attr.c
44219 +++ b/fs/attr.c
44220 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44221 unsigned long limit;
44222
44223 limit = rlimit(RLIMIT_FSIZE);
44224 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44225 if (limit != RLIM_INFINITY && offset > limit)
44226 goto out_sig;
44227 if (offset > inode->i_sb->s_maxbytes)
44228 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44229 index dce436e..55e670d 100644
44230 --- a/fs/autofs4/waitq.c
44231 +++ b/fs/autofs4/waitq.c
44232 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44233 {
44234 unsigned long sigpipe, flags;
44235 mm_segment_t fs;
44236 - const char *data = (const char *)addr;
44237 + const char __user *data = (const char __force_user *)addr;
44238 ssize_t wr = 0;
44239
44240 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44241 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44242 return 1;
44243 }
44244
44245 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44246 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44247 +#endif
44248 +
44249 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44250 enum autofs_notify notify)
44251 {
44252 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44253
44254 /* If this is a direct mount request create a dummy name */
44255 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44256 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44257 + /* this name does get written to userland via autofs4_write() */
44258 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44259 +#else
44260 qstr.len = sprintf(name, "%p", dentry);
44261 +#endif
44262 else {
44263 qstr.len = autofs4_getpath(sbi, dentry, &name);
44264 if (!qstr.len) {
44265 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44266 index 2b3bda8..6a2d4be 100644
44267 --- a/fs/befs/linuxvfs.c
44268 +++ b/fs/befs/linuxvfs.c
44269 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44270 {
44271 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44272 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44273 - char *link = nd_get_link(nd);
44274 + const char *link = nd_get_link(nd);
44275 if (!IS_ERR(link))
44276 kfree(link);
44277 }
44278 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44279 index 0e7a6f8..332b1ca 100644
44280 --- a/fs/binfmt_aout.c
44281 +++ b/fs/binfmt_aout.c
44282 @@ -16,6 +16,7 @@
44283 #include <linux/string.h>
44284 #include <linux/fs.h>
44285 #include <linux/file.h>
44286 +#include <linux/security.h>
44287 #include <linux/stat.h>
44288 #include <linux/fcntl.h>
44289 #include <linux/ptrace.h>
44290 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44291 #endif
44292 # define START_STACK(u) ((void __user *)u.start_stack)
44293
44294 + memset(&dump, 0, sizeof(dump));
44295 +
44296 fs = get_fs();
44297 set_fs(KERNEL_DS);
44298 has_dumped = 1;
44299 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44300
44301 /* If the size of the dump file exceeds the rlimit, then see what would happen
44302 if we wrote the stack, but not the data area. */
44303 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44304 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44305 dump.u_dsize = 0;
44306
44307 /* Make sure we have enough room to write the stack and data areas. */
44308 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44309 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44310 dump.u_ssize = 0;
44311
44312 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44313 rlim = rlimit(RLIMIT_DATA);
44314 if (rlim >= RLIM_INFINITY)
44315 rlim = ~0;
44316 +
44317 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44318 if (ex.a_data + ex.a_bss > rlim)
44319 return -ENOMEM;
44320
44321 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44322
44323 install_exec_creds(bprm);
44324
44325 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44326 + current->mm->pax_flags = 0UL;
44327 +#endif
44328 +
44329 +#ifdef CONFIG_PAX_PAGEEXEC
44330 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44331 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44332 +
44333 +#ifdef CONFIG_PAX_EMUTRAMP
44334 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44335 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44336 +#endif
44337 +
44338 +#ifdef CONFIG_PAX_MPROTECT
44339 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44340 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44341 +#endif
44342 +
44343 + }
44344 +#endif
44345 +
44346 if (N_MAGIC(ex) == OMAGIC) {
44347 unsigned long text_addr, map_size;
44348 loff_t pos;
44349 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44350 }
44351
44352 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44353 - PROT_READ | PROT_WRITE | PROT_EXEC,
44354 + PROT_READ | PROT_WRITE,
44355 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44356 fd_offset + ex.a_text);
44357 if (error != N_DATADDR(ex)) {
44358 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44359 index fbd9f60..0b845dd 100644
44360 --- a/fs/binfmt_elf.c
44361 +++ b/fs/binfmt_elf.c
44362 @@ -33,6 +33,7 @@
44363 #include <linux/elf.h>
44364 #include <linux/utsname.h>
44365 #include <linux/coredump.h>
44366 +#include <linux/xattr.h>
44367 #include <asm/uaccess.h>
44368 #include <asm/param.h>
44369 #include <asm/page.h>
44370 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44371 #define elf_core_dump NULL
44372 #endif
44373
44374 +#ifdef CONFIG_PAX_MPROTECT
44375 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44376 +#endif
44377 +
44378 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44379 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44380 #else
44381 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44382 .load_binary = load_elf_binary,
44383 .load_shlib = load_elf_library,
44384 .core_dump = elf_core_dump,
44385 +
44386 +#ifdef CONFIG_PAX_MPROTECT
44387 + .handle_mprotect= elf_handle_mprotect,
44388 +#endif
44389 +
44390 .min_coredump = ELF_EXEC_PAGESIZE,
44391 };
44392
44393 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44394
44395 static int set_brk(unsigned long start, unsigned long end)
44396 {
44397 + unsigned long e = end;
44398 +
44399 start = ELF_PAGEALIGN(start);
44400 end = ELF_PAGEALIGN(end);
44401 if (end > start) {
44402 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44403 if (BAD_ADDR(addr))
44404 return addr;
44405 }
44406 - current->mm->start_brk = current->mm->brk = end;
44407 + current->mm->start_brk = current->mm->brk = e;
44408 return 0;
44409 }
44410
44411 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44412 elf_addr_t __user *u_rand_bytes;
44413 const char *k_platform = ELF_PLATFORM;
44414 const char *k_base_platform = ELF_BASE_PLATFORM;
44415 - unsigned char k_rand_bytes[16];
44416 + u32 k_rand_bytes[4];
44417 int items;
44418 elf_addr_t *elf_info;
44419 int ei_index = 0;
44420 const struct cred *cred = current_cred();
44421 struct vm_area_struct *vma;
44422 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44423
44424 /*
44425 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44426 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44427 * Generate 16 random bytes for userspace PRNG seeding.
44428 */
44429 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44430 - u_rand_bytes = (elf_addr_t __user *)
44431 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44432 + srandom32(k_rand_bytes[0] ^ random32());
44433 + srandom32(k_rand_bytes[1] ^ random32());
44434 + srandom32(k_rand_bytes[2] ^ random32());
44435 + srandom32(k_rand_bytes[3] ^ random32());
44436 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44437 + u_rand_bytes = (elf_addr_t __user *) p;
44438 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44439 return -EFAULT;
44440
44441 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44442 return -EFAULT;
44443 current->mm->env_end = p;
44444
44445 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44446 +
44447 /* Put the elf_info on the stack in the right place. */
44448 sp = (elf_addr_t __user *)envp + 1;
44449 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44450 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44451 return -EFAULT;
44452 return 0;
44453 }
44454 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44455 an ELF header */
44456
44457 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44458 - struct file *interpreter, unsigned long *interp_map_addr,
44459 - unsigned long no_base)
44460 + struct file *interpreter, unsigned long no_base)
44461 {
44462 struct elf_phdr *elf_phdata;
44463 struct elf_phdr *eppnt;
44464 - unsigned long load_addr = 0;
44465 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44466 int load_addr_set = 0;
44467 unsigned long last_bss = 0, elf_bss = 0;
44468 - unsigned long error = ~0UL;
44469 + unsigned long error = -EINVAL;
44470 unsigned long total_size;
44471 int retval, i, size;
44472
44473 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44474 goto out_close;
44475 }
44476
44477 +#ifdef CONFIG_PAX_SEGMEXEC
44478 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44479 + pax_task_size = SEGMEXEC_TASK_SIZE;
44480 +#endif
44481 +
44482 eppnt = elf_phdata;
44483 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44484 if (eppnt->p_type == PT_LOAD) {
44485 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44486 map_addr = elf_map(interpreter, load_addr + vaddr,
44487 eppnt, elf_prot, elf_type, total_size);
44488 total_size = 0;
44489 - if (!*interp_map_addr)
44490 - *interp_map_addr = map_addr;
44491 error = map_addr;
44492 if (BAD_ADDR(map_addr))
44493 goto out_close;
44494 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44495 k = load_addr + eppnt->p_vaddr;
44496 if (BAD_ADDR(k) ||
44497 eppnt->p_filesz > eppnt->p_memsz ||
44498 - eppnt->p_memsz > TASK_SIZE ||
44499 - TASK_SIZE - eppnt->p_memsz < k) {
44500 + eppnt->p_memsz > pax_task_size ||
44501 + pax_task_size - eppnt->p_memsz < k) {
44502 error = -ENOMEM;
44503 goto out_close;
44504 }
44505 @@ -530,6 +551,315 @@ out:
44506 return error;
44507 }
44508
44509 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44510 +#ifdef CONFIG_PAX_SOFTMODE
44511 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44512 +{
44513 + unsigned long pax_flags = 0UL;
44514 +
44515 +#ifdef CONFIG_PAX_PAGEEXEC
44516 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44517 + pax_flags |= MF_PAX_PAGEEXEC;
44518 +#endif
44519 +
44520 +#ifdef CONFIG_PAX_SEGMEXEC
44521 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44522 + pax_flags |= MF_PAX_SEGMEXEC;
44523 +#endif
44524 +
44525 +#ifdef CONFIG_PAX_EMUTRAMP
44526 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44527 + pax_flags |= MF_PAX_EMUTRAMP;
44528 +#endif
44529 +
44530 +#ifdef CONFIG_PAX_MPROTECT
44531 + if (elf_phdata->p_flags & PF_MPROTECT)
44532 + pax_flags |= MF_PAX_MPROTECT;
44533 +#endif
44534 +
44535 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44536 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44537 + pax_flags |= MF_PAX_RANDMMAP;
44538 +#endif
44539 +
44540 + return pax_flags;
44541 +}
44542 +#endif
44543 +
44544 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44545 +{
44546 + unsigned long pax_flags = 0UL;
44547 +
44548 +#ifdef CONFIG_PAX_PAGEEXEC
44549 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44550 + pax_flags |= MF_PAX_PAGEEXEC;
44551 +#endif
44552 +
44553 +#ifdef CONFIG_PAX_SEGMEXEC
44554 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44555 + pax_flags |= MF_PAX_SEGMEXEC;
44556 +#endif
44557 +
44558 +#ifdef CONFIG_PAX_EMUTRAMP
44559 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44560 + pax_flags |= MF_PAX_EMUTRAMP;
44561 +#endif
44562 +
44563 +#ifdef CONFIG_PAX_MPROTECT
44564 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44565 + pax_flags |= MF_PAX_MPROTECT;
44566 +#endif
44567 +
44568 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44569 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44570 + pax_flags |= MF_PAX_RANDMMAP;
44571 +#endif
44572 +
44573 + return pax_flags;
44574 +}
44575 +#endif
44576 +
44577 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44578 +#ifdef CONFIG_PAX_SOFTMODE
44579 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44580 +{
44581 + unsigned long pax_flags = 0UL;
44582 +
44583 +#ifdef CONFIG_PAX_PAGEEXEC
44584 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44585 + pax_flags |= MF_PAX_PAGEEXEC;
44586 +#endif
44587 +
44588 +#ifdef CONFIG_PAX_SEGMEXEC
44589 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44590 + pax_flags |= MF_PAX_SEGMEXEC;
44591 +#endif
44592 +
44593 +#ifdef CONFIG_PAX_EMUTRAMP
44594 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44595 + pax_flags |= MF_PAX_EMUTRAMP;
44596 +#endif
44597 +
44598 +#ifdef CONFIG_PAX_MPROTECT
44599 + if (pax_flags_softmode & MF_PAX_MPROTECT)
44600 + pax_flags |= MF_PAX_MPROTECT;
44601 +#endif
44602 +
44603 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44604 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44605 + pax_flags |= MF_PAX_RANDMMAP;
44606 +#endif
44607 +
44608 + return pax_flags;
44609 +}
44610 +#endif
44611 +
44612 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44613 +{
44614 + unsigned long pax_flags = 0UL;
44615 +
44616 +#ifdef CONFIG_PAX_PAGEEXEC
44617 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44618 + pax_flags |= MF_PAX_PAGEEXEC;
44619 +#endif
44620 +
44621 +#ifdef CONFIG_PAX_SEGMEXEC
44622 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44623 + pax_flags |= MF_PAX_SEGMEXEC;
44624 +#endif
44625 +
44626 +#ifdef CONFIG_PAX_EMUTRAMP
44627 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44628 + pax_flags |= MF_PAX_EMUTRAMP;
44629 +#endif
44630 +
44631 +#ifdef CONFIG_PAX_MPROTECT
44632 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44633 + pax_flags |= MF_PAX_MPROTECT;
44634 +#endif
44635 +
44636 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44637 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44638 + pax_flags |= MF_PAX_RANDMMAP;
44639 +#endif
44640 +
44641 + return pax_flags;
44642 +}
44643 +#endif
44644 +
44645 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44646 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44647 +{
44648 + unsigned long pax_flags = 0UL;
44649 +
44650 +#ifdef CONFIG_PAX_EI_PAX
44651 +
44652 +#ifdef CONFIG_PAX_PAGEEXEC
44653 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44654 + pax_flags |= MF_PAX_PAGEEXEC;
44655 +#endif
44656 +
44657 +#ifdef CONFIG_PAX_SEGMEXEC
44658 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44659 + pax_flags |= MF_PAX_SEGMEXEC;
44660 +#endif
44661 +
44662 +#ifdef CONFIG_PAX_EMUTRAMP
44663 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44664 + pax_flags |= MF_PAX_EMUTRAMP;
44665 +#endif
44666 +
44667 +#ifdef CONFIG_PAX_MPROTECT
44668 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44669 + pax_flags |= MF_PAX_MPROTECT;
44670 +#endif
44671 +
44672 +#ifdef CONFIG_PAX_ASLR
44673 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44674 + pax_flags |= MF_PAX_RANDMMAP;
44675 +#endif
44676 +
44677 +#else
44678 +
44679 +#ifdef CONFIG_PAX_PAGEEXEC
44680 + pax_flags |= MF_PAX_PAGEEXEC;
44681 +#endif
44682 +
44683 +#ifdef CONFIG_PAX_SEGMEXEC
44684 + pax_flags |= MF_PAX_SEGMEXEC;
44685 +#endif
44686 +
44687 +#ifdef CONFIG_PAX_MPROTECT
44688 + pax_flags |= MF_PAX_MPROTECT;
44689 +#endif
44690 +
44691 +#ifdef CONFIG_PAX_RANDMMAP
44692 + if (randomize_va_space)
44693 + pax_flags |= MF_PAX_RANDMMAP;
44694 +#endif
44695 +
44696 +#endif
44697 +
44698 + return pax_flags;
44699 +}
44700 +
44701 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44702 +{
44703 +
44704 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44705 + unsigned long i;
44706 +
44707 + for (i = 0UL; i < elf_ex->e_phnum; i++)
44708 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44709 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44710 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44711 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44712 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44713 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44714 + return ~0UL;
44715 +
44716 +#ifdef CONFIG_PAX_SOFTMODE
44717 + if (pax_softmode)
44718 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44719 + else
44720 +#endif
44721 +
44722 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44723 + break;
44724 + }
44725 +#endif
44726 +
44727 + return ~0UL;
44728 +}
44729 +
44730 +static unsigned long pax_parse_xattr_pax(struct file * const file)
44731 +{
44732 +
44733 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44734 + ssize_t xattr_size, i;
44735 + unsigned char xattr_value[5];
44736 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44737 +
44738 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44739 + if (xattr_size <= 0 || xattr_size > 5)
44740 + return ~0UL;
44741 +
44742 + for (i = 0; i < xattr_size; i++)
44743 + switch (xattr_value[i]) {
44744 + default:
44745 + return ~0UL;
44746 +
44747 +#define parse_flag(option1, option2, flag) \
44748 + case option1: \
44749 + if (pax_flags_hardmode & MF_PAX_##flag) \
44750 + return ~0UL; \
44751 + pax_flags_hardmode |= MF_PAX_##flag; \
44752 + break; \
44753 + case option2: \
44754 + if (pax_flags_softmode & MF_PAX_##flag) \
44755 + return ~0UL; \
44756 + pax_flags_softmode |= MF_PAX_##flag; \
44757 + break;
44758 +
44759 + parse_flag('p', 'P', PAGEEXEC);
44760 + parse_flag('e', 'E', EMUTRAMP);
44761 + parse_flag('m', 'M', MPROTECT);
44762 + parse_flag('r', 'R', RANDMMAP);
44763 + parse_flag('s', 'S', SEGMEXEC);
44764 +
44765 +#undef parse_flag
44766 + }
44767 +
44768 + if (pax_flags_hardmode & pax_flags_softmode)
44769 + return ~0UL;
44770 +
44771 +#ifdef CONFIG_PAX_SOFTMODE
44772 + if (pax_softmode)
44773 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
44774 + else
44775 +#endif
44776 +
44777 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
44778 +#else
44779 + return ~0UL;
44780 +#endif
44781 +
44782 +}
44783 +
44784 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
44785 +{
44786 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
44787 +
44788 + pax_flags = pax_parse_ei_pax(elf_ex);
44789 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
44790 + xattr_pax_flags = pax_parse_xattr_pax(file);
44791 +
44792 + if (pt_pax_flags == ~0UL)
44793 + pt_pax_flags = xattr_pax_flags;
44794 + else if (xattr_pax_flags == ~0UL)
44795 + xattr_pax_flags = pt_pax_flags;
44796 + if (pt_pax_flags != xattr_pax_flags)
44797 + return -EINVAL;
44798 + if (pt_pax_flags != ~0UL)
44799 + pax_flags = pt_pax_flags;
44800 +
44801 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
44802 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44803 + if ((__supported_pte_mask & _PAGE_NX))
44804 + pax_flags &= ~MF_PAX_SEGMEXEC;
44805 + else
44806 + pax_flags &= ~MF_PAX_PAGEEXEC;
44807 + }
44808 +#endif
44809 +
44810 + if (0 > pax_check_flags(&pax_flags))
44811 + return -EINVAL;
44812 +
44813 + current->mm->pax_flags = pax_flags;
44814 + return 0;
44815 +}
44816 +#endif
44817 +
44818 /*
44819 * These are the functions used to load ELF style executables and shared
44820 * libraries. There is no binary dependent code anywhere else.
44821 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
44822 {
44823 unsigned int random_variable = 0;
44824
44825 +#ifdef CONFIG_PAX_RANDUSTACK
44826 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
44827 + return stack_top - current->mm->delta_stack;
44828 +#endif
44829 +
44830 if ((current->flags & PF_RANDOMIZE) &&
44831 !(current->personality & ADDR_NO_RANDOMIZE)) {
44832 random_variable = get_random_int() & STACK_RND_MASK;
44833 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44834 unsigned long load_addr = 0, load_bias = 0;
44835 int load_addr_set = 0;
44836 char * elf_interpreter = NULL;
44837 - unsigned long error;
44838 + unsigned long error = 0;
44839 struct elf_phdr *elf_ppnt, *elf_phdata;
44840 unsigned long elf_bss, elf_brk;
44841 int retval, i;
44842 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44843 unsigned long start_code, end_code, start_data, end_data;
44844 unsigned long reloc_func_desc __maybe_unused = 0;
44845 int executable_stack = EXSTACK_DEFAULT;
44846 - unsigned long def_flags = 0;
44847 struct {
44848 struct elfhdr elf_ex;
44849 struct elfhdr interp_elf_ex;
44850 } *loc;
44851 + unsigned long pax_task_size = TASK_SIZE;
44852
44853 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
44854 if (!loc) {
44855 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44856 goto out_free_dentry;
44857
44858 /* OK, This is the point of no return */
44859 - current->mm->def_flags = def_flags;
44860 +
44861 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44862 + current->mm->pax_flags = 0UL;
44863 +#endif
44864 +
44865 +#ifdef CONFIG_PAX_DLRESOLVE
44866 + current->mm->call_dl_resolve = 0UL;
44867 +#endif
44868 +
44869 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
44870 + current->mm->call_syscall = 0UL;
44871 +#endif
44872 +
44873 +#ifdef CONFIG_PAX_ASLR
44874 + current->mm->delta_mmap = 0UL;
44875 + current->mm->delta_stack = 0UL;
44876 +#endif
44877 +
44878 + current->mm->def_flags = 0;
44879 +
44880 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44881 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
44882 + send_sig(SIGKILL, current, 0);
44883 + goto out_free_dentry;
44884 + }
44885 +#endif
44886 +
44887 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44888 + pax_set_initial_flags(bprm);
44889 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
44890 + if (pax_set_initial_flags_func)
44891 + (pax_set_initial_flags_func)(bprm);
44892 +#endif
44893 +
44894 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
44895 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
44896 + current->mm->context.user_cs_limit = PAGE_SIZE;
44897 + current->mm->def_flags |= VM_PAGEEXEC;
44898 + }
44899 +#endif
44900 +
44901 +#ifdef CONFIG_PAX_SEGMEXEC
44902 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
44903 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
44904 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
44905 + pax_task_size = SEGMEXEC_TASK_SIZE;
44906 + current->mm->def_flags |= VM_NOHUGEPAGE;
44907 + }
44908 +#endif
44909 +
44910 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
44911 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44912 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
44913 + put_cpu();
44914 + }
44915 +#endif
44916
44917 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
44918 may depend on the personality. */
44919 SET_PERSONALITY(loc->elf_ex);
44920 +
44921 +#ifdef CONFIG_PAX_ASLR
44922 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44923 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
44924 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
44925 + }
44926 +#endif
44927 +
44928 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44929 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44930 + executable_stack = EXSTACK_DISABLE_X;
44931 + current->personality &= ~READ_IMPLIES_EXEC;
44932 + } else
44933 +#endif
44934 +
44935 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
44936 current->personality |= READ_IMPLIES_EXEC;
44937
44938 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44939 #else
44940 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
44941 #endif
44942 +
44943 +#ifdef CONFIG_PAX_RANDMMAP
44944 + /* PaX: randomize base address at the default exe base if requested */
44945 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
44946 +#ifdef CONFIG_SPARC64
44947 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
44948 +#else
44949 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
44950 +#endif
44951 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
44952 + elf_flags |= MAP_FIXED;
44953 + }
44954 +#endif
44955 +
44956 }
44957
44958 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
44959 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44960 * allowed task size. Note that p_filesz must always be
44961 * <= p_memsz so it is only necessary to check p_memsz.
44962 */
44963 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44964 - elf_ppnt->p_memsz > TASK_SIZE ||
44965 - TASK_SIZE - elf_ppnt->p_memsz < k) {
44966 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44967 + elf_ppnt->p_memsz > pax_task_size ||
44968 + pax_task_size - elf_ppnt->p_memsz < k) {
44969 /* set_brk can never work. Avoid overflows. */
44970 send_sig(SIGKILL, current, 0);
44971 retval = -EINVAL;
44972 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44973 goto out_free_dentry;
44974 }
44975 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
44976 - send_sig(SIGSEGV, current, 0);
44977 - retval = -EFAULT; /* Nobody gets to see this, but.. */
44978 - goto out_free_dentry;
44979 + /*
44980 + * This bss-zeroing can fail if the ELF
44981 + * file specifies odd protections. So
44982 + * we don't check the return value
44983 + */
44984 }
44985
44986 +#ifdef CONFIG_PAX_RANDMMAP
44987 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44988 + unsigned long start, size;
44989 +
44990 + start = ELF_PAGEALIGN(elf_brk);
44991 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
44992 + down_read(&current->mm->mmap_sem);
44993 + retval = -ENOMEM;
44994 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
44995 + unsigned long prot = PROT_NONE;
44996 +
44997 + up_read(&current->mm->mmap_sem);
44998 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
44999 +// if (current->personality & ADDR_NO_RANDOMIZE)
45000 +// prot = PROT_READ;
45001 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45002 + retval = IS_ERR_VALUE(start) ? start : 0;
45003 + } else
45004 + up_read(&current->mm->mmap_sem);
45005 + if (retval == 0)
45006 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45007 + if (retval < 0) {
45008 + send_sig(SIGKILL, current, 0);
45009 + goto out_free_dentry;
45010 + }
45011 + }
45012 +#endif
45013 +
45014 if (elf_interpreter) {
45015 - unsigned long interp_map_addr = 0;
45016 -
45017 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45018 interpreter,
45019 - &interp_map_addr,
45020 load_bias);
45021 if (!IS_ERR((void *)elf_entry)) {
45022 /*
45023 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45024 * Decide what to dump of a segment, part, all or none.
45025 */
45026 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45027 - unsigned long mm_flags)
45028 + unsigned long mm_flags, long signr)
45029 {
45030 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45031
45032 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45033 if (vma->vm_file == NULL)
45034 return 0;
45035
45036 - if (FILTER(MAPPED_PRIVATE))
45037 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45038 goto whole;
45039
45040 /*
45041 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45042 {
45043 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45044 int i = 0;
45045 - do
45046 + do {
45047 i += 2;
45048 - while (auxv[i - 2] != AT_NULL);
45049 + } while (auxv[i - 2] != AT_NULL);
45050 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45051 }
45052
45053 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45054 }
45055
45056 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45057 - unsigned long mm_flags)
45058 + struct coredump_params *cprm)
45059 {
45060 struct vm_area_struct *vma;
45061 size_t size = 0;
45062
45063 for (vma = first_vma(current, gate_vma); vma != NULL;
45064 vma = next_vma(vma, gate_vma))
45065 - size += vma_dump_size(vma, mm_flags);
45066 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45067 return size;
45068 }
45069
45070 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45071
45072 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45073
45074 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45075 + offset += elf_core_vma_data_size(gate_vma, cprm);
45076 offset += elf_core_extra_data_size();
45077 e_shoff = offset;
45078
45079 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45080 offset = dataoff;
45081
45082 size += sizeof(*elf);
45083 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45084 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45085 goto end_coredump;
45086
45087 size += sizeof(*phdr4note);
45088 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45089 if (size > cprm->limit
45090 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45091 goto end_coredump;
45092 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45093 phdr.p_offset = offset;
45094 phdr.p_vaddr = vma->vm_start;
45095 phdr.p_paddr = 0;
45096 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45097 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45098 phdr.p_memsz = vma->vm_end - vma->vm_start;
45099 offset += phdr.p_filesz;
45100 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45101 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45102 phdr.p_align = ELF_EXEC_PAGESIZE;
45103
45104 size += sizeof(phdr);
45105 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45106 if (size > cprm->limit
45107 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45108 goto end_coredump;
45109 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45110 unsigned long addr;
45111 unsigned long end;
45112
45113 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45114 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45115
45116 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45117 struct page *page;
45118 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45119 page = get_dump_page(addr);
45120 if (page) {
45121 void *kaddr = kmap(page);
45122 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45123 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45124 !dump_write(cprm->file, kaddr,
45125 PAGE_SIZE);
45126 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45127
45128 if (e_phnum == PN_XNUM) {
45129 size += sizeof(*shdr4extnum);
45130 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45131 if (size > cprm->limit
45132 || !dump_write(cprm->file, shdr4extnum,
45133 sizeof(*shdr4extnum)))
45134 @@ -2216,6 +2667,97 @@ out:
45135
45136 #endif /* CONFIG_ELF_CORE */
45137
45138 +#ifdef CONFIG_PAX_MPROTECT
45139 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
45140 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45141 + * we'll remove VM_MAYWRITE for good on RELRO segments.
45142 + *
45143 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45144 + * basis because we want to allow the common case and not the special ones.
45145 + */
45146 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45147 +{
45148 + struct elfhdr elf_h;
45149 + struct elf_phdr elf_p;
45150 + unsigned long i;
45151 + unsigned long oldflags;
45152 + bool is_textrel_rw, is_textrel_rx, is_relro;
45153 +
45154 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45155 + return;
45156 +
45157 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45158 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45159 +
45160 +#ifdef CONFIG_PAX_ELFRELOCS
45161 + /* possible TEXTREL */
45162 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45163 + 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);
45164 +#else
45165 + is_textrel_rw = false;
45166 + is_textrel_rx = false;
45167 +#endif
45168 +
45169 + /* possible RELRO */
45170 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45171 +
45172 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45173 + return;
45174 +
45175 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45176 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45177 +
45178 +#ifdef CONFIG_PAX_ETEXECRELOCS
45179 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45180 +#else
45181 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45182 +#endif
45183 +
45184 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45185 + !elf_check_arch(&elf_h) ||
45186 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45187 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45188 + return;
45189 +
45190 + for (i = 0UL; i < elf_h.e_phnum; i++) {
45191 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45192 + return;
45193 + switch (elf_p.p_type) {
45194 + case PT_DYNAMIC:
45195 + if (!is_textrel_rw && !is_textrel_rx)
45196 + continue;
45197 + i = 0UL;
45198 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45199 + elf_dyn dyn;
45200 +
45201 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45202 + return;
45203 + if (dyn.d_tag == DT_NULL)
45204 + return;
45205 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45206 + gr_log_textrel(vma);
45207 + if (is_textrel_rw)
45208 + vma->vm_flags |= VM_MAYWRITE;
45209 + else
45210 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45211 + vma->vm_flags &= ~VM_MAYWRITE;
45212 + return;
45213 + }
45214 + i++;
45215 + }
45216 + return;
45217 +
45218 + case PT_GNU_RELRO:
45219 + if (!is_relro)
45220 + continue;
45221 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45222 + vma->vm_flags &= ~VM_MAYWRITE;
45223 + return;
45224 + }
45225 + }
45226 +}
45227 +#endif
45228 +
45229 static int __init init_elf_binfmt(void)
45230 {
45231 register_binfmt(&elf_format);
45232 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45233 index e280352..7b2f231 100644
45234 --- a/fs/binfmt_flat.c
45235 +++ b/fs/binfmt_flat.c
45236 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45237 realdatastart = (unsigned long) -ENOMEM;
45238 printk("Unable to allocate RAM for process data, errno %d\n",
45239 (int)-realdatastart);
45240 + down_write(&current->mm->mmap_sem);
45241 vm_munmap(textpos, text_len);
45242 + up_write(&current->mm->mmap_sem);
45243 ret = realdatastart;
45244 goto err;
45245 }
45246 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45247 }
45248 if (IS_ERR_VALUE(result)) {
45249 printk("Unable to read data+bss, errno %d\n", (int)-result);
45250 + down_write(&current->mm->mmap_sem);
45251 vm_munmap(textpos, text_len);
45252 vm_munmap(realdatastart, len);
45253 + up_write(&current->mm->mmap_sem);
45254 ret = result;
45255 goto err;
45256 }
45257 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45258 }
45259 if (IS_ERR_VALUE(result)) {
45260 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45261 + down_write(&current->mm->mmap_sem);
45262 vm_munmap(textpos, text_len + data_len + extra +
45263 MAX_SHARED_LIBS * sizeof(unsigned long));
45264 + up_write(&current->mm->mmap_sem);
45265 ret = result;
45266 goto err;
45267 }
45268 diff --git a/fs/bio.c b/fs/bio.c
45269 index b96fc6c..431d628 100644
45270 --- a/fs/bio.c
45271 +++ b/fs/bio.c
45272 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45273 /*
45274 * Overflow, abort
45275 */
45276 - if (end < start)
45277 + if (end < start || end - start > INT_MAX - nr_pages)
45278 return ERR_PTR(-EINVAL);
45279
45280 nr_pages += end - start;
45281 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45282 /*
45283 * Overflow, abort
45284 */
45285 - if (end < start)
45286 + if (end < start || end - start > INT_MAX - nr_pages)
45287 return ERR_PTR(-EINVAL);
45288
45289 nr_pages += end - start;
45290 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45291 const int read = bio_data_dir(bio) == READ;
45292 struct bio_map_data *bmd = bio->bi_private;
45293 int i;
45294 - char *p = bmd->sgvecs[0].iov_base;
45295 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45296
45297 __bio_for_each_segment(bvec, bio, i, 0) {
45298 char *addr = page_address(bvec->bv_page);
45299 diff --git a/fs/block_dev.c b/fs/block_dev.c
45300 index ab3a456..7da538b 100644
45301 --- a/fs/block_dev.c
45302 +++ b/fs/block_dev.c
45303 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45304 else if (bdev->bd_contains == bdev)
45305 return true; /* is a whole device which isn't held */
45306
45307 - else if (whole->bd_holder == bd_may_claim)
45308 + else if (whole->bd_holder == (void *)bd_may_claim)
45309 return true; /* is a partition of a device that is being partitioned */
45310 else if (whole->bd_holder != NULL)
45311 return false; /* is a partition of a held device */
45312 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45313 index cdfb4c4..da736d4 100644
45314 --- a/fs/btrfs/ctree.c
45315 +++ b/fs/btrfs/ctree.c
45316 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45317 free_extent_buffer(buf);
45318 add_root_to_dirty_list(root);
45319 } else {
45320 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45321 - parent_start = parent->start;
45322 - else
45323 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45324 + if (parent)
45325 + parent_start = parent->start;
45326 + else
45327 + parent_start = 0;
45328 + } else
45329 parent_start = 0;
45330
45331 WARN_ON(trans->transid != btrfs_header_generation(parent));
45332 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45333 index 95542a1..95a8727 100644
45334 --- a/fs/btrfs/inode.c
45335 +++ b/fs/btrfs/inode.c
45336 @@ -7243,7 +7243,7 @@ fail:
45337 return -ENOMEM;
45338 }
45339
45340 -static int btrfs_getattr(struct vfsmount *mnt,
45341 +int btrfs_getattr(struct vfsmount *mnt,
45342 struct dentry *dentry, struct kstat *stat)
45343 {
45344 struct inode *inode = dentry->d_inode;
45345 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45346 return 0;
45347 }
45348
45349 +EXPORT_SYMBOL(btrfs_getattr);
45350 +
45351 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45352 +{
45353 + return BTRFS_I(inode)->root->anon_dev;
45354 +}
45355 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45356 +
45357 /*
45358 * If a file is moved, it will inherit the cow and compression flags of the new
45359 * directory.
45360 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45361 index 8fcf9a5..a200000 100644
45362 --- a/fs/btrfs/ioctl.c
45363 +++ b/fs/btrfs/ioctl.c
45364 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45365 for (i = 0; i < num_types; i++) {
45366 struct btrfs_space_info *tmp;
45367
45368 + /* Don't copy in more than we allocated */
45369 if (!slot_count)
45370 break;
45371
45372 + slot_count--;
45373 +
45374 info = NULL;
45375 rcu_read_lock();
45376 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45377 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45378 memcpy(dest, &space, sizeof(space));
45379 dest++;
45380 space_args.total_spaces++;
45381 - slot_count--;
45382 }
45383 - if (!slot_count)
45384 - break;
45385 }
45386 up_read(&info->groups_sem);
45387 }
45388 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45389 index 776f0aa..3aad281 100644
45390 --- a/fs/btrfs/relocation.c
45391 +++ b/fs/btrfs/relocation.c
45392 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45393 }
45394 spin_unlock(&rc->reloc_root_tree.lock);
45395
45396 - BUG_ON((struct btrfs_root *)node->data != root);
45397 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45398
45399 if (!del) {
45400 spin_lock(&rc->reloc_root_tree.lock);
45401 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45402 index 622f469..e8d2d55 100644
45403 --- a/fs/cachefiles/bind.c
45404 +++ b/fs/cachefiles/bind.c
45405 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45406 args);
45407
45408 /* start by checking things over */
45409 - ASSERT(cache->fstop_percent >= 0 &&
45410 - cache->fstop_percent < cache->fcull_percent &&
45411 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45412 cache->fcull_percent < cache->frun_percent &&
45413 cache->frun_percent < 100);
45414
45415 - ASSERT(cache->bstop_percent >= 0 &&
45416 - cache->bstop_percent < cache->bcull_percent &&
45417 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45418 cache->bcull_percent < cache->brun_percent &&
45419 cache->brun_percent < 100);
45420
45421 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45422 index 0a1467b..6a53245 100644
45423 --- a/fs/cachefiles/daemon.c
45424 +++ b/fs/cachefiles/daemon.c
45425 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45426 if (n > buflen)
45427 return -EMSGSIZE;
45428
45429 - if (copy_to_user(_buffer, buffer, n) != 0)
45430 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45431 return -EFAULT;
45432
45433 return n;
45434 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45435 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45436 return -EIO;
45437
45438 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45439 + if (datalen > PAGE_SIZE - 1)
45440 return -EOPNOTSUPP;
45441
45442 /* drag the command string into the kernel so we can parse it */
45443 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45444 if (args[0] != '%' || args[1] != '\0')
45445 return -EINVAL;
45446
45447 - if (fstop < 0 || fstop >= cache->fcull_percent)
45448 + if (fstop >= cache->fcull_percent)
45449 return cachefiles_daemon_range_error(cache, args);
45450
45451 cache->fstop_percent = fstop;
45452 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45453 if (args[0] != '%' || args[1] != '\0')
45454 return -EINVAL;
45455
45456 - if (bstop < 0 || bstop >= cache->bcull_percent)
45457 + if (bstop >= cache->bcull_percent)
45458 return cachefiles_daemon_range_error(cache, args);
45459
45460 cache->bstop_percent = bstop;
45461 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45462 index bd6bc1b..b627b53 100644
45463 --- a/fs/cachefiles/internal.h
45464 +++ b/fs/cachefiles/internal.h
45465 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45466 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45467 struct rb_root active_nodes; /* active nodes (can't be culled) */
45468 rwlock_t active_lock; /* lock for active_nodes */
45469 - atomic_t gravecounter; /* graveyard uniquifier */
45470 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45471 unsigned frun_percent; /* when to stop culling (% files) */
45472 unsigned fcull_percent; /* when to start culling (% files) */
45473 unsigned fstop_percent; /* when to stop allocating (% files) */
45474 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45475 * proc.c
45476 */
45477 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45478 -extern atomic_t cachefiles_lookup_histogram[HZ];
45479 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45480 -extern atomic_t cachefiles_create_histogram[HZ];
45481 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45482 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45483 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45484
45485 extern int __init cachefiles_proc_init(void);
45486 extern void cachefiles_proc_cleanup(void);
45487 static inline
45488 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45489 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45490 {
45491 unsigned long jif = jiffies - start_jif;
45492 if (jif >= HZ)
45493 jif = HZ - 1;
45494 - atomic_inc(&histogram[jif]);
45495 + atomic_inc_unchecked(&histogram[jif]);
45496 }
45497
45498 #else
45499 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45500 index b0b5f7c..039bb26 100644
45501 --- a/fs/cachefiles/namei.c
45502 +++ b/fs/cachefiles/namei.c
45503 @@ -318,7 +318,7 @@ try_again:
45504 /* first step is to make up a grave dentry in the graveyard */
45505 sprintf(nbuffer, "%08x%08x",
45506 (uint32_t) get_seconds(),
45507 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45508 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45509
45510 /* do the multiway lock magic */
45511 trap = lock_rename(cache->graveyard, dir);
45512 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45513 index eccd339..4c1d995 100644
45514 --- a/fs/cachefiles/proc.c
45515 +++ b/fs/cachefiles/proc.c
45516 @@ -14,9 +14,9 @@
45517 #include <linux/seq_file.h>
45518 #include "internal.h"
45519
45520 -atomic_t cachefiles_lookup_histogram[HZ];
45521 -atomic_t cachefiles_mkdir_histogram[HZ];
45522 -atomic_t cachefiles_create_histogram[HZ];
45523 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45524 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45525 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45526
45527 /*
45528 * display the latency histogram
45529 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45530 return 0;
45531 default:
45532 index = (unsigned long) v - 3;
45533 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45534 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45535 - z = atomic_read(&cachefiles_create_histogram[index]);
45536 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45537 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45538 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45539 if (x == 0 && y == 0 && z == 0)
45540 return 0;
45541
45542 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45543 index c994691..2a1537f 100644
45544 --- a/fs/cachefiles/rdwr.c
45545 +++ b/fs/cachefiles/rdwr.c
45546 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45547 old_fs = get_fs();
45548 set_fs(KERNEL_DS);
45549 ret = file->f_op->write(
45550 - file, (const void __user *) data, len, &pos);
45551 + file, (const void __force_user *) data, len, &pos);
45552 set_fs(old_fs);
45553 kunmap(page);
45554 if (ret != len)
45555 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45556 index e5b7731..b9c59fb 100644
45557 --- a/fs/ceph/dir.c
45558 +++ b/fs/ceph/dir.c
45559 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45560 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45561 struct ceph_mds_client *mdsc = fsc->mdsc;
45562 unsigned frag = fpos_frag(filp->f_pos);
45563 - int off = fpos_off(filp->f_pos);
45564 + unsigned int off = fpos_off(filp->f_pos);
45565 int err;
45566 u32 ftype;
45567 struct ceph_mds_reply_info_parsed *rinfo;
45568 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45569 index d9ea6ed..1e6c8ac 100644
45570 --- a/fs/cifs/cifs_debug.c
45571 +++ b/fs/cifs/cifs_debug.c
45572 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45573
45574 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45575 #ifdef CONFIG_CIFS_STATS2
45576 - atomic_set(&totBufAllocCount, 0);
45577 - atomic_set(&totSmBufAllocCount, 0);
45578 + atomic_set_unchecked(&totBufAllocCount, 0);
45579 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45580 #endif /* CONFIG_CIFS_STATS2 */
45581 spin_lock(&cifs_tcp_ses_lock);
45582 list_for_each(tmp1, &cifs_tcp_ses_list) {
45583 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45584 tcon = list_entry(tmp3,
45585 struct cifs_tcon,
45586 tcon_list);
45587 - atomic_set(&tcon->num_smbs_sent, 0);
45588 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45589 if (server->ops->clear_stats)
45590 server->ops->clear_stats(tcon);
45591 }
45592 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45593 smBufAllocCount.counter, cifs_min_small);
45594 #ifdef CONFIG_CIFS_STATS2
45595 seq_printf(m, "Total Large %d Small %d Allocations\n",
45596 - atomic_read(&totBufAllocCount),
45597 - atomic_read(&totSmBufAllocCount));
45598 + atomic_read_unchecked(&totBufAllocCount),
45599 + atomic_read_unchecked(&totSmBufAllocCount));
45600 #endif /* CONFIG_CIFS_STATS2 */
45601
45602 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45603 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45604 if (tcon->need_reconnect)
45605 seq_puts(m, "\tDISCONNECTED ");
45606 seq_printf(m, "\nSMBs: %d",
45607 - atomic_read(&tcon->num_smbs_sent));
45608 + atomic_read_unchecked(&tcon->num_smbs_sent));
45609 if (server->ops->print_stats)
45610 server->ops->print_stats(m, tcon);
45611 }
45612 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45613 index e7931cc..76a1ab9 100644
45614 --- a/fs/cifs/cifsfs.c
45615 +++ b/fs/cifs/cifsfs.c
45616 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45617 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45618 cifs_req_cachep = kmem_cache_create("cifs_request",
45619 CIFSMaxBufSize + max_hdr_size, 0,
45620 - SLAB_HWCACHE_ALIGN, NULL);
45621 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45622 if (cifs_req_cachep == NULL)
45623 return -ENOMEM;
45624
45625 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45626 efficient to alloc 1 per page off the slab compared to 17K (5page)
45627 alloc of large cifs buffers even when page debugging is on */
45628 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45629 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45630 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45631 NULL);
45632 if (cifs_sm_req_cachep == NULL) {
45633 mempool_destroy(cifs_req_poolp);
45634 @@ -1111,8 +1111,8 @@ init_cifs(void)
45635 atomic_set(&bufAllocCount, 0);
45636 atomic_set(&smBufAllocCount, 0);
45637 #ifdef CONFIG_CIFS_STATS2
45638 - atomic_set(&totBufAllocCount, 0);
45639 - atomic_set(&totSmBufAllocCount, 0);
45640 + atomic_set_unchecked(&totBufAllocCount, 0);
45641 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45642 #endif /* CONFIG_CIFS_STATS2 */
45643
45644 atomic_set(&midCount, 0);
45645 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45646 index f5af252..489b5f2 100644
45647 --- a/fs/cifs/cifsglob.h
45648 +++ b/fs/cifs/cifsglob.h
45649 @@ -751,35 +751,35 @@ struct cifs_tcon {
45650 __u16 Flags; /* optional support bits */
45651 enum statusEnum tidStatus;
45652 #ifdef CONFIG_CIFS_STATS
45653 - atomic_t num_smbs_sent;
45654 + atomic_unchecked_t num_smbs_sent;
45655 union {
45656 struct {
45657 - atomic_t num_writes;
45658 - atomic_t num_reads;
45659 - atomic_t num_flushes;
45660 - atomic_t num_oplock_brks;
45661 - atomic_t num_opens;
45662 - atomic_t num_closes;
45663 - atomic_t num_deletes;
45664 - atomic_t num_mkdirs;
45665 - atomic_t num_posixopens;
45666 - atomic_t num_posixmkdirs;
45667 - atomic_t num_rmdirs;
45668 - atomic_t num_renames;
45669 - atomic_t num_t2renames;
45670 - atomic_t num_ffirst;
45671 - atomic_t num_fnext;
45672 - atomic_t num_fclose;
45673 - atomic_t num_hardlinks;
45674 - atomic_t num_symlinks;
45675 - atomic_t num_locks;
45676 - atomic_t num_acl_get;
45677 - atomic_t num_acl_set;
45678 + atomic_unchecked_t num_writes;
45679 + atomic_unchecked_t num_reads;
45680 + atomic_unchecked_t num_flushes;
45681 + atomic_unchecked_t num_oplock_brks;
45682 + atomic_unchecked_t num_opens;
45683 + atomic_unchecked_t num_closes;
45684 + atomic_unchecked_t num_deletes;
45685 + atomic_unchecked_t num_mkdirs;
45686 + atomic_unchecked_t num_posixopens;
45687 + atomic_unchecked_t num_posixmkdirs;
45688 + atomic_unchecked_t num_rmdirs;
45689 + atomic_unchecked_t num_renames;
45690 + atomic_unchecked_t num_t2renames;
45691 + atomic_unchecked_t num_ffirst;
45692 + atomic_unchecked_t num_fnext;
45693 + atomic_unchecked_t num_fclose;
45694 + atomic_unchecked_t num_hardlinks;
45695 + atomic_unchecked_t num_symlinks;
45696 + atomic_unchecked_t num_locks;
45697 + atomic_unchecked_t num_acl_get;
45698 + atomic_unchecked_t num_acl_set;
45699 } cifs_stats;
45700 #ifdef CONFIG_CIFS_SMB2
45701 struct {
45702 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45703 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45704 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45705 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45706 } smb2_stats;
45707 #endif /* CONFIG_CIFS_SMB2 */
45708 } stats;
45709 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45710 }
45711
45712 #ifdef CONFIG_CIFS_STATS
45713 -#define cifs_stats_inc atomic_inc
45714 +#define cifs_stats_inc atomic_inc_unchecked
45715
45716 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45717 unsigned int bytes)
45718 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45719 /* Various Debug counters */
45720 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45721 #ifdef CONFIG_CIFS_STATS2
45722 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45723 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45724 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45725 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45726 #endif
45727 GLOBAL_EXTERN atomic_t smBufAllocCount;
45728 GLOBAL_EXTERN atomic_t midCount;
45729 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45730 index 51dc2fb..1e12a33 100644
45731 --- a/fs/cifs/link.c
45732 +++ b/fs/cifs/link.c
45733 @@ -616,7 +616,7 @@ symlink_exit:
45734
45735 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45736 {
45737 - char *p = nd_get_link(nd);
45738 + const char *p = nd_get_link(nd);
45739 if (!IS_ERR(p))
45740 kfree(p);
45741 }
45742 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45743 index 3a00c0d..42d901c 100644
45744 --- a/fs/cifs/misc.c
45745 +++ b/fs/cifs/misc.c
45746 @@ -169,7 +169,7 @@ cifs_buf_get(void)
45747 memset(ret_buf, 0, buf_size + 3);
45748 atomic_inc(&bufAllocCount);
45749 #ifdef CONFIG_CIFS_STATS2
45750 - atomic_inc(&totBufAllocCount);
45751 + atomic_inc_unchecked(&totBufAllocCount);
45752 #endif /* CONFIG_CIFS_STATS2 */
45753 }
45754
45755 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
45756 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
45757 atomic_inc(&smBufAllocCount);
45758 #ifdef CONFIG_CIFS_STATS2
45759 - atomic_inc(&totSmBufAllocCount);
45760 + atomic_inc_unchecked(&totSmBufAllocCount);
45761 #endif /* CONFIG_CIFS_STATS2 */
45762
45763 }
45764 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
45765 index 591bf19..690d600 100644
45766 --- a/fs/cifs/smb1ops.c
45767 +++ b/fs/cifs/smb1ops.c
45768 @@ -617,27 +617,27 @@ static void
45769 cifs_clear_stats(struct cifs_tcon *tcon)
45770 {
45771 #ifdef CONFIG_CIFS_STATS
45772 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
45773 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
45774 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
45775 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45776 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
45777 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
45778 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45779 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
45780 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
45781 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
45782 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
45783 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
45784 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
45785 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
45786 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
45787 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
45788 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
45789 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
45790 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
45791 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
45792 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
45793 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
45794 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
45795 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
45796 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45797 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
45798 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
45799 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45800 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
45801 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
45802 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
45803 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
45804 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
45805 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
45806 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
45807 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
45808 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
45809 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
45810 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
45811 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
45812 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
45813 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
45814 #endif
45815 }
45816
45817 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45818 {
45819 #ifdef CONFIG_CIFS_STATS
45820 seq_printf(m, " Oplocks breaks: %d",
45821 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
45822 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
45823 seq_printf(m, "\nReads: %d Bytes: %llu",
45824 - atomic_read(&tcon->stats.cifs_stats.num_reads),
45825 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
45826 (long long)(tcon->bytes_read));
45827 seq_printf(m, "\nWrites: %d Bytes: %llu",
45828 - atomic_read(&tcon->stats.cifs_stats.num_writes),
45829 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
45830 (long long)(tcon->bytes_written));
45831 seq_printf(m, "\nFlushes: %d",
45832 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
45833 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
45834 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
45835 - atomic_read(&tcon->stats.cifs_stats.num_locks),
45836 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
45837 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
45838 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
45839 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
45840 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
45841 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
45842 - atomic_read(&tcon->stats.cifs_stats.num_opens),
45843 - atomic_read(&tcon->stats.cifs_stats.num_closes),
45844 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
45845 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
45846 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
45847 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
45848 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
45849 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
45850 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
45851 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
45852 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
45853 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
45854 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
45855 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
45856 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
45857 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
45858 seq_printf(m, "\nRenames: %d T2 Renames %d",
45859 - atomic_read(&tcon->stats.cifs_stats.num_renames),
45860 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
45861 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
45862 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
45863 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
45864 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
45865 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
45866 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
45867 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
45868 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
45869 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
45870 #endif
45871 }
45872
45873 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
45874 index 4d9dbe0..0af4601 100644
45875 --- a/fs/cifs/smb2ops.c
45876 +++ b/fs/cifs/smb2ops.c
45877 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
45878 #ifdef CONFIG_CIFS_STATS
45879 int i;
45880 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
45881 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45882 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45883 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45884 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45885 }
45886 #endif
45887 }
45888 @@ -301,66 +301,66 @@ static void
45889 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45890 {
45891 #ifdef CONFIG_CIFS_STATS
45892 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45893 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45894 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45895 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45896 seq_printf(m, "\nNegotiates: %d sent %d failed",
45897 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
45898 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
45899 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
45900 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
45901 seq_printf(m, "\nSessionSetups: %d sent %d failed",
45902 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
45903 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
45904 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
45905 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
45906 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
45907 seq_printf(m, "\nLogoffs: %d sent %d failed",
45908 - atomic_read(&sent[SMB2_LOGOFF_HE]),
45909 - atomic_read(&failed[SMB2_LOGOFF_HE]));
45910 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
45911 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
45912 seq_printf(m, "\nTreeConnects: %d sent %d failed",
45913 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
45914 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
45915 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
45916 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
45917 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
45918 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
45919 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
45920 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
45921 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
45922 seq_printf(m, "\nCreates: %d sent %d failed",
45923 - atomic_read(&sent[SMB2_CREATE_HE]),
45924 - atomic_read(&failed[SMB2_CREATE_HE]));
45925 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
45926 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
45927 seq_printf(m, "\nCloses: %d sent %d failed",
45928 - atomic_read(&sent[SMB2_CLOSE_HE]),
45929 - atomic_read(&failed[SMB2_CLOSE_HE]));
45930 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
45931 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
45932 seq_printf(m, "\nFlushes: %d sent %d failed",
45933 - atomic_read(&sent[SMB2_FLUSH_HE]),
45934 - atomic_read(&failed[SMB2_FLUSH_HE]));
45935 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
45936 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
45937 seq_printf(m, "\nReads: %d sent %d failed",
45938 - atomic_read(&sent[SMB2_READ_HE]),
45939 - atomic_read(&failed[SMB2_READ_HE]));
45940 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
45941 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
45942 seq_printf(m, "\nWrites: %d sent %d failed",
45943 - atomic_read(&sent[SMB2_WRITE_HE]),
45944 - atomic_read(&failed[SMB2_WRITE_HE]));
45945 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
45946 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
45947 seq_printf(m, "\nLocks: %d sent %d failed",
45948 - atomic_read(&sent[SMB2_LOCK_HE]),
45949 - atomic_read(&failed[SMB2_LOCK_HE]));
45950 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
45951 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
45952 seq_printf(m, "\nIOCTLs: %d sent %d failed",
45953 - atomic_read(&sent[SMB2_IOCTL_HE]),
45954 - atomic_read(&failed[SMB2_IOCTL_HE]));
45955 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
45956 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
45957 seq_printf(m, "\nCancels: %d sent %d failed",
45958 - atomic_read(&sent[SMB2_CANCEL_HE]),
45959 - atomic_read(&failed[SMB2_CANCEL_HE]));
45960 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
45961 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
45962 seq_printf(m, "\nEchos: %d sent %d failed",
45963 - atomic_read(&sent[SMB2_ECHO_HE]),
45964 - atomic_read(&failed[SMB2_ECHO_HE]));
45965 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
45966 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
45967 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
45968 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
45969 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
45970 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
45971 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
45972 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
45973 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
45974 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
45975 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
45976 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
45977 seq_printf(m, "\nQueryInfos: %d sent %d failed",
45978 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
45979 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
45980 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
45981 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
45982 seq_printf(m, "\nSetInfos: %d sent %d failed",
45983 - atomic_read(&sent[SMB2_SET_INFO_HE]),
45984 - atomic_read(&failed[SMB2_SET_INFO_HE]));
45985 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
45986 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
45987 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
45988 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
45989 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
45990 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
45991 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
45992 #endif
45993 }
45994
45995 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
45996 index 958ae0e..505c9d0 100644
45997 --- a/fs/coda/cache.c
45998 +++ b/fs/coda/cache.c
45999 @@ -24,7 +24,7 @@
46000 #include "coda_linux.h"
46001 #include "coda_cache.h"
46002
46003 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46004 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46005
46006 /* replace or extend an acl cache hit */
46007 void coda_cache_enter(struct inode *inode, int mask)
46008 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46009 struct coda_inode_info *cii = ITOC(inode);
46010
46011 spin_lock(&cii->c_lock);
46012 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46013 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46014 if (cii->c_uid != current_fsuid()) {
46015 cii->c_uid = current_fsuid();
46016 cii->c_cached_perm = mask;
46017 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46018 {
46019 struct coda_inode_info *cii = ITOC(inode);
46020 spin_lock(&cii->c_lock);
46021 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46022 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46023 spin_unlock(&cii->c_lock);
46024 }
46025
46026 /* remove all acl caches */
46027 void coda_cache_clear_all(struct super_block *sb)
46028 {
46029 - atomic_inc(&permission_epoch);
46030 + atomic_inc_unchecked(&permission_epoch);
46031 }
46032
46033
46034 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46035 spin_lock(&cii->c_lock);
46036 hit = (mask & cii->c_cached_perm) == mask &&
46037 cii->c_uid == current_fsuid() &&
46038 - cii->c_cached_epoch == atomic_read(&permission_epoch);
46039 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46040 spin_unlock(&cii->c_lock);
46041
46042 return hit;
46043 diff --git a/fs/compat.c b/fs/compat.c
46044 index 015e1e1..5ce8e54 100644
46045 --- a/fs/compat.c
46046 +++ b/fs/compat.c
46047 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46048
46049 set_fs(KERNEL_DS);
46050 /* The __user pointer cast is valid because of the set_fs() */
46051 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46052 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46053 set_fs(oldfs);
46054 /* truncating is ok because it's a user address */
46055 if (!ret)
46056 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46057 goto out;
46058
46059 ret = -EINVAL;
46060 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46061 + if (nr_segs > UIO_MAXIOV)
46062 goto out;
46063 if (nr_segs > fast_segs) {
46064 ret = -ENOMEM;
46065 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46066
46067 struct compat_readdir_callback {
46068 struct compat_old_linux_dirent __user *dirent;
46069 + struct file * file;
46070 int result;
46071 };
46072
46073 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46074 buf->result = -EOVERFLOW;
46075 return -EOVERFLOW;
46076 }
46077 +
46078 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46079 + return 0;
46080 +
46081 buf->result++;
46082 dirent = buf->dirent;
46083 if (!access_ok(VERIFY_WRITE, dirent,
46084 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46085
46086 buf.result = 0;
46087 buf.dirent = dirent;
46088 + buf.file = f.file;
46089
46090 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46091 if (buf.result)
46092 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
46093 struct compat_getdents_callback {
46094 struct compat_linux_dirent __user *current_dir;
46095 struct compat_linux_dirent __user *previous;
46096 + struct file * file;
46097 int count;
46098 int error;
46099 };
46100 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46101 buf->error = -EOVERFLOW;
46102 return -EOVERFLOW;
46103 }
46104 +
46105 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46106 + return 0;
46107 +
46108 dirent = buf->previous;
46109 if (dirent) {
46110 if (__put_user(offset, &dirent->d_off))
46111 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46112 buf.previous = NULL;
46113 buf.count = count;
46114 buf.error = 0;
46115 + buf.file = f.file;
46116
46117 error = vfs_readdir(f.file, compat_filldir, &buf);
46118 if (error >= 0)
46119 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46120 struct compat_getdents_callback64 {
46121 struct linux_dirent64 __user *current_dir;
46122 struct linux_dirent64 __user *previous;
46123 + struct file * file;
46124 int count;
46125 int error;
46126 };
46127 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46128 buf->error = -EINVAL; /* only used if we fail.. */
46129 if (reclen > buf->count)
46130 return -EINVAL;
46131 +
46132 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46133 + return 0;
46134 +
46135 dirent = buf->previous;
46136
46137 if (dirent) {
46138 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46139 buf.previous = NULL;
46140 buf.count = count;
46141 buf.error = 0;
46142 + buf.file = f.file;
46143
46144 error = vfs_readdir(f.file, compat_filldir64, &buf);
46145 if (error >= 0)
46146 error = buf.error;
46147 lastdirent = buf.previous;
46148 if (lastdirent) {
46149 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
46150 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46151 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46152 error = -EFAULT;
46153 else
46154 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46155 index a81147e..20bf2b5 100644
46156 --- a/fs/compat_binfmt_elf.c
46157 +++ b/fs/compat_binfmt_elf.c
46158 @@ -30,11 +30,13 @@
46159 #undef elf_phdr
46160 #undef elf_shdr
46161 #undef elf_note
46162 +#undef elf_dyn
46163 #undef elf_addr_t
46164 #define elfhdr elf32_hdr
46165 #define elf_phdr elf32_phdr
46166 #define elf_shdr elf32_shdr
46167 #define elf_note elf32_note
46168 +#define elf_dyn Elf32_Dyn
46169 #define elf_addr_t Elf32_Addr
46170
46171 /*
46172 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46173 index 4c6285f..b7a2411 100644
46174 --- a/fs/compat_ioctl.c
46175 +++ b/fs/compat_ioctl.c
46176 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46177 return -EFAULT;
46178 if (__get_user(udata, &ss32->iomem_base))
46179 return -EFAULT;
46180 - ss.iomem_base = compat_ptr(udata);
46181 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46182 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46183 __get_user(ss.port_high, &ss32->port_high))
46184 return -EFAULT;
46185 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46186 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46187 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46188 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46189 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46190 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46191 return -EFAULT;
46192
46193 return ioctl_preallocate(file, p);
46194 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46195 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46196 {
46197 unsigned int a, b;
46198 - a = *(unsigned int *)p;
46199 - b = *(unsigned int *)q;
46200 + a = *(const unsigned int *)p;
46201 + b = *(const unsigned int *)q;
46202 if (a > b)
46203 return 1;
46204 if (a < b)
46205 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46206 index 7414ae2..d98ad6d 100644
46207 --- a/fs/configfs/dir.c
46208 +++ b/fs/configfs/dir.c
46209 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46210 }
46211 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46212 struct configfs_dirent *next;
46213 - const char * name;
46214 + const unsigned char * name;
46215 + char d_name[sizeof(next->s_dentry->d_iname)];
46216 int len;
46217 struct inode *inode = NULL;
46218
46219 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46220 continue;
46221
46222 name = configfs_get_name(next);
46223 - len = strlen(name);
46224 + if (next->s_dentry && name == next->s_dentry->d_iname) {
46225 + len = next->s_dentry->d_name.len;
46226 + memcpy(d_name, name, len);
46227 + name = d_name;
46228 + } else
46229 + len = strlen(name);
46230
46231 /*
46232 * We'll have a dentry and an inode for
46233 diff --git a/fs/coredump.c b/fs/coredump.c
46234 index ce47379..68c8e43 100644
46235 --- a/fs/coredump.c
46236 +++ b/fs/coredump.c
46237 @@ -52,7 +52,7 @@ struct core_name {
46238 char *corename;
46239 int used, size;
46240 };
46241 -static atomic_t call_count = ATOMIC_INIT(1);
46242 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46243
46244 /* The maximal length of core_pattern is also specified in sysctl.c */
46245
46246 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46247 {
46248 char *old_corename = cn->corename;
46249
46250 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46251 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46252 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46253
46254 if (!cn->corename) {
46255 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46256 int pid_in_pattern = 0;
46257 int err = 0;
46258
46259 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46260 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46261 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46262 cn->used = 0;
46263
46264 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46265 pipe = file->f_path.dentry->d_inode->i_pipe;
46266
46267 pipe_lock(pipe);
46268 - pipe->readers++;
46269 - pipe->writers--;
46270 + atomic_inc(&pipe->readers);
46271 + atomic_dec(&pipe->writers);
46272
46273 - while ((pipe->readers > 1) && (!signal_pending(current))) {
46274 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46275 wake_up_interruptible_sync(&pipe->wait);
46276 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46277 pipe_wait(pipe);
46278 }
46279
46280 - pipe->readers--;
46281 - pipe->writers++;
46282 + atomic_dec(&pipe->readers);
46283 + atomic_inc(&pipe->writers);
46284 pipe_unlock(pipe);
46285
46286 }
46287 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46288 int ispipe;
46289 struct files_struct *displaced;
46290 bool need_nonrelative = false;
46291 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46292 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46293 + long signr = siginfo->si_signo;
46294 struct coredump_params cprm = {
46295 .siginfo = siginfo,
46296 .regs = regs,
46297 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46298 .mm_flags = mm->flags,
46299 };
46300
46301 - audit_core_dumps(siginfo->si_signo);
46302 + audit_core_dumps(signr);
46303 +
46304 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46305 + gr_handle_brute_attach(cprm.mm_flags);
46306
46307 binfmt = mm->binfmt;
46308 if (!binfmt || !binfmt->core_dump)
46309 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46310 need_nonrelative = true;
46311 }
46312
46313 - retval = coredump_wait(siginfo->si_signo, &core_state);
46314 + retval = coredump_wait(signr, &core_state);
46315 if (retval < 0)
46316 goto fail_creds;
46317
46318 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46319 }
46320 cprm.limit = RLIM_INFINITY;
46321
46322 - dump_count = atomic_inc_return(&core_dump_count);
46323 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46324 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46325 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46326 task_tgid_vnr(current), current->comm);
46327 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46328 } else {
46329 struct inode *inode;
46330
46331 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46332 +
46333 if (cprm.limit < binfmt->min_coredump)
46334 goto fail_unlock;
46335
46336 @@ -640,7 +646,7 @@ close_fail:
46337 filp_close(cprm.file, NULL);
46338 fail_dropcount:
46339 if (ispipe)
46340 - atomic_dec(&core_dump_count);
46341 + atomic_dec_unchecked(&core_dump_count);
46342 fail_unlock:
46343 kfree(cn.corename);
46344 fail_corename:
46345 @@ -659,7 +665,7 @@ fail:
46346 */
46347 int dump_write(struct file *file, const void *addr, int nr)
46348 {
46349 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46350 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46351 }
46352 EXPORT_SYMBOL(dump_write);
46353
46354 diff --git a/fs/dcache.c b/fs/dcache.c
46355 index 0d0adb6..f4646e9 100644
46356 --- a/fs/dcache.c
46357 +++ b/fs/dcache.c
46358 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46359 mempages -= reserve;
46360
46361 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46362 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46363 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46364
46365 dcache_init();
46366 inode_init();
46367 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46368 index b607d92..41fda09 100644
46369 --- a/fs/debugfs/inode.c
46370 +++ b/fs/debugfs/inode.c
46371 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46372 */
46373 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46374 {
46375 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46376 + return __create_file(name, S_IFDIR | S_IRWXU,
46377 +#else
46378 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46379 +#endif
46380 parent, NULL, NULL);
46381 }
46382 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46383 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46384 index cc7709e..7e7211f 100644
46385 --- a/fs/ecryptfs/inode.c
46386 +++ b/fs/ecryptfs/inode.c
46387 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46388 old_fs = get_fs();
46389 set_fs(get_ds());
46390 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46391 - (char __user *)lower_buf,
46392 + (char __force_user *)lower_buf,
46393 PATH_MAX);
46394 set_fs(old_fs);
46395 if (rc < 0)
46396 @@ -706,7 +706,7 @@ out:
46397 static void
46398 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46399 {
46400 - char *buf = nd_get_link(nd);
46401 + const char *buf = nd_get_link(nd);
46402 if (!IS_ERR(buf)) {
46403 /* Free the char* */
46404 kfree(buf);
46405 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46406 index 412e6ed..4292d22 100644
46407 --- a/fs/ecryptfs/miscdev.c
46408 +++ b/fs/ecryptfs/miscdev.c
46409 @@ -315,7 +315,7 @@ check_list:
46410 goto out_unlock_msg_ctx;
46411 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46412 if (msg_ctx->msg) {
46413 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46414 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46415 goto out_unlock_msg_ctx;
46416 i += packet_length_size;
46417 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46418 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46419 index b2a34a1..162fa69 100644
46420 --- a/fs/ecryptfs/read_write.c
46421 +++ b/fs/ecryptfs/read_write.c
46422 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46423 return -EIO;
46424 fs_save = get_fs();
46425 set_fs(get_ds());
46426 - rc = vfs_write(lower_file, data, size, &offset);
46427 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46428 set_fs(fs_save);
46429 mark_inode_dirty_sync(ecryptfs_inode);
46430 return rc;
46431 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46432 return -EIO;
46433 fs_save = get_fs();
46434 set_fs(get_ds());
46435 - rc = vfs_read(lower_file, data, size, &offset);
46436 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46437 set_fs(fs_save);
46438 return rc;
46439 }
46440 diff --git a/fs/exec.c b/fs/exec.c
46441 index c6e6de4..fb98879 100644
46442 --- a/fs/exec.c
46443 +++ b/fs/exec.c
46444 @@ -55,6 +55,17 @@
46445 #include <linux/pipe_fs_i.h>
46446 #include <linux/oom.h>
46447 #include <linux/compat.h>
46448 +#include <linux/random.h>
46449 +#include <linux/seq_file.h>
46450 +#include <linux/coredump.h>
46451 +#include <linux/mman.h>
46452 +
46453 +#ifdef CONFIG_PAX_REFCOUNT
46454 +#include <linux/kallsyms.h>
46455 +#include <linux/kdebug.h>
46456 +#endif
46457 +
46458 +#include <trace/events/fs.h>
46459
46460 #include <asm/uaccess.h>
46461 #include <asm/mmu_context.h>
46462 @@ -66,6 +77,18 @@
46463
46464 #include <trace/events/sched.h>
46465
46466 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46467 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46468 +{
46469 + 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");
46470 +}
46471 +#endif
46472 +
46473 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46474 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46475 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46476 +#endif
46477 +
46478 int suid_dumpable = 0;
46479
46480 static LIST_HEAD(formats);
46481 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46482 int write)
46483 {
46484 struct page *page;
46485 - int ret;
46486
46487 -#ifdef CONFIG_STACK_GROWSUP
46488 - if (write) {
46489 - ret = expand_downwards(bprm->vma, pos);
46490 - if (ret < 0)
46491 - return NULL;
46492 - }
46493 -#endif
46494 - ret = get_user_pages(current, bprm->mm, pos,
46495 - 1, write, 1, &page, NULL);
46496 - if (ret <= 0)
46497 + if (0 > expand_downwards(bprm->vma, pos))
46498 + return NULL;
46499 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46500 return NULL;
46501
46502 if (write) {
46503 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46504 if (size <= ARG_MAX)
46505 return page;
46506
46507 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46508 + // only allow 512KB for argv+env on suid/sgid binaries
46509 + // to prevent easy ASLR exhaustion
46510 + if (((bprm->cred->euid != current_euid()) ||
46511 + (bprm->cred->egid != current_egid())) &&
46512 + (size > (512 * 1024))) {
46513 + put_page(page);
46514 + return NULL;
46515 + }
46516 +#endif
46517 +
46518 /*
46519 * Limit to 1/4-th the stack size for the argv+env strings.
46520 * This ensures that:
46521 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46522 vma->vm_end = STACK_TOP_MAX;
46523 vma->vm_start = vma->vm_end - PAGE_SIZE;
46524 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46525 +
46526 +#ifdef CONFIG_PAX_SEGMEXEC
46527 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46528 +#endif
46529 +
46530 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46531 INIT_LIST_HEAD(&vma->anon_vma_chain);
46532
46533 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46534 mm->stack_vm = mm->total_vm = 1;
46535 up_write(&mm->mmap_sem);
46536 bprm->p = vma->vm_end - sizeof(void *);
46537 +
46538 +#ifdef CONFIG_PAX_RANDUSTACK
46539 + if (randomize_va_space)
46540 + bprm->p ^= random32() & ~PAGE_MASK;
46541 +#endif
46542 +
46543 return 0;
46544 err:
46545 up_write(&mm->mmap_sem);
46546 @@ -384,19 +421,7 @@ err:
46547 return err;
46548 }
46549
46550 -struct user_arg_ptr {
46551 -#ifdef CONFIG_COMPAT
46552 - bool is_compat;
46553 -#endif
46554 - union {
46555 - const char __user *const __user *native;
46556 -#ifdef CONFIG_COMPAT
46557 - const compat_uptr_t __user *compat;
46558 -#endif
46559 - } ptr;
46560 -};
46561 -
46562 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46563 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46564 {
46565 const char __user *native;
46566
46567 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46568 compat_uptr_t compat;
46569
46570 if (get_user(compat, argv.ptr.compat + nr))
46571 - return ERR_PTR(-EFAULT);
46572 + return (const char __force_user *)ERR_PTR(-EFAULT);
46573
46574 return compat_ptr(compat);
46575 }
46576 #endif
46577
46578 if (get_user(native, argv.ptr.native + nr))
46579 - return ERR_PTR(-EFAULT);
46580 + return (const char __force_user *)ERR_PTR(-EFAULT);
46581
46582 return native;
46583 }
46584 @@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46585 if (!p)
46586 break;
46587
46588 - if (IS_ERR(p))
46589 + if (IS_ERR((const char __force_kernel *)p))
46590 return -EFAULT;
46591
46592 - if (i++ >= max)
46593 + if (i >= max)
46594 return -E2BIG;
46595 + ++i;
46596
46597 if (fatal_signal_pending(current))
46598 return -ERESTARTNOHAND;
46599 @@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46600
46601 ret = -EFAULT;
46602 str = get_user_arg_ptr(argv, argc);
46603 - if (IS_ERR(str))
46604 + if (IS_ERR((const char __force_kernel *)str))
46605 goto out;
46606
46607 len = strnlen_user(str, MAX_ARG_STRLEN);
46608 @@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46609 int r;
46610 mm_segment_t oldfs = get_fs();
46611 struct user_arg_ptr argv = {
46612 - .ptr.native = (const char __user *const __user *)__argv,
46613 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46614 };
46615
46616 set_fs(KERNEL_DS);
46617 @@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46618 unsigned long new_end = old_end - shift;
46619 struct mmu_gather tlb;
46620
46621 - BUG_ON(new_start > new_end);
46622 + if (new_start >= new_end || new_start < mmap_min_addr)
46623 + return -ENOMEM;
46624
46625 /*
46626 * ensure there are no vmas between where we want to go
46627 @@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46628 if (vma != find_vma(mm, new_start))
46629 return -EFAULT;
46630
46631 +#ifdef CONFIG_PAX_SEGMEXEC
46632 + BUG_ON(pax_find_mirror_vma(vma));
46633 +#endif
46634 +
46635 /*
46636 * cover the whole range: [new_start, old_end)
46637 */
46638 @@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46639 stack_top = arch_align_stack(stack_top);
46640 stack_top = PAGE_ALIGN(stack_top);
46641
46642 - if (unlikely(stack_top < mmap_min_addr) ||
46643 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46644 - return -ENOMEM;
46645 -
46646 stack_shift = vma->vm_end - stack_top;
46647
46648 bprm->p -= stack_shift;
46649 @@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46650 bprm->exec -= stack_shift;
46651
46652 down_write(&mm->mmap_sem);
46653 +
46654 + /* Move stack pages down in memory. */
46655 + if (stack_shift) {
46656 + ret = shift_arg_pages(vma, stack_shift);
46657 + if (ret)
46658 + goto out_unlock;
46659 + }
46660 +
46661 vm_flags = VM_STACK_FLAGS;
46662
46663 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46664 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46665 + vm_flags &= ~VM_EXEC;
46666 +
46667 +#ifdef CONFIG_PAX_MPROTECT
46668 + if (mm->pax_flags & MF_PAX_MPROTECT)
46669 + vm_flags &= ~VM_MAYEXEC;
46670 +#endif
46671 +
46672 + }
46673 +#endif
46674 +
46675 /*
46676 * Adjust stack execute permissions; explicitly enable for
46677 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46678 @@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46679 goto out_unlock;
46680 BUG_ON(prev != vma);
46681
46682 - /* Move stack pages down in memory. */
46683 - if (stack_shift) {
46684 - ret = shift_arg_pages(vma, stack_shift);
46685 - if (ret)
46686 - goto out_unlock;
46687 - }
46688 -
46689 /* mprotect_fixup is overkill to remove the temporary stack flags */
46690 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46691
46692 @@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46693 #endif
46694 current->mm->start_stack = bprm->p;
46695 ret = expand_stack(vma, stack_base);
46696 +
46697 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46698 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46699 + unsigned long size, flags, vm_flags;
46700 +
46701 + size = STACK_TOP - vma->vm_end;
46702 + flags = MAP_FIXED | MAP_PRIVATE;
46703 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46704 +
46705 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46706 +
46707 +#ifdef CONFIG_X86
46708 + if (!ret) {
46709 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46710 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46711 + }
46712 +#endif
46713 +
46714 + }
46715 +#endif
46716 +
46717 if (ret)
46718 ret = -EFAULT;
46719
46720 @@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46721
46722 fsnotify_open(file);
46723
46724 + trace_open_exec(name);
46725 +
46726 err = deny_write_access(file);
46727 if (err)
46728 goto exit;
46729 @@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46730 old_fs = get_fs();
46731 set_fs(get_ds());
46732 /* The cast to a user pointer is valid due to the set_fs() */
46733 - result = vfs_read(file, (void __user *)addr, count, &pos);
46734 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
46735 set_fs(old_fs);
46736 return result;
46737 }
46738 @@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46739 }
46740 rcu_read_unlock();
46741
46742 - if (p->fs->users > n_fs) {
46743 + if (atomic_read(&p->fs->users) > n_fs) {
46744 bprm->unsafe |= LSM_UNSAFE_SHARE;
46745 } else {
46746 res = -EAGAIN;
46747 @@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46748
46749 EXPORT_SYMBOL(search_binary_handler);
46750
46751 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46752 +static DEFINE_PER_CPU(u64, exec_counter);
46753 +static int __init init_exec_counters(void)
46754 +{
46755 + unsigned int cpu;
46756 +
46757 + for_each_possible_cpu(cpu) {
46758 + per_cpu(exec_counter, cpu) = (u64)cpu;
46759 + }
46760 +
46761 + return 0;
46762 +}
46763 +early_initcall(init_exec_counters);
46764 +static inline void increment_exec_counter(void)
46765 +{
46766 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
46767 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
46768 +}
46769 +#else
46770 +static inline void increment_exec_counter(void) {}
46771 +#endif
46772 +
46773 /*
46774 * sys_execve() executes a new program.
46775 */
46776 @@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
46777 struct user_arg_ptr envp,
46778 struct pt_regs *regs)
46779 {
46780 +#ifdef CONFIG_GRKERNSEC
46781 + struct file *old_exec_file;
46782 + struct acl_subject_label *old_acl;
46783 + struct rlimit old_rlim[RLIM_NLIMITS];
46784 +#endif
46785 struct linux_binprm *bprm;
46786 struct file *file;
46787 struct files_struct *displaced;
46788 @@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
46789 int retval;
46790 const struct cred *cred = current_cred();
46791
46792 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
46793 +
46794 /*
46795 * We move the actual failure in case of RLIMIT_NPROC excess from
46796 * set*uid() to execve() because too many poorly written programs
46797 @@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
46798 if (IS_ERR(file))
46799 goto out_unmark;
46800
46801 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
46802 + retval = -EPERM;
46803 + goto out_file;
46804 + }
46805 +
46806 sched_exec();
46807
46808 bprm->file = file;
46809 bprm->filename = filename;
46810 bprm->interp = filename;
46811
46812 + if (gr_process_user_ban()) {
46813 + retval = -EPERM;
46814 + goto out_file;
46815 + }
46816 +
46817 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
46818 + retval = -EACCES;
46819 + goto out_file;
46820 + }
46821 +
46822 retval = bprm_mm_init(bprm);
46823 if (retval)
46824 goto out_file;
46825 @@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
46826 if (retval < 0)
46827 goto out;
46828
46829 +#ifdef CONFIG_GRKERNSEC
46830 + old_acl = current->acl;
46831 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
46832 + old_exec_file = current->exec_file;
46833 + get_file(file);
46834 + current->exec_file = file;
46835 +#endif
46836 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46837 + /* limit suid stack to 8MB
46838 + we saved the old limits above and will restore them if this exec fails
46839 + */
46840 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
46841 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
46842 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
46843 +#endif
46844 +
46845 + if (!gr_tpe_allow(file)) {
46846 + retval = -EACCES;
46847 + goto out_fail;
46848 + }
46849 +
46850 + if (gr_check_crash_exec(file)) {
46851 + retval = -EACCES;
46852 + goto out_fail;
46853 + }
46854 +
46855 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
46856 + bprm->unsafe);
46857 + if (retval < 0)
46858 + goto out_fail;
46859 +
46860 retval = copy_strings_kernel(1, &bprm->filename, bprm);
46861 if (retval < 0)
46862 - goto out;
46863 + goto out_fail;
46864
46865 bprm->exec = bprm->p;
46866 retval = copy_strings(bprm->envc, envp, bprm);
46867 if (retval < 0)
46868 - goto out;
46869 + goto out_fail;
46870
46871 retval = copy_strings(bprm->argc, argv, bprm);
46872 if (retval < 0)
46873 - goto out;
46874 + goto out_fail;
46875 +
46876 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
46877 +
46878 + gr_handle_exec_args(bprm, argv);
46879
46880 retval = search_binary_handler(bprm,regs);
46881 if (retval < 0)
46882 - goto out;
46883 + goto out_fail;
46884 +#ifdef CONFIG_GRKERNSEC
46885 + if (old_exec_file)
46886 + fput(old_exec_file);
46887 +#endif
46888
46889 /* execve succeeded */
46890 +
46891 + increment_exec_counter();
46892 current->fs->in_exec = 0;
46893 current->in_execve = 0;
46894 acct_update_integrals(current);
46895 @@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
46896 put_files_struct(displaced);
46897 return retval;
46898
46899 +out_fail:
46900 +#ifdef CONFIG_GRKERNSEC
46901 + current->acl = old_acl;
46902 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
46903 + fput(current->exec_file);
46904 + current->exec_file = old_exec_file;
46905 +#endif
46906 +
46907 out:
46908 if (bprm->mm) {
46909 acct_arg_size(bprm, 0);
46910 @@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
46911 ret_from_kernel_execve(p);
46912 }
46913 #endif
46914 +
46915 +int pax_check_flags(unsigned long *flags)
46916 +{
46917 + int retval = 0;
46918 +
46919 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
46920 + if (*flags & MF_PAX_SEGMEXEC)
46921 + {
46922 + *flags &= ~MF_PAX_SEGMEXEC;
46923 + retval = -EINVAL;
46924 + }
46925 +#endif
46926 +
46927 + if ((*flags & MF_PAX_PAGEEXEC)
46928 +
46929 +#ifdef CONFIG_PAX_PAGEEXEC
46930 + && (*flags & MF_PAX_SEGMEXEC)
46931 +#endif
46932 +
46933 + )
46934 + {
46935 + *flags &= ~MF_PAX_PAGEEXEC;
46936 + retval = -EINVAL;
46937 + }
46938 +
46939 + if ((*flags & MF_PAX_MPROTECT)
46940 +
46941 +#ifdef CONFIG_PAX_MPROTECT
46942 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46943 +#endif
46944 +
46945 + )
46946 + {
46947 + *flags &= ~MF_PAX_MPROTECT;
46948 + retval = -EINVAL;
46949 + }
46950 +
46951 + if ((*flags & MF_PAX_EMUTRAMP)
46952 +
46953 +#ifdef CONFIG_PAX_EMUTRAMP
46954 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46955 +#endif
46956 +
46957 + )
46958 + {
46959 + *flags &= ~MF_PAX_EMUTRAMP;
46960 + retval = -EINVAL;
46961 + }
46962 +
46963 + return retval;
46964 +}
46965 +
46966 +EXPORT_SYMBOL(pax_check_flags);
46967 +
46968 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46969 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
46970 +{
46971 + struct task_struct *tsk = current;
46972 + struct mm_struct *mm = current->mm;
46973 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
46974 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
46975 + char *path_exec = NULL;
46976 + char *path_fault = NULL;
46977 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
46978 + siginfo_t info = { };
46979 +
46980 + if (buffer_exec && buffer_fault) {
46981 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
46982 +
46983 + down_read(&mm->mmap_sem);
46984 + vma = mm->mmap;
46985 + while (vma && (!vma_exec || !vma_fault)) {
46986 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
46987 + vma_exec = vma;
46988 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
46989 + vma_fault = vma;
46990 + vma = vma->vm_next;
46991 + }
46992 + if (vma_exec) {
46993 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
46994 + if (IS_ERR(path_exec))
46995 + path_exec = "<path too long>";
46996 + else {
46997 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
46998 + if (path_exec) {
46999 + *path_exec = 0;
47000 + path_exec = buffer_exec;
47001 + } else
47002 + path_exec = "<path too long>";
47003 + }
47004 + }
47005 + if (vma_fault) {
47006 + start = vma_fault->vm_start;
47007 + end = vma_fault->vm_end;
47008 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47009 + if (vma_fault->vm_file) {
47010 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47011 + if (IS_ERR(path_fault))
47012 + path_fault = "<path too long>";
47013 + else {
47014 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47015 + if (path_fault) {
47016 + *path_fault = 0;
47017 + path_fault = buffer_fault;
47018 + } else
47019 + path_fault = "<path too long>";
47020 + }
47021 + } else
47022 + path_fault = "<anonymous mapping>";
47023 + }
47024 + up_read(&mm->mmap_sem);
47025 + }
47026 + if (tsk->signal->curr_ip)
47027 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47028 + else
47029 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47030 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
47031 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
47032 + task_uid(tsk), task_euid(tsk), pc, sp);
47033 + free_page((unsigned long)buffer_exec);
47034 + free_page((unsigned long)buffer_fault);
47035 + pax_report_insns(regs, pc, sp);
47036 + info.si_signo = SIGKILL;
47037 + info.si_errno = 0;
47038 + info.si_code = SI_KERNEL;
47039 + info.si_pid = 0;
47040 + info.si_uid = 0;
47041 + do_coredump(&info, regs);
47042 +}
47043 +#endif
47044 +
47045 +#ifdef CONFIG_PAX_REFCOUNT
47046 +void pax_report_refcount_overflow(struct pt_regs *regs)
47047 +{
47048 + if (current->signal->curr_ip)
47049 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47050 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
47051 + else
47052 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47053 + current->comm, task_pid_nr(current), current_uid(), current_euid());
47054 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47055 + show_regs(regs);
47056 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47057 +}
47058 +#endif
47059 +
47060 +#ifdef CONFIG_PAX_USERCOPY
47061 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47062 +static noinline int check_stack_object(const void *obj, unsigned long len)
47063 +{
47064 + const void * const stack = task_stack_page(current);
47065 + const void * const stackend = stack + THREAD_SIZE;
47066 +
47067 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47068 + const void *frame = NULL;
47069 + const void *oldframe;
47070 +#endif
47071 +
47072 + if (obj + len < obj)
47073 + return -1;
47074 +
47075 + if (obj + len <= stack || stackend <= obj)
47076 + return 0;
47077 +
47078 + if (obj < stack || stackend < obj + len)
47079 + return -1;
47080 +
47081 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47082 + oldframe = __builtin_frame_address(1);
47083 + if (oldframe)
47084 + frame = __builtin_frame_address(2);
47085 + /*
47086 + low ----------------------------------------------> high
47087 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
47088 + ^----------------^
47089 + allow copies only within here
47090 + */
47091 + while (stack <= frame && frame < stackend) {
47092 + /* if obj + len extends past the last frame, this
47093 + check won't pass and the next frame will be 0,
47094 + causing us to bail out and correctly report
47095 + the copy as invalid
47096 + */
47097 + if (obj + len <= frame)
47098 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47099 + oldframe = frame;
47100 + frame = *(const void * const *)frame;
47101 + }
47102 + return -1;
47103 +#else
47104 + return 1;
47105 +#endif
47106 +}
47107 +
47108 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47109 +{
47110 + if (current->signal->curr_ip)
47111 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47112 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47113 + else
47114 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47115 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47116 + dump_stack();
47117 + gr_handle_kernel_exploit();
47118 + do_group_exit(SIGKILL);
47119 +}
47120 +#endif
47121 +
47122 +void check_object_size(const void *ptr, unsigned long n, bool to)
47123 +{
47124 +
47125 +#ifdef CONFIG_PAX_USERCOPY
47126 + const char *type;
47127 +
47128 + if (!n)
47129 + return;
47130 +
47131 + type = check_heap_object(ptr, n);
47132 + if (!type) {
47133 + if (check_stack_object(ptr, n) != -1)
47134 + return;
47135 + type = "<process stack>";
47136 + }
47137 +
47138 + pax_report_usercopy(ptr, n, to, type);
47139 +#endif
47140 +
47141 +}
47142 +EXPORT_SYMBOL(check_object_size);
47143 +
47144 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47145 +void pax_track_stack(void)
47146 +{
47147 + unsigned long sp = (unsigned long)&sp;
47148 + if (sp < current_thread_info()->lowest_stack &&
47149 + sp > (unsigned long)task_stack_page(current))
47150 + current_thread_info()->lowest_stack = sp;
47151 +}
47152 +EXPORT_SYMBOL(pax_track_stack);
47153 +#endif
47154 +
47155 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
47156 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47157 +{
47158 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47159 + dump_stack();
47160 + do_group_exit(SIGKILL);
47161 +}
47162 +EXPORT_SYMBOL(report_size_overflow);
47163 +#endif
47164 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47165 index 2616d0e..2ffdec9 100644
47166 --- a/fs/ext2/balloc.c
47167 +++ b/fs/ext2/balloc.c
47168 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47169
47170 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47171 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47172 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47173 + if (free_blocks < root_blocks + 1 &&
47174 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47175 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47176 - !in_group_p (sbi->s_resgid))) {
47177 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47178 return 0;
47179 }
47180 return 1;
47181 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47182 index 22548f5..41521d8 100644
47183 --- a/fs/ext3/balloc.c
47184 +++ b/fs/ext3/balloc.c
47185 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47186
47187 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47188 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47189 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47190 + if (free_blocks < root_blocks + 1 &&
47191 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47192 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47193 - !in_group_p (sbi->s_resgid))) {
47194 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47195 return 0;
47196 }
47197 return 1;
47198 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47199 index cf18217..8f6b9c3 100644
47200 --- a/fs/ext4/balloc.c
47201 +++ b/fs/ext4/balloc.c
47202 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47203 /* Hm, nope. Are (enough) root reserved clusters available? */
47204 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47205 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47206 - capable(CAP_SYS_RESOURCE) ||
47207 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47208 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47209 + capable_nolog(CAP_SYS_RESOURCE)) {
47210
47211 if (free_clusters >= (nclusters + dirty_clusters))
47212 return 1;
47213 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47214 index 3c20de1..6ff2460 100644
47215 --- a/fs/ext4/ext4.h
47216 +++ b/fs/ext4/ext4.h
47217 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47218 unsigned long s_mb_last_start;
47219
47220 /* stats for buddy allocator */
47221 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47222 - atomic_t s_bal_success; /* we found long enough chunks */
47223 - atomic_t s_bal_allocated; /* in blocks */
47224 - atomic_t s_bal_ex_scanned; /* total extents scanned */
47225 - atomic_t s_bal_goals; /* goal hits */
47226 - atomic_t s_bal_breaks; /* too long searches */
47227 - atomic_t s_bal_2orders; /* 2^order hits */
47228 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47229 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47230 + atomic_unchecked_t s_bal_allocated; /* in blocks */
47231 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47232 + atomic_unchecked_t s_bal_goals; /* goal hits */
47233 + atomic_unchecked_t s_bal_breaks; /* too long searches */
47234 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47235 spinlock_t s_bal_lock;
47236 unsigned long s_mb_buddies_generated;
47237 unsigned long long s_mb_generation_time;
47238 - atomic_t s_mb_lost_chunks;
47239 - atomic_t s_mb_preallocated;
47240 - atomic_t s_mb_discarded;
47241 + atomic_unchecked_t s_mb_lost_chunks;
47242 + atomic_unchecked_t s_mb_preallocated;
47243 + atomic_unchecked_t s_mb_discarded;
47244 atomic_t s_lock_busy;
47245
47246 /* locality groups */
47247 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47248 index 526e553..3f2de85 100644
47249 --- a/fs/ext4/mballoc.c
47250 +++ b/fs/ext4/mballoc.c
47251 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47252 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47253
47254 if (EXT4_SB(sb)->s_mb_stats)
47255 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47256 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47257
47258 break;
47259 }
47260 @@ -2044,7 +2044,7 @@ repeat:
47261 ac->ac_status = AC_STATUS_CONTINUE;
47262 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47263 cr = 3;
47264 - atomic_inc(&sbi->s_mb_lost_chunks);
47265 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47266 goto repeat;
47267 }
47268 }
47269 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47270 if (sbi->s_mb_stats) {
47271 ext4_msg(sb, KERN_INFO,
47272 "mballoc: %u blocks %u reqs (%u success)",
47273 - atomic_read(&sbi->s_bal_allocated),
47274 - atomic_read(&sbi->s_bal_reqs),
47275 - atomic_read(&sbi->s_bal_success));
47276 + atomic_read_unchecked(&sbi->s_bal_allocated),
47277 + atomic_read_unchecked(&sbi->s_bal_reqs),
47278 + atomic_read_unchecked(&sbi->s_bal_success));
47279 ext4_msg(sb, KERN_INFO,
47280 "mballoc: %u extents scanned, %u goal hits, "
47281 "%u 2^N hits, %u breaks, %u lost",
47282 - atomic_read(&sbi->s_bal_ex_scanned),
47283 - atomic_read(&sbi->s_bal_goals),
47284 - atomic_read(&sbi->s_bal_2orders),
47285 - atomic_read(&sbi->s_bal_breaks),
47286 - atomic_read(&sbi->s_mb_lost_chunks));
47287 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47288 + atomic_read_unchecked(&sbi->s_bal_goals),
47289 + atomic_read_unchecked(&sbi->s_bal_2orders),
47290 + atomic_read_unchecked(&sbi->s_bal_breaks),
47291 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47292 ext4_msg(sb, KERN_INFO,
47293 "mballoc: %lu generated and it took %Lu",
47294 sbi->s_mb_buddies_generated,
47295 sbi->s_mb_generation_time);
47296 ext4_msg(sb, KERN_INFO,
47297 "mballoc: %u preallocated, %u discarded",
47298 - atomic_read(&sbi->s_mb_preallocated),
47299 - atomic_read(&sbi->s_mb_discarded));
47300 + atomic_read_unchecked(&sbi->s_mb_preallocated),
47301 + atomic_read_unchecked(&sbi->s_mb_discarded));
47302 }
47303
47304 free_percpu(sbi->s_locality_groups);
47305 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47306 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47307
47308 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47309 - atomic_inc(&sbi->s_bal_reqs);
47310 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47311 + atomic_inc_unchecked(&sbi->s_bal_reqs);
47312 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47313 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47314 - atomic_inc(&sbi->s_bal_success);
47315 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47316 + atomic_inc_unchecked(&sbi->s_bal_success);
47317 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47318 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47319 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47320 - atomic_inc(&sbi->s_bal_goals);
47321 + atomic_inc_unchecked(&sbi->s_bal_goals);
47322 if (ac->ac_found > sbi->s_mb_max_to_scan)
47323 - atomic_inc(&sbi->s_bal_breaks);
47324 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47325 }
47326
47327 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47328 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47329 trace_ext4_mb_new_inode_pa(ac, pa);
47330
47331 ext4_mb_use_inode_pa(ac, pa);
47332 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47333 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47334
47335 ei = EXT4_I(ac->ac_inode);
47336 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47337 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47338 trace_ext4_mb_new_group_pa(ac, pa);
47339
47340 ext4_mb_use_group_pa(ac, pa);
47341 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47342 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47343
47344 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47345 lg = ac->ac_lg;
47346 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47347 * from the bitmap and continue.
47348 */
47349 }
47350 - atomic_add(free, &sbi->s_mb_discarded);
47351 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47352
47353 return err;
47354 }
47355 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47356 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47357 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47358 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47359 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47360 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47361 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47362
47363 return 0;
47364 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47365 index d59b351..775f8c8 100644
47366 --- a/fs/ext4/super.c
47367 +++ b/fs/ext4/super.c
47368 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47369 ext4_fsblk_t overhead = 0;
47370 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47371
47372 - memset(buf, 0, PAGE_SIZE);
47373 if (!buf)
47374 return -ENOMEM;
47375
47376 diff --git a/fs/fcntl.c b/fs/fcntl.c
47377 index 71a600a..20d87b1 100644
47378 --- a/fs/fcntl.c
47379 +++ b/fs/fcntl.c
47380 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47381 if (err)
47382 return err;
47383
47384 + if (gr_handle_chroot_fowner(pid, type))
47385 + return -ENOENT;
47386 + if (gr_check_protected_task_fowner(pid, type))
47387 + return -EACCES;
47388 +
47389 f_modown(filp, pid, type, force);
47390 return 0;
47391 }
47392 diff --git a/fs/fhandle.c b/fs/fhandle.c
47393 index f775bfd..629bd4c 100644
47394 --- a/fs/fhandle.c
47395 +++ b/fs/fhandle.c
47396 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47397 } else
47398 retval = 0;
47399 /* copy the mount id */
47400 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47401 - sizeof(*mnt_id)) ||
47402 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47403 copy_to_user(ufh, handle,
47404 sizeof(struct file_handle) + handle_bytes))
47405 retval = -EFAULT;
47406 diff --git a/fs/fifo.c b/fs/fifo.c
47407 index cf6f434..3d7942c 100644
47408 --- a/fs/fifo.c
47409 +++ b/fs/fifo.c
47410 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47411 */
47412 filp->f_op = &read_pipefifo_fops;
47413 pipe->r_counter++;
47414 - if (pipe->readers++ == 0)
47415 + if (atomic_inc_return(&pipe->readers) == 1)
47416 wake_up_partner(inode);
47417
47418 - if (!pipe->writers) {
47419 + if (!atomic_read(&pipe->writers)) {
47420 if ((filp->f_flags & O_NONBLOCK)) {
47421 /* suppress POLLHUP until we have
47422 * seen a writer */
47423 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47424 * errno=ENXIO when there is no process reading the FIFO.
47425 */
47426 ret = -ENXIO;
47427 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47428 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47429 goto err;
47430
47431 filp->f_op = &write_pipefifo_fops;
47432 pipe->w_counter++;
47433 - if (!pipe->writers++)
47434 + if (atomic_inc_return(&pipe->writers) == 1)
47435 wake_up_partner(inode);
47436
47437 - if (!pipe->readers) {
47438 + if (!atomic_read(&pipe->readers)) {
47439 if (wait_for_partner(inode, &pipe->r_counter))
47440 goto err_wr;
47441 }
47442 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47443 */
47444 filp->f_op = &rdwr_pipefifo_fops;
47445
47446 - pipe->readers++;
47447 - pipe->writers++;
47448 + atomic_inc(&pipe->readers);
47449 + atomic_inc(&pipe->writers);
47450 pipe->r_counter++;
47451 pipe->w_counter++;
47452 - if (pipe->readers == 1 || pipe->writers == 1)
47453 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47454 wake_up_partner(inode);
47455 break;
47456
47457 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47458 return 0;
47459
47460 err_rd:
47461 - if (!--pipe->readers)
47462 + if (atomic_dec_and_test(&pipe->readers))
47463 wake_up_interruptible(&pipe->wait);
47464 ret = -ERESTARTSYS;
47465 goto err;
47466
47467 err_wr:
47468 - if (!--pipe->writers)
47469 + if (atomic_dec_and_test(&pipe->writers))
47470 wake_up_interruptible(&pipe->wait);
47471 ret = -ERESTARTSYS;
47472 goto err;
47473
47474 err:
47475 - if (!pipe->readers && !pipe->writers)
47476 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47477 free_pipe_info(inode);
47478
47479 err_nocleanup:
47480 diff --git a/fs/file.c b/fs/file.c
47481 index eff2316..8c8930c 100644
47482 --- a/fs/file.c
47483 +++ b/fs/file.c
47484 @@ -16,6 +16,7 @@
47485 #include <linux/slab.h>
47486 #include <linux/vmalloc.h>
47487 #include <linux/file.h>
47488 +#include <linux/security.h>
47489 #include <linux/fdtable.h>
47490 #include <linux/bitops.h>
47491 #include <linux/interrupt.h>
47492 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47493 if (!file)
47494 return __close_fd(files, fd);
47495
47496 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47497 if (fd >= rlimit(RLIMIT_NOFILE))
47498 return -EBADF;
47499
47500 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47501 if (unlikely(oldfd == newfd))
47502 return -EINVAL;
47503
47504 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47505 if (newfd >= rlimit(RLIMIT_NOFILE))
47506 return -EBADF;
47507
47508 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47509 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47510 {
47511 int err;
47512 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47513 if (from >= rlimit(RLIMIT_NOFILE))
47514 return -EINVAL;
47515 err = alloc_fd(from, flags);
47516 diff --git a/fs/filesystems.c b/fs/filesystems.c
47517 index da165f6..3671bdb 100644
47518 --- a/fs/filesystems.c
47519 +++ b/fs/filesystems.c
47520 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47521 int len = dot ? dot - name : strlen(name);
47522
47523 fs = __get_fs_type(name, len);
47524 +
47525 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47526 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47527 +#else
47528 if (!fs && (request_module("%.*s", len, name) == 0))
47529 +#endif
47530 fs = __get_fs_type(name, len);
47531
47532 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47533 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47534 index 5df4775..9d9336f 100644
47535 --- a/fs/fs_struct.c
47536 +++ b/fs/fs_struct.c
47537 @@ -4,6 +4,7 @@
47538 #include <linux/path.h>
47539 #include <linux/slab.h>
47540 #include <linux/fs_struct.h>
47541 +#include <linux/grsecurity.h>
47542 #include "internal.h"
47543
47544 /*
47545 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47546 write_seqcount_begin(&fs->seq);
47547 old_root = fs->root;
47548 fs->root = *path;
47549 + gr_set_chroot_entries(current, path);
47550 write_seqcount_end(&fs->seq);
47551 spin_unlock(&fs->lock);
47552 if (old_root.dentry)
47553 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47554 return 1;
47555 }
47556
47557 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47558 +{
47559 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47560 + return 0;
47561 + *p = *new;
47562 +
47563 + /* This function is only called from pivot_root(). Leave our
47564 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47565 + pivoted root isn't treated as a chroot
47566 + */
47567 + //gr_set_chroot_entries(task, new);
47568 +
47569 + return 1;
47570 +}
47571 +
47572 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47573 {
47574 struct task_struct *g, *p;
47575 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47576 int hits = 0;
47577 spin_lock(&fs->lock);
47578 write_seqcount_begin(&fs->seq);
47579 - hits += replace_path(&fs->root, old_root, new_root);
47580 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47581 hits += replace_path(&fs->pwd, old_root, new_root);
47582 write_seqcount_end(&fs->seq);
47583 while (hits--) {
47584 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47585 task_lock(tsk);
47586 spin_lock(&fs->lock);
47587 tsk->fs = NULL;
47588 - kill = !--fs->users;
47589 + gr_clear_chroot_entries(tsk);
47590 + kill = !atomic_dec_return(&fs->users);
47591 spin_unlock(&fs->lock);
47592 task_unlock(tsk);
47593 if (kill)
47594 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47595 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47596 /* We don't need to lock fs - think why ;-) */
47597 if (fs) {
47598 - fs->users = 1;
47599 + atomic_set(&fs->users, 1);
47600 fs->in_exec = 0;
47601 spin_lock_init(&fs->lock);
47602 seqcount_init(&fs->seq);
47603 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47604 spin_lock(&old->lock);
47605 fs->root = old->root;
47606 path_get(&fs->root);
47607 + /* instead of calling gr_set_chroot_entries here,
47608 + we call it from every caller of this function
47609 + */
47610 fs->pwd = old->pwd;
47611 path_get(&fs->pwd);
47612 spin_unlock(&old->lock);
47613 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47614
47615 task_lock(current);
47616 spin_lock(&fs->lock);
47617 - kill = !--fs->users;
47618 + kill = !atomic_dec_return(&fs->users);
47619 current->fs = new_fs;
47620 + gr_set_chroot_entries(current, &new_fs->root);
47621 spin_unlock(&fs->lock);
47622 task_unlock(current);
47623
47624 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47625
47626 int current_umask(void)
47627 {
47628 - return current->fs->umask;
47629 + return current->fs->umask | gr_acl_umask();
47630 }
47631 EXPORT_SYMBOL(current_umask);
47632
47633 /* to be mentioned only in INIT_TASK */
47634 struct fs_struct init_fs = {
47635 - .users = 1,
47636 + .users = ATOMIC_INIT(1),
47637 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47638 .seq = SEQCNT_ZERO,
47639 .umask = 0022,
47640 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47641 task_lock(current);
47642
47643 spin_lock(&init_fs.lock);
47644 - init_fs.users++;
47645 + atomic_inc(&init_fs.users);
47646 spin_unlock(&init_fs.lock);
47647
47648 spin_lock(&fs->lock);
47649 current->fs = &init_fs;
47650 - kill = !--fs->users;
47651 + gr_set_chroot_entries(current, &current->fs->root);
47652 + kill = !atomic_dec_return(&fs->users);
47653 spin_unlock(&fs->lock);
47654
47655 task_unlock(current);
47656 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47657 index 9905350..02eaec4 100644
47658 --- a/fs/fscache/cookie.c
47659 +++ b/fs/fscache/cookie.c
47660 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47661 parent ? (char *) parent->def->name : "<no-parent>",
47662 def->name, netfs_data);
47663
47664 - fscache_stat(&fscache_n_acquires);
47665 + fscache_stat_unchecked(&fscache_n_acquires);
47666
47667 /* if there's no parent cookie, then we don't create one here either */
47668 if (!parent) {
47669 - fscache_stat(&fscache_n_acquires_null);
47670 + fscache_stat_unchecked(&fscache_n_acquires_null);
47671 _leave(" [no parent]");
47672 return NULL;
47673 }
47674 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47675 /* allocate and initialise a cookie */
47676 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47677 if (!cookie) {
47678 - fscache_stat(&fscache_n_acquires_oom);
47679 + fscache_stat_unchecked(&fscache_n_acquires_oom);
47680 _leave(" [ENOMEM]");
47681 return NULL;
47682 }
47683 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47684
47685 switch (cookie->def->type) {
47686 case FSCACHE_COOKIE_TYPE_INDEX:
47687 - fscache_stat(&fscache_n_cookie_index);
47688 + fscache_stat_unchecked(&fscache_n_cookie_index);
47689 break;
47690 case FSCACHE_COOKIE_TYPE_DATAFILE:
47691 - fscache_stat(&fscache_n_cookie_data);
47692 + fscache_stat_unchecked(&fscache_n_cookie_data);
47693 break;
47694 default:
47695 - fscache_stat(&fscache_n_cookie_special);
47696 + fscache_stat_unchecked(&fscache_n_cookie_special);
47697 break;
47698 }
47699
47700 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47701 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47702 atomic_dec(&parent->n_children);
47703 __fscache_cookie_put(cookie);
47704 - fscache_stat(&fscache_n_acquires_nobufs);
47705 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47706 _leave(" = NULL");
47707 return NULL;
47708 }
47709 }
47710
47711 - fscache_stat(&fscache_n_acquires_ok);
47712 + fscache_stat_unchecked(&fscache_n_acquires_ok);
47713 _leave(" = %p", cookie);
47714 return cookie;
47715 }
47716 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47717 cache = fscache_select_cache_for_object(cookie->parent);
47718 if (!cache) {
47719 up_read(&fscache_addremove_sem);
47720 - fscache_stat(&fscache_n_acquires_no_cache);
47721 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47722 _leave(" = -ENOMEDIUM [no cache]");
47723 return -ENOMEDIUM;
47724 }
47725 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47726 object = cache->ops->alloc_object(cache, cookie);
47727 fscache_stat_d(&fscache_n_cop_alloc_object);
47728 if (IS_ERR(object)) {
47729 - fscache_stat(&fscache_n_object_no_alloc);
47730 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
47731 ret = PTR_ERR(object);
47732 goto error;
47733 }
47734
47735 - fscache_stat(&fscache_n_object_alloc);
47736 + fscache_stat_unchecked(&fscache_n_object_alloc);
47737
47738 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47739
47740 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47741 struct fscache_object *object;
47742 struct hlist_node *_p;
47743
47744 - fscache_stat(&fscache_n_updates);
47745 + fscache_stat_unchecked(&fscache_n_updates);
47746
47747 if (!cookie) {
47748 - fscache_stat(&fscache_n_updates_null);
47749 + fscache_stat_unchecked(&fscache_n_updates_null);
47750 _leave(" [no cookie]");
47751 return;
47752 }
47753 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47754 struct fscache_object *object;
47755 unsigned long event;
47756
47757 - fscache_stat(&fscache_n_relinquishes);
47758 + fscache_stat_unchecked(&fscache_n_relinquishes);
47759 if (retire)
47760 - fscache_stat(&fscache_n_relinquishes_retire);
47761 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
47762
47763 if (!cookie) {
47764 - fscache_stat(&fscache_n_relinquishes_null);
47765 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
47766 _leave(" [no cookie]");
47767 return;
47768 }
47769 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47770
47771 /* wait for the cookie to finish being instantiated (or to fail) */
47772 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
47773 - fscache_stat(&fscache_n_relinquishes_waitcrt);
47774 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
47775 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
47776 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
47777 }
47778 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
47779 index f6aad48..88dcf26 100644
47780 --- a/fs/fscache/internal.h
47781 +++ b/fs/fscache/internal.h
47782 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
47783 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
47784 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
47785
47786 -extern atomic_t fscache_n_op_pend;
47787 -extern atomic_t fscache_n_op_run;
47788 -extern atomic_t fscache_n_op_enqueue;
47789 -extern atomic_t fscache_n_op_deferred_release;
47790 -extern atomic_t fscache_n_op_release;
47791 -extern atomic_t fscache_n_op_gc;
47792 -extern atomic_t fscache_n_op_cancelled;
47793 -extern atomic_t fscache_n_op_rejected;
47794 +extern atomic_unchecked_t fscache_n_op_pend;
47795 +extern atomic_unchecked_t fscache_n_op_run;
47796 +extern atomic_unchecked_t fscache_n_op_enqueue;
47797 +extern atomic_unchecked_t fscache_n_op_deferred_release;
47798 +extern atomic_unchecked_t fscache_n_op_release;
47799 +extern atomic_unchecked_t fscache_n_op_gc;
47800 +extern atomic_unchecked_t fscache_n_op_cancelled;
47801 +extern atomic_unchecked_t fscache_n_op_rejected;
47802
47803 -extern atomic_t fscache_n_attr_changed;
47804 -extern atomic_t fscache_n_attr_changed_ok;
47805 -extern atomic_t fscache_n_attr_changed_nobufs;
47806 -extern atomic_t fscache_n_attr_changed_nomem;
47807 -extern atomic_t fscache_n_attr_changed_calls;
47808 +extern atomic_unchecked_t fscache_n_attr_changed;
47809 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
47810 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
47811 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
47812 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
47813
47814 -extern atomic_t fscache_n_allocs;
47815 -extern atomic_t fscache_n_allocs_ok;
47816 -extern atomic_t fscache_n_allocs_wait;
47817 -extern atomic_t fscache_n_allocs_nobufs;
47818 -extern atomic_t fscache_n_allocs_intr;
47819 -extern atomic_t fscache_n_allocs_object_dead;
47820 -extern atomic_t fscache_n_alloc_ops;
47821 -extern atomic_t fscache_n_alloc_op_waits;
47822 +extern atomic_unchecked_t fscache_n_allocs;
47823 +extern atomic_unchecked_t fscache_n_allocs_ok;
47824 +extern atomic_unchecked_t fscache_n_allocs_wait;
47825 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
47826 +extern atomic_unchecked_t fscache_n_allocs_intr;
47827 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
47828 +extern atomic_unchecked_t fscache_n_alloc_ops;
47829 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
47830
47831 -extern atomic_t fscache_n_retrievals;
47832 -extern atomic_t fscache_n_retrievals_ok;
47833 -extern atomic_t fscache_n_retrievals_wait;
47834 -extern atomic_t fscache_n_retrievals_nodata;
47835 -extern atomic_t fscache_n_retrievals_nobufs;
47836 -extern atomic_t fscache_n_retrievals_intr;
47837 -extern atomic_t fscache_n_retrievals_nomem;
47838 -extern atomic_t fscache_n_retrievals_object_dead;
47839 -extern atomic_t fscache_n_retrieval_ops;
47840 -extern atomic_t fscache_n_retrieval_op_waits;
47841 +extern atomic_unchecked_t fscache_n_retrievals;
47842 +extern atomic_unchecked_t fscache_n_retrievals_ok;
47843 +extern atomic_unchecked_t fscache_n_retrievals_wait;
47844 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
47845 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
47846 +extern atomic_unchecked_t fscache_n_retrievals_intr;
47847 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
47848 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
47849 +extern atomic_unchecked_t fscache_n_retrieval_ops;
47850 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
47851
47852 -extern atomic_t fscache_n_stores;
47853 -extern atomic_t fscache_n_stores_ok;
47854 -extern atomic_t fscache_n_stores_again;
47855 -extern atomic_t fscache_n_stores_nobufs;
47856 -extern atomic_t fscache_n_stores_oom;
47857 -extern atomic_t fscache_n_store_ops;
47858 -extern atomic_t fscache_n_store_calls;
47859 -extern atomic_t fscache_n_store_pages;
47860 -extern atomic_t fscache_n_store_radix_deletes;
47861 -extern atomic_t fscache_n_store_pages_over_limit;
47862 +extern atomic_unchecked_t fscache_n_stores;
47863 +extern atomic_unchecked_t fscache_n_stores_ok;
47864 +extern atomic_unchecked_t fscache_n_stores_again;
47865 +extern atomic_unchecked_t fscache_n_stores_nobufs;
47866 +extern atomic_unchecked_t fscache_n_stores_oom;
47867 +extern atomic_unchecked_t fscache_n_store_ops;
47868 +extern atomic_unchecked_t fscache_n_store_calls;
47869 +extern atomic_unchecked_t fscache_n_store_pages;
47870 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
47871 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
47872
47873 -extern atomic_t fscache_n_store_vmscan_not_storing;
47874 -extern atomic_t fscache_n_store_vmscan_gone;
47875 -extern atomic_t fscache_n_store_vmscan_busy;
47876 -extern atomic_t fscache_n_store_vmscan_cancelled;
47877 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47878 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
47879 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
47880 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47881
47882 -extern atomic_t fscache_n_marks;
47883 -extern atomic_t fscache_n_uncaches;
47884 +extern atomic_unchecked_t fscache_n_marks;
47885 +extern atomic_unchecked_t fscache_n_uncaches;
47886
47887 -extern atomic_t fscache_n_acquires;
47888 -extern atomic_t fscache_n_acquires_null;
47889 -extern atomic_t fscache_n_acquires_no_cache;
47890 -extern atomic_t fscache_n_acquires_ok;
47891 -extern atomic_t fscache_n_acquires_nobufs;
47892 -extern atomic_t fscache_n_acquires_oom;
47893 +extern atomic_unchecked_t fscache_n_acquires;
47894 +extern atomic_unchecked_t fscache_n_acquires_null;
47895 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
47896 +extern atomic_unchecked_t fscache_n_acquires_ok;
47897 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
47898 +extern atomic_unchecked_t fscache_n_acquires_oom;
47899
47900 -extern atomic_t fscache_n_updates;
47901 -extern atomic_t fscache_n_updates_null;
47902 -extern atomic_t fscache_n_updates_run;
47903 +extern atomic_unchecked_t fscache_n_updates;
47904 +extern atomic_unchecked_t fscache_n_updates_null;
47905 +extern atomic_unchecked_t fscache_n_updates_run;
47906
47907 -extern atomic_t fscache_n_relinquishes;
47908 -extern atomic_t fscache_n_relinquishes_null;
47909 -extern atomic_t fscache_n_relinquishes_waitcrt;
47910 -extern atomic_t fscache_n_relinquishes_retire;
47911 +extern atomic_unchecked_t fscache_n_relinquishes;
47912 +extern atomic_unchecked_t fscache_n_relinquishes_null;
47913 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47914 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
47915
47916 -extern atomic_t fscache_n_cookie_index;
47917 -extern atomic_t fscache_n_cookie_data;
47918 -extern atomic_t fscache_n_cookie_special;
47919 +extern atomic_unchecked_t fscache_n_cookie_index;
47920 +extern atomic_unchecked_t fscache_n_cookie_data;
47921 +extern atomic_unchecked_t fscache_n_cookie_special;
47922
47923 -extern atomic_t fscache_n_object_alloc;
47924 -extern atomic_t fscache_n_object_no_alloc;
47925 -extern atomic_t fscache_n_object_lookups;
47926 -extern atomic_t fscache_n_object_lookups_negative;
47927 -extern atomic_t fscache_n_object_lookups_positive;
47928 -extern atomic_t fscache_n_object_lookups_timed_out;
47929 -extern atomic_t fscache_n_object_created;
47930 -extern atomic_t fscache_n_object_avail;
47931 -extern atomic_t fscache_n_object_dead;
47932 +extern atomic_unchecked_t fscache_n_object_alloc;
47933 +extern atomic_unchecked_t fscache_n_object_no_alloc;
47934 +extern atomic_unchecked_t fscache_n_object_lookups;
47935 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
47936 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
47937 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
47938 +extern atomic_unchecked_t fscache_n_object_created;
47939 +extern atomic_unchecked_t fscache_n_object_avail;
47940 +extern atomic_unchecked_t fscache_n_object_dead;
47941
47942 -extern atomic_t fscache_n_checkaux_none;
47943 -extern atomic_t fscache_n_checkaux_okay;
47944 -extern atomic_t fscache_n_checkaux_update;
47945 -extern atomic_t fscache_n_checkaux_obsolete;
47946 +extern atomic_unchecked_t fscache_n_checkaux_none;
47947 +extern atomic_unchecked_t fscache_n_checkaux_okay;
47948 +extern atomic_unchecked_t fscache_n_checkaux_update;
47949 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
47950
47951 extern atomic_t fscache_n_cop_alloc_object;
47952 extern atomic_t fscache_n_cop_lookup_object;
47953 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
47954 atomic_inc(stat);
47955 }
47956
47957 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
47958 +{
47959 + atomic_inc_unchecked(stat);
47960 +}
47961 +
47962 static inline void fscache_stat_d(atomic_t *stat)
47963 {
47964 atomic_dec(stat);
47965 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
47966
47967 #define __fscache_stat(stat) (NULL)
47968 #define fscache_stat(stat) do {} while (0)
47969 +#define fscache_stat_unchecked(stat) do {} while (0)
47970 #define fscache_stat_d(stat) do {} while (0)
47971 #endif
47972
47973 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
47974 index b6b897c..0ffff9c 100644
47975 --- a/fs/fscache/object.c
47976 +++ b/fs/fscache/object.c
47977 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47978 /* update the object metadata on disk */
47979 case FSCACHE_OBJECT_UPDATING:
47980 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
47981 - fscache_stat(&fscache_n_updates_run);
47982 + fscache_stat_unchecked(&fscache_n_updates_run);
47983 fscache_stat(&fscache_n_cop_update_object);
47984 object->cache->ops->update_object(object);
47985 fscache_stat_d(&fscache_n_cop_update_object);
47986 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47987 spin_lock(&object->lock);
47988 object->state = FSCACHE_OBJECT_DEAD;
47989 spin_unlock(&object->lock);
47990 - fscache_stat(&fscache_n_object_dead);
47991 + fscache_stat_unchecked(&fscache_n_object_dead);
47992 goto terminal_transit;
47993
47994 /* handle the parent cache of this object being withdrawn from
47995 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47996 spin_lock(&object->lock);
47997 object->state = FSCACHE_OBJECT_DEAD;
47998 spin_unlock(&object->lock);
47999 - fscache_stat(&fscache_n_object_dead);
48000 + fscache_stat_unchecked(&fscache_n_object_dead);
48001 goto terminal_transit;
48002
48003 /* complain about the object being woken up once it is
48004 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48005 parent->cookie->def->name, cookie->def->name,
48006 object->cache->tag->name);
48007
48008 - fscache_stat(&fscache_n_object_lookups);
48009 + fscache_stat_unchecked(&fscache_n_object_lookups);
48010 fscache_stat(&fscache_n_cop_lookup_object);
48011 ret = object->cache->ops->lookup_object(object);
48012 fscache_stat_d(&fscache_n_cop_lookup_object);
48013 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48014 if (ret == -ETIMEDOUT) {
48015 /* probably stuck behind another object, so move this one to
48016 * the back of the queue */
48017 - fscache_stat(&fscache_n_object_lookups_timed_out);
48018 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48019 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48020 }
48021
48022 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48023
48024 spin_lock(&object->lock);
48025 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48026 - fscache_stat(&fscache_n_object_lookups_negative);
48027 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48028
48029 /* transit here to allow write requests to begin stacking up
48030 * and read requests to begin returning ENODATA */
48031 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48032 * result, in which case there may be data available */
48033 spin_lock(&object->lock);
48034 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48035 - fscache_stat(&fscache_n_object_lookups_positive);
48036 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48037
48038 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48039
48040 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48041 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48042 } else {
48043 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48044 - fscache_stat(&fscache_n_object_created);
48045 + fscache_stat_unchecked(&fscache_n_object_created);
48046
48047 object->state = FSCACHE_OBJECT_AVAILABLE;
48048 spin_unlock(&object->lock);
48049 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48050 fscache_enqueue_dependents(object);
48051
48052 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48053 - fscache_stat(&fscache_n_object_avail);
48054 + fscache_stat_unchecked(&fscache_n_object_avail);
48055
48056 _leave("");
48057 }
48058 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48059 enum fscache_checkaux result;
48060
48061 if (!object->cookie->def->check_aux) {
48062 - fscache_stat(&fscache_n_checkaux_none);
48063 + fscache_stat_unchecked(&fscache_n_checkaux_none);
48064 return FSCACHE_CHECKAUX_OKAY;
48065 }
48066
48067 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48068 switch (result) {
48069 /* entry okay as is */
48070 case FSCACHE_CHECKAUX_OKAY:
48071 - fscache_stat(&fscache_n_checkaux_okay);
48072 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
48073 break;
48074
48075 /* entry requires update */
48076 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48077 - fscache_stat(&fscache_n_checkaux_update);
48078 + fscache_stat_unchecked(&fscache_n_checkaux_update);
48079 break;
48080
48081 /* entry requires deletion */
48082 case FSCACHE_CHECKAUX_OBSOLETE:
48083 - fscache_stat(&fscache_n_checkaux_obsolete);
48084 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48085 break;
48086
48087 default:
48088 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48089 index 30afdfa..2256596 100644
48090 --- a/fs/fscache/operation.c
48091 +++ b/fs/fscache/operation.c
48092 @@ -17,7 +17,7 @@
48093 #include <linux/slab.h>
48094 #include "internal.h"
48095
48096 -atomic_t fscache_op_debug_id;
48097 +atomic_unchecked_t fscache_op_debug_id;
48098 EXPORT_SYMBOL(fscache_op_debug_id);
48099
48100 /**
48101 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48102 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48103 ASSERTCMP(atomic_read(&op->usage), >, 0);
48104
48105 - fscache_stat(&fscache_n_op_enqueue);
48106 + fscache_stat_unchecked(&fscache_n_op_enqueue);
48107 switch (op->flags & FSCACHE_OP_TYPE) {
48108 case FSCACHE_OP_ASYNC:
48109 _debug("queue async");
48110 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48111 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48112 if (op->processor)
48113 fscache_enqueue_operation(op);
48114 - fscache_stat(&fscache_n_op_run);
48115 + fscache_stat_unchecked(&fscache_n_op_run);
48116 }
48117
48118 /*
48119 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48120 if (object->n_ops > 1) {
48121 atomic_inc(&op->usage);
48122 list_add_tail(&op->pend_link, &object->pending_ops);
48123 - fscache_stat(&fscache_n_op_pend);
48124 + fscache_stat_unchecked(&fscache_n_op_pend);
48125 } else if (!list_empty(&object->pending_ops)) {
48126 atomic_inc(&op->usage);
48127 list_add_tail(&op->pend_link, &object->pending_ops);
48128 - fscache_stat(&fscache_n_op_pend);
48129 + fscache_stat_unchecked(&fscache_n_op_pend);
48130 fscache_start_operations(object);
48131 } else {
48132 ASSERTCMP(object->n_in_progress, ==, 0);
48133 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48134 object->n_exclusive++; /* reads and writes must wait */
48135 atomic_inc(&op->usage);
48136 list_add_tail(&op->pend_link, &object->pending_ops);
48137 - fscache_stat(&fscache_n_op_pend);
48138 + fscache_stat_unchecked(&fscache_n_op_pend);
48139 ret = 0;
48140 } else {
48141 /* not allowed to submit ops in any other state */
48142 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48143 if (object->n_exclusive > 0) {
48144 atomic_inc(&op->usage);
48145 list_add_tail(&op->pend_link, &object->pending_ops);
48146 - fscache_stat(&fscache_n_op_pend);
48147 + fscache_stat_unchecked(&fscache_n_op_pend);
48148 } else if (!list_empty(&object->pending_ops)) {
48149 atomic_inc(&op->usage);
48150 list_add_tail(&op->pend_link, &object->pending_ops);
48151 - fscache_stat(&fscache_n_op_pend);
48152 + fscache_stat_unchecked(&fscache_n_op_pend);
48153 fscache_start_operations(object);
48154 } else {
48155 ASSERTCMP(object->n_exclusive, ==, 0);
48156 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48157 object->n_ops++;
48158 atomic_inc(&op->usage);
48159 list_add_tail(&op->pend_link, &object->pending_ops);
48160 - fscache_stat(&fscache_n_op_pend);
48161 + fscache_stat_unchecked(&fscache_n_op_pend);
48162 ret = 0;
48163 } else if (object->state == FSCACHE_OBJECT_DYING ||
48164 object->state == FSCACHE_OBJECT_LC_DYING ||
48165 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48166 - fscache_stat(&fscache_n_op_rejected);
48167 + fscache_stat_unchecked(&fscache_n_op_rejected);
48168 ret = -ENOBUFS;
48169 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48170 fscache_report_unexpected_submission(object, op, ostate);
48171 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48172
48173 ret = -EBUSY;
48174 if (!list_empty(&op->pend_link)) {
48175 - fscache_stat(&fscache_n_op_cancelled);
48176 + fscache_stat_unchecked(&fscache_n_op_cancelled);
48177 list_del_init(&op->pend_link);
48178 object->n_ops--;
48179 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48180 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48181 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48182 BUG();
48183
48184 - fscache_stat(&fscache_n_op_release);
48185 + fscache_stat_unchecked(&fscache_n_op_release);
48186
48187 if (op->release) {
48188 op->release(op);
48189 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48190 * lock, and defer it otherwise */
48191 if (!spin_trylock(&object->lock)) {
48192 _debug("defer put");
48193 - fscache_stat(&fscache_n_op_deferred_release);
48194 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
48195
48196 cache = object->cache;
48197 spin_lock(&cache->op_gc_list_lock);
48198 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48199
48200 _debug("GC DEFERRED REL OBJ%x OP%x",
48201 object->debug_id, op->debug_id);
48202 - fscache_stat(&fscache_n_op_gc);
48203 + fscache_stat_unchecked(&fscache_n_op_gc);
48204
48205 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48206
48207 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48208 index 3f7a59b..cf196cc 100644
48209 --- a/fs/fscache/page.c
48210 +++ b/fs/fscache/page.c
48211 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48212 val = radix_tree_lookup(&cookie->stores, page->index);
48213 if (!val) {
48214 rcu_read_unlock();
48215 - fscache_stat(&fscache_n_store_vmscan_not_storing);
48216 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48217 __fscache_uncache_page(cookie, page);
48218 return true;
48219 }
48220 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48221 spin_unlock(&cookie->stores_lock);
48222
48223 if (xpage) {
48224 - fscache_stat(&fscache_n_store_vmscan_cancelled);
48225 - fscache_stat(&fscache_n_store_radix_deletes);
48226 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48227 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48228 ASSERTCMP(xpage, ==, page);
48229 } else {
48230 - fscache_stat(&fscache_n_store_vmscan_gone);
48231 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48232 }
48233
48234 wake_up_bit(&cookie->flags, 0);
48235 @@ -107,7 +107,7 @@ page_busy:
48236 /* we might want to wait here, but that could deadlock the allocator as
48237 * the work threads writing to the cache may all end up sleeping
48238 * on memory allocation */
48239 - fscache_stat(&fscache_n_store_vmscan_busy);
48240 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48241 return false;
48242 }
48243 EXPORT_SYMBOL(__fscache_maybe_release_page);
48244 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48245 FSCACHE_COOKIE_STORING_TAG);
48246 if (!radix_tree_tag_get(&cookie->stores, page->index,
48247 FSCACHE_COOKIE_PENDING_TAG)) {
48248 - fscache_stat(&fscache_n_store_radix_deletes);
48249 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48250 xpage = radix_tree_delete(&cookie->stores, page->index);
48251 }
48252 spin_unlock(&cookie->stores_lock);
48253 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48254
48255 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48256
48257 - fscache_stat(&fscache_n_attr_changed_calls);
48258 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48259
48260 if (fscache_object_is_active(object)) {
48261 fscache_stat(&fscache_n_cop_attr_changed);
48262 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48263
48264 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48265
48266 - fscache_stat(&fscache_n_attr_changed);
48267 + fscache_stat_unchecked(&fscache_n_attr_changed);
48268
48269 op = kzalloc(sizeof(*op), GFP_KERNEL);
48270 if (!op) {
48271 - fscache_stat(&fscache_n_attr_changed_nomem);
48272 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48273 _leave(" = -ENOMEM");
48274 return -ENOMEM;
48275 }
48276 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48277 if (fscache_submit_exclusive_op(object, op) < 0)
48278 goto nobufs;
48279 spin_unlock(&cookie->lock);
48280 - fscache_stat(&fscache_n_attr_changed_ok);
48281 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48282 fscache_put_operation(op);
48283 _leave(" = 0");
48284 return 0;
48285 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48286 nobufs:
48287 spin_unlock(&cookie->lock);
48288 kfree(op);
48289 - fscache_stat(&fscache_n_attr_changed_nobufs);
48290 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48291 _leave(" = %d", -ENOBUFS);
48292 return -ENOBUFS;
48293 }
48294 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48295 /* allocate a retrieval operation and attempt to submit it */
48296 op = kzalloc(sizeof(*op), GFP_NOIO);
48297 if (!op) {
48298 - fscache_stat(&fscache_n_retrievals_nomem);
48299 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48300 return NULL;
48301 }
48302
48303 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48304 return 0;
48305 }
48306
48307 - fscache_stat(&fscache_n_retrievals_wait);
48308 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
48309
48310 jif = jiffies;
48311 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48312 fscache_wait_bit_interruptible,
48313 TASK_INTERRUPTIBLE) != 0) {
48314 - fscache_stat(&fscache_n_retrievals_intr);
48315 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48316 _leave(" = -ERESTARTSYS");
48317 return -ERESTARTSYS;
48318 }
48319 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48320 */
48321 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48322 struct fscache_retrieval *op,
48323 - atomic_t *stat_op_waits,
48324 - atomic_t *stat_object_dead)
48325 + atomic_unchecked_t *stat_op_waits,
48326 + atomic_unchecked_t *stat_object_dead)
48327 {
48328 int ret;
48329
48330 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48331 goto check_if_dead;
48332
48333 _debug(">>> WT");
48334 - fscache_stat(stat_op_waits);
48335 + fscache_stat_unchecked(stat_op_waits);
48336 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48337 fscache_wait_bit_interruptible,
48338 TASK_INTERRUPTIBLE) < 0) {
48339 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48340
48341 check_if_dead:
48342 if (unlikely(fscache_object_is_dead(object))) {
48343 - fscache_stat(stat_object_dead);
48344 + fscache_stat_unchecked(stat_object_dead);
48345 return -ENOBUFS;
48346 }
48347 return 0;
48348 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48349
48350 _enter("%p,%p,,,", cookie, page);
48351
48352 - fscache_stat(&fscache_n_retrievals);
48353 + fscache_stat_unchecked(&fscache_n_retrievals);
48354
48355 if (hlist_empty(&cookie->backing_objects))
48356 goto nobufs;
48357 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48358 goto nobufs_unlock;
48359 spin_unlock(&cookie->lock);
48360
48361 - fscache_stat(&fscache_n_retrieval_ops);
48362 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48363
48364 /* pin the netfs read context in case we need to do the actual netfs
48365 * read because we've encountered a cache read failure */
48366 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48367
48368 error:
48369 if (ret == -ENOMEM)
48370 - fscache_stat(&fscache_n_retrievals_nomem);
48371 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48372 else if (ret == -ERESTARTSYS)
48373 - fscache_stat(&fscache_n_retrievals_intr);
48374 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48375 else if (ret == -ENODATA)
48376 - fscache_stat(&fscache_n_retrievals_nodata);
48377 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48378 else if (ret < 0)
48379 - fscache_stat(&fscache_n_retrievals_nobufs);
48380 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48381 else
48382 - fscache_stat(&fscache_n_retrievals_ok);
48383 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48384
48385 fscache_put_retrieval(op);
48386 _leave(" = %d", ret);
48387 @@ -429,7 +429,7 @@ nobufs_unlock:
48388 spin_unlock(&cookie->lock);
48389 kfree(op);
48390 nobufs:
48391 - fscache_stat(&fscache_n_retrievals_nobufs);
48392 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48393 _leave(" = -ENOBUFS");
48394 return -ENOBUFS;
48395 }
48396 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48397
48398 _enter("%p,,%d,,,", cookie, *nr_pages);
48399
48400 - fscache_stat(&fscache_n_retrievals);
48401 + fscache_stat_unchecked(&fscache_n_retrievals);
48402
48403 if (hlist_empty(&cookie->backing_objects))
48404 goto nobufs;
48405 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48406 goto nobufs_unlock;
48407 spin_unlock(&cookie->lock);
48408
48409 - fscache_stat(&fscache_n_retrieval_ops);
48410 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48411
48412 /* pin the netfs read context in case we need to do the actual netfs
48413 * read because we've encountered a cache read failure */
48414 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48415
48416 error:
48417 if (ret == -ENOMEM)
48418 - fscache_stat(&fscache_n_retrievals_nomem);
48419 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48420 else if (ret == -ERESTARTSYS)
48421 - fscache_stat(&fscache_n_retrievals_intr);
48422 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48423 else if (ret == -ENODATA)
48424 - fscache_stat(&fscache_n_retrievals_nodata);
48425 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48426 else if (ret < 0)
48427 - fscache_stat(&fscache_n_retrievals_nobufs);
48428 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48429 else
48430 - fscache_stat(&fscache_n_retrievals_ok);
48431 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48432
48433 fscache_put_retrieval(op);
48434 _leave(" = %d", ret);
48435 @@ -545,7 +545,7 @@ nobufs_unlock:
48436 spin_unlock(&cookie->lock);
48437 kfree(op);
48438 nobufs:
48439 - fscache_stat(&fscache_n_retrievals_nobufs);
48440 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48441 _leave(" = -ENOBUFS");
48442 return -ENOBUFS;
48443 }
48444 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48445
48446 _enter("%p,%p,,,", cookie, page);
48447
48448 - fscache_stat(&fscache_n_allocs);
48449 + fscache_stat_unchecked(&fscache_n_allocs);
48450
48451 if (hlist_empty(&cookie->backing_objects))
48452 goto nobufs;
48453 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48454 goto nobufs_unlock;
48455 spin_unlock(&cookie->lock);
48456
48457 - fscache_stat(&fscache_n_alloc_ops);
48458 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48459
48460 ret = fscache_wait_for_retrieval_activation(
48461 object, op,
48462 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48463
48464 error:
48465 if (ret == -ERESTARTSYS)
48466 - fscache_stat(&fscache_n_allocs_intr);
48467 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48468 else if (ret < 0)
48469 - fscache_stat(&fscache_n_allocs_nobufs);
48470 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48471 else
48472 - fscache_stat(&fscache_n_allocs_ok);
48473 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48474
48475 fscache_put_retrieval(op);
48476 _leave(" = %d", ret);
48477 @@ -625,7 +625,7 @@ nobufs_unlock:
48478 spin_unlock(&cookie->lock);
48479 kfree(op);
48480 nobufs:
48481 - fscache_stat(&fscache_n_allocs_nobufs);
48482 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48483 _leave(" = -ENOBUFS");
48484 return -ENOBUFS;
48485 }
48486 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48487
48488 spin_lock(&cookie->stores_lock);
48489
48490 - fscache_stat(&fscache_n_store_calls);
48491 + fscache_stat_unchecked(&fscache_n_store_calls);
48492
48493 /* find a page to store */
48494 page = NULL;
48495 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48496 page = results[0];
48497 _debug("gang %d [%lx]", n, page->index);
48498 if (page->index > op->store_limit) {
48499 - fscache_stat(&fscache_n_store_pages_over_limit);
48500 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48501 goto superseded;
48502 }
48503
48504 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48505 spin_unlock(&cookie->stores_lock);
48506 spin_unlock(&object->lock);
48507
48508 - fscache_stat(&fscache_n_store_pages);
48509 + fscache_stat_unchecked(&fscache_n_store_pages);
48510 fscache_stat(&fscache_n_cop_write_page);
48511 ret = object->cache->ops->write_page(op, page);
48512 fscache_stat_d(&fscache_n_cop_write_page);
48513 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48514 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48515 ASSERT(PageFsCache(page));
48516
48517 - fscache_stat(&fscache_n_stores);
48518 + fscache_stat_unchecked(&fscache_n_stores);
48519
48520 op = kzalloc(sizeof(*op), GFP_NOIO);
48521 if (!op)
48522 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48523 spin_unlock(&cookie->stores_lock);
48524 spin_unlock(&object->lock);
48525
48526 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48527 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48528 op->store_limit = object->store_limit;
48529
48530 if (fscache_submit_op(object, &op->op) < 0)
48531 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48532
48533 spin_unlock(&cookie->lock);
48534 radix_tree_preload_end();
48535 - fscache_stat(&fscache_n_store_ops);
48536 - fscache_stat(&fscache_n_stores_ok);
48537 + fscache_stat_unchecked(&fscache_n_store_ops);
48538 + fscache_stat_unchecked(&fscache_n_stores_ok);
48539
48540 /* the work queue now carries its own ref on the object */
48541 fscache_put_operation(&op->op);
48542 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48543 return 0;
48544
48545 already_queued:
48546 - fscache_stat(&fscache_n_stores_again);
48547 + fscache_stat_unchecked(&fscache_n_stores_again);
48548 already_pending:
48549 spin_unlock(&cookie->stores_lock);
48550 spin_unlock(&object->lock);
48551 spin_unlock(&cookie->lock);
48552 radix_tree_preload_end();
48553 kfree(op);
48554 - fscache_stat(&fscache_n_stores_ok);
48555 + fscache_stat_unchecked(&fscache_n_stores_ok);
48556 _leave(" = 0");
48557 return 0;
48558
48559 @@ -851,14 +851,14 @@ nobufs:
48560 spin_unlock(&cookie->lock);
48561 radix_tree_preload_end();
48562 kfree(op);
48563 - fscache_stat(&fscache_n_stores_nobufs);
48564 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48565 _leave(" = -ENOBUFS");
48566 return -ENOBUFS;
48567
48568 nomem_free:
48569 kfree(op);
48570 nomem:
48571 - fscache_stat(&fscache_n_stores_oom);
48572 + fscache_stat_unchecked(&fscache_n_stores_oom);
48573 _leave(" = -ENOMEM");
48574 return -ENOMEM;
48575 }
48576 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48577 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48578 ASSERTCMP(page, !=, NULL);
48579
48580 - fscache_stat(&fscache_n_uncaches);
48581 + fscache_stat_unchecked(&fscache_n_uncaches);
48582
48583 /* cache withdrawal may beat us to it */
48584 if (!PageFsCache(page))
48585 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48586 unsigned long loop;
48587
48588 #ifdef CONFIG_FSCACHE_STATS
48589 - atomic_add(pagevec->nr, &fscache_n_marks);
48590 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48591 #endif
48592
48593 for (loop = 0; loop < pagevec->nr; loop++) {
48594 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48595 index 4765190..2a067f2 100644
48596 --- a/fs/fscache/stats.c
48597 +++ b/fs/fscache/stats.c
48598 @@ -18,95 +18,95 @@
48599 /*
48600 * operation counters
48601 */
48602 -atomic_t fscache_n_op_pend;
48603 -atomic_t fscache_n_op_run;
48604 -atomic_t fscache_n_op_enqueue;
48605 -atomic_t fscache_n_op_requeue;
48606 -atomic_t fscache_n_op_deferred_release;
48607 -atomic_t fscache_n_op_release;
48608 -atomic_t fscache_n_op_gc;
48609 -atomic_t fscache_n_op_cancelled;
48610 -atomic_t fscache_n_op_rejected;
48611 +atomic_unchecked_t fscache_n_op_pend;
48612 +atomic_unchecked_t fscache_n_op_run;
48613 +atomic_unchecked_t fscache_n_op_enqueue;
48614 +atomic_unchecked_t fscache_n_op_requeue;
48615 +atomic_unchecked_t fscache_n_op_deferred_release;
48616 +atomic_unchecked_t fscache_n_op_release;
48617 +atomic_unchecked_t fscache_n_op_gc;
48618 +atomic_unchecked_t fscache_n_op_cancelled;
48619 +atomic_unchecked_t fscache_n_op_rejected;
48620
48621 -atomic_t fscache_n_attr_changed;
48622 -atomic_t fscache_n_attr_changed_ok;
48623 -atomic_t fscache_n_attr_changed_nobufs;
48624 -atomic_t fscache_n_attr_changed_nomem;
48625 -atomic_t fscache_n_attr_changed_calls;
48626 +atomic_unchecked_t fscache_n_attr_changed;
48627 +atomic_unchecked_t fscache_n_attr_changed_ok;
48628 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48629 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48630 +atomic_unchecked_t fscache_n_attr_changed_calls;
48631
48632 -atomic_t fscache_n_allocs;
48633 -atomic_t fscache_n_allocs_ok;
48634 -atomic_t fscache_n_allocs_wait;
48635 -atomic_t fscache_n_allocs_nobufs;
48636 -atomic_t fscache_n_allocs_intr;
48637 -atomic_t fscache_n_allocs_object_dead;
48638 -atomic_t fscache_n_alloc_ops;
48639 -atomic_t fscache_n_alloc_op_waits;
48640 +atomic_unchecked_t fscache_n_allocs;
48641 +atomic_unchecked_t fscache_n_allocs_ok;
48642 +atomic_unchecked_t fscache_n_allocs_wait;
48643 +atomic_unchecked_t fscache_n_allocs_nobufs;
48644 +atomic_unchecked_t fscache_n_allocs_intr;
48645 +atomic_unchecked_t fscache_n_allocs_object_dead;
48646 +atomic_unchecked_t fscache_n_alloc_ops;
48647 +atomic_unchecked_t fscache_n_alloc_op_waits;
48648
48649 -atomic_t fscache_n_retrievals;
48650 -atomic_t fscache_n_retrievals_ok;
48651 -atomic_t fscache_n_retrievals_wait;
48652 -atomic_t fscache_n_retrievals_nodata;
48653 -atomic_t fscache_n_retrievals_nobufs;
48654 -atomic_t fscache_n_retrievals_intr;
48655 -atomic_t fscache_n_retrievals_nomem;
48656 -atomic_t fscache_n_retrievals_object_dead;
48657 -atomic_t fscache_n_retrieval_ops;
48658 -atomic_t fscache_n_retrieval_op_waits;
48659 +atomic_unchecked_t fscache_n_retrievals;
48660 +atomic_unchecked_t fscache_n_retrievals_ok;
48661 +atomic_unchecked_t fscache_n_retrievals_wait;
48662 +atomic_unchecked_t fscache_n_retrievals_nodata;
48663 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48664 +atomic_unchecked_t fscache_n_retrievals_intr;
48665 +atomic_unchecked_t fscache_n_retrievals_nomem;
48666 +atomic_unchecked_t fscache_n_retrievals_object_dead;
48667 +atomic_unchecked_t fscache_n_retrieval_ops;
48668 +atomic_unchecked_t fscache_n_retrieval_op_waits;
48669
48670 -atomic_t fscache_n_stores;
48671 -atomic_t fscache_n_stores_ok;
48672 -atomic_t fscache_n_stores_again;
48673 -atomic_t fscache_n_stores_nobufs;
48674 -atomic_t fscache_n_stores_oom;
48675 -atomic_t fscache_n_store_ops;
48676 -atomic_t fscache_n_store_calls;
48677 -atomic_t fscache_n_store_pages;
48678 -atomic_t fscache_n_store_radix_deletes;
48679 -atomic_t fscache_n_store_pages_over_limit;
48680 +atomic_unchecked_t fscache_n_stores;
48681 +atomic_unchecked_t fscache_n_stores_ok;
48682 +atomic_unchecked_t fscache_n_stores_again;
48683 +atomic_unchecked_t fscache_n_stores_nobufs;
48684 +atomic_unchecked_t fscache_n_stores_oom;
48685 +atomic_unchecked_t fscache_n_store_ops;
48686 +atomic_unchecked_t fscache_n_store_calls;
48687 +atomic_unchecked_t fscache_n_store_pages;
48688 +atomic_unchecked_t fscache_n_store_radix_deletes;
48689 +atomic_unchecked_t fscache_n_store_pages_over_limit;
48690
48691 -atomic_t fscache_n_store_vmscan_not_storing;
48692 -atomic_t fscache_n_store_vmscan_gone;
48693 -atomic_t fscache_n_store_vmscan_busy;
48694 -atomic_t fscache_n_store_vmscan_cancelled;
48695 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48696 +atomic_unchecked_t fscache_n_store_vmscan_gone;
48697 +atomic_unchecked_t fscache_n_store_vmscan_busy;
48698 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48699
48700 -atomic_t fscache_n_marks;
48701 -atomic_t fscache_n_uncaches;
48702 +atomic_unchecked_t fscache_n_marks;
48703 +atomic_unchecked_t fscache_n_uncaches;
48704
48705 -atomic_t fscache_n_acquires;
48706 -atomic_t fscache_n_acquires_null;
48707 -atomic_t fscache_n_acquires_no_cache;
48708 -atomic_t fscache_n_acquires_ok;
48709 -atomic_t fscache_n_acquires_nobufs;
48710 -atomic_t fscache_n_acquires_oom;
48711 +atomic_unchecked_t fscache_n_acquires;
48712 +atomic_unchecked_t fscache_n_acquires_null;
48713 +atomic_unchecked_t fscache_n_acquires_no_cache;
48714 +atomic_unchecked_t fscache_n_acquires_ok;
48715 +atomic_unchecked_t fscache_n_acquires_nobufs;
48716 +atomic_unchecked_t fscache_n_acquires_oom;
48717
48718 -atomic_t fscache_n_updates;
48719 -atomic_t fscache_n_updates_null;
48720 -atomic_t fscache_n_updates_run;
48721 +atomic_unchecked_t fscache_n_updates;
48722 +atomic_unchecked_t fscache_n_updates_null;
48723 +atomic_unchecked_t fscache_n_updates_run;
48724
48725 -atomic_t fscache_n_relinquishes;
48726 -atomic_t fscache_n_relinquishes_null;
48727 -atomic_t fscache_n_relinquishes_waitcrt;
48728 -atomic_t fscache_n_relinquishes_retire;
48729 +atomic_unchecked_t fscache_n_relinquishes;
48730 +atomic_unchecked_t fscache_n_relinquishes_null;
48731 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48732 +atomic_unchecked_t fscache_n_relinquishes_retire;
48733
48734 -atomic_t fscache_n_cookie_index;
48735 -atomic_t fscache_n_cookie_data;
48736 -atomic_t fscache_n_cookie_special;
48737 +atomic_unchecked_t fscache_n_cookie_index;
48738 +atomic_unchecked_t fscache_n_cookie_data;
48739 +atomic_unchecked_t fscache_n_cookie_special;
48740
48741 -atomic_t fscache_n_object_alloc;
48742 -atomic_t fscache_n_object_no_alloc;
48743 -atomic_t fscache_n_object_lookups;
48744 -atomic_t fscache_n_object_lookups_negative;
48745 -atomic_t fscache_n_object_lookups_positive;
48746 -atomic_t fscache_n_object_lookups_timed_out;
48747 -atomic_t fscache_n_object_created;
48748 -atomic_t fscache_n_object_avail;
48749 -atomic_t fscache_n_object_dead;
48750 +atomic_unchecked_t fscache_n_object_alloc;
48751 +atomic_unchecked_t fscache_n_object_no_alloc;
48752 +atomic_unchecked_t fscache_n_object_lookups;
48753 +atomic_unchecked_t fscache_n_object_lookups_negative;
48754 +atomic_unchecked_t fscache_n_object_lookups_positive;
48755 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
48756 +atomic_unchecked_t fscache_n_object_created;
48757 +atomic_unchecked_t fscache_n_object_avail;
48758 +atomic_unchecked_t fscache_n_object_dead;
48759
48760 -atomic_t fscache_n_checkaux_none;
48761 -atomic_t fscache_n_checkaux_okay;
48762 -atomic_t fscache_n_checkaux_update;
48763 -atomic_t fscache_n_checkaux_obsolete;
48764 +atomic_unchecked_t fscache_n_checkaux_none;
48765 +atomic_unchecked_t fscache_n_checkaux_okay;
48766 +atomic_unchecked_t fscache_n_checkaux_update;
48767 +atomic_unchecked_t fscache_n_checkaux_obsolete;
48768
48769 atomic_t fscache_n_cop_alloc_object;
48770 atomic_t fscache_n_cop_lookup_object;
48771 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
48772 seq_puts(m, "FS-Cache statistics\n");
48773
48774 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
48775 - atomic_read(&fscache_n_cookie_index),
48776 - atomic_read(&fscache_n_cookie_data),
48777 - atomic_read(&fscache_n_cookie_special));
48778 + atomic_read_unchecked(&fscache_n_cookie_index),
48779 + atomic_read_unchecked(&fscache_n_cookie_data),
48780 + atomic_read_unchecked(&fscache_n_cookie_special));
48781
48782 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
48783 - atomic_read(&fscache_n_object_alloc),
48784 - atomic_read(&fscache_n_object_no_alloc),
48785 - atomic_read(&fscache_n_object_avail),
48786 - atomic_read(&fscache_n_object_dead));
48787 + atomic_read_unchecked(&fscache_n_object_alloc),
48788 + atomic_read_unchecked(&fscache_n_object_no_alloc),
48789 + atomic_read_unchecked(&fscache_n_object_avail),
48790 + atomic_read_unchecked(&fscache_n_object_dead));
48791 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
48792 - atomic_read(&fscache_n_checkaux_none),
48793 - atomic_read(&fscache_n_checkaux_okay),
48794 - atomic_read(&fscache_n_checkaux_update),
48795 - atomic_read(&fscache_n_checkaux_obsolete));
48796 + atomic_read_unchecked(&fscache_n_checkaux_none),
48797 + atomic_read_unchecked(&fscache_n_checkaux_okay),
48798 + atomic_read_unchecked(&fscache_n_checkaux_update),
48799 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
48800
48801 seq_printf(m, "Pages : mrk=%u unc=%u\n",
48802 - atomic_read(&fscache_n_marks),
48803 - atomic_read(&fscache_n_uncaches));
48804 + atomic_read_unchecked(&fscache_n_marks),
48805 + atomic_read_unchecked(&fscache_n_uncaches));
48806
48807 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
48808 " oom=%u\n",
48809 - atomic_read(&fscache_n_acquires),
48810 - atomic_read(&fscache_n_acquires_null),
48811 - atomic_read(&fscache_n_acquires_no_cache),
48812 - atomic_read(&fscache_n_acquires_ok),
48813 - atomic_read(&fscache_n_acquires_nobufs),
48814 - atomic_read(&fscache_n_acquires_oom));
48815 + atomic_read_unchecked(&fscache_n_acquires),
48816 + atomic_read_unchecked(&fscache_n_acquires_null),
48817 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
48818 + atomic_read_unchecked(&fscache_n_acquires_ok),
48819 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
48820 + atomic_read_unchecked(&fscache_n_acquires_oom));
48821
48822 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
48823 - atomic_read(&fscache_n_object_lookups),
48824 - atomic_read(&fscache_n_object_lookups_negative),
48825 - atomic_read(&fscache_n_object_lookups_positive),
48826 - atomic_read(&fscache_n_object_created),
48827 - atomic_read(&fscache_n_object_lookups_timed_out));
48828 + atomic_read_unchecked(&fscache_n_object_lookups),
48829 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
48830 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
48831 + atomic_read_unchecked(&fscache_n_object_created),
48832 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
48833
48834 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
48835 - atomic_read(&fscache_n_updates),
48836 - atomic_read(&fscache_n_updates_null),
48837 - atomic_read(&fscache_n_updates_run));
48838 + atomic_read_unchecked(&fscache_n_updates),
48839 + atomic_read_unchecked(&fscache_n_updates_null),
48840 + atomic_read_unchecked(&fscache_n_updates_run));
48841
48842 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
48843 - atomic_read(&fscache_n_relinquishes),
48844 - atomic_read(&fscache_n_relinquishes_null),
48845 - atomic_read(&fscache_n_relinquishes_waitcrt),
48846 - atomic_read(&fscache_n_relinquishes_retire));
48847 + atomic_read_unchecked(&fscache_n_relinquishes),
48848 + atomic_read_unchecked(&fscache_n_relinquishes_null),
48849 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
48850 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
48851
48852 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
48853 - atomic_read(&fscache_n_attr_changed),
48854 - atomic_read(&fscache_n_attr_changed_ok),
48855 - atomic_read(&fscache_n_attr_changed_nobufs),
48856 - atomic_read(&fscache_n_attr_changed_nomem),
48857 - atomic_read(&fscache_n_attr_changed_calls));
48858 + atomic_read_unchecked(&fscache_n_attr_changed),
48859 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
48860 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
48861 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
48862 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
48863
48864 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
48865 - atomic_read(&fscache_n_allocs),
48866 - atomic_read(&fscache_n_allocs_ok),
48867 - atomic_read(&fscache_n_allocs_wait),
48868 - atomic_read(&fscache_n_allocs_nobufs),
48869 - atomic_read(&fscache_n_allocs_intr));
48870 + atomic_read_unchecked(&fscache_n_allocs),
48871 + atomic_read_unchecked(&fscache_n_allocs_ok),
48872 + atomic_read_unchecked(&fscache_n_allocs_wait),
48873 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
48874 + atomic_read_unchecked(&fscache_n_allocs_intr));
48875 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
48876 - atomic_read(&fscache_n_alloc_ops),
48877 - atomic_read(&fscache_n_alloc_op_waits),
48878 - atomic_read(&fscache_n_allocs_object_dead));
48879 + atomic_read_unchecked(&fscache_n_alloc_ops),
48880 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
48881 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
48882
48883 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
48884 " int=%u oom=%u\n",
48885 - atomic_read(&fscache_n_retrievals),
48886 - atomic_read(&fscache_n_retrievals_ok),
48887 - atomic_read(&fscache_n_retrievals_wait),
48888 - atomic_read(&fscache_n_retrievals_nodata),
48889 - atomic_read(&fscache_n_retrievals_nobufs),
48890 - atomic_read(&fscache_n_retrievals_intr),
48891 - atomic_read(&fscache_n_retrievals_nomem));
48892 + atomic_read_unchecked(&fscache_n_retrievals),
48893 + atomic_read_unchecked(&fscache_n_retrievals_ok),
48894 + atomic_read_unchecked(&fscache_n_retrievals_wait),
48895 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
48896 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
48897 + atomic_read_unchecked(&fscache_n_retrievals_intr),
48898 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
48899 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
48900 - atomic_read(&fscache_n_retrieval_ops),
48901 - atomic_read(&fscache_n_retrieval_op_waits),
48902 - atomic_read(&fscache_n_retrievals_object_dead));
48903 + atomic_read_unchecked(&fscache_n_retrieval_ops),
48904 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
48905 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
48906
48907 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
48908 - atomic_read(&fscache_n_stores),
48909 - atomic_read(&fscache_n_stores_ok),
48910 - atomic_read(&fscache_n_stores_again),
48911 - atomic_read(&fscache_n_stores_nobufs),
48912 - atomic_read(&fscache_n_stores_oom));
48913 + atomic_read_unchecked(&fscache_n_stores),
48914 + atomic_read_unchecked(&fscache_n_stores_ok),
48915 + atomic_read_unchecked(&fscache_n_stores_again),
48916 + atomic_read_unchecked(&fscache_n_stores_nobufs),
48917 + atomic_read_unchecked(&fscache_n_stores_oom));
48918 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
48919 - atomic_read(&fscache_n_store_ops),
48920 - atomic_read(&fscache_n_store_calls),
48921 - atomic_read(&fscache_n_store_pages),
48922 - atomic_read(&fscache_n_store_radix_deletes),
48923 - atomic_read(&fscache_n_store_pages_over_limit));
48924 + atomic_read_unchecked(&fscache_n_store_ops),
48925 + atomic_read_unchecked(&fscache_n_store_calls),
48926 + atomic_read_unchecked(&fscache_n_store_pages),
48927 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
48928 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
48929
48930 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
48931 - atomic_read(&fscache_n_store_vmscan_not_storing),
48932 - atomic_read(&fscache_n_store_vmscan_gone),
48933 - atomic_read(&fscache_n_store_vmscan_busy),
48934 - atomic_read(&fscache_n_store_vmscan_cancelled));
48935 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
48936 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
48937 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
48938 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
48939
48940 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
48941 - atomic_read(&fscache_n_op_pend),
48942 - atomic_read(&fscache_n_op_run),
48943 - atomic_read(&fscache_n_op_enqueue),
48944 - atomic_read(&fscache_n_op_cancelled),
48945 - atomic_read(&fscache_n_op_rejected));
48946 + atomic_read_unchecked(&fscache_n_op_pend),
48947 + atomic_read_unchecked(&fscache_n_op_run),
48948 + atomic_read_unchecked(&fscache_n_op_enqueue),
48949 + atomic_read_unchecked(&fscache_n_op_cancelled),
48950 + atomic_read_unchecked(&fscache_n_op_rejected));
48951 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
48952 - atomic_read(&fscache_n_op_deferred_release),
48953 - atomic_read(&fscache_n_op_release),
48954 - atomic_read(&fscache_n_op_gc));
48955 + atomic_read_unchecked(&fscache_n_op_deferred_release),
48956 + atomic_read_unchecked(&fscache_n_op_release),
48957 + atomic_read_unchecked(&fscache_n_op_gc));
48958
48959 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
48960 atomic_read(&fscache_n_cop_alloc_object),
48961 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
48962 index ee8d550..7189d8c 100644
48963 --- a/fs/fuse/cuse.c
48964 +++ b/fs/fuse/cuse.c
48965 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
48966 INIT_LIST_HEAD(&cuse_conntbl[i]);
48967
48968 /* inherit and extend fuse_dev_operations */
48969 - cuse_channel_fops = fuse_dev_operations;
48970 - cuse_channel_fops.owner = THIS_MODULE;
48971 - cuse_channel_fops.open = cuse_channel_open;
48972 - cuse_channel_fops.release = cuse_channel_release;
48973 + pax_open_kernel();
48974 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
48975 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
48976 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
48977 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
48978 + pax_close_kernel();
48979
48980 cuse_class = class_create(THIS_MODULE, "cuse");
48981 if (IS_ERR(cuse_class))
48982 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
48983 index 8c23fa7..0e3aac7 100644
48984 --- a/fs/fuse/dev.c
48985 +++ b/fs/fuse/dev.c
48986 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
48987 ret = 0;
48988 pipe_lock(pipe);
48989
48990 - if (!pipe->readers) {
48991 + if (!atomic_read(&pipe->readers)) {
48992 send_sig(SIGPIPE, current, 0);
48993 if (!ret)
48994 ret = -EPIPE;
48995 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
48996 index 324bc08..4fdd56e 100644
48997 --- a/fs/fuse/dir.c
48998 +++ b/fs/fuse/dir.c
48999 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49000 return link;
49001 }
49002
49003 -static void free_link(char *link)
49004 +static void free_link(const char *link)
49005 {
49006 if (!IS_ERR(link))
49007 free_page((unsigned long) link);
49008 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49009 index 381893c..3793318 100644
49010 --- a/fs/gfs2/inode.c
49011 +++ b/fs/gfs2/inode.c
49012 @@ -1490,7 +1490,7 @@ out:
49013
49014 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49015 {
49016 - char *s = nd_get_link(nd);
49017 + const char *s = nd_get_link(nd);
49018 if (!IS_ERR(s))
49019 kfree(s);
49020 }
49021 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49022 index c5bc355..5a513bb 100644
49023 --- a/fs/hugetlbfs/inode.c
49024 +++ b/fs/hugetlbfs/inode.c
49025 @@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49026 .kill_sb = kill_litter_super,
49027 };
49028
49029 -static struct vfsmount *hugetlbfs_vfsmount;
49030 +struct vfsmount *hugetlbfs_vfsmount;
49031
49032 static int can_do_hugetlb_shm(void)
49033 {
49034 diff --git a/fs/inode.c b/fs/inode.c
49035 index 64999f1..8fad608 100644
49036 --- a/fs/inode.c
49037 +++ b/fs/inode.c
49038 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49039
49040 #ifdef CONFIG_SMP
49041 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49042 - static atomic_t shared_last_ino;
49043 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49044 + static atomic_unchecked_t shared_last_ino;
49045 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49046
49047 res = next - LAST_INO_BATCH;
49048 }
49049 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49050 index 4a6cf28..d3a29d3 100644
49051 --- a/fs/jffs2/erase.c
49052 +++ b/fs/jffs2/erase.c
49053 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49054 struct jffs2_unknown_node marker = {
49055 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49056 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49057 - .totlen = cpu_to_je32(c->cleanmarker_size)
49058 + .totlen = cpu_to_je32(c->cleanmarker_size),
49059 + .hdr_crc = cpu_to_je32(0)
49060 };
49061
49062 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49063 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49064 index a6597d6..41b30ec 100644
49065 --- a/fs/jffs2/wbuf.c
49066 +++ b/fs/jffs2/wbuf.c
49067 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49068 {
49069 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49070 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49071 - .totlen = constant_cpu_to_je32(8)
49072 + .totlen = constant_cpu_to_je32(8),
49073 + .hdr_crc = constant_cpu_to_je32(0)
49074 };
49075
49076 /*
49077 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49078 index 1a543be..d803c40 100644
49079 --- a/fs/jfs/super.c
49080 +++ b/fs/jfs/super.c
49081 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49082
49083 jfs_inode_cachep =
49084 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49085 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49086 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49087 init_once);
49088 if (jfs_inode_cachep == NULL)
49089 return -ENOMEM;
49090 diff --git a/fs/libfs.c b/fs/libfs.c
49091 index 7cc37ca..b3e3eec 100644
49092 --- a/fs/libfs.c
49093 +++ b/fs/libfs.c
49094 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49095
49096 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49097 struct dentry *next;
49098 + char d_name[sizeof(next->d_iname)];
49099 + const unsigned char *name;
49100 +
49101 next = list_entry(p, struct dentry, d_u.d_child);
49102 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49103 if (!simple_positive(next)) {
49104 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49105
49106 spin_unlock(&next->d_lock);
49107 spin_unlock(&dentry->d_lock);
49108 - if (filldir(dirent, next->d_name.name,
49109 + name = next->d_name.name;
49110 + if (name == next->d_iname) {
49111 + memcpy(d_name, name, next->d_name.len);
49112 + name = d_name;
49113 + }
49114 + if (filldir(dirent, name,
49115 next->d_name.len, filp->f_pos,
49116 next->d_inode->i_ino,
49117 dt_type(next->d_inode)) < 0)
49118 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49119 index 05d2912..760abfa 100644
49120 --- a/fs/lockd/clntproc.c
49121 +++ b/fs/lockd/clntproc.c
49122 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49123 /*
49124 * Cookie counter for NLM requests
49125 */
49126 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49127 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49128
49129 void nlmclnt_next_cookie(struct nlm_cookie *c)
49130 {
49131 - u32 cookie = atomic_inc_return(&nlm_cookie);
49132 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49133
49134 memcpy(c->data, &cookie, 4);
49135 c->len=4;
49136 diff --git a/fs/locks.c b/fs/locks.c
49137 index a94e331..060bce3 100644
49138 --- a/fs/locks.c
49139 +++ b/fs/locks.c
49140 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49141 return;
49142
49143 if (filp->f_op && filp->f_op->flock) {
49144 - struct file_lock fl = {
49145 + struct file_lock flock = {
49146 .fl_pid = current->tgid,
49147 .fl_file = filp,
49148 .fl_flags = FL_FLOCK,
49149 .fl_type = F_UNLCK,
49150 .fl_end = OFFSET_MAX,
49151 };
49152 - filp->f_op->flock(filp, F_SETLKW, &fl);
49153 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
49154 - fl.fl_ops->fl_release_private(&fl);
49155 + filp->f_op->flock(filp, F_SETLKW, &flock);
49156 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
49157 + flock.fl_ops->fl_release_private(&flock);
49158 }
49159
49160 lock_flocks();
49161 diff --git a/fs/namei.c b/fs/namei.c
49162 index 5f4cdf3..959a013 100644
49163 --- a/fs/namei.c
49164 +++ b/fs/namei.c
49165 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49166 if (ret != -EACCES)
49167 return ret;
49168
49169 +#ifdef CONFIG_GRKERNSEC
49170 + /* we'll block if we have to log due to a denied capability use */
49171 + if (mask & MAY_NOT_BLOCK)
49172 + return -ECHILD;
49173 +#endif
49174 +
49175 if (S_ISDIR(inode->i_mode)) {
49176 /* DACs are overridable for directories */
49177 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
49178 - return 0;
49179 if (!(mask & MAY_WRITE))
49180 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49181 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49182 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49183 return 0;
49184 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
49185 + return 0;
49186 return -EACCES;
49187 }
49188 /*
49189 + * Searching includes executable on directories, else just read.
49190 + */
49191 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49192 + if (mask == MAY_READ)
49193 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49194 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49195 + return 0;
49196 +
49197 + /*
49198 * Read/write DACs are always overridable.
49199 * Executable DACs are overridable when there is
49200 * at least one exec bit set.
49201 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49202 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49203 return 0;
49204
49205 - /*
49206 - * Searching includes executable on directories, else just read.
49207 - */
49208 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49209 - if (mask == MAY_READ)
49210 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49211 - return 0;
49212 -
49213 return -EACCES;
49214 }
49215
49216 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49217 {
49218 struct dentry *dentry = link->dentry;
49219 int error;
49220 - char *s;
49221 + const char *s;
49222
49223 BUG_ON(nd->flags & LOOKUP_RCU);
49224
49225 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49226 if (error)
49227 goto out_put_nd_path;
49228
49229 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
49230 + dentry->d_inode, dentry, nd->path.mnt)) {
49231 + error = -EACCES;
49232 + goto out_put_nd_path;
49233 + }
49234 +
49235 nd->last_type = LAST_BIND;
49236 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49237 error = PTR_ERR(*p);
49238 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49239 break;
49240 res = walk_component(nd, path, &nd->last,
49241 nd->last_type, LOOKUP_FOLLOW);
49242 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49243 + res = -EACCES;
49244 put_link(nd, &link, cookie);
49245 } while (res > 0);
49246
49247 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49248 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49249 {
49250 unsigned long a, b, adata, bdata, mask, hash, len;
49251 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49252 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49253
49254 hash = a = 0;
49255 len = -sizeof(unsigned long);
49256 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49257 if (err)
49258 break;
49259 err = lookup_last(nd, &path);
49260 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
49261 + err = -EACCES;
49262 put_link(nd, &link, cookie);
49263 }
49264 }
49265 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49266 if (!err)
49267 err = complete_walk(nd);
49268
49269 + if (!(nd->flags & LOOKUP_PARENT)) {
49270 +#ifdef CONFIG_GRKERNSEC
49271 + if (flags & LOOKUP_RCU) {
49272 + if (!err)
49273 + path_put(&nd->path);
49274 + err = -ECHILD;
49275 + } else
49276 +#endif
49277 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49278 + if (!err)
49279 + path_put(&nd->path);
49280 + err = -ENOENT;
49281 + }
49282 + }
49283 +
49284 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49285 if (!nd->inode->i_op->lookup) {
49286 path_put(&nd->path);
49287 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49288 retval = path_lookupat(dfd, name->name,
49289 flags | LOOKUP_REVAL, nd);
49290
49291 - if (likely(!retval))
49292 + if (likely(!retval)) {
49293 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49294 +#ifdef CONFIG_GRKERNSEC
49295 + if (flags & LOOKUP_RCU)
49296 + return -ECHILD;
49297 +#endif
49298 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49299 + return -ENOENT;
49300 + }
49301 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49302 + }
49303 return retval;
49304 }
49305
49306 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49307 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49308 return -EPERM;
49309
49310 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49311 + return -EPERM;
49312 + if (gr_handle_rawio(inode))
49313 + return -EPERM;
49314 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49315 + return -EACCES;
49316 +
49317 return 0;
49318 }
49319
49320 @@ -2623,7 +2672,7 @@ looked_up:
49321 * cleared otherwise prior to returning.
49322 */
49323 static int lookup_open(struct nameidata *nd, struct path *path,
49324 - struct file *file,
49325 + struct path *link, struct file *file,
49326 const struct open_flags *op,
49327 bool got_write, int *opened)
49328 {
49329 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49330 /* Negative dentry, just create the file */
49331 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49332 umode_t mode = op->mode;
49333 +
49334 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49335 + error = -EACCES;
49336 + goto out_dput;
49337 + }
49338 +
49339 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49340 + error = -EACCES;
49341 + goto out_dput;
49342 + }
49343 +
49344 if (!IS_POSIXACL(dir->d_inode))
49345 mode &= ~current_umask();
49346 /*
49347 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49348 nd->flags & LOOKUP_EXCL);
49349 if (error)
49350 goto out_dput;
49351 + else
49352 + gr_handle_create(dentry, nd->path.mnt);
49353 }
49354 out_no_open:
49355 path->dentry = dentry;
49356 @@ -2693,7 +2755,7 @@ out_dput:
49357 /*
49358 * Handle the last step of open()
49359 */
49360 -static int do_last(struct nameidata *nd, struct path *path,
49361 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49362 struct file *file, const struct open_flags *op,
49363 int *opened, struct filename *name)
49364 {
49365 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49366 error = complete_walk(nd);
49367 if (error)
49368 return error;
49369 +#ifdef CONFIG_GRKERNSEC
49370 + if (nd->flags & LOOKUP_RCU) {
49371 + error = -ECHILD;
49372 + goto out;
49373 + }
49374 +#endif
49375 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49376 + error = -ENOENT;
49377 + goto out;
49378 + }
49379 audit_inode(name, nd->path.dentry, 0);
49380 if (open_flag & O_CREAT) {
49381 error = -EISDIR;
49382 goto out;
49383 }
49384 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49385 + error = -EACCES;
49386 + goto out;
49387 + }
49388 goto finish_open;
49389 case LAST_BIND:
49390 error = complete_walk(nd);
49391 if (error)
49392 return error;
49393 +#ifdef CONFIG_GRKERNSEC
49394 + if (nd->flags & LOOKUP_RCU) {
49395 + error = -ECHILD;
49396 + goto out;
49397 + }
49398 +#endif
49399 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49400 + error = -ENOENT;
49401 + goto out;
49402 + }
49403 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49404 + error = -EACCES;
49405 + goto out;
49406 + }
49407 audit_inode(name, dir, 0);
49408 goto finish_open;
49409 }
49410 @@ -2780,7 +2870,7 @@ retry_lookup:
49411 */
49412 }
49413 mutex_lock(&dir->d_inode->i_mutex);
49414 - error = lookup_open(nd, path, file, op, got_write, opened);
49415 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49416 mutex_unlock(&dir->d_inode->i_mutex);
49417
49418 if (error <= 0) {
49419 @@ -2804,11 +2894,28 @@ retry_lookup:
49420 goto finish_open_created;
49421 }
49422
49423 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49424 + error = -ENOENT;
49425 + goto exit_dput;
49426 + }
49427 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49428 + error = -EACCES;
49429 + goto exit_dput;
49430 + }
49431 +
49432 /*
49433 * create/update audit record if it already exists.
49434 */
49435 - if (path->dentry->d_inode)
49436 + if (path->dentry->d_inode) {
49437 + /* only check if O_CREAT is specified, all other checks need to go
49438 + into may_open */
49439 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49440 + error = -EACCES;
49441 + goto exit_dput;
49442 + }
49443 +
49444 audit_inode(name, path->dentry, 0);
49445 + }
49446
49447 /*
49448 * If atomic_open() acquired write access it is dropped now due to
49449 @@ -2849,6 +2956,11 @@ finish_lookup:
49450 }
49451 }
49452 BUG_ON(inode != path->dentry->d_inode);
49453 + /* if we're resolving a symlink to another symlink */
49454 + if (link && gr_handle_symlink_owner(link, inode)) {
49455 + error = -EACCES;
49456 + goto out;
49457 + }
49458 return 1;
49459 }
49460
49461 @@ -2858,7 +2970,6 @@ finish_lookup:
49462 save_parent.dentry = nd->path.dentry;
49463 save_parent.mnt = mntget(path->mnt);
49464 nd->path.dentry = path->dentry;
49465 -
49466 }
49467 nd->inode = inode;
49468 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49469 @@ -2867,6 +2978,22 @@ finish_lookup:
49470 path_put(&save_parent);
49471 return error;
49472 }
49473 +
49474 +#ifdef CONFIG_GRKERNSEC
49475 + if (nd->flags & LOOKUP_RCU) {
49476 + error = -ECHILD;
49477 + goto out;
49478 + }
49479 +#endif
49480 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49481 + error = -ENOENT;
49482 + goto out;
49483 + }
49484 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49485 + error = -EACCES;
49486 + goto out;
49487 + }
49488 +
49489 error = -EISDIR;
49490 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49491 goto out;
49492 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49493 if (unlikely(error))
49494 goto out;
49495
49496 - error = do_last(nd, &path, file, op, &opened, pathname);
49497 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49498 while (unlikely(error > 0)) { /* trailing symlink */
49499 struct path link = path;
49500 void *cookie;
49501 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49502 error = follow_link(&link, nd, &cookie);
49503 if (unlikely(error))
49504 break;
49505 - error = do_last(nd, &path, file, op, &opened, pathname);
49506 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49507 put_link(nd, &link, cookie);
49508 }
49509 out:
49510 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49511 goto unlock;
49512
49513 error = -EEXIST;
49514 - if (dentry->d_inode)
49515 + if (dentry->d_inode) {
49516 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49517 + error = -ENOENT;
49518 + }
49519 goto fail;
49520 + }
49521 /*
49522 * Special case - lookup gave negative, but... we had foo/bar/
49523 * From the vfs_mknod() POV we just have a negative dentry -
49524 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49525 }
49526 EXPORT_SYMBOL(user_path_create);
49527
49528 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49529 +{
49530 + struct filename *tmp = getname(pathname);
49531 + struct dentry *res;
49532 + if (IS_ERR(tmp))
49533 + return ERR_CAST(tmp);
49534 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49535 + if (IS_ERR(res))
49536 + putname(tmp);
49537 + else
49538 + *to = tmp;
49539 + return res;
49540 +}
49541 +
49542 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49543 {
49544 int error = may_create(dir, dentry);
49545 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49546
49547 if (!IS_POSIXACL(path.dentry->d_inode))
49548 mode &= ~current_umask();
49549 +
49550 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49551 + error = -EPERM;
49552 + goto out;
49553 + }
49554 +
49555 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49556 + error = -EACCES;
49557 + goto out;
49558 + }
49559 +
49560 error = security_path_mknod(&path, dentry, mode, dev);
49561 if (error)
49562 goto out;
49563 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49564 break;
49565 }
49566 out:
49567 + if (!error)
49568 + gr_handle_create(dentry, path.mnt);
49569 done_path_create(&path, dentry);
49570 return error;
49571 }
49572 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49573
49574 if (!IS_POSIXACL(path.dentry->d_inode))
49575 mode &= ~current_umask();
49576 +
49577 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49578 + error = -EACCES;
49579 + goto out;
49580 + }
49581 +
49582 error = security_path_mkdir(&path, dentry, mode);
49583 if (!error)
49584 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49585 + if (!error)
49586 + gr_handle_create(dentry, path.mnt);
49587 +out:
49588 done_path_create(&path, dentry);
49589 return error;
49590 }
49591 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49592 struct filename *name;
49593 struct dentry *dentry;
49594 struct nameidata nd;
49595 + ino_t saved_ino = 0;
49596 + dev_t saved_dev = 0;
49597
49598 name = user_path_parent(dfd, pathname, &nd);
49599 if (IS_ERR(name))
49600 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49601 error = -ENOENT;
49602 goto exit3;
49603 }
49604 +
49605 + saved_ino = dentry->d_inode->i_ino;
49606 + saved_dev = gr_get_dev_from_dentry(dentry);
49607 +
49608 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49609 + error = -EACCES;
49610 + goto exit3;
49611 + }
49612 +
49613 error = security_path_rmdir(&nd.path, dentry);
49614 if (error)
49615 goto exit3;
49616 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49617 + if (!error && (saved_dev || saved_ino))
49618 + gr_handle_delete(saved_ino, saved_dev);
49619 exit3:
49620 dput(dentry);
49621 exit2:
49622 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49623 struct dentry *dentry;
49624 struct nameidata nd;
49625 struct inode *inode = NULL;
49626 + ino_t saved_ino = 0;
49627 + dev_t saved_dev = 0;
49628
49629 name = user_path_parent(dfd, pathname, &nd);
49630 if (IS_ERR(name))
49631 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49632 if (!inode)
49633 goto slashes;
49634 ihold(inode);
49635 +
49636 + if (inode->i_nlink <= 1) {
49637 + saved_ino = inode->i_ino;
49638 + saved_dev = gr_get_dev_from_dentry(dentry);
49639 + }
49640 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49641 + error = -EACCES;
49642 + goto exit2;
49643 + }
49644 +
49645 error = security_path_unlink(&nd.path, dentry);
49646 if (error)
49647 goto exit2;
49648 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49649 + if (!error && (saved_ino || saved_dev))
49650 + gr_handle_delete(saved_ino, saved_dev);
49651 exit2:
49652 dput(dentry);
49653 }
49654 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49655 if (IS_ERR(dentry))
49656 goto out_putname;
49657
49658 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49659 + error = -EACCES;
49660 + goto out;
49661 + }
49662 +
49663 error = security_path_symlink(&path, dentry, from->name);
49664 if (!error)
49665 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49666 + if (!error)
49667 + gr_handle_create(dentry, path.mnt);
49668 +out:
49669 done_path_create(&path, dentry);
49670 out_putname:
49671 putname(from);
49672 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49673 {
49674 struct dentry *new_dentry;
49675 struct path old_path, new_path;
49676 + struct filename *to = NULL;
49677 int how = 0;
49678 int error;
49679
49680 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49681 if (error)
49682 return error;
49683
49684 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49685 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49686 error = PTR_ERR(new_dentry);
49687 if (IS_ERR(new_dentry))
49688 goto out;
49689 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49690 error = may_linkat(&old_path);
49691 if (unlikely(error))
49692 goto out_dput;
49693 +
49694 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49695 + old_path.dentry->d_inode,
49696 + old_path.dentry->d_inode->i_mode, to)) {
49697 + error = -EACCES;
49698 + goto out_dput;
49699 + }
49700 +
49701 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49702 + old_path.dentry, old_path.mnt, to)) {
49703 + error = -EACCES;
49704 + goto out_dput;
49705 + }
49706 +
49707 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49708 if (error)
49709 goto out_dput;
49710 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49711 + if (!error)
49712 + gr_handle_create(new_dentry, new_path.mnt);
49713 out_dput:
49714 + putname(to);
49715 done_path_create(&new_path, new_dentry);
49716 out:
49717 path_put(&old_path);
49718 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49719 if (new_dentry == trap)
49720 goto exit5;
49721
49722 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49723 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
49724 + to);
49725 + if (error)
49726 + goto exit5;
49727 +
49728 error = security_path_rename(&oldnd.path, old_dentry,
49729 &newnd.path, new_dentry);
49730 if (error)
49731 goto exit5;
49732 error = vfs_rename(old_dir->d_inode, old_dentry,
49733 new_dir->d_inode, new_dentry);
49734 + if (!error)
49735 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49736 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49737 exit5:
49738 dput(new_dentry);
49739 exit4:
49740 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49741
49742 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49743 {
49744 + char tmpbuf[64];
49745 + const char *newlink;
49746 int len;
49747
49748 len = PTR_ERR(link);
49749 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49750 len = strlen(link);
49751 if (len > (unsigned) buflen)
49752 len = buflen;
49753 - if (copy_to_user(buffer, link, len))
49754 +
49755 + if (len < sizeof(tmpbuf)) {
49756 + memcpy(tmpbuf, link, len);
49757 + newlink = tmpbuf;
49758 + } else
49759 + newlink = link;
49760 +
49761 + if (copy_to_user(buffer, newlink, len))
49762 len = -EFAULT;
49763 out:
49764 return len;
49765 diff --git a/fs/namespace.c b/fs/namespace.c
49766 index 2496062..e26f6d6 100644
49767 --- a/fs/namespace.c
49768 +++ b/fs/namespace.c
49769 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
49770 if (!(sb->s_flags & MS_RDONLY))
49771 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
49772 up_write(&sb->s_umount);
49773 +
49774 + gr_log_remount(mnt->mnt_devname, retval);
49775 +
49776 return retval;
49777 }
49778
49779 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
49780 br_write_unlock(&vfsmount_lock);
49781 up_write(&namespace_sem);
49782 release_mounts(&umount_list);
49783 +
49784 + gr_log_unmount(mnt->mnt_devname, retval);
49785 +
49786 return retval;
49787 }
49788
49789 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
49790 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
49791 MS_STRICTATIME);
49792
49793 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
49794 + retval = -EPERM;
49795 + goto dput_out;
49796 + }
49797 +
49798 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
49799 + retval = -EPERM;
49800 + goto dput_out;
49801 + }
49802 +
49803 if (flags & MS_REMOUNT)
49804 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
49805 data_page);
49806 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
49807 dev_name, data_page);
49808 dput_out:
49809 path_put(&path);
49810 +
49811 + gr_log_mount(dev_name, dir_name, retval);
49812 +
49813 return retval;
49814 }
49815
49816 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
49817 if (error)
49818 goto out2;
49819
49820 + if (gr_handle_chroot_pivot()) {
49821 + error = -EPERM;
49822 + goto out2;
49823 + }
49824 +
49825 get_fs_root(current->fs, &root);
49826 error = lock_mount(&old);
49827 if (error)
49828 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
49829 index 6fa01ae..2790820 100644
49830 --- a/fs/nfs/inode.c
49831 +++ b/fs/nfs/inode.c
49832 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
49833 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
49834 }
49835
49836 -static atomic_long_t nfs_attr_generation_counter;
49837 +static atomic_long_unchecked_t nfs_attr_generation_counter;
49838
49839 static unsigned long nfs_read_attr_generation_counter(void)
49840 {
49841 - return atomic_long_read(&nfs_attr_generation_counter);
49842 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
49843 }
49844
49845 unsigned long nfs_inc_attr_generation_counter(void)
49846 {
49847 - return atomic_long_inc_return(&nfs_attr_generation_counter);
49848 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
49849 }
49850
49851 void nfs_fattr_init(struct nfs_fattr *fattr)
49852 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
49853 index f59169e..fd7d359 100644
49854 --- a/fs/nfsd/vfs.c
49855 +++ b/fs/nfsd/vfs.c
49856 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49857 } else {
49858 oldfs = get_fs();
49859 set_fs(KERNEL_DS);
49860 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
49861 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
49862 set_fs(oldfs);
49863 }
49864
49865 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49866
49867 /* Write the data. */
49868 oldfs = get_fs(); set_fs(KERNEL_DS);
49869 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
49870 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
49871 set_fs(oldfs);
49872 if (host_err < 0)
49873 goto out_nfserr;
49874 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
49875 */
49876
49877 oldfs = get_fs(); set_fs(KERNEL_DS);
49878 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
49879 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
49880 set_fs(oldfs);
49881
49882 if (host_err < 0)
49883 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
49884 index 6fcaeb8..9d16d04 100644
49885 --- a/fs/notify/fanotify/fanotify_user.c
49886 +++ b/fs/notify/fanotify/fanotify_user.c
49887 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
49888
49889 fd = fanotify_event_metadata.fd;
49890 ret = -EFAULT;
49891 - if (copy_to_user(buf, &fanotify_event_metadata,
49892 - fanotify_event_metadata.event_len))
49893 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
49894 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
49895 goto out_close_fd;
49896
49897 ret = prepare_for_access_response(group, event, fd);
49898 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
49899 index c887b13..0fdf472 100644
49900 --- a/fs/notify/notification.c
49901 +++ b/fs/notify/notification.c
49902 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
49903 * get set to 0 so it will never get 'freed'
49904 */
49905 static struct fsnotify_event *q_overflow_event;
49906 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49907 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49908
49909 /**
49910 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
49911 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49912 */
49913 u32 fsnotify_get_cookie(void)
49914 {
49915 - return atomic_inc_return(&fsnotify_sync_cookie);
49916 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
49917 }
49918 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
49919
49920 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
49921 index 99e3610..02c1068 100644
49922 --- a/fs/ntfs/dir.c
49923 +++ b/fs/ntfs/dir.c
49924 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
49925 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
49926 ~(s64)(ndir->itype.index.block_size - 1)));
49927 /* Bounds checks. */
49928 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49929 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49930 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
49931 "inode 0x%lx or driver bug.", vdir->i_ino);
49932 goto err_out;
49933 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
49934 index 1ecf464..e1ff8bf 100644
49935 --- a/fs/ntfs/file.c
49936 +++ b/fs/ntfs/file.c
49937 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
49938 #endif /* NTFS_RW */
49939 };
49940
49941 -const struct file_operations ntfs_empty_file_ops = {};
49942 +const struct file_operations ntfs_empty_file_ops __read_only;
49943
49944 -const struct inode_operations ntfs_empty_inode_ops = {};
49945 +const struct inode_operations ntfs_empty_inode_ops __read_only;
49946 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
49947 index a9f78c7..ed8a381 100644
49948 --- a/fs/ocfs2/localalloc.c
49949 +++ b/fs/ocfs2/localalloc.c
49950 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
49951 goto bail;
49952 }
49953
49954 - atomic_inc(&osb->alloc_stats.moves);
49955 + atomic_inc_unchecked(&osb->alloc_stats.moves);
49956
49957 bail:
49958 if (handle)
49959 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
49960 index d355e6e..578d905 100644
49961 --- a/fs/ocfs2/ocfs2.h
49962 +++ b/fs/ocfs2/ocfs2.h
49963 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
49964
49965 struct ocfs2_alloc_stats
49966 {
49967 - atomic_t moves;
49968 - atomic_t local_data;
49969 - atomic_t bitmap_data;
49970 - atomic_t bg_allocs;
49971 - atomic_t bg_extends;
49972 + atomic_unchecked_t moves;
49973 + atomic_unchecked_t local_data;
49974 + atomic_unchecked_t bitmap_data;
49975 + atomic_unchecked_t bg_allocs;
49976 + atomic_unchecked_t bg_extends;
49977 };
49978
49979 enum ocfs2_local_alloc_state
49980 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
49981 index f169da4..9112253 100644
49982 --- a/fs/ocfs2/suballoc.c
49983 +++ b/fs/ocfs2/suballoc.c
49984 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
49985 mlog_errno(status);
49986 goto bail;
49987 }
49988 - atomic_inc(&osb->alloc_stats.bg_extends);
49989 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49990
49991 /* You should never ask for this much metadata */
49992 BUG_ON(bits_wanted >
49993 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
49994 mlog_errno(status);
49995 goto bail;
49996 }
49997 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49998 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49999
50000 *suballoc_loc = res.sr_bg_blkno;
50001 *suballoc_bit_start = res.sr_bit_offset;
50002 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50003 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50004 res->sr_bits);
50005
50006 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50007 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50008
50009 BUG_ON(res->sr_bits != 1);
50010
50011 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50012 mlog_errno(status);
50013 goto bail;
50014 }
50015 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50016 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50017
50018 BUG_ON(res.sr_bits != 1);
50019
50020 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50021 cluster_start,
50022 num_clusters);
50023 if (!status)
50024 - atomic_inc(&osb->alloc_stats.local_data);
50025 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
50026 } else {
50027 if (min_clusters > (osb->bitmap_cpg - 1)) {
50028 /* The only paths asking for contiguousness
50029 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50030 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50031 res.sr_bg_blkno,
50032 res.sr_bit_offset);
50033 - atomic_inc(&osb->alloc_stats.bitmap_data);
50034 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50035 *num_clusters = res.sr_bits;
50036 }
50037 }
50038 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50039 index 0e91ec2..f4b3fc6 100644
50040 --- a/fs/ocfs2/super.c
50041 +++ b/fs/ocfs2/super.c
50042 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50043 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50044 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50045 "Stats",
50046 - atomic_read(&osb->alloc_stats.bitmap_data),
50047 - atomic_read(&osb->alloc_stats.local_data),
50048 - atomic_read(&osb->alloc_stats.bg_allocs),
50049 - atomic_read(&osb->alloc_stats.moves),
50050 - atomic_read(&osb->alloc_stats.bg_extends));
50051 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50052 + atomic_read_unchecked(&osb->alloc_stats.local_data),
50053 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50054 + atomic_read_unchecked(&osb->alloc_stats.moves),
50055 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50056
50057 out += snprintf(buf + out, len - out,
50058 "%10s => State: %u Descriptor: %llu Size: %u bits "
50059 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50060 spin_lock_init(&osb->osb_xattr_lock);
50061 ocfs2_init_steal_slots(osb);
50062
50063 - atomic_set(&osb->alloc_stats.moves, 0);
50064 - atomic_set(&osb->alloc_stats.local_data, 0);
50065 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
50066 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
50067 - atomic_set(&osb->alloc_stats.bg_extends, 0);
50068 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50069 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50070 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50071 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50072 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50073
50074 /* Copy the blockcheck stats from the superblock probe */
50075 osb->osb_ecc_stats = *stats;
50076 diff --git a/fs/open.c b/fs/open.c
50077 index 59071f5..c6229a0 100644
50078 --- a/fs/open.c
50079 +++ b/fs/open.c
50080 @@ -31,6 +31,8 @@
50081 #include <linux/ima.h>
50082 #include <linux/dnotify.h>
50083
50084 +#define CREATE_TRACE_POINTS
50085 +#include <trace/events/fs.h>
50086 #include "internal.h"
50087
50088 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50089 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50090 error = locks_verify_truncate(inode, NULL, length);
50091 if (!error)
50092 error = security_path_truncate(&path);
50093 +
50094 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50095 + error = -EACCES;
50096 +
50097 if (!error)
50098 error = do_truncate(path.dentry, length, 0, NULL);
50099
50100 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50101 if (__mnt_is_readonly(path.mnt))
50102 res = -EROFS;
50103
50104 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50105 + res = -EACCES;
50106 +
50107 out_path_release:
50108 path_put(&path);
50109 out:
50110 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50111 if (error)
50112 goto dput_and_out;
50113
50114 + gr_log_chdir(path.dentry, path.mnt);
50115 +
50116 set_fs_pwd(current->fs, &path);
50117
50118 dput_and_out:
50119 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50120 goto out_putf;
50121
50122 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50123 +
50124 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50125 + error = -EPERM;
50126 +
50127 + if (!error)
50128 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50129 +
50130 if (!error)
50131 set_fs_pwd(current->fs, &f.file->f_path);
50132 out_putf:
50133 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50134 if (error)
50135 goto dput_and_out;
50136
50137 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50138 + goto dput_and_out;
50139 +
50140 set_fs_root(current->fs, &path);
50141 +
50142 + gr_handle_chroot_chdir(&path);
50143 +
50144 error = 0;
50145 dput_and_out:
50146 path_put(&path);
50147 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50148 if (error)
50149 return error;
50150 mutex_lock(&inode->i_mutex);
50151 +
50152 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50153 + error = -EACCES;
50154 + goto out_unlock;
50155 + }
50156 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50157 + error = -EACCES;
50158 + goto out_unlock;
50159 + }
50160 +
50161 error = security_path_chmod(path, mode);
50162 if (error)
50163 goto out_unlock;
50164 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50165 uid = make_kuid(current_user_ns(), user);
50166 gid = make_kgid(current_user_ns(), group);
50167
50168 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
50169 + return -EACCES;
50170 +
50171 newattrs.ia_valid = ATTR_CTIME;
50172 if (user != (uid_t) -1) {
50173 if (!uid_valid(uid))
50174 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50175 } else {
50176 fsnotify_open(f);
50177 fd_install(fd, f);
50178 + trace_do_sys_open(tmp->name, flags, mode);
50179 }
50180 }
50181 putname(tmp);
50182 diff --git a/fs/pipe.c b/fs/pipe.c
50183 index bd3479d..fb92c4d 100644
50184 --- a/fs/pipe.c
50185 +++ b/fs/pipe.c
50186 @@ -438,9 +438,9 @@ redo:
50187 }
50188 if (bufs) /* More to do? */
50189 continue;
50190 - if (!pipe->writers)
50191 + if (!atomic_read(&pipe->writers))
50192 break;
50193 - if (!pipe->waiting_writers) {
50194 + if (!atomic_read(&pipe->waiting_writers)) {
50195 /* syscall merging: Usually we must not sleep
50196 * if O_NONBLOCK is set, or if we got some data.
50197 * But if a writer sleeps in kernel space, then
50198 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50199 mutex_lock(&inode->i_mutex);
50200 pipe = inode->i_pipe;
50201
50202 - if (!pipe->readers) {
50203 + if (!atomic_read(&pipe->readers)) {
50204 send_sig(SIGPIPE, current, 0);
50205 ret = -EPIPE;
50206 goto out;
50207 @@ -553,7 +553,7 @@ redo1:
50208 for (;;) {
50209 int bufs;
50210
50211 - if (!pipe->readers) {
50212 + if (!atomic_read(&pipe->readers)) {
50213 send_sig(SIGPIPE, current, 0);
50214 if (!ret)
50215 ret = -EPIPE;
50216 @@ -644,9 +644,9 @@ redo2:
50217 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50218 do_wakeup = 0;
50219 }
50220 - pipe->waiting_writers++;
50221 + atomic_inc(&pipe->waiting_writers);
50222 pipe_wait(pipe);
50223 - pipe->waiting_writers--;
50224 + atomic_dec(&pipe->waiting_writers);
50225 }
50226 out:
50227 mutex_unlock(&inode->i_mutex);
50228 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50229 mask = 0;
50230 if (filp->f_mode & FMODE_READ) {
50231 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50232 - if (!pipe->writers && filp->f_version != pipe->w_counter)
50233 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50234 mask |= POLLHUP;
50235 }
50236
50237 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50238 * Most Unices do not set POLLERR for FIFOs but on Linux they
50239 * behave exactly like pipes for poll().
50240 */
50241 - if (!pipe->readers)
50242 + if (!atomic_read(&pipe->readers))
50243 mask |= POLLERR;
50244 }
50245
50246 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50247
50248 mutex_lock(&inode->i_mutex);
50249 pipe = inode->i_pipe;
50250 - pipe->readers -= decr;
50251 - pipe->writers -= decw;
50252 + atomic_sub(decr, &pipe->readers);
50253 + atomic_sub(decw, &pipe->writers);
50254
50255 - if (!pipe->readers && !pipe->writers) {
50256 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50257 free_pipe_info(inode);
50258 } else {
50259 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50260 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50261
50262 if (inode->i_pipe) {
50263 ret = 0;
50264 - inode->i_pipe->readers++;
50265 + atomic_inc(&inode->i_pipe->readers);
50266 }
50267
50268 mutex_unlock(&inode->i_mutex);
50269 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50270
50271 if (inode->i_pipe) {
50272 ret = 0;
50273 - inode->i_pipe->writers++;
50274 + atomic_inc(&inode->i_pipe->writers);
50275 }
50276
50277 mutex_unlock(&inode->i_mutex);
50278 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50279 if (inode->i_pipe) {
50280 ret = 0;
50281 if (filp->f_mode & FMODE_READ)
50282 - inode->i_pipe->readers++;
50283 + atomic_inc(&inode->i_pipe->readers);
50284 if (filp->f_mode & FMODE_WRITE)
50285 - inode->i_pipe->writers++;
50286 + atomic_inc(&inode->i_pipe->writers);
50287 }
50288
50289 mutex_unlock(&inode->i_mutex);
50290 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50291 inode->i_pipe = NULL;
50292 }
50293
50294 -static struct vfsmount *pipe_mnt __read_mostly;
50295 +struct vfsmount *pipe_mnt __read_mostly;
50296
50297 /*
50298 * pipefs_dname() is called from d_path().
50299 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50300 goto fail_iput;
50301 inode->i_pipe = pipe;
50302
50303 - pipe->readers = pipe->writers = 1;
50304 + atomic_set(&pipe->readers, 1);
50305 + atomic_set(&pipe->writers, 1);
50306 inode->i_fop = &rdwr_pipefifo_fops;
50307
50308 /*
50309 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50310 index 15af622..0e9f4467 100644
50311 --- a/fs/proc/Kconfig
50312 +++ b/fs/proc/Kconfig
50313 @@ -30,12 +30,12 @@ config PROC_FS
50314
50315 config PROC_KCORE
50316 bool "/proc/kcore support" if !ARM
50317 - depends on PROC_FS && MMU
50318 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50319
50320 config PROC_VMCORE
50321 bool "/proc/vmcore support"
50322 - depends on PROC_FS && CRASH_DUMP
50323 - default y
50324 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50325 + default n
50326 help
50327 Exports the dump image of crashed kernel in ELF format.
50328
50329 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50330 limited in memory.
50331
50332 config PROC_PAGE_MONITOR
50333 - default y
50334 - depends on PROC_FS && MMU
50335 + default n
50336 + depends on PROC_FS && MMU && !GRKERNSEC
50337 bool "Enable /proc page monitoring" if EXPERT
50338 help
50339 Various /proc files exist to monitor process memory utilization:
50340 diff --git a/fs/proc/array.c b/fs/proc/array.c
50341 index bd31e02..15cae71 100644
50342 --- a/fs/proc/array.c
50343 +++ b/fs/proc/array.c
50344 @@ -60,6 +60,7 @@
50345 #include <linux/tty.h>
50346 #include <linux/string.h>
50347 #include <linux/mman.h>
50348 +#include <linux/grsecurity.h>
50349 #include <linux/proc_fs.h>
50350 #include <linux/ioport.h>
50351 #include <linux/uaccess.h>
50352 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50353 seq_putc(m, '\n');
50354 }
50355
50356 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50357 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50358 +{
50359 + if (p->mm)
50360 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50361 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50362 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50363 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50364 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50365 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50366 + else
50367 + seq_printf(m, "PaX:\t-----\n");
50368 +}
50369 +#endif
50370 +
50371 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50372 struct pid *pid, struct task_struct *task)
50373 {
50374 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50375 task_cpus_allowed(m, task);
50376 cpuset_task_status_allowed(m, task);
50377 task_context_switch_counts(m, task);
50378 +
50379 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50380 + task_pax(m, task);
50381 +#endif
50382 +
50383 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50384 + task_grsec_rbac(m, task);
50385 +#endif
50386 +
50387 return 0;
50388 }
50389
50390 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50391 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50392 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50393 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50394 +#endif
50395 +
50396 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50397 struct pid *pid, struct task_struct *task, int whole)
50398 {
50399 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50400 char tcomm[sizeof(task->comm)];
50401 unsigned long flags;
50402
50403 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50404 + if (current->exec_id != m->exec_id) {
50405 + gr_log_badprocpid("stat");
50406 + return 0;
50407 + }
50408 +#endif
50409 +
50410 state = *get_task_state(task);
50411 vsize = eip = esp = 0;
50412 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50413 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50414 gtime = task->gtime;
50415 }
50416
50417 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50418 + if (PAX_RAND_FLAGS(mm)) {
50419 + eip = 0;
50420 + esp = 0;
50421 + wchan = 0;
50422 + }
50423 +#endif
50424 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50425 + wchan = 0;
50426 + eip =0;
50427 + esp =0;
50428 +#endif
50429 +
50430 /* scale priority and nice values from timeslices to -20..20 */
50431 /* to make it look like a "normal" Unix priority/nice value */
50432 priority = task_prio(task);
50433 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50434 seq_put_decimal_ull(m, ' ', vsize);
50435 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50436 seq_put_decimal_ull(m, ' ', rsslim);
50437 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50438 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50439 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50440 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50441 +#else
50442 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50443 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50444 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50445 +#endif
50446 seq_put_decimal_ull(m, ' ', esp);
50447 seq_put_decimal_ull(m, ' ', eip);
50448 /* The signal information here is obsolete.
50449 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50450 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50451 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50452
50453 - if (mm && permitted) {
50454 + if (mm && permitted
50455 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50456 + && !PAX_RAND_FLAGS(mm)
50457 +#endif
50458 + ) {
50459 seq_put_decimal_ull(m, ' ', mm->start_data);
50460 seq_put_decimal_ull(m, ' ', mm->end_data);
50461 seq_put_decimal_ull(m, ' ', mm->start_brk);
50462 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50463 struct pid *pid, struct task_struct *task)
50464 {
50465 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50466 - struct mm_struct *mm = get_task_mm(task);
50467 + struct mm_struct *mm;
50468
50469 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50470 + if (current->exec_id != m->exec_id) {
50471 + gr_log_badprocpid("statm");
50472 + return 0;
50473 + }
50474 +#endif
50475 + mm = get_task_mm(task);
50476 if (mm) {
50477 size = task_statm(mm, &shared, &text, &data, &resident);
50478 mmput(mm);
50479 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50480 return 0;
50481 }
50482
50483 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50484 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50485 +{
50486 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50487 +}
50488 +#endif
50489 +
50490 #ifdef CONFIG_CHECKPOINT_RESTORE
50491 static struct pid *
50492 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50493 diff --git a/fs/proc/base.c b/fs/proc/base.c
50494 index 9e28356..c485b3c 100644
50495 --- a/fs/proc/base.c
50496 +++ b/fs/proc/base.c
50497 @@ -111,6 +111,14 @@ struct pid_entry {
50498 union proc_op op;
50499 };
50500
50501 +struct getdents_callback {
50502 + struct linux_dirent __user * current_dir;
50503 + struct linux_dirent __user * previous;
50504 + struct file * file;
50505 + int count;
50506 + int error;
50507 +};
50508 +
50509 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50510 .name = (NAME), \
50511 .len = sizeof(NAME) - 1, \
50512 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50513 if (!mm->arg_end)
50514 goto out_mm; /* Shh! No looking before we're done */
50515
50516 + if (gr_acl_handle_procpidmem(task))
50517 + goto out_mm;
50518 +
50519 len = mm->arg_end - mm->arg_start;
50520
50521 if (len > PAGE_SIZE)
50522 @@ -235,12 +246,28 @@ out:
50523 return res;
50524 }
50525
50526 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50527 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50528 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50529 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50530 +#endif
50531 +
50532 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50533 {
50534 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50535 int res = PTR_ERR(mm);
50536 if (mm && !IS_ERR(mm)) {
50537 unsigned int nwords = 0;
50538 +
50539 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50540 + /* allow if we're currently ptracing this task */
50541 + if (PAX_RAND_FLAGS(mm) &&
50542 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50543 + mmput(mm);
50544 + return 0;
50545 + }
50546 +#endif
50547 +
50548 do {
50549 nwords += 2;
50550 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50551 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50552 }
50553
50554
50555 -#ifdef CONFIG_KALLSYMS
50556 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50557 /*
50558 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50559 * Returns the resolved symbol. If that fails, simply return the address.
50560 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50561 mutex_unlock(&task->signal->cred_guard_mutex);
50562 }
50563
50564 -#ifdef CONFIG_STACKTRACE
50565 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50566
50567 #define MAX_STACK_TRACE_DEPTH 64
50568
50569 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50570 return count;
50571 }
50572
50573 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50574 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50575 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50576 {
50577 long nr;
50578 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50579 /************************************************************************/
50580
50581 /* permission checks */
50582 -static int proc_fd_access_allowed(struct inode *inode)
50583 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50584 {
50585 struct task_struct *task;
50586 int allowed = 0;
50587 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50588 */
50589 task = get_proc_task(inode);
50590 if (task) {
50591 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50592 + if (log)
50593 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50594 + else
50595 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50596 put_task_struct(task);
50597 }
50598 return allowed;
50599 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50600 struct task_struct *task,
50601 int hide_pid_min)
50602 {
50603 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50604 + return false;
50605 +
50606 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50607 + rcu_read_lock();
50608 + {
50609 + const struct cred *tmpcred = current_cred();
50610 + const struct cred *cred = __task_cred(task);
50611 +
50612 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50613 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50614 + || in_group_p(grsec_proc_gid)
50615 +#endif
50616 + ) {
50617 + rcu_read_unlock();
50618 + return true;
50619 + }
50620 + }
50621 + rcu_read_unlock();
50622 +
50623 + if (!pid->hide_pid)
50624 + return false;
50625 +#endif
50626 +
50627 if (pid->hide_pid < hide_pid_min)
50628 return true;
50629 if (in_group_p(pid->pid_gid))
50630 return true;
50631 +
50632 return ptrace_may_access(task, PTRACE_MODE_READ);
50633 }
50634
50635 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50636 put_task_struct(task);
50637
50638 if (!has_perms) {
50639 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50640 + {
50641 +#else
50642 if (pid->hide_pid == 2) {
50643 +#endif
50644 /*
50645 * Let's make getdents(), stat(), and open()
50646 * consistent with each other. If a process
50647 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50648 if (!task)
50649 return -ESRCH;
50650
50651 + if (gr_acl_handle_procpidmem(task)) {
50652 + put_task_struct(task);
50653 + return -EPERM;
50654 + }
50655 +
50656 mm = mm_access(task, mode);
50657 put_task_struct(task);
50658
50659 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50660
50661 file->private_data = mm;
50662
50663 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50664 + file->f_version = current->exec_id;
50665 +#endif
50666 +
50667 return 0;
50668 }
50669
50670 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50671 ssize_t copied;
50672 char *page;
50673
50674 +#ifdef CONFIG_GRKERNSEC
50675 + if (write)
50676 + return -EPERM;
50677 +#endif
50678 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50679 + if (file->f_version != current->exec_id) {
50680 + gr_log_badprocpid("mem");
50681 + return 0;
50682 + }
50683 +#endif
50684 +
50685 if (!mm)
50686 return 0;
50687
50688 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50689 if (!mm)
50690 return 0;
50691
50692 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50693 + if (file->f_version != current->exec_id) {
50694 + gr_log_badprocpid("environ");
50695 + return 0;
50696 + }
50697 +#endif
50698 +
50699 page = (char *)__get_free_page(GFP_TEMPORARY);
50700 if (!page)
50701 return -ENOMEM;
50702 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50703 int error = -EACCES;
50704
50705 /* Are we allowed to snoop on the tasks file descriptors? */
50706 - if (!proc_fd_access_allowed(inode))
50707 + if (!proc_fd_access_allowed(inode, 0))
50708 goto out;
50709
50710 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50711 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50712 struct path path;
50713
50714 /* Are we allowed to snoop on the tasks file descriptors? */
50715 - if (!proc_fd_access_allowed(inode))
50716 - goto out;
50717 + /* logging this is needed for learning on chromium to work properly,
50718 + but we don't want to flood the logs from 'ps' which does a readlink
50719 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50720 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
50721 + */
50722 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50723 + if (!proc_fd_access_allowed(inode,0))
50724 + goto out;
50725 + } else {
50726 + if (!proc_fd_access_allowed(inode,1))
50727 + goto out;
50728 + }
50729
50730 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50731 if (error)
50732 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50733 rcu_read_lock();
50734 cred = __task_cred(task);
50735 inode->i_uid = cred->euid;
50736 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50737 + inode->i_gid = grsec_proc_gid;
50738 +#else
50739 inode->i_gid = cred->egid;
50740 +#endif
50741 rcu_read_unlock();
50742 }
50743 security_task_to_inode(task, inode);
50744 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50745 return -ENOENT;
50746 }
50747 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50748 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50749 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50750 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50751 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50752 +#endif
50753 task_dumpable(task)) {
50754 cred = __task_cred(task);
50755 stat->uid = cred->euid;
50756 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50757 + stat->gid = grsec_proc_gid;
50758 +#else
50759 stat->gid = cred->egid;
50760 +#endif
50761 }
50762 }
50763 rcu_read_unlock();
50764 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
50765
50766 if (task) {
50767 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50768 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50769 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50770 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50771 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50772 +#endif
50773 task_dumpable(task)) {
50774 rcu_read_lock();
50775 cred = __task_cred(task);
50776 inode->i_uid = cred->euid;
50777 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50778 + inode->i_gid = grsec_proc_gid;
50779 +#else
50780 inode->i_gid = cred->egid;
50781 +#endif
50782 rcu_read_unlock();
50783 } else {
50784 inode->i_uid = GLOBAL_ROOT_UID;
50785 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
50786 if (!task)
50787 goto out_no_task;
50788
50789 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50790 + goto out;
50791 +
50792 /*
50793 * Yes, it does not scale. And it should not. Don't add
50794 * new entries into /proc/<tgid>/ without very good reasons.
50795 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
50796 if (!task)
50797 goto out_no_task;
50798
50799 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50800 + goto out;
50801 +
50802 ret = 0;
50803 i = filp->f_pos;
50804 switch (i) {
50805 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
50806 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
50807 void *cookie)
50808 {
50809 - char *s = nd_get_link(nd);
50810 + const char *s = nd_get_link(nd);
50811 if (!IS_ERR(s))
50812 kfree(s);
50813 }
50814 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
50815 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
50816 #endif
50817 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50818 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50819 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50820 INF("syscall", S_IRUGO, proc_pid_syscall),
50821 #endif
50822 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50823 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
50824 #ifdef CONFIG_SECURITY
50825 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50826 #endif
50827 -#ifdef CONFIG_KALLSYMS
50828 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50829 INF("wchan", S_IRUGO, proc_pid_wchan),
50830 #endif
50831 -#ifdef CONFIG_STACKTRACE
50832 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50833 ONE("stack", S_IRUGO, proc_pid_stack),
50834 #endif
50835 #ifdef CONFIG_SCHEDSTATS
50836 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
50837 #ifdef CONFIG_HARDWALL
50838 INF("hardwall", S_IRUGO, proc_pid_hardwall),
50839 #endif
50840 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50841 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
50842 +#endif
50843 #ifdef CONFIG_USER_NS
50844 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
50845 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
50846 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
50847 if (!inode)
50848 goto out;
50849
50850 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50851 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
50852 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50853 + inode->i_gid = grsec_proc_gid;
50854 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
50855 +#else
50856 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
50857 +#endif
50858 inode->i_op = &proc_tgid_base_inode_operations;
50859 inode->i_fop = &proc_tgid_base_operations;
50860 inode->i_flags|=S_IMMUTABLE;
50861 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
50862 if (!task)
50863 goto out;
50864
50865 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50866 + goto out_put_task;
50867 +
50868 result = proc_pid_instantiate(dir, dentry, task, NULL);
50869 +out_put_task:
50870 put_task_struct(task);
50871 out:
50872 return result;
50873 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
50874 static int fake_filldir(void *buf, const char *name, int namelen,
50875 loff_t offset, u64 ino, unsigned d_type)
50876 {
50877 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
50878 + __buf->error = -EINVAL;
50879 return 0;
50880 }
50881
50882 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
50883 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50884 #endif
50885 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50886 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50887 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50888 INF("syscall", S_IRUGO, proc_pid_syscall),
50889 #endif
50890 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50891 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
50892 #ifdef CONFIG_SECURITY
50893 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50894 #endif
50895 -#ifdef CONFIG_KALLSYMS
50896 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50897 INF("wchan", S_IRUGO, proc_pid_wchan),
50898 #endif
50899 -#ifdef CONFIG_STACKTRACE
50900 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50901 ONE("stack", S_IRUGO, proc_pid_stack),
50902 #endif
50903 #ifdef CONFIG_SCHEDSTATS
50904 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
50905 index 82676e3..5f8518a 100644
50906 --- a/fs/proc/cmdline.c
50907 +++ b/fs/proc/cmdline.c
50908 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
50909
50910 static int __init proc_cmdline_init(void)
50911 {
50912 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50913 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50914 +#else
50915 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50916 +#endif
50917 return 0;
50918 }
50919 module_init(proc_cmdline_init);
50920 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
50921 index b143471..bb105e5 100644
50922 --- a/fs/proc/devices.c
50923 +++ b/fs/proc/devices.c
50924 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
50925
50926 static int __init proc_devices_init(void)
50927 {
50928 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50929 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50930 +#else
50931 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50932 +#endif
50933 return 0;
50934 }
50935 module_init(proc_devices_init);
50936 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
50937 index f28a875..c467953 100644
50938 --- a/fs/proc/fd.c
50939 +++ b/fs/proc/fd.c
50940 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
50941 if (!task)
50942 return -ENOENT;
50943
50944 - files = get_files_struct(task);
50945 + if (!gr_acl_handle_procpidmem(task))
50946 + files = get_files_struct(task);
50947 put_task_struct(task);
50948
50949 if (files) {
50950 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
50951 */
50952 int proc_fd_permission(struct inode *inode, int mask)
50953 {
50954 + struct task_struct *task;
50955 int rv = generic_permission(inode, mask);
50956 - if (rv == 0)
50957 - return 0;
50958 +
50959 if (task_pid(current) == proc_pid(inode))
50960 rv = 0;
50961 +
50962 + task = get_proc_task(inode);
50963 + if (task == NULL)
50964 + return rv;
50965 +
50966 + if (gr_acl_handle_procpidmem(task))
50967 + rv = -EACCES;
50968 +
50969 + put_task_struct(task);
50970 +
50971 return rv;
50972 }
50973
50974 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
50975 index 3b22bbd..895b58c 100644
50976 --- a/fs/proc/inode.c
50977 +++ b/fs/proc/inode.c
50978 @@ -21,11 +21,17 @@
50979 #include <linux/seq_file.h>
50980 #include <linux/slab.h>
50981 #include <linux/mount.h>
50982 +#include <linux/grsecurity.h>
50983
50984 #include <asm/uaccess.h>
50985
50986 #include "internal.h"
50987
50988 +#ifdef CONFIG_PROC_SYSCTL
50989 +extern const struct inode_operations proc_sys_inode_operations;
50990 +extern const struct inode_operations proc_sys_dir_operations;
50991 +#endif
50992 +
50993 static void proc_evict_inode(struct inode *inode)
50994 {
50995 struct proc_dir_entry *de;
50996 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
50997 ns_ops = PROC_I(inode)->ns_ops;
50998 if (ns_ops && ns_ops->put)
50999 ns_ops->put(PROC_I(inode)->ns);
51000 +
51001 +#ifdef CONFIG_PROC_SYSCTL
51002 + if (inode->i_op == &proc_sys_inode_operations ||
51003 + inode->i_op == &proc_sys_dir_operations)
51004 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51005 +#endif
51006 +
51007 }
51008
51009 static struct kmem_cache * proc_inode_cachep;
51010 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51011 if (de->mode) {
51012 inode->i_mode = de->mode;
51013 inode->i_uid = de->uid;
51014 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51015 + inode->i_gid = grsec_proc_gid;
51016 +#else
51017 inode->i_gid = de->gid;
51018 +#endif
51019 }
51020 if (de->size)
51021 inode->i_size = de->size;
51022 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51023 index 43973b0..a20e704 100644
51024 --- a/fs/proc/internal.h
51025 +++ b/fs/proc/internal.h
51026 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51027 struct pid *pid, struct task_struct *task);
51028 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51029 struct pid *pid, struct task_struct *task);
51030 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51031 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51032 +#endif
51033 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51034
51035 extern const struct file_operations proc_tid_children_operations;
51036 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51037 index 86c67ee..cdca321 100644
51038 --- a/fs/proc/kcore.c
51039 +++ b/fs/proc/kcore.c
51040 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51041 * the addresses in the elf_phdr on our list.
51042 */
51043 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51044 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51045 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51046 + if (tsz > buflen)
51047 tsz = buflen;
51048 -
51049 +
51050 while (buflen) {
51051 struct kcore_list *m;
51052
51053 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51054 kfree(elf_buf);
51055 } else {
51056 if (kern_addr_valid(start)) {
51057 - unsigned long n;
51058 + char *elf_buf;
51059 + mm_segment_t oldfs;
51060
51061 - n = copy_to_user(buffer, (char *)start, tsz);
51062 - /*
51063 - * We cannot distinguish between fault on source
51064 - * and fault on destination. When this happens
51065 - * we clear too and hope it will trigger the
51066 - * EFAULT again.
51067 - */
51068 - if (n) {
51069 - if (clear_user(buffer + tsz - n,
51070 - n))
51071 + elf_buf = kmalloc(tsz, GFP_KERNEL);
51072 + if (!elf_buf)
51073 + return -ENOMEM;
51074 + oldfs = get_fs();
51075 + set_fs(KERNEL_DS);
51076 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51077 + set_fs(oldfs);
51078 + if (copy_to_user(buffer, elf_buf, tsz)) {
51079 + kfree(elf_buf);
51080 return -EFAULT;
51081 + }
51082 }
51083 + set_fs(oldfs);
51084 + kfree(elf_buf);
51085 } else {
51086 if (clear_user(buffer, tsz))
51087 return -EFAULT;
51088 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51089
51090 static int open_kcore(struct inode *inode, struct file *filp)
51091 {
51092 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51093 + return -EPERM;
51094 +#endif
51095 if (!capable(CAP_SYS_RAWIO))
51096 return -EPERM;
51097 if (kcore_need_update)
51098 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51099 index 80e4645..53e5fcf 100644
51100 --- a/fs/proc/meminfo.c
51101 +++ b/fs/proc/meminfo.c
51102 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51103 vmi.used >> 10,
51104 vmi.largest_chunk >> 10
51105 #ifdef CONFIG_MEMORY_FAILURE
51106 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51107 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51108 #endif
51109 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51110 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51111 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51112 index b1822dd..df622cb 100644
51113 --- a/fs/proc/nommu.c
51114 +++ b/fs/proc/nommu.c
51115 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51116 if (len < 1)
51117 len = 1;
51118 seq_printf(m, "%*c", len, ' ');
51119 - seq_path(m, &file->f_path, "");
51120 + seq_path(m, &file->f_path, "\n\\");
51121 }
51122
51123 seq_putc(m, '\n');
51124 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51125 index fe72cd0..cb9b67d 100644
51126 --- a/fs/proc/proc_net.c
51127 +++ b/fs/proc/proc_net.c
51128 @@ -23,6 +23,7 @@
51129 #include <linux/nsproxy.h>
51130 #include <net/net_namespace.h>
51131 #include <linux/seq_file.h>
51132 +#include <linux/grsecurity.h>
51133
51134 #include "internal.h"
51135
51136 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51137 struct task_struct *task;
51138 struct nsproxy *ns;
51139 struct net *net = NULL;
51140 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51141 + const struct cred *cred = current_cred();
51142 +#endif
51143 +
51144 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51145 + if (cred->fsuid)
51146 + return net;
51147 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51148 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
51149 + return net;
51150 +#endif
51151
51152 rcu_read_lock();
51153 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51154 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51155 index a781bdf..6665284 100644
51156 --- a/fs/proc/proc_sysctl.c
51157 +++ b/fs/proc/proc_sysctl.c
51158 @@ -12,11 +12,15 @@
51159 #include <linux/module.h>
51160 #include "internal.h"
51161
51162 +extern int gr_handle_chroot_sysctl(const int op);
51163 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51164 + const int op);
51165 +
51166 static const struct dentry_operations proc_sys_dentry_operations;
51167 static const struct file_operations proc_sys_file_operations;
51168 -static const struct inode_operations proc_sys_inode_operations;
51169 +const struct inode_operations proc_sys_inode_operations;
51170 static const struct file_operations proc_sys_dir_file_operations;
51171 -static const struct inode_operations proc_sys_dir_operations;
51172 +const struct inode_operations proc_sys_dir_operations;
51173
51174 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51175 {
51176 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51177
51178 err = NULL;
51179 d_set_d_op(dentry, &proc_sys_dentry_operations);
51180 +
51181 + gr_handle_proc_create(dentry, inode);
51182 +
51183 d_add(dentry, inode);
51184
51185 out:
51186 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51187 struct inode *inode = filp->f_path.dentry->d_inode;
51188 struct ctl_table_header *head = grab_header(inode);
51189 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51190 + int op = write ? MAY_WRITE : MAY_READ;
51191 ssize_t error;
51192 size_t res;
51193
51194 if (IS_ERR(head))
51195 return PTR_ERR(head);
51196
51197 +
51198 /*
51199 * At this point we know that the sysctl was not unregistered
51200 * and won't be until we finish.
51201 */
51202 error = -EPERM;
51203 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51204 + if (sysctl_perm(head->root, table, op))
51205 goto out;
51206
51207 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51208 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51209 if (!table->proc_handler)
51210 goto out;
51211
51212 +#ifdef CONFIG_GRKERNSEC
51213 + error = -EPERM;
51214 + if (gr_handle_chroot_sysctl(op))
51215 + goto out;
51216 + dget(filp->f_path.dentry);
51217 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51218 + dput(filp->f_path.dentry);
51219 + goto out;
51220 + }
51221 + dput(filp->f_path.dentry);
51222 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51223 + goto out;
51224 + if (write && !capable(CAP_SYS_ADMIN))
51225 + goto out;
51226 +#endif
51227 +
51228 /* careful: calling conventions are nasty here */
51229 res = count;
51230 error = table->proc_handler(table, write, buf, &res, ppos);
51231 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51232 return -ENOMEM;
51233 } else {
51234 d_set_d_op(child, &proc_sys_dentry_operations);
51235 +
51236 + gr_handle_proc_create(child, inode);
51237 +
51238 d_add(child, inode);
51239 }
51240 } else {
51241 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51242 if ((*pos)++ < file->f_pos)
51243 return 0;
51244
51245 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51246 + return 0;
51247 +
51248 if (unlikely(S_ISLNK(table->mode)))
51249 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51250 else
51251 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51252 if (IS_ERR(head))
51253 return PTR_ERR(head);
51254
51255 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51256 + return -ENOENT;
51257 +
51258 generic_fillattr(inode, stat);
51259 if (table)
51260 stat->mode = (stat->mode & S_IFMT) | table->mode;
51261 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51262 .llseek = generic_file_llseek,
51263 };
51264
51265 -static const struct inode_operations proc_sys_inode_operations = {
51266 +const struct inode_operations proc_sys_inode_operations = {
51267 .permission = proc_sys_permission,
51268 .setattr = proc_sys_setattr,
51269 .getattr = proc_sys_getattr,
51270 };
51271
51272 -static const struct inode_operations proc_sys_dir_operations = {
51273 +const struct inode_operations proc_sys_dir_operations = {
51274 .lookup = proc_sys_lookup,
51275 .permission = proc_sys_permission,
51276 .setattr = proc_sys_setattr,
51277 diff --git a/fs/proc/root.c b/fs/proc/root.c
51278 index 9889a92..2613b48 100644
51279 --- a/fs/proc/root.c
51280 +++ b/fs/proc/root.c
51281 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
51282 #ifdef CONFIG_PROC_DEVICETREE
51283 proc_device_tree_init();
51284 #endif
51285 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51286 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51287 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51288 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51289 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51290 +#endif
51291 +#else
51292 proc_mkdir("bus", NULL);
51293 +#endif
51294 proc_sys_init();
51295 }
51296
51297 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51298 index 90c63f9..e662cfc 100644
51299 --- a/fs/proc/task_mmu.c
51300 +++ b/fs/proc/task_mmu.c
51301 @@ -11,12 +11,19 @@
51302 #include <linux/rmap.h>
51303 #include <linux/swap.h>
51304 #include <linux/swapops.h>
51305 +#include <linux/grsecurity.h>
51306
51307 #include <asm/elf.h>
51308 #include <asm/uaccess.h>
51309 #include <asm/tlbflush.h>
51310 #include "internal.h"
51311
51312 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51313 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51314 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51315 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51316 +#endif
51317 +
51318 void task_mem(struct seq_file *m, struct mm_struct *mm)
51319 {
51320 unsigned long data, text, lib, swap;
51321 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51322 "VmExe:\t%8lu kB\n"
51323 "VmLib:\t%8lu kB\n"
51324 "VmPTE:\t%8lu kB\n"
51325 - "VmSwap:\t%8lu kB\n",
51326 - hiwater_vm << (PAGE_SHIFT-10),
51327 + "VmSwap:\t%8lu kB\n"
51328 +
51329 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51330 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51331 +#endif
51332 +
51333 + ,hiwater_vm << (PAGE_SHIFT-10),
51334 total_vm << (PAGE_SHIFT-10),
51335 mm->locked_vm << (PAGE_SHIFT-10),
51336 mm->pinned_vm << (PAGE_SHIFT-10),
51337 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51338 data << (PAGE_SHIFT-10),
51339 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51340 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51341 - swap << (PAGE_SHIFT-10));
51342 + swap << (PAGE_SHIFT-10)
51343 +
51344 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51345 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51346 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51347 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51348 +#else
51349 + , mm->context.user_cs_base
51350 + , mm->context.user_cs_limit
51351 +#endif
51352 +#endif
51353 +
51354 + );
51355 }
51356
51357 unsigned long task_vsize(struct mm_struct *mm)
51358 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51359 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51360 }
51361
51362 - /* We don't show the stack guard page in /proc/maps */
51363 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51364 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51365 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51366 +#else
51367 start = vma->vm_start;
51368 - if (stack_guard_page_start(vma, start))
51369 - start += PAGE_SIZE;
51370 end = vma->vm_end;
51371 - if (stack_guard_page_end(vma, end))
51372 - end -= PAGE_SIZE;
51373 +#endif
51374
51375 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51376 start,
51377 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51378 flags & VM_WRITE ? 'w' : '-',
51379 flags & VM_EXEC ? 'x' : '-',
51380 flags & VM_MAYSHARE ? 's' : 'p',
51381 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51382 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51383 +#else
51384 pgoff,
51385 +#endif
51386 MAJOR(dev), MINOR(dev), ino, &len);
51387
51388 /*
51389 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51390 */
51391 if (file) {
51392 pad_len_spaces(m, len);
51393 - seq_path(m, &file->f_path, "\n");
51394 + seq_path(m, &file->f_path, "\n\\");
51395 goto done;
51396 }
51397
51398 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51399 * Thread stack in /proc/PID/task/TID/maps or
51400 * the main process stack.
51401 */
51402 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51403 - vma->vm_end >= mm->start_stack)) {
51404 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51405 + (vma->vm_start <= mm->start_stack &&
51406 + vma->vm_end >= mm->start_stack)) {
51407 name = "[stack]";
51408 } else {
51409 /* Thread stack in /proc/PID/maps */
51410 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51411 struct proc_maps_private *priv = m->private;
51412 struct task_struct *task = priv->task;
51413
51414 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51415 + if (current->exec_id != m->exec_id) {
51416 + gr_log_badprocpid("maps");
51417 + return 0;
51418 + }
51419 +#endif
51420 +
51421 show_map_vma(m, vma, is_pid);
51422
51423 if (m->count < m->size) /* vma is copied successfully */
51424 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51425 .private = &mss,
51426 };
51427
51428 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51429 + if (current->exec_id != m->exec_id) {
51430 + gr_log_badprocpid("smaps");
51431 + return 0;
51432 + }
51433 +#endif
51434 memset(&mss, 0, sizeof mss);
51435 - mss.vma = vma;
51436 - /* mmap_sem is held in m_start */
51437 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51438 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51439 -
51440 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51441 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51442 +#endif
51443 + mss.vma = vma;
51444 + /* mmap_sem is held in m_start */
51445 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51446 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51447 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51448 + }
51449 +#endif
51450 show_map_vma(m, vma, is_pid);
51451
51452 seq_printf(m,
51453 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51454 "KernelPageSize: %8lu kB\n"
51455 "MMUPageSize: %8lu kB\n"
51456 "Locked: %8lu kB\n",
51457 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51458 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51459 +#else
51460 (vma->vm_end - vma->vm_start) >> 10,
51461 +#endif
51462 mss.resident >> 10,
51463 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51464 mss.shared_clean >> 10,
51465 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51466 int n;
51467 char buffer[50];
51468
51469 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51470 + if (current->exec_id != m->exec_id) {
51471 + gr_log_badprocpid("numa_maps");
51472 + return 0;
51473 + }
51474 +#endif
51475 +
51476 if (!mm)
51477 return 0;
51478
51479 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51480 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51481 mpol_cond_put(pol);
51482
51483 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51484 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51485 +#else
51486 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51487 +#endif
51488
51489 if (file) {
51490 seq_printf(m, " file=");
51491 - seq_path(m, &file->f_path, "\n\t= ");
51492 + seq_path(m, &file->f_path, "\n\t\\= ");
51493 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51494 seq_printf(m, " heap");
51495 } else {
51496 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51497 index 1ccfa53..0848f95 100644
51498 --- a/fs/proc/task_nommu.c
51499 +++ b/fs/proc/task_nommu.c
51500 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51501 else
51502 bytes += kobjsize(mm);
51503
51504 - if (current->fs && current->fs->users > 1)
51505 + if (current->fs && atomic_read(&current->fs->users) > 1)
51506 sbytes += kobjsize(current->fs);
51507 else
51508 bytes += kobjsize(current->fs);
51509 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51510
51511 if (file) {
51512 pad_len_spaces(m, len);
51513 - seq_path(m, &file->f_path, "");
51514 + seq_path(m, &file->f_path, "\n\\");
51515 } else if (mm) {
51516 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51517
51518 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51519 index 2d57e1a..43b1280 100644
51520 --- a/fs/pstore/ftrace.c
51521 +++ b/fs/pstore/ftrace.c
51522 @@ -28,7 +28,9 @@
51523 #include "internal.h"
51524
51525 static void notrace pstore_ftrace_call(unsigned long ip,
51526 - unsigned long parent_ip)
51527 + unsigned long parent_ip,
51528 + struct ftrace_ops *op,
51529 + struct pt_regs *regs)
51530 {
51531 unsigned long flags;
51532 struct pstore_ftrace_record rec = {};
51533 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51534 index 16e8abb..2dcf914 100644
51535 --- a/fs/quota/netlink.c
51536 +++ b/fs/quota/netlink.c
51537 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51538 void quota_send_warning(struct kqid qid, dev_t dev,
51539 const char warntype)
51540 {
51541 - static atomic_t seq;
51542 + static atomic_unchecked_t seq;
51543 struct sk_buff *skb;
51544 void *msg_head;
51545 int ret;
51546 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51547 "VFS: Not enough memory to send quota warning.\n");
51548 return;
51549 }
51550 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51551 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51552 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51553 if (!msg_head) {
51554 printk(KERN_ERR
51555 diff --git a/fs/read_write.c b/fs/read_write.c
51556 index d065348..8e2b43d 100644
51557 --- a/fs/read_write.c
51558 +++ b/fs/read_write.c
51559 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51560 if (retval > 0) {
51561 add_rchar(current, retval);
51562 add_wchar(current, retval);
51563 + fsnotify_access(in.file);
51564 + fsnotify_modify(out.file);
51565 }
51566
51567 inc_syscr(current);
51568 diff --git a/fs/readdir.c b/fs/readdir.c
51569 index 5e69ef5..e5d9099 100644
51570 --- a/fs/readdir.c
51571 +++ b/fs/readdir.c
51572 @@ -17,6 +17,7 @@
51573 #include <linux/security.h>
51574 #include <linux/syscalls.h>
51575 #include <linux/unistd.h>
51576 +#include <linux/namei.h>
51577
51578 #include <asm/uaccess.h>
51579
51580 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51581
51582 struct readdir_callback {
51583 struct old_linux_dirent __user * dirent;
51584 + struct file * file;
51585 int result;
51586 };
51587
51588 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51589 buf->result = -EOVERFLOW;
51590 return -EOVERFLOW;
51591 }
51592 +
51593 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51594 + return 0;
51595 +
51596 buf->result++;
51597 dirent = buf->dirent;
51598 if (!access_ok(VERIFY_WRITE, dirent,
51599 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51600
51601 buf.result = 0;
51602 buf.dirent = dirent;
51603 + buf.file = f.file;
51604
51605 error = vfs_readdir(f.file, fillonedir, &buf);
51606 if (buf.result)
51607 @@ -139,6 +146,7 @@ struct linux_dirent {
51608 struct getdents_callback {
51609 struct linux_dirent __user * current_dir;
51610 struct linux_dirent __user * previous;
51611 + struct file * file;
51612 int count;
51613 int error;
51614 };
51615 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51616 buf->error = -EOVERFLOW;
51617 return -EOVERFLOW;
51618 }
51619 +
51620 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51621 + return 0;
51622 +
51623 dirent = buf->previous;
51624 if (dirent) {
51625 if (__put_user(offset, &dirent->d_off))
51626 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51627 buf.previous = NULL;
51628 buf.count = count;
51629 buf.error = 0;
51630 + buf.file = f.file;
51631
51632 error = vfs_readdir(f.file, filldir, &buf);
51633 if (error >= 0)
51634 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51635 struct getdents_callback64 {
51636 struct linux_dirent64 __user * current_dir;
51637 struct linux_dirent64 __user * previous;
51638 + struct file *file;
51639 int count;
51640 int error;
51641 };
51642 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51643 buf->error = -EINVAL; /* only used if we fail.. */
51644 if (reclen > buf->count)
51645 return -EINVAL;
51646 +
51647 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51648 + return 0;
51649 +
51650 dirent = buf->previous;
51651 if (dirent) {
51652 if (__put_user(offset, &dirent->d_off))
51653 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51654
51655 buf.current_dir = dirent;
51656 buf.previous = NULL;
51657 + buf.file = f.file;
51658 buf.count = count;
51659 buf.error = 0;
51660
51661 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51662 error = buf.error;
51663 lastdirent = buf.previous;
51664 if (lastdirent) {
51665 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
51666 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51667 if (__put_user(d_off, &lastdirent->d_off))
51668 error = -EFAULT;
51669 else
51670 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51671 index 2b7882b..1c5ef48 100644
51672 --- a/fs/reiserfs/do_balan.c
51673 +++ b/fs/reiserfs/do_balan.c
51674 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51675 return;
51676 }
51677
51678 - atomic_inc(&(fs_generation(tb->tb_sb)));
51679 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51680 do_balance_starts(tb);
51681
51682 /* balance leaf returns 0 except if combining L R and S into
51683 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51684 index e60e870..f40ac16 100644
51685 --- a/fs/reiserfs/procfs.c
51686 +++ b/fs/reiserfs/procfs.c
51687 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51688 "SMALL_TAILS " : "NO_TAILS ",
51689 replay_only(sb) ? "REPLAY_ONLY " : "",
51690 convert_reiserfs(sb) ? "CONV " : "",
51691 - atomic_read(&r->s_generation_counter),
51692 + atomic_read_unchecked(&r->s_generation_counter),
51693 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51694 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51695 SF(s_good_search_by_key_reada), SF(s_bmaps),
51696 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51697 index 33215f5..c5d427a 100644
51698 --- a/fs/reiserfs/reiserfs.h
51699 +++ b/fs/reiserfs/reiserfs.h
51700 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51701 /* Comment? -Hans */
51702 wait_queue_head_t s_wait;
51703 /* To be obsoleted soon by per buffer seals.. -Hans */
51704 - atomic_t s_generation_counter; // increased by one every time the
51705 + atomic_unchecked_t s_generation_counter; // increased by one every time the
51706 // tree gets re-balanced
51707 unsigned long s_properties; /* File system properties. Currently holds
51708 on-disk FS format */
51709 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51710 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51711
51712 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51713 -#define get_generation(s) atomic_read (&fs_generation(s))
51714 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51715 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51716 #define __fs_changed(gen,s) (gen != get_generation (s))
51717 #define fs_changed(gen,s) \
51718 diff --git a/fs/select.c b/fs/select.c
51719 index 2ef72d9..f213b17 100644
51720 --- a/fs/select.c
51721 +++ b/fs/select.c
51722 @@ -20,6 +20,7 @@
51723 #include <linux/export.h>
51724 #include <linux/slab.h>
51725 #include <linux/poll.h>
51726 +#include <linux/security.h>
51727 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51728 #include <linux/file.h>
51729 #include <linux/fdtable.h>
51730 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51731 struct poll_list *walk = head;
51732 unsigned long todo = nfds;
51733
51734 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51735 if (nfds > rlimit(RLIMIT_NOFILE))
51736 return -EINVAL;
51737
51738 diff --git a/fs/seq_file.c b/fs/seq_file.c
51739 index 99dffab..e4fcb71 100644
51740 --- a/fs/seq_file.c
51741 +++ b/fs/seq_file.c
51742 @@ -10,6 +10,7 @@
51743 #include <linux/seq_file.h>
51744 #include <linux/slab.h>
51745 #include <linux/cred.h>
51746 +#include <linux/sched.h>
51747
51748 #include <asm/uaccess.h>
51749 #include <asm/page.h>
51750 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51751 #ifdef CONFIG_USER_NS
51752 p->user_ns = file->f_cred->user_ns;
51753 #endif
51754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51755 + p->exec_id = current->exec_id;
51756 +#endif
51757
51758 /*
51759 * Wrappers around seq_open(e.g. swaps_open) need to be
51760 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51761 return 0;
51762 }
51763 if (!m->buf) {
51764 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51765 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51766 if (!m->buf)
51767 return -ENOMEM;
51768 }
51769 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51770 Eoverflow:
51771 m->op->stop(m, p);
51772 kfree(m->buf);
51773 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51774 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51775 return !m->buf ? -ENOMEM : -EAGAIN;
51776 }
51777
51778 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51779
51780 /* grab buffer if we didn't have one */
51781 if (!m->buf) {
51782 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51783 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51784 if (!m->buf)
51785 goto Enomem;
51786 }
51787 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51788 goto Fill;
51789 m->op->stop(m, p);
51790 kfree(m->buf);
51791 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51792 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51793 if (!m->buf)
51794 goto Enomem;
51795 m->count = 0;
51796 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
51797 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
51798 void *data)
51799 {
51800 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
51801 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
51802 int res = -ENOMEM;
51803
51804 if (op) {
51805 diff --git a/fs/splice.c b/fs/splice.c
51806 index 48c7bd1..d0740e4 100644
51807 --- a/fs/splice.c
51808 +++ b/fs/splice.c
51809 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51810 pipe_lock(pipe);
51811
51812 for (;;) {
51813 - if (!pipe->readers) {
51814 + if (!atomic_read(&pipe->readers)) {
51815 send_sig(SIGPIPE, current, 0);
51816 if (!ret)
51817 ret = -EPIPE;
51818 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51819 do_wakeup = 0;
51820 }
51821
51822 - pipe->waiting_writers++;
51823 + atomic_inc(&pipe->waiting_writers);
51824 pipe_wait(pipe);
51825 - pipe->waiting_writers--;
51826 + atomic_dec(&pipe->waiting_writers);
51827 }
51828
51829 pipe_unlock(pipe);
51830 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
51831 old_fs = get_fs();
51832 set_fs(get_ds());
51833 /* The cast to a user pointer is valid due to the set_fs() */
51834 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
51835 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
51836 set_fs(old_fs);
51837
51838 return res;
51839 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
51840 old_fs = get_fs();
51841 set_fs(get_ds());
51842 /* The cast to a user pointer is valid due to the set_fs() */
51843 - res = vfs_write(file, (const char __user *)buf, count, &pos);
51844 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
51845 set_fs(old_fs);
51846
51847 return res;
51848 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
51849 goto err;
51850
51851 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
51852 - vec[i].iov_base = (void __user *) page_address(page);
51853 + vec[i].iov_base = (void __force_user *) page_address(page);
51854 vec[i].iov_len = this_len;
51855 spd.pages[i] = page;
51856 spd.nr_pages++;
51857 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
51858 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
51859 {
51860 while (!pipe->nrbufs) {
51861 - if (!pipe->writers)
51862 + if (!atomic_read(&pipe->writers))
51863 return 0;
51864
51865 - if (!pipe->waiting_writers && sd->num_spliced)
51866 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
51867 return 0;
51868
51869 if (sd->flags & SPLICE_F_NONBLOCK)
51870 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
51871 * out of the pipe right after the splice_to_pipe(). So set
51872 * PIPE_READERS appropriately.
51873 */
51874 - pipe->readers = 1;
51875 + atomic_set(&pipe->readers, 1);
51876
51877 current->splice_pipe = pipe;
51878 }
51879 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51880 ret = -ERESTARTSYS;
51881 break;
51882 }
51883 - if (!pipe->writers)
51884 + if (!atomic_read(&pipe->writers))
51885 break;
51886 - if (!pipe->waiting_writers) {
51887 + if (!atomic_read(&pipe->waiting_writers)) {
51888 if (flags & SPLICE_F_NONBLOCK) {
51889 ret = -EAGAIN;
51890 break;
51891 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51892 pipe_lock(pipe);
51893
51894 while (pipe->nrbufs >= pipe->buffers) {
51895 - if (!pipe->readers) {
51896 + if (!atomic_read(&pipe->readers)) {
51897 send_sig(SIGPIPE, current, 0);
51898 ret = -EPIPE;
51899 break;
51900 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51901 ret = -ERESTARTSYS;
51902 break;
51903 }
51904 - pipe->waiting_writers++;
51905 + atomic_inc(&pipe->waiting_writers);
51906 pipe_wait(pipe);
51907 - pipe->waiting_writers--;
51908 + atomic_dec(&pipe->waiting_writers);
51909 }
51910
51911 pipe_unlock(pipe);
51912 @@ -1826,14 +1826,14 @@ retry:
51913 pipe_double_lock(ipipe, opipe);
51914
51915 do {
51916 - if (!opipe->readers) {
51917 + if (!atomic_read(&opipe->readers)) {
51918 send_sig(SIGPIPE, current, 0);
51919 if (!ret)
51920 ret = -EPIPE;
51921 break;
51922 }
51923
51924 - if (!ipipe->nrbufs && !ipipe->writers)
51925 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
51926 break;
51927
51928 /*
51929 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51930 pipe_double_lock(ipipe, opipe);
51931
51932 do {
51933 - if (!opipe->readers) {
51934 + if (!atomic_read(&opipe->readers)) {
51935 send_sig(SIGPIPE, current, 0);
51936 if (!ret)
51937 ret = -EPIPE;
51938 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51939 * return EAGAIN if we have the potential of some data in the
51940 * future, otherwise just return 0
51941 */
51942 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51943 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51944 ret = -EAGAIN;
51945
51946 pipe_unlock(ipipe);
51947 diff --git a/fs/stat.c b/fs/stat.c
51948 index eae4946..6198f55 100644
51949 --- a/fs/stat.c
51950 +++ b/fs/stat.c
51951 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
51952 stat->gid = inode->i_gid;
51953 stat->rdev = inode->i_rdev;
51954 stat->size = i_size_read(inode);
51955 - stat->atime = inode->i_atime;
51956 - stat->mtime = inode->i_mtime;
51957 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
51958 + stat->atime = inode->i_ctime;
51959 + stat->mtime = inode->i_ctime;
51960 + } else {
51961 + stat->atime = inode->i_atime;
51962 + stat->mtime = inode->i_mtime;
51963 + }
51964 stat->ctime = inode->i_ctime;
51965 stat->blksize = (1 << inode->i_blkbits);
51966 stat->blocks = inode->i_blocks;
51967 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51968 if (retval)
51969 return retval;
51970
51971 - if (inode->i_op->getattr)
51972 - return inode->i_op->getattr(mnt, dentry, stat);
51973 + if (inode->i_op->getattr) {
51974 + retval = inode->i_op->getattr(mnt, dentry, stat);
51975 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
51976 + stat->atime = stat->ctime;
51977 + stat->mtime = stat->ctime;
51978 + }
51979 + return retval;
51980 + }
51981
51982 generic_fillattr(inode, stat);
51983 return 0;
51984 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
51985 index 2fbdff6..5530a61 100644
51986 --- a/fs/sysfs/dir.c
51987 +++ b/fs/sysfs/dir.c
51988 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
51989 struct sysfs_dirent *sd;
51990 int rc;
51991
51992 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51993 + const char *parent_name = parent_sd->s_name;
51994 +
51995 + mode = S_IFDIR | S_IRWXU;
51996 +
51997 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
51998 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
51999 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52000 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52001 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52002 +#endif
52003 +
52004 /* allocate */
52005 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52006 if (!sd)
52007 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52008 index 00012e3..8392349 100644
52009 --- a/fs/sysfs/file.c
52010 +++ b/fs/sysfs/file.c
52011 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52012
52013 struct sysfs_open_dirent {
52014 atomic_t refcnt;
52015 - atomic_t event;
52016 + atomic_unchecked_t event;
52017 wait_queue_head_t poll;
52018 struct list_head buffers; /* goes through sysfs_buffer.list */
52019 };
52020 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52021 if (!sysfs_get_active(attr_sd))
52022 return -ENODEV;
52023
52024 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52025 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52026 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52027
52028 sysfs_put_active(attr_sd);
52029 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52030 return -ENOMEM;
52031
52032 atomic_set(&new_od->refcnt, 0);
52033 - atomic_set(&new_od->event, 1);
52034 + atomic_set_unchecked(&new_od->event, 1);
52035 init_waitqueue_head(&new_od->poll);
52036 INIT_LIST_HEAD(&new_od->buffers);
52037 goto retry;
52038 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52039
52040 sysfs_put_active(attr_sd);
52041
52042 - if (buffer->event != atomic_read(&od->event))
52043 + if (buffer->event != atomic_read_unchecked(&od->event))
52044 goto trigger;
52045
52046 return DEFAULT_POLLMASK;
52047 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52048
52049 od = sd->s_attr.open;
52050 if (od) {
52051 - atomic_inc(&od->event);
52052 + atomic_inc_unchecked(&od->event);
52053 wake_up_interruptible(&od->poll);
52054 }
52055
52056 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52057 index 3c9eb56..9dea5be 100644
52058 --- a/fs/sysfs/symlink.c
52059 +++ b/fs/sysfs/symlink.c
52060 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52061
52062 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52063 {
52064 - char *page = nd_get_link(nd);
52065 + const char *page = nd_get_link(nd);
52066 if (!IS_ERR(page))
52067 free_page((unsigned long)page);
52068 }
52069 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52070 index c175b4d..8f36a16 100644
52071 --- a/fs/udf/misc.c
52072 +++ b/fs/udf/misc.c
52073 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52074
52075 u8 udf_tag_checksum(const struct tag *t)
52076 {
52077 - u8 *data = (u8 *)t;
52078 + const u8 *data = (const u8 *)t;
52079 u8 checksum = 0;
52080 int i;
52081 for (i = 0; i < sizeof(struct tag); ++i)
52082 diff --git a/fs/utimes.c b/fs/utimes.c
52083 index bb0696a..552054b 100644
52084 --- a/fs/utimes.c
52085 +++ b/fs/utimes.c
52086 @@ -1,6 +1,7 @@
52087 #include <linux/compiler.h>
52088 #include <linux/file.h>
52089 #include <linux/fs.h>
52090 +#include <linux/security.h>
52091 #include <linux/linkage.h>
52092 #include <linux/mount.h>
52093 #include <linux/namei.h>
52094 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52095 goto mnt_drop_write_and_out;
52096 }
52097 }
52098 +
52099 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52100 + error = -EACCES;
52101 + goto mnt_drop_write_and_out;
52102 + }
52103 +
52104 mutex_lock(&inode->i_mutex);
52105 error = notify_change(path->dentry, &newattrs);
52106 mutex_unlock(&inode->i_mutex);
52107 diff --git a/fs/xattr.c b/fs/xattr.c
52108 index e21c119..21dfc7c 100644
52109 --- a/fs/xattr.c
52110 +++ b/fs/xattr.c
52111 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52112 * Extended attribute SET operations
52113 */
52114 static long
52115 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
52116 +setxattr(struct path *path, const char __user *name, const void __user *value,
52117 size_t size, int flags)
52118 {
52119 int error;
52120 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52121 posix_acl_fix_xattr_from_user(kvalue, size);
52122 }
52123
52124 - error = vfs_setxattr(d, kname, kvalue, size, flags);
52125 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52126 + error = -EACCES;
52127 + goto out;
52128 + }
52129 +
52130 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52131 out:
52132 if (vvalue)
52133 vfree(vvalue);
52134 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52135 return error;
52136 error = mnt_want_write(path.mnt);
52137 if (!error) {
52138 - error = setxattr(path.dentry, name, value, size, flags);
52139 + error = setxattr(&path, name, value, size, flags);
52140 mnt_drop_write(path.mnt);
52141 }
52142 path_put(&path);
52143 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52144 return error;
52145 error = mnt_want_write(path.mnt);
52146 if (!error) {
52147 - error = setxattr(path.dentry, name, value, size, flags);
52148 + error = setxattr(&path, name, value, size, flags);
52149 mnt_drop_write(path.mnt);
52150 }
52151 path_put(&path);
52152 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52153 const void __user *,value, size_t, size, int, flags)
52154 {
52155 struct fd f = fdget(fd);
52156 - struct dentry *dentry;
52157 int error = -EBADF;
52158
52159 if (!f.file)
52160 return error;
52161 - dentry = f.file->f_path.dentry;
52162 - audit_inode(NULL, dentry, 0);
52163 + audit_inode(NULL, f.file->f_path.dentry, 0);
52164 error = mnt_want_write_file(f.file);
52165 if (!error) {
52166 - error = setxattr(dentry, name, value, size, flags);
52167 + error = setxattr(&f.file->f_path, name, value, size, flags);
52168 mnt_drop_write_file(f.file);
52169 }
52170 fdput(f);
52171 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52172 index 9fbea87..6b19972 100644
52173 --- a/fs/xattr_acl.c
52174 +++ b/fs/xattr_acl.c
52175 @@ -76,8 +76,8 @@ struct posix_acl *
52176 posix_acl_from_xattr(struct user_namespace *user_ns,
52177 const void *value, size_t size)
52178 {
52179 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52180 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52181 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52182 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52183 int count;
52184 struct posix_acl *acl;
52185 struct posix_acl_entry *acl_e;
52186 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52187 index 83d0cf3..2ef526b 100644
52188 --- a/fs/xfs/xfs_bmap.c
52189 +++ b/fs/xfs/xfs_bmap.c
52190 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52191 int nmap,
52192 int ret_nmap);
52193 #else
52194 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52195 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52196 #endif /* DEBUG */
52197
52198 STATIC int
52199 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52200 index 1b9fc3e..e1bdde0 100644
52201 --- a/fs/xfs/xfs_dir2_sf.c
52202 +++ b/fs/xfs/xfs_dir2_sf.c
52203 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52204 }
52205
52206 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52207 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52208 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52209 + char name[sfep->namelen];
52210 + memcpy(name, sfep->name, sfep->namelen);
52211 + if (filldir(dirent, name, sfep->namelen,
52212 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
52213 + *offset = off & 0x7fffffff;
52214 + return 0;
52215 + }
52216 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52217 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52218 *offset = off & 0x7fffffff;
52219 return 0;
52220 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52221 index c1df3c6..f987db6 100644
52222 --- a/fs/xfs/xfs_ioctl.c
52223 +++ b/fs/xfs/xfs_ioctl.c
52224 @@ -126,7 +126,7 @@ xfs_find_handle(
52225 }
52226
52227 error = -EFAULT;
52228 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52229 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52230 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52231 goto out_put;
52232
52233 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52234 index 4e00cf0..3374374 100644
52235 --- a/fs/xfs/xfs_iops.c
52236 +++ b/fs/xfs/xfs_iops.c
52237 @@ -394,7 +394,7 @@ xfs_vn_put_link(
52238 struct nameidata *nd,
52239 void *p)
52240 {
52241 - char *s = nd_get_link(nd);
52242 + const char *s = nd_get_link(nd);
52243
52244 if (!IS_ERR(s))
52245 kfree(s);
52246 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52247 new file mode 100644
52248 index 0000000..92247e4
52249 --- /dev/null
52250 +++ b/grsecurity/Kconfig
52251 @@ -0,0 +1,1021 @@
52252 +#
52253 +# grecurity configuration
52254 +#
52255 +menu "Memory Protections"
52256 +depends on GRKERNSEC
52257 +
52258 +config GRKERNSEC_KMEM
52259 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52260 + default y if GRKERNSEC_CONFIG_AUTO
52261 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52262 + help
52263 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52264 + be written to or read from to modify or leak the contents of the running
52265 + kernel. /dev/port will also not be allowed to be opened and support
52266 + for /dev/cpu/*/msr will be removed. If you have module
52267 + support disabled, enabling this will close up five ways that are
52268 + currently used to insert malicious code into the running kernel.
52269 +
52270 + Even with all these features enabled, we still highly recommend that
52271 + you use the RBAC system, as it is still possible for an attacker to
52272 + modify the running kernel through privileged I/O granted by ioperm/iopl.
52273 +
52274 + If you are not using XFree86, you may be able to stop this additional
52275 + case by enabling the 'Disable privileged I/O' option. Though nothing
52276 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52277 + but only to video memory, which is the only writing we allow in this
52278 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52279 + not be allowed to mprotect it with PROT_WRITE later.
52280 + Enabling this feature will prevent the "cpupower" and "powertop" tools
52281 + from working.
52282 +
52283 + It is highly recommended that you say Y here if you meet all the
52284 + conditions above.
52285 +
52286 +config GRKERNSEC_VM86
52287 + bool "Restrict VM86 mode"
52288 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52289 + depends on X86_32
52290 +
52291 + help
52292 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52293 + make use of a special execution mode on 32bit x86 processors called
52294 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52295 + video cards and will still work with this option enabled. The purpose
52296 + of the option is to prevent exploitation of emulation errors in
52297 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
52298 + Nearly all users should be able to enable this option.
52299 +
52300 +config GRKERNSEC_IO
52301 + bool "Disable privileged I/O"
52302 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52303 + depends on X86
52304 + select RTC_CLASS
52305 + select RTC_INTF_DEV
52306 + select RTC_DRV_CMOS
52307 +
52308 + help
52309 + If you say Y here, all ioperm and iopl calls will return an error.
52310 + Ioperm and iopl can be used to modify the running kernel.
52311 + Unfortunately, some programs need this access to operate properly,
52312 + the most notable of which are XFree86 and hwclock. hwclock can be
52313 + remedied by having RTC support in the kernel, so real-time
52314 + clock support is enabled if this option is enabled, to ensure
52315 + that hwclock operates correctly. XFree86 still will not
52316 + operate correctly with this option enabled, so DO NOT CHOOSE Y
52317 + IF YOU USE XFree86. If you use XFree86 and you still want to
52318 + protect your kernel against modification, use the RBAC system.
52319 +
52320 +config GRKERNSEC_JIT_HARDEN
52321 + bool "Harden BPF JIT against spray attacks"
52322 + default y if GRKERNSEC_CONFIG_AUTO
52323 + depends on BPF_JIT
52324 + help
52325 + If you say Y here, the native code generated by the kernel's Berkeley
52326 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52327 + attacks that attempt to fit attacker-beneficial instructions in
52328 + 32bit immediate fields of JIT-generated native instructions. The
52329 + attacker will generally aim to cause an unintended instruction sequence
52330 + of JIT-generated native code to execute by jumping into the middle of
52331 + a generated instruction. This feature effectively randomizes the 32bit
52332 + immediate constants present in the generated code to thwart such attacks.
52333 +
52334 + If you're using KERNEXEC, it's recommended that you enable this option
52335 + to supplement the hardening of the kernel.
52336 +
52337 +config GRKERNSEC_RAND_THREADSTACK
52338 + bool "Insert random gaps between thread stacks"
52339 + default y if GRKERNSEC_CONFIG_AUTO
52340 + depends on PAX_RANDMMAP && !PPC
52341 + help
52342 + If you say Y here, a random-sized gap will be enforced between allocated
52343 + thread stacks. Glibc's NPTL and other threading libraries that
52344 + pass MAP_STACK to the kernel for thread stack allocation are supported.
52345 + The implementation currently provides 8 bits of entropy for the gap.
52346 +
52347 + Many distributions do not compile threaded remote services with the
52348 + -fstack-check argument to GCC, causing the variable-sized stack-based
52349 + allocator, alloca(), to not probe the stack on allocation. This
52350 + permits an unbounded alloca() to skip over any guard page and potentially
52351 + modify another thread's stack reliably. An enforced random gap
52352 + reduces the reliability of such an attack and increases the chance
52353 + that such a read/write to another thread's stack instead lands in
52354 + an unmapped area, causing a crash and triggering grsecurity's
52355 + anti-bruteforcing logic.
52356 +
52357 +config GRKERNSEC_PROC_MEMMAP
52358 + bool "Harden ASLR against information leaks and entropy reduction"
52359 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52360 + depends on PAX_NOEXEC || PAX_ASLR
52361 + help
52362 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52363 + give no information about the addresses of its mappings if
52364 + PaX features that rely on random addresses are enabled on the task.
52365 + In addition to sanitizing this information and disabling other
52366 + dangerous sources of information, this option causes reads of sensitive
52367 + /proc/<pid> entries where the file descriptor was opened in a different
52368 + task than the one performing the read. Such attempts are logged.
52369 + This option also limits argv/env strings for suid/sgid binaries
52370 + to 512KB to prevent a complete exhaustion of the stack entropy provided
52371 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52372 + binaries to prevent alternative mmap layouts from being abused.
52373 +
52374 + If you use PaX it is essential that you say Y here as it closes up
52375 + several holes that make full ASLR useless locally.
52376 +
52377 +config GRKERNSEC_BRUTE
52378 + bool "Deter exploit bruteforcing"
52379 + default y if GRKERNSEC_CONFIG_AUTO
52380 + help
52381 + If you say Y here, attempts to bruteforce exploits against forking
52382 + daemons such as apache or sshd, as well as against suid/sgid binaries
52383 + will be deterred. When a child of a forking daemon is killed by PaX
52384 + or crashes due to an illegal instruction or other suspicious signal,
52385 + the parent process will be delayed 30 seconds upon every subsequent
52386 + fork until the administrator is able to assess the situation and
52387 + restart the daemon.
52388 + In the suid/sgid case, the attempt is logged, the user has all their
52389 + processes terminated, and they are prevented from executing any further
52390 + processes for 15 minutes.
52391 + It is recommended that you also enable signal logging in the auditing
52392 + section so that logs are generated when a process triggers a suspicious
52393 + signal.
52394 + If the sysctl option is enabled, a sysctl option with name
52395 + "deter_bruteforce" is created.
52396 +
52397 +
52398 +config GRKERNSEC_MODHARDEN
52399 + bool "Harden module auto-loading"
52400 + default y if GRKERNSEC_CONFIG_AUTO
52401 + depends on MODULES
52402 + help
52403 + If you say Y here, module auto-loading in response to use of some
52404 + feature implemented by an unloaded module will be restricted to
52405 + root users. Enabling this option helps defend against attacks
52406 + by unprivileged users who abuse the auto-loading behavior to
52407 + cause a vulnerable module to load that is then exploited.
52408 +
52409 + If this option prevents a legitimate use of auto-loading for a
52410 + non-root user, the administrator can execute modprobe manually
52411 + with the exact name of the module mentioned in the alert log.
52412 + Alternatively, the administrator can add the module to the list
52413 + of modules loaded at boot by modifying init scripts.
52414 +
52415 + Modification of init scripts will most likely be needed on
52416 + Ubuntu servers with encrypted home directory support enabled,
52417 + as the first non-root user logging in will cause the ecb(aes),
52418 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52419 +
52420 +config GRKERNSEC_HIDESYM
52421 + bool "Hide kernel symbols"
52422 + default y if GRKERNSEC_CONFIG_AUTO
52423 + select PAX_USERCOPY_SLABS
52424 + help
52425 + If you say Y here, getting information on loaded modules, and
52426 + displaying all kernel symbols through a syscall will be restricted
52427 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52428 + /proc/kallsyms will be restricted to the root user. The RBAC
52429 + system can hide that entry even from root.
52430 +
52431 + This option also prevents leaking of kernel addresses through
52432 + several /proc entries.
52433 +
52434 + Note that this option is only effective provided the following
52435 + conditions are met:
52436 + 1) The kernel using grsecurity is not precompiled by some distribution
52437 + 2) You have also enabled GRKERNSEC_DMESG
52438 + 3) You are using the RBAC system and hiding other files such as your
52439 + kernel image and System.map. Alternatively, enabling this option
52440 + causes the permissions on /boot, /lib/modules, and the kernel
52441 + source directory to change at compile time to prevent
52442 + reading by non-root users.
52443 + If the above conditions are met, this option will aid in providing a
52444 + useful protection against local kernel exploitation of overflows
52445 + and arbitrary read/write vulnerabilities.
52446 +
52447 +config GRKERNSEC_KERN_LOCKOUT
52448 + bool "Active kernel exploit response"
52449 + default y if GRKERNSEC_CONFIG_AUTO
52450 + depends on X86 || ARM || PPC || SPARC
52451 + help
52452 + If you say Y here, when a PaX alert is triggered due to suspicious
52453 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52454 + or an OOPS occurs due to bad memory accesses, instead of just
52455 + terminating the offending process (and potentially allowing
52456 + a subsequent exploit from the same user), we will take one of two
52457 + actions:
52458 + If the user was root, we will panic the system
52459 + If the user was non-root, we will log the attempt, terminate
52460 + all processes owned by the user, then prevent them from creating
52461 + any new processes until the system is restarted
52462 + This deters repeated kernel exploitation/bruteforcing attempts
52463 + and is useful for later forensics.
52464 +
52465 +endmenu
52466 +menu "Role Based Access Control Options"
52467 +depends on GRKERNSEC
52468 +
52469 +config GRKERNSEC_RBAC_DEBUG
52470 + bool
52471 +
52472 +config GRKERNSEC_NO_RBAC
52473 + bool "Disable RBAC system"
52474 + help
52475 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52476 + preventing the RBAC system from being enabled. You should only say Y
52477 + here if you have no intention of using the RBAC system, so as to prevent
52478 + an attacker with root access from misusing the RBAC system to hide files
52479 + and processes when loadable module support and /dev/[k]mem have been
52480 + locked down.
52481 +
52482 +config GRKERNSEC_ACL_HIDEKERN
52483 + bool "Hide kernel processes"
52484 + help
52485 + If you say Y here, all kernel threads will be hidden to all
52486 + processes but those whose subject has the "view hidden processes"
52487 + flag.
52488 +
52489 +config GRKERNSEC_ACL_MAXTRIES
52490 + int "Maximum tries before password lockout"
52491 + default 3
52492 + help
52493 + This option enforces the maximum number of times a user can attempt
52494 + to authorize themselves with the grsecurity RBAC system before being
52495 + denied the ability to attempt authorization again for a specified time.
52496 + The lower the number, the harder it will be to brute-force a password.
52497 +
52498 +config GRKERNSEC_ACL_TIMEOUT
52499 + int "Time to wait after max password tries, in seconds"
52500 + default 30
52501 + help
52502 + This option specifies the time the user must wait after attempting to
52503 + authorize to the RBAC system with the maximum number of invalid
52504 + passwords. The higher the number, the harder it will be to brute-force
52505 + a password.
52506 +
52507 +endmenu
52508 +menu "Filesystem Protections"
52509 +depends on GRKERNSEC
52510 +
52511 +config GRKERNSEC_PROC
52512 + bool "Proc restrictions"
52513 + default y if GRKERNSEC_CONFIG_AUTO
52514 + help
52515 + If you say Y here, the permissions of the /proc filesystem
52516 + will be altered to enhance system security and privacy. You MUST
52517 + choose either a user only restriction or a user and group restriction.
52518 + Depending upon the option you choose, you can either restrict users to
52519 + see only the processes they themselves run, or choose a group that can
52520 + view all processes and files normally restricted to root if you choose
52521 + the "restrict to user only" option. NOTE: If you're running identd or
52522 + ntpd as a non-root user, you will have to run it as the group you
52523 + specify here.
52524 +
52525 +config GRKERNSEC_PROC_USER
52526 + bool "Restrict /proc to user only"
52527 + depends on GRKERNSEC_PROC
52528 + help
52529 + If you say Y here, non-root users will only be able to view their own
52530 + processes, and restricts them from viewing network-related information,
52531 + and viewing kernel symbol and module information.
52532 +
52533 +config GRKERNSEC_PROC_USERGROUP
52534 + bool "Allow special group"
52535 + default y if GRKERNSEC_CONFIG_AUTO
52536 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52537 + help
52538 + If you say Y here, you will be able to select a group that will be
52539 + able to view all processes and network-related information. If you've
52540 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52541 + remain hidden. This option is useful if you want to run identd as
52542 + a non-root user. The group you select may also be chosen at boot time
52543 + via "grsec_proc_gid=" on the kernel commandline.
52544 +
52545 +config GRKERNSEC_PROC_GID
52546 + int "GID for special group"
52547 + depends on GRKERNSEC_PROC_USERGROUP
52548 + default 1001
52549 +
52550 +config GRKERNSEC_PROC_ADD
52551 + bool "Additional restrictions"
52552 + default y if GRKERNSEC_CONFIG_AUTO
52553 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52554 + help
52555 + If you say Y here, additional restrictions will be placed on
52556 + /proc that keep normal users from viewing device information and
52557 + slabinfo information that could be useful for exploits.
52558 +
52559 +config GRKERNSEC_LINK
52560 + bool "Linking restrictions"
52561 + default y if GRKERNSEC_CONFIG_AUTO
52562 + help
52563 + If you say Y here, /tmp race exploits will be prevented, since users
52564 + will no longer be able to follow symlinks owned by other users in
52565 + world-writable +t directories (e.g. /tmp), unless the owner of the
52566 + symlink is the owner of the directory. users will also not be
52567 + able to hardlink to files they do not own. If the sysctl option is
52568 + enabled, a sysctl option with name "linking_restrictions" is created.
52569 +
52570 +config GRKERNSEC_SYMLINKOWN
52571 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52572 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52573 + help
52574 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52575 + that prevents it from being used as a security feature. As Apache
52576 + verifies the symlink by performing a stat() against the target of
52577 + the symlink before it is followed, an attacker can setup a symlink
52578 + to point to a same-owned file, then replace the symlink with one
52579 + that targets another user's file just after Apache "validates" the
52580 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52581 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52582 + will be in place for the group you specify. If the sysctl option
52583 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52584 + created.
52585 +
52586 +config GRKERNSEC_SYMLINKOWN_GID
52587 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52588 + depends on GRKERNSEC_SYMLINKOWN
52589 + default 1006
52590 + help
52591 + Setting this GID determines what group kernel-enforced
52592 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52593 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52594 +
52595 +config GRKERNSEC_FIFO
52596 + bool "FIFO restrictions"
52597 + default y if GRKERNSEC_CONFIG_AUTO
52598 + help
52599 + If you say Y here, users will not be able to write to FIFOs they don't
52600 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52601 + the FIFO is the same owner of the directory it's held in. If the sysctl
52602 + option is enabled, a sysctl option with name "fifo_restrictions" is
52603 + created.
52604 +
52605 +config GRKERNSEC_SYSFS_RESTRICT
52606 + bool "Sysfs/debugfs restriction"
52607 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52608 + depends on SYSFS
52609 + help
52610 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52611 + any filesystem normally mounted under it (e.g. debugfs) will be
52612 + mostly accessible only by root. These filesystems generally provide access
52613 + to hardware and debug information that isn't appropriate for unprivileged
52614 + users of the system. Sysfs and debugfs have also become a large source
52615 + of new vulnerabilities, ranging from infoleaks to local compromise.
52616 + There has been very little oversight with an eye toward security involved
52617 + in adding new exporters of information to these filesystems, so their
52618 + use is discouraged.
52619 + For reasons of compatibility, a few directories have been whitelisted
52620 + for access by non-root users:
52621 + /sys/fs/selinux
52622 + /sys/fs/fuse
52623 + /sys/devices/system/cpu
52624 +
52625 +config GRKERNSEC_ROFS
52626 + bool "Runtime read-only mount protection"
52627 + help
52628 + If you say Y here, a sysctl option with name "romount_protect" will
52629 + be created. By setting this option to 1 at runtime, filesystems
52630 + will be protected in the following ways:
52631 + * No new writable mounts will be allowed
52632 + * Existing read-only mounts won't be able to be remounted read/write
52633 + * Write operations will be denied on all block devices
52634 + This option acts independently of grsec_lock: once it is set to 1,
52635 + it cannot be turned off. Therefore, please be mindful of the resulting
52636 + behavior if this option is enabled in an init script on a read-only
52637 + filesystem. This feature is mainly intended for secure embedded systems.
52638 +
52639 +config GRKERNSEC_DEVICE_SIDECHANNEL
52640 + bool "Eliminate stat/notify-based device sidechannels"
52641 + default y if GRKERNSEC_CONFIG_AUTO
52642 + help
52643 + If you say Y here, timing analyses on block or character
52644 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52645 + will be thwarted for unprivileged users. If a process without
52646 + CAP_MKNOD stats such a device, the last access and last modify times
52647 + will match the device's create time. No access or modify events
52648 + will be triggered through inotify/dnotify/fanotify for such devices.
52649 + This feature will prevent attacks that may at a minimum
52650 + allow an attacker to determine the administrator's password length.
52651 +
52652 +config GRKERNSEC_CHROOT
52653 + bool "Chroot jail restrictions"
52654 + default y if GRKERNSEC_CONFIG_AUTO
52655 + help
52656 + If you say Y here, you will be able to choose several options that will
52657 + make breaking out of a chrooted jail much more difficult. If you
52658 + encounter no software incompatibilities with the following options, it
52659 + is recommended that you enable each one.
52660 +
52661 +config GRKERNSEC_CHROOT_MOUNT
52662 + bool "Deny mounts"
52663 + default y if GRKERNSEC_CONFIG_AUTO
52664 + depends on GRKERNSEC_CHROOT
52665 + help
52666 + If you say Y here, processes inside a chroot will not be able to
52667 + mount or remount filesystems. If the sysctl option is enabled, a
52668 + sysctl option with name "chroot_deny_mount" is created.
52669 +
52670 +config GRKERNSEC_CHROOT_DOUBLE
52671 + bool "Deny double-chroots"
52672 + default y if GRKERNSEC_CONFIG_AUTO
52673 + depends on GRKERNSEC_CHROOT
52674 + help
52675 + If you say Y here, processes inside a chroot will not be able to chroot
52676 + again outside the chroot. This is a widely used method of breaking
52677 + out of a chroot jail and should not be allowed. If the sysctl
52678 + option is enabled, a sysctl option with name
52679 + "chroot_deny_chroot" is created.
52680 +
52681 +config GRKERNSEC_CHROOT_PIVOT
52682 + bool "Deny pivot_root in chroot"
52683 + default y if GRKERNSEC_CONFIG_AUTO
52684 + depends on GRKERNSEC_CHROOT
52685 + help
52686 + If you say Y here, processes inside a chroot will not be able to use
52687 + a function called pivot_root() that was introduced in Linux 2.3.41. It
52688 + works similar to chroot in that it changes the root filesystem. This
52689 + function could be misused in a chrooted process to attempt to break out
52690 + of the chroot, and therefore should not be allowed. If the sysctl
52691 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
52692 + created.
52693 +
52694 +config GRKERNSEC_CHROOT_CHDIR
52695 + bool "Enforce chdir(\"/\") on all chroots"
52696 + default y if GRKERNSEC_CONFIG_AUTO
52697 + depends on GRKERNSEC_CHROOT
52698 + help
52699 + If you say Y here, the current working directory of all newly-chrooted
52700 + applications will be set to the the root directory of the chroot.
52701 + The man page on chroot(2) states:
52702 + Note that this call does not change the current working
52703 + directory, so that `.' can be outside the tree rooted at
52704 + `/'. In particular, the super-user can escape from a
52705 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52706 +
52707 + It is recommended that you say Y here, since it's not known to break
52708 + any software. If the sysctl option is enabled, a sysctl option with
52709 + name "chroot_enforce_chdir" is created.
52710 +
52711 +config GRKERNSEC_CHROOT_CHMOD
52712 + bool "Deny (f)chmod +s"
52713 + default y if GRKERNSEC_CONFIG_AUTO
52714 + depends on GRKERNSEC_CHROOT
52715 + help
52716 + If you say Y here, processes inside a chroot will not be able to chmod
52717 + or fchmod files to make them have suid or sgid bits. This protects
52718 + against another published method of breaking a chroot. If the sysctl
52719 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
52720 + created.
52721 +
52722 +config GRKERNSEC_CHROOT_FCHDIR
52723 + bool "Deny fchdir out of chroot"
52724 + default y if GRKERNSEC_CONFIG_AUTO
52725 + depends on GRKERNSEC_CHROOT
52726 + help
52727 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
52728 + to a file descriptor of the chrooting process that points to a directory
52729 + outside the filesystem will be stopped. If the sysctl option
52730 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52731 +
52732 +config GRKERNSEC_CHROOT_MKNOD
52733 + bool "Deny mknod"
52734 + default y if GRKERNSEC_CONFIG_AUTO
52735 + depends on GRKERNSEC_CHROOT
52736 + help
52737 + If you say Y here, processes inside a chroot will not be allowed to
52738 + mknod. The problem with using mknod inside a chroot is that it
52739 + would allow an attacker to create a device entry that is the same
52740 + as one on the physical root of your system, which could range from
52741 + anything from the console device to a device for your harddrive (which
52742 + they could then use to wipe the drive or steal data). It is recommended
52743 + that you say Y here, unless you run into software incompatibilities.
52744 + If the sysctl option is enabled, a sysctl option with name
52745 + "chroot_deny_mknod" is created.
52746 +
52747 +config GRKERNSEC_CHROOT_SHMAT
52748 + bool "Deny shmat() out of chroot"
52749 + default y if GRKERNSEC_CONFIG_AUTO
52750 + depends on GRKERNSEC_CHROOT
52751 + help
52752 + If you say Y here, processes inside a chroot will not be able to attach
52753 + to shared memory segments that were created outside of the chroot jail.
52754 + It is recommended that you say Y here. If the sysctl option is enabled,
52755 + a sysctl option with name "chroot_deny_shmat" is created.
52756 +
52757 +config GRKERNSEC_CHROOT_UNIX
52758 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
52759 + default y if GRKERNSEC_CONFIG_AUTO
52760 + depends on GRKERNSEC_CHROOT
52761 + help
52762 + If you say Y here, processes inside a chroot will not be able to
52763 + connect to abstract (meaning not belonging to a filesystem) Unix
52764 + domain sockets that were bound outside of a chroot. It is recommended
52765 + that you say Y here. If the sysctl option is enabled, a sysctl option
52766 + with name "chroot_deny_unix" is created.
52767 +
52768 +config GRKERNSEC_CHROOT_FINDTASK
52769 + bool "Protect outside processes"
52770 + default y if GRKERNSEC_CONFIG_AUTO
52771 + depends on GRKERNSEC_CHROOT
52772 + help
52773 + If you say Y here, processes inside a chroot will not be able to
52774 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52775 + getsid, or view any process outside of the chroot. If the sysctl
52776 + option is enabled, a sysctl option with name "chroot_findtask" is
52777 + created.
52778 +
52779 +config GRKERNSEC_CHROOT_NICE
52780 + bool "Restrict priority changes"
52781 + default y if GRKERNSEC_CONFIG_AUTO
52782 + depends on GRKERNSEC_CHROOT
52783 + help
52784 + If you say Y here, processes inside a chroot will not be able to raise
52785 + the priority of processes in the chroot, or alter the priority of
52786 + processes outside the chroot. This provides more security than simply
52787 + removing CAP_SYS_NICE from the process' capability set. If the
52788 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52789 + is created.
52790 +
52791 +config GRKERNSEC_CHROOT_SYSCTL
52792 + bool "Deny sysctl writes"
52793 + default y if GRKERNSEC_CONFIG_AUTO
52794 + depends on GRKERNSEC_CHROOT
52795 + help
52796 + If you say Y here, an attacker in a chroot will not be able to
52797 + write to sysctl entries, either by sysctl(2) or through a /proc
52798 + interface. It is strongly recommended that you say Y here. If the
52799 + sysctl option is enabled, a sysctl option with name
52800 + "chroot_deny_sysctl" is created.
52801 +
52802 +config GRKERNSEC_CHROOT_CAPS
52803 + bool "Capability restrictions"
52804 + default y if GRKERNSEC_CONFIG_AUTO
52805 + depends on GRKERNSEC_CHROOT
52806 + help
52807 + If you say Y here, the capabilities on all processes within a
52808 + chroot jail will be lowered to stop module insertion, raw i/o,
52809 + system and net admin tasks, rebooting the system, modifying immutable
52810 + files, modifying IPC owned by another, and changing the system time.
52811 + This is left an option because it can break some apps. Disable this
52812 + if your chrooted apps are having problems performing those kinds of
52813 + tasks. If the sysctl option is enabled, a sysctl option with
52814 + name "chroot_caps" is created.
52815 +
52816 +endmenu
52817 +menu "Kernel Auditing"
52818 +depends on GRKERNSEC
52819 +
52820 +config GRKERNSEC_AUDIT_GROUP
52821 + bool "Single group for auditing"
52822 + help
52823 + If you say Y here, the exec and chdir logging features will only operate
52824 + on a group you specify. This option is recommended if you only want to
52825 + watch certain users instead of having a large amount of logs from the
52826 + entire system. If the sysctl option is enabled, a sysctl option with
52827 + name "audit_group" is created.
52828 +
52829 +config GRKERNSEC_AUDIT_GID
52830 + int "GID for auditing"
52831 + depends on GRKERNSEC_AUDIT_GROUP
52832 + default 1007
52833 +
52834 +config GRKERNSEC_EXECLOG
52835 + bool "Exec logging"
52836 + help
52837 + If you say Y here, all execve() calls will be logged (since the
52838 + other exec*() calls are frontends to execve(), all execution
52839 + will be logged). Useful for shell-servers that like to keep track
52840 + of their users. If the sysctl option is enabled, a sysctl option with
52841 + name "exec_logging" is created.
52842 + WARNING: This option when enabled will produce a LOT of logs, especially
52843 + on an active system.
52844 +
52845 +config GRKERNSEC_RESLOG
52846 + bool "Resource logging"
52847 + default y if GRKERNSEC_CONFIG_AUTO
52848 + help
52849 + If you say Y here, all attempts to overstep resource limits will
52850 + be logged with the resource name, the requested size, and the current
52851 + limit. It is highly recommended that you say Y here. If the sysctl
52852 + option is enabled, a sysctl option with name "resource_logging" is
52853 + created. If the RBAC system is enabled, the sysctl value is ignored.
52854 +
52855 +config GRKERNSEC_CHROOT_EXECLOG
52856 + bool "Log execs within chroot"
52857 + help
52858 + If you say Y here, all executions inside a chroot jail will be logged
52859 + to syslog. This can cause a large amount of logs if certain
52860 + applications (eg. djb's daemontools) are installed on the system, and
52861 + is therefore left as an option. If the sysctl option is enabled, a
52862 + sysctl option with name "chroot_execlog" is created.
52863 +
52864 +config GRKERNSEC_AUDIT_PTRACE
52865 + bool "Ptrace logging"
52866 + help
52867 + If you say Y here, all attempts to attach to a process via ptrace
52868 + will be logged. If the sysctl option is enabled, a sysctl option
52869 + with name "audit_ptrace" is created.
52870 +
52871 +config GRKERNSEC_AUDIT_CHDIR
52872 + bool "Chdir logging"
52873 + help
52874 + If you say Y here, all chdir() calls will be logged. If the sysctl
52875 + option is enabled, a sysctl option with name "audit_chdir" is created.
52876 +
52877 +config GRKERNSEC_AUDIT_MOUNT
52878 + bool "(Un)Mount logging"
52879 + help
52880 + If you say Y here, all mounts and unmounts will be logged. If the
52881 + sysctl option is enabled, a sysctl option with name "audit_mount" is
52882 + created.
52883 +
52884 +config GRKERNSEC_SIGNAL
52885 + bool "Signal logging"
52886 + default y if GRKERNSEC_CONFIG_AUTO
52887 + help
52888 + If you say Y here, certain important signals will be logged, such as
52889 + SIGSEGV, which will as a result inform you of when a error in a program
52890 + occurred, which in some cases could mean a possible exploit attempt.
52891 + If the sysctl option is enabled, a sysctl option with name
52892 + "signal_logging" is created.
52893 +
52894 +config GRKERNSEC_FORKFAIL
52895 + bool "Fork failure logging"
52896 + help
52897 + If you say Y here, all failed fork() attempts will be logged.
52898 + This could suggest a fork bomb, or someone attempting to overstep
52899 + their process limit. If the sysctl option is enabled, a sysctl option
52900 + with name "forkfail_logging" is created.
52901 +
52902 +config GRKERNSEC_TIME
52903 + bool "Time change logging"
52904 + default y if GRKERNSEC_CONFIG_AUTO
52905 + help
52906 + If you say Y here, any changes of the system clock will be logged.
52907 + If the sysctl option is enabled, a sysctl option with name
52908 + "timechange_logging" is created.
52909 +
52910 +config GRKERNSEC_PROC_IPADDR
52911 + bool "/proc/<pid>/ipaddr support"
52912 + default y if GRKERNSEC_CONFIG_AUTO
52913 + help
52914 + If you say Y here, a new entry will be added to each /proc/<pid>
52915 + directory that contains the IP address of the person using the task.
52916 + The IP is carried across local TCP and AF_UNIX stream sockets.
52917 + This information can be useful for IDS/IPSes to perform remote response
52918 + to a local attack. The entry is readable by only the owner of the
52919 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
52920 + the RBAC system), and thus does not create privacy concerns.
52921 +
52922 +config GRKERNSEC_RWXMAP_LOG
52923 + bool 'Denied RWX mmap/mprotect logging'
52924 + default y if GRKERNSEC_CONFIG_AUTO
52925 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
52926 + help
52927 + If you say Y here, calls to mmap() and mprotect() with explicit
52928 + usage of PROT_WRITE and PROT_EXEC together will be logged when
52929 + denied by the PAX_MPROTECT feature. If the sysctl option is
52930 + enabled, a sysctl option with name "rwxmap_logging" is created.
52931 +
52932 +config GRKERNSEC_AUDIT_TEXTREL
52933 + bool 'ELF text relocations logging (READ HELP)'
52934 + depends on PAX_MPROTECT
52935 + help
52936 + If you say Y here, text relocations will be logged with the filename
52937 + of the offending library or binary. The purpose of the feature is
52938 + to help Linux distribution developers get rid of libraries and
52939 + binaries that need text relocations which hinder the future progress
52940 + of PaX. Only Linux distribution developers should say Y here, and
52941 + never on a production machine, as this option creates an information
52942 + leak that could aid an attacker in defeating the randomization of
52943 + a single memory region. If the sysctl option is enabled, a sysctl
52944 + option with name "audit_textrel" is created.
52945 +
52946 +endmenu
52947 +
52948 +menu "Executable Protections"
52949 +depends on GRKERNSEC
52950 +
52951 +config GRKERNSEC_DMESG
52952 + bool "Dmesg(8) restriction"
52953 + default y if GRKERNSEC_CONFIG_AUTO
52954 + help
52955 + If you say Y here, non-root users will not be able to use dmesg(8)
52956 + to view the contents of the kernel's circular log buffer.
52957 + The kernel's log buffer often contains kernel addresses and other
52958 + identifying information useful to an attacker in fingerprinting a
52959 + system for a targeted exploit.
52960 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
52961 + created.
52962 +
52963 +config GRKERNSEC_HARDEN_PTRACE
52964 + bool "Deter ptrace-based process snooping"
52965 + default y if GRKERNSEC_CONFIG_AUTO
52966 + help
52967 + If you say Y here, TTY sniffers and other malicious monitoring
52968 + programs implemented through ptrace will be defeated. If you
52969 + have been using the RBAC system, this option has already been
52970 + enabled for several years for all users, with the ability to make
52971 + fine-grained exceptions.
52972 +
52973 + This option only affects the ability of non-root users to ptrace
52974 + processes that are not a descendent of the ptracing process.
52975 + This means that strace ./binary and gdb ./binary will still work,
52976 + but attaching to arbitrary processes will not. If the sysctl
52977 + option is enabled, a sysctl option with name "harden_ptrace" is
52978 + created.
52979 +
52980 +config GRKERNSEC_PTRACE_READEXEC
52981 + bool "Require read access to ptrace sensitive binaries"
52982 + default y if GRKERNSEC_CONFIG_AUTO
52983 + help
52984 + If you say Y here, unprivileged users will not be able to ptrace unreadable
52985 + binaries. This option is useful in environments that
52986 + remove the read bits (e.g. file mode 4711) from suid binaries to
52987 + prevent infoleaking of their contents. This option adds
52988 + consistency to the use of that file mode, as the binary could normally
52989 + be read out when run without privileges while ptracing.
52990 +
52991 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
52992 + is created.
52993 +
52994 +config GRKERNSEC_SETXID
52995 + bool "Enforce consistent multithreaded privileges"
52996 + default y if GRKERNSEC_CONFIG_AUTO
52997 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
52998 + help
52999 + If you say Y here, a change from a root uid to a non-root uid
53000 + in a multithreaded application will cause the resulting uids,
53001 + gids, supplementary groups, and capabilities in that thread
53002 + to be propagated to the other threads of the process. In most
53003 + cases this is unnecessary, as glibc will emulate this behavior
53004 + on behalf of the application. Other libcs do not act in the
53005 + same way, allowing the other threads of the process to continue
53006 + running with root privileges. If the sysctl option is enabled,
53007 + a sysctl option with name "consistent_setxid" is created.
53008 +
53009 +config GRKERNSEC_TPE
53010 + bool "Trusted Path Execution (TPE)"
53011 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53012 + help
53013 + If you say Y here, you will be able to choose a gid to add to the
53014 + supplementary groups of users you want to mark as "untrusted."
53015 + These users will not be able to execute any files that are not in
53016 + root-owned directories writable only by root. If the sysctl option
53017 + is enabled, a sysctl option with name "tpe" is created.
53018 +
53019 +config GRKERNSEC_TPE_ALL
53020 + bool "Partially restrict all non-root users"
53021 + depends on GRKERNSEC_TPE
53022 + help
53023 + If you say Y here, all non-root users will be covered under
53024 + a weaker TPE restriction. This is separate from, and in addition to,
53025 + the main TPE options that you have selected elsewhere. Thus, if a
53026 + "trusted" GID is chosen, this restriction applies to even that GID.
53027 + Under this restriction, all non-root users will only be allowed to
53028 + execute files in directories they own that are not group or
53029 + world-writable, or in directories owned by root and writable only by
53030 + root. If the sysctl option is enabled, a sysctl option with name
53031 + "tpe_restrict_all" is created.
53032 +
53033 +config GRKERNSEC_TPE_INVERT
53034 + bool "Invert GID option"
53035 + depends on GRKERNSEC_TPE
53036 + help
53037 + If you say Y here, the group you specify in the TPE configuration will
53038 + decide what group TPE restrictions will be *disabled* for. This
53039 + option is useful if you want TPE restrictions to be applied to most
53040 + users on the system. If the sysctl option is enabled, a sysctl option
53041 + with name "tpe_invert" is created. Unlike other sysctl options, this
53042 + entry will default to on for backward-compatibility.
53043 +
53044 +config GRKERNSEC_TPE_GID
53045 + int
53046 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53047 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53048 +
53049 +config GRKERNSEC_TPE_UNTRUSTED_GID
53050 + int "GID for TPE-untrusted users"
53051 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53052 + default 1005
53053 + help
53054 + Setting this GID determines what group TPE restrictions will be
53055 + *enabled* for. If the sysctl option is enabled, a sysctl option
53056 + with name "tpe_gid" is created.
53057 +
53058 +config GRKERNSEC_TPE_TRUSTED_GID
53059 + int "GID for TPE-trusted users"
53060 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53061 + default 1005
53062 + help
53063 + Setting this GID determines what group TPE restrictions will be
53064 + *disabled* for. If the sysctl option is enabled, a sysctl option
53065 + with name "tpe_gid" is created.
53066 +
53067 +endmenu
53068 +menu "Network Protections"
53069 +depends on GRKERNSEC
53070 +
53071 +config GRKERNSEC_RANDNET
53072 + bool "Larger entropy pools"
53073 + default y if GRKERNSEC_CONFIG_AUTO
53074 + help
53075 + If you say Y here, the entropy pools used for many features of Linux
53076 + and grsecurity will be doubled in size. Since several grsecurity
53077 + features use additional randomness, it is recommended that you say Y
53078 + here. Saying Y here has a similar effect as modifying
53079 + /proc/sys/kernel/random/poolsize.
53080 +
53081 +config GRKERNSEC_BLACKHOLE
53082 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53083 + default y if GRKERNSEC_CONFIG_AUTO
53084 + depends on NET
53085 + help
53086 + If you say Y here, neither TCP resets nor ICMP
53087 + destination-unreachable packets will be sent in response to packets
53088 + sent to ports for which no associated listening process exists.
53089 + This feature supports both IPV4 and IPV6 and exempts the
53090 + loopback interface from blackholing. Enabling this feature
53091 + makes a host more resilient to DoS attacks and reduces network
53092 + visibility against scanners.
53093 +
53094 + The blackhole feature as-implemented is equivalent to the FreeBSD
53095 + blackhole feature, as it prevents RST responses to all packets, not
53096 + just SYNs. Under most application behavior this causes no
53097 + problems, but applications (like haproxy) may not close certain
53098 + connections in a way that cleanly terminates them on the remote
53099 + end, leaving the remote host in LAST_ACK state. Because of this
53100 + side-effect and to prevent intentional LAST_ACK DoSes, this
53101 + feature also adds automatic mitigation against such attacks.
53102 + The mitigation drastically reduces the amount of time a socket
53103 + can spend in LAST_ACK state. If you're using haproxy and not
53104 + all servers it connects to have this option enabled, consider
53105 + disabling this feature on the haproxy host.
53106 +
53107 + If the sysctl option is enabled, two sysctl options with names
53108 + "ip_blackhole" and "lastack_retries" will be created.
53109 + While "ip_blackhole" takes the standard zero/non-zero on/off
53110 + toggle, "lastack_retries" uses the same kinds of values as
53111 + "tcp_retries1" and "tcp_retries2". The default value of 4
53112 + prevents a socket from lasting more than 45 seconds in LAST_ACK
53113 + state.
53114 +
53115 +config GRKERNSEC_NO_SIMULT_CONNECT
53116 + bool "Disable TCP Simultaneous Connect"
53117 + default y if GRKERNSEC_CONFIG_AUTO
53118 + depends on NET
53119 + help
53120 + If you say Y here, a feature by Willy Tarreau will be enabled that
53121 + removes a weakness in Linux's strict implementation of TCP that
53122 + allows two clients to connect to each other without either entering
53123 + a listening state. The weakness allows an attacker to easily prevent
53124 + a client from connecting to a known server provided the source port
53125 + for the connection is guessed correctly.
53126 +
53127 + As the weakness could be used to prevent an antivirus or IPS from
53128 + fetching updates, or prevent an SSL gateway from fetching a CRL,
53129 + it should be eliminated by enabling this option. Though Linux is
53130 + one of few operating systems supporting simultaneous connect, it
53131 + has no legitimate use in practice and is rarely supported by firewalls.
53132 +
53133 +config GRKERNSEC_SOCKET
53134 + bool "Socket restrictions"
53135 + depends on NET
53136 + help
53137 + If you say Y here, you will be able to choose from several options.
53138 + If you assign a GID on your system and add it to the supplementary
53139 + groups of users you want to restrict socket access to, this patch
53140 + will perform up to three things, based on the option(s) you choose.
53141 +
53142 +config GRKERNSEC_SOCKET_ALL
53143 + bool "Deny any sockets to group"
53144 + depends on GRKERNSEC_SOCKET
53145 + help
53146 + If you say Y here, you will be able to choose a GID of whose users will
53147 + be unable to connect to other hosts from your machine or run server
53148 + applications from your machine. If the sysctl option is enabled, a
53149 + sysctl option with name "socket_all" is created.
53150 +
53151 +config GRKERNSEC_SOCKET_ALL_GID
53152 + int "GID to deny all sockets for"
53153 + depends on GRKERNSEC_SOCKET_ALL
53154 + default 1004
53155 + help
53156 + Here you can choose the GID to disable socket access for. Remember to
53157 + add the users you want socket access disabled for to the GID
53158 + specified here. If the sysctl option is enabled, a sysctl option
53159 + with name "socket_all_gid" is created.
53160 +
53161 +config GRKERNSEC_SOCKET_CLIENT
53162 + bool "Deny client sockets to group"
53163 + depends on GRKERNSEC_SOCKET
53164 + help
53165 + If you say Y here, you will be able to choose a GID of whose users will
53166 + be unable to connect to other hosts from your machine, but will be
53167 + able to run servers. If this option is enabled, all users in the group
53168 + you specify will have to use passive mode when initiating ftp transfers
53169 + from the shell on your machine. If the sysctl option is enabled, a
53170 + sysctl option with name "socket_client" is created.
53171 +
53172 +config GRKERNSEC_SOCKET_CLIENT_GID
53173 + int "GID to deny client sockets for"
53174 + depends on GRKERNSEC_SOCKET_CLIENT
53175 + default 1003
53176 + help
53177 + Here you can choose the GID to disable client socket access for.
53178 + Remember to add the users you want client socket access disabled for to
53179 + the GID specified here. If the sysctl option is enabled, a sysctl
53180 + option with name "socket_client_gid" is created.
53181 +
53182 +config GRKERNSEC_SOCKET_SERVER
53183 + bool "Deny server sockets to group"
53184 + depends on GRKERNSEC_SOCKET
53185 + help
53186 + If you say Y here, you will be able to choose a GID of whose users will
53187 + be unable to run server applications from your machine. If the sysctl
53188 + option is enabled, a sysctl option with name "socket_server" is created.
53189 +
53190 +config GRKERNSEC_SOCKET_SERVER_GID
53191 + int "GID to deny server sockets for"
53192 + depends on GRKERNSEC_SOCKET_SERVER
53193 + default 1002
53194 + help
53195 + Here you can choose the GID to disable server socket access for.
53196 + Remember to add the users you want server socket access disabled for to
53197 + the GID specified here. If the sysctl option is enabled, a sysctl
53198 + option with name "socket_server_gid" is created.
53199 +
53200 +endmenu
53201 +menu "Sysctl Support"
53202 +depends on GRKERNSEC && SYSCTL
53203 +
53204 +config GRKERNSEC_SYSCTL
53205 + bool "Sysctl support"
53206 + default y if GRKERNSEC_CONFIG_AUTO
53207 + help
53208 + If you say Y here, you will be able to change the options that
53209 + grsecurity runs with at bootup, without having to recompile your
53210 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53211 + to enable (1) or disable (0) various features. All the sysctl entries
53212 + are mutable until the "grsec_lock" entry is set to a non-zero value.
53213 + All features enabled in the kernel configuration are disabled at boot
53214 + if you do not say Y to the "Turn on features by default" option.
53215 + All options should be set at startup, and the grsec_lock entry should
53216 + be set to a non-zero value after all the options are set.
53217 + *THIS IS EXTREMELY IMPORTANT*
53218 +
53219 +config GRKERNSEC_SYSCTL_DISTRO
53220 + bool "Extra sysctl support for distro makers (READ HELP)"
53221 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53222 + help
53223 + If you say Y here, additional sysctl options will be created
53224 + for features that affect processes running as root. Therefore,
53225 + it is critical when using this option that the grsec_lock entry be
53226 + enabled after boot. Only distros with prebuilt kernel packages
53227 + with this option enabled that can ensure grsec_lock is enabled
53228 + after boot should use this option.
53229 + *Failure to set grsec_lock after boot makes all grsec features
53230 + this option covers useless*
53231 +
53232 + Currently this option creates the following sysctl entries:
53233 + "Disable Privileged I/O": "disable_priv_io"
53234 +
53235 +config GRKERNSEC_SYSCTL_ON
53236 + bool "Turn on features by default"
53237 + default y if GRKERNSEC_CONFIG_AUTO
53238 + depends on GRKERNSEC_SYSCTL
53239 + help
53240 + If you say Y here, instead of having all features enabled in the
53241 + kernel configuration disabled at boot time, the features will be
53242 + enabled at boot time. It is recommended you say Y here unless
53243 + there is some reason you would want all sysctl-tunable features to
53244 + be disabled by default. As mentioned elsewhere, it is important
53245 + to enable the grsec_lock entry once you have finished modifying
53246 + the sysctl entries.
53247 +
53248 +endmenu
53249 +menu "Logging Options"
53250 +depends on GRKERNSEC
53251 +
53252 +config GRKERNSEC_FLOODTIME
53253 + int "Seconds in between log messages (minimum)"
53254 + default 10
53255 + help
53256 + This option allows you to enforce the number of seconds between
53257 + grsecurity log messages. The default should be suitable for most
53258 + people, however, if you choose to change it, choose a value small enough
53259 + to allow informative logs to be produced, but large enough to
53260 + prevent flooding.
53261 +
53262 +config GRKERNSEC_FLOODBURST
53263 + int "Number of messages in a burst (maximum)"
53264 + default 6
53265 + help
53266 + This option allows you to choose the maximum number of messages allowed
53267 + within the flood time interval you chose in a separate option. The
53268 + default should be suitable for most people, however if you find that
53269 + many of your logs are being interpreted as flooding, you may want to
53270 + raise this value.
53271 +
53272 +endmenu
53273 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53274 new file mode 100644
53275 index 0000000..1b9afa9
53276 --- /dev/null
53277 +++ b/grsecurity/Makefile
53278 @@ -0,0 +1,38 @@
53279 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53280 +# during 2001-2009 it has been completely redesigned by Brad Spengler
53281 +# into an RBAC system
53282 +#
53283 +# All code in this directory and various hooks inserted throughout the kernel
53284 +# are copyright Brad Spengler - Open Source Security, Inc., and released
53285 +# under the GPL v2 or higher
53286 +
53287 +KBUILD_CFLAGS += -Werror
53288 +
53289 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53290 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
53291 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53292 +
53293 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53294 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53295 + gracl_learn.o grsec_log.o
53296 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53297 +
53298 +ifdef CONFIG_NET
53299 +obj-y += grsec_sock.o
53300 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53301 +endif
53302 +
53303 +ifndef CONFIG_GRKERNSEC
53304 +obj-y += grsec_disabled.o
53305 +endif
53306 +
53307 +ifdef CONFIG_GRKERNSEC_HIDESYM
53308 +extra-y := grsec_hidesym.o
53309 +$(obj)/grsec_hidesym.o:
53310 + @-chmod -f 500 /boot
53311 + @-chmod -f 500 /lib/modules
53312 + @-chmod -f 500 /lib64/modules
53313 + @-chmod -f 500 /lib32/modules
53314 + @-chmod -f 700 .
53315 + @echo ' grsec: protected kernel image paths'
53316 +endif
53317 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53318 new file mode 100644
53319 index 0000000..78353bd
53320 --- /dev/null
53321 +++ b/grsecurity/gracl.c
53322 @@ -0,0 +1,4039 @@
53323 +#include <linux/kernel.h>
53324 +#include <linux/module.h>
53325 +#include <linux/sched.h>
53326 +#include <linux/mm.h>
53327 +#include <linux/file.h>
53328 +#include <linux/fs.h>
53329 +#include <linux/namei.h>
53330 +#include <linux/mount.h>
53331 +#include <linux/tty.h>
53332 +#include <linux/proc_fs.h>
53333 +#include <linux/lglock.h>
53334 +#include <linux/slab.h>
53335 +#include <linux/vmalloc.h>
53336 +#include <linux/types.h>
53337 +#include <linux/sysctl.h>
53338 +#include <linux/netdevice.h>
53339 +#include <linux/ptrace.h>
53340 +#include <linux/gracl.h>
53341 +#include <linux/gralloc.h>
53342 +#include <linux/security.h>
53343 +#include <linux/grinternal.h>
53344 +#include <linux/pid_namespace.h>
53345 +#include <linux/stop_machine.h>
53346 +#include <linux/fdtable.h>
53347 +#include <linux/percpu.h>
53348 +#include <linux/lglock.h>
53349 +#include "../fs/mount.h"
53350 +
53351 +#include <asm/uaccess.h>
53352 +#include <asm/errno.h>
53353 +#include <asm/mman.h>
53354 +
53355 +extern struct lglock vfsmount_lock;
53356 +
53357 +static struct acl_role_db acl_role_set;
53358 +static struct name_db name_set;
53359 +static struct inodev_db inodev_set;
53360 +
53361 +/* for keeping track of userspace pointers used for subjects, so we
53362 + can share references in the kernel as well
53363 +*/
53364 +
53365 +static struct path real_root;
53366 +
53367 +static struct acl_subj_map_db subj_map_set;
53368 +
53369 +static struct acl_role_label *default_role;
53370 +
53371 +static struct acl_role_label *role_list;
53372 +
53373 +static u16 acl_sp_role_value;
53374 +
53375 +extern char *gr_shared_page[4];
53376 +static DEFINE_MUTEX(gr_dev_mutex);
53377 +DEFINE_RWLOCK(gr_inode_lock);
53378 +
53379 +struct gr_arg *gr_usermode;
53380 +
53381 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
53382 +
53383 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53384 +extern void gr_clear_learn_entries(void);
53385 +
53386 +#ifdef CONFIG_GRKERNSEC_RESLOG
53387 +extern void gr_log_resource(const struct task_struct *task,
53388 + const int res, const unsigned long wanted, const int gt);
53389 +#endif
53390 +
53391 +unsigned char *gr_system_salt;
53392 +unsigned char *gr_system_sum;
53393 +
53394 +static struct sprole_pw **acl_special_roles = NULL;
53395 +static __u16 num_sprole_pws = 0;
53396 +
53397 +static struct acl_role_label *kernel_role = NULL;
53398 +
53399 +static unsigned int gr_auth_attempts = 0;
53400 +static unsigned long gr_auth_expires = 0UL;
53401 +
53402 +#ifdef CONFIG_NET
53403 +extern struct vfsmount *sock_mnt;
53404 +#endif
53405 +
53406 +extern struct vfsmount *pipe_mnt;
53407 +extern struct vfsmount *shm_mnt;
53408 +#ifdef CONFIG_HUGETLBFS
53409 +extern struct vfsmount *hugetlbfs_vfsmount;
53410 +#endif
53411 +
53412 +static struct acl_object_label *fakefs_obj_rw;
53413 +static struct acl_object_label *fakefs_obj_rwx;
53414 +
53415 +extern int gr_init_uidset(void);
53416 +extern void gr_free_uidset(void);
53417 +extern void gr_remove_uid(uid_t uid);
53418 +extern int gr_find_uid(uid_t uid);
53419 +
53420 +__inline__ int
53421 +gr_acl_is_enabled(void)
53422 +{
53423 + return (gr_status & GR_READY);
53424 +}
53425 +
53426 +#ifdef CONFIG_BTRFS_FS
53427 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53428 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53429 +#endif
53430 +
53431 +static inline dev_t __get_dev(const struct dentry *dentry)
53432 +{
53433 +#ifdef CONFIG_BTRFS_FS
53434 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53435 + return get_btrfs_dev_from_inode(dentry->d_inode);
53436 + else
53437 +#endif
53438 + return dentry->d_inode->i_sb->s_dev;
53439 +}
53440 +
53441 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53442 +{
53443 + return __get_dev(dentry);
53444 +}
53445 +
53446 +static char gr_task_roletype_to_char(struct task_struct *task)
53447 +{
53448 + switch (task->role->roletype &
53449 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53450 + GR_ROLE_SPECIAL)) {
53451 + case GR_ROLE_DEFAULT:
53452 + return 'D';
53453 + case GR_ROLE_USER:
53454 + return 'U';
53455 + case GR_ROLE_GROUP:
53456 + return 'G';
53457 + case GR_ROLE_SPECIAL:
53458 + return 'S';
53459 + }
53460 +
53461 + return 'X';
53462 +}
53463 +
53464 +char gr_roletype_to_char(void)
53465 +{
53466 + return gr_task_roletype_to_char(current);
53467 +}
53468 +
53469 +__inline__ int
53470 +gr_acl_tpe_check(void)
53471 +{
53472 + if (unlikely(!(gr_status & GR_READY)))
53473 + return 0;
53474 + if (current->role->roletype & GR_ROLE_TPE)
53475 + return 1;
53476 + else
53477 + return 0;
53478 +}
53479 +
53480 +int
53481 +gr_handle_rawio(const struct inode *inode)
53482 +{
53483 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53484 + if (inode && S_ISBLK(inode->i_mode) &&
53485 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53486 + !capable(CAP_SYS_RAWIO))
53487 + return 1;
53488 +#endif
53489 + return 0;
53490 +}
53491 +
53492 +static int
53493 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53494 +{
53495 + if (likely(lena != lenb))
53496 + return 0;
53497 +
53498 + return !memcmp(a, b, lena);
53499 +}
53500 +
53501 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53502 +{
53503 + *buflen -= namelen;
53504 + if (*buflen < 0)
53505 + return -ENAMETOOLONG;
53506 + *buffer -= namelen;
53507 + memcpy(*buffer, str, namelen);
53508 + return 0;
53509 +}
53510 +
53511 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53512 +{
53513 + return prepend(buffer, buflen, name->name, name->len);
53514 +}
53515 +
53516 +static int prepend_path(const struct path *path, struct path *root,
53517 + char **buffer, int *buflen)
53518 +{
53519 + struct dentry *dentry = path->dentry;
53520 + struct vfsmount *vfsmnt = path->mnt;
53521 + struct mount *mnt = real_mount(vfsmnt);
53522 + bool slash = false;
53523 + int error = 0;
53524 +
53525 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53526 + struct dentry * parent;
53527 +
53528 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53529 + /* Global root? */
53530 + if (!mnt_has_parent(mnt)) {
53531 + goto out;
53532 + }
53533 + dentry = mnt->mnt_mountpoint;
53534 + mnt = mnt->mnt_parent;
53535 + vfsmnt = &mnt->mnt;
53536 + continue;
53537 + }
53538 + parent = dentry->d_parent;
53539 + prefetch(parent);
53540 + spin_lock(&dentry->d_lock);
53541 + error = prepend_name(buffer, buflen, &dentry->d_name);
53542 + spin_unlock(&dentry->d_lock);
53543 + if (!error)
53544 + error = prepend(buffer, buflen, "/", 1);
53545 + if (error)
53546 + break;
53547 +
53548 + slash = true;
53549 + dentry = parent;
53550 + }
53551 +
53552 +out:
53553 + if (!error && !slash)
53554 + error = prepend(buffer, buflen, "/", 1);
53555 +
53556 + return error;
53557 +}
53558 +
53559 +/* this must be called with vfsmount_lock and rename_lock held */
53560 +
53561 +static char *__our_d_path(const struct path *path, struct path *root,
53562 + char *buf, int buflen)
53563 +{
53564 + char *res = buf + buflen;
53565 + int error;
53566 +
53567 + prepend(&res, &buflen, "\0", 1);
53568 + error = prepend_path(path, root, &res, &buflen);
53569 + if (error)
53570 + return ERR_PTR(error);
53571 +
53572 + return res;
53573 +}
53574 +
53575 +static char *
53576 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53577 +{
53578 + char *retval;
53579 +
53580 + retval = __our_d_path(path, root, buf, buflen);
53581 + if (unlikely(IS_ERR(retval)))
53582 + retval = strcpy(buf, "<path too long>");
53583 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53584 + retval[1] = '\0';
53585 +
53586 + return retval;
53587 +}
53588 +
53589 +static char *
53590 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53591 + char *buf, int buflen)
53592 +{
53593 + struct path path;
53594 + char *res;
53595 +
53596 + path.dentry = (struct dentry *)dentry;
53597 + path.mnt = (struct vfsmount *)vfsmnt;
53598 +
53599 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53600 + by the RBAC system */
53601 + res = gen_full_path(&path, &real_root, buf, buflen);
53602 +
53603 + return res;
53604 +}
53605 +
53606 +static char *
53607 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53608 + char *buf, int buflen)
53609 +{
53610 + char *res;
53611 + struct path path;
53612 + struct path root;
53613 + struct task_struct *reaper = init_pid_ns.child_reaper;
53614 +
53615 + path.dentry = (struct dentry *)dentry;
53616 + path.mnt = (struct vfsmount *)vfsmnt;
53617 +
53618 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53619 + get_fs_root(reaper->fs, &root);
53620 +
53621 + write_seqlock(&rename_lock);
53622 + br_read_lock(&vfsmount_lock);
53623 + res = gen_full_path(&path, &root, buf, buflen);
53624 + br_read_unlock(&vfsmount_lock);
53625 + write_sequnlock(&rename_lock);
53626 +
53627 + path_put(&root);
53628 + return res;
53629 +}
53630 +
53631 +static char *
53632 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53633 +{
53634 + char *ret;
53635 + write_seqlock(&rename_lock);
53636 + br_read_lock(&vfsmount_lock);
53637 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53638 + PAGE_SIZE);
53639 + br_read_unlock(&vfsmount_lock);
53640 + write_sequnlock(&rename_lock);
53641 + return ret;
53642 +}
53643 +
53644 +static char *
53645 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53646 +{
53647 + char *ret;
53648 + char *buf;
53649 + int buflen;
53650 +
53651 + write_seqlock(&rename_lock);
53652 + br_read_lock(&vfsmount_lock);
53653 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53654 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53655 + buflen = (int)(ret - buf);
53656 + if (buflen >= 5)
53657 + prepend(&ret, &buflen, "/proc", 5);
53658 + else
53659 + ret = strcpy(buf, "<path too long>");
53660 + br_read_unlock(&vfsmount_lock);
53661 + write_sequnlock(&rename_lock);
53662 + return ret;
53663 +}
53664 +
53665 +char *
53666 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53667 +{
53668 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53669 + PAGE_SIZE);
53670 +}
53671 +
53672 +char *
53673 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53674 +{
53675 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53676 + PAGE_SIZE);
53677 +}
53678 +
53679 +char *
53680 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53681 +{
53682 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53683 + PAGE_SIZE);
53684 +}
53685 +
53686 +char *
53687 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53688 +{
53689 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53690 + PAGE_SIZE);
53691 +}
53692 +
53693 +char *
53694 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53695 +{
53696 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53697 + PAGE_SIZE);
53698 +}
53699 +
53700 +__inline__ __u32
53701 +to_gr_audit(const __u32 reqmode)
53702 +{
53703 + /* masks off auditable permission flags, then shifts them to create
53704 + auditing flags, and adds the special case of append auditing if
53705 + we're requesting write */
53706 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53707 +}
53708 +
53709 +struct acl_subject_label *
53710 +lookup_subject_map(const struct acl_subject_label *userp)
53711 +{
53712 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
53713 + struct subject_map *match;
53714 +
53715 + match = subj_map_set.s_hash[index];
53716 +
53717 + while (match && match->user != userp)
53718 + match = match->next;
53719 +
53720 + if (match != NULL)
53721 + return match->kernel;
53722 + else
53723 + return NULL;
53724 +}
53725 +
53726 +static void
53727 +insert_subj_map_entry(struct subject_map *subjmap)
53728 +{
53729 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53730 + struct subject_map **curr;
53731 +
53732 + subjmap->prev = NULL;
53733 +
53734 + curr = &subj_map_set.s_hash[index];
53735 + if (*curr != NULL)
53736 + (*curr)->prev = subjmap;
53737 +
53738 + subjmap->next = *curr;
53739 + *curr = subjmap;
53740 +
53741 + return;
53742 +}
53743 +
53744 +static struct acl_role_label *
53745 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53746 + const gid_t gid)
53747 +{
53748 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53749 + struct acl_role_label *match;
53750 + struct role_allowed_ip *ipp;
53751 + unsigned int x;
53752 + u32 curr_ip = task->signal->curr_ip;
53753 +
53754 + task->signal->saved_ip = curr_ip;
53755 +
53756 + match = acl_role_set.r_hash[index];
53757 +
53758 + while (match) {
53759 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53760 + for (x = 0; x < match->domain_child_num; x++) {
53761 + if (match->domain_children[x] == uid)
53762 + goto found;
53763 + }
53764 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
53765 + break;
53766 + match = match->next;
53767 + }
53768 +found:
53769 + if (match == NULL) {
53770 + try_group:
53771 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
53772 + match = acl_role_set.r_hash[index];
53773 +
53774 + while (match) {
53775 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
53776 + for (x = 0; x < match->domain_child_num; x++) {
53777 + if (match->domain_children[x] == gid)
53778 + goto found2;
53779 + }
53780 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
53781 + break;
53782 + match = match->next;
53783 + }
53784 +found2:
53785 + if (match == NULL)
53786 + match = default_role;
53787 + if (match->allowed_ips == NULL)
53788 + return match;
53789 + else {
53790 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53791 + if (likely
53792 + ((ntohl(curr_ip) & ipp->netmask) ==
53793 + (ntohl(ipp->addr) & ipp->netmask)))
53794 + return match;
53795 + }
53796 + match = default_role;
53797 + }
53798 + } else if (match->allowed_ips == NULL) {
53799 + return match;
53800 + } else {
53801 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53802 + if (likely
53803 + ((ntohl(curr_ip) & ipp->netmask) ==
53804 + (ntohl(ipp->addr) & ipp->netmask)))
53805 + return match;
53806 + }
53807 + goto try_group;
53808 + }
53809 +
53810 + return match;
53811 +}
53812 +
53813 +struct acl_subject_label *
53814 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
53815 + const struct acl_role_label *role)
53816 +{
53817 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53818 + struct acl_subject_label *match;
53819 +
53820 + match = role->subj_hash[index];
53821 +
53822 + while (match && (match->inode != ino || match->device != dev ||
53823 + (match->mode & GR_DELETED))) {
53824 + match = match->next;
53825 + }
53826 +
53827 + if (match && !(match->mode & GR_DELETED))
53828 + return match;
53829 + else
53830 + return NULL;
53831 +}
53832 +
53833 +struct acl_subject_label *
53834 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
53835 + const struct acl_role_label *role)
53836 +{
53837 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53838 + struct acl_subject_label *match;
53839 +
53840 + match = role->subj_hash[index];
53841 +
53842 + while (match && (match->inode != ino || match->device != dev ||
53843 + !(match->mode & GR_DELETED))) {
53844 + match = match->next;
53845 + }
53846 +
53847 + if (match && (match->mode & GR_DELETED))
53848 + return match;
53849 + else
53850 + return NULL;
53851 +}
53852 +
53853 +static struct acl_object_label *
53854 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
53855 + const struct acl_subject_label *subj)
53856 +{
53857 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53858 + struct acl_object_label *match;
53859 +
53860 + match = subj->obj_hash[index];
53861 +
53862 + while (match && (match->inode != ino || match->device != dev ||
53863 + (match->mode & GR_DELETED))) {
53864 + match = match->next;
53865 + }
53866 +
53867 + if (match && !(match->mode & GR_DELETED))
53868 + return match;
53869 + else
53870 + return NULL;
53871 +}
53872 +
53873 +static struct acl_object_label *
53874 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
53875 + const struct acl_subject_label *subj)
53876 +{
53877 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53878 + struct acl_object_label *match;
53879 +
53880 + match = subj->obj_hash[index];
53881 +
53882 + while (match && (match->inode != ino || match->device != dev ||
53883 + !(match->mode & GR_DELETED))) {
53884 + match = match->next;
53885 + }
53886 +
53887 + if (match && (match->mode & GR_DELETED))
53888 + return match;
53889 +
53890 + match = subj->obj_hash[index];
53891 +
53892 + while (match && (match->inode != ino || match->device != dev ||
53893 + (match->mode & GR_DELETED))) {
53894 + match = match->next;
53895 + }
53896 +
53897 + if (match && !(match->mode & GR_DELETED))
53898 + return match;
53899 + else
53900 + return NULL;
53901 +}
53902 +
53903 +static struct name_entry *
53904 +lookup_name_entry(const char *name)
53905 +{
53906 + unsigned int len = strlen(name);
53907 + unsigned int key = full_name_hash(name, len);
53908 + unsigned int index = key % name_set.n_size;
53909 + struct name_entry *match;
53910 +
53911 + match = name_set.n_hash[index];
53912 +
53913 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
53914 + match = match->next;
53915 +
53916 + return match;
53917 +}
53918 +
53919 +static struct name_entry *
53920 +lookup_name_entry_create(const char *name)
53921 +{
53922 + unsigned int len = strlen(name);
53923 + unsigned int key = full_name_hash(name, len);
53924 + unsigned int index = key % name_set.n_size;
53925 + struct name_entry *match;
53926 +
53927 + match = name_set.n_hash[index];
53928 +
53929 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53930 + !match->deleted))
53931 + match = match->next;
53932 +
53933 + if (match && match->deleted)
53934 + return match;
53935 +
53936 + match = name_set.n_hash[index];
53937 +
53938 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53939 + match->deleted))
53940 + match = match->next;
53941 +
53942 + if (match && !match->deleted)
53943 + return match;
53944 + else
53945 + return NULL;
53946 +}
53947 +
53948 +static struct inodev_entry *
53949 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
53950 +{
53951 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
53952 + struct inodev_entry *match;
53953 +
53954 + match = inodev_set.i_hash[index];
53955 +
53956 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
53957 + match = match->next;
53958 +
53959 + return match;
53960 +}
53961 +
53962 +static void
53963 +insert_inodev_entry(struct inodev_entry *entry)
53964 +{
53965 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
53966 + inodev_set.i_size);
53967 + struct inodev_entry **curr;
53968 +
53969 + entry->prev = NULL;
53970 +
53971 + curr = &inodev_set.i_hash[index];
53972 + if (*curr != NULL)
53973 + (*curr)->prev = entry;
53974 +
53975 + entry->next = *curr;
53976 + *curr = entry;
53977 +
53978 + return;
53979 +}
53980 +
53981 +static void
53982 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
53983 +{
53984 + unsigned int index =
53985 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
53986 + struct acl_role_label **curr;
53987 + struct acl_role_label *tmp, *tmp2;
53988 +
53989 + curr = &acl_role_set.r_hash[index];
53990 +
53991 + /* simple case, slot is empty, just set it to our role */
53992 + if (*curr == NULL) {
53993 + *curr = role;
53994 + } else {
53995 + /* example:
53996 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
53997 + 2 -> 3
53998 + */
53999 + /* first check to see if we can already be reached via this slot */
54000 + tmp = *curr;
54001 + while (tmp && tmp != role)
54002 + tmp = tmp->next;
54003 + if (tmp == role) {
54004 + /* we don't need to add ourselves to this slot's chain */
54005 + return;
54006 + }
54007 + /* we need to add ourselves to this chain, two cases */
54008 + if (role->next == NULL) {
54009 + /* simple case, append the current chain to our role */
54010 + role->next = *curr;
54011 + *curr = role;
54012 + } else {
54013 + /* 1 -> 2 -> 3 -> 4
54014 + 2 -> 3 -> 4
54015 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54016 + */
54017 + /* trickier case: walk our role's chain until we find
54018 + the role for the start of the current slot's chain */
54019 + tmp = role;
54020 + tmp2 = *curr;
54021 + while (tmp->next && tmp->next != tmp2)
54022 + tmp = tmp->next;
54023 + if (tmp->next == tmp2) {
54024 + /* from example above, we found 3, so just
54025 + replace this slot's chain with ours */
54026 + *curr = role;
54027 + } else {
54028 + /* we didn't find a subset of our role's chain
54029 + in the current slot's chain, so append their
54030 + chain to ours, and set us as the first role in
54031 + the slot's chain
54032 +
54033 + we could fold this case with the case above,
54034 + but making it explicit for clarity
54035 + */
54036 + tmp->next = tmp2;
54037 + *curr = role;
54038 + }
54039 + }
54040 + }
54041 +
54042 + return;
54043 +}
54044 +
54045 +static void
54046 +insert_acl_role_label(struct acl_role_label *role)
54047 +{
54048 + int i;
54049 +
54050 + if (role_list == NULL) {
54051 + role_list = role;
54052 + role->prev = NULL;
54053 + } else {
54054 + role->prev = role_list;
54055 + role_list = role;
54056 + }
54057 +
54058 + /* used for hash chains */
54059 + role->next = NULL;
54060 +
54061 + if (role->roletype & GR_ROLE_DOMAIN) {
54062 + for (i = 0; i < role->domain_child_num; i++)
54063 + __insert_acl_role_label(role, role->domain_children[i]);
54064 + } else
54065 + __insert_acl_role_label(role, role->uidgid);
54066 +}
54067 +
54068 +static int
54069 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54070 +{
54071 + struct name_entry **curr, *nentry;
54072 + struct inodev_entry *ientry;
54073 + unsigned int len = strlen(name);
54074 + unsigned int key = full_name_hash(name, len);
54075 + unsigned int index = key % name_set.n_size;
54076 +
54077 + curr = &name_set.n_hash[index];
54078 +
54079 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54080 + curr = &((*curr)->next);
54081 +
54082 + if (*curr != NULL)
54083 + return 1;
54084 +
54085 + nentry = acl_alloc(sizeof (struct name_entry));
54086 + if (nentry == NULL)
54087 + return 0;
54088 + ientry = acl_alloc(sizeof (struct inodev_entry));
54089 + if (ientry == NULL)
54090 + return 0;
54091 + ientry->nentry = nentry;
54092 +
54093 + nentry->key = key;
54094 + nentry->name = name;
54095 + nentry->inode = inode;
54096 + nentry->device = device;
54097 + nentry->len = len;
54098 + nentry->deleted = deleted;
54099 +
54100 + nentry->prev = NULL;
54101 + curr = &name_set.n_hash[index];
54102 + if (*curr != NULL)
54103 + (*curr)->prev = nentry;
54104 + nentry->next = *curr;
54105 + *curr = nentry;
54106 +
54107 + /* insert us into the table searchable by inode/dev */
54108 + insert_inodev_entry(ientry);
54109 +
54110 + return 1;
54111 +}
54112 +
54113 +static void
54114 +insert_acl_obj_label(struct acl_object_label *obj,
54115 + struct acl_subject_label *subj)
54116 +{
54117 + unsigned int index =
54118 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54119 + struct acl_object_label **curr;
54120 +
54121 +
54122 + obj->prev = NULL;
54123 +
54124 + curr = &subj->obj_hash[index];
54125 + if (*curr != NULL)
54126 + (*curr)->prev = obj;
54127 +
54128 + obj->next = *curr;
54129 + *curr = obj;
54130 +
54131 + return;
54132 +}
54133 +
54134 +static void
54135 +insert_acl_subj_label(struct acl_subject_label *obj,
54136 + struct acl_role_label *role)
54137 +{
54138 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54139 + struct acl_subject_label **curr;
54140 +
54141 + obj->prev = NULL;
54142 +
54143 + curr = &role->subj_hash[index];
54144 + if (*curr != NULL)
54145 + (*curr)->prev = obj;
54146 +
54147 + obj->next = *curr;
54148 + *curr = obj;
54149 +
54150 + return;
54151 +}
54152 +
54153 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54154 +
54155 +static void *
54156 +create_table(__u32 * len, int elementsize)
54157 +{
54158 + unsigned int table_sizes[] = {
54159 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54160 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54161 + 4194301, 8388593, 16777213, 33554393, 67108859
54162 + };
54163 + void *newtable = NULL;
54164 + unsigned int pwr = 0;
54165 +
54166 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54167 + table_sizes[pwr] <= *len)
54168 + pwr++;
54169 +
54170 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54171 + return newtable;
54172 +
54173 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54174 + newtable =
54175 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54176 + else
54177 + newtable = vmalloc(table_sizes[pwr] * elementsize);
54178 +
54179 + *len = table_sizes[pwr];
54180 +
54181 + return newtable;
54182 +}
54183 +
54184 +static int
54185 +init_variables(const struct gr_arg *arg)
54186 +{
54187 + struct task_struct *reaper = init_pid_ns.child_reaper;
54188 + unsigned int stacksize;
54189 +
54190 + subj_map_set.s_size = arg->role_db.num_subjects;
54191 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54192 + name_set.n_size = arg->role_db.num_objects;
54193 + inodev_set.i_size = arg->role_db.num_objects;
54194 +
54195 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
54196 + !name_set.n_size || !inodev_set.i_size)
54197 + return 1;
54198 +
54199 + if (!gr_init_uidset())
54200 + return 1;
54201 +
54202 + /* set up the stack that holds allocation info */
54203 +
54204 + stacksize = arg->role_db.num_pointers + 5;
54205 +
54206 + if (!acl_alloc_stack_init(stacksize))
54207 + return 1;
54208 +
54209 + /* grab reference for the real root dentry and vfsmount */
54210 + get_fs_root(reaper->fs, &real_root);
54211 +
54212 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54213 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54214 +#endif
54215 +
54216 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54217 + if (fakefs_obj_rw == NULL)
54218 + return 1;
54219 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54220 +
54221 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54222 + if (fakefs_obj_rwx == NULL)
54223 + return 1;
54224 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54225 +
54226 + subj_map_set.s_hash =
54227 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54228 + acl_role_set.r_hash =
54229 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54230 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54231 + inodev_set.i_hash =
54232 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54233 +
54234 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54235 + !name_set.n_hash || !inodev_set.i_hash)
54236 + return 1;
54237 +
54238 + memset(subj_map_set.s_hash, 0,
54239 + sizeof(struct subject_map *) * subj_map_set.s_size);
54240 + memset(acl_role_set.r_hash, 0,
54241 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
54242 + memset(name_set.n_hash, 0,
54243 + sizeof (struct name_entry *) * name_set.n_size);
54244 + memset(inodev_set.i_hash, 0,
54245 + sizeof (struct inodev_entry *) * inodev_set.i_size);
54246 +
54247 + return 0;
54248 +}
54249 +
54250 +/* free information not needed after startup
54251 + currently contains user->kernel pointer mappings for subjects
54252 +*/
54253 +
54254 +static void
54255 +free_init_variables(void)
54256 +{
54257 + __u32 i;
54258 +
54259 + if (subj_map_set.s_hash) {
54260 + for (i = 0; i < subj_map_set.s_size; i++) {
54261 + if (subj_map_set.s_hash[i]) {
54262 + kfree(subj_map_set.s_hash[i]);
54263 + subj_map_set.s_hash[i] = NULL;
54264 + }
54265 + }
54266 +
54267 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54268 + PAGE_SIZE)
54269 + kfree(subj_map_set.s_hash);
54270 + else
54271 + vfree(subj_map_set.s_hash);
54272 + }
54273 +
54274 + return;
54275 +}
54276 +
54277 +static void
54278 +free_variables(void)
54279 +{
54280 + struct acl_subject_label *s;
54281 + struct acl_role_label *r;
54282 + struct task_struct *task, *task2;
54283 + unsigned int x;
54284 +
54285 + gr_clear_learn_entries();
54286 +
54287 + read_lock(&tasklist_lock);
54288 + do_each_thread(task2, task) {
54289 + task->acl_sp_role = 0;
54290 + task->acl_role_id = 0;
54291 + task->acl = NULL;
54292 + task->role = NULL;
54293 + } while_each_thread(task2, task);
54294 + read_unlock(&tasklist_lock);
54295 +
54296 + /* release the reference to the real root dentry and vfsmount */
54297 + path_put(&real_root);
54298 + memset(&real_root, 0, sizeof(real_root));
54299 +
54300 + /* free all object hash tables */
54301 +
54302 + FOR_EACH_ROLE_START(r)
54303 + if (r->subj_hash == NULL)
54304 + goto next_role;
54305 + FOR_EACH_SUBJECT_START(r, s, x)
54306 + if (s->obj_hash == NULL)
54307 + break;
54308 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54309 + kfree(s->obj_hash);
54310 + else
54311 + vfree(s->obj_hash);
54312 + FOR_EACH_SUBJECT_END(s, x)
54313 + FOR_EACH_NESTED_SUBJECT_START(r, s)
54314 + if (s->obj_hash == NULL)
54315 + break;
54316 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54317 + kfree(s->obj_hash);
54318 + else
54319 + vfree(s->obj_hash);
54320 + FOR_EACH_NESTED_SUBJECT_END(s)
54321 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54322 + kfree(r->subj_hash);
54323 + else
54324 + vfree(r->subj_hash);
54325 + r->subj_hash = NULL;
54326 +next_role:
54327 + FOR_EACH_ROLE_END(r)
54328 +
54329 + acl_free_all();
54330 +
54331 + if (acl_role_set.r_hash) {
54332 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54333 + PAGE_SIZE)
54334 + kfree(acl_role_set.r_hash);
54335 + else
54336 + vfree(acl_role_set.r_hash);
54337 + }
54338 + if (name_set.n_hash) {
54339 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
54340 + PAGE_SIZE)
54341 + kfree(name_set.n_hash);
54342 + else
54343 + vfree(name_set.n_hash);
54344 + }
54345 +
54346 + if (inodev_set.i_hash) {
54347 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54348 + PAGE_SIZE)
54349 + kfree(inodev_set.i_hash);
54350 + else
54351 + vfree(inodev_set.i_hash);
54352 + }
54353 +
54354 + gr_free_uidset();
54355 +
54356 + memset(&name_set, 0, sizeof (struct name_db));
54357 + memset(&inodev_set, 0, sizeof (struct inodev_db));
54358 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54359 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54360 +
54361 + default_role = NULL;
54362 + kernel_role = NULL;
54363 + role_list = NULL;
54364 +
54365 + return;
54366 +}
54367 +
54368 +static __u32
54369 +count_user_objs(struct acl_object_label *userp)
54370 +{
54371 + struct acl_object_label o_tmp;
54372 + __u32 num = 0;
54373 +
54374 + while (userp) {
54375 + if (copy_from_user(&o_tmp, userp,
54376 + sizeof (struct acl_object_label)))
54377 + break;
54378 +
54379 + userp = o_tmp.prev;
54380 + num++;
54381 + }
54382 +
54383 + return num;
54384 +}
54385 +
54386 +static struct acl_subject_label *
54387 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54388 +
54389 +static int
54390 +copy_user_glob(struct acl_object_label *obj)
54391 +{
54392 + struct acl_object_label *g_tmp, **guser;
54393 + unsigned int len;
54394 + char *tmp;
54395 +
54396 + if (obj->globbed == NULL)
54397 + return 0;
54398 +
54399 + guser = &obj->globbed;
54400 + while (*guser) {
54401 + g_tmp = (struct acl_object_label *)
54402 + acl_alloc(sizeof (struct acl_object_label));
54403 + if (g_tmp == NULL)
54404 + return -ENOMEM;
54405 +
54406 + if (copy_from_user(g_tmp, *guser,
54407 + sizeof (struct acl_object_label)))
54408 + return -EFAULT;
54409 +
54410 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54411 +
54412 + if (!len || len >= PATH_MAX)
54413 + return -EINVAL;
54414 +
54415 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54416 + return -ENOMEM;
54417 +
54418 + if (copy_from_user(tmp, g_tmp->filename, len))
54419 + return -EFAULT;
54420 + tmp[len-1] = '\0';
54421 + g_tmp->filename = tmp;
54422 +
54423 + *guser = g_tmp;
54424 + guser = &(g_tmp->next);
54425 + }
54426 +
54427 + return 0;
54428 +}
54429 +
54430 +static int
54431 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54432 + struct acl_role_label *role)
54433 +{
54434 + struct acl_object_label *o_tmp;
54435 + unsigned int len;
54436 + int ret;
54437 + char *tmp;
54438 +
54439 + while (userp) {
54440 + if ((o_tmp = (struct acl_object_label *)
54441 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54442 + return -ENOMEM;
54443 +
54444 + if (copy_from_user(o_tmp, userp,
54445 + sizeof (struct acl_object_label)))
54446 + return -EFAULT;
54447 +
54448 + userp = o_tmp->prev;
54449 +
54450 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54451 +
54452 + if (!len || len >= PATH_MAX)
54453 + return -EINVAL;
54454 +
54455 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54456 + return -ENOMEM;
54457 +
54458 + if (copy_from_user(tmp, o_tmp->filename, len))
54459 + return -EFAULT;
54460 + tmp[len-1] = '\0';
54461 + o_tmp->filename = tmp;
54462 +
54463 + insert_acl_obj_label(o_tmp, subj);
54464 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54465 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54466 + return -ENOMEM;
54467 +
54468 + ret = copy_user_glob(o_tmp);
54469 + if (ret)
54470 + return ret;
54471 +
54472 + if (o_tmp->nested) {
54473 + int already_copied;
54474 +
54475 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54476 + if (IS_ERR(o_tmp->nested))
54477 + return PTR_ERR(o_tmp->nested);
54478 +
54479 + /* insert into nested subject list if we haven't copied this one yet
54480 + to prevent duplicate entries */
54481 + if (!already_copied) {
54482 + o_tmp->nested->next = role->hash->first;
54483 + role->hash->first = o_tmp->nested;
54484 + }
54485 + }
54486 + }
54487 +
54488 + return 0;
54489 +}
54490 +
54491 +static __u32
54492 +count_user_subjs(struct acl_subject_label *userp)
54493 +{
54494 + struct acl_subject_label s_tmp;
54495 + __u32 num = 0;
54496 +
54497 + while (userp) {
54498 + if (copy_from_user(&s_tmp, userp,
54499 + sizeof (struct acl_subject_label)))
54500 + break;
54501 +
54502 + userp = s_tmp.prev;
54503 + }
54504 +
54505 + return num;
54506 +}
54507 +
54508 +static int
54509 +copy_user_allowedips(struct acl_role_label *rolep)
54510 +{
54511 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54512 +
54513 + ruserip = rolep->allowed_ips;
54514 +
54515 + while (ruserip) {
54516 + rlast = rtmp;
54517 +
54518 + if ((rtmp = (struct role_allowed_ip *)
54519 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54520 + return -ENOMEM;
54521 +
54522 + if (copy_from_user(rtmp, ruserip,
54523 + sizeof (struct role_allowed_ip)))
54524 + return -EFAULT;
54525 +
54526 + ruserip = rtmp->prev;
54527 +
54528 + if (!rlast) {
54529 + rtmp->prev = NULL;
54530 + rolep->allowed_ips = rtmp;
54531 + } else {
54532 + rlast->next = rtmp;
54533 + rtmp->prev = rlast;
54534 + }
54535 +
54536 + if (!ruserip)
54537 + rtmp->next = NULL;
54538 + }
54539 +
54540 + return 0;
54541 +}
54542 +
54543 +static int
54544 +copy_user_transitions(struct acl_role_label *rolep)
54545 +{
54546 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54547 +
54548 + unsigned int len;
54549 + char *tmp;
54550 +
54551 + rusertp = rolep->transitions;
54552 +
54553 + while (rusertp) {
54554 + rlast = rtmp;
54555 +
54556 + if ((rtmp = (struct role_transition *)
54557 + acl_alloc(sizeof (struct role_transition))) == NULL)
54558 + return -ENOMEM;
54559 +
54560 + if (copy_from_user(rtmp, rusertp,
54561 + sizeof (struct role_transition)))
54562 + return -EFAULT;
54563 +
54564 + rusertp = rtmp->prev;
54565 +
54566 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54567 +
54568 + if (!len || len >= GR_SPROLE_LEN)
54569 + return -EINVAL;
54570 +
54571 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54572 + return -ENOMEM;
54573 +
54574 + if (copy_from_user(tmp, rtmp->rolename, len))
54575 + return -EFAULT;
54576 + tmp[len-1] = '\0';
54577 + rtmp->rolename = tmp;
54578 +
54579 + if (!rlast) {
54580 + rtmp->prev = NULL;
54581 + rolep->transitions = rtmp;
54582 + } else {
54583 + rlast->next = rtmp;
54584 + rtmp->prev = rlast;
54585 + }
54586 +
54587 + if (!rusertp)
54588 + rtmp->next = NULL;
54589 + }
54590 +
54591 + return 0;
54592 +}
54593 +
54594 +static struct acl_subject_label *
54595 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54596 +{
54597 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54598 + unsigned int len;
54599 + char *tmp;
54600 + __u32 num_objs;
54601 + struct acl_ip_label **i_tmp, *i_utmp2;
54602 + struct gr_hash_struct ghash;
54603 + struct subject_map *subjmap;
54604 + unsigned int i_num;
54605 + int err;
54606 +
54607 + if (already_copied != NULL)
54608 + *already_copied = 0;
54609 +
54610 + s_tmp = lookup_subject_map(userp);
54611 +
54612 + /* we've already copied this subject into the kernel, just return
54613 + the reference to it, and don't copy it over again
54614 + */
54615 + if (s_tmp) {
54616 + if (already_copied != NULL)
54617 + *already_copied = 1;
54618 + return(s_tmp);
54619 + }
54620 +
54621 + if ((s_tmp = (struct acl_subject_label *)
54622 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54623 + return ERR_PTR(-ENOMEM);
54624 +
54625 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54626 + if (subjmap == NULL)
54627 + return ERR_PTR(-ENOMEM);
54628 +
54629 + subjmap->user = userp;
54630 + subjmap->kernel = s_tmp;
54631 + insert_subj_map_entry(subjmap);
54632 +
54633 + if (copy_from_user(s_tmp, userp,
54634 + sizeof (struct acl_subject_label)))
54635 + return ERR_PTR(-EFAULT);
54636 +
54637 + len = strnlen_user(s_tmp->filename, PATH_MAX);
54638 +
54639 + if (!len || len >= PATH_MAX)
54640 + return ERR_PTR(-EINVAL);
54641 +
54642 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54643 + return ERR_PTR(-ENOMEM);
54644 +
54645 + if (copy_from_user(tmp, s_tmp->filename, len))
54646 + return ERR_PTR(-EFAULT);
54647 + tmp[len-1] = '\0';
54648 + s_tmp->filename = tmp;
54649 +
54650 + if (!strcmp(s_tmp->filename, "/"))
54651 + role->root_label = s_tmp;
54652 +
54653 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54654 + return ERR_PTR(-EFAULT);
54655 +
54656 + /* copy user and group transition tables */
54657 +
54658 + if (s_tmp->user_trans_num) {
54659 + uid_t *uidlist;
54660 +
54661 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54662 + if (uidlist == NULL)
54663 + return ERR_PTR(-ENOMEM);
54664 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54665 + return ERR_PTR(-EFAULT);
54666 +
54667 + s_tmp->user_transitions = uidlist;
54668 + }
54669 +
54670 + if (s_tmp->group_trans_num) {
54671 + gid_t *gidlist;
54672 +
54673 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54674 + if (gidlist == NULL)
54675 + return ERR_PTR(-ENOMEM);
54676 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54677 + return ERR_PTR(-EFAULT);
54678 +
54679 + s_tmp->group_transitions = gidlist;
54680 + }
54681 +
54682 + /* set up object hash table */
54683 + num_objs = count_user_objs(ghash.first);
54684 +
54685 + s_tmp->obj_hash_size = num_objs;
54686 + s_tmp->obj_hash =
54687 + (struct acl_object_label **)
54688 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54689 +
54690 + if (!s_tmp->obj_hash)
54691 + return ERR_PTR(-ENOMEM);
54692 +
54693 + memset(s_tmp->obj_hash, 0,
54694 + s_tmp->obj_hash_size *
54695 + sizeof (struct acl_object_label *));
54696 +
54697 + /* add in objects */
54698 + err = copy_user_objs(ghash.first, s_tmp, role);
54699 +
54700 + if (err)
54701 + return ERR_PTR(err);
54702 +
54703 + /* set pointer for parent subject */
54704 + if (s_tmp->parent_subject) {
54705 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54706 +
54707 + if (IS_ERR(s_tmp2))
54708 + return s_tmp2;
54709 +
54710 + s_tmp->parent_subject = s_tmp2;
54711 + }
54712 +
54713 + /* add in ip acls */
54714 +
54715 + if (!s_tmp->ip_num) {
54716 + s_tmp->ips = NULL;
54717 + goto insert;
54718 + }
54719 +
54720 + i_tmp =
54721 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54722 + sizeof (struct acl_ip_label *));
54723 +
54724 + if (!i_tmp)
54725 + return ERR_PTR(-ENOMEM);
54726 +
54727 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54728 + *(i_tmp + i_num) =
54729 + (struct acl_ip_label *)
54730 + acl_alloc(sizeof (struct acl_ip_label));
54731 + if (!*(i_tmp + i_num))
54732 + return ERR_PTR(-ENOMEM);
54733 +
54734 + if (copy_from_user
54735 + (&i_utmp2, s_tmp->ips + i_num,
54736 + sizeof (struct acl_ip_label *)))
54737 + return ERR_PTR(-EFAULT);
54738 +
54739 + if (copy_from_user
54740 + (*(i_tmp + i_num), i_utmp2,
54741 + sizeof (struct acl_ip_label)))
54742 + return ERR_PTR(-EFAULT);
54743 +
54744 + if ((*(i_tmp + i_num))->iface == NULL)
54745 + continue;
54746 +
54747 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54748 + if (!len || len >= IFNAMSIZ)
54749 + return ERR_PTR(-EINVAL);
54750 + tmp = acl_alloc(len);
54751 + if (tmp == NULL)
54752 + return ERR_PTR(-ENOMEM);
54753 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54754 + return ERR_PTR(-EFAULT);
54755 + (*(i_tmp + i_num))->iface = tmp;
54756 + }
54757 +
54758 + s_tmp->ips = i_tmp;
54759 +
54760 +insert:
54761 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
54762 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
54763 + return ERR_PTR(-ENOMEM);
54764 +
54765 + return s_tmp;
54766 +}
54767 +
54768 +static int
54769 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
54770 +{
54771 + struct acl_subject_label s_pre;
54772 + struct acl_subject_label * ret;
54773 + int err;
54774 +
54775 + while (userp) {
54776 + if (copy_from_user(&s_pre, userp,
54777 + sizeof (struct acl_subject_label)))
54778 + return -EFAULT;
54779 +
54780 + ret = do_copy_user_subj(userp, role, NULL);
54781 +
54782 + err = PTR_ERR(ret);
54783 + if (IS_ERR(ret))
54784 + return err;
54785 +
54786 + insert_acl_subj_label(ret, role);
54787 +
54788 + userp = s_pre.prev;
54789 + }
54790 +
54791 + return 0;
54792 +}
54793 +
54794 +static int
54795 +copy_user_acl(struct gr_arg *arg)
54796 +{
54797 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
54798 + struct acl_subject_label *subj_list;
54799 + struct sprole_pw *sptmp;
54800 + struct gr_hash_struct *ghash;
54801 + uid_t *domainlist;
54802 + unsigned int r_num;
54803 + unsigned int len;
54804 + char *tmp;
54805 + int err = 0;
54806 + __u16 i;
54807 + __u32 num_subjs;
54808 +
54809 + /* we need a default and kernel role */
54810 + if (arg->role_db.num_roles < 2)
54811 + return -EINVAL;
54812 +
54813 + /* copy special role authentication info from userspace */
54814 +
54815 + num_sprole_pws = arg->num_sprole_pws;
54816 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
54817 +
54818 + if (!acl_special_roles && num_sprole_pws)
54819 + return -ENOMEM;
54820 +
54821 + for (i = 0; i < num_sprole_pws; i++) {
54822 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
54823 + if (!sptmp)
54824 + return -ENOMEM;
54825 + if (copy_from_user(sptmp, arg->sprole_pws + i,
54826 + sizeof (struct sprole_pw)))
54827 + return -EFAULT;
54828 +
54829 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
54830 +
54831 + if (!len || len >= GR_SPROLE_LEN)
54832 + return -EINVAL;
54833 +
54834 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54835 + return -ENOMEM;
54836 +
54837 + if (copy_from_user(tmp, sptmp->rolename, len))
54838 + return -EFAULT;
54839 +
54840 + tmp[len-1] = '\0';
54841 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54842 + printk(KERN_ALERT "Copying special role %s\n", tmp);
54843 +#endif
54844 + sptmp->rolename = tmp;
54845 + acl_special_roles[i] = sptmp;
54846 + }
54847 +
54848 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
54849 +
54850 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
54851 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
54852 +
54853 + if (!r_tmp)
54854 + return -ENOMEM;
54855 +
54856 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
54857 + sizeof (struct acl_role_label *)))
54858 + return -EFAULT;
54859 +
54860 + if (copy_from_user(r_tmp, r_utmp2,
54861 + sizeof (struct acl_role_label)))
54862 + return -EFAULT;
54863 +
54864 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
54865 +
54866 + if (!len || len >= PATH_MAX)
54867 + return -EINVAL;
54868 +
54869 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54870 + return -ENOMEM;
54871 +
54872 + if (copy_from_user(tmp, r_tmp->rolename, len))
54873 + return -EFAULT;
54874 +
54875 + tmp[len-1] = '\0';
54876 + r_tmp->rolename = tmp;
54877 +
54878 + if (!strcmp(r_tmp->rolename, "default")
54879 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
54880 + default_role = r_tmp;
54881 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
54882 + kernel_role = r_tmp;
54883 + }
54884 +
54885 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
54886 + return -ENOMEM;
54887 +
54888 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
54889 + return -EFAULT;
54890 +
54891 + r_tmp->hash = ghash;
54892 +
54893 + num_subjs = count_user_subjs(r_tmp->hash->first);
54894 +
54895 + r_tmp->subj_hash_size = num_subjs;
54896 + r_tmp->subj_hash =
54897 + (struct acl_subject_label **)
54898 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
54899 +
54900 + if (!r_tmp->subj_hash)
54901 + return -ENOMEM;
54902 +
54903 + err = copy_user_allowedips(r_tmp);
54904 + if (err)
54905 + return err;
54906 +
54907 + /* copy domain info */
54908 + if (r_tmp->domain_children != NULL) {
54909 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
54910 + if (domainlist == NULL)
54911 + return -ENOMEM;
54912 +
54913 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
54914 + return -EFAULT;
54915 +
54916 + r_tmp->domain_children = domainlist;
54917 + }
54918 +
54919 + err = copy_user_transitions(r_tmp);
54920 + if (err)
54921 + return err;
54922 +
54923 + memset(r_tmp->subj_hash, 0,
54924 + r_tmp->subj_hash_size *
54925 + sizeof (struct acl_subject_label *));
54926 +
54927 + /* acquire the list of subjects, then NULL out
54928 + the list prior to parsing the subjects for this role,
54929 + as during this parsing the list is replaced with a list
54930 + of *nested* subjects for the role
54931 + */
54932 + subj_list = r_tmp->hash->first;
54933 +
54934 + /* set nested subject list to null */
54935 + r_tmp->hash->first = NULL;
54936 +
54937 + err = copy_user_subjs(subj_list, r_tmp);
54938 +
54939 + if (err)
54940 + return err;
54941 +
54942 + insert_acl_role_label(r_tmp);
54943 + }
54944 +
54945 + if (default_role == NULL || kernel_role == NULL)
54946 + return -EINVAL;
54947 +
54948 + return err;
54949 +}
54950 +
54951 +static int
54952 +gracl_init(struct gr_arg *args)
54953 +{
54954 + int error = 0;
54955 +
54956 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
54957 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
54958 +
54959 + if (init_variables(args)) {
54960 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
54961 + error = -ENOMEM;
54962 + free_variables();
54963 + goto out;
54964 + }
54965 +
54966 + error = copy_user_acl(args);
54967 + free_init_variables();
54968 + if (error) {
54969 + free_variables();
54970 + goto out;
54971 + }
54972 +
54973 + if ((error = gr_set_acls(0))) {
54974 + free_variables();
54975 + goto out;
54976 + }
54977 +
54978 + pax_open_kernel();
54979 + gr_status |= GR_READY;
54980 + pax_close_kernel();
54981 +
54982 + out:
54983 + return error;
54984 +}
54985 +
54986 +/* derived from glibc fnmatch() 0: match, 1: no match*/
54987 +
54988 +static int
54989 +glob_match(const char *p, const char *n)
54990 +{
54991 + char c;
54992 +
54993 + while ((c = *p++) != '\0') {
54994 + switch (c) {
54995 + case '?':
54996 + if (*n == '\0')
54997 + return 1;
54998 + else if (*n == '/')
54999 + return 1;
55000 + break;
55001 + case '\\':
55002 + if (*n != c)
55003 + return 1;
55004 + break;
55005 + case '*':
55006 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
55007 + if (*n == '/')
55008 + return 1;
55009 + else if (c == '?') {
55010 + if (*n == '\0')
55011 + return 1;
55012 + else
55013 + ++n;
55014 + }
55015 + }
55016 + if (c == '\0') {
55017 + return 0;
55018 + } else {
55019 + const char *endp;
55020 +
55021 + if ((endp = strchr(n, '/')) == NULL)
55022 + endp = n + strlen(n);
55023 +
55024 + if (c == '[') {
55025 + for (--p; n < endp; ++n)
55026 + if (!glob_match(p, n))
55027 + return 0;
55028 + } else if (c == '/') {
55029 + while (*n != '\0' && *n != '/')
55030 + ++n;
55031 + if (*n == '/' && !glob_match(p, n + 1))
55032 + return 0;
55033 + } else {
55034 + for (--p; n < endp; ++n)
55035 + if (*n == c && !glob_match(p, n))
55036 + return 0;
55037 + }
55038 +
55039 + return 1;
55040 + }
55041 + case '[':
55042 + {
55043 + int not;
55044 + char cold;
55045 +
55046 + if (*n == '\0' || *n == '/')
55047 + return 1;
55048 +
55049 + not = (*p == '!' || *p == '^');
55050 + if (not)
55051 + ++p;
55052 +
55053 + c = *p++;
55054 + for (;;) {
55055 + unsigned char fn = (unsigned char)*n;
55056 +
55057 + if (c == '\0')
55058 + return 1;
55059 + else {
55060 + if (c == fn)
55061 + goto matched;
55062 + cold = c;
55063 + c = *p++;
55064 +
55065 + if (c == '-' && *p != ']') {
55066 + unsigned char cend = *p++;
55067 +
55068 + if (cend == '\0')
55069 + return 1;
55070 +
55071 + if (cold <= fn && fn <= cend)
55072 + goto matched;
55073 +
55074 + c = *p++;
55075 + }
55076 + }
55077 +
55078 + if (c == ']')
55079 + break;
55080 + }
55081 + if (!not)
55082 + return 1;
55083 + break;
55084 + matched:
55085 + while (c != ']') {
55086 + if (c == '\0')
55087 + return 1;
55088 +
55089 + c = *p++;
55090 + }
55091 + if (not)
55092 + return 1;
55093 + }
55094 + break;
55095 + default:
55096 + if (c != *n)
55097 + return 1;
55098 + }
55099 +
55100 + ++n;
55101 + }
55102 +
55103 + if (*n == '\0')
55104 + return 0;
55105 +
55106 + if (*n == '/')
55107 + return 0;
55108 +
55109 + return 1;
55110 +}
55111 +
55112 +static struct acl_object_label *
55113 +chk_glob_label(struct acl_object_label *globbed,
55114 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55115 +{
55116 + struct acl_object_label *tmp;
55117 +
55118 + if (*path == NULL)
55119 + *path = gr_to_filename_nolock(dentry, mnt);
55120 +
55121 + tmp = globbed;
55122 +
55123 + while (tmp) {
55124 + if (!glob_match(tmp->filename, *path))
55125 + return tmp;
55126 + tmp = tmp->next;
55127 + }
55128 +
55129 + return NULL;
55130 +}
55131 +
55132 +static struct acl_object_label *
55133 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55134 + const ino_t curr_ino, const dev_t curr_dev,
55135 + const struct acl_subject_label *subj, char **path, const int checkglob)
55136 +{
55137 + struct acl_subject_label *tmpsubj;
55138 + struct acl_object_label *retval;
55139 + struct acl_object_label *retval2;
55140 +
55141 + tmpsubj = (struct acl_subject_label *) subj;
55142 + read_lock(&gr_inode_lock);
55143 + do {
55144 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55145 + if (retval) {
55146 + if (checkglob && retval->globbed) {
55147 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55148 + if (retval2)
55149 + retval = retval2;
55150 + }
55151 + break;
55152 + }
55153 + } while ((tmpsubj = tmpsubj->parent_subject));
55154 + read_unlock(&gr_inode_lock);
55155 +
55156 + return retval;
55157 +}
55158 +
55159 +static __inline__ struct acl_object_label *
55160 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55161 + struct dentry *curr_dentry,
55162 + const struct acl_subject_label *subj, char **path, const int checkglob)
55163 +{
55164 + int newglob = checkglob;
55165 + ino_t inode;
55166 + dev_t device;
55167 +
55168 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55169 + as we don't want a / * rule to match instead of the / object
55170 + don't do this for create lookups that call this function though, since they're looking up
55171 + on the parent and thus need globbing checks on all paths
55172 + */
55173 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55174 + newglob = GR_NO_GLOB;
55175 +
55176 + spin_lock(&curr_dentry->d_lock);
55177 + inode = curr_dentry->d_inode->i_ino;
55178 + device = __get_dev(curr_dentry);
55179 + spin_unlock(&curr_dentry->d_lock);
55180 +
55181 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55182 +}
55183 +
55184 +static struct acl_object_label *
55185 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55186 + const struct acl_subject_label *subj, char *path, const int checkglob)
55187 +{
55188 + struct dentry *dentry = (struct dentry *) l_dentry;
55189 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55190 + struct mount *real_mnt = real_mount(mnt);
55191 + struct acl_object_label *retval;
55192 + struct dentry *parent;
55193 +
55194 + write_seqlock(&rename_lock);
55195 + br_read_lock(&vfsmount_lock);
55196 +
55197 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55198 +#ifdef CONFIG_NET
55199 + mnt == sock_mnt ||
55200 +#endif
55201 +#ifdef CONFIG_HUGETLBFS
55202 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55203 +#endif
55204 + /* ignore Eric Biederman */
55205 + IS_PRIVATE(l_dentry->d_inode))) {
55206 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55207 + goto out;
55208 + }
55209 +
55210 + for (;;) {
55211 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55212 + break;
55213 +
55214 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55215 + if (!mnt_has_parent(real_mnt))
55216 + break;
55217 +
55218 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55219 + if (retval != NULL)
55220 + goto out;
55221 +
55222 + dentry = real_mnt->mnt_mountpoint;
55223 + real_mnt = real_mnt->mnt_parent;
55224 + mnt = &real_mnt->mnt;
55225 + continue;
55226 + }
55227 +
55228 + parent = dentry->d_parent;
55229 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55230 + if (retval != NULL)
55231 + goto out;
55232 +
55233 + dentry = parent;
55234 + }
55235 +
55236 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55237 +
55238 + /* real_root is pinned so we don't have to hold a reference */
55239 + if (retval == NULL)
55240 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55241 +out:
55242 + br_read_unlock(&vfsmount_lock);
55243 + write_sequnlock(&rename_lock);
55244 +
55245 + BUG_ON(retval == NULL);
55246 +
55247 + return retval;
55248 +}
55249 +
55250 +static __inline__ struct acl_object_label *
55251 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55252 + const struct acl_subject_label *subj)
55253 +{
55254 + char *path = NULL;
55255 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55256 +}
55257 +
55258 +static __inline__ struct acl_object_label *
55259 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55260 + const struct acl_subject_label *subj)
55261 +{
55262 + char *path = NULL;
55263 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55264 +}
55265 +
55266 +static __inline__ struct acl_object_label *
55267 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55268 + const struct acl_subject_label *subj, char *path)
55269 +{
55270 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55271 +}
55272 +
55273 +static struct acl_subject_label *
55274 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55275 + const struct acl_role_label *role)
55276 +{
55277 + struct dentry *dentry = (struct dentry *) l_dentry;
55278 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55279 + struct mount *real_mnt = real_mount(mnt);
55280 + struct acl_subject_label *retval;
55281 + struct dentry *parent;
55282 +
55283 + write_seqlock(&rename_lock);
55284 + br_read_lock(&vfsmount_lock);
55285 +
55286 + for (;;) {
55287 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55288 + break;
55289 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55290 + if (!mnt_has_parent(real_mnt))
55291 + break;
55292 +
55293 + spin_lock(&dentry->d_lock);
55294 + read_lock(&gr_inode_lock);
55295 + retval =
55296 + lookup_acl_subj_label(dentry->d_inode->i_ino,
55297 + __get_dev(dentry), role);
55298 + read_unlock(&gr_inode_lock);
55299 + spin_unlock(&dentry->d_lock);
55300 + if (retval != NULL)
55301 + goto out;
55302 +
55303 + dentry = real_mnt->mnt_mountpoint;
55304 + real_mnt = real_mnt->mnt_parent;
55305 + mnt = &real_mnt->mnt;
55306 + continue;
55307 + }
55308 +
55309 + spin_lock(&dentry->d_lock);
55310 + read_lock(&gr_inode_lock);
55311 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55312 + __get_dev(dentry), role);
55313 + read_unlock(&gr_inode_lock);
55314 + parent = dentry->d_parent;
55315 + spin_unlock(&dentry->d_lock);
55316 +
55317 + if (retval != NULL)
55318 + goto out;
55319 +
55320 + dentry = parent;
55321 + }
55322 +
55323 + spin_lock(&dentry->d_lock);
55324 + read_lock(&gr_inode_lock);
55325 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55326 + __get_dev(dentry), role);
55327 + read_unlock(&gr_inode_lock);
55328 + spin_unlock(&dentry->d_lock);
55329 +
55330 + if (unlikely(retval == NULL)) {
55331 + /* real_root is pinned, we don't need to hold a reference */
55332 + read_lock(&gr_inode_lock);
55333 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55334 + __get_dev(real_root.dentry), role);
55335 + read_unlock(&gr_inode_lock);
55336 + }
55337 +out:
55338 + br_read_unlock(&vfsmount_lock);
55339 + write_sequnlock(&rename_lock);
55340 +
55341 + BUG_ON(retval == NULL);
55342 +
55343 + return retval;
55344 +}
55345 +
55346 +static void
55347 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55348 +{
55349 + struct task_struct *task = current;
55350 + const struct cred *cred = current_cred();
55351 +
55352 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55353 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55354 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55355 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55356 +
55357 + return;
55358 +}
55359 +
55360 +static void
55361 +gr_log_learn_id_change(const char type, const unsigned int real,
55362 + const unsigned int effective, const unsigned int fs)
55363 +{
55364 + struct task_struct *task = current;
55365 + const struct cred *cred = current_cred();
55366 +
55367 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55368 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55369 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55370 + type, real, effective, fs, &task->signal->saved_ip);
55371 +
55372 + return;
55373 +}
55374 +
55375 +__u32
55376 +gr_search_file(const struct dentry * dentry, const __u32 mode,
55377 + const struct vfsmount * mnt)
55378 +{
55379 + __u32 retval = mode;
55380 + struct acl_subject_label *curracl;
55381 + struct acl_object_label *currobj;
55382 +
55383 + if (unlikely(!(gr_status & GR_READY)))
55384 + return (mode & ~GR_AUDITS);
55385 +
55386 + curracl = current->acl;
55387 +
55388 + currobj = chk_obj_label(dentry, mnt, curracl);
55389 + retval = currobj->mode & mode;
55390 +
55391 + /* if we're opening a specified transfer file for writing
55392 + (e.g. /dev/initctl), then transfer our role to init
55393 + */
55394 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55395 + current->role->roletype & GR_ROLE_PERSIST)) {
55396 + struct task_struct *task = init_pid_ns.child_reaper;
55397 +
55398 + if (task->role != current->role) {
55399 + task->acl_sp_role = 0;
55400 + task->acl_role_id = current->acl_role_id;
55401 + task->role = current->role;
55402 + rcu_read_lock();
55403 + read_lock(&grsec_exec_file_lock);
55404 + gr_apply_subject_to_task(task);
55405 + read_unlock(&grsec_exec_file_lock);
55406 + rcu_read_unlock();
55407 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55408 + }
55409 + }
55410 +
55411 + if (unlikely
55412 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55413 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55414 + __u32 new_mode = mode;
55415 +
55416 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55417 +
55418 + retval = new_mode;
55419 +
55420 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55421 + new_mode |= GR_INHERIT;
55422 +
55423 + if (!(mode & GR_NOLEARN))
55424 + gr_log_learn(dentry, mnt, new_mode);
55425 + }
55426 +
55427 + return retval;
55428 +}
55429 +
55430 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55431 + const struct dentry *parent,
55432 + const struct vfsmount *mnt)
55433 +{
55434 + struct name_entry *match;
55435 + struct acl_object_label *matchpo;
55436 + struct acl_subject_label *curracl;
55437 + char *path;
55438 +
55439 + if (unlikely(!(gr_status & GR_READY)))
55440 + return NULL;
55441 +
55442 + preempt_disable();
55443 + path = gr_to_filename_rbac(new_dentry, mnt);
55444 + match = lookup_name_entry_create(path);
55445 +
55446 + curracl = current->acl;
55447 +
55448 + if (match) {
55449 + read_lock(&gr_inode_lock);
55450 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55451 + read_unlock(&gr_inode_lock);
55452 +
55453 + if (matchpo) {
55454 + preempt_enable();
55455 + return matchpo;
55456 + }
55457 + }
55458 +
55459 + // lookup parent
55460 +
55461 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55462 +
55463 + preempt_enable();
55464 + return matchpo;
55465 +}
55466 +
55467 +__u32
55468 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55469 + const struct vfsmount * mnt, const __u32 mode)
55470 +{
55471 + struct acl_object_label *matchpo;
55472 + __u32 retval;
55473 +
55474 + if (unlikely(!(gr_status & GR_READY)))
55475 + return (mode & ~GR_AUDITS);
55476 +
55477 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55478 +
55479 + retval = matchpo->mode & mode;
55480 +
55481 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55482 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55483 + __u32 new_mode = mode;
55484 +
55485 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55486 +
55487 + gr_log_learn(new_dentry, mnt, new_mode);
55488 + return new_mode;
55489 + }
55490 +
55491 + return retval;
55492 +}
55493 +
55494 +__u32
55495 +gr_check_link(const struct dentry * new_dentry,
55496 + const struct dentry * parent_dentry,
55497 + const struct vfsmount * parent_mnt,
55498 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55499 +{
55500 + struct acl_object_label *obj;
55501 + __u32 oldmode, newmode;
55502 + __u32 needmode;
55503 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55504 + GR_DELETE | GR_INHERIT;
55505 +
55506 + if (unlikely(!(gr_status & GR_READY)))
55507 + return (GR_CREATE | GR_LINK);
55508 +
55509 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55510 + oldmode = obj->mode;
55511 +
55512 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55513 + newmode = obj->mode;
55514 +
55515 + needmode = newmode & checkmodes;
55516 +
55517 + // old name for hardlink must have at least the permissions of the new name
55518 + if ((oldmode & needmode) != needmode)
55519 + goto bad;
55520 +
55521 + // if old name had restrictions/auditing, make sure the new name does as well
55522 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55523 +
55524 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55525 + if (is_privileged_binary(old_dentry))
55526 + needmode |= GR_SETID;
55527 +
55528 + if ((newmode & needmode) != needmode)
55529 + goto bad;
55530 +
55531 + // enforce minimum permissions
55532 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55533 + return newmode;
55534 +bad:
55535 + needmode = oldmode;
55536 + if (is_privileged_binary(old_dentry))
55537 + needmode |= GR_SETID;
55538 +
55539 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55540 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55541 + return (GR_CREATE | GR_LINK);
55542 + } else if (newmode & GR_SUPPRESS)
55543 + return GR_SUPPRESS;
55544 + else
55545 + return 0;
55546 +}
55547 +
55548 +int
55549 +gr_check_hidden_task(const struct task_struct *task)
55550 +{
55551 + if (unlikely(!(gr_status & GR_READY)))
55552 + return 0;
55553 +
55554 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55555 + return 1;
55556 +
55557 + return 0;
55558 +}
55559 +
55560 +int
55561 +gr_check_protected_task(const struct task_struct *task)
55562 +{
55563 + if (unlikely(!(gr_status & GR_READY) || !task))
55564 + return 0;
55565 +
55566 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55567 + task->acl != current->acl)
55568 + return 1;
55569 +
55570 + return 0;
55571 +}
55572 +
55573 +int
55574 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55575 +{
55576 + struct task_struct *p;
55577 + int ret = 0;
55578 +
55579 + if (unlikely(!(gr_status & GR_READY) || !pid))
55580 + return ret;
55581 +
55582 + read_lock(&tasklist_lock);
55583 + do_each_pid_task(pid, type, p) {
55584 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55585 + p->acl != current->acl) {
55586 + ret = 1;
55587 + goto out;
55588 + }
55589 + } while_each_pid_task(pid, type, p);
55590 +out:
55591 + read_unlock(&tasklist_lock);
55592 +
55593 + return ret;
55594 +}
55595 +
55596 +void
55597 +gr_copy_label(struct task_struct *tsk)
55598 +{
55599 + tsk->signal->used_accept = 0;
55600 + tsk->acl_sp_role = 0;
55601 + tsk->acl_role_id = current->acl_role_id;
55602 + tsk->acl = current->acl;
55603 + tsk->role = current->role;
55604 + tsk->signal->curr_ip = current->signal->curr_ip;
55605 + tsk->signal->saved_ip = current->signal->saved_ip;
55606 + if (current->exec_file)
55607 + get_file(current->exec_file);
55608 + tsk->exec_file = current->exec_file;
55609 + tsk->is_writable = current->is_writable;
55610 + if (unlikely(current->signal->used_accept)) {
55611 + current->signal->curr_ip = 0;
55612 + current->signal->saved_ip = 0;
55613 + }
55614 +
55615 + return;
55616 +}
55617 +
55618 +static void
55619 +gr_set_proc_res(struct task_struct *task)
55620 +{
55621 + struct acl_subject_label *proc;
55622 + unsigned short i;
55623 +
55624 + proc = task->acl;
55625 +
55626 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55627 + return;
55628 +
55629 + for (i = 0; i < RLIM_NLIMITS; i++) {
55630 + if (!(proc->resmask & (1 << i)))
55631 + continue;
55632 +
55633 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55634 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55635 + }
55636 +
55637 + return;
55638 +}
55639 +
55640 +extern int __gr_process_user_ban(struct user_struct *user);
55641 +
55642 +int
55643 +gr_check_user_change(int real, int effective, int fs)
55644 +{
55645 + unsigned int i;
55646 + __u16 num;
55647 + uid_t *uidlist;
55648 + int curuid;
55649 + int realok = 0;
55650 + int effectiveok = 0;
55651 + int fsok = 0;
55652 +
55653 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55654 + struct user_struct *user;
55655 +
55656 + if (real == -1)
55657 + goto skipit;
55658 +
55659 + user = find_user(real);
55660 + if (user == NULL)
55661 + goto skipit;
55662 +
55663 + if (__gr_process_user_ban(user)) {
55664 + /* for find_user */
55665 + free_uid(user);
55666 + return 1;
55667 + }
55668 +
55669 + /* for find_user */
55670 + free_uid(user);
55671 +
55672 +skipit:
55673 +#endif
55674 +
55675 + if (unlikely(!(gr_status & GR_READY)))
55676 + return 0;
55677 +
55678 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55679 + gr_log_learn_id_change('u', real, effective, fs);
55680 +
55681 + num = current->acl->user_trans_num;
55682 + uidlist = current->acl->user_transitions;
55683 +
55684 + if (uidlist == NULL)
55685 + return 0;
55686 +
55687 + if (real == -1)
55688 + realok = 1;
55689 + if (effective == -1)
55690 + effectiveok = 1;
55691 + if (fs == -1)
55692 + fsok = 1;
55693 +
55694 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
55695 + for (i = 0; i < num; i++) {
55696 + curuid = (int)uidlist[i];
55697 + if (real == curuid)
55698 + realok = 1;
55699 + if (effective == curuid)
55700 + effectiveok = 1;
55701 + if (fs == curuid)
55702 + fsok = 1;
55703 + }
55704 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
55705 + for (i = 0; i < num; i++) {
55706 + curuid = (int)uidlist[i];
55707 + if (real == curuid)
55708 + break;
55709 + if (effective == curuid)
55710 + break;
55711 + if (fs == curuid)
55712 + break;
55713 + }
55714 + /* not in deny list */
55715 + if (i == num) {
55716 + realok = 1;
55717 + effectiveok = 1;
55718 + fsok = 1;
55719 + }
55720 + }
55721 +
55722 + if (realok && effectiveok && fsok)
55723 + return 0;
55724 + else {
55725 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55726 + return 1;
55727 + }
55728 +}
55729 +
55730 +int
55731 +gr_check_group_change(int real, int effective, int fs)
55732 +{
55733 + unsigned int i;
55734 + __u16 num;
55735 + gid_t *gidlist;
55736 + int curgid;
55737 + int realok = 0;
55738 + int effectiveok = 0;
55739 + int fsok = 0;
55740 +
55741 + if (unlikely(!(gr_status & GR_READY)))
55742 + return 0;
55743 +
55744 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55745 + gr_log_learn_id_change('g', real, effective, fs);
55746 +
55747 + num = current->acl->group_trans_num;
55748 + gidlist = current->acl->group_transitions;
55749 +
55750 + if (gidlist == NULL)
55751 + return 0;
55752 +
55753 + if (real == -1)
55754 + realok = 1;
55755 + if (effective == -1)
55756 + effectiveok = 1;
55757 + if (fs == -1)
55758 + fsok = 1;
55759 +
55760 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
55761 + for (i = 0; i < num; i++) {
55762 + curgid = (int)gidlist[i];
55763 + if (real == curgid)
55764 + realok = 1;
55765 + if (effective == curgid)
55766 + effectiveok = 1;
55767 + if (fs == curgid)
55768 + fsok = 1;
55769 + }
55770 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
55771 + for (i = 0; i < num; i++) {
55772 + curgid = (int)gidlist[i];
55773 + if (real == curgid)
55774 + break;
55775 + if (effective == curgid)
55776 + break;
55777 + if (fs == curgid)
55778 + break;
55779 + }
55780 + /* not in deny list */
55781 + if (i == num) {
55782 + realok = 1;
55783 + effectiveok = 1;
55784 + fsok = 1;
55785 + }
55786 + }
55787 +
55788 + if (realok && effectiveok && fsok)
55789 + return 0;
55790 + else {
55791 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55792 + return 1;
55793 + }
55794 +}
55795 +
55796 +extern int gr_acl_is_capable(const int cap);
55797 +
55798 +void
55799 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
55800 +{
55801 + struct acl_role_label *role = task->role;
55802 + struct acl_subject_label *subj = NULL;
55803 + struct acl_object_label *obj;
55804 + struct file *filp;
55805 +
55806 + if (unlikely(!(gr_status & GR_READY)))
55807 + return;
55808 +
55809 + filp = task->exec_file;
55810 +
55811 + /* kernel process, we'll give them the kernel role */
55812 + if (unlikely(!filp)) {
55813 + task->role = kernel_role;
55814 + task->acl = kernel_role->root_label;
55815 + return;
55816 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
55817 + role = lookup_acl_role_label(task, uid, gid);
55818 +
55819 + /* don't change the role if we're not a privileged process */
55820 + if (role && task->role != role &&
55821 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
55822 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
55823 + return;
55824 +
55825 + /* perform subject lookup in possibly new role
55826 + we can use this result below in the case where role == task->role
55827 + */
55828 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
55829 +
55830 + /* if we changed uid/gid, but result in the same role
55831 + and are using inheritance, don't lose the inherited subject
55832 + if current subject is other than what normal lookup
55833 + would result in, we arrived via inheritance, don't
55834 + lose subject
55835 + */
55836 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
55837 + (subj == task->acl)))
55838 + task->acl = subj;
55839 +
55840 + task->role = role;
55841 +
55842 + task->is_writable = 0;
55843 +
55844 + /* ignore additional mmap checks for processes that are writable
55845 + by the default ACL */
55846 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55847 + if (unlikely(obj->mode & GR_WRITE))
55848 + task->is_writable = 1;
55849 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55850 + if (unlikely(obj->mode & GR_WRITE))
55851 + task->is_writable = 1;
55852 +
55853 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55854 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55855 +#endif
55856 +
55857 + gr_set_proc_res(task);
55858 +
55859 + return;
55860 +}
55861 +
55862 +int
55863 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55864 + const int unsafe_flags)
55865 +{
55866 + struct task_struct *task = current;
55867 + struct acl_subject_label *newacl;
55868 + struct acl_object_label *obj;
55869 + __u32 retmode;
55870 +
55871 + if (unlikely(!(gr_status & GR_READY)))
55872 + return 0;
55873 +
55874 + newacl = chk_subj_label(dentry, mnt, task->role);
55875 +
55876 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
55877 + did an exec
55878 + */
55879 + rcu_read_lock();
55880 + read_lock(&tasklist_lock);
55881 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
55882 + (task->parent->acl->mode & GR_POVERRIDE))) {
55883 + read_unlock(&tasklist_lock);
55884 + rcu_read_unlock();
55885 + goto skip_check;
55886 + }
55887 + read_unlock(&tasklist_lock);
55888 + rcu_read_unlock();
55889 +
55890 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
55891 + !(task->role->roletype & GR_ROLE_GOD) &&
55892 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
55893 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55894 + if (unsafe_flags & LSM_UNSAFE_SHARE)
55895 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
55896 + else
55897 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
55898 + return -EACCES;
55899 + }
55900 +
55901 +skip_check:
55902 +
55903 + obj = chk_obj_label(dentry, mnt, task->acl);
55904 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
55905 +
55906 + if (!(task->acl->mode & GR_INHERITLEARN) &&
55907 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
55908 + if (obj->nested)
55909 + task->acl = obj->nested;
55910 + else
55911 + task->acl = newacl;
55912 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
55913 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
55914 +
55915 + task->is_writable = 0;
55916 +
55917 + /* ignore additional mmap checks for processes that are writable
55918 + by the default ACL */
55919 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
55920 + if (unlikely(obj->mode & GR_WRITE))
55921 + task->is_writable = 1;
55922 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
55923 + if (unlikely(obj->mode & GR_WRITE))
55924 + task->is_writable = 1;
55925 +
55926 + gr_set_proc_res(task);
55927 +
55928 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55929 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55930 +#endif
55931 + return 0;
55932 +}
55933 +
55934 +/* always called with valid inodev ptr */
55935 +static void
55936 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
55937 +{
55938 + struct acl_object_label *matchpo;
55939 + struct acl_subject_label *matchps;
55940 + struct acl_subject_label *subj;
55941 + struct acl_role_label *role;
55942 + unsigned int x;
55943 +
55944 + FOR_EACH_ROLE_START(role)
55945 + FOR_EACH_SUBJECT_START(role, subj, x)
55946 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55947 + matchpo->mode |= GR_DELETED;
55948 + FOR_EACH_SUBJECT_END(subj,x)
55949 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
55950 + /* nested subjects aren't in the role's subj_hash table */
55951 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55952 + matchpo->mode |= GR_DELETED;
55953 + FOR_EACH_NESTED_SUBJECT_END(subj)
55954 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
55955 + matchps->mode |= GR_DELETED;
55956 + FOR_EACH_ROLE_END(role)
55957 +
55958 + inodev->nentry->deleted = 1;
55959 +
55960 + return;
55961 +}
55962 +
55963 +void
55964 +gr_handle_delete(const ino_t ino, const dev_t dev)
55965 +{
55966 + struct inodev_entry *inodev;
55967 +
55968 + if (unlikely(!(gr_status & GR_READY)))
55969 + return;
55970 +
55971 + write_lock(&gr_inode_lock);
55972 + inodev = lookup_inodev_entry(ino, dev);
55973 + if (inodev != NULL)
55974 + do_handle_delete(inodev, ino, dev);
55975 + write_unlock(&gr_inode_lock);
55976 +
55977 + return;
55978 +}
55979 +
55980 +static void
55981 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
55982 + const ino_t newinode, const dev_t newdevice,
55983 + struct acl_subject_label *subj)
55984 +{
55985 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
55986 + struct acl_object_label *match;
55987 +
55988 + match = subj->obj_hash[index];
55989 +
55990 + while (match && (match->inode != oldinode ||
55991 + match->device != olddevice ||
55992 + !(match->mode & GR_DELETED)))
55993 + match = match->next;
55994 +
55995 + if (match && (match->inode == oldinode)
55996 + && (match->device == olddevice)
55997 + && (match->mode & GR_DELETED)) {
55998 + if (match->prev == NULL) {
55999 + subj->obj_hash[index] = match->next;
56000 + if (match->next != NULL)
56001 + match->next->prev = NULL;
56002 + } else {
56003 + match->prev->next = match->next;
56004 + if (match->next != NULL)
56005 + match->next->prev = match->prev;
56006 + }
56007 + match->prev = NULL;
56008 + match->next = NULL;
56009 + match->inode = newinode;
56010 + match->device = newdevice;
56011 + match->mode &= ~GR_DELETED;
56012 +
56013 + insert_acl_obj_label(match, subj);
56014 + }
56015 +
56016 + return;
56017 +}
56018 +
56019 +static void
56020 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56021 + const ino_t newinode, const dev_t newdevice,
56022 + struct acl_role_label *role)
56023 +{
56024 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56025 + struct acl_subject_label *match;
56026 +
56027 + match = role->subj_hash[index];
56028 +
56029 + while (match && (match->inode != oldinode ||
56030 + match->device != olddevice ||
56031 + !(match->mode & GR_DELETED)))
56032 + match = match->next;
56033 +
56034 + if (match && (match->inode == oldinode)
56035 + && (match->device == olddevice)
56036 + && (match->mode & GR_DELETED)) {
56037 + if (match->prev == NULL) {
56038 + role->subj_hash[index] = match->next;
56039 + if (match->next != NULL)
56040 + match->next->prev = NULL;
56041 + } else {
56042 + match->prev->next = match->next;
56043 + if (match->next != NULL)
56044 + match->next->prev = match->prev;
56045 + }
56046 + match->prev = NULL;
56047 + match->next = NULL;
56048 + match->inode = newinode;
56049 + match->device = newdevice;
56050 + match->mode &= ~GR_DELETED;
56051 +
56052 + insert_acl_subj_label(match, role);
56053 + }
56054 +
56055 + return;
56056 +}
56057 +
56058 +static void
56059 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56060 + const ino_t newinode, const dev_t newdevice)
56061 +{
56062 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56063 + struct inodev_entry *match;
56064 +
56065 + match = inodev_set.i_hash[index];
56066 +
56067 + while (match && (match->nentry->inode != oldinode ||
56068 + match->nentry->device != olddevice || !match->nentry->deleted))
56069 + match = match->next;
56070 +
56071 + if (match && (match->nentry->inode == oldinode)
56072 + && (match->nentry->device == olddevice) &&
56073 + match->nentry->deleted) {
56074 + if (match->prev == NULL) {
56075 + inodev_set.i_hash[index] = match->next;
56076 + if (match->next != NULL)
56077 + match->next->prev = NULL;
56078 + } else {
56079 + match->prev->next = match->next;
56080 + if (match->next != NULL)
56081 + match->next->prev = match->prev;
56082 + }
56083 + match->prev = NULL;
56084 + match->next = NULL;
56085 + match->nentry->inode = newinode;
56086 + match->nentry->device = newdevice;
56087 + match->nentry->deleted = 0;
56088 +
56089 + insert_inodev_entry(match);
56090 + }
56091 +
56092 + return;
56093 +}
56094 +
56095 +static void
56096 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56097 +{
56098 + struct acl_subject_label *subj;
56099 + struct acl_role_label *role;
56100 + unsigned int x;
56101 +
56102 + FOR_EACH_ROLE_START(role)
56103 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56104 +
56105 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56106 + if ((subj->inode == ino) && (subj->device == dev)) {
56107 + subj->inode = ino;
56108 + subj->device = dev;
56109 + }
56110 + /* nested subjects aren't in the role's subj_hash table */
56111 + update_acl_obj_label(matchn->inode, matchn->device,
56112 + ino, dev, subj);
56113 + FOR_EACH_NESTED_SUBJECT_END(subj)
56114 + FOR_EACH_SUBJECT_START(role, subj, x)
56115 + update_acl_obj_label(matchn->inode, matchn->device,
56116 + ino, dev, subj);
56117 + FOR_EACH_SUBJECT_END(subj,x)
56118 + FOR_EACH_ROLE_END(role)
56119 +
56120 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56121 +
56122 + return;
56123 +}
56124 +
56125 +static void
56126 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56127 + const struct vfsmount *mnt)
56128 +{
56129 + ino_t ino = dentry->d_inode->i_ino;
56130 + dev_t dev = __get_dev(dentry);
56131 +
56132 + __do_handle_create(matchn, ino, dev);
56133 +
56134 + return;
56135 +}
56136 +
56137 +void
56138 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56139 +{
56140 + struct name_entry *matchn;
56141 +
56142 + if (unlikely(!(gr_status & GR_READY)))
56143 + return;
56144 +
56145 + preempt_disable();
56146 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56147 +
56148 + if (unlikely((unsigned long)matchn)) {
56149 + write_lock(&gr_inode_lock);
56150 + do_handle_create(matchn, dentry, mnt);
56151 + write_unlock(&gr_inode_lock);
56152 + }
56153 + preempt_enable();
56154 +
56155 + return;
56156 +}
56157 +
56158 +void
56159 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56160 +{
56161 + struct name_entry *matchn;
56162 +
56163 + if (unlikely(!(gr_status & GR_READY)))
56164 + return;
56165 +
56166 + preempt_disable();
56167 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56168 +
56169 + if (unlikely((unsigned long)matchn)) {
56170 + write_lock(&gr_inode_lock);
56171 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56172 + write_unlock(&gr_inode_lock);
56173 + }
56174 + preempt_enable();
56175 +
56176 + return;
56177 +}
56178 +
56179 +void
56180 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56181 + struct dentry *old_dentry,
56182 + struct dentry *new_dentry,
56183 + struct vfsmount *mnt, const __u8 replace)
56184 +{
56185 + struct name_entry *matchn;
56186 + struct inodev_entry *inodev;
56187 + struct inode *inode = new_dentry->d_inode;
56188 + ino_t old_ino = old_dentry->d_inode->i_ino;
56189 + dev_t old_dev = __get_dev(old_dentry);
56190 +
56191 + /* vfs_rename swaps the name and parent link for old_dentry and
56192 + new_dentry
56193 + at this point, old_dentry has the new name, parent link, and inode
56194 + for the renamed file
56195 + if a file is being replaced by a rename, new_dentry has the inode
56196 + and name for the replaced file
56197 + */
56198 +
56199 + if (unlikely(!(gr_status & GR_READY)))
56200 + return;
56201 +
56202 + preempt_disable();
56203 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56204 +
56205 + /* we wouldn't have to check d_inode if it weren't for
56206 + NFS silly-renaming
56207 + */
56208 +
56209 + write_lock(&gr_inode_lock);
56210 + if (unlikely(replace && inode)) {
56211 + ino_t new_ino = inode->i_ino;
56212 + dev_t new_dev = __get_dev(new_dentry);
56213 +
56214 + inodev = lookup_inodev_entry(new_ino, new_dev);
56215 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56216 + do_handle_delete(inodev, new_ino, new_dev);
56217 + }
56218 +
56219 + inodev = lookup_inodev_entry(old_ino, old_dev);
56220 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56221 + do_handle_delete(inodev, old_ino, old_dev);
56222 +
56223 + if (unlikely((unsigned long)matchn))
56224 + do_handle_create(matchn, old_dentry, mnt);
56225 +
56226 + write_unlock(&gr_inode_lock);
56227 + preempt_enable();
56228 +
56229 + return;
56230 +}
56231 +
56232 +static int
56233 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56234 + unsigned char **sum)
56235 +{
56236 + struct acl_role_label *r;
56237 + struct role_allowed_ip *ipp;
56238 + struct role_transition *trans;
56239 + unsigned int i;
56240 + int found = 0;
56241 + u32 curr_ip = current->signal->curr_ip;
56242 +
56243 + current->signal->saved_ip = curr_ip;
56244 +
56245 + /* check transition table */
56246 +
56247 + for (trans = current->role->transitions; trans; trans = trans->next) {
56248 + if (!strcmp(rolename, trans->rolename)) {
56249 + found = 1;
56250 + break;
56251 + }
56252 + }
56253 +
56254 + if (!found)
56255 + return 0;
56256 +
56257 + /* handle special roles that do not require authentication
56258 + and check ip */
56259 +
56260 + FOR_EACH_ROLE_START(r)
56261 + if (!strcmp(rolename, r->rolename) &&
56262 + (r->roletype & GR_ROLE_SPECIAL)) {
56263 + found = 0;
56264 + if (r->allowed_ips != NULL) {
56265 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56266 + if ((ntohl(curr_ip) & ipp->netmask) ==
56267 + (ntohl(ipp->addr) & ipp->netmask))
56268 + found = 1;
56269 + }
56270 + } else
56271 + found = 2;
56272 + if (!found)
56273 + return 0;
56274 +
56275 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56276 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56277 + *salt = NULL;
56278 + *sum = NULL;
56279 + return 1;
56280 + }
56281 + }
56282 + FOR_EACH_ROLE_END(r)
56283 +
56284 + for (i = 0; i < num_sprole_pws; i++) {
56285 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56286 + *salt = acl_special_roles[i]->salt;
56287 + *sum = acl_special_roles[i]->sum;
56288 + return 1;
56289 + }
56290 + }
56291 +
56292 + return 0;
56293 +}
56294 +
56295 +static void
56296 +assign_special_role(char *rolename)
56297 +{
56298 + struct acl_object_label *obj;
56299 + struct acl_role_label *r;
56300 + struct acl_role_label *assigned = NULL;
56301 + struct task_struct *tsk;
56302 + struct file *filp;
56303 +
56304 + FOR_EACH_ROLE_START(r)
56305 + if (!strcmp(rolename, r->rolename) &&
56306 + (r->roletype & GR_ROLE_SPECIAL)) {
56307 + assigned = r;
56308 + break;
56309 + }
56310 + FOR_EACH_ROLE_END(r)
56311 +
56312 + if (!assigned)
56313 + return;
56314 +
56315 + read_lock(&tasklist_lock);
56316 + read_lock(&grsec_exec_file_lock);
56317 +
56318 + tsk = current->real_parent;
56319 + if (tsk == NULL)
56320 + goto out_unlock;
56321 +
56322 + filp = tsk->exec_file;
56323 + if (filp == NULL)
56324 + goto out_unlock;
56325 +
56326 + tsk->is_writable = 0;
56327 +
56328 + tsk->acl_sp_role = 1;
56329 + tsk->acl_role_id = ++acl_sp_role_value;
56330 + tsk->role = assigned;
56331 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56332 +
56333 + /* ignore additional mmap checks for processes that are writable
56334 + by the default ACL */
56335 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56336 + if (unlikely(obj->mode & GR_WRITE))
56337 + tsk->is_writable = 1;
56338 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56339 + if (unlikely(obj->mode & GR_WRITE))
56340 + tsk->is_writable = 1;
56341 +
56342 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56343 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56344 +#endif
56345 +
56346 +out_unlock:
56347 + read_unlock(&grsec_exec_file_lock);
56348 + read_unlock(&tasklist_lock);
56349 + return;
56350 +}
56351 +
56352 +int gr_check_secure_terminal(struct task_struct *task)
56353 +{
56354 + struct task_struct *p, *p2, *p3;
56355 + struct files_struct *files;
56356 + struct fdtable *fdt;
56357 + struct file *our_file = NULL, *file;
56358 + int i;
56359 +
56360 + if (task->signal->tty == NULL)
56361 + return 1;
56362 +
56363 + files = get_files_struct(task);
56364 + if (files != NULL) {
56365 + rcu_read_lock();
56366 + fdt = files_fdtable(files);
56367 + for (i=0; i < fdt->max_fds; i++) {
56368 + file = fcheck_files(files, i);
56369 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56370 + get_file(file);
56371 + our_file = file;
56372 + }
56373 + }
56374 + rcu_read_unlock();
56375 + put_files_struct(files);
56376 + }
56377 +
56378 + if (our_file == NULL)
56379 + return 1;
56380 +
56381 + read_lock(&tasklist_lock);
56382 + do_each_thread(p2, p) {
56383 + files = get_files_struct(p);
56384 + if (files == NULL ||
56385 + (p->signal && p->signal->tty == task->signal->tty)) {
56386 + if (files != NULL)
56387 + put_files_struct(files);
56388 + continue;
56389 + }
56390 + rcu_read_lock();
56391 + fdt = files_fdtable(files);
56392 + for (i=0; i < fdt->max_fds; i++) {
56393 + file = fcheck_files(files, i);
56394 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56395 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56396 + p3 = task;
56397 + while (p3->pid > 0) {
56398 + if (p3 == p)
56399 + break;
56400 + p3 = p3->real_parent;
56401 + }
56402 + if (p3 == p)
56403 + break;
56404 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56405 + gr_handle_alertkill(p);
56406 + rcu_read_unlock();
56407 + put_files_struct(files);
56408 + read_unlock(&tasklist_lock);
56409 + fput(our_file);
56410 + return 0;
56411 + }
56412 + }
56413 + rcu_read_unlock();
56414 + put_files_struct(files);
56415 + } while_each_thread(p2, p);
56416 + read_unlock(&tasklist_lock);
56417 +
56418 + fput(our_file);
56419 + return 1;
56420 +}
56421 +
56422 +static int gr_rbac_disable(void *unused)
56423 +{
56424 + pax_open_kernel();
56425 + gr_status &= ~GR_READY;
56426 + pax_close_kernel();
56427 +
56428 + return 0;
56429 +}
56430 +
56431 +ssize_t
56432 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56433 +{
56434 + struct gr_arg_wrapper uwrap;
56435 + unsigned char *sprole_salt = NULL;
56436 + unsigned char *sprole_sum = NULL;
56437 + int error = sizeof (struct gr_arg_wrapper);
56438 + int error2 = 0;
56439 +
56440 + mutex_lock(&gr_dev_mutex);
56441 +
56442 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56443 + error = -EPERM;
56444 + goto out;
56445 + }
56446 +
56447 + if (count != sizeof (struct gr_arg_wrapper)) {
56448 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56449 + error = -EINVAL;
56450 + goto out;
56451 + }
56452 +
56453 +
56454 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56455 + gr_auth_expires = 0;
56456 + gr_auth_attempts = 0;
56457 + }
56458 +
56459 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56460 + error = -EFAULT;
56461 + goto out;
56462 + }
56463 +
56464 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56465 + error = -EINVAL;
56466 + goto out;
56467 + }
56468 +
56469 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56470 + error = -EFAULT;
56471 + goto out;
56472 + }
56473 +
56474 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56475 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56476 + time_after(gr_auth_expires, get_seconds())) {
56477 + error = -EBUSY;
56478 + goto out;
56479 + }
56480 +
56481 + /* if non-root trying to do anything other than use a special role,
56482 + do not attempt authentication, do not count towards authentication
56483 + locking
56484 + */
56485 +
56486 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56487 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56488 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56489 + error = -EPERM;
56490 + goto out;
56491 + }
56492 +
56493 + /* ensure pw and special role name are null terminated */
56494 +
56495 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56496 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56497 +
56498 + /* Okay.
56499 + * We have our enough of the argument structure..(we have yet
56500 + * to copy_from_user the tables themselves) . Copy the tables
56501 + * only if we need them, i.e. for loading operations. */
56502 +
56503 + switch (gr_usermode->mode) {
56504 + case GR_STATUS:
56505 + if (gr_status & GR_READY) {
56506 + error = 1;
56507 + if (!gr_check_secure_terminal(current))
56508 + error = 3;
56509 + } else
56510 + error = 2;
56511 + goto out;
56512 + case GR_SHUTDOWN:
56513 + if ((gr_status & GR_READY)
56514 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56515 + stop_machine(gr_rbac_disable, NULL, NULL);
56516 + free_variables();
56517 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56518 + memset(gr_system_salt, 0, GR_SALT_LEN);
56519 + memset(gr_system_sum, 0, GR_SHA_LEN);
56520 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56521 + } else if (gr_status & GR_READY) {
56522 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56523 + error = -EPERM;
56524 + } else {
56525 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56526 + error = -EAGAIN;
56527 + }
56528 + break;
56529 + case GR_ENABLE:
56530 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56531 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56532 + else {
56533 + if (gr_status & GR_READY)
56534 + error = -EAGAIN;
56535 + else
56536 + error = error2;
56537 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56538 + }
56539 + break;
56540 + case GR_RELOAD:
56541 + if (!(gr_status & GR_READY)) {
56542 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56543 + error = -EAGAIN;
56544 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56545 + stop_machine(gr_rbac_disable, NULL, NULL);
56546 + free_variables();
56547 + error2 = gracl_init(gr_usermode);
56548 + if (!error2)
56549 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56550 + else {
56551 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56552 + error = error2;
56553 + }
56554 + } else {
56555 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56556 + error = -EPERM;
56557 + }
56558 + break;
56559 + case GR_SEGVMOD:
56560 + if (unlikely(!(gr_status & GR_READY))) {
56561 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56562 + error = -EAGAIN;
56563 + break;
56564 + }
56565 +
56566 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56567 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56568 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56569 + struct acl_subject_label *segvacl;
56570 + segvacl =
56571 + lookup_acl_subj_label(gr_usermode->segv_inode,
56572 + gr_usermode->segv_device,
56573 + current->role);
56574 + if (segvacl) {
56575 + segvacl->crashes = 0;
56576 + segvacl->expires = 0;
56577 + }
56578 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56579 + gr_remove_uid(gr_usermode->segv_uid);
56580 + }
56581 + } else {
56582 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56583 + error = -EPERM;
56584 + }
56585 + break;
56586 + case GR_SPROLE:
56587 + case GR_SPROLEPAM:
56588 + if (unlikely(!(gr_status & GR_READY))) {
56589 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56590 + error = -EAGAIN;
56591 + break;
56592 + }
56593 +
56594 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56595 + current->role->expires = 0;
56596 + current->role->auth_attempts = 0;
56597 + }
56598 +
56599 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56600 + time_after(current->role->expires, get_seconds())) {
56601 + error = -EBUSY;
56602 + goto out;
56603 + }
56604 +
56605 + if (lookup_special_role_auth
56606 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56607 + && ((!sprole_salt && !sprole_sum)
56608 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56609 + char *p = "";
56610 + assign_special_role(gr_usermode->sp_role);
56611 + read_lock(&tasklist_lock);
56612 + if (current->real_parent)
56613 + p = current->real_parent->role->rolename;
56614 + read_unlock(&tasklist_lock);
56615 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56616 + p, acl_sp_role_value);
56617 + } else {
56618 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56619 + error = -EPERM;
56620 + if(!(current->role->auth_attempts++))
56621 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56622 +
56623 + goto out;
56624 + }
56625 + break;
56626 + case GR_UNSPROLE:
56627 + if (unlikely(!(gr_status & GR_READY))) {
56628 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56629 + error = -EAGAIN;
56630 + break;
56631 + }
56632 +
56633 + if (current->role->roletype & GR_ROLE_SPECIAL) {
56634 + char *p = "";
56635 + int i = 0;
56636 +
56637 + read_lock(&tasklist_lock);
56638 + if (current->real_parent) {
56639 + p = current->real_parent->role->rolename;
56640 + i = current->real_parent->acl_role_id;
56641 + }
56642 + read_unlock(&tasklist_lock);
56643 +
56644 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56645 + gr_set_acls(1);
56646 + } else {
56647 + error = -EPERM;
56648 + goto out;
56649 + }
56650 + break;
56651 + default:
56652 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56653 + error = -EINVAL;
56654 + break;
56655 + }
56656 +
56657 + if (error != -EPERM)
56658 + goto out;
56659 +
56660 + if(!(gr_auth_attempts++))
56661 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56662 +
56663 + out:
56664 + mutex_unlock(&gr_dev_mutex);
56665 + return error;
56666 +}
56667 +
56668 +/* must be called with
56669 + rcu_read_lock();
56670 + read_lock(&tasklist_lock);
56671 + read_lock(&grsec_exec_file_lock);
56672 +*/
56673 +int gr_apply_subject_to_task(struct task_struct *task)
56674 +{
56675 + struct acl_object_label *obj;
56676 + char *tmpname;
56677 + struct acl_subject_label *tmpsubj;
56678 + struct file *filp;
56679 + struct name_entry *nmatch;
56680 +
56681 + filp = task->exec_file;
56682 + if (filp == NULL)
56683 + return 0;
56684 +
56685 + /* the following is to apply the correct subject
56686 + on binaries running when the RBAC system
56687 + is enabled, when the binaries have been
56688 + replaced or deleted since their execution
56689 + -----
56690 + when the RBAC system starts, the inode/dev
56691 + from exec_file will be one the RBAC system
56692 + is unaware of. It only knows the inode/dev
56693 + of the present file on disk, or the absence
56694 + of it.
56695 + */
56696 + preempt_disable();
56697 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56698 +
56699 + nmatch = lookup_name_entry(tmpname);
56700 + preempt_enable();
56701 + tmpsubj = NULL;
56702 + if (nmatch) {
56703 + if (nmatch->deleted)
56704 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56705 + else
56706 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56707 + if (tmpsubj != NULL)
56708 + task->acl = tmpsubj;
56709 + }
56710 + if (tmpsubj == NULL)
56711 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56712 + task->role);
56713 + if (task->acl) {
56714 + task->is_writable = 0;
56715 + /* ignore additional mmap checks for processes that are writable
56716 + by the default ACL */
56717 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56718 + if (unlikely(obj->mode & GR_WRITE))
56719 + task->is_writable = 1;
56720 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56721 + if (unlikely(obj->mode & GR_WRITE))
56722 + task->is_writable = 1;
56723 +
56724 + gr_set_proc_res(task);
56725 +
56726 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56727 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56728 +#endif
56729 + } else {
56730 + return 1;
56731 + }
56732 +
56733 + return 0;
56734 +}
56735 +
56736 +int
56737 +gr_set_acls(const int type)
56738 +{
56739 + struct task_struct *task, *task2;
56740 + struct acl_role_label *role = current->role;
56741 + __u16 acl_role_id = current->acl_role_id;
56742 + const struct cred *cred;
56743 + int ret;
56744 +
56745 + rcu_read_lock();
56746 + read_lock(&tasklist_lock);
56747 + read_lock(&grsec_exec_file_lock);
56748 + do_each_thread(task2, task) {
56749 + /* check to see if we're called from the exit handler,
56750 + if so, only replace ACLs that have inherited the admin
56751 + ACL */
56752 +
56753 + if (type && (task->role != role ||
56754 + task->acl_role_id != acl_role_id))
56755 + continue;
56756 +
56757 + task->acl_role_id = 0;
56758 + task->acl_sp_role = 0;
56759 +
56760 + if (task->exec_file) {
56761 + cred = __task_cred(task);
56762 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
56763 + ret = gr_apply_subject_to_task(task);
56764 + if (ret) {
56765 + read_unlock(&grsec_exec_file_lock);
56766 + read_unlock(&tasklist_lock);
56767 + rcu_read_unlock();
56768 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
56769 + return ret;
56770 + }
56771 + } else {
56772 + // it's a kernel process
56773 + task->role = kernel_role;
56774 + task->acl = kernel_role->root_label;
56775 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
56776 + task->acl->mode &= ~GR_PROCFIND;
56777 +#endif
56778 + }
56779 + } while_each_thread(task2, task);
56780 + read_unlock(&grsec_exec_file_lock);
56781 + read_unlock(&tasklist_lock);
56782 + rcu_read_unlock();
56783 +
56784 + return 0;
56785 +}
56786 +
56787 +void
56788 +gr_learn_resource(const struct task_struct *task,
56789 + const int res, const unsigned long wanted, const int gt)
56790 +{
56791 + struct acl_subject_label *acl;
56792 + const struct cred *cred;
56793 +
56794 + if (unlikely((gr_status & GR_READY) &&
56795 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
56796 + goto skip_reslog;
56797 +
56798 +#ifdef CONFIG_GRKERNSEC_RESLOG
56799 + gr_log_resource(task, res, wanted, gt);
56800 +#endif
56801 + skip_reslog:
56802 +
56803 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
56804 + return;
56805 +
56806 + acl = task->acl;
56807 +
56808 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
56809 + !(acl->resmask & (1 << (unsigned short) res))))
56810 + return;
56811 +
56812 + if (wanted >= acl->res[res].rlim_cur) {
56813 + unsigned long res_add;
56814 +
56815 + res_add = wanted;
56816 + switch (res) {
56817 + case RLIMIT_CPU:
56818 + res_add += GR_RLIM_CPU_BUMP;
56819 + break;
56820 + case RLIMIT_FSIZE:
56821 + res_add += GR_RLIM_FSIZE_BUMP;
56822 + break;
56823 + case RLIMIT_DATA:
56824 + res_add += GR_RLIM_DATA_BUMP;
56825 + break;
56826 + case RLIMIT_STACK:
56827 + res_add += GR_RLIM_STACK_BUMP;
56828 + break;
56829 + case RLIMIT_CORE:
56830 + res_add += GR_RLIM_CORE_BUMP;
56831 + break;
56832 + case RLIMIT_RSS:
56833 + res_add += GR_RLIM_RSS_BUMP;
56834 + break;
56835 + case RLIMIT_NPROC:
56836 + res_add += GR_RLIM_NPROC_BUMP;
56837 + break;
56838 + case RLIMIT_NOFILE:
56839 + res_add += GR_RLIM_NOFILE_BUMP;
56840 + break;
56841 + case RLIMIT_MEMLOCK:
56842 + res_add += GR_RLIM_MEMLOCK_BUMP;
56843 + break;
56844 + case RLIMIT_AS:
56845 + res_add += GR_RLIM_AS_BUMP;
56846 + break;
56847 + case RLIMIT_LOCKS:
56848 + res_add += GR_RLIM_LOCKS_BUMP;
56849 + break;
56850 + case RLIMIT_SIGPENDING:
56851 + res_add += GR_RLIM_SIGPENDING_BUMP;
56852 + break;
56853 + case RLIMIT_MSGQUEUE:
56854 + res_add += GR_RLIM_MSGQUEUE_BUMP;
56855 + break;
56856 + case RLIMIT_NICE:
56857 + res_add += GR_RLIM_NICE_BUMP;
56858 + break;
56859 + case RLIMIT_RTPRIO:
56860 + res_add += GR_RLIM_RTPRIO_BUMP;
56861 + break;
56862 + case RLIMIT_RTTIME:
56863 + res_add += GR_RLIM_RTTIME_BUMP;
56864 + break;
56865 + }
56866 +
56867 + acl->res[res].rlim_cur = res_add;
56868 +
56869 + if (wanted > acl->res[res].rlim_max)
56870 + acl->res[res].rlim_max = res_add;
56871 +
56872 + /* only log the subject filename, since resource logging is supported for
56873 + single-subject learning only */
56874 + rcu_read_lock();
56875 + cred = __task_cred(task);
56876 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56877 + task->role->roletype, cred->uid, cred->gid, acl->filename,
56878 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
56879 + "", (unsigned long) res, &task->signal->saved_ip);
56880 + rcu_read_unlock();
56881 + }
56882 +
56883 + return;
56884 +}
56885 +
56886 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
56887 +void
56888 +pax_set_initial_flags(struct linux_binprm *bprm)
56889 +{
56890 + struct task_struct *task = current;
56891 + struct acl_subject_label *proc;
56892 + unsigned long flags;
56893 +
56894 + if (unlikely(!(gr_status & GR_READY)))
56895 + return;
56896 +
56897 + flags = pax_get_flags(task);
56898 +
56899 + proc = task->acl;
56900 +
56901 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
56902 + flags &= ~MF_PAX_PAGEEXEC;
56903 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
56904 + flags &= ~MF_PAX_SEGMEXEC;
56905 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
56906 + flags &= ~MF_PAX_RANDMMAP;
56907 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
56908 + flags &= ~MF_PAX_EMUTRAMP;
56909 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
56910 + flags &= ~MF_PAX_MPROTECT;
56911 +
56912 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
56913 + flags |= MF_PAX_PAGEEXEC;
56914 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
56915 + flags |= MF_PAX_SEGMEXEC;
56916 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
56917 + flags |= MF_PAX_RANDMMAP;
56918 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
56919 + flags |= MF_PAX_EMUTRAMP;
56920 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
56921 + flags |= MF_PAX_MPROTECT;
56922 +
56923 + pax_set_flags(task, flags);
56924 +
56925 + return;
56926 +}
56927 +#endif
56928 +
56929 +int
56930 +gr_handle_proc_ptrace(struct task_struct *task)
56931 +{
56932 + struct file *filp;
56933 + struct task_struct *tmp = task;
56934 + struct task_struct *curtemp = current;
56935 + __u32 retmode;
56936 +
56937 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56938 + if (unlikely(!(gr_status & GR_READY)))
56939 + return 0;
56940 +#endif
56941 +
56942 + read_lock(&tasklist_lock);
56943 + read_lock(&grsec_exec_file_lock);
56944 + filp = task->exec_file;
56945 +
56946 + while (tmp->pid > 0) {
56947 + if (tmp == curtemp)
56948 + break;
56949 + tmp = tmp->real_parent;
56950 + }
56951 +
56952 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56953 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
56954 + read_unlock(&grsec_exec_file_lock);
56955 + read_unlock(&tasklist_lock);
56956 + return 1;
56957 + }
56958 +
56959 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56960 + if (!(gr_status & GR_READY)) {
56961 + read_unlock(&grsec_exec_file_lock);
56962 + read_unlock(&tasklist_lock);
56963 + return 0;
56964 + }
56965 +#endif
56966 +
56967 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
56968 + read_unlock(&grsec_exec_file_lock);
56969 + read_unlock(&tasklist_lock);
56970 +
56971 + if (retmode & GR_NOPTRACE)
56972 + return 1;
56973 +
56974 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
56975 + && (current->acl != task->acl || (current->acl != current->role->root_label
56976 + && current->pid != task->pid)))
56977 + return 1;
56978 +
56979 + return 0;
56980 +}
56981 +
56982 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
56983 +{
56984 + if (unlikely(!(gr_status & GR_READY)))
56985 + return;
56986 +
56987 + if (!(current->role->roletype & GR_ROLE_GOD))
56988 + return;
56989 +
56990 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
56991 + p->role->rolename, gr_task_roletype_to_char(p),
56992 + p->acl->filename);
56993 +}
56994 +
56995 +int
56996 +gr_handle_ptrace(struct task_struct *task, const long request)
56997 +{
56998 + struct task_struct *tmp = task;
56999 + struct task_struct *curtemp = current;
57000 + __u32 retmode;
57001 +
57002 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57003 + if (unlikely(!(gr_status & GR_READY)))
57004 + return 0;
57005 +#endif
57006 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57007 + read_lock(&tasklist_lock);
57008 + while (tmp->pid > 0) {
57009 + if (tmp == curtemp)
57010 + break;
57011 + tmp = tmp->real_parent;
57012 + }
57013 +
57014 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57015 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57016 + read_unlock(&tasklist_lock);
57017 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57018 + return 1;
57019 + }
57020 + read_unlock(&tasklist_lock);
57021 + }
57022 +
57023 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57024 + if (!(gr_status & GR_READY))
57025 + return 0;
57026 +#endif
57027 +
57028 + read_lock(&grsec_exec_file_lock);
57029 + if (unlikely(!task->exec_file)) {
57030 + read_unlock(&grsec_exec_file_lock);
57031 + return 0;
57032 + }
57033 +
57034 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57035 + read_unlock(&grsec_exec_file_lock);
57036 +
57037 + if (retmode & GR_NOPTRACE) {
57038 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57039 + return 1;
57040 + }
57041 +
57042 + if (retmode & GR_PTRACERD) {
57043 + switch (request) {
57044 + case PTRACE_SEIZE:
57045 + case PTRACE_POKETEXT:
57046 + case PTRACE_POKEDATA:
57047 + case PTRACE_POKEUSR:
57048 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57049 + case PTRACE_SETREGS:
57050 + case PTRACE_SETFPREGS:
57051 +#endif
57052 +#ifdef CONFIG_X86
57053 + case PTRACE_SETFPXREGS:
57054 +#endif
57055 +#ifdef CONFIG_ALTIVEC
57056 + case PTRACE_SETVRREGS:
57057 +#endif
57058 + return 1;
57059 + default:
57060 + return 0;
57061 + }
57062 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
57063 + !(current->role->roletype & GR_ROLE_GOD) &&
57064 + (current->acl != task->acl)) {
57065 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57066 + return 1;
57067 + }
57068 +
57069 + return 0;
57070 +}
57071 +
57072 +static int is_writable_mmap(const struct file *filp)
57073 +{
57074 + struct task_struct *task = current;
57075 + struct acl_object_label *obj, *obj2;
57076 +
57077 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57078 + !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))) {
57079 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57080 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57081 + task->role->root_label);
57082 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57083 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57084 + return 1;
57085 + }
57086 + }
57087 + return 0;
57088 +}
57089 +
57090 +int
57091 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57092 +{
57093 + __u32 mode;
57094 +
57095 + if (unlikely(!file || !(prot & PROT_EXEC)))
57096 + return 1;
57097 +
57098 + if (is_writable_mmap(file))
57099 + return 0;
57100 +
57101 + mode =
57102 + gr_search_file(file->f_path.dentry,
57103 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57104 + file->f_path.mnt);
57105 +
57106 + if (!gr_tpe_allow(file))
57107 + return 0;
57108 +
57109 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57110 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57111 + return 0;
57112 + } else if (unlikely(!(mode & GR_EXEC))) {
57113 + return 0;
57114 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57115 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57116 + return 1;
57117 + }
57118 +
57119 + return 1;
57120 +}
57121 +
57122 +int
57123 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57124 +{
57125 + __u32 mode;
57126 +
57127 + if (unlikely(!file || !(prot & PROT_EXEC)))
57128 + return 1;
57129 +
57130 + if (is_writable_mmap(file))
57131 + return 0;
57132 +
57133 + mode =
57134 + gr_search_file(file->f_path.dentry,
57135 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57136 + file->f_path.mnt);
57137 +
57138 + if (!gr_tpe_allow(file))
57139 + return 0;
57140 +
57141 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57142 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57143 + return 0;
57144 + } else if (unlikely(!(mode & GR_EXEC))) {
57145 + return 0;
57146 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57147 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57148 + return 1;
57149 + }
57150 +
57151 + return 1;
57152 +}
57153 +
57154 +void
57155 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57156 +{
57157 + unsigned long runtime;
57158 + unsigned long cputime;
57159 + unsigned int wday, cday;
57160 + __u8 whr, chr;
57161 + __u8 wmin, cmin;
57162 + __u8 wsec, csec;
57163 + struct timespec timeval;
57164 +
57165 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57166 + !(task->acl->mode & GR_PROCACCT)))
57167 + return;
57168 +
57169 + do_posix_clock_monotonic_gettime(&timeval);
57170 + runtime = timeval.tv_sec - task->start_time.tv_sec;
57171 + wday = runtime / (3600 * 24);
57172 + runtime -= wday * (3600 * 24);
57173 + whr = runtime / 3600;
57174 + runtime -= whr * 3600;
57175 + wmin = runtime / 60;
57176 + runtime -= wmin * 60;
57177 + wsec = runtime;
57178 +
57179 + cputime = (task->utime + task->stime) / HZ;
57180 + cday = cputime / (3600 * 24);
57181 + cputime -= cday * (3600 * 24);
57182 + chr = cputime / 3600;
57183 + cputime -= chr * 3600;
57184 + cmin = cputime / 60;
57185 + cputime -= cmin * 60;
57186 + csec = cputime;
57187 +
57188 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57189 +
57190 + return;
57191 +}
57192 +
57193 +void gr_set_kernel_label(struct task_struct *task)
57194 +{
57195 + if (gr_status & GR_READY) {
57196 + task->role = kernel_role;
57197 + task->acl = kernel_role->root_label;
57198 + }
57199 + return;
57200 +}
57201 +
57202 +#ifdef CONFIG_TASKSTATS
57203 +int gr_is_taskstats_denied(int pid)
57204 +{
57205 + struct task_struct *task;
57206 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57207 + const struct cred *cred;
57208 +#endif
57209 + int ret = 0;
57210 +
57211 + /* restrict taskstats viewing to un-chrooted root users
57212 + who have the 'view' subject flag if the RBAC system is enabled
57213 + */
57214 +
57215 + rcu_read_lock();
57216 + read_lock(&tasklist_lock);
57217 + task = find_task_by_vpid(pid);
57218 + if (task) {
57219 +#ifdef CONFIG_GRKERNSEC_CHROOT
57220 + if (proc_is_chrooted(task))
57221 + ret = -EACCES;
57222 +#endif
57223 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57224 + cred = __task_cred(task);
57225 +#ifdef CONFIG_GRKERNSEC_PROC_USER
57226 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57227 + ret = -EACCES;
57228 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57229 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57230 + ret = -EACCES;
57231 +#endif
57232 +#endif
57233 + if (gr_status & GR_READY) {
57234 + if (!(task->acl->mode & GR_VIEW))
57235 + ret = -EACCES;
57236 + }
57237 + } else
57238 + ret = -ENOENT;
57239 +
57240 + read_unlock(&tasklist_lock);
57241 + rcu_read_unlock();
57242 +
57243 + return ret;
57244 +}
57245 +#endif
57246 +
57247 +/* AUXV entries are filled via a descendant of search_binary_handler
57248 + after we've already applied the subject for the target
57249 +*/
57250 +int gr_acl_enable_at_secure(void)
57251 +{
57252 + if (unlikely(!(gr_status & GR_READY)))
57253 + return 0;
57254 +
57255 + if (current->acl->mode & GR_ATSECURE)
57256 + return 1;
57257 +
57258 + return 0;
57259 +}
57260 +
57261 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57262 +{
57263 + struct task_struct *task = current;
57264 + struct dentry *dentry = file->f_path.dentry;
57265 + struct vfsmount *mnt = file->f_path.mnt;
57266 + struct acl_object_label *obj, *tmp;
57267 + struct acl_subject_label *subj;
57268 + unsigned int bufsize;
57269 + int is_not_root;
57270 + char *path;
57271 + dev_t dev = __get_dev(dentry);
57272 +
57273 + if (unlikely(!(gr_status & GR_READY)))
57274 + return 1;
57275 +
57276 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57277 + return 1;
57278 +
57279 + /* ignore Eric Biederman */
57280 + if (IS_PRIVATE(dentry->d_inode))
57281 + return 1;
57282 +
57283 + subj = task->acl;
57284 + read_lock(&gr_inode_lock);
57285 + do {
57286 + obj = lookup_acl_obj_label(ino, dev, subj);
57287 + if (obj != NULL) {
57288 + read_unlock(&gr_inode_lock);
57289 + return (obj->mode & GR_FIND) ? 1 : 0;
57290 + }
57291 + } while ((subj = subj->parent_subject));
57292 + read_unlock(&gr_inode_lock);
57293 +
57294 + /* this is purely an optimization since we're looking for an object
57295 + for the directory we're doing a readdir on
57296 + if it's possible for any globbed object to match the entry we're
57297 + filling into the directory, then the object we find here will be
57298 + an anchor point with attached globbed objects
57299 + */
57300 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57301 + if (obj->globbed == NULL)
57302 + return (obj->mode & GR_FIND) ? 1 : 0;
57303 +
57304 + is_not_root = ((obj->filename[0] == '/') &&
57305 + (obj->filename[1] == '\0')) ? 0 : 1;
57306 + bufsize = PAGE_SIZE - namelen - is_not_root;
57307 +
57308 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
57309 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57310 + return 1;
57311 +
57312 + preempt_disable();
57313 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57314 + bufsize);
57315 +
57316 + bufsize = strlen(path);
57317 +
57318 + /* if base is "/", don't append an additional slash */
57319 + if (is_not_root)
57320 + *(path + bufsize) = '/';
57321 + memcpy(path + bufsize + is_not_root, name, namelen);
57322 + *(path + bufsize + namelen + is_not_root) = '\0';
57323 +
57324 + tmp = obj->globbed;
57325 + while (tmp) {
57326 + if (!glob_match(tmp->filename, path)) {
57327 + preempt_enable();
57328 + return (tmp->mode & GR_FIND) ? 1 : 0;
57329 + }
57330 + tmp = tmp->next;
57331 + }
57332 + preempt_enable();
57333 + return (obj->mode & GR_FIND) ? 1 : 0;
57334 +}
57335 +
57336 +void gr_put_exec_file(struct task_struct *task)
57337 +{
57338 + struct file *filp;
57339 +
57340 + write_lock(&grsec_exec_file_lock);
57341 + filp = task->exec_file;
57342 + task->exec_file = NULL;
57343 + write_unlock(&grsec_exec_file_lock);
57344 +
57345 + if (filp)
57346 + fput(filp);
57347 +
57348 + return;
57349 +}
57350 +
57351 +
57352 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57353 +EXPORT_SYMBOL(gr_acl_is_enabled);
57354 +#endif
57355 +EXPORT_SYMBOL(gr_learn_resource);
57356 +EXPORT_SYMBOL(gr_set_kernel_label);
57357 +#ifdef CONFIG_SECURITY
57358 +EXPORT_SYMBOL(gr_check_user_change);
57359 +EXPORT_SYMBOL(gr_check_group_change);
57360 +#endif
57361 +
57362 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57363 new file mode 100644
57364 index 0000000..34fefda
57365 --- /dev/null
57366 +++ b/grsecurity/gracl_alloc.c
57367 @@ -0,0 +1,105 @@
57368 +#include <linux/kernel.h>
57369 +#include <linux/mm.h>
57370 +#include <linux/slab.h>
57371 +#include <linux/vmalloc.h>
57372 +#include <linux/gracl.h>
57373 +#include <linux/grsecurity.h>
57374 +
57375 +static unsigned long alloc_stack_next = 1;
57376 +static unsigned long alloc_stack_size = 1;
57377 +static void **alloc_stack;
57378 +
57379 +static __inline__ int
57380 +alloc_pop(void)
57381 +{
57382 + if (alloc_stack_next == 1)
57383 + return 0;
57384 +
57385 + kfree(alloc_stack[alloc_stack_next - 2]);
57386 +
57387 + alloc_stack_next--;
57388 +
57389 + return 1;
57390 +}
57391 +
57392 +static __inline__ int
57393 +alloc_push(void *buf)
57394 +{
57395 + if (alloc_stack_next >= alloc_stack_size)
57396 + return 1;
57397 +
57398 + alloc_stack[alloc_stack_next - 1] = buf;
57399 +
57400 + alloc_stack_next++;
57401 +
57402 + return 0;
57403 +}
57404 +
57405 +void *
57406 +acl_alloc(unsigned long len)
57407 +{
57408 + void *ret = NULL;
57409 +
57410 + if (!len || len > PAGE_SIZE)
57411 + goto out;
57412 +
57413 + ret = kmalloc(len, GFP_KERNEL);
57414 +
57415 + if (ret) {
57416 + if (alloc_push(ret)) {
57417 + kfree(ret);
57418 + ret = NULL;
57419 + }
57420 + }
57421 +
57422 +out:
57423 + return ret;
57424 +}
57425 +
57426 +void *
57427 +acl_alloc_num(unsigned long num, unsigned long len)
57428 +{
57429 + if (!len || (num > (PAGE_SIZE / len)))
57430 + return NULL;
57431 +
57432 + return acl_alloc(num * len);
57433 +}
57434 +
57435 +void
57436 +acl_free_all(void)
57437 +{
57438 + if (gr_acl_is_enabled() || !alloc_stack)
57439 + return;
57440 +
57441 + while (alloc_pop()) ;
57442 +
57443 + if (alloc_stack) {
57444 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57445 + kfree(alloc_stack);
57446 + else
57447 + vfree(alloc_stack);
57448 + }
57449 +
57450 + alloc_stack = NULL;
57451 + alloc_stack_size = 1;
57452 + alloc_stack_next = 1;
57453 +
57454 + return;
57455 +}
57456 +
57457 +int
57458 +acl_alloc_stack_init(unsigned long size)
57459 +{
57460 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57461 + alloc_stack =
57462 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57463 + else
57464 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57465 +
57466 + alloc_stack_size = size;
57467 +
57468 + if (!alloc_stack)
57469 + return 0;
57470 + else
57471 + return 1;
57472 +}
57473 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57474 new file mode 100644
57475 index 0000000..6d21049
57476 --- /dev/null
57477 +++ b/grsecurity/gracl_cap.c
57478 @@ -0,0 +1,110 @@
57479 +#include <linux/kernel.h>
57480 +#include <linux/module.h>
57481 +#include <linux/sched.h>
57482 +#include <linux/gracl.h>
57483 +#include <linux/grsecurity.h>
57484 +#include <linux/grinternal.h>
57485 +
57486 +extern const char *captab_log[];
57487 +extern int captab_log_entries;
57488 +
57489 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57490 +{
57491 + struct acl_subject_label *curracl;
57492 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57493 + kernel_cap_t cap_audit = __cap_empty_set;
57494 +
57495 + if (!gr_acl_is_enabled())
57496 + return 1;
57497 +
57498 + curracl = task->acl;
57499 +
57500 + cap_drop = curracl->cap_lower;
57501 + cap_mask = curracl->cap_mask;
57502 + cap_audit = curracl->cap_invert_audit;
57503 +
57504 + while ((curracl = curracl->parent_subject)) {
57505 + /* if the cap isn't specified in the current computed mask but is specified in the
57506 + current level subject, and is lowered in the current level subject, then add
57507 + it to the set of dropped capabilities
57508 + otherwise, add the current level subject's mask to the current computed mask
57509 + */
57510 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57511 + cap_raise(cap_mask, cap);
57512 + if (cap_raised(curracl->cap_lower, cap))
57513 + cap_raise(cap_drop, cap);
57514 + if (cap_raised(curracl->cap_invert_audit, cap))
57515 + cap_raise(cap_audit, cap);
57516 + }
57517 + }
57518 +
57519 + if (!cap_raised(cap_drop, cap)) {
57520 + if (cap_raised(cap_audit, cap))
57521 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57522 + return 1;
57523 + }
57524 +
57525 + curracl = task->acl;
57526 +
57527 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57528 + && cap_raised(cred->cap_effective, cap)) {
57529 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57530 + task->role->roletype, cred->uid,
57531 + cred->gid, task->exec_file ?
57532 + gr_to_filename(task->exec_file->f_path.dentry,
57533 + task->exec_file->f_path.mnt) : curracl->filename,
57534 + curracl->filename, 0UL,
57535 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57536 + return 1;
57537 + }
57538 +
57539 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57540 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57541 +
57542 + return 0;
57543 +}
57544 +
57545 +int
57546 +gr_acl_is_capable(const int cap)
57547 +{
57548 + return gr_task_acl_is_capable(current, current_cred(), cap);
57549 +}
57550 +
57551 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57552 +{
57553 + struct acl_subject_label *curracl;
57554 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57555 +
57556 + if (!gr_acl_is_enabled())
57557 + return 1;
57558 +
57559 + curracl = task->acl;
57560 +
57561 + cap_drop = curracl->cap_lower;
57562 + cap_mask = curracl->cap_mask;
57563 +
57564 + while ((curracl = curracl->parent_subject)) {
57565 + /* if the cap isn't specified in the current computed mask but is specified in the
57566 + current level subject, and is lowered in the current level subject, then add
57567 + it to the set of dropped capabilities
57568 + otherwise, add the current level subject's mask to the current computed mask
57569 + */
57570 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57571 + cap_raise(cap_mask, cap);
57572 + if (cap_raised(curracl->cap_lower, cap))
57573 + cap_raise(cap_drop, cap);
57574 + }
57575 + }
57576 +
57577 + if (!cap_raised(cap_drop, cap))
57578 + return 1;
57579 +
57580 + return 0;
57581 +}
57582 +
57583 +int
57584 +gr_acl_is_capable_nolog(const int cap)
57585 +{
57586 + return gr_task_acl_is_capable_nolog(current, cap);
57587 +}
57588 +
57589 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57590 new file mode 100644
57591 index 0000000..a340c17
57592 --- /dev/null
57593 +++ b/grsecurity/gracl_fs.c
57594 @@ -0,0 +1,431 @@
57595 +#include <linux/kernel.h>
57596 +#include <linux/sched.h>
57597 +#include <linux/types.h>
57598 +#include <linux/fs.h>
57599 +#include <linux/file.h>
57600 +#include <linux/stat.h>
57601 +#include <linux/grsecurity.h>
57602 +#include <linux/grinternal.h>
57603 +#include <linux/gracl.h>
57604 +
57605 +umode_t
57606 +gr_acl_umask(void)
57607 +{
57608 + if (unlikely(!gr_acl_is_enabled()))
57609 + return 0;
57610 +
57611 + return current->role->umask;
57612 +}
57613 +
57614 +__u32
57615 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57616 + const struct vfsmount * mnt)
57617 +{
57618 + __u32 mode;
57619 +
57620 + if (unlikely(!dentry->d_inode))
57621 + return GR_FIND;
57622 +
57623 + mode =
57624 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57625 +
57626 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57627 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57628 + return mode;
57629 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57630 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57631 + return 0;
57632 + } else if (unlikely(!(mode & GR_FIND)))
57633 + return 0;
57634 +
57635 + return GR_FIND;
57636 +}
57637 +
57638 +__u32
57639 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57640 + int acc_mode)
57641 +{
57642 + __u32 reqmode = GR_FIND;
57643 + __u32 mode;
57644 +
57645 + if (unlikely(!dentry->d_inode))
57646 + return reqmode;
57647 +
57648 + if (acc_mode & MAY_APPEND)
57649 + reqmode |= GR_APPEND;
57650 + else if (acc_mode & MAY_WRITE)
57651 + reqmode |= GR_WRITE;
57652 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57653 + reqmode |= GR_READ;
57654 +
57655 + mode =
57656 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57657 + mnt);
57658 +
57659 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57660 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57661 + reqmode & GR_READ ? " reading" : "",
57662 + reqmode & GR_WRITE ? " writing" : reqmode &
57663 + GR_APPEND ? " appending" : "");
57664 + return reqmode;
57665 + } else
57666 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57667 + {
57668 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57669 + reqmode & GR_READ ? " reading" : "",
57670 + reqmode & GR_WRITE ? " writing" : reqmode &
57671 + GR_APPEND ? " appending" : "");
57672 + return 0;
57673 + } else if (unlikely((mode & reqmode) != reqmode))
57674 + return 0;
57675 +
57676 + return reqmode;
57677 +}
57678 +
57679 +__u32
57680 +gr_acl_handle_creat(const struct dentry * dentry,
57681 + const struct dentry * p_dentry,
57682 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57683 + const int imode)
57684 +{
57685 + __u32 reqmode = GR_WRITE | GR_CREATE;
57686 + __u32 mode;
57687 +
57688 + if (acc_mode & MAY_APPEND)
57689 + reqmode |= GR_APPEND;
57690 + // if a directory was required or the directory already exists, then
57691 + // don't count this open as a read
57692 + if ((acc_mode & MAY_READ) &&
57693 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57694 + reqmode |= GR_READ;
57695 + if ((open_flags & O_CREAT) &&
57696 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57697 + reqmode |= GR_SETID;
57698 +
57699 + mode =
57700 + gr_check_create(dentry, p_dentry, p_mnt,
57701 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57702 +
57703 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57704 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57705 + reqmode & GR_READ ? " reading" : "",
57706 + reqmode & GR_WRITE ? " writing" : reqmode &
57707 + GR_APPEND ? " appending" : "");
57708 + return reqmode;
57709 + } else
57710 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57711 + {
57712 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57713 + reqmode & GR_READ ? " reading" : "",
57714 + reqmode & GR_WRITE ? " writing" : reqmode &
57715 + GR_APPEND ? " appending" : "");
57716 + return 0;
57717 + } else if (unlikely((mode & reqmode) != reqmode))
57718 + return 0;
57719 +
57720 + return reqmode;
57721 +}
57722 +
57723 +__u32
57724 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57725 + const int fmode)
57726 +{
57727 + __u32 mode, reqmode = GR_FIND;
57728 +
57729 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57730 + reqmode |= GR_EXEC;
57731 + if (fmode & S_IWOTH)
57732 + reqmode |= GR_WRITE;
57733 + if (fmode & S_IROTH)
57734 + reqmode |= GR_READ;
57735 +
57736 + mode =
57737 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57738 + mnt);
57739 +
57740 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57741 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57742 + reqmode & GR_READ ? " reading" : "",
57743 + reqmode & GR_WRITE ? " writing" : "",
57744 + reqmode & GR_EXEC ? " executing" : "");
57745 + return reqmode;
57746 + } else
57747 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57748 + {
57749 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57750 + reqmode & GR_READ ? " reading" : "",
57751 + reqmode & GR_WRITE ? " writing" : "",
57752 + reqmode & GR_EXEC ? " executing" : "");
57753 + return 0;
57754 + } else if (unlikely((mode & reqmode) != reqmode))
57755 + return 0;
57756 +
57757 + return reqmode;
57758 +}
57759 +
57760 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57761 +{
57762 + __u32 mode;
57763 +
57764 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57765 +
57766 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57767 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57768 + return mode;
57769 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57770 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57771 + return 0;
57772 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
57773 + return 0;
57774 +
57775 + return (reqmode);
57776 +}
57777 +
57778 +__u32
57779 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57780 +{
57781 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57782 +}
57783 +
57784 +__u32
57785 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57786 +{
57787 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57788 +}
57789 +
57790 +__u32
57791 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
57792 +{
57793 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
57794 +}
57795 +
57796 +__u32
57797 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
57798 +{
57799 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
57800 +}
57801 +
57802 +__u32
57803 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
57804 + umode_t *modeptr)
57805 +{
57806 + umode_t mode;
57807 +
57808 + *modeptr &= ~gr_acl_umask();
57809 + mode = *modeptr;
57810 +
57811 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
57812 + return 1;
57813 +
57814 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
57815 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
57816 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
57817 + GR_CHMOD_ACL_MSG);
57818 + } else {
57819 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
57820 + }
57821 +}
57822 +
57823 +__u32
57824 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
57825 +{
57826 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
57827 +}
57828 +
57829 +__u32
57830 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
57831 +{
57832 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
57833 +}
57834 +
57835 +__u32
57836 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
57837 +{
57838 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
57839 +}
57840 +
57841 +__u32
57842 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
57843 +{
57844 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
57845 + GR_UNIXCONNECT_ACL_MSG);
57846 +}
57847 +
57848 +/* hardlinks require at minimum create and link permission,
57849 + any additional privilege required is based on the
57850 + privilege of the file being linked to
57851 +*/
57852 +__u32
57853 +gr_acl_handle_link(const struct dentry * new_dentry,
57854 + const struct dentry * parent_dentry,
57855 + const struct vfsmount * parent_mnt,
57856 + const struct dentry * old_dentry,
57857 + const struct vfsmount * old_mnt, const struct filename *to)
57858 +{
57859 + __u32 mode;
57860 + __u32 needmode = GR_CREATE | GR_LINK;
57861 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
57862 +
57863 + mode =
57864 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
57865 + old_mnt);
57866 +
57867 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
57868 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57869 + return mode;
57870 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57871 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57872 + return 0;
57873 + } else if (unlikely((mode & needmode) != needmode))
57874 + return 0;
57875 +
57876 + return 1;
57877 +}
57878 +
57879 +__u32
57880 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57881 + const struct dentry * parent_dentry,
57882 + const struct vfsmount * parent_mnt, const struct filename *from)
57883 +{
57884 + __u32 needmode = GR_WRITE | GR_CREATE;
57885 + __u32 mode;
57886 +
57887 + mode =
57888 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
57889 + GR_CREATE | GR_AUDIT_CREATE |
57890 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
57891 +
57892 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
57893 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57894 + return mode;
57895 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57896 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57897 + return 0;
57898 + } else if (unlikely((mode & needmode) != needmode))
57899 + return 0;
57900 +
57901 + return (GR_WRITE | GR_CREATE);
57902 +}
57903 +
57904 +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)
57905 +{
57906 + __u32 mode;
57907 +
57908 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57909 +
57910 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57911 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
57912 + return mode;
57913 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57914 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
57915 + return 0;
57916 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
57917 + return 0;
57918 +
57919 + return (reqmode);
57920 +}
57921 +
57922 +__u32
57923 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57924 + const struct dentry * parent_dentry,
57925 + const struct vfsmount * parent_mnt,
57926 + const int mode)
57927 +{
57928 + __u32 reqmode = GR_WRITE | GR_CREATE;
57929 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57930 + reqmode |= GR_SETID;
57931 +
57932 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57933 + reqmode, GR_MKNOD_ACL_MSG);
57934 +}
57935 +
57936 +__u32
57937 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
57938 + const struct dentry *parent_dentry,
57939 + const struct vfsmount *parent_mnt)
57940 +{
57941 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57942 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
57943 +}
57944 +
57945 +#define RENAME_CHECK_SUCCESS(old, new) \
57946 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
57947 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
57948 +
57949 +int
57950 +gr_acl_handle_rename(struct dentry *new_dentry,
57951 + struct dentry *parent_dentry,
57952 + const struct vfsmount *parent_mnt,
57953 + struct dentry *old_dentry,
57954 + struct inode *old_parent_inode,
57955 + struct vfsmount *old_mnt, const struct filename *newname)
57956 +{
57957 + __u32 comp1, comp2;
57958 + int error = 0;
57959 +
57960 + if (unlikely(!gr_acl_is_enabled()))
57961 + return 0;
57962 +
57963 + if (!new_dentry->d_inode) {
57964 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
57965 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
57966 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
57967 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
57968 + GR_DELETE | GR_AUDIT_DELETE |
57969 + GR_AUDIT_READ | GR_AUDIT_WRITE |
57970 + GR_SUPPRESS, old_mnt);
57971 + } else {
57972 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
57973 + GR_CREATE | GR_DELETE |
57974 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
57975 + GR_AUDIT_READ | GR_AUDIT_WRITE |
57976 + GR_SUPPRESS, parent_mnt);
57977 + comp2 =
57978 + gr_search_file(old_dentry,
57979 + GR_READ | GR_WRITE | GR_AUDIT_READ |
57980 + GR_DELETE | GR_AUDIT_DELETE |
57981 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
57982 + }
57983 +
57984 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
57985 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
57986 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57987 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
57988 + && !(comp2 & GR_SUPPRESS)) {
57989 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57990 + error = -EACCES;
57991 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
57992 + error = -EACCES;
57993 +
57994 + return error;
57995 +}
57996 +
57997 +void
57998 +gr_acl_handle_exit(void)
57999 +{
58000 + u16 id;
58001 + char *rolename;
58002 +
58003 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58004 + !(current->role->roletype & GR_ROLE_PERSIST))) {
58005 + id = current->acl_role_id;
58006 + rolename = current->role->rolename;
58007 + gr_set_acls(1);
58008 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58009 + }
58010 +
58011 + gr_put_exec_file(current);
58012 + return;
58013 +}
58014 +
58015 +int
58016 +gr_acl_handle_procpidmem(const struct task_struct *task)
58017 +{
58018 + if (unlikely(!gr_acl_is_enabled()))
58019 + return 0;
58020 +
58021 + if (task != current && task->acl->mode & GR_PROTPROCFD)
58022 + return -EACCES;
58023 +
58024 + return 0;
58025 +}
58026 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58027 new file mode 100644
58028 index 0000000..58800a7
58029 --- /dev/null
58030 +++ b/grsecurity/gracl_ip.c
58031 @@ -0,0 +1,384 @@
58032 +#include <linux/kernel.h>
58033 +#include <asm/uaccess.h>
58034 +#include <asm/errno.h>
58035 +#include <net/sock.h>
58036 +#include <linux/file.h>
58037 +#include <linux/fs.h>
58038 +#include <linux/net.h>
58039 +#include <linux/in.h>
58040 +#include <linux/skbuff.h>
58041 +#include <linux/ip.h>
58042 +#include <linux/udp.h>
58043 +#include <linux/types.h>
58044 +#include <linux/sched.h>
58045 +#include <linux/netdevice.h>
58046 +#include <linux/inetdevice.h>
58047 +#include <linux/gracl.h>
58048 +#include <linux/grsecurity.h>
58049 +#include <linux/grinternal.h>
58050 +
58051 +#define GR_BIND 0x01
58052 +#define GR_CONNECT 0x02
58053 +#define GR_INVERT 0x04
58054 +#define GR_BINDOVERRIDE 0x08
58055 +#define GR_CONNECTOVERRIDE 0x10
58056 +#define GR_SOCK_FAMILY 0x20
58057 +
58058 +static const char * gr_protocols[IPPROTO_MAX] = {
58059 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58060 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58061 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58062 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58063 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58064 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58065 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58066 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58067 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58068 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58069 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58070 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58071 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58072 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58073 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58074 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58075 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58076 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58077 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58078 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58079 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58080 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58081 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58082 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58083 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58084 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58085 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58086 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58087 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58088 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58089 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58090 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58091 + };
58092 +
58093 +static const char * gr_socktypes[SOCK_MAX] = {
58094 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58095 + "unknown:7", "unknown:8", "unknown:9", "packet"
58096 + };
58097 +
58098 +static const char * gr_sockfamilies[AF_MAX+1] = {
58099 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58100 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58101 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58102 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58103 + };
58104 +
58105 +const char *
58106 +gr_proto_to_name(unsigned char proto)
58107 +{
58108 + return gr_protocols[proto];
58109 +}
58110 +
58111 +const char *
58112 +gr_socktype_to_name(unsigned char type)
58113 +{
58114 + return gr_socktypes[type];
58115 +}
58116 +
58117 +const char *
58118 +gr_sockfamily_to_name(unsigned char family)
58119 +{
58120 + return gr_sockfamilies[family];
58121 +}
58122 +
58123 +int
58124 +gr_search_socket(const int domain, const int type, const int protocol)
58125 +{
58126 + struct acl_subject_label *curr;
58127 + const struct cred *cred = current_cred();
58128 +
58129 + if (unlikely(!gr_acl_is_enabled()))
58130 + goto exit;
58131 +
58132 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
58133 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58134 + goto exit; // let the kernel handle it
58135 +
58136 + curr = current->acl;
58137 +
58138 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58139 + /* the family is allowed, if this is PF_INET allow it only if
58140 + the extra sock type/protocol checks pass */
58141 + if (domain == PF_INET)
58142 + goto inet_check;
58143 + goto exit;
58144 + } else {
58145 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58146 + __u32 fakeip = 0;
58147 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58148 + current->role->roletype, cred->uid,
58149 + cred->gid, current->exec_file ?
58150 + gr_to_filename(current->exec_file->f_path.dentry,
58151 + current->exec_file->f_path.mnt) :
58152 + curr->filename, curr->filename,
58153 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58154 + &current->signal->saved_ip);
58155 + goto exit;
58156 + }
58157 + goto exit_fail;
58158 + }
58159 +
58160 +inet_check:
58161 + /* the rest of this checking is for IPv4 only */
58162 + if (!curr->ips)
58163 + goto exit;
58164 +
58165 + if ((curr->ip_type & (1 << type)) &&
58166 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58167 + goto exit;
58168 +
58169 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58170 + /* we don't place acls on raw sockets , and sometimes
58171 + dgram/ip sockets are opened for ioctl and not
58172 + bind/connect, so we'll fake a bind learn log */
58173 + if (type == SOCK_RAW || type == SOCK_PACKET) {
58174 + __u32 fakeip = 0;
58175 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58176 + current->role->roletype, cred->uid,
58177 + cred->gid, current->exec_file ?
58178 + gr_to_filename(current->exec_file->f_path.dentry,
58179 + current->exec_file->f_path.mnt) :
58180 + curr->filename, curr->filename,
58181 + &fakeip, 0, type,
58182 + protocol, GR_CONNECT, &current->signal->saved_ip);
58183 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58184 + __u32 fakeip = 0;
58185 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58186 + current->role->roletype, cred->uid,
58187 + cred->gid, current->exec_file ?
58188 + gr_to_filename(current->exec_file->f_path.dentry,
58189 + current->exec_file->f_path.mnt) :
58190 + curr->filename, curr->filename,
58191 + &fakeip, 0, type,
58192 + protocol, GR_BIND, &current->signal->saved_ip);
58193 + }
58194 + /* we'll log when they use connect or bind */
58195 + goto exit;
58196 + }
58197 +
58198 +exit_fail:
58199 + if (domain == PF_INET)
58200 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58201 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
58202 + else
58203 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58204 + gr_socktype_to_name(type), protocol);
58205 +
58206 + return 0;
58207 +exit:
58208 + return 1;
58209 +}
58210 +
58211 +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)
58212 +{
58213 + if ((ip->mode & mode) &&
58214 + (ip_port >= ip->low) &&
58215 + (ip_port <= ip->high) &&
58216 + ((ntohl(ip_addr) & our_netmask) ==
58217 + (ntohl(our_addr) & our_netmask))
58218 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58219 + && (ip->type & (1 << type))) {
58220 + if (ip->mode & GR_INVERT)
58221 + return 2; // specifically denied
58222 + else
58223 + return 1; // allowed
58224 + }
58225 +
58226 + return 0; // not specifically allowed, may continue parsing
58227 +}
58228 +
58229 +static int
58230 +gr_search_connectbind(const int full_mode, struct sock *sk,
58231 + struct sockaddr_in *addr, const int type)
58232 +{
58233 + char iface[IFNAMSIZ] = {0};
58234 + struct acl_subject_label *curr;
58235 + struct acl_ip_label *ip;
58236 + struct inet_sock *isk;
58237 + struct net_device *dev;
58238 + struct in_device *idev;
58239 + unsigned long i;
58240 + int ret;
58241 + int mode = full_mode & (GR_BIND | GR_CONNECT);
58242 + __u32 ip_addr = 0;
58243 + __u32 our_addr;
58244 + __u32 our_netmask;
58245 + char *p;
58246 + __u16 ip_port = 0;
58247 + const struct cred *cred = current_cred();
58248 +
58249 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58250 + return 0;
58251 +
58252 + curr = current->acl;
58253 + isk = inet_sk(sk);
58254 +
58255 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58256 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58257 + addr->sin_addr.s_addr = curr->inaddr_any_override;
58258 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58259 + struct sockaddr_in saddr;
58260 + int err;
58261 +
58262 + saddr.sin_family = AF_INET;
58263 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
58264 + saddr.sin_port = isk->inet_sport;
58265 +
58266 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58267 + if (err)
58268 + return err;
58269 +
58270 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58271 + if (err)
58272 + return err;
58273 + }
58274 +
58275 + if (!curr->ips)
58276 + return 0;
58277 +
58278 + ip_addr = addr->sin_addr.s_addr;
58279 + ip_port = ntohs(addr->sin_port);
58280 +
58281 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58282 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58283 + current->role->roletype, cred->uid,
58284 + cred->gid, current->exec_file ?
58285 + gr_to_filename(current->exec_file->f_path.dentry,
58286 + current->exec_file->f_path.mnt) :
58287 + curr->filename, curr->filename,
58288 + &ip_addr, ip_port, type,
58289 + sk->sk_protocol, mode, &current->signal->saved_ip);
58290 + return 0;
58291 + }
58292 +
58293 + for (i = 0; i < curr->ip_num; i++) {
58294 + ip = *(curr->ips + i);
58295 + if (ip->iface != NULL) {
58296 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
58297 + p = strchr(iface, ':');
58298 + if (p != NULL)
58299 + *p = '\0';
58300 + dev = dev_get_by_name(sock_net(sk), iface);
58301 + if (dev == NULL)
58302 + continue;
58303 + idev = in_dev_get(dev);
58304 + if (idev == NULL) {
58305 + dev_put(dev);
58306 + continue;
58307 + }
58308 + rcu_read_lock();
58309 + for_ifa(idev) {
58310 + if (!strcmp(ip->iface, ifa->ifa_label)) {
58311 + our_addr = ifa->ifa_address;
58312 + our_netmask = 0xffffffff;
58313 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58314 + if (ret == 1) {
58315 + rcu_read_unlock();
58316 + in_dev_put(idev);
58317 + dev_put(dev);
58318 + return 0;
58319 + } else if (ret == 2) {
58320 + rcu_read_unlock();
58321 + in_dev_put(idev);
58322 + dev_put(dev);
58323 + goto denied;
58324 + }
58325 + }
58326 + } endfor_ifa(idev);
58327 + rcu_read_unlock();
58328 + in_dev_put(idev);
58329 + dev_put(dev);
58330 + } else {
58331 + our_addr = ip->addr;
58332 + our_netmask = ip->netmask;
58333 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58334 + if (ret == 1)
58335 + return 0;
58336 + else if (ret == 2)
58337 + goto denied;
58338 + }
58339 + }
58340 +
58341 +denied:
58342 + if (mode == GR_BIND)
58343 + 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));
58344 + else if (mode == GR_CONNECT)
58345 + 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));
58346 +
58347 + return -EACCES;
58348 +}
58349 +
58350 +int
58351 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58352 +{
58353 + /* always allow disconnection of dgram sockets with connect */
58354 + if (addr->sin_family == AF_UNSPEC)
58355 + return 0;
58356 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58357 +}
58358 +
58359 +int
58360 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58361 +{
58362 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58363 +}
58364 +
58365 +int gr_search_listen(struct socket *sock)
58366 +{
58367 + struct sock *sk = sock->sk;
58368 + struct sockaddr_in addr;
58369 +
58370 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58371 + addr.sin_port = inet_sk(sk)->inet_sport;
58372 +
58373 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58374 +}
58375 +
58376 +int gr_search_accept(struct socket *sock)
58377 +{
58378 + struct sock *sk = sock->sk;
58379 + struct sockaddr_in addr;
58380 +
58381 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58382 + addr.sin_port = inet_sk(sk)->inet_sport;
58383 +
58384 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58385 +}
58386 +
58387 +int
58388 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58389 +{
58390 + if (addr)
58391 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58392 + else {
58393 + struct sockaddr_in sin;
58394 + const struct inet_sock *inet = inet_sk(sk);
58395 +
58396 + sin.sin_addr.s_addr = inet->inet_daddr;
58397 + sin.sin_port = inet->inet_dport;
58398 +
58399 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58400 + }
58401 +}
58402 +
58403 +int
58404 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58405 +{
58406 + struct sockaddr_in sin;
58407 +
58408 + if (unlikely(skb->len < sizeof (struct udphdr)))
58409 + return 0; // skip this packet
58410 +
58411 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58412 + sin.sin_port = udp_hdr(skb)->source;
58413 +
58414 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58415 +}
58416 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58417 new file mode 100644
58418 index 0000000..25f54ef
58419 --- /dev/null
58420 +++ b/grsecurity/gracl_learn.c
58421 @@ -0,0 +1,207 @@
58422 +#include <linux/kernel.h>
58423 +#include <linux/mm.h>
58424 +#include <linux/sched.h>
58425 +#include <linux/poll.h>
58426 +#include <linux/string.h>
58427 +#include <linux/file.h>
58428 +#include <linux/types.h>
58429 +#include <linux/vmalloc.h>
58430 +#include <linux/grinternal.h>
58431 +
58432 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58433 + size_t count, loff_t *ppos);
58434 +extern int gr_acl_is_enabled(void);
58435 +
58436 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58437 +static int gr_learn_attached;
58438 +
58439 +/* use a 512k buffer */
58440 +#define LEARN_BUFFER_SIZE (512 * 1024)
58441 +
58442 +static DEFINE_SPINLOCK(gr_learn_lock);
58443 +static DEFINE_MUTEX(gr_learn_user_mutex);
58444 +
58445 +/* we need to maintain two buffers, so that the kernel context of grlearn
58446 + uses a semaphore around the userspace copying, and the other kernel contexts
58447 + use a spinlock when copying into the buffer, since they cannot sleep
58448 +*/
58449 +static char *learn_buffer;
58450 +static char *learn_buffer_user;
58451 +static int learn_buffer_len;
58452 +static int learn_buffer_user_len;
58453 +
58454 +static ssize_t
58455 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58456 +{
58457 + DECLARE_WAITQUEUE(wait, current);
58458 + ssize_t retval = 0;
58459 +
58460 + add_wait_queue(&learn_wait, &wait);
58461 + set_current_state(TASK_INTERRUPTIBLE);
58462 + do {
58463 + mutex_lock(&gr_learn_user_mutex);
58464 + spin_lock(&gr_learn_lock);
58465 + if (learn_buffer_len)
58466 + break;
58467 + spin_unlock(&gr_learn_lock);
58468 + mutex_unlock(&gr_learn_user_mutex);
58469 + if (file->f_flags & O_NONBLOCK) {
58470 + retval = -EAGAIN;
58471 + goto out;
58472 + }
58473 + if (signal_pending(current)) {
58474 + retval = -ERESTARTSYS;
58475 + goto out;
58476 + }
58477 +
58478 + schedule();
58479 + } while (1);
58480 +
58481 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58482 + learn_buffer_user_len = learn_buffer_len;
58483 + retval = learn_buffer_len;
58484 + learn_buffer_len = 0;
58485 +
58486 + spin_unlock(&gr_learn_lock);
58487 +
58488 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58489 + retval = -EFAULT;
58490 +
58491 + mutex_unlock(&gr_learn_user_mutex);
58492 +out:
58493 + set_current_state(TASK_RUNNING);
58494 + remove_wait_queue(&learn_wait, &wait);
58495 + return retval;
58496 +}
58497 +
58498 +static unsigned int
58499 +poll_learn(struct file * file, poll_table * wait)
58500 +{
58501 + poll_wait(file, &learn_wait, wait);
58502 +
58503 + if (learn_buffer_len)
58504 + return (POLLIN | POLLRDNORM);
58505 +
58506 + return 0;
58507 +}
58508 +
58509 +void
58510 +gr_clear_learn_entries(void)
58511 +{
58512 + char *tmp;
58513 +
58514 + mutex_lock(&gr_learn_user_mutex);
58515 + spin_lock(&gr_learn_lock);
58516 + tmp = learn_buffer;
58517 + learn_buffer = NULL;
58518 + spin_unlock(&gr_learn_lock);
58519 + if (tmp)
58520 + vfree(tmp);
58521 + if (learn_buffer_user != NULL) {
58522 + vfree(learn_buffer_user);
58523 + learn_buffer_user = NULL;
58524 + }
58525 + learn_buffer_len = 0;
58526 + mutex_unlock(&gr_learn_user_mutex);
58527 +
58528 + return;
58529 +}
58530 +
58531 +void
58532 +gr_add_learn_entry(const char *fmt, ...)
58533 +{
58534 + va_list args;
58535 + unsigned int len;
58536 +
58537 + if (!gr_learn_attached)
58538 + return;
58539 +
58540 + spin_lock(&gr_learn_lock);
58541 +
58542 + /* leave a gap at the end so we know when it's "full" but don't have to
58543 + compute the exact length of the string we're trying to append
58544 + */
58545 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58546 + spin_unlock(&gr_learn_lock);
58547 + wake_up_interruptible(&learn_wait);
58548 + return;
58549 + }
58550 + if (learn_buffer == NULL) {
58551 + spin_unlock(&gr_learn_lock);
58552 + return;
58553 + }
58554 +
58555 + va_start(args, fmt);
58556 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58557 + va_end(args);
58558 +
58559 + learn_buffer_len += len + 1;
58560 +
58561 + spin_unlock(&gr_learn_lock);
58562 + wake_up_interruptible(&learn_wait);
58563 +
58564 + return;
58565 +}
58566 +
58567 +static int
58568 +open_learn(struct inode *inode, struct file *file)
58569 +{
58570 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58571 + return -EBUSY;
58572 + if (file->f_mode & FMODE_READ) {
58573 + int retval = 0;
58574 + mutex_lock(&gr_learn_user_mutex);
58575 + if (learn_buffer == NULL)
58576 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58577 + if (learn_buffer_user == NULL)
58578 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58579 + if (learn_buffer == NULL) {
58580 + retval = -ENOMEM;
58581 + goto out_error;
58582 + }
58583 + if (learn_buffer_user == NULL) {
58584 + retval = -ENOMEM;
58585 + goto out_error;
58586 + }
58587 + learn_buffer_len = 0;
58588 + learn_buffer_user_len = 0;
58589 + gr_learn_attached = 1;
58590 +out_error:
58591 + mutex_unlock(&gr_learn_user_mutex);
58592 + return retval;
58593 + }
58594 + return 0;
58595 +}
58596 +
58597 +static int
58598 +close_learn(struct inode *inode, struct file *file)
58599 +{
58600 + if (file->f_mode & FMODE_READ) {
58601 + char *tmp = NULL;
58602 + mutex_lock(&gr_learn_user_mutex);
58603 + spin_lock(&gr_learn_lock);
58604 + tmp = learn_buffer;
58605 + learn_buffer = NULL;
58606 + spin_unlock(&gr_learn_lock);
58607 + if (tmp)
58608 + vfree(tmp);
58609 + if (learn_buffer_user != NULL) {
58610 + vfree(learn_buffer_user);
58611 + learn_buffer_user = NULL;
58612 + }
58613 + learn_buffer_len = 0;
58614 + learn_buffer_user_len = 0;
58615 + gr_learn_attached = 0;
58616 + mutex_unlock(&gr_learn_user_mutex);
58617 + }
58618 +
58619 + return 0;
58620 +}
58621 +
58622 +const struct file_operations grsec_fops = {
58623 + .read = read_learn,
58624 + .write = write_grsec_handler,
58625 + .open = open_learn,
58626 + .release = close_learn,
58627 + .poll = poll_learn,
58628 +};
58629 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58630 new file mode 100644
58631 index 0000000..39645c9
58632 --- /dev/null
58633 +++ b/grsecurity/gracl_res.c
58634 @@ -0,0 +1,68 @@
58635 +#include <linux/kernel.h>
58636 +#include <linux/sched.h>
58637 +#include <linux/gracl.h>
58638 +#include <linux/grinternal.h>
58639 +
58640 +static const char *restab_log[] = {
58641 + [RLIMIT_CPU] = "RLIMIT_CPU",
58642 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58643 + [RLIMIT_DATA] = "RLIMIT_DATA",
58644 + [RLIMIT_STACK] = "RLIMIT_STACK",
58645 + [RLIMIT_CORE] = "RLIMIT_CORE",
58646 + [RLIMIT_RSS] = "RLIMIT_RSS",
58647 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58648 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58649 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58650 + [RLIMIT_AS] = "RLIMIT_AS",
58651 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58652 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58653 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58654 + [RLIMIT_NICE] = "RLIMIT_NICE",
58655 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58656 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58657 + [GR_CRASH_RES] = "RLIMIT_CRASH"
58658 +};
58659 +
58660 +void
58661 +gr_log_resource(const struct task_struct *task,
58662 + const int res, const unsigned long wanted, const int gt)
58663 +{
58664 + const struct cred *cred;
58665 + unsigned long rlim;
58666 +
58667 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
58668 + return;
58669 +
58670 + // not yet supported resource
58671 + if (unlikely(!restab_log[res]))
58672 + return;
58673 +
58674 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58675 + rlim = task_rlimit_max(task, res);
58676 + else
58677 + rlim = task_rlimit(task, res);
58678 +
58679 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58680 + return;
58681 +
58682 + rcu_read_lock();
58683 + cred = __task_cred(task);
58684 +
58685 + if (res == RLIMIT_NPROC &&
58686 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58687 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58688 + goto out_rcu_unlock;
58689 + else if (res == RLIMIT_MEMLOCK &&
58690 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58691 + goto out_rcu_unlock;
58692 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58693 + goto out_rcu_unlock;
58694 + rcu_read_unlock();
58695 +
58696 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58697 +
58698 + return;
58699 +out_rcu_unlock:
58700 + rcu_read_unlock();
58701 + return;
58702 +}
58703 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58704 new file mode 100644
58705 index 0000000..25197e9
58706 --- /dev/null
58707 +++ b/grsecurity/gracl_segv.c
58708 @@ -0,0 +1,299 @@
58709 +#include <linux/kernel.h>
58710 +#include <linux/mm.h>
58711 +#include <asm/uaccess.h>
58712 +#include <asm/errno.h>
58713 +#include <asm/mman.h>
58714 +#include <net/sock.h>
58715 +#include <linux/file.h>
58716 +#include <linux/fs.h>
58717 +#include <linux/net.h>
58718 +#include <linux/in.h>
58719 +#include <linux/slab.h>
58720 +#include <linux/types.h>
58721 +#include <linux/sched.h>
58722 +#include <linux/timer.h>
58723 +#include <linux/gracl.h>
58724 +#include <linux/grsecurity.h>
58725 +#include <linux/grinternal.h>
58726 +
58727 +static struct crash_uid *uid_set;
58728 +static unsigned short uid_used;
58729 +static DEFINE_SPINLOCK(gr_uid_lock);
58730 +extern rwlock_t gr_inode_lock;
58731 +extern struct acl_subject_label *
58732 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58733 + struct acl_role_label *role);
58734 +
58735 +#ifdef CONFIG_BTRFS_FS
58736 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58737 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58738 +#endif
58739 +
58740 +static inline dev_t __get_dev(const struct dentry *dentry)
58741 +{
58742 +#ifdef CONFIG_BTRFS_FS
58743 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58744 + return get_btrfs_dev_from_inode(dentry->d_inode);
58745 + else
58746 +#endif
58747 + return dentry->d_inode->i_sb->s_dev;
58748 +}
58749 +
58750 +int
58751 +gr_init_uidset(void)
58752 +{
58753 + uid_set =
58754 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58755 + uid_used = 0;
58756 +
58757 + return uid_set ? 1 : 0;
58758 +}
58759 +
58760 +void
58761 +gr_free_uidset(void)
58762 +{
58763 + if (uid_set)
58764 + kfree(uid_set);
58765 +
58766 + return;
58767 +}
58768 +
58769 +int
58770 +gr_find_uid(const uid_t uid)
58771 +{
58772 + struct crash_uid *tmp = uid_set;
58773 + uid_t buid;
58774 + int low = 0, high = uid_used - 1, mid;
58775 +
58776 + while (high >= low) {
58777 + mid = (low + high) >> 1;
58778 + buid = tmp[mid].uid;
58779 + if (buid == uid)
58780 + return mid;
58781 + if (buid > uid)
58782 + high = mid - 1;
58783 + if (buid < uid)
58784 + low = mid + 1;
58785 + }
58786 +
58787 + return -1;
58788 +}
58789 +
58790 +static __inline__ void
58791 +gr_insertsort(void)
58792 +{
58793 + unsigned short i, j;
58794 + struct crash_uid index;
58795 +
58796 + for (i = 1; i < uid_used; i++) {
58797 + index = uid_set[i];
58798 + j = i;
58799 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
58800 + uid_set[j] = uid_set[j - 1];
58801 + j--;
58802 + }
58803 + uid_set[j] = index;
58804 + }
58805 +
58806 + return;
58807 +}
58808 +
58809 +static __inline__ void
58810 +gr_insert_uid(const uid_t uid, const unsigned long expires)
58811 +{
58812 + int loc;
58813 +
58814 + if (uid_used == GR_UIDTABLE_MAX)
58815 + return;
58816 +
58817 + loc = gr_find_uid(uid);
58818 +
58819 + if (loc >= 0) {
58820 + uid_set[loc].expires = expires;
58821 + return;
58822 + }
58823 +
58824 + uid_set[uid_used].uid = uid;
58825 + uid_set[uid_used].expires = expires;
58826 + uid_used++;
58827 +
58828 + gr_insertsort();
58829 +
58830 + return;
58831 +}
58832 +
58833 +void
58834 +gr_remove_uid(const unsigned short loc)
58835 +{
58836 + unsigned short i;
58837 +
58838 + for (i = loc + 1; i < uid_used; i++)
58839 + uid_set[i - 1] = uid_set[i];
58840 +
58841 + uid_used--;
58842 +
58843 + return;
58844 +}
58845 +
58846 +int
58847 +gr_check_crash_uid(const uid_t uid)
58848 +{
58849 + int loc;
58850 + int ret = 0;
58851 +
58852 + if (unlikely(!gr_acl_is_enabled()))
58853 + return 0;
58854 +
58855 + spin_lock(&gr_uid_lock);
58856 + loc = gr_find_uid(uid);
58857 +
58858 + if (loc < 0)
58859 + goto out_unlock;
58860 +
58861 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
58862 + gr_remove_uid(loc);
58863 + else
58864 + ret = 1;
58865 +
58866 +out_unlock:
58867 + spin_unlock(&gr_uid_lock);
58868 + return ret;
58869 +}
58870 +
58871 +static __inline__ int
58872 +proc_is_setxid(const struct cred *cred)
58873 +{
58874 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
58875 + !uid_eq(cred->uid, cred->fsuid))
58876 + return 1;
58877 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
58878 + !uid_eq(cred->gid, cred->fsgid))
58879 + return 1;
58880 +
58881 + return 0;
58882 +}
58883 +
58884 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
58885 +
58886 +void
58887 +gr_handle_crash(struct task_struct *task, const int sig)
58888 +{
58889 + struct acl_subject_label *curr;
58890 + struct task_struct *tsk, *tsk2;
58891 + const struct cred *cred;
58892 + const struct cred *cred2;
58893 +
58894 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
58895 + return;
58896 +
58897 + if (unlikely(!gr_acl_is_enabled()))
58898 + return;
58899 +
58900 + curr = task->acl;
58901 +
58902 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
58903 + return;
58904 +
58905 + if (time_before_eq(curr->expires, get_seconds())) {
58906 + curr->expires = 0;
58907 + curr->crashes = 0;
58908 + }
58909 +
58910 + curr->crashes++;
58911 +
58912 + if (!curr->expires)
58913 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
58914 +
58915 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58916 + time_after(curr->expires, get_seconds())) {
58917 + rcu_read_lock();
58918 + cred = __task_cred(task);
58919 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
58920 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58921 + spin_lock(&gr_uid_lock);
58922 + gr_insert_uid(cred->uid, curr->expires);
58923 + spin_unlock(&gr_uid_lock);
58924 + curr->expires = 0;
58925 + curr->crashes = 0;
58926 + read_lock(&tasklist_lock);
58927 + do_each_thread(tsk2, tsk) {
58928 + cred2 = __task_cred(tsk);
58929 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
58930 + gr_fake_force_sig(SIGKILL, tsk);
58931 + } while_each_thread(tsk2, tsk);
58932 + read_unlock(&tasklist_lock);
58933 + } else {
58934 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58935 + read_lock(&tasklist_lock);
58936 + read_lock(&grsec_exec_file_lock);
58937 + do_each_thread(tsk2, tsk) {
58938 + if (likely(tsk != task)) {
58939 + // if this thread has the same subject as the one that triggered
58940 + // RES_CRASH and it's the same binary, kill it
58941 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
58942 + gr_fake_force_sig(SIGKILL, tsk);
58943 + }
58944 + } while_each_thread(tsk2, tsk);
58945 + read_unlock(&grsec_exec_file_lock);
58946 + read_unlock(&tasklist_lock);
58947 + }
58948 + rcu_read_unlock();
58949 + }
58950 +
58951 + return;
58952 +}
58953 +
58954 +int
58955 +gr_check_crash_exec(const struct file *filp)
58956 +{
58957 + struct acl_subject_label *curr;
58958 +
58959 + if (unlikely(!gr_acl_is_enabled()))
58960 + return 0;
58961 +
58962 + read_lock(&gr_inode_lock);
58963 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
58964 + __get_dev(filp->f_path.dentry),
58965 + current->role);
58966 + read_unlock(&gr_inode_lock);
58967 +
58968 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
58969 + (!curr->crashes && !curr->expires))
58970 + return 0;
58971 +
58972 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58973 + time_after(curr->expires, get_seconds()))
58974 + return 1;
58975 + else if (time_before_eq(curr->expires, get_seconds())) {
58976 + curr->crashes = 0;
58977 + curr->expires = 0;
58978 + }
58979 +
58980 + return 0;
58981 +}
58982 +
58983 +void
58984 +gr_handle_alertkill(struct task_struct *task)
58985 +{
58986 + struct acl_subject_label *curracl;
58987 + __u32 curr_ip;
58988 + struct task_struct *p, *p2;
58989 +
58990 + if (unlikely(!gr_acl_is_enabled()))
58991 + return;
58992 +
58993 + curracl = task->acl;
58994 + curr_ip = task->signal->curr_ip;
58995 +
58996 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
58997 + read_lock(&tasklist_lock);
58998 + do_each_thread(p2, p) {
58999 + if (p->signal->curr_ip == curr_ip)
59000 + gr_fake_force_sig(SIGKILL, p);
59001 + } while_each_thread(p2, p);
59002 + read_unlock(&tasklist_lock);
59003 + } else if (curracl->mode & GR_KILLPROC)
59004 + gr_fake_force_sig(SIGKILL, task);
59005 +
59006 + return;
59007 +}
59008 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59009 new file mode 100644
59010 index 0000000..9d83a69
59011 --- /dev/null
59012 +++ b/grsecurity/gracl_shm.c
59013 @@ -0,0 +1,40 @@
59014 +#include <linux/kernel.h>
59015 +#include <linux/mm.h>
59016 +#include <linux/sched.h>
59017 +#include <linux/file.h>
59018 +#include <linux/ipc.h>
59019 +#include <linux/gracl.h>
59020 +#include <linux/grsecurity.h>
59021 +#include <linux/grinternal.h>
59022 +
59023 +int
59024 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59025 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59026 +{
59027 + struct task_struct *task;
59028 +
59029 + if (!gr_acl_is_enabled())
59030 + return 1;
59031 +
59032 + rcu_read_lock();
59033 + read_lock(&tasklist_lock);
59034 +
59035 + task = find_task_by_vpid(shm_cprid);
59036 +
59037 + if (unlikely(!task))
59038 + task = find_task_by_vpid(shm_lapid);
59039 +
59040 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59041 + (task->pid == shm_lapid)) &&
59042 + (task->acl->mode & GR_PROTSHM) &&
59043 + (task->acl != current->acl))) {
59044 + read_unlock(&tasklist_lock);
59045 + rcu_read_unlock();
59046 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59047 + return 0;
59048 + }
59049 + read_unlock(&tasklist_lock);
59050 + rcu_read_unlock();
59051 +
59052 + return 1;
59053 +}
59054 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59055 new file mode 100644
59056 index 0000000..bc0be01
59057 --- /dev/null
59058 +++ b/grsecurity/grsec_chdir.c
59059 @@ -0,0 +1,19 @@
59060 +#include <linux/kernel.h>
59061 +#include <linux/sched.h>
59062 +#include <linux/fs.h>
59063 +#include <linux/file.h>
59064 +#include <linux/grsecurity.h>
59065 +#include <linux/grinternal.h>
59066 +
59067 +void
59068 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59069 +{
59070 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59071 + if ((grsec_enable_chdir && grsec_enable_group &&
59072 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59073 + !grsec_enable_group)) {
59074 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59075 + }
59076 +#endif
59077 + return;
59078 +}
59079 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59080 new file mode 100644
59081 index 0000000..9807ee2
59082 --- /dev/null
59083 +++ b/grsecurity/grsec_chroot.c
59084 @@ -0,0 +1,368 @@
59085 +#include <linux/kernel.h>
59086 +#include <linux/module.h>
59087 +#include <linux/sched.h>
59088 +#include <linux/file.h>
59089 +#include <linux/fs.h>
59090 +#include <linux/mount.h>
59091 +#include <linux/types.h>
59092 +#include "../fs/mount.h"
59093 +#include <linux/grsecurity.h>
59094 +#include <linux/grinternal.h>
59095 +
59096 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59097 +{
59098 +#ifdef CONFIG_GRKERNSEC
59099 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59100 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59101 + task->gr_is_chrooted = 1;
59102 + else
59103 + task->gr_is_chrooted = 0;
59104 +
59105 + task->gr_chroot_dentry = path->dentry;
59106 +#endif
59107 + return;
59108 +}
59109 +
59110 +void gr_clear_chroot_entries(struct task_struct *task)
59111 +{
59112 +#ifdef CONFIG_GRKERNSEC
59113 + task->gr_is_chrooted = 0;
59114 + task->gr_chroot_dentry = NULL;
59115 +#endif
59116 + return;
59117 +}
59118 +
59119 +int
59120 +gr_handle_chroot_unix(const pid_t pid)
59121 +{
59122 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59123 + struct task_struct *p;
59124 +
59125 + if (unlikely(!grsec_enable_chroot_unix))
59126 + return 1;
59127 +
59128 + if (likely(!proc_is_chrooted(current)))
59129 + return 1;
59130 +
59131 + rcu_read_lock();
59132 + read_lock(&tasklist_lock);
59133 + p = find_task_by_vpid_unrestricted(pid);
59134 + if (unlikely(p && !have_same_root(current, p))) {
59135 + read_unlock(&tasklist_lock);
59136 + rcu_read_unlock();
59137 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59138 + return 0;
59139 + }
59140 + read_unlock(&tasklist_lock);
59141 + rcu_read_unlock();
59142 +#endif
59143 + return 1;
59144 +}
59145 +
59146 +int
59147 +gr_handle_chroot_nice(void)
59148 +{
59149 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59150 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59151 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59152 + return -EPERM;
59153 + }
59154 +#endif
59155 + return 0;
59156 +}
59157 +
59158 +int
59159 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59160 +{
59161 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59162 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59163 + && proc_is_chrooted(current)) {
59164 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59165 + return -EACCES;
59166 + }
59167 +#endif
59168 + return 0;
59169 +}
59170 +
59171 +int
59172 +gr_handle_chroot_rawio(const struct inode *inode)
59173 +{
59174 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59175 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
59176 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
59177 + return 1;
59178 +#endif
59179 + return 0;
59180 +}
59181 +
59182 +int
59183 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59184 +{
59185 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59186 + struct task_struct *p;
59187 + int ret = 0;
59188 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59189 + return ret;
59190 +
59191 + read_lock(&tasklist_lock);
59192 + do_each_pid_task(pid, type, p) {
59193 + if (!have_same_root(current, p)) {
59194 + ret = 1;
59195 + goto out;
59196 + }
59197 + } while_each_pid_task(pid, type, p);
59198 +out:
59199 + read_unlock(&tasklist_lock);
59200 + return ret;
59201 +#endif
59202 + return 0;
59203 +}
59204 +
59205 +int
59206 +gr_pid_is_chrooted(struct task_struct *p)
59207 +{
59208 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59209 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59210 + return 0;
59211 +
59212 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59213 + !have_same_root(current, p)) {
59214 + return 1;
59215 + }
59216 +#endif
59217 + return 0;
59218 +}
59219 +
59220 +EXPORT_SYMBOL(gr_pid_is_chrooted);
59221 +
59222 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59223 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59224 +{
59225 + struct path path, currentroot;
59226 + int ret = 0;
59227 +
59228 + path.dentry = (struct dentry *)u_dentry;
59229 + path.mnt = (struct vfsmount *)u_mnt;
59230 + get_fs_root(current->fs, &currentroot);
59231 + if (path_is_under(&path, &currentroot))
59232 + ret = 1;
59233 + path_put(&currentroot);
59234 +
59235 + return ret;
59236 +}
59237 +#endif
59238 +
59239 +int
59240 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59241 +{
59242 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59243 + if (!grsec_enable_chroot_fchdir)
59244 + return 1;
59245 +
59246 + if (!proc_is_chrooted(current))
59247 + return 1;
59248 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59249 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59250 + return 0;
59251 + }
59252 +#endif
59253 + return 1;
59254 +}
59255 +
59256 +int
59257 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59258 + const time_t shm_createtime)
59259 +{
59260 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59261 + struct task_struct *p;
59262 + time_t starttime;
59263 +
59264 + if (unlikely(!grsec_enable_chroot_shmat))
59265 + return 1;
59266 +
59267 + if (likely(!proc_is_chrooted(current)))
59268 + return 1;
59269 +
59270 + rcu_read_lock();
59271 + read_lock(&tasklist_lock);
59272 +
59273 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59274 + starttime = p->start_time.tv_sec;
59275 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59276 + if (have_same_root(current, p)) {
59277 + goto allow;
59278 + } else {
59279 + read_unlock(&tasklist_lock);
59280 + rcu_read_unlock();
59281 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59282 + return 0;
59283 + }
59284 + }
59285 + /* creator exited, pid reuse, fall through to next check */
59286 + }
59287 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59288 + if (unlikely(!have_same_root(current, p))) {
59289 + read_unlock(&tasklist_lock);
59290 + rcu_read_unlock();
59291 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59292 + return 0;
59293 + }
59294 + }
59295 +
59296 +allow:
59297 + read_unlock(&tasklist_lock);
59298 + rcu_read_unlock();
59299 +#endif
59300 + return 1;
59301 +}
59302 +
59303 +void
59304 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59305 +{
59306 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59307 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59308 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59309 +#endif
59310 + return;
59311 +}
59312 +
59313 +int
59314 +gr_handle_chroot_mknod(const struct dentry *dentry,
59315 + const struct vfsmount *mnt, const int mode)
59316 +{
59317 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59318 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59319 + proc_is_chrooted(current)) {
59320 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59321 + return -EPERM;
59322 + }
59323 +#endif
59324 + return 0;
59325 +}
59326 +
59327 +int
59328 +gr_handle_chroot_mount(const struct dentry *dentry,
59329 + const struct vfsmount *mnt, const char *dev_name)
59330 +{
59331 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59332 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59333 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59334 + return -EPERM;
59335 + }
59336 +#endif
59337 + return 0;
59338 +}
59339 +
59340 +int
59341 +gr_handle_chroot_pivot(void)
59342 +{
59343 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59344 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59345 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59346 + return -EPERM;
59347 + }
59348 +#endif
59349 + return 0;
59350 +}
59351 +
59352 +int
59353 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59354 +{
59355 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59356 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59357 + !gr_is_outside_chroot(dentry, mnt)) {
59358 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59359 + return -EPERM;
59360 + }
59361 +#endif
59362 + return 0;
59363 +}
59364 +
59365 +extern const char *captab_log[];
59366 +extern int captab_log_entries;
59367 +
59368 +int
59369 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59370 +{
59371 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59372 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59373 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59374 + if (cap_raised(chroot_caps, cap)) {
59375 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59376 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59377 + }
59378 + return 0;
59379 + }
59380 + }
59381 +#endif
59382 + return 1;
59383 +}
59384 +
59385 +int
59386 +gr_chroot_is_capable(const int cap)
59387 +{
59388 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59389 + return gr_task_chroot_is_capable(current, current_cred(), cap);
59390 +#endif
59391 + return 1;
59392 +}
59393 +
59394 +int
59395 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59396 +{
59397 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59398 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59399 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59400 + if (cap_raised(chroot_caps, cap)) {
59401 + return 0;
59402 + }
59403 + }
59404 +#endif
59405 + return 1;
59406 +}
59407 +
59408 +int
59409 +gr_chroot_is_capable_nolog(const int cap)
59410 +{
59411 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59412 + return gr_task_chroot_is_capable_nolog(current, cap);
59413 +#endif
59414 + return 1;
59415 +}
59416 +
59417 +int
59418 +gr_handle_chroot_sysctl(const int op)
59419 +{
59420 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59421 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59422 + proc_is_chrooted(current))
59423 + return -EACCES;
59424 +#endif
59425 + return 0;
59426 +}
59427 +
59428 +void
59429 +gr_handle_chroot_chdir(struct path *path)
59430 +{
59431 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59432 + if (grsec_enable_chroot_chdir)
59433 + set_fs_pwd(current->fs, path);
59434 +#endif
59435 + return;
59436 +}
59437 +
59438 +int
59439 +gr_handle_chroot_chmod(const struct dentry *dentry,
59440 + const struct vfsmount *mnt, const int mode)
59441 +{
59442 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59443 + /* allow chmod +s on directories, but not files */
59444 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59445 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59446 + proc_is_chrooted(current)) {
59447 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59448 + return -EPERM;
59449 + }
59450 +#endif
59451 + return 0;
59452 +}
59453 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59454 new file mode 100644
59455 index 0000000..7de2055
59456 --- /dev/null
59457 +++ b/grsecurity/grsec_disabled.c
59458 @@ -0,0 +1,442 @@
59459 +#include <linux/kernel.h>
59460 +#include <linux/module.h>
59461 +#include <linux/sched.h>
59462 +#include <linux/file.h>
59463 +#include <linux/fs.h>
59464 +#include <linux/kdev_t.h>
59465 +#include <linux/net.h>
59466 +#include <linux/in.h>
59467 +#include <linux/ip.h>
59468 +#include <linux/skbuff.h>
59469 +#include <linux/sysctl.h>
59470 +
59471 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59472 +void
59473 +pax_set_initial_flags(struct linux_binprm *bprm)
59474 +{
59475 + return;
59476 +}
59477 +#endif
59478 +
59479 +#ifdef CONFIG_SYSCTL
59480 +__u32
59481 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59482 +{
59483 + return 0;
59484 +}
59485 +#endif
59486 +
59487 +#ifdef CONFIG_TASKSTATS
59488 +int gr_is_taskstats_denied(int pid)
59489 +{
59490 + return 0;
59491 +}
59492 +#endif
59493 +
59494 +int
59495 +gr_acl_is_enabled(void)
59496 +{
59497 + return 0;
59498 +}
59499 +
59500 +void
59501 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59502 +{
59503 + return;
59504 +}
59505 +
59506 +int
59507 +gr_handle_rawio(const struct inode *inode)
59508 +{
59509 + return 0;
59510 +}
59511 +
59512 +void
59513 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59514 +{
59515 + return;
59516 +}
59517 +
59518 +int
59519 +gr_handle_ptrace(struct task_struct *task, const long request)
59520 +{
59521 + return 0;
59522 +}
59523 +
59524 +int
59525 +gr_handle_proc_ptrace(struct task_struct *task)
59526 +{
59527 + return 0;
59528 +}
59529 +
59530 +void
59531 +gr_learn_resource(const struct task_struct *task,
59532 + const int res, const unsigned long wanted, const int gt)
59533 +{
59534 + return;
59535 +}
59536 +
59537 +int
59538 +gr_set_acls(const int type)
59539 +{
59540 + return 0;
59541 +}
59542 +
59543 +int
59544 +gr_check_hidden_task(const struct task_struct *tsk)
59545 +{
59546 + return 0;
59547 +}
59548 +
59549 +int
59550 +gr_check_protected_task(const struct task_struct *task)
59551 +{
59552 + return 0;
59553 +}
59554 +
59555 +int
59556 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59557 +{
59558 + return 0;
59559 +}
59560 +
59561 +void
59562 +gr_copy_label(struct task_struct *tsk)
59563 +{
59564 + return;
59565 +}
59566 +
59567 +void
59568 +gr_set_pax_flags(struct task_struct *task)
59569 +{
59570 + return;
59571 +}
59572 +
59573 +int
59574 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59575 + const int unsafe_share)
59576 +{
59577 + return 0;
59578 +}
59579 +
59580 +void
59581 +gr_handle_delete(const ino_t ino, const dev_t dev)
59582 +{
59583 + return;
59584 +}
59585 +
59586 +void
59587 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59588 +{
59589 + return;
59590 +}
59591 +
59592 +void
59593 +gr_handle_crash(struct task_struct *task, const int sig)
59594 +{
59595 + return;
59596 +}
59597 +
59598 +int
59599 +gr_check_crash_exec(const struct file *filp)
59600 +{
59601 + return 0;
59602 +}
59603 +
59604 +int
59605 +gr_check_crash_uid(const uid_t uid)
59606 +{
59607 + return 0;
59608 +}
59609 +
59610 +void
59611 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59612 + struct dentry *old_dentry,
59613 + struct dentry *new_dentry,
59614 + struct vfsmount *mnt, const __u8 replace)
59615 +{
59616 + return;
59617 +}
59618 +
59619 +int
59620 +gr_search_socket(const int family, const int type, const int protocol)
59621 +{
59622 + return 1;
59623 +}
59624 +
59625 +int
59626 +gr_search_connectbind(const int mode, const struct socket *sock,
59627 + const struct sockaddr_in *addr)
59628 +{
59629 + return 0;
59630 +}
59631 +
59632 +void
59633 +gr_handle_alertkill(struct task_struct *task)
59634 +{
59635 + return;
59636 +}
59637 +
59638 +__u32
59639 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59640 +{
59641 + return 1;
59642 +}
59643 +
59644 +__u32
59645 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59646 + const struct vfsmount * mnt)
59647 +{
59648 + return 1;
59649 +}
59650 +
59651 +__u32
59652 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59653 + int acc_mode)
59654 +{
59655 + return 1;
59656 +}
59657 +
59658 +__u32
59659 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59660 +{
59661 + return 1;
59662 +}
59663 +
59664 +__u32
59665 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59666 +{
59667 + return 1;
59668 +}
59669 +
59670 +int
59671 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59672 + unsigned int *vm_flags)
59673 +{
59674 + return 1;
59675 +}
59676 +
59677 +__u32
59678 +gr_acl_handle_truncate(const struct dentry * dentry,
59679 + const struct vfsmount * mnt)
59680 +{
59681 + return 1;
59682 +}
59683 +
59684 +__u32
59685 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59686 +{
59687 + return 1;
59688 +}
59689 +
59690 +__u32
59691 +gr_acl_handle_access(const struct dentry * dentry,
59692 + const struct vfsmount * mnt, const int fmode)
59693 +{
59694 + return 1;
59695 +}
59696 +
59697 +__u32
59698 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59699 + umode_t *mode)
59700 +{
59701 + return 1;
59702 +}
59703 +
59704 +__u32
59705 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59706 +{
59707 + return 1;
59708 +}
59709 +
59710 +__u32
59711 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59712 +{
59713 + return 1;
59714 +}
59715 +
59716 +void
59717 +grsecurity_init(void)
59718 +{
59719 + return;
59720 +}
59721 +
59722 +umode_t gr_acl_umask(void)
59723 +{
59724 + return 0;
59725 +}
59726 +
59727 +__u32
59728 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59729 + const struct dentry * parent_dentry,
59730 + const struct vfsmount * parent_mnt,
59731 + const int mode)
59732 +{
59733 + return 1;
59734 +}
59735 +
59736 +__u32
59737 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
59738 + const struct dentry * parent_dentry,
59739 + const struct vfsmount * parent_mnt)
59740 +{
59741 + return 1;
59742 +}
59743 +
59744 +__u32
59745 +gr_acl_handle_symlink(const struct dentry * new_dentry,
59746 + const struct dentry * parent_dentry,
59747 + const struct vfsmount * parent_mnt, const struct filename *from)
59748 +{
59749 + return 1;
59750 +}
59751 +
59752 +__u32
59753 +gr_acl_handle_link(const struct dentry * new_dentry,
59754 + const struct dentry * parent_dentry,
59755 + const struct vfsmount * parent_mnt,
59756 + const struct dentry * old_dentry,
59757 + const struct vfsmount * old_mnt, const struct filename *to)
59758 +{
59759 + return 1;
59760 +}
59761 +
59762 +int
59763 +gr_acl_handle_rename(const struct dentry *new_dentry,
59764 + const struct dentry *parent_dentry,
59765 + const struct vfsmount *parent_mnt,
59766 + const struct dentry *old_dentry,
59767 + const struct inode *old_parent_inode,
59768 + const struct vfsmount *old_mnt, const struct filename *newname)
59769 +{
59770 + return 0;
59771 +}
59772 +
59773 +int
59774 +gr_acl_handle_filldir(const struct file *file, const char *name,
59775 + const int namelen, const ino_t ino)
59776 +{
59777 + return 1;
59778 +}
59779 +
59780 +int
59781 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59782 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59783 +{
59784 + return 1;
59785 +}
59786 +
59787 +int
59788 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59789 +{
59790 + return 0;
59791 +}
59792 +
59793 +int
59794 +gr_search_accept(const struct socket *sock)
59795 +{
59796 + return 0;
59797 +}
59798 +
59799 +int
59800 +gr_search_listen(const struct socket *sock)
59801 +{
59802 + return 0;
59803 +}
59804 +
59805 +int
59806 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59807 +{
59808 + return 0;
59809 +}
59810 +
59811 +__u32
59812 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
59813 +{
59814 + return 1;
59815 +}
59816 +
59817 +__u32
59818 +gr_acl_handle_creat(const struct dentry * dentry,
59819 + const struct dentry * p_dentry,
59820 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59821 + const int imode)
59822 +{
59823 + return 1;
59824 +}
59825 +
59826 +void
59827 +gr_acl_handle_exit(void)
59828 +{
59829 + return;
59830 +}
59831 +
59832 +int
59833 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59834 +{
59835 + return 1;
59836 +}
59837 +
59838 +void
59839 +gr_set_role_label(const uid_t uid, const gid_t gid)
59840 +{
59841 + return;
59842 +}
59843 +
59844 +int
59845 +gr_acl_handle_procpidmem(const struct task_struct *task)
59846 +{
59847 + return 0;
59848 +}
59849 +
59850 +int
59851 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
59852 +{
59853 + return 0;
59854 +}
59855 +
59856 +int
59857 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
59858 +{
59859 + return 0;
59860 +}
59861 +
59862 +void
59863 +gr_set_kernel_label(struct task_struct *task)
59864 +{
59865 + return;
59866 +}
59867 +
59868 +int
59869 +gr_check_user_change(int real, int effective, int fs)
59870 +{
59871 + return 0;
59872 +}
59873 +
59874 +int
59875 +gr_check_group_change(int real, int effective, int fs)
59876 +{
59877 + return 0;
59878 +}
59879 +
59880 +int gr_acl_enable_at_secure(void)
59881 +{
59882 + return 0;
59883 +}
59884 +
59885 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
59886 +{
59887 + return dentry->d_inode->i_sb->s_dev;
59888 +}
59889 +
59890 +void gr_put_exec_file(struct task_struct *task)
59891 +{
59892 + return;
59893 +}
59894 +
59895 +EXPORT_SYMBOL(gr_learn_resource);
59896 +EXPORT_SYMBOL(gr_set_kernel_label);
59897 +#ifdef CONFIG_SECURITY
59898 +EXPORT_SYMBOL(gr_check_user_change);
59899 +EXPORT_SYMBOL(gr_check_group_change);
59900 +#endif
59901 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
59902 new file mode 100644
59903 index 0000000..abfa971
59904 --- /dev/null
59905 +++ b/grsecurity/grsec_exec.c
59906 @@ -0,0 +1,174 @@
59907 +#include <linux/kernel.h>
59908 +#include <linux/sched.h>
59909 +#include <linux/file.h>
59910 +#include <linux/binfmts.h>
59911 +#include <linux/fs.h>
59912 +#include <linux/types.h>
59913 +#include <linux/grdefs.h>
59914 +#include <linux/grsecurity.h>
59915 +#include <linux/grinternal.h>
59916 +#include <linux/capability.h>
59917 +#include <linux/module.h>
59918 +
59919 +#include <asm/uaccess.h>
59920 +
59921 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59922 +static char gr_exec_arg_buf[132];
59923 +static DEFINE_MUTEX(gr_exec_arg_mutex);
59924 +#endif
59925 +
59926 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
59927 +
59928 +void
59929 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
59930 +{
59931 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59932 + char *grarg = gr_exec_arg_buf;
59933 + unsigned int i, x, execlen = 0;
59934 + char c;
59935 +
59936 + if (!((grsec_enable_execlog && grsec_enable_group &&
59937 + in_group_p(grsec_audit_gid))
59938 + || (grsec_enable_execlog && !grsec_enable_group)))
59939 + return;
59940 +
59941 + mutex_lock(&gr_exec_arg_mutex);
59942 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
59943 +
59944 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
59945 + const char __user *p;
59946 + unsigned int len;
59947 +
59948 + p = get_user_arg_ptr(argv, i);
59949 + if (IS_ERR(p))
59950 + goto log;
59951 +
59952 + len = strnlen_user(p, 128 - execlen);
59953 + if (len > 128 - execlen)
59954 + len = 128 - execlen;
59955 + else if (len > 0)
59956 + len--;
59957 + if (copy_from_user(grarg + execlen, p, len))
59958 + goto log;
59959 +
59960 + /* rewrite unprintable characters */
59961 + for (x = 0; x < len; x++) {
59962 + c = *(grarg + execlen + x);
59963 + if (c < 32 || c > 126)
59964 + *(grarg + execlen + x) = ' ';
59965 + }
59966 +
59967 + execlen += len;
59968 + *(grarg + execlen) = ' ';
59969 + *(grarg + execlen + 1) = '\0';
59970 + execlen++;
59971 + }
59972 +
59973 + log:
59974 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
59975 + bprm->file->f_path.mnt, grarg);
59976 + mutex_unlock(&gr_exec_arg_mutex);
59977 +#endif
59978 + return;
59979 +}
59980 +
59981 +#ifdef CONFIG_GRKERNSEC
59982 +extern int gr_acl_is_capable(const int cap);
59983 +extern int gr_acl_is_capable_nolog(const int cap);
59984 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59985 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
59986 +extern int gr_chroot_is_capable(const int cap);
59987 +extern int gr_chroot_is_capable_nolog(const int cap);
59988 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59989 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
59990 +#endif
59991 +
59992 +const char *captab_log[] = {
59993 + "CAP_CHOWN",
59994 + "CAP_DAC_OVERRIDE",
59995 + "CAP_DAC_READ_SEARCH",
59996 + "CAP_FOWNER",
59997 + "CAP_FSETID",
59998 + "CAP_KILL",
59999 + "CAP_SETGID",
60000 + "CAP_SETUID",
60001 + "CAP_SETPCAP",
60002 + "CAP_LINUX_IMMUTABLE",
60003 + "CAP_NET_BIND_SERVICE",
60004 + "CAP_NET_BROADCAST",
60005 + "CAP_NET_ADMIN",
60006 + "CAP_NET_RAW",
60007 + "CAP_IPC_LOCK",
60008 + "CAP_IPC_OWNER",
60009 + "CAP_SYS_MODULE",
60010 + "CAP_SYS_RAWIO",
60011 + "CAP_SYS_CHROOT",
60012 + "CAP_SYS_PTRACE",
60013 + "CAP_SYS_PACCT",
60014 + "CAP_SYS_ADMIN",
60015 + "CAP_SYS_BOOT",
60016 + "CAP_SYS_NICE",
60017 + "CAP_SYS_RESOURCE",
60018 + "CAP_SYS_TIME",
60019 + "CAP_SYS_TTY_CONFIG",
60020 + "CAP_MKNOD",
60021 + "CAP_LEASE",
60022 + "CAP_AUDIT_WRITE",
60023 + "CAP_AUDIT_CONTROL",
60024 + "CAP_SETFCAP",
60025 + "CAP_MAC_OVERRIDE",
60026 + "CAP_MAC_ADMIN",
60027 + "CAP_SYSLOG",
60028 + "CAP_WAKE_ALARM"
60029 +};
60030 +
60031 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60032 +
60033 +int gr_is_capable(const int cap)
60034 +{
60035 +#ifdef CONFIG_GRKERNSEC
60036 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60037 + return 1;
60038 + return 0;
60039 +#else
60040 + return 1;
60041 +#endif
60042 +}
60043 +
60044 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60045 +{
60046 +#ifdef CONFIG_GRKERNSEC
60047 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60048 + return 1;
60049 + return 0;
60050 +#else
60051 + return 1;
60052 +#endif
60053 +}
60054 +
60055 +int gr_is_capable_nolog(const int cap)
60056 +{
60057 +#ifdef CONFIG_GRKERNSEC
60058 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60059 + return 1;
60060 + return 0;
60061 +#else
60062 + return 1;
60063 +#endif
60064 +}
60065 +
60066 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60067 +{
60068 +#ifdef CONFIG_GRKERNSEC
60069 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60070 + return 1;
60071 + return 0;
60072 +#else
60073 + return 1;
60074 +#endif
60075 +}
60076 +
60077 +EXPORT_SYMBOL(gr_is_capable);
60078 +EXPORT_SYMBOL(gr_is_capable_nolog);
60079 +EXPORT_SYMBOL(gr_task_is_capable);
60080 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
60081 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60082 new file mode 100644
60083 index 0000000..d3ee748
60084 --- /dev/null
60085 +++ b/grsecurity/grsec_fifo.c
60086 @@ -0,0 +1,24 @@
60087 +#include <linux/kernel.h>
60088 +#include <linux/sched.h>
60089 +#include <linux/fs.h>
60090 +#include <linux/file.h>
60091 +#include <linux/grinternal.h>
60092 +
60093 +int
60094 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60095 + const struct dentry *dir, const int flag, const int acc_mode)
60096 +{
60097 +#ifdef CONFIG_GRKERNSEC_FIFO
60098 + const struct cred *cred = current_cred();
60099 +
60100 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60101 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60102 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60103 + (cred->fsuid != dentry->d_inode->i_uid)) {
60104 + if (!inode_permission(dentry->d_inode, acc_mode))
60105 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60106 + return -EACCES;
60107 + }
60108 +#endif
60109 + return 0;
60110 +}
60111 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60112 new file mode 100644
60113 index 0000000..8ca18bf
60114 --- /dev/null
60115 +++ b/grsecurity/grsec_fork.c
60116 @@ -0,0 +1,23 @@
60117 +#include <linux/kernel.h>
60118 +#include <linux/sched.h>
60119 +#include <linux/grsecurity.h>
60120 +#include <linux/grinternal.h>
60121 +#include <linux/errno.h>
60122 +
60123 +void
60124 +gr_log_forkfail(const int retval)
60125 +{
60126 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60127 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60128 + switch (retval) {
60129 + case -EAGAIN:
60130 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60131 + break;
60132 + case -ENOMEM:
60133 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60134 + break;
60135 + }
60136 + }
60137 +#endif
60138 + return;
60139 +}
60140 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60141 new file mode 100644
60142 index 0000000..05a6015
60143 --- /dev/null
60144 +++ b/grsecurity/grsec_init.c
60145 @@ -0,0 +1,283 @@
60146 +#include <linux/kernel.h>
60147 +#include <linux/sched.h>
60148 +#include <linux/mm.h>
60149 +#include <linux/gracl.h>
60150 +#include <linux/slab.h>
60151 +#include <linux/vmalloc.h>
60152 +#include <linux/percpu.h>
60153 +#include <linux/module.h>
60154 +
60155 +int grsec_enable_ptrace_readexec;
60156 +int grsec_enable_setxid;
60157 +int grsec_enable_symlinkown;
60158 +int grsec_symlinkown_gid;
60159 +int grsec_enable_brute;
60160 +int grsec_enable_link;
60161 +int grsec_enable_dmesg;
60162 +int grsec_enable_harden_ptrace;
60163 +int grsec_enable_fifo;
60164 +int grsec_enable_execlog;
60165 +int grsec_enable_signal;
60166 +int grsec_enable_forkfail;
60167 +int grsec_enable_audit_ptrace;
60168 +int grsec_enable_time;
60169 +int grsec_enable_audit_textrel;
60170 +int grsec_enable_group;
60171 +int grsec_audit_gid;
60172 +int grsec_enable_chdir;
60173 +int grsec_enable_mount;
60174 +int grsec_enable_rofs;
60175 +int grsec_enable_chroot_findtask;
60176 +int grsec_enable_chroot_mount;
60177 +int grsec_enable_chroot_shmat;
60178 +int grsec_enable_chroot_fchdir;
60179 +int grsec_enable_chroot_double;
60180 +int grsec_enable_chroot_pivot;
60181 +int grsec_enable_chroot_chdir;
60182 +int grsec_enable_chroot_chmod;
60183 +int grsec_enable_chroot_mknod;
60184 +int grsec_enable_chroot_nice;
60185 +int grsec_enable_chroot_execlog;
60186 +int grsec_enable_chroot_caps;
60187 +int grsec_enable_chroot_sysctl;
60188 +int grsec_enable_chroot_unix;
60189 +int grsec_enable_tpe;
60190 +int grsec_tpe_gid;
60191 +int grsec_enable_blackhole;
60192 +#ifdef CONFIG_IPV6_MODULE
60193 +EXPORT_SYMBOL(grsec_enable_blackhole);
60194 +#endif
60195 +int grsec_lastack_retries;
60196 +int grsec_enable_tpe_all;
60197 +int grsec_enable_tpe_invert;
60198 +int grsec_enable_socket_all;
60199 +int grsec_socket_all_gid;
60200 +int grsec_enable_socket_client;
60201 +int grsec_socket_client_gid;
60202 +int grsec_enable_socket_server;
60203 +int grsec_socket_server_gid;
60204 +int grsec_resource_logging;
60205 +int grsec_disable_privio;
60206 +int grsec_enable_log_rwxmaps;
60207 +int grsec_lock;
60208 +
60209 +DEFINE_SPINLOCK(grsec_alert_lock);
60210 +unsigned long grsec_alert_wtime = 0;
60211 +unsigned long grsec_alert_fyet = 0;
60212 +
60213 +DEFINE_SPINLOCK(grsec_audit_lock);
60214 +
60215 +DEFINE_RWLOCK(grsec_exec_file_lock);
60216 +
60217 +char *gr_shared_page[4];
60218 +
60219 +char *gr_alert_log_fmt;
60220 +char *gr_audit_log_fmt;
60221 +char *gr_alert_log_buf;
60222 +char *gr_audit_log_buf;
60223 +
60224 +extern struct gr_arg *gr_usermode;
60225 +extern unsigned char *gr_system_salt;
60226 +extern unsigned char *gr_system_sum;
60227 +
60228 +void __init
60229 +grsecurity_init(void)
60230 +{
60231 + int j;
60232 + /* create the per-cpu shared pages */
60233 +
60234 +#ifdef CONFIG_X86
60235 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60236 +#endif
60237 +
60238 + for (j = 0; j < 4; j++) {
60239 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60240 + if (gr_shared_page[j] == NULL) {
60241 + panic("Unable to allocate grsecurity shared page");
60242 + return;
60243 + }
60244 + }
60245 +
60246 + /* allocate log buffers */
60247 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60248 + if (!gr_alert_log_fmt) {
60249 + panic("Unable to allocate grsecurity alert log format buffer");
60250 + return;
60251 + }
60252 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60253 + if (!gr_audit_log_fmt) {
60254 + panic("Unable to allocate grsecurity audit log format buffer");
60255 + return;
60256 + }
60257 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60258 + if (!gr_alert_log_buf) {
60259 + panic("Unable to allocate grsecurity alert log buffer");
60260 + return;
60261 + }
60262 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60263 + if (!gr_audit_log_buf) {
60264 + panic("Unable to allocate grsecurity audit log buffer");
60265 + return;
60266 + }
60267 +
60268 + /* allocate memory for authentication structure */
60269 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60270 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60271 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60272 +
60273 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60274 + panic("Unable to allocate grsecurity authentication structure");
60275 + return;
60276 + }
60277 +
60278 +
60279 +#ifdef CONFIG_GRKERNSEC_IO
60280 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60281 + grsec_disable_privio = 1;
60282 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60283 + grsec_disable_privio = 1;
60284 +#else
60285 + grsec_disable_privio = 0;
60286 +#endif
60287 +#endif
60288 +
60289 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60290 + /* for backward compatibility, tpe_invert always defaults to on if
60291 + enabled in the kernel
60292 + */
60293 + grsec_enable_tpe_invert = 1;
60294 +#endif
60295 +
60296 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60297 +#ifndef CONFIG_GRKERNSEC_SYSCTL
60298 + grsec_lock = 1;
60299 +#endif
60300 +
60301 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60302 + grsec_enable_audit_textrel = 1;
60303 +#endif
60304 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60305 + grsec_enable_log_rwxmaps = 1;
60306 +#endif
60307 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60308 + grsec_enable_group = 1;
60309 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60310 +#endif
60311 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60312 + grsec_enable_ptrace_readexec = 1;
60313 +#endif
60314 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60315 + grsec_enable_chdir = 1;
60316 +#endif
60317 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60318 + grsec_enable_harden_ptrace = 1;
60319 +#endif
60320 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60321 + grsec_enable_mount = 1;
60322 +#endif
60323 +#ifdef CONFIG_GRKERNSEC_LINK
60324 + grsec_enable_link = 1;
60325 +#endif
60326 +#ifdef CONFIG_GRKERNSEC_BRUTE
60327 + grsec_enable_brute = 1;
60328 +#endif
60329 +#ifdef CONFIG_GRKERNSEC_DMESG
60330 + grsec_enable_dmesg = 1;
60331 +#endif
60332 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60333 + grsec_enable_blackhole = 1;
60334 + grsec_lastack_retries = 4;
60335 +#endif
60336 +#ifdef CONFIG_GRKERNSEC_FIFO
60337 + grsec_enable_fifo = 1;
60338 +#endif
60339 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60340 + grsec_enable_execlog = 1;
60341 +#endif
60342 +#ifdef CONFIG_GRKERNSEC_SETXID
60343 + grsec_enable_setxid = 1;
60344 +#endif
60345 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60346 + grsec_enable_signal = 1;
60347 +#endif
60348 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60349 + grsec_enable_forkfail = 1;
60350 +#endif
60351 +#ifdef CONFIG_GRKERNSEC_TIME
60352 + grsec_enable_time = 1;
60353 +#endif
60354 +#ifdef CONFIG_GRKERNSEC_RESLOG
60355 + grsec_resource_logging = 1;
60356 +#endif
60357 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60358 + grsec_enable_chroot_findtask = 1;
60359 +#endif
60360 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60361 + grsec_enable_chroot_unix = 1;
60362 +#endif
60363 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60364 + grsec_enable_chroot_mount = 1;
60365 +#endif
60366 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60367 + grsec_enable_chroot_fchdir = 1;
60368 +#endif
60369 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60370 + grsec_enable_chroot_shmat = 1;
60371 +#endif
60372 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60373 + grsec_enable_audit_ptrace = 1;
60374 +#endif
60375 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60376 + grsec_enable_chroot_double = 1;
60377 +#endif
60378 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60379 + grsec_enable_chroot_pivot = 1;
60380 +#endif
60381 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60382 + grsec_enable_chroot_chdir = 1;
60383 +#endif
60384 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60385 + grsec_enable_chroot_chmod = 1;
60386 +#endif
60387 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60388 + grsec_enable_chroot_mknod = 1;
60389 +#endif
60390 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60391 + grsec_enable_chroot_nice = 1;
60392 +#endif
60393 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60394 + grsec_enable_chroot_execlog = 1;
60395 +#endif
60396 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60397 + grsec_enable_chroot_caps = 1;
60398 +#endif
60399 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60400 + grsec_enable_chroot_sysctl = 1;
60401 +#endif
60402 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60403 + grsec_enable_symlinkown = 1;
60404 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60405 +#endif
60406 +#ifdef CONFIG_GRKERNSEC_TPE
60407 + grsec_enable_tpe = 1;
60408 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60409 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60410 + grsec_enable_tpe_all = 1;
60411 +#endif
60412 +#endif
60413 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60414 + grsec_enable_socket_all = 1;
60415 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60416 +#endif
60417 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60418 + grsec_enable_socket_client = 1;
60419 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60420 +#endif
60421 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60422 + grsec_enable_socket_server = 1;
60423 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60424 +#endif
60425 +#endif
60426 +
60427 + return;
60428 +}
60429 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60430 new file mode 100644
60431 index 0000000..6095407
60432 --- /dev/null
60433 +++ b/grsecurity/grsec_link.c
60434 @@ -0,0 +1,58 @@
60435 +#include <linux/kernel.h>
60436 +#include <linux/sched.h>
60437 +#include <linux/fs.h>
60438 +#include <linux/file.h>
60439 +#include <linux/grinternal.h>
60440 +
60441 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60442 +{
60443 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60444 + const struct inode *link_inode = link->dentry->d_inode;
60445 +
60446 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60447 + /* ignore root-owned links, e.g. /proc/self */
60448 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60449 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60450 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60451 + return 1;
60452 + }
60453 +#endif
60454 + return 0;
60455 +}
60456 +
60457 +int
60458 +gr_handle_follow_link(const struct inode *parent,
60459 + const struct inode *inode,
60460 + const struct dentry *dentry, const struct vfsmount *mnt)
60461 +{
60462 +#ifdef CONFIG_GRKERNSEC_LINK
60463 + const struct cred *cred = current_cred();
60464 +
60465 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60466 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60467 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60468 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60469 + return -EACCES;
60470 + }
60471 +#endif
60472 + return 0;
60473 +}
60474 +
60475 +int
60476 +gr_handle_hardlink(const struct dentry *dentry,
60477 + const struct vfsmount *mnt,
60478 + struct inode *inode, const int mode, const struct filename *to)
60479 +{
60480 +#ifdef CONFIG_GRKERNSEC_LINK
60481 + const struct cred *cred = current_cred();
60482 +
60483 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60484 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60485 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60486 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60487 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60488 + return -EPERM;
60489 + }
60490 +#endif
60491 + return 0;
60492 +}
60493 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60494 new file mode 100644
60495 index 0000000..a45d2e9
60496 --- /dev/null
60497 +++ b/grsecurity/grsec_log.c
60498 @@ -0,0 +1,322 @@
60499 +#include <linux/kernel.h>
60500 +#include <linux/sched.h>
60501 +#include <linux/file.h>
60502 +#include <linux/tty.h>
60503 +#include <linux/fs.h>
60504 +#include <linux/grinternal.h>
60505 +
60506 +#ifdef CONFIG_TREE_PREEMPT_RCU
60507 +#define DISABLE_PREEMPT() preempt_disable()
60508 +#define ENABLE_PREEMPT() preempt_enable()
60509 +#else
60510 +#define DISABLE_PREEMPT()
60511 +#define ENABLE_PREEMPT()
60512 +#endif
60513 +
60514 +#define BEGIN_LOCKS(x) \
60515 + DISABLE_PREEMPT(); \
60516 + rcu_read_lock(); \
60517 + read_lock(&tasklist_lock); \
60518 + read_lock(&grsec_exec_file_lock); \
60519 + if (x != GR_DO_AUDIT) \
60520 + spin_lock(&grsec_alert_lock); \
60521 + else \
60522 + spin_lock(&grsec_audit_lock)
60523 +
60524 +#define END_LOCKS(x) \
60525 + if (x != GR_DO_AUDIT) \
60526 + spin_unlock(&grsec_alert_lock); \
60527 + else \
60528 + spin_unlock(&grsec_audit_lock); \
60529 + read_unlock(&grsec_exec_file_lock); \
60530 + read_unlock(&tasklist_lock); \
60531 + rcu_read_unlock(); \
60532 + ENABLE_PREEMPT(); \
60533 + if (x == GR_DONT_AUDIT) \
60534 + gr_handle_alertkill(current)
60535 +
60536 +enum {
60537 + FLOODING,
60538 + NO_FLOODING
60539 +};
60540 +
60541 +extern char *gr_alert_log_fmt;
60542 +extern char *gr_audit_log_fmt;
60543 +extern char *gr_alert_log_buf;
60544 +extern char *gr_audit_log_buf;
60545 +
60546 +static int gr_log_start(int audit)
60547 +{
60548 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60549 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60550 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60551 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60552 + unsigned long curr_secs = get_seconds();
60553 +
60554 + if (audit == GR_DO_AUDIT)
60555 + goto set_fmt;
60556 +
60557 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60558 + grsec_alert_wtime = curr_secs;
60559 + grsec_alert_fyet = 0;
60560 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60561 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60562 + grsec_alert_fyet++;
60563 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60564 + grsec_alert_wtime = curr_secs;
60565 + grsec_alert_fyet++;
60566 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60567 + return FLOODING;
60568 + }
60569 + else return FLOODING;
60570 +
60571 +set_fmt:
60572 +#endif
60573 + memset(buf, 0, PAGE_SIZE);
60574 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60575 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60576 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60577 + } else if (current->signal->curr_ip) {
60578 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60579 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60580 + } else if (gr_acl_is_enabled()) {
60581 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60582 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60583 + } else {
60584 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60585 + strcpy(buf, fmt);
60586 + }
60587 +
60588 + return NO_FLOODING;
60589 +}
60590 +
60591 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60592 + __attribute__ ((format (printf, 2, 0)));
60593 +
60594 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60595 +{
60596 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60597 + unsigned int len = strlen(buf);
60598 +
60599 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60600 +
60601 + return;
60602 +}
60603 +
60604 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60605 + __attribute__ ((format (printf, 2, 3)));
60606 +
60607 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60608 +{
60609 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60610 + unsigned int len = strlen(buf);
60611 + va_list ap;
60612 +
60613 + va_start(ap, msg);
60614 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60615 + va_end(ap);
60616 +
60617 + return;
60618 +}
60619 +
60620 +static void gr_log_end(int audit, int append_default)
60621 +{
60622 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60623 +
60624 + if (append_default) {
60625 + unsigned int len = strlen(buf);
60626 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
60627 + }
60628 +
60629 + printk("%s\n", buf);
60630 +
60631 + return;
60632 +}
60633 +
60634 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60635 +{
60636 + int logtype;
60637 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60638 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60639 + void *voidptr = NULL;
60640 + int num1 = 0, num2 = 0;
60641 + unsigned long ulong1 = 0, ulong2 = 0;
60642 + struct dentry *dentry = NULL;
60643 + struct vfsmount *mnt = NULL;
60644 + struct file *file = NULL;
60645 + struct task_struct *task = NULL;
60646 + const struct cred *cred, *pcred;
60647 + va_list ap;
60648 +
60649 + BEGIN_LOCKS(audit);
60650 + logtype = gr_log_start(audit);
60651 + if (logtype == FLOODING) {
60652 + END_LOCKS(audit);
60653 + return;
60654 + }
60655 + va_start(ap, argtypes);
60656 + switch (argtypes) {
60657 + case GR_TTYSNIFF:
60658 + task = va_arg(ap, struct task_struct *);
60659 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
60660 + break;
60661 + case GR_SYSCTL_HIDDEN:
60662 + str1 = va_arg(ap, char *);
60663 + gr_log_middle_varargs(audit, msg, result, str1);
60664 + break;
60665 + case GR_RBAC:
60666 + dentry = va_arg(ap, struct dentry *);
60667 + mnt = va_arg(ap, struct vfsmount *);
60668 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60669 + break;
60670 + case GR_RBAC_STR:
60671 + dentry = va_arg(ap, struct dentry *);
60672 + mnt = va_arg(ap, struct vfsmount *);
60673 + str1 = va_arg(ap, char *);
60674 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60675 + break;
60676 + case GR_STR_RBAC:
60677 + str1 = va_arg(ap, char *);
60678 + dentry = va_arg(ap, struct dentry *);
60679 + mnt = va_arg(ap, struct vfsmount *);
60680 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60681 + break;
60682 + case GR_RBAC_MODE2:
60683 + dentry = va_arg(ap, struct dentry *);
60684 + mnt = va_arg(ap, struct vfsmount *);
60685 + str1 = va_arg(ap, char *);
60686 + str2 = va_arg(ap, char *);
60687 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60688 + break;
60689 + case GR_RBAC_MODE3:
60690 + dentry = va_arg(ap, struct dentry *);
60691 + mnt = va_arg(ap, struct vfsmount *);
60692 + str1 = va_arg(ap, char *);
60693 + str2 = va_arg(ap, char *);
60694 + str3 = va_arg(ap, char *);
60695 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60696 + break;
60697 + case GR_FILENAME:
60698 + dentry = va_arg(ap, struct dentry *);
60699 + mnt = va_arg(ap, struct vfsmount *);
60700 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60701 + break;
60702 + case GR_STR_FILENAME:
60703 + str1 = va_arg(ap, char *);
60704 + dentry = va_arg(ap, struct dentry *);
60705 + mnt = va_arg(ap, struct vfsmount *);
60706 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60707 + break;
60708 + case GR_FILENAME_STR:
60709 + dentry = va_arg(ap, struct dentry *);
60710 + mnt = va_arg(ap, struct vfsmount *);
60711 + str1 = va_arg(ap, char *);
60712 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60713 + break;
60714 + case GR_FILENAME_TWO_INT:
60715 + dentry = va_arg(ap, struct dentry *);
60716 + mnt = va_arg(ap, struct vfsmount *);
60717 + num1 = va_arg(ap, int);
60718 + num2 = va_arg(ap, int);
60719 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60720 + break;
60721 + case GR_FILENAME_TWO_INT_STR:
60722 + dentry = va_arg(ap, struct dentry *);
60723 + mnt = va_arg(ap, struct vfsmount *);
60724 + num1 = va_arg(ap, int);
60725 + num2 = va_arg(ap, int);
60726 + str1 = va_arg(ap, char *);
60727 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60728 + break;
60729 + case GR_TEXTREL:
60730 + file = va_arg(ap, struct file *);
60731 + ulong1 = va_arg(ap, unsigned long);
60732 + ulong2 = va_arg(ap, unsigned long);
60733 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60734 + break;
60735 + case GR_PTRACE:
60736 + task = va_arg(ap, struct task_struct *);
60737 + 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);
60738 + break;
60739 + case GR_RESOURCE:
60740 + task = va_arg(ap, struct task_struct *);
60741 + cred = __task_cred(task);
60742 + pcred = __task_cred(task->real_parent);
60743 + ulong1 = va_arg(ap, unsigned long);
60744 + str1 = va_arg(ap, char *);
60745 + ulong2 = va_arg(ap, unsigned long);
60746 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60747 + break;
60748 + case GR_CAP:
60749 + task = va_arg(ap, struct task_struct *);
60750 + cred = __task_cred(task);
60751 + pcred = __task_cred(task->real_parent);
60752 + str1 = va_arg(ap, char *);
60753 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60754 + break;
60755 + case GR_SIG:
60756 + str1 = va_arg(ap, char *);
60757 + voidptr = va_arg(ap, void *);
60758 + gr_log_middle_varargs(audit, msg, str1, voidptr);
60759 + break;
60760 + case GR_SIG2:
60761 + task = va_arg(ap, struct task_struct *);
60762 + cred = __task_cred(task);
60763 + pcred = __task_cred(task->real_parent);
60764 + num1 = va_arg(ap, int);
60765 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60766 + break;
60767 + case GR_CRASH1:
60768 + task = va_arg(ap, struct task_struct *);
60769 + cred = __task_cred(task);
60770 + pcred = __task_cred(task->real_parent);
60771 + ulong1 = va_arg(ap, unsigned long);
60772 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
60773 + break;
60774 + case GR_CRASH2:
60775 + task = va_arg(ap, struct task_struct *);
60776 + cred = __task_cred(task);
60777 + pcred = __task_cred(task->real_parent);
60778 + ulong1 = va_arg(ap, unsigned long);
60779 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
60780 + break;
60781 + case GR_RWXMAP:
60782 + file = va_arg(ap, struct file *);
60783 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60784 + break;
60785 + case GR_PSACCT:
60786 + {
60787 + unsigned int wday, cday;
60788 + __u8 whr, chr;
60789 + __u8 wmin, cmin;
60790 + __u8 wsec, csec;
60791 + char cur_tty[64] = { 0 };
60792 + char parent_tty[64] = { 0 };
60793 +
60794 + task = va_arg(ap, struct task_struct *);
60795 + wday = va_arg(ap, unsigned int);
60796 + cday = va_arg(ap, unsigned int);
60797 + whr = va_arg(ap, int);
60798 + chr = va_arg(ap, int);
60799 + wmin = va_arg(ap, int);
60800 + cmin = va_arg(ap, int);
60801 + wsec = va_arg(ap, int);
60802 + csec = va_arg(ap, int);
60803 + ulong1 = va_arg(ap, unsigned long);
60804 + cred = __task_cred(task);
60805 + pcred = __task_cred(task->real_parent);
60806 +
60807 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->gid, cred->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60808 + }
60809 + break;
60810 + default:
60811 + gr_log_middle(audit, msg, ap);
60812 + }
60813 + va_end(ap);
60814 + // these don't need DEFAULTSECARGS printed on the end
60815 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
60816 + gr_log_end(audit, 0);
60817 + else
60818 + gr_log_end(audit, 1);
60819 + END_LOCKS(audit);
60820 +}
60821 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
60822 new file mode 100644
60823 index 0000000..f536303
60824 --- /dev/null
60825 +++ b/grsecurity/grsec_mem.c
60826 @@ -0,0 +1,40 @@
60827 +#include <linux/kernel.h>
60828 +#include <linux/sched.h>
60829 +#include <linux/mm.h>
60830 +#include <linux/mman.h>
60831 +#include <linux/grinternal.h>
60832 +
60833 +void
60834 +gr_handle_ioperm(void)
60835 +{
60836 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
60837 + return;
60838 +}
60839 +
60840 +void
60841 +gr_handle_iopl(void)
60842 +{
60843 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
60844 + return;
60845 +}
60846 +
60847 +void
60848 +gr_handle_mem_readwrite(u64 from, u64 to)
60849 +{
60850 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
60851 + return;
60852 +}
60853 +
60854 +void
60855 +gr_handle_vm86(void)
60856 +{
60857 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
60858 + return;
60859 +}
60860 +
60861 +void
60862 +gr_log_badprocpid(const char *entry)
60863 +{
60864 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
60865 + return;
60866 +}
60867 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
60868 new file mode 100644
60869 index 0000000..2131422
60870 --- /dev/null
60871 +++ b/grsecurity/grsec_mount.c
60872 @@ -0,0 +1,62 @@
60873 +#include <linux/kernel.h>
60874 +#include <linux/sched.h>
60875 +#include <linux/mount.h>
60876 +#include <linux/grsecurity.h>
60877 +#include <linux/grinternal.h>
60878 +
60879 +void
60880 +gr_log_remount(const char *devname, const int retval)
60881 +{
60882 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60883 + if (grsec_enable_mount && (retval >= 0))
60884 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
60885 +#endif
60886 + return;
60887 +}
60888 +
60889 +void
60890 +gr_log_unmount(const char *devname, const int retval)
60891 +{
60892 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60893 + if (grsec_enable_mount && (retval >= 0))
60894 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
60895 +#endif
60896 + return;
60897 +}
60898 +
60899 +void
60900 +gr_log_mount(const char *from, const char *to, const int retval)
60901 +{
60902 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60903 + if (grsec_enable_mount && (retval >= 0))
60904 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
60905 +#endif
60906 + return;
60907 +}
60908 +
60909 +int
60910 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
60911 +{
60912 +#ifdef CONFIG_GRKERNSEC_ROFS
60913 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
60914 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
60915 + return -EPERM;
60916 + } else
60917 + return 0;
60918 +#endif
60919 + return 0;
60920 +}
60921 +
60922 +int
60923 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
60924 +{
60925 +#ifdef CONFIG_GRKERNSEC_ROFS
60926 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
60927 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
60928 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
60929 + return -EPERM;
60930 + } else
60931 + return 0;
60932 +#endif
60933 + return 0;
60934 +}
60935 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
60936 new file mode 100644
60937 index 0000000..a3b12a0
60938 --- /dev/null
60939 +++ b/grsecurity/grsec_pax.c
60940 @@ -0,0 +1,36 @@
60941 +#include <linux/kernel.h>
60942 +#include <linux/sched.h>
60943 +#include <linux/mm.h>
60944 +#include <linux/file.h>
60945 +#include <linux/grinternal.h>
60946 +#include <linux/grsecurity.h>
60947 +
60948 +void
60949 +gr_log_textrel(struct vm_area_struct * vma)
60950 +{
60951 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60952 + if (grsec_enable_audit_textrel)
60953 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
60954 +#endif
60955 + return;
60956 +}
60957 +
60958 +void
60959 +gr_log_rwxmmap(struct file *file)
60960 +{
60961 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60962 + if (grsec_enable_log_rwxmaps)
60963 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
60964 +#endif
60965 + return;
60966 +}
60967 +
60968 +void
60969 +gr_log_rwxmprotect(struct file *file)
60970 +{
60971 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60972 + if (grsec_enable_log_rwxmaps)
60973 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
60974 +#endif
60975 + return;
60976 +}
60977 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
60978 new file mode 100644
60979 index 0000000..f7f29aa
60980 --- /dev/null
60981 +++ b/grsecurity/grsec_ptrace.c
60982 @@ -0,0 +1,30 @@
60983 +#include <linux/kernel.h>
60984 +#include <linux/sched.h>
60985 +#include <linux/grinternal.h>
60986 +#include <linux/security.h>
60987 +
60988 +void
60989 +gr_audit_ptrace(struct task_struct *task)
60990 +{
60991 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60992 + if (grsec_enable_audit_ptrace)
60993 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
60994 +#endif
60995 + return;
60996 +}
60997 +
60998 +int
60999 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
61000 +{
61001 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61002 + const struct dentry *dentry = file->f_path.dentry;
61003 + const struct vfsmount *mnt = file->f_path.mnt;
61004 +
61005 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61006 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61007 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61008 + return -EACCES;
61009 + }
61010 +#endif
61011 + return 0;
61012 +}
61013 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61014 new file mode 100644
61015 index 0000000..5c00416
61016 --- /dev/null
61017 +++ b/grsecurity/grsec_sig.c
61018 @@ -0,0 +1,222 @@
61019 +#include <linux/kernel.h>
61020 +#include <linux/sched.h>
61021 +#include <linux/delay.h>
61022 +#include <linux/grsecurity.h>
61023 +#include <linux/grinternal.h>
61024 +#include <linux/hardirq.h>
61025 +
61026 +char *signames[] = {
61027 + [SIGSEGV] = "Segmentation fault",
61028 + [SIGILL] = "Illegal instruction",
61029 + [SIGABRT] = "Abort",
61030 + [SIGBUS] = "Invalid alignment/Bus error"
61031 +};
61032 +
61033 +void
61034 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61035 +{
61036 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61037 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61038 + (sig == SIGABRT) || (sig == SIGBUS))) {
61039 + if (t->pid == current->pid) {
61040 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61041 + } else {
61042 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61043 + }
61044 + }
61045 +#endif
61046 + return;
61047 +}
61048 +
61049 +int
61050 +gr_handle_signal(const struct task_struct *p, const int sig)
61051 +{
61052 +#ifdef CONFIG_GRKERNSEC
61053 + /* ignore the 0 signal for protected task checks */
61054 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61055 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61056 + return -EPERM;
61057 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61058 + return -EPERM;
61059 + }
61060 +#endif
61061 + return 0;
61062 +}
61063 +
61064 +#ifdef CONFIG_GRKERNSEC
61065 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61066 +
61067 +int gr_fake_force_sig(int sig, struct task_struct *t)
61068 +{
61069 + unsigned long int flags;
61070 + int ret, blocked, ignored;
61071 + struct k_sigaction *action;
61072 +
61073 + spin_lock_irqsave(&t->sighand->siglock, flags);
61074 + action = &t->sighand->action[sig-1];
61075 + ignored = action->sa.sa_handler == SIG_IGN;
61076 + blocked = sigismember(&t->blocked, sig);
61077 + if (blocked || ignored) {
61078 + action->sa.sa_handler = SIG_DFL;
61079 + if (blocked) {
61080 + sigdelset(&t->blocked, sig);
61081 + recalc_sigpending_and_wake(t);
61082 + }
61083 + }
61084 + if (action->sa.sa_handler == SIG_DFL)
61085 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
61086 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61087 +
61088 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
61089 +
61090 + return ret;
61091 +}
61092 +#endif
61093 +
61094 +#ifdef CONFIG_GRKERNSEC_BRUTE
61095 +#define GR_USER_BAN_TIME (15 * 60)
61096 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
61097 +
61098 +static int __get_dumpable(unsigned long mm_flags)
61099 +{
61100 + int ret;
61101 +
61102 + ret = mm_flags & MMF_DUMPABLE_MASK;
61103 + return (ret >= 2) ? 2 : ret;
61104 +}
61105 +#endif
61106 +
61107 +void gr_handle_brute_attach(unsigned long mm_flags)
61108 +{
61109 +#ifdef CONFIG_GRKERNSEC_BRUTE
61110 + struct task_struct *p = current;
61111 + kuid_t uid = GLOBAL_ROOT_UID;
61112 + int daemon = 0;
61113 +
61114 + if (!grsec_enable_brute)
61115 + return;
61116 +
61117 + rcu_read_lock();
61118 + read_lock(&tasklist_lock);
61119 + read_lock(&grsec_exec_file_lock);
61120 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61121 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61122 + p->real_parent->brute = 1;
61123 + daemon = 1;
61124 + } else {
61125 + const struct cred *cred = __task_cred(p), *cred2;
61126 + struct task_struct *tsk, *tsk2;
61127 +
61128 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61129 + struct user_struct *user;
61130 +
61131 + uid = cred->uid;
61132 +
61133 + /* this is put upon execution past expiration */
61134 + user = find_user(uid);
61135 + if (user == NULL)
61136 + goto unlock;
61137 + user->banned = 1;
61138 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61139 + if (user->ban_expires == ~0UL)
61140 + user->ban_expires--;
61141 +
61142 + do_each_thread(tsk2, tsk) {
61143 + cred2 = __task_cred(tsk);
61144 + if (tsk != p && uid_eq(cred2->uid, uid))
61145 + gr_fake_force_sig(SIGKILL, tsk);
61146 + } while_each_thread(tsk2, tsk);
61147 + }
61148 + }
61149 +unlock:
61150 + read_unlock(&grsec_exec_file_lock);
61151 + read_unlock(&tasklist_lock);
61152 + rcu_read_unlock();
61153 +
61154 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
61155 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61156 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61157 + else if (daemon)
61158 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61159 +
61160 +#endif
61161 + return;
61162 +}
61163 +
61164 +void gr_handle_brute_check(void)
61165 +{
61166 +#ifdef CONFIG_GRKERNSEC_BRUTE
61167 + struct task_struct *p = current;
61168 +
61169 + if (unlikely(p->brute)) {
61170 + if (!grsec_enable_brute)
61171 + p->brute = 0;
61172 + else if (time_before(get_seconds(), p->brute_expires))
61173 + msleep(30 * 1000);
61174 + }
61175 +#endif
61176 + return;
61177 +}
61178 +
61179 +void gr_handle_kernel_exploit(void)
61180 +{
61181 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61182 + const struct cred *cred;
61183 + struct task_struct *tsk, *tsk2;
61184 + struct user_struct *user;
61185 + kuid_t uid;
61186 +
61187 + if (in_irq() || in_serving_softirq() || in_nmi())
61188 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61189 +
61190 + uid = current_uid();
61191 +
61192 + if (uid_eq(uid, GLOBAL_ROOT_UID))
61193 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
61194 + else {
61195 + /* kill all the processes of this user, hold a reference
61196 + to their creds struct, and prevent them from creating
61197 + another process until system reset
61198 + */
61199 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61200 + from_kuid_munged(&init_user_ns, uid));
61201 + /* we intentionally leak this ref */
61202 + user = get_uid(current->cred->user);
61203 + if (user) {
61204 + user->banned = 1;
61205 + user->ban_expires = ~0UL;
61206 + }
61207 +
61208 + read_lock(&tasklist_lock);
61209 + do_each_thread(tsk2, tsk) {
61210 + cred = __task_cred(tsk);
61211 + if (uid_eq(cred->uid, uid))
61212 + gr_fake_force_sig(SIGKILL, tsk);
61213 + } while_each_thread(tsk2, tsk);
61214 + read_unlock(&tasklist_lock);
61215 + }
61216 +#endif
61217 +}
61218 +
61219 +int __gr_process_user_ban(struct user_struct *user)
61220 +{
61221 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61222 + if (unlikely(user->banned)) {
61223 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61224 + user->banned = 0;
61225 + user->ban_expires = 0;
61226 + free_uid(user);
61227 + } else
61228 + return -EPERM;
61229 + }
61230 +#endif
61231 + return 0;
61232 +}
61233 +
61234 +int gr_process_user_ban(void)
61235 +{
61236 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61237 + return __gr_process_user_ban(current->cred->user);
61238 +#endif
61239 + return 0;
61240 +}
61241 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61242 new file mode 100644
61243 index 0000000..4030d57
61244 --- /dev/null
61245 +++ b/grsecurity/grsec_sock.c
61246 @@ -0,0 +1,244 @@
61247 +#include <linux/kernel.h>
61248 +#include <linux/module.h>
61249 +#include <linux/sched.h>
61250 +#include <linux/file.h>
61251 +#include <linux/net.h>
61252 +#include <linux/in.h>
61253 +#include <linux/ip.h>
61254 +#include <net/sock.h>
61255 +#include <net/inet_sock.h>
61256 +#include <linux/grsecurity.h>
61257 +#include <linux/grinternal.h>
61258 +#include <linux/gracl.h>
61259 +
61260 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61261 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61262 +
61263 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
61264 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
61265 +
61266 +#ifdef CONFIG_UNIX_MODULE
61267 +EXPORT_SYMBOL(gr_acl_handle_unix);
61268 +EXPORT_SYMBOL(gr_acl_handle_mknod);
61269 +EXPORT_SYMBOL(gr_handle_chroot_unix);
61270 +EXPORT_SYMBOL(gr_handle_create);
61271 +#endif
61272 +
61273 +#ifdef CONFIG_GRKERNSEC
61274 +#define gr_conn_table_size 32749
61275 +struct conn_table_entry {
61276 + struct conn_table_entry *next;
61277 + struct signal_struct *sig;
61278 +};
61279 +
61280 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61281 +DEFINE_SPINLOCK(gr_conn_table_lock);
61282 +
61283 +extern const char * gr_socktype_to_name(unsigned char type);
61284 +extern const char * gr_proto_to_name(unsigned char proto);
61285 +extern const char * gr_sockfamily_to_name(unsigned char family);
61286 +
61287 +static __inline__ int
61288 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61289 +{
61290 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61291 +}
61292 +
61293 +static __inline__ int
61294 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61295 + __u16 sport, __u16 dport)
61296 +{
61297 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61298 + sig->gr_sport == sport && sig->gr_dport == dport))
61299 + return 1;
61300 + else
61301 + return 0;
61302 +}
61303 +
61304 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61305 +{
61306 + struct conn_table_entry **match;
61307 + unsigned int index;
61308 +
61309 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61310 + sig->gr_sport, sig->gr_dport,
61311 + gr_conn_table_size);
61312 +
61313 + newent->sig = sig;
61314 +
61315 + match = &gr_conn_table[index];
61316 + newent->next = *match;
61317 + *match = newent;
61318 +
61319 + return;
61320 +}
61321 +
61322 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61323 +{
61324 + struct conn_table_entry *match, *last = NULL;
61325 + unsigned int index;
61326 +
61327 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61328 + sig->gr_sport, sig->gr_dport,
61329 + gr_conn_table_size);
61330 +
61331 + match = gr_conn_table[index];
61332 + while (match && !conn_match(match->sig,
61333 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61334 + sig->gr_dport)) {
61335 + last = match;
61336 + match = match->next;
61337 + }
61338 +
61339 + if (match) {
61340 + if (last)
61341 + last->next = match->next;
61342 + else
61343 + gr_conn_table[index] = NULL;
61344 + kfree(match);
61345 + }
61346 +
61347 + return;
61348 +}
61349 +
61350 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61351 + __u16 sport, __u16 dport)
61352 +{
61353 + struct conn_table_entry *match;
61354 + unsigned int index;
61355 +
61356 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61357 +
61358 + match = gr_conn_table[index];
61359 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61360 + match = match->next;
61361 +
61362 + if (match)
61363 + return match->sig;
61364 + else
61365 + return NULL;
61366 +}
61367 +
61368 +#endif
61369 +
61370 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61371 +{
61372 +#ifdef CONFIG_GRKERNSEC
61373 + struct signal_struct *sig = task->signal;
61374 + struct conn_table_entry *newent;
61375 +
61376 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61377 + if (newent == NULL)
61378 + return;
61379 + /* no bh lock needed since we are called with bh disabled */
61380 + spin_lock(&gr_conn_table_lock);
61381 + gr_del_task_from_ip_table_nolock(sig);
61382 + sig->gr_saddr = inet->inet_rcv_saddr;
61383 + sig->gr_daddr = inet->inet_daddr;
61384 + sig->gr_sport = inet->inet_sport;
61385 + sig->gr_dport = inet->inet_dport;
61386 + gr_add_to_task_ip_table_nolock(sig, newent);
61387 + spin_unlock(&gr_conn_table_lock);
61388 +#endif
61389 + return;
61390 +}
61391 +
61392 +void gr_del_task_from_ip_table(struct task_struct *task)
61393 +{
61394 +#ifdef CONFIG_GRKERNSEC
61395 + spin_lock_bh(&gr_conn_table_lock);
61396 + gr_del_task_from_ip_table_nolock(task->signal);
61397 + spin_unlock_bh(&gr_conn_table_lock);
61398 +#endif
61399 + return;
61400 +}
61401 +
61402 +void
61403 +gr_attach_curr_ip(const struct sock *sk)
61404 +{
61405 +#ifdef CONFIG_GRKERNSEC
61406 + struct signal_struct *p, *set;
61407 + const struct inet_sock *inet = inet_sk(sk);
61408 +
61409 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61410 + return;
61411 +
61412 + set = current->signal;
61413 +
61414 + spin_lock_bh(&gr_conn_table_lock);
61415 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61416 + inet->inet_dport, inet->inet_sport);
61417 + if (unlikely(p != NULL)) {
61418 + set->curr_ip = p->curr_ip;
61419 + set->used_accept = 1;
61420 + gr_del_task_from_ip_table_nolock(p);
61421 + spin_unlock_bh(&gr_conn_table_lock);
61422 + return;
61423 + }
61424 + spin_unlock_bh(&gr_conn_table_lock);
61425 +
61426 + set->curr_ip = inet->inet_daddr;
61427 + set->used_accept = 1;
61428 +#endif
61429 + return;
61430 +}
61431 +
61432 +int
61433 +gr_handle_sock_all(const int family, const int type, const int protocol)
61434 +{
61435 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61436 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61437 + (family != AF_UNIX)) {
61438 + if (family == AF_INET)
61439 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61440 + else
61441 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61442 + return -EACCES;
61443 + }
61444 +#endif
61445 + return 0;
61446 +}
61447 +
61448 +int
61449 +gr_handle_sock_server(const struct sockaddr *sck)
61450 +{
61451 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61452 + if (grsec_enable_socket_server &&
61453 + in_group_p(grsec_socket_server_gid) &&
61454 + sck && (sck->sa_family != AF_UNIX) &&
61455 + (sck->sa_family != AF_LOCAL)) {
61456 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61457 + return -EACCES;
61458 + }
61459 +#endif
61460 + return 0;
61461 +}
61462 +
61463 +int
61464 +gr_handle_sock_server_other(const struct sock *sck)
61465 +{
61466 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61467 + if (grsec_enable_socket_server &&
61468 + in_group_p(grsec_socket_server_gid) &&
61469 + sck && (sck->sk_family != AF_UNIX) &&
61470 + (sck->sk_family != AF_LOCAL)) {
61471 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61472 + return -EACCES;
61473 + }
61474 +#endif
61475 + return 0;
61476 +}
61477 +
61478 +int
61479 +gr_handle_sock_client(const struct sockaddr *sck)
61480 +{
61481 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61482 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61483 + sck && (sck->sa_family != AF_UNIX) &&
61484 + (sck->sa_family != AF_LOCAL)) {
61485 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61486 + return -EACCES;
61487 + }
61488 +#endif
61489 + return 0;
61490 +}
61491 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61492 new file mode 100644
61493 index 0000000..f55ef0f
61494 --- /dev/null
61495 +++ b/grsecurity/grsec_sysctl.c
61496 @@ -0,0 +1,469 @@
61497 +#include <linux/kernel.h>
61498 +#include <linux/sched.h>
61499 +#include <linux/sysctl.h>
61500 +#include <linux/grsecurity.h>
61501 +#include <linux/grinternal.h>
61502 +
61503 +int
61504 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61505 +{
61506 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61507 + if (dirname == NULL || name == NULL)
61508 + return 0;
61509 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61510 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61511 + return -EACCES;
61512 + }
61513 +#endif
61514 + return 0;
61515 +}
61516 +
61517 +#ifdef CONFIG_GRKERNSEC_ROFS
61518 +static int __maybe_unused one = 1;
61519 +#endif
61520 +
61521 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61522 +struct ctl_table grsecurity_table[] = {
61523 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61524 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61525 +#ifdef CONFIG_GRKERNSEC_IO
61526 + {
61527 + .procname = "disable_priv_io",
61528 + .data = &grsec_disable_privio,
61529 + .maxlen = sizeof(int),
61530 + .mode = 0600,
61531 + .proc_handler = &proc_dointvec,
61532 + },
61533 +#endif
61534 +#endif
61535 +#ifdef CONFIG_GRKERNSEC_LINK
61536 + {
61537 + .procname = "linking_restrictions",
61538 + .data = &grsec_enable_link,
61539 + .maxlen = sizeof(int),
61540 + .mode = 0600,
61541 + .proc_handler = &proc_dointvec,
61542 + },
61543 +#endif
61544 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61545 + {
61546 + .procname = "enforce_symlinksifowner",
61547 + .data = &grsec_enable_symlinkown,
61548 + .maxlen = sizeof(int),
61549 + .mode = 0600,
61550 + .proc_handler = &proc_dointvec,
61551 + },
61552 + {
61553 + .procname = "symlinkown_gid",
61554 + .data = &grsec_symlinkown_gid,
61555 + .maxlen = sizeof(int),
61556 + .mode = 0600,
61557 + .proc_handler = &proc_dointvec,
61558 + },
61559 +#endif
61560 +#ifdef CONFIG_GRKERNSEC_BRUTE
61561 + {
61562 + .procname = "deter_bruteforce",
61563 + .data = &grsec_enable_brute,
61564 + .maxlen = sizeof(int),
61565 + .mode = 0600,
61566 + .proc_handler = &proc_dointvec,
61567 + },
61568 +#endif
61569 +#ifdef CONFIG_GRKERNSEC_FIFO
61570 + {
61571 + .procname = "fifo_restrictions",
61572 + .data = &grsec_enable_fifo,
61573 + .maxlen = sizeof(int),
61574 + .mode = 0600,
61575 + .proc_handler = &proc_dointvec,
61576 + },
61577 +#endif
61578 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61579 + {
61580 + .procname = "ptrace_readexec",
61581 + .data = &grsec_enable_ptrace_readexec,
61582 + .maxlen = sizeof(int),
61583 + .mode = 0600,
61584 + .proc_handler = &proc_dointvec,
61585 + },
61586 +#endif
61587 +#ifdef CONFIG_GRKERNSEC_SETXID
61588 + {
61589 + .procname = "consistent_setxid",
61590 + .data = &grsec_enable_setxid,
61591 + .maxlen = sizeof(int),
61592 + .mode = 0600,
61593 + .proc_handler = &proc_dointvec,
61594 + },
61595 +#endif
61596 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61597 + {
61598 + .procname = "ip_blackhole",
61599 + .data = &grsec_enable_blackhole,
61600 + .maxlen = sizeof(int),
61601 + .mode = 0600,
61602 + .proc_handler = &proc_dointvec,
61603 + },
61604 + {
61605 + .procname = "lastack_retries",
61606 + .data = &grsec_lastack_retries,
61607 + .maxlen = sizeof(int),
61608 + .mode = 0600,
61609 + .proc_handler = &proc_dointvec,
61610 + },
61611 +#endif
61612 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61613 + {
61614 + .procname = "exec_logging",
61615 + .data = &grsec_enable_execlog,
61616 + .maxlen = sizeof(int),
61617 + .mode = 0600,
61618 + .proc_handler = &proc_dointvec,
61619 + },
61620 +#endif
61621 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61622 + {
61623 + .procname = "rwxmap_logging",
61624 + .data = &grsec_enable_log_rwxmaps,
61625 + .maxlen = sizeof(int),
61626 + .mode = 0600,
61627 + .proc_handler = &proc_dointvec,
61628 + },
61629 +#endif
61630 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61631 + {
61632 + .procname = "signal_logging",
61633 + .data = &grsec_enable_signal,
61634 + .maxlen = sizeof(int),
61635 + .mode = 0600,
61636 + .proc_handler = &proc_dointvec,
61637 + },
61638 +#endif
61639 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61640 + {
61641 + .procname = "forkfail_logging",
61642 + .data = &grsec_enable_forkfail,
61643 + .maxlen = sizeof(int),
61644 + .mode = 0600,
61645 + .proc_handler = &proc_dointvec,
61646 + },
61647 +#endif
61648 +#ifdef CONFIG_GRKERNSEC_TIME
61649 + {
61650 + .procname = "timechange_logging",
61651 + .data = &grsec_enable_time,
61652 + .maxlen = sizeof(int),
61653 + .mode = 0600,
61654 + .proc_handler = &proc_dointvec,
61655 + },
61656 +#endif
61657 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61658 + {
61659 + .procname = "chroot_deny_shmat",
61660 + .data = &grsec_enable_chroot_shmat,
61661 + .maxlen = sizeof(int),
61662 + .mode = 0600,
61663 + .proc_handler = &proc_dointvec,
61664 + },
61665 +#endif
61666 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61667 + {
61668 + .procname = "chroot_deny_unix",
61669 + .data = &grsec_enable_chroot_unix,
61670 + .maxlen = sizeof(int),
61671 + .mode = 0600,
61672 + .proc_handler = &proc_dointvec,
61673 + },
61674 +#endif
61675 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61676 + {
61677 + .procname = "chroot_deny_mount",
61678 + .data = &grsec_enable_chroot_mount,
61679 + .maxlen = sizeof(int),
61680 + .mode = 0600,
61681 + .proc_handler = &proc_dointvec,
61682 + },
61683 +#endif
61684 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61685 + {
61686 + .procname = "chroot_deny_fchdir",
61687 + .data = &grsec_enable_chroot_fchdir,
61688 + .maxlen = sizeof(int),
61689 + .mode = 0600,
61690 + .proc_handler = &proc_dointvec,
61691 + },
61692 +#endif
61693 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61694 + {
61695 + .procname = "chroot_deny_chroot",
61696 + .data = &grsec_enable_chroot_double,
61697 + .maxlen = sizeof(int),
61698 + .mode = 0600,
61699 + .proc_handler = &proc_dointvec,
61700 + },
61701 +#endif
61702 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61703 + {
61704 + .procname = "chroot_deny_pivot",
61705 + .data = &grsec_enable_chroot_pivot,
61706 + .maxlen = sizeof(int),
61707 + .mode = 0600,
61708 + .proc_handler = &proc_dointvec,
61709 + },
61710 +#endif
61711 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61712 + {
61713 + .procname = "chroot_enforce_chdir",
61714 + .data = &grsec_enable_chroot_chdir,
61715 + .maxlen = sizeof(int),
61716 + .mode = 0600,
61717 + .proc_handler = &proc_dointvec,
61718 + },
61719 +#endif
61720 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61721 + {
61722 + .procname = "chroot_deny_chmod",
61723 + .data = &grsec_enable_chroot_chmod,
61724 + .maxlen = sizeof(int),
61725 + .mode = 0600,
61726 + .proc_handler = &proc_dointvec,
61727 + },
61728 +#endif
61729 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61730 + {
61731 + .procname = "chroot_deny_mknod",
61732 + .data = &grsec_enable_chroot_mknod,
61733 + .maxlen = sizeof(int),
61734 + .mode = 0600,
61735 + .proc_handler = &proc_dointvec,
61736 + },
61737 +#endif
61738 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61739 + {
61740 + .procname = "chroot_restrict_nice",
61741 + .data = &grsec_enable_chroot_nice,
61742 + .maxlen = sizeof(int),
61743 + .mode = 0600,
61744 + .proc_handler = &proc_dointvec,
61745 + },
61746 +#endif
61747 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61748 + {
61749 + .procname = "chroot_execlog",
61750 + .data = &grsec_enable_chroot_execlog,
61751 + .maxlen = sizeof(int),
61752 + .mode = 0600,
61753 + .proc_handler = &proc_dointvec,
61754 + },
61755 +#endif
61756 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61757 + {
61758 + .procname = "chroot_caps",
61759 + .data = &grsec_enable_chroot_caps,
61760 + .maxlen = sizeof(int),
61761 + .mode = 0600,
61762 + .proc_handler = &proc_dointvec,
61763 + },
61764 +#endif
61765 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61766 + {
61767 + .procname = "chroot_deny_sysctl",
61768 + .data = &grsec_enable_chroot_sysctl,
61769 + .maxlen = sizeof(int),
61770 + .mode = 0600,
61771 + .proc_handler = &proc_dointvec,
61772 + },
61773 +#endif
61774 +#ifdef CONFIG_GRKERNSEC_TPE
61775 + {
61776 + .procname = "tpe",
61777 + .data = &grsec_enable_tpe,
61778 + .maxlen = sizeof(int),
61779 + .mode = 0600,
61780 + .proc_handler = &proc_dointvec,
61781 + },
61782 + {
61783 + .procname = "tpe_gid",
61784 + .data = &grsec_tpe_gid,
61785 + .maxlen = sizeof(int),
61786 + .mode = 0600,
61787 + .proc_handler = &proc_dointvec,
61788 + },
61789 +#endif
61790 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61791 + {
61792 + .procname = "tpe_invert",
61793 + .data = &grsec_enable_tpe_invert,
61794 + .maxlen = sizeof(int),
61795 + .mode = 0600,
61796 + .proc_handler = &proc_dointvec,
61797 + },
61798 +#endif
61799 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61800 + {
61801 + .procname = "tpe_restrict_all",
61802 + .data = &grsec_enable_tpe_all,
61803 + .maxlen = sizeof(int),
61804 + .mode = 0600,
61805 + .proc_handler = &proc_dointvec,
61806 + },
61807 +#endif
61808 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61809 + {
61810 + .procname = "socket_all",
61811 + .data = &grsec_enable_socket_all,
61812 + .maxlen = sizeof(int),
61813 + .mode = 0600,
61814 + .proc_handler = &proc_dointvec,
61815 + },
61816 + {
61817 + .procname = "socket_all_gid",
61818 + .data = &grsec_socket_all_gid,
61819 + .maxlen = sizeof(int),
61820 + .mode = 0600,
61821 + .proc_handler = &proc_dointvec,
61822 + },
61823 +#endif
61824 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61825 + {
61826 + .procname = "socket_client",
61827 + .data = &grsec_enable_socket_client,
61828 + .maxlen = sizeof(int),
61829 + .mode = 0600,
61830 + .proc_handler = &proc_dointvec,
61831 + },
61832 + {
61833 + .procname = "socket_client_gid",
61834 + .data = &grsec_socket_client_gid,
61835 + .maxlen = sizeof(int),
61836 + .mode = 0600,
61837 + .proc_handler = &proc_dointvec,
61838 + },
61839 +#endif
61840 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61841 + {
61842 + .procname = "socket_server",
61843 + .data = &grsec_enable_socket_server,
61844 + .maxlen = sizeof(int),
61845 + .mode = 0600,
61846 + .proc_handler = &proc_dointvec,
61847 + },
61848 + {
61849 + .procname = "socket_server_gid",
61850 + .data = &grsec_socket_server_gid,
61851 + .maxlen = sizeof(int),
61852 + .mode = 0600,
61853 + .proc_handler = &proc_dointvec,
61854 + },
61855 +#endif
61856 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61857 + {
61858 + .procname = "audit_group",
61859 + .data = &grsec_enable_group,
61860 + .maxlen = sizeof(int),
61861 + .mode = 0600,
61862 + .proc_handler = &proc_dointvec,
61863 + },
61864 + {
61865 + .procname = "audit_gid",
61866 + .data = &grsec_audit_gid,
61867 + .maxlen = sizeof(int),
61868 + .mode = 0600,
61869 + .proc_handler = &proc_dointvec,
61870 + },
61871 +#endif
61872 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61873 + {
61874 + .procname = "audit_chdir",
61875 + .data = &grsec_enable_chdir,
61876 + .maxlen = sizeof(int),
61877 + .mode = 0600,
61878 + .proc_handler = &proc_dointvec,
61879 + },
61880 +#endif
61881 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61882 + {
61883 + .procname = "audit_mount",
61884 + .data = &grsec_enable_mount,
61885 + .maxlen = sizeof(int),
61886 + .mode = 0600,
61887 + .proc_handler = &proc_dointvec,
61888 + },
61889 +#endif
61890 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61891 + {
61892 + .procname = "audit_textrel",
61893 + .data = &grsec_enable_audit_textrel,
61894 + .maxlen = sizeof(int),
61895 + .mode = 0600,
61896 + .proc_handler = &proc_dointvec,
61897 + },
61898 +#endif
61899 +#ifdef CONFIG_GRKERNSEC_DMESG
61900 + {
61901 + .procname = "dmesg",
61902 + .data = &grsec_enable_dmesg,
61903 + .maxlen = sizeof(int),
61904 + .mode = 0600,
61905 + .proc_handler = &proc_dointvec,
61906 + },
61907 +#endif
61908 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61909 + {
61910 + .procname = "chroot_findtask",
61911 + .data = &grsec_enable_chroot_findtask,
61912 + .maxlen = sizeof(int),
61913 + .mode = 0600,
61914 + .proc_handler = &proc_dointvec,
61915 + },
61916 +#endif
61917 +#ifdef CONFIG_GRKERNSEC_RESLOG
61918 + {
61919 + .procname = "resource_logging",
61920 + .data = &grsec_resource_logging,
61921 + .maxlen = sizeof(int),
61922 + .mode = 0600,
61923 + .proc_handler = &proc_dointvec,
61924 + },
61925 +#endif
61926 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61927 + {
61928 + .procname = "audit_ptrace",
61929 + .data = &grsec_enable_audit_ptrace,
61930 + .maxlen = sizeof(int),
61931 + .mode = 0600,
61932 + .proc_handler = &proc_dointvec,
61933 + },
61934 +#endif
61935 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61936 + {
61937 + .procname = "harden_ptrace",
61938 + .data = &grsec_enable_harden_ptrace,
61939 + .maxlen = sizeof(int),
61940 + .mode = 0600,
61941 + .proc_handler = &proc_dointvec,
61942 + },
61943 +#endif
61944 + {
61945 + .procname = "grsec_lock",
61946 + .data = &grsec_lock,
61947 + .maxlen = sizeof(int),
61948 + .mode = 0600,
61949 + .proc_handler = &proc_dointvec,
61950 + },
61951 +#endif
61952 +#ifdef CONFIG_GRKERNSEC_ROFS
61953 + {
61954 + .procname = "romount_protect",
61955 + .data = &grsec_enable_rofs,
61956 + .maxlen = sizeof(int),
61957 + .mode = 0600,
61958 + .proc_handler = &proc_dointvec_minmax,
61959 + .extra1 = &one,
61960 + .extra2 = &one,
61961 + },
61962 +#endif
61963 + { }
61964 +};
61965 +#endif
61966 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
61967 new file mode 100644
61968 index 0000000..0dc13c3
61969 --- /dev/null
61970 +++ b/grsecurity/grsec_time.c
61971 @@ -0,0 +1,16 @@
61972 +#include <linux/kernel.h>
61973 +#include <linux/sched.h>
61974 +#include <linux/grinternal.h>
61975 +#include <linux/module.h>
61976 +
61977 +void
61978 +gr_log_timechange(void)
61979 +{
61980 +#ifdef CONFIG_GRKERNSEC_TIME
61981 + if (grsec_enable_time)
61982 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
61983 +#endif
61984 + return;
61985 +}
61986 +
61987 +EXPORT_SYMBOL(gr_log_timechange);
61988 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
61989 new file mode 100644
61990 index 0000000..07e0dc0
61991 --- /dev/null
61992 +++ b/grsecurity/grsec_tpe.c
61993 @@ -0,0 +1,73 @@
61994 +#include <linux/kernel.h>
61995 +#include <linux/sched.h>
61996 +#include <linux/file.h>
61997 +#include <linux/fs.h>
61998 +#include <linux/grinternal.h>
61999 +
62000 +extern int gr_acl_tpe_check(void);
62001 +
62002 +int
62003 +gr_tpe_allow(const struct file *file)
62004 +{
62005 +#ifdef CONFIG_GRKERNSEC
62006 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62007 + const struct cred *cred = current_cred();
62008 + char *msg = NULL;
62009 + char *msg2 = NULL;
62010 +
62011 + // never restrict root
62012 + if (!cred->uid)
62013 + return 1;
62014 +
62015 + if (grsec_enable_tpe) {
62016 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62017 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62018 + msg = "not being in trusted group";
62019 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62020 + msg = "being in untrusted group";
62021 +#else
62022 + if (in_group_p(grsec_tpe_gid))
62023 + msg = "being in untrusted group";
62024 +#endif
62025 + }
62026 + if (!msg && gr_acl_tpe_check())
62027 + msg = "being in untrusted role";
62028 +
62029 + // not in any affected group/role
62030 + if (!msg)
62031 + goto next_check;
62032 +
62033 + if (inode->i_uid)
62034 + msg2 = "file in non-root-owned directory";
62035 + else if (inode->i_mode & S_IWOTH)
62036 + msg2 = "file in world-writable directory";
62037 + else if (inode->i_mode & S_IWGRP)
62038 + msg2 = "file in group-writable directory";
62039 +
62040 + if (msg && msg2) {
62041 + char fullmsg[70] = {0};
62042 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62043 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62044 + return 0;
62045 + }
62046 + msg = NULL;
62047 +next_check:
62048 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62049 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62050 + return 1;
62051 +
62052 + if (inode->i_uid && (inode->i_uid != cred->uid))
62053 + msg = "directory not owned by user";
62054 + else if (inode->i_mode & S_IWOTH)
62055 + msg = "file in world-writable directory";
62056 + else if (inode->i_mode & S_IWGRP)
62057 + msg = "file in group-writable directory";
62058 +
62059 + if (msg) {
62060 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62061 + return 0;
62062 + }
62063 +#endif
62064 +#endif
62065 + return 1;
62066 +}
62067 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62068 new file mode 100644
62069 index 0000000..9f7b1ac
62070 --- /dev/null
62071 +++ b/grsecurity/grsum.c
62072 @@ -0,0 +1,61 @@
62073 +#include <linux/err.h>
62074 +#include <linux/kernel.h>
62075 +#include <linux/sched.h>
62076 +#include <linux/mm.h>
62077 +#include <linux/scatterlist.h>
62078 +#include <linux/crypto.h>
62079 +#include <linux/gracl.h>
62080 +
62081 +
62082 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62083 +#error "crypto and sha256 must be built into the kernel"
62084 +#endif
62085 +
62086 +int
62087 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62088 +{
62089 + char *p;
62090 + struct crypto_hash *tfm;
62091 + struct hash_desc desc;
62092 + struct scatterlist sg;
62093 + unsigned char temp_sum[GR_SHA_LEN];
62094 + volatile int retval = 0;
62095 + volatile int dummy = 0;
62096 + unsigned int i;
62097 +
62098 + sg_init_table(&sg, 1);
62099 +
62100 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62101 + if (IS_ERR(tfm)) {
62102 + /* should never happen, since sha256 should be built in */
62103 + return 1;
62104 + }
62105 +
62106 + desc.tfm = tfm;
62107 + desc.flags = 0;
62108 +
62109 + crypto_hash_init(&desc);
62110 +
62111 + p = salt;
62112 + sg_set_buf(&sg, p, GR_SALT_LEN);
62113 + crypto_hash_update(&desc, &sg, sg.length);
62114 +
62115 + p = entry->pw;
62116 + sg_set_buf(&sg, p, strlen(p));
62117 +
62118 + crypto_hash_update(&desc, &sg, sg.length);
62119 +
62120 + crypto_hash_final(&desc, temp_sum);
62121 +
62122 + memset(entry->pw, 0, GR_PW_LEN);
62123 +
62124 + for (i = 0; i < GR_SHA_LEN; i++)
62125 + if (sum[i] != temp_sum[i])
62126 + retval = 1;
62127 + else
62128 + dummy = 1; // waste a cycle
62129 +
62130 + crypto_free_hash(tfm);
62131 +
62132 + return retval;
62133 +}
62134 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62135 index 77ff547..181834f 100644
62136 --- a/include/asm-generic/4level-fixup.h
62137 +++ b/include/asm-generic/4level-fixup.h
62138 @@ -13,8 +13,10 @@
62139 #define pmd_alloc(mm, pud, address) \
62140 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62141 NULL: pmd_offset(pud, address))
62142 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62143
62144 #define pud_alloc(mm, pgd, address) (pgd)
62145 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62146 #define pud_offset(pgd, start) (pgd)
62147 #define pud_none(pud) 0
62148 #define pud_bad(pud) 0
62149 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62150 index b7babf0..04ad282 100644
62151 --- a/include/asm-generic/atomic-long.h
62152 +++ b/include/asm-generic/atomic-long.h
62153 @@ -22,6 +22,12 @@
62154
62155 typedef atomic64_t atomic_long_t;
62156
62157 +#ifdef CONFIG_PAX_REFCOUNT
62158 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
62159 +#else
62160 +typedef atomic64_t atomic_long_unchecked_t;
62161 +#endif
62162 +
62163 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62164
62165 static inline long atomic_long_read(atomic_long_t *l)
62166 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62167 return (long)atomic64_read(v);
62168 }
62169
62170 +#ifdef CONFIG_PAX_REFCOUNT
62171 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62172 +{
62173 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62174 +
62175 + return (long)atomic64_read_unchecked(v);
62176 +}
62177 +#endif
62178 +
62179 static inline void atomic_long_set(atomic_long_t *l, long i)
62180 {
62181 atomic64_t *v = (atomic64_t *)l;
62182 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62183 atomic64_set(v, i);
62184 }
62185
62186 +#ifdef CONFIG_PAX_REFCOUNT
62187 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62188 +{
62189 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62190 +
62191 + atomic64_set_unchecked(v, i);
62192 +}
62193 +#endif
62194 +
62195 static inline void atomic_long_inc(atomic_long_t *l)
62196 {
62197 atomic64_t *v = (atomic64_t *)l;
62198 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62199 atomic64_inc(v);
62200 }
62201
62202 +#ifdef CONFIG_PAX_REFCOUNT
62203 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62204 +{
62205 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62206 +
62207 + atomic64_inc_unchecked(v);
62208 +}
62209 +#endif
62210 +
62211 static inline void atomic_long_dec(atomic_long_t *l)
62212 {
62213 atomic64_t *v = (atomic64_t *)l;
62214 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62215 atomic64_dec(v);
62216 }
62217
62218 +#ifdef CONFIG_PAX_REFCOUNT
62219 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62220 +{
62221 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62222 +
62223 + atomic64_dec_unchecked(v);
62224 +}
62225 +#endif
62226 +
62227 static inline void atomic_long_add(long i, atomic_long_t *l)
62228 {
62229 atomic64_t *v = (atomic64_t *)l;
62230 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62231 atomic64_add(i, v);
62232 }
62233
62234 +#ifdef CONFIG_PAX_REFCOUNT
62235 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62236 +{
62237 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62238 +
62239 + atomic64_add_unchecked(i, v);
62240 +}
62241 +#endif
62242 +
62243 static inline void atomic_long_sub(long i, atomic_long_t *l)
62244 {
62245 atomic64_t *v = (atomic64_t *)l;
62246 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62247 atomic64_sub(i, v);
62248 }
62249
62250 +#ifdef CONFIG_PAX_REFCOUNT
62251 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62252 +{
62253 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62254 +
62255 + atomic64_sub_unchecked(i, v);
62256 +}
62257 +#endif
62258 +
62259 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62260 {
62261 atomic64_t *v = (atomic64_t *)l;
62262 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62263 return (long)atomic64_add_return(i, v);
62264 }
62265
62266 +#ifdef CONFIG_PAX_REFCOUNT
62267 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62268 +{
62269 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62270 +
62271 + return (long)atomic64_add_return_unchecked(i, v);
62272 +}
62273 +#endif
62274 +
62275 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62276 {
62277 atomic64_t *v = (atomic64_t *)l;
62278 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62279 return (long)atomic64_inc_return(v);
62280 }
62281
62282 +#ifdef CONFIG_PAX_REFCOUNT
62283 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62284 +{
62285 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62286 +
62287 + return (long)atomic64_inc_return_unchecked(v);
62288 +}
62289 +#endif
62290 +
62291 static inline long atomic_long_dec_return(atomic_long_t *l)
62292 {
62293 atomic64_t *v = (atomic64_t *)l;
62294 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62295
62296 typedef atomic_t atomic_long_t;
62297
62298 +#ifdef CONFIG_PAX_REFCOUNT
62299 +typedef atomic_unchecked_t atomic_long_unchecked_t;
62300 +#else
62301 +typedef atomic_t atomic_long_unchecked_t;
62302 +#endif
62303 +
62304 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62305 static inline long atomic_long_read(atomic_long_t *l)
62306 {
62307 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62308 return (long)atomic_read(v);
62309 }
62310
62311 +#ifdef CONFIG_PAX_REFCOUNT
62312 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62313 +{
62314 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62315 +
62316 + return (long)atomic_read_unchecked(v);
62317 +}
62318 +#endif
62319 +
62320 static inline void atomic_long_set(atomic_long_t *l, long i)
62321 {
62322 atomic_t *v = (atomic_t *)l;
62323 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62324 atomic_set(v, i);
62325 }
62326
62327 +#ifdef CONFIG_PAX_REFCOUNT
62328 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62329 +{
62330 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62331 +
62332 + atomic_set_unchecked(v, i);
62333 +}
62334 +#endif
62335 +
62336 static inline void atomic_long_inc(atomic_long_t *l)
62337 {
62338 atomic_t *v = (atomic_t *)l;
62339 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62340 atomic_inc(v);
62341 }
62342
62343 +#ifdef CONFIG_PAX_REFCOUNT
62344 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62345 +{
62346 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62347 +
62348 + atomic_inc_unchecked(v);
62349 +}
62350 +#endif
62351 +
62352 static inline void atomic_long_dec(atomic_long_t *l)
62353 {
62354 atomic_t *v = (atomic_t *)l;
62355 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62356 atomic_dec(v);
62357 }
62358
62359 +#ifdef CONFIG_PAX_REFCOUNT
62360 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62361 +{
62362 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62363 +
62364 + atomic_dec_unchecked(v);
62365 +}
62366 +#endif
62367 +
62368 static inline void atomic_long_add(long i, atomic_long_t *l)
62369 {
62370 atomic_t *v = (atomic_t *)l;
62371 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62372 atomic_add(i, v);
62373 }
62374
62375 +#ifdef CONFIG_PAX_REFCOUNT
62376 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62377 +{
62378 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62379 +
62380 + atomic_add_unchecked(i, v);
62381 +}
62382 +#endif
62383 +
62384 static inline void atomic_long_sub(long i, atomic_long_t *l)
62385 {
62386 atomic_t *v = (atomic_t *)l;
62387 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62388 atomic_sub(i, v);
62389 }
62390
62391 +#ifdef CONFIG_PAX_REFCOUNT
62392 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62393 +{
62394 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62395 +
62396 + atomic_sub_unchecked(i, v);
62397 +}
62398 +#endif
62399 +
62400 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62401 {
62402 atomic_t *v = (atomic_t *)l;
62403 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62404 return (long)atomic_add_return(i, v);
62405 }
62406
62407 +#ifdef CONFIG_PAX_REFCOUNT
62408 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62409 +{
62410 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62411 +
62412 + return (long)atomic_add_return_unchecked(i, v);
62413 +}
62414 +
62415 +#endif
62416 +
62417 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62418 {
62419 atomic_t *v = (atomic_t *)l;
62420 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62421 return (long)atomic_inc_return(v);
62422 }
62423
62424 +#ifdef CONFIG_PAX_REFCOUNT
62425 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62426 +{
62427 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62428 +
62429 + return (long)atomic_inc_return_unchecked(v);
62430 +}
62431 +#endif
62432 +
62433 static inline long atomic_long_dec_return(atomic_long_t *l)
62434 {
62435 atomic_t *v = (atomic_t *)l;
62436 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62437
62438 #endif /* BITS_PER_LONG == 64 */
62439
62440 +#ifdef CONFIG_PAX_REFCOUNT
62441 +static inline void pax_refcount_needs_these_functions(void)
62442 +{
62443 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62444 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62445 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62446 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62447 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62448 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62449 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62450 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62451 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62452 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62453 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62454 +#ifdef CONFIG_X86
62455 + atomic_clear_mask_unchecked(0, NULL);
62456 + atomic_set_mask_unchecked(0, NULL);
62457 +#endif
62458 +
62459 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62460 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62461 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62462 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62463 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62464 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62465 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62466 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62467 +}
62468 +#else
62469 +#define atomic_read_unchecked(v) atomic_read(v)
62470 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62471 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62472 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62473 +#define atomic_inc_unchecked(v) atomic_inc(v)
62474 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62475 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62476 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62477 +#define atomic_dec_unchecked(v) atomic_dec(v)
62478 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62479 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62480 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62481 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62482 +
62483 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62484 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62485 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62486 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62487 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62488 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62489 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62490 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62491 +#endif
62492 +
62493 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62494 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62495 index 1ced641..c896ee8 100644
62496 --- a/include/asm-generic/atomic.h
62497 +++ b/include/asm-generic/atomic.h
62498 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62499 * Atomically clears the bits set in @mask from @v
62500 */
62501 #ifndef atomic_clear_mask
62502 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62503 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62504 {
62505 unsigned long flags;
62506
62507 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62508 index b18ce4f..2ee2843 100644
62509 --- a/include/asm-generic/atomic64.h
62510 +++ b/include/asm-generic/atomic64.h
62511 @@ -16,6 +16,8 @@ typedef struct {
62512 long long counter;
62513 } atomic64_t;
62514
62515 +typedef atomic64_t atomic64_unchecked_t;
62516 +
62517 #define ATOMIC64_INIT(i) { (i) }
62518
62519 extern long long atomic64_read(const atomic64_t *v);
62520 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62521 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62522 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62523
62524 +#define atomic64_read_unchecked(v) atomic64_read(v)
62525 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62526 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62527 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62528 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62529 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62530 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62531 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62532 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62533 +
62534 #endif /* _ASM_GENERIC_ATOMIC64_H */
62535 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62536 index 1bfcfe5..e04c5c9 100644
62537 --- a/include/asm-generic/cache.h
62538 +++ b/include/asm-generic/cache.h
62539 @@ -6,7 +6,7 @@
62540 * cache lines need to provide their own cache.h.
62541 */
62542
62543 -#define L1_CACHE_SHIFT 5
62544 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62545 +#define L1_CACHE_SHIFT 5UL
62546 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62547
62548 #endif /* __ASM_GENERIC_CACHE_H */
62549 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62550 index 0d68a1e..b74a761 100644
62551 --- a/include/asm-generic/emergency-restart.h
62552 +++ b/include/asm-generic/emergency-restart.h
62553 @@ -1,7 +1,7 @@
62554 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62555 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62556
62557 -static inline void machine_emergency_restart(void)
62558 +static inline __noreturn void machine_emergency_restart(void)
62559 {
62560 machine_restart(NULL);
62561 }
62562 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62563 index 90f99c7..00ce236 100644
62564 --- a/include/asm-generic/kmap_types.h
62565 +++ b/include/asm-generic/kmap_types.h
62566 @@ -2,9 +2,9 @@
62567 #define _ASM_GENERIC_KMAP_TYPES_H
62568
62569 #ifdef __WITH_KM_FENCE
62570 -# define KM_TYPE_NR 41
62571 +# define KM_TYPE_NR 42
62572 #else
62573 -# define KM_TYPE_NR 20
62574 +# define KM_TYPE_NR 21
62575 #endif
62576
62577 #endif
62578 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62579 index 9ceb03b..62b0b8f 100644
62580 --- a/include/asm-generic/local.h
62581 +++ b/include/asm-generic/local.h
62582 @@ -23,24 +23,37 @@ typedef struct
62583 atomic_long_t a;
62584 } local_t;
62585
62586 +typedef struct {
62587 + atomic_long_unchecked_t a;
62588 +} local_unchecked_t;
62589 +
62590 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62591
62592 #define local_read(l) atomic_long_read(&(l)->a)
62593 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62594 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62595 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62596 #define local_inc(l) atomic_long_inc(&(l)->a)
62597 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62598 #define local_dec(l) atomic_long_dec(&(l)->a)
62599 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62600 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62601 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62602 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62603 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62604
62605 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62606 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62607 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62608 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62609 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62610 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62611 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62612 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62613 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62614
62615 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62616 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62617 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62618 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62619 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62620 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62621 index 725612b..9cc513a 100644
62622 --- a/include/asm-generic/pgtable-nopmd.h
62623 +++ b/include/asm-generic/pgtable-nopmd.h
62624 @@ -1,14 +1,19 @@
62625 #ifndef _PGTABLE_NOPMD_H
62626 #define _PGTABLE_NOPMD_H
62627
62628 -#ifndef __ASSEMBLY__
62629 -
62630 #include <asm-generic/pgtable-nopud.h>
62631
62632 -struct mm_struct;
62633 -
62634 #define __PAGETABLE_PMD_FOLDED
62635
62636 +#define PMD_SHIFT PUD_SHIFT
62637 +#define PTRS_PER_PMD 1
62638 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62639 +#define PMD_MASK (~(PMD_SIZE-1))
62640 +
62641 +#ifndef __ASSEMBLY__
62642 +
62643 +struct mm_struct;
62644 +
62645 /*
62646 * Having the pmd type consist of a pud gets the size right, and allows
62647 * us to conceptually access the pud entry that this pmd is folded into
62648 @@ -16,11 +21,6 @@ struct mm_struct;
62649 */
62650 typedef struct { pud_t pud; } pmd_t;
62651
62652 -#define PMD_SHIFT PUD_SHIFT
62653 -#define PTRS_PER_PMD 1
62654 -#define PMD_SIZE (1UL << PMD_SHIFT)
62655 -#define PMD_MASK (~(PMD_SIZE-1))
62656 -
62657 /*
62658 * The "pud_xxx()" functions here are trivial for a folded two-level
62659 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62660 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62661 index 810431d..0ec4804f 100644
62662 --- a/include/asm-generic/pgtable-nopud.h
62663 +++ b/include/asm-generic/pgtable-nopud.h
62664 @@ -1,10 +1,15 @@
62665 #ifndef _PGTABLE_NOPUD_H
62666 #define _PGTABLE_NOPUD_H
62667
62668 -#ifndef __ASSEMBLY__
62669 -
62670 #define __PAGETABLE_PUD_FOLDED
62671
62672 +#define PUD_SHIFT PGDIR_SHIFT
62673 +#define PTRS_PER_PUD 1
62674 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62675 +#define PUD_MASK (~(PUD_SIZE-1))
62676 +
62677 +#ifndef __ASSEMBLY__
62678 +
62679 /*
62680 * Having the pud type consist of a pgd gets the size right, and allows
62681 * us to conceptually access the pgd entry that this pud is folded into
62682 @@ -12,11 +17,6 @@
62683 */
62684 typedef struct { pgd_t pgd; } pud_t;
62685
62686 -#define PUD_SHIFT PGDIR_SHIFT
62687 -#define PTRS_PER_PUD 1
62688 -#define PUD_SIZE (1UL << PUD_SHIFT)
62689 -#define PUD_MASK (~(PUD_SIZE-1))
62690 -
62691 /*
62692 * The "pgd_xxx()" functions here are trivial for a folded two-level
62693 * setup: the pud is never bad, and a pud always exists (as it's folded
62694 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62695 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62696
62697 #define pgd_populate(mm, pgd, pud) do { } while (0)
62698 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62699 /*
62700 * (puds are folded into pgds so this doesn't get actually called,
62701 * but the define is needed for a generic inline function.)
62702 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62703 index b36ce40..019426d 100644
62704 --- a/include/asm-generic/pgtable.h
62705 +++ b/include/asm-generic/pgtable.h
62706 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62707 #endif
62708 }
62709
62710 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62711 +static inline unsigned long pax_open_kernel(void) { return 0; }
62712 +#endif
62713 +
62714 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62715 +static inline unsigned long pax_close_kernel(void) { return 0; }
62716 +#endif
62717 +
62718 #endif /* CONFIG_MMU */
62719
62720 #endif /* !__ASSEMBLY__ */
62721 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62722 index d1ea7ce..b1ebf2a 100644
62723 --- a/include/asm-generic/vmlinux.lds.h
62724 +++ b/include/asm-generic/vmlinux.lds.h
62725 @@ -218,6 +218,7 @@
62726 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62727 VMLINUX_SYMBOL(__start_rodata) = .; \
62728 *(.rodata) *(.rodata.*) \
62729 + *(.data..read_only) \
62730 *(__vermagic) /* Kernel version magic */ \
62731 . = ALIGN(8); \
62732 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62733 @@ -725,17 +726,18 @@
62734 * section in the linker script will go there too. @phdr should have
62735 * a leading colon.
62736 *
62737 - * Note that this macros defines __per_cpu_load as an absolute symbol.
62738 + * Note that this macros defines per_cpu_load as an absolute symbol.
62739 * If there is no need to put the percpu section at a predetermined
62740 * address, use PERCPU_SECTION.
62741 */
62742 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62743 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
62744 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62745 + per_cpu_load = .; \
62746 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62747 - LOAD_OFFSET) { \
62748 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62749 PERCPU_INPUT(cacheline) \
62750 } phdr \
62751 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62752 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62753
62754 /**
62755 * PERCPU_SECTION - define output section for percpu area, simple version
62756 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62757 index 418d270..bfd2794 100644
62758 --- a/include/crypto/algapi.h
62759 +++ b/include/crypto/algapi.h
62760 @@ -34,7 +34,7 @@ struct crypto_type {
62761 unsigned int maskclear;
62762 unsigned int maskset;
62763 unsigned int tfmsize;
62764 -};
62765 +} __do_const;
62766
62767 struct crypto_instance {
62768 struct crypto_alg alg;
62769 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62770 index 3fd8280..2b3c415 100644
62771 --- a/include/drm/drmP.h
62772 +++ b/include/drm/drmP.h
62773 @@ -72,6 +72,7 @@
62774 #include <linux/workqueue.h>
62775 #include <linux/poll.h>
62776 #include <asm/pgalloc.h>
62777 +#include <asm/local.h>
62778 #include <drm/drm.h>
62779 #include <drm/drm_sarea.h>
62780
62781 @@ -1068,7 +1069,7 @@ struct drm_device {
62782
62783 /** \name Usage Counters */
62784 /*@{ */
62785 - int open_count; /**< Outstanding files open */
62786 + local_t open_count; /**< Outstanding files open */
62787 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62788 atomic_t vma_count; /**< Outstanding vma areas open */
62789 int buf_use; /**< Buffers in use -- cannot alloc */
62790 @@ -1079,7 +1080,7 @@ struct drm_device {
62791 /*@{ */
62792 unsigned long counters;
62793 enum drm_stat_type types[15];
62794 - atomic_t counts[15];
62795 + atomic_unchecked_t counts[15];
62796 /*@} */
62797
62798 struct list_head filelist;
62799 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62800 index e01cc80..6fb6f25 100644
62801 --- a/include/drm/drm_crtc_helper.h
62802 +++ b/include/drm/drm_crtc_helper.h
62803 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
62804 struct drm_connector *connector);
62805 /* disable encoder when not in use - more explicit than dpms off */
62806 void (*disable)(struct drm_encoder *encoder);
62807 -};
62808 +} __no_const;
62809
62810 /**
62811 * drm_connector_helper_funcs - helper operations for connectors
62812 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
62813 index d6d1da4..fdd1ac5 100644
62814 --- a/include/drm/ttm/ttm_memory.h
62815 +++ b/include/drm/ttm/ttm_memory.h
62816 @@ -48,7 +48,7 @@
62817
62818 struct ttm_mem_shrink {
62819 int (*do_shrink) (struct ttm_mem_shrink *);
62820 -};
62821 +} __no_const;
62822
62823 /**
62824 * struct ttm_mem_global - Global memory accounting structure.
62825 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
62826 index 22ef21c..75904ba 100644
62827 --- a/include/linux/atmdev.h
62828 +++ b/include/linux/atmdev.h
62829 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
62830 #endif
62831
62832 struct k_atm_aal_stats {
62833 -#define __HANDLE_ITEM(i) atomic_t i
62834 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62835 __AAL_STAT_ITEMS
62836 #undef __HANDLE_ITEM
62837 };
62838 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
62839 index de0628e..38f42eb 100644
62840 --- a/include/linux/binfmts.h
62841 +++ b/include/linux/binfmts.h
62842 @@ -75,6 +75,7 @@ struct linux_binfmt {
62843 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
62844 int (*load_shlib)(struct file *);
62845 int (*core_dump)(struct coredump_params *cprm);
62846 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
62847 unsigned long min_coredump; /* minimal dump size */
62848 };
62849
62850 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
62851 index 1756001..ab117ec 100644
62852 --- a/include/linux/blkdev.h
62853 +++ b/include/linux/blkdev.h
62854 @@ -1478,7 +1478,7 @@ struct block_device_operations {
62855 /* this callback is with swap_lock and sometimes page table lock held */
62856 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
62857 struct module *owner;
62858 -};
62859 +} __do_const;
62860
62861 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
62862 unsigned long);
62863 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
62864 index 7c2e030..b72475d 100644
62865 --- a/include/linux/blktrace_api.h
62866 +++ b/include/linux/blktrace_api.h
62867 @@ -23,7 +23,7 @@ struct blk_trace {
62868 struct dentry *dir;
62869 struct dentry *dropped_file;
62870 struct dentry *msg_file;
62871 - atomic_t dropped;
62872 + atomic_unchecked_t dropped;
62873 };
62874
62875 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
62876 diff --git a/include/linux/cache.h b/include/linux/cache.h
62877 index 4c57065..4307975 100644
62878 --- a/include/linux/cache.h
62879 +++ b/include/linux/cache.h
62880 @@ -16,6 +16,10 @@
62881 #define __read_mostly
62882 #endif
62883
62884 +#ifndef __read_only
62885 +#define __read_only __read_mostly
62886 +#endif
62887 +
62888 #ifndef ____cacheline_aligned
62889 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
62890 #endif
62891 diff --git a/include/linux/capability.h b/include/linux/capability.h
62892 index 98503b7..cc36d18 100644
62893 --- a/include/linux/capability.h
62894 +++ b/include/linux/capability.h
62895 @@ -211,8 +211,13 @@ extern bool capable(int cap);
62896 extern bool ns_capable(struct user_namespace *ns, int cap);
62897 extern bool nsown_capable(int cap);
62898 extern bool inode_capable(const struct inode *inode, int cap);
62899 +extern bool capable_nolog(int cap);
62900 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
62901 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
62902
62903 /* audit system wants to get cap info from files as well */
62904 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
62905
62906 +extern int is_privileged_binary(const struct dentry *dentry);
62907 +
62908 #endif /* !_LINUX_CAPABILITY_H */
62909 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
62910 index 8609d57..86e4d79 100644
62911 --- a/include/linux/cdrom.h
62912 +++ b/include/linux/cdrom.h
62913 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
62914
62915 /* driver specifications */
62916 const int capability; /* capability flags */
62917 - int n_minors; /* number of active minor devices */
62918 /* handle uniform packets for scsi type devices (scsi,atapi) */
62919 int (*generic_packet) (struct cdrom_device_info *,
62920 struct packet_command *);
62921 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
62922 index 42e55de..1cd0e66 100644
62923 --- a/include/linux/cleancache.h
62924 +++ b/include/linux/cleancache.h
62925 @@ -31,7 +31,7 @@ struct cleancache_ops {
62926 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
62927 void (*invalidate_inode)(int, struct cleancache_filekey);
62928 void (*invalidate_fs)(int);
62929 -};
62930 +} __no_const;
62931
62932 extern struct cleancache_ops
62933 cleancache_register_ops(struct cleancache_ops *ops);
62934 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
62935 index 412bc6c..c31666e 100644
62936 --- a/include/linux/compiler-gcc4.h
62937 +++ b/include/linux/compiler-gcc4.h
62938 @@ -32,6 +32,21 @@
62939 #define __linktime_error(message) __attribute__((__error__(message)))
62940
62941 #if __GNUC_MINOR__ >= 5
62942 +
62943 +#ifdef CONSTIFY_PLUGIN
62944 +#define __no_const __attribute__((no_const))
62945 +#define __do_const __attribute__((do_const))
62946 +#endif
62947 +
62948 +#ifdef SIZE_OVERFLOW_PLUGIN
62949 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
62950 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
62951 +#endif
62952 +
62953 +#ifdef LATENT_ENTROPY_PLUGIN
62954 +#define __latent_entropy __attribute__((latent_entropy))
62955 +#endif
62956 +
62957 /*
62958 * Mark a position in code as unreachable. This can be used to
62959 * suppress control flow warnings after asm blocks that transfer
62960 @@ -47,6 +62,11 @@
62961 #define __noclone __attribute__((__noclone__))
62962
62963 #endif
62964 +
62965 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
62966 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
62967 +#define __bos0(ptr) __bos((ptr), 0)
62968 +#define __bos1(ptr) __bos((ptr), 1)
62969 #endif
62970
62971 #if __GNUC_MINOR__ >= 6
62972 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
62973 index f430e41..38be90f 100644
62974 --- a/include/linux/compiler.h
62975 +++ b/include/linux/compiler.h
62976 @@ -5,31 +5,62 @@
62977
62978 #ifdef __CHECKER__
62979 # define __user __attribute__((noderef, address_space(1)))
62980 +# define __force_user __force __user
62981 # define __kernel __attribute__((address_space(0)))
62982 +# define __force_kernel __force __kernel
62983 # define __safe __attribute__((safe))
62984 # define __force __attribute__((force))
62985 # define __nocast __attribute__((nocast))
62986 # define __iomem __attribute__((noderef, address_space(2)))
62987 +# define __force_iomem __force __iomem
62988 # define __acquires(x) __attribute__((context(x,0,1)))
62989 # define __releases(x) __attribute__((context(x,1,0)))
62990 # define __acquire(x) __context__(x,1)
62991 # define __release(x) __context__(x,-1)
62992 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
62993 # define __percpu __attribute__((noderef, address_space(3)))
62994 +# define __force_percpu __force __percpu
62995 #ifdef CONFIG_SPARSE_RCU_POINTER
62996 # define __rcu __attribute__((noderef, address_space(4)))
62997 +# define __force_rcu __force __rcu
62998 #else
62999 # define __rcu
63000 +# define __force_rcu
63001 #endif
63002 extern void __chk_user_ptr(const volatile void __user *);
63003 extern void __chk_io_ptr(const volatile void __iomem *);
63004 +#elif defined(CHECKER_PLUGIN)
63005 +//# define __user
63006 +//# define __force_user
63007 +//# define __kernel
63008 +//# define __force_kernel
63009 +# define __safe
63010 +# define __force
63011 +# define __nocast
63012 +# define __iomem
63013 +# define __force_iomem
63014 +# define __chk_user_ptr(x) (void)0
63015 +# define __chk_io_ptr(x) (void)0
63016 +# define __builtin_warning(x, y...) (1)
63017 +# define __acquires(x)
63018 +# define __releases(x)
63019 +# define __acquire(x) (void)0
63020 +# define __release(x) (void)0
63021 +# define __cond_lock(x,c) (c)
63022 +# define __percpu
63023 +# define __force_percpu
63024 +# define __rcu
63025 +# define __force_rcu
63026 #else
63027 # define __user
63028 +# define __force_user
63029 # define __kernel
63030 +# define __force_kernel
63031 # define __safe
63032 # define __force
63033 # define __nocast
63034 # define __iomem
63035 +# define __force_iomem
63036 # define __chk_user_ptr(x) (void)0
63037 # define __chk_io_ptr(x) (void)0
63038 # define __builtin_warning(x, y...) (1)
63039 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63040 # define __release(x) (void)0
63041 # define __cond_lock(x,c) (c)
63042 # define __percpu
63043 +# define __force_percpu
63044 # define __rcu
63045 +# define __force_rcu
63046 #endif
63047
63048 #ifdef __KERNEL__
63049 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63050 # define __attribute_const__ /* unimplemented */
63051 #endif
63052
63053 +#ifndef __no_const
63054 +# define __no_const
63055 +#endif
63056 +
63057 +#ifndef __do_const
63058 +# define __do_const
63059 +#endif
63060 +
63061 +#ifndef __size_overflow
63062 +# define __size_overflow(...)
63063 +#endif
63064 +
63065 +#ifndef __intentional_overflow
63066 +# define __intentional_overflow(...)
63067 +#endif
63068 +
63069 +#ifndef __latent_entropy
63070 +# define __latent_entropy
63071 +#endif
63072 +
63073 /*
63074 * Tell gcc if a function is cold. The compiler will assume any path
63075 * directly leading to the call is unlikely.
63076 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63077 #define __cold
63078 #endif
63079
63080 +#ifndef __alloc_size
63081 +#define __alloc_size(...)
63082 +#endif
63083 +
63084 +#ifndef __bos
63085 +#define __bos(ptr, arg)
63086 +#endif
63087 +
63088 +#ifndef __bos0
63089 +#define __bos0(ptr)
63090 +#endif
63091 +
63092 +#ifndef __bos1
63093 +#define __bos1(ptr)
63094 +#endif
63095 +
63096 /* Simple shorthand for a section definition */
63097 #ifndef __section
63098 # define __section(S) __attribute__ ((__section__(#S)))
63099 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63100 * use is to mediate communication between process-level code and irq/NMI
63101 * handlers, all running on the same CPU.
63102 */
63103 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63104 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63105 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63106
63107 #endif /* __LINUX_COMPILER_H */
63108 diff --git a/include/linux/cred.h b/include/linux/cred.h
63109 index ebbed2c..908cc2c 100644
63110 --- a/include/linux/cred.h
63111 +++ b/include/linux/cred.h
63112 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63113 static inline void validate_process_creds(void)
63114 {
63115 }
63116 +static inline void validate_task_creds(struct task_struct *task)
63117 +{
63118 +}
63119 #endif
63120
63121 /**
63122 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63123 index b92eadf..b4ecdc1 100644
63124 --- a/include/linux/crypto.h
63125 +++ b/include/linux/crypto.h
63126 @@ -373,7 +373,7 @@ struct cipher_tfm {
63127 const u8 *key, unsigned int keylen);
63128 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63129 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63130 -};
63131 +} __no_const;
63132
63133 struct hash_tfm {
63134 int (*init)(struct hash_desc *desc);
63135 @@ -394,13 +394,13 @@ struct compress_tfm {
63136 int (*cot_decompress)(struct crypto_tfm *tfm,
63137 const u8 *src, unsigned int slen,
63138 u8 *dst, unsigned int *dlen);
63139 -};
63140 +} __no_const;
63141
63142 struct rng_tfm {
63143 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63144 unsigned int dlen);
63145 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63146 -};
63147 +} __no_const;
63148
63149 #define crt_ablkcipher crt_u.ablkcipher
63150 #define crt_aead crt_u.aead
63151 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63152 index 7925bf0..d5143d2 100644
63153 --- a/include/linux/decompress/mm.h
63154 +++ b/include/linux/decompress/mm.h
63155 @@ -77,7 +77,7 @@ static void free(void *where)
63156 * warnings when not needed (indeed large_malloc / large_free are not
63157 * needed by inflate */
63158
63159 -#define malloc(a) kmalloc(a, GFP_KERNEL)
63160 +#define malloc(a) kmalloc((a), GFP_KERNEL)
63161 #define free(a) kfree(a)
63162
63163 #define large_malloc(a) vmalloc(a)
63164 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63165 index 94af418..b1ca7a2 100644
63166 --- a/include/linux/dma-mapping.h
63167 +++ b/include/linux/dma-mapping.h
63168 @@ -54,7 +54,7 @@ struct dma_map_ops {
63169 u64 (*get_required_mask)(struct device *dev);
63170 #endif
63171 int is_phys;
63172 -};
63173 +} __do_const;
63174
63175 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63176
63177 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63178 index d3201e4..8281e63 100644
63179 --- a/include/linux/dmaengine.h
63180 +++ b/include/linux/dmaengine.h
63181 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63182 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63183 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63184
63185 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63186 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63187 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63188 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63189 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63190 struct dma_pinned_list *pinned_list, struct page *page,
63191 unsigned int offset, size_t len);
63192
63193 diff --git a/include/linux/elf.h b/include/linux/elf.h
63194 index 8c9048e..16a4665 100644
63195 --- a/include/linux/elf.h
63196 +++ b/include/linux/elf.h
63197 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63198 #define elf_note elf32_note
63199 #define elf_addr_t Elf32_Off
63200 #define Elf_Half Elf32_Half
63201 +#define elf_dyn Elf32_Dyn
63202
63203 #else
63204
63205 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63206 #define elf_note elf64_note
63207 #define elf_addr_t Elf64_Off
63208 #define Elf_Half Elf64_Half
63209 +#define elf_dyn Elf64_Dyn
63210
63211 #endif
63212
63213 diff --git a/include/linux/filter.h b/include/linux/filter.h
63214 index 24d251f..7afb83d 100644
63215 --- a/include/linux/filter.h
63216 +++ b/include/linux/filter.h
63217 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
63218
63219 struct sk_buff;
63220 struct sock;
63221 +struct bpf_jit_work;
63222
63223 struct sk_filter
63224 {
63225 @@ -27,6 +28,9 @@ struct sk_filter
63226 unsigned int len; /* Number of filter blocks */
63227 unsigned int (*bpf_func)(const struct sk_buff *skb,
63228 const struct sock_filter *filter);
63229 +#ifdef CONFIG_BPF_JIT
63230 + struct bpf_jit_work *work;
63231 +#endif
63232 struct rcu_head rcu;
63233 struct sock_filter insns[0];
63234 };
63235 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63236 index 3044254..9767f41 100644
63237 --- a/include/linux/frontswap.h
63238 +++ b/include/linux/frontswap.h
63239 @@ -11,7 +11,7 @@ struct frontswap_ops {
63240 int (*load)(unsigned, pgoff_t, struct page *);
63241 void (*invalidate_page)(unsigned, pgoff_t);
63242 void (*invalidate_area)(unsigned);
63243 -};
63244 +} __no_const;
63245
63246 extern bool frontswap_enabled;
63247 extern struct frontswap_ops
63248 diff --git a/include/linux/fs.h b/include/linux/fs.h
63249 index 75fe9a1..8417cac 100644
63250 --- a/include/linux/fs.h
63251 +++ b/include/linux/fs.h
63252 @@ -1543,7 +1543,8 @@ struct file_operations {
63253 int (*setlease)(struct file *, long, struct file_lock **);
63254 long (*fallocate)(struct file *file, int mode, loff_t offset,
63255 loff_t len);
63256 -};
63257 +} __do_const;
63258 +typedef struct file_operations __no_const file_operations_no_const;
63259
63260 struct inode_operations {
63261 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63262 @@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63263 inode->i_flags |= S_NOSEC;
63264 }
63265
63266 +static inline bool is_sidechannel_device(const struct inode *inode)
63267 +{
63268 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63269 + umode_t mode = inode->i_mode;
63270 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63271 +#else
63272 + return false;
63273 +#endif
63274 +}
63275 +
63276 #endif /* _LINUX_FS_H */
63277 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63278 index 003dc0f..3c4ea97 100644
63279 --- a/include/linux/fs_struct.h
63280 +++ b/include/linux/fs_struct.h
63281 @@ -6,7 +6,7 @@
63282 #include <linux/seqlock.h>
63283
63284 struct fs_struct {
63285 - int users;
63286 + atomic_t users;
63287 spinlock_t lock;
63288 seqcount_t seq;
63289 int umask;
63290 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63291 index ce31408..b1ad003 100644
63292 --- a/include/linux/fscache-cache.h
63293 +++ b/include/linux/fscache-cache.h
63294 @@ -102,7 +102,7 @@ struct fscache_operation {
63295 fscache_operation_release_t release;
63296 };
63297
63298 -extern atomic_t fscache_op_debug_id;
63299 +extern atomic_unchecked_t fscache_op_debug_id;
63300 extern void fscache_op_work_func(struct work_struct *work);
63301
63302 extern void fscache_enqueue_operation(struct fscache_operation *);
63303 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63304 {
63305 INIT_WORK(&op->work, fscache_op_work_func);
63306 atomic_set(&op->usage, 1);
63307 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63308 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63309 op->processor = processor;
63310 op->release = release;
63311 INIT_LIST_HEAD(&op->pend_link);
63312 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63313 index 0fbfb46..508eb0d 100644
63314 --- a/include/linux/fsnotify.h
63315 +++ b/include/linux/fsnotify.h
63316 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63317 struct inode *inode = path->dentry->d_inode;
63318 __u32 mask = FS_ACCESS;
63319
63320 + if (is_sidechannel_device(inode))
63321 + return;
63322 +
63323 if (S_ISDIR(inode->i_mode))
63324 mask |= FS_ISDIR;
63325
63326 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63327 struct inode *inode = path->dentry->d_inode;
63328 __u32 mask = FS_MODIFY;
63329
63330 + if (is_sidechannel_device(inode))
63331 + return;
63332 +
63333 if (S_ISDIR(inode->i_mode))
63334 mask |= FS_ISDIR;
63335
63336 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63337 */
63338 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63339 {
63340 - return kstrdup(name, GFP_KERNEL);
63341 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63342 }
63343
63344 /*
63345 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63346 index 642928c..93afe6a 100644
63347 --- a/include/linux/ftrace_event.h
63348 +++ b/include/linux/ftrace_event.h
63349 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63350 extern int trace_add_event_call(struct ftrace_event_call *call);
63351 extern void trace_remove_event_call(struct ftrace_event_call *call);
63352
63353 -#define is_signed_type(type) (((type)(-1)) < 0)
63354 +#define is_signed_type(type) (((type)(-1)) < (type)1)
63355
63356 int trace_set_clr_event(const char *system, const char *event, int set);
63357
63358 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63359 index 4f440b3..342233a 100644
63360 --- a/include/linux/genhd.h
63361 +++ b/include/linux/genhd.h
63362 @@ -190,7 +190,7 @@ struct gendisk {
63363 struct kobject *slave_dir;
63364
63365 struct timer_rand_state *random;
63366 - atomic_t sync_io; /* RAID */
63367 + atomic_unchecked_t sync_io; /* RAID */
63368 struct disk_events *ev;
63369 #ifdef CONFIG_BLK_DEV_INTEGRITY
63370 struct blk_integrity *integrity;
63371 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63372 index d0a7967..63c4c47 100644
63373 --- a/include/linux/gfp.h
63374 +++ b/include/linux/gfp.h
63375 @@ -35,6 +35,12 @@ struct vm_area_struct;
63376 #define ___GFP_OTHER_NODE 0x800000u
63377 #define ___GFP_WRITE 0x1000000u
63378
63379 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63380 +#define ___GFP_USERCOPY 0x2000000u
63381 +#else
63382 +#define ___GFP_USERCOPY 0
63383 +#endif
63384 +
63385 /*
63386 * GFP bitmasks..
63387 *
63388 @@ -89,6 +95,7 @@ struct vm_area_struct;
63389 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63390 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63391 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63392 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63393
63394 /*
63395 * This may seem redundant, but it's a way of annotating false positives vs.
63396 @@ -96,7 +103,7 @@ struct vm_area_struct;
63397 */
63398 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63399
63400 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63401 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63402 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63403
63404 /* This equals 0, but use constants in case they ever change */
63405 @@ -150,6 +157,8 @@ struct vm_area_struct;
63406 /* 4GB DMA on some platforms */
63407 #define GFP_DMA32 __GFP_DMA32
63408
63409 +#define GFP_USERCOPY __GFP_USERCOPY
63410 +
63411 /* Convert GFP flags to their corresponding migrate type */
63412 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63413 {
63414 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63415 new file mode 100644
63416 index 0000000..ebe6d72
63417 --- /dev/null
63418 +++ b/include/linux/gracl.h
63419 @@ -0,0 +1,319 @@
63420 +#ifndef GR_ACL_H
63421 +#define GR_ACL_H
63422 +
63423 +#include <linux/grdefs.h>
63424 +#include <linux/resource.h>
63425 +#include <linux/capability.h>
63426 +#include <linux/dcache.h>
63427 +#include <asm/resource.h>
63428 +
63429 +/* Major status information */
63430 +
63431 +#define GR_VERSION "grsecurity 2.9.1"
63432 +#define GRSECURITY_VERSION 0x2901
63433 +
63434 +enum {
63435 + GR_SHUTDOWN = 0,
63436 + GR_ENABLE = 1,
63437 + GR_SPROLE = 2,
63438 + GR_RELOAD = 3,
63439 + GR_SEGVMOD = 4,
63440 + GR_STATUS = 5,
63441 + GR_UNSPROLE = 6,
63442 + GR_PASSSET = 7,
63443 + GR_SPROLEPAM = 8,
63444 +};
63445 +
63446 +/* Password setup definitions
63447 + * kernel/grhash.c */
63448 +enum {
63449 + GR_PW_LEN = 128,
63450 + GR_SALT_LEN = 16,
63451 + GR_SHA_LEN = 32,
63452 +};
63453 +
63454 +enum {
63455 + GR_SPROLE_LEN = 64,
63456 +};
63457 +
63458 +enum {
63459 + GR_NO_GLOB = 0,
63460 + GR_REG_GLOB,
63461 + GR_CREATE_GLOB
63462 +};
63463 +
63464 +#define GR_NLIMITS 32
63465 +
63466 +/* Begin Data Structures */
63467 +
63468 +struct sprole_pw {
63469 + unsigned char *rolename;
63470 + unsigned char salt[GR_SALT_LEN];
63471 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63472 +};
63473 +
63474 +struct name_entry {
63475 + __u32 key;
63476 + ino_t inode;
63477 + dev_t device;
63478 + char *name;
63479 + __u16 len;
63480 + __u8 deleted;
63481 + struct name_entry *prev;
63482 + struct name_entry *next;
63483 +};
63484 +
63485 +struct inodev_entry {
63486 + struct name_entry *nentry;
63487 + struct inodev_entry *prev;
63488 + struct inodev_entry *next;
63489 +};
63490 +
63491 +struct acl_role_db {
63492 + struct acl_role_label **r_hash;
63493 + __u32 r_size;
63494 +};
63495 +
63496 +struct inodev_db {
63497 + struct inodev_entry **i_hash;
63498 + __u32 i_size;
63499 +};
63500 +
63501 +struct name_db {
63502 + struct name_entry **n_hash;
63503 + __u32 n_size;
63504 +};
63505 +
63506 +struct crash_uid {
63507 + uid_t uid;
63508 + unsigned long expires;
63509 +};
63510 +
63511 +struct gr_hash_struct {
63512 + void **table;
63513 + void **nametable;
63514 + void *first;
63515 + __u32 table_size;
63516 + __u32 used_size;
63517 + int type;
63518 +};
63519 +
63520 +/* Userspace Grsecurity ACL data structures */
63521 +
63522 +struct acl_subject_label {
63523 + char *filename;
63524 + ino_t inode;
63525 + dev_t device;
63526 + __u32 mode;
63527 + kernel_cap_t cap_mask;
63528 + kernel_cap_t cap_lower;
63529 + kernel_cap_t cap_invert_audit;
63530 +
63531 + struct rlimit res[GR_NLIMITS];
63532 + __u32 resmask;
63533 +
63534 + __u8 user_trans_type;
63535 + __u8 group_trans_type;
63536 + uid_t *user_transitions;
63537 + gid_t *group_transitions;
63538 + __u16 user_trans_num;
63539 + __u16 group_trans_num;
63540 +
63541 + __u32 sock_families[2];
63542 + __u32 ip_proto[8];
63543 + __u32 ip_type;
63544 + struct acl_ip_label **ips;
63545 + __u32 ip_num;
63546 + __u32 inaddr_any_override;
63547 +
63548 + __u32 crashes;
63549 + unsigned long expires;
63550 +
63551 + struct acl_subject_label *parent_subject;
63552 + struct gr_hash_struct *hash;
63553 + struct acl_subject_label *prev;
63554 + struct acl_subject_label *next;
63555 +
63556 + struct acl_object_label **obj_hash;
63557 + __u32 obj_hash_size;
63558 + __u16 pax_flags;
63559 +};
63560 +
63561 +struct role_allowed_ip {
63562 + __u32 addr;
63563 + __u32 netmask;
63564 +
63565 + struct role_allowed_ip *prev;
63566 + struct role_allowed_ip *next;
63567 +};
63568 +
63569 +struct role_transition {
63570 + char *rolename;
63571 +
63572 + struct role_transition *prev;
63573 + struct role_transition *next;
63574 +};
63575 +
63576 +struct acl_role_label {
63577 + char *rolename;
63578 + uid_t uidgid;
63579 + __u16 roletype;
63580 +
63581 + __u16 auth_attempts;
63582 + unsigned long expires;
63583 +
63584 + struct acl_subject_label *root_label;
63585 + struct gr_hash_struct *hash;
63586 +
63587 + struct acl_role_label *prev;
63588 + struct acl_role_label *next;
63589 +
63590 + struct role_transition *transitions;
63591 + struct role_allowed_ip *allowed_ips;
63592 + uid_t *domain_children;
63593 + __u16 domain_child_num;
63594 +
63595 + umode_t umask;
63596 +
63597 + struct acl_subject_label **subj_hash;
63598 + __u32 subj_hash_size;
63599 +};
63600 +
63601 +struct user_acl_role_db {
63602 + struct acl_role_label **r_table;
63603 + __u32 num_pointers; /* Number of allocations to track */
63604 + __u32 num_roles; /* Number of roles */
63605 + __u32 num_domain_children; /* Number of domain children */
63606 + __u32 num_subjects; /* Number of subjects */
63607 + __u32 num_objects; /* Number of objects */
63608 +};
63609 +
63610 +struct acl_object_label {
63611 + char *filename;
63612 + ino_t inode;
63613 + dev_t device;
63614 + __u32 mode;
63615 +
63616 + struct acl_subject_label *nested;
63617 + struct acl_object_label *globbed;
63618 +
63619 + /* next two structures not used */
63620 +
63621 + struct acl_object_label *prev;
63622 + struct acl_object_label *next;
63623 +};
63624 +
63625 +struct acl_ip_label {
63626 + char *iface;
63627 + __u32 addr;
63628 + __u32 netmask;
63629 + __u16 low, high;
63630 + __u8 mode;
63631 + __u32 type;
63632 + __u32 proto[8];
63633 +
63634 + /* next two structures not used */
63635 +
63636 + struct acl_ip_label *prev;
63637 + struct acl_ip_label *next;
63638 +};
63639 +
63640 +struct gr_arg {
63641 + struct user_acl_role_db role_db;
63642 + unsigned char pw[GR_PW_LEN];
63643 + unsigned char salt[GR_SALT_LEN];
63644 + unsigned char sum[GR_SHA_LEN];
63645 + unsigned char sp_role[GR_SPROLE_LEN];
63646 + struct sprole_pw *sprole_pws;
63647 + dev_t segv_device;
63648 + ino_t segv_inode;
63649 + uid_t segv_uid;
63650 + __u16 num_sprole_pws;
63651 + __u16 mode;
63652 +};
63653 +
63654 +struct gr_arg_wrapper {
63655 + struct gr_arg *arg;
63656 + __u32 version;
63657 + __u32 size;
63658 +};
63659 +
63660 +struct subject_map {
63661 + struct acl_subject_label *user;
63662 + struct acl_subject_label *kernel;
63663 + struct subject_map *prev;
63664 + struct subject_map *next;
63665 +};
63666 +
63667 +struct acl_subj_map_db {
63668 + struct subject_map **s_hash;
63669 + __u32 s_size;
63670 +};
63671 +
63672 +/* End Data Structures Section */
63673 +
63674 +/* Hash functions generated by empirical testing by Brad Spengler
63675 + Makes good use of the low bits of the inode. Generally 0-1 times
63676 + in loop for successful match. 0-3 for unsuccessful match.
63677 + Shift/add algorithm with modulus of table size and an XOR*/
63678 +
63679 +static __inline__ unsigned int
63680 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63681 +{
63682 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
63683 +}
63684 +
63685 + static __inline__ unsigned int
63686 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63687 +{
63688 + return ((const unsigned long)userp % sz);
63689 +}
63690 +
63691 +static __inline__ unsigned int
63692 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63693 +{
63694 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63695 +}
63696 +
63697 +static __inline__ unsigned int
63698 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63699 +{
63700 + return full_name_hash((const unsigned char *)name, len) % sz;
63701 +}
63702 +
63703 +#define FOR_EACH_ROLE_START(role) \
63704 + role = role_list; \
63705 + while (role) {
63706 +
63707 +#define FOR_EACH_ROLE_END(role) \
63708 + role = role->prev; \
63709 + }
63710 +
63711 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63712 + subj = NULL; \
63713 + iter = 0; \
63714 + while (iter < role->subj_hash_size) { \
63715 + if (subj == NULL) \
63716 + subj = role->subj_hash[iter]; \
63717 + if (subj == NULL) { \
63718 + iter++; \
63719 + continue; \
63720 + }
63721 +
63722 +#define FOR_EACH_SUBJECT_END(subj,iter) \
63723 + subj = subj->next; \
63724 + if (subj == NULL) \
63725 + iter++; \
63726 + }
63727 +
63728 +
63729 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63730 + subj = role->hash->first; \
63731 + while (subj != NULL) {
63732 +
63733 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63734 + subj = subj->next; \
63735 + }
63736 +
63737 +#endif
63738 +
63739 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63740 new file mode 100644
63741 index 0000000..323ecf2
63742 --- /dev/null
63743 +++ b/include/linux/gralloc.h
63744 @@ -0,0 +1,9 @@
63745 +#ifndef __GRALLOC_H
63746 +#define __GRALLOC_H
63747 +
63748 +void acl_free_all(void);
63749 +int acl_alloc_stack_init(unsigned long size);
63750 +void *acl_alloc(unsigned long len);
63751 +void *acl_alloc_num(unsigned long num, unsigned long len);
63752 +
63753 +#endif
63754 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63755 new file mode 100644
63756 index 0000000..be66033
63757 --- /dev/null
63758 +++ b/include/linux/grdefs.h
63759 @@ -0,0 +1,140 @@
63760 +#ifndef GRDEFS_H
63761 +#define GRDEFS_H
63762 +
63763 +/* Begin grsecurity status declarations */
63764 +
63765 +enum {
63766 + GR_READY = 0x01,
63767 + GR_STATUS_INIT = 0x00 // disabled state
63768 +};
63769 +
63770 +/* Begin ACL declarations */
63771 +
63772 +/* Role flags */
63773 +
63774 +enum {
63775 + GR_ROLE_USER = 0x0001,
63776 + GR_ROLE_GROUP = 0x0002,
63777 + GR_ROLE_DEFAULT = 0x0004,
63778 + GR_ROLE_SPECIAL = 0x0008,
63779 + GR_ROLE_AUTH = 0x0010,
63780 + GR_ROLE_NOPW = 0x0020,
63781 + GR_ROLE_GOD = 0x0040,
63782 + GR_ROLE_LEARN = 0x0080,
63783 + GR_ROLE_TPE = 0x0100,
63784 + GR_ROLE_DOMAIN = 0x0200,
63785 + GR_ROLE_PAM = 0x0400,
63786 + GR_ROLE_PERSIST = 0x0800
63787 +};
63788 +
63789 +/* ACL Subject and Object mode flags */
63790 +enum {
63791 + GR_DELETED = 0x80000000
63792 +};
63793 +
63794 +/* ACL Object-only mode flags */
63795 +enum {
63796 + GR_READ = 0x00000001,
63797 + GR_APPEND = 0x00000002,
63798 + GR_WRITE = 0x00000004,
63799 + GR_EXEC = 0x00000008,
63800 + GR_FIND = 0x00000010,
63801 + GR_INHERIT = 0x00000020,
63802 + GR_SETID = 0x00000040,
63803 + GR_CREATE = 0x00000080,
63804 + GR_DELETE = 0x00000100,
63805 + GR_LINK = 0x00000200,
63806 + GR_AUDIT_READ = 0x00000400,
63807 + GR_AUDIT_APPEND = 0x00000800,
63808 + GR_AUDIT_WRITE = 0x00001000,
63809 + GR_AUDIT_EXEC = 0x00002000,
63810 + GR_AUDIT_FIND = 0x00004000,
63811 + GR_AUDIT_INHERIT= 0x00008000,
63812 + GR_AUDIT_SETID = 0x00010000,
63813 + GR_AUDIT_CREATE = 0x00020000,
63814 + GR_AUDIT_DELETE = 0x00040000,
63815 + GR_AUDIT_LINK = 0x00080000,
63816 + GR_PTRACERD = 0x00100000,
63817 + GR_NOPTRACE = 0x00200000,
63818 + GR_SUPPRESS = 0x00400000,
63819 + GR_NOLEARN = 0x00800000,
63820 + GR_INIT_TRANSFER= 0x01000000
63821 +};
63822 +
63823 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
63824 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
63825 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
63826 +
63827 +/* ACL subject-only mode flags */
63828 +enum {
63829 + GR_KILL = 0x00000001,
63830 + GR_VIEW = 0x00000002,
63831 + GR_PROTECTED = 0x00000004,
63832 + GR_LEARN = 0x00000008,
63833 + GR_OVERRIDE = 0x00000010,
63834 + /* just a placeholder, this mode is only used in userspace */
63835 + GR_DUMMY = 0x00000020,
63836 + GR_PROTSHM = 0x00000040,
63837 + GR_KILLPROC = 0x00000080,
63838 + GR_KILLIPPROC = 0x00000100,
63839 + /* just a placeholder, this mode is only used in userspace */
63840 + GR_NOTROJAN = 0x00000200,
63841 + GR_PROTPROCFD = 0x00000400,
63842 + GR_PROCACCT = 0x00000800,
63843 + GR_RELAXPTRACE = 0x00001000,
63844 + //GR_NESTED = 0x00002000,
63845 + GR_INHERITLEARN = 0x00004000,
63846 + GR_PROCFIND = 0x00008000,
63847 + GR_POVERRIDE = 0x00010000,
63848 + GR_KERNELAUTH = 0x00020000,
63849 + GR_ATSECURE = 0x00040000,
63850 + GR_SHMEXEC = 0x00080000
63851 +};
63852 +
63853 +enum {
63854 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
63855 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
63856 + GR_PAX_ENABLE_MPROTECT = 0x0004,
63857 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
63858 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
63859 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
63860 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
63861 + GR_PAX_DISABLE_MPROTECT = 0x0400,
63862 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
63863 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
63864 +};
63865 +
63866 +enum {
63867 + GR_ID_USER = 0x01,
63868 + GR_ID_GROUP = 0x02,
63869 +};
63870 +
63871 +enum {
63872 + GR_ID_ALLOW = 0x01,
63873 + GR_ID_DENY = 0x02,
63874 +};
63875 +
63876 +#define GR_CRASH_RES 31
63877 +#define GR_UIDTABLE_MAX 500
63878 +
63879 +/* begin resource learning section */
63880 +enum {
63881 + GR_RLIM_CPU_BUMP = 60,
63882 + GR_RLIM_FSIZE_BUMP = 50000,
63883 + GR_RLIM_DATA_BUMP = 10000,
63884 + GR_RLIM_STACK_BUMP = 1000,
63885 + GR_RLIM_CORE_BUMP = 10000,
63886 + GR_RLIM_RSS_BUMP = 500000,
63887 + GR_RLIM_NPROC_BUMP = 1,
63888 + GR_RLIM_NOFILE_BUMP = 5,
63889 + GR_RLIM_MEMLOCK_BUMP = 50000,
63890 + GR_RLIM_AS_BUMP = 500000,
63891 + GR_RLIM_LOCKS_BUMP = 2,
63892 + GR_RLIM_SIGPENDING_BUMP = 5,
63893 + GR_RLIM_MSGQUEUE_BUMP = 10000,
63894 + GR_RLIM_NICE_BUMP = 1,
63895 + GR_RLIM_RTPRIO_BUMP = 1,
63896 + GR_RLIM_RTTIME_BUMP = 1000000
63897 +};
63898 +
63899 +#endif
63900 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
63901 new file mode 100644
63902 index 0000000..c9292f7
63903 --- /dev/null
63904 +++ b/include/linux/grinternal.h
63905 @@ -0,0 +1,223 @@
63906 +#ifndef __GRINTERNAL_H
63907 +#define __GRINTERNAL_H
63908 +
63909 +#ifdef CONFIG_GRKERNSEC
63910 +
63911 +#include <linux/fs.h>
63912 +#include <linux/mnt_namespace.h>
63913 +#include <linux/nsproxy.h>
63914 +#include <linux/gracl.h>
63915 +#include <linux/grdefs.h>
63916 +#include <linux/grmsg.h>
63917 +
63918 +void gr_add_learn_entry(const char *fmt, ...)
63919 + __attribute__ ((format (printf, 1, 2)));
63920 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
63921 + const struct vfsmount *mnt);
63922 +__u32 gr_check_create(const struct dentry *new_dentry,
63923 + const struct dentry *parent,
63924 + const struct vfsmount *mnt, const __u32 mode);
63925 +int gr_check_protected_task(const struct task_struct *task);
63926 +__u32 to_gr_audit(const __u32 reqmode);
63927 +int gr_set_acls(const int type);
63928 +int gr_apply_subject_to_task(struct task_struct *task);
63929 +int gr_acl_is_enabled(void);
63930 +char gr_roletype_to_char(void);
63931 +
63932 +void gr_handle_alertkill(struct task_struct *task);
63933 +char *gr_to_filename(const struct dentry *dentry,
63934 + const struct vfsmount *mnt);
63935 +char *gr_to_filename1(const struct dentry *dentry,
63936 + const struct vfsmount *mnt);
63937 +char *gr_to_filename2(const struct dentry *dentry,
63938 + const struct vfsmount *mnt);
63939 +char *gr_to_filename3(const struct dentry *dentry,
63940 + const struct vfsmount *mnt);
63941 +
63942 +extern int grsec_enable_ptrace_readexec;
63943 +extern int grsec_enable_harden_ptrace;
63944 +extern int grsec_enable_link;
63945 +extern int grsec_enable_fifo;
63946 +extern int grsec_enable_execve;
63947 +extern int grsec_enable_shm;
63948 +extern int grsec_enable_execlog;
63949 +extern int grsec_enable_signal;
63950 +extern int grsec_enable_audit_ptrace;
63951 +extern int grsec_enable_forkfail;
63952 +extern int grsec_enable_time;
63953 +extern int grsec_enable_rofs;
63954 +extern int grsec_enable_chroot_shmat;
63955 +extern int grsec_enable_chroot_mount;
63956 +extern int grsec_enable_chroot_double;
63957 +extern int grsec_enable_chroot_pivot;
63958 +extern int grsec_enable_chroot_chdir;
63959 +extern int grsec_enable_chroot_chmod;
63960 +extern int grsec_enable_chroot_mknod;
63961 +extern int grsec_enable_chroot_fchdir;
63962 +extern int grsec_enable_chroot_nice;
63963 +extern int grsec_enable_chroot_execlog;
63964 +extern int grsec_enable_chroot_caps;
63965 +extern int grsec_enable_chroot_sysctl;
63966 +extern int grsec_enable_chroot_unix;
63967 +extern int grsec_enable_symlinkown;
63968 +extern int grsec_symlinkown_gid;
63969 +extern int grsec_enable_tpe;
63970 +extern int grsec_tpe_gid;
63971 +extern int grsec_enable_tpe_all;
63972 +extern int grsec_enable_tpe_invert;
63973 +extern int grsec_enable_socket_all;
63974 +extern int grsec_socket_all_gid;
63975 +extern int grsec_enable_socket_client;
63976 +extern int grsec_socket_client_gid;
63977 +extern int grsec_enable_socket_server;
63978 +extern int grsec_socket_server_gid;
63979 +extern int grsec_audit_gid;
63980 +extern int grsec_enable_group;
63981 +extern int grsec_enable_audit_textrel;
63982 +extern int grsec_enable_log_rwxmaps;
63983 +extern int grsec_enable_mount;
63984 +extern int grsec_enable_chdir;
63985 +extern int grsec_resource_logging;
63986 +extern int grsec_enable_blackhole;
63987 +extern int grsec_lastack_retries;
63988 +extern int grsec_enable_brute;
63989 +extern int grsec_lock;
63990 +
63991 +extern spinlock_t grsec_alert_lock;
63992 +extern unsigned long grsec_alert_wtime;
63993 +extern unsigned long grsec_alert_fyet;
63994 +
63995 +extern spinlock_t grsec_audit_lock;
63996 +
63997 +extern rwlock_t grsec_exec_file_lock;
63998 +
63999 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64000 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64001 + (tsk)->exec_file->f_vfsmnt) : "/")
64002 +
64003 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64004 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64005 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64006 +
64007 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64008 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
64009 + (tsk)->exec_file->f_vfsmnt) : "/")
64010 +
64011 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64012 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64013 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64014 +
64015 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64016 +
64017 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64018 +
64019 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
64020 + (task)->pid, (cred)->uid, \
64021 + (cred)->euid, (cred)->gid, (cred)->egid, \
64022 + gr_parent_task_fullpath(task), \
64023 + (task)->real_parent->comm, (task)->real_parent->pid, \
64024 + (pcred)->uid, (pcred)->euid, \
64025 + (pcred)->gid, (pcred)->egid
64026 +
64027 +#define GR_CHROOT_CAPS {{ \
64028 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64029 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64030 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64031 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64032 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64033 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64034 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64035 +
64036 +#define security_learn(normal_msg,args...) \
64037 +({ \
64038 + read_lock(&grsec_exec_file_lock); \
64039 + gr_add_learn_entry(normal_msg "\n", ## args); \
64040 + read_unlock(&grsec_exec_file_lock); \
64041 +})
64042 +
64043 +enum {
64044 + GR_DO_AUDIT,
64045 + GR_DONT_AUDIT,
64046 + /* used for non-audit messages that we shouldn't kill the task on */
64047 + GR_DONT_AUDIT_GOOD
64048 +};
64049 +
64050 +enum {
64051 + GR_TTYSNIFF,
64052 + GR_RBAC,
64053 + GR_RBAC_STR,
64054 + GR_STR_RBAC,
64055 + GR_RBAC_MODE2,
64056 + GR_RBAC_MODE3,
64057 + GR_FILENAME,
64058 + GR_SYSCTL_HIDDEN,
64059 + GR_NOARGS,
64060 + GR_ONE_INT,
64061 + GR_ONE_INT_TWO_STR,
64062 + GR_ONE_STR,
64063 + GR_STR_INT,
64064 + GR_TWO_STR_INT,
64065 + GR_TWO_INT,
64066 + GR_TWO_U64,
64067 + GR_THREE_INT,
64068 + GR_FIVE_INT_TWO_STR,
64069 + GR_TWO_STR,
64070 + GR_THREE_STR,
64071 + GR_FOUR_STR,
64072 + GR_STR_FILENAME,
64073 + GR_FILENAME_STR,
64074 + GR_FILENAME_TWO_INT,
64075 + GR_FILENAME_TWO_INT_STR,
64076 + GR_TEXTREL,
64077 + GR_PTRACE,
64078 + GR_RESOURCE,
64079 + GR_CAP,
64080 + GR_SIG,
64081 + GR_SIG2,
64082 + GR_CRASH1,
64083 + GR_CRASH2,
64084 + GR_PSACCT,
64085 + GR_RWXMAP
64086 +};
64087 +
64088 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64089 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64090 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64091 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64092 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64093 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64094 +#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)
64095 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64096 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64097 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64098 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64099 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64100 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64101 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64102 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64103 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64104 +#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)
64105 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64106 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64107 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64108 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64109 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64110 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64111 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64112 +#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)
64113 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64114 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64115 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64116 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64117 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64118 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64119 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64120 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64121 +#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)
64122 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64123 +
64124 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64125 +
64126 +#endif
64127 +
64128 +#endif
64129 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64130 new file mode 100644
64131 index 0000000..2bd4c8d
64132 --- /dev/null
64133 +++ b/include/linux/grmsg.h
64134 @@ -0,0 +1,111 @@
64135 +#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"
64136 +#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"
64137 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64138 +#define GR_STOPMOD_MSG "denied modification of module state by "
64139 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64140 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64141 +#define GR_IOPERM_MSG "denied use of ioperm() by "
64142 +#define GR_IOPL_MSG "denied use of iopl() by "
64143 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64144 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64145 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64146 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64147 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64148 +#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"
64149 +#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"
64150 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64151 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64152 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64153 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64154 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64155 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64156 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64157 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64158 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64159 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64160 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64161 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64162 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64163 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64164 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64165 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64166 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64167 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64168 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64169 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64170 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64171 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64172 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64173 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64174 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64175 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64176 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64177 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64178 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64179 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64180 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64181 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64182 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64183 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64184 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64185 +#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"
64186 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64187 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64188 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64189 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64190 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64191 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64192 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64193 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64194 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64195 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64196 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64197 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64198 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64199 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64200 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64201 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64202 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64203 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64204 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64205 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64206 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
64207 +#define GR_NICE_CHROOT_MSG "denied priority change by "
64208 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64209 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64210 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64211 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64212 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64213 +#define GR_TIME_MSG "time set by "
64214 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64215 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64216 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64217 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64218 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64219 +#define GR_BIND_MSG "denied bind() by "
64220 +#define GR_CONNECT_MSG "denied connect() by "
64221 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64222 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64223 +#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"
64224 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64225 +#define GR_CAP_ACL_MSG "use of %s denied for "
64226 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64227 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64228 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64229 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64230 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64231 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64232 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64233 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64234 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64235 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64236 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64237 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64238 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64239 +#define GR_VM86_MSG "denied use of vm86 by "
64240 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64241 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64242 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64243 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64244 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64245 +#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 "
64246 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64247 new file mode 100644
64248 index 0000000..f2f5d5b
64249 --- /dev/null
64250 +++ b/include/linux/grsecurity.h
64251 @@ -0,0 +1,239 @@
64252 +#ifndef GR_SECURITY_H
64253 +#define GR_SECURITY_H
64254 +#include <linux/fs.h>
64255 +#include <linux/fs_struct.h>
64256 +#include <linux/binfmts.h>
64257 +#include <linux/gracl.h>
64258 +
64259 +/* notify of brain-dead configs */
64260 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64261 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64262 +#endif
64263 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64264 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64265 +#endif
64266 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64267 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64268 +#endif
64269 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64270 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
64271 +#endif
64272 +
64273 +#include <linux/compat.h>
64274 +
64275 +struct user_arg_ptr {
64276 +#ifdef CONFIG_COMPAT
64277 + bool is_compat;
64278 +#endif
64279 + union {
64280 + const char __user *const __user *native;
64281 +#ifdef CONFIG_COMPAT
64282 + const compat_uptr_t __user *compat;
64283 +#endif
64284 + } ptr;
64285 +};
64286 +
64287 +void gr_handle_brute_attach(unsigned long mm_flags);
64288 +void gr_handle_brute_check(void);
64289 +void gr_handle_kernel_exploit(void);
64290 +int gr_process_user_ban(void);
64291 +
64292 +char gr_roletype_to_char(void);
64293 +
64294 +int gr_acl_enable_at_secure(void);
64295 +
64296 +int gr_check_user_change(int real, int effective, int fs);
64297 +int gr_check_group_change(int real, int effective, int fs);
64298 +
64299 +void gr_del_task_from_ip_table(struct task_struct *p);
64300 +
64301 +int gr_pid_is_chrooted(struct task_struct *p);
64302 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64303 +int gr_handle_chroot_nice(void);
64304 +int gr_handle_chroot_sysctl(const int op);
64305 +int gr_handle_chroot_setpriority(struct task_struct *p,
64306 + const int niceval);
64307 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64308 +int gr_handle_chroot_chroot(const struct dentry *dentry,
64309 + const struct vfsmount *mnt);
64310 +void gr_handle_chroot_chdir(struct path *path);
64311 +int gr_handle_chroot_chmod(const struct dentry *dentry,
64312 + const struct vfsmount *mnt, const int mode);
64313 +int gr_handle_chroot_mknod(const struct dentry *dentry,
64314 + const struct vfsmount *mnt, const int mode);
64315 +int gr_handle_chroot_mount(const struct dentry *dentry,
64316 + const struct vfsmount *mnt,
64317 + const char *dev_name);
64318 +int gr_handle_chroot_pivot(void);
64319 +int gr_handle_chroot_unix(const pid_t pid);
64320 +
64321 +int gr_handle_rawio(const struct inode *inode);
64322 +
64323 +void gr_handle_ioperm(void);
64324 +void gr_handle_iopl(void);
64325 +
64326 +umode_t gr_acl_umask(void);
64327 +
64328 +int gr_tpe_allow(const struct file *file);
64329 +
64330 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64331 +void gr_clear_chroot_entries(struct task_struct *task);
64332 +
64333 +void gr_log_forkfail(const int retval);
64334 +void gr_log_timechange(void);
64335 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64336 +void gr_log_chdir(const struct dentry *dentry,
64337 + const struct vfsmount *mnt);
64338 +void gr_log_chroot_exec(const struct dentry *dentry,
64339 + const struct vfsmount *mnt);
64340 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64341 +void gr_log_remount(const char *devname, const int retval);
64342 +void gr_log_unmount(const char *devname, const int retval);
64343 +void gr_log_mount(const char *from, const char *to, const int retval);
64344 +void gr_log_textrel(struct vm_area_struct *vma);
64345 +void gr_log_rwxmmap(struct file *file);
64346 +void gr_log_rwxmprotect(struct file *file);
64347 +
64348 +int gr_handle_follow_link(const struct inode *parent,
64349 + const struct inode *inode,
64350 + const struct dentry *dentry,
64351 + const struct vfsmount *mnt);
64352 +int gr_handle_fifo(const struct dentry *dentry,
64353 + const struct vfsmount *mnt,
64354 + const struct dentry *dir, const int flag,
64355 + const int acc_mode);
64356 +int gr_handle_hardlink(const struct dentry *dentry,
64357 + const struct vfsmount *mnt,
64358 + struct inode *inode,
64359 + const int mode, const struct filename *to);
64360 +
64361 +int gr_is_capable(const int cap);
64362 +int gr_is_capable_nolog(const int cap);
64363 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64364 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64365 +
64366 +void gr_learn_resource(const struct task_struct *task, const int limit,
64367 + const unsigned long wanted, const int gt);
64368 +void gr_copy_label(struct task_struct *tsk);
64369 +void gr_handle_crash(struct task_struct *task, const int sig);
64370 +int gr_handle_signal(const struct task_struct *p, const int sig);
64371 +int gr_check_crash_uid(const uid_t uid);
64372 +int gr_check_protected_task(const struct task_struct *task);
64373 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64374 +int gr_acl_handle_mmap(const struct file *file,
64375 + const unsigned long prot);
64376 +int gr_acl_handle_mprotect(const struct file *file,
64377 + const unsigned long prot);
64378 +int gr_check_hidden_task(const struct task_struct *tsk);
64379 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64380 + const struct vfsmount *mnt);
64381 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
64382 + const struct vfsmount *mnt);
64383 +__u32 gr_acl_handle_access(const struct dentry *dentry,
64384 + const struct vfsmount *mnt, const int fmode);
64385 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64386 + const struct vfsmount *mnt, umode_t *mode);
64387 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
64388 + const struct vfsmount *mnt);
64389 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64390 + const struct vfsmount *mnt);
64391 +int gr_handle_ptrace(struct task_struct *task, const long request);
64392 +int gr_handle_proc_ptrace(struct task_struct *task);
64393 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
64394 + const struct vfsmount *mnt);
64395 +int gr_check_crash_exec(const struct file *filp);
64396 +int gr_acl_is_enabled(void);
64397 +void gr_set_kernel_label(struct task_struct *task);
64398 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
64399 + const gid_t gid);
64400 +int gr_set_proc_label(const struct dentry *dentry,
64401 + const struct vfsmount *mnt,
64402 + const int unsafe_flags);
64403 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64404 + const struct vfsmount *mnt);
64405 +__u32 gr_acl_handle_open(const struct dentry *dentry,
64406 + const struct vfsmount *mnt, int acc_mode);
64407 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
64408 + const struct dentry *p_dentry,
64409 + const struct vfsmount *p_mnt,
64410 + int open_flags, int acc_mode, const int imode);
64411 +void gr_handle_create(const struct dentry *dentry,
64412 + const struct vfsmount *mnt);
64413 +void gr_handle_proc_create(const struct dentry *dentry,
64414 + const struct inode *inode);
64415 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64416 + const struct dentry *parent_dentry,
64417 + const struct vfsmount *parent_mnt,
64418 + const int mode);
64419 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64420 + const struct dentry *parent_dentry,
64421 + const struct vfsmount *parent_mnt);
64422 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64423 + const struct vfsmount *mnt);
64424 +void gr_handle_delete(const ino_t ino, const dev_t dev);
64425 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64426 + const struct vfsmount *mnt);
64427 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64428 + const struct dentry *parent_dentry,
64429 + const struct vfsmount *parent_mnt,
64430 + const struct filename *from);
64431 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64432 + const struct dentry *parent_dentry,
64433 + const struct vfsmount *parent_mnt,
64434 + const struct dentry *old_dentry,
64435 + const struct vfsmount *old_mnt, const struct filename *to);
64436 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64437 +int gr_acl_handle_rename(struct dentry *new_dentry,
64438 + struct dentry *parent_dentry,
64439 + const struct vfsmount *parent_mnt,
64440 + struct dentry *old_dentry,
64441 + struct inode *old_parent_inode,
64442 + struct vfsmount *old_mnt, const struct filename *newname);
64443 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64444 + struct dentry *old_dentry,
64445 + struct dentry *new_dentry,
64446 + struct vfsmount *mnt, const __u8 replace);
64447 +__u32 gr_check_link(const struct dentry *new_dentry,
64448 + const struct dentry *parent_dentry,
64449 + const struct vfsmount *parent_mnt,
64450 + const struct dentry *old_dentry,
64451 + const struct vfsmount *old_mnt);
64452 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64453 + const unsigned int namelen, const ino_t ino);
64454 +
64455 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64456 + const struct vfsmount *mnt);
64457 +void gr_acl_handle_exit(void);
64458 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64459 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64460 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64461 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64462 +void gr_audit_ptrace(struct task_struct *task);
64463 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64464 +void gr_put_exec_file(struct task_struct *task);
64465 +
64466 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64467 +
64468 +#ifdef CONFIG_GRKERNSEC
64469 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64470 +void gr_handle_vm86(void);
64471 +void gr_handle_mem_readwrite(u64 from, u64 to);
64472 +
64473 +void gr_log_badprocpid(const char *entry);
64474 +
64475 +extern int grsec_enable_dmesg;
64476 +extern int grsec_disable_privio;
64477 +
64478 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64479 +extern int grsec_proc_gid;
64480 +#endif
64481 +
64482 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64483 +extern int grsec_enable_chroot_findtask;
64484 +#endif
64485 +#ifdef CONFIG_GRKERNSEC_SETXID
64486 +extern int grsec_enable_setxid;
64487 +#endif
64488 +#endif
64489 +
64490 +#endif
64491 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64492 new file mode 100644
64493 index 0000000..e7ffaaf
64494 --- /dev/null
64495 +++ b/include/linux/grsock.h
64496 @@ -0,0 +1,19 @@
64497 +#ifndef __GRSOCK_H
64498 +#define __GRSOCK_H
64499 +
64500 +extern void gr_attach_curr_ip(const struct sock *sk);
64501 +extern int gr_handle_sock_all(const int family, const int type,
64502 + const int protocol);
64503 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64504 +extern int gr_handle_sock_server_other(const struct sock *sck);
64505 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64506 +extern int gr_search_connect(struct socket * sock,
64507 + struct sockaddr_in * addr);
64508 +extern int gr_search_bind(struct socket * sock,
64509 + struct sockaddr_in * addr);
64510 +extern int gr_search_listen(struct socket * sock);
64511 +extern int gr_search_accept(struct socket * sock);
64512 +extern int gr_search_socket(const int domain, const int type,
64513 + const int protocol);
64514 +
64515 +#endif
64516 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64517 index ef788b5..ac41b7b 100644
64518 --- a/include/linux/highmem.h
64519 +++ b/include/linux/highmem.h
64520 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64521 kunmap_atomic(kaddr);
64522 }
64523
64524 +static inline void sanitize_highpage(struct page *page)
64525 +{
64526 + void *kaddr;
64527 + unsigned long flags;
64528 +
64529 + local_irq_save(flags);
64530 + kaddr = kmap_atomic(page);
64531 + clear_page(kaddr);
64532 + kunmap_atomic(kaddr);
64533 + local_irq_restore(flags);
64534 +}
64535 +
64536 static inline void zero_user_segments(struct page *page,
64537 unsigned start1, unsigned end1,
64538 unsigned start2, unsigned end2)
64539 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64540 index 800de22..7a2fa46 100644
64541 --- a/include/linux/i2c.h
64542 +++ b/include/linux/i2c.h
64543 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64544 /* To determine what the adapter supports */
64545 u32 (*functionality) (struct i2c_adapter *);
64546 };
64547 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64548
64549 /*
64550 * i2c_adapter is the structure used to identify a physical i2c bus along
64551 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64552 index d23c3c2..eb63c81 100644
64553 --- a/include/linux/i2o.h
64554 +++ b/include/linux/i2o.h
64555 @@ -565,7 +565,7 @@ struct i2o_controller {
64556 struct i2o_device *exec; /* Executive */
64557 #if BITS_PER_LONG == 64
64558 spinlock_t context_list_lock; /* lock for context_list */
64559 - atomic_t context_list_counter; /* needed for unique contexts */
64560 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64561 struct list_head context_list; /* list of context id's
64562 and pointers */
64563 #endif
64564 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64565 index aff7ad8..3942bbd 100644
64566 --- a/include/linux/if_pppox.h
64567 +++ b/include/linux/if_pppox.h
64568 @@ -76,7 +76,7 @@ struct pppox_proto {
64569 int (*ioctl)(struct socket *sock, unsigned int cmd,
64570 unsigned long arg);
64571 struct module *owner;
64572 -};
64573 +} __do_const;
64574
64575 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64576 extern void unregister_pppox_proto(int proto_num);
64577 diff --git a/include/linux/init.h b/include/linux/init.h
64578 index e59041e..df0a975 100644
64579 --- a/include/linux/init.h
64580 +++ b/include/linux/init.h
64581 @@ -39,9 +39,36 @@
64582 * Also note, that this data cannot be "const".
64583 */
64584
64585 +#ifdef MODULE
64586 +#define add_init_latent_entropy
64587 +#define add_devinit_latent_entropy
64588 +#define add_cpuinit_latent_entropy
64589 +#define add_meminit_latent_entropy
64590 +#else
64591 +#define add_init_latent_entropy __latent_entropy
64592 +
64593 +#ifdef CONFIG_HOTPLUG
64594 +#define add_devinit_latent_entropy
64595 +#else
64596 +#define add_devinit_latent_entropy __latent_entropy
64597 +#endif
64598 +
64599 +#ifdef CONFIG_HOTPLUG_CPU
64600 +#define add_cpuinit_latent_entropy
64601 +#else
64602 +#define add_cpuinit_latent_entropy __latent_entropy
64603 +#endif
64604 +
64605 +#ifdef CONFIG_MEMORY_HOTPLUG
64606 +#define add_meminit_latent_entropy
64607 +#else
64608 +#define add_meminit_latent_entropy __latent_entropy
64609 +#endif
64610 +#endif
64611 +
64612 /* These are for everybody (although not all archs will actually
64613 discard it in modules) */
64614 -#define __init __section(.init.text) __cold notrace
64615 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64616 #define __initdata __section(.init.data)
64617 #define __initconst __constsection(.init.rodata)
64618 #define __exitdata __section(.exit.data)
64619 @@ -94,7 +121,7 @@
64620 #define __exit __section(.exit.text) __exitused __cold notrace
64621
64622 /* Used for HOTPLUG */
64623 -#define __devinit __section(.devinit.text) __cold notrace
64624 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64625 #define __devinitdata __section(.devinit.data)
64626 #define __devinitconst __constsection(.devinit.rodata)
64627 #define __devexit __section(.devexit.text) __exitused __cold notrace
64628 @@ -102,7 +129,7 @@
64629 #define __devexitconst __constsection(.devexit.rodata)
64630
64631 /* Used for HOTPLUG_CPU */
64632 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64633 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64634 #define __cpuinitdata __section(.cpuinit.data)
64635 #define __cpuinitconst __constsection(.cpuinit.rodata)
64636 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64637 @@ -110,7 +137,7 @@
64638 #define __cpuexitconst __constsection(.cpuexit.rodata)
64639
64640 /* Used for MEMORY_HOTPLUG */
64641 -#define __meminit __section(.meminit.text) __cold notrace
64642 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64643 #define __meminitdata __section(.meminit.data)
64644 #define __meminitconst __constsection(.meminit.rodata)
64645 #define __memexit __section(.memexit.text) __exitused __cold notrace
64646 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64647 index 6d087c5..401cab8 100644
64648 --- a/include/linux/init_task.h
64649 +++ b/include/linux/init_task.h
64650 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64651
64652 #define INIT_TASK_COMM "swapper"
64653
64654 +#ifdef CONFIG_X86
64655 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64656 +#else
64657 +#define INIT_TASK_THREAD_INFO
64658 +#endif
64659 +
64660 /*
64661 * INIT_TASK is used to set up the first task table, touch at
64662 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64663 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64664 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64665 .comm = INIT_TASK_COMM, \
64666 .thread = INIT_THREAD, \
64667 + INIT_TASK_THREAD_INFO \
64668 .fs = &init_fs, \
64669 .files = &init_files, \
64670 .signal = &init_signals, \
64671 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64672 index 5e4e617..eee383d 100644
64673 --- a/include/linux/interrupt.h
64674 +++ b/include/linux/interrupt.h
64675 @@ -435,7 +435,7 @@ enum
64676 /* map softirq index to softirq name. update 'softirq_to_name' in
64677 * kernel/softirq.c when adding a new softirq.
64678 */
64679 -extern char *softirq_to_name[NR_SOFTIRQS];
64680 +extern const char * const softirq_to_name[NR_SOFTIRQS];
64681
64682 /* softirq mask and active fields moved to irq_cpustat_t in
64683 * asm/hardirq.h to get better cache usage. KAO
64684 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64685
64686 struct softirq_action
64687 {
64688 - void (*action)(struct softirq_action *);
64689 + void (*action)(void);
64690 };
64691
64692 asmlinkage void do_softirq(void);
64693 asmlinkage void __do_softirq(void);
64694 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64695 +extern void open_softirq(int nr, void (*action)(void));
64696 extern void softirq_init(void);
64697 extern void __raise_softirq_irqoff(unsigned int nr);
64698
64699 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64700 index 6883e19..06992b1 100644
64701 --- a/include/linux/kallsyms.h
64702 +++ b/include/linux/kallsyms.h
64703 @@ -15,7 +15,8 @@
64704
64705 struct module;
64706
64707 -#ifdef CONFIG_KALLSYMS
64708 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64709 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64710 /* Lookup the address for a symbol. Returns 0 if not found. */
64711 unsigned long kallsyms_lookup_name(const char *name);
64712
64713 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64714 /* Stupid that this does nothing, but I didn't create this mess. */
64715 #define __print_symbol(fmt, addr)
64716 #endif /*CONFIG_KALLSYMS*/
64717 +#else /* when included by kallsyms.c, vsnprintf.c, or
64718 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64719 +extern void __print_symbol(const char *fmt, unsigned long address);
64720 +extern int sprint_backtrace(char *buffer, unsigned long address);
64721 +extern int sprint_symbol(char *buffer, unsigned long address);
64722 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64723 +const char *kallsyms_lookup(unsigned long addr,
64724 + unsigned long *symbolsize,
64725 + unsigned long *offset,
64726 + char **modname, char *namebuf);
64727 +#endif
64728
64729 /* This macro allows us to keep printk typechecking */
64730 static __printf(1, 2)
64731 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64732 index 4dff0c6..1ca9b72 100644
64733 --- a/include/linux/kgdb.h
64734 +++ b/include/linux/kgdb.h
64735 @@ -53,7 +53,7 @@ extern int kgdb_connected;
64736 extern int kgdb_io_module_registered;
64737
64738 extern atomic_t kgdb_setting_breakpoint;
64739 -extern atomic_t kgdb_cpu_doing_single_step;
64740 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64741
64742 extern struct task_struct *kgdb_usethread;
64743 extern struct task_struct *kgdb_contthread;
64744 @@ -255,7 +255,7 @@ struct kgdb_arch {
64745 void (*correct_hw_break)(void);
64746
64747 void (*enable_nmi)(bool on);
64748 -};
64749 +} __do_const;
64750
64751 /**
64752 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64753 @@ -280,7 +280,7 @@ struct kgdb_io {
64754 void (*pre_exception) (void);
64755 void (*post_exception) (void);
64756 int is_console;
64757 -};
64758 +} __do_const;
64759
64760 extern struct kgdb_arch arch_kgdb_ops;
64761
64762 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64763 index 5398d58..5883a34 100644
64764 --- a/include/linux/kmod.h
64765 +++ b/include/linux/kmod.h
64766 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64767 * usually useless though. */
64768 extern __printf(2, 3)
64769 int __request_module(bool wait, const char *name, ...);
64770 +extern __printf(3, 4)
64771 +int ___request_module(bool wait, char *param_name, const char *name, ...);
64772 #define request_module(mod...) __request_module(true, mod)
64773 #define request_module_nowait(mod...) __request_module(false, mod)
64774 #define try_then_request_module(x, mod...) \
64775 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64776 index 1e57449..4fede7b 100644
64777 --- a/include/linux/kobject.h
64778 +++ b/include/linux/kobject.h
64779 @@ -111,7 +111,7 @@ struct kobj_type {
64780 struct attribute **default_attrs;
64781 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64782 const void *(*namespace)(struct kobject *kobj);
64783 -};
64784 +} __do_const;
64785
64786 struct kobj_uevent_env {
64787 char *envp[UEVENT_NUM_ENVP];
64788 diff --git a/include/linux/kref.h b/include/linux/kref.h
64789 index 65af688..0592677 100644
64790 --- a/include/linux/kref.h
64791 +++ b/include/linux/kref.h
64792 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
64793 static inline int kref_sub(struct kref *kref, unsigned int count,
64794 void (*release)(struct kref *kref))
64795 {
64796 - WARN_ON(release == NULL);
64797 + BUG_ON(release == NULL);
64798
64799 if (atomic_sub_and_test((int) count, &kref->refcount)) {
64800 release(kref);
64801 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
64802 index ecc5543..0e96bcc 100644
64803 --- a/include/linux/kvm_host.h
64804 +++ b/include/linux/kvm_host.h
64805 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
64806 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
64807 void vcpu_put(struct kvm_vcpu *vcpu);
64808
64809 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64810 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64811 struct module *module);
64812 void kvm_exit(void);
64813
64814 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
64815 struct kvm_guest_debug *dbg);
64816 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
64817
64818 -int kvm_arch_init(void *opaque);
64819 +int kvm_arch_init(const void *opaque);
64820 void kvm_arch_exit(void);
64821
64822 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
64823 diff --git a/include/linux/libata.h b/include/linux/libata.h
64824 index 1e36c63..0c5046e 100644
64825 --- a/include/linux/libata.h
64826 +++ b/include/linux/libata.h
64827 @@ -915,7 +915,7 @@ struct ata_port_operations {
64828 * fields must be pointers.
64829 */
64830 const struct ata_port_operations *inherits;
64831 -};
64832 +} __do_const;
64833
64834 struct ata_port_info {
64835 unsigned long flags;
64836 diff --git a/include/linux/list.h b/include/linux/list.h
64837 index cc6d2aa..71febca 100644
64838 --- a/include/linux/list.h
64839 +++ b/include/linux/list.h
64840 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
64841 extern void list_del(struct list_head *entry);
64842 #endif
64843
64844 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
64845 +extern void pax_list_del(struct list_head *entry);
64846 +
64847 /**
64848 * list_replace - replace old entry by new one
64849 * @old : the element to be replaced
64850 diff --git a/include/linux/mm.h b/include/linux/mm.h
64851 index 280dae5..39046ec 100644
64852 --- a/include/linux/mm.h
64853 +++ b/include/linux/mm.h
64854 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
64855 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
64856 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
64857 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
64858 +
64859 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64860 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
64861 +#endif
64862 +
64863 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
64864
64865 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
64866 @@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
64867 int set_page_dirty_lock(struct page *page);
64868 int clear_page_dirty_for_io(struct page *page);
64869
64870 -/* Is the vma a continuation of the stack vma above it? */
64871 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
64872 -{
64873 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
64874 -}
64875 -
64876 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
64877 - unsigned long addr)
64878 -{
64879 - return (vma->vm_flags & VM_GROWSDOWN) &&
64880 - (vma->vm_start == addr) &&
64881 - !vma_growsdown(vma->vm_prev, addr);
64882 -}
64883 -
64884 -/* Is the vma a continuation of the stack vma below it? */
64885 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
64886 -{
64887 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
64888 -}
64889 -
64890 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
64891 - unsigned long addr)
64892 -{
64893 - return (vma->vm_flags & VM_GROWSUP) &&
64894 - (vma->vm_end == addr) &&
64895 - !vma_growsup(vma->vm_next, addr);
64896 -}
64897 -
64898 extern pid_t
64899 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
64900
64901 @@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
64902 }
64903 #endif
64904
64905 +#ifdef CONFIG_MMU
64906 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
64907 +#else
64908 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64909 +{
64910 + return __pgprot(0);
64911 +}
64912 +#endif
64913 +
64914 int vma_wants_writenotify(struct vm_area_struct *vma);
64915
64916 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
64917 @@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
64918 {
64919 return 0;
64920 }
64921 +
64922 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
64923 + unsigned long address)
64924 +{
64925 + return 0;
64926 +}
64927 #else
64928 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64929 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64930 #endif
64931
64932 #ifdef __PAGETABLE_PMD_FOLDED
64933 @@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
64934 {
64935 return 0;
64936 }
64937 +
64938 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
64939 + unsigned long address)
64940 +{
64941 + return 0;
64942 +}
64943 #else
64944 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
64945 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
64946 #endif
64947
64948 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
64949 @@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
64950 NULL: pud_offset(pgd, address);
64951 }
64952
64953 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
64954 +{
64955 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
64956 + NULL: pud_offset(pgd, address);
64957 +}
64958 +
64959 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
64960 {
64961 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
64962 NULL: pmd_offset(pud, address);
64963 }
64964 +
64965 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
64966 +{
64967 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
64968 + NULL: pmd_offset(pud, address);
64969 +}
64970 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
64971
64972 #if USE_SPLIT_PTLOCKS
64973 @@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
64974 unsigned long, unsigned long,
64975 unsigned long, unsigned long);
64976 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
64977 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
64978
64979 /* These take the mm semaphore themselves */
64980 extern unsigned long vm_brk(unsigned long, unsigned long);
64981 @@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
64982 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
64983 struct vm_area_struct **pprev);
64984
64985 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
64986 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
64987 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
64988 +
64989 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
64990 NULL if none. Assume start_addr < end_addr. */
64991 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
64992 @@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
64993 return vma;
64994 }
64995
64996 -#ifdef CONFIG_MMU
64997 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
64998 -#else
64999 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65000 -{
65001 - return __pgprot(0);
65002 -}
65003 -#endif
65004 -
65005 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65006 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65007 unsigned long pfn, unsigned long size, pgprot_t);
65008 @@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
65009 extern int sysctl_memory_failure_early_kill;
65010 extern int sysctl_memory_failure_recovery;
65011 extern void shake_page(struct page *p, int access);
65012 -extern atomic_long_t mce_bad_pages;
65013 +extern atomic_long_unchecked_t mce_bad_pages;
65014 extern int soft_offline_page(struct page *page, int flags);
65015
65016 extern void dump_page(struct page *page);
65017 @@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65018 static inline bool page_is_guard(struct page *page) { return false; }
65019 #endif /* CONFIG_DEBUG_PAGEALLOC */
65020
65021 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65022 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65023 +#else
65024 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65025 +#endif
65026 +
65027 #endif /* __KERNEL__ */
65028 #endif /* _LINUX_MM_H */
65029 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65030 index 31f8a3a..499f1db 100644
65031 --- a/include/linux/mm_types.h
65032 +++ b/include/linux/mm_types.h
65033 @@ -275,6 +275,8 @@ struct vm_area_struct {
65034 #ifdef CONFIG_NUMA
65035 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65036 #endif
65037 +
65038 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65039 };
65040
65041 struct core_thread {
65042 @@ -348,7 +350,7 @@ struct mm_struct {
65043 unsigned long def_flags;
65044 unsigned long nr_ptes; /* Page table pages */
65045 unsigned long start_code, end_code, start_data, end_data;
65046 - unsigned long start_brk, brk, start_stack;
65047 + unsigned long brk_gap, start_brk, brk, start_stack;
65048 unsigned long arg_start, arg_end, env_start, env_end;
65049
65050 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65051 @@ -399,6 +401,24 @@ struct mm_struct {
65052 struct cpumask cpumask_allocation;
65053 #endif
65054 struct uprobes_state uprobes_state;
65055 +
65056 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65057 + unsigned long pax_flags;
65058 +#endif
65059 +
65060 +#ifdef CONFIG_PAX_DLRESOLVE
65061 + unsigned long call_dl_resolve;
65062 +#endif
65063 +
65064 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65065 + unsigned long call_syscall;
65066 +#endif
65067 +
65068 +#ifdef CONFIG_PAX_ASLR
65069 + unsigned long delta_mmap; /* randomized offset */
65070 + unsigned long delta_stack; /* randomized offset */
65071 +#endif
65072 +
65073 };
65074
65075 static inline void mm_init_cpumask(struct mm_struct *mm)
65076 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65077 index c5d5278..f0b68c8 100644
65078 --- a/include/linux/mmiotrace.h
65079 +++ b/include/linux/mmiotrace.h
65080 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65081 /* Called from ioremap.c */
65082 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65083 void __iomem *addr);
65084 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
65085 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65086
65087 /* For anyone to insert markers. Remember trailing newline. */
65088 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65089 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65090 {
65091 }
65092
65093 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65094 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65095 {
65096 }
65097
65098 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65099 index a23923b..073fee4 100644
65100 --- a/include/linux/mmzone.h
65101 +++ b/include/linux/mmzone.h
65102 @@ -421,7 +421,7 @@ struct zone {
65103 unsigned long flags; /* zone flags, see below */
65104
65105 /* Zone statistics */
65106 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65107 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65108
65109 /*
65110 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65111 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65112 index fed3def..7cc3f93 100644
65113 --- a/include/linux/mod_devicetable.h
65114 +++ b/include/linux/mod_devicetable.h
65115 @@ -12,7 +12,7 @@
65116 typedef unsigned long kernel_ulong_t;
65117 #endif
65118
65119 -#define PCI_ANY_ID (~0)
65120 +#define PCI_ANY_ID ((__u16)~0)
65121
65122 struct pci_device_id {
65123 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65124 @@ -139,7 +139,7 @@ struct usb_device_id {
65125 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65126 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65127
65128 -#define HID_ANY_ID (~0)
65129 +#define HID_ANY_ID (~0U)
65130 #define HID_BUS_ANY 0xffff
65131 #define HID_GROUP_ANY 0x0000
65132
65133 diff --git a/include/linux/module.h b/include/linux/module.h
65134 index 1375ee3..d631af0 100644
65135 --- a/include/linux/module.h
65136 +++ b/include/linux/module.h
65137 @@ -17,9 +17,11 @@
65138 #include <linux/moduleparam.h>
65139 #include <linux/tracepoint.h>
65140 #include <linux/export.h>
65141 +#include <linux/fs.h>
65142
65143 #include <linux/percpu.h>
65144 #include <asm/module.h>
65145 +#include <asm/pgtable.h>
65146
65147 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65148 #define MODULE_SIG_STRING "~Module signature appended~\n"
65149 @@ -281,19 +283,16 @@ struct module
65150 int (*init)(void);
65151
65152 /* If this is non-NULL, vfree after init() returns */
65153 - void *module_init;
65154 + void *module_init_rx, *module_init_rw;
65155
65156 /* Here is the actual code + data, vfree'd on unload. */
65157 - void *module_core;
65158 + void *module_core_rx, *module_core_rw;
65159
65160 /* Here are the sizes of the init and core sections */
65161 - unsigned int init_size, core_size;
65162 + unsigned int init_size_rw, core_size_rw;
65163
65164 /* The size of the executable code in each section. */
65165 - unsigned int init_text_size, core_text_size;
65166 -
65167 - /* Size of RO sections of the module (text+rodata) */
65168 - unsigned int init_ro_size, core_ro_size;
65169 + unsigned int init_size_rx, core_size_rx;
65170
65171 /* Arch-specific module values */
65172 struct mod_arch_specific arch;
65173 @@ -349,6 +348,10 @@ struct module
65174 #ifdef CONFIG_EVENT_TRACING
65175 struct ftrace_event_call **trace_events;
65176 unsigned int num_trace_events;
65177 + struct file_operations trace_id;
65178 + struct file_operations trace_enable;
65179 + struct file_operations trace_format;
65180 + struct file_operations trace_filter;
65181 #endif
65182 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65183 unsigned int num_ftrace_callsites;
65184 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65185 bool is_module_percpu_address(unsigned long addr);
65186 bool is_module_text_address(unsigned long addr);
65187
65188 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65189 +{
65190 +
65191 +#ifdef CONFIG_PAX_KERNEXEC
65192 + if (ktla_ktva(addr) >= (unsigned long)start &&
65193 + ktla_ktva(addr) < (unsigned long)start + size)
65194 + return 1;
65195 +#endif
65196 +
65197 + return ((void *)addr >= start && (void *)addr < start + size);
65198 +}
65199 +
65200 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65201 +{
65202 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65203 +}
65204 +
65205 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65206 +{
65207 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65208 +}
65209 +
65210 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65211 +{
65212 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65213 +}
65214 +
65215 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65216 +{
65217 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65218 +}
65219 +
65220 static inline int within_module_core(unsigned long addr, struct module *mod)
65221 {
65222 - return (unsigned long)mod->module_core <= addr &&
65223 - addr < (unsigned long)mod->module_core + mod->core_size;
65224 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65225 }
65226
65227 static inline int within_module_init(unsigned long addr, struct module *mod)
65228 {
65229 - return (unsigned long)mod->module_init <= addr &&
65230 - addr < (unsigned long)mod->module_init + mod->init_size;
65231 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65232 }
65233
65234 /* Search for module by name: must hold module_mutex. */
65235 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65236 index 560ca53..5ee8d73 100644
65237 --- a/include/linux/moduleloader.h
65238 +++ b/include/linux/moduleloader.h
65239 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65240
65241 /* Allocator used for allocating struct module, core sections and init
65242 sections. Returns NULL on failure. */
65243 -void *module_alloc(unsigned long size);
65244 +void *module_alloc(unsigned long size) __size_overflow(1);
65245 +
65246 +#ifdef CONFIG_PAX_KERNEXEC
65247 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
65248 +#else
65249 +#define module_alloc_exec(x) module_alloc(x)
65250 +#endif
65251
65252 /* Free memory returned from module_alloc. */
65253 void module_free(struct module *mod, void *module_region);
65254
65255 +#ifdef CONFIG_PAX_KERNEXEC
65256 +void module_free_exec(struct module *mod, void *module_region);
65257 +#else
65258 +#define module_free_exec(x, y) module_free((x), (y))
65259 +#endif
65260 +
65261 /*
65262 * Apply the given relocation to the (simplified) ELF. Return -error
65263 * or 0.
65264 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65265 unsigned int relsec,
65266 struct module *me)
65267 {
65268 +#ifdef CONFIG_MODULES
65269 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65270 +#endif
65271 return -ENOEXEC;
65272 }
65273 #endif
65274 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65275 unsigned int relsec,
65276 struct module *me)
65277 {
65278 +#ifdef CONFIG_MODULES
65279 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65280 +#endif
65281 return -ENOEXEC;
65282 }
65283 #endif
65284 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65285 index d6a5806..7c13347 100644
65286 --- a/include/linux/moduleparam.h
65287 +++ b/include/linux/moduleparam.h
65288 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65289 * @len is usually just sizeof(string).
65290 */
65291 #define module_param_string(name, string, len, perm) \
65292 - static const struct kparam_string __param_string_##name \
65293 + static const struct kparam_string __param_string_##name __used \
65294 = { len, string }; \
65295 __module_param_call(MODULE_PARAM_PREFIX, name, \
65296 &param_ops_string, \
65297 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65298 */
65299 #define module_param_array_named(name, array, type, nump, perm) \
65300 param_check_##type(name, &(array)[0]); \
65301 - static const struct kparam_array __param_arr_##name \
65302 + static const struct kparam_array __param_arr_##name __used \
65303 = { .max = ARRAY_SIZE(array), .num = nump, \
65304 .ops = &param_ops_##type, \
65305 .elemsize = sizeof(array[0]), .elem = array }; \
65306 diff --git a/include/linux/namei.h b/include/linux/namei.h
65307 index 4bf19d8..5268cea 100644
65308 --- a/include/linux/namei.h
65309 +++ b/include/linux/namei.h
65310 @@ -18,7 +18,7 @@ struct nameidata {
65311 unsigned seq;
65312 int last_type;
65313 unsigned depth;
65314 - char *saved_names[MAX_NESTED_LINKS + 1];
65315 + const char *saved_names[MAX_NESTED_LINKS + 1];
65316 };
65317
65318 /*
65319 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65320
65321 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65322
65323 -static inline void nd_set_link(struct nameidata *nd, char *path)
65324 +static inline void nd_set_link(struct nameidata *nd, const char *path)
65325 {
65326 nd->saved_names[nd->depth] = path;
65327 }
65328
65329 -static inline char *nd_get_link(struct nameidata *nd)
65330 +static inline const char *nd_get_link(const struct nameidata *nd)
65331 {
65332 return nd->saved_names[nd->depth];
65333 }
65334 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65335 index a848ffc..3bbbaee 100644
65336 --- a/include/linux/netdevice.h
65337 +++ b/include/linux/netdevice.h
65338 @@ -999,6 +999,7 @@ struct net_device_ops {
65339 struct net_device *dev,
65340 int idx);
65341 };
65342 +typedef struct net_device_ops __no_const net_device_ops_no_const;
65343
65344 /*
65345 * The DEVICE structure.
65346 @@ -1059,7 +1060,7 @@ struct net_device {
65347 int iflink;
65348
65349 struct net_device_stats stats;
65350 - atomic_long_t rx_dropped; /* dropped packets by core network
65351 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65352 * Do not use this in drivers.
65353 */
65354
65355 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65356 index 7958e84..ed74d7a 100644
65357 --- a/include/linux/netfilter/ipset/ip_set.h
65358 +++ b/include/linux/netfilter/ipset/ip_set.h
65359 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
65360 /* Return true if "b" set is the same as "a"
65361 * according to the create set parameters */
65362 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65363 -};
65364 +} __do_const;
65365
65366 /* The core set type structure */
65367 struct ip_set_type {
65368 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65369 index 4966dde..7d8ce06 100644
65370 --- a/include/linux/netfilter/nfnetlink.h
65371 +++ b/include/linux/netfilter/nfnetlink.h
65372 @@ -16,7 +16,7 @@ struct nfnl_callback {
65373 const struct nlattr * const cda[]);
65374 const struct nla_policy *policy; /* netlink attribute policy */
65375 const u_int16_t attr_count; /* number of nlattr's */
65376 -};
65377 +} __do_const;
65378
65379 struct nfnetlink_subsystem {
65380 const char *name;
65381 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65382 new file mode 100644
65383 index 0000000..33f4af8
65384 --- /dev/null
65385 +++ b/include/linux/netfilter/xt_gradm.h
65386 @@ -0,0 +1,9 @@
65387 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
65388 +#define _LINUX_NETFILTER_XT_GRADM_H 1
65389 +
65390 +struct xt_gradm_mtinfo {
65391 + __u16 flags;
65392 + __u16 invflags;
65393 +};
65394 +
65395 +#endif
65396 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65397 index d65746e..62e72c2 100644
65398 --- a/include/linux/notifier.h
65399 +++ b/include/linux/notifier.h
65400 @@ -51,7 +51,8 @@ struct notifier_block {
65401 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65402 struct notifier_block __rcu *next;
65403 int priority;
65404 -};
65405 +} __do_const;
65406 +typedef struct notifier_block __no_const notifier_block_no_const;
65407
65408 struct atomic_notifier_head {
65409 spinlock_t lock;
65410 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65411 index a4c5624..79d6d88 100644
65412 --- a/include/linux/oprofile.h
65413 +++ b/include/linux/oprofile.h
65414 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65415 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65416 char const * name, ulong * val);
65417
65418 -/** Create a file for read-only access to an atomic_t. */
65419 +/** Create a file for read-only access to an atomic_unchecked_t. */
65420 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65421 - char const * name, atomic_t * val);
65422 + char const * name, atomic_unchecked_t * val);
65423
65424 /** create a directory */
65425 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65426 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65427 index 6bfb2faa..1204767 100644
65428 --- a/include/linux/perf_event.h
65429 +++ b/include/linux/perf_event.h
65430 @@ -328,8 +328,8 @@ struct perf_event {
65431
65432 enum perf_event_active_state state;
65433 unsigned int attach_state;
65434 - local64_t count;
65435 - atomic64_t child_count;
65436 + local64_t count; /* PaX: fix it one day */
65437 + atomic64_unchecked_t child_count;
65438
65439 /*
65440 * These are the total time in nanoseconds that the event
65441 @@ -380,8 +380,8 @@ struct perf_event {
65442 * These accumulate total time (in nanoseconds) that children
65443 * events have been enabled and running, respectively.
65444 */
65445 - atomic64_t child_total_time_enabled;
65446 - atomic64_t child_total_time_running;
65447 + atomic64_unchecked_t child_total_time_enabled;
65448 + atomic64_unchecked_t child_total_time_running;
65449
65450 /*
65451 * Protect attach/detach and child_list:
65452 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65453 index ad1a427..6419649 100644
65454 --- a/include/linux/pipe_fs_i.h
65455 +++ b/include/linux/pipe_fs_i.h
65456 @@ -45,9 +45,9 @@ struct pipe_buffer {
65457 struct pipe_inode_info {
65458 wait_queue_head_t wait;
65459 unsigned int nrbufs, curbuf, buffers;
65460 - unsigned int readers;
65461 - unsigned int writers;
65462 - unsigned int waiting_writers;
65463 + atomic_t readers;
65464 + atomic_t writers;
65465 + atomic_t waiting_writers;
65466 unsigned int r_counter;
65467 unsigned int w_counter;
65468 struct page *tmp_page;
65469 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65470 index 5f28cae..3d23723 100644
65471 --- a/include/linux/platform_data/usb-ehci-s5p.h
65472 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65473 @@ -14,7 +14,7 @@
65474 struct s5p_ehci_platdata {
65475 int (*phy_init)(struct platform_device *pdev, int type);
65476 int (*phy_exit)(struct platform_device *pdev, int type);
65477 -};
65478 +} __no_const;
65479
65480 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65481
65482 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65483 index f271860..6b3bec5 100644
65484 --- a/include/linux/pm_runtime.h
65485 +++ b/include/linux/pm_runtime.h
65486 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65487
65488 static inline void pm_runtime_mark_last_busy(struct device *dev)
65489 {
65490 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65491 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65492 }
65493
65494 #else /* !CONFIG_PM_RUNTIME */
65495 diff --git a/include/linux/poison.h b/include/linux/poison.h
65496 index 2110a81..13a11bb 100644
65497 --- a/include/linux/poison.h
65498 +++ b/include/linux/poison.h
65499 @@ -19,8 +19,8 @@
65500 * under normal circumstances, used to verify that nobody uses
65501 * non-initialized list entries.
65502 */
65503 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65504 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65505 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65506 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65507
65508 /********** include/linux/timer.h **********/
65509 /*
65510 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65511 index 4a496eb..d9c5659 100644
65512 --- a/include/linux/power/smartreflex.h
65513 +++ b/include/linux/power/smartreflex.h
65514 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65515 int (*notify)(struct omap_sr *sr, u32 status);
65516 u8 notify_flags;
65517 u8 class_type;
65518 -};
65519 +} __do_const;
65520
65521 /**
65522 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65523 diff --git a/include/linux/printk.h b/include/linux/printk.h
65524 index 9afc01e..92c32e8 100644
65525 --- a/include/linux/printk.h
65526 +++ b/include/linux/printk.h
65527 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65528 extern int printk_needs_cpu(int cpu);
65529 extern void printk_tick(void);
65530
65531 +extern int kptr_restrict;
65532 +
65533 #ifdef CONFIG_PRINTK
65534 asmlinkage __printf(5, 0)
65535 int vprintk_emit(int facility, int level,
65536 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65537
65538 extern int printk_delay_msec;
65539 extern int dmesg_restrict;
65540 -extern int kptr_restrict;
65541
65542 void log_buf_kexec_setup(void);
65543 void __init setup_log_buf(int early);
65544 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65545 index 3fd2e87..75db910 100644
65546 --- a/include/linux/proc_fs.h
65547 +++ b/include/linux/proc_fs.h
65548 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65549 return proc_create_data(name, mode, parent, proc_fops, NULL);
65550 }
65551
65552 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65553 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65554 +{
65555 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65556 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65557 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65558 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65559 +#else
65560 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65561 +#endif
65562 +}
65563 +
65564 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65565 umode_t mode, struct proc_dir_entry *base,
65566 read_proc_t *read_proc, void * data)
65567 diff --git a/include/linux/random.h b/include/linux/random.h
65568 index 6330ed4..419c6c3 100644
65569 --- a/include/linux/random.h
65570 +++ b/include/linux/random.h
65571 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65572
65573 u32 prandom32(struct rnd_state *);
65574
65575 +static inline unsigned long pax_get_random_long(void)
65576 +{
65577 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65578 +}
65579 +
65580 /*
65581 * Handle minimum values for seeds
65582 */
65583 static inline u32 __seed(u32 x, u32 m)
65584 {
65585 - return (x < m) ? x + m : x;
65586 + return (x <= m) ? x + m + 1 : x;
65587 }
65588
65589 /**
65590 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65591 index 23b3630..e1bc12b 100644
65592 --- a/include/linux/reboot.h
65593 +++ b/include/linux/reboot.h
65594 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65595 * Architecture-specific implementations of sys_reboot commands.
65596 */
65597
65598 -extern void machine_restart(char *cmd);
65599 -extern void machine_halt(void);
65600 -extern void machine_power_off(void);
65601 +extern void machine_restart(char *cmd) __noreturn;
65602 +extern void machine_halt(void) __noreturn;
65603 +extern void machine_power_off(void) __noreturn;
65604
65605 extern void machine_shutdown(void);
65606 struct pt_regs;
65607 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65608 */
65609
65610 extern void kernel_restart_prepare(char *cmd);
65611 -extern void kernel_restart(char *cmd);
65612 -extern void kernel_halt(void);
65613 -extern void kernel_power_off(void);
65614 +extern void kernel_restart(char *cmd) __noreturn;
65615 +extern void kernel_halt(void) __noreturn;
65616 +extern void kernel_power_off(void) __noreturn;
65617
65618 extern int C_A_D; /* for sysctl */
65619 void ctrl_alt_del(void);
65620 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65621 * Emergency restart, callable from an interrupt handler.
65622 */
65623
65624 -extern void emergency_restart(void);
65625 +extern void emergency_restart(void) __noreturn;
65626 #include <asm/emergency-restart.h>
65627
65628 #endif /* _LINUX_REBOOT_H */
65629 diff --git a/include/linux/regset.h b/include/linux/regset.h
65630 index 8e0c9fe..fdb64bc 100644
65631 --- a/include/linux/regset.h
65632 +++ b/include/linux/regset.h
65633 @@ -161,7 +161,7 @@ struct user_regset {
65634 unsigned int align;
65635 unsigned int bias;
65636 unsigned int core_note_type;
65637 -};
65638 +} __do_const;
65639
65640 /**
65641 * struct user_regset_view - available regsets
65642 diff --git a/include/linux/relay.h b/include/linux/relay.h
65643 index 91cacc3..b55ff74 100644
65644 --- a/include/linux/relay.h
65645 +++ b/include/linux/relay.h
65646 @@ -160,7 +160,7 @@ struct rchan_callbacks
65647 * The callback should return 0 if successful, negative if not.
65648 */
65649 int (*remove_buf_file)(struct dentry *dentry);
65650 -};
65651 +} __no_const;
65652
65653 /*
65654 * CONFIG_RELAY kernel API, kernel/relay.c
65655 diff --git a/include/linux/rio.h b/include/linux/rio.h
65656 index a3e7842..d973ca6 100644
65657 --- a/include/linux/rio.h
65658 +++ b/include/linux/rio.h
65659 @@ -339,7 +339,7 @@ struct rio_ops {
65660 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65661 u64 rstart, u32 size, u32 flags);
65662 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65663 -};
65664 +} __no_const;
65665
65666 #define RIO_RESOURCE_MEM 0x00000100
65667 #define RIO_RESOURCE_DOORBELL 0x00000200
65668 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65669 index bfe1f47..6a33ee3 100644
65670 --- a/include/linux/rmap.h
65671 +++ b/include/linux/rmap.h
65672 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65673 void anon_vma_init(void); /* create anon_vma_cachep */
65674 int anon_vma_prepare(struct vm_area_struct *);
65675 void unlink_anon_vmas(struct vm_area_struct *);
65676 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65677 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65678 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65679 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65680
65681 static inline void anon_vma_merge(struct vm_area_struct *vma,
65682 struct vm_area_struct *next)
65683 diff --git a/include/linux/sched.h b/include/linux/sched.h
65684 index 3e63925..1d69dff 100644
65685 --- a/include/linux/sched.h
65686 +++ b/include/linux/sched.h
65687 @@ -61,6 +61,7 @@ struct bio_list;
65688 struct fs_struct;
65689 struct perf_event_context;
65690 struct blk_plug;
65691 +struct linux_binprm;
65692
65693 /*
65694 * List of flags we want to share for kernel threads,
65695 @@ -344,10 +345,23 @@ struct user_namespace;
65696 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65697
65698 extern int sysctl_max_map_count;
65699 +extern unsigned long sysctl_heap_stack_gap;
65700
65701 #include <linux/aio.h>
65702
65703 #ifdef CONFIG_MMU
65704 +
65705 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65706 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65707 +#else
65708 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65709 +{
65710 + return 0;
65711 +}
65712 +#endif
65713 +
65714 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65715 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65716 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65717 extern unsigned long
65718 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65719 @@ -614,6 +628,17 @@ struct signal_struct {
65720 #ifdef CONFIG_TASKSTATS
65721 struct taskstats *stats;
65722 #endif
65723 +
65724 +#ifdef CONFIG_GRKERNSEC
65725 + u32 curr_ip;
65726 + u32 saved_ip;
65727 + u32 gr_saddr;
65728 + u32 gr_daddr;
65729 + u16 gr_sport;
65730 + u16 gr_dport;
65731 + u8 used_accept:1;
65732 +#endif
65733 +
65734 #ifdef CONFIG_AUDIT
65735 unsigned audit_tty;
65736 struct tty_audit_buf *tty_audit_buf;
65737 @@ -691,6 +716,11 @@ struct user_struct {
65738 struct key *session_keyring; /* UID's default session keyring */
65739 #endif
65740
65741 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65742 + unsigned int banned;
65743 + unsigned long ban_expires;
65744 +#endif
65745 +
65746 /* Hash table maintenance information */
65747 struct hlist_node uidhash_node;
65748 kuid_t uid;
65749 @@ -1312,8 +1342,8 @@ struct task_struct {
65750 struct list_head thread_group;
65751
65752 struct completion *vfork_done; /* for vfork() */
65753 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65754 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65755 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65756 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65757
65758 cputime_t utime, stime, utimescaled, stimescaled;
65759 cputime_t gtime;
65760 @@ -1329,11 +1359,6 @@ struct task_struct {
65761 struct task_cputime cputime_expires;
65762 struct list_head cpu_timers[3];
65763
65764 -/* process credentials */
65765 - const struct cred __rcu *real_cred; /* objective and real subjective task
65766 - * credentials (COW) */
65767 - const struct cred __rcu *cred; /* effective (overridable) subjective task
65768 - * credentials (COW) */
65769 char comm[TASK_COMM_LEN]; /* executable name excluding path
65770 - access with [gs]et_task_comm (which lock
65771 it with task_lock())
65772 @@ -1350,6 +1375,10 @@ struct task_struct {
65773 #endif
65774 /* CPU-specific state of this task */
65775 struct thread_struct thread;
65776 +/* thread_info moved to task_struct */
65777 +#ifdef CONFIG_X86
65778 + struct thread_info tinfo;
65779 +#endif
65780 /* filesystem information */
65781 struct fs_struct *fs;
65782 /* open file information */
65783 @@ -1423,6 +1452,10 @@ struct task_struct {
65784 gfp_t lockdep_reclaim_gfp;
65785 #endif
65786
65787 +/* process credentials */
65788 + const struct cred __rcu *real_cred; /* objective and real subjective task
65789 + * credentials (COW) */
65790 +
65791 /* journalling filesystem info */
65792 void *journal_info;
65793
65794 @@ -1461,6 +1494,10 @@ struct task_struct {
65795 /* cg_list protected by css_set_lock and tsk->alloc_lock */
65796 struct list_head cg_list;
65797 #endif
65798 +
65799 + const struct cred __rcu *cred; /* effective (overridable) subjective task
65800 + * credentials (COW) */
65801 +
65802 #ifdef CONFIG_FUTEX
65803 struct robust_list_head __user *robust_list;
65804 #ifdef CONFIG_COMPAT
65805 @@ -1548,8 +1585,75 @@ struct task_struct {
65806 #ifdef CONFIG_UPROBES
65807 struct uprobe_task *utask;
65808 #endif
65809 +
65810 +#ifdef CONFIG_GRKERNSEC
65811 + /* grsecurity */
65812 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65813 + u64 exec_id;
65814 +#endif
65815 +#ifdef CONFIG_GRKERNSEC_SETXID
65816 + const struct cred *delayed_cred;
65817 +#endif
65818 + struct dentry *gr_chroot_dentry;
65819 + struct acl_subject_label *acl;
65820 + struct acl_role_label *role;
65821 + struct file *exec_file;
65822 + unsigned long brute_expires;
65823 + u16 acl_role_id;
65824 + /* is this the task that authenticated to the special role */
65825 + u8 acl_sp_role;
65826 + u8 is_writable;
65827 + u8 brute;
65828 + u8 gr_is_chrooted;
65829 +#endif
65830 +
65831 };
65832
65833 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
65834 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
65835 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
65836 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
65837 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
65838 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
65839 +
65840 +#ifdef CONFIG_PAX_SOFTMODE
65841 +extern int pax_softmode;
65842 +#endif
65843 +
65844 +extern int pax_check_flags(unsigned long *);
65845 +
65846 +/* if tsk != current then task_lock must be held on it */
65847 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65848 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
65849 +{
65850 + if (likely(tsk->mm))
65851 + return tsk->mm->pax_flags;
65852 + else
65853 + return 0UL;
65854 +}
65855 +
65856 +/* if tsk != current then task_lock must be held on it */
65857 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
65858 +{
65859 + if (likely(tsk->mm)) {
65860 + tsk->mm->pax_flags = flags;
65861 + return 0;
65862 + }
65863 + return -EINVAL;
65864 +}
65865 +#endif
65866 +
65867 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
65868 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
65869 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
65870 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
65871 +#endif
65872 +
65873 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
65874 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
65875 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
65876 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
65877 +
65878 /* Future-safe accessor for struct task_struct's cpus_allowed. */
65879 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
65880
65881 @@ -2092,7 +2196,9 @@ void yield(void);
65882 extern struct exec_domain default_exec_domain;
65883
65884 union thread_union {
65885 +#ifndef CONFIG_X86
65886 struct thread_info thread_info;
65887 +#endif
65888 unsigned long stack[THREAD_SIZE/sizeof(long)];
65889 };
65890
65891 @@ -2125,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
65892 */
65893
65894 extern struct task_struct *find_task_by_vpid(pid_t nr);
65895 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
65896 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
65897 struct pid_namespace *ns);
65898
65899 @@ -2281,7 +2388,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
65900 extern void exit_itimers(struct signal_struct *);
65901 extern void flush_itimer_signals(void);
65902
65903 -extern void do_group_exit(int);
65904 +extern __noreturn void do_group_exit(int);
65905
65906 extern void daemonize(const char *, ...);
65907 extern int allow_signal(int);
65908 @@ -2485,9 +2592,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
65909
65910 #endif
65911
65912 -static inline int object_is_on_stack(void *obj)
65913 +static inline int object_starts_on_stack(void *obj)
65914 {
65915 - void *stack = task_stack_page(current);
65916 + const void *stack = task_stack_page(current);
65917
65918 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
65919 }
65920 diff --git a/include/linux/security.h b/include/linux/security.h
65921 index 05e88bd..5cda002 100644
65922 --- a/include/linux/security.h
65923 +++ b/include/linux/security.h
65924 @@ -26,6 +26,7 @@
65925 #include <linux/capability.h>
65926 #include <linux/slab.h>
65927 #include <linux/err.h>
65928 +#include <linux/grsecurity.h>
65929
65930 struct linux_binprm;
65931 struct cred;
65932 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
65933 index 68a04a3..866e6a1 100644
65934 --- a/include/linux/seq_file.h
65935 +++ b/include/linux/seq_file.h
65936 @@ -26,6 +26,9 @@ struct seq_file {
65937 struct mutex lock;
65938 const struct seq_operations *op;
65939 int poll_event;
65940 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65941 + u64 exec_id;
65942 +#endif
65943 #ifdef CONFIG_USER_NS
65944 struct user_namespace *user_ns;
65945 #endif
65946 @@ -38,6 +41,7 @@ struct seq_operations {
65947 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
65948 int (*show) (struct seq_file *m, void *v);
65949 };
65950 +typedef struct seq_operations __no_const seq_operations_no_const;
65951
65952 #define SEQ_SKIP 1
65953
65954 diff --git a/include/linux/shm.h b/include/linux/shm.h
65955 index bcf8a6a..4d0af77 100644
65956 --- a/include/linux/shm.h
65957 +++ b/include/linux/shm.h
65958 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
65959
65960 /* The task created the shm object. NULL if the task is dead. */
65961 struct task_struct *shm_creator;
65962 +#ifdef CONFIG_GRKERNSEC
65963 + time_t shm_createtime;
65964 + pid_t shm_lapid;
65965 +#endif
65966 };
65967
65968 /* shm_mode upper byte flags */
65969 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
65970 index 6a2c34e..a1f320f 100644
65971 --- a/include/linux/skbuff.h
65972 +++ b/include/linux/skbuff.h
65973 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
65974 extern struct sk_buff *__alloc_skb(unsigned int size,
65975 gfp_t priority, int flags, int node);
65976 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
65977 -static inline struct sk_buff *alloc_skb(unsigned int size,
65978 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
65979 gfp_t priority)
65980 {
65981 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
65982 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
65983 */
65984 static inline int skb_queue_empty(const struct sk_buff_head *list)
65985 {
65986 - return list->next == (struct sk_buff *)list;
65987 + return list->next == (const struct sk_buff *)list;
65988 }
65989
65990 /**
65991 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
65992 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65993 const struct sk_buff *skb)
65994 {
65995 - return skb->next == (struct sk_buff *)list;
65996 + return skb->next == (const struct sk_buff *)list;
65997 }
65998
65999 /**
66000 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66001 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66002 const struct sk_buff *skb)
66003 {
66004 - return skb->prev == (struct sk_buff *)list;
66005 + return skb->prev == (const struct sk_buff *)list;
66006 }
66007
66008 /**
66009 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66010 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66011 */
66012 #ifndef NET_SKB_PAD
66013 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66014 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66015 #endif
66016
66017 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66018 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66019 int noblock, int *err);
66020 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66021 struct poll_table_struct *wait);
66022 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66023 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66024 int offset, struct iovec *to,
66025 int size);
66026 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66027 diff --git a/include/linux/slab.h b/include/linux/slab.h
66028 index 83d1a14..209e1a6 100644
66029 --- a/include/linux/slab.h
66030 +++ b/include/linux/slab.h
66031 @@ -11,12 +11,20 @@
66032
66033 #include <linux/gfp.h>
66034 #include <linux/types.h>
66035 +#include <linux/err.h>
66036
66037 /*
66038 * Flags to pass to kmem_cache_create().
66039 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66040 */
66041 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66042 +
66043 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66044 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66045 +#else
66046 +#define SLAB_USERCOPY 0x00000000UL
66047 +#endif
66048 +
66049 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66050 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66051 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66052 @@ -87,10 +95,13 @@
66053 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66054 * Both make kfree a no-op.
66055 */
66056 -#define ZERO_SIZE_PTR ((void *)16)
66057 +#define ZERO_SIZE_PTR \
66058 +({ \
66059 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66060 + (void *)(-MAX_ERRNO-1L); \
66061 +})
66062
66063 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66064 - (unsigned long)ZERO_SIZE_PTR)
66065 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66066
66067 /*
66068 * Common fields provided in kmem_cache by all slab allocators
66069 @@ -110,7 +121,7 @@ struct kmem_cache {
66070 unsigned int align; /* Alignment as calculated */
66071 unsigned long flags; /* Active flags on the slab */
66072 const char *name; /* Slab name for sysfs */
66073 - int refcount; /* Use counter */
66074 + atomic_t refcount; /* Use counter */
66075 void (*ctor)(void *); /* Called on object slot creation */
66076 struct list_head list; /* List of all slab caches on the system */
66077 };
66078 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66079 void kfree(const void *);
66080 void kzfree(const void *);
66081 size_t ksize(const void *);
66082 +const char *check_heap_object(const void *ptr, unsigned long n);
66083 +bool is_usercopy_object(const void *ptr);
66084
66085 /*
66086 * Allocator specific definitions. These are mainly used to establish optimized
66087 @@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66088 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66089 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66090 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66091 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66092 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66093 #define kmalloc_track_caller(size, flags) \
66094 __kmalloc_track_caller(size, flags, _RET_IP_)
66095 #else
66096 @@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66097 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66098 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66099 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66100 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66101 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66102 #define kmalloc_node_track_caller(size, flags, node) \
66103 __kmalloc_node_track_caller(size, flags, node, \
66104 _RET_IP_)
66105 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66106 index cc290f0..0ba60931 100644
66107 --- a/include/linux/slab_def.h
66108 +++ b/include/linux/slab_def.h
66109 @@ -52,7 +52,7 @@ struct kmem_cache {
66110 /* 4) cache creation/removal */
66111 const char *name;
66112 struct list_head list;
66113 - int refcount;
66114 + atomic_t refcount;
66115 int object_size;
66116 int align;
66117
66118 @@ -68,10 +68,10 @@ struct kmem_cache {
66119 unsigned long node_allocs;
66120 unsigned long node_frees;
66121 unsigned long node_overflow;
66122 - atomic_t allochit;
66123 - atomic_t allocmiss;
66124 - atomic_t freehit;
66125 - atomic_t freemiss;
66126 + atomic_unchecked_t allochit;
66127 + atomic_unchecked_t allocmiss;
66128 + atomic_unchecked_t freehit;
66129 + atomic_unchecked_t freemiss;
66130
66131 /*
66132 * If debugging is enabled, then the allocator can add additional
66133 @@ -104,11 +104,16 @@ struct cache_sizes {
66134 #ifdef CONFIG_ZONE_DMA
66135 struct kmem_cache *cs_dmacachep;
66136 #endif
66137 +
66138 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66139 + struct kmem_cache *cs_usercopycachep;
66140 +#endif
66141 +
66142 };
66143 extern struct cache_sizes malloc_sizes[];
66144
66145 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66146 -void *__kmalloc(size_t size, gfp_t flags);
66147 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66148
66149 #ifdef CONFIG_TRACING
66150 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66151 @@ -145,6 +150,13 @@ found:
66152 cachep = malloc_sizes[i].cs_dmacachep;
66153 else
66154 #endif
66155 +
66156 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66157 + if (flags & GFP_USERCOPY)
66158 + cachep = malloc_sizes[i].cs_usercopycachep;
66159 + else
66160 +#endif
66161 +
66162 cachep = malloc_sizes[i].cs_cachep;
66163
66164 ret = kmem_cache_alloc_trace(cachep, flags, size);
66165 @@ -155,7 +167,7 @@ found:
66166 }
66167
66168 #ifdef CONFIG_NUMA
66169 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66170 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66171 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66172
66173 #ifdef CONFIG_TRACING
66174 @@ -198,6 +210,13 @@ found:
66175 cachep = malloc_sizes[i].cs_dmacachep;
66176 else
66177 #endif
66178 +
66179 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66180 + if (flags & GFP_USERCOPY)
66181 + cachep = malloc_sizes[i].cs_usercopycachep;
66182 + else
66183 +#endif
66184 +
66185 cachep = malloc_sizes[i].cs_cachep;
66186
66187 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66188 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66189 index f28e14a..7831211 100644
66190 --- a/include/linux/slob_def.h
66191 +++ b/include/linux/slob_def.h
66192 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66193 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66194 }
66195
66196 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66197 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66198
66199 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66200 {
66201 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66202 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66203 }
66204
66205 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66206 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66207 {
66208 return kmalloc(size, flags);
66209 }
66210 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66211 index df448ad..b99e7f6 100644
66212 --- a/include/linux/slub_def.h
66213 +++ b/include/linux/slub_def.h
66214 @@ -91,7 +91,7 @@ struct kmem_cache {
66215 struct kmem_cache_order_objects max;
66216 struct kmem_cache_order_objects min;
66217 gfp_t allocflags; /* gfp flags to use on each alloc */
66218 - int refcount; /* Refcount for slab cache destroy */
66219 + atomic_t refcount; /* Refcount for slab cache destroy */
66220 void (*ctor)(void *);
66221 int inuse; /* Offset to metadata */
66222 int align; /* Alignment */
66223 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66224 * Sorry that the following has to be that ugly but some versions of GCC
66225 * have trouble with constant propagation and loops.
66226 */
66227 -static __always_inline int kmalloc_index(size_t size)
66228 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66229 {
66230 if (!size)
66231 return 0;
66232 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66233 }
66234
66235 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66236 -void *__kmalloc(size_t size, gfp_t flags);
66237 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66238
66239 static __always_inline void *
66240 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66241 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66242 }
66243 #endif
66244
66245 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66246 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66247 {
66248 unsigned int order = get_order(size);
66249 return kmalloc_order_trace(size, flags, order);
66250 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66251 }
66252
66253 #ifdef CONFIG_NUMA
66254 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66255 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66256 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66257
66258 #ifdef CONFIG_TRACING
66259 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66260 index 680f9a3..f13aeb0 100644
66261 --- a/include/linux/sonet.h
66262 +++ b/include/linux/sonet.h
66263 @@ -7,7 +7,7 @@
66264 #include <uapi/linux/sonet.h>
66265
66266 struct k_sonet_stats {
66267 -#define __HANDLE_ITEM(i) atomic_t i
66268 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66269 __SONET_ITEMS
66270 #undef __HANDLE_ITEM
66271 };
66272 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66273 index 34206b8..f019e06 100644
66274 --- a/include/linux/sunrpc/clnt.h
66275 +++ b/include/linux/sunrpc/clnt.h
66276 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66277 {
66278 switch (sap->sa_family) {
66279 case AF_INET:
66280 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
66281 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66282 case AF_INET6:
66283 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66284 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66285 }
66286 return 0;
66287 }
66288 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66289 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66290 const struct sockaddr *src)
66291 {
66292 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66293 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66294 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66295
66296 dsin->sin_family = ssin->sin_family;
66297 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66298 if (sa->sa_family != AF_INET6)
66299 return 0;
66300
66301 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66302 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66303 }
66304
66305 #endif /* __KERNEL__ */
66306 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66307 index 0b8e3e6..33e0a01 100644
66308 --- a/include/linux/sunrpc/svc_rdma.h
66309 +++ b/include/linux/sunrpc/svc_rdma.h
66310 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66311 extern unsigned int svcrdma_max_requests;
66312 extern unsigned int svcrdma_max_req_size;
66313
66314 -extern atomic_t rdma_stat_recv;
66315 -extern atomic_t rdma_stat_read;
66316 -extern atomic_t rdma_stat_write;
66317 -extern atomic_t rdma_stat_sq_starve;
66318 -extern atomic_t rdma_stat_rq_starve;
66319 -extern atomic_t rdma_stat_rq_poll;
66320 -extern atomic_t rdma_stat_rq_prod;
66321 -extern atomic_t rdma_stat_sq_poll;
66322 -extern atomic_t rdma_stat_sq_prod;
66323 +extern atomic_unchecked_t rdma_stat_recv;
66324 +extern atomic_unchecked_t rdma_stat_read;
66325 +extern atomic_unchecked_t rdma_stat_write;
66326 +extern atomic_unchecked_t rdma_stat_sq_starve;
66327 +extern atomic_unchecked_t rdma_stat_rq_starve;
66328 +extern atomic_unchecked_t rdma_stat_rq_poll;
66329 +extern atomic_unchecked_t rdma_stat_rq_prod;
66330 +extern atomic_unchecked_t rdma_stat_sq_poll;
66331 +extern atomic_unchecked_t rdma_stat_sq_prod;
66332
66333 #define RPCRDMA_VERSION 1
66334
66335 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66336 index cd844a6..3ca3592 100644
66337 --- a/include/linux/sysctl.h
66338 +++ b/include/linux/sysctl.h
66339 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66340
66341 extern int proc_dostring(struct ctl_table *, int,
66342 void __user *, size_t *, loff_t *);
66343 +extern int proc_dostring_modpriv(struct ctl_table *, int,
66344 + void __user *, size_t *, loff_t *);
66345 extern int proc_dointvec(struct ctl_table *, int,
66346 void __user *, size_t *, loff_t *);
66347 extern int proc_dointvec_minmax(struct ctl_table *, int,
66348 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66349 index 7faf933..eb6f5e3 100644
66350 --- a/include/linux/sysrq.h
66351 +++ b/include/linux/sysrq.h
66352 @@ -36,7 +36,7 @@ struct sysrq_key_op {
66353 char *help_msg;
66354 char *action_msg;
66355 int enable_mask;
66356 -};
66357 +} __do_const;
66358
66359 #ifdef CONFIG_MAGIC_SYSRQ
66360
66361 diff --git a/include/linux/tty.h b/include/linux/tty.h
66362 index f0b4eb4..1c4854e 100644
66363 --- a/include/linux/tty.h
66364 +++ b/include/linux/tty.h
66365 @@ -192,7 +192,7 @@ struct tty_port {
66366 const struct tty_port_operations *ops; /* Port operations */
66367 spinlock_t lock; /* Lock protecting tty field */
66368 int blocked_open; /* Waiting to open */
66369 - int count; /* Usage count */
66370 + atomic_t count; /* Usage count */
66371 wait_queue_head_t open_wait; /* Open waiters */
66372 wait_queue_head_t close_wait; /* Close waiters */
66373 wait_queue_head_t delta_msr_wait; /* Modem status change */
66374 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66375 struct tty_struct *tty, struct file *filp);
66376 static inline int tty_port_users(struct tty_port *port)
66377 {
66378 - return port->count + port->blocked_open;
66379 + return atomic_read(&port->count) + port->blocked_open;
66380 }
66381
66382 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66383 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66384 index dd976cf..e272742 100644
66385 --- a/include/linux/tty_driver.h
66386 +++ b/include/linux/tty_driver.h
66387 @@ -284,7 +284,7 @@ struct tty_operations {
66388 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66389 #endif
66390 const struct file_operations *proc_fops;
66391 -};
66392 +} __do_const;
66393
66394 struct tty_driver {
66395 int magic; /* magic number for this structure */
66396 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66397 index fb79dd8d..07d4773 100644
66398 --- a/include/linux/tty_ldisc.h
66399 +++ b/include/linux/tty_ldisc.h
66400 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66401
66402 struct module *owner;
66403
66404 - int refcount;
66405 + atomic_t refcount;
66406 };
66407
66408 struct tty_ldisc {
66409 diff --git a/include/linux/types.h b/include/linux/types.h
66410 index 1cc0e4b..0d50edf 100644
66411 --- a/include/linux/types.h
66412 +++ b/include/linux/types.h
66413 @@ -175,10 +175,26 @@ typedef struct {
66414 int counter;
66415 } atomic_t;
66416
66417 +#ifdef CONFIG_PAX_REFCOUNT
66418 +typedef struct {
66419 + int counter;
66420 +} atomic_unchecked_t;
66421 +#else
66422 +typedef atomic_t atomic_unchecked_t;
66423 +#endif
66424 +
66425 #ifdef CONFIG_64BIT
66426 typedef struct {
66427 long counter;
66428 } atomic64_t;
66429 +
66430 +#ifdef CONFIG_PAX_REFCOUNT
66431 +typedef struct {
66432 + long counter;
66433 +} atomic64_unchecked_t;
66434 +#else
66435 +typedef atomic64_t atomic64_unchecked_t;
66436 +#endif
66437 #endif
66438
66439 struct list_head {
66440 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66441 index 5ca0951..ab496a5 100644
66442 --- a/include/linux/uaccess.h
66443 +++ b/include/linux/uaccess.h
66444 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66445 long ret; \
66446 mm_segment_t old_fs = get_fs(); \
66447 \
66448 - set_fs(KERNEL_DS); \
66449 pagefault_disable(); \
66450 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66451 - pagefault_enable(); \
66452 + set_fs(KERNEL_DS); \
66453 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66454 set_fs(old_fs); \
66455 + pagefault_enable(); \
66456 ret; \
66457 })
66458
66459 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66460 index 99c1b4d..bb94261 100644
66461 --- a/include/linux/unaligned/access_ok.h
66462 +++ b/include/linux/unaligned/access_ok.h
66463 @@ -6,32 +6,32 @@
66464
66465 static inline u16 get_unaligned_le16(const void *p)
66466 {
66467 - return le16_to_cpup((__le16 *)p);
66468 + return le16_to_cpup((const __le16 *)p);
66469 }
66470
66471 static inline u32 get_unaligned_le32(const void *p)
66472 {
66473 - return le32_to_cpup((__le32 *)p);
66474 + return le32_to_cpup((const __le32 *)p);
66475 }
66476
66477 static inline u64 get_unaligned_le64(const void *p)
66478 {
66479 - return le64_to_cpup((__le64 *)p);
66480 + return le64_to_cpup((const __le64 *)p);
66481 }
66482
66483 static inline u16 get_unaligned_be16(const void *p)
66484 {
66485 - return be16_to_cpup((__be16 *)p);
66486 + return be16_to_cpup((const __be16 *)p);
66487 }
66488
66489 static inline u32 get_unaligned_be32(const void *p)
66490 {
66491 - return be32_to_cpup((__be32 *)p);
66492 + return be32_to_cpup((const __be32 *)p);
66493 }
66494
66495 static inline u64 get_unaligned_be64(const void *p)
66496 {
66497 - return be64_to_cpup((__be64 *)p);
66498 + return be64_to_cpup((const __be64 *)p);
66499 }
66500
66501 static inline void put_unaligned_le16(u16 val, void *p)
66502 diff --git a/include/linux/usb.h b/include/linux/usb.h
66503 index 10278d1..e21ec3c 100644
66504 --- a/include/linux/usb.h
66505 +++ b/include/linux/usb.h
66506 @@ -551,7 +551,7 @@ struct usb_device {
66507 int maxchild;
66508
66509 u32 quirks;
66510 - atomic_t urbnum;
66511 + atomic_unchecked_t urbnum;
66512
66513 unsigned long active_duration;
66514
66515 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66516 index c5d36c6..108f4f9 100644
66517 --- a/include/linux/usb/renesas_usbhs.h
66518 +++ b/include/linux/usb/renesas_usbhs.h
66519 @@ -39,7 +39,7 @@ enum {
66520 */
66521 struct renesas_usbhs_driver_callback {
66522 int (*notify_hotplug)(struct platform_device *pdev);
66523 -};
66524 +} __no_const;
66525
66526 /*
66527 * callback functions for platform
66528 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66529 index 6f8fbcf..8259001 100644
66530 --- a/include/linux/vermagic.h
66531 +++ b/include/linux/vermagic.h
66532 @@ -25,9 +25,35 @@
66533 #define MODULE_ARCH_VERMAGIC ""
66534 #endif
66535
66536 +#ifdef CONFIG_PAX_REFCOUNT
66537 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66538 +#else
66539 +#define MODULE_PAX_REFCOUNT ""
66540 +#endif
66541 +
66542 +#ifdef CONSTIFY_PLUGIN
66543 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66544 +#else
66545 +#define MODULE_CONSTIFY_PLUGIN ""
66546 +#endif
66547 +
66548 +#ifdef STACKLEAK_PLUGIN
66549 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66550 +#else
66551 +#define MODULE_STACKLEAK_PLUGIN ""
66552 +#endif
66553 +
66554 +#ifdef CONFIG_GRKERNSEC
66555 +#define MODULE_GRSEC "GRSEC "
66556 +#else
66557 +#define MODULE_GRSEC ""
66558 +#endif
66559 +
66560 #define VERMAGIC_STRING \
66561 UTS_RELEASE " " \
66562 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66563 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66564 - MODULE_ARCH_VERMAGIC
66565 + MODULE_ARCH_VERMAGIC \
66566 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66567 + MODULE_GRSEC
66568
66569 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66570 index 6071e91..ca6a489 100644
66571 --- a/include/linux/vmalloc.h
66572 +++ b/include/linux/vmalloc.h
66573 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66574 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66575 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66576 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66577 +
66578 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66579 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66580 +#endif
66581 +
66582 /* bits [20..32] reserved for arch specific ioremap internals */
66583
66584 /*
66585 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66586 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66587 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66588 unsigned long start, unsigned long end, gfp_t gfp_mask,
66589 - pgprot_t prot, int node, const void *caller);
66590 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66591 extern void vfree(const void *addr);
66592
66593 extern void *vmap(struct page **pages, unsigned int count,
66594 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66595 extern void free_vm_area(struct vm_struct *area);
66596
66597 /* for /dev/kmem */
66598 -extern long vread(char *buf, char *addr, unsigned long count);
66599 -extern long vwrite(char *buf, char *addr, unsigned long count);
66600 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66601 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66602
66603 /*
66604 * Internals. Dont't use..
66605 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66606 index 92a86b2..1d9eb3c 100644
66607 --- a/include/linux/vmstat.h
66608 +++ b/include/linux/vmstat.h
66609 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66610 /*
66611 * Zone based page accounting with per cpu differentials.
66612 */
66613 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66614 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66615
66616 static inline void zone_page_state_add(long x, struct zone *zone,
66617 enum zone_stat_item item)
66618 {
66619 - atomic_long_add(x, &zone->vm_stat[item]);
66620 - atomic_long_add(x, &vm_stat[item]);
66621 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66622 + atomic_long_add_unchecked(x, &vm_stat[item]);
66623 }
66624
66625 static inline unsigned long global_page_state(enum zone_stat_item item)
66626 {
66627 - long x = atomic_long_read(&vm_stat[item]);
66628 + long x = atomic_long_read_unchecked(&vm_stat[item]);
66629 #ifdef CONFIG_SMP
66630 if (x < 0)
66631 x = 0;
66632 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66633 static inline unsigned long zone_page_state(struct zone *zone,
66634 enum zone_stat_item item)
66635 {
66636 - long x = atomic_long_read(&zone->vm_stat[item]);
66637 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66638 #ifdef CONFIG_SMP
66639 if (x < 0)
66640 x = 0;
66641 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66642 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66643 enum zone_stat_item item)
66644 {
66645 - long x = atomic_long_read(&zone->vm_stat[item]);
66646 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66647
66648 #ifdef CONFIG_SMP
66649 int cpu;
66650 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66651
66652 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66653 {
66654 - atomic_long_inc(&zone->vm_stat[item]);
66655 - atomic_long_inc(&vm_stat[item]);
66656 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
66657 + atomic_long_inc_unchecked(&vm_stat[item]);
66658 }
66659
66660 static inline void __inc_zone_page_state(struct page *page,
66661 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66662
66663 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66664 {
66665 - atomic_long_dec(&zone->vm_stat[item]);
66666 - atomic_long_dec(&vm_stat[item]);
66667 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
66668 + atomic_long_dec_unchecked(&vm_stat[item]);
66669 }
66670
66671 static inline void __dec_zone_page_state(struct page *page,
66672 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66673 index 95d1c91..6798cca 100644
66674 --- a/include/media/v4l2-dev.h
66675 +++ b/include/media/v4l2-dev.h
66676 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
66677 int (*mmap) (struct file *, struct vm_area_struct *);
66678 int (*open) (struct file *);
66679 int (*release) (struct file *);
66680 -};
66681 +} __do_const;
66682
66683 /*
66684 * Newer version of video_device, handled by videodev2.c
66685 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66686 index e48b571..7e40de4 100644
66687 --- a/include/media/v4l2-ioctl.h
66688 +++ b/include/media/v4l2-ioctl.h
66689 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66690 bool valid_prio, int cmd, void *arg);
66691 };
66692
66693 -
66694 /* v4l debugging and diagnostics */
66695
66696 /* Debug bitmask flags to be used on V4L2 */
66697 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66698 index 9e5425b..8136ffc 100644
66699 --- a/include/net/caif/cfctrl.h
66700 +++ b/include/net/caif/cfctrl.h
66701 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
66702 void (*radioset_rsp)(void);
66703 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66704 struct cflayer *client_layer);
66705 -};
66706 +} __no_const;
66707
66708 /* Link Setup Parameters for CAIF-Links. */
66709 struct cfctrl_link_param {
66710 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
66711 struct cfctrl {
66712 struct cfsrvl serv;
66713 struct cfctrl_rsp res;
66714 - atomic_t req_seq_no;
66715 - atomic_t rsp_seq_no;
66716 + atomic_unchecked_t req_seq_no;
66717 + atomic_unchecked_t rsp_seq_no;
66718 struct list_head list;
66719 /* Protects from simultaneous access to first_req list */
66720 spinlock_t info_list_lock;
66721 diff --git a/include/net/flow.h b/include/net/flow.h
66722 index 628e11b..4c475df 100644
66723 --- a/include/net/flow.h
66724 +++ b/include/net/flow.h
66725 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66726
66727 extern void flow_cache_flush(void);
66728 extern void flow_cache_flush_deferred(void);
66729 -extern atomic_t flow_cache_genid;
66730 +extern atomic_unchecked_t flow_cache_genid;
66731
66732 #endif
66733 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66734 index e5062c9..e709988 100644
66735 --- a/include/net/gro_cells.h
66736 +++ b/include/net/gro_cells.h
66737 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66738 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66739
66740 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66741 - atomic_long_inc(&dev->rx_dropped);
66742 + atomic_long_inc_unchecked(&dev->rx_dropped);
66743 kfree_skb(skb);
66744 return;
66745 }
66746 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66747 index 1832927..ce39aea 100644
66748 --- a/include/net/inet_connection_sock.h
66749 +++ b/include/net/inet_connection_sock.h
66750 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66751 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66752 int (*bind_conflict)(const struct sock *sk,
66753 const struct inet_bind_bucket *tb, bool relax);
66754 -};
66755 +} __do_const;
66756
66757 /** inet_connection_sock - INET connection oriented sock
66758 *
66759 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66760 index 53f464d..ba76aaa 100644
66761 --- a/include/net/inetpeer.h
66762 +++ b/include/net/inetpeer.h
66763 @@ -47,8 +47,8 @@ struct inet_peer {
66764 */
66765 union {
66766 struct {
66767 - atomic_t rid; /* Frag reception counter */
66768 - atomic_t ip_id_count; /* IP ID for the next packet */
66769 + atomic_unchecked_t rid; /* Frag reception counter */
66770 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
66771 };
66772 struct rcu_head rcu;
66773 struct inet_peer *gc_next;
66774 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
66775 more++;
66776 inet_peer_refcheck(p);
66777 do {
66778 - old = atomic_read(&p->ip_id_count);
66779 + old = atomic_read_unchecked(&p->ip_id_count);
66780 new = old + more;
66781 if (!new)
66782 new = 1;
66783 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
66784 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
66785 return new;
66786 }
66787
66788 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
66789 index 9497be1..5a4fafe 100644
66790 --- a/include/net/ip_fib.h
66791 +++ b/include/net/ip_fib.h
66792 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
66793
66794 #define FIB_RES_SADDR(net, res) \
66795 ((FIB_RES_NH(res).nh_saddr_genid == \
66796 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
66797 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
66798 FIB_RES_NH(res).nh_saddr : \
66799 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
66800 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
66801 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
66802 index ee75ccd..2cc2b95 100644
66803 --- a/include/net/ip_vs.h
66804 +++ b/include/net/ip_vs.h
66805 @@ -510,7 +510,7 @@ struct ip_vs_conn {
66806 struct ip_vs_conn *control; /* Master control connection */
66807 atomic_t n_control; /* Number of controlled ones */
66808 struct ip_vs_dest *dest; /* real server */
66809 - atomic_t in_pkts; /* incoming packet counter */
66810 + atomic_unchecked_t in_pkts; /* incoming packet counter */
66811
66812 /* packet transmitter for different forwarding methods. If it
66813 mangles the packet, it must return NF_DROP or better NF_STOLEN,
66814 @@ -648,7 +648,7 @@ struct ip_vs_dest {
66815 __be16 port; /* port number of the server */
66816 union nf_inet_addr addr; /* IP address of the server */
66817 volatile unsigned int flags; /* dest status flags */
66818 - atomic_t conn_flags; /* flags to copy to conn */
66819 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
66820 atomic_t weight; /* server weight */
66821
66822 atomic_t refcnt; /* reference counter */
66823 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
66824 index 80ffde3..968b0f4 100644
66825 --- a/include/net/irda/ircomm_tty.h
66826 +++ b/include/net/irda/ircomm_tty.h
66827 @@ -35,6 +35,7 @@
66828 #include <linux/termios.h>
66829 #include <linux/timer.h>
66830 #include <linux/tty.h> /* struct tty_struct */
66831 +#include <asm/local.h>
66832
66833 #include <net/irda/irias_object.h>
66834 #include <net/irda/ircomm_core.h>
66835 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
66836 index cc7c197..9f2da2a 100644
66837 --- a/include/net/iucv/af_iucv.h
66838 +++ b/include/net/iucv/af_iucv.h
66839 @@ -141,7 +141,7 @@ struct iucv_sock {
66840 struct iucv_sock_list {
66841 struct hlist_head head;
66842 rwlock_t lock;
66843 - atomic_t autobind_name;
66844 + atomic_unchecked_t autobind_name;
66845 };
66846
66847 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
66848 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
66849 index 0dab173..1b76af0 100644
66850 --- a/include/net/neighbour.h
66851 +++ b/include/net/neighbour.h
66852 @@ -123,7 +123,7 @@ struct neigh_ops {
66853 void (*error_report)(struct neighbour *, struct sk_buff *);
66854 int (*output)(struct neighbour *, struct sk_buff *);
66855 int (*connected_output)(struct neighbour *, struct sk_buff *);
66856 -};
66857 +} __do_const;
66858
66859 struct pneigh_entry {
66860 struct pneigh_entry *next;
66861 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
66862 index 95e6466..251016d 100644
66863 --- a/include/net/net_namespace.h
66864 +++ b/include/net/net_namespace.h
66865 @@ -110,7 +110,7 @@ struct net {
66866 #endif
66867 struct netns_ipvs *ipvs;
66868 struct sock *diag_nlsk;
66869 - atomic_t rt_genid;
66870 + atomic_unchecked_t rt_genid;
66871 };
66872
66873 /*
66874 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
66875
66876 static inline int rt_genid(struct net *net)
66877 {
66878 - return atomic_read(&net->rt_genid);
66879 + return atomic_read_unchecked(&net->rt_genid);
66880 }
66881
66882 static inline void rt_genid_bump(struct net *net)
66883 {
66884 - atomic_inc(&net->rt_genid);
66885 + atomic_inc_unchecked(&net->rt_genid);
66886 }
66887
66888 #endif /* __NET_NET_NAMESPACE_H */
66889 diff --git a/include/net/netdma.h b/include/net/netdma.h
66890 index 8ba8ce2..99b7fff 100644
66891 --- a/include/net/netdma.h
66892 +++ b/include/net/netdma.h
66893 @@ -24,7 +24,7 @@
66894 #include <linux/dmaengine.h>
66895 #include <linux/skbuff.h>
66896
66897 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66898 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66899 struct sk_buff *skb, int offset, struct iovec *to,
66900 size_t len, struct dma_pinned_list *pinned_list);
66901
66902 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
66903 index 252fd10..aa1421f 100644
66904 --- a/include/net/netfilter/nf_queue.h
66905 +++ b/include/net/netfilter/nf_queue.h
66906 @@ -22,7 +22,7 @@ struct nf_queue_handler {
66907 int (*outfn)(struct nf_queue_entry *entry,
66908 unsigned int queuenum);
66909 char *name;
66910 -};
66911 +} __do_const;
66912
66913 extern int nf_register_queue_handler(u_int8_t pf,
66914 const struct nf_queue_handler *qh);
66915 diff --git a/include/net/netlink.h b/include/net/netlink.h
66916 index 9690b0f..87aded7 100644
66917 --- a/include/net/netlink.h
66918 +++ b/include/net/netlink.h
66919 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
66920 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
66921 {
66922 if (mark)
66923 - skb_trim(skb, (unsigned char *) mark - skb->data);
66924 + skb_trim(skb, (const unsigned char *) mark - skb->data);
66925 }
66926
66927 /**
66928 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
66929 index 2ae2b83..dbdc85e 100644
66930 --- a/include/net/netns/ipv4.h
66931 +++ b/include/net/netns/ipv4.h
66932 @@ -64,7 +64,7 @@ struct netns_ipv4 {
66933 kgid_t sysctl_ping_group_range[2];
66934 long sysctl_tcp_mem[3];
66935
66936 - atomic_t dev_addr_genid;
66937 + atomic_unchecked_t dev_addr_genid;
66938
66939 #ifdef CONFIG_IP_MROUTE
66940 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
66941 diff --git a/include/net/protocol.h b/include/net/protocol.h
66942 index 929528c..c84d4f6 100644
66943 --- a/include/net/protocol.h
66944 +++ b/include/net/protocol.h
66945 @@ -48,7 +48,7 @@ struct net_protocol {
66946 int (*gro_complete)(struct sk_buff *skb);
66947 unsigned int no_policy:1,
66948 netns_ok:1;
66949 -};
66950 +} __do_const;
66951
66952 #if IS_ENABLED(CONFIG_IPV6)
66953 struct inet6_protocol {
66954 @@ -69,7 +69,7 @@ struct inet6_protocol {
66955 int (*gro_complete)(struct sk_buff *skb);
66956
66957 unsigned int flags; /* INET6_PROTO_xxx */
66958 -};
66959 +} __do_const;
66960
66961 #define INET6_PROTO_NOPOLICY 0x1
66962 #define INET6_PROTO_FINAL 0x2
66963 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
66964 index 9c6414f..fbd0524 100644
66965 --- a/include/net/sctp/sctp.h
66966 +++ b/include/net/sctp/sctp.h
66967 @@ -318,9 +318,9 @@ do { \
66968
66969 #else /* SCTP_DEBUG */
66970
66971 -#define SCTP_DEBUG_PRINTK(whatever...)
66972 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
66973 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
66974 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
66975 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
66976 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
66977 #define SCTP_ENABLE_DEBUG
66978 #define SCTP_DISABLE_DEBUG
66979 #define SCTP_ASSERT(expr, str, func)
66980 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
66981 index 64158aa..b65533c 100644
66982 --- a/include/net/sctp/structs.h
66983 +++ b/include/net/sctp/structs.h
66984 @@ -496,7 +496,7 @@ struct sctp_af {
66985 int sockaddr_len;
66986 sa_family_t sa_family;
66987 struct list_head list;
66988 -};
66989 +} __do_const;
66990
66991 struct sctp_af *sctp_get_af_specific(sa_family_t);
66992 int sctp_register_af(struct sctp_af *);
66993 @@ -516,7 +516,7 @@ struct sctp_pf {
66994 struct sctp_association *asoc);
66995 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
66996 struct sctp_af *af;
66997 -};
66998 +} __do_const;
66999
67000
67001 /* Structure to track chunk fragments that have been acked, but peer
67002 diff --git a/include/net/sock.h b/include/net/sock.h
67003 index c945fba..e162e56 100644
67004 --- a/include/net/sock.h
67005 +++ b/include/net/sock.h
67006 @@ -304,7 +304,7 @@ struct sock {
67007 #ifdef CONFIG_RPS
67008 __u32 sk_rxhash;
67009 #endif
67010 - atomic_t sk_drops;
67011 + atomic_unchecked_t sk_drops;
67012 int sk_rcvbuf;
67013
67014 struct sk_filter __rcu *sk_filter;
67015 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67016 }
67017
67018 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67019 - char __user *from, char *to,
67020 + char __user *from, unsigned char *to,
67021 int copy, int offset)
67022 {
67023 if (skb->ip_summed == CHECKSUM_NONE) {
67024 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67025 }
67026 }
67027
67028 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67029 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67030
67031 /**
67032 * sk_page_frag - return an appropriate page_frag
67033 diff --git a/include/net/tcp.h b/include/net/tcp.h
67034 index 4af45e3..af97861 100644
67035 --- a/include/net/tcp.h
67036 +++ b/include/net/tcp.h
67037 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67038 extern void tcp_xmit_retransmit_queue(struct sock *);
67039 extern void tcp_simple_retransmit(struct sock *);
67040 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67041 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67042 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67043
67044 extern void tcp_send_probe0(struct sock *);
67045 extern void tcp_send_partial(struct sock *);
67046 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
67047 struct inet6_skb_parm h6;
67048 #endif
67049 } header; /* For incoming frames */
67050 - __u32 seq; /* Starting sequence number */
67051 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67052 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
67053 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67054 __u32 when; /* used to compute rtt's */
67055 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67056
67057 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
67058
67059 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67060 /* 1 byte hole */
67061 - __u32 ack_seq; /* Sequence number ACK'd */
67062 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67063 };
67064
67065 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67066 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67067 index 63445ed..74ef61d 100644
67068 --- a/include/net/xfrm.h
67069 +++ b/include/net/xfrm.h
67070 @@ -423,7 +423,7 @@ struct xfrm_mode {
67071 struct module *owner;
67072 unsigned int encap;
67073 int flags;
67074 -};
67075 +} __do_const;
67076
67077 /* Flags for xfrm_mode. */
67078 enum {
67079 @@ -514,7 +514,7 @@ struct xfrm_policy {
67080 struct timer_list timer;
67081
67082 struct flow_cache_object flo;
67083 - atomic_t genid;
67084 + atomic_unchecked_t genid;
67085 u32 priority;
67086 u32 index;
67087 struct xfrm_mark mark;
67088 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67089 index 1a046b1..ee0bef0 100644
67090 --- a/include/rdma/iw_cm.h
67091 +++ b/include/rdma/iw_cm.h
67092 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
67093 int backlog);
67094
67095 int (*destroy_listen)(struct iw_cm_id *cm_id);
67096 -};
67097 +} __no_const;
67098
67099 /**
67100 * iw_create_cm_id - Create an IW CM identifier.
67101 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67102 index 399162b..b337f1a 100644
67103 --- a/include/scsi/libfc.h
67104 +++ b/include/scsi/libfc.h
67105 @@ -762,6 +762,7 @@ struct libfc_function_template {
67106 */
67107 void (*disc_stop_final) (struct fc_lport *);
67108 };
67109 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67110
67111 /**
67112 * struct fc_disc - Discovery context
67113 @@ -866,7 +867,7 @@ struct fc_lport {
67114 struct fc_vport *vport;
67115
67116 /* Operational Information */
67117 - struct libfc_function_template tt;
67118 + libfc_function_template_no_const tt;
67119 u8 link_up;
67120 u8 qfull;
67121 enum fc_lport_state state;
67122 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67123 index 55367b0..d97bd2a 100644
67124 --- a/include/scsi/scsi_device.h
67125 +++ b/include/scsi/scsi_device.h
67126 @@ -169,9 +169,9 @@ struct scsi_device {
67127 unsigned int max_device_blocked; /* what device_blocked counts down from */
67128 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67129
67130 - atomic_t iorequest_cnt;
67131 - atomic_t iodone_cnt;
67132 - atomic_t ioerr_cnt;
67133 + atomic_unchecked_t iorequest_cnt;
67134 + atomic_unchecked_t iodone_cnt;
67135 + atomic_unchecked_t ioerr_cnt;
67136
67137 struct device sdev_gendev,
67138 sdev_dev;
67139 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67140 index b797e8f..8e2c3aa 100644
67141 --- a/include/scsi/scsi_transport_fc.h
67142 +++ b/include/scsi/scsi_transport_fc.h
67143 @@ -751,7 +751,8 @@ struct fc_function_template {
67144 unsigned long show_host_system_hostname:1;
67145
67146 unsigned long disable_target_scan:1;
67147 -};
67148 +} __do_const;
67149 +typedef struct fc_function_template __no_const fc_function_template_no_const;
67150
67151
67152 /**
67153 diff --git a/include/sound/soc.h b/include/sound/soc.h
67154 index 91244a0..89ca1a7 100644
67155 --- a/include/sound/soc.h
67156 +++ b/include/sound/soc.h
67157 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67158 /* probe ordering - for components with runtime dependencies */
67159 int probe_order;
67160 int remove_order;
67161 -};
67162 +} __do_const;
67163
67164 /* SoC platform interface */
67165 struct snd_soc_platform_driver {
67166 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67167 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67168 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67169 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67170 -};
67171 +} __do_const;
67172
67173 struct snd_soc_platform {
67174 const char *name;
67175 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67176 index fca8bbe..c0242ea 100644
67177 --- a/include/target/target_core_base.h
67178 +++ b/include/target/target_core_base.h
67179 @@ -760,7 +760,7 @@ struct se_device {
67180 spinlock_t stats_lock;
67181 /* Active commands on this virtual SE device */
67182 atomic_t simple_cmds;
67183 - atomic_t dev_ordered_id;
67184 + atomic_unchecked_t dev_ordered_id;
67185 atomic_t dev_ordered_sync;
67186 atomic_t dev_qf_count;
67187 struct se_obj dev_obj;
67188 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67189 new file mode 100644
67190 index 0000000..fb634b7
67191 --- /dev/null
67192 +++ b/include/trace/events/fs.h
67193 @@ -0,0 +1,53 @@
67194 +#undef TRACE_SYSTEM
67195 +#define TRACE_SYSTEM fs
67196 +
67197 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67198 +#define _TRACE_FS_H
67199 +
67200 +#include <linux/fs.h>
67201 +#include <linux/tracepoint.h>
67202 +
67203 +TRACE_EVENT(do_sys_open,
67204 +
67205 + TP_PROTO(const char *filename, int flags, int mode),
67206 +
67207 + TP_ARGS(filename, flags, mode),
67208 +
67209 + TP_STRUCT__entry(
67210 + __string( filename, filename )
67211 + __field( int, flags )
67212 + __field( int, mode )
67213 + ),
67214 +
67215 + TP_fast_assign(
67216 + __assign_str(filename, filename);
67217 + __entry->flags = flags;
67218 + __entry->mode = mode;
67219 + ),
67220 +
67221 + TP_printk("\"%s\" %x %o",
67222 + __get_str(filename), __entry->flags, __entry->mode)
67223 +);
67224 +
67225 +TRACE_EVENT(open_exec,
67226 +
67227 + TP_PROTO(const char *filename),
67228 +
67229 + TP_ARGS(filename),
67230 +
67231 + TP_STRUCT__entry(
67232 + __string( filename, filename )
67233 + ),
67234 +
67235 + TP_fast_assign(
67236 + __assign_str(filename, filename);
67237 + ),
67238 +
67239 + TP_printk("\"%s\"",
67240 + __get_str(filename))
67241 +);
67242 +
67243 +#endif /* _TRACE_FS_H */
67244 +
67245 +/* This part must be outside protection */
67246 +#include <trace/define_trace.h>
67247 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67248 index 1c09820..7f5ec79 100644
67249 --- a/include/trace/events/irq.h
67250 +++ b/include/trace/events/irq.h
67251 @@ -36,7 +36,7 @@ struct softirq_action;
67252 */
67253 TRACE_EVENT(irq_handler_entry,
67254
67255 - TP_PROTO(int irq, struct irqaction *action),
67256 + TP_PROTO(int irq, const struct irqaction *action),
67257
67258 TP_ARGS(irq, action),
67259
67260 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67261 */
67262 TRACE_EVENT(irq_handler_exit,
67263
67264 - TP_PROTO(int irq, struct irqaction *action, int ret),
67265 + TP_PROTO(int irq, const struct irqaction *action, int ret),
67266
67267 TP_ARGS(irq, action, ret),
67268
67269 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67270 index 7caf44c..23c6f27 100644
67271 --- a/include/uapi/linux/a.out.h
67272 +++ b/include/uapi/linux/a.out.h
67273 @@ -39,6 +39,14 @@ enum machine_type {
67274 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67275 };
67276
67277 +/* Constants for the N_FLAGS field */
67278 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67279 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67280 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67281 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67282 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67283 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67284 +
67285 #if !defined (N_MAGIC)
67286 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67287 #endif
67288 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67289 index d876736..b36014e 100644
67290 --- a/include/uapi/linux/byteorder/little_endian.h
67291 +++ b/include/uapi/linux/byteorder/little_endian.h
67292 @@ -42,51 +42,51 @@
67293
67294 static inline __le64 __cpu_to_le64p(const __u64 *p)
67295 {
67296 - return (__force __le64)*p;
67297 + return (__force const __le64)*p;
67298 }
67299 static inline __u64 __le64_to_cpup(const __le64 *p)
67300 {
67301 - return (__force __u64)*p;
67302 + return (__force const __u64)*p;
67303 }
67304 static inline __le32 __cpu_to_le32p(const __u32 *p)
67305 {
67306 - return (__force __le32)*p;
67307 + return (__force const __le32)*p;
67308 }
67309 static inline __u32 __le32_to_cpup(const __le32 *p)
67310 {
67311 - return (__force __u32)*p;
67312 + return (__force const __u32)*p;
67313 }
67314 static inline __le16 __cpu_to_le16p(const __u16 *p)
67315 {
67316 - return (__force __le16)*p;
67317 + return (__force const __le16)*p;
67318 }
67319 static inline __u16 __le16_to_cpup(const __le16 *p)
67320 {
67321 - return (__force __u16)*p;
67322 + return (__force const __u16)*p;
67323 }
67324 static inline __be64 __cpu_to_be64p(const __u64 *p)
67325 {
67326 - return (__force __be64)__swab64p(p);
67327 + return (__force const __be64)__swab64p(p);
67328 }
67329 static inline __u64 __be64_to_cpup(const __be64 *p)
67330 {
67331 - return __swab64p((__u64 *)p);
67332 + return __swab64p((const __u64 *)p);
67333 }
67334 static inline __be32 __cpu_to_be32p(const __u32 *p)
67335 {
67336 - return (__force __be32)__swab32p(p);
67337 + return (__force const __be32)__swab32p(p);
67338 }
67339 static inline __u32 __be32_to_cpup(const __be32 *p)
67340 {
67341 - return __swab32p((__u32 *)p);
67342 + return __swab32p((const __u32 *)p);
67343 }
67344 static inline __be16 __cpu_to_be16p(const __u16 *p)
67345 {
67346 - return (__force __be16)__swab16p(p);
67347 + return (__force const __be16)__swab16p(p);
67348 }
67349 static inline __u16 __be16_to_cpup(const __be16 *p)
67350 {
67351 - return __swab16p((__u16 *)p);
67352 + return __swab16p((const __u16 *)p);
67353 }
67354 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67355 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67356 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67357 index 126a817..d522bd1 100644
67358 --- a/include/uapi/linux/elf.h
67359 +++ b/include/uapi/linux/elf.h
67360 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67361 #define PT_GNU_EH_FRAME 0x6474e550
67362
67363 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67364 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67365 +
67366 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67367 +
67368 +/* Constants for the e_flags field */
67369 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67370 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67371 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67372 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67373 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67374 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67375
67376 /*
67377 * Extended Numbering
67378 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67379 #define DT_DEBUG 21
67380 #define DT_TEXTREL 22
67381 #define DT_JMPREL 23
67382 +#define DT_FLAGS 30
67383 + #define DF_TEXTREL 0x00000004
67384 #define DT_ENCODING 32
67385 #define OLD_DT_LOOS 0x60000000
67386 #define DT_LOOS 0x6000000d
67387 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67388 #define PF_W 0x2
67389 #define PF_X 0x1
67390
67391 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67392 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67393 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67394 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67395 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67396 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67397 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67398 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67399 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67400 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67401 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67402 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67403 +
67404 typedef struct elf32_phdr{
67405 Elf32_Word p_type;
67406 Elf32_Off p_offset;
67407 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67408 #define EI_OSABI 7
67409 #define EI_PAD 8
67410
67411 +#define EI_PAX 14
67412 +
67413 #define ELFMAG0 0x7f /* EI_MAG */
67414 #define ELFMAG1 'E'
67415 #define ELFMAG2 'L'
67416 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67417 index aa169c4..6a2771d 100644
67418 --- a/include/uapi/linux/personality.h
67419 +++ b/include/uapi/linux/personality.h
67420 @@ -30,6 +30,7 @@ enum {
67421 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67422 ADDR_NO_RANDOMIZE | \
67423 ADDR_COMPAT_LAYOUT | \
67424 + ADDR_LIMIT_3GB | \
67425 MMAP_PAGE_ZERO)
67426
67427 /*
67428 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67429 index 7530e74..e714828 100644
67430 --- a/include/uapi/linux/screen_info.h
67431 +++ b/include/uapi/linux/screen_info.h
67432 @@ -43,7 +43,8 @@ struct screen_info {
67433 __u16 pages; /* 0x32 */
67434 __u16 vesa_attributes; /* 0x34 */
67435 __u32 capabilities; /* 0x36 */
67436 - __u8 _reserved[6]; /* 0x3a */
67437 + __u16 vesapm_size; /* 0x3a */
67438 + __u8 _reserved[4]; /* 0x3c */
67439 } __attribute__((packed));
67440
67441 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67442 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67443 index 6d67213..8dab561 100644
67444 --- a/include/uapi/linux/sysctl.h
67445 +++ b/include/uapi/linux/sysctl.h
67446 @@ -155,7 +155,11 @@ enum
67447 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67448 };
67449
67450 -
67451 +#ifdef CONFIG_PAX_SOFTMODE
67452 +enum {
67453 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67454 +};
67455 +#endif
67456
67457 /* CTL_VM names: */
67458 enum
67459 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67460 index 26607bd..588b65f 100644
67461 --- a/include/uapi/linux/xattr.h
67462 +++ b/include/uapi/linux/xattr.h
67463 @@ -60,5 +60,9 @@
67464 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67465 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67466
67467 +/* User namespace */
67468 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67469 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67470 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67471
67472 #endif /* _UAPI_LINUX_XATTR_H */
67473 diff --git a/include/video/omapdss.h b/include/video/omapdss.h
67474 index 3729173..7b2df7e 100644
67475 --- a/include/video/omapdss.h
67476 +++ b/include/video/omapdss.h
67477 @@ -323,7 +323,7 @@ struct omap_dss_board_info {
67478 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
67479 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
67480 int (*set_min_bus_tput)(struct device *dev, unsigned long r);
67481 -};
67482 +} __do_const;
67483
67484 /* Init with the board info */
67485 extern int omap_display_init(struct omap_dss_board_info *board_data);
67486 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67487 index f9466fa..f4e2b81 100644
67488 --- a/include/video/udlfb.h
67489 +++ b/include/video/udlfb.h
67490 @@ -53,10 +53,10 @@ struct dlfb_data {
67491 u32 pseudo_palette[256];
67492 int blank_mode; /*one of FB_BLANK_ */
67493 /* blit-only rendering path metrics, exposed through sysfs */
67494 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67495 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67496 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67497 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67498 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67499 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67500 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67501 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67502 };
67503
67504 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67505 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67506 index 0993a22..32ba2fe 100644
67507 --- a/include/video/uvesafb.h
67508 +++ b/include/video/uvesafb.h
67509 @@ -177,6 +177,7 @@ struct uvesafb_par {
67510 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67511 u8 pmi_setpal; /* PMI for palette changes */
67512 u16 *pmi_base; /* protected mode interface location */
67513 + u8 *pmi_code; /* protected mode code location */
67514 void *pmi_start;
67515 void *pmi_pal;
67516 u8 *vbe_state_orig; /*
67517 diff --git a/init/Kconfig b/init/Kconfig
67518 index 6fdd6e3..5b01610 100644
67519 --- a/init/Kconfig
67520 +++ b/init/Kconfig
67521 @@ -925,6 +925,7 @@ endif # CGROUPS
67522
67523 config CHECKPOINT_RESTORE
67524 bool "Checkpoint/restore support" if EXPERT
67525 + depends on !GRKERNSEC
67526 default n
67527 help
67528 Enables additional kernel features in a sake of checkpoint/restore.
67529 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67530 depends on OCFS2_FS = n
67531 depends on XFS_FS = n
67532
67533 + depends on GRKERNSEC = n
67534 +
67535 config UIDGID_STRICT_TYPE_CHECKS
67536 bool "Require conversions between uid/gids and their internal representation"
67537 depends on UIDGID_CONVERTED
67538 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67539
67540 config COMPAT_BRK
67541 bool "Disable heap randomization"
67542 - default y
67543 + default n
67544 help
67545 Randomizing heap placement makes heap exploits harder, but it
67546 also breaks ancient binaries (including anything libc5 based).
67547 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67548 config STOP_MACHINE
67549 bool
67550 default y
67551 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67552 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67553 help
67554 Need stop_machine() primitive.
67555
67556 diff --git a/init/Makefile b/init/Makefile
67557 index 7bc47ee..6da2dc7 100644
67558 --- a/init/Makefile
67559 +++ b/init/Makefile
67560 @@ -2,6 +2,9 @@
67561 # Makefile for the linux kernel.
67562 #
67563
67564 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67565 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67566 +
67567 obj-y := main.o version.o mounts.o
67568 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67569 obj-y += noinitramfs.o
67570 diff --git a/init/do_mounts.c b/init/do_mounts.c
67571 index f8a6642..4e5ee1b 100644
67572 --- a/init/do_mounts.c
67573 +++ b/init/do_mounts.c
67574 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67575 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67576 {
67577 struct super_block *s;
67578 - int err = sys_mount(name, "/root", fs, flags, data);
67579 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67580 if (err)
67581 return err;
67582
67583 - sys_chdir("/root");
67584 + sys_chdir((const char __force_user *)"/root");
67585 s = current->fs->pwd.dentry->d_sb;
67586 ROOT_DEV = s->s_dev;
67587 printk(KERN_INFO
67588 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67589 va_start(args, fmt);
67590 vsprintf(buf, fmt, args);
67591 va_end(args);
67592 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67593 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67594 if (fd >= 0) {
67595 sys_ioctl(fd, FDEJECT, 0);
67596 sys_close(fd);
67597 }
67598 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67599 - fd = sys_open("/dev/console", O_RDWR, 0);
67600 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67601 if (fd >= 0) {
67602 sys_ioctl(fd, TCGETS, (long)&termios);
67603 termios.c_lflag &= ~ICANON;
67604 sys_ioctl(fd, TCSETSF, (long)&termios);
67605 - sys_read(fd, &c, 1);
67606 + sys_read(fd, (char __user *)&c, 1);
67607 termios.c_lflag |= ICANON;
67608 sys_ioctl(fd, TCSETSF, (long)&termios);
67609 sys_close(fd);
67610 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67611 mount_root();
67612 out:
67613 devtmpfs_mount("dev");
67614 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
67615 - sys_chroot(".");
67616 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67617 + sys_chroot((const char __force_user *)".");
67618 }
67619 diff --git a/init/do_mounts.h b/init/do_mounts.h
67620 index f5b978a..69dbfe8 100644
67621 --- a/init/do_mounts.h
67622 +++ b/init/do_mounts.h
67623 @@ -15,15 +15,15 @@ extern int root_mountflags;
67624
67625 static inline int create_dev(char *name, dev_t dev)
67626 {
67627 - sys_unlink(name);
67628 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67629 + sys_unlink((char __force_user *)name);
67630 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67631 }
67632
67633 #if BITS_PER_LONG == 32
67634 static inline u32 bstat(char *name)
67635 {
67636 struct stat64 stat;
67637 - if (sys_stat64(name, &stat) != 0)
67638 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67639 return 0;
67640 if (!S_ISBLK(stat.st_mode))
67641 return 0;
67642 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67643 static inline u32 bstat(char *name)
67644 {
67645 struct stat stat;
67646 - if (sys_newstat(name, &stat) != 0)
67647 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67648 return 0;
67649 if (!S_ISBLK(stat.st_mode))
67650 return 0;
67651 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67652 index f9acf71..1e19144 100644
67653 --- a/init/do_mounts_initrd.c
67654 +++ b/init/do_mounts_initrd.c
67655 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67656 create_dev("/dev/root.old", Root_RAM0);
67657 /* mount initrd on rootfs' /root */
67658 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67659 - sys_mkdir("/old", 0700);
67660 - sys_chdir("/old");
67661 + sys_mkdir((const char __force_user *)"/old", 0700);
67662 + sys_chdir((const char __force_user *)"/old");
67663
67664 /*
67665 * In case that a resume from disk is carried out by linuxrc or one of
67666 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67667 current->flags &= ~PF_FREEZER_SKIP;
67668
67669 /* move initrd to rootfs' /old */
67670 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
67671 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67672 /* switch root and cwd back to / of rootfs */
67673 - sys_chroot("..");
67674 + sys_chroot((const char __force_user *)"..");
67675
67676 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67677 - sys_chdir("/old");
67678 + sys_chdir((const char __force_user *)"/old");
67679 return;
67680 }
67681
67682 - sys_chdir("/");
67683 + sys_chdir((const char __force_user *)"/");
67684 ROOT_DEV = new_decode_dev(real_root_dev);
67685 mount_root();
67686
67687 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67688 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67689 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67690 if (!error)
67691 printk("okay\n");
67692 else {
67693 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
67694 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67695 if (error == -ENOENT)
67696 printk("/initrd does not exist. Ignored.\n");
67697 else
67698 printk("failed\n");
67699 printk(KERN_NOTICE "Unmounting old root\n");
67700 - sys_umount("/old", MNT_DETACH);
67701 + sys_umount((char __force_user *)"/old", MNT_DETACH);
67702 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
67703 if (fd < 0) {
67704 error = fd;
67705 @@ -120,11 +120,11 @@ int __init initrd_load(void)
67706 * mounted in the normal path.
67707 */
67708 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
67709 - sys_unlink("/initrd.image");
67710 + sys_unlink((const char __force_user *)"/initrd.image");
67711 handle_initrd();
67712 return 1;
67713 }
67714 }
67715 - sys_unlink("/initrd.image");
67716 + sys_unlink((const char __force_user *)"/initrd.image");
67717 return 0;
67718 }
67719 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
67720 index 8cb6db5..d729f50 100644
67721 --- a/init/do_mounts_md.c
67722 +++ b/init/do_mounts_md.c
67723 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
67724 partitioned ? "_d" : "", minor,
67725 md_setup_args[ent].device_names);
67726
67727 - fd = sys_open(name, 0, 0);
67728 + fd = sys_open((char __force_user *)name, 0, 0);
67729 if (fd < 0) {
67730 printk(KERN_ERR "md: open failed - cannot start "
67731 "array %s\n", name);
67732 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
67733 * array without it
67734 */
67735 sys_close(fd);
67736 - fd = sys_open(name, 0, 0);
67737 + fd = sys_open((char __force_user *)name, 0, 0);
67738 sys_ioctl(fd, BLKRRPART, 0);
67739 }
67740 sys_close(fd);
67741 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
67742
67743 wait_for_device_probe();
67744
67745 - fd = sys_open("/dev/md0", 0, 0);
67746 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
67747 if (fd >= 0) {
67748 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
67749 sys_close(fd);
67750 diff --git a/init/init_task.c b/init/init_task.c
67751 index 8b2f399..f0797c9 100644
67752 --- a/init/init_task.c
67753 +++ b/init/init_task.c
67754 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
67755 * Initial thread structure. Alignment of this is handled by a special
67756 * linker map entry.
67757 */
67758 +#ifdef CONFIG_X86
67759 +union thread_union init_thread_union __init_task_data;
67760 +#else
67761 union thread_union init_thread_union __init_task_data =
67762 { INIT_THREAD_INFO(init_task) };
67763 +#endif
67764 diff --git a/init/initramfs.c b/init/initramfs.c
67765 index 84c6bf1..8899338 100644
67766 --- a/init/initramfs.c
67767 +++ b/init/initramfs.c
67768 @@ -84,7 +84,7 @@ static void __init free_hash(void)
67769 }
67770 }
67771
67772 -static long __init do_utime(char *filename, time_t mtime)
67773 +static long __init do_utime(char __force_user *filename, time_t mtime)
67774 {
67775 struct timespec t[2];
67776
67777 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
67778 struct dir_entry *de, *tmp;
67779 list_for_each_entry_safe(de, tmp, &dir_list, list) {
67780 list_del(&de->list);
67781 - do_utime(de->name, de->mtime);
67782 + do_utime((char __force_user *)de->name, de->mtime);
67783 kfree(de->name);
67784 kfree(de);
67785 }
67786 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
67787 if (nlink >= 2) {
67788 char *old = find_link(major, minor, ino, mode, collected);
67789 if (old)
67790 - return (sys_link(old, collected) < 0) ? -1 : 1;
67791 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
67792 }
67793 return 0;
67794 }
67795 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
67796 {
67797 struct stat st;
67798
67799 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
67800 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
67801 if (S_ISDIR(st.st_mode))
67802 - sys_rmdir(path);
67803 + sys_rmdir((char __force_user *)path);
67804 else
67805 - sys_unlink(path);
67806 + sys_unlink((char __force_user *)path);
67807 }
67808 }
67809
67810 @@ -315,7 +315,7 @@ static int __init do_name(void)
67811 int openflags = O_WRONLY|O_CREAT;
67812 if (ml != 1)
67813 openflags |= O_TRUNC;
67814 - wfd = sys_open(collected, openflags, mode);
67815 + wfd = sys_open((char __force_user *)collected, openflags, mode);
67816
67817 if (wfd >= 0) {
67818 sys_fchown(wfd, uid, gid);
67819 @@ -327,17 +327,17 @@ static int __init do_name(void)
67820 }
67821 }
67822 } else if (S_ISDIR(mode)) {
67823 - sys_mkdir(collected, mode);
67824 - sys_chown(collected, uid, gid);
67825 - sys_chmod(collected, mode);
67826 + sys_mkdir((char __force_user *)collected, mode);
67827 + sys_chown((char __force_user *)collected, uid, gid);
67828 + sys_chmod((char __force_user *)collected, mode);
67829 dir_add(collected, mtime);
67830 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
67831 S_ISFIFO(mode) || S_ISSOCK(mode)) {
67832 if (maybe_link() == 0) {
67833 - sys_mknod(collected, mode, rdev);
67834 - sys_chown(collected, uid, gid);
67835 - sys_chmod(collected, mode);
67836 - do_utime(collected, mtime);
67837 + sys_mknod((char __force_user *)collected, mode, rdev);
67838 + sys_chown((char __force_user *)collected, uid, gid);
67839 + sys_chmod((char __force_user *)collected, mode);
67840 + do_utime((char __force_user *)collected, mtime);
67841 }
67842 }
67843 return 0;
67844 @@ -346,15 +346,15 @@ static int __init do_name(void)
67845 static int __init do_copy(void)
67846 {
67847 if (count >= body_len) {
67848 - sys_write(wfd, victim, body_len);
67849 + sys_write(wfd, (char __force_user *)victim, body_len);
67850 sys_close(wfd);
67851 - do_utime(vcollected, mtime);
67852 + do_utime((char __force_user *)vcollected, mtime);
67853 kfree(vcollected);
67854 eat(body_len);
67855 state = SkipIt;
67856 return 0;
67857 } else {
67858 - sys_write(wfd, victim, count);
67859 + sys_write(wfd, (char __force_user *)victim, count);
67860 body_len -= count;
67861 eat(count);
67862 return 1;
67863 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
67864 {
67865 collected[N_ALIGN(name_len) + body_len] = '\0';
67866 clean_path(collected, 0);
67867 - sys_symlink(collected + N_ALIGN(name_len), collected);
67868 - sys_lchown(collected, uid, gid);
67869 - do_utime(collected, mtime);
67870 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
67871 + sys_lchown((char __force_user *)collected, uid, gid);
67872 + do_utime((char __force_user *)collected, mtime);
67873 state = SkipIt;
67874 next_state = Reset;
67875 return 0;
67876 diff --git a/init/main.c b/init/main.c
67877 index cd147a9..12ce8c2 100644
67878 --- a/init/main.c
67879 +++ b/init/main.c
67880 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
67881 extern void tc_init(void);
67882 #endif
67883
67884 +extern void grsecurity_init(void);
67885 +
67886 /*
67887 * Debug helper: via this flag we know that we are in 'early bootup code'
67888 * where only the boot processor is running with IRQ disabled. This means
67889 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
67890
67891 __setup("reset_devices", set_reset_devices);
67892
67893 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67894 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
67895 +static int __init setup_grsec_proc_gid(char *str)
67896 +{
67897 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
67898 + return 1;
67899 +}
67900 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
67901 +#endif
67902 +
67903 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
67904 +extern char pax_enter_kernel_user[];
67905 +extern char pax_exit_kernel_user[];
67906 +extern pgdval_t clone_pgd_mask;
67907 +#endif
67908 +
67909 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
67910 +static int __init setup_pax_nouderef(char *str)
67911 +{
67912 +#ifdef CONFIG_X86_32
67913 + unsigned int cpu;
67914 + struct desc_struct *gdt;
67915 +
67916 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
67917 + gdt = get_cpu_gdt_table(cpu);
67918 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
67919 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
67920 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
67921 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
67922 + }
67923 + loadsegment(ds, __KERNEL_DS);
67924 + loadsegment(es, __KERNEL_DS);
67925 + loadsegment(ss, __KERNEL_DS);
67926 +#else
67927 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
67928 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
67929 + clone_pgd_mask = ~(pgdval_t)0UL;
67930 +#endif
67931 +
67932 + return 0;
67933 +}
67934 +early_param("pax_nouderef", setup_pax_nouderef);
67935 +#endif
67936 +
67937 +#ifdef CONFIG_PAX_SOFTMODE
67938 +int pax_softmode;
67939 +
67940 +static int __init setup_pax_softmode(char *str)
67941 +{
67942 + get_option(&str, &pax_softmode);
67943 + return 1;
67944 +}
67945 +__setup("pax_softmode=", setup_pax_softmode);
67946 +#endif
67947 +
67948 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
67949 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
67950 static const char *panic_later, *panic_param;
67951 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
67952 {
67953 int count = preempt_count();
67954 int ret;
67955 + const char *msg1 = "", *msg2 = "";
67956
67957 if (initcall_debug)
67958 ret = do_one_initcall_debug(fn);
67959 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
67960 sprintf(msgbuf, "error code %d ", ret);
67961
67962 if (preempt_count() != count) {
67963 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
67964 + msg1 = " preemption imbalance";
67965 preempt_count() = count;
67966 }
67967 if (irqs_disabled()) {
67968 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
67969 + msg2 = " disabled interrupts";
67970 local_irq_enable();
67971 }
67972 - if (msgbuf[0]) {
67973 - printk("initcall %pF returned with %s\n", fn, msgbuf);
67974 + if (msgbuf[0] || *msg1 || *msg2) {
67975 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
67976 }
67977
67978 return ret;
67979 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
67980 "late",
67981 };
67982
67983 +#ifdef CONFIG_PAX_LATENT_ENTROPY
67984 +u64 latent_entropy;
67985 +#endif
67986 +
67987 static void __init do_initcall_level(int level)
67988 {
67989 extern const struct kernel_param __start___param[], __stop___param[];
67990 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
67991 level, level,
67992 &repair_env_string);
67993
67994 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
67995 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
67996 do_one_initcall(*fn);
67997 +
67998 +#ifdef CONFIG_PAX_LATENT_ENTROPY
67999 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68000 +#endif
68001 +
68002 + }
68003 }
68004
68005 static void __init do_initcalls(void)
68006 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68007 {
68008 initcall_t *fn;
68009
68010 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
68011 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68012 do_one_initcall(*fn);
68013 +
68014 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68015 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68016 +#endif
68017 +
68018 + }
68019 }
68020
68021 static int run_init_process(const char *init_filename)
68022 @@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68023 do_basic_setup();
68024
68025 /* Open the /dev/console on the rootfs, this should never fail */
68026 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68027 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68028 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68029
68030 (void) sys_dup(0);
68031 @@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68032 if (!ramdisk_execute_command)
68033 ramdisk_execute_command = "/init";
68034
68035 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68036 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68037 ramdisk_execute_command = NULL;
68038 prepare_namespace();
68039 }
68040
68041 + grsecurity_init();
68042 +
68043 /*
68044 * Ok, we have completed the initial bootup, and
68045 * we're essentially up and running. Get rid of the
68046 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68047 index 71a3ca1..cc330ee 100644
68048 --- a/ipc/mqueue.c
68049 +++ b/ipc/mqueue.c
68050 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68051 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68052 info->attr.mq_msgsize);
68053
68054 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68055 spin_lock(&mq_lock);
68056 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68057 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68058 diff --git a/ipc/msg.c b/ipc/msg.c
68059 index a71af5a..a90a110 100644
68060 --- a/ipc/msg.c
68061 +++ b/ipc/msg.c
68062 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68063 return security_msg_queue_associate(msq, msgflg);
68064 }
68065
68066 +static struct ipc_ops msg_ops = {
68067 + .getnew = newque,
68068 + .associate = msg_security,
68069 + .more_checks = NULL
68070 +};
68071 +
68072 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68073 {
68074 struct ipc_namespace *ns;
68075 - struct ipc_ops msg_ops;
68076 struct ipc_params msg_params;
68077
68078 ns = current->nsproxy->ipc_ns;
68079
68080 - msg_ops.getnew = newque;
68081 - msg_ops.associate = msg_security;
68082 - msg_ops.more_checks = NULL;
68083 -
68084 msg_params.key = key;
68085 msg_params.flg = msgflg;
68086
68087 diff --git a/ipc/sem.c b/ipc/sem.c
68088 index 58d31f1..cce7a55 100644
68089 --- a/ipc/sem.c
68090 +++ b/ipc/sem.c
68091 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68092 return 0;
68093 }
68094
68095 +static struct ipc_ops sem_ops = {
68096 + .getnew = newary,
68097 + .associate = sem_security,
68098 + .more_checks = sem_more_checks
68099 +};
68100 +
68101 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68102 {
68103 struct ipc_namespace *ns;
68104 - struct ipc_ops sem_ops;
68105 struct ipc_params sem_params;
68106
68107 ns = current->nsproxy->ipc_ns;
68108 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68109 if (nsems < 0 || nsems > ns->sc_semmsl)
68110 return -EINVAL;
68111
68112 - sem_ops.getnew = newary;
68113 - sem_ops.associate = sem_security;
68114 - sem_ops.more_checks = sem_more_checks;
68115 -
68116 sem_params.key = key;
68117 sem_params.flg = semflg;
68118 sem_params.u.nsems = nsems;
68119 diff --git a/ipc/shm.c b/ipc/shm.c
68120 index dff40c9..9450e27 100644
68121 --- a/ipc/shm.c
68122 +++ b/ipc/shm.c
68123 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68124 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68125 #endif
68126
68127 +#ifdef CONFIG_GRKERNSEC
68128 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68129 + const time_t shm_createtime, const uid_t cuid,
68130 + const int shmid);
68131 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68132 + const time_t shm_createtime);
68133 +#endif
68134 +
68135 void shm_init_ns(struct ipc_namespace *ns)
68136 {
68137 ns->shm_ctlmax = SHMMAX;
68138 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68139 shp->shm_lprid = 0;
68140 shp->shm_atim = shp->shm_dtim = 0;
68141 shp->shm_ctim = get_seconds();
68142 +#ifdef CONFIG_GRKERNSEC
68143 + {
68144 + struct timespec timeval;
68145 + do_posix_clock_monotonic_gettime(&timeval);
68146 +
68147 + shp->shm_createtime = timeval.tv_sec;
68148 + }
68149 +#endif
68150 shp->shm_segsz = size;
68151 shp->shm_nattch = 0;
68152 shp->shm_file = file;
68153 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68154 return 0;
68155 }
68156
68157 +static struct ipc_ops shm_ops = {
68158 + .getnew = newseg,
68159 + .associate = shm_security,
68160 + .more_checks = shm_more_checks
68161 +};
68162 +
68163 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68164 {
68165 struct ipc_namespace *ns;
68166 - struct ipc_ops shm_ops;
68167 struct ipc_params shm_params;
68168
68169 ns = current->nsproxy->ipc_ns;
68170
68171 - shm_ops.getnew = newseg;
68172 - shm_ops.associate = shm_security;
68173 - shm_ops.more_checks = shm_more_checks;
68174 -
68175 shm_params.key = key;
68176 shm_params.flg = shmflg;
68177 shm_params.u.size = size;
68178 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68179 f_mode = FMODE_READ | FMODE_WRITE;
68180 }
68181 if (shmflg & SHM_EXEC) {
68182 +
68183 +#ifdef CONFIG_PAX_MPROTECT
68184 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
68185 + goto out;
68186 +#endif
68187 +
68188 prot |= PROT_EXEC;
68189 acc_mode |= S_IXUGO;
68190 }
68191 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68192 if (err)
68193 goto out_unlock;
68194
68195 +#ifdef CONFIG_GRKERNSEC
68196 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68197 + shp->shm_perm.cuid, shmid) ||
68198 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68199 + err = -EACCES;
68200 + goto out_unlock;
68201 + }
68202 +#endif
68203 +
68204 path = shp->shm_file->f_path;
68205 path_get(&path);
68206 shp->shm_nattch++;
68207 +#ifdef CONFIG_GRKERNSEC
68208 + shp->shm_lapid = current->pid;
68209 +#endif
68210 size = i_size_read(path.dentry->d_inode);
68211 shm_unlock(shp);
68212
68213 diff --git a/kernel/acct.c b/kernel/acct.c
68214 index 051e071..15e0920 100644
68215 --- a/kernel/acct.c
68216 +++ b/kernel/acct.c
68217 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68218 */
68219 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68220 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68221 - file->f_op->write(file, (char *)&ac,
68222 + file->f_op->write(file, (char __force_user *)&ac,
68223 sizeof(acct_t), &file->f_pos);
68224 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68225 set_fs(fs);
68226 diff --git a/kernel/audit.c b/kernel/audit.c
68227 index 40414e9..c920b72 100644
68228 --- a/kernel/audit.c
68229 +++ b/kernel/audit.c
68230 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68231 3) suppressed due to audit_rate_limit
68232 4) suppressed due to audit_backlog_limit
68233 */
68234 -static atomic_t audit_lost = ATOMIC_INIT(0);
68235 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68236
68237 /* The netlink socket. */
68238 static struct sock *audit_sock;
68239 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68240 unsigned long now;
68241 int print;
68242
68243 - atomic_inc(&audit_lost);
68244 + atomic_inc_unchecked(&audit_lost);
68245
68246 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68247
68248 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68249 printk(KERN_WARNING
68250 "audit: audit_lost=%d audit_rate_limit=%d "
68251 "audit_backlog_limit=%d\n",
68252 - atomic_read(&audit_lost),
68253 + atomic_read_unchecked(&audit_lost),
68254 audit_rate_limit,
68255 audit_backlog_limit);
68256 audit_panic(message);
68257 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68258 status_set.pid = audit_pid;
68259 status_set.rate_limit = audit_rate_limit;
68260 status_set.backlog_limit = audit_backlog_limit;
68261 - status_set.lost = atomic_read(&audit_lost);
68262 + status_set.lost = atomic_read_unchecked(&audit_lost);
68263 status_set.backlog = skb_queue_len(&audit_skb_queue);
68264 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68265 &status_set, sizeof(status_set));
68266 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68267 index 157e989..b28b365 100644
68268 --- a/kernel/auditsc.c
68269 +++ b/kernel/auditsc.c
68270 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68271 }
68272
68273 /* global counter which is incremented every time something logs in */
68274 -static atomic_t session_id = ATOMIC_INIT(0);
68275 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68276
68277 /**
68278 * audit_set_loginuid - set current task's audit_context loginuid
68279 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68280 return -EPERM;
68281 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68282
68283 - sessionid = atomic_inc_return(&session_id);
68284 + sessionid = atomic_inc_return_unchecked(&session_id);
68285 if (context && context->in_syscall) {
68286 struct audit_buffer *ab;
68287
68288 diff --git a/kernel/capability.c b/kernel/capability.c
68289 index 493d972..ea17248 100644
68290 --- a/kernel/capability.c
68291 +++ b/kernel/capability.c
68292 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68293 * before modification is attempted and the application
68294 * fails.
68295 */
68296 + if (tocopy > ARRAY_SIZE(kdata))
68297 + return -EFAULT;
68298 +
68299 if (copy_to_user(dataptr, kdata, tocopy
68300 * sizeof(struct __user_cap_data_struct))) {
68301 return -EFAULT;
68302 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68303 int ret;
68304
68305 rcu_read_lock();
68306 - ret = security_capable(__task_cred(t), ns, cap);
68307 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68308 + gr_task_is_capable(t, __task_cred(t), cap);
68309 rcu_read_unlock();
68310
68311 - return (ret == 0);
68312 + return ret;
68313 }
68314
68315 /**
68316 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68317 int ret;
68318
68319 rcu_read_lock();
68320 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
68321 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68322 rcu_read_unlock();
68323
68324 - return (ret == 0);
68325 + return ret;
68326 }
68327
68328 /**
68329 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68330 BUG();
68331 }
68332
68333 - if (security_capable(current_cred(), ns, cap) == 0) {
68334 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68335 current->flags |= PF_SUPERPRIV;
68336 return true;
68337 }
68338 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68339 }
68340 EXPORT_SYMBOL(ns_capable);
68341
68342 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
68343 +{
68344 + if (unlikely(!cap_valid(cap))) {
68345 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68346 + BUG();
68347 + }
68348 +
68349 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68350 + current->flags |= PF_SUPERPRIV;
68351 + return true;
68352 + }
68353 + return false;
68354 +}
68355 +EXPORT_SYMBOL(ns_capable_nolog);
68356 +
68357 /**
68358 * capable - Determine if the current task has a superior capability in effect
68359 * @cap: The capability to be tested for
68360 @@ -408,6 +427,12 @@ bool capable(int cap)
68361 }
68362 EXPORT_SYMBOL(capable);
68363
68364 +bool capable_nolog(int cap)
68365 +{
68366 + return ns_capable_nolog(&init_user_ns, cap);
68367 +}
68368 +EXPORT_SYMBOL(capable_nolog);
68369 +
68370 /**
68371 * nsown_capable - Check superior capability to one's own user_ns
68372 * @cap: The capability in question
68373 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68374
68375 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68376 }
68377 +
68378 +bool inode_capable_nolog(const struct inode *inode, int cap)
68379 +{
68380 + struct user_namespace *ns = current_user_ns();
68381 +
68382 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68383 +}
68384 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68385 index ad99830..992d8a7 100644
68386 --- a/kernel/cgroup.c
68387 +++ b/kernel/cgroup.c
68388 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68389 struct css_set *cg = link->cg;
68390 struct task_struct *task;
68391 int count = 0;
68392 - seq_printf(seq, "css_set %p\n", cg);
68393 + seq_printf(seq, "css_set %pK\n", cg);
68394 list_for_each_entry(task, &cg->tasks, cg_list) {
68395 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68396 seq_puts(seq, " ...\n");
68397 diff --git a/kernel/compat.c b/kernel/compat.c
68398 index c28a306..b4d0cf3 100644
68399 --- a/kernel/compat.c
68400 +++ b/kernel/compat.c
68401 @@ -13,6 +13,7 @@
68402
68403 #include <linux/linkage.h>
68404 #include <linux/compat.h>
68405 +#include <linux/module.h>
68406 #include <linux/errno.h>
68407 #include <linux/time.h>
68408 #include <linux/signal.h>
68409 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68410 mm_segment_t oldfs;
68411 long ret;
68412
68413 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68414 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68415 oldfs = get_fs();
68416 set_fs(KERNEL_DS);
68417 ret = hrtimer_nanosleep_restart(restart);
68418 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68419 oldfs = get_fs();
68420 set_fs(KERNEL_DS);
68421 ret = hrtimer_nanosleep(&tu,
68422 - rmtp ? (struct timespec __user *)&rmt : NULL,
68423 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
68424 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68425 set_fs(oldfs);
68426
68427 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68428 mm_segment_t old_fs = get_fs();
68429
68430 set_fs(KERNEL_DS);
68431 - ret = sys_sigpending((old_sigset_t __user *) &s);
68432 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
68433 set_fs(old_fs);
68434 if (ret == 0)
68435 ret = put_user(s, set);
68436 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68437 mm_segment_t old_fs = get_fs();
68438
68439 set_fs(KERNEL_DS);
68440 - ret = sys_old_getrlimit(resource, &r);
68441 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68442 set_fs(old_fs);
68443
68444 if (!ret) {
68445 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68446 mm_segment_t old_fs = get_fs();
68447
68448 set_fs(KERNEL_DS);
68449 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68450 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68451 set_fs(old_fs);
68452
68453 if (ret)
68454 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68455 set_fs (KERNEL_DS);
68456 ret = sys_wait4(pid,
68457 (stat_addr ?
68458 - (unsigned int __user *) &status : NULL),
68459 - options, (struct rusage __user *) &r);
68460 + (unsigned int __force_user *) &status : NULL),
68461 + options, (struct rusage __force_user *) &r);
68462 set_fs (old_fs);
68463
68464 if (ret > 0) {
68465 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68466 memset(&info, 0, sizeof(info));
68467
68468 set_fs(KERNEL_DS);
68469 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68470 - uru ? (struct rusage __user *)&ru : NULL);
68471 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68472 + uru ? (struct rusage __force_user *)&ru : NULL);
68473 set_fs(old_fs);
68474
68475 if ((ret < 0) || (info.si_signo == 0))
68476 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68477 oldfs = get_fs();
68478 set_fs(KERNEL_DS);
68479 err = sys_timer_settime(timer_id, flags,
68480 - (struct itimerspec __user *) &newts,
68481 - (struct itimerspec __user *) &oldts);
68482 + (struct itimerspec __force_user *) &newts,
68483 + (struct itimerspec __force_user *) &oldts);
68484 set_fs(oldfs);
68485 if (!err && old && put_compat_itimerspec(old, &oldts))
68486 return -EFAULT;
68487 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68488 oldfs = get_fs();
68489 set_fs(KERNEL_DS);
68490 err = sys_timer_gettime(timer_id,
68491 - (struct itimerspec __user *) &ts);
68492 + (struct itimerspec __force_user *) &ts);
68493 set_fs(oldfs);
68494 if (!err && put_compat_itimerspec(setting, &ts))
68495 return -EFAULT;
68496 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68497 oldfs = get_fs();
68498 set_fs(KERNEL_DS);
68499 err = sys_clock_settime(which_clock,
68500 - (struct timespec __user *) &ts);
68501 + (struct timespec __force_user *) &ts);
68502 set_fs(oldfs);
68503 return err;
68504 }
68505 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68506 oldfs = get_fs();
68507 set_fs(KERNEL_DS);
68508 err = sys_clock_gettime(which_clock,
68509 - (struct timespec __user *) &ts);
68510 + (struct timespec __force_user *) &ts);
68511 set_fs(oldfs);
68512 if (!err && put_compat_timespec(&ts, tp))
68513 return -EFAULT;
68514 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68515
68516 oldfs = get_fs();
68517 set_fs(KERNEL_DS);
68518 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68519 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68520 set_fs(oldfs);
68521
68522 err = compat_put_timex(utp, &txc);
68523 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68524 oldfs = get_fs();
68525 set_fs(KERNEL_DS);
68526 err = sys_clock_getres(which_clock,
68527 - (struct timespec __user *) &ts);
68528 + (struct timespec __force_user *) &ts);
68529 set_fs(oldfs);
68530 if (!err && tp && put_compat_timespec(&ts, tp))
68531 return -EFAULT;
68532 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68533 long err;
68534 mm_segment_t oldfs;
68535 struct timespec tu;
68536 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68537 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68538
68539 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68540 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68541 oldfs = get_fs();
68542 set_fs(KERNEL_DS);
68543 err = clock_nanosleep_restart(restart);
68544 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68545 oldfs = get_fs();
68546 set_fs(KERNEL_DS);
68547 err = sys_clock_nanosleep(which_clock, flags,
68548 - (struct timespec __user *) &in,
68549 - (struct timespec __user *) &out);
68550 + (struct timespec __force_user *) &in,
68551 + (struct timespec __force_user *) &out);
68552 set_fs(oldfs);
68553
68554 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68555 diff --git a/kernel/configs.c b/kernel/configs.c
68556 index 42e8fa0..9e7406b 100644
68557 --- a/kernel/configs.c
68558 +++ b/kernel/configs.c
68559 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68560 struct proc_dir_entry *entry;
68561
68562 /* create the current config file */
68563 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68564 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68565 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68566 + &ikconfig_file_ops);
68567 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68568 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68569 + &ikconfig_file_ops);
68570 +#endif
68571 +#else
68572 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68573 &ikconfig_file_ops);
68574 +#endif
68575 +
68576 if (!entry)
68577 return -ENOMEM;
68578
68579 diff --git a/kernel/cred.c b/kernel/cred.c
68580 index 48cea3d..3476734 100644
68581 --- a/kernel/cred.c
68582 +++ b/kernel/cred.c
68583 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68584 validate_creds(cred);
68585 alter_cred_subscribers(cred, -1);
68586 put_cred(cred);
68587 +
68588 +#ifdef CONFIG_GRKERNSEC_SETXID
68589 + cred = (struct cred *) tsk->delayed_cred;
68590 + if (cred != NULL) {
68591 + tsk->delayed_cred = NULL;
68592 + validate_creds(cred);
68593 + alter_cred_subscribers(cred, -1);
68594 + put_cred(cred);
68595 + }
68596 +#endif
68597 }
68598
68599 /**
68600 @@ -469,7 +479,7 @@ error_put:
68601 * Always returns 0 thus allowing this function to be tail-called at the end
68602 * of, say, sys_setgid().
68603 */
68604 -int commit_creds(struct cred *new)
68605 +static int __commit_creds(struct cred *new)
68606 {
68607 struct task_struct *task = current;
68608 const struct cred *old = task->real_cred;
68609 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68610
68611 get_cred(new); /* we will require a ref for the subj creds too */
68612
68613 + gr_set_role_label(task, new->uid, new->gid);
68614 +
68615 /* dumpability changes */
68616 if (!uid_eq(old->euid, new->euid) ||
68617 !gid_eq(old->egid, new->egid) ||
68618 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68619 put_cred(old);
68620 return 0;
68621 }
68622 +#ifdef CONFIG_GRKERNSEC_SETXID
68623 +extern int set_user(struct cred *new);
68624 +
68625 +void gr_delayed_cred_worker(void)
68626 +{
68627 + const struct cred *new = current->delayed_cred;
68628 + struct cred *ncred;
68629 +
68630 + current->delayed_cred = NULL;
68631 +
68632 + if (current_uid() && new != NULL) {
68633 + // from doing get_cred on it when queueing this
68634 + put_cred(new);
68635 + return;
68636 + } else if (new == NULL)
68637 + return;
68638 +
68639 + ncred = prepare_creds();
68640 + if (!ncred)
68641 + goto die;
68642 + // uids
68643 + ncred->uid = new->uid;
68644 + ncred->euid = new->euid;
68645 + ncred->suid = new->suid;
68646 + ncred->fsuid = new->fsuid;
68647 + // gids
68648 + ncred->gid = new->gid;
68649 + ncred->egid = new->egid;
68650 + ncred->sgid = new->sgid;
68651 + ncred->fsgid = new->fsgid;
68652 + // groups
68653 + if (set_groups(ncred, new->group_info) < 0) {
68654 + abort_creds(ncred);
68655 + goto die;
68656 + }
68657 + // caps
68658 + ncred->securebits = new->securebits;
68659 + ncred->cap_inheritable = new->cap_inheritable;
68660 + ncred->cap_permitted = new->cap_permitted;
68661 + ncred->cap_effective = new->cap_effective;
68662 + ncred->cap_bset = new->cap_bset;
68663 +
68664 + if (set_user(ncred)) {
68665 + abort_creds(ncred);
68666 + goto die;
68667 + }
68668 +
68669 + // from doing get_cred on it when queueing this
68670 + put_cred(new);
68671 +
68672 + __commit_creds(ncred);
68673 + return;
68674 +die:
68675 + // from doing get_cred on it when queueing this
68676 + put_cred(new);
68677 + do_group_exit(SIGKILL);
68678 +}
68679 +#endif
68680 +
68681 +int commit_creds(struct cred *new)
68682 +{
68683 +#ifdef CONFIG_GRKERNSEC_SETXID
68684 + int ret;
68685 + int schedule_it = 0;
68686 + struct task_struct *t;
68687 +
68688 + /* we won't get called with tasklist_lock held for writing
68689 + and interrupts disabled as the cred struct in that case is
68690 + init_cred
68691 + */
68692 + if (grsec_enable_setxid && !current_is_single_threaded() &&
68693 + !current_uid() && new->uid) {
68694 + schedule_it = 1;
68695 + }
68696 + ret = __commit_creds(new);
68697 + if (schedule_it) {
68698 + rcu_read_lock();
68699 + read_lock(&tasklist_lock);
68700 + for (t = next_thread(current); t != current;
68701 + t = next_thread(t)) {
68702 + if (t->delayed_cred == NULL) {
68703 + t->delayed_cred = get_cred(new);
68704 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
68705 + set_tsk_need_resched(t);
68706 + }
68707 + }
68708 + read_unlock(&tasklist_lock);
68709 + rcu_read_unlock();
68710 + }
68711 + return ret;
68712 +#else
68713 + return __commit_creds(new);
68714 +#endif
68715 +}
68716 +
68717 EXPORT_SYMBOL(commit_creds);
68718
68719 /**
68720 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
68721 index 9a61738..c5c8f3a 100644
68722 --- a/kernel/debug/debug_core.c
68723 +++ b/kernel/debug/debug_core.c
68724 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
68725 */
68726 static atomic_t masters_in_kgdb;
68727 static atomic_t slaves_in_kgdb;
68728 -static atomic_t kgdb_break_tasklet_var;
68729 +static atomic_unchecked_t kgdb_break_tasklet_var;
68730 atomic_t kgdb_setting_breakpoint;
68731
68732 struct task_struct *kgdb_usethread;
68733 @@ -132,7 +132,7 @@ int kgdb_single_step;
68734 static pid_t kgdb_sstep_pid;
68735
68736 /* to keep track of the CPU which is doing the single stepping*/
68737 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68738 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68739
68740 /*
68741 * If you are debugging a problem where roundup (the collection of
68742 @@ -540,7 +540,7 @@ return_normal:
68743 * kernel will only try for the value of sstep_tries before
68744 * giving up and continuing on.
68745 */
68746 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
68747 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
68748 (kgdb_info[cpu].task &&
68749 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
68750 atomic_set(&kgdb_active, -1);
68751 @@ -634,8 +634,8 @@ cpu_master_loop:
68752 }
68753
68754 kgdb_restore:
68755 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
68756 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
68757 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
68758 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
68759 if (kgdb_info[sstep_cpu].task)
68760 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
68761 else
68762 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
68763 static void kgdb_tasklet_bpt(unsigned long ing)
68764 {
68765 kgdb_breakpoint();
68766 - atomic_set(&kgdb_break_tasklet_var, 0);
68767 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
68768 }
68769
68770 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
68771
68772 void kgdb_schedule_breakpoint(void)
68773 {
68774 - if (atomic_read(&kgdb_break_tasklet_var) ||
68775 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
68776 atomic_read(&kgdb_active) != -1 ||
68777 atomic_read(&kgdb_setting_breakpoint))
68778 return;
68779 - atomic_inc(&kgdb_break_tasklet_var);
68780 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
68781 tasklet_schedule(&kgdb_tasklet_breakpoint);
68782 }
68783 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
68784 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
68785 index 8875254..7cf4928 100644
68786 --- a/kernel/debug/kdb/kdb_main.c
68787 +++ b/kernel/debug/kdb/kdb_main.c
68788 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
68789 continue;
68790
68791 kdb_printf("%-20s%8u 0x%p ", mod->name,
68792 - mod->core_size, (void *)mod);
68793 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
68794 #ifdef CONFIG_MODULE_UNLOAD
68795 kdb_printf("%4ld ", module_refcount(mod));
68796 #endif
68797 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
68798 kdb_printf(" (Loading)");
68799 else
68800 kdb_printf(" (Live)");
68801 - kdb_printf(" 0x%p", mod->module_core);
68802 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
68803
68804 #ifdef CONFIG_MODULE_UNLOAD
68805 {
68806 diff --git a/kernel/events/core.c b/kernel/events/core.c
68807 index dbccf83..8c66482 100644
68808 --- a/kernel/events/core.c
68809 +++ b/kernel/events/core.c
68810 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
68811 return 0;
68812 }
68813
68814 -static atomic64_t perf_event_id;
68815 +static atomic64_unchecked_t perf_event_id;
68816
68817 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68818 enum event_type_t event_type);
68819 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
68820
68821 static inline u64 perf_event_count(struct perf_event *event)
68822 {
68823 - return local64_read(&event->count) + atomic64_read(&event->child_count);
68824 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68825 }
68826
68827 static u64 perf_event_read(struct perf_event *event)
68828 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
68829 mutex_lock(&event->child_mutex);
68830 total += perf_event_read(event);
68831 *enabled += event->total_time_enabled +
68832 - atomic64_read(&event->child_total_time_enabled);
68833 + atomic64_read_unchecked(&event->child_total_time_enabled);
68834 *running += event->total_time_running +
68835 - atomic64_read(&event->child_total_time_running);
68836 + atomic64_read_unchecked(&event->child_total_time_running);
68837
68838 list_for_each_entry(child, &event->child_list, child_list) {
68839 total += perf_event_read(child);
68840 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
68841 userpg->offset -= local64_read(&event->hw.prev_count);
68842
68843 userpg->time_enabled = enabled +
68844 - atomic64_read(&event->child_total_time_enabled);
68845 + atomic64_read_unchecked(&event->child_total_time_enabled);
68846
68847 userpg->time_running = running +
68848 - atomic64_read(&event->child_total_time_running);
68849 + atomic64_read_unchecked(&event->child_total_time_running);
68850
68851 arch_perf_update_userpage(userpg, now);
68852
68853 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
68854 values[n++] = perf_event_count(event);
68855 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68856 values[n++] = enabled +
68857 - atomic64_read(&event->child_total_time_enabled);
68858 + atomic64_read_unchecked(&event->child_total_time_enabled);
68859 }
68860 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68861 values[n++] = running +
68862 - atomic64_read(&event->child_total_time_running);
68863 + atomic64_read_unchecked(&event->child_total_time_running);
68864 }
68865 if (read_format & PERF_FORMAT_ID)
68866 values[n++] = primary_event_id(event);
68867 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
68868 * need to add enough zero bytes after the string to handle
68869 * the 64bit alignment we do later.
68870 */
68871 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
68872 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
68873 if (!buf) {
68874 name = strncpy(tmp, "//enomem", sizeof(tmp));
68875 goto got_name;
68876 }
68877 - name = d_path(&file->f_path, buf, PATH_MAX);
68878 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
68879 if (IS_ERR(name)) {
68880 name = strncpy(tmp, "//toolong", sizeof(tmp));
68881 goto got_name;
68882 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
68883 event->parent = parent_event;
68884
68885 event->ns = get_pid_ns(current->nsproxy->pid_ns);
68886 - event->id = atomic64_inc_return(&perf_event_id);
68887 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
68888
68889 event->state = PERF_EVENT_STATE_INACTIVE;
68890
68891 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
68892 /*
68893 * Add back the child's count to the parent's count:
68894 */
68895 - atomic64_add(child_val, &parent_event->child_count);
68896 - atomic64_add(child_event->total_time_enabled,
68897 + atomic64_add_unchecked(child_val, &parent_event->child_count);
68898 + atomic64_add_unchecked(child_event->total_time_enabled,
68899 &parent_event->child_total_time_enabled);
68900 - atomic64_add(child_event->total_time_running,
68901 + atomic64_add_unchecked(child_event->total_time_running,
68902 &parent_event->child_total_time_running);
68903
68904 /*
68905 diff --git a/kernel/exit.c b/kernel/exit.c
68906 index 346616c..f103b28 100644
68907 --- a/kernel/exit.c
68908 +++ b/kernel/exit.c
68909 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
68910 struct task_struct *leader;
68911 int zap_leader;
68912 repeat:
68913 +#ifdef CONFIG_NET
68914 + gr_del_task_from_ip_table(p);
68915 +#endif
68916 +
68917 /* don't need to get the RCU readlock here - the process is dead and
68918 * can't be modifying its own credentials. But shut RCU-lockdep up */
68919 rcu_read_lock();
68920 @@ -394,7 +398,7 @@ int allow_signal(int sig)
68921 * know it'll be handled, so that they don't get converted to
68922 * SIGKILL or just silently dropped.
68923 */
68924 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
68925 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
68926 recalc_sigpending();
68927 spin_unlock_irq(&current->sighand->siglock);
68928 return 0;
68929 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
68930 vsnprintf(current->comm, sizeof(current->comm), name, args);
68931 va_end(args);
68932
68933 + gr_put_exec_file(current);
68934 + gr_set_kernel_label(current);
68935 +
68936 /*
68937 * If we were started as result of loading a module, close all of the
68938 * user space pages. We don't need them, and if we didn't close them
68939 @@ -812,6 +819,8 @@ void do_exit(long code)
68940 struct task_struct *tsk = current;
68941 int group_dead;
68942
68943 + set_fs(USER_DS);
68944 +
68945 profile_task_exit(tsk);
68946
68947 WARN_ON(blk_needs_flush_plug(tsk));
68948 @@ -828,7 +837,6 @@ void do_exit(long code)
68949 * mm_release()->clear_child_tid() from writing to a user-controlled
68950 * kernel address.
68951 */
68952 - set_fs(USER_DS);
68953
68954 ptrace_event(PTRACE_EVENT_EXIT, code);
68955
68956 @@ -887,6 +895,9 @@ void do_exit(long code)
68957 tsk->exit_code = code;
68958 taskstats_exit(tsk, group_dead);
68959
68960 + gr_acl_handle_psacct(tsk, code);
68961 + gr_acl_handle_exit();
68962 +
68963 exit_mm(tsk);
68964
68965 if (group_dead)
68966 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
68967 * Take down every thread in the group. This is called by fatal signals
68968 * as well as by sys_exit_group (below).
68969 */
68970 -void
68971 +__noreturn void
68972 do_group_exit(int exit_code)
68973 {
68974 struct signal_struct *sig = current->signal;
68975 diff --git a/kernel/fork.c b/kernel/fork.c
68976 index acc4cb6..b524cb5 100644
68977 --- a/kernel/fork.c
68978 +++ b/kernel/fork.c
68979 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
68980 *stackend = STACK_END_MAGIC; /* for overflow detection */
68981
68982 #ifdef CONFIG_CC_STACKPROTECTOR
68983 - tsk->stack_canary = get_random_int();
68984 + tsk->stack_canary = pax_get_random_long();
68985 #endif
68986
68987 /*
68988 @@ -344,13 +344,81 @@ free_tsk:
68989 }
68990
68991 #ifdef CONFIG_MMU
68992 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
68993 +{
68994 + struct vm_area_struct *tmp;
68995 + unsigned long charge;
68996 + struct mempolicy *pol;
68997 + struct file *file;
68998 +
68999 + charge = 0;
69000 + if (mpnt->vm_flags & VM_ACCOUNT) {
69001 + unsigned long len = vma_pages(mpnt);
69002 +
69003 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69004 + goto fail_nomem;
69005 + charge = len;
69006 + }
69007 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69008 + if (!tmp)
69009 + goto fail_nomem;
69010 + *tmp = *mpnt;
69011 + tmp->vm_mm = mm;
69012 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
69013 + pol = mpol_dup(vma_policy(mpnt));
69014 + if (IS_ERR(pol))
69015 + goto fail_nomem_policy;
69016 + vma_set_policy(tmp, pol);
69017 + if (anon_vma_fork(tmp, mpnt))
69018 + goto fail_nomem_anon_vma_fork;
69019 + tmp->vm_flags &= ~VM_LOCKED;
69020 + tmp->vm_next = tmp->vm_prev = NULL;
69021 + tmp->vm_mirror = NULL;
69022 + file = tmp->vm_file;
69023 + if (file) {
69024 + struct inode *inode = file->f_path.dentry->d_inode;
69025 + struct address_space *mapping = file->f_mapping;
69026 +
69027 + get_file(file);
69028 + if (tmp->vm_flags & VM_DENYWRITE)
69029 + atomic_dec(&inode->i_writecount);
69030 + mutex_lock(&mapping->i_mmap_mutex);
69031 + if (tmp->vm_flags & VM_SHARED)
69032 + mapping->i_mmap_writable++;
69033 + flush_dcache_mmap_lock(mapping);
69034 + /* insert tmp into the share list, just after mpnt */
69035 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69036 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69037 + else
69038 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69039 + flush_dcache_mmap_unlock(mapping);
69040 + mutex_unlock(&mapping->i_mmap_mutex);
69041 + }
69042 +
69043 + /*
69044 + * Clear hugetlb-related page reserves for children. This only
69045 + * affects MAP_PRIVATE mappings. Faults generated by the child
69046 + * are not guaranteed to succeed, even if read-only
69047 + */
69048 + if (is_vm_hugetlb_page(tmp))
69049 + reset_vma_resv_huge_pages(tmp);
69050 +
69051 + return tmp;
69052 +
69053 +fail_nomem_anon_vma_fork:
69054 + mpol_put(pol);
69055 +fail_nomem_policy:
69056 + kmem_cache_free(vm_area_cachep, tmp);
69057 +fail_nomem:
69058 + vm_unacct_memory(charge);
69059 + return NULL;
69060 +}
69061 +
69062 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69063 {
69064 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69065 struct rb_node **rb_link, *rb_parent;
69066 int retval;
69067 - unsigned long charge;
69068 - struct mempolicy *pol;
69069
69070 down_write(&oldmm->mmap_sem);
69071 flush_cache_dup_mm(oldmm);
69072 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69073 mm->locked_vm = 0;
69074 mm->mmap = NULL;
69075 mm->mmap_cache = NULL;
69076 - mm->free_area_cache = oldmm->mmap_base;
69077 - mm->cached_hole_size = ~0UL;
69078 + mm->free_area_cache = oldmm->free_area_cache;
69079 + mm->cached_hole_size = oldmm->cached_hole_size;
69080 mm->map_count = 0;
69081 cpumask_clear(mm_cpumask(mm));
69082 mm->mm_rb = RB_ROOT;
69083 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69084
69085 prev = NULL;
69086 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69087 - struct file *file;
69088 -
69089 if (mpnt->vm_flags & VM_DONTCOPY) {
69090 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69091 -vma_pages(mpnt));
69092 continue;
69093 }
69094 - charge = 0;
69095 - if (mpnt->vm_flags & VM_ACCOUNT) {
69096 - unsigned long len = vma_pages(mpnt);
69097 -
69098 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69099 - goto fail_nomem;
69100 - charge = len;
69101 - }
69102 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69103 - if (!tmp)
69104 - goto fail_nomem;
69105 - *tmp = *mpnt;
69106 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
69107 - pol = mpol_dup(vma_policy(mpnt));
69108 - retval = PTR_ERR(pol);
69109 - if (IS_ERR(pol))
69110 - goto fail_nomem_policy;
69111 - vma_set_policy(tmp, pol);
69112 - tmp->vm_mm = mm;
69113 - if (anon_vma_fork(tmp, mpnt))
69114 - goto fail_nomem_anon_vma_fork;
69115 - tmp->vm_flags &= ~VM_LOCKED;
69116 - tmp->vm_next = tmp->vm_prev = NULL;
69117 - file = tmp->vm_file;
69118 - if (file) {
69119 - struct inode *inode = file->f_path.dentry->d_inode;
69120 - struct address_space *mapping = file->f_mapping;
69121 -
69122 - get_file(file);
69123 - if (tmp->vm_flags & VM_DENYWRITE)
69124 - atomic_dec(&inode->i_writecount);
69125 - mutex_lock(&mapping->i_mmap_mutex);
69126 - if (tmp->vm_flags & VM_SHARED)
69127 - mapping->i_mmap_writable++;
69128 - flush_dcache_mmap_lock(mapping);
69129 - /* insert tmp into the share list, just after mpnt */
69130 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69131 - vma_nonlinear_insert(tmp,
69132 - &mapping->i_mmap_nonlinear);
69133 - else
69134 - vma_interval_tree_insert_after(tmp, mpnt,
69135 - &mapping->i_mmap);
69136 - flush_dcache_mmap_unlock(mapping);
69137 - mutex_unlock(&mapping->i_mmap_mutex);
69138 + tmp = dup_vma(mm, oldmm, mpnt);
69139 + if (!tmp) {
69140 + retval = -ENOMEM;
69141 + goto out;
69142 }
69143
69144 /*
69145 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69146 if (retval)
69147 goto out;
69148 }
69149 +
69150 +#ifdef CONFIG_PAX_SEGMEXEC
69151 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69152 + struct vm_area_struct *mpnt_m;
69153 +
69154 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69155 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69156 +
69157 + if (!mpnt->vm_mirror)
69158 + continue;
69159 +
69160 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69161 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69162 + mpnt->vm_mirror = mpnt_m;
69163 + } else {
69164 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69165 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69166 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69167 + mpnt->vm_mirror->vm_mirror = mpnt;
69168 + }
69169 + }
69170 + BUG_ON(mpnt_m);
69171 + }
69172 +#endif
69173 +
69174 /* a new mm has just been created */
69175 arch_dup_mmap(oldmm, mm);
69176 retval = 0;
69177 @@ -470,14 +521,6 @@ out:
69178 flush_tlb_mm(oldmm);
69179 up_write(&oldmm->mmap_sem);
69180 return retval;
69181 -fail_nomem_anon_vma_fork:
69182 - mpol_put(pol);
69183 -fail_nomem_policy:
69184 - kmem_cache_free(vm_area_cachep, tmp);
69185 -fail_nomem:
69186 - retval = -ENOMEM;
69187 - vm_unacct_memory(charge);
69188 - goto out;
69189 }
69190
69191 static inline int mm_alloc_pgd(struct mm_struct *mm)
69192 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69193 return ERR_PTR(err);
69194
69195 mm = get_task_mm(task);
69196 - if (mm && mm != current->mm &&
69197 - !ptrace_may_access(task, mode)) {
69198 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69199 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69200 mmput(mm);
69201 mm = ERR_PTR(-EACCES);
69202 }
69203 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69204 spin_unlock(&fs->lock);
69205 return -EAGAIN;
69206 }
69207 - fs->users++;
69208 + atomic_inc(&fs->users);
69209 spin_unlock(&fs->lock);
69210 return 0;
69211 }
69212 tsk->fs = copy_fs_struct(fs);
69213 if (!tsk->fs)
69214 return -ENOMEM;
69215 + /* Carry through gr_chroot_dentry and is_chrooted instead
69216 + of recomputing it here. Already copied when the task struct
69217 + is duplicated. This allows pivot_root to not be treated as
69218 + a chroot
69219 + */
69220 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
69221 +
69222 return 0;
69223 }
69224
69225 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69226 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69227 #endif
69228 retval = -EAGAIN;
69229 +
69230 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69231 +
69232 if (atomic_read(&p->real_cred->user->processes) >=
69233 task_rlimit(p, RLIMIT_NPROC)) {
69234 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69235 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69236 goto bad_fork_free_pid;
69237 }
69238
69239 + /* synchronizes with gr_set_acls()
69240 + we need to call this past the point of no return for fork()
69241 + */
69242 + gr_copy_label(p);
69243 +
69244 if (clone_flags & CLONE_THREAD) {
69245 current->signal->nr_threads++;
69246 atomic_inc(&current->signal->live);
69247 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69248 bad_fork_free:
69249 free_task(p);
69250 fork_out:
69251 + gr_log_forkfail(retval);
69252 +
69253 return ERR_PTR(retval);
69254 }
69255
69256 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69257 if (clone_flags & CLONE_PARENT_SETTID)
69258 put_user(nr, parent_tidptr);
69259
69260 + gr_handle_brute_check();
69261 +
69262 if (clone_flags & CLONE_VFORK) {
69263 p->vfork_done = &vfork;
69264 init_completion(&vfork);
69265 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69266 return 0;
69267
69268 /* don't need lock here; in the worst case we'll do useless copy */
69269 - if (fs->users == 1)
69270 + if (atomic_read(&fs->users) == 1)
69271 return 0;
69272
69273 *new_fsp = copy_fs_struct(fs);
69274 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69275 fs = current->fs;
69276 spin_lock(&fs->lock);
69277 current->fs = new_fs;
69278 - if (--fs->users)
69279 + gr_set_chroot_entries(current, &current->fs->root);
69280 + if (atomic_dec_return(&fs->users))
69281 new_fs = NULL;
69282 else
69283 new_fs = fs;
69284 diff --git a/kernel/futex.c b/kernel/futex.c
69285 index 19eb089..b8c65ea 100644
69286 --- a/kernel/futex.c
69287 +++ b/kernel/futex.c
69288 @@ -54,6 +54,7 @@
69289 #include <linux/mount.h>
69290 #include <linux/pagemap.h>
69291 #include <linux/syscalls.h>
69292 +#include <linux/ptrace.h>
69293 #include <linux/signal.h>
69294 #include <linux/export.h>
69295 #include <linux/magic.h>
69296 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69297 struct page *page, *page_head;
69298 int err, ro = 0;
69299
69300 +#ifdef CONFIG_PAX_SEGMEXEC
69301 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69302 + return -EFAULT;
69303 +#endif
69304 +
69305 /*
69306 * The futex address must be "naturally" aligned.
69307 */
69308 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69309 {
69310 u32 curval;
69311 int i;
69312 + mm_segment_t oldfs;
69313
69314 /*
69315 * This will fail and we want it. Some arch implementations do
69316 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69317 * implementation, the non-functional ones will return
69318 * -ENOSYS.
69319 */
69320 + oldfs = get_fs();
69321 + set_fs(USER_DS);
69322 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69323 futex_cmpxchg_enabled = 1;
69324 + set_fs(oldfs);
69325
69326 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69327 plist_head_init(&futex_queues[i].chain);
69328 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69329 index 9b22d03..6295b62 100644
69330 --- a/kernel/gcov/base.c
69331 +++ b/kernel/gcov/base.c
69332 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
69333 }
69334
69335 #ifdef CONFIG_MODULES
69336 -static inline int within(void *addr, void *start, unsigned long size)
69337 -{
69338 - return ((addr >= start) && (addr < start + size));
69339 -}
69340 -
69341 /* Update list and generate events when modules are unloaded. */
69342 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69343 void *data)
69344 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69345 prev = NULL;
69346 /* Remove entries located in module from linked list. */
69347 for (info = gcov_info_head; info; info = info->next) {
69348 - if (within(info, mod->module_core, mod->core_size)) {
69349 + if (within_module_core_rw((unsigned long)info, mod)) {
69350 if (prev)
69351 prev->next = info->next;
69352 else
69353 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69354 index 6db7a5e..25b6648 100644
69355 --- a/kernel/hrtimer.c
69356 +++ b/kernel/hrtimer.c
69357 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69358 local_irq_restore(flags);
69359 }
69360
69361 -static void run_hrtimer_softirq(struct softirq_action *h)
69362 +static void run_hrtimer_softirq(void)
69363 {
69364 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69365
69366 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69367 index 60f48fa..7f3a770 100644
69368 --- a/kernel/jump_label.c
69369 +++ b/kernel/jump_label.c
69370 @@ -13,6 +13,7 @@
69371 #include <linux/sort.h>
69372 #include <linux/err.h>
69373 #include <linux/static_key.h>
69374 +#include <linux/mm.h>
69375
69376 #ifdef HAVE_JUMP_LABEL
69377
69378 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69379
69380 size = (((unsigned long)stop - (unsigned long)start)
69381 / sizeof(struct jump_entry));
69382 + pax_open_kernel();
69383 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69384 + pax_close_kernel();
69385 }
69386
69387 static void jump_label_update(struct static_key *key, int enable);
69388 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69389 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69390 struct jump_entry *iter;
69391
69392 + pax_open_kernel();
69393 for (iter = iter_start; iter < iter_stop; iter++) {
69394 if (within_module_init(iter->code, mod))
69395 iter->code = 0;
69396 }
69397 + pax_close_kernel();
69398 }
69399
69400 static int
69401 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69402 index 2169fee..45c017a 100644
69403 --- a/kernel/kallsyms.c
69404 +++ b/kernel/kallsyms.c
69405 @@ -11,6 +11,9 @@
69406 * Changed the compression method from stem compression to "table lookup"
69407 * compression (see scripts/kallsyms.c for a more complete description)
69408 */
69409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69410 +#define __INCLUDED_BY_HIDESYM 1
69411 +#endif
69412 #include <linux/kallsyms.h>
69413 #include <linux/module.h>
69414 #include <linux/init.h>
69415 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69416
69417 static inline int is_kernel_inittext(unsigned long addr)
69418 {
69419 + if (system_state != SYSTEM_BOOTING)
69420 + return 0;
69421 +
69422 if (addr >= (unsigned long)_sinittext
69423 && addr <= (unsigned long)_einittext)
69424 return 1;
69425 return 0;
69426 }
69427
69428 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69429 +#ifdef CONFIG_MODULES
69430 +static inline int is_module_text(unsigned long addr)
69431 +{
69432 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69433 + return 1;
69434 +
69435 + addr = ktla_ktva(addr);
69436 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69437 +}
69438 +#else
69439 +static inline int is_module_text(unsigned long addr)
69440 +{
69441 + return 0;
69442 +}
69443 +#endif
69444 +#endif
69445 +
69446 static inline int is_kernel_text(unsigned long addr)
69447 {
69448 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69449 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69450
69451 static inline int is_kernel(unsigned long addr)
69452 {
69453 +
69454 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69455 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69456 + return 1;
69457 +
69458 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69459 +#else
69460 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69461 +#endif
69462 +
69463 return 1;
69464 return in_gate_area_no_mm(addr);
69465 }
69466
69467 static int is_ksym_addr(unsigned long addr)
69468 {
69469 +
69470 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69471 + if (is_module_text(addr))
69472 + return 0;
69473 +#endif
69474 +
69475 if (all_var)
69476 return is_kernel(addr);
69477
69478 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69479
69480 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69481 {
69482 - iter->name[0] = '\0';
69483 iter->nameoff = get_symbol_offset(new_pos);
69484 iter->pos = new_pos;
69485 }
69486 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69487 {
69488 struct kallsym_iter *iter = m->private;
69489
69490 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69491 + if (current_uid())
69492 + return 0;
69493 +#endif
69494 +
69495 /* Some debugging symbols have no name. Ignore them. */
69496 if (!iter->name[0])
69497 return 0;
69498 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69499 */
69500 type = iter->exported ? toupper(iter->type) :
69501 tolower(iter->type);
69502 +
69503 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69504 type, iter->name, iter->module_name);
69505 } else
69506 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69507 struct kallsym_iter *iter;
69508 int ret;
69509
69510 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69511 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69512 if (!iter)
69513 return -ENOMEM;
69514 reset_iter(iter, 0);
69515 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69516 index 30b7b22..c726387 100644
69517 --- a/kernel/kcmp.c
69518 +++ b/kernel/kcmp.c
69519 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69520 struct task_struct *task1, *task2;
69521 int ret;
69522
69523 +#ifdef CONFIG_GRKERNSEC
69524 + return -ENOSYS;
69525 +#endif
69526 +
69527 rcu_read_lock();
69528
69529 /*
69530 diff --git a/kernel/kexec.c b/kernel/kexec.c
69531 index 5e4bd78..00c5b91 100644
69532 --- a/kernel/kexec.c
69533 +++ b/kernel/kexec.c
69534 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69535 unsigned long flags)
69536 {
69537 struct compat_kexec_segment in;
69538 - struct kexec_segment out, __user *ksegments;
69539 + struct kexec_segment out;
69540 + struct kexec_segment __user *ksegments;
69541 unsigned long i, result;
69542
69543 /* Don't allow clients that don't understand the native
69544 diff --git a/kernel/kmod.c b/kernel/kmod.c
69545 index 1c317e3..4a92a55 100644
69546 --- a/kernel/kmod.c
69547 +++ b/kernel/kmod.c
69548 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69549 kfree(info->argv);
69550 }
69551
69552 -static int call_modprobe(char *module_name, int wait)
69553 +static int call_modprobe(char *module_name, char *module_param, int wait)
69554 {
69555 static char *envp[] = {
69556 "HOME=/",
69557 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69558 NULL
69559 };
69560
69561 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69562 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69563 if (!argv)
69564 goto out;
69565
69566 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69567 argv[1] = "-q";
69568 argv[2] = "--";
69569 argv[3] = module_name; /* check free_modprobe_argv() */
69570 - argv[4] = NULL;
69571 + argv[4] = module_param;
69572 + argv[5] = NULL;
69573
69574 return call_usermodehelper_fns(modprobe_path, argv, envp,
69575 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69576 @@ -120,9 +121,8 @@ out:
69577 * If module auto-loading support is disabled then this function
69578 * becomes a no-operation.
69579 */
69580 -int __request_module(bool wait, const char *fmt, ...)
69581 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69582 {
69583 - va_list args;
69584 char module_name[MODULE_NAME_LEN];
69585 unsigned int max_modprobes;
69586 int ret;
69587 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69588 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69589 static int kmod_loop_msg;
69590
69591 - va_start(args, fmt);
69592 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69593 - va_end(args);
69594 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69595 if (ret >= MODULE_NAME_LEN)
69596 return -ENAMETOOLONG;
69597
69598 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69599 if (ret)
69600 return ret;
69601
69602 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69603 + if (!current_uid()) {
69604 + /* hack to workaround consolekit/udisks stupidity */
69605 + read_lock(&tasklist_lock);
69606 + if (!strcmp(current->comm, "mount") &&
69607 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69608 + read_unlock(&tasklist_lock);
69609 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69610 + return -EPERM;
69611 + }
69612 + read_unlock(&tasklist_lock);
69613 + }
69614 +#endif
69615 +
69616 /* If modprobe needs a service that is in a module, we get a recursive
69617 * loop. Limit the number of running kmod threads to max_threads/2 or
69618 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69619 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69620
69621 trace_module_request(module_name, wait, _RET_IP_);
69622
69623 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69624 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69625
69626 atomic_dec(&kmod_concurrent);
69627 return ret;
69628 }
69629 +
69630 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69631 +{
69632 + va_list args;
69633 + int ret;
69634 +
69635 + va_start(args, fmt);
69636 + ret = ____request_module(wait, module_param, fmt, args);
69637 + va_end(args);
69638 +
69639 + return ret;
69640 +}
69641 +
69642 +int __request_module(bool wait, const char *fmt, ...)
69643 +{
69644 + va_list args;
69645 + int ret;
69646 +
69647 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69648 + if (current_uid()) {
69649 + char module_param[MODULE_NAME_LEN];
69650 +
69651 + memset(module_param, 0, sizeof(module_param));
69652 +
69653 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69654 +
69655 + va_start(args, fmt);
69656 + ret = ____request_module(wait, module_param, fmt, args);
69657 + va_end(args);
69658 +
69659 + return ret;
69660 + }
69661 +#endif
69662 +
69663 + va_start(args, fmt);
69664 + ret = ____request_module(wait, NULL, fmt, args);
69665 + va_end(args);
69666 +
69667 + return ret;
69668 +}
69669 +
69670 EXPORT_SYMBOL(__request_module);
69671 #endif /* CONFIG_MODULES */
69672
69673 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69674 *
69675 * Thus the __user pointer cast is valid here.
69676 */
69677 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
69678 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69679
69680 /*
69681 * If ret is 0, either ____call_usermodehelper failed and the
69682 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69683 index 098f396..fe85ff1 100644
69684 --- a/kernel/kprobes.c
69685 +++ b/kernel/kprobes.c
69686 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69687 * kernel image and loaded module images reside. This is required
69688 * so x86_64 can correctly handle the %rip-relative fixups.
69689 */
69690 - kip->insns = module_alloc(PAGE_SIZE);
69691 + kip->insns = module_alloc_exec(PAGE_SIZE);
69692 if (!kip->insns) {
69693 kfree(kip);
69694 return NULL;
69695 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69696 */
69697 if (!list_is_singular(&kip->list)) {
69698 list_del(&kip->list);
69699 - module_free(NULL, kip->insns);
69700 + module_free_exec(NULL, kip->insns);
69701 kfree(kip);
69702 }
69703 return 1;
69704 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
69705 {
69706 int i, err = 0;
69707 unsigned long offset = 0, size = 0;
69708 - char *modname, namebuf[128];
69709 + char *modname, namebuf[KSYM_NAME_LEN];
69710 const char *symbol_name;
69711 void *addr;
69712 struct kprobe_blackpoint *kb;
69713 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
69714 kprobe_type = "k";
69715
69716 if (sym)
69717 - seq_printf(pi, "%p %s %s+0x%x %s ",
69718 + seq_printf(pi, "%pK %s %s+0x%x %s ",
69719 p->addr, kprobe_type, sym, offset,
69720 (modname ? modname : " "));
69721 else
69722 - seq_printf(pi, "%p %s %p ",
69723 + seq_printf(pi, "%pK %s %pK ",
69724 p->addr, kprobe_type, p->addr);
69725
69726 if (!pp)
69727 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
69728 const char *sym = NULL;
69729 unsigned int i = *(loff_t *) v;
69730 unsigned long offset = 0;
69731 - char *modname, namebuf[128];
69732 + char *modname, namebuf[KSYM_NAME_LEN];
69733
69734 head = &kprobe_table[i];
69735 preempt_disable();
69736 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
69737 index 4e316e1..5501eef 100644
69738 --- a/kernel/ksysfs.c
69739 +++ b/kernel/ksysfs.c
69740 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
69741 {
69742 if (count+1 > UEVENT_HELPER_PATH_LEN)
69743 return -ENOENT;
69744 + if (!capable(CAP_SYS_ADMIN))
69745 + return -EPERM;
69746 memcpy(uevent_helper, buf, count);
69747 uevent_helper[count] = '\0';
69748 if (count && uevent_helper[count-1] == '\n')
69749 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
69750 index 7981e5b..7f2105c 100644
69751 --- a/kernel/lockdep.c
69752 +++ b/kernel/lockdep.c
69753 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
69754 end = (unsigned long) &_end,
69755 addr = (unsigned long) obj;
69756
69757 +#ifdef CONFIG_PAX_KERNEXEC
69758 + start = ktla_ktva(start);
69759 +#endif
69760 +
69761 /*
69762 * static variable?
69763 */
69764 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
69765 if (!static_obj(lock->key)) {
69766 debug_locks_off();
69767 printk("INFO: trying to register non-static key.\n");
69768 + printk("lock:%pS key:%pS.\n", lock, lock->key);
69769 printk("the code is fine but needs lockdep annotation.\n");
69770 printk("turning off the locking correctness validator.\n");
69771 dump_stack();
69772 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
69773 if (!class)
69774 return 0;
69775 }
69776 - atomic_inc((atomic_t *)&class->ops);
69777 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
69778 if (very_verbose(class)) {
69779 printk("\nacquire class [%p] %s", class->key, class->name);
69780 if (class->name_version > 1)
69781 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
69782 index 91c32a0..7b88d63 100644
69783 --- a/kernel/lockdep_proc.c
69784 +++ b/kernel/lockdep_proc.c
69785 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
69786
69787 static void print_name(struct seq_file *m, struct lock_class *class)
69788 {
69789 - char str[128];
69790 + char str[KSYM_NAME_LEN];
69791 const char *name = class->name;
69792
69793 if (!name) {
69794 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
69795 return 0;
69796 }
69797
69798 - seq_printf(m, "%p", class->key);
69799 + seq_printf(m, "%pK", class->key);
69800 #ifdef CONFIG_DEBUG_LOCKDEP
69801 seq_printf(m, " OPS:%8ld", class->ops);
69802 #endif
69803 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
69804
69805 list_for_each_entry(entry, &class->locks_after, entry) {
69806 if (entry->distance == 1) {
69807 - seq_printf(m, " -> [%p] ", entry->class->key);
69808 + seq_printf(m, " -> [%pK] ", entry->class->key);
69809 print_name(m, entry->class);
69810 seq_puts(m, "\n");
69811 }
69812 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
69813 if (!class->key)
69814 continue;
69815
69816 - seq_printf(m, "[%p] ", class->key);
69817 + seq_printf(m, "[%pK] ", class->key);
69818 print_name(m, class);
69819 seq_puts(m, "\n");
69820 }
69821 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69822 if (!i)
69823 seq_line(m, '-', 40-namelen, namelen);
69824
69825 - snprintf(ip, sizeof(ip), "[<%p>]",
69826 + snprintf(ip, sizeof(ip), "[<%pK>]",
69827 (void *)class->contention_point[i]);
69828 seq_printf(m, "%40s %14lu %29s %pS\n",
69829 name, stats->contention_point[i],
69830 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69831 if (!i)
69832 seq_line(m, '-', 40-namelen, namelen);
69833
69834 - snprintf(ip, sizeof(ip), "[<%p>]",
69835 + snprintf(ip, sizeof(ip), "[<%pK>]",
69836 (void *)class->contending_point[i]);
69837 seq_printf(m, "%40s %14lu %29s %pS\n",
69838 name, stats->contending_point[i],
69839 diff --git a/kernel/module.c b/kernel/module.c
69840 index 3e544f4..096cb73 100644
69841 --- a/kernel/module.c
69842 +++ b/kernel/module.c
69843 @@ -59,6 +59,7 @@
69844 #include <linux/pfn.h>
69845 #include <linux/bsearch.h>
69846 #include <linux/fips.h>
69847 +#include <linux/grsecurity.h>
69848 #include "module-internal.h"
69849
69850 #define CREATE_TRACE_POINTS
69851 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
69852
69853 /* Bounds of module allocation, for speeding __module_address.
69854 * Protected by module_mutex. */
69855 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
69856 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
69857 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
69858
69859 int register_module_notifier(struct notifier_block * nb)
69860 {
69861 @@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69862 return true;
69863
69864 list_for_each_entry_rcu(mod, &modules, list) {
69865 - struct symsearch arr[] = {
69866 + struct symsearch modarr[] = {
69867 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
69868 NOT_GPL_ONLY, false },
69869 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
69870 @@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69871 if (mod->state == MODULE_STATE_UNFORMED)
69872 continue;
69873
69874 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
69875 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
69876 return true;
69877 }
69878 return false;
69879 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
69880 static int percpu_modalloc(struct module *mod,
69881 unsigned long size, unsigned long align)
69882 {
69883 - if (align > PAGE_SIZE) {
69884 + if (align-1 >= PAGE_SIZE) {
69885 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
69886 mod->name, align, PAGE_SIZE);
69887 align = PAGE_SIZE;
69888 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
69889 static ssize_t show_coresize(struct module_attribute *mattr,
69890 struct module_kobject *mk, char *buffer)
69891 {
69892 - return sprintf(buffer, "%u\n", mk->mod->core_size);
69893 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
69894 }
69895
69896 static struct module_attribute modinfo_coresize =
69897 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
69898 static ssize_t show_initsize(struct module_attribute *mattr,
69899 struct module_kobject *mk, char *buffer)
69900 {
69901 - return sprintf(buffer, "%u\n", mk->mod->init_size);
69902 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
69903 }
69904
69905 static struct module_attribute modinfo_initsize =
69906 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
69907 */
69908 #ifdef CONFIG_SYSFS
69909
69910 -#ifdef CONFIG_KALLSYMS
69911 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69912 static inline bool sect_empty(const Elf_Shdr *sect)
69913 {
69914 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
69915 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
69916
69917 static void unset_module_core_ro_nx(struct module *mod)
69918 {
69919 - set_page_attributes(mod->module_core + mod->core_text_size,
69920 - mod->module_core + mod->core_size,
69921 + set_page_attributes(mod->module_core_rw,
69922 + mod->module_core_rw + mod->core_size_rw,
69923 set_memory_x);
69924 - set_page_attributes(mod->module_core,
69925 - mod->module_core + mod->core_ro_size,
69926 + set_page_attributes(mod->module_core_rx,
69927 + mod->module_core_rx + mod->core_size_rx,
69928 set_memory_rw);
69929 }
69930
69931 static void unset_module_init_ro_nx(struct module *mod)
69932 {
69933 - set_page_attributes(mod->module_init + mod->init_text_size,
69934 - mod->module_init + mod->init_size,
69935 + set_page_attributes(mod->module_init_rw,
69936 + mod->module_init_rw + mod->init_size_rw,
69937 set_memory_x);
69938 - set_page_attributes(mod->module_init,
69939 - mod->module_init + mod->init_ro_size,
69940 + set_page_attributes(mod->module_init_rx,
69941 + mod->module_init_rx + mod->init_size_rx,
69942 set_memory_rw);
69943 }
69944
69945 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
69946 list_for_each_entry_rcu(mod, &modules, list) {
69947 if (mod->state == MODULE_STATE_UNFORMED)
69948 continue;
69949 - if ((mod->module_core) && (mod->core_text_size)) {
69950 - set_page_attributes(mod->module_core,
69951 - mod->module_core + mod->core_text_size,
69952 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
69953 + set_page_attributes(mod->module_core_rx,
69954 + mod->module_core_rx + mod->core_size_rx,
69955 set_memory_rw);
69956 }
69957 - if ((mod->module_init) && (mod->init_text_size)) {
69958 - set_page_attributes(mod->module_init,
69959 - mod->module_init + mod->init_text_size,
69960 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
69961 + set_page_attributes(mod->module_init_rx,
69962 + mod->module_init_rx + mod->init_size_rx,
69963 set_memory_rw);
69964 }
69965 }
69966 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
69967 list_for_each_entry_rcu(mod, &modules, list) {
69968 if (mod->state == MODULE_STATE_UNFORMED)
69969 continue;
69970 - if ((mod->module_core) && (mod->core_text_size)) {
69971 - set_page_attributes(mod->module_core,
69972 - mod->module_core + mod->core_text_size,
69973 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
69974 + set_page_attributes(mod->module_core_rx,
69975 + mod->module_core_rx + mod->core_size_rx,
69976 set_memory_ro);
69977 }
69978 - if ((mod->module_init) && (mod->init_text_size)) {
69979 - set_page_attributes(mod->module_init,
69980 - mod->module_init + mod->init_text_size,
69981 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
69982 + set_page_attributes(mod->module_init_rx,
69983 + mod->module_init_rx + mod->init_size_rx,
69984 set_memory_ro);
69985 }
69986 }
69987 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
69988
69989 /* This may be NULL, but that's OK */
69990 unset_module_init_ro_nx(mod);
69991 - module_free(mod, mod->module_init);
69992 + module_free(mod, mod->module_init_rw);
69993 + module_free_exec(mod, mod->module_init_rx);
69994 kfree(mod->args);
69995 percpu_modfree(mod);
69996
69997 /* Free lock-classes: */
69998 - lockdep_free_key_range(mod->module_core, mod->core_size);
69999 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70000 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70001
70002 /* Finally, free the core (containing the module structure) */
70003 unset_module_core_ro_nx(mod);
70004 - module_free(mod, mod->module_core);
70005 + module_free_exec(mod, mod->module_core_rx);
70006 + module_free(mod, mod->module_core_rw);
70007
70008 #ifdef CONFIG_MPU
70009 update_protections(current->mm);
70010 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70011 int ret = 0;
70012 const struct kernel_symbol *ksym;
70013
70014 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70015 + int is_fs_load = 0;
70016 + int register_filesystem_found = 0;
70017 + char *p;
70018 +
70019 + p = strstr(mod->args, "grsec_modharden_fs");
70020 + if (p) {
70021 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70022 + /* copy \0 as well */
70023 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70024 + is_fs_load = 1;
70025 + }
70026 +#endif
70027 +
70028 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70029 const char *name = info->strtab + sym[i].st_name;
70030
70031 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70032 + /* it's a real shame this will never get ripped and copied
70033 + upstream! ;(
70034 + */
70035 + if (is_fs_load && !strcmp(name, "register_filesystem"))
70036 + register_filesystem_found = 1;
70037 +#endif
70038 +
70039 switch (sym[i].st_shndx) {
70040 case SHN_COMMON:
70041 /* We compiled with -fno-common. These are not
70042 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70043 ksym = resolve_symbol_wait(mod, info, name);
70044 /* Ok if resolved. */
70045 if (ksym && !IS_ERR(ksym)) {
70046 + pax_open_kernel();
70047 sym[i].st_value = ksym->value;
70048 + pax_close_kernel();
70049 break;
70050 }
70051
70052 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70053 secbase = (unsigned long)mod_percpu(mod);
70054 else
70055 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70056 + pax_open_kernel();
70057 sym[i].st_value += secbase;
70058 + pax_close_kernel();
70059 break;
70060 }
70061 }
70062
70063 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70064 + if (is_fs_load && !register_filesystem_found) {
70065 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70066 + ret = -EPERM;
70067 + }
70068 +#endif
70069 +
70070 return ret;
70071 }
70072
70073 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70074 || s->sh_entsize != ~0UL
70075 || strstarts(sname, ".init"))
70076 continue;
70077 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70078 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70079 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70080 + else
70081 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70082 pr_debug("\t%s\n", sname);
70083 }
70084 - switch (m) {
70085 - case 0: /* executable */
70086 - mod->core_size = debug_align(mod->core_size);
70087 - mod->core_text_size = mod->core_size;
70088 - break;
70089 - case 1: /* RO: text and ro-data */
70090 - mod->core_size = debug_align(mod->core_size);
70091 - mod->core_ro_size = mod->core_size;
70092 - break;
70093 - case 3: /* whole core */
70094 - mod->core_size = debug_align(mod->core_size);
70095 - break;
70096 - }
70097 }
70098
70099 pr_debug("Init section allocation order:\n");
70100 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70101 || s->sh_entsize != ~0UL
70102 || !strstarts(sname, ".init"))
70103 continue;
70104 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70105 - | INIT_OFFSET_MASK);
70106 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70107 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70108 + else
70109 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70110 + s->sh_entsize |= INIT_OFFSET_MASK;
70111 pr_debug("\t%s\n", sname);
70112 }
70113 - switch (m) {
70114 - case 0: /* executable */
70115 - mod->init_size = debug_align(mod->init_size);
70116 - mod->init_text_size = mod->init_size;
70117 - break;
70118 - case 1: /* RO: text and ro-data */
70119 - mod->init_size = debug_align(mod->init_size);
70120 - mod->init_ro_size = mod->init_size;
70121 - break;
70122 - case 3: /* whole init */
70123 - mod->init_size = debug_align(mod->init_size);
70124 - break;
70125 - }
70126 }
70127 }
70128
70129 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70130
70131 /* Put symbol section at end of init part of module. */
70132 symsect->sh_flags |= SHF_ALLOC;
70133 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70134 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70135 info->index.sym) | INIT_OFFSET_MASK;
70136 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70137
70138 @@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70139 }
70140
70141 /* Append room for core symbols at end of core part. */
70142 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70143 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70144 - mod->core_size += strtab_size;
70145 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70146 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70147 + mod->core_size_rx += strtab_size;
70148
70149 /* Put string table section at end of init part of module. */
70150 strsect->sh_flags |= SHF_ALLOC;
70151 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70152 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70153 info->index.str) | INIT_OFFSET_MASK;
70154 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70155 }
70156 @@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70157 /* Make sure we get permanent strtab: don't use info->strtab. */
70158 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70159
70160 + pax_open_kernel();
70161 +
70162 /* Set types up while we still have access to sections. */
70163 for (i = 0; i < mod->num_symtab; i++)
70164 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70165
70166 - mod->core_symtab = dst = mod->module_core + info->symoffs;
70167 - mod->core_strtab = s = mod->module_core + info->stroffs;
70168 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70169 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70170 src = mod->symtab;
70171 *s++ = 0;
70172 for (ndst = i = 0; i < mod->num_symtab; i++) {
70173 @@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70174 }
70175 }
70176 mod->core_num_syms = ndst;
70177 +
70178 + pax_close_kernel();
70179 }
70180 #else
70181 static inline void layout_symtab(struct module *mod, struct load_info *info)
70182 @@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70183 return size == 0 ? NULL : vmalloc_exec(size);
70184 }
70185
70186 -static void *module_alloc_update_bounds(unsigned long size)
70187 +static void *module_alloc_update_bounds_rw(unsigned long size)
70188 {
70189 void *ret = module_alloc(size);
70190
70191 if (ret) {
70192 mutex_lock(&module_mutex);
70193 /* Update module bounds. */
70194 - if ((unsigned long)ret < module_addr_min)
70195 - module_addr_min = (unsigned long)ret;
70196 - if ((unsigned long)ret + size > module_addr_max)
70197 - module_addr_max = (unsigned long)ret + size;
70198 + if ((unsigned long)ret < module_addr_min_rw)
70199 + module_addr_min_rw = (unsigned long)ret;
70200 + if ((unsigned long)ret + size > module_addr_max_rw)
70201 + module_addr_max_rw = (unsigned long)ret + size;
70202 + mutex_unlock(&module_mutex);
70203 + }
70204 + return ret;
70205 +}
70206 +
70207 +static void *module_alloc_update_bounds_rx(unsigned long size)
70208 +{
70209 + void *ret = module_alloc_exec(size);
70210 +
70211 + if (ret) {
70212 + mutex_lock(&module_mutex);
70213 + /* Update module bounds. */
70214 + if ((unsigned long)ret < module_addr_min_rx)
70215 + module_addr_min_rx = (unsigned long)ret;
70216 + if ((unsigned long)ret + size > module_addr_max_rx)
70217 + module_addr_max_rx = (unsigned long)ret + size;
70218 mutex_unlock(&module_mutex);
70219 }
70220 return ret;
70221 @@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70222 static int check_modinfo(struct module *mod, struct load_info *info)
70223 {
70224 const char *modmagic = get_modinfo(info, "vermagic");
70225 + const char *license = get_modinfo(info, "license");
70226 int err;
70227
70228 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70229 + if (!license || !license_is_gpl_compatible(license))
70230 + return -ENOEXEC;
70231 +#endif
70232 +
70233 /* This is allowed: modprobe --force will invalidate it. */
70234 if (!modmagic) {
70235 err = try_to_force_load(mod, "bad vermagic");
70236 @@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70237 }
70238
70239 /* Set up license info based on the info section */
70240 - set_license(mod, get_modinfo(info, "license"));
70241 + set_license(mod, license);
70242
70243 return 0;
70244 }
70245 @@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70246 void *ptr;
70247
70248 /* Do the allocs. */
70249 - ptr = module_alloc_update_bounds(mod->core_size);
70250 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70251 /*
70252 * The pointer to this block is stored in the module structure
70253 * which is inside the block. Just mark it as not being a
70254 @@ -2758,23 +2802,50 @@ static int move_module(struct module *mod, struct load_info *info)
70255 if (!ptr)
70256 return -ENOMEM;
70257
70258 - memset(ptr, 0, mod->core_size);
70259 - mod->module_core = ptr;
70260 + memset(ptr, 0, mod->core_size_rw);
70261 + mod->module_core_rw = ptr;
70262
70263 - ptr = module_alloc_update_bounds(mod->init_size);
70264 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70265 /*
70266 * The pointer to this block is stored in the module structure
70267 * which is inside the block. This block doesn't need to be
70268 * scanned as it contains data and code that will be freed
70269 * after the module is initialized.
70270 */
70271 - kmemleak_ignore(ptr);
70272 - if (!ptr && mod->init_size) {
70273 - module_free(mod, mod->module_core);
70274 + kmemleak_not_leak(ptr);
70275 + if (!ptr && mod->init_size_rw) {
70276 + module_free(mod, mod->module_core_rw);
70277 return -ENOMEM;
70278 }
70279 - memset(ptr, 0, mod->init_size);
70280 - mod->module_init = ptr;
70281 + memset(ptr, 0, mod->init_size_rw);
70282 + mod->module_init_rw = ptr;
70283 +
70284 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70285 + kmemleak_not_leak(ptr);
70286 + if (!ptr) {
70287 + module_free(mod, mod->module_init_rw);
70288 + module_free(mod, mod->module_core_rw);
70289 + return -ENOMEM;
70290 + }
70291 +
70292 + pax_open_kernel();
70293 + memset(ptr, 0, mod->core_size_rx);
70294 + pax_close_kernel();
70295 + mod->module_core_rx = ptr;
70296 +
70297 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70298 + kmemleak_not_leak(ptr);
70299 + if (!ptr && mod->init_size_rx) {
70300 + module_free_exec(mod, mod->module_core_rx);
70301 + module_free(mod, mod->module_init_rw);
70302 + module_free(mod, mod->module_core_rw);
70303 + return -ENOMEM;
70304 + }
70305 +
70306 + pax_open_kernel();
70307 + memset(ptr, 0, mod->init_size_rx);
70308 + pax_close_kernel();
70309 + mod->module_init_rx = ptr;
70310
70311 /* Transfer each section which specifies SHF_ALLOC */
70312 pr_debug("final section addresses:\n");
70313 @@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70314 if (!(shdr->sh_flags & SHF_ALLOC))
70315 continue;
70316
70317 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
70318 - dest = mod->module_init
70319 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70320 - else
70321 - dest = mod->module_core + shdr->sh_entsize;
70322 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70323 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70324 + dest = mod->module_init_rw
70325 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70326 + else
70327 + dest = mod->module_init_rx
70328 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70329 + } else {
70330 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70331 + dest = mod->module_core_rw + shdr->sh_entsize;
70332 + else
70333 + dest = mod->module_core_rx + shdr->sh_entsize;
70334 + }
70335 +
70336 + if (shdr->sh_type != SHT_NOBITS) {
70337 +
70338 +#ifdef CONFIG_PAX_KERNEXEC
70339 +#ifdef CONFIG_X86_64
70340 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70341 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70342 +#endif
70343 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70344 + pax_open_kernel();
70345 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70346 + pax_close_kernel();
70347 + } else
70348 +#endif
70349
70350 - if (shdr->sh_type != SHT_NOBITS)
70351 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70352 + }
70353 /* Update sh_addr to point to copy in image. */
70354 - shdr->sh_addr = (unsigned long)dest;
70355 +
70356 +#ifdef CONFIG_PAX_KERNEXEC
70357 + if (shdr->sh_flags & SHF_EXECINSTR)
70358 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
70359 + else
70360 +#endif
70361 +
70362 + shdr->sh_addr = (unsigned long)dest;
70363 pr_debug("\t0x%lx %s\n",
70364 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70365 }
70366 @@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70367 * Do it before processing of module parameters, so the module
70368 * can provide parameter accessor functions of its own.
70369 */
70370 - if (mod->module_init)
70371 - flush_icache_range((unsigned long)mod->module_init,
70372 - (unsigned long)mod->module_init
70373 - + mod->init_size);
70374 - flush_icache_range((unsigned long)mod->module_core,
70375 - (unsigned long)mod->module_core + mod->core_size);
70376 + if (mod->module_init_rx)
70377 + flush_icache_range((unsigned long)mod->module_init_rx,
70378 + (unsigned long)mod->module_init_rx
70379 + + mod->init_size_rx);
70380 + flush_icache_range((unsigned long)mod->module_core_rx,
70381 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
70382
70383 set_fs(old_fs);
70384 }
70385 @@ -2924,8 +3024,10 @@ out:
70386 static void module_deallocate(struct module *mod, struct load_info *info)
70387 {
70388 percpu_modfree(mod);
70389 - module_free(mod, mod->module_init);
70390 - module_free(mod, mod->module_core);
70391 + module_free_exec(mod, mod->module_init_rx);
70392 + module_free_exec(mod, mod->module_core_rx);
70393 + module_free(mod, mod->module_init_rw);
70394 + module_free(mod, mod->module_core_rw);
70395 }
70396
70397 int __weak module_finalize(const Elf_Ehdr *hdr,
70398 @@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70399 static int post_relocation(struct module *mod, const struct load_info *info)
70400 {
70401 /* Sort exception table now relocations are done. */
70402 + pax_open_kernel();
70403 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70404 + pax_close_kernel();
70405
70406 /* Copy relocated percpu area over. */
70407 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70408 @@ -3036,9 +3140,38 @@ again:
70409 if (err)
70410 goto free_unload;
70411
70412 + /* Now copy in args */
70413 + mod->args = strndup_user(uargs, ~0UL >> 1);
70414 + if (IS_ERR(mod->args)) {
70415 + err = PTR_ERR(mod->args);
70416 + goto free_unload;
70417 + }
70418 +
70419 /* Set up MODINFO_ATTR fields */
70420 setup_modinfo(mod, &info);
70421
70422 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70423 + {
70424 + char *p, *p2;
70425 +
70426 + if (strstr(mod->args, "grsec_modharden_netdev")) {
70427 + 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);
70428 + err = -EPERM;
70429 + goto free_modinfo;
70430 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70431 + p += sizeof("grsec_modharden_normal") - 1;
70432 + p2 = strstr(p, "_");
70433 + if (p2) {
70434 + *p2 = '\0';
70435 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70436 + *p2 = '_';
70437 + }
70438 + err = -EPERM;
70439 + goto free_modinfo;
70440 + }
70441 + }
70442 +#endif
70443 +
70444 /* Fix up syms, so that st_value is a pointer to location. */
70445 err = simplify_symbols(mod, &info);
70446 if (err < 0)
70447 @@ -3104,11 +3237,11 @@ again:
70448 mutex_unlock(&module_mutex);
70449 dynamic_debug_remove(info.debug);
70450 synchronize_sched();
70451 - kfree(mod->args);
70452 free_arch_cleanup:
70453 module_arch_cleanup(mod);
70454 free_modinfo:
70455 free_modinfo(mod);
70456 + kfree(mod->args);
70457 free_unload:
70458 module_unload_free(mod);
70459 unlink_mod:
70460 @@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70461 MODULE_STATE_COMING, mod);
70462
70463 /* Set RO and NX regions for core */
70464 - set_section_ro_nx(mod->module_core,
70465 - mod->core_text_size,
70466 - mod->core_ro_size,
70467 - mod->core_size);
70468 + set_section_ro_nx(mod->module_core_rx,
70469 + mod->core_size_rx,
70470 + mod->core_size_rx,
70471 + mod->core_size_rx);
70472
70473 /* Set RO and NX regions for init */
70474 - set_section_ro_nx(mod->module_init,
70475 - mod->init_text_size,
70476 - mod->init_ro_size,
70477 - mod->init_size);
70478 + set_section_ro_nx(mod->module_init_rx,
70479 + mod->init_size_rx,
70480 + mod->init_size_rx,
70481 + mod->init_size_rx);
70482
70483 do_mod_ctors(mod);
70484 /* Start the module */
70485 @@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70486 mod->strtab = mod->core_strtab;
70487 #endif
70488 unset_module_init_ro_nx(mod);
70489 - module_free(mod, mod->module_init);
70490 - mod->module_init = NULL;
70491 - mod->init_size = 0;
70492 - mod->init_ro_size = 0;
70493 - mod->init_text_size = 0;
70494 + module_free(mod, mod->module_init_rw);
70495 + module_free_exec(mod, mod->module_init_rx);
70496 + mod->module_init_rw = NULL;
70497 + mod->module_init_rx = NULL;
70498 + mod->init_size_rw = 0;
70499 + mod->init_size_rx = 0;
70500 mutex_unlock(&module_mutex);
70501 wake_up_all(&module_wq);
70502
70503 @@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70504 unsigned long nextval;
70505
70506 /* At worse, next value is at end of module */
70507 - if (within_module_init(addr, mod))
70508 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70509 + if (within_module_init_rx(addr, mod))
70510 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70511 + else if (within_module_init_rw(addr, mod))
70512 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70513 + else if (within_module_core_rx(addr, mod))
70514 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70515 + else if (within_module_core_rw(addr, mod))
70516 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70517 else
70518 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70519 + return NULL;
70520
70521 /* Scan for closest preceding symbol, and next symbol. (ELF
70522 starts real symbols at 1). */
70523 @@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70524 return 0;
70525
70526 seq_printf(m, "%s %u",
70527 - mod->name, mod->init_size + mod->core_size);
70528 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70529 print_unload_info(m, mod);
70530
70531 /* Informative for users. */
70532 @@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70533 mod->state == MODULE_STATE_COMING ? "Loading":
70534 "Live");
70535 /* Used by oprofile and other similar tools. */
70536 - seq_printf(m, " 0x%pK", mod->module_core);
70537 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70538
70539 /* Taints info */
70540 if (mod->taints)
70541 @@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70542
70543 static int __init proc_modules_init(void)
70544 {
70545 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70546 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70547 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70548 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70549 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70550 +#else
70551 proc_create("modules", 0, NULL, &proc_modules_operations);
70552 +#endif
70553 +#else
70554 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70555 +#endif
70556 return 0;
70557 }
70558 module_init(proc_modules_init);
70559 @@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70560 {
70561 struct module *mod;
70562
70563 - if (addr < module_addr_min || addr > module_addr_max)
70564 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70565 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70566 return NULL;
70567
70568 list_for_each_entry_rcu(mod, &modules, list) {
70569 if (mod->state == MODULE_STATE_UNFORMED)
70570 continue;
70571 - if (within_module_core(addr, mod)
70572 - || within_module_init(addr, mod))
70573 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70574 return mod;
70575 }
70576 return NULL;
70577 @@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70578 */
70579 struct module *__module_text_address(unsigned long addr)
70580 {
70581 - struct module *mod = __module_address(addr);
70582 + struct module *mod;
70583 +
70584 +#ifdef CONFIG_X86_32
70585 + addr = ktla_ktva(addr);
70586 +#endif
70587 +
70588 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70589 + return NULL;
70590 +
70591 + mod = __module_address(addr);
70592 +
70593 if (mod) {
70594 /* Make sure it's within the text section. */
70595 - if (!within(addr, mod->module_init, mod->init_text_size)
70596 - && !within(addr, mod->module_core, mod->core_text_size))
70597 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70598 mod = NULL;
70599 }
70600 return mod;
70601 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70602 index 7e3443f..b2a1e6b 100644
70603 --- a/kernel/mutex-debug.c
70604 +++ b/kernel/mutex-debug.c
70605 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70606 }
70607
70608 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70609 - struct thread_info *ti)
70610 + struct task_struct *task)
70611 {
70612 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70613
70614 /* Mark the current thread as blocked on the lock: */
70615 - ti->task->blocked_on = waiter;
70616 + task->blocked_on = waiter;
70617 }
70618
70619 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70620 - struct thread_info *ti)
70621 + struct task_struct *task)
70622 {
70623 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70624 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70625 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70626 - ti->task->blocked_on = NULL;
70627 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
70628 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70629 + task->blocked_on = NULL;
70630
70631 list_del_init(&waiter->list);
70632 waiter->task = NULL;
70633 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70634 index 0799fd3..d06ae3b 100644
70635 --- a/kernel/mutex-debug.h
70636 +++ b/kernel/mutex-debug.h
70637 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70638 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70639 extern void debug_mutex_add_waiter(struct mutex *lock,
70640 struct mutex_waiter *waiter,
70641 - struct thread_info *ti);
70642 + struct task_struct *task);
70643 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70644 - struct thread_info *ti);
70645 + struct task_struct *task);
70646 extern void debug_mutex_unlock(struct mutex *lock);
70647 extern void debug_mutex_init(struct mutex *lock, const char *name,
70648 struct lock_class_key *key);
70649 diff --git a/kernel/mutex.c b/kernel/mutex.c
70650 index a307cc9..27fd2e9 100644
70651 --- a/kernel/mutex.c
70652 +++ b/kernel/mutex.c
70653 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70654 spin_lock_mutex(&lock->wait_lock, flags);
70655
70656 debug_mutex_lock_common(lock, &waiter);
70657 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70658 + debug_mutex_add_waiter(lock, &waiter, task);
70659
70660 /* add waiting tasks to the end of the waitqueue (FIFO): */
70661 list_add_tail(&waiter.list, &lock->wait_list);
70662 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70663 * TASK_UNINTERRUPTIBLE case.)
70664 */
70665 if (unlikely(signal_pending_state(state, task))) {
70666 - mutex_remove_waiter(lock, &waiter,
70667 - task_thread_info(task));
70668 + mutex_remove_waiter(lock, &waiter, task);
70669 mutex_release(&lock->dep_map, 1, ip);
70670 spin_unlock_mutex(&lock->wait_lock, flags);
70671
70672 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70673 done:
70674 lock_acquired(&lock->dep_map, ip);
70675 /* got the lock - rejoice! */
70676 - mutex_remove_waiter(lock, &waiter, current_thread_info());
70677 + mutex_remove_waiter(lock, &waiter, task);
70678 mutex_set_owner(lock);
70679
70680 /* set it to 0 if there are no waiters left: */
70681 diff --git a/kernel/notifier.c b/kernel/notifier.c
70682 index 2d5cc4c..d9ea600 100644
70683 --- a/kernel/notifier.c
70684 +++ b/kernel/notifier.c
70685 @@ -5,6 +5,7 @@
70686 #include <linux/rcupdate.h>
70687 #include <linux/vmalloc.h>
70688 #include <linux/reboot.h>
70689 +#include <linux/mm.h>
70690
70691 /*
70692 * Notifier list for kernel code which wants to be called
70693 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70694 while ((*nl) != NULL) {
70695 if (n->priority > (*nl)->priority)
70696 break;
70697 - nl = &((*nl)->next);
70698 + nl = (struct notifier_block **)&((*nl)->next);
70699 }
70700 - n->next = *nl;
70701 + pax_open_kernel();
70702 + *(const void **)&n->next = *nl;
70703 rcu_assign_pointer(*nl, n);
70704 + pax_close_kernel();
70705 return 0;
70706 }
70707
70708 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
70709 return 0;
70710 if (n->priority > (*nl)->priority)
70711 break;
70712 - nl = &((*nl)->next);
70713 + nl = (struct notifier_block **)&((*nl)->next);
70714 }
70715 - n->next = *nl;
70716 + pax_open_kernel();
70717 + *(const void **)&n->next = *nl;
70718 rcu_assign_pointer(*nl, n);
70719 + pax_close_kernel();
70720 return 0;
70721 }
70722
70723 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
70724 {
70725 while ((*nl) != NULL) {
70726 if ((*nl) == n) {
70727 + pax_open_kernel();
70728 rcu_assign_pointer(*nl, n->next);
70729 + pax_close_kernel();
70730 return 0;
70731 }
70732 - nl = &((*nl)->next);
70733 + nl = (struct notifier_block **)&((*nl)->next);
70734 }
70735 return -ENOENT;
70736 }
70737 diff --git a/kernel/panic.c b/kernel/panic.c
70738 index e1b2822..5edc1d9 100644
70739 --- a/kernel/panic.c
70740 +++ b/kernel/panic.c
70741 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
70742 const char *board;
70743
70744 printk(KERN_WARNING "------------[ cut here ]------------\n");
70745 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
70746 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
70747 board = dmi_get_system_info(DMI_PRODUCT_NAME);
70748 if (board)
70749 printk(KERN_WARNING "Hardware name: %s\n", board);
70750 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
70751 */
70752 void __stack_chk_fail(void)
70753 {
70754 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
70755 + dump_stack();
70756 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
70757 __builtin_return_address(0));
70758 }
70759 EXPORT_SYMBOL(__stack_chk_fail);
70760 diff --git a/kernel/pid.c b/kernel/pid.c
70761 index aebd4f5..1693c13 100644
70762 --- a/kernel/pid.c
70763 +++ b/kernel/pid.c
70764 @@ -33,6 +33,7 @@
70765 #include <linux/rculist.h>
70766 #include <linux/bootmem.h>
70767 #include <linux/hash.h>
70768 +#include <linux/security.h>
70769 #include <linux/pid_namespace.h>
70770 #include <linux/init_task.h>
70771 #include <linux/syscalls.h>
70772 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
70773
70774 int pid_max = PID_MAX_DEFAULT;
70775
70776 -#define RESERVED_PIDS 300
70777 +#define RESERVED_PIDS 500
70778
70779 int pid_max_min = RESERVED_PIDS + 1;
70780 int pid_max_max = PID_MAX_LIMIT;
70781 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
70782 */
70783 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
70784 {
70785 + struct task_struct *task;
70786 +
70787 rcu_lockdep_assert(rcu_read_lock_held(),
70788 "find_task_by_pid_ns() needs rcu_read_lock()"
70789 " protection");
70790 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70791 +
70792 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70793 +
70794 + if (gr_pid_is_chrooted(task))
70795 + return NULL;
70796 +
70797 + return task;
70798 }
70799
70800 struct task_struct *find_task_by_vpid(pid_t vnr)
70801 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
70802 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
70803 }
70804
70805 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
70806 +{
70807 + rcu_lockdep_assert(rcu_read_lock_held(),
70808 + "find_task_by_pid_ns() needs rcu_read_lock()"
70809 + " protection");
70810 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
70811 +}
70812 +
70813 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
70814 {
70815 struct pid *pid;
70816 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
70817 index 125cb67..2e5c8ad 100644
70818 --- a/kernel/posix-cpu-timers.c
70819 +++ b/kernel/posix-cpu-timers.c
70820 @@ -6,9 +6,11 @@
70821 #include <linux/posix-timers.h>
70822 #include <linux/errno.h>
70823 #include <linux/math64.h>
70824 +#include <linux/security.h>
70825 #include <asm/uaccess.h>
70826 #include <linux/kernel_stat.h>
70827 #include <trace/events/timer.h>
70828 +#include <linux/random.h>
70829
70830 /*
70831 * Called after updating RLIMIT_CPU to run cpu timer and update
70832 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
70833 */
70834 void posix_cpu_timers_exit(struct task_struct *tsk)
70835 {
70836 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
70837 + sizeof(unsigned long long));
70838 cleanup_timers(tsk->cpu_timers,
70839 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
70840
70841 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
70842
70843 static __init int init_posix_cpu_timers(void)
70844 {
70845 - struct k_clock process = {
70846 + static struct k_clock process = {
70847 .clock_getres = process_cpu_clock_getres,
70848 .clock_get = process_cpu_clock_get,
70849 .timer_create = process_cpu_timer_create,
70850 .nsleep = process_cpu_nsleep,
70851 .nsleep_restart = process_cpu_nsleep_restart,
70852 };
70853 - struct k_clock thread = {
70854 + static struct k_clock thread = {
70855 .clock_getres = thread_cpu_clock_getres,
70856 .clock_get = thread_cpu_clock_get,
70857 .timer_create = thread_cpu_timer_create,
70858 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
70859 index 69185ae..cc2847a 100644
70860 --- a/kernel/posix-timers.c
70861 +++ b/kernel/posix-timers.c
70862 @@ -43,6 +43,7 @@
70863 #include <linux/idr.h>
70864 #include <linux/posix-clock.h>
70865 #include <linux/posix-timers.h>
70866 +#include <linux/grsecurity.h>
70867 #include <linux/syscalls.h>
70868 #include <linux/wait.h>
70869 #include <linux/workqueue.h>
70870 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
70871 * which we beg off on and pass to do_sys_settimeofday().
70872 */
70873
70874 -static struct k_clock posix_clocks[MAX_CLOCKS];
70875 +static struct k_clock *posix_clocks[MAX_CLOCKS];
70876
70877 /*
70878 * These ones are defined below.
70879 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
70880 */
70881 static __init int init_posix_timers(void)
70882 {
70883 - struct k_clock clock_realtime = {
70884 + static struct k_clock clock_realtime = {
70885 .clock_getres = hrtimer_get_res,
70886 .clock_get = posix_clock_realtime_get,
70887 .clock_set = posix_clock_realtime_set,
70888 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
70889 .timer_get = common_timer_get,
70890 .timer_del = common_timer_del,
70891 };
70892 - struct k_clock clock_monotonic = {
70893 + static struct k_clock clock_monotonic = {
70894 .clock_getres = hrtimer_get_res,
70895 .clock_get = posix_ktime_get_ts,
70896 .nsleep = common_nsleep,
70897 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
70898 .timer_get = common_timer_get,
70899 .timer_del = common_timer_del,
70900 };
70901 - struct k_clock clock_monotonic_raw = {
70902 + static struct k_clock clock_monotonic_raw = {
70903 .clock_getres = hrtimer_get_res,
70904 .clock_get = posix_get_monotonic_raw,
70905 };
70906 - struct k_clock clock_realtime_coarse = {
70907 + static struct k_clock clock_realtime_coarse = {
70908 .clock_getres = posix_get_coarse_res,
70909 .clock_get = posix_get_realtime_coarse,
70910 };
70911 - struct k_clock clock_monotonic_coarse = {
70912 + static struct k_clock clock_monotonic_coarse = {
70913 .clock_getres = posix_get_coarse_res,
70914 .clock_get = posix_get_monotonic_coarse,
70915 };
70916 - struct k_clock clock_boottime = {
70917 + static struct k_clock clock_boottime = {
70918 .clock_getres = hrtimer_get_res,
70919 .clock_get = posix_get_boottime,
70920 .nsleep = common_nsleep,
70921 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
70922 return;
70923 }
70924
70925 - posix_clocks[clock_id] = *new_clock;
70926 + posix_clocks[clock_id] = new_clock;
70927 }
70928 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
70929
70930 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
70931 return (id & CLOCKFD_MASK) == CLOCKFD ?
70932 &clock_posix_dynamic : &clock_posix_cpu;
70933
70934 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
70935 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
70936 return NULL;
70937 - return &posix_clocks[id];
70938 + return posix_clocks[id];
70939 }
70940
70941 static int common_timer_create(struct k_itimer *new_timer)
70942 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
70943 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
70944 return -EFAULT;
70945
70946 + /* only the CLOCK_REALTIME clock can be set, all other clocks
70947 + have their clock_set fptr set to a nosettime dummy function
70948 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
70949 + call common_clock_set, which calls do_sys_settimeofday, which
70950 + we hook
70951 + */
70952 +
70953 return kc->clock_set(which_clock, &new_tp);
70954 }
70955
70956 diff --git a/kernel/power/process.c b/kernel/power/process.c
70957 index 87da817..30ddd13 100644
70958 --- a/kernel/power/process.c
70959 +++ b/kernel/power/process.c
70960 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
70961 u64 elapsed_csecs64;
70962 unsigned int elapsed_csecs;
70963 bool wakeup = false;
70964 + bool timedout = false;
70965
70966 do_gettimeofday(&start);
70967
70968 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
70969
70970 while (true) {
70971 todo = 0;
70972 + if (time_after(jiffies, end_time))
70973 + timedout = true;
70974 read_lock(&tasklist_lock);
70975 do_each_thread(g, p) {
70976 if (p == current || !freeze_task(p))
70977 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
70978 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
70979 * transition can't race with task state testing here.
70980 */
70981 - if (!task_is_stopped_or_traced(p) &&
70982 - !freezer_should_skip(p))
70983 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
70984 todo++;
70985 + if (timedout) {
70986 + printk(KERN_ERR "Task refusing to freeze:\n");
70987 + sched_show_task(p);
70988 + }
70989 + }
70990 } while_each_thread(g, p);
70991 read_unlock(&tasklist_lock);
70992
70993 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
70994 todo += wq_busy;
70995 }
70996
70997 - if (!todo || time_after(jiffies, end_time))
70998 + if (!todo || timedout)
70999 break;
71000
71001 if (pm_wakeup_pending()) {
71002 diff --git a/kernel/printk.c b/kernel/printk.c
71003 index f8e0b5a..dda2a5c 100644
71004 --- a/kernel/printk.c
71005 +++ b/kernel/printk.c
71006 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71007 if (from_file && type != SYSLOG_ACTION_OPEN)
71008 return 0;
71009
71010 +#ifdef CONFIG_GRKERNSEC_DMESG
71011 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71012 + return -EPERM;
71013 +#endif
71014 +
71015 if (syslog_action_restricted(type)) {
71016 if (capable(CAP_SYSLOG))
71017 return 0;
71018 diff --git a/kernel/profile.c b/kernel/profile.c
71019 index 76b8e77..a2930e8 100644
71020 --- a/kernel/profile.c
71021 +++ b/kernel/profile.c
71022 @@ -39,7 +39,7 @@ struct profile_hit {
71023 /* Oprofile timer tick hook */
71024 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71025
71026 -static atomic_t *prof_buffer;
71027 +static atomic_unchecked_t *prof_buffer;
71028 static unsigned long prof_len, prof_shift;
71029
71030 int prof_on __read_mostly;
71031 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71032 hits[i].pc = 0;
71033 continue;
71034 }
71035 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71036 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71037 hits[i].hits = hits[i].pc = 0;
71038 }
71039 }
71040 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71041 * Add the current hit(s) and flush the write-queue out
71042 * to the global buffer:
71043 */
71044 - atomic_add(nr_hits, &prof_buffer[pc]);
71045 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71046 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71047 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71048 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71049 hits[i].pc = hits[i].hits = 0;
71050 }
71051 out:
71052 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71053 {
71054 unsigned long pc;
71055 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71056 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71057 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71058 }
71059 #endif /* !CONFIG_SMP */
71060
71061 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71062 return -EFAULT;
71063 buf++; p++; count--; read++;
71064 }
71065 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71066 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71067 if (copy_to_user(buf, (void *)pnt, count))
71068 return -EFAULT;
71069 read += count;
71070 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71071 }
71072 #endif
71073 profile_discard_flip_buffers();
71074 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71075 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71076 return count;
71077 }
71078
71079 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71080 index fbea91d..9bf15e8 100644
71081 --- a/kernel/ptrace.c
71082 +++ b/kernel/ptrace.c
71083 @@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71084
71085 if (seize)
71086 flags |= PT_SEIZED;
71087 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71088 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71089 flags |= PT_PTRACE_CAP;
71090 task->ptrace = flags;
71091
71092 @@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71093 break;
71094 return -EIO;
71095 }
71096 - if (copy_to_user(dst, buf, retval))
71097 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71098 return -EFAULT;
71099 copied += retval;
71100 src += retval;
71101 @@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71102 bool seized = child->ptrace & PT_SEIZED;
71103 int ret = -EIO;
71104 siginfo_t siginfo, *si;
71105 - void __user *datavp = (void __user *) data;
71106 + void __user *datavp = (__force void __user *) data;
71107 unsigned long __user *datalp = datavp;
71108 unsigned long flags;
71109
71110 @@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71111 goto out;
71112 }
71113
71114 + if (gr_handle_ptrace(child, request)) {
71115 + ret = -EPERM;
71116 + goto out_put_task_struct;
71117 + }
71118 +
71119 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71120 ret = ptrace_attach(child, request, addr, data);
71121 /*
71122 * Some architectures need to do book-keeping after
71123 * a ptrace attach.
71124 */
71125 - if (!ret)
71126 + if (!ret) {
71127 arch_ptrace_attach(child);
71128 + gr_audit_ptrace(child);
71129 + }
71130 goto out_put_task_struct;
71131 }
71132
71133 @@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71134 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71135 if (copied != sizeof(tmp))
71136 return -EIO;
71137 - return put_user(tmp, (unsigned long __user *)data);
71138 + return put_user(tmp, (__force unsigned long __user *)data);
71139 }
71140
71141 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71142 @@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71143 goto out;
71144 }
71145
71146 + if (gr_handle_ptrace(child, request)) {
71147 + ret = -EPERM;
71148 + goto out_put_task_struct;
71149 + }
71150 +
71151 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71152 ret = ptrace_attach(child, request, addr, data);
71153 /*
71154 * Some architectures need to do book-keeping after
71155 * a ptrace attach.
71156 */
71157 - if (!ret)
71158 + if (!ret) {
71159 arch_ptrace_attach(child);
71160 + gr_audit_ptrace(child);
71161 + }
71162 goto out_put_task_struct;
71163 }
71164
71165 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71166 index e4c6a59..c86621a 100644
71167 --- a/kernel/rcutiny.c
71168 +++ b/kernel/rcutiny.c
71169 @@ -46,7 +46,7 @@
71170 struct rcu_ctrlblk;
71171 static void invoke_rcu_callbacks(void);
71172 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71173 -static void rcu_process_callbacks(struct softirq_action *unused);
71174 +static void rcu_process_callbacks(void);
71175 static void __call_rcu(struct rcu_head *head,
71176 void (*func)(struct rcu_head *rcu),
71177 struct rcu_ctrlblk *rcp);
71178 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71179 rcu_is_callbacks_kthread()));
71180 }
71181
71182 -static void rcu_process_callbacks(struct softirq_action *unused)
71183 +static void rcu_process_callbacks(void)
71184 {
71185 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71186 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71187 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71188 index 3d01902..afbf46e 100644
71189 --- a/kernel/rcutiny_plugin.h
71190 +++ b/kernel/rcutiny_plugin.h
71191 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71192 have_rcu_kthread_work = morework;
71193 local_irq_restore(flags);
71194 if (work)
71195 - rcu_process_callbacks(NULL);
71196 + rcu_process_callbacks();
71197 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71198 }
71199
71200 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71201 index aaa7b9f..055ff1e 100644
71202 --- a/kernel/rcutorture.c
71203 +++ b/kernel/rcutorture.c
71204 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71205 { 0 };
71206 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71207 { 0 };
71208 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71209 -static atomic_t n_rcu_torture_alloc;
71210 -static atomic_t n_rcu_torture_alloc_fail;
71211 -static atomic_t n_rcu_torture_free;
71212 -static atomic_t n_rcu_torture_mberror;
71213 -static atomic_t n_rcu_torture_error;
71214 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71215 +static atomic_unchecked_t n_rcu_torture_alloc;
71216 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
71217 +static atomic_unchecked_t n_rcu_torture_free;
71218 +static atomic_unchecked_t n_rcu_torture_mberror;
71219 +static atomic_unchecked_t n_rcu_torture_error;
71220 static long n_rcu_torture_barrier_error;
71221 static long n_rcu_torture_boost_ktrerror;
71222 static long n_rcu_torture_boost_rterror;
71223 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71224
71225 spin_lock_bh(&rcu_torture_lock);
71226 if (list_empty(&rcu_torture_freelist)) {
71227 - atomic_inc(&n_rcu_torture_alloc_fail);
71228 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71229 spin_unlock_bh(&rcu_torture_lock);
71230 return NULL;
71231 }
71232 - atomic_inc(&n_rcu_torture_alloc);
71233 + atomic_inc_unchecked(&n_rcu_torture_alloc);
71234 p = rcu_torture_freelist.next;
71235 list_del_init(p);
71236 spin_unlock_bh(&rcu_torture_lock);
71237 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71238 static void
71239 rcu_torture_free(struct rcu_torture *p)
71240 {
71241 - atomic_inc(&n_rcu_torture_free);
71242 + atomic_inc_unchecked(&n_rcu_torture_free);
71243 spin_lock_bh(&rcu_torture_lock);
71244 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71245 spin_unlock_bh(&rcu_torture_lock);
71246 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71247 i = rp->rtort_pipe_count;
71248 if (i > RCU_TORTURE_PIPE_LEN)
71249 i = RCU_TORTURE_PIPE_LEN;
71250 - atomic_inc(&rcu_torture_wcount[i]);
71251 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71252 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71253 rp->rtort_mbtest = 0;
71254 rcu_torture_free(rp);
71255 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71256 i = rp->rtort_pipe_count;
71257 if (i > RCU_TORTURE_PIPE_LEN)
71258 i = RCU_TORTURE_PIPE_LEN;
71259 - atomic_inc(&rcu_torture_wcount[i]);
71260 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71261 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71262 rp->rtort_mbtest = 0;
71263 list_del(&rp->rtort_free);
71264 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71265 i = old_rp->rtort_pipe_count;
71266 if (i > RCU_TORTURE_PIPE_LEN)
71267 i = RCU_TORTURE_PIPE_LEN;
71268 - atomic_inc(&rcu_torture_wcount[i]);
71269 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71270 old_rp->rtort_pipe_count++;
71271 cur_ops->deferred_free(old_rp);
71272 }
71273 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71274 }
71275 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71276 if (p->rtort_mbtest == 0)
71277 - atomic_inc(&n_rcu_torture_mberror);
71278 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71279 spin_lock(&rand_lock);
71280 cur_ops->read_delay(&rand);
71281 n_rcu_torture_timers++;
71282 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71283 }
71284 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71285 if (p->rtort_mbtest == 0)
71286 - atomic_inc(&n_rcu_torture_mberror);
71287 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71288 cur_ops->read_delay(&rand);
71289 preempt_disable();
71290 pipe_count = p->rtort_pipe_count;
71291 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71292 rcu_torture_current,
71293 rcu_torture_current_version,
71294 list_empty(&rcu_torture_freelist),
71295 - atomic_read(&n_rcu_torture_alloc),
71296 - atomic_read(&n_rcu_torture_alloc_fail),
71297 - atomic_read(&n_rcu_torture_free));
71298 + atomic_read_unchecked(&n_rcu_torture_alloc),
71299 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71300 + atomic_read_unchecked(&n_rcu_torture_free));
71301 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71302 - atomic_read(&n_rcu_torture_mberror),
71303 + atomic_read_unchecked(&n_rcu_torture_mberror),
71304 n_rcu_torture_boost_ktrerror,
71305 n_rcu_torture_boost_rterror);
71306 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71307 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71308 n_barrier_attempts,
71309 n_rcu_torture_barrier_error);
71310 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71311 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71312 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71313 n_rcu_torture_barrier_error != 0 ||
71314 n_rcu_torture_boost_ktrerror != 0 ||
71315 n_rcu_torture_boost_rterror != 0 ||
71316 n_rcu_torture_boost_failure != 0 ||
71317 i > 1) {
71318 cnt += sprintf(&page[cnt], "!!! ");
71319 - atomic_inc(&n_rcu_torture_error);
71320 + atomic_inc_unchecked(&n_rcu_torture_error);
71321 WARN_ON_ONCE(1);
71322 }
71323 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71324 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71325 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71326 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71327 cnt += sprintf(&page[cnt], " %d",
71328 - atomic_read(&rcu_torture_wcount[i]));
71329 + atomic_read_unchecked(&rcu_torture_wcount[i]));
71330 }
71331 cnt += sprintf(&page[cnt], "\n");
71332 if (cur_ops->stats)
71333 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71334
71335 if (cur_ops->cleanup)
71336 cur_ops->cleanup();
71337 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71338 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71339 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71340 else if (n_online_successes != n_online_attempts ||
71341 n_offline_successes != n_offline_attempts)
71342 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71343
71344 rcu_torture_current = NULL;
71345 rcu_torture_current_version = 0;
71346 - atomic_set(&n_rcu_torture_alloc, 0);
71347 - atomic_set(&n_rcu_torture_alloc_fail, 0);
71348 - atomic_set(&n_rcu_torture_free, 0);
71349 - atomic_set(&n_rcu_torture_mberror, 0);
71350 - atomic_set(&n_rcu_torture_error, 0);
71351 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71352 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71353 + atomic_set_unchecked(&n_rcu_torture_free, 0);
71354 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71355 + atomic_set_unchecked(&n_rcu_torture_error, 0);
71356 n_rcu_torture_barrier_error = 0;
71357 n_rcu_torture_boost_ktrerror = 0;
71358 n_rcu_torture_boost_rterror = 0;
71359 n_rcu_torture_boost_failure = 0;
71360 n_rcu_torture_boosts = 0;
71361 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71362 - atomic_set(&rcu_torture_wcount[i], 0);
71363 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71364 for_each_possible_cpu(cpu) {
71365 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71366 per_cpu(rcu_torture_count, cpu)[i] = 0;
71367 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71368 index 2682295..0f2297e 100644
71369 --- a/kernel/rcutree.c
71370 +++ b/kernel/rcutree.c
71371 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71372 rcu_prepare_for_idle(smp_processor_id());
71373 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71374 smp_mb__before_atomic_inc(); /* See above. */
71375 - atomic_inc(&rdtp->dynticks);
71376 + atomic_inc_unchecked(&rdtp->dynticks);
71377 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71378 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71379 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71380
71381 /*
71382 * It is illegal to enter an extended quiescent state while
71383 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71384 int user)
71385 {
71386 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71387 - atomic_inc(&rdtp->dynticks);
71388 + atomic_inc_unchecked(&rdtp->dynticks);
71389 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71390 smp_mb__after_atomic_inc(); /* See above. */
71391 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71392 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71393 rcu_cleanup_after_idle(smp_processor_id());
71394 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71395 if (!user && !is_idle_task(current)) {
71396 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71397 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71398
71399 if (rdtp->dynticks_nmi_nesting == 0 &&
71400 - (atomic_read(&rdtp->dynticks) & 0x1))
71401 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71402 return;
71403 rdtp->dynticks_nmi_nesting++;
71404 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71405 - atomic_inc(&rdtp->dynticks);
71406 + atomic_inc_unchecked(&rdtp->dynticks);
71407 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71408 smp_mb__after_atomic_inc(); /* See above. */
71409 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71410 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71411 }
71412
71413 /**
71414 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71415 return;
71416 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71417 smp_mb__before_atomic_inc(); /* See above. */
71418 - atomic_inc(&rdtp->dynticks);
71419 + atomic_inc_unchecked(&rdtp->dynticks);
71420 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71421 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71422 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71423 }
71424
71425 /**
71426 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71427 int ret;
71428
71429 preempt_disable();
71430 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71431 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71432 preempt_enable();
71433 return ret;
71434 }
71435 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71436 */
71437 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71438 {
71439 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71440 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71441 return (rdp->dynticks_snap & 0x1) == 0;
71442 }
71443
71444 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71445 unsigned int curr;
71446 unsigned int snap;
71447
71448 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71449 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71450 snap = (unsigned int)rdp->dynticks_snap;
71451
71452 /*
71453 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71454 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71455 */
71456 if (till_stall_check < 3) {
71457 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71458 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71459 till_stall_check = 3;
71460 } else if (till_stall_check > 300) {
71461 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71462 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71463 till_stall_check = 300;
71464 }
71465 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71466 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71467 rsp->qlen += rdp->qlen;
71468 rdp->n_cbs_orphaned += rdp->qlen;
71469 rdp->qlen_lazy = 0;
71470 - ACCESS_ONCE(rdp->qlen) = 0;
71471 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71472 }
71473
71474 /*
71475 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71476 }
71477 smp_mb(); /* List handling before counting for rcu_barrier(). */
71478 rdp->qlen_lazy -= count_lazy;
71479 - ACCESS_ONCE(rdp->qlen) -= count;
71480 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71481 rdp->n_cbs_invoked += count;
71482
71483 /* Reinstate batch limit if we have worked down the excess. */
71484 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71485 /*
71486 * Do RCU core processing for the current CPU.
71487 */
71488 -static void rcu_process_callbacks(struct softirq_action *unused)
71489 +static void rcu_process_callbacks(void)
71490 {
71491 struct rcu_state *rsp;
71492
71493 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71494 local_irq_restore(flags);
71495 return;
71496 }
71497 - ACCESS_ONCE(rdp->qlen)++;
71498 + ACCESS_ONCE_RW(rdp->qlen)++;
71499 if (lazy)
71500 rdp->qlen_lazy++;
71501 else
71502 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71503 }
71504 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71505
71506 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71507 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71508 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71509 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71510
71511 static int synchronize_sched_expedited_cpu_stop(void *data)
71512 {
71513 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71514 int firstsnap, s, snap, trycount = 0;
71515
71516 /* Note that atomic_inc_return() implies full memory barrier. */
71517 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71518 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71519 get_online_cpus();
71520 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71521
71522 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71523 }
71524
71525 /* Check to see if someone else did our work for us. */
71526 - s = atomic_read(&sync_sched_expedited_done);
71527 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71528 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71529 smp_mb(); /* ensure test happens before caller kfree */
71530 return;
71531 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71532 * grace period works for us.
71533 */
71534 get_online_cpus();
71535 - snap = atomic_read(&sync_sched_expedited_started);
71536 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71537 smp_mb(); /* ensure read is before try_stop_cpus(). */
71538 }
71539
71540 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71541 * than we did beat us to the punch.
71542 */
71543 do {
71544 - s = atomic_read(&sync_sched_expedited_done);
71545 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71546 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71547 smp_mb(); /* ensure test happens before caller kfree */
71548 break;
71549 }
71550 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71551 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71552
71553 put_online_cpus();
71554 }
71555 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71556 * ACCESS_ONCE() to prevent the compiler from speculating
71557 * the increment to precede the early-exit check.
71558 */
71559 - ACCESS_ONCE(rsp->n_barrier_done)++;
71560 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71561 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71562 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71563 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71564 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71565
71566 /* Increment ->n_barrier_done to prevent duplicate work. */
71567 smp_mb(); /* Keep increment after above mechanism. */
71568 - ACCESS_ONCE(rsp->n_barrier_done)++;
71569 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71570 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71571 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71572 smp_mb(); /* Keep increment before caller's subsequent code. */
71573 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71574 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71575 init_callback_list(rdp);
71576 rdp->qlen_lazy = 0;
71577 - ACCESS_ONCE(rdp->qlen) = 0;
71578 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71579 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71580 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71581 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71582 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71583 #ifdef CONFIG_RCU_USER_QS
71584 WARN_ON_ONCE(rdp->dynticks->in_user);
71585 #endif
71586 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71587 rdp->blimit = blimit;
71588 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71589 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71590 - atomic_set(&rdp->dynticks->dynticks,
71591 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71592 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71593 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71594 rcu_prepare_for_idle_init(cpu);
71595 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71596
71597 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71598 index a240f03..d469618 100644
71599 --- a/kernel/rcutree.h
71600 +++ b/kernel/rcutree.h
71601 @@ -86,7 +86,7 @@ struct rcu_dynticks {
71602 long long dynticks_nesting; /* Track irq/process nesting level. */
71603 /* Process level is worth LLONG_MAX/2. */
71604 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71605 - atomic_t dynticks; /* Even value for idle, else odd. */
71606 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71607 #ifdef CONFIG_RCU_FAST_NO_HZ
71608 int dyntick_drain; /* Prepare-for-idle state variable. */
71609 unsigned long dyntick_holdoff;
71610 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71611 index f921154..34c4873 100644
71612 --- a/kernel/rcutree_plugin.h
71613 +++ b/kernel/rcutree_plugin.h
71614 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71615
71616 /* Clean up and exit. */
71617 smp_mb(); /* ensure expedited GP seen before counter increment. */
71618 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71619 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71620 unlock_mb_ret:
71621 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71622 mb_ret:
71623 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71624 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71625 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71626 cpu, ticks_value, ticks_title,
71627 - atomic_read(&rdtp->dynticks) & 0xfff,
71628 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71629 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71630 fast_no_hz);
71631 }
71632 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71633 index 693513b..b9f1d63 100644
71634 --- a/kernel/rcutree_trace.c
71635 +++ b/kernel/rcutree_trace.c
71636 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71637 rdp->completed, rdp->gpnum,
71638 rdp->passed_quiesce, rdp->qs_pending);
71639 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71640 - atomic_read(&rdp->dynticks->dynticks),
71641 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71642 rdp->dynticks->dynticks_nesting,
71643 rdp->dynticks->dynticks_nmi_nesting,
71644 rdp->dynticks_fqs);
71645 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71646 rdp->completed, rdp->gpnum,
71647 rdp->passed_quiesce, rdp->qs_pending);
71648 seq_printf(m, ",%d,%llx,%d,%lu",
71649 - atomic_read(&rdp->dynticks->dynticks),
71650 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71651 rdp->dynticks->dynticks_nesting,
71652 rdp->dynticks->dynticks_nmi_nesting,
71653 rdp->dynticks_fqs);
71654 diff --git a/kernel/resource.c b/kernel/resource.c
71655 index 73f35d4..4684fc4 100644
71656 --- a/kernel/resource.c
71657 +++ b/kernel/resource.c
71658 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71659
71660 static int __init ioresources_init(void)
71661 {
71662 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71663 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71664 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71665 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71666 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71667 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71668 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71669 +#endif
71670 +#else
71671 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71672 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71673 +#endif
71674 return 0;
71675 }
71676 __initcall(ioresources_init);
71677 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71678 index 98ec494..4241d6d 100644
71679 --- a/kernel/rtmutex-tester.c
71680 +++ b/kernel/rtmutex-tester.c
71681 @@ -20,7 +20,7 @@
71682 #define MAX_RT_TEST_MUTEXES 8
71683
71684 static spinlock_t rttest_lock;
71685 -static atomic_t rttest_event;
71686 +static atomic_unchecked_t rttest_event;
71687
71688 struct test_thread_data {
71689 int opcode;
71690 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71691
71692 case RTTEST_LOCKCONT:
71693 td->mutexes[td->opdata] = 1;
71694 - td->event = atomic_add_return(1, &rttest_event);
71695 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71696 return 0;
71697
71698 case RTTEST_RESET:
71699 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71700 return 0;
71701
71702 case RTTEST_RESETEVENT:
71703 - atomic_set(&rttest_event, 0);
71704 + atomic_set_unchecked(&rttest_event, 0);
71705 return 0;
71706
71707 default:
71708 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71709 return ret;
71710
71711 td->mutexes[id] = 1;
71712 - td->event = atomic_add_return(1, &rttest_event);
71713 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71714 rt_mutex_lock(&mutexes[id]);
71715 - td->event = atomic_add_return(1, &rttest_event);
71716 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71717 td->mutexes[id] = 4;
71718 return 0;
71719
71720 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71721 return ret;
71722
71723 td->mutexes[id] = 1;
71724 - td->event = atomic_add_return(1, &rttest_event);
71725 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71726 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
71727 - td->event = atomic_add_return(1, &rttest_event);
71728 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71729 td->mutexes[id] = ret ? 0 : 4;
71730 return ret ? -EINTR : 0;
71731
71732 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71733 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
71734 return ret;
71735
71736 - td->event = atomic_add_return(1, &rttest_event);
71737 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71738 rt_mutex_unlock(&mutexes[id]);
71739 - td->event = atomic_add_return(1, &rttest_event);
71740 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71741 td->mutexes[id] = 0;
71742 return 0;
71743
71744 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71745 break;
71746
71747 td->mutexes[dat] = 2;
71748 - td->event = atomic_add_return(1, &rttest_event);
71749 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71750 break;
71751
71752 default:
71753 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71754 return;
71755
71756 td->mutexes[dat] = 3;
71757 - td->event = atomic_add_return(1, &rttest_event);
71758 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71759 break;
71760
71761 case RTTEST_LOCKNOWAIT:
71762 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71763 return;
71764
71765 td->mutexes[dat] = 1;
71766 - td->event = atomic_add_return(1, &rttest_event);
71767 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71768 return;
71769
71770 default:
71771 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
71772 index 15f60d0..7e50319 100644
71773 --- a/kernel/sched/auto_group.c
71774 +++ b/kernel/sched/auto_group.c
71775 @@ -11,7 +11,7 @@
71776
71777 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
71778 static struct autogroup autogroup_default;
71779 -static atomic_t autogroup_seq_nr;
71780 +static atomic_unchecked_t autogroup_seq_nr;
71781
71782 void __init autogroup_init(struct task_struct *init_task)
71783 {
71784 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
71785
71786 kref_init(&ag->kref);
71787 init_rwsem(&ag->lock);
71788 - ag->id = atomic_inc_return(&autogroup_seq_nr);
71789 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
71790 ag->tg = tg;
71791 #ifdef CONFIG_RT_GROUP_SCHED
71792 /*
71793 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
71794 index c529d00..d00b4f3 100644
71795 --- a/kernel/sched/core.c
71796 +++ b/kernel/sched/core.c
71797 @@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
71798 /* convert nice value [19,-20] to rlimit style value [1,40] */
71799 int nice_rlim = 20 - nice;
71800
71801 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
71802 +
71803 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
71804 capable(CAP_SYS_NICE));
71805 }
71806 @@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
71807 if (nice > 19)
71808 nice = 19;
71809
71810 - if (increment < 0 && !can_nice(current, nice))
71811 + if (increment < 0 && (!can_nice(current, nice) ||
71812 + gr_handle_chroot_nice()))
71813 return -EPERM;
71814
71815 retval = security_task_setnice(current, nice);
71816 @@ -3750,6 +3753,7 @@ recheck:
71817 unsigned long rlim_rtprio =
71818 task_rlimit(p, RLIMIT_RTPRIO);
71819
71820 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
71821 /* can't set/change the rt policy */
71822 if (policy != p->policy && !rlim_rtprio)
71823 return -EPERM;
71824 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
71825 index 6b800a1..0c36227 100644
71826 --- a/kernel/sched/fair.c
71827 +++ b/kernel/sched/fair.c
71828 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
71829 * run_rebalance_domains is triggered when needed from the scheduler tick.
71830 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
71831 */
71832 -static void run_rebalance_domains(struct softirq_action *h)
71833 +static void run_rebalance_domains(void)
71834 {
71835 int this_cpu = smp_processor_id();
71836 struct rq *this_rq = cpu_rq(this_cpu);
71837 diff --git a/kernel/signal.c b/kernel/signal.c
71838 index 57dde52..2c561f0 100644
71839 --- a/kernel/signal.c
71840 +++ b/kernel/signal.c
71841 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
71842
71843 int print_fatal_signals __read_mostly;
71844
71845 -static void __user *sig_handler(struct task_struct *t, int sig)
71846 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
71847 {
71848 return t->sighand->action[sig - 1].sa.sa_handler;
71849 }
71850
71851 -static int sig_handler_ignored(void __user *handler, int sig)
71852 +static int sig_handler_ignored(__sighandler_t handler, int sig)
71853 {
71854 /* Is it explicitly or implicitly ignored? */
71855 return handler == SIG_IGN ||
71856 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
71857
71858 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
71859 {
71860 - void __user *handler;
71861 + __sighandler_t handler;
71862
71863 handler = sig_handler(t, sig);
71864
71865 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
71866 atomic_inc(&user->sigpending);
71867 rcu_read_unlock();
71868
71869 + if (!override_rlimit)
71870 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
71871 +
71872 if (override_rlimit ||
71873 atomic_read(&user->sigpending) <=
71874 task_rlimit(t, RLIMIT_SIGPENDING)) {
71875 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
71876
71877 int unhandled_signal(struct task_struct *tsk, int sig)
71878 {
71879 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
71880 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
71881 if (is_global_init(tsk))
71882 return 1;
71883 if (handler != SIG_IGN && handler != SIG_DFL)
71884 @@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
71885 }
71886 }
71887
71888 + /* allow glibc communication via tgkill to other threads in our
71889 + thread group */
71890 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
71891 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
71892 + && gr_handle_signal(t, sig))
71893 + return -EPERM;
71894 +
71895 return security_task_kill(t, info, sig, 0);
71896 }
71897
71898 @@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71899 return send_signal(sig, info, p, 1);
71900 }
71901
71902 -static int
71903 +int
71904 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71905 {
71906 return send_signal(sig, info, t, 0);
71907 @@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71908 unsigned long int flags;
71909 int ret, blocked, ignored;
71910 struct k_sigaction *action;
71911 + int is_unhandled = 0;
71912
71913 spin_lock_irqsave(&t->sighand->siglock, flags);
71914 action = &t->sighand->action[sig-1];
71915 @@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71916 }
71917 if (action->sa.sa_handler == SIG_DFL)
71918 t->signal->flags &= ~SIGNAL_UNKILLABLE;
71919 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
71920 + is_unhandled = 1;
71921 ret = specific_send_sig_info(sig, info, t);
71922 spin_unlock_irqrestore(&t->sighand->siglock, flags);
71923
71924 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
71925 + normal operation */
71926 + if (is_unhandled) {
71927 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
71928 + gr_handle_crash(t, sig);
71929 + }
71930 +
71931 return ret;
71932 }
71933
71934 @@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71935 ret = check_kill_permission(sig, info, p);
71936 rcu_read_unlock();
71937
71938 - if (!ret && sig)
71939 + if (!ret && sig) {
71940 ret = do_send_sig_info(sig, info, p, true);
71941 + if (!ret)
71942 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
71943 + }
71944
71945 return ret;
71946 }
71947 @@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
71948 int error = -ESRCH;
71949
71950 rcu_read_lock();
71951 - p = find_task_by_vpid(pid);
71952 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71953 + /* allow glibc communication via tgkill to other threads in our
71954 + thread group */
71955 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
71956 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
71957 + p = find_task_by_vpid_unrestricted(pid);
71958 + else
71959 +#endif
71960 + p = find_task_by_vpid(pid);
71961 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
71962 error = check_kill_permission(sig, info, p);
71963 /*
71964 diff --git a/kernel/softirq.c b/kernel/softirq.c
71965 index cc96bdc..8bb9750 100644
71966 --- a/kernel/softirq.c
71967 +++ b/kernel/softirq.c
71968 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
71969
71970 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
71971
71972 -char *softirq_to_name[NR_SOFTIRQS] = {
71973 +const char * const softirq_to_name[NR_SOFTIRQS] = {
71974 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
71975 "TASKLET", "SCHED", "HRTIMER", "RCU"
71976 };
71977 @@ -244,7 +244,7 @@ restart:
71978 kstat_incr_softirqs_this_cpu(vec_nr);
71979
71980 trace_softirq_entry(vec_nr);
71981 - h->action(h);
71982 + h->action();
71983 trace_softirq_exit(vec_nr);
71984 if (unlikely(prev_count != preempt_count())) {
71985 printk(KERN_ERR "huh, entered softirq %u %s %p"
71986 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
71987 or_softirq_pending(1UL << nr);
71988 }
71989
71990 -void open_softirq(int nr, void (*action)(struct softirq_action *))
71991 +void open_softirq(int nr, void (*action)(void))
71992 {
71993 - softirq_vec[nr].action = action;
71994 + pax_open_kernel();
71995 + *(void **)&softirq_vec[nr].action = action;
71996 + pax_close_kernel();
71997 }
71998
71999 /*
72000 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72001
72002 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72003
72004 -static void tasklet_action(struct softirq_action *a)
72005 +static void tasklet_action(void)
72006 {
72007 struct tasklet_struct *list;
72008
72009 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72010 }
72011 }
72012
72013 -static void tasklet_hi_action(struct softirq_action *a)
72014 +static void tasklet_hi_action(void)
72015 {
72016 struct tasklet_struct *list;
72017
72018 diff --git a/kernel/srcu.c b/kernel/srcu.c
72019 index 97c465e..d83f3bb 100644
72020 --- a/kernel/srcu.c
72021 +++ b/kernel/srcu.c
72022 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72023 preempt_disable();
72024 idx = rcu_dereference_index_check(sp->completed,
72025 rcu_read_lock_sched_held()) & 0x1;
72026 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72027 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72028 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72029 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72030 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72031 preempt_enable();
72032 return idx;
72033 }
72034 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72035 {
72036 preempt_disable();
72037 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72038 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72039 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72040 preempt_enable();
72041 }
72042 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72043 diff --git a/kernel/sys.c b/kernel/sys.c
72044 index e6e0ece..1f2e413 100644
72045 --- a/kernel/sys.c
72046 +++ b/kernel/sys.c
72047 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72048 error = -EACCES;
72049 goto out;
72050 }
72051 +
72052 + if (gr_handle_chroot_setpriority(p, niceval)) {
72053 + error = -EACCES;
72054 + goto out;
72055 + }
72056 +
72057 no_nice = security_task_setnice(p, niceval);
72058 if (no_nice) {
72059 error = no_nice;
72060 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72061 goto error;
72062 }
72063
72064 + if (gr_check_group_change(new->gid, new->egid, -1))
72065 + goto error;
72066 +
72067 if (rgid != (gid_t) -1 ||
72068 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72069 new->sgid = new->egid;
72070 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72071 old = current_cred();
72072
72073 retval = -EPERM;
72074 +
72075 + if (gr_check_group_change(kgid, kgid, kgid))
72076 + goto error;
72077 +
72078 if (nsown_capable(CAP_SETGID))
72079 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72080 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72081 @@ -647,7 +660,7 @@ error:
72082 /*
72083 * change the user struct in a credentials set to match the new UID
72084 */
72085 -static int set_user(struct cred *new)
72086 +int set_user(struct cred *new)
72087 {
72088 struct user_struct *new_user;
72089
72090 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72091 goto error;
72092 }
72093
72094 + if (gr_check_user_change(new->uid, new->euid, -1))
72095 + goto error;
72096 +
72097 if (!uid_eq(new->uid, old->uid)) {
72098 retval = set_user(new);
72099 if (retval < 0)
72100 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72101 old = current_cred();
72102
72103 retval = -EPERM;
72104 +
72105 + if (gr_check_crash_uid(kuid))
72106 + goto error;
72107 + if (gr_check_user_change(kuid, kuid, kuid))
72108 + goto error;
72109 +
72110 if (nsown_capable(CAP_SETUID)) {
72111 new->suid = new->uid = kuid;
72112 if (!uid_eq(kuid, old->uid)) {
72113 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72114 goto error;
72115 }
72116
72117 + if (gr_check_user_change(kruid, keuid, -1))
72118 + goto error;
72119 +
72120 if (ruid != (uid_t) -1) {
72121 new->uid = kruid;
72122 if (!uid_eq(kruid, old->uid)) {
72123 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72124 goto error;
72125 }
72126
72127 + if (gr_check_group_change(krgid, kegid, -1))
72128 + goto error;
72129 +
72130 if (rgid != (gid_t) -1)
72131 new->gid = krgid;
72132 if (egid != (gid_t) -1)
72133 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72134 if (!uid_valid(kuid))
72135 return old_fsuid;
72136
72137 + if (gr_check_user_change(-1, -1, kuid))
72138 + goto error;
72139 +
72140 new = prepare_creds();
72141 if (!new)
72142 return old_fsuid;
72143 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72144 }
72145 }
72146
72147 +error:
72148 abort_creds(new);
72149 return old_fsuid;
72150
72151 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72152 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72153 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72154 nsown_capable(CAP_SETGID)) {
72155 + if (gr_check_group_change(-1, -1, kgid))
72156 + goto error;
72157 +
72158 if (!gid_eq(kgid, old->fsgid)) {
72159 new->fsgid = kgid;
72160 goto change_okay;
72161 }
72162 }
72163
72164 +error:
72165 abort_creds(new);
72166 return old_fsgid;
72167
72168 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72169 return -EFAULT;
72170
72171 down_read(&uts_sem);
72172 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
72173 + error = __copy_to_user(name->sysname, &utsname()->sysname,
72174 __OLD_UTS_LEN);
72175 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72176 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72177 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
72178 __OLD_UTS_LEN);
72179 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72180 - error |= __copy_to_user(&name->release, &utsname()->release,
72181 + error |= __copy_to_user(name->release, &utsname()->release,
72182 __OLD_UTS_LEN);
72183 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72184 - error |= __copy_to_user(&name->version, &utsname()->version,
72185 + error |= __copy_to_user(name->version, &utsname()->version,
72186 __OLD_UTS_LEN);
72187 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72188 - error |= __copy_to_user(&name->machine, &utsname()->machine,
72189 + error |= __copy_to_user(name->machine, &utsname()->machine,
72190 __OLD_UTS_LEN);
72191 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72192 up_read(&uts_sem);
72193 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72194 error = get_dumpable(me->mm);
72195 break;
72196 case PR_SET_DUMPABLE:
72197 - if (arg2 < 0 || arg2 > 1) {
72198 + if (arg2 > 1) {
72199 error = -EINVAL;
72200 break;
72201 }
72202 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72203 index 26f65ea..df8e5ad 100644
72204 --- a/kernel/sysctl.c
72205 +++ b/kernel/sysctl.c
72206 @@ -92,7 +92,6 @@
72207
72208
72209 #if defined(CONFIG_SYSCTL)
72210 -
72211 /* External variables not in a header file. */
72212 extern int sysctl_overcommit_memory;
72213 extern int sysctl_overcommit_ratio;
72214 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72215 void __user *buffer, size_t *lenp, loff_t *ppos);
72216 #endif
72217
72218 -#ifdef CONFIG_PRINTK
72219 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72220 void __user *buffer, size_t *lenp, loff_t *ppos);
72221 -#endif
72222
72223 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72224 void __user *buffer, size_t *lenp, loff_t *ppos);
72225 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72226
72227 #endif
72228
72229 +extern struct ctl_table grsecurity_table[];
72230 +
72231 static struct ctl_table kern_table[];
72232 static struct ctl_table vm_table[];
72233 static struct ctl_table fs_table[];
72234 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72235 int sysctl_legacy_va_layout;
72236 #endif
72237
72238 +#ifdef CONFIG_PAX_SOFTMODE
72239 +static ctl_table pax_table[] = {
72240 + {
72241 + .procname = "softmode",
72242 + .data = &pax_softmode,
72243 + .maxlen = sizeof(unsigned int),
72244 + .mode = 0600,
72245 + .proc_handler = &proc_dointvec,
72246 + },
72247 +
72248 + { }
72249 +};
72250 +#endif
72251 +
72252 /* The default sysctl tables: */
72253
72254 static struct ctl_table sysctl_base_table[] = {
72255 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72256 #endif
72257
72258 static struct ctl_table kern_table[] = {
72259 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72260 + {
72261 + .procname = "grsecurity",
72262 + .mode = 0500,
72263 + .child = grsecurity_table,
72264 + },
72265 +#endif
72266 +
72267 +#ifdef CONFIG_PAX_SOFTMODE
72268 + {
72269 + .procname = "pax",
72270 + .mode = 0500,
72271 + .child = pax_table,
72272 + },
72273 +#endif
72274 +
72275 {
72276 .procname = "sched_child_runs_first",
72277 .data = &sysctl_sched_child_runs_first,
72278 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72279 .data = &modprobe_path,
72280 .maxlen = KMOD_PATH_LEN,
72281 .mode = 0644,
72282 - .proc_handler = proc_dostring,
72283 + .proc_handler = proc_dostring_modpriv,
72284 },
72285 {
72286 .procname = "modules_disabled",
72287 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72288 .extra1 = &zero,
72289 .extra2 = &one,
72290 },
72291 +#endif
72292 {
72293 .procname = "kptr_restrict",
72294 .data = &kptr_restrict,
72295 .maxlen = sizeof(int),
72296 .mode = 0644,
72297 .proc_handler = proc_dointvec_minmax_sysadmin,
72298 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72299 + .extra1 = &two,
72300 +#else
72301 .extra1 = &zero,
72302 +#endif
72303 .extra2 = &two,
72304 },
72305 -#endif
72306 {
72307 .procname = "ngroups_max",
72308 .data = &ngroups_max,
72309 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72310 .proc_handler = proc_dointvec_minmax,
72311 .extra1 = &zero,
72312 },
72313 + {
72314 + .procname = "heap_stack_gap",
72315 + .data = &sysctl_heap_stack_gap,
72316 + .maxlen = sizeof(sysctl_heap_stack_gap),
72317 + .mode = 0644,
72318 + .proc_handler = proc_doulongvec_minmax,
72319 + },
72320 #else
72321 {
72322 .procname = "nr_trim_pages",
72323 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72324 buffer, lenp, ppos);
72325 }
72326
72327 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72328 + void __user *buffer, size_t *lenp, loff_t *ppos)
72329 +{
72330 + if (write && !capable(CAP_SYS_MODULE))
72331 + return -EPERM;
72332 +
72333 + return _proc_do_string(table->data, table->maxlen, write,
72334 + buffer, lenp, ppos);
72335 +}
72336 +
72337 static size_t proc_skip_spaces(char **buf)
72338 {
72339 size_t ret;
72340 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72341 len = strlen(tmp);
72342 if (len > *size)
72343 len = *size;
72344 + if (len > sizeof(tmp))
72345 + len = sizeof(tmp);
72346 if (copy_to_user(*buf, tmp, len))
72347 return -EFAULT;
72348 *size -= len;
72349 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72350 return err;
72351 }
72352
72353 -#ifdef CONFIG_PRINTK
72354 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72355 void __user *buffer, size_t *lenp, loff_t *ppos)
72356 {
72357 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72358
72359 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72360 }
72361 -#endif
72362
72363 struct do_proc_dointvec_minmax_conv_param {
72364 int *min;
72365 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72366 *i = val;
72367 } else {
72368 val = convdiv * (*i) / convmul;
72369 - if (!first)
72370 + if (!first) {
72371 err = proc_put_char(&buffer, &left, '\t');
72372 + if (err)
72373 + break;
72374 + }
72375 err = proc_put_long(&buffer, &left, val, false);
72376 if (err)
72377 break;
72378 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72379 return -ENOSYS;
72380 }
72381
72382 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72383 + void __user *buffer, size_t *lenp, loff_t *ppos)
72384 +{
72385 + return -ENOSYS;
72386 +}
72387 +
72388 int proc_dointvec(struct ctl_table *table, int write,
72389 void __user *buffer, size_t *lenp, loff_t *ppos)
72390 {
72391 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72392 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72393 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72394 EXPORT_SYMBOL(proc_dostring);
72395 +EXPORT_SYMBOL(proc_dostring_modpriv);
72396 EXPORT_SYMBOL(proc_doulongvec_minmax);
72397 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72398 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72399 index 65bdcf1..21eb831 100644
72400 --- a/kernel/sysctl_binary.c
72401 +++ b/kernel/sysctl_binary.c
72402 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72403 int i;
72404
72405 set_fs(KERNEL_DS);
72406 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72407 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72408 set_fs(old_fs);
72409 if (result < 0)
72410 goto out_kfree;
72411 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72412 }
72413
72414 set_fs(KERNEL_DS);
72415 - result = vfs_write(file, buffer, str - buffer, &pos);
72416 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72417 set_fs(old_fs);
72418 if (result < 0)
72419 goto out_kfree;
72420 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72421 int i;
72422
72423 set_fs(KERNEL_DS);
72424 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72425 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72426 set_fs(old_fs);
72427 if (result < 0)
72428 goto out_kfree;
72429 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72430 }
72431
72432 set_fs(KERNEL_DS);
72433 - result = vfs_write(file, buffer, str - buffer, &pos);
72434 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72435 set_fs(old_fs);
72436 if (result < 0)
72437 goto out_kfree;
72438 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72439 int i;
72440
72441 set_fs(KERNEL_DS);
72442 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72443 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72444 set_fs(old_fs);
72445 if (result < 0)
72446 goto out;
72447 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72448 __le16 dnaddr;
72449
72450 set_fs(KERNEL_DS);
72451 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72452 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72453 set_fs(old_fs);
72454 if (result < 0)
72455 goto out;
72456 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72457 le16_to_cpu(dnaddr) & 0x3ff);
72458
72459 set_fs(KERNEL_DS);
72460 - result = vfs_write(file, buf, len, &pos);
72461 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72462 set_fs(old_fs);
72463 if (result < 0)
72464 goto out;
72465 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72466 index 145bb4d..b2aa969 100644
72467 --- a/kernel/taskstats.c
72468 +++ b/kernel/taskstats.c
72469 @@ -28,9 +28,12 @@
72470 #include <linux/fs.h>
72471 #include <linux/file.h>
72472 #include <linux/pid_namespace.h>
72473 +#include <linux/grsecurity.h>
72474 #include <net/genetlink.h>
72475 #include <linux/atomic.h>
72476
72477 +extern int gr_is_taskstats_denied(int pid);
72478 +
72479 /*
72480 * Maximum length of a cpumask that can be specified in
72481 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72482 @@ -570,6 +573,9 @@ err:
72483
72484 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72485 {
72486 + if (gr_is_taskstats_denied(current->pid))
72487 + return -EACCES;
72488 +
72489 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72490 return cmd_attr_register_cpumask(info);
72491 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72492 diff --git a/kernel/time.c b/kernel/time.c
72493 index d226c6a..c7c0960 100644
72494 --- a/kernel/time.c
72495 +++ b/kernel/time.c
72496 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72497 return error;
72498
72499 if (tz) {
72500 + /* we log in do_settimeofday called below, so don't log twice
72501 + */
72502 + if (!tv)
72503 + gr_log_timechange();
72504 +
72505 sys_tz = *tz;
72506 update_vsyscall_tz();
72507 if (firsttime) {
72508 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72509 index f11d83b..d016d91 100644
72510 --- a/kernel/time/alarmtimer.c
72511 +++ b/kernel/time/alarmtimer.c
72512 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72513 struct platform_device *pdev;
72514 int error = 0;
72515 int i;
72516 - struct k_clock alarm_clock = {
72517 + static struct k_clock alarm_clock = {
72518 .clock_getres = alarm_clock_getres,
72519 .clock_get = alarm_clock_get,
72520 .timer_create = alarm_timer_create,
72521 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72522 index f113755..ec24223 100644
72523 --- a/kernel/time/tick-broadcast.c
72524 +++ b/kernel/time/tick-broadcast.c
72525 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72526 * then clear the broadcast bit.
72527 */
72528 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72529 - int cpu = smp_processor_id();
72530 + cpu = smp_processor_id();
72531
72532 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72533 tick_broadcast_clear_oneshot(cpu);
72534 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72535 index e424970..4c7962b 100644
72536 --- a/kernel/time/timekeeping.c
72537 +++ b/kernel/time/timekeeping.c
72538 @@ -15,6 +15,7 @@
72539 #include <linux/init.h>
72540 #include <linux/mm.h>
72541 #include <linux/sched.h>
72542 +#include <linux/grsecurity.h>
72543 #include <linux/syscore_ops.h>
72544 #include <linux/clocksource.h>
72545 #include <linux/jiffies.h>
72546 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72547 if (!timespec_valid_strict(tv))
72548 return -EINVAL;
72549
72550 + gr_log_timechange();
72551 +
72552 write_seqlock_irqsave(&tk->lock, flags);
72553
72554 timekeeping_forward_now(tk);
72555 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72556 index af5a7e9..715611a 100644
72557 --- a/kernel/time/timer_list.c
72558 +++ b/kernel/time/timer_list.c
72559 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72560
72561 static void print_name_offset(struct seq_file *m, void *sym)
72562 {
72563 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72564 + SEQ_printf(m, "<%p>", NULL);
72565 +#else
72566 char symname[KSYM_NAME_LEN];
72567
72568 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72569 SEQ_printf(m, "<%pK>", sym);
72570 else
72571 SEQ_printf(m, "%s", symname);
72572 +#endif
72573 }
72574
72575 static void
72576 @@ -112,7 +116,11 @@ next_one:
72577 static void
72578 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72579 {
72580 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72581 + SEQ_printf(m, " .base: %p\n", NULL);
72582 +#else
72583 SEQ_printf(m, " .base: %pK\n", base);
72584 +#endif
72585 SEQ_printf(m, " .index: %d\n",
72586 base->index);
72587 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72588 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72589 {
72590 struct proc_dir_entry *pe;
72591
72592 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72593 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72594 +#else
72595 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72596 +#endif
72597 if (!pe)
72598 return -ENOMEM;
72599 return 0;
72600 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72601 index 0b537f2..40d6c20 100644
72602 --- a/kernel/time/timer_stats.c
72603 +++ b/kernel/time/timer_stats.c
72604 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72605 static unsigned long nr_entries;
72606 static struct entry entries[MAX_ENTRIES];
72607
72608 -static atomic_t overflow_count;
72609 +static atomic_unchecked_t overflow_count;
72610
72611 /*
72612 * The entries are in a hash-table, for fast lookup:
72613 @@ -140,7 +140,7 @@ static void reset_entries(void)
72614 nr_entries = 0;
72615 memset(entries, 0, sizeof(entries));
72616 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72617 - atomic_set(&overflow_count, 0);
72618 + atomic_set_unchecked(&overflow_count, 0);
72619 }
72620
72621 static struct entry *alloc_entry(void)
72622 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72623 if (likely(entry))
72624 entry->count++;
72625 else
72626 - atomic_inc(&overflow_count);
72627 + atomic_inc_unchecked(&overflow_count);
72628
72629 out_unlock:
72630 raw_spin_unlock_irqrestore(lock, flags);
72631 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72632
72633 static void print_name_offset(struct seq_file *m, unsigned long addr)
72634 {
72635 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72636 + seq_printf(m, "<%p>", NULL);
72637 +#else
72638 char symname[KSYM_NAME_LEN];
72639
72640 if (lookup_symbol_name(addr, symname) < 0)
72641 - seq_printf(m, "<%p>", (void *)addr);
72642 + seq_printf(m, "<%pK>", (void *)addr);
72643 else
72644 seq_printf(m, "%s", symname);
72645 +#endif
72646 }
72647
72648 static int tstats_show(struct seq_file *m, void *v)
72649 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72650
72651 seq_puts(m, "Timer Stats Version: v0.2\n");
72652 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72653 - if (atomic_read(&overflow_count))
72654 + if (atomic_read_unchecked(&overflow_count))
72655 seq_printf(m, "Overflow: %d entries\n",
72656 - atomic_read(&overflow_count));
72657 + atomic_read_unchecked(&overflow_count));
72658
72659 for (i = 0; i < nr_entries; i++) {
72660 entry = entries + i;
72661 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72662 {
72663 struct proc_dir_entry *pe;
72664
72665 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72666 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72667 +#else
72668 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72669 +#endif
72670 if (!pe)
72671 return -ENOMEM;
72672 return 0;
72673 diff --git a/kernel/timer.c b/kernel/timer.c
72674 index 367d008..46857a0 100644
72675 --- a/kernel/timer.c
72676 +++ b/kernel/timer.c
72677 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72678 /*
72679 * This function runs timers and the timer-tq in bottom half context.
72680 */
72681 -static void run_timer_softirq(struct softirq_action *h)
72682 +static void run_timer_softirq(void)
72683 {
72684 struct tvec_base *base = __this_cpu_read(tvec_bases);
72685
72686 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72687 return NOTIFY_OK;
72688 }
72689
72690 -static struct notifier_block __cpuinitdata timers_nb = {
72691 +static struct notifier_block __cpuinitconst timers_nb = {
72692 .notifier_call = timer_cpu_notify,
72693 };
72694
72695 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72696 index c0bd030..62a1927 100644
72697 --- a/kernel/trace/blktrace.c
72698 +++ b/kernel/trace/blktrace.c
72699 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72700 struct blk_trace *bt = filp->private_data;
72701 char buf[16];
72702
72703 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
72704 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
72705
72706 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
72707 }
72708 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
72709 return 1;
72710
72711 bt = buf->chan->private_data;
72712 - atomic_inc(&bt->dropped);
72713 + atomic_inc_unchecked(&bt->dropped);
72714 return 0;
72715 }
72716
72717 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
72718
72719 bt->dir = dir;
72720 bt->dev = dev;
72721 - atomic_set(&bt->dropped, 0);
72722 + atomic_set_unchecked(&bt->dropped, 0);
72723
72724 ret = -EIO;
72725 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
72726 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
72727 index 356bc2f..7c94fc0 100644
72728 --- a/kernel/trace/ftrace.c
72729 +++ b/kernel/trace/ftrace.c
72730 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
72731 if (unlikely(ftrace_disabled))
72732 return 0;
72733
72734 + ret = ftrace_arch_code_modify_prepare();
72735 + FTRACE_WARN_ON(ret);
72736 + if (ret)
72737 + return 0;
72738 +
72739 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
72740 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
72741 if (ret) {
72742 ftrace_bug(ret, ip);
72743 - return 0;
72744 }
72745 - return 1;
72746 + return ret ? 0 : 1;
72747 }
72748
72749 /*
72750 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
72751
72752 int
72753 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
72754 - void *data)
72755 + void *data)
72756 {
72757 struct ftrace_func_probe *entry;
72758 struct ftrace_page *pg;
72759 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
72760 if (!count)
72761 return 0;
72762
72763 + pax_open_kernel();
72764 sort(start, count, sizeof(*start),
72765 ftrace_cmp_ips, ftrace_swap_ips);
72766 + pax_close_kernel();
72767
72768 start_pg = ftrace_allocate_pages(count);
72769 if (!start_pg)
72770 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
72771 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
72772
72773 static int ftrace_graph_active;
72774 -static struct notifier_block ftrace_suspend_notifier;
72775 -
72776 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
72777 {
72778 return 0;
72779 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
72780 return NOTIFY_DONE;
72781 }
72782
72783 +static struct notifier_block ftrace_suspend_notifier = {
72784 + .notifier_call = ftrace_suspend_notifier_call
72785 +};
72786 +
72787 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72788 trace_func_graph_ent_t entryfunc)
72789 {
72790 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72791 goto out;
72792 }
72793
72794 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
72795 register_pm_notifier(&ftrace_suspend_notifier);
72796
72797 ftrace_graph_active++;
72798 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
72799 index 4cb5e51..e7e05d9 100644
72800 --- a/kernel/trace/ring_buffer.c
72801 +++ b/kernel/trace/ring_buffer.c
72802 @@ -346,9 +346,9 @@ struct buffer_data_page {
72803 */
72804 struct buffer_page {
72805 struct list_head list; /* list of buffer pages */
72806 - local_t write; /* index for next write */
72807 + local_unchecked_t write; /* index for next write */
72808 unsigned read; /* index for next read */
72809 - local_t entries; /* entries on this page */
72810 + local_unchecked_t entries; /* entries on this page */
72811 unsigned long real_end; /* real end of data */
72812 struct buffer_data_page *page; /* Actual data page */
72813 };
72814 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
72815 unsigned long lost_events;
72816 unsigned long last_overrun;
72817 local_t entries_bytes;
72818 - local_t commit_overrun;
72819 - local_t overrun;
72820 + local_unchecked_t commit_overrun;
72821 + local_unchecked_t overrun;
72822 local_t entries;
72823 local_t committing;
72824 local_t commits;
72825 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72826 *
72827 * We add a counter to the write field to denote this.
72828 */
72829 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
72830 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
72831 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
72832 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
72833
72834 /*
72835 * Just make sure we have seen our old_write and synchronize
72836 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72837 * cmpxchg to only update if an interrupt did not already
72838 * do it for us. If the cmpxchg fails, we don't care.
72839 */
72840 - (void)local_cmpxchg(&next_page->write, old_write, val);
72841 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
72842 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
72843 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
72844
72845 /*
72846 * No need to worry about races with clearing out the commit.
72847 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
72848
72849 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
72850 {
72851 - return local_read(&bpage->entries) & RB_WRITE_MASK;
72852 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
72853 }
72854
72855 static inline unsigned long rb_page_write(struct buffer_page *bpage)
72856 {
72857 - return local_read(&bpage->write) & RB_WRITE_MASK;
72858 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
72859 }
72860
72861 static int
72862 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
72863 * bytes consumed in ring buffer from here.
72864 * Increment overrun to account for the lost events.
72865 */
72866 - local_add(page_entries, &cpu_buffer->overrun);
72867 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
72868 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72869 }
72870
72871 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
72872 * it is our responsibility to update
72873 * the counters.
72874 */
72875 - local_add(entries, &cpu_buffer->overrun);
72876 + local_add_unchecked(entries, &cpu_buffer->overrun);
72877 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72878
72879 /*
72880 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72881 if (tail == BUF_PAGE_SIZE)
72882 tail_page->real_end = 0;
72883
72884 - local_sub(length, &tail_page->write);
72885 + local_sub_unchecked(length, &tail_page->write);
72886 return;
72887 }
72888
72889 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72890 rb_event_set_padding(event);
72891
72892 /* Set the write back to the previous setting */
72893 - local_sub(length, &tail_page->write);
72894 + local_sub_unchecked(length, &tail_page->write);
72895 return;
72896 }
72897
72898 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72899
72900 /* Set write to end of buffer */
72901 length = (tail + length) - BUF_PAGE_SIZE;
72902 - local_sub(length, &tail_page->write);
72903 + local_sub_unchecked(length, &tail_page->write);
72904 }
72905
72906 /*
72907 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72908 * about it.
72909 */
72910 if (unlikely(next_page == commit_page)) {
72911 - local_inc(&cpu_buffer->commit_overrun);
72912 + local_inc_unchecked(&cpu_buffer->commit_overrun);
72913 goto out_reset;
72914 }
72915
72916 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72917 cpu_buffer->tail_page) &&
72918 (cpu_buffer->commit_page ==
72919 cpu_buffer->reader_page))) {
72920 - local_inc(&cpu_buffer->commit_overrun);
72921 + local_inc_unchecked(&cpu_buffer->commit_overrun);
72922 goto out_reset;
72923 }
72924 }
72925 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72926 length += RB_LEN_TIME_EXTEND;
72927
72928 tail_page = cpu_buffer->tail_page;
72929 - write = local_add_return(length, &tail_page->write);
72930 + write = local_add_return_unchecked(length, &tail_page->write);
72931
72932 /* set write to only the index of the write */
72933 write &= RB_WRITE_MASK;
72934 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72935 kmemcheck_annotate_bitfield(event, bitfield);
72936 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
72937
72938 - local_inc(&tail_page->entries);
72939 + local_inc_unchecked(&tail_page->entries);
72940
72941 /*
72942 * If this is the first commit on the page, then update
72943 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72944
72945 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
72946 unsigned long write_mask =
72947 - local_read(&bpage->write) & ~RB_WRITE_MASK;
72948 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
72949 unsigned long event_length = rb_event_length(event);
72950 /*
72951 * This is on the tail page. It is possible that
72952 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72953 */
72954 old_index += write_mask;
72955 new_index += write_mask;
72956 - index = local_cmpxchg(&bpage->write, old_index, new_index);
72957 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
72958 if (index == old_index) {
72959 /* update counters */
72960 local_sub(event_length, &cpu_buffer->entries_bytes);
72961 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72962
72963 /* Do the likely case first */
72964 if (likely(bpage->page == (void *)addr)) {
72965 - local_dec(&bpage->entries);
72966 + local_dec_unchecked(&bpage->entries);
72967 return;
72968 }
72969
72970 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72971 start = bpage;
72972 do {
72973 if (bpage->page == (void *)addr) {
72974 - local_dec(&bpage->entries);
72975 + local_dec_unchecked(&bpage->entries);
72976 return;
72977 }
72978 rb_inc_page(cpu_buffer, &bpage);
72979 @@ -2923,7 +2923,7 @@ static inline unsigned long
72980 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
72981 {
72982 return local_read(&cpu_buffer->entries) -
72983 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
72984 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
72985 }
72986
72987 /**
72988 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
72989 return 0;
72990
72991 cpu_buffer = buffer->buffers[cpu];
72992 - ret = local_read(&cpu_buffer->overrun);
72993 + ret = local_read_unchecked(&cpu_buffer->overrun);
72994
72995 return ret;
72996 }
72997 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
72998 return 0;
72999
73000 cpu_buffer = buffer->buffers[cpu];
73001 - ret = local_read(&cpu_buffer->commit_overrun);
73002 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73003
73004 return ret;
73005 }
73006 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73007 /* if you care about this being correct, lock the buffer */
73008 for_each_buffer_cpu(buffer, cpu) {
73009 cpu_buffer = buffer->buffers[cpu];
73010 - overruns += local_read(&cpu_buffer->overrun);
73011 + overruns += local_read_unchecked(&cpu_buffer->overrun);
73012 }
73013
73014 return overruns;
73015 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73016 /*
73017 * Reset the reader page to size zero.
73018 */
73019 - local_set(&cpu_buffer->reader_page->write, 0);
73020 - local_set(&cpu_buffer->reader_page->entries, 0);
73021 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73022 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73023 local_set(&cpu_buffer->reader_page->page->commit, 0);
73024 cpu_buffer->reader_page->real_end = 0;
73025
73026 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73027 * want to compare with the last_overrun.
73028 */
73029 smp_mb();
73030 - overwrite = local_read(&(cpu_buffer->overrun));
73031 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73032
73033 /*
73034 * Here's the tricky part.
73035 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73036
73037 cpu_buffer->head_page
73038 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73039 - local_set(&cpu_buffer->head_page->write, 0);
73040 - local_set(&cpu_buffer->head_page->entries, 0);
73041 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
73042 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73043 local_set(&cpu_buffer->head_page->page->commit, 0);
73044
73045 cpu_buffer->head_page->read = 0;
73046 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73047
73048 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73049 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73050 - local_set(&cpu_buffer->reader_page->write, 0);
73051 - local_set(&cpu_buffer->reader_page->entries, 0);
73052 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73053 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73054 local_set(&cpu_buffer->reader_page->page->commit, 0);
73055 cpu_buffer->reader_page->read = 0;
73056
73057 - local_set(&cpu_buffer->commit_overrun, 0);
73058 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73059 local_set(&cpu_buffer->entries_bytes, 0);
73060 - local_set(&cpu_buffer->overrun, 0);
73061 + local_set_unchecked(&cpu_buffer->overrun, 0);
73062 local_set(&cpu_buffer->entries, 0);
73063 local_set(&cpu_buffer->committing, 0);
73064 local_set(&cpu_buffer->commits, 0);
73065 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73066 rb_init_page(bpage);
73067 bpage = reader->page;
73068 reader->page = *data_page;
73069 - local_set(&reader->write, 0);
73070 - local_set(&reader->entries, 0);
73071 + local_set_unchecked(&reader->write, 0);
73072 + local_set_unchecked(&reader->entries, 0);
73073 reader->read = 0;
73074 *data_page = bpage;
73075
73076 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73077 index 31e4f55..62da00f 100644
73078 --- a/kernel/trace/trace.c
73079 +++ b/kernel/trace/trace.c
73080 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73081 };
73082 #endif
73083
73084 -static struct dentry *d_tracer;
73085 -
73086 struct dentry *tracing_init_dentry(void)
73087 {
73088 + static struct dentry *d_tracer;
73089 static int once;
73090
73091 if (d_tracer)
73092 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73093 return d_tracer;
73094 }
73095
73096 -static struct dentry *d_percpu;
73097 -
73098 struct dentry *tracing_dentry_percpu(void)
73099 {
73100 + static struct dentry *d_percpu;
73101 static int once;
73102 struct dentry *d_tracer;
73103
73104 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73105 index d608d09..7eddcb1 100644
73106 --- a/kernel/trace/trace_events.c
73107 +++ b/kernel/trace/trace_events.c
73108 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73109 struct ftrace_module_file_ops {
73110 struct list_head list;
73111 struct module *mod;
73112 - struct file_operations id;
73113 - struct file_operations enable;
73114 - struct file_operations format;
73115 - struct file_operations filter;
73116 };
73117
73118 static struct ftrace_module_file_ops *
73119 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73120
73121 file_ops->mod = mod;
73122
73123 - file_ops->id = ftrace_event_id_fops;
73124 - file_ops->id.owner = mod;
73125 -
73126 - file_ops->enable = ftrace_enable_fops;
73127 - file_ops->enable.owner = mod;
73128 -
73129 - file_ops->filter = ftrace_event_filter_fops;
73130 - file_ops->filter.owner = mod;
73131 -
73132 - file_ops->format = ftrace_event_format_fops;
73133 - file_ops->format.owner = mod;
73134 + pax_open_kernel();
73135 + *(void **)&mod->trace_id.owner = mod;
73136 + *(void **)&mod->trace_enable.owner = mod;
73137 + *(void **)&mod->trace_filter.owner = mod;
73138 + *(void **)&mod->trace_format.owner = mod;
73139 + pax_close_kernel();
73140
73141 list_add(&file_ops->list, &ftrace_module_file_list);
73142
73143 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73144
73145 for_each_event(call, start, end) {
73146 __trace_add_event_call(*call, mod,
73147 - &file_ops->id, &file_ops->enable,
73148 - &file_ops->filter, &file_ops->format);
73149 + &mod->trace_id, &mod->trace_enable,
73150 + &mod->trace_filter, &mod->trace_format);
73151 }
73152 }
73153
73154 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73155 index fd3c8aa..5f324a6 100644
73156 --- a/kernel/trace/trace_mmiotrace.c
73157 +++ b/kernel/trace/trace_mmiotrace.c
73158 @@ -24,7 +24,7 @@ struct header_iter {
73159 static struct trace_array *mmio_trace_array;
73160 static bool overrun_detected;
73161 static unsigned long prev_overruns;
73162 -static atomic_t dropped_count;
73163 +static atomic_unchecked_t dropped_count;
73164
73165 static void mmio_reset_data(struct trace_array *tr)
73166 {
73167 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73168
73169 static unsigned long count_overruns(struct trace_iterator *iter)
73170 {
73171 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
73172 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73173 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73174
73175 if (over > prev_overruns)
73176 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73177 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73178 sizeof(*entry), 0, pc);
73179 if (!event) {
73180 - atomic_inc(&dropped_count);
73181 + atomic_inc_unchecked(&dropped_count);
73182 return;
73183 }
73184 entry = ring_buffer_event_data(event);
73185 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73186 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73187 sizeof(*entry), 0, pc);
73188 if (!event) {
73189 - atomic_inc(&dropped_count);
73190 + atomic_inc_unchecked(&dropped_count);
73191 return;
73192 }
73193 entry = ring_buffer_event_data(event);
73194 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73195 index 123b189..1e9e2a6 100644
73196 --- a/kernel/trace/trace_output.c
73197 +++ b/kernel/trace/trace_output.c
73198 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73199
73200 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73201 if (!IS_ERR(p)) {
73202 - p = mangle_path(s->buffer + s->len, p, "\n");
73203 + p = mangle_path(s->buffer + s->len, p, "\n\\");
73204 if (p) {
73205 s->len = p - s->buffer;
73206 return 1;
73207 @@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73208 goto out;
73209 }
73210
73211 + pax_open_kernel();
73212 if (event->funcs->trace == NULL)
73213 - event->funcs->trace = trace_nop_print;
73214 + *(void **)&event->funcs->trace = trace_nop_print;
73215 if (event->funcs->raw == NULL)
73216 - event->funcs->raw = trace_nop_print;
73217 + *(void **)&event->funcs->raw = trace_nop_print;
73218 if (event->funcs->hex == NULL)
73219 - event->funcs->hex = trace_nop_print;
73220 + *(void **)&event->funcs->hex = trace_nop_print;
73221 if (event->funcs->binary == NULL)
73222 - event->funcs->binary = trace_nop_print;
73223 + *(void **)&event->funcs->binary = trace_nop_print;
73224 + pax_close_kernel();
73225
73226 key = event->type & (EVENT_HASHSIZE - 1);
73227
73228 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73229 index 0c1b1657..95337e9 100644
73230 --- a/kernel/trace/trace_stack.c
73231 +++ b/kernel/trace/trace_stack.c
73232 @@ -53,7 +53,7 @@ static inline void check_stack(void)
73233 return;
73234
73235 /* we do not handle interrupt stacks yet */
73236 - if (!object_is_on_stack(&this_size))
73237 + if (!object_starts_on_stack(&this_size))
73238 return;
73239
73240 local_irq_save(flags);
73241 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73242 index 28e9d6c9..50381bd 100644
73243 --- a/lib/Kconfig.debug
73244 +++ b/lib/Kconfig.debug
73245 @@ -1278,6 +1278,7 @@ config LATENCYTOP
73246 depends on DEBUG_KERNEL
73247 depends on STACKTRACE_SUPPORT
73248 depends on PROC_FS
73249 + depends on !GRKERNSEC_HIDESYM
73250 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73251 select KALLSYMS
73252 select KALLSYMS_ALL
73253 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73254
73255 config PROVIDE_OHCI1394_DMA_INIT
73256 bool "Remote debugging over FireWire early on boot"
73257 - depends on PCI && X86
73258 + depends on PCI && X86 && !GRKERNSEC
73259 help
73260 If you want to debug problems which hang or crash the kernel early
73261 on boot and the crashing machine has a FireWire port, you can use
73262 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73263
73264 config FIREWIRE_OHCI_REMOTE_DMA
73265 bool "Remote debugging over FireWire with firewire-ohci"
73266 - depends on FIREWIRE_OHCI
73267 + depends on FIREWIRE_OHCI && !GRKERNSEC
73268 help
73269 This option lets you use the FireWire bus for remote debugging
73270 with help of the firewire-ohci driver. It enables unfiltered
73271 diff --git a/lib/Makefile b/lib/Makefile
73272 index a08b791..a3ff1eb 100644
73273 --- a/lib/Makefile
73274 +++ b/lib/Makefile
73275 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73276
73277 obj-$(CONFIG_BTREE) += btree.o
73278 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73279 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73280 +obj-y += list_debug.o
73281 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73282
73283 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73284 diff --git a/lib/bitmap.c b/lib/bitmap.c
73285 index 06fdfa1..97c5c7d 100644
73286 --- a/lib/bitmap.c
73287 +++ b/lib/bitmap.c
73288 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73289 {
73290 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73291 u32 chunk;
73292 - const char __user __force *ubuf = (const char __user __force *)buf;
73293 + const char __user *ubuf = (const char __force_user *)buf;
73294
73295 bitmap_zero(maskp, nmaskbits);
73296
73297 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73298 {
73299 if (!access_ok(VERIFY_READ, ubuf, ulen))
73300 return -EFAULT;
73301 - return __bitmap_parse((const char __force *)ubuf,
73302 + return __bitmap_parse((const char __force_kernel *)ubuf,
73303 ulen, 1, maskp, nmaskbits);
73304
73305 }
73306 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73307 {
73308 unsigned a, b;
73309 int c, old_c, totaldigits;
73310 - const char __user __force *ubuf = (const char __user __force *)buf;
73311 + const char __user *ubuf = (const char __force_user *)buf;
73312 int exp_digit, in_range;
73313
73314 totaldigits = c = 0;
73315 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73316 {
73317 if (!access_ok(VERIFY_READ, ubuf, ulen))
73318 return -EFAULT;
73319 - return __bitmap_parselist((const char __force *)ubuf,
73320 + return __bitmap_parselist((const char __force_kernel *)ubuf,
73321 ulen, 1, maskp, nmaskbits);
73322 }
73323 EXPORT_SYMBOL(bitmap_parselist_user);
73324 diff --git a/lib/bug.c b/lib/bug.c
73325 index d0cdf14..4d07bd2 100644
73326 --- a/lib/bug.c
73327 +++ b/lib/bug.c
73328 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73329 return BUG_TRAP_TYPE_NONE;
73330
73331 bug = find_bug(bugaddr);
73332 + if (!bug)
73333 + return BUG_TRAP_TYPE_NONE;
73334
73335 file = NULL;
73336 line = 0;
73337 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73338 index d11808c..dc2d6f8 100644
73339 --- a/lib/debugobjects.c
73340 +++ b/lib/debugobjects.c
73341 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73342 if (limit > 4)
73343 return;
73344
73345 - is_on_stack = object_is_on_stack(addr);
73346 + is_on_stack = object_starts_on_stack(addr);
73347 if (is_on_stack == onstack)
73348 return;
73349
73350 diff --git a/lib/devres.c b/lib/devres.c
73351 index 80b9c76..9e32279 100644
73352 --- a/lib/devres.c
73353 +++ b/lib/devres.c
73354 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73355 void devm_iounmap(struct device *dev, void __iomem *addr)
73356 {
73357 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73358 - (void *)addr));
73359 + (void __force *)addr));
73360 iounmap(addr);
73361 }
73362 EXPORT_SYMBOL(devm_iounmap);
73363 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73364 {
73365 ioport_unmap(addr);
73366 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73367 - devm_ioport_map_match, (void *)addr));
73368 + devm_ioport_map_match, (void __force *)addr));
73369 }
73370 EXPORT_SYMBOL(devm_ioport_unmap);
73371
73372 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73373 index d84beb9..da44791 100644
73374 --- a/lib/dma-debug.c
73375 +++ b/lib/dma-debug.c
73376 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73377
73378 void dma_debug_add_bus(struct bus_type *bus)
73379 {
73380 - struct notifier_block *nb;
73381 + notifier_block_no_const *nb;
73382
73383 if (global_disable)
73384 return;
73385 @@ -919,7 +919,7 @@ out:
73386
73387 static void check_for_stack(struct device *dev, void *addr)
73388 {
73389 - if (object_is_on_stack(addr))
73390 + if (object_starts_on_stack(addr))
73391 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73392 "stack [addr=%p]\n", addr);
73393 }
73394 diff --git a/lib/inflate.c b/lib/inflate.c
73395 index 013a761..c28f3fc 100644
73396 --- a/lib/inflate.c
73397 +++ b/lib/inflate.c
73398 @@ -269,7 +269,7 @@ static void free(void *where)
73399 malloc_ptr = free_mem_ptr;
73400 }
73401 #else
73402 -#define malloc(a) kmalloc(a, GFP_KERNEL)
73403 +#define malloc(a) kmalloc((a), GFP_KERNEL)
73404 #define free(a) kfree(a)
73405 #endif
73406
73407 diff --git a/lib/ioremap.c b/lib/ioremap.c
73408 index 0c9216c..863bd89 100644
73409 --- a/lib/ioremap.c
73410 +++ b/lib/ioremap.c
73411 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73412 unsigned long next;
73413
73414 phys_addr -= addr;
73415 - pmd = pmd_alloc(&init_mm, pud, addr);
73416 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73417 if (!pmd)
73418 return -ENOMEM;
73419 do {
73420 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73421 unsigned long next;
73422
73423 phys_addr -= addr;
73424 - pud = pud_alloc(&init_mm, pgd, addr);
73425 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73426 if (!pud)
73427 return -ENOMEM;
73428 do {
73429 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73430 index bd2bea9..6b3c95e 100644
73431 --- a/lib/is_single_threaded.c
73432 +++ b/lib/is_single_threaded.c
73433 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73434 struct task_struct *p, *t;
73435 bool ret;
73436
73437 + if (!mm)
73438 + return true;
73439 +
73440 if (atomic_read(&task->signal->live) != 1)
73441 return false;
73442
73443 diff --git a/lib/list_debug.c b/lib/list_debug.c
73444 index c24c2f7..3fc5da0 100644
73445 --- a/lib/list_debug.c
73446 +++ b/lib/list_debug.c
73447 @@ -11,7 +11,9 @@
73448 #include <linux/bug.h>
73449 #include <linux/kernel.h>
73450 #include <linux/rculist.h>
73451 +#include <linux/mm.h>
73452
73453 +#ifdef CONFIG_DEBUG_LIST
73454 /*
73455 * Insert a new entry between two known consecutive entries.
73456 *
73457 @@ -19,21 +21,32 @@
73458 * the prev/next entries already!
73459 */
73460
73461 -void __list_add(struct list_head *new,
73462 - struct list_head *prev,
73463 - struct list_head *next)
73464 +static bool __list_add_debug(struct list_head *new,
73465 + struct list_head *prev,
73466 + struct list_head *next)
73467 {
73468 - WARN(next->prev != prev,
73469 + if (WARN(next->prev != prev,
73470 "list_add corruption. next->prev should be "
73471 "prev (%p), but was %p. (next=%p).\n",
73472 - prev, next->prev, next);
73473 - WARN(prev->next != next,
73474 + prev, next->prev, next) ||
73475 + WARN(prev->next != next,
73476 "list_add corruption. prev->next should be "
73477 "next (%p), but was %p. (prev=%p).\n",
73478 - next, prev->next, prev);
73479 - WARN(new == prev || new == next,
73480 + next, prev->next, prev) ||
73481 + WARN(new == prev || new == next,
73482 "list_add double add: new=%p, prev=%p, next=%p.\n",
73483 - new, prev, next);
73484 + new, prev, next))
73485 + return false;
73486 + return true;
73487 +}
73488 +
73489 +void __list_add(struct list_head *new,
73490 + struct list_head *prev,
73491 + struct list_head *next)
73492 +{
73493 + if (!__list_add_debug(new, prev, next))
73494 + return;
73495 +
73496 next->prev = new;
73497 new->next = next;
73498 new->prev = prev;
73499 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73500 }
73501 EXPORT_SYMBOL(__list_add);
73502
73503 -void __list_del_entry(struct list_head *entry)
73504 +static bool __list_del_entry_debug(struct list_head *entry)
73505 {
73506 struct list_head *prev, *next;
73507
73508 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73509 WARN(next->prev != entry,
73510 "list_del corruption. next->prev should be %p, "
73511 "but was %p\n", entry, next->prev))
73512 + return false;
73513 + return true;
73514 +}
73515 +
73516 +void __list_del_entry(struct list_head *entry)
73517 +{
73518 + if (!__list_del_entry_debug(entry))
73519 return;
73520
73521 - __list_del(prev, next);
73522 + __list_del(entry->prev, entry->next);
73523 }
73524 EXPORT_SYMBOL(__list_del_entry);
73525
73526 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73527 void __list_add_rcu(struct list_head *new,
73528 struct list_head *prev, struct list_head *next)
73529 {
73530 - WARN(next->prev != prev,
73531 + if (WARN(next->prev != prev,
73532 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73533 - prev, next->prev, next);
73534 - WARN(prev->next != next,
73535 + prev, next->prev, next) ||
73536 + WARN(prev->next != next,
73537 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73538 - next, prev->next, prev);
73539 + next, prev->next, prev))
73540 + return;
73541 +
73542 new->next = next;
73543 new->prev = prev;
73544 rcu_assign_pointer(list_next_rcu(prev), new);
73545 next->prev = new;
73546 }
73547 EXPORT_SYMBOL(__list_add_rcu);
73548 +#endif
73549 +
73550 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73551 +{
73552 + struct list_head *prev, *next;
73553 +
73554 + prev = head->prev;
73555 + next = head;
73556 +
73557 +#ifdef CONFIG_DEBUG_LIST
73558 + if (!__list_add_debug(new, prev, next))
73559 + return;
73560 +#endif
73561 +
73562 + pax_open_kernel();
73563 + next->prev = new;
73564 + new->next = next;
73565 + new->prev = prev;
73566 + prev->next = new;
73567 + pax_close_kernel();
73568 +}
73569 +EXPORT_SYMBOL(pax_list_add_tail);
73570 +
73571 +void pax_list_del(struct list_head *entry)
73572 +{
73573 +#ifdef CONFIG_DEBUG_LIST
73574 + if (!__list_del_entry_debug(entry))
73575 + return;
73576 +#endif
73577 +
73578 + pax_open_kernel();
73579 + __list_del(entry->prev, entry->next);
73580 + entry->next = LIST_POISON1;
73581 + entry->prev = LIST_POISON2;
73582 + pax_close_kernel();
73583 +}
73584 +EXPORT_SYMBOL(pax_list_del);
73585 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73586 index e796429..6e38f9f 100644
73587 --- a/lib/radix-tree.c
73588 +++ b/lib/radix-tree.c
73589 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73590 int nr;
73591 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73592 };
73593 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73594 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73595
73596 static inline void *ptr_to_indirect(void *ptr)
73597 {
73598 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73599 index bb2b201..46abaf9 100644
73600 --- a/lib/strncpy_from_user.c
73601 +++ b/lib/strncpy_from_user.c
73602 @@ -21,7 +21,7 @@
73603 */
73604 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73605 {
73606 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73607 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73608 long res = 0;
73609
73610 /*
73611 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73612 index a28df52..3d55877 100644
73613 --- a/lib/strnlen_user.c
73614 +++ b/lib/strnlen_user.c
73615 @@ -26,7 +26,7 @@
73616 */
73617 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73618 {
73619 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73620 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73621 long align, res = 0;
73622 unsigned long c;
73623
73624 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73625 index 39c99fe..18f060b 100644
73626 --- a/lib/vsprintf.c
73627 +++ b/lib/vsprintf.c
73628 @@ -16,6 +16,9 @@
73629 * - scnprintf and vscnprintf
73630 */
73631
73632 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73633 +#define __INCLUDED_BY_HIDESYM 1
73634 +#endif
73635 #include <stdarg.h>
73636 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73637 #include <linux/types.h>
73638 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73639 char sym[KSYM_SYMBOL_LEN];
73640 if (ext == 'B')
73641 sprint_backtrace(sym, value);
73642 - else if (ext != 'f' && ext != 's')
73643 + else if (ext != 'f' && ext != 's' && ext != 'a')
73644 sprint_symbol(sym, value);
73645 else
73646 sprint_symbol_no_offset(sym, value);
73647 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73648 return number(buf, end, *(const netdev_features_t *)addr, spec);
73649 }
73650
73651 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73652 +int kptr_restrict __read_mostly = 2;
73653 +#else
73654 int kptr_restrict __read_mostly;
73655 +#endif
73656
73657 /*
73658 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73659 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73660 * - 'S' For symbolic direct pointers with offset
73661 * - 's' For symbolic direct pointers without offset
73662 * - 'B' For backtraced symbolic direct pointers with offset
73663 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73664 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73665 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73666 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73667 * - 'M' For a 6-byte MAC address, it prints the address in the
73668 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73669
73670 if (!ptr && *fmt != 'K') {
73671 /*
73672 - * Print (null) with the same width as a pointer so it makes
73673 + * Print (nil) with the same width as a pointer so it makes
73674 * tabular output look nice.
73675 */
73676 if (spec.field_width == -1)
73677 spec.field_width = default_width;
73678 - return string(buf, end, "(null)", spec);
73679 + return string(buf, end, "(nil)", spec);
73680 }
73681
73682 switch (*fmt) {
73683 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73684 /* Fallthrough */
73685 case 'S':
73686 case 's':
73687 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73688 + break;
73689 +#else
73690 + return symbol_string(buf, end, ptr, spec, *fmt);
73691 +#endif
73692 + case 'A':
73693 + case 'a':
73694 case 'B':
73695 return symbol_string(buf, end, ptr, spec, *fmt);
73696 case 'R':
73697 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73698 va_end(va);
73699 return buf;
73700 }
73701 + case 'P':
73702 + break;
73703 case 'K':
73704 /*
73705 * %pK cannot be used in IRQ context because its test
73706 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73707 }
73708 break;
73709 }
73710 +
73711 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73712 + /* 'P' = approved pointers to copy to userland,
73713 + as in the /proc/kallsyms case, as we make it display nothing
73714 + for non-root users, and the real contents for root users
73715 + Also ignore 'K' pointers, since we force their NULLing for non-root users
73716 + above
73717 + */
73718 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
73719 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
73720 + dump_stack();
73721 + ptr = NULL;
73722 + }
73723 +#endif
73724 +
73725 spec.flags |= SMALL;
73726 if (spec.field_width == -1) {
73727 spec.field_width = default_width;
73728 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73729 typeof(type) value; \
73730 if (sizeof(type) == 8) { \
73731 args = PTR_ALIGN(args, sizeof(u32)); \
73732 - *(u32 *)&value = *(u32 *)args; \
73733 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
73734 + *(u32 *)&value = *(const u32 *)args; \
73735 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
73736 } else { \
73737 args = PTR_ALIGN(args, sizeof(type)); \
73738 - value = *(typeof(type) *)args; \
73739 + value = *(const typeof(type) *)args; \
73740 } \
73741 args += sizeof(type); \
73742 value; \
73743 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73744 case FORMAT_TYPE_STR: {
73745 const char *str_arg = args;
73746 args += strlen(str_arg) + 1;
73747 - str = string(str, end, (char *)str_arg, spec);
73748 + str = string(str, end, str_arg, spec);
73749 break;
73750 }
73751
73752 diff --git a/localversion-grsec b/localversion-grsec
73753 new file mode 100644
73754 index 0000000..7cd6065
73755 --- /dev/null
73756 +++ b/localversion-grsec
73757 @@ -0,0 +1 @@
73758 +-grsec
73759 diff --git a/mm/Kconfig b/mm/Kconfig
73760 index a3f8ddd..f31e92e 100644
73761 --- a/mm/Kconfig
73762 +++ b/mm/Kconfig
73763 @@ -252,10 +252,10 @@ config KSM
73764 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
73765
73766 config DEFAULT_MMAP_MIN_ADDR
73767 - int "Low address space to protect from user allocation"
73768 + int "Low address space to protect from user allocation"
73769 depends on MMU
73770 - default 4096
73771 - help
73772 + default 65536
73773 + help
73774 This is the portion of low virtual memory which should be protected
73775 from userspace allocation. Keeping a user from writing to low pages
73776 can help reduce the impact of kernel NULL pointer bugs.
73777 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
73778
73779 config HWPOISON_INJECT
73780 tristate "HWPoison pages injector"
73781 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
73782 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
73783 select PROC_PAGE_MONITOR
73784
73785 config NOMMU_INITIAL_TRIM_EXCESS
73786 diff --git a/mm/filemap.c b/mm/filemap.c
73787 index 83efee7..3f99381 100644
73788 --- a/mm/filemap.c
73789 +++ b/mm/filemap.c
73790 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
73791 struct address_space *mapping = file->f_mapping;
73792
73793 if (!mapping->a_ops->readpage)
73794 - return -ENOEXEC;
73795 + return -ENODEV;
73796 file_accessed(file);
73797 vma->vm_ops = &generic_file_vm_ops;
73798 return 0;
73799 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
73800 *pos = i_size_read(inode);
73801
73802 if (limit != RLIM_INFINITY) {
73803 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
73804 if (*pos >= limit) {
73805 send_sig(SIGXFSZ, current, 0);
73806 return -EFBIG;
73807 diff --git a/mm/fremap.c b/mm/fremap.c
73808 index a0aaf0e..20325c3 100644
73809 --- a/mm/fremap.c
73810 +++ b/mm/fremap.c
73811 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
73812 retry:
73813 vma = find_vma(mm, start);
73814
73815 +#ifdef CONFIG_PAX_SEGMEXEC
73816 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
73817 + goto out;
73818 +#endif
73819 +
73820 /*
73821 * Make sure the vma is shared, that it supports prefaulting,
73822 * and that the remapped range is valid and fully within
73823 diff --git a/mm/highmem.c b/mm/highmem.c
73824 index 09fc744..3936897 100644
73825 --- a/mm/highmem.c
73826 +++ b/mm/highmem.c
73827 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
73828 * So no dangers, even with speculative execution.
73829 */
73830 page = pte_page(pkmap_page_table[i]);
73831 + pax_open_kernel();
73832 pte_clear(&init_mm, (unsigned long)page_address(page),
73833 &pkmap_page_table[i]);
73834 -
73835 + pax_close_kernel();
73836 set_page_address(page, NULL);
73837 need_flush = 1;
73838 }
73839 @@ -199,9 +200,11 @@ start:
73840 }
73841 }
73842 vaddr = PKMAP_ADDR(last_pkmap_nr);
73843 +
73844 + pax_open_kernel();
73845 set_pte_at(&init_mm, vaddr,
73846 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
73847 -
73848 + pax_close_kernel();
73849 pkmap_count[last_pkmap_nr] = 1;
73850 set_page_address(page, (void *)vaddr);
73851
73852 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
73853 index 40f17c3..c1cc011 100644
73854 --- a/mm/huge_memory.c
73855 +++ b/mm/huge_memory.c
73856 @@ -710,7 +710,7 @@ out:
73857 * run pte_offset_map on the pmd, if an huge pmd could
73858 * materialize from under us from a different thread.
73859 */
73860 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
73861 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73862 return VM_FAULT_OOM;
73863 /* if an huge pmd materialized from under us just retry later */
73864 if (unlikely(pmd_trans_huge(*pmd)))
73865 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
73866 index f198aca..a19a5a5 100644
73867 --- a/mm/hugetlb.c
73868 +++ b/mm/hugetlb.c
73869 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
73870 return 1;
73871 }
73872
73873 +#ifdef CONFIG_PAX_SEGMEXEC
73874 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
73875 +{
73876 + struct mm_struct *mm = vma->vm_mm;
73877 + struct vm_area_struct *vma_m;
73878 + unsigned long address_m;
73879 + pte_t *ptep_m;
73880 +
73881 + vma_m = pax_find_mirror_vma(vma);
73882 + if (!vma_m)
73883 + return;
73884 +
73885 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
73886 + address_m = address + SEGMEXEC_TASK_SIZE;
73887 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
73888 + get_page(page_m);
73889 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
73890 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
73891 +}
73892 +#endif
73893 +
73894 /*
73895 * Hugetlb_cow() should be called with page lock of the original hugepage held.
73896 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
73897 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
73898 make_huge_pte(vma, new_page, 1));
73899 page_remove_rmap(old_page);
73900 hugepage_add_new_anon_rmap(new_page, vma, address);
73901 +
73902 +#ifdef CONFIG_PAX_SEGMEXEC
73903 + pax_mirror_huge_pte(vma, address, new_page);
73904 +#endif
73905 +
73906 /* Make the old page be freed below */
73907 new_page = old_page;
73908 }
73909 @@ -2786,6 +2812,10 @@ retry:
73910 && (vma->vm_flags & VM_SHARED)));
73911 set_huge_pte_at(mm, address, ptep, new_pte);
73912
73913 +#ifdef CONFIG_PAX_SEGMEXEC
73914 + pax_mirror_huge_pte(vma, address, page);
73915 +#endif
73916 +
73917 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
73918 /* Optimization, do the COW without a second fault */
73919 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
73920 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73921 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
73922 struct hstate *h = hstate_vma(vma);
73923
73924 +#ifdef CONFIG_PAX_SEGMEXEC
73925 + struct vm_area_struct *vma_m;
73926 +#endif
73927 +
73928 address &= huge_page_mask(h);
73929
73930 ptep = huge_pte_offset(mm, address);
73931 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73932 VM_FAULT_SET_HINDEX(hstate_index(h));
73933 }
73934
73935 +#ifdef CONFIG_PAX_SEGMEXEC
73936 + vma_m = pax_find_mirror_vma(vma);
73937 + if (vma_m) {
73938 + unsigned long address_m;
73939 +
73940 + if (vma->vm_start > vma_m->vm_start) {
73941 + address_m = address;
73942 + address -= SEGMEXEC_TASK_SIZE;
73943 + vma = vma_m;
73944 + h = hstate_vma(vma);
73945 + } else
73946 + address_m = address + SEGMEXEC_TASK_SIZE;
73947 +
73948 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
73949 + return VM_FAULT_OOM;
73950 + address_m &= HPAGE_MASK;
73951 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
73952 + }
73953 +#endif
73954 +
73955 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
73956 if (!ptep)
73957 return VM_FAULT_OOM;
73958 diff --git a/mm/internal.h b/mm/internal.h
73959 index 3c5197d..08d0065 100644
73960 --- a/mm/internal.h
73961 +++ b/mm/internal.h
73962 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
73963 * in mm/page_alloc.c
73964 */
73965 extern void __free_pages_bootmem(struct page *page, unsigned int order);
73966 +extern void free_compound_page(struct page *page);
73967 extern void prep_compound_page(struct page *page, unsigned long order);
73968 #ifdef CONFIG_MEMORY_FAILURE
73969 extern bool is_free_buddy_page(struct page *page);
73970 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
73971 index a217cc5..44b2b35 100644
73972 --- a/mm/kmemleak.c
73973 +++ b/mm/kmemleak.c
73974 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
73975
73976 for (i = 0; i < object->trace_len; i++) {
73977 void *ptr = (void *)object->trace[i];
73978 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
73979 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
73980 }
73981 }
73982
73983 @@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
73984 return -ENOMEM;
73985 }
73986
73987 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
73988 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
73989 &kmemleak_fops);
73990 if (!dentry)
73991 pr_warning("Failed to create the debugfs kmemleak file\n");
73992 diff --git a/mm/maccess.c b/mm/maccess.c
73993 index d53adf9..03a24bf 100644
73994 --- a/mm/maccess.c
73995 +++ b/mm/maccess.c
73996 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
73997 set_fs(KERNEL_DS);
73998 pagefault_disable();
73999 ret = __copy_from_user_inatomic(dst,
74000 - (__force const void __user *)src, size);
74001 + (const void __force_user *)src, size);
74002 pagefault_enable();
74003 set_fs(old_fs);
74004
74005 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74006
74007 set_fs(KERNEL_DS);
74008 pagefault_disable();
74009 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74010 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74011 pagefault_enable();
74012 set_fs(old_fs);
74013
74014 diff --git a/mm/madvise.c b/mm/madvise.c
74015 index 03dfa5c..b032917 100644
74016 --- a/mm/madvise.c
74017 +++ b/mm/madvise.c
74018 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74019 pgoff_t pgoff;
74020 unsigned long new_flags = vma->vm_flags;
74021
74022 +#ifdef CONFIG_PAX_SEGMEXEC
74023 + struct vm_area_struct *vma_m;
74024 +#endif
74025 +
74026 switch (behavior) {
74027 case MADV_NORMAL:
74028 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74029 @@ -123,6 +127,13 @@ success:
74030 /*
74031 * vm_flags is protected by the mmap_sem held in write mode.
74032 */
74033 +
74034 +#ifdef CONFIG_PAX_SEGMEXEC
74035 + vma_m = pax_find_mirror_vma(vma);
74036 + if (vma_m)
74037 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74038 +#endif
74039 +
74040 vma->vm_flags = new_flags;
74041
74042 out:
74043 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74044 struct vm_area_struct ** prev,
74045 unsigned long start, unsigned long end)
74046 {
74047 +
74048 +#ifdef CONFIG_PAX_SEGMEXEC
74049 + struct vm_area_struct *vma_m;
74050 +#endif
74051 +
74052 *prev = vma;
74053 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74054 return -EINVAL;
74055 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74056 zap_page_range(vma, start, end - start, &details);
74057 } else
74058 zap_page_range(vma, start, end - start, NULL);
74059 +
74060 +#ifdef CONFIG_PAX_SEGMEXEC
74061 + vma_m = pax_find_mirror_vma(vma);
74062 + if (vma_m) {
74063 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74064 + struct zap_details details = {
74065 + .nonlinear_vma = vma_m,
74066 + .last_index = ULONG_MAX,
74067 + };
74068 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74069 + } else
74070 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74071 + }
74072 +#endif
74073 +
74074 return 0;
74075 }
74076
74077 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74078 if (end < start)
74079 goto out;
74080
74081 +#ifdef CONFIG_PAX_SEGMEXEC
74082 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74083 + if (end > SEGMEXEC_TASK_SIZE)
74084 + goto out;
74085 + } else
74086 +#endif
74087 +
74088 + if (end > TASK_SIZE)
74089 + goto out;
74090 +
74091 error = 0;
74092 if (end == start)
74093 goto out;
74094 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74095 index 8b20278..05dac18 100644
74096 --- a/mm/memory-failure.c
74097 +++ b/mm/memory-failure.c
74098 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74099
74100 int sysctl_memory_failure_recovery __read_mostly = 1;
74101
74102 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74103 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74104
74105 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74106
74107 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74108 pfn, t->comm, t->pid);
74109 si.si_signo = SIGBUS;
74110 si.si_errno = 0;
74111 - si.si_addr = (void *)addr;
74112 + si.si_addr = (void __user *)addr;
74113 #ifdef __ARCH_SI_TRAPNO
74114 si.si_trapno = trapno;
74115 #endif
74116 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74117 }
74118
74119 nr_pages = 1 << compound_trans_order(hpage);
74120 - atomic_long_add(nr_pages, &mce_bad_pages);
74121 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74122
74123 /*
74124 * We need/can do nothing about count=0 pages.
74125 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74126 if (!PageHWPoison(hpage)
74127 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74128 || (p != hpage && TestSetPageHWPoison(hpage))) {
74129 - atomic_long_sub(nr_pages, &mce_bad_pages);
74130 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74131 return 0;
74132 }
74133 set_page_hwpoison_huge_page(hpage);
74134 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74135 }
74136 if (hwpoison_filter(p)) {
74137 if (TestClearPageHWPoison(p))
74138 - atomic_long_sub(nr_pages, &mce_bad_pages);
74139 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74140 unlock_page(hpage);
74141 put_page(hpage);
74142 return 0;
74143 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74144 return 0;
74145 }
74146 if (TestClearPageHWPoison(p))
74147 - atomic_long_sub(nr_pages, &mce_bad_pages);
74148 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74149 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74150 return 0;
74151 }
74152 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74153 */
74154 if (TestClearPageHWPoison(page)) {
74155 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74156 - atomic_long_sub(nr_pages, &mce_bad_pages);
74157 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74158 freeit = 1;
74159 if (PageHuge(page))
74160 clear_page_hwpoison_huge_page(page);
74161 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74162 }
74163 done:
74164 if (!PageHWPoison(hpage))
74165 - atomic_long_add(1 << compound_trans_order(hpage),
74166 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74167 &mce_bad_pages);
74168 set_page_hwpoison_huge_page(hpage);
74169 dequeue_hwpoisoned_huge_page(hpage);
74170 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74171 return ret;
74172
74173 done:
74174 - atomic_long_add(1, &mce_bad_pages);
74175 + atomic_long_add_unchecked(1, &mce_bad_pages);
74176 SetPageHWPoison(page);
74177 /* keep elevated page count for bad page */
74178 return ret;
74179 diff --git a/mm/memory.c b/mm/memory.c
74180 index f2973b2..fd020a7 100644
74181 --- a/mm/memory.c
74182 +++ b/mm/memory.c
74183 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74184 free_pte_range(tlb, pmd, addr);
74185 } while (pmd++, addr = next, addr != end);
74186
74187 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74188 start &= PUD_MASK;
74189 if (start < floor)
74190 return;
74191 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74192 pmd = pmd_offset(pud, start);
74193 pud_clear(pud);
74194 pmd_free_tlb(tlb, pmd, start);
74195 +#endif
74196 +
74197 }
74198
74199 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74200 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74201 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74202 } while (pud++, addr = next, addr != end);
74203
74204 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74205 start &= PGDIR_MASK;
74206 if (start < floor)
74207 return;
74208 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74209 pud = pud_offset(pgd, start);
74210 pgd_clear(pgd);
74211 pud_free_tlb(tlb, pud, start);
74212 +#endif
74213 +
74214 }
74215
74216 /*
74217 @@ -1626,12 +1632,6 @@ no_page_table:
74218 return page;
74219 }
74220
74221 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74222 -{
74223 - return stack_guard_page_start(vma, addr) ||
74224 - stack_guard_page_end(vma, addr+PAGE_SIZE);
74225 -}
74226 -
74227 /**
74228 * __get_user_pages() - pin user pages in memory
74229 * @tsk: task_struct of target task
74230 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74231 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74232 i = 0;
74233
74234 - do {
74235 + while (nr_pages) {
74236 struct vm_area_struct *vma;
74237
74238 - vma = find_extend_vma(mm, start);
74239 + vma = find_vma(mm, start);
74240 if (!vma && in_gate_area(mm, start)) {
74241 unsigned long pg = start & PAGE_MASK;
74242 pgd_t *pgd;
74243 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74244 goto next_page;
74245 }
74246
74247 - if (!vma ||
74248 + if (!vma || start < vma->vm_start ||
74249 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74250 !(vm_flags & vma->vm_flags))
74251 return i ? : -EFAULT;
74252 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74253 int ret;
74254 unsigned int fault_flags = 0;
74255
74256 - /* For mlock, just skip the stack guard page. */
74257 - if (foll_flags & FOLL_MLOCK) {
74258 - if (stack_guard_page(vma, start))
74259 - goto next_page;
74260 - }
74261 if (foll_flags & FOLL_WRITE)
74262 fault_flags |= FAULT_FLAG_WRITE;
74263 if (nonblocking)
74264 @@ -1860,7 +1855,7 @@ next_page:
74265 start += PAGE_SIZE;
74266 nr_pages--;
74267 } while (nr_pages && start < vma->vm_end);
74268 - } while (nr_pages);
74269 + }
74270 return i;
74271 }
74272 EXPORT_SYMBOL(__get_user_pages);
74273 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74274 page_add_file_rmap(page);
74275 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74276
74277 +#ifdef CONFIG_PAX_SEGMEXEC
74278 + pax_mirror_file_pte(vma, addr, page, ptl);
74279 +#endif
74280 +
74281 retval = 0;
74282 pte_unmap_unlock(pte, ptl);
74283 return retval;
74284 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74285 if (!page_count(page))
74286 return -EINVAL;
74287 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74288 +
74289 +#ifdef CONFIG_PAX_SEGMEXEC
74290 + struct vm_area_struct *vma_m;
74291 +#endif
74292 +
74293 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74294 BUG_ON(vma->vm_flags & VM_PFNMAP);
74295 vma->vm_flags |= VM_MIXEDMAP;
74296 +
74297 +#ifdef CONFIG_PAX_SEGMEXEC
74298 + vma_m = pax_find_mirror_vma(vma);
74299 + if (vma_m)
74300 + vma_m->vm_flags |= VM_MIXEDMAP;
74301 +#endif
74302 +
74303 }
74304 return insert_page(vma, addr, page, vma->vm_page_prot);
74305 }
74306 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74307 unsigned long pfn)
74308 {
74309 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74310 + BUG_ON(vma->vm_mirror);
74311
74312 if (addr < vma->vm_start || addr >= vma->vm_end)
74313 return -EFAULT;
74314 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74315
74316 BUG_ON(pud_huge(*pud));
74317
74318 - pmd = pmd_alloc(mm, pud, addr);
74319 + pmd = (mm == &init_mm) ?
74320 + pmd_alloc_kernel(mm, pud, addr) :
74321 + pmd_alloc(mm, pud, addr);
74322 if (!pmd)
74323 return -ENOMEM;
74324 do {
74325 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74326 unsigned long next;
74327 int err;
74328
74329 - pud = pud_alloc(mm, pgd, addr);
74330 + pud = (mm == &init_mm) ?
74331 + pud_alloc_kernel(mm, pgd, addr) :
74332 + pud_alloc(mm, pgd, addr);
74333 if (!pud)
74334 return -ENOMEM;
74335 do {
74336 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74337 copy_user_highpage(dst, src, va, vma);
74338 }
74339
74340 +#ifdef CONFIG_PAX_SEGMEXEC
74341 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74342 +{
74343 + struct mm_struct *mm = vma->vm_mm;
74344 + spinlock_t *ptl;
74345 + pte_t *pte, entry;
74346 +
74347 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74348 + entry = *pte;
74349 + if (!pte_present(entry)) {
74350 + if (!pte_none(entry)) {
74351 + BUG_ON(pte_file(entry));
74352 + free_swap_and_cache(pte_to_swp_entry(entry));
74353 + pte_clear_not_present_full(mm, address, pte, 0);
74354 + }
74355 + } else {
74356 + struct page *page;
74357 +
74358 + flush_cache_page(vma, address, pte_pfn(entry));
74359 + entry = ptep_clear_flush(vma, address, pte);
74360 + BUG_ON(pte_dirty(entry));
74361 + page = vm_normal_page(vma, address, entry);
74362 + if (page) {
74363 + update_hiwater_rss(mm);
74364 + if (PageAnon(page))
74365 + dec_mm_counter_fast(mm, MM_ANONPAGES);
74366 + else
74367 + dec_mm_counter_fast(mm, MM_FILEPAGES);
74368 + page_remove_rmap(page);
74369 + page_cache_release(page);
74370 + }
74371 + }
74372 + pte_unmap_unlock(pte, ptl);
74373 +}
74374 +
74375 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
74376 + *
74377 + * the ptl of the lower mapped page is held on entry and is not released on exit
74378 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74379 + */
74380 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74381 +{
74382 + struct mm_struct *mm = vma->vm_mm;
74383 + unsigned long address_m;
74384 + spinlock_t *ptl_m;
74385 + struct vm_area_struct *vma_m;
74386 + pmd_t *pmd_m;
74387 + pte_t *pte_m, entry_m;
74388 +
74389 + BUG_ON(!page_m || !PageAnon(page_m));
74390 +
74391 + vma_m = pax_find_mirror_vma(vma);
74392 + if (!vma_m)
74393 + return;
74394 +
74395 + BUG_ON(!PageLocked(page_m));
74396 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74397 + address_m = address + SEGMEXEC_TASK_SIZE;
74398 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74399 + pte_m = pte_offset_map(pmd_m, address_m);
74400 + ptl_m = pte_lockptr(mm, pmd_m);
74401 + if (ptl != ptl_m) {
74402 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74403 + if (!pte_none(*pte_m))
74404 + goto out;
74405 + }
74406 +
74407 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74408 + page_cache_get(page_m);
74409 + page_add_anon_rmap(page_m, vma_m, address_m);
74410 + inc_mm_counter_fast(mm, MM_ANONPAGES);
74411 + set_pte_at(mm, address_m, pte_m, entry_m);
74412 + update_mmu_cache(vma_m, address_m, entry_m);
74413 +out:
74414 + if (ptl != ptl_m)
74415 + spin_unlock(ptl_m);
74416 + pte_unmap(pte_m);
74417 + unlock_page(page_m);
74418 +}
74419 +
74420 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74421 +{
74422 + struct mm_struct *mm = vma->vm_mm;
74423 + unsigned long address_m;
74424 + spinlock_t *ptl_m;
74425 + struct vm_area_struct *vma_m;
74426 + pmd_t *pmd_m;
74427 + pte_t *pte_m, entry_m;
74428 +
74429 + BUG_ON(!page_m || PageAnon(page_m));
74430 +
74431 + vma_m = pax_find_mirror_vma(vma);
74432 + if (!vma_m)
74433 + return;
74434 +
74435 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74436 + address_m = address + SEGMEXEC_TASK_SIZE;
74437 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74438 + pte_m = pte_offset_map(pmd_m, address_m);
74439 + ptl_m = pte_lockptr(mm, pmd_m);
74440 + if (ptl != ptl_m) {
74441 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74442 + if (!pte_none(*pte_m))
74443 + goto out;
74444 + }
74445 +
74446 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74447 + page_cache_get(page_m);
74448 + page_add_file_rmap(page_m);
74449 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74450 + set_pte_at(mm, address_m, pte_m, entry_m);
74451 + update_mmu_cache(vma_m, address_m, entry_m);
74452 +out:
74453 + if (ptl != ptl_m)
74454 + spin_unlock(ptl_m);
74455 + pte_unmap(pte_m);
74456 +}
74457 +
74458 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74459 +{
74460 + struct mm_struct *mm = vma->vm_mm;
74461 + unsigned long address_m;
74462 + spinlock_t *ptl_m;
74463 + struct vm_area_struct *vma_m;
74464 + pmd_t *pmd_m;
74465 + pte_t *pte_m, entry_m;
74466 +
74467 + vma_m = pax_find_mirror_vma(vma);
74468 + if (!vma_m)
74469 + return;
74470 +
74471 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74472 + address_m = address + SEGMEXEC_TASK_SIZE;
74473 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74474 + pte_m = pte_offset_map(pmd_m, address_m);
74475 + ptl_m = pte_lockptr(mm, pmd_m);
74476 + if (ptl != ptl_m) {
74477 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74478 + if (!pte_none(*pte_m))
74479 + goto out;
74480 + }
74481 +
74482 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74483 + set_pte_at(mm, address_m, pte_m, entry_m);
74484 +out:
74485 + if (ptl != ptl_m)
74486 + spin_unlock(ptl_m);
74487 + pte_unmap(pte_m);
74488 +}
74489 +
74490 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74491 +{
74492 + struct page *page_m;
74493 + pte_t entry;
74494 +
74495 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74496 + goto out;
74497 +
74498 + entry = *pte;
74499 + page_m = vm_normal_page(vma, address, entry);
74500 + if (!page_m)
74501 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74502 + else if (PageAnon(page_m)) {
74503 + if (pax_find_mirror_vma(vma)) {
74504 + pte_unmap_unlock(pte, ptl);
74505 + lock_page(page_m);
74506 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74507 + if (pte_same(entry, *pte))
74508 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74509 + else
74510 + unlock_page(page_m);
74511 + }
74512 + } else
74513 + pax_mirror_file_pte(vma, address, page_m, ptl);
74514 +
74515 +out:
74516 + pte_unmap_unlock(pte, ptl);
74517 +}
74518 +#endif
74519 +
74520 /*
74521 * This routine handles present pages, when users try to write
74522 * to a shared page. It is done by copying the page to a new address
74523 @@ -2720,6 +2916,12 @@ gotten:
74524 */
74525 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74526 if (likely(pte_same(*page_table, orig_pte))) {
74527 +
74528 +#ifdef CONFIG_PAX_SEGMEXEC
74529 + if (pax_find_mirror_vma(vma))
74530 + BUG_ON(!trylock_page(new_page));
74531 +#endif
74532 +
74533 if (old_page) {
74534 if (!PageAnon(old_page)) {
74535 dec_mm_counter_fast(mm, MM_FILEPAGES);
74536 @@ -2771,6 +2973,10 @@ gotten:
74537 page_remove_rmap(old_page);
74538 }
74539
74540 +#ifdef CONFIG_PAX_SEGMEXEC
74541 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74542 +#endif
74543 +
74544 /* Free the old page.. */
74545 new_page = old_page;
74546 ret |= VM_FAULT_WRITE;
74547 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74548 swap_free(entry);
74549 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74550 try_to_free_swap(page);
74551 +
74552 +#ifdef CONFIG_PAX_SEGMEXEC
74553 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74554 +#endif
74555 +
74556 unlock_page(page);
74557 if (swapcache) {
74558 /*
74559 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74560
74561 /* No need to invalidate - it was non-present before */
74562 update_mmu_cache(vma, address, page_table);
74563 +
74564 +#ifdef CONFIG_PAX_SEGMEXEC
74565 + pax_mirror_anon_pte(vma, address, page, ptl);
74566 +#endif
74567 +
74568 unlock:
74569 pte_unmap_unlock(page_table, ptl);
74570 out:
74571 @@ -3093,40 +3309,6 @@ out_release:
74572 }
74573
74574 /*
74575 - * This is like a special single-page "expand_{down|up}wards()",
74576 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74577 - * doesn't hit another vma.
74578 - */
74579 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74580 -{
74581 - address &= PAGE_MASK;
74582 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74583 - struct vm_area_struct *prev = vma->vm_prev;
74584 -
74585 - /*
74586 - * Is there a mapping abutting this one below?
74587 - *
74588 - * That's only ok if it's the same stack mapping
74589 - * that has gotten split..
74590 - */
74591 - if (prev && prev->vm_end == address)
74592 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74593 -
74594 - expand_downwards(vma, address - PAGE_SIZE);
74595 - }
74596 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74597 - struct vm_area_struct *next = vma->vm_next;
74598 -
74599 - /* As VM_GROWSDOWN but s/below/above/ */
74600 - if (next && next->vm_start == address + PAGE_SIZE)
74601 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74602 -
74603 - expand_upwards(vma, address + PAGE_SIZE);
74604 - }
74605 - return 0;
74606 -}
74607 -
74608 -/*
74609 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74610 * but allow concurrent faults), and pte mapped but not yet locked.
74611 * We return with mmap_sem still held, but pte unmapped and unlocked.
74612 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74613 unsigned long address, pte_t *page_table, pmd_t *pmd,
74614 unsigned int flags)
74615 {
74616 - struct page *page;
74617 + struct page *page = NULL;
74618 spinlock_t *ptl;
74619 pte_t entry;
74620
74621 - pte_unmap(page_table);
74622 -
74623 - /* Check if we need to add a guard page to the stack */
74624 - if (check_stack_guard_page(vma, address) < 0)
74625 - return VM_FAULT_SIGBUS;
74626 -
74627 - /* Use the zero-page for reads */
74628 if (!(flags & FAULT_FLAG_WRITE)) {
74629 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74630 vma->vm_page_prot));
74631 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74632 + ptl = pte_lockptr(mm, pmd);
74633 + spin_lock(ptl);
74634 if (!pte_none(*page_table))
74635 goto unlock;
74636 goto setpte;
74637 }
74638
74639 /* Allocate our own private page. */
74640 + pte_unmap(page_table);
74641 +
74642 if (unlikely(anon_vma_prepare(vma)))
74643 goto oom;
74644 page = alloc_zeroed_user_highpage_movable(vma, address);
74645 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74646 if (!pte_none(*page_table))
74647 goto release;
74648
74649 +#ifdef CONFIG_PAX_SEGMEXEC
74650 + if (pax_find_mirror_vma(vma))
74651 + BUG_ON(!trylock_page(page));
74652 +#endif
74653 +
74654 inc_mm_counter_fast(mm, MM_ANONPAGES);
74655 page_add_new_anon_rmap(page, vma, address);
74656 setpte:
74657 @@ -3181,6 +3364,12 @@ setpte:
74658
74659 /* No need to invalidate - it was non-present before */
74660 update_mmu_cache(vma, address, page_table);
74661 +
74662 +#ifdef CONFIG_PAX_SEGMEXEC
74663 + if (page)
74664 + pax_mirror_anon_pte(vma, address, page, ptl);
74665 +#endif
74666 +
74667 unlock:
74668 pte_unmap_unlock(page_table, ptl);
74669 return 0;
74670 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74671 */
74672 /* Only go through if we didn't race with anybody else... */
74673 if (likely(pte_same(*page_table, orig_pte))) {
74674 +
74675 +#ifdef CONFIG_PAX_SEGMEXEC
74676 + if (anon && pax_find_mirror_vma(vma))
74677 + BUG_ON(!trylock_page(page));
74678 +#endif
74679 +
74680 flush_icache_page(vma, page);
74681 entry = mk_pte(page, vma->vm_page_prot);
74682 if (flags & FAULT_FLAG_WRITE)
74683 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74684
74685 /* no need to invalidate: a not-present page won't be cached */
74686 update_mmu_cache(vma, address, page_table);
74687 +
74688 +#ifdef CONFIG_PAX_SEGMEXEC
74689 + if (anon)
74690 + pax_mirror_anon_pte(vma, address, page, ptl);
74691 + else
74692 + pax_mirror_file_pte(vma, address, page, ptl);
74693 +#endif
74694 +
74695 } else {
74696 if (cow_page)
74697 mem_cgroup_uncharge_page(cow_page);
74698 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
74699 if (flags & FAULT_FLAG_WRITE)
74700 flush_tlb_fix_spurious_fault(vma, address);
74701 }
74702 +
74703 +#ifdef CONFIG_PAX_SEGMEXEC
74704 + pax_mirror_pte(vma, address, pte, pmd, ptl);
74705 + return 0;
74706 +#endif
74707 +
74708 unlock:
74709 pte_unmap_unlock(pte, ptl);
74710 return 0;
74711 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74712 pmd_t *pmd;
74713 pte_t *pte;
74714
74715 +#ifdef CONFIG_PAX_SEGMEXEC
74716 + struct vm_area_struct *vma_m;
74717 +#endif
74718 +
74719 __set_current_state(TASK_RUNNING);
74720
74721 count_vm_event(PGFAULT);
74722 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74723 if (unlikely(is_vm_hugetlb_page(vma)))
74724 return hugetlb_fault(mm, vma, address, flags);
74725
74726 +#ifdef CONFIG_PAX_SEGMEXEC
74727 + vma_m = pax_find_mirror_vma(vma);
74728 + if (vma_m) {
74729 + unsigned long address_m;
74730 + pgd_t *pgd_m;
74731 + pud_t *pud_m;
74732 + pmd_t *pmd_m;
74733 +
74734 + if (vma->vm_start > vma_m->vm_start) {
74735 + address_m = address;
74736 + address -= SEGMEXEC_TASK_SIZE;
74737 + vma = vma_m;
74738 + } else
74739 + address_m = address + SEGMEXEC_TASK_SIZE;
74740 +
74741 + pgd_m = pgd_offset(mm, address_m);
74742 + pud_m = pud_alloc(mm, pgd_m, address_m);
74743 + if (!pud_m)
74744 + return VM_FAULT_OOM;
74745 + pmd_m = pmd_alloc(mm, pud_m, address_m);
74746 + if (!pmd_m)
74747 + return VM_FAULT_OOM;
74748 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
74749 + return VM_FAULT_OOM;
74750 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
74751 + }
74752 +#endif
74753 +
74754 retry:
74755 pgd = pgd_offset(mm, address);
74756 pud = pud_alloc(mm, pgd, address);
74757 @@ -3565,7 +3806,7 @@ retry:
74758 * run pte_offset_map on the pmd, if an huge pmd could
74759 * materialize from under us from a different thread.
74760 */
74761 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
74762 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74763 return VM_FAULT_OOM;
74764 /* if an huge pmd materialized from under us just retry later */
74765 if (unlikely(pmd_trans_huge(*pmd)))
74766 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74767 spin_unlock(&mm->page_table_lock);
74768 return 0;
74769 }
74770 +
74771 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74772 +{
74773 + pud_t *new = pud_alloc_one(mm, address);
74774 + if (!new)
74775 + return -ENOMEM;
74776 +
74777 + smp_wmb(); /* See comment in __pte_alloc */
74778 +
74779 + spin_lock(&mm->page_table_lock);
74780 + if (pgd_present(*pgd)) /* Another has populated it */
74781 + pud_free(mm, new);
74782 + else
74783 + pgd_populate_kernel(mm, pgd, new);
74784 + spin_unlock(&mm->page_table_lock);
74785 + return 0;
74786 +}
74787 #endif /* __PAGETABLE_PUD_FOLDED */
74788
74789 #ifndef __PAGETABLE_PMD_FOLDED
74790 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74791 spin_unlock(&mm->page_table_lock);
74792 return 0;
74793 }
74794 +
74795 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74796 +{
74797 + pmd_t *new = pmd_alloc_one(mm, address);
74798 + if (!new)
74799 + return -ENOMEM;
74800 +
74801 + smp_wmb(); /* See comment in __pte_alloc */
74802 +
74803 + spin_lock(&mm->page_table_lock);
74804 +#ifndef __ARCH_HAS_4LEVEL_HACK
74805 + if (pud_present(*pud)) /* Another has populated it */
74806 + pmd_free(mm, new);
74807 + else
74808 + pud_populate_kernel(mm, pud, new);
74809 +#else
74810 + if (pgd_present(*pud)) /* Another has populated it */
74811 + pmd_free(mm, new);
74812 + else
74813 + pgd_populate_kernel(mm, pud, new);
74814 +#endif /* __ARCH_HAS_4LEVEL_HACK */
74815 + spin_unlock(&mm->page_table_lock);
74816 + return 0;
74817 +}
74818 #endif /* __PAGETABLE_PMD_FOLDED */
74819
74820 int make_pages_present(unsigned long addr, unsigned long end)
74821 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
74822 gate_vma.vm_start = FIXADDR_USER_START;
74823 gate_vma.vm_end = FIXADDR_USER_END;
74824 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
74825 - gate_vma.vm_page_prot = __P101;
74826 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
74827
74828 return 0;
74829 }
74830 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
74831 index 002c281..9429765 100644
74832 --- a/mm/mempolicy.c
74833 +++ b/mm/mempolicy.c
74834 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74835 unsigned long vmstart;
74836 unsigned long vmend;
74837
74838 +#ifdef CONFIG_PAX_SEGMEXEC
74839 + struct vm_area_struct *vma_m;
74840 +#endif
74841 +
74842 vma = find_vma(mm, start);
74843 if (!vma || vma->vm_start > start)
74844 return -EFAULT;
74845 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74846 if (err)
74847 goto out;
74848 }
74849 +
74850 err = vma_replace_policy(vma, new_pol);
74851 if (err)
74852 goto out;
74853 +
74854 +#ifdef CONFIG_PAX_SEGMEXEC
74855 + vma_m = pax_find_mirror_vma(vma);
74856 + if (vma_m) {
74857 + err = vma_replace_policy(vma_m, new_pol);
74858 + if (err)
74859 + goto out;
74860 + }
74861 +#endif
74862 +
74863 }
74864
74865 out:
74866 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
74867
74868 if (end < start)
74869 return -EINVAL;
74870 +
74871 +#ifdef CONFIG_PAX_SEGMEXEC
74872 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74873 + if (end > SEGMEXEC_TASK_SIZE)
74874 + return -EINVAL;
74875 + } else
74876 +#endif
74877 +
74878 + if (end > TASK_SIZE)
74879 + return -EINVAL;
74880 +
74881 if (end == start)
74882 return 0;
74883
74884 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74885 */
74886 tcred = __task_cred(task);
74887 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74888 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74889 - !capable(CAP_SYS_NICE)) {
74890 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74891 rcu_read_unlock();
74892 err = -EPERM;
74893 goto out_put;
74894 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74895 goto out;
74896 }
74897
74898 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
74899 + if (mm != current->mm &&
74900 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
74901 + mmput(mm);
74902 + err = -EPERM;
74903 + goto out;
74904 + }
74905 +#endif
74906 +
74907 err = do_migrate_pages(mm, old, new,
74908 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
74909
74910 diff --git a/mm/migrate.c b/mm/migrate.c
74911 index 77ed2d7..317d528 100644
74912 --- a/mm/migrate.c
74913 +++ b/mm/migrate.c
74914 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
74915 */
74916 tcred = __task_cred(task);
74917 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74918 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74919 - !capable(CAP_SYS_NICE)) {
74920 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74921 rcu_read_unlock();
74922 err = -EPERM;
74923 goto out;
74924 diff --git a/mm/mlock.c b/mm/mlock.c
74925 index f0b9ce5..da8d069 100644
74926 --- a/mm/mlock.c
74927 +++ b/mm/mlock.c
74928 @@ -13,6 +13,7 @@
74929 #include <linux/pagemap.h>
74930 #include <linux/mempolicy.h>
74931 #include <linux/syscalls.h>
74932 +#include <linux/security.h>
74933 #include <linux/sched.h>
74934 #include <linux/export.h>
74935 #include <linux/rmap.h>
74936 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
74937 {
74938 unsigned long nstart, end, tmp;
74939 struct vm_area_struct * vma, * prev;
74940 - int error;
74941 + int error = 0;
74942
74943 VM_BUG_ON(start & ~PAGE_MASK);
74944 VM_BUG_ON(len != PAGE_ALIGN(len));
74945 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
74946 return -EINVAL;
74947 if (end == start)
74948 return 0;
74949 + if (end > TASK_SIZE)
74950 + return -EINVAL;
74951 +
74952 vma = find_vma(current->mm, start);
74953 if (!vma || vma->vm_start > start)
74954 return -ENOMEM;
74955 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
74956 for (nstart = start ; ; ) {
74957 vm_flags_t newflags;
74958
74959 +#ifdef CONFIG_PAX_SEGMEXEC
74960 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74961 + break;
74962 +#endif
74963 +
74964 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
74965
74966 newflags = vma->vm_flags | VM_LOCKED;
74967 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
74968 lock_limit >>= PAGE_SHIFT;
74969
74970 /* check against resource limits */
74971 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
74972 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
74973 error = do_mlock(start, len, 1);
74974 up_write(&current->mm->mmap_sem);
74975 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
74976 static int do_mlockall(int flags)
74977 {
74978 struct vm_area_struct * vma, * prev = NULL;
74979 - unsigned int def_flags = 0;
74980
74981 if (flags & MCL_FUTURE)
74982 - def_flags = VM_LOCKED;
74983 - current->mm->def_flags = def_flags;
74984 + current->mm->def_flags |= VM_LOCKED;
74985 + else
74986 + current->mm->def_flags &= ~VM_LOCKED;
74987 if (flags == MCL_FUTURE)
74988 goto out;
74989
74990 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
74991 vm_flags_t newflags;
74992
74993 +#ifdef CONFIG_PAX_SEGMEXEC
74994 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74995 + break;
74996 +#endif
74997 +
74998 + BUG_ON(vma->vm_end > TASK_SIZE);
74999 newflags = vma->vm_flags | VM_LOCKED;
75000 if (!(flags & MCL_CURRENT))
75001 newflags &= ~VM_LOCKED;
75002 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75003 lock_limit >>= PAGE_SHIFT;
75004
75005 ret = -ENOMEM;
75006 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75007 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75008 capable(CAP_IPC_LOCK))
75009 ret = do_mlockall(flags);
75010 diff --git a/mm/mmap.c b/mm/mmap.c
75011 index 9a796c4..21f8e50 100644
75012 --- a/mm/mmap.c
75013 +++ b/mm/mmap.c
75014 @@ -31,6 +31,7 @@
75015 #include <linux/audit.h>
75016 #include <linux/khugepaged.h>
75017 #include <linux/uprobes.h>
75018 +#include <linux/random.h>
75019
75020 #include <asm/uaccess.h>
75021 #include <asm/cacheflush.h>
75022 @@ -47,6 +48,16 @@
75023 #define arch_rebalance_pgtables(addr, len) (addr)
75024 #endif
75025
75026 +static inline void verify_mm_writelocked(struct mm_struct *mm)
75027 +{
75028 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75029 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75030 + up_read(&mm->mmap_sem);
75031 + BUG();
75032 + }
75033 +#endif
75034 +}
75035 +
75036 static void unmap_region(struct mm_struct *mm,
75037 struct vm_area_struct *vma, struct vm_area_struct *prev,
75038 unsigned long start, unsigned long end);
75039 @@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75040 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75041 *
75042 */
75043 -pgprot_t protection_map[16] = {
75044 +pgprot_t protection_map[16] __read_only = {
75045 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75046 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75047 };
75048
75049 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
75050 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75051 {
75052 - return __pgprot(pgprot_val(protection_map[vm_flags &
75053 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75054 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75055 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75056 +
75057 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75058 + if (!(__supported_pte_mask & _PAGE_NX) &&
75059 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75060 + (vm_flags & (VM_READ | VM_WRITE)))
75061 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75062 +#endif
75063 +
75064 + return prot;
75065 }
75066 EXPORT_SYMBOL(vm_get_page_prot);
75067
75068 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75069 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75070 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75071 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75072 /*
75073 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75074 * other variables. It can be updated by several CPUs frequently.
75075 @@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75076 struct vm_area_struct *next = vma->vm_next;
75077
75078 might_sleep();
75079 + BUG_ON(vma->vm_mirror);
75080 if (vma->vm_ops && vma->vm_ops->close)
75081 vma->vm_ops->close(vma);
75082 if (vma->vm_file)
75083 @@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75084 * not page aligned -Ram Gupta
75085 */
75086 rlim = rlimit(RLIMIT_DATA);
75087 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75088 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75089 (mm->end_data - mm->start_data) > rlim)
75090 goto out;
75091 @@ -736,6 +759,12 @@ static int
75092 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75093 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75094 {
75095 +
75096 +#ifdef CONFIG_PAX_SEGMEXEC
75097 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75098 + return 0;
75099 +#endif
75100 +
75101 if (is_mergeable_vma(vma, file, vm_flags) &&
75102 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75103 if (vma->vm_pgoff == vm_pgoff)
75104 @@ -755,6 +784,12 @@ static int
75105 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75106 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75107 {
75108 +
75109 +#ifdef CONFIG_PAX_SEGMEXEC
75110 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75111 + return 0;
75112 +#endif
75113 +
75114 if (is_mergeable_vma(vma, file, vm_flags) &&
75115 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75116 pgoff_t vm_pglen;
75117 @@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75118 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75119 struct vm_area_struct *prev, unsigned long addr,
75120 unsigned long end, unsigned long vm_flags,
75121 - struct anon_vma *anon_vma, struct file *file,
75122 + struct anon_vma *anon_vma, struct file *file,
75123 pgoff_t pgoff, struct mempolicy *policy)
75124 {
75125 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75126 struct vm_area_struct *area, *next;
75127 int err;
75128
75129 +#ifdef CONFIG_PAX_SEGMEXEC
75130 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75131 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75132 +
75133 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75134 +#endif
75135 +
75136 /*
75137 * We later require that vma->vm_flags == vm_flags,
75138 * so this tests vma->vm_flags & VM_SPECIAL, too.
75139 @@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75140 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75141 next = next->vm_next;
75142
75143 +#ifdef CONFIG_PAX_SEGMEXEC
75144 + if (prev)
75145 + prev_m = pax_find_mirror_vma(prev);
75146 + if (area)
75147 + area_m = pax_find_mirror_vma(area);
75148 + if (next)
75149 + next_m = pax_find_mirror_vma(next);
75150 +#endif
75151 +
75152 /*
75153 * Can it merge with the predecessor?
75154 */
75155 @@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75156 /* cases 1, 6 */
75157 err = vma_adjust(prev, prev->vm_start,
75158 next->vm_end, prev->vm_pgoff, NULL);
75159 - } else /* cases 2, 5, 7 */
75160 +
75161 +#ifdef CONFIG_PAX_SEGMEXEC
75162 + if (!err && prev_m)
75163 + err = vma_adjust(prev_m, prev_m->vm_start,
75164 + next_m->vm_end, prev_m->vm_pgoff, NULL);
75165 +#endif
75166 +
75167 + } else { /* cases 2, 5, 7 */
75168 err = vma_adjust(prev, prev->vm_start,
75169 end, prev->vm_pgoff, NULL);
75170 +
75171 +#ifdef CONFIG_PAX_SEGMEXEC
75172 + if (!err && prev_m)
75173 + err = vma_adjust(prev_m, prev_m->vm_start,
75174 + end_m, prev_m->vm_pgoff, NULL);
75175 +#endif
75176 +
75177 + }
75178 if (err)
75179 return NULL;
75180 khugepaged_enter_vma_merge(prev);
75181 @@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75182 mpol_equal(policy, vma_policy(next)) &&
75183 can_vma_merge_before(next, vm_flags,
75184 anon_vma, file, pgoff+pglen)) {
75185 - if (prev && addr < prev->vm_end) /* case 4 */
75186 + if (prev && addr < prev->vm_end) { /* case 4 */
75187 err = vma_adjust(prev, prev->vm_start,
75188 addr, prev->vm_pgoff, NULL);
75189 - else /* cases 3, 8 */
75190 +
75191 +#ifdef CONFIG_PAX_SEGMEXEC
75192 + if (!err && prev_m)
75193 + err = vma_adjust(prev_m, prev_m->vm_start,
75194 + addr_m, prev_m->vm_pgoff, NULL);
75195 +#endif
75196 +
75197 + } else { /* cases 3, 8 */
75198 err = vma_adjust(area, addr, next->vm_end,
75199 next->vm_pgoff - pglen, NULL);
75200 +
75201 +#ifdef CONFIG_PAX_SEGMEXEC
75202 + if (!err && area_m)
75203 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
75204 + next_m->vm_pgoff - pglen, NULL);
75205 +#endif
75206 +
75207 + }
75208 if (err)
75209 return NULL;
75210 khugepaged_enter_vma_merge(area);
75211 @@ -968,16 +1049,13 @@ none:
75212 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75213 struct file *file, long pages)
75214 {
75215 - const unsigned long stack_flags
75216 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75217 -
75218 mm->total_vm += pages;
75219
75220 if (file) {
75221 mm->shared_vm += pages;
75222 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75223 mm->exec_vm += pages;
75224 - } else if (flags & stack_flags)
75225 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75226 mm->stack_vm += pages;
75227 }
75228 #endif /* CONFIG_PROC_FS */
75229 @@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75230 * (the exception is when the underlying filesystem is noexec
75231 * mounted, in which case we dont add PROT_EXEC.)
75232 */
75233 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75234 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75235 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75236 prot |= PROT_EXEC;
75237
75238 @@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75239 /* Obtain the address to map to. we verify (or select) it and ensure
75240 * that it represents a valid section of the address space.
75241 */
75242 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
75243 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75244 if (addr & ~PAGE_MASK)
75245 return addr;
75246
75247 @@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75248 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75249 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75250
75251 +#ifdef CONFIG_PAX_MPROTECT
75252 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75253 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75254 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75255 + gr_log_rwxmmap(file);
75256 +
75257 +#ifdef CONFIG_PAX_EMUPLT
75258 + vm_flags &= ~VM_EXEC;
75259 +#else
75260 + return -EPERM;
75261 +#endif
75262 +
75263 + }
75264 +
75265 + if (!(vm_flags & VM_EXEC))
75266 + vm_flags &= ~VM_MAYEXEC;
75267 +#else
75268 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75269 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75270 +#endif
75271 + else
75272 + vm_flags &= ~VM_MAYWRITE;
75273 + }
75274 +#endif
75275 +
75276 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75277 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75278 + vm_flags &= ~VM_PAGEEXEC;
75279 +#endif
75280 +
75281 if (flags & MAP_LOCKED)
75282 if (!can_do_mlock())
75283 return -EPERM;
75284 @@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75285 locked += mm->locked_vm;
75286 lock_limit = rlimit(RLIMIT_MEMLOCK);
75287 lock_limit >>= PAGE_SHIFT;
75288 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75289 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75290 return -EAGAIN;
75291 }
75292 @@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75293 }
75294 }
75295
75296 + if (!gr_acl_handle_mmap(file, prot))
75297 + return -EACCES;
75298 +
75299 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75300 }
75301
75302 @@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75303 vm_flags_t vm_flags = vma->vm_flags;
75304
75305 /* If it was private or non-writable, the write bit is already clear */
75306 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75307 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75308 return 0;
75309
75310 /* The backer wishes to know when pages are first written to? */
75311 @@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75312 unsigned long charged = 0;
75313 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75314
75315 +#ifdef CONFIG_PAX_SEGMEXEC
75316 + struct vm_area_struct *vma_m = NULL;
75317 +#endif
75318 +
75319 + /*
75320 + * mm->mmap_sem is required to protect against another thread
75321 + * changing the mappings in case we sleep.
75322 + */
75323 + verify_mm_writelocked(mm);
75324 +
75325 /* Clear old maps */
75326 error = -ENOMEM;
75327 -munmap_back:
75328 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75329 if (do_munmap(mm, addr, len))
75330 return -ENOMEM;
75331 - goto munmap_back;
75332 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75333 }
75334
75335 /* Check against address space limit. */
75336 @@ -1307,6 +1428,16 @@ munmap_back:
75337 goto unacct_error;
75338 }
75339
75340 +#ifdef CONFIG_PAX_SEGMEXEC
75341 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75342 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75343 + if (!vma_m) {
75344 + error = -ENOMEM;
75345 + goto free_vma;
75346 + }
75347 + }
75348 +#endif
75349 +
75350 vma->vm_mm = mm;
75351 vma->vm_start = addr;
75352 vma->vm_end = addr + len;
75353 @@ -1331,6 +1462,13 @@ munmap_back:
75354 if (error)
75355 goto unmap_and_free_vma;
75356
75357 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75358 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75359 + vma->vm_flags |= VM_PAGEEXEC;
75360 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75361 + }
75362 +#endif
75363 +
75364 /* Can addr have changed??
75365 *
75366 * Answer: Yes, several device drivers can do it in their
75367 @@ -1365,6 +1503,11 @@ munmap_back:
75368 vma_link(mm, vma, prev, rb_link, rb_parent);
75369 file = vma->vm_file;
75370
75371 +#ifdef CONFIG_PAX_SEGMEXEC
75372 + if (vma_m)
75373 + BUG_ON(pax_mirror_vma(vma_m, vma));
75374 +#endif
75375 +
75376 /* Once vma denies write, undo our temporary denial count */
75377 if (correct_wcount)
75378 atomic_inc(&inode->i_writecount);
75379 @@ -1372,6 +1515,7 @@ out:
75380 perf_event_mmap(vma);
75381
75382 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75383 + track_exec_limit(mm, addr, addr + len, vm_flags);
75384 if (vm_flags & VM_LOCKED) {
75385 if (!mlock_vma_pages_range(vma, addr, addr + len))
75386 mm->locked_vm += (len >> PAGE_SHIFT);
75387 @@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75388 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75389 charged = 0;
75390 free_vma:
75391 +
75392 +#ifdef CONFIG_PAX_SEGMEXEC
75393 + if (vma_m)
75394 + kmem_cache_free(vm_area_cachep, vma_m);
75395 +#endif
75396 +
75397 kmem_cache_free(vm_area_cachep, vma);
75398 unacct_error:
75399 if (charged)
75400 @@ -1400,6 +1550,62 @@ unacct_error:
75401 return error;
75402 }
75403
75404 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75405 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75406 +{
75407 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75408 + return (random32() & 0xFF) << PAGE_SHIFT;
75409 +
75410 + return 0;
75411 +}
75412 +#endif
75413 +
75414 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75415 +{
75416 + if (!vma) {
75417 +#ifdef CONFIG_STACK_GROWSUP
75418 + if (addr > sysctl_heap_stack_gap)
75419 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75420 + else
75421 + vma = find_vma(current->mm, 0);
75422 + if (vma && (vma->vm_flags & VM_GROWSUP))
75423 + return false;
75424 +#endif
75425 + return true;
75426 + }
75427 +
75428 + if (addr + len > vma->vm_start)
75429 + return false;
75430 +
75431 + if (vma->vm_flags & VM_GROWSDOWN)
75432 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75433 +#ifdef CONFIG_STACK_GROWSUP
75434 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75435 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75436 +#endif
75437 + else if (offset)
75438 + return offset <= vma->vm_start - addr - len;
75439 +
75440 + return true;
75441 +}
75442 +
75443 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75444 +{
75445 + if (vma->vm_start < len)
75446 + return -ENOMEM;
75447 +
75448 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
75449 + if (offset <= vma->vm_start - len)
75450 + return vma->vm_start - len - offset;
75451 + else
75452 + return -ENOMEM;
75453 + }
75454 +
75455 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
75456 + return vma->vm_start - len - sysctl_heap_stack_gap;
75457 + return -ENOMEM;
75458 +}
75459 +
75460 /* Get an address range which is currently unmapped.
75461 * For shmat() with addr=0.
75462 *
75463 @@ -1426,18 +1632,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75464 if (flags & MAP_FIXED)
75465 return addr;
75466
75467 +#ifdef CONFIG_PAX_RANDMMAP
75468 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75469 +#endif
75470 +
75471 if (addr) {
75472 addr = PAGE_ALIGN(addr);
75473 - vma = find_vma(mm, addr);
75474 - if (TASK_SIZE - len >= addr &&
75475 - (!vma || addr + len <= vma->vm_start))
75476 - return addr;
75477 + if (TASK_SIZE - len >= addr) {
75478 + vma = find_vma(mm, addr);
75479 + if (check_heap_stack_gap(vma, addr, len))
75480 + return addr;
75481 + }
75482 }
75483 if (len > mm->cached_hole_size) {
75484 - start_addr = addr = mm->free_area_cache;
75485 + start_addr = addr = mm->free_area_cache;
75486 } else {
75487 - start_addr = addr = TASK_UNMAPPED_BASE;
75488 - mm->cached_hole_size = 0;
75489 + start_addr = addr = mm->mmap_base;
75490 + mm->cached_hole_size = 0;
75491 }
75492
75493 full_search:
75494 @@ -1448,34 +1659,40 @@ full_search:
75495 * Start a new search - just in case we missed
75496 * some holes.
75497 */
75498 - if (start_addr != TASK_UNMAPPED_BASE) {
75499 - addr = TASK_UNMAPPED_BASE;
75500 - start_addr = addr;
75501 + if (start_addr != mm->mmap_base) {
75502 + start_addr = addr = mm->mmap_base;
75503 mm->cached_hole_size = 0;
75504 goto full_search;
75505 }
75506 return -ENOMEM;
75507 }
75508 - if (!vma || addr + len <= vma->vm_start) {
75509 - /*
75510 - * Remember the place where we stopped the search:
75511 - */
75512 - mm->free_area_cache = addr + len;
75513 - return addr;
75514 - }
75515 + if (check_heap_stack_gap(vma, addr, len))
75516 + break;
75517 if (addr + mm->cached_hole_size < vma->vm_start)
75518 mm->cached_hole_size = vma->vm_start - addr;
75519 addr = vma->vm_end;
75520 }
75521 +
75522 + /*
75523 + * Remember the place where we stopped the search:
75524 + */
75525 + mm->free_area_cache = addr + len;
75526 + return addr;
75527 }
75528 #endif
75529
75530 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75531 {
75532 +
75533 +#ifdef CONFIG_PAX_SEGMEXEC
75534 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75535 + return;
75536 +#endif
75537 +
75538 /*
75539 * Is this a new hole at the lowest possible address?
75540 */
75541 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75542 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75543 mm->free_area_cache = addr;
75544 }
75545
75546 @@ -1491,7 +1708,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75547 {
75548 struct vm_area_struct *vma;
75549 struct mm_struct *mm = current->mm;
75550 - unsigned long addr = addr0, start_addr;
75551 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75552
75553 /* requested length too big for entire address space */
75554 if (len > TASK_SIZE)
75555 @@ -1500,13 +1717,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75556 if (flags & MAP_FIXED)
75557 return addr;
75558
75559 +#ifdef CONFIG_PAX_RANDMMAP
75560 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75561 +#endif
75562 +
75563 /* requesting a specific address */
75564 if (addr) {
75565 addr = PAGE_ALIGN(addr);
75566 - vma = find_vma(mm, addr);
75567 - if (TASK_SIZE - len >= addr &&
75568 - (!vma || addr + len <= vma->vm_start))
75569 - return addr;
75570 + if (TASK_SIZE - len >= addr) {
75571 + vma = find_vma(mm, addr);
75572 + if (check_heap_stack_gap(vma, addr, len))
75573 + return addr;
75574 + }
75575 }
75576
75577 /* check if free_area_cache is useful for us */
75578 @@ -1530,7 +1752,7 @@ try_again:
75579 * return with success:
75580 */
75581 vma = find_vma(mm, addr);
75582 - if (!vma || addr+len <= vma->vm_start)
75583 + if (check_heap_stack_gap(vma, addr, len))
75584 /* remember the address as a hint for next time */
75585 return (mm->free_area_cache = addr);
75586
75587 @@ -1539,8 +1761,8 @@ try_again:
75588 mm->cached_hole_size = vma->vm_start - addr;
75589
75590 /* try just below the current vma->vm_start */
75591 - addr = vma->vm_start-len;
75592 - } while (len < vma->vm_start);
75593 + addr = skip_heap_stack_gap(vma, len);
75594 + } while (!IS_ERR_VALUE(addr));
75595
75596 fail:
75597 /*
75598 @@ -1563,13 +1785,21 @@ fail:
75599 * can happen with large stack limits and large mmap()
75600 * allocations.
75601 */
75602 + mm->mmap_base = TASK_UNMAPPED_BASE;
75603 +
75604 +#ifdef CONFIG_PAX_RANDMMAP
75605 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75606 + mm->mmap_base += mm->delta_mmap;
75607 +#endif
75608 +
75609 + mm->free_area_cache = mm->mmap_base;
75610 mm->cached_hole_size = ~0UL;
75611 - mm->free_area_cache = TASK_UNMAPPED_BASE;
75612 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75613 /*
75614 * Restore the topdown base:
75615 */
75616 - mm->free_area_cache = mm->mmap_base;
75617 + mm->mmap_base = base;
75618 + mm->free_area_cache = base;
75619 mm->cached_hole_size = ~0UL;
75620
75621 return addr;
75622 @@ -1578,6 +1808,12 @@ fail:
75623
75624 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75625 {
75626 +
75627 +#ifdef CONFIG_PAX_SEGMEXEC
75628 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75629 + return;
75630 +#endif
75631 +
75632 /*
75633 * Is this a new hole at the highest possible address?
75634 */
75635 @@ -1585,8 +1821,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75636 mm->free_area_cache = addr;
75637
75638 /* dont allow allocations above current base */
75639 - if (mm->free_area_cache > mm->mmap_base)
75640 + if (mm->free_area_cache > mm->mmap_base) {
75641 mm->free_area_cache = mm->mmap_base;
75642 + mm->cached_hole_size = ~0UL;
75643 + }
75644 }
75645
75646 unsigned long
75647 @@ -1685,6 +1923,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75648 return vma;
75649 }
75650
75651 +#ifdef CONFIG_PAX_SEGMEXEC
75652 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75653 +{
75654 + struct vm_area_struct *vma_m;
75655 +
75656 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75657 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75658 + BUG_ON(vma->vm_mirror);
75659 + return NULL;
75660 + }
75661 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75662 + vma_m = vma->vm_mirror;
75663 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75664 + BUG_ON(vma->vm_file != vma_m->vm_file);
75665 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75666 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
75667 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
75668 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
75669 + return vma_m;
75670 +}
75671 +#endif
75672 +
75673 /*
75674 * Verify that the stack growth is acceptable and
75675 * update accounting. This is shared with both the
75676 @@ -1701,6 +1961,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75677 return -ENOMEM;
75678
75679 /* Stack limit test */
75680 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
75681 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
75682 return -ENOMEM;
75683
75684 @@ -1711,6 +1972,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75685 locked = mm->locked_vm + grow;
75686 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
75687 limit >>= PAGE_SHIFT;
75688 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75689 if (locked > limit && !capable(CAP_IPC_LOCK))
75690 return -ENOMEM;
75691 }
75692 @@ -1740,37 +2002,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75693 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
75694 * vma is the last one with address > vma->vm_end. Have to extend vma.
75695 */
75696 +#ifndef CONFIG_IA64
75697 +static
75698 +#endif
75699 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75700 {
75701 int error;
75702 + bool locknext;
75703
75704 if (!(vma->vm_flags & VM_GROWSUP))
75705 return -EFAULT;
75706
75707 + /* Also guard against wrapping around to address 0. */
75708 + if (address < PAGE_ALIGN(address+1))
75709 + address = PAGE_ALIGN(address+1);
75710 + else
75711 + return -ENOMEM;
75712 +
75713 /*
75714 * We must make sure the anon_vma is allocated
75715 * so that the anon_vma locking is not a noop.
75716 */
75717 if (unlikely(anon_vma_prepare(vma)))
75718 return -ENOMEM;
75719 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
75720 + if (locknext && anon_vma_prepare(vma->vm_next))
75721 + return -ENOMEM;
75722 vma_lock_anon_vma(vma);
75723 + if (locknext)
75724 + vma_lock_anon_vma(vma->vm_next);
75725
75726 /*
75727 * vma->vm_start/vm_end cannot change under us because the caller
75728 * is required to hold the mmap_sem in read mode. We need the
75729 - * anon_vma lock to serialize against concurrent expand_stacks.
75730 - * Also guard against wrapping around to address 0.
75731 + * anon_vma locks to serialize against concurrent expand_stacks
75732 + * and expand_upwards.
75733 */
75734 - if (address < PAGE_ALIGN(address+4))
75735 - address = PAGE_ALIGN(address+4);
75736 - else {
75737 - vma_unlock_anon_vma(vma);
75738 - return -ENOMEM;
75739 - }
75740 error = 0;
75741
75742 /* Somebody else might have raced and expanded it already */
75743 - if (address > vma->vm_end) {
75744 + 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)
75745 + error = -ENOMEM;
75746 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
75747 unsigned long size, grow;
75748
75749 size = address - vma->vm_start;
75750 @@ -1787,6 +2060,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75751 }
75752 }
75753 }
75754 + if (locknext)
75755 + vma_unlock_anon_vma(vma->vm_next);
75756 vma_unlock_anon_vma(vma);
75757 khugepaged_enter_vma_merge(vma);
75758 validate_mm(vma->vm_mm);
75759 @@ -1801,6 +2076,8 @@ int expand_downwards(struct vm_area_struct *vma,
75760 unsigned long address)
75761 {
75762 int error;
75763 + bool lockprev = false;
75764 + struct vm_area_struct *prev;
75765
75766 /*
75767 * We must make sure the anon_vma is allocated
75768 @@ -1814,6 +2091,15 @@ int expand_downwards(struct vm_area_struct *vma,
75769 if (error)
75770 return error;
75771
75772 + prev = vma->vm_prev;
75773 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
75774 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
75775 +#endif
75776 + if (lockprev && anon_vma_prepare(prev))
75777 + return -ENOMEM;
75778 + if (lockprev)
75779 + vma_lock_anon_vma(prev);
75780 +
75781 vma_lock_anon_vma(vma);
75782
75783 /*
75784 @@ -1823,9 +2109,17 @@ int expand_downwards(struct vm_area_struct *vma,
75785 */
75786
75787 /* Somebody else might have raced and expanded it already */
75788 - if (address < vma->vm_start) {
75789 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
75790 + error = -ENOMEM;
75791 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
75792 unsigned long size, grow;
75793
75794 +#ifdef CONFIG_PAX_SEGMEXEC
75795 + struct vm_area_struct *vma_m;
75796 +
75797 + vma_m = pax_find_mirror_vma(vma);
75798 +#endif
75799 +
75800 size = vma->vm_end - address;
75801 grow = (vma->vm_start - address) >> PAGE_SHIFT;
75802
75803 @@ -1837,6 +2131,17 @@ int expand_downwards(struct vm_area_struct *vma,
75804 vma->vm_start = address;
75805 vma->vm_pgoff -= grow;
75806 anon_vma_interval_tree_post_update_vma(vma);
75807 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
75808 +
75809 +#ifdef CONFIG_PAX_SEGMEXEC
75810 + if (vma_m) {
75811 + anon_vma_interval_tree_pre_update_vma(vma_m);
75812 + vma_m->vm_start -= grow << PAGE_SHIFT;
75813 + vma_m->vm_pgoff -= grow;
75814 + anon_vma_interval_tree_post_update_vma(vma_m);
75815 + }
75816 +#endif
75817 +
75818 perf_event_mmap(vma);
75819 }
75820 }
75821 @@ -1914,6 +2219,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
75822 do {
75823 long nrpages = vma_pages(vma);
75824
75825 +#ifdef CONFIG_PAX_SEGMEXEC
75826 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
75827 + vma = remove_vma(vma);
75828 + continue;
75829 + }
75830 +#endif
75831 +
75832 if (vma->vm_flags & VM_ACCOUNT)
75833 nr_accounted += nrpages;
75834 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
75835 @@ -1959,6 +2271,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
75836 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
75837 vma->vm_prev = NULL;
75838 do {
75839 +
75840 +#ifdef CONFIG_PAX_SEGMEXEC
75841 + if (vma->vm_mirror) {
75842 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
75843 + vma->vm_mirror->vm_mirror = NULL;
75844 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
75845 + vma->vm_mirror = NULL;
75846 + }
75847 +#endif
75848 +
75849 rb_erase(&vma->vm_rb, &mm->mm_rb);
75850 mm->map_count--;
75851 tail_vma = vma;
75852 @@ -1987,14 +2309,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75853 struct vm_area_struct *new;
75854 int err = -ENOMEM;
75855
75856 +#ifdef CONFIG_PAX_SEGMEXEC
75857 + struct vm_area_struct *vma_m, *new_m = NULL;
75858 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
75859 +#endif
75860 +
75861 if (is_vm_hugetlb_page(vma) && (addr &
75862 ~(huge_page_mask(hstate_vma(vma)))))
75863 return -EINVAL;
75864
75865 +#ifdef CONFIG_PAX_SEGMEXEC
75866 + vma_m = pax_find_mirror_vma(vma);
75867 +#endif
75868 +
75869 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75870 if (!new)
75871 goto out_err;
75872
75873 +#ifdef CONFIG_PAX_SEGMEXEC
75874 + if (vma_m) {
75875 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75876 + if (!new_m) {
75877 + kmem_cache_free(vm_area_cachep, new);
75878 + goto out_err;
75879 + }
75880 + }
75881 +#endif
75882 +
75883 /* most fields are the same, copy all, and then fixup */
75884 *new = *vma;
75885
75886 @@ -2007,6 +2348,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75887 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
75888 }
75889
75890 +#ifdef CONFIG_PAX_SEGMEXEC
75891 + if (vma_m) {
75892 + *new_m = *vma_m;
75893 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
75894 + new_m->vm_mirror = new;
75895 + new->vm_mirror = new_m;
75896 +
75897 + if (new_below)
75898 + new_m->vm_end = addr_m;
75899 + else {
75900 + new_m->vm_start = addr_m;
75901 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
75902 + }
75903 + }
75904 +#endif
75905 +
75906 pol = mpol_dup(vma_policy(vma));
75907 if (IS_ERR(pol)) {
75908 err = PTR_ERR(pol);
75909 @@ -2029,6 +2386,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75910 else
75911 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
75912
75913 +#ifdef CONFIG_PAX_SEGMEXEC
75914 + if (!err && vma_m) {
75915 + if (anon_vma_clone(new_m, vma_m))
75916 + goto out_free_mpol;
75917 +
75918 + mpol_get(pol);
75919 + vma_set_policy(new_m, pol);
75920 +
75921 + if (new_m->vm_file)
75922 + get_file(new_m->vm_file);
75923 +
75924 + if (new_m->vm_ops && new_m->vm_ops->open)
75925 + new_m->vm_ops->open(new_m);
75926 +
75927 + if (new_below)
75928 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
75929 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
75930 + else
75931 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
75932 +
75933 + if (err) {
75934 + if (new_m->vm_ops && new_m->vm_ops->close)
75935 + new_m->vm_ops->close(new_m);
75936 + if (new_m->vm_file)
75937 + fput(new_m->vm_file);
75938 + mpol_put(pol);
75939 + }
75940 + }
75941 +#endif
75942 +
75943 /* Success. */
75944 if (!err)
75945 return 0;
75946 @@ -2038,10 +2425,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75947 new->vm_ops->close(new);
75948 if (new->vm_file)
75949 fput(new->vm_file);
75950 - unlink_anon_vmas(new);
75951 out_free_mpol:
75952 mpol_put(pol);
75953 out_free_vma:
75954 +
75955 +#ifdef CONFIG_PAX_SEGMEXEC
75956 + if (new_m) {
75957 + unlink_anon_vmas(new_m);
75958 + kmem_cache_free(vm_area_cachep, new_m);
75959 + }
75960 +#endif
75961 +
75962 + unlink_anon_vmas(new);
75963 kmem_cache_free(vm_area_cachep, new);
75964 out_err:
75965 return err;
75966 @@ -2054,6 +2449,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75967 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75968 unsigned long addr, int new_below)
75969 {
75970 +
75971 +#ifdef CONFIG_PAX_SEGMEXEC
75972 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75973 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
75974 + if (mm->map_count >= sysctl_max_map_count-1)
75975 + return -ENOMEM;
75976 + } else
75977 +#endif
75978 +
75979 if (mm->map_count >= sysctl_max_map_count)
75980 return -ENOMEM;
75981
75982 @@ -2065,11 +2469,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75983 * work. This now handles partial unmappings.
75984 * Jeremy Fitzhardinge <jeremy@goop.org>
75985 */
75986 +#ifdef CONFIG_PAX_SEGMEXEC
75987 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75988 {
75989 + int ret = __do_munmap(mm, start, len);
75990 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
75991 + return ret;
75992 +
75993 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
75994 +}
75995 +
75996 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75997 +#else
75998 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75999 +#endif
76000 +{
76001 unsigned long end;
76002 struct vm_area_struct *vma, *prev, *last;
76003
76004 + /*
76005 + * mm->mmap_sem is required to protect against another thread
76006 + * changing the mappings in case we sleep.
76007 + */
76008 + verify_mm_writelocked(mm);
76009 +
76010 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76011 return -EINVAL;
76012
76013 @@ -2144,6 +2567,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76014 /* Fix up all other VM information */
76015 remove_vma_list(mm, vma);
76016
76017 + track_exec_limit(mm, start, end, 0UL);
76018 +
76019 return 0;
76020 }
76021
76022 @@ -2152,6 +2577,13 @@ int vm_munmap(unsigned long start, size_t len)
76023 int ret;
76024 struct mm_struct *mm = current->mm;
76025
76026 +
76027 +#ifdef CONFIG_PAX_SEGMEXEC
76028 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76029 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76030 + return -EINVAL;
76031 +#endif
76032 +
76033 down_write(&mm->mmap_sem);
76034 ret = do_munmap(mm, start, len);
76035 up_write(&mm->mmap_sem);
76036 @@ -2165,16 +2597,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76037 return vm_munmap(addr, len);
76038 }
76039
76040 -static inline void verify_mm_writelocked(struct mm_struct *mm)
76041 -{
76042 -#ifdef CONFIG_DEBUG_VM
76043 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76044 - WARN_ON(1);
76045 - up_read(&mm->mmap_sem);
76046 - }
76047 -#endif
76048 -}
76049 -
76050 /*
76051 * this is really a simplified "do_mmap". it only handles
76052 * anonymous maps. eventually we may be able to do some
76053 @@ -2188,6 +2610,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76054 struct rb_node ** rb_link, * rb_parent;
76055 pgoff_t pgoff = addr >> PAGE_SHIFT;
76056 int error;
76057 + unsigned long charged;
76058
76059 len = PAGE_ALIGN(len);
76060 if (!len)
76061 @@ -2195,16 +2618,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76062
76063 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76064
76065 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76066 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76067 + flags &= ~VM_EXEC;
76068 +
76069 +#ifdef CONFIG_PAX_MPROTECT
76070 + if (mm->pax_flags & MF_PAX_MPROTECT)
76071 + flags &= ~VM_MAYEXEC;
76072 +#endif
76073 +
76074 + }
76075 +#endif
76076 +
76077 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76078 if (error & ~PAGE_MASK)
76079 return error;
76080
76081 + charged = len >> PAGE_SHIFT;
76082 +
76083 /*
76084 * mlock MCL_FUTURE?
76085 */
76086 if (mm->def_flags & VM_LOCKED) {
76087 unsigned long locked, lock_limit;
76088 - locked = len >> PAGE_SHIFT;
76089 + locked = charged;
76090 locked += mm->locked_vm;
76091 lock_limit = rlimit(RLIMIT_MEMLOCK);
76092 lock_limit >>= PAGE_SHIFT;
76093 @@ -2221,21 +2658,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76094 /*
76095 * Clear old maps. this also does some error checking for us
76096 */
76097 - munmap_back:
76098 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76099 if (do_munmap(mm, addr, len))
76100 return -ENOMEM;
76101 - goto munmap_back;
76102 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76103 }
76104
76105 /* Check against address space limits *after* clearing old maps... */
76106 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76107 + if (!may_expand_vm(mm, charged))
76108 return -ENOMEM;
76109
76110 if (mm->map_count > sysctl_max_map_count)
76111 return -ENOMEM;
76112
76113 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76114 + if (security_vm_enough_memory_mm(mm, charged))
76115 return -ENOMEM;
76116
76117 /* Can we just expand an old private anonymous mapping? */
76118 @@ -2249,7 +2685,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76119 */
76120 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76121 if (!vma) {
76122 - vm_unacct_memory(len >> PAGE_SHIFT);
76123 + vm_unacct_memory(charged);
76124 return -ENOMEM;
76125 }
76126
76127 @@ -2263,11 +2699,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76128 vma_link(mm, vma, prev, rb_link, rb_parent);
76129 out:
76130 perf_event_mmap(vma);
76131 - mm->total_vm += len >> PAGE_SHIFT;
76132 + mm->total_vm += charged;
76133 if (flags & VM_LOCKED) {
76134 if (!mlock_vma_pages_range(vma, addr, addr + len))
76135 - mm->locked_vm += (len >> PAGE_SHIFT);
76136 + mm->locked_vm += charged;
76137 }
76138 + track_exec_limit(mm, addr, addr + len, flags);
76139 return addr;
76140 }
76141
76142 @@ -2325,6 +2762,7 @@ void exit_mmap(struct mm_struct *mm)
76143 while (vma) {
76144 if (vma->vm_flags & VM_ACCOUNT)
76145 nr_accounted += vma_pages(vma);
76146 + vma->vm_mirror = NULL;
76147 vma = remove_vma(vma);
76148 }
76149 vm_unacct_memory(nr_accounted);
76150 @@ -2341,6 +2779,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76151 struct vm_area_struct *prev;
76152 struct rb_node **rb_link, *rb_parent;
76153
76154 +#ifdef CONFIG_PAX_SEGMEXEC
76155 + struct vm_area_struct *vma_m = NULL;
76156 +#endif
76157 +
76158 + if (security_mmap_addr(vma->vm_start))
76159 + return -EPERM;
76160 +
76161 /*
76162 * The vm_pgoff of a purely anonymous vma should be irrelevant
76163 * until its first write fault, when page's anon_vma and index
76164 @@ -2364,7 +2809,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76165 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76166 return -ENOMEM;
76167
76168 +#ifdef CONFIG_PAX_SEGMEXEC
76169 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76170 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76171 + if (!vma_m)
76172 + return -ENOMEM;
76173 + }
76174 +#endif
76175 +
76176 vma_link(mm, vma, prev, rb_link, rb_parent);
76177 +
76178 +#ifdef CONFIG_PAX_SEGMEXEC
76179 + if (vma_m)
76180 + BUG_ON(pax_mirror_vma(vma_m, vma));
76181 +#endif
76182 +
76183 return 0;
76184 }
76185
76186 @@ -2384,6 +2843,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76187 struct mempolicy *pol;
76188 bool faulted_in_anon_vma = true;
76189
76190 + BUG_ON(vma->vm_mirror);
76191 +
76192 /*
76193 * If anonymous vma has not yet been faulted, update new pgoff
76194 * to match new location, to increase its chance of merging.
76195 @@ -2450,6 +2911,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76196 return NULL;
76197 }
76198
76199 +#ifdef CONFIG_PAX_SEGMEXEC
76200 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76201 +{
76202 + struct vm_area_struct *prev_m;
76203 + struct rb_node **rb_link_m, *rb_parent_m;
76204 + struct mempolicy *pol_m;
76205 +
76206 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76207 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76208 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76209 + *vma_m = *vma;
76210 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76211 + if (anon_vma_clone(vma_m, vma))
76212 + return -ENOMEM;
76213 + pol_m = vma_policy(vma_m);
76214 + mpol_get(pol_m);
76215 + vma_set_policy(vma_m, pol_m);
76216 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76217 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76218 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76219 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76220 + if (vma_m->vm_file)
76221 + get_file(vma_m->vm_file);
76222 + if (vma_m->vm_ops && vma_m->vm_ops->open)
76223 + vma_m->vm_ops->open(vma_m);
76224 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76225 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76226 + vma_m->vm_mirror = vma;
76227 + vma->vm_mirror = vma_m;
76228 + return 0;
76229 +}
76230 +#endif
76231 +
76232 /*
76233 * Return true if the calling process may expand its vm space by the passed
76234 * number of pages
76235 @@ -2461,6 +2955,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76236
76237 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76238
76239 +#ifdef CONFIG_PAX_RANDMMAP
76240 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76241 + cur -= mm->brk_gap;
76242 +#endif
76243 +
76244 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76245 if (cur + npages > lim)
76246 return 0;
76247 return 1;
76248 @@ -2531,6 +3031,22 @@ int install_special_mapping(struct mm_struct *mm,
76249 vma->vm_start = addr;
76250 vma->vm_end = addr + len;
76251
76252 +#ifdef CONFIG_PAX_MPROTECT
76253 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76254 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76255 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76256 + return -EPERM;
76257 + if (!(vm_flags & VM_EXEC))
76258 + vm_flags &= ~VM_MAYEXEC;
76259 +#else
76260 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76261 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76262 +#endif
76263 + else
76264 + vm_flags &= ~VM_MAYWRITE;
76265 + }
76266 +#endif
76267 +
76268 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76269 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76270
76271 diff --git a/mm/mprotect.c b/mm/mprotect.c
76272 index a409926..8b32e6d 100644
76273 --- a/mm/mprotect.c
76274 +++ b/mm/mprotect.c
76275 @@ -23,10 +23,17 @@
76276 #include <linux/mmu_notifier.h>
76277 #include <linux/migrate.h>
76278 #include <linux/perf_event.h>
76279 +
76280 +#ifdef CONFIG_PAX_MPROTECT
76281 +#include <linux/elf.h>
76282 +#include <linux/binfmts.h>
76283 +#endif
76284 +
76285 #include <asm/uaccess.h>
76286 #include <asm/pgtable.h>
76287 #include <asm/cacheflush.h>
76288 #include <asm/tlbflush.h>
76289 +#include <asm/mmu_context.h>
76290
76291 #ifndef pgprot_modify
76292 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76293 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76294 flush_tlb_range(vma, start, end);
76295 }
76296
76297 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76298 +/* called while holding the mmap semaphor for writing except stack expansion */
76299 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76300 +{
76301 + unsigned long oldlimit, newlimit = 0UL;
76302 +
76303 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76304 + return;
76305 +
76306 + spin_lock(&mm->page_table_lock);
76307 + oldlimit = mm->context.user_cs_limit;
76308 + if ((prot & VM_EXEC) && oldlimit < end)
76309 + /* USER_CS limit moved up */
76310 + newlimit = end;
76311 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76312 + /* USER_CS limit moved down */
76313 + newlimit = start;
76314 +
76315 + if (newlimit) {
76316 + mm->context.user_cs_limit = newlimit;
76317 +
76318 +#ifdef CONFIG_SMP
76319 + wmb();
76320 + cpus_clear(mm->context.cpu_user_cs_mask);
76321 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76322 +#endif
76323 +
76324 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76325 + }
76326 + spin_unlock(&mm->page_table_lock);
76327 + if (newlimit == end) {
76328 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
76329 +
76330 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
76331 + if (is_vm_hugetlb_page(vma))
76332 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76333 + else
76334 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76335 + }
76336 +}
76337 +#endif
76338 +
76339 int
76340 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76341 unsigned long start, unsigned long end, unsigned long newflags)
76342 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76343 int error;
76344 int dirty_accountable = 0;
76345
76346 +#ifdef CONFIG_PAX_SEGMEXEC
76347 + struct vm_area_struct *vma_m = NULL;
76348 + unsigned long start_m, end_m;
76349 +
76350 + start_m = start + SEGMEXEC_TASK_SIZE;
76351 + end_m = end + SEGMEXEC_TASK_SIZE;
76352 +#endif
76353 +
76354 if (newflags == oldflags) {
76355 *pprev = vma;
76356 return 0;
76357 }
76358
76359 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76360 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76361 +
76362 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76363 + return -ENOMEM;
76364 +
76365 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76366 + return -ENOMEM;
76367 + }
76368 +
76369 /*
76370 * If we make a private mapping writable we increase our commit;
76371 * but (without finer accounting) cannot reduce our commit if we
76372 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76373 }
76374 }
76375
76376 +#ifdef CONFIG_PAX_SEGMEXEC
76377 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76378 + if (start != vma->vm_start) {
76379 + error = split_vma(mm, vma, start, 1);
76380 + if (error)
76381 + goto fail;
76382 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76383 + *pprev = (*pprev)->vm_next;
76384 + }
76385 +
76386 + if (end != vma->vm_end) {
76387 + error = split_vma(mm, vma, end, 0);
76388 + if (error)
76389 + goto fail;
76390 + }
76391 +
76392 + if (pax_find_mirror_vma(vma)) {
76393 + error = __do_munmap(mm, start_m, end_m - start_m);
76394 + if (error)
76395 + goto fail;
76396 + } else {
76397 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76398 + if (!vma_m) {
76399 + error = -ENOMEM;
76400 + goto fail;
76401 + }
76402 + vma->vm_flags = newflags;
76403 + error = pax_mirror_vma(vma_m, vma);
76404 + if (error) {
76405 + vma->vm_flags = oldflags;
76406 + goto fail;
76407 + }
76408 + }
76409 + }
76410 +#endif
76411 +
76412 /*
76413 * First try to merge with previous and/or next vma.
76414 */
76415 @@ -204,9 +307,21 @@ success:
76416 * vm_flags and vm_page_prot are protected by the mmap_sem
76417 * held in write mode.
76418 */
76419 +
76420 +#ifdef CONFIG_PAX_SEGMEXEC
76421 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76422 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76423 +#endif
76424 +
76425 vma->vm_flags = newflags;
76426 +
76427 +#ifdef CONFIG_PAX_MPROTECT
76428 + if (mm->binfmt && mm->binfmt->handle_mprotect)
76429 + mm->binfmt->handle_mprotect(vma, newflags);
76430 +#endif
76431 +
76432 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76433 - vm_get_page_prot(newflags));
76434 + vm_get_page_prot(vma->vm_flags));
76435
76436 if (vma_wants_writenotify(vma)) {
76437 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76438 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76439 end = start + len;
76440 if (end <= start)
76441 return -ENOMEM;
76442 +
76443 +#ifdef CONFIG_PAX_SEGMEXEC
76444 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76445 + if (end > SEGMEXEC_TASK_SIZE)
76446 + return -EINVAL;
76447 + } else
76448 +#endif
76449 +
76450 + if (end > TASK_SIZE)
76451 + return -EINVAL;
76452 +
76453 if (!arch_validate_prot(prot))
76454 return -EINVAL;
76455
76456 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76457 /*
76458 * Does the application expect PROT_READ to imply PROT_EXEC:
76459 */
76460 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76461 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76462 prot |= PROT_EXEC;
76463
76464 vm_flags = calc_vm_prot_bits(prot);
76465 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76466 if (start > vma->vm_start)
76467 prev = vma;
76468
76469 +#ifdef CONFIG_PAX_MPROTECT
76470 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76471 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
76472 +#endif
76473 +
76474 for (nstart = start ; ; ) {
76475 unsigned long newflags;
76476
76477 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76478
76479 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76480 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76481 + if (prot & (PROT_WRITE | PROT_EXEC))
76482 + gr_log_rwxmprotect(vma->vm_file);
76483 +
76484 + error = -EACCES;
76485 + goto out;
76486 + }
76487 +
76488 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76489 error = -EACCES;
76490 goto out;
76491 }
76492 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76493 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76494 if (error)
76495 goto out;
76496 +
76497 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76498 +
76499 nstart = tmp;
76500
76501 if (nstart < prev->vm_end)
76502 diff --git a/mm/mremap.c b/mm/mremap.c
76503 index 1b61c2d..1cc0e3c 100644
76504 --- a/mm/mremap.c
76505 +++ b/mm/mremap.c
76506 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76507 continue;
76508 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76509 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76510 +
76511 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76512 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76513 + pte = pte_exprotect(pte);
76514 +#endif
76515 +
76516 set_pte_at(mm, new_addr, new_pte, pte);
76517 }
76518
76519 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76520 if (is_vm_hugetlb_page(vma))
76521 goto Einval;
76522
76523 +#ifdef CONFIG_PAX_SEGMEXEC
76524 + if (pax_find_mirror_vma(vma))
76525 + goto Einval;
76526 +#endif
76527 +
76528 /* We can't remap across vm area boundaries */
76529 if (old_len > vma->vm_end - addr)
76530 goto Efault;
76531 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76532 unsigned long ret = -EINVAL;
76533 unsigned long charged = 0;
76534 unsigned long map_flags;
76535 + unsigned long pax_task_size = TASK_SIZE;
76536
76537 if (new_addr & ~PAGE_MASK)
76538 goto out;
76539
76540 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76541 +#ifdef CONFIG_PAX_SEGMEXEC
76542 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76543 + pax_task_size = SEGMEXEC_TASK_SIZE;
76544 +#endif
76545 +
76546 + pax_task_size -= PAGE_SIZE;
76547 +
76548 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76549 goto out;
76550
76551 /* Check if the location we're moving into overlaps the
76552 * old location at all, and fail if it does.
76553 */
76554 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76555 - goto out;
76556 -
76557 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76558 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76559 goto out;
76560
76561 ret = do_munmap(mm, new_addr, new_len);
76562 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76563 struct vm_area_struct *vma;
76564 unsigned long ret = -EINVAL;
76565 unsigned long charged = 0;
76566 + unsigned long pax_task_size = TASK_SIZE;
76567
76568 down_write(&current->mm->mmap_sem);
76569
76570 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76571 if (!new_len)
76572 goto out;
76573
76574 +#ifdef CONFIG_PAX_SEGMEXEC
76575 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76576 + pax_task_size = SEGMEXEC_TASK_SIZE;
76577 +#endif
76578 +
76579 + pax_task_size -= PAGE_SIZE;
76580 +
76581 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76582 + old_len > pax_task_size || addr > pax_task_size-old_len)
76583 + goto out;
76584 +
76585 if (flags & MREMAP_FIXED) {
76586 if (flags & MREMAP_MAYMOVE)
76587 ret = mremap_to(addr, old_len, new_addr, new_len);
76588 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76589 addr + new_len);
76590 }
76591 ret = addr;
76592 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76593 goto out;
76594 }
76595 }
76596 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76597 goto out;
76598 }
76599
76600 + map_flags = vma->vm_flags;
76601 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76602 + if (!(ret & ~PAGE_MASK)) {
76603 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76604 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76605 + }
76606 }
76607 out:
76608 if (ret & ~PAGE_MASK)
76609 diff --git a/mm/nommu.c b/mm/nommu.c
76610 index 45131b4..c521665 100644
76611 --- a/mm/nommu.c
76612 +++ b/mm/nommu.c
76613 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76614 int sysctl_overcommit_ratio = 50; /* default is 50% */
76615 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76616 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76617 -int heap_stack_gap = 0;
76618
76619 atomic_long_t mmap_pages_allocated;
76620
76621 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76622 EXPORT_SYMBOL(find_vma);
76623
76624 /*
76625 - * find a VMA
76626 - * - we don't extend stack VMAs under NOMMU conditions
76627 - */
76628 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76629 -{
76630 - return find_vma(mm, addr);
76631 -}
76632 -
76633 -/*
76634 * expand a stack to a given address
76635 * - not supported under NOMMU conditions
76636 */
76637 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76638
76639 /* most fields are the same, copy all, and then fixup */
76640 *new = *vma;
76641 + INIT_LIST_HEAD(&new->anon_vma_chain);
76642 *region = *vma->vm_region;
76643 new->vm_region = region;
76644
76645 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76646 index ceb4168..d7774f2 100644
76647 --- a/mm/page_alloc.c
76648 +++ b/mm/page_alloc.c
76649 @@ -340,7 +340,7 @@ out:
76650 * This usage means that zero-order pages may not be compound.
76651 */
76652
76653 -static void free_compound_page(struct page *page)
76654 +void free_compound_page(struct page *page)
76655 {
76656 __free_pages_ok(page, compound_order(page));
76657 }
76658 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76659 int i;
76660 int bad = 0;
76661
76662 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76663 + unsigned long index = 1UL << order;
76664 +#endif
76665 +
76666 trace_mm_page_free(page, order);
76667 kmemcheck_free_shadow(page, order);
76668
76669 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76670 debug_check_no_obj_freed(page_address(page),
76671 PAGE_SIZE << order);
76672 }
76673 +
76674 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76675 + for (; index; --index)
76676 + sanitize_highpage(page + index - 1);
76677 +#endif
76678 +
76679 arch_free_page(page, order);
76680 kernel_map_pages(page, 1 << order, 0);
76681
76682 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
76683 arch_alloc_page(page, order);
76684 kernel_map_pages(page, 1 << order, 1);
76685
76686 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
76687 if (gfp_flags & __GFP_ZERO)
76688 prep_zero_page(page, order, gfp_flags);
76689 +#endif
76690
76691 if (order && (gfp_flags & __GFP_COMP))
76692 prep_compound_page(page, order);
76693 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
76694 unsigned long pfn;
76695
76696 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
76697 +#ifdef CONFIG_X86_32
76698 + /* boot failures in VMware 8 on 32bit vanilla since
76699 + this change */
76700 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
76701 +#else
76702 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
76703 +#endif
76704 return 1;
76705 }
76706 return 0;
76707 diff --git a/mm/percpu.c b/mm/percpu.c
76708 index ddc5efb..f632d2c 100644
76709 --- a/mm/percpu.c
76710 +++ b/mm/percpu.c
76711 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
76712 static unsigned int pcpu_high_unit_cpu __read_mostly;
76713
76714 /* the address of the first chunk which starts with the kernel static area */
76715 -void *pcpu_base_addr __read_mostly;
76716 +void *pcpu_base_addr __read_only;
76717 EXPORT_SYMBOL_GPL(pcpu_base_addr);
76718
76719 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
76720 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
76721 index 926b466..b23df53 100644
76722 --- a/mm/process_vm_access.c
76723 +++ b/mm/process_vm_access.c
76724 @@ -13,6 +13,7 @@
76725 #include <linux/uio.h>
76726 #include <linux/sched.h>
76727 #include <linux/highmem.h>
76728 +#include <linux/security.h>
76729 #include <linux/ptrace.h>
76730 #include <linux/slab.h>
76731 #include <linux/syscalls.h>
76732 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76733 size_t iov_l_curr_offset = 0;
76734 ssize_t iov_len;
76735
76736 + return -ENOSYS; // PaX: until properly audited
76737 +
76738 /*
76739 * Work out how many pages of struct pages we're going to need
76740 * when eventually calling get_user_pages
76741 */
76742 for (i = 0; i < riovcnt; i++) {
76743 iov_len = rvec[i].iov_len;
76744 - if (iov_len > 0) {
76745 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
76746 - + iov_len)
76747 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
76748 - / PAGE_SIZE + 1;
76749 - nr_pages = max(nr_pages, nr_pages_iov);
76750 - }
76751 + if (iov_len <= 0)
76752 + continue;
76753 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
76754 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
76755 + nr_pages = max(nr_pages, nr_pages_iov);
76756 }
76757
76758 if (nr_pages == 0)
76759 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76760 goto free_proc_pages;
76761 }
76762
76763 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
76764 + rc = -EPERM;
76765 + goto put_task_struct;
76766 + }
76767 +
76768 mm = mm_access(task, PTRACE_MODE_ATTACH);
76769 if (!mm || IS_ERR(mm)) {
76770 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
76771 diff --git a/mm/rmap.c b/mm/rmap.c
76772 index 2ee1ef0..2e175ba 100644
76773 --- a/mm/rmap.c
76774 +++ b/mm/rmap.c
76775 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76776 struct anon_vma *anon_vma = vma->anon_vma;
76777 struct anon_vma_chain *avc;
76778
76779 +#ifdef CONFIG_PAX_SEGMEXEC
76780 + struct anon_vma_chain *avc_m = NULL;
76781 +#endif
76782 +
76783 might_sleep();
76784 if (unlikely(!anon_vma)) {
76785 struct mm_struct *mm = vma->vm_mm;
76786 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76787 if (!avc)
76788 goto out_enomem;
76789
76790 +#ifdef CONFIG_PAX_SEGMEXEC
76791 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
76792 + if (!avc_m)
76793 + goto out_enomem_free_avc;
76794 +#endif
76795 +
76796 anon_vma = find_mergeable_anon_vma(vma);
76797 allocated = NULL;
76798 if (!anon_vma) {
76799 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76800 /* page_table_lock to protect against threads */
76801 spin_lock(&mm->page_table_lock);
76802 if (likely(!vma->anon_vma)) {
76803 +
76804 +#ifdef CONFIG_PAX_SEGMEXEC
76805 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
76806 +
76807 + if (vma_m) {
76808 + BUG_ON(vma_m->anon_vma);
76809 + vma_m->anon_vma = anon_vma;
76810 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
76811 + avc_m = NULL;
76812 + }
76813 +#endif
76814 +
76815 vma->anon_vma = anon_vma;
76816 anon_vma_chain_link(vma, avc, anon_vma);
76817 allocated = NULL;
76818 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76819
76820 if (unlikely(allocated))
76821 put_anon_vma(allocated);
76822 +
76823 +#ifdef CONFIG_PAX_SEGMEXEC
76824 + if (unlikely(avc_m))
76825 + anon_vma_chain_free(avc_m);
76826 +#endif
76827 +
76828 if (unlikely(avc))
76829 anon_vma_chain_free(avc);
76830 }
76831 return 0;
76832
76833 out_enomem_free_avc:
76834 +
76835 +#ifdef CONFIG_PAX_SEGMEXEC
76836 + if (avc_m)
76837 + anon_vma_chain_free(avc_m);
76838 +#endif
76839 +
76840 anon_vma_chain_free(avc);
76841 out_enomem:
76842 return -ENOMEM;
76843 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
76844 * Attach the anon_vmas from src to dst.
76845 * Returns 0 on success, -ENOMEM on failure.
76846 */
76847 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
76848 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
76849 {
76850 struct anon_vma_chain *avc, *pavc;
76851 struct anon_vma *root = NULL;
76852 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
76853 * the corresponding VMA in the parent process is attached to.
76854 * Returns 0 on success, non-zero on failure.
76855 */
76856 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
76857 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
76858 {
76859 struct anon_vma_chain *avc;
76860 struct anon_vma *anon_vma;
76861 diff --git a/mm/shmem.c b/mm/shmem.c
76862 index 50c5b8f..0bc87f7 100644
76863 --- a/mm/shmem.c
76864 +++ b/mm/shmem.c
76865 @@ -31,7 +31,7 @@
76866 #include <linux/export.h>
76867 #include <linux/swap.h>
76868
76869 -static struct vfsmount *shm_mnt;
76870 +struct vfsmount *shm_mnt;
76871
76872 #ifdef CONFIG_SHMEM
76873 /*
76874 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
76875 #define BOGO_DIRENT_SIZE 20
76876
76877 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
76878 -#define SHORT_SYMLINK_LEN 128
76879 +#define SHORT_SYMLINK_LEN 64
76880
76881 /*
76882 * shmem_fallocate and shmem_writepage communicate via inode->i_private
76883 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
76884 static int shmem_xattr_validate(const char *name)
76885 {
76886 struct { const char *prefix; size_t len; } arr[] = {
76887 +
76888 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76889 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
76890 +#endif
76891 +
76892 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
76893 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
76894 };
76895 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
76896 if (err)
76897 return err;
76898
76899 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76900 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
76901 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
76902 + return -EOPNOTSUPP;
76903 + if (size > 8)
76904 + return -EINVAL;
76905 + }
76906 +#endif
76907 +
76908 return simple_xattr_set(&info->xattrs, name, value, size, flags);
76909 }
76910
76911 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
76912 int err = -ENOMEM;
76913
76914 /* Round up to L1_CACHE_BYTES to resist false sharing */
76915 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
76916 - L1_CACHE_BYTES), GFP_KERNEL);
76917 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
76918 if (!sbinfo)
76919 return -ENOMEM;
76920
76921 diff --git a/mm/slab.c b/mm/slab.c
76922 index 33d3363..93c6810 100644
76923 --- a/mm/slab.c
76924 +++ b/mm/slab.c
76925 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
76926
76927 /* Legal flag mask for kmem_cache_create(). */
76928 #if DEBUG
76929 -# define CREATE_MASK (SLAB_RED_ZONE | \
76930 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
76931 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
76932 SLAB_CACHE_DMA | \
76933 SLAB_STORE_USER | \
76934 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
76935 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
76936 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
76937 #else
76938 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
76939 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
76940 SLAB_CACHE_DMA | \
76941 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
76942 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
76943 @@ -322,7 +322,7 @@ struct kmem_list3 {
76944 * Need this for bootstrapping a per node allocator.
76945 */
76946 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
76947 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
76948 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
76949 #define CACHE_CACHE 0
76950 #define SIZE_AC MAX_NUMNODES
76951 #define SIZE_L3 (2 * MAX_NUMNODES)
76952 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
76953 if ((x)->max_freeable < i) \
76954 (x)->max_freeable = i; \
76955 } while (0)
76956 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
76957 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
76958 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
76959 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
76960 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
76961 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
76962 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
76963 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
76964 #else
76965 #define STATS_INC_ACTIVE(x) do { } while (0)
76966 #define STATS_DEC_ACTIVE(x) do { } while (0)
76967 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
76968 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
76969 */
76970 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
76971 - const struct slab *slab, void *obj)
76972 + const struct slab *slab, const void *obj)
76973 {
76974 u32 offset = (obj - slab->s_mem);
76975 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
76976 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
76977 struct cache_names {
76978 char *name;
76979 char *name_dma;
76980 + char *name_usercopy;
76981 };
76982
76983 static struct cache_names __initdata cache_names[] = {
76984 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
76985 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
76986 #include <linux/kmalloc_sizes.h>
76987 - {NULL,}
76988 + {NULL}
76989 #undef CACHE
76990 };
76991
76992 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
76993 if (unlikely(gfpflags & GFP_DMA))
76994 return csizep->cs_dmacachep;
76995 #endif
76996 +
76997 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76998 + if (unlikely(gfpflags & GFP_USERCOPY))
76999 + return csizep->cs_usercopycachep;
77000 +#endif
77001 +
77002 return csizep->cs_cachep;
77003 }
77004
77005 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77006 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77007 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77008 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77009 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77010 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77011 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77012
77013 if (INDEX_AC != INDEX_L3) {
77014 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77015 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77016 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77017 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77018 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77019 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77020 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77021 }
77022
77023 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77024 sizes->cs_cachep->size = sizes->cs_size;
77025 sizes->cs_cachep->object_size = sizes->cs_size;
77026 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77027 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77028 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77029 list_add(&sizes->cs_cachep->list, &slab_caches);
77030 }
77031 #ifdef CONFIG_ZONE_DMA
77032 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77033 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77034 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77035 #endif
77036 +
77037 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77038 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77039 + sizes->cs_usercopycachep->name = names->name_dma;
77040 + sizes->cs_usercopycachep->size = sizes->cs_size;
77041 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
77042 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77043 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77044 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77045 +#endif
77046 +
77047 sizes++;
77048 names++;
77049 }
77050 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77051 }
77052 /* cpu stats */
77053 {
77054 - unsigned long allochit = atomic_read(&cachep->allochit);
77055 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77056 - unsigned long freehit = atomic_read(&cachep->freehit);
77057 - unsigned long freemiss = atomic_read(&cachep->freemiss);
77058 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77059 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77060 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77061 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77062
77063 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77064 allochit, allocmiss, freehit, freemiss);
77065 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77066 {
77067 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77068 #ifdef CONFIG_DEBUG_SLAB_LEAK
77069 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77070 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77071 #endif
77072 return 0;
77073 }
77074 module_init(slab_proc_init);
77075 #endif
77076
77077 +bool is_usercopy_object(const void *ptr)
77078 +{
77079 + struct page *page;
77080 + struct kmem_cache *cachep;
77081 +
77082 + if (ZERO_OR_NULL_PTR(ptr))
77083 + return false;
77084 +
77085 + if (!slab_is_available())
77086 + return false;
77087 +
77088 + if (!virt_addr_valid(ptr))
77089 + return false;
77090 +
77091 + page = virt_to_head_page(ptr);
77092 +
77093 + if (!PageSlab(page))
77094 + return false;
77095 +
77096 + cachep = page->slab_cache;
77097 + return cachep->flags & SLAB_USERCOPY;
77098 +}
77099 +
77100 +#ifdef CONFIG_PAX_USERCOPY
77101 +const char *check_heap_object(const void *ptr, unsigned long n)
77102 +{
77103 + struct page *page;
77104 + struct kmem_cache *cachep;
77105 + struct slab *slabp;
77106 + unsigned int objnr;
77107 + unsigned long offset;
77108 +
77109 + if (ZERO_OR_NULL_PTR(ptr))
77110 + return "<null>";
77111 +
77112 + if (!virt_addr_valid(ptr))
77113 + return NULL;
77114 +
77115 + page = virt_to_head_page(ptr);
77116 +
77117 + if (!PageSlab(page))
77118 + return NULL;
77119 +
77120 + cachep = page->slab_cache;
77121 + if (!(cachep->flags & SLAB_USERCOPY))
77122 + return cachep->name;
77123 +
77124 + slabp = page->slab_page;
77125 + objnr = obj_to_index(cachep, slabp, ptr);
77126 + BUG_ON(objnr >= cachep->num);
77127 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77128 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77129 + return NULL;
77130 +
77131 + return cachep->name;
77132 +}
77133 +#endif
77134 +
77135 /**
77136 * ksize - get the actual amount of memory allocated for a given object
77137 * @objp: Pointer to the object
77138 diff --git a/mm/slab_common.c b/mm/slab_common.c
77139 index 069a24e6..226a310 100644
77140 --- a/mm/slab_common.c
77141 +++ b/mm/slab_common.c
77142 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77143 err = __kmem_cache_create(s, flags);
77144 if (!err) {
77145
77146 - s->refcount = 1;
77147 + atomic_set(&s->refcount, 1);
77148 list_add(&s->list, &slab_caches);
77149
77150 } else {
77151 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77152 {
77153 get_online_cpus();
77154 mutex_lock(&slab_mutex);
77155 - s->refcount--;
77156 - if (!s->refcount) {
77157 + if (atomic_dec_and_test(&s->refcount)) {
77158 list_del(&s->list);
77159
77160 if (!__kmem_cache_shutdown(s)) {
77161 diff --git a/mm/slob.c b/mm/slob.c
77162 index 1e921c5..1ce12c2 100644
77163 --- a/mm/slob.c
77164 +++ b/mm/slob.c
77165 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77166 /*
77167 * Return the size of a slob block.
77168 */
77169 -static slobidx_t slob_units(slob_t *s)
77170 +static slobidx_t slob_units(const slob_t *s)
77171 {
77172 if (s->units > 0)
77173 return s->units;
77174 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77175 /*
77176 * Return the next free slob block pointer after this one.
77177 */
77178 -static slob_t *slob_next(slob_t *s)
77179 +static slob_t *slob_next(const slob_t *s)
77180 {
77181 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77182 slobidx_t next;
77183 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77184 /*
77185 * Returns true if s is the last free block in its page.
77186 */
77187 -static int slob_last(slob_t *s)
77188 +static int slob_last(const slob_t *s)
77189 {
77190 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77191 }
77192
77193 -static void *slob_new_pages(gfp_t gfp, int order, int node)
77194 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77195 {
77196 - void *page;
77197 + struct page *page;
77198
77199 #ifdef CONFIG_NUMA
77200 if (node != NUMA_NO_NODE)
77201 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77202 if (!page)
77203 return NULL;
77204
77205 - return page_address(page);
77206 + __SetPageSlab(page);
77207 + return page;
77208 }
77209
77210 -static void slob_free_pages(void *b, int order)
77211 +static void slob_free_pages(struct page *sp, int order)
77212 {
77213 if (current->reclaim_state)
77214 current->reclaim_state->reclaimed_slab += 1 << order;
77215 - free_pages((unsigned long)b, order);
77216 + __ClearPageSlab(sp);
77217 + reset_page_mapcount(sp);
77218 + sp->private = 0;
77219 + __free_pages(sp, order);
77220 }
77221
77222 /*
77223 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77224
77225 /* Not enough space: must allocate a new page */
77226 if (!b) {
77227 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77228 - if (!b)
77229 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77230 + if (!sp)
77231 return NULL;
77232 - sp = virt_to_page(b);
77233 - __SetPageSlab(sp);
77234 + b = page_address(sp);
77235
77236 spin_lock_irqsave(&slob_lock, flags);
77237 sp->units = SLOB_UNITS(PAGE_SIZE);
77238 sp->freelist = b;
77239 + sp->private = 0;
77240 INIT_LIST_HEAD(&sp->list);
77241 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77242 set_slob_page_free(sp, slob_list);
77243 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77244 if (slob_page_free(sp))
77245 clear_slob_page_free(sp);
77246 spin_unlock_irqrestore(&slob_lock, flags);
77247 - __ClearPageSlab(sp);
77248 - reset_page_mapcount(sp);
77249 - slob_free_pages(b, 0);
77250 + slob_free_pages(sp, 0);
77251 return;
77252 }
77253
77254 @@ -426,11 +428,10 @@ out:
77255 */
77256
77257 static __always_inline void *
77258 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77259 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77260 {
77261 - unsigned int *m;
77262 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77263 - void *ret;
77264 + slob_t *m;
77265 + void *ret = NULL;
77266
77267 gfp &= gfp_allowed_mask;
77268
77269 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77270
77271 if (!m)
77272 return NULL;
77273 - *m = size;
77274 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77275 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77276 + m[0].units = size;
77277 + m[1].units = align;
77278 ret = (void *)m + align;
77279
77280 trace_kmalloc_node(caller, ret,
77281 size, size + align, gfp, node);
77282 } else {
77283 unsigned int order = get_order(size);
77284 + struct page *page;
77285
77286 if (likely(order))
77287 gfp |= __GFP_COMP;
77288 - ret = slob_new_pages(gfp, order, node);
77289 - if (ret) {
77290 - struct page *page;
77291 - page = virt_to_page(ret);
77292 + page = slob_new_pages(gfp, order, node);
77293 + if (page) {
77294 + ret = page_address(page);
77295 page->private = size;
77296 }
77297
77298 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77299 size, PAGE_SIZE << order, gfp, node);
77300 }
77301
77302 - kmemleak_alloc(ret, size, 1, gfp);
77303 + return ret;
77304 +}
77305 +
77306 +static __always_inline void *
77307 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77308 +{
77309 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77310 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77311 +
77312 + if (!ZERO_OR_NULL_PTR(ret))
77313 + kmemleak_alloc(ret, size, 1, gfp);
77314 return ret;
77315 }
77316
77317 @@ -501,15 +515,91 @@ void kfree(const void *block)
77318 kmemleak_free(block);
77319
77320 sp = virt_to_page(block);
77321 - if (PageSlab(sp)) {
77322 + VM_BUG_ON(!PageSlab(sp));
77323 + if (!sp->private) {
77324 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77325 - unsigned int *m = (unsigned int *)(block - align);
77326 - slob_free(m, *m + align);
77327 - } else
77328 + slob_t *m = (slob_t *)(block - align);
77329 + slob_free(m, m[0].units + align);
77330 + } else {
77331 + __ClearPageSlab(sp);
77332 + reset_page_mapcount(sp);
77333 + sp->private = 0;
77334 put_page(sp);
77335 + }
77336 }
77337 EXPORT_SYMBOL(kfree);
77338
77339 +bool is_usercopy_object(const void *ptr)
77340 +{
77341 + if (!slab_is_available())
77342 + return false;
77343 +
77344 + // PAX: TODO
77345 +
77346 + return false;
77347 +}
77348 +
77349 +#ifdef CONFIG_PAX_USERCOPY
77350 +const char *check_heap_object(const void *ptr, unsigned long n)
77351 +{
77352 + struct page *page;
77353 + const slob_t *free;
77354 + const void *base;
77355 + unsigned long flags;
77356 +
77357 + if (ZERO_OR_NULL_PTR(ptr))
77358 + return "<null>";
77359 +
77360 + if (!virt_addr_valid(ptr))
77361 + return NULL;
77362 +
77363 + page = virt_to_head_page(ptr);
77364 + if (!PageSlab(page))
77365 + return NULL;
77366 +
77367 + if (page->private) {
77368 + base = page;
77369 + if (base <= ptr && n <= page->private - (ptr - base))
77370 + return NULL;
77371 + return "<slob>";
77372 + }
77373 +
77374 + /* some tricky double walking to find the chunk */
77375 + spin_lock_irqsave(&slob_lock, flags);
77376 + base = (void *)((unsigned long)ptr & PAGE_MASK);
77377 + free = page->freelist;
77378 +
77379 + while (!slob_last(free) && (void *)free <= ptr) {
77380 + base = free + slob_units(free);
77381 + free = slob_next(free);
77382 + }
77383 +
77384 + while (base < (void *)free) {
77385 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77386 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
77387 + int offset;
77388 +
77389 + if (ptr < base + align)
77390 + break;
77391 +
77392 + offset = ptr - base - align;
77393 + if (offset >= m) {
77394 + base += size;
77395 + continue;
77396 + }
77397 +
77398 + if (n > m - offset)
77399 + break;
77400 +
77401 + spin_unlock_irqrestore(&slob_lock, flags);
77402 + return NULL;
77403 + }
77404 +
77405 + spin_unlock_irqrestore(&slob_lock, flags);
77406 + return "<slob>";
77407 +}
77408 +#endif
77409 +
77410 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77411 size_t ksize(const void *block)
77412 {
77413 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
77414 return 0;
77415
77416 sp = virt_to_page(block);
77417 - if (PageSlab(sp)) {
77418 + VM_BUG_ON(!PageSlab(sp));
77419 + if (!sp->private) {
77420 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77421 - unsigned int *m = (unsigned int *)(block - align);
77422 - return SLOB_UNITS(*m) * SLOB_UNIT;
77423 + slob_t *m = (slob_t *)(block - align);
77424 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77425 } else
77426 return sp->private;
77427 }
77428 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77429
77430 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77431 {
77432 - void *b;
77433 + void *b = NULL;
77434
77435 flags &= gfp_allowed_mask;
77436
77437 lockdep_trace_alloc(flags);
77438
77439 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77440 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77441 +#else
77442 if (c->size < PAGE_SIZE) {
77443 b = slob_alloc(c->size, flags, c->align, node);
77444 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77445 SLOB_UNITS(c->size) * SLOB_UNIT,
77446 flags, node);
77447 } else {
77448 - b = slob_new_pages(flags, get_order(c->size), node);
77449 + struct page *sp;
77450 +
77451 + sp = slob_new_pages(flags, get_order(c->size), node);
77452 + if (sp) {
77453 + b = page_address(sp);
77454 + sp->private = c->size;
77455 + }
77456 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77457 PAGE_SIZE << get_order(c->size),
77458 flags, node);
77459 }
77460 +#endif
77461
77462 if (c->ctor)
77463 c->ctor(b);
77464 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77465
77466 static void __kmem_cache_free(void *b, int size)
77467 {
77468 - if (size < PAGE_SIZE)
77469 + struct page *sp;
77470 +
77471 + sp = virt_to_page(b);
77472 + BUG_ON(!PageSlab(sp));
77473 + if (!sp->private)
77474 slob_free(b, size);
77475 else
77476 - slob_free_pages(b, get_order(size));
77477 + slob_free_pages(sp, get_order(size));
77478 }
77479
77480 static void kmem_rcu_free(struct rcu_head *head)
77481 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77482
77483 void kmem_cache_free(struct kmem_cache *c, void *b)
77484 {
77485 + int size = c->size;
77486 +
77487 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77488 + if (size + c->align < PAGE_SIZE) {
77489 + size += c->align;
77490 + b -= c->align;
77491 + }
77492 +#endif
77493 +
77494 kmemleak_free_recursive(b, c->flags);
77495 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77496 struct slob_rcu *slob_rcu;
77497 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77498 - slob_rcu->size = c->size;
77499 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77500 + slob_rcu->size = size;
77501 call_rcu(&slob_rcu->head, kmem_rcu_free);
77502 } else {
77503 - __kmem_cache_free(b, c->size);
77504 + __kmem_cache_free(b, size);
77505 }
77506
77507 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77508 + trace_kfree(_RET_IP_, b);
77509 +#else
77510 trace_kmem_cache_free(_RET_IP_, b);
77511 +#endif
77512 +
77513 }
77514 EXPORT_SYMBOL(kmem_cache_free);
77515
77516 diff --git a/mm/slub.c b/mm/slub.c
77517 index a0d6984..e280e5d 100644
77518 --- a/mm/slub.c
77519 +++ b/mm/slub.c
77520 @@ -201,7 +201,7 @@ struct track {
77521
77522 enum track_item { TRACK_ALLOC, TRACK_FREE };
77523
77524 -#ifdef CONFIG_SYSFS
77525 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77526 static int sysfs_slab_add(struct kmem_cache *);
77527 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77528 static void sysfs_slab_remove(struct kmem_cache *);
77529 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77530 if (!t->addr)
77531 return;
77532
77533 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77534 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77535 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77536 #ifdef CONFIG_STACKTRACE
77537 {
77538 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77539
77540 page = virt_to_head_page(x);
77541
77542 + BUG_ON(!PageSlab(page));
77543 +
77544 if (kmem_cache_debug(s) && page->slab != s) {
77545 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77546 " is from %s\n", page->slab->name, s->name);
77547 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77548 * Merge control. If this is set then no merging of slab caches will occur.
77549 * (Could be removed. This was introduced to pacify the merge skeptics.)
77550 */
77551 -static int slub_nomerge;
77552 +static int slub_nomerge = 1;
77553
77554 /*
77555 * Calculate the order of allocation given an slab object size.
77556 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77557 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77558 #endif
77559
77560 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77561 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77562 +#endif
77563 +
77564 static int __init setup_slub_min_order(char *str)
77565 {
77566 get_option(&str, &slub_min_order);
77567 @@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77568 return kmalloc_dma_caches[index];
77569
77570 #endif
77571 +
77572 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77573 + if (flags & SLAB_USERCOPY)
77574 + return kmalloc_usercopy_caches[index];
77575 +
77576 +#endif
77577 +
77578 return kmalloc_caches[index];
77579 }
77580
77581 @@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77582 EXPORT_SYMBOL(__kmalloc_node);
77583 #endif
77584
77585 +bool is_usercopy_object(const void *ptr)
77586 +{
77587 + struct page *page;
77588 + struct kmem_cache *s;
77589 +
77590 + if (ZERO_OR_NULL_PTR(ptr))
77591 + return false;
77592 +
77593 + if (!slab_is_available())
77594 + return false;
77595 +
77596 + if (!virt_addr_valid(ptr))
77597 + return false;
77598 +
77599 + page = virt_to_head_page(ptr);
77600 +
77601 + if (!PageSlab(page))
77602 + return false;
77603 +
77604 + s = page->slab;
77605 + return s->flags & SLAB_USERCOPY;
77606 +}
77607 +
77608 +#ifdef CONFIG_PAX_USERCOPY
77609 +const char *check_heap_object(const void *ptr, unsigned long n)
77610 +{
77611 + struct page *page;
77612 + struct kmem_cache *s;
77613 + unsigned long offset;
77614 +
77615 + if (ZERO_OR_NULL_PTR(ptr))
77616 + return "<null>";
77617 +
77618 + if (!virt_addr_valid(ptr))
77619 + return NULL;
77620 +
77621 + page = virt_to_head_page(ptr);
77622 +
77623 + if (!PageSlab(page))
77624 + return NULL;
77625 +
77626 + s = page->slab;
77627 + if (!(s->flags & SLAB_USERCOPY))
77628 + return s->name;
77629 +
77630 + offset = (ptr - page_address(page)) % s->size;
77631 + if (offset <= s->object_size && n <= s->object_size - offset)
77632 + return NULL;
77633 +
77634 + return s->name;
77635 +}
77636 +#endif
77637 +
77638 size_t ksize(const void *object)
77639 {
77640 struct page *page;
77641 @@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77642 int node;
77643
77644 list_add(&s->list, &slab_caches);
77645 - s->refcount = -1;
77646 + atomic_set(&s->refcount, -1);
77647
77648 for_each_node_state(node, N_NORMAL_MEMORY) {
77649 struct kmem_cache_node *n = get_node(s, node);
77650 @@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
77651
77652 /* Caches that are not of the two-to-the-power-of size */
77653 if (KMALLOC_MIN_SIZE <= 32) {
77654 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77655 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77656 caches++;
77657 }
77658
77659 if (KMALLOC_MIN_SIZE <= 64) {
77660 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77661 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77662 caches++;
77663 }
77664
77665 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77666 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77667 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77668 caches++;
77669 }
77670
77671 @@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
77672 }
77673 }
77674 #endif
77675 +
77676 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77677 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
77678 + struct kmem_cache *s = kmalloc_caches[i];
77679 +
77680 + if (s && s->size) {
77681 + char *name = kasprintf(GFP_NOWAIT,
77682 + "usercopy-kmalloc-%d", s->object_size);
77683 +
77684 + BUG_ON(!name);
77685 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
77686 + s->object_size, SLAB_USERCOPY);
77687 + }
77688 + }
77689 +#endif
77690 +
77691 printk(KERN_INFO
77692 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
77693 " CPUs=%d, Nodes=%d\n",
77694 @@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
77695 /*
77696 * We may have set a slab to be unmergeable during bootstrap.
77697 */
77698 - if (s->refcount < 0)
77699 + if (atomic_read(&s->refcount) < 0)
77700 return 1;
77701
77702 return 0;
77703 @@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77704
77705 s = find_mergeable(size, align, flags, name, ctor);
77706 if (s) {
77707 - s->refcount++;
77708 + atomic_inc(&s->refcount);
77709 /*
77710 * Adjust the object sizes so that we clear
77711 * the complete object on kzalloc.
77712 @@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77713 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
77714
77715 if (sysfs_slab_alias(s, name)) {
77716 - s->refcount--;
77717 + atomic_dec(&s->refcount);
77718 s = NULL;
77719 }
77720 }
77721 @@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
77722 }
77723 #endif
77724
77725 -#ifdef CONFIG_SYSFS
77726 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77727 static int count_inuse(struct page *page)
77728 {
77729 return page->inuse;
77730 @@ -4450,12 +4532,12 @@ static void resiliency_test(void)
77731 validate_slab_cache(kmalloc_caches[9]);
77732 }
77733 #else
77734 -#ifdef CONFIG_SYSFS
77735 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77736 static void resiliency_test(void) {};
77737 #endif
77738 #endif
77739
77740 -#ifdef CONFIG_SYSFS
77741 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77742 enum slab_stat_type {
77743 SL_ALL, /* All slabs */
77744 SL_PARTIAL, /* Only partially allocated slabs */
77745 @@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
77746
77747 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
77748 {
77749 - return sprintf(buf, "%d\n", s->refcount - 1);
77750 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
77751 }
77752 SLAB_ATTR_RO(aliases);
77753
77754 @@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
77755 return name;
77756 }
77757
77758 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77759 static int sysfs_slab_add(struct kmem_cache *s)
77760 {
77761 int err;
77762 @@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
77763 kobject_del(&s->kobj);
77764 kobject_put(&s->kobj);
77765 }
77766 +#endif
77767
77768 /*
77769 * Need to buffer aliases during bootup until sysfs becomes
77770 @@ -5336,6 +5420,7 @@ struct saved_alias {
77771
77772 static struct saved_alias *alias_list;
77773
77774 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77775 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77776 {
77777 struct saved_alias *al;
77778 @@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77779 alias_list = al;
77780 return 0;
77781 }
77782 +#endif
77783
77784 static int __init slab_sysfs_init(void)
77785 {
77786 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
77787 index 1b7e22a..3fcd4f3 100644
77788 --- a/mm/sparse-vmemmap.c
77789 +++ b/mm/sparse-vmemmap.c
77790 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
77791 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77792 if (!p)
77793 return NULL;
77794 - pud_populate(&init_mm, pud, p);
77795 + pud_populate_kernel(&init_mm, pud, p);
77796 }
77797 return pud;
77798 }
77799 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
77800 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77801 if (!p)
77802 return NULL;
77803 - pgd_populate(&init_mm, pgd, p);
77804 + pgd_populate_kernel(&init_mm, pgd, p);
77805 }
77806 return pgd;
77807 }
77808 diff --git a/mm/swap.c b/mm/swap.c
77809 index 6310dc2..3662b3f 100644
77810 --- a/mm/swap.c
77811 +++ b/mm/swap.c
77812 @@ -30,6 +30,7 @@
77813 #include <linux/backing-dev.h>
77814 #include <linux/memcontrol.h>
77815 #include <linux/gfp.h>
77816 +#include <linux/hugetlb.h>
77817
77818 #include "internal.h"
77819
77820 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
77821
77822 __page_cache_release(page);
77823 dtor = get_compound_page_dtor(page);
77824 + if (!PageHuge(page))
77825 + BUG_ON(dtor != free_compound_page);
77826 (*dtor)(page);
77827 }
77828
77829 diff --git a/mm/swapfile.c b/mm/swapfile.c
77830 index f91a255..9dcac21 100644
77831 --- a/mm/swapfile.c
77832 +++ b/mm/swapfile.c
77833 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
77834
77835 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
77836 /* Activity counter to indicate that a swapon or swapoff has occurred */
77837 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
77838 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
77839
77840 static inline unsigned char swap_count(unsigned char ent)
77841 {
77842 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
77843 }
77844 filp_close(swap_file, NULL);
77845 err = 0;
77846 - atomic_inc(&proc_poll_event);
77847 + atomic_inc_unchecked(&proc_poll_event);
77848 wake_up_interruptible(&proc_poll_wait);
77849
77850 out_dput:
77851 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
77852
77853 poll_wait(file, &proc_poll_wait, wait);
77854
77855 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
77856 - seq->poll_event = atomic_read(&proc_poll_event);
77857 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
77858 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77859 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
77860 }
77861
77862 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
77863 return ret;
77864
77865 seq = file->private_data;
77866 - seq->poll_event = atomic_read(&proc_poll_event);
77867 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77868 return 0;
77869 }
77870
77871 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
77872 (frontswap_map) ? "FS" : "");
77873
77874 mutex_unlock(&swapon_mutex);
77875 - atomic_inc(&proc_poll_event);
77876 + atomic_inc_unchecked(&proc_poll_event);
77877 wake_up_interruptible(&proc_poll_wait);
77878
77879 if (S_ISREG(inode->i_mode))
77880 diff --git a/mm/util.c b/mm/util.c
77881 index dc3036c..b6c7c9d 100644
77882 --- a/mm/util.c
77883 +++ b/mm/util.c
77884 @@ -292,6 +292,12 @@ done:
77885 void arch_pick_mmap_layout(struct mm_struct *mm)
77886 {
77887 mm->mmap_base = TASK_UNMAPPED_BASE;
77888 +
77889 +#ifdef CONFIG_PAX_RANDMMAP
77890 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77891 + mm->mmap_base += mm->delta_mmap;
77892 +#endif
77893 +
77894 mm->get_unmapped_area = arch_get_unmapped_area;
77895 mm->unmap_area = arch_unmap_area;
77896 }
77897 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
77898 index 78e0830..bc6bbd8 100644
77899 --- a/mm/vmalloc.c
77900 +++ b/mm/vmalloc.c
77901 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
77902
77903 pte = pte_offset_kernel(pmd, addr);
77904 do {
77905 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77906 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77907 +
77908 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77909 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
77910 + BUG_ON(!pte_exec(*pte));
77911 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
77912 + continue;
77913 + }
77914 +#endif
77915 +
77916 + {
77917 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77918 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77919 + }
77920 } while (pte++, addr += PAGE_SIZE, addr != end);
77921 }
77922
77923 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
77924 pte = pte_alloc_kernel(pmd, addr);
77925 if (!pte)
77926 return -ENOMEM;
77927 +
77928 + pax_open_kernel();
77929 do {
77930 struct page *page = pages[*nr];
77931
77932 - if (WARN_ON(!pte_none(*pte)))
77933 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77934 + if (pgprot_val(prot) & _PAGE_NX)
77935 +#endif
77936 +
77937 + if (!pte_none(*pte)) {
77938 + pax_close_kernel();
77939 + WARN_ON(1);
77940 return -EBUSY;
77941 - if (WARN_ON(!page))
77942 + }
77943 + if (!page) {
77944 + pax_close_kernel();
77945 + WARN_ON(1);
77946 return -ENOMEM;
77947 + }
77948 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
77949 (*nr)++;
77950 } while (pte++, addr += PAGE_SIZE, addr != end);
77951 + pax_close_kernel();
77952 return 0;
77953 }
77954
77955 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
77956 pmd_t *pmd;
77957 unsigned long next;
77958
77959 - pmd = pmd_alloc(&init_mm, pud, addr);
77960 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
77961 if (!pmd)
77962 return -ENOMEM;
77963 do {
77964 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
77965 pud_t *pud;
77966 unsigned long next;
77967
77968 - pud = pud_alloc(&init_mm, pgd, addr);
77969 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
77970 if (!pud)
77971 return -ENOMEM;
77972 do {
77973 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
77974 * and fall back on vmalloc() if that fails. Others
77975 * just put it in the vmalloc space.
77976 */
77977 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
77978 +#ifdef CONFIG_MODULES
77979 +#ifdef MODULES_VADDR
77980 unsigned long addr = (unsigned long)x;
77981 if (addr >= MODULES_VADDR && addr < MODULES_END)
77982 return 1;
77983 #endif
77984 +
77985 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77986 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
77987 + return 1;
77988 +#endif
77989 +
77990 +#endif
77991 +
77992 return is_vmalloc_addr(x);
77993 }
77994
77995 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
77996
77997 if (!pgd_none(*pgd)) {
77998 pud_t *pud = pud_offset(pgd, addr);
77999 +#ifdef CONFIG_X86
78000 + if (!pud_large(*pud))
78001 +#endif
78002 if (!pud_none(*pud)) {
78003 pmd_t *pmd = pmd_offset(pud, addr);
78004 +#ifdef CONFIG_X86
78005 + if (!pmd_large(*pmd))
78006 +#endif
78007 if (!pmd_none(*pmd)) {
78008 pte_t *ptep, pte;
78009
78010 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78011 * Allocate a region of KVA of the specified size and alignment, within the
78012 * vstart and vend.
78013 */
78014 -static struct vmap_area *alloc_vmap_area(unsigned long size,
78015 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78016 unsigned long align,
78017 unsigned long vstart, unsigned long vend,
78018 int node, gfp_t gfp_mask)
78019 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78020 struct vm_struct *area;
78021
78022 BUG_ON(in_interrupt());
78023 +
78024 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78025 + if (flags & VM_KERNEXEC) {
78026 + if (start != VMALLOC_START || end != VMALLOC_END)
78027 + return NULL;
78028 + start = (unsigned long)MODULES_EXEC_VADDR;
78029 + end = (unsigned long)MODULES_EXEC_END;
78030 + }
78031 +#endif
78032 +
78033 if (flags & VM_IOREMAP) {
78034 int bit = fls(size);
78035
78036 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78037 if (count > totalram_pages)
78038 return NULL;
78039
78040 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78041 + if (!(pgprot_val(prot) & _PAGE_NX))
78042 + flags |= VM_KERNEXEC;
78043 +#endif
78044 +
78045 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78046 __builtin_return_address(0));
78047 if (!area)
78048 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78049 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78050 goto fail;
78051
78052 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78053 + if (!(pgprot_val(prot) & _PAGE_NX))
78054 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78055 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78056 + else
78057 +#endif
78058 +
78059 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78060 start, end, node, gfp_mask, caller);
78061 if (!area)
78062 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78063 * For tight control over page level allocator and protection flags
78064 * use __vmalloc() instead.
78065 */
78066 -
78067 void *vmalloc_exec(unsigned long size)
78068 {
78069 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78070 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78071 -1, __builtin_return_address(0));
78072 }
78073
78074 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78075 unsigned long uaddr = vma->vm_start;
78076 unsigned long usize = vma->vm_end - vma->vm_start;
78077
78078 + BUG_ON(vma->vm_mirror);
78079 +
78080 if ((PAGE_SIZE-1) & (unsigned long)addr)
78081 return -EINVAL;
78082
78083 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78084 v->addr, v->addr + v->size, v->size);
78085
78086 if (v->caller)
78087 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78088 + seq_printf(m, " %pK", v->caller);
78089 +#else
78090 seq_printf(m, " %pS", v->caller);
78091 +#endif
78092
78093 if (v->nr_pages)
78094 seq_printf(m, " pages=%d", v->nr_pages);
78095 diff --git a/mm/vmstat.c b/mm/vmstat.c
78096 index c737057..a49753a 100644
78097 --- a/mm/vmstat.c
78098 +++ b/mm/vmstat.c
78099 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78100 *
78101 * vm_stat contains the global counters
78102 */
78103 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78104 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78105 EXPORT_SYMBOL(vm_stat);
78106
78107 #ifdef CONFIG_SMP
78108 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78109 v = p->vm_stat_diff[i];
78110 p->vm_stat_diff[i] = 0;
78111 local_irq_restore(flags);
78112 - atomic_long_add(v, &zone->vm_stat[i]);
78113 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78114 global_diff[i] += v;
78115 #ifdef CONFIG_NUMA
78116 /* 3 seconds idle till flush */
78117 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78118
78119 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78120 if (global_diff[i])
78121 - atomic_long_add(global_diff[i], &vm_stat[i]);
78122 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78123 }
78124
78125 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78126 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78127 if (pset->vm_stat_diff[i]) {
78128 int v = pset->vm_stat_diff[i];
78129 pset->vm_stat_diff[i] = 0;
78130 - atomic_long_add(v, &zone->vm_stat[i]);
78131 - atomic_long_add(v, &vm_stat[i]);
78132 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78133 + atomic_long_add_unchecked(v, &vm_stat[i]);
78134 }
78135 }
78136 #endif
78137 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78138 start_cpu_timer(cpu);
78139 #endif
78140 #ifdef CONFIG_PROC_FS
78141 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78142 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78143 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78144 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78145 + {
78146 + mode_t gr_mode = S_IRUGO;
78147 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78148 + gr_mode = S_IRUSR;
78149 +#endif
78150 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78151 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78152 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78153 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78154 +#else
78155 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78156 +#endif
78157 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78158 + }
78159 #endif
78160 return 0;
78161 }
78162 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78163 index ee07072..593e3fd 100644
78164 --- a/net/8021q/vlan.c
78165 +++ b/net/8021q/vlan.c
78166 @@ -484,7 +484,7 @@ out:
78167 return NOTIFY_DONE;
78168 }
78169
78170 -static struct notifier_block vlan_notifier_block __read_mostly = {
78171 +static struct notifier_block vlan_notifier_block = {
78172 .notifier_call = vlan_device_event,
78173 };
78174
78175 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78176 err = -EPERM;
78177 if (!capable(CAP_NET_ADMIN))
78178 break;
78179 - if ((args.u.name_type >= 0) &&
78180 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78181 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78182 struct vlan_net *vn;
78183
78184 vn = net_generic(net, vlan_net_id);
78185 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78186 index 02efb25..41541a9 100644
78187 --- a/net/9p/trans_fd.c
78188 +++ b/net/9p/trans_fd.c
78189 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78190 oldfs = get_fs();
78191 set_fs(get_ds());
78192 /* The cast to a user pointer is valid due to the set_fs() */
78193 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78194 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78195 set_fs(oldfs);
78196
78197 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78198 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78199 index 876fbe8..8bbea9f 100644
78200 --- a/net/atm/atm_misc.c
78201 +++ b/net/atm/atm_misc.c
78202 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78203 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78204 return 1;
78205 atm_return(vcc, truesize);
78206 - atomic_inc(&vcc->stats->rx_drop);
78207 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78208 return 0;
78209 }
78210 EXPORT_SYMBOL(atm_charge);
78211 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78212 }
78213 }
78214 atm_return(vcc, guess);
78215 - atomic_inc(&vcc->stats->rx_drop);
78216 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78217 return NULL;
78218 }
78219 EXPORT_SYMBOL(atm_alloc_charge);
78220 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78221
78222 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78223 {
78224 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78225 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78226 __SONET_ITEMS
78227 #undef __HANDLE_ITEM
78228 }
78229 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78230
78231 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78232 {
78233 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78234 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78235 __SONET_ITEMS
78236 #undef __HANDLE_ITEM
78237 }
78238 diff --git a/net/atm/lec.h b/net/atm/lec.h
78239 index a86aff9..3a0d6f6 100644
78240 --- a/net/atm/lec.h
78241 +++ b/net/atm/lec.h
78242 @@ -48,7 +48,7 @@ struct lane2_ops {
78243 const u8 *tlvs, u32 sizeoftlvs);
78244 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78245 const u8 *tlvs, u32 sizeoftlvs);
78246 -};
78247 +} __no_const;
78248
78249 /*
78250 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78251 diff --git a/net/atm/proc.c b/net/atm/proc.c
78252 index 0d020de..011c7bb 100644
78253 --- a/net/atm/proc.c
78254 +++ b/net/atm/proc.c
78255 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78256 const struct k_atm_aal_stats *stats)
78257 {
78258 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78259 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78260 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78261 - atomic_read(&stats->rx_drop));
78262 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78263 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78264 + atomic_read_unchecked(&stats->rx_drop));
78265 }
78266
78267 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78268 diff --git a/net/atm/resources.c b/net/atm/resources.c
78269 index 0447d5d..3cf4728 100644
78270 --- a/net/atm/resources.c
78271 +++ b/net/atm/resources.c
78272 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78273 static void copy_aal_stats(struct k_atm_aal_stats *from,
78274 struct atm_aal_stats *to)
78275 {
78276 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78277 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78278 __AAL_STAT_ITEMS
78279 #undef __HANDLE_ITEM
78280 }
78281 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78282 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78283 struct atm_aal_stats *to)
78284 {
78285 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78286 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78287 __AAL_STAT_ITEMS
78288 #undef __HANDLE_ITEM
78289 }
78290 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78291 index c6fcc76..1270d14 100644
78292 --- a/net/batman-adv/bat_iv_ogm.c
78293 +++ b/net/batman-adv/bat_iv_ogm.c
78294 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78295
78296 /* randomize initial seqno to avoid collision */
78297 get_random_bytes(&random_seqno, sizeof(random_seqno));
78298 - atomic_set(&hard_iface->seqno, random_seqno);
78299 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78300
78301 hard_iface->packet_len = BATADV_OGM_HLEN;
78302 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78303 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78304 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78305
78306 /* change sequence number to network order */
78307 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78308 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78309 batadv_ogm_packet->seqno = htonl(seqno);
78310 - atomic_inc(&hard_iface->seqno);
78311 + atomic_inc_unchecked(&hard_iface->seqno);
78312
78313 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78314 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78315 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78316 return;
78317
78318 /* could be changed by schedule_own_packet() */
78319 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
78320 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78321
78322 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78323 has_directlink_flag = 1;
78324 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78325 index d112fd6..686a447 100644
78326 --- a/net/batman-adv/hard-interface.c
78327 +++ b/net/batman-adv/hard-interface.c
78328 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78329 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78330 dev_add_pack(&hard_iface->batman_adv_ptype);
78331
78332 - atomic_set(&hard_iface->frag_seqno, 1);
78333 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78334 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78335 hard_iface->net_dev->name);
78336
78337 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78338 /* This can't be called via a bat_priv callback because
78339 * we have no bat_priv yet.
78340 */
78341 - atomic_set(&hard_iface->seqno, 1);
78342 + atomic_set_unchecked(&hard_iface->seqno, 1);
78343 hard_iface->packet_buff = NULL;
78344
78345 return hard_iface;
78346 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78347 index ce0684a..4a0cbf1 100644
78348 --- a/net/batman-adv/soft-interface.c
78349 +++ b/net/batman-adv/soft-interface.c
78350 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78351 primary_if->net_dev->dev_addr, ETH_ALEN);
78352
78353 /* set broadcast sequence number */
78354 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78355 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78356 bcast_packet->seqno = htonl(seqno);
78357
78358 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78359 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78360 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78361
78362 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78363 - atomic_set(&bat_priv->bcast_seqno, 1);
78364 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78365 atomic_set(&bat_priv->tt.vn, 0);
78366 atomic_set(&bat_priv->tt.local_changes, 0);
78367 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78368 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78369 index ac1e07a..4c846e2 100644
78370 --- a/net/batman-adv/types.h
78371 +++ b/net/batman-adv/types.h
78372 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
78373 int16_t if_num;
78374 char if_status;
78375 struct net_device *net_dev;
78376 - atomic_t seqno;
78377 - atomic_t frag_seqno;
78378 + atomic_unchecked_t seqno;
78379 + atomic_unchecked_t frag_seqno;
78380 unsigned char *packet_buff;
78381 int packet_len;
78382 struct kobject *hardif_obj;
78383 @@ -244,7 +244,7 @@ struct batadv_priv {
78384 atomic_t orig_interval; /* uint */
78385 atomic_t hop_penalty; /* uint */
78386 atomic_t log_level; /* uint */
78387 - atomic_t bcast_seqno;
78388 + atomic_unchecked_t bcast_seqno;
78389 atomic_t bcast_queue_left;
78390 atomic_t batman_queue_left;
78391 char num_ifaces;
78392 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78393 index f397232..3206a33 100644
78394 --- a/net/batman-adv/unicast.c
78395 +++ b/net/batman-adv/unicast.c
78396 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78397 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78398 frag2->flags = large_tail;
78399
78400 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78401 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78402 frag1->seqno = htons(seqno - 1);
78403 frag2->seqno = htons(seqno);
78404
78405 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78406 index 07f0739..3c42e34 100644
78407 --- a/net/bluetooth/hci_sock.c
78408 +++ b/net/bluetooth/hci_sock.c
78409 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78410 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78411 }
78412
78413 - len = min_t(unsigned int, len, sizeof(uf));
78414 + len = min((size_t)len, sizeof(uf));
78415 if (copy_from_user(&uf, optval, len)) {
78416 err = -EFAULT;
78417 break;
78418 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78419 index a91239d..d7ed533 100644
78420 --- a/net/bluetooth/l2cap_core.c
78421 +++ b/net/bluetooth/l2cap_core.c
78422 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78423 break;
78424
78425 case L2CAP_CONF_RFC:
78426 - if (olen == sizeof(rfc))
78427 - memcpy(&rfc, (void *)val, olen);
78428 + if (olen != sizeof(rfc))
78429 + break;
78430 +
78431 + memcpy(&rfc, (void *)val, olen);
78432
78433 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78434 rfc.mode != chan->mode)
78435 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78436 index 083f2bf..799f9448 100644
78437 --- a/net/bluetooth/l2cap_sock.c
78438 +++ b/net/bluetooth/l2cap_sock.c
78439 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78440 struct sock *sk = sock->sk;
78441 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78442 struct l2cap_options opts;
78443 - int len, err = 0;
78444 + int err = 0;
78445 + size_t len = optlen;
78446 u32 opt;
78447
78448 BT_DBG("sk %p", sk);
78449 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78450 opts.max_tx = chan->max_tx;
78451 opts.txwin_size = chan->tx_win;
78452
78453 - len = min_t(unsigned int, sizeof(opts), optlen);
78454 + len = min(sizeof(opts), len);
78455 if (copy_from_user((char *) &opts, optval, len)) {
78456 err = -EFAULT;
78457 break;
78458 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78459 struct bt_security sec;
78460 struct bt_power pwr;
78461 struct l2cap_conn *conn;
78462 - int len, err = 0;
78463 + int err = 0;
78464 + size_t len = optlen;
78465 u32 opt;
78466
78467 BT_DBG("sk %p", sk);
78468 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78469
78470 sec.level = BT_SECURITY_LOW;
78471
78472 - len = min_t(unsigned int, sizeof(sec), optlen);
78473 + len = min(sizeof(sec), len);
78474 if (copy_from_user((char *) &sec, optval, len)) {
78475 err = -EFAULT;
78476 break;
78477 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78478
78479 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78480
78481 - len = min_t(unsigned int, sizeof(pwr), optlen);
78482 + len = min(sizeof(pwr), len);
78483 if (copy_from_user((char *) &pwr, optval, len)) {
78484 err = -EFAULT;
78485 break;
78486 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78487 index 868a909..d044bc3 100644
78488 --- a/net/bluetooth/rfcomm/sock.c
78489 +++ b/net/bluetooth/rfcomm/sock.c
78490 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78491 struct sock *sk = sock->sk;
78492 struct bt_security sec;
78493 int err = 0;
78494 - size_t len;
78495 + size_t len = optlen;
78496 u32 opt;
78497
78498 BT_DBG("sk %p", sk);
78499 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78500
78501 sec.level = BT_SECURITY_LOW;
78502
78503 - len = min_t(unsigned int, sizeof(sec), optlen);
78504 + len = min(sizeof(sec), len);
78505 if (copy_from_user((char *) &sec, optval, len)) {
78506 err = -EFAULT;
78507 break;
78508 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78509 index ccc2487..921073d 100644
78510 --- a/net/bluetooth/rfcomm/tty.c
78511 +++ b/net/bluetooth/rfcomm/tty.c
78512 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78513 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78514
78515 spin_lock_irqsave(&dev->port.lock, flags);
78516 - if (dev->port.count > 0) {
78517 + if (atomic_read(&dev->port.count) > 0) {
78518 spin_unlock_irqrestore(&dev->port.lock, flags);
78519 return;
78520 }
78521 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78522 return -ENODEV;
78523
78524 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78525 - dev->channel, dev->port.count);
78526 + dev->channel, atomic_read(&dev->port.count));
78527
78528 spin_lock_irqsave(&dev->port.lock, flags);
78529 - if (++dev->port.count > 1) {
78530 + if (atomic_inc_return(&dev->port.count) > 1) {
78531 spin_unlock_irqrestore(&dev->port.lock, flags);
78532 return 0;
78533 }
78534 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78535 return;
78536
78537 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78538 - dev->port.count);
78539 + atomic_read(&dev->port.count));
78540
78541 spin_lock_irqsave(&dev->port.lock, flags);
78542 - if (!--dev->port.count) {
78543 + if (!atomic_dec_return(&dev->port.count)) {
78544 spin_unlock_irqrestore(&dev->port.lock, flags);
78545 if (dev->tty_dev->parent)
78546 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78547 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78548 index 5fe2ff3..121d696 100644
78549 --- a/net/bridge/netfilter/ebtables.c
78550 +++ b/net/bridge/netfilter/ebtables.c
78551 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78552 tmp.valid_hooks = t->table->valid_hooks;
78553 }
78554 mutex_unlock(&ebt_mutex);
78555 - if (copy_to_user(user, &tmp, *len) != 0){
78556 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78557 BUGPRINT("c2u Didn't work\n");
78558 ret = -EFAULT;
78559 break;
78560 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78561 goto out;
78562 tmp.valid_hooks = t->valid_hooks;
78563
78564 - if (copy_to_user(user, &tmp, *len) != 0) {
78565 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78566 ret = -EFAULT;
78567 break;
78568 }
78569 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78570 tmp.entries_size = t->table->entries_size;
78571 tmp.valid_hooks = t->table->valid_hooks;
78572
78573 - if (copy_to_user(user, &tmp, *len) != 0) {
78574 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78575 ret = -EFAULT;
78576 break;
78577 }
78578 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78579 index 44f270f..1f5602d 100644
78580 --- a/net/caif/cfctrl.c
78581 +++ b/net/caif/cfctrl.c
78582 @@ -10,6 +10,7 @@
78583 #include <linux/spinlock.h>
78584 #include <linux/slab.h>
78585 #include <linux/pkt_sched.h>
78586 +#include <linux/sched.h>
78587 #include <net/caif/caif_layer.h>
78588 #include <net/caif/cfpkt.h>
78589 #include <net/caif/cfctrl.h>
78590 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78591 memset(&dev_info, 0, sizeof(dev_info));
78592 dev_info.id = 0xff;
78593 cfsrvl_init(&this->serv, 0, &dev_info, false);
78594 - atomic_set(&this->req_seq_no, 1);
78595 - atomic_set(&this->rsp_seq_no, 1);
78596 + atomic_set_unchecked(&this->req_seq_no, 1);
78597 + atomic_set_unchecked(&this->rsp_seq_no, 1);
78598 this->serv.layer.receive = cfctrl_recv;
78599 sprintf(this->serv.layer.name, "ctrl");
78600 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78601 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78602 struct cfctrl_request_info *req)
78603 {
78604 spin_lock_bh(&ctrl->info_list_lock);
78605 - atomic_inc(&ctrl->req_seq_no);
78606 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
78607 + atomic_inc_unchecked(&ctrl->req_seq_no);
78608 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78609 list_add_tail(&req->list, &ctrl->list);
78610 spin_unlock_bh(&ctrl->info_list_lock);
78611 }
78612 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78613 if (p != first)
78614 pr_warn("Requests are not received in order\n");
78615
78616 - atomic_set(&ctrl->rsp_seq_no,
78617 + atomic_set_unchecked(&ctrl->rsp_seq_no,
78618 p->sequence_no);
78619 list_del(&p->list);
78620 goto out;
78621 diff --git a/net/can/af_can.c b/net/can/af_can.c
78622 index ddac1ee..3ee0a78 100644
78623 --- a/net/can/af_can.c
78624 +++ b/net/can/af_can.c
78625 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78626 };
78627
78628 /* notifier block for netdevice event */
78629 -static struct notifier_block can_netdev_notifier __read_mostly = {
78630 +static struct notifier_block can_netdev_notifier = {
78631 .notifier_call = can_notifier,
78632 };
78633
78634 diff --git a/net/can/gw.c b/net/can/gw.c
78635 index 1f5c978..ef714c7 100644
78636 --- a/net/can/gw.c
78637 +++ b/net/can/gw.c
78638 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78639 MODULE_ALIAS("can-gw");
78640
78641 static HLIST_HEAD(cgw_list);
78642 -static struct notifier_block notifier;
78643
78644 static struct kmem_cache *cgw_cache __read_mostly;
78645
78646 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78647 return err;
78648 }
78649
78650 +static struct notifier_block notifier = {
78651 + .notifier_call = cgw_notifier
78652 +};
78653 +
78654 static __init int cgw_module_init(void)
78655 {
78656 printk(banner);
78657 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78658 return -ENOMEM;
78659
78660 /* set notifier */
78661 - notifier.notifier_call = cgw_notifier;
78662 register_netdevice_notifier(&notifier);
78663
78664 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78665 diff --git a/net/compat.c b/net/compat.c
78666 index 79ae884..17c5c09 100644
78667 --- a/net/compat.c
78668 +++ b/net/compat.c
78669 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78670 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78671 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78672 return -EFAULT;
78673 - kmsg->msg_name = compat_ptr(tmp1);
78674 - kmsg->msg_iov = compat_ptr(tmp2);
78675 - kmsg->msg_control = compat_ptr(tmp3);
78676 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
78677 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
78678 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
78679 return 0;
78680 }
78681
78682 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78683
78684 if (kern_msg->msg_namelen) {
78685 if (mode == VERIFY_READ) {
78686 - int err = move_addr_to_kernel(kern_msg->msg_name,
78687 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
78688 kern_msg->msg_namelen,
78689 kern_address);
78690 if (err < 0)
78691 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78692 kern_msg->msg_name = NULL;
78693
78694 tot_len = iov_from_user_compat_to_kern(kern_iov,
78695 - (struct compat_iovec __user *)kern_msg->msg_iov,
78696 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
78697 kern_msg->msg_iovlen);
78698 if (tot_len >= 0)
78699 kern_msg->msg_iov = kern_iov;
78700 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78701
78702 #define CMSG_COMPAT_FIRSTHDR(msg) \
78703 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
78704 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
78705 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
78706 (struct compat_cmsghdr __user *)NULL)
78707
78708 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
78709 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
78710 (ucmlen) <= (unsigned long) \
78711 ((mhdr)->msg_controllen - \
78712 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
78713 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
78714
78715 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
78716 struct compat_cmsghdr __user *cmsg, int cmsg_len)
78717 {
78718 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
78719 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
78720 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
78721 msg->msg_controllen)
78722 return NULL;
78723 return (struct compat_cmsghdr __user *)ptr;
78724 @@ -219,7 +219,7 @@ Efault:
78725
78726 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
78727 {
78728 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78729 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78730 struct compat_cmsghdr cmhdr;
78731 struct compat_timeval ctv;
78732 struct compat_timespec cts[3];
78733 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
78734
78735 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
78736 {
78737 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78738 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78739 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
78740 int fdnum = scm->fp->count;
78741 struct file **fp = scm->fp->fp;
78742 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
78743 return -EFAULT;
78744 old_fs = get_fs();
78745 set_fs(KERNEL_DS);
78746 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
78747 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
78748 set_fs(old_fs);
78749
78750 return err;
78751 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
78752 len = sizeof(ktime);
78753 old_fs = get_fs();
78754 set_fs(KERNEL_DS);
78755 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
78756 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
78757 set_fs(old_fs);
78758
78759 if (!err) {
78760 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78761 case MCAST_JOIN_GROUP:
78762 case MCAST_LEAVE_GROUP:
78763 {
78764 - struct compat_group_req __user *gr32 = (void *)optval;
78765 + struct compat_group_req __user *gr32 = (void __user *)optval;
78766 struct group_req __user *kgr =
78767 compat_alloc_user_space(sizeof(struct group_req));
78768 u32 interface;
78769 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78770 case MCAST_BLOCK_SOURCE:
78771 case MCAST_UNBLOCK_SOURCE:
78772 {
78773 - struct compat_group_source_req __user *gsr32 = (void *)optval;
78774 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
78775 struct group_source_req __user *kgsr = compat_alloc_user_space(
78776 sizeof(struct group_source_req));
78777 u32 interface;
78778 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78779 }
78780 case MCAST_MSFILTER:
78781 {
78782 - struct compat_group_filter __user *gf32 = (void *)optval;
78783 + struct compat_group_filter __user *gf32 = (void __user *)optval;
78784 struct group_filter __user *kgf;
78785 u32 interface, fmode, numsrc;
78786
78787 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
78788 char __user *optval, int __user *optlen,
78789 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
78790 {
78791 - struct compat_group_filter __user *gf32 = (void *)optval;
78792 + struct compat_group_filter __user *gf32 = (void __user *)optval;
78793 struct group_filter __user *kgf;
78794 int __user *koptlen;
78795 u32 interface, fmode, numsrc;
78796 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
78797
78798 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
78799 return -EINVAL;
78800 - if (copy_from_user(a, args, nas[call]))
78801 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
78802 return -EFAULT;
78803 a0 = a[0];
78804 a1 = a[1];
78805 diff --git a/net/core/datagram.c b/net/core/datagram.c
78806 index 0337e2b..47914a0 100644
78807 --- a/net/core/datagram.c
78808 +++ b/net/core/datagram.c
78809 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
78810 }
78811
78812 kfree_skb(skb);
78813 - atomic_inc(&sk->sk_drops);
78814 + atomic_inc_unchecked(&sk->sk_drops);
78815 sk_mem_reclaim_partial(sk);
78816
78817 return err;
78818 diff --git a/net/core/dev.c b/net/core/dev.c
78819 index e5942bf..25998c3 100644
78820 --- a/net/core/dev.c
78821 +++ b/net/core/dev.c
78822 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
78823 if (no_module && capable(CAP_NET_ADMIN))
78824 no_module = request_module("netdev-%s", name);
78825 if (no_module && capable(CAP_SYS_MODULE)) {
78826 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
78827 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
78828 +#else
78829 if (!request_module("%s", name))
78830 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
78831 name);
78832 +#endif
78833 }
78834 }
78835 EXPORT_SYMBOL(dev_load);
78836 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78837 {
78838 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
78839 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
78840 - atomic_long_inc(&dev->rx_dropped);
78841 + atomic_long_inc_unchecked(&dev->rx_dropped);
78842 kfree_skb(skb);
78843 return NET_RX_DROP;
78844 }
78845 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78846 nf_reset(skb);
78847
78848 if (unlikely(!is_skb_forwardable(dev, skb))) {
78849 - atomic_long_inc(&dev->rx_dropped);
78850 + atomic_long_inc_unchecked(&dev->rx_dropped);
78851 kfree_skb(skb);
78852 return NET_RX_DROP;
78853 }
78854 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
78855
78856 struct dev_gso_cb {
78857 void (*destructor)(struct sk_buff *skb);
78858 -};
78859 +} __no_const;
78860
78861 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
78862
78863 @@ -2955,7 +2959,7 @@ enqueue:
78864
78865 local_irq_restore(flags);
78866
78867 - atomic_long_inc(&skb->dev->rx_dropped);
78868 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78869 kfree_skb(skb);
78870 return NET_RX_DROP;
78871 }
78872 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
78873 }
78874 EXPORT_SYMBOL(netif_rx_ni);
78875
78876 -static void net_tx_action(struct softirq_action *h)
78877 +static void net_tx_action(void)
78878 {
78879 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78880
78881 @@ -3358,7 +3362,7 @@ ncls:
78882 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
78883 } else {
78884 drop:
78885 - atomic_long_inc(&skb->dev->rx_dropped);
78886 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78887 kfree_skb(skb);
78888 /* Jamal, now you will not able to escape explaining
78889 * me how you were going to use this. :-)
78890 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
78891 }
78892 EXPORT_SYMBOL(netif_napi_del);
78893
78894 -static void net_rx_action(struct softirq_action *h)
78895 +static void net_rx_action(void)
78896 {
78897 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78898 unsigned long time_limit = jiffies + 2;
78899 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
78900 else
78901 seq_printf(seq, "%04x", ntohs(pt->type));
78902
78903 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78904 + seq_printf(seq, " %-8s %p\n",
78905 + pt->dev ? pt->dev->name : "", NULL);
78906 +#else
78907 seq_printf(seq, " %-8s %pF\n",
78908 pt->dev ? pt->dev->name : "", pt->func);
78909 +#endif
78910 }
78911
78912 return 0;
78913 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
78914 } else {
78915 netdev_stats_to_stats64(storage, &dev->stats);
78916 }
78917 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
78918 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
78919 return storage;
78920 }
78921 EXPORT_SYMBOL(dev_get_stats);
78922 diff --git a/net/core/flow.c b/net/core/flow.c
78923 index e318c7e..168b1d0 100644
78924 --- a/net/core/flow.c
78925 +++ b/net/core/flow.c
78926 @@ -61,7 +61,7 @@ struct flow_cache {
78927 struct timer_list rnd_timer;
78928 };
78929
78930 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
78931 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
78932 EXPORT_SYMBOL(flow_cache_genid);
78933 static struct flow_cache flow_cache_global;
78934 static struct kmem_cache *flow_cachep __read_mostly;
78935 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
78936
78937 static int flow_entry_valid(struct flow_cache_entry *fle)
78938 {
78939 - if (atomic_read(&flow_cache_genid) != fle->genid)
78940 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
78941 return 0;
78942 if (fle->object && !fle->object->ops->check(fle->object))
78943 return 0;
78944 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
78945 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
78946 fcp->hash_count++;
78947 }
78948 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
78949 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
78950 flo = fle->object;
78951 if (!flo)
78952 goto ret_object;
78953 @@ -280,7 +280,7 @@ nocache:
78954 }
78955 flo = resolver(net, key, family, dir, flo, ctx);
78956 if (fle) {
78957 - fle->genid = atomic_read(&flow_cache_genid);
78958 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
78959 if (!IS_ERR(flo))
78960 fle->object = flo;
78961 else
78962 diff --git a/net/core/iovec.c b/net/core/iovec.c
78963 index 7e7aeb0..2a998cb 100644
78964 --- a/net/core/iovec.c
78965 +++ b/net/core/iovec.c
78966 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78967 if (m->msg_namelen) {
78968 if (mode == VERIFY_READ) {
78969 void __user *namep;
78970 - namep = (void __user __force *) m->msg_name;
78971 + namep = (void __force_user *) m->msg_name;
78972 err = move_addr_to_kernel(namep, m->msg_namelen,
78973 address);
78974 if (err < 0)
78975 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78976 }
78977
78978 size = m->msg_iovlen * sizeof(struct iovec);
78979 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
78980 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
78981 return -EFAULT;
78982
78983 m->msg_iov = iov;
78984 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
78985 index fad649a..f2fdac4 100644
78986 --- a/net/core/rtnetlink.c
78987 +++ b/net/core/rtnetlink.c
78988 @@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
78989 rtnl_msg_handlers[protocol] = tab;
78990 }
78991
78992 + pax_open_kernel();
78993 if (doit)
78994 - tab[msgindex].doit = doit;
78995 + *(void **)&tab[msgindex].doit = doit;
78996
78997 if (dumpit)
78998 - tab[msgindex].dumpit = dumpit;
78999 + *(void **)&tab[msgindex].dumpit = dumpit;
79000
79001 if (calcit)
79002 - tab[msgindex].calcit = calcit;
79003 + *(void **)&tab[msgindex].calcit = calcit;
79004 + pax_close_kernel();
79005
79006 return 0;
79007 }
79008 @@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
79009 if (rtnl_msg_handlers[protocol] == NULL)
79010 return -ENOENT;
79011
79012 - rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79013 - rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79014 + pax_open_kernel();
79015 + *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79016 + *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79017 + pax_close_kernel();
79018
79019 return 0;
79020 }
79021 diff --git a/net/core/scm.c b/net/core/scm.c
79022 index ab57084..0190c8f 100644
79023 --- a/net/core/scm.c
79024 +++ b/net/core/scm.c
79025 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79026 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79027 {
79028 struct cmsghdr __user *cm
79029 - = (__force struct cmsghdr __user *)msg->msg_control;
79030 + = (struct cmsghdr __force_user *)msg->msg_control;
79031 struct cmsghdr cmhdr;
79032 int cmlen = CMSG_LEN(len);
79033 int err;
79034 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79035 err = -EFAULT;
79036 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79037 goto out;
79038 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79039 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79040 goto out;
79041 cmlen = CMSG_SPACE(len);
79042 if (msg->msg_controllen < cmlen)
79043 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79044 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79045 {
79046 struct cmsghdr __user *cm
79047 - = (__force struct cmsghdr __user*)msg->msg_control;
79048 + = (struct cmsghdr __force_user *)msg->msg_control;
79049
79050 int fdmax = 0;
79051 int fdnum = scm->fp->count;
79052 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79053 if (fdnum < fdmax)
79054 fdmax = fdnum;
79055
79056 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79057 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79058 i++, cmfptr++)
79059 {
79060 struct socket *sock;
79061 diff --git a/net/core/sock.c b/net/core/sock.c
79062 index 8a146cf..ee08914d 100644
79063 --- a/net/core/sock.c
79064 +++ b/net/core/sock.c
79065 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79066 struct sk_buff_head *list = &sk->sk_receive_queue;
79067
79068 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79069 - atomic_inc(&sk->sk_drops);
79070 + atomic_inc_unchecked(&sk->sk_drops);
79071 trace_sock_rcvqueue_full(sk, skb);
79072 return -ENOMEM;
79073 }
79074 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79075 return err;
79076
79077 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79078 - atomic_inc(&sk->sk_drops);
79079 + atomic_inc_unchecked(&sk->sk_drops);
79080 return -ENOBUFS;
79081 }
79082
79083 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79084 skb_dst_force(skb);
79085
79086 spin_lock_irqsave(&list->lock, flags);
79087 - skb->dropcount = atomic_read(&sk->sk_drops);
79088 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79089 __skb_queue_tail(list, skb);
79090 spin_unlock_irqrestore(&list->lock, flags);
79091
79092 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79093 skb->dev = NULL;
79094
79095 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79096 - atomic_inc(&sk->sk_drops);
79097 + atomic_inc_unchecked(&sk->sk_drops);
79098 goto discard_and_relse;
79099 }
79100 if (nested)
79101 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79102 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79103 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79104 bh_unlock_sock(sk);
79105 - atomic_inc(&sk->sk_drops);
79106 + atomic_inc_unchecked(&sk->sk_drops);
79107 goto discard_and_relse;
79108 }
79109
79110 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79111 struct timeval tm;
79112 } v;
79113
79114 - int lv = sizeof(int);
79115 - int len;
79116 + unsigned int lv = sizeof(int);
79117 + unsigned int len;
79118
79119 if (get_user(len, optlen))
79120 return -EFAULT;
79121 - if (len < 0)
79122 + if (len > INT_MAX)
79123 return -EINVAL;
79124
79125 memset(&v, 0, sizeof(v));
79126 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79127
79128 case SO_PEERNAME:
79129 {
79130 - char address[128];
79131 + char address[_K_SS_MAXSIZE];
79132
79133 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79134 return -ENOTCONN;
79135 - if (lv < len)
79136 + if (lv < len || sizeof address < len)
79137 return -EINVAL;
79138 if (copy_to_user(optval, address, len))
79139 return -EFAULT;
79140 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79141
79142 if (len > lv)
79143 len = lv;
79144 - if (copy_to_user(optval, &v, len))
79145 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
79146 return -EFAULT;
79147 lenout:
79148 if (put_user(len, optlen))
79149 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79150 */
79151 smp_wmb();
79152 atomic_set(&sk->sk_refcnt, 1);
79153 - atomic_set(&sk->sk_drops, 0);
79154 + atomic_set_unchecked(&sk->sk_drops, 0);
79155 }
79156 EXPORT_SYMBOL(sock_init_data);
79157
79158 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79159 index 602cd63..05c6c60 100644
79160 --- a/net/core/sock_diag.c
79161 +++ b/net/core/sock_diag.c
79162 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79163
79164 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79165 {
79166 +#ifndef CONFIG_GRKERNSEC_HIDESYM
79167 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79168 cookie[1] != INET_DIAG_NOCOOKIE) &&
79169 ((u32)(unsigned long)sk != cookie[0] ||
79170 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79171 return -ESTALE;
79172 else
79173 +#endif
79174 return 0;
79175 }
79176 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79177
79178 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79179 {
79180 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79181 + cookie[0] = 0;
79182 + cookie[1] = 0;
79183 +#else
79184 cookie[0] = (u32)(unsigned long)sk;
79185 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79186 +#endif
79187 }
79188 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79189
79190 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79191 index a55eecc..dd8428c 100644
79192 --- a/net/decnet/sysctl_net_decnet.c
79193 +++ b/net/decnet/sysctl_net_decnet.c
79194 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79195
79196 if (len > *lenp) len = *lenp;
79197
79198 - if (copy_to_user(buffer, addr, len))
79199 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
79200 return -EFAULT;
79201
79202 *lenp = len;
79203 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79204
79205 if (len > *lenp) len = *lenp;
79206
79207 - if (copy_to_user(buffer, devname, len))
79208 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
79209 return -EFAULT;
79210
79211 *lenp = len;
79212 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79213 index 2a6abc1..c379ba7 100644
79214 --- a/net/ipv4/devinet.c
79215 +++ b/net/ipv4/devinet.c
79216 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79217 if (!ifa) {
79218 ret = -ENOBUFS;
79219 ifa = inet_alloc_ifa();
79220 + if (!ifa)
79221 + break;
79222 INIT_HLIST_NODE(&ifa->hash);
79223 - if (!ifa)
79224 - break;
79225 if (colon)
79226 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79227 else
79228 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79229 index 825c608..750ff29 100644
79230 --- a/net/ipv4/fib_frontend.c
79231 +++ b/net/ipv4/fib_frontend.c
79232 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79233 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79234 fib_sync_up(dev);
79235 #endif
79236 - atomic_inc(&net->ipv4.dev_addr_genid);
79237 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79238 rt_cache_flush(dev_net(dev));
79239 break;
79240 case NETDEV_DOWN:
79241 fib_del_ifaddr(ifa, NULL);
79242 - atomic_inc(&net->ipv4.dev_addr_genid);
79243 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79244 if (ifa->ifa_dev->ifa_list == NULL) {
79245 /* Last address was deleted from this interface.
79246 * Disable IP.
79247 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79248 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79249 fib_sync_up(dev);
79250 #endif
79251 - atomic_inc(&net->ipv4.dev_addr_genid);
79252 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79253 rt_cache_flush(net);
79254 break;
79255 case NETDEV_DOWN:
79256 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79257 index 71b125c..f4c70b0 100644
79258 --- a/net/ipv4/fib_semantics.c
79259 +++ b/net/ipv4/fib_semantics.c
79260 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79261 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79262 nh->nh_gw,
79263 nh->nh_parent->fib_scope);
79264 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79265 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79266
79267 return nh->nh_saddr;
79268 }
79269 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79270 index 7880af9..70f92a3 100644
79271 --- a/net/ipv4/inet_hashtables.c
79272 +++ b/net/ipv4/inet_hashtables.c
79273 @@ -18,12 +18,15 @@
79274 #include <linux/sched.h>
79275 #include <linux/slab.h>
79276 #include <linux/wait.h>
79277 +#include <linux/security.h>
79278
79279 #include <net/inet_connection_sock.h>
79280 #include <net/inet_hashtables.h>
79281 #include <net/secure_seq.h>
79282 #include <net/ip.h>
79283
79284 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79285 +
79286 /*
79287 * Allocate and initialize a new local port bind bucket.
79288 * The bindhash mutex for snum's hash chain must be held here.
79289 @@ -530,6 +533,8 @@ ok:
79290 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79291 spin_unlock(&head->lock);
79292
79293 + gr_update_task_in_ip_table(current, inet_sk(sk));
79294 +
79295 if (tw) {
79296 inet_twsk_deschedule(tw, death_row);
79297 while (twrefcnt) {
79298 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79299 index 000e3d2..5472da3 100644
79300 --- a/net/ipv4/inetpeer.c
79301 +++ b/net/ipv4/inetpeer.c
79302 @@ -503,8 +503,8 @@ relookup:
79303 if (p) {
79304 p->daddr = *daddr;
79305 atomic_set(&p->refcnt, 1);
79306 - atomic_set(&p->rid, 0);
79307 - atomic_set(&p->ip_id_count,
79308 + atomic_set_unchecked(&p->rid, 0);
79309 + atomic_set_unchecked(&p->ip_id_count,
79310 (daddr->family == AF_INET) ?
79311 secure_ip_id(daddr->addr.a4) :
79312 secure_ipv6_id(daddr->addr.a6));
79313 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79314 index 8d5cc75..821fd11 100644
79315 --- a/net/ipv4/ip_fragment.c
79316 +++ b/net/ipv4/ip_fragment.c
79317 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79318 return 0;
79319
79320 start = qp->rid;
79321 - end = atomic_inc_return(&peer->rid);
79322 + end = atomic_inc_return_unchecked(&peer->rid);
79323 qp->rid = end;
79324
79325 rc = qp->q.fragments && (end - start) > max;
79326 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79327 index 14bbfcf..644f472 100644
79328 --- a/net/ipv4/ip_sockglue.c
79329 +++ b/net/ipv4/ip_sockglue.c
79330 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79331 len = min_t(unsigned int, len, opt->optlen);
79332 if (put_user(len, optlen))
79333 return -EFAULT;
79334 - if (copy_to_user(optval, opt->__data, len))
79335 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79336 + copy_to_user(optval, opt->__data, len))
79337 return -EFAULT;
79338 return 0;
79339 }
79340 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79341 if (sk->sk_type != SOCK_STREAM)
79342 return -ENOPROTOOPT;
79343
79344 - msg.msg_control = optval;
79345 + msg.msg_control = (void __force_kernel *)optval;
79346 msg.msg_controllen = len;
79347 msg.msg_flags = flags;
79348
79349 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79350 index 798358b..73570b7 100644
79351 --- a/net/ipv4/ipconfig.c
79352 +++ b/net/ipv4/ipconfig.c
79353 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79354
79355 mm_segment_t oldfs = get_fs();
79356 set_fs(get_ds());
79357 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79358 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79359 set_fs(oldfs);
79360 return res;
79361 }
79362 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79363
79364 mm_segment_t oldfs = get_fs();
79365 set_fs(get_ds());
79366 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79367 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79368 set_fs(oldfs);
79369 return res;
79370 }
79371 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79372
79373 mm_segment_t oldfs = get_fs();
79374 set_fs(get_ds());
79375 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79376 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79377 set_fs(oldfs);
79378 return res;
79379 }
79380 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79381 index 97e61ea..cac1bbb 100644
79382 --- a/net/ipv4/netfilter/arp_tables.c
79383 +++ b/net/ipv4/netfilter/arp_tables.c
79384 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79385 #endif
79386
79387 static int get_info(struct net *net, void __user *user,
79388 - const int *len, int compat)
79389 + int len, int compat)
79390 {
79391 char name[XT_TABLE_MAXNAMELEN];
79392 struct xt_table *t;
79393 int ret;
79394
79395 - if (*len != sizeof(struct arpt_getinfo)) {
79396 - duprintf("length %u != %Zu\n", *len,
79397 + if (len != sizeof(struct arpt_getinfo)) {
79398 + duprintf("length %u != %Zu\n", len,
79399 sizeof(struct arpt_getinfo));
79400 return -EINVAL;
79401 }
79402 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79403 info.size = private->size;
79404 strcpy(info.name, name);
79405
79406 - if (copy_to_user(user, &info, *len) != 0)
79407 + if (copy_to_user(user, &info, len) != 0)
79408 ret = -EFAULT;
79409 else
79410 ret = 0;
79411 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79412
79413 switch (cmd) {
79414 case ARPT_SO_GET_INFO:
79415 - ret = get_info(sock_net(sk), user, len, 1);
79416 + ret = get_info(sock_net(sk), user, *len, 1);
79417 break;
79418 case ARPT_SO_GET_ENTRIES:
79419 ret = compat_get_entries(sock_net(sk), user, len);
79420 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79421
79422 switch (cmd) {
79423 case ARPT_SO_GET_INFO:
79424 - ret = get_info(sock_net(sk), user, len, 0);
79425 + ret = get_info(sock_net(sk), user, *len, 0);
79426 break;
79427
79428 case ARPT_SO_GET_ENTRIES:
79429 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79430 index 170b1fd..6105b91 100644
79431 --- a/net/ipv4/netfilter/ip_tables.c
79432 +++ b/net/ipv4/netfilter/ip_tables.c
79433 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79434 #endif
79435
79436 static int get_info(struct net *net, void __user *user,
79437 - const int *len, int compat)
79438 + int len, int compat)
79439 {
79440 char name[XT_TABLE_MAXNAMELEN];
79441 struct xt_table *t;
79442 int ret;
79443
79444 - if (*len != sizeof(struct ipt_getinfo)) {
79445 - duprintf("length %u != %zu\n", *len,
79446 + if (len != sizeof(struct ipt_getinfo)) {
79447 + duprintf("length %u != %zu\n", len,
79448 sizeof(struct ipt_getinfo));
79449 return -EINVAL;
79450 }
79451 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79452 info.size = private->size;
79453 strcpy(info.name, name);
79454
79455 - if (copy_to_user(user, &info, *len) != 0)
79456 + if (copy_to_user(user, &info, len) != 0)
79457 ret = -EFAULT;
79458 else
79459 ret = 0;
79460 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79461
79462 switch (cmd) {
79463 case IPT_SO_GET_INFO:
79464 - ret = get_info(sock_net(sk), user, len, 1);
79465 + ret = get_info(sock_net(sk), user, *len, 1);
79466 break;
79467 case IPT_SO_GET_ENTRIES:
79468 ret = compat_get_entries(sock_net(sk), user, len);
79469 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79470
79471 switch (cmd) {
79472 case IPT_SO_GET_INFO:
79473 - ret = get_info(sock_net(sk), user, len, 0);
79474 + ret = get_info(sock_net(sk), user, *len, 0);
79475 break;
79476
79477 case IPT_SO_GET_ENTRIES:
79478 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79479 index 8f3d054..c58d05d 100644
79480 --- a/net/ipv4/ping.c
79481 +++ b/net/ipv4/ping.c
79482 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79483 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79484 0, sock_i_ino(sp),
79485 atomic_read(&sp->sk_refcnt), sp,
79486 - atomic_read(&sp->sk_drops), len);
79487 + atomic_read_unchecked(&sp->sk_drops), len);
79488 }
79489
79490 static int ping_seq_show(struct seq_file *seq, void *v)
79491 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79492 index 73d1e4d..3af0e8f 100644
79493 --- a/net/ipv4/raw.c
79494 +++ b/net/ipv4/raw.c
79495 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79496 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79497 {
79498 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79499 - atomic_inc(&sk->sk_drops);
79500 + atomic_inc_unchecked(&sk->sk_drops);
79501 kfree_skb(skb);
79502 return NET_RX_DROP;
79503 }
79504 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79505
79506 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79507 {
79508 + struct icmp_filter filter;
79509 +
79510 if (optlen > sizeof(struct icmp_filter))
79511 optlen = sizeof(struct icmp_filter);
79512 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79513 + if (copy_from_user(&filter, optval, optlen))
79514 return -EFAULT;
79515 + raw_sk(sk)->filter = filter;
79516 return 0;
79517 }
79518
79519 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79520 {
79521 int len, ret = -EFAULT;
79522 + struct icmp_filter filter;
79523
79524 if (get_user(len, optlen))
79525 goto out;
79526 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79527 if (len > sizeof(struct icmp_filter))
79528 len = sizeof(struct icmp_filter);
79529 ret = -EFAULT;
79530 - if (put_user(len, optlen) ||
79531 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79532 + filter = raw_sk(sk)->filter;
79533 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79534 goto out;
79535 ret = 0;
79536 out: return ret;
79537 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79538 0, 0L, 0,
79539 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79540 0, sock_i_ino(sp),
79541 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79542 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79543 }
79544
79545 static int raw_seq_show(struct seq_file *seq, void *v)
79546 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79547 index df25142..e92a82a 100644
79548 --- a/net/ipv4/route.c
79549 +++ b/net/ipv4/route.c
79550 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79551
79552 static __net_init int rt_genid_init(struct net *net)
79553 {
79554 - atomic_set(&net->rt_genid, 0);
79555 + atomic_set_unchecked(&net->rt_genid, 0);
79556 get_random_bytes(&net->ipv4.dev_addr_genid,
79557 sizeof(net->ipv4.dev_addr_genid));
79558 return 0;
79559 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79560 index 181fc82..cc95f8c 100644
79561 --- a/net/ipv4/tcp_input.c
79562 +++ b/net/ipv4/tcp_input.c
79563 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79564 * simplifies code)
79565 */
79566 static void
79567 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79568 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79569 struct sk_buff *head, struct sk_buff *tail,
79570 u32 start, u32 end)
79571 {
79572 @@ -5536,6 +5536,9 @@ slow_path:
79573 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79574 goto csum_error;
79575
79576 + if (!th->ack)
79577 + goto discard;
79578 +
79579 /*
79580 * Standard slow path.
79581 */
79582 @@ -5544,7 +5547,7 @@ slow_path:
79583 return 0;
79584
79585 step5:
79586 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79587 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79588 goto discard;
79589
79590 /* ts_recent update must be made after we are sure that the packet
79591 @@ -5836,6 +5839,7 @@ discard:
79592 tcp_paws_reject(&tp->rx_opt, 0))
79593 goto discard_and_undo;
79594
79595 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79596 if (th->syn) {
79597 /* We see SYN without ACK. It is attempt of
79598 * simultaneous connect with crossed SYNs.
79599 @@ -5886,6 +5890,7 @@ discard:
79600 goto discard;
79601 #endif
79602 }
79603 +#endif
79604 /* "fifth, if neither of the SYN or RST bits is set then
79605 * drop the segment and return."
79606 */
79607 @@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79608 goto discard;
79609
79610 if (th->syn) {
79611 - if (th->fin)
79612 + if (th->fin || th->urg || th->psh)
79613 goto discard;
79614 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79615 return 1;
79616 @@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79617 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79618 goto discard;
79619 }
79620 +
79621 + if (!th->ack)
79622 + goto discard;
79623 +
79624 if (!tcp_validate_incoming(sk, skb, th, 0))
79625 return 0;
79626
79627 /* step 5: check the ACK field */
79628 - if (th->ack) {
79629 + if (true) {
79630 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79631
79632 switch (sk->sk_state) {
79633 @@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79634 }
79635 break;
79636 }
79637 - } else
79638 - goto discard;
79639 + }
79640
79641 /* ts_recent update must be made after we are sure that the packet
79642 * is in window.
79643 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79644 index bc3cb46..815ccd6 100644
79645 --- a/net/ipv4/tcp_ipv4.c
79646 +++ b/net/ipv4/tcp_ipv4.c
79647 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79648 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79649
79650
79651 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79652 +extern int grsec_enable_blackhole;
79653 +#endif
79654 +
79655 #ifdef CONFIG_TCP_MD5SIG
79656 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79657 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79658 @@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79659 return 0;
79660
79661 reset:
79662 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79663 + if (!grsec_enable_blackhole)
79664 +#endif
79665 tcp_v4_send_reset(rsk, skb);
79666 discard:
79667 kfree_skb(skb);
79668 @@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79669 TCP_SKB_CB(skb)->sacked = 0;
79670
79671 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79672 - if (!sk)
79673 + if (!sk) {
79674 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79675 + ret = 1;
79676 +#endif
79677 goto no_tcp_socket;
79678 -
79679 + }
79680 process:
79681 - if (sk->sk_state == TCP_TIME_WAIT)
79682 + if (sk->sk_state == TCP_TIME_WAIT) {
79683 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79684 + ret = 2;
79685 +#endif
79686 goto do_time_wait;
79687 + }
79688
79689 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
79690 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79691 @@ -2055,6 +2069,10 @@ no_tcp_socket:
79692 bad_packet:
79693 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79694 } else {
79695 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79696 + if (!grsec_enable_blackhole || (ret == 1 &&
79697 + (skb->dev->flags & IFF_LOOPBACK)))
79698 +#endif
79699 tcp_v4_send_reset(NULL, skb);
79700 }
79701
79702 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
79703 index a7302d9..e3ec754 100644
79704 --- a/net/ipv4/tcp_minisocks.c
79705 +++ b/net/ipv4/tcp_minisocks.c
79706 @@ -27,6 +27,10 @@
79707 #include <net/inet_common.h>
79708 #include <net/xfrm.h>
79709
79710 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79711 +extern int grsec_enable_blackhole;
79712 +#endif
79713 +
79714 int sysctl_tcp_syncookies __read_mostly = 1;
79715 EXPORT_SYMBOL(sysctl_tcp_syncookies);
79716
79717 @@ -742,7 +746,10 @@ embryonic_reset:
79718 * avoid becoming vulnerable to outside attack aiming at
79719 * resetting legit local connections.
79720 */
79721 - req->rsk_ops->send_reset(sk, skb);
79722 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79723 + if (!grsec_enable_blackhole)
79724 +#endif
79725 + req->rsk_ops->send_reset(sk, skb);
79726 } else if (fastopen) { /* received a valid RST pkt */
79727 reqsk_fastopen_remove(sk, req, true);
79728 tcp_reset(sk);
79729 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
79730 index 4526fe6..1a34e43 100644
79731 --- a/net/ipv4/tcp_probe.c
79732 +++ b/net/ipv4/tcp_probe.c
79733 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
79734 if (cnt + width >= len)
79735 break;
79736
79737 - if (copy_to_user(buf + cnt, tbuf, width))
79738 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
79739 return -EFAULT;
79740 cnt += width;
79741 }
79742 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
79743 index d47c1b4..b0584de 100644
79744 --- a/net/ipv4/tcp_timer.c
79745 +++ b/net/ipv4/tcp_timer.c
79746 @@ -22,6 +22,10 @@
79747 #include <linux/gfp.h>
79748 #include <net/tcp.h>
79749
79750 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79751 +extern int grsec_lastack_retries;
79752 +#endif
79753 +
79754 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
79755 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
79756 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
79757 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
79758 }
79759 }
79760
79761 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79762 + if ((sk->sk_state == TCP_LAST_ACK) &&
79763 + (grsec_lastack_retries > 0) &&
79764 + (grsec_lastack_retries < retry_until))
79765 + retry_until = grsec_lastack_retries;
79766 +#endif
79767 +
79768 if (retransmits_timed_out(sk, retry_until,
79769 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
79770 /* Has it gone just too far? */
79771 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
79772 index 79c8dbe..aceb1b6 100644
79773 --- a/net/ipv4/udp.c
79774 +++ b/net/ipv4/udp.c
79775 @@ -87,6 +87,7 @@
79776 #include <linux/types.h>
79777 #include <linux/fcntl.h>
79778 #include <linux/module.h>
79779 +#include <linux/security.h>
79780 #include <linux/socket.h>
79781 #include <linux/sockios.h>
79782 #include <linux/igmp.h>
79783 @@ -111,6 +112,10 @@
79784 #include <trace/events/skb.h>
79785 #include "udp_impl.h"
79786
79787 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79788 +extern int grsec_enable_blackhole;
79789 +#endif
79790 +
79791 struct udp_table udp_table __read_mostly;
79792 EXPORT_SYMBOL(udp_table);
79793
79794 @@ -569,6 +574,9 @@ found:
79795 return s;
79796 }
79797
79798 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
79799 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
79800 +
79801 /*
79802 * This routine is called by the ICMP module when it gets some
79803 * sort of error condition. If err < 0 then the socket should
79804 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
79805 dport = usin->sin_port;
79806 if (dport == 0)
79807 return -EINVAL;
79808 +
79809 + err = gr_search_udp_sendmsg(sk, usin);
79810 + if (err)
79811 + return err;
79812 } else {
79813 if (sk->sk_state != TCP_ESTABLISHED)
79814 return -EDESTADDRREQ;
79815 +
79816 + err = gr_search_udp_sendmsg(sk, NULL);
79817 + if (err)
79818 + return err;
79819 +
79820 daddr = inet->inet_daddr;
79821 dport = inet->inet_dport;
79822 /* Open fast path for connected socket.
79823 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
79824 udp_lib_checksum_complete(skb)) {
79825 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79826 IS_UDPLITE(sk));
79827 - atomic_inc(&sk->sk_drops);
79828 + atomic_inc_unchecked(&sk->sk_drops);
79829 __skb_unlink(skb, rcvq);
79830 __skb_queue_tail(&list_kill, skb);
79831 }
79832 @@ -1194,6 +1211,10 @@ try_again:
79833 if (!skb)
79834 goto out;
79835
79836 + err = gr_search_udp_recvmsg(sk, skb);
79837 + if (err)
79838 + goto out_free;
79839 +
79840 ulen = skb->len - sizeof(struct udphdr);
79841 copied = len;
79842 if (copied > ulen)
79843 @@ -1227,7 +1248,7 @@ try_again:
79844 if (unlikely(err)) {
79845 trace_kfree_skb(skb, udp_recvmsg);
79846 if (!peeked) {
79847 - atomic_inc(&sk->sk_drops);
79848 + atomic_inc_unchecked(&sk->sk_drops);
79849 UDP_INC_STATS_USER(sock_net(sk),
79850 UDP_MIB_INERRORS, is_udplite);
79851 }
79852 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79853
79854 drop:
79855 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
79856 - atomic_inc(&sk->sk_drops);
79857 + atomic_inc_unchecked(&sk->sk_drops);
79858 kfree_skb(skb);
79859 return -1;
79860 }
79861 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
79862 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
79863
79864 if (!skb1) {
79865 - atomic_inc(&sk->sk_drops);
79866 + atomic_inc_unchecked(&sk->sk_drops);
79867 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
79868 IS_UDPLITE(sk));
79869 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79870 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
79871 goto csum_error;
79872
79873 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
79874 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79875 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
79876 +#endif
79877 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
79878
79879 /*
79880 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
79881 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79882 0, sock_i_ino(sp),
79883 atomic_read(&sp->sk_refcnt), sp,
79884 - atomic_read(&sp->sk_drops), len);
79885 + atomic_read_unchecked(&sp->sk_drops), len);
79886 }
79887
79888 int udp4_seq_show(struct seq_file *seq, void *v)
79889 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
79890 index 0424e4e..308dd43 100644
79891 --- a/net/ipv6/addrconf.c
79892 +++ b/net/ipv6/addrconf.c
79893 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
79894 p.iph.ihl = 5;
79895 p.iph.protocol = IPPROTO_IPV6;
79896 p.iph.ttl = 64;
79897 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
79898 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
79899
79900 if (ops->ndo_do_ioctl) {
79901 mm_segment_t oldfs = get_fs();
79902 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
79903 index d5cb3c4..b3e38d0 100644
79904 --- a/net/ipv6/ip6_gre.c
79905 +++ b/net/ipv6/ip6_gre.c
79906 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
79907 }
79908
79909
79910 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
79911 +static struct inet6_protocol ip6gre_protocol = {
79912 .handler = ip6gre_rcv,
79913 .err_handler = ip6gre_err,
79914 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
79915 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
79916 index e02faed..9780f28 100644
79917 --- a/net/ipv6/ipv6_sockglue.c
79918 +++ b/net/ipv6/ipv6_sockglue.c
79919 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
79920 if (sk->sk_type != SOCK_STREAM)
79921 return -ENOPROTOOPT;
79922
79923 - msg.msg_control = optval;
79924 + msg.msg_control = (void __force_kernel *)optval;
79925 msg.msg_controllen = len;
79926 msg.msg_flags = flags;
79927
79928 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
79929 index d7cb045..8c0ded6 100644
79930 --- a/net/ipv6/netfilter/ip6_tables.c
79931 +++ b/net/ipv6/netfilter/ip6_tables.c
79932 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
79933 #endif
79934
79935 static int get_info(struct net *net, void __user *user,
79936 - const int *len, int compat)
79937 + int len, int compat)
79938 {
79939 char name[XT_TABLE_MAXNAMELEN];
79940 struct xt_table *t;
79941 int ret;
79942
79943 - if (*len != sizeof(struct ip6t_getinfo)) {
79944 - duprintf("length %u != %zu\n", *len,
79945 + if (len != sizeof(struct ip6t_getinfo)) {
79946 + duprintf("length %u != %zu\n", len,
79947 sizeof(struct ip6t_getinfo));
79948 return -EINVAL;
79949 }
79950 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
79951 info.size = private->size;
79952 strcpy(info.name, name);
79953
79954 - if (copy_to_user(user, &info, *len) != 0)
79955 + if (copy_to_user(user, &info, len) != 0)
79956 ret = -EFAULT;
79957 else
79958 ret = 0;
79959 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79960
79961 switch (cmd) {
79962 case IP6T_SO_GET_INFO:
79963 - ret = get_info(sock_net(sk), user, len, 1);
79964 + ret = get_info(sock_net(sk), user, *len, 1);
79965 break;
79966 case IP6T_SO_GET_ENTRIES:
79967 ret = compat_get_entries(sock_net(sk), user, len);
79968 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79969
79970 switch (cmd) {
79971 case IP6T_SO_GET_INFO:
79972 - ret = get_info(sock_net(sk), user, len, 0);
79973 + ret = get_info(sock_net(sk), user, *len, 0);
79974 break;
79975
79976 case IP6T_SO_GET_ENTRIES:
79977 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
79978 index d8e95c7..81422bc 100644
79979 --- a/net/ipv6/raw.c
79980 +++ b/net/ipv6/raw.c
79981 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
79982 {
79983 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
79984 skb_checksum_complete(skb)) {
79985 - atomic_inc(&sk->sk_drops);
79986 + atomic_inc_unchecked(&sk->sk_drops);
79987 kfree_skb(skb);
79988 return NET_RX_DROP;
79989 }
79990 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79991 struct raw6_sock *rp = raw6_sk(sk);
79992
79993 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
79994 - atomic_inc(&sk->sk_drops);
79995 + atomic_inc_unchecked(&sk->sk_drops);
79996 kfree_skb(skb);
79997 return NET_RX_DROP;
79998 }
79999 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80000
80001 if (inet->hdrincl) {
80002 if (skb_checksum_complete(skb)) {
80003 - atomic_inc(&sk->sk_drops);
80004 + atomic_inc_unchecked(&sk->sk_drops);
80005 kfree_skb(skb);
80006 return NET_RX_DROP;
80007 }
80008 @@ -604,7 +604,7 @@ out:
80009 return err;
80010 }
80011
80012 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80013 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80014 struct flowi6 *fl6, struct dst_entry **dstp,
80015 unsigned int flags)
80016 {
80017 @@ -916,12 +916,15 @@ do_confirm:
80018 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80019 char __user *optval, int optlen)
80020 {
80021 + struct icmp6_filter filter;
80022 +
80023 switch (optname) {
80024 case ICMPV6_FILTER:
80025 if (optlen > sizeof(struct icmp6_filter))
80026 optlen = sizeof(struct icmp6_filter);
80027 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80028 + if (copy_from_user(&filter, optval, optlen))
80029 return -EFAULT;
80030 + raw6_sk(sk)->filter = filter;
80031 return 0;
80032 default:
80033 return -ENOPROTOOPT;
80034 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80035 char __user *optval, int __user *optlen)
80036 {
80037 int len;
80038 + struct icmp6_filter filter;
80039
80040 switch (optname) {
80041 case ICMPV6_FILTER:
80042 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80043 len = sizeof(struct icmp6_filter);
80044 if (put_user(len, optlen))
80045 return -EFAULT;
80046 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80047 + filter = raw6_sk(sk)->filter;
80048 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80049 return -EFAULT;
80050 return 0;
80051 default:
80052 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80053 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80054 0,
80055 sock_i_ino(sp),
80056 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80057 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80058 }
80059
80060 static int raw6_seq_show(struct seq_file *seq, void *v)
80061 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80062 index 73f2a6b..f8049a1 100644
80063 --- a/net/ipv6/tcp_ipv6.c
80064 +++ b/net/ipv6/tcp_ipv6.c
80065 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80066 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80067 }
80068
80069 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80070 +extern int grsec_enable_blackhole;
80071 +#endif
80072 +
80073 static void tcp_v6_hash(struct sock *sk)
80074 {
80075 if (sk->sk_state != TCP_CLOSE) {
80076 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80077 return 0;
80078
80079 reset:
80080 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80081 + if (!grsec_enable_blackhole)
80082 +#endif
80083 tcp_v6_send_reset(sk, skb);
80084 discard:
80085 if (opt_skb)
80086 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80087 TCP_SKB_CB(skb)->sacked = 0;
80088
80089 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80090 - if (!sk)
80091 + if (!sk) {
80092 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80093 + ret = 1;
80094 +#endif
80095 goto no_tcp_socket;
80096 + }
80097
80098 process:
80099 - if (sk->sk_state == TCP_TIME_WAIT)
80100 + if (sk->sk_state == TCP_TIME_WAIT) {
80101 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80102 + ret = 2;
80103 +#endif
80104 goto do_time_wait;
80105 + }
80106
80107 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80108 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80109 @@ -1660,6 +1675,10 @@ no_tcp_socket:
80110 bad_packet:
80111 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80112 } else {
80113 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80114 + if (!grsec_enable_blackhole || (ret == 1 &&
80115 + (skb->dev->flags & IFF_LOOPBACK)))
80116 +#endif
80117 tcp_v6_send_reset(NULL, skb);
80118 }
80119
80120 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80121 index fc99972..69397e8 100644
80122 --- a/net/ipv6/udp.c
80123 +++ b/net/ipv6/udp.c
80124 @@ -51,6 +51,10 @@
80125 #include <trace/events/skb.h>
80126 #include "udp_impl.h"
80127
80128 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80129 +extern int grsec_enable_blackhole;
80130 +#endif
80131 +
80132 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80133 {
80134 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80135 @@ -395,7 +399,7 @@ try_again:
80136 if (unlikely(err)) {
80137 trace_kfree_skb(skb, udpv6_recvmsg);
80138 if (!peeked) {
80139 - atomic_inc(&sk->sk_drops);
80140 + atomic_inc_unchecked(&sk->sk_drops);
80141 if (is_udp4)
80142 UDP_INC_STATS_USER(sock_net(sk),
80143 UDP_MIB_INERRORS,
80144 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80145 return rc;
80146 drop:
80147 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80148 - atomic_inc(&sk->sk_drops);
80149 + atomic_inc_unchecked(&sk->sk_drops);
80150 kfree_skb(skb);
80151 return -1;
80152 }
80153 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80154 if (likely(skb1 == NULL))
80155 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80156 if (!skb1) {
80157 - atomic_inc(&sk->sk_drops);
80158 + atomic_inc_unchecked(&sk->sk_drops);
80159 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80160 IS_UDPLITE(sk));
80161 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80162 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80163 goto discard;
80164
80165 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80166 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80167 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80168 +#endif
80169 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80170
80171 kfree_skb(skb);
80172 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80173 0,
80174 sock_i_ino(sp),
80175 atomic_read(&sp->sk_refcnt), sp,
80176 - atomic_read(&sp->sk_drops));
80177 + atomic_read_unchecked(&sp->sk_drops));
80178 }
80179
80180 int udp6_seq_show(struct seq_file *seq, void *v)
80181 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80182 index 496ce2c..f79fac8 100644
80183 --- a/net/irda/ircomm/ircomm_tty.c
80184 +++ b/net/irda/ircomm/ircomm_tty.c
80185 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80186 add_wait_queue(&port->open_wait, &wait);
80187
80188 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80189 - __FILE__, __LINE__, tty->driver->name, port->count);
80190 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80191
80192 spin_lock_irqsave(&port->lock, flags);
80193 if (!tty_hung_up_p(filp)) {
80194 extra_count = 1;
80195 - port->count--;
80196 + atomic_dec(&port->count);
80197 }
80198 spin_unlock_irqrestore(&port->lock, flags);
80199 port->blocked_open++;
80200 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80201 }
80202
80203 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80204 - __FILE__, __LINE__, tty->driver->name, port->count);
80205 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80206
80207 schedule();
80208 }
80209 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80210 if (extra_count) {
80211 /* ++ is not atomic, so this should be protected - Jean II */
80212 spin_lock_irqsave(&port->lock, flags);
80213 - port->count++;
80214 + atomic_inc(&port->count);
80215 spin_unlock_irqrestore(&port->lock, flags);
80216 }
80217 port->blocked_open--;
80218
80219 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80220 - __FILE__, __LINE__, tty->driver->name, port->count);
80221 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80222
80223 if (!retval)
80224 port->flags |= ASYNC_NORMAL_ACTIVE;
80225 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80226
80227 /* ++ is not atomic, so this should be protected - Jean II */
80228 spin_lock_irqsave(&self->port.lock, flags);
80229 - self->port.count++;
80230 + atomic_inc(&self->port.count);
80231 spin_unlock_irqrestore(&self->port.lock, flags);
80232 tty_port_tty_set(&self->port, tty);
80233
80234 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80235 - self->line, self->port.count);
80236 + self->line, atomic_read(&self->port.count));
80237
80238 /* Not really used by us, but lets do it anyway */
80239 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80240 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80241 tty_kref_put(port->tty);
80242 }
80243 port->tty = NULL;
80244 - port->count = 0;
80245 + atomic_set(&port->count, 0);
80246 spin_unlock_irqrestore(&port->lock, flags);
80247
80248 wake_up_interruptible(&port->open_wait);
80249 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80250 seq_putc(m, '\n');
80251
80252 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80253 - seq_printf(m, "Open count: %d\n", self->port.count);
80254 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80255 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80256 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80257
80258 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80259 index cd6f7a9..e63fe89 100644
80260 --- a/net/iucv/af_iucv.c
80261 +++ b/net/iucv/af_iucv.c
80262 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80263
80264 write_lock_bh(&iucv_sk_list.lock);
80265
80266 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80267 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80268 while (__iucv_get_sock_by_name(name)) {
80269 sprintf(name, "%08x",
80270 - atomic_inc_return(&iucv_sk_list.autobind_name));
80271 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80272 }
80273
80274 write_unlock_bh(&iucv_sk_list.lock);
80275 diff --git a/net/key/af_key.c b/net/key/af_key.c
80276 index 08897a3..0b812ab 100644
80277 --- a/net/key/af_key.c
80278 +++ b/net/key/af_key.c
80279 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80280 static u32 get_acqseq(void)
80281 {
80282 u32 res;
80283 - static atomic_t acqseq;
80284 + static atomic_unchecked_t acqseq;
80285
80286 do {
80287 - res = atomic_inc_return(&acqseq);
80288 + res = atomic_inc_return_unchecked(&acqseq);
80289 } while (!res);
80290 return res;
80291 }
80292 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80293 index 7371f67..9897314 100644
80294 --- a/net/mac80211/cfg.c
80295 +++ b/net/mac80211/cfg.c
80296 @@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80297 else
80298 local->probe_req_reg--;
80299
80300 - if (!local->open_count)
80301 + if (!local_read(&local->open_count))
80302 break;
80303
80304 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80305 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80306 index 3da215c..497a6e3 100644
80307 --- a/net/mac80211/ieee80211_i.h
80308 +++ b/net/mac80211/ieee80211_i.h
80309 @@ -28,6 +28,7 @@
80310 #include <net/ieee80211_radiotap.h>
80311 #include <net/cfg80211.h>
80312 #include <net/mac80211.h>
80313 +#include <asm/local.h>
80314 #include "key.h"
80315 #include "sta_info.h"
80316 #include "debug.h"
80317 @@ -852,7 +853,7 @@ struct ieee80211_local {
80318 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80319 spinlock_t queue_stop_reason_lock;
80320
80321 - int open_count;
80322 + local_t open_count;
80323 int monitors, cooked_mntrs;
80324 /* number of interfaces with corresponding FIF_ flags */
80325 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80326 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80327 index 0f5af91..4dba9e7 100644
80328 --- a/net/mac80211/iface.c
80329 +++ b/net/mac80211/iface.c
80330 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80331 break;
80332 }
80333
80334 - if (local->open_count == 0) {
80335 + if (local_read(&local->open_count) == 0) {
80336 res = drv_start(local);
80337 if (res)
80338 goto err_del_bss;
80339 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80340 break;
80341 }
80342
80343 - if (local->monitors == 0 && local->open_count == 0) {
80344 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80345 res = ieee80211_add_virtual_monitor(local);
80346 if (res)
80347 goto err_stop;
80348 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80349 mutex_unlock(&local->mtx);
80350
80351 if (coming_up)
80352 - local->open_count++;
80353 + local_inc(&local->open_count);
80354
80355 if (hw_reconf_flags)
80356 ieee80211_hw_config(local, hw_reconf_flags);
80357 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80358 err_del_interface:
80359 drv_remove_interface(local, sdata);
80360 err_stop:
80361 - if (!local->open_count)
80362 + if (!local_read(&local->open_count))
80363 drv_stop(local);
80364 err_del_bss:
80365 sdata->bss = NULL;
80366 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80367 }
80368
80369 if (going_down)
80370 - local->open_count--;
80371 + local_dec(&local->open_count);
80372
80373 switch (sdata->vif.type) {
80374 case NL80211_IFTYPE_AP_VLAN:
80375 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80376
80377 ieee80211_recalc_ps(local, -1);
80378
80379 - if (local->open_count == 0) {
80380 + if (local_read(&local->open_count) == 0) {
80381 if (local->ops->napi_poll)
80382 napi_disable(&local->napi);
80383 ieee80211_clear_tx_pending(local);
80384 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80385 }
80386 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80387
80388 - if (local->monitors == local->open_count && local->monitors > 0)
80389 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80390 ieee80211_add_virtual_monitor(local);
80391 }
80392
80393 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80394 index f57f597..e0a7c03 100644
80395 --- a/net/mac80211/main.c
80396 +++ b/net/mac80211/main.c
80397 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80398 local->hw.conf.power_level = power;
80399 }
80400
80401 - if (changed && local->open_count) {
80402 + if (changed && local_read(&local->open_count)) {
80403 ret = drv_config(local, changed);
80404 /*
80405 * Goal:
80406 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80407 index 5c572e7..ecf75ce 100644
80408 --- a/net/mac80211/pm.c
80409 +++ b/net/mac80211/pm.c
80410 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80411 struct ieee80211_sub_if_data *sdata;
80412 struct sta_info *sta;
80413
80414 - if (!local->open_count)
80415 + if (!local_read(&local->open_count))
80416 goto suspend;
80417
80418 ieee80211_scan_cancel(local);
80419 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80420 cancel_work_sync(&local->dynamic_ps_enable_work);
80421 del_timer_sync(&local->dynamic_ps_timer);
80422
80423 - local->wowlan = wowlan && local->open_count;
80424 + local->wowlan = wowlan && local_read(&local->open_count);
80425 if (local->wowlan) {
80426 int err = drv_suspend(local, wowlan);
80427 if (err < 0) {
80428 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80429 drv_remove_interface(local, sdata);
80430
80431 /* stop hardware - this must stop RX */
80432 - if (local->open_count)
80433 + if (local_read(&local->open_count))
80434 ieee80211_stop_device(local);
80435
80436 suspend:
80437 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80438 index 3313c11..bec9f17 100644
80439 --- a/net/mac80211/rate.c
80440 +++ b/net/mac80211/rate.c
80441 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80442
80443 ASSERT_RTNL();
80444
80445 - if (local->open_count)
80446 + if (local_read(&local->open_count))
80447 return -EBUSY;
80448
80449 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80450 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80451 index c97a065..ff61928 100644
80452 --- a/net/mac80211/rc80211_pid_debugfs.c
80453 +++ b/net/mac80211/rc80211_pid_debugfs.c
80454 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80455
80456 spin_unlock_irqrestore(&events->lock, status);
80457
80458 - if (copy_to_user(buf, pb, p))
80459 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80460 return -EFAULT;
80461
80462 return p;
80463 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80464 index 0151ae3..26709d3 100644
80465 --- a/net/mac80211/util.c
80466 +++ b/net/mac80211/util.c
80467 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80468 }
80469 #endif
80470 /* everything else happens only if HW was up & running */
80471 - if (!local->open_count)
80472 + if (!local_read(&local->open_count))
80473 goto wake_up;
80474
80475 /*
80476 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80477 index fefa514..0755f23 100644
80478 --- a/net/netfilter/Kconfig
80479 +++ b/net/netfilter/Kconfig
80480 @@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
80481
80482 To compile it as a module, choose M here. If unsure, say N.
80483
80484 +config NETFILTER_XT_MATCH_GRADM
80485 + tristate '"gradm" match support'
80486 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80487 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80488 + ---help---
80489 + The gradm match allows to match on grsecurity RBAC being enabled.
80490 + It is useful when iptables rules are applied early on bootup to
80491 + prevent connections to the machine (except from a trusted host)
80492 + while the RBAC system is disabled.
80493 +
80494 config NETFILTER_XT_MATCH_HASHLIMIT
80495 tristate '"hashlimit" match support'
80496 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80497 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80498 index 3259697..54d5393 100644
80499 --- a/net/netfilter/Makefile
80500 +++ b/net/netfilter/Makefile
80501 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80502 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80503 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80504 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80505 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80506 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80507 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80508 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80509 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80510 index 1548df9..98ad9b4 100644
80511 --- a/net/netfilter/ipvs/ip_vs_conn.c
80512 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80513 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80514 /* Increase the refcnt counter of the dest */
80515 atomic_inc(&dest->refcnt);
80516
80517 - conn_flags = atomic_read(&dest->conn_flags);
80518 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80519 if (cp->protocol != IPPROTO_UDP)
80520 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80521 flags = cp->flags;
80522 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80523 atomic_set(&cp->refcnt, 1);
80524
80525 atomic_set(&cp->n_control, 0);
80526 - atomic_set(&cp->in_pkts, 0);
80527 + atomic_set_unchecked(&cp->in_pkts, 0);
80528
80529 atomic_inc(&ipvs->conn_count);
80530 if (flags & IP_VS_CONN_F_NO_CPORT)
80531 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80532
80533 /* Don't drop the entry if its number of incoming packets is not
80534 located in [0, 8] */
80535 - i = atomic_read(&cp->in_pkts);
80536 + i = atomic_read_unchecked(&cp->in_pkts);
80537 if (i > 8 || i < 0) return 0;
80538
80539 if (!todrop_rate[i]) return 0;
80540 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80541 index 58918e2..4d177a9 100644
80542 --- a/net/netfilter/ipvs/ip_vs_core.c
80543 +++ b/net/netfilter/ipvs/ip_vs_core.c
80544 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80545 ret = cp->packet_xmit(skb, cp, pd->pp);
80546 /* do not touch skb anymore */
80547
80548 - atomic_inc(&cp->in_pkts);
80549 + atomic_inc_unchecked(&cp->in_pkts);
80550 ip_vs_conn_put(cp);
80551 return ret;
80552 }
80553 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80554 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80555 pkts = sysctl_sync_threshold(ipvs);
80556 else
80557 - pkts = atomic_add_return(1, &cp->in_pkts);
80558 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80559
80560 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80561 ip_vs_sync_conn(net, cp, pkts);
80562 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80563 index c4ee437..a774a74 100644
80564 --- a/net/netfilter/ipvs/ip_vs_ctl.c
80565 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
80566 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80567 ip_vs_rs_hash(ipvs, dest);
80568 write_unlock_bh(&ipvs->rs_lock);
80569 }
80570 - atomic_set(&dest->conn_flags, conn_flags);
80571 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
80572
80573 /* bind the service */
80574 if (!dest->svc) {
80575 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80576 " %-7s %-6d %-10d %-10d\n",
80577 &dest->addr.in6,
80578 ntohs(dest->port),
80579 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80580 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80581 atomic_read(&dest->weight),
80582 atomic_read(&dest->activeconns),
80583 atomic_read(&dest->inactconns));
80584 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80585 "%-7s %-6d %-10d %-10d\n",
80586 ntohl(dest->addr.ip),
80587 ntohs(dest->port),
80588 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80589 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80590 atomic_read(&dest->weight),
80591 atomic_read(&dest->activeconns),
80592 atomic_read(&dest->inactconns));
80593 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80594
80595 entry.addr = dest->addr.ip;
80596 entry.port = dest->port;
80597 - entry.conn_flags = atomic_read(&dest->conn_flags);
80598 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80599 entry.weight = atomic_read(&dest->weight);
80600 entry.u_threshold = dest->u_threshold;
80601 entry.l_threshold = dest->l_threshold;
80602 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80603 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80604 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80605 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80606 - (atomic_read(&dest->conn_flags) &
80607 + (atomic_read_unchecked(&dest->conn_flags) &
80608 IP_VS_CONN_F_FWD_MASK)) ||
80609 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80610 atomic_read(&dest->weight)) ||
80611 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80612 index effa10c..9058928 100644
80613 --- a/net/netfilter/ipvs/ip_vs_sync.c
80614 +++ b/net/netfilter/ipvs/ip_vs_sync.c
80615 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80616 cp = cp->control;
80617 if (cp) {
80618 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80619 - pkts = atomic_add_return(1, &cp->in_pkts);
80620 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80621 else
80622 pkts = sysctl_sync_threshold(ipvs);
80623 ip_vs_sync_conn(net, cp->control, pkts);
80624 @@ -758,7 +758,7 @@ control:
80625 if (!cp)
80626 return;
80627 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80628 - pkts = atomic_add_return(1, &cp->in_pkts);
80629 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80630 else
80631 pkts = sysctl_sync_threshold(ipvs);
80632 goto sloop;
80633 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80634
80635 if (opt)
80636 memcpy(&cp->in_seq, opt, sizeof(*opt));
80637 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80638 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80639 cp->state = state;
80640 cp->old_state = cp->state;
80641 /*
80642 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80643 index cc4c809..50f8fe5 100644
80644 --- a/net/netfilter/ipvs/ip_vs_xmit.c
80645 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
80646 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80647 else
80648 rc = NF_ACCEPT;
80649 /* do not touch skb anymore */
80650 - atomic_inc(&cp->in_pkts);
80651 + atomic_inc_unchecked(&cp->in_pkts);
80652 goto out;
80653 }
80654
80655 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80656 else
80657 rc = NF_ACCEPT;
80658 /* do not touch skb anymore */
80659 - atomic_inc(&cp->in_pkts);
80660 + atomic_inc_unchecked(&cp->in_pkts);
80661 goto out;
80662 }
80663
80664 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80665 index 0f241be..2c9be6d 100644
80666 --- a/net/netfilter/nf_conntrack_core.c
80667 +++ b/net/netfilter/nf_conntrack_core.c
80668 @@ -1532,6 +1532,10 @@ err_extend:
80669 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80670 #define DYING_NULLS_VAL ((1<<30)+1)
80671
80672 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80673 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80674 +#endif
80675 +
80676 static int nf_conntrack_init_net(struct net *net)
80677 {
80678 int ret;
80679 @@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
80680 goto err_stat;
80681 }
80682
80683 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80684 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
80685 +#else
80686 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
80687 +#endif
80688 if (!net->ct.slabname) {
80689 ret = -ENOMEM;
80690 goto err_slabname;
80691 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
80692 index 9f199f2..719ad23 100644
80693 --- a/net/netfilter/nfnetlink_log.c
80694 +++ b/net/netfilter/nfnetlink_log.c
80695 @@ -71,7 +71,7 @@ struct nfulnl_instance {
80696 };
80697
80698 static DEFINE_SPINLOCK(instances_lock);
80699 -static atomic_t global_seq;
80700 +static atomic_unchecked_t global_seq;
80701
80702 #define INSTANCE_BUCKETS 16
80703 static struct hlist_head instance_table[INSTANCE_BUCKETS];
80704 @@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
80705 /* global sequence number */
80706 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
80707 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
80708 - htonl(atomic_inc_return(&global_seq))))
80709 + htonl(atomic_inc_return_unchecked(&global_seq))))
80710 goto nla_put_failure;
80711
80712 if (data_len) {
80713 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
80714 new file mode 100644
80715 index 0000000..c566332
80716 --- /dev/null
80717 +++ b/net/netfilter/xt_gradm.c
80718 @@ -0,0 +1,51 @@
80719 +/*
80720 + * gradm match for netfilter
80721 + * Copyright © Zbigniew Krzystolik, 2010
80722 + *
80723 + * This program is free software; you can redistribute it and/or modify
80724 + * it under the terms of the GNU General Public License; either version
80725 + * 2 or 3 as published by the Free Software Foundation.
80726 + */
80727 +#include <linux/module.h>
80728 +#include <linux/moduleparam.h>
80729 +#include <linux/skbuff.h>
80730 +#include <linux/netfilter/x_tables.h>
80731 +#include <linux/grsecurity.h>
80732 +#include <linux/netfilter/xt_gradm.h>
80733 +
80734 +static bool
80735 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
80736 +{
80737 + const struct xt_gradm_mtinfo *info = par->matchinfo;
80738 + bool retval = false;
80739 + if (gr_acl_is_enabled())
80740 + retval = true;
80741 + return retval ^ info->invflags;
80742 +}
80743 +
80744 +static struct xt_match gradm_mt_reg __read_mostly = {
80745 + .name = "gradm",
80746 + .revision = 0,
80747 + .family = NFPROTO_UNSPEC,
80748 + .match = gradm_mt,
80749 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
80750 + .me = THIS_MODULE,
80751 +};
80752 +
80753 +static int __init gradm_mt_init(void)
80754 +{
80755 + return xt_register_match(&gradm_mt_reg);
80756 +}
80757 +
80758 +static void __exit gradm_mt_exit(void)
80759 +{
80760 + xt_unregister_match(&gradm_mt_reg);
80761 +}
80762 +
80763 +module_init(gradm_mt_init);
80764 +module_exit(gradm_mt_exit);
80765 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
80766 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
80767 +MODULE_LICENSE("GPL");
80768 +MODULE_ALIAS("ipt_gradm");
80769 +MODULE_ALIAS("ip6t_gradm");
80770 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
80771 index 4fe4fb4..87a89e5 100644
80772 --- a/net/netfilter/xt_statistic.c
80773 +++ b/net/netfilter/xt_statistic.c
80774 @@ -19,7 +19,7 @@
80775 #include <linux/module.h>
80776
80777 struct xt_statistic_priv {
80778 - atomic_t count;
80779 + atomic_unchecked_t count;
80780 } ____cacheline_aligned_in_smp;
80781
80782 MODULE_LICENSE("GPL");
80783 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
80784 break;
80785 case XT_STATISTIC_MODE_NTH:
80786 do {
80787 - oval = atomic_read(&info->master->count);
80788 + oval = atomic_read_unchecked(&info->master->count);
80789 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
80790 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
80791 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
80792 if (nval == 0)
80793 ret = !ret;
80794 break;
80795 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
80796 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
80797 if (info->master == NULL)
80798 return -ENOMEM;
80799 - atomic_set(&info->master->count, info->u.nth.count);
80800 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
80801
80802 return 0;
80803 }
80804 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
80805 index 4da797f..eb1df70 100644
80806 --- a/net/netlink/af_netlink.c
80807 +++ b/net/netlink/af_netlink.c
80808 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
80809 sk->sk_error_report(sk);
80810 }
80811 }
80812 - atomic_inc(&sk->sk_drops);
80813 + atomic_inc_unchecked(&sk->sk_drops);
80814 }
80815
80816 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
80817 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
80818 sk_wmem_alloc_get(s),
80819 nlk->cb,
80820 atomic_read(&s->sk_refcnt),
80821 - atomic_read(&s->sk_drops),
80822 + atomic_read_unchecked(&s->sk_drops),
80823 sock_i_ino(s)
80824 );
80825
80826 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
80827 index 7261eb8..44e8ac6 100644
80828 --- a/net/netrom/af_netrom.c
80829 +++ b/net/netrom/af_netrom.c
80830 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
80831 struct sock *sk = sock->sk;
80832 struct nr_sock *nr = nr_sk(sk);
80833
80834 + memset(sax, 0, sizeof(*sax));
80835 lock_sock(sk);
80836 if (peer != 0) {
80837 if (sk->sk_state != TCP_ESTABLISHED) {
80838 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
80839 *uaddr_len = sizeof(struct full_sockaddr_ax25);
80840 } else {
80841 sax->fsa_ax25.sax25_family = AF_NETROM;
80842 - sax->fsa_ax25.sax25_ndigis = 0;
80843 sax->fsa_ax25.sax25_call = nr->source_addr;
80844 *uaddr_len = sizeof(struct sockaddr_ax25);
80845 }
80846 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
80847 index 94060ed..9c066f3 100644
80848 --- a/net/packet/af_packet.c
80849 +++ b/net/packet/af_packet.c
80850 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
80851
80852 spin_lock(&sk->sk_receive_queue.lock);
80853 po->stats.tp_packets++;
80854 - skb->dropcount = atomic_read(&sk->sk_drops);
80855 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80856 __skb_queue_tail(&sk->sk_receive_queue, skb);
80857 spin_unlock(&sk->sk_receive_queue.lock);
80858 sk->sk_data_ready(sk, skb->len);
80859 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
80860 drop_n_acct:
80861 spin_lock(&sk->sk_receive_queue.lock);
80862 po->stats.tp_drops++;
80863 - atomic_inc(&sk->sk_drops);
80864 + atomic_inc_unchecked(&sk->sk_drops);
80865 spin_unlock(&sk->sk_receive_queue.lock);
80866
80867 drop_n_restore:
80868 @@ -2537,6 +2537,7 @@ out:
80869
80870 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
80871 {
80872 + struct sock_extended_err ee;
80873 struct sock_exterr_skb *serr;
80874 struct sk_buff *skb, *skb2;
80875 int copied, err;
80876 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
80877 sock_recv_timestamp(msg, sk, skb);
80878
80879 serr = SKB_EXT_ERR(skb);
80880 + ee = serr->ee;
80881 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
80882 - sizeof(serr->ee), &serr->ee);
80883 + sizeof ee, &ee);
80884
80885 msg->msg_flags |= MSG_ERRQUEUE;
80886 err = copied;
80887 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
80888 case PACKET_HDRLEN:
80889 if (len > sizeof(int))
80890 len = sizeof(int);
80891 - if (copy_from_user(&val, optval, len))
80892 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
80893 return -EFAULT;
80894 switch (val) {
80895 case TPACKET_V1:
80896 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
80897 len = lv;
80898 if (put_user(len, optlen))
80899 return -EFAULT;
80900 - if (copy_to_user(optval, data, len))
80901 + if (len > sizeof(st) || copy_to_user(optval, data, len))
80902 return -EFAULT;
80903 return 0;
80904 }
80905 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
80906 index 5a940db..f0b9c12 100644
80907 --- a/net/phonet/af_phonet.c
80908 +++ b/net/phonet/af_phonet.c
80909 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
80910 {
80911 struct phonet_protocol *pp;
80912
80913 - if (protocol >= PHONET_NPROTO)
80914 + if (protocol < 0 || protocol >= PHONET_NPROTO)
80915 return NULL;
80916
80917 rcu_read_lock();
80918 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
80919 {
80920 int err = 0;
80921
80922 - if (protocol >= PHONET_NPROTO)
80923 + if (protocol < 0 || protocol >= PHONET_NPROTO)
80924 return -EINVAL;
80925
80926 err = proto_register(pp->prot, 1);
80927 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
80928 index 576f22c..bc7a71b 100644
80929 --- a/net/phonet/pep.c
80930 +++ b/net/phonet/pep.c
80931 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
80932
80933 case PNS_PEP_CTRL_REQ:
80934 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
80935 - atomic_inc(&sk->sk_drops);
80936 + atomic_inc_unchecked(&sk->sk_drops);
80937 break;
80938 }
80939 __skb_pull(skb, 4);
80940 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
80941 }
80942
80943 if (pn->rx_credits == 0) {
80944 - atomic_inc(&sk->sk_drops);
80945 + atomic_inc_unchecked(&sk->sk_drops);
80946 err = -ENOBUFS;
80947 break;
80948 }
80949 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
80950 }
80951
80952 if (pn->rx_credits == 0) {
80953 - atomic_inc(&sk->sk_drops);
80954 + atomic_inc_unchecked(&sk->sk_drops);
80955 err = NET_RX_DROP;
80956 break;
80957 }
80958 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
80959 index b7e9827..c264c85 100644
80960 --- a/net/phonet/socket.c
80961 +++ b/net/phonet/socket.c
80962 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
80963 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
80964 sock_i_ino(sk),
80965 atomic_read(&sk->sk_refcnt), sk,
80966 - atomic_read(&sk->sk_drops), &len);
80967 + atomic_read_unchecked(&sk->sk_drops), &len);
80968 }
80969 seq_printf(seq, "%*s\n", 127 - len, "");
80970 return 0;
80971 diff --git a/net/rds/cong.c b/net/rds/cong.c
80972 index e5b65ac..f3b6fb7 100644
80973 --- a/net/rds/cong.c
80974 +++ b/net/rds/cong.c
80975 @@ -78,7 +78,7 @@
80976 * finds that the saved generation number is smaller than the global generation
80977 * number, it wakes up the process.
80978 */
80979 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
80980 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
80981
80982 /*
80983 * Congestion monitoring
80984 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
80985 rdsdebug("waking map %p for %pI4\n",
80986 map, &map->m_addr);
80987 rds_stats_inc(s_cong_update_received);
80988 - atomic_inc(&rds_cong_generation);
80989 + atomic_inc_unchecked(&rds_cong_generation);
80990 if (waitqueue_active(&map->m_waitq))
80991 wake_up(&map->m_waitq);
80992 if (waitqueue_active(&rds_poll_waitq))
80993 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
80994
80995 int rds_cong_updated_since(unsigned long *recent)
80996 {
80997 - unsigned long gen = atomic_read(&rds_cong_generation);
80998 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
80999
81000 if (likely(*recent == gen))
81001 return 0;
81002 diff --git a/net/rds/ib.h b/net/rds/ib.h
81003 index 8d2b3d5..227ec5b 100644
81004 --- a/net/rds/ib.h
81005 +++ b/net/rds/ib.h
81006 @@ -128,7 +128,7 @@ struct rds_ib_connection {
81007 /* sending acks */
81008 unsigned long i_ack_flags;
81009 #ifdef KERNEL_HAS_ATOMIC64
81010 - atomic64_t i_ack_next; /* next ACK to send */
81011 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81012 #else
81013 spinlock_t i_ack_lock; /* protect i_ack_next */
81014 u64 i_ack_next; /* next ACK to send */
81015 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
81016 index a1e1162..265e129 100644
81017 --- a/net/rds/ib_cm.c
81018 +++ b/net/rds/ib_cm.c
81019 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
81020 /* Clear the ACK state */
81021 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81022 #ifdef KERNEL_HAS_ATOMIC64
81023 - atomic64_set(&ic->i_ack_next, 0);
81024 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81025 #else
81026 ic->i_ack_next = 0;
81027 #endif
81028 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
81029 index 8d19491..05a3e65 100644
81030 --- a/net/rds/ib_recv.c
81031 +++ b/net/rds/ib_recv.c
81032 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81033 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
81034 int ack_required)
81035 {
81036 - atomic64_set(&ic->i_ack_next, seq);
81037 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81038 if (ack_required) {
81039 smp_mb__before_clear_bit();
81040 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81041 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81042 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81043 smp_mb__after_clear_bit();
81044
81045 - return atomic64_read(&ic->i_ack_next);
81046 + return atomic64_read_unchecked(&ic->i_ack_next);
81047 }
81048 #endif
81049
81050 diff --git a/net/rds/iw.h b/net/rds/iw.h
81051 index 04ce3b1..48119a6 100644
81052 --- a/net/rds/iw.h
81053 +++ b/net/rds/iw.h
81054 @@ -134,7 +134,7 @@ struct rds_iw_connection {
81055 /* sending acks */
81056 unsigned long i_ack_flags;
81057 #ifdef KERNEL_HAS_ATOMIC64
81058 - atomic64_t i_ack_next; /* next ACK to send */
81059 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81060 #else
81061 spinlock_t i_ack_lock; /* protect i_ack_next */
81062 u64 i_ack_next; /* next ACK to send */
81063 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
81064 index a91e1db..cf3053f 100644
81065 --- a/net/rds/iw_cm.c
81066 +++ b/net/rds/iw_cm.c
81067 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
81068 /* Clear the ACK state */
81069 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81070 #ifdef KERNEL_HAS_ATOMIC64
81071 - atomic64_set(&ic->i_ack_next, 0);
81072 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81073 #else
81074 ic->i_ack_next = 0;
81075 #endif
81076 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
81077 index 4503335..db566b4 100644
81078 --- a/net/rds/iw_recv.c
81079 +++ b/net/rds/iw_recv.c
81080 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81081 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
81082 int ack_required)
81083 {
81084 - atomic64_set(&ic->i_ack_next, seq);
81085 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81086 if (ack_required) {
81087 smp_mb__before_clear_bit();
81088 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81089 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81090 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81091 smp_mb__after_clear_bit();
81092
81093 - return atomic64_read(&ic->i_ack_next);
81094 + return atomic64_read_unchecked(&ic->i_ack_next);
81095 }
81096 #endif
81097
81098 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
81099 index edac9ef..16bcb98 100644
81100 --- a/net/rds/tcp.c
81101 +++ b/net/rds/tcp.c
81102 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
81103 int val = 1;
81104
81105 set_fs(KERNEL_DS);
81106 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
81107 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
81108 sizeof(val));
81109 set_fs(oldfs);
81110 }
81111 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
81112 index 81cf5a4..b5826ff 100644
81113 --- a/net/rds/tcp_send.c
81114 +++ b/net/rds/tcp_send.c
81115 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
81116
81117 oldfs = get_fs();
81118 set_fs(KERNEL_DS);
81119 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
81120 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
81121 sizeof(val));
81122 set_fs(oldfs);
81123 }
81124 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
81125 index 05996d0..5a1dfe0 100644
81126 --- a/net/rxrpc/af_rxrpc.c
81127 +++ b/net/rxrpc/af_rxrpc.c
81128 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
81129 __be32 rxrpc_epoch;
81130
81131 /* current debugging ID */
81132 -atomic_t rxrpc_debug_id;
81133 +atomic_unchecked_t rxrpc_debug_id;
81134
81135 /* count of skbs currently in use */
81136 atomic_t rxrpc_n_skbs;
81137 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
81138 index e4d9cbc..b229649 100644
81139 --- a/net/rxrpc/ar-ack.c
81140 +++ b/net/rxrpc/ar-ack.c
81141 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81142
81143 _enter("{%d,%d,%d,%d},",
81144 call->acks_hard, call->acks_unacked,
81145 - atomic_read(&call->sequence),
81146 + atomic_read_unchecked(&call->sequence),
81147 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
81148
81149 stop = 0;
81150 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81151
81152 /* each Tx packet has a new serial number */
81153 sp->hdr.serial =
81154 - htonl(atomic_inc_return(&call->conn->serial));
81155 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
81156
81157 hdr = (struct rxrpc_header *) txb->head;
81158 hdr->serial = sp->hdr.serial;
81159 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
81160 */
81161 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
81162 {
81163 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
81164 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
81165 }
81166
81167 /*
81168 @@ -629,7 +629,7 @@ process_further:
81169
81170 latest = ntohl(sp->hdr.serial);
81171 hard = ntohl(ack.firstPacket);
81172 - tx = atomic_read(&call->sequence);
81173 + tx = atomic_read_unchecked(&call->sequence);
81174
81175 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81176 latest,
81177 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
81178 goto maybe_reschedule;
81179
81180 send_ACK_with_skew:
81181 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
81182 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
81183 ntohl(ack.serial));
81184 send_ACK:
81185 mtu = call->conn->trans->peer->if_mtu;
81186 @@ -1173,7 +1173,7 @@ send_ACK:
81187 ackinfo.rxMTU = htonl(5692);
81188 ackinfo.jumbo_max = htonl(4);
81189
81190 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81191 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81192 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81193 ntohl(hdr.serial),
81194 ntohs(ack.maxSkew),
81195 @@ -1191,7 +1191,7 @@ send_ACK:
81196 send_message:
81197 _debug("send message");
81198
81199 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81200 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81201 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
81202 send_message_2:
81203
81204 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
81205 index a3bbb36..3341fb9 100644
81206 --- a/net/rxrpc/ar-call.c
81207 +++ b/net/rxrpc/ar-call.c
81208 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
81209 spin_lock_init(&call->lock);
81210 rwlock_init(&call->state_lock);
81211 atomic_set(&call->usage, 1);
81212 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
81213 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81214 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
81215
81216 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
81217 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
81218 index 4106ca9..a338d7a 100644
81219 --- a/net/rxrpc/ar-connection.c
81220 +++ b/net/rxrpc/ar-connection.c
81221 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
81222 rwlock_init(&conn->lock);
81223 spin_lock_init(&conn->state_lock);
81224 atomic_set(&conn->usage, 1);
81225 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
81226 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81227 conn->avail_calls = RXRPC_MAXCALLS;
81228 conn->size_align = 4;
81229 conn->header_size = sizeof(struct rxrpc_header);
81230 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
81231 index e7ed43a..6afa140 100644
81232 --- a/net/rxrpc/ar-connevent.c
81233 +++ b/net/rxrpc/ar-connevent.c
81234 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
81235
81236 len = iov[0].iov_len + iov[1].iov_len;
81237
81238 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81239 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81240 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
81241
81242 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81243 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
81244 index 529572f..c758ca7 100644
81245 --- a/net/rxrpc/ar-input.c
81246 +++ b/net/rxrpc/ar-input.c
81247 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
81248 /* track the latest serial number on this connection for ACK packet
81249 * information */
81250 serial = ntohl(sp->hdr.serial);
81251 - hi_serial = atomic_read(&call->conn->hi_serial);
81252 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
81253 while (serial > hi_serial)
81254 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
81255 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
81256 serial);
81257
81258 /* request ACK generation for any ACK or DATA packet that requests
81259 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
81260 index a693aca..81e7293 100644
81261 --- a/net/rxrpc/ar-internal.h
81262 +++ b/net/rxrpc/ar-internal.h
81263 @@ -272,8 +272,8 @@ struct rxrpc_connection {
81264 int error; /* error code for local abort */
81265 int debug_id; /* debug ID for printks */
81266 unsigned int call_counter; /* call ID counter */
81267 - atomic_t serial; /* packet serial number counter */
81268 - atomic_t hi_serial; /* highest serial number received */
81269 + atomic_unchecked_t serial; /* packet serial number counter */
81270 + atomic_unchecked_t hi_serial; /* highest serial number received */
81271 u8 avail_calls; /* number of calls available */
81272 u8 size_align; /* data size alignment (for security) */
81273 u8 header_size; /* rxrpc + security header size */
81274 @@ -346,7 +346,7 @@ struct rxrpc_call {
81275 spinlock_t lock;
81276 rwlock_t state_lock; /* lock for state transition */
81277 atomic_t usage;
81278 - atomic_t sequence; /* Tx data packet sequence counter */
81279 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
81280 u32 abort_code; /* local/remote abort code */
81281 enum { /* current state of call */
81282 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
81283 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
81284 */
81285 extern atomic_t rxrpc_n_skbs;
81286 extern __be32 rxrpc_epoch;
81287 -extern atomic_t rxrpc_debug_id;
81288 +extern atomic_unchecked_t rxrpc_debug_id;
81289 extern struct workqueue_struct *rxrpc_workqueue;
81290
81291 /*
81292 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
81293 index 87f7135..74d3703 100644
81294 --- a/net/rxrpc/ar-local.c
81295 +++ b/net/rxrpc/ar-local.c
81296 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
81297 spin_lock_init(&local->lock);
81298 rwlock_init(&local->services_lock);
81299 atomic_set(&local->usage, 1);
81300 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
81301 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81302 memcpy(&local->srx, srx, sizeof(*srx));
81303 }
81304
81305 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
81306 index e1ac183..b43e10e 100644
81307 --- a/net/rxrpc/ar-output.c
81308 +++ b/net/rxrpc/ar-output.c
81309 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
81310 sp->hdr.cid = call->cid;
81311 sp->hdr.callNumber = call->call_id;
81312 sp->hdr.seq =
81313 - htonl(atomic_inc_return(&call->sequence));
81314 + htonl(atomic_inc_return_unchecked(&call->sequence));
81315 sp->hdr.serial =
81316 - htonl(atomic_inc_return(&conn->serial));
81317 + htonl(atomic_inc_return_unchecked(&conn->serial));
81318 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
81319 sp->hdr.userStatus = 0;
81320 sp->hdr.securityIndex = conn->security_ix;
81321 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
81322 index bebaa43..2644591 100644
81323 --- a/net/rxrpc/ar-peer.c
81324 +++ b/net/rxrpc/ar-peer.c
81325 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
81326 INIT_LIST_HEAD(&peer->error_targets);
81327 spin_lock_init(&peer->lock);
81328 atomic_set(&peer->usage, 1);
81329 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
81330 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81331 memcpy(&peer->srx, srx, sizeof(*srx));
81332
81333 rxrpc_assess_MTU_size(peer);
81334 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
81335 index 38047f7..9f48511 100644
81336 --- a/net/rxrpc/ar-proc.c
81337 +++ b/net/rxrpc/ar-proc.c
81338 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
81339 atomic_read(&conn->usage),
81340 rxrpc_conn_states[conn->state],
81341 key_serial(conn->key),
81342 - atomic_read(&conn->serial),
81343 - atomic_read(&conn->hi_serial));
81344 + atomic_read_unchecked(&conn->serial),
81345 + atomic_read_unchecked(&conn->hi_serial));
81346
81347 return 0;
81348 }
81349 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
81350 index 92df566..87ec1bf 100644
81351 --- a/net/rxrpc/ar-transport.c
81352 +++ b/net/rxrpc/ar-transport.c
81353 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
81354 spin_lock_init(&trans->client_lock);
81355 rwlock_init(&trans->conn_lock);
81356 atomic_set(&trans->usage, 1);
81357 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
81358 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81359
81360 if (peer->srx.transport.family == AF_INET) {
81361 switch (peer->srx.transport_type) {
81362 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
81363 index f226709..0e735a8 100644
81364 --- a/net/rxrpc/rxkad.c
81365 +++ b/net/rxrpc/rxkad.c
81366 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
81367
81368 len = iov[0].iov_len + iov[1].iov_len;
81369
81370 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81371 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81372 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
81373
81374 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81375 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
81376
81377 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
81378
81379 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
81380 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81381 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
81382
81383 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
81384 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
81385 index ea14cb4..834e8e4 100644
81386 --- a/net/sctp/ipv6.c
81387 +++ b/net/sctp/ipv6.c
81388 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
81389
81390 void sctp_v6_pf_exit(void)
81391 {
81392 - list_del(&sctp_af_inet6.list);
81393 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
81394 }
81395
81396 /* Initialize IPv6 support and register with socket layer. */
81397 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
81398 index 9966e7b..540c575 100644
81399 --- a/net/sctp/proc.c
81400 +++ b/net/sctp/proc.c
81401 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
81402 seq_printf(seq,
81403 "%8pK %8pK %-3d %-3d %-2d %-4d "
81404 "%4d %8d %8d %7d %5lu %-5d %5d ",
81405 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
81406 + assoc, sk,
81407 + sctp_sk(sk)->type, sk->sk_state,
81408 assoc->state, hash,
81409 assoc->assoc_id,
81410 assoc->sndbuf_used,
81411 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
81412 index 2d51842..150ba5c 100644
81413 --- a/net/sctp/protocol.c
81414 +++ b/net/sctp/protocol.c
81415 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
81416 return 0;
81417 }
81418
81419 - INIT_LIST_HEAD(&af->list);
81420 - list_add_tail(&af->list, &sctp_address_families);
81421 + pax_open_kernel();
81422 + INIT_LIST_HEAD((struct list_head *)&af->list);
81423 + pax_close_kernel();
81424 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
81425 return 1;
81426 }
81427
81428 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
81429
81430 static void sctp_v4_pf_exit(void)
81431 {
81432 - list_del(&sctp_af_inet.list);
81433 + pax_list_del((struct list_head *)&sctp_af_inet.list);
81434 }
81435
81436 static int sctp_v4_protosw_init(void)
81437 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
81438 index 406d957..543c737 100644
81439 --- a/net/sctp/socket.c
81440 +++ b/net/sctp/socket.c
81441 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
81442 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
81443 if (space_left < addrlen)
81444 return -ENOMEM;
81445 + if (addrlen > sizeof(temp) || addrlen < 0)
81446 + return -EFAULT;
81447 if (copy_to_user(to, &temp, addrlen))
81448 return -EFAULT;
81449 to += addrlen;
81450 diff --git a/net/socket.c b/net/socket.c
81451 index d92c490..b4bc863 100644
81452 --- a/net/socket.c
81453 +++ b/net/socket.c
81454 @@ -89,6 +89,7 @@
81455 #include <linux/magic.h>
81456 #include <linux/slab.h>
81457 #include <linux/xattr.h>
81458 +#include <linux/in.h>
81459
81460 #include <asm/uaccess.h>
81461 #include <asm/unistd.h>
81462 @@ -106,6 +107,8 @@
81463 #include <linux/sockios.h>
81464 #include <linux/atalk.h>
81465
81466 +#include <linux/grsock.h>
81467 +
81468 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
81469 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
81470 unsigned long nr_segs, loff_t pos);
81471 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
81472 &sockfs_dentry_operations, SOCKFS_MAGIC);
81473 }
81474
81475 -static struct vfsmount *sock_mnt __read_mostly;
81476 +struct vfsmount *sock_mnt __read_mostly;
81477
81478 static struct file_system_type sock_fs_type = {
81479 .name = "sockfs",
81480 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
81481 return -EAFNOSUPPORT;
81482 if (type < 0 || type >= SOCK_MAX)
81483 return -EINVAL;
81484 + if (protocol < 0)
81485 + return -EINVAL;
81486
81487 /* Compatibility.
81488
81489 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
81490 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
81491 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
81492
81493 + if(!gr_search_socket(family, type, protocol)) {
81494 + retval = -EACCES;
81495 + goto out;
81496 + }
81497 +
81498 + if (gr_handle_sock_all(family, type, protocol)) {
81499 + retval = -EACCES;
81500 + goto out;
81501 + }
81502 +
81503 retval = sock_create(family, type, protocol, &sock);
81504 if (retval < 0)
81505 goto out;
81506 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81507 if (sock) {
81508 err = move_addr_to_kernel(umyaddr, addrlen, &address);
81509 if (err >= 0) {
81510 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
81511 + err = -EACCES;
81512 + goto error;
81513 + }
81514 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
81515 + if (err)
81516 + goto error;
81517 +
81518 err = security_socket_bind(sock,
81519 (struct sockaddr *)&address,
81520 addrlen);
81521 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81522 (struct sockaddr *)
81523 &address, addrlen);
81524 }
81525 +error:
81526 fput_light(sock->file, fput_needed);
81527 }
81528 return err;
81529 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
81530 if ((unsigned int)backlog > somaxconn)
81531 backlog = somaxconn;
81532
81533 + if (gr_handle_sock_server_other(sock->sk)) {
81534 + err = -EPERM;
81535 + goto error;
81536 + }
81537 +
81538 + err = gr_search_listen(sock);
81539 + if (err)
81540 + goto error;
81541 +
81542 err = security_socket_listen(sock, backlog);
81543 if (!err)
81544 err = sock->ops->listen(sock, backlog);
81545
81546 +error:
81547 fput_light(sock->file, fput_needed);
81548 }
81549 return err;
81550 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81551 newsock->type = sock->type;
81552 newsock->ops = sock->ops;
81553
81554 + if (gr_handle_sock_server_other(sock->sk)) {
81555 + err = -EPERM;
81556 + sock_release(newsock);
81557 + goto out_put;
81558 + }
81559 +
81560 + err = gr_search_accept(sock);
81561 + if (err) {
81562 + sock_release(newsock);
81563 + goto out_put;
81564 + }
81565 +
81566 /*
81567 * We don't need try_module_get here, as the listening socket (sock)
81568 * has the protocol module (sock->ops->owner) held.
81569 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81570 fd_install(newfd, newfile);
81571 err = newfd;
81572
81573 + gr_attach_curr_ip(newsock->sk);
81574 +
81575 out_put:
81576 fput_light(sock->file, fput_needed);
81577 out:
81578 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81579 int, addrlen)
81580 {
81581 struct socket *sock;
81582 + struct sockaddr *sck;
81583 struct sockaddr_storage address;
81584 int err, fput_needed;
81585
81586 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81587 if (err < 0)
81588 goto out_put;
81589
81590 + sck = (struct sockaddr *)&address;
81591 +
81592 + if (gr_handle_sock_client(sck)) {
81593 + err = -EACCES;
81594 + goto out_put;
81595 + }
81596 +
81597 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
81598 + if (err)
81599 + goto out_put;
81600 +
81601 err =
81602 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
81603 if (err)
81604 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
81605 * checking falls down on this.
81606 */
81607 if (copy_from_user(ctl_buf,
81608 - (void __user __force *)msg_sys->msg_control,
81609 + (void __force_user *)msg_sys->msg_control,
81610 ctl_len))
81611 goto out_freectl;
81612 msg_sys->msg_control = ctl_buf;
81613 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
81614 * kernel msghdr to use the kernel address space)
81615 */
81616
81617 - uaddr = (__force void __user *)msg_sys->msg_name;
81618 + uaddr = (void __force_user *)msg_sys->msg_name;
81619 uaddr_len = COMPAT_NAMELEN(msg);
81620 if (MSG_CMSG_COMPAT & flags) {
81621 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
81622 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81623 }
81624
81625 ifr = compat_alloc_user_space(buf_size);
81626 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
81627 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
81628
81629 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
81630 return -EFAULT;
81631 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81632 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
81633
81634 if (copy_in_user(rxnfc, compat_rxnfc,
81635 - (void *)(&rxnfc->fs.m_ext + 1) -
81636 - (void *)rxnfc) ||
81637 + (void __user *)(&rxnfc->fs.m_ext + 1) -
81638 + (void __user *)rxnfc) ||
81639 copy_in_user(&rxnfc->fs.ring_cookie,
81640 &compat_rxnfc->fs.ring_cookie,
81641 - (void *)(&rxnfc->fs.location + 1) -
81642 - (void *)&rxnfc->fs.ring_cookie) ||
81643 + (void __user *)(&rxnfc->fs.location + 1) -
81644 + (void __user *)&rxnfc->fs.ring_cookie) ||
81645 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
81646 sizeof(rxnfc->rule_cnt)))
81647 return -EFAULT;
81648 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81649
81650 if (convert_out) {
81651 if (copy_in_user(compat_rxnfc, rxnfc,
81652 - (const void *)(&rxnfc->fs.m_ext + 1) -
81653 - (const void *)rxnfc) ||
81654 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
81655 + (const void __user *)rxnfc) ||
81656 copy_in_user(&compat_rxnfc->fs.ring_cookie,
81657 &rxnfc->fs.ring_cookie,
81658 - (const void *)(&rxnfc->fs.location + 1) -
81659 - (const void *)&rxnfc->fs.ring_cookie) ||
81660 + (const void __user *)(&rxnfc->fs.location + 1) -
81661 + (const void __user *)&rxnfc->fs.ring_cookie) ||
81662 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
81663 sizeof(rxnfc->rule_cnt)))
81664 return -EFAULT;
81665 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
81666 old_fs = get_fs();
81667 set_fs(KERNEL_DS);
81668 err = dev_ioctl(net, cmd,
81669 - (struct ifreq __user __force *) &kifr);
81670 + (struct ifreq __force_user *) &kifr);
81671 set_fs(old_fs);
81672
81673 return err;
81674 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
81675
81676 old_fs = get_fs();
81677 set_fs(KERNEL_DS);
81678 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
81679 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
81680 set_fs(old_fs);
81681
81682 if (cmd == SIOCGIFMAP && !err) {
81683 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
81684 ret |= __get_user(rtdev, &(ur4->rt_dev));
81685 if (rtdev) {
81686 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
81687 - r4.rt_dev = (char __user __force *)devname;
81688 + r4.rt_dev = (char __force_user *)devname;
81689 devname[15] = 0;
81690 } else
81691 r4.rt_dev = NULL;
81692 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
81693 int __user *uoptlen;
81694 int err;
81695
81696 - uoptval = (char __user __force *) optval;
81697 - uoptlen = (int __user __force *) optlen;
81698 + uoptval = (char __force_user *) optval;
81699 + uoptlen = (int __force_user *) optlen;
81700
81701 set_fs(KERNEL_DS);
81702 if (level == SOL_SOCKET)
81703 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
81704 char __user *uoptval;
81705 int err;
81706
81707 - uoptval = (char __user __force *) optval;
81708 + uoptval = (char __force_user *) optval;
81709
81710 set_fs(KERNEL_DS);
81711 if (level == SOL_SOCKET)
81712 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
81713 index 7865b44..174662e 100644
81714 --- a/net/sunrpc/sched.c
81715 +++ b/net/sunrpc/sched.c
81716 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
81717 #ifdef RPC_DEBUG
81718 static void rpc_task_set_debuginfo(struct rpc_task *task)
81719 {
81720 - static atomic_t rpc_pid;
81721 + static atomic_unchecked_t rpc_pid;
81722
81723 - task->tk_pid = atomic_inc_return(&rpc_pid);
81724 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
81725 }
81726 #else
81727 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
81728 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
81729 index 8343737..677025e 100644
81730 --- a/net/sunrpc/xprtrdma/svc_rdma.c
81731 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
81732 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
81733 static unsigned int min_max_inline = 4096;
81734 static unsigned int max_max_inline = 65536;
81735
81736 -atomic_t rdma_stat_recv;
81737 -atomic_t rdma_stat_read;
81738 -atomic_t rdma_stat_write;
81739 -atomic_t rdma_stat_sq_starve;
81740 -atomic_t rdma_stat_rq_starve;
81741 -atomic_t rdma_stat_rq_poll;
81742 -atomic_t rdma_stat_rq_prod;
81743 -atomic_t rdma_stat_sq_poll;
81744 -atomic_t rdma_stat_sq_prod;
81745 +atomic_unchecked_t rdma_stat_recv;
81746 +atomic_unchecked_t rdma_stat_read;
81747 +atomic_unchecked_t rdma_stat_write;
81748 +atomic_unchecked_t rdma_stat_sq_starve;
81749 +atomic_unchecked_t rdma_stat_rq_starve;
81750 +atomic_unchecked_t rdma_stat_rq_poll;
81751 +atomic_unchecked_t rdma_stat_rq_prod;
81752 +atomic_unchecked_t rdma_stat_sq_poll;
81753 +atomic_unchecked_t rdma_stat_sq_prod;
81754
81755 /* Temporary NFS request map and context caches */
81756 struct kmem_cache *svc_rdma_map_cachep;
81757 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
81758 len -= *ppos;
81759 if (len > *lenp)
81760 len = *lenp;
81761 - if (len && copy_to_user(buffer, str_buf, len))
81762 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
81763 return -EFAULT;
81764 *lenp = len;
81765 *ppos += len;
81766 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
81767 {
81768 .procname = "rdma_stat_read",
81769 .data = &rdma_stat_read,
81770 - .maxlen = sizeof(atomic_t),
81771 + .maxlen = sizeof(atomic_unchecked_t),
81772 .mode = 0644,
81773 .proc_handler = read_reset_stat,
81774 },
81775 {
81776 .procname = "rdma_stat_recv",
81777 .data = &rdma_stat_recv,
81778 - .maxlen = sizeof(atomic_t),
81779 + .maxlen = sizeof(atomic_unchecked_t),
81780 .mode = 0644,
81781 .proc_handler = read_reset_stat,
81782 },
81783 {
81784 .procname = "rdma_stat_write",
81785 .data = &rdma_stat_write,
81786 - .maxlen = sizeof(atomic_t),
81787 + .maxlen = sizeof(atomic_unchecked_t),
81788 .mode = 0644,
81789 .proc_handler = read_reset_stat,
81790 },
81791 {
81792 .procname = "rdma_stat_sq_starve",
81793 .data = &rdma_stat_sq_starve,
81794 - .maxlen = sizeof(atomic_t),
81795 + .maxlen = sizeof(atomic_unchecked_t),
81796 .mode = 0644,
81797 .proc_handler = read_reset_stat,
81798 },
81799 {
81800 .procname = "rdma_stat_rq_starve",
81801 .data = &rdma_stat_rq_starve,
81802 - .maxlen = sizeof(atomic_t),
81803 + .maxlen = sizeof(atomic_unchecked_t),
81804 .mode = 0644,
81805 .proc_handler = read_reset_stat,
81806 },
81807 {
81808 .procname = "rdma_stat_rq_poll",
81809 .data = &rdma_stat_rq_poll,
81810 - .maxlen = sizeof(atomic_t),
81811 + .maxlen = sizeof(atomic_unchecked_t),
81812 .mode = 0644,
81813 .proc_handler = read_reset_stat,
81814 },
81815 {
81816 .procname = "rdma_stat_rq_prod",
81817 .data = &rdma_stat_rq_prod,
81818 - .maxlen = sizeof(atomic_t),
81819 + .maxlen = sizeof(atomic_unchecked_t),
81820 .mode = 0644,
81821 .proc_handler = read_reset_stat,
81822 },
81823 {
81824 .procname = "rdma_stat_sq_poll",
81825 .data = &rdma_stat_sq_poll,
81826 - .maxlen = sizeof(atomic_t),
81827 + .maxlen = sizeof(atomic_unchecked_t),
81828 .mode = 0644,
81829 .proc_handler = read_reset_stat,
81830 },
81831 {
81832 .procname = "rdma_stat_sq_prod",
81833 .data = &rdma_stat_sq_prod,
81834 - .maxlen = sizeof(atomic_t),
81835 + .maxlen = sizeof(atomic_unchecked_t),
81836 .mode = 0644,
81837 .proc_handler = read_reset_stat,
81838 },
81839 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
81840 index 41cb63b..c4a1489 100644
81841 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
81842 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
81843 @@ -501,7 +501,7 @@ next_sge:
81844 svc_rdma_put_context(ctxt, 0);
81845 goto out;
81846 }
81847 - atomic_inc(&rdma_stat_read);
81848 + atomic_inc_unchecked(&rdma_stat_read);
81849
81850 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
81851 chl_map->ch[ch_no].count -= read_wr.num_sge;
81852 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
81853 dto_q);
81854 list_del_init(&ctxt->dto_q);
81855 } else {
81856 - atomic_inc(&rdma_stat_rq_starve);
81857 + atomic_inc_unchecked(&rdma_stat_rq_starve);
81858 clear_bit(XPT_DATA, &xprt->xpt_flags);
81859 ctxt = NULL;
81860 }
81861 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
81862 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
81863 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
81864 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
81865 - atomic_inc(&rdma_stat_recv);
81866 + atomic_inc_unchecked(&rdma_stat_recv);
81867
81868 /* Build up the XDR from the receive buffers. */
81869 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
81870 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
81871 index 42eb7ba..c887c45 100644
81872 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
81873 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
81874 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
81875 write_wr.wr.rdma.remote_addr = to;
81876
81877 /* Post It */
81878 - atomic_inc(&rdma_stat_write);
81879 + atomic_inc_unchecked(&rdma_stat_write);
81880 if (svc_rdma_send(xprt, &write_wr))
81881 goto err;
81882 return 0;
81883 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
81884 index 62e4f9b..dd3f2d7 100644
81885 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
81886 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
81887 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
81888 return;
81889
81890 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
81891 - atomic_inc(&rdma_stat_rq_poll);
81892 + atomic_inc_unchecked(&rdma_stat_rq_poll);
81893
81894 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
81895 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
81896 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
81897 }
81898
81899 if (ctxt)
81900 - atomic_inc(&rdma_stat_rq_prod);
81901 + atomic_inc_unchecked(&rdma_stat_rq_prod);
81902
81903 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
81904 /*
81905 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
81906 return;
81907
81908 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
81909 - atomic_inc(&rdma_stat_sq_poll);
81910 + atomic_inc_unchecked(&rdma_stat_sq_poll);
81911 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
81912 if (wc.status != IB_WC_SUCCESS)
81913 /* Close the transport */
81914 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
81915 }
81916
81917 if (ctxt)
81918 - atomic_inc(&rdma_stat_sq_prod);
81919 + atomic_inc_unchecked(&rdma_stat_sq_prod);
81920 }
81921
81922 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
81923 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
81924 spin_lock_bh(&xprt->sc_lock);
81925 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
81926 spin_unlock_bh(&xprt->sc_lock);
81927 - atomic_inc(&rdma_stat_sq_starve);
81928 + atomic_inc_unchecked(&rdma_stat_sq_starve);
81929
81930 /* See if we can opportunistically reap SQ WR to make room */
81931 sq_cq_reap(xprt);
81932 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
81933 index e3a6e37..be2ea77 100644
81934 --- a/net/sysctl_net.c
81935 +++ b/net/sysctl_net.c
81936 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
81937 struct ctl_table *table)
81938 {
81939 /* Allow network administrator to have same access as root. */
81940 - if (capable(CAP_NET_ADMIN)) {
81941 + if (capable_nolog(CAP_NET_ADMIN)) {
81942 int mode = (table->mode >> 6) & 7;
81943 return (mode << 6) | (mode << 3) | mode;
81944 }
81945 diff --git a/net/tipc/link.c b/net/tipc/link.c
81946 index a79c755..eca357d 100644
81947 --- a/net/tipc/link.c
81948 +++ b/net/tipc/link.c
81949 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
81950 struct tipc_msg fragm_hdr;
81951 struct sk_buff *buf, *buf_chain, *prev;
81952 u32 fragm_crs, fragm_rest, hsz, sect_rest;
81953 - const unchar *sect_crs;
81954 + const unchar __user *sect_crs;
81955 int curr_sect;
81956 u32 fragm_no;
81957
81958 @@ -1210,7 +1210,7 @@ again:
81959
81960 if (!sect_rest) {
81961 sect_rest = msg_sect[++curr_sect].iov_len;
81962 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
81963 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
81964 }
81965
81966 if (sect_rest < fragm_rest)
81967 @@ -1229,7 +1229,7 @@ error:
81968 }
81969 } else
81970 skb_copy_to_linear_data_offset(buf, fragm_crs,
81971 - sect_crs, sz);
81972 + (const void __force_kernel *)sect_crs, sz);
81973 sect_crs += sz;
81974 sect_rest -= sz;
81975 fragm_crs += sz;
81976 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
81977 index f2db8a8..9245aa4 100644
81978 --- a/net/tipc/msg.c
81979 +++ b/net/tipc/msg.c
81980 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
81981 msg_sect[cnt].iov_len);
81982 else
81983 skb_copy_to_linear_data_offset(*buf, pos,
81984 - msg_sect[cnt].iov_base,
81985 + (const void __force_kernel *)msg_sect[cnt].iov_base,
81986 msg_sect[cnt].iov_len);
81987 pos += msg_sect[cnt].iov_len;
81988 }
81989 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
81990 index 0f7d0d0..00f89bf 100644
81991 --- a/net/tipc/subscr.c
81992 +++ b/net/tipc/subscr.c
81993 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
81994 {
81995 struct iovec msg_sect;
81996
81997 - msg_sect.iov_base = (void *)&sub->evt;
81998 + msg_sect.iov_base = (void __force_user *)&sub->evt;
81999 msg_sect.iov_len = sizeof(struct tipc_event);
82000
82001 sub->evt.event = htohl(event, sub->swap);
82002 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82003 index 5b5c876..3127bf7 100644
82004 --- a/net/unix/af_unix.c
82005 +++ b/net/unix/af_unix.c
82006 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
82007 err = -ECONNREFUSED;
82008 if (!S_ISSOCK(inode->i_mode))
82009 goto put_fail;
82010 +
82011 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82012 + err = -EACCES;
82013 + goto put_fail;
82014 + }
82015 +
82016 u = unix_find_socket_byinode(inode);
82017 if (!u)
82018 goto put_fail;
82019 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
82020 if (u) {
82021 struct dentry *dentry;
82022 dentry = unix_sk(u)->path.dentry;
82023 +
82024 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
82025 + err = -EPERM;
82026 + sock_put(u);
82027 + goto fail;
82028 + }
82029 +
82030 if (dentry)
82031 touch_atime(&unix_sk(u)->path);
82032 } else
82033 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
82034 */
82035 err = security_path_mknod(&path, dentry, mode, 0);
82036 if (!err) {
82037 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
82038 + err = -EACCES;
82039 + goto out;
82040 + }
82041 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
82042 if (!err) {
82043 res->mnt = mntget(path.mnt);
82044 res->dentry = dget(dentry);
82045 + gr_handle_create(dentry, path.mnt);
82046 }
82047 }
82048 +out:
82049 done_path_create(&path, dentry);
82050 return err;
82051 }
82052 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
82053 index c8717c1..08539f5 100644
82054 --- a/net/wireless/wext-core.c
82055 +++ b/net/wireless/wext-core.c
82056 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82057 */
82058
82059 /* Support for very large requests */
82060 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
82061 - (user_length > descr->max_tokens)) {
82062 + if (user_length > descr->max_tokens) {
82063 /* Allow userspace to GET more than max so
82064 * we can support any size GET requests.
82065 * There is still a limit : -ENOMEM.
82066 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82067 }
82068 }
82069
82070 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
82071 - /*
82072 - * If this is a GET, but not NOMAX, it means that the extra
82073 - * data is not bounded by userspace, but by max_tokens. Thus
82074 - * set the length to max_tokens. This matches the extra data
82075 - * allocation.
82076 - * The driver should fill it with the number of tokens it
82077 - * provided, and it may check iwp->length rather than having
82078 - * knowledge of max_tokens. If the driver doesn't change the
82079 - * iwp->length, this ioctl just copies back max_token tokens
82080 - * filled with zeroes. Hopefully the driver isn't claiming
82081 - * them to be valid data.
82082 - */
82083 - iwp->length = descr->max_tokens;
82084 - }
82085 -
82086 err = handler(dev, info, (union iwreq_data *) iwp, extra);
82087
82088 iwp->length += essid_compat;
82089 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
82090 index 41eabc4..8d4e6d6 100644
82091 --- a/net/xfrm/xfrm_policy.c
82092 +++ b/net/xfrm/xfrm_policy.c
82093 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
82094 {
82095 policy->walk.dead = 1;
82096
82097 - atomic_inc(&policy->genid);
82098 + atomic_inc_unchecked(&policy->genid);
82099
82100 if (del_timer(&policy->timer))
82101 xfrm_pol_put(policy);
82102 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
82103 hlist_add_head(&policy->bydst, chain);
82104 xfrm_pol_hold(policy);
82105 net->xfrm.policy_count[dir]++;
82106 - atomic_inc(&flow_cache_genid);
82107 + atomic_inc_unchecked(&flow_cache_genid);
82108 rt_genid_bump(net);
82109 if (delpol)
82110 __xfrm_policy_unlink(delpol, dir);
82111 @@ -1550,7 +1550,7 @@ free_dst:
82112 goto out;
82113 }
82114
82115 -static int inline
82116 +static inline int
82117 xfrm_dst_alloc_copy(void **target, const void *src, int size)
82118 {
82119 if (!*target) {
82120 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
82121 return 0;
82122 }
82123
82124 -static int inline
82125 +static inline int
82126 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82127 {
82128 #ifdef CONFIG_XFRM_SUB_POLICY
82129 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82130 #endif
82131 }
82132
82133 -static int inline
82134 +static inline int
82135 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
82136 {
82137 #ifdef CONFIG_XFRM_SUB_POLICY
82138 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
82139
82140 xdst->num_pols = num_pols;
82141 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
82142 - xdst->policy_genid = atomic_read(&pols[0]->genid);
82143 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
82144
82145 return xdst;
82146 }
82147 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
82148 if (xdst->xfrm_genid != dst->xfrm->genid)
82149 return 0;
82150 if (xdst->num_pols > 0 &&
82151 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
82152 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
82153 return 0;
82154
82155 mtu = dst_mtu(dst->child);
82156 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
82157 sizeof(pol->xfrm_vec[i].saddr));
82158 pol->xfrm_vec[i].encap_family = mp->new_family;
82159 /* flush bundles */
82160 - atomic_inc(&pol->genid);
82161 + atomic_inc_unchecked(&pol->genid);
82162 }
82163 }
82164
82165 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
82166 index 3459692..eefb515 100644
82167 --- a/net/xfrm/xfrm_state.c
82168 +++ b/net/xfrm/xfrm_state.c
82169 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
82170 if (!try_module_get(afinfo->owner))
82171 goto out;
82172
82173 - mode->afinfo = afinfo;
82174 + pax_open_kernel();
82175 + *(void **)&mode->afinfo = afinfo;
82176 + pax_close_kernel();
82177 modemap[mode->encap] = mode;
82178 err = 0;
82179
82180 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
82181 index 0e801c3..5c8ad3b 100644
82182 --- a/scripts/Makefile.build
82183 +++ b/scripts/Makefile.build
82184 @@ -111,7 +111,7 @@ endif
82185 endif
82186
82187 # Do not include host rules unless needed
82188 -ifneq ($(hostprogs-y)$(hostprogs-m),)
82189 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
82190 include scripts/Makefile.host
82191 endif
82192
82193 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
82194 index 686cb0d..9d653bf 100644
82195 --- a/scripts/Makefile.clean
82196 +++ b/scripts/Makefile.clean
82197 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
82198 __clean-files := $(extra-y) $(always) \
82199 $(targets) $(clean-files) \
82200 $(host-progs) \
82201 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
82202 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
82203 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
82204
82205 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
82206
82207 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
82208 index 1ac414f..38575f7 100644
82209 --- a/scripts/Makefile.host
82210 +++ b/scripts/Makefile.host
82211 @@ -31,6 +31,8 @@
82212 # Note: Shared libraries consisting of C++ files are not supported
82213
82214 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
82215 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
82216 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
82217
82218 # C code
82219 # Executables compiled from a single .c file
82220 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
82221 # Shared libaries (only .c supported)
82222 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
82223 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
82224 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
82225 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
82226 # Remove .so files from "xxx-objs"
82227 host-cobjs := $(filter-out %.so,$(host-cobjs))
82228 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
82229
82230 -#Object (.o) files used by the shared libaries
82231 +# Object (.o) files used by the shared libaries
82232 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
82233 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
82234
82235 # output directory for programs/.o files
82236 # hostprogs-y := tools/build may have been specified. Retrieve directory
82237 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82238 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
82239 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
82240 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
82241 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
82242 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
82243 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
82244 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
82245
82246 obj-dirs += $(host-objdirs)
82247 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
82248 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
82249 $(call if_changed_dep,host-cshobjs)
82250
82251 +# Compile .c file, create position independent .o file
82252 +# host-cxxshobjs -> .o
82253 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
82254 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
82255 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
82256 + $(call if_changed_dep,host-cxxshobjs)
82257 +
82258 # Link a shared library, based on position independent .o files
82259 # *.o -> .so shared library (host-cshlib)
82260 quiet_cmd_host-cshlib = HOSTLLD -shared $@
82261 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
82262 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
82263 $(call if_changed,host-cshlib)
82264
82265 +# Link a shared library, based on position independent .o files
82266 +# *.o -> .so shared library (host-cxxshlib)
82267 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
82268 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
82269 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
82270 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
82271 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
82272 + $(call if_changed,host-cxxshlib)
82273 +
82274 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
82275 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
82276 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
82277
82278 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
82279 index cb1f50c..cef2a7c 100644
82280 --- a/scripts/basic/fixdep.c
82281 +++ b/scripts/basic/fixdep.c
82282 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
82283 /*
82284 * Lookup a value in the configuration string.
82285 */
82286 -static int is_defined_config(const char *name, int len, unsigned int hash)
82287 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
82288 {
82289 struct item *aux;
82290
82291 @@ -211,10 +211,10 @@ static void clear_config(void)
82292 /*
82293 * Record the use of a CONFIG_* word.
82294 */
82295 -static void use_config(const char *m, int slen)
82296 +static void use_config(const char *m, unsigned int slen)
82297 {
82298 unsigned int hash = strhash(m, slen);
82299 - int c, i;
82300 + unsigned int c, i;
82301
82302 if (is_defined_config(m, slen, hash))
82303 return;
82304 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
82305
82306 static void parse_config_file(const char *map, size_t len)
82307 {
82308 - const int *end = (const int *) (map + len);
82309 + const unsigned int *end = (const unsigned int *) (map + len);
82310 /* start at +1, so that p can never be < map */
82311 - const int *m = (const int *) map + 1;
82312 + const unsigned int *m = (const unsigned int *) map + 1;
82313 const char *p, *q;
82314
82315 for (; m < end; m++) {
82316 @@ -406,7 +406,7 @@ static void print_deps(void)
82317 static void traps(void)
82318 {
82319 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
82320 - int *p = (int *)test;
82321 + unsigned int *p = (unsigned int *)test;
82322
82323 if (*p != INT_CONF) {
82324 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
82325 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
82326 new file mode 100644
82327 index 0000000..008ac1a
82328 --- /dev/null
82329 +++ b/scripts/gcc-plugin.sh
82330 @@ -0,0 +1,17 @@
82331 +#!/bin/bash
82332 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
82333 +#include "gcc-plugin.h"
82334 +#include "tree.h"
82335 +#include "tm.h"
82336 +#include "rtl.h"
82337 +#ifdef ENABLE_BUILD_WITH_CXX
82338 +#warning $2
82339 +#else
82340 +#warning $1
82341 +#endif
82342 +EOF`
82343 +if [ $? -eq 0 ]
82344 +then
82345 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
82346 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
82347 +fi
82348 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
82349 index b3d907e..a4782ab 100644
82350 --- a/scripts/link-vmlinux.sh
82351 +++ b/scripts/link-vmlinux.sh
82352 @@ -152,7 +152,7 @@ else
82353 fi;
82354
82355 # final build of init/
82356 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
82357 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
82358
82359 kallsymso=""
82360 kallsyms_vmlinux=""
82361 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
82362 index df4fc23..0ea719d 100644
82363 --- a/scripts/mod/file2alias.c
82364 +++ b/scripts/mod/file2alias.c
82365 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
82366 unsigned long size, unsigned long id_size,
82367 void *symval)
82368 {
82369 - int i;
82370 + unsigned int i;
82371
82372 if (size % id_size || size < id_size) {
82373 if (cross_build != 0)
82374 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
82375 /* USB is special because the bcdDevice can be matched against a numeric range */
82376 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
82377 static void do_usb_entry(struct usb_device_id *id,
82378 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
82379 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
82380 unsigned char range_lo, unsigned char range_hi,
82381 unsigned char max, struct module *mod)
82382 {
82383 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
82384 {
82385 unsigned int devlo, devhi;
82386 unsigned char chi, clo, max;
82387 - int ndigits;
82388 + unsigned int ndigits;
82389
82390 id->match_flags = TO_NATIVE(id->match_flags);
82391 id->idVendor = TO_NATIVE(id->idVendor);
82392 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
82393 for (i = 0; i < count; i++) {
82394 const char *id = (char *)devs[i].id;
82395 char acpi_id[sizeof(devs[0].id)];
82396 - int j;
82397 + unsigned int j;
82398
82399 buf_printf(&mod->dev_table_buf,
82400 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82401 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82402
82403 for (j = 0; j < PNP_MAX_DEVICES; j++) {
82404 const char *id = (char *)card->devs[j].id;
82405 - int i2, j2;
82406 + unsigned int i2, j2;
82407 int dup = 0;
82408
82409 if (!id[0])
82410 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82411 /* add an individual alias for every device entry */
82412 if (!dup) {
82413 char acpi_id[sizeof(card->devs[0].id)];
82414 - int k;
82415 + unsigned int k;
82416
82417 buf_printf(&mod->dev_table_buf,
82418 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82419 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
82420 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
82421 char *alias)
82422 {
82423 - int i, j;
82424 + unsigned int i, j;
82425
82426 sprintf(alias, "dmi*");
82427
82428 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
82429 index 0d93856..e828363 100644
82430 --- a/scripts/mod/modpost.c
82431 +++ b/scripts/mod/modpost.c
82432 @@ -933,6 +933,7 @@ enum mismatch {
82433 ANY_INIT_TO_ANY_EXIT,
82434 ANY_EXIT_TO_ANY_INIT,
82435 EXPORT_TO_INIT_EXIT,
82436 + DATA_TO_TEXT
82437 };
82438
82439 struct sectioncheck {
82440 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
82441 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
82442 .mismatch = EXPORT_TO_INIT_EXIT,
82443 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
82444 +},
82445 +/* Do not reference code from writable data */
82446 +{
82447 + .fromsec = { DATA_SECTIONS, NULL },
82448 + .tosec = { TEXT_SECTIONS, NULL },
82449 + .mismatch = DATA_TO_TEXT
82450 }
82451 };
82452
82453 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
82454 continue;
82455 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
82456 continue;
82457 - if (sym->st_value == addr)
82458 - return sym;
82459 /* Find a symbol nearby - addr are maybe negative */
82460 d = sym->st_value - addr;
82461 + if (d == 0)
82462 + return sym;
82463 if (d < 0)
82464 d = addr - sym->st_value;
82465 if (d < distance) {
82466 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
82467 tosym, prl_to, prl_to, tosym);
82468 free(prl_to);
82469 break;
82470 + case DATA_TO_TEXT:
82471 +#if 0
82472 + fprintf(stderr,
82473 + "The %s %s:%s references\n"
82474 + "the %s %s:%s%s\n",
82475 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82476 +#endif
82477 + break;
82478 }
82479 fprintf(stderr, "\n");
82480 }
82481 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
82482 static void check_sec_ref(struct module *mod, const char *modname,
82483 struct elf_info *elf)
82484 {
82485 - int i;
82486 + unsigned int i;
82487 Elf_Shdr *sechdrs = elf->sechdrs;
82488
82489 /* Walk through all sections */
82490 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
82491 va_end(ap);
82492 }
82493
82494 -void buf_write(struct buffer *buf, const char *s, int len)
82495 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
82496 {
82497 if (buf->size - buf->pos < len) {
82498 buf->size += len + SZ;
82499 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
82500 if (fstat(fileno(file), &st) < 0)
82501 goto close_write;
82502
82503 - if (st.st_size != b->pos)
82504 + if (st.st_size != (off_t)b->pos)
82505 goto close_write;
82506
82507 tmp = NOFAIL(malloc(b->pos));
82508 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
82509 index 51207e4..f7d603d 100644
82510 --- a/scripts/mod/modpost.h
82511 +++ b/scripts/mod/modpost.h
82512 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
82513
82514 struct buffer {
82515 char *p;
82516 - int pos;
82517 - int size;
82518 + unsigned int pos;
82519 + unsigned int size;
82520 };
82521
82522 void __attribute__((format(printf, 2, 3)))
82523 buf_printf(struct buffer *buf, const char *fmt, ...);
82524
82525 void
82526 -buf_write(struct buffer *buf, const char *s, int len);
82527 +buf_write(struct buffer *buf, const char *s, unsigned int len);
82528
82529 struct module {
82530 struct module *next;
82531 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
82532 index 9dfcd6d..099068e 100644
82533 --- a/scripts/mod/sumversion.c
82534 +++ b/scripts/mod/sumversion.c
82535 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
82536 goto out;
82537 }
82538
82539 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
82540 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
82541 warn("writing sum in %s failed: %s\n",
82542 filename, strerror(errno));
82543 goto out;
82544 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
82545 index 5c11312..72742b5 100644
82546 --- a/scripts/pnmtologo.c
82547 +++ b/scripts/pnmtologo.c
82548 @@ -237,14 +237,14 @@ static void write_header(void)
82549 fprintf(out, " * Linux logo %s\n", logoname);
82550 fputs(" */\n\n", out);
82551 fputs("#include <linux/linux_logo.h>\n\n", out);
82552 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
82553 + fprintf(out, "static unsigned char %s_data[] = {\n",
82554 logoname);
82555 }
82556
82557 static void write_footer(void)
82558 {
82559 fputs("\n};\n\n", out);
82560 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
82561 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
82562 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
82563 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
82564 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
82565 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
82566 fputs("\n};\n\n", out);
82567
82568 /* write logo clut */
82569 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
82570 + fprintf(out, "static unsigned char %s_clut[] = {\n",
82571 logoname);
82572 write_hex_cnt = 0;
82573 for (i = 0; i < logo_clutsize; i++) {
82574 diff --git a/security/Kconfig b/security/Kconfig
82575 index e9c6ac7..a9bcf23 100644
82576 --- a/security/Kconfig
82577 +++ b/security/Kconfig
82578 @@ -4,6 +4,896 @@
82579
82580 menu "Security options"
82581
82582 +menu "Grsecurity"
82583 +
82584 + config ARCH_TRACK_EXEC_LIMIT
82585 + bool
82586 +
82587 + config PAX_KERNEXEC_PLUGIN
82588 + bool
82589 +
82590 + config PAX_PER_CPU_PGD
82591 + bool
82592 +
82593 + config TASK_SIZE_MAX_SHIFT
82594 + int
82595 + depends on X86_64
82596 + default 47 if !PAX_PER_CPU_PGD
82597 + default 42 if PAX_PER_CPU_PGD
82598 +
82599 + config PAX_ENABLE_PAE
82600 + bool
82601 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
82602 +
82603 + config PAX_USERCOPY_SLABS
82604 + bool
82605 +
82606 +config GRKERNSEC
82607 + bool "Grsecurity"
82608 + select CRYPTO
82609 + select CRYPTO_SHA256
82610 + select PROC_FS
82611 + select STOP_MACHINE
82612 + help
82613 + If you say Y here, you will be able to configure many features
82614 + that will enhance the security of your system. It is highly
82615 + recommended that you say Y here and read through the help
82616 + for each option so that you fully understand the features and
82617 + can evaluate their usefulness for your machine.
82618 +
82619 +choice
82620 + prompt "Configuration Method"
82621 + depends on GRKERNSEC
82622 + default GRKERNSEC_CONFIG_CUSTOM
82623 + help
82624 +
82625 +config GRKERNSEC_CONFIG_AUTO
82626 + bool "Automatic"
82627 + help
82628 + If you choose this configuration method, you'll be able to answer a small
82629 + number of simple questions about how you plan to use this kernel.
82630 + The settings of grsecurity and PaX will be automatically configured for
82631 + the highest commonly-used settings within the provided constraints.
82632 +
82633 + If you require additional configuration, custom changes can still be made
82634 + from the "custom configuration" menu.
82635 +
82636 +config GRKERNSEC_CONFIG_CUSTOM
82637 + bool "Custom"
82638 + help
82639 + If you choose this configuration method, you'll be able to configure all
82640 + grsecurity and PaX settings manually. Via this method, no options are
82641 + automatically enabled.
82642 +
82643 +endchoice
82644 +
82645 +choice
82646 + prompt "Usage Type"
82647 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82648 + default GRKERNSEC_CONFIG_SERVER
82649 + help
82650 +
82651 +config GRKERNSEC_CONFIG_SERVER
82652 + bool "Server"
82653 + help
82654 + Choose this option if you plan to use this kernel on a server.
82655 +
82656 +config GRKERNSEC_CONFIG_DESKTOP
82657 + bool "Desktop"
82658 + help
82659 + Choose this option if you plan to use this kernel on a desktop.
82660 +
82661 +endchoice
82662 +
82663 +choice
82664 + prompt "Virtualization Type"
82665 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
82666 + default GRKERNSEC_CONFIG_VIRT_NONE
82667 + help
82668 +
82669 +config GRKERNSEC_CONFIG_VIRT_NONE
82670 + bool "None"
82671 + help
82672 + Choose this option if this kernel will be run on bare metal.
82673 +
82674 +config GRKERNSEC_CONFIG_VIRT_GUEST
82675 + bool "Guest"
82676 + help
82677 + Choose this option if this kernel will be run as a VM guest.
82678 +
82679 +config GRKERNSEC_CONFIG_VIRT_HOST
82680 + bool "Host"
82681 + help
82682 + Choose this option if this kernel will be run as a VM host.
82683 +
82684 +endchoice
82685 +
82686 +choice
82687 + prompt "Virtualization Hardware"
82688 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82689 + help
82690 +
82691 +config GRKERNSEC_CONFIG_VIRT_EPT
82692 + bool "EPT/RVI Processor Support"
82693 + depends on X86
82694 + help
82695 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
82696 + hardware virtualization. This allows for additional kernel hardening protections
82697 + to operate without additional performance impact.
82698 +
82699 + To see if your Intel processor supports EPT, see:
82700 + http://ark.intel.com/Products/VirtualizationTechnology
82701 + (Most Core i3/5/7 support EPT)
82702 +
82703 + To see if your AMD processor supports RVI, see:
82704 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
82705 +
82706 +config GRKERNSEC_CONFIG_VIRT_SOFT
82707 + bool "First-gen/No Hardware Virtualization"
82708 + help
82709 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
82710 + support hardware virtualization or doesn't support the EPT/RVI extensions.
82711 +
82712 +endchoice
82713 +
82714 +choice
82715 + prompt "Virtualization Software"
82716 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82717 + help
82718 +
82719 +config GRKERNSEC_CONFIG_VIRT_XEN
82720 + bool "Xen"
82721 + help
82722 + Choose this option if this kernel is running as a Xen guest or host.
82723 +
82724 +config GRKERNSEC_CONFIG_VIRT_VMWARE
82725 + bool "VMWare"
82726 + help
82727 + Choose this option if this kernel is running as a VMWare guest or host.
82728 +
82729 +config GRKERNSEC_CONFIG_VIRT_KVM
82730 + bool "KVM"
82731 + help
82732 + Choose this option if this kernel is running as a KVM guest or host.
82733 +
82734 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
82735 + bool "VirtualBox"
82736 + help
82737 + Choose this option if this kernel is running as a VirtualBox guest or host.
82738 +
82739 +endchoice
82740 +
82741 +choice
82742 + prompt "Required Priorities"
82743 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82744 + default GRKERNSEC_CONFIG_PRIORITY_PERF
82745 + help
82746 +
82747 +config GRKERNSEC_CONFIG_PRIORITY_PERF
82748 + bool "Performance"
82749 + help
82750 + Choose this option if performance is of highest priority for this deployment
82751 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
82752 + and freed memory sanitizing will be disabled.
82753 +
82754 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
82755 + bool "Security"
82756 + help
82757 + Choose this option if security is of highest priority for this deployment of
82758 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
82759 + be enabled for this kernel. In a worst-case scenario, these features can
82760 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
82761 +
82762 +endchoice
82763 +
82764 +menu "Default Special Groups"
82765 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82766 +
82767 +config GRKERNSEC_PROC_GID
82768 + int "GID exempted from /proc restrictions"
82769 + default 1001
82770 + help
82771 + Setting this GID determines which group will be exempted from
82772 + grsecurity's /proc restrictions, allowing users of the specified
82773 + group to view network statistics and the existence of other users'
82774 + processes on the system. This GID may also be chosen at boot time
82775 + via "grsec_proc_gid=" on the kernel commandline.
82776 +
82777 +config GRKERNSEC_TPE_UNTRUSTED_GID
82778 + int "GID for TPE-untrusted users"
82779 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
82780 + default 1005
82781 + help
82782 + Setting this GID determines which group untrusted users should
82783 + be added to. These users will be placed under grsecurity's Trusted Path
82784 + Execution mechanism, preventing them from executing their own binaries.
82785 + The users will only be able to execute binaries in directories owned and
82786 + writable only by the root user. If the sysctl option is enabled, a sysctl
82787 + option with name "tpe_gid" is created.
82788 +
82789 +config GRKERNSEC_TPE_TRUSTED_GID
82790 + int "GID for TPE-trusted users"
82791 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
82792 + default 1005
82793 + help
82794 + Setting this GID determines what group TPE restrictions will be
82795 + *disabled* for. If the sysctl option is enabled, a sysctl option
82796 + with name "tpe_gid" is created.
82797 +
82798 +config GRKERNSEC_SYMLINKOWN_GID
82799 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
82800 + depends on GRKERNSEC_CONFIG_SERVER
82801 + default 1006
82802 + help
82803 + Setting this GID determines what group kernel-enforced
82804 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
82805 + is enabled, a sysctl option with name "symlinkown_gid" is created.
82806 +
82807 +
82808 +endmenu
82809 +
82810 +menu "Customize Configuration"
82811 +depends on GRKERNSEC
82812 +
82813 +menu "PaX"
82814 +
82815 +config PAX
82816 + bool "Enable various PaX features"
82817 + default y if GRKERNSEC_CONFIG_AUTO
82818 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
82819 + help
82820 + This allows you to enable various PaX features. PaX adds
82821 + intrusion prevention mechanisms to the kernel that reduce
82822 + the risks posed by exploitable memory corruption bugs.
82823 +
82824 +menu "PaX Control"
82825 + depends on PAX
82826 +
82827 +config PAX_SOFTMODE
82828 + bool 'Support soft mode'
82829 + help
82830 + Enabling this option will allow you to run PaX in soft mode, that
82831 + is, PaX features will not be enforced by default, only on executables
82832 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
82833 + support as they are the only way to mark executables for soft mode use.
82834 +
82835 + Soft mode can be activated by using the "pax_softmode=1" kernel command
82836 + line option on boot. Furthermore you can control various PaX features
82837 + at runtime via the entries in /proc/sys/kernel/pax.
82838 +
82839 +config PAX_EI_PAX
82840 + bool 'Use legacy ELF header marking'
82841 + default y if GRKERNSEC_CONFIG_AUTO
82842 + help
82843 + Enabling this option will allow you to control PaX features on
82844 + a per executable basis via the 'chpax' utility available at
82845 + http://pax.grsecurity.net/. The control flags will be read from
82846 + an otherwise reserved part of the ELF header. This marking has
82847 + numerous drawbacks (no support for soft-mode, toolchain does not
82848 + know about the non-standard use of the ELF header) therefore it
82849 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
82850 + support.
82851 +
82852 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
82853 + support as well, they will override the legacy EI_PAX marks.
82854 +
82855 + If you enable none of the marking options then all applications
82856 + will run with PaX enabled on them by default.
82857 +
82858 +config PAX_PT_PAX_FLAGS
82859 + bool 'Use ELF program header marking'
82860 + default y if GRKERNSEC_CONFIG_AUTO
82861 + help
82862 + Enabling this option will allow you to control PaX features on
82863 + a per executable basis via the 'paxctl' utility available at
82864 + http://pax.grsecurity.net/. The control flags will be read from
82865 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
82866 + has the benefits of supporting both soft mode and being fully
82867 + integrated into the toolchain (the binutils patch is available
82868 + from http://pax.grsecurity.net).
82869 +
82870 + Note that if you enable the legacy EI_PAX marking support as well,
82871 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
82872 +
82873 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
82874 + must make sure that the marks are the same if a binary has both marks.
82875 +
82876 + If you enable none of the marking options then all applications
82877 + will run with PaX enabled on them by default.
82878 +
82879 +config PAX_XATTR_PAX_FLAGS
82880 + bool 'Use filesystem extended attributes marking'
82881 + default y if GRKERNSEC_CONFIG_AUTO
82882 + select CIFS_XATTR if CIFS
82883 + select EXT2_FS_XATTR if EXT2_FS
82884 + select EXT3_FS_XATTR if EXT3_FS
82885 + select EXT4_FS_XATTR if EXT4_FS
82886 + select JFFS2_FS_XATTR if JFFS2_FS
82887 + select REISERFS_FS_XATTR if REISERFS_FS
82888 + select SQUASHFS_XATTR if SQUASHFS
82889 + select TMPFS_XATTR if TMPFS
82890 + select UBIFS_FS_XATTR if UBIFS_FS
82891 + help
82892 + Enabling this option will allow you to control PaX features on
82893 + a per executable basis via the 'setfattr' utility. The control
82894 + flags will be read from the user.pax.flags extended attribute of
82895 + the file. This marking has the benefit of supporting binary-only
82896 + applications that self-check themselves (e.g., skype) and would
82897 + not tolerate chpax/paxctl changes. The main drawback is that
82898 + extended attributes are not supported by some filesystems (e.g.,
82899 + isofs, udf, vfat) so copying files through such filesystems will
82900 + lose the extended attributes and these PaX markings.
82901 +
82902 + Note that if you enable the legacy EI_PAX marking support as well,
82903 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
82904 +
82905 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
82906 + must make sure that the marks are the same if a binary has both marks.
82907 +
82908 + If you enable none of the marking options then all applications
82909 + will run with PaX enabled on them by default.
82910 +
82911 +choice
82912 + prompt 'MAC system integration'
82913 + default PAX_HAVE_ACL_FLAGS
82914 + help
82915 + Mandatory Access Control systems have the option of controlling
82916 + PaX flags on a per executable basis, choose the method supported
82917 + by your particular system.
82918 +
82919 + - "none": if your MAC system does not interact with PaX,
82920 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
82921 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
82922 +
82923 + NOTE: this option is for developers/integrators only.
82924 +
82925 + config PAX_NO_ACL_FLAGS
82926 + bool 'none'
82927 +
82928 + config PAX_HAVE_ACL_FLAGS
82929 + bool 'direct'
82930 +
82931 + config PAX_HOOK_ACL_FLAGS
82932 + bool 'hook'
82933 +endchoice
82934 +
82935 +endmenu
82936 +
82937 +menu "Non-executable pages"
82938 + depends on PAX
82939 +
82940 +config PAX_NOEXEC
82941 + bool "Enforce non-executable pages"
82942 + default y if GRKERNSEC_CONFIG_AUTO
82943 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
82944 + help
82945 + By design some architectures do not allow for protecting memory
82946 + pages against execution or even if they do, Linux does not make
82947 + use of this feature. In practice this means that if a page is
82948 + readable (such as the stack or heap) it is also executable.
82949 +
82950 + There is a well known exploit technique that makes use of this
82951 + fact and a common programming mistake where an attacker can
82952 + introduce code of his choice somewhere in the attacked program's
82953 + memory (typically the stack or the heap) and then execute it.
82954 +
82955 + If the attacked program was running with different (typically
82956 + higher) privileges than that of the attacker, then he can elevate
82957 + his own privilege level (e.g. get a root shell, write to files for
82958 + which he does not have write access to, etc).
82959 +
82960 + Enabling this option will let you choose from various features
82961 + that prevent the injection and execution of 'foreign' code in
82962 + a program.
82963 +
82964 + This will also break programs that rely on the old behaviour and
82965 + expect that dynamically allocated memory via the malloc() family
82966 + of functions is executable (which it is not). Notable examples
82967 + are the XFree86 4.x server, the java runtime and wine.
82968 +
82969 +config PAX_PAGEEXEC
82970 + bool "Paging based non-executable pages"
82971 + default y if GRKERNSEC_CONFIG_AUTO
82972 + 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)
82973 + select S390_SWITCH_AMODE if S390
82974 + select S390_EXEC_PROTECT if S390
82975 + select ARCH_TRACK_EXEC_LIMIT if X86_32
82976 + help
82977 + This implementation is based on the paging feature of the CPU.
82978 + On i386 without hardware non-executable bit support there is a
82979 + variable but usually low performance impact, however on Intel's
82980 + P4 core based CPUs it is very high so you should not enable this
82981 + for kernels meant to be used on such CPUs.
82982 +
82983 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
82984 + with hardware non-executable bit support there is no performance
82985 + impact, on ppc the impact is negligible.
82986 +
82987 + Note that several architectures require various emulations due to
82988 + badly designed userland ABIs, this will cause a performance impact
82989 + but will disappear as soon as userland is fixed. For example, ppc
82990 + userland MUST have been built with secure-plt by a recent toolchain.
82991 +
82992 +config PAX_SEGMEXEC
82993 + bool "Segmentation based non-executable pages"
82994 + default y if GRKERNSEC_CONFIG_AUTO
82995 + depends on PAX_NOEXEC && X86_32
82996 + help
82997 + This implementation is based on the segmentation feature of the
82998 + CPU and has a very small performance impact, however applications
82999 + will be limited to a 1.5 GB address space instead of the normal
83000 + 3 GB.
83001 +
83002 +config PAX_EMUTRAMP
83003 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83004 + default y if PARISC
83005 + help
83006 + There are some programs and libraries that for one reason or
83007 + another attempt to execute special small code snippets from
83008 + non-executable memory pages. Most notable examples are the
83009 + signal handler return code generated by the kernel itself and
83010 + the GCC trampolines.
83011 +
83012 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83013 + such programs will no longer work under your kernel.
83014 +
83015 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83016 + utilities to enable trampoline emulation for the affected programs
83017 + yet still have the protection provided by the non-executable pages.
83018 +
83019 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83020 + your system will not even boot.
83021 +
83022 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83023 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83024 + for the affected files.
83025 +
83026 + NOTE: enabling this feature *may* open up a loophole in the
83027 + protection provided by non-executable pages that an attacker
83028 + could abuse. Therefore the best solution is to not have any
83029 + files on your system that would require this option. This can
83030 + be achieved by not using libc5 (which relies on the kernel
83031 + signal handler return code) and not using or rewriting programs
83032 + that make use of the nested function implementation of GCC.
83033 + Skilled users can just fix GCC itself so that it implements
83034 + nested function calls in a way that does not interfere with PaX.
83035 +
83036 +config PAX_EMUSIGRT
83037 + bool "Automatically emulate sigreturn trampolines"
83038 + depends on PAX_EMUTRAMP && PARISC
83039 + default y
83040 + help
83041 + Enabling this option will have the kernel automatically detect
83042 + and emulate signal return trampolines executing on the stack
83043 + that would otherwise lead to task termination.
83044 +
83045 + This solution is intended as a temporary one for users with
83046 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83047 + Modula-3 runtime, etc) or executables linked to such, basically
83048 + everything that does not specify its own SA_RESTORER function in
83049 + normal executable memory like glibc 2.1+ does.
83050 +
83051 + On parisc you MUST enable this option, otherwise your system will
83052 + not even boot.
83053 +
83054 + NOTE: this feature cannot be disabled on a per executable basis
83055 + and since it *does* open up a loophole in the protection provided
83056 + by non-executable pages, the best solution is to not have any
83057 + files on your system that would require this option.
83058 +
83059 +config PAX_MPROTECT
83060 + bool "Restrict mprotect()"
83061 + default y if GRKERNSEC_CONFIG_AUTO
83062 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83063 + help
83064 + Enabling this option will prevent programs from
83065 + - changing the executable status of memory pages that were
83066 + not originally created as executable,
83067 + - making read-only executable pages writable again,
83068 + - creating executable pages from anonymous memory,
83069 + - making read-only-after-relocations (RELRO) data pages writable again.
83070 +
83071 + You should say Y here to complete the protection provided by
83072 + the enforcement of non-executable pages.
83073 +
83074 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83075 + this feature on a per file basis.
83076 +
83077 +config PAX_MPROTECT_COMPAT
83078 + bool "Use legacy/compat protection demoting (read help)"
83079 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83080 + depends on PAX_MPROTECT
83081 + help
83082 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83083 + by sending the proper error code to the application. For some broken
83084 + userland, this can cause problems with Python or other applications. The
83085 + current implementation however allows for applications like clamav to
83086 + detect if JIT compilation/execution is allowed and to fall back gracefully
83087 + to an interpreter-based mode if it does not. While we encourage everyone
83088 + to use the current implementation as-is and push upstream to fix broken
83089 + userland (note that the RWX logging option can assist with this), in some
83090 + environments this may not be possible. Having to disable MPROTECT
83091 + completely on certain binaries reduces the security benefit of PaX,
83092 + so this option is provided for those environments to revert to the old
83093 + behavior.
83094 +
83095 +config PAX_ELFRELOCS
83096 + bool "Allow ELF text relocations (read help)"
83097 + depends on PAX_MPROTECT
83098 + default n
83099 + help
83100 + Non-executable pages and mprotect() restrictions are effective
83101 + in preventing the introduction of new executable code into an
83102 + attacked task's address space. There remain only two venues
83103 + for this kind of attack: if the attacker can execute already
83104 + existing code in the attacked task then he can either have it
83105 + create and mmap() a file containing his code or have it mmap()
83106 + an already existing ELF library that does not have position
83107 + independent code in it and use mprotect() on it to make it
83108 + writable and copy his code there. While protecting against
83109 + the former approach is beyond PaX, the latter can be prevented
83110 + by having only PIC ELF libraries on one's system (which do not
83111 + need to relocate their code). If you are sure this is your case,
83112 + as is the case with all modern Linux distributions, then leave
83113 + this option disabled. You should say 'n' here.
83114 +
83115 +config PAX_ETEXECRELOCS
83116 + bool "Allow ELF ET_EXEC text relocations"
83117 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83118 + select PAX_ELFRELOCS
83119 + default y
83120 + help
83121 + On some architectures there are incorrectly created applications
83122 + that require text relocations and would not work without enabling
83123 + this option. If you are an alpha, ia64 or parisc user, you should
83124 + enable this option and disable it once you have made sure that
83125 + none of your applications need it.
83126 +
83127 +config PAX_EMUPLT
83128 + bool "Automatically emulate ELF PLT"
83129 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83130 + default y
83131 + help
83132 + Enabling this option will have the kernel automatically detect
83133 + and emulate the Procedure Linkage Table entries in ELF files.
83134 + On some architectures such entries are in writable memory, and
83135 + become non-executable leading to task termination. Therefore
83136 + it is mandatory that you enable this option on alpha, parisc,
83137 + sparc and sparc64, otherwise your system would not even boot.
83138 +
83139 + NOTE: this feature *does* open up a loophole in the protection
83140 + provided by the non-executable pages, therefore the proper
83141 + solution is to modify the toolchain to produce a PLT that does
83142 + not need to be writable.
83143 +
83144 +config PAX_DLRESOLVE
83145 + bool 'Emulate old glibc resolver stub'
83146 + depends on PAX_EMUPLT && SPARC
83147 + default n
83148 + help
83149 + This option is needed if userland has an old glibc (before 2.4)
83150 + that puts a 'save' instruction into the runtime generated resolver
83151 + stub that needs special emulation.
83152 +
83153 +config PAX_KERNEXEC
83154 + bool "Enforce non-executable kernel pages"
83155 + 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))
83156 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83157 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83158 + select PAX_KERNEXEC_PLUGIN if X86_64
83159 + help
83160 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83161 + that is, enabling this option will make it harder to inject
83162 + and execute 'foreign' code in kernel memory itself.
83163 +
83164 +choice
83165 + prompt "Return Address Instrumentation Method"
83166 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83167 + depends on PAX_KERNEXEC_PLUGIN
83168 + help
83169 + Select the method used to instrument function pointer dereferences.
83170 + Note that binary modules cannot be instrumented by this approach.
83171 +
83172 + Note that the implementation requires a gcc with plugin support,
83173 + i.e., gcc 4.5 or newer. You may need to install the supporting
83174 + headers explicitly in addition to the normal gcc package.
83175 +
83176 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83177 + bool "bts"
83178 + help
83179 + This method is compatible with binary only modules but has
83180 + a higher runtime overhead.
83181 +
83182 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83183 + bool "or"
83184 + depends on !PARAVIRT
83185 + help
83186 + This method is incompatible with binary only modules but has
83187 + a lower runtime overhead.
83188 +endchoice
83189 +
83190 +config PAX_KERNEXEC_PLUGIN_METHOD
83191 + string
83192 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83193 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83194 + default ""
83195 +
83196 +config PAX_KERNEXEC_MODULE_TEXT
83197 + int "Minimum amount of memory reserved for module code"
83198 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
83199 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83200 + depends on PAX_KERNEXEC && X86_32 && MODULES
83201 + help
83202 + Due to implementation details the kernel must reserve a fixed
83203 + amount of memory for module code at compile time that cannot be
83204 + changed at runtime. Here you can specify the minimum amount
83205 + in MB that will be reserved. Due to the same implementation
83206 + details this size will always be rounded up to the next 2/4 MB
83207 + boundary (depends on PAE) so the actually available memory for
83208 + module code will usually be more than this minimum.
83209 +
83210 + The default 4 MB should be enough for most users but if you have
83211 + an excessive number of modules (e.g., most distribution configs
83212 + compile many drivers as modules) or use huge modules such as
83213 + nvidia's kernel driver, you will need to adjust this amount.
83214 + A good rule of thumb is to look at your currently loaded kernel
83215 + modules and add up their sizes.
83216 +
83217 +endmenu
83218 +
83219 +menu "Address Space Layout Randomization"
83220 + depends on PAX
83221 +
83222 +config PAX_ASLR
83223 + bool "Address Space Layout Randomization"
83224 + default y if GRKERNSEC_CONFIG_AUTO
83225 + help
83226 + Many if not most exploit techniques rely on the knowledge of
83227 + certain addresses in the attacked program. The following options
83228 + will allow the kernel to apply a certain amount of randomization
83229 + to specific parts of the program thereby forcing an attacker to
83230 + guess them in most cases. Any failed guess will most likely crash
83231 + the attacked program which allows the kernel to detect such attempts
83232 + and react on them. PaX itself provides no reaction mechanisms,
83233 + instead it is strongly encouraged that you make use of Nergal's
83234 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83235 + (http://www.grsecurity.net/) built-in crash detection features or
83236 + develop one yourself.
83237 +
83238 + By saying Y here you can choose to randomize the following areas:
83239 + - top of the task's kernel stack
83240 + - top of the task's userland stack
83241 + - base address for mmap() requests that do not specify one
83242 + (this includes all libraries)
83243 + - base address of the main executable
83244 +
83245 + It is strongly recommended to say Y here as address space layout
83246 + randomization has negligible impact on performance yet it provides
83247 + a very effective protection.
83248 +
83249 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83250 + this feature on a per file basis.
83251 +
83252 +config PAX_RANDKSTACK
83253 + bool "Randomize kernel stack base"
83254 + default y if GRKERNSEC_CONFIG_AUTO
83255 + depends on X86_TSC && X86
83256 + help
83257 + By saying Y here the kernel will randomize every task's kernel
83258 + stack on every system call. This will not only force an attacker
83259 + to guess it but also prevent him from making use of possible
83260 + leaked information about it.
83261 +
83262 + Since the kernel stack is a rather scarce resource, randomization
83263 + may cause unexpected stack overflows, therefore you should very
83264 + carefully test your system. Note that once enabled in the kernel
83265 + configuration, this feature cannot be disabled on a per file basis.
83266 +
83267 +config PAX_RANDUSTACK
83268 + bool "Randomize user stack base"
83269 + default y if GRKERNSEC_CONFIG_AUTO
83270 + depends on PAX_ASLR
83271 + help
83272 + By saying Y here the kernel will randomize every task's userland
83273 + stack. The randomization is done in two steps where the second
83274 + one may apply a big amount of shift to the top of the stack and
83275 + cause problems for programs that want to use lots of memory (more
83276 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83277 + For this reason the second step can be controlled by 'chpax' or
83278 + 'paxctl' on a per file basis.
83279 +
83280 +config PAX_RANDMMAP
83281 + bool "Randomize mmap() base"
83282 + default y if GRKERNSEC_CONFIG_AUTO
83283 + depends on PAX_ASLR
83284 + help
83285 + By saying Y here the kernel will use a randomized base address for
83286 + mmap() requests that do not specify one themselves. As a result
83287 + all dynamically loaded libraries will appear at random addresses
83288 + and therefore be harder to exploit by a technique where an attacker
83289 + attempts to execute library code for his purposes (e.g. spawn a
83290 + shell from an exploited program that is running at an elevated
83291 + privilege level).
83292 +
83293 + Furthermore, if a program is relinked as a dynamic ELF file, its
83294 + base address will be randomized as well, completing the full
83295 + randomization of the address space layout. Attacking such programs
83296 + becomes a guess game. You can find an example of doing this at
83297 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
83298 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
83299 +
83300 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
83301 + feature on a per file basis.
83302 +
83303 +endmenu
83304 +
83305 +menu "Miscellaneous hardening features"
83306 +
83307 +config PAX_MEMORY_SANITIZE
83308 + bool "Sanitize all freed memory"
83309 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83310 + depends on !HIBERNATION
83311 + help
83312 + By saying Y here the kernel will erase memory pages as soon as they
83313 + are freed. This in turn reduces the lifetime of data stored in the
83314 + pages, making it less likely that sensitive information such as
83315 + passwords, cryptographic secrets, etc stay in memory for too long.
83316 +
83317 + This is especially useful for programs whose runtime is short, long
83318 + lived processes and the kernel itself benefit from this as long as
83319 + they operate on whole memory pages and ensure timely freeing of pages
83320 + that may hold sensitive information.
83321 +
83322 + The tradeoff is performance impact, on a single CPU system kernel
83323 + compilation sees a 3% slowdown, other systems and workloads may vary
83324 + and you are advised to test this feature on your expected workload
83325 + before deploying it.
83326 +
83327 + Note that this feature does not protect data stored in live pages,
83328 + e.g., process memory swapped to disk may stay there for a long time.
83329 +
83330 +config PAX_MEMORY_STACKLEAK
83331 + bool "Sanitize kernel stack"
83332 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83333 + depends on X86
83334 + help
83335 + By saying Y here the kernel will erase the kernel stack before it
83336 + returns from a system call. This in turn reduces the information
83337 + that a kernel stack leak bug can reveal.
83338 +
83339 + Note that such a bug can still leak information that was put on
83340 + the stack by the current system call (the one eventually triggering
83341 + the bug) but traces of earlier system calls on the kernel stack
83342 + cannot leak anymore.
83343 +
83344 + The tradeoff is performance impact: on a single CPU system kernel
83345 + compilation sees a 1% slowdown, other systems and workloads may vary
83346 + and you are advised to test this feature on your expected workload
83347 + before deploying it.
83348 +
83349 + Note that the full feature requires a gcc with plugin support,
83350 + i.e., gcc 4.5 or newer. You may need to install the supporting
83351 + headers explicitly in addition to the normal gcc package. Using
83352 + older gcc versions means that functions with large enough stack
83353 + frames may leave uninitialized memory behind that may be exposed
83354 + to a later syscall leaking the stack.
83355 +
83356 +config PAX_MEMORY_UDEREF
83357 + bool "Prevent invalid userland pointer dereference"
83358 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
83359 + depends on X86 && !UML_X86 && !XEN
83360 + select PAX_PER_CPU_PGD if X86_64
83361 + help
83362 + By saying Y here the kernel will be prevented from dereferencing
83363 + userland pointers in contexts where the kernel expects only kernel
83364 + pointers. This is both a useful runtime debugging feature and a
83365 + security measure that prevents exploiting a class of kernel bugs.
83366 +
83367 + The tradeoff is that some virtualization solutions may experience
83368 + a huge slowdown and therefore you should not enable this feature
83369 + for kernels meant to run in such environments. Whether a given VM
83370 + solution is affected or not is best determined by simply trying it
83371 + out, the performance impact will be obvious right on boot as this
83372 + mechanism engages from very early on. A good rule of thumb is that
83373 + VMs running on CPUs without hardware virtualization support (i.e.,
83374 + the majority of IA-32 CPUs) will likely experience the slowdown.
83375 +
83376 +config PAX_REFCOUNT
83377 + bool "Prevent various kernel object reference counter overflows"
83378 + default y if GRKERNSEC_CONFIG_AUTO
83379 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
83380 + help
83381 + By saying Y here the kernel will detect and prevent overflowing
83382 + various (but not all) kinds of object reference counters. Such
83383 + overflows can normally occur due to bugs only and are often, if
83384 + not always, exploitable.
83385 +
83386 + The tradeoff is that data structures protected by an overflowed
83387 + refcount will never be freed and therefore will leak memory. Note
83388 + that this leak also happens even without this protection but in
83389 + that case the overflow can eventually trigger the freeing of the
83390 + data structure while it is still being used elsewhere, resulting
83391 + in the exploitable situation that this feature prevents.
83392 +
83393 + Since this has a negligible performance impact, you should enable
83394 + this feature.
83395 +
83396 +config PAX_USERCOPY
83397 + bool "Harden heap object copies between kernel and userland"
83398 + default y if GRKERNSEC_CONFIG_AUTO
83399 + depends on ARM || IA64 || PPC || SPARC || X86
83400 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
83401 + select PAX_USERCOPY_SLABS
83402 + help
83403 + By saying Y here the kernel will enforce the size of heap objects
83404 + when they are copied in either direction between the kernel and
83405 + userland, even if only a part of the heap object is copied.
83406 +
83407 + Specifically, this checking prevents information leaking from the
83408 + kernel heap during kernel to userland copies (if the kernel heap
83409 + object is otherwise fully initialized) and prevents kernel heap
83410 + overflows during userland to kernel copies.
83411 +
83412 + Note that the current implementation provides the strictest bounds
83413 + checks for the SLUB allocator.
83414 +
83415 + Enabling this option also enables per-slab cache protection against
83416 + data in a given cache being copied into/out of via userland
83417 + accessors. Though the whitelist of regions will be reduced over
83418 + time, it notably protects important data structures like task structs.
83419 +
83420 + If frame pointers are enabled on x86, this option will also restrict
83421 + copies into and out of the kernel stack to local variables within a
83422 + single frame.
83423 +
83424 + Since this has a negligible performance impact, you should enable
83425 + this feature.
83426 +
83427 +config PAX_SIZE_OVERFLOW
83428 + bool "Prevent various integer overflows in function size parameters"
83429 + default y if GRKERNSEC_CONFIG_AUTO
83430 + depends on X86
83431 + help
83432 + By saying Y here the kernel recomputes expressions of function
83433 + arguments marked by a size_overflow attribute with double integer
83434 + precision (DImode/TImode for 32/64 bit integer types).
83435 +
83436 + The recomputed argument is checked against TYPE_MAX and an event
83437 + is logged on overflow and the triggering process is killed.
83438 +
83439 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
83440 +
83441 + Note that the implementation requires a gcc with plugin support,
83442 + i.e., gcc 4.5 or newer. You may need to install the supporting
83443 + headers explicitly in addition to the normal gcc package.
83444 +
83445 +config PAX_LATENT_ENTROPY
83446 + bool "Generate some entropy during boot"
83447 + default y if GRKERNSEC_CONFIG_AUTO
83448 + help
83449 + By saying Y here the kernel will instrument early boot code to
83450 + extract some entropy from both original and artificially created
83451 + program state. This will help especially embedded systems where
83452 + there is little 'natural' source of entropy normally. The cost
83453 + is some slowdown of the boot process.
83454 +
83455 + Note that the implementation requires a gcc with plugin support,
83456 + i.e., gcc 4.5 or newer. You may need to install the supporting
83457 + headers explicitly in addition to the normal gcc package.
83458 +
83459 + Note that entropy extracted this way is not cryptographically
83460 + secure!
83461 +
83462 +endmenu
83463 +
83464 +endmenu
83465 +
83466 +source grsecurity/Kconfig
83467 +
83468 +endmenu
83469 +
83470 +endmenu
83471 +
83472 source security/keys/Kconfig
83473
83474 config SECURITY_DMESG_RESTRICT
83475 @@ -103,7 +993,7 @@ config INTEL_TXT
83476 config LSM_MMAP_MIN_ADDR
83477 int "Low address space for LSM to protect from user allocation"
83478 depends on SECURITY && SECURITY_SELINUX
83479 - default 32768 if ARM
83480 + default 32768 if ALPHA || ARM || PARISC || SPARC32
83481 default 65536
83482 help
83483 This is the portion of low virtual memory which should be protected
83484 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
83485 index 8c2a7f6..b133ac9 100644
83486 --- a/security/apparmor/lsm.c
83487 +++ b/security/apparmor/lsm.c
83488 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
83489 return error;
83490 }
83491
83492 -static struct security_operations apparmor_ops = {
83493 +static struct security_operations apparmor_ops __read_only = {
83494 .name = "apparmor",
83495
83496 .ptrace_access_check = apparmor_ptrace_access_check,
83497 diff --git a/security/commoncap.c b/security/commoncap.c
83498 index 6dbae46..d5611fd 100644
83499 --- a/security/commoncap.c
83500 +++ b/security/commoncap.c
83501 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
83502 return 0;
83503 }
83504
83505 +/* returns:
83506 + 1 for suid privilege
83507 + 2 for sgid privilege
83508 + 3 for fscap privilege
83509 +*/
83510 +int is_privileged_binary(const struct dentry *dentry)
83511 +{
83512 + struct cpu_vfs_cap_data capdata;
83513 + struct inode *inode = dentry->d_inode;
83514 +
83515 + if (!inode || S_ISDIR(inode->i_mode))
83516 + return 0;
83517 +
83518 + if (inode->i_mode & S_ISUID)
83519 + return 1;
83520 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
83521 + return 2;
83522 +
83523 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
83524 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
83525 + return 3;
83526 + }
83527 +
83528 + return 0;
83529 +}
83530 +
83531 /*
83532 * Attempt to get the on-exec apply capability sets for an executable file from
83533 * its xattrs and, if present, apply them to the proposed credentials being
83534 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
83535 const struct cred *cred = current_cred();
83536 kuid_t root_uid = make_kuid(cred->user_ns, 0);
83537
83538 + if (gr_acl_enable_at_secure())
83539 + return 1;
83540 +
83541 if (!uid_eq(cred->uid, root_uid)) {
83542 if (bprm->cap_effective)
83543 return 1;
83544 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
83545 index 6ee8826..6350060 100644
83546 --- a/security/integrity/ima/ima.h
83547 +++ b/security/integrity/ima/ima.h
83548 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83549 extern spinlock_t ima_queue_lock;
83550
83551 struct ima_h_table {
83552 - atomic_long_t len; /* number of stored measurements in the list */
83553 - atomic_long_t violations;
83554 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
83555 + atomic_long_unchecked_t violations;
83556 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
83557 };
83558 extern struct ima_h_table ima_htable;
83559 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
83560 index b356884..fd9676e 100644
83561 --- a/security/integrity/ima/ima_api.c
83562 +++ b/security/integrity/ima/ima_api.c
83563 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83564 int result;
83565
83566 /* can overflow, only indicator */
83567 - atomic_long_inc(&ima_htable.violations);
83568 + atomic_long_inc_unchecked(&ima_htable.violations);
83569
83570 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
83571 if (!entry) {
83572 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
83573 index 38477c9..87a60c7 100644
83574 --- a/security/integrity/ima/ima_fs.c
83575 +++ b/security/integrity/ima/ima_fs.c
83576 @@ -28,12 +28,12 @@
83577 static int valid_policy = 1;
83578 #define TMPBUFLEN 12
83579 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
83580 - loff_t *ppos, atomic_long_t *val)
83581 + loff_t *ppos, atomic_long_unchecked_t *val)
83582 {
83583 char tmpbuf[TMPBUFLEN];
83584 ssize_t len;
83585
83586 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
83587 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
83588 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
83589 }
83590
83591 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
83592 index 55a6271..ad829c3 100644
83593 --- a/security/integrity/ima/ima_queue.c
83594 +++ b/security/integrity/ima/ima_queue.c
83595 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
83596 INIT_LIST_HEAD(&qe->later);
83597 list_add_tail_rcu(&qe->later, &ima_measurements);
83598
83599 - atomic_long_inc(&ima_htable.len);
83600 + atomic_long_inc_unchecked(&ima_htable.len);
83601 key = ima_hash_key(entry->digest);
83602 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
83603 return 0;
83604 diff --git a/security/keys/compat.c b/security/keys/compat.c
83605 index 1c26176..64a1ba2 100644
83606 --- a/security/keys/compat.c
83607 +++ b/security/keys/compat.c
83608 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
83609 if (ret == 0)
83610 goto no_payload_free;
83611
83612 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83613 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83614
83615 if (iov != iovstack)
83616 kfree(iov);
83617 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
83618 index 5d34b4e..2456674 100644
83619 --- a/security/keys/keyctl.c
83620 +++ b/security/keys/keyctl.c
83621 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
83622 /*
83623 * Copy the iovec data from userspace
83624 */
83625 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83626 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
83627 unsigned ioc)
83628 {
83629 for (; ioc > 0; ioc--) {
83630 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83631 * If successful, 0 will be returned.
83632 */
83633 long keyctl_instantiate_key_common(key_serial_t id,
83634 - const struct iovec *payload_iov,
83635 + const struct iovec __user *payload_iov,
83636 unsigned ioc,
83637 size_t plen,
83638 key_serial_t ringid)
83639 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
83640 [0].iov_len = plen
83641 };
83642
83643 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
83644 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
83645 }
83646
83647 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
83648 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
83649 if (ret == 0)
83650 goto no_payload_free;
83651
83652 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83653 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83654
83655 if (iov != iovstack)
83656 kfree(iov);
83657 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
83658 index 6e42df1..aba52bd 100644
83659 --- a/security/keys/keyring.c
83660 +++ b/security/keys/keyring.c
83661 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
83662 ret = -EFAULT;
83663
83664 for (loop = 0; loop < klist->nkeys; loop++) {
83665 + key_serial_t serial;
83666 key = rcu_deref_link_locked(klist, loop,
83667 keyring);
83668 + serial = key->serial;
83669
83670 tmp = sizeof(key_serial_t);
83671 if (tmp > buflen)
83672 tmp = buflen;
83673
83674 - if (copy_to_user(buffer,
83675 - &key->serial,
83676 - tmp) != 0)
83677 + if (copy_to_user(buffer, &serial, tmp))
83678 goto error;
83679
83680 buflen -= tmp;
83681 diff --git a/security/min_addr.c b/security/min_addr.c
83682 index f728728..6457a0c 100644
83683 --- a/security/min_addr.c
83684 +++ b/security/min_addr.c
83685 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
83686 */
83687 static void update_mmap_min_addr(void)
83688 {
83689 +#ifndef SPARC
83690 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
83691 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
83692 mmap_min_addr = dac_mmap_min_addr;
83693 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
83694 #else
83695 mmap_min_addr = dac_mmap_min_addr;
83696 #endif
83697 +#endif
83698 }
83699
83700 /*
83701 diff --git a/security/security.c b/security/security.c
83702 index 8dcd4ae..1124de7 100644
83703 --- a/security/security.c
83704 +++ b/security/security.c
83705 @@ -20,6 +20,7 @@
83706 #include <linux/ima.h>
83707 #include <linux/evm.h>
83708 #include <linux/fsnotify.h>
83709 +#include <linux/mm.h>
83710 #include <linux/mman.h>
83711 #include <linux/mount.h>
83712 #include <linux/personality.h>
83713 @@ -32,8 +33,8 @@
83714 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
83715 CONFIG_DEFAULT_SECURITY;
83716
83717 -static struct security_operations *security_ops;
83718 -static struct security_operations default_security_ops = {
83719 +static struct security_operations *security_ops __read_only;
83720 +static struct security_operations default_security_ops __read_only = {
83721 .name = "default",
83722 };
83723
83724 @@ -74,7 +75,9 @@ int __init security_init(void)
83725
83726 void reset_security_ops(void)
83727 {
83728 + pax_open_kernel();
83729 security_ops = &default_security_ops;
83730 + pax_close_kernel();
83731 }
83732
83733 /* Save user chosen LSM */
83734 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
83735 index 61a5336..27215d8 100644
83736 --- a/security/selinux/hooks.c
83737 +++ b/security/selinux/hooks.c
83738 @@ -95,8 +95,6 @@
83739
83740 #define NUM_SEL_MNT_OPTS 5
83741
83742 -extern struct security_operations *security_ops;
83743 -
83744 /* SECMARK reference count */
83745 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
83746
83747 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
83748
83749 #endif
83750
83751 -static struct security_operations selinux_ops = {
83752 +static struct security_operations selinux_ops __read_only = {
83753 .name = "selinux",
83754
83755 .ptrace_access_check = selinux_ptrace_access_check,
83756 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
83757 index 65f67cb..3f141ef 100644
83758 --- a/security/selinux/include/xfrm.h
83759 +++ b/security/selinux/include/xfrm.h
83760 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
83761
83762 static inline void selinux_xfrm_notify_policyload(void)
83763 {
83764 - atomic_inc(&flow_cache_genid);
83765 + atomic_inc_unchecked(&flow_cache_genid);
83766 rt_genid_bump(&init_net);
83767 }
83768 #else
83769 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
83770 index 38be92c..21f49ee 100644
83771 --- a/security/smack/smack_lsm.c
83772 +++ b/security/smack/smack_lsm.c
83773 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
83774 return 0;
83775 }
83776
83777 -struct security_operations smack_ops = {
83778 +struct security_operations smack_ops __read_only = {
83779 .name = "smack",
83780
83781 .ptrace_access_check = smack_ptrace_access_check,
83782 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
83783 index a2ee362..5754f34 100644
83784 --- a/security/tomoyo/tomoyo.c
83785 +++ b/security/tomoyo/tomoyo.c
83786 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
83787 * tomoyo_security_ops is a "struct security_operations" which is used for
83788 * registering TOMOYO.
83789 */
83790 -static struct security_operations tomoyo_security_ops = {
83791 +static struct security_operations tomoyo_security_ops __read_only = {
83792 .name = "tomoyo",
83793 .cred_alloc_blank = tomoyo_cred_alloc_blank,
83794 .cred_prepare = tomoyo_cred_prepare,
83795 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
83796 index 20ef514..4182bed 100644
83797 --- a/security/yama/Kconfig
83798 +++ b/security/yama/Kconfig
83799 @@ -1,6 +1,6 @@
83800 config SECURITY_YAMA
83801 bool "Yama support"
83802 - depends on SECURITY
83803 + depends on SECURITY && !GRKERNSEC
83804 select SECURITYFS
83805 select SECURITY_PATH
83806 default n
83807 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
83808 index 4cedc69..e59d8a3 100644
83809 --- a/sound/aoa/codecs/onyx.c
83810 +++ b/sound/aoa/codecs/onyx.c
83811 @@ -54,7 +54,7 @@ struct onyx {
83812 spdif_locked:1,
83813 analog_locked:1,
83814 original_mute:2;
83815 - int open_count;
83816 + local_t open_count;
83817 struct codec_info *codec_info;
83818
83819 /* mutex serializes concurrent access to the device
83820 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
83821 struct onyx *onyx = cii->codec_data;
83822
83823 mutex_lock(&onyx->mutex);
83824 - onyx->open_count++;
83825 + local_inc(&onyx->open_count);
83826 mutex_unlock(&onyx->mutex);
83827
83828 return 0;
83829 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
83830 struct onyx *onyx = cii->codec_data;
83831
83832 mutex_lock(&onyx->mutex);
83833 - onyx->open_count--;
83834 - if (!onyx->open_count)
83835 + if (local_dec_and_test(&onyx->open_count))
83836 onyx->spdif_locked = onyx->analog_locked = 0;
83837 mutex_unlock(&onyx->mutex);
83838
83839 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
83840 index ffd2025..df062c9 100644
83841 --- a/sound/aoa/codecs/onyx.h
83842 +++ b/sound/aoa/codecs/onyx.h
83843 @@ -11,6 +11,7 @@
83844 #include <linux/i2c.h>
83845 #include <asm/pmac_low_i2c.h>
83846 #include <asm/prom.h>
83847 +#include <asm/local.h>
83848
83849 /* PCM3052 register definitions */
83850
83851 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
83852 index 4c1cc51..16040040 100644
83853 --- a/sound/core/oss/pcm_oss.c
83854 +++ b/sound/core/oss/pcm_oss.c
83855 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
83856 if (in_kernel) {
83857 mm_segment_t fs;
83858 fs = snd_enter_user();
83859 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
83860 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
83861 snd_leave_user(fs);
83862 } else {
83863 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
83864 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
83865 }
83866 if (ret != -EPIPE && ret != -ESTRPIPE)
83867 break;
83868 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
83869 if (in_kernel) {
83870 mm_segment_t fs;
83871 fs = snd_enter_user();
83872 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
83873 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
83874 snd_leave_user(fs);
83875 } else {
83876 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
83877 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
83878 }
83879 if (ret == -EPIPE) {
83880 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
83881 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
83882 struct snd_pcm_plugin_channel *channels;
83883 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
83884 if (!in_kernel) {
83885 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
83886 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
83887 return -EFAULT;
83888 buf = runtime->oss.buffer;
83889 }
83890 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
83891 }
83892 } else {
83893 tmp = snd_pcm_oss_write2(substream,
83894 - (const char __force *)buf,
83895 + (const char __force_kernel *)buf,
83896 runtime->oss.period_bytes, 0);
83897 if (tmp <= 0)
83898 goto err;
83899 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
83900 struct snd_pcm_runtime *runtime = substream->runtime;
83901 snd_pcm_sframes_t frames, frames1;
83902 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
83903 - char __user *final_dst = (char __force __user *)buf;
83904 + char __user *final_dst = (char __force_user *)buf;
83905 if (runtime->oss.plugin_first) {
83906 struct snd_pcm_plugin_channel *channels;
83907 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
83908 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
83909 xfer += tmp;
83910 runtime->oss.buffer_used -= tmp;
83911 } else {
83912 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
83913 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
83914 runtime->oss.period_bytes, 0);
83915 if (tmp <= 0)
83916 goto err;
83917 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
83918 size1);
83919 size1 /= runtime->channels; /* frames */
83920 fs = snd_enter_user();
83921 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
83922 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
83923 snd_leave_user(fs);
83924 }
83925 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
83926 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
83927 index 91cdf943..4085161 100644
83928 --- a/sound/core/pcm_compat.c
83929 +++ b/sound/core/pcm_compat.c
83930 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
83931 int err;
83932
83933 fs = snd_enter_user();
83934 - err = snd_pcm_delay(substream, &delay);
83935 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
83936 snd_leave_user(fs);
83937 if (err < 0)
83938 return err;
83939 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
83940 index f9ddecf..e27404d 100644
83941 --- a/sound/core/pcm_native.c
83942 +++ b/sound/core/pcm_native.c
83943 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
83944 switch (substream->stream) {
83945 case SNDRV_PCM_STREAM_PLAYBACK:
83946 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
83947 - (void __user *)arg);
83948 + (void __force_user *)arg);
83949 break;
83950 case SNDRV_PCM_STREAM_CAPTURE:
83951 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
83952 - (void __user *)arg);
83953 + (void __force_user *)arg);
83954 break;
83955 default:
83956 result = -EINVAL;
83957 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
83958 index 60e8fc1..786abcb 100644
83959 --- a/sound/core/seq/seq_device.c
83960 +++ b/sound/core/seq/seq_device.c
83961 @@ -64,7 +64,7 @@ struct ops_list {
83962 int argsize; /* argument size */
83963
83964 /* operators */
83965 - struct snd_seq_dev_ops ops;
83966 + struct snd_seq_dev_ops *ops;
83967
83968 /* registred devices */
83969 struct list_head dev_list; /* list of devices */
83970 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
83971
83972 mutex_lock(&ops->reg_mutex);
83973 /* copy driver operators */
83974 - ops->ops = *entry;
83975 + ops->ops = entry;
83976 ops->driver |= DRIVER_LOADED;
83977 ops->argsize = argsize;
83978
83979 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
83980 dev->name, ops->id, ops->argsize, dev->argsize);
83981 return -EINVAL;
83982 }
83983 - if (ops->ops.init_device(dev) >= 0) {
83984 + if (ops->ops->init_device(dev) >= 0) {
83985 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
83986 ops->num_init_devices++;
83987 } else {
83988 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
83989 dev->name, ops->id, ops->argsize, dev->argsize);
83990 return -EINVAL;
83991 }
83992 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
83993 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
83994 dev->status = SNDRV_SEQ_DEVICE_FREE;
83995 dev->driver_data = NULL;
83996 ops->num_init_devices--;
83997 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
83998 index 2d5514b..3afae9c 100644
83999 --- a/sound/drivers/mts64.c
84000 +++ b/sound/drivers/mts64.c
84001 @@ -29,6 +29,7 @@
84002 #include <sound/initval.h>
84003 #include <sound/rawmidi.h>
84004 #include <sound/control.h>
84005 +#include <asm/local.h>
84006
84007 #define CARD_NAME "Miditerminal 4140"
84008 #define DRIVER_NAME "MTS64"
84009 @@ -67,7 +68,7 @@ struct mts64 {
84010 struct pardevice *pardev;
84011 int pardev_claimed;
84012
84013 - int open_count;
84014 + local_t open_count;
84015 int current_midi_output_port;
84016 int current_midi_input_port;
84017 u8 mode[MTS64_NUM_INPUT_PORTS];
84018 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84019 {
84020 struct mts64 *mts = substream->rmidi->private_data;
84021
84022 - if (mts->open_count == 0) {
84023 + if (local_read(&mts->open_count) == 0) {
84024 /* We don't need a spinlock here, because this is just called
84025 if the device has not been opened before.
84026 So there aren't any IRQs from the device */
84027 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84028
84029 msleep(50);
84030 }
84031 - ++(mts->open_count);
84032 + local_inc(&mts->open_count);
84033
84034 return 0;
84035 }
84036 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84037 struct mts64 *mts = substream->rmidi->private_data;
84038 unsigned long flags;
84039
84040 - --(mts->open_count);
84041 - if (mts->open_count == 0) {
84042 + if (local_dec_return(&mts->open_count) == 0) {
84043 /* We need the spinlock_irqsave here because we can still
84044 have IRQs at this point */
84045 spin_lock_irqsave(&mts->lock, flags);
84046 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84047
84048 msleep(500);
84049
84050 - } else if (mts->open_count < 0)
84051 - mts->open_count = 0;
84052 + } else if (local_read(&mts->open_count) < 0)
84053 + local_set(&mts->open_count, 0);
84054
84055 return 0;
84056 }
84057 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84058 index b953fb4..1999c01 100644
84059 --- a/sound/drivers/opl4/opl4_lib.c
84060 +++ b/sound/drivers/opl4/opl4_lib.c
84061 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84062 MODULE_DESCRIPTION("OPL4 driver");
84063 MODULE_LICENSE("GPL");
84064
84065 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84066 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84067 {
84068 int timeout = 10;
84069 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84070 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84071 index 8364855..59f2e2b 100644
84072 --- a/sound/drivers/portman2x4.c
84073 +++ b/sound/drivers/portman2x4.c
84074 @@ -48,6 +48,7 @@
84075 #include <sound/initval.h>
84076 #include <sound/rawmidi.h>
84077 #include <sound/control.h>
84078 +#include <asm/local.h>
84079
84080 #define CARD_NAME "Portman 2x4"
84081 #define DRIVER_NAME "portman"
84082 @@ -85,7 +86,7 @@ struct portman {
84083 struct pardevice *pardev;
84084 int pardev_claimed;
84085
84086 - int open_count;
84087 + local_t open_count;
84088 int mode[PORTMAN_NUM_INPUT_PORTS];
84089 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84090 };
84091 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
84092 index ea995af..f1bfa37 100644
84093 --- a/sound/firewire/amdtp.c
84094 +++ b/sound/firewire/amdtp.c
84095 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
84096 ptr = s->pcm_buffer_pointer + data_blocks;
84097 if (ptr >= pcm->runtime->buffer_size)
84098 ptr -= pcm->runtime->buffer_size;
84099 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
84100 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
84101
84102 s->pcm_period_pointer += data_blocks;
84103 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
84104 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
84105 */
84106 void amdtp_out_stream_update(struct amdtp_out_stream *s)
84107 {
84108 - ACCESS_ONCE(s->source_node_id_field) =
84109 + ACCESS_ONCE_RW(s->source_node_id_field) =
84110 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
84111 }
84112 EXPORT_SYMBOL(amdtp_out_stream_update);
84113 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
84114 index b680c5e..061b7a0 100644
84115 --- a/sound/firewire/amdtp.h
84116 +++ b/sound/firewire/amdtp.h
84117 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
84118 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
84119 struct snd_pcm_substream *pcm)
84120 {
84121 - ACCESS_ONCE(s->pcm) = pcm;
84122 + ACCESS_ONCE_RW(s->pcm) = pcm;
84123 }
84124
84125 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
84126 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
84127 index d428ffe..751ef78 100644
84128 --- a/sound/firewire/isight.c
84129 +++ b/sound/firewire/isight.c
84130 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
84131 ptr += count;
84132 if (ptr >= runtime->buffer_size)
84133 ptr -= runtime->buffer_size;
84134 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
84135 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
84136
84137 isight->period_counter += count;
84138 if (isight->period_counter >= runtime->period_size) {
84139 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
84140 if (err < 0)
84141 return err;
84142
84143 - ACCESS_ONCE(isight->pcm_active) = true;
84144 + ACCESS_ONCE_RW(isight->pcm_active) = true;
84145
84146 return 0;
84147 }
84148 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
84149 {
84150 struct isight *isight = substream->private_data;
84151
84152 - ACCESS_ONCE(isight->pcm_active) = false;
84153 + ACCESS_ONCE_RW(isight->pcm_active) = false;
84154
84155 mutex_lock(&isight->mutex);
84156 isight_stop_streaming(isight);
84157 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
84158
84159 switch (cmd) {
84160 case SNDRV_PCM_TRIGGER_START:
84161 - ACCESS_ONCE(isight->pcm_running) = true;
84162 + ACCESS_ONCE_RW(isight->pcm_running) = true;
84163 break;
84164 case SNDRV_PCM_TRIGGER_STOP:
84165 - ACCESS_ONCE(isight->pcm_running) = false;
84166 + ACCESS_ONCE_RW(isight->pcm_running) = false;
84167 break;
84168 default:
84169 return -EINVAL;
84170 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84171 index b2b3c01..e1c1e1f 100644
84172 --- a/sound/oss/sb_audio.c
84173 +++ b/sound/oss/sb_audio.c
84174 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
84175 buf16 = (signed short *)(localbuf + localoffs);
84176 while (c)
84177 {
84178 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84179 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84180 if (copy_from_user(lbuf8,
84181 userbuf+useroffs + p,
84182 locallen))
84183 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84184 index 7d8803a..559f8d0 100644
84185 --- a/sound/oss/swarm_cs4297a.c
84186 +++ b/sound/oss/swarm_cs4297a.c
84187 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
84188 {
84189 struct cs4297a_state *s;
84190 u32 pwr, id;
84191 - mm_segment_t fs;
84192 int rval;
84193 #ifndef CONFIG_BCM_CS4297A_CSWARM
84194 u64 cfg;
84195 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
84196 if (!rval) {
84197 char *sb1250_duart_present;
84198
84199 +#if 0
84200 + mm_segment_t fs;
84201 fs = get_fs();
84202 set_fs(KERNEL_DS);
84203 -#if 0
84204 val = SOUND_MASK_LINE;
84205 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84206 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84207 val = initvol[i].vol;
84208 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84209 }
84210 + set_fs(fs);
84211 // cs4297a_write_ac97(s, 0x18, 0x0808);
84212 #else
84213 // cs4297a_write_ac97(s, 0x5e, 0x180);
84214 cs4297a_write_ac97(s, 0x02, 0x0808);
84215 cs4297a_write_ac97(s, 0x18, 0x0808);
84216 #endif
84217 - set_fs(fs);
84218
84219 list_add(&s->list, &cs4297a_devs);
84220
84221 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
84222 index 4631a23..001ae57 100644
84223 --- a/sound/pci/ymfpci/ymfpci.h
84224 +++ b/sound/pci/ymfpci/ymfpci.h
84225 @@ -358,7 +358,7 @@ struct snd_ymfpci {
84226 spinlock_t reg_lock;
84227 spinlock_t voice_lock;
84228 wait_queue_head_t interrupt_sleep;
84229 - atomic_t interrupt_sleep_count;
84230 + atomic_unchecked_t interrupt_sleep_count;
84231 struct snd_info_entry *proc_entry;
84232 const struct firmware *dsp_microcode;
84233 const struct firmware *controller_microcode;
84234 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
84235 index 3a6f03f..bc5c86c 100644
84236 --- a/sound/pci/ymfpci/ymfpci_main.c
84237 +++ b/sound/pci/ymfpci/ymfpci_main.c
84238 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
84239 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
84240 break;
84241 }
84242 - if (atomic_read(&chip->interrupt_sleep_count)) {
84243 - atomic_set(&chip->interrupt_sleep_count, 0);
84244 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84245 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84246 wake_up(&chip->interrupt_sleep);
84247 }
84248 __end:
84249 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
84250 continue;
84251 init_waitqueue_entry(&wait, current);
84252 add_wait_queue(&chip->interrupt_sleep, &wait);
84253 - atomic_inc(&chip->interrupt_sleep_count);
84254 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
84255 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
84256 remove_wait_queue(&chip->interrupt_sleep, &wait);
84257 }
84258 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
84259 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
84260 spin_unlock(&chip->reg_lock);
84261
84262 - if (atomic_read(&chip->interrupt_sleep_count)) {
84263 - atomic_set(&chip->interrupt_sleep_count, 0);
84264 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84265 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84266 wake_up(&chip->interrupt_sleep);
84267 }
84268 }
84269 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
84270 spin_lock_init(&chip->reg_lock);
84271 spin_lock_init(&chip->voice_lock);
84272 init_waitqueue_head(&chip->interrupt_sleep);
84273 - atomic_set(&chip->interrupt_sleep_count, 0);
84274 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84275 chip->card = card;
84276 chip->pci = pci;
84277 chip->irq = -1;
84278 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
84279 new file mode 100644
84280 index 0000000..50f2f2f
84281 --- /dev/null
84282 +++ b/tools/gcc/.gitignore
84283 @@ -0,0 +1 @@
84284 +size_overflow_hash.h
84285 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
84286 new file mode 100644
84287 index 0000000..1d09b7e
84288 --- /dev/null
84289 +++ b/tools/gcc/Makefile
84290 @@ -0,0 +1,43 @@
84291 +#CC := gcc
84292 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84293 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84294 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
84295 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
84296 +
84297 +ifeq ($(PLUGINCC),$(HOSTCC))
84298 +HOSTLIBS := hostlibs
84299 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
84300 +else
84301 +HOSTLIBS := hostcxxlibs
84302 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
84303 +endif
84304 +
84305 +$(HOSTLIBS)-y := constify_plugin.so
84306 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
84307 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
84308 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
84309 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
84310 +$(HOSTLIBS)-y += colorize_plugin.so
84311 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
84312 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
84313 +
84314 +always := $($(HOSTLIBS)-y)
84315 +
84316 +constify_plugin-objs := constify_plugin.o
84317 +stackleak_plugin-objs := stackleak_plugin.o
84318 +kallocstat_plugin-objs := kallocstat_plugin.o
84319 +kernexec_plugin-objs := kernexec_plugin.o
84320 +checker_plugin-objs := checker_plugin.o
84321 +colorize_plugin-objs := colorize_plugin.o
84322 +size_overflow_plugin-objs := size_overflow_plugin.o
84323 +latent_entropy_plugin-objs := latent_entropy_plugin.o
84324 +
84325 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
84326 +
84327 +quiet_cmd_build_size_overflow_hash = GENHASH $@
84328 + cmd_build_size_overflow_hash = \
84329 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
84330 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
84331 + $(call if_changed,build_size_overflow_hash)
84332 +
84333 +targets += size_overflow_hash.h
84334 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
84335 new file mode 100644
84336 index 0000000..d41b5af
84337 --- /dev/null
84338 +++ b/tools/gcc/checker_plugin.c
84339 @@ -0,0 +1,171 @@
84340 +/*
84341 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84342 + * Licensed under the GPL v2
84343 + *
84344 + * Note: the choice of the license means that the compilation process is
84345 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84346 + * but for the kernel it doesn't matter since it doesn't link against
84347 + * any of the gcc libraries
84348 + *
84349 + * gcc plugin to implement various sparse (source code checker) features
84350 + *
84351 + * TODO:
84352 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
84353 + *
84354 + * BUGS:
84355 + * - none known
84356 + */
84357 +#include "gcc-plugin.h"
84358 +#include "config.h"
84359 +#include "system.h"
84360 +#include "coretypes.h"
84361 +#include "tree.h"
84362 +#include "tree-pass.h"
84363 +#include "flags.h"
84364 +#include "intl.h"
84365 +#include "toplev.h"
84366 +#include "plugin.h"
84367 +//#include "expr.h" where are you...
84368 +#include "diagnostic.h"
84369 +#include "plugin-version.h"
84370 +#include "tm.h"
84371 +#include "function.h"
84372 +#include "basic-block.h"
84373 +#include "gimple.h"
84374 +#include "rtl.h"
84375 +#include "emit-rtl.h"
84376 +#include "tree-flow.h"
84377 +#include "target.h"
84378 +
84379 +extern void c_register_addr_space (const char *str, addr_space_t as);
84380 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
84381 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
84382 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
84383 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
84384 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
84385 +
84386 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84387 +extern rtx emit_move_insn(rtx x, rtx y);
84388 +
84389 +int plugin_is_GPL_compatible;
84390 +
84391 +static struct plugin_info checker_plugin_info = {
84392 + .version = "201111150100",
84393 +};
84394 +
84395 +#define ADDR_SPACE_KERNEL 0
84396 +#define ADDR_SPACE_FORCE_KERNEL 1
84397 +#define ADDR_SPACE_USER 2
84398 +#define ADDR_SPACE_FORCE_USER 3
84399 +#define ADDR_SPACE_IOMEM 0
84400 +#define ADDR_SPACE_FORCE_IOMEM 0
84401 +#define ADDR_SPACE_PERCPU 0
84402 +#define ADDR_SPACE_FORCE_PERCPU 0
84403 +#define ADDR_SPACE_RCU 0
84404 +#define ADDR_SPACE_FORCE_RCU 0
84405 +
84406 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
84407 +{
84408 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
84409 +}
84410 +
84411 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
84412 +{
84413 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
84414 +}
84415 +
84416 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
84417 +{
84418 + return default_addr_space_valid_pointer_mode(mode, as);
84419 +}
84420 +
84421 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
84422 +{
84423 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
84424 +}
84425 +
84426 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
84427 +{
84428 + return default_addr_space_legitimize_address(x, oldx, mode, as);
84429 +}
84430 +
84431 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
84432 +{
84433 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
84434 + return true;
84435 +
84436 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
84437 + return true;
84438 +
84439 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
84440 + return true;
84441 +
84442 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
84443 + return true;
84444 +
84445 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
84446 + return true;
84447 +
84448 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
84449 + return true;
84450 +
84451 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
84452 + return true;
84453 +
84454 + return subset == superset;
84455 +}
84456 +
84457 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
84458 +{
84459 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
84460 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
84461 +
84462 + return op;
84463 +}
84464 +
84465 +static void register_checker_address_spaces(void *event_data, void *data)
84466 +{
84467 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
84468 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
84469 + c_register_addr_space("__user", ADDR_SPACE_USER);
84470 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
84471 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
84472 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
84473 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
84474 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
84475 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
84476 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
84477 +
84478 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
84479 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
84480 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
84481 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
84482 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
84483 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
84484 + targetm.addr_space.convert = checker_addr_space_convert;
84485 +}
84486 +
84487 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84488 +{
84489 + const char * const plugin_name = plugin_info->base_name;
84490 + const int argc = plugin_info->argc;
84491 + const struct plugin_argument * const argv = plugin_info->argv;
84492 + int i;
84493 +
84494 + if (!plugin_default_version_check(version, &gcc_version)) {
84495 + error(G_("incompatible gcc/plugin versions"));
84496 + return 1;
84497 + }
84498 +
84499 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
84500 +
84501 + for (i = 0; i < argc; ++i)
84502 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84503 +
84504 + if (TARGET_64BIT == 0)
84505 + return 0;
84506 +
84507 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
84508 +
84509 + return 0;
84510 +}
84511 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
84512 new file mode 100644
84513 index 0000000..846aeb0
84514 --- /dev/null
84515 +++ b/tools/gcc/colorize_plugin.c
84516 @@ -0,0 +1,148 @@
84517 +/*
84518 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
84519 + * Licensed under the GPL v2
84520 + *
84521 + * Note: the choice of the license means that the compilation process is
84522 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84523 + * but for the kernel it doesn't matter since it doesn't link against
84524 + * any of the gcc libraries
84525 + *
84526 + * gcc plugin to colorize diagnostic output
84527 + *
84528 + */
84529 +
84530 +#include "gcc-plugin.h"
84531 +#include "config.h"
84532 +#include "system.h"
84533 +#include "coretypes.h"
84534 +#include "tree.h"
84535 +#include "tree-pass.h"
84536 +#include "flags.h"
84537 +#include "intl.h"
84538 +#include "toplev.h"
84539 +#include "plugin.h"
84540 +#include "diagnostic.h"
84541 +#include "plugin-version.h"
84542 +#include "tm.h"
84543 +
84544 +int plugin_is_GPL_compatible;
84545 +
84546 +static struct plugin_info colorize_plugin_info = {
84547 + .version = "201203092200",
84548 + .help = NULL,
84549 +};
84550 +
84551 +#define GREEN "\033[32m\033[2m"
84552 +#define LIGHTGREEN "\033[32m\033[1m"
84553 +#define YELLOW "\033[33m\033[2m"
84554 +#define LIGHTYELLOW "\033[33m\033[1m"
84555 +#define RED "\033[31m\033[2m"
84556 +#define LIGHTRED "\033[31m\033[1m"
84557 +#define BLUE "\033[34m\033[2m"
84558 +#define LIGHTBLUE "\033[34m\033[1m"
84559 +#define BRIGHT "\033[m\033[1m"
84560 +#define NORMAL "\033[m"
84561 +
84562 +static diagnostic_starter_fn old_starter;
84563 +static diagnostic_finalizer_fn old_finalizer;
84564 +
84565 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84566 +{
84567 + const char *color;
84568 + char *newprefix;
84569 +
84570 + switch (diagnostic->kind) {
84571 + case DK_NOTE:
84572 + color = LIGHTBLUE;
84573 + break;
84574 +
84575 + case DK_PEDWARN:
84576 + case DK_WARNING:
84577 + color = LIGHTYELLOW;
84578 + break;
84579 +
84580 + case DK_ERROR:
84581 + case DK_FATAL:
84582 + case DK_ICE:
84583 + case DK_PERMERROR:
84584 + case DK_SORRY:
84585 + color = LIGHTRED;
84586 + break;
84587 +
84588 + default:
84589 + color = NORMAL;
84590 + }
84591 +
84592 + old_starter(context, diagnostic);
84593 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
84594 + return;
84595 + pp_destroy_prefix(context->printer);
84596 + pp_set_prefix(context->printer, newprefix);
84597 +}
84598 +
84599 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84600 +{
84601 + old_finalizer(context, diagnostic);
84602 +}
84603 +
84604 +static void colorize_arm(void)
84605 +{
84606 + old_starter = diagnostic_starter(global_dc);
84607 + old_finalizer = diagnostic_finalizer(global_dc);
84608 +
84609 + diagnostic_starter(global_dc) = start_colorize;
84610 + diagnostic_finalizer(global_dc) = finalize_colorize;
84611 +}
84612 +
84613 +static unsigned int execute_colorize_rearm(void)
84614 +{
84615 + if (diagnostic_starter(global_dc) == start_colorize)
84616 + return 0;
84617 +
84618 + colorize_arm();
84619 + return 0;
84620 +}
84621 +
84622 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
84623 + .pass = {
84624 + .type = SIMPLE_IPA_PASS,
84625 + .name = "colorize_rearm",
84626 + .gate = NULL,
84627 + .execute = execute_colorize_rearm,
84628 + .sub = NULL,
84629 + .next = NULL,
84630 + .static_pass_number = 0,
84631 + .tv_id = TV_NONE,
84632 + .properties_required = 0,
84633 + .properties_provided = 0,
84634 + .properties_destroyed = 0,
84635 + .todo_flags_start = 0,
84636 + .todo_flags_finish = 0
84637 + }
84638 +};
84639 +
84640 +static void colorize_start_unit(void *gcc_data, void *user_data)
84641 +{
84642 + colorize_arm();
84643 +}
84644 +
84645 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84646 +{
84647 + const char * const plugin_name = plugin_info->base_name;
84648 + struct register_pass_info colorize_rearm_pass_info = {
84649 + .pass = &pass_ipa_colorize_rearm.pass,
84650 + .reference_pass_name = "*free_lang_data",
84651 + .ref_pass_instance_number = 1,
84652 + .pos_op = PASS_POS_INSERT_AFTER
84653 + };
84654 +
84655 + if (!plugin_default_version_check(version, &gcc_version)) {
84656 + error(G_("incompatible gcc/plugin versions"));
84657 + return 1;
84658 + }
84659 +
84660 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
84661 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
84662 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
84663 + return 0;
84664 +}
84665 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
84666 new file mode 100644
84667 index 0000000..1742271
84668 --- /dev/null
84669 +++ b/tools/gcc/constify_plugin.c
84670 @@ -0,0 +1,349 @@
84671 +/*
84672 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
84673 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
84674 + * Licensed under the GPL v2, or (at your option) v3
84675 + *
84676 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
84677 + *
84678 + * Homepage:
84679 + * http://www.grsecurity.net/~ephox/const_plugin/
84680 + *
84681 + * Usage:
84682 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
84683 + * $ gcc -fplugin=constify_plugin.so test.c -O2
84684 + */
84685 +
84686 +#include "gcc-plugin.h"
84687 +#include "config.h"
84688 +#include "system.h"
84689 +#include "coretypes.h"
84690 +#include "tree.h"
84691 +#include "tree-pass.h"
84692 +#include "flags.h"
84693 +#include "intl.h"
84694 +#include "toplev.h"
84695 +#include "plugin.h"
84696 +#include "diagnostic.h"
84697 +#include "plugin-version.h"
84698 +#include "tm.h"
84699 +#include "function.h"
84700 +#include "basic-block.h"
84701 +#include "gimple.h"
84702 +#include "rtl.h"
84703 +#include "emit-rtl.h"
84704 +#include "tree-flow.h"
84705 +
84706 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
84707 +
84708 +int plugin_is_GPL_compatible;
84709 +
84710 +static struct plugin_info const_plugin_info = {
84711 + .version = "201301150230",
84712 + .help = "no-constify\tturn off constification\n",
84713 +};
84714 +
84715 +static tree get_field_type(tree field)
84716 +{
84717 + return strip_array_types(TREE_TYPE(field));
84718 +}
84719 +
84720 +static bool walk_struct(tree node);
84721 +static void deconstify_tree(tree node);
84722 +
84723 +static void deconstify_type(tree type)
84724 +{
84725 + tree field;
84726 +
84727 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
84728 + tree fieldtype = get_field_type(field);
84729 +
84730 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
84731 + continue;
84732 + if (!TYPE_READONLY(fieldtype))
84733 + continue;
84734 + if (!walk_struct(fieldtype))
84735 + continue;
84736 +
84737 + deconstify_tree(field);
84738 + TREE_READONLY(field) = 0;
84739 + }
84740 + TYPE_READONLY(type) = 0;
84741 + C_TYPE_FIELDS_READONLY(type) = 0;
84742 +}
84743 +
84744 +static void deconstify_tree(tree node)
84745 +{
84746 + tree old_type, new_type, field;
84747 +
84748 +// TREE_READONLY(node) = 0;
84749 + old_type = TREE_TYPE(node);
84750 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
84751 + node = old_type;
84752 + old_type = TREE_TYPE(old_type);
84753 + }
84754 +
84755 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
84756 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
84757 +
84758 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
84759 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
84760 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
84761 + DECL_FIELD_CONTEXT(field) = new_type;
84762 +
84763 + deconstify_type(new_type);
84764 +
84765 + TREE_TYPE(node) = new_type;
84766 +}
84767 +
84768 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84769 +{
84770 + tree type;
84771 +
84772 + *no_add_attrs = true;
84773 + if (TREE_CODE(*node) == FUNCTION_DECL) {
84774 + error("%qE attribute does not apply to functions", name);
84775 + return NULL_TREE;
84776 + }
84777 +
84778 + if (TREE_CODE(*node) == VAR_DECL) {
84779 + error("%qE attribute does not apply to variables", name);
84780 + return NULL_TREE;
84781 + }
84782 +
84783 + if (TYPE_P(*node)) {
84784 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
84785 + *no_add_attrs = false;
84786 + else
84787 + error("%qE attribute applies to struct and union types only", name);
84788 + return NULL_TREE;
84789 + }
84790 +
84791 + type = TREE_TYPE(*node);
84792 +
84793 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
84794 + error("%qE attribute applies to struct and union types only", name);
84795 + return NULL_TREE;
84796 + }
84797 +
84798 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
84799 + error("%qE attribute is already applied to the type", name);
84800 + return NULL_TREE;
84801 + }
84802 +
84803 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
84804 + error("%qE attribute used on type that is not constified", name);
84805 + return NULL_TREE;
84806 + }
84807 +
84808 + if (TREE_CODE(*node) == TYPE_DECL) {
84809 + deconstify_tree(*node);
84810 + return NULL_TREE;
84811 + }
84812 +
84813 + return NULL_TREE;
84814 +}
84815 +
84816 +static void constify_type(tree type)
84817 +{
84818 + TYPE_READONLY(type) = 1;
84819 + C_TYPE_FIELDS_READONLY(type) = 1;
84820 +}
84821 +
84822 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84823 +{
84824 + *no_add_attrs = true;
84825 + if (!TYPE_P(*node)) {
84826 + error("%qE attribute applies to types only", name);
84827 + return NULL_TREE;
84828 + }
84829 +
84830 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
84831 + error("%qE attribute applies to struct and union types only", name);
84832 + return NULL_TREE;
84833 + }
84834 +
84835 + *no_add_attrs = false;
84836 + constify_type(*node);
84837 + return NULL_TREE;
84838 +}
84839 +
84840 +static struct attribute_spec no_const_attr = {
84841 + .name = "no_const",
84842 + .min_length = 0,
84843 + .max_length = 0,
84844 + .decl_required = false,
84845 + .type_required = false,
84846 + .function_type_required = false,
84847 + .handler = handle_no_const_attribute,
84848 +#if BUILDING_GCC_VERSION >= 4007
84849 + .affects_type_identity = true
84850 +#endif
84851 +};
84852 +
84853 +static struct attribute_spec do_const_attr = {
84854 + .name = "do_const",
84855 + .min_length = 0,
84856 + .max_length = 0,
84857 + .decl_required = false,
84858 + .type_required = false,
84859 + .function_type_required = false,
84860 + .handler = handle_do_const_attribute,
84861 +#if BUILDING_GCC_VERSION >= 4007
84862 + .affects_type_identity = true
84863 +#endif
84864 +};
84865 +
84866 +static void register_attributes(void *event_data, void *data)
84867 +{
84868 + register_attribute(&no_const_attr);
84869 + register_attribute(&do_const_attr);
84870 +}
84871 +
84872 +static bool is_fptr(tree field)
84873 +{
84874 + tree ptr = get_field_type(field);
84875 +
84876 + if (TREE_CODE(ptr) != POINTER_TYPE)
84877 + return false;
84878 +
84879 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
84880 +}
84881 +
84882 +static bool walk_struct(tree node)
84883 +{
84884 + tree field;
84885 +
84886 + if (TYPE_FIELDS(node) == NULL_TREE)
84887 + return false;
84888 +
84889 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
84890 + return true;
84891 +
84892 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
84893 + gcc_assert(!TYPE_READONLY(node));
84894 + deconstify_type(node);
84895 + return false;
84896 + }
84897 +
84898 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
84899 + tree type = get_field_type(field);
84900 + enum tree_code code = TREE_CODE(type);
84901 +
84902 + if (node == type)
84903 + return false;
84904 + if (code == RECORD_TYPE || code == UNION_TYPE) {
84905 + if (!(walk_struct(type)))
84906 + return false;
84907 + } else if (!is_fptr(field) && !TREE_READONLY(field))
84908 + return false;
84909 + }
84910 + return true;
84911 +}
84912 +
84913 +static void finish_type(void *event_data, void *data)
84914 +{
84915 + tree type = (tree)event_data;
84916 +
84917 + if (type == NULL_TREE || type == error_mark_node)
84918 + return;
84919 +
84920 + if (TYPE_READONLY(type))
84921 + return;
84922 +
84923 + if (walk_struct(type))
84924 + constify_type(type);
84925 + else
84926 + deconstify_type(type);
84927 +}
84928 +
84929 +static unsigned int check_local_variables(void)
84930 +{
84931 + unsigned int ret = 0;
84932 + tree var;
84933 + referenced_var_iterator rvi;
84934 +
84935 +#if BUILDING_GCC_VERSION == 4005
84936 + FOR_EACH_REFERENCED_VAR(var, rvi) {
84937 +#else
84938 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
84939 +#endif
84940 + tree type = TREE_TYPE(var);
84941 +
84942 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
84943 + continue;
84944 +
84945 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
84946 + continue;
84947 +
84948 + if (!TYPE_READONLY(type))
84949 + continue;
84950 +
84951 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
84952 +// continue;
84953 +
84954 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
84955 +// continue;
84956 +
84957 + if (walk_struct(type)) {
84958 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
84959 + ret = 1;
84960 + }
84961 + }
84962 + return ret;
84963 +}
84964 +
84965 +struct gimple_opt_pass pass_local_variable = {
84966 + {
84967 + .type = GIMPLE_PASS,
84968 + .name = "check_local_variables",
84969 + .gate = NULL,
84970 + .execute = check_local_variables,
84971 + .sub = NULL,
84972 + .next = NULL,
84973 + .static_pass_number = 0,
84974 + .tv_id = TV_NONE,
84975 + .properties_required = 0,
84976 + .properties_provided = 0,
84977 + .properties_destroyed = 0,
84978 + .todo_flags_start = 0,
84979 + .todo_flags_finish = 0
84980 + }
84981 +};
84982 +
84983 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84984 +{
84985 + const char * const plugin_name = plugin_info->base_name;
84986 + const int argc = plugin_info->argc;
84987 + const struct plugin_argument * const argv = plugin_info->argv;
84988 + int i;
84989 + bool constify = true;
84990 +
84991 + struct register_pass_info local_variable_pass_info = {
84992 + .pass = &pass_local_variable.pass,
84993 + .reference_pass_name = "ssa",
84994 + .ref_pass_instance_number = 1,
84995 + .pos_op = PASS_POS_INSERT_BEFORE
84996 + };
84997 +
84998 + if (!plugin_default_version_check(version, &gcc_version)) {
84999 + error(G_("incompatible gcc/plugin versions"));
85000 + return 1;
85001 + }
85002 +
85003 + for (i = 0; i < argc; ++i) {
85004 + if (!(strcmp(argv[i].key, "no-constify"))) {
85005 + constify = false;
85006 + continue;
85007 + }
85008 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85009 + }
85010 +
85011 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85012 + if (constify) {
85013 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85014 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85015 + }
85016 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85017 +
85018 + return 0;
85019 +}
85020 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
85021 new file mode 100644
85022 index 0000000..e518932
85023 --- /dev/null
85024 +++ b/tools/gcc/generate_size_overflow_hash.sh
85025 @@ -0,0 +1,94 @@
85026 +#!/bin/bash
85027 +
85028 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
85029 +
85030 +header1="size_overflow_hash.h"
85031 +database="size_overflow_hash.data"
85032 +n=65536
85033 +
85034 +usage() {
85035 +cat <<EOF
85036 +usage: $0 options
85037 +OPTIONS:
85038 + -h|--help help
85039 + -o header file
85040 + -d database file
85041 + -n hash array size
85042 +EOF
85043 + return 0
85044 +}
85045 +
85046 +while true
85047 +do
85048 + case "$1" in
85049 + -h|--help) usage && exit 0;;
85050 + -n) n=$2; shift 2;;
85051 + -o) header1="$2"; shift 2;;
85052 + -d) database="$2"; shift 2;;
85053 + --) shift 1; break ;;
85054 + *) break ;;
85055 + esac
85056 +done
85057 +
85058 +create_defines() {
85059 + for i in `seq 0 31`
85060 + do
85061 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
85062 + done
85063 + echo >> "$header1"
85064 +}
85065 +
85066 +create_structs() {
85067 + rm -f "$header1"
85068 +
85069 + create_defines
85070 +
85071 + cat "$database" | while read data
85072 + do
85073 + data_array=($data)
85074 + struct_hash_name="${data_array[0]}"
85075 + funcn="${data_array[1]}"
85076 + params="${data_array[2]}"
85077 + next="${data_array[4]}"
85078 +
85079 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
85080 +
85081 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
85082 + echo -en "\t.param\t= " >> "$header1"
85083 + line=
85084 + for param_num in ${params//-/ };
85085 + do
85086 + line="${line}PARAM"$param_num"|"
85087 + done
85088 +
85089 + echo -e "${line%?},\n};\n" >> "$header1"
85090 + done
85091 +}
85092 +
85093 +create_headers() {
85094 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
85095 +}
85096 +
85097 +create_array_elements() {
85098 + index=0
85099 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
85100 + do
85101 + data_array=($data)
85102 + i="${data_array[3]}"
85103 + hash="${data_array[0]}"
85104 + while [[ $index -lt $i ]]
85105 + do
85106 + echo -e "\t["$index"]\t= NULL," >> "$header1"
85107 + index=$(($index + 1))
85108 + done
85109 + index=$(($index + 1))
85110 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
85111 + done
85112 + echo '};' >> $header1
85113 +}
85114 +
85115 +create_structs
85116 +create_headers
85117 +create_array_elements
85118 +
85119 +exit 0
85120 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85121 new file mode 100644
85122 index 0000000..a86e422
85123 --- /dev/null
85124 +++ b/tools/gcc/kallocstat_plugin.c
85125 @@ -0,0 +1,167 @@
85126 +/*
85127 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85128 + * Licensed under the GPL v2
85129 + *
85130 + * Note: the choice of the license means that the compilation process is
85131 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85132 + * but for the kernel it doesn't matter since it doesn't link against
85133 + * any of the gcc libraries
85134 + *
85135 + * gcc plugin to find the distribution of k*alloc sizes
85136 + *
85137 + * TODO:
85138 + *
85139 + * BUGS:
85140 + * - none known
85141 + */
85142 +#include "gcc-plugin.h"
85143 +#include "config.h"
85144 +#include "system.h"
85145 +#include "coretypes.h"
85146 +#include "tree.h"
85147 +#include "tree-pass.h"
85148 +#include "flags.h"
85149 +#include "intl.h"
85150 +#include "toplev.h"
85151 +#include "plugin.h"
85152 +//#include "expr.h" where are you...
85153 +#include "diagnostic.h"
85154 +#include "plugin-version.h"
85155 +#include "tm.h"
85156 +#include "function.h"
85157 +#include "basic-block.h"
85158 +#include "gimple.h"
85159 +#include "rtl.h"
85160 +#include "emit-rtl.h"
85161 +
85162 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85163 +
85164 +int plugin_is_GPL_compatible;
85165 +
85166 +static const char * const kalloc_functions[] = {
85167 + "__kmalloc",
85168 + "kmalloc",
85169 + "kmalloc_large",
85170 + "kmalloc_node",
85171 + "kmalloc_order",
85172 + "kmalloc_order_trace",
85173 + "kmalloc_slab",
85174 + "kzalloc",
85175 + "kzalloc_node",
85176 +};
85177 +
85178 +static struct plugin_info kallocstat_plugin_info = {
85179 + .version = "201111150100",
85180 +};
85181 +
85182 +static unsigned int execute_kallocstat(void);
85183 +
85184 +static struct gimple_opt_pass kallocstat_pass = {
85185 + .pass = {
85186 + .type = GIMPLE_PASS,
85187 + .name = "kallocstat",
85188 + .gate = NULL,
85189 + .execute = execute_kallocstat,
85190 + .sub = NULL,
85191 + .next = NULL,
85192 + .static_pass_number = 0,
85193 + .tv_id = TV_NONE,
85194 + .properties_required = 0,
85195 + .properties_provided = 0,
85196 + .properties_destroyed = 0,
85197 + .todo_flags_start = 0,
85198 + .todo_flags_finish = 0
85199 + }
85200 +};
85201 +
85202 +static bool is_kalloc(const char *fnname)
85203 +{
85204 + size_t i;
85205 +
85206 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
85207 + if (!strcmp(fnname, kalloc_functions[i]))
85208 + return true;
85209 + return false;
85210 +}
85211 +
85212 +static unsigned int execute_kallocstat(void)
85213 +{
85214 + basic_block bb;
85215 +
85216 + // 1. loop through BBs and GIMPLE statements
85217 + FOR_EACH_BB(bb) {
85218 + gimple_stmt_iterator gsi;
85219 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85220 + // gimple match:
85221 + tree fndecl, size;
85222 + gimple call_stmt;
85223 + const char *fnname;
85224 +
85225 + // is it a call
85226 + call_stmt = gsi_stmt(gsi);
85227 + if (!is_gimple_call(call_stmt))
85228 + continue;
85229 + fndecl = gimple_call_fndecl(call_stmt);
85230 + if (fndecl == NULL_TREE)
85231 + continue;
85232 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
85233 + continue;
85234 +
85235 + // is it a call to k*alloc
85236 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
85237 + if (!is_kalloc(fnname))
85238 + continue;
85239 +
85240 + // is the size arg the result of a simple const assignment
85241 + size = gimple_call_arg(call_stmt, 0);
85242 + while (true) {
85243 + gimple def_stmt;
85244 + expanded_location xloc;
85245 + size_t size_val;
85246 +
85247 + if (TREE_CODE(size) != SSA_NAME)
85248 + break;
85249 + def_stmt = SSA_NAME_DEF_STMT(size);
85250 + if (!def_stmt || !is_gimple_assign(def_stmt))
85251 + break;
85252 + if (gimple_num_ops(def_stmt) != 2)
85253 + break;
85254 + size = gimple_assign_rhs1(def_stmt);
85255 + if (!TREE_CONSTANT(size))
85256 + continue;
85257 + xloc = expand_location(gimple_location(def_stmt));
85258 + if (!xloc.file)
85259 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85260 + size_val = TREE_INT_CST_LOW(size);
85261 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
85262 + break;
85263 + }
85264 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85265 +//debug_tree(gimple_call_fn(call_stmt));
85266 +//print_node(stderr, "pax", fndecl, 4);
85267 + }
85268 + }
85269 +
85270 + return 0;
85271 +}
85272 +
85273 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85274 +{
85275 + const char * const plugin_name = plugin_info->base_name;
85276 + struct register_pass_info kallocstat_pass_info = {
85277 + .pass = &kallocstat_pass.pass,
85278 + .reference_pass_name = "ssa",
85279 + .ref_pass_instance_number = 1,
85280 + .pos_op = PASS_POS_INSERT_AFTER
85281 + };
85282 +
85283 + if (!plugin_default_version_check(version, &gcc_version)) {
85284 + error(G_("incompatible gcc/plugin versions"));
85285 + return 1;
85286 + }
85287 +
85288 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
85289 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
85290 +
85291 + return 0;
85292 +}
85293 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
85294 new file mode 100644
85295 index 0000000..8856202
85296 --- /dev/null
85297 +++ b/tools/gcc/kernexec_plugin.c
85298 @@ -0,0 +1,432 @@
85299 +/*
85300 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85301 + * Licensed under the GPL v2
85302 + *
85303 + * Note: the choice of the license means that the compilation process is
85304 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85305 + * but for the kernel it doesn't matter since it doesn't link against
85306 + * any of the gcc libraries
85307 + *
85308 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
85309 + *
85310 + * TODO:
85311 + *
85312 + * BUGS:
85313 + * - none known
85314 + */
85315 +#include "gcc-plugin.h"
85316 +#include "config.h"
85317 +#include "system.h"
85318 +#include "coretypes.h"
85319 +#include "tree.h"
85320 +#include "tree-pass.h"
85321 +#include "flags.h"
85322 +#include "intl.h"
85323 +#include "toplev.h"
85324 +#include "plugin.h"
85325 +//#include "expr.h" where are you...
85326 +#include "diagnostic.h"
85327 +#include "plugin-version.h"
85328 +#include "tm.h"
85329 +#include "function.h"
85330 +#include "basic-block.h"
85331 +#include "gimple.h"
85332 +#include "rtl.h"
85333 +#include "emit-rtl.h"
85334 +#include "tree-flow.h"
85335 +
85336 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85337 +extern rtx emit_move_insn(rtx x, rtx y);
85338 +
85339 +#if BUILDING_GCC_VERSION <= 4006
85340 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
85341 +#endif
85342 +
85343 +int plugin_is_GPL_compatible;
85344 +
85345 +static struct plugin_info kernexec_plugin_info = {
85346 + .version = "201111291120",
85347 + .help = "method=[bts|or]\tinstrumentation method\n"
85348 +};
85349 +
85350 +static unsigned int execute_kernexec_reload(void);
85351 +static unsigned int execute_kernexec_fptr(void);
85352 +static unsigned int execute_kernexec_retaddr(void);
85353 +static bool kernexec_cmodel_check(void);
85354 +
85355 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
85356 +static void (*kernexec_instrument_retaddr)(rtx);
85357 +
85358 +static struct gimple_opt_pass kernexec_reload_pass = {
85359 + .pass = {
85360 + .type = GIMPLE_PASS,
85361 + .name = "kernexec_reload",
85362 + .gate = kernexec_cmodel_check,
85363 + .execute = execute_kernexec_reload,
85364 + .sub = NULL,
85365 + .next = NULL,
85366 + .static_pass_number = 0,
85367 + .tv_id = TV_NONE,
85368 + .properties_required = 0,
85369 + .properties_provided = 0,
85370 + .properties_destroyed = 0,
85371 + .todo_flags_start = 0,
85372 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85373 + }
85374 +};
85375 +
85376 +static struct gimple_opt_pass kernexec_fptr_pass = {
85377 + .pass = {
85378 + .type = GIMPLE_PASS,
85379 + .name = "kernexec_fptr",
85380 + .gate = kernexec_cmodel_check,
85381 + .execute = execute_kernexec_fptr,
85382 + .sub = NULL,
85383 + .next = NULL,
85384 + .static_pass_number = 0,
85385 + .tv_id = TV_NONE,
85386 + .properties_required = 0,
85387 + .properties_provided = 0,
85388 + .properties_destroyed = 0,
85389 + .todo_flags_start = 0,
85390 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85391 + }
85392 +};
85393 +
85394 +static struct rtl_opt_pass kernexec_retaddr_pass = {
85395 + .pass = {
85396 + .type = RTL_PASS,
85397 + .name = "kernexec_retaddr",
85398 + .gate = kernexec_cmodel_check,
85399 + .execute = execute_kernexec_retaddr,
85400 + .sub = NULL,
85401 + .next = NULL,
85402 + .static_pass_number = 0,
85403 + .tv_id = TV_NONE,
85404 + .properties_required = 0,
85405 + .properties_provided = 0,
85406 + .properties_destroyed = 0,
85407 + .todo_flags_start = 0,
85408 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
85409 + }
85410 +};
85411 +
85412 +static bool kernexec_cmodel_check(void)
85413 +{
85414 + tree section;
85415 +
85416 + if (ix86_cmodel != CM_KERNEL)
85417 + return false;
85418 +
85419 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
85420 + if (!section || !TREE_VALUE(section))
85421 + return true;
85422 +
85423 + section = TREE_VALUE(TREE_VALUE(section));
85424 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
85425 + return true;
85426 +
85427 + return false;
85428 +}
85429 +
85430 +/*
85431 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
85432 + */
85433 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
85434 +{
85435 + gimple asm_movabs_stmt;
85436 +
85437 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
85438 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
85439 + gimple_asm_set_volatile(asm_movabs_stmt, true);
85440 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
85441 + update_stmt(asm_movabs_stmt);
85442 +}
85443 +
85444 +/*
85445 + * find all asm() stmts that clobber r10 and add a reload of r10
85446 + */
85447 +static unsigned int execute_kernexec_reload(void)
85448 +{
85449 + basic_block bb;
85450 +
85451 + // 1. loop through BBs and GIMPLE statements
85452 + FOR_EACH_BB(bb) {
85453 + gimple_stmt_iterator gsi;
85454 +
85455 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85456 + // gimple match: __asm__ ("" : : : "r10");
85457 + gimple asm_stmt;
85458 + size_t nclobbers;
85459 +
85460 + // is it an asm ...
85461 + asm_stmt = gsi_stmt(gsi);
85462 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
85463 + continue;
85464 +
85465 + // ... clobbering r10
85466 + nclobbers = gimple_asm_nclobbers(asm_stmt);
85467 + while (nclobbers--) {
85468 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
85469 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
85470 + continue;
85471 + kernexec_reload_fptr_mask(&gsi);
85472 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
85473 + break;
85474 + }
85475 + }
85476 + }
85477 +
85478 + return 0;
85479 +}
85480 +
85481 +/*
85482 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
85483 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
85484 + */
85485 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
85486 +{
85487 + gimple assign_intptr, assign_new_fptr, call_stmt;
85488 + tree intptr, old_fptr, new_fptr, kernexec_mask;
85489 +
85490 + call_stmt = gsi_stmt(*gsi);
85491 + old_fptr = gimple_call_fn(call_stmt);
85492 +
85493 + // create temporary unsigned long variable used for bitops and cast fptr to it
85494 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
85495 + add_referenced_var(intptr);
85496 + mark_sym_for_renaming(intptr);
85497 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
85498 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85499 + update_stmt(assign_intptr);
85500 +
85501 + // apply logical or to temporary unsigned long and bitmask
85502 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
85503 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
85504 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
85505 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85506 + update_stmt(assign_intptr);
85507 +
85508 + // cast temporary unsigned long back to a temporary fptr variable
85509 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
85510 + add_referenced_var(new_fptr);
85511 + mark_sym_for_renaming(new_fptr);
85512 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
85513 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
85514 + update_stmt(assign_new_fptr);
85515 +
85516 + // replace call stmt fn with the new fptr
85517 + gimple_call_set_fn(call_stmt, new_fptr);
85518 + update_stmt(call_stmt);
85519 +}
85520 +
85521 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
85522 +{
85523 + gimple asm_or_stmt, call_stmt;
85524 + tree old_fptr, new_fptr, input, output;
85525 + VEC(tree, gc) *inputs = NULL;
85526 + VEC(tree, gc) *outputs = NULL;
85527 +
85528 + call_stmt = gsi_stmt(*gsi);
85529 + old_fptr = gimple_call_fn(call_stmt);
85530 +
85531 + // create temporary fptr variable
85532 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
85533 + add_referenced_var(new_fptr);
85534 + mark_sym_for_renaming(new_fptr);
85535 +
85536 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
85537 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
85538 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
85539 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
85540 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
85541 + VEC_safe_push(tree, gc, inputs, input);
85542 + VEC_safe_push(tree, gc, outputs, output);
85543 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
85544 + gimple_asm_set_volatile(asm_or_stmt, true);
85545 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
85546 + update_stmt(asm_or_stmt);
85547 +
85548 + // replace call stmt fn with the new fptr
85549 + gimple_call_set_fn(call_stmt, new_fptr);
85550 + update_stmt(call_stmt);
85551 +}
85552 +
85553 +/*
85554 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
85555 + */
85556 +static unsigned int execute_kernexec_fptr(void)
85557 +{
85558 + basic_block bb;
85559 +
85560 + // 1. loop through BBs and GIMPLE statements
85561 + FOR_EACH_BB(bb) {
85562 + gimple_stmt_iterator gsi;
85563 +
85564 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85565 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
85566 + tree fn;
85567 + gimple call_stmt;
85568 +
85569 + // is it a call ...
85570 + call_stmt = gsi_stmt(gsi);
85571 + if (!is_gimple_call(call_stmt))
85572 + continue;
85573 + fn = gimple_call_fn(call_stmt);
85574 + if (TREE_CODE(fn) == ADDR_EXPR)
85575 + continue;
85576 + if (TREE_CODE(fn) != SSA_NAME)
85577 + gcc_unreachable();
85578 +
85579 + // ... through a function pointer
85580 + fn = SSA_NAME_VAR(fn);
85581 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
85582 + continue;
85583 + fn = TREE_TYPE(fn);
85584 + if (TREE_CODE(fn) != POINTER_TYPE)
85585 + continue;
85586 + fn = TREE_TYPE(fn);
85587 + if (TREE_CODE(fn) != FUNCTION_TYPE)
85588 + continue;
85589 +
85590 + kernexec_instrument_fptr(&gsi);
85591 +
85592 +//debug_tree(gimple_call_fn(call_stmt));
85593 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85594 + }
85595 + }
85596 +
85597 + return 0;
85598 +}
85599 +
85600 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
85601 +static void kernexec_instrument_retaddr_bts(rtx insn)
85602 +{
85603 + rtx btsq;
85604 + rtvec argvec, constraintvec, labelvec;
85605 + int line;
85606 +
85607 + // create asm volatile("btsq $63,(%%rsp)":::)
85608 + argvec = rtvec_alloc(0);
85609 + constraintvec = rtvec_alloc(0);
85610 + labelvec = rtvec_alloc(0);
85611 + line = expand_location(RTL_LOCATION(insn)).line;
85612 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85613 + MEM_VOLATILE_P(btsq) = 1;
85614 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
85615 + emit_insn_before(btsq, insn);
85616 +}
85617 +
85618 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
85619 +static void kernexec_instrument_retaddr_or(rtx insn)
85620 +{
85621 + rtx orq;
85622 + rtvec argvec, constraintvec, labelvec;
85623 + int line;
85624 +
85625 + // create asm volatile("orq %%r10,(%%rsp)":::)
85626 + argvec = rtvec_alloc(0);
85627 + constraintvec = rtvec_alloc(0);
85628 + labelvec = rtvec_alloc(0);
85629 + line = expand_location(RTL_LOCATION(insn)).line;
85630 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85631 + MEM_VOLATILE_P(orq) = 1;
85632 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
85633 + emit_insn_before(orq, insn);
85634 +}
85635 +
85636 +/*
85637 + * find all asm level function returns and forcibly set the highest bit of the return address
85638 + */
85639 +static unsigned int execute_kernexec_retaddr(void)
85640 +{
85641 + rtx insn;
85642 +
85643 + // 1. find function returns
85644 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85645 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
85646 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
85647 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
85648 + rtx body;
85649 +
85650 + // is it a retn
85651 + if (!JUMP_P(insn))
85652 + continue;
85653 + body = PATTERN(insn);
85654 + if (GET_CODE(body) == PARALLEL)
85655 + body = XVECEXP(body, 0, 0);
85656 + if (!ANY_RETURN_P(body))
85657 + continue;
85658 + kernexec_instrument_retaddr(insn);
85659 + }
85660 +
85661 +// print_simple_rtl(stderr, get_insns());
85662 +// print_rtl(stderr, get_insns());
85663 +
85664 + return 0;
85665 +}
85666 +
85667 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85668 +{
85669 + const char * const plugin_name = plugin_info->base_name;
85670 + const int argc = plugin_info->argc;
85671 + const struct plugin_argument * const argv = plugin_info->argv;
85672 + int i;
85673 + struct register_pass_info kernexec_reload_pass_info = {
85674 + .pass = &kernexec_reload_pass.pass,
85675 + .reference_pass_name = "ssa",
85676 + .ref_pass_instance_number = 1,
85677 + .pos_op = PASS_POS_INSERT_AFTER
85678 + };
85679 + struct register_pass_info kernexec_fptr_pass_info = {
85680 + .pass = &kernexec_fptr_pass.pass,
85681 + .reference_pass_name = "ssa",
85682 + .ref_pass_instance_number = 1,
85683 + .pos_op = PASS_POS_INSERT_AFTER
85684 + };
85685 + struct register_pass_info kernexec_retaddr_pass_info = {
85686 + .pass = &kernexec_retaddr_pass.pass,
85687 + .reference_pass_name = "pro_and_epilogue",
85688 + .ref_pass_instance_number = 1,
85689 + .pos_op = PASS_POS_INSERT_AFTER
85690 + };
85691 +
85692 + if (!plugin_default_version_check(version, &gcc_version)) {
85693 + error(G_("incompatible gcc/plugin versions"));
85694 + return 1;
85695 + }
85696 +
85697 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
85698 +
85699 + if (TARGET_64BIT == 0)
85700 + return 0;
85701 +
85702 + for (i = 0; i < argc; ++i) {
85703 + if (!strcmp(argv[i].key, "method")) {
85704 + if (!argv[i].value) {
85705 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85706 + continue;
85707 + }
85708 + if (!strcmp(argv[i].value, "bts")) {
85709 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
85710 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
85711 + } else if (!strcmp(argv[i].value, "or")) {
85712 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
85713 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
85714 + fix_register("r10", 1, 1);
85715 + } else
85716 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85717 + continue;
85718 + }
85719 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85720 + }
85721 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
85722 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
85723 +
85724 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
85725 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
85726 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
85727 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
85728 +
85729 + return 0;
85730 +}
85731 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
85732 new file mode 100644
85733 index 0000000..b8008f7
85734 --- /dev/null
85735 +++ b/tools/gcc/latent_entropy_plugin.c
85736 @@ -0,0 +1,295 @@
85737 +/*
85738 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
85739 + * Licensed under the GPL v2
85740 + *
85741 + * Note: the choice of the license means that the compilation process is
85742 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85743 + * but for the kernel it doesn't matter since it doesn't link against
85744 + * any of the gcc libraries
85745 + *
85746 + * gcc plugin to help generate a little bit of entropy from program state,
85747 + * used during boot in the kernel
85748 + *
85749 + * TODO:
85750 + * - add ipa pass to identify not explicitly marked candidate functions
85751 + * - mix in more program state (function arguments/return values, loop variables, etc)
85752 + * - more instrumentation control via attribute parameters
85753 + *
85754 + * BUGS:
85755 + * - LTO needs -flto-partition=none for now
85756 + */
85757 +#include "gcc-plugin.h"
85758 +#include "config.h"
85759 +#include "system.h"
85760 +#include "coretypes.h"
85761 +#include "tree.h"
85762 +#include "tree-pass.h"
85763 +#include "flags.h"
85764 +#include "intl.h"
85765 +#include "toplev.h"
85766 +#include "plugin.h"
85767 +//#include "expr.h" where are you...
85768 +#include "diagnostic.h"
85769 +#include "plugin-version.h"
85770 +#include "tm.h"
85771 +#include "function.h"
85772 +#include "basic-block.h"
85773 +#include "gimple.h"
85774 +#include "rtl.h"
85775 +#include "emit-rtl.h"
85776 +#include "tree-flow.h"
85777 +
85778 +int plugin_is_GPL_compatible;
85779 +
85780 +static tree latent_entropy_decl;
85781 +
85782 +static struct plugin_info latent_entropy_plugin_info = {
85783 + .version = "201207271820",
85784 + .help = NULL
85785 +};
85786 +
85787 +static unsigned int execute_latent_entropy(void);
85788 +static bool gate_latent_entropy(void);
85789 +
85790 +static struct gimple_opt_pass latent_entropy_pass = {
85791 + .pass = {
85792 + .type = GIMPLE_PASS,
85793 + .name = "latent_entropy",
85794 + .gate = gate_latent_entropy,
85795 + .execute = execute_latent_entropy,
85796 + .sub = NULL,
85797 + .next = NULL,
85798 + .static_pass_number = 0,
85799 + .tv_id = TV_NONE,
85800 + .properties_required = PROP_gimple_leh | PROP_cfg,
85801 + .properties_provided = 0,
85802 + .properties_destroyed = 0,
85803 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85804 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85805 + }
85806 +};
85807 +
85808 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85809 +{
85810 + if (TREE_CODE(*node) != FUNCTION_DECL) {
85811 + *no_add_attrs = true;
85812 + error("%qE attribute only applies to functions", name);
85813 + }
85814 + return NULL_TREE;
85815 +}
85816 +
85817 +static struct attribute_spec latent_entropy_attr = {
85818 + .name = "latent_entropy",
85819 + .min_length = 0,
85820 + .max_length = 0,
85821 + .decl_required = true,
85822 + .type_required = false,
85823 + .function_type_required = false,
85824 + .handler = handle_latent_entropy_attribute,
85825 +#if BUILDING_GCC_VERSION >= 4007
85826 + .affects_type_identity = false
85827 +#endif
85828 +};
85829 +
85830 +static void register_attributes(void *event_data, void *data)
85831 +{
85832 + register_attribute(&latent_entropy_attr);
85833 +}
85834 +
85835 +static bool gate_latent_entropy(void)
85836 +{
85837 + tree latent_entropy_attr;
85838 +
85839 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
85840 + return latent_entropy_attr != NULL_TREE;
85841 +}
85842 +
85843 +static unsigned HOST_WIDE_INT seed;
85844 +static unsigned HOST_WIDE_INT get_random_const(void)
85845 +{
85846 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
85847 + return seed;
85848 +}
85849 +
85850 +static enum tree_code get_op(tree *rhs)
85851 +{
85852 + static enum tree_code op;
85853 + unsigned HOST_WIDE_INT random_const;
85854 +
85855 + random_const = get_random_const();
85856 +
85857 + switch (op) {
85858 + case BIT_XOR_EXPR:
85859 + op = PLUS_EXPR;
85860 + break;
85861 +
85862 + case PLUS_EXPR:
85863 + if (rhs) {
85864 + op = LROTATE_EXPR;
85865 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
85866 + break;
85867 + }
85868 +
85869 + case LROTATE_EXPR:
85870 + default:
85871 + op = BIT_XOR_EXPR;
85872 + break;
85873 + }
85874 + if (rhs)
85875 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
85876 + return op;
85877 +}
85878 +
85879 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
85880 +{
85881 + gimple_stmt_iterator gsi;
85882 + gimple assign;
85883 + tree addxorrol, rhs;
85884 + enum tree_code op;
85885 +
85886 + op = get_op(&rhs);
85887 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
85888 + assign = gimple_build_assign(local_entropy, addxorrol);
85889 + find_referenced_vars_in(assign);
85890 +//debug_bb(bb);
85891 + gsi = gsi_after_labels(bb);
85892 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
85893 + update_stmt(assign);
85894 +}
85895 +
85896 +static void perturb_latent_entropy(basic_block bb, tree rhs)
85897 +{
85898 + gimple_stmt_iterator gsi;
85899 + gimple assign;
85900 + tree addxorrol, temp;
85901 +
85902 + // 1. create temporary copy of latent_entropy
85903 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
85904 + add_referenced_var(temp);
85905 + mark_sym_for_renaming(temp);
85906 +
85907 + // 2. read...
85908 + assign = gimple_build_assign(temp, latent_entropy_decl);
85909 + find_referenced_vars_in(assign);
85910 + gsi = gsi_after_labels(bb);
85911 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85912 + update_stmt(assign);
85913 +
85914 + // 3. ...modify...
85915 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
85916 + assign = gimple_build_assign(temp, addxorrol);
85917 + find_referenced_vars_in(assign);
85918 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85919 + update_stmt(assign);
85920 +
85921 + // 4. ...write latent_entropy
85922 + assign = gimple_build_assign(latent_entropy_decl, temp);
85923 + find_referenced_vars_in(assign);
85924 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85925 + update_stmt(assign);
85926 +}
85927 +
85928 +static unsigned int execute_latent_entropy(void)
85929 +{
85930 + basic_block bb;
85931 + gimple assign;
85932 + gimple_stmt_iterator gsi;
85933 + tree local_entropy;
85934 +
85935 + if (!latent_entropy_decl) {
85936 + struct varpool_node *node;
85937 +
85938 + for (node = varpool_nodes; node; node = node->next) {
85939 + tree var = node->decl;
85940 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
85941 + continue;
85942 + latent_entropy_decl = var;
85943 +// debug_tree(var);
85944 + break;
85945 + }
85946 + if (!latent_entropy_decl) {
85947 +// debug_tree(current_function_decl);
85948 + return 0;
85949 + }
85950 + }
85951 +
85952 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
85953 +
85954 + // 1. create local entropy variable
85955 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
85956 + add_referenced_var(local_entropy);
85957 + mark_sym_for_renaming(local_entropy);
85958 +
85959 + // 2. initialize local entropy variable
85960 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85961 + if (dom_info_available_p(CDI_DOMINATORS))
85962 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85963 + gsi = gsi_start_bb(bb);
85964 +
85965 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
85966 +// gimple_set_location(assign, loc);
85967 + find_referenced_vars_in(assign);
85968 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
85969 + update_stmt(assign);
85970 + bb = bb->next_bb;
85971 +
85972 + // 3. instrument each BB with an operation on the local entropy variable
85973 + while (bb != EXIT_BLOCK_PTR) {
85974 + perturb_local_entropy(bb, local_entropy);
85975 + bb = bb->next_bb;
85976 + };
85977 +
85978 + // 4. mix local entropy into the global entropy variable
85979 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
85980 + return 0;
85981 +}
85982 +
85983 +static void start_unit_callback(void *gcc_data, void *user_data)
85984 +{
85985 +#if BUILDING_GCC_VERSION >= 4007
85986 + seed = get_random_seed(false);
85987 +#else
85988 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
85989 + seed *= seed;
85990 +#endif
85991 +
85992 + if (in_lto_p)
85993 + return;
85994 +
85995 + // extern u64 latent_entropy
85996 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
85997 +
85998 + TREE_STATIC(latent_entropy_decl) = 1;
85999 + TREE_PUBLIC(latent_entropy_decl) = 1;
86000 + TREE_USED(latent_entropy_decl) = 1;
86001 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
86002 + DECL_EXTERNAL(latent_entropy_decl) = 1;
86003 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
86004 + DECL_INITIAL(latent_entropy_decl) = NULL;
86005 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
86006 +// varpool_finalize_decl(latent_entropy_decl);
86007 +// varpool_mark_needed_node(latent_entropy_decl);
86008 +}
86009 +
86010 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86011 +{
86012 + const char * const plugin_name = plugin_info->base_name;
86013 + struct register_pass_info latent_entropy_pass_info = {
86014 + .pass = &latent_entropy_pass.pass,
86015 + .reference_pass_name = "optimized",
86016 + .ref_pass_instance_number = 1,
86017 + .pos_op = PASS_POS_INSERT_BEFORE
86018 + };
86019 +
86020 + if (!plugin_default_version_check(version, &gcc_version)) {
86021 + error(G_("incompatible gcc/plugin versions"));
86022 + return 1;
86023 + }
86024 +
86025 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
86026 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86027 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
86028 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86029 +
86030 + return 0;
86031 +}
86032 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
86033 new file mode 100644
86034 index 0000000..5921fd7
86035 --- /dev/null
86036 +++ b/tools/gcc/size_overflow_hash.data
86037 @@ -0,0 +1,3713 @@
86038 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
86039 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
86040 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
86041 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
86042 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
86043 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
86044 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
86045 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
86046 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
86047 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
86048 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
86049 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
86050 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
86051 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
86052 +create_log_8225 create_log 2 8225 NULL
86053 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
86054 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
86055 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
86056 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
86057 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
86058 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
86059 +padzero_55 padzero 1 55 &sel_read_policyvers_55
86060 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
86061 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
86062 +read_file_blob_57406 read_file_blob 3 57406 NULL
86063 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
86064 +enclosure_register_57412 enclosure_register 3 57412 NULL
86065 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
86066 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
86067 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
86068 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
86069 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
86070 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
86071 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
86072 +init_cdev_8274 init_cdev 1 8274 NULL
86073 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
86074 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
86075 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
86076 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
86077 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
86078 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
86079 +load_msg_95 load_msg 2 95 NULL
86080 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
86081 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
86082 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86083 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
86084 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
86085 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
86086 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
86087 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
86088 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
86089 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
86090 +send_midi_async_57463 send_midi_async 3 57463 NULL
86091 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
86092 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
86093 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
86094 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
86095 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
86096 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
86097 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
86098 +init_q_132 init_q 4 132 NULL
86099 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
86100 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
86101 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
86102 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
86103 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
86104 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
86105 +uio_read_49300 uio_read 3 49300 NULL
86106 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
86107 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
86108 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
86109 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
86110 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
86111 +play_iframe_8219 play_iframe 3 8219 NULL
86112 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
86113 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
86114 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
86115 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
86116 +init_tag_map_57515 init_tag_map 3 57515 NULL
86117 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
86118 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
86119 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
86120 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
86121 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
86122 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
86123 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
86124 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
86125 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
86126 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
86127 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
86128 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
86129 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86130 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
86131 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
86132 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
86133 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
86134 +cache_read_24790 cache_read 3 24790 NULL
86135 +px_raw_event_49371 px_raw_event 4 49371 NULL
86136 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
86137 +compat_filldir_32999 compat_filldir 3 32999 NULL
86138 +hci_si_event_1404 hci_si_event 3 1404 NULL
86139 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
86140 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
86141 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
86142 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
86143 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
86144 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
86145 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
86146 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
86147 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
86148 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
86149 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
86150 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
86151 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
86152 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
86153 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
86154 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
86155 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
86156 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
86157 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
86158 +mem_read_57631 mem_read 3 57631 NULL
86159 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
86160 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
86161 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
86162 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
86163 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
86164 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
86165 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
86166 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
86167 +queues_read_24877 queues_read 3 24877 NULL
86168 +__fprog_create_41263 __fprog_create 2 41263 NULL
86169 +syslog_print_307 syslog_print 2 307 NULL
86170 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
86171 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
86172 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
86173 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
86174 +r3964_write_57662 r3964_write 4 57662 NULL
86175 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
86176 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
86177 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
86178 +alloc_context_41283 alloc_context 1 41283 NULL
86179 +__lgwrite_57669 __lgwrite 4 57669 NULL
86180 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
86181 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
86182 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
86183 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
86184 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86185 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
86186 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
86187 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
86188 +write_node_33121 write_node 4 33121 NULL
86189 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86190 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
86191 +profile_remove_8556 profile_remove 3 8556 NULL
86192 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86193 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
86194 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
86195 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
86196 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
86197 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
86198 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
86199 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
86200 +tower_write_8580 tower_write 3 8580 NULL
86201 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
86202 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
86203 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
86204 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
86205 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
86206 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
86207 +smk_write_access_49561 smk_write_access 3 49561 NULL
86208 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
86209 +kmp_init_41373 kmp_init 2 41373 NULL
86210 +context_alloc_24645 context_alloc 3 24645 NULL
86211 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
86212 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
86213 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
86214 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
86215 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
86216 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
86217 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
86218 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
86219 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
86220 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
86221 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
86222 +pp_read_33210 pp_read 3 33210 NULL
86223 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
86224 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
86225 +ivtv_read_57796 ivtv_read 3 57796 NULL
86226 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
86227 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
86228 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
86229 +heap_init_49617 heap_init 2 49617 NULL
86230 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
86231 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86232 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
86233 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
86234 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
86235 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
86236 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
86237 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
86238 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
86239 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
86240 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
86241 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
86242 +st_write_16874 st_write 3 16874 NULL
86243 +copy_to_user_57835 copy_to_user 3 57835 NULL
86244 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
86245 +pidlist_resize_496 pidlist_resize 2 496 NULL
86246 +flash_read_57843 flash_read 3 57843 NULL
86247 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
86248 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
86249 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
86250 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
86251 +arcfb_write_8702 arcfb_write 3 8702 NULL
86252 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86253 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
86254 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
86255 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86256 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86257 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
86258 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
86259 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
86260 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
86261 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
86262 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
86263 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
86264 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
86265 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
86266 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
86267 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
86268 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
86269 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
86270 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
86271 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
86272 +devres_alloc_551 devres_alloc 2 551 NULL
86273 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
86274 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
86275 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
86276 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
86277 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
86278 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
86279 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
86280 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
86281 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
86282 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
86283 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86284 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
86285 +sys_prctl_8766 sys_prctl 4 8766 NULL
86286 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
86287 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
86288 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
86289 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
86290 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
86291 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
86292 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
86293 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
86294 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
86295 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
86296 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
86297 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
86298 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
86299 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
86300 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
86301 +gserial_setup_41558 gserial_setup 2 41558 NULL
86302 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
86303 +rx_57944 rx 4 57944 NULL
86304 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
86305 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
86306 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
86307 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
86308 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
86309 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
86310 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86311 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
86312 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
86313 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
86314 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
86315 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
86316 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
86317 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
86318 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86319 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
86320 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
86321 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
86322 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
86323 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86324 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86325 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
86326 +a2mp_send_41615 a2mp_send 4 41615 NULL
86327 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
86328 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
86329 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
86330 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
86331 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
86332 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
86333 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
86334 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
86335 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
86336 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
86337 +add_uuid_49831 add_uuid 4 49831 NULL
86338 +send_pages_8872 send_pages 3 8872 NULL
86339 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
86340 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
86341 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
86342 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
86343 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
86344 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
86345 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
86346 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
86347 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
86348 +vfs_writev_25278 vfs_writev 3 25278 NULL
86349 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
86350 +alloc_async_14208 alloc_async 1 14208 NULL
86351 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
86352 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
86353 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
86354 +create_entry_33479 create_entry 2 33479 NULL
86355 +mce_async_out_58056 mce_async_out 3 58056 NULL
86356 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
86357 +sys_preadv_17100 sys_preadv 3 17100 NULL
86358 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
86359 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
86360 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
86361 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
86362 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
86363 +res_counter_read_33499 res_counter_read 4 33499 NULL
86364 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
86365 +cm4040_write_58079 cm4040_write 3 58079 NULL
86366 +fb_read_33506 fb_read 3 33506 NULL
86367 +help_25316 help 5 25316 NULL nohasharray
86368 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
86369 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
86370 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
86371 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
86372 +ddp_set_map_751 ddp_set_map 4 751 NULL
86373 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
86374 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
86375 +dvb_video_write_754 dvb_video_write 3 754 NULL
86376 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
86377 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
86378 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
86379 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
86380 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
86381 +udi_log_event_58105 udi_log_event 3 58105 NULL
86382 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
86383 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
86384 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
86385 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
86386 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
86387 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
86388 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
86389 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
86390 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
86391 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
86392 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
86393 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
86394 +sep_read_17161 sep_read 3 17161 NULL
86395 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
86396 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
86397 +dup_array_33551 dup_array 3 33551 NULL
86398 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
86399 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
86400 +fillonedir_41746 fillonedir 3 41746 NULL
86401 +init_bch_64130 init_bch 1-2 64130 NULL
86402 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
86403 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
86404 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
86405 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
86406 +savemem_58129 savemem 3 58129 NULL
86407 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
86408 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86409 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
86410 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
86411 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
86412 +if_writecmd_815 if_writecmd 2 815 NULL
86413 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
86414 +read_fifo_826 read_fifo 3 826 NULL
86415 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
86416 +scsi_execute_33596 scsi_execute 5 33596 NULL
86417 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
86418 +ms_rw_17220 ms_rw 3-4 17220 NULL
86419 +read_tree_block_841 read_tree_block 3 841 NULL
86420 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
86421 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
86422 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
86423 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
86424 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
86425 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
86426 +um_idi_read_850 um_idi_read 3 850 NULL
86427 +__module_alloc_50004 __module_alloc 1 50004 NULL
86428 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
86429 +ts_read_44687 ts_read 3 44687 NULL
86430 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
86431 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
86432 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
86433 +provide_user_output_41105 provide_user_output 3 41105 NULL
86434 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
86435 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
86436 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
86437 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
86438 +alloc_ep_17269 alloc_ep 1 17269 NULL
86439 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
86440 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
86441 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
86442 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
86443 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
86444 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
86445 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
86446 +create_queues_9088 create_queues 2-3 9088 NULL
86447 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
86448 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
86449 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
86450 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
86451 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
86452 +read_file_debug_58256 read_file_debug 3 58256 NULL
86453 +skb_pad_17302 skb_pad 2 17302 NULL
86454 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
86455 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
86456 +profile_load_58267 profile_load 3 58267 NULL
86457 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
86458 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
86459 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
86460 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
86461 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
86462 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
86463 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
86464 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
86465 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
86466 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
86467 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
86468 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
86469 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
86470 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
86471 +get_packet_41914 get_packet 3 41914 NULL
86472 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
86473 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
86474 +read_file_slot_50111 read_file_slot 3 50111 NULL
86475 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
86476 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
86477 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
86478 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86479 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
86480 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
86481 +copy_items_50140 copy_items 6 50140 NULL
86482 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
86483 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
86484 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
86485 +map_addr_56144 map_addr 7 56144 NULL
86486 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
86487 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
86488 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
86489 +portnames_read_41958 portnames_read 3 41958 NULL
86490 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
86491 +hashtab_create_33769 hashtab_create 3 33769 NULL
86492 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
86493 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
86494 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
86495 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
86496 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
86497 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
86498 +odev_update_50169 odev_update 2 50169 NULL
86499 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
86500 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
86501 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
86502 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86503 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
86504 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
86505 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
86506 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
86507 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86508 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
86509 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
86510 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
86511 +lguest_map_42008 lguest_map 1-2 42008 NULL
86512 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
86513 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
86514 +pool_allocate_42012 pool_allocate 3 42012 NULL
86515 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
86516 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
86517 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
86518 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
86519 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
86520 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
86521 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
86522 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
86523 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
86524 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
86525 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
86526 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
86527 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
86528 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
86529 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
86530 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
86531 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
86532 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
86533 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
86534 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
86535 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
86536 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
86537 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
86538 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
86539 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
86540 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
86541 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
86542 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
86543 +config_proc_write_33878 config_proc_write 3 33878 NULL
86544 +capabilities_read_58457 capabilities_read 3 58457 NULL
86545 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
86546 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
86547 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
86548 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
86549 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
86550 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
86551 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
86552 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
86553 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
86554 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
86555 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
86556 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
86557 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
86558 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
86559 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
86560 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
86561 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
86562 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
86563 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
86564 +vme_user_write_15587 vme_user_write 3 15587 NULL
86565 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
86566 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
86567 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
86568 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
86569 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
86570 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
86571 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
86572 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
86573 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
86574 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
86575 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
86576 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
86577 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
86578 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
86579 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
86580 +read_9397 read 3 9397 NULL
86581 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
86582 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
86583 +printer_write_60276 printer_write 3 60276 NULL
86584 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
86585 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
86586 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
86587 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
86588 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
86589 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
86590 +osst_execute_17607 osst_execute 7-6 17607 NULL
86591 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
86592 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
86593 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
86594 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
86595 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
86596 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
86597 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
86598 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
86599 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
86600 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
86601 +xip_file_read_58592 xip_file_read 3 58592 NULL
86602 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
86603 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
86604 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
86605 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
86606 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
86607 +ppp_write_34034 ppp_write 3 34034 NULL
86608 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
86609 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
86610 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
86611 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
86612 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
86613 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
86614 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
86615 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
86616 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
86617 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
86618 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
86619 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
86620 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
86621 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
86622 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
86623 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
86624 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
86625 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
86626 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
86627 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
86628 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
86629 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
86630 +lp_write_9511 lp_write 3 9511 NULL
86631 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
86632 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
86633 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
86634 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
86635 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
86636 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
86637 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
86638 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
86639 +read_file_dma_9530 read_file_dma 3 9530 NULL
86640 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
86641 +rcname_read_25919 rcname_read 3 25919 NULL
86642 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
86643 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
86644 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
86645 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
86646 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
86647 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
86648 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
86649 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
86650 +key_flags_read_25931 key_flags_read 3 25931 NULL
86651 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
86652 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
86653 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
86654 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
86655 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
86656 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
86657 +fw_node_create_9559 fw_node_create 2 9559 NULL
86658 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
86659 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
86660 +kobj_map_9566 kobj_map 2-3 9566 NULL
86661 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
86662 +acpi_map_58725 acpi_map 1-2 58725 NULL
86663 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
86664 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
86665 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
86666 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
86667 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
86668 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
86669 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
86670 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
86671 +file_read_actor_1401 file_read_actor 4 1401 NULL
86672 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86673 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
86674 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
86675 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
86676 +do_sync_9604 do_sync 1 9604 NULL
86677 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
86678 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86679 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
86680 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
86681 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
86682 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
86683 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
86684 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
86685 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
86686 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
86687 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
86688 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
86689 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
86690 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
86691 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
86692 +sge_rx_50594 sge_rx 3 50594 NULL
86693 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
86694 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
86695 +skb_padto_50759 skb_padto 2 50759 NULL
86696 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
86697 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
86698 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
86699 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
86700 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
86701 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
86702 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
86703 +ep_read_58813 ep_read 3 58813 NULL
86704 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
86705 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
86706 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
86707 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
86708 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
86709 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
86710 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
86711 +dns_query_9676 dns_query 3 9676 NULL
86712 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
86713 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
86714 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
86715 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
86716 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
86717 +command_write_58841 command_write 3 58841 NULL
86718 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86719 +dev_config_8506 dev_config 3 8506 NULL
86720 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
86721 +sys_readv_50664 sys_readv 3 50664 NULL
86722 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
86723 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
86724 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
86725 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
86726 +recover_head_17904 recover_head 3 17904 NULL
86727 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
86728 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
86729 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
86730 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
86731 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
86732 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
86733 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
86734 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
86735 +skb_cow_26138 skb_cow 2 26138 NULL
86736 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
86737 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
86738 +do_sigpending_9766 do_sigpending 2 9766 NULL
86739 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
86740 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
86741 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
86742 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
86743 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
86744 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
86745 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
86746 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
86747 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
86748 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
86749 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
86750 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
86751 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
86752 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
86753 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
86754 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
86755 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
86756 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
86757 +get_registers_26187 get_registers 3 26187 NULL
86758 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
86759 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
86760 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
86761 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
86762 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
86763 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
86764 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
86765 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
86766 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
86767 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
86768 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
86769 +mce_write_26201 mce_write 3 26201 NULL
86770 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
86771 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
86772 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
86773 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
86774 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
86775 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
86776 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
86777 +tpm_write_50798 tpm_write 3 50798 NULL
86778 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
86779 +tun_do_read_50800 tun_do_read 4 50800 NULL
86780 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
86781 +write_flush_50803 write_flush 3 50803 NULL
86782 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
86783 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
86784 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
86785 +dvb_play_50814 dvb_play 3 50814 NULL
86786 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
86787 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
86788 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
86789 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
86790 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
86791 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
86792 +dma_attach_50831 dma_attach 6-7 50831 NULL
86793 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
86794 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
86795 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
86796 +packet_came_18072 packet_came 3 18072 NULL
86797 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
86798 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
86799 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
86800 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
86801 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
86802 +get_vm_area_18080 get_vm_area 1 18080 NULL
86803 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
86804 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
86805 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
86806 +self_check_write_50856 self_check_write 5 50856 NULL
86807 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
86808 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
86809 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
86810 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
86811 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
86812 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
86813 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
86814 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
86815 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
86816 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
86817 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
86818 +vb2_read_42703 vb2_read 3 42703 NULL
86819 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
86820 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
86821 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
86822 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
86823 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
86824 +read_file_misc_9948 read_file_misc 3 9948 NULL
86825 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
86826 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
86827 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
86828 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
86829 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
86830 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
86831 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
86832 +cosa_write_1774 cosa_write 3 1774 NULL
86833 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
86834 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
86835 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
86836 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
86837 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
86838 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
86839 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
86840 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
86841 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
86842 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
86843 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
86844 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
86845 +mld_newpack_50950 mld_newpack 2 50950 NULL
86846 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
86847 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
86848 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
86849 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
86850 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
86851 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
86852 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
86853 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
86854 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
86855 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
86856 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
86857 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
86858 +handle_request_10024 handle_request 9 10024 NULL
86859 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
86860 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
86861 +timeout_write_50991 timeout_write 3 50991 NULL
86862 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
86863 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
86864 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
86865 +proc_write_51003 proc_write 3 51003 NULL
86866 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
86867 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
86868 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
86869 +set_arg_42824 set_arg 3 42824 NULL
86870 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
86871 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
86872 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
86873 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
86874 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
86875 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
86876 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
86877 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
86878 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
86879 +dt3155_read_59226 dt3155_read 3 59226 NULL
86880 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
86881 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
86882 +dump_midi_51040 dump_midi 3 51040 NULL
86883 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
86884 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
86885 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
86886 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
86887 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
86888 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
86889 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
86890 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
86891 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
86892 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
86893 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
86894 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
86895 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
86896 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
86897 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
86898 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
86899 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
86900 +read_vmcore_26501 read_vmcore 3 26501 NULL
86901 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
86902 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
86903 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
86904 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
86905 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
86906 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
86907 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
86908 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
86909 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
86910 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
86911 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
86912 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
86913 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
86914 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
86915 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
86916 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
86917 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
86918 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
86919 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
86920 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
86921 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
86922 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
86923 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
86924 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
86925 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
86926 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
86927 +fd_copyout_59323 fd_copyout 3 59323 NULL
86928 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
86929 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
86930 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
86931 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
86932 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
86933 +solos_param_store_34755 solos_param_store 4 34755 NULL
86934 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
86935 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
86936 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
86937 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
86938 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
86939 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
86940 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
86941 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
86942 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
86943 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
86944 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
86945 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
86946 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
86947 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
86948 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
86949 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
86950 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
86951 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
86952 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
86953 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
86954 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
86955 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
86956 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
86957 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
86958 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
86959 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
86960 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
86961 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
86962 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
86963 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
86964 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
86965 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
86966 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
86967 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
86968 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
86969 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
86970 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
86971 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
86972 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
86973 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
86974 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
86975 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
86976 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
86977 +tipc_send_51238 tipc_send 4 51238 NULL
86978 +drm_property_create_51239 drm_property_create 4 51239 NULL
86979 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
86980 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
86981 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
86982 +audit_expand_2098 audit_expand 2 2098 NULL
86983 +st_read_51251 st_read 3 51251 NULL
86984 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
86985 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
86986 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
86987 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
86988 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
86989 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
86990 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
86991 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
86992 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
86993 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
86994 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
86995 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
86996 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
86997 +c4_add_card_54968 c4_add_card 3 54968 NULL
86998 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
86999 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
87000 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
87001 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
87002 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
87003 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
87004 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
87005 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
87006 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
87007 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
87008 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
87009 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
87010 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
87011 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
87012 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
87013 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
87014 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
87015 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
87016 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
87017 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
87018 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
87019 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
87020 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
87021 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
87022 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
87023 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
87024 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87025 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
87026 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
87027 +debug_output_18575 debug_output 3 18575 NULL
87028 +Realloc_34961 Realloc 2 34961 NULL
87029 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
87030 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
87031 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
87032 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
87033 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
87034 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
87035 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
87036 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
87037 +vhci_write_2224 vhci_write 3 2224 NULL
87038 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
87039 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
87040 +rb_alloc_3102 rb_alloc 1 3102 NULL
87041 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
87042 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
87043 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
87044 +write_pbl_59583 write_pbl 4 59583 NULL
87045 +from_buffer_18625 from_buffer 3 18625 NULL
87046 +uio_write_43202 uio_write 3 43202 NULL
87047 +memdup_user_59590 memdup_user 2 59590 NULL
87048 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
87049 +iso_callback_43208 iso_callback 3 43208 NULL
87050 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
87051 +smk_write_load_26829 smk_write_load 3 26829 NULL
87052 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
87053 +do_update_counters_2259 do_update_counters 4 2259 NULL
87054 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
87055 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
87056 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
87057 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
87058 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
87059 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
87060 +mtrr_write_59622 mtrr_write 3 59622 NULL
87061 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
87062 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
87063 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
87064 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
87065 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
87066 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
87067 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
87068 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
87069 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
87070 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
87071 +fixup_leb_43256 fixup_leb 3 43256 NULL
87072 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
87073 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
87074 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
87075 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
87076 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
87077 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
87078 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
87079 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
87080 +evtchn_write_43278 evtchn_write 3 43278 NULL
87081 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
87082 +store_ifalias_35088 store_ifalias 4 35088 NULL
87083 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
87084 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
87085 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
87086 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
87087 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
87088 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
87089 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
87090 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
87091 +capi_write_35104 capi_write 3 35104 NULL nohasharray
87092 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
87093 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
87094 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
87095 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
87096 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
87097 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
87098 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
87099 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
87100 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
87101 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87102 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
87103 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
87104 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
87105 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
87106 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
87107 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
87108 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
87109 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
87110 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
87111 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
87112 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
87113 +do_trimming_26952 do_trimming 3 26952 NULL
87114 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
87115 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
87116 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
87117 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
87118 +alloc_buf_34532 alloc_buf 1 34532 NULL
87119 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
87120 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
87121 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
87122 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
87123 +otp_read_10594 otp_read 2-4-5 10594 NULL
87124 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
87125 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
87126 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
87127 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87128 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
87129 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
87130 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
87131 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
87132 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
87133 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
87134 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
87135 +venus_remove_59781 venus_remove 4 59781 NULL
87136 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
87137 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
87138 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
87139 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
87140 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
87141 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
87142 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
87143 +xenfb_write_43412 xenfb_write 3 43412 NULL
87144 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
87145 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
87146 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
87147 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
87148 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
87149 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
87150 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
87151 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
87152 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
87153 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
87154 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
87155 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
87156 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
87157 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
87158 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
87159 +cmd_complete_51629 cmd_complete 6 51629 NULL
87160 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
87161 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
87162 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
87163 +set_fd_set_35249 set_fd_set 1 35249 NULL
87164 +wiphy_new_2482 wiphy_new 2 2482 NULL
87165 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
87166 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
87167 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
87168 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
87169 +tcp_push_10680 tcp_push 3 10680 NULL
87170 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
87171 +c101_run_37279 c101_run 2 37279 NULL
87172 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
87173 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
87174 +tun_put_user_59849 tun_put_user 4 59849 NULL
87175 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
87176 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
87177 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
87178 +dm_write_2513 dm_write 3 2513 NULL
87179 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
87180 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
87181 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
87182 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
87183 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
87184 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
87185 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
87186 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
87187 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
87188 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
87189 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
87190 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
87191 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
87192 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
87193 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
87194 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
87195 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
87196 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
87197 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
87198 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
87199 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
87200 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
87201 +sel_write_access_51704 sel_write_access 3 51704 NULL
87202 +sys_syslog_10746 sys_syslog 3 10746 NULL
87203 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
87204 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
87205 +do_readlink_43518 do_readlink 2 43518 NULL
87206 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
87207 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
87208 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
87209 +read_file_reset_52310 read_file_reset 3 52310 NULL
87210 +pms_capture_27142 pms_capture 4 27142 NULL
87211 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
87212 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
87213 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
87214 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
87215 +msg_set_51725 msg_set 3 51725 NULL
87216 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
87217 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
87218 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
87219 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
87220 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
87221 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
87222 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
87223 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87224 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
87225 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
87226 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
87227 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
87228 +sys_bind_10799 sys_bind 3 10799 NULL
87229 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
87230 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
87231 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
87232 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
87233 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
87234 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
87235 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
87236 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
87237 +send_command_10832 send_command 4 10832 NULL
87238 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
87239 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
87240 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
87241 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87242 +proc_read_43614 proc_read 3 43614 NULL
87243 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
87244 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
87245 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
87246 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
87247 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
87248 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
87249 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
87250 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
87251 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
87252 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87253 +vmalloc_15464 vmalloc 1 15464 NULL
87254 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
87255 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
87256 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
87257 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
87258 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
87259 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
87260 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
87261 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
87262 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
87263 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
87264 +adu_write_30487 adu_write 3 30487 NULL
87265 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
87266 +get_scq_10897 get_scq 2 10897 NULL
87267 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
87268 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
87269 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
87270 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
87271 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
87272 +load_module_60056 load_module 2 60056 NULL nohasharray
87273 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
87274 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
87275 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
87276 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
87277 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
87278 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
87279 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
87280 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
87281 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
87282 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
87283 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
87284 +user_read_51881 user_read 3 51881 NULL
87285 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
87286 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
87287 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
87288 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
87289 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
87290 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
87291 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
87292 +async_setkey_35521 async_setkey 3 35521 NULL
87293 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
87294 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
87295 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
87296 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
87297 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
87298 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
87299 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87300 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87301 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
87302 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
87303 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
87304 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
87305 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
87306 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
87307 +alloc_context_3194 alloc_context 1 3194 NULL
87308 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
87309 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
87310 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
87311 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
87312 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
87313 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
87314 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
87315 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
87316 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
87317 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
87318 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87319 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
87320 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
87321 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
87322 +init_state_60165 init_state 2 60165 NULL
87323 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
87324 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
87325 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
87326 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
87327 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
87328 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
87329 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
87330 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
87331 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
87332 +calc_hmac_32010 calc_hmac 3 32010 NULL
87333 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
87334 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
87335 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
87336 +kernel_readv_35617 kernel_readv 3 35617 NULL
87337 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
87338 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
87339 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
87340 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
87341 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
87342 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
87343 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
87344 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
87345 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
87346 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
87347 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
87348 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
87349 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
87350 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
87351 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87352 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
87353 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
87354 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
87355 +store_debug_level_35652 store_debug_level 3 35652 NULL
87356 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87357 +read_flush_43851 read_flush 3 43851 NULL
87358 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
87359 +cmm_write_2896 cmm_write 3 2896 NULL
87360 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
87361 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
87362 +tunables_write_59563 tunables_write 3 59563 NULL
87363 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
87364 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
87365 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
87366 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
87367 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
87368 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
87369 +dm_table_create_35687 dm_table_create 3 35687 NULL
87370 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
87371 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
87372 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
87373 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
87374 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
87375 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
87376 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
87377 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
87378 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
87379 +debug_read_19322 debug_read 3 19322 NULL
87380 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
87381 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
87382 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
87383 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
87384 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
87385 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
87386 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
87387 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
87388 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
87389 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
87390 +doc_probe_23285 doc_probe 1 23285 NULL
87391 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
87392 +SendString_43928 SendString 3 43928 NULL
87393 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
87394 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
87395 +retry_count_read_52129 retry_count_read 3 52129 NULL
87396 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87397 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
87398 +read_zero_19366 read_zero 3 19366 NULL
87399 +bch_alloc_4593 bch_alloc 1 4593 NULL
87400 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
87401 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
87402 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
87403 +raid5_resize_63306 raid5_resize 2 63306 NULL
87404 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
87405 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
87406 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
87407 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
87408 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
87409 +depth_write_3021 depth_write 3 3021 NULL
87410 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
87411 +read_file_stations_35795 read_file_stations 3 35795 NULL
87412 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
87413 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
87414 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
87415 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
87416 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
87417 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
87418 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
87419 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
87420 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
87421 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
87422 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
87423 +driver_names_read_60399 driver_names_read 3 60399 NULL
87424 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
87425 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
87426 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
87427 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
87428 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
87429 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
87430 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
87431 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
87432 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
87433 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
87434 +rx_data_60442 rx_data 4 60442 NULL
87435 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
87436 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
87437 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
87438 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
87439 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87440 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
87441 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
87442 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
87443 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
87444 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
87445 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
87446 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
87447 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
87448 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
87449 +construct_key_11329 construct_key 3 11329 NULL
87450 +evm_write_key_27715 evm_write_key 3 27715 NULL
87451 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
87452 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
87453 +filldir_55137 filldir 3 55137 NULL
87454 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
87455 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
87456 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
87457 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
87458 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
87459 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
87460 +sel_write_create_11353 sel_write_create 3 11353 NULL
87461 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
87462 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
87463 +hwflags_read_52318 hwflags_read 3 52318 NULL
87464 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
87465 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
87466 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
87467 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
87468 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
87469 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
87470 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
87471 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
87472 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
87473 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
87474 +nfsd_read_19568 nfsd_read 5 19568 NULL
87475 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
87476 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
87477 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
87478 +kcalloc_27770 kcalloc 1-2 27770 NULL
87479 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
87480 +bm_status_read_19583 bm_status_read 3 19583 NULL
87481 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
87482 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
87483 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
87484 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
87485 +acl_alloc_35979 acl_alloc 1 35979 NULL
87486 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
87487 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
87488 +str_to_user_11411 str_to_user 2 11411 NULL
87489 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
87490 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
87491 +trace_options_read_11419 trace_options_read 3 11419 NULL
87492 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
87493 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
87494 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
87495 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
87496 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
87497 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
87498 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
87499 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
87500 +console_store_36007 console_store 4 36007 NULL
87501 +bttv_read_11432 bttv_read 3 11432 NULL
87502 +key_key_read_3241 key_key_read 3 3241 NULL
87503 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
87504 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
87505 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
87506 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
87507 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
87508 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87509 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
87510 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
87511 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
87512 +um_idi_write_18293 um_idi_write 3 18293 NULL
87513 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
87514 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
87515 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
87516 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
87517 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
87518 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
87519 +sys_init_module_36047 sys_init_module 2 36047 NULL
87520 +read_profile_27859 read_profile 3 27859 NULL
87521 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
87522 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
87523 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
87524 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
87525 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
87526 +refill_pool_19477 refill_pool 2 19477 NULL
87527 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
87528 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
87529 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
87530 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
87531 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
87532 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
87533 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
87534 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
87535 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
87536 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
87537 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
87538 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
87539 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
87540 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
87541 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
87542 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
87543 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87544 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
87545 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
87546 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
87547 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
87548 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
87549 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
87550 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
87551 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
87552 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
87553 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
87554 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
87555 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
87556 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
87557 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
87558 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
87559 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
87560 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87561 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
87562 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
87563 +init_data_container_60709 init_data_container 1 60709 NULL
87564 +p9_client_read_19750 p9_client_read 5 19750 NULL
87565 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
87566 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
87567 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
87568 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
87569 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
87570 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
87571 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
87572 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
87573 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
87574 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
87575 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
87576 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
87577 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
87578 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
87579 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
87580 +send_stream_3397 send_stream 4 3397 NULL
87581 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
87582 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
87583 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
87584 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
87585 +msix_map_region_3411 msix_map_region 3 3411 NULL
87586 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
87587 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
87588 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
87589 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
87590 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
87591 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
87592 +opticon_write_60775 opticon_write 4 60775 NULL
87593 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
87594 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
87595 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
87596 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
87597 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
87598 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
87599 +vip_read_19832 vip_read 3 19832 NULL
87600 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
87601 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
87602 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
87603 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
87604 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
87605 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
87606 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
87607 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
87608 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
87609 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
87610 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
87611 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
87612 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
87613 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
87614 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
87615 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
87616 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
87617 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
87618 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
87619 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
87620 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
87621 +split_11691 split 2 11691 NULL
87622 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
87623 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
87624 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
87625 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
87626 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
87627 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
87628 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
87629 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
87630 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
87631 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
87632 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
87633 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
87634 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
87635 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
87636 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
87637 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
87638 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
87639 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
87640 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
87641 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
87642 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
87643 +spidev_write_44510 spidev_write 3 44510 NULL
87644 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
87645 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
87646 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
87647 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
87648 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
87649 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
87650 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
87651 +kone_receive_4690 kone_receive 4 4690 NULL
87652 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
87653 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
87654 +evtchn_read_3569 evtchn_read 3 3569 NULL
87655 +video_read_28148 video_read 3 28148 NULL
87656 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
87657 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
87658 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
87659 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
87660 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
87661 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
87662 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
87663 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
87664 +vc_resize_3585 vc_resize 2-3 3585 NULL
87665 +gluebi_write_27905 gluebi_write 3 27905 NULL
87666 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
87667 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
87668 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
87669 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
87670 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
87671 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
87672 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
87673 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
87674 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
87675 +pti_char_write_60960 pti_char_write 3 60960 NULL
87676 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
87677 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
87678 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
87679 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
87680 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
87681 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
87682 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
87683 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
87684 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
87685 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
87686 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
87687 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
87688 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
87689 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
87690 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
87691 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
87692 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
87693 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
87694 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
87695 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
87696 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
87697 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
87698 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
87699 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
87700 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
87701 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
87702 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
87703 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
87704 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
87705 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
87706 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
87707 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
87708 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
87709 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
87710 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
87711 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
87712 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
87713 +symtab_init_61050 symtab_init 2 61050 NULL
87714 +team_options_register_20091 team_options_register 3 20091 NULL
87715 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
87716 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
87717 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
87718 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
87719 +mpi_resize_44674 mpi_resize 2 44674 NULL
87720 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
87721 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
87722 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
87723 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
87724 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
87725 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
87726 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
87727 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
87728 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
87729 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
87730 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
87731 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
87732 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87733 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
87734 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
87735 +pms_read_53873 pms_read 3 53873 NULL
87736 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
87737 +get_derived_key_61100 get_derived_key 4 61100 NULL
87738 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
87739 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
87740 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
87741 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
87742 +dm_read_15674 dm_read 3 15674 NULL
87743 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
87744 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
87745 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
87746 +kone_send_63435 kone_send 4 63435 NULL
87747 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
87748 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
87749 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
87750 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
87751 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
87752 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
87753 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
87754 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
87755 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
87756 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
87757 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
87758 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
87759 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
87760 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
87761 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
87762 +send_packet_52960 send_packet 4 52960 NULL
87763 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
87764 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
87765 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
87766 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
87767 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
87768 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
87769 +put_cmsg_36589 put_cmsg 4 36589 NULL
87770 +__vmalloc_61168 __vmalloc 1 61168 NULL
87771 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
87772 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
87773 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
87774 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
87775 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
87776 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
87777 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
87778 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
87779 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
87780 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
87781 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
87782 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
87783 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
87784 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
87785 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
87786 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
87787 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
87788 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
87789 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
87790 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
87791 +get_fd_set_3866 get_fd_set 1 3866 NULL
87792 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
87793 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
87794 +unlink_queued_645 unlink_queued 3-4 645 NULL
87795 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
87796 +sisusb_write_44834 sisusb_write 3 44834 NULL
87797 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
87798 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
87799 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
87800 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
87801 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
87802 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
87803 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
87804 +nvram_write_3894 nvram_write 3 3894 NULL
87805 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
87806 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
87807 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
87808 +vcs_write_3910 vcs_write 3 3910 NULL
87809 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
87810 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
87811 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
87812 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
87813 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
87814 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
87815 +do_tty_write_44896 do_tty_write 5 44896 NULL
87816 +set_powered_12129 set_powered 4 12129 NULL
87817 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
87818 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
87819 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
87820 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
87821 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
87822 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
87823 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
87824 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
87825 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
87826 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
87827 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
87828 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
87829 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
87830 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
87831 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
87832 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
87833 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
87834 +gather_array_56641 gather_array 3 56641 NULL
87835 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
87836 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
87837 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
87838 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
87839 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
87840 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
87841 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
87842 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
87843 +do_add_counters_3992 do_add_counters 3 3992 NULL
87844 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
87845 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
87846 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
87847 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
87848 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
87849 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
87850 +mei_write_4005 mei_write 3 4005 NULL
87851 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
87852 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
87853 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
87854 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
87855 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
87856 +receive_copy_12216 receive_copy 3 12216 NULL
87857 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
87858 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
87859 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
87860 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
87861 +change_xattr_61390 change_xattr 5 61390 NULL
87862 +find_skb_20431 find_skb 2 20431 NULL
87863 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
87864 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
87865 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
87866 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
87867 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
87868 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
87869 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
87870 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
87871 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
87872 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
87873 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
87874 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
87875 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
87876 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
87877 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
87878 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
87879 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
87880 +read_buf_20469 read_buf 2 20469 NULL
87881 +cm_write_36858 cm_write 3 36858 NULL
87882 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
87883 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
87884 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
87885 +sel_write_user_45060 sel_write_user 3 45060 NULL
87886 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
87887 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
87888 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
87889 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
87890 +fast_user_write_20494 fast_user_write 5 20494 NULL
87891 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
87892 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
87893 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
87894 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
87895 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
87896 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
87897 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
87898 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
87899 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
87900 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
87901 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
87902 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
87903 +osst_read_40237 osst_read 3 40237 NULL
87904 +tm6000_read_4151 tm6000_read 3 4151 NULL
87905 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
87906 +usbdev_read_45114 usbdev_read 3 45114 NULL
87907 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
87908 +spi_execute_28736 spi_execute 5 28736 NULL
87909 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
87910 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
87911 +get_alua_req_4166 get_alua_req 3 4166 NULL
87912 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
87913 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
87914 +venus_create_20555 venus_create 4 20555 NULL
87915 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
87916 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
87917 +receive_packet_12367 receive_packet 2 12367 NULL
87918 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
87919 +mem_write_22232 mem_write 3 22232 NULL
87920 +read_file_bool_4180 read_file_bool 3 4180 NULL
87921 +send_to_tty_45141 send_to_tty 3 45141 NULL
87922 +fops_read_40672 fops_read 3 40672 NULL
87923 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
87924 +write_leb_36957 write_leb 5 36957 NULL
87925 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
87926 +device_write_45156 device_write 3 45156 NULL
87927 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
87928 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
87929 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
87930 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
87931 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
87932 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
87933 +isp1760_register_628 isp1760_register 1-2 628 NULL
87934 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
87935 +lirc_write_20604 lirc_write 3 20604 NULL
87936 +sel_write_member_28800 sel_write_member 3 28800 NULL
87937 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
87938 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
87939 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
87940 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
87941 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
87942 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
87943 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
87944 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
87945 +setxattr_37006 setxattr 4 37006 NULL
87946 +add_child_45201 add_child 4 45201 NULL
87947 +seq_open_private_61589 seq_open_private 3 61589 NULL
87948 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
87949 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
87950 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
87951 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
87952 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
87953 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
87954 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
87955 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
87956 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
87957 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
87958 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
87959 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
87960 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
87961 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
87962 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
87963 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
87964 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
87965 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
87966 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
87967 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
87968 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
87969 +resize_stripes_61650 resize_stripes 2 61650 NULL
87970 +n2_run_53459 n2_run 3 53459 NULL
87971 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
87972 +parse_command_37079 parse_command 2 37079 NULL
87973 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
87974 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
87975 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
87976 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
87977 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
87978 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
87979 +insert_one_name_61668 insert_one_name 7 61668 NULL
87980 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
87981 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
87982 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
87983 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
87984 +lock_loop_61681 lock_loop 1 61681 NULL
87985 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
87986 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
87987 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
87988 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
87989 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
87990 +push_rx_28939 push_rx 3 28939 NULL
87991 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
87992 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
87993 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
87994 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
87995 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
87996 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
87997 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
87998 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
87999 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
88000 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
88001 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
88002 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
88003 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
88004 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
88005 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
88006 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
88007 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
88008 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
88009 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
88010 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
88011 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
88012 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
88013 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
88014 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
88015 +bin_uuid_28999 bin_uuid 3 28999 NULL
88016 +sys_sendto_20809 sys_sendto 6 20809 NULL
88017 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
88018 +set_registers_53582 set_registers 3 53582 NULL
88019 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
88020 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
88021 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
88022 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
88023 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
88024 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
88025 +keymap_store_45406 keymap_store 4 45406 NULL
88026 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
88027 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
88028 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
88029 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
88030 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
88031 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
88032 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
88033 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
88034 +__do_replace_37227 __do_replace 5 37227 NULL
88035 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
88036 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
88037 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
88038 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
88039 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
88040 +tso_fragment_29050 tso_fragment 3 29050 NULL
88041 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
88042 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
88043 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
88044 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
88045 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
88046 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
88047 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
88048 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
88049 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
88050 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
88051 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
88052 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
88053 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
88054 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
88055 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
88056 +set_link_security_4502 set_link_security 4 4502 NULL
88057 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
88058 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
88059 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
88060 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
88061 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
88062 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
88063 +mmio_read_40348 mmio_read 4 40348 NULL
88064 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
88065 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
88066 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
88067 +ivtv_write_12721 ivtv_write 3 12721 NULL
88068 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
88069 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
88070 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
88071 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
88072 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
88073 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
88074 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
88075 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
88076 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
88077 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
88078 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
88079 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
88080 +send_msg_37323 send_msg 4 37323 NULL
88081 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
88082 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
88083 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
88084 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
88085 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
88086 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
88087 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
88088 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
88089 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
88090 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
88091 +reshape_ring_29147 reshape_ring 2 29147 NULL
88092 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
88093 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
88094 +copy_macs_45534 copy_macs 4 45534 NULL
88095 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
88096 +listxattr_12769 listxattr 3 12769 NULL
88097 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
88098 +wdm_write_53735 wdm_write 3 53735 NULL
88099 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
88100 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
88101 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
88102 +mempool_create_29437 mempool_create 1 29437 NULL
88103 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
88104 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
88105 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
88106 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
88107 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
88108 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
88109 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
88110 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
88111 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
88112 +mgmt_event_12810 mgmt_event 4 12810 NULL
88113 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
88114 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
88115 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
88116 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
88117 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
88118 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
88119 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
88120 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
88121 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
88122 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
88123 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
88124 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
88125 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
88126 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
88127 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
88128 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
88129 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
88130 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
88131 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
88132 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
88133 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
88134 +recover_peb_29238 recover_peb 6-7 29238 NULL
88135 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
88136 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
88137 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
88138 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
88139 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
88140 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
88141 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
88142 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
88143 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
88144 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
88145 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
88146 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
88147 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
88148 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
88149 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
88150 +do_pselect_62061 do_pselect 1 62061 NULL
88151 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
88152 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
88153 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
88154 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
88155 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
88156 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
88157 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
88158 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
88159 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
88160 +sg_read_25799 sg_read 3 25799 NULL
88161 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
88162 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
88163 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
88164 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
88165 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
88166 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
88167 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
88168 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
88169 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
88170 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
88171 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
88172 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
88173 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
88174 +new_skb_21148 new_skb 1 21148 NULL
88175 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
88176 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
88177 +bm_status_write_12964 bm_status_write 3 12964 NULL
88178 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
88179 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
88180 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
88181 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
88182 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
88183 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
88184 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
88185 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
88186 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
88187 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
88188 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
88189 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
88190 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
88191 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
88192 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
88193 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
88194 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
88195 +video_usercopy_62151 video_usercopy 2 62151 NULL
88196 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
88197 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
88198 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
88199 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
88200 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
88201 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
88202 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
88203 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
88204 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
88205 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
88206 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
88207 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
88208 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
88209 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
88210 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
88211 +input_ff_create_21240 input_ff_create 2 21240 NULL
88212 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
88213 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
88214 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
88215 +amthi_read_45831 amthi_read 4 45831 NULL
88216 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
88217 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
88218 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
88219 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
88220 +sys_ipc_4889 sys_ipc 3 4889 NULL
88221 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
88222 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
88223 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
88224 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
88225 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
88226 +do_register_entry_29478 do_register_entry 4 29478 NULL
88227 +isdn_write_45863 isdn_write 3 45863 NULL
88228 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
88229 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
88230 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
88231 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
88232 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
88233 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
88234 +_malloc_54077 _malloc 1 54077 NULL
88235 +add_res_range_21310 add_res_range 4 21310 NULL
88236 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
88237 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
88238 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
88239 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
88240 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
88241 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
88242 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
88243 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
88244 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
88245 +create_xattr_54106 create_xattr 5 54106 NULL
88246 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
88247 +ep_write_59008 ep_write 3 59008 NULL
88248 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
88249 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
88250 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
88251 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
88252 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
88253 +alloc_mr_45935 alloc_mr 1 45935 NULL
88254 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
88255 +isku_receive_54130 isku_receive 4 54130 NULL
88256 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
88257 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
88258 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
88259 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
88260 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
88261 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
88262 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
88263 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
88264 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
88265 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
88266 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
88267 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
88268 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
88269 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
88270 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
88271 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
88272 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
88273 +comedi_read_13199 comedi_read 3 13199 NULL
88274 +flash_write_62354 flash_write 3 62354 NULL
88275 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
88276 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
88277 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
88278 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
88279 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
88280 +proc_file_read_53905 proc_file_read 3 53905 NULL
88281 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
88282 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
88283 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
88284 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
88285 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
88286 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
88287 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
88288 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
88289 +cru_detect_11272 cru_detect 1 11272 NULL
88290 +altera_irscan_62396 altera_irscan 2 62396 NULL
88291 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
88292 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
88293 +fw_download_code_13249 fw_download_code 3 13249 NULL
88294 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
88295 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
88296 +set_ssp_62411 set_ssp 4 62411 NULL
88297 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
88298 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
88299 +get_free_entries_46030 get_free_entries 1 46030 NULL
88300 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
88301 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
88302 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
88303 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
88304 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
88305 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
88306 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
88307 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
88308 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
88309 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
88310 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
88311 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
88312 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
88313 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
88314 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
88315 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
88316 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
88317 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
88318 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
88319 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
88320 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
88321 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
88322 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
88323 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
88324 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
88325 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
88326 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
88327 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
88328 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
88329 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
88330 +probes_write_29711 probes_write 3 29711 NULL
88331 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
88332 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
88333 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
88334 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
88335 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
88336 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
88337 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
88338 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
88339 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
88340 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
88341 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
88342 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
88343 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
88344 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
88345 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
88346 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
88347 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
88348 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
88349 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
88350 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
88351 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
88352 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
88353 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
88354 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
88355 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
88356 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
88357 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
88358 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
88359 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
88360 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
88361 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
88362 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
88363 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
88364 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
88365 +isdn_read_50021 isdn_read 3 50021 NULL
88366 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
88367 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
88368 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
88369 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
88370 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
88371 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
88372 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
88373 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
88374 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
88375 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
88376 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
88377 +get_subdir_62581 get_subdir 3 62581 NULL
88378 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
88379 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
88380 +vfs_readv_38011 vfs_readv 3 38011 NULL
88381 +keyring_read_13438 keyring_read 3 13438 NULL
88382 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
88383 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
88384 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
88385 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
88386 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
88387 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
88388 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
88389 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
88390 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
88391 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
88392 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
88393 +ftrace_write_29551 ftrace_write 3 29551 NULL
88394 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
88395 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
88396 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
88397 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
88398 +dev_write_7708 dev_write 3 7708 NULL
88399 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
88400 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
88401 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
88402 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
88403 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
88404 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
88405 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
88406 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
88407 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
88408 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
88409 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
88410 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
88411 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
88412 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
88413 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
88414 +bm_init_13529 bm_init 2 13529 NULL
88415 +check586_29914 check586 2 29914 NULL
88416 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
88417 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
88418 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
88419 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
88420 +pg_read_17276 pg_read 3 17276 NULL
88421 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
88422 +ep0_read_38095 ep0_read 3 38095 NULL
88423 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
88424 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
88425 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
88426 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
88427 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
88428 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
88429 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
88430 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
88431 +l2down_create_21755 l2down_create 4 21755 NULL
88432 +alloc_tio_13564 alloc_tio 3 13564 NULL
88433 +viacam_read_54526 viacam_read 3 54526 NULL
88434 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
88435 +tunables_read_36385 tunables_read 3 36385 NULL
88436 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
88437 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
88438 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
88439 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
88440 +setsockopt_54539 setsockopt 5 54539 NULL
88441 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
88442 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
88443 +tty_register_device_4544 tty_register_device 2 4544 NULL
88444 +cache_write_13589 cache_write 3 13589 NULL
88445 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
88446 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
88447 +key_replays_read_62746 key_replays_read 3 62746 NULL
88448 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
88449 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
88450 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
88451 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
88452 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
88453 +cdev_add_38176 cdev_add 2-3 38176 NULL
88454 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
88455 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
88456 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
88457 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
88458 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
88459 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
88460 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
88461 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
88462 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
88463 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
88464 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
88465 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
88466 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
88467 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
88468 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
88469 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
88470 +packet_snd_13634 packet_snd 3 13634 NULL
88471 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
88472 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
88473 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
88474 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
88475 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
88476 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
88477 +drp_wmove_30043 drp_wmove 4 30043 NULL
88478 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
88479 +cache_downcall_13666 cache_downcall 3 13666 NULL
88480 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
88481 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
88482 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
88483 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
88484 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
88485 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
88486 +tty_write_5494 tty_write 3 5494 NULL
88487 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
88488 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
88489 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
88490 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
88491 +teiup_create_43201 teiup_create 3 43201 NULL
88492 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
88493 +filldir64_46469 filldir64 3 46469 NULL
88494 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
88495 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
88496 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
88497 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
88498 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
88499 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
88500 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
88501 +spidev_message_5518 spidev_message 3 5518 NULL
88502 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
88503 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
88504 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
88505 +evm_read_key_54674 evm_read_key 3 54674 NULL
88506 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
88507 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
88508 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
88509 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
88510 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
88511 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
88512 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
88513 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
88514 +u32_array_read_2219 u32_array_read 3 2219 NULL
88515 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
88516 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
88517 +sys_add_key_61288 sys_add_key 4 61288 NULL
88518 +kmsg_read_46514 kmsg_read 3 46514 NULL
88519 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
88520 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
88521 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
88522 +recv_stream_30138 recv_stream 4 30138 NULL
88523 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
88524 +getdqbuf_62908 getdqbuf 1 62908 NULL
88525 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
88526 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
88527 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
88528 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
88529 +fir16_create_5574 fir16_create 3 5574 NULL
88530 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
88531 +pt_write_40159 pt_write 3 40159 NULL
88532 +bioset_create_5580 bioset_create 1 5580 NULL
88533 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
88534 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
88535 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
88536 +kzalloc_54740 kzalloc 1 54740 NULL
88537 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
88538 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
88539 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
88540 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
88541 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
88542 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
88543 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
88544 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
88545 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
88546 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
88547 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
88548 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
88549 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
88550 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
88551 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
88552 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
88553 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
88554 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
88555 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
88556 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
88557 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
88558 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
88559 +ti_recv_22027 ti_recv 4 22027 NULL
88560 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
88561 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
88562 +nfsd_write_54809 nfsd_write 6 54809 NULL
88563 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
88564 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
88565 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
88566 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
88567 +get_skb_63008 get_skb 2 63008 NULL
88568 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
88569 +netlink_send_38434 netlink_send 5 38434 NULL
88570 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
88571 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
88572 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
88573 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
88574 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
88575 +write_rio_54837 write_rio 3 54837 NULL
88576 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
88577 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
88578 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
88579 +get_arg_5694 get_arg 3 5694 NULL
88580 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
88581 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
88582 +compat_readv_30273 compat_readv 3 30273 NULL
88583 +printer_read_54851 printer_read 3 54851 NULL
88584 +mem_rw_22085 mem_rw 3 22085 NULL
88585 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
88586 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
88587 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
88588 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
88589 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
88590 +unlink1_63059 unlink1 3 63059 NULL
88591 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
88592 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
88593 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
88594 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
88595 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
88596 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
88597 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
88598 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
88599 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
88600 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
88601 +dev_names_read_38509 dev_names_read 3 38509 NULL
88602 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
88603 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
88604 +get_packet_5747 get_packet 3 5747 NULL
88605 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
88606 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
88607 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
88608 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
88609 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
88610 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
88611 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
88612 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
88613 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
88614 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
88615 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
88616 +resource_from_user_30341 resource_from_user 3 30341 NULL
88617 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
88618 +sound_write_5102 sound_write 3 5102 NULL
88619 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
88620 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
88621 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
88622 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
88623 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
88624 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
88625 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
88626 +com90xx_found_13974 com90xx_found 3 13974 NULL
88627 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
88628 +qcam_read_13977 qcam_read 3 13977 NULL
88629 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
88630 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
88631 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
88632 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
88633 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
88634 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
88635 +generic_readlink_32654 generic_readlink 3 32654 NULL
88636 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
88637 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
88638 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
88639 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
88640 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
88641 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
88642 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
88643 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
88644 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
88645 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
88646 +concat_writev_21451 concat_writev 3 21451 NULL
88647 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
88648 +_queue_data_54983 _queue_data 4 54983 NULL
88649 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
88650 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
88651 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
88652 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
88653 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
88654 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
88655 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
88656 +setup_req_5848 setup_req 3 5848 NULL
88657 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
88658 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
88659 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
88660 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
88661 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
88662 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
88663 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
88664 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
88665 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
88666 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
88667 +cma_create_area_38642 cma_create_area 2 38642 NULL
88668 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
88669 +sriov_enable_59689 sriov_enable 2 59689 NULL
88670 +enable_write_30456 enable_write 3 30456 NULL
88671 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
88672 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
88673 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
88674 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
88675 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
88676 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
88677 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
88678 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
88679 +port_show_regs_5904 port_show_regs 3 5904 NULL
88680 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
88681 +ptp_read_63251 ptp_read 4 63251 NULL
88682 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
88683 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
88684 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
88685 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
88686 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
88687 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
88688 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
88689 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
88690 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
88691 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
88692 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
88693 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
88694 +read_dma_55086 read_dma 3 55086 NULL
88695 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
88696 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
88697 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
88698 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
88699 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
88700 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
88701 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
88702 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
88703 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
88704 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
88705 +em_canid_change_14150 em_canid_change 3 14150 NULL
88706 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
88707 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
88708 +fb_write_46924 fb_write 3 46924 NULL
88709 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
88710 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
88711 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
88712 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
88713 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
88714 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
88715 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
88716 +udf_readpages_38761 udf_readpages 4 38761 NULL
88717 +reada_add_block_54247 reada_add_block 2 54247 NULL
88718 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
88719 +proc_info_read_63344 proc_info_read 3 63344 NULL
88720 +pep_indicate_38611 pep_indicate 5 38611 NULL
88721 +set_le_30581 set_le 4 30581 NULL
88722 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
88723 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
88724 +alloc_private_22399 alloc_private 2 22399 NULL
88725 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
88726 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
88727 +zoran_write_22404 zoran_write 3 22404 NULL
88728 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
88729 +idmouse_read_63374 idmouse_read 3 63374 NULL
88730 +queue_reply_22416 queue_reply 3 22416 NULL
88731 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
88732 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
88733 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
88734 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
88735 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
88736 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
88737 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
88738 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
88739 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
88740 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
88741 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
88742 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
88743 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
88744 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
88745 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
88746 +sys_select_38827 sys_select 1 38827 NULL
88747 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
88748 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
88749 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
88750 +direct_entry_38836 direct_entry 3 38836 NULL
88751 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
88752 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
88753 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
88754 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
88755 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
88756 +write_head_30481 write_head 4 30481 NULL
88757 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
88758 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
88759 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
88760 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
88761 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
88762 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
88763 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
88764 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
88765 +agp_remap_30665 agp_remap 2 30665 NULL
88766 +interfaces_38859 interfaces 2 38859 NULL
88767 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
88768 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
88769 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
88770 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
88771 +qc_capture_19298 qc_capture 3 19298 NULL
88772 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
88773 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
88774 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
88775 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
88776 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
88777 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
88778 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
88779 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
88780 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
88781 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
88782 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
88783 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
88784 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
88785 +read_kcore_63488 read_kcore 3 63488 NULL
88786 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
88787 +__skb_cow_39254 __skb_cow 2 39254 NULL
88788 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
88789 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
88790 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
88791 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
88792 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
88793 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
88794 +mousedev_read_47123 mousedev_read 3 47123 NULL
88795 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
88796 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
88797 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
88798 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
88799 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
88800 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
88801 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
88802 +vme_user_read_55338 vme_user_read 3 55338 NULL
88803 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
88804 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
88805 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
88806 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
88807 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
88808 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
88809 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
88810 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
88811 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
88812 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
88813 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
88814 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
88815 +snapshot_read_22601 snapshot_read 3 22601 NULL
88816 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
88817 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
88818 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
88819 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
88820 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
88821 +__send_to_port_55383 __send_to_port 3 55383 NULL
88822 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
88823 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
88824 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
88825 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
88826 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
88827 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
88828 +get_nodes_39012 get_nodes 3 39012 NULL
88829 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
88830 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
88831 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
88832 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
88833 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
88834 +create_subvol_30836 create_subvol 4 30836 NULL
88835 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
88836 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
88837 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
88838 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
88839 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
88840 +read_oldmem_55658 read_oldmem 3 55658 NULL
88841 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
88842 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
88843 +options_write_47243 options_write 3 47243 NULL
88844 +module_alloc_63630 module_alloc 1 63630 NULL
88845 +alloc_skb_55439 alloc_skb 1 55439 NULL
88846 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
88847 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
88848 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
88849 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
88850 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
88851 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
88852 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
88853 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
88854 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
88855 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
88856 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
88857 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
88858 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
88859 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
88860 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
88861 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
88862 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
88863 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
88864 +vbi_read_63673 vbi_read 3 63673 NULL
88865 +tun_get_user_39099 tun_get_user 4 39099 NULL
88866 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
88867 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
88868 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
88869 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
88870 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
88871 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
88872 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
88873 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
88874 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
88875 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
88876 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
88877 +ax25_output_22736 ax25_output 2 22736 NULL
88878 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
88879 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
88880 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
88881 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
88882 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
88883 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
88884 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
88885 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
88886 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
88887 +hid_input_report_32458 hid_input_report 4 32458 NULL
88888 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
88889 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
88890 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
88891 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
88892 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
88893 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
88894 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
88895 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
88896 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
88897 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
88898 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
88899 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
88900 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
88901 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
88902 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
88903 +get_info_55681 get_info 3 55681 NULL
88904 +setkey_14987 setkey 3 14987 NULL
88905 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
88906 +init_list_set_39188 init_list_set 2-3 39188 NULL
88907 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
88908 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
88909 +l2up_create_6430 l2up_create 3 6430 NULL
88910 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
88911 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
88912 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
88913 +add_partition_55588 add_partition 2 55588 NULL
88914 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
88915 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
88916 +depth_read_31112 depth_read 3 31112 NULL
88917 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
88918 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
88919 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
88920 +profile_replace_14652 profile_replace 3 14652 NULL
88921 +vzalloc_47421 vzalloc 1 47421 NULL
88922 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
88923 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
88924 +sys_writev_28384 sys_writev 3 28384 NULL
88925 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
88926 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
88927 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
88928 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
88929 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
88930 +create_attr_set_22861 create_attr_set 1 22861 NULL
88931 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
88932 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
88933 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
88934 +sel_write_load_63830 sel_write_load 3 63830 NULL
88935 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
88936 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
88937 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
88938 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
88939 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
88940 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
88941 +probe_bios_17467 probe_bios 1 17467 NULL
88942 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
88943 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
88944 +mei_read_6507 mei_read 3 6507 NULL
88945 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
88946 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
88947 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
88948 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
88949 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
88950 +SetArea_50835 SetArea 4 50835 NULL
88951 +tpm_read_50344 tpm_read 3 50344 NULL
88952 +newpart_47485 newpart 6 47485 NULL
88953 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
88954 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
88955 +core_sys_select_47494 core_sys_select 1 47494 NULL
88956 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
88957 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
88958 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
88959 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
88960 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
88961 +unlink_simple_47506 unlink_simple 3 47506 NULL
88962 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
88963 +wdm_read_6549 wdm_read 3 6549 NULL
88964 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
88965 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
88966 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
88967 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
88968 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
88969 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
88970 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
88971 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
88972 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
88973 +filter_read_61692 filter_read 3 61692 NULL
88974 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
88975 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
88976 +debugfs_read_62535 debugfs_read 3 62535 NULL
88977 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
88978 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
88979 +divas_write_63901 divas_write 3 63901 NULL
88980 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
88981 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
88982 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
88983 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
88984 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
88985 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
88986 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
88987 +ipw_write_59807 ipw_write 3 59807 NULL
88988 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
88989 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
88990 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
88991 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
88992 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
88993 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
88994 +cycx_setup_47562 cycx_setup 4 47562 NULL
88995 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
88996 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
88997 +set_local_name_55757 set_local_name 4 55757 NULL
88998 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
88999 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
89000 +read_ldt_47570 read_ldt 2 47570 NULL
89001 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
89002 +pci_iomap_47575 pci_iomap 3 47575 NULL
89003 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
89004 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
89005 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
89006 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
89007 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
89008 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
89009 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
89010 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
89011 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
89012 +conf_read_55786 conf_read 3 55786 NULL
89013 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
89014 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
89015 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
89016 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
89017 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
89018 +user_power_read_39414 user_power_read 3 39414 NULL
89019 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
89020 +uea_request_47613 uea_request 4 47613 NULL
89021 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
89022 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
89023 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
89024 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
89025 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
89026 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
89027 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
89028 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
89029 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
89030 +kmemdup_64015 kmemdup 2 64015 NULL
89031 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
89032 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
89033 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
89034 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
89035 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
89036 +oz_events_read_47535 oz_events_read 3 47535 NULL
89037 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
89038 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
89039 +sys_semop_39457 sys_semop 3 39457 NULL
89040 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
89041 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
89042 +update_pmkid_2481 update_pmkid 4 2481 NULL
89043 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
89044 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
89045 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
89046 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
89047 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
89048 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
89049 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
89050 +mpeg_read_6708 mpeg_read 3 6708 NULL
89051 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
89052 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
89053 +sky2_receive_13407 sky2_receive 2 13407 NULL
89054 +krealloc_14908 krealloc 2 14908 NULL
89055 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
89056 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
89057 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
89058 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
89059 +video_proc_write_6724 video_proc_write 3 6724 NULL
89060 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
89061 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
89062 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
89063 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
89064 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
89065 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
89066 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
89067 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
89068 +command_file_write_31318 command_file_write 3 31318 NULL
89069 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
89070 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
89071 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
89072 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
89073 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
89074 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
89075 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
89076 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
89077 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
89078 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
89079 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
89080 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
89081 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
89082 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
89083 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
89084 +int_proc_write_39542 int_proc_write 3 39542 NULL
89085 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
89086 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
89087 +read_file_ani_23161 read_file_ani 3 23161 NULL
89088 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
89089 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
89090 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
89091 +pp_write_39554 pp_write 3 39554 NULL
89092 +ioremap_23172 ioremap 1-2 23172 NULL
89093 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
89094 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
89095 +usblp_write_23178 usblp_write 3 23178 NULL
89096 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
89097 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
89098 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
89099 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
89100 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
89101 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
89102 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
89103 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
89104 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
89105 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
89106 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
89107 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
89108 +__team_options_register_63941 __team_options_register 3 63941 NULL
89109 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
89110 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
89111 +rvmalloc_46873 rvmalloc 1 46873 NULL
89112 +vmap_15025 vmap 2 15025 NULL
89113 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
89114 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
89115 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
89116 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
89117 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
89118 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
89119 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
89120 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
89121 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
89122 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
89123 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
89124 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
89125 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
89126 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
89127 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
89128 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
89129 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
89130 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
89131 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
89132 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
89133 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
89134 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
89135 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
89136 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
89137 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
89138 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
89139 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
89140 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
89141 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
89142 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
89143 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
89144 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
89145 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
89146 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
89147 +alg_setkey_31485 alg_setkey 3 31485 NULL
89148 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
89149 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
89150 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
89151 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
89152 +vhci_read_47878 vhci_read 3 47878 NULL
89153 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
89154 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
89155 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
89156 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
89157 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
89158 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
89159 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
89160 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
89161 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
89162 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
89163 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
89164 +timeout_read_47915 timeout_read 3 47915 NULL
89165 +hidraw_write_31536 hidraw_write 3 31536 NULL
89166 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
89167 +page_readlink_23346 page_readlink 3 23346 NULL
89168 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
89169 +comedi_write_47926 comedi_write 3 47926 NULL
89170 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
89171 +dsp_write_46218 dsp_write 2 46218 NULL
89172 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
89173 +usbvision_read_31555 usbvision_read 3 31555 NULL
89174 +pd_video_read_24510 pd_video_read 3 24510 NULL
89175 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
89176 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
89177 +request_key_async_6990 request_key_async 4 6990 NULL
89178 +ts_write_64336 ts_write 3 64336 NULL
89179 +handle_response_55951 handle_response 5 55951 NULL
89180 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
89181 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
89182 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
89183 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
89184 +osst_write_31581 osst_write 3 31581 NULL
89185 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
89186 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
89187 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
89188 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
89189 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
89190 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
89191 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
89192 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
89193 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
89194 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
89195 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
89196 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
89197 +ilo_write_64378 ilo_write 3 64378 NULL
89198 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
89199 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
89200 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
89201 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
89202 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
89203 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
89204 +copy_from_user_17559 copy_from_user 3 17559 NULL
89205 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
89206 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
89207 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
89208 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
89209 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
89210 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
89211 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
89212 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
89213 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
89214 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
89215 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
89216 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
89217 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
89218 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
89219 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
89220 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
89221 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
89222 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
89223 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
89224 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
89225 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
89226 +__lgread_31668 __lgread 4 31668 NULL
89227 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
89228 +fd_copyin_56247 fd_copyin 3 56247 NULL
89229 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
89230 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
89231 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
89232 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
89233 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
89234 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
89235 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
89236 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
89237 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
89238 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
89239 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
89240 +event_filter_read_23494 event_filter_read 3 23494 NULL
89241 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
89242 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
89243 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
89244 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
89245 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
89246 +pkt_add_39897 pkt_add 3 39897 NULL
89247 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
89248 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
89249 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
89250 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
89251 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
89252 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
89253 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
89254 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
89255 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
89256 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
89257 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
89258 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
89259 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
89260 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
89261 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
89262 +remove_uuid_64505 remove_uuid 4 64505 NULL
89263 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
89264 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
89265 +create_table_16213 create_table 2 16213 NULL
89266 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
89267 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
89268 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
89269 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
89270 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
89271 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
89272 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
89273 +set_discoverable_48141 set_discoverable 4 48141 NULL
89274 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
89275 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
89276 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
89277 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
89278 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
89279 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
89280 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
89281 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
89282 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
89283 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
89284 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
89285 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
89286 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
89287 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
89288 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
89289 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
89290 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
89291 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
89292 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
89293 +dev_read_56369 dev_read 3 56369 NULL
89294 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
89295 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
89296 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
89297 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
89298 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
89299 +init_ipath_48187 init_ipath 1 48187 NULL
89300 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
89301 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
89302 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
89303 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
89304 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
89305 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
89306 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
89307 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
89308 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
89309 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
89310 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
89311 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
89312 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
89313 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
89314 +use_pool_64607 use_pool 2 64607 NULL
89315 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
89316 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
89317 +store_msg_56417 store_msg 3 56417 NULL
89318 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
89319 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
89320 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
89321 +read_file_recv_48232 read_file_recv 3 48232 NULL
89322 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
89323 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
89324 +fanotify_write_64623 fanotify_write 3 64623 NULL
89325 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
89326 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
89327 +fl_create_56435 fl_create 5 56435 NULL
89328 +gnttab_map_56439 gnttab_map 2 56439 NULL
89329 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
89330 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
89331 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
89332 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
89333 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
89334 +set_connectable_56458 set_connectable 4 56458 NULL
89335 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
89336 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
89337 +add_port_54941 add_port 2 54941 NULL
89338 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
89339 +cx18_read_23699 cx18_read 3 23699 NULL
89340 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
89341 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
89342 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
89343 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
89344 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
89345 +send_set_info_48288 send_set_info 7 48288 NULL
89346 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
89347 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
89348 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
89349 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
89350 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
89351 +new_dir_31919 new_dir 3 31919 NULL
89352 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
89353 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
89354 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
89355 +mgmt_control_7349 mgmt_control 3 7349 NULL
89356 +hash_setkey_48310 hash_setkey 3 48310 NULL
89357 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
89358 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
89359 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
89360 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
89361 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
89362 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
89363 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
89364 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
89365 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
89366 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
89367 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
89368 +vb2_write_31948 vb2_write 3 31948 NULL
89369 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
89370 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
89371 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
89372 +ip_options_get_56538 ip_options_get 4 56538 NULL
89373 +write_62671 write 3 62671 NULL
89374 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
89375 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
89376 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
89377 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
89378 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
89379 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
89380 +skb_add_data_48363 skb_add_data 3 48363 NULL
89381 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
89382 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
89383 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
89384 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
89385 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
89386 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
89387 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
89388 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
89389 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
89390 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
89391 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
89392 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
89393 +system_enable_read_25815 system_enable_read 3 25815 NULL
89394 +allocate_probes_40204 allocate_probes 1 40204 NULL
89395 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
89396 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
89397 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
89398 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
89399 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
89400 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
89401 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
89402 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
89403 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
89404 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
89405 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
89406 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
89407 +fs_path_add_15648 fs_path_add 3 15648 NULL
89408 +event_filter_write_56609 event_filter_write 3 56609 NULL
89409 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
89410 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
89411 +xsd_read_15653 xsd_read 3 15653 NULL
89412 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
89413 +p54_init_common_23850 p54_init_common 1 23850 NULL
89414 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
89415 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
89416 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
89417 +garp_request_join_7471 garp_request_join 4 7471 NULL
89418 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
89419 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
89420 +unifi_read_14899 unifi_read 3 14899 NULL
89421 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
89422 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
89423 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
89424 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
89425 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
89426 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
89427 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
89428 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
89429 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
89430 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
89431 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
89432 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
89433 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
89434 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
89435 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
89436 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
89437 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
89438 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
89439 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
89440 +bio_alloc_32095 bio_alloc 2 32095 NULL
89441 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
89442 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
89443 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
89444 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
89445 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
89446 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
89447 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
89448 +send_control_msg_48498 send_control_msg 6 48498 NULL
89449 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
89450 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
89451 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
89452 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
89453 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
89454 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
89455 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
89456 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
89457 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
89458 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
89459 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
89460 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
89461 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
89462 +alloc_tx_32143 alloc_tx 2 32143 NULL
89463 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
89464 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
89465 +hsc_write_55875 hsc_write 3 55875 NULL
89466 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
89467 +do_test_15766 do_test 1 15766 NULL
89468 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
89469 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
89470 +named_distribute_48544 named_distribute 4 48544 NULL
89471 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
89472 +venus_link_32165 venus_link 5 32165 NULL
89473 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
89474 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
89475 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
89476 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
89477 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
89478 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
89479 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
89480 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
89481 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
89482 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
89483 +groups_alloc_7614 groups_alloc 1 7614 NULL
89484 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
89485 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
89486 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
89487 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
89488 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
89489 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
89490 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
89491 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
89492 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
89493 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
89494 +snapshot_write_28351 snapshot_write 3 28351 NULL
89495 +event_enable_read_7074 event_enable_read 3 7074 NULL
89496 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
89497 +do_syslog_56807 do_syslog 3 56807 NULL
89498 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
89499 +pskb_pull_65005 pskb_pull 2 65005 NULL
89500 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
89501 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
89502 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
89503 +unifi_write_65012 unifi_write 3 65012 NULL
89504 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
89505 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
89506 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
89507 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
89508 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
89509 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
89510 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
89511 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
89512 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
89513 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
89514 +if_write_51756 if_write 3 51756 NULL
89515 +insert_dent_65034 insert_dent 7 65034 NULL
89516 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
89517 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
89518 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
89519 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
89520 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
89521 +lc_create_48662 lc_create 3 48662 NULL
89522 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
89523 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
89524 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
89525 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
89526 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
89527 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
89528 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
89529 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
89530 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
89531 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
89532 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
89533 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
89534 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
89535 +altera_drscan_48698 altera_drscan 2 48698 NULL
89536 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
89537 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
89538 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
89539 +power_read_15939 power_read 3 15939 NULL
89540 +recv_msg_48709 recv_msg 4 48709 NULL
89541 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
89542 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
89543 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
89544 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
89545 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
89546 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
89547 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
89548 +revalidate_19043 revalidate 2 19043 NULL
89549 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
89550 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
89551 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
89552 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
89553 +check_header_56930 check_header 2 56930 NULL
89554 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
89555 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
89556 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
89557 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
89558 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
89559 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
89560 +frame_alloc_15981 frame_alloc 4 15981 NULL
89561 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
89562 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
89563 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
89564 +adu_read_24177 adu_read 3 24177 NULL
89565 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
89566 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
89567 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
89568 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
89569 +vfd_write_14717 vfd_write 3 14717 NULL
89570 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
89571 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
89572 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
89573 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
89574 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
89575 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
89576 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
89577 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
89578 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
89579 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
89580 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
89581 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
89582 +register_device_60015 register_device 2-3 60015 NULL
89583 +got_frame_16028 got_frame 2 16028 NULL
89584 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
89585 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
89586 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
89587 +scsi_register_49094 scsi_register 2 49094 NULL
89588 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
89589 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
89590 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
89591 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
89592 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
89593 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
89594 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
89595 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
89596 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
89597 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
89598 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
89599 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
89600 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
89601 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
89602 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
89603 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
89604 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
89605 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
89606 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
89607 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
89608 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
89609 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
89610 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
89611 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
89612 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
89613 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
89614 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
89615 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
89616 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
89617 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
89618 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
89619 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
89620 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
89621 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
89622 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
89623 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
89624 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
89625 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
89626 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
89627 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
89628 +fsm_init_16134 fsm_init 2 16134 NULL
89629 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
89630 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
89631 +disconnect_32521 disconnect 4 32521 NULL
89632 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
89633 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
89634 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
89635 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
89636 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
89637 +ilo_read_32531 ilo_read 3 32531 NULL
89638 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
89639 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
89640 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
89641 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
89642 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
89643 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
89644 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
89645 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
89646 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
89647 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
89648 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
89649 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
89650 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
89651 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
89652 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
89653 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
89654 +card_send_command_40757 card_send_command 3 40757 NULL
89655 +sys_mbind_7990 sys_mbind 5 7990 NULL
89656 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
89657 +pg_write_40766 pg_write 3 40766 NULL
89658 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
89659 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
89660 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
89661 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
89662 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
89663 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
89664 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
89665 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
89666 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
89667 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
89668 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
89669 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
89670 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
89671 +vcs_read_8017 vcs_read 3 8017 NULL
89672 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
89673 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
89674 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
89675 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
89676 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
89677 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
89678 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
89679 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
89680 +copy_and_check_19089 copy_and_check 3 19089 NULL
89681 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
89682 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
89683 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
89684 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
89685 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
89686 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
89687 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
89688 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
89689 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
89690 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
89691 +smk_user_access_24440 smk_user_access 3 24440 NULL
89692 +xd_rw_49020 xd_rw 3-4 49020 NULL
89693 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
89694 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
89695 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
89696 +kvmalloc_32646 kvmalloc 1 32646 NULL
89697 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
89698 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
89699 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
89700 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
89701 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
89702 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
89703 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
89704 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
89705 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
89706 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
89707 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
89708 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
89709 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
89710 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
89711 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
89712 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
89713 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
89714 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
89715 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
89716 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
89717 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
89718 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
89719 +venus_lookup_8121 venus_lookup 4 8121 NULL
89720 +compat_writev_60063 compat_writev 3 60063 NULL
89721 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
89722 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
89723 +read_file_queue_40895 read_file_queue 3 40895 NULL
89724 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
89725 +waiters_read_40902 waiters_read 3 40902 NULL
89726 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
89727 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
89728 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
89729 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
89730 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
89731 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
89732 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
89733 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
89734 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
89735 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
89736 +alloc_dr_65495 alloc_dr 2 65495 NULL
89737 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
89738 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
89739 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
89740 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
89741 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
89742 +rbd_add_16366 rbd_add 3 16366 NULL
89743 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
89744 +pt_read_49136 pt_read 3 49136 NULL
89745 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
89746 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
89747 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
89748 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
89749 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
89750 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
89751 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
89752 new file mode 100644
89753 index 0000000..792ee60
89754 --- /dev/null
89755 +++ b/tools/gcc/size_overflow_plugin.c
89756 @@ -0,0 +1,1930 @@
89757 +/*
89758 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
89759 + * Licensed under the GPL v2, or (at your option) v3
89760 + *
89761 + * Homepage:
89762 + * http://www.grsecurity.net/~ephox/overflow_plugin/
89763 + *
89764 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
89765 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
89766 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
89767 + *
89768 + * Usage:
89769 + * $ 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
89770 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
89771 + */
89772 +
89773 +#include "gcc-plugin.h"
89774 +#include "config.h"
89775 +#include "system.h"
89776 +#include "coretypes.h"
89777 +#include "tree.h"
89778 +#include "tree-pass.h"
89779 +#include "intl.h"
89780 +#include "plugin-version.h"
89781 +#include "tm.h"
89782 +#include "toplev.h"
89783 +#include "function.h"
89784 +#include "tree-flow.h"
89785 +#include "plugin.h"
89786 +#include "gimple.h"
89787 +#include "c-common.h"
89788 +#include "diagnostic.h"
89789 +#include "cfgloop.h"
89790 +
89791 +#if BUILDING_GCC_VERSION >= 4007
89792 +#include "c-tree.h"
89793 +#else
89794 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
89795 +#endif
89796 +
89797 +struct size_overflow_hash {
89798 + const struct size_overflow_hash * const next;
89799 + const char * const name;
89800 + const unsigned int param;
89801 +};
89802 +
89803 +#include "size_overflow_hash.h"
89804 +
89805 +enum marked {
89806 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
89807 +};
89808 +
89809 +static unsigned int call_count = 0;
89810 +
89811 +#define __unused __attribute__((__unused__))
89812 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
89813 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
89814 +#define BEFORE_STMT true
89815 +#define AFTER_STMT false
89816 +#define CREATE_NEW_VAR NULL_TREE
89817 +#define CODES_LIMIT 32
89818 +#define MAX_PARAM 32
89819 +#define MY_STMT GF_PLF_1
89820 +#define NO_CAST_CHECK GF_PLF_2
89821 +
89822 +#if BUILDING_GCC_VERSION == 4005
89823 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
89824 +#endif
89825 +
89826 +int plugin_is_GPL_compatible;
89827 +void debug_gimple_stmt(gimple gs);
89828 +
89829 +static tree expand(struct pointer_set_t *visited, tree lhs);
89830 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
89831 +static tree report_size_overflow_decl;
89832 +static const_tree const_char_ptr_type_node;
89833 +static unsigned int handle_function(void);
89834 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
89835 +static tree get_size_overflow_type(gimple stmt, const_tree node);
89836 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
89837 +
89838 +static struct plugin_info size_overflow_plugin_info = {
89839 + .version = "20130109beta",
89840 + .help = "no-size-overflow\tturn off size overflow checking\n",
89841 +};
89842 +
89843 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
89844 +{
89845 + unsigned int arg_count;
89846 + enum tree_code code = TREE_CODE(*node);
89847 +
89848 + switch (code) {
89849 + case FUNCTION_DECL:
89850 + arg_count = type_num_arguments(TREE_TYPE(*node));
89851 + break;
89852 + case FUNCTION_TYPE:
89853 + case METHOD_TYPE:
89854 + arg_count = type_num_arguments(*node);
89855 + break;
89856 + default:
89857 + *no_add_attrs = true;
89858 + error("%s: %qE attribute only applies to functions", __func__, name);
89859 + return NULL_TREE;
89860 + }
89861 +
89862 + for (; args; args = TREE_CHAIN(args)) {
89863 + tree position = TREE_VALUE(args);
89864 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
89865 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
89866 + *no_add_attrs = true;
89867 + }
89868 + }
89869 + return NULL_TREE;
89870 +}
89871 +
89872 +static const char* get_asm_name(tree node)
89873 +{
89874 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
89875 +}
89876 +
89877 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
89878 +{
89879 + unsigned int arg_count, arg_num;
89880 + enum tree_code code = TREE_CODE(*node);
89881 +
89882 + switch (code) {
89883 + case FUNCTION_DECL:
89884 + arg_count = type_num_arguments(TREE_TYPE(*node));
89885 + break;
89886 + case FUNCTION_TYPE:
89887 + case METHOD_TYPE:
89888 + arg_count = type_num_arguments(*node);
89889 + break;
89890 + case FIELD_DECL:
89891 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
89892 + if (arg_num != 0) {
89893 + *no_add_attrs = true;
89894 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
89895 + }
89896 + return NULL_TREE;
89897 + default:
89898 + *no_add_attrs = true;
89899 + error("%qE attribute only applies to functions", name);
89900 + return NULL_TREE;
89901 + }
89902 +
89903 + for (; args; args = TREE_CHAIN(args)) {
89904 + tree position = TREE_VALUE(args);
89905 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
89906 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
89907 + *no_add_attrs = true;
89908 + }
89909 + }
89910 + return NULL_TREE;
89911 +}
89912 +
89913 +static struct attribute_spec size_overflow_attr = {
89914 + .name = "size_overflow",
89915 + .min_length = 1,
89916 + .max_length = -1,
89917 + .decl_required = true,
89918 + .type_required = false,
89919 + .function_type_required = false,
89920 + .handler = handle_size_overflow_attribute,
89921 +#if BUILDING_GCC_VERSION >= 4007
89922 + .affects_type_identity = false
89923 +#endif
89924 +};
89925 +
89926 +static struct attribute_spec intentional_overflow_attr = {
89927 + .name = "intentional_overflow",
89928 + .min_length = 1,
89929 + .max_length = -1,
89930 + .decl_required = true,
89931 + .type_required = false,
89932 + .function_type_required = false,
89933 + .handler = handle_intentional_overflow_attribute,
89934 +#if BUILDING_GCC_VERSION >= 4007
89935 + .affects_type_identity = false
89936 +#endif
89937 +};
89938 +
89939 +static void register_attributes(void __unused *event_data, void __unused *data)
89940 +{
89941 + register_attribute(&size_overflow_attr);
89942 + register_attribute(&intentional_overflow_attr);
89943 +}
89944 +
89945 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
89946 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
89947 +{
89948 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
89949 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
89950 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
89951 +
89952 + unsigned int m = 0x57559429;
89953 + unsigned int n = 0x5052acdb;
89954 + const unsigned int *key4 = (const unsigned int *)key;
89955 + unsigned int h = len;
89956 + unsigned int k = len + seed + n;
89957 + unsigned long long p;
89958 +
89959 + while (len >= 8) {
89960 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
89961 + len -= 8;
89962 + }
89963 + if (len >= 4) {
89964 + cwmixb(key4[0]) key4 += 1;
89965 + len -= 4;
89966 + }
89967 + if (len)
89968 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
89969 + cwmixb(h ^ (k + n));
89970 + return k ^ h;
89971 +
89972 +#undef cwfold
89973 +#undef cwmixa
89974 +#undef cwmixb
89975 +}
89976 +
89977 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
89978 +{
89979 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
89980 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
89981 + return fn ^ codes;
89982 +}
89983 +
89984 +static inline tree get_original_function_decl(tree fndecl)
89985 +{
89986 + if (DECL_ABSTRACT_ORIGIN(fndecl))
89987 + return DECL_ABSTRACT_ORIGIN(fndecl);
89988 + return fndecl;
89989 +}
89990 +
89991 +static inline gimple get_def_stmt(const_tree node)
89992 +{
89993 + gcc_assert(node != NULL_TREE);
89994 + gcc_assert(TREE_CODE(node) == SSA_NAME);
89995 + return SSA_NAME_DEF_STMT(node);
89996 +}
89997 +
89998 +static unsigned char get_tree_code(const_tree type)
89999 +{
90000 + switch (TREE_CODE(type)) {
90001 + case ARRAY_TYPE:
90002 + return 0;
90003 + case BOOLEAN_TYPE:
90004 + return 1;
90005 + case ENUMERAL_TYPE:
90006 + return 2;
90007 + case FUNCTION_TYPE:
90008 + return 3;
90009 + case INTEGER_TYPE:
90010 + return 4;
90011 + case POINTER_TYPE:
90012 + return 5;
90013 + case RECORD_TYPE:
90014 + return 6;
90015 + case UNION_TYPE:
90016 + return 7;
90017 + case VOID_TYPE:
90018 + return 8;
90019 + case REAL_TYPE:
90020 + return 9;
90021 + case VECTOR_TYPE:
90022 + return 10;
90023 + case REFERENCE_TYPE:
90024 + return 11;
90025 + case OFFSET_TYPE:
90026 + return 12;
90027 + case COMPLEX_TYPE:
90028 + return 13;
90029 + default:
90030 + debug_tree((tree)type);
90031 + gcc_unreachable();
90032 + }
90033 +}
90034 +
90035 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
90036 +{
90037 + gcc_assert(type != NULL_TREE);
90038 +
90039 + while (type && len < CODES_LIMIT) {
90040 + tree_codes[len] = get_tree_code(type);
90041 + len++;
90042 + type = TREE_TYPE(type);
90043 + }
90044 + return len;
90045 +}
90046 +
90047 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
90048 +{
90049 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
90050 + enum tree_code code = TREE_CODE(type);
90051 + size_t len = 0;
90052 +
90053 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
90054 +
90055 + arg = TYPE_ARG_TYPES(type);
90056 + // skip builtins __builtin_constant_p
90057 + if (!arg && DECL_BUILT_IN(fndecl))
90058 + return 0;
90059 +
90060 + if (TREE_CODE_CLASS(code) == tcc_type)
90061 + result = type;
90062 + else
90063 + result = DECL_RESULT(fndecl);
90064 +
90065 + gcc_assert(result != NULL_TREE);
90066 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
90067 +
90068 + if (arg == NULL_TREE) {
90069 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
90070 + arg_field = DECL_ARGUMENT_FLD(fndecl);
90071 + if (arg_field == NULL_TREE)
90072 + return 0;
90073 + arg = TREE_TYPE(arg_field);
90074 + len = add_type_codes(arg, tree_codes, len);
90075 + gcc_assert(len != 0);
90076 + return len;
90077 + }
90078 +
90079 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
90080 + while (arg && len < CODES_LIMIT) {
90081 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
90082 + arg = TREE_CHAIN(arg);
90083 + }
90084 +
90085 + gcc_assert(len != 0);
90086 + return len;
90087 +}
90088 +
90089 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
90090 +{
90091 + unsigned int hash;
90092 + const struct size_overflow_hash *entry;
90093 + unsigned char tree_codes[CODES_LIMIT];
90094 + size_t len;
90095 + const char *func_name = get_asm_name(fndecl);
90096 +
90097 + len = get_function_decl(fndecl, tree_codes);
90098 + if (len == 0)
90099 + return NULL;
90100 +
90101 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
90102 +
90103 + entry = size_overflow_hash[hash];
90104 + while (entry) {
90105 + if (!strcmp(entry->name, func_name))
90106 + return entry;
90107 + entry = entry->next;
90108 + }
90109 +
90110 + return NULL;
90111 +}
90112 +
90113 +static void check_arg_type(const_tree arg)
90114 +{
90115 + const_tree type = TREE_TYPE(arg);
90116 + enum tree_code code = TREE_CODE(type);
90117 +
90118 + if (code == BOOLEAN_TYPE)
90119 + return;
90120 +
90121 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
90122 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
90123 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
90124 +}
90125 +
90126 +static unsigned int find_arg_number(const_tree arg, tree func)
90127 +{
90128 + tree var;
90129 + unsigned int argnum = 1;
90130 +
90131 + if (TREE_CODE(arg) == SSA_NAME)
90132 + arg = SSA_NAME_VAR(arg);
90133 +
90134 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
90135 + if (strcmp(NAME(arg), NAME(var))) {
90136 + argnum++;
90137 + continue;
90138 + }
90139 + check_arg_type(var);
90140 + return argnum;
90141 + }
90142 + gcc_unreachable();
90143 +}
90144 +
90145 +static tree create_new_var(tree type)
90146 +{
90147 + tree new_var = create_tmp_var(type, "cicus");
90148 +
90149 + add_referenced_var(new_var);
90150 + mark_sym_for_renaming(new_var);
90151 + return new_var;
90152 +}
90153 +
90154 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
90155 +{
90156 + gimple assign;
90157 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90158 + tree type = TREE_TYPE(rhs1);
90159 + tree lhs = create_new_var(type);
90160 +
90161 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
90162 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
90163 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90164 +
90165 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
90166 + update_stmt(assign);
90167 + gimple_set_plf(assign, MY_STMT, true);
90168 + return assign;
90169 +}
90170 +
90171 +static bool is_bool(const_tree node)
90172 +{
90173 + const_tree type;
90174 +
90175 + if (node == NULL_TREE)
90176 + return false;
90177 +
90178 + type = TREE_TYPE(node);
90179 + if (!INTEGRAL_TYPE_P(type))
90180 + return false;
90181 + if (TREE_CODE(type) == BOOLEAN_TYPE)
90182 + return true;
90183 + if (TYPE_PRECISION(type) == 1)
90184 + return true;
90185 + return false;
90186 +}
90187 +
90188 +static tree cast_a_tree(tree type, tree var)
90189 +{
90190 + gcc_assert(type != NULL_TREE);
90191 + gcc_assert(var != NULL_TREE);
90192 + gcc_assert(fold_convertible_p(type, var));
90193 +
90194 + return fold_convert(type, var);
90195 +}
90196 +
90197 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
90198 +{
90199 + gimple assign;
90200 +
90201 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
90202 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
90203 + gcc_unreachable();
90204 +
90205 + if (lhs == CREATE_NEW_VAR)
90206 + lhs = create_new_var(dst_type);
90207 +
90208 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
90209 +
90210 + if (!gsi_end_p(*gsi)) {
90211 + location_t loc = gimple_location(gsi_stmt(*gsi));
90212 + gimple_set_location(assign, loc);
90213 + }
90214 +
90215 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90216 +
90217 + if (before)
90218 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
90219 + else
90220 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
90221 + update_stmt(assign);
90222 + gimple_set_plf(assign, MY_STMT, true);
90223 +
90224 + return assign;
90225 +}
90226 +
90227 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
90228 +{
90229 + gimple assign;
90230 + gimple_stmt_iterator gsi;
90231 +
90232 + if (rhs == NULL_TREE)
90233 + return NULL_TREE;
90234 +
90235 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
90236 + return rhs;
90237 +
90238 + gsi = gsi_for_stmt(stmt);
90239 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
90240 + gimple_set_plf(assign, MY_STMT, true);
90241 + return gimple_get_lhs(assign);
90242 +}
90243 +
90244 +static tree cast_to_TI_type(gimple stmt, tree node)
90245 +{
90246 + gimple_stmt_iterator gsi;
90247 + gimple cast_stmt;
90248 + tree type = TREE_TYPE(node);
90249 +
90250 + if (types_compatible_p(type, intTI_type_node))
90251 + return node;
90252 +
90253 + gsi = gsi_for_stmt(stmt);
90254 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90255 + gimple_set_plf(cast_stmt, MY_STMT, true);
90256 + return gimple_get_lhs(cast_stmt);
90257 +}
90258 +
90259 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
90260 +{
90261 + tree lhs;
90262 + gimple_stmt_iterator gsi;
90263 +
90264 + if (rhs1 == NULL_TREE) {
90265 + debug_gimple_stmt(oldstmt);
90266 + error("%s: rhs1 is NULL_TREE", __func__);
90267 + gcc_unreachable();
90268 + }
90269 +
90270 + switch (gimple_code(oldstmt)) {
90271 + case GIMPLE_ASM:
90272 + lhs = rhs1;
90273 + break;
90274 + case GIMPLE_CALL:
90275 + lhs = gimple_call_lhs(oldstmt);
90276 + break;
90277 + case GIMPLE_ASSIGN:
90278 + lhs = gimple_get_lhs(oldstmt);
90279 + break;
90280 + default:
90281 + debug_gimple_stmt(oldstmt);
90282 + gcc_unreachable();
90283 + }
90284 +
90285 + gsi = gsi_for_stmt(oldstmt);
90286 + pointer_set_insert(visited, oldstmt);
90287 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
90288 + basic_block next_bb, cur_bb;
90289 + const_edge e;
90290 +
90291 + gcc_assert(before == false);
90292 + gcc_assert(stmt_can_throw_internal(oldstmt));
90293 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
90294 + gcc_assert(!gsi_end_p(gsi));
90295 +
90296 + cur_bb = gimple_bb(oldstmt);
90297 + next_bb = cur_bb->next_bb;
90298 + e = find_edge(cur_bb, next_bb);
90299 + gcc_assert(e != NULL);
90300 + gcc_assert(e->flags & EDGE_FALLTHRU);
90301 +
90302 + gsi = gsi_after_labels(next_bb);
90303 + gcc_assert(!gsi_end_p(gsi));
90304 +
90305 + before = true;
90306 + oldstmt = gsi_stmt(gsi);
90307 + }
90308 +
90309 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
90310 +}
90311 +
90312 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
90313 +{
90314 + gimple stmt;
90315 + gimple_stmt_iterator gsi;
90316 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
90317 +
90318 + if (gimple_plf(oldstmt, MY_STMT))
90319 + return lhs;
90320 +
90321 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
90322 + rhs1 = gimple_assign_rhs1(oldstmt);
90323 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
90324 + }
90325 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
90326 + rhs2 = gimple_assign_rhs2(oldstmt);
90327 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
90328 + }
90329 +
90330 + stmt = gimple_copy(oldstmt);
90331 + gimple_set_location(stmt, gimple_location(oldstmt));
90332 + gimple_set_plf(stmt, MY_STMT, true);
90333 +
90334 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
90335 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
90336 +
90337 + size_overflow_type = get_size_overflow_type(oldstmt, node);
90338 +
90339 + if (is_bool(lhs))
90340 + new_var = SSA_NAME_VAR(lhs);
90341 + else
90342 + new_var = create_new_var(size_overflow_type);
90343 + new_var = make_ssa_name(new_var, stmt);
90344 + gimple_set_lhs(stmt, new_var);
90345 +
90346 + if (rhs1 != NULL_TREE)
90347 + gimple_assign_set_rhs1(stmt, rhs1);
90348 +
90349 + if (rhs2 != NULL_TREE)
90350 + gimple_assign_set_rhs2(stmt, rhs2);
90351 +#if BUILDING_GCC_VERSION >= 4007
90352 + if (rhs3 != NULL_TREE)
90353 + gimple_assign_set_rhs3(stmt, rhs3);
90354 +#endif
90355 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
90356 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
90357 +
90358 + gsi = gsi_for_stmt(oldstmt);
90359 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
90360 + update_stmt(stmt);
90361 + pointer_set_insert(visited, oldstmt);
90362 + return gimple_get_lhs(stmt);
90363 +}
90364 +
90365 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
90366 +{
90367 + basic_block bb;
90368 + gimple phi;
90369 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
90370 +
90371 + bb = gsi_bb(gsi);
90372 +
90373 + phi = create_phi_node(result, bb);
90374 + gsi = gsi_last(phi_nodes(bb));
90375 + gsi_remove(&gsi, false);
90376 +
90377 + gsi = gsi_for_stmt(oldstmt);
90378 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
90379 + gimple_set_bb(phi, bb);
90380 + gimple_set_plf(phi, MY_STMT, true);
90381 + return phi;
90382 +}
90383 +
90384 +static basic_block create_a_first_bb(void)
90385 +{
90386 + basic_block first_bb;
90387 +
90388 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90389 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90390 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
90391 + return first_bb;
90392 +}
90393 +
90394 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
90395 +{
90396 + basic_block bb;
90397 + const_gimple newstmt;
90398 + gimple_stmt_iterator gsi;
90399 + bool before = BEFORE_STMT;
90400 +
90401 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
90402 + gsi = gsi_for_stmt(get_def_stmt(arg));
90403 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
90404 + return gimple_get_lhs(newstmt);
90405 + }
90406 +
90407 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
90408 + gsi = gsi_after_labels(bb);
90409 + if (bb->index == 0) {
90410 + bb = create_a_first_bb();
90411 + gsi = gsi_start_bb(bb);
90412 + }
90413 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
90414 + return gimple_get_lhs(newstmt);
90415 +}
90416 +
90417 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
90418 +{
90419 + gimple newstmt;
90420 + gimple_stmt_iterator gsi;
90421 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
90422 + gimple def_newstmt = get_def_stmt(new_rhs);
90423 +
90424 + gsi_insert = gsi_insert_after;
90425 + gsi = gsi_for_stmt(def_newstmt);
90426 +
90427 + switch (gimple_code(get_def_stmt(arg))) {
90428 + case GIMPLE_PHI:
90429 + newstmt = gimple_build_assign(new_var, new_rhs);
90430 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
90431 + gsi_insert = gsi_insert_before;
90432 + break;
90433 + case GIMPLE_ASM:
90434 + case GIMPLE_CALL:
90435 + newstmt = gimple_build_assign(new_var, new_rhs);
90436 + break;
90437 + case GIMPLE_ASSIGN:
90438 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
90439 + break;
90440 + default:
90441 + /* unknown gimple_code (handle_build_new_phi_arg) */
90442 + gcc_unreachable();
90443 + }
90444 +
90445 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
90446 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
90447 + gimple_set_plf(newstmt, MY_STMT, true);
90448 + update_stmt(newstmt);
90449 + return newstmt;
90450 +}
90451 +
90452 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
90453 +{
90454 + const_gimple newstmt;
90455 + gimple def_stmt;
90456 + tree new_rhs;
90457 +
90458 + new_rhs = expand(visited, arg);
90459 + if (new_rhs == NULL_TREE)
90460 + return NULL_TREE;
90461 +
90462 + def_stmt = get_def_stmt(new_rhs);
90463 + if (gimple_code(def_stmt) == GIMPLE_NOP)
90464 + return NULL_TREE;
90465 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
90466 +
90467 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
90468 + return gimple_get_lhs(newstmt);
90469 +}
90470 +
90471 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
90472 +{
90473 + gimple phi, oldstmt = get_def_stmt(orig_result);
90474 + tree new_result, size_overflow_type;
90475 + unsigned int i;
90476 + unsigned int n = gimple_phi_num_args(oldstmt);
90477 +
90478 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
90479 +
90480 + new_result = create_new_var(size_overflow_type);
90481 +
90482 + pointer_set_insert(visited, oldstmt);
90483 + phi = overflow_create_phi_node(oldstmt, new_result);
90484 + for (i = 0; i < n; i++) {
90485 + tree arg, lhs;
90486 +
90487 + arg = gimple_phi_arg_def(oldstmt, i);
90488 + if (is_gimple_constant(arg))
90489 + arg = cast_a_tree(size_overflow_type, arg);
90490 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
90491 + if (lhs == NULL_TREE)
90492 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
90493 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
90494 + }
90495 +
90496 + update_stmt(phi);
90497 + return gimple_phi_result(phi);
90498 +}
90499 +
90500 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
90501 +{
90502 + const_gimple assign;
90503 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90504 + tree origtype = TREE_TYPE(orig_rhs);
90505 +
90506 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
90507 +
90508 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90509 + return gimple_get_lhs(assign);
90510 +}
90511 +
90512 +static void change_rhs1(gimple stmt, tree new_rhs1)
90513 +{
90514 + tree assign_rhs;
90515 + const_tree rhs = gimple_assign_rhs1(stmt);
90516 +
90517 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
90518 + gimple_assign_set_rhs1(stmt, assign_rhs);
90519 + update_stmt(stmt);
90520 +}
90521 +
90522 +static bool check_mode_type(const_gimple stmt)
90523 +{
90524 + const_tree lhs = gimple_get_lhs(stmt);
90525 + const_tree lhs_type = TREE_TYPE(lhs);
90526 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
90527 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
90528 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
90529 +
90530 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
90531 + return false;
90532 +
90533 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
90534 + return false;
90535 +
90536 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
90537 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
90538 + return false;
90539 +
90540 + return true;
90541 +}
90542 +
90543 +static bool check_undefined_integer_operation(const_gimple stmt)
90544 +{
90545 + const_gimple def_stmt;
90546 + const_tree lhs = gimple_get_lhs(stmt);
90547 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90548 + const_tree rhs1_type = TREE_TYPE(rhs1);
90549 + const_tree lhs_type = TREE_TYPE(lhs);
90550 +
90551 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90552 + return false;
90553 +
90554 + def_stmt = get_def_stmt(rhs1);
90555 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
90556 + return false;
90557 +
90558 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
90559 + return false;
90560 + return true;
90561 +}
90562 +
90563 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
90564 +{
90565 + const_tree rhs1, lhs, rhs1_type, lhs_type;
90566 + enum machine_mode lhs_mode, rhs_mode;
90567 + gimple def_stmt = get_def_stmt(no_const_rhs);
90568 +
90569 + if (!gimple_assign_cast_p(def_stmt))
90570 + return false;
90571 +
90572 + rhs1 = gimple_assign_rhs1(def_stmt);
90573 + lhs = gimple_get_lhs(def_stmt);
90574 + rhs1_type = TREE_TYPE(rhs1);
90575 + lhs_type = TREE_TYPE(lhs);
90576 + rhs_mode = TYPE_MODE(rhs1_type);
90577 + lhs_mode = TYPE_MODE(lhs_type);
90578 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
90579 + return false;
90580 +
90581 + return true;
90582 +}
90583 +
90584 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
90585 +{
90586 + tree rhs1 = gimple_assign_rhs1(stmt);
90587 + tree lhs = gimple_get_lhs(stmt);
90588 + const_tree rhs1_type = TREE_TYPE(rhs1);
90589 + const_tree lhs_type = TREE_TYPE(lhs);
90590 +
90591 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90592 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90593 +
90594 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
90595 +}
90596 +
90597 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
90598 +{
90599 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
90600 + tree new_rhs1 = NULL_TREE;
90601 + tree rhs1 = gimple_assign_rhs1(stmt);
90602 + const_tree rhs1_type = TREE_TYPE(rhs1);
90603 + const_tree lhs_type = TREE_TYPE(lhs);
90604 +
90605 + if (gimple_plf(stmt, MY_STMT))
90606 + return lhs;
90607 +
90608 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
90609 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90610 +
90611 + new_rhs1 = expand(visited, rhs1);
90612 +
90613 + if (new_rhs1 == NULL_TREE)
90614 + return create_cast_assign(visited, stmt);
90615 +
90616 + if (gimple_plf(stmt, NO_CAST_CHECK))
90617 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90618 +
90619 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
90620 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90621 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90622 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90623 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90624 + }
90625 +
90626 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
90627 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90628 +
90629 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
90630 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90631 +
90632 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90633 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90634 +
90635 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90636 +
90637 + change_rhs1(stmt, new_rhs1);
90638 +
90639 + if (!check_mode_type(stmt))
90640 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90641 +
90642 + size_overflow_type = get_size_overflow_type(stmt, lhs);
90643 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90644 +
90645 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
90646 +
90647 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90648 +}
90649 +
90650 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
90651 +{
90652 + tree rhs1, lhs = gimple_get_lhs(stmt);
90653 + gimple def_stmt = get_def_stmt(lhs);
90654 +
90655 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
90656 + rhs1 = gimple_assign_rhs1(def_stmt);
90657 +
90658 + if (is_gimple_constant(rhs1))
90659 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90660 +
90661 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
90662 + switch (TREE_CODE(rhs1)) {
90663 + case SSA_NAME:
90664 + return handle_unary_rhs(visited, def_stmt);
90665 + case ARRAY_REF:
90666 + case BIT_FIELD_REF:
90667 + case ADDR_EXPR:
90668 + case COMPONENT_REF:
90669 + case INDIRECT_REF:
90670 +#if BUILDING_GCC_VERSION >= 4006
90671 + case MEM_REF:
90672 +#endif
90673 + case TARGET_MEM_REF:
90674 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90675 + case PARM_DECL:
90676 + case VAR_DECL:
90677 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90678 +
90679 + default:
90680 + debug_gimple_stmt(def_stmt);
90681 + debug_tree(rhs1);
90682 + gcc_unreachable();
90683 + }
90684 +}
90685 +
90686 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
90687 +{
90688 + gimple cond_stmt;
90689 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
90690 +
90691 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
90692 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
90693 + update_stmt(cond_stmt);
90694 +}
90695 +
90696 +static tree create_string_param(tree string)
90697 +{
90698 + tree i_type, a_type;
90699 + const int length = TREE_STRING_LENGTH(string);
90700 +
90701 + gcc_assert(length > 0);
90702 +
90703 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
90704 + a_type = build_array_type(char_type_node, i_type);
90705 +
90706 + TREE_TYPE(string) = a_type;
90707 + TREE_CONSTANT(string) = 1;
90708 + TREE_READONLY(string) = 1;
90709 +
90710 + return build1(ADDR_EXPR, ptr_type_node, string);
90711 +}
90712 +
90713 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
90714 +{
90715 + gimple func_stmt;
90716 + const_gimple def_stmt;
90717 + const_tree loc_line;
90718 + tree loc_file, ssa_name, current_func;
90719 + expanded_location xloc;
90720 + char *ssa_name_buf;
90721 + int len;
90722 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
90723 +
90724 + def_stmt = get_def_stmt(arg);
90725 + xloc = expand_location(gimple_location(def_stmt));
90726 +
90727 + if (!gimple_has_location(def_stmt)) {
90728 + xloc = expand_location(gimple_location(stmt));
90729 + if (!gimple_has_location(stmt))
90730 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
90731 + }
90732 +
90733 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
90734 +
90735 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
90736 + loc_file = create_string_param(loc_file);
90737 +
90738 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
90739 + current_func = create_string_param(current_func);
90740 +
90741 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
90742 + call_count++;
90743 + 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);
90744 + gcc_assert(len > 0);
90745 + ssa_name = build_string(len + 1, ssa_name_buf);
90746 + free(ssa_name_buf);
90747 + ssa_name = create_string_param(ssa_name);
90748 +
90749 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
90750 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
90751 +
90752 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
90753 +}
90754 +
90755 +static void __unused print_the_code_insertions(const_gimple stmt)
90756 +{
90757 + location_t loc = gimple_location(stmt);
90758 +
90759 + inform(loc, "Integer size_overflow check applied here.");
90760 +}
90761 +
90762 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
90763 +{
90764 + basic_block cond_bb, join_bb, bb_true;
90765 + edge e;
90766 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90767 +
90768 + cond_bb = gimple_bb(stmt);
90769 + if (before)
90770 + gsi_prev(&gsi);
90771 + if (gsi_end_p(gsi))
90772 + e = split_block_after_labels(cond_bb);
90773 + else
90774 + e = split_block(cond_bb, gsi_stmt(gsi));
90775 + cond_bb = e->src;
90776 + join_bb = e->dest;
90777 + e->flags = EDGE_FALSE_VALUE;
90778 + e->probability = REG_BR_PROB_BASE;
90779 +
90780 + bb_true = create_empty_bb(cond_bb);
90781 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
90782 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
90783 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
90784 +
90785 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90786 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
90787 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
90788 +
90789 + if (current_loops != NULL) {
90790 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
90791 + add_bb_to_loop(bb_true, cond_bb->loop_father);
90792 + }
90793 +
90794 + insert_cond(cond_bb, arg, cond_code, type_value);
90795 + insert_cond_result(bb_true, stmt, arg, min);
90796 +
90797 +// print_the_code_insertions(stmt);
90798 +}
90799 +
90800 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
90801 +{
90802 + const_tree rhs_type = TREE_TYPE(rhs);
90803 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
90804 +
90805 + gcc_assert(rhs_type != NULL_TREE);
90806 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
90807 + return;
90808 +
90809 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
90810 +
90811 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
90812 + // typemax (-1) < typemin (0)
90813 + if (TREE_OVERFLOW(type_max))
90814 + return;
90815 +
90816 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
90817 +
90818 + cast_rhs_type = TREE_TYPE(cast_rhs);
90819 + type_max_type = TREE_TYPE(type_max);
90820 + type_min_type = TREE_TYPE(type_min);
90821 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
90822 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
90823 +
90824 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
90825 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
90826 +}
90827 +
90828 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
90829 +{
90830 + gimple change_rhs_def_stmt;
90831 + tree lhs = gimple_get_lhs(def_stmt);
90832 + tree lhs_type = TREE_TYPE(lhs);
90833 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
90834 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
90835 +
90836 + if (change_rhs == NULL_TREE)
90837 + return get_size_overflow_type(def_stmt, lhs);
90838 +
90839 + change_rhs_def_stmt = get_def_stmt(change_rhs);
90840 +
90841 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
90842 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
90843 +
90844 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
90845 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
90846 +
90847 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
90848 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
90849 +
90850 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
90851 + debug_gimple_stmt(def_stmt);
90852 + gcc_unreachable();
90853 + }
90854 +
90855 + return get_size_overflow_type(def_stmt, lhs);
90856 +}
90857 +
90858 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
90859 +{
90860 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
90861 + return false;
90862 + if (!is_gimple_constant(rhs))
90863 + return false;
90864 + return true;
90865 +}
90866 +
90867 +static bool is_subtraction_special(const_gimple stmt)
90868 +{
90869 + gimple rhs1_def_stmt, rhs2_def_stmt;
90870 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
90871 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
90872 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90873 + const_tree rhs2 = gimple_assign_rhs2(stmt);
90874 +
90875 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
90876 + return false;
90877 +
90878 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
90879 +
90880 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
90881 + return false;
90882 +
90883 + rhs1_def_stmt = get_def_stmt(rhs1);
90884 + rhs2_def_stmt = get_def_stmt(rhs2);
90885 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
90886 + return false;
90887 +
90888 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
90889 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
90890 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
90891 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
90892 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
90893 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
90894 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
90895 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
90896 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
90897 + return false;
90898 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
90899 + return false;
90900 +
90901 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
90902 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
90903 + return true;
90904 +}
90905 +
90906 +static tree get_def_stmt_rhs(const_tree var)
90907 +{
90908 + tree rhs1, def_stmt_rhs1;
90909 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
90910 +
90911 + def_stmt = get_def_stmt(var);
90912 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
90913 +
90914 + rhs1 = gimple_assign_rhs1(def_stmt);
90915 + rhs1_def_stmt = get_def_stmt(rhs1);
90916 + if (!gimple_assign_cast_p(rhs1_def_stmt))
90917 + return rhs1;
90918 +
90919 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
90920 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
90921 +
90922 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
90923 + case GIMPLE_CALL:
90924 + case GIMPLE_NOP:
90925 + case GIMPLE_ASM:
90926 + return def_stmt_rhs1;
90927 + case GIMPLE_ASSIGN:
90928 + return rhs1;
90929 + default:
90930 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
90931 + gcc_unreachable();
90932 + }
90933 +}
90934 +
90935 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
90936 +{
90937 + tree new_rhs1, new_rhs2;
90938 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
90939 + gimple assign, stmt = get_def_stmt(lhs);
90940 + tree rhs1 = gimple_assign_rhs1(stmt);
90941 + tree rhs2 = gimple_assign_rhs2(stmt);
90942 +
90943 + if (!is_subtraction_special(stmt))
90944 + return NULL_TREE;
90945 +
90946 + new_rhs1 = expand(visited, rhs1);
90947 + new_rhs2 = expand(visited, rhs2);
90948 +
90949 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
90950 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
90951 +
90952 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
90953 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
90954 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
90955 + }
90956 +
90957 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
90958 + new_lhs = gimple_get_lhs(assign);
90959 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
90960 +
90961 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
90962 +}
90963 +
90964 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
90965 +{
90966 + const_gimple def_stmt;
90967 +
90968 + if (TREE_CODE(rhs) != SSA_NAME)
90969 + return false;
90970 +
90971 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
90972 + return false;
90973 +
90974 + def_stmt = get_def_stmt(rhs);
90975 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
90976 + return false;
90977 +
90978 + return true;
90979 +}
90980 +
90981 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
90982 +{
90983 + tree new_rhs, size_overflow_type, orig_rhs;
90984 + void (*gimple_assign_set_rhs)(gimple, tree);
90985 + tree rhs1 = gimple_assign_rhs1(stmt);
90986 + tree rhs2 = gimple_assign_rhs2(stmt);
90987 + tree lhs = gimple_get_lhs(stmt);
90988 +
90989 + if (change_rhs == NULL_TREE)
90990 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90991 +
90992 + if (new_rhs2 == NULL_TREE) {
90993 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
90994 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
90995 + orig_rhs = rhs1;
90996 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
90997 + } else {
90998 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
90999 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
91000 + orig_rhs = rhs2;
91001 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
91002 + }
91003 +
91004 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
91005 +
91006 + if (check_overflow)
91007 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
91008 +
91009 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
91010 + gimple_assign_set_rhs(stmt, new_rhs);
91011 + update_stmt(stmt);
91012 +
91013 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91014 +}
91015 +
91016 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
91017 +{
91018 + tree rhs1, rhs2, new_lhs;
91019 + gimple def_stmt = get_def_stmt(lhs);
91020 + tree new_rhs1 = NULL_TREE;
91021 + tree new_rhs2 = NULL_TREE;
91022 +
91023 + rhs1 = gimple_assign_rhs1(def_stmt);
91024 + rhs2 = gimple_assign_rhs2(def_stmt);
91025 +
91026 + /* no DImode/TImode division in the 32/64 bit kernel */
91027 + switch (gimple_assign_rhs_code(def_stmt)) {
91028 + case RDIV_EXPR:
91029 + case TRUNC_DIV_EXPR:
91030 + case CEIL_DIV_EXPR:
91031 + case FLOOR_DIV_EXPR:
91032 + case ROUND_DIV_EXPR:
91033 + case TRUNC_MOD_EXPR:
91034 + case CEIL_MOD_EXPR:
91035 + case FLOOR_MOD_EXPR:
91036 + case ROUND_MOD_EXPR:
91037 + case EXACT_DIV_EXPR:
91038 + case POINTER_PLUS_EXPR:
91039 + case BIT_AND_EXPR:
91040 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91041 + default:
91042 + break;
91043 + }
91044 +
91045 + new_lhs = handle_integer_truncation(visited, lhs);
91046 + if (new_lhs != NULL_TREE)
91047 + return new_lhs;
91048 +
91049 + if (TREE_CODE(rhs1) == SSA_NAME)
91050 + new_rhs1 = expand(visited, rhs1);
91051 + if (TREE_CODE(rhs2) == SSA_NAME)
91052 + new_rhs2 = expand(visited, rhs2);
91053 +
91054 + if (is_a_neg_overflow(def_stmt, rhs2))
91055 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91056 + if (is_a_neg_overflow(def_stmt, rhs1))
91057 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91058 +
91059 + if (is_a_constant_overflow(def_stmt, rhs2))
91060 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91061 + if (is_a_constant_overflow(def_stmt, rhs1))
91062 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91063 +
91064 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91065 +}
91066 +
91067 +#if BUILDING_GCC_VERSION >= 4007
91068 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
91069 +{
91070 + if (is_gimple_constant(rhs))
91071 + return cast_a_tree(size_overflow_type, rhs);
91072 + if (TREE_CODE(rhs) != SSA_NAME)
91073 + return NULL_TREE;
91074 + return expand(visited, rhs);
91075 +}
91076 +
91077 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
91078 +{
91079 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
91080 + gimple def_stmt = get_def_stmt(lhs);
91081 +
91082 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
91083 +
91084 + rhs1 = gimple_assign_rhs1(def_stmt);
91085 + rhs2 = gimple_assign_rhs2(def_stmt);
91086 + rhs3 = gimple_assign_rhs3(def_stmt);
91087 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
91088 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
91089 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
91090 +
91091 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
91092 +}
91093 +#endif
91094 +
91095 +static tree get_size_overflow_type(gimple stmt, const_tree node)
91096 +{
91097 + const_tree type;
91098 + tree new_type;
91099 +
91100 + gcc_assert(node != NULL_TREE);
91101 +
91102 + type = TREE_TYPE(node);
91103 +
91104 + if (gimple_plf(stmt, MY_STMT))
91105 + return TREE_TYPE(node);
91106 +
91107 + switch (TYPE_MODE(type)) {
91108 + case QImode:
91109 + new_type = intHI_type_node;
91110 + break;
91111 + case HImode:
91112 + new_type = intSI_type_node;
91113 + break;
91114 + case SImode:
91115 + new_type = intDI_type_node;
91116 + break;
91117 + case DImode:
91118 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
91119 + new_type = intDI_type_node;
91120 + else
91121 + new_type = intTI_type_node;
91122 + break;
91123 + default:
91124 + debug_tree((tree)node);
91125 + error("%s: unsupported gcc configuration.", __func__);
91126 + gcc_unreachable();
91127 + }
91128 +
91129 + if (TYPE_QUALS(type) != 0)
91130 + return build_qualified_type(new_type, TYPE_QUALS(type));
91131 + return new_type;
91132 +}
91133 +
91134 +static tree expand_visited(gimple def_stmt)
91135 +{
91136 + const_gimple next_stmt;
91137 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
91138 +
91139 + gsi_next(&gsi);
91140 + next_stmt = gsi_stmt(gsi);
91141 +
91142 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
91143 +
91144 + switch (gimple_code(next_stmt)) {
91145 + case GIMPLE_ASSIGN:
91146 + return gimple_get_lhs(next_stmt);
91147 + case GIMPLE_PHI:
91148 + return gimple_phi_result(next_stmt);
91149 + case GIMPLE_CALL:
91150 + return gimple_call_lhs(next_stmt);
91151 + default:
91152 + return NULL_TREE;
91153 + }
91154 +}
91155 +
91156 +static tree expand(struct pointer_set_t *visited, tree lhs)
91157 +{
91158 + gimple def_stmt;
91159 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
91160 +
91161 + if (is_gimple_constant(lhs))
91162 + return NULL_TREE;
91163 +
91164 + if (TREE_CODE(lhs) == ADDR_EXPR)
91165 + return NULL_TREE;
91166 +
91167 + if (code == REAL_TYPE)
91168 + return NULL_TREE;
91169 +
91170 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
91171 +
91172 + def_stmt = get_def_stmt(lhs);
91173 +
91174 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
91175 + return NULL_TREE;
91176 +
91177 + if (gimple_plf(def_stmt, MY_STMT))
91178 + return lhs;
91179 +
91180 + if (pointer_set_contains(visited, def_stmt))
91181 + return expand_visited(def_stmt);
91182 +
91183 + switch (gimple_code(def_stmt)) {
91184 + case GIMPLE_PHI:
91185 + return build_new_phi(visited, lhs);
91186 + case GIMPLE_CALL:
91187 + case GIMPLE_ASM:
91188 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91189 + case GIMPLE_ASSIGN:
91190 + switch (gimple_num_ops(def_stmt)) {
91191 + case 2:
91192 + return handle_unary_ops(visited, def_stmt);
91193 + case 3:
91194 + return handle_binary_ops(visited, lhs);
91195 +#if BUILDING_GCC_VERSION >= 4007
91196 + case 4:
91197 + return handle_ternary_ops(visited, lhs);
91198 +#endif
91199 + }
91200 + default:
91201 + debug_gimple_stmt(def_stmt);
91202 + error("%s: unknown gimple code", __func__);
91203 + gcc_unreachable();
91204 + }
91205 +}
91206 +
91207 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
91208 +{
91209 + const_gimple assign;
91210 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91211 + tree origtype = TREE_TYPE(origarg);
91212 +
91213 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
91214 +
91215 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91216 +
91217 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
91218 + update_stmt(stmt);
91219 +}
91220 +
91221 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
91222 +{
91223 + const char *origid;
91224 + tree arg;
91225 + const_tree origarg;
91226 +
91227 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
91228 + return true;
91229 +
91230 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
91231 + while (origarg && *argnum) {
91232 + (*argnum)--;
91233 + origarg = TREE_CHAIN(origarg);
91234 + }
91235 +
91236 + gcc_assert(*argnum == 0);
91237 +
91238 + gcc_assert(origarg != NULL_TREE);
91239 + origid = NAME(origarg);
91240 + *argnum = 0;
91241 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
91242 + if (!strcmp(origid, NAME(arg)))
91243 + return true;
91244 + (*argnum)++;
91245 + }
91246 + return false;
91247 +}
91248 +
91249 +static bool skip_types(const_tree var)
91250 +{
91251 + const_tree type;
91252 +
91253 + switch (TREE_CODE(var)) {
91254 + case ADDR_EXPR:
91255 +#if BUILDING_GCC_VERSION >= 4006
91256 + case MEM_REF:
91257 +#endif
91258 + case ARRAY_REF:
91259 + case BIT_FIELD_REF:
91260 + case INDIRECT_REF:
91261 + case TARGET_MEM_REF:
91262 + case VAR_DECL:
91263 + return true;
91264 + default:
91265 + break;
91266 + }
91267 +
91268 + type = TREE_TYPE(TREE_TYPE(var));
91269 + if (!type)
91270 + return false;
91271 + switch (TREE_CODE(type)) {
91272 + case RECORD_TYPE:
91273 + return true;
91274 + default:
91275 + break;
91276 + }
91277 +
91278 + return false;
91279 +}
91280 +
91281 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
91282 +{
91283 + gimple phi = get_def_stmt(result);
91284 + unsigned int i, n = gimple_phi_num_args(phi);
91285 +
91286 + if (!phi)
91287 + return false;
91288 +
91289 + pointer_set_insert(visited, phi);
91290 + for (i = 0; i < n; i++) {
91291 + const_tree arg = gimple_phi_arg_def(phi, i);
91292 + if (pre_expand(visited, arg))
91293 + return true;
91294 + }
91295 + return false;
91296 +}
91297 +
91298 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
91299 +{
91300 + gimple def_stmt = get_def_stmt(lhs);
91301 + const_tree rhs;
91302 +
91303 + if (!def_stmt)
91304 + return false;
91305 +
91306 + rhs = gimple_assign_rhs1(def_stmt);
91307 + if (pre_expand(visited, rhs))
91308 + return true;
91309 + return false;
91310 +}
91311 +
91312 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
91313 +{
91314 + bool rhs1_found, rhs2_found;
91315 + gimple def_stmt = get_def_stmt(lhs);
91316 + const_tree rhs1, rhs2;
91317 +
91318 + if (!def_stmt)
91319 + return false;
91320 +
91321 + rhs1 = gimple_assign_rhs1(def_stmt);
91322 + rhs2 = gimple_assign_rhs2(def_stmt);
91323 + rhs1_found = pre_expand(visited, rhs1);
91324 + rhs2_found = pre_expand(visited, rhs2);
91325 +
91326 + return rhs1_found || rhs2_found;
91327 +}
91328 +
91329 +static const_tree search_field_decl(const_tree comp_ref)
91330 +{
91331 + const_tree field = NULL_TREE;
91332 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
91333 +
91334 + for (i = 0; i < len; i++) {
91335 + field = TREE_OPERAND(comp_ref, i);
91336 + if (TREE_CODE(field) == FIELD_DECL)
91337 + break;
91338 + }
91339 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
91340 + return field;
91341 +}
91342 +
91343 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
91344 +{
91345 + const_tree attr, p;
91346 +
91347 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
91348 + if (!attr || !TREE_VALUE(attr))
91349 + return MARKED_NO;
91350 +
91351 + p = TREE_VALUE(attr);
91352 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
91353 + return MARKED_NOT_INTENTIONAL;
91354 +
91355 + do {
91356 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
91357 + return MARKED_YES;
91358 + p = TREE_CHAIN(p);
91359 + } while (p);
91360 +
91361 + return MARKED_NO;
91362 +}
91363 +
91364 +static void print_missing_msg(tree func, unsigned int argnum)
91365 +{
91366 + unsigned int new_hash;
91367 + size_t len;
91368 + unsigned char tree_codes[CODES_LIMIT];
91369 + location_t loc = DECL_SOURCE_LOCATION(func);
91370 + const char *curfunc = get_asm_name(func);
91371 +
91372 + len = get_function_decl(func, tree_codes);
91373 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
91374 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
91375 +}
91376 +
91377 +static unsigned int search_missing_attribute(const_tree arg)
91378 +{
91379 + const_tree type = TREE_TYPE(arg);
91380 + tree func = get_original_function_decl(current_function_decl);
91381 + unsigned int argnum;
91382 + const struct size_overflow_hash *hash;
91383 +
91384 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
91385 +
91386 + if (TREE_CODE(type) == POINTER_TYPE)
91387 + return 0;
91388 +
91389 + argnum = find_arg_number(arg, func);
91390 + if (argnum == 0)
91391 + return 0;
91392 +
91393 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
91394 + return argnum;
91395 +
91396 + hash = get_function_hash(func);
91397 + if (!hash || !(hash->param & (1U << argnum))) {
91398 + print_missing_msg(func, argnum);
91399 + return 0;
91400 + }
91401 + return argnum;
91402 +}
91403 +
91404 +static bool is_already_marked(const_tree lhs)
91405 +{
91406 + unsigned int argnum;
91407 + const_tree fndecl;
91408 +
91409 + argnum = search_missing_attribute(lhs);
91410 + fndecl = get_original_function_decl(current_function_decl);
91411 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
91412 + return true;
91413 + return false;
91414 +}
91415 +
91416 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
91417 +{
91418 + const_gimple def_stmt;
91419 +
91420 + if (is_gimple_constant(lhs))
91421 + return false;
91422 +
91423 + if (skip_types(lhs))
91424 + return false;
91425 +
91426 + // skip char type (FIXME: only kernel)
91427 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
91428 + return false;
91429 +
91430 + if (TREE_CODE(lhs) == PARM_DECL)
91431 + return is_already_marked(lhs);
91432 +
91433 + if (TREE_CODE(lhs) == COMPONENT_REF) {
91434 + const_tree field, attr;
91435 +
91436 + field = search_field_decl(lhs);
91437 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
91438 + if (!attr || !TREE_VALUE(attr))
91439 + return false;
91440 + return true;
91441 + }
91442 +
91443 + def_stmt = get_def_stmt(lhs);
91444 +
91445 + if (!def_stmt)
91446 + return false;
91447 +
91448 + if (pointer_set_contains(visited, def_stmt))
91449 + return false;
91450 +
91451 + switch (gimple_code(def_stmt)) {
91452 + case GIMPLE_NOP:
91453 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
91454 + return is_already_marked(lhs);
91455 + return false;
91456 + case GIMPLE_PHI:
91457 + return walk_phi(visited, lhs);
91458 + case GIMPLE_CALL:
91459 + case GIMPLE_ASM:
91460 + return false;
91461 + case GIMPLE_ASSIGN:
91462 + switch (gimple_num_ops(def_stmt)) {
91463 + case 2:
91464 + return walk_unary_ops(visited, lhs);
91465 + case 3:
91466 + return walk_binary_ops(visited, lhs);
91467 + }
91468 + default:
91469 + debug_gimple_stmt((gimple)def_stmt);
91470 + error("%s: unknown gimple code", __func__);
91471 + gcc_unreachable();
91472 + }
91473 +}
91474 +
91475 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
91476 +{
91477 + struct pointer_set_t *visited;
91478 + bool is_found;
91479 + enum marked is_marked;
91480 + location_t loc;
91481 +
91482 + visited = pointer_set_create();
91483 + is_found = pre_expand(visited, arg);
91484 + pointer_set_destroy(visited);
91485 +
91486 + is_marked = mark_status(fndecl, argnum + 1);
91487 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
91488 + return true;
91489 +
91490 + if (is_found) {
91491 + loc = DECL_SOURCE_LOCATION(fndecl);
91492 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
91493 + return true;
91494 + }
91495 + return false;
91496 +}
91497 +
91498 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
91499 +{
91500 + struct pointer_set_t *visited;
91501 + tree arg, newarg;
91502 + bool match;
91503 +
91504 + match = get_function_arg(&argnum, fndecl);
91505 + if (!match)
91506 + return;
91507 + gcc_assert(gimple_call_num_args(stmt) > argnum);
91508 + arg = gimple_call_arg(stmt, argnum);
91509 + if (arg == NULL_TREE)
91510 + return;
91511 +
91512 + if (is_gimple_constant(arg))
91513 + return;
91514 +
91515 + if (search_attributes(fndecl, arg, argnum))
91516 + return;
91517 +
91518 + if (TREE_CODE(arg) != SSA_NAME)
91519 + return;
91520 +
91521 + check_arg_type(arg);
91522 +
91523 + visited = pointer_set_create();
91524 + newarg = expand(visited, arg);
91525 + pointer_set_destroy(visited);
91526 +
91527 + if (newarg == NULL_TREE)
91528 + return;
91529 +
91530 + change_function_arg(stmt, arg, argnum, newarg);
91531 +
91532 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
91533 +}
91534 +
91535 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
91536 +{
91537 + tree p = TREE_VALUE(attr);
91538 + do {
91539 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
91540 + p = TREE_CHAIN(p);
91541 + } while (p);
91542 +}
91543 +
91544 +static void handle_function_by_hash(gimple stmt, tree fndecl)
91545 +{
91546 + tree orig_fndecl;
91547 + unsigned int num;
91548 + const struct size_overflow_hash *hash;
91549 +
91550 + orig_fndecl = get_original_function_decl(fndecl);
91551 + if (C_DECL_IMPLICIT(orig_fndecl))
91552 + return;
91553 + hash = get_function_hash(orig_fndecl);
91554 + if (!hash)
91555 + return;
91556 +
91557 + for (num = 1; num <= MAX_PARAM; num++)
91558 + if (hash->param & (1U << num))
91559 + handle_function_arg(stmt, fndecl, num - 1);
91560 +}
91561 +
91562 +static void set_plf_false(void)
91563 +{
91564 + basic_block bb;
91565 +
91566 + FOR_ALL_BB(bb) {
91567 + gimple_stmt_iterator si;
91568 +
91569 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
91570 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91571 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
91572 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91573 + }
91574 +}
91575 +
91576 +static unsigned int handle_function(void)
91577 +{
91578 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
91579 +
91580 + set_plf_false();
91581 +
91582 + do {
91583 + gimple_stmt_iterator gsi;
91584 + next = bb->next_bb;
91585 +
91586 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91587 + tree fndecl, attr;
91588 + gimple stmt = gsi_stmt(gsi);
91589 +
91590 + if (!(is_gimple_call(stmt)))
91591 + continue;
91592 + fndecl = gimple_call_fndecl(stmt);
91593 + if (fndecl == NULL_TREE)
91594 + continue;
91595 + if (gimple_call_num_args(stmt) == 0)
91596 + continue;
91597 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
91598 + if (!attr || !TREE_VALUE(attr))
91599 + handle_function_by_hash(stmt, fndecl);
91600 + else
91601 + handle_function_by_attribute(stmt, attr, fndecl);
91602 + gsi = gsi_for_stmt(stmt);
91603 + next = gimple_bb(stmt)->next_bb;
91604 + }
91605 + bb = next;
91606 + } while (bb);
91607 + return 0;
91608 +}
91609 +
91610 +static struct gimple_opt_pass size_overflow_pass = {
91611 + .pass = {
91612 + .type = GIMPLE_PASS,
91613 + .name = "size_overflow",
91614 + .gate = NULL,
91615 + .execute = handle_function,
91616 + .sub = NULL,
91617 + .next = NULL,
91618 + .static_pass_number = 0,
91619 + .tv_id = TV_NONE,
91620 + .properties_required = PROP_cfg | PROP_referenced_vars,
91621 + .properties_provided = 0,
91622 + .properties_destroyed = 0,
91623 + .todo_flags_start = 0,
91624 + .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
91625 + }
91626 +};
91627 +
91628 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
91629 +{
91630 + tree fntype;
91631 +
91632 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
91633 +
91634 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
91635 + fntype = build_function_type_list(void_type_node,
91636 + const_char_ptr_type_node,
91637 + unsigned_type_node,
91638 + const_char_ptr_type_node,
91639 + const_char_ptr_type_node,
91640 + NULL_TREE);
91641 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
91642 +
91643 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
91644 + TREE_PUBLIC(report_size_overflow_decl) = 1;
91645 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
91646 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
91647 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
91648 +}
91649 +
91650 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91651 +{
91652 + int i;
91653 + const char * const plugin_name = plugin_info->base_name;
91654 + const int argc = plugin_info->argc;
91655 + const struct plugin_argument * const argv = plugin_info->argv;
91656 + bool enable = true;
91657 +
91658 + struct register_pass_info size_overflow_pass_info = {
91659 + .pass = &size_overflow_pass.pass,
91660 + .reference_pass_name = "ssa",
91661 + .ref_pass_instance_number = 1,
91662 + .pos_op = PASS_POS_INSERT_AFTER
91663 + };
91664 +
91665 + if (!plugin_default_version_check(version, &gcc_version)) {
91666 + error(G_("incompatible gcc/plugin versions"));
91667 + return 1;
91668 + }
91669 +
91670 + for (i = 0; i < argc; ++i) {
91671 + if (!strcmp(argv[i].key, "no-size-overflow")) {
91672 + enable = false;
91673 + continue;
91674 + }
91675 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91676 + }
91677 +
91678 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
91679 + if (enable) {
91680 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
91681 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
91682 + }
91683 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
91684 +
91685 + return 0;
91686 +}
91687 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
91688 new file mode 100644
91689 index 0000000..38d2014
91690 --- /dev/null
91691 +++ b/tools/gcc/stackleak_plugin.c
91692 @@ -0,0 +1,313 @@
91693 +/*
91694 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
91695 + * Licensed under the GPL v2
91696 + *
91697 + * Note: the choice of the license means that the compilation process is
91698 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91699 + * but for the kernel it doesn't matter since it doesn't link against
91700 + * any of the gcc libraries
91701 + *
91702 + * gcc plugin to help implement various PaX features
91703 + *
91704 + * - track lowest stack pointer
91705 + *
91706 + * TODO:
91707 + * - initialize all local variables
91708 + *
91709 + * BUGS:
91710 + * - none known
91711 + */
91712 +#include "gcc-plugin.h"
91713 +#include "config.h"
91714 +#include "system.h"
91715 +#include "coretypes.h"
91716 +#include "tree.h"
91717 +#include "tree-pass.h"
91718 +#include "flags.h"
91719 +#include "intl.h"
91720 +#include "toplev.h"
91721 +#include "plugin.h"
91722 +//#include "expr.h" where are you...
91723 +#include "diagnostic.h"
91724 +#include "plugin-version.h"
91725 +#include "tm.h"
91726 +#include "function.h"
91727 +#include "basic-block.h"
91728 +#include "gimple.h"
91729 +#include "rtl.h"
91730 +#include "emit-rtl.h"
91731 +
91732 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91733 +
91734 +int plugin_is_GPL_compatible;
91735 +
91736 +static int track_frame_size = -1;
91737 +static const char track_function[] = "pax_track_stack";
91738 +static const char check_function[] = "pax_check_alloca";
91739 +static bool init_locals;
91740 +
91741 +static struct plugin_info stackleak_plugin_info = {
91742 + .version = "201203140940",
91743 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
91744 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
91745 +};
91746 +
91747 +static bool gate_stackleak_track_stack(void);
91748 +static unsigned int execute_stackleak_tree_instrument(void);
91749 +static unsigned int execute_stackleak_final(void);
91750 +
91751 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
91752 + .pass = {
91753 + .type = GIMPLE_PASS,
91754 + .name = "stackleak_tree_instrument",
91755 + .gate = gate_stackleak_track_stack,
91756 + .execute = execute_stackleak_tree_instrument,
91757 + .sub = NULL,
91758 + .next = NULL,
91759 + .static_pass_number = 0,
91760 + .tv_id = TV_NONE,
91761 + .properties_required = PROP_gimple_leh | PROP_cfg,
91762 + .properties_provided = 0,
91763 + .properties_destroyed = 0,
91764 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
91765 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
91766 + }
91767 +};
91768 +
91769 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
91770 + .pass = {
91771 + .type = RTL_PASS,
91772 + .name = "stackleak_final",
91773 + .gate = gate_stackleak_track_stack,
91774 + .execute = execute_stackleak_final,
91775 + .sub = NULL,
91776 + .next = NULL,
91777 + .static_pass_number = 0,
91778 + .tv_id = TV_NONE,
91779 + .properties_required = 0,
91780 + .properties_provided = 0,
91781 + .properties_destroyed = 0,
91782 + .todo_flags_start = 0,
91783 + .todo_flags_finish = TODO_dump_func
91784 + }
91785 +};
91786 +
91787 +static bool gate_stackleak_track_stack(void)
91788 +{
91789 + return track_frame_size >= 0;
91790 +}
91791 +
91792 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
91793 +{
91794 + gimple check_alloca;
91795 + tree fntype, fndecl, alloca_size;
91796 +
91797 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
91798 + fndecl = build_fn_decl(check_function, fntype);
91799 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
91800 +
91801 + // insert call to void pax_check_alloca(unsigned long size)
91802 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
91803 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
91804 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
91805 +}
91806 +
91807 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
91808 +{
91809 + gimple track_stack;
91810 + tree fntype, fndecl;
91811 +
91812 + fntype = build_function_type_list(void_type_node, NULL_TREE);
91813 + fndecl = build_fn_decl(track_function, fntype);
91814 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
91815 +
91816 + // insert call to void pax_track_stack(void)
91817 + track_stack = gimple_build_call(fndecl, 0);
91818 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
91819 +}
91820 +
91821 +#if BUILDING_GCC_VERSION == 4005
91822 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
91823 +{
91824 + tree fndecl;
91825 +
91826 + if (!is_gimple_call(stmt))
91827 + return false;
91828 + fndecl = gimple_call_fndecl(stmt);
91829 + if (!fndecl)
91830 + return false;
91831 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
91832 + return false;
91833 +// print_node(stderr, "pax", fndecl, 4);
91834 + return DECL_FUNCTION_CODE(fndecl) == code;
91835 +}
91836 +#endif
91837 +
91838 +static bool is_alloca(gimple stmt)
91839 +{
91840 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
91841 + return true;
91842 +
91843 +#if BUILDING_GCC_VERSION >= 4007
91844 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
91845 + return true;
91846 +#endif
91847 +
91848 + return false;
91849 +}
91850 +
91851 +static unsigned int execute_stackleak_tree_instrument(void)
91852 +{
91853 + basic_block bb, entry_bb;
91854 + bool prologue_instrumented = false, is_leaf = true;
91855 +
91856 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
91857 +
91858 + // 1. loop through BBs and GIMPLE statements
91859 + FOR_EACH_BB(bb) {
91860 + gimple_stmt_iterator gsi;
91861 +
91862 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91863 + gimple stmt;
91864 +
91865 + stmt = gsi_stmt(gsi);
91866 +
91867 + if (is_gimple_call(stmt))
91868 + is_leaf = false;
91869 +
91870 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
91871 + if (!is_alloca(stmt))
91872 + continue;
91873 +
91874 + // 2. insert stack overflow check before each __builtin_alloca call
91875 + stackleak_check_alloca(&gsi);
91876 +
91877 + // 3. insert track call after each __builtin_alloca call
91878 + stackleak_add_instrumentation(&gsi);
91879 + if (bb == entry_bb)
91880 + prologue_instrumented = true;
91881 + }
91882 + }
91883 +
91884 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
91885 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
91886 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
91887 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
91888 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
91889 + return 0;
91890 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
91891 + return 0;
91892 +
91893 + // 4. insert track call at the beginning
91894 + if (!prologue_instrumented) {
91895 + gimple_stmt_iterator gsi;
91896 +
91897 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
91898 + if (dom_info_available_p(CDI_DOMINATORS))
91899 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
91900 + gsi = gsi_start_bb(bb);
91901 + stackleak_add_instrumentation(&gsi);
91902 + }
91903 +
91904 + return 0;
91905 +}
91906 +
91907 +static unsigned int execute_stackleak_final(void)
91908 +{
91909 + rtx insn;
91910 +
91911 + if (cfun->calls_alloca)
91912 + return 0;
91913 +
91914 + // keep calls only if function frame is big enough
91915 + if (get_frame_size() >= track_frame_size)
91916 + return 0;
91917 +
91918 + // 1. find pax_track_stack calls
91919 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
91920 + // 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))
91921 + rtx body;
91922 +
91923 + if (!CALL_P(insn))
91924 + continue;
91925 + body = PATTERN(insn);
91926 + if (GET_CODE(body) != CALL)
91927 + continue;
91928 + body = XEXP(body, 0);
91929 + if (GET_CODE(body) != MEM)
91930 + continue;
91931 + body = XEXP(body, 0);
91932 + if (GET_CODE(body) != SYMBOL_REF)
91933 + continue;
91934 + if (strcmp(XSTR(body, 0), track_function))
91935 + continue;
91936 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
91937 + // 2. delete call
91938 + insn = delete_insn_and_edges(insn);
91939 +#if BUILDING_GCC_VERSION >= 4007
91940 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
91941 + insn = delete_insn_and_edges(insn);
91942 +#endif
91943 + }
91944 +
91945 +// print_simple_rtl(stderr, get_insns());
91946 +// print_rtl(stderr, get_insns());
91947 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
91948 +
91949 + return 0;
91950 +}
91951 +
91952 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91953 +{
91954 + const char * const plugin_name = plugin_info->base_name;
91955 + const int argc = plugin_info->argc;
91956 + const struct plugin_argument * const argv = plugin_info->argv;
91957 + int i;
91958 + struct register_pass_info stackleak_tree_instrument_pass_info = {
91959 + .pass = &stackleak_tree_instrument_pass.pass,
91960 +// .reference_pass_name = "tree_profile",
91961 + .reference_pass_name = "optimized",
91962 + .ref_pass_instance_number = 1,
91963 + .pos_op = PASS_POS_INSERT_BEFORE
91964 + };
91965 + struct register_pass_info stackleak_final_pass_info = {
91966 + .pass = &stackleak_final_rtl_opt_pass.pass,
91967 + .reference_pass_name = "final",
91968 + .ref_pass_instance_number = 1,
91969 + .pos_op = PASS_POS_INSERT_BEFORE
91970 + };
91971 +
91972 + if (!plugin_default_version_check(version, &gcc_version)) {
91973 + error(G_("incompatible gcc/plugin versions"));
91974 + return 1;
91975 + }
91976 +
91977 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
91978 +
91979 + for (i = 0; i < argc; ++i) {
91980 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
91981 + if (!argv[i].value) {
91982 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91983 + continue;
91984 + }
91985 + track_frame_size = atoi(argv[i].value);
91986 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
91987 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
91988 + continue;
91989 + }
91990 + if (!strcmp(argv[i].key, "initialize-locals")) {
91991 + if (argv[i].value) {
91992 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
91993 + continue;
91994 + }
91995 + init_locals = true;
91996 + continue;
91997 + }
91998 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91999 + }
92000 +
92001 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
92002 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
92003 +
92004 + return 0;
92005 +}
92006 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
92007 index 6789d78..4afd019e 100644
92008 --- a/tools/perf/util/include/asm/alternative-asm.h
92009 +++ b/tools/perf/util/include/asm/alternative-asm.h
92010 @@ -5,4 +5,7 @@
92011
92012 #define altinstruction_entry #
92013
92014 + .macro pax_force_retaddr rip=0, reload=0
92015 + .endm
92016 +
92017 #endif
92018 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
92019 index 6e8fa7e..37f02a5 100644
92020 --- a/virt/kvm/kvm_main.c
92021 +++ b/virt/kvm/kvm_main.c
92022 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
92023
92024 static cpumask_var_t cpus_hardware_enabled;
92025 static int kvm_usage_count = 0;
92026 -static atomic_t hardware_enable_failed;
92027 +static atomic_unchecked_t hardware_enable_failed;
92028
92029 struct kmem_cache *kvm_vcpu_cache;
92030 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
92031
92032 -static __read_mostly struct preempt_ops kvm_preempt_ops;
92033 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
92034 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
92035 +static struct preempt_ops kvm_preempt_ops = {
92036 + .sched_in = kvm_sched_in,
92037 + .sched_out = kvm_sched_out,
92038 +};
92039
92040 struct dentry *kvm_debugfs_dir;
92041
92042 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
92043 /* We can read the guest memory with __xxx_user() later on. */
92044 if (user_alloc &&
92045 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
92046 - !access_ok(VERIFY_WRITE,
92047 + !__access_ok(VERIFY_WRITE,
92048 (void __user *)(unsigned long)mem->userspace_addr,
92049 mem->memory_size)))
92050 goto out;
92051 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
92052
92053 if (r) {
92054 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
92055 - atomic_inc(&hardware_enable_failed);
92056 + atomic_inc_unchecked(&hardware_enable_failed);
92057 printk(KERN_INFO "kvm: enabling virtualization on "
92058 "CPU%d failed\n", cpu);
92059 }
92060 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
92061
92062 kvm_usage_count++;
92063 if (kvm_usage_count == 1) {
92064 - atomic_set(&hardware_enable_failed, 0);
92065 + atomic_set_unchecked(&hardware_enable_failed, 0);
92066 on_each_cpu(hardware_enable_nolock, NULL, 1);
92067
92068 - if (atomic_read(&hardware_enable_failed)) {
92069 + if (atomic_read_unchecked(&hardware_enable_failed)) {
92070 hardware_disable_all_nolock();
92071 r = -EBUSY;
92072 }
92073 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
92074 kvm_arch_vcpu_put(vcpu);
92075 }
92076
92077 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92078 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92079 struct module *module)
92080 {
92081 int r;
92082 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92083 if (!vcpu_align)
92084 vcpu_align = __alignof__(struct kvm_vcpu);
92085 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
92086 - 0, NULL);
92087 + SLAB_USERCOPY, NULL);
92088 if (!kvm_vcpu_cache) {
92089 r = -ENOMEM;
92090 goto out_free_3;
92091 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92092 if (r)
92093 goto out_free;
92094
92095 - kvm_chardev_ops.owner = module;
92096 - kvm_vm_fops.owner = module;
92097 - kvm_vcpu_fops.owner = module;
92098 + pax_open_kernel();
92099 + *(void **)&kvm_chardev_ops.owner = module;
92100 + *(void **)&kvm_vm_fops.owner = module;
92101 + *(void **)&kvm_vcpu_fops.owner = module;
92102 + pax_close_kernel();
92103
92104 r = misc_register(&kvm_dev);
92105 if (r) {
92106 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92107
92108 register_syscore_ops(&kvm_syscore_ops);
92109
92110 - kvm_preempt_ops.sched_in = kvm_sched_in;
92111 - kvm_preempt_ops.sched_out = kvm_sched_out;
92112 -
92113 r = kvm_init_debug();
92114 if (r) {
92115 printk(KERN_ERR "kvm: create debugfs files failed\n");