]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.0-201212161206.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.0-201212161206.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 540f7b2..c823fc5 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 @@ -1050,6 +1110,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 @@ -1210,6 +1271,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 @@ -1347,17 +1410,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 @@ -1367,11 +1434,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..65de923 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1304,7 +1304,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1340,6 +1340,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1347,8 +1351,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e1489c5..d418304 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index 812a494..71fc0b6 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index 8477b4c..c651b08 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_SYSCALL_TRACE 8
1543 #define TIF_SYSCALL_AUDIT 9
1544 #define TIF_SYSCALL_TRACEPOINT 10
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 11
1550 +
1551 #define TIF_USING_IWMMXT 17
1552 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1553 #define TIF_RESTORE_SIGMASK 20
1554 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 7e1f760..1af891c 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 90084a6..bf4bcfb 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652 #include <linux/leds.h>
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 739db3a..7f4a272 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1694
1695 current_thread_info()->syscall = scno;
1696
1697 +#ifdef CONFIG_GRKERNSEC_SETXID
1698 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1699 + gr_delayed_cred_worker();
1700 +#endif
1701 +
1702 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1703 return scno;
1704
1705 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1706 index da1d1aa..fea3ec9 100644
1707 --- a/arch/arm/kernel/setup.c
1708 +++ b/arch/arm/kernel/setup.c
1709 @@ -105,13 +105,13 @@ struct processor processor __read_mostly;
1710 struct cpu_tlb_fns cpu_tlb __read_mostly;
1711 #endif
1712 #ifdef MULTI_USER
1713 -struct cpu_user_fns cpu_user __read_mostly;
1714 +struct cpu_user_fns cpu_user __read_only;
1715 #endif
1716 #ifdef MULTI_CACHE
1717 -struct cpu_cache_fns cpu_cache __read_mostly;
1718 +struct cpu_cache_fns cpu_cache __read_only;
1719 #endif
1720 #ifdef CONFIG_OUTER_CACHE
1721 -struct outer_cache_fns outer_cache __read_mostly;
1722 +struct outer_cache_fns outer_cache __read_only;
1723 EXPORT_SYMBOL(outer_cache);
1724 #endif
1725
1726 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1727 index b0179b8..b54c6c1 100644
1728 --- a/arch/arm/kernel/traps.c
1729 +++ b/arch/arm/kernel/traps.c
1730 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1731 static int die_owner = -1;
1732 static unsigned int die_nest_count;
1733
1734 +extern void gr_handle_kernel_exploit(void);
1735 +
1736 static unsigned long oops_begin(void)
1737 {
1738 int cpu;
1739 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1740 panic("Fatal exception in interrupt");
1741 if (panic_on_oops)
1742 panic("Fatal exception");
1743 +
1744 + gr_handle_kernel_exploit();
1745 +
1746 if (signr)
1747 do_exit(signr);
1748 }
1749 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1750 index 66a477a..bee61d3 100644
1751 --- a/arch/arm/lib/copy_from_user.S
1752 +++ b/arch/arm/lib/copy_from_user.S
1753 @@ -16,7 +16,7 @@
1754 /*
1755 * Prototype:
1756 *
1757 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1758 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1759 *
1760 * Purpose:
1761 *
1762 @@ -84,11 +84,11 @@
1763
1764 .text
1765
1766 -ENTRY(__copy_from_user)
1767 +ENTRY(___copy_from_user)
1768
1769 #include "copy_template.S"
1770
1771 -ENDPROC(__copy_from_user)
1772 +ENDPROC(___copy_from_user)
1773
1774 .pushsection .fixup,"ax"
1775 .align 0
1776 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1777 index 6ee2f67..d1cce76 100644
1778 --- a/arch/arm/lib/copy_page.S
1779 +++ b/arch/arm/lib/copy_page.S
1780 @@ -10,6 +10,7 @@
1781 * ASM optimised string functions
1782 */
1783 #include <linux/linkage.h>
1784 +#include <linux/const.h>
1785 #include <asm/assembler.h>
1786 #include <asm/asm-offsets.h>
1787 #include <asm/cache.h>
1788 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1789 index d066df6..df28194 100644
1790 --- a/arch/arm/lib/copy_to_user.S
1791 +++ b/arch/arm/lib/copy_to_user.S
1792 @@ -16,7 +16,7 @@
1793 /*
1794 * Prototype:
1795 *
1796 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1797 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1798 *
1799 * Purpose:
1800 *
1801 @@ -88,11 +88,11 @@
1802 .text
1803
1804 ENTRY(__copy_to_user_std)
1805 -WEAK(__copy_to_user)
1806 +WEAK(___copy_to_user)
1807
1808 #include "copy_template.S"
1809
1810 -ENDPROC(__copy_to_user)
1811 +ENDPROC(___copy_to_user)
1812 ENDPROC(__copy_to_user_std)
1813
1814 .pushsection .fixup,"ax"
1815 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1816 index 025f742..8432b08 100644
1817 --- a/arch/arm/lib/uaccess_with_memcpy.c
1818 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1819 @@ -104,7 +104,7 @@ out:
1820 }
1821
1822 unsigned long
1823 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1824 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1825 {
1826 /*
1827 * This test is stubbed out of the main function above to keep
1828 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1829 index 2c6c218..f491e87 100644
1830 --- a/arch/arm/mach-kirkwood/common.c
1831 +++ b/arch/arm/mach-kirkwood/common.c
1832 @@ -150,7 +150,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1833 clk_gate_ops.disable(hw);
1834 }
1835
1836 -static struct clk_ops clk_gate_fn_ops;
1837 +static clk_ops_no_const clk_gate_fn_ops;
1838
1839 static struct clk __init *clk_register_gate_fn(struct device *dev,
1840 const char *name,
1841 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1842 index d95f727..12f10dd 100644
1843 --- a/arch/arm/mach-omap2/board-n8x0.c
1844 +++ b/arch/arm/mach-omap2/board-n8x0.c
1845 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1846 }
1847 #endif
1848
1849 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1850 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1851 .late_init = n8x0_menelaus_late_init,
1852 };
1853
1854 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1855 index 87cc6d0..fd4f248 100644
1856 --- a/arch/arm/mach-omap2/omap_hwmod.c
1857 +++ b/arch/arm/mach-omap2/omap_hwmod.c
1858 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
1859 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1860 struct omap_hwmod_rst_info *ohri);
1861 int (*init_clkdm)(struct omap_hwmod *oh);
1862 -};
1863 +} __no_const;
1864
1865 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1866 -static struct omap_hwmod_soc_ops soc_ops;
1867 +static struct omap_hwmod_soc_ops soc_ops __read_only;
1868
1869 /* omap_hwmod_list contains all registered struct omap_hwmods */
1870 static LIST_HEAD(omap_hwmod_list);
1871 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1872 index 5dbf13f..d908372 100644
1873 --- a/arch/arm/mm/fault.c
1874 +++ b/arch/arm/mm/fault.c
1875 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1876 }
1877 #endif
1878
1879 +#ifdef CONFIG_PAX_PAGEEXEC
1880 + if (fsr & FSR_LNX_PF) {
1881 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1882 + do_group_exit(SIGKILL);
1883 + }
1884 +#endif
1885 +
1886 tsk->thread.address = addr;
1887 tsk->thread.error_code = fsr;
1888 tsk->thread.trap_no = 14;
1889 @@ -398,6 +405,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1890 }
1891 #endif /* CONFIG_MMU */
1892
1893 +#ifdef CONFIG_PAX_PAGEEXEC
1894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1895 +{
1896 + long i;
1897 +
1898 + printk(KERN_ERR "PAX: bytes at PC: ");
1899 + for (i = 0; i < 20; i++) {
1900 + unsigned char c;
1901 + if (get_user(c, (__force unsigned char __user *)pc+i))
1902 + printk(KERN_CONT "?? ");
1903 + else
1904 + printk(KERN_CONT "%02x ", c);
1905 + }
1906 + printk("\n");
1907 +
1908 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1909 + for (i = -1; i < 20; i++) {
1910 + unsigned long c;
1911 + if (get_user(c, (__force unsigned long __user *)sp+i))
1912 + printk(KERN_CONT "???????? ");
1913 + else
1914 + printk(KERN_CONT "%08lx ", c);
1915 + }
1916 + printk("\n");
1917 +}
1918 +#endif
1919 +
1920 /*
1921 * First Level Translation Fault Handler
1922 *
1923 @@ -575,6 +609,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1924 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1925 struct siginfo info;
1926
1927 +#ifdef CONFIG_PAX_REFCOUNT
1928 + if (fsr_fs(ifsr) == 2) {
1929 + unsigned int bkpt;
1930 +
1931 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1932 + current->thread.error_code = ifsr;
1933 + current->thread.trap_no = 0;
1934 + pax_report_refcount_overflow(regs);
1935 + fixup_exception(regs);
1936 + return;
1937 + }
1938 + }
1939 +#endif
1940 +
1941 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1942 return;
1943
1944 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1945 index ce8cb19..3ec539d 100644
1946 --- a/arch/arm/mm/mmap.c
1947 +++ b/arch/arm/mm/mmap.c
1948 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1949 if (len > TASK_SIZE)
1950 return -ENOMEM;
1951
1952 +#ifdef CONFIG_PAX_RANDMMAP
1953 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1954 +#endif
1955 +
1956 if (addr) {
1957 if (do_align)
1958 addr = COLOUR_ALIGN(addr, pgoff);
1959 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1960 addr = PAGE_ALIGN(addr);
1961
1962 vma = find_vma(mm, addr);
1963 - if (TASK_SIZE - len >= addr &&
1964 - (!vma || addr + len <= vma->vm_start))
1965 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1966 return addr;
1967 }
1968 if (len > mm->cached_hole_size) {
1969 - start_addr = addr = mm->free_area_cache;
1970 + start_addr = addr = mm->free_area_cache;
1971 } else {
1972 - start_addr = addr = mm->mmap_base;
1973 - mm->cached_hole_size = 0;
1974 + start_addr = addr = mm->mmap_base;
1975 + mm->cached_hole_size = 0;
1976 }
1977
1978 full_search:
1979 @@ -124,14 +127,14 @@ full_search:
1980 * Start a new search - just in case we missed
1981 * some holes.
1982 */
1983 - if (start_addr != TASK_UNMAPPED_BASE) {
1984 - start_addr = addr = TASK_UNMAPPED_BASE;
1985 + if (start_addr != mm->mmap_base) {
1986 + start_addr = addr = mm->mmap_base;
1987 mm->cached_hole_size = 0;
1988 goto full_search;
1989 }
1990 return -ENOMEM;
1991 }
1992 - if (!vma || addr + len <= vma->vm_start) {
1993 + if (check_heap_stack_gap(vma, addr, len)) {
1994 /*
1995 * Remember the place where we stopped the search:
1996 */
1997 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1998
1999 if (mmap_is_legacy()) {
2000 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2001 +
2002 +#ifdef CONFIG_PAX_RANDMMAP
2003 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2004 + mm->mmap_base += mm->delta_mmap;
2005 +#endif
2006 +
2007 mm->get_unmapped_area = arch_get_unmapped_area;
2008 mm->unmap_area = arch_unmap_area;
2009 } else {
2010 mm->mmap_base = mmap_base(random_factor);
2011 +
2012 +#ifdef CONFIG_PAX_RANDMMAP
2013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2014 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2015 +#endif
2016 +
2017 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2018 mm->unmap_area = arch_unmap_area_topdown;
2019 }
2020 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2021 index ec63e4a..62aa5f1d 100644
2022 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2023 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2024 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2025 value in bridge_virt_base */
2026 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2027 const int win);
2028 -};
2029 +} __no_const;
2030
2031 /*
2032 * Information needed to setup one address mapping.
2033 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 index f5144cd..71f6d1f 100644
2035 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2036 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2037 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2038 int (*started)(unsigned ch);
2039 int (*flush)(unsigned ch);
2040 int (*stop)(unsigned ch);
2041 -};
2042 +} __no_const;
2043
2044 extern void *samsung_dmadev_get_ops(void);
2045 extern void *s3c_dma_get_ops(void);
2046 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2047 index c3a58a1..78fbf54 100644
2048 --- a/arch/avr32/include/asm/cache.h
2049 +++ b/arch/avr32/include/asm/cache.h
2050 @@ -1,8 +1,10 @@
2051 #ifndef __ASM_AVR32_CACHE_H
2052 #define __ASM_AVR32_CACHE_H
2053
2054 +#include <linux/const.h>
2055 +
2056 #define L1_CACHE_SHIFT 5
2057 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2058 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2059
2060 /*
2061 * Memory returned by kmalloc() may be used for DMA, so we must make
2062 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2063 index e2c3287..6c4f98c 100644
2064 --- a/arch/avr32/include/asm/elf.h
2065 +++ b/arch/avr32/include/asm/elf.h
2066 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2067 the loader. We need to make sure that it is out of the way of the program
2068 that it will "exec", and that there is sufficient room for the brk. */
2069
2070 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2071 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2072
2073 +#ifdef CONFIG_PAX_ASLR
2074 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2075 +
2076 +#define PAX_DELTA_MMAP_LEN 15
2077 +#define PAX_DELTA_STACK_LEN 15
2078 +#endif
2079
2080 /* This yields a mask that user programs can use to figure out what
2081 instruction set this CPU supports. This could be done in user space,
2082 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2083 index 479330b..53717a8 100644
2084 --- a/arch/avr32/include/asm/kmap_types.h
2085 +++ b/arch/avr32/include/asm/kmap_types.h
2086 @@ -2,9 +2,9 @@
2087 #define __ASM_AVR32_KMAP_TYPES_H
2088
2089 #ifdef CONFIG_DEBUG_HIGHMEM
2090 -# define KM_TYPE_NR 29
2091 +# define KM_TYPE_NR 30
2092 #else
2093 -# define KM_TYPE_NR 14
2094 +# define KM_TYPE_NR 15
2095 #endif
2096
2097 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2098 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2099 index b2f2d2d..d1c85cb 100644
2100 --- a/arch/avr32/mm/fault.c
2101 +++ b/arch/avr32/mm/fault.c
2102 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2103
2104 int exception_trace = 1;
2105
2106 +#ifdef CONFIG_PAX_PAGEEXEC
2107 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2108 +{
2109 + unsigned long i;
2110 +
2111 + printk(KERN_ERR "PAX: bytes at PC: ");
2112 + for (i = 0; i < 20; i++) {
2113 + unsigned char c;
2114 + if (get_user(c, (unsigned char *)pc+i))
2115 + printk(KERN_CONT "???????? ");
2116 + else
2117 + printk(KERN_CONT "%02x ", c);
2118 + }
2119 + printk("\n");
2120 +}
2121 +#endif
2122 +
2123 /*
2124 * This routine handles page faults. It determines the address and the
2125 * problem, and then passes it off to one of the appropriate routines.
2126 @@ -174,6 +191,16 @@ bad_area:
2127 up_read(&mm->mmap_sem);
2128
2129 if (user_mode(regs)) {
2130 +
2131 +#ifdef CONFIG_PAX_PAGEEXEC
2132 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2133 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2134 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2135 + do_group_exit(SIGKILL);
2136 + }
2137 + }
2138 +#endif
2139 +
2140 if (exception_trace && printk_ratelimit())
2141 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2142 "sp %08lx ecr %lu\n",
2143 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2144 index 568885a..f8008df 100644
2145 --- a/arch/blackfin/include/asm/cache.h
2146 +++ b/arch/blackfin/include/asm/cache.h
2147 @@ -7,6 +7,7 @@
2148 #ifndef __ARCH_BLACKFIN_CACHE_H
2149 #define __ARCH_BLACKFIN_CACHE_H
2150
2151 +#include <linux/const.h>
2152 #include <linux/linkage.h> /* for asmlinkage */
2153
2154 /*
2155 @@ -14,7 +15,7 @@
2156 * Blackfin loads 32 bytes for cache
2157 */
2158 #define L1_CACHE_SHIFT 5
2159 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2160 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2161 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2162
2163 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2164 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2165 index aea2718..3639a60 100644
2166 --- a/arch/cris/include/arch-v10/arch/cache.h
2167 +++ b/arch/cris/include/arch-v10/arch/cache.h
2168 @@ -1,8 +1,9 @@
2169 #ifndef _ASM_ARCH_CACHE_H
2170 #define _ASM_ARCH_CACHE_H
2171
2172 +#include <linux/const.h>
2173 /* Etrax 100LX have 32-byte cache-lines. */
2174 -#define L1_CACHE_BYTES 32
2175 #define L1_CACHE_SHIFT 5
2176 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2177
2178 #endif /* _ASM_ARCH_CACHE_H */
2179 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2180 index 7caf25d..ee65ac5 100644
2181 --- a/arch/cris/include/arch-v32/arch/cache.h
2182 +++ b/arch/cris/include/arch-v32/arch/cache.h
2183 @@ -1,11 +1,12 @@
2184 #ifndef _ASM_CRIS_ARCH_CACHE_H
2185 #define _ASM_CRIS_ARCH_CACHE_H
2186
2187 +#include <linux/const.h>
2188 #include <arch/hwregs/dma.h>
2189
2190 /* A cache-line is 32 bytes. */
2191 -#define L1_CACHE_BYTES 32
2192 #define L1_CACHE_SHIFT 5
2193 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2194
2195 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2196
2197 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2198 index b86329d..6709906 100644
2199 --- a/arch/frv/include/asm/atomic.h
2200 +++ b/arch/frv/include/asm/atomic.h
2201 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2202 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2203 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2204
2205 +#define atomic64_read_unchecked(v) atomic64_read(v)
2206 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2207 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2208 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2209 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2210 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2211 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2212 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2213 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2214 +
2215 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2216 {
2217 int c, old;
2218 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2219 index 2797163..c2a401d 100644
2220 --- a/arch/frv/include/asm/cache.h
2221 +++ b/arch/frv/include/asm/cache.h
2222 @@ -12,10 +12,11 @@
2223 #ifndef __ASM_CACHE_H
2224 #define __ASM_CACHE_H
2225
2226 +#include <linux/const.h>
2227
2228 /* bytes per L1 cache line */
2229 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2230 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2231 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2232
2233 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2234 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2235 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2236 index 43901f2..0d8b865 100644
2237 --- a/arch/frv/include/asm/kmap_types.h
2238 +++ b/arch/frv/include/asm/kmap_types.h
2239 @@ -2,6 +2,6 @@
2240 #ifndef _ASM_KMAP_TYPES_H
2241 #define _ASM_KMAP_TYPES_H
2242
2243 -#define KM_TYPE_NR 17
2244 +#define KM_TYPE_NR 18
2245
2246 #endif
2247 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2248 index 385fd30..6c3d97e 100644
2249 --- a/arch/frv/mm/elf-fdpic.c
2250 +++ b/arch/frv/mm/elf-fdpic.c
2251 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2252 if (addr) {
2253 addr = PAGE_ALIGN(addr);
2254 vma = find_vma(current->mm, addr);
2255 - if (TASK_SIZE - len >= addr &&
2256 - (!vma || addr + len <= vma->vm_start))
2257 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2258 goto success;
2259 }
2260
2261 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2262 for (; vma; vma = vma->vm_next) {
2263 if (addr > limit)
2264 break;
2265 - if (addr + len <= vma->vm_start)
2266 + if (check_heap_stack_gap(vma, addr, len))
2267 goto success;
2268 addr = vma->vm_end;
2269 }
2270 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2271 for (; vma; vma = vma->vm_next) {
2272 if (addr > limit)
2273 break;
2274 - if (addr + len <= vma->vm_start)
2275 + if (check_heap_stack_gap(vma, addr, len))
2276 goto success;
2277 addr = vma->vm_end;
2278 }
2279 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2280 index f4ca594..adc72fd6 100644
2281 --- a/arch/hexagon/include/asm/cache.h
2282 +++ b/arch/hexagon/include/asm/cache.h
2283 @@ -21,9 +21,11 @@
2284 #ifndef __ASM_CACHE_H
2285 #define __ASM_CACHE_H
2286
2287 +#include <linux/const.h>
2288 +
2289 /* Bytes per L1 cache line */
2290 -#define L1_CACHE_SHIFT (5)
2291 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2292 +#define L1_CACHE_SHIFT 5
2293 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2294
2295 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2296 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2297 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2298 index 6e6fe18..a6ae668 100644
2299 --- a/arch/ia64/include/asm/atomic.h
2300 +++ b/arch/ia64/include/asm/atomic.h
2301 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2302 #define atomic64_inc(v) atomic64_add(1, (v))
2303 #define atomic64_dec(v) atomic64_sub(1, (v))
2304
2305 +#define atomic64_read_unchecked(v) atomic64_read(v)
2306 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2307 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2308 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2309 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2310 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2311 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2312 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2313 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2314 +
2315 /* Atomic operations are already serializing */
2316 #define smp_mb__before_atomic_dec() barrier()
2317 #define smp_mb__after_atomic_dec() barrier()
2318 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2319 index 988254a..e1ee885 100644
2320 --- a/arch/ia64/include/asm/cache.h
2321 +++ b/arch/ia64/include/asm/cache.h
2322 @@ -1,6 +1,7 @@
2323 #ifndef _ASM_IA64_CACHE_H
2324 #define _ASM_IA64_CACHE_H
2325
2326 +#include <linux/const.h>
2327
2328 /*
2329 * Copyright (C) 1998-2000 Hewlett-Packard Co
2330 @@ -9,7 +10,7 @@
2331
2332 /* Bytes per L1 (data) cache line. */
2333 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2334 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2335 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2336
2337 #ifdef CONFIG_SMP
2338 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2339 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2340 index b5298eb..67c6e62 100644
2341 --- a/arch/ia64/include/asm/elf.h
2342 +++ b/arch/ia64/include/asm/elf.h
2343 @@ -42,6 +42,13 @@
2344 */
2345 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2346
2347 +#ifdef CONFIG_PAX_ASLR
2348 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2349 +
2350 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2351 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2352 +#endif
2353 +
2354 #define PT_IA_64_UNWIND 0x70000001
2355
2356 /* IA-64 relocations: */
2357 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2358 index 96a8d92..617a1cf 100644
2359 --- a/arch/ia64/include/asm/pgalloc.h
2360 +++ b/arch/ia64/include/asm/pgalloc.h
2361 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2362 pgd_val(*pgd_entry) = __pa(pud);
2363 }
2364
2365 +static inline void
2366 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2367 +{
2368 + pgd_populate(mm, pgd_entry, pud);
2369 +}
2370 +
2371 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2372 {
2373 return quicklist_alloc(0, GFP_KERNEL, NULL);
2374 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2375 pud_val(*pud_entry) = __pa(pmd);
2376 }
2377
2378 +static inline void
2379 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2380 +{
2381 + pud_populate(mm, pud_entry, pmd);
2382 +}
2383 +
2384 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2385 {
2386 return quicklist_alloc(0, GFP_KERNEL, NULL);
2387 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2388 index 815810c..d60bd4c 100644
2389 --- a/arch/ia64/include/asm/pgtable.h
2390 +++ b/arch/ia64/include/asm/pgtable.h
2391 @@ -12,7 +12,7 @@
2392 * David Mosberger-Tang <davidm@hpl.hp.com>
2393 */
2394
2395 -
2396 +#include <linux/const.h>
2397 #include <asm/mman.h>
2398 #include <asm/page.h>
2399 #include <asm/processor.h>
2400 @@ -142,6 +142,17 @@
2401 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2402 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2403 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2404 +
2405 +#ifdef CONFIG_PAX_PAGEEXEC
2406 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2407 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2408 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2409 +#else
2410 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2411 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2412 +# define PAGE_COPY_NOEXEC PAGE_COPY
2413 +#endif
2414 +
2415 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2416 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2417 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2418 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2419 index 54ff557..70c88b7 100644
2420 --- a/arch/ia64/include/asm/spinlock.h
2421 +++ b/arch/ia64/include/asm/spinlock.h
2422 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2423 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2424
2425 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2426 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2427 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2428 }
2429
2430 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2431 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2432 index 449c8c0..432a3d2 100644
2433 --- a/arch/ia64/include/asm/uaccess.h
2434 +++ b/arch/ia64/include/asm/uaccess.h
2435 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2436 const void *__cu_from = (from); \
2437 long __cu_len = (n); \
2438 \
2439 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2440 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2441 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2442 __cu_len; \
2443 })
2444 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2445 long __cu_len = (n); \
2446 \
2447 __chk_user_ptr(__cu_from); \
2448 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2449 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2450 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2451 __cu_len; \
2452 })
2453 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2454 index 24603be..948052d 100644
2455 --- a/arch/ia64/kernel/module.c
2456 +++ b/arch/ia64/kernel/module.c
2457 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2458 void
2459 module_free (struct module *mod, void *module_region)
2460 {
2461 - if (mod && mod->arch.init_unw_table &&
2462 - module_region == mod->module_init) {
2463 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2464 unw_remove_unwind_table(mod->arch.init_unw_table);
2465 mod->arch.init_unw_table = NULL;
2466 }
2467 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2468 }
2469
2470 static inline int
2471 +in_init_rx (const struct module *mod, uint64_t addr)
2472 +{
2473 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2474 +}
2475 +
2476 +static inline int
2477 +in_init_rw (const struct module *mod, uint64_t addr)
2478 +{
2479 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2480 +}
2481 +
2482 +static inline int
2483 in_init (const struct module *mod, uint64_t addr)
2484 {
2485 - return addr - (uint64_t) mod->module_init < mod->init_size;
2486 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2487 +}
2488 +
2489 +static inline int
2490 +in_core_rx (const struct module *mod, uint64_t addr)
2491 +{
2492 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2493 +}
2494 +
2495 +static inline int
2496 +in_core_rw (const struct module *mod, uint64_t addr)
2497 +{
2498 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2499 }
2500
2501 static inline int
2502 in_core (const struct module *mod, uint64_t addr)
2503 {
2504 - return addr - (uint64_t) mod->module_core < mod->core_size;
2505 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2506 }
2507
2508 static inline int
2509 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2510 break;
2511
2512 case RV_BDREL:
2513 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2514 + if (in_init_rx(mod, val))
2515 + val -= (uint64_t) mod->module_init_rx;
2516 + else if (in_init_rw(mod, val))
2517 + val -= (uint64_t) mod->module_init_rw;
2518 + else if (in_core_rx(mod, val))
2519 + val -= (uint64_t) mod->module_core_rx;
2520 + else if (in_core_rw(mod, val))
2521 + val -= (uint64_t) mod->module_core_rw;
2522 break;
2523
2524 case RV_LTV:
2525 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2526 * addresses have been selected...
2527 */
2528 uint64_t gp;
2529 - if (mod->core_size > MAX_LTOFF)
2530 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2531 /*
2532 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2533 * at the end of the module.
2534 */
2535 - gp = mod->core_size - MAX_LTOFF / 2;
2536 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2537 else
2538 - gp = mod->core_size / 2;
2539 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2540 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2541 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2542 mod->arch.gp = gp;
2543 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2544 }
2545 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2546 index d9439ef..b9a4303 100644
2547 --- a/arch/ia64/kernel/sys_ia64.c
2548 +++ b/arch/ia64/kernel/sys_ia64.c
2549 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2550 if (REGION_NUMBER(addr) == RGN_HPAGE)
2551 addr = 0;
2552 #endif
2553 +
2554 +#ifdef CONFIG_PAX_RANDMMAP
2555 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2556 + addr = mm->free_area_cache;
2557 + else
2558 +#endif
2559 +
2560 if (!addr)
2561 addr = mm->free_area_cache;
2562
2563 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2564 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2565 /* At this point: (!vma || addr < vma->vm_end). */
2566 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2567 - if (start_addr != TASK_UNMAPPED_BASE) {
2568 + if (start_addr != mm->mmap_base) {
2569 /* Start a new search --- just in case we missed some holes. */
2570 - addr = TASK_UNMAPPED_BASE;
2571 + addr = mm->mmap_base;
2572 goto full_search;
2573 }
2574 return -ENOMEM;
2575 }
2576 - if (!vma || addr + len <= vma->vm_start) {
2577 + if (check_heap_stack_gap(vma, addr, len)) {
2578 /* Remember the address where we stopped this search: */
2579 mm->free_area_cache = addr + len;
2580 return addr;
2581 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2582 index 0ccb28f..8992469 100644
2583 --- a/arch/ia64/kernel/vmlinux.lds.S
2584 +++ b/arch/ia64/kernel/vmlinux.lds.S
2585 @@ -198,7 +198,7 @@ SECTIONS {
2586 /* Per-cpu data: */
2587 . = ALIGN(PERCPU_PAGE_SIZE);
2588 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2589 - __phys_per_cpu_start = __per_cpu_load;
2590 + __phys_per_cpu_start = per_cpu_load;
2591 /*
2592 * ensure percpu data fits
2593 * into percpu page size
2594 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2595 index 6cf0341..d352594 100644
2596 --- a/arch/ia64/mm/fault.c
2597 +++ b/arch/ia64/mm/fault.c
2598 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2599 return pte_present(pte);
2600 }
2601
2602 +#ifdef CONFIG_PAX_PAGEEXEC
2603 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2604 +{
2605 + unsigned long i;
2606 +
2607 + printk(KERN_ERR "PAX: bytes at PC: ");
2608 + for (i = 0; i < 8; i++) {
2609 + unsigned int c;
2610 + if (get_user(c, (unsigned int *)pc+i))
2611 + printk(KERN_CONT "???????? ");
2612 + else
2613 + printk(KERN_CONT "%08x ", c);
2614 + }
2615 + printk("\n");
2616 +}
2617 +#endif
2618 +
2619 # define VM_READ_BIT 0
2620 # define VM_WRITE_BIT 1
2621 # define VM_EXEC_BIT 2
2622 @@ -149,8 +166,21 @@ retry:
2623 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2624 goto bad_area;
2625
2626 - if ((vma->vm_flags & mask) != mask)
2627 + if ((vma->vm_flags & mask) != mask) {
2628 +
2629 +#ifdef CONFIG_PAX_PAGEEXEC
2630 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2631 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2632 + goto bad_area;
2633 +
2634 + up_read(&mm->mmap_sem);
2635 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2636 + do_group_exit(SIGKILL);
2637 + }
2638 +#endif
2639 +
2640 goto bad_area;
2641 + }
2642
2643 /*
2644 * If for any reason at all we couldn't handle the fault, make
2645 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2646 index 5ca674b..e0e1b70 100644
2647 --- a/arch/ia64/mm/hugetlbpage.c
2648 +++ b/arch/ia64/mm/hugetlbpage.c
2649 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2650 /* At this point: (!vmm || addr < vmm->vm_end). */
2651 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2652 return -ENOMEM;
2653 - if (!vmm || (addr + len) <= vmm->vm_start)
2654 + if (check_heap_stack_gap(vmm, addr, len))
2655 return addr;
2656 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2657 }
2658 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2659 index 082e383..fb7be80 100644
2660 --- a/arch/ia64/mm/init.c
2661 +++ b/arch/ia64/mm/init.c
2662 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2663 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2664 vma->vm_end = vma->vm_start + PAGE_SIZE;
2665 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2666 +
2667 +#ifdef CONFIG_PAX_PAGEEXEC
2668 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2669 + vma->vm_flags &= ~VM_EXEC;
2670 +
2671 +#ifdef CONFIG_PAX_MPROTECT
2672 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2673 + vma->vm_flags &= ~VM_MAYEXEC;
2674 +#endif
2675 +
2676 + }
2677 +#endif
2678 +
2679 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2680 down_write(&current->mm->mmap_sem);
2681 if (insert_vm_struct(current->mm, vma)) {
2682 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2683 index 40b3ee9..8c2c112 100644
2684 --- a/arch/m32r/include/asm/cache.h
2685 +++ b/arch/m32r/include/asm/cache.h
2686 @@ -1,8 +1,10 @@
2687 #ifndef _ASM_M32R_CACHE_H
2688 #define _ASM_M32R_CACHE_H
2689
2690 +#include <linux/const.h>
2691 +
2692 /* L1 cache line size */
2693 #define L1_CACHE_SHIFT 4
2694 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2695 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2696
2697 #endif /* _ASM_M32R_CACHE_H */
2698 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2699 index 82abd15..d95ae5d 100644
2700 --- a/arch/m32r/lib/usercopy.c
2701 +++ b/arch/m32r/lib/usercopy.c
2702 @@ -14,6 +14,9 @@
2703 unsigned long
2704 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2705 {
2706 + if ((long)n < 0)
2707 + return n;
2708 +
2709 prefetch(from);
2710 if (access_ok(VERIFY_WRITE, to, n))
2711 __copy_user(to,from,n);
2712 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2713 unsigned long
2714 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2715 {
2716 + if ((long)n < 0)
2717 + return n;
2718 +
2719 prefetchw(to);
2720 if (access_ok(VERIFY_READ, from, n))
2721 __copy_user_zeroing(to,from,n);
2722 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2723 index 0395c51..5f26031 100644
2724 --- a/arch/m68k/include/asm/cache.h
2725 +++ b/arch/m68k/include/asm/cache.h
2726 @@ -4,9 +4,11 @@
2727 #ifndef __ARCH_M68K_CACHE_H
2728 #define __ARCH_M68K_CACHE_H
2729
2730 +#include <linux/const.h>
2731 +
2732 /* bytes per L1 cache line */
2733 #define L1_CACHE_SHIFT 4
2734 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2735 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2736
2737 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2738
2739 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2740 index 4efe96a..60e8699 100644
2741 --- a/arch/microblaze/include/asm/cache.h
2742 +++ b/arch/microblaze/include/asm/cache.h
2743 @@ -13,11 +13,12 @@
2744 #ifndef _ASM_MICROBLAZE_CACHE_H
2745 #define _ASM_MICROBLAZE_CACHE_H
2746
2747 +#include <linux/const.h>
2748 #include <asm/registers.h>
2749
2750 #define L1_CACHE_SHIFT 5
2751 /* word-granular cache in microblaze */
2752 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2753 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2754
2755 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2756
2757 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2758 index 01cc6ba..bcb7a5d 100644
2759 --- a/arch/mips/include/asm/atomic.h
2760 +++ b/arch/mips/include/asm/atomic.h
2761 @@ -21,6 +21,10 @@
2762 #include <asm/cmpxchg.h>
2763 #include <asm/war.h>
2764
2765 +#ifdef CONFIG_GENERIC_ATOMIC64
2766 +#include <asm-generic/atomic64.h>
2767 +#endif
2768 +
2769 #define ATOMIC_INIT(i) { (i) }
2770
2771 /*
2772 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2773 */
2774 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2775
2776 +#define atomic64_read_unchecked(v) atomic64_read(v)
2777 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2778 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2779 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2780 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2781 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2782 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2783 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2784 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2785 +
2786 #endif /* CONFIG_64BIT */
2787
2788 /*
2789 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2790 index b4db69f..8f3b093 100644
2791 --- a/arch/mips/include/asm/cache.h
2792 +++ b/arch/mips/include/asm/cache.h
2793 @@ -9,10 +9,11 @@
2794 #ifndef _ASM_CACHE_H
2795 #define _ASM_CACHE_H
2796
2797 +#include <linux/const.h>
2798 #include <kmalloc.h>
2799
2800 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2801 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2802 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2803
2804 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2805 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2806 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2807 index 455c0ac..ad65fbe 100644
2808 --- a/arch/mips/include/asm/elf.h
2809 +++ b/arch/mips/include/asm/elf.h
2810 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2811 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2812 #endif
2813
2814 +#ifdef CONFIG_PAX_ASLR
2815 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2816 +
2817 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2818 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2819 +#endif
2820 +
2821 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2822 struct linux_binprm;
2823 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2824 int uses_interp);
2825
2826 -struct mm_struct;
2827 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2828 -#define arch_randomize_brk arch_randomize_brk
2829 -
2830 #endif /* _ASM_ELF_H */
2831 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2832 index c1f6afa..38cc6e9 100644
2833 --- a/arch/mips/include/asm/exec.h
2834 +++ b/arch/mips/include/asm/exec.h
2835 @@ -12,6 +12,6 @@
2836 #ifndef _ASM_EXEC_H
2837 #define _ASM_EXEC_H
2838
2839 -extern unsigned long arch_align_stack(unsigned long sp);
2840 +#define arch_align_stack(x) ((x) & ~0xfUL)
2841
2842 #endif /* _ASM_EXEC_H */
2843 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2844 index da9bd7d..91aa7ab 100644
2845 --- a/arch/mips/include/asm/page.h
2846 +++ b/arch/mips/include/asm/page.h
2847 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2848 #ifdef CONFIG_CPU_MIPS32
2849 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2850 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2851 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2852 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2853 #else
2854 typedef struct { unsigned long long pte; } pte_t;
2855 #define pte_val(x) ((x).pte)
2856 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2857 index 881d18b..cea38bc 100644
2858 --- a/arch/mips/include/asm/pgalloc.h
2859 +++ b/arch/mips/include/asm/pgalloc.h
2860 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2861 {
2862 set_pud(pud, __pud((unsigned long)pmd));
2863 }
2864 +
2865 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2866 +{
2867 + pud_populate(mm, pud, pmd);
2868 +}
2869 #endif
2870
2871 /*
2872 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2873 index 18806a5..141ffcf 100644
2874 --- a/arch/mips/include/asm/thread_info.h
2875 +++ b/arch/mips/include/asm/thread_info.h
2876 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2877 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2878 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2879 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2880 +/* li takes a 32bit immediate */
2881 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2882 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2883
2884 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
2885 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2886 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2887 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2888 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2889 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2890 +
2891 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2892
2893 /* work to do in syscall_trace_leave() */
2894 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2895 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2896
2897 /* work to do on interrupt/exception return */
2898 #define _TIF_WORK_MASK \
2899 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
2900 /* work to do on any return to u-space */
2901 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
2902 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
2903
2904 #endif /* __KERNEL__ */
2905
2906 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2907 index 9fdd8bc..4bd7f1a 100644
2908 --- a/arch/mips/kernel/binfmt_elfn32.c
2909 +++ b/arch/mips/kernel/binfmt_elfn32.c
2910 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2911 #undef ELF_ET_DYN_BASE
2912 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2913
2914 +#ifdef CONFIG_PAX_ASLR
2915 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2916 +
2917 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2918 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2919 +#endif
2920 +
2921 #include <asm/processor.h>
2922 #include <linux/module.h>
2923 #include <linux/elfcore.h>
2924 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2925 index ff44823..97f8906 100644
2926 --- a/arch/mips/kernel/binfmt_elfo32.c
2927 +++ b/arch/mips/kernel/binfmt_elfo32.c
2928 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2929 #undef ELF_ET_DYN_BASE
2930 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2931
2932 +#ifdef CONFIG_PAX_ASLR
2933 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2934 +
2935 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2936 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2937 +#endif
2938 +
2939 #include <asm/processor.h>
2940
2941 /*
2942 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2943 index e9a5fd7..378809a 100644
2944 --- a/arch/mips/kernel/process.c
2945 +++ b/arch/mips/kernel/process.c
2946 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2947 out:
2948 return pc;
2949 }
2950 -
2951 -/*
2952 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2953 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2954 - */
2955 -unsigned long arch_align_stack(unsigned long sp)
2956 -{
2957 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2958 - sp -= get_random_int() & ~PAGE_MASK;
2959 -
2960 - return sp & ALMASK;
2961 -}
2962 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2963 index 4812c6d..2069554 100644
2964 --- a/arch/mips/kernel/ptrace.c
2965 +++ b/arch/mips/kernel/ptrace.c
2966 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2967 return arch;
2968 }
2969
2970 +#ifdef CONFIG_GRKERNSEC_SETXID
2971 +extern void gr_delayed_cred_worker(void);
2972 +#endif
2973 +
2974 /*
2975 * Notification of system call entry/exit
2976 * - triggered by current->work.syscall_trace
2977 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2978 /* do the secure computing check first */
2979 secure_computing_strict(regs->regs[2]);
2980
2981 +#ifdef CONFIG_GRKERNSEC_SETXID
2982 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2983 + gr_delayed_cred_worker();
2984 +#endif
2985 +
2986 if (!(current->ptrace & PT_PTRACED))
2987 goto out;
2988
2989 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
2990 index 374f66e..1c882a0 100644
2991 --- a/arch/mips/kernel/scall32-o32.S
2992 +++ b/arch/mips/kernel/scall32-o32.S
2993 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
2994
2995 stack_done:
2996 lw t0, TI_FLAGS($28) # syscall tracing enabled?
2997 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2998 + li t1, _TIF_SYSCALL_WORK
2999 and t0, t1
3000 bnez t0, syscall_trace_entry # -> yes
3001
3002 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3003 index 169de6a..f594a89 100644
3004 --- a/arch/mips/kernel/scall64-64.S
3005 +++ b/arch/mips/kernel/scall64-64.S
3006 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3007
3008 sd a3, PT_R26(sp) # save a3 for syscall restarting
3009
3010 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3011 + li t1, _TIF_SYSCALL_WORK
3012 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3013 and t0, t1, t0
3014 bnez t0, syscall_trace_entry
3015 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3016 index 86ec03f..1235baf 100644
3017 --- a/arch/mips/kernel/scall64-n32.S
3018 +++ b/arch/mips/kernel/scall64-n32.S
3019 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3020
3021 sd a3, PT_R26(sp) # save a3 for syscall restarting
3022
3023 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3024 + li t1, _TIF_SYSCALL_WORK
3025 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3026 and t0, t1, t0
3027 bnez t0, n32_syscall_trace_entry
3028 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3029 index 53c2d72..3734584 100644
3030 --- a/arch/mips/kernel/scall64-o32.S
3031 +++ b/arch/mips/kernel/scall64-o32.S
3032 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3033 PTR 4b, bad_stack
3034 .previous
3035
3036 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3037 + li t1, _TIF_SYSCALL_WORK
3038 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3039 and t0, t1, t0
3040 bnez t0, trace_a_syscall
3041 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3042 index ddcec1e..c7f983e 100644
3043 --- a/arch/mips/mm/fault.c
3044 +++ b/arch/mips/mm/fault.c
3045 @@ -27,6 +27,23 @@
3046 #include <asm/highmem.h> /* For VMALLOC_END */
3047 #include <linux/kdebug.h>
3048
3049 +#ifdef CONFIG_PAX_PAGEEXEC
3050 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3051 +{
3052 + unsigned long i;
3053 +
3054 + printk(KERN_ERR "PAX: bytes at PC: ");
3055 + for (i = 0; i < 5; i++) {
3056 + unsigned int c;
3057 + if (get_user(c, (unsigned int *)pc+i))
3058 + printk(KERN_CONT "???????? ");
3059 + else
3060 + printk(KERN_CONT "%08x ", c);
3061 + }
3062 + printk("\n");
3063 +}
3064 +#endif
3065 +
3066 /*
3067 * This routine handles page faults. It determines the address,
3068 * and the problem, and then passes it off to one of the appropriate
3069 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3070 index 302d779..7d35bf8 100644
3071 --- a/arch/mips/mm/mmap.c
3072 +++ b/arch/mips/mm/mmap.c
3073 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3074 do_color_align = 1;
3075
3076 /* requesting a specific address */
3077 +
3078 +#ifdef CONFIG_PAX_RANDMMAP
3079 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3080 +#endif
3081 +
3082 if (addr) {
3083 if (do_color_align)
3084 addr = COLOUR_ALIGN(addr, pgoff);
3085 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3086 addr = PAGE_ALIGN(addr);
3087
3088 vma = find_vma(mm, addr);
3089 - if (TASK_SIZE - len >= addr &&
3090 - (!vma || addr + len <= vma->vm_start))
3091 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3092 return addr;
3093 }
3094
3095 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3096 /* At this point: (!vma || addr < vma->vm_end). */
3097 if (TASK_SIZE - len < addr)
3098 return -ENOMEM;
3099 - if (!vma || addr + len <= vma->vm_start)
3100 + if (check_heap_stack_gap(vmm, addr, len))
3101 return addr;
3102 addr = vma->vm_end;
3103 if (do_color_align)
3104 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3105 /* make sure it can fit in the remaining address space */
3106 if (likely(addr > len)) {
3107 vma = find_vma(mm, addr - len);
3108 - if (!vma || addr <= vma->vm_start) {
3109 + if (check_heap_stack_gap(vmm, addr - len, len))
3110 /* cache the address as a hint for next time */
3111 return mm->free_area_cache = addr - len;
3112 }
3113 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3114 * return with success:
3115 */
3116 vma = find_vma(mm, addr);
3117 - if (likely(!vma || addr + len <= vma->vm_start)) {
3118 + if (check_heap_stack_gap(vmm, addr, len)) {
3119 /* cache the address as a hint for next time */
3120 return mm->free_area_cache = addr;
3121 }
3122 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3123 mm->unmap_area = arch_unmap_area_topdown;
3124 }
3125 }
3126 -
3127 -static inline unsigned long brk_rnd(void)
3128 -{
3129 - unsigned long rnd = get_random_int();
3130 -
3131 - rnd = rnd << PAGE_SHIFT;
3132 - /* 8MB for 32bit, 256MB for 64bit */
3133 - if (TASK_IS_32BIT_ADDR)
3134 - rnd = rnd & 0x7ffffful;
3135 - else
3136 - rnd = rnd & 0xffffffful;
3137 -
3138 - return rnd;
3139 -}
3140 -
3141 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3142 -{
3143 - unsigned long base = mm->brk;
3144 - unsigned long ret;
3145 -
3146 - ret = PAGE_ALIGN(base + brk_rnd());
3147 -
3148 - if (ret < mm->brk)
3149 - return mm->brk;
3150 -
3151 - return ret;
3152 -}
3153 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3154 index 967d144..db12197 100644
3155 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3156 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3157 @@ -11,12 +11,14 @@
3158 #ifndef _ASM_PROC_CACHE_H
3159 #define _ASM_PROC_CACHE_H
3160
3161 +#include <linux/const.h>
3162 +
3163 /* L1 cache */
3164
3165 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3166 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3167 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3168 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3169 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3170 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3171
3172 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3173 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3174 index bcb5df2..84fabd2 100644
3175 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3176 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3177 @@ -16,13 +16,15 @@
3178 #ifndef _ASM_PROC_CACHE_H
3179 #define _ASM_PROC_CACHE_H
3180
3181 +#include <linux/const.h>
3182 +
3183 /*
3184 * L1 cache
3185 */
3186 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3187 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3188 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3189 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3190 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3191 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3192
3193 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3194 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3195 index 4ce7a01..449202a 100644
3196 --- a/arch/openrisc/include/asm/cache.h
3197 +++ b/arch/openrisc/include/asm/cache.h
3198 @@ -19,11 +19,13 @@
3199 #ifndef __ASM_OPENRISC_CACHE_H
3200 #define __ASM_OPENRISC_CACHE_H
3201
3202 +#include <linux/const.h>
3203 +
3204 /* FIXME: How can we replace these with values from the CPU...
3205 * they shouldn't be hard-coded!
3206 */
3207
3208 -#define L1_CACHE_BYTES 16
3209 #define L1_CACHE_SHIFT 4
3210 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3211
3212 #endif /* __ASM_OPENRISC_CACHE_H */
3213 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3214 index af9cf30..2aae9b2 100644
3215 --- a/arch/parisc/include/asm/atomic.h
3216 +++ b/arch/parisc/include/asm/atomic.h
3217 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3218
3219 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3220
3221 +#define atomic64_read_unchecked(v) atomic64_read(v)
3222 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3223 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3224 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3225 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3226 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3227 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3228 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3229 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3230 +
3231 #endif /* !CONFIG_64BIT */
3232
3233
3234 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3235 index 47f11c7..3420df2 100644
3236 --- a/arch/parisc/include/asm/cache.h
3237 +++ b/arch/parisc/include/asm/cache.h
3238 @@ -5,6 +5,7 @@
3239 #ifndef __ARCH_PARISC_CACHE_H
3240 #define __ARCH_PARISC_CACHE_H
3241
3242 +#include <linux/const.h>
3243
3244 /*
3245 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3246 @@ -15,13 +16,13 @@
3247 * just ruin performance.
3248 */
3249 #ifdef CONFIG_PA20
3250 -#define L1_CACHE_BYTES 64
3251 #define L1_CACHE_SHIFT 6
3252 #else
3253 -#define L1_CACHE_BYTES 32
3254 #define L1_CACHE_SHIFT 5
3255 #endif
3256
3257 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3258 +
3259 #ifndef __ASSEMBLY__
3260
3261 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3262 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3263 index 19f6cb1..6c78cf2 100644
3264 --- a/arch/parisc/include/asm/elf.h
3265 +++ b/arch/parisc/include/asm/elf.h
3266 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3267
3268 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3269
3270 +#ifdef CONFIG_PAX_ASLR
3271 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3272 +
3273 +#define PAX_DELTA_MMAP_LEN 16
3274 +#define PAX_DELTA_STACK_LEN 16
3275 +#endif
3276 +
3277 /* This yields a mask that user programs can use to figure out what
3278 instruction set this CPU supports. This could be done in user space,
3279 but it's not easy, and we've already done it here. */
3280 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3281 index fc987a1..6e068ef 100644
3282 --- a/arch/parisc/include/asm/pgalloc.h
3283 +++ b/arch/parisc/include/asm/pgalloc.h
3284 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3285 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3286 }
3287
3288 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3289 +{
3290 + pgd_populate(mm, pgd, pmd);
3291 +}
3292 +
3293 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3294 {
3295 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3296 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3297 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3298 #define pmd_free(mm, x) do { } while (0)
3299 #define pgd_populate(mm, pmd, pte) BUG()
3300 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3301
3302 #endif
3303
3304 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3305 index ee99f23..802b0a1 100644
3306 --- a/arch/parisc/include/asm/pgtable.h
3307 +++ b/arch/parisc/include/asm/pgtable.h
3308 @@ -212,6 +212,17 @@ struct vm_area_struct;
3309 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3310 #define PAGE_COPY PAGE_EXECREAD
3311 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3312 +
3313 +#ifdef CONFIG_PAX_PAGEEXEC
3314 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3315 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3316 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3317 +#else
3318 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3319 +# define PAGE_COPY_NOEXEC PAGE_COPY
3320 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3321 +#endif
3322 +
3323 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3324 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3325 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3326 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3327 index 4ba2c93..f5e3974 100644
3328 --- a/arch/parisc/include/asm/uaccess.h
3329 +++ b/arch/parisc/include/asm/uaccess.h
3330 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3331 const void __user *from,
3332 unsigned long n)
3333 {
3334 - int sz = __compiletime_object_size(to);
3335 + size_t sz = __compiletime_object_size(to);
3336 int ret = -EFAULT;
3337
3338 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3339 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3340 ret = __copy_from_user(to, from, n);
3341 else
3342 copy_from_user_overflow();
3343 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3344 index 5e34ccf..672bc9c 100644
3345 --- a/arch/parisc/kernel/module.c
3346 +++ b/arch/parisc/kernel/module.c
3347 @@ -98,16 +98,38 @@
3348
3349 /* three functions to determine where in the module core
3350 * or init pieces the location is */
3351 +static inline int in_init_rx(struct module *me, void *loc)
3352 +{
3353 + return (loc >= me->module_init_rx &&
3354 + loc < (me->module_init_rx + me->init_size_rx));
3355 +}
3356 +
3357 +static inline int in_init_rw(struct module *me, void *loc)
3358 +{
3359 + return (loc >= me->module_init_rw &&
3360 + loc < (me->module_init_rw + me->init_size_rw));
3361 +}
3362 +
3363 static inline int in_init(struct module *me, void *loc)
3364 {
3365 - return (loc >= me->module_init &&
3366 - loc <= (me->module_init + me->init_size));
3367 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3368 +}
3369 +
3370 +static inline int in_core_rx(struct module *me, void *loc)
3371 +{
3372 + return (loc >= me->module_core_rx &&
3373 + loc < (me->module_core_rx + me->core_size_rx));
3374 +}
3375 +
3376 +static inline int in_core_rw(struct module *me, void *loc)
3377 +{
3378 + return (loc >= me->module_core_rw &&
3379 + loc < (me->module_core_rw + me->core_size_rw));
3380 }
3381
3382 static inline int in_core(struct module *me, void *loc)
3383 {
3384 - return (loc >= me->module_core &&
3385 - loc <= (me->module_core + me->core_size));
3386 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3387 }
3388
3389 static inline int in_local(struct module *me, void *loc)
3390 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3391 }
3392
3393 /* align things a bit */
3394 - me->core_size = ALIGN(me->core_size, 16);
3395 - me->arch.got_offset = me->core_size;
3396 - me->core_size += gots * sizeof(struct got_entry);
3397 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3398 + me->arch.got_offset = me->core_size_rw;
3399 + me->core_size_rw += gots * sizeof(struct got_entry);
3400
3401 - me->core_size = ALIGN(me->core_size, 16);
3402 - me->arch.fdesc_offset = me->core_size;
3403 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3404 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3405 + me->arch.fdesc_offset = me->core_size_rw;
3406 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3407
3408 me->arch.got_max = gots;
3409 me->arch.fdesc_max = fdescs;
3410 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3411
3412 BUG_ON(value == 0);
3413
3414 - got = me->module_core + me->arch.got_offset;
3415 + got = me->module_core_rw + me->arch.got_offset;
3416 for (i = 0; got[i].addr; i++)
3417 if (got[i].addr == value)
3418 goto out;
3419 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3420 #ifdef CONFIG_64BIT
3421 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3422 {
3423 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3424 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3425
3426 if (!value) {
3427 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3428 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3429
3430 /* Create new one */
3431 fdesc->addr = value;
3432 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3433 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3434 return (Elf_Addr)fdesc;
3435 }
3436 #endif /* CONFIG_64BIT */
3437 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3438
3439 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3440 end = table + sechdrs[me->arch.unwind_section].sh_size;
3441 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3442 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3443
3444 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3445 me->arch.unwind_section, table, end, gp);
3446 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3447 index f76c108..8117482 100644
3448 --- a/arch/parisc/kernel/sys_parisc.c
3449 +++ b/arch/parisc/kernel/sys_parisc.c
3450 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3451 /* At this point: (!vma || addr < vma->vm_end). */
3452 if (TASK_SIZE - len < addr)
3453 return -ENOMEM;
3454 - if (!vma || addr + len <= vma->vm_start)
3455 + if (check_heap_stack_gap(vma, addr, len))
3456 return addr;
3457 addr = vma->vm_end;
3458 }
3459 @@ -81,7 +81,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3460 /* At this point: (!vma || addr < vma->vm_end). */
3461 if (TASK_SIZE - len < addr)
3462 return -ENOMEM;
3463 - if (!vma || addr + len <= vma->vm_start)
3464 + if (check_heap_stack_gap(vma, addr, len))
3465 return addr;
3466 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3467 if (addr < vma->vm_end) /* handle wraparound */
3468 @@ -100,7 +100,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3469 if (flags & MAP_FIXED)
3470 return addr;
3471 if (!addr)
3472 - addr = TASK_UNMAPPED_BASE;
3473 + addr = current->mm->mmap_base;
3474
3475 if (filp) {
3476 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3477 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3478 index 45ba99f..8e22c33 100644
3479 --- a/arch/parisc/kernel/traps.c
3480 +++ b/arch/parisc/kernel/traps.c
3481 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3482
3483 down_read(&current->mm->mmap_sem);
3484 vma = find_vma(current->mm,regs->iaoq[0]);
3485 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3486 - && (vma->vm_flags & VM_EXEC)) {
3487 -
3488 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3489 fault_address = regs->iaoq[0];
3490 fault_space = regs->iasq[0];
3491
3492 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3493 index 18162ce..94de376 100644
3494 --- a/arch/parisc/mm/fault.c
3495 +++ b/arch/parisc/mm/fault.c
3496 @@ -15,6 +15,7 @@
3497 #include <linux/sched.h>
3498 #include <linux/interrupt.h>
3499 #include <linux/module.h>
3500 +#include <linux/unistd.h>
3501
3502 #include <asm/uaccess.h>
3503 #include <asm/traps.h>
3504 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3505 static unsigned long
3506 parisc_acctyp(unsigned long code, unsigned int inst)
3507 {
3508 - if (code == 6 || code == 16)
3509 + if (code == 6 || code == 7 || code == 16)
3510 return VM_EXEC;
3511
3512 switch (inst & 0xf0000000) {
3513 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3514 }
3515 #endif
3516
3517 +#ifdef CONFIG_PAX_PAGEEXEC
3518 +/*
3519 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3520 + *
3521 + * returns 1 when task should be killed
3522 + * 2 when rt_sigreturn trampoline was detected
3523 + * 3 when unpatched PLT trampoline was detected
3524 + */
3525 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3526 +{
3527 +
3528 +#ifdef CONFIG_PAX_EMUPLT
3529 + int err;
3530 +
3531 + do { /* PaX: unpatched PLT emulation */
3532 + unsigned int bl, depwi;
3533 +
3534 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3535 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3536 +
3537 + if (err)
3538 + break;
3539 +
3540 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3541 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3542 +
3543 + err = get_user(ldw, (unsigned int *)addr);
3544 + err |= get_user(bv, (unsigned int *)(addr+4));
3545 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3546 +
3547 + if (err)
3548 + break;
3549 +
3550 + if (ldw == 0x0E801096U &&
3551 + bv == 0xEAC0C000U &&
3552 + ldw2 == 0x0E881095U)
3553 + {
3554 + unsigned int resolver, map;
3555 +
3556 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3557 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3558 + if (err)
3559 + break;
3560 +
3561 + regs->gr[20] = instruction_pointer(regs)+8;
3562 + regs->gr[21] = map;
3563 + regs->gr[22] = resolver;
3564 + regs->iaoq[0] = resolver | 3UL;
3565 + regs->iaoq[1] = regs->iaoq[0] + 4;
3566 + return 3;
3567 + }
3568 + }
3569 + } while (0);
3570 +#endif
3571 +
3572 +#ifdef CONFIG_PAX_EMUTRAMP
3573 +
3574 +#ifndef CONFIG_PAX_EMUSIGRT
3575 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3576 + return 1;
3577 +#endif
3578 +
3579 + do { /* PaX: rt_sigreturn emulation */
3580 + unsigned int ldi1, ldi2, bel, nop;
3581 +
3582 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3583 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3584 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3585 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3586 +
3587 + if (err)
3588 + break;
3589 +
3590 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3591 + ldi2 == 0x3414015AU &&
3592 + bel == 0xE4008200U &&
3593 + nop == 0x08000240U)
3594 + {
3595 + regs->gr[25] = (ldi1 & 2) >> 1;
3596 + regs->gr[20] = __NR_rt_sigreturn;
3597 + regs->gr[31] = regs->iaoq[1] + 16;
3598 + regs->sr[0] = regs->iasq[1];
3599 + regs->iaoq[0] = 0x100UL;
3600 + regs->iaoq[1] = regs->iaoq[0] + 4;
3601 + regs->iasq[0] = regs->sr[2];
3602 + regs->iasq[1] = regs->sr[2];
3603 + return 2;
3604 + }
3605 + } while (0);
3606 +#endif
3607 +
3608 + return 1;
3609 +}
3610 +
3611 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3612 +{
3613 + unsigned long i;
3614 +
3615 + printk(KERN_ERR "PAX: bytes at PC: ");
3616 + for (i = 0; i < 5; i++) {
3617 + unsigned int c;
3618 + if (get_user(c, (unsigned int *)pc+i))
3619 + printk(KERN_CONT "???????? ");
3620 + else
3621 + printk(KERN_CONT "%08x ", c);
3622 + }
3623 + printk("\n");
3624 +}
3625 +#endif
3626 +
3627 int fixup_exception(struct pt_regs *regs)
3628 {
3629 const struct exception_table_entry *fix;
3630 @@ -192,8 +303,33 @@ good_area:
3631
3632 acc_type = parisc_acctyp(code,regs->iir);
3633
3634 - if ((vma->vm_flags & acc_type) != acc_type)
3635 + if ((vma->vm_flags & acc_type) != acc_type) {
3636 +
3637 +#ifdef CONFIG_PAX_PAGEEXEC
3638 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3639 + (address & ~3UL) == instruction_pointer(regs))
3640 + {
3641 + up_read(&mm->mmap_sem);
3642 + switch (pax_handle_fetch_fault(regs)) {
3643 +
3644 +#ifdef CONFIG_PAX_EMUPLT
3645 + case 3:
3646 + return;
3647 +#endif
3648 +
3649 +#ifdef CONFIG_PAX_EMUTRAMP
3650 + case 2:
3651 + return;
3652 +#endif
3653 +
3654 + }
3655 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3656 + do_group_exit(SIGKILL);
3657 + }
3658 +#endif
3659 +
3660 goto bad_area;
3661 + }
3662
3663 /*
3664 * If for any reason at all we couldn't handle the fault, make
3665 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3666 index e3b1d41..8e81edf 100644
3667 --- a/arch/powerpc/include/asm/atomic.h
3668 +++ b/arch/powerpc/include/asm/atomic.h
3669 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3670 return t1;
3671 }
3672
3673 +#define atomic64_read_unchecked(v) atomic64_read(v)
3674 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3675 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3676 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3677 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3678 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3679 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3680 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3681 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3682 +
3683 #endif /* __powerpc64__ */
3684
3685 #endif /* __KERNEL__ */
3686 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3687 index 9e495c9..b6878e5 100644
3688 --- a/arch/powerpc/include/asm/cache.h
3689 +++ b/arch/powerpc/include/asm/cache.h
3690 @@ -3,6 +3,7 @@
3691
3692 #ifdef __KERNEL__
3693
3694 +#include <linux/const.h>
3695
3696 /* bytes per L1 cache line */
3697 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3698 @@ -22,7 +23,7 @@
3699 #define L1_CACHE_SHIFT 7
3700 #endif
3701
3702 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3703 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3704
3705 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3706
3707 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3708 index 6abf0a1..459d0f1 100644
3709 --- a/arch/powerpc/include/asm/elf.h
3710 +++ b/arch/powerpc/include/asm/elf.h
3711 @@ -28,8 +28,19 @@
3712 the loader. We need to make sure that it is out of the way of the program
3713 that it will "exec", and that there is sufficient room for the brk. */
3714
3715 -extern unsigned long randomize_et_dyn(unsigned long base);
3716 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3717 +#define ELF_ET_DYN_BASE (0x20000000)
3718 +
3719 +#ifdef CONFIG_PAX_ASLR
3720 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3721 +
3722 +#ifdef __powerpc64__
3723 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3724 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3725 +#else
3726 +#define PAX_DELTA_MMAP_LEN 15
3727 +#define PAX_DELTA_STACK_LEN 15
3728 +#endif
3729 +#endif
3730
3731 /*
3732 * Our registers are always unsigned longs, whether we're a 32 bit
3733 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3734 (0x7ff >> (PAGE_SHIFT - 12)) : \
3735 (0x3ffff >> (PAGE_SHIFT - 12)))
3736
3737 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3738 -#define arch_randomize_brk arch_randomize_brk
3739 -
3740 -
3741 #ifdef CONFIG_SPU_BASE
3742 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
3743 #define NT_SPU 1
3744 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3745 index 8196e9c..d83a9f3 100644
3746 --- a/arch/powerpc/include/asm/exec.h
3747 +++ b/arch/powerpc/include/asm/exec.h
3748 @@ -4,6 +4,6 @@
3749 #ifndef _ASM_POWERPC_EXEC_H
3750 #define _ASM_POWERPC_EXEC_H
3751
3752 -extern unsigned long arch_align_stack(unsigned long sp);
3753 +#define arch_align_stack(x) ((x) & ~0xfUL)
3754
3755 #endif /* _ASM_POWERPC_EXEC_H */
3756 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3757 index 5acabbd..7ea14fa 100644
3758 --- a/arch/powerpc/include/asm/kmap_types.h
3759 +++ b/arch/powerpc/include/asm/kmap_types.h
3760 @@ -10,7 +10,7 @@
3761 * 2 of the License, or (at your option) any later version.
3762 */
3763
3764 -#define KM_TYPE_NR 16
3765 +#define KM_TYPE_NR 17
3766
3767 #endif /* __KERNEL__ */
3768 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3769 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3770 index 8565c25..2865190 100644
3771 --- a/arch/powerpc/include/asm/mman.h
3772 +++ b/arch/powerpc/include/asm/mman.h
3773 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3774 }
3775 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3776
3777 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3778 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3779 {
3780 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3781 }
3782 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3783 index f072e97..b436dee 100644
3784 --- a/arch/powerpc/include/asm/page.h
3785 +++ b/arch/powerpc/include/asm/page.h
3786 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3787 * and needs to be executable. This means the whole heap ends
3788 * up being executable.
3789 */
3790 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3791 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3792 +#define VM_DATA_DEFAULT_FLAGS32 \
3793 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3794 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3795
3796 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3797 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3798 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3799 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3800 #endif
3801
3802 +#define ktla_ktva(addr) (addr)
3803 +#define ktva_ktla(addr) (addr)
3804 +
3805 /*
3806 * Use the top bit of the higher-level page table entries to indicate whether
3807 * the entries we point to contain hugepages. This works because we know that
3808 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3809 index cd915d6..c10cee8 100644
3810 --- a/arch/powerpc/include/asm/page_64.h
3811 +++ b/arch/powerpc/include/asm/page_64.h
3812 @@ -154,15 +154,18 @@ do { \
3813 * stack by default, so in the absence of a PT_GNU_STACK program header
3814 * we turn execute permission off.
3815 */
3816 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818 +#define VM_STACK_DEFAULT_FLAGS32 \
3819 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824
3825 +#ifndef CONFIG_PAX_PAGEEXEC
3826 #define VM_STACK_DEFAULT_FLAGS \
3827 (is_32bit_task() ? \
3828 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3829 +#endif
3830
3831 #include <asm-generic/getorder.h>
3832
3833 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3834 index 292725c..f87ae14 100644
3835 --- a/arch/powerpc/include/asm/pgalloc-64.h
3836 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3837 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3838 #ifndef CONFIG_PPC_64K_PAGES
3839
3840 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3841 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3842
3843 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3844 {
3845 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3846 pud_set(pud, (unsigned long)pmd);
3847 }
3848
3849 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3850 +{
3851 + pud_populate(mm, pud, pmd);
3852 +}
3853 +
3854 #define pmd_populate(mm, pmd, pte_page) \
3855 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3856 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3857 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3858 #else /* CONFIG_PPC_64K_PAGES */
3859
3860 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3861 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3862
3863 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3864 pte_t *pte)
3865 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3866 index a9cbd3b..3b67efa 100644
3867 --- a/arch/powerpc/include/asm/pgtable.h
3868 +++ b/arch/powerpc/include/asm/pgtable.h
3869 @@ -2,6 +2,7 @@
3870 #define _ASM_POWERPC_PGTABLE_H
3871 #ifdef __KERNEL__
3872
3873 +#include <linux/const.h>
3874 #ifndef __ASSEMBLY__
3875 #include <asm/processor.h> /* For TASK_SIZE */
3876 #include <asm/mmu.h>
3877 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3878 index 4aad413..85d86bf 100644
3879 --- a/arch/powerpc/include/asm/pte-hash32.h
3880 +++ b/arch/powerpc/include/asm/pte-hash32.h
3881 @@ -21,6 +21,7 @@
3882 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3883 #define _PAGE_USER 0x004 /* usermode access allowed */
3884 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3885 +#define _PAGE_EXEC _PAGE_GUARDED
3886 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3887 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3888 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3889 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3890 index d24c141..b60696e 100644
3891 --- a/arch/powerpc/include/asm/reg.h
3892 +++ b/arch/powerpc/include/asm/reg.h
3893 @@ -215,6 +215,7 @@
3894 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3895 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3896 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3897 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3898 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3899 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3900 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3901 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3902 index 406b7b9..af63426 100644
3903 --- a/arch/powerpc/include/asm/thread_info.h
3904 +++ b/arch/powerpc/include/asm/thread_info.h
3905 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
3906 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3907 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3908 #define TIF_SINGLESTEP 8 /* singlestepping active */
3909 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3910 #define TIF_SECCOMP 10 /* secure computing */
3911 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3912 #define TIF_NOERROR 12 /* Force successful syscall return */
3913 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
3914 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3915 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
3916 for stack store? */
3917 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
3918 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3919 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3920
3921 /* as above, but as bit values */
3922 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3923 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
3924 #define _TIF_UPROBE (1<<TIF_UPROBE)
3925 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3926 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
3927 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3928 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3929 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3930 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3931 + _TIF_GRSEC_SETXID)
3932
3933 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3934 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
3935 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3936 index 4db4959..335e00c 100644
3937 --- a/arch/powerpc/include/asm/uaccess.h
3938 +++ b/arch/powerpc/include/asm/uaccess.h
3939 @@ -13,6 +13,8 @@
3940 #define VERIFY_READ 0
3941 #define VERIFY_WRITE 1
3942
3943 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3944 +
3945 /*
3946 * The fs value determines whether argument validity checking should be
3947 * performed or not. If get_fs() == USER_DS, checking is performed, with
3948 @@ -318,52 +320,6 @@ do { \
3949 extern unsigned long __copy_tofrom_user(void __user *to,
3950 const void __user *from, unsigned long size);
3951
3952 -#ifndef __powerpc64__
3953 -
3954 -static inline unsigned long copy_from_user(void *to,
3955 - const void __user *from, unsigned long n)
3956 -{
3957 - unsigned long over;
3958 -
3959 - if (access_ok(VERIFY_READ, from, n))
3960 - return __copy_tofrom_user((__force void __user *)to, from, n);
3961 - if ((unsigned long)from < TASK_SIZE) {
3962 - over = (unsigned long)from + n - TASK_SIZE;
3963 - return __copy_tofrom_user((__force void __user *)to, from,
3964 - n - over) + over;
3965 - }
3966 - return n;
3967 -}
3968 -
3969 -static inline unsigned long copy_to_user(void __user *to,
3970 - const void *from, unsigned long n)
3971 -{
3972 - unsigned long over;
3973 -
3974 - if (access_ok(VERIFY_WRITE, to, n))
3975 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3976 - if ((unsigned long)to < TASK_SIZE) {
3977 - over = (unsigned long)to + n - TASK_SIZE;
3978 - return __copy_tofrom_user(to, (__force void __user *)from,
3979 - n - over) + over;
3980 - }
3981 - return n;
3982 -}
3983 -
3984 -#else /* __powerpc64__ */
3985 -
3986 -#define __copy_in_user(to, from, size) \
3987 - __copy_tofrom_user((to), (from), (size))
3988 -
3989 -extern unsigned long copy_from_user(void *to, const void __user *from,
3990 - unsigned long n);
3991 -extern unsigned long copy_to_user(void __user *to, const void *from,
3992 - unsigned long n);
3993 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3994 - unsigned long n);
3995 -
3996 -#endif /* __powerpc64__ */
3997 -
3998 static inline unsigned long __copy_from_user_inatomic(void *to,
3999 const void __user *from, unsigned long n)
4000 {
4001 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4002 if (ret == 0)
4003 return 0;
4004 }
4005 +
4006 + if (!__builtin_constant_p(n))
4007 + check_object_size(to, n, false);
4008 +
4009 return __copy_tofrom_user((__force void __user *)to, from, n);
4010 }
4011
4012 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4013 if (ret == 0)
4014 return 0;
4015 }
4016 +
4017 + if (!__builtin_constant_p(n))
4018 + check_object_size(from, n, true);
4019 +
4020 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4021 }
4022
4023 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4024 return __copy_to_user_inatomic(to, from, size);
4025 }
4026
4027 +#ifndef __powerpc64__
4028 +
4029 +static inline unsigned long __must_check copy_from_user(void *to,
4030 + const void __user *from, unsigned long n)
4031 +{
4032 + unsigned long over;
4033 +
4034 + if ((long)n < 0)
4035 + return n;
4036 +
4037 + if (access_ok(VERIFY_READ, from, n)) {
4038 + if (!__builtin_constant_p(n))
4039 + check_object_size(to, n, false);
4040 + return __copy_tofrom_user((__force void __user *)to, from, n);
4041 + }
4042 + if ((unsigned long)from < TASK_SIZE) {
4043 + over = (unsigned long)from + n - TASK_SIZE;
4044 + if (!__builtin_constant_p(n - over))
4045 + check_object_size(to, n - over, false);
4046 + return __copy_tofrom_user((__force void __user *)to, from,
4047 + n - over) + over;
4048 + }
4049 + return n;
4050 +}
4051 +
4052 +static inline unsigned long __must_check copy_to_user(void __user *to,
4053 + const void *from, unsigned long n)
4054 +{
4055 + unsigned long over;
4056 +
4057 + if ((long)n < 0)
4058 + return n;
4059 +
4060 + if (access_ok(VERIFY_WRITE, to, n)) {
4061 + if (!__builtin_constant_p(n))
4062 + check_object_size(from, n, true);
4063 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4064 + }
4065 + if ((unsigned long)to < TASK_SIZE) {
4066 + over = (unsigned long)to + n - TASK_SIZE;
4067 + if (!__builtin_constant_p(n))
4068 + check_object_size(from, n - over, true);
4069 + return __copy_tofrom_user(to, (__force void __user *)from,
4070 + n - over) + over;
4071 + }
4072 + return n;
4073 +}
4074 +
4075 +#else /* __powerpc64__ */
4076 +
4077 +#define __copy_in_user(to, from, size) \
4078 + __copy_tofrom_user((to), (from), (size))
4079 +
4080 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4081 +{
4082 + if ((long)n < 0 || n > INT_MAX)
4083 + return n;
4084 +
4085 + if (!__builtin_constant_p(n))
4086 + check_object_size(to, n, false);
4087 +
4088 + if (likely(access_ok(VERIFY_READ, from, n)))
4089 + n = __copy_from_user(to, from, n);
4090 + else
4091 + memset(to, 0, n);
4092 + return n;
4093 +}
4094 +
4095 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4096 +{
4097 + if ((long)n < 0 || n > INT_MAX)
4098 + return n;
4099 +
4100 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4101 + if (!__builtin_constant_p(n))
4102 + check_object_size(from, n, true);
4103 + n = __copy_to_user(to, from, n);
4104 + }
4105 + return n;
4106 +}
4107 +
4108 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4109 + unsigned long n);
4110 +
4111 +#endif /* __powerpc64__ */
4112 +
4113 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4114
4115 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4116 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4117 index 4684e33..acc4d19e 100644
4118 --- a/arch/powerpc/kernel/exceptions-64e.S
4119 +++ b/arch/powerpc/kernel/exceptions-64e.S
4120 @@ -715,6 +715,7 @@ storage_fault_common:
4121 std r14,_DAR(r1)
4122 std r15,_DSISR(r1)
4123 addi r3,r1,STACK_FRAME_OVERHEAD
4124 + bl .save_nvgprs
4125 mr r4,r14
4126 mr r5,r15
4127 ld r14,PACA_EXGEN+EX_R14(r13)
4128 @@ -723,8 +724,7 @@ storage_fault_common:
4129 cmpdi r3,0
4130 bne- 1f
4131 b .ret_from_except_lite
4132 -1: bl .save_nvgprs
4133 - mr r5,r3
4134 +1: mr r5,r3
4135 addi r3,r1,STACK_FRAME_OVERHEAD
4136 ld r4,_DAR(r1)
4137 bl .bad_page_fault
4138 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4139 index 10b658a..e542888 100644
4140 --- a/arch/powerpc/kernel/exceptions-64s.S
4141 +++ b/arch/powerpc/kernel/exceptions-64s.S
4142 @@ -1013,10 +1013,10 @@ handle_page_fault:
4143 11: ld r4,_DAR(r1)
4144 ld r5,_DSISR(r1)
4145 addi r3,r1,STACK_FRAME_OVERHEAD
4146 + bl .save_nvgprs
4147 bl .do_page_fault
4148 cmpdi r3,0
4149 beq+ 12f
4150 - bl .save_nvgprs
4151 mr r5,r3
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 lwz r4,_DAR(r1)
4154 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4155 index 2e3200c..72095ce 100644
4156 --- a/arch/powerpc/kernel/module_32.c
4157 +++ b/arch/powerpc/kernel/module_32.c
4158 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4159 me->arch.core_plt_section = i;
4160 }
4161 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4162 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4163 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4164 return -ENOEXEC;
4165 }
4166
4167 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4168
4169 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4170 /* Init, or core PLT? */
4171 - if (location >= mod->module_core
4172 - && location < mod->module_core + mod->core_size)
4173 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4174 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4175 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4176 - else
4177 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4178 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4179 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4180 + else {
4181 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4182 + return ~0UL;
4183 + }
4184
4185 /* Find this entry, or if that fails, the next avail. entry */
4186 while (entry->jump[0]) {
4187 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4188 index ba48233..16ac31d 100644
4189 --- a/arch/powerpc/kernel/process.c
4190 +++ b/arch/powerpc/kernel/process.c
4191 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
4192 * Lookup NIP late so we have the best change of getting the
4193 * above info out without failing
4194 */
4195 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4196 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4197 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4198 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4199 #endif
4200 show_stack(current, (unsigned long *) regs->gpr[1]);
4201 if (!user_mode(regs))
4202 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4203 newsp = stack[0];
4204 ip = stack[STACK_FRAME_LR_SAVE];
4205 if (!firstframe || ip != lr) {
4206 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4207 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4208 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4209 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4210 - printk(" (%pS)",
4211 + printk(" (%pA)",
4212 (void *)current->ret_stack[curr_frame].ret);
4213 curr_frame--;
4214 }
4215 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4216 struct pt_regs *regs = (struct pt_regs *)
4217 (sp + STACK_FRAME_OVERHEAD);
4218 lr = regs->link;
4219 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4220 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4221 regs->trap, (void *)regs->nip, (void *)lr);
4222 firstframe = 1;
4223 }
4224 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
4225 mtspr(SPRN_CTRLT, ctrl);
4226 }
4227 #endif /* CONFIG_PPC64 */
4228 -
4229 -unsigned long arch_align_stack(unsigned long sp)
4230 -{
4231 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4232 - sp -= get_random_int() & ~PAGE_MASK;
4233 - return sp & ~0xf;
4234 -}
4235 -
4236 -static inline unsigned long brk_rnd(void)
4237 -{
4238 - unsigned long rnd = 0;
4239 -
4240 - /* 8MB for 32bit, 1GB for 64bit */
4241 - if (is_32bit_task())
4242 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4243 - else
4244 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4245 -
4246 - return rnd << PAGE_SHIFT;
4247 -}
4248 -
4249 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4250 -{
4251 - unsigned long base = mm->brk;
4252 - unsigned long ret;
4253 -
4254 -#ifdef CONFIG_PPC_STD_MMU_64
4255 - /*
4256 - * If we are using 1TB segments and we are allowed to randomise
4257 - * the heap, we can put it above 1TB so it is backed by a 1TB
4258 - * segment. Otherwise the heap will be in the bottom 1TB
4259 - * which always uses 256MB segments and this may result in a
4260 - * performance penalty.
4261 - */
4262 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4263 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4264 -#endif
4265 -
4266 - ret = PAGE_ALIGN(base + brk_rnd());
4267 -
4268 - if (ret < mm->brk)
4269 - return mm->brk;
4270 -
4271 - return ret;
4272 -}
4273 -
4274 -unsigned long randomize_et_dyn(unsigned long base)
4275 -{
4276 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4277 -
4278 - if (ret < base)
4279 - return base;
4280 -
4281 - return ret;
4282 -}
4283 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4284 index 79d8e56..38ffcbb 100644
4285 --- a/arch/powerpc/kernel/ptrace.c
4286 +++ b/arch/powerpc/kernel/ptrace.c
4287 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
4288 return ret;
4289 }
4290
4291 +#ifdef CONFIG_GRKERNSEC_SETXID
4292 +extern void gr_delayed_cred_worker(void);
4293 +#endif
4294 +
4295 /*
4296 * We must return the syscall number to actually look up in the table.
4297 * This can be -1L to skip running any syscall at all.
4298 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4299
4300 secure_computing_strict(regs->gpr[0]);
4301
4302 +#ifdef CONFIG_GRKERNSEC_SETXID
4303 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4304 + gr_delayed_cred_worker();
4305 +#endif
4306 +
4307 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4308 tracehook_report_syscall_entry(regs))
4309 /*
4310 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4311 {
4312 int step;
4313
4314 +#ifdef CONFIG_GRKERNSEC_SETXID
4315 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4316 + gr_delayed_cred_worker();
4317 +#endif
4318 +
4319 audit_syscall_exit(regs);
4320
4321 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4322 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4323 index 804e323..79181c1 100644
4324 --- a/arch/powerpc/kernel/signal_32.c
4325 +++ b/arch/powerpc/kernel/signal_32.c
4326 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4327 /* Save user registers on the stack */
4328 frame = &rt_sf->uc.uc_mcontext;
4329 addr = frame;
4330 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4331 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4332 if (save_user_regs(regs, frame, 0, 1))
4333 goto badframe;
4334 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4335 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4336 index d183f87..1867f1a 100644
4337 --- a/arch/powerpc/kernel/signal_64.c
4338 +++ b/arch/powerpc/kernel/signal_64.c
4339 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4340 current->thread.fpscr.val = 0;
4341
4342 /* Set up to return from userspace. */
4343 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4344 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4345 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4346 } else {
4347 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4348 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4349 index 3251840..3f7c77a 100644
4350 --- a/arch/powerpc/kernel/traps.c
4351 +++ b/arch/powerpc/kernel/traps.c
4352 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4353 return flags;
4354 }
4355
4356 +extern void gr_handle_kernel_exploit(void);
4357 +
4358 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4359 int signr)
4360 {
4361 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4362 panic("Fatal exception in interrupt");
4363 if (panic_on_oops)
4364 panic("Fatal exception");
4365 +
4366 + gr_handle_kernel_exploit();
4367 +
4368 do_exit(signr);
4369 }
4370
4371 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4372 index 1b2076f..835e4be 100644
4373 --- a/arch/powerpc/kernel/vdso.c
4374 +++ b/arch/powerpc/kernel/vdso.c
4375 @@ -34,6 +34,7 @@
4376 #include <asm/firmware.h>
4377 #include <asm/vdso.h>
4378 #include <asm/vdso_datapage.h>
4379 +#include <asm/mman.h>
4380
4381 #include "setup.h"
4382
4383 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4384 vdso_base = VDSO32_MBASE;
4385 #endif
4386
4387 - current->mm->context.vdso_base = 0;
4388 + current->mm->context.vdso_base = ~0UL;
4389
4390 /* vDSO has a problem and was disabled, just don't "enable" it for the
4391 * process
4392 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4393 vdso_base = get_unmapped_area(NULL, vdso_base,
4394 (vdso_pages << PAGE_SHIFT) +
4395 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4396 - 0, 0);
4397 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4398 if (IS_ERR_VALUE(vdso_base)) {
4399 rc = vdso_base;
4400 goto fail_mmapsem;
4401 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4402 index 5eea6f3..5d10396 100644
4403 --- a/arch/powerpc/lib/usercopy_64.c
4404 +++ b/arch/powerpc/lib/usercopy_64.c
4405 @@ -9,22 +9,6 @@
4406 #include <linux/module.h>
4407 #include <asm/uaccess.h>
4408
4409 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4410 -{
4411 - if (likely(access_ok(VERIFY_READ, from, n)))
4412 - n = __copy_from_user(to, from, n);
4413 - else
4414 - memset(to, 0, n);
4415 - return n;
4416 -}
4417 -
4418 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4419 -{
4420 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4421 - n = __copy_to_user(to, from, n);
4422 - return n;
4423 -}
4424 -
4425 unsigned long copy_in_user(void __user *to, const void __user *from,
4426 unsigned long n)
4427 {
4428 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4429 return n;
4430 }
4431
4432 -EXPORT_SYMBOL(copy_from_user);
4433 -EXPORT_SYMBOL(copy_to_user);
4434 EXPORT_SYMBOL(copy_in_user);
4435
4436 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4437 index 0a6b283..7674925 100644
4438 --- a/arch/powerpc/mm/fault.c
4439 +++ b/arch/powerpc/mm/fault.c
4440 @@ -32,6 +32,10 @@
4441 #include <linux/perf_event.h>
4442 #include <linux/magic.h>
4443 #include <linux/ratelimit.h>
4444 +#include <linux/slab.h>
4445 +#include <linux/pagemap.h>
4446 +#include <linux/compiler.h>
4447 +#include <linux/unistd.h>
4448
4449 #include <asm/firmware.h>
4450 #include <asm/page.h>
4451 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4452 }
4453 #endif
4454
4455 +#ifdef CONFIG_PAX_PAGEEXEC
4456 +/*
4457 + * PaX: decide what to do with offenders (regs->nip = fault address)
4458 + *
4459 + * returns 1 when task should be killed
4460 + */
4461 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4462 +{
4463 + return 1;
4464 +}
4465 +
4466 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4467 +{
4468 + unsigned long i;
4469 +
4470 + printk(KERN_ERR "PAX: bytes at PC: ");
4471 + for (i = 0; i < 5; i++) {
4472 + unsigned int c;
4473 + if (get_user(c, (unsigned int __user *)pc+i))
4474 + printk(KERN_CONT "???????? ");
4475 + else
4476 + printk(KERN_CONT "%08x ", c);
4477 + }
4478 + printk("\n");
4479 +}
4480 +#endif
4481 +
4482 /*
4483 * Check whether the instruction at regs->nip is a store using
4484 * an update addressing form which will update r1.
4485 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4486 * indicate errors in DSISR but can validly be set in SRR1.
4487 */
4488 if (trap == 0x400)
4489 - error_code &= 0x48200000;
4490 + error_code &= 0x58200000;
4491 else
4492 is_write = error_code & DSISR_ISSTORE;
4493 #else
4494 @@ -367,7 +398,7 @@ good_area:
4495 * "undefined". Of those that can be set, this is the only
4496 * one which seems bad.
4497 */
4498 - if (error_code & 0x10000000)
4499 + if (error_code & DSISR_GUARDED)
4500 /* Guarded storage error. */
4501 goto bad_area;
4502 #endif /* CONFIG_8xx */
4503 @@ -382,7 +413,7 @@ good_area:
4504 * processors use the same I/D cache coherency mechanism
4505 * as embedded.
4506 */
4507 - if (error_code & DSISR_PROTFAULT)
4508 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4509 goto bad_area;
4510 #endif /* CONFIG_PPC_STD_MMU */
4511
4512 @@ -465,6 +496,23 @@ bad_area:
4513 bad_area_nosemaphore:
4514 /* User mode accesses cause a SIGSEGV */
4515 if (user_mode(regs)) {
4516 +
4517 +#ifdef CONFIG_PAX_PAGEEXEC
4518 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4519 +#ifdef CONFIG_PPC_STD_MMU
4520 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4521 +#else
4522 + if (is_exec && regs->nip == address) {
4523 +#endif
4524 + switch (pax_handle_fetch_fault(regs)) {
4525 + }
4526 +
4527 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4528 + do_group_exit(SIGKILL);
4529 + }
4530 + }
4531 +#endif
4532 +
4533 _exception(SIGSEGV, regs, code, address);
4534 return 0;
4535 }
4536 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4537 index 67a42ed..1c7210c 100644
4538 --- a/arch/powerpc/mm/mmap_64.c
4539 +++ b/arch/powerpc/mm/mmap_64.c
4540 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4541 */
4542 if (mmap_is_legacy()) {
4543 mm->mmap_base = TASK_UNMAPPED_BASE;
4544 +
4545 +#ifdef CONFIG_PAX_RANDMMAP
4546 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4547 + mm->mmap_base += mm->delta_mmap;
4548 +#endif
4549 +
4550 mm->get_unmapped_area = arch_get_unmapped_area;
4551 mm->unmap_area = arch_unmap_area;
4552 } else {
4553 mm->mmap_base = mmap_base();
4554 +
4555 +#ifdef CONFIG_PAX_RANDMMAP
4556 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4557 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4558 +#endif
4559 +
4560 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4561 mm->unmap_area = arch_unmap_area_topdown;
4562 }
4563 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4564 index 5829d2a..b64ed2e 100644
4565 --- a/arch/powerpc/mm/slice.c
4566 +++ b/arch/powerpc/mm/slice.c
4567 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4568 if ((mm->task_size - len) < addr)
4569 return 0;
4570 vma = find_vma(mm, addr);
4571 - return (!vma || (addr + len) <= vma->vm_start);
4572 + return check_heap_stack_gap(vma, addr, len);
4573 }
4574
4575 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4576 @@ -272,7 +272,7 @@ full_search:
4577 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4578 continue;
4579 }
4580 - if (!vma || addr + len <= vma->vm_start) {
4581 + if (check_heap_stack_gap(vma, addr, len)) {
4582 /*
4583 * Remember the place where we stopped the search:
4584 */
4585 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4586 }
4587 }
4588
4589 - addr = mm->mmap_base;
4590 - while (addr > len) {
4591 + if (mm->mmap_base < len)
4592 + addr = -ENOMEM;
4593 + else
4594 + addr = mm->mmap_base - len;
4595 +
4596 + while (!IS_ERR_VALUE(addr)) {
4597 /* Go down by chunk size */
4598 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4599 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4600
4601 /* Check for hit with different page size */
4602 mask = slice_range_to_mask(addr, len);
4603 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4604 * return with success:
4605 */
4606 vma = find_vma(mm, addr);
4607 - if (!vma || (addr + len) <= vma->vm_start) {
4608 + if (check_heap_stack_gap(vma, addr, len)) {
4609 /* remember the address as a hint for next time */
4610 if (use_cache)
4611 mm->free_area_cache = addr;
4612 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4613 mm->cached_hole_size = vma->vm_start - addr;
4614
4615 /* try just below the current vma->vm_start */
4616 - addr = vma->vm_start;
4617 + addr = skip_heap_stack_gap(vma, len);
4618 }
4619
4620 /*
4621 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4622 if (fixed && addr > (mm->task_size - len))
4623 return -EINVAL;
4624
4625 +#ifdef CONFIG_PAX_RANDMMAP
4626 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4627 + addr = 0;
4628 +#endif
4629 +
4630 /* If hint, make sure it matches our alignment restrictions */
4631 if (!fixed && addr) {
4632 addr = _ALIGN_UP(addr, 1ul << pshift);
4633 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4634 index c797832..ce575c8 100644
4635 --- a/arch/s390/include/asm/atomic.h
4636 +++ b/arch/s390/include/asm/atomic.h
4637 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4638 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4639 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4640
4641 +#define atomic64_read_unchecked(v) atomic64_read(v)
4642 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4643 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4644 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4645 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4646 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4647 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4648 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4649 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4650 +
4651 #define smp_mb__before_atomic_dec() smp_mb()
4652 #define smp_mb__after_atomic_dec() smp_mb()
4653 #define smp_mb__before_atomic_inc() smp_mb()
4654 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4655 index 4d7ccac..d03d0ad 100644
4656 --- a/arch/s390/include/asm/cache.h
4657 +++ b/arch/s390/include/asm/cache.h
4658 @@ -9,8 +9,10 @@
4659 #ifndef __ARCH_S390_CACHE_H
4660 #define __ARCH_S390_CACHE_H
4661
4662 -#define L1_CACHE_BYTES 256
4663 +#include <linux/const.h>
4664 +
4665 #define L1_CACHE_SHIFT 8
4666 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4667 #define NET_SKB_PAD 32
4668
4669 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4670 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4671 index 178ff96..8c93bd1 100644
4672 --- a/arch/s390/include/asm/elf.h
4673 +++ b/arch/s390/include/asm/elf.h
4674 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
4675 the loader. We need to make sure that it is out of the way of the program
4676 that it will "exec", and that there is sufficient room for the brk. */
4677
4678 -extern unsigned long randomize_et_dyn(unsigned long base);
4679 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4680 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4681 +
4682 +#ifdef CONFIG_PAX_ASLR
4683 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4684 +
4685 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4686 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4687 +#endif
4688
4689 /* This yields a mask that user programs can use to figure out what
4690 instruction set this CPU supports. */
4691 @@ -210,9 +216,6 @@ struct linux_binprm;
4692 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4693 int arch_setup_additional_pages(struct linux_binprm *, int);
4694
4695 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4696 -#define arch_randomize_brk arch_randomize_brk
4697 -
4698 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
4699
4700 #endif
4701 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4702 index c4a93d6..4d2a9b4 100644
4703 --- a/arch/s390/include/asm/exec.h
4704 +++ b/arch/s390/include/asm/exec.h
4705 @@ -7,6 +7,6 @@
4706 #ifndef __ASM_EXEC_H
4707 #define __ASM_EXEC_H
4708
4709 -extern unsigned long arch_align_stack(unsigned long sp);
4710 +#define arch_align_stack(x) ((x) & ~0xfUL)
4711
4712 #endif /* __ASM_EXEC_H */
4713 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4714 index 34268df..ea97318 100644
4715 --- a/arch/s390/include/asm/uaccess.h
4716 +++ b/arch/s390/include/asm/uaccess.h
4717 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
4718 copy_to_user(void __user *to, const void *from, unsigned long n)
4719 {
4720 might_fault();
4721 +
4722 + if ((long)n < 0)
4723 + return n;
4724 +
4725 if (access_ok(VERIFY_WRITE, to, n))
4726 n = __copy_to_user(to, from, n);
4727 return n;
4728 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4729 static inline unsigned long __must_check
4730 __copy_from_user(void *to, const void __user *from, unsigned long n)
4731 {
4732 + if ((long)n < 0)
4733 + return n;
4734 +
4735 if (__builtin_constant_p(n) && (n <= 256))
4736 return uaccess.copy_from_user_small(n, from, to);
4737 else
4738 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4739 static inline unsigned long __must_check
4740 copy_from_user(void *to, const void __user *from, unsigned long n)
4741 {
4742 - unsigned int sz = __compiletime_object_size(to);
4743 + size_t sz = __compiletime_object_size(to);
4744
4745 might_fault();
4746 - if (unlikely(sz != -1 && sz < n)) {
4747 +
4748 + if ((long)n < 0)
4749 + return n;
4750 +
4751 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4752 copy_from_user_overflow();
4753 return n;
4754 }
4755 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4756 index 4610dea..cf0af21 100644
4757 --- a/arch/s390/kernel/module.c
4758 +++ b/arch/s390/kernel/module.c
4759 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4760
4761 /* Increase core size by size of got & plt and set start
4762 offsets for got and plt. */
4763 - me->core_size = ALIGN(me->core_size, 4);
4764 - me->arch.got_offset = me->core_size;
4765 - me->core_size += me->arch.got_size;
4766 - me->arch.plt_offset = me->core_size;
4767 - me->core_size += me->arch.plt_size;
4768 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4769 + me->arch.got_offset = me->core_size_rw;
4770 + me->core_size_rw += me->arch.got_size;
4771 + me->arch.plt_offset = me->core_size_rx;
4772 + me->core_size_rx += me->arch.plt_size;
4773 return 0;
4774 }
4775
4776 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4777 if (info->got_initialized == 0) {
4778 Elf_Addr *gotent;
4779
4780 - gotent = me->module_core + me->arch.got_offset +
4781 + gotent = me->module_core_rw + me->arch.got_offset +
4782 info->got_offset;
4783 *gotent = val;
4784 info->got_initialized = 1;
4785 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4786 else if (r_type == R_390_GOTENT ||
4787 r_type == R_390_GOTPLTENT)
4788 *(unsigned int *) loc =
4789 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4790 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4791 else if (r_type == R_390_GOT64 ||
4792 r_type == R_390_GOTPLT64)
4793 *(unsigned long *) loc = val;
4794 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4795 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4796 if (info->plt_initialized == 0) {
4797 unsigned int *ip;
4798 - ip = me->module_core + me->arch.plt_offset +
4799 + ip = me->module_core_rx + me->arch.plt_offset +
4800 info->plt_offset;
4801 #ifndef CONFIG_64BIT
4802 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4803 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4804 val - loc + 0xffffUL < 0x1ffffeUL) ||
4805 (r_type == R_390_PLT32DBL &&
4806 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4807 - val = (Elf_Addr) me->module_core +
4808 + val = (Elf_Addr) me->module_core_rx +
4809 me->arch.plt_offset +
4810 info->plt_offset;
4811 val += rela->r_addend - loc;
4812 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4813 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4814 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4815 val = val + rela->r_addend -
4816 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4817 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4818 if (r_type == R_390_GOTOFF16)
4819 *(unsigned short *) loc = val;
4820 else if (r_type == R_390_GOTOFF32)
4821 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4822 break;
4823 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4824 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4825 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4826 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4827 rela->r_addend - loc;
4828 if (r_type == R_390_GOTPC)
4829 *(unsigned int *) loc = val;
4830 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4831 index cd31ad4..201c5a3 100644
4832 --- a/arch/s390/kernel/process.c
4833 +++ b/arch/s390/kernel/process.c
4834 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
4835 }
4836 return 0;
4837 }
4838 -
4839 -unsigned long arch_align_stack(unsigned long sp)
4840 -{
4841 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4842 - sp -= get_random_int() & ~PAGE_MASK;
4843 - return sp & ~0xf;
4844 -}
4845 -
4846 -static inline unsigned long brk_rnd(void)
4847 -{
4848 - /* 8MB for 32bit, 1GB for 64bit */
4849 - if (is_32bit_task())
4850 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4851 - else
4852 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4853 -}
4854 -
4855 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4856 -{
4857 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4858 -
4859 - if (ret < mm->brk)
4860 - return mm->brk;
4861 - return ret;
4862 -}
4863 -
4864 -unsigned long randomize_et_dyn(unsigned long base)
4865 -{
4866 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4867 -
4868 - if (!(current->flags & PF_RANDOMIZE))
4869 - return base;
4870 - if (ret < base)
4871 - return base;
4872 - return ret;
4873 -}
4874 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4875 index c59a5ef..3fae59c 100644
4876 --- a/arch/s390/mm/mmap.c
4877 +++ b/arch/s390/mm/mmap.c
4878 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4879 */
4880 if (mmap_is_legacy()) {
4881 mm->mmap_base = TASK_UNMAPPED_BASE;
4882 +
4883 +#ifdef CONFIG_PAX_RANDMMAP
4884 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4885 + mm->mmap_base += mm->delta_mmap;
4886 +#endif
4887 +
4888 mm->get_unmapped_area = arch_get_unmapped_area;
4889 mm->unmap_area = arch_unmap_area;
4890 } else {
4891 mm->mmap_base = mmap_base();
4892 +
4893 +#ifdef CONFIG_PAX_RANDMMAP
4894 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4895 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4896 +#endif
4897 +
4898 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4899 mm->unmap_area = arch_unmap_area_topdown;
4900 }
4901 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4902 */
4903 if (mmap_is_legacy()) {
4904 mm->mmap_base = TASK_UNMAPPED_BASE;
4905 +
4906 +#ifdef CONFIG_PAX_RANDMMAP
4907 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4908 + mm->mmap_base += mm->delta_mmap;
4909 +#endif
4910 +
4911 mm->get_unmapped_area = s390_get_unmapped_area;
4912 mm->unmap_area = arch_unmap_area;
4913 } else {
4914 mm->mmap_base = mmap_base();
4915 +
4916 +#ifdef CONFIG_PAX_RANDMMAP
4917 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4918 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4919 +#endif
4920 +
4921 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4922 mm->unmap_area = arch_unmap_area_topdown;
4923 }
4924 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4925 index ae3d59f..f65f075 100644
4926 --- a/arch/score/include/asm/cache.h
4927 +++ b/arch/score/include/asm/cache.h
4928 @@ -1,7 +1,9 @@
4929 #ifndef _ASM_SCORE_CACHE_H
4930 #define _ASM_SCORE_CACHE_H
4931
4932 +#include <linux/const.h>
4933 +
4934 #define L1_CACHE_SHIFT 4
4935 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4936 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4937
4938 #endif /* _ASM_SCORE_CACHE_H */
4939 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4940 index f9f3cd5..58ff438 100644
4941 --- a/arch/score/include/asm/exec.h
4942 +++ b/arch/score/include/asm/exec.h
4943 @@ -1,6 +1,6 @@
4944 #ifndef _ASM_SCORE_EXEC_H
4945 #define _ASM_SCORE_EXEC_H
4946
4947 -extern unsigned long arch_align_stack(unsigned long sp);
4948 +#define arch_align_stack(x) (x)
4949
4950 #endif /* _ASM_SCORE_EXEC_H */
4951 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4952 index 637970c..0b6556b 100644
4953 --- a/arch/score/kernel/process.c
4954 +++ b/arch/score/kernel/process.c
4955 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4956
4957 return task_pt_regs(task)->cp0_epc;
4958 }
4959 -
4960 -unsigned long arch_align_stack(unsigned long sp)
4961 -{
4962 - return sp;
4963 -}
4964 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4965 index ef9e555..331bd29 100644
4966 --- a/arch/sh/include/asm/cache.h
4967 +++ b/arch/sh/include/asm/cache.h
4968 @@ -9,10 +9,11 @@
4969 #define __ASM_SH_CACHE_H
4970 #ifdef __KERNEL__
4971
4972 +#include <linux/const.h>
4973 #include <linux/init.h>
4974 #include <cpu/cache.h>
4975
4976 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4977 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4978
4979 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4980
4981 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4982 index afeb710..d1d1289 100644
4983 --- a/arch/sh/mm/mmap.c
4984 +++ b/arch/sh/mm/mmap.c
4985 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4986 addr = PAGE_ALIGN(addr);
4987
4988 vma = find_vma(mm, addr);
4989 - if (TASK_SIZE - len >= addr &&
4990 - (!vma || addr + len <= vma->vm_start))
4991 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4992 return addr;
4993 }
4994
4995 @@ -106,7 +105,7 @@ full_search:
4996 }
4997 return -ENOMEM;
4998 }
4999 - if (likely(!vma || addr + len <= vma->vm_start)) {
5000 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5001 /*
5002 * Remember the place where we stopped the search:
5003 */
5004 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5005 addr = PAGE_ALIGN(addr);
5006
5007 vma = find_vma(mm, addr);
5008 - if (TASK_SIZE - len >= addr &&
5009 - (!vma || addr + len <= vma->vm_start))
5010 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5011 return addr;
5012 }
5013
5014 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5015 /* make sure it can fit in the remaining address space */
5016 if (likely(addr > len)) {
5017 vma = find_vma(mm, addr-len);
5018 - if (!vma || addr <= vma->vm_start) {
5019 + if (check_heap_stack_gap(vma, addr - len, len)) {
5020 /* remember the address as a hint for next time */
5021 return (mm->free_area_cache = addr-len);
5022 }
5023 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5024 if (unlikely(mm->mmap_base < len))
5025 goto bottomup;
5026
5027 - addr = mm->mmap_base-len;
5028 - if (do_colour_align)
5029 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5030 + addr = mm->mmap_base - len;
5031
5032 do {
5033 + if (do_colour_align)
5034 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5035 /*
5036 * Lookup failure means no vma is above this address,
5037 * else if new region fits below vma->vm_start,
5038 * return with success:
5039 */
5040 vma = find_vma(mm, addr);
5041 - if (likely(!vma || addr+len <= vma->vm_start)) {
5042 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5043 /* remember the address as a hint for next time */
5044 return (mm->free_area_cache = addr);
5045 }
5046 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5047 mm->cached_hole_size = vma->vm_start - addr;
5048
5049 /* try just below the current vma->vm_start */
5050 - addr = vma->vm_start-len;
5051 - if (do_colour_align)
5052 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5053 - } while (likely(len < vma->vm_start));
5054 + addr = skip_heap_stack_gap(vma, len);
5055 + } while (!IS_ERR_VALUE(addr));
5056
5057 bottomup:
5058 /*
5059 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5060 index be56a24..443328f 100644
5061 --- a/arch/sparc/include/asm/atomic_64.h
5062 +++ b/arch/sparc/include/asm/atomic_64.h
5063 @@ -14,18 +14,40 @@
5064 #define ATOMIC64_INIT(i) { (i) }
5065
5066 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5067 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5068 +{
5069 + return v->counter;
5070 +}
5071 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5072 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5073 +{
5074 + return v->counter;
5075 +}
5076
5077 #define atomic_set(v, i) (((v)->counter) = i)
5078 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5079 +{
5080 + v->counter = i;
5081 +}
5082 #define atomic64_set(v, i) (((v)->counter) = i)
5083 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5084 +{
5085 + v->counter = i;
5086 +}
5087
5088 extern void atomic_add(int, atomic_t *);
5089 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5090 extern void atomic64_add(long, atomic64_t *);
5091 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5092 extern void atomic_sub(int, atomic_t *);
5093 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5094 extern void atomic64_sub(long, atomic64_t *);
5095 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5096
5097 extern int atomic_add_ret(int, atomic_t *);
5098 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5099 extern long atomic64_add_ret(long, atomic64_t *);
5100 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5101 extern int atomic_sub_ret(int, atomic_t *);
5102 extern long atomic64_sub_ret(long, atomic64_t *);
5103
5104 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5105 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5106
5107 #define atomic_inc_return(v) atomic_add_ret(1, v)
5108 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5109 +{
5110 + return atomic_add_ret_unchecked(1, v);
5111 +}
5112 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5113 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5114 +{
5115 + return atomic64_add_ret_unchecked(1, v);
5116 +}
5117
5118 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5119 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5120
5121 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5122 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5123 +{
5124 + return atomic_add_ret_unchecked(i, v);
5125 +}
5126 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5127 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5128 +{
5129 + return atomic64_add_ret_unchecked(i, v);
5130 +}
5131
5132 /*
5133 * atomic_inc_and_test - increment and test
5134 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5135 * other cases.
5136 */
5137 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5138 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5139 +{
5140 + return atomic_inc_return_unchecked(v) == 0;
5141 +}
5142 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5143
5144 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5145 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5146 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5147
5148 #define atomic_inc(v) atomic_add(1, v)
5149 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5150 +{
5151 + atomic_add_unchecked(1, v);
5152 +}
5153 #define atomic64_inc(v) atomic64_add(1, v)
5154 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5155 +{
5156 + atomic64_add_unchecked(1, v);
5157 +}
5158
5159 #define atomic_dec(v) atomic_sub(1, v)
5160 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5161 +{
5162 + atomic_sub_unchecked(1, v);
5163 +}
5164 #define atomic64_dec(v) atomic64_sub(1, v)
5165 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5166 +{
5167 + atomic64_sub_unchecked(1, v);
5168 +}
5169
5170 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5171 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5172
5173 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5174 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5175 +{
5176 + return cmpxchg(&v->counter, old, new);
5177 +}
5178 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5179 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5180 +{
5181 + return xchg(&v->counter, new);
5182 +}
5183
5184 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5185 {
5186 - int c, old;
5187 + int c, old, new;
5188 c = atomic_read(v);
5189 for (;;) {
5190 - if (unlikely(c == (u)))
5191 + if (unlikely(c == u))
5192 break;
5193 - old = atomic_cmpxchg((v), c, c + (a));
5194 +
5195 + asm volatile("addcc %2, %0, %0\n"
5196 +
5197 +#ifdef CONFIG_PAX_REFCOUNT
5198 + "tvs %%icc, 6\n"
5199 +#endif
5200 +
5201 + : "=r" (new)
5202 + : "0" (c), "ir" (a)
5203 + : "cc");
5204 +
5205 + old = atomic_cmpxchg(v, c, new);
5206 if (likely(old == c))
5207 break;
5208 c = old;
5209 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5210 #define atomic64_cmpxchg(v, o, n) \
5211 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5212 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5213 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5214 +{
5215 + return xchg(&v->counter, new);
5216 +}
5217
5218 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5219 {
5220 - long c, old;
5221 + long c, old, new;
5222 c = atomic64_read(v);
5223 for (;;) {
5224 - if (unlikely(c == (u)))
5225 + if (unlikely(c == u))
5226 break;
5227 - old = atomic64_cmpxchg((v), c, c + (a));
5228 +
5229 + asm volatile("addcc %2, %0, %0\n"
5230 +
5231 +#ifdef CONFIG_PAX_REFCOUNT
5232 + "tvs %%xcc, 6\n"
5233 +#endif
5234 +
5235 + : "=r" (new)
5236 + : "0" (c), "ir" (a)
5237 + : "cc");
5238 +
5239 + old = atomic64_cmpxchg(v, c, new);
5240 if (likely(old == c))
5241 break;
5242 c = old;
5243 }
5244 - return c != (u);
5245 + return c != u;
5246 }
5247
5248 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5249 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5250 index 5bb6991..5c2132e 100644
5251 --- a/arch/sparc/include/asm/cache.h
5252 +++ b/arch/sparc/include/asm/cache.h
5253 @@ -7,10 +7,12 @@
5254 #ifndef _SPARC_CACHE_H
5255 #define _SPARC_CACHE_H
5256
5257 +#include <linux/const.h>
5258 +
5259 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5260
5261 #define L1_CACHE_SHIFT 5
5262 -#define L1_CACHE_BYTES 32
5263 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5264
5265 #ifdef CONFIG_SPARC32
5266 #define SMP_CACHE_BYTES_SHIFT 5
5267 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5268 index ac74a2c..a9e58af 100644
5269 --- a/arch/sparc/include/asm/elf_32.h
5270 +++ b/arch/sparc/include/asm/elf_32.h
5271 @@ -114,6 +114,13 @@ typedef struct {
5272
5273 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5274
5275 +#ifdef CONFIG_PAX_ASLR
5276 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5277 +
5278 +#define PAX_DELTA_MMAP_LEN 16
5279 +#define PAX_DELTA_STACK_LEN 16
5280 +#endif
5281 +
5282 /* This yields a mask that user programs can use to figure out what
5283 instruction set this cpu supports. This can NOT be done in userspace
5284 on Sparc. */
5285 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5286 index 370ca1e..d4f4a98 100644
5287 --- a/arch/sparc/include/asm/elf_64.h
5288 +++ b/arch/sparc/include/asm/elf_64.h
5289 @@ -189,6 +189,13 @@ typedef struct {
5290 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5291 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5292
5293 +#ifdef CONFIG_PAX_ASLR
5294 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5295 +
5296 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5297 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5298 +#endif
5299 +
5300 extern unsigned long sparc64_elf_hwcap;
5301 #define ELF_HWCAP sparc64_elf_hwcap
5302
5303 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5304 index 9b1c36d..209298b 100644
5305 --- a/arch/sparc/include/asm/pgalloc_32.h
5306 +++ b/arch/sparc/include/asm/pgalloc_32.h
5307 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5308 }
5309
5310 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5311 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5312
5313 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5314 unsigned long address)
5315 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5316 index bcfe063..b333142 100644
5317 --- a/arch/sparc/include/asm/pgalloc_64.h
5318 +++ b/arch/sparc/include/asm/pgalloc_64.h
5319 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5320 }
5321
5322 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5323 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5324
5325 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5326 {
5327 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5328 index 6fc1348..390c50a 100644
5329 --- a/arch/sparc/include/asm/pgtable_32.h
5330 +++ b/arch/sparc/include/asm/pgtable_32.h
5331 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5332 #define PAGE_SHARED SRMMU_PAGE_SHARED
5333 #define PAGE_COPY SRMMU_PAGE_COPY
5334 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5335 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5336 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5337 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5338 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5339
5340 /* Top-level page directory - dummy used by init-mm.
5341 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5342
5343 /* xwr */
5344 #define __P000 PAGE_NONE
5345 -#define __P001 PAGE_READONLY
5346 -#define __P010 PAGE_COPY
5347 -#define __P011 PAGE_COPY
5348 +#define __P001 PAGE_READONLY_NOEXEC
5349 +#define __P010 PAGE_COPY_NOEXEC
5350 +#define __P011 PAGE_COPY_NOEXEC
5351 #define __P100 PAGE_READONLY
5352 #define __P101 PAGE_READONLY
5353 #define __P110 PAGE_COPY
5354 #define __P111 PAGE_COPY
5355
5356 #define __S000 PAGE_NONE
5357 -#define __S001 PAGE_READONLY
5358 -#define __S010 PAGE_SHARED
5359 -#define __S011 PAGE_SHARED
5360 +#define __S001 PAGE_READONLY_NOEXEC
5361 +#define __S010 PAGE_SHARED_NOEXEC
5362 +#define __S011 PAGE_SHARED_NOEXEC
5363 #define __S100 PAGE_READONLY
5364 #define __S101 PAGE_READONLY
5365 #define __S110 PAGE_SHARED
5366 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5367 index 79da178..c2eede8 100644
5368 --- a/arch/sparc/include/asm/pgtsrmmu.h
5369 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5370 @@ -115,6 +115,11 @@
5371 SRMMU_EXEC | SRMMU_REF)
5372 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5373 SRMMU_EXEC | SRMMU_REF)
5374 +
5375 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5376 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5377 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5378 +
5379 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5380 SRMMU_DIRTY | SRMMU_REF)
5381
5382 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5383 index 9689176..63c18ea 100644
5384 --- a/arch/sparc/include/asm/spinlock_64.h
5385 +++ b/arch/sparc/include/asm/spinlock_64.h
5386 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5387
5388 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5389
5390 -static void inline arch_read_lock(arch_rwlock_t *lock)
5391 +static inline void arch_read_lock(arch_rwlock_t *lock)
5392 {
5393 unsigned long tmp1, tmp2;
5394
5395 __asm__ __volatile__ (
5396 "1: ldsw [%2], %0\n"
5397 " brlz,pn %0, 2f\n"
5398 -"4: add %0, 1, %1\n"
5399 +"4: addcc %0, 1, %1\n"
5400 +
5401 +#ifdef CONFIG_PAX_REFCOUNT
5402 +" tvs %%icc, 6\n"
5403 +#endif
5404 +
5405 " cas [%2], %0, %1\n"
5406 " cmp %0, %1\n"
5407 " bne,pn %%icc, 1b\n"
5408 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5409 " .previous"
5410 : "=&r" (tmp1), "=&r" (tmp2)
5411 : "r" (lock)
5412 - : "memory");
5413 + : "memory", "cc");
5414 }
5415
5416 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5417 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5418 {
5419 int tmp1, tmp2;
5420
5421 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5422 "1: ldsw [%2], %0\n"
5423 " brlz,a,pn %0, 2f\n"
5424 " mov 0, %0\n"
5425 -" add %0, 1, %1\n"
5426 +" addcc %0, 1, %1\n"
5427 +
5428 +#ifdef CONFIG_PAX_REFCOUNT
5429 +" tvs %%icc, 6\n"
5430 +#endif
5431 +
5432 " cas [%2], %0, %1\n"
5433 " cmp %0, %1\n"
5434 " bne,pn %%icc, 1b\n"
5435 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5436 return tmp1;
5437 }
5438
5439 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5440 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5441 {
5442 unsigned long tmp1, tmp2;
5443
5444 __asm__ __volatile__(
5445 "1: lduw [%2], %0\n"
5446 -" sub %0, 1, %1\n"
5447 +" subcc %0, 1, %1\n"
5448 +
5449 +#ifdef CONFIG_PAX_REFCOUNT
5450 +" tvs %%icc, 6\n"
5451 +#endif
5452 +
5453 " cas [%2], %0, %1\n"
5454 " cmp %0, %1\n"
5455 " bne,pn %%xcc, 1b\n"
5456 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5457 : "memory");
5458 }
5459
5460 -static void inline arch_write_lock(arch_rwlock_t *lock)
5461 +static inline void arch_write_lock(arch_rwlock_t *lock)
5462 {
5463 unsigned long mask, tmp1, tmp2;
5464
5465 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5466 : "memory");
5467 }
5468
5469 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5470 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5471 {
5472 __asm__ __volatile__(
5473 " stw %%g0, [%0]"
5474 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5475 : "memory");
5476 }
5477
5478 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5479 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5480 {
5481 unsigned long mask, tmp1, tmp2, result;
5482
5483 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5484 index 25849ae..924c54b 100644
5485 --- a/arch/sparc/include/asm/thread_info_32.h
5486 +++ b/arch/sparc/include/asm/thread_info_32.h
5487 @@ -49,6 +49,8 @@ struct thread_info {
5488 unsigned long w_saved;
5489
5490 struct restart_block restart_block;
5491 +
5492 + unsigned long lowest_stack;
5493 };
5494
5495 /*
5496 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5497 index a3fe4dc..cae132a 100644
5498 --- a/arch/sparc/include/asm/thread_info_64.h
5499 +++ b/arch/sparc/include/asm/thread_info_64.h
5500 @@ -63,6 +63,8 @@ struct thread_info {
5501 struct pt_regs *kern_una_regs;
5502 unsigned int kern_una_insn;
5503
5504 + unsigned long lowest_stack;
5505 +
5506 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5507 };
5508
5509 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5510 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5511 /* flag bit 6 is available */
5512 #define TIF_32BIT 7 /* 32-bit binary */
5513 -/* flag bit 8 is available */
5514 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5515 #define TIF_SECCOMP 9 /* secure computing */
5516 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5517 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5518 +
5519 /* NOTE: Thread flags >= 12 should be ones we have no interest
5520 * in using in assembly, else we can't use the mask as
5521 * an immediate value in instructions such as andcc.
5522 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5523 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5524 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5525 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5526 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5527
5528 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5529 _TIF_DO_NOTIFY_RESUME_MASK | \
5530 _TIF_NEED_RESCHED)
5531 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5532
5533 +#define _TIF_WORK_SYSCALL \
5534 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5535 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5536 +
5537 +
5538 /*
5539 * Thread-synchronous status.
5540 *
5541 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5542 index 0167d26..9acd8ed 100644
5543 --- a/arch/sparc/include/asm/uaccess.h
5544 +++ b/arch/sparc/include/asm/uaccess.h
5545 @@ -1,5 +1,13 @@
5546 #ifndef ___ASM_SPARC_UACCESS_H
5547 #define ___ASM_SPARC_UACCESS_H
5548 +
5549 +#ifdef __KERNEL__
5550 +#ifndef __ASSEMBLY__
5551 +#include <linux/types.h>
5552 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5553 +#endif
5554 +#endif
5555 +
5556 #if defined(__sparc__) && defined(__arch64__)
5557 #include <asm/uaccess_64.h>
5558 #else
5559 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5560 index 53a28dd..50c38c3 100644
5561 --- a/arch/sparc/include/asm/uaccess_32.h
5562 +++ b/arch/sparc/include/asm/uaccess_32.h
5563 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5564
5565 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5566 {
5567 - if (n && __access_ok((unsigned long) to, n))
5568 + if ((long)n < 0)
5569 + return n;
5570 +
5571 + if (n && __access_ok((unsigned long) to, n)) {
5572 + if (!__builtin_constant_p(n))
5573 + check_object_size(from, n, true);
5574 return __copy_user(to, (__force void __user *) from, n);
5575 - else
5576 + } else
5577 return n;
5578 }
5579
5580 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5581 {
5582 + if ((long)n < 0)
5583 + return n;
5584 +
5585 + if (!__builtin_constant_p(n))
5586 + check_object_size(from, n, true);
5587 +
5588 return __copy_user(to, (__force void __user *) from, n);
5589 }
5590
5591 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5592 {
5593 - if (n && __access_ok((unsigned long) from, n))
5594 + if ((long)n < 0)
5595 + return n;
5596 +
5597 + if (n && __access_ok((unsigned long) from, n)) {
5598 + if (!__builtin_constant_p(n))
5599 + check_object_size(to, n, false);
5600 return __copy_user((__force void __user *) to, from, n);
5601 - else
5602 + } else
5603 return n;
5604 }
5605
5606 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5607 {
5608 + if ((long)n < 0)
5609 + return n;
5610 +
5611 return __copy_user((__force void __user *) to, from, n);
5612 }
5613
5614 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5615 index 73083e1..2bc62a6 100644
5616 --- a/arch/sparc/include/asm/uaccess_64.h
5617 +++ b/arch/sparc/include/asm/uaccess_64.h
5618 @@ -10,6 +10,7 @@
5619 #include <linux/compiler.h>
5620 #include <linux/string.h>
5621 #include <linux/thread_info.h>
5622 +#include <linux/kernel.h>
5623 #include <asm/asi.h>
5624 #include <asm/spitfire.h>
5625 #include <asm-generic/uaccess-unaligned.h>
5626 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5627 static inline unsigned long __must_check
5628 copy_from_user(void *to, const void __user *from, unsigned long size)
5629 {
5630 - unsigned long ret = ___copy_from_user(to, from, size);
5631 + unsigned long ret;
5632
5633 + if ((long)size < 0 || size > INT_MAX)
5634 + return size;
5635 +
5636 + if (!__builtin_constant_p(size))
5637 + check_object_size(to, size, false);
5638 +
5639 + ret = ___copy_from_user(to, from, size);
5640 if (unlikely(ret))
5641 ret = copy_from_user_fixup(to, from, size);
5642
5643 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5644 static inline unsigned long __must_check
5645 copy_to_user(void __user *to, const void *from, unsigned long size)
5646 {
5647 - unsigned long ret = ___copy_to_user(to, from, size);
5648 + unsigned long ret;
5649
5650 + if ((long)size < 0 || size > INT_MAX)
5651 + return size;
5652 +
5653 + if (!__builtin_constant_p(size))
5654 + check_object_size(from, size, true);
5655 +
5656 + ret = ___copy_to_user(to, from, size);
5657 if (unlikely(ret))
5658 ret = copy_to_user_fixup(to, from, size);
5659 return ret;
5660 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5661 index 6cf591b..b49e65a 100644
5662 --- a/arch/sparc/kernel/Makefile
5663 +++ b/arch/sparc/kernel/Makefile
5664 @@ -3,7 +3,7 @@
5665 #
5666
5667 asflags-y := -ansi
5668 -ccflags-y := -Werror
5669 +#ccflags-y := -Werror
5670
5671 extra-y := head_$(BITS).o
5672
5673 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5674 index 487bffb..955a925 100644
5675 --- a/arch/sparc/kernel/process_32.c
5676 +++ b/arch/sparc/kernel/process_32.c
5677 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5678
5679 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5680 r->psr, r->pc, r->npc, r->y, print_tainted());
5681 - printk("PC: <%pS>\n", (void *) r->pc);
5682 + printk("PC: <%pA>\n", (void *) r->pc);
5683 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5684 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5685 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5686 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5687 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5688 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5689 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5690 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5691
5692 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5693 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5694 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5695 rw = (struct reg_window32 *) fp;
5696 pc = rw->ins[7];
5697 printk("[%08lx : ", pc);
5698 - printk("%pS ] ", (void *) pc);
5699 + printk("%pA ] ", (void *) pc);
5700 fp = rw->ins[6];
5701 } while (++count < 16);
5702 printk("\n");
5703 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5704 index c6e0c29..052832b 100644
5705 --- a/arch/sparc/kernel/process_64.c
5706 +++ b/arch/sparc/kernel/process_64.c
5707 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
5708 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5709 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5710 if (regs->tstate & TSTATE_PRIV)
5711 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5712 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5713 }
5714
5715 void show_regs(struct pt_regs *regs)
5716 {
5717 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5718 regs->tpc, regs->tnpc, regs->y, print_tainted());
5719 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5720 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5721 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5722 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5723 regs->u_regs[3]);
5724 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
5725 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5726 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5727 regs->u_regs[15]);
5728 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5729 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5730 show_regwindow(regs);
5731 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5732 }
5733 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
5734 ((tp && tp->task) ? tp->task->pid : -1));
5735
5736 if (gp->tstate & TSTATE_PRIV) {
5737 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5738 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5739 (void *) gp->tpc,
5740 (void *) gp->o7,
5741 (void *) gp->i7,
5742 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5743 index 7ff45e4..a58f271 100644
5744 --- a/arch/sparc/kernel/ptrace_64.c
5745 +++ b/arch/sparc/kernel/ptrace_64.c
5746 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5747 return ret;
5748 }
5749
5750 +#ifdef CONFIG_GRKERNSEC_SETXID
5751 +extern void gr_delayed_cred_worker(void);
5752 +#endif
5753 +
5754 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5755 {
5756 int ret = 0;
5757 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5758 /* do the secure computing check first */
5759 secure_computing_strict(regs->u_regs[UREG_G1]);
5760
5761 +#ifdef CONFIG_GRKERNSEC_SETXID
5762 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5763 + gr_delayed_cred_worker();
5764 +#endif
5765 +
5766 if (test_thread_flag(TIF_SYSCALL_TRACE))
5767 ret = tracehook_report_syscall_entry(regs);
5768
5769 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5770
5771 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5772 {
5773 +#ifdef CONFIG_GRKERNSEC_SETXID
5774 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5775 + gr_delayed_cred_worker();
5776 +#endif
5777 +
5778 audit_syscall_exit(regs);
5779
5780 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5781 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5782 index 0c9b31b..7cb7aee 100644
5783 --- a/arch/sparc/kernel/sys_sparc_32.c
5784 +++ b/arch/sparc/kernel/sys_sparc_32.c
5785 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5786 if (len > TASK_SIZE - PAGE_SIZE)
5787 return -ENOMEM;
5788 if (!addr)
5789 - addr = TASK_UNMAPPED_BASE;
5790 + addr = current->mm->mmap_base;
5791
5792 if (flags & MAP_SHARED)
5793 addr = COLOUR_ALIGN(addr);
5794 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5795 /* At this point: (!vmm || addr < vmm->vm_end). */
5796 if (TASK_SIZE - PAGE_SIZE - len < addr)
5797 return -ENOMEM;
5798 - if (!vmm || addr + len <= vmm->vm_start)
5799 + if (check_heap_stack_gap(vmm, addr, len))
5800 return addr;
5801 addr = vmm->vm_end;
5802 if (flags & MAP_SHARED)
5803 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5804 index 878ef3d..8742f10 100644
5805 --- a/arch/sparc/kernel/sys_sparc_64.c
5806 +++ b/arch/sparc/kernel/sys_sparc_64.c
5807 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5808 /* We do not accept a shared mapping if it would violate
5809 * cache aliasing constraints.
5810 */
5811 - if ((flags & MAP_SHARED) &&
5812 + if ((filp || (flags & MAP_SHARED)) &&
5813 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5814 return -EINVAL;
5815 return addr;
5816 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5817 if (filp || (flags & MAP_SHARED))
5818 do_color_align = 1;
5819
5820 +#ifdef CONFIG_PAX_RANDMMAP
5821 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5822 +#endif
5823 +
5824 if (addr) {
5825 if (do_color_align)
5826 addr = COLOUR_ALIGN(addr, pgoff);
5827 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5828 addr = PAGE_ALIGN(addr);
5829
5830 vma = find_vma(mm, addr);
5831 - if (task_size - len >= addr &&
5832 - (!vma || addr + len <= vma->vm_start))
5833 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5834 return addr;
5835 }
5836
5837 if (len > mm->cached_hole_size) {
5838 - start_addr = addr = mm->free_area_cache;
5839 + start_addr = addr = mm->free_area_cache;
5840 } else {
5841 - start_addr = addr = TASK_UNMAPPED_BASE;
5842 + start_addr = addr = mm->mmap_base;
5843 mm->cached_hole_size = 0;
5844 }
5845
5846 @@ -157,14 +160,14 @@ full_search:
5847 vma = find_vma(mm, VA_EXCLUDE_END);
5848 }
5849 if (unlikely(task_size < addr)) {
5850 - if (start_addr != TASK_UNMAPPED_BASE) {
5851 - start_addr = addr = TASK_UNMAPPED_BASE;
5852 + if (start_addr != mm->mmap_base) {
5853 + start_addr = addr = mm->mmap_base;
5854 mm->cached_hole_size = 0;
5855 goto full_search;
5856 }
5857 return -ENOMEM;
5858 }
5859 - if (likely(!vma || addr + len <= vma->vm_start)) {
5860 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5861 /*
5862 * Remember the place where we stopped the search:
5863 */
5864 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5865 /* We do not accept a shared mapping if it would violate
5866 * cache aliasing constraints.
5867 */
5868 - if ((flags & MAP_SHARED) &&
5869 + if ((filp || (flags & MAP_SHARED)) &&
5870 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5871 return -EINVAL;
5872 return addr;
5873 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5874 addr = PAGE_ALIGN(addr);
5875
5876 vma = find_vma(mm, addr);
5877 - if (task_size - len >= addr &&
5878 - (!vma || addr + len <= vma->vm_start))
5879 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5880 return addr;
5881 }
5882
5883 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5884 /* make sure it can fit in the remaining address space */
5885 if (likely(addr > len)) {
5886 vma = find_vma(mm, addr-len);
5887 - if (!vma || addr <= vma->vm_start) {
5888 + if (check_heap_stack_gap(vma, addr - len, len)) {
5889 /* remember the address as a hint for next time */
5890 return (mm->free_area_cache = addr-len);
5891 }
5892 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5893 if (unlikely(mm->mmap_base < len))
5894 goto bottomup;
5895
5896 - addr = mm->mmap_base-len;
5897 - if (do_color_align)
5898 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5899 + addr = mm->mmap_base - len;
5900
5901 do {
5902 + if (do_color_align)
5903 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5904 /*
5905 * Lookup failure means no vma is above this address,
5906 * else if new region fits below vma->vm_start,
5907 * return with success:
5908 */
5909 vma = find_vma(mm, addr);
5910 - if (likely(!vma || addr+len <= vma->vm_start)) {
5911 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5912 /* remember the address as a hint for next time */
5913 return (mm->free_area_cache = addr);
5914 }
5915 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5916 mm->cached_hole_size = vma->vm_start - addr;
5917
5918 /* try just below the current vma->vm_start */
5919 - addr = vma->vm_start-len;
5920 - if (do_color_align)
5921 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5922 - } while (likely(len < vma->vm_start));
5923 + addr = skip_heap_stack_gap(vma, len);
5924 + } while (!IS_ERR_VALUE(addr));
5925
5926 bottomup:
5927 /*
5928 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5929 gap == RLIM_INFINITY ||
5930 sysctl_legacy_va_layout) {
5931 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5932 +
5933 +#ifdef CONFIG_PAX_RANDMMAP
5934 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5935 + mm->mmap_base += mm->delta_mmap;
5936 +#endif
5937 +
5938 mm->get_unmapped_area = arch_get_unmapped_area;
5939 mm->unmap_area = arch_unmap_area;
5940 } else {
5941 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5942 gap = (task_size / 6 * 5);
5943
5944 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5945 +
5946 +#ifdef CONFIG_PAX_RANDMMAP
5947 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5948 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5949 +#endif
5950 +
5951 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5952 mm->unmap_area = arch_unmap_area_topdown;
5953 }
5954 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5955 index bf23477..b7425a6 100644
5956 --- a/arch/sparc/kernel/syscalls.S
5957 +++ b/arch/sparc/kernel/syscalls.S
5958 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5959 #endif
5960 .align 32
5961 1: ldx [%g6 + TI_FLAGS], %l5
5962 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5963 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5964 be,pt %icc, rtrap
5965 nop
5966 call syscall_trace_leave
5967 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
5968
5969 srl %i5, 0, %o5 ! IEU1
5970 srl %i2, 0, %o2 ! IEU0 Group
5971 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5972 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5973 bne,pn %icc, linux_syscall_trace32 ! CTI
5974 mov %i0, %l5 ! IEU1
5975 call %l7 ! CTI Group brk forced
5976 @@ -212,7 +212,7 @@ linux_sparc_syscall:
5977
5978 mov %i3, %o3 ! IEU1
5979 mov %i4, %o4 ! IEU0 Group
5980 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5981 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5982 bne,pn %icc, linux_syscall_trace ! CTI Group
5983 mov %i0, %l5 ! IEU0
5984 2: call %l7 ! CTI Group brk forced
5985 @@ -228,7 +228,7 @@ ret_sys_call:
5986
5987 cmp %o0, -ERESTART_RESTARTBLOCK
5988 bgeu,pn %xcc, 1f
5989 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5990 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5991 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
5992
5993 2:
5994 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5995 index a5785ea..405c5f7 100644
5996 --- a/arch/sparc/kernel/traps_32.c
5997 +++ b/arch/sparc/kernel/traps_32.c
5998 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
5999 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6000 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6001
6002 +extern void gr_handle_kernel_exploit(void);
6003 +
6004 void die_if_kernel(char *str, struct pt_regs *regs)
6005 {
6006 static int die_counter;
6007 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6008 count++ < 30 &&
6009 (((unsigned long) rw) >= PAGE_OFFSET) &&
6010 !(((unsigned long) rw) & 0x7)) {
6011 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6012 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6013 (void *) rw->ins[7]);
6014 rw = (struct reg_window32 *)rw->ins[6];
6015 }
6016 }
6017 printk("Instruction DUMP:");
6018 instruction_dump ((unsigned long *) regs->pc);
6019 - if(regs->psr & PSR_PS)
6020 + if(regs->psr & PSR_PS) {
6021 + gr_handle_kernel_exploit();
6022 do_exit(SIGKILL);
6023 + }
6024 do_exit(SIGSEGV);
6025 }
6026
6027 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6028 index b66a779..8e8d66c 100644
6029 --- a/arch/sparc/kernel/traps_64.c
6030 +++ b/arch/sparc/kernel/traps_64.c
6031 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6032 i + 1,
6033 p->trapstack[i].tstate, p->trapstack[i].tpc,
6034 p->trapstack[i].tnpc, p->trapstack[i].tt);
6035 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6036 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6037 }
6038 }
6039
6040 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6041
6042 lvl -= 0x100;
6043 if (regs->tstate & TSTATE_PRIV) {
6044 +
6045 +#ifdef CONFIG_PAX_REFCOUNT
6046 + if (lvl == 6)
6047 + pax_report_refcount_overflow(regs);
6048 +#endif
6049 +
6050 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6051 die_if_kernel(buffer, regs);
6052 }
6053 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6054 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6055 {
6056 char buffer[32];
6057 -
6058 +
6059 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6060 0, lvl, SIGTRAP) == NOTIFY_STOP)
6061 return;
6062
6063 +#ifdef CONFIG_PAX_REFCOUNT
6064 + if (lvl == 6)
6065 + pax_report_refcount_overflow(regs);
6066 +#endif
6067 +
6068 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6069
6070 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6071 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6072 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6073 printk("%s" "ERROR(%d): ",
6074 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6075 - printk("TPC<%pS>\n", (void *) regs->tpc);
6076 + printk("TPC<%pA>\n", (void *) regs->tpc);
6077 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6078 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6079 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6080 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6081 smp_processor_id(),
6082 (type & 0x1) ? 'I' : 'D',
6083 regs->tpc);
6084 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6085 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6086 panic("Irrecoverable Cheetah+ parity error.");
6087 }
6088
6089 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6090 smp_processor_id(),
6091 (type & 0x1) ? 'I' : 'D',
6092 regs->tpc);
6093 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6094 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6095 }
6096
6097 struct sun4v_error_entry {
6098 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6099
6100 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6101 regs->tpc, tl);
6102 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6103 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6104 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6105 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6106 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6107 (void *) regs->u_regs[UREG_I7]);
6108 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6109 "pte[%lx] error[%lx]\n",
6110 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6111
6112 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6113 regs->tpc, tl);
6114 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6115 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6116 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6117 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6118 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6119 (void *) regs->u_regs[UREG_I7]);
6120 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6121 "pte[%lx] error[%lx]\n",
6122 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6123 fp = (unsigned long)sf->fp + STACK_BIAS;
6124 }
6125
6126 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6127 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6128 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6129 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6130 int index = tsk->curr_ret_stack;
6131 if (tsk->ret_stack && index >= graph) {
6132 pc = tsk->ret_stack[index - graph].ret;
6133 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6134 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6135 graph++;
6136 }
6137 }
6138 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6139 return (struct reg_window *) (fp + STACK_BIAS);
6140 }
6141
6142 +extern void gr_handle_kernel_exploit(void);
6143 +
6144 void die_if_kernel(char *str, struct pt_regs *regs)
6145 {
6146 static int die_counter;
6147 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6148 while (rw &&
6149 count++ < 30 &&
6150 kstack_valid(tp, (unsigned long) rw)) {
6151 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6152 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6153 (void *) rw->ins[7]);
6154
6155 rw = kernel_stack_up(rw);
6156 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6157 }
6158 user_instruction_dump ((unsigned int __user *) regs->tpc);
6159 }
6160 - if (regs->tstate & TSTATE_PRIV)
6161 + if (regs->tstate & TSTATE_PRIV) {
6162 + gr_handle_kernel_exploit();
6163 do_exit(SIGKILL);
6164 + }
6165 do_exit(SIGSEGV);
6166 }
6167 EXPORT_SYMBOL(die_if_kernel);
6168 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6169 index 8201c25e..072a2a7 100644
6170 --- a/arch/sparc/kernel/unaligned_64.c
6171 +++ b/arch/sparc/kernel/unaligned_64.c
6172 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
6173 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6174
6175 if (__ratelimit(&ratelimit)) {
6176 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6177 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6178 regs->tpc, (void *) regs->tpc);
6179 }
6180 }
6181 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6182 index 8410065f2..4fd4ca22 100644
6183 --- a/arch/sparc/lib/Makefile
6184 +++ b/arch/sparc/lib/Makefile
6185 @@ -2,7 +2,7 @@
6186 #
6187
6188 asflags-y := -ansi -DST_DIV0=0x02
6189 -ccflags-y := -Werror
6190 +#ccflags-y := -Werror
6191
6192 lib-$(CONFIG_SPARC32) += ashrdi3.o
6193 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6194 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6195 index 85c233d..68500e0 100644
6196 --- a/arch/sparc/lib/atomic_64.S
6197 +++ b/arch/sparc/lib/atomic_64.S
6198 @@ -17,7 +17,12 @@
6199 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6200 BACKOFF_SETUP(%o2)
6201 1: lduw [%o1], %g1
6202 - add %g1, %o0, %g7
6203 + addcc %g1, %o0, %g7
6204 +
6205 +#ifdef CONFIG_PAX_REFCOUNT
6206 + tvs %icc, 6
6207 +#endif
6208 +
6209 cas [%o1], %g1, %g7
6210 cmp %g1, %g7
6211 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6212 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6213 2: BACKOFF_SPIN(%o2, %o3, 1b)
6214 ENDPROC(atomic_add)
6215
6216 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6217 + BACKOFF_SETUP(%o2)
6218 +1: lduw [%o1], %g1
6219 + add %g1, %o0, %g7
6220 + cas [%o1], %g1, %g7
6221 + cmp %g1, %g7
6222 + bne,pn %icc, 2f
6223 + nop
6224 + retl
6225 + nop
6226 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6227 +ENDPROC(atomic_add_unchecked)
6228 +
6229 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6230 BACKOFF_SETUP(%o2)
6231 1: lduw [%o1], %g1
6232 - sub %g1, %o0, %g7
6233 + subcc %g1, %o0, %g7
6234 +
6235 +#ifdef CONFIG_PAX_REFCOUNT
6236 + tvs %icc, 6
6237 +#endif
6238 +
6239 cas [%o1], %g1, %g7
6240 cmp %g1, %g7
6241 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6242 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6243 2: BACKOFF_SPIN(%o2, %o3, 1b)
6244 ENDPROC(atomic_sub)
6245
6246 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6247 + BACKOFF_SETUP(%o2)
6248 +1: lduw [%o1], %g1
6249 + sub %g1, %o0, %g7
6250 + cas [%o1], %g1, %g7
6251 + cmp %g1, %g7
6252 + bne,pn %icc, 2f
6253 + nop
6254 + retl
6255 + nop
6256 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6257 +ENDPROC(atomic_sub_unchecked)
6258 +
6259 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6260 BACKOFF_SETUP(%o2)
6261 1: lduw [%o1], %g1
6262 - add %g1, %o0, %g7
6263 + addcc %g1, %o0, %g7
6264 +
6265 +#ifdef CONFIG_PAX_REFCOUNT
6266 + tvs %icc, 6
6267 +#endif
6268 +
6269 cas [%o1], %g1, %g7
6270 cmp %g1, %g7
6271 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6272 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6273 2: BACKOFF_SPIN(%o2, %o3, 1b)
6274 ENDPROC(atomic_add_ret)
6275
6276 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6277 + BACKOFF_SETUP(%o2)
6278 +1: lduw [%o1], %g1
6279 + addcc %g1, %o0, %g7
6280 + cas [%o1], %g1, %g7
6281 + cmp %g1, %g7
6282 + bne,pn %icc, 2f
6283 + add %g7, %o0, %g7
6284 + sra %g7, 0, %o0
6285 + retl
6286 + nop
6287 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6288 +ENDPROC(atomic_add_ret_unchecked)
6289 +
6290 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6291 BACKOFF_SETUP(%o2)
6292 1: lduw [%o1], %g1
6293 - sub %g1, %o0, %g7
6294 + subcc %g1, %o0, %g7
6295 +
6296 +#ifdef CONFIG_PAX_REFCOUNT
6297 + tvs %icc, 6
6298 +#endif
6299 +
6300 cas [%o1], %g1, %g7
6301 cmp %g1, %g7
6302 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6303 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6304 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6305 BACKOFF_SETUP(%o2)
6306 1: ldx [%o1], %g1
6307 - add %g1, %o0, %g7
6308 + addcc %g1, %o0, %g7
6309 +
6310 +#ifdef CONFIG_PAX_REFCOUNT
6311 + tvs %xcc, 6
6312 +#endif
6313 +
6314 casx [%o1], %g1, %g7
6315 cmp %g1, %g7
6316 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6317 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6318 2: BACKOFF_SPIN(%o2, %o3, 1b)
6319 ENDPROC(atomic64_add)
6320
6321 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6322 + BACKOFF_SETUP(%o2)
6323 +1: ldx [%o1], %g1
6324 + addcc %g1, %o0, %g7
6325 + casx [%o1], %g1, %g7
6326 + cmp %g1, %g7
6327 + bne,pn %xcc, 2f
6328 + nop
6329 + retl
6330 + nop
6331 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6332 +ENDPROC(atomic64_add_unchecked)
6333 +
6334 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6335 BACKOFF_SETUP(%o2)
6336 1: ldx [%o1], %g1
6337 - sub %g1, %o0, %g7
6338 + subcc %g1, %o0, %g7
6339 +
6340 +#ifdef CONFIG_PAX_REFCOUNT
6341 + tvs %xcc, 6
6342 +#endif
6343 +
6344 casx [%o1], %g1, %g7
6345 cmp %g1, %g7
6346 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6347 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6348 2: BACKOFF_SPIN(%o2, %o3, 1b)
6349 ENDPROC(atomic64_sub)
6350
6351 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6352 + BACKOFF_SETUP(%o2)
6353 +1: ldx [%o1], %g1
6354 + subcc %g1, %o0, %g7
6355 + casx [%o1], %g1, %g7
6356 + cmp %g1, %g7
6357 + bne,pn %xcc, 2f
6358 + nop
6359 + retl
6360 + nop
6361 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6362 +ENDPROC(atomic64_sub_unchecked)
6363 +
6364 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6365 BACKOFF_SETUP(%o2)
6366 1: ldx [%o1], %g1
6367 - add %g1, %o0, %g7
6368 + addcc %g1, %o0, %g7
6369 +
6370 +#ifdef CONFIG_PAX_REFCOUNT
6371 + tvs %xcc, 6
6372 +#endif
6373 +
6374 casx [%o1], %g1, %g7
6375 cmp %g1, %g7
6376 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6377 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6378 2: BACKOFF_SPIN(%o2, %o3, 1b)
6379 ENDPROC(atomic64_add_ret)
6380
6381 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6382 + BACKOFF_SETUP(%o2)
6383 +1: ldx [%o1], %g1
6384 + addcc %g1, %o0, %g7
6385 + casx [%o1], %g1, %g7
6386 + cmp %g1, %g7
6387 + bne,pn %xcc, 2f
6388 + add %g7, %o0, %g7
6389 + mov %g7, %o0
6390 + retl
6391 + nop
6392 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6393 +ENDPROC(atomic64_add_ret_unchecked)
6394 +
6395 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6396 BACKOFF_SETUP(%o2)
6397 1: ldx [%o1], %g1
6398 - sub %g1, %o0, %g7
6399 + subcc %g1, %o0, %g7
6400 +
6401 +#ifdef CONFIG_PAX_REFCOUNT
6402 + tvs %xcc, 6
6403 +#endif
6404 +
6405 casx [%o1], %g1, %g7
6406 cmp %g1, %g7
6407 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6408 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6409 index 0c4e35e..745d3e4 100644
6410 --- a/arch/sparc/lib/ksyms.c
6411 +++ b/arch/sparc/lib/ksyms.c
6412 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6413
6414 /* Atomic counter implementation. */
6415 EXPORT_SYMBOL(atomic_add);
6416 +EXPORT_SYMBOL(atomic_add_unchecked);
6417 EXPORT_SYMBOL(atomic_add_ret);
6418 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6419 EXPORT_SYMBOL(atomic_sub);
6420 +EXPORT_SYMBOL(atomic_sub_unchecked);
6421 EXPORT_SYMBOL(atomic_sub_ret);
6422 EXPORT_SYMBOL(atomic64_add);
6423 +EXPORT_SYMBOL(atomic64_add_unchecked);
6424 EXPORT_SYMBOL(atomic64_add_ret);
6425 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6426 EXPORT_SYMBOL(atomic64_sub);
6427 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6428 EXPORT_SYMBOL(atomic64_sub_ret);
6429 EXPORT_SYMBOL(atomic64_dec_if_positive);
6430
6431 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6432 index 30c3ecc..736f015 100644
6433 --- a/arch/sparc/mm/Makefile
6434 +++ b/arch/sparc/mm/Makefile
6435 @@ -2,7 +2,7 @@
6436 #
6437
6438 asflags-y := -ansi
6439 -ccflags-y := -Werror
6440 +#ccflags-y := -Werror
6441
6442 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6443 obj-y += fault_$(BITS).o
6444 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6445 index e98bfda..ea8d221 100644
6446 --- a/arch/sparc/mm/fault_32.c
6447 +++ b/arch/sparc/mm/fault_32.c
6448 @@ -21,6 +21,9 @@
6449 #include <linux/perf_event.h>
6450 #include <linux/interrupt.h>
6451 #include <linux/kdebug.h>
6452 +#include <linux/slab.h>
6453 +#include <linux/pagemap.h>
6454 +#include <linux/compiler.h>
6455
6456 #include <asm/page.h>
6457 #include <asm/pgtable.h>
6458 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6459 return safe_compute_effective_address(regs, insn);
6460 }
6461
6462 +#ifdef CONFIG_PAX_PAGEEXEC
6463 +#ifdef CONFIG_PAX_DLRESOLVE
6464 +static void pax_emuplt_close(struct vm_area_struct *vma)
6465 +{
6466 + vma->vm_mm->call_dl_resolve = 0UL;
6467 +}
6468 +
6469 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6470 +{
6471 + unsigned int *kaddr;
6472 +
6473 + vmf->page = alloc_page(GFP_HIGHUSER);
6474 + if (!vmf->page)
6475 + return VM_FAULT_OOM;
6476 +
6477 + kaddr = kmap(vmf->page);
6478 + memset(kaddr, 0, PAGE_SIZE);
6479 + kaddr[0] = 0x9DE3BFA8U; /* save */
6480 + flush_dcache_page(vmf->page);
6481 + kunmap(vmf->page);
6482 + return VM_FAULT_MAJOR;
6483 +}
6484 +
6485 +static const struct vm_operations_struct pax_vm_ops = {
6486 + .close = pax_emuplt_close,
6487 + .fault = pax_emuplt_fault
6488 +};
6489 +
6490 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6491 +{
6492 + int ret;
6493 +
6494 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6495 + vma->vm_mm = current->mm;
6496 + vma->vm_start = addr;
6497 + vma->vm_end = addr + PAGE_SIZE;
6498 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6499 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6500 + vma->vm_ops = &pax_vm_ops;
6501 +
6502 + ret = insert_vm_struct(current->mm, vma);
6503 + if (ret)
6504 + return ret;
6505 +
6506 + ++current->mm->total_vm;
6507 + return 0;
6508 +}
6509 +#endif
6510 +
6511 +/*
6512 + * PaX: decide what to do with offenders (regs->pc = fault address)
6513 + *
6514 + * returns 1 when task should be killed
6515 + * 2 when patched PLT trampoline was detected
6516 + * 3 when unpatched PLT trampoline was detected
6517 + */
6518 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6519 +{
6520 +
6521 +#ifdef CONFIG_PAX_EMUPLT
6522 + int err;
6523 +
6524 + do { /* PaX: patched PLT emulation #1 */
6525 + unsigned int sethi1, sethi2, jmpl;
6526 +
6527 + err = get_user(sethi1, (unsigned int *)regs->pc);
6528 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6529 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6530 +
6531 + if (err)
6532 + break;
6533 +
6534 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6535 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6536 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6537 + {
6538 + unsigned int addr;
6539 +
6540 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6541 + addr = regs->u_regs[UREG_G1];
6542 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6543 + regs->pc = addr;
6544 + regs->npc = addr+4;
6545 + return 2;
6546 + }
6547 + } while (0);
6548 +
6549 + do { /* PaX: patched PLT emulation #2 */
6550 + unsigned int ba;
6551 +
6552 + err = get_user(ba, (unsigned int *)regs->pc);
6553 +
6554 + if (err)
6555 + break;
6556 +
6557 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6558 + unsigned int addr;
6559 +
6560 + if ((ba & 0xFFC00000U) == 0x30800000U)
6561 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6562 + else
6563 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6564 + regs->pc = addr;
6565 + regs->npc = addr+4;
6566 + return 2;
6567 + }
6568 + } while (0);
6569 +
6570 + do { /* PaX: patched PLT emulation #3 */
6571 + unsigned int sethi, bajmpl, nop;
6572 +
6573 + err = get_user(sethi, (unsigned int *)regs->pc);
6574 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6575 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6576 +
6577 + if (err)
6578 + break;
6579 +
6580 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6581 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6582 + nop == 0x01000000U)
6583 + {
6584 + unsigned int addr;
6585 +
6586 + addr = (sethi & 0x003FFFFFU) << 10;
6587 + regs->u_regs[UREG_G1] = addr;
6588 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6589 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6590 + else
6591 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6592 + regs->pc = addr;
6593 + regs->npc = addr+4;
6594 + return 2;
6595 + }
6596 + } while (0);
6597 +
6598 + do { /* PaX: unpatched PLT emulation step 1 */
6599 + unsigned int sethi, ba, nop;
6600 +
6601 + err = get_user(sethi, (unsigned int *)regs->pc);
6602 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6603 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6604 +
6605 + if (err)
6606 + break;
6607 +
6608 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6609 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6610 + nop == 0x01000000U)
6611 + {
6612 + unsigned int addr, save, call;
6613 +
6614 + if ((ba & 0xFFC00000U) == 0x30800000U)
6615 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6616 + else
6617 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6618 +
6619 + err = get_user(save, (unsigned int *)addr);
6620 + err |= get_user(call, (unsigned int *)(addr+4));
6621 + err |= get_user(nop, (unsigned int *)(addr+8));
6622 + if (err)
6623 + break;
6624 +
6625 +#ifdef CONFIG_PAX_DLRESOLVE
6626 + if (save == 0x9DE3BFA8U &&
6627 + (call & 0xC0000000U) == 0x40000000U &&
6628 + nop == 0x01000000U)
6629 + {
6630 + struct vm_area_struct *vma;
6631 + unsigned long call_dl_resolve;
6632 +
6633 + down_read(&current->mm->mmap_sem);
6634 + call_dl_resolve = current->mm->call_dl_resolve;
6635 + up_read(&current->mm->mmap_sem);
6636 + if (likely(call_dl_resolve))
6637 + goto emulate;
6638 +
6639 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6640 +
6641 + down_write(&current->mm->mmap_sem);
6642 + if (current->mm->call_dl_resolve) {
6643 + call_dl_resolve = current->mm->call_dl_resolve;
6644 + up_write(&current->mm->mmap_sem);
6645 + if (vma)
6646 + kmem_cache_free(vm_area_cachep, vma);
6647 + goto emulate;
6648 + }
6649 +
6650 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6651 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6652 + up_write(&current->mm->mmap_sem);
6653 + if (vma)
6654 + kmem_cache_free(vm_area_cachep, vma);
6655 + return 1;
6656 + }
6657 +
6658 + if (pax_insert_vma(vma, call_dl_resolve)) {
6659 + up_write(&current->mm->mmap_sem);
6660 + kmem_cache_free(vm_area_cachep, vma);
6661 + return 1;
6662 + }
6663 +
6664 + current->mm->call_dl_resolve = call_dl_resolve;
6665 + up_write(&current->mm->mmap_sem);
6666 +
6667 +emulate:
6668 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6669 + regs->pc = call_dl_resolve;
6670 + regs->npc = addr+4;
6671 + return 3;
6672 + }
6673 +#endif
6674 +
6675 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6676 + if ((save & 0xFFC00000U) == 0x05000000U &&
6677 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6678 + nop == 0x01000000U)
6679 + {
6680 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6681 + regs->u_regs[UREG_G2] = addr + 4;
6682 + addr = (save & 0x003FFFFFU) << 10;
6683 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6684 + regs->pc = addr;
6685 + regs->npc = addr+4;
6686 + return 3;
6687 + }
6688 + }
6689 + } while (0);
6690 +
6691 + do { /* PaX: unpatched PLT emulation step 2 */
6692 + unsigned int save, call, nop;
6693 +
6694 + err = get_user(save, (unsigned int *)(regs->pc-4));
6695 + err |= get_user(call, (unsigned int *)regs->pc);
6696 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6697 + if (err)
6698 + break;
6699 +
6700 + if (save == 0x9DE3BFA8U &&
6701 + (call & 0xC0000000U) == 0x40000000U &&
6702 + nop == 0x01000000U)
6703 + {
6704 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6705 +
6706 + regs->u_regs[UREG_RETPC] = regs->pc;
6707 + regs->pc = dl_resolve;
6708 + regs->npc = dl_resolve+4;
6709 + return 3;
6710 + }
6711 + } while (0);
6712 +#endif
6713 +
6714 + return 1;
6715 +}
6716 +
6717 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6718 +{
6719 + unsigned long i;
6720 +
6721 + printk(KERN_ERR "PAX: bytes at PC: ");
6722 + for (i = 0; i < 8; i++) {
6723 + unsigned int c;
6724 + if (get_user(c, (unsigned int *)pc+i))
6725 + printk(KERN_CONT "???????? ");
6726 + else
6727 + printk(KERN_CONT "%08x ", c);
6728 + }
6729 + printk("\n");
6730 +}
6731 +#endif
6732 +
6733 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6734 int text_fault)
6735 {
6736 @@ -230,6 +504,24 @@ good_area:
6737 if (!(vma->vm_flags & VM_WRITE))
6738 goto bad_area;
6739 } else {
6740 +
6741 +#ifdef CONFIG_PAX_PAGEEXEC
6742 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6743 + up_read(&mm->mmap_sem);
6744 + switch (pax_handle_fetch_fault(regs)) {
6745 +
6746 +#ifdef CONFIG_PAX_EMUPLT
6747 + case 2:
6748 + case 3:
6749 + return;
6750 +#endif
6751 +
6752 + }
6753 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6754 + do_group_exit(SIGKILL);
6755 + }
6756 +#endif
6757 +
6758 /* Allow reads even for write-only mappings */
6759 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6760 goto bad_area;
6761 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6762 index 097aee7..5ca6697 100644
6763 --- a/arch/sparc/mm/fault_64.c
6764 +++ b/arch/sparc/mm/fault_64.c
6765 @@ -21,6 +21,9 @@
6766 #include <linux/kprobes.h>
6767 #include <linux/kdebug.h>
6768 #include <linux/percpu.h>
6769 +#include <linux/slab.h>
6770 +#include <linux/pagemap.h>
6771 +#include <linux/compiler.h>
6772
6773 #include <asm/page.h>
6774 #include <asm/pgtable.h>
6775 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6776 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6777 regs->tpc);
6778 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6779 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6780 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6781 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6782 dump_stack();
6783 unhandled_fault(regs->tpc, current, regs);
6784 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6785 show_regs(regs);
6786 }
6787
6788 +#ifdef CONFIG_PAX_PAGEEXEC
6789 +#ifdef CONFIG_PAX_DLRESOLVE
6790 +static void pax_emuplt_close(struct vm_area_struct *vma)
6791 +{
6792 + vma->vm_mm->call_dl_resolve = 0UL;
6793 +}
6794 +
6795 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6796 +{
6797 + unsigned int *kaddr;
6798 +
6799 + vmf->page = alloc_page(GFP_HIGHUSER);
6800 + if (!vmf->page)
6801 + return VM_FAULT_OOM;
6802 +
6803 + kaddr = kmap(vmf->page);
6804 + memset(kaddr, 0, PAGE_SIZE);
6805 + kaddr[0] = 0x9DE3BFA8U; /* save */
6806 + flush_dcache_page(vmf->page);
6807 + kunmap(vmf->page);
6808 + return VM_FAULT_MAJOR;
6809 +}
6810 +
6811 +static const struct vm_operations_struct pax_vm_ops = {
6812 + .close = pax_emuplt_close,
6813 + .fault = pax_emuplt_fault
6814 +};
6815 +
6816 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6817 +{
6818 + int ret;
6819 +
6820 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6821 + vma->vm_mm = current->mm;
6822 + vma->vm_start = addr;
6823 + vma->vm_end = addr + PAGE_SIZE;
6824 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6825 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6826 + vma->vm_ops = &pax_vm_ops;
6827 +
6828 + ret = insert_vm_struct(current->mm, vma);
6829 + if (ret)
6830 + return ret;
6831 +
6832 + ++current->mm->total_vm;
6833 + return 0;
6834 +}
6835 +#endif
6836 +
6837 +/*
6838 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6839 + *
6840 + * returns 1 when task should be killed
6841 + * 2 when patched PLT trampoline was detected
6842 + * 3 when unpatched PLT trampoline was detected
6843 + */
6844 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6845 +{
6846 +
6847 +#ifdef CONFIG_PAX_EMUPLT
6848 + int err;
6849 +
6850 + do { /* PaX: patched PLT emulation #1 */
6851 + unsigned int sethi1, sethi2, jmpl;
6852 +
6853 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6854 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6855 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6856 +
6857 + if (err)
6858 + break;
6859 +
6860 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6861 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6862 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6863 + {
6864 + unsigned long addr;
6865 +
6866 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6867 + addr = regs->u_regs[UREG_G1];
6868 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6869 +
6870 + if (test_thread_flag(TIF_32BIT))
6871 + addr &= 0xFFFFFFFFUL;
6872 +
6873 + regs->tpc = addr;
6874 + regs->tnpc = addr+4;
6875 + return 2;
6876 + }
6877 + } while (0);
6878 +
6879 + do { /* PaX: patched PLT emulation #2 */
6880 + unsigned int ba;
6881 +
6882 + err = get_user(ba, (unsigned int *)regs->tpc);
6883 +
6884 + if (err)
6885 + break;
6886 +
6887 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6888 + unsigned long addr;
6889 +
6890 + if ((ba & 0xFFC00000U) == 0x30800000U)
6891 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6892 + else
6893 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6894 +
6895 + if (test_thread_flag(TIF_32BIT))
6896 + addr &= 0xFFFFFFFFUL;
6897 +
6898 + regs->tpc = addr;
6899 + regs->tnpc = addr+4;
6900 + return 2;
6901 + }
6902 + } while (0);
6903 +
6904 + do { /* PaX: patched PLT emulation #3 */
6905 + unsigned int sethi, bajmpl, nop;
6906 +
6907 + err = get_user(sethi, (unsigned int *)regs->tpc);
6908 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6909 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6910 +
6911 + if (err)
6912 + break;
6913 +
6914 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6915 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6916 + nop == 0x01000000U)
6917 + {
6918 + unsigned long addr;
6919 +
6920 + addr = (sethi & 0x003FFFFFU) << 10;
6921 + regs->u_regs[UREG_G1] = addr;
6922 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6923 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6924 + else
6925 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6926 +
6927 + if (test_thread_flag(TIF_32BIT))
6928 + addr &= 0xFFFFFFFFUL;
6929 +
6930 + regs->tpc = addr;
6931 + regs->tnpc = addr+4;
6932 + return 2;
6933 + }
6934 + } while (0);
6935 +
6936 + do { /* PaX: patched PLT emulation #4 */
6937 + unsigned int sethi, mov1, call, mov2;
6938 +
6939 + err = get_user(sethi, (unsigned int *)regs->tpc);
6940 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6941 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6942 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6943 +
6944 + if (err)
6945 + break;
6946 +
6947 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6948 + mov1 == 0x8210000FU &&
6949 + (call & 0xC0000000U) == 0x40000000U &&
6950 + mov2 == 0x9E100001U)
6951 + {
6952 + unsigned long addr;
6953 +
6954 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6955 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6956 +
6957 + if (test_thread_flag(TIF_32BIT))
6958 + addr &= 0xFFFFFFFFUL;
6959 +
6960 + regs->tpc = addr;
6961 + regs->tnpc = addr+4;
6962 + return 2;
6963 + }
6964 + } while (0);
6965 +
6966 + do { /* PaX: patched PLT emulation #5 */
6967 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6968 +
6969 + err = get_user(sethi, (unsigned int *)regs->tpc);
6970 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6971 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6972 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6973 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6974 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6975 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6976 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6977 +
6978 + if (err)
6979 + break;
6980 +
6981 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6982 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6983 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6984 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6985 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6986 + sllx == 0x83287020U &&
6987 + jmpl == 0x81C04005U &&
6988 + nop == 0x01000000U)
6989 + {
6990 + unsigned long addr;
6991 +
6992 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6993 + regs->u_regs[UREG_G1] <<= 32;
6994 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6995 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6996 + regs->tpc = addr;
6997 + regs->tnpc = addr+4;
6998 + return 2;
6999 + }
7000 + } while (0);
7001 +
7002 + do { /* PaX: patched PLT emulation #6 */
7003 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7004 +
7005 + err = get_user(sethi, (unsigned int *)regs->tpc);
7006 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7007 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7008 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7009 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7010 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7011 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7012 +
7013 + if (err)
7014 + break;
7015 +
7016 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7017 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7018 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7019 + sllx == 0x83287020U &&
7020 + (or & 0xFFFFE000U) == 0x8A116000U &&
7021 + jmpl == 0x81C04005U &&
7022 + nop == 0x01000000U)
7023 + {
7024 + unsigned long addr;
7025 +
7026 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7027 + regs->u_regs[UREG_G1] <<= 32;
7028 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7029 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7030 + regs->tpc = addr;
7031 + regs->tnpc = addr+4;
7032 + return 2;
7033 + }
7034 + } while (0);
7035 +
7036 + do { /* PaX: unpatched PLT emulation step 1 */
7037 + unsigned int sethi, ba, nop;
7038 +
7039 + err = get_user(sethi, (unsigned int *)regs->tpc);
7040 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7041 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7042 +
7043 + if (err)
7044 + break;
7045 +
7046 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7047 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7048 + nop == 0x01000000U)
7049 + {
7050 + unsigned long addr;
7051 + unsigned int save, call;
7052 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7053 +
7054 + if ((ba & 0xFFC00000U) == 0x30800000U)
7055 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7056 + else
7057 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7058 +
7059 + if (test_thread_flag(TIF_32BIT))
7060 + addr &= 0xFFFFFFFFUL;
7061 +
7062 + err = get_user(save, (unsigned int *)addr);
7063 + err |= get_user(call, (unsigned int *)(addr+4));
7064 + err |= get_user(nop, (unsigned int *)(addr+8));
7065 + if (err)
7066 + break;
7067 +
7068 +#ifdef CONFIG_PAX_DLRESOLVE
7069 + if (save == 0x9DE3BFA8U &&
7070 + (call & 0xC0000000U) == 0x40000000U &&
7071 + nop == 0x01000000U)
7072 + {
7073 + struct vm_area_struct *vma;
7074 + unsigned long call_dl_resolve;
7075 +
7076 + down_read(&current->mm->mmap_sem);
7077 + call_dl_resolve = current->mm->call_dl_resolve;
7078 + up_read(&current->mm->mmap_sem);
7079 + if (likely(call_dl_resolve))
7080 + goto emulate;
7081 +
7082 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7083 +
7084 + down_write(&current->mm->mmap_sem);
7085 + if (current->mm->call_dl_resolve) {
7086 + call_dl_resolve = current->mm->call_dl_resolve;
7087 + up_write(&current->mm->mmap_sem);
7088 + if (vma)
7089 + kmem_cache_free(vm_area_cachep, vma);
7090 + goto emulate;
7091 + }
7092 +
7093 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7094 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7095 + up_write(&current->mm->mmap_sem);
7096 + if (vma)
7097 + kmem_cache_free(vm_area_cachep, vma);
7098 + return 1;
7099 + }
7100 +
7101 + if (pax_insert_vma(vma, call_dl_resolve)) {
7102 + up_write(&current->mm->mmap_sem);
7103 + kmem_cache_free(vm_area_cachep, vma);
7104 + return 1;
7105 + }
7106 +
7107 + current->mm->call_dl_resolve = call_dl_resolve;
7108 + up_write(&current->mm->mmap_sem);
7109 +
7110 +emulate:
7111 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7112 + regs->tpc = call_dl_resolve;
7113 + regs->tnpc = addr+4;
7114 + return 3;
7115 + }
7116 +#endif
7117 +
7118 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7119 + if ((save & 0xFFC00000U) == 0x05000000U &&
7120 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7121 + nop == 0x01000000U)
7122 + {
7123 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7124 + regs->u_regs[UREG_G2] = addr + 4;
7125 + addr = (save & 0x003FFFFFU) << 10;
7126 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7127 +
7128 + if (test_thread_flag(TIF_32BIT))
7129 + addr &= 0xFFFFFFFFUL;
7130 +
7131 + regs->tpc = addr;
7132 + regs->tnpc = addr+4;
7133 + return 3;
7134 + }
7135 +
7136 + /* PaX: 64-bit PLT stub */
7137 + err = get_user(sethi1, (unsigned int *)addr);
7138 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7139 + err |= get_user(or1, (unsigned int *)(addr+8));
7140 + err |= get_user(or2, (unsigned int *)(addr+12));
7141 + err |= get_user(sllx, (unsigned int *)(addr+16));
7142 + err |= get_user(add, (unsigned int *)(addr+20));
7143 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7144 + err |= get_user(nop, (unsigned int *)(addr+28));
7145 + if (err)
7146 + break;
7147 +
7148 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7149 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7150 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7151 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7152 + sllx == 0x89293020U &&
7153 + add == 0x8A010005U &&
7154 + jmpl == 0x89C14000U &&
7155 + nop == 0x01000000U)
7156 + {
7157 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7158 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7159 + regs->u_regs[UREG_G4] <<= 32;
7160 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7161 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7162 + regs->u_regs[UREG_G4] = addr + 24;
7163 + addr = regs->u_regs[UREG_G5];
7164 + regs->tpc = addr;
7165 + regs->tnpc = addr+4;
7166 + return 3;
7167 + }
7168 + }
7169 + } while (0);
7170 +
7171 +#ifdef CONFIG_PAX_DLRESOLVE
7172 + do { /* PaX: unpatched PLT emulation step 2 */
7173 + unsigned int save, call, nop;
7174 +
7175 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7176 + err |= get_user(call, (unsigned int *)regs->tpc);
7177 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7178 + if (err)
7179 + break;
7180 +
7181 + if (save == 0x9DE3BFA8U &&
7182 + (call & 0xC0000000U) == 0x40000000U &&
7183 + nop == 0x01000000U)
7184 + {
7185 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7186 +
7187 + if (test_thread_flag(TIF_32BIT))
7188 + dl_resolve &= 0xFFFFFFFFUL;
7189 +
7190 + regs->u_regs[UREG_RETPC] = regs->tpc;
7191 + regs->tpc = dl_resolve;
7192 + regs->tnpc = dl_resolve+4;
7193 + return 3;
7194 + }
7195 + } while (0);
7196 +#endif
7197 +
7198 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7199 + unsigned int sethi, ba, nop;
7200 +
7201 + err = get_user(sethi, (unsigned int *)regs->tpc);
7202 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7203 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7204 +
7205 + if (err)
7206 + break;
7207 +
7208 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7209 + (ba & 0xFFF00000U) == 0x30600000U &&
7210 + nop == 0x01000000U)
7211 + {
7212 + unsigned long addr;
7213 +
7214 + addr = (sethi & 0x003FFFFFU) << 10;
7215 + regs->u_regs[UREG_G1] = addr;
7216 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7217 +
7218 + if (test_thread_flag(TIF_32BIT))
7219 + addr &= 0xFFFFFFFFUL;
7220 +
7221 + regs->tpc = addr;
7222 + regs->tnpc = addr+4;
7223 + return 2;
7224 + }
7225 + } while (0);
7226 +
7227 +#endif
7228 +
7229 + return 1;
7230 +}
7231 +
7232 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7233 +{
7234 + unsigned long i;
7235 +
7236 + printk(KERN_ERR "PAX: bytes at PC: ");
7237 + for (i = 0; i < 8; i++) {
7238 + unsigned int c;
7239 + if (get_user(c, (unsigned int *)pc+i))
7240 + printk(KERN_CONT "???????? ");
7241 + else
7242 + printk(KERN_CONT "%08x ", c);
7243 + }
7244 + printk("\n");
7245 +}
7246 +#endif
7247 +
7248 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7249 {
7250 struct mm_struct *mm = current->mm;
7251 @@ -341,6 +804,29 @@ retry:
7252 if (!vma)
7253 goto bad_area;
7254
7255 +#ifdef CONFIG_PAX_PAGEEXEC
7256 + /* PaX: detect ITLB misses on non-exec pages */
7257 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7258 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7259 + {
7260 + if (address != regs->tpc)
7261 + goto good_area;
7262 +
7263 + up_read(&mm->mmap_sem);
7264 + switch (pax_handle_fetch_fault(regs)) {
7265 +
7266 +#ifdef CONFIG_PAX_EMUPLT
7267 + case 2:
7268 + case 3:
7269 + return;
7270 +#endif
7271 +
7272 + }
7273 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7274 + do_group_exit(SIGKILL);
7275 + }
7276 +#endif
7277 +
7278 /* Pure DTLB misses do not tell us whether the fault causing
7279 * load/store/atomic was a write or not, it only says that there
7280 * was no match. So in such a case we (carefully) read the
7281 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7282 index f76f83d..0f28457 100644
7283 --- a/arch/sparc/mm/hugetlbpage.c
7284 +++ b/arch/sparc/mm/hugetlbpage.c
7285 @@ -67,7 +67,7 @@ full_search:
7286 }
7287 return -ENOMEM;
7288 }
7289 - if (likely(!vma || addr + len <= vma->vm_start)) {
7290 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7291 /*
7292 * Remember the place where we stopped the search:
7293 */
7294 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7295 /* make sure it can fit in the remaining address space */
7296 if (likely(addr > len)) {
7297 vma = find_vma(mm, addr-len);
7298 - if (!vma || addr <= vma->vm_start) {
7299 + if (check_heap_stack_gap(vma, addr - len, len)) {
7300 /* remember the address as a hint for next time */
7301 return (mm->free_area_cache = addr-len);
7302 }
7303 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7304 if (unlikely(mm->mmap_base < len))
7305 goto bottomup;
7306
7307 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7308 + addr = mm->mmap_base - len;
7309
7310 do {
7311 + addr &= HPAGE_MASK;
7312 /*
7313 * Lookup failure means no vma is above this address,
7314 * else if new region fits below vma->vm_start,
7315 * return with success:
7316 */
7317 vma = find_vma(mm, addr);
7318 - if (likely(!vma || addr+len <= vma->vm_start)) {
7319 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7320 /* remember the address as a hint for next time */
7321 return (mm->free_area_cache = addr);
7322 }
7323 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7324 mm->cached_hole_size = vma->vm_start - addr;
7325
7326 /* try just below the current vma->vm_start */
7327 - addr = (vma->vm_start-len) & HPAGE_MASK;
7328 - } while (likely(len < vma->vm_start));
7329 + addr = skip_heap_stack_gap(vma, len);
7330 + } while (!IS_ERR_VALUE(addr));
7331
7332 bottomup:
7333 /*
7334 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7335 if (addr) {
7336 addr = ALIGN(addr, HPAGE_SIZE);
7337 vma = find_vma(mm, addr);
7338 - if (task_size - len >= addr &&
7339 - (!vma || addr + len <= vma->vm_start))
7340 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7341 return addr;
7342 }
7343 if (mm->get_unmapped_area == arch_get_unmapped_area)
7344 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7345 index f4500c6..889656c 100644
7346 --- a/arch/tile/include/asm/atomic_64.h
7347 +++ b/arch/tile/include/asm/atomic_64.h
7348 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7349
7350 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7351
7352 +#define atomic64_read_unchecked(v) atomic64_read(v)
7353 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7354 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7355 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7356 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7357 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7358 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7359 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7360 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7361 +
7362 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7363 #define smp_mb__before_atomic_dec() smp_mb()
7364 #define smp_mb__after_atomic_dec() smp_mb()
7365 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7366 index a9a5299..0fce79e 100644
7367 --- a/arch/tile/include/asm/cache.h
7368 +++ b/arch/tile/include/asm/cache.h
7369 @@ -15,11 +15,12 @@
7370 #ifndef _ASM_TILE_CACHE_H
7371 #define _ASM_TILE_CACHE_H
7372
7373 +#include <linux/const.h>
7374 #include <arch/chip.h>
7375
7376 /* bytes per L1 data cache line */
7377 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7378 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7379 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7380
7381 /* bytes per L2 cache line */
7382 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7383 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7384 index 9ab078a..d6635c2 100644
7385 --- a/arch/tile/include/asm/uaccess.h
7386 +++ b/arch/tile/include/asm/uaccess.h
7387 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7388 const void __user *from,
7389 unsigned long n)
7390 {
7391 - int sz = __compiletime_object_size(to);
7392 + size_t sz = __compiletime_object_size(to);
7393
7394 - if (likely(sz == -1 || sz >= n))
7395 + if (likely(sz == (size_t)-1 || sz >= n))
7396 n = _copy_from_user(to, from, n);
7397 else
7398 copy_from_user_overflow();
7399 diff --git a/arch/um/Makefile b/arch/um/Makefile
7400 index 133f7de..1d6f2f1 100644
7401 --- a/arch/um/Makefile
7402 +++ b/arch/um/Makefile
7403 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7404 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7405 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7406
7407 +ifdef CONSTIFY_PLUGIN
7408 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7409 +endif
7410 +
7411 #This will adjust *FLAGS accordingly to the platform.
7412 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7413
7414 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7415 index 19e1bdd..3665b77 100644
7416 --- a/arch/um/include/asm/cache.h
7417 +++ b/arch/um/include/asm/cache.h
7418 @@ -1,6 +1,7 @@
7419 #ifndef __UM_CACHE_H
7420 #define __UM_CACHE_H
7421
7422 +#include <linux/const.h>
7423
7424 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7425 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7426 @@ -12,6 +13,6 @@
7427 # define L1_CACHE_SHIFT 5
7428 #endif
7429
7430 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7431 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7432
7433 #endif
7434 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7435 index 2e0a6b1..a64d0f5 100644
7436 --- a/arch/um/include/asm/kmap_types.h
7437 +++ b/arch/um/include/asm/kmap_types.h
7438 @@ -8,6 +8,6 @@
7439
7440 /* No more #include "asm/arch/kmap_types.h" ! */
7441
7442 -#define KM_TYPE_NR 14
7443 +#define KM_TYPE_NR 15
7444
7445 #endif
7446 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7447 index 5ff53d9..5850cdf 100644
7448 --- a/arch/um/include/asm/page.h
7449 +++ b/arch/um/include/asm/page.h
7450 @@ -14,6 +14,9 @@
7451 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7452 #define PAGE_MASK (~(PAGE_SIZE-1))
7453
7454 +#define ktla_ktva(addr) (addr)
7455 +#define ktva_ktla(addr) (addr)
7456 +
7457 #ifndef __ASSEMBLY__
7458
7459 struct page;
7460 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7461 index 0032f92..cd151e0 100644
7462 --- a/arch/um/include/asm/pgtable-3level.h
7463 +++ b/arch/um/include/asm/pgtable-3level.h
7464 @@ -58,6 +58,7 @@
7465 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7466 #define pud_populate(mm, pud, pmd) \
7467 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7468 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7469
7470 #ifdef CONFIG_64BIT
7471 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7472 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7473 index b6d699c..df7ac1d 100644
7474 --- a/arch/um/kernel/process.c
7475 +++ b/arch/um/kernel/process.c
7476 @@ -387,22 +387,6 @@ int singlestepping(void * t)
7477 return 2;
7478 }
7479
7480 -/*
7481 - * Only x86 and x86_64 have an arch_align_stack().
7482 - * All other arches have "#define arch_align_stack(x) (x)"
7483 - * in their asm/system.h
7484 - * As this is included in UML from asm-um/system-generic.h,
7485 - * we can use it to behave as the subarch does.
7486 - */
7487 -#ifndef arch_align_stack
7488 -unsigned long arch_align_stack(unsigned long sp)
7489 -{
7490 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7491 - sp -= get_random_int() % 8192;
7492 - return sp & ~0xf;
7493 -}
7494 -#endif
7495 -
7496 unsigned long get_wchan(struct task_struct *p)
7497 {
7498 unsigned long stack_page, sp, ip;
7499 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7500 index ad8f795..2c7eec6 100644
7501 --- a/arch/unicore32/include/asm/cache.h
7502 +++ b/arch/unicore32/include/asm/cache.h
7503 @@ -12,8 +12,10 @@
7504 #ifndef __UNICORE_CACHE_H__
7505 #define __UNICORE_CACHE_H__
7506
7507 -#define L1_CACHE_SHIFT (5)
7508 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7509 +#include <linux/const.h>
7510 +
7511 +#define L1_CACHE_SHIFT 5
7512 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7513
7514 /*
7515 * Memory returned by kmalloc() may be used for DMA, so we must make
7516 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7517 index 46c3bff..c2286e7 100644
7518 --- a/arch/x86/Kconfig
7519 +++ b/arch/x86/Kconfig
7520 @@ -241,7 +241,7 @@ config X86_HT
7521
7522 config X86_32_LAZY_GS
7523 def_bool y
7524 - depends on X86_32 && !CC_STACKPROTECTOR
7525 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7526
7527 config ARCH_HWEIGHT_CFLAGS
7528 string
7529 @@ -1056,7 +1056,7 @@ choice
7530
7531 config NOHIGHMEM
7532 bool "off"
7533 - depends on !X86_NUMAQ
7534 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7535 ---help---
7536 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7537 However, the address space of 32-bit x86 processors is only 4
7538 @@ -1093,7 +1093,7 @@ config NOHIGHMEM
7539
7540 config HIGHMEM4G
7541 bool "4GB"
7542 - depends on !X86_NUMAQ
7543 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7544 ---help---
7545 Select this if you have a 32-bit processor and between 1 and 4
7546 gigabytes of physical RAM.
7547 @@ -1147,7 +1147,7 @@ config PAGE_OFFSET
7548 hex
7549 default 0xB0000000 if VMSPLIT_3G_OPT
7550 default 0x80000000 if VMSPLIT_2G
7551 - default 0x78000000 if VMSPLIT_2G_OPT
7552 + default 0x70000000 if VMSPLIT_2G_OPT
7553 default 0x40000000 if VMSPLIT_1G
7554 default 0xC0000000
7555 depends on X86_32
7556 @@ -1548,6 +1548,7 @@ config SECCOMP
7557
7558 config CC_STACKPROTECTOR
7559 bool "Enable -fstack-protector buffer overflow detection"
7560 + depends on X86_64 || !PAX_MEMORY_UDEREF
7561 ---help---
7562 This option turns on the -fstack-protector GCC feature. This
7563 feature puts, at the beginning of functions, a canary value on
7564 @@ -1605,6 +1606,7 @@ config KEXEC_JUMP
7565 config PHYSICAL_START
7566 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7567 default "0x1000000"
7568 + range 0x400000 0x40000000
7569 ---help---
7570 This gives the physical address where the kernel is loaded.
7571
7572 @@ -1668,6 +1670,7 @@ config X86_NEED_RELOCS
7573 config PHYSICAL_ALIGN
7574 hex "Alignment value to which kernel should be aligned" if X86_32
7575 default "0x1000000"
7576 + range 0x400000 0x1000000 if PAX_KERNEXEC
7577 range 0x2000 0x1000000
7578 ---help---
7579 This value puts the alignment restrictions on physical address
7580 @@ -1699,9 +1702,10 @@ config HOTPLUG_CPU
7581 Say N if you want to disable CPU hotplug.
7582
7583 config COMPAT_VDSO
7584 - def_bool y
7585 + def_bool n
7586 prompt "Compat VDSO support"
7587 depends on X86_32 || IA32_EMULATION
7588 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7589 ---help---
7590 Map the 32-bit VDSO to the predictable old-style address too.
7591
7592 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7593 index f3b86d0..17fd30f 100644
7594 --- a/arch/x86/Kconfig.cpu
7595 +++ b/arch/x86/Kconfig.cpu
7596 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7597
7598 config X86_F00F_BUG
7599 def_bool y
7600 - depends on M586MMX || M586TSC || M586 || M486 || M386
7601 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7602
7603 config X86_INVD_BUG
7604 def_bool y
7605 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7606
7607 config X86_ALIGNMENT_16
7608 def_bool y
7609 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7610 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7611
7612 config X86_INTEL_USERCOPY
7613 def_bool y
7614 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7615 # generates cmov.
7616 config X86_CMOV
7617 def_bool y
7618 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7619 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7620
7621 config X86_MINIMUM_CPU_FAMILY
7622 int
7623 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7624 index b322f12..652d0d9 100644
7625 --- a/arch/x86/Kconfig.debug
7626 +++ b/arch/x86/Kconfig.debug
7627 @@ -84,7 +84,7 @@ config X86_PTDUMP
7628 config DEBUG_RODATA
7629 bool "Write protect kernel read-only data structures"
7630 default y
7631 - depends on DEBUG_KERNEL
7632 + depends on DEBUG_KERNEL && BROKEN
7633 ---help---
7634 Mark the kernel read-only data as write-protected in the pagetables,
7635 in order to catch accidental (and incorrect) writes to such const
7636 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7637
7638 config DEBUG_SET_MODULE_RONX
7639 bool "Set loadable kernel module data as NX and text as RO"
7640 - depends on MODULES
7641 + depends on MODULES && BROKEN
7642 ---help---
7643 This option helps catch unintended modifications to loadable
7644 kernel module's text and read-only data. It also prevents execution
7645 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7646
7647 config DEBUG_STRICT_USER_COPY_CHECKS
7648 bool "Strict copy size checks"
7649 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7650 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7651 ---help---
7652 Enabling this option turns a certain set of sanity checks for user
7653 copy operations into compile time failures.
7654 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7655 index 05afcca..b6ecb51 100644
7656 --- a/arch/x86/Makefile
7657 +++ b/arch/x86/Makefile
7658 @@ -50,6 +50,7 @@ else
7659 UTS_MACHINE := x86_64
7660 CHECKFLAGS += -D__x86_64__ -m64
7661
7662 + biarch := $(call cc-option,-m64)
7663 KBUILD_AFLAGS += -m64
7664 KBUILD_CFLAGS += -m64
7665
7666 @@ -229,3 +230,12 @@ define archhelp
7667 echo ' FDARGS="..." arguments for the booted kernel'
7668 echo ' FDINITRD=file initrd for the booted kernel'
7669 endef
7670 +
7671 +define OLD_LD
7672 +
7673 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7674 +*** Please upgrade your binutils to 2.18 or newer
7675 +endef
7676 +
7677 +archprepare:
7678 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7679 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7680 index ccce0ed..fd9da25 100644
7681 --- a/arch/x86/boot/Makefile
7682 +++ b/arch/x86/boot/Makefile
7683 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7684 $(call cc-option, -fno-stack-protector) \
7685 $(call cc-option, -mpreferred-stack-boundary=2)
7686 KBUILD_CFLAGS += $(call cc-option, -m32)
7687 +ifdef CONSTIFY_PLUGIN
7688 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7689 +endif
7690 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7691 GCOV_PROFILE := n
7692
7693 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7694 index 878e4b9..20537ab 100644
7695 --- a/arch/x86/boot/bitops.h
7696 +++ b/arch/x86/boot/bitops.h
7697 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7698 u8 v;
7699 const u32 *p = (const u32 *)addr;
7700
7701 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7702 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7703 return v;
7704 }
7705
7706 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7707
7708 static inline void set_bit(int nr, void *addr)
7709 {
7710 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7711 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7712 }
7713
7714 #endif /* BOOT_BITOPS_H */
7715 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7716 index 18997e5..83d9c67 100644
7717 --- a/arch/x86/boot/boot.h
7718 +++ b/arch/x86/boot/boot.h
7719 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7720 static inline u16 ds(void)
7721 {
7722 u16 seg;
7723 - asm("movw %%ds,%0" : "=rm" (seg));
7724 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7725 return seg;
7726 }
7727
7728 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7729 static inline int memcmp(const void *s1, const void *s2, size_t len)
7730 {
7731 u8 diff;
7732 - asm("repe; cmpsb; setnz %0"
7733 + asm volatile("repe; cmpsb; setnz %0"
7734 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7735 return diff;
7736 }
7737 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7738 index 8a84501..b2d165f 100644
7739 --- a/arch/x86/boot/compressed/Makefile
7740 +++ b/arch/x86/boot/compressed/Makefile
7741 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7742 KBUILD_CFLAGS += $(cflags-y)
7743 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7744 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7745 +ifdef CONSTIFY_PLUGIN
7746 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7747 +endif
7748
7749 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7750 GCOV_PROFILE := n
7751 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7752 index e87b0ca..2bce457 100644
7753 --- a/arch/x86/boot/compressed/eboot.c
7754 +++ b/arch/x86/boot/compressed/eboot.c
7755 @@ -144,7 +144,6 @@ again:
7756 *addr = max_addr;
7757 }
7758
7759 -free_pool:
7760 efi_call_phys1(sys_table->boottime->free_pool, map);
7761
7762 fail:
7763 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7764 if (i == map_size / desc_size)
7765 status = EFI_NOT_FOUND;
7766
7767 -free_pool:
7768 efi_call_phys1(sys_table->boottime->free_pool, map);
7769 fail:
7770 return status;
7771 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7772 index aa4aaf1..6656f2f 100644
7773 --- a/arch/x86/boot/compressed/head_32.S
7774 +++ b/arch/x86/boot/compressed/head_32.S
7775 @@ -116,7 +116,7 @@ preferred_addr:
7776 notl %eax
7777 andl %eax, %ebx
7778 #else
7779 - movl $LOAD_PHYSICAL_ADDR, %ebx
7780 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7781 #endif
7782
7783 /* Target address to relocate to for decompression */
7784 @@ -202,7 +202,7 @@ relocated:
7785 * and where it was actually loaded.
7786 */
7787 movl %ebp, %ebx
7788 - subl $LOAD_PHYSICAL_ADDR, %ebx
7789 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7790 jz 2f /* Nothing to be done if loaded at compiled addr. */
7791 /*
7792 * Process relocations.
7793 @@ -210,8 +210,7 @@ relocated:
7794
7795 1: subl $4, %edi
7796 movl (%edi), %ecx
7797 - testl %ecx, %ecx
7798 - jz 2f
7799 + jecxz 2f
7800 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7801 jmp 1b
7802 2:
7803 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7804 index 2c4b171..e1fa5b1 100644
7805 --- a/arch/x86/boot/compressed/head_64.S
7806 +++ b/arch/x86/boot/compressed/head_64.S
7807 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7808 notl %eax
7809 andl %eax, %ebx
7810 #else
7811 - movl $LOAD_PHYSICAL_ADDR, %ebx
7812 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7813 #endif
7814
7815 /* Target address to relocate to for decompression */
7816 @@ -273,7 +273,7 @@ preferred_addr:
7817 notq %rax
7818 andq %rax, %rbp
7819 #else
7820 - movq $LOAD_PHYSICAL_ADDR, %rbp
7821 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7822 #endif
7823
7824 /* Target address to relocate to for decompression */
7825 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7826 index 88f7ff6..ed695dd 100644
7827 --- a/arch/x86/boot/compressed/misc.c
7828 +++ b/arch/x86/boot/compressed/misc.c
7829 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7830 case PT_LOAD:
7831 #ifdef CONFIG_RELOCATABLE
7832 dest = output;
7833 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7834 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7835 #else
7836 dest = (void *)(phdr->p_paddr);
7837 #endif
7838 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7839 error("Destination address too large");
7840 #endif
7841 #ifndef CONFIG_RELOCATABLE
7842 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7843 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7844 error("Wrong destination address");
7845 #endif
7846
7847 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7848 index 4d3ff03..e4972ff 100644
7849 --- a/arch/x86/boot/cpucheck.c
7850 +++ b/arch/x86/boot/cpucheck.c
7851 @@ -74,7 +74,7 @@ static int has_fpu(void)
7852 u16 fcw = -1, fsw = -1;
7853 u32 cr0;
7854
7855 - asm("movl %%cr0,%0" : "=r" (cr0));
7856 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7857 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7858 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7859 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7860 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7861 {
7862 u32 f0, f1;
7863
7864 - asm("pushfl ; "
7865 + asm volatile("pushfl ; "
7866 "pushfl ; "
7867 "popl %0 ; "
7868 "movl %0,%1 ; "
7869 @@ -115,7 +115,7 @@ static void get_flags(void)
7870 set_bit(X86_FEATURE_FPU, cpu.flags);
7871
7872 if (has_eflag(X86_EFLAGS_ID)) {
7873 - asm("cpuid"
7874 + asm volatile("cpuid"
7875 : "=a" (max_intel_level),
7876 "=b" (cpu_vendor[0]),
7877 "=d" (cpu_vendor[1]),
7878 @@ -124,7 +124,7 @@ static void get_flags(void)
7879
7880 if (max_intel_level >= 0x00000001 &&
7881 max_intel_level <= 0x0000ffff) {
7882 - asm("cpuid"
7883 + asm volatile("cpuid"
7884 : "=a" (tfms),
7885 "=c" (cpu.flags[4]),
7886 "=d" (cpu.flags[0])
7887 @@ -136,7 +136,7 @@ static void get_flags(void)
7888 cpu.model += ((tfms >> 16) & 0xf) << 4;
7889 }
7890
7891 - asm("cpuid"
7892 + asm volatile("cpuid"
7893 : "=a" (max_amd_level)
7894 : "a" (0x80000000)
7895 : "ebx", "ecx", "edx");
7896 @@ -144,7 +144,7 @@ static void get_flags(void)
7897 if (max_amd_level >= 0x80000001 &&
7898 max_amd_level <= 0x8000ffff) {
7899 u32 eax = 0x80000001;
7900 - asm("cpuid"
7901 + asm volatile("cpuid"
7902 : "+a" (eax),
7903 "=c" (cpu.flags[6]),
7904 "=d" (cpu.flags[1])
7905 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7906 u32 ecx = MSR_K7_HWCR;
7907 u32 eax, edx;
7908
7909 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7910 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7911 eax &= ~(1 << 15);
7912 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7913 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7914
7915 get_flags(); /* Make sure it really did something */
7916 err = check_flags();
7917 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7918 u32 ecx = MSR_VIA_FCR;
7919 u32 eax, edx;
7920
7921 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7922 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7923 eax |= (1<<1)|(1<<7);
7924 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7925 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7926
7927 set_bit(X86_FEATURE_CX8, cpu.flags);
7928 err = check_flags();
7929 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7930 u32 eax, edx;
7931 u32 level = 1;
7932
7933 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7934 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7935 - asm("cpuid"
7936 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7937 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7938 + asm volatile("cpuid"
7939 : "+a" (level), "=d" (cpu.flags[0])
7940 : : "ecx", "ebx");
7941 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7942 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7943
7944 err = check_flags();
7945 }
7946 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7947 index 8c132a6..13e5c96 100644
7948 --- a/arch/x86/boot/header.S
7949 +++ b/arch/x86/boot/header.S
7950 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7951 # single linked list of
7952 # struct setup_data
7953
7954 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7955 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7956
7957 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7958 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7959 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7960 +#else
7961 #define VO_INIT_SIZE (VO__end - VO__text)
7962 +#endif
7963 #if ZO_INIT_SIZE > VO_INIT_SIZE
7964 #define INIT_SIZE ZO_INIT_SIZE
7965 #else
7966 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7967 index db75d07..8e6d0af 100644
7968 --- a/arch/x86/boot/memory.c
7969 +++ b/arch/x86/boot/memory.c
7970 @@ -19,7 +19,7 @@
7971
7972 static int detect_memory_e820(void)
7973 {
7974 - int count = 0;
7975 + unsigned int count = 0;
7976 struct biosregs ireg, oreg;
7977 struct e820entry *desc = boot_params.e820_map;
7978 static struct e820entry buf; /* static so it is zeroed */
7979 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7980 index 11e8c6e..fdbb1ed 100644
7981 --- a/arch/x86/boot/video-vesa.c
7982 +++ b/arch/x86/boot/video-vesa.c
7983 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7984
7985 boot_params.screen_info.vesapm_seg = oreg.es;
7986 boot_params.screen_info.vesapm_off = oreg.di;
7987 + boot_params.screen_info.vesapm_size = oreg.cx;
7988 }
7989
7990 /*
7991 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7992 index 43eda28..5ab5fdb 100644
7993 --- a/arch/x86/boot/video.c
7994 +++ b/arch/x86/boot/video.c
7995 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7996 static unsigned int get_entry(void)
7997 {
7998 char entry_buf[4];
7999 - int i, len = 0;
8000 + unsigned int i, len = 0;
8001 int key;
8002 unsigned int v;
8003
8004 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8005 index 5b577d5..3c1fed4 100644
8006 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8007 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8008 @@ -8,6 +8,8 @@
8009 * including this sentence is retained in full.
8010 */
8011
8012 +#include <asm/alternative-asm.h>
8013 +
8014 .extern crypto_ft_tab
8015 .extern crypto_it_tab
8016 .extern crypto_fl_tab
8017 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8018 je B192; \
8019 leaq 32(r9),r9;
8020
8021 +#define ret pax_force_retaddr 0, 1; ret
8022 +
8023 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8024 movq r1,r2; \
8025 movq r3,r4; \
8026 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8027 index 3470624..201259d 100644
8028 --- a/arch/x86/crypto/aesni-intel_asm.S
8029 +++ b/arch/x86/crypto/aesni-intel_asm.S
8030 @@ -31,6 +31,7 @@
8031
8032 #include <linux/linkage.h>
8033 #include <asm/inst.h>
8034 +#include <asm/alternative-asm.h>
8035
8036 #ifdef __x86_64__
8037 .data
8038 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8039 pop %r14
8040 pop %r13
8041 pop %r12
8042 + pax_force_retaddr 0, 1
8043 ret
8044 +ENDPROC(aesni_gcm_dec)
8045
8046
8047 /*****************************************************************************
8048 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8049 pop %r14
8050 pop %r13
8051 pop %r12
8052 + pax_force_retaddr 0, 1
8053 ret
8054 +ENDPROC(aesni_gcm_enc)
8055
8056 #endif
8057
8058 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8059 pxor %xmm1, %xmm0
8060 movaps %xmm0, (TKEYP)
8061 add $0x10, TKEYP
8062 + pax_force_retaddr_bts
8063 ret
8064
8065 .align 4
8066 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8067 shufps $0b01001110, %xmm2, %xmm1
8068 movaps %xmm1, 0x10(TKEYP)
8069 add $0x20, TKEYP
8070 + pax_force_retaddr_bts
8071 ret
8072
8073 .align 4
8074 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8075
8076 movaps %xmm0, (TKEYP)
8077 add $0x10, TKEYP
8078 + pax_force_retaddr_bts
8079 ret
8080
8081 .align 4
8082 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8083 pxor %xmm1, %xmm2
8084 movaps %xmm2, (TKEYP)
8085 add $0x10, TKEYP
8086 + pax_force_retaddr_bts
8087 ret
8088
8089 /*
8090 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8091 #ifndef __x86_64__
8092 popl KEYP
8093 #endif
8094 + pax_force_retaddr 0, 1
8095 ret
8096 +ENDPROC(aesni_set_key)
8097
8098 /*
8099 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8100 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8101 popl KLEN
8102 popl KEYP
8103 #endif
8104 + pax_force_retaddr 0, 1
8105 ret
8106 +ENDPROC(aesni_enc)
8107
8108 /*
8109 * _aesni_enc1: internal ABI
8110 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8111 AESENC KEY STATE
8112 movaps 0x70(TKEYP), KEY
8113 AESENCLAST KEY STATE
8114 + pax_force_retaddr_bts
8115 ret
8116
8117 /*
8118 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8119 AESENCLAST KEY STATE2
8120 AESENCLAST KEY STATE3
8121 AESENCLAST KEY STATE4
8122 + pax_force_retaddr_bts
8123 ret
8124
8125 /*
8126 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8127 popl KLEN
8128 popl KEYP
8129 #endif
8130 + pax_force_retaddr 0, 1
8131 ret
8132 +ENDPROC(aesni_dec)
8133
8134 /*
8135 * _aesni_dec1: internal ABI
8136 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8137 AESDEC KEY STATE
8138 movaps 0x70(TKEYP), KEY
8139 AESDECLAST KEY STATE
8140 + pax_force_retaddr_bts
8141 ret
8142
8143 /*
8144 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8145 AESDECLAST KEY STATE2
8146 AESDECLAST KEY STATE3
8147 AESDECLAST KEY STATE4
8148 + pax_force_retaddr_bts
8149 ret
8150
8151 /*
8152 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8153 popl KEYP
8154 popl LEN
8155 #endif
8156 + pax_force_retaddr 0, 1
8157 ret
8158 +ENDPROC(aesni_ecb_enc)
8159
8160 /*
8161 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8162 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8163 popl KEYP
8164 popl LEN
8165 #endif
8166 + pax_force_retaddr 0, 1
8167 ret
8168 +ENDPROC(aesni_ecb_dec)
8169
8170 /*
8171 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8172 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8173 popl LEN
8174 popl IVP
8175 #endif
8176 + pax_force_retaddr 0, 1
8177 ret
8178 +ENDPROC(aesni_cbc_enc)
8179
8180 /*
8181 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8182 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8183 popl LEN
8184 popl IVP
8185 #endif
8186 + pax_force_retaddr 0, 1
8187 ret
8188 +ENDPROC(aesni_cbc_dec)
8189
8190 #ifdef __x86_64__
8191 .align 16
8192 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8193 mov $1, TCTR_LOW
8194 MOVQ_R64_XMM TCTR_LOW INC
8195 MOVQ_R64_XMM CTR TCTR_LOW
8196 + pax_force_retaddr_bts
8197 ret
8198
8199 /*
8200 @@ -2554,6 +2582,7 @@ _aesni_inc:
8201 .Linc_low:
8202 movaps CTR, IV
8203 PSHUFB_XMM BSWAP_MASK IV
8204 + pax_force_retaddr_bts
8205 ret
8206
8207 /*
8208 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8209 .Lctr_enc_ret:
8210 movups IV, (IVP)
8211 .Lctr_enc_just_ret:
8212 + pax_force_retaddr 0, 1
8213 ret
8214 +ENDPROC(aesni_ctr_enc)
8215 #endif
8216 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8217 index 391d245..67f35c2 100644
8218 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8219 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8220 @@ -20,6 +20,8 @@
8221 *
8222 */
8223
8224 +#include <asm/alternative-asm.h>
8225 +
8226 .file "blowfish-x86_64-asm.S"
8227 .text
8228
8229 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8230 jnz __enc_xor;
8231
8232 write_block();
8233 + pax_force_retaddr 0, 1
8234 ret;
8235 __enc_xor:
8236 xor_block();
8237 + pax_force_retaddr 0, 1
8238 ret;
8239
8240 .align 8
8241 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8242
8243 movq %r11, %rbp;
8244
8245 + pax_force_retaddr 0, 1
8246 ret;
8247
8248 /**********************************************************************
8249 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8250
8251 popq %rbx;
8252 popq %rbp;
8253 + pax_force_retaddr 0, 1
8254 ret;
8255
8256 __enc_xor4:
8257 @@ -349,6 +355,7 @@ __enc_xor4:
8258
8259 popq %rbx;
8260 popq %rbp;
8261 + pax_force_retaddr 0, 1
8262 ret;
8263
8264 .align 8
8265 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8266 popq %rbx;
8267 popq %rbp;
8268
8269 + pax_force_retaddr 0, 1
8270 ret;
8271
8272 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8273 index 0b33743..7a56206 100644
8274 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8275 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8276 @@ -20,6 +20,8 @@
8277 *
8278 */
8279
8280 +#include <asm/alternative-asm.h>
8281 +
8282 .file "camellia-x86_64-asm_64.S"
8283 .text
8284
8285 @@ -229,12 +231,14 @@ __enc_done:
8286 enc_outunpack(mov, RT1);
8287
8288 movq RRBP, %rbp;
8289 + pax_force_retaddr 0, 1
8290 ret;
8291
8292 __enc_xor:
8293 enc_outunpack(xor, RT1);
8294
8295 movq RRBP, %rbp;
8296 + pax_force_retaddr 0, 1
8297 ret;
8298
8299 .global camellia_dec_blk;
8300 @@ -275,6 +279,7 @@ __dec_rounds16:
8301 dec_outunpack();
8302
8303 movq RRBP, %rbp;
8304 + pax_force_retaddr 0, 1
8305 ret;
8306
8307 /**********************************************************************
8308 @@ -468,6 +473,7 @@ __enc2_done:
8309
8310 movq RRBP, %rbp;
8311 popq %rbx;
8312 + pax_force_retaddr 0, 1
8313 ret;
8314
8315 __enc2_xor:
8316 @@ -475,6 +481,7 @@ __enc2_xor:
8317
8318 movq RRBP, %rbp;
8319 popq %rbx;
8320 + pax_force_retaddr 0, 1
8321 ret;
8322
8323 .global camellia_dec_blk_2way;
8324 @@ -517,4 +524,5 @@ __dec2_rounds16:
8325
8326 movq RRBP, %rbp;
8327 movq RXOR, %rbx;
8328 + pax_force_retaddr 0, 1
8329 ret;
8330 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
8331 index a41a3aa..bdf5753 100644
8332 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
8333 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
8334 @@ -23,6 +23,8 @@
8335 *
8336 */
8337
8338 +#include <asm/alternative-asm.h>
8339 +
8340 .file "cast5-avx-x86_64-asm_64.S"
8341
8342 .extern cast5_s1
8343 @@ -293,6 +295,7 @@ __skip_enc:
8344 leaq 3*(2*4*4)(%r11), %rax;
8345 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
8346
8347 + pax_force_retaddr 0, 1
8348 ret;
8349
8350 __enc_xor16:
8351 @@ -303,6 +306,7 @@ __enc_xor16:
8352 leaq 3*(2*4*4)(%r11), %rax;
8353 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
8354
8355 + pax_force_retaddr 0, 1
8356 ret;
8357
8358 .align 16
8359 @@ -369,6 +373,7 @@ __dec_tail:
8360 leaq 3*(2*4*4)(%r11), %rax;
8361 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
8362
8363 + pax_force_retaddr 0, 1
8364 ret;
8365
8366 __skip_dec:
8367 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
8368 index 218d283..819e6da 100644
8369 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
8370 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
8371 @@ -23,6 +23,8 @@
8372 *
8373 */
8374
8375 +#include <asm/alternative-asm.h>
8376 +
8377 .file "cast6-avx-x86_64-asm_64.S"
8378
8379 .extern cast6_s1
8380 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
8381 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
8382 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
8383
8384 + pax_force_retaddr 0, 1
8385 ret;
8386
8387 __enc_xor8:
8388 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
8389 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
8390
8391 + pax_force_retaddr 0, 1
8392 ret;
8393
8394 .align 16
8395 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
8396 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
8397 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
8398
8399 + pax_force_retaddr 0, 1
8400 ret;
8401 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8402 index 6214a9b..1f4fc9a 100644
8403 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8404 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8405 @@ -1,3 +1,5 @@
8406 +#include <asm/alternative-asm.h>
8407 +
8408 # enter ECRYPT_encrypt_bytes
8409 .text
8410 .p2align 5
8411 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8412 add %r11,%rsp
8413 mov %rdi,%rax
8414 mov %rsi,%rdx
8415 + pax_force_retaddr 0, 1
8416 ret
8417 # bytesatleast65:
8418 ._bytesatleast65:
8419 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8420 add %r11,%rsp
8421 mov %rdi,%rax
8422 mov %rsi,%rdx
8423 + pax_force_retaddr
8424 ret
8425 # enter ECRYPT_ivsetup
8426 .text
8427 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8428 add %r11,%rsp
8429 mov %rdi,%rax
8430 mov %rsi,%rdx
8431 + pax_force_retaddr
8432 ret
8433 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8434 index 504106b..4e50951 100644
8435 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8436 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8437 @@ -24,6 +24,8 @@
8438 *
8439 */
8440
8441 +#include <asm/alternative-asm.h>
8442 +
8443 .file "serpent-avx-x86_64-asm_64.S"
8444 .text
8445
8446 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8447 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8448 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8449
8450 + pax_force_retaddr
8451 ret;
8452
8453 __enc_xor8:
8454 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8455 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8456
8457 + pax_force_retaddr
8458 ret;
8459
8460 .align 8
8461 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8462 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8463 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8464
8465 + pax_force_retaddr
8466 ret;
8467 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8468 index 3ee1ff0..cbc568b 100644
8469 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8470 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8471 @@ -24,6 +24,8 @@
8472 *
8473 */
8474
8475 +#include <asm/alternative-asm.h>
8476 +
8477 .file "serpent-sse2-x86_64-asm_64.S"
8478 .text
8479
8480 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8481 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8482 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8483
8484 + pax_force_retaddr
8485 ret;
8486
8487 __enc_xor8:
8488 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8489 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8490
8491 + pax_force_retaddr
8492 ret;
8493
8494 .align 8
8495 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8496 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8497 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8498
8499 + pax_force_retaddr
8500 ret;
8501 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8502 index 49d6987..df66bd4 100644
8503 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8504 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8505 @@ -28,6 +28,8 @@
8506 * (at your option) any later version.
8507 */
8508
8509 +#include <asm/alternative-asm.h>
8510 +
8511 #define CTX %rdi // arg1
8512 #define BUF %rsi // arg2
8513 #define CNT %rdx // arg3
8514 @@ -104,6 +106,7 @@
8515 pop %r12
8516 pop %rbp
8517 pop %rbx
8518 + pax_force_retaddr 0, 1
8519 ret
8520
8521 .size \name, .-\name
8522 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8523 index 1585abb..4a9af16 100644
8524 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8525 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8526 @@ -23,6 +23,8 @@
8527 *
8528 */
8529
8530 +#include <asm/alternative-asm.h>
8531 +
8532 .file "twofish-avx-x86_64-asm_64.S"
8533 .text
8534
8535 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
8536 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
8537 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
8538
8539 + pax_force_retaddr
8540 ret;
8541
8542 __enc_xor8:
8543 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
8544 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
8545
8546 + pax_force_retaddr
8547 ret;
8548
8549 .align 8
8550 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
8551 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
8552 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
8553
8554 + pax_force_retaddr
8555 ret;
8556 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8557 index 5b012a2..36d5364 100644
8558 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8559 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8560 @@ -20,6 +20,8 @@
8561 *
8562 */
8563
8564 +#include <asm/alternative-asm.h>
8565 +
8566 .file "twofish-x86_64-asm-3way.S"
8567 .text
8568
8569 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8570 popq %r13;
8571 popq %r14;
8572 popq %r15;
8573 + pax_force_retaddr 0, 1
8574 ret;
8575
8576 __enc_xor3:
8577 @@ -271,6 +274,7 @@ __enc_xor3:
8578 popq %r13;
8579 popq %r14;
8580 popq %r15;
8581 + pax_force_retaddr 0, 1
8582 ret;
8583
8584 .global twofish_dec_blk_3way
8585 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8586 popq %r13;
8587 popq %r14;
8588 popq %r15;
8589 + pax_force_retaddr 0, 1
8590 ret;
8591
8592 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8593 index 7bcf3fc..f53832f 100644
8594 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8595 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8596 @@ -21,6 +21,7 @@
8597 .text
8598
8599 #include <asm/asm-offsets.h>
8600 +#include <asm/alternative-asm.h>
8601
8602 #define a_offset 0
8603 #define b_offset 4
8604 @@ -268,6 +269,7 @@ twofish_enc_blk:
8605
8606 popq R1
8607 movq $1,%rax
8608 + pax_force_retaddr 0, 1
8609 ret
8610
8611 twofish_dec_blk:
8612 @@ -319,4 +321,5 @@ twofish_dec_blk:
8613
8614 popq R1
8615 movq $1,%rax
8616 + pax_force_retaddr 0, 1
8617 ret
8618 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8619 index 07b3a68..bd2a388 100644
8620 --- a/arch/x86/ia32/ia32_aout.c
8621 +++ b/arch/x86/ia32/ia32_aout.c
8622 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8623 unsigned long dump_start, dump_size;
8624 struct user32 dump;
8625
8626 + memset(&dump, 0, sizeof(dump));
8627 +
8628 fs = get_fs();
8629 set_fs(KERNEL_DS);
8630 has_dumped = 1;
8631 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8632 index efc6a95..95abfe2 100644
8633 --- a/arch/x86/ia32/ia32_signal.c
8634 +++ b/arch/x86/ia32/ia32_signal.c
8635 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8636 }
8637 seg = get_fs();
8638 set_fs(KERNEL_DS);
8639 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
8640 - (stack_t __force __user *) &uoss, regs->sp);
8641 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
8642 + (stack_t __force_user *) &uoss, regs->sp);
8643 set_fs(seg);
8644 if (ret >= 0 && uoss_ptr) {
8645 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8646 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8647 sp -= frame_size;
8648 /* Align the stack pointer according to the i386 ABI,
8649 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8650 - sp = ((sp + 4) & -16ul) - 4;
8651 + sp = ((sp - 12) & -16ul) - 4;
8652 return (void __user *) sp;
8653 }
8654
8655 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8656 * These are actually not used anymore, but left because some
8657 * gdb versions depend on them as a marker.
8658 */
8659 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
8660 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8661 } put_user_catch(err);
8662
8663 if (err)
8664 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8665 0xb8,
8666 __NR_ia32_rt_sigreturn,
8667 0x80cd,
8668 - 0,
8669 + 0
8670 };
8671
8672 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8673 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8674
8675 if (ka->sa.sa_flags & SA_RESTORER)
8676 restorer = ka->sa.sa_restorer;
8677 + else if (current->mm->context.vdso)
8678 + /* Return stub is in 32bit vsyscall page */
8679 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8680 else
8681 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8682 - rt_sigreturn);
8683 + restorer = &frame->retcode;
8684 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8685
8686 /*
8687 * Not actually used anymore, but left because some gdb
8688 * versions need it.
8689 */
8690 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
8691 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8692 } put_user_catch(err);
8693
8694 err |= copy_siginfo_to_user32(&frame->info, info);
8695 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8696 index 076745f..ae8f6cb 100644
8697 --- a/arch/x86/ia32/ia32entry.S
8698 +++ b/arch/x86/ia32/ia32entry.S
8699 @@ -15,8 +15,10 @@
8700 #include <asm/irqflags.h>
8701 #include <asm/asm.h>
8702 #include <asm/smap.h>
8703 +#include <asm/pgtable.h>
8704 #include <linux/linkage.h>
8705 #include <linux/err.h>
8706 +#include <asm/alternative-asm.h>
8707
8708 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8709 #include <linux/elf-em.h>
8710 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
8711 ENDPROC(native_irq_enable_sysexit)
8712 #endif
8713
8714 + .macro pax_enter_kernel_user
8715 + pax_set_fptr_mask
8716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8717 + call pax_enter_kernel_user
8718 +#endif
8719 + .endm
8720 +
8721 + .macro pax_exit_kernel_user
8722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8723 + call pax_exit_kernel_user
8724 +#endif
8725 +#ifdef CONFIG_PAX_RANDKSTACK
8726 + pushq %rax
8727 + pushq %r11
8728 + call pax_randomize_kstack
8729 + popq %r11
8730 + popq %rax
8731 +#endif
8732 + .endm
8733 +
8734 +.macro pax_erase_kstack
8735 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8736 + call pax_erase_kstack
8737 +#endif
8738 +.endm
8739 +
8740 /*
8741 * 32bit SYSENTER instruction entry.
8742 *
8743 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
8744 CFI_REGISTER rsp,rbp
8745 SWAPGS_UNSAFE_STACK
8746 movq PER_CPU_VAR(kernel_stack), %rsp
8747 - addq $(KERNEL_STACK_OFFSET),%rsp
8748 - /*
8749 - * No need to follow this irqs on/off section: the syscall
8750 - * disabled irqs, here we enable it straight after entry:
8751 - */
8752 - ENABLE_INTERRUPTS(CLBR_NONE)
8753 movl %ebp,%ebp /* zero extension */
8754 pushq_cfi $__USER32_DS
8755 /*CFI_REL_OFFSET ss,0*/
8756 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
8757 CFI_REL_OFFSET rsp,0
8758 pushfq_cfi
8759 /*CFI_REL_OFFSET rflags,0*/
8760 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8761 - CFI_REGISTER rip,r10
8762 + orl $X86_EFLAGS_IF,(%rsp)
8763 + GET_THREAD_INFO(%r11)
8764 + movl TI_sysenter_return(%r11), %r11d
8765 + CFI_REGISTER rip,r11
8766 pushq_cfi $__USER32_CS
8767 /*CFI_REL_OFFSET cs,0*/
8768 movl %eax, %eax
8769 - pushq_cfi %r10
8770 + pushq_cfi %r11
8771 CFI_REL_OFFSET rip,0
8772 pushq_cfi %rax
8773 cld
8774 SAVE_ARGS 0,1,0
8775 + pax_enter_kernel_user
8776 +
8777 +#ifdef CONFIG_PAX_RANDKSTACK
8778 + pax_erase_kstack
8779 +#endif
8780 +
8781 + /*
8782 + * No need to follow this irqs on/off section: the syscall
8783 + * disabled irqs, here we enable it straight after entry:
8784 + */
8785 + ENABLE_INTERRUPTS(CLBR_NONE)
8786 /* no need to do an access_ok check here because rbp has been
8787 32bit zero extended */
8788 +
8789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8790 + mov $PAX_USER_SHADOW_BASE,%r11
8791 + add %r11,%rbp
8792 +#endif
8793 +
8794 ASM_STAC
8795 1: movl (%rbp),%ebp
8796 _ASM_EXTABLE(1b,ia32_badarg)
8797 ASM_CLAC
8798 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8799 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8800 + GET_THREAD_INFO(%r11)
8801 + orl $TS_COMPAT,TI_status(%r11)
8802 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8803 CFI_REMEMBER_STATE
8804 jnz sysenter_tracesys
8805 cmpq $(IA32_NR_syscalls-1),%rax
8806 @@ -162,12 +204,15 @@ sysenter_do_call:
8807 sysenter_dispatch:
8808 call *ia32_sys_call_table(,%rax,8)
8809 movq %rax,RAX-ARGOFFSET(%rsp)
8810 + GET_THREAD_INFO(%r11)
8811 DISABLE_INTERRUPTS(CLBR_NONE)
8812 TRACE_IRQS_OFF
8813 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8814 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8815 jnz sysexit_audit
8816 sysexit_from_sys_call:
8817 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8818 + pax_exit_kernel_user
8819 + pax_erase_kstack
8820 + andl $~TS_COMPAT,TI_status(%r11)
8821 /* clear IF, that popfq doesn't enable interrupts early */
8822 andl $~0x200,EFLAGS-R11(%rsp)
8823 movl RIP-R11(%rsp),%edx /* User %eip */
8824 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
8825 movl %eax,%esi /* 2nd arg: syscall number */
8826 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8827 call __audit_syscall_entry
8828 +
8829 + pax_erase_kstack
8830 +
8831 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8832 cmpq $(IA32_NR_syscalls-1),%rax
8833 ja ia32_badsys
8834 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
8835 .endm
8836
8837 .macro auditsys_exit exit
8838 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8839 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8840 jnz ia32_ret_from_sys_call
8841 TRACE_IRQS_ON
8842 sti
8843 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
8844 1: setbe %al /* 1 if error, 0 if not */
8845 movzbl %al,%edi /* zero-extend that into %edi */
8846 call __audit_syscall_exit
8847 + GET_THREAD_INFO(%r11)
8848 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8849 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8850 cli
8851 TRACE_IRQS_OFF
8852 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8853 + testl %edi,TI_flags(%r11)
8854 jz \exit
8855 CLEAR_RREGS -ARGOFFSET
8856 jmp int_with_check
8857 @@ -237,7 +286,7 @@ sysexit_audit:
8858
8859 sysenter_tracesys:
8860 #ifdef CONFIG_AUDITSYSCALL
8861 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8862 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8863 jz sysenter_auditsys
8864 #endif
8865 SAVE_REST
8866 @@ -249,6 +298,9 @@ sysenter_tracesys:
8867 RESTORE_REST
8868 cmpq $(IA32_NR_syscalls-1),%rax
8869 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8870 +
8871 + pax_erase_kstack
8872 +
8873 jmp sysenter_do_call
8874 CFI_ENDPROC
8875 ENDPROC(ia32_sysenter_target)
8876 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
8877 ENTRY(ia32_cstar_target)
8878 CFI_STARTPROC32 simple
8879 CFI_SIGNAL_FRAME
8880 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8881 + CFI_DEF_CFA rsp,0
8882 CFI_REGISTER rip,rcx
8883 /*CFI_REGISTER rflags,r11*/
8884 SWAPGS_UNSAFE_STACK
8885 movl %esp,%r8d
8886 CFI_REGISTER rsp,r8
8887 movq PER_CPU_VAR(kernel_stack),%rsp
8888 + SAVE_ARGS 8*6,0,0
8889 + pax_enter_kernel_user
8890 +
8891 +#ifdef CONFIG_PAX_RANDKSTACK
8892 + pax_erase_kstack
8893 +#endif
8894 +
8895 /*
8896 * No need to follow this irqs on/off section: the syscall
8897 * disabled irqs and here we enable it straight after entry:
8898 */
8899 ENABLE_INTERRUPTS(CLBR_NONE)
8900 - SAVE_ARGS 8,0,0
8901 movl %eax,%eax /* zero extension */
8902 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8903 movq %rcx,RIP-ARGOFFSET(%rsp)
8904 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
8905 /* no need to do an access_ok check here because r8 has been
8906 32bit zero extended */
8907 /* hardware stack frame is complete now */
8908 +
8909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8910 + mov $PAX_USER_SHADOW_BASE,%r11
8911 + add %r11,%r8
8912 +#endif
8913 +
8914 ASM_STAC
8915 1: movl (%r8),%r9d
8916 _ASM_EXTABLE(1b,ia32_badarg)
8917 ASM_CLAC
8918 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8919 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8920 + GET_THREAD_INFO(%r11)
8921 + orl $TS_COMPAT,TI_status(%r11)
8922 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8923 CFI_REMEMBER_STATE
8924 jnz cstar_tracesys
8925 cmpq $IA32_NR_syscalls-1,%rax
8926 @@ -319,12 +384,15 @@ cstar_do_call:
8927 cstar_dispatch:
8928 call *ia32_sys_call_table(,%rax,8)
8929 movq %rax,RAX-ARGOFFSET(%rsp)
8930 + GET_THREAD_INFO(%r11)
8931 DISABLE_INTERRUPTS(CLBR_NONE)
8932 TRACE_IRQS_OFF
8933 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8935 jnz sysretl_audit
8936 sysretl_from_sys_call:
8937 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8938 + pax_exit_kernel_user
8939 + pax_erase_kstack
8940 + andl $~TS_COMPAT,TI_status(%r11)
8941 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8942 movl RIP-ARGOFFSET(%rsp),%ecx
8943 CFI_REGISTER rip,rcx
8944 @@ -352,7 +420,7 @@ sysretl_audit:
8945
8946 cstar_tracesys:
8947 #ifdef CONFIG_AUDITSYSCALL
8948 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8949 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8950 jz cstar_auditsys
8951 #endif
8952 xchgl %r9d,%ebp
8953 @@ -366,6 +434,9 @@ cstar_tracesys:
8954 xchgl %ebp,%r9d
8955 cmpq $(IA32_NR_syscalls-1),%rax
8956 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8957 +
8958 + pax_erase_kstack
8959 +
8960 jmp cstar_do_call
8961 END(ia32_cstar_target)
8962
8963 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
8964 CFI_REL_OFFSET rip,RIP-RIP
8965 PARAVIRT_ADJUST_EXCEPTION_FRAME
8966 SWAPGS
8967 - /*
8968 - * No need to follow this irqs on/off section: the syscall
8969 - * disabled irqs and here we enable it straight after entry:
8970 - */
8971 - ENABLE_INTERRUPTS(CLBR_NONE)
8972 movl %eax,%eax
8973 pushq_cfi %rax
8974 cld
8975 /* note the registers are not zero extended to the sf.
8976 this could be a problem. */
8977 SAVE_ARGS 0,1,0
8978 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8979 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8980 + pax_enter_kernel_user
8981 +
8982 +#ifdef CONFIG_PAX_RANDKSTACK
8983 + pax_erase_kstack
8984 +#endif
8985 +
8986 + /*
8987 + * No need to follow this irqs on/off section: the syscall
8988 + * disabled irqs and here we enable it straight after entry:
8989 + */
8990 + ENABLE_INTERRUPTS(CLBR_NONE)
8991 + GET_THREAD_INFO(%r11)
8992 + orl $TS_COMPAT,TI_status(%r11)
8993 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8994 jnz ia32_tracesys
8995 cmpq $(IA32_NR_syscalls-1),%rax
8996 ja ia32_badsys
8997 @@ -442,6 +520,9 @@ ia32_tracesys:
8998 RESTORE_REST
8999 cmpq $(IA32_NR_syscalls-1),%rax
9000 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
9001 +
9002 + pax_erase_kstack
9003 +
9004 jmp ia32_do_call
9005 END(ia32_syscall)
9006
9007 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9008 index 86d68d1..f9960fe 100644
9009 --- a/arch/x86/ia32/sys_ia32.c
9010 +++ b/arch/x86/ia32/sys_ia32.c
9011 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9012 */
9013 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9014 {
9015 - typeof(ubuf->st_uid) uid = 0;
9016 - typeof(ubuf->st_gid) gid = 0;
9017 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9018 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9019 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9020 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9021 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9022 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9023 mm_segment_t old_fs = get_fs();
9024
9025 set_fs(KERNEL_DS);
9026 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9027 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9028 set_fs(old_fs);
9029 if (put_compat_timespec(&t, interval))
9030 return -EFAULT;
9031 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9032 mm_segment_t old_fs = get_fs();
9033
9034 set_fs(KERNEL_DS);
9035 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9036 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9037 set_fs(old_fs);
9038 if (!ret) {
9039 switch (_NSIG_WORDS) {
9040 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9041 if (copy_siginfo_from_user32(&info, uinfo))
9042 return -EFAULT;
9043 set_fs(KERNEL_DS);
9044 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9045 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9046 set_fs(old_fs);
9047 return ret;
9048 }
9049 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9050 return -EFAULT;
9051
9052 set_fs(KERNEL_DS);
9053 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9054 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9055 count);
9056 set_fs(old_fs);
9057
9058 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9059 index 372231c..a5aa1a1 100644
9060 --- a/arch/x86/include/asm/alternative-asm.h
9061 +++ b/arch/x86/include/asm/alternative-asm.h
9062 @@ -18,6 +18,45 @@
9063 .endm
9064 #endif
9065
9066 +#ifdef KERNEXEC_PLUGIN
9067 + .macro pax_force_retaddr_bts rip=0
9068 + btsq $63,\rip(%rsp)
9069 + .endm
9070 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9071 + .macro pax_force_retaddr rip=0, reload=0
9072 + btsq $63,\rip(%rsp)
9073 + .endm
9074 + .macro pax_force_fptr ptr
9075 + btsq $63,\ptr
9076 + .endm
9077 + .macro pax_set_fptr_mask
9078 + .endm
9079 +#endif
9080 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9081 + .macro pax_force_retaddr rip=0, reload=0
9082 + .if \reload
9083 + pax_set_fptr_mask
9084 + .endif
9085 + orq %r10,\rip(%rsp)
9086 + .endm
9087 + .macro pax_force_fptr ptr
9088 + orq %r10,\ptr
9089 + .endm
9090 + .macro pax_set_fptr_mask
9091 + movabs $0x8000000000000000,%r10
9092 + .endm
9093 +#endif
9094 +#else
9095 + .macro pax_force_retaddr rip=0, reload=0
9096 + .endm
9097 + .macro pax_force_fptr ptr
9098 + .endm
9099 + .macro pax_force_retaddr_bts rip=0
9100 + .endm
9101 + .macro pax_set_fptr_mask
9102 + .endm
9103 +#endif
9104 +
9105 .macro altinstruction_entry orig alt feature orig_len alt_len
9106 .long \orig - .
9107 .long \alt - .
9108 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9109 index 58ed6d9..f1cbe58 100644
9110 --- a/arch/x86/include/asm/alternative.h
9111 +++ b/arch/x86/include/asm/alternative.h
9112 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9113 ".pushsection .discard,\"aw\",@progbits\n" \
9114 DISCARD_ENTRY(1) \
9115 ".popsection\n" \
9116 - ".pushsection .altinstr_replacement, \"ax\"\n" \
9117 + ".pushsection .altinstr_replacement, \"a\"\n" \
9118 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9119 ".popsection"
9120
9121 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9122 DISCARD_ENTRY(1) \
9123 DISCARD_ENTRY(2) \
9124 ".popsection\n" \
9125 - ".pushsection .altinstr_replacement, \"ax\"\n" \
9126 + ".pushsection .altinstr_replacement, \"a\"\n" \
9127 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9128 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9129 ".popsection"
9130 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9131 index 3388034..ba52312 100644
9132 --- a/arch/x86/include/asm/apic.h
9133 +++ b/arch/x86/include/asm/apic.h
9134 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9135
9136 #ifdef CONFIG_X86_LOCAL_APIC
9137
9138 -extern unsigned int apic_verbosity;
9139 +extern int apic_verbosity;
9140 extern int local_apic_timer_c2_ok;
9141
9142 extern int disable_apic;
9143 @@ -391,7 +391,7 @@ struct apic {
9144 */
9145 int (*x86_32_numa_cpu_node)(int cpu);
9146 #endif
9147 -};
9148 +} __do_const;
9149
9150 /*
9151 * Pointer to the local APIC driver in use on this system (there's
9152 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9153 index 20370c6..a2eb9b0 100644
9154 --- a/arch/x86/include/asm/apm.h
9155 +++ b/arch/x86/include/asm/apm.h
9156 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9157 __asm__ __volatile__(APM_DO_ZERO_SEGS
9158 "pushl %%edi\n\t"
9159 "pushl %%ebp\n\t"
9160 - "lcall *%%cs:apm_bios_entry\n\t"
9161 + "lcall *%%ss:apm_bios_entry\n\t"
9162 "setc %%al\n\t"
9163 "popl %%ebp\n\t"
9164 "popl %%edi\n\t"
9165 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9166 __asm__ __volatile__(APM_DO_ZERO_SEGS
9167 "pushl %%edi\n\t"
9168 "pushl %%ebp\n\t"
9169 - "lcall *%%cs:apm_bios_entry\n\t"
9170 + "lcall *%%ss:apm_bios_entry\n\t"
9171 "setc %%bl\n\t"
9172 "popl %%ebp\n\t"
9173 "popl %%edi\n\t"
9174 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9175 index b6c3b82..b4c077a 100644
9176 --- a/arch/x86/include/asm/atomic.h
9177 +++ b/arch/x86/include/asm/atomic.h
9178 @@ -22,7 +22,18 @@
9179 */
9180 static inline int atomic_read(const atomic_t *v)
9181 {
9182 - return (*(volatile int *)&(v)->counter);
9183 + return (*(volatile const int *)&(v)->counter);
9184 +}
9185 +
9186 +/**
9187 + * atomic_read_unchecked - read atomic variable
9188 + * @v: pointer of type atomic_unchecked_t
9189 + *
9190 + * Atomically reads the value of @v.
9191 + */
9192 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9193 +{
9194 + return (*(volatile const int *)&(v)->counter);
9195 }
9196
9197 /**
9198 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9199 }
9200
9201 /**
9202 + * atomic_set_unchecked - set atomic variable
9203 + * @v: pointer of type atomic_unchecked_t
9204 + * @i: required value
9205 + *
9206 + * Atomically sets the value of @v to @i.
9207 + */
9208 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9209 +{
9210 + v->counter = i;
9211 +}
9212 +
9213 +/**
9214 * atomic_add - add integer to atomic variable
9215 * @i: integer value to add
9216 * @v: pointer of type atomic_t
9217 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9218 */
9219 static inline void atomic_add(int i, atomic_t *v)
9220 {
9221 - asm volatile(LOCK_PREFIX "addl %1,%0"
9222 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9223 +
9224 +#ifdef CONFIG_PAX_REFCOUNT
9225 + "jno 0f\n"
9226 + LOCK_PREFIX "subl %1,%0\n"
9227 + "int $4\n0:\n"
9228 + _ASM_EXTABLE(0b, 0b)
9229 +#endif
9230 +
9231 + : "+m" (v->counter)
9232 + : "ir" (i));
9233 +}
9234 +
9235 +/**
9236 + * atomic_add_unchecked - add integer to atomic variable
9237 + * @i: integer value to add
9238 + * @v: pointer of type atomic_unchecked_t
9239 + *
9240 + * Atomically adds @i to @v.
9241 + */
9242 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9243 +{
9244 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9245 : "+m" (v->counter)
9246 : "ir" (i));
9247 }
9248 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9249 */
9250 static inline void atomic_sub(int i, atomic_t *v)
9251 {
9252 - asm volatile(LOCK_PREFIX "subl %1,%0"
9253 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9254 +
9255 +#ifdef CONFIG_PAX_REFCOUNT
9256 + "jno 0f\n"
9257 + LOCK_PREFIX "addl %1,%0\n"
9258 + "int $4\n0:\n"
9259 + _ASM_EXTABLE(0b, 0b)
9260 +#endif
9261 +
9262 + : "+m" (v->counter)
9263 + : "ir" (i));
9264 +}
9265 +
9266 +/**
9267 + * atomic_sub_unchecked - subtract integer from atomic variable
9268 + * @i: integer value to subtract
9269 + * @v: pointer of type atomic_unchecked_t
9270 + *
9271 + * Atomically subtracts @i from @v.
9272 + */
9273 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9274 +{
9275 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9276 : "+m" (v->counter)
9277 : "ir" (i));
9278 }
9279 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9280 {
9281 unsigned char c;
9282
9283 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9284 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9285 +
9286 +#ifdef CONFIG_PAX_REFCOUNT
9287 + "jno 0f\n"
9288 + LOCK_PREFIX "addl %2,%0\n"
9289 + "int $4\n0:\n"
9290 + _ASM_EXTABLE(0b, 0b)
9291 +#endif
9292 +
9293 + "sete %1\n"
9294 : "+m" (v->counter), "=qm" (c)
9295 : "ir" (i) : "memory");
9296 return c;
9297 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9298 */
9299 static inline void atomic_inc(atomic_t *v)
9300 {
9301 - asm volatile(LOCK_PREFIX "incl %0"
9302 + asm volatile(LOCK_PREFIX "incl %0\n"
9303 +
9304 +#ifdef CONFIG_PAX_REFCOUNT
9305 + "jno 0f\n"
9306 + LOCK_PREFIX "decl %0\n"
9307 + "int $4\n0:\n"
9308 + _ASM_EXTABLE(0b, 0b)
9309 +#endif
9310 +
9311 + : "+m" (v->counter));
9312 +}
9313 +
9314 +/**
9315 + * atomic_inc_unchecked - increment atomic variable
9316 + * @v: pointer of type atomic_unchecked_t
9317 + *
9318 + * Atomically increments @v by 1.
9319 + */
9320 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9321 +{
9322 + asm volatile(LOCK_PREFIX "incl %0\n"
9323 : "+m" (v->counter));
9324 }
9325
9326 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9327 */
9328 static inline void atomic_dec(atomic_t *v)
9329 {
9330 - asm volatile(LOCK_PREFIX "decl %0"
9331 + asm volatile(LOCK_PREFIX "decl %0\n"
9332 +
9333 +#ifdef CONFIG_PAX_REFCOUNT
9334 + "jno 0f\n"
9335 + LOCK_PREFIX "incl %0\n"
9336 + "int $4\n0:\n"
9337 + _ASM_EXTABLE(0b, 0b)
9338 +#endif
9339 +
9340 + : "+m" (v->counter));
9341 +}
9342 +
9343 +/**
9344 + * atomic_dec_unchecked - decrement atomic variable
9345 + * @v: pointer of type atomic_unchecked_t
9346 + *
9347 + * Atomically decrements @v by 1.
9348 + */
9349 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9350 +{
9351 + asm volatile(LOCK_PREFIX "decl %0\n"
9352 : "+m" (v->counter));
9353 }
9354
9355 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9356 {
9357 unsigned char c;
9358
9359 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9360 + asm volatile(LOCK_PREFIX "decl %0\n"
9361 +
9362 +#ifdef CONFIG_PAX_REFCOUNT
9363 + "jno 0f\n"
9364 + LOCK_PREFIX "incl %0\n"
9365 + "int $4\n0:\n"
9366 + _ASM_EXTABLE(0b, 0b)
9367 +#endif
9368 +
9369 + "sete %1\n"
9370 : "+m" (v->counter), "=qm" (c)
9371 : : "memory");
9372 return c != 0;
9373 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9374 {
9375 unsigned char c;
9376
9377 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9378 + asm volatile(LOCK_PREFIX "incl %0\n"
9379 +
9380 +#ifdef CONFIG_PAX_REFCOUNT
9381 + "jno 0f\n"
9382 + LOCK_PREFIX "decl %0\n"
9383 + "int $4\n0:\n"
9384 + _ASM_EXTABLE(0b, 0b)
9385 +#endif
9386 +
9387 + "sete %1\n"
9388 + : "+m" (v->counter), "=qm" (c)
9389 + : : "memory");
9390 + return c != 0;
9391 +}
9392 +
9393 +/**
9394 + * atomic_inc_and_test_unchecked - increment and test
9395 + * @v: pointer of type atomic_unchecked_t
9396 + *
9397 + * Atomically increments @v by 1
9398 + * and returns true if the result is zero, or false for all
9399 + * other cases.
9400 + */
9401 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9402 +{
9403 + unsigned char c;
9404 +
9405 + asm volatile(LOCK_PREFIX "incl %0\n"
9406 + "sete %1\n"
9407 : "+m" (v->counter), "=qm" (c)
9408 : : "memory");
9409 return c != 0;
9410 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9411 {
9412 unsigned char c;
9413
9414 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9415 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9416 +
9417 +#ifdef CONFIG_PAX_REFCOUNT
9418 + "jno 0f\n"
9419 + LOCK_PREFIX "subl %2,%0\n"
9420 + "int $4\n0:\n"
9421 + _ASM_EXTABLE(0b, 0b)
9422 +#endif
9423 +
9424 + "sets %1\n"
9425 : "+m" (v->counter), "=qm" (c)
9426 : "ir" (i) : "memory");
9427 return c;
9428 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9429 goto no_xadd;
9430 #endif
9431 /* Modern 486+ processor */
9432 - return i + xadd(&v->counter, i);
9433 + return i + xadd_check_overflow(&v->counter, i);
9434
9435 #ifdef CONFIG_M386
9436 no_xadd: /* Legacy 386 processor */
9437 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9438 }
9439
9440 /**
9441 + * atomic_add_return_unchecked - add integer and return
9442 + * @i: integer value to add
9443 + * @v: pointer of type atomic_unchecked_t
9444 + *
9445 + * Atomically adds @i to @v and returns @i + @v
9446 + */
9447 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9448 +{
9449 +#ifdef CONFIG_M386
9450 + int __i;
9451 + unsigned long flags;
9452 + if (unlikely(boot_cpu_data.x86 <= 3))
9453 + goto no_xadd;
9454 +#endif
9455 + /* Modern 486+ processor */
9456 + return i + xadd(&v->counter, i);
9457 +
9458 +#ifdef CONFIG_M386
9459 +no_xadd: /* Legacy 386 processor */
9460 + raw_local_irq_save(flags);
9461 + __i = atomic_read_unchecked(v);
9462 + atomic_set_unchecked(v, i + __i);
9463 + raw_local_irq_restore(flags);
9464 + return i + __i;
9465 +#endif
9466 +}
9467 +
9468 +/**
9469 * atomic_sub_return - subtract integer and return
9470 * @v: pointer of type atomic_t
9471 * @i: integer value to subtract
9472 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9473 }
9474
9475 #define atomic_inc_return(v) (atomic_add_return(1, v))
9476 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9477 +{
9478 + return atomic_add_return_unchecked(1, v);
9479 +}
9480 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9481
9482 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9483 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9484 return cmpxchg(&v->counter, old, new);
9485 }
9486
9487 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9488 +{
9489 + return cmpxchg(&v->counter, old, new);
9490 +}
9491 +
9492 static inline int atomic_xchg(atomic_t *v, int new)
9493 {
9494 return xchg(&v->counter, new);
9495 }
9496
9497 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9498 +{
9499 + return xchg(&v->counter, new);
9500 +}
9501 +
9502 /**
9503 * __atomic_add_unless - add unless the number is already a given value
9504 * @v: pointer of type atomic_t
9505 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9506 */
9507 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9508 {
9509 - int c, old;
9510 + int c, old, new;
9511 c = atomic_read(v);
9512 for (;;) {
9513 - if (unlikely(c == (u)))
9514 + if (unlikely(c == u))
9515 break;
9516 - old = atomic_cmpxchg((v), c, c + (a));
9517 +
9518 + asm volatile("addl %2,%0\n"
9519 +
9520 +#ifdef CONFIG_PAX_REFCOUNT
9521 + "jno 0f\n"
9522 + "subl %2,%0\n"
9523 + "int $4\n0:\n"
9524 + _ASM_EXTABLE(0b, 0b)
9525 +#endif
9526 +
9527 + : "=r" (new)
9528 + : "0" (c), "ir" (a));
9529 +
9530 + old = atomic_cmpxchg(v, c, new);
9531 if (likely(old == c))
9532 break;
9533 c = old;
9534 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9535 }
9536
9537 /**
9538 + * atomic_inc_not_zero_hint - increment if not null
9539 + * @v: pointer of type atomic_t
9540 + * @hint: probable value of the atomic before the increment
9541 + *
9542 + * This version of atomic_inc_not_zero() gives a hint of probable
9543 + * value of the atomic. This helps processor to not read the memory
9544 + * before doing the atomic read/modify/write cycle, lowering
9545 + * number of bus transactions on some arches.
9546 + *
9547 + * Returns: 0 if increment was not done, 1 otherwise.
9548 + */
9549 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9550 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9551 +{
9552 + int val, c = hint, new;
9553 +
9554 + /* sanity test, should be removed by compiler if hint is a constant */
9555 + if (!hint)
9556 + return __atomic_add_unless(v, 1, 0);
9557 +
9558 + do {
9559 + asm volatile("incl %0\n"
9560 +
9561 +#ifdef CONFIG_PAX_REFCOUNT
9562 + "jno 0f\n"
9563 + "decl %0\n"
9564 + "int $4\n0:\n"
9565 + _ASM_EXTABLE(0b, 0b)
9566 +#endif
9567 +
9568 + : "=r" (new)
9569 + : "0" (c));
9570 +
9571 + val = atomic_cmpxchg(v, c, new);
9572 + if (val == c)
9573 + return 1;
9574 + c = val;
9575 + } while (c);
9576 +
9577 + return 0;
9578 +}
9579 +
9580 +/**
9581 * atomic_inc_short - increment of a short integer
9582 * @v: pointer to type int
9583 *
9584 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9585 #endif
9586
9587 /* These are x86-specific, used by some header files */
9588 -#define atomic_clear_mask(mask, addr) \
9589 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9590 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9591 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9592 +{
9593 + asm volatile(LOCK_PREFIX "andl %1,%0"
9594 + : "+m" (v->counter)
9595 + : "r" (~(mask))
9596 + : "memory");
9597 +}
9598
9599 -#define atomic_set_mask(mask, addr) \
9600 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9601 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9602 - : "memory")
9603 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9604 +{
9605 + asm volatile(LOCK_PREFIX "andl %1,%0"
9606 + : "+m" (v->counter)
9607 + : "r" (~(mask))
9608 + : "memory");
9609 +}
9610 +
9611 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9612 +{
9613 + asm volatile(LOCK_PREFIX "orl %1,%0"
9614 + : "+m" (v->counter)
9615 + : "r" (mask)
9616 + : "memory");
9617 +}
9618 +
9619 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9620 +{
9621 + asm volatile(LOCK_PREFIX "orl %1,%0"
9622 + : "+m" (v->counter)
9623 + : "r" (mask)
9624 + : "memory");
9625 +}
9626
9627 /* Atomic operations are already serializing on x86 */
9628 #define smp_mb__before_atomic_dec() barrier()
9629 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9630 index b154de7..aadebd8 100644
9631 --- a/arch/x86/include/asm/atomic64_32.h
9632 +++ b/arch/x86/include/asm/atomic64_32.h
9633 @@ -12,6 +12,14 @@ typedef struct {
9634 u64 __aligned(8) counter;
9635 } atomic64_t;
9636
9637 +#ifdef CONFIG_PAX_REFCOUNT
9638 +typedef struct {
9639 + u64 __aligned(8) counter;
9640 +} atomic64_unchecked_t;
9641 +#else
9642 +typedef atomic64_t atomic64_unchecked_t;
9643 +#endif
9644 +
9645 #define ATOMIC64_INIT(val) { (val) }
9646
9647 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9648 @@ -37,21 +45,31 @@ typedef struct {
9649 ATOMIC64_DECL_ONE(sym##_386)
9650
9651 ATOMIC64_DECL_ONE(add_386);
9652 +ATOMIC64_DECL_ONE(add_unchecked_386);
9653 ATOMIC64_DECL_ONE(sub_386);
9654 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9655 ATOMIC64_DECL_ONE(inc_386);
9656 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9657 ATOMIC64_DECL_ONE(dec_386);
9658 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9659 #endif
9660
9661 #define alternative_atomic64(f, out, in...) \
9662 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9663
9664 ATOMIC64_DECL(read);
9665 +ATOMIC64_DECL(read_unchecked);
9666 ATOMIC64_DECL(set);
9667 +ATOMIC64_DECL(set_unchecked);
9668 ATOMIC64_DECL(xchg);
9669 ATOMIC64_DECL(add_return);
9670 +ATOMIC64_DECL(add_return_unchecked);
9671 ATOMIC64_DECL(sub_return);
9672 +ATOMIC64_DECL(sub_return_unchecked);
9673 ATOMIC64_DECL(inc_return);
9674 +ATOMIC64_DECL(inc_return_unchecked);
9675 ATOMIC64_DECL(dec_return);
9676 +ATOMIC64_DECL(dec_return_unchecked);
9677 ATOMIC64_DECL(dec_if_positive);
9678 ATOMIC64_DECL(inc_not_zero);
9679 ATOMIC64_DECL(add_unless);
9680 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9681 }
9682
9683 /**
9684 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9685 + * @p: pointer to type atomic64_unchecked_t
9686 + * @o: expected value
9687 + * @n: new value
9688 + *
9689 + * Atomically sets @v to @n if it was equal to @o and returns
9690 + * the old value.
9691 + */
9692 +
9693 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9694 +{
9695 + return cmpxchg64(&v->counter, o, n);
9696 +}
9697 +
9698 +/**
9699 * atomic64_xchg - xchg atomic64 variable
9700 * @v: pointer to type atomic64_t
9701 * @n: value to assign
9702 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9703 }
9704
9705 /**
9706 + * atomic64_set_unchecked - set atomic64 variable
9707 + * @v: pointer to type atomic64_unchecked_t
9708 + * @n: value to assign
9709 + *
9710 + * Atomically sets the value of @v to @n.
9711 + */
9712 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9713 +{
9714 + unsigned high = (unsigned)(i >> 32);
9715 + unsigned low = (unsigned)i;
9716 + alternative_atomic64(set, /* no output */,
9717 + "S" (v), "b" (low), "c" (high)
9718 + : "eax", "edx", "memory");
9719 +}
9720 +
9721 +/**
9722 * atomic64_read - read atomic64 variable
9723 * @v: pointer to type atomic64_t
9724 *
9725 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9726 }
9727
9728 /**
9729 + * atomic64_read_unchecked - read atomic64 variable
9730 + * @v: pointer to type atomic64_unchecked_t
9731 + *
9732 + * Atomically reads the value of @v and returns it.
9733 + */
9734 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9735 +{
9736 + long long r;
9737 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9738 + return r;
9739 + }
9740 +
9741 +/**
9742 * atomic64_add_return - add and return
9743 * @i: integer value to add
9744 * @v: pointer to type atomic64_t
9745 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9746 return i;
9747 }
9748
9749 +/**
9750 + * atomic64_add_return_unchecked - add and return
9751 + * @i: integer value to add
9752 + * @v: pointer to type atomic64_unchecked_t
9753 + *
9754 + * Atomically adds @i to @v and returns @i + *@v
9755 + */
9756 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9757 +{
9758 + alternative_atomic64(add_return_unchecked,
9759 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9760 + ASM_NO_INPUT_CLOBBER("memory"));
9761 + return i;
9762 +}
9763 +
9764 /*
9765 * Other variants with different arithmetic operators:
9766 */
9767 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9768 return a;
9769 }
9770
9771 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9772 +{
9773 + long long a;
9774 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9775 + "S" (v) : "memory", "ecx");
9776 + return a;
9777 +}
9778 +
9779 static inline long long atomic64_dec_return(atomic64_t *v)
9780 {
9781 long long a;
9782 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9783 }
9784
9785 /**
9786 + * atomic64_add_unchecked - add integer to atomic64 variable
9787 + * @i: integer value to add
9788 + * @v: pointer to type atomic64_unchecked_t
9789 + *
9790 + * Atomically adds @i to @v.
9791 + */
9792 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9793 +{
9794 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9795 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9796 + ASM_NO_INPUT_CLOBBER("memory"));
9797 + return i;
9798 +}
9799 +
9800 +/**
9801 * atomic64_sub - subtract the atomic64 variable
9802 * @i: integer value to subtract
9803 * @v: pointer to type atomic64_t
9804 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9805 index 0e1cbfc..5623683 100644
9806 --- a/arch/x86/include/asm/atomic64_64.h
9807 +++ b/arch/x86/include/asm/atomic64_64.h
9808 @@ -18,7 +18,19 @@
9809 */
9810 static inline long atomic64_read(const atomic64_t *v)
9811 {
9812 - return (*(volatile long *)&(v)->counter);
9813 + return (*(volatile const long *)&(v)->counter);
9814 +}
9815 +
9816 +/**
9817 + * atomic64_read_unchecked - read atomic64 variable
9818 + * @v: pointer of type atomic64_unchecked_t
9819 + *
9820 + * Atomically reads the value of @v.
9821 + * Doesn't imply a read memory barrier.
9822 + */
9823 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9824 +{
9825 + return (*(volatile const long *)&(v)->counter);
9826 }
9827
9828 /**
9829 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9830 }
9831
9832 /**
9833 + * atomic64_set_unchecked - set atomic64 variable
9834 + * @v: pointer to type atomic64_unchecked_t
9835 + * @i: required value
9836 + *
9837 + * Atomically sets the value of @v to @i.
9838 + */
9839 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9840 +{
9841 + v->counter = i;
9842 +}
9843 +
9844 +/**
9845 * atomic64_add - add integer to atomic64 variable
9846 * @i: integer value to add
9847 * @v: pointer to type atomic64_t
9848 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9849 */
9850 static inline void atomic64_add(long i, atomic64_t *v)
9851 {
9852 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9853 +
9854 +#ifdef CONFIG_PAX_REFCOUNT
9855 + "jno 0f\n"
9856 + LOCK_PREFIX "subq %1,%0\n"
9857 + "int $4\n0:\n"
9858 + _ASM_EXTABLE(0b, 0b)
9859 +#endif
9860 +
9861 + : "=m" (v->counter)
9862 + : "er" (i), "m" (v->counter));
9863 +}
9864 +
9865 +/**
9866 + * atomic64_add_unchecked - add integer to atomic64 variable
9867 + * @i: integer value to add
9868 + * @v: pointer to type atomic64_unchecked_t
9869 + *
9870 + * Atomically adds @i to @v.
9871 + */
9872 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9873 +{
9874 asm volatile(LOCK_PREFIX "addq %1,%0"
9875 : "=m" (v->counter)
9876 : "er" (i), "m" (v->counter));
9877 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9878 */
9879 static inline void atomic64_sub(long i, atomic64_t *v)
9880 {
9881 - asm volatile(LOCK_PREFIX "subq %1,%0"
9882 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9883 +
9884 +#ifdef CONFIG_PAX_REFCOUNT
9885 + "jno 0f\n"
9886 + LOCK_PREFIX "addq %1,%0\n"
9887 + "int $4\n0:\n"
9888 + _ASM_EXTABLE(0b, 0b)
9889 +#endif
9890 +
9891 + : "=m" (v->counter)
9892 + : "er" (i), "m" (v->counter));
9893 +}
9894 +
9895 +/**
9896 + * atomic64_sub_unchecked - subtract the atomic64 variable
9897 + * @i: integer value to subtract
9898 + * @v: pointer to type atomic64_unchecked_t
9899 + *
9900 + * Atomically subtracts @i from @v.
9901 + */
9902 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9903 +{
9904 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9905 : "=m" (v->counter)
9906 : "er" (i), "m" (v->counter));
9907 }
9908 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9909 {
9910 unsigned char c;
9911
9912 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9913 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9914 +
9915 +#ifdef CONFIG_PAX_REFCOUNT
9916 + "jno 0f\n"
9917 + LOCK_PREFIX "addq %2,%0\n"
9918 + "int $4\n0:\n"
9919 + _ASM_EXTABLE(0b, 0b)
9920 +#endif
9921 +
9922 + "sete %1\n"
9923 : "=m" (v->counter), "=qm" (c)
9924 : "er" (i), "m" (v->counter) : "memory");
9925 return c;
9926 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9927 */
9928 static inline void atomic64_inc(atomic64_t *v)
9929 {
9930 + asm volatile(LOCK_PREFIX "incq %0\n"
9931 +
9932 +#ifdef CONFIG_PAX_REFCOUNT
9933 + "jno 0f\n"
9934 + LOCK_PREFIX "decq %0\n"
9935 + "int $4\n0:\n"
9936 + _ASM_EXTABLE(0b, 0b)
9937 +#endif
9938 +
9939 + : "=m" (v->counter)
9940 + : "m" (v->counter));
9941 +}
9942 +
9943 +/**
9944 + * atomic64_inc_unchecked - increment atomic64 variable
9945 + * @v: pointer to type atomic64_unchecked_t
9946 + *
9947 + * Atomically increments @v by 1.
9948 + */
9949 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9950 +{
9951 asm volatile(LOCK_PREFIX "incq %0"
9952 : "=m" (v->counter)
9953 : "m" (v->counter));
9954 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9955 */
9956 static inline void atomic64_dec(atomic64_t *v)
9957 {
9958 - asm volatile(LOCK_PREFIX "decq %0"
9959 + asm volatile(LOCK_PREFIX "decq %0\n"
9960 +
9961 +#ifdef CONFIG_PAX_REFCOUNT
9962 + "jno 0f\n"
9963 + LOCK_PREFIX "incq %0\n"
9964 + "int $4\n0:\n"
9965 + _ASM_EXTABLE(0b, 0b)
9966 +#endif
9967 +
9968 + : "=m" (v->counter)
9969 + : "m" (v->counter));
9970 +}
9971 +
9972 +/**
9973 + * atomic64_dec_unchecked - decrement atomic64 variable
9974 + * @v: pointer to type atomic64_t
9975 + *
9976 + * Atomically decrements @v by 1.
9977 + */
9978 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9979 +{
9980 + asm volatile(LOCK_PREFIX "decq %0\n"
9981 : "=m" (v->counter)
9982 : "m" (v->counter));
9983 }
9984 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9985 {
9986 unsigned char c;
9987
9988 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9989 + asm volatile(LOCK_PREFIX "decq %0\n"
9990 +
9991 +#ifdef CONFIG_PAX_REFCOUNT
9992 + "jno 0f\n"
9993 + LOCK_PREFIX "incq %0\n"
9994 + "int $4\n0:\n"
9995 + _ASM_EXTABLE(0b, 0b)
9996 +#endif
9997 +
9998 + "sete %1\n"
9999 : "=m" (v->counter), "=qm" (c)
10000 : "m" (v->counter) : "memory");
10001 return c != 0;
10002 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10003 {
10004 unsigned char c;
10005
10006 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
10007 + asm volatile(LOCK_PREFIX "incq %0\n"
10008 +
10009 +#ifdef CONFIG_PAX_REFCOUNT
10010 + "jno 0f\n"
10011 + LOCK_PREFIX "decq %0\n"
10012 + "int $4\n0:\n"
10013 + _ASM_EXTABLE(0b, 0b)
10014 +#endif
10015 +
10016 + "sete %1\n"
10017 : "=m" (v->counter), "=qm" (c)
10018 : "m" (v->counter) : "memory");
10019 return c != 0;
10020 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10021 {
10022 unsigned char c;
10023
10024 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10025 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10026 +
10027 +#ifdef CONFIG_PAX_REFCOUNT
10028 + "jno 0f\n"
10029 + LOCK_PREFIX "subq %2,%0\n"
10030 + "int $4\n0:\n"
10031 + _ASM_EXTABLE(0b, 0b)
10032 +#endif
10033 +
10034 + "sets %1\n"
10035 : "=m" (v->counter), "=qm" (c)
10036 : "er" (i), "m" (v->counter) : "memory");
10037 return c;
10038 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10039 */
10040 static inline long atomic64_add_return(long i, atomic64_t *v)
10041 {
10042 + return i + xadd_check_overflow(&v->counter, i);
10043 +}
10044 +
10045 +/**
10046 + * atomic64_add_return_unchecked - add and return
10047 + * @i: integer value to add
10048 + * @v: pointer to type atomic64_unchecked_t
10049 + *
10050 + * Atomically adds @i to @v and returns @i + @v
10051 + */
10052 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10053 +{
10054 return i + xadd(&v->counter, i);
10055 }
10056
10057 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10058 }
10059
10060 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10061 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10062 +{
10063 + return atomic64_add_return_unchecked(1, v);
10064 +}
10065 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10066
10067 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10068 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10069 return cmpxchg(&v->counter, old, new);
10070 }
10071
10072 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10073 +{
10074 + return cmpxchg(&v->counter, old, new);
10075 +}
10076 +
10077 static inline long atomic64_xchg(atomic64_t *v, long new)
10078 {
10079 return xchg(&v->counter, new);
10080 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10081 */
10082 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10083 {
10084 - long c, old;
10085 + long c, old, new;
10086 c = atomic64_read(v);
10087 for (;;) {
10088 - if (unlikely(c == (u)))
10089 + if (unlikely(c == u))
10090 break;
10091 - old = atomic64_cmpxchg((v), c, c + (a));
10092 +
10093 + asm volatile("add %2,%0\n"
10094 +
10095 +#ifdef CONFIG_PAX_REFCOUNT
10096 + "jno 0f\n"
10097 + "sub %2,%0\n"
10098 + "int $4\n0:\n"
10099 + _ASM_EXTABLE(0b, 0b)
10100 +#endif
10101 +
10102 + : "=r" (new)
10103 + : "0" (c), "ir" (a));
10104 +
10105 + old = atomic64_cmpxchg(v, c, new);
10106 if (likely(old == c))
10107 break;
10108 c = old;
10109 }
10110 - return c != (u);
10111 + return c != u;
10112 }
10113
10114 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10115 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10116 index 6dfd019..0c6699f 100644
10117 --- a/arch/x86/include/asm/bitops.h
10118 +++ b/arch/x86/include/asm/bitops.h
10119 @@ -40,7 +40,7 @@
10120 * a mask operation on a byte.
10121 */
10122 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10123 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10124 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10125 #define CONST_MASK(nr) (1 << ((nr) & 7))
10126
10127 /**
10128 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10129 index b13fe63..0dab13a 100644
10130 --- a/arch/x86/include/asm/boot.h
10131 +++ b/arch/x86/include/asm/boot.h
10132 @@ -11,10 +11,15 @@
10133 #include <asm/pgtable_types.h>
10134
10135 /* Physical address where kernel should be loaded. */
10136 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10137 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10138 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10139 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10140
10141 +#ifndef __ASSEMBLY__
10142 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10143 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10144 +#endif
10145 +
10146 /* Minimum kernel alignment, as a power of two */
10147 #ifdef CONFIG_X86_64
10148 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10149 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10150 index 48f99f1..d78ebf9 100644
10151 --- a/arch/x86/include/asm/cache.h
10152 +++ b/arch/x86/include/asm/cache.h
10153 @@ -5,12 +5,13 @@
10154
10155 /* L1 cache line size */
10156 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10157 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10158 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10159
10160 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10161 +#define __read_only __attribute__((__section__(".data..read_only")))
10162
10163 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10164 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10165 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10166
10167 #ifdef CONFIG_X86_VSMP
10168 #ifdef CONFIG_SMP
10169 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10170 index 9863ee3..4a1f8e1 100644
10171 --- a/arch/x86/include/asm/cacheflush.h
10172 +++ b/arch/x86/include/asm/cacheflush.h
10173 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10174 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10175
10176 if (pg_flags == _PGMT_DEFAULT)
10177 - return -1;
10178 + return ~0UL;
10179 else if (pg_flags == _PGMT_WC)
10180 return _PAGE_CACHE_WC;
10181 else if (pg_flags == _PGMT_UC_MINUS)
10182 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10183 index 46fc474..b02b0f9 100644
10184 --- a/arch/x86/include/asm/checksum_32.h
10185 +++ b/arch/x86/include/asm/checksum_32.h
10186 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10187 int len, __wsum sum,
10188 int *src_err_ptr, int *dst_err_ptr);
10189
10190 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10191 + int len, __wsum sum,
10192 + int *src_err_ptr, int *dst_err_ptr);
10193 +
10194 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10195 + int len, __wsum sum,
10196 + int *src_err_ptr, int *dst_err_ptr);
10197 +
10198 /*
10199 * Note: when you get a NULL pointer exception here this means someone
10200 * passed in an incorrect kernel address to one of these functions.
10201 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10202 int *err_ptr)
10203 {
10204 might_sleep();
10205 - return csum_partial_copy_generic((__force void *)src, dst,
10206 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10207 len, sum, err_ptr, NULL);
10208 }
10209
10210 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10211 {
10212 might_sleep();
10213 if (access_ok(VERIFY_WRITE, dst, len))
10214 - return csum_partial_copy_generic(src, (__force void *)dst,
10215 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10216 len, sum, NULL, err_ptr);
10217
10218 if (len)
10219 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10220 index 8d871ea..c1a0dc9 100644
10221 --- a/arch/x86/include/asm/cmpxchg.h
10222 +++ b/arch/x86/include/asm/cmpxchg.h
10223 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10224 __compiletime_error("Bad argument size for cmpxchg");
10225 extern void __xadd_wrong_size(void)
10226 __compiletime_error("Bad argument size for xadd");
10227 +extern void __xadd_check_overflow_wrong_size(void)
10228 + __compiletime_error("Bad argument size for xadd_check_overflow");
10229 extern void __add_wrong_size(void)
10230 __compiletime_error("Bad argument size for add");
10231 +extern void __add_check_overflow_wrong_size(void)
10232 + __compiletime_error("Bad argument size for add_check_overflow");
10233
10234 /*
10235 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10236 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10237 __ret; \
10238 })
10239
10240 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10241 + ({ \
10242 + __typeof__ (*(ptr)) __ret = (arg); \
10243 + switch (sizeof(*(ptr))) { \
10244 + case __X86_CASE_L: \
10245 + asm volatile (lock #op "l %0, %1\n" \
10246 + "jno 0f\n" \
10247 + "mov %0,%1\n" \
10248 + "int $4\n0:\n" \
10249 + _ASM_EXTABLE(0b, 0b) \
10250 + : "+r" (__ret), "+m" (*(ptr)) \
10251 + : : "memory", "cc"); \
10252 + break; \
10253 + case __X86_CASE_Q: \
10254 + asm volatile (lock #op "q %q0, %1\n" \
10255 + "jno 0f\n" \
10256 + "mov %0,%1\n" \
10257 + "int $4\n0:\n" \
10258 + _ASM_EXTABLE(0b, 0b) \
10259 + : "+r" (__ret), "+m" (*(ptr)) \
10260 + : : "memory", "cc"); \
10261 + break; \
10262 + default: \
10263 + __ ## op ## _check_overflow_wrong_size(); \
10264 + } \
10265 + __ret; \
10266 + })
10267 +
10268 /*
10269 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10270 * Since this is generally used to protect other memory information, we
10271 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10272 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10273 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10274
10275 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10276 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10277 +
10278 #define __add(ptr, inc, lock) \
10279 ({ \
10280 __typeof__ (*(ptr)) __ret = (inc); \
10281 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10282 index 8c297aa..7a90f03 100644
10283 --- a/arch/x86/include/asm/cpufeature.h
10284 +++ b/arch/x86/include/asm/cpufeature.h
10285 @@ -205,7 +205,7 @@
10286 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10287 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10288 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10289 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10290 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10291 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10292 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10293 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10294 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10295 ".section .discard,\"aw\",@progbits\n"
10296 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10297 ".previous\n"
10298 - ".section .altinstr_replacement,\"ax\"\n"
10299 + ".section .altinstr_replacement,\"a\"\n"
10300 "3: movb $1,%0\n"
10301 "4:\n"
10302 ".previous\n"
10303 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10304 index 8bf1c06..f723dfd 100644
10305 --- a/arch/x86/include/asm/desc.h
10306 +++ b/arch/x86/include/asm/desc.h
10307 @@ -4,6 +4,7 @@
10308 #include <asm/desc_defs.h>
10309 #include <asm/ldt.h>
10310 #include <asm/mmu.h>
10311 +#include <asm/pgtable.h>
10312
10313 #include <linux/smp.h>
10314 #include <linux/percpu.h>
10315 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10316
10317 desc->type = (info->read_exec_only ^ 1) << 1;
10318 desc->type |= info->contents << 2;
10319 + desc->type |= info->seg_not_present ^ 1;
10320
10321 desc->s = 1;
10322 desc->dpl = 0x3;
10323 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10324 }
10325
10326 extern struct desc_ptr idt_descr;
10327 -extern gate_desc idt_table[];
10328 extern struct desc_ptr nmi_idt_descr;
10329 -extern gate_desc nmi_idt_table[];
10330 -
10331 -struct gdt_page {
10332 - struct desc_struct gdt[GDT_ENTRIES];
10333 -} __attribute__((aligned(PAGE_SIZE)));
10334 -
10335 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10336 +extern gate_desc idt_table[256];
10337 +extern gate_desc nmi_idt_table[256];
10338
10339 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10340 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10341 {
10342 - return per_cpu(gdt_page, cpu).gdt;
10343 + return cpu_gdt_table[cpu];
10344 }
10345
10346 #ifdef CONFIG_X86_64
10347 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10348 unsigned long base, unsigned dpl, unsigned flags,
10349 unsigned short seg)
10350 {
10351 - gate->a = (seg << 16) | (base & 0xffff);
10352 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10353 + gate->gate.offset_low = base;
10354 + gate->gate.seg = seg;
10355 + gate->gate.reserved = 0;
10356 + gate->gate.type = type;
10357 + gate->gate.s = 0;
10358 + gate->gate.dpl = dpl;
10359 + gate->gate.p = 1;
10360 + gate->gate.offset_high = base >> 16;
10361 }
10362
10363 #endif
10364 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10365
10366 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10367 {
10368 + pax_open_kernel();
10369 memcpy(&idt[entry], gate, sizeof(*gate));
10370 + pax_close_kernel();
10371 }
10372
10373 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10374 {
10375 + pax_open_kernel();
10376 memcpy(&ldt[entry], desc, 8);
10377 + pax_close_kernel();
10378 }
10379
10380 static inline void
10381 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10382 default: size = sizeof(*gdt); break;
10383 }
10384
10385 + pax_open_kernel();
10386 memcpy(&gdt[entry], desc, size);
10387 + pax_close_kernel();
10388 }
10389
10390 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10391 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10392
10393 static inline void native_load_tr_desc(void)
10394 {
10395 + pax_open_kernel();
10396 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10397 + pax_close_kernel();
10398 }
10399
10400 static inline void native_load_gdt(const struct desc_ptr *dtr)
10401 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10402 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10403 unsigned int i;
10404
10405 + pax_open_kernel();
10406 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10407 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10408 + pax_close_kernel();
10409 }
10410
10411 #define _LDT_empty(info) \
10412 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10413 }
10414
10415 #ifdef CONFIG_X86_64
10416 -static inline void set_nmi_gate(int gate, void *addr)
10417 +static inline void set_nmi_gate(int gate, const void *addr)
10418 {
10419 gate_desc s;
10420
10421 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10422 }
10423 #endif
10424
10425 -static inline void _set_gate(int gate, unsigned type, void *addr,
10426 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10427 unsigned dpl, unsigned ist, unsigned seg)
10428 {
10429 gate_desc s;
10430 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10431 * Pentium F0 0F bugfix can have resulted in the mapped
10432 * IDT being write-protected.
10433 */
10434 -static inline void set_intr_gate(unsigned int n, void *addr)
10435 +static inline void set_intr_gate(unsigned int n, const void *addr)
10436 {
10437 BUG_ON((unsigned)n > 0xFF);
10438 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10439 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10440 /*
10441 * This routine sets up an interrupt gate at directory privilege level 3.
10442 */
10443 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10444 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10445 {
10446 BUG_ON((unsigned)n > 0xFF);
10447 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10448 }
10449
10450 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10451 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10452 {
10453 BUG_ON((unsigned)n > 0xFF);
10454 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10455 }
10456
10457 -static inline void set_trap_gate(unsigned int n, void *addr)
10458 +static inline void set_trap_gate(unsigned int n, const void *addr)
10459 {
10460 BUG_ON((unsigned)n > 0xFF);
10461 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10462 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10463 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10464 {
10465 BUG_ON((unsigned)n > 0xFF);
10466 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10467 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10468 }
10469
10470 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10471 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10472 {
10473 BUG_ON((unsigned)n > 0xFF);
10474 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10475 }
10476
10477 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10478 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10479 {
10480 BUG_ON((unsigned)n > 0xFF);
10481 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10482 }
10483
10484 +#ifdef CONFIG_X86_32
10485 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10486 +{
10487 + struct desc_struct d;
10488 +
10489 + if (likely(limit))
10490 + limit = (limit - 1UL) >> PAGE_SHIFT;
10491 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10492 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10493 +}
10494 +#endif
10495 +
10496 #endif /* _ASM_X86_DESC_H */
10497 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10498 index 278441f..b95a174 100644
10499 --- a/arch/x86/include/asm/desc_defs.h
10500 +++ b/arch/x86/include/asm/desc_defs.h
10501 @@ -31,6 +31,12 @@ struct desc_struct {
10502 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10503 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10504 };
10505 + struct {
10506 + u16 offset_low;
10507 + u16 seg;
10508 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10509 + unsigned offset_high: 16;
10510 + } gate;
10511 };
10512 } __attribute__((packed));
10513
10514 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10515 index 3778256..c5d4fce 100644
10516 --- a/arch/x86/include/asm/e820.h
10517 +++ b/arch/x86/include/asm/e820.h
10518 @@ -69,7 +69,7 @@ struct e820map {
10519 #define ISA_START_ADDRESS 0xa0000
10520 #define ISA_END_ADDRESS 0x100000
10521
10522 -#define BIOS_BEGIN 0x000a0000
10523 +#define BIOS_BEGIN 0x000c0000
10524 #define BIOS_END 0x00100000
10525
10526 #define BIOS_ROM_BASE 0xffe00000
10527 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10528 index 5939f44..f8845f6 100644
10529 --- a/arch/x86/include/asm/elf.h
10530 +++ b/arch/x86/include/asm/elf.h
10531 @@ -243,7 +243,25 @@ extern int force_personality32;
10532 the loader. We need to make sure that it is out of the way of the program
10533 that it will "exec", and that there is sufficient room for the brk. */
10534
10535 +#ifdef CONFIG_PAX_SEGMEXEC
10536 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10537 +#else
10538 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10539 +#endif
10540 +
10541 +#ifdef CONFIG_PAX_ASLR
10542 +#ifdef CONFIG_X86_32
10543 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10544 +
10545 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10546 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10547 +#else
10548 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10549 +
10550 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10551 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10552 +#endif
10553 +#endif
10554
10555 /* This yields a mask that user programs can use to figure out what
10556 instruction set this CPU supports. This could be done in user space,
10557 @@ -296,16 +314,12 @@ do { \
10558
10559 #define ARCH_DLINFO \
10560 do { \
10561 - if (vdso_enabled) \
10562 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10563 - (unsigned long)current->mm->context.vdso); \
10564 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10565 } while (0)
10566
10567 #define ARCH_DLINFO_X32 \
10568 do { \
10569 - if (vdso_enabled) \
10570 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10571 - (unsigned long)current->mm->context.vdso); \
10572 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10573 } while (0)
10574
10575 #define AT_SYSINFO 32
10576 @@ -320,7 +334,7 @@ else \
10577
10578 #endif /* !CONFIG_X86_32 */
10579
10580 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10581 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10582
10583 #define VDSO_ENTRY \
10584 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10585 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10586 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10587 #define compat_arch_setup_additional_pages syscall32_setup_pages
10588
10589 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10590 -#define arch_randomize_brk arch_randomize_brk
10591 -
10592 /*
10593 * True on X86_32 or when emulating IA32 on X86_64
10594 */
10595 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10596 index 75ce3f4..882e801 100644
10597 --- a/arch/x86/include/asm/emergency-restart.h
10598 +++ b/arch/x86/include/asm/emergency-restart.h
10599 @@ -13,6 +13,6 @@ enum reboot_type {
10600
10601 extern enum reboot_type reboot_type;
10602
10603 -extern void machine_emergency_restart(void);
10604 +extern void machine_emergency_restart(void) __noreturn;
10605
10606 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10607 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10608 index 41ab26e..a88c9e6 100644
10609 --- a/arch/x86/include/asm/fpu-internal.h
10610 +++ b/arch/x86/include/asm/fpu-internal.h
10611 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
10612 ({ \
10613 int err; \
10614 asm volatile(ASM_STAC "\n" \
10615 - "1:" #insn "\n\t" \
10616 + "1:" \
10617 + __copyuser_seg \
10618 + #insn "\n\t" \
10619 "2: " ASM_CLAC "\n" \
10620 ".section .fixup,\"ax\"\n" \
10621 "3: movl $-1,%[err]\n" \
10622 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10623 "emms\n\t" /* clear stack tags */
10624 "fildl %P[addr]", /* set F?P to defined value */
10625 X86_FEATURE_FXSAVE_LEAK,
10626 - [addr] "m" (tsk->thread.fpu.has_fpu));
10627 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
10628
10629 return fpu_restore_checking(&tsk->thread.fpu);
10630 }
10631 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10632 index f373046..02653e2 100644
10633 --- a/arch/x86/include/asm/futex.h
10634 +++ b/arch/x86/include/asm/futex.h
10635 @@ -12,6 +12,7 @@
10636 #include <asm/smap.h>
10637
10638 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10639 + typecheck(u32 __user *, uaddr); \
10640 asm volatile("\t" ASM_STAC "\n" \
10641 "1:\t" insn "\n" \
10642 "2:\t" ASM_CLAC "\n" \
10643 @@ -20,15 +21,16 @@
10644 "\tjmp\t2b\n" \
10645 "\t.previous\n" \
10646 _ASM_EXTABLE(1b, 3b) \
10647 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10648 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
10649 : "i" (-EFAULT), "0" (oparg), "1" (0))
10650
10651 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10652 + typecheck(u32 __user *, uaddr); \
10653 asm volatile("\t" ASM_STAC "\n" \
10654 "1:\tmovl %2, %0\n" \
10655 "\tmovl\t%0, %3\n" \
10656 "\t" insn "\n" \
10657 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
10658 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
10659 "\tjnz\t1b\n" \
10660 "3:\t" ASM_CLAC "\n" \
10661 "\t.section .fixup,\"ax\"\n" \
10662 @@ -38,7 +40,7 @@
10663 _ASM_EXTABLE(1b, 4b) \
10664 _ASM_EXTABLE(2b, 4b) \
10665 : "=&a" (oldval), "=&r" (ret), \
10666 - "+m" (*uaddr), "=&r" (tem) \
10667 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10668 : "r" (oparg), "i" (-EFAULT), "1" (0))
10669
10670 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10671 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10672
10673 switch (op) {
10674 case FUTEX_OP_SET:
10675 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10676 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10677 break;
10678 case FUTEX_OP_ADD:
10679 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10680 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10681 uaddr, oparg);
10682 break;
10683 case FUTEX_OP_OR:
10684 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10685 return -EFAULT;
10686
10687 asm volatile("\t" ASM_STAC "\n"
10688 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10689 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10690 "2:\t" ASM_CLAC "\n"
10691 "\t.section .fixup, \"ax\"\n"
10692 "3:\tmov %3, %0\n"
10693 "\tjmp 2b\n"
10694 "\t.previous\n"
10695 _ASM_EXTABLE(1b, 3b)
10696 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10697 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10698 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10699 : "memory"
10700 );
10701 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10702 index eb92a6e..b98b2f4 100644
10703 --- a/arch/x86/include/asm/hw_irq.h
10704 +++ b/arch/x86/include/asm/hw_irq.h
10705 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10706 extern void enable_IO_APIC(void);
10707
10708 /* Statistics */
10709 -extern atomic_t irq_err_count;
10710 -extern atomic_t irq_mis_count;
10711 +extern atomic_unchecked_t irq_err_count;
10712 +extern atomic_unchecked_t irq_mis_count;
10713
10714 /* EISA */
10715 extern void eisa_set_level_irq(unsigned int irq);
10716 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10717 index d8e8eef..99f81ae 100644
10718 --- a/arch/x86/include/asm/io.h
10719 +++ b/arch/x86/include/asm/io.h
10720 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10721
10722 #include <linux/vmalloc.h>
10723
10724 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10725 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10726 +{
10727 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10728 +}
10729 +
10730 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10731 +{
10732 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10733 +}
10734 +
10735 /*
10736 * Convert a virtual cached pointer to an uncached pointer
10737 */
10738 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10739 index bba3cf8..06bc8da 100644
10740 --- a/arch/x86/include/asm/irqflags.h
10741 +++ b/arch/x86/include/asm/irqflags.h
10742 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10743 sti; \
10744 sysexit
10745
10746 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10747 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10748 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10749 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10750 +
10751 #else
10752 #define INTERRUPT_RETURN iret
10753 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10754 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10755 index d3ddd17..c9fb0cc 100644
10756 --- a/arch/x86/include/asm/kprobes.h
10757 +++ b/arch/x86/include/asm/kprobes.h
10758 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
10759 #define RELATIVEJUMP_SIZE 5
10760 #define RELATIVECALL_OPCODE 0xe8
10761 #define RELATIVE_ADDR_SIZE 4
10762 -#define MAX_STACK_SIZE 64
10763 -#define MIN_STACK_SIZE(ADDR) \
10764 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10765 - THREAD_SIZE - (unsigned long)(ADDR))) \
10766 - ? (MAX_STACK_SIZE) \
10767 - : (((unsigned long)current_thread_info()) + \
10768 - THREAD_SIZE - (unsigned long)(ADDR)))
10769 +#define MAX_STACK_SIZE 64UL
10770 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10771
10772 #define flush_insn_slot(p) do { } while (0)
10773
10774 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10775 index b2e11f4..f293e2e 100644
10776 --- a/arch/x86/include/asm/kvm_host.h
10777 +++ b/arch/x86/include/asm/kvm_host.h
10778 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
10779 int (*check_intercept)(struct kvm_vcpu *vcpu,
10780 struct x86_instruction_info *info,
10781 enum x86_intercept_stage stage);
10782 -};
10783 +} __do_const;
10784
10785 struct kvm_arch_async_pf {
10786 u32 token;
10787 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10788 index c8bed0d..85c03fd 100644
10789 --- a/arch/x86/include/asm/local.h
10790 +++ b/arch/x86/include/asm/local.h
10791 @@ -10,33 +10,97 @@ typedef struct {
10792 atomic_long_t a;
10793 } local_t;
10794
10795 +typedef struct {
10796 + atomic_long_unchecked_t a;
10797 +} local_unchecked_t;
10798 +
10799 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
10800
10801 #define local_read(l) atomic_long_read(&(l)->a)
10802 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
10803 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
10804 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
10805
10806 static inline void local_inc(local_t *l)
10807 {
10808 - asm volatile(_ASM_INC "%0"
10809 + asm volatile(_ASM_INC "%0\n"
10810 +
10811 +#ifdef CONFIG_PAX_REFCOUNT
10812 + "jno 0f\n"
10813 + _ASM_DEC "%0\n"
10814 + "int $4\n0:\n"
10815 + _ASM_EXTABLE(0b, 0b)
10816 +#endif
10817 +
10818 + : "+m" (l->a.counter));
10819 +}
10820 +
10821 +static inline void local_inc_unchecked(local_unchecked_t *l)
10822 +{
10823 + asm volatile(_ASM_INC "%0\n"
10824 : "+m" (l->a.counter));
10825 }
10826
10827 static inline void local_dec(local_t *l)
10828 {
10829 - asm volatile(_ASM_DEC "%0"
10830 + asm volatile(_ASM_DEC "%0\n"
10831 +
10832 +#ifdef CONFIG_PAX_REFCOUNT
10833 + "jno 0f\n"
10834 + _ASM_INC "%0\n"
10835 + "int $4\n0:\n"
10836 + _ASM_EXTABLE(0b, 0b)
10837 +#endif
10838 +
10839 + : "+m" (l->a.counter));
10840 +}
10841 +
10842 +static inline void local_dec_unchecked(local_unchecked_t *l)
10843 +{
10844 + asm volatile(_ASM_DEC "%0\n"
10845 : "+m" (l->a.counter));
10846 }
10847
10848 static inline void local_add(long i, local_t *l)
10849 {
10850 - asm volatile(_ASM_ADD "%1,%0"
10851 + asm volatile(_ASM_ADD "%1,%0\n"
10852 +
10853 +#ifdef CONFIG_PAX_REFCOUNT
10854 + "jno 0f\n"
10855 + _ASM_SUB "%1,%0\n"
10856 + "int $4\n0:\n"
10857 + _ASM_EXTABLE(0b, 0b)
10858 +#endif
10859 +
10860 + : "+m" (l->a.counter)
10861 + : "ir" (i));
10862 +}
10863 +
10864 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
10865 +{
10866 + asm volatile(_ASM_ADD "%1,%0\n"
10867 : "+m" (l->a.counter)
10868 : "ir" (i));
10869 }
10870
10871 static inline void local_sub(long i, local_t *l)
10872 {
10873 - asm volatile(_ASM_SUB "%1,%0"
10874 + asm volatile(_ASM_SUB "%1,%0\n"
10875 +
10876 +#ifdef CONFIG_PAX_REFCOUNT
10877 + "jno 0f\n"
10878 + _ASM_ADD "%1,%0\n"
10879 + "int $4\n0:\n"
10880 + _ASM_EXTABLE(0b, 0b)
10881 +#endif
10882 +
10883 + : "+m" (l->a.counter)
10884 + : "ir" (i));
10885 +}
10886 +
10887 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
10888 +{
10889 + asm volatile(_ASM_SUB "%1,%0\n"
10890 : "+m" (l->a.counter)
10891 : "ir" (i));
10892 }
10893 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10894 {
10895 unsigned char c;
10896
10897 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10898 + asm volatile(_ASM_SUB "%2,%0\n"
10899 +
10900 +#ifdef CONFIG_PAX_REFCOUNT
10901 + "jno 0f\n"
10902 + _ASM_ADD "%2,%0\n"
10903 + "int $4\n0:\n"
10904 + _ASM_EXTABLE(0b, 0b)
10905 +#endif
10906 +
10907 + "sete %1\n"
10908 : "+m" (l->a.counter), "=qm" (c)
10909 : "ir" (i) : "memory");
10910 return c;
10911 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
10912 {
10913 unsigned char c;
10914
10915 - asm volatile(_ASM_DEC "%0; sete %1"
10916 + asm volatile(_ASM_DEC "%0\n"
10917 +
10918 +#ifdef CONFIG_PAX_REFCOUNT
10919 + "jno 0f\n"
10920 + _ASM_INC "%0\n"
10921 + "int $4\n0:\n"
10922 + _ASM_EXTABLE(0b, 0b)
10923 +#endif
10924 +
10925 + "sete %1\n"
10926 : "+m" (l->a.counter), "=qm" (c)
10927 : : "memory");
10928 return c != 0;
10929 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
10930 {
10931 unsigned char c;
10932
10933 - asm volatile(_ASM_INC "%0; sete %1"
10934 + asm volatile(_ASM_INC "%0\n"
10935 +
10936 +#ifdef CONFIG_PAX_REFCOUNT
10937 + "jno 0f\n"
10938 + _ASM_DEC "%0\n"
10939 + "int $4\n0:\n"
10940 + _ASM_EXTABLE(0b, 0b)
10941 +#endif
10942 +
10943 + "sete %1\n"
10944 : "+m" (l->a.counter), "=qm" (c)
10945 : : "memory");
10946 return c != 0;
10947 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
10948 {
10949 unsigned char c;
10950
10951 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10952 + asm volatile(_ASM_ADD "%2,%0\n"
10953 +
10954 +#ifdef CONFIG_PAX_REFCOUNT
10955 + "jno 0f\n"
10956 + _ASM_SUB "%2,%0\n"
10957 + "int $4\n0:\n"
10958 + _ASM_EXTABLE(0b, 0b)
10959 +#endif
10960 +
10961 + "sets %1\n"
10962 : "+m" (l->a.counter), "=qm" (c)
10963 : "ir" (i) : "memory");
10964 return c;
10965 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
10966 #endif
10967 /* Modern 486+ processor */
10968 __i = i;
10969 - asm volatile(_ASM_XADD "%0, %1;"
10970 + asm volatile(_ASM_XADD "%0, %1\n"
10971 +
10972 +#ifdef CONFIG_PAX_REFCOUNT
10973 + "jno 0f\n"
10974 + _ASM_MOV "%0,%1\n"
10975 + "int $4\n0:\n"
10976 + _ASM_EXTABLE(0b, 0b)
10977 +#endif
10978 +
10979 : "+r" (i), "+m" (l->a.counter)
10980 : : "memory");
10981 return i + __i;
10982 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
10983 #endif
10984 }
10985
10986 +/**
10987 + * local_add_return_unchecked - add and return
10988 + * @i: integer value to add
10989 + * @l: pointer to type local_unchecked_t
10990 + *
10991 + * Atomically adds @i to @l and returns @i + @l
10992 + */
10993 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
10994 +{
10995 + long __i;
10996 +#ifdef CONFIG_M386
10997 + unsigned long flags;
10998 + if (unlikely(boot_cpu_data.x86 <= 3))
10999 + goto no_xadd;
11000 +#endif
11001 + /* Modern 486+ processor */
11002 + __i = i;
11003 + asm volatile(_ASM_XADD "%0, %1\n"
11004 + : "+r" (i), "+m" (l->a.counter)
11005 + : : "memory");
11006 + return i + __i;
11007 +
11008 +#ifdef CONFIG_M386
11009 +no_xadd: /* Legacy 386 processor */
11010 + local_irq_save(flags);
11011 + __i = local_read_unchecked(l);
11012 + local_set_unchecked(l, i + __i);
11013 + local_irq_restore(flags);
11014 + return i + __i;
11015 +#endif
11016 +}
11017 +
11018 static inline long local_sub_return(long i, local_t *l)
11019 {
11020 return local_add_return(-i, l);
11021 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
11022
11023 #define local_cmpxchg(l, o, n) \
11024 (cmpxchg_local(&((l)->a.counter), (o), (n)))
11025 +#define local_cmpxchg_unchecked(l, o, n) \
11026 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
11027 /* Always has a lock prefix */
11028 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
11029
11030 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
11031 index 593e51d..fa69c9a 100644
11032 --- a/arch/x86/include/asm/mman.h
11033 +++ b/arch/x86/include/asm/mman.h
11034 @@ -5,4 +5,14 @@
11035
11036 #include <asm-generic/mman.h>
11037
11038 +#ifdef __KERNEL__
11039 +#ifndef __ASSEMBLY__
11040 +#ifdef CONFIG_X86_32
11041 +#define arch_mmap_check i386_mmap_check
11042 +int i386_mmap_check(unsigned long addr, unsigned long len,
11043 + unsigned long flags);
11044 +#endif
11045 +#endif
11046 +#endif
11047 +
11048 #endif /* _ASM_X86_MMAN_H */
11049 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11050 index 5f55e69..e20bfb1 100644
11051 --- a/arch/x86/include/asm/mmu.h
11052 +++ b/arch/x86/include/asm/mmu.h
11053 @@ -9,7 +9,7 @@
11054 * we put the segment information here.
11055 */
11056 typedef struct {
11057 - void *ldt;
11058 + struct desc_struct *ldt;
11059 int size;
11060
11061 #ifdef CONFIG_X86_64
11062 @@ -18,7 +18,19 @@ typedef struct {
11063 #endif
11064
11065 struct mutex lock;
11066 - void *vdso;
11067 + unsigned long vdso;
11068 +
11069 +#ifdef CONFIG_X86_32
11070 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11071 + unsigned long user_cs_base;
11072 + unsigned long user_cs_limit;
11073 +
11074 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11075 + cpumask_t cpu_user_cs_mask;
11076 +#endif
11077 +
11078 +#endif
11079 +#endif
11080 } mm_context_t;
11081
11082 #ifdef CONFIG_SMP
11083 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11084 index cdbf367..adb37ac 100644
11085 --- a/arch/x86/include/asm/mmu_context.h
11086 +++ b/arch/x86/include/asm/mmu_context.h
11087 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11088
11089 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11090 {
11091 +
11092 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11093 + unsigned int i;
11094 + pgd_t *pgd;
11095 +
11096 + pax_open_kernel();
11097 + pgd = get_cpu_pgd(smp_processor_id());
11098 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11099 + set_pgd_batched(pgd+i, native_make_pgd(0));
11100 + pax_close_kernel();
11101 +#endif
11102 +
11103 #ifdef CONFIG_SMP
11104 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11105 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11106 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11107 struct task_struct *tsk)
11108 {
11109 unsigned cpu = smp_processor_id();
11110 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11111 + int tlbstate = TLBSTATE_OK;
11112 +#endif
11113
11114 if (likely(prev != next)) {
11115 #ifdef CONFIG_SMP
11116 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11117 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11118 +#endif
11119 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11120 this_cpu_write(cpu_tlbstate.active_mm, next);
11121 #endif
11122 cpumask_set_cpu(cpu, mm_cpumask(next));
11123
11124 /* Re-load page tables */
11125 +#ifdef CONFIG_PAX_PER_CPU_PGD
11126 + pax_open_kernel();
11127 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11128 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11129 + pax_close_kernel();
11130 + load_cr3(get_cpu_pgd(cpu));
11131 +#else
11132 load_cr3(next->pgd);
11133 +#endif
11134
11135 /* stop flush ipis for the previous mm */
11136 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11137 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11138 */
11139 if (unlikely(prev->context.ldt != next->context.ldt))
11140 load_LDT_nolock(&next->context);
11141 - }
11142 +
11143 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11144 + if (!(__supported_pte_mask & _PAGE_NX)) {
11145 + smp_mb__before_clear_bit();
11146 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11147 + smp_mb__after_clear_bit();
11148 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11149 + }
11150 +#endif
11151 +
11152 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11153 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11154 + prev->context.user_cs_limit != next->context.user_cs_limit))
11155 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11156 #ifdef CONFIG_SMP
11157 + else if (unlikely(tlbstate != TLBSTATE_OK))
11158 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11159 +#endif
11160 +#endif
11161 +
11162 + }
11163 else {
11164 +
11165 +#ifdef CONFIG_PAX_PER_CPU_PGD
11166 + pax_open_kernel();
11167 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11168 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11169 + pax_close_kernel();
11170 + load_cr3(get_cpu_pgd(cpu));
11171 +#endif
11172 +
11173 +#ifdef CONFIG_SMP
11174 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11175 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11176
11177 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11178 * tlb flush IPI delivery. We must reload CR3
11179 * to make sure to use no freed page tables.
11180 */
11181 +
11182 +#ifndef CONFIG_PAX_PER_CPU_PGD
11183 load_cr3(next->pgd);
11184 +#endif
11185 +
11186 load_LDT_nolock(&next->context);
11187 +
11188 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11189 + if (!(__supported_pte_mask & _PAGE_NX))
11190 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11191 +#endif
11192 +
11193 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11194 +#ifdef CONFIG_PAX_PAGEEXEC
11195 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11196 +#endif
11197 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11198 +#endif
11199 +
11200 }
11201 +#endif
11202 }
11203 -#endif
11204 }
11205
11206 #define activate_mm(prev, next) \
11207 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11208 index 9eae775..c914fea 100644
11209 --- a/arch/x86/include/asm/module.h
11210 +++ b/arch/x86/include/asm/module.h
11211 @@ -5,6 +5,7 @@
11212
11213 #ifdef CONFIG_X86_64
11214 /* X86_64 does not define MODULE_PROC_FAMILY */
11215 +#define MODULE_PROC_FAMILY ""
11216 #elif defined CONFIG_M386
11217 #define MODULE_PROC_FAMILY "386 "
11218 #elif defined CONFIG_M486
11219 @@ -59,8 +60,20 @@
11220 #error unknown processor family
11221 #endif
11222
11223 -#ifdef CONFIG_X86_32
11224 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11225 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11226 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11227 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11228 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11229 +#else
11230 +#define MODULE_PAX_KERNEXEC ""
11231 #endif
11232
11233 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11234 +#define MODULE_PAX_UDEREF "UDEREF "
11235 +#else
11236 +#define MODULE_PAX_UDEREF ""
11237 +#endif
11238 +
11239 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11240 +
11241 #endif /* _ASM_X86_MODULE_H */
11242 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11243 index 320f7bb..e89f8f8 100644
11244 --- a/arch/x86/include/asm/page_64_types.h
11245 +++ b/arch/x86/include/asm/page_64_types.h
11246 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11247
11248 /* duplicated to the one in bootmem.h */
11249 extern unsigned long max_pfn;
11250 -extern unsigned long phys_base;
11251 +extern const unsigned long phys_base;
11252
11253 extern unsigned long __phys_addr(unsigned long);
11254 #define __phys_reloc_hide(x) (x)
11255 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11256 index a0facf3..c017b15 100644
11257 --- a/arch/x86/include/asm/paravirt.h
11258 +++ b/arch/x86/include/asm/paravirt.h
11259 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11260 val);
11261 }
11262
11263 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11264 +{
11265 + pgdval_t val = native_pgd_val(pgd);
11266 +
11267 + if (sizeof(pgdval_t) > sizeof(long))
11268 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11269 + val, (u64)val >> 32);
11270 + else
11271 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11272 + val);
11273 +}
11274 +
11275 static inline void pgd_clear(pgd_t *pgdp)
11276 {
11277 set_pgd(pgdp, __pgd(0));
11278 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11279 pv_mmu_ops.set_fixmap(idx, phys, flags);
11280 }
11281
11282 +#ifdef CONFIG_PAX_KERNEXEC
11283 +static inline unsigned long pax_open_kernel(void)
11284 +{
11285 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11286 +}
11287 +
11288 +static inline unsigned long pax_close_kernel(void)
11289 +{
11290 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11291 +}
11292 +#else
11293 +static inline unsigned long pax_open_kernel(void) { return 0; }
11294 +static inline unsigned long pax_close_kernel(void) { return 0; }
11295 +#endif
11296 +
11297 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11298
11299 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11300 @@ -929,7 +956,7 @@ extern void default_banner(void);
11301
11302 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11303 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11304 -#define PARA_INDIRECT(addr) *%cs:addr
11305 +#define PARA_INDIRECT(addr) *%ss:addr
11306 #endif
11307
11308 #define INTERRUPT_RETURN \
11309 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11310 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11311 CLBR_NONE, \
11312 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11313 +
11314 +#define GET_CR0_INTO_RDI \
11315 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11316 + mov %rax,%rdi
11317 +
11318 +#define SET_RDI_INTO_CR0 \
11319 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11320 +
11321 +#define GET_CR3_INTO_RDI \
11322 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11323 + mov %rax,%rdi
11324 +
11325 +#define SET_RDI_INTO_CR3 \
11326 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11327 +
11328 #endif /* CONFIG_X86_32 */
11329
11330 #endif /* __ASSEMBLY__ */
11331 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11332 index 142236e..6a6b4a6 100644
11333 --- a/arch/x86/include/asm/paravirt_types.h
11334 +++ b/arch/x86/include/asm/paravirt_types.h
11335 @@ -84,20 +84,20 @@ struct pv_init_ops {
11336 */
11337 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11338 unsigned long addr, unsigned len);
11339 -};
11340 +} __no_const;
11341
11342
11343 struct pv_lazy_ops {
11344 /* Set deferred update mode, used for batching operations. */
11345 void (*enter)(void);
11346 void (*leave)(void);
11347 -};
11348 +} __no_const;
11349
11350 struct pv_time_ops {
11351 unsigned long long (*sched_clock)(void);
11352 unsigned long long (*steal_clock)(int cpu);
11353 unsigned long (*get_tsc_khz)(void);
11354 -};
11355 +} __no_const;
11356
11357 struct pv_cpu_ops {
11358 /* hooks for various privileged instructions */
11359 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11360
11361 void (*start_context_switch)(struct task_struct *prev);
11362 void (*end_context_switch)(struct task_struct *next);
11363 -};
11364 +} __no_const;
11365
11366 struct pv_irq_ops {
11367 /*
11368 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11369 unsigned long start_eip,
11370 unsigned long start_esp);
11371 #endif
11372 -};
11373 +} __no_const;
11374
11375 struct pv_mmu_ops {
11376 unsigned long (*read_cr2)(void);
11377 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11378 struct paravirt_callee_save make_pud;
11379
11380 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11381 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11382 #endif /* PAGETABLE_LEVELS == 4 */
11383 #endif /* PAGETABLE_LEVELS >= 3 */
11384
11385 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11386 an mfn. We can tell which is which from the index. */
11387 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11388 phys_addr_t phys, pgprot_t flags);
11389 +
11390 +#ifdef CONFIG_PAX_KERNEXEC
11391 + unsigned long (*pax_open_kernel)(void);
11392 + unsigned long (*pax_close_kernel)(void);
11393 +#endif
11394 +
11395 };
11396
11397 struct arch_spinlock;
11398 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11399 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11400 int (*spin_trylock)(struct arch_spinlock *lock);
11401 void (*spin_unlock)(struct arch_spinlock *lock);
11402 -};
11403 +} __no_const;
11404
11405 /* This contains all the paravirt structures: we get a convenient
11406 * number for each function using the offset which we use to indicate
11407 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11408 index b4389a4..7024269 100644
11409 --- a/arch/x86/include/asm/pgalloc.h
11410 +++ b/arch/x86/include/asm/pgalloc.h
11411 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11412 pmd_t *pmd, pte_t *pte)
11413 {
11414 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11415 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11416 +}
11417 +
11418 +static inline void pmd_populate_user(struct mm_struct *mm,
11419 + pmd_t *pmd, pte_t *pte)
11420 +{
11421 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11422 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11423 }
11424
11425 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11426
11427 #ifdef CONFIG_X86_PAE
11428 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11429 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11430 +{
11431 + pud_populate(mm, pudp, pmd);
11432 +}
11433 #else /* !CONFIG_X86_PAE */
11434 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11435 {
11436 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11437 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11438 }
11439 +
11440 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11441 +{
11442 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11443 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11444 +}
11445 #endif /* CONFIG_X86_PAE */
11446
11447 #if PAGETABLE_LEVELS > 3
11448 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11449 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11450 }
11451
11452 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11453 +{
11454 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11455 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11456 +}
11457 +
11458 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11459 {
11460 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11461 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11462 index f2b489c..4f7e2e5 100644
11463 --- a/arch/x86/include/asm/pgtable-2level.h
11464 +++ b/arch/x86/include/asm/pgtable-2level.h
11465 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11466
11467 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11468 {
11469 + pax_open_kernel();
11470 *pmdp = pmd;
11471 + pax_close_kernel();
11472 }
11473
11474 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11475 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11476 index 4cc9f2b..5fd9226 100644
11477 --- a/arch/x86/include/asm/pgtable-3level.h
11478 +++ b/arch/x86/include/asm/pgtable-3level.h
11479 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11480
11481 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11482 {
11483 + pax_open_kernel();
11484 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11485 + pax_close_kernel();
11486 }
11487
11488 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11489 {
11490 + pax_open_kernel();
11491 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11492 + pax_close_kernel();
11493 }
11494
11495 /*
11496 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11497 index a1f780d..5f38ced4 100644
11498 --- a/arch/x86/include/asm/pgtable.h
11499 +++ b/arch/x86/include/asm/pgtable.h
11500 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11501
11502 #ifndef __PAGETABLE_PUD_FOLDED
11503 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11504 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11505 #define pgd_clear(pgd) native_pgd_clear(pgd)
11506 #endif
11507
11508 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11509
11510 #define arch_end_context_switch(prev) do {} while(0)
11511
11512 +#define pax_open_kernel() native_pax_open_kernel()
11513 +#define pax_close_kernel() native_pax_close_kernel()
11514 #endif /* CONFIG_PARAVIRT */
11515
11516 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11517 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11518 +
11519 +#ifdef CONFIG_PAX_KERNEXEC
11520 +static inline unsigned long native_pax_open_kernel(void)
11521 +{
11522 + unsigned long cr0;
11523 +
11524 + preempt_disable();
11525 + barrier();
11526 + cr0 = read_cr0() ^ X86_CR0_WP;
11527 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11528 + write_cr0(cr0);
11529 + return cr0 ^ X86_CR0_WP;
11530 +}
11531 +
11532 +static inline unsigned long native_pax_close_kernel(void)
11533 +{
11534 + unsigned long cr0;
11535 +
11536 + cr0 = read_cr0() ^ X86_CR0_WP;
11537 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11538 + write_cr0(cr0);
11539 + barrier();
11540 + preempt_enable_no_resched();
11541 + return cr0 ^ X86_CR0_WP;
11542 +}
11543 +#else
11544 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11545 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11546 +#endif
11547 +
11548 /*
11549 * The following only work if pte_present() is true.
11550 * Undefined behaviour if not..
11551 */
11552 +static inline int pte_user(pte_t pte)
11553 +{
11554 + return pte_val(pte) & _PAGE_USER;
11555 +}
11556 +
11557 static inline int pte_dirty(pte_t pte)
11558 {
11559 return pte_flags(pte) & _PAGE_DIRTY;
11560 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11561 return pte_clear_flags(pte, _PAGE_RW);
11562 }
11563
11564 +static inline pte_t pte_mkread(pte_t pte)
11565 +{
11566 + return __pte(pte_val(pte) | _PAGE_USER);
11567 +}
11568 +
11569 static inline pte_t pte_mkexec(pte_t pte)
11570 {
11571 - return pte_clear_flags(pte, _PAGE_NX);
11572 +#ifdef CONFIG_X86_PAE
11573 + if (__supported_pte_mask & _PAGE_NX)
11574 + return pte_clear_flags(pte, _PAGE_NX);
11575 + else
11576 +#endif
11577 + return pte_set_flags(pte, _PAGE_USER);
11578 +}
11579 +
11580 +static inline pte_t pte_exprotect(pte_t pte)
11581 +{
11582 +#ifdef CONFIG_X86_PAE
11583 + if (__supported_pte_mask & _PAGE_NX)
11584 + return pte_set_flags(pte, _PAGE_NX);
11585 + else
11586 +#endif
11587 + return pte_clear_flags(pte, _PAGE_USER);
11588 }
11589
11590 static inline pte_t pte_mkdirty(pte_t pte)
11591 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11592 #endif
11593
11594 #ifndef __ASSEMBLY__
11595 +
11596 +#ifdef CONFIG_PAX_PER_CPU_PGD
11597 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11598 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11599 +{
11600 + return cpu_pgd[cpu];
11601 +}
11602 +#endif
11603 +
11604 #include <linux/mm_types.h>
11605
11606 static inline int pte_none(pte_t pte)
11607 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11608
11609 static inline int pgd_bad(pgd_t pgd)
11610 {
11611 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11612 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11613 }
11614
11615 static inline int pgd_none(pgd_t pgd)
11616 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11617 * pgd_offset() returns a (pgd_t *)
11618 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11619 */
11620 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11621 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11622 +
11623 +#ifdef CONFIG_PAX_PER_CPU_PGD
11624 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11625 +#endif
11626 +
11627 /*
11628 * a shortcut which implies the use of the kernel's pgd, instead
11629 * of a process's
11630 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11631 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11632 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11633
11634 +#ifdef CONFIG_X86_32
11635 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11636 +#else
11637 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11638 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11639 +
11640 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11641 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11642 +#else
11643 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11644 +#endif
11645 +
11646 +#endif
11647 +
11648 #ifndef __ASSEMBLY__
11649
11650 extern int direct_gbpages;
11651 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11652 * dst and src can be on the same page, but the range must not overlap,
11653 * and must not cross a page boundary.
11654 */
11655 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11656 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11657 {
11658 - memcpy(dst, src, count * sizeof(pgd_t));
11659 + pax_open_kernel();
11660 + while (count--)
11661 + *dst++ = *src++;
11662 + pax_close_kernel();
11663 }
11664
11665 +#ifdef CONFIG_PAX_PER_CPU_PGD
11666 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11667 +#endif
11668 +
11669 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11670 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11671 +#else
11672 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11673 +#endif
11674
11675 #include <asm-generic/pgtable.h>
11676 #endif /* __ASSEMBLY__ */
11677 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11678 index 8faa215..a8a17ea 100644
11679 --- a/arch/x86/include/asm/pgtable_32.h
11680 +++ b/arch/x86/include/asm/pgtable_32.h
11681 @@ -25,9 +25,6 @@
11682 struct mm_struct;
11683 struct vm_area_struct;
11684
11685 -extern pgd_t swapper_pg_dir[1024];
11686 -extern pgd_t initial_page_table[1024];
11687 -
11688 static inline void pgtable_cache_init(void) { }
11689 static inline void check_pgt_cache(void) { }
11690 void paging_init(void);
11691 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11692 # include <asm/pgtable-2level.h>
11693 #endif
11694
11695 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11696 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11697 +#ifdef CONFIG_X86_PAE
11698 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11699 +#endif
11700 +
11701 #if defined(CONFIG_HIGHPTE)
11702 #define pte_offset_map(dir, address) \
11703 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11704 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11705 /* Clear a kernel PTE and flush it from the TLB */
11706 #define kpte_clear_flush(ptep, vaddr) \
11707 do { \
11708 + pax_open_kernel(); \
11709 pte_clear(&init_mm, (vaddr), (ptep)); \
11710 + pax_close_kernel(); \
11711 __flush_tlb_one((vaddr)); \
11712 } while (0)
11713
11714 @@ -75,6 +80,9 @@ do { \
11715
11716 #endif /* !__ASSEMBLY__ */
11717
11718 +#define HAVE_ARCH_UNMAPPED_AREA
11719 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11720 +
11721 /*
11722 * kern_addr_valid() is (1) for FLATMEM and (0) for
11723 * SPARSEMEM and DISCONTIGMEM
11724 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11725 index ed5903b..c7fe163 100644
11726 --- a/arch/x86/include/asm/pgtable_32_types.h
11727 +++ b/arch/x86/include/asm/pgtable_32_types.h
11728 @@ -8,7 +8,7 @@
11729 */
11730 #ifdef CONFIG_X86_PAE
11731 # include <asm/pgtable-3level_types.h>
11732 -# define PMD_SIZE (1UL << PMD_SHIFT)
11733 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11734 # define PMD_MASK (~(PMD_SIZE - 1))
11735 #else
11736 # include <asm/pgtable-2level_types.h>
11737 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11738 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11739 #endif
11740
11741 +#ifdef CONFIG_PAX_KERNEXEC
11742 +#ifndef __ASSEMBLY__
11743 +extern unsigned char MODULES_EXEC_VADDR[];
11744 +extern unsigned char MODULES_EXEC_END[];
11745 +#endif
11746 +#include <asm/boot.h>
11747 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11748 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11749 +#else
11750 +#define ktla_ktva(addr) (addr)
11751 +#define ktva_ktla(addr) (addr)
11752 +#endif
11753 +
11754 #define MODULES_VADDR VMALLOC_START
11755 #define MODULES_END VMALLOC_END
11756 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11757 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11758 index 47356f9..deb94a2 100644
11759 --- a/arch/x86/include/asm/pgtable_64.h
11760 +++ b/arch/x86/include/asm/pgtable_64.h
11761 @@ -16,10 +16,14 @@
11762
11763 extern pud_t level3_kernel_pgt[512];
11764 extern pud_t level3_ident_pgt[512];
11765 +extern pud_t level3_vmalloc_start_pgt[512];
11766 +extern pud_t level3_vmalloc_end_pgt[512];
11767 +extern pud_t level3_vmemmap_pgt[512];
11768 +extern pud_t level2_vmemmap_pgt[512];
11769 extern pmd_t level2_kernel_pgt[512];
11770 extern pmd_t level2_fixmap_pgt[512];
11771 -extern pmd_t level2_ident_pgt[512];
11772 -extern pgd_t init_level4_pgt[];
11773 +extern pmd_t level2_ident_pgt[512*2];
11774 +extern pgd_t init_level4_pgt[512];
11775
11776 #define swapper_pg_dir init_level4_pgt
11777
11778 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11779
11780 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11781 {
11782 + pax_open_kernel();
11783 *pmdp = pmd;
11784 + pax_close_kernel();
11785 }
11786
11787 static inline void native_pmd_clear(pmd_t *pmd)
11788 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11789
11790 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11791 {
11792 + pax_open_kernel();
11793 *pudp = pud;
11794 + pax_close_kernel();
11795 }
11796
11797 static inline void native_pud_clear(pud_t *pud)
11798 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11799
11800 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11801 {
11802 + pax_open_kernel();
11803 + *pgdp = pgd;
11804 + pax_close_kernel();
11805 +}
11806 +
11807 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11808 +{
11809 *pgdp = pgd;
11810 }
11811
11812 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11813 index 766ea16..5b96cb3 100644
11814 --- a/arch/x86/include/asm/pgtable_64_types.h
11815 +++ b/arch/x86/include/asm/pgtable_64_types.h
11816 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11817 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11818 #define MODULES_END _AC(0xffffffffff000000, UL)
11819 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11820 +#define MODULES_EXEC_VADDR MODULES_VADDR
11821 +#define MODULES_EXEC_END MODULES_END
11822 +
11823 +#define ktla_ktva(addr) (addr)
11824 +#define ktva_ktla(addr) (addr)
11825
11826 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11827 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11828 index ec8a1fc..7ccb593 100644
11829 --- a/arch/x86/include/asm/pgtable_types.h
11830 +++ b/arch/x86/include/asm/pgtable_types.h
11831 @@ -16,13 +16,12 @@
11832 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11833 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11834 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11835 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11836 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11837 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11838 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11839 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11840 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11841 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11842 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11843 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11844 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11845 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11846
11847 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11848 @@ -40,7 +39,6 @@
11849 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11850 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11851 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11852 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11853 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11854 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11855 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11856 @@ -57,8 +55,10 @@
11857
11858 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11859 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11860 -#else
11861 +#elif defined(CONFIG_KMEMCHECK)
11862 #define _PAGE_NX (_AT(pteval_t, 0))
11863 +#else
11864 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11865 #endif
11866
11867 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11868 @@ -96,6 +96,9 @@
11869 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11870 _PAGE_ACCESSED)
11871
11872 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11873 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11874 +
11875 #define __PAGE_KERNEL_EXEC \
11876 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11877 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11878 @@ -106,7 +109,7 @@
11879 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11880 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11881 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11882 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11883 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11884 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11885 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11886 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11887 @@ -168,8 +171,8 @@
11888 * bits are combined, this will alow user to access the high address mapped
11889 * VDSO in the presence of CONFIG_COMPAT_VDSO
11890 */
11891 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11892 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11893 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11894 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11895 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11896 #endif
11897
11898 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11899 {
11900 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11901 }
11902 +#endif
11903
11904 +#if PAGETABLE_LEVELS == 3
11905 +#include <asm-generic/pgtable-nopud.h>
11906 +#endif
11907 +
11908 +#if PAGETABLE_LEVELS == 2
11909 +#include <asm-generic/pgtable-nopmd.h>
11910 +#endif
11911 +
11912 +#ifndef __ASSEMBLY__
11913 #if PAGETABLE_LEVELS > 3
11914 typedef struct { pudval_t pud; } pud_t;
11915
11916 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11917 return pud.pud;
11918 }
11919 #else
11920 -#include <asm-generic/pgtable-nopud.h>
11921 -
11922 static inline pudval_t native_pud_val(pud_t pud)
11923 {
11924 return native_pgd_val(pud.pgd);
11925 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11926 return pmd.pmd;
11927 }
11928 #else
11929 -#include <asm-generic/pgtable-nopmd.h>
11930 -
11931 static inline pmdval_t native_pmd_val(pmd_t pmd)
11932 {
11933 return native_pgd_val(pmd.pud.pgd);
11934 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11935
11936 extern pteval_t __supported_pte_mask;
11937 extern void set_nx(void);
11938 -extern int nx_enabled;
11939
11940 #define pgprot_writecombine pgprot_writecombine
11941 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11942 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11943 index ad1fc85..0b15fe1 100644
11944 --- a/arch/x86/include/asm/processor.h
11945 +++ b/arch/x86/include/asm/processor.h
11946 @@ -289,7 +289,7 @@ struct tss_struct {
11947
11948 } ____cacheline_aligned;
11949
11950 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11951 +extern struct tss_struct init_tss[NR_CPUS];
11952
11953 /*
11954 * Save the original ist values for checking stack pointers during debugging
11955 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
11956 */
11957 #define TASK_SIZE PAGE_OFFSET
11958 #define TASK_SIZE_MAX TASK_SIZE
11959 +
11960 +#ifdef CONFIG_PAX_SEGMEXEC
11961 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11962 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11963 +#else
11964 #define STACK_TOP TASK_SIZE
11965 -#define STACK_TOP_MAX STACK_TOP
11966 +#endif
11967 +
11968 +#define STACK_TOP_MAX TASK_SIZE
11969
11970 #define INIT_THREAD { \
11971 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11972 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11973 .vm86_info = NULL, \
11974 .sysenter_cs = __KERNEL_CS, \
11975 .io_bitmap_ptr = NULL, \
11976 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11977 */
11978 #define INIT_TSS { \
11979 .x86_tss = { \
11980 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11981 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11982 .ss0 = __KERNEL_DS, \
11983 .ss1 = __KERNEL_CS, \
11984 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11985 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
11986 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11987
11988 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11989 -#define KSTK_TOP(info) \
11990 -({ \
11991 - unsigned long *__ptr = (unsigned long *)(info); \
11992 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11993 -})
11994 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11995
11996 /*
11997 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11998 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11999 #define task_pt_regs(task) \
12000 ({ \
12001 struct pt_regs *__regs__; \
12002 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
12003 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
12004 __regs__ - 1; \
12005 })
12006
12007 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12008 /*
12009 * User space process size. 47bits minus one guard page.
12010 */
12011 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
12012 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
12013
12014 /* This decides where the kernel will search for a free chunk of vm
12015 * space during mmap's.
12016 */
12017 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
12018 - 0xc0000000 : 0xFFFFe000)
12019 + 0xc0000000 : 0xFFFFf000)
12020
12021 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
12022 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
12023 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12024 #define STACK_TOP_MAX TASK_SIZE_MAX
12025
12026 #define INIT_THREAD { \
12027 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12028 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12029 }
12030
12031 #define INIT_TSS { \
12032 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12033 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12034 }
12035
12036 /*
12037 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12038 */
12039 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12040
12041 +#ifdef CONFIG_PAX_SEGMEXEC
12042 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12043 +#endif
12044 +
12045 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12046
12047 /* Get/set a process' ability to use the timestamp counter instruction */
12048 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
12049 #define cpu_has_amd_erratum(x) (false)
12050 #endif /* CONFIG_CPU_SUP_AMD */
12051
12052 -extern unsigned long arch_align_stack(unsigned long sp);
12053 +#define arch_align_stack(x) ((x) & ~0xfUL)
12054 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12055
12056 void default_idle(void);
12057 bool set_pm_idle_to_default(void);
12058
12059 -void stop_this_cpu(void *dummy);
12060 +void stop_this_cpu(void *dummy) __noreturn;
12061
12062 #endif /* _ASM_X86_PROCESSOR_H */
12063 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12064 index 19f16eb..b50624b 100644
12065 --- a/arch/x86/include/asm/ptrace.h
12066 +++ b/arch/x86/include/asm/ptrace.h
12067 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12068 }
12069
12070 /*
12071 - * user_mode_vm(regs) determines whether a register set came from user mode.
12072 + * user_mode(regs) determines whether a register set came from user mode.
12073 * This is true if V8086 mode was enabled OR if the register set was from
12074 * protected mode with RPL-3 CS value. This tricky test checks that with
12075 * one comparison. Many places in the kernel can bypass this full check
12076 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12077 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12078 + * be used.
12079 */
12080 -static inline int user_mode(struct pt_regs *regs)
12081 +static inline int user_mode_novm(struct pt_regs *regs)
12082 {
12083 #ifdef CONFIG_X86_32
12084 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12085 #else
12086 - return !!(regs->cs & 3);
12087 + return !!(regs->cs & SEGMENT_RPL_MASK);
12088 #endif
12089 }
12090
12091 -static inline int user_mode_vm(struct pt_regs *regs)
12092 +static inline int user_mode(struct pt_regs *regs)
12093 {
12094 #ifdef CONFIG_X86_32
12095 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12096 USER_RPL;
12097 #else
12098 - return user_mode(regs);
12099 + return user_mode_novm(regs);
12100 #endif
12101 }
12102
12103 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12104 #ifdef CONFIG_X86_64
12105 static inline bool user_64bit_mode(struct pt_regs *regs)
12106 {
12107 + unsigned long cs = regs->cs & 0xffff;
12108 #ifndef CONFIG_PARAVIRT
12109 /*
12110 * On non-paravirt systems, this is the only long mode CPL 3
12111 * selector. We do not allow long mode selectors in the LDT.
12112 */
12113 - return regs->cs == __USER_CS;
12114 + return cs == __USER_CS;
12115 #else
12116 /* Headers are too twisted for this to go in paravirt.h. */
12117 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12118 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12119 #endif
12120 }
12121 #endif
12122 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12123 index fe1ec5b..dc5c3fe 100644
12124 --- a/arch/x86/include/asm/realmode.h
12125 +++ b/arch/x86/include/asm/realmode.h
12126 @@ -22,16 +22,14 @@ struct real_mode_header {
12127 #endif
12128 /* APM/BIOS reboot */
12129 u32 machine_real_restart_asm;
12130 -#ifdef CONFIG_X86_64
12131 u32 machine_real_restart_seg;
12132 -#endif
12133 };
12134
12135 /* This must match data at trampoline_32/64.S */
12136 struct trampoline_header {
12137 #ifdef CONFIG_X86_32
12138 u32 start;
12139 - u16 gdt_pad;
12140 + u16 boot_cs;
12141 u16 gdt_limit;
12142 u32 gdt_base;
12143 #else
12144 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12145 index a82c4f1..ac45053 100644
12146 --- a/arch/x86/include/asm/reboot.h
12147 +++ b/arch/x86/include/asm/reboot.h
12148 @@ -6,13 +6,13 @@
12149 struct pt_regs;
12150
12151 struct machine_ops {
12152 - void (*restart)(char *cmd);
12153 - void (*halt)(void);
12154 - void (*power_off)(void);
12155 + void (* __noreturn restart)(char *cmd);
12156 + void (* __noreturn halt)(void);
12157 + void (* __noreturn power_off)(void);
12158 void (*shutdown)(void);
12159 void (*crash_shutdown)(struct pt_regs *);
12160 - void (*emergency_restart)(void);
12161 -};
12162 + void (* __noreturn emergency_restart)(void);
12163 +} __no_const;
12164
12165 extern struct machine_ops machine_ops;
12166
12167 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12168 index 2dbe4a7..ce1db00 100644
12169 --- a/arch/x86/include/asm/rwsem.h
12170 +++ b/arch/x86/include/asm/rwsem.h
12171 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12172 {
12173 asm volatile("# beginning down_read\n\t"
12174 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12175 +
12176 +#ifdef CONFIG_PAX_REFCOUNT
12177 + "jno 0f\n"
12178 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12179 + "int $4\n0:\n"
12180 + _ASM_EXTABLE(0b, 0b)
12181 +#endif
12182 +
12183 /* adds 0x00000001 */
12184 " jns 1f\n"
12185 " call call_rwsem_down_read_failed\n"
12186 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12187 "1:\n\t"
12188 " mov %1,%2\n\t"
12189 " add %3,%2\n\t"
12190 +
12191 +#ifdef CONFIG_PAX_REFCOUNT
12192 + "jno 0f\n"
12193 + "sub %3,%2\n"
12194 + "int $4\n0:\n"
12195 + _ASM_EXTABLE(0b, 0b)
12196 +#endif
12197 +
12198 " jle 2f\n\t"
12199 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12200 " jnz 1b\n\t"
12201 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12202 long tmp;
12203 asm volatile("# beginning down_write\n\t"
12204 LOCK_PREFIX " xadd %1,(%2)\n\t"
12205 +
12206 +#ifdef CONFIG_PAX_REFCOUNT
12207 + "jno 0f\n"
12208 + "mov %1,(%2)\n"
12209 + "int $4\n0:\n"
12210 + _ASM_EXTABLE(0b, 0b)
12211 +#endif
12212 +
12213 /* adds 0xffff0001, returns the old value */
12214 " test %1,%1\n\t"
12215 /* was the count 0 before? */
12216 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12217 long tmp;
12218 asm volatile("# beginning __up_read\n\t"
12219 LOCK_PREFIX " xadd %1,(%2)\n\t"
12220 +
12221 +#ifdef CONFIG_PAX_REFCOUNT
12222 + "jno 0f\n"
12223 + "mov %1,(%2)\n"
12224 + "int $4\n0:\n"
12225 + _ASM_EXTABLE(0b, 0b)
12226 +#endif
12227 +
12228 /* subtracts 1, returns the old value */
12229 " jns 1f\n\t"
12230 " call call_rwsem_wake\n" /* expects old value in %edx */
12231 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12232 long tmp;
12233 asm volatile("# beginning __up_write\n\t"
12234 LOCK_PREFIX " xadd %1,(%2)\n\t"
12235 +
12236 +#ifdef CONFIG_PAX_REFCOUNT
12237 + "jno 0f\n"
12238 + "mov %1,(%2)\n"
12239 + "int $4\n0:\n"
12240 + _ASM_EXTABLE(0b, 0b)
12241 +#endif
12242 +
12243 /* subtracts 0xffff0001, returns the old value */
12244 " jns 1f\n\t"
12245 " call call_rwsem_wake\n" /* expects old value in %edx */
12246 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12247 {
12248 asm volatile("# beginning __downgrade_write\n\t"
12249 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12250 +
12251 +#ifdef CONFIG_PAX_REFCOUNT
12252 + "jno 0f\n"
12253 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12254 + "int $4\n0:\n"
12255 + _ASM_EXTABLE(0b, 0b)
12256 +#endif
12257 +
12258 /*
12259 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12260 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12261 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12262 */
12263 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12264 {
12265 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12266 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12267 +
12268 +#ifdef CONFIG_PAX_REFCOUNT
12269 + "jno 0f\n"
12270 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12271 + "int $4\n0:\n"
12272 + _ASM_EXTABLE(0b, 0b)
12273 +#endif
12274 +
12275 : "+m" (sem->count)
12276 : "er" (delta));
12277 }
12278 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12279 */
12280 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12281 {
12282 - return delta + xadd(&sem->count, delta);
12283 + return delta + xadd_check_overflow(&sem->count, delta);
12284 }
12285
12286 #endif /* __KERNEL__ */
12287 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12288 index c48a950..c6d7468 100644
12289 --- a/arch/x86/include/asm/segment.h
12290 +++ b/arch/x86/include/asm/segment.h
12291 @@ -64,10 +64,15 @@
12292 * 26 - ESPFIX small SS
12293 * 27 - per-cpu [ offset to per-cpu data area ]
12294 * 28 - stack_canary-20 [ for stack protector ]
12295 - * 29 - unused
12296 - * 30 - unused
12297 + * 29 - PCI BIOS CS
12298 + * 30 - PCI BIOS DS
12299 * 31 - TSS for double fault handler
12300 */
12301 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12302 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12303 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12304 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12305 +
12306 #define GDT_ENTRY_TLS_MIN 6
12307 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12308
12309 @@ -79,6 +84,8 @@
12310
12311 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12312
12313 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12314 +
12315 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12316
12317 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12318 @@ -104,6 +111,12 @@
12319 #define __KERNEL_STACK_CANARY 0
12320 #endif
12321
12322 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12323 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12324 +
12325 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12326 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12327 +
12328 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12329
12330 /*
12331 @@ -141,7 +154,7 @@
12332 */
12333
12334 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12335 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12336 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12337
12338
12339 #else
12340 @@ -165,6 +178,8 @@
12341 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12342 #define __USER32_DS __USER_DS
12343
12344 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12345 +
12346 #define GDT_ENTRY_TSS 8 /* needs two entries */
12347 #define GDT_ENTRY_LDT 10 /* needs two entries */
12348 #define GDT_ENTRY_TLS_MIN 12
12349 @@ -185,6 +200,7 @@
12350 #endif
12351
12352 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12353 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12354 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12355 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12356 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12357 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12358 {
12359 unsigned long __limit;
12360 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12361 - return __limit + 1;
12362 + return __limit;
12363 }
12364
12365 #endif /* !__ASSEMBLY__ */
12366 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12367 index 4f19a15..9e14f27 100644
12368 --- a/arch/x86/include/asm/smp.h
12369 +++ b/arch/x86/include/asm/smp.h
12370 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12371 /* cpus sharing the last level cache: */
12372 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12373 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12374 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12375 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12376
12377 static inline struct cpumask *cpu_sibling_mask(int cpu)
12378 {
12379 @@ -79,7 +79,7 @@ struct smp_ops {
12380
12381 void (*send_call_func_ipi)(const struct cpumask *mask);
12382 void (*send_call_func_single_ipi)(int cpu);
12383 -};
12384 +} __no_const;
12385
12386 /* Globals due to paravirt */
12387 extern void set_cpu_sibling_map(int cpu);
12388 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12389 extern int safe_smp_processor_id(void);
12390
12391 #elif defined(CONFIG_X86_64_SMP)
12392 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12393 -
12394 -#define stack_smp_processor_id() \
12395 -({ \
12396 - struct thread_info *ti; \
12397 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12398 - ti->cpu; \
12399 -})
12400 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12401 +#define stack_smp_processor_id() raw_smp_processor_id()
12402 #define safe_smp_processor_id() smp_processor_id()
12403
12404 #endif
12405 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12406 index 33692ea..350a534 100644
12407 --- a/arch/x86/include/asm/spinlock.h
12408 +++ b/arch/x86/include/asm/spinlock.h
12409 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12410 static inline void arch_read_lock(arch_rwlock_t *rw)
12411 {
12412 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12413 +
12414 +#ifdef CONFIG_PAX_REFCOUNT
12415 + "jno 0f\n"
12416 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12417 + "int $4\n0:\n"
12418 + _ASM_EXTABLE(0b, 0b)
12419 +#endif
12420 +
12421 "jns 1f\n"
12422 "call __read_lock_failed\n\t"
12423 "1:\n"
12424 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12425 static inline void arch_write_lock(arch_rwlock_t *rw)
12426 {
12427 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12428 +
12429 +#ifdef CONFIG_PAX_REFCOUNT
12430 + "jno 0f\n"
12431 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12432 + "int $4\n0:\n"
12433 + _ASM_EXTABLE(0b, 0b)
12434 +#endif
12435 +
12436 "jz 1f\n"
12437 "call __write_lock_failed\n\t"
12438 "1:\n"
12439 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12440
12441 static inline void arch_read_unlock(arch_rwlock_t *rw)
12442 {
12443 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12444 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12445 +
12446 +#ifdef CONFIG_PAX_REFCOUNT
12447 + "jno 0f\n"
12448 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12449 + "int $4\n0:\n"
12450 + _ASM_EXTABLE(0b, 0b)
12451 +#endif
12452 +
12453 :"+m" (rw->lock) : : "memory");
12454 }
12455
12456 static inline void arch_write_unlock(arch_rwlock_t *rw)
12457 {
12458 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12459 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12460 +
12461 +#ifdef CONFIG_PAX_REFCOUNT
12462 + "jno 0f\n"
12463 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12464 + "int $4\n0:\n"
12465 + _ASM_EXTABLE(0b, 0b)
12466 +#endif
12467 +
12468 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12469 }
12470
12471 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12472 index 6a99859..03cb807 100644
12473 --- a/arch/x86/include/asm/stackprotector.h
12474 +++ b/arch/x86/include/asm/stackprotector.h
12475 @@ -47,7 +47,7 @@
12476 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12477 */
12478 #define GDT_STACK_CANARY_INIT \
12479 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12480 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12481
12482 /*
12483 * Initialize the stackprotector canary value.
12484 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12485
12486 static inline void load_stack_canary_segment(void)
12487 {
12488 -#ifdef CONFIG_X86_32
12489 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12490 asm volatile ("mov %0, %%gs" : : "r" (0));
12491 #endif
12492 }
12493 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12494 index 70bbe39..4ae2bd4 100644
12495 --- a/arch/x86/include/asm/stacktrace.h
12496 +++ b/arch/x86/include/asm/stacktrace.h
12497 @@ -11,28 +11,20 @@
12498
12499 extern int kstack_depth_to_print;
12500
12501 -struct thread_info;
12502 +struct task_struct;
12503 struct stacktrace_ops;
12504
12505 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12506 - unsigned long *stack,
12507 - unsigned long bp,
12508 - const struct stacktrace_ops *ops,
12509 - void *data,
12510 - unsigned long *end,
12511 - int *graph);
12512 +typedef unsigned long walk_stack_t(struct task_struct *task,
12513 + void *stack_start,
12514 + unsigned long *stack,
12515 + unsigned long bp,
12516 + const struct stacktrace_ops *ops,
12517 + void *data,
12518 + unsigned long *end,
12519 + int *graph);
12520
12521 -extern unsigned long
12522 -print_context_stack(struct thread_info *tinfo,
12523 - unsigned long *stack, unsigned long bp,
12524 - const struct stacktrace_ops *ops, void *data,
12525 - unsigned long *end, int *graph);
12526 -
12527 -extern unsigned long
12528 -print_context_stack_bp(struct thread_info *tinfo,
12529 - unsigned long *stack, unsigned long bp,
12530 - const struct stacktrace_ops *ops, void *data,
12531 - unsigned long *end, int *graph);
12532 +extern walk_stack_t print_context_stack;
12533 +extern walk_stack_t print_context_stack_bp;
12534
12535 /* Generic stack tracer with callbacks */
12536
12537 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12538 void (*address)(void *data, unsigned long address, int reliable);
12539 /* On negative return stop dumping */
12540 int (*stack)(void *data, char *name);
12541 - walk_stack_t walk_stack;
12542 + walk_stack_t *walk_stack;
12543 };
12544
12545 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12546 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12547 index 4ec45b3..a4f0a8a 100644
12548 --- a/arch/x86/include/asm/switch_to.h
12549 +++ b/arch/x86/include/asm/switch_to.h
12550 @@ -108,7 +108,7 @@ do { \
12551 "call __switch_to\n\t" \
12552 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12553 __switch_canary \
12554 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12555 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12556 "movq %%rax,%%rdi\n\t" \
12557 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12558 "jnz ret_from_fork\n\t" \
12559 @@ -119,7 +119,7 @@ do { \
12560 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12561 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12562 [_tif_fork] "i" (_TIF_FORK), \
12563 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12564 + [thread_info] "m" (current_tinfo), \
12565 [current_task] "m" (current_task) \
12566 __switch_canary_iparam \
12567 : "memory", "cc" __EXTRA_CLOBBER)
12568 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12569 index 2d946e6..e453ec4 100644
12570 --- a/arch/x86/include/asm/thread_info.h
12571 +++ b/arch/x86/include/asm/thread_info.h
12572 @@ -10,6 +10,7 @@
12573 #include <linux/compiler.h>
12574 #include <asm/page.h>
12575 #include <asm/types.h>
12576 +#include <asm/percpu.h>
12577
12578 /*
12579 * low level task data that entry.S needs immediate access to
12580 @@ -24,7 +25,6 @@ struct exec_domain;
12581 #include <linux/atomic.h>
12582
12583 struct thread_info {
12584 - struct task_struct *task; /* main task structure */
12585 struct exec_domain *exec_domain; /* execution domain */
12586 __u32 flags; /* low level flags */
12587 __u32 status; /* thread synchronous flags */
12588 @@ -34,19 +34,13 @@ struct thread_info {
12589 mm_segment_t addr_limit;
12590 struct restart_block restart_block;
12591 void __user *sysenter_return;
12592 -#ifdef CONFIG_X86_32
12593 - unsigned long previous_esp; /* ESP of the previous stack in
12594 - case of nested (IRQ) stacks
12595 - */
12596 - __u8 supervisor_stack[0];
12597 -#endif
12598 + unsigned long lowest_stack;
12599 unsigned int sig_on_uaccess_error:1;
12600 unsigned int uaccess_err:1; /* uaccess failed */
12601 };
12602
12603 -#define INIT_THREAD_INFO(tsk) \
12604 +#define INIT_THREAD_INFO \
12605 { \
12606 - .task = &tsk, \
12607 .exec_domain = &default_exec_domain, \
12608 .flags = 0, \
12609 .cpu = 0, \
12610 @@ -57,7 +51,7 @@ struct thread_info {
12611 }, \
12612 }
12613
12614 -#define init_thread_info (init_thread_union.thread_info)
12615 +#define init_thread_info (init_thread_union.stack)
12616 #define init_stack (init_thread_union.stack)
12617
12618 #else /* !__ASSEMBLY__ */
12619 @@ -98,6 +92,7 @@ struct thread_info {
12620 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12621 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12622 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12623 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12624
12625 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12626 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12627 @@ -122,17 +117,18 @@ struct thread_info {
12628 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12629 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12630 #define _TIF_X32 (1 << TIF_X32)
12631 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12632
12633 /* work to do in syscall_trace_enter() */
12634 #define _TIF_WORK_SYSCALL_ENTRY \
12635 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12636 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12637 - _TIF_NOHZ)
12638 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
12639
12640 /* work to do in syscall_trace_leave() */
12641 #define _TIF_WORK_SYSCALL_EXIT \
12642 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12643 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
12644 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
12645
12646 /* work to do on interrupt/exception return */
12647 #define _TIF_WORK_MASK \
12648 @@ -143,7 +139,7 @@ struct thread_info {
12649 /* work to do on any return to user space */
12650 #define _TIF_ALLWORK_MASK \
12651 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12652 - _TIF_NOHZ)
12653 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
12654
12655 /* Only used for 64 bit */
12656 #define _TIF_DO_NOTIFY_MASK \
12657 @@ -159,45 +155,40 @@ struct thread_info {
12658
12659 #define PREEMPT_ACTIVE 0x10000000
12660
12661 -#ifdef CONFIG_X86_32
12662 -
12663 -#define STACK_WARN (THREAD_SIZE/8)
12664 -/*
12665 - * macros/functions for gaining access to the thread information structure
12666 - *
12667 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12668 - */
12669 -#ifndef __ASSEMBLY__
12670 -
12671 -
12672 -/* how to get the current stack pointer from C */
12673 -register unsigned long current_stack_pointer asm("esp") __used;
12674 -
12675 -/* how to get the thread information struct from C */
12676 -static inline struct thread_info *current_thread_info(void)
12677 -{
12678 - return (struct thread_info *)
12679 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12680 -}
12681 -
12682 -#else /* !__ASSEMBLY__ */
12683 -
12684 +#ifdef __ASSEMBLY__
12685 /* how to get the thread information struct from ASM */
12686 #define GET_THREAD_INFO(reg) \
12687 - movl $-THREAD_SIZE, reg; \
12688 - andl %esp, reg
12689 + mov PER_CPU_VAR(current_tinfo), reg
12690
12691 /* use this one if reg already contains %esp */
12692 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12693 - andl $-THREAD_SIZE, reg
12694 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12695 +#else
12696 +/* how to get the thread information struct from C */
12697 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12698 +
12699 +static __always_inline struct thread_info *current_thread_info(void)
12700 +{
12701 + return this_cpu_read_stable(current_tinfo);
12702 +}
12703 +#endif
12704 +
12705 +#ifdef CONFIG_X86_32
12706 +
12707 +#define STACK_WARN (THREAD_SIZE/8)
12708 +/*
12709 + * macros/functions for gaining access to the thread information structure
12710 + *
12711 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12712 + */
12713 +#ifndef __ASSEMBLY__
12714 +
12715 +/* how to get the current stack pointer from C */
12716 +register unsigned long current_stack_pointer asm("esp") __used;
12717
12718 #endif
12719
12720 #else /* X86_32 */
12721
12722 -#include <asm/percpu.h>
12723 -#define KERNEL_STACK_OFFSET (5*8)
12724 -
12725 /*
12726 * macros/functions for gaining access to the thread information structure
12727 * preempt_count needs to be 1 initially, until the scheduler is functional.
12728 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12729 #ifndef __ASSEMBLY__
12730 DECLARE_PER_CPU(unsigned long, kernel_stack);
12731
12732 -static inline struct thread_info *current_thread_info(void)
12733 -{
12734 - struct thread_info *ti;
12735 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12736 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12737 - return ti;
12738 -}
12739 -
12740 -#else /* !__ASSEMBLY__ */
12741 -
12742 -/* how to get the thread information struct from ASM */
12743 -#define GET_THREAD_INFO(reg) \
12744 - movq PER_CPU_VAR(kernel_stack),reg ; \
12745 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12746 -
12747 -/*
12748 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12749 - * a certain register (to be used in assembler memory operands).
12750 - */
12751 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12752 -
12753 +/* how to get the current stack pointer from C */
12754 +register unsigned long current_stack_pointer asm("rsp") __used;
12755 #endif
12756
12757 #endif /* !X86_32 */
12758 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
12759 extern void arch_task_cache_init(void);
12760 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12761 extern void arch_release_task_struct(struct task_struct *tsk);
12762 +
12763 +#define __HAVE_THREAD_FUNCTIONS
12764 +#define task_thread_info(task) (&(task)->tinfo)
12765 +#define task_stack_page(task) ((task)->stack)
12766 +#define setup_thread_stack(p, org) do {} while (0)
12767 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12768 +
12769 #endif
12770 #endif /* _ASM_X86_THREAD_INFO_H */
12771 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12772 index 7ccf8d1..7cdca12 100644
12773 --- a/arch/x86/include/asm/uaccess.h
12774 +++ b/arch/x86/include/asm/uaccess.h
12775 @@ -7,6 +7,7 @@
12776 #include <linux/compiler.h>
12777 #include <linux/thread_info.h>
12778 #include <linux/string.h>
12779 +#include <linux/sched.h>
12780 #include <asm/asm.h>
12781 #include <asm/page.h>
12782 #include <asm/smap.h>
12783 @@ -14,6 +15,8 @@
12784 #define VERIFY_READ 0
12785 #define VERIFY_WRITE 1
12786
12787 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12788 +
12789 /*
12790 * The fs value determines whether argument validity checking should be
12791 * performed or not. If get_fs() == USER_DS, checking is performed, with
12792 @@ -29,7 +32,12 @@
12793
12794 #define get_ds() (KERNEL_DS)
12795 #define get_fs() (current_thread_info()->addr_limit)
12796 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12797 +void __set_fs(mm_segment_t x);
12798 +void set_fs(mm_segment_t x);
12799 +#else
12800 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12801 +#endif
12802
12803 #define segment_eq(a, b) ((a).seg == (b).seg)
12804
12805 @@ -77,8 +85,33 @@
12806 * checks that the pointer is in the user space range - after calling
12807 * this function, memory access functions may still return -EFAULT.
12808 */
12809 -#define access_ok(type, addr, size) \
12810 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12811 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12812 +#define access_ok(type, addr, size) \
12813 +({ \
12814 + long __size = size; \
12815 + unsigned long __addr = (unsigned long)addr; \
12816 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12817 + unsigned long __end_ao = __addr + __size - 1; \
12818 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12819 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12820 + while(__addr_ao <= __end_ao) { \
12821 + char __c_ao; \
12822 + __addr_ao += PAGE_SIZE; \
12823 + if (__size > PAGE_SIZE) \
12824 + cond_resched(); \
12825 + if (__get_user(__c_ao, (char __user *)__addr)) \
12826 + break; \
12827 + if (type != VERIFY_WRITE) { \
12828 + __addr = __addr_ao; \
12829 + continue; \
12830 + } \
12831 + if (__put_user(__c_ao, (char __user *)__addr)) \
12832 + break; \
12833 + __addr = __addr_ao; \
12834 + } \
12835 + } \
12836 + __ret_ao; \
12837 +})
12838
12839 /*
12840 * The exception table consists of pairs of addresses relative to the
12841 @@ -189,13 +222,21 @@ extern int __get_user_bad(void);
12842 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12843 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12844
12845 -
12846 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12847 +#define __copyuser_seg "gs;"
12848 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12849 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12850 +#else
12851 +#define __copyuser_seg
12852 +#define __COPYUSER_SET_ES
12853 +#define __COPYUSER_RESTORE_ES
12854 +#endif
12855
12856 #ifdef CONFIG_X86_32
12857 #define __put_user_asm_u64(x, addr, err, errret) \
12858 asm volatile(ASM_STAC "\n" \
12859 - "1: movl %%eax,0(%2)\n" \
12860 - "2: movl %%edx,4(%2)\n" \
12861 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12862 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12863 "3: " ASM_CLAC "\n" \
12864 ".section .fixup,\"ax\"\n" \
12865 "4: movl %3,%0\n" \
12866 @@ -208,8 +249,8 @@ extern int __get_user_bad(void);
12867
12868 #define __put_user_asm_ex_u64(x, addr) \
12869 asm volatile(ASM_STAC "\n" \
12870 - "1: movl %%eax,0(%1)\n" \
12871 - "2: movl %%edx,4(%1)\n" \
12872 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12873 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12874 "3: " ASM_CLAC "\n" \
12875 _ASM_EXTABLE_EX(1b, 2b) \
12876 _ASM_EXTABLE_EX(2b, 3b) \
12877 @@ -261,7 +302,7 @@ extern void __put_user_8(void);
12878 __typeof__(*(ptr)) __pu_val; \
12879 __chk_user_ptr(ptr); \
12880 might_fault(); \
12881 - __pu_val = x; \
12882 + __pu_val = (x); \
12883 switch (sizeof(*(ptr))) { \
12884 case 1: \
12885 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12886 @@ -383,7 +424,7 @@ do { \
12887
12888 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12889 asm volatile(ASM_STAC "\n" \
12890 - "1: mov"itype" %2,%"rtype"1\n" \
12891 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12892 "2: " ASM_CLAC "\n" \
12893 ".section .fixup,\"ax\"\n" \
12894 "3: mov %3,%0\n" \
12895 @@ -391,7 +432,7 @@ do { \
12896 " jmp 2b\n" \
12897 ".previous\n" \
12898 _ASM_EXTABLE(1b, 3b) \
12899 - : "=r" (err), ltype(x) \
12900 + : "=r" (err), ltype (x) \
12901 : "m" (__m(addr)), "i" (errret), "0" (err))
12902
12903 #define __get_user_size_ex(x, ptr, size) \
12904 @@ -416,7 +457,7 @@ do { \
12905 } while (0)
12906
12907 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12908 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12909 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12910 "2:\n" \
12911 _ASM_EXTABLE_EX(1b, 2b) \
12912 : ltype(x) : "m" (__m(addr)))
12913 @@ -433,13 +474,24 @@ do { \
12914 int __gu_err; \
12915 unsigned long __gu_val; \
12916 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12917 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12918 + (x) = (__typeof__(*(ptr)))__gu_val; \
12919 __gu_err; \
12920 })
12921
12922 /* FIXME: this hack is definitely wrong -AK */
12923 struct __large_struct { unsigned long buf[100]; };
12924 -#define __m(x) (*(struct __large_struct __user *)(x))
12925 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12926 +#define ____m(x) \
12927 +({ \
12928 + unsigned long ____x = (unsigned long)(x); \
12929 + if (____x < PAX_USER_SHADOW_BASE) \
12930 + ____x += PAX_USER_SHADOW_BASE; \
12931 + (void __user *)____x; \
12932 +})
12933 +#else
12934 +#define ____m(x) (x)
12935 +#endif
12936 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12937
12938 /*
12939 * Tell gcc we read from memory instead of writing: this is because
12940 @@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
12941 */
12942 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12943 asm volatile(ASM_STAC "\n" \
12944 - "1: mov"itype" %"rtype"1,%2\n" \
12945 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12946 "2: " ASM_CLAC "\n" \
12947 ".section .fixup,\"ax\"\n" \
12948 "3: mov %3,%0\n" \
12949 @@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
12950 ".previous\n" \
12951 _ASM_EXTABLE(1b, 3b) \
12952 : "=r"(err) \
12953 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12954 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12955
12956 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12957 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12958 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12959 "2:\n" \
12960 _ASM_EXTABLE_EX(1b, 2b) \
12961 : : ltype(x), "m" (__m(addr)))
12962 @@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
12963 * On error, the variable @x is set to zero.
12964 */
12965
12966 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12967 +#define __get_user(x, ptr) get_user((x), (ptr))
12968 +#else
12969 #define __get_user(x, ptr) \
12970 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12971 +#endif
12972
12973 /**
12974 * __put_user: - Write a simple value into user space, with less checking.
12975 @@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
12976 * Returns zero on success, or -EFAULT on error.
12977 */
12978
12979 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12980 +#define __put_user(x, ptr) put_user((x), (ptr))
12981 +#else
12982 #define __put_user(x, ptr) \
12983 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12984 +#endif
12985
12986 #define __get_user_unaligned __get_user
12987 #define __put_user_unaligned __put_user
12988 @@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
12989 #define get_user_ex(x, ptr) do { \
12990 unsigned long __gue_val; \
12991 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12992 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12993 + (x) = (__typeof__(*(ptr)))__gue_val; \
12994 } while (0)
12995
12996 #ifdef CONFIG_X86_WP_WORKS_OK
12997 @@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
12998 extern __must_check long strlen_user(const char __user *str);
12999 extern __must_check long strnlen_user(const char __user *str, long n);
13000
13001 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13002 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13003 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13004 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13005
13006 /*
13007 * movsl can be slow when source and dest are not both 8-byte aligned
13008 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
13009 index 7f760a9..00f93c0 100644
13010 --- a/arch/x86/include/asm/uaccess_32.h
13011 +++ b/arch/x86/include/asm/uaccess_32.h
13012 @@ -11,15 +11,15 @@
13013 #include <asm/page.h>
13014
13015 unsigned long __must_check __copy_to_user_ll
13016 - (void __user *to, const void *from, unsigned long n);
13017 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
13018 unsigned long __must_check __copy_from_user_ll
13019 - (void *to, const void __user *from, unsigned long n);
13020 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13021 unsigned long __must_check __copy_from_user_ll_nozero
13022 - (void *to, const void __user *from, unsigned long n);
13023 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13024 unsigned long __must_check __copy_from_user_ll_nocache
13025 - (void *to, const void __user *from, unsigned long n);
13026 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13027 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13028 - (void *to, const void __user *from, unsigned long n);
13029 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13030
13031 /**
13032 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13033 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13034 static __always_inline unsigned long __must_check
13035 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13036 {
13037 + if ((long)n < 0)
13038 + return n;
13039 +
13040 if (__builtin_constant_p(n)) {
13041 unsigned long ret;
13042
13043 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13044 return ret;
13045 }
13046 }
13047 + if (!__builtin_constant_p(n))
13048 + check_object_size(from, n, true);
13049 return __copy_to_user_ll(to, from, n);
13050 }
13051
13052 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13053 __copy_to_user(void __user *to, const void *from, unsigned long n)
13054 {
13055 might_fault();
13056 +
13057 return __copy_to_user_inatomic(to, from, n);
13058 }
13059
13060 static __always_inline unsigned long
13061 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13062 {
13063 + if ((long)n < 0)
13064 + return n;
13065 +
13066 /* Avoid zeroing the tail if the copy fails..
13067 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13068 * but as the zeroing behaviour is only significant when n is not
13069 @@ -137,6 +146,10 @@ static __always_inline unsigned long
13070 __copy_from_user(void *to, const void __user *from, unsigned long n)
13071 {
13072 might_fault();
13073 +
13074 + if ((long)n < 0)
13075 + return n;
13076 +
13077 if (__builtin_constant_p(n)) {
13078 unsigned long ret;
13079
13080 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13081 return ret;
13082 }
13083 }
13084 + if (!__builtin_constant_p(n))
13085 + check_object_size(to, n, false);
13086 return __copy_from_user_ll(to, from, n);
13087 }
13088
13089 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13090 const void __user *from, unsigned long n)
13091 {
13092 might_fault();
13093 +
13094 + if ((long)n < 0)
13095 + return n;
13096 +
13097 if (__builtin_constant_p(n)) {
13098 unsigned long ret;
13099
13100 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13101 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13102 unsigned long n)
13103 {
13104 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13105 + if ((long)n < 0)
13106 + return n;
13107 +
13108 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13109 }
13110
13111 -unsigned long __must_check copy_to_user(void __user *to,
13112 - const void *from, unsigned long n);
13113 -unsigned long __must_check _copy_from_user(void *to,
13114 - const void __user *from,
13115 - unsigned long n);
13116 -
13117 +extern void copy_to_user_overflow(void)
13118 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13119 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13120 +#else
13121 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13122 +#endif
13123 +;
13124
13125 extern void copy_from_user_overflow(void)
13126 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13127 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13128 #endif
13129 ;
13130
13131 -static inline unsigned long __must_check copy_from_user(void *to,
13132 - const void __user *from,
13133 - unsigned long n)
13134 +/**
13135 + * copy_to_user: - Copy a block of data into user space.
13136 + * @to: Destination address, in user space.
13137 + * @from: Source address, in kernel space.
13138 + * @n: Number of bytes to copy.
13139 + *
13140 + * Context: User context only. This function may sleep.
13141 + *
13142 + * Copy data from kernel space to user space.
13143 + *
13144 + * Returns number of bytes that could not be copied.
13145 + * On success, this will be zero.
13146 + */
13147 +static inline unsigned long __must_check
13148 +copy_to_user(void __user *to, const void *from, unsigned long n)
13149 {
13150 - int sz = __compiletime_object_size(to);
13151 + size_t sz = __compiletime_object_size(from);
13152
13153 - if (likely(sz == -1 || sz >= n))
13154 - n = _copy_from_user(to, from, n);
13155 - else
13156 + if (unlikely(sz != (size_t)-1 && sz < n))
13157 + copy_to_user_overflow();
13158 + else if (access_ok(VERIFY_WRITE, to, n))
13159 + n = __copy_to_user(to, from, n);
13160 + return n;
13161 +}
13162 +
13163 +/**
13164 + * copy_from_user: - Copy a block of data from user space.
13165 + * @to: Destination address, in kernel space.
13166 + * @from: Source address, in user space.
13167 + * @n: Number of bytes to copy.
13168 + *
13169 + * Context: User context only. This function may sleep.
13170 + *
13171 + * Copy data from user space to kernel space.
13172 + *
13173 + * Returns number of bytes that could not be copied.
13174 + * On success, this will be zero.
13175 + *
13176 + * If some data could not be copied, this function will pad the copied
13177 + * data to the requested size using zero bytes.
13178 + */
13179 +static inline unsigned long __must_check
13180 +copy_from_user(void *to, const void __user *from, unsigned long n)
13181 +{
13182 + size_t sz = __compiletime_object_size(to);
13183 +
13184 + if (unlikely(sz != (size_t)-1 && sz < n))
13185 copy_from_user_overflow();
13186 -
13187 + else if (access_ok(VERIFY_READ, from, n))
13188 + n = __copy_from_user(to, from, n);
13189 + else if ((long)n > 0) {
13190 + if (!__builtin_constant_p(n))
13191 + check_object_size(to, n, false);
13192 + memset(to, 0, n);
13193 + }
13194 return n;
13195 }
13196
13197 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13198 index 142810c..4389299 100644
13199 --- a/arch/x86/include/asm/uaccess_64.h
13200 +++ b/arch/x86/include/asm/uaccess_64.h
13201 @@ -10,6 +10,9 @@
13202 #include <asm/alternative.h>
13203 #include <asm/cpufeature.h>
13204 #include <asm/page.h>
13205 +#include <asm/pgtable.h>
13206 +
13207 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13208
13209 /*
13210 * Copy To/From Userspace
13211 @@ -17,13 +20,13 @@
13212
13213 /* Handles exceptions in both to and from, but doesn't do access_ok */
13214 __must_check unsigned long
13215 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13216 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13217 __must_check unsigned long
13218 -copy_user_generic_string(void *to, const void *from, unsigned len);
13219 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13220 __must_check unsigned long
13221 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13222 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13223
13224 -static __always_inline __must_check unsigned long
13225 +static __always_inline __must_check __size_overflow(3) unsigned long
13226 copy_user_generic(void *to, const void *from, unsigned len)
13227 {
13228 unsigned ret;
13229 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
13230 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13231 "=d" (len)),
13232 "1" (to), "2" (from), "3" (len)
13233 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13234 + : "memory", "rcx", "r8", "r9", "r11");
13235 return ret;
13236 }
13237
13238 +static __always_inline __must_check unsigned long
13239 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13240 +static __always_inline __must_check unsigned long
13241 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13242 __must_check unsigned long
13243 -_copy_to_user(void __user *to, const void *from, unsigned len);
13244 -__must_check unsigned long
13245 -_copy_from_user(void *to, const void __user *from, unsigned len);
13246 -__must_check unsigned long
13247 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13248 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13249 +
13250 +extern void copy_to_user_overflow(void)
13251 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13252 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13253 +#else
13254 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13255 +#endif
13256 +;
13257 +
13258 +extern void copy_from_user_overflow(void)
13259 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13260 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13261 +#else
13262 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13263 +#endif
13264 +;
13265
13266 static inline unsigned long __must_check copy_from_user(void *to,
13267 const void __user *from,
13268 unsigned long n)
13269 {
13270 - int sz = __compiletime_object_size(to);
13271 -
13272 might_fault();
13273 - if (likely(sz == -1 || sz >= n))
13274 - n = _copy_from_user(to, from, n);
13275 -#ifdef CONFIG_DEBUG_VM
13276 - else
13277 - WARN(1, "Buffer overflow detected!\n");
13278 -#endif
13279 +
13280 + if (access_ok(VERIFY_READ, from, n))
13281 + n = __copy_from_user(to, from, n);
13282 + else if (n < INT_MAX) {
13283 + if (!__builtin_constant_p(n))
13284 + check_object_size(to, n, false);
13285 + memset(to, 0, n);
13286 + }
13287 return n;
13288 }
13289
13290 static __always_inline __must_check
13291 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13292 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13293 {
13294 might_fault();
13295
13296 - return _copy_to_user(dst, src, size);
13297 + if (access_ok(VERIFY_WRITE, dst, size))
13298 + size = __copy_to_user(dst, src, size);
13299 + return size;
13300 }
13301
13302 static __always_inline __must_check
13303 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13304 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13305 {
13306 - int ret = 0;
13307 + size_t sz = __compiletime_object_size(dst);
13308 + unsigned ret = 0;
13309
13310 might_fault();
13311 - if (!__builtin_constant_p(size))
13312 - return copy_user_generic(dst, (__force void *)src, size);
13313 +
13314 + if (size > INT_MAX)
13315 + return size;
13316 +
13317 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13318 + if (!__access_ok(VERIFY_READ, src, size))
13319 + return size;
13320 +#endif
13321 +
13322 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13323 + copy_from_user_overflow();
13324 + return size;
13325 + }
13326 +
13327 + if (!__builtin_constant_p(size)) {
13328 + check_object_size(dst, size, false);
13329 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13330 + }
13331 switch (size) {
13332 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13333 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13334 ret, "b", "b", "=q", 1);
13335 return ret;
13336 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13337 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13338 ret, "w", "w", "=r", 2);
13339 return ret;
13340 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13341 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13342 ret, "l", "k", "=r", 4);
13343 return ret;
13344 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13345 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13346 ret, "q", "", "=r", 8);
13347 return ret;
13348 case 10:
13349 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13350 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13351 ret, "q", "", "=r", 10);
13352 if (unlikely(ret))
13353 return ret;
13354 __get_user_asm(*(u16 *)(8 + (char *)dst),
13355 - (u16 __user *)(8 + (char __user *)src),
13356 + (const u16 __user *)(8 + (const char __user *)src),
13357 ret, "w", "w", "=r", 2);
13358 return ret;
13359 case 16:
13360 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13361 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13362 ret, "q", "", "=r", 16);
13363 if (unlikely(ret))
13364 return ret;
13365 __get_user_asm(*(u64 *)(8 + (char *)dst),
13366 - (u64 __user *)(8 + (char __user *)src),
13367 + (const u64 __user *)(8 + (const char __user *)src),
13368 ret, "q", "", "=r", 8);
13369 return ret;
13370 default:
13371 - return copy_user_generic(dst, (__force void *)src, size);
13372 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13373 }
13374 }
13375
13376 static __always_inline __must_check
13377 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13378 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13379 {
13380 - int ret = 0;
13381 + size_t sz = __compiletime_object_size(src);
13382 + unsigned ret = 0;
13383
13384 might_fault();
13385 - if (!__builtin_constant_p(size))
13386 - return copy_user_generic((__force void *)dst, src, size);
13387 +
13388 + if (size > INT_MAX)
13389 + return size;
13390 +
13391 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13392 + if (!__access_ok(VERIFY_WRITE, dst, size))
13393 + return size;
13394 +#endif
13395 +
13396 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13397 + copy_to_user_overflow();
13398 + return size;
13399 + }
13400 +
13401 + if (!__builtin_constant_p(size)) {
13402 + check_object_size(src, size, true);
13403 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13404 + }
13405 switch (size) {
13406 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13407 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13408 ret, "b", "b", "iq", 1);
13409 return ret;
13410 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13411 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13412 ret, "w", "w", "ir", 2);
13413 return ret;
13414 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13415 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13416 ret, "l", "k", "ir", 4);
13417 return ret;
13418 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13419 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13420 ret, "q", "", "er", 8);
13421 return ret;
13422 case 10:
13423 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13424 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13425 ret, "q", "", "er", 10);
13426 if (unlikely(ret))
13427 return ret;
13428 asm("":::"memory");
13429 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13430 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13431 ret, "w", "w", "ir", 2);
13432 return ret;
13433 case 16:
13434 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13435 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13436 ret, "q", "", "er", 16);
13437 if (unlikely(ret))
13438 return ret;
13439 asm("":::"memory");
13440 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13441 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13442 ret, "q", "", "er", 8);
13443 return ret;
13444 default:
13445 - return copy_user_generic((__force void *)dst, src, size);
13446 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13447 }
13448 }
13449
13450 static __always_inline __must_check
13451 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13452 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13453 {
13454 - int ret = 0;
13455 + unsigned ret = 0;
13456
13457 might_fault();
13458 +
13459 + if (size > INT_MAX)
13460 + return size;
13461 +
13462 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13463 + if (!__access_ok(VERIFY_READ, src, size))
13464 + return size;
13465 + if (!__access_ok(VERIFY_WRITE, dst, size))
13466 + return size;
13467 +#endif
13468 +
13469 if (!__builtin_constant_p(size))
13470 - return copy_user_generic((__force void *)dst,
13471 - (__force void *)src, size);
13472 + return copy_user_generic((__force_kernel void *)____m(dst),
13473 + (__force_kernel const void *)____m(src), size);
13474 switch (size) {
13475 case 1: {
13476 u8 tmp;
13477 - __get_user_asm(tmp, (u8 __user *)src,
13478 + __get_user_asm(tmp, (const u8 __user *)src,
13479 ret, "b", "b", "=q", 1);
13480 if (likely(!ret))
13481 __put_user_asm(tmp, (u8 __user *)dst,
13482 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13483 }
13484 case 2: {
13485 u16 tmp;
13486 - __get_user_asm(tmp, (u16 __user *)src,
13487 + __get_user_asm(tmp, (const u16 __user *)src,
13488 ret, "w", "w", "=r", 2);
13489 if (likely(!ret))
13490 __put_user_asm(tmp, (u16 __user *)dst,
13491 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13492
13493 case 4: {
13494 u32 tmp;
13495 - __get_user_asm(tmp, (u32 __user *)src,
13496 + __get_user_asm(tmp, (const u32 __user *)src,
13497 ret, "l", "k", "=r", 4);
13498 if (likely(!ret))
13499 __put_user_asm(tmp, (u32 __user *)dst,
13500 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13501 }
13502 case 8: {
13503 u64 tmp;
13504 - __get_user_asm(tmp, (u64 __user *)src,
13505 + __get_user_asm(tmp, (const u64 __user *)src,
13506 ret, "q", "", "=r", 8);
13507 if (likely(!ret))
13508 __put_user_asm(tmp, (u64 __user *)dst,
13509 @@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13510 return ret;
13511 }
13512 default:
13513 - return copy_user_generic((__force void *)dst,
13514 - (__force void *)src, size);
13515 + return copy_user_generic((__force_kernel void *)____m(dst),
13516 + (__force_kernel const void *)____m(src), size);
13517 }
13518 }
13519
13520 static __must_check __always_inline int
13521 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13522 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13523 {
13524 - return copy_user_generic(dst, (__force const void *)src, size);
13525 + if (size > INT_MAX)
13526 + return size;
13527 +
13528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13529 + if (!__access_ok(VERIFY_READ, src, size))
13530 + return size;
13531 +#endif
13532 +
13533 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13534 }
13535
13536 -static __must_check __always_inline int
13537 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13538 +static __must_check __always_inline unsigned long
13539 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13540 {
13541 - return copy_user_generic((__force void *)dst, src, size);
13542 + if (size > INT_MAX)
13543 + return size;
13544 +
13545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13546 + if (!__access_ok(VERIFY_WRITE, dst, size))
13547 + return size;
13548 +#endif
13549 +
13550 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13551 }
13552
13553 -extern long __copy_user_nocache(void *dst, const void __user *src,
13554 - unsigned size, int zerorest);
13555 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13556 + unsigned long size, int zerorest) __size_overflow(3);
13557
13558 -static inline int
13559 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13560 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13561 {
13562 might_sleep();
13563 +
13564 + if (size > INT_MAX)
13565 + return size;
13566 +
13567 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13568 + if (!__access_ok(VERIFY_READ, src, size))
13569 + return size;
13570 +#endif
13571 +
13572 return __copy_user_nocache(dst, src, size, 1);
13573 }
13574
13575 -static inline int
13576 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13577 - unsigned size)
13578 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13579 + unsigned long size)
13580 {
13581 + if (size > INT_MAX)
13582 + return size;
13583 +
13584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13585 + if (!__access_ok(VERIFY_READ, src, size))
13586 + return size;
13587 +#endif
13588 +
13589 return __copy_user_nocache(dst, src, size, 0);
13590 }
13591
13592 -unsigned long
13593 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13594 +extern unsigned long
13595 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13596
13597 #endif /* _ASM_X86_UACCESS_64_H */
13598 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13599 index 5b238981..77fdd78 100644
13600 --- a/arch/x86/include/asm/word-at-a-time.h
13601 +++ b/arch/x86/include/asm/word-at-a-time.h
13602 @@ -11,7 +11,7 @@
13603 * and shift, for example.
13604 */
13605 struct word_at_a_time {
13606 - const unsigned long one_bits, high_bits;
13607 + unsigned long one_bits, high_bits;
13608 };
13609
13610 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13611 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13612 index 5769349..d49a4dd 100644
13613 --- a/arch/x86/include/asm/x86_init.h
13614 +++ b/arch/x86/include/asm/x86_init.h
13615 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13616 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13617 void (*find_smp_config)(void);
13618 void (*get_smp_config)(unsigned int early);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_resources - platform specific resource related ops
13624 @@ -43,7 +43,7 @@ struct x86_init_resources {
13625 void (*probe_roms)(void);
13626 void (*reserve_resources)(void);
13627 char *(*memory_setup)(void);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_irqs - platform specific interrupt setup
13633 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13634 void (*pre_vector_init)(void);
13635 void (*intr_init)(void);
13636 void (*trap_init)(void);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_oem - oem platform specific customizing functions
13642 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13643 struct x86_init_oem {
13644 void (*arch_setup)(void);
13645 void (*banner)(void);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13651 @@ -77,7 +77,7 @@ struct x86_init_oem {
13652 */
13653 struct x86_init_mapping {
13654 void (*pagetable_reserve)(u64 start, u64 end);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_paging - platform specific paging functions
13660 @@ -88,7 +88,7 @@ struct x86_init_mapping {
13661 */
13662 struct x86_init_paging {
13663 void (*pagetable_init)(void);
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_init_timers - platform specific timer setup
13669 @@ -103,7 +103,7 @@ struct x86_init_timers {
13670 void (*tsc_pre_init)(void);
13671 void (*timer_init)(void);
13672 void (*wallclock_init)(void);
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_init_iommu - platform specific iommu setup
13678 @@ -111,7 +111,7 @@ struct x86_init_timers {
13679 */
13680 struct x86_init_iommu {
13681 int (*iommu_init)(void);
13682 -};
13683 +} __no_const;
13684
13685 /**
13686 * struct x86_init_pci - platform specific pci init functions
13687 @@ -125,7 +125,7 @@ struct x86_init_pci {
13688 int (*init)(void);
13689 void (*init_irq)(void);
13690 void (*fixup_irqs)(void);
13691 -};
13692 +} __no_const;
13693
13694 /**
13695 * struct x86_init_ops - functions for platform specific setup
13696 @@ -141,7 +141,7 @@ struct x86_init_ops {
13697 struct x86_init_timers timers;
13698 struct x86_init_iommu iommu;
13699 struct x86_init_pci pci;
13700 -};
13701 +} __no_const;
13702
13703 /**
13704 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13705 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
13706 void (*setup_percpu_clockev)(void);
13707 void (*early_percpu_clock_init)(void);
13708 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13709 -};
13710 +} __no_const;
13711
13712 /**
13713 * struct x86_platform_ops - platform specific runtime functions
13714 @@ -178,7 +178,7 @@ struct x86_platform_ops {
13715 void (*save_sched_clock_state)(void);
13716 void (*restore_sched_clock_state)(void);
13717 void (*apic_post_init)(void);
13718 -};
13719 +} __no_const;
13720
13721 struct pci_dev;
13722
13723 @@ -187,14 +187,14 @@ struct x86_msi_ops {
13724 void (*teardown_msi_irq)(unsigned int irq);
13725 void (*teardown_msi_irqs)(struct pci_dev *dev);
13726 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13727 -};
13728 +} __no_const;
13729
13730 struct x86_io_apic_ops {
13731 void (*init) (void);
13732 unsigned int (*read) (unsigned int apic, unsigned int reg);
13733 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13734 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13735 -};
13736 +} __no_const;
13737
13738 extern struct x86_init_ops x86_init;
13739 extern struct x86_cpuinit_ops x86_cpuinit;
13740 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13741 index 0415cda..b43d877 100644
13742 --- a/arch/x86/include/asm/xsave.h
13743 +++ b/arch/x86/include/asm/xsave.h
13744 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13745 return -EFAULT;
13746
13747 __asm__ __volatile__(ASM_STAC "\n"
13748 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13749 + "1:"
13750 + __copyuser_seg
13751 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
13752 "2: " ASM_CLAC "\n"
13753 ".section .fixup,\"ax\"\n"
13754 "3: movl $-1,%[err]\n"
13755 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13756 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13757 {
13758 int err;
13759 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13760 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13761 u32 lmask = mask;
13762 u32 hmask = mask >> 32;
13763
13764 __asm__ __volatile__(ASM_STAC "\n"
13765 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13766 + "1:"
13767 + __copyuser_seg
13768 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13769 "2: " ASM_CLAC "\n"
13770 ".section .fixup,\"ax\"\n"
13771 "3: movl $-1,%[err]\n"
13772 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
13773 index 91ce48f..a48ea05 100644
13774 --- a/arch/x86/kernel/Makefile
13775 +++ b/arch/x86/kernel/Makefile
13776 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
13777 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
13778 obj-$(CONFIG_IRQ_WORK) += irq_work.o
13779 obj-y += probe_roms.o
13780 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
13781 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
13782 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
13783 obj-y += syscall_$(BITS).o
13784 obj-$(CONFIG_X86_64) += vsyscall_64.o
13785 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13786 index 11676cf..a8cf3ec 100644
13787 --- a/arch/x86/kernel/acpi/sleep.c
13788 +++ b/arch/x86/kernel/acpi/sleep.c
13789 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
13790 #else /* CONFIG_64BIT */
13791 #ifdef CONFIG_SMP
13792 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13793 +
13794 + pax_open_kernel();
13795 early_gdt_descr.address =
13796 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13797 + pax_close_kernel();
13798 +
13799 initial_gs = per_cpu_offset(smp_processor_id());
13800 #endif
13801 initial_code = (unsigned long)wakeup_long64;
13802 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13803 index 13ab720..95d5442 100644
13804 --- a/arch/x86/kernel/acpi/wakeup_32.S
13805 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13806 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13807 # and restore the stack ... but you need gdt for this to work
13808 movl saved_context_esp, %esp
13809
13810 - movl %cs:saved_magic, %eax
13811 - cmpl $0x12345678, %eax
13812 + cmpl $0x12345678, saved_magic
13813 jne bogus_magic
13814
13815 # jump to place where we left off
13816 - movl saved_eip, %eax
13817 - jmp *%eax
13818 + jmp *(saved_eip)
13819
13820 bogus_magic:
13821 jmp bogus_magic
13822 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13823 index ef5ccca..bd83949 100644
13824 --- a/arch/x86/kernel/alternative.c
13825 +++ b/arch/x86/kernel/alternative.c
13826 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13827 */
13828 for (a = start; a < end; a++) {
13829 instr = (u8 *)&a->instr_offset + a->instr_offset;
13830 +
13831 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13832 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13833 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13834 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13835 +#endif
13836 +
13837 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13838 BUG_ON(a->replacementlen > a->instrlen);
13839 BUG_ON(a->instrlen > sizeof(insnbuf));
13840 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13841 for (poff = start; poff < end; poff++) {
13842 u8 *ptr = (u8 *)poff + *poff;
13843
13844 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13845 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13846 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13847 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13848 +#endif
13849 +
13850 if (!*poff || ptr < text || ptr >= text_end)
13851 continue;
13852 /* turn DS segment override prefix into lock prefix */
13853 - if (*ptr == 0x3e)
13854 + if (*ktla_ktva(ptr) == 0x3e)
13855 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13856 }
13857 mutex_unlock(&text_mutex);
13858 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13859 for (poff = start; poff < end; poff++) {
13860 u8 *ptr = (u8 *)poff + *poff;
13861
13862 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13863 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13864 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13865 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13866 +#endif
13867 +
13868 if (!*poff || ptr < text || ptr >= text_end)
13869 continue;
13870 /* turn lock prefix into DS segment override prefix */
13871 - if (*ptr == 0xf0)
13872 + if (*ktla_ktva(ptr) == 0xf0)
13873 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13874 }
13875 mutex_unlock(&text_mutex);
13876 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13877
13878 BUG_ON(p->len > MAX_PATCH_LEN);
13879 /* prep the buffer with the original instructions */
13880 - memcpy(insnbuf, p->instr, p->len);
13881 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13882 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13883 (unsigned long)p->instr, p->len);
13884
13885 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
13886 if (!uniproc_patched || num_possible_cpus() == 1)
13887 free_init_pages("SMP alternatives",
13888 (unsigned long)__smp_locks,
13889 - (unsigned long)__smp_locks_end);
13890 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13891 #endif
13892
13893 apply_paravirt(__parainstructions, __parainstructions_end);
13894 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
13895 * instructions. And on the local CPU you need to be protected again NMI or MCE
13896 * handlers seeing an inconsistent instruction while you patch.
13897 */
13898 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13899 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13900 size_t len)
13901 {
13902 unsigned long flags;
13903 local_irq_save(flags);
13904 - memcpy(addr, opcode, len);
13905 +
13906 + pax_open_kernel();
13907 + memcpy(ktla_ktva(addr), opcode, len);
13908 sync_core();
13909 + pax_close_kernel();
13910 +
13911 local_irq_restore(flags);
13912 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13913 that causes hangs on some VIA CPUs. */
13914 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13915 */
13916 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13917 {
13918 - unsigned long flags;
13919 - char *vaddr;
13920 + unsigned char *vaddr = ktla_ktva(addr);
13921 struct page *pages[2];
13922 - int i;
13923 + size_t i;
13924
13925 if (!core_kernel_text((unsigned long)addr)) {
13926 - pages[0] = vmalloc_to_page(addr);
13927 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13928 + pages[0] = vmalloc_to_page(vaddr);
13929 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13930 } else {
13931 - pages[0] = virt_to_page(addr);
13932 + pages[0] = virt_to_page(vaddr);
13933 WARN_ON(!PageReserved(pages[0]));
13934 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13935 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13936 }
13937 BUG_ON(!pages[0]);
13938 - local_irq_save(flags);
13939 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13940 - if (pages[1])
13941 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13942 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13943 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13944 - clear_fixmap(FIX_TEXT_POKE0);
13945 - if (pages[1])
13946 - clear_fixmap(FIX_TEXT_POKE1);
13947 - local_flush_tlb();
13948 - sync_core();
13949 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13950 - that causes hangs on some VIA CPUs. */
13951 + text_poke_early(addr, opcode, len);
13952 for (i = 0; i < len; i++)
13953 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13954 - local_irq_restore(flags);
13955 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13956 return addr;
13957 }
13958
13959 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13960 index b17416e..be6e5dc 100644
13961 --- a/arch/x86/kernel/apic/apic.c
13962 +++ b/arch/x86/kernel/apic/apic.c
13963 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13964 /*
13965 * Debug level, exported for io_apic.c
13966 */
13967 -unsigned int apic_verbosity;
13968 +int apic_verbosity;
13969
13970 int pic_mode;
13971
13972 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13973 apic_write(APIC_ESR, 0);
13974 v1 = apic_read(APIC_ESR);
13975 ack_APIC_irq();
13976 - atomic_inc(&irq_err_count);
13977 + atomic_inc_unchecked(&irq_err_count);
13978
13979 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13980 smp_processor_id(), v0 , v1);
13981 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13982 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13983 /* Should happen once for each apic */
13984 WARN_ON((*drv)->eoi_write == eoi_write);
13985 - (*drv)->eoi_write = eoi_write;
13986 + pax_open_kernel();
13987 + *(void **)&(*drv)->eoi_write = eoi_write;
13988 + pax_close_kernel();
13989 }
13990 }
13991
13992 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13993 index 1817fa9..7bff097 100644
13994 --- a/arch/x86/kernel/apic/io_apic.c
13995 +++ b/arch/x86/kernel/apic/io_apic.c
13996 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13997 }
13998 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13999
14000 -void lock_vector_lock(void)
14001 +void lock_vector_lock(void) __acquires(vector_lock)
14002 {
14003 /* Used to the online set of cpus does not change
14004 * during assign_irq_vector.
14005 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14006 raw_spin_lock(&vector_lock);
14007 }
14008
14009 -void unlock_vector_lock(void)
14010 +void unlock_vector_lock(void) __releases(vector_lock)
14011 {
14012 raw_spin_unlock(&vector_lock);
14013 }
14014 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14015 ack_APIC_irq();
14016 }
14017
14018 -atomic_t irq_mis_count;
14019 +atomic_unchecked_t irq_mis_count;
14020
14021 #ifdef CONFIG_GENERIC_PENDING_IRQ
14022 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14023 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
14024 * at the cpu.
14025 */
14026 if (!(v & (1 << (i & 0x1f)))) {
14027 - atomic_inc(&irq_mis_count);
14028 + atomic_inc_unchecked(&irq_mis_count);
14029
14030 eoi_ioapic_irq(irq, cfg);
14031 }
14032 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14033 index d65464e..1035d31 100644
14034 --- a/arch/x86/kernel/apm_32.c
14035 +++ b/arch/x86/kernel/apm_32.c
14036 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14037 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14038 * even though they are called in protected mode.
14039 */
14040 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14041 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14042 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14043
14044 static const char driver_version[] = "1.16ac"; /* no spaces */
14045 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14046 BUG_ON(cpu != 0);
14047 gdt = get_cpu_gdt_table(cpu);
14048 save_desc_40 = gdt[0x40 / 8];
14049 +
14050 + pax_open_kernel();
14051 gdt[0x40 / 8] = bad_bios_desc;
14052 + pax_close_kernel();
14053
14054 apm_irq_save(flags);
14055 APM_DO_SAVE_SEGS;
14056 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14057 &call->esi);
14058 APM_DO_RESTORE_SEGS;
14059 apm_irq_restore(flags);
14060 +
14061 + pax_open_kernel();
14062 gdt[0x40 / 8] = save_desc_40;
14063 + pax_close_kernel();
14064 +
14065 put_cpu();
14066
14067 return call->eax & 0xff;
14068 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14069 BUG_ON(cpu != 0);
14070 gdt = get_cpu_gdt_table(cpu);
14071 save_desc_40 = gdt[0x40 / 8];
14072 +
14073 + pax_open_kernel();
14074 gdt[0x40 / 8] = bad_bios_desc;
14075 + pax_close_kernel();
14076
14077 apm_irq_save(flags);
14078 APM_DO_SAVE_SEGS;
14079 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14080 &call->eax);
14081 APM_DO_RESTORE_SEGS;
14082 apm_irq_restore(flags);
14083 +
14084 + pax_open_kernel();
14085 gdt[0x40 / 8] = save_desc_40;
14086 + pax_close_kernel();
14087 +
14088 put_cpu();
14089 return error;
14090 }
14091 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14092 * code to that CPU.
14093 */
14094 gdt = get_cpu_gdt_table(0);
14095 +
14096 + pax_open_kernel();
14097 set_desc_base(&gdt[APM_CS >> 3],
14098 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14099 set_desc_base(&gdt[APM_CS_16 >> 3],
14100 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14101 set_desc_base(&gdt[APM_DS >> 3],
14102 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14103 + pax_close_kernel();
14104
14105 proc_create("apm", 0, NULL, &apm_file_ops);
14106
14107 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14108 index 2861082..6d4718e 100644
14109 --- a/arch/x86/kernel/asm-offsets.c
14110 +++ b/arch/x86/kernel/asm-offsets.c
14111 @@ -33,6 +33,8 @@ void common(void) {
14112 OFFSET(TI_status, thread_info, status);
14113 OFFSET(TI_addr_limit, thread_info, addr_limit);
14114 OFFSET(TI_preempt_count, thread_info, preempt_count);
14115 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14116 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14117
14118 BLANK();
14119 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14120 @@ -53,8 +55,26 @@ void common(void) {
14121 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14122 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14123 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14124 +
14125 +#ifdef CONFIG_PAX_KERNEXEC
14126 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14127 #endif
14128
14129 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14130 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14131 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14132 +#ifdef CONFIG_X86_64
14133 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14134 +#endif
14135 +#endif
14136 +
14137 +#endif
14138 +
14139 + BLANK();
14140 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14141 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14142 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14143 +
14144 #ifdef CONFIG_XEN
14145 BLANK();
14146 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14147 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14148 index 1b4754f..fbb4227 100644
14149 --- a/arch/x86/kernel/asm-offsets_64.c
14150 +++ b/arch/x86/kernel/asm-offsets_64.c
14151 @@ -76,6 +76,7 @@ int main(void)
14152 BLANK();
14153 #undef ENTRY
14154
14155 + DEFINE(TSS_size, sizeof(struct tss_struct));
14156 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14157 BLANK();
14158
14159 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14160 index a0e067d..9c7db16 100644
14161 --- a/arch/x86/kernel/cpu/Makefile
14162 +++ b/arch/x86/kernel/cpu/Makefile
14163 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14164 CFLAGS_REMOVE_perf_event.o = -pg
14165 endif
14166
14167 -# Make sure load_percpu_segment has no stackprotector
14168 -nostackp := $(call cc-option, -fno-stack-protector)
14169 -CFLAGS_common.o := $(nostackp)
14170 -
14171 obj-y := intel_cacheinfo.o scattered.o topology.o
14172 obj-y += proc.o capflags.o powerflags.o common.o
14173 obj-y += vmware.o hypervisor.o mshyperv.o
14174 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14175 index 1b7d165..b9e2627 100644
14176 --- a/arch/x86/kernel/cpu/amd.c
14177 +++ b/arch/x86/kernel/cpu/amd.c
14178 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14179 unsigned int size)
14180 {
14181 /* AMD errata T13 (order #21922) */
14182 - if ((c->x86 == 6)) {
14183 + if (c->x86 == 6) {
14184 /* Duron Rev A0 */
14185 if (c->x86_model == 3 && c->x86_mask == 0)
14186 size = 64;
14187 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14188 index 7505f7b..d59dac0 100644
14189 --- a/arch/x86/kernel/cpu/common.c
14190 +++ b/arch/x86/kernel/cpu/common.c
14191 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14192
14193 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14194
14195 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14196 -#ifdef CONFIG_X86_64
14197 - /*
14198 - * We need valid kernel segments for data and code in long mode too
14199 - * IRET will check the segment types kkeil 2000/10/28
14200 - * Also sysret mandates a special GDT layout
14201 - *
14202 - * TLS descriptors are currently at a different place compared to i386.
14203 - * Hopefully nobody expects them at a fixed place (Wine?)
14204 - */
14205 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14206 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14207 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14208 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14209 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14210 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14211 -#else
14212 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14213 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14214 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14215 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14216 - /*
14217 - * Segments used for calling PnP BIOS have byte granularity.
14218 - * They code segments and data segments have fixed 64k limits,
14219 - * the transfer segment sizes are set at run time.
14220 - */
14221 - /* 32-bit code */
14222 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14223 - /* 16-bit code */
14224 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14225 - /* 16-bit data */
14226 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14227 - /* 16-bit data */
14228 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14229 - /* 16-bit data */
14230 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14231 - /*
14232 - * The APM segments have byte granularity and their bases
14233 - * are set at run time. All have 64k limits.
14234 - */
14235 - /* 32-bit code */
14236 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14237 - /* 16-bit code */
14238 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14239 - /* data */
14240 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14241 -
14242 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14243 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14244 - GDT_STACK_CANARY_INIT
14245 -#endif
14246 -} };
14247 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14248 -
14249 static int __init x86_xsave_setup(char *s)
14250 {
14251 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14252 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
14253 {
14254 struct desc_ptr gdt_descr;
14255
14256 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14257 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14258 gdt_descr.size = GDT_SIZE - 1;
14259 load_gdt(&gdt_descr);
14260 /* Reload the per-cpu base */
14261 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14262 /* Filter out anything that depends on CPUID levels we don't have */
14263 filter_cpuid_features(c, true);
14264
14265 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14266 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14267 +#endif
14268 +
14269 /* If the model name is still unset, do table lookup. */
14270 if (!c->x86_model_id[0]) {
14271 const char *p;
14272 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
14273 }
14274 __setup("clearcpuid=", setup_disablecpuid);
14275
14276 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14277 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14278 +
14279 #ifdef CONFIG_X86_64
14280 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14281 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14282 - (unsigned long) nmi_idt_table };
14283 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14284
14285 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14286 irq_stack_union) __aligned(PAGE_SIZE);
14287 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14288 EXPORT_PER_CPU_SYMBOL(current_task);
14289
14290 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14291 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14292 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14293 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14294
14295 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14296 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14297 {
14298 memset(regs, 0, sizeof(struct pt_regs));
14299 regs->fs = __KERNEL_PERCPU;
14300 - regs->gs = __KERNEL_STACK_CANARY;
14301 + savesegment(gs, regs->gs);
14302
14303 return regs;
14304 }
14305 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
14306 int i;
14307
14308 cpu = stack_smp_processor_id();
14309 - t = &per_cpu(init_tss, cpu);
14310 + t = init_tss + cpu;
14311 oist = &per_cpu(orig_ist, cpu);
14312
14313 #ifdef CONFIG_NUMA
14314 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
14315 switch_to_new_gdt(cpu);
14316 loadsegment(fs, 0);
14317
14318 - load_idt((const struct desc_ptr *)&idt_descr);
14319 + load_idt(&idt_descr);
14320
14321 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14322 syscall_init();
14323 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
14324 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14325 barrier();
14326
14327 - x86_configure_nx();
14328 if (cpu != 0)
14329 enable_x2apic();
14330
14331 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
14332 {
14333 int cpu = smp_processor_id();
14334 struct task_struct *curr = current;
14335 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14336 + struct tss_struct *t = init_tss + cpu;
14337 struct thread_struct *thread = &curr->thread;
14338
14339 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14340 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14341 index 198e019..867575e 100644
14342 --- a/arch/x86/kernel/cpu/intel.c
14343 +++ b/arch/x86/kernel/cpu/intel.c
14344 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14345 * Update the IDT descriptor and reload the IDT so that
14346 * it uses the read-only mapped virtual address.
14347 */
14348 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14349 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14350 load_idt(&idt_descr);
14351 }
14352 #endif
14353 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14354 index 46cbf86..8f8d94c 100644
14355 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14356 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14357 @@ -45,6 +45,7 @@
14358 #include <asm/processor.h>
14359 #include <asm/mce.h>
14360 #include <asm/msr.h>
14361 +#include <asm/local.h>
14362
14363 #include "mce-internal.h"
14364
14365 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
14366 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14367 m->cs, m->ip);
14368
14369 - if (m->cs == __KERNEL_CS)
14370 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14371 print_symbol("{%s}", m->ip);
14372 pr_cont("\n");
14373 }
14374 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
14375
14376 #define PANIC_TIMEOUT 5 /* 5 seconds */
14377
14378 -static atomic_t mce_paniced;
14379 +static atomic_unchecked_t mce_paniced;
14380
14381 static int fake_panic;
14382 -static atomic_t mce_fake_paniced;
14383 +static atomic_unchecked_t mce_fake_paniced;
14384
14385 /* Panic in progress. Enable interrupts and wait for final IPI */
14386 static void wait_for_panic(void)
14387 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14388 /*
14389 * Make sure only one CPU runs in machine check panic
14390 */
14391 - if (atomic_inc_return(&mce_paniced) > 1)
14392 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14393 wait_for_panic();
14394 barrier();
14395
14396 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14397 console_verbose();
14398 } else {
14399 /* Don't log too much for fake panic */
14400 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14401 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14402 return;
14403 }
14404 /* First print corrected ones that are still unlogged */
14405 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
14406 * might have been modified by someone else.
14407 */
14408 rmb();
14409 - if (atomic_read(&mce_paniced))
14410 + if (atomic_read_unchecked(&mce_paniced))
14411 wait_for_panic();
14412 if (!monarch_timeout)
14413 goto out;
14414 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14415 }
14416
14417 /* Call the installed machine check handler for this CPU setup. */
14418 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14419 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14420 unexpected_machine_check;
14421
14422 /*
14423 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14424 return;
14425 }
14426
14427 + pax_open_kernel();
14428 machine_check_vector = do_machine_check;
14429 + pax_close_kernel();
14430
14431 __mcheck_cpu_init_generic();
14432 __mcheck_cpu_init_vendor(c);
14433 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14434 */
14435
14436 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14437 -static int mce_chrdev_open_count; /* #times opened */
14438 +static local_t mce_chrdev_open_count; /* #times opened */
14439 static int mce_chrdev_open_exclu; /* already open exclusive? */
14440
14441 static int mce_chrdev_open(struct inode *inode, struct file *file)
14442 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14443 spin_lock(&mce_chrdev_state_lock);
14444
14445 if (mce_chrdev_open_exclu ||
14446 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14447 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14448 spin_unlock(&mce_chrdev_state_lock);
14449
14450 return -EBUSY;
14451 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14452
14453 if (file->f_flags & O_EXCL)
14454 mce_chrdev_open_exclu = 1;
14455 - mce_chrdev_open_count++;
14456 + local_inc(&mce_chrdev_open_count);
14457
14458 spin_unlock(&mce_chrdev_state_lock);
14459
14460 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14461 {
14462 spin_lock(&mce_chrdev_state_lock);
14463
14464 - mce_chrdev_open_count--;
14465 + local_dec(&mce_chrdev_open_count);
14466 mce_chrdev_open_exclu = 0;
14467
14468 spin_unlock(&mce_chrdev_state_lock);
14469 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
14470 static void mce_reset(void)
14471 {
14472 cpu_missing = 0;
14473 - atomic_set(&mce_fake_paniced, 0);
14474 + atomic_set_unchecked(&mce_fake_paniced, 0);
14475 atomic_set(&mce_executing, 0);
14476 atomic_set(&mce_callin, 0);
14477 atomic_set(&global_nwo, 0);
14478 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14479 index 2d5454c..51987eb 100644
14480 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14481 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14482 @@ -11,6 +11,7 @@
14483 #include <asm/processor.h>
14484 #include <asm/mce.h>
14485 #include <asm/msr.h>
14486 +#include <asm/pgtable.h>
14487
14488 /* By default disabled */
14489 int mce_p5_enabled __read_mostly;
14490 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14491 if (!cpu_has(c, X86_FEATURE_MCE))
14492 return;
14493
14494 + pax_open_kernel();
14495 machine_check_vector = pentium_machine_check;
14496 + pax_close_kernel();
14497 /* Make sure the vector pointer is visible before we enable MCEs: */
14498 wmb();
14499
14500 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14501 index 2d7998f..17c9de1 100644
14502 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14503 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14504 @@ -10,6 +10,7 @@
14505 #include <asm/processor.h>
14506 #include <asm/mce.h>
14507 #include <asm/msr.h>
14508 +#include <asm/pgtable.h>
14509
14510 /* Machine check handler for WinChip C6: */
14511 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14512 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14513 {
14514 u32 lo, hi;
14515
14516 + pax_open_kernel();
14517 machine_check_vector = winchip_machine_check;
14518 + pax_close_kernel();
14519 /* Make sure the vector pointer is visible before we enable MCEs: */
14520 wmb();
14521
14522 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14523 index 6b96110..0da73eb 100644
14524 --- a/arch/x86/kernel/cpu/mtrr/main.c
14525 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14526 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14527 u64 size_or_mask, size_and_mask;
14528 static bool mtrr_aps_delayed_init;
14529
14530 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14531 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14532
14533 const struct mtrr_ops *mtrr_if;
14534
14535 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14536 index df5e41f..816c719 100644
14537 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14538 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14539 @@ -25,7 +25,7 @@ struct mtrr_ops {
14540 int (*validate_add_page)(unsigned long base, unsigned long size,
14541 unsigned int type);
14542 int (*have_wrcomb)(void);
14543 -};
14544 +} __do_const;
14545
14546 extern int generic_get_free_region(unsigned long base, unsigned long size,
14547 int replace_reg);
14548 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14549 index 4a3374e..1ca3ecb 100644
14550 --- a/arch/x86/kernel/cpu/perf_event.c
14551 +++ b/arch/x86/kernel/cpu/perf_event.c
14552 @@ -1765,7 +1765,7 @@ static unsigned long get_segment_base(unsigned int segment)
14553 if (idx > GDT_ENTRIES)
14554 return 0;
14555
14556 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14557 + desc = get_cpu_gdt_table(smp_processor_id());
14558 }
14559
14560 return get_desc_base(desc + idx);
14561 @@ -1855,7 +1855,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14562 break;
14563
14564 perf_callchain_store(entry, frame.return_address);
14565 - fp = frame.next_frame;
14566 + fp = (const void __force_user *)frame.next_frame;
14567 }
14568 }
14569
14570 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14571 index 324bb52..1a93d85 100644
14572 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14573 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14574 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
14575 * v2 and above have a perf capabilities MSR
14576 */
14577 if (version > 1) {
14578 - u64 capabilities;
14579 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14580
14581 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14582 - x86_pmu.intel_cap.capabilities = capabilities;
14583 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14584 + x86_pmu.intel_cap.capabilities = capabilities;
14585 }
14586
14587 intel_ds_init();
14588 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14589 index 13ad899..f642b9a 100644
14590 --- a/arch/x86/kernel/crash.c
14591 +++ b/arch/x86/kernel/crash.c
14592 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14593 {
14594 #ifdef CONFIG_X86_32
14595 struct pt_regs fixed_regs;
14596 -#endif
14597
14598 -#ifdef CONFIG_X86_32
14599 - if (!user_mode_vm(regs)) {
14600 + if (!user_mode(regs)) {
14601 crash_fixup_ss_esp(&fixed_regs, regs);
14602 regs = &fixed_regs;
14603 }
14604 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14605 index 37250fe..bf2ec74 100644
14606 --- a/arch/x86/kernel/doublefault_32.c
14607 +++ b/arch/x86/kernel/doublefault_32.c
14608 @@ -11,7 +11,7 @@
14609
14610 #define DOUBLEFAULT_STACKSIZE (1024)
14611 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14612 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14613 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14614
14615 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14616
14617 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14618 unsigned long gdt, tss;
14619
14620 store_gdt(&gdt_desc);
14621 - gdt = gdt_desc.address;
14622 + gdt = (unsigned long)gdt_desc.address;
14623
14624 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14625
14626 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14627 /* 0x2 bit is always set */
14628 .flags = X86_EFLAGS_SF | 0x2,
14629 .sp = STACK_START,
14630 - .es = __USER_DS,
14631 + .es = __KERNEL_DS,
14632 .cs = __KERNEL_CS,
14633 .ss = __KERNEL_DS,
14634 - .ds = __USER_DS,
14635 + .ds = __KERNEL_DS,
14636 .fs = __KERNEL_PERCPU,
14637
14638 .__cr3 = __pa_nodebug(swapper_pg_dir),
14639 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14640 index ae42418b..787c16b 100644
14641 --- a/arch/x86/kernel/dumpstack.c
14642 +++ b/arch/x86/kernel/dumpstack.c
14643 @@ -2,6 +2,9 @@
14644 * Copyright (C) 1991, 1992 Linus Torvalds
14645 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14646 */
14647 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14648 +#define __INCLUDED_BY_HIDESYM 1
14649 +#endif
14650 #include <linux/kallsyms.h>
14651 #include <linux/kprobes.h>
14652 #include <linux/uaccess.h>
14653 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14654 static void
14655 print_ftrace_graph_addr(unsigned long addr, void *data,
14656 const struct stacktrace_ops *ops,
14657 - struct thread_info *tinfo, int *graph)
14658 + struct task_struct *task, int *graph)
14659 {
14660 - struct task_struct *task;
14661 unsigned long ret_addr;
14662 int index;
14663
14664 if (addr != (unsigned long)return_to_handler)
14665 return;
14666
14667 - task = tinfo->task;
14668 index = task->curr_ret_stack;
14669
14670 if (!task->ret_stack || index < *graph)
14671 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14672 static inline void
14673 print_ftrace_graph_addr(unsigned long addr, void *data,
14674 const struct stacktrace_ops *ops,
14675 - struct thread_info *tinfo, int *graph)
14676 + struct task_struct *task, int *graph)
14677 { }
14678 #endif
14679
14680 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14681 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14682 */
14683
14684 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14685 - void *p, unsigned int size, void *end)
14686 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14687 {
14688 - void *t = tinfo;
14689 if (end) {
14690 if (p < end && p >= (end-THREAD_SIZE))
14691 return 1;
14692 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14693 }
14694
14695 unsigned long
14696 -print_context_stack(struct thread_info *tinfo,
14697 +print_context_stack(struct task_struct *task, void *stack_start,
14698 unsigned long *stack, unsigned long bp,
14699 const struct stacktrace_ops *ops, void *data,
14700 unsigned long *end, int *graph)
14701 {
14702 struct stack_frame *frame = (struct stack_frame *)bp;
14703
14704 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14705 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14706 unsigned long addr;
14707
14708 addr = *stack;
14709 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14710 } else {
14711 ops->address(data, addr, 0);
14712 }
14713 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14714 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14715 }
14716 stack++;
14717 }
14718 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14719 EXPORT_SYMBOL_GPL(print_context_stack);
14720
14721 unsigned long
14722 -print_context_stack_bp(struct thread_info *tinfo,
14723 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14724 unsigned long *stack, unsigned long bp,
14725 const struct stacktrace_ops *ops, void *data,
14726 unsigned long *end, int *graph)
14727 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14728 struct stack_frame *frame = (struct stack_frame *)bp;
14729 unsigned long *ret_addr = &frame->return_address;
14730
14731 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14732 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14733 unsigned long addr = *ret_addr;
14734
14735 if (!__kernel_text_address(addr))
14736 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14737 ops->address(data, addr, 1);
14738 frame = frame->next_frame;
14739 ret_addr = &frame->return_address;
14740 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14741 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14742 }
14743
14744 return (unsigned long)frame;
14745 @@ -189,7 +188,7 @@ void dump_stack(void)
14746
14747 bp = stack_frame(current, NULL);
14748 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14749 - current->pid, current->comm, print_tainted(),
14750 + task_pid_nr(current), current->comm, print_tainted(),
14751 init_utsname()->release,
14752 (int)strcspn(init_utsname()->version, " "),
14753 init_utsname()->version);
14754 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14755 }
14756 EXPORT_SYMBOL_GPL(oops_begin);
14757
14758 +extern void gr_handle_kernel_exploit(void);
14759 +
14760 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14761 {
14762 if (regs && kexec_should_crash(current))
14763 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14764 panic("Fatal exception in interrupt");
14765 if (panic_on_oops)
14766 panic("Fatal exception");
14767 - do_exit(signr);
14768 +
14769 + gr_handle_kernel_exploit();
14770 +
14771 + do_group_exit(signr);
14772 }
14773
14774 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14775 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14776 print_modules();
14777 show_regs(regs);
14778 #ifdef CONFIG_X86_32
14779 - if (user_mode_vm(regs)) {
14780 + if (user_mode(regs)) {
14781 sp = regs->sp;
14782 ss = regs->ss & 0xffff;
14783 } else {
14784 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14785 unsigned long flags = oops_begin();
14786 int sig = SIGSEGV;
14787
14788 - if (!user_mode_vm(regs))
14789 + if (!user_mode(regs))
14790 report_bug(regs->ip, regs);
14791
14792 if (__die(str, regs, err))
14793 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14794 index 1038a41..db2c12b 100644
14795 --- a/arch/x86/kernel/dumpstack_32.c
14796 +++ b/arch/x86/kernel/dumpstack_32.c
14797 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14798 bp = stack_frame(task, regs);
14799
14800 for (;;) {
14801 - struct thread_info *context;
14802 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14803
14804 - context = (struct thread_info *)
14805 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14806 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14807 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14808
14809 - stack = (unsigned long *)context->previous_esp;
14810 - if (!stack)
14811 + if (stack_start == task_stack_page(task))
14812 break;
14813 + stack = *(unsigned long **)stack_start;
14814 if (ops->stack(data, "IRQ") < 0)
14815 break;
14816 touch_nmi_watchdog();
14817 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14818 {
14819 int i;
14820
14821 - __show_regs(regs, !user_mode_vm(regs));
14822 + __show_regs(regs, !user_mode(regs));
14823
14824 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14825 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14826 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14827 * When in-kernel, we also print out the stack and code at the
14828 * time of the fault..
14829 */
14830 - if (!user_mode_vm(regs)) {
14831 + if (!user_mode(regs)) {
14832 unsigned int code_prologue = code_bytes * 43 / 64;
14833 unsigned int code_len = code_bytes;
14834 unsigned char c;
14835 u8 *ip;
14836 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
14837
14838 pr_emerg("Stack:\n");
14839 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14840
14841 pr_emerg("Code:");
14842
14843 - ip = (u8 *)regs->ip - code_prologue;
14844 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14845 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14846 /* try starting at IP */
14847 - ip = (u8 *)regs->ip;
14848 + ip = (u8 *)regs->ip + cs_base;
14849 code_len = code_len - code_prologue + 1;
14850 }
14851 for (i = 0; i < code_len; i++, ip++) {
14852 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14853 pr_cont(" Bad EIP value.");
14854 break;
14855 }
14856 - if (ip == (u8 *)regs->ip)
14857 + if (ip == (u8 *)regs->ip + cs_base)
14858 pr_cont(" <%02x>", c);
14859 else
14860 pr_cont(" %02x", c);
14861 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14862 {
14863 unsigned short ud2;
14864
14865 + ip = ktla_ktva(ip);
14866 if (ip < PAGE_OFFSET)
14867 return 0;
14868 if (probe_kernel_address((unsigned short *)ip, ud2))
14869 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14870
14871 return ud2 == 0x0b0f;
14872 }
14873 +
14874 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14875 +void pax_check_alloca(unsigned long size)
14876 +{
14877 + unsigned long sp = (unsigned long)&sp, stack_left;
14878 +
14879 + /* all kernel stacks are of the same size */
14880 + stack_left = sp & (THREAD_SIZE - 1);
14881 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14882 +}
14883 +EXPORT_SYMBOL(pax_check_alloca);
14884 +#endif
14885 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14886 index b653675..51cc8c0 100644
14887 --- a/arch/x86/kernel/dumpstack_64.c
14888 +++ b/arch/x86/kernel/dumpstack_64.c
14889 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14890 unsigned long *irq_stack_end =
14891 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14892 unsigned used = 0;
14893 - struct thread_info *tinfo;
14894 int graph = 0;
14895 unsigned long dummy;
14896 + void *stack_start;
14897
14898 if (!task)
14899 task = current;
14900 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14901 * current stack address. If the stacks consist of nested
14902 * exceptions
14903 */
14904 - tinfo = task_thread_info(task);
14905 for (;;) {
14906 char *id;
14907 unsigned long *estack_end;
14908 +
14909 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14910 &used, &id);
14911
14912 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14913 if (ops->stack(data, id) < 0)
14914 break;
14915
14916 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14917 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14918 data, estack_end, &graph);
14919 ops->stack(data, "<EOE>");
14920 /*
14921 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14922 * second-to-last pointer (index -2 to end) in the
14923 * exception stack:
14924 */
14925 + if ((u16)estack_end[-1] != __KERNEL_DS)
14926 + goto out;
14927 stack = (unsigned long *) estack_end[-2];
14928 continue;
14929 }
14930 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14931 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14932 if (ops->stack(data, "IRQ") < 0)
14933 break;
14934 - bp = ops->walk_stack(tinfo, stack, bp,
14935 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14936 ops, data, irq_stack_end, &graph);
14937 /*
14938 * We link to the next stack (which would be
14939 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14940 /*
14941 * This handles the process stack:
14942 */
14943 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14944 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14945 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14946 +out:
14947 put_cpu();
14948 }
14949 EXPORT_SYMBOL(dump_trace);
14950 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
14951 {
14952 int i;
14953 unsigned long sp;
14954 - const int cpu = smp_processor_id();
14955 + const int cpu = raw_smp_processor_id();
14956 struct task_struct *cur = current;
14957
14958 sp = regs->sp;
14959 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14960
14961 return ud2 == 0x0b0f;
14962 }
14963 +
14964 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14965 +void pax_check_alloca(unsigned long size)
14966 +{
14967 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14968 + unsigned cpu, used;
14969 + char *id;
14970 +
14971 + /* check the process stack first */
14972 + stack_start = (unsigned long)task_stack_page(current);
14973 + stack_end = stack_start + THREAD_SIZE;
14974 + if (likely(stack_start <= sp && sp < stack_end)) {
14975 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14976 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14977 + return;
14978 + }
14979 +
14980 + cpu = get_cpu();
14981 +
14982 + /* check the irq stacks */
14983 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14984 + stack_start = stack_end - IRQ_STACK_SIZE;
14985 + if (stack_start <= sp && sp < stack_end) {
14986 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14987 + put_cpu();
14988 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14989 + return;
14990 + }
14991 +
14992 + /* check the exception stacks */
14993 + used = 0;
14994 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14995 + stack_start = stack_end - EXCEPTION_STKSZ;
14996 + if (stack_end && stack_start <= sp && sp < stack_end) {
14997 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14998 + put_cpu();
14999 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15000 + return;
15001 + }
15002 +
15003 + put_cpu();
15004 +
15005 + /* unknown stack */
15006 + BUG();
15007 +}
15008 +EXPORT_SYMBOL(pax_check_alloca);
15009 +#endif
15010 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15011 index 9b9f18b..9fcaa04 100644
15012 --- a/arch/x86/kernel/early_printk.c
15013 +++ b/arch/x86/kernel/early_printk.c
15014 @@ -7,6 +7,7 @@
15015 #include <linux/pci_regs.h>
15016 #include <linux/pci_ids.h>
15017 #include <linux/errno.h>
15018 +#include <linux/sched.h>
15019 #include <asm/io.h>
15020 #include <asm/processor.h>
15021 #include <asm/fcntl.h>
15022 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15023 index 88b725a..3efabf6 100644
15024 --- a/arch/x86/kernel/entry_32.S
15025 +++ b/arch/x86/kernel/entry_32.S
15026 @@ -177,13 +177,153 @@
15027 /*CFI_REL_OFFSET gs, PT_GS*/
15028 .endm
15029 .macro SET_KERNEL_GS reg
15030 +
15031 +#ifdef CONFIG_CC_STACKPROTECTOR
15032 movl $(__KERNEL_STACK_CANARY), \reg
15033 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15034 + movl $(__USER_DS), \reg
15035 +#else
15036 + xorl \reg, \reg
15037 +#endif
15038 +
15039 movl \reg, %gs
15040 .endm
15041
15042 #endif /* CONFIG_X86_32_LAZY_GS */
15043
15044 -.macro SAVE_ALL
15045 +.macro pax_enter_kernel
15046 +#ifdef CONFIG_PAX_KERNEXEC
15047 + call pax_enter_kernel
15048 +#endif
15049 +.endm
15050 +
15051 +.macro pax_exit_kernel
15052 +#ifdef CONFIG_PAX_KERNEXEC
15053 + call pax_exit_kernel
15054 +#endif
15055 +.endm
15056 +
15057 +#ifdef CONFIG_PAX_KERNEXEC
15058 +ENTRY(pax_enter_kernel)
15059 +#ifdef CONFIG_PARAVIRT
15060 + pushl %eax
15061 + pushl %ecx
15062 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15063 + mov %eax, %esi
15064 +#else
15065 + mov %cr0, %esi
15066 +#endif
15067 + bts $16, %esi
15068 + jnc 1f
15069 + mov %cs, %esi
15070 + cmp $__KERNEL_CS, %esi
15071 + jz 3f
15072 + ljmp $__KERNEL_CS, $3f
15073 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15074 +2:
15075 +#ifdef CONFIG_PARAVIRT
15076 + mov %esi, %eax
15077 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15078 +#else
15079 + mov %esi, %cr0
15080 +#endif
15081 +3:
15082 +#ifdef CONFIG_PARAVIRT
15083 + popl %ecx
15084 + popl %eax
15085 +#endif
15086 + ret
15087 +ENDPROC(pax_enter_kernel)
15088 +
15089 +ENTRY(pax_exit_kernel)
15090 +#ifdef CONFIG_PARAVIRT
15091 + pushl %eax
15092 + pushl %ecx
15093 +#endif
15094 + mov %cs, %esi
15095 + cmp $__KERNEXEC_KERNEL_CS, %esi
15096 + jnz 2f
15097 +#ifdef CONFIG_PARAVIRT
15098 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15099 + mov %eax, %esi
15100 +#else
15101 + mov %cr0, %esi
15102 +#endif
15103 + btr $16, %esi
15104 + ljmp $__KERNEL_CS, $1f
15105 +1:
15106 +#ifdef CONFIG_PARAVIRT
15107 + mov %esi, %eax
15108 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15109 +#else
15110 + mov %esi, %cr0
15111 +#endif
15112 +2:
15113 +#ifdef CONFIG_PARAVIRT
15114 + popl %ecx
15115 + popl %eax
15116 +#endif
15117 + ret
15118 +ENDPROC(pax_exit_kernel)
15119 +#endif
15120 +
15121 +.macro pax_erase_kstack
15122 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15123 + call pax_erase_kstack
15124 +#endif
15125 +.endm
15126 +
15127 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15128 +/*
15129 + * ebp: thread_info
15130 + */
15131 +ENTRY(pax_erase_kstack)
15132 + pushl %edi
15133 + pushl %ecx
15134 + pushl %eax
15135 +
15136 + mov TI_lowest_stack(%ebp), %edi
15137 + mov $-0xBEEF, %eax
15138 + std
15139 +
15140 +1: mov %edi, %ecx
15141 + and $THREAD_SIZE_asm - 1, %ecx
15142 + shr $2, %ecx
15143 + repne scasl
15144 + jecxz 2f
15145 +
15146 + cmp $2*16, %ecx
15147 + jc 2f
15148 +
15149 + mov $2*16, %ecx
15150 + repe scasl
15151 + jecxz 2f
15152 + jne 1b
15153 +
15154 +2: cld
15155 + mov %esp, %ecx
15156 + sub %edi, %ecx
15157 +
15158 + cmp $THREAD_SIZE_asm, %ecx
15159 + jb 3f
15160 + ud2
15161 +3:
15162 +
15163 + shr $2, %ecx
15164 + rep stosl
15165 +
15166 + mov TI_task_thread_sp0(%ebp), %edi
15167 + sub $128, %edi
15168 + mov %edi, TI_lowest_stack(%ebp)
15169 +
15170 + popl %eax
15171 + popl %ecx
15172 + popl %edi
15173 + ret
15174 +ENDPROC(pax_erase_kstack)
15175 +#endif
15176 +
15177 +.macro __SAVE_ALL _DS
15178 cld
15179 PUSH_GS
15180 pushl_cfi %fs
15181 @@ -206,7 +346,7 @@
15182 CFI_REL_OFFSET ecx, 0
15183 pushl_cfi %ebx
15184 CFI_REL_OFFSET ebx, 0
15185 - movl $(__USER_DS), %edx
15186 + movl $\_DS, %edx
15187 movl %edx, %ds
15188 movl %edx, %es
15189 movl $(__KERNEL_PERCPU), %edx
15190 @@ -214,6 +354,15 @@
15191 SET_KERNEL_GS %edx
15192 .endm
15193
15194 +.macro SAVE_ALL
15195 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15196 + __SAVE_ALL __KERNEL_DS
15197 + pax_enter_kernel
15198 +#else
15199 + __SAVE_ALL __USER_DS
15200 +#endif
15201 +.endm
15202 +
15203 .macro RESTORE_INT_REGS
15204 popl_cfi %ebx
15205 CFI_RESTORE ebx
15206 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
15207 popfl_cfi
15208 jmp syscall_exit
15209 CFI_ENDPROC
15210 -END(ret_from_fork)
15211 +ENDPROC(ret_from_fork)
15212
15213 ENTRY(ret_from_kernel_thread)
15214 CFI_STARTPROC
15215 @@ -344,7 +493,15 @@ ret_from_intr:
15216 andl $SEGMENT_RPL_MASK, %eax
15217 #endif
15218 cmpl $USER_RPL, %eax
15219 +
15220 +#ifdef CONFIG_PAX_KERNEXEC
15221 + jae resume_userspace
15222 +
15223 + pax_exit_kernel
15224 + jmp resume_kernel
15225 +#else
15226 jb resume_kernel # not returning to v8086 or userspace
15227 +#endif
15228
15229 ENTRY(resume_userspace)
15230 LOCKDEP_SYS_EXIT
15231 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
15232 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15233 # int/exception return?
15234 jne work_pending
15235 - jmp restore_all
15236 -END(ret_from_exception)
15237 + jmp restore_all_pax
15238 +ENDPROC(ret_from_exception)
15239
15240 #ifdef CONFIG_PREEMPT
15241 ENTRY(resume_kernel)
15242 @@ -372,7 +529,7 @@ need_resched:
15243 jz restore_all
15244 call preempt_schedule_irq
15245 jmp need_resched
15246 -END(resume_kernel)
15247 +ENDPROC(resume_kernel)
15248 #endif
15249 CFI_ENDPROC
15250 /*
15251 @@ -406,30 +563,45 @@ sysenter_past_esp:
15252 /*CFI_REL_OFFSET cs, 0*/
15253 /*
15254 * Push current_thread_info()->sysenter_return to the stack.
15255 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15256 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15257 */
15258 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15259 + pushl_cfi $0
15260 CFI_REL_OFFSET eip, 0
15261
15262 pushl_cfi %eax
15263 SAVE_ALL
15264 + GET_THREAD_INFO(%ebp)
15265 + movl TI_sysenter_return(%ebp),%ebp
15266 + movl %ebp,PT_EIP(%esp)
15267 ENABLE_INTERRUPTS(CLBR_NONE)
15268
15269 /*
15270 * Load the potential sixth argument from user stack.
15271 * Careful about security.
15272 */
15273 + movl PT_OLDESP(%esp),%ebp
15274 +
15275 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15276 + mov PT_OLDSS(%esp),%ds
15277 +1: movl %ds:(%ebp),%ebp
15278 + push %ss
15279 + pop %ds
15280 +#else
15281 cmpl $__PAGE_OFFSET-3,%ebp
15282 jae syscall_fault
15283 ASM_STAC
15284 1: movl (%ebp),%ebp
15285 ASM_CLAC
15286 +#endif
15287 +
15288 movl %ebp,PT_EBP(%esp)
15289 _ASM_EXTABLE(1b,syscall_fault)
15290
15291 GET_THREAD_INFO(%ebp)
15292
15293 +#ifdef CONFIG_PAX_RANDKSTACK
15294 + pax_erase_kstack
15295 +#endif
15296 +
15297 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15298 jnz sysenter_audit
15299 sysenter_do_call:
15300 @@ -444,12 +616,24 @@ sysenter_do_call:
15301 testl $_TIF_ALLWORK_MASK, %ecx
15302 jne sysexit_audit
15303 sysenter_exit:
15304 +
15305 +#ifdef CONFIG_PAX_RANDKSTACK
15306 + pushl_cfi %eax
15307 + movl %esp, %eax
15308 + call pax_randomize_kstack
15309 + popl_cfi %eax
15310 +#endif
15311 +
15312 + pax_erase_kstack
15313 +
15314 /* if something modifies registers it must also disable sysexit */
15315 movl PT_EIP(%esp), %edx
15316 movl PT_OLDESP(%esp), %ecx
15317 xorl %ebp,%ebp
15318 TRACE_IRQS_ON
15319 1: mov PT_FS(%esp), %fs
15320 +2: mov PT_DS(%esp), %ds
15321 +3: mov PT_ES(%esp), %es
15322 PTGS_TO_GS
15323 ENABLE_INTERRUPTS_SYSEXIT
15324
15325 @@ -466,6 +650,9 @@ sysenter_audit:
15326 movl %eax,%edx /* 2nd arg: syscall number */
15327 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15328 call __audit_syscall_entry
15329 +
15330 + pax_erase_kstack
15331 +
15332 pushl_cfi %ebx
15333 movl PT_EAX(%esp),%eax /* reload syscall number */
15334 jmp sysenter_do_call
15335 @@ -491,10 +678,16 @@ sysexit_audit:
15336
15337 CFI_ENDPROC
15338 .pushsection .fixup,"ax"
15339 -2: movl $0,PT_FS(%esp)
15340 +4: movl $0,PT_FS(%esp)
15341 + jmp 1b
15342 +5: movl $0,PT_DS(%esp)
15343 + jmp 1b
15344 +6: movl $0,PT_ES(%esp)
15345 jmp 1b
15346 .popsection
15347 - _ASM_EXTABLE(1b,2b)
15348 + _ASM_EXTABLE(1b,4b)
15349 + _ASM_EXTABLE(2b,5b)
15350 + _ASM_EXTABLE(3b,6b)
15351 PTGS_TO_GS_EX
15352 ENDPROC(ia32_sysenter_target)
15353
15354 @@ -509,6 +702,11 @@ ENTRY(system_call)
15355 pushl_cfi %eax # save orig_eax
15356 SAVE_ALL
15357 GET_THREAD_INFO(%ebp)
15358 +
15359 +#ifdef CONFIG_PAX_RANDKSTACK
15360 + pax_erase_kstack
15361 +#endif
15362 +
15363 # system call tracing in operation / emulation
15364 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15365 jnz syscall_trace_entry
15366 @@ -527,6 +725,15 @@ syscall_exit:
15367 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15368 jne syscall_exit_work
15369
15370 +restore_all_pax:
15371 +
15372 +#ifdef CONFIG_PAX_RANDKSTACK
15373 + movl %esp, %eax
15374 + call pax_randomize_kstack
15375 +#endif
15376 +
15377 + pax_erase_kstack
15378 +
15379 restore_all:
15380 TRACE_IRQS_IRET
15381 restore_all_notrace:
15382 @@ -583,14 +790,34 @@ ldt_ss:
15383 * compensating for the offset by changing to the ESPFIX segment with
15384 * a base address that matches for the difference.
15385 */
15386 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15387 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15388 mov %esp, %edx /* load kernel esp */
15389 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15390 mov %dx, %ax /* eax: new kernel esp */
15391 sub %eax, %edx /* offset (low word is 0) */
15392 +#ifdef CONFIG_SMP
15393 + movl PER_CPU_VAR(cpu_number), %ebx
15394 + shll $PAGE_SHIFT_asm, %ebx
15395 + addl $cpu_gdt_table, %ebx
15396 +#else
15397 + movl $cpu_gdt_table, %ebx
15398 +#endif
15399 shr $16, %edx
15400 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15401 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15402 +
15403 +#ifdef CONFIG_PAX_KERNEXEC
15404 + mov %cr0, %esi
15405 + btr $16, %esi
15406 + mov %esi, %cr0
15407 +#endif
15408 +
15409 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15410 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15411 +
15412 +#ifdef CONFIG_PAX_KERNEXEC
15413 + bts $16, %esi
15414 + mov %esi, %cr0
15415 +#endif
15416 +
15417 pushl_cfi $__ESPFIX_SS
15418 pushl_cfi %eax /* new kernel esp */
15419 /* Disable interrupts, but do not irqtrace this section: we
15420 @@ -619,20 +846,18 @@ work_resched:
15421 movl TI_flags(%ebp), %ecx
15422 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15423 # than syscall tracing?
15424 - jz restore_all
15425 + jz restore_all_pax
15426 testb $_TIF_NEED_RESCHED, %cl
15427 jnz work_resched
15428
15429 work_notifysig: # deal with pending signals and
15430 # notify-resume requests
15431 + movl %esp, %eax
15432 #ifdef CONFIG_VM86
15433 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15434 - movl %esp, %eax
15435 jne work_notifysig_v86 # returning to kernel-space or
15436 # vm86-space
15437 1:
15438 -#else
15439 - movl %esp, %eax
15440 #endif
15441 TRACE_IRQS_ON
15442 ENABLE_INTERRUPTS(CLBR_NONE)
15443 @@ -653,7 +878,7 @@ work_notifysig_v86:
15444 movl %eax, %esp
15445 jmp 1b
15446 #endif
15447 -END(work_pending)
15448 +ENDPROC(work_pending)
15449
15450 # perform syscall exit tracing
15451 ALIGN
15452 @@ -661,11 +886,14 @@ syscall_trace_entry:
15453 movl $-ENOSYS,PT_EAX(%esp)
15454 movl %esp, %eax
15455 call syscall_trace_enter
15456 +
15457 + pax_erase_kstack
15458 +
15459 /* What it returned is what we'll actually use. */
15460 cmpl $(NR_syscalls), %eax
15461 jnae syscall_call
15462 jmp syscall_exit
15463 -END(syscall_trace_entry)
15464 +ENDPROC(syscall_trace_entry)
15465
15466 # perform syscall exit tracing
15467 ALIGN
15468 @@ -678,21 +906,25 @@ syscall_exit_work:
15469 movl %esp, %eax
15470 call syscall_trace_leave
15471 jmp resume_userspace
15472 -END(syscall_exit_work)
15473 +ENDPROC(syscall_exit_work)
15474 CFI_ENDPROC
15475
15476 RING0_INT_FRAME # can't unwind into user space anyway
15477 syscall_fault:
15478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15479 + push %ss
15480 + pop %ds
15481 +#endif
15482 ASM_CLAC
15483 GET_THREAD_INFO(%ebp)
15484 movl $-EFAULT,PT_EAX(%esp)
15485 jmp resume_userspace
15486 -END(syscall_fault)
15487 +ENDPROC(syscall_fault)
15488
15489 syscall_badsys:
15490 movl $-ENOSYS,PT_EAX(%esp)
15491 jmp resume_userspace
15492 -END(syscall_badsys)
15493 +ENDPROC(syscall_badsys)
15494 CFI_ENDPROC
15495 /*
15496 * End of kprobes section
15497 @@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
15498 CFI_ENDPROC
15499 ENDPROC(ptregs_clone)
15500
15501 + ALIGN;
15502 +ENTRY(kernel_execve)
15503 + CFI_STARTPROC
15504 + pushl_cfi %ebp
15505 + sub $PT_OLDSS+4,%esp
15506 + pushl_cfi %edi
15507 + pushl_cfi %ecx
15508 + pushl_cfi %eax
15509 + lea 3*4(%esp),%edi
15510 + mov $PT_OLDSS/4+1,%ecx
15511 + xorl %eax,%eax
15512 + rep stosl
15513 + popl_cfi %eax
15514 + popl_cfi %ecx
15515 + popl_cfi %edi
15516 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15517 + pushl_cfi %esp
15518 + call sys_execve
15519 + add $4,%esp
15520 + CFI_ADJUST_CFA_OFFSET -4
15521 + GET_THREAD_INFO(%ebp)
15522 + test %eax,%eax
15523 + jz syscall_exit
15524 + add $PT_OLDSS+4,%esp
15525 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15526 + popl_cfi %ebp
15527 + ret
15528 + CFI_ENDPROC
15529 +ENDPROC(kernel_execve)
15530 +
15531 .macro FIXUP_ESPFIX_STACK
15532 /*
15533 * Switch back for ESPFIX stack to the normal zerobased stack
15534 @@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
15535 * normal stack and adjusts ESP with the matching offset.
15536 */
15537 /* fixup the stack */
15538 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15539 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15540 +#ifdef CONFIG_SMP
15541 + movl PER_CPU_VAR(cpu_number), %ebx
15542 + shll $PAGE_SHIFT_asm, %ebx
15543 + addl $cpu_gdt_table, %ebx
15544 +#else
15545 + movl $cpu_gdt_table, %ebx
15546 +#endif
15547 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15548 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15549 shl $16, %eax
15550 addl %esp, %eax /* the adjusted stack pointer */
15551 pushl_cfi $__KERNEL_DS
15552 @@ -826,7 +1095,7 @@ vector=vector+1
15553 .endr
15554 2: jmp common_interrupt
15555 .endr
15556 -END(irq_entries_start)
15557 +ENDPROC(irq_entries_start)
15558
15559 .previous
15560 END(interrupt)
15561 @@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
15562 pushl_cfi $do_coprocessor_error
15563 jmp error_code
15564 CFI_ENDPROC
15565 -END(coprocessor_error)
15566 +ENDPROC(coprocessor_error)
15567
15568 ENTRY(simd_coprocessor_error)
15569 RING0_INT_FRAME
15570 @@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
15571 #endif
15572 jmp error_code
15573 CFI_ENDPROC
15574 -END(simd_coprocessor_error)
15575 +ENDPROC(simd_coprocessor_error)
15576
15577 ENTRY(device_not_available)
15578 RING0_INT_FRAME
15579 @@ -908,18 +1177,18 @@ ENTRY(device_not_available)
15580 pushl_cfi $do_device_not_available
15581 jmp error_code
15582 CFI_ENDPROC
15583 -END(device_not_available)
15584 +ENDPROC(device_not_available)
15585
15586 #ifdef CONFIG_PARAVIRT
15587 ENTRY(native_iret)
15588 iret
15589 _ASM_EXTABLE(native_iret, iret_exc)
15590 -END(native_iret)
15591 +ENDPROC(native_iret)
15592
15593 ENTRY(native_irq_enable_sysexit)
15594 sti
15595 sysexit
15596 -END(native_irq_enable_sysexit)
15597 +ENDPROC(native_irq_enable_sysexit)
15598 #endif
15599
15600 ENTRY(overflow)
15601 @@ -929,7 +1198,7 @@ ENTRY(overflow)
15602 pushl_cfi $do_overflow
15603 jmp error_code
15604 CFI_ENDPROC
15605 -END(overflow)
15606 +ENDPROC(overflow)
15607
15608 ENTRY(bounds)
15609 RING0_INT_FRAME
15610 @@ -938,7 +1207,7 @@ ENTRY(bounds)
15611 pushl_cfi $do_bounds
15612 jmp error_code
15613 CFI_ENDPROC
15614 -END(bounds)
15615 +ENDPROC(bounds)
15616
15617 ENTRY(invalid_op)
15618 RING0_INT_FRAME
15619 @@ -947,7 +1216,7 @@ ENTRY(invalid_op)
15620 pushl_cfi $do_invalid_op
15621 jmp error_code
15622 CFI_ENDPROC
15623 -END(invalid_op)
15624 +ENDPROC(invalid_op)
15625
15626 ENTRY(coprocessor_segment_overrun)
15627 RING0_INT_FRAME
15628 @@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
15629 pushl_cfi $do_coprocessor_segment_overrun
15630 jmp error_code
15631 CFI_ENDPROC
15632 -END(coprocessor_segment_overrun)
15633 +ENDPROC(coprocessor_segment_overrun)
15634
15635 ENTRY(invalid_TSS)
15636 RING0_EC_FRAME
15637 @@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
15638 pushl_cfi $do_invalid_TSS
15639 jmp error_code
15640 CFI_ENDPROC
15641 -END(invalid_TSS)
15642 +ENDPROC(invalid_TSS)
15643
15644 ENTRY(segment_not_present)
15645 RING0_EC_FRAME
15646 @@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
15647 pushl_cfi $do_segment_not_present
15648 jmp error_code
15649 CFI_ENDPROC
15650 -END(segment_not_present)
15651 +ENDPROC(segment_not_present)
15652
15653 ENTRY(stack_segment)
15654 RING0_EC_FRAME
15655 @@ -980,7 +1249,7 @@ ENTRY(stack_segment)
15656 pushl_cfi $do_stack_segment
15657 jmp error_code
15658 CFI_ENDPROC
15659 -END(stack_segment)
15660 +ENDPROC(stack_segment)
15661
15662 ENTRY(alignment_check)
15663 RING0_EC_FRAME
15664 @@ -988,7 +1257,7 @@ ENTRY(alignment_check)
15665 pushl_cfi $do_alignment_check
15666 jmp error_code
15667 CFI_ENDPROC
15668 -END(alignment_check)
15669 +ENDPROC(alignment_check)
15670
15671 ENTRY(divide_error)
15672 RING0_INT_FRAME
15673 @@ -997,7 +1266,7 @@ ENTRY(divide_error)
15674 pushl_cfi $do_divide_error
15675 jmp error_code
15676 CFI_ENDPROC
15677 -END(divide_error)
15678 +ENDPROC(divide_error)
15679
15680 #ifdef CONFIG_X86_MCE
15681 ENTRY(machine_check)
15682 @@ -1007,7 +1276,7 @@ ENTRY(machine_check)
15683 pushl_cfi machine_check_vector
15684 jmp error_code
15685 CFI_ENDPROC
15686 -END(machine_check)
15687 +ENDPROC(machine_check)
15688 #endif
15689
15690 ENTRY(spurious_interrupt_bug)
15691 @@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
15692 pushl_cfi $do_spurious_interrupt_bug
15693 jmp error_code
15694 CFI_ENDPROC
15695 -END(spurious_interrupt_bug)
15696 +ENDPROC(spurious_interrupt_bug)
15697 /*
15698 * End of kprobes section
15699 */
15700 @@ -1121,7 +1390,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15701
15702 ENTRY(mcount)
15703 ret
15704 -END(mcount)
15705 +ENDPROC(mcount)
15706
15707 ENTRY(ftrace_caller)
15708 cmpl $0, function_trace_stop
15709 @@ -1154,7 +1423,7 @@ ftrace_graph_call:
15710 .globl ftrace_stub
15711 ftrace_stub:
15712 ret
15713 -END(ftrace_caller)
15714 +ENDPROC(ftrace_caller)
15715
15716 ENTRY(ftrace_regs_caller)
15717 pushf /* push flags before compare (in cs location) */
15718 @@ -1255,7 +1524,7 @@ trace:
15719 popl %ecx
15720 popl %eax
15721 jmp ftrace_stub
15722 -END(mcount)
15723 +ENDPROC(mcount)
15724 #endif /* CONFIG_DYNAMIC_FTRACE */
15725 #endif /* CONFIG_FUNCTION_TRACER */
15726
15727 @@ -1273,7 +1542,7 @@ ENTRY(ftrace_graph_caller)
15728 popl %ecx
15729 popl %eax
15730 ret
15731 -END(ftrace_graph_caller)
15732 +ENDPROC(ftrace_graph_caller)
15733
15734 .globl return_to_handler
15735 return_to_handler:
15736 @@ -1329,15 +1598,18 @@ error_code:
15737 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15738 REG_TO_PTGS %ecx
15739 SET_KERNEL_GS %ecx
15740 - movl $(__USER_DS), %ecx
15741 + movl $(__KERNEL_DS), %ecx
15742 movl %ecx, %ds
15743 movl %ecx, %es
15744 +
15745 + pax_enter_kernel
15746 +
15747 TRACE_IRQS_OFF
15748 movl %esp,%eax # pt_regs pointer
15749 call *%edi
15750 jmp ret_from_exception
15751 CFI_ENDPROC
15752 -END(page_fault)
15753 +ENDPROC(page_fault)
15754
15755 /*
15756 * Debug traps and NMI can happen at the one SYSENTER instruction
15757 @@ -1380,7 +1652,7 @@ debug_stack_correct:
15758 call do_debug
15759 jmp ret_from_exception
15760 CFI_ENDPROC
15761 -END(debug)
15762 +ENDPROC(debug)
15763
15764 /*
15765 * NMI is doubly nasty. It can happen _while_ we're handling
15766 @@ -1418,6 +1690,9 @@ nmi_stack_correct:
15767 xorl %edx,%edx # zero error code
15768 movl %esp,%eax # pt_regs pointer
15769 call do_nmi
15770 +
15771 + pax_exit_kernel
15772 +
15773 jmp restore_all_notrace
15774 CFI_ENDPROC
15775
15776 @@ -1454,12 +1729,15 @@ nmi_espfix_stack:
15777 FIXUP_ESPFIX_STACK # %eax == %esp
15778 xorl %edx,%edx # zero error code
15779 call do_nmi
15780 +
15781 + pax_exit_kernel
15782 +
15783 RESTORE_REGS
15784 lss 12+4(%esp), %esp # back to espfix stack
15785 CFI_ADJUST_CFA_OFFSET -24
15786 jmp irq_return
15787 CFI_ENDPROC
15788 -END(nmi)
15789 +ENDPROC(nmi)
15790
15791 ENTRY(int3)
15792 RING0_INT_FRAME
15793 @@ -1472,14 +1750,14 @@ ENTRY(int3)
15794 call do_int3
15795 jmp ret_from_exception
15796 CFI_ENDPROC
15797 -END(int3)
15798 +ENDPROC(int3)
15799
15800 ENTRY(general_protection)
15801 RING0_EC_FRAME
15802 pushl_cfi $do_general_protection
15803 jmp error_code
15804 CFI_ENDPROC
15805 -END(general_protection)
15806 +ENDPROC(general_protection)
15807
15808 #ifdef CONFIG_KVM_GUEST
15809 ENTRY(async_page_fault)
15810 @@ -1488,7 +1766,7 @@ ENTRY(async_page_fault)
15811 pushl_cfi $do_async_page_fault
15812 jmp error_code
15813 CFI_ENDPROC
15814 -END(async_page_fault)
15815 +ENDPROC(async_page_fault)
15816 #endif
15817
15818 /*
15819 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15820 index 1328fe4..cb03298 100644
15821 --- a/arch/x86/kernel/entry_64.S
15822 +++ b/arch/x86/kernel/entry_64.S
15823 @@ -59,6 +59,8 @@
15824 #include <asm/rcu.h>
15825 #include <asm/smap.h>
15826 #include <linux/err.h>
15827 +#include <asm/pgtable.h>
15828 +#include <asm/alternative-asm.h>
15829
15830 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15831 #include <linux/elf-em.h>
15832 @@ -80,8 +82,9 @@
15833 #ifdef CONFIG_DYNAMIC_FTRACE
15834
15835 ENTRY(function_hook)
15836 + pax_force_retaddr
15837 retq
15838 -END(function_hook)
15839 +ENDPROC(function_hook)
15840
15841 /* skip is set if stack has been adjusted */
15842 .macro ftrace_caller_setup skip=0
15843 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
15844 #endif
15845
15846 GLOBAL(ftrace_stub)
15847 + pax_force_retaddr
15848 retq
15849 -END(ftrace_caller)
15850 +ENDPROC(ftrace_caller)
15851
15852 ENTRY(ftrace_regs_caller)
15853 /* Save the current flags before compare (in SS location)*/
15854 @@ -191,7 +195,7 @@ ftrace_restore_flags:
15855 popfq
15856 jmp ftrace_stub
15857
15858 -END(ftrace_regs_caller)
15859 +ENDPROC(ftrace_regs_caller)
15860
15861
15862 #else /* ! CONFIG_DYNAMIC_FTRACE */
15863 @@ -212,6 +216,7 @@ ENTRY(function_hook)
15864 #endif
15865
15866 GLOBAL(ftrace_stub)
15867 + pax_force_retaddr
15868 retq
15869
15870 trace:
15871 @@ -225,12 +230,13 @@ trace:
15872 #endif
15873 subq $MCOUNT_INSN_SIZE, %rdi
15874
15875 + pax_force_fptr ftrace_trace_function
15876 call *ftrace_trace_function
15877
15878 MCOUNT_RESTORE_FRAME
15879
15880 jmp ftrace_stub
15881 -END(function_hook)
15882 +ENDPROC(function_hook)
15883 #endif /* CONFIG_DYNAMIC_FTRACE */
15884 #endif /* CONFIG_FUNCTION_TRACER */
15885
15886 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
15887
15888 MCOUNT_RESTORE_FRAME
15889
15890 + pax_force_retaddr
15891 retq
15892 -END(ftrace_graph_caller)
15893 +ENDPROC(ftrace_graph_caller)
15894
15895 GLOBAL(return_to_handler)
15896 subq $24, %rsp
15897 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
15898 movq 8(%rsp), %rdx
15899 movq (%rsp), %rax
15900 addq $24, %rsp
15901 + pax_force_fptr %rdi
15902 jmp *%rdi
15903 +ENDPROC(return_to_handler)
15904 #endif
15905
15906
15907 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
15908 ENDPROC(native_usergs_sysret64)
15909 #endif /* CONFIG_PARAVIRT */
15910
15911 + .macro ljmpq sel, off
15912 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15913 + .byte 0x48; ljmp *1234f(%rip)
15914 + .pushsection .rodata
15915 + .align 16
15916 + 1234: .quad \off; .word \sel
15917 + .popsection
15918 +#else
15919 + pushq $\sel
15920 + pushq $\off
15921 + lretq
15922 +#endif
15923 + .endm
15924 +
15925 + .macro pax_enter_kernel
15926 + pax_set_fptr_mask
15927 +#ifdef CONFIG_PAX_KERNEXEC
15928 + call pax_enter_kernel
15929 +#endif
15930 + .endm
15931 +
15932 + .macro pax_exit_kernel
15933 +#ifdef CONFIG_PAX_KERNEXEC
15934 + call pax_exit_kernel
15935 +#endif
15936 + .endm
15937 +
15938 +#ifdef CONFIG_PAX_KERNEXEC
15939 +ENTRY(pax_enter_kernel)
15940 + pushq %rdi
15941 +
15942 +#ifdef CONFIG_PARAVIRT
15943 + PV_SAVE_REGS(CLBR_RDI)
15944 +#endif
15945 +
15946 + GET_CR0_INTO_RDI
15947 + bts $16,%rdi
15948 + jnc 3f
15949 + mov %cs,%edi
15950 + cmp $__KERNEL_CS,%edi
15951 + jnz 2f
15952 +1:
15953 +
15954 +#ifdef CONFIG_PARAVIRT
15955 + PV_RESTORE_REGS(CLBR_RDI)
15956 +#endif
15957 +
15958 + popq %rdi
15959 + pax_force_retaddr
15960 + retq
15961 +
15962 +2: ljmpq __KERNEL_CS,1f
15963 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15964 +4: SET_RDI_INTO_CR0
15965 + jmp 1b
15966 +ENDPROC(pax_enter_kernel)
15967 +
15968 +ENTRY(pax_exit_kernel)
15969 + pushq %rdi
15970 +
15971 +#ifdef CONFIG_PARAVIRT
15972 + PV_SAVE_REGS(CLBR_RDI)
15973 +#endif
15974 +
15975 + mov %cs,%rdi
15976 + cmp $__KERNEXEC_KERNEL_CS,%edi
15977 + jz 2f
15978 +1:
15979 +
15980 +#ifdef CONFIG_PARAVIRT
15981 + PV_RESTORE_REGS(CLBR_RDI);
15982 +#endif
15983 +
15984 + popq %rdi
15985 + pax_force_retaddr
15986 + retq
15987 +
15988 +2: GET_CR0_INTO_RDI
15989 + btr $16,%rdi
15990 + ljmpq __KERNEL_CS,3f
15991 +3: SET_RDI_INTO_CR0
15992 + jmp 1b
15993 +ENDPROC(pax_exit_kernel)
15994 +#endif
15995 +
15996 + .macro pax_enter_kernel_user
15997 + pax_set_fptr_mask
15998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15999 + call pax_enter_kernel_user
16000 +#endif
16001 + .endm
16002 +
16003 + .macro pax_exit_kernel_user
16004 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16005 + call pax_exit_kernel_user
16006 +#endif
16007 +#ifdef CONFIG_PAX_RANDKSTACK
16008 + pushq %rax
16009 + call pax_randomize_kstack
16010 + popq %rax
16011 +#endif
16012 + .endm
16013 +
16014 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16015 +ENTRY(pax_enter_kernel_user)
16016 + pushq %rdi
16017 + pushq %rbx
16018 +
16019 +#ifdef CONFIG_PARAVIRT
16020 + PV_SAVE_REGS(CLBR_RDI)
16021 +#endif
16022 +
16023 + GET_CR3_INTO_RDI
16024 + mov %rdi,%rbx
16025 + add $__START_KERNEL_map,%rbx
16026 + sub phys_base(%rip),%rbx
16027 +
16028 +#ifdef CONFIG_PARAVIRT
16029 + pushq %rdi
16030 + cmpl $0, pv_info+PARAVIRT_enabled
16031 + jz 1f
16032 + i = 0
16033 + .rept USER_PGD_PTRS
16034 + mov i*8(%rbx),%rsi
16035 + mov $0,%sil
16036 + lea i*8(%rbx),%rdi
16037 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16038 + i = i + 1
16039 + .endr
16040 + jmp 2f
16041 +1:
16042 +#endif
16043 +
16044 + i = 0
16045 + .rept USER_PGD_PTRS
16046 + movb $0,i*8(%rbx)
16047 + i = i + 1
16048 + .endr
16049 +
16050 +#ifdef CONFIG_PARAVIRT
16051 +2: popq %rdi
16052 +#endif
16053 + SET_RDI_INTO_CR3
16054 +
16055 +#ifdef CONFIG_PAX_KERNEXEC
16056 + GET_CR0_INTO_RDI
16057 + bts $16,%rdi
16058 + SET_RDI_INTO_CR0
16059 +#endif
16060 +
16061 +#ifdef CONFIG_PARAVIRT
16062 + PV_RESTORE_REGS(CLBR_RDI)
16063 +#endif
16064 +
16065 + popq %rbx
16066 + popq %rdi
16067 + pax_force_retaddr
16068 + retq
16069 +ENDPROC(pax_enter_kernel_user)
16070 +
16071 +ENTRY(pax_exit_kernel_user)
16072 + push %rdi
16073 +
16074 +#ifdef CONFIG_PARAVIRT
16075 + pushq %rbx
16076 + PV_SAVE_REGS(CLBR_RDI)
16077 +#endif
16078 +
16079 +#ifdef CONFIG_PAX_KERNEXEC
16080 + GET_CR0_INTO_RDI
16081 + btr $16,%rdi
16082 + SET_RDI_INTO_CR0
16083 +#endif
16084 +
16085 + GET_CR3_INTO_RDI
16086 + add $__START_KERNEL_map,%rdi
16087 + sub phys_base(%rip),%rdi
16088 +
16089 +#ifdef CONFIG_PARAVIRT
16090 + cmpl $0, pv_info+PARAVIRT_enabled
16091 + jz 1f
16092 + mov %rdi,%rbx
16093 + i = 0
16094 + .rept USER_PGD_PTRS
16095 + mov i*8(%rbx),%rsi
16096 + mov $0x67,%sil
16097 + lea i*8(%rbx),%rdi
16098 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16099 + i = i + 1
16100 + .endr
16101 + jmp 2f
16102 +1:
16103 +#endif
16104 +
16105 + i = 0
16106 + .rept USER_PGD_PTRS
16107 + movb $0x67,i*8(%rdi)
16108 + i = i + 1
16109 + .endr
16110 +
16111 +#ifdef CONFIG_PARAVIRT
16112 +2: PV_RESTORE_REGS(CLBR_RDI)
16113 + popq %rbx
16114 +#endif
16115 +
16116 + popq %rdi
16117 + pax_force_retaddr
16118 + retq
16119 +ENDPROC(pax_exit_kernel_user)
16120 +#endif
16121 +
16122 +.macro pax_erase_kstack
16123 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16124 + call pax_erase_kstack
16125 +#endif
16126 +.endm
16127 +
16128 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16129 +ENTRY(pax_erase_kstack)
16130 + pushq %rdi
16131 + pushq %rcx
16132 + pushq %rax
16133 + pushq %r11
16134 +
16135 + GET_THREAD_INFO(%r11)
16136 + mov TI_lowest_stack(%r11), %rdi
16137 + mov $-0xBEEF, %rax
16138 + std
16139 +
16140 +1: mov %edi, %ecx
16141 + and $THREAD_SIZE_asm - 1, %ecx
16142 + shr $3, %ecx
16143 + repne scasq
16144 + jecxz 2f
16145 +
16146 + cmp $2*8, %ecx
16147 + jc 2f
16148 +
16149 + mov $2*8, %ecx
16150 + repe scasq
16151 + jecxz 2f
16152 + jne 1b
16153 +
16154 +2: cld
16155 + mov %esp, %ecx
16156 + sub %edi, %ecx
16157 +
16158 + cmp $THREAD_SIZE_asm, %rcx
16159 + jb 3f
16160 + ud2
16161 +3:
16162 +
16163 + shr $3, %ecx
16164 + rep stosq
16165 +
16166 + mov TI_task_thread_sp0(%r11), %rdi
16167 + sub $256, %rdi
16168 + mov %rdi, TI_lowest_stack(%r11)
16169 +
16170 + popq %r11
16171 + popq %rax
16172 + popq %rcx
16173 + popq %rdi
16174 + pax_force_retaddr
16175 + ret
16176 +ENDPROC(pax_erase_kstack)
16177 +#endif
16178
16179 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16180 #ifdef CONFIG_TRACE_IRQFLAGS
16181 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
16182 .endm
16183
16184 .macro UNFAKE_STACK_FRAME
16185 - addq $8*6, %rsp
16186 - CFI_ADJUST_CFA_OFFSET -(6*8)
16187 + addq $8*6 + ARG_SKIP, %rsp
16188 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16189 .endm
16190
16191 /*
16192 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
16193 movq %rsp, %rsi
16194
16195 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16196 - testl $3, CS-RBP(%rsi)
16197 + testb $3, CS-RBP(%rsi)
16198 je 1f
16199 SWAPGS
16200 /*
16201 @@ -498,9 +774,10 @@ ENTRY(save_rest)
16202 movq_cfi r15, R15+16
16203 movq %r11, 8(%rsp) /* return address */
16204 FIXUP_TOP_OF_STACK %r11, 16
16205 + pax_force_retaddr
16206 ret
16207 CFI_ENDPROC
16208 -END(save_rest)
16209 +ENDPROC(save_rest)
16210
16211 /* save complete stack frame */
16212 .pushsection .kprobes.text, "ax"
16213 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
16214 js 1f /* negative -> in kernel */
16215 SWAPGS
16216 xorl %ebx,%ebx
16217 -1: ret
16218 +1: pax_force_retaddr_bts
16219 + ret
16220 CFI_ENDPROC
16221 -END(save_paranoid)
16222 +ENDPROC(save_paranoid)
16223 .popsection
16224
16225 /*
16226 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
16227
16228 RESTORE_REST
16229
16230 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16231 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16232 jz 1f
16233
16234 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16235 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
16236 RESTORE_REST
16237 jmp int_ret_from_sys_call
16238 CFI_ENDPROC
16239 -END(ret_from_fork)
16240 +ENDPROC(ret_from_fork)
16241
16242 /*
16243 * System call entry. Up to 6 arguments in registers are supported.
16244 @@ -608,7 +886,7 @@ END(ret_from_fork)
16245 ENTRY(system_call)
16246 CFI_STARTPROC simple
16247 CFI_SIGNAL_FRAME
16248 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16249 + CFI_DEF_CFA rsp,0
16250 CFI_REGISTER rip,rcx
16251 /*CFI_REGISTER rflags,r11*/
16252 SWAPGS_UNSAFE_STACK
16253 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
16254
16255 movq %rsp,PER_CPU_VAR(old_rsp)
16256 movq PER_CPU_VAR(kernel_stack),%rsp
16257 + SAVE_ARGS 8*6,0
16258 + pax_enter_kernel_user
16259 +
16260 +#ifdef CONFIG_PAX_RANDKSTACK
16261 + pax_erase_kstack
16262 +#endif
16263 +
16264 /*
16265 * No need to follow this irqs off/on section - it's straight
16266 * and short:
16267 */
16268 ENABLE_INTERRUPTS(CLBR_NONE)
16269 - SAVE_ARGS 8,0
16270 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16271 movq %rcx,RIP-ARGOFFSET(%rsp)
16272 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16273 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16274 + GET_THREAD_INFO(%rcx)
16275 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16276 jnz tracesys
16277 system_call_fastpath:
16278 #if __SYSCALL_MASK == ~0
16279 @@ -640,7 +925,7 @@ system_call_fastpath:
16280 cmpl $__NR_syscall_max,%eax
16281 #endif
16282 ja badsys
16283 - movq %r10,%rcx
16284 + movq R10-ARGOFFSET(%rsp),%rcx
16285 call *sys_call_table(,%rax,8) # XXX: rip relative
16286 movq %rax,RAX-ARGOFFSET(%rsp)
16287 /*
16288 @@ -654,10 +939,13 @@ sysret_check:
16289 LOCKDEP_SYS_EXIT
16290 DISABLE_INTERRUPTS(CLBR_NONE)
16291 TRACE_IRQS_OFF
16292 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16293 + GET_THREAD_INFO(%rcx)
16294 + movl TI_flags(%rcx),%edx
16295 andl %edi,%edx
16296 jnz sysret_careful
16297 CFI_REMEMBER_STATE
16298 + pax_exit_kernel_user
16299 + pax_erase_kstack
16300 /*
16301 * sysretq will re-enable interrupts:
16302 */
16303 @@ -709,14 +997,18 @@ badsys:
16304 * jump back to the normal fast path.
16305 */
16306 auditsys:
16307 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16308 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16309 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16310 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16311 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16312 movq %rax,%rsi /* 2nd arg: syscall number */
16313 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16314 call __audit_syscall_entry
16315 +
16316 + pax_erase_kstack
16317 +
16318 LOAD_ARGS 0 /* reload call-clobbered registers */
16319 + pax_set_fptr_mask
16320 jmp system_call_fastpath
16321
16322 /*
16323 @@ -737,7 +1029,7 @@ sysret_audit:
16324 /* Do syscall tracing */
16325 tracesys:
16326 #ifdef CONFIG_AUDITSYSCALL
16327 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16328 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16329 jz auditsys
16330 #endif
16331 SAVE_REST
16332 @@ -745,12 +1037,16 @@ tracesys:
16333 FIXUP_TOP_OF_STACK %rdi
16334 movq %rsp,%rdi
16335 call syscall_trace_enter
16336 +
16337 + pax_erase_kstack
16338 +
16339 /*
16340 * Reload arg registers from stack in case ptrace changed them.
16341 * We don't reload %rax because syscall_trace_enter() returned
16342 * the value it wants us to use in the table lookup.
16343 */
16344 LOAD_ARGS ARGOFFSET, 1
16345 + pax_set_fptr_mask
16346 RESTORE_REST
16347 #if __SYSCALL_MASK == ~0
16348 cmpq $__NR_syscall_max,%rax
16349 @@ -759,7 +1055,7 @@ tracesys:
16350 cmpl $__NR_syscall_max,%eax
16351 #endif
16352 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16353 - movq %r10,%rcx /* fixup for C */
16354 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16355 call *sys_call_table(,%rax,8)
16356 movq %rax,RAX-ARGOFFSET(%rsp)
16357 /* Use IRET because user could have changed frame */
16358 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
16359 andl %edi,%edx
16360 jnz int_careful
16361 andl $~TS_COMPAT,TI_status(%rcx)
16362 - jmp retint_swapgs
16363 + pax_exit_kernel_user
16364 + pax_erase_kstack
16365 + jmp retint_swapgs_pax
16366
16367 /* Either reschedule or signal or syscall exit tracking needed. */
16368 /* First do a reschedule test. */
16369 @@ -826,7 +1124,7 @@ int_restore_rest:
16370 TRACE_IRQS_OFF
16371 jmp int_with_check
16372 CFI_ENDPROC
16373 -END(system_call)
16374 +ENDPROC(system_call)
16375
16376 /*
16377 * Certain special system calls that need to save a complete full stack frame.
16378 @@ -842,7 +1140,7 @@ ENTRY(\label)
16379 call \func
16380 jmp ptregscall_common
16381 CFI_ENDPROC
16382 -END(\label)
16383 +ENDPROC(\label)
16384 .endm
16385
16386 PTREGSCALL stub_clone, sys_clone, %r8
16387 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
16388 movq_cfi_restore R12+8, r12
16389 movq_cfi_restore RBP+8, rbp
16390 movq_cfi_restore RBX+8, rbx
16391 + pax_force_retaddr
16392 ret $REST_SKIP /* pop extended registers */
16393 CFI_ENDPROC
16394 -END(ptregscall_common)
16395 +ENDPROC(ptregscall_common)
16396
16397 ENTRY(stub_execve)
16398 CFI_STARTPROC
16399 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
16400 RESTORE_REST
16401 jmp int_ret_from_sys_call
16402 CFI_ENDPROC
16403 -END(stub_execve)
16404 +ENDPROC(stub_execve)
16405
16406 /*
16407 * sigreturn is special because it needs to restore all registers on return.
16408 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
16409 RESTORE_REST
16410 jmp int_ret_from_sys_call
16411 CFI_ENDPROC
16412 -END(stub_rt_sigreturn)
16413 +ENDPROC(stub_rt_sigreturn)
16414
16415 #ifdef CONFIG_X86_X32_ABI
16416 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16417 @@ -962,7 +1261,7 @@ vector=vector+1
16418 2: jmp common_interrupt
16419 .endr
16420 CFI_ENDPROC
16421 -END(irq_entries_start)
16422 +ENDPROC(irq_entries_start)
16423
16424 .previous
16425 END(interrupt)
16426 @@ -982,6 +1281,16 @@ END(interrupt)
16427 subq $ORIG_RAX-RBP, %rsp
16428 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16429 SAVE_ARGS_IRQ
16430 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16431 + testb $3, CS(%rdi)
16432 + jnz 1f
16433 + pax_enter_kernel
16434 + jmp 2f
16435 +1: pax_enter_kernel_user
16436 +2:
16437 +#else
16438 + pax_enter_kernel
16439 +#endif
16440 call \func
16441 .endm
16442
16443 @@ -1014,7 +1323,7 @@ ret_from_intr:
16444
16445 exit_intr:
16446 GET_THREAD_INFO(%rcx)
16447 - testl $3,CS-ARGOFFSET(%rsp)
16448 + testb $3,CS-ARGOFFSET(%rsp)
16449 je retint_kernel
16450
16451 /* Interrupt came from user space */
16452 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
16453 * The iretq could re-enable interrupts:
16454 */
16455 DISABLE_INTERRUPTS(CLBR_ANY)
16456 + pax_exit_kernel_user
16457 +retint_swapgs_pax:
16458 TRACE_IRQS_IRETQ
16459 SWAPGS
16460 jmp restore_args
16461
16462 retint_restore_args: /* return to kernel space */
16463 DISABLE_INTERRUPTS(CLBR_ANY)
16464 + pax_exit_kernel
16465 + pax_force_retaddr (RIP-ARGOFFSET)
16466 /*
16467 * The iretq could re-enable interrupts:
16468 */
16469 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
16470 #endif
16471
16472 CFI_ENDPROC
16473 -END(common_interrupt)
16474 +ENDPROC(common_interrupt)
16475 /*
16476 * End of kprobes section
16477 */
16478 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
16479 interrupt \do_sym
16480 jmp ret_from_intr
16481 CFI_ENDPROC
16482 -END(\sym)
16483 +ENDPROC(\sym)
16484 .endm
16485
16486 #ifdef CONFIG_SMP
16487 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
16488 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16489 call error_entry
16490 DEFAULT_FRAME 0
16491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16492 + testb $3, CS(%rsp)
16493 + jnz 1f
16494 + pax_enter_kernel
16495 + jmp 2f
16496 +1: pax_enter_kernel_user
16497 +2:
16498 +#else
16499 + pax_enter_kernel
16500 +#endif
16501 movq %rsp,%rdi /* pt_regs pointer */
16502 xorl %esi,%esi /* no error code */
16503 call \do_sym
16504 jmp error_exit /* %ebx: no swapgs flag */
16505 CFI_ENDPROC
16506 -END(\sym)
16507 +ENDPROC(\sym)
16508 .endm
16509
16510 .macro paranoidzeroentry sym do_sym
16511 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
16512 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16513 call save_paranoid
16514 TRACE_IRQS_OFF
16515 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16516 + testb $3, CS(%rsp)
16517 + jnz 1f
16518 + pax_enter_kernel
16519 + jmp 2f
16520 +1: pax_enter_kernel_user
16521 +2:
16522 +#else
16523 + pax_enter_kernel
16524 +#endif
16525 movq %rsp,%rdi /* pt_regs pointer */
16526 xorl %esi,%esi /* no error code */
16527 call \do_sym
16528 jmp paranoid_exit /* %ebx: no swapgs flag */
16529 CFI_ENDPROC
16530 -END(\sym)
16531 +ENDPROC(\sym)
16532 .endm
16533
16534 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16535 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16536 .macro paranoidzeroentry_ist sym do_sym ist
16537 ENTRY(\sym)
16538 INTR_FRAME
16539 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
16540 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16541 call save_paranoid
16542 TRACE_IRQS_OFF_DEBUG
16543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16544 + testb $3, CS(%rsp)
16545 + jnz 1f
16546 + pax_enter_kernel
16547 + jmp 2f
16548 +1: pax_enter_kernel_user
16549 +2:
16550 +#else
16551 + pax_enter_kernel
16552 +#endif
16553 movq %rsp,%rdi /* pt_regs pointer */
16554 xorl %esi,%esi /* no error code */
16555 +#ifdef CONFIG_SMP
16556 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16557 + lea init_tss(%r12), %r12
16558 +#else
16559 + lea init_tss(%rip), %r12
16560 +#endif
16561 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16562 call \do_sym
16563 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16564 jmp paranoid_exit /* %ebx: no swapgs flag */
16565 CFI_ENDPROC
16566 -END(\sym)
16567 +ENDPROC(\sym)
16568 .endm
16569
16570 .macro errorentry sym do_sym
16571 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
16572 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16573 call error_entry
16574 DEFAULT_FRAME 0
16575 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16576 + testb $3, CS(%rsp)
16577 + jnz 1f
16578 + pax_enter_kernel
16579 + jmp 2f
16580 +1: pax_enter_kernel_user
16581 +2:
16582 +#else
16583 + pax_enter_kernel
16584 +#endif
16585 movq %rsp,%rdi /* pt_regs pointer */
16586 movq ORIG_RAX(%rsp),%rsi /* get error code */
16587 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16588 call \do_sym
16589 jmp error_exit /* %ebx: no swapgs flag */
16590 CFI_ENDPROC
16591 -END(\sym)
16592 +ENDPROC(\sym)
16593 .endm
16594
16595 /* error code is on the stack already */
16596 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
16597 call save_paranoid
16598 DEFAULT_FRAME 0
16599 TRACE_IRQS_OFF
16600 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16601 + testb $3, CS(%rsp)
16602 + jnz 1f
16603 + pax_enter_kernel
16604 + jmp 2f
16605 +1: pax_enter_kernel_user
16606 +2:
16607 +#else
16608 + pax_enter_kernel
16609 +#endif
16610 movq %rsp,%rdi /* pt_regs pointer */
16611 movq ORIG_RAX(%rsp),%rsi /* get error code */
16612 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16613 call \do_sym
16614 jmp paranoid_exit /* %ebx: no swapgs flag */
16615 CFI_ENDPROC
16616 -END(\sym)
16617 +ENDPROC(\sym)
16618 .endm
16619
16620 zeroentry divide_error do_divide_error
16621 @@ -1310,9 +1679,10 @@ gs_change:
16622 2: mfence /* workaround */
16623 SWAPGS
16624 popfq_cfi
16625 + pax_force_retaddr
16626 ret
16627 CFI_ENDPROC
16628 -END(native_load_gs_index)
16629 +ENDPROC(native_load_gs_index)
16630
16631 _ASM_EXTABLE(gs_change,bad_gs)
16632 .section .fixup,"ax"
16633 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
16634 CFI_DEF_CFA_REGISTER rsp
16635 CFI_ADJUST_CFA_OFFSET -8
16636 decl PER_CPU_VAR(irq_count)
16637 + pax_force_retaddr
16638 ret
16639 CFI_ENDPROC
16640 -END(call_softirq)
16641 +ENDPROC(call_softirq)
16642
16643 #ifdef CONFIG_XEN
16644 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16645 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16646 decl PER_CPU_VAR(irq_count)
16647 jmp error_exit
16648 CFI_ENDPROC
16649 -END(xen_do_hypervisor_callback)
16650 +ENDPROC(xen_do_hypervisor_callback)
16651
16652 /*
16653 * Hypervisor uses this for application faults while it executes.
16654 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
16655 SAVE_ALL
16656 jmp error_exit
16657 CFI_ENDPROC
16658 -END(xen_failsafe_callback)
16659 +ENDPROC(xen_failsafe_callback)
16660
16661 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16662 xen_hvm_callback_vector xen_evtchn_do_upcall
16663 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
16664 TRACE_IRQS_OFF_DEBUG
16665 testl %ebx,%ebx /* swapgs needed? */
16666 jnz paranoid_restore
16667 - testl $3,CS(%rsp)
16668 + testb $3,CS(%rsp)
16669 jnz paranoid_userspace
16670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16671 + pax_exit_kernel
16672 + TRACE_IRQS_IRETQ 0
16673 + SWAPGS_UNSAFE_STACK
16674 + RESTORE_ALL 8
16675 + pax_force_retaddr_bts
16676 + jmp irq_return
16677 +#endif
16678 paranoid_swapgs:
16679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16680 + pax_exit_kernel_user
16681 +#else
16682 + pax_exit_kernel
16683 +#endif
16684 TRACE_IRQS_IRETQ 0
16685 SWAPGS_UNSAFE_STACK
16686 RESTORE_ALL 8
16687 jmp irq_return
16688 paranoid_restore:
16689 + pax_exit_kernel
16690 TRACE_IRQS_IRETQ_DEBUG 0
16691 RESTORE_ALL 8
16692 + pax_force_retaddr_bts
16693 jmp irq_return
16694 paranoid_userspace:
16695 GET_THREAD_INFO(%rcx)
16696 @@ -1526,7 +1912,7 @@ paranoid_schedule:
16697 TRACE_IRQS_OFF
16698 jmp paranoid_userspace
16699 CFI_ENDPROC
16700 -END(paranoid_exit)
16701 +ENDPROC(paranoid_exit)
16702
16703 /*
16704 * Exception entry point. This expects an error code/orig_rax on the stack.
16705 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
16706 movq_cfi r14, R14+8
16707 movq_cfi r15, R15+8
16708 xorl %ebx,%ebx
16709 - testl $3,CS+8(%rsp)
16710 + testb $3,CS+8(%rsp)
16711 je error_kernelspace
16712 error_swapgs:
16713 SWAPGS
16714 error_sti:
16715 TRACE_IRQS_OFF
16716 + pax_force_retaddr_bts
16717 ret
16718
16719 /*
16720 @@ -1585,7 +1972,7 @@ bstep_iret:
16721 movq %rcx,RIP+8(%rsp)
16722 jmp error_swapgs
16723 CFI_ENDPROC
16724 -END(error_entry)
16725 +ENDPROC(error_entry)
16726
16727
16728 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16729 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
16730 jnz retint_careful
16731 jmp retint_swapgs
16732 CFI_ENDPROC
16733 -END(error_exit)
16734 +ENDPROC(error_exit)
16735
16736 /*
16737 * Test if a given stack is an NMI stack or not.
16738 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
16739 * If %cs was not the kernel segment, then the NMI triggered in user
16740 * space, which means it is definitely not nested.
16741 */
16742 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16743 + je 1f
16744 cmpl $__KERNEL_CS, 16(%rsp)
16745 jne first_nmi
16746 -
16747 +1:
16748 /*
16749 * Check the special variable on the stack to see if NMIs are
16750 * executing.
16751 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
16752 */
16753 movq %cr2, %r12
16754
16755 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16756 + testb $3, CS(%rsp)
16757 + jnz 1f
16758 + pax_enter_kernel
16759 + jmp 2f
16760 +1: pax_enter_kernel_user
16761 +2:
16762 +#else
16763 + pax_enter_kernel
16764 +#endif
16765 +
16766 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16767 movq %rsp,%rdi
16768 movq $-1,%rsi
16769 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
16770 testl %ebx,%ebx /* swapgs needed? */
16771 jnz nmi_restore
16772 nmi_swapgs:
16773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16774 + pax_exit_kernel_user
16775 +#else
16776 + pax_exit_kernel
16777 +#endif
16778 SWAPGS_UNSAFE_STACK
16779 + RESTORE_ALL 8
16780 + /* Clear the NMI executing stack variable */
16781 + movq $0, 10*8(%rsp)
16782 + jmp irq_return
16783 nmi_restore:
16784 + pax_exit_kernel
16785 RESTORE_ALL 8
16786 + pax_force_retaddr_bts
16787 /* Clear the NMI executing stack variable */
16788 movq $0, 10*8(%rsp)
16789 jmp irq_return
16790 CFI_ENDPROC
16791 -END(nmi)
16792 +ENDPROC(nmi)
16793
16794 ENTRY(ignore_sysret)
16795 CFI_STARTPROC
16796 mov $-ENOSYS,%eax
16797 sysret
16798 CFI_ENDPROC
16799 -END(ignore_sysret)
16800 +ENDPROC(ignore_sysret)
16801
16802 /*
16803 * End of kprobes section
16804 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16805 index 1d41402..af9a46a 100644
16806 --- a/arch/x86/kernel/ftrace.c
16807 +++ b/arch/x86/kernel/ftrace.c
16808 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16809 {
16810 unsigned char replaced[MCOUNT_INSN_SIZE];
16811
16812 + ip = ktla_ktva(ip);
16813 +
16814 /*
16815 * Note: Due to modules and __init, code can
16816 * disappear and change, we need to protect against faulting
16817 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16818 unsigned char old[MCOUNT_INSN_SIZE], *new;
16819 int ret;
16820
16821 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16822 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16823 new = ftrace_call_replace(ip, (unsigned long)func);
16824
16825 /* See comment above by declaration of modifying_ftrace_code */
16826 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16827 /* Also update the regs callback function */
16828 if (!ret) {
16829 ip = (unsigned long)(&ftrace_regs_call);
16830 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
16831 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
16832 new = ftrace_call_replace(ip, (unsigned long)func);
16833 ret = ftrace_modify_code(ip, old, new);
16834 }
16835 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
16836 * kernel identity mapping to modify code.
16837 */
16838 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
16839 - ip = (unsigned long)__va(__pa(ip));
16840 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
16841
16842 return probe_kernel_write((void *)ip, val, size);
16843 }
16844 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
16845 unsigned char replaced[MCOUNT_INSN_SIZE];
16846 unsigned char brk = BREAKPOINT_INSTRUCTION;
16847
16848 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
16849 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
16850 return -EFAULT;
16851
16852 /* Make sure it is what we expect it to be */
16853 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16854 return ret;
16855
16856 fail_update:
16857 - probe_kernel_write((void *)ip, &old_code[0], 1);
16858 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
16859 goto out;
16860 }
16861
16862 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16863 {
16864 unsigned char code[MCOUNT_INSN_SIZE];
16865
16866 + ip = ktla_ktva(ip);
16867 +
16868 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16869 return -EFAULT;
16870
16871 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16872 index c18f59d..9c0c9f6 100644
16873 --- a/arch/x86/kernel/head32.c
16874 +++ b/arch/x86/kernel/head32.c
16875 @@ -18,6 +18,7 @@
16876 #include <asm/io_apic.h>
16877 #include <asm/bios_ebda.h>
16878 #include <asm/tlbflush.h>
16879 +#include <asm/boot.h>
16880
16881 static void __init i386_default_early_setup(void)
16882 {
16883 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16884
16885 void __init i386_start_kernel(void)
16886 {
16887 - memblock_reserve(__pa_symbol(&_text),
16888 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16889 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16890
16891 #ifdef CONFIG_BLK_DEV_INITRD
16892 /* Reserve INITRD */
16893 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16894 index 4dac2f6..bc6a335 100644
16895 --- a/arch/x86/kernel/head_32.S
16896 +++ b/arch/x86/kernel/head_32.S
16897 @@ -26,6 +26,12 @@
16898 /* Physical address */
16899 #define pa(X) ((X) - __PAGE_OFFSET)
16900
16901 +#ifdef CONFIG_PAX_KERNEXEC
16902 +#define ta(X) (X)
16903 +#else
16904 +#define ta(X) ((X) - __PAGE_OFFSET)
16905 +#endif
16906 +
16907 /*
16908 * References to members of the new_cpu_data structure.
16909 */
16910 @@ -55,11 +61,7 @@
16911 * and small than max_low_pfn, otherwise will waste some page table entries
16912 */
16913
16914 -#if PTRS_PER_PMD > 1
16915 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16916 -#else
16917 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16918 -#endif
16919 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16920
16921 /* Number of possible pages in the lowmem region */
16922 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16923 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16924 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16925
16926 /*
16927 + * Real beginning of normal "text" segment
16928 + */
16929 +ENTRY(stext)
16930 +ENTRY(_stext)
16931 +
16932 +/*
16933 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16934 * %esi points to the real-mode code as a 32-bit pointer.
16935 * CS and DS must be 4 GB flat segments, but we don't depend on
16936 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16937 * can.
16938 */
16939 __HEAD
16940 +
16941 +#ifdef CONFIG_PAX_KERNEXEC
16942 + jmp startup_32
16943 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16944 +.fill PAGE_SIZE-5,1,0xcc
16945 +#endif
16946 +
16947 ENTRY(startup_32)
16948 movl pa(stack_start),%ecx
16949
16950 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16951 2:
16952 leal -__PAGE_OFFSET(%ecx),%esp
16953
16954 +#ifdef CONFIG_SMP
16955 + movl $pa(cpu_gdt_table),%edi
16956 + movl $__per_cpu_load,%eax
16957 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16958 + rorl $16,%eax
16959 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16960 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16961 + movl $__per_cpu_end - 1,%eax
16962 + subl $__per_cpu_start,%eax
16963 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16964 +#endif
16965 +
16966 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16967 + movl $NR_CPUS,%ecx
16968 + movl $pa(cpu_gdt_table),%edi
16969 +1:
16970 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16971 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16972 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16973 + addl $PAGE_SIZE_asm,%edi
16974 + loop 1b
16975 +#endif
16976 +
16977 +#ifdef CONFIG_PAX_KERNEXEC
16978 + movl $pa(boot_gdt),%edi
16979 + movl $__LOAD_PHYSICAL_ADDR,%eax
16980 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16981 + rorl $16,%eax
16982 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16983 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16984 + rorl $16,%eax
16985 +
16986 + ljmp $(__BOOT_CS),$1f
16987 +1:
16988 +
16989 + movl $NR_CPUS,%ecx
16990 + movl $pa(cpu_gdt_table),%edi
16991 + addl $__PAGE_OFFSET,%eax
16992 +1:
16993 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16994 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16995 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16996 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16997 + rorl $16,%eax
16998 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16999 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
17000 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
17001 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
17002 + rorl $16,%eax
17003 + addl $PAGE_SIZE_asm,%edi
17004 + loop 1b
17005 +#endif
17006 +
17007 /*
17008 * Clear BSS first so that there are no surprises...
17009 */
17010 @@ -196,8 +264,11 @@ ENTRY(startup_32)
17011 movl %eax, pa(max_pfn_mapped)
17012
17013 /* Do early initialization of the fixmap area */
17014 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17015 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17016 +#ifdef CONFIG_COMPAT_VDSO
17017 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17018 +#else
17019 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17020 +#endif
17021 #else /* Not PAE */
17022
17023 page_pde_offset = (__PAGE_OFFSET >> 20);
17024 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17025 movl %eax, pa(max_pfn_mapped)
17026
17027 /* Do early initialization of the fixmap area */
17028 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17029 - movl %eax,pa(initial_page_table+0xffc)
17030 +#ifdef CONFIG_COMPAT_VDSO
17031 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17032 +#else
17033 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17034 +#endif
17035 #endif
17036
17037 #ifdef CONFIG_PARAVIRT
17038 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17039 cmpl $num_subarch_entries, %eax
17040 jae bad_subarch
17041
17042 - movl pa(subarch_entries)(,%eax,4), %eax
17043 - subl $__PAGE_OFFSET, %eax
17044 - jmp *%eax
17045 + jmp *pa(subarch_entries)(,%eax,4)
17046
17047 bad_subarch:
17048 WEAK(lguest_entry)
17049 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17050 __INITDATA
17051
17052 subarch_entries:
17053 - .long default_entry /* normal x86/PC */
17054 - .long lguest_entry /* lguest hypervisor */
17055 - .long xen_entry /* Xen hypervisor */
17056 - .long default_entry /* Moorestown MID */
17057 + .long ta(default_entry) /* normal x86/PC */
17058 + .long ta(lguest_entry) /* lguest hypervisor */
17059 + .long ta(xen_entry) /* Xen hypervisor */
17060 + .long ta(default_entry) /* Moorestown MID */
17061 num_subarch_entries = (. - subarch_entries) / 4
17062 .previous
17063 #else
17064 @@ -316,6 +388,7 @@ default_entry:
17065 movl pa(mmu_cr4_features),%eax
17066 movl %eax,%cr4
17067
17068 +#ifdef CONFIG_X86_PAE
17069 testb $X86_CR4_PAE, %al # check if PAE is enabled
17070 jz 6f
17071
17072 @@ -344,6 +417,9 @@ default_entry:
17073 /* Make changes effective */
17074 wrmsr
17075
17076 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17077 +#endif
17078 +
17079 6:
17080
17081 /*
17082 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
17083 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17084 movl %eax,%ss # after changing gdt.
17085
17086 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17087 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17088 movl %eax,%ds
17089 movl %eax,%es
17090
17091 movl $(__KERNEL_PERCPU), %eax
17092 movl %eax,%fs # set this cpu's percpu
17093
17094 +#ifdef CONFIG_CC_STACKPROTECTOR
17095 movl $(__KERNEL_STACK_CANARY),%eax
17096 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17097 + movl $(__USER_DS),%eax
17098 +#else
17099 + xorl %eax,%eax
17100 +#endif
17101 movl %eax,%gs
17102
17103 xorl %eax,%eax # Clear LDT
17104 @@ -526,8 +608,11 @@ setup_once:
17105 * relocation. Manually set base address in stack canary
17106 * segment descriptor.
17107 */
17108 - movl $gdt_page,%eax
17109 + movl $cpu_gdt_table,%eax
17110 movl $stack_canary,%ecx
17111 +#ifdef CONFIG_SMP
17112 + addl $__per_cpu_load,%ecx
17113 +#endif
17114 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17115 shrl $16, %ecx
17116 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17117 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
17118 /* This is global to keep gas from relaxing the jumps */
17119 ENTRY(early_idt_handler)
17120 cld
17121 - cmpl $2,%ss:early_recursion_flag
17122 + cmpl $1,%ss:early_recursion_flag
17123 je hlt_loop
17124 incl %ss:early_recursion_flag
17125
17126 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
17127 pushl (20+6*4)(%esp) /* trapno */
17128 pushl $fault_msg
17129 call printk
17130 -#endif
17131 call dump_stack
17132 +#endif
17133 hlt_loop:
17134 hlt
17135 jmp hlt_loop
17136 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
17137 /* This is the default interrupt "handler" :-) */
17138 ALIGN
17139 ignore_int:
17140 - cld
17141 #ifdef CONFIG_PRINTK
17142 + cmpl $2,%ss:early_recursion_flag
17143 + je hlt_loop
17144 + incl %ss:early_recursion_flag
17145 + cld
17146 pushl %eax
17147 pushl %ecx
17148 pushl %edx
17149 @@ -626,9 +714,6 @@ ignore_int:
17150 movl $(__KERNEL_DS),%eax
17151 movl %eax,%ds
17152 movl %eax,%es
17153 - cmpl $2,early_recursion_flag
17154 - je hlt_loop
17155 - incl early_recursion_flag
17156 pushl 16(%esp)
17157 pushl 24(%esp)
17158 pushl 32(%esp)
17159 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
17160 /*
17161 * BSS section
17162 */
17163 -__PAGE_ALIGNED_BSS
17164 - .align PAGE_SIZE
17165 #ifdef CONFIG_X86_PAE
17166 +.section .initial_pg_pmd,"a",@progbits
17167 initial_pg_pmd:
17168 .fill 1024*KPMDS,4,0
17169 #else
17170 +.section .initial_page_table,"a",@progbits
17171 ENTRY(initial_page_table)
17172 .fill 1024,4,0
17173 #endif
17174 +.section .initial_pg_fixmap,"a",@progbits
17175 initial_pg_fixmap:
17176 .fill 1024,4,0
17177 +.section .empty_zero_page,"a",@progbits
17178 ENTRY(empty_zero_page)
17179 .fill 4096,1,0
17180 +.section .swapper_pg_dir,"a",@progbits
17181 ENTRY(swapper_pg_dir)
17182 +#ifdef CONFIG_X86_PAE
17183 + .fill 4,8,0
17184 +#else
17185 .fill 1024,4,0
17186 +#endif
17187 +
17188 +/*
17189 + * The IDT has to be page-aligned to simplify the Pentium
17190 + * F0 0F bug workaround.. We have a special link segment
17191 + * for this.
17192 + */
17193 +.section .idt,"a",@progbits
17194 +ENTRY(idt_table)
17195 + .fill 256,8,0
17196
17197 /*
17198 * This starts the data section.
17199 */
17200 #ifdef CONFIG_X86_PAE
17201 -__PAGE_ALIGNED_DATA
17202 - /* Page-aligned for the benefit of paravirt? */
17203 - .align PAGE_SIZE
17204 +.section .initial_page_table,"a",@progbits
17205 ENTRY(initial_page_table)
17206 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17207 # if KPMDS == 3
17208 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
17209 # error "Kernel PMDs should be 1, 2 or 3"
17210 # endif
17211 .align PAGE_SIZE /* needs to be page-sized too */
17212 +
17213 +#ifdef CONFIG_PAX_PER_CPU_PGD
17214 +ENTRY(cpu_pgd)
17215 + .rept NR_CPUS
17216 + .fill 4,8,0
17217 + .endr
17218 +#endif
17219 +
17220 #endif
17221
17222 .data
17223 .balign 4
17224 ENTRY(stack_start)
17225 - .long init_thread_union+THREAD_SIZE
17226 + .long init_thread_union+THREAD_SIZE-8
17227
17228 __INITRODATA
17229 int_msg:
17230 @@ -736,7 +843,7 @@ fault_msg:
17231 * segment size, and 32-bit linear address value:
17232 */
17233
17234 - .data
17235 +.section .rodata,"a",@progbits
17236 .globl boot_gdt_descr
17237 .globl idt_descr
17238
17239 @@ -745,7 +852,7 @@ fault_msg:
17240 .word 0 # 32 bit align gdt_desc.address
17241 boot_gdt_descr:
17242 .word __BOOT_DS+7
17243 - .long boot_gdt - __PAGE_OFFSET
17244 + .long pa(boot_gdt)
17245
17246 .word 0 # 32-bit align idt_desc.address
17247 idt_descr:
17248 @@ -756,7 +863,7 @@ idt_descr:
17249 .word 0 # 32 bit align gdt_desc.address
17250 ENTRY(early_gdt_descr)
17251 .word GDT_ENTRIES*8-1
17252 - .long gdt_page /* Overwritten for secondary CPUs */
17253 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17254
17255 /*
17256 * The boot_gdt must mirror the equivalent in setup.S and is
17257 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
17258 .align L1_CACHE_BYTES
17259 ENTRY(boot_gdt)
17260 .fill GDT_ENTRY_BOOT_CS,8,0
17261 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17262 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17263 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17264 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17265 +
17266 + .align PAGE_SIZE_asm
17267 +ENTRY(cpu_gdt_table)
17268 + .rept NR_CPUS
17269 + .quad 0x0000000000000000 /* NULL descriptor */
17270 + .quad 0x0000000000000000 /* 0x0b reserved */
17271 + .quad 0x0000000000000000 /* 0x13 reserved */
17272 + .quad 0x0000000000000000 /* 0x1b reserved */
17273 +
17274 +#ifdef CONFIG_PAX_KERNEXEC
17275 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17276 +#else
17277 + .quad 0x0000000000000000 /* 0x20 unused */
17278 +#endif
17279 +
17280 + .quad 0x0000000000000000 /* 0x28 unused */
17281 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17282 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17283 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17284 + .quad 0x0000000000000000 /* 0x4b reserved */
17285 + .quad 0x0000000000000000 /* 0x53 reserved */
17286 + .quad 0x0000000000000000 /* 0x5b reserved */
17287 +
17288 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17289 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17290 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17291 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17292 +
17293 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17294 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17295 +
17296 + /*
17297 + * Segments used for calling PnP BIOS have byte granularity.
17298 + * The code segments and data segments have fixed 64k limits,
17299 + * the transfer segment sizes are set at run time.
17300 + */
17301 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17302 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17303 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17304 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17305 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17306 +
17307 + /*
17308 + * The APM segments have byte granularity and their bases
17309 + * are set at run time. All have 64k limits.
17310 + */
17311 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17312 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17313 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17314 +
17315 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17316 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17317 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17318 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17319 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17320 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17321 +
17322 + /* Be sure this is zeroed to avoid false validations in Xen */
17323 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17324 + .endr
17325 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17326 index 94bf9cc..400455a 100644
17327 --- a/arch/x86/kernel/head_64.S
17328 +++ b/arch/x86/kernel/head_64.S
17329 @@ -20,6 +20,8 @@
17330 #include <asm/processor-flags.h>
17331 #include <asm/percpu.h>
17332 #include <asm/nops.h>
17333 +#include <asm/cpufeature.h>
17334 +#include <asm/alternative-asm.h>
17335
17336 #ifdef CONFIG_PARAVIRT
17337 #include <asm/asm-offsets.h>
17338 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17339 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17340 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17341 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17342 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17343 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17344 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17345 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17346 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17347 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17348
17349 .text
17350 __HEAD
17351 @@ -88,35 +96,23 @@ startup_64:
17352 */
17353 addq %rbp, init_level4_pgt + 0(%rip)
17354 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17355 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17356 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17357 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17358 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17359
17360 addq %rbp, level3_ident_pgt + 0(%rip)
17361 +#ifndef CONFIG_XEN
17362 + addq %rbp, level3_ident_pgt + 8(%rip)
17363 +#endif
17364
17365 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17366 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17367 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17368 +
17369 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17370 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17371
17372 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17373 -
17374 - /* Add an Identity mapping if I am above 1G */
17375 - leaq _text(%rip), %rdi
17376 - andq $PMD_PAGE_MASK, %rdi
17377 -
17378 - movq %rdi, %rax
17379 - shrq $PUD_SHIFT, %rax
17380 - andq $(PTRS_PER_PUD - 1), %rax
17381 - jz ident_complete
17382 -
17383 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17384 - leaq level3_ident_pgt(%rip), %rbx
17385 - movq %rdx, 0(%rbx, %rax, 8)
17386 -
17387 - movq %rdi, %rax
17388 - shrq $PMD_SHIFT, %rax
17389 - andq $(PTRS_PER_PMD - 1), %rax
17390 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17391 - leaq level2_spare_pgt(%rip), %rbx
17392 - movq %rdx, 0(%rbx, %rax, 8)
17393 -ident_complete:
17394 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17395
17396 /*
17397 * Fixup the kernel text+data virtual addresses. Note that
17398 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17399 * after the boot processor executes this code.
17400 */
17401
17402 - /* Enable PAE mode and PGE */
17403 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17404 + /* Enable PAE mode and PSE/PGE */
17405 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17406 movq %rax, %cr4
17407
17408 /* Setup early boot stage 4 level pagetables. */
17409 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17410 movl $MSR_EFER, %ecx
17411 rdmsr
17412 btsl $_EFER_SCE, %eax /* Enable System Call */
17413 - btl $20,%edi /* No Execute supported? */
17414 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17415 jnc 1f
17416 btsl $_EFER_NX, %eax
17417 + leaq init_level4_pgt(%rip), %rdi
17418 +#ifndef CONFIG_EFI
17419 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17420 +#endif
17421 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17422 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17423 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17424 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17425 1: wrmsr /* Make changes effective */
17426
17427 /* Setup cr0 */
17428 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17429 * jump. In addition we need to ensure %cs is set so we make this
17430 * a far return.
17431 */
17432 + pax_set_fptr_mask
17433 movq initial_code(%rip),%rax
17434 pushq $0 # fake return address to stop unwinder
17435 pushq $__KERNEL_CS # set correct cs
17436 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17437 bad_address:
17438 jmp bad_address
17439
17440 - .section ".init.text","ax"
17441 + __INIT
17442 .globl early_idt_handlers
17443 early_idt_handlers:
17444 # 104(%rsp) %rflags
17445 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17446 addq $16,%rsp # drop vector number and error code
17447 decl early_recursion_flag(%rip)
17448 INTERRUPT_RETURN
17449 + .previous
17450
17451 + __INITDATA
17452 .balign 4
17453 early_recursion_flag:
17454 .long 0
17455 + .previous
17456
17457 + .section .rodata,"a",@progbits
17458 #ifdef CONFIG_EARLY_PRINTK
17459 early_idt_msg:
17460 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17461 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17462 #endif /* CONFIG_EARLY_PRINTK */
17463 .previous
17464
17465 + .section .rodata,"a",@progbits
17466 #define NEXT_PAGE(name) \
17467 .balign PAGE_SIZE; \
17468 ENTRY(name)
17469 @@ -372,7 +382,6 @@ ENTRY(name)
17470 i = i + 1 ; \
17471 .endr
17472
17473 - .data
17474 /*
17475 * This default setting generates an ident mapping at address 0x100000
17476 * and a mapping for the kernel that precisely maps virtual address
17477 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17478 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17479 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17480 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17481 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17482 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17483 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17484 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17485 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17486 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17487 .org init_level4_pgt + L4_START_KERNEL*8, 0
17488 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17489 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17490
17491 +#ifdef CONFIG_PAX_PER_CPU_PGD
17492 +NEXT_PAGE(cpu_pgd)
17493 + .rept NR_CPUS
17494 + .fill 512,8,0
17495 + .endr
17496 +#endif
17497 +
17498 NEXT_PAGE(level3_ident_pgt)
17499 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17500 +#ifdef CONFIG_XEN
17501 .fill 511,8,0
17502 +#else
17503 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17504 + .fill 510,8,0
17505 +#endif
17506 +
17507 +NEXT_PAGE(level3_vmalloc_start_pgt)
17508 + .fill 512,8,0
17509 +
17510 +NEXT_PAGE(level3_vmalloc_end_pgt)
17511 + .fill 512,8,0
17512 +
17513 +NEXT_PAGE(level3_vmemmap_pgt)
17514 + .fill L3_VMEMMAP_START,8,0
17515 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17516
17517 NEXT_PAGE(level3_kernel_pgt)
17518 .fill L3_START_KERNEL,8,0
17519 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17520 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17521 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17522
17523 +NEXT_PAGE(level2_vmemmap_pgt)
17524 + .fill 512,8,0
17525 +
17526 NEXT_PAGE(level2_fixmap_pgt)
17527 - .fill 506,8,0
17528 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17529 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17530 - .fill 5,8,0
17531 + .fill 507,8,0
17532 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17533 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17534 + .fill 4,8,0
17535
17536 -NEXT_PAGE(level1_fixmap_pgt)
17537 +NEXT_PAGE(level1_vsyscall_pgt)
17538 .fill 512,8,0
17539
17540 -NEXT_PAGE(level2_ident_pgt)
17541 - /* Since I easily can, map the first 1G.
17542 + /* Since I easily can, map the first 2G.
17543 * Don't set NX because code runs from these pages.
17544 */
17545 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17546 +NEXT_PAGE(level2_ident_pgt)
17547 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17548
17549 NEXT_PAGE(level2_kernel_pgt)
17550 /*
17551 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17552 * If you want to increase this then increase MODULES_VADDR
17553 * too.)
17554 */
17555 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17556 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17557 -
17558 -NEXT_PAGE(level2_spare_pgt)
17559 - .fill 512, 8, 0
17560 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17561
17562 #undef PMDS
17563 #undef NEXT_PAGE
17564
17565 - .data
17566 + .align PAGE_SIZE
17567 +ENTRY(cpu_gdt_table)
17568 + .rept NR_CPUS
17569 + .quad 0x0000000000000000 /* NULL descriptor */
17570 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17571 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17572 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17573 + .quad 0x00cffb000000ffff /* __USER32_CS */
17574 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17575 + .quad 0x00affb000000ffff /* __USER_CS */
17576 +
17577 +#ifdef CONFIG_PAX_KERNEXEC
17578 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17579 +#else
17580 + .quad 0x0 /* unused */
17581 +#endif
17582 +
17583 + .quad 0,0 /* TSS */
17584 + .quad 0,0 /* LDT */
17585 + .quad 0,0,0 /* three TLS descriptors */
17586 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17587 + /* asm/segment.h:GDT_ENTRIES must match this */
17588 +
17589 + /* zero the remaining page */
17590 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17591 + .endr
17592 +
17593 .align 16
17594 .globl early_gdt_descr
17595 early_gdt_descr:
17596 .word GDT_ENTRIES*8-1
17597 early_gdt_descr_base:
17598 - .quad INIT_PER_CPU_VAR(gdt_page)
17599 + .quad cpu_gdt_table
17600
17601 ENTRY(phys_base)
17602 /* This must match the first entry in level2_kernel_pgt */
17603 .quad 0x0000000000000000
17604
17605 #include "../../x86/xen/xen-head.S"
17606 -
17607 - .section .bss, "aw", @nobits
17608 +
17609 + .section .rodata,"a",@progbits
17610 .align L1_CACHE_BYTES
17611 ENTRY(idt_table)
17612 - .skip IDT_ENTRIES * 16
17613 + .fill 512,8,0
17614
17615 .align L1_CACHE_BYTES
17616 ENTRY(nmi_idt_table)
17617 - .skip IDT_ENTRIES * 16
17618 + .fill 512,8,0
17619
17620 __PAGE_ALIGNED_BSS
17621 .align PAGE_SIZE
17622 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17623 index 9c3bd4a..e1d9b35 100644
17624 --- a/arch/x86/kernel/i386_ksyms_32.c
17625 +++ b/arch/x86/kernel/i386_ksyms_32.c
17626 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17627 EXPORT_SYMBOL(cmpxchg8b_emu);
17628 #endif
17629
17630 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17631 +
17632 /* Networking helper routines. */
17633 EXPORT_SYMBOL(csum_partial_copy_generic);
17634 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17635 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17636
17637 EXPORT_SYMBOL(__get_user_1);
17638 EXPORT_SYMBOL(__get_user_2);
17639 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17640
17641 EXPORT_SYMBOL(csum_partial);
17642 EXPORT_SYMBOL(empty_zero_page);
17643 +
17644 +#ifdef CONFIG_PAX_KERNEXEC
17645 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17646 +#endif
17647 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17648 index 675a050..95febfd 100644
17649 --- a/arch/x86/kernel/i387.c
17650 +++ b/arch/x86/kernel/i387.c
17651 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17652 static inline bool interrupted_user_mode(void)
17653 {
17654 struct pt_regs *regs = get_irq_regs();
17655 - return regs && user_mode_vm(regs);
17656 + return regs && user_mode(regs);
17657 }
17658
17659 /*
17660 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17661 index 9a5c460..dc4374d 100644
17662 --- a/arch/x86/kernel/i8259.c
17663 +++ b/arch/x86/kernel/i8259.c
17664 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17665 "spurious 8259A interrupt: IRQ%d.\n", irq);
17666 spurious_irq_mask |= irqmask;
17667 }
17668 - atomic_inc(&irq_err_count);
17669 + atomic_inc_unchecked(&irq_err_count);
17670 /*
17671 * Theoretically we do not have to handle this IRQ,
17672 * but in Linux this does not cause problems and is
17673 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17674 index 8c96897..be66bfa 100644
17675 --- a/arch/x86/kernel/ioport.c
17676 +++ b/arch/x86/kernel/ioport.c
17677 @@ -6,6 +6,7 @@
17678 #include <linux/sched.h>
17679 #include <linux/kernel.h>
17680 #include <linux/capability.h>
17681 +#include <linux/security.h>
17682 #include <linux/errno.h>
17683 #include <linux/types.h>
17684 #include <linux/ioport.h>
17685 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17686
17687 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17688 return -EINVAL;
17689 +#ifdef CONFIG_GRKERNSEC_IO
17690 + if (turn_on && grsec_disable_privio) {
17691 + gr_handle_ioperm();
17692 + return -EPERM;
17693 + }
17694 +#endif
17695 if (turn_on && !capable(CAP_SYS_RAWIO))
17696 return -EPERM;
17697
17698 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17699 * because the ->io_bitmap_max value must match the bitmap
17700 * contents:
17701 */
17702 - tss = &per_cpu(init_tss, get_cpu());
17703 + tss = init_tss + get_cpu();
17704
17705 if (turn_on)
17706 bitmap_clear(t->io_bitmap_ptr, from, num);
17707 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17708 return -EINVAL;
17709 /* Trying to gain more privileges? */
17710 if (level > old) {
17711 +#ifdef CONFIG_GRKERNSEC_IO
17712 + if (grsec_disable_privio) {
17713 + gr_handle_iopl();
17714 + return -EPERM;
17715 + }
17716 +#endif
17717 if (!capable(CAP_SYS_RAWIO))
17718 return -EPERM;
17719 }
17720 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17721 index e4595f1..ee3bfb8 100644
17722 --- a/arch/x86/kernel/irq.c
17723 +++ b/arch/x86/kernel/irq.c
17724 @@ -18,7 +18,7 @@
17725 #include <asm/mce.h>
17726 #include <asm/hw_irq.h>
17727
17728 -atomic_t irq_err_count;
17729 +atomic_unchecked_t irq_err_count;
17730
17731 /* Function pointer for generic interrupt vector handling */
17732 void (*x86_platform_ipi_callback)(void) = NULL;
17733 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17734 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17735 seq_printf(p, " Machine check polls\n");
17736 #endif
17737 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17738 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17739 #if defined(CONFIG_X86_IO_APIC)
17740 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17741 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17742 #endif
17743 return 0;
17744 }
17745 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17746
17747 u64 arch_irq_stat(void)
17748 {
17749 - u64 sum = atomic_read(&irq_err_count);
17750 + u64 sum = atomic_read_unchecked(&irq_err_count);
17751
17752 #ifdef CONFIG_X86_IO_APIC
17753 - sum += atomic_read(&irq_mis_count);
17754 + sum += atomic_read_unchecked(&irq_mis_count);
17755 #endif
17756 return sum;
17757 }
17758 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17759 index 344faf8..355f60d 100644
17760 --- a/arch/x86/kernel/irq_32.c
17761 +++ b/arch/x86/kernel/irq_32.c
17762 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17763 __asm__ __volatile__("andl %%esp,%0" :
17764 "=r" (sp) : "0" (THREAD_SIZE - 1));
17765
17766 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17767 + return sp < STACK_WARN;
17768 }
17769
17770 static void print_stack_overflow(void)
17771 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17772 * per-CPU IRQ handling contexts (thread information and stack)
17773 */
17774 union irq_ctx {
17775 - struct thread_info tinfo;
17776 - u32 stack[THREAD_SIZE/sizeof(u32)];
17777 + unsigned long previous_esp;
17778 + u32 stack[THREAD_SIZE/sizeof(u32)];
17779 } __attribute__((aligned(THREAD_SIZE)));
17780
17781 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17782 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17783 static inline int
17784 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17785 {
17786 - union irq_ctx *curctx, *irqctx;
17787 + union irq_ctx *irqctx;
17788 u32 *isp, arg1, arg2;
17789
17790 - curctx = (union irq_ctx *) current_thread_info();
17791 irqctx = __this_cpu_read(hardirq_ctx);
17792
17793 /*
17794 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17795 * handler) we can't do that and just have to keep using the
17796 * current stack (which is the irq stack already after all)
17797 */
17798 - if (unlikely(curctx == irqctx))
17799 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17800 return 0;
17801
17802 /* build the stack frame on the IRQ stack */
17803 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17804 - irqctx->tinfo.task = curctx->tinfo.task;
17805 - irqctx->tinfo.previous_esp = current_stack_pointer;
17806 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17807 + irqctx->previous_esp = current_stack_pointer;
17808
17809 - /* Copy the preempt_count so that the [soft]irq checks work. */
17810 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17812 + __set_fs(MAKE_MM_SEG(0));
17813 +#endif
17814
17815 if (unlikely(overflow))
17816 call_on_stack(print_stack_overflow, isp);
17817 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17818 : "0" (irq), "1" (desc), "2" (isp),
17819 "D" (desc->handle_irq)
17820 : "memory", "cc", "ecx");
17821 +
17822 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17823 + __set_fs(current_thread_info()->addr_limit);
17824 +#endif
17825 +
17826 return 1;
17827 }
17828
17829 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17830 */
17831 void __cpuinit irq_ctx_init(int cpu)
17832 {
17833 - union irq_ctx *irqctx;
17834 -
17835 if (per_cpu(hardirq_ctx, cpu))
17836 return;
17837
17838 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17839 - THREADINFO_GFP,
17840 - THREAD_SIZE_ORDER));
17841 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17842 - irqctx->tinfo.cpu = cpu;
17843 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17844 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17845 -
17846 - per_cpu(hardirq_ctx, cpu) = irqctx;
17847 -
17848 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17849 - THREADINFO_GFP,
17850 - THREAD_SIZE_ORDER));
17851 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17852 - irqctx->tinfo.cpu = cpu;
17853 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17854 -
17855 - per_cpu(softirq_ctx, cpu) = irqctx;
17856 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17857 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17858 +
17859 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17860 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17861
17862 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17863 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17864 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17865 asmlinkage void do_softirq(void)
17866 {
17867 unsigned long flags;
17868 - struct thread_info *curctx;
17869 union irq_ctx *irqctx;
17870 u32 *isp;
17871
17872 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17873 local_irq_save(flags);
17874
17875 if (local_softirq_pending()) {
17876 - curctx = current_thread_info();
17877 irqctx = __this_cpu_read(softirq_ctx);
17878 - irqctx->tinfo.task = curctx->task;
17879 - irqctx->tinfo.previous_esp = current_stack_pointer;
17880 + irqctx->previous_esp = current_stack_pointer;
17881
17882 /* build the stack frame on the softirq stack */
17883 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17884 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17885 +
17886 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17887 + __set_fs(MAKE_MM_SEG(0));
17888 +#endif
17889
17890 call_on_stack(__do_softirq, isp);
17891 +
17892 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17893 + __set_fs(current_thread_info()->addr_limit);
17894 +#endif
17895 +
17896 /*
17897 * Shouldn't happen, we returned above if in_interrupt():
17898 */
17899 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17900 if (unlikely(!desc))
17901 return false;
17902
17903 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17904 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17905 if (unlikely(overflow))
17906 print_stack_overflow();
17907 desc->handle_irq(irq, desc);
17908 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17909 index d04d3ec..ea4b374 100644
17910 --- a/arch/x86/kernel/irq_64.c
17911 +++ b/arch/x86/kernel/irq_64.c
17912 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17913 u64 estack_top, estack_bottom;
17914 u64 curbase = (u64)task_stack_page(current);
17915
17916 - if (user_mode_vm(regs))
17917 + if (user_mode(regs))
17918 return;
17919
17920 if (regs->sp >= curbase + sizeof(struct thread_info) +
17921 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17922 index dc1404b..bbc43e7 100644
17923 --- a/arch/x86/kernel/kdebugfs.c
17924 +++ b/arch/x86/kernel/kdebugfs.c
17925 @@ -27,7 +27,7 @@ struct setup_data_node {
17926 u32 len;
17927 };
17928
17929 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17930 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17931 size_t count, loff_t *ppos)
17932 {
17933 struct setup_data_node *node = file->private_data;
17934 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17935 index 836f832..a8bda67 100644
17936 --- a/arch/x86/kernel/kgdb.c
17937 +++ b/arch/x86/kernel/kgdb.c
17938 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17939 #ifdef CONFIG_X86_32
17940 switch (regno) {
17941 case GDB_SS:
17942 - if (!user_mode_vm(regs))
17943 + if (!user_mode(regs))
17944 *(unsigned long *)mem = __KERNEL_DS;
17945 break;
17946 case GDB_SP:
17947 - if (!user_mode_vm(regs))
17948 + if (!user_mode(regs))
17949 *(unsigned long *)mem = kernel_stack_pointer(regs);
17950 break;
17951 case GDB_GS:
17952 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
17953 bp->attr.bp_addr = breakinfo[breakno].addr;
17954 bp->attr.bp_len = breakinfo[breakno].len;
17955 bp->attr.bp_type = breakinfo[breakno].type;
17956 - info->address = breakinfo[breakno].addr;
17957 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
17958 + info->address = ktla_ktva(breakinfo[breakno].addr);
17959 + else
17960 + info->address = breakinfo[breakno].addr;
17961 info->len = breakinfo[breakno].len;
17962 info->type = breakinfo[breakno].type;
17963 val = arch_install_hw_breakpoint(bp);
17964 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17965 case 'k':
17966 /* clear the trace bit */
17967 linux_regs->flags &= ~X86_EFLAGS_TF;
17968 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17969 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17970
17971 /* set the trace bit if we're stepping */
17972 if (remcomInBuffer[0] == 's') {
17973 linux_regs->flags |= X86_EFLAGS_TF;
17974 - atomic_set(&kgdb_cpu_doing_single_step,
17975 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17976 raw_smp_processor_id());
17977 }
17978
17979 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17980
17981 switch (cmd) {
17982 case DIE_DEBUG:
17983 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17984 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17985 if (user_mode(regs))
17986 return single_step_cont(regs, args);
17987 break;
17988 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
17989 #endif /* CONFIG_DEBUG_RODATA */
17990
17991 bpt->type = BP_BREAKPOINT;
17992 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
17993 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
17994 BREAK_INSTR_SIZE);
17995 if (err)
17996 return err;
17997 - err = probe_kernel_write((char *)bpt->bpt_addr,
17998 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
17999 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
18000 #ifdef CONFIG_DEBUG_RODATA
18001 if (!err)
18002 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18003 return -EBUSY;
18004 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
18005 BREAK_INSTR_SIZE);
18006 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18007 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18008 if (err)
18009 return err;
18010 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
18011 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
18012 if (mutex_is_locked(&text_mutex))
18013 goto knl_write;
18014 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
18015 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18016 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18017 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
18018 goto knl_write;
18019 return err;
18020 knl_write:
18021 #endif /* CONFIG_DEBUG_RODATA */
18022 - return probe_kernel_write((char *)bpt->bpt_addr,
18023 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18024 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
18025 }
18026
18027 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
18028 index c5e410e..ed5a7f0 100644
18029 --- a/arch/x86/kernel/kprobes-opt.c
18030 +++ b/arch/x86/kernel/kprobes-opt.c
18031 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18032 * Verify if the address gap is in 2GB range, because this uses
18033 * a relative jump.
18034 */
18035 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18036 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18037 if (abs(rel) > 0x7fffffff)
18038 return -ERANGE;
18039
18040 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18041 op->optinsn.size = ret;
18042
18043 /* Copy arch-dep-instance from template */
18044 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
18045 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
18046
18047 /* Set probe information */
18048 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18049
18050 /* Set probe function call */
18051 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18052 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
18053
18054 /* Set returning jmp instruction at the tail of out-of-line buffer */
18055 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18056 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
18057 (u8 *)op->kp.addr + op->optinsn.size);
18058
18059 flush_icache_range((unsigned long) buf,
18060 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18061 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18062
18063 /* Backup instructions which will be replaced by jump address */
18064 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18065 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18066 RELATIVE_ADDR_SIZE);
18067
18068 insn_buf[0] = RELATIVEJUMP_OPCODE;
18069 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
18070 /* This kprobe is really able to run optimized path. */
18071 op = container_of(p, struct optimized_kprobe, kp);
18072 /* Detour through copied instructions */
18073 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
18074 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
18075 if (!reenter)
18076 reset_current_kprobe();
18077 preempt_enable_no_resched();
18078 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
18079 index 57916c0..9e0b9d0 100644
18080 --- a/arch/x86/kernel/kprobes.c
18081 +++ b/arch/x86/kernel/kprobes.c
18082 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
18083 s32 raddr;
18084 } __attribute__((packed)) *insn;
18085
18086 - insn = (struct __arch_relative_insn *)from;
18087 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
18088 +
18089 + pax_open_kernel();
18090 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18091 insn->op = op;
18092 + pax_close_kernel();
18093 }
18094
18095 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18096 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18097 kprobe_opcode_t opcode;
18098 kprobe_opcode_t *orig_opcodes = opcodes;
18099
18100 - if (search_exception_tables((unsigned long)opcodes))
18101 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18102 return 0; /* Page fault may occur on this address. */
18103
18104 retry:
18105 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
18106 * for the first byte, we can recover the original instruction
18107 * from it and kp->opcode.
18108 */
18109 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
18110 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
18111 buf[0] = kp->opcode;
18112 - return (unsigned long)buf;
18113 + return ktva_ktla((unsigned long)buf);
18114 }
18115
18116 /*
18117 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18118 /* Another subsystem puts a breakpoint, failed to recover */
18119 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18120 return 0;
18121 + pax_open_kernel();
18122 memcpy(dest, insn.kaddr, insn.length);
18123 + pax_close_kernel();
18124
18125 #ifdef CONFIG_X86_64
18126 if (insn_rip_relative(&insn)) {
18127 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18128 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18129 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18130 disp = (u8 *) dest + insn_offset_displacement(&insn);
18131 + pax_open_kernel();
18132 *(s32 *) disp = (s32) newdisp;
18133 + pax_close_kernel();
18134 }
18135 #endif
18136 return insn.length;
18137 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18138 * nor set current_kprobe, because it doesn't use single
18139 * stepping.
18140 */
18141 - regs->ip = (unsigned long)p->ainsn.insn;
18142 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18143 preempt_enable_no_resched();
18144 return;
18145 }
18146 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18147 regs->flags &= ~X86_EFLAGS_IF;
18148 /* single step inline if the instruction is an int3 */
18149 if (p->opcode == BREAKPOINT_INSTRUCTION)
18150 - regs->ip = (unsigned long)p->addr;
18151 + regs->ip = ktla_ktva((unsigned long)p->addr);
18152 else
18153 - regs->ip = (unsigned long)p->ainsn.insn;
18154 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18155 }
18156
18157 /*
18158 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18159 setup_singlestep(p, regs, kcb, 0);
18160 return 1;
18161 }
18162 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18163 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18164 /*
18165 * The breakpoint instruction was removed right
18166 * after we hit it. Another cpu has removed
18167 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18168 " movq %rax, 152(%rsp)\n"
18169 RESTORE_REGS_STRING
18170 " popfq\n"
18171 +#ifdef KERNEXEC_PLUGIN
18172 + " btsq $63,(%rsp)\n"
18173 +#endif
18174 #else
18175 " pushf\n"
18176 SAVE_REGS_STRING
18177 @@ -788,7 +798,7 @@ static void __kprobes
18178 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18179 {
18180 unsigned long *tos = stack_addr(regs);
18181 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18182 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18183 unsigned long orig_ip = (unsigned long)p->addr;
18184 kprobe_opcode_t *insn = p->ainsn.insn;
18185
18186 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18187 struct die_args *args = data;
18188 int ret = NOTIFY_DONE;
18189
18190 - if (args->regs && user_mode_vm(args->regs))
18191 + if (args->regs && user_mode(args->regs))
18192 return ret;
18193
18194 switch (val) {
18195 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18196 index ebc9873..1b9724b 100644
18197 --- a/arch/x86/kernel/ldt.c
18198 +++ b/arch/x86/kernel/ldt.c
18199 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18200 if (reload) {
18201 #ifdef CONFIG_SMP
18202 preempt_disable();
18203 - load_LDT(pc);
18204 + load_LDT_nolock(pc);
18205 if (!cpumask_equal(mm_cpumask(current->mm),
18206 cpumask_of(smp_processor_id())))
18207 smp_call_function(flush_ldt, current->mm, 1);
18208 preempt_enable();
18209 #else
18210 - load_LDT(pc);
18211 + load_LDT_nolock(pc);
18212 #endif
18213 }
18214 if (oldsize) {
18215 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18216 return err;
18217
18218 for (i = 0; i < old->size; i++)
18219 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18220 + write_ldt_entry(new->ldt, i, old->ldt + i);
18221 return 0;
18222 }
18223
18224 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18225 retval = copy_ldt(&mm->context, &old_mm->context);
18226 mutex_unlock(&old_mm->context.lock);
18227 }
18228 +
18229 + if (tsk == current) {
18230 + mm->context.vdso = 0;
18231 +
18232 +#ifdef CONFIG_X86_32
18233 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18234 + mm->context.user_cs_base = 0UL;
18235 + mm->context.user_cs_limit = ~0UL;
18236 +
18237 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18238 + cpus_clear(mm->context.cpu_user_cs_mask);
18239 +#endif
18240 +
18241 +#endif
18242 +#endif
18243 +
18244 + }
18245 +
18246 return retval;
18247 }
18248
18249 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18250 }
18251 }
18252
18253 +#ifdef CONFIG_PAX_SEGMEXEC
18254 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18255 + error = -EINVAL;
18256 + goto out_unlock;
18257 + }
18258 +#endif
18259 +
18260 fill_ldt(&ldt, &ldt_info);
18261 if (oldmode)
18262 ldt.avl = 0;
18263 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18264 index 5b19e4d..6476a76 100644
18265 --- a/arch/x86/kernel/machine_kexec_32.c
18266 +++ b/arch/x86/kernel/machine_kexec_32.c
18267 @@ -26,7 +26,7 @@
18268 #include <asm/cacheflush.h>
18269 #include <asm/debugreg.h>
18270
18271 -static void set_idt(void *newidt, __u16 limit)
18272 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18273 {
18274 struct desc_ptr curidt;
18275
18276 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18277 }
18278
18279
18280 -static void set_gdt(void *newgdt, __u16 limit)
18281 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18282 {
18283 struct desc_ptr curgdt;
18284
18285 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18286 }
18287
18288 control_page = page_address(image->control_code_page);
18289 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18290 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18291
18292 relocate_kernel_ptr = control_page;
18293 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18294 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18295 index 3544aed..01ddc1c 100644
18296 --- a/arch/x86/kernel/microcode_intel.c
18297 +++ b/arch/x86/kernel/microcode_intel.c
18298 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
18299
18300 static int get_ucode_user(void *to, const void *from, size_t n)
18301 {
18302 - return copy_from_user(to, from, n);
18303 + return copy_from_user(to, (const void __force_user *)from, n);
18304 }
18305
18306 static enum ucode_state
18307 request_microcode_user(int cpu, const void __user *buf, size_t size)
18308 {
18309 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18310 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18311 }
18312
18313 static void microcode_fini_cpu(int cpu)
18314 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18315 index 216a4d7..b328f09 100644
18316 --- a/arch/x86/kernel/module.c
18317 +++ b/arch/x86/kernel/module.c
18318 @@ -43,15 +43,60 @@ do { \
18319 } while (0)
18320 #endif
18321
18322 -void *module_alloc(unsigned long size)
18323 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18324 {
18325 - if (PAGE_ALIGN(size) > MODULES_LEN)
18326 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18327 return NULL;
18328 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18329 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18330 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18331 -1, __builtin_return_address(0));
18332 }
18333
18334 +void *module_alloc(unsigned long size)
18335 +{
18336 +
18337 +#ifdef CONFIG_PAX_KERNEXEC
18338 + return __module_alloc(size, PAGE_KERNEL);
18339 +#else
18340 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18341 +#endif
18342 +
18343 +}
18344 +
18345 +#ifdef CONFIG_PAX_KERNEXEC
18346 +#ifdef CONFIG_X86_32
18347 +void *module_alloc_exec(unsigned long size)
18348 +{
18349 + struct vm_struct *area;
18350 +
18351 + if (size == 0)
18352 + return NULL;
18353 +
18354 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18355 + return area ? area->addr : NULL;
18356 +}
18357 +EXPORT_SYMBOL(module_alloc_exec);
18358 +
18359 +void module_free_exec(struct module *mod, void *module_region)
18360 +{
18361 + vunmap(module_region);
18362 +}
18363 +EXPORT_SYMBOL(module_free_exec);
18364 +#else
18365 +void module_free_exec(struct module *mod, void *module_region)
18366 +{
18367 + module_free(mod, module_region);
18368 +}
18369 +EXPORT_SYMBOL(module_free_exec);
18370 +
18371 +void *module_alloc_exec(unsigned long size)
18372 +{
18373 + return __module_alloc(size, PAGE_KERNEL_RX);
18374 +}
18375 +EXPORT_SYMBOL(module_alloc_exec);
18376 +#endif
18377 +#endif
18378 +
18379 #ifdef CONFIG_X86_32
18380 int apply_relocate(Elf32_Shdr *sechdrs,
18381 const char *strtab,
18382 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18383 unsigned int i;
18384 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18385 Elf32_Sym *sym;
18386 - uint32_t *location;
18387 + uint32_t *plocation, location;
18388
18389 DEBUGP("Applying relocate section %u to %u\n",
18390 relsec, sechdrs[relsec].sh_info);
18391 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18392 /* This is where to make the change */
18393 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18394 - + rel[i].r_offset;
18395 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18396 + location = (uint32_t)plocation;
18397 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18398 + plocation = ktla_ktva((void *)plocation);
18399 /* This is the symbol it is referring to. Note that all
18400 undefined symbols have been resolved. */
18401 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18402 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18403 switch (ELF32_R_TYPE(rel[i].r_info)) {
18404 case R_386_32:
18405 /* We add the value into the location given */
18406 - *location += sym->st_value;
18407 + pax_open_kernel();
18408 + *plocation += sym->st_value;
18409 + pax_close_kernel();
18410 break;
18411 case R_386_PC32:
18412 /* Add the value, subtract its position */
18413 - *location += sym->st_value - (uint32_t)location;
18414 + pax_open_kernel();
18415 + *plocation += sym->st_value - location;
18416 + pax_close_kernel();
18417 break;
18418 default:
18419 pr_err("%s: Unknown relocation: %u\n",
18420 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18421 case R_X86_64_NONE:
18422 break;
18423 case R_X86_64_64:
18424 + pax_open_kernel();
18425 *(u64 *)loc = val;
18426 + pax_close_kernel();
18427 break;
18428 case R_X86_64_32:
18429 + pax_open_kernel();
18430 *(u32 *)loc = val;
18431 + pax_close_kernel();
18432 if (val != *(u32 *)loc)
18433 goto overflow;
18434 break;
18435 case R_X86_64_32S:
18436 + pax_open_kernel();
18437 *(s32 *)loc = val;
18438 + pax_close_kernel();
18439 if ((s64)val != *(s32 *)loc)
18440 goto overflow;
18441 break;
18442 case R_X86_64_PC32:
18443 val -= (u64)loc;
18444 + pax_open_kernel();
18445 *(u32 *)loc = val;
18446 + pax_close_kernel();
18447 +
18448 #if 0
18449 if ((s64)val != *(s32 *)loc)
18450 goto overflow;
18451 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18452 index f84f5c5..e27e54b 100644
18453 --- a/arch/x86/kernel/nmi.c
18454 +++ b/arch/x86/kernel/nmi.c
18455 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18456 dotraplinkage notrace __kprobes void
18457 do_nmi(struct pt_regs *regs, long error_code)
18458 {
18459 +
18460 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18461 + if (!user_mode(regs)) {
18462 + unsigned long cs = regs->cs & 0xFFFF;
18463 + unsigned long ip = ktva_ktla(regs->ip);
18464 +
18465 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18466 + regs->ip = ip;
18467 + }
18468 +#endif
18469 +
18470 nmi_nesting_preprocess(regs);
18471
18472 nmi_enter();
18473 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18474 index 676b8c7..870ba04 100644
18475 --- a/arch/x86/kernel/paravirt-spinlocks.c
18476 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18477 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18478 arch_spin_lock(lock);
18479 }
18480
18481 -struct pv_lock_ops pv_lock_ops = {
18482 +struct pv_lock_ops pv_lock_ops __read_only = {
18483 #ifdef CONFIG_SMP
18484 .spin_is_locked = __ticket_spin_is_locked,
18485 .spin_is_contended = __ticket_spin_is_contended,
18486 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18487 index 17fff18..7bb2088 100644
18488 --- a/arch/x86/kernel/paravirt.c
18489 +++ b/arch/x86/kernel/paravirt.c
18490 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18491 {
18492 return x;
18493 }
18494 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18495 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18496 +#endif
18497
18498 void __init default_banner(void)
18499 {
18500 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18501 if (opfunc == NULL)
18502 /* If there's no function, patch it with a ud2a (BUG) */
18503 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18504 - else if (opfunc == _paravirt_nop)
18505 + else if (opfunc == (void *)_paravirt_nop)
18506 /* If the operation is a nop, then nop the callsite */
18507 ret = paravirt_patch_nop();
18508
18509 /* identity functions just return their single argument */
18510 - else if (opfunc == _paravirt_ident_32)
18511 + else if (opfunc == (void *)_paravirt_ident_32)
18512 ret = paravirt_patch_ident_32(insnbuf, len);
18513 - else if (opfunc == _paravirt_ident_64)
18514 + else if (opfunc == (void *)_paravirt_ident_64)
18515 ret = paravirt_patch_ident_64(insnbuf, len);
18516 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18517 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18518 + ret = paravirt_patch_ident_64(insnbuf, len);
18519 +#endif
18520
18521 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18522 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18523 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18524 if (insn_len > len || start == NULL)
18525 insn_len = len;
18526 else
18527 - memcpy(insnbuf, start, insn_len);
18528 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18529
18530 return insn_len;
18531 }
18532 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18533 preempt_enable();
18534 }
18535
18536 -struct pv_info pv_info = {
18537 +struct pv_info pv_info __read_only = {
18538 .name = "bare hardware",
18539 .paravirt_enabled = 0,
18540 .kernel_rpl = 0,
18541 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18542 #endif
18543 };
18544
18545 -struct pv_init_ops pv_init_ops = {
18546 +struct pv_init_ops pv_init_ops __read_only = {
18547 .patch = native_patch,
18548 };
18549
18550 -struct pv_time_ops pv_time_ops = {
18551 +struct pv_time_ops pv_time_ops __read_only = {
18552 .sched_clock = native_sched_clock,
18553 .steal_clock = native_steal_clock,
18554 };
18555
18556 -struct pv_irq_ops pv_irq_ops = {
18557 +struct pv_irq_ops pv_irq_ops __read_only = {
18558 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18559 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18560 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18561 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18562 #endif
18563 };
18564
18565 -struct pv_cpu_ops pv_cpu_ops = {
18566 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18567 .cpuid = native_cpuid,
18568 .get_debugreg = native_get_debugreg,
18569 .set_debugreg = native_set_debugreg,
18570 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18571 .end_context_switch = paravirt_nop,
18572 };
18573
18574 -struct pv_apic_ops pv_apic_ops = {
18575 +struct pv_apic_ops pv_apic_ops __read_only = {
18576 #ifdef CONFIG_X86_LOCAL_APIC
18577 .startup_ipi_hook = paravirt_nop,
18578 #endif
18579 };
18580
18581 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18582 +#ifdef CONFIG_X86_32
18583 +#ifdef CONFIG_X86_PAE
18584 +/* 64-bit pagetable entries */
18585 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18586 +#else
18587 /* 32-bit pagetable entries */
18588 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18589 +#endif
18590 #else
18591 /* 64-bit pagetable entries */
18592 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18593 #endif
18594
18595 -struct pv_mmu_ops pv_mmu_ops = {
18596 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18597
18598 .read_cr2 = native_read_cr2,
18599 .write_cr2 = native_write_cr2,
18600 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18601 .make_pud = PTE_IDENT,
18602
18603 .set_pgd = native_set_pgd,
18604 + .set_pgd_batched = native_set_pgd_batched,
18605 #endif
18606 #endif /* PAGETABLE_LEVELS >= 3 */
18607
18608 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18609 },
18610
18611 .set_fixmap = native_set_fixmap,
18612 +
18613 +#ifdef CONFIG_PAX_KERNEXEC
18614 + .pax_open_kernel = native_pax_open_kernel,
18615 + .pax_close_kernel = native_pax_close_kernel,
18616 +#endif
18617 +
18618 };
18619
18620 EXPORT_SYMBOL_GPL(pv_time_ops);
18621 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18622 index 35ccf75..7a15747 100644
18623 --- a/arch/x86/kernel/pci-iommu_table.c
18624 +++ b/arch/x86/kernel/pci-iommu_table.c
18625 @@ -2,7 +2,7 @@
18626 #include <asm/iommu_table.h>
18627 #include <linux/string.h>
18628 #include <linux/kallsyms.h>
18629 -
18630 +#include <linux/sched.h>
18631
18632 #define DEBUG 1
18633
18634 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18635 index b644e1c..4a6d379 100644
18636 --- a/arch/x86/kernel/process.c
18637 +++ b/arch/x86/kernel/process.c
18638 @@ -36,7 +36,8 @@
18639 * section. Since TSS's are completely CPU-local, we want them
18640 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18641 */
18642 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18643 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18644 +EXPORT_SYMBOL(init_tss);
18645
18646 #ifdef CONFIG_X86_64
18647 static DEFINE_PER_CPU(unsigned char, is_idle);
18648 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18649 task_xstate_cachep =
18650 kmem_cache_create("task_xstate", xstate_size,
18651 __alignof__(union thread_xstate),
18652 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18653 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18654 }
18655
18656 /*
18657 @@ -105,7 +106,7 @@ void exit_thread(void)
18658 unsigned long *bp = t->io_bitmap_ptr;
18659
18660 if (bp) {
18661 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18662 + struct tss_struct *tss = init_tss + get_cpu();
18663
18664 t->io_bitmap_ptr = NULL;
18665 clear_thread_flag(TIF_IO_BITMAP);
18666 @@ -136,7 +137,7 @@ void show_regs_common(void)
18667 board = dmi_get_system_info(DMI_BOARD_NAME);
18668
18669 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18670 - current->pid, current->comm, print_tainted(),
18671 + task_pid_nr(current), current->comm, print_tainted(),
18672 init_utsname()->release,
18673 (int)strcspn(init_utsname()->version, " "),
18674 init_utsname()->version,
18675 @@ -149,6 +150,9 @@ void flush_thread(void)
18676 {
18677 struct task_struct *tsk = current;
18678
18679 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18680 + loadsegment(gs, 0);
18681 +#endif
18682 flush_ptrace_hw_breakpoint(tsk);
18683 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18684 drop_init_fpu(tsk);
18685 @@ -336,7 +340,7 @@ static void __exit_idle(void)
18686 void exit_idle(void)
18687 {
18688 /* idle loop has pid 0 */
18689 - if (current->pid)
18690 + if (task_pid_nr(current))
18691 return;
18692 __exit_idle();
18693 }
18694 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
18695
18696 return ret;
18697 }
18698 -void stop_this_cpu(void *dummy)
18699 +__noreturn void stop_this_cpu(void *dummy)
18700 {
18701 local_irq_disable();
18702 /*
18703 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
18704 }
18705 early_param("idle", idle_setup);
18706
18707 -unsigned long arch_align_stack(unsigned long sp)
18708 +#ifdef CONFIG_PAX_RANDKSTACK
18709 +void pax_randomize_kstack(struct pt_regs *regs)
18710 {
18711 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18712 - sp -= get_random_int() % 8192;
18713 - return sp & ~0xf;
18714 -}
18715 + struct thread_struct *thread = &current->thread;
18716 + unsigned long time;
18717
18718 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18719 -{
18720 - unsigned long range_end = mm->brk + 0x02000000;
18721 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18722 -}
18723 + if (!randomize_va_space)
18724 + return;
18725 +
18726 + if (v8086_mode(regs))
18727 + return;
18728
18729 + rdtscl(time);
18730 +
18731 + /* P4 seems to return a 0 LSB, ignore it */
18732 +#ifdef CONFIG_MPENTIUM4
18733 + time &= 0x3EUL;
18734 + time <<= 2;
18735 +#elif defined(CONFIG_X86_64)
18736 + time &= 0xFUL;
18737 + time <<= 4;
18738 +#else
18739 + time &= 0x1FUL;
18740 + time <<= 3;
18741 +#endif
18742 +
18743 + thread->sp0 ^= time;
18744 + load_sp0(init_tss + smp_processor_id(), thread);
18745 +
18746 +#ifdef CONFIG_X86_64
18747 + this_cpu_write(kernel_stack, thread->sp0);
18748 +#endif
18749 +}
18750 +#endif
18751 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18752 index 44e0bff..5ceb99c 100644
18753 --- a/arch/x86/kernel/process_32.c
18754 +++ b/arch/x86/kernel/process_32.c
18755 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
18756 unsigned long thread_saved_pc(struct task_struct *tsk)
18757 {
18758 return ((unsigned long *)tsk->thread.sp)[3];
18759 +//XXX return tsk->thread.eip;
18760 }
18761
18762 void __show_regs(struct pt_regs *regs, int all)
18763 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
18764 unsigned long sp;
18765 unsigned short ss, gs;
18766
18767 - if (user_mode_vm(regs)) {
18768 + if (user_mode(regs)) {
18769 sp = regs->sp;
18770 ss = regs->ss & 0xffff;
18771 - gs = get_user_gs(regs);
18772 } else {
18773 sp = kernel_stack_pointer(regs);
18774 savesegment(ss, ss);
18775 - savesegment(gs, gs);
18776 }
18777 + gs = get_user_gs(regs);
18778
18779 show_regs_common();
18780
18781 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
18782 (u16)regs->cs, regs->ip, regs->flags,
18783 - smp_processor_id());
18784 + raw_smp_processor_id());
18785 print_symbol("EIP is at %s\n", regs->ip);
18786
18787 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
18788 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18789 unsigned long arg,
18790 struct task_struct *p, struct pt_regs *regs)
18791 {
18792 - struct pt_regs *childregs = task_pt_regs(p);
18793 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18794 struct task_struct *tsk;
18795 int err;
18796
18797 p->thread.sp = (unsigned long) childregs;
18798 p->thread.sp0 = (unsigned long) (childregs+1);
18799 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18800
18801 if (unlikely(!regs)) {
18802 /* kernel thread */
18803 memset(childregs, 0, sizeof(struct pt_regs));
18804 p->thread.ip = (unsigned long) ret_from_kernel_thread;
18805 - task_user_gs(p) = __KERNEL_STACK_CANARY;
18806 - childregs->ds = __USER_DS;
18807 - childregs->es = __USER_DS;
18808 + savesegment(gs, childregs->gs);
18809 + childregs->ds = __KERNEL_DS;
18810 + childregs->es = __KERNEL_DS;
18811 childregs->fs = __KERNEL_PERCPU;
18812 childregs->bx = sp; /* function */
18813 childregs->bp = arg;
18814 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18815 struct thread_struct *prev = &prev_p->thread,
18816 *next = &next_p->thread;
18817 int cpu = smp_processor_id();
18818 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18819 + struct tss_struct *tss = init_tss + cpu;
18820 fpu_switch_t fpu;
18821
18822 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18823 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18824 */
18825 lazy_save_gs(prev->gs);
18826
18827 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18828 + __set_fs(task_thread_info(next_p)->addr_limit);
18829 +#endif
18830 +
18831 /*
18832 * Load the per-thread Thread-Local Storage descriptor.
18833 */
18834 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18835 */
18836 arch_end_context_switch(next_p);
18837
18838 + this_cpu_write(current_task, next_p);
18839 + this_cpu_write(current_tinfo, &next_p->tinfo);
18840 +
18841 /*
18842 * Restore %gs if needed (which is common)
18843 */
18844 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18845
18846 switch_fpu_finish(next_p, fpu);
18847
18848 - this_cpu_write(current_task, next_p);
18849 -
18850 return prev_p;
18851 }
18852
18853 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
18854 } while (count++ < 16);
18855 return 0;
18856 }
18857 -
18858 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18859 index 16c6365..5d32218 100644
18860 --- a/arch/x86/kernel/process_64.c
18861 +++ b/arch/x86/kernel/process_64.c
18862 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18863 struct pt_regs *childregs;
18864 struct task_struct *me = current;
18865
18866 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
18867 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
18868 childregs = task_pt_regs(p);
18869 p->thread.sp = (unsigned long) childregs;
18870 p->thread.usersp = me->thread.usersp;
18871 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18872 set_tsk_thread_flag(p, TIF_FORK);
18873 p->fpu_counter = 0;
18874 p->thread.io_bitmap_ptr = NULL;
18875 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18876 struct thread_struct *prev = &prev_p->thread;
18877 struct thread_struct *next = &next_p->thread;
18878 int cpu = smp_processor_id();
18879 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18880 + struct tss_struct *tss = init_tss + cpu;
18881 unsigned fsindex, gsindex;
18882 fpu_switch_t fpu;
18883
18884 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18885 prev->usersp = this_cpu_read(old_rsp);
18886 this_cpu_write(old_rsp, next->usersp);
18887 this_cpu_write(current_task, next_p);
18888 + this_cpu_write(current_tinfo, &next_p->tinfo);
18889
18890 - this_cpu_write(kernel_stack,
18891 - (unsigned long)task_stack_page(next_p) +
18892 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18893 + this_cpu_write(kernel_stack, next->sp0);
18894
18895 /*
18896 * Now maybe reload the debug registers and handle I/O bitmaps
18897 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
18898 if (!p || p == current || p->state == TASK_RUNNING)
18899 return 0;
18900 stack = (unsigned long)task_stack_page(p);
18901 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18902 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18903 return 0;
18904 fp = *(u64 *)(p->thread.sp);
18905 do {
18906 - if (fp < (unsigned long)stack ||
18907 - fp >= (unsigned long)stack+THREAD_SIZE)
18908 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18909 return 0;
18910 ip = *(u64 *)(fp+8);
18911 if (!in_sched_functions(ip))
18912 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18913 index 974b67e..561fcd7 100644
18914 --- a/arch/x86/kernel/ptrace.c
18915 +++ b/arch/x86/kernel/ptrace.c
18916 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
18917 {
18918 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
18919 unsigned long sp = (unsigned long)&regs->sp;
18920 - struct thread_info *tinfo;
18921
18922 - if (context == (sp & ~(THREAD_SIZE - 1)))
18923 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
18924 return sp;
18925
18926 - tinfo = (struct thread_info *)context;
18927 - if (tinfo->previous_esp)
18928 - return tinfo->previous_esp;
18929 + sp = *(unsigned long *)context;
18930 + if (sp)
18931 + return sp;
18932
18933 return (unsigned long)regs;
18934 }
18935 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
18936 unsigned long addr, unsigned long data)
18937 {
18938 int ret;
18939 - unsigned long __user *datap = (unsigned long __user *)data;
18940 + unsigned long __user *datap = (__force unsigned long __user *)data;
18941
18942 switch (request) {
18943 /* read the word at location addr in the USER area. */
18944 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
18945 if ((int) addr < 0)
18946 return -EIO;
18947 ret = do_get_thread_area(child, addr,
18948 - (struct user_desc __user *)data);
18949 + (__force struct user_desc __user *) data);
18950 break;
18951
18952 case PTRACE_SET_THREAD_AREA:
18953 if ((int) addr < 0)
18954 return -EIO;
18955 ret = do_set_thread_area(child, addr,
18956 - (struct user_desc __user *)data, 0);
18957 + (__force struct user_desc __user *) data, 0);
18958 break;
18959 #endif
18960
18961 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18962 memset(info, 0, sizeof(*info));
18963 info->si_signo = SIGTRAP;
18964 info->si_code = si_code;
18965 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18966 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18967 }
18968
18969 void user_single_step_siginfo(struct task_struct *tsk,
18970 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18971 # define IS_IA32 0
18972 #endif
18973
18974 +#ifdef CONFIG_GRKERNSEC_SETXID
18975 +extern void gr_delayed_cred_worker(void);
18976 +#endif
18977 +
18978 /*
18979 * We must return the syscall number to actually look up in the table.
18980 * This can be -1L to skip running any syscall at all.
18981 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18982
18983 rcu_user_exit();
18984
18985 +#ifdef CONFIG_GRKERNSEC_SETXID
18986 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18987 + gr_delayed_cred_worker();
18988 +#endif
18989 +
18990 /*
18991 * If we stepped into a sysenter/syscall insn, it trapped in
18992 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18993 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18994 */
18995 rcu_user_exit();
18996
18997 +#ifdef CONFIG_GRKERNSEC_SETXID
18998 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18999 + gr_delayed_cred_worker();
19000 +#endif
19001 +
19002 audit_syscall_exit(regs);
19003
19004 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
19005 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
19006 index 42eb330..139955c 100644
19007 --- a/arch/x86/kernel/pvclock.c
19008 +++ b/arch/x86/kernel/pvclock.c
19009 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
19010 return pv_tsc_khz;
19011 }
19012
19013 -static atomic64_t last_value = ATOMIC64_INIT(0);
19014 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
19015
19016 void pvclock_resume(void)
19017 {
19018 - atomic64_set(&last_value, 0);
19019 + atomic64_set_unchecked(&last_value, 0);
19020 }
19021
19022 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19023 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19024 * updating at the same time, and one of them could be slightly behind,
19025 * making the assumption that last_value always go forward fail to hold.
19026 */
19027 - last = atomic64_read(&last_value);
19028 + last = atomic64_read_unchecked(&last_value);
19029 do {
19030 if (ret < last)
19031 return last;
19032 - last = atomic64_cmpxchg(&last_value, last, ret);
19033 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
19034 } while (unlikely(last != ret));
19035
19036 return ret;
19037 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
19038 index 4e8ba39..e0186b3 100644
19039 --- a/arch/x86/kernel/reboot.c
19040 +++ b/arch/x86/kernel/reboot.c
19041 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
19042 EXPORT_SYMBOL(pm_power_off);
19043
19044 static const struct desc_ptr no_idt = {};
19045 -static int reboot_mode;
19046 +static unsigned short reboot_mode;
19047 enum reboot_type reboot_type = BOOT_ACPI;
19048 int reboot_force;
19049
19050 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
19051
19052 void __noreturn machine_real_restart(unsigned int type)
19053 {
19054 +
19055 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19056 + struct desc_struct *gdt;
19057 +#endif
19058 +
19059 local_irq_disable();
19060
19061 /*
19062 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
19063
19064 /* Jump to the identity-mapped low memory code */
19065 #ifdef CONFIG_X86_32
19066 - asm volatile("jmpl *%0" : :
19067 +
19068 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
19069 + gdt = get_cpu_gdt_table(smp_processor_id());
19070 + pax_open_kernel();
19071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19072 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
19073 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
19074 + loadsegment(ds, __KERNEL_DS);
19075 + loadsegment(es, __KERNEL_DS);
19076 + loadsegment(ss, __KERNEL_DS);
19077 +#endif
19078 +#ifdef CONFIG_PAX_KERNEXEC
19079 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
19080 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
19081 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
19082 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
19083 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
19084 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
19085 +#endif
19086 + pax_close_kernel();
19087 +#endif
19088 +
19089 + asm volatile("ljmpl *%0" : :
19090 "rm" (real_mode_header->machine_real_restart_asm),
19091 "a" (type));
19092 #else
19093 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19094 * try to force a triple fault and then cycle between hitting the keyboard
19095 * controller and doing that
19096 */
19097 -static void native_machine_emergency_restart(void)
19098 +static void __noreturn native_machine_emergency_restart(void)
19099 {
19100 int i;
19101 int attempt = 0;
19102 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
19103 #endif
19104 }
19105
19106 -static void __machine_emergency_restart(int emergency)
19107 +static void __noreturn __machine_emergency_restart(int emergency)
19108 {
19109 reboot_emergency = emergency;
19110 machine_ops.emergency_restart();
19111 }
19112
19113 -static void native_machine_restart(char *__unused)
19114 +static void __noreturn native_machine_restart(char *__unused)
19115 {
19116 pr_notice("machine restart\n");
19117
19118 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
19119 __machine_emergency_restart(0);
19120 }
19121
19122 -static void native_machine_halt(void)
19123 +static void __noreturn native_machine_halt(void)
19124 {
19125 /* Stop other cpus and apics */
19126 machine_shutdown();
19127 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
19128 stop_this_cpu(NULL);
19129 }
19130
19131 -static void native_machine_power_off(void)
19132 +static void __noreturn native_machine_power_off(void)
19133 {
19134 if (pm_power_off) {
19135 if (!reboot_force)
19136 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
19137 }
19138 /* A fallback in case there is no PM info available */
19139 tboot_shutdown(TB_SHUTDOWN_HALT);
19140 + unreachable();
19141 }
19142
19143 struct machine_ops machine_ops = {
19144 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19145 index 7a6f3b3..bed145d7 100644
19146 --- a/arch/x86/kernel/relocate_kernel_64.S
19147 +++ b/arch/x86/kernel/relocate_kernel_64.S
19148 @@ -11,6 +11,7 @@
19149 #include <asm/kexec.h>
19150 #include <asm/processor-flags.h>
19151 #include <asm/pgtable_types.h>
19152 +#include <asm/alternative-asm.h>
19153
19154 /*
19155 * Must be relocatable PIC code callable as a C function
19156 @@ -160,13 +161,14 @@ identity_mapped:
19157 xorq %rbp, %rbp
19158 xorq %r8, %r8
19159 xorq %r9, %r9
19160 - xorq %r10, %r9
19161 + xorq %r10, %r10
19162 xorq %r11, %r11
19163 xorq %r12, %r12
19164 xorq %r13, %r13
19165 xorq %r14, %r14
19166 xorq %r15, %r15
19167
19168 + pax_force_retaddr 0, 1
19169 ret
19170
19171 1:
19172 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19173 index ca45696..6384a09 100644
19174 --- a/arch/x86/kernel/setup.c
19175 +++ b/arch/x86/kernel/setup.c
19176 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
19177
19178 switch (data->type) {
19179 case SETUP_E820_EXT:
19180 - parse_e820_ext(data);
19181 + parse_e820_ext((struct setup_data __force_kernel *)data);
19182 break;
19183 case SETUP_DTB:
19184 add_dtb(pa_data);
19185 @@ -633,7 +633,7 @@ static void __init trim_bios_range(void)
19186 * area (640->1Mb) as ram even though it is not.
19187 * take them out.
19188 */
19189 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19190 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19191 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19192 }
19193
19194 @@ -756,14 +756,14 @@ void __init setup_arch(char **cmdline_p)
19195
19196 if (!boot_params.hdr.root_flags)
19197 root_mountflags &= ~MS_RDONLY;
19198 - init_mm.start_code = (unsigned long) _text;
19199 - init_mm.end_code = (unsigned long) _etext;
19200 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19201 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19202 init_mm.end_data = (unsigned long) _edata;
19203 init_mm.brk = _brk_end;
19204
19205 - code_resource.start = virt_to_phys(_text);
19206 - code_resource.end = virt_to_phys(_etext)-1;
19207 - data_resource.start = virt_to_phys(_etext);
19208 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19209 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19210 + data_resource.start = virt_to_phys(_sdata);
19211 data_resource.end = virt_to_phys(_edata)-1;
19212 bss_resource.start = virt_to_phys(&__bss_start);
19213 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19214 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19215 index 5cdff03..5810740 100644
19216 --- a/arch/x86/kernel/setup_percpu.c
19217 +++ b/arch/x86/kernel/setup_percpu.c
19218 @@ -21,19 +21,17 @@
19219 #include <asm/cpu.h>
19220 #include <asm/stackprotector.h>
19221
19222 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19223 +#ifdef CONFIG_SMP
19224 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19225 EXPORT_PER_CPU_SYMBOL(cpu_number);
19226 +#endif
19227
19228 -#ifdef CONFIG_X86_64
19229 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19230 -#else
19231 -#define BOOT_PERCPU_OFFSET 0
19232 -#endif
19233
19234 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19235 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19236
19237 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19238 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19239 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19240 };
19241 EXPORT_SYMBOL(__per_cpu_offset);
19242 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19243 {
19244 #ifdef CONFIG_X86_32
19245 struct desc_struct gdt;
19246 + unsigned long base = per_cpu_offset(cpu);
19247
19248 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19249 - 0x2 | DESCTYPE_S, 0x8);
19250 - gdt.s = 1;
19251 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19252 + 0x83 | DESCTYPE_S, 0xC);
19253 write_gdt_entry(get_cpu_gdt_table(cpu),
19254 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19255 #endif
19256 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19257 /* alrighty, percpu areas up and running */
19258 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19259 for_each_possible_cpu(cpu) {
19260 +#ifdef CONFIG_CC_STACKPROTECTOR
19261 +#ifdef CONFIG_X86_32
19262 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19263 +#endif
19264 +#endif
19265 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19266 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19267 per_cpu(cpu_number, cpu) = cpu;
19268 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19269 */
19270 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19271 #endif
19272 +#ifdef CONFIG_CC_STACKPROTECTOR
19273 +#ifdef CONFIG_X86_32
19274 + if (!cpu)
19275 + per_cpu(stack_canary.canary, cpu) = canary;
19276 +#endif
19277 +#endif
19278 /*
19279 * Up to this point, the boot CPU has been using .init.data
19280 * area. Reload any changed state for the boot CPU.
19281 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19282 index 70b27ee..fcf827f 100644
19283 --- a/arch/x86/kernel/signal.c
19284 +++ b/arch/x86/kernel/signal.c
19285 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
19286 * Align the stack pointer according to the i386 ABI,
19287 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19288 */
19289 - sp = ((sp + 4) & -16ul) - 4;
19290 + sp = ((sp - 12) & -16ul) - 4;
19291 #else /* !CONFIG_X86_32 */
19292 sp = round_down(sp, 16) - 8;
19293 #endif
19294 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19295 }
19296
19297 if (current->mm->context.vdso)
19298 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19299 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19300 else
19301 - restorer = &frame->retcode;
19302 + restorer = (void __user *)&frame->retcode;
19303 if (ka->sa.sa_flags & SA_RESTORER)
19304 restorer = ka->sa.sa_restorer;
19305
19306 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19307 * reasons and because gdb uses it as a signature to notice
19308 * signal handler stack frames.
19309 */
19310 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19311 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19312
19313 if (err)
19314 return -EFAULT;
19315 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19316 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
19317
19318 /* Set up to return from userspace. */
19319 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19320 + if (current->mm->context.vdso)
19321 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19322 + else
19323 + restorer = (void __user *)&frame->retcode;
19324 if (ka->sa.sa_flags & SA_RESTORER)
19325 restorer = ka->sa.sa_restorer;
19326 put_user_ex(restorer, &frame->pretcode);
19327 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19328 * reasons and because gdb uses it as a signature to notice
19329 * signal handler stack frames.
19330 */
19331 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19332 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19333 } put_user_catch(err);
19334
19335 err |= copy_siginfo_to_user(&frame->info, info);
19336 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19337 index f3e2ec8..ad5287a 100644
19338 --- a/arch/x86/kernel/smpboot.c
19339 +++ b/arch/x86/kernel/smpboot.c
19340 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19341 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19342 (THREAD_SIZE + task_stack_page(idle))) - 1);
19343 per_cpu(current_task, cpu) = idle;
19344 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19345
19346 #ifdef CONFIG_X86_32
19347 /* Stack for startup_32 can be just as for start_secondary onwards */
19348 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19349 #else
19350 clear_tsk_thread_flag(idle, TIF_FORK);
19351 initial_gs = per_cpu_offset(cpu);
19352 - per_cpu(kernel_stack, cpu) =
19353 - (unsigned long)task_stack_page(idle) -
19354 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19355 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19356 #endif
19357 +
19358 + pax_open_kernel();
19359 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19360 + pax_close_kernel();
19361 +
19362 initial_code = (unsigned long)start_secondary;
19363 stack_start = idle->thread.sp;
19364
19365 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19366 /* the FPU context is blank, nobody can own it */
19367 __cpu_disable_lazy_restore(cpu);
19368
19369 +#ifdef CONFIG_PAX_PER_CPU_PGD
19370 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19371 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19372 + KERNEL_PGD_PTRS);
19373 +#endif
19374 +
19375 + /* the FPU context is blank, nobody can own it */
19376 + __cpu_disable_lazy_restore(cpu);
19377 +
19378 err = do_boot_cpu(apicid, cpu, tidle);
19379 if (err) {
19380 pr_debug("do_boot_cpu failed %d\n", err);
19381 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19382 index cd3b243..4ba27a4 100644
19383 --- a/arch/x86/kernel/step.c
19384 +++ b/arch/x86/kernel/step.c
19385 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19386 struct desc_struct *desc;
19387 unsigned long base;
19388
19389 - seg &= ~7UL;
19390 + seg >>= 3;
19391
19392 mutex_lock(&child->mm->context.lock);
19393 - if (unlikely((seg >> 3) >= child->mm->context.size))
19394 + if (unlikely(seg >= child->mm->context.size))
19395 addr = -1L; /* bogus selector, access would fault */
19396 else {
19397 desc = child->mm->context.ldt + seg;
19398 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19399 addr += base;
19400 }
19401 mutex_unlock(&child->mm->context.lock);
19402 - }
19403 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19404 + addr = ktla_ktva(addr);
19405
19406 return addr;
19407 }
19408 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19409 unsigned char opcode[15];
19410 unsigned long addr = convert_ip_to_linear(child, regs);
19411
19412 + if (addr == -EINVAL)
19413 + return 0;
19414 +
19415 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19416 for (i = 0; i < copied; i++) {
19417 switch (opcode[i]) {
19418 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19419 new file mode 100644
19420 index 0000000..db6b9ed
19421 --- /dev/null
19422 +++ b/arch/x86/kernel/sys_i386_32.c
19423 @@ -0,0 +1,247 @@
19424 +/*
19425 + * This file contains various random system calls that
19426 + * have a non-standard calling sequence on the Linux/i386
19427 + * platform.
19428 + */
19429 +
19430 +#include <linux/errno.h>
19431 +#include <linux/sched.h>
19432 +#include <linux/mm.h>
19433 +#include <linux/fs.h>
19434 +#include <linux/smp.h>
19435 +#include <linux/sem.h>
19436 +#include <linux/msg.h>
19437 +#include <linux/shm.h>
19438 +#include <linux/stat.h>
19439 +#include <linux/syscalls.h>
19440 +#include <linux/mman.h>
19441 +#include <linux/file.h>
19442 +#include <linux/utsname.h>
19443 +#include <linux/ipc.h>
19444 +
19445 +#include <linux/uaccess.h>
19446 +#include <linux/unistd.h>
19447 +
19448 +#include <asm/syscalls.h>
19449 +
19450 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19451 +{
19452 + unsigned long pax_task_size = TASK_SIZE;
19453 +
19454 +#ifdef CONFIG_PAX_SEGMEXEC
19455 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19456 + pax_task_size = SEGMEXEC_TASK_SIZE;
19457 +#endif
19458 +
19459 + if (len > pax_task_size || addr > pax_task_size - len)
19460 + return -EINVAL;
19461 +
19462 + return 0;
19463 +}
19464 +
19465 +unsigned long
19466 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19467 + unsigned long len, unsigned long pgoff, unsigned long flags)
19468 +{
19469 + struct mm_struct *mm = current->mm;
19470 + struct vm_area_struct *vma;
19471 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19472 +
19473 +#ifdef CONFIG_PAX_SEGMEXEC
19474 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19475 + pax_task_size = SEGMEXEC_TASK_SIZE;
19476 +#endif
19477 +
19478 + pax_task_size -= PAGE_SIZE;
19479 +
19480 + if (len > pax_task_size)
19481 + return -ENOMEM;
19482 +
19483 + if (flags & MAP_FIXED)
19484 + return addr;
19485 +
19486 +#ifdef CONFIG_PAX_RANDMMAP
19487 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19488 +#endif
19489 +
19490 + if (addr) {
19491 + addr = PAGE_ALIGN(addr);
19492 + if (pax_task_size - len >= addr) {
19493 + vma = find_vma(mm, addr);
19494 + if (check_heap_stack_gap(vma, addr, len))
19495 + return addr;
19496 + }
19497 + }
19498 + if (len > mm->cached_hole_size) {
19499 + start_addr = addr = mm->free_area_cache;
19500 + } else {
19501 + start_addr = addr = mm->mmap_base;
19502 + mm->cached_hole_size = 0;
19503 + }
19504 +
19505 +#ifdef CONFIG_PAX_PAGEEXEC
19506 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19507 + start_addr = 0x00110000UL;
19508 +
19509 +#ifdef CONFIG_PAX_RANDMMAP
19510 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19511 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19512 +#endif
19513 +
19514 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19515 + start_addr = addr = mm->mmap_base;
19516 + else
19517 + addr = start_addr;
19518 + }
19519 +#endif
19520 +
19521 +full_search:
19522 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19523 + /* At this point: (!vma || addr < vma->vm_end). */
19524 + if (pax_task_size - len < addr) {
19525 + /*
19526 + * Start a new search - just in case we missed
19527 + * some holes.
19528 + */
19529 + if (start_addr != mm->mmap_base) {
19530 + start_addr = addr = mm->mmap_base;
19531 + mm->cached_hole_size = 0;
19532 + goto full_search;
19533 + }
19534 + return -ENOMEM;
19535 + }
19536 + if (check_heap_stack_gap(vma, addr, len))
19537 + break;
19538 + if (addr + mm->cached_hole_size < vma->vm_start)
19539 + mm->cached_hole_size = vma->vm_start - addr;
19540 + addr = vma->vm_end;
19541 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19542 + start_addr = addr = mm->mmap_base;
19543 + mm->cached_hole_size = 0;
19544 + goto full_search;
19545 + }
19546 + }
19547 +
19548 + /*
19549 + * Remember the place where we stopped the search:
19550 + */
19551 + mm->free_area_cache = addr + len;
19552 + return addr;
19553 +}
19554 +
19555 +unsigned long
19556 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19557 + const unsigned long len, const unsigned long pgoff,
19558 + const unsigned long flags)
19559 +{
19560 + struct vm_area_struct *vma;
19561 + struct mm_struct *mm = current->mm;
19562 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19563 +
19564 +#ifdef CONFIG_PAX_SEGMEXEC
19565 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19566 + pax_task_size = SEGMEXEC_TASK_SIZE;
19567 +#endif
19568 +
19569 + pax_task_size -= PAGE_SIZE;
19570 +
19571 + /* requested length too big for entire address space */
19572 + if (len > pax_task_size)
19573 + return -ENOMEM;
19574 +
19575 + if (flags & MAP_FIXED)
19576 + return addr;
19577 +
19578 +#ifdef CONFIG_PAX_PAGEEXEC
19579 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19580 + goto bottomup;
19581 +#endif
19582 +
19583 +#ifdef CONFIG_PAX_RANDMMAP
19584 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19585 +#endif
19586 +
19587 + /* requesting a specific address */
19588 + if (addr) {
19589 + addr = PAGE_ALIGN(addr);
19590 + if (pax_task_size - len >= addr) {
19591 + vma = find_vma(mm, addr);
19592 + if (check_heap_stack_gap(vma, addr, len))
19593 + return addr;
19594 + }
19595 + }
19596 +
19597 + /* check if free_area_cache is useful for us */
19598 + if (len <= mm->cached_hole_size) {
19599 + mm->cached_hole_size = 0;
19600 + mm->free_area_cache = mm->mmap_base;
19601 + }
19602 +
19603 + /* either no address requested or can't fit in requested address hole */
19604 + addr = mm->free_area_cache;
19605 +
19606 + /* make sure it can fit in the remaining address space */
19607 + if (addr > len) {
19608 + vma = find_vma(mm, addr-len);
19609 + if (check_heap_stack_gap(vma, addr - len, len))
19610 + /* remember the address as a hint for next time */
19611 + return (mm->free_area_cache = addr-len);
19612 + }
19613 +
19614 + if (mm->mmap_base < len)
19615 + goto bottomup;
19616 +
19617 + addr = mm->mmap_base-len;
19618 +
19619 + do {
19620 + /*
19621 + * Lookup failure means no vma is above this address,
19622 + * else if new region fits below vma->vm_start,
19623 + * return with success:
19624 + */
19625 + vma = find_vma(mm, addr);
19626 + if (check_heap_stack_gap(vma, addr, len))
19627 + /* remember the address as a hint for next time */
19628 + return (mm->free_area_cache = addr);
19629 +
19630 + /* remember the largest hole we saw so far */
19631 + if (addr + mm->cached_hole_size < vma->vm_start)
19632 + mm->cached_hole_size = vma->vm_start - addr;
19633 +
19634 + /* try just below the current vma->vm_start */
19635 + addr = skip_heap_stack_gap(vma, len);
19636 + } while (!IS_ERR_VALUE(addr));
19637 +
19638 +bottomup:
19639 + /*
19640 + * A failed mmap() very likely causes application failure,
19641 + * so fall back to the bottom-up function here. This scenario
19642 + * can happen with large stack limits and large mmap()
19643 + * allocations.
19644 + */
19645 +
19646 +#ifdef CONFIG_PAX_SEGMEXEC
19647 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19648 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19649 + else
19650 +#endif
19651 +
19652 + mm->mmap_base = TASK_UNMAPPED_BASE;
19653 +
19654 +#ifdef CONFIG_PAX_RANDMMAP
19655 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19656 + mm->mmap_base += mm->delta_mmap;
19657 +#endif
19658 +
19659 + mm->free_area_cache = mm->mmap_base;
19660 + mm->cached_hole_size = ~0UL;
19661 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19662 + /*
19663 + * Restore the topdown base:
19664 + */
19665 + mm->mmap_base = base;
19666 + mm->free_area_cache = base;
19667 + mm->cached_hole_size = ~0UL;
19668 +
19669 + return addr;
19670 +}
19671 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19672 index b4d3c39..82bb73b 100644
19673 --- a/arch/x86/kernel/sys_x86_64.c
19674 +++ b/arch/x86/kernel/sys_x86_64.c
19675 @@ -95,8 +95,8 @@ out:
19676 return error;
19677 }
19678
19679 -static void find_start_end(unsigned long flags, unsigned long *begin,
19680 - unsigned long *end)
19681 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19682 + unsigned long *begin, unsigned long *end)
19683 {
19684 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19685 unsigned long new_begin;
19686 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19687 *begin = new_begin;
19688 }
19689 } else {
19690 - *begin = TASK_UNMAPPED_BASE;
19691 + *begin = mm->mmap_base;
19692 *end = TASK_SIZE;
19693 }
19694 }
19695 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19696 if (flags & MAP_FIXED)
19697 return addr;
19698
19699 - find_start_end(flags, &begin, &end);
19700 + find_start_end(mm, flags, &begin, &end);
19701
19702 if (len > end)
19703 return -ENOMEM;
19704
19705 +#ifdef CONFIG_PAX_RANDMMAP
19706 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19707 +#endif
19708 +
19709 if (addr) {
19710 addr = PAGE_ALIGN(addr);
19711 vma = find_vma(mm, addr);
19712 - if (end - len >= addr &&
19713 - (!vma || addr + len <= vma->vm_start))
19714 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19715 return addr;
19716 }
19717 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19718 @@ -172,7 +175,7 @@ full_search:
19719 }
19720 return -ENOMEM;
19721 }
19722 - if (!vma || addr + len <= vma->vm_start) {
19723 + if (check_heap_stack_gap(vma, addr, len)) {
19724 /*
19725 * Remember the place where we stopped the search:
19726 */
19727 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19728 {
19729 struct vm_area_struct *vma;
19730 struct mm_struct *mm = current->mm;
19731 - unsigned long addr = addr0, start_addr;
19732 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19733
19734 /* requested length too big for entire address space */
19735 if (len > TASK_SIZE)
19736 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19737 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19738 goto bottomup;
19739
19740 +#ifdef CONFIG_PAX_RANDMMAP
19741 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19742 +#endif
19743 +
19744 /* requesting a specific address */
19745 if (addr) {
19746 addr = PAGE_ALIGN(addr);
19747 - vma = find_vma(mm, addr);
19748 - if (TASK_SIZE - len >= addr &&
19749 - (!vma || addr + len <= vma->vm_start))
19750 - return addr;
19751 + if (TASK_SIZE - len >= addr) {
19752 + vma = find_vma(mm, addr);
19753 + if (check_heap_stack_gap(vma, addr, len))
19754 + return addr;
19755 + }
19756 }
19757
19758 /* check if free_area_cache is useful for us */
19759 @@ -240,7 +248,7 @@ try_again:
19760 * return with success:
19761 */
19762 vma = find_vma(mm, addr);
19763 - if (!vma || addr+len <= vma->vm_start)
19764 + if (check_heap_stack_gap(vma, addr, len))
19765 /* remember the address as a hint for next time */
19766 return mm->free_area_cache = addr;
19767
19768 @@ -249,8 +257,8 @@ try_again:
19769 mm->cached_hole_size = vma->vm_start - addr;
19770
19771 /* try just below the current vma->vm_start */
19772 - addr = vma->vm_start-len;
19773 - } while (len < vma->vm_start);
19774 + addr = skip_heap_stack_gap(vma, len);
19775 + } while (!IS_ERR_VALUE(addr));
19776
19777 fail:
19778 /*
19779 @@ -270,13 +278,21 @@ bottomup:
19780 * can happen with large stack limits and large mmap()
19781 * allocations.
19782 */
19783 + mm->mmap_base = TASK_UNMAPPED_BASE;
19784 +
19785 +#ifdef CONFIG_PAX_RANDMMAP
19786 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19787 + mm->mmap_base += mm->delta_mmap;
19788 +#endif
19789 +
19790 + mm->free_area_cache = mm->mmap_base;
19791 mm->cached_hole_size = ~0UL;
19792 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19793 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19794 /*
19795 * Restore the topdown base:
19796 */
19797 - mm->free_area_cache = mm->mmap_base;
19798 + mm->mmap_base = base;
19799 + mm->free_area_cache = base;
19800 mm->cached_hole_size = ~0UL;
19801
19802 return addr;
19803 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19804 index f84fe00..93fe08f 100644
19805 --- a/arch/x86/kernel/tboot.c
19806 +++ b/arch/x86/kernel/tboot.c
19807 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19808
19809 void tboot_shutdown(u32 shutdown_type)
19810 {
19811 - void (*shutdown)(void);
19812 + void (* __noreturn shutdown)(void);
19813
19814 if (!tboot_enabled())
19815 return;
19816 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19817
19818 switch_to_tboot_pt();
19819
19820 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19821 + shutdown = (void *)tboot->shutdown_entry;
19822 shutdown();
19823
19824 /* should not reach here */
19825 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19826 return 0;
19827 }
19828
19829 -static atomic_t ap_wfs_count;
19830 +static atomic_unchecked_t ap_wfs_count;
19831
19832 static int tboot_wait_for_aps(int num_aps)
19833 {
19834 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19835 {
19836 switch (action) {
19837 case CPU_DYING:
19838 - atomic_inc(&ap_wfs_count);
19839 + atomic_inc_unchecked(&ap_wfs_count);
19840 if (num_online_cpus() == 1)
19841 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19842 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19843 return NOTIFY_BAD;
19844 break;
19845 }
19846 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19847
19848 tboot_create_trampoline();
19849
19850 - atomic_set(&ap_wfs_count, 0);
19851 + atomic_set_unchecked(&ap_wfs_count, 0);
19852 register_hotcpu_notifier(&tboot_cpu_notifier);
19853
19854 acpi_os_set_prepare_sleep(&tboot_sleep);
19855 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19856 index 24d3c91..d06b473 100644
19857 --- a/arch/x86/kernel/time.c
19858 +++ b/arch/x86/kernel/time.c
19859 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19860 {
19861 unsigned long pc = instruction_pointer(regs);
19862
19863 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19864 + if (!user_mode(regs) && in_lock_functions(pc)) {
19865 #ifdef CONFIG_FRAME_POINTER
19866 - return *(unsigned long *)(regs->bp + sizeof(long));
19867 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19868 #else
19869 unsigned long *sp =
19870 (unsigned long *)kernel_stack_pointer(regs);
19871 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19872 * or above a saved flags. Eflags has bits 22-31 zero,
19873 * kernel addresses don't.
19874 */
19875 +
19876 +#ifdef CONFIG_PAX_KERNEXEC
19877 + return ktla_ktva(sp[0]);
19878 +#else
19879 if (sp[0] >> 22)
19880 return sp[0];
19881 if (sp[1] >> 22)
19882 return sp[1];
19883 #endif
19884 +
19885 +#endif
19886 }
19887 return pc;
19888 }
19889 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19890 index 9d9d2f9..cad418a 100644
19891 --- a/arch/x86/kernel/tls.c
19892 +++ b/arch/x86/kernel/tls.c
19893 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19894 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19895 return -EINVAL;
19896
19897 +#ifdef CONFIG_PAX_SEGMEXEC
19898 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19899 + return -EINVAL;
19900 +#endif
19901 +
19902 set_tls_desc(p, idx, &info, 1);
19903
19904 return 0;
19905 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19906
19907 if (kbuf)
19908 info = kbuf;
19909 - else if (__copy_from_user(infobuf, ubuf, count))
19910 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19911 return -EFAULT;
19912 else
19913 info = infobuf;
19914 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19915 index 8276dc6..4ca48a2 100644
19916 --- a/arch/x86/kernel/traps.c
19917 +++ b/arch/x86/kernel/traps.c
19918 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
19919
19920 /* Do we ignore FPU interrupts ? */
19921 char ignore_fpu_irq;
19922 -
19923 -/*
19924 - * The IDT has to be page-aligned to simplify the Pentium
19925 - * F0 0F bug workaround.
19926 - */
19927 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19928 #endif
19929
19930 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19931 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19932 }
19933
19934 static int __kprobes
19935 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
19936 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
19937 struct pt_regs *regs, long error_code)
19938 {
19939 #ifdef CONFIG_X86_32
19940 - if (regs->flags & X86_VM_MASK) {
19941 + if (v8086_mode(regs)) {
19942 /*
19943 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19944 * On nmi (interrupt 2), do_trap should not be called.
19945 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
19946 return -1;
19947 }
19948 #endif
19949 - if (!user_mode(regs)) {
19950 + if (!user_mode_novm(regs)) {
19951 if (!fixup_exception(regs)) {
19952 tsk->thread.error_code = error_code;
19953 tsk->thread.trap_nr = trapnr;
19954 +
19955 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19956 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19957 + str = "PAX: suspicious stack segment fault";
19958 +#endif
19959 +
19960 die(str, regs, error_code);
19961 }
19962 +
19963 +#ifdef CONFIG_PAX_REFCOUNT
19964 + if (trapnr == 4)
19965 + pax_report_refcount_overflow(regs);
19966 +#endif
19967 +
19968 return 0;
19969 }
19970
19971 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
19972 }
19973
19974 static void __kprobes
19975 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19976 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19977 long error_code, siginfo_t *info)
19978 {
19979 struct task_struct *tsk = current;
19980 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19981 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19982 printk_ratelimit()) {
19983 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19984 - tsk->comm, tsk->pid, str,
19985 + tsk->comm, task_pid_nr(tsk), str,
19986 regs->ip, regs->sp, error_code);
19987 print_vma_addr(" in ", regs->ip);
19988 pr_cont("\n");
19989 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
19990 conditional_sti(regs);
19991
19992 #ifdef CONFIG_X86_32
19993 - if (regs->flags & X86_VM_MASK) {
19994 + if (v8086_mode(regs)) {
19995 local_irq_enable();
19996 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
19997 goto exit;
19998 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
19999 #endif
20000
20001 tsk = current;
20002 - if (!user_mode(regs)) {
20003 + if (!user_mode_novm(regs)) {
20004 if (fixup_exception(regs))
20005 goto exit;
20006
20007 tsk->thread.error_code = error_code;
20008 tsk->thread.trap_nr = X86_TRAP_GP;
20009 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
20010 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
20011 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
20012 +
20013 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20014 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20015 + die("PAX: suspicious general protection fault", regs, error_code);
20016 + else
20017 +#endif
20018 +
20019 die("general protection fault", regs, error_code);
20020 + }
20021 goto exit;
20022 }
20023
20024 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20025 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20026 + struct mm_struct *mm = tsk->mm;
20027 + unsigned long limit;
20028 +
20029 + down_write(&mm->mmap_sem);
20030 + limit = mm->context.user_cs_limit;
20031 + if (limit < TASK_SIZE) {
20032 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20033 + up_write(&mm->mmap_sem);
20034 + return;
20035 + }
20036 + up_write(&mm->mmap_sem);
20037 + }
20038 +#endif
20039 +
20040 tsk->thread.error_code = error_code;
20041 tsk->thread.trap_nr = X86_TRAP_GP;
20042
20043 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20044 /* It's safe to allow irq's after DR6 has been saved */
20045 preempt_conditional_sti(regs);
20046
20047 - if (regs->flags & X86_VM_MASK) {
20048 + if (v8086_mode(regs)) {
20049 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
20050 X86_TRAP_DB);
20051 preempt_conditional_cli(regs);
20052 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20053 * We already checked v86 mode above, so we can check for kernel mode
20054 * by just checking the CPL of CS.
20055 */
20056 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
20057 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
20058 tsk->thread.debugreg6 &= ~DR_STEP;
20059 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20060 regs->flags &= ~X86_EFLAGS_TF;
20061 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
20062 return;
20063 conditional_sti(regs);
20064
20065 - if (!user_mode_vm(regs))
20066 + if (!user_mode(regs))
20067 {
20068 if (!fixup_exception(regs)) {
20069 task->thread.error_code = error_code;
20070 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
20071 index aafa555..a04691a 100644
20072 --- a/arch/x86/kernel/uprobes.c
20073 +++ b/arch/x86/kernel/uprobes.c
20074 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
20075 int ret = NOTIFY_DONE;
20076
20077 /* We are only interested in userspace traps */
20078 - if (regs && !user_mode_vm(regs))
20079 + if (regs && !user_mode(regs))
20080 return NOTIFY_DONE;
20081
20082 switch (val) {
20083 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20084 index b9242ba..50c5edd 100644
20085 --- a/arch/x86/kernel/verify_cpu.S
20086 +++ b/arch/x86/kernel/verify_cpu.S
20087 @@ -20,6 +20,7 @@
20088 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20089 * arch/x86/kernel/trampoline_64.S: secondary processor verification
20090 * arch/x86/kernel/head_32.S: processor startup
20091 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20092 *
20093 * verify_cpu, returns the status of longmode and SSE in register %eax.
20094 * 0: Success 1: Failure
20095 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20096 index 5c9687b..5f857d3 100644
20097 --- a/arch/x86/kernel/vm86_32.c
20098 +++ b/arch/x86/kernel/vm86_32.c
20099 @@ -43,6 +43,7 @@
20100 #include <linux/ptrace.h>
20101 #include <linux/audit.h>
20102 #include <linux/stddef.h>
20103 +#include <linux/grsecurity.h>
20104
20105 #include <asm/uaccess.h>
20106 #include <asm/io.h>
20107 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20108 do_exit(SIGSEGV);
20109 }
20110
20111 - tss = &per_cpu(init_tss, get_cpu());
20112 + tss = init_tss + get_cpu();
20113 current->thread.sp0 = current->thread.saved_sp0;
20114 current->thread.sysenter_cs = __KERNEL_CS;
20115 load_sp0(tss, &current->thread);
20116 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20117 struct task_struct *tsk;
20118 int tmp, ret = -EPERM;
20119
20120 +#ifdef CONFIG_GRKERNSEC_VM86
20121 + if (!capable(CAP_SYS_RAWIO)) {
20122 + gr_handle_vm86();
20123 + goto out;
20124 + }
20125 +#endif
20126 +
20127 tsk = current;
20128 if (tsk->thread.saved_sp0)
20129 goto out;
20130 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20131 int tmp, ret;
20132 struct vm86plus_struct __user *v86;
20133
20134 +#ifdef CONFIG_GRKERNSEC_VM86
20135 + if (!capable(CAP_SYS_RAWIO)) {
20136 + gr_handle_vm86();
20137 + ret = -EPERM;
20138 + goto out;
20139 + }
20140 +#endif
20141 +
20142 tsk = current;
20143 switch (cmd) {
20144 case VM86_REQUEST_IRQ:
20145 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20146 tsk->thread.saved_fs = info->regs32->fs;
20147 tsk->thread.saved_gs = get_user_gs(info->regs32);
20148
20149 - tss = &per_cpu(init_tss, get_cpu());
20150 + tss = init_tss + get_cpu();
20151 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20152 if (cpu_has_sep)
20153 tsk->thread.sysenter_cs = 0;
20154 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20155 goto cannot_handle;
20156 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20157 goto cannot_handle;
20158 - intr_ptr = (unsigned long __user *) (i << 2);
20159 + intr_ptr = (__force unsigned long __user *) (i << 2);
20160 if (get_user(segoffs, intr_ptr))
20161 goto cannot_handle;
20162 if ((segoffs >> 16) == BIOSSEG)
20163 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20164 index 22a1530..8fbaaad 100644
20165 --- a/arch/x86/kernel/vmlinux.lds.S
20166 +++ b/arch/x86/kernel/vmlinux.lds.S
20167 @@ -26,6 +26,13 @@
20168 #include <asm/page_types.h>
20169 #include <asm/cache.h>
20170 #include <asm/boot.h>
20171 +#include <asm/segment.h>
20172 +
20173 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20174 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20175 +#else
20176 +#define __KERNEL_TEXT_OFFSET 0
20177 +#endif
20178
20179 #undef i386 /* in case the preprocessor is a 32bit one */
20180
20181 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20182
20183 PHDRS {
20184 text PT_LOAD FLAGS(5); /* R_E */
20185 +#ifdef CONFIG_X86_32
20186 + module PT_LOAD FLAGS(5); /* R_E */
20187 +#endif
20188 +#ifdef CONFIG_XEN
20189 + rodata PT_LOAD FLAGS(5); /* R_E */
20190 +#else
20191 + rodata PT_LOAD FLAGS(4); /* R__ */
20192 +#endif
20193 data PT_LOAD FLAGS(6); /* RW_ */
20194 -#ifdef CONFIG_X86_64
20195 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20196 #ifdef CONFIG_SMP
20197 percpu PT_LOAD FLAGS(6); /* RW_ */
20198 #endif
20199 + text.init PT_LOAD FLAGS(5); /* R_E */
20200 + text.exit PT_LOAD FLAGS(5); /* R_E */
20201 init PT_LOAD FLAGS(7); /* RWE */
20202 -#endif
20203 note PT_NOTE FLAGS(0); /* ___ */
20204 }
20205
20206 SECTIONS
20207 {
20208 #ifdef CONFIG_X86_32
20209 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20210 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20211 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20212 #else
20213 - . = __START_KERNEL;
20214 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20215 + . = __START_KERNEL;
20216 #endif
20217
20218 /* Text and read-only data */
20219 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20220 - _text = .;
20221 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20222 /* bootstrapping code */
20223 +#ifdef CONFIG_X86_32
20224 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20225 +#else
20226 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20227 +#endif
20228 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20229 + _text = .;
20230 HEAD_TEXT
20231 #ifdef CONFIG_X86_32
20232 . = ALIGN(PAGE_SIZE);
20233 @@ -108,13 +128,48 @@ SECTIONS
20234 IRQENTRY_TEXT
20235 *(.fixup)
20236 *(.gnu.warning)
20237 - /* End of text section */
20238 - _etext = .;
20239 } :text = 0x9090
20240
20241 - NOTES :text :note
20242 + . += __KERNEL_TEXT_OFFSET;
20243
20244 - EXCEPTION_TABLE(16) :text = 0x9090
20245 +#ifdef CONFIG_X86_32
20246 + . = ALIGN(PAGE_SIZE);
20247 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20248 +
20249 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20250 + MODULES_EXEC_VADDR = .;
20251 + BYTE(0)
20252 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20253 + . = ALIGN(HPAGE_SIZE) - 1;
20254 + MODULES_EXEC_END = .;
20255 +#endif
20256 +
20257 + } :module
20258 +#endif
20259 +
20260 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20261 + /* End of text section */
20262 + BYTE(0)
20263 + _etext = . - __KERNEL_TEXT_OFFSET;
20264 + }
20265 +
20266 +#ifdef CONFIG_X86_32
20267 + . = ALIGN(PAGE_SIZE);
20268 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20269 + *(.idt)
20270 + . = ALIGN(PAGE_SIZE);
20271 + *(.empty_zero_page)
20272 + *(.initial_pg_fixmap)
20273 + *(.initial_pg_pmd)
20274 + *(.initial_page_table)
20275 + *(.swapper_pg_dir)
20276 + } :rodata
20277 +#endif
20278 +
20279 + . = ALIGN(PAGE_SIZE);
20280 + NOTES :rodata :note
20281 +
20282 + EXCEPTION_TABLE(16) :rodata
20283
20284 #if defined(CONFIG_DEBUG_RODATA)
20285 /* .text should occupy whole number of pages */
20286 @@ -126,16 +181,20 @@ SECTIONS
20287
20288 /* Data */
20289 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20290 +
20291 +#ifdef CONFIG_PAX_KERNEXEC
20292 + . = ALIGN(HPAGE_SIZE);
20293 +#else
20294 + . = ALIGN(PAGE_SIZE);
20295 +#endif
20296 +
20297 /* Start of data section */
20298 _sdata = .;
20299
20300 /* init_task */
20301 INIT_TASK_DATA(THREAD_SIZE)
20302
20303 -#ifdef CONFIG_X86_32
20304 - /* 32 bit has nosave before _edata */
20305 NOSAVE_DATA
20306 -#endif
20307
20308 PAGE_ALIGNED_DATA(PAGE_SIZE)
20309
20310 @@ -176,12 +235,19 @@ SECTIONS
20311 #endif /* CONFIG_X86_64 */
20312
20313 /* Init code and data - will be freed after init */
20314 - . = ALIGN(PAGE_SIZE);
20315 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20316 + BYTE(0)
20317 +
20318 +#ifdef CONFIG_PAX_KERNEXEC
20319 + . = ALIGN(HPAGE_SIZE);
20320 +#else
20321 + . = ALIGN(PAGE_SIZE);
20322 +#endif
20323 +
20324 __init_begin = .; /* paired with __init_end */
20325 - }
20326 + } :init.begin
20327
20328 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20329 +#ifdef CONFIG_SMP
20330 /*
20331 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20332 * output PHDR, so the next output section - .init.text - should
20333 @@ -190,12 +256,27 @@ SECTIONS
20334 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20335 #endif
20336
20337 - INIT_TEXT_SECTION(PAGE_SIZE)
20338 -#ifdef CONFIG_X86_64
20339 - :init
20340 -#endif
20341 + . = ALIGN(PAGE_SIZE);
20342 + init_begin = .;
20343 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20344 + VMLINUX_SYMBOL(_sinittext) = .;
20345 + INIT_TEXT
20346 + VMLINUX_SYMBOL(_einittext) = .;
20347 + . = ALIGN(PAGE_SIZE);
20348 + } :text.init
20349
20350 - INIT_DATA_SECTION(16)
20351 + /*
20352 + * .exit.text is discard at runtime, not link time, to deal with
20353 + * references from .altinstructions and .eh_frame
20354 + */
20355 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20356 + EXIT_TEXT
20357 + . = ALIGN(16);
20358 + } :text.exit
20359 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20360 +
20361 + . = ALIGN(PAGE_SIZE);
20362 + INIT_DATA_SECTION(16) :init
20363
20364 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20365 __x86_cpu_dev_start = .;
20366 @@ -257,19 +338,12 @@ SECTIONS
20367 }
20368
20369 . = ALIGN(8);
20370 - /*
20371 - * .exit.text is discard at runtime, not link time, to deal with
20372 - * references from .altinstructions and .eh_frame
20373 - */
20374 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20375 - EXIT_TEXT
20376 - }
20377
20378 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20379 EXIT_DATA
20380 }
20381
20382 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20383 +#ifndef CONFIG_SMP
20384 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20385 #endif
20386
20387 @@ -288,16 +362,10 @@ SECTIONS
20388 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20389 __smp_locks = .;
20390 *(.smp_locks)
20391 - . = ALIGN(PAGE_SIZE);
20392 __smp_locks_end = .;
20393 + . = ALIGN(PAGE_SIZE);
20394 }
20395
20396 -#ifdef CONFIG_X86_64
20397 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20398 - NOSAVE_DATA
20399 - }
20400 -#endif
20401 -
20402 /* BSS */
20403 . = ALIGN(PAGE_SIZE);
20404 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20405 @@ -313,6 +381,7 @@ SECTIONS
20406 __brk_base = .;
20407 . += 64 * 1024; /* 64k alignment slop space */
20408 *(.brk_reservation) /* areas brk users have reserved */
20409 + . = ALIGN(HPAGE_SIZE);
20410 __brk_limit = .;
20411 }
20412
20413 @@ -339,13 +408,12 @@ SECTIONS
20414 * for the boot processor.
20415 */
20416 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20417 -INIT_PER_CPU(gdt_page);
20418 INIT_PER_CPU(irq_stack_union);
20419
20420 /*
20421 * Build-time check on the image size:
20422 */
20423 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20424 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20425 "kernel image bigger than KERNEL_IMAGE_SIZE");
20426
20427 #ifdef CONFIG_SMP
20428 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20429 index 992f890..fc38904 100644
20430 --- a/arch/x86/kernel/vsmp_64.c
20431 +++ b/arch/x86/kernel/vsmp_64.c
20432 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20433 static void vsmp_apic_post_init(void)
20434 {
20435 /* need to update phys_pkg_id */
20436 - apic->phys_pkg_id = apicid_phys_pkg_id;
20437 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20438 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20439 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20440 }
20441
20442 void __init vsmp_init(void)
20443 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20444 index 3a3e8c9..1af9465 100644
20445 --- a/arch/x86/kernel/vsyscall_64.c
20446 +++ b/arch/x86/kernel/vsyscall_64.c
20447 @@ -56,15 +56,13 @@
20448 DEFINE_VVAR(int, vgetcpu_mode);
20449 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20450
20451 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20452 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20453
20454 static int __init vsyscall_setup(char *str)
20455 {
20456 if (str) {
20457 if (!strcmp("emulate", str))
20458 vsyscall_mode = EMULATE;
20459 - else if (!strcmp("native", str))
20460 - vsyscall_mode = NATIVE;
20461 else if (!strcmp("none", str))
20462 vsyscall_mode = NONE;
20463 else
20464 @@ -315,8 +313,7 @@ done:
20465 return true;
20466
20467 sigsegv:
20468 - force_sig(SIGSEGV, current);
20469 - return true;
20470 + do_group_exit(SIGKILL);
20471 }
20472
20473 /*
20474 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
20475 extern char __vvar_page;
20476 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20477
20478 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20479 - vsyscall_mode == NATIVE
20480 - ? PAGE_KERNEL_VSYSCALL
20481 - : PAGE_KERNEL_VVAR);
20482 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20483 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20484 (unsigned long)VSYSCALL_START);
20485
20486 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20487 index 1330dd1..d220b99 100644
20488 --- a/arch/x86/kernel/x8664_ksyms_64.c
20489 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20490 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20491 EXPORT_SYMBOL(copy_user_generic_unrolled);
20492 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20493 EXPORT_SYMBOL(__copy_user_nocache);
20494 -EXPORT_SYMBOL(_copy_from_user);
20495 -EXPORT_SYMBOL(_copy_to_user);
20496
20497 EXPORT_SYMBOL(copy_page);
20498 EXPORT_SYMBOL(clear_page);
20499 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20500 index ada87a3..afea76d 100644
20501 --- a/arch/x86/kernel/xsave.c
20502 +++ b/arch/x86/kernel/xsave.c
20503 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
20504 {
20505 int err;
20506
20507 + buf = (struct xsave_struct __user *)____m(buf);
20508 if (use_xsave())
20509 err = xsave_user(buf);
20510 else if (use_fxsr())
20511 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
20512 */
20513 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
20514 {
20515 + buf = (void __user *)____m(buf);
20516 if (use_xsave()) {
20517 if ((unsigned long)buf % 64 || fx_only) {
20518 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
20519 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20520 index ec79e77..420f5cc 100644
20521 --- a/arch/x86/kvm/cpuid.c
20522 +++ b/arch/x86/kvm/cpuid.c
20523 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20524 struct kvm_cpuid2 *cpuid,
20525 struct kvm_cpuid_entry2 __user *entries)
20526 {
20527 - int r;
20528 + int r, i;
20529
20530 r = -E2BIG;
20531 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20532 goto out;
20533 r = -EFAULT;
20534 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20535 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20536 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20537 goto out;
20538 + for (i = 0; i < cpuid->nent; ++i) {
20539 + struct kvm_cpuid_entry2 cpuid_entry;
20540 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20541 + goto out;
20542 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20543 + }
20544 vcpu->arch.cpuid_nent = cpuid->nent;
20545 kvm_apic_set_version(vcpu);
20546 kvm_x86_ops->cpuid_update(vcpu);
20547 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20548 struct kvm_cpuid2 *cpuid,
20549 struct kvm_cpuid_entry2 __user *entries)
20550 {
20551 - int r;
20552 + int r, i;
20553
20554 r = -E2BIG;
20555 if (cpuid->nent < vcpu->arch.cpuid_nent)
20556 goto out;
20557 r = -EFAULT;
20558 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20559 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20560 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20561 goto out;
20562 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20563 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20564 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20565 + goto out;
20566 + }
20567 return 0;
20568
20569 out:
20570 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20571 index bba39bf..296540a 100644
20572 --- a/arch/x86/kvm/emulate.c
20573 +++ b/arch/x86/kvm/emulate.c
20574 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
20575
20576 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20577 do { \
20578 + unsigned long _tmp; \
20579 __asm__ __volatile__ ( \
20580 _PRE_EFLAGS("0", "4", "2") \
20581 _op _suffix " %"_x"3,%1; " \
20582 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
20583 /* Raw emulation: instruction has two explicit operands. */
20584 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20585 do { \
20586 - unsigned long _tmp; \
20587 - \
20588 switch ((ctxt)->dst.bytes) { \
20589 case 2: \
20590 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20591 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
20592
20593 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20594 do { \
20595 - unsigned long _tmp; \
20596 switch ((ctxt)->dst.bytes) { \
20597 case 1: \
20598 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20599 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20600 index 43e9fad..3b7c059 100644
20601 --- a/arch/x86/kvm/lapic.c
20602 +++ b/arch/x86/kvm/lapic.c
20603 @@ -55,7 +55,7 @@
20604 #define APIC_BUS_CYCLE_NS 1
20605
20606 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20607 -#define apic_debug(fmt, arg...)
20608 +#define apic_debug(fmt, arg...) do {} while (0)
20609
20610 #define APIC_LVT_NUM 6
20611 /* 14 is the version for Xeon and Pentium 8.4.8*/
20612 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20613 index 714e2c0..3f7a086 100644
20614 --- a/arch/x86/kvm/paging_tmpl.h
20615 +++ b/arch/x86/kvm/paging_tmpl.h
20616 @@ -208,7 +208,7 @@ retry_walk:
20617 if (unlikely(kvm_is_error_hva(host_addr)))
20618 goto error;
20619
20620 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20621 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20622 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20623 goto error;
20624 walker->ptep_user[walker->level - 1] = ptep_user;
20625 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20626 index d017df3..61ae42e 100644
20627 --- a/arch/x86/kvm/svm.c
20628 +++ b/arch/x86/kvm/svm.c
20629 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20630 int cpu = raw_smp_processor_id();
20631
20632 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20633 +
20634 + pax_open_kernel();
20635 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20636 + pax_close_kernel();
20637 +
20638 load_TR_desc();
20639 }
20640
20641 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20642 #endif
20643 #endif
20644
20645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20646 + __set_fs(current_thread_info()->addr_limit);
20647 +#endif
20648 +
20649 reload_tss(vcpu);
20650
20651 local_irq_disable();
20652 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20653 index f858159..491d386 100644
20654 --- a/arch/x86/kvm/vmx.c
20655 +++ b/arch/x86/kvm/vmx.c
20656 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
20657 struct desc_struct *descs;
20658
20659 descs = (void *)gdt->address;
20660 +
20661 + pax_open_kernel();
20662 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20663 + pax_close_kernel();
20664 +
20665 load_TR_desc();
20666 }
20667
20668 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20669 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20670 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20671
20672 +#ifdef CONFIG_PAX_PER_CPU_PGD
20673 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20674 +#endif
20675 +
20676 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20677 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20678 vmx->loaded_vmcs->cpu = cpu;
20679 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
20680 if (!cpu_has_vmx_flexpriority())
20681 flexpriority_enabled = 0;
20682
20683 - if (!cpu_has_vmx_tpr_shadow())
20684 - kvm_x86_ops->update_cr8_intercept = NULL;
20685 + if (!cpu_has_vmx_tpr_shadow()) {
20686 + pax_open_kernel();
20687 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20688 + pax_close_kernel();
20689 + }
20690
20691 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20692 kvm_disable_largepages();
20693 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
20694
20695 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
20696 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20697 +
20698 +#ifndef CONFIG_PAX_PER_CPU_PGD
20699 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20700 +#endif
20701
20702 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20703 #ifdef CONFIG_X86_64
20704 @@ -3734,6 +3748,7 @@ static void vmx_set_constant_host_state(void)
20705 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20706
20707 vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
20708 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
20709
20710 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20711 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20712 @@ -6279,6 +6294,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20713 "jmp 2f \n\t"
20714 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
20715 "2: "
20716 +
20717 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20718 + "ljmp %[cs],$3f\n\t"
20719 + "3: "
20720 +#endif
20721 +
20722 /* Save guest registers, load host registers, keep flags */
20723 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
20724 "pop %0 \n\t"
20725 @@ -6331,6 +6352,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20726 #endif
20727 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20728 [wordsize]"i"(sizeof(ulong))
20729 +
20730 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20731 + ,[cs]"i"(__KERNEL_CS)
20732 +#endif
20733 +
20734 : "cc", "memory"
20735 #ifdef CONFIG_X86_64
20736 , "rax", "rbx", "rdi", "rsi"
20737 @@ -6344,7 +6370,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20738 if (debugctlmsr)
20739 update_debugctlmsr(debugctlmsr);
20740
20741 -#ifndef CONFIG_X86_64
20742 +#ifdef CONFIG_X86_32
20743 /*
20744 * The sysexit path does not restore ds/es, so we must set them to
20745 * a reasonable value ourselves.
20746 @@ -6353,8 +6379,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20747 * may be executed in interrupt context, which saves and restore segments
20748 * around it, nullifying its effect.
20749 */
20750 - loadsegment(ds, __USER_DS);
20751 - loadsegment(es, __USER_DS);
20752 + loadsegment(ds, __KERNEL_DS);
20753 + loadsegment(es, __KERNEL_DS);
20754 + loadsegment(ss, __KERNEL_DS);
20755 +
20756 +#ifdef CONFIG_PAX_KERNEXEC
20757 + loadsegment(fs, __KERNEL_PERCPU);
20758 +#endif
20759 +
20760 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20761 + __set_fs(current_thread_info()->addr_limit);
20762 +#endif
20763 +
20764 #endif
20765
20766 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20767 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20768 index 4f76417..93429b5 100644
20769 --- a/arch/x86/kvm/x86.c
20770 +++ b/arch/x86/kvm/x86.c
20771 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20772 {
20773 struct kvm *kvm = vcpu->kvm;
20774 int lm = is_long_mode(vcpu);
20775 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20776 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20777 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20778 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20779 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20780 : kvm->arch.xen_hvm_config.blob_size_32;
20781 u32 page_num = data & ~PAGE_MASK;
20782 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20783 if (n < msr_list.nmsrs)
20784 goto out;
20785 r = -EFAULT;
20786 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20787 + goto out;
20788 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20789 num_msrs_to_save * sizeof(u32)))
20790 goto out;
20791 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20792 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20793 struct kvm_interrupt *irq)
20794 {
20795 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
20796 + if (irq->irq >= KVM_NR_INTERRUPTS)
20797 return -EINVAL;
20798 if (irqchip_in_kernel(vcpu->kvm))
20799 return -ENXIO;
20800 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
20801 kvm_mmu_set_mmio_spte_mask(mask);
20802 }
20803
20804 -int kvm_arch_init(void *opaque)
20805 +int kvm_arch_init(const void *opaque)
20806 {
20807 int r;
20808 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20809 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20810 index 642d880..cc9ebac 100644
20811 --- a/arch/x86/lguest/boot.c
20812 +++ b/arch/x86/lguest/boot.c
20813 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20814
20815 static void set_lguest_basic_apic_ops(void)
20816 {
20817 - apic->read = lguest_apic_read;
20818 - apic->write = lguest_apic_write;
20819 - apic->icr_read = lguest_apic_icr_read;
20820 - apic->icr_write = lguest_apic_icr_write;
20821 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20822 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20823 + *(void **)&apic->read = lguest_apic_read;
20824 + *(void **)&apic->write = lguest_apic_write;
20825 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20826 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20827 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20828 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20829 };
20830 #endif
20831
20832 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20833 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20834 * Launcher to reboot us.
20835 */
20836 -static void lguest_restart(char *reason)
20837 +static __noreturn void lguest_restart(char *reason)
20838 {
20839 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20840 + BUG();
20841 }
20842
20843 /*G:050
20844 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20845 index 00933d5..3a64af9 100644
20846 --- a/arch/x86/lib/atomic64_386_32.S
20847 +++ b/arch/x86/lib/atomic64_386_32.S
20848 @@ -48,6 +48,10 @@ BEGIN(read)
20849 movl (v), %eax
20850 movl 4(v), %edx
20851 RET_ENDP
20852 +BEGIN(read_unchecked)
20853 + movl (v), %eax
20854 + movl 4(v), %edx
20855 +RET_ENDP
20856 #undef v
20857
20858 #define v %esi
20859 @@ -55,6 +59,10 @@ BEGIN(set)
20860 movl %ebx, (v)
20861 movl %ecx, 4(v)
20862 RET_ENDP
20863 +BEGIN(set_unchecked)
20864 + movl %ebx, (v)
20865 + movl %ecx, 4(v)
20866 +RET_ENDP
20867 #undef v
20868
20869 #define v %esi
20870 @@ -70,6 +78,20 @@ RET_ENDP
20871 BEGIN(add)
20872 addl %eax, (v)
20873 adcl %edx, 4(v)
20874 +
20875 +#ifdef CONFIG_PAX_REFCOUNT
20876 + jno 0f
20877 + subl %eax, (v)
20878 + sbbl %edx, 4(v)
20879 + int $4
20880 +0:
20881 + _ASM_EXTABLE(0b, 0b)
20882 +#endif
20883 +
20884 +RET_ENDP
20885 +BEGIN(add_unchecked)
20886 + addl %eax, (v)
20887 + adcl %edx, 4(v)
20888 RET_ENDP
20889 #undef v
20890
20891 @@ -77,6 +99,24 @@ RET_ENDP
20892 BEGIN(add_return)
20893 addl (v), %eax
20894 adcl 4(v), %edx
20895 +
20896 +#ifdef CONFIG_PAX_REFCOUNT
20897 + into
20898 +1234:
20899 + _ASM_EXTABLE(1234b, 2f)
20900 +#endif
20901 +
20902 + movl %eax, (v)
20903 + movl %edx, 4(v)
20904 +
20905 +#ifdef CONFIG_PAX_REFCOUNT
20906 +2:
20907 +#endif
20908 +
20909 +RET_ENDP
20910 +BEGIN(add_return_unchecked)
20911 + addl (v), %eax
20912 + adcl 4(v), %edx
20913 movl %eax, (v)
20914 movl %edx, 4(v)
20915 RET_ENDP
20916 @@ -86,6 +126,20 @@ RET_ENDP
20917 BEGIN(sub)
20918 subl %eax, (v)
20919 sbbl %edx, 4(v)
20920 +
20921 +#ifdef CONFIG_PAX_REFCOUNT
20922 + jno 0f
20923 + addl %eax, (v)
20924 + adcl %edx, 4(v)
20925 + int $4
20926 +0:
20927 + _ASM_EXTABLE(0b, 0b)
20928 +#endif
20929 +
20930 +RET_ENDP
20931 +BEGIN(sub_unchecked)
20932 + subl %eax, (v)
20933 + sbbl %edx, 4(v)
20934 RET_ENDP
20935 #undef v
20936
20937 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20938 sbbl $0, %edx
20939 addl (v), %eax
20940 adcl 4(v), %edx
20941 +
20942 +#ifdef CONFIG_PAX_REFCOUNT
20943 + into
20944 +1234:
20945 + _ASM_EXTABLE(1234b, 2f)
20946 +#endif
20947 +
20948 + movl %eax, (v)
20949 + movl %edx, 4(v)
20950 +
20951 +#ifdef CONFIG_PAX_REFCOUNT
20952 +2:
20953 +#endif
20954 +
20955 +RET_ENDP
20956 +BEGIN(sub_return_unchecked)
20957 + negl %edx
20958 + negl %eax
20959 + sbbl $0, %edx
20960 + addl (v), %eax
20961 + adcl 4(v), %edx
20962 movl %eax, (v)
20963 movl %edx, 4(v)
20964 RET_ENDP
20965 @@ -105,6 +180,20 @@ RET_ENDP
20966 BEGIN(inc)
20967 addl $1, (v)
20968 adcl $0, 4(v)
20969 +
20970 +#ifdef CONFIG_PAX_REFCOUNT
20971 + jno 0f
20972 + subl $1, (v)
20973 + sbbl $0, 4(v)
20974 + int $4
20975 +0:
20976 + _ASM_EXTABLE(0b, 0b)
20977 +#endif
20978 +
20979 +RET_ENDP
20980 +BEGIN(inc_unchecked)
20981 + addl $1, (v)
20982 + adcl $0, 4(v)
20983 RET_ENDP
20984 #undef v
20985
20986 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20987 movl 4(v), %edx
20988 addl $1, %eax
20989 adcl $0, %edx
20990 +
20991 +#ifdef CONFIG_PAX_REFCOUNT
20992 + into
20993 +1234:
20994 + _ASM_EXTABLE(1234b, 2f)
20995 +#endif
20996 +
20997 + movl %eax, (v)
20998 + movl %edx, 4(v)
20999 +
21000 +#ifdef CONFIG_PAX_REFCOUNT
21001 +2:
21002 +#endif
21003 +
21004 +RET_ENDP
21005 +BEGIN(inc_return_unchecked)
21006 + movl (v), %eax
21007 + movl 4(v), %edx
21008 + addl $1, %eax
21009 + adcl $0, %edx
21010 movl %eax, (v)
21011 movl %edx, 4(v)
21012 RET_ENDP
21013 @@ -123,6 +232,20 @@ RET_ENDP
21014 BEGIN(dec)
21015 subl $1, (v)
21016 sbbl $0, 4(v)
21017 +
21018 +#ifdef CONFIG_PAX_REFCOUNT
21019 + jno 0f
21020 + addl $1, (v)
21021 + adcl $0, 4(v)
21022 + int $4
21023 +0:
21024 + _ASM_EXTABLE(0b, 0b)
21025 +#endif
21026 +
21027 +RET_ENDP
21028 +BEGIN(dec_unchecked)
21029 + subl $1, (v)
21030 + sbbl $0, 4(v)
21031 RET_ENDP
21032 #undef v
21033
21034 @@ -132,6 +255,26 @@ BEGIN(dec_return)
21035 movl 4(v), %edx
21036 subl $1, %eax
21037 sbbl $0, %edx
21038 +
21039 +#ifdef CONFIG_PAX_REFCOUNT
21040 + into
21041 +1234:
21042 + _ASM_EXTABLE(1234b, 2f)
21043 +#endif
21044 +
21045 + movl %eax, (v)
21046 + movl %edx, 4(v)
21047 +
21048 +#ifdef CONFIG_PAX_REFCOUNT
21049 +2:
21050 +#endif
21051 +
21052 +RET_ENDP
21053 +BEGIN(dec_return_unchecked)
21054 + movl (v), %eax
21055 + movl 4(v), %edx
21056 + subl $1, %eax
21057 + sbbl $0, %edx
21058 movl %eax, (v)
21059 movl %edx, 4(v)
21060 RET_ENDP
21061 @@ -143,6 +286,13 @@ BEGIN(add_unless)
21062 adcl %edx, %edi
21063 addl (v), %eax
21064 adcl 4(v), %edx
21065 +
21066 +#ifdef CONFIG_PAX_REFCOUNT
21067 + into
21068 +1234:
21069 + _ASM_EXTABLE(1234b, 2f)
21070 +#endif
21071 +
21072 cmpl %eax, %ecx
21073 je 3f
21074 1:
21075 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21076 1:
21077 addl $1, %eax
21078 adcl $0, %edx
21079 +
21080 +#ifdef CONFIG_PAX_REFCOUNT
21081 + into
21082 +1234:
21083 + _ASM_EXTABLE(1234b, 2f)
21084 +#endif
21085 +
21086 movl %eax, (v)
21087 movl %edx, 4(v)
21088 movl $1, %eax
21089 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21090 movl 4(v), %edx
21091 subl $1, %eax
21092 sbbl $0, %edx
21093 +
21094 +#ifdef CONFIG_PAX_REFCOUNT
21095 + into
21096 +1234:
21097 + _ASM_EXTABLE(1234b, 1f)
21098 +#endif
21099 +
21100 js 1f
21101 movl %eax, (v)
21102 movl %edx, 4(v)
21103 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21104 index f5cc9eb..51fa319 100644
21105 --- a/arch/x86/lib/atomic64_cx8_32.S
21106 +++ b/arch/x86/lib/atomic64_cx8_32.S
21107 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21108 CFI_STARTPROC
21109
21110 read64 %ecx
21111 + pax_force_retaddr
21112 ret
21113 CFI_ENDPROC
21114 ENDPROC(atomic64_read_cx8)
21115
21116 +ENTRY(atomic64_read_unchecked_cx8)
21117 + CFI_STARTPROC
21118 +
21119 + read64 %ecx
21120 + pax_force_retaddr
21121 + ret
21122 + CFI_ENDPROC
21123 +ENDPROC(atomic64_read_unchecked_cx8)
21124 +
21125 ENTRY(atomic64_set_cx8)
21126 CFI_STARTPROC
21127
21128 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21129 cmpxchg8b (%esi)
21130 jne 1b
21131
21132 + pax_force_retaddr
21133 ret
21134 CFI_ENDPROC
21135 ENDPROC(atomic64_set_cx8)
21136
21137 +ENTRY(atomic64_set_unchecked_cx8)
21138 + CFI_STARTPROC
21139 +
21140 +1:
21141 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21142 + * are atomic on 586 and newer */
21143 + cmpxchg8b (%esi)
21144 + jne 1b
21145 +
21146 + pax_force_retaddr
21147 + ret
21148 + CFI_ENDPROC
21149 +ENDPROC(atomic64_set_unchecked_cx8)
21150 +
21151 ENTRY(atomic64_xchg_cx8)
21152 CFI_STARTPROC
21153
21154 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21155 cmpxchg8b (%esi)
21156 jne 1b
21157
21158 + pax_force_retaddr
21159 ret
21160 CFI_ENDPROC
21161 ENDPROC(atomic64_xchg_cx8)
21162
21163 -.macro addsub_return func ins insc
21164 -ENTRY(atomic64_\func\()_return_cx8)
21165 +.macro addsub_return func ins insc unchecked=""
21166 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21167 CFI_STARTPROC
21168 SAVE ebp
21169 SAVE ebx
21170 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21171 movl %edx, %ecx
21172 \ins\()l %esi, %ebx
21173 \insc\()l %edi, %ecx
21174 +
21175 +.ifb \unchecked
21176 +#ifdef CONFIG_PAX_REFCOUNT
21177 + into
21178 +2:
21179 + _ASM_EXTABLE(2b, 3f)
21180 +#endif
21181 +.endif
21182 +
21183 LOCK_PREFIX
21184 cmpxchg8b (%ebp)
21185 jne 1b
21186 -
21187 -10:
21188 movl %ebx, %eax
21189 movl %ecx, %edx
21190 +
21191 +.ifb \unchecked
21192 +#ifdef CONFIG_PAX_REFCOUNT
21193 +3:
21194 +#endif
21195 +.endif
21196 +
21197 RESTORE edi
21198 RESTORE esi
21199 RESTORE ebx
21200 RESTORE ebp
21201 + pax_force_retaddr
21202 ret
21203 CFI_ENDPROC
21204 -ENDPROC(atomic64_\func\()_return_cx8)
21205 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21206 .endm
21207
21208 addsub_return add add adc
21209 addsub_return sub sub sbb
21210 +addsub_return add add adc _unchecked
21211 +addsub_return sub sub sbb _unchecked
21212
21213 -.macro incdec_return func ins insc
21214 -ENTRY(atomic64_\func\()_return_cx8)
21215 +.macro incdec_return func ins insc unchecked=""
21216 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21217 CFI_STARTPROC
21218 SAVE ebx
21219
21220 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21221 movl %edx, %ecx
21222 \ins\()l $1, %ebx
21223 \insc\()l $0, %ecx
21224 +
21225 +.ifb \unchecked
21226 +#ifdef CONFIG_PAX_REFCOUNT
21227 + into
21228 +2:
21229 + _ASM_EXTABLE(2b, 3f)
21230 +#endif
21231 +.endif
21232 +
21233 LOCK_PREFIX
21234 cmpxchg8b (%esi)
21235 jne 1b
21236
21237 -10:
21238 movl %ebx, %eax
21239 movl %ecx, %edx
21240 +
21241 +.ifb \unchecked
21242 +#ifdef CONFIG_PAX_REFCOUNT
21243 +3:
21244 +#endif
21245 +.endif
21246 +
21247 RESTORE ebx
21248 + pax_force_retaddr
21249 ret
21250 CFI_ENDPROC
21251 -ENDPROC(atomic64_\func\()_return_cx8)
21252 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21253 .endm
21254
21255 incdec_return inc add adc
21256 incdec_return dec sub sbb
21257 +incdec_return inc add adc _unchecked
21258 +incdec_return dec sub sbb _unchecked
21259
21260 ENTRY(atomic64_dec_if_positive_cx8)
21261 CFI_STARTPROC
21262 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21263 movl %edx, %ecx
21264 subl $1, %ebx
21265 sbb $0, %ecx
21266 +
21267 +#ifdef CONFIG_PAX_REFCOUNT
21268 + into
21269 +1234:
21270 + _ASM_EXTABLE(1234b, 2f)
21271 +#endif
21272 +
21273 js 2f
21274 LOCK_PREFIX
21275 cmpxchg8b (%esi)
21276 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21277 movl %ebx, %eax
21278 movl %ecx, %edx
21279 RESTORE ebx
21280 + pax_force_retaddr
21281 ret
21282 CFI_ENDPROC
21283 ENDPROC(atomic64_dec_if_positive_cx8)
21284 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21285 movl %edx, %ecx
21286 addl %ebp, %ebx
21287 adcl %edi, %ecx
21288 +
21289 +#ifdef CONFIG_PAX_REFCOUNT
21290 + into
21291 +1234:
21292 + _ASM_EXTABLE(1234b, 3f)
21293 +#endif
21294 +
21295 LOCK_PREFIX
21296 cmpxchg8b (%esi)
21297 jne 1b
21298 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21299 CFI_ADJUST_CFA_OFFSET -8
21300 RESTORE ebx
21301 RESTORE ebp
21302 + pax_force_retaddr
21303 ret
21304 4:
21305 cmpl %edx, 4(%esp)
21306 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21307 xorl %ecx, %ecx
21308 addl $1, %ebx
21309 adcl %edx, %ecx
21310 +
21311 +#ifdef CONFIG_PAX_REFCOUNT
21312 + into
21313 +1234:
21314 + _ASM_EXTABLE(1234b, 3f)
21315 +#endif
21316 +
21317 LOCK_PREFIX
21318 cmpxchg8b (%esi)
21319 jne 1b
21320 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21321 movl $1, %eax
21322 3:
21323 RESTORE ebx
21324 + pax_force_retaddr
21325 ret
21326 CFI_ENDPROC
21327 ENDPROC(atomic64_inc_not_zero_cx8)
21328 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21329 index 2af5df3..62b1a5a 100644
21330 --- a/arch/x86/lib/checksum_32.S
21331 +++ b/arch/x86/lib/checksum_32.S
21332 @@ -29,7 +29,8 @@
21333 #include <asm/dwarf2.h>
21334 #include <asm/errno.h>
21335 #include <asm/asm.h>
21336 -
21337 +#include <asm/segment.h>
21338 +
21339 /*
21340 * computes a partial checksum, e.g. for TCP/UDP fragments
21341 */
21342 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21343
21344 #define ARGBASE 16
21345 #define FP 12
21346 -
21347 -ENTRY(csum_partial_copy_generic)
21348 +
21349 +ENTRY(csum_partial_copy_generic_to_user)
21350 CFI_STARTPROC
21351 +
21352 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21353 + pushl_cfi %gs
21354 + popl_cfi %es
21355 + jmp csum_partial_copy_generic
21356 +#endif
21357 +
21358 +ENTRY(csum_partial_copy_generic_from_user)
21359 +
21360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21361 + pushl_cfi %gs
21362 + popl_cfi %ds
21363 +#endif
21364 +
21365 +ENTRY(csum_partial_copy_generic)
21366 subl $4,%esp
21367 CFI_ADJUST_CFA_OFFSET 4
21368 pushl_cfi %edi
21369 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21370 jmp 4f
21371 SRC(1: movw (%esi), %bx )
21372 addl $2, %esi
21373 -DST( movw %bx, (%edi) )
21374 +DST( movw %bx, %es:(%edi) )
21375 addl $2, %edi
21376 addw %bx, %ax
21377 adcl $0, %eax
21378 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21379 SRC(1: movl (%esi), %ebx )
21380 SRC( movl 4(%esi), %edx )
21381 adcl %ebx, %eax
21382 -DST( movl %ebx, (%edi) )
21383 +DST( movl %ebx, %es:(%edi) )
21384 adcl %edx, %eax
21385 -DST( movl %edx, 4(%edi) )
21386 +DST( movl %edx, %es:4(%edi) )
21387
21388 SRC( movl 8(%esi), %ebx )
21389 SRC( movl 12(%esi), %edx )
21390 adcl %ebx, %eax
21391 -DST( movl %ebx, 8(%edi) )
21392 +DST( movl %ebx, %es:8(%edi) )
21393 adcl %edx, %eax
21394 -DST( movl %edx, 12(%edi) )
21395 +DST( movl %edx, %es:12(%edi) )
21396
21397 SRC( movl 16(%esi), %ebx )
21398 SRC( movl 20(%esi), %edx )
21399 adcl %ebx, %eax
21400 -DST( movl %ebx, 16(%edi) )
21401 +DST( movl %ebx, %es:16(%edi) )
21402 adcl %edx, %eax
21403 -DST( movl %edx, 20(%edi) )
21404 +DST( movl %edx, %es:20(%edi) )
21405
21406 SRC( movl 24(%esi), %ebx )
21407 SRC( movl 28(%esi), %edx )
21408 adcl %ebx, %eax
21409 -DST( movl %ebx, 24(%edi) )
21410 +DST( movl %ebx, %es:24(%edi) )
21411 adcl %edx, %eax
21412 -DST( movl %edx, 28(%edi) )
21413 +DST( movl %edx, %es:28(%edi) )
21414
21415 lea 32(%esi), %esi
21416 lea 32(%edi), %edi
21417 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21418 shrl $2, %edx # This clears CF
21419 SRC(3: movl (%esi), %ebx )
21420 adcl %ebx, %eax
21421 -DST( movl %ebx, (%edi) )
21422 +DST( movl %ebx, %es:(%edi) )
21423 lea 4(%esi), %esi
21424 lea 4(%edi), %edi
21425 dec %edx
21426 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21427 jb 5f
21428 SRC( movw (%esi), %cx )
21429 leal 2(%esi), %esi
21430 -DST( movw %cx, (%edi) )
21431 +DST( movw %cx, %es:(%edi) )
21432 leal 2(%edi), %edi
21433 je 6f
21434 shll $16,%ecx
21435 SRC(5: movb (%esi), %cl )
21436 -DST( movb %cl, (%edi) )
21437 +DST( movb %cl, %es:(%edi) )
21438 6: addl %ecx, %eax
21439 adcl $0, %eax
21440 7:
21441 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21442
21443 6001:
21444 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21445 - movl $-EFAULT, (%ebx)
21446 + movl $-EFAULT, %ss:(%ebx)
21447
21448 # zero the complete destination - computing the rest
21449 # is too much work
21450 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21451
21452 6002:
21453 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21454 - movl $-EFAULT,(%ebx)
21455 + movl $-EFAULT,%ss:(%ebx)
21456 jmp 5000b
21457
21458 .previous
21459
21460 + pushl_cfi %ss
21461 + popl_cfi %ds
21462 + pushl_cfi %ss
21463 + popl_cfi %es
21464 popl_cfi %ebx
21465 CFI_RESTORE ebx
21466 popl_cfi %esi
21467 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21468 popl_cfi %ecx # equivalent to addl $4,%esp
21469 ret
21470 CFI_ENDPROC
21471 -ENDPROC(csum_partial_copy_generic)
21472 +ENDPROC(csum_partial_copy_generic_to_user)
21473
21474 #else
21475
21476 /* Version for PentiumII/PPro */
21477
21478 #define ROUND1(x) \
21479 + nop; nop; nop; \
21480 SRC(movl x(%esi), %ebx ) ; \
21481 addl %ebx, %eax ; \
21482 - DST(movl %ebx, x(%edi) ) ;
21483 + DST(movl %ebx, %es:x(%edi)) ;
21484
21485 #define ROUND(x) \
21486 + nop; nop; nop; \
21487 SRC(movl x(%esi), %ebx ) ; \
21488 adcl %ebx, %eax ; \
21489 - DST(movl %ebx, x(%edi) ) ;
21490 + DST(movl %ebx, %es:x(%edi)) ;
21491
21492 #define ARGBASE 12
21493 -
21494 -ENTRY(csum_partial_copy_generic)
21495 +
21496 +ENTRY(csum_partial_copy_generic_to_user)
21497 CFI_STARTPROC
21498 +
21499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21500 + pushl_cfi %gs
21501 + popl_cfi %es
21502 + jmp csum_partial_copy_generic
21503 +#endif
21504 +
21505 +ENTRY(csum_partial_copy_generic_from_user)
21506 +
21507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21508 + pushl_cfi %gs
21509 + popl_cfi %ds
21510 +#endif
21511 +
21512 +ENTRY(csum_partial_copy_generic)
21513 pushl_cfi %ebx
21514 CFI_REL_OFFSET ebx, 0
21515 pushl_cfi %edi
21516 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21517 subl %ebx, %edi
21518 lea -1(%esi),%edx
21519 andl $-32,%edx
21520 - lea 3f(%ebx,%ebx), %ebx
21521 + lea 3f(%ebx,%ebx,2), %ebx
21522 testl %esi, %esi
21523 jmp *%ebx
21524 1: addl $64,%esi
21525 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21526 jb 5f
21527 SRC( movw (%esi), %dx )
21528 leal 2(%esi), %esi
21529 -DST( movw %dx, (%edi) )
21530 +DST( movw %dx, %es:(%edi) )
21531 leal 2(%edi), %edi
21532 je 6f
21533 shll $16,%edx
21534 5:
21535 SRC( movb (%esi), %dl )
21536 -DST( movb %dl, (%edi) )
21537 +DST( movb %dl, %es:(%edi) )
21538 6: addl %edx, %eax
21539 adcl $0, %eax
21540 7:
21541 .section .fixup, "ax"
21542 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21543 - movl $-EFAULT, (%ebx)
21544 + movl $-EFAULT, %ss:(%ebx)
21545 # zero the complete destination (computing the rest is too much work)
21546 movl ARGBASE+8(%esp),%edi # dst
21547 movl ARGBASE+12(%esp),%ecx # len
21548 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21549 rep; stosb
21550 jmp 7b
21551 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21552 - movl $-EFAULT, (%ebx)
21553 + movl $-EFAULT, %ss:(%ebx)
21554 jmp 7b
21555 .previous
21556
21557 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21558 + pushl_cfi %ss
21559 + popl_cfi %ds
21560 + pushl_cfi %ss
21561 + popl_cfi %es
21562 +#endif
21563 +
21564 popl_cfi %esi
21565 CFI_RESTORE esi
21566 popl_cfi %edi
21567 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21568 CFI_RESTORE ebx
21569 ret
21570 CFI_ENDPROC
21571 -ENDPROC(csum_partial_copy_generic)
21572 +ENDPROC(csum_partial_copy_generic_to_user)
21573
21574 #undef ROUND
21575 #undef ROUND1
21576 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21577 index f2145cf..cea889d 100644
21578 --- a/arch/x86/lib/clear_page_64.S
21579 +++ b/arch/x86/lib/clear_page_64.S
21580 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21581 movl $4096/8,%ecx
21582 xorl %eax,%eax
21583 rep stosq
21584 + pax_force_retaddr
21585 ret
21586 CFI_ENDPROC
21587 ENDPROC(clear_page_c)
21588 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21589 movl $4096,%ecx
21590 xorl %eax,%eax
21591 rep stosb
21592 + pax_force_retaddr
21593 ret
21594 CFI_ENDPROC
21595 ENDPROC(clear_page_c_e)
21596 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21597 leaq 64(%rdi),%rdi
21598 jnz .Lloop
21599 nop
21600 + pax_force_retaddr
21601 ret
21602 CFI_ENDPROC
21603 .Lclear_page_end:
21604 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21605
21606 #include <asm/cpufeature.h>
21607
21608 - .section .altinstr_replacement,"ax"
21609 + .section .altinstr_replacement,"a"
21610 1: .byte 0xeb /* jmp <disp8> */
21611 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21612 2: .byte 0xeb /* jmp <disp8> */
21613 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21614 index 1e572c5..2a162cd 100644
21615 --- a/arch/x86/lib/cmpxchg16b_emu.S
21616 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21617 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21618
21619 popf
21620 mov $1, %al
21621 + pax_force_retaddr
21622 ret
21623
21624 not_same:
21625 popf
21626 xor %al,%al
21627 + pax_force_retaddr
21628 ret
21629
21630 CFI_ENDPROC
21631 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21632 index 6b34d04..dccb07f 100644
21633 --- a/arch/x86/lib/copy_page_64.S
21634 +++ b/arch/x86/lib/copy_page_64.S
21635 @@ -9,6 +9,7 @@ copy_page_c:
21636 CFI_STARTPROC
21637 movl $4096/8,%ecx
21638 rep movsq
21639 + pax_force_retaddr
21640 ret
21641 CFI_ENDPROC
21642 ENDPROC(copy_page_c)
21643 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21644
21645 ENTRY(copy_page)
21646 CFI_STARTPROC
21647 - subq $2*8,%rsp
21648 - CFI_ADJUST_CFA_OFFSET 2*8
21649 + subq $3*8,%rsp
21650 + CFI_ADJUST_CFA_OFFSET 3*8
21651 movq %rbx,(%rsp)
21652 CFI_REL_OFFSET rbx, 0
21653 movq %r12,1*8(%rsp)
21654 CFI_REL_OFFSET r12, 1*8
21655 + movq %r13,2*8(%rsp)
21656 + CFI_REL_OFFSET r13, 2*8
21657
21658 movl $(4096/64)-5,%ecx
21659 .p2align 4
21660 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21661 movq 16 (%rsi), %rdx
21662 movq 24 (%rsi), %r8
21663 movq 32 (%rsi), %r9
21664 - movq 40 (%rsi), %r10
21665 + movq 40 (%rsi), %r13
21666 movq 48 (%rsi), %r11
21667 movq 56 (%rsi), %r12
21668
21669 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21670 movq %rdx, 16 (%rdi)
21671 movq %r8, 24 (%rdi)
21672 movq %r9, 32 (%rdi)
21673 - movq %r10, 40 (%rdi)
21674 + movq %r13, 40 (%rdi)
21675 movq %r11, 48 (%rdi)
21676 movq %r12, 56 (%rdi)
21677
21678 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21679 movq 16 (%rsi), %rdx
21680 movq 24 (%rsi), %r8
21681 movq 32 (%rsi), %r9
21682 - movq 40 (%rsi), %r10
21683 + movq 40 (%rsi), %r13
21684 movq 48 (%rsi), %r11
21685 movq 56 (%rsi), %r12
21686
21687 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21688 movq %rdx, 16 (%rdi)
21689 movq %r8, 24 (%rdi)
21690 movq %r9, 32 (%rdi)
21691 - movq %r10, 40 (%rdi)
21692 + movq %r13, 40 (%rdi)
21693 movq %r11, 48 (%rdi)
21694 movq %r12, 56 (%rdi)
21695
21696 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21697 CFI_RESTORE rbx
21698 movq 1*8(%rsp),%r12
21699 CFI_RESTORE r12
21700 - addq $2*8,%rsp
21701 - CFI_ADJUST_CFA_OFFSET -2*8
21702 + movq 2*8(%rsp),%r13
21703 + CFI_RESTORE r13
21704 + addq $3*8,%rsp
21705 + CFI_ADJUST_CFA_OFFSET -3*8
21706 + pax_force_retaddr
21707 ret
21708 .Lcopy_page_end:
21709 CFI_ENDPROC
21710 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21711
21712 #include <asm/cpufeature.h>
21713
21714 - .section .altinstr_replacement,"ax"
21715 + .section .altinstr_replacement,"a"
21716 1: .byte 0xeb /* jmp <disp8> */
21717 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21718 2:
21719 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21720 index a30ca15..d25fab6 100644
21721 --- a/arch/x86/lib/copy_user_64.S
21722 +++ b/arch/x86/lib/copy_user_64.S
21723 @@ -18,6 +18,7 @@
21724 #include <asm/alternative-asm.h>
21725 #include <asm/asm.h>
21726 #include <asm/smap.h>
21727 +#include <asm/pgtable.h>
21728
21729 /*
21730 * By placing feature2 after feature1 in altinstructions section, we logically
21731 @@ -31,7 +32,7 @@
21732 .byte 0xe9 /* 32bit jump */
21733 .long \orig-1f /* by default jump to orig */
21734 1:
21735 - .section .altinstr_replacement,"ax"
21736 + .section .altinstr_replacement,"a"
21737 2: .byte 0xe9 /* near jump with 32bit immediate */
21738 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21739 3: .byte 0xe9 /* near jump with 32bit immediate */
21740 @@ -70,47 +71,20 @@
21741 #endif
21742 .endm
21743
21744 -/* Standard copy_to_user with segment limit checking */
21745 -ENTRY(_copy_to_user)
21746 - CFI_STARTPROC
21747 - GET_THREAD_INFO(%rax)
21748 - movq %rdi,%rcx
21749 - addq %rdx,%rcx
21750 - jc bad_to_user
21751 - cmpq TI_addr_limit(%rax),%rcx
21752 - ja bad_to_user
21753 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21754 - copy_user_generic_unrolled,copy_user_generic_string, \
21755 - copy_user_enhanced_fast_string
21756 - CFI_ENDPROC
21757 -ENDPROC(_copy_to_user)
21758 -
21759 -/* Standard copy_from_user with segment limit checking */
21760 -ENTRY(_copy_from_user)
21761 - CFI_STARTPROC
21762 - GET_THREAD_INFO(%rax)
21763 - movq %rsi,%rcx
21764 - addq %rdx,%rcx
21765 - jc bad_from_user
21766 - cmpq TI_addr_limit(%rax),%rcx
21767 - ja bad_from_user
21768 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21769 - copy_user_generic_unrolled,copy_user_generic_string, \
21770 - copy_user_enhanced_fast_string
21771 - CFI_ENDPROC
21772 -ENDPROC(_copy_from_user)
21773 -
21774 .section .fixup,"ax"
21775 /* must zero dest */
21776 ENTRY(bad_from_user)
21777 bad_from_user:
21778 CFI_STARTPROC
21779 + testl %edx,%edx
21780 + js bad_to_user
21781 movl %edx,%ecx
21782 xorl %eax,%eax
21783 rep
21784 stosb
21785 bad_to_user:
21786 movl %edx,%eax
21787 + pax_force_retaddr
21788 ret
21789 CFI_ENDPROC
21790 ENDPROC(bad_from_user)
21791 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21792 jz 17f
21793 1: movq (%rsi),%r8
21794 2: movq 1*8(%rsi),%r9
21795 -3: movq 2*8(%rsi),%r10
21796 +3: movq 2*8(%rsi),%rax
21797 4: movq 3*8(%rsi),%r11
21798 5: movq %r8,(%rdi)
21799 6: movq %r9,1*8(%rdi)
21800 -7: movq %r10,2*8(%rdi)
21801 +7: movq %rax,2*8(%rdi)
21802 8: movq %r11,3*8(%rdi)
21803 9: movq 4*8(%rsi),%r8
21804 10: movq 5*8(%rsi),%r9
21805 -11: movq 6*8(%rsi),%r10
21806 +11: movq 6*8(%rsi),%rax
21807 12: movq 7*8(%rsi),%r11
21808 13: movq %r8,4*8(%rdi)
21809 14: movq %r9,5*8(%rdi)
21810 -15: movq %r10,6*8(%rdi)
21811 +15: movq %rax,6*8(%rdi)
21812 16: movq %r11,7*8(%rdi)
21813 leaq 64(%rsi),%rsi
21814 leaq 64(%rdi),%rdi
21815 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
21816 jnz 21b
21817 23: xor %eax,%eax
21818 ASM_CLAC
21819 + pax_force_retaddr
21820 ret
21821
21822 .section .fixup,"ax"
21823 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21824 movsb
21825 4: xorl %eax,%eax
21826 ASM_CLAC
21827 + pax_force_retaddr
21828 ret
21829
21830 .section .fixup,"ax"
21831 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
21832 movsb
21833 2: xorl %eax,%eax
21834 ASM_CLAC
21835 + pax_force_retaddr
21836 ret
21837
21838 .section .fixup,"ax"
21839 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21840 index 6a4f43c..f5f9e26 100644
21841 --- a/arch/x86/lib/copy_user_nocache_64.S
21842 +++ b/arch/x86/lib/copy_user_nocache_64.S
21843 @@ -8,6 +8,7 @@
21844
21845 #include <linux/linkage.h>
21846 #include <asm/dwarf2.h>
21847 +#include <asm/alternative-asm.h>
21848
21849 #define FIX_ALIGNMENT 1
21850
21851 @@ -16,6 +17,7 @@
21852 #include <asm/thread_info.h>
21853 #include <asm/asm.h>
21854 #include <asm/smap.h>
21855 +#include <asm/pgtable.h>
21856
21857 .macro ALIGN_DESTINATION
21858 #ifdef FIX_ALIGNMENT
21859 @@ -49,6 +51,15 @@
21860 */
21861 ENTRY(__copy_user_nocache)
21862 CFI_STARTPROC
21863 +
21864 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21865 + mov $PAX_USER_SHADOW_BASE,%rcx
21866 + cmp %rcx,%rsi
21867 + jae 1f
21868 + add %rcx,%rsi
21869 +1:
21870 +#endif
21871 +
21872 ASM_STAC
21873 cmpl $8,%edx
21874 jb 20f /* less then 8 bytes, go to byte copy loop */
21875 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21876 jz 17f
21877 1: movq (%rsi),%r8
21878 2: movq 1*8(%rsi),%r9
21879 -3: movq 2*8(%rsi),%r10
21880 +3: movq 2*8(%rsi),%rax
21881 4: movq 3*8(%rsi),%r11
21882 5: movnti %r8,(%rdi)
21883 6: movnti %r9,1*8(%rdi)
21884 -7: movnti %r10,2*8(%rdi)
21885 +7: movnti %rax,2*8(%rdi)
21886 8: movnti %r11,3*8(%rdi)
21887 9: movq 4*8(%rsi),%r8
21888 10: movq 5*8(%rsi),%r9
21889 -11: movq 6*8(%rsi),%r10
21890 +11: movq 6*8(%rsi),%rax
21891 12: movq 7*8(%rsi),%r11
21892 13: movnti %r8,4*8(%rdi)
21893 14: movnti %r9,5*8(%rdi)
21894 -15: movnti %r10,6*8(%rdi)
21895 +15: movnti %rax,6*8(%rdi)
21896 16: movnti %r11,7*8(%rdi)
21897 leaq 64(%rsi),%rsi
21898 leaq 64(%rdi),%rdi
21899 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
21900 23: xorl %eax,%eax
21901 ASM_CLAC
21902 sfence
21903 + pax_force_retaddr
21904 ret
21905
21906 .section .fixup,"ax"
21907 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21908 index 2419d5f..953ee51 100644
21909 --- a/arch/x86/lib/csum-copy_64.S
21910 +++ b/arch/x86/lib/csum-copy_64.S
21911 @@ -9,6 +9,7 @@
21912 #include <asm/dwarf2.h>
21913 #include <asm/errno.h>
21914 #include <asm/asm.h>
21915 +#include <asm/alternative-asm.h>
21916
21917 /*
21918 * Checksum copy with exception handling.
21919 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21920 CFI_RESTORE rbp
21921 addq $7*8, %rsp
21922 CFI_ADJUST_CFA_OFFSET -7*8
21923 + pax_force_retaddr 0, 1
21924 ret
21925 CFI_RESTORE_STATE
21926
21927 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21928 index 25b7ae8..169fafc 100644
21929 --- a/arch/x86/lib/csum-wrappers_64.c
21930 +++ b/arch/x86/lib/csum-wrappers_64.c
21931 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21932 len -= 2;
21933 }
21934 }
21935 - isum = csum_partial_copy_generic((__force const void *)src,
21936 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
21937 dst, len, isum, errp, NULL);
21938 if (unlikely(*errp))
21939 goto out_err;
21940 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21941 }
21942
21943 *errp = 0;
21944 - return csum_partial_copy_generic(src, (void __force *)dst,
21945 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
21946 len, isum, NULL, errp);
21947 }
21948 EXPORT_SYMBOL(csum_partial_copy_to_user);
21949 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21950 index 156b9c8..b144132 100644
21951 --- a/arch/x86/lib/getuser.S
21952 +++ b/arch/x86/lib/getuser.S
21953 @@ -34,17 +34,40 @@
21954 #include <asm/thread_info.h>
21955 #include <asm/asm.h>
21956 #include <asm/smap.h>
21957 +#include <asm/segment.h>
21958 +#include <asm/pgtable.h>
21959 +#include <asm/alternative-asm.h>
21960 +
21961 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21962 +#define __copyuser_seg gs;
21963 +#else
21964 +#define __copyuser_seg
21965 +#endif
21966
21967 .text
21968 ENTRY(__get_user_1)
21969 CFI_STARTPROC
21970 +
21971 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21972 GET_THREAD_INFO(%_ASM_DX)
21973 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21974 jae bad_get_user
21975 ASM_STAC
21976 -1: movzb (%_ASM_AX),%edx
21977 +
21978 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21979 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21980 + cmp %_ASM_DX,%_ASM_AX
21981 + jae 1234f
21982 + add %_ASM_DX,%_ASM_AX
21983 +1234:
21984 +#endif
21985 +
21986 +#endif
21987 +
21988 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21989 xor %eax,%eax
21990 ASM_CLAC
21991 + pax_force_retaddr
21992 ret
21993 CFI_ENDPROC
21994 ENDPROC(__get_user_1)
21995 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
21996 ENTRY(__get_user_2)
21997 CFI_STARTPROC
21998 add $1,%_ASM_AX
21999 +
22000 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22001 jc bad_get_user
22002 GET_THREAD_INFO(%_ASM_DX)
22003 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22004 jae bad_get_user
22005 ASM_STAC
22006 -2: movzwl -1(%_ASM_AX),%edx
22007 +
22008 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22009 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22010 + cmp %_ASM_DX,%_ASM_AX
22011 + jae 1234f
22012 + add %_ASM_DX,%_ASM_AX
22013 +1234:
22014 +#endif
22015 +
22016 +#endif
22017 +
22018 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22019 xor %eax,%eax
22020 ASM_CLAC
22021 + pax_force_retaddr
22022 ret
22023 CFI_ENDPROC
22024 ENDPROC(__get_user_2)
22025 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
22026 ENTRY(__get_user_4)
22027 CFI_STARTPROC
22028 add $3,%_ASM_AX
22029 +
22030 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22031 jc bad_get_user
22032 GET_THREAD_INFO(%_ASM_DX)
22033 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22034 jae bad_get_user
22035 ASM_STAC
22036 -3: mov -3(%_ASM_AX),%edx
22037 +
22038 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22039 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22040 + cmp %_ASM_DX,%_ASM_AX
22041 + jae 1234f
22042 + add %_ASM_DX,%_ASM_AX
22043 +1234:
22044 +#endif
22045 +
22046 +#endif
22047 +
22048 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
22049 xor %eax,%eax
22050 ASM_CLAC
22051 + pax_force_retaddr
22052 ret
22053 CFI_ENDPROC
22054 ENDPROC(__get_user_4)
22055 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
22056 GET_THREAD_INFO(%_ASM_DX)
22057 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22058 jae bad_get_user
22059 +
22060 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22061 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22062 + cmp %_ASM_DX,%_ASM_AX
22063 + jae 1234f
22064 + add %_ASM_DX,%_ASM_AX
22065 +1234:
22066 +#endif
22067 +
22068 ASM_STAC
22069 4: movq -7(%_ASM_AX),%_ASM_DX
22070 xor %eax,%eax
22071 ASM_CLAC
22072 + pax_force_retaddr
22073 ret
22074 CFI_ENDPROC
22075 ENDPROC(__get_user_8)
22076 @@ -101,6 +162,7 @@ bad_get_user:
22077 xor %edx,%edx
22078 mov $(-EFAULT),%_ASM_AX
22079 ASM_CLAC
22080 + pax_force_retaddr
22081 ret
22082 CFI_ENDPROC
22083 END(bad_get_user)
22084 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22085 index 54fcffe..7be149e 100644
22086 --- a/arch/x86/lib/insn.c
22087 +++ b/arch/x86/lib/insn.c
22088 @@ -20,8 +20,10 @@
22089
22090 #ifdef __KERNEL__
22091 #include <linux/string.h>
22092 +#include <asm/pgtable_types.h>
22093 #else
22094 #include <string.h>
22095 +#define ktla_ktva(addr) addr
22096 #endif
22097 #include <asm/inat.h>
22098 #include <asm/insn.h>
22099 @@ -53,8 +55,8 @@
22100 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22101 {
22102 memset(insn, 0, sizeof(*insn));
22103 - insn->kaddr = kaddr;
22104 - insn->next_byte = kaddr;
22105 + insn->kaddr = ktla_ktva(kaddr);
22106 + insn->next_byte = ktla_ktva(kaddr);
22107 insn->x86_64 = x86_64 ? 1 : 0;
22108 insn->opnd_bytes = 4;
22109 if (x86_64)
22110 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22111 index 05a95e7..326f2fa 100644
22112 --- a/arch/x86/lib/iomap_copy_64.S
22113 +++ b/arch/x86/lib/iomap_copy_64.S
22114 @@ -17,6 +17,7 @@
22115
22116 #include <linux/linkage.h>
22117 #include <asm/dwarf2.h>
22118 +#include <asm/alternative-asm.h>
22119
22120 /*
22121 * override generic version in lib/iomap_copy.c
22122 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22123 CFI_STARTPROC
22124 movl %edx,%ecx
22125 rep movsd
22126 + pax_force_retaddr
22127 ret
22128 CFI_ENDPROC
22129 ENDPROC(__iowrite32_copy)
22130 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22131 index 1c273be..da9cc0e 100644
22132 --- a/arch/x86/lib/memcpy_64.S
22133 +++ b/arch/x86/lib/memcpy_64.S
22134 @@ -33,6 +33,7 @@
22135 rep movsq
22136 movl %edx, %ecx
22137 rep movsb
22138 + pax_force_retaddr
22139 ret
22140 .Lmemcpy_e:
22141 .previous
22142 @@ -49,6 +50,7 @@
22143 movq %rdi, %rax
22144 movq %rdx, %rcx
22145 rep movsb
22146 + pax_force_retaddr
22147 ret
22148 .Lmemcpy_e_e:
22149 .previous
22150 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22151 */
22152 movq 0*8(%rsi), %r8
22153 movq 1*8(%rsi), %r9
22154 - movq 2*8(%rsi), %r10
22155 + movq 2*8(%rsi), %rcx
22156 movq 3*8(%rsi), %r11
22157 leaq 4*8(%rsi), %rsi
22158
22159 movq %r8, 0*8(%rdi)
22160 movq %r9, 1*8(%rdi)
22161 - movq %r10, 2*8(%rdi)
22162 + movq %rcx, 2*8(%rdi)
22163 movq %r11, 3*8(%rdi)
22164 leaq 4*8(%rdi), %rdi
22165 jae .Lcopy_forward_loop
22166 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22167 subq $0x20, %rdx
22168 movq -1*8(%rsi), %r8
22169 movq -2*8(%rsi), %r9
22170 - movq -3*8(%rsi), %r10
22171 + movq -3*8(%rsi), %rcx
22172 movq -4*8(%rsi), %r11
22173 leaq -4*8(%rsi), %rsi
22174 movq %r8, -1*8(%rdi)
22175 movq %r9, -2*8(%rdi)
22176 - movq %r10, -3*8(%rdi)
22177 + movq %rcx, -3*8(%rdi)
22178 movq %r11, -4*8(%rdi)
22179 leaq -4*8(%rdi), %rdi
22180 jae .Lcopy_backward_loop
22181 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22182 */
22183 movq 0*8(%rsi), %r8
22184 movq 1*8(%rsi), %r9
22185 - movq -2*8(%rsi, %rdx), %r10
22186 + movq -2*8(%rsi, %rdx), %rcx
22187 movq -1*8(%rsi, %rdx), %r11
22188 movq %r8, 0*8(%rdi)
22189 movq %r9, 1*8(%rdi)
22190 - movq %r10, -2*8(%rdi, %rdx)
22191 + movq %rcx, -2*8(%rdi, %rdx)
22192 movq %r11, -1*8(%rdi, %rdx)
22193 + pax_force_retaddr
22194 retq
22195 .p2align 4
22196 .Lless_16bytes:
22197 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22198 movq -1*8(%rsi, %rdx), %r9
22199 movq %r8, 0*8(%rdi)
22200 movq %r9, -1*8(%rdi, %rdx)
22201 + pax_force_retaddr
22202 retq
22203 .p2align 4
22204 .Lless_8bytes:
22205 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22206 movl -4(%rsi, %rdx), %r8d
22207 movl %ecx, (%rdi)
22208 movl %r8d, -4(%rdi, %rdx)
22209 + pax_force_retaddr
22210 retq
22211 .p2align 4
22212 .Lless_3bytes:
22213 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22214 movb %cl, (%rdi)
22215
22216 .Lend:
22217 + pax_force_retaddr
22218 retq
22219 CFI_ENDPROC
22220 ENDPROC(memcpy)
22221 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22222 index ee16461..c39c199 100644
22223 --- a/arch/x86/lib/memmove_64.S
22224 +++ b/arch/x86/lib/memmove_64.S
22225 @@ -61,13 +61,13 @@ ENTRY(memmove)
22226 5:
22227 sub $0x20, %rdx
22228 movq 0*8(%rsi), %r11
22229 - movq 1*8(%rsi), %r10
22230 + movq 1*8(%rsi), %rcx
22231 movq 2*8(%rsi), %r9
22232 movq 3*8(%rsi), %r8
22233 leaq 4*8(%rsi), %rsi
22234
22235 movq %r11, 0*8(%rdi)
22236 - movq %r10, 1*8(%rdi)
22237 + movq %rcx, 1*8(%rdi)
22238 movq %r9, 2*8(%rdi)
22239 movq %r8, 3*8(%rdi)
22240 leaq 4*8(%rdi), %rdi
22241 @@ -81,10 +81,10 @@ ENTRY(memmove)
22242 4:
22243 movq %rdx, %rcx
22244 movq -8(%rsi, %rdx), %r11
22245 - lea -8(%rdi, %rdx), %r10
22246 + lea -8(%rdi, %rdx), %r9
22247 shrq $3, %rcx
22248 rep movsq
22249 - movq %r11, (%r10)
22250 + movq %r11, (%r9)
22251 jmp 13f
22252 .Lmemmove_end_forward:
22253
22254 @@ -95,14 +95,14 @@ ENTRY(memmove)
22255 7:
22256 movq %rdx, %rcx
22257 movq (%rsi), %r11
22258 - movq %rdi, %r10
22259 + movq %rdi, %r9
22260 leaq -8(%rsi, %rdx), %rsi
22261 leaq -8(%rdi, %rdx), %rdi
22262 shrq $3, %rcx
22263 std
22264 rep movsq
22265 cld
22266 - movq %r11, (%r10)
22267 + movq %r11, (%r9)
22268 jmp 13f
22269
22270 /*
22271 @@ -127,13 +127,13 @@ ENTRY(memmove)
22272 8:
22273 subq $0x20, %rdx
22274 movq -1*8(%rsi), %r11
22275 - movq -2*8(%rsi), %r10
22276 + movq -2*8(%rsi), %rcx
22277 movq -3*8(%rsi), %r9
22278 movq -4*8(%rsi), %r8
22279 leaq -4*8(%rsi), %rsi
22280
22281 movq %r11, -1*8(%rdi)
22282 - movq %r10, -2*8(%rdi)
22283 + movq %rcx, -2*8(%rdi)
22284 movq %r9, -3*8(%rdi)
22285 movq %r8, -4*8(%rdi)
22286 leaq -4*8(%rdi), %rdi
22287 @@ -151,11 +151,11 @@ ENTRY(memmove)
22288 * Move data from 16 bytes to 31 bytes.
22289 */
22290 movq 0*8(%rsi), %r11
22291 - movq 1*8(%rsi), %r10
22292 + movq 1*8(%rsi), %rcx
22293 movq -2*8(%rsi, %rdx), %r9
22294 movq -1*8(%rsi, %rdx), %r8
22295 movq %r11, 0*8(%rdi)
22296 - movq %r10, 1*8(%rdi)
22297 + movq %rcx, 1*8(%rdi)
22298 movq %r9, -2*8(%rdi, %rdx)
22299 movq %r8, -1*8(%rdi, %rdx)
22300 jmp 13f
22301 @@ -167,9 +167,9 @@ ENTRY(memmove)
22302 * Move data from 8 bytes to 15 bytes.
22303 */
22304 movq 0*8(%rsi), %r11
22305 - movq -1*8(%rsi, %rdx), %r10
22306 + movq -1*8(%rsi, %rdx), %r9
22307 movq %r11, 0*8(%rdi)
22308 - movq %r10, -1*8(%rdi, %rdx)
22309 + movq %r9, -1*8(%rdi, %rdx)
22310 jmp 13f
22311 10:
22312 cmpq $4, %rdx
22313 @@ -178,9 +178,9 @@ ENTRY(memmove)
22314 * Move data from 4 bytes to 7 bytes.
22315 */
22316 movl (%rsi), %r11d
22317 - movl -4(%rsi, %rdx), %r10d
22318 + movl -4(%rsi, %rdx), %r9d
22319 movl %r11d, (%rdi)
22320 - movl %r10d, -4(%rdi, %rdx)
22321 + movl %r9d, -4(%rdi, %rdx)
22322 jmp 13f
22323 11:
22324 cmp $2, %rdx
22325 @@ -189,9 +189,9 @@ ENTRY(memmove)
22326 * Move data from 2 bytes to 3 bytes.
22327 */
22328 movw (%rsi), %r11w
22329 - movw -2(%rsi, %rdx), %r10w
22330 + movw -2(%rsi, %rdx), %r9w
22331 movw %r11w, (%rdi)
22332 - movw %r10w, -2(%rdi, %rdx)
22333 + movw %r9w, -2(%rdi, %rdx)
22334 jmp 13f
22335 12:
22336 cmp $1, %rdx
22337 @@ -202,6 +202,7 @@ ENTRY(memmove)
22338 movb (%rsi), %r11b
22339 movb %r11b, (%rdi)
22340 13:
22341 + pax_force_retaddr
22342 retq
22343 CFI_ENDPROC
22344
22345 @@ -210,6 +211,7 @@ ENTRY(memmove)
22346 /* Forward moving data. */
22347 movq %rdx, %rcx
22348 rep movsb
22349 + pax_force_retaddr
22350 retq
22351 .Lmemmove_end_forward_efs:
22352 .previous
22353 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22354 index 2dcb380..963660a 100644
22355 --- a/arch/x86/lib/memset_64.S
22356 +++ b/arch/x86/lib/memset_64.S
22357 @@ -30,6 +30,7 @@
22358 movl %edx,%ecx
22359 rep stosb
22360 movq %r9,%rax
22361 + pax_force_retaddr
22362 ret
22363 .Lmemset_e:
22364 .previous
22365 @@ -52,6 +53,7 @@
22366 movq %rdx,%rcx
22367 rep stosb
22368 movq %r9,%rax
22369 + pax_force_retaddr
22370 ret
22371 .Lmemset_e_e:
22372 .previous
22373 @@ -59,7 +61,7 @@
22374 ENTRY(memset)
22375 ENTRY(__memset)
22376 CFI_STARTPROC
22377 - movq %rdi,%r10
22378 + movq %rdi,%r11
22379
22380 /* expand byte value */
22381 movzbl %sil,%ecx
22382 @@ -117,7 +119,8 @@ ENTRY(__memset)
22383 jnz .Lloop_1
22384
22385 .Lende:
22386 - movq %r10,%rax
22387 + movq %r11,%rax
22388 + pax_force_retaddr
22389 ret
22390
22391 CFI_RESTORE_STATE
22392 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22393 index c9f2d9b..e7fd2c0 100644
22394 --- a/arch/x86/lib/mmx_32.c
22395 +++ b/arch/x86/lib/mmx_32.c
22396 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22397 {
22398 void *p;
22399 int i;
22400 + unsigned long cr0;
22401
22402 if (unlikely(in_interrupt()))
22403 return __memcpy(to, from, len);
22404 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22405 kernel_fpu_begin();
22406
22407 __asm__ __volatile__ (
22408 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22409 - " prefetch 64(%0)\n"
22410 - " prefetch 128(%0)\n"
22411 - " prefetch 192(%0)\n"
22412 - " prefetch 256(%0)\n"
22413 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22414 + " prefetch 64(%1)\n"
22415 + " prefetch 128(%1)\n"
22416 + " prefetch 192(%1)\n"
22417 + " prefetch 256(%1)\n"
22418 "2: \n"
22419 ".section .fixup, \"ax\"\n"
22420 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22421 + "3: \n"
22422 +
22423 +#ifdef CONFIG_PAX_KERNEXEC
22424 + " movl %%cr0, %0\n"
22425 + " movl %0, %%eax\n"
22426 + " andl $0xFFFEFFFF, %%eax\n"
22427 + " movl %%eax, %%cr0\n"
22428 +#endif
22429 +
22430 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22431 +
22432 +#ifdef CONFIG_PAX_KERNEXEC
22433 + " movl %0, %%cr0\n"
22434 +#endif
22435 +
22436 " jmp 2b\n"
22437 ".previous\n"
22438 _ASM_EXTABLE(1b, 3b)
22439 - : : "r" (from));
22440 + : "=&r" (cr0) : "r" (from) : "ax");
22441
22442 for ( ; i > 5; i--) {
22443 __asm__ __volatile__ (
22444 - "1: prefetch 320(%0)\n"
22445 - "2: movq (%0), %%mm0\n"
22446 - " movq 8(%0), %%mm1\n"
22447 - " movq 16(%0), %%mm2\n"
22448 - " movq 24(%0), %%mm3\n"
22449 - " movq %%mm0, (%1)\n"
22450 - " movq %%mm1, 8(%1)\n"
22451 - " movq %%mm2, 16(%1)\n"
22452 - " movq %%mm3, 24(%1)\n"
22453 - " movq 32(%0), %%mm0\n"
22454 - " movq 40(%0), %%mm1\n"
22455 - " movq 48(%0), %%mm2\n"
22456 - " movq 56(%0), %%mm3\n"
22457 - " movq %%mm0, 32(%1)\n"
22458 - " movq %%mm1, 40(%1)\n"
22459 - " movq %%mm2, 48(%1)\n"
22460 - " movq %%mm3, 56(%1)\n"
22461 + "1: prefetch 320(%1)\n"
22462 + "2: movq (%1), %%mm0\n"
22463 + " movq 8(%1), %%mm1\n"
22464 + " movq 16(%1), %%mm2\n"
22465 + " movq 24(%1), %%mm3\n"
22466 + " movq %%mm0, (%2)\n"
22467 + " movq %%mm1, 8(%2)\n"
22468 + " movq %%mm2, 16(%2)\n"
22469 + " movq %%mm3, 24(%2)\n"
22470 + " movq 32(%1), %%mm0\n"
22471 + " movq 40(%1), %%mm1\n"
22472 + " movq 48(%1), %%mm2\n"
22473 + " movq 56(%1), %%mm3\n"
22474 + " movq %%mm0, 32(%2)\n"
22475 + " movq %%mm1, 40(%2)\n"
22476 + " movq %%mm2, 48(%2)\n"
22477 + " movq %%mm3, 56(%2)\n"
22478 ".section .fixup, \"ax\"\n"
22479 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22480 + "3:\n"
22481 +
22482 +#ifdef CONFIG_PAX_KERNEXEC
22483 + " movl %%cr0, %0\n"
22484 + " movl %0, %%eax\n"
22485 + " andl $0xFFFEFFFF, %%eax\n"
22486 + " movl %%eax, %%cr0\n"
22487 +#endif
22488 +
22489 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22490 +
22491 +#ifdef CONFIG_PAX_KERNEXEC
22492 + " movl %0, %%cr0\n"
22493 +#endif
22494 +
22495 " jmp 2b\n"
22496 ".previous\n"
22497 _ASM_EXTABLE(1b, 3b)
22498 - : : "r" (from), "r" (to) : "memory");
22499 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22500
22501 from += 64;
22502 to += 64;
22503 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22504 static void fast_copy_page(void *to, void *from)
22505 {
22506 int i;
22507 + unsigned long cr0;
22508
22509 kernel_fpu_begin();
22510
22511 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22512 * but that is for later. -AV
22513 */
22514 __asm__ __volatile__(
22515 - "1: prefetch (%0)\n"
22516 - " prefetch 64(%0)\n"
22517 - " prefetch 128(%0)\n"
22518 - " prefetch 192(%0)\n"
22519 - " prefetch 256(%0)\n"
22520 + "1: prefetch (%1)\n"
22521 + " prefetch 64(%1)\n"
22522 + " prefetch 128(%1)\n"
22523 + " prefetch 192(%1)\n"
22524 + " prefetch 256(%1)\n"
22525 "2: \n"
22526 ".section .fixup, \"ax\"\n"
22527 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22528 + "3: \n"
22529 +
22530 +#ifdef CONFIG_PAX_KERNEXEC
22531 + " movl %%cr0, %0\n"
22532 + " movl %0, %%eax\n"
22533 + " andl $0xFFFEFFFF, %%eax\n"
22534 + " movl %%eax, %%cr0\n"
22535 +#endif
22536 +
22537 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22538 +
22539 +#ifdef CONFIG_PAX_KERNEXEC
22540 + " movl %0, %%cr0\n"
22541 +#endif
22542 +
22543 " jmp 2b\n"
22544 ".previous\n"
22545 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22546 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22547
22548 for (i = 0; i < (4096-320)/64; i++) {
22549 __asm__ __volatile__ (
22550 - "1: prefetch 320(%0)\n"
22551 - "2: movq (%0), %%mm0\n"
22552 - " movntq %%mm0, (%1)\n"
22553 - " movq 8(%0), %%mm1\n"
22554 - " movntq %%mm1, 8(%1)\n"
22555 - " movq 16(%0), %%mm2\n"
22556 - " movntq %%mm2, 16(%1)\n"
22557 - " movq 24(%0), %%mm3\n"
22558 - " movntq %%mm3, 24(%1)\n"
22559 - " movq 32(%0), %%mm4\n"
22560 - " movntq %%mm4, 32(%1)\n"
22561 - " movq 40(%0), %%mm5\n"
22562 - " movntq %%mm5, 40(%1)\n"
22563 - " movq 48(%0), %%mm6\n"
22564 - " movntq %%mm6, 48(%1)\n"
22565 - " movq 56(%0), %%mm7\n"
22566 - " movntq %%mm7, 56(%1)\n"
22567 + "1: prefetch 320(%1)\n"
22568 + "2: movq (%1), %%mm0\n"
22569 + " movntq %%mm0, (%2)\n"
22570 + " movq 8(%1), %%mm1\n"
22571 + " movntq %%mm1, 8(%2)\n"
22572 + " movq 16(%1), %%mm2\n"
22573 + " movntq %%mm2, 16(%2)\n"
22574 + " movq 24(%1), %%mm3\n"
22575 + " movntq %%mm3, 24(%2)\n"
22576 + " movq 32(%1), %%mm4\n"
22577 + " movntq %%mm4, 32(%2)\n"
22578 + " movq 40(%1), %%mm5\n"
22579 + " movntq %%mm5, 40(%2)\n"
22580 + " movq 48(%1), %%mm6\n"
22581 + " movntq %%mm6, 48(%2)\n"
22582 + " movq 56(%1), %%mm7\n"
22583 + " movntq %%mm7, 56(%2)\n"
22584 ".section .fixup, \"ax\"\n"
22585 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22586 + "3:\n"
22587 +
22588 +#ifdef CONFIG_PAX_KERNEXEC
22589 + " movl %%cr0, %0\n"
22590 + " movl %0, %%eax\n"
22591 + " andl $0xFFFEFFFF, %%eax\n"
22592 + " movl %%eax, %%cr0\n"
22593 +#endif
22594 +
22595 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22596 +
22597 +#ifdef CONFIG_PAX_KERNEXEC
22598 + " movl %0, %%cr0\n"
22599 +#endif
22600 +
22601 " jmp 2b\n"
22602 ".previous\n"
22603 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22604 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22605
22606 from += 64;
22607 to += 64;
22608 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22609 static void fast_copy_page(void *to, void *from)
22610 {
22611 int i;
22612 + unsigned long cr0;
22613
22614 kernel_fpu_begin();
22615
22616 __asm__ __volatile__ (
22617 - "1: prefetch (%0)\n"
22618 - " prefetch 64(%0)\n"
22619 - " prefetch 128(%0)\n"
22620 - " prefetch 192(%0)\n"
22621 - " prefetch 256(%0)\n"
22622 + "1: prefetch (%1)\n"
22623 + " prefetch 64(%1)\n"
22624 + " prefetch 128(%1)\n"
22625 + " prefetch 192(%1)\n"
22626 + " prefetch 256(%1)\n"
22627 "2: \n"
22628 ".section .fixup, \"ax\"\n"
22629 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22630 + "3: \n"
22631 +
22632 +#ifdef CONFIG_PAX_KERNEXEC
22633 + " movl %%cr0, %0\n"
22634 + " movl %0, %%eax\n"
22635 + " andl $0xFFFEFFFF, %%eax\n"
22636 + " movl %%eax, %%cr0\n"
22637 +#endif
22638 +
22639 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22640 +
22641 +#ifdef CONFIG_PAX_KERNEXEC
22642 + " movl %0, %%cr0\n"
22643 +#endif
22644 +
22645 " jmp 2b\n"
22646 ".previous\n"
22647 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22648 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22649
22650 for (i = 0; i < 4096/64; i++) {
22651 __asm__ __volatile__ (
22652 - "1: prefetch 320(%0)\n"
22653 - "2: movq (%0), %%mm0\n"
22654 - " movq 8(%0), %%mm1\n"
22655 - " movq 16(%0), %%mm2\n"
22656 - " movq 24(%0), %%mm3\n"
22657 - " movq %%mm0, (%1)\n"
22658 - " movq %%mm1, 8(%1)\n"
22659 - " movq %%mm2, 16(%1)\n"
22660 - " movq %%mm3, 24(%1)\n"
22661 - " movq 32(%0), %%mm0\n"
22662 - " movq 40(%0), %%mm1\n"
22663 - " movq 48(%0), %%mm2\n"
22664 - " movq 56(%0), %%mm3\n"
22665 - " movq %%mm0, 32(%1)\n"
22666 - " movq %%mm1, 40(%1)\n"
22667 - " movq %%mm2, 48(%1)\n"
22668 - " movq %%mm3, 56(%1)\n"
22669 + "1: prefetch 320(%1)\n"
22670 + "2: movq (%1), %%mm0\n"
22671 + " movq 8(%1), %%mm1\n"
22672 + " movq 16(%1), %%mm2\n"
22673 + " movq 24(%1), %%mm3\n"
22674 + " movq %%mm0, (%2)\n"
22675 + " movq %%mm1, 8(%2)\n"
22676 + " movq %%mm2, 16(%2)\n"
22677 + " movq %%mm3, 24(%2)\n"
22678 + " movq 32(%1), %%mm0\n"
22679 + " movq 40(%1), %%mm1\n"
22680 + " movq 48(%1), %%mm2\n"
22681 + " movq 56(%1), %%mm3\n"
22682 + " movq %%mm0, 32(%2)\n"
22683 + " movq %%mm1, 40(%2)\n"
22684 + " movq %%mm2, 48(%2)\n"
22685 + " movq %%mm3, 56(%2)\n"
22686 ".section .fixup, \"ax\"\n"
22687 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22688 + "3:\n"
22689 +
22690 +#ifdef CONFIG_PAX_KERNEXEC
22691 + " movl %%cr0, %0\n"
22692 + " movl %0, %%eax\n"
22693 + " andl $0xFFFEFFFF, %%eax\n"
22694 + " movl %%eax, %%cr0\n"
22695 +#endif
22696 +
22697 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22698 +
22699 +#ifdef CONFIG_PAX_KERNEXEC
22700 + " movl %0, %%cr0\n"
22701 +#endif
22702 +
22703 " jmp 2b\n"
22704 ".previous\n"
22705 _ASM_EXTABLE(1b, 3b)
22706 - : : "r" (from), "r" (to) : "memory");
22707 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22708
22709 from += 64;
22710 to += 64;
22711 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22712 index f6d13ee..aca5f0b 100644
22713 --- a/arch/x86/lib/msr-reg.S
22714 +++ b/arch/x86/lib/msr-reg.S
22715 @@ -3,6 +3,7 @@
22716 #include <asm/dwarf2.h>
22717 #include <asm/asm.h>
22718 #include <asm/msr.h>
22719 +#include <asm/alternative-asm.h>
22720
22721 #ifdef CONFIG_X86_64
22722 /*
22723 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22724 CFI_STARTPROC
22725 pushq_cfi %rbx
22726 pushq_cfi %rbp
22727 - movq %rdi, %r10 /* Save pointer */
22728 + movq %rdi, %r9 /* Save pointer */
22729 xorl %r11d, %r11d /* Return value */
22730 movl (%rdi), %eax
22731 movl 4(%rdi), %ecx
22732 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22733 movl 28(%rdi), %edi
22734 CFI_REMEMBER_STATE
22735 1: \op
22736 -2: movl %eax, (%r10)
22737 +2: movl %eax, (%r9)
22738 movl %r11d, %eax /* Return value */
22739 - movl %ecx, 4(%r10)
22740 - movl %edx, 8(%r10)
22741 - movl %ebx, 12(%r10)
22742 - movl %ebp, 20(%r10)
22743 - movl %esi, 24(%r10)
22744 - movl %edi, 28(%r10)
22745 + movl %ecx, 4(%r9)
22746 + movl %edx, 8(%r9)
22747 + movl %ebx, 12(%r9)
22748 + movl %ebp, 20(%r9)
22749 + movl %esi, 24(%r9)
22750 + movl %edi, 28(%r9)
22751 popq_cfi %rbp
22752 popq_cfi %rbx
22753 + pax_force_retaddr
22754 ret
22755 3:
22756 CFI_RESTORE_STATE
22757 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22758 index fc6ba17..04471c5 100644
22759 --- a/arch/x86/lib/putuser.S
22760 +++ b/arch/x86/lib/putuser.S
22761 @@ -16,7 +16,9 @@
22762 #include <asm/errno.h>
22763 #include <asm/asm.h>
22764 #include <asm/smap.h>
22765 -
22766 +#include <asm/segment.h>
22767 +#include <asm/pgtable.h>
22768 +#include <asm/alternative-asm.h>
22769
22770 /*
22771 * __put_user_X
22772 @@ -30,57 +32,125 @@
22773 * as they get called from within inline assembly.
22774 */
22775
22776 -#define ENTER CFI_STARTPROC ; \
22777 - GET_THREAD_INFO(%_ASM_BX)
22778 -#define EXIT ASM_CLAC ; \
22779 - ret ; \
22780 +#define ENTER CFI_STARTPROC
22781 +#define EXIT ASM_CLAC ; \
22782 + pax_force_retaddr ; \
22783 + ret ; \
22784 CFI_ENDPROC
22785
22786 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22787 +#define _DEST %_ASM_CX,%_ASM_BX
22788 +#else
22789 +#define _DEST %_ASM_CX
22790 +#endif
22791 +
22792 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22793 +#define __copyuser_seg gs;
22794 +#else
22795 +#define __copyuser_seg
22796 +#endif
22797 +
22798 .text
22799 ENTRY(__put_user_1)
22800 ENTER
22801 +
22802 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22803 + GET_THREAD_INFO(%_ASM_BX)
22804 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22805 jae bad_put_user
22806 ASM_STAC
22807 -1: movb %al,(%_ASM_CX)
22808 +
22809 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22810 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22811 + cmp %_ASM_BX,%_ASM_CX
22812 + jb 1234f
22813 + xor %ebx,%ebx
22814 +1234:
22815 +#endif
22816 +
22817 +#endif
22818 +
22819 +1: __copyuser_seg movb %al,(_DEST)
22820 xor %eax,%eax
22821 EXIT
22822 ENDPROC(__put_user_1)
22823
22824 ENTRY(__put_user_2)
22825 ENTER
22826 +
22827 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22828 + GET_THREAD_INFO(%_ASM_BX)
22829 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22830 sub $1,%_ASM_BX
22831 cmp %_ASM_BX,%_ASM_CX
22832 jae bad_put_user
22833 ASM_STAC
22834 -2: movw %ax,(%_ASM_CX)
22835 +
22836 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22837 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22838 + cmp %_ASM_BX,%_ASM_CX
22839 + jb 1234f
22840 + xor %ebx,%ebx
22841 +1234:
22842 +#endif
22843 +
22844 +#endif
22845 +
22846 +2: __copyuser_seg movw %ax,(_DEST)
22847 xor %eax,%eax
22848 EXIT
22849 ENDPROC(__put_user_2)
22850
22851 ENTRY(__put_user_4)
22852 ENTER
22853 +
22854 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22855 + GET_THREAD_INFO(%_ASM_BX)
22856 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22857 sub $3,%_ASM_BX
22858 cmp %_ASM_BX,%_ASM_CX
22859 jae bad_put_user
22860 ASM_STAC
22861 -3: movl %eax,(%_ASM_CX)
22862 +
22863 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22864 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22865 + cmp %_ASM_BX,%_ASM_CX
22866 + jb 1234f
22867 + xor %ebx,%ebx
22868 +1234:
22869 +#endif
22870 +
22871 +#endif
22872 +
22873 +3: __copyuser_seg movl %eax,(_DEST)
22874 xor %eax,%eax
22875 EXIT
22876 ENDPROC(__put_user_4)
22877
22878 ENTRY(__put_user_8)
22879 ENTER
22880 +
22881 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22882 + GET_THREAD_INFO(%_ASM_BX)
22883 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22884 sub $7,%_ASM_BX
22885 cmp %_ASM_BX,%_ASM_CX
22886 jae bad_put_user
22887 ASM_STAC
22888 -4: mov %_ASM_AX,(%_ASM_CX)
22889 +
22890 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22891 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22892 + cmp %_ASM_BX,%_ASM_CX
22893 + jb 1234f
22894 + xor %ebx,%ebx
22895 +1234:
22896 +#endif
22897 +
22898 +#endif
22899 +
22900 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22901 #ifdef CONFIG_X86_32
22902 -5: movl %edx,4(%_ASM_CX)
22903 +5: __copyuser_seg movl %edx,4(_DEST)
22904 #endif
22905 xor %eax,%eax
22906 EXIT
22907 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22908 index 1cad221..de671ee 100644
22909 --- a/arch/x86/lib/rwlock.S
22910 +++ b/arch/x86/lib/rwlock.S
22911 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22912 FRAME
22913 0: LOCK_PREFIX
22914 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22915 +
22916 +#ifdef CONFIG_PAX_REFCOUNT
22917 + jno 1234f
22918 + LOCK_PREFIX
22919 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22920 + int $4
22921 +1234:
22922 + _ASM_EXTABLE(1234b, 1234b)
22923 +#endif
22924 +
22925 1: rep; nop
22926 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22927 jne 1b
22928 LOCK_PREFIX
22929 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22930 +
22931 +#ifdef CONFIG_PAX_REFCOUNT
22932 + jno 1234f
22933 + LOCK_PREFIX
22934 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22935 + int $4
22936 +1234:
22937 + _ASM_EXTABLE(1234b, 1234b)
22938 +#endif
22939 +
22940 jnz 0b
22941 ENDFRAME
22942 + pax_force_retaddr
22943 ret
22944 CFI_ENDPROC
22945 END(__write_lock_failed)
22946 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22947 FRAME
22948 0: LOCK_PREFIX
22949 READ_LOCK_SIZE(inc) (%__lock_ptr)
22950 +
22951 +#ifdef CONFIG_PAX_REFCOUNT
22952 + jno 1234f
22953 + LOCK_PREFIX
22954 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22955 + int $4
22956 +1234:
22957 + _ASM_EXTABLE(1234b, 1234b)
22958 +#endif
22959 +
22960 1: rep; nop
22961 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22962 js 1b
22963 LOCK_PREFIX
22964 READ_LOCK_SIZE(dec) (%__lock_ptr)
22965 +
22966 +#ifdef CONFIG_PAX_REFCOUNT
22967 + jno 1234f
22968 + LOCK_PREFIX
22969 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22970 + int $4
22971 +1234:
22972 + _ASM_EXTABLE(1234b, 1234b)
22973 +#endif
22974 +
22975 js 0b
22976 ENDFRAME
22977 + pax_force_retaddr
22978 ret
22979 CFI_ENDPROC
22980 END(__read_lock_failed)
22981 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22982 index 5dff5f0..cadebf4 100644
22983 --- a/arch/x86/lib/rwsem.S
22984 +++ b/arch/x86/lib/rwsem.S
22985 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22986 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22987 CFI_RESTORE __ASM_REG(dx)
22988 restore_common_regs
22989 + pax_force_retaddr
22990 ret
22991 CFI_ENDPROC
22992 ENDPROC(call_rwsem_down_read_failed)
22993 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22994 movq %rax,%rdi
22995 call rwsem_down_write_failed
22996 restore_common_regs
22997 + pax_force_retaddr
22998 ret
22999 CFI_ENDPROC
23000 ENDPROC(call_rwsem_down_write_failed)
23001 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
23002 movq %rax,%rdi
23003 call rwsem_wake
23004 restore_common_regs
23005 -1: ret
23006 +1: pax_force_retaddr
23007 + ret
23008 CFI_ENDPROC
23009 ENDPROC(call_rwsem_wake)
23010
23011 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
23012 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23013 CFI_RESTORE __ASM_REG(dx)
23014 restore_common_regs
23015 + pax_force_retaddr
23016 ret
23017 CFI_ENDPROC
23018 ENDPROC(call_rwsem_downgrade_wake)
23019 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23020 index a63efd6..ccecad8 100644
23021 --- a/arch/x86/lib/thunk_64.S
23022 +++ b/arch/x86/lib/thunk_64.S
23023 @@ -8,6 +8,7 @@
23024 #include <linux/linkage.h>
23025 #include <asm/dwarf2.h>
23026 #include <asm/calling.h>
23027 +#include <asm/alternative-asm.h>
23028
23029 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23030 .macro THUNK name, func, put_ret_addr_in_rdi=0
23031 @@ -41,5 +42,6 @@
23032 SAVE_ARGS
23033 restore:
23034 RESTORE_ARGS
23035 + pax_force_retaddr
23036 ret
23037 CFI_ENDPROC
23038 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23039 index 98f6d6b6..d27f045 100644
23040 --- a/arch/x86/lib/usercopy_32.c
23041 +++ b/arch/x86/lib/usercopy_32.c
23042 @@ -42,11 +42,13 @@ do { \
23043 int __d0; \
23044 might_fault(); \
23045 __asm__ __volatile__( \
23046 + __COPYUSER_SET_ES \
23047 ASM_STAC "\n" \
23048 "0: rep; stosl\n" \
23049 " movl %2,%0\n" \
23050 "1: rep; stosb\n" \
23051 "2: " ASM_CLAC "\n" \
23052 + __COPYUSER_RESTORE_ES \
23053 ".section .fixup,\"ax\"\n" \
23054 "3: lea 0(%2,%0,4),%0\n" \
23055 " jmp 2b\n" \
23056 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
23057
23058 #ifdef CONFIG_X86_INTEL_USERCOPY
23059 static unsigned long
23060 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
23061 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23062 {
23063 int d0, d1;
23064 __asm__ __volatile__(
23065 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23066 " .align 2,0x90\n"
23067 "3: movl 0(%4), %%eax\n"
23068 "4: movl 4(%4), %%edx\n"
23069 - "5: movl %%eax, 0(%3)\n"
23070 - "6: movl %%edx, 4(%3)\n"
23071 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23072 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23073 "7: movl 8(%4), %%eax\n"
23074 "8: movl 12(%4),%%edx\n"
23075 - "9: movl %%eax, 8(%3)\n"
23076 - "10: movl %%edx, 12(%3)\n"
23077 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23078 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23079 "11: movl 16(%4), %%eax\n"
23080 "12: movl 20(%4), %%edx\n"
23081 - "13: movl %%eax, 16(%3)\n"
23082 - "14: movl %%edx, 20(%3)\n"
23083 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23084 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23085 "15: movl 24(%4), %%eax\n"
23086 "16: movl 28(%4), %%edx\n"
23087 - "17: movl %%eax, 24(%3)\n"
23088 - "18: movl %%edx, 28(%3)\n"
23089 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23090 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23091 "19: movl 32(%4), %%eax\n"
23092 "20: movl 36(%4), %%edx\n"
23093 - "21: movl %%eax, 32(%3)\n"
23094 - "22: movl %%edx, 36(%3)\n"
23095 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23096 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23097 "23: movl 40(%4), %%eax\n"
23098 "24: movl 44(%4), %%edx\n"
23099 - "25: movl %%eax, 40(%3)\n"
23100 - "26: movl %%edx, 44(%3)\n"
23101 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23102 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23103 "27: movl 48(%4), %%eax\n"
23104 "28: movl 52(%4), %%edx\n"
23105 - "29: movl %%eax, 48(%3)\n"
23106 - "30: movl %%edx, 52(%3)\n"
23107 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23108 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23109 "31: movl 56(%4), %%eax\n"
23110 "32: movl 60(%4), %%edx\n"
23111 - "33: movl %%eax, 56(%3)\n"
23112 - "34: movl %%edx, 60(%3)\n"
23113 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23114 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23115 " addl $-64, %0\n"
23116 " addl $64, %4\n"
23117 " addl $64, %3\n"
23118 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23119 " shrl $2, %0\n"
23120 " andl $3, %%eax\n"
23121 " cld\n"
23122 + __COPYUSER_SET_ES
23123 "99: rep; movsl\n"
23124 "36: movl %%eax, %0\n"
23125 "37: rep; movsb\n"
23126 "100:\n"
23127 + __COPYUSER_RESTORE_ES
23128 ".section .fixup,\"ax\"\n"
23129 "101: lea 0(%%eax,%0,4),%0\n"
23130 " jmp 100b\n"
23131 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23132 }
23133
23134 static unsigned long
23135 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23136 +{
23137 + int d0, d1;
23138 + __asm__ __volatile__(
23139 + " .align 2,0x90\n"
23140 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23141 + " cmpl $67, %0\n"
23142 + " jbe 3f\n"
23143 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23144 + " .align 2,0x90\n"
23145 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23146 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23147 + "5: movl %%eax, 0(%3)\n"
23148 + "6: movl %%edx, 4(%3)\n"
23149 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23150 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23151 + "9: movl %%eax, 8(%3)\n"
23152 + "10: movl %%edx, 12(%3)\n"
23153 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23154 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23155 + "13: movl %%eax, 16(%3)\n"
23156 + "14: movl %%edx, 20(%3)\n"
23157 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23158 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23159 + "17: movl %%eax, 24(%3)\n"
23160 + "18: movl %%edx, 28(%3)\n"
23161 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23162 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23163 + "21: movl %%eax, 32(%3)\n"
23164 + "22: movl %%edx, 36(%3)\n"
23165 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23166 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23167 + "25: movl %%eax, 40(%3)\n"
23168 + "26: movl %%edx, 44(%3)\n"
23169 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23170 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23171 + "29: movl %%eax, 48(%3)\n"
23172 + "30: movl %%edx, 52(%3)\n"
23173 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23174 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23175 + "33: movl %%eax, 56(%3)\n"
23176 + "34: movl %%edx, 60(%3)\n"
23177 + " addl $-64, %0\n"
23178 + " addl $64, %4\n"
23179 + " addl $64, %3\n"
23180 + " cmpl $63, %0\n"
23181 + " ja 1b\n"
23182 + "35: movl %0, %%eax\n"
23183 + " shrl $2, %0\n"
23184 + " andl $3, %%eax\n"
23185 + " cld\n"
23186 + "99: rep; "__copyuser_seg" movsl\n"
23187 + "36: movl %%eax, %0\n"
23188 + "37: rep; "__copyuser_seg" movsb\n"
23189 + "100:\n"
23190 + ".section .fixup,\"ax\"\n"
23191 + "101: lea 0(%%eax,%0,4),%0\n"
23192 + " jmp 100b\n"
23193 + ".previous\n"
23194 + _ASM_EXTABLE(1b,100b)
23195 + _ASM_EXTABLE(2b,100b)
23196 + _ASM_EXTABLE(3b,100b)
23197 + _ASM_EXTABLE(4b,100b)
23198 + _ASM_EXTABLE(5b,100b)
23199 + _ASM_EXTABLE(6b,100b)
23200 + _ASM_EXTABLE(7b,100b)
23201 + _ASM_EXTABLE(8b,100b)
23202 + _ASM_EXTABLE(9b,100b)
23203 + _ASM_EXTABLE(10b,100b)
23204 + _ASM_EXTABLE(11b,100b)
23205 + _ASM_EXTABLE(12b,100b)
23206 + _ASM_EXTABLE(13b,100b)
23207 + _ASM_EXTABLE(14b,100b)
23208 + _ASM_EXTABLE(15b,100b)
23209 + _ASM_EXTABLE(16b,100b)
23210 + _ASM_EXTABLE(17b,100b)
23211 + _ASM_EXTABLE(18b,100b)
23212 + _ASM_EXTABLE(19b,100b)
23213 + _ASM_EXTABLE(20b,100b)
23214 + _ASM_EXTABLE(21b,100b)
23215 + _ASM_EXTABLE(22b,100b)
23216 + _ASM_EXTABLE(23b,100b)
23217 + _ASM_EXTABLE(24b,100b)
23218 + _ASM_EXTABLE(25b,100b)
23219 + _ASM_EXTABLE(26b,100b)
23220 + _ASM_EXTABLE(27b,100b)
23221 + _ASM_EXTABLE(28b,100b)
23222 + _ASM_EXTABLE(29b,100b)
23223 + _ASM_EXTABLE(30b,100b)
23224 + _ASM_EXTABLE(31b,100b)
23225 + _ASM_EXTABLE(32b,100b)
23226 + _ASM_EXTABLE(33b,100b)
23227 + _ASM_EXTABLE(34b,100b)
23228 + _ASM_EXTABLE(35b,100b)
23229 + _ASM_EXTABLE(36b,100b)
23230 + _ASM_EXTABLE(37b,100b)
23231 + _ASM_EXTABLE(99b,101b)
23232 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23233 + : "1"(to), "2"(from), "0"(size)
23234 + : "eax", "edx", "memory");
23235 + return size;
23236 +}
23237 +
23238 +static unsigned long __size_overflow(3)
23239 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23240 {
23241 int d0, d1;
23242 __asm__ __volatile__(
23243 " .align 2,0x90\n"
23244 - "0: movl 32(%4), %%eax\n"
23245 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23246 " cmpl $67, %0\n"
23247 " jbe 2f\n"
23248 - "1: movl 64(%4), %%eax\n"
23249 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23250 " .align 2,0x90\n"
23251 - "2: movl 0(%4), %%eax\n"
23252 - "21: movl 4(%4), %%edx\n"
23253 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23254 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23255 " movl %%eax, 0(%3)\n"
23256 " movl %%edx, 4(%3)\n"
23257 - "3: movl 8(%4), %%eax\n"
23258 - "31: movl 12(%4),%%edx\n"
23259 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23260 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23261 " movl %%eax, 8(%3)\n"
23262 " movl %%edx, 12(%3)\n"
23263 - "4: movl 16(%4), %%eax\n"
23264 - "41: movl 20(%4), %%edx\n"
23265 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23266 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23267 " movl %%eax, 16(%3)\n"
23268 " movl %%edx, 20(%3)\n"
23269 - "10: movl 24(%4), %%eax\n"
23270 - "51: movl 28(%4), %%edx\n"
23271 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23272 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23273 " movl %%eax, 24(%3)\n"
23274 " movl %%edx, 28(%3)\n"
23275 - "11: movl 32(%4), %%eax\n"
23276 - "61: movl 36(%4), %%edx\n"
23277 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23278 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23279 " movl %%eax, 32(%3)\n"
23280 " movl %%edx, 36(%3)\n"
23281 - "12: movl 40(%4), %%eax\n"
23282 - "71: movl 44(%4), %%edx\n"
23283 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23284 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23285 " movl %%eax, 40(%3)\n"
23286 " movl %%edx, 44(%3)\n"
23287 - "13: movl 48(%4), %%eax\n"
23288 - "81: movl 52(%4), %%edx\n"
23289 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23290 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23291 " movl %%eax, 48(%3)\n"
23292 " movl %%edx, 52(%3)\n"
23293 - "14: movl 56(%4), %%eax\n"
23294 - "91: movl 60(%4), %%edx\n"
23295 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23296 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23297 " movl %%eax, 56(%3)\n"
23298 " movl %%edx, 60(%3)\n"
23299 " addl $-64, %0\n"
23300 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23301 " shrl $2, %0\n"
23302 " andl $3, %%eax\n"
23303 " cld\n"
23304 - "6: rep; movsl\n"
23305 + "6: rep; "__copyuser_seg" movsl\n"
23306 " movl %%eax,%0\n"
23307 - "7: rep; movsb\n"
23308 + "7: rep; "__copyuser_seg" movsb\n"
23309 "8:\n"
23310 ".section .fixup,\"ax\"\n"
23311 "9: lea 0(%%eax,%0,4),%0\n"
23312 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23313 * hyoshiok@miraclelinux.com
23314 */
23315
23316 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23317 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23318 const void __user *from, unsigned long size)
23319 {
23320 int d0, d1;
23321
23322 __asm__ __volatile__(
23323 " .align 2,0x90\n"
23324 - "0: movl 32(%4), %%eax\n"
23325 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23326 " cmpl $67, %0\n"
23327 " jbe 2f\n"
23328 - "1: movl 64(%4), %%eax\n"
23329 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23330 " .align 2,0x90\n"
23331 - "2: movl 0(%4), %%eax\n"
23332 - "21: movl 4(%4), %%edx\n"
23333 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23334 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23335 " movnti %%eax, 0(%3)\n"
23336 " movnti %%edx, 4(%3)\n"
23337 - "3: movl 8(%4), %%eax\n"
23338 - "31: movl 12(%4),%%edx\n"
23339 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23340 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23341 " movnti %%eax, 8(%3)\n"
23342 " movnti %%edx, 12(%3)\n"
23343 - "4: movl 16(%4), %%eax\n"
23344 - "41: movl 20(%4), %%edx\n"
23345 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23346 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23347 " movnti %%eax, 16(%3)\n"
23348 " movnti %%edx, 20(%3)\n"
23349 - "10: movl 24(%4), %%eax\n"
23350 - "51: movl 28(%4), %%edx\n"
23351 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23352 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23353 " movnti %%eax, 24(%3)\n"
23354 " movnti %%edx, 28(%3)\n"
23355 - "11: movl 32(%4), %%eax\n"
23356 - "61: movl 36(%4), %%edx\n"
23357 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23358 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23359 " movnti %%eax, 32(%3)\n"
23360 " movnti %%edx, 36(%3)\n"
23361 - "12: movl 40(%4), %%eax\n"
23362 - "71: movl 44(%4), %%edx\n"
23363 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23364 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23365 " movnti %%eax, 40(%3)\n"
23366 " movnti %%edx, 44(%3)\n"
23367 - "13: movl 48(%4), %%eax\n"
23368 - "81: movl 52(%4), %%edx\n"
23369 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23370 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23371 " movnti %%eax, 48(%3)\n"
23372 " movnti %%edx, 52(%3)\n"
23373 - "14: movl 56(%4), %%eax\n"
23374 - "91: movl 60(%4), %%edx\n"
23375 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23376 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23377 " movnti %%eax, 56(%3)\n"
23378 " movnti %%edx, 60(%3)\n"
23379 " addl $-64, %0\n"
23380 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23381 " shrl $2, %0\n"
23382 " andl $3, %%eax\n"
23383 " cld\n"
23384 - "6: rep; movsl\n"
23385 + "6: rep; "__copyuser_seg" movsl\n"
23386 " movl %%eax,%0\n"
23387 - "7: rep; movsb\n"
23388 + "7: rep; "__copyuser_seg" movsb\n"
23389 "8:\n"
23390 ".section .fixup,\"ax\"\n"
23391 "9: lea 0(%%eax,%0,4),%0\n"
23392 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23393 return size;
23394 }
23395
23396 -static unsigned long __copy_user_intel_nocache(void *to,
23397 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23398 const void __user *from, unsigned long size)
23399 {
23400 int d0, d1;
23401
23402 __asm__ __volatile__(
23403 " .align 2,0x90\n"
23404 - "0: movl 32(%4), %%eax\n"
23405 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23406 " cmpl $67, %0\n"
23407 " jbe 2f\n"
23408 - "1: movl 64(%4), %%eax\n"
23409 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23410 " .align 2,0x90\n"
23411 - "2: movl 0(%4), %%eax\n"
23412 - "21: movl 4(%4), %%edx\n"
23413 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23414 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23415 " movnti %%eax, 0(%3)\n"
23416 " movnti %%edx, 4(%3)\n"
23417 - "3: movl 8(%4), %%eax\n"
23418 - "31: movl 12(%4),%%edx\n"
23419 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23420 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23421 " movnti %%eax, 8(%3)\n"
23422 " movnti %%edx, 12(%3)\n"
23423 - "4: movl 16(%4), %%eax\n"
23424 - "41: movl 20(%4), %%edx\n"
23425 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23426 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23427 " movnti %%eax, 16(%3)\n"
23428 " movnti %%edx, 20(%3)\n"
23429 - "10: movl 24(%4), %%eax\n"
23430 - "51: movl 28(%4), %%edx\n"
23431 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23432 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23433 " movnti %%eax, 24(%3)\n"
23434 " movnti %%edx, 28(%3)\n"
23435 - "11: movl 32(%4), %%eax\n"
23436 - "61: movl 36(%4), %%edx\n"
23437 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23438 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23439 " movnti %%eax, 32(%3)\n"
23440 " movnti %%edx, 36(%3)\n"
23441 - "12: movl 40(%4), %%eax\n"
23442 - "71: movl 44(%4), %%edx\n"
23443 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23444 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23445 " movnti %%eax, 40(%3)\n"
23446 " movnti %%edx, 44(%3)\n"
23447 - "13: movl 48(%4), %%eax\n"
23448 - "81: movl 52(%4), %%edx\n"
23449 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23450 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23451 " movnti %%eax, 48(%3)\n"
23452 " movnti %%edx, 52(%3)\n"
23453 - "14: movl 56(%4), %%eax\n"
23454 - "91: movl 60(%4), %%edx\n"
23455 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23456 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23457 " movnti %%eax, 56(%3)\n"
23458 " movnti %%edx, 60(%3)\n"
23459 " addl $-64, %0\n"
23460 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23461 " shrl $2, %0\n"
23462 " andl $3, %%eax\n"
23463 " cld\n"
23464 - "6: rep; movsl\n"
23465 + "6: rep; "__copyuser_seg" movsl\n"
23466 " movl %%eax,%0\n"
23467 - "7: rep; movsb\n"
23468 + "7: rep; "__copyuser_seg" movsb\n"
23469 "8:\n"
23470 ".section .fixup,\"ax\"\n"
23471 "9: lea 0(%%eax,%0,4),%0\n"
23472 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23473 */
23474 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23475 unsigned long size);
23476 -unsigned long __copy_user_intel(void __user *to, const void *from,
23477 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23478 + unsigned long size);
23479 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23480 unsigned long size);
23481 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23482 const void __user *from, unsigned long size);
23483 #endif /* CONFIG_X86_INTEL_USERCOPY */
23484
23485 /* Generic arbitrary sized copy. */
23486 -#define __copy_user(to, from, size) \
23487 +#define __copy_user(to, from, size, prefix, set, restore) \
23488 do { \
23489 int __d0, __d1, __d2; \
23490 __asm__ __volatile__( \
23491 + set \
23492 " cmp $7,%0\n" \
23493 " jbe 1f\n" \
23494 " movl %1,%0\n" \
23495 " negl %0\n" \
23496 " andl $7,%0\n" \
23497 " subl %0,%3\n" \
23498 - "4: rep; movsb\n" \
23499 + "4: rep; "prefix"movsb\n" \
23500 " movl %3,%0\n" \
23501 " shrl $2,%0\n" \
23502 " andl $3,%3\n" \
23503 " .align 2,0x90\n" \
23504 - "0: rep; movsl\n" \
23505 + "0: rep; "prefix"movsl\n" \
23506 " movl %3,%0\n" \
23507 - "1: rep; movsb\n" \
23508 + "1: rep; "prefix"movsb\n" \
23509 "2:\n" \
23510 + restore \
23511 ".section .fixup,\"ax\"\n" \
23512 "5: addl %3,%0\n" \
23513 " jmp 2b\n" \
23514 @@ -538,14 +650,14 @@ do { \
23515 " negl %0\n" \
23516 " andl $7,%0\n" \
23517 " subl %0,%3\n" \
23518 - "4: rep; movsb\n" \
23519 + "4: rep; "__copyuser_seg"movsb\n" \
23520 " movl %3,%0\n" \
23521 " shrl $2,%0\n" \
23522 " andl $3,%3\n" \
23523 " .align 2,0x90\n" \
23524 - "0: rep; movsl\n" \
23525 + "0: rep; "__copyuser_seg"movsl\n" \
23526 " movl %3,%0\n" \
23527 - "1: rep; movsb\n" \
23528 + "1: rep; "__copyuser_seg"movsb\n" \
23529 "2:\n" \
23530 ".section .fixup,\"ax\"\n" \
23531 "5: addl %3,%0\n" \
23532 @@ -629,9 +741,9 @@ survive:
23533 #endif
23534 stac();
23535 if (movsl_is_ok(to, from, n))
23536 - __copy_user(to, from, n);
23537 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23538 else
23539 - n = __copy_user_intel(to, from, n);
23540 + n = __generic_copy_to_user_intel(to, from, n);
23541 clac();
23542 return n;
23543 }
23544 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23545 {
23546 stac();
23547 if (movsl_is_ok(to, from, n))
23548 - __copy_user(to, from, n);
23549 + __copy_user(to, from, n, __copyuser_seg, "", "");
23550 else
23551 - n = __copy_user_intel((void __user *)to,
23552 - (const void *)from, n);
23553 + n = __generic_copy_from_user_intel(to, from, n);
23554 clac();
23555 return n;
23556 }
23557 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23558 if (n > 64 && cpu_has_xmm2)
23559 n = __copy_user_intel_nocache(to, from, n);
23560 else
23561 - __copy_user(to, from, n);
23562 + __copy_user(to, from, n, __copyuser_seg, "", "");
23563 #else
23564 - __copy_user(to, from, n);
23565 + __copy_user(to, from, n, __copyuser_seg, "", "");
23566 #endif
23567 clac();
23568 return n;
23569 }
23570 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23571
23572 -/**
23573 - * copy_to_user: - Copy a block of data into user space.
23574 - * @to: Destination address, in user space.
23575 - * @from: Source address, in kernel space.
23576 - * @n: Number of bytes to copy.
23577 - *
23578 - * Context: User context only. This function may sleep.
23579 - *
23580 - * Copy data from kernel space to user space.
23581 - *
23582 - * Returns number of bytes that could not be copied.
23583 - * On success, this will be zero.
23584 - */
23585 -unsigned long
23586 -copy_to_user(void __user *to, const void *from, unsigned long n)
23587 -{
23588 - if (access_ok(VERIFY_WRITE, to, n))
23589 - n = __copy_to_user(to, from, n);
23590 - return n;
23591 -}
23592 -EXPORT_SYMBOL(copy_to_user);
23593 -
23594 -/**
23595 - * copy_from_user: - Copy a block of data from user space.
23596 - * @to: Destination address, in kernel space.
23597 - * @from: Source address, in user space.
23598 - * @n: Number of bytes to copy.
23599 - *
23600 - * Context: User context only. This function may sleep.
23601 - *
23602 - * Copy data from user space to kernel space.
23603 - *
23604 - * Returns number of bytes that could not be copied.
23605 - * On success, this will be zero.
23606 - *
23607 - * If some data could not be copied, this function will pad the copied
23608 - * data to the requested size using zero bytes.
23609 - */
23610 -unsigned long
23611 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23612 -{
23613 - if (access_ok(VERIFY_READ, from, n))
23614 - n = __copy_from_user(to, from, n);
23615 - else
23616 - memset(to, 0, n);
23617 - return n;
23618 -}
23619 -EXPORT_SYMBOL(_copy_from_user);
23620 -
23621 void copy_from_user_overflow(void)
23622 {
23623 WARN(1, "Buffer overflow detected!\n");
23624 }
23625 EXPORT_SYMBOL(copy_from_user_overflow);
23626 +
23627 +void copy_to_user_overflow(void)
23628 +{
23629 + WARN(1, "Buffer overflow detected!\n");
23630 +}
23631 +EXPORT_SYMBOL(copy_to_user_overflow);
23632 +
23633 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23634 +void __set_fs(mm_segment_t x)
23635 +{
23636 + switch (x.seg) {
23637 + case 0:
23638 + loadsegment(gs, 0);
23639 + break;
23640 + case TASK_SIZE_MAX:
23641 + loadsegment(gs, __USER_DS);
23642 + break;
23643 + case -1UL:
23644 + loadsegment(gs, __KERNEL_DS);
23645 + break;
23646 + default:
23647 + BUG();
23648 + }
23649 + return;
23650 +}
23651 +EXPORT_SYMBOL(__set_fs);
23652 +
23653 +void set_fs(mm_segment_t x)
23654 +{
23655 + current_thread_info()->addr_limit = x;
23656 + __set_fs(x);
23657 +}
23658 +EXPORT_SYMBOL(set_fs);
23659 +#endif
23660 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23661 index 05928aa..b33dea1 100644
23662 --- a/arch/x86/lib/usercopy_64.c
23663 +++ b/arch/x86/lib/usercopy_64.c
23664 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23665 _ASM_EXTABLE(0b,3b)
23666 _ASM_EXTABLE(1b,2b)
23667 : [size8] "=&c"(size), [dst] "=&D" (__d0)
23668 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
23669 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
23670 [zero] "r" (0UL), [eight] "r" (8UL));
23671 clac();
23672 return size;
23673 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
23674 }
23675 EXPORT_SYMBOL(clear_user);
23676
23677 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23678 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23679 {
23680 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23681 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23682 - }
23683 - return len;
23684 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
23685 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
23686 + return len;
23687 }
23688 EXPORT_SYMBOL(copy_in_user);
23689
23690 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
23691 * it is not necessary to optimize tail handling.
23692 */
23693 unsigned long
23694 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23695 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23696 {
23697 char c;
23698 unsigned zero_len;
23699 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23700 clac();
23701 return len;
23702 }
23703 +
23704 +void copy_from_user_overflow(void)
23705 +{
23706 + WARN(1, "Buffer overflow detected!\n");
23707 +}
23708 +EXPORT_SYMBOL(copy_from_user_overflow);
23709 +
23710 +void copy_to_user_overflow(void)
23711 +{
23712 + WARN(1, "Buffer overflow detected!\n");
23713 +}
23714 +EXPORT_SYMBOL(copy_to_user_overflow);
23715 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23716 index 903ec1e..c4166b2 100644
23717 --- a/arch/x86/mm/extable.c
23718 +++ b/arch/x86/mm/extable.c
23719 @@ -6,12 +6,24 @@
23720 static inline unsigned long
23721 ex_insn_addr(const struct exception_table_entry *x)
23722 {
23723 - return (unsigned long)&x->insn + x->insn;
23724 + unsigned long reloc = 0;
23725 +
23726 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23727 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23728 +#endif
23729 +
23730 + return (unsigned long)&x->insn + x->insn + reloc;
23731 }
23732 static inline unsigned long
23733 ex_fixup_addr(const struct exception_table_entry *x)
23734 {
23735 - return (unsigned long)&x->fixup + x->fixup;
23736 + unsigned long reloc = 0;
23737 +
23738 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23739 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23740 +#endif
23741 +
23742 + return (unsigned long)&x->fixup + x->fixup + reloc;
23743 }
23744
23745 int fixup_exception(struct pt_regs *regs)
23746 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23747 unsigned long new_ip;
23748
23749 #ifdef CONFIG_PNPBIOS
23750 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23751 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23752 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23753 extern u32 pnp_bios_is_utter_crap;
23754 pnp_bios_is_utter_crap = 1;
23755 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23756 i += 4;
23757 p->fixup -= i;
23758 i += 4;
23759 +
23760 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23761 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23762 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23763 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23764 +#endif
23765 +
23766 }
23767 }
23768
23769 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23770 index 8e13ecb..831f2d0 100644
23771 --- a/arch/x86/mm/fault.c
23772 +++ b/arch/x86/mm/fault.c
23773 @@ -13,12 +13,19 @@
23774 #include <linux/perf_event.h> /* perf_sw_event */
23775 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23776 #include <linux/prefetch.h> /* prefetchw */
23777 +#include <linux/unistd.h>
23778 +#include <linux/compiler.h>
23779
23780 #include <asm/traps.h> /* dotraplinkage, ... */
23781 #include <asm/pgalloc.h> /* pgd_*(), ... */
23782 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23783 #include <asm/fixmap.h> /* VSYSCALL_START */
23784 #include <asm/rcu.h> /* exception_enter(), ... */
23785 +#include <asm/tlbflush.h>
23786 +
23787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23788 +#include <asm/stacktrace.h>
23789 +#endif
23790
23791 /*
23792 * Page fault error code bits:
23793 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23794 int ret = 0;
23795
23796 /* kprobe_running() needs smp_processor_id() */
23797 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23798 + if (kprobes_built_in() && !user_mode(regs)) {
23799 preempt_disable();
23800 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23801 ret = 1;
23802 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23803 return !instr_lo || (instr_lo>>1) == 1;
23804 case 0x00:
23805 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23806 - if (probe_kernel_address(instr, opcode))
23807 + if (user_mode(regs)) {
23808 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23809 + return 0;
23810 + } else if (probe_kernel_address(instr, opcode))
23811 return 0;
23812
23813 *prefetch = (instr_lo == 0xF) &&
23814 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23815 while (instr < max_instr) {
23816 unsigned char opcode;
23817
23818 - if (probe_kernel_address(instr, opcode))
23819 + if (user_mode(regs)) {
23820 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23821 + break;
23822 + } else if (probe_kernel_address(instr, opcode))
23823 break;
23824
23825 instr++;
23826 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23827 force_sig_info(si_signo, &info, tsk);
23828 }
23829
23830 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23831 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23832 +#endif
23833 +
23834 +#ifdef CONFIG_PAX_EMUTRAMP
23835 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23836 +#endif
23837 +
23838 +#ifdef CONFIG_PAX_PAGEEXEC
23839 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23840 +{
23841 + pgd_t *pgd;
23842 + pud_t *pud;
23843 + pmd_t *pmd;
23844 +
23845 + pgd = pgd_offset(mm, address);
23846 + if (!pgd_present(*pgd))
23847 + return NULL;
23848 + pud = pud_offset(pgd, address);
23849 + if (!pud_present(*pud))
23850 + return NULL;
23851 + pmd = pmd_offset(pud, address);
23852 + if (!pmd_present(*pmd))
23853 + return NULL;
23854 + return pmd;
23855 +}
23856 +#endif
23857 +
23858 DEFINE_SPINLOCK(pgd_lock);
23859 LIST_HEAD(pgd_list);
23860
23861 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
23862 for (address = VMALLOC_START & PMD_MASK;
23863 address >= TASK_SIZE && address < FIXADDR_TOP;
23864 address += PMD_SIZE) {
23865 +
23866 +#ifdef CONFIG_PAX_PER_CPU_PGD
23867 + unsigned long cpu;
23868 +#else
23869 struct page *page;
23870 +#endif
23871
23872 spin_lock(&pgd_lock);
23873 +
23874 +#ifdef CONFIG_PAX_PER_CPU_PGD
23875 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23876 + pgd_t *pgd = get_cpu_pgd(cpu);
23877 + pmd_t *ret;
23878 +#else
23879 list_for_each_entry(page, &pgd_list, lru) {
23880 + pgd_t *pgd = page_address(page);
23881 spinlock_t *pgt_lock;
23882 pmd_t *ret;
23883
23884 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
23885 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23886
23887 spin_lock(pgt_lock);
23888 - ret = vmalloc_sync_one(page_address(page), address);
23889 +#endif
23890 +
23891 + ret = vmalloc_sync_one(pgd, address);
23892 +
23893 +#ifndef CONFIG_PAX_PER_CPU_PGD
23894 spin_unlock(pgt_lock);
23895 +#endif
23896
23897 if (!ret)
23898 break;
23899 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23900 * an interrupt in the middle of a task switch..
23901 */
23902 pgd_paddr = read_cr3();
23903 +
23904 +#ifdef CONFIG_PAX_PER_CPU_PGD
23905 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23906 +#endif
23907 +
23908 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23909 if (!pmd_k)
23910 return -1;
23911 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23912 * happen within a race in page table update. In the later
23913 * case just flush:
23914 */
23915 +
23916 +#ifdef CONFIG_PAX_PER_CPU_PGD
23917 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23918 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23919 +#else
23920 pgd = pgd_offset(current->active_mm, address);
23921 +#endif
23922 +
23923 pgd_ref = pgd_offset_k(address);
23924 if (pgd_none(*pgd_ref))
23925 return -1;
23926 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23927 static int is_errata100(struct pt_regs *regs, unsigned long address)
23928 {
23929 #ifdef CONFIG_X86_64
23930 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23931 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23932 return 1;
23933 #endif
23934 return 0;
23935 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23936 }
23937
23938 static const char nx_warning[] = KERN_CRIT
23939 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23940 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23941
23942 static void
23943 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23944 @@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23945 if (!oops_may_print())
23946 return;
23947
23948 - if (error_code & PF_INSTR) {
23949 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23950 unsigned int level;
23951
23952 pte_t *pte = lookup_address(address, &level);
23953
23954 if (pte && pte_present(*pte) && !pte_exec(*pte))
23955 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23956 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23957 }
23958
23959 +#ifdef CONFIG_PAX_KERNEXEC
23960 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23961 + if (current->signal->curr_ip)
23962 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23963 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23964 + else
23965 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23966 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23967 + }
23968 +#endif
23969 +
23970 printk(KERN_ALERT "BUG: unable to handle kernel ");
23971 if (address < PAGE_SIZE)
23972 printk(KERN_CONT "NULL pointer dereference");
23973 @@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23974 }
23975 #endif
23976
23977 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23978 + if (pax_is_fetch_fault(regs, error_code, address)) {
23979 +
23980 +#ifdef CONFIG_PAX_EMUTRAMP
23981 + switch (pax_handle_fetch_fault(regs)) {
23982 + case 2:
23983 + return;
23984 + }
23985 +#endif
23986 +
23987 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23988 + do_group_exit(SIGKILL);
23989 + }
23990 +#endif
23991 +
23992 if (unlikely(show_unhandled_signals))
23993 show_signal_msg(regs, error_code, address, tsk);
23994
23995 @@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23996 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23997 printk(KERN_ERR
23998 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23999 - tsk->comm, tsk->pid, address);
24000 + tsk->comm, task_pid_nr(tsk), address);
24001 code = BUS_MCEERR_AR;
24002 }
24003 #endif
24004 @@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24005 return 1;
24006 }
24007
24008 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24009 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24010 +{
24011 + pte_t *pte;
24012 + pmd_t *pmd;
24013 + spinlock_t *ptl;
24014 + unsigned char pte_mask;
24015 +
24016 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24017 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
24018 + return 0;
24019 +
24020 + /* PaX: it's our fault, let's handle it if we can */
24021 +
24022 + /* PaX: take a look at read faults before acquiring any locks */
24023 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24024 + /* instruction fetch attempt from a protected page in user mode */
24025 + up_read(&mm->mmap_sem);
24026 +
24027 +#ifdef CONFIG_PAX_EMUTRAMP
24028 + switch (pax_handle_fetch_fault(regs)) {
24029 + case 2:
24030 + return 1;
24031 + }
24032 +#endif
24033 +
24034 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24035 + do_group_exit(SIGKILL);
24036 + }
24037 +
24038 + pmd = pax_get_pmd(mm, address);
24039 + if (unlikely(!pmd))
24040 + return 0;
24041 +
24042 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24043 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24044 + pte_unmap_unlock(pte, ptl);
24045 + return 0;
24046 + }
24047 +
24048 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24049 + /* write attempt to a protected page in user mode */
24050 + pte_unmap_unlock(pte, ptl);
24051 + return 0;
24052 + }
24053 +
24054 +#ifdef CONFIG_SMP
24055 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24056 +#else
24057 + if (likely(address > get_limit(regs->cs)))
24058 +#endif
24059 + {
24060 + set_pte(pte, pte_mkread(*pte));
24061 + __flush_tlb_one(address);
24062 + pte_unmap_unlock(pte, ptl);
24063 + up_read(&mm->mmap_sem);
24064 + return 1;
24065 + }
24066 +
24067 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24068 +
24069 + /*
24070 + * PaX: fill DTLB with user rights and retry
24071 + */
24072 + __asm__ __volatile__ (
24073 + "orb %2,(%1)\n"
24074 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24075 +/*
24076 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24077 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24078 + * page fault when examined during a TLB load attempt. this is true not only
24079 + * for PTEs holding a non-present entry but also present entries that will
24080 + * raise a page fault (such as those set up by PaX, or the copy-on-write
24081 + * mechanism). in effect it means that we do *not* need to flush the TLBs
24082 + * for our target pages since their PTEs are simply not in the TLBs at all.
24083 +
24084 + * the best thing in omitting it is that we gain around 15-20% speed in the
24085 + * fast path of the page fault handler and can get rid of tracing since we
24086 + * can no longer flush unintended entries.
24087 + */
24088 + "invlpg (%0)\n"
24089 +#endif
24090 + __copyuser_seg"testb $0,(%0)\n"
24091 + "xorb %3,(%1)\n"
24092 + :
24093 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24094 + : "memory", "cc");
24095 + pte_unmap_unlock(pte, ptl);
24096 + up_read(&mm->mmap_sem);
24097 + return 1;
24098 +}
24099 +#endif
24100 +
24101 /*
24102 * Handle a spurious fault caused by a stale TLB entry.
24103 *
24104 @@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
24105 static inline int
24106 access_error(unsigned long error_code, struct vm_area_struct *vma)
24107 {
24108 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24109 + return 1;
24110 +
24111 if (error_code & PF_WRITE) {
24112 /* write, present and write, not present: */
24113 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24114 @@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
24115 if (error_code & PF_USER)
24116 return false;
24117
24118 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
24119 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
24120 return false;
24121
24122 return true;
24123 @@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
24124 {
24125 struct vm_area_struct *vma;
24126 struct task_struct *tsk;
24127 - unsigned long address;
24128 struct mm_struct *mm;
24129 int fault;
24130 int write = error_code & PF_WRITE;
24131 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24132 (write ? FAULT_FLAG_WRITE : 0);
24133
24134 - tsk = current;
24135 - mm = tsk->mm;
24136 -
24137 /* Get the faulting address: */
24138 - address = read_cr2();
24139 + unsigned long address = read_cr2();
24140 +
24141 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24142 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24143 + if (!search_exception_tables(regs->ip)) {
24144 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24145 + bad_area_nosemaphore(regs, error_code, address);
24146 + return;
24147 + }
24148 + if (address < PAX_USER_SHADOW_BASE) {
24149 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24150 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24151 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24152 + } else
24153 + address -= PAX_USER_SHADOW_BASE;
24154 + }
24155 +#endif
24156 +
24157 + tsk = current;
24158 + mm = tsk->mm;
24159
24160 /*
24161 * Detect and handle instructions that would cause a page fault for
24162 @@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
24163 * User-mode registers count as a user access even for any
24164 * potential system fault or CPU buglet:
24165 */
24166 - if (user_mode_vm(regs)) {
24167 + if (user_mode(regs)) {
24168 local_irq_enable();
24169 error_code |= PF_USER;
24170 } else {
24171 @@ -1151,6 +1358,11 @@ retry:
24172 might_sleep();
24173 }
24174
24175 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24176 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24177 + return;
24178 +#endif
24179 +
24180 vma = find_vma(mm, address);
24181 if (unlikely(!vma)) {
24182 bad_area(regs, error_code, address);
24183 @@ -1162,18 +1374,24 @@ retry:
24184 bad_area(regs, error_code, address);
24185 return;
24186 }
24187 - if (error_code & PF_USER) {
24188 - /*
24189 - * Accessing the stack below %sp is always a bug.
24190 - * The large cushion allows instructions like enter
24191 - * and pusha to work. ("enter $65535, $31" pushes
24192 - * 32 pointers and then decrements %sp by 65535.)
24193 - */
24194 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24195 - bad_area(regs, error_code, address);
24196 - return;
24197 - }
24198 + /*
24199 + * Accessing the stack below %sp is always a bug.
24200 + * The large cushion allows instructions like enter
24201 + * and pusha to work. ("enter $65535, $31" pushes
24202 + * 32 pointers and then decrements %sp by 65535.)
24203 + */
24204 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24205 + bad_area(regs, error_code, address);
24206 + return;
24207 }
24208 +
24209 +#ifdef CONFIG_PAX_SEGMEXEC
24210 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24211 + bad_area(regs, error_code, address);
24212 + return;
24213 + }
24214 +#endif
24215 +
24216 if (unlikely(expand_stack(vma, address))) {
24217 bad_area(regs, error_code, address);
24218 return;
24219 @@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24220 __do_page_fault(regs, error_code);
24221 exception_exit(regs);
24222 }
24223 +
24224 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24225 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24226 +{
24227 + struct mm_struct *mm = current->mm;
24228 + unsigned long ip = regs->ip;
24229 +
24230 + if (v8086_mode(regs))
24231 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24232 +
24233 +#ifdef CONFIG_PAX_PAGEEXEC
24234 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24235 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24236 + return true;
24237 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24238 + return true;
24239 + return false;
24240 + }
24241 +#endif
24242 +
24243 +#ifdef CONFIG_PAX_SEGMEXEC
24244 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24245 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24246 + return true;
24247 + return false;
24248 + }
24249 +#endif
24250 +
24251 + return false;
24252 +}
24253 +#endif
24254 +
24255 +#ifdef CONFIG_PAX_EMUTRAMP
24256 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24257 +{
24258 + int err;
24259 +
24260 + do { /* PaX: libffi trampoline emulation */
24261 + unsigned char mov, jmp;
24262 + unsigned int addr1, addr2;
24263 +
24264 +#ifdef CONFIG_X86_64
24265 + if ((regs->ip + 9) >> 32)
24266 + break;
24267 +#endif
24268 +
24269 + err = get_user(mov, (unsigned char __user *)regs->ip);
24270 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24271 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24272 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24273 +
24274 + if (err)
24275 + break;
24276 +
24277 + if (mov == 0xB8 && jmp == 0xE9) {
24278 + regs->ax = addr1;
24279 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24280 + return 2;
24281 + }
24282 + } while (0);
24283 +
24284 + do { /* PaX: gcc trampoline emulation #1 */
24285 + unsigned char mov1, mov2;
24286 + unsigned short jmp;
24287 + unsigned int addr1, addr2;
24288 +
24289 +#ifdef CONFIG_X86_64
24290 + if ((regs->ip + 11) >> 32)
24291 + break;
24292 +#endif
24293 +
24294 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24295 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24296 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24297 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24298 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24299 +
24300 + if (err)
24301 + break;
24302 +
24303 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24304 + regs->cx = addr1;
24305 + regs->ax = addr2;
24306 + regs->ip = addr2;
24307 + return 2;
24308 + }
24309 + } while (0);
24310 +
24311 + do { /* PaX: gcc trampoline emulation #2 */
24312 + unsigned char mov, jmp;
24313 + unsigned int addr1, addr2;
24314 +
24315 +#ifdef CONFIG_X86_64
24316 + if ((regs->ip + 9) >> 32)
24317 + break;
24318 +#endif
24319 +
24320 + err = get_user(mov, (unsigned char __user *)regs->ip);
24321 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24322 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24323 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24324 +
24325 + if (err)
24326 + break;
24327 +
24328 + if (mov == 0xB9 && jmp == 0xE9) {
24329 + regs->cx = addr1;
24330 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24331 + return 2;
24332 + }
24333 + } while (0);
24334 +
24335 + return 1; /* PaX in action */
24336 +}
24337 +
24338 +#ifdef CONFIG_X86_64
24339 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24340 +{
24341 + int err;
24342 +
24343 + do { /* PaX: libffi trampoline emulation */
24344 + unsigned short mov1, mov2, jmp1;
24345 + unsigned char stcclc, jmp2;
24346 + unsigned long addr1, addr2;
24347 +
24348 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24349 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24350 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24351 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24352 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24353 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24354 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24355 +
24356 + if (err)
24357 + break;
24358 +
24359 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24360 + regs->r11 = addr1;
24361 + regs->r10 = addr2;
24362 + if (stcclc == 0xF8)
24363 + regs->flags &= ~X86_EFLAGS_CF;
24364 + else
24365 + regs->flags |= X86_EFLAGS_CF;
24366 + regs->ip = addr1;
24367 + return 2;
24368 + }
24369 + } while (0);
24370 +
24371 + do { /* PaX: gcc trampoline emulation #1 */
24372 + unsigned short mov1, mov2, jmp1;
24373 + unsigned char jmp2;
24374 + unsigned int addr1;
24375 + unsigned long addr2;
24376 +
24377 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24378 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24379 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24380 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24381 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24382 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24383 +
24384 + if (err)
24385 + break;
24386 +
24387 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24388 + regs->r11 = addr1;
24389 + regs->r10 = addr2;
24390 + regs->ip = addr1;
24391 + return 2;
24392 + }
24393 + } while (0);
24394 +
24395 + do { /* PaX: gcc trampoline emulation #2 */
24396 + unsigned short mov1, mov2, jmp1;
24397 + unsigned char jmp2;
24398 + unsigned long addr1, addr2;
24399 +
24400 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24401 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24402 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24403 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24404 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24405 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24406 +
24407 + if (err)
24408 + break;
24409 +
24410 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24411 + regs->r11 = addr1;
24412 + regs->r10 = addr2;
24413 + regs->ip = addr1;
24414 + return 2;
24415 + }
24416 + } while (0);
24417 +
24418 + return 1; /* PaX in action */
24419 +}
24420 +#endif
24421 +
24422 +/*
24423 + * PaX: decide what to do with offenders (regs->ip = fault address)
24424 + *
24425 + * returns 1 when task should be killed
24426 + * 2 when gcc trampoline was detected
24427 + */
24428 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24429 +{
24430 + if (v8086_mode(regs))
24431 + return 1;
24432 +
24433 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24434 + return 1;
24435 +
24436 +#ifdef CONFIG_X86_32
24437 + return pax_handle_fetch_fault_32(regs);
24438 +#else
24439 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24440 + return pax_handle_fetch_fault_32(regs);
24441 + else
24442 + return pax_handle_fetch_fault_64(regs);
24443 +#endif
24444 +}
24445 +#endif
24446 +
24447 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24448 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24449 +{
24450 + long i;
24451 +
24452 + printk(KERN_ERR "PAX: bytes at PC: ");
24453 + for (i = 0; i < 20; i++) {
24454 + unsigned char c;
24455 + if (get_user(c, (unsigned char __force_user *)pc+i))
24456 + printk(KERN_CONT "?? ");
24457 + else
24458 + printk(KERN_CONT "%02x ", c);
24459 + }
24460 + printk("\n");
24461 +
24462 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24463 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24464 + unsigned long c;
24465 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24466 +#ifdef CONFIG_X86_32
24467 + printk(KERN_CONT "???????? ");
24468 +#else
24469 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24470 + printk(KERN_CONT "???????? ???????? ");
24471 + else
24472 + printk(KERN_CONT "???????????????? ");
24473 +#endif
24474 + } else {
24475 +#ifdef CONFIG_X86_64
24476 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24477 + printk(KERN_CONT "%08x ", (unsigned int)c);
24478 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24479 + } else
24480 +#endif
24481 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24482 + }
24483 + }
24484 + printk("\n");
24485 +}
24486 +#endif
24487 +
24488 +/**
24489 + * probe_kernel_write(): safely attempt to write to a location
24490 + * @dst: address to write to
24491 + * @src: pointer to the data that shall be written
24492 + * @size: size of the data chunk
24493 + *
24494 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24495 + * happens, handle that and return -EFAULT.
24496 + */
24497 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24498 +{
24499 + long ret;
24500 + mm_segment_t old_fs = get_fs();
24501 +
24502 + set_fs(KERNEL_DS);
24503 + pagefault_disable();
24504 + pax_open_kernel();
24505 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24506 + pax_close_kernel();
24507 + pagefault_enable();
24508 + set_fs(old_fs);
24509 +
24510 + return ret ? -EFAULT : 0;
24511 +}
24512 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24513 index dd74e46..7d26398 100644
24514 --- a/arch/x86/mm/gup.c
24515 +++ b/arch/x86/mm/gup.c
24516 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24517 addr = start;
24518 len = (unsigned long) nr_pages << PAGE_SHIFT;
24519 end = start + len;
24520 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24521 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24522 (void __user *)start, len)))
24523 return 0;
24524
24525 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24526 index 6f31ee5..8ee4164 100644
24527 --- a/arch/x86/mm/highmem_32.c
24528 +++ b/arch/x86/mm/highmem_32.c
24529 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24530 idx = type + KM_TYPE_NR*smp_processor_id();
24531 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24532 BUG_ON(!pte_none(*(kmap_pte-idx)));
24533 +
24534 + pax_open_kernel();
24535 set_pte(kmap_pte-idx, mk_pte(page, prot));
24536 + pax_close_kernel();
24537 +
24538 arch_flush_lazy_mmu_mode();
24539
24540 return (void *)vaddr;
24541 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24542 index 937bff5..d777418 100644
24543 --- a/arch/x86/mm/hugetlbpage.c
24544 +++ b/arch/x86/mm/hugetlbpage.c
24545 @@ -276,13 +276,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24546 struct hstate *h = hstate_file(file);
24547 struct mm_struct *mm = current->mm;
24548 struct vm_area_struct *vma;
24549 - unsigned long start_addr;
24550 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24551 +
24552 +#ifdef CONFIG_PAX_SEGMEXEC
24553 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24554 + pax_task_size = SEGMEXEC_TASK_SIZE;
24555 +#endif
24556 +
24557 + pax_task_size -= PAGE_SIZE;
24558
24559 if (len > mm->cached_hole_size) {
24560 - start_addr = mm->free_area_cache;
24561 + start_addr = mm->free_area_cache;
24562 } else {
24563 - start_addr = TASK_UNMAPPED_BASE;
24564 - mm->cached_hole_size = 0;
24565 + start_addr = mm->mmap_base;
24566 + mm->cached_hole_size = 0;
24567 }
24568
24569 full_search:
24570 @@ -290,26 +297,27 @@ full_search:
24571
24572 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24573 /* At this point: (!vma || addr < vma->vm_end). */
24574 - if (TASK_SIZE - len < addr) {
24575 + if (pax_task_size - len < addr) {
24576 /*
24577 * Start a new search - just in case we missed
24578 * some holes.
24579 */
24580 - if (start_addr != TASK_UNMAPPED_BASE) {
24581 - start_addr = TASK_UNMAPPED_BASE;
24582 + if (start_addr != mm->mmap_base) {
24583 + start_addr = mm->mmap_base;
24584 mm->cached_hole_size = 0;
24585 goto full_search;
24586 }
24587 return -ENOMEM;
24588 }
24589 - if (!vma || addr + len <= vma->vm_start) {
24590 - mm->free_area_cache = addr + len;
24591 - return addr;
24592 - }
24593 + if (check_heap_stack_gap(vma, addr, len))
24594 + break;
24595 if (addr + mm->cached_hole_size < vma->vm_start)
24596 mm->cached_hole_size = vma->vm_start - addr;
24597 addr = ALIGN(vma->vm_end, huge_page_size(h));
24598 }
24599 +
24600 + mm->free_area_cache = addr + len;
24601 + return addr;
24602 }
24603
24604 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24605 @@ -320,9 +328,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24606 struct mm_struct *mm = current->mm;
24607 struct vm_area_struct *vma;
24608 unsigned long base = mm->mmap_base;
24609 - unsigned long addr = addr0;
24610 + unsigned long addr;
24611 unsigned long largest_hole = mm->cached_hole_size;
24612 - unsigned long start_addr;
24613
24614 /* don't allow allocations above current base */
24615 if (mm->free_area_cache > base)
24616 @@ -332,16 +339,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24617 largest_hole = 0;
24618 mm->free_area_cache = base;
24619 }
24620 -try_again:
24621 - start_addr = mm->free_area_cache;
24622
24623 /* make sure it can fit in the remaining address space */
24624 if (mm->free_area_cache < len)
24625 goto fail;
24626
24627 /* either no address requested or can't fit in requested address hole */
24628 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24629 + addr = mm->free_area_cache - len;
24630 do {
24631 + addr &= huge_page_mask(h);
24632 /*
24633 * Lookup failure means no vma is above this address,
24634 * i.e. return with success:
24635 @@ -350,10 +356,10 @@ try_again:
24636 if (!vma)
24637 return addr;
24638
24639 - if (addr + len <= vma->vm_start) {
24640 + if (check_heap_stack_gap(vma, addr, len)) {
24641 /* remember the address as a hint for next time */
24642 - mm->cached_hole_size = largest_hole;
24643 - return (mm->free_area_cache = addr);
24644 + mm->cached_hole_size = largest_hole;
24645 + return (mm->free_area_cache = addr);
24646 } else if (mm->free_area_cache == vma->vm_end) {
24647 /* pull free_area_cache down to the first hole */
24648 mm->free_area_cache = vma->vm_start;
24649 @@ -362,29 +368,34 @@ try_again:
24650
24651 /* remember the largest hole we saw so far */
24652 if (addr + largest_hole < vma->vm_start)
24653 - largest_hole = vma->vm_start - addr;
24654 + largest_hole = vma->vm_start - addr;
24655
24656 /* try just below the current vma->vm_start */
24657 - addr = (vma->vm_start - len) & huge_page_mask(h);
24658 - } while (len <= vma->vm_start);
24659 + addr = skip_heap_stack_gap(vma, len);
24660 + } while (!IS_ERR_VALUE(addr));
24661
24662 fail:
24663 /*
24664 - * if hint left us with no space for the requested
24665 - * mapping then try again:
24666 - */
24667 - if (start_addr != base) {
24668 - mm->free_area_cache = base;
24669 - largest_hole = 0;
24670 - goto try_again;
24671 - }
24672 - /*
24673 * A failed mmap() very likely causes application failure,
24674 * so fall back to the bottom-up function here. This scenario
24675 * can happen with large stack limits and large mmap()
24676 * allocations.
24677 */
24678 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24679 +
24680 +#ifdef CONFIG_PAX_SEGMEXEC
24681 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24682 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24683 + else
24684 +#endif
24685 +
24686 + mm->mmap_base = TASK_UNMAPPED_BASE;
24687 +
24688 +#ifdef CONFIG_PAX_RANDMMAP
24689 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24690 + mm->mmap_base += mm->delta_mmap;
24691 +#endif
24692 +
24693 + mm->free_area_cache = mm->mmap_base;
24694 mm->cached_hole_size = ~0UL;
24695 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24696 len, pgoff, flags);
24697 @@ -392,6 +403,7 @@ fail:
24698 /*
24699 * Restore the topdown base:
24700 */
24701 + mm->mmap_base = base;
24702 mm->free_area_cache = base;
24703 mm->cached_hole_size = ~0UL;
24704
24705 @@ -405,10 +417,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24706 struct hstate *h = hstate_file(file);
24707 struct mm_struct *mm = current->mm;
24708 struct vm_area_struct *vma;
24709 + unsigned long pax_task_size = TASK_SIZE;
24710
24711 if (len & ~huge_page_mask(h))
24712 return -EINVAL;
24713 - if (len > TASK_SIZE)
24714 +
24715 +#ifdef CONFIG_PAX_SEGMEXEC
24716 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24717 + pax_task_size = SEGMEXEC_TASK_SIZE;
24718 +#endif
24719 +
24720 + pax_task_size -= PAGE_SIZE;
24721 +
24722 + if (len > pax_task_size)
24723 return -ENOMEM;
24724
24725 if (flags & MAP_FIXED) {
24726 @@ -420,8 +441,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24727 if (addr) {
24728 addr = ALIGN(addr, huge_page_size(h));
24729 vma = find_vma(mm, addr);
24730 - if (TASK_SIZE - len >= addr &&
24731 - (!vma || addr + len <= vma->vm_start))
24732 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24733 return addr;
24734 }
24735 if (mm->get_unmapped_area == arch_get_unmapped_area)
24736 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24737 index d7aea41..0fc945b 100644
24738 --- a/arch/x86/mm/init.c
24739 +++ b/arch/x86/mm/init.c
24740 @@ -4,6 +4,7 @@
24741 #include <linux/swap.h>
24742 #include <linux/memblock.h>
24743 #include <linux/bootmem.h> /* for max_low_pfn */
24744 +#include <linux/tboot.h>
24745
24746 #include <asm/cacheflush.h>
24747 #include <asm/e820.h>
24748 @@ -16,6 +17,8 @@
24749 #include <asm/tlb.h>
24750 #include <asm/proto.h>
24751 #include <asm/dma.h> /* for MAX_DMA_PFN */
24752 +#include <asm/desc.h>
24753 +#include <asm/bios_ebda.h>
24754
24755 unsigned long __initdata pgt_buf_start;
24756 unsigned long __meminitdata pgt_buf_end;
24757 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24758 {
24759 int i;
24760 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24761 - unsigned long start = 0, good_end;
24762 + unsigned long start = 0x100000, good_end;
24763 phys_addr_t base;
24764
24765 for (i = 0; i < nr_range; i++) {
24766 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24767 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24768 * mmio resources as well as potential bios/acpi data regions.
24769 */
24770 +
24771 +#ifdef CONFIG_GRKERNSEC_KMEM
24772 +static unsigned int ebda_start __read_only;
24773 +static unsigned int ebda_end __read_only;
24774 +#endif
24775 +
24776 int devmem_is_allowed(unsigned long pagenr)
24777 {
24778 - if (pagenr < 256)
24779 +#ifdef CONFIG_GRKERNSEC_KMEM
24780 + /* allow BDA */
24781 + if (!pagenr)
24782 return 1;
24783 + /* allow EBDA */
24784 + if (pagenr >= ebda_start && pagenr < ebda_end)
24785 + return 1;
24786 + /* if tboot is in use, allow access to its hardcoded serial log range */
24787 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24788 + return 1;
24789 +#else
24790 + if (!pagenr)
24791 + return 1;
24792 +#ifdef CONFIG_VM86
24793 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24794 + return 1;
24795 +#endif
24796 +#endif
24797 +
24798 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24799 + return 1;
24800 +#ifdef CONFIG_GRKERNSEC_KMEM
24801 + /* throw out everything else below 1MB */
24802 + if (pagenr <= 256)
24803 + return 0;
24804 +#endif
24805 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24806 return 0;
24807 if (!page_is_ram(pagenr))
24808 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24809 #endif
24810 }
24811
24812 +#ifdef CONFIG_GRKERNSEC_KMEM
24813 +static inline void gr_init_ebda(void)
24814 +{
24815 + unsigned int ebda_addr;
24816 + unsigned int ebda_size = 0;
24817 +
24818 + ebda_addr = get_bios_ebda();
24819 + if (ebda_addr) {
24820 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24821 + ebda_size <<= 10;
24822 + }
24823 + if (ebda_addr && ebda_size) {
24824 + ebda_start = ebda_addr >> PAGE_SHIFT;
24825 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24826 + } else {
24827 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24828 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24829 + }
24830 +}
24831 +#else
24832 +static inline void gr_init_ebda(void) { }
24833 +#endif
24834 +
24835 void free_initmem(void)
24836 {
24837 +#ifdef CONFIG_PAX_KERNEXEC
24838 +#ifdef CONFIG_X86_32
24839 + /* PaX: limit KERNEL_CS to actual size */
24840 + unsigned long addr, limit;
24841 + struct desc_struct d;
24842 + int cpu;
24843 +#else
24844 + pgd_t *pgd;
24845 + pud_t *pud;
24846 + pmd_t *pmd;
24847 + unsigned long addr, end;
24848 +#endif
24849 +#endif
24850 +
24851 + gr_init_ebda();
24852 +
24853 +#ifdef CONFIG_PAX_KERNEXEC
24854 +#ifdef CONFIG_X86_32
24855 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24856 + limit = (limit - 1UL) >> PAGE_SHIFT;
24857 +
24858 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24859 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24860 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24861 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24862 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24863 + }
24864 +
24865 + /* PaX: make KERNEL_CS read-only */
24866 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24867 + if (!paravirt_enabled())
24868 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24869 +/*
24870 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24871 + pgd = pgd_offset_k(addr);
24872 + pud = pud_offset(pgd, addr);
24873 + pmd = pmd_offset(pud, addr);
24874 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24875 + }
24876 +*/
24877 +#ifdef CONFIG_X86_PAE
24878 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24879 +/*
24880 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24881 + pgd = pgd_offset_k(addr);
24882 + pud = pud_offset(pgd, addr);
24883 + pmd = pmd_offset(pud, addr);
24884 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24885 + }
24886 +*/
24887 +#endif
24888 +
24889 +#ifdef CONFIG_MODULES
24890 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24891 +#endif
24892 +
24893 +#else
24894 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24895 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24896 + pgd = pgd_offset_k(addr);
24897 + pud = pud_offset(pgd, addr);
24898 + pmd = pmd_offset(pud, addr);
24899 + if (!pmd_present(*pmd))
24900 + continue;
24901 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24902 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24903 + else
24904 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24905 + }
24906 +
24907 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24908 + end = addr + KERNEL_IMAGE_SIZE;
24909 + for (; addr < end; addr += PMD_SIZE) {
24910 + pgd = pgd_offset_k(addr);
24911 + pud = pud_offset(pgd, addr);
24912 + pmd = pmd_offset(pud, addr);
24913 + if (!pmd_present(*pmd))
24914 + continue;
24915 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24916 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24917 + }
24918 +#endif
24919 +
24920 + flush_tlb_all();
24921 +#endif
24922 +
24923 free_init_pages("unused kernel memory",
24924 (unsigned long)(&__init_begin),
24925 (unsigned long)(&__init_end));
24926 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24927 index 11a5800..4bd9977 100644
24928 --- a/arch/x86/mm/init_32.c
24929 +++ b/arch/x86/mm/init_32.c
24930 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24931 }
24932
24933 /*
24934 - * Creates a middle page table and puts a pointer to it in the
24935 - * given global directory entry. This only returns the gd entry
24936 - * in non-PAE compilation mode, since the middle layer is folded.
24937 - */
24938 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24939 -{
24940 - pud_t *pud;
24941 - pmd_t *pmd_table;
24942 -
24943 -#ifdef CONFIG_X86_PAE
24944 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24945 - if (after_bootmem)
24946 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24947 - else
24948 - pmd_table = (pmd_t *)alloc_low_page();
24949 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24950 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24951 - pud = pud_offset(pgd, 0);
24952 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24953 -
24954 - return pmd_table;
24955 - }
24956 -#endif
24957 - pud = pud_offset(pgd, 0);
24958 - pmd_table = pmd_offset(pud, 0);
24959 -
24960 - return pmd_table;
24961 -}
24962 -
24963 -/*
24964 * Create a page table and place a pointer to it in a middle page
24965 * directory entry:
24966 */
24967 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24968 page_table = (pte_t *)alloc_low_page();
24969
24970 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24971 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24972 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24973 +#else
24974 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24975 +#endif
24976 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24977 }
24978
24979 return pte_offset_kernel(pmd, 0);
24980 }
24981
24982 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24983 +{
24984 + pud_t *pud;
24985 + pmd_t *pmd_table;
24986 +
24987 + pud = pud_offset(pgd, 0);
24988 + pmd_table = pmd_offset(pud, 0);
24989 +
24990 + return pmd_table;
24991 +}
24992 +
24993 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24994 {
24995 int pgd_idx = pgd_index(vaddr);
24996 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24997 int pgd_idx, pmd_idx;
24998 unsigned long vaddr;
24999 pgd_t *pgd;
25000 + pud_t *pud;
25001 pmd_t *pmd;
25002 pte_t *pte = NULL;
25003
25004 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25005 pgd = pgd_base + pgd_idx;
25006
25007 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25008 - pmd = one_md_table_init(pgd);
25009 - pmd = pmd + pmd_index(vaddr);
25010 + pud = pud_offset(pgd, vaddr);
25011 + pmd = pmd_offset(pud, vaddr);
25012 +
25013 +#ifdef CONFIG_X86_PAE
25014 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25015 +#endif
25016 +
25017 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25018 pmd++, pmd_idx++) {
25019 pte = page_table_kmap_check(one_page_table_init(pmd),
25020 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25021 }
25022 }
25023
25024 -static inline int is_kernel_text(unsigned long addr)
25025 +static inline int is_kernel_text(unsigned long start, unsigned long end)
25026 {
25027 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
25028 - return 1;
25029 - return 0;
25030 + if ((start > ktla_ktva((unsigned long)_etext) ||
25031 + end <= ktla_ktva((unsigned long)_stext)) &&
25032 + (start > ktla_ktva((unsigned long)_einittext) ||
25033 + end <= ktla_ktva((unsigned long)_sinittext)) &&
25034 +
25035 +#ifdef CONFIG_ACPI_SLEEP
25036 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25037 +#endif
25038 +
25039 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25040 + return 0;
25041 + return 1;
25042 }
25043
25044 /*
25045 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
25046 unsigned long last_map_addr = end;
25047 unsigned long start_pfn, end_pfn;
25048 pgd_t *pgd_base = swapper_pg_dir;
25049 - int pgd_idx, pmd_idx, pte_ofs;
25050 + unsigned int pgd_idx, pmd_idx, pte_ofs;
25051 unsigned long pfn;
25052 pgd_t *pgd;
25053 + pud_t *pud;
25054 pmd_t *pmd;
25055 pte_t *pte;
25056 unsigned pages_2m, pages_4k;
25057 @@ -280,8 +281,13 @@ repeat:
25058 pfn = start_pfn;
25059 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25060 pgd = pgd_base + pgd_idx;
25061 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25062 - pmd = one_md_table_init(pgd);
25063 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25064 + pud = pud_offset(pgd, 0);
25065 + pmd = pmd_offset(pud, 0);
25066 +
25067 +#ifdef CONFIG_X86_PAE
25068 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25069 +#endif
25070
25071 if (pfn >= end_pfn)
25072 continue;
25073 @@ -293,14 +299,13 @@ repeat:
25074 #endif
25075 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25076 pmd++, pmd_idx++) {
25077 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25078 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25079
25080 /*
25081 * Map with big pages if possible, otherwise
25082 * create normal page tables:
25083 */
25084 if (use_pse) {
25085 - unsigned int addr2;
25086 pgprot_t prot = PAGE_KERNEL_LARGE;
25087 /*
25088 * first pass will use the same initial
25089 @@ -310,11 +315,7 @@ repeat:
25090 __pgprot(PTE_IDENT_ATTR |
25091 _PAGE_PSE);
25092
25093 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25094 - PAGE_OFFSET + PAGE_SIZE-1;
25095 -
25096 - if (is_kernel_text(addr) ||
25097 - is_kernel_text(addr2))
25098 + if (is_kernel_text(address, address + PMD_SIZE))
25099 prot = PAGE_KERNEL_LARGE_EXEC;
25100
25101 pages_2m++;
25102 @@ -331,7 +332,7 @@ repeat:
25103 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25104 pte += pte_ofs;
25105 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25106 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25107 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25108 pgprot_t prot = PAGE_KERNEL;
25109 /*
25110 * first pass will use the same initial
25111 @@ -339,7 +340,7 @@ repeat:
25112 */
25113 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25114
25115 - if (is_kernel_text(addr))
25116 + if (is_kernel_text(address, address + PAGE_SIZE))
25117 prot = PAGE_KERNEL_EXEC;
25118
25119 pages_4k++;
25120 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
25121
25122 pud = pud_offset(pgd, va);
25123 pmd = pmd_offset(pud, va);
25124 - if (!pmd_present(*pmd))
25125 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25126 break;
25127
25128 pte = pte_offset_kernel(pmd, va);
25129 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
25130
25131 static void __init pagetable_init(void)
25132 {
25133 - pgd_t *pgd_base = swapper_pg_dir;
25134 -
25135 - permanent_kmaps_init(pgd_base);
25136 + permanent_kmaps_init(swapper_pg_dir);
25137 }
25138
25139 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25140 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25141 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25142
25143 /* user-defined highmem size */
25144 @@ -731,6 +730,12 @@ void __init mem_init(void)
25145
25146 pci_iommu_alloc();
25147
25148 +#ifdef CONFIG_PAX_PER_CPU_PGD
25149 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25150 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25151 + KERNEL_PGD_PTRS);
25152 +#endif
25153 +
25154 #ifdef CONFIG_FLATMEM
25155 BUG_ON(!mem_map);
25156 #endif
25157 @@ -757,7 +762,7 @@ void __init mem_init(void)
25158 reservedpages++;
25159
25160 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25161 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25162 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25163 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25164
25165 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25166 @@ -798,10 +803,10 @@ void __init mem_init(void)
25167 ((unsigned long)&__init_end -
25168 (unsigned long)&__init_begin) >> 10,
25169
25170 - (unsigned long)&_etext, (unsigned long)&_edata,
25171 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25172 + (unsigned long)&_sdata, (unsigned long)&_edata,
25173 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25174
25175 - (unsigned long)&_text, (unsigned long)&_etext,
25176 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25177 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25178
25179 /*
25180 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
25181 if (!kernel_set_to_readonly)
25182 return;
25183
25184 + start = ktla_ktva(start);
25185 pr_debug("Set kernel text: %lx - %lx for read write\n",
25186 start, start+size);
25187
25188 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
25189 if (!kernel_set_to_readonly)
25190 return;
25191
25192 + start = ktla_ktva(start);
25193 pr_debug("Set kernel text: %lx - %lx for read only\n",
25194 start, start+size);
25195
25196 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
25197 unsigned long start = PFN_ALIGN(_text);
25198 unsigned long size = PFN_ALIGN(_etext) - start;
25199
25200 + start = ktla_ktva(start);
25201 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25202 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25203 size >> 10);
25204 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25205 index 3baff25..8b37564 100644
25206 --- a/arch/x86/mm/init_64.c
25207 +++ b/arch/x86/mm/init_64.c
25208 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25209 * around without checking the pgd every time.
25210 */
25211
25212 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25213 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25214 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25215
25216 int force_personality32;
25217 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25218
25219 for (address = start; address <= end; address += PGDIR_SIZE) {
25220 const pgd_t *pgd_ref = pgd_offset_k(address);
25221 +
25222 +#ifdef CONFIG_PAX_PER_CPU_PGD
25223 + unsigned long cpu;
25224 +#else
25225 struct page *page;
25226 +#endif
25227
25228 if (pgd_none(*pgd_ref))
25229 continue;
25230
25231 spin_lock(&pgd_lock);
25232 +
25233 +#ifdef CONFIG_PAX_PER_CPU_PGD
25234 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25235 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25236 +#else
25237 list_for_each_entry(page, &pgd_list, lru) {
25238 pgd_t *pgd;
25239 spinlock_t *pgt_lock;
25240 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25241 /* the pgt_lock only for Xen */
25242 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25243 spin_lock(pgt_lock);
25244 +#endif
25245
25246 if (pgd_none(*pgd))
25247 set_pgd(pgd, *pgd_ref);
25248 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25249 BUG_ON(pgd_page_vaddr(*pgd)
25250 != pgd_page_vaddr(*pgd_ref));
25251
25252 +#ifndef CONFIG_PAX_PER_CPU_PGD
25253 spin_unlock(pgt_lock);
25254 +#endif
25255 +
25256 }
25257 spin_unlock(&pgd_lock);
25258 }
25259 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25260 {
25261 if (pgd_none(*pgd)) {
25262 pud_t *pud = (pud_t *)spp_getpage();
25263 - pgd_populate(&init_mm, pgd, pud);
25264 + pgd_populate_kernel(&init_mm, pgd, pud);
25265 if (pud != pud_offset(pgd, 0))
25266 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25267 pud, pud_offset(pgd, 0));
25268 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25269 {
25270 if (pud_none(*pud)) {
25271 pmd_t *pmd = (pmd_t *) spp_getpage();
25272 - pud_populate(&init_mm, pud, pmd);
25273 + pud_populate_kernel(&init_mm, pud, pmd);
25274 if (pmd != pmd_offset(pud, 0))
25275 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25276 pmd, pmd_offset(pud, 0));
25277 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25278 pmd = fill_pmd(pud, vaddr);
25279 pte = fill_pte(pmd, vaddr);
25280
25281 + pax_open_kernel();
25282 set_pte(pte, new_pte);
25283 + pax_close_kernel();
25284
25285 /*
25286 * It's enough to flush this one mapping.
25287 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25288 pgd = pgd_offset_k((unsigned long)__va(phys));
25289 if (pgd_none(*pgd)) {
25290 pud = (pud_t *) spp_getpage();
25291 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25292 - _PAGE_USER));
25293 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25294 }
25295 pud = pud_offset(pgd, (unsigned long)__va(phys));
25296 if (pud_none(*pud)) {
25297 pmd = (pmd_t *) spp_getpage();
25298 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25299 - _PAGE_USER));
25300 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25301 }
25302 pmd = pmd_offset(pud, phys);
25303 BUG_ON(!pmd_none(*pmd));
25304 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25305 if (pfn >= pgt_buf_top)
25306 panic("alloc_low_page: ran out of memory");
25307
25308 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25309 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25310 clear_page(adr);
25311 *phys = pfn * PAGE_SIZE;
25312 return adr;
25313 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25314
25315 phys = __pa(virt);
25316 left = phys & (PAGE_SIZE - 1);
25317 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25318 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25319 adr = (void *)(((unsigned long)adr) | left);
25320
25321 return adr;
25322 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25323 unmap_low_page(pmd);
25324
25325 spin_lock(&init_mm.page_table_lock);
25326 - pud_populate(&init_mm, pud, __va(pmd_phys));
25327 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25328 spin_unlock(&init_mm.page_table_lock);
25329 }
25330 __flush_tlb_all();
25331 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25332 unmap_low_page(pud);
25333
25334 spin_lock(&init_mm.page_table_lock);
25335 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25336 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25337 spin_unlock(&init_mm.page_table_lock);
25338 pgd_changed = true;
25339 }
25340 @@ -691,6 +705,12 @@ void __init mem_init(void)
25341
25342 pci_iommu_alloc();
25343
25344 +#ifdef CONFIG_PAX_PER_CPU_PGD
25345 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25346 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25347 + KERNEL_PGD_PTRS);
25348 +#endif
25349 +
25350 /* clear_bss() already clear the empty_zero_page */
25351
25352 reservedpages = 0;
25353 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25354 static struct vm_area_struct gate_vma = {
25355 .vm_start = VSYSCALL_START,
25356 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25357 - .vm_page_prot = PAGE_READONLY_EXEC,
25358 - .vm_flags = VM_READ | VM_EXEC
25359 + .vm_page_prot = PAGE_READONLY,
25360 + .vm_flags = VM_READ
25361 };
25362
25363 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25364 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25365
25366 const char *arch_vma_name(struct vm_area_struct *vma)
25367 {
25368 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25369 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25370 return "[vdso]";
25371 if (vma == &gate_vma)
25372 return "[vsyscall]";
25373 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25374 index 7b179b4..6bd1777 100644
25375 --- a/arch/x86/mm/iomap_32.c
25376 +++ b/arch/x86/mm/iomap_32.c
25377 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25378 type = kmap_atomic_idx_push();
25379 idx = type + KM_TYPE_NR * smp_processor_id();
25380 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25381 +
25382 + pax_open_kernel();
25383 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25384 + pax_close_kernel();
25385 +
25386 arch_flush_lazy_mmu_mode();
25387
25388 return (void *)vaddr;
25389 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25390 index 78fe3f1..8293b6f 100644
25391 --- a/arch/x86/mm/ioremap.c
25392 +++ b/arch/x86/mm/ioremap.c
25393 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25394 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25395 int is_ram = page_is_ram(pfn);
25396
25397 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25398 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25399 return NULL;
25400 WARN_ON_ONCE(is_ram);
25401 }
25402 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25403
25404 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25405 if (page_is_ram(start >> PAGE_SHIFT))
25406 +#ifdef CONFIG_HIGHMEM
25407 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25408 +#endif
25409 return __va(phys);
25410
25411 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25412 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25413 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25414
25415 static __initdata int after_paging_init;
25416 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25417 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25418
25419 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25420 {
25421 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25422 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25423
25424 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25425 - memset(bm_pte, 0, sizeof(bm_pte));
25426 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25427 + pmd_populate_user(&init_mm, pmd, bm_pte);
25428
25429 /*
25430 * The boot-ioremap range spans multiple pmds, for which
25431 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25432 index d87dd6d..bf3fa66 100644
25433 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25434 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25435 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25436 * memory (e.g. tracked pages)? For now, we need this to avoid
25437 * invoking kmemcheck for PnP BIOS calls.
25438 */
25439 - if (regs->flags & X86_VM_MASK)
25440 + if (v8086_mode(regs))
25441 return false;
25442 - if (regs->cs != __KERNEL_CS)
25443 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25444 return false;
25445
25446 pte = kmemcheck_pte_lookup(address);
25447 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25448 index 845df68..1d8d29f 100644
25449 --- a/arch/x86/mm/mmap.c
25450 +++ b/arch/x86/mm/mmap.c
25451 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25452 * Leave an at least ~128 MB hole with possible stack randomization.
25453 */
25454 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25455 -#define MAX_GAP (TASK_SIZE/6*5)
25456 +#define MAX_GAP (pax_task_size/6*5)
25457
25458 static int mmap_is_legacy(void)
25459 {
25460 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25461 return rnd << PAGE_SHIFT;
25462 }
25463
25464 -static unsigned long mmap_base(void)
25465 +static unsigned long mmap_base(struct mm_struct *mm)
25466 {
25467 unsigned long gap = rlimit(RLIMIT_STACK);
25468 + unsigned long pax_task_size = TASK_SIZE;
25469 +
25470 +#ifdef CONFIG_PAX_SEGMEXEC
25471 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25472 + pax_task_size = SEGMEXEC_TASK_SIZE;
25473 +#endif
25474
25475 if (gap < MIN_GAP)
25476 gap = MIN_GAP;
25477 else if (gap > MAX_GAP)
25478 gap = MAX_GAP;
25479
25480 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25481 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25482 }
25483
25484 /*
25485 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25486 * does, but not when emulating X86_32
25487 */
25488 -static unsigned long mmap_legacy_base(void)
25489 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25490 {
25491 - if (mmap_is_ia32())
25492 + if (mmap_is_ia32()) {
25493 +
25494 +#ifdef CONFIG_PAX_SEGMEXEC
25495 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25496 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25497 + else
25498 +#endif
25499 +
25500 return TASK_UNMAPPED_BASE;
25501 - else
25502 + } else
25503 return TASK_UNMAPPED_BASE + mmap_rnd();
25504 }
25505
25506 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25507 void arch_pick_mmap_layout(struct mm_struct *mm)
25508 {
25509 if (mmap_is_legacy()) {
25510 - mm->mmap_base = mmap_legacy_base();
25511 + mm->mmap_base = mmap_legacy_base(mm);
25512 +
25513 +#ifdef CONFIG_PAX_RANDMMAP
25514 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25515 + mm->mmap_base += mm->delta_mmap;
25516 +#endif
25517 +
25518 mm->get_unmapped_area = arch_get_unmapped_area;
25519 mm->unmap_area = arch_unmap_area;
25520 } else {
25521 - mm->mmap_base = mmap_base();
25522 + mm->mmap_base = mmap_base(mm);
25523 +
25524 +#ifdef CONFIG_PAX_RANDMMAP
25525 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25526 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25527 +#endif
25528 +
25529 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25530 mm->unmap_area = arch_unmap_area_topdown;
25531 }
25532 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25533 index dc0b727..dc9d71a 100644
25534 --- a/arch/x86/mm/mmio-mod.c
25535 +++ b/arch/x86/mm/mmio-mod.c
25536 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25537 break;
25538 default:
25539 {
25540 - unsigned char *ip = (unsigned char *)instptr;
25541 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25542 my_trace->opcode = MMIO_UNKNOWN_OP;
25543 my_trace->width = 0;
25544 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25545 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25546 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25547 void __iomem *addr)
25548 {
25549 - static atomic_t next_id;
25550 + static atomic_unchecked_t next_id;
25551 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25552 /* These are page-unaligned. */
25553 struct mmiotrace_map map = {
25554 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25555 .private = trace
25556 },
25557 .phys = offset,
25558 - .id = atomic_inc_return(&next_id)
25559 + .id = atomic_inc_return_unchecked(&next_id)
25560 };
25561 map.map_id = trace->id;
25562
25563 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25564 index b008656..773eac2 100644
25565 --- a/arch/x86/mm/pageattr-test.c
25566 +++ b/arch/x86/mm/pageattr-test.c
25567 @@ -36,7 +36,7 @@ enum {
25568
25569 static int pte_testbit(pte_t pte)
25570 {
25571 - return pte_flags(pte) & _PAGE_UNUSED1;
25572 + return pte_flags(pte) & _PAGE_CPA_TEST;
25573 }
25574
25575 struct split_state {
25576 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25577 index a718e0d..77419bc 100644
25578 --- a/arch/x86/mm/pageattr.c
25579 +++ b/arch/x86/mm/pageattr.c
25580 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25581 */
25582 #ifdef CONFIG_PCI_BIOS
25583 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25584 - pgprot_val(forbidden) |= _PAGE_NX;
25585 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25586 #endif
25587
25588 /*
25589 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25590 * Does not cover __inittext since that is gone later on. On
25591 * 64bit we do not enforce !NX on the low mapping
25592 */
25593 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25594 - pgprot_val(forbidden) |= _PAGE_NX;
25595 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25596 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25597
25598 +#ifdef CONFIG_DEBUG_RODATA
25599 /*
25600 * The .rodata section needs to be read-only. Using the pfn
25601 * catches all aliases.
25602 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25603 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25604 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25605 pgprot_val(forbidden) |= _PAGE_RW;
25606 +#endif
25607
25608 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25609 /*
25610 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25611 }
25612 #endif
25613
25614 +#ifdef CONFIG_PAX_KERNEXEC
25615 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
25616 + pgprot_val(forbidden) |= _PAGE_RW;
25617 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25618 + }
25619 +#endif
25620 +
25621 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25622
25623 return prot;
25624 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25625 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25626 {
25627 /* change init_mm */
25628 + pax_open_kernel();
25629 set_pte_atomic(kpte, pte);
25630 +
25631 #ifdef CONFIG_X86_32
25632 if (!SHARED_KERNEL_PMD) {
25633 +
25634 +#ifdef CONFIG_PAX_PER_CPU_PGD
25635 + unsigned long cpu;
25636 +#else
25637 struct page *page;
25638 +#endif
25639
25640 +#ifdef CONFIG_PAX_PER_CPU_PGD
25641 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25642 + pgd_t *pgd = get_cpu_pgd(cpu);
25643 +#else
25644 list_for_each_entry(page, &pgd_list, lru) {
25645 - pgd_t *pgd;
25646 + pgd_t *pgd = (pgd_t *)page_address(page);
25647 +#endif
25648 +
25649 pud_t *pud;
25650 pmd_t *pmd;
25651
25652 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25653 + pgd += pgd_index(address);
25654 pud = pud_offset(pgd, address);
25655 pmd = pmd_offset(pud, address);
25656 set_pte_atomic((pte_t *)pmd, pte);
25657 }
25658 }
25659 #endif
25660 + pax_close_kernel();
25661 }
25662
25663 static int
25664 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25665 index 0eb572e..92f5c1e 100644
25666 --- a/arch/x86/mm/pat.c
25667 +++ b/arch/x86/mm/pat.c
25668 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25669
25670 if (!entry) {
25671 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25672 - current->comm, current->pid, start, end - 1);
25673 + current->comm, task_pid_nr(current), start, end - 1);
25674 return -EINVAL;
25675 }
25676
25677 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25678
25679 while (cursor < to) {
25680 if (!devmem_is_allowed(pfn)) {
25681 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25682 - current->comm, from, to - 1);
25683 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25684 + current->comm, from, to - 1, cursor);
25685 return 0;
25686 }
25687 cursor += PAGE_SIZE;
25688 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25689 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25690 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25691 "for [mem %#010Lx-%#010Lx]\n",
25692 - current->comm, current->pid,
25693 + current->comm, task_pid_nr(current),
25694 cattr_name(flags),
25695 base, (unsigned long long)(base + size-1));
25696 return -EINVAL;
25697 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25698 flags = lookup_memtype(paddr);
25699 if (want_flags != flags) {
25700 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25701 - current->comm, current->pid,
25702 + current->comm, task_pid_nr(current),
25703 cattr_name(want_flags),
25704 (unsigned long long)paddr,
25705 (unsigned long long)(paddr + size - 1),
25706 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25707 free_memtype(paddr, paddr + size);
25708 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25709 " for [mem %#010Lx-%#010Lx], got %s\n",
25710 - current->comm, current->pid,
25711 + current->comm, task_pid_nr(current),
25712 cattr_name(want_flags),
25713 (unsigned long long)paddr,
25714 (unsigned long long)(paddr + size - 1),
25715 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25716 index 9f0614d..92ae64a 100644
25717 --- a/arch/x86/mm/pf_in.c
25718 +++ b/arch/x86/mm/pf_in.c
25719 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25720 int i;
25721 enum reason_type rv = OTHERS;
25722
25723 - p = (unsigned char *)ins_addr;
25724 + p = (unsigned char *)ktla_ktva(ins_addr);
25725 p += skip_prefix(p, &prf);
25726 p += get_opcode(p, &opcode);
25727
25728 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25729 struct prefix_bits prf;
25730 int i;
25731
25732 - p = (unsigned char *)ins_addr;
25733 + p = (unsigned char *)ktla_ktva(ins_addr);
25734 p += skip_prefix(p, &prf);
25735 p += get_opcode(p, &opcode);
25736
25737 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25738 struct prefix_bits prf;
25739 int i;
25740
25741 - p = (unsigned char *)ins_addr;
25742 + p = (unsigned char *)ktla_ktva(ins_addr);
25743 p += skip_prefix(p, &prf);
25744 p += get_opcode(p, &opcode);
25745
25746 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25747 struct prefix_bits prf;
25748 int i;
25749
25750 - p = (unsigned char *)ins_addr;
25751 + p = (unsigned char *)ktla_ktva(ins_addr);
25752 p += skip_prefix(p, &prf);
25753 p += get_opcode(p, &opcode);
25754 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25755 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25756 struct prefix_bits prf;
25757 int i;
25758
25759 - p = (unsigned char *)ins_addr;
25760 + p = (unsigned char *)ktla_ktva(ins_addr);
25761 p += skip_prefix(p, &prf);
25762 p += get_opcode(p, &opcode);
25763 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25764 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25765 index 8573b83..4f3ed7e 100644
25766 --- a/arch/x86/mm/pgtable.c
25767 +++ b/arch/x86/mm/pgtable.c
25768 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25769 list_del(&page->lru);
25770 }
25771
25772 -#define UNSHARED_PTRS_PER_PGD \
25773 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25774 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25775 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25776
25777 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25778 +{
25779 + unsigned int count = USER_PGD_PTRS;
25780
25781 + while (count--)
25782 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25783 +}
25784 +#endif
25785 +
25786 +#ifdef CONFIG_PAX_PER_CPU_PGD
25787 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25788 +{
25789 + unsigned int count = USER_PGD_PTRS;
25790 +
25791 + while (count--) {
25792 + pgd_t pgd;
25793 +
25794 +#ifdef CONFIG_X86_64
25795 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25796 +#else
25797 + pgd = *src++;
25798 +#endif
25799 +
25800 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25801 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25802 +#endif
25803 +
25804 + *dst++ = pgd;
25805 + }
25806 +
25807 +}
25808 +#endif
25809 +
25810 +#ifdef CONFIG_X86_64
25811 +#define pxd_t pud_t
25812 +#define pyd_t pgd_t
25813 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25814 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25815 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25816 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25817 +#define PYD_SIZE PGDIR_SIZE
25818 +#else
25819 +#define pxd_t pmd_t
25820 +#define pyd_t pud_t
25821 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25822 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25823 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25824 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25825 +#define PYD_SIZE PUD_SIZE
25826 +#endif
25827 +
25828 +#ifdef CONFIG_PAX_PER_CPU_PGD
25829 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25830 +static inline void pgd_dtor(pgd_t *pgd) {}
25831 +#else
25832 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25833 {
25834 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25835 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25836 pgd_list_del(pgd);
25837 spin_unlock(&pgd_lock);
25838 }
25839 +#endif
25840
25841 /*
25842 * List of all pgd's needed for non-PAE so it can invalidate entries
25843 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25844 * -- wli
25845 */
25846
25847 -#ifdef CONFIG_X86_PAE
25848 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25849 /*
25850 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25851 * updating the top-level pagetable entries to guarantee the
25852 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25853 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25854 * and initialize the kernel pmds here.
25855 */
25856 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25857 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25858
25859 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25860 {
25861 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25862 */
25863 flush_tlb_mm(mm);
25864 }
25865 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25866 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25867 #else /* !CONFIG_X86_PAE */
25868
25869 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25870 -#define PREALLOCATED_PMDS 0
25871 +#define PREALLOCATED_PXDS 0
25872
25873 #endif /* CONFIG_X86_PAE */
25874
25875 -static void free_pmds(pmd_t *pmds[])
25876 +static void free_pxds(pxd_t *pxds[])
25877 {
25878 int i;
25879
25880 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25881 - if (pmds[i])
25882 - free_page((unsigned long)pmds[i]);
25883 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25884 + if (pxds[i])
25885 + free_page((unsigned long)pxds[i]);
25886 }
25887
25888 -static int preallocate_pmds(pmd_t *pmds[])
25889 +static int preallocate_pxds(pxd_t *pxds[])
25890 {
25891 int i;
25892 bool failed = false;
25893
25894 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25895 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25896 - if (pmd == NULL)
25897 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25898 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25899 + if (pxd == NULL)
25900 failed = true;
25901 - pmds[i] = pmd;
25902 + pxds[i] = pxd;
25903 }
25904
25905 if (failed) {
25906 - free_pmds(pmds);
25907 + free_pxds(pxds);
25908 return -ENOMEM;
25909 }
25910
25911 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25912 * preallocate which never got a corresponding vma will need to be
25913 * freed manually.
25914 */
25915 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25916 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25917 {
25918 int i;
25919
25920 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25921 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25922 pgd_t pgd = pgdp[i];
25923
25924 if (pgd_val(pgd) != 0) {
25925 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25926 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25927
25928 - pgdp[i] = native_make_pgd(0);
25929 + set_pgd(pgdp + i, native_make_pgd(0));
25930
25931 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25932 - pmd_free(mm, pmd);
25933 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25934 + pxd_free(mm, pxd);
25935 }
25936 }
25937 }
25938
25939 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25940 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25941 {
25942 - pud_t *pud;
25943 + pyd_t *pyd;
25944 unsigned long addr;
25945 int i;
25946
25947 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25948 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25949 return;
25950
25951 - pud = pud_offset(pgd, 0);
25952 +#ifdef CONFIG_X86_64
25953 + pyd = pyd_offset(mm, 0L);
25954 +#else
25955 + pyd = pyd_offset(pgd, 0L);
25956 +#endif
25957
25958 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25959 - i++, pud++, addr += PUD_SIZE) {
25960 - pmd_t *pmd = pmds[i];
25961 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25962 + i++, pyd++, addr += PYD_SIZE) {
25963 + pxd_t *pxd = pxds[i];
25964
25965 if (i >= KERNEL_PGD_BOUNDARY)
25966 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25967 - sizeof(pmd_t) * PTRS_PER_PMD);
25968 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25969 + sizeof(pxd_t) * PTRS_PER_PMD);
25970
25971 - pud_populate(mm, pud, pmd);
25972 + pyd_populate(mm, pyd, pxd);
25973 }
25974 }
25975
25976 pgd_t *pgd_alloc(struct mm_struct *mm)
25977 {
25978 pgd_t *pgd;
25979 - pmd_t *pmds[PREALLOCATED_PMDS];
25980 + pxd_t *pxds[PREALLOCATED_PXDS];
25981
25982 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25983
25984 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25985
25986 mm->pgd = pgd;
25987
25988 - if (preallocate_pmds(pmds) != 0)
25989 + if (preallocate_pxds(pxds) != 0)
25990 goto out_free_pgd;
25991
25992 if (paravirt_pgd_alloc(mm) != 0)
25993 - goto out_free_pmds;
25994 + goto out_free_pxds;
25995
25996 /*
25997 * Make sure that pre-populating the pmds is atomic with
25998 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25999 spin_lock(&pgd_lock);
26000
26001 pgd_ctor(mm, pgd);
26002 - pgd_prepopulate_pmd(mm, pgd, pmds);
26003 + pgd_prepopulate_pxd(mm, pgd, pxds);
26004
26005 spin_unlock(&pgd_lock);
26006
26007 return pgd;
26008
26009 -out_free_pmds:
26010 - free_pmds(pmds);
26011 +out_free_pxds:
26012 + free_pxds(pxds);
26013 out_free_pgd:
26014 free_page((unsigned long)pgd);
26015 out:
26016 @@ -295,7 +356,7 @@ out:
26017
26018 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
26019 {
26020 - pgd_mop_up_pmds(mm, pgd);
26021 + pgd_mop_up_pxds(mm, pgd);
26022 pgd_dtor(pgd);
26023 paravirt_pgd_free(mm, pgd);
26024 free_page((unsigned long)pgd);
26025 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
26026 index a69bcb8..19068ab 100644
26027 --- a/arch/x86/mm/pgtable_32.c
26028 +++ b/arch/x86/mm/pgtable_32.c
26029 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
26030 return;
26031 }
26032 pte = pte_offset_kernel(pmd, vaddr);
26033 +
26034 + pax_open_kernel();
26035 if (pte_val(pteval))
26036 set_pte_at(&init_mm, vaddr, pte, pteval);
26037 else
26038 pte_clear(&init_mm, vaddr, pte);
26039 + pax_close_kernel();
26040
26041 /*
26042 * It's enough to flush this one mapping.
26043 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26044 index 410531d..0f16030 100644
26045 --- a/arch/x86/mm/setup_nx.c
26046 +++ b/arch/x86/mm/setup_nx.c
26047 @@ -5,8 +5,10 @@
26048 #include <asm/pgtable.h>
26049 #include <asm/proto.h>
26050
26051 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26052 static int disable_nx __cpuinitdata;
26053
26054 +#ifndef CONFIG_PAX_PAGEEXEC
26055 /*
26056 * noexec = on|off
26057 *
26058 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
26059 return 0;
26060 }
26061 early_param("noexec", noexec_setup);
26062 +#endif
26063 +
26064 +#endif
26065
26066 void __cpuinit x86_configure_nx(void)
26067 {
26068 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26069 if (cpu_has_nx && !disable_nx)
26070 __supported_pte_mask |= _PAGE_NX;
26071 else
26072 +#endif
26073 __supported_pte_mask &= ~_PAGE_NX;
26074 }
26075
26076 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26077 index 60f926c..a710970 100644
26078 --- a/arch/x86/mm/tlb.c
26079 +++ b/arch/x86/mm/tlb.c
26080 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
26081 BUG();
26082 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
26083 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
26084 +
26085 +#ifndef CONFIG_PAX_PER_CPU_PGD
26086 load_cr3(swapper_pg_dir);
26087 +#endif
26088 +
26089 }
26090 }
26091 EXPORT_SYMBOL_GPL(leave_mm);
26092 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26093 index 877b9a1..a8ecf42 100644
26094 --- a/arch/x86/net/bpf_jit.S
26095 +++ b/arch/x86/net/bpf_jit.S
26096 @@ -9,6 +9,7 @@
26097 */
26098 #include <linux/linkage.h>
26099 #include <asm/dwarf2.h>
26100 +#include <asm/alternative-asm.h>
26101
26102 /*
26103 * Calling convention :
26104 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26105 jle bpf_slow_path_word
26106 mov (SKBDATA,%rsi),%eax
26107 bswap %eax /* ntohl() */
26108 + pax_force_retaddr
26109 ret
26110
26111 sk_load_half:
26112 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26113 jle bpf_slow_path_half
26114 movzwl (SKBDATA,%rsi),%eax
26115 rol $8,%ax # ntohs()
26116 + pax_force_retaddr
26117 ret
26118
26119 sk_load_byte:
26120 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26121 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26122 jle bpf_slow_path_byte
26123 movzbl (SKBDATA,%rsi),%eax
26124 + pax_force_retaddr
26125 ret
26126
26127 /**
26128 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26129 movzbl (SKBDATA,%rsi),%ebx
26130 and $15,%bl
26131 shl $2,%bl
26132 + pax_force_retaddr
26133 ret
26134
26135 /* rsi contains offset and can be scratched */
26136 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26137 js bpf_error
26138 mov -12(%rbp),%eax
26139 bswap %eax
26140 + pax_force_retaddr
26141 ret
26142
26143 bpf_slow_path_half:
26144 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26145 mov -12(%rbp),%ax
26146 rol $8,%ax
26147 movzwl %ax,%eax
26148 + pax_force_retaddr
26149 ret
26150
26151 bpf_slow_path_byte:
26152 bpf_slow_path_common(1)
26153 js bpf_error
26154 movzbl -12(%rbp),%eax
26155 + pax_force_retaddr
26156 ret
26157
26158 bpf_slow_path_byte_msh:
26159 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26160 and $15,%al
26161 shl $2,%al
26162 xchg %eax,%ebx
26163 + pax_force_retaddr
26164 ret
26165
26166 #define sk_negative_common(SIZE) \
26167 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26168 sk_negative_common(4)
26169 mov (%rax), %eax
26170 bswap %eax
26171 + pax_force_retaddr
26172 ret
26173
26174 bpf_slow_path_half_neg:
26175 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26176 mov (%rax),%ax
26177 rol $8,%ax
26178 movzwl %ax,%eax
26179 + pax_force_retaddr
26180 ret
26181
26182 bpf_slow_path_byte_neg:
26183 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26184 .globl sk_load_byte_negative_offset
26185 sk_negative_common(1)
26186 movzbl (%rax), %eax
26187 + pax_force_retaddr
26188 ret
26189
26190 bpf_slow_path_byte_msh_neg:
26191 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26192 and $15,%al
26193 shl $2,%al
26194 xchg %eax,%ebx
26195 + pax_force_retaddr
26196 ret
26197
26198 bpf_error:
26199 @@ -197,4 +210,5 @@ bpf_error:
26200 xor %eax,%eax
26201 mov -8(%rbp),%rbx
26202 leaveq
26203 + pax_force_retaddr
26204 ret
26205 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26206 index 520d2bd..b895ef4 100644
26207 --- a/arch/x86/net/bpf_jit_comp.c
26208 +++ b/arch/x86/net/bpf_jit_comp.c
26209 @@ -11,6 +11,7 @@
26210 #include <asm/cacheflush.h>
26211 #include <linux/netdevice.h>
26212 #include <linux/filter.h>
26213 +#include <linux/random.h>
26214
26215 /*
26216 * Conventions :
26217 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26218 return ptr + len;
26219 }
26220
26221 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26222 +#define MAX_INSTR_CODE_SIZE 96
26223 +#else
26224 +#define MAX_INSTR_CODE_SIZE 64
26225 +#endif
26226 +
26227 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26228
26229 #define EMIT1(b1) EMIT(b1, 1)
26230 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26231 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26232 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26233 +
26234 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26235 +/* original constant will appear in ecx */
26236 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
26237 +do { \
26238 + /* mov ecx, randkey */ \
26239 + EMIT1(0xb9); \
26240 + EMIT(_key, 4); \
26241 + /* xor ecx, randkey ^ off */ \
26242 + EMIT2(0x81, 0xf1); \
26243 + EMIT((_key) ^ (_off), 4); \
26244 +} while (0)
26245 +
26246 +#define EMIT1_off32(b1, _off) \
26247 +do { \
26248 + switch (b1) { \
26249 + case 0x05: /* add eax, imm32 */ \
26250 + case 0x2d: /* sub eax, imm32 */ \
26251 + case 0x25: /* and eax, imm32 */ \
26252 + case 0x0d: /* or eax, imm32 */ \
26253 + case 0xb8: /* mov eax, imm32 */ \
26254 + case 0x3d: /* cmp eax, imm32 */ \
26255 + case 0xa9: /* test eax, imm32 */ \
26256 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26257 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26258 + break; \
26259 + case 0xbb: /* mov ebx, imm32 */ \
26260 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26261 + /* mov ebx, ecx */ \
26262 + EMIT2(0x89, 0xcb); \
26263 + break; \
26264 + case 0xbe: /* mov esi, imm32 */ \
26265 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26266 + /* mov esi, ecx */ \
26267 + EMIT2(0x89, 0xce); \
26268 + break; \
26269 + case 0xe9: /* jmp rel imm32 */ \
26270 + EMIT1(b1); \
26271 + EMIT(_off, 4); \
26272 + /* prevent fall-through, we're not called if off = 0 */ \
26273 + EMIT(0xcccccccc, 4); \
26274 + EMIT(0xcccccccc, 4); \
26275 + break; \
26276 + default: \
26277 + EMIT1(b1); \
26278 + EMIT(_off, 4); \
26279 + } \
26280 +} while (0)
26281 +
26282 +#define EMIT2_off32(b1, b2, _off) \
26283 +do { \
26284 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26285 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26286 + EMIT(randkey, 4); \
26287 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26288 + EMIT((_off) - randkey, 4); \
26289 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26290 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26291 + /* imul eax, ecx */ \
26292 + EMIT3(0x0f, 0xaf, 0xc1); \
26293 + } else { \
26294 + EMIT2(b1, b2); \
26295 + EMIT(_off, 4); \
26296 + } \
26297 +} while (0)
26298 +#else
26299 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26300 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26301 +#endif
26302
26303 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26304 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26305 @@ -89,6 +164,24 @@ do { \
26306 #define X86_JBE 0x76
26307 #define X86_JA 0x77
26308
26309 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26310 +#define APPEND_FLOW_VERIFY() \
26311 +do { \
26312 + /* mov ecx, randkey */ \
26313 + EMIT1(0xb9); \
26314 + EMIT(randkey, 4); \
26315 + /* cmp ecx, randkey */ \
26316 + EMIT2(0x81, 0xf9); \
26317 + EMIT(randkey, 4); \
26318 + /* jz after 8 int 3s */ \
26319 + EMIT2(0x74, 0x08); \
26320 + EMIT(0xcccccccc, 4); \
26321 + EMIT(0xcccccccc, 4); \
26322 +} while (0)
26323 +#else
26324 +#define APPEND_FLOW_VERIFY() do { } while (0)
26325 +#endif
26326 +
26327 #define EMIT_COND_JMP(op, offset) \
26328 do { \
26329 if (is_near(offset)) \
26330 @@ -96,6 +189,7 @@ do { \
26331 else { \
26332 EMIT2(0x0f, op + 0x10); \
26333 EMIT(offset, 4); /* jxx .+off32 */ \
26334 + APPEND_FLOW_VERIFY(); \
26335 } \
26336 } while (0)
26337
26338 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26339 set_fs(old_fs);
26340 }
26341
26342 +struct bpf_jit_work {
26343 + struct work_struct work;
26344 + void *image;
26345 +};
26346 +
26347 #define CHOOSE_LOAD_FUNC(K, func) \
26348 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26349
26350 void bpf_jit_compile(struct sk_filter *fp)
26351 {
26352 - u8 temp[64];
26353 + u8 temp[MAX_INSTR_CODE_SIZE];
26354 u8 *prog;
26355 unsigned int proglen, oldproglen = 0;
26356 int ilen, i;
26357 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26358 unsigned int *addrs;
26359 const struct sock_filter *filter = fp->insns;
26360 int flen = fp->len;
26361 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26362 + unsigned int randkey;
26363 +#endif
26364
26365 if (!bpf_jit_enable)
26366 return;
26367 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26368 if (addrs == NULL)
26369 return;
26370
26371 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26372 + if (!fp->work)
26373 + goto out;
26374 +
26375 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26376 + randkey = get_random_int();
26377 +#endif
26378 +
26379 /* Before first pass, make a rough estimation of addrs[]
26380 - * each bpf instruction is translated to less than 64 bytes
26381 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26382 */
26383 for (proglen = 0, i = 0; i < flen; i++) {
26384 - proglen += 64;
26385 + proglen += MAX_INSTR_CODE_SIZE;
26386 addrs[i] = proglen;
26387 }
26388 cleanup_addr = proglen; /* epilogue address */
26389 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26390 case BPF_S_ALU_MUL_K: /* A *= K */
26391 if (is_imm8(K))
26392 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26393 - else {
26394 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26395 - EMIT(K, 4);
26396 - }
26397 + else
26398 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26399 break;
26400 case BPF_S_ALU_DIV_X: /* A /= X; */
26401 seen |= SEEN_XREG;
26402 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
26403 break;
26404 case BPF_S_ALU_MOD_K: /* A %= K; */
26405 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
26406 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26407 + DILUTE_CONST_SEQUENCE(K, randkey);
26408 +#else
26409 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
26410 +#endif
26411 EMIT2(0xf7, 0xf1); /* div %ecx */
26412 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
26413 break;
26414 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26415 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26416 + DILUTE_CONST_SEQUENCE(K, randkey);
26417 + // imul rax, rcx
26418 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26419 +#else
26420 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26421 EMIT(K, 4);
26422 +#endif
26423 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26424 break;
26425 case BPF_S_ALU_AND_X:
26426 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26427 if (is_imm8(K)) {
26428 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26429 } else {
26430 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26431 - EMIT(K, 4);
26432 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26433 }
26434 } else {
26435 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26436 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26437 break;
26438 default:
26439 /* hmm, too complex filter, give up with jit compiler */
26440 - goto out;
26441 + goto error;
26442 }
26443 ilen = prog - temp;
26444 if (image) {
26445 if (unlikely(proglen + ilen > oldproglen)) {
26446 pr_err("bpb_jit_compile fatal error\n");
26447 - kfree(addrs);
26448 - module_free(NULL, image);
26449 - return;
26450 + module_free_exec(NULL, image);
26451 + goto error;
26452 }
26453 + pax_open_kernel();
26454 memcpy(image + proglen, temp, ilen);
26455 + pax_close_kernel();
26456 }
26457 proglen += ilen;
26458 addrs[i] = proglen;
26459 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26460 break;
26461 }
26462 if (proglen == oldproglen) {
26463 - image = module_alloc(max_t(unsigned int,
26464 - proglen,
26465 - sizeof(struct work_struct)));
26466 + image = module_alloc_exec(proglen);
26467 if (!image)
26468 - goto out;
26469 + goto error;
26470 }
26471 oldproglen = proglen;
26472 }
26473 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26474 bpf_flush_icache(image, image + proglen);
26475
26476 fp->bpf_func = (void *)image;
26477 - }
26478 + } else
26479 +error:
26480 + kfree(fp->work);
26481 +
26482 out:
26483 kfree(addrs);
26484 return;
26485 @@ -686,18 +805,20 @@ out:
26486
26487 static void jit_free_defer(struct work_struct *arg)
26488 {
26489 - module_free(NULL, arg);
26490 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26491 + kfree(arg);
26492 }
26493
26494 /* run from softirq, we must use a work_struct to call
26495 - * module_free() from process context
26496 + * module_free_exec() from process context
26497 */
26498 void bpf_jit_free(struct sk_filter *fp)
26499 {
26500 if (fp->bpf_func != sk_run_filter) {
26501 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26502 + struct work_struct *work = &fp->work->work;
26503
26504 INIT_WORK(work, jit_free_defer);
26505 + fp->work->image = fp->bpf_func;
26506 schedule_work(work);
26507 }
26508 }
26509 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26510 index d6aa6e8..266395a 100644
26511 --- a/arch/x86/oprofile/backtrace.c
26512 +++ b/arch/x86/oprofile/backtrace.c
26513 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26514 struct stack_frame_ia32 *fp;
26515 unsigned long bytes;
26516
26517 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26518 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26519 if (bytes != sizeof(bufhead))
26520 return NULL;
26521
26522 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26523 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26524
26525 oprofile_add_trace(bufhead[0].return_address);
26526
26527 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26528 struct stack_frame bufhead[2];
26529 unsigned long bytes;
26530
26531 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26532 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26533 if (bytes != sizeof(bufhead))
26534 return NULL;
26535
26536 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26537 {
26538 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26539
26540 - if (!user_mode_vm(regs)) {
26541 + if (!user_mode(regs)) {
26542 unsigned long stack = kernel_stack_pointer(regs);
26543 if (depth)
26544 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26545 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26546 index e14a2ff..3fd6b58 100644
26547 --- a/arch/x86/pci/mrst.c
26548 +++ b/arch/x86/pci/mrst.c
26549 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26550 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26551 pci_mmcfg_late_init();
26552 pcibios_enable_irq = mrst_pci_irq_enable;
26553 - pci_root_ops = pci_mrst_ops;
26554 + pax_open_kernel();
26555 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26556 + pax_close_kernel();
26557 pci_soc_mode = 1;
26558 /* Continue with standard init */
26559 return 1;
26560 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26561 index da8fe05..7ee6704 100644
26562 --- a/arch/x86/pci/pcbios.c
26563 +++ b/arch/x86/pci/pcbios.c
26564 @@ -79,50 +79,93 @@ union bios32 {
26565 static struct {
26566 unsigned long address;
26567 unsigned short segment;
26568 -} bios32_indirect = { 0, __KERNEL_CS };
26569 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26570
26571 /*
26572 * Returns the entry point for the given service, NULL on error
26573 */
26574
26575 -static unsigned long bios32_service(unsigned long service)
26576 +static unsigned long __devinit bios32_service(unsigned long service)
26577 {
26578 unsigned char return_code; /* %al */
26579 unsigned long address; /* %ebx */
26580 unsigned long length; /* %ecx */
26581 unsigned long entry; /* %edx */
26582 unsigned long flags;
26583 + struct desc_struct d, *gdt;
26584
26585 local_irq_save(flags);
26586 - __asm__("lcall *(%%edi); cld"
26587 +
26588 + gdt = get_cpu_gdt_table(smp_processor_id());
26589 +
26590 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26591 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26592 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26593 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26594 +
26595 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26596 : "=a" (return_code),
26597 "=b" (address),
26598 "=c" (length),
26599 "=d" (entry)
26600 : "0" (service),
26601 "1" (0),
26602 - "D" (&bios32_indirect));
26603 + "D" (&bios32_indirect),
26604 + "r"(__PCIBIOS_DS)
26605 + : "memory");
26606 +
26607 + pax_open_kernel();
26608 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26609 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26610 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26611 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26612 + pax_close_kernel();
26613 +
26614 local_irq_restore(flags);
26615
26616 switch (return_code) {
26617 - case 0:
26618 - return address + entry;
26619 - case 0x80: /* Not present */
26620 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26621 - return 0;
26622 - default: /* Shouldn't happen */
26623 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26624 - service, return_code);
26625 + case 0: {
26626 + int cpu;
26627 + unsigned char flags;
26628 +
26629 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26630 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26631 + printk(KERN_WARNING "bios32_service: not valid\n");
26632 return 0;
26633 + }
26634 + address = address + PAGE_OFFSET;
26635 + length += 16UL; /* some BIOSs underreport this... */
26636 + flags = 4;
26637 + if (length >= 64*1024*1024) {
26638 + length >>= PAGE_SHIFT;
26639 + flags |= 8;
26640 + }
26641 +
26642 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26643 + gdt = get_cpu_gdt_table(cpu);
26644 + pack_descriptor(&d, address, length, 0x9b, flags);
26645 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26646 + pack_descriptor(&d, address, length, 0x93, flags);
26647 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26648 + }
26649 + return entry;
26650 + }
26651 + case 0x80: /* Not present */
26652 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26653 + return 0;
26654 + default: /* Shouldn't happen */
26655 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26656 + service, return_code);
26657 + return 0;
26658 }
26659 }
26660
26661 static struct {
26662 unsigned long address;
26663 unsigned short segment;
26664 -} pci_indirect = { 0, __KERNEL_CS };
26665 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26666
26667 -static int pci_bios_present;
26668 +static int pci_bios_present __read_only;
26669
26670 static int __devinit check_pcibios(void)
26671 {
26672 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26673 unsigned long flags, pcibios_entry;
26674
26675 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26676 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26677 + pci_indirect.address = pcibios_entry;
26678
26679 local_irq_save(flags);
26680 - __asm__(
26681 - "lcall *(%%edi); cld\n\t"
26682 + __asm__("movw %w6, %%ds\n\t"
26683 + "lcall *%%ss:(%%edi); cld\n\t"
26684 + "push %%ss\n\t"
26685 + "pop %%ds\n\t"
26686 "jc 1f\n\t"
26687 "xor %%ah, %%ah\n"
26688 "1:"
26689 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26690 "=b" (ebx),
26691 "=c" (ecx)
26692 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26693 - "D" (&pci_indirect)
26694 + "D" (&pci_indirect),
26695 + "r" (__PCIBIOS_DS)
26696 : "memory");
26697 local_irq_restore(flags);
26698
26699 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26700
26701 switch (len) {
26702 case 1:
26703 - __asm__("lcall *(%%esi); cld\n\t"
26704 + __asm__("movw %w6, %%ds\n\t"
26705 + "lcall *%%ss:(%%esi); cld\n\t"
26706 + "push %%ss\n\t"
26707 + "pop %%ds\n\t"
26708 "jc 1f\n\t"
26709 "xor %%ah, %%ah\n"
26710 "1:"
26711 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26712 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26713 "b" (bx),
26714 "D" ((long)reg),
26715 - "S" (&pci_indirect));
26716 + "S" (&pci_indirect),
26717 + "r" (__PCIBIOS_DS));
26718 /*
26719 * Zero-extend the result beyond 8 bits, do not trust the
26720 * BIOS having done it:
26721 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26722 *value &= 0xff;
26723 break;
26724 case 2:
26725 - __asm__("lcall *(%%esi); cld\n\t"
26726 + __asm__("movw %w6, %%ds\n\t"
26727 + "lcall *%%ss:(%%esi); cld\n\t"
26728 + "push %%ss\n\t"
26729 + "pop %%ds\n\t"
26730 "jc 1f\n\t"
26731 "xor %%ah, %%ah\n"
26732 "1:"
26733 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26734 : "1" (PCIBIOS_READ_CONFIG_WORD),
26735 "b" (bx),
26736 "D" ((long)reg),
26737 - "S" (&pci_indirect));
26738 + "S" (&pci_indirect),
26739 + "r" (__PCIBIOS_DS));
26740 /*
26741 * Zero-extend the result beyond 16 bits, do not trust the
26742 * BIOS having done it:
26743 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26744 *value &= 0xffff;
26745 break;
26746 case 4:
26747 - __asm__("lcall *(%%esi); cld\n\t"
26748 + __asm__("movw %w6, %%ds\n\t"
26749 + "lcall *%%ss:(%%esi); cld\n\t"
26750 + "push %%ss\n\t"
26751 + "pop %%ds\n\t"
26752 "jc 1f\n\t"
26753 "xor %%ah, %%ah\n"
26754 "1:"
26755 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26756 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26757 "b" (bx),
26758 "D" ((long)reg),
26759 - "S" (&pci_indirect));
26760 + "S" (&pci_indirect),
26761 + "r" (__PCIBIOS_DS));
26762 break;
26763 }
26764
26765 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26766
26767 switch (len) {
26768 case 1:
26769 - __asm__("lcall *(%%esi); cld\n\t"
26770 + __asm__("movw %w6, %%ds\n\t"
26771 + "lcall *%%ss:(%%esi); cld\n\t"
26772 + "push %%ss\n\t"
26773 + "pop %%ds\n\t"
26774 "jc 1f\n\t"
26775 "xor %%ah, %%ah\n"
26776 "1:"
26777 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26778 "c" (value),
26779 "b" (bx),
26780 "D" ((long)reg),
26781 - "S" (&pci_indirect));
26782 + "S" (&pci_indirect),
26783 + "r" (__PCIBIOS_DS));
26784 break;
26785 case 2:
26786 - __asm__("lcall *(%%esi); cld\n\t"
26787 + __asm__("movw %w6, %%ds\n\t"
26788 + "lcall *%%ss:(%%esi); cld\n\t"
26789 + "push %%ss\n\t"
26790 + "pop %%ds\n\t"
26791 "jc 1f\n\t"
26792 "xor %%ah, %%ah\n"
26793 "1:"
26794 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26795 "c" (value),
26796 "b" (bx),
26797 "D" ((long)reg),
26798 - "S" (&pci_indirect));
26799 + "S" (&pci_indirect),
26800 + "r" (__PCIBIOS_DS));
26801 break;
26802 case 4:
26803 - __asm__("lcall *(%%esi); cld\n\t"
26804 + __asm__("movw %w6, %%ds\n\t"
26805 + "lcall *%%ss:(%%esi); cld\n\t"
26806 + "push %%ss\n\t"
26807 + "pop %%ds\n\t"
26808 "jc 1f\n\t"
26809 "xor %%ah, %%ah\n"
26810 "1:"
26811 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26812 "c" (value),
26813 "b" (bx),
26814 "D" ((long)reg),
26815 - "S" (&pci_indirect));
26816 + "S" (&pci_indirect),
26817 + "r" (__PCIBIOS_DS));
26818 break;
26819 }
26820
26821 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26822
26823 DBG("PCI: Fetching IRQ routing table... ");
26824 __asm__("push %%es\n\t"
26825 + "movw %w8, %%ds\n\t"
26826 "push %%ds\n\t"
26827 "pop %%es\n\t"
26828 - "lcall *(%%esi); cld\n\t"
26829 + "lcall *%%ss:(%%esi); cld\n\t"
26830 "pop %%es\n\t"
26831 + "push %%ss\n\t"
26832 + "pop %%ds\n"
26833 "jc 1f\n\t"
26834 "xor %%ah, %%ah\n"
26835 "1:"
26836 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26837 "1" (0),
26838 "D" ((long) &opt),
26839 "S" (&pci_indirect),
26840 - "m" (opt)
26841 + "m" (opt),
26842 + "r" (__PCIBIOS_DS)
26843 : "memory");
26844 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26845 if (ret & 0xff00)
26846 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26847 {
26848 int ret;
26849
26850 - __asm__("lcall *(%%esi); cld\n\t"
26851 + __asm__("movw %w5, %%ds\n\t"
26852 + "lcall *%%ss:(%%esi); cld\n\t"
26853 + "push %%ss\n\t"
26854 + "pop %%ds\n"
26855 "jc 1f\n\t"
26856 "xor %%ah, %%ah\n"
26857 "1:"
26858 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26859 : "0" (PCIBIOS_SET_PCI_HW_INT),
26860 "b" ((dev->bus->number << 8) | dev->devfn),
26861 "c" ((irq << 8) | (pin + 10)),
26862 - "S" (&pci_indirect));
26863 + "S" (&pci_indirect),
26864 + "r" (__PCIBIOS_DS));
26865 return !(ret & 0xff00);
26866 }
26867 EXPORT_SYMBOL(pcibios_set_irq_routing);
26868 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26869 index 40e4469..1ab536e 100644
26870 --- a/arch/x86/platform/efi/efi_32.c
26871 +++ b/arch/x86/platform/efi/efi_32.c
26872 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26873 {
26874 struct desc_ptr gdt_descr;
26875
26876 +#ifdef CONFIG_PAX_KERNEXEC
26877 + struct desc_struct d;
26878 +#endif
26879 +
26880 local_irq_save(efi_rt_eflags);
26881
26882 load_cr3(initial_page_table);
26883 __flush_tlb_all();
26884
26885 +#ifdef CONFIG_PAX_KERNEXEC
26886 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26887 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26888 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26889 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26890 +#endif
26891 +
26892 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26893 gdt_descr.size = GDT_SIZE - 1;
26894 load_gdt(&gdt_descr);
26895 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26896 {
26897 struct desc_ptr gdt_descr;
26898
26899 +#ifdef CONFIG_PAX_KERNEXEC
26900 + struct desc_struct d;
26901 +
26902 + memset(&d, 0, sizeof d);
26903 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26904 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26905 +#endif
26906 +
26907 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26908 gdt_descr.size = GDT_SIZE - 1;
26909 load_gdt(&gdt_descr);
26910 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26911 index fbe66e6..eae5e38 100644
26912 --- a/arch/x86/platform/efi/efi_stub_32.S
26913 +++ b/arch/x86/platform/efi/efi_stub_32.S
26914 @@ -6,7 +6,9 @@
26915 */
26916
26917 #include <linux/linkage.h>
26918 +#include <linux/init.h>
26919 #include <asm/page_types.h>
26920 +#include <asm/segment.h>
26921
26922 /*
26923 * efi_call_phys(void *, ...) is a function with variable parameters.
26924 @@ -20,7 +22,7 @@
26925 * service functions will comply with gcc calling convention, too.
26926 */
26927
26928 -.text
26929 +__INIT
26930 ENTRY(efi_call_phys)
26931 /*
26932 * 0. The function can only be called in Linux kernel. So CS has been
26933 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26934 * The mapping of lower virtual memory has been created in prelog and
26935 * epilog.
26936 */
26937 - movl $1f, %edx
26938 - subl $__PAGE_OFFSET, %edx
26939 - jmp *%edx
26940 +#ifdef CONFIG_PAX_KERNEXEC
26941 + movl $(__KERNEXEC_EFI_DS), %edx
26942 + mov %edx, %ds
26943 + mov %edx, %es
26944 + mov %edx, %ss
26945 + addl $2f,(1f)
26946 + ljmp *(1f)
26947 +
26948 +__INITDATA
26949 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26950 +.previous
26951 +
26952 +2:
26953 + subl $2b,(1b)
26954 +#else
26955 + jmp 1f-__PAGE_OFFSET
26956 1:
26957 +#endif
26958
26959 /*
26960 * 2. Now on the top of stack is the return
26961 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26962 * parameter 2, ..., param n. To make things easy, we save the return
26963 * address of efi_call_phys in a global variable.
26964 */
26965 - popl %edx
26966 - movl %edx, saved_return_addr
26967 - /* get the function pointer into ECX*/
26968 - popl %ecx
26969 - movl %ecx, efi_rt_function_ptr
26970 - movl $2f, %edx
26971 - subl $__PAGE_OFFSET, %edx
26972 - pushl %edx
26973 + popl (saved_return_addr)
26974 + popl (efi_rt_function_ptr)
26975
26976 /*
26977 * 3. Clear PG bit in %CR0.
26978 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26979 /*
26980 * 5. Call the physical function.
26981 */
26982 - jmp *%ecx
26983 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26984
26985 -2:
26986 /*
26987 * 6. After EFI runtime service returns, control will return to
26988 * following instruction. We'd better readjust stack pointer first.
26989 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26990 movl %cr0, %edx
26991 orl $0x80000000, %edx
26992 movl %edx, %cr0
26993 - jmp 1f
26994 -1:
26995 +
26996 /*
26997 * 8. Now restore the virtual mode from flat mode by
26998 * adding EIP with PAGE_OFFSET.
26999 */
27000 - movl $1f, %edx
27001 - jmp *%edx
27002 +#ifdef CONFIG_PAX_KERNEXEC
27003 + movl $(__KERNEL_DS), %edx
27004 + mov %edx, %ds
27005 + mov %edx, %es
27006 + mov %edx, %ss
27007 + ljmp $(__KERNEL_CS),$1f
27008 +#else
27009 + jmp 1f+__PAGE_OFFSET
27010 +#endif
27011 1:
27012
27013 /*
27014 * 9. Balance the stack. And because EAX contain the return value,
27015 * we'd better not clobber it.
27016 */
27017 - leal efi_rt_function_ptr, %edx
27018 - movl (%edx), %ecx
27019 - pushl %ecx
27020 + pushl (efi_rt_function_ptr)
27021
27022 /*
27023 - * 10. Push the saved return address onto the stack and return.
27024 + * 10. Return to the saved return address.
27025 */
27026 - leal saved_return_addr, %edx
27027 - movl (%edx), %ecx
27028 - pushl %ecx
27029 - ret
27030 + jmpl *(saved_return_addr)
27031 ENDPROC(efi_call_phys)
27032 .previous
27033
27034 -.data
27035 +__INITDATA
27036 saved_return_addr:
27037 .long 0
27038 efi_rt_function_ptr:
27039 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
27040 index 4c07cca..2c8427d 100644
27041 --- a/arch/x86/platform/efi/efi_stub_64.S
27042 +++ b/arch/x86/platform/efi/efi_stub_64.S
27043 @@ -7,6 +7,7 @@
27044 */
27045
27046 #include <linux/linkage.h>
27047 +#include <asm/alternative-asm.h>
27048
27049 #define SAVE_XMM \
27050 mov %rsp, %rax; \
27051 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
27052 call *%rdi
27053 addq $32, %rsp
27054 RESTORE_XMM
27055 + pax_force_retaddr 0, 1
27056 ret
27057 ENDPROC(efi_call0)
27058
27059 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
27060 call *%rdi
27061 addq $32, %rsp
27062 RESTORE_XMM
27063 + pax_force_retaddr 0, 1
27064 ret
27065 ENDPROC(efi_call1)
27066
27067 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
27068 call *%rdi
27069 addq $32, %rsp
27070 RESTORE_XMM
27071 + pax_force_retaddr 0, 1
27072 ret
27073 ENDPROC(efi_call2)
27074
27075 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
27076 call *%rdi
27077 addq $32, %rsp
27078 RESTORE_XMM
27079 + pax_force_retaddr 0, 1
27080 ret
27081 ENDPROC(efi_call3)
27082
27083 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
27084 call *%rdi
27085 addq $32, %rsp
27086 RESTORE_XMM
27087 + pax_force_retaddr 0, 1
27088 ret
27089 ENDPROC(efi_call4)
27090
27091 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
27092 call *%rdi
27093 addq $48, %rsp
27094 RESTORE_XMM
27095 + pax_force_retaddr 0, 1
27096 ret
27097 ENDPROC(efi_call5)
27098
27099 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
27100 call *%rdi
27101 addq $48, %rsp
27102 RESTORE_XMM
27103 + pax_force_retaddr 0, 1
27104 ret
27105 ENDPROC(efi_call6)
27106 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
27107 index fd41a92..9c33628 100644
27108 --- a/arch/x86/platform/mrst/mrst.c
27109 +++ b/arch/x86/platform/mrst/mrst.c
27110 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
27111 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27112 int sfi_mrtc_num;
27113
27114 -static void mrst_power_off(void)
27115 +static __noreturn void mrst_power_off(void)
27116 {
27117 + BUG();
27118 }
27119
27120 -static void mrst_reboot(void)
27121 +static __noreturn void mrst_reboot(void)
27122 {
27123 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27124 + BUG();
27125 }
27126
27127 /* parse all the mtimer info to a static mtimer array */
27128 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27129 index 218cdb1..c1178eb 100644
27130 --- a/arch/x86/power/cpu.c
27131 +++ b/arch/x86/power/cpu.c
27132 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
27133 static void fix_processor_context(void)
27134 {
27135 int cpu = smp_processor_id();
27136 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27137 + struct tss_struct *t = init_tss + cpu;
27138
27139 set_tss_desc(cpu, t); /*
27140 * This just modifies memory; should not be
27141 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
27142 */
27143
27144 #ifdef CONFIG_X86_64
27145 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27146 -
27147 syscall_init(); /* This sets MSR_*STAR and related */
27148 #endif
27149 load_TR_desc(); /* This does ltr */
27150 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27151 index cbca565..bae7133 100644
27152 --- a/arch/x86/realmode/init.c
27153 +++ b/arch/x86/realmode/init.c
27154 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27155 __va(real_mode_header->trampoline_header);
27156
27157 #ifdef CONFIG_X86_32
27158 - trampoline_header->start = __pa(startup_32_smp);
27159 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27160 +
27161 +#ifdef CONFIG_PAX_KERNEXEC
27162 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27163 +#endif
27164 +
27165 + trampoline_header->boot_cs = __BOOT_CS;
27166 trampoline_header->gdt_limit = __BOOT_DS + 7;
27167 trampoline_header->gdt_base = __pa(boot_gdt);
27168 #else
27169 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27170 index 8869287..d577672 100644
27171 --- a/arch/x86/realmode/rm/Makefile
27172 +++ b/arch/x86/realmode/rm/Makefile
27173 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27174 $(call cc-option, -fno-unit-at-a-time)) \
27175 $(call cc-option, -fno-stack-protector) \
27176 $(call cc-option, -mpreferred-stack-boundary=2)
27177 +ifdef CONSTIFY_PLUGIN
27178 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27179 +endif
27180 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27181 GCOV_PROFILE := n
27182 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27183 index a28221d..93c40f1 100644
27184 --- a/arch/x86/realmode/rm/header.S
27185 +++ b/arch/x86/realmode/rm/header.S
27186 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27187 #endif
27188 /* APM/BIOS reboot */
27189 .long pa_machine_real_restart_asm
27190 -#ifdef CONFIG_X86_64
27191 +#ifdef CONFIG_X86_32
27192 + .long __KERNEL_CS
27193 +#else
27194 .long __KERNEL32_CS
27195 #endif
27196 END(real_mode_header)
27197 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27198 index c1b2791..f9e31c7 100644
27199 --- a/arch/x86/realmode/rm/trampoline_32.S
27200 +++ b/arch/x86/realmode/rm/trampoline_32.S
27201 @@ -25,6 +25,12 @@
27202 #include <asm/page_types.h>
27203 #include "realmode.h"
27204
27205 +#ifdef CONFIG_PAX_KERNEXEC
27206 +#define ta(X) (X)
27207 +#else
27208 +#define ta(X) (pa_ ## X)
27209 +#endif
27210 +
27211 .text
27212 .code16
27213
27214 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27215
27216 cli # We should be safe anyway
27217
27218 - movl tr_start, %eax # where we need to go
27219 -
27220 movl $0xA5A5A5A5, trampoline_status
27221 # write marker for master knows we're running
27222
27223 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27224 movw $1, %dx # protected mode (PE) bit
27225 lmsw %dx # into protected mode
27226
27227 - ljmpl $__BOOT_CS, $pa_startup_32
27228 + ljmpl *(trampoline_header)
27229
27230 .section ".text32","ax"
27231 .code32
27232 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27233 .balign 8
27234 GLOBAL(trampoline_header)
27235 tr_start: .space 4
27236 - tr_gdt_pad: .space 2
27237 + tr_boot_cs: .space 2
27238 tr_gdt: .space 6
27239 END(trampoline_header)
27240
27241 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27242 index bb360dc..3e5945f 100644
27243 --- a/arch/x86/realmode/rm/trampoline_64.S
27244 +++ b/arch/x86/realmode/rm/trampoline_64.S
27245 @@ -107,7 +107,7 @@ ENTRY(startup_32)
27246 wrmsr
27247
27248 # Enable paging and in turn activate Long Mode
27249 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27250 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
27251 movl %eax, %cr0
27252
27253 /*
27254 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27255 index 5a1847d..deccb30 100644
27256 --- a/arch/x86/tools/relocs.c
27257 +++ b/arch/x86/tools/relocs.c
27258 @@ -12,10 +12,13 @@
27259 #include <regex.h>
27260 #include <tools/le_byteshift.h>
27261
27262 +#include "../../../include/generated/autoconf.h"
27263 +
27264 static void die(char *fmt, ...);
27265
27266 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27267 static Elf32_Ehdr ehdr;
27268 +static Elf32_Phdr *phdr;
27269 static unsigned long reloc_count, reloc_idx;
27270 static unsigned long *relocs;
27271 static unsigned long reloc16_count, reloc16_idx;
27272 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27273 }
27274 }
27275
27276 +static void read_phdrs(FILE *fp)
27277 +{
27278 + unsigned int i;
27279 +
27280 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27281 + if (!phdr) {
27282 + die("Unable to allocate %d program headers\n",
27283 + ehdr.e_phnum);
27284 + }
27285 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27286 + die("Seek to %d failed: %s\n",
27287 + ehdr.e_phoff, strerror(errno));
27288 + }
27289 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27290 + die("Cannot read ELF program headers: %s\n",
27291 + strerror(errno));
27292 + }
27293 + for(i = 0; i < ehdr.e_phnum; i++) {
27294 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27295 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27296 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27297 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27298 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27299 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27300 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27301 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27302 + }
27303 +
27304 +}
27305 +
27306 static void read_shdrs(FILE *fp)
27307 {
27308 - int i;
27309 + unsigned int i;
27310 Elf32_Shdr shdr;
27311
27312 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27313 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27314
27315 static void read_strtabs(FILE *fp)
27316 {
27317 - int i;
27318 + unsigned int i;
27319 for (i = 0; i < ehdr.e_shnum; i++) {
27320 struct section *sec = &secs[i];
27321 if (sec->shdr.sh_type != SHT_STRTAB) {
27322 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27323
27324 static void read_symtabs(FILE *fp)
27325 {
27326 - int i,j;
27327 + unsigned int i,j;
27328 for (i = 0; i < ehdr.e_shnum; i++) {
27329 struct section *sec = &secs[i];
27330 if (sec->shdr.sh_type != SHT_SYMTAB) {
27331 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27332 }
27333
27334
27335 -static void read_relocs(FILE *fp)
27336 +static void read_relocs(FILE *fp, int use_real_mode)
27337 {
27338 - int i,j;
27339 + unsigned int i,j;
27340 + uint32_t base;
27341 +
27342 for (i = 0; i < ehdr.e_shnum; i++) {
27343 struct section *sec = &secs[i];
27344 if (sec->shdr.sh_type != SHT_REL) {
27345 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27346 die("Cannot read symbol table: %s\n",
27347 strerror(errno));
27348 }
27349 + base = 0;
27350 +
27351 +#ifdef CONFIG_X86_32
27352 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27353 + if (phdr[j].p_type != PT_LOAD )
27354 + continue;
27355 + 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)
27356 + continue;
27357 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27358 + break;
27359 + }
27360 +#endif
27361 +
27362 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27363 Elf32_Rel *rel = &sec->reltab[j];
27364 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27365 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27366 rel->r_info = elf32_to_cpu(rel->r_info);
27367 }
27368 }
27369 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27370
27371 static void print_absolute_symbols(void)
27372 {
27373 - int i;
27374 + unsigned int i;
27375 printf("Absolute symbols\n");
27376 printf(" Num: Value Size Type Bind Visibility Name\n");
27377 for (i = 0; i < ehdr.e_shnum; i++) {
27378 struct section *sec = &secs[i];
27379 char *sym_strtab;
27380 - int j;
27381 + unsigned int j;
27382
27383 if (sec->shdr.sh_type != SHT_SYMTAB) {
27384 continue;
27385 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27386
27387 static void print_absolute_relocs(void)
27388 {
27389 - int i, printed = 0;
27390 + unsigned int i, printed = 0;
27391
27392 for (i = 0; i < ehdr.e_shnum; i++) {
27393 struct section *sec = &secs[i];
27394 struct section *sec_applies, *sec_symtab;
27395 char *sym_strtab;
27396 Elf32_Sym *sh_symtab;
27397 - int j;
27398 + unsigned int j;
27399 if (sec->shdr.sh_type != SHT_REL) {
27400 continue;
27401 }
27402 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27403 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27404 int use_real_mode)
27405 {
27406 - int i;
27407 + unsigned int i;
27408 /* Walk through the relocations */
27409 for (i = 0; i < ehdr.e_shnum; i++) {
27410 char *sym_strtab;
27411 Elf32_Sym *sh_symtab;
27412 struct section *sec_applies, *sec_symtab;
27413 - int j;
27414 + unsigned int j;
27415 struct section *sec = &secs[i];
27416
27417 if (sec->shdr.sh_type != SHT_REL) {
27418 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27419 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27420 r_type = ELF32_R_TYPE(rel->r_info);
27421
27422 + if (!use_real_mode) {
27423 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27424 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27425 + continue;
27426 +
27427 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27428 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27429 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27430 + continue;
27431 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27432 + continue;
27433 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27434 + continue;
27435 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27436 + continue;
27437 +#endif
27438 + }
27439 +
27440 shn_abs = sym->st_shndx == SHN_ABS;
27441
27442 switch (r_type) {
27443 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27444
27445 static void emit_relocs(int as_text, int use_real_mode)
27446 {
27447 - int i;
27448 + unsigned int i;
27449 /* Count how many relocations I have and allocate space for them. */
27450 reloc_count = 0;
27451 walk_relocs(count_reloc, use_real_mode);
27452 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27453 fname, strerror(errno));
27454 }
27455 read_ehdr(fp);
27456 + read_phdrs(fp);
27457 read_shdrs(fp);
27458 read_strtabs(fp);
27459 read_symtabs(fp);
27460 - read_relocs(fp);
27461 + read_relocs(fp, use_real_mode);
27462 if (show_absolute_syms) {
27463 print_absolute_symbols();
27464 return 0;
27465 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27466 index fd14be1..e3c79c0 100644
27467 --- a/arch/x86/vdso/Makefile
27468 +++ b/arch/x86/vdso/Makefile
27469 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27470 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27471 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27472
27473 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27474 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27475 GCOV_PROFILE := n
27476
27477 #
27478 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27479 index 0faad64..39ef157 100644
27480 --- a/arch/x86/vdso/vdso32-setup.c
27481 +++ b/arch/x86/vdso/vdso32-setup.c
27482 @@ -25,6 +25,7 @@
27483 #include <asm/tlbflush.h>
27484 #include <asm/vdso.h>
27485 #include <asm/proto.h>
27486 +#include <asm/mman.h>
27487
27488 enum {
27489 VDSO_DISABLED = 0,
27490 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27491 void enable_sep_cpu(void)
27492 {
27493 int cpu = get_cpu();
27494 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27495 + struct tss_struct *tss = init_tss + cpu;
27496
27497 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27498 put_cpu();
27499 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27500 gate_vma.vm_start = FIXADDR_USER_START;
27501 gate_vma.vm_end = FIXADDR_USER_END;
27502 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27503 - gate_vma.vm_page_prot = __P101;
27504 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27505
27506 return 0;
27507 }
27508 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27509 if (compat)
27510 addr = VDSO_HIGH_BASE;
27511 else {
27512 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27513 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27514 if (IS_ERR_VALUE(addr)) {
27515 ret = addr;
27516 goto up_fail;
27517 }
27518 }
27519
27520 - current->mm->context.vdso = (void *)addr;
27521 + current->mm->context.vdso = addr;
27522
27523 if (compat_uses_vma || !compat) {
27524 /*
27525 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27526 }
27527
27528 current_thread_info()->sysenter_return =
27529 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27530 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27531
27532 up_fail:
27533 if (ret)
27534 - current->mm->context.vdso = NULL;
27535 + current->mm->context.vdso = 0;
27536
27537 up_write(&mm->mmap_sem);
27538
27539 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27540
27541 const char *arch_vma_name(struct vm_area_struct *vma)
27542 {
27543 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27544 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27545 return "[vdso]";
27546 +
27547 +#ifdef CONFIG_PAX_SEGMEXEC
27548 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27549 + return "[vdso]";
27550 +#endif
27551 +
27552 return NULL;
27553 }
27554
27555 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27556 * Check to see if the corresponding task was created in compat vdso
27557 * mode.
27558 */
27559 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27560 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27561 return &gate_vma;
27562 return NULL;
27563 }
27564 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27565 index 00aaf04..4a26505 100644
27566 --- a/arch/x86/vdso/vma.c
27567 +++ b/arch/x86/vdso/vma.c
27568 @@ -16,8 +16,6 @@
27569 #include <asm/vdso.h>
27570 #include <asm/page.h>
27571
27572 -unsigned int __read_mostly vdso_enabled = 1;
27573 -
27574 extern char vdso_start[], vdso_end[];
27575 extern unsigned short vdso_sync_cpuid;
27576
27577 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27578 * unaligned here as a result of stack start randomization.
27579 */
27580 addr = PAGE_ALIGN(addr);
27581 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27582
27583 return addr;
27584 }
27585 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27586 unsigned size)
27587 {
27588 struct mm_struct *mm = current->mm;
27589 - unsigned long addr;
27590 + unsigned long addr = 0;
27591 int ret;
27592
27593 - if (!vdso_enabled)
27594 - return 0;
27595 -
27596 down_write(&mm->mmap_sem);
27597 +
27598 +#ifdef CONFIG_PAX_RANDMMAP
27599 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27600 +#endif
27601 +
27602 addr = vdso_addr(mm->start_stack, size);
27603 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27604 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27605 if (IS_ERR_VALUE(addr)) {
27606 ret = addr;
27607 goto up_fail;
27608 }
27609
27610 - current->mm->context.vdso = (void *)addr;
27611 + mm->context.vdso = addr;
27612
27613 ret = install_special_mapping(mm, addr, size,
27614 VM_READ|VM_EXEC|
27615 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27616 pages);
27617 - if (ret) {
27618 - current->mm->context.vdso = NULL;
27619 - goto up_fail;
27620 - }
27621 + if (ret)
27622 + mm->context.vdso = 0;
27623
27624 up_fail:
27625 up_write(&mm->mmap_sem);
27626 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27627 vdsox32_size);
27628 }
27629 #endif
27630 -
27631 -static __init int vdso_setup(char *s)
27632 -{
27633 - vdso_enabled = simple_strtoul(s, NULL, 0);
27634 - return 0;
27635 -}
27636 -__setup("vdso=", vdso_setup);
27637 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27638 index 586d838..38cb3ff 100644
27639 --- a/arch/x86/xen/enlighten.c
27640 +++ b/arch/x86/xen/enlighten.c
27641 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27642
27643 struct shared_info xen_dummy_shared_info;
27644
27645 -void *xen_initial_gdt;
27646 -
27647 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27648 __read_mostly int xen_have_vector_callback;
27649 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27650 @@ -918,21 +916,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27651
27652 static void set_xen_basic_apic_ops(void)
27653 {
27654 - apic->read = xen_apic_read;
27655 - apic->write = xen_apic_write;
27656 - apic->icr_read = xen_apic_icr_read;
27657 - apic->icr_write = xen_apic_icr_write;
27658 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27659 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27660 - apic->set_apic_id = xen_set_apic_id;
27661 - apic->get_apic_id = xen_get_apic_id;
27662 + *(void **)&apic->read = xen_apic_read;
27663 + *(void **)&apic->write = xen_apic_write;
27664 + *(void **)&apic->icr_read = xen_apic_icr_read;
27665 + *(void **)&apic->icr_write = xen_apic_icr_write;
27666 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27667 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27668 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27669 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27670
27671 #ifdef CONFIG_SMP
27672 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27673 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27674 - apic->send_IPI_mask = xen_send_IPI_mask;
27675 - apic->send_IPI_all = xen_send_IPI_all;
27676 - apic->send_IPI_self = xen_send_IPI_self;
27677 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27678 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27679 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27680 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27681 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27682 #endif
27683 }
27684
27685 @@ -1222,30 +1220,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27686 #endif
27687 };
27688
27689 -static void xen_reboot(int reason)
27690 +static __noreturn void xen_reboot(int reason)
27691 {
27692 struct sched_shutdown r = { .reason = reason };
27693
27694 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27695 - BUG();
27696 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27697 + BUG();
27698 }
27699
27700 -static void xen_restart(char *msg)
27701 +static __noreturn void xen_restart(char *msg)
27702 {
27703 xen_reboot(SHUTDOWN_reboot);
27704 }
27705
27706 -static void xen_emergency_restart(void)
27707 +static __noreturn void xen_emergency_restart(void)
27708 {
27709 xen_reboot(SHUTDOWN_reboot);
27710 }
27711
27712 -static void xen_machine_halt(void)
27713 +static __noreturn void xen_machine_halt(void)
27714 {
27715 xen_reboot(SHUTDOWN_poweroff);
27716 }
27717
27718 -static void xen_machine_power_off(void)
27719 +static __noreturn void xen_machine_power_off(void)
27720 {
27721 if (pm_power_off)
27722 pm_power_off();
27723 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27724 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27725
27726 /* Work out if we support NX */
27727 - x86_configure_nx();
27728 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27729 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27730 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27731 + unsigned l, h;
27732 +
27733 + __supported_pte_mask |= _PAGE_NX;
27734 + rdmsr(MSR_EFER, l, h);
27735 + l |= EFER_NX;
27736 + wrmsr(MSR_EFER, l, h);
27737 + }
27738 +#endif
27739
27740 xen_setup_features();
27741
27742 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27743
27744 machine_ops = xen_machine_ops;
27745
27746 - /*
27747 - * The only reliable way to retain the initial address of the
27748 - * percpu gdt_page is to remember it here, so we can go and
27749 - * mark it RW later, when the initial percpu area is freed.
27750 - */
27751 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27752 -
27753 xen_smp_init();
27754
27755 #ifdef CONFIG_ACPI_NUMA
27756 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27757 index dcf5f2d..d804c25 100644
27758 --- a/arch/x86/xen/mmu.c
27759 +++ b/arch/x86/xen/mmu.c
27760 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
27761 /* L3_k[510] -> level2_kernel_pgt
27762 * L3_i[511] -> level2_fixmap_pgt */
27763 convert_pfn_mfn(level3_kernel_pgt);
27764 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27765 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27766 + convert_pfn_mfn(level3_vmemmap_pgt);
27767
27768 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
27769 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27770 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
27771 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27772 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27773 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27774 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27775 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27776 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27777 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27778 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
27779 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27780 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27781 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27782
27783 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
27784 pv_mmu_ops.set_pud = xen_set_pud;
27785 #if PAGETABLE_LEVELS == 4
27786 pv_mmu_ops.set_pgd = xen_set_pgd;
27787 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27788 #endif
27789
27790 /* This will work as long as patching hasn't happened yet
27791 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27792 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27793 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27794 .set_pgd = xen_set_pgd_hyper,
27795 + .set_pgd_batched = xen_set_pgd_hyper,
27796
27797 .alloc_pud = xen_alloc_pmd_init,
27798 .release_pud = xen_release_pmd_init,
27799 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27800 index 353c50f..5b7cb95 100644
27801 --- a/arch/x86/xen/smp.c
27802 +++ b/arch/x86/xen/smp.c
27803 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27804 {
27805 BUG_ON(smp_processor_id() != 0);
27806 native_smp_prepare_boot_cpu();
27807 -
27808 - /* We've switched to the "real" per-cpu gdt, so make sure the
27809 - old memory can be recycled */
27810 - make_lowmem_page_readwrite(xen_initial_gdt);
27811 -
27812 xen_filter_cpu_maps();
27813 xen_setup_vcpu_info_placement();
27814 }
27815 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27816 gdt = get_cpu_gdt_table(cpu);
27817
27818 ctxt->flags = VGCF_IN_KERNEL;
27819 - ctxt->user_regs.ds = __USER_DS;
27820 - ctxt->user_regs.es = __USER_DS;
27821 + ctxt->user_regs.ds = __KERNEL_DS;
27822 + ctxt->user_regs.es = __KERNEL_DS;
27823 ctxt->user_regs.ss = __KERNEL_DS;
27824 #ifdef CONFIG_X86_32
27825 ctxt->user_regs.fs = __KERNEL_PERCPU;
27826 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27827 + savesegment(gs, ctxt->user_regs.gs);
27828 #else
27829 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27830 #endif
27831 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27832 int rc;
27833
27834 per_cpu(current_task, cpu) = idle;
27835 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27836 #ifdef CONFIG_X86_32
27837 irq_ctx_init(cpu);
27838 #else
27839 clear_tsk_thread_flag(idle, TIF_FORK);
27840 - per_cpu(kernel_stack, cpu) =
27841 - (unsigned long)task_stack_page(idle) -
27842 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27843 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27844 #endif
27845 xen_setup_runstate_info(cpu);
27846 xen_setup_timer(cpu);
27847 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27848 index f9643fc..602e8af 100644
27849 --- a/arch/x86/xen/xen-asm_32.S
27850 +++ b/arch/x86/xen/xen-asm_32.S
27851 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27852 ESP_OFFSET=4 # bytes pushed onto stack
27853
27854 /*
27855 - * Store vcpu_info pointer for easy access. Do it this way to
27856 - * avoid having to reload %fs
27857 + * Store vcpu_info pointer for easy access.
27858 */
27859 #ifdef CONFIG_SMP
27860 - GET_THREAD_INFO(%eax)
27861 - movl TI_cpu(%eax), %eax
27862 - movl __per_cpu_offset(,%eax,4), %eax
27863 - mov xen_vcpu(%eax), %eax
27864 + push %fs
27865 + mov $(__KERNEL_PERCPU), %eax
27866 + mov %eax, %fs
27867 + mov PER_CPU_VAR(xen_vcpu), %eax
27868 + pop %fs
27869 #else
27870 movl xen_vcpu, %eax
27871 #endif
27872 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27873 index 7faed58..ba4427c 100644
27874 --- a/arch/x86/xen/xen-head.S
27875 +++ b/arch/x86/xen/xen-head.S
27876 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27877 #ifdef CONFIG_X86_32
27878 mov %esi,xen_start_info
27879 mov $init_thread_union+THREAD_SIZE,%esp
27880 +#ifdef CONFIG_SMP
27881 + movl $cpu_gdt_table,%edi
27882 + movl $__per_cpu_load,%eax
27883 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27884 + rorl $16,%eax
27885 + movb %al,__KERNEL_PERCPU + 4(%edi)
27886 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27887 + movl $__per_cpu_end - 1,%eax
27888 + subl $__per_cpu_start,%eax
27889 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27890 +#endif
27891 #else
27892 mov %rsi,xen_start_info
27893 mov $init_thread_union+THREAD_SIZE,%rsp
27894 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27895 index a95b417..b6dbd0b 100644
27896 --- a/arch/x86/xen/xen-ops.h
27897 +++ b/arch/x86/xen/xen-ops.h
27898 @@ -10,8 +10,6 @@
27899 extern const char xen_hypervisor_callback[];
27900 extern const char xen_failsafe_callback[];
27901
27902 -extern void *xen_initial_gdt;
27903 -
27904 struct trap_info;
27905 void xen_copy_trap_info(struct trap_info *traps);
27906
27907 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27908 index 525bd3d..ef888b1 100644
27909 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27910 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27911 @@ -119,9 +119,9 @@
27912 ----------------------------------------------------------------------*/
27913
27914 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27915 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27916 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27917 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27918 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27919
27920 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27921 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27922 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27923 index 2f33760..835e50a 100644
27924 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27925 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27926 @@ -11,6 +11,7 @@
27927 #ifndef _XTENSA_CORE_H
27928 #define _XTENSA_CORE_H
27929
27930 +#include <linux/const.h>
27931
27932 /****************************************************************************
27933 Parameters Useful for Any Code, USER or PRIVILEGED
27934 @@ -112,9 +113,9 @@
27935 ----------------------------------------------------------------------*/
27936
27937 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27938 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27939 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27940 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27941 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27942
27943 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27944 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27945 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27946 index af00795..2bb8105 100644
27947 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27948 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27949 @@ -11,6 +11,7 @@
27950 #ifndef _XTENSA_CORE_CONFIGURATION_H
27951 #define _XTENSA_CORE_CONFIGURATION_H
27952
27953 +#include <linux/const.h>
27954
27955 /****************************************************************************
27956 Parameters Useful for Any Code, USER or PRIVILEGED
27957 @@ -118,9 +119,9 @@
27958 ----------------------------------------------------------------------*/
27959
27960 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27961 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27962 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27963 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27964 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27965
27966 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27967 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27968 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27969 index 58916af..9cb880b 100644
27970 --- a/block/blk-iopoll.c
27971 +++ b/block/blk-iopoll.c
27972 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27973 }
27974 EXPORT_SYMBOL(blk_iopoll_complete);
27975
27976 -static void blk_iopoll_softirq(struct softirq_action *h)
27977 +static void blk_iopoll_softirq(void)
27978 {
27979 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27980 int rearm = 0, budget = blk_iopoll_budget;
27981 diff --git a/block/blk-map.c b/block/blk-map.c
27982 index 623e1cd..ca1e109 100644
27983 --- a/block/blk-map.c
27984 +++ b/block/blk-map.c
27985 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27986 if (!len || !kbuf)
27987 return -EINVAL;
27988
27989 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27990 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27991 if (do_copy)
27992 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27993 else
27994 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27995 index 467c8de..4bddc6d 100644
27996 --- a/block/blk-softirq.c
27997 +++ b/block/blk-softirq.c
27998 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27999 * Softirq action handler - move entries to local list and loop over them
28000 * while passing them to the queue registered handler.
28001 */
28002 -static void blk_done_softirq(struct softirq_action *h)
28003 +static void blk_done_softirq(void)
28004 {
28005 struct list_head *cpu_list, local_list;
28006
28007 diff --git a/block/bsg.c b/block/bsg.c
28008 index ff64ae3..593560c 100644
28009 --- a/block/bsg.c
28010 +++ b/block/bsg.c
28011 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
28012 struct sg_io_v4 *hdr, struct bsg_device *bd,
28013 fmode_t has_write_perm)
28014 {
28015 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28016 + unsigned char *cmdptr;
28017 +
28018 if (hdr->request_len > BLK_MAX_CDB) {
28019 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
28020 if (!rq->cmd)
28021 return -ENOMEM;
28022 - }
28023 + cmdptr = rq->cmd;
28024 + } else
28025 + cmdptr = tmpcmd;
28026
28027 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
28028 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
28029 hdr->request_len))
28030 return -EFAULT;
28031
28032 + if (cmdptr != rq->cmd)
28033 + memcpy(rq->cmd, cmdptr, hdr->request_len);
28034 +
28035 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
28036 if (blk_verify_command(rq->cmd, has_write_perm))
28037 return -EPERM;
28038 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
28039 index 7c668c8..db3521c 100644
28040 --- a/block/compat_ioctl.c
28041 +++ b/block/compat_ioctl.c
28042 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
28043 err |= __get_user(f->spec1, &uf->spec1);
28044 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
28045 err |= __get_user(name, &uf->name);
28046 - f->name = compat_ptr(name);
28047 + f->name = (void __force_kernel *)compat_ptr(name);
28048 if (err) {
28049 err = -EFAULT;
28050 goto out;
28051 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
28052 index 6296b40..417c00f 100644
28053 --- a/block/partitions/efi.c
28054 +++ b/block/partitions/efi.c
28055 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
28056 if (!gpt)
28057 return NULL;
28058
28059 + if (!le32_to_cpu(gpt->num_partition_entries))
28060 + return NULL;
28061 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
28062 + if (!pte)
28063 + return NULL;
28064 +
28065 count = le32_to_cpu(gpt->num_partition_entries) *
28066 le32_to_cpu(gpt->sizeof_partition_entry);
28067 - if (!count)
28068 - return NULL;
28069 - pte = kzalloc(count, GFP_KERNEL);
28070 - if (!pte)
28071 - return NULL;
28072 -
28073 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
28074 (u8 *) pte,
28075 count) < count) {
28076 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
28077 index 9a87daa..fb17486 100644
28078 --- a/block/scsi_ioctl.c
28079 +++ b/block/scsi_ioctl.c
28080 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
28081 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
28082 struct sg_io_hdr *hdr, fmode_t mode)
28083 {
28084 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
28085 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28086 + unsigned char *cmdptr;
28087 +
28088 + if (rq->cmd != rq->__cmd)
28089 + cmdptr = rq->cmd;
28090 + else
28091 + cmdptr = tmpcmd;
28092 +
28093 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
28094 return -EFAULT;
28095 +
28096 + if (cmdptr != rq->cmd)
28097 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
28098 +
28099 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
28100 return -EPERM;
28101
28102 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28103 int err;
28104 unsigned int in_len, out_len, bytes, opcode, cmdlen;
28105 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
28106 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28107 + unsigned char *cmdptr;
28108
28109 if (!sic)
28110 return -EINVAL;
28111 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28112 */
28113 err = -EFAULT;
28114 rq->cmd_len = cmdlen;
28115 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
28116 +
28117 + if (rq->cmd != rq->__cmd)
28118 + cmdptr = rq->cmd;
28119 + else
28120 + cmdptr = tmpcmd;
28121 +
28122 + if (copy_from_user(cmdptr, sic->data, cmdlen))
28123 goto error;
28124
28125 + if (rq->cmd != cmdptr)
28126 + memcpy(rq->cmd, cmdptr, cmdlen);
28127 +
28128 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28129 goto error;
28130
28131 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28132 index 7bdd61b..afec999 100644
28133 --- a/crypto/cryptd.c
28134 +++ b/crypto/cryptd.c
28135 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28136
28137 struct cryptd_blkcipher_request_ctx {
28138 crypto_completion_t complete;
28139 -};
28140 +} __no_const;
28141
28142 struct cryptd_hash_ctx {
28143 struct crypto_shash *child;
28144 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28145
28146 struct cryptd_aead_request_ctx {
28147 crypto_completion_t complete;
28148 -};
28149 +} __no_const;
28150
28151 static void cryptd_queue_worker(struct work_struct *work);
28152
28153 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28154 index e6defd8..c26a225 100644
28155 --- a/drivers/acpi/apei/cper.c
28156 +++ b/drivers/acpi/apei/cper.c
28157 @@ -38,12 +38,12 @@
28158 */
28159 u64 cper_next_record_id(void)
28160 {
28161 - static atomic64_t seq;
28162 + static atomic64_unchecked_t seq;
28163
28164 - if (!atomic64_read(&seq))
28165 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
28166 + if (!atomic64_read_unchecked(&seq))
28167 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28168
28169 - return atomic64_inc_return(&seq);
28170 + return atomic64_inc_return_unchecked(&seq);
28171 }
28172 EXPORT_SYMBOL_GPL(cper_next_record_id);
28173
28174 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28175 index 7586544..636a2f0 100644
28176 --- a/drivers/acpi/ec_sys.c
28177 +++ b/drivers/acpi/ec_sys.c
28178 @@ -12,6 +12,7 @@
28179 #include <linux/acpi.h>
28180 #include <linux/debugfs.h>
28181 #include <linux/module.h>
28182 +#include <linux/uaccess.h>
28183 #include "internal.h"
28184
28185 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28186 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28187 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28188 */
28189 unsigned int size = EC_SPACE_SIZE;
28190 - u8 *data = (u8 *) buf;
28191 + u8 data;
28192 loff_t init_off = *off;
28193 int err = 0;
28194
28195 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28196 size = count;
28197
28198 while (size) {
28199 - err = ec_read(*off, &data[*off - init_off]);
28200 + err = ec_read(*off, &data);
28201 if (err)
28202 return err;
28203 + if (put_user(data, &buf[*off - init_off]))
28204 + return -EFAULT;
28205 *off += 1;
28206 size--;
28207 }
28208 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28209
28210 unsigned int size = count;
28211 loff_t init_off = *off;
28212 - u8 *data = (u8 *) buf;
28213 int err = 0;
28214
28215 if (*off >= EC_SPACE_SIZE)
28216 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28217 }
28218
28219 while (size) {
28220 - u8 byte_write = data[*off - init_off];
28221 + u8 byte_write;
28222 + if (get_user(byte_write, &buf[*off - init_off]))
28223 + return -EFAULT;
28224 err = ec_write(*off, byte_write);
28225 if (err)
28226 return err;
28227 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28228 index 27adb09..1ed412d 100644
28229 --- a/drivers/acpi/proc.c
28230 +++ b/drivers/acpi/proc.c
28231 @@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
28232 size_t count, loff_t * ppos)
28233 {
28234 struct list_head *node, *next;
28235 - char strbuf[5];
28236 - char str[5] = "";
28237 - unsigned int len = count;
28238 + char strbuf[5] = {0};
28239
28240 - if (len > 4)
28241 - len = 4;
28242 - if (len < 0)
28243 + if (count > 4)
28244 + count = 4;
28245 + if (copy_from_user(strbuf, buffer, count))
28246 return -EFAULT;
28247 -
28248 - if (copy_from_user(strbuf, buffer, len))
28249 - return -EFAULT;
28250 - strbuf[len] = '\0';
28251 - sscanf(strbuf, "%s", str);
28252 + strbuf[count] = '\0';
28253
28254 mutex_lock(&acpi_device_lock);
28255 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28256 @@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
28257 if (!dev->wakeup.flags.valid)
28258 continue;
28259
28260 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28261 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28262 if (device_can_wakeup(&dev->dev)) {
28263 bool enable = !device_may_wakeup(&dev->dev);
28264 device_set_wakeup_enable(&dev->dev, enable);
28265 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28266 index bd4e5dc..0497b66 100644
28267 --- a/drivers/acpi/processor_driver.c
28268 +++ b/drivers/acpi/processor_driver.c
28269 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28270 return 0;
28271 #endif
28272
28273 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28274 + BUG_ON(pr->id >= nr_cpu_ids);
28275
28276 /*
28277 * Buggy BIOS check
28278 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28279 index f46fbd3..b8341f3 100644
28280 --- a/drivers/ata/libata-core.c
28281 +++ b/drivers/ata/libata-core.c
28282 @@ -4774,7 +4774,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28283 struct ata_port *ap;
28284 unsigned int tag;
28285
28286 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28287 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28288 ap = qc->ap;
28289
28290 qc->flags = 0;
28291 @@ -4790,7 +4790,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28292 struct ata_port *ap;
28293 struct ata_link *link;
28294
28295 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28296 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28297 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28298 ap = qc->ap;
28299 link = qc->dev->link;
28300 @@ -5886,6 +5886,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28301 return;
28302
28303 spin_lock(&lock);
28304 + pax_open_kernel();
28305
28306 for (cur = ops->inherits; cur; cur = cur->inherits) {
28307 void **inherit = (void **)cur;
28308 @@ -5899,8 +5900,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28309 if (IS_ERR(*pp))
28310 *pp = NULL;
28311
28312 - ops->inherits = NULL;
28313 + *(struct ata_port_operations **)&ops->inherits = NULL;
28314
28315 + pax_close_kernel();
28316 spin_unlock(&lock);
28317 }
28318
28319 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28320 index 371fd2c..0836c78 100644
28321 --- a/drivers/ata/pata_arasan_cf.c
28322 +++ b/drivers/ata/pata_arasan_cf.c
28323 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28324 /* Handle platform specific quirks */
28325 if (pdata->quirk) {
28326 if (pdata->quirk & CF_BROKEN_PIO) {
28327 - ap->ops->set_piomode = NULL;
28328 + pax_open_kernel();
28329 + *(void **)&ap->ops->set_piomode = NULL;
28330 + pax_close_kernel();
28331 ap->pio_mask = 0;
28332 }
28333 if (pdata->quirk & CF_BROKEN_MWDMA)
28334 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28335 index f9b983a..887b9d8 100644
28336 --- a/drivers/atm/adummy.c
28337 +++ b/drivers/atm/adummy.c
28338 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28339 vcc->pop(vcc, skb);
28340 else
28341 dev_kfree_skb_any(skb);
28342 - atomic_inc(&vcc->stats->tx);
28343 + atomic_inc_unchecked(&vcc->stats->tx);
28344
28345 return 0;
28346 }
28347 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28348 index ff7bb8a..568fc0b 100644
28349 --- a/drivers/atm/ambassador.c
28350 +++ b/drivers/atm/ambassador.c
28351 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28352 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28353
28354 // VC layer stats
28355 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28356 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28357
28358 // free the descriptor
28359 kfree (tx_descr);
28360 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28361 dump_skb ("<<<", vc, skb);
28362
28363 // VC layer stats
28364 - atomic_inc(&atm_vcc->stats->rx);
28365 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28366 __net_timestamp(skb);
28367 // end of our responsibility
28368 atm_vcc->push (atm_vcc, skb);
28369 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28370 } else {
28371 PRINTK (KERN_INFO, "dropped over-size frame");
28372 // should we count this?
28373 - atomic_inc(&atm_vcc->stats->rx_drop);
28374 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28375 }
28376
28377 } else {
28378 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28379 }
28380
28381 if (check_area (skb->data, skb->len)) {
28382 - atomic_inc(&atm_vcc->stats->tx_err);
28383 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28384 return -ENOMEM; // ?
28385 }
28386
28387 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28388 index b22d71c..d6e1049 100644
28389 --- a/drivers/atm/atmtcp.c
28390 +++ b/drivers/atm/atmtcp.c
28391 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28392 if (vcc->pop) vcc->pop(vcc,skb);
28393 else dev_kfree_skb(skb);
28394 if (dev_data) return 0;
28395 - atomic_inc(&vcc->stats->tx_err);
28396 + atomic_inc_unchecked(&vcc->stats->tx_err);
28397 return -ENOLINK;
28398 }
28399 size = skb->len+sizeof(struct atmtcp_hdr);
28400 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28401 if (!new_skb) {
28402 if (vcc->pop) vcc->pop(vcc,skb);
28403 else dev_kfree_skb(skb);
28404 - atomic_inc(&vcc->stats->tx_err);
28405 + atomic_inc_unchecked(&vcc->stats->tx_err);
28406 return -ENOBUFS;
28407 }
28408 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28409 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28410 if (vcc->pop) vcc->pop(vcc,skb);
28411 else dev_kfree_skb(skb);
28412 out_vcc->push(out_vcc,new_skb);
28413 - atomic_inc(&vcc->stats->tx);
28414 - atomic_inc(&out_vcc->stats->rx);
28415 + atomic_inc_unchecked(&vcc->stats->tx);
28416 + atomic_inc_unchecked(&out_vcc->stats->rx);
28417 return 0;
28418 }
28419
28420 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28421 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28422 read_unlock(&vcc_sklist_lock);
28423 if (!out_vcc) {
28424 - atomic_inc(&vcc->stats->tx_err);
28425 + atomic_inc_unchecked(&vcc->stats->tx_err);
28426 goto done;
28427 }
28428 skb_pull(skb,sizeof(struct atmtcp_hdr));
28429 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28430 __net_timestamp(new_skb);
28431 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28432 out_vcc->push(out_vcc,new_skb);
28433 - atomic_inc(&vcc->stats->tx);
28434 - atomic_inc(&out_vcc->stats->rx);
28435 + atomic_inc_unchecked(&vcc->stats->tx);
28436 + atomic_inc_unchecked(&out_vcc->stats->rx);
28437 done:
28438 if (vcc->pop) vcc->pop(vcc,skb);
28439 else dev_kfree_skb(skb);
28440 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28441 index 81e44f7..498ea36 100644
28442 --- a/drivers/atm/eni.c
28443 +++ b/drivers/atm/eni.c
28444 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28445 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28446 vcc->dev->number);
28447 length = 0;
28448 - atomic_inc(&vcc->stats->rx_err);
28449 + atomic_inc_unchecked(&vcc->stats->rx_err);
28450 }
28451 else {
28452 length = ATM_CELL_SIZE-1; /* no HEC */
28453 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28454 size);
28455 }
28456 eff = length = 0;
28457 - atomic_inc(&vcc->stats->rx_err);
28458 + atomic_inc_unchecked(&vcc->stats->rx_err);
28459 }
28460 else {
28461 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28462 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28463 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28464 vcc->dev->number,vcc->vci,length,size << 2,descr);
28465 length = eff = 0;
28466 - atomic_inc(&vcc->stats->rx_err);
28467 + atomic_inc_unchecked(&vcc->stats->rx_err);
28468 }
28469 }
28470 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28471 @@ -767,7 +767,7 @@ rx_dequeued++;
28472 vcc->push(vcc,skb);
28473 pushed++;
28474 }
28475 - atomic_inc(&vcc->stats->rx);
28476 + atomic_inc_unchecked(&vcc->stats->rx);
28477 }
28478 wake_up(&eni_dev->rx_wait);
28479 }
28480 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28481 PCI_DMA_TODEVICE);
28482 if (vcc->pop) vcc->pop(vcc,skb);
28483 else dev_kfree_skb_irq(skb);
28484 - atomic_inc(&vcc->stats->tx);
28485 + atomic_inc_unchecked(&vcc->stats->tx);
28486 wake_up(&eni_dev->tx_wait);
28487 dma_complete++;
28488 }
28489 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28490 index 86fed1b..6dc4721 100644
28491 --- a/drivers/atm/firestream.c
28492 +++ b/drivers/atm/firestream.c
28493 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28494 }
28495 }
28496
28497 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28498 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28499
28500 fs_dprintk (FS_DEBUG_TXMEM, "i");
28501 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28502 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28503 #endif
28504 skb_put (skb, qe->p1 & 0xffff);
28505 ATM_SKB(skb)->vcc = atm_vcc;
28506 - atomic_inc(&atm_vcc->stats->rx);
28507 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28508 __net_timestamp(skb);
28509 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28510 atm_vcc->push (atm_vcc, skb);
28511 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28512 kfree (pe);
28513 }
28514 if (atm_vcc)
28515 - atomic_inc(&atm_vcc->stats->rx_drop);
28516 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28517 break;
28518 case 0x1f: /* Reassembly abort: no buffers. */
28519 /* Silently increment error counter. */
28520 if (atm_vcc)
28521 - atomic_inc(&atm_vcc->stats->rx_drop);
28522 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28523 break;
28524 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28525 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28526 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28527 index 361f5ae..7fc552d 100644
28528 --- a/drivers/atm/fore200e.c
28529 +++ b/drivers/atm/fore200e.c
28530 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28531 #endif
28532 /* check error condition */
28533 if (*entry->status & STATUS_ERROR)
28534 - atomic_inc(&vcc->stats->tx_err);
28535 + atomic_inc_unchecked(&vcc->stats->tx_err);
28536 else
28537 - atomic_inc(&vcc->stats->tx);
28538 + atomic_inc_unchecked(&vcc->stats->tx);
28539 }
28540 }
28541
28542 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28543 if (skb == NULL) {
28544 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28545
28546 - atomic_inc(&vcc->stats->rx_drop);
28547 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28548 return -ENOMEM;
28549 }
28550
28551 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28552
28553 dev_kfree_skb_any(skb);
28554
28555 - atomic_inc(&vcc->stats->rx_drop);
28556 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28557 return -ENOMEM;
28558 }
28559
28560 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28561
28562 vcc->push(vcc, skb);
28563 - atomic_inc(&vcc->stats->rx);
28564 + atomic_inc_unchecked(&vcc->stats->rx);
28565
28566 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28567
28568 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28569 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28570 fore200e->atm_dev->number,
28571 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28572 - atomic_inc(&vcc->stats->rx_err);
28573 + atomic_inc_unchecked(&vcc->stats->rx_err);
28574 }
28575 }
28576
28577 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28578 goto retry_here;
28579 }
28580
28581 - atomic_inc(&vcc->stats->tx_err);
28582 + atomic_inc_unchecked(&vcc->stats->tx_err);
28583
28584 fore200e->tx_sat++;
28585 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28586 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28587 index b182c2f..1c6fa8a 100644
28588 --- a/drivers/atm/he.c
28589 +++ b/drivers/atm/he.c
28590 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28591
28592 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28593 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28594 - atomic_inc(&vcc->stats->rx_drop);
28595 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28596 goto return_host_buffers;
28597 }
28598
28599 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28600 RBRQ_LEN_ERR(he_dev->rbrq_head)
28601 ? "LEN_ERR" : "",
28602 vcc->vpi, vcc->vci);
28603 - atomic_inc(&vcc->stats->rx_err);
28604 + atomic_inc_unchecked(&vcc->stats->rx_err);
28605 goto return_host_buffers;
28606 }
28607
28608 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28609 vcc->push(vcc, skb);
28610 spin_lock(&he_dev->global_lock);
28611
28612 - atomic_inc(&vcc->stats->rx);
28613 + atomic_inc_unchecked(&vcc->stats->rx);
28614
28615 return_host_buffers:
28616 ++pdus_assembled;
28617 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28618 tpd->vcc->pop(tpd->vcc, tpd->skb);
28619 else
28620 dev_kfree_skb_any(tpd->skb);
28621 - atomic_inc(&tpd->vcc->stats->tx_err);
28622 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28623 }
28624 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28625 return;
28626 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28627 vcc->pop(vcc, skb);
28628 else
28629 dev_kfree_skb_any(skb);
28630 - atomic_inc(&vcc->stats->tx_err);
28631 + atomic_inc_unchecked(&vcc->stats->tx_err);
28632 return -EINVAL;
28633 }
28634
28635 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28636 vcc->pop(vcc, skb);
28637 else
28638 dev_kfree_skb_any(skb);
28639 - atomic_inc(&vcc->stats->tx_err);
28640 + atomic_inc_unchecked(&vcc->stats->tx_err);
28641 return -EINVAL;
28642 }
28643 #endif
28644 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28645 vcc->pop(vcc, skb);
28646 else
28647 dev_kfree_skb_any(skb);
28648 - atomic_inc(&vcc->stats->tx_err);
28649 + atomic_inc_unchecked(&vcc->stats->tx_err);
28650 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28651 return -ENOMEM;
28652 }
28653 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28654 vcc->pop(vcc, skb);
28655 else
28656 dev_kfree_skb_any(skb);
28657 - atomic_inc(&vcc->stats->tx_err);
28658 + atomic_inc_unchecked(&vcc->stats->tx_err);
28659 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28660 return -ENOMEM;
28661 }
28662 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28663 __enqueue_tpd(he_dev, tpd, cid);
28664 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28665
28666 - atomic_inc(&vcc->stats->tx);
28667 + atomic_inc_unchecked(&vcc->stats->tx);
28668
28669 return 0;
28670 }
28671 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28672 index 7d01c2a..4e3ac01 100644
28673 --- a/drivers/atm/horizon.c
28674 +++ b/drivers/atm/horizon.c
28675 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28676 {
28677 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28678 // VC layer stats
28679 - atomic_inc(&vcc->stats->rx);
28680 + atomic_inc_unchecked(&vcc->stats->rx);
28681 __net_timestamp(skb);
28682 // end of our responsibility
28683 vcc->push (vcc, skb);
28684 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28685 dev->tx_iovec = NULL;
28686
28687 // VC layer stats
28688 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28689 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28690
28691 // free the skb
28692 hrz_kfree_skb (skb);
28693 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28694 index 8974bd2..b856f85 100644
28695 --- a/drivers/atm/idt77252.c
28696 +++ b/drivers/atm/idt77252.c
28697 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28698 else
28699 dev_kfree_skb(skb);
28700
28701 - atomic_inc(&vcc->stats->tx);
28702 + atomic_inc_unchecked(&vcc->stats->tx);
28703 }
28704
28705 atomic_dec(&scq->used);
28706 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28707 if ((sb = dev_alloc_skb(64)) == NULL) {
28708 printk("%s: Can't allocate buffers for aal0.\n",
28709 card->name);
28710 - atomic_add(i, &vcc->stats->rx_drop);
28711 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28712 break;
28713 }
28714 if (!atm_charge(vcc, sb->truesize)) {
28715 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28716 card->name);
28717 - atomic_add(i - 1, &vcc->stats->rx_drop);
28718 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28719 dev_kfree_skb(sb);
28720 break;
28721 }
28722 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28723 ATM_SKB(sb)->vcc = vcc;
28724 __net_timestamp(sb);
28725 vcc->push(vcc, sb);
28726 - atomic_inc(&vcc->stats->rx);
28727 + atomic_inc_unchecked(&vcc->stats->rx);
28728
28729 cell += ATM_CELL_PAYLOAD;
28730 }
28731 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28732 "(CDC: %08x)\n",
28733 card->name, len, rpp->len, readl(SAR_REG_CDC));
28734 recycle_rx_pool_skb(card, rpp);
28735 - atomic_inc(&vcc->stats->rx_err);
28736 + atomic_inc_unchecked(&vcc->stats->rx_err);
28737 return;
28738 }
28739 if (stat & SAR_RSQE_CRC) {
28740 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28741 recycle_rx_pool_skb(card, rpp);
28742 - atomic_inc(&vcc->stats->rx_err);
28743 + atomic_inc_unchecked(&vcc->stats->rx_err);
28744 return;
28745 }
28746 if (skb_queue_len(&rpp->queue) > 1) {
28747 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28748 RXPRINTK("%s: Can't alloc RX skb.\n",
28749 card->name);
28750 recycle_rx_pool_skb(card, rpp);
28751 - atomic_inc(&vcc->stats->rx_err);
28752 + atomic_inc_unchecked(&vcc->stats->rx_err);
28753 return;
28754 }
28755 if (!atm_charge(vcc, skb->truesize)) {
28756 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28757 __net_timestamp(skb);
28758
28759 vcc->push(vcc, skb);
28760 - atomic_inc(&vcc->stats->rx);
28761 + atomic_inc_unchecked(&vcc->stats->rx);
28762
28763 return;
28764 }
28765 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28766 __net_timestamp(skb);
28767
28768 vcc->push(vcc, skb);
28769 - atomic_inc(&vcc->stats->rx);
28770 + atomic_inc_unchecked(&vcc->stats->rx);
28771
28772 if (skb->truesize > SAR_FB_SIZE_3)
28773 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28774 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28775 if (vcc->qos.aal != ATM_AAL0) {
28776 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28777 card->name, vpi, vci);
28778 - atomic_inc(&vcc->stats->rx_drop);
28779 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28780 goto drop;
28781 }
28782
28783 if ((sb = dev_alloc_skb(64)) == NULL) {
28784 printk("%s: Can't allocate buffers for AAL0.\n",
28785 card->name);
28786 - atomic_inc(&vcc->stats->rx_err);
28787 + atomic_inc_unchecked(&vcc->stats->rx_err);
28788 goto drop;
28789 }
28790
28791 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28792 ATM_SKB(sb)->vcc = vcc;
28793 __net_timestamp(sb);
28794 vcc->push(vcc, sb);
28795 - atomic_inc(&vcc->stats->rx);
28796 + atomic_inc_unchecked(&vcc->stats->rx);
28797
28798 drop:
28799 skb_pull(queue, 64);
28800 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28801
28802 if (vc == NULL) {
28803 printk("%s: NULL connection in send().\n", card->name);
28804 - atomic_inc(&vcc->stats->tx_err);
28805 + atomic_inc_unchecked(&vcc->stats->tx_err);
28806 dev_kfree_skb(skb);
28807 return -EINVAL;
28808 }
28809 if (!test_bit(VCF_TX, &vc->flags)) {
28810 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28811 - atomic_inc(&vcc->stats->tx_err);
28812 + atomic_inc_unchecked(&vcc->stats->tx_err);
28813 dev_kfree_skb(skb);
28814 return -EINVAL;
28815 }
28816 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28817 break;
28818 default:
28819 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28820 - atomic_inc(&vcc->stats->tx_err);
28821 + atomic_inc_unchecked(&vcc->stats->tx_err);
28822 dev_kfree_skb(skb);
28823 return -EINVAL;
28824 }
28825
28826 if (skb_shinfo(skb)->nr_frags != 0) {
28827 printk("%s: No scatter-gather yet.\n", card->name);
28828 - atomic_inc(&vcc->stats->tx_err);
28829 + atomic_inc_unchecked(&vcc->stats->tx_err);
28830 dev_kfree_skb(skb);
28831 return -EINVAL;
28832 }
28833 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28834
28835 err = queue_skb(card, vc, skb, oam);
28836 if (err) {
28837 - atomic_inc(&vcc->stats->tx_err);
28838 + atomic_inc_unchecked(&vcc->stats->tx_err);
28839 dev_kfree_skb(skb);
28840 return err;
28841 }
28842 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28843 skb = dev_alloc_skb(64);
28844 if (!skb) {
28845 printk("%s: Out of memory in send_oam().\n", card->name);
28846 - atomic_inc(&vcc->stats->tx_err);
28847 + atomic_inc_unchecked(&vcc->stats->tx_err);
28848 return -ENOMEM;
28849 }
28850 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28851 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28852 index 96cce6d..62c3ec5 100644
28853 --- a/drivers/atm/iphase.c
28854 +++ b/drivers/atm/iphase.c
28855 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28856 status = (u_short) (buf_desc_ptr->desc_mode);
28857 if (status & (RX_CER | RX_PTE | RX_OFL))
28858 {
28859 - atomic_inc(&vcc->stats->rx_err);
28860 + atomic_inc_unchecked(&vcc->stats->rx_err);
28861 IF_ERR(printk("IA: bad packet, dropping it");)
28862 if (status & RX_CER) {
28863 IF_ERR(printk(" cause: packet CRC error\n");)
28864 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28865 len = dma_addr - buf_addr;
28866 if (len > iadev->rx_buf_sz) {
28867 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28868 - atomic_inc(&vcc->stats->rx_err);
28869 + atomic_inc_unchecked(&vcc->stats->rx_err);
28870 goto out_free_desc;
28871 }
28872
28873 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28874 ia_vcc = INPH_IA_VCC(vcc);
28875 if (ia_vcc == NULL)
28876 {
28877 - atomic_inc(&vcc->stats->rx_err);
28878 + atomic_inc_unchecked(&vcc->stats->rx_err);
28879 atm_return(vcc, skb->truesize);
28880 dev_kfree_skb_any(skb);
28881 goto INCR_DLE;
28882 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28883 if ((length > iadev->rx_buf_sz) || (length >
28884 (skb->len - sizeof(struct cpcs_trailer))))
28885 {
28886 - atomic_inc(&vcc->stats->rx_err);
28887 + atomic_inc_unchecked(&vcc->stats->rx_err);
28888 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28889 length, skb->len);)
28890 atm_return(vcc, skb->truesize);
28891 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28892
28893 IF_RX(printk("rx_dle_intr: skb push");)
28894 vcc->push(vcc,skb);
28895 - atomic_inc(&vcc->stats->rx);
28896 + atomic_inc_unchecked(&vcc->stats->rx);
28897 iadev->rx_pkt_cnt++;
28898 }
28899 INCR_DLE:
28900 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28901 {
28902 struct k_sonet_stats *stats;
28903 stats = &PRIV(_ia_dev[board])->sonet_stats;
28904 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28905 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28906 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28907 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28908 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28909 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28910 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28911 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28912 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28913 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28914 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28915 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28916 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28917 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28918 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28919 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28920 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28921 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28922 }
28923 ia_cmds.status = 0;
28924 break;
28925 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28926 if ((desc == 0) || (desc > iadev->num_tx_desc))
28927 {
28928 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28929 - atomic_inc(&vcc->stats->tx);
28930 + atomic_inc_unchecked(&vcc->stats->tx);
28931 if (vcc->pop)
28932 vcc->pop(vcc, skb);
28933 else
28934 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28935 ATM_DESC(skb) = vcc->vci;
28936 skb_queue_tail(&iadev->tx_dma_q, skb);
28937
28938 - atomic_inc(&vcc->stats->tx);
28939 + atomic_inc_unchecked(&vcc->stats->tx);
28940 iadev->tx_pkt_cnt++;
28941 /* Increment transaction counter */
28942 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28943
28944 #if 0
28945 /* add flow control logic */
28946 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28947 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28948 if (iavcc->vc_desc_cnt > 10) {
28949 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28950 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28951 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28952 index 68c7588..7036683 100644
28953 --- a/drivers/atm/lanai.c
28954 +++ b/drivers/atm/lanai.c
28955 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28956 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28957 lanai_endtx(lanai, lvcc);
28958 lanai_free_skb(lvcc->tx.atmvcc, skb);
28959 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28960 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28961 }
28962
28963 /* Try to fill the buffer - don't call unless there is backlog */
28964 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28965 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28966 __net_timestamp(skb);
28967 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28968 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28969 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28970 out:
28971 lvcc->rx.buf.ptr = end;
28972 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28973 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28974 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28975 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28976 lanai->stats.service_rxnotaal5++;
28977 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28978 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28979 return 0;
28980 }
28981 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28982 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28983 int bytes;
28984 read_unlock(&vcc_sklist_lock);
28985 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28986 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28987 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28988 lvcc->stats.x.aal5.service_trash++;
28989 bytes = (SERVICE_GET_END(s) * 16) -
28990 (((unsigned long) lvcc->rx.buf.ptr) -
28991 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28992 }
28993 if (s & SERVICE_STREAM) {
28994 read_unlock(&vcc_sklist_lock);
28995 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28996 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28997 lvcc->stats.x.aal5.service_stream++;
28998 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28999 "PDU on VCI %d!\n", lanai->number, vci);
29000 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29001 return 0;
29002 }
29003 DPRINTK("got rx crc error on vci %d\n", vci);
29004 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29005 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29006 lvcc->stats.x.aal5.service_rxcrc++;
29007 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29008 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29009 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29010 index 1c70c45..300718d 100644
29011 --- a/drivers/atm/nicstar.c
29012 +++ b/drivers/atm/nicstar.c
29013 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29014 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
29015 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
29016 card->index);
29017 - atomic_inc(&vcc->stats->tx_err);
29018 + atomic_inc_unchecked(&vcc->stats->tx_err);
29019 dev_kfree_skb_any(skb);
29020 return -EINVAL;
29021 }
29022 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29023 if (!vc->tx) {
29024 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
29025 card->index);
29026 - atomic_inc(&vcc->stats->tx_err);
29027 + atomic_inc_unchecked(&vcc->stats->tx_err);
29028 dev_kfree_skb_any(skb);
29029 return -EINVAL;
29030 }
29031 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29032 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
29033 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
29034 card->index);
29035 - atomic_inc(&vcc->stats->tx_err);
29036 + atomic_inc_unchecked(&vcc->stats->tx_err);
29037 dev_kfree_skb_any(skb);
29038 return -EINVAL;
29039 }
29040
29041 if (skb_shinfo(skb)->nr_frags != 0) {
29042 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29043 - atomic_inc(&vcc->stats->tx_err);
29044 + atomic_inc_unchecked(&vcc->stats->tx_err);
29045 dev_kfree_skb_any(skb);
29046 return -EINVAL;
29047 }
29048 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29049 }
29050
29051 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
29052 - atomic_inc(&vcc->stats->tx_err);
29053 + atomic_inc_unchecked(&vcc->stats->tx_err);
29054 dev_kfree_skb_any(skb);
29055 return -EIO;
29056 }
29057 - atomic_inc(&vcc->stats->tx);
29058 + atomic_inc_unchecked(&vcc->stats->tx);
29059
29060 return 0;
29061 }
29062 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29063 printk
29064 ("nicstar%d: Can't allocate buffers for aal0.\n",
29065 card->index);
29066 - atomic_add(i, &vcc->stats->rx_drop);
29067 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
29068 break;
29069 }
29070 if (!atm_charge(vcc, sb->truesize)) {
29071 RXPRINTK
29072 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
29073 card->index);
29074 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29075 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29076 dev_kfree_skb_any(sb);
29077 break;
29078 }
29079 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29080 ATM_SKB(sb)->vcc = vcc;
29081 __net_timestamp(sb);
29082 vcc->push(vcc, sb);
29083 - atomic_inc(&vcc->stats->rx);
29084 + atomic_inc_unchecked(&vcc->stats->rx);
29085 cell += ATM_CELL_PAYLOAD;
29086 }
29087
29088 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29089 if (iovb == NULL) {
29090 printk("nicstar%d: Out of iovec buffers.\n",
29091 card->index);
29092 - atomic_inc(&vcc->stats->rx_drop);
29093 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29094 recycle_rx_buf(card, skb);
29095 return;
29096 }
29097 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29098 small or large buffer itself. */
29099 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
29100 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29101 - atomic_inc(&vcc->stats->rx_err);
29102 + atomic_inc_unchecked(&vcc->stats->rx_err);
29103 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29104 NS_MAX_IOVECS);
29105 NS_PRV_IOVCNT(iovb) = 0;
29106 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29107 ("nicstar%d: Expected a small buffer, and this is not one.\n",
29108 card->index);
29109 which_list(card, skb);
29110 - atomic_inc(&vcc->stats->rx_err);
29111 + atomic_inc_unchecked(&vcc->stats->rx_err);
29112 recycle_rx_buf(card, skb);
29113 vc->rx_iov = NULL;
29114 recycle_iov_buf(card, iovb);
29115 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29116 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29117 card->index);
29118 which_list(card, skb);
29119 - atomic_inc(&vcc->stats->rx_err);
29120 + atomic_inc_unchecked(&vcc->stats->rx_err);
29121 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29122 NS_PRV_IOVCNT(iovb));
29123 vc->rx_iov = NULL;
29124 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29125 printk(" - PDU size mismatch.\n");
29126 else
29127 printk(".\n");
29128 - atomic_inc(&vcc->stats->rx_err);
29129 + atomic_inc_unchecked(&vcc->stats->rx_err);
29130 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29131 NS_PRV_IOVCNT(iovb));
29132 vc->rx_iov = NULL;
29133 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29134 /* skb points to a small buffer */
29135 if (!atm_charge(vcc, skb->truesize)) {
29136 push_rxbufs(card, skb);
29137 - atomic_inc(&vcc->stats->rx_drop);
29138 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29139 } else {
29140 skb_put(skb, len);
29141 dequeue_sm_buf(card, skb);
29142 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29143 ATM_SKB(skb)->vcc = vcc;
29144 __net_timestamp(skb);
29145 vcc->push(vcc, skb);
29146 - atomic_inc(&vcc->stats->rx);
29147 + atomic_inc_unchecked(&vcc->stats->rx);
29148 }
29149 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29150 struct sk_buff *sb;
29151 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29152 if (len <= NS_SMBUFSIZE) {
29153 if (!atm_charge(vcc, sb->truesize)) {
29154 push_rxbufs(card, sb);
29155 - atomic_inc(&vcc->stats->rx_drop);
29156 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29157 } else {
29158 skb_put(sb, len);
29159 dequeue_sm_buf(card, sb);
29160 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29161 ATM_SKB(sb)->vcc = vcc;
29162 __net_timestamp(sb);
29163 vcc->push(vcc, sb);
29164 - atomic_inc(&vcc->stats->rx);
29165 + atomic_inc_unchecked(&vcc->stats->rx);
29166 }
29167
29168 push_rxbufs(card, skb);
29169 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29170
29171 if (!atm_charge(vcc, skb->truesize)) {
29172 push_rxbufs(card, skb);
29173 - atomic_inc(&vcc->stats->rx_drop);
29174 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29175 } else {
29176 dequeue_lg_buf(card, skb);
29177 #ifdef NS_USE_DESTRUCTORS
29178 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29179 ATM_SKB(skb)->vcc = vcc;
29180 __net_timestamp(skb);
29181 vcc->push(vcc, skb);
29182 - atomic_inc(&vcc->stats->rx);
29183 + atomic_inc_unchecked(&vcc->stats->rx);
29184 }
29185
29186 push_rxbufs(card, sb);
29187 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29188 printk
29189 ("nicstar%d: Out of huge buffers.\n",
29190 card->index);
29191 - atomic_inc(&vcc->stats->rx_drop);
29192 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29193 recycle_iovec_rx_bufs(card,
29194 (struct iovec *)
29195 iovb->data,
29196 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29197 card->hbpool.count++;
29198 } else
29199 dev_kfree_skb_any(hb);
29200 - atomic_inc(&vcc->stats->rx_drop);
29201 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29202 } else {
29203 /* Copy the small buffer to the huge buffer */
29204 sb = (struct sk_buff *)iov->iov_base;
29205 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29206 #endif /* NS_USE_DESTRUCTORS */
29207 __net_timestamp(hb);
29208 vcc->push(vcc, hb);
29209 - atomic_inc(&vcc->stats->rx);
29210 + atomic_inc_unchecked(&vcc->stats->rx);
29211 }
29212 }
29213
29214 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29215 index 9851093..adb2b1e 100644
29216 --- a/drivers/atm/solos-pci.c
29217 +++ b/drivers/atm/solos-pci.c
29218 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29219 }
29220 atm_charge(vcc, skb->truesize);
29221 vcc->push(vcc, skb);
29222 - atomic_inc(&vcc->stats->rx);
29223 + atomic_inc_unchecked(&vcc->stats->rx);
29224 break;
29225
29226 case PKT_STATUS:
29227 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29228 vcc = SKB_CB(oldskb)->vcc;
29229
29230 if (vcc) {
29231 - atomic_inc(&vcc->stats->tx);
29232 + atomic_inc_unchecked(&vcc->stats->tx);
29233 solos_pop(vcc, oldskb);
29234 } else
29235 dev_kfree_skb_irq(oldskb);
29236 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29237 index 0215934..ce9f5b1 100644
29238 --- a/drivers/atm/suni.c
29239 +++ b/drivers/atm/suni.c
29240 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29241
29242
29243 #define ADD_LIMITED(s,v) \
29244 - atomic_add((v),&stats->s); \
29245 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29246 + atomic_add_unchecked((v),&stats->s); \
29247 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29248
29249
29250 static void suni_hz(unsigned long from_timer)
29251 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29252 index 5120a96..e2572bd 100644
29253 --- a/drivers/atm/uPD98402.c
29254 +++ b/drivers/atm/uPD98402.c
29255 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29256 struct sonet_stats tmp;
29257 int error = 0;
29258
29259 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29260 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29261 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29262 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29263 if (zero && !error) {
29264 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29265
29266
29267 #define ADD_LIMITED(s,v) \
29268 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29269 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29270 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29271 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29272 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29273 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29274
29275
29276 static void stat_event(struct atm_dev *dev)
29277 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29278 if (reason & uPD98402_INT_PFM) stat_event(dev);
29279 if (reason & uPD98402_INT_PCO) {
29280 (void) GET(PCOCR); /* clear interrupt cause */
29281 - atomic_add(GET(HECCT),
29282 + atomic_add_unchecked(GET(HECCT),
29283 &PRIV(dev)->sonet_stats.uncorr_hcs);
29284 }
29285 if ((reason & uPD98402_INT_RFO) &&
29286 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29287 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29288 uPD98402_INT_LOS),PIMR); /* enable them */
29289 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29290 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29291 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29292 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29293 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29294 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29295 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29296 return 0;
29297 }
29298
29299 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29300 index abe4e20..83c4727 100644
29301 --- a/drivers/atm/zatm.c
29302 +++ b/drivers/atm/zatm.c
29303 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29304 }
29305 if (!size) {
29306 dev_kfree_skb_irq(skb);
29307 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29308 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29309 continue;
29310 }
29311 if (!atm_charge(vcc,skb->truesize)) {
29312 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29313 skb->len = size;
29314 ATM_SKB(skb)->vcc = vcc;
29315 vcc->push(vcc,skb);
29316 - atomic_inc(&vcc->stats->rx);
29317 + atomic_inc_unchecked(&vcc->stats->rx);
29318 }
29319 zout(pos & 0xffff,MTA(mbx));
29320 #if 0 /* probably a stupid idea */
29321 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29322 skb_queue_head(&zatm_vcc->backlog,skb);
29323 break;
29324 }
29325 - atomic_inc(&vcc->stats->tx);
29326 + atomic_inc_unchecked(&vcc->stats->tx);
29327 wake_up(&zatm_vcc->tx_wait);
29328 }
29329
29330 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29331 index 147d1a4..d0fd4b0 100644
29332 --- a/drivers/base/devtmpfs.c
29333 +++ b/drivers/base/devtmpfs.c
29334 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29335 if (!thread)
29336 return 0;
29337
29338 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29339 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29340 if (err)
29341 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29342 else
29343 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29344 index e6ee5e8..98ad7fc 100644
29345 --- a/drivers/base/power/wakeup.c
29346 +++ b/drivers/base/power/wakeup.c
29347 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29348 * They need to be modified together atomically, so it's better to use one
29349 * atomic variable to hold them both.
29350 */
29351 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29352 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29353
29354 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29355 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29356
29357 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29358 {
29359 - unsigned int comb = atomic_read(&combined_event_count);
29360 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29361
29362 *cnt = (comb >> IN_PROGRESS_BITS);
29363 *inpr = comb & MAX_IN_PROGRESS;
29364 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29365 ws->start_prevent_time = ws->last_time;
29366
29367 /* Increment the counter of events in progress. */
29368 - cec = atomic_inc_return(&combined_event_count);
29369 + cec = atomic_inc_return_unchecked(&combined_event_count);
29370
29371 trace_wakeup_source_activate(ws->name, cec);
29372 }
29373 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29374 * Increment the counter of registered wakeup events and decrement the
29375 * couter of wakeup events in progress simultaneously.
29376 */
29377 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29378 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29379 trace_wakeup_source_deactivate(ws->name, cec);
29380
29381 split_counters(&cnt, &inpr);
29382 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29383 index ca83f96..69d4ea9 100644
29384 --- a/drivers/block/cciss.c
29385 +++ b/drivers/block/cciss.c
29386 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29387 int err;
29388 u32 cp;
29389
29390 + memset(&arg64, 0, sizeof(arg64));
29391 +
29392 err = 0;
29393 err |=
29394 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29395 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29396 while (!list_empty(&h->reqQ)) {
29397 c = list_entry(h->reqQ.next, CommandList_struct, list);
29398 /* can't do anything if fifo is full */
29399 - if ((h->access.fifo_full(h))) {
29400 + if ((h->access->fifo_full(h))) {
29401 dev_warn(&h->pdev->dev, "fifo full\n");
29402 break;
29403 }
29404 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29405 h->Qdepth--;
29406
29407 /* Tell the controller execute command */
29408 - h->access.submit_command(h, c);
29409 + h->access->submit_command(h, c);
29410
29411 /* Put job onto the completed Q */
29412 addQ(&h->cmpQ, c);
29413 @@ -3443,17 +3445,17 @@ startio:
29414
29415 static inline unsigned long get_next_completion(ctlr_info_t *h)
29416 {
29417 - return h->access.command_completed(h);
29418 + return h->access->command_completed(h);
29419 }
29420
29421 static inline int interrupt_pending(ctlr_info_t *h)
29422 {
29423 - return h->access.intr_pending(h);
29424 + return h->access->intr_pending(h);
29425 }
29426
29427 static inline long interrupt_not_for_us(ctlr_info_t *h)
29428 {
29429 - return ((h->access.intr_pending(h) == 0) ||
29430 + return ((h->access->intr_pending(h) == 0) ||
29431 (h->interrupts_enabled == 0));
29432 }
29433
29434 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29435 u32 a;
29436
29437 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29438 - return h->access.command_completed(h);
29439 + return h->access->command_completed(h);
29440
29441 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29442 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29443 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29444 trans_support & CFGTBL_Trans_use_short_tags);
29445
29446 /* Change the access methods to the performant access methods */
29447 - h->access = SA5_performant_access;
29448 + h->access = &SA5_performant_access;
29449 h->transMethod = CFGTBL_Trans_Performant;
29450
29451 return;
29452 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29453 if (prod_index < 0)
29454 return -ENODEV;
29455 h->product_name = products[prod_index].product_name;
29456 - h->access = *(products[prod_index].access);
29457 + h->access = products[prod_index].access;
29458
29459 if (cciss_board_disabled(h)) {
29460 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29461 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29462 }
29463
29464 /* make sure the board interrupts are off */
29465 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29466 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29467 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29468 if (rc)
29469 goto clean2;
29470 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29471 * fake ones to scoop up any residual completions.
29472 */
29473 spin_lock_irqsave(&h->lock, flags);
29474 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29475 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29476 spin_unlock_irqrestore(&h->lock, flags);
29477 free_irq(h->intr[h->intr_mode], h);
29478 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29479 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29480 dev_info(&h->pdev->dev, "Board READY.\n");
29481 dev_info(&h->pdev->dev,
29482 "Waiting for stale completions to drain.\n");
29483 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29484 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29485 msleep(10000);
29486 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29487 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29488
29489 rc = controller_reset_failed(h->cfgtable);
29490 if (rc)
29491 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29492 cciss_scsi_setup(h);
29493
29494 /* Turn the interrupts on so we can service requests */
29495 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29496 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29497
29498 /* Get the firmware version */
29499 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29500 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29501 kfree(flush_buf);
29502 if (return_code != IO_OK)
29503 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29504 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29505 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29506 free_irq(h->intr[h->intr_mode], h);
29507 }
29508
29509 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29510 index 7fda30e..eb5dfe0 100644
29511 --- a/drivers/block/cciss.h
29512 +++ b/drivers/block/cciss.h
29513 @@ -101,7 +101,7 @@ struct ctlr_info
29514 /* information about each logical volume */
29515 drive_info_struct *drv[CISS_MAX_LUN];
29516
29517 - struct access_method access;
29518 + struct access_method *access;
29519
29520 /* queue and queue Info */
29521 struct list_head reqQ;
29522 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29523 index 9125bbe..eede5c8 100644
29524 --- a/drivers/block/cpqarray.c
29525 +++ b/drivers/block/cpqarray.c
29526 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29527 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29528 goto Enomem4;
29529 }
29530 - hba[i]->access.set_intr_mask(hba[i], 0);
29531 + hba[i]->access->set_intr_mask(hba[i], 0);
29532 if (request_irq(hba[i]->intr, do_ida_intr,
29533 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29534 {
29535 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29536 add_timer(&hba[i]->timer);
29537
29538 /* Enable IRQ now that spinlock and rate limit timer are set up */
29539 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29540 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29541
29542 for(j=0; j<NWD; j++) {
29543 struct gendisk *disk = ida_gendisk[i][j];
29544 @@ -694,7 +694,7 @@ DBGINFO(
29545 for(i=0; i<NR_PRODUCTS; i++) {
29546 if (board_id == products[i].board_id) {
29547 c->product_name = products[i].product_name;
29548 - c->access = *(products[i].access);
29549 + c->access = products[i].access;
29550 break;
29551 }
29552 }
29553 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29554 hba[ctlr]->intr = intr;
29555 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29556 hba[ctlr]->product_name = products[j].product_name;
29557 - hba[ctlr]->access = *(products[j].access);
29558 + hba[ctlr]->access = products[j].access;
29559 hba[ctlr]->ctlr = ctlr;
29560 hba[ctlr]->board_id = board_id;
29561 hba[ctlr]->pci_dev = NULL; /* not PCI */
29562 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29563
29564 while((c = h->reqQ) != NULL) {
29565 /* Can't do anything if we're busy */
29566 - if (h->access.fifo_full(h) == 0)
29567 + if (h->access->fifo_full(h) == 0)
29568 return;
29569
29570 /* Get the first entry from the request Q */
29571 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29572 h->Qdepth--;
29573
29574 /* Tell the controller to do our bidding */
29575 - h->access.submit_command(h, c);
29576 + h->access->submit_command(h, c);
29577
29578 /* Get onto the completion Q */
29579 addQ(&h->cmpQ, c);
29580 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29581 unsigned long flags;
29582 __u32 a,a1;
29583
29584 - istat = h->access.intr_pending(h);
29585 + istat = h->access->intr_pending(h);
29586 /* Is this interrupt for us? */
29587 if (istat == 0)
29588 return IRQ_NONE;
29589 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29590 */
29591 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29592 if (istat & FIFO_NOT_EMPTY) {
29593 - while((a = h->access.command_completed(h))) {
29594 + while((a = h->access->command_completed(h))) {
29595 a1 = a; a &= ~3;
29596 if ((c = h->cmpQ) == NULL)
29597 {
29598 @@ -1449,11 +1449,11 @@ static int sendcmd(
29599 /*
29600 * Disable interrupt
29601 */
29602 - info_p->access.set_intr_mask(info_p, 0);
29603 + info_p->access->set_intr_mask(info_p, 0);
29604 /* Make sure there is room in the command FIFO */
29605 /* Actually it should be completely empty at this time. */
29606 for (i = 200000; i > 0; i--) {
29607 - temp = info_p->access.fifo_full(info_p);
29608 + temp = info_p->access->fifo_full(info_p);
29609 if (temp != 0) {
29610 break;
29611 }
29612 @@ -1466,7 +1466,7 @@ DBG(
29613 /*
29614 * Send the cmd
29615 */
29616 - info_p->access.submit_command(info_p, c);
29617 + info_p->access->submit_command(info_p, c);
29618 complete = pollcomplete(ctlr);
29619
29620 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29621 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29622 * we check the new geometry. Then turn interrupts back on when
29623 * we're done.
29624 */
29625 - host->access.set_intr_mask(host, 0);
29626 + host->access->set_intr_mask(host, 0);
29627 getgeometry(ctlr);
29628 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29629 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29630
29631 for(i=0; i<NWD; i++) {
29632 struct gendisk *disk = ida_gendisk[ctlr][i];
29633 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29634 /* Wait (up to 2 seconds) for a command to complete */
29635
29636 for (i = 200000; i > 0; i--) {
29637 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29638 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29639 if (done == 0) {
29640 udelay(10); /* a short fixed delay */
29641 } else
29642 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29643 index be73e9d..7fbf140 100644
29644 --- a/drivers/block/cpqarray.h
29645 +++ b/drivers/block/cpqarray.h
29646 @@ -99,7 +99,7 @@ struct ctlr_info {
29647 drv_info_t drv[NWD];
29648 struct proc_dir_entry *proc;
29649
29650 - struct access_method access;
29651 + struct access_method *access;
29652
29653 cmdlist_t *reqQ;
29654 cmdlist_t *cmpQ;
29655 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29656 index b953cc7..e3dc580 100644
29657 --- a/drivers/block/drbd/drbd_int.h
29658 +++ b/drivers/block/drbd/drbd_int.h
29659 @@ -735,7 +735,7 @@ struct drbd_request;
29660 struct drbd_epoch {
29661 struct list_head list;
29662 unsigned int barrier_nr;
29663 - atomic_t epoch_size; /* increased on every request added. */
29664 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29665 atomic_t active; /* increased on every req. added, and dec on every finished. */
29666 unsigned long flags;
29667 };
29668 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29669 void *int_dig_in;
29670 void *int_dig_vv;
29671 wait_queue_head_t seq_wait;
29672 - atomic_t packet_seq;
29673 + atomic_unchecked_t packet_seq;
29674 unsigned int peer_seq;
29675 spinlock_t peer_seq_lock;
29676 unsigned int minor;
29677 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29678
29679 static inline void drbd_tcp_cork(struct socket *sock)
29680 {
29681 - int __user val = 1;
29682 + int val = 1;
29683 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29684 - (char __user *)&val, sizeof(val));
29685 + (char __force_user *)&val, sizeof(val));
29686 }
29687
29688 static inline void drbd_tcp_uncork(struct socket *sock)
29689 {
29690 - int __user val = 0;
29691 + int val = 0;
29692 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29693 - (char __user *)&val, sizeof(val));
29694 + (char __force_user *)&val, sizeof(val));
29695 }
29696
29697 static inline void drbd_tcp_nodelay(struct socket *sock)
29698 {
29699 - int __user val = 1;
29700 + int val = 1;
29701 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29702 - (char __user *)&val, sizeof(val));
29703 + (char __force_user *)&val, sizeof(val));
29704 }
29705
29706 static inline void drbd_tcp_quickack(struct socket *sock)
29707 {
29708 - int __user val = 2;
29709 + int val = 2;
29710 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29711 - (char __user *)&val, sizeof(val));
29712 + (char __force_user *)&val, sizeof(val));
29713 }
29714
29715 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29716 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29717 index f55683a..2101b96 100644
29718 --- a/drivers/block/drbd/drbd_main.c
29719 +++ b/drivers/block/drbd/drbd_main.c
29720 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29721 p.sector = sector;
29722 p.block_id = block_id;
29723 p.blksize = blksize;
29724 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29725 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29726
29727 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29728 return false;
29729 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29730
29731 p.sector = cpu_to_be64(req->sector);
29732 p.block_id = (unsigned long)req;
29733 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29734 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29735
29736 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29737
29738 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29739 atomic_set(&mdev->unacked_cnt, 0);
29740 atomic_set(&mdev->local_cnt, 0);
29741 atomic_set(&mdev->net_cnt, 0);
29742 - atomic_set(&mdev->packet_seq, 0);
29743 + atomic_set_unchecked(&mdev->packet_seq, 0);
29744 atomic_set(&mdev->pp_in_use, 0);
29745 atomic_set(&mdev->pp_in_use_by_net, 0);
29746 atomic_set(&mdev->rs_sect_in, 0);
29747 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29748 mdev->receiver.t_state);
29749
29750 /* no need to lock it, I'm the only thread alive */
29751 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29752 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29753 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29754 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29755 mdev->al_writ_cnt =
29756 mdev->bm_writ_cnt =
29757 mdev->read_cnt =
29758 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29759 index edb490a..ecd69da 100644
29760 --- a/drivers/block/drbd/drbd_nl.c
29761 +++ b/drivers/block/drbd/drbd_nl.c
29762 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29763 module_put(THIS_MODULE);
29764 }
29765
29766 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29767 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29768
29769 static unsigned short *
29770 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29771 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29772 cn_reply->id.idx = CN_IDX_DRBD;
29773 cn_reply->id.val = CN_VAL_DRBD;
29774
29775 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29776 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29777 cn_reply->ack = 0; /* not used here. */
29778 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29779 (int)((char *)tl - (char *)reply->tag_list);
29780 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29781 cn_reply->id.idx = CN_IDX_DRBD;
29782 cn_reply->id.val = CN_VAL_DRBD;
29783
29784 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29785 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29786 cn_reply->ack = 0; /* not used here. */
29787 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29788 (int)((char *)tl - (char *)reply->tag_list);
29789 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29790 cn_reply->id.idx = CN_IDX_DRBD;
29791 cn_reply->id.val = CN_VAL_DRBD;
29792
29793 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29794 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29795 cn_reply->ack = 0; // not used here.
29796 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29797 (int)((char*)tl - (char*)reply->tag_list);
29798 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29799 cn_reply->id.idx = CN_IDX_DRBD;
29800 cn_reply->id.val = CN_VAL_DRBD;
29801
29802 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29803 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29804 cn_reply->ack = 0; /* not used here. */
29805 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29806 (int)((char *)tl - (char *)reply->tag_list);
29807 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29808 index c74ca2d..860c819 100644
29809 --- a/drivers/block/drbd/drbd_receiver.c
29810 +++ b/drivers/block/drbd/drbd_receiver.c
29811 @@ -898,7 +898,7 @@ retry:
29812 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29813 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29814
29815 - atomic_set(&mdev->packet_seq, 0);
29816 + atomic_set_unchecked(&mdev->packet_seq, 0);
29817 mdev->peer_seq = 0;
29818
29819 if (drbd_send_protocol(mdev) == -1)
29820 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29821 do {
29822 next_epoch = NULL;
29823
29824 - epoch_size = atomic_read(&epoch->epoch_size);
29825 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29826
29827 switch (ev & ~EV_CLEANUP) {
29828 case EV_PUT:
29829 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29830 rv = FE_DESTROYED;
29831 } else {
29832 epoch->flags = 0;
29833 - atomic_set(&epoch->epoch_size, 0);
29834 + atomic_set_unchecked(&epoch->epoch_size, 0);
29835 /* atomic_set(&epoch->active, 0); is already zero */
29836 if (rv == FE_STILL_LIVE)
29837 rv = FE_RECYCLED;
29838 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29839 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29840 drbd_flush(mdev);
29841
29842 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29843 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29844 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29845 if (epoch)
29846 break;
29847 }
29848
29849 epoch = mdev->current_epoch;
29850 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29851 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29852
29853 D_ASSERT(atomic_read(&epoch->active) == 0);
29854 D_ASSERT(epoch->flags == 0);
29855 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29856 }
29857
29858 epoch->flags = 0;
29859 - atomic_set(&epoch->epoch_size, 0);
29860 + atomic_set_unchecked(&epoch->epoch_size, 0);
29861 atomic_set(&epoch->active, 0);
29862
29863 spin_lock(&mdev->epoch_lock);
29864 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29865 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29866 list_add(&epoch->list, &mdev->current_epoch->list);
29867 mdev->current_epoch = epoch;
29868 mdev->epochs++;
29869 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29870 spin_unlock(&mdev->peer_seq_lock);
29871
29872 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29873 - atomic_inc(&mdev->current_epoch->epoch_size);
29874 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29875 return drbd_drain_block(mdev, data_size);
29876 }
29877
29878 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29879
29880 spin_lock(&mdev->epoch_lock);
29881 e->epoch = mdev->current_epoch;
29882 - atomic_inc(&e->epoch->epoch_size);
29883 + atomic_inc_unchecked(&e->epoch->epoch_size);
29884 atomic_inc(&e->epoch->active);
29885 spin_unlock(&mdev->epoch_lock);
29886
29887 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29888 D_ASSERT(list_empty(&mdev->done_ee));
29889
29890 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29891 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29892 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29893 D_ASSERT(list_empty(&mdev->current_epoch->list));
29894 }
29895
29896 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29897 index 54046e5..7759c55 100644
29898 --- a/drivers/block/loop.c
29899 +++ b/drivers/block/loop.c
29900 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29901 mm_segment_t old_fs = get_fs();
29902
29903 set_fs(get_ds());
29904 - bw = file->f_op->write(file, buf, len, &pos);
29905 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29906 set_fs(old_fs);
29907 if (likely(bw == len))
29908 return 0;
29909 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29910 index 72bedad..8181ce1 100644
29911 --- a/drivers/char/Kconfig
29912 +++ b/drivers/char/Kconfig
29913 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29914
29915 config DEVKMEM
29916 bool "/dev/kmem virtual device support"
29917 - default y
29918 + default n
29919 + depends on !GRKERNSEC_KMEM
29920 help
29921 Say Y here if you want to support the /dev/kmem device. The
29922 /dev/kmem device is rarely used, but can be used for certain
29923 @@ -581,6 +582,7 @@ config DEVPORT
29924 bool
29925 depends on !M68K
29926 depends on ISA || PCI
29927 + depends on !GRKERNSEC_KMEM
29928 default y
29929
29930 source "drivers/s390/char/Kconfig"
29931 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29932 index 2e04433..22afc64 100644
29933 --- a/drivers/char/agp/frontend.c
29934 +++ b/drivers/char/agp/frontend.c
29935 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29936 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29937 return -EFAULT;
29938
29939 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29940 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29941 return -EFAULT;
29942
29943 client = agp_find_client_by_pid(reserve.pid);
29944 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29945 index 21cb980..f15107c 100644
29946 --- a/drivers/char/genrtc.c
29947 +++ b/drivers/char/genrtc.c
29948 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29949 switch (cmd) {
29950
29951 case RTC_PLL_GET:
29952 + memset(&pll, 0, sizeof(pll));
29953 if (get_rtc_pll(&pll))
29954 return -EINVAL;
29955 else
29956 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29957 index dfd7876..c0b0885 100644
29958 --- a/drivers/char/hpet.c
29959 +++ b/drivers/char/hpet.c
29960 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29961 }
29962
29963 static int
29964 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29965 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29966 struct hpet_info *info)
29967 {
29968 struct hpet_timer __iomem *timer;
29969 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29970 index a0c84bb..9edcf60 100644
29971 --- a/drivers/char/ipmi/ipmi_msghandler.c
29972 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29973 @@ -420,7 +420,7 @@ struct ipmi_smi {
29974 struct proc_dir_entry *proc_dir;
29975 char proc_dir_name[10];
29976
29977 - atomic_t stats[IPMI_NUM_STATS];
29978 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29979
29980 /*
29981 * run_to_completion duplicate of smb_info, smi_info
29982 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29983
29984
29985 #define ipmi_inc_stat(intf, stat) \
29986 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29987 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29988 #define ipmi_get_stat(intf, stat) \
29989 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29990 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29991
29992 static int is_lan_addr(struct ipmi_addr *addr)
29993 {
29994 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29995 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29996 init_waitqueue_head(&intf->waitq);
29997 for (i = 0; i < IPMI_NUM_STATS; i++)
29998 - atomic_set(&intf->stats[i], 0);
29999 + atomic_set_unchecked(&intf->stats[i], 0);
30000
30001 intf->proc_dir = NULL;
30002
30003 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
30004 index 32a6c7e..f6966a9 100644
30005 --- a/drivers/char/ipmi/ipmi_si_intf.c
30006 +++ b/drivers/char/ipmi/ipmi_si_intf.c
30007 @@ -275,7 +275,7 @@ struct smi_info {
30008 unsigned char slave_addr;
30009
30010 /* Counters and things for the proc filesystem. */
30011 - atomic_t stats[SI_NUM_STATS];
30012 + atomic_unchecked_t stats[SI_NUM_STATS];
30013
30014 struct task_struct *thread;
30015
30016 @@ -284,9 +284,9 @@ struct smi_info {
30017 };
30018
30019 #define smi_inc_stat(smi, stat) \
30020 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
30021 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
30022 #define smi_get_stat(smi, stat) \
30023 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
30024 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
30025
30026 #define SI_MAX_PARMS 4
30027
30028 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
30029 atomic_set(&new_smi->req_events, 0);
30030 new_smi->run_to_completion = 0;
30031 for (i = 0; i < SI_NUM_STATS; i++)
30032 - atomic_set(&new_smi->stats[i], 0);
30033 + atomic_set_unchecked(&new_smi->stats[i], 0);
30034
30035 new_smi->interrupt_disabled = 1;
30036 atomic_set(&new_smi->stop_operation, 0);
30037 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
30038 index 0537903..121c699 100644
30039 --- a/drivers/char/mem.c
30040 +++ b/drivers/char/mem.c
30041 @@ -18,6 +18,7 @@
30042 #include <linux/raw.h>
30043 #include <linux/tty.h>
30044 #include <linux/capability.h>
30045 +#include <linux/security.h>
30046 #include <linux/ptrace.h>
30047 #include <linux/device.h>
30048 #include <linux/highmem.h>
30049 @@ -37,6 +38,10 @@
30050
30051 #define DEVPORT_MINOR 4
30052
30053 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30054 +extern const struct file_operations grsec_fops;
30055 +#endif
30056 +
30057 static inline unsigned long size_inside_page(unsigned long start,
30058 unsigned long size)
30059 {
30060 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30061
30062 while (cursor < to) {
30063 if (!devmem_is_allowed(pfn)) {
30064 +#ifdef CONFIG_GRKERNSEC_KMEM
30065 + gr_handle_mem_readwrite(from, to);
30066 +#else
30067 printk(KERN_INFO
30068 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
30069 current->comm, from, to);
30070 +#endif
30071 return 0;
30072 }
30073 cursor += PAGE_SIZE;
30074 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30075 }
30076 return 1;
30077 }
30078 +#elif defined(CONFIG_GRKERNSEC_KMEM)
30079 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30080 +{
30081 + return 0;
30082 +}
30083 #else
30084 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30085 {
30086 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30087
30088 while (count > 0) {
30089 unsigned long remaining;
30090 + char *temp;
30091
30092 sz = size_inside_page(p, count);
30093
30094 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30095 if (!ptr)
30096 return -EFAULT;
30097
30098 - remaining = copy_to_user(buf, ptr, sz);
30099 +#ifdef CONFIG_PAX_USERCOPY
30100 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30101 + if (!temp) {
30102 + unxlate_dev_mem_ptr(p, ptr);
30103 + return -ENOMEM;
30104 + }
30105 + memcpy(temp, ptr, sz);
30106 +#else
30107 + temp = ptr;
30108 +#endif
30109 +
30110 + remaining = copy_to_user(buf, temp, sz);
30111 +
30112 +#ifdef CONFIG_PAX_USERCOPY
30113 + kfree(temp);
30114 +#endif
30115 +
30116 unxlate_dev_mem_ptr(p, ptr);
30117 if (remaining)
30118 return -EFAULT;
30119 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30120 size_t count, loff_t *ppos)
30121 {
30122 unsigned long p = *ppos;
30123 - ssize_t low_count, read, sz;
30124 + ssize_t low_count, read, sz, err = 0;
30125 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30126 - int err = 0;
30127
30128 read = 0;
30129 if (p < (unsigned long) high_memory) {
30130 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30131 }
30132 #endif
30133 while (low_count > 0) {
30134 + char *temp;
30135 +
30136 sz = size_inside_page(p, low_count);
30137
30138 /*
30139 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30140 */
30141 kbuf = xlate_dev_kmem_ptr((char *)p);
30142
30143 - if (copy_to_user(buf, kbuf, sz))
30144 +#ifdef CONFIG_PAX_USERCOPY
30145 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30146 + if (!temp)
30147 + return -ENOMEM;
30148 + memcpy(temp, kbuf, sz);
30149 +#else
30150 + temp = kbuf;
30151 +#endif
30152 +
30153 + err = copy_to_user(buf, temp, sz);
30154 +
30155 +#ifdef CONFIG_PAX_USERCOPY
30156 + kfree(temp);
30157 +#endif
30158 +
30159 + if (err)
30160 return -EFAULT;
30161 buf += sz;
30162 p += sz;
30163 @@ -833,6 +880,9 @@ static const struct memdev {
30164 #ifdef CONFIG_CRASH_DUMP
30165 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30166 #endif
30167 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30168 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30169 +#endif
30170 };
30171
30172 static int memory_open(struct inode *inode, struct file *filp)
30173 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30174 index 9df78e2..01ba9ae 100644
30175 --- a/drivers/char/nvram.c
30176 +++ b/drivers/char/nvram.c
30177 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30178
30179 spin_unlock_irq(&rtc_lock);
30180
30181 - if (copy_to_user(buf, contents, tmp - contents))
30182 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30183 return -EFAULT;
30184
30185 *ppos = i;
30186 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30187 index 21721d2..4e98777 100644
30188 --- a/drivers/char/pcmcia/synclink_cs.c
30189 +++ b/drivers/char/pcmcia/synclink_cs.c
30190 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30191
30192 if (debug_level >= DEBUG_LEVEL_INFO)
30193 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30194 - __FILE__,__LINE__, info->device_name, port->count);
30195 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30196
30197 - WARN_ON(!port->count);
30198 + WARN_ON(!atomic_read(&port->count));
30199
30200 if (tty_port_close_start(port, tty, filp) == 0)
30201 goto cleanup;
30202 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30203 cleanup:
30204 if (debug_level >= DEBUG_LEVEL_INFO)
30205 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30206 - tty->driver->name, port->count);
30207 + tty->driver->name, atomic_read(&port->count));
30208 }
30209
30210 /* Wait until the transmitter is empty.
30211 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30212
30213 if (debug_level >= DEBUG_LEVEL_INFO)
30214 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30215 - __FILE__,__LINE__,tty->driver->name, port->count);
30216 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30217
30218 /* If port is closing, signal caller to try again */
30219 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30220 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30221 goto cleanup;
30222 }
30223 spin_lock(&port->lock);
30224 - port->count++;
30225 + atomic_inc(&port->count);
30226 spin_unlock(&port->lock);
30227 spin_unlock_irqrestore(&info->netlock, flags);
30228
30229 - if (port->count == 1) {
30230 + if (atomic_read(&port->count) == 1) {
30231 /* 1st open on this device, init hardware */
30232 retval = startup(info, tty);
30233 if (retval < 0)
30234 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30235 unsigned short new_crctype;
30236
30237 /* return error if TTY interface open */
30238 - if (info->port.count)
30239 + if (atomic_read(&info->port.count))
30240 return -EBUSY;
30241
30242 switch (encoding)
30243 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
30244
30245 /* arbitrate between network and tty opens */
30246 spin_lock_irqsave(&info->netlock, flags);
30247 - if (info->port.count != 0 || info->netcount != 0) {
30248 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30249 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30250 spin_unlock_irqrestore(&info->netlock, flags);
30251 return -EBUSY;
30252 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30253 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30254
30255 /* return error if TTY interface open */
30256 - if (info->port.count)
30257 + if (atomic_read(&info->port.count))
30258 return -EBUSY;
30259
30260 if (cmd != SIOCWANDEV)
30261 diff --git a/drivers/char/random.c b/drivers/char/random.c
30262 index b86eae9..4192a7a 100644
30263 --- a/drivers/char/random.c
30264 +++ b/drivers/char/random.c
30265 @@ -272,8 +272,13 @@
30266 /*
30267 * Configuration information
30268 */
30269 +#ifdef CONFIG_GRKERNSEC_RANDNET
30270 +#define INPUT_POOL_WORDS 512
30271 +#define OUTPUT_POOL_WORDS 128
30272 +#else
30273 #define INPUT_POOL_WORDS 128
30274 #define OUTPUT_POOL_WORDS 32
30275 +#endif
30276 #define SEC_XFER_SIZE 512
30277 #define EXTRACT_SIZE 10
30278
30279 @@ -313,10 +318,17 @@ static struct poolinfo {
30280 int poolwords;
30281 int tap1, tap2, tap3, tap4, tap5;
30282 } poolinfo_table[] = {
30283 +#ifdef CONFIG_GRKERNSEC_RANDNET
30284 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30285 + { 512, 411, 308, 208, 104, 1 },
30286 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30287 + { 128, 103, 76, 51, 25, 1 },
30288 +#else
30289 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30290 { 128, 103, 76, 51, 25, 1 },
30291 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30292 { 32, 26, 20, 14, 7, 1 },
30293 +#endif
30294 #if 0
30295 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30296 { 2048, 1638, 1231, 819, 411, 1 },
30297 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30298 input_rotate += i ? 7 : 14;
30299 }
30300
30301 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30302 - ACCESS_ONCE(r->add_ptr) = i;
30303 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30304 + ACCESS_ONCE_RW(r->add_ptr) = i;
30305 smp_wmb();
30306
30307 if (out)
30308 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30309 }
30310 #endif
30311
30312 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30313 +u64 latent_entropy;
30314 +
30315 +__init void transfer_latent_entropy(void)
30316 +{
30317 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30318 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30319 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30320 +}
30321 +#endif
30322 +
30323 /*********************************************************************
30324 *
30325 * Entropy extraction routines
30326 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30327
30328 extract_buf(r, tmp);
30329 i = min_t(int, nbytes, EXTRACT_SIZE);
30330 - if (copy_to_user(buf, tmp, i)) {
30331 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30332 ret = -EFAULT;
30333 break;
30334 }
30335 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30336 #include <linux/sysctl.h>
30337
30338 static int min_read_thresh = 8, min_write_thresh;
30339 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30340 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30341 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30342 static char sysctl_bootid[16];
30343
30344 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30345 index 9b4f011..b7e0a1a 100644
30346 --- a/drivers/char/sonypi.c
30347 +++ b/drivers/char/sonypi.c
30348 @@ -54,6 +54,7 @@
30349
30350 #include <asm/uaccess.h>
30351 #include <asm/io.h>
30352 +#include <asm/local.h>
30353
30354 #include <linux/sonypi.h>
30355
30356 @@ -490,7 +491,7 @@ static struct sonypi_device {
30357 spinlock_t fifo_lock;
30358 wait_queue_head_t fifo_proc_list;
30359 struct fasync_struct *fifo_async;
30360 - int open_count;
30361 + local_t open_count;
30362 int model;
30363 struct input_dev *input_jog_dev;
30364 struct input_dev *input_key_dev;
30365 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30366 static int sonypi_misc_release(struct inode *inode, struct file *file)
30367 {
30368 mutex_lock(&sonypi_device.lock);
30369 - sonypi_device.open_count--;
30370 + local_dec(&sonypi_device.open_count);
30371 mutex_unlock(&sonypi_device.lock);
30372 return 0;
30373 }
30374 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30375 {
30376 mutex_lock(&sonypi_device.lock);
30377 /* Flush input queue on first open */
30378 - if (!sonypi_device.open_count)
30379 + if (!local_read(&sonypi_device.open_count))
30380 kfifo_reset(&sonypi_device.fifo);
30381 - sonypi_device.open_count++;
30382 + local_inc(&sonypi_device.open_count);
30383 mutex_unlock(&sonypi_device.lock);
30384
30385 return 0;
30386 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30387 index 93211df..c7805f7 100644
30388 --- a/drivers/char/tpm/tpm.c
30389 +++ b/drivers/char/tpm/tpm.c
30390 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30391 chip->vendor.req_complete_val)
30392 goto out_recv;
30393
30394 - if ((status == chip->vendor.req_canceled)) {
30395 + if (status == chip->vendor.req_canceled) {
30396 dev_err(chip->dev, "Operation Canceled\n");
30397 rc = -ECANCELED;
30398 goto out;
30399 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
30400 index 56051d0..11cf3b7 100644
30401 --- a/drivers/char/tpm/tpm_acpi.c
30402 +++ b/drivers/char/tpm/tpm_acpi.c
30403 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
30404 virt = acpi_os_map_memory(start, len);
30405 if (!virt) {
30406 kfree(log->bios_event_log);
30407 + log->bios_event_log = NULL;
30408 printk("%s: ERROR - Unable to map memory\n", __func__);
30409 return -EIO;
30410 }
30411
30412 - memcpy_fromio(log->bios_event_log, virt, len);
30413 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
30414
30415 acpi_os_unmap_memory(virt, len);
30416 return 0;
30417 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
30418 index 84ddc55..1d32f1e 100644
30419 --- a/drivers/char/tpm/tpm_eventlog.c
30420 +++ b/drivers/char/tpm/tpm_eventlog.c
30421 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30422 event = addr;
30423
30424 if ((event->event_type == 0 && event->event_size == 0) ||
30425 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30426 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30427 return NULL;
30428
30429 return addr;
30430 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30431 return NULL;
30432
30433 if ((event->event_type == 0 && event->event_size == 0) ||
30434 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30435 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30436 return NULL;
30437
30438 (*pos)++;
30439 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30440 int i;
30441
30442 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30443 - seq_putc(m, data[i]);
30444 + if (!seq_putc(m, data[i]))
30445 + return -EFAULT;
30446
30447 return 0;
30448 }
30449 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30450 index 8ab9c3d..c3e65d3 100644
30451 --- a/drivers/char/virtio_console.c
30452 +++ b/drivers/char/virtio_console.c
30453 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30454 if (to_user) {
30455 ssize_t ret;
30456
30457 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30458 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30459 if (ret)
30460 return -EFAULT;
30461 } else {
30462 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30463 if (!port_has_data(port) && !port->host_connected)
30464 return 0;
30465
30466 - return fill_readbuf(port, ubuf, count, true);
30467 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30468 }
30469
30470 static int wait_port_writable(struct port *port, bool nonblock)
30471 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30472 index e164c55..3aabb50 100644
30473 --- a/drivers/edac/edac_pci_sysfs.c
30474 +++ b/drivers/edac/edac_pci_sysfs.c
30475 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30476 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30477 static int edac_pci_poll_msec = 1000; /* one second workq period */
30478
30479 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30480 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30481 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30482 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30483
30484 static struct kobject *edac_pci_top_main_kobj;
30485 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30486 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30487 edac_printk(KERN_CRIT, EDAC_PCI,
30488 "Signaled System Error on %s\n",
30489 pci_name(dev));
30490 - atomic_inc(&pci_nonparity_count);
30491 + atomic_inc_unchecked(&pci_nonparity_count);
30492 }
30493
30494 if (status & (PCI_STATUS_PARITY)) {
30495 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30496 "Master Data Parity Error on %s\n",
30497 pci_name(dev));
30498
30499 - atomic_inc(&pci_parity_count);
30500 + atomic_inc_unchecked(&pci_parity_count);
30501 }
30502
30503 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30504 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30505 "Detected Parity Error on %s\n",
30506 pci_name(dev));
30507
30508 - atomic_inc(&pci_parity_count);
30509 + atomic_inc_unchecked(&pci_parity_count);
30510 }
30511 }
30512
30513 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30514 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30515 "Signaled System Error on %s\n",
30516 pci_name(dev));
30517 - atomic_inc(&pci_nonparity_count);
30518 + atomic_inc_unchecked(&pci_nonparity_count);
30519 }
30520
30521 if (status & (PCI_STATUS_PARITY)) {
30522 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30523 "Master Data Parity Error on "
30524 "%s\n", pci_name(dev));
30525
30526 - atomic_inc(&pci_parity_count);
30527 + atomic_inc_unchecked(&pci_parity_count);
30528 }
30529
30530 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30531 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30532 "Detected Parity Error on %s\n",
30533 pci_name(dev));
30534
30535 - atomic_inc(&pci_parity_count);
30536 + atomic_inc_unchecked(&pci_parity_count);
30537 }
30538 }
30539 }
30540 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30541 if (!check_pci_errors)
30542 return;
30543
30544 - before_count = atomic_read(&pci_parity_count);
30545 + before_count = atomic_read_unchecked(&pci_parity_count);
30546
30547 /* scan all PCI devices looking for a Parity Error on devices and
30548 * bridges.
30549 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30550 /* Only if operator has selected panic on PCI Error */
30551 if (edac_pci_get_panic_on_pe()) {
30552 /* If the count is different 'after' from 'before' */
30553 - if (before_count != atomic_read(&pci_parity_count))
30554 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30555 panic("EDAC: PCI Parity Error");
30556 }
30557 }
30558 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30559 index 8c87a5e..a19cbd7 100644
30560 --- a/drivers/edac/mce_amd.h
30561 +++ b/drivers/edac/mce_amd.h
30562 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30563 struct amd_decoder_ops {
30564 bool (*dc_mce)(u16, u8);
30565 bool (*ic_mce)(u16, u8);
30566 -};
30567 +} __no_const;
30568
30569 void amd_report_gart_errors(bool);
30570 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30571 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30572 index 57ea7f4..789e3c3 100644
30573 --- a/drivers/firewire/core-card.c
30574 +++ b/drivers/firewire/core-card.c
30575 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30576
30577 void fw_core_remove_card(struct fw_card *card)
30578 {
30579 - struct fw_card_driver dummy_driver = dummy_driver_template;
30580 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30581
30582 card->driver->update_phy_reg(card, 4,
30583 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30584 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30585 index f8d2287..5aaf4db 100644
30586 --- a/drivers/firewire/core-cdev.c
30587 +++ b/drivers/firewire/core-cdev.c
30588 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30589 int ret;
30590
30591 if ((request->channels == 0 && request->bandwidth == 0) ||
30592 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30593 - request->bandwidth < 0)
30594 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30595 return -EINVAL;
30596
30597 r = kmalloc(sizeof(*r), GFP_KERNEL);
30598 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30599 index 28a94c7..58da63a 100644
30600 --- a/drivers/firewire/core-transaction.c
30601 +++ b/drivers/firewire/core-transaction.c
30602 @@ -38,6 +38,7 @@
30603 #include <linux/timer.h>
30604 #include <linux/types.h>
30605 #include <linux/workqueue.h>
30606 +#include <linux/sched.h>
30607
30608 #include <asm/byteorder.h>
30609
30610 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30611 index 515a42c..5ecf3ba 100644
30612 --- a/drivers/firewire/core.h
30613 +++ b/drivers/firewire/core.h
30614 @@ -111,6 +111,7 @@ struct fw_card_driver {
30615
30616 int (*stop_iso)(struct fw_iso_context *ctx);
30617 };
30618 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30619
30620 void fw_card_initialize(struct fw_card *card,
30621 const struct fw_card_driver *driver, struct device *device);
30622 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30623 index b298158..7ed8432 100644
30624 --- a/drivers/firmware/dmi_scan.c
30625 +++ b/drivers/firmware/dmi_scan.c
30626 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30627 }
30628 }
30629 else {
30630 - /*
30631 - * no iounmap() for that ioremap(); it would be a no-op, but
30632 - * it's so early in setup that sucker gets confused into doing
30633 - * what it shouldn't if we actually call it.
30634 - */
30635 p = dmi_ioremap(0xF0000, 0x10000);
30636 if (p == NULL)
30637 goto error;
30638 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30639 if (buf == NULL)
30640 return -1;
30641
30642 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30643 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30644
30645 iounmap(buf);
30646 return 0;
30647 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30648 index 82d5c20..44a7177 100644
30649 --- a/drivers/gpio/gpio-vr41xx.c
30650 +++ b/drivers/gpio/gpio-vr41xx.c
30651 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30652 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30653 maskl, pendl, maskh, pendh);
30654
30655 - atomic_inc(&irq_err_count);
30656 + atomic_inc_unchecked(&irq_err_count);
30657
30658 return -EINVAL;
30659 }
30660 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30661 index 1227adf..f2301c2 100644
30662 --- a/drivers/gpu/drm/drm_crtc_helper.c
30663 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30664 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30665 struct drm_crtc *tmp;
30666 int crtc_mask = 1;
30667
30668 - WARN(!crtc, "checking null crtc?\n");
30669 + BUG_ON(!crtc);
30670
30671 dev = crtc->dev;
30672
30673 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30674 index be174ca..0bcbb71 100644
30675 --- a/drivers/gpu/drm/drm_drv.c
30676 +++ b/drivers/gpu/drm/drm_drv.c
30677 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30678 /**
30679 * Copy and IOCTL return string to user space
30680 */
30681 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30682 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30683 {
30684 int len;
30685
30686 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30687 return -ENODEV;
30688
30689 atomic_inc(&dev->ioctl_count);
30690 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30691 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30692 ++file_priv->ioctl_count;
30693
30694 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30695 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30696 index 133b413..fd68225 100644
30697 --- a/drivers/gpu/drm/drm_fops.c
30698 +++ b/drivers/gpu/drm/drm_fops.c
30699 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30700 }
30701
30702 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30703 - atomic_set(&dev->counts[i], 0);
30704 + atomic_set_unchecked(&dev->counts[i], 0);
30705
30706 dev->sigdata.lock = NULL;
30707
30708 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30709 if (drm_device_is_unplugged(dev))
30710 return -ENODEV;
30711
30712 - if (!dev->open_count++)
30713 + if (local_inc_return(&dev->open_count) == 1)
30714 need_setup = 1;
30715 mutex_lock(&dev->struct_mutex);
30716 old_mapping = dev->dev_mapping;
30717 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30718 retcode = drm_open_helper(inode, filp, dev);
30719 if (retcode)
30720 goto err_undo;
30721 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30722 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30723 if (need_setup) {
30724 retcode = drm_setup(dev);
30725 if (retcode)
30726 @@ -164,7 +164,7 @@ err_undo:
30727 iput(container_of(dev->dev_mapping, struct inode, i_data));
30728 dev->dev_mapping = old_mapping;
30729 mutex_unlock(&dev->struct_mutex);
30730 - dev->open_count--;
30731 + local_dec(&dev->open_count);
30732 return retcode;
30733 }
30734 EXPORT_SYMBOL(drm_open);
30735 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30736
30737 mutex_lock(&drm_global_mutex);
30738
30739 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30740 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30741
30742 if (dev->driver->preclose)
30743 dev->driver->preclose(dev, file_priv);
30744 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30745 * Begin inline drm_release
30746 */
30747
30748 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30749 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30750 task_pid_nr(current),
30751 (long)old_encode_dev(file_priv->minor->device),
30752 - dev->open_count);
30753 + local_read(&dev->open_count));
30754
30755 /* Release any auth tokens that might point to this file_priv,
30756 (do that under the drm_global_mutex) */
30757 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
30758 * End inline drm_release
30759 */
30760
30761 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30762 - if (!--dev->open_count) {
30763 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30764 + if (local_dec_and_test(&dev->open_count)) {
30765 if (atomic_read(&dev->ioctl_count)) {
30766 DRM_ERROR("Device busy: %d\n",
30767 atomic_read(&dev->ioctl_count));
30768 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30769 index f731116..629842c 100644
30770 --- a/drivers/gpu/drm/drm_global.c
30771 +++ b/drivers/gpu/drm/drm_global.c
30772 @@ -36,7 +36,7 @@
30773 struct drm_global_item {
30774 struct mutex mutex;
30775 void *object;
30776 - int refcount;
30777 + atomic_t refcount;
30778 };
30779
30780 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30781 @@ -49,7 +49,7 @@ void drm_global_init(void)
30782 struct drm_global_item *item = &glob[i];
30783 mutex_init(&item->mutex);
30784 item->object = NULL;
30785 - item->refcount = 0;
30786 + atomic_set(&item->refcount, 0);
30787 }
30788 }
30789
30790 @@ -59,7 +59,7 @@ void drm_global_release(void)
30791 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30792 struct drm_global_item *item = &glob[i];
30793 BUG_ON(item->object != NULL);
30794 - BUG_ON(item->refcount != 0);
30795 + BUG_ON(atomic_read(&item->refcount) != 0);
30796 }
30797 }
30798
30799 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30800 void *object;
30801
30802 mutex_lock(&item->mutex);
30803 - if (item->refcount == 0) {
30804 + if (atomic_read(&item->refcount) == 0) {
30805 item->object = kzalloc(ref->size, GFP_KERNEL);
30806 if (unlikely(item->object == NULL)) {
30807 ret = -ENOMEM;
30808 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30809 goto out_err;
30810
30811 }
30812 - ++item->refcount;
30813 + atomic_inc(&item->refcount);
30814 ref->object = item->object;
30815 object = item->object;
30816 mutex_unlock(&item->mutex);
30817 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30818 struct drm_global_item *item = &glob[ref->global_type];
30819
30820 mutex_lock(&item->mutex);
30821 - BUG_ON(item->refcount == 0);
30822 + BUG_ON(atomic_read(&item->refcount) == 0);
30823 BUG_ON(ref->object != item->object);
30824 - if (--item->refcount == 0) {
30825 + if (atomic_dec_and_test(&item->refcount)) {
30826 ref->release(ref);
30827 item->object = NULL;
30828 }
30829 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30830 index d4b20ce..77a8d41 100644
30831 --- a/drivers/gpu/drm/drm_info.c
30832 +++ b/drivers/gpu/drm/drm_info.c
30833 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30834 struct drm_local_map *map;
30835 struct drm_map_list *r_list;
30836
30837 - /* Hardcoded from _DRM_FRAME_BUFFER,
30838 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30839 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30840 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30841 + static const char * const types[] = {
30842 + [_DRM_FRAME_BUFFER] = "FB",
30843 + [_DRM_REGISTERS] = "REG",
30844 + [_DRM_SHM] = "SHM",
30845 + [_DRM_AGP] = "AGP",
30846 + [_DRM_SCATTER_GATHER] = "SG",
30847 + [_DRM_CONSISTENT] = "PCI",
30848 + [_DRM_GEM] = "GEM" };
30849 const char *type;
30850 int i;
30851
30852 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30853 map = r_list->map;
30854 if (!map)
30855 continue;
30856 - if (map->type < 0 || map->type > 5)
30857 + if (map->type >= ARRAY_SIZE(types))
30858 type = "??";
30859 else
30860 type = types[map->type];
30861 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30862 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30863 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30864 vma->vm_flags & VM_IO ? 'i' : '-',
30865 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30866 + 0);
30867 +#else
30868 vma->vm_pgoff);
30869 +#endif
30870
30871 #if defined(__i386__)
30872 pgprot = pgprot_val(vma->vm_page_prot);
30873 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30874 index 2f4c434..764794b 100644
30875 --- a/drivers/gpu/drm/drm_ioc32.c
30876 +++ b/drivers/gpu/drm/drm_ioc32.c
30877 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30878 request = compat_alloc_user_space(nbytes);
30879 if (!access_ok(VERIFY_WRITE, request, nbytes))
30880 return -EFAULT;
30881 - list = (struct drm_buf_desc *) (request + 1);
30882 + list = (struct drm_buf_desc __user *) (request + 1);
30883
30884 if (__put_user(count, &request->count)
30885 || __put_user(list, &request->list))
30886 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30887 request = compat_alloc_user_space(nbytes);
30888 if (!access_ok(VERIFY_WRITE, request, nbytes))
30889 return -EFAULT;
30890 - list = (struct drm_buf_pub *) (request + 1);
30891 + list = (struct drm_buf_pub __user *) (request + 1);
30892
30893 if (__put_user(count, &request->count)
30894 || __put_user(list, &request->list))
30895 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30896 index 23dd975..63e9801 100644
30897 --- a/drivers/gpu/drm/drm_ioctl.c
30898 +++ b/drivers/gpu/drm/drm_ioctl.c
30899 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30900 stats->data[i].value =
30901 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30902 else
30903 - stats->data[i].value = atomic_read(&dev->counts[i]);
30904 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30905 stats->data[i].type = dev->types[i];
30906 }
30907
30908 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30909 index d752c96..fe08455 100644
30910 --- a/drivers/gpu/drm/drm_lock.c
30911 +++ b/drivers/gpu/drm/drm_lock.c
30912 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30913 if (drm_lock_take(&master->lock, lock->context)) {
30914 master->lock.file_priv = file_priv;
30915 master->lock.lock_time = jiffies;
30916 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30917 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30918 break; /* Got lock */
30919 }
30920
30921 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30922 return -EINVAL;
30923 }
30924
30925 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30926 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30927
30928 if (drm_lock_free(&master->lock, lock->context)) {
30929 /* FIXME: Should really bail out here. */
30930 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30931 index c236fd2..6b5f2e7 100644
30932 --- a/drivers/gpu/drm/drm_stub.c
30933 +++ b/drivers/gpu/drm/drm_stub.c
30934 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30935
30936 drm_device_set_unplugged(dev);
30937
30938 - if (dev->open_count == 0) {
30939 + if (local_read(&dev->open_count) == 0) {
30940 drm_put_dev(dev);
30941 }
30942 mutex_unlock(&drm_global_mutex);
30943 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30944 index 004ecdf..db1f6e0 100644
30945 --- a/drivers/gpu/drm/i810/i810_dma.c
30946 +++ b/drivers/gpu/drm/i810/i810_dma.c
30947 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30948 dma->buflist[vertex->idx],
30949 vertex->discard, vertex->used);
30950
30951 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30952 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30953 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30954 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30955 sarea_priv->last_enqueue = dev_priv->counter - 1;
30956 sarea_priv->last_dispatch = (int)hw_status[5];
30957
30958 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30959 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30960 mc->last_render);
30961
30962 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30963 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30964 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30965 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30966 sarea_priv->last_enqueue = dev_priv->counter - 1;
30967 sarea_priv->last_dispatch = (int)hw_status[5];
30968
30969 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30970 index 6e0acad..93c8289 100644
30971 --- a/drivers/gpu/drm/i810/i810_drv.h
30972 +++ b/drivers/gpu/drm/i810/i810_drv.h
30973 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30974 int page_flipping;
30975
30976 wait_queue_head_t irq_queue;
30977 - atomic_t irq_received;
30978 - atomic_t irq_emitted;
30979 + atomic_unchecked_t irq_received;
30980 + atomic_unchecked_t irq_emitted;
30981
30982 int front_offset;
30983 } drm_i810_private_t;
30984 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30985 index dde8b50..da88e32 100644
30986 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30987 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30988 @@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30989 I915_READ(GTIMR));
30990 }
30991 seq_printf(m, "Interrupts received: %d\n",
30992 - atomic_read(&dev_priv->irq_received));
30993 + atomic_read_unchecked(&dev_priv->irq_received));
30994 for_each_ring(ring, dev_priv, i) {
30995 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30996 seq_printf(m,
30997 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30998 index 61ae104..f8a4bc1 100644
30999 --- a/drivers/gpu/drm/i915/i915_dma.c
31000 +++ b/drivers/gpu/drm/i915/i915_dma.c
31001 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
31002 bool can_switch;
31003
31004 spin_lock(&dev->count_lock);
31005 - can_switch = (dev->open_count == 0);
31006 + can_switch = (local_read(&dev->open_count) == 0);
31007 spin_unlock(&dev->count_lock);
31008 return can_switch;
31009 }
31010 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
31011 index f511fa2..4c11773 100644
31012 --- a/drivers/gpu/drm/i915/i915_drv.h
31013 +++ b/drivers/gpu/drm/i915/i915_drv.h
31014 @@ -274,12 +274,12 @@ struct drm_i915_display_funcs {
31015 /* render clock increase/decrease */
31016 /* display clock increase/decrease */
31017 /* pll clock increase/decrease */
31018 -};
31019 +} __no_const;
31020
31021 struct drm_i915_gt_funcs {
31022 void (*force_wake_get)(struct drm_i915_private *dev_priv);
31023 void (*force_wake_put)(struct drm_i915_private *dev_priv);
31024 -};
31025 +} __no_const;
31026
31027 #define DEV_INFO_FLAGS \
31028 DEV_INFO_FLAG(is_mobile) DEV_INFO_SEP \
31029 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
31030
31031 struct resource mch_res;
31032
31033 - atomic_t irq_received;
31034 + atomic_unchecked_t irq_received;
31035
31036 /* protects the irq masks */
31037 spinlock_t irq_lock;
31038 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
31039 * will be page flipped away on the next vblank. When it
31040 * reaches 0, dev_priv->pending_flip_queue will be woken up.
31041 */
31042 - atomic_t pending_flip;
31043 + atomic_unchecked_t pending_flip;
31044 };
31045
31046 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
31047 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
31048 struct drm_i915_private *dev_priv, unsigned port);
31049 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
31050 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
31051 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31052 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31053 {
31054 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
31055 }
31056 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31057 index 3eea143..a0b77db 100644
31058 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31059 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31060 @@ -660,7 +660,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
31061 i915_gem_clflush_object(obj);
31062
31063 if (obj->base.pending_write_domain)
31064 - flips |= atomic_read(&obj->pending_flip);
31065 + flips |= atomic_read_unchecked(&obj->pending_flip);
31066
31067 flush_domains |= obj->base.write_domain;
31068 }
31069 @@ -691,9 +691,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
31070
31071 static int
31072 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
31073 - int count)
31074 + unsigned int count)
31075 {
31076 - int i;
31077 + unsigned int i;
31078
31079 for (i = 0; i < count; i++) {
31080 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
31081 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
31082 index 32e1bda..9b2ca91 100644
31083 --- a/drivers/gpu/drm/i915/i915_irq.c
31084 +++ b/drivers/gpu/drm/i915/i915_irq.c
31085 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
31086 u32 pipe_stats[I915_MAX_PIPES];
31087 bool blc_event;
31088
31089 - atomic_inc(&dev_priv->irq_received);
31090 + atomic_inc_unchecked(&dev_priv->irq_received);
31091
31092 while (true) {
31093 iir = I915_READ(VLV_IIR);
31094 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31095 irqreturn_t ret = IRQ_NONE;
31096 int i;
31097
31098 - atomic_inc(&dev_priv->irq_received);
31099 + atomic_inc_unchecked(&dev_priv->irq_received);
31100
31101 /* disable master interrupt before clearing iir */
31102 de_ier = I915_READ(DEIER);
31103 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31104 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31105 u32 hotplug_mask;
31106
31107 - atomic_inc(&dev_priv->irq_received);
31108 + atomic_inc_unchecked(&dev_priv->irq_received);
31109
31110 /* disable master interrupt before clearing iir */
31111 de_ier = I915_READ(DEIER);
31112 @@ -1760,7 +1760,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31113 {
31114 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31115
31116 - atomic_set(&dev_priv->irq_received, 0);
31117 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31118
31119 I915_WRITE(HWSTAM, 0xeffe);
31120
31121 @@ -1786,7 +1786,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31122 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31123 int pipe;
31124
31125 - atomic_set(&dev_priv->irq_received, 0);
31126 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31127
31128 /* VLV magic */
31129 I915_WRITE(VLV_IMR, 0);
31130 @@ -2091,7 +2091,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31131 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31132 int pipe;
31133
31134 - atomic_set(&dev_priv->irq_received, 0);
31135 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31136
31137 for_each_pipe(pipe)
31138 I915_WRITE(PIPESTAT(pipe), 0);
31139 @@ -2142,7 +2142,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31140 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31141 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31142
31143 - atomic_inc(&dev_priv->irq_received);
31144 + atomic_inc_unchecked(&dev_priv->irq_received);
31145
31146 iir = I915_READ16(IIR);
31147 if (iir == 0)
31148 @@ -2227,7 +2227,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31149 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31150 int pipe;
31151
31152 - atomic_set(&dev_priv->irq_received, 0);
31153 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31154
31155 if (I915_HAS_HOTPLUG(dev)) {
31156 I915_WRITE(PORT_HOTPLUG_EN, 0);
31157 @@ -2322,7 +2322,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31158 };
31159 int pipe, ret = IRQ_NONE;
31160
31161 - atomic_inc(&dev_priv->irq_received);
31162 + atomic_inc_unchecked(&dev_priv->irq_received);
31163
31164 iir = I915_READ(IIR);
31165 do {
31166 @@ -2448,7 +2448,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31167 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31168 int pipe;
31169
31170 - atomic_set(&dev_priv->irq_received, 0);
31171 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31172
31173 I915_WRITE(PORT_HOTPLUG_EN, 0);
31174 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31175 @@ -2555,7 +2555,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31176 int irq_received;
31177 int ret = IRQ_NONE, pipe;
31178
31179 - atomic_inc(&dev_priv->irq_received);
31180 + atomic_inc_unchecked(&dev_priv->irq_received);
31181
31182 iir = I915_READ(IIR);
31183
31184 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31185 index b426d44..1b9038d 100644
31186 --- a/drivers/gpu/drm/i915/intel_display.c
31187 +++ b/drivers/gpu/drm/i915/intel_display.c
31188 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31189
31190 wait_event(dev_priv->pending_flip_queue,
31191 atomic_read(&dev_priv->mm.wedged) ||
31192 - atomic_read(&obj->pending_flip) == 0);
31193 + atomic_read_unchecked(&obj->pending_flip) == 0);
31194
31195 /* Big Hammer, we also need to ensure that any pending
31196 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31197 @@ -6236,8 +6236,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31198
31199 obj = work->old_fb_obj;
31200
31201 - atomic_clear_mask(1 << intel_crtc->plane,
31202 - &obj->pending_flip.counter);
31203 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31204
31205 wake_up(&dev_priv->pending_flip_queue);
31206 schedule_work(&work->work);
31207 @@ -6583,7 +6582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31208 /* Block clients from rendering to the new back buffer until
31209 * the flip occurs and the object is no longer visible.
31210 */
31211 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31212 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31213
31214 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31215 if (ret)
31216 @@ -6598,7 +6597,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31217 return 0;
31218
31219 cleanup_pending:
31220 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31221 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31222 drm_gem_object_unreference(&work->old_fb_obj->base);
31223 drm_gem_object_unreference(&obj->base);
31224 mutex_unlock(&dev->struct_mutex);
31225 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31226 index 54558a0..2d97005 100644
31227 --- a/drivers/gpu/drm/mga/mga_drv.h
31228 +++ b/drivers/gpu/drm/mga/mga_drv.h
31229 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31230 u32 clear_cmd;
31231 u32 maccess;
31232
31233 - atomic_t vbl_received; /**< Number of vblanks received. */
31234 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31235 wait_queue_head_t fence_queue;
31236 - atomic_t last_fence_retired;
31237 + atomic_unchecked_t last_fence_retired;
31238 u32 next_fence_to_post;
31239
31240 unsigned int fb_cpp;
31241 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31242 index 598c281..60d590e 100644
31243 --- a/drivers/gpu/drm/mga/mga_irq.c
31244 +++ b/drivers/gpu/drm/mga/mga_irq.c
31245 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31246 if (crtc != 0)
31247 return 0;
31248
31249 - return atomic_read(&dev_priv->vbl_received);
31250 + return atomic_read_unchecked(&dev_priv->vbl_received);
31251 }
31252
31253
31254 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31255 /* VBLANK interrupt */
31256 if (status & MGA_VLINEPEN) {
31257 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31258 - atomic_inc(&dev_priv->vbl_received);
31259 + atomic_inc_unchecked(&dev_priv->vbl_received);
31260 drm_handle_vblank(dev, 0);
31261 handled = 1;
31262 }
31263 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31264 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31265 MGA_WRITE(MGA_PRIMEND, prim_end);
31266
31267 - atomic_inc(&dev_priv->last_fence_retired);
31268 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31269 DRM_WAKEUP(&dev_priv->fence_queue);
31270 handled = 1;
31271 }
31272 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31273 * using fences.
31274 */
31275 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31276 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31277 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31278 - *sequence) <= (1 << 23)));
31279
31280 *sequence = cur_fence;
31281 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31282 index 09fdef2..57f5c3b 100644
31283 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31284 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31285 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31286 struct bit_table {
31287 const char id;
31288 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31289 -};
31290 +} __no_const;
31291
31292 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31293
31294 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
31295 index a101699..a163f0a 100644
31296 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
31297 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
31298 @@ -80,7 +80,7 @@ struct nouveau_drm {
31299 struct drm_global_reference mem_global_ref;
31300 struct ttm_bo_global_ref bo_global_ref;
31301 struct ttm_bo_device bdev;
31302 - atomic_t validate_sequence;
31303 + atomic_unchecked_t validate_sequence;
31304 int (*move)(struct nouveau_channel *,
31305 struct ttm_buffer_object *,
31306 struct ttm_mem_reg *, struct ttm_mem_reg *);
31307 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
31308 index bedafd1..ca5330a 100644
31309 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
31310 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
31311 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
31312 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
31313 struct nouveau_channel *);
31314 u32 (*read)(struct nouveau_channel *);
31315 -};
31316 +} __no_const;
31317
31318 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
31319
31320 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31321 index 5e2f521..0d21436 100644
31322 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31323 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31324 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31325 int trycnt = 0;
31326 int ret, i;
31327
31328 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
31329 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
31330 retry:
31331 if (++trycnt > 100000) {
31332 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
31333 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
31334 index 6f0ac64..9c2dfb4 100644
31335 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
31336 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
31337 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31338 bool can_switch;
31339
31340 spin_lock(&dev->count_lock);
31341 - can_switch = (dev->open_count == 0);
31342 + can_switch = (local_read(&dev->open_count) == 0);
31343 spin_unlock(&dev->count_lock);
31344 return can_switch;
31345 }
31346 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
31347 index 9f6f55c..30e3a29 100644
31348 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
31349 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
31350 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
31351 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
31352 evo->object->oclass->ofuncs =
31353 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
31354 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
31355 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
31356 - evo->object->oclass->ofuncs->rd08 =
31357 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
31358 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
31359 + *(void**)&evo->object->oclass->ofuncs->rd08 =
31360 ioremap(pci_resource_start(dev->pdev, 0) +
31361 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
31362 return 0;
31363 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31364 index b562b59..9d725a8 100644
31365 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31366 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31367 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31368 }
31369
31370 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
31371 - struct dp_train_func func = {
31372 + static struct dp_train_func func = {
31373 .link_set = nv50_sor_dp_link_set,
31374 .train_set = nv50_sor_dp_train_set,
31375 .train_adj = nv50_sor_dp_train_adj
31376 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31377 index c402fca..f1d694b 100644
31378 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31379 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31380 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31381 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31382
31383 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
31384 - struct dp_train_func func = {
31385 + static struct dp_train_func func = {
31386 .link_set = nvd0_sor_dp_link_set,
31387 .train_set = nvd0_sor_dp_train_set,
31388 .train_adj = nvd0_sor_dp_train_adj
31389 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31390 index d4660cf..70dbe65 100644
31391 --- a/drivers/gpu/drm/r128/r128_cce.c
31392 +++ b/drivers/gpu/drm/r128/r128_cce.c
31393 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31394
31395 /* GH: Simple idle check.
31396 */
31397 - atomic_set(&dev_priv->idle_count, 0);
31398 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31399
31400 /* We don't support anything other than bus-mastering ring mode,
31401 * but the ring can be in either AGP or PCI space for the ring
31402 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31403 index 930c71b..499aded 100644
31404 --- a/drivers/gpu/drm/r128/r128_drv.h
31405 +++ b/drivers/gpu/drm/r128/r128_drv.h
31406 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31407 int is_pci;
31408 unsigned long cce_buffers_offset;
31409
31410 - atomic_t idle_count;
31411 + atomic_unchecked_t idle_count;
31412
31413 int page_flipping;
31414 int current_page;
31415 u32 crtc_offset;
31416 u32 crtc_offset_cntl;
31417
31418 - atomic_t vbl_received;
31419 + atomic_unchecked_t vbl_received;
31420
31421 u32 color_fmt;
31422 unsigned int front_offset;
31423 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31424 index 2ea4f09..d391371 100644
31425 --- a/drivers/gpu/drm/r128/r128_irq.c
31426 +++ b/drivers/gpu/drm/r128/r128_irq.c
31427 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31428 if (crtc != 0)
31429 return 0;
31430
31431 - return atomic_read(&dev_priv->vbl_received);
31432 + return atomic_read_unchecked(&dev_priv->vbl_received);
31433 }
31434
31435 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31436 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31437 /* VBLANK interrupt */
31438 if (status & R128_CRTC_VBLANK_INT) {
31439 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31440 - atomic_inc(&dev_priv->vbl_received);
31441 + atomic_inc_unchecked(&dev_priv->vbl_received);
31442 drm_handle_vblank(dev, 0);
31443 return IRQ_HANDLED;
31444 }
31445 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31446 index 19bb7e6..de7e2a2 100644
31447 --- a/drivers/gpu/drm/r128/r128_state.c
31448 +++ b/drivers/gpu/drm/r128/r128_state.c
31449 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31450
31451 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31452 {
31453 - if (atomic_read(&dev_priv->idle_count) == 0)
31454 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31455 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31456 else
31457 - atomic_set(&dev_priv->idle_count, 0);
31458 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31459 }
31460
31461 #endif
31462 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31463 index 5a82b6b..9e69c73 100644
31464 --- a/drivers/gpu/drm/radeon/mkregtable.c
31465 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31466 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31467 regex_t mask_rex;
31468 regmatch_t match[4];
31469 char buf[1024];
31470 - size_t end;
31471 + long end;
31472 int len;
31473 int done = 0;
31474 int r;
31475 unsigned o;
31476 struct offset *offset;
31477 char last_reg_s[10];
31478 - int last_reg;
31479 + unsigned long last_reg;
31480
31481 if (regcomp
31482 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31483 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31484 index 8c42d54..5ef3789 100644
31485 --- a/drivers/gpu/drm/radeon/radeon.h
31486 +++ b/drivers/gpu/drm/radeon/radeon.h
31487 @@ -728,7 +728,7 @@ struct r600_blit_cp_primitives {
31488 int x2, int y2);
31489 void (*draw_auto)(struct radeon_device *rdev);
31490 void (*set_default_state)(struct radeon_device *rdev);
31491 -};
31492 +} __no_const;
31493
31494 struct r600_blit {
31495 struct radeon_bo *shader_obj;
31496 @@ -1248,7 +1248,7 @@ struct radeon_asic {
31497 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31498 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31499 } pflip;
31500 -};
31501 +} __no_const;
31502
31503 /*
31504 * Asic structures
31505 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31506 index e2f5f88..82f22da 100644
31507 --- a/drivers/gpu/drm/radeon/radeon_device.c
31508 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31509 @@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31510 bool can_switch;
31511
31512 spin_lock(&dev->count_lock);
31513 - can_switch = (dev->open_count == 0);
31514 + can_switch = (local_read(&dev->open_count) == 0);
31515 spin_unlock(&dev->count_lock);
31516 return can_switch;
31517 }
31518 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31519 index a1b59ca..86f2d44 100644
31520 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31521 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31522 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31523
31524 /* SW interrupt */
31525 wait_queue_head_t swi_queue;
31526 - atomic_t swi_emitted;
31527 + atomic_unchecked_t swi_emitted;
31528 int vblank_crtc;
31529 uint32_t irq_enable_reg;
31530 uint32_t r500_disp_irq_reg;
31531 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31532 index c180df8..cd80dd2d 100644
31533 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31534 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31535 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31536 request = compat_alloc_user_space(sizeof(*request));
31537 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31538 || __put_user(req32.param, &request->param)
31539 - || __put_user((void __user *)(unsigned long)req32.value,
31540 + || __put_user((unsigned long)req32.value,
31541 &request->value))
31542 return -EFAULT;
31543
31544 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31545 index e771033..a0bc6b3 100644
31546 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31547 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31548 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31549 unsigned int ret;
31550 RING_LOCALS;
31551
31552 - atomic_inc(&dev_priv->swi_emitted);
31553 - ret = atomic_read(&dev_priv->swi_emitted);
31554 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31555 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31556
31557 BEGIN_RING(4);
31558 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31559 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31560 drm_radeon_private_t *dev_priv =
31561 (drm_radeon_private_t *) dev->dev_private;
31562
31563 - atomic_set(&dev_priv->swi_emitted, 0);
31564 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31565 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31566
31567 dev->max_vblank_count = 0x001fffff;
31568 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31569 index 8e9057b..af6dacb 100644
31570 --- a/drivers/gpu/drm/radeon/radeon_state.c
31571 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31572 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31573 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31574 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31575
31576 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31577 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31578 sarea_priv->nbox * sizeof(depth_boxes[0])))
31579 return -EFAULT;
31580
31581 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31582 {
31583 drm_radeon_private_t *dev_priv = dev->dev_private;
31584 drm_radeon_getparam_t *param = data;
31585 - int value;
31586 + int value = 0;
31587
31588 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31589
31590 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31591 index 5ebe1b3..1ed9426 100644
31592 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31593 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31594 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31595 }
31596 if (unlikely(ttm_vm_ops == NULL)) {
31597 ttm_vm_ops = vma->vm_ops;
31598 - radeon_ttm_vm_ops = *ttm_vm_ops;
31599 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31600 + pax_open_kernel();
31601 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31602 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31603 + pax_close_kernel();
31604 }
31605 vma->vm_ops = &radeon_ttm_vm_ops;
31606 return 0;
31607 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31608 index 5706d2a..17aedaa 100644
31609 --- a/drivers/gpu/drm/radeon/rs690.c
31610 +++ b/drivers/gpu/drm/radeon/rs690.c
31611 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31612 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31613 rdev->pm.sideport_bandwidth.full)
31614 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31615 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31616 + read_delay_latency.full = dfixed_const(800 * 1000);
31617 read_delay_latency.full = dfixed_div(read_delay_latency,
31618 rdev->pm.igp_sideport_mclk);
31619 + a.full = dfixed_const(370);
31620 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31621 } else {
31622 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31623 rdev->pm.k8_bandwidth.full)
31624 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31625 index bd2a3b4..122d9ad 100644
31626 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31627 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31628 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31629 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31630 struct shrink_control *sc)
31631 {
31632 - static atomic_t start_pool = ATOMIC_INIT(0);
31633 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31634 unsigned i;
31635 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31636 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31637 struct ttm_page_pool *pool;
31638 int shrink_pages = sc->nr_to_scan;
31639
31640 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31641 index 893a650..6190d3b 100644
31642 --- a/drivers/gpu/drm/via/via_drv.h
31643 +++ b/drivers/gpu/drm/via/via_drv.h
31644 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31645 typedef uint32_t maskarray_t[5];
31646
31647 typedef struct drm_via_irq {
31648 - atomic_t irq_received;
31649 + atomic_unchecked_t irq_received;
31650 uint32_t pending_mask;
31651 uint32_t enable_mask;
31652 wait_queue_head_t irq_queue;
31653 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31654 struct timeval last_vblank;
31655 int last_vblank_valid;
31656 unsigned usec_per_vblank;
31657 - atomic_t vbl_received;
31658 + atomic_unchecked_t vbl_received;
31659 drm_via_state_t hc_state;
31660 char pci_buf[VIA_PCI_BUF_SIZE];
31661 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31662 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31663 index ac98964..5dbf512 100644
31664 --- a/drivers/gpu/drm/via/via_irq.c
31665 +++ b/drivers/gpu/drm/via/via_irq.c
31666 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31667 if (crtc != 0)
31668 return 0;
31669
31670 - return atomic_read(&dev_priv->vbl_received);
31671 + return atomic_read_unchecked(&dev_priv->vbl_received);
31672 }
31673
31674 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31675 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31676
31677 status = VIA_READ(VIA_REG_INTERRUPT);
31678 if (status & VIA_IRQ_VBLANK_PENDING) {
31679 - atomic_inc(&dev_priv->vbl_received);
31680 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31681 + atomic_inc_unchecked(&dev_priv->vbl_received);
31682 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31683 do_gettimeofday(&cur_vblank);
31684 if (dev_priv->last_vblank_valid) {
31685 dev_priv->usec_per_vblank =
31686 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31687 dev_priv->last_vblank = cur_vblank;
31688 dev_priv->last_vblank_valid = 1;
31689 }
31690 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31691 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31692 DRM_DEBUG("US per vblank is: %u\n",
31693 dev_priv->usec_per_vblank);
31694 }
31695 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31696
31697 for (i = 0; i < dev_priv->num_irqs; ++i) {
31698 if (status & cur_irq->pending_mask) {
31699 - atomic_inc(&cur_irq->irq_received);
31700 + atomic_inc_unchecked(&cur_irq->irq_received);
31701 DRM_WAKEUP(&cur_irq->irq_queue);
31702 handled = 1;
31703 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31704 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31705 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31706 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31707 masks[irq][4]));
31708 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31709 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31710 } else {
31711 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31712 (((cur_irq_sequence =
31713 - atomic_read(&cur_irq->irq_received)) -
31714 + atomic_read_unchecked(&cur_irq->irq_received)) -
31715 *sequence) <= (1 << 23)));
31716 }
31717 *sequence = cur_irq_sequence;
31718 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31719 }
31720
31721 for (i = 0; i < dev_priv->num_irqs; ++i) {
31722 - atomic_set(&cur_irq->irq_received, 0);
31723 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31724 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31725 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31726 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31727 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31728 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31729 case VIA_IRQ_RELATIVE:
31730 irqwait->request.sequence +=
31731 - atomic_read(&cur_irq->irq_received);
31732 + atomic_read_unchecked(&cur_irq->irq_received);
31733 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31734 case VIA_IRQ_ABSOLUTE:
31735 break;
31736 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31737 index 88a179e..57fe50481c 100644
31738 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31739 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31740 @@ -263,7 +263,7 @@ struct vmw_private {
31741 * Fencing and IRQs.
31742 */
31743
31744 - atomic_t marker_seq;
31745 + atomic_unchecked_t marker_seq;
31746 wait_queue_head_t fence_queue;
31747 wait_queue_head_t fifo_queue;
31748 int fence_queue_waiters; /* Protected by hw_mutex */
31749 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31750 index 3eb1486..0a47ee9 100644
31751 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31752 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31753 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31754 (unsigned int) min,
31755 (unsigned int) fifo->capabilities);
31756
31757 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31758 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31759 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31760 vmw_marker_queue_init(&fifo->marker_queue);
31761 return vmw_fifo_send_fence(dev_priv, &dummy);
31762 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31763 if (reserveable)
31764 iowrite32(bytes, fifo_mem +
31765 SVGA_FIFO_RESERVED);
31766 - return fifo_mem + (next_cmd >> 2);
31767 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31768 } else {
31769 need_bounce = true;
31770 }
31771 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31772
31773 fm = vmw_fifo_reserve(dev_priv, bytes);
31774 if (unlikely(fm == NULL)) {
31775 - *seqno = atomic_read(&dev_priv->marker_seq);
31776 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31777 ret = -ENOMEM;
31778 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31779 false, 3*HZ);
31780 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31781 }
31782
31783 do {
31784 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31785 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31786 } while (*seqno == 0);
31787
31788 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31789 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31790 index 4640adb..e1384ed 100644
31791 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31792 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31793 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31794 * emitted. Then the fence is stale and signaled.
31795 */
31796
31797 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31798 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31799 > VMW_FENCE_WRAP);
31800
31801 return ret;
31802 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31803
31804 if (fifo_idle)
31805 down_read(&fifo_state->rwsem);
31806 - signal_seq = atomic_read(&dev_priv->marker_seq);
31807 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31808 ret = 0;
31809
31810 for (;;) {
31811 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31812 index 8a8725c..afed796 100644
31813 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31814 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31815 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31816 while (!vmw_lag_lt(queue, us)) {
31817 spin_lock(&queue->lock);
31818 if (list_empty(&queue->head))
31819 - seqno = atomic_read(&dev_priv->marker_seq);
31820 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31821 else {
31822 marker = list_first_entry(&queue->head,
31823 struct vmw_marker, head);
31824 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31825 index f4109fd..7c62889 100644
31826 --- a/drivers/hid/hid-core.c
31827 +++ b/drivers/hid/hid-core.c
31828 @@ -2200,7 +2200,7 @@ static bool hid_ignore(struct hid_device *hdev)
31829
31830 int hid_add_device(struct hid_device *hdev)
31831 {
31832 - static atomic_t id = ATOMIC_INIT(0);
31833 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31834 int ret;
31835
31836 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31837 @@ -2235,7 +2235,7 @@ int hid_add_device(struct hid_device *hdev)
31838 /* XXX hack, any other cleaner solution after the driver core
31839 * is converted to allow more than 20 bytes as the device name? */
31840 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31841 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31842 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31843
31844 hid_debug_register(hdev, dev_name(&hdev->dev));
31845 ret = device_add(&hdev->dev);
31846 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31847 index eec3291..8ed706b 100644
31848 --- a/drivers/hid/hid-wiimote-debug.c
31849 +++ b/drivers/hid/hid-wiimote-debug.c
31850 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31851 else if (size == 0)
31852 return -EIO;
31853
31854 - if (copy_to_user(u, buf, size))
31855 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31856 return -EFAULT;
31857
31858 *off += size;
31859 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31860 index 14599e2..711c965 100644
31861 --- a/drivers/hid/usbhid/hiddev.c
31862 +++ b/drivers/hid/usbhid/hiddev.c
31863 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31864 break;
31865
31866 case HIDIOCAPPLICATION:
31867 - if (arg < 0 || arg >= hid->maxapplication)
31868 + if (arg >= hid->maxapplication)
31869 break;
31870
31871 for (i = 0; i < hid->maxcollection; i++)
31872 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31873 index f4c3d28..82f45a9 100644
31874 --- a/drivers/hv/channel.c
31875 +++ b/drivers/hv/channel.c
31876 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31877 int ret = 0;
31878 int t;
31879
31880 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31881 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31882 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31883 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31884
31885 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31886 if (ret)
31887 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31888 index 3648f8f..30ef30d 100644
31889 --- a/drivers/hv/hv.c
31890 +++ b/drivers/hv/hv.c
31891 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31892 u64 output_address = (output) ? virt_to_phys(output) : 0;
31893 u32 output_address_hi = output_address >> 32;
31894 u32 output_address_lo = output_address & 0xFFFFFFFF;
31895 - void *hypercall_page = hv_context.hypercall_page;
31896 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31897
31898 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31899 "=a"(hv_status_lo) : "d" (control_hi),
31900 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31901 index d8d1fad..b91caf7 100644
31902 --- a/drivers/hv/hyperv_vmbus.h
31903 +++ b/drivers/hv/hyperv_vmbus.h
31904 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
31905 struct vmbus_connection {
31906 enum vmbus_connect_state conn_state;
31907
31908 - atomic_t next_gpadl_handle;
31909 + atomic_unchecked_t next_gpadl_handle;
31910
31911 /*
31912 * Represents channel interrupts. Each bit position represents a
31913 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31914 index 8e1a9ec..4687821 100644
31915 --- a/drivers/hv/vmbus_drv.c
31916 +++ b/drivers/hv/vmbus_drv.c
31917 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31918 {
31919 int ret = 0;
31920
31921 - static atomic_t device_num = ATOMIC_INIT(0);
31922 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31923
31924 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31925 - atomic_inc_return(&device_num));
31926 + atomic_inc_return_unchecked(&device_num));
31927
31928 child_device_obj->device.bus = &hv_bus;
31929 child_device_obj->device.parent = &hv_acpi_dev->dev;
31930 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31931 index 07a0c1a..0cac334 100644
31932 --- a/drivers/hwmon/sht15.c
31933 +++ b/drivers/hwmon/sht15.c
31934 @@ -169,7 +169,7 @@ struct sht15_data {
31935 int supply_uV;
31936 bool supply_uV_valid;
31937 struct work_struct update_supply_work;
31938 - atomic_t interrupt_handled;
31939 + atomic_unchecked_t interrupt_handled;
31940 };
31941
31942 /**
31943 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
31944 return ret;
31945
31946 gpio_direction_input(data->pdata->gpio_data);
31947 - atomic_set(&data->interrupt_handled, 0);
31948 + atomic_set_unchecked(&data->interrupt_handled, 0);
31949
31950 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31951 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31952 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31953 /* Only relevant if the interrupt hasn't occurred. */
31954 - if (!atomic_read(&data->interrupt_handled))
31955 + if (!atomic_read_unchecked(&data->interrupt_handled))
31956 schedule_work(&data->read_work);
31957 }
31958 ret = wait_event_timeout(data->wait_queue,
31959 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31960
31961 /* First disable the interrupt */
31962 disable_irq_nosync(irq);
31963 - atomic_inc(&data->interrupt_handled);
31964 + atomic_inc_unchecked(&data->interrupt_handled);
31965 /* Then schedule a reading work struct */
31966 if (data->state != SHT15_READING_NOTHING)
31967 schedule_work(&data->read_work);
31968 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31969 * If not, then start the interrupt again - care here as could
31970 * have gone low in meantime so verify it hasn't!
31971 */
31972 - atomic_set(&data->interrupt_handled, 0);
31973 + atomic_set_unchecked(&data->interrupt_handled, 0);
31974 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31975 /* If still not occurred or another handler was scheduled */
31976 if (gpio_get_value(data->pdata->gpio_data)
31977 - || atomic_read(&data->interrupt_handled))
31978 + || atomic_read_unchecked(&data->interrupt_handled))
31979 return;
31980 }
31981
31982 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31983 index 378fcb5..5e91fa8 100644
31984 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31985 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31986 @@ -43,7 +43,7 @@
31987 extern struct i2c_adapter amd756_smbus;
31988
31989 static struct i2c_adapter *s4882_adapter;
31990 -static struct i2c_algorithm *s4882_algo;
31991 +static i2c_algorithm_no_const *s4882_algo;
31992
31993 /* Wrapper access functions for multiplexed SMBus */
31994 static DEFINE_MUTEX(amd756_lock);
31995 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31996 index 29015eb..af2d8e9 100644
31997 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31998 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31999 @@ -41,7 +41,7 @@
32000 extern struct i2c_adapter *nforce2_smbus;
32001
32002 static struct i2c_adapter *s4985_adapter;
32003 -static struct i2c_algorithm *s4985_algo;
32004 +static i2c_algorithm_no_const *s4985_algo;
32005
32006 /* Wrapper access functions for multiplexed SMBus */
32007 static DEFINE_MUTEX(nforce2_lock);
32008 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
32009 index d94e0ce..7055125 100644
32010 --- a/drivers/i2c/i2c-mux.c
32011 +++ b/drivers/i2c/i2c-mux.c
32012 @@ -30,7 +30,7 @@
32013 /* multiplexer per channel data */
32014 struct i2c_mux_priv {
32015 struct i2c_adapter adap;
32016 - struct i2c_algorithm algo;
32017 + i2c_algorithm_no_const algo;
32018
32019 struct i2c_adapter *parent;
32020 void *mux_priv; /* the mux chip/device */
32021 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32022 index 8126824..55a2798 100644
32023 --- a/drivers/ide/ide-cd.c
32024 +++ b/drivers/ide/ide-cd.c
32025 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32026 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32027 if ((unsigned long)buf & alignment
32028 || blk_rq_bytes(rq) & q->dma_pad_mask
32029 - || object_is_on_stack(buf))
32030 + || object_starts_on_stack(buf))
32031 drive->dma = 0;
32032 }
32033 }
32034 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32035 index 394fea2..c833880 100644
32036 --- a/drivers/infiniband/core/cm.c
32037 +++ b/drivers/infiniband/core/cm.c
32038 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32039
32040 struct cm_counter_group {
32041 struct kobject obj;
32042 - atomic_long_t counter[CM_ATTR_COUNT];
32043 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32044 };
32045
32046 struct cm_counter_attribute {
32047 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32048 struct ib_mad_send_buf *msg = NULL;
32049 int ret;
32050
32051 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32052 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32053 counter[CM_REQ_COUNTER]);
32054
32055 /* Quick state check to discard duplicate REQs. */
32056 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32057 if (!cm_id_priv)
32058 return;
32059
32060 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32061 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32062 counter[CM_REP_COUNTER]);
32063 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32064 if (ret)
32065 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32066 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32067 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32068 spin_unlock_irq(&cm_id_priv->lock);
32069 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32070 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32071 counter[CM_RTU_COUNTER]);
32072 goto out;
32073 }
32074 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32075 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32076 dreq_msg->local_comm_id);
32077 if (!cm_id_priv) {
32078 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32079 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32080 counter[CM_DREQ_COUNTER]);
32081 cm_issue_drep(work->port, work->mad_recv_wc);
32082 return -EINVAL;
32083 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32084 case IB_CM_MRA_REP_RCVD:
32085 break;
32086 case IB_CM_TIMEWAIT:
32087 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32088 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32089 counter[CM_DREQ_COUNTER]);
32090 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32091 goto unlock;
32092 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32093 cm_free_msg(msg);
32094 goto deref;
32095 case IB_CM_DREQ_RCVD:
32096 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32097 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32098 counter[CM_DREQ_COUNTER]);
32099 goto unlock;
32100 default:
32101 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32102 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32103 cm_id_priv->msg, timeout)) {
32104 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32105 - atomic_long_inc(&work->port->
32106 + atomic_long_inc_unchecked(&work->port->
32107 counter_group[CM_RECV_DUPLICATES].
32108 counter[CM_MRA_COUNTER]);
32109 goto out;
32110 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32111 break;
32112 case IB_CM_MRA_REQ_RCVD:
32113 case IB_CM_MRA_REP_RCVD:
32114 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32115 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32116 counter[CM_MRA_COUNTER]);
32117 /* fall through */
32118 default:
32119 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32120 case IB_CM_LAP_IDLE:
32121 break;
32122 case IB_CM_MRA_LAP_SENT:
32123 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32124 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32125 counter[CM_LAP_COUNTER]);
32126 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32127 goto unlock;
32128 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32129 cm_free_msg(msg);
32130 goto deref;
32131 case IB_CM_LAP_RCVD:
32132 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32133 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32134 counter[CM_LAP_COUNTER]);
32135 goto unlock;
32136 default:
32137 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32138 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32139 if (cur_cm_id_priv) {
32140 spin_unlock_irq(&cm.lock);
32141 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32142 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32143 counter[CM_SIDR_REQ_COUNTER]);
32144 goto out; /* Duplicate message. */
32145 }
32146 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32147 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32148 msg->retries = 1;
32149
32150 - atomic_long_add(1 + msg->retries,
32151 + atomic_long_add_unchecked(1 + msg->retries,
32152 &port->counter_group[CM_XMIT].counter[attr_index]);
32153 if (msg->retries)
32154 - atomic_long_add(msg->retries,
32155 + atomic_long_add_unchecked(msg->retries,
32156 &port->counter_group[CM_XMIT_RETRIES].
32157 counter[attr_index]);
32158
32159 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32160 }
32161
32162 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32163 - atomic_long_inc(&port->counter_group[CM_RECV].
32164 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32165 counter[attr_id - CM_ATTR_ID_OFFSET]);
32166
32167 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32168 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32169 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32170
32171 return sprintf(buf, "%ld\n",
32172 - atomic_long_read(&group->counter[cm_attr->index]));
32173 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32174 }
32175
32176 static const struct sysfs_ops cm_counter_ops = {
32177 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32178 index 176c8f9..2627b62 100644
32179 --- a/drivers/infiniband/core/fmr_pool.c
32180 +++ b/drivers/infiniband/core/fmr_pool.c
32181 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32182
32183 struct task_struct *thread;
32184
32185 - atomic_t req_ser;
32186 - atomic_t flush_ser;
32187 + atomic_unchecked_t req_ser;
32188 + atomic_unchecked_t flush_ser;
32189
32190 wait_queue_head_t force_wait;
32191 };
32192 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32193 struct ib_fmr_pool *pool = pool_ptr;
32194
32195 do {
32196 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32197 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32198 ib_fmr_batch_release(pool);
32199
32200 - atomic_inc(&pool->flush_ser);
32201 + atomic_inc_unchecked(&pool->flush_ser);
32202 wake_up_interruptible(&pool->force_wait);
32203
32204 if (pool->flush_function)
32205 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32206 }
32207
32208 set_current_state(TASK_INTERRUPTIBLE);
32209 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32210 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32211 !kthread_should_stop())
32212 schedule();
32213 __set_current_state(TASK_RUNNING);
32214 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32215 pool->dirty_watermark = params->dirty_watermark;
32216 pool->dirty_len = 0;
32217 spin_lock_init(&pool->pool_lock);
32218 - atomic_set(&pool->req_ser, 0);
32219 - atomic_set(&pool->flush_ser, 0);
32220 + atomic_set_unchecked(&pool->req_ser, 0);
32221 + atomic_set_unchecked(&pool->flush_ser, 0);
32222 init_waitqueue_head(&pool->force_wait);
32223
32224 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32225 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32226 }
32227 spin_unlock_irq(&pool->pool_lock);
32228
32229 - serial = atomic_inc_return(&pool->req_ser);
32230 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32231 wake_up_process(pool->thread);
32232
32233 if (wait_event_interruptible(pool->force_wait,
32234 - atomic_read(&pool->flush_ser) - serial >= 0))
32235 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32236 return -EINTR;
32237
32238 return 0;
32239 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32240 } else {
32241 list_add_tail(&fmr->list, &pool->dirty_list);
32242 if (++pool->dirty_len >= pool->dirty_watermark) {
32243 - atomic_inc(&pool->req_ser);
32244 + atomic_inc_unchecked(&pool->req_ser);
32245 wake_up_process(pool->thread);
32246 }
32247 }
32248 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32249 index afd8179..598063f 100644
32250 --- a/drivers/infiniband/hw/cxgb4/mem.c
32251 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32252 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32253 int err;
32254 struct fw_ri_tpte tpt;
32255 u32 stag_idx;
32256 - static atomic_t key;
32257 + static atomic_unchecked_t key;
32258
32259 if (c4iw_fatal_error(rdev))
32260 return -EIO;
32261 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32262 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32263 rdev->stats.stag.max = rdev->stats.stag.cur;
32264 mutex_unlock(&rdev->stats.lock);
32265 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32266 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32267 }
32268 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32269 __func__, stag_state, type, pdid, stag_idx);
32270 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32271 index 79b3dbc..96e5fcc 100644
32272 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32273 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32274 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32275 struct ib_atomic_eth *ateth;
32276 struct ipath_ack_entry *e;
32277 u64 vaddr;
32278 - atomic64_t *maddr;
32279 + atomic64_unchecked_t *maddr;
32280 u64 sdata;
32281 u32 rkey;
32282 u8 next;
32283 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32284 IB_ACCESS_REMOTE_ATOMIC)))
32285 goto nack_acc_unlck;
32286 /* Perform atomic OP and save result. */
32287 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32288 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32289 sdata = be64_to_cpu(ateth->swap_data);
32290 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32291 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32292 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32293 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32294 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32295 be64_to_cpu(ateth->compare_data),
32296 sdata);
32297 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32298 index 1f95bba..9530f87 100644
32299 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32300 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32301 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32302 unsigned long flags;
32303 struct ib_wc wc;
32304 u64 sdata;
32305 - atomic64_t *maddr;
32306 + atomic64_unchecked_t *maddr;
32307 enum ib_wc_status send_status;
32308
32309 /*
32310 @@ -382,11 +382,11 @@ again:
32311 IB_ACCESS_REMOTE_ATOMIC)))
32312 goto acc_err;
32313 /* Perform atomic OP and save result. */
32314 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32315 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32316 sdata = wqe->wr.wr.atomic.compare_add;
32317 *(u64 *) sqp->s_sge.sge.vaddr =
32318 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32319 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32320 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32321 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32322 sdata, wqe->wr.wr.atomic.swap);
32323 goto send_comp;
32324 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32325 index 748db2d..5f75cc3 100644
32326 --- a/drivers/infiniband/hw/nes/nes.c
32327 +++ b/drivers/infiniband/hw/nes/nes.c
32328 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32329 LIST_HEAD(nes_adapter_list);
32330 static LIST_HEAD(nes_dev_list);
32331
32332 -atomic_t qps_destroyed;
32333 +atomic_unchecked_t qps_destroyed;
32334
32335 static unsigned int ee_flsh_adapter;
32336 static unsigned int sysfs_nonidx_addr;
32337 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32338 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32339 struct nes_adapter *nesadapter = nesdev->nesadapter;
32340
32341 - atomic_inc(&qps_destroyed);
32342 + atomic_inc_unchecked(&qps_destroyed);
32343
32344 /* Free the control structures */
32345
32346 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32347 index 5cac29e..c471744 100644
32348 --- a/drivers/infiniband/hw/nes/nes.h
32349 +++ b/drivers/infiniband/hw/nes/nes.h
32350 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
32351 extern unsigned int wqm_quanta;
32352 extern struct list_head nes_adapter_list;
32353
32354 -extern atomic_t cm_connects;
32355 -extern atomic_t cm_accepts;
32356 -extern atomic_t cm_disconnects;
32357 -extern atomic_t cm_closes;
32358 -extern atomic_t cm_connecteds;
32359 -extern atomic_t cm_connect_reqs;
32360 -extern atomic_t cm_rejects;
32361 -extern atomic_t mod_qp_timouts;
32362 -extern atomic_t qps_created;
32363 -extern atomic_t qps_destroyed;
32364 -extern atomic_t sw_qps_destroyed;
32365 +extern atomic_unchecked_t cm_connects;
32366 +extern atomic_unchecked_t cm_accepts;
32367 +extern atomic_unchecked_t cm_disconnects;
32368 +extern atomic_unchecked_t cm_closes;
32369 +extern atomic_unchecked_t cm_connecteds;
32370 +extern atomic_unchecked_t cm_connect_reqs;
32371 +extern atomic_unchecked_t cm_rejects;
32372 +extern atomic_unchecked_t mod_qp_timouts;
32373 +extern atomic_unchecked_t qps_created;
32374 +extern atomic_unchecked_t qps_destroyed;
32375 +extern atomic_unchecked_t sw_qps_destroyed;
32376 extern u32 mh_detected;
32377 extern u32 mh_pauses_sent;
32378 extern u32 cm_packets_sent;
32379 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
32380 extern u32 cm_packets_received;
32381 extern u32 cm_packets_dropped;
32382 extern u32 cm_packets_retrans;
32383 -extern atomic_t cm_listens_created;
32384 -extern atomic_t cm_listens_destroyed;
32385 +extern atomic_unchecked_t cm_listens_created;
32386 +extern atomic_unchecked_t cm_listens_destroyed;
32387 extern u32 cm_backlog_drops;
32388 -extern atomic_t cm_loopbacks;
32389 -extern atomic_t cm_nodes_created;
32390 -extern atomic_t cm_nodes_destroyed;
32391 -extern atomic_t cm_accel_dropped_pkts;
32392 -extern atomic_t cm_resets_recvd;
32393 -extern atomic_t pau_qps_created;
32394 -extern atomic_t pau_qps_destroyed;
32395 +extern atomic_unchecked_t cm_loopbacks;
32396 +extern atomic_unchecked_t cm_nodes_created;
32397 +extern atomic_unchecked_t cm_nodes_destroyed;
32398 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32399 +extern atomic_unchecked_t cm_resets_recvd;
32400 +extern atomic_unchecked_t pau_qps_created;
32401 +extern atomic_unchecked_t pau_qps_destroyed;
32402
32403 extern u32 int_mod_timer_init;
32404 extern u32 int_mod_cq_depth_256;
32405 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32406 index cfaacaf..fa0722e 100644
32407 --- a/drivers/infiniband/hw/nes/nes_cm.c
32408 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32409 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32410 u32 cm_packets_retrans;
32411 u32 cm_packets_created;
32412 u32 cm_packets_received;
32413 -atomic_t cm_listens_created;
32414 -atomic_t cm_listens_destroyed;
32415 +atomic_unchecked_t cm_listens_created;
32416 +atomic_unchecked_t cm_listens_destroyed;
32417 u32 cm_backlog_drops;
32418 -atomic_t cm_loopbacks;
32419 -atomic_t cm_nodes_created;
32420 -atomic_t cm_nodes_destroyed;
32421 -atomic_t cm_accel_dropped_pkts;
32422 -atomic_t cm_resets_recvd;
32423 +atomic_unchecked_t cm_loopbacks;
32424 +atomic_unchecked_t cm_nodes_created;
32425 +atomic_unchecked_t cm_nodes_destroyed;
32426 +atomic_unchecked_t cm_accel_dropped_pkts;
32427 +atomic_unchecked_t cm_resets_recvd;
32428
32429 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32430 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32431 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32432
32433 static struct nes_cm_core *g_cm_core;
32434
32435 -atomic_t cm_connects;
32436 -atomic_t cm_accepts;
32437 -atomic_t cm_disconnects;
32438 -atomic_t cm_closes;
32439 -atomic_t cm_connecteds;
32440 -atomic_t cm_connect_reqs;
32441 -atomic_t cm_rejects;
32442 +atomic_unchecked_t cm_connects;
32443 +atomic_unchecked_t cm_accepts;
32444 +atomic_unchecked_t cm_disconnects;
32445 +atomic_unchecked_t cm_closes;
32446 +atomic_unchecked_t cm_connecteds;
32447 +atomic_unchecked_t cm_connect_reqs;
32448 +atomic_unchecked_t cm_rejects;
32449
32450 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32451 {
32452 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32453 kfree(listener);
32454 listener = NULL;
32455 ret = 0;
32456 - atomic_inc(&cm_listens_destroyed);
32457 + atomic_inc_unchecked(&cm_listens_destroyed);
32458 } else {
32459 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32460 }
32461 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32462 cm_node->rem_mac);
32463
32464 add_hte_node(cm_core, cm_node);
32465 - atomic_inc(&cm_nodes_created);
32466 + atomic_inc_unchecked(&cm_nodes_created);
32467
32468 return cm_node;
32469 }
32470 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32471 }
32472
32473 atomic_dec(&cm_core->node_cnt);
32474 - atomic_inc(&cm_nodes_destroyed);
32475 + atomic_inc_unchecked(&cm_nodes_destroyed);
32476 nesqp = cm_node->nesqp;
32477 if (nesqp) {
32478 nesqp->cm_node = NULL;
32479 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32480
32481 static void drop_packet(struct sk_buff *skb)
32482 {
32483 - atomic_inc(&cm_accel_dropped_pkts);
32484 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32485 dev_kfree_skb_any(skb);
32486 }
32487
32488 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32489 {
32490
32491 int reset = 0; /* whether to send reset in case of err.. */
32492 - atomic_inc(&cm_resets_recvd);
32493 + atomic_inc_unchecked(&cm_resets_recvd);
32494 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32495 " refcnt=%d\n", cm_node, cm_node->state,
32496 atomic_read(&cm_node->ref_count));
32497 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32498 rem_ref_cm_node(cm_node->cm_core, cm_node);
32499 return NULL;
32500 }
32501 - atomic_inc(&cm_loopbacks);
32502 + atomic_inc_unchecked(&cm_loopbacks);
32503 loopbackremotenode->loopbackpartner = cm_node;
32504 loopbackremotenode->tcp_cntxt.rcv_wscale =
32505 NES_CM_DEFAULT_RCV_WND_SCALE;
32506 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32507 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32508 else {
32509 rem_ref_cm_node(cm_core, cm_node);
32510 - atomic_inc(&cm_accel_dropped_pkts);
32511 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32512 dev_kfree_skb_any(skb);
32513 }
32514 break;
32515 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32516
32517 if ((cm_id) && (cm_id->event_handler)) {
32518 if (issue_disconn) {
32519 - atomic_inc(&cm_disconnects);
32520 + atomic_inc_unchecked(&cm_disconnects);
32521 cm_event.event = IW_CM_EVENT_DISCONNECT;
32522 cm_event.status = disconn_status;
32523 cm_event.local_addr = cm_id->local_addr;
32524 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32525 }
32526
32527 if (issue_close) {
32528 - atomic_inc(&cm_closes);
32529 + atomic_inc_unchecked(&cm_closes);
32530 nes_disconnect(nesqp, 1);
32531
32532 cm_id->provider_data = nesqp;
32533 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32534
32535 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32536 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32537 - atomic_inc(&cm_accepts);
32538 + atomic_inc_unchecked(&cm_accepts);
32539
32540 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32541 netdev_refcnt_read(nesvnic->netdev));
32542 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32543 struct nes_cm_core *cm_core;
32544 u8 *start_buff;
32545
32546 - atomic_inc(&cm_rejects);
32547 + atomic_inc_unchecked(&cm_rejects);
32548 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32549 loopback = cm_node->loopbackpartner;
32550 cm_core = cm_node->cm_core;
32551 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32552 ntohl(cm_id->local_addr.sin_addr.s_addr),
32553 ntohs(cm_id->local_addr.sin_port));
32554
32555 - atomic_inc(&cm_connects);
32556 + atomic_inc_unchecked(&cm_connects);
32557 nesqp->active_conn = 1;
32558
32559 /* cache the cm_id in the qp */
32560 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32561 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32562 return err;
32563 }
32564 - atomic_inc(&cm_listens_created);
32565 + atomic_inc_unchecked(&cm_listens_created);
32566 }
32567
32568 cm_id->add_ref(cm_id);
32569 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32570
32571 if (nesqp->destroyed)
32572 return;
32573 - atomic_inc(&cm_connecteds);
32574 + atomic_inc_unchecked(&cm_connecteds);
32575 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32576 " local port 0x%04X. jiffies = %lu.\n",
32577 nesqp->hwqp.qp_id,
32578 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32579
32580 cm_id->add_ref(cm_id);
32581 ret = cm_id->event_handler(cm_id, &cm_event);
32582 - atomic_inc(&cm_closes);
32583 + atomic_inc_unchecked(&cm_closes);
32584 cm_event.event = IW_CM_EVENT_CLOSE;
32585 cm_event.status = 0;
32586 cm_event.provider_data = cm_id->provider_data;
32587 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32588 return;
32589 cm_id = cm_node->cm_id;
32590
32591 - atomic_inc(&cm_connect_reqs);
32592 + atomic_inc_unchecked(&cm_connect_reqs);
32593 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32594 cm_node, cm_id, jiffies);
32595
32596 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32597 return;
32598 cm_id = cm_node->cm_id;
32599
32600 - atomic_inc(&cm_connect_reqs);
32601 + atomic_inc_unchecked(&cm_connect_reqs);
32602 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32603 cm_node, cm_id, jiffies);
32604
32605 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32606 index 3ba7be3..c81f6ff 100644
32607 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32608 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32609 @@ -40,8 +40,8 @@
32610 #include "nes.h"
32611 #include "nes_mgt.h"
32612
32613 -atomic_t pau_qps_created;
32614 -atomic_t pau_qps_destroyed;
32615 +atomic_unchecked_t pau_qps_created;
32616 +atomic_unchecked_t pau_qps_destroyed;
32617
32618 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32619 {
32620 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32621 {
32622 struct sk_buff *skb;
32623 unsigned long flags;
32624 - atomic_inc(&pau_qps_destroyed);
32625 + atomic_inc_unchecked(&pau_qps_destroyed);
32626
32627 /* Free packets that have not yet been forwarded */
32628 /* Lock is acquired by skb_dequeue when removing the skb */
32629 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32630 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32631 skb_queue_head_init(&nesqp->pau_list);
32632 spin_lock_init(&nesqp->pau_lock);
32633 - atomic_inc(&pau_qps_created);
32634 + atomic_inc_unchecked(&pau_qps_created);
32635 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32636 }
32637
32638 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32639 index 0564be7..f68b0f1 100644
32640 --- a/drivers/infiniband/hw/nes/nes_nic.c
32641 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32642 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32643 target_stat_values[++index] = mh_detected;
32644 target_stat_values[++index] = mh_pauses_sent;
32645 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32646 - target_stat_values[++index] = atomic_read(&cm_connects);
32647 - target_stat_values[++index] = atomic_read(&cm_accepts);
32648 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32649 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32650 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32651 - target_stat_values[++index] = atomic_read(&cm_rejects);
32652 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32653 - target_stat_values[++index] = atomic_read(&qps_created);
32654 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32655 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32656 - target_stat_values[++index] = atomic_read(&cm_closes);
32657 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32658 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32659 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32660 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32661 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32662 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32663 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32664 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32665 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32666 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32667 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32668 target_stat_values[++index] = cm_packets_sent;
32669 target_stat_values[++index] = cm_packets_bounced;
32670 target_stat_values[++index] = cm_packets_created;
32671 target_stat_values[++index] = cm_packets_received;
32672 target_stat_values[++index] = cm_packets_dropped;
32673 target_stat_values[++index] = cm_packets_retrans;
32674 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32675 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32676 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32677 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32678 target_stat_values[++index] = cm_backlog_drops;
32679 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32680 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32681 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32682 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32683 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32684 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32685 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32686 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32687 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32688 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32689 target_stat_values[++index] = nesadapter->free_4kpbl;
32690 target_stat_values[++index] = nesadapter->free_256pbl;
32691 target_stat_values[++index] = int_mod_timer_init;
32692 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32693 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32694 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32695 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32696 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32697 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32698 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32699 }
32700
32701 /**
32702 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32703 index cd0ecb2..7099ff0 100644
32704 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32705 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32706 @@ -46,9 +46,9 @@
32707
32708 #include <rdma/ib_umem.h>
32709
32710 -atomic_t mod_qp_timouts;
32711 -atomic_t qps_created;
32712 -atomic_t sw_qps_destroyed;
32713 +atomic_unchecked_t mod_qp_timouts;
32714 +atomic_unchecked_t qps_created;
32715 +atomic_unchecked_t sw_qps_destroyed;
32716
32717 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32718
32719 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32720 if (init_attr->create_flags)
32721 return ERR_PTR(-EINVAL);
32722
32723 - atomic_inc(&qps_created);
32724 + atomic_inc_unchecked(&qps_created);
32725 switch (init_attr->qp_type) {
32726 case IB_QPT_RC:
32727 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32728 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32729 struct iw_cm_event cm_event;
32730 int ret = 0;
32731
32732 - atomic_inc(&sw_qps_destroyed);
32733 + atomic_inc_unchecked(&sw_qps_destroyed);
32734 nesqp->destroyed = 1;
32735
32736 /* Blow away the connection if it exists. */
32737 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32738 index 4d11575..3e890e5 100644
32739 --- a/drivers/infiniband/hw/qib/qib.h
32740 +++ b/drivers/infiniband/hw/qib/qib.h
32741 @@ -51,6 +51,7 @@
32742 #include <linux/completion.h>
32743 #include <linux/kref.h>
32744 #include <linux/sched.h>
32745 +#include <linux/slab.h>
32746
32747 #include "qib_common.h"
32748 #include "qib_verbs.h"
32749 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32750 index da739d9..da1c7f4 100644
32751 --- a/drivers/input/gameport/gameport.c
32752 +++ b/drivers/input/gameport/gameport.c
32753 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32754 */
32755 static void gameport_init_port(struct gameport *gameport)
32756 {
32757 - static atomic_t gameport_no = ATOMIC_INIT(0);
32758 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32759
32760 __module_get(THIS_MODULE);
32761
32762 mutex_init(&gameport->drv_mutex);
32763 device_initialize(&gameport->dev);
32764 dev_set_name(&gameport->dev, "gameport%lu",
32765 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32766 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32767 gameport->dev.bus = &gameport_bus;
32768 gameport->dev.release = gameport_release_port;
32769 if (gameport->parent)
32770 diff --git a/drivers/input/input.c b/drivers/input/input.c
32771 index 53a0dde..abffda7 100644
32772 --- a/drivers/input/input.c
32773 +++ b/drivers/input/input.c
32774 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32775 */
32776 int input_register_device(struct input_dev *dev)
32777 {
32778 - static atomic_t input_no = ATOMIC_INIT(0);
32779 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32780 struct input_handler *handler;
32781 unsigned int packet_size;
32782 const char *path;
32783 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
32784 dev->setkeycode = input_default_setkeycode;
32785
32786 dev_set_name(&dev->dev, "input%ld",
32787 - (unsigned long) atomic_inc_return(&input_no) - 1);
32788 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32789
32790 error = device_add(&dev->dev);
32791 if (error)
32792 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32793 index 04c69af..5f92d00 100644
32794 --- a/drivers/input/joystick/sidewinder.c
32795 +++ b/drivers/input/joystick/sidewinder.c
32796 @@ -30,6 +30,7 @@
32797 #include <linux/kernel.h>
32798 #include <linux/module.h>
32799 #include <linux/slab.h>
32800 +#include <linux/sched.h>
32801 #include <linux/init.h>
32802 #include <linux/input.h>
32803 #include <linux/gameport.h>
32804 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32805 index 83811e4..0822b90 100644
32806 --- a/drivers/input/joystick/xpad.c
32807 +++ b/drivers/input/joystick/xpad.c
32808 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32809
32810 static int xpad_led_probe(struct usb_xpad *xpad)
32811 {
32812 - static atomic_t led_seq = ATOMIC_INIT(0);
32813 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32814 long led_no;
32815 struct xpad_led *led;
32816 struct led_classdev *led_cdev;
32817 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32818 if (!led)
32819 return -ENOMEM;
32820
32821 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32822 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32823
32824 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32825 led->xpad = xpad;
32826 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32827 index 4c842c3..590b0bf 100644
32828 --- a/drivers/input/mousedev.c
32829 +++ b/drivers/input/mousedev.c
32830 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32831
32832 spin_unlock_irq(&client->packet_lock);
32833
32834 - if (copy_to_user(buffer, data, count))
32835 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32836 return -EFAULT;
32837
32838 return count;
32839 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32840 index d0f7533..fb8215b 100644
32841 --- a/drivers/input/serio/serio.c
32842 +++ b/drivers/input/serio/serio.c
32843 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32844 */
32845 static void serio_init_port(struct serio *serio)
32846 {
32847 - static atomic_t serio_no = ATOMIC_INIT(0);
32848 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32849
32850 __module_get(THIS_MODULE);
32851
32852 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32853 mutex_init(&serio->drv_mutex);
32854 device_initialize(&serio->dev);
32855 dev_set_name(&serio->dev, "serio%ld",
32856 - (long)atomic_inc_return(&serio_no) - 1);
32857 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32858 serio->dev.bus = &serio_bus;
32859 serio->dev.release = serio_release_port;
32860 serio->dev.groups = serio_device_attr_groups;
32861 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32862 index c679867..6e2e34d 100644
32863 --- a/drivers/isdn/capi/capi.c
32864 +++ b/drivers/isdn/capi/capi.c
32865 @@ -83,8 +83,8 @@ struct capiminor {
32866
32867 struct capi20_appl *ap;
32868 u32 ncci;
32869 - atomic_t datahandle;
32870 - atomic_t msgid;
32871 + atomic_unchecked_t datahandle;
32872 + atomic_unchecked_t msgid;
32873
32874 struct tty_port port;
32875 int ttyinstop;
32876 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32877 capimsg_setu16(s, 2, mp->ap->applid);
32878 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32879 capimsg_setu8 (s, 5, CAPI_RESP);
32880 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32881 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32882 capimsg_setu32(s, 8, mp->ncci);
32883 capimsg_setu16(s, 12, datahandle);
32884 }
32885 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
32886 mp->outbytes -= len;
32887 spin_unlock_bh(&mp->outlock);
32888
32889 - datahandle = atomic_inc_return(&mp->datahandle);
32890 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32891 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32892 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32893 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32894 capimsg_setu16(skb->data, 2, mp->ap->applid);
32895 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32896 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32897 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32898 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32899 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32900 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32901 capimsg_setu16(skb->data, 16, len); /* Data length */
32902 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32903 index 67abf3f..076b3a6 100644
32904 --- a/drivers/isdn/gigaset/interface.c
32905 +++ b/drivers/isdn/gigaset/interface.c
32906 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32907 }
32908 tty->driver_data = cs;
32909
32910 - ++cs->port.count;
32911 + atomic_inc(&cs->port.count);
32912
32913 - if (cs->port.count == 1) {
32914 + if (atomic_read(&cs->port.count) == 1) {
32915 tty_port_tty_set(&cs->port, tty);
32916 tty->low_latency = 1;
32917 }
32918 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32919
32920 if (!cs->connected)
32921 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32922 - else if (!cs->port.count)
32923 + else if (!atomic_read(&cs->port.count))
32924 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32925 - else if (!--cs->port.count)
32926 + else if (!atomic_dec_return(&cs->port.count))
32927 tty_port_tty_set(&cs->port, NULL);
32928
32929 mutex_unlock(&cs->mutex);
32930 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32931 index 821f7ac..28d4030 100644
32932 --- a/drivers/isdn/hardware/avm/b1.c
32933 +++ b/drivers/isdn/hardware/avm/b1.c
32934 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32935 }
32936 if (left) {
32937 if (t4file->user) {
32938 - if (copy_from_user(buf, dp, left))
32939 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32940 return -EFAULT;
32941 } else {
32942 memcpy(buf, dp, left);
32943 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32944 }
32945 if (left) {
32946 if (config->user) {
32947 - if (copy_from_user(buf, dp, left))
32948 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32949 return -EFAULT;
32950 } else {
32951 memcpy(buf, dp, left);
32952 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32953 index dd6b53a..19d9ee6 100644
32954 --- a/drivers/isdn/hardware/eicon/divasync.h
32955 +++ b/drivers/isdn/hardware/eicon/divasync.h
32956 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32957 } diva_didd_add_adapter_t;
32958 typedef struct _diva_didd_remove_adapter {
32959 IDI_CALL p_request;
32960 -} diva_didd_remove_adapter_t;
32961 +} __no_const diva_didd_remove_adapter_t;
32962 typedef struct _diva_didd_read_adapter_array {
32963 void *buffer;
32964 dword length;
32965 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32966 index d303e65..28bcb7b 100644
32967 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32968 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32969 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32970 typedef struct _diva_os_idi_adapter_interface {
32971 diva_init_card_proc_t cleanup_adapter_proc;
32972 diva_cmd_card_proc_t cmd_proc;
32973 -} diva_os_idi_adapter_interface_t;
32974 +} __no_const diva_os_idi_adapter_interface_t;
32975
32976 typedef struct _diva_os_xdi_adapter {
32977 struct list_head link;
32978 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32979 index b817809..409caff 100644
32980 --- a/drivers/isdn/i4l/isdn_tty.c
32981 +++ b/drivers/isdn/i4l/isdn_tty.c
32982 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32983
32984 #ifdef ISDN_DEBUG_MODEM_OPEN
32985 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32986 - port->count);
32987 + atomic_read(&port->count));
32988 #endif
32989 - port->count++;
32990 + atomic_inc(&port->count);
32991 port->tty = tty;
32992 /*
32993 * Start up serial port
32994 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32995 #endif
32996 return;
32997 }
32998 - if ((tty->count == 1) && (port->count != 1)) {
32999 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33000 /*
33001 * Uh, oh. tty->count is 1, which means that the tty
33002 * structure will be freed. Info->count should always
33003 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33004 * serial port won't be shutdown.
33005 */
33006 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33007 - "info->count is %d\n", port->count);
33008 - port->count = 1;
33009 + "info->count is %d\n", atomic_read(&port->count));
33010 + atomic_set(&port->count, 1);
33011 }
33012 - if (--port->count < 0) {
33013 + if (atomic_dec_return(&port->count) < 0) {
33014 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33015 - info->line, port->count);
33016 - port->count = 0;
33017 + info->line, atomic_read(&port->count));
33018 + atomic_set(&port->count, 0);
33019 }
33020 - if (port->count) {
33021 + if (atomic_read(&port->count)) {
33022 #ifdef ISDN_DEBUG_MODEM_OPEN
33023 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33024 #endif
33025 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33026 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33027 return;
33028 isdn_tty_shutdown(info);
33029 - port->count = 0;
33030 + atomic_set(&port->count, 0);
33031 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33032 port->tty = NULL;
33033 wake_up_interruptible(&port->open_wait);
33034 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33035 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33036 modem_info *info = &dev->mdm.info[i];
33037
33038 - if (info->port.count == 0)
33039 + if (atomic_read(&info->port.count) == 0)
33040 continue;
33041 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33042 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33043 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33044 index e74df7c..03a03ba 100644
33045 --- a/drivers/isdn/icn/icn.c
33046 +++ b/drivers/isdn/icn/icn.c
33047 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33048 if (count > len)
33049 count = len;
33050 if (user) {
33051 - if (copy_from_user(msg, buf, count))
33052 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33053 return -EFAULT;
33054 } else
33055 memcpy(msg, buf, count);
33056 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33057 index b5fdcb7..5b6c59f 100644
33058 --- a/drivers/lguest/core.c
33059 +++ b/drivers/lguest/core.c
33060 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33061 * it's worked so far. The end address needs +1 because __get_vm_area
33062 * allocates an extra guard page, so we need space for that.
33063 */
33064 +
33065 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33066 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33067 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33068 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33069 +#else
33070 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33071 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33072 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33073 +#endif
33074 +
33075 if (!switcher_vma) {
33076 err = -ENOMEM;
33077 printk("lguest: could not map switcher pages high\n");
33078 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33079 * Now the Switcher is mapped at the right address, we can't fail!
33080 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33081 */
33082 - memcpy(switcher_vma->addr, start_switcher_text,
33083 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33084 end_switcher_text - start_switcher_text);
33085
33086 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33087 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33088 index 4af12e1..0e89afe 100644
33089 --- a/drivers/lguest/x86/core.c
33090 +++ b/drivers/lguest/x86/core.c
33091 @@ -59,7 +59,7 @@ static struct {
33092 /* Offset from where switcher.S was compiled to where we've copied it */
33093 static unsigned long switcher_offset(void)
33094 {
33095 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33096 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33097 }
33098
33099 /* This cpu's struct lguest_pages. */
33100 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33101 * These copies are pretty cheap, so we do them unconditionally: */
33102 /* Save the current Host top-level page directory.
33103 */
33104 +
33105 +#ifdef CONFIG_PAX_PER_CPU_PGD
33106 + pages->state.host_cr3 = read_cr3();
33107 +#else
33108 pages->state.host_cr3 = __pa(current->mm->pgd);
33109 +#endif
33110 +
33111 /*
33112 * Set up the Guest's page tables to see this CPU's pages (and no
33113 * other CPU's pages).
33114 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
33115 * compiled-in switcher code and the high-mapped copy we just made.
33116 */
33117 for (i = 0; i < IDT_ENTRIES; i++)
33118 - default_idt_entries[i] += switcher_offset();
33119 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33120
33121 /*
33122 * Set up the Switcher's per-cpu areas.
33123 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
33124 * it will be undisturbed when we switch. To change %cs and jump we
33125 * need this structure to feed to Intel's "lcall" instruction.
33126 */
33127 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33128 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33129 lguest_entry.segment = LGUEST_CS;
33130
33131 /*
33132 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33133 index 40634b0..4f5855e 100644
33134 --- a/drivers/lguest/x86/switcher_32.S
33135 +++ b/drivers/lguest/x86/switcher_32.S
33136 @@ -87,6 +87,7 @@
33137 #include <asm/page.h>
33138 #include <asm/segment.h>
33139 #include <asm/lguest.h>
33140 +#include <asm/processor-flags.h>
33141
33142 // We mark the start of the code to copy
33143 // It's placed in .text tho it's never run here
33144 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33145 // Changes type when we load it: damn Intel!
33146 // For after we switch over our page tables
33147 // That entry will be read-only: we'd crash.
33148 +
33149 +#ifdef CONFIG_PAX_KERNEXEC
33150 + mov %cr0, %edx
33151 + xor $X86_CR0_WP, %edx
33152 + mov %edx, %cr0
33153 +#endif
33154 +
33155 movl $(GDT_ENTRY_TSS*8), %edx
33156 ltr %dx
33157
33158 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33159 // Let's clear it again for our return.
33160 // The GDT descriptor of the Host
33161 // Points to the table after two "size" bytes
33162 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33163 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33164 // Clear "used" from type field (byte 5, bit 2)
33165 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33166 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33167 +
33168 +#ifdef CONFIG_PAX_KERNEXEC
33169 + mov %cr0, %eax
33170 + xor $X86_CR0_WP, %eax
33171 + mov %eax, %cr0
33172 +#endif
33173
33174 // Once our page table's switched, the Guest is live!
33175 // The Host fades as we run this final step.
33176 @@ -295,13 +309,12 @@ deliver_to_host:
33177 // I consulted gcc, and it gave
33178 // These instructions, which I gladly credit:
33179 leal (%edx,%ebx,8), %eax
33180 - movzwl (%eax),%edx
33181 - movl 4(%eax), %eax
33182 - xorw %ax, %ax
33183 - orl %eax, %edx
33184 + movl 4(%eax), %edx
33185 + movw (%eax), %dx
33186 // Now the address of the handler's in %edx
33187 // We call it now: its "iret" drops us home.
33188 - jmp *%edx
33189 + ljmp $__KERNEL_CS, $1f
33190 +1: jmp *%edx
33191
33192 // Every interrupt can come to us here
33193 // But we must truly tell each apart.
33194 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33195 index 7155945..4bcc562 100644
33196 --- a/drivers/md/bitmap.c
33197 +++ b/drivers/md/bitmap.c
33198 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33199 chunk_kb ? "KB" : "B");
33200 if (bitmap->storage.file) {
33201 seq_printf(seq, ", file: ");
33202 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33203 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33204 }
33205
33206 seq_printf(seq, "\n");
33207 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33208 index afd9598..528d8f9 100644
33209 --- a/drivers/md/dm-ioctl.c
33210 +++ b/drivers/md/dm-ioctl.c
33211 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33212 cmd == DM_LIST_VERSIONS_CMD)
33213 return 0;
33214
33215 - if ((cmd == DM_DEV_CREATE_CMD)) {
33216 + if (cmd == DM_DEV_CREATE_CMD) {
33217 if (!*param->name) {
33218 DMWARN("name not supplied when creating device");
33219 return -EINVAL;
33220 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33221 index fd61f98..8050783 100644
33222 --- a/drivers/md/dm-raid1.c
33223 +++ b/drivers/md/dm-raid1.c
33224 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33225
33226 struct mirror {
33227 struct mirror_set *ms;
33228 - atomic_t error_count;
33229 + atomic_unchecked_t error_count;
33230 unsigned long error_type;
33231 struct dm_dev *dev;
33232 sector_t offset;
33233 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33234 struct mirror *m;
33235
33236 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33237 - if (!atomic_read(&m->error_count))
33238 + if (!atomic_read_unchecked(&m->error_count))
33239 return m;
33240
33241 return NULL;
33242 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33243 * simple way to tell if a device has encountered
33244 * errors.
33245 */
33246 - atomic_inc(&m->error_count);
33247 + atomic_inc_unchecked(&m->error_count);
33248
33249 if (test_and_set_bit(error_type, &m->error_type))
33250 return;
33251 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33252 struct mirror *m = get_default_mirror(ms);
33253
33254 do {
33255 - if (likely(!atomic_read(&m->error_count)))
33256 + if (likely(!atomic_read_unchecked(&m->error_count)))
33257 return m;
33258
33259 if (m-- == ms->mirror)
33260 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33261 {
33262 struct mirror *default_mirror = get_default_mirror(m->ms);
33263
33264 - return !atomic_read(&default_mirror->error_count);
33265 + return !atomic_read_unchecked(&default_mirror->error_count);
33266 }
33267
33268 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33269 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33270 */
33271 if (likely(region_in_sync(ms, region, 1)))
33272 m = choose_mirror(ms, bio->bi_sector);
33273 - else if (m && atomic_read(&m->error_count))
33274 + else if (m && atomic_read_unchecked(&m->error_count))
33275 m = NULL;
33276
33277 if (likely(m))
33278 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33279 }
33280
33281 ms->mirror[mirror].ms = ms;
33282 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33283 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33284 ms->mirror[mirror].error_type = 0;
33285 ms->mirror[mirror].offset = offset;
33286
33287 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33288 */
33289 static char device_status_char(struct mirror *m)
33290 {
33291 - if (!atomic_read(&(m->error_count)))
33292 + if (!atomic_read_unchecked(&(m->error_count)))
33293 return 'A';
33294
33295 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33296 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33297 index e2f87653..f279abe 100644
33298 --- a/drivers/md/dm-stripe.c
33299 +++ b/drivers/md/dm-stripe.c
33300 @@ -20,7 +20,7 @@ struct stripe {
33301 struct dm_dev *dev;
33302 sector_t physical_start;
33303
33304 - atomic_t error_count;
33305 + atomic_unchecked_t error_count;
33306 };
33307
33308 struct stripe_c {
33309 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33310 kfree(sc);
33311 return r;
33312 }
33313 - atomic_set(&(sc->stripe[i].error_count), 0);
33314 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33315 }
33316
33317 ti->private = sc;
33318 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33319 DMEMIT("%d ", sc->stripes);
33320 for (i = 0; i < sc->stripes; i++) {
33321 DMEMIT("%s ", sc->stripe[i].dev->name);
33322 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33323 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33324 'D' : 'A';
33325 }
33326 buffer[i] = '\0';
33327 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33328 */
33329 for (i = 0; i < sc->stripes; i++)
33330 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33331 - atomic_inc(&(sc->stripe[i].error_count));
33332 - if (atomic_read(&(sc->stripe[i].error_count)) <
33333 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33334 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33335 DM_IO_ERROR_THRESHOLD)
33336 schedule_work(&sc->trigger_event);
33337 }
33338 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33339 index 100368e..64262ce 100644
33340 --- a/drivers/md/dm-table.c
33341 +++ b/drivers/md/dm-table.c
33342 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33343 if (!dev_size)
33344 return 0;
33345
33346 - if ((start >= dev_size) || (start + len > dev_size)) {
33347 + if ((start >= dev_size) || (len > dev_size - start)) {
33348 DMWARN("%s: %s too small for target: "
33349 "start=%llu, len=%llu, dev_size=%llu",
33350 dm_device_name(ti->table->md), bdevname(bdev, b),
33351 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33352 index 693e149..b7e0fde 100644
33353 --- a/drivers/md/dm-thin-metadata.c
33354 +++ b/drivers/md/dm-thin-metadata.c
33355 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33356 {
33357 pmd->info.tm = pmd->tm;
33358 pmd->info.levels = 2;
33359 - pmd->info.value_type.context = pmd->data_sm;
33360 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33361 pmd->info.value_type.size = sizeof(__le64);
33362 pmd->info.value_type.inc = data_block_inc;
33363 pmd->info.value_type.dec = data_block_dec;
33364 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33365
33366 pmd->bl_info.tm = pmd->tm;
33367 pmd->bl_info.levels = 1;
33368 - pmd->bl_info.value_type.context = pmd->data_sm;
33369 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33370 pmd->bl_info.value_type.size = sizeof(__le64);
33371 pmd->bl_info.value_type.inc = data_block_inc;
33372 pmd->bl_info.value_type.dec = data_block_dec;
33373 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33374 index 77e6eff..913d695 100644
33375 --- a/drivers/md/dm.c
33376 +++ b/drivers/md/dm.c
33377 @@ -182,9 +182,9 @@ struct mapped_device {
33378 /*
33379 * Event handling.
33380 */
33381 - atomic_t event_nr;
33382 + atomic_unchecked_t event_nr;
33383 wait_queue_head_t eventq;
33384 - atomic_t uevent_seq;
33385 + atomic_unchecked_t uevent_seq;
33386 struct list_head uevent_list;
33387 spinlock_t uevent_lock; /* Protect access to uevent_list */
33388
33389 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
33390 rwlock_init(&md->map_lock);
33391 atomic_set(&md->holders, 1);
33392 atomic_set(&md->open_count, 0);
33393 - atomic_set(&md->event_nr, 0);
33394 - atomic_set(&md->uevent_seq, 0);
33395 + atomic_set_unchecked(&md->event_nr, 0);
33396 + atomic_set_unchecked(&md->uevent_seq, 0);
33397 INIT_LIST_HEAD(&md->uevent_list);
33398 spin_lock_init(&md->uevent_lock);
33399
33400 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
33401
33402 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33403
33404 - atomic_inc(&md->event_nr);
33405 + atomic_inc_unchecked(&md->event_nr);
33406 wake_up(&md->eventq);
33407 }
33408
33409 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33410
33411 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33412 {
33413 - return atomic_add_return(1, &md->uevent_seq);
33414 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33415 }
33416
33417 uint32_t dm_get_event_nr(struct mapped_device *md)
33418 {
33419 - return atomic_read(&md->event_nr);
33420 + return atomic_read_unchecked(&md->event_nr);
33421 }
33422
33423 int dm_wait_event(struct mapped_device *md, int event_nr)
33424 {
33425 return wait_event_interruptible(md->eventq,
33426 - (event_nr != atomic_read(&md->event_nr)));
33427 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33428 }
33429
33430 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33431 diff --git a/drivers/md/md.c b/drivers/md/md.c
33432 index 6120071..31d9be2 100644
33433 --- a/drivers/md/md.c
33434 +++ b/drivers/md/md.c
33435 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33436 * start build, activate spare
33437 */
33438 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33439 -static atomic_t md_event_count;
33440 +static atomic_unchecked_t md_event_count;
33441 void md_new_event(struct mddev *mddev)
33442 {
33443 - atomic_inc(&md_event_count);
33444 + atomic_inc_unchecked(&md_event_count);
33445 wake_up(&md_event_waiters);
33446 }
33447 EXPORT_SYMBOL_GPL(md_new_event);
33448 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33449 */
33450 static void md_new_event_inintr(struct mddev *mddev)
33451 {
33452 - atomic_inc(&md_event_count);
33453 + atomic_inc_unchecked(&md_event_count);
33454 wake_up(&md_event_waiters);
33455 }
33456
33457 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33458 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33459 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33460 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33461 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33462 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33463
33464 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33465 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33466 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33467 else
33468 sb->resync_offset = cpu_to_le64(0);
33469
33470 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33471 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33472
33473 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33474 sb->size = cpu_to_le64(mddev->dev_sectors);
33475 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33476 static ssize_t
33477 errors_show(struct md_rdev *rdev, char *page)
33478 {
33479 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33480 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33481 }
33482
33483 static ssize_t
33484 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33485 char *e;
33486 unsigned long n = simple_strtoul(buf, &e, 10);
33487 if (*buf && (*e == 0 || *e == '\n')) {
33488 - atomic_set(&rdev->corrected_errors, n);
33489 + atomic_set_unchecked(&rdev->corrected_errors, n);
33490 return len;
33491 }
33492 return -EINVAL;
33493 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
33494 rdev->sb_loaded = 0;
33495 rdev->bb_page = NULL;
33496 atomic_set(&rdev->nr_pending, 0);
33497 - atomic_set(&rdev->read_errors, 0);
33498 - atomic_set(&rdev->corrected_errors, 0);
33499 + atomic_set_unchecked(&rdev->read_errors, 0);
33500 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33501
33502 INIT_LIST_HEAD(&rdev->same_set);
33503 init_waitqueue_head(&rdev->blocked_wait);
33504 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33505
33506 spin_unlock(&pers_lock);
33507 seq_printf(seq, "\n");
33508 - seq->poll_event = atomic_read(&md_event_count);
33509 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33510 return 0;
33511 }
33512 if (v == (void*)2) {
33513 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33514 return error;
33515
33516 seq = file->private_data;
33517 - seq->poll_event = atomic_read(&md_event_count);
33518 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33519 return error;
33520 }
33521
33522 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33523 /* always allow read */
33524 mask = POLLIN | POLLRDNORM;
33525
33526 - if (seq->poll_event != atomic_read(&md_event_count))
33527 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33528 mask |= POLLERR | POLLPRI;
33529 return mask;
33530 }
33531 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33532 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33533 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33534 (int)part_stat_read(&disk->part0, sectors[1]) -
33535 - atomic_read(&disk->sync_io);
33536 + atomic_read_unchecked(&disk->sync_io);
33537 /* sync IO will cause sync_io to increase before the disk_stats
33538 * as sync_io is counted when a request starts, and
33539 * disk_stats is counted when it completes.
33540 diff --git a/drivers/md/md.h b/drivers/md/md.h
33541 index af443ab..0f93be3 100644
33542 --- a/drivers/md/md.h
33543 +++ b/drivers/md/md.h
33544 @@ -94,13 +94,13 @@ struct md_rdev {
33545 * only maintained for arrays that
33546 * support hot removal
33547 */
33548 - atomic_t read_errors; /* number of consecutive read errors that
33549 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33550 * we have tried to ignore.
33551 */
33552 struct timespec last_read_error; /* monotonic time since our
33553 * last read error
33554 */
33555 - atomic_t corrected_errors; /* number of corrected read errors,
33556 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33557 * for reporting to userspace and storing
33558 * in superblock.
33559 */
33560 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33561
33562 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33563 {
33564 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33565 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33566 }
33567
33568 struct md_personality
33569 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33570 index f6d29e6..7917f5e 100644
33571 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33572 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33573 @@ -22,7 +22,7 @@
33574 * Space map interface.
33575 */
33576 struct sm_disk {
33577 - struct dm_space_map sm;
33578 + dm_space_map_no_const sm;
33579
33580 struct ll_disk ll;
33581 struct ll_disk old_ll;
33582 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33583 index e89ae5e..062e4c2 100644
33584 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33585 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33586 @@ -43,7 +43,7 @@ struct block_op {
33587 };
33588
33589 struct sm_metadata {
33590 - struct dm_space_map sm;
33591 + dm_space_map_no_const sm;
33592
33593 struct ll_disk ll;
33594 struct ll_disk old_ll;
33595 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33596 index 1cbfc6b..56e1dbb 100644
33597 --- a/drivers/md/persistent-data/dm-space-map.h
33598 +++ b/drivers/md/persistent-data/dm-space-map.h
33599 @@ -60,6 +60,7 @@ struct dm_space_map {
33600 int (*root_size)(struct dm_space_map *sm, size_t *result);
33601 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33602 };
33603 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33604
33605 /*----------------------------------------------------------------*/
33606
33607 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33608 index a0f7309..5599dbc 100644
33609 --- a/drivers/md/raid1.c
33610 +++ b/drivers/md/raid1.c
33611 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33612 if (r1_sync_page_io(rdev, sect, s,
33613 bio->bi_io_vec[idx].bv_page,
33614 READ) != 0)
33615 - atomic_add(s, &rdev->corrected_errors);
33616 + atomic_add_unchecked(s, &rdev->corrected_errors);
33617 }
33618 sectors -= s;
33619 sect += s;
33620 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33621 test_bit(In_sync, &rdev->flags)) {
33622 if (r1_sync_page_io(rdev, sect, s,
33623 conf->tmppage, READ)) {
33624 - atomic_add(s, &rdev->corrected_errors);
33625 + atomic_add_unchecked(s, &rdev->corrected_errors);
33626 printk(KERN_INFO
33627 "md/raid1:%s: read error corrected "
33628 "(%d sectors at %llu on %s)\n",
33629 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33630 index c9acbd7..386cd3e 100644
33631 --- a/drivers/md/raid10.c
33632 +++ b/drivers/md/raid10.c
33633 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
33634 /* The write handler will notice the lack of
33635 * R10BIO_Uptodate and record any errors etc
33636 */
33637 - atomic_add(r10_bio->sectors,
33638 + atomic_add_unchecked(r10_bio->sectors,
33639 &conf->mirrors[d].rdev->corrected_errors);
33640
33641 /* for reconstruct, we always reschedule after a read.
33642 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33643 {
33644 struct timespec cur_time_mon;
33645 unsigned long hours_since_last;
33646 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33647 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33648
33649 ktime_get_ts(&cur_time_mon);
33650
33651 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33652 * overflowing the shift of read_errors by hours_since_last.
33653 */
33654 if (hours_since_last >= 8 * sizeof(read_errors))
33655 - atomic_set(&rdev->read_errors, 0);
33656 + atomic_set_unchecked(&rdev->read_errors, 0);
33657 else
33658 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33659 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33660 }
33661
33662 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33663 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33664 return;
33665
33666 check_decay_read_errors(mddev, rdev);
33667 - atomic_inc(&rdev->read_errors);
33668 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33669 + atomic_inc_unchecked(&rdev->read_errors);
33670 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33671 char b[BDEVNAME_SIZE];
33672 bdevname(rdev->bdev, b);
33673
33674 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33675 "md/raid10:%s: %s: Raid device exceeded "
33676 "read_error threshold [cur %d:max %d]\n",
33677 mdname(mddev), b,
33678 - atomic_read(&rdev->read_errors), max_read_errors);
33679 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33680 printk(KERN_NOTICE
33681 "md/raid10:%s: %s: Failing raid device\n",
33682 mdname(mddev), b);
33683 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33684 sect +
33685 choose_data_offset(r10_bio, rdev)),
33686 bdevname(rdev->bdev, b));
33687 - atomic_add(s, &rdev->corrected_errors);
33688 + atomic_add_unchecked(s, &rdev->corrected_errors);
33689 }
33690
33691 rdev_dec_pending(rdev, mddev);
33692 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33693 index a450268..c4168a9 100644
33694 --- a/drivers/md/raid5.c
33695 +++ b/drivers/md/raid5.c
33696 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33697 mdname(conf->mddev), STRIPE_SECTORS,
33698 (unsigned long long)s,
33699 bdevname(rdev->bdev, b));
33700 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33701 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33702 clear_bit(R5_ReadError, &sh->dev[i].flags);
33703 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33704 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33705 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33706
33707 - if (atomic_read(&rdev->read_errors))
33708 - atomic_set(&rdev->read_errors, 0);
33709 + if (atomic_read_unchecked(&rdev->read_errors))
33710 + atomic_set_unchecked(&rdev->read_errors, 0);
33711 } else {
33712 const char *bdn = bdevname(rdev->bdev, b);
33713 int retry = 0;
33714 int set_bad = 0;
33715
33716 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33717 - atomic_inc(&rdev->read_errors);
33718 + atomic_inc_unchecked(&rdev->read_errors);
33719 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33720 printk_ratelimited(
33721 KERN_WARNING
33722 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33723 mdname(conf->mddev),
33724 (unsigned long long)s,
33725 bdn);
33726 - } else if (atomic_read(&rdev->read_errors)
33727 + } else if (atomic_read_unchecked(&rdev->read_errors)
33728 > conf->max_nr_stripes)
33729 printk(KERN_WARNING
33730 "md/raid:%s: Too many read errors, failing device %s.\n",
33731 diff --git a/drivers/media/dvb-core/dvb_demux.h b/drivers/media/dvb-core/dvb_demux.h
33732 index fa7188a..04a045e 100644
33733 --- a/drivers/media/dvb-core/dvb_demux.h
33734 +++ b/drivers/media/dvb-core/dvb_demux.h
33735 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33736 union {
33737 dmx_ts_cb ts;
33738 dmx_section_cb sec;
33739 - } cb;
33740 + } __no_const cb;
33741
33742 struct dvb_demux *demux;
33743 void *priv;
33744 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
33745 index d33101a..6b13069 100644
33746 --- a/drivers/media/dvb-core/dvbdev.c
33747 +++ b/drivers/media/dvb-core/dvbdev.c
33748 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33749 const struct dvb_device *template, void *priv, int type)
33750 {
33751 struct dvb_device *dvbdev;
33752 - struct file_operations *dvbdevfops;
33753 + file_operations_no_const *dvbdevfops;
33754 struct device *clsdev;
33755 int minor;
33756 int id;
33757 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
33758 index 404f63a..4796533 100644
33759 --- a/drivers/media/dvb-frontends/dib3000.h
33760 +++ b/drivers/media/dvb-frontends/dib3000.h
33761 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33762 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33763 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33764 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33765 -};
33766 +} __no_const;
33767
33768 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33769 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33770 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
33771 index 3aa6856..435ad25 100644
33772 --- a/drivers/media/pci/cx88/cx88-alsa.c
33773 +++ b/drivers/media/pci/cx88/cx88-alsa.c
33774 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33775 * Only boards with eeprom and byte 1 at eeprom=1 have it
33776 */
33777
33778 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
33779 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
33780 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33781 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33782 {0, }
33783 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
33784 index feff57e..66a2c67 100644
33785 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
33786 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
33787 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33788 .subvendor = _subvend, .subdevice = _subdev, \
33789 .driver_data = (unsigned long)&_driverdata }
33790
33791 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33792 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33793 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33794 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33795 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33796 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
33797 index 96a13ed..6df45b4 100644
33798 --- a/drivers/media/pci/ngene/ngene-cards.c
33799 +++ b/drivers/media/pci/ngene/ngene-cards.c
33800 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
33801
33802 /****************************************************************************/
33803
33804 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33805 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33806 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33807 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33808 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33809 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
33810 index a3b1a34..71ce0e3 100644
33811 --- a/drivers/media/platform/omap/omap_vout.c
33812 +++ b/drivers/media/platform/omap/omap_vout.c
33813 @@ -65,7 +65,6 @@ enum omap_vout_channels {
33814 OMAP_VIDEO2,
33815 };
33816
33817 -static struct videobuf_queue_ops video_vbq_ops;
33818 /* Variables configurable through module params*/
33819 static u32 video1_numbuffers = 3;
33820 static u32 video2_numbuffers = 3;
33821 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
33822 {
33823 struct videobuf_queue *q;
33824 struct omap_vout_device *vout = NULL;
33825 + static struct videobuf_queue_ops video_vbq_ops = {
33826 + .buf_setup = omap_vout_buffer_setup,
33827 + .buf_prepare = omap_vout_buffer_prepare,
33828 + .buf_release = omap_vout_buffer_release,
33829 + .buf_queue = omap_vout_buffer_queue,
33830 + };
33831
33832 vout = video_drvdata(file);
33833 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33834 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
33835 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33836
33837 q = &vout->vbq;
33838 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33839 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33840 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33841 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33842 spin_lock_init(&vout->vbq_lock);
33843
33844 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33845 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
33846 index 02194c0..091733b 100644
33847 --- a/drivers/media/platform/timblogiw.c
33848 +++ b/drivers/media/platform/timblogiw.c
33849 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33850
33851 /* Platform device functions */
33852
33853 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33854 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33855 .vidioc_querycap = timblogiw_querycap,
33856 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33857 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33858 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33859 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33860 };
33861
33862 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33863 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33864 .owner = THIS_MODULE,
33865 .open = timblogiw_open,
33866 .release = timblogiw_close,
33867 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33868 index 697a421..16c5a5f 100644
33869 --- a/drivers/media/radio/radio-cadet.c
33870 +++ b/drivers/media/radio/radio-cadet.c
33871 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33872 unsigned char readbuf[RDS_BUFFER];
33873 int i = 0;
33874
33875 + if (count > RDS_BUFFER)
33876 + return -EFAULT;
33877 mutex_lock(&dev->lock);
33878 if (dev->rdsstat == 0)
33879 cadet_start_rds(dev);
33880 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33881 while (i < count && dev->rdsin != dev->rdsout)
33882 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33883
33884 - if (i && copy_to_user(data, readbuf, i))
33885 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33886 i = -EFAULT;
33887 unlock:
33888 mutex_unlock(&dev->lock);
33889 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
33890 index 4ea43a9..66f4a8f 100644
33891 --- a/drivers/media/radio/radio-tea5777.h
33892 +++ b/drivers/media/radio/radio-tea5777.h
33893 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
33894
33895 struct radio_tea5777 {
33896 struct v4l2_device *v4l2_dev;
33897 - struct v4l2_file_operations fops;
33898 + v4l2_file_operations_no_const fops;
33899 struct video_device vd; /* video device */
33900 bool has_am; /* Device can tune to AM freqs */
33901 bool write_before_read; /* must write before read quirk */
33902 diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
33903 index 66a56ef..d139911 100644
33904 --- a/drivers/media/usb/au0828/au0828.h
33905 +++ b/drivers/media/usb/au0828/au0828.h
33906 @@ -191,7 +191,7 @@ struct au0828_dev {
33907
33908 /* I2C */
33909 struct i2c_adapter i2c_adap;
33910 - struct i2c_algorithm i2c_algo;
33911 + i2c_algorithm_no_const i2c_algo;
33912 struct i2c_client i2c_client;
33913 u32 i2c_rc;
33914
33915 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
33916 index 3940bb0..fb3952a 100644
33917 --- a/drivers/media/usb/dvb-usb/cxusb.c
33918 +++ b/drivers/media/usb/dvb-usb/cxusb.c
33919 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33920
33921 struct dib0700_adapter_state {
33922 int (*set_param_save) (struct dvb_frontend *);
33923 -};
33924 +} __no_const;
33925
33926 static int dib7070_set_param_override(struct dvb_frontend *fe)
33927 {
33928 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
33929 index 9382895..ac8093c 100644
33930 --- a/drivers/media/usb/dvb-usb/dw2102.c
33931 +++ b/drivers/media/usb/dvb-usb/dw2102.c
33932 @@ -95,7 +95,7 @@ struct su3000_state {
33933
33934 struct s6x0_state {
33935 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33936 -};
33937 +} __no_const;
33938
33939 /* debug */
33940 static int dvb_usb_dw2102_debug;
33941 diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
33942 index 036952f..80d356d 100644
33943 --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
33944 +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
33945 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33946
33947 /* I2C stuff */
33948 struct i2c_adapter i2c_adap;
33949 - struct i2c_algorithm i2c_algo;
33950 + i2c_algorithm_no_const i2c_algo;
33951 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33952 int i2c_cx25840_hack_state;
33953 int i2c_linked;
33954 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33955 index fb69baa..cf7ad22 100644
33956 --- a/drivers/message/fusion/mptbase.c
33957 +++ b/drivers/message/fusion/mptbase.c
33958 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33959 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33960 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33961
33962 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33963 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33964 +#else
33965 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33966 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33967 +#endif
33968 +
33969 /*
33970 * Rounding UP to nearest 4-kB boundary here...
33971 */
33972 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33973 index 551262e..7551198 100644
33974 --- a/drivers/message/fusion/mptsas.c
33975 +++ b/drivers/message/fusion/mptsas.c
33976 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33977 return 0;
33978 }
33979
33980 +static inline void
33981 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33982 +{
33983 + if (phy_info->port_details) {
33984 + phy_info->port_details->rphy = rphy;
33985 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33986 + ioc->name, rphy));
33987 + }
33988 +
33989 + if (rphy) {
33990 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33991 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33992 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33993 + ioc->name, rphy, rphy->dev.release));
33994 + }
33995 +}
33996 +
33997 /* no mutex */
33998 static void
33999 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34000 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34001 return NULL;
34002 }
34003
34004 -static inline void
34005 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34006 -{
34007 - if (phy_info->port_details) {
34008 - phy_info->port_details->rphy = rphy;
34009 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34010 - ioc->name, rphy));
34011 - }
34012 -
34013 - if (rphy) {
34014 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34015 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34016 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34017 - ioc->name, rphy, rphy->dev.release));
34018 - }
34019 -}
34020 -
34021 static inline struct sas_port *
34022 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34023 {
34024 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34025 index 0c3ced7..1fe34ec 100644
34026 --- a/drivers/message/fusion/mptscsih.c
34027 +++ b/drivers/message/fusion/mptscsih.c
34028 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34029
34030 h = shost_priv(SChost);
34031
34032 - if (h) {
34033 - if (h->info_kbuf == NULL)
34034 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34035 - return h->info_kbuf;
34036 - h->info_kbuf[0] = '\0';
34037 + if (!h)
34038 + return NULL;
34039
34040 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34041 - h->info_kbuf[size-1] = '\0';
34042 - }
34043 + if (h->info_kbuf == NULL)
34044 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34045 + return h->info_kbuf;
34046 + h->info_kbuf[0] = '\0';
34047 +
34048 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34049 + h->info_kbuf[size-1] = '\0';
34050
34051 return h->info_kbuf;
34052 }
34053 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34054 index 8001aa6..b137580 100644
34055 --- a/drivers/message/i2o/i2o_proc.c
34056 +++ b/drivers/message/i2o/i2o_proc.c
34057 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34058 "Array Controller Device"
34059 };
34060
34061 -static char *chtostr(char *tmp, u8 *chars, int n)
34062 -{
34063 - tmp[0] = 0;
34064 - return strncat(tmp, (char *)chars, n);
34065 -}
34066 -
34067 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34068 char *group)
34069 {
34070 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34071 } *result;
34072
34073 i2o_exec_execute_ddm_table ddm_table;
34074 - char tmp[28 + 1];
34075
34076 result = kmalloc(sizeof(*result), GFP_KERNEL);
34077 if (!result)
34078 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34079
34080 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34081 seq_printf(seq, "%-#8x", ddm_table.module_id);
34082 - seq_printf(seq, "%-29s",
34083 - chtostr(tmp, ddm_table.module_name_version, 28));
34084 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34085 seq_printf(seq, "%9d ", ddm_table.data_size);
34086 seq_printf(seq, "%8d", ddm_table.code_size);
34087
34088 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34089
34090 i2o_driver_result_table *result;
34091 i2o_driver_store_table *dst;
34092 - char tmp[28 + 1];
34093
34094 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34095 if (result == NULL)
34096 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34097
34098 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34099 seq_printf(seq, "%-#8x", dst->module_id);
34100 - seq_printf(seq, "%-29s",
34101 - chtostr(tmp, dst->module_name_version, 28));
34102 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34103 + seq_printf(seq, "%-.28s", dst->module_name_version);
34104 + seq_printf(seq, "%-.8s", dst->date);
34105 seq_printf(seq, "%8d ", dst->module_size);
34106 seq_printf(seq, "%8d ", dst->mpb_size);
34107 seq_printf(seq, "0x%04x", dst->module_flags);
34108 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34109 // == (allow) 512d bytes (max)
34110 static u16 *work16 = (u16 *) work32;
34111 int token;
34112 - char tmp[16 + 1];
34113
34114 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34115
34116 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34117 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34118 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34119 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34120 - seq_printf(seq, "Vendor info : %s\n",
34121 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34122 - seq_printf(seq, "Product info : %s\n",
34123 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34124 - seq_printf(seq, "Description : %s\n",
34125 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34126 - seq_printf(seq, "Product rev. : %s\n",
34127 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34128 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34129 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34130 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34131 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34132
34133 seq_printf(seq, "Serial number : ");
34134 print_serial_number(seq, (u8 *) (work32 + 16),
34135 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34136 u8 pad[256]; // allow up to 256 byte (max) serial number
34137 } result;
34138
34139 - char tmp[24 + 1];
34140 -
34141 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34142
34143 if (token < 0) {
34144 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34145 }
34146
34147 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34148 - seq_printf(seq, "Module name : %s\n",
34149 - chtostr(tmp, result.module_name, 24));
34150 - seq_printf(seq, "Module revision : %s\n",
34151 - chtostr(tmp, result.module_rev, 8));
34152 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34153 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34154
34155 seq_printf(seq, "Serial number : ");
34156 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34157 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34158 u8 instance_number[4];
34159 } result;
34160
34161 - char tmp[64 + 1];
34162 -
34163 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34164
34165 if (token < 0) {
34166 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34167 return 0;
34168 }
34169
34170 - seq_printf(seq, "Device name : %s\n",
34171 - chtostr(tmp, result.device_name, 64));
34172 - seq_printf(seq, "Service name : %s\n",
34173 - chtostr(tmp, result.service_name, 64));
34174 - seq_printf(seq, "Physical name : %s\n",
34175 - chtostr(tmp, result.physical_location, 64));
34176 - seq_printf(seq, "Instance number : %s\n",
34177 - chtostr(tmp, result.instance_number, 4));
34178 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34179 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34180 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34181 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34182
34183 return 0;
34184 }
34185 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34186 index a8c08f3..155fe3d 100644
34187 --- a/drivers/message/i2o/iop.c
34188 +++ b/drivers/message/i2o/iop.c
34189 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34190
34191 spin_lock_irqsave(&c->context_list_lock, flags);
34192
34193 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34194 - atomic_inc(&c->context_list_counter);
34195 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34196 + atomic_inc_unchecked(&c->context_list_counter);
34197
34198 - entry->context = atomic_read(&c->context_list_counter);
34199 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34200
34201 list_add(&entry->list, &c->context_list);
34202
34203 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34204
34205 #if BITS_PER_LONG == 64
34206 spin_lock_init(&c->context_list_lock);
34207 - atomic_set(&c->context_list_counter, 0);
34208 + atomic_set_unchecked(&c->context_list_counter, 0);
34209 INIT_LIST_HEAD(&c->context_list);
34210 #endif
34211
34212 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34213 index 7ce65f4..e66e9bc 100644
34214 --- a/drivers/mfd/abx500-core.c
34215 +++ b/drivers/mfd/abx500-core.c
34216 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34217
34218 struct abx500_device_entry {
34219 struct list_head list;
34220 - struct abx500_ops ops;
34221 + abx500_ops_no_const ops;
34222 struct device *dev;
34223 };
34224
34225 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34226 index 965c480..71f2db9 100644
34227 --- a/drivers/mfd/janz-cmodio.c
34228 +++ b/drivers/mfd/janz-cmodio.c
34229 @@ -13,6 +13,7 @@
34230
34231 #include <linux/kernel.h>
34232 #include <linux/module.h>
34233 +#include <linux/slab.h>
34234 #include <linux/init.h>
34235 #include <linux/pci.h>
34236 #include <linux/interrupt.h>
34237 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
34238 index 3aa9a96..59cf685 100644
34239 --- a/drivers/misc/kgdbts.c
34240 +++ b/drivers/misc/kgdbts.c
34241 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
34242 char before[BREAK_INSTR_SIZE];
34243 char after[BREAK_INSTR_SIZE];
34244
34245 - probe_kernel_read(before, (char *)kgdbts_break_test,
34246 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
34247 BREAK_INSTR_SIZE);
34248 init_simple_test();
34249 ts.tst = plant_and_detach_test;
34250 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
34251 /* Activate test with initial breakpoint */
34252 if (!is_early)
34253 kgdb_breakpoint();
34254 - probe_kernel_read(after, (char *)kgdbts_break_test,
34255 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
34256 BREAK_INSTR_SIZE);
34257 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
34258 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
34259 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34260 index 4a87e5c..76bdf5c 100644
34261 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34262 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34263 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34264 * the lid is closed. This leads to interrupts as soon as a little move
34265 * is done.
34266 */
34267 - atomic_inc(&lis3->count);
34268 + atomic_inc_unchecked(&lis3->count);
34269
34270 wake_up_interruptible(&lis3->misc_wait);
34271 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34272 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34273 if (lis3->pm_dev)
34274 pm_runtime_get_sync(lis3->pm_dev);
34275
34276 - atomic_set(&lis3->count, 0);
34277 + atomic_set_unchecked(&lis3->count, 0);
34278 return 0;
34279 }
34280
34281 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34282 add_wait_queue(&lis3->misc_wait, &wait);
34283 while (true) {
34284 set_current_state(TASK_INTERRUPTIBLE);
34285 - data = atomic_xchg(&lis3->count, 0);
34286 + data = atomic_xchg_unchecked(&lis3->count, 0);
34287 if (data)
34288 break;
34289
34290 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34291 struct lis3lv02d, miscdev);
34292
34293 poll_wait(file, &lis3->misc_wait, wait);
34294 - if (atomic_read(&lis3->count))
34295 + if (atomic_read_unchecked(&lis3->count))
34296 return POLLIN | POLLRDNORM;
34297 return 0;
34298 }
34299 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34300 index c439c82..1f20f57 100644
34301 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34302 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34303 @@ -297,7 +297,7 @@ struct lis3lv02d {
34304 struct input_polled_dev *idev; /* input device */
34305 struct platform_device *pdev; /* platform device */
34306 struct regulator_bulk_data regulators[2];
34307 - atomic_t count; /* interrupt count after last read */
34308 + atomic_unchecked_t count; /* interrupt count after last read */
34309 union axis_conversion ac; /* hw -> logical axis */
34310 int mapped_btns[3];
34311
34312 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34313 index 2f30bad..c4c13d0 100644
34314 --- a/drivers/misc/sgi-gru/gruhandles.c
34315 +++ b/drivers/misc/sgi-gru/gruhandles.c
34316 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34317 unsigned long nsec;
34318
34319 nsec = CLKS2NSEC(clks);
34320 - atomic_long_inc(&mcs_op_statistics[op].count);
34321 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34322 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34323 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34324 if (mcs_op_statistics[op].max < nsec)
34325 mcs_op_statistics[op].max = nsec;
34326 }
34327 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34328 index 950dbe9..eeef0f8 100644
34329 --- a/drivers/misc/sgi-gru/gruprocfs.c
34330 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34331 @@ -32,9 +32,9 @@
34332
34333 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34334
34335 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34336 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34337 {
34338 - unsigned long val = atomic_long_read(v);
34339 + unsigned long val = atomic_long_read_unchecked(v);
34340
34341 seq_printf(s, "%16lu %s\n", val, id);
34342 }
34343 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34344
34345 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34346 for (op = 0; op < mcsop_last; op++) {
34347 - count = atomic_long_read(&mcs_op_statistics[op].count);
34348 - total = atomic_long_read(&mcs_op_statistics[op].total);
34349 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34350 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34351 max = mcs_op_statistics[op].max;
34352 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34353 count ? total / count : 0, max);
34354 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34355 index 5c3ce24..4915ccb 100644
34356 --- a/drivers/misc/sgi-gru/grutables.h
34357 +++ b/drivers/misc/sgi-gru/grutables.h
34358 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34359 * GRU statistics.
34360 */
34361 struct gru_stats_s {
34362 - atomic_long_t vdata_alloc;
34363 - atomic_long_t vdata_free;
34364 - atomic_long_t gts_alloc;
34365 - atomic_long_t gts_free;
34366 - atomic_long_t gms_alloc;
34367 - atomic_long_t gms_free;
34368 - atomic_long_t gts_double_allocate;
34369 - atomic_long_t assign_context;
34370 - atomic_long_t assign_context_failed;
34371 - atomic_long_t free_context;
34372 - atomic_long_t load_user_context;
34373 - atomic_long_t load_kernel_context;
34374 - atomic_long_t lock_kernel_context;
34375 - atomic_long_t unlock_kernel_context;
34376 - atomic_long_t steal_user_context;
34377 - atomic_long_t steal_kernel_context;
34378 - atomic_long_t steal_context_failed;
34379 - atomic_long_t nopfn;
34380 - atomic_long_t asid_new;
34381 - atomic_long_t asid_next;
34382 - atomic_long_t asid_wrap;
34383 - atomic_long_t asid_reuse;
34384 - atomic_long_t intr;
34385 - atomic_long_t intr_cbr;
34386 - atomic_long_t intr_tfh;
34387 - atomic_long_t intr_spurious;
34388 - atomic_long_t intr_mm_lock_failed;
34389 - atomic_long_t call_os;
34390 - atomic_long_t call_os_wait_queue;
34391 - atomic_long_t user_flush_tlb;
34392 - atomic_long_t user_unload_context;
34393 - atomic_long_t user_exception;
34394 - atomic_long_t set_context_option;
34395 - atomic_long_t check_context_retarget_intr;
34396 - atomic_long_t check_context_unload;
34397 - atomic_long_t tlb_dropin;
34398 - atomic_long_t tlb_preload_page;
34399 - atomic_long_t tlb_dropin_fail_no_asid;
34400 - atomic_long_t tlb_dropin_fail_upm;
34401 - atomic_long_t tlb_dropin_fail_invalid;
34402 - atomic_long_t tlb_dropin_fail_range_active;
34403 - atomic_long_t tlb_dropin_fail_idle;
34404 - atomic_long_t tlb_dropin_fail_fmm;
34405 - atomic_long_t tlb_dropin_fail_no_exception;
34406 - atomic_long_t tfh_stale_on_fault;
34407 - atomic_long_t mmu_invalidate_range;
34408 - atomic_long_t mmu_invalidate_page;
34409 - atomic_long_t flush_tlb;
34410 - atomic_long_t flush_tlb_gru;
34411 - atomic_long_t flush_tlb_gru_tgh;
34412 - atomic_long_t flush_tlb_gru_zero_asid;
34413 + atomic_long_unchecked_t vdata_alloc;
34414 + atomic_long_unchecked_t vdata_free;
34415 + atomic_long_unchecked_t gts_alloc;
34416 + atomic_long_unchecked_t gts_free;
34417 + atomic_long_unchecked_t gms_alloc;
34418 + atomic_long_unchecked_t gms_free;
34419 + atomic_long_unchecked_t gts_double_allocate;
34420 + atomic_long_unchecked_t assign_context;
34421 + atomic_long_unchecked_t assign_context_failed;
34422 + atomic_long_unchecked_t free_context;
34423 + atomic_long_unchecked_t load_user_context;
34424 + atomic_long_unchecked_t load_kernel_context;
34425 + atomic_long_unchecked_t lock_kernel_context;
34426 + atomic_long_unchecked_t unlock_kernel_context;
34427 + atomic_long_unchecked_t steal_user_context;
34428 + atomic_long_unchecked_t steal_kernel_context;
34429 + atomic_long_unchecked_t steal_context_failed;
34430 + atomic_long_unchecked_t nopfn;
34431 + atomic_long_unchecked_t asid_new;
34432 + atomic_long_unchecked_t asid_next;
34433 + atomic_long_unchecked_t asid_wrap;
34434 + atomic_long_unchecked_t asid_reuse;
34435 + atomic_long_unchecked_t intr;
34436 + atomic_long_unchecked_t intr_cbr;
34437 + atomic_long_unchecked_t intr_tfh;
34438 + atomic_long_unchecked_t intr_spurious;
34439 + atomic_long_unchecked_t intr_mm_lock_failed;
34440 + atomic_long_unchecked_t call_os;
34441 + atomic_long_unchecked_t call_os_wait_queue;
34442 + atomic_long_unchecked_t user_flush_tlb;
34443 + atomic_long_unchecked_t user_unload_context;
34444 + atomic_long_unchecked_t user_exception;
34445 + atomic_long_unchecked_t set_context_option;
34446 + atomic_long_unchecked_t check_context_retarget_intr;
34447 + atomic_long_unchecked_t check_context_unload;
34448 + atomic_long_unchecked_t tlb_dropin;
34449 + atomic_long_unchecked_t tlb_preload_page;
34450 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34451 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34452 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34453 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34454 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34455 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34456 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34457 + atomic_long_unchecked_t tfh_stale_on_fault;
34458 + atomic_long_unchecked_t mmu_invalidate_range;
34459 + atomic_long_unchecked_t mmu_invalidate_page;
34460 + atomic_long_unchecked_t flush_tlb;
34461 + atomic_long_unchecked_t flush_tlb_gru;
34462 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34463 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34464
34465 - atomic_long_t copy_gpa;
34466 - atomic_long_t read_gpa;
34467 + atomic_long_unchecked_t copy_gpa;
34468 + atomic_long_unchecked_t read_gpa;
34469
34470 - atomic_long_t mesq_receive;
34471 - atomic_long_t mesq_receive_none;
34472 - atomic_long_t mesq_send;
34473 - atomic_long_t mesq_send_failed;
34474 - atomic_long_t mesq_noop;
34475 - atomic_long_t mesq_send_unexpected_error;
34476 - atomic_long_t mesq_send_lb_overflow;
34477 - atomic_long_t mesq_send_qlimit_reached;
34478 - atomic_long_t mesq_send_amo_nacked;
34479 - atomic_long_t mesq_send_put_nacked;
34480 - atomic_long_t mesq_page_overflow;
34481 - atomic_long_t mesq_qf_locked;
34482 - atomic_long_t mesq_qf_noop_not_full;
34483 - atomic_long_t mesq_qf_switch_head_failed;
34484 - atomic_long_t mesq_qf_unexpected_error;
34485 - atomic_long_t mesq_noop_unexpected_error;
34486 - atomic_long_t mesq_noop_lb_overflow;
34487 - atomic_long_t mesq_noop_qlimit_reached;
34488 - atomic_long_t mesq_noop_amo_nacked;
34489 - atomic_long_t mesq_noop_put_nacked;
34490 - atomic_long_t mesq_noop_page_overflow;
34491 + atomic_long_unchecked_t mesq_receive;
34492 + atomic_long_unchecked_t mesq_receive_none;
34493 + atomic_long_unchecked_t mesq_send;
34494 + atomic_long_unchecked_t mesq_send_failed;
34495 + atomic_long_unchecked_t mesq_noop;
34496 + atomic_long_unchecked_t mesq_send_unexpected_error;
34497 + atomic_long_unchecked_t mesq_send_lb_overflow;
34498 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34499 + atomic_long_unchecked_t mesq_send_amo_nacked;
34500 + atomic_long_unchecked_t mesq_send_put_nacked;
34501 + atomic_long_unchecked_t mesq_page_overflow;
34502 + atomic_long_unchecked_t mesq_qf_locked;
34503 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34504 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34505 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34506 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34507 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34508 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34509 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34510 + atomic_long_unchecked_t mesq_noop_put_nacked;
34511 + atomic_long_unchecked_t mesq_noop_page_overflow;
34512
34513 };
34514
34515 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34516 tghop_invalidate, mcsop_last};
34517
34518 struct mcs_op_statistic {
34519 - atomic_long_t count;
34520 - atomic_long_t total;
34521 + atomic_long_unchecked_t count;
34522 + atomic_long_unchecked_t total;
34523 unsigned long max;
34524 };
34525
34526 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34527
34528 #define STAT(id) do { \
34529 if (gru_options & OPT_STATS) \
34530 - atomic_long_inc(&gru_stats.id); \
34531 + atomic_long_inc_unchecked(&gru_stats.id); \
34532 } while (0)
34533
34534 #ifdef CONFIG_SGI_GRU_DEBUG
34535 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34536 index c862cd4..0d176fe 100644
34537 --- a/drivers/misc/sgi-xp/xp.h
34538 +++ b/drivers/misc/sgi-xp/xp.h
34539 @@ -288,7 +288,7 @@ struct xpc_interface {
34540 xpc_notify_func, void *);
34541 void (*received) (short, int, void *);
34542 enum xp_retval (*partid_to_nasids) (short, void *);
34543 -};
34544 +} __no_const;
34545
34546 extern struct xpc_interface xpc_interface;
34547
34548 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34549 index b94d5f7..7f494c5 100644
34550 --- a/drivers/misc/sgi-xp/xpc.h
34551 +++ b/drivers/misc/sgi-xp/xpc.h
34552 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34553 void (*received_payload) (struct xpc_channel *, void *);
34554 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34555 };
34556 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34557
34558 /* struct xpc_partition act_state values (for XPC HB) */
34559
34560 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34561 /* found in xpc_main.c */
34562 extern struct device *xpc_part;
34563 extern struct device *xpc_chan;
34564 -extern struct xpc_arch_operations xpc_arch_ops;
34565 +extern xpc_arch_operations_no_const xpc_arch_ops;
34566 extern int xpc_disengage_timelimit;
34567 extern int xpc_disengage_timedout;
34568 extern int xpc_activate_IRQ_rcvd;
34569 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34570 index 8d082b4..aa749ae 100644
34571 --- a/drivers/misc/sgi-xp/xpc_main.c
34572 +++ b/drivers/misc/sgi-xp/xpc_main.c
34573 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34574 .notifier_call = xpc_system_die,
34575 };
34576
34577 -struct xpc_arch_operations xpc_arch_ops;
34578 +xpc_arch_operations_no_const xpc_arch_ops;
34579
34580 /*
34581 * Timer function to enforce the timelimit on the partition disengage.
34582 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
34583 index a0e1720..ee63d0b 100644
34584 --- a/drivers/mmc/core/mmc_ops.c
34585 +++ b/drivers/mmc/core/mmc_ops.c
34586 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
34587 void *data_buf;
34588 int is_on_stack;
34589
34590 - is_on_stack = object_is_on_stack(buf);
34591 + is_on_stack = object_starts_on_stack(buf);
34592 if (is_on_stack) {
34593 /*
34594 * dma onto stack is unsafe/nonportable, but callers to this
34595 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34596 index a4eb8b5..8c0628f 100644
34597 --- a/drivers/mtd/devices/doc2000.c
34598 +++ b/drivers/mtd/devices/doc2000.c
34599 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34600
34601 /* The ECC will not be calculated correctly if less than 512 is written */
34602 /* DBB-
34603 - if (len != 0x200 && eccbuf)
34604 + if (len != 0x200)
34605 printk(KERN_WARNING
34606 "ECC needs a full sector write (adr: %lx size %lx)\n",
34607 (long) to, (long) len);
34608 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34609 index e706a23..b3d262f 100644
34610 --- a/drivers/mtd/nand/denali.c
34611 +++ b/drivers/mtd/nand/denali.c
34612 @@ -26,6 +26,7 @@
34613 #include <linux/pci.h>
34614 #include <linux/mtd/mtd.h>
34615 #include <linux/module.h>
34616 +#include <linux/slab.h>
34617
34618 #include "denali.h"
34619
34620 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34621 index 51b9d6a..52af9a7 100644
34622 --- a/drivers/mtd/nftlmount.c
34623 +++ b/drivers/mtd/nftlmount.c
34624 @@ -24,6 +24,7 @@
34625 #include <asm/errno.h>
34626 #include <linux/delay.h>
34627 #include <linux/slab.h>
34628 +#include <linux/sched.h>
34629 #include <linux/mtd/mtd.h>
34630 #include <linux/mtd/nand.h>
34631 #include <linux/mtd/nftl.h>
34632 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34633 index acf2fe4..25cf8fd 100644
34634 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34635 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34636 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34637
34638 int (*wait_comp)(struct bnx2x *bp,
34639 struct bnx2x_rx_mode_ramrod_params *p);
34640 -};
34641 +} __no_const;
34642
34643 /********************** Set multicast group ***********************************/
34644
34645 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34646 index d9308c32..d87b824 100644
34647 --- a/drivers/net/ethernet/broadcom/tg3.h
34648 +++ b/drivers/net/ethernet/broadcom/tg3.h
34649 @@ -140,6 +140,7 @@
34650 #define CHIPREV_ID_5750_A0 0x4000
34651 #define CHIPREV_ID_5750_A1 0x4001
34652 #define CHIPREV_ID_5750_A3 0x4003
34653 +#define CHIPREV_ID_5750_C1 0x4201
34654 #define CHIPREV_ID_5750_C2 0x4202
34655 #define CHIPREV_ID_5752_A0_HW 0x5000
34656 #define CHIPREV_ID_5752_A0 0x6000
34657 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34658 index 8cffcdf..aadf043 100644
34659 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34660 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34661 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34662 */
34663 struct l2t_skb_cb {
34664 arp_failure_handler_func arp_failure_handler;
34665 -};
34666 +} __no_const;
34667
34668 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34669
34670 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34671 index f879e92..726f20f 100644
34672 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34673 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34674 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34675 for (i=0; i<ETH_ALEN; i++) {
34676 tmp.addr[i] = dev->dev_addr[i];
34677 }
34678 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34679 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34680 break;
34681
34682 case DE4X5_SET_HWADDR: /* Set the hardware address */
34683 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34684 spin_lock_irqsave(&lp->lock, flags);
34685 memcpy(&statbuf, &lp->pktStats, ioc->len);
34686 spin_unlock_irqrestore(&lp->lock, flags);
34687 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34688 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34689 return -EFAULT;
34690 break;
34691 }
34692 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34693 index 75d45f8..3d9c55b 100644
34694 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34695 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34696 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34697 struct uli_phy_ops {
34698 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34699 u16 (*read)(struct uli526x_board_info *, u8, u8);
34700 - } phy;
34701 + } __no_const phy;
34702 struct net_device *next_dev; /* next device */
34703 struct pci_dev *pdev; /* PCI device */
34704 spinlock_t lock;
34705 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34706 index d1b6cc5..cde0d97 100644
34707 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34708 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34709 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34710
34711 if (wrapped)
34712 newacc += 65536;
34713 - ACCESS_ONCE(*acc) = newacc;
34714 + ACCESS_ONCE_RW(*acc) = newacc;
34715 }
34716
34717 void be_parse_stats(struct be_adapter *adapter)
34718 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34719 index 74d749e..eefb1bd 100644
34720 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34721 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34722 @@ -31,6 +31,8 @@
34723 #include <linux/netdevice.h>
34724 #include <linux/phy.h>
34725 #include <linux/platform_device.h>
34726 +#include <linux/interrupt.h>
34727 +#include <linux/irqreturn.h>
34728 #include <net/ip.h>
34729
34730 #include "ftgmac100.h"
34731 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34732 index b901a01..1ff32ee 100644
34733 --- a/drivers/net/ethernet/faraday/ftmac100.c
34734 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34735 @@ -31,6 +31,8 @@
34736 #include <linux/module.h>
34737 #include <linux/netdevice.h>
34738 #include <linux/platform_device.h>
34739 +#include <linux/interrupt.h>
34740 +#include <linux/irqreturn.h>
34741
34742 #include "ftmac100.h"
34743
34744 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34745 index d37bfd9..5e13032 100644
34746 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34747 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34748 @@ -799,6 +799,7 @@ struct e1000_mac_operations {
34749 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34750 s32 (*read_mac_addr)(struct e1000_hw *);
34751 };
34752 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34753
34754 /*
34755 * When to use various PHY register access functions:
34756 @@ -839,6 +840,7 @@ struct e1000_phy_operations {
34757 void (*power_up)(struct e1000_hw *);
34758 void (*power_down)(struct e1000_hw *);
34759 };
34760 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34761
34762 /* Function pointers for the NVM. */
34763 struct e1000_nvm_operations {
34764 @@ -851,9 +853,10 @@ struct e1000_nvm_operations {
34765 s32 (*validate)(struct e1000_hw *);
34766 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34767 };
34768 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34769
34770 struct e1000_mac_info {
34771 - struct e1000_mac_operations ops;
34772 + e1000_mac_operations_no_const ops;
34773 u8 addr[ETH_ALEN];
34774 u8 perm_addr[ETH_ALEN];
34775
34776 @@ -894,7 +897,7 @@ struct e1000_mac_info {
34777 };
34778
34779 struct e1000_phy_info {
34780 - struct e1000_phy_operations ops;
34781 + e1000_phy_operations_no_const ops;
34782
34783 enum e1000_phy_type type;
34784
34785 @@ -928,7 +931,7 @@ struct e1000_phy_info {
34786 };
34787
34788 struct e1000_nvm_info {
34789 - struct e1000_nvm_operations ops;
34790 + e1000_nvm_operations_no_const ops;
34791
34792 enum e1000_nvm_type type;
34793 enum e1000_nvm_override override;
34794 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34795 index c2a51dc..c2bd262 100644
34796 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34797 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34798 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34799 void (*release_swfw_sync)(struct e1000_hw *, u16);
34800
34801 };
34802 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34803
34804 struct e1000_phy_operations {
34805 s32 (*acquire)(struct e1000_hw *);
34806 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34807 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34808 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34809 };
34810 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34811
34812 struct e1000_nvm_operations {
34813 s32 (*acquire)(struct e1000_hw *);
34814 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34815 s32 (*validate)(struct e1000_hw *);
34816 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34817 };
34818 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34819
34820 struct e1000_info {
34821 s32 (*get_invariants)(struct e1000_hw *);
34822 @@ -364,7 +367,7 @@ struct e1000_info {
34823 extern const struct e1000_info e1000_82575_info;
34824
34825 struct e1000_mac_info {
34826 - struct e1000_mac_operations ops;
34827 + e1000_mac_operations_no_const ops;
34828
34829 u8 addr[6];
34830 u8 perm_addr[6];
34831 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34832 };
34833
34834 struct e1000_phy_info {
34835 - struct e1000_phy_operations ops;
34836 + e1000_phy_operations_no_const ops;
34837
34838 enum e1000_phy_type type;
34839
34840 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34841 };
34842
34843 struct e1000_nvm_info {
34844 - struct e1000_nvm_operations ops;
34845 + e1000_nvm_operations_no_const ops;
34846 enum e1000_nvm_type type;
34847 enum e1000_nvm_override override;
34848
34849 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34850 s32 (*check_for_ack)(struct e1000_hw *, u16);
34851 s32 (*check_for_rst)(struct e1000_hw *, u16);
34852 };
34853 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34854
34855 struct e1000_mbx_stats {
34856 u32 msgs_tx;
34857 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34858 };
34859
34860 struct e1000_mbx_info {
34861 - struct e1000_mbx_operations ops;
34862 + e1000_mbx_operations_no_const ops;
34863 struct e1000_mbx_stats stats;
34864 u32 timeout;
34865 u32 usec_delay;
34866 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34867 index 57db3c6..aa825fc 100644
34868 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34869 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34870 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34871 s32 (*read_mac_addr)(struct e1000_hw *);
34872 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34873 };
34874 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34875
34876 struct e1000_mac_info {
34877 - struct e1000_mac_operations ops;
34878 + e1000_mac_operations_no_const ops;
34879 u8 addr[6];
34880 u8 perm_addr[6];
34881
34882 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34883 s32 (*check_for_ack)(struct e1000_hw *);
34884 s32 (*check_for_rst)(struct e1000_hw *);
34885 };
34886 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34887
34888 struct e1000_mbx_stats {
34889 u32 msgs_tx;
34890 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34891 };
34892
34893 struct e1000_mbx_info {
34894 - struct e1000_mbx_operations ops;
34895 + e1000_mbx_operations_no_const ops;
34896 struct e1000_mbx_stats stats;
34897 u32 timeout;
34898 u32 usec_delay;
34899 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34900 index d929131..aed108f 100644
34901 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34902 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34903 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34904 /* store the new cycle speed */
34905 adapter->cycle_speed = cycle_speed;
34906
34907 - ACCESS_ONCE(adapter->base_incval) = incval;
34908 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34909 smp_mb();
34910
34911 /* grab the ptp lock */
34912 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34913 index 0722f33..771758a 100644
34914 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34915 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34916 @@ -2800,6 +2800,7 @@ struct ixgbe_eeprom_operations {
34917 s32 (*update_checksum)(struct ixgbe_hw *);
34918 u16 (*calc_checksum)(struct ixgbe_hw *);
34919 };
34920 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34921
34922 struct ixgbe_mac_operations {
34923 s32 (*init_hw)(struct ixgbe_hw *);
34924 @@ -2866,6 +2867,7 @@ struct ixgbe_mac_operations {
34925 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34926 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34927 };
34928 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34929
34930 struct ixgbe_phy_operations {
34931 s32 (*identify)(struct ixgbe_hw *);
34932 @@ -2885,9 +2887,10 @@ struct ixgbe_phy_operations {
34933 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34934 s32 (*check_overtemp)(struct ixgbe_hw *);
34935 };
34936 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34937
34938 struct ixgbe_eeprom_info {
34939 - struct ixgbe_eeprom_operations ops;
34940 + ixgbe_eeprom_operations_no_const ops;
34941 enum ixgbe_eeprom_type type;
34942 u32 semaphore_delay;
34943 u16 word_size;
34944 @@ -2897,7 +2900,7 @@ struct ixgbe_eeprom_info {
34945
34946 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34947 struct ixgbe_mac_info {
34948 - struct ixgbe_mac_operations ops;
34949 + ixgbe_mac_operations_no_const ops;
34950 enum ixgbe_mac_type type;
34951 u8 addr[ETH_ALEN];
34952 u8 perm_addr[ETH_ALEN];
34953 @@ -2927,7 +2930,7 @@ struct ixgbe_mac_info {
34954 };
34955
34956 struct ixgbe_phy_info {
34957 - struct ixgbe_phy_operations ops;
34958 + ixgbe_phy_operations_no_const ops;
34959 struct mdio_if_info mdio;
34960 enum ixgbe_phy_type type;
34961 u32 id;
34962 @@ -2955,6 +2958,7 @@ struct ixgbe_mbx_operations {
34963 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34964 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34965 };
34966 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34967
34968 struct ixgbe_mbx_stats {
34969 u32 msgs_tx;
34970 @@ -2966,7 +2970,7 @@ struct ixgbe_mbx_stats {
34971 };
34972
34973 struct ixgbe_mbx_info {
34974 - struct ixgbe_mbx_operations ops;
34975 + ixgbe_mbx_operations_no_const ops;
34976 struct ixgbe_mbx_stats stats;
34977 u32 timeout;
34978 u32 usec_delay;
34979 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34980 index 47f11a5..c817d97 100644
34981 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34982 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34983 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34984 s32 (*clear_vfta)(struct ixgbe_hw *);
34985 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34986 };
34987 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34988
34989 enum ixgbe_mac_type {
34990 ixgbe_mac_unknown = 0,
34991 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34992 };
34993
34994 struct ixgbe_mac_info {
34995 - struct ixgbe_mac_operations ops;
34996 + ixgbe_mac_operations_no_const ops;
34997 u8 addr[6];
34998 u8 perm_addr[6];
34999
35000 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35001 s32 (*check_for_ack)(struct ixgbe_hw *);
35002 s32 (*check_for_rst)(struct ixgbe_hw *);
35003 };
35004 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35005
35006 struct ixgbe_mbx_stats {
35007 u32 msgs_tx;
35008 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35009 };
35010
35011 struct ixgbe_mbx_info {
35012 - struct ixgbe_mbx_operations ops;
35013 + ixgbe_mbx_operations_no_const ops;
35014 struct ixgbe_mbx_stats stats;
35015 u32 timeout;
35016 u32 udelay;
35017 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35018 index 9e0c1ee..8471f77 100644
35019 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35020 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35021 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35022 void (*link_down)(struct __vxge_hw_device *devh);
35023 void (*crit_err)(struct __vxge_hw_device *devh,
35024 enum vxge_hw_event type, u64 ext_data);
35025 -};
35026 +} __no_const;
35027
35028 /*
35029 * struct __vxge_hw_blockpool_entry - Block private data structure
35030 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35031 index 4a518a3..936b334 100644
35032 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35033 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35034 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35035 struct vxge_hw_mempool_dma *dma_object,
35036 u32 index,
35037 u32 is_last);
35038 -};
35039 +} __no_const;
35040
35041 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35042 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35043 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35044 index 927aa33..a6c2518 100644
35045 --- a/drivers/net/ethernet/realtek/r8169.c
35046 +++ b/drivers/net/ethernet/realtek/r8169.c
35047 @@ -747,22 +747,22 @@ struct rtl8169_private {
35048 struct mdio_ops {
35049 void (*write)(struct rtl8169_private *, int, int);
35050 int (*read)(struct rtl8169_private *, int);
35051 - } mdio_ops;
35052 + } __no_const mdio_ops;
35053
35054 struct pll_power_ops {
35055 void (*down)(struct rtl8169_private *);
35056 void (*up)(struct rtl8169_private *);
35057 - } pll_power_ops;
35058 + } __no_const pll_power_ops;
35059
35060 struct jumbo_ops {
35061 void (*enable)(struct rtl8169_private *);
35062 void (*disable)(struct rtl8169_private *);
35063 - } jumbo_ops;
35064 + } __no_const jumbo_ops;
35065
35066 struct csi_ops {
35067 void (*write)(struct rtl8169_private *, int, int);
35068 u32 (*read)(struct rtl8169_private *, int);
35069 - } csi_ops;
35070 + } __no_const csi_ops;
35071
35072 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35073 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35074 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
35075 index 0767043f..08c2553 100644
35076 --- a/drivers/net/ethernet/sfc/ptp.c
35077 +++ b/drivers/net/ethernet/sfc/ptp.c
35078 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
35079 (u32)((u64)ptp->start.dma_addr >> 32));
35080
35081 /* Clear flag that signals MC ready */
35082 - ACCESS_ONCE(*start) = 0;
35083 + ACCESS_ONCE_RW(*start) = 0;
35084 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
35085 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
35086
35087 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35088 index 0c74a70..3bc6f68 100644
35089 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35090 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35091 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35092
35093 writel(value, ioaddr + MMC_CNTRL);
35094
35095 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35096 - MMC_CNTRL, value);
35097 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35098 +// MMC_CNTRL, value);
35099 }
35100
35101 /* To mask all all interrupts.*/
35102 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35103 index 5fd6f46..ee1f265 100644
35104 --- a/drivers/net/hyperv/hyperv_net.h
35105 +++ b/drivers/net/hyperv/hyperv_net.h
35106 @@ -101,7 +101,7 @@ struct rndis_device {
35107
35108 enum rndis_device_state state;
35109 bool link_state;
35110 - atomic_t new_req_id;
35111 + atomic_unchecked_t new_req_id;
35112
35113 spinlock_t request_lock;
35114 struct list_head req_list;
35115 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35116 index 928148c..d83298e 100644
35117 --- a/drivers/net/hyperv/rndis_filter.c
35118 +++ b/drivers/net/hyperv/rndis_filter.c
35119 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35120 * template
35121 */
35122 set = &rndis_msg->msg.set_req;
35123 - set->req_id = atomic_inc_return(&dev->new_req_id);
35124 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35125
35126 /* Add to the request list */
35127 spin_lock_irqsave(&dev->request_lock, flags);
35128 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35129
35130 /* Setup the rndis set */
35131 halt = &request->request_msg.msg.halt_req;
35132 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35133 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35134
35135 /* Ignore return since this msg is optional. */
35136 rndis_filter_send_request(dev, request);
35137 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
35138 index 7d39add..037e1da 100644
35139 --- a/drivers/net/ieee802154/fakehard.c
35140 +++ b/drivers/net/ieee802154/fakehard.c
35141 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
35142 phy->transmit_power = 0xbf;
35143
35144 dev->netdev_ops = &fake_ops;
35145 - dev->ml_priv = &fake_mlme;
35146 + dev->ml_priv = (void *)&fake_mlme;
35147
35148 priv = netdev_priv(dev);
35149 priv->phy = phy;
35150 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35151 index daec9b0..6428fcb 100644
35152 --- a/drivers/net/phy/mdio-bitbang.c
35153 +++ b/drivers/net/phy/mdio-bitbang.c
35154 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35155 struct mdiobb_ctrl *ctrl = bus->priv;
35156
35157 module_put(ctrl->ops->owner);
35158 + mdiobus_unregister(bus);
35159 mdiobus_free(bus);
35160 }
35161 EXPORT_SYMBOL(free_mdio_bitbang);
35162 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35163 index eb3f5ce..d773730 100644
35164 --- a/drivers/net/ppp/ppp_generic.c
35165 +++ b/drivers/net/ppp/ppp_generic.c
35166 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35167 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35168 struct ppp_stats stats;
35169 struct ppp_comp_stats cstats;
35170 - char *vers;
35171
35172 switch (cmd) {
35173 case SIOCGPPPSTATS:
35174 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35175 break;
35176
35177 case SIOCGPPPVER:
35178 - vers = PPP_VERSION;
35179 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35180 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35181 break;
35182 err = 0;
35183 break;
35184 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35185 index 0873cdc..ddb178e 100644
35186 --- a/drivers/net/tun.c
35187 +++ b/drivers/net/tun.c
35188 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35189 }
35190
35191 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35192 - unsigned long arg, int ifreq_len)
35193 + unsigned long arg, size_t ifreq_len)
35194 {
35195 struct tun_file *tfile = file->private_data;
35196 struct tun_struct *tun;
35197 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35198 int vnet_hdr_sz;
35199 int ret;
35200
35201 + if (ifreq_len > sizeof ifr)
35202 + return -EFAULT;
35203 +
35204 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35205 if (copy_from_user(&ifr, argp, ifreq_len))
35206 return -EFAULT;
35207 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35208 index 605a4ba..a883dd1 100644
35209 --- a/drivers/net/usb/hso.c
35210 +++ b/drivers/net/usb/hso.c
35211 @@ -71,7 +71,7 @@
35212 #include <asm/byteorder.h>
35213 #include <linux/serial_core.h>
35214 #include <linux/serial.h>
35215 -
35216 +#include <asm/local.h>
35217
35218 #define MOD_AUTHOR "Option Wireless"
35219 #define MOD_DESCRIPTION "USB High Speed Option driver"
35220 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35221 struct urb *urb;
35222
35223 urb = serial->rx_urb[0];
35224 - if (serial->port.count > 0) {
35225 + if (atomic_read(&serial->port.count) > 0) {
35226 count = put_rxbuf_data(urb, serial);
35227 if (count == -1)
35228 return;
35229 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35230 DUMP1(urb->transfer_buffer, urb->actual_length);
35231
35232 /* Anyone listening? */
35233 - if (serial->port.count == 0)
35234 + if (atomic_read(&serial->port.count) == 0)
35235 return;
35236
35237 if (status == 0) {
35238 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35239 tty_port_tty_set(&serial->port, tty);
35240
35241 /* check for port already opened, if not set the termios */
35242 - serial->port.count++;
35243 - if (serial->port.count == 1) {
35244 + if (atomic_inc_return(&serial->port.count) == 1) {
35245 serial->rx_state = RX_IDLE;
35246 /* Force default termio settings */
35247 _hso_serial_set_termios(tty, NULL);
35248 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35249 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35250 if (result) {
35251 hso_stop_serial_device(serial->parent);
35252 - serial->port.count--;
35253 + atomic_dec(&serial->port.count);
35254 kref_put(&serial->parent->ref, hso_serial_ref_free);
35255 }
35256 } else {
35257 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35258
35259 /* reset the rts and dtr */
35260 /* do the actual close */
35261 - serial->port.count--;
35262 + atomic_dec(&serial->port.count);
35263
35264 - if (serial->port.count <= 0) {
35265 - serial->port.count = 0;
35266 + if (atomic_read(&serial->port.count) <= 0) {
35267 + atomic_set(&serial->port.count, 0);
35268 tty_port_tty_set(&serial->port, NULL);
35269 if (!usb_gone)
35270 hso_stop_serial_device(serial->parent);
35271 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35272
35273 /* the actual setup */
35274 spin_lock_irqsave(&serial->serial_lock, flags);
35275 - if (serial->port.count)
35276 + if (atomic_read(&serial->port.count))
35277 _hso_serial_set_termios(tty, old);
35278 else
35279 tty->termios = *old;
35280 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
35281 D1("Pending read interrupt on port %d\n", i);
35282 spin_lock(&serial->serial_lock);
35283 if (serial->rx_state == RX_IDLE &&
35284 - serial->port.count > 0) {
35285 + atomic_read(&serial->port.count) > 0) {
35286 /* Setup and send a ctrl req read on
35287 * port i */
35288 if (!serial->rx_urb_filled[0]) {
35289 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
35290 /* Start all serial ports */
35291 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35292 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35293 - if (dev2ser(serial_table[i])->port.count) {
35294 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35295 result =
35296 hso_start_serial_device(serial_table[i], GFP_NOIO);
35297 hso_kick_transmit(dev2ser(serial_table[i]));
35298 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35299 index 4521342..9f0a994d 100644
35300 --- a/drivers/net/wireless/ath/ath.h
35301 +++ b/drivers/net/wireless/ath/ath.h
35302 @@ -119,6 +119,7 @@ struct ath_ops {
35303 void (*write_flush) (void *);
35304 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35305 };
35306 +typedef struct ath_ops __no_const ath_ops_no_const;
35307
35308 struct ath_common;
35309 struct ath_bus_ops;
35310 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35311 index 8d78253..bebbb68 100644
35312 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35313 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35314 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35315 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35316 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35317
35318 - ACCESS_ONCE(ads->ds_link) = i->link;
35319 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35320 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35321 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35322
35323 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35324 ctl6 = SM(i->keytype, AR_EncrType);
35325 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35326
35327 if ((i->is_first || i->is_last) &&
35328 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35329 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35330 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35331 | set11nTries(i->rates, 1)
35332 | set11nTries(i->rates, 2)
35333 | set11nTries(i->rates, 3)
35334 | (i->dur_update ? AR_DurUpdateEna : 0)
35335 | SM(0, AR_BurstDur);
35336
35337 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35338 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35339 | set11nRate(i->rates, 1)
35340 | set11nRate(i->rates, 2)
35341 | set11nRate(i->rates, 3);
35342 } else {
35343 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35344 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35345 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35346 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35347 }
35348
35349 if (!i->is_first) {
35350 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35351 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35352 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35353 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35354 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35355 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35356 return;
35357 }
35358
35359 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35360 break;
35361 }
35362
35363 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35364 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35365 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35366 | SM(i->txpower, AR_XmitPower)
35367 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35368 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35369 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35370 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35371
35372 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35373 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35374 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35375 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35376
35377 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35378 return;
35379
35380 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35381 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35382 | set11nPktDurRTSCTS(i->rates, 1);
35383
35384 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35385 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35386 | set11nPktDurRTSCTS(i->rates, 3);
35387
35388 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35389 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35390 | set11nRateFlags(i->rates, 1)
35391 | set11nRateFlags(i->rates, 2)
35392 | set11nRateFlags(i->rates, 3)
35393 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35394 index 301bf72..3f5654f 100644
35395 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35396 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35397 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35398 (i->qcu << AR_TxQcuNum_S) | desc_len;
35399
35400 checksum += val;
35401 - ACCESS_ONCE(ads->info) = val;
35402 + ACCESS_ONCE_RW(ads->info) = val;
35403
35404 checksum += i->link;
35405 - ACCESS_ONCE(ads->link) = i->link;
35406 + ACCESS_ONCE_RW(ads->link) = i->link;
35407
35408 checksum += i->buf_addr[0];
35409 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35410 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35411 checksum += i->buf_addr[1];
35412 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35413 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35414 checksum += i->buf_addr[2];
35415 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35416 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35417 checksum += i->buf_addr[3];
35418 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35419 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35420
35421 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35422 - ACCESS_ONCE(ads->ctl3) = val;
35423 + ACCESS_ONCE_RW(ads->ctl3) = val;
35424 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35425 - ACCESS_ONCE(ads->ctl5) = val;
35426 + ACCESS_ONCE_RW(ads->ctl5) = val;
35427 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35428 - ACCESS_ONCE(ads->ctl7) = val;
35429 + ACCESS_ONCE_RW(ads->ctl7) = val;
35430 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35431 - ACCESS_ONCE(ads->ctl9) = val;
35432 + ACCESS_ONCE_RW(ads->ctl9) = val;
35433
35434 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35435 - ACCESS_ONCE(ads->ctl10) = checksum;
35436 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35437
35438 if (i->is_first || i->is_last) {
35439 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35440 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35441 | set11nTries(i->rates, 1)
35442 | set11nTries(i->rates, 2)
35443 | set11nTries(i->rates, 3)
35444 | (i->dur_update ? AR_DurUpdateEna : 0)
35445 | SM(0, AR_BurstDur);
35446
35447 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35448 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35449 | set11nRate(i->rates, 1)
35450 | set11nRate(i->rates, 2)
35451 | set11nRate(i->rates, 3);
35452 } else {
35453 - ACCESS_ONCE(ads->ctl13) = 0;
35454 - ACCESS_ONCE(ads->ctl14) = 0;
35455 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35456 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35457 }
35458
35459 ads->ctl20 = 0;
35460 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35461
35462 ctl17 = SM(i->keytype, AR_EncrType);
35463 if (!i->is_first) {
35464 - ACCESS_ONCE(ads->ctl11) = 0;
35465 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35466 - ACCESS_ONCE(ads->ctl15) = 0;
35467 - ACCESS_ONCE(ads->ctl16) = 0;
35468 - ACCESS_ONCE(ads->ctl17) = ctl17;
35469 - ACCESS_ONCE(ads->ctl18) = 0;
35470 - ACCESS_ONCE(ads->ctl19) = 0;
35471 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35472 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35473 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35474 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35475 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35476 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35477 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35478 return;
35479 }
35480
35481 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35482 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35483 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35484 | SM(i->txpower, AR_XmitPower)
35485 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35486 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35487 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35488 ctl12 |= SM(val, AR_PAPRDChainMask);
35489
35490 - ACCESS_ONCE(ads->ctl12) = ctl12;
35491 - ACCESS_ONCE(ads->ctl17) = ctl17;
35492 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35493 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35494
35495 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35496 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35497 | set11nPktDurRTSCTS(i->rates, 1);
35498
35499 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35500 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35501 | set11nPktDurRTSCTS(i->rates, 3);
35502
35503 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35504 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35505 | set11nRateFlags(i->rates, 1)
35506 | set11nRateFlags(i->rates, 2)
35507 | set11nRateFlags(i->rates, 3)
35508 | SM(i->rtscts_rate, AR_RTSCTSRate);
35509
35510 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35511 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35512 }
35513
35514 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35515 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35516 index dbc1b7a..addccc0 100644
35517 --- a/drivers/net/wireless/ath/ath9k/hw.h
35518 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35519 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
35520
35521 /* ANI */
35522 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35523 -};
35524 +} __no_const;
35525
35526 /**
35527 * struct ath_hw_ops - callbacks used by hardware code and driver code
35528 @@ -687,7 +687,7 @@ struct ath_hw_ops {
35529 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35530 struct ath_hw_antcomb_conf *antconf);
35531 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
35532 -};
35533 +} __no_const;
35534
35535 struct ath_nf_limits {
35536 s16 max;
35537 @@ -707,7 +707,7 @@ enum ath_cal_list {
35538 #define AH_FASTCC 0x4
35539
35540 struct ath_hw {
35541 - struct ath_ops reg_ops;
35542 + ath_ops_no_const reg_ops;
35543
35544 struct ieee80211_hw *hw;
35545 struct ath_common common;
35546 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35547 index af00e2c..ab04d34 100644
35548 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35549 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35550 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35551 void (*carrsuppr)(struct brcms_phy *);
35552 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35553 void (*detach)(struct brcms_phy *);
35554 -};
35555 +} __no_const;
35556
35557 struct brcms_phy {
35558 struct brcms_phy_pub pubpi_ro;
35559 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35560 index e252acb..6ad1e65 100644
35561 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35562 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35563 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35564 */
35565 if (il3945_mod_params.disable_hw_scan) {
35566 D_INFO("Disabling hw_scan\n");
35567 - il3945_mac_ops.hw_scan = NULL;
35568 + pax_open_kernel();
35569 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35570 + pax_close_kernel();
35571 }
35572
35573 D_INFO("*** LOAD DRIVER ***\n");
35574 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35575 index 1a98fa3..51e6661 100644
35576 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35577 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35578 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35579 {
35580 struct iwl_priv *priv = file->private_data;
35581 char buf[64];
35582 - int buf_size;
35583 + size_t buf_size;
35584 u32 offset, len;
35585
35586 memset(buf, 0, sizeof(buf));
35587 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35588 struct iwl_priv *priv = file->private_data;
35589
35590 char buf[8];
35591 - int buf_size;
35592 + size_t buf_size;
35593 u32 reset_flag;
35594
35595 memset(buf, 0, sizeof(buf));
35596 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35597 {
35598 struct iwl_priv *priv = file->private_data;
35599 char buf[8];
35600 - int buf_size;
35601 + size_t buf_size;
35602 int ht40;
35603
35604 memset(buf, 0, sizeof(buf));
35605 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35606 {
35607 struct iwl_priv *priv = file->private_data;
35608 char buf[8];
35609 - int buf_size;
35610 + size_t buf_size;
35611 int value;
35612
35613 memset(buf, 0, sizeof(buf));
35614 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35615 {
35616 struct iwl_priv *priv = file->private_data;
35617 char buf[8];
35618 - int buf_size;
35619 + size_t buf_size;
35620 int clear;
35621
35622 memset(buf, 0, sizeof(buf));
35623 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35624 {
35625 struct iwl_priv *priv = file->private_data;
35626 char buf[8];
35627 - int buf_size;
35628 + size_t buf_size;
35629 int trace;
35630
35631 memset(buf, 0, sizeof(buf));
35632 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35633 {
35634 struct iwl_priv *priv = file->private_data;
35635 char buf[8];
35636 - int buf_size;
35637 + size_t buf_size;
35638 int missed;
35639
35640 memset(buf, 0, sizeof(buf));
35641 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35642
35643 struct iwl_priv *priv = file->private_data;
35644 char buf[8];
35645 - int buf_size;
35646 + size_t buf_size;
35647 int plcp;
35648
35649 memset(buf, 0, sizeof(buf));
35650 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35651
35652 struct iwl_priv *priv = file->private_data;
35653 char buf[8];
35654 - int buf_size;
35655 + size_t buf_size;
35656 int flush;
35657
35658 memset(buf, 0, sizeof(buf));
35659 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35660
35661 struct iwl_priv *priv = file->private_data;
35662 char buf[8];
35663 - int buf_size;
35664 + size_t buf_size;
35665 int rts;
35666
35667 if (!priv->cfg->ht_params)
35668 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35669 {
35670 struct iwl_priv *priv = file->private_data;
35671 char buf[8];
35672 - int buf_size;
35673 + size_t buf_size;
35674
35675 memset(buf, 0, sizeof(buf));
35676 buf_size = min(count, sizeof(buf) - 1);
35677 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35678 struct iwl_priv *priv = file->private_data;
35679 u32 event_log_flag;
35680 char buf[8];
35681 - int buf_size;
35682 + size_t buf_size;
35683
35684 /* check that the interface is up */
35685 if (!iwl_is_ready(priv))
35686 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35687 struct iwl_priv *priv = file->private_data;
35688 char buf[8];
35689 u32 calib_disabled;
35690 - int buf_size;
35691 + size_t buf_size;
35692
35693 memset(buf, 0, sizeof(buf));
35694 buf_size = min(count, sizeof(buf) - 1);
35695 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35696 index fe0fffd..b4c5724 100644
35697 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35698 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35699 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35700 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35701
35702 char buf[8];
35703 - int buf_size;
35704 + size_t buf_size;
35705 u32 reset_flag;
35706
35707 memset(buf, 0, sizeof(buf));
35708 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35709 {
35710 struct iwl_trans *trans = file->private_data;
35711 char buf[8];
35712 - int buf_size;
35713 + size_t buf_size;
35714 int csr;
35715
35716 memset(buf, 0, sizeof(buf));
35717 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35718 index 429ca32..f86236b 100644
35719 --- a/drivers/net/wireless/mac80211_hwsim.c
35720 +++ b/drivers/net/wireless/mac80211_hwsim.c
35721 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
35722 return -EINVAL;
35723
35724 if (fake_hw_scan) {
35725 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35726 - mac80211_hwsim_ops.sw_scan_start = NULL;
35727 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35728 + pax_open_kernel();
35729 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35730 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35731 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35732 + pax_close_kernel();
35733 }
35734
35735 spin_lock_init(&hwsim_radio_lock);
35736 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35737 index c2d0ab1..fb9afe2 100644
35738 --- a/drivers/net/wireless/mwifiex/main.h
35739 +++ b/drivers/net/wireless/mwifiex/main.h
35740 @@ -603,7 +603,7 @@ struct mwifiex_if_ops {
35741 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35742 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35743 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35744 -};
35745 +} __no_const;
35746
35747 struct mwifiex_adapter {
35748 u8 iface_type;
35749 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35750 index bd1f0cb..db85ab0 100644
35751 --- a/drivers/net/wireless/rndis_wlan.c
35752 +++ b/drivers/net/wireless/rndis_wlan.c
35753 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35754
35755 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35756
35757 - if (rts_threshold < 0 || rts_threshold > 2347)
35758 + if (rts_threshold > 2347)
35759 rts_threshold = 2347;
35760
35761 tmp = cpu_to_le32(rts_threshold);
35762 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35763 index 0751b35..246ba3e 100644
35764 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35765 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35766 @@ -398,7 +398,7 @@ struct rt2x00_intf {
35767 * for hardware which doesn't support hardware
35768 * sequence counting.
35769 */
35770 - atomic_t seqno;
35771 + atomic_unchecked_t seqno;
35772 };
35773
35774 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35775 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35776 index e488b94..14b6a0c 100644
35777 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35778 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35779 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35780 * sequence counter given by mac80211.
35781 */
35782 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35783 - seqno = atomic_add_return(0x10, &intf->seqno);
35784 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35785 else
35786 - seqno = atomic_read(&intf->seqno);
35787 + seqno = atomic_read_unchecked(&intf->seqno);
35788
35789 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35790 hdr->seq_ctrl |= cpu_to_le16(seqno);
35791 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35792 index fd02060..74ee481 100644
35793 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35794 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35795 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35796 void (*reset)(struct wl1251 *wl);
35797 void (*enable_irq)(struct wl1251 *wl);
35798 void (*disable_irq)(struct wl1251 *wl);
35799 -};
35800 +} __no_const;
35801
35802 struct wl1251 {
35803 struct ieee80211_hw *hw;
35804 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35805 index 68584aa..10fc178 100644
35806 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35807 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35808 @@ -88,7 +88,7 @@ struct wlcore_ops {
35809 struct ieee80211_sta *sta,
35810 struct ieee80211_key_conf *key_conf);
35811 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
35812 -};
35813 +} __no_const;
35814
35815 enum wlcore_partitions {
35816 PART_DOWN,
35817 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35818 index d93b2b6..ae50401 100644
35819 --- a/drivers/oprofile/buffer_sync.c
35820 +++ b/drivers/oprofile/buffer_sync.c
35821 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35822 if (cookie == NO_COOKIE)
35823 offset = pc;
35824 if (cookie == INVALID_COOKIE) {
35825 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35826 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35827 offset = pc;
35828 }
35829 if (cookie != last_cookie) {
35830 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35831 /* add userspace sample */
35832
35833 if (!mm) {
35834 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35835 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35836 return 0;
35837 }
35838
35839 cookie = lookup_dcookie(mm, s->eip, &offset);
35840
35841 if (cookie == INVALID_COOKIE) {
35842 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35843 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35844 return 0;
35845 }
35846
35847 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
35848 /* ignore backtraces if failed to add a sample */
35849 if (state == sb_bt_start) {
35850 state = sb_bt_ignore;
35851 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35852 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35853 }
35854 }
35855 release_mm(mm);
35856 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35857 index c0cc4e7..44d4e54 100644
35858 --- a/drivers/oprofile/event_buffer.c
35859 +++ b/drivers/oprofile/event_buffer.c
35860 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35861 }
35862
35863 if (buffer_pos == buffer_size) {
35864 - atomic_inc(&oprofile_stats.event_lost_overflow);
35865 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35866 return;
35867 }
35868
35869 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35870 index ed2c3ec..deda85a 100644
35871 --- a/drivers/oprofile/oprof.c
35872 +++ b/drivers/oprofile/oprof.c
35873 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35874 if (oprofile_ops.switch_events())
35875 return;
35876
35877 - atomic_inc(&oprofile_stats.multiplex_counter);
35878 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35879 start_switch_worker();
35880 }
35881
35882 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35883 index 917d28e..d62d981 100644
35884 --- a/drivers/oprofile/oprofile_stats.c
35885 +++ b/drivers/oprofile/oprofile_stats.c
35886 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35887 cpu_buf->sample_invalid_eip = 0;
35888 }
35889
35890 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35891 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35892 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35893 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35894 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35895 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35896 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35897 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35898 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35899 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35900 }
35901
35902
35903 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35904 index 38b6fc0..b5cbfce 100644
35905 --- a/drivers/oprofile/oprofile_stats.h
35906 +++ b/drivers/oprofile/oprofile_stats.h
35907 @@ -13,11 +13,11 @@
35908 #include <linux/atomic.h>
35909
35910 struct oprofile_stat_struct {
35911 - atomic_t sample_lost_no_mm;
35912 - atomic_t sample_lost_no_mapping;
35913 - atomic_t bt_lost_no_mapping;
35914 - atomic_t event_lost_overflow;
35915 - atomic_t multiplex_counter;
35916 + atomic_unchecked_t sample_lost_no_mm;
35917 + atomic_unchecked_t sample_lost_no_mapping;
35918 + atomic_unchecked_t bt_lost_no_mapping;
35919 + atomic_unchecked_t event_lost_overflow;
35920 + atomic_unchecked_t multiplex_counter;
35921 };
35922
35923 extern struct oprofile_stat_struct oprofile_stats;
35924 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35925 index 849357c..b83c1e0 100644
35926 --- a/drivers/oprofile/oprofilefs.c
35927 +++ b/drivers/oprofile/oprofilefs.c
35928 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35929
35930
35931 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35932 - char const *name, atomic_t *val)
35933 + char const *name, atomic_unchecked_t *val)
35934 {
35935 return __oprofilefs_create_file(sb, root, name,
35936 &atomic_ro_fops, 0444, val);
35937 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35938 index 3f56bc0..707d642 100644
35939 --- a/drivers/parport/procfs.c
35940 +++ b/drivers/parport/procfs.c
35941 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35942
35943 *ppos += len;
35944
35945 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35946 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35947 }
35948
35949 #ifdef CONFIG_PARPORT_1284
35950 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35951
35952 *ppos += len;
35953
35954 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35955 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35956 }
35957 #endif /* IEEE1284.3 support. */
35958
35959 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35960 index 9fff878..ad0ad53 100644
35961 --- a/drivers/pci/hotplug/cpci_hotplug.h
35962 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35963 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35964 int (*hardware_test) (struct slot* slot, u32 value);
35965 u8 (*get_power) (struct slot* slot);
35966 int (*set_power) (struct slot* slot, int value);
35967 -};
35968 +} __no_const;
35969
35970 struct cpci_hp_controller {
35971 unsigned int irq;
35972 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35973 index 76ba8a1..20ca857 100644
35974 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35975 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35976 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35977
35978 void compaq_nvram_init (void __iomem *rom_start)
35979 {
35980 +
35981 +#ifndef CONFIG_PAX_KERNEXEC
35982 if (rom_start) {
35983 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35984 }
35985 +#endif
35986 +
35987 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35988
35989 /* initialize our int15 lock */
35990 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35991 index 213753b..b4abaac 100644
35992 --- a/drivers/pci/pcie/aspm.c
35993 +++ b/drivers/pci/pcie/aspm.c
35994 @@ -27,9 +27,9 @@
35995 #define MODULE_PARAM_PREFIX "pcie_aspm."
35996
35997 /* Note: those are not register definitions */
35998 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35999 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36000 -#define ASPM_STATE_L1 (4) /* L1 state */
36001 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36002 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36003 +#define ASPM_STATE_L1 (4U) /* L1 state */
36004 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36005 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36006
36007 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36008 index ec909af..e7517f3 100644
36009 --- a/drivers/pci/probe.c
36010 +++ b/drivers/pci/probe.c
36011 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36012 struct pci_bus_region region;
36013 bool bar_too_big = false, bar_disabled = false;
36014
36015 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36016 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36017
36018 /* No printks while decoding is disabled! */
36019 if (!dev->mmio_always_on) {
36020 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36021 index 9b8505c..f00870a 100644
36022 --- a/drivers/pci/proc.c
36023 +++ b/drivers/pci/proc.c
36024 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36025 static int __init pci_proc_init(void)
36026 {
36027 struct pci_dev *dev = NULL;
36028 +
36029 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36030 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36031 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36032 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36033 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36034 +#endif
36035 +#else
36036 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36037 +#endif
36038 proc_create("devices", 0, proc_bus_pci_dir,
36039 &proc_bus_pci_dev_operations);
36040 proc_initialized = 1;
36041 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36042 index 75dd651..2af4c9a 100644
36043 --- a/drivers/platform/x86/thinkpad_acpi.c
36044 +++ b/drivers/platform/x86/thinkpad_acpi.c
36045 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36046 return 0;
36047 }
36048
36049 -void static hotkey_mask_warn_incomplete_mask(void)
36050 +static void hotkey_mask_warn_incomplete_mask(void)
36051 {
36052 /* log only what the user can fix... */
36053 const u32 wantedmask = hotkey_driver_mask &
36054 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36055 }
36056 }
36057
36058 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36059 - struct tp_nvram_state *newn,
36060 - const u32 event_mask)
36061 -{
36062 -
36063 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36064 do { \
36065 if ((event_mask & (1 << __scancode)) && \
36066 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36067 tpacpi_hotkey_send_key(__scancode); \
36068 } while (0)
36069
36070 - void issue_volchange(const unsigned int oldvol,
36071 - const unsigned int newvol)
36072 - {
36073 - unsigned int i = oldvol;
36074 +static void issue_volchange(const unsigned int oldvol,
36075 + const unsigned int newvol,
36076 + const u32 event_mask)
36077 +{
36078 + unsigned int i = oldvol;
36079
36080 - while (i > newvol) {
36081 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36082 - i--;
36083 - }
36084 - while (i < newvol) {
36085 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36086 - i++;
36087 - }
36088 + while (i > newvol) {
36089 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36090 + i--;
36091 }
36092 + while (i < newvol) {
36093 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36094 + i++;
36095 + }
36096 +}
36097
36098 - void issue_brightnesschange(const unsigned int oldbrt,
36099 - const unsigned int newbrt)
36100 - {
36101 - unsigned int i = oldbrt;
36102 +static void issue_brightnesschange(const unsigned int oldbrt,
36103 + const unsigned int newbrt,
36104 + const u32 event_mask)
36105 +{
36106 + unsigned int i = oldbrt;
36107
36108 - while (i > newbrt) {
36109 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36110 - i--;
36111 - }
36112 - while (i < newbrt) {
36113 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36114 - i++;
36115 - }
36116 + while (i > newbrt) {
36117 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36118 + i--;
36119 + }
36120 + while (i < newbrt) {
36121 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36122 + i++;
36123 }
36124 +}
36125
36126 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36127 + struct tp_nvram_state *newn,
36128 + const u32 event_mask)
36129 +{
36130 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36131 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36132 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36133 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36134 oldn->volume_level != newn->volume_level) {
36135 /* recently muted, or repeated mute keypress, or
36136 * multiple presses ending in mute */
36137 - issue_volchange(oldn->volume_level, newn->volume_level);
36138 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36139 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36140 }
36141 } else {
36142 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36143 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36144 }
36145 if (oldn->volume_level != newn->volume_level) {
36146 - issue_volchange(oldn->volume_level, newn->volume_level);
36147 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36148 } else if (oldn->volume_toggle != newn->volume_toggle) {
36149 /* repeated vol up/down keypress at end of scale ? */
36150 if (newn->volume_level == 0)
36151 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36152 /* handle brightness */
36153 if (oldn->brightness_level != newn->brightness_level) {
36154 issue_brightnesschange(oldn->brightness_level,
36155 - newn->brightness_level);
36156 + newn->brightness_level,
36157 + event_mask);
36158 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36159 /* repeated key presses that didn't change state */
36160 if (newn->brightness_level == 0)
36161 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36162 && !tp_features.bright_unkfw)
36163 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36164 }
36165 +}
36166
36167 #undef TPACPI_COMPARE_KEY
36168 #undef TPACPI_MAY_SEND_KEY
36169 -}
36170
36171 /*
36172 * Polling driver
36173 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36174 index 769d265..a3a05ca 100644
36175 --- a/drivers/pnp/pnpbios/bioscalls.c
36176 +++ b/drivers/pnp/pnpbios/bioscalls.c
36177 @@ -58,7 +58,7 @@ do { \
36178 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36179 } while(0)
36180
36181 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36182 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36183 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36184
36185 /*
36186 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36187
36188 cpu = get_cpu();
36189 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36190 +
36191 + pax_open_kernel();
36192 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36193 + pax_close_kernel();
36194
36195 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36196 spin_lock_irqsave(&pnp_bios_lock, flags);
36197 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36198 :"memory");
36199 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36200
36201 + pax_open_kernel();
36202 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36203 + pax_close_kernel();
36204 +
36205 put_cpu();
36206
36207 /* If we get here and this is set then the PnP BIOS faulted on us. */
36208 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36209 return status;
36210 }
36211
36212 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36213 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36214 {
36215 int i;
36216
36217 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36218 pnp_bios_callpoint.offset = header->fields.pm16offset;
36219 pnp_bios_callpoint.segment = PNP_CS16;
36220
36221 + pax_open_kernel();
36222 +
36223 for_each_possible_cpu(i) {
36224 struct desc_struct *gdt = get_cpu_gdt_table(i);
36225 if (!gdt)
36226 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36227 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36228 (unsigned long)__va(header->fields.pm16dseg));
36229 }
36230 +
36231 + pax_close_kernel();
36232 }
36233 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36234 index b0ecacb..7c9da2e 100644
36235 --- a/drivers/pnp/resource.c
36236 +++ b/drivers/pnp/resource.c
36237 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36238 return 1;
36239
36240 /* check if the resource is valid */
36241 - if (*irq < 0 || *irq > 15)
36242 + if (*irq > 15)
36243 return 0;
36244
36245 /* check if the resource is reserved */
36246 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36247 return 1;
36248
36249 /* check if the resource is valid */
36250 - if (*dma < 0 || *dma == 4 || *dma > 7)
36251 + if (*dma == 4 || *dma > 7)
36252 return 0;
36253
36254 /* check if the resource is reserved */
36255 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36256 index 5860d4d..d90d268 100644
36257 --- a/drivers/power/bq27x00_battery.c
36258 +++ b/drivers/power/bq27x00_battery.c
36259 @@ -80,7 +80,7 @@
36260 struct bq27x00_device_info;
36261 struct bq27x00_access_methods {
36262 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36263 -};
36264 +} __no_const;
36265
36266 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36267
36268 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36269 index 8d53174..04c65de 100644
36270 --- a/drivers/regulator/max8660.c
36271 +++ b/drivers/regulator/max8660.c
36272 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36273 max8660->shadow_regs[MAX8660_OVER1] = 5;
36274 } else {
36275 /* Otherwise devices can be toggled via software */
36276 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36277 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36278 + pax_open_kernel();
36279 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36280 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36281 + pax_close_kernel();
36282 }
36283
36284 /*
36285 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36286 index 1fa6381..f58834e 100644
36287 --- a/drivers/regulator/mc13892-regulator.c
36288 +++ b/drivers/regulator/mc13892-regulator.c
36289 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36290 }
36291 mc13xxx_unlock(mc13892);
36292
36293 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36294 + pax_open_kernel();
36295 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36296 = mc13892_vcam_set_mode;
36297 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36298 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36299 = mc13892_vcam_get_mode;
36300 + pax_close_kernel();
36301
36302 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36303 ARRAY_SIZE(mc13892_regulators));
36304 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36305 index cace6d3..f623fda 100644
36306 --- a/drivers/rtc/rtc-dev.c
36307 +++ b/drivers/rtc/rtc-dev.c
36308 @@ -14,6 +14,7 @@
36309 #include <linux/module.h>
36310 #include <linux/rtc.h>
36311 #include <linux/sched.h>
36312 +#include <linux/grsecurity.h>
36313 #include "rtc-core.h"
36314
36315 static dev_t rtc_devt;
36316 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36317 if (copy_from_user(&tm, uarg, sizeof(tm)))
36318 return -EFAULT;
36319
36320 + gr_log_timechange();
36321 +
36322 return rtc_set_time(rtc, &tm);
36323
36324 case RTC_PIE_ON:
36325 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36326 index 9e933a8..4f969f7 100644
36327 --- a/drivers/scsi/aacraid/aacraid.h
36328 +++ b/drivers/scsi/aacraid/aacraid.h
36329 @@ -503,7 +503,7 @@ struct adapter_ops
36330 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36331 /* Administrative operations */
36332 int (*adapter_comm)(struct aac_dev * dev, int comm);
36333 -};
36334 +} __no_const;
36335
36336 /*
36337 * Define which interrupt handler needs to be installed
36338 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36339 index 4ad7e36..d004679 100644
36340 --- a/drivers/scsi/bfa/bfa.h
36341 +++ b/drivers/scsi/bfa/bfa.h
36342 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36343 u32 *end);
36344 int cpe_vec_q0;
36345 int rme_vec_q0;
36346 -};
36347 +} __no_const;
36348 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36349
36350 struct bfa_faa_cbfn_s {
36351 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36352 index 27b5609..e08d9c4 100644
36353 --- a/drivers/scsi/bfa/bfa_fcpim.c
36354 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36355 @@ -3731,7 +3731,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36356
36357 bfa_iotag_attach(fcp);
36358
36359 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36360 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36361 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36362 (fcp->num_itns * sizeof(struct bfa_itn_s));
36363 memset(fcp->itn_arr, 0,
36364 @@ -3799,7 +3799,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36365 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36366 {
36367 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36368 - struct bfa_itn_s *itn;
36369 + bfa_itn_s_no_const *itn;
36370
36371 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36372 itn->isr = isr;
36373 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36374 index e693af6..4faba24 100644
36375 --- a/drivers/scsi/bfa/bfa_fcpim.h
36376 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36377 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36378 struct bfa_itn_s {
36379 bfa_isr_func_t isr;
36380 };
36381 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36382
36383 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36384 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36385 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
36386 struct list_head iotag_tio_free_q; /* free IO resources */
36387 struct list_head iotag_unused_q; /* unused IO resources*/
36388 struct bfa_iotag_s *iotag_arr;
36389 - struct bfa_itn_s *itn_arr;
36390 + bfa_itn_s_no_const *itn_arr;
36391 int max_ioim_reqs;
36392 int num_ioim_reqs;
36393 int num_fwtio_reqs;
36394 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36395 index 23a90e7..9cf04ee 100644
36396 --- a/drivers/scsi/bfa/bfa_ioc.h
36397 +++ b/drivers/scsi/bfa/bfa_ioc.h
36398 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36399 bfa_ioc_disable_cbfn_t disable_cbfn;
36400 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36401 bfa_ioc_reset_cbfn_t reset_cbfn;
36402 -};
36403 +} __no_const;
36404
36405 /*
36406 * IOC event notification mechanism.
36407 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36408 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36409 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36410 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36411 -};
36412 +} __no_const;
36413
36414 /*
36415 * Queue element to wait for room in request queue. FIFO order is
36416 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36417 index 593085a..47aa999 100644
36418 --- a/drivers/scsi/hosts.c
36419 +++ b/drivers/scsi/hosts.c
36420 @@ -42,7 +42,7 @@
36421 #include "scsi_logging.h"
36422
36423
36424 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36425 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36426
36427
36428 static void scsi_host_cls_release(struct device *dev)
36429 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36430 * subtract one because we increment first then return, but we need to
36431 * know what the next host number was before increment
36432 */
36433 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36434 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36435 shost->dma_channel = 0xff;
36436
36437 /* These three are default values which can be overridden */
36438 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36439 index 4217e49..9c77e3e 100644
36440 --- a/drivers/scsi/hpsa.c
36441 +++ b/drivers/scsi/hpsa.c
36442 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36443 unsigned long flags;
36444
36445 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36446 - return h->access.command_completed(h, q);
36447 + return h->access->command_completed(h, q);
36448
36449 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36450 a = rq->head[rq->current_entry];
36451 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
36452 while (!list_empty(&h->reqQ)) {
36453 c = list_entry(h->reqQ.next, struct CommandList, list);
36454 /* can't do anything if fifo is full */
36455 - if ((h->access.fifo_full(h))) {
36456 + if ((h->access->fifo_full(h))) {
36457 dev_warn(&h->pdev->dev, "fifo full\n");
36458 break;
36459 }
36460 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
36461
36462 /* Tell the controller execute command */
36463 spin_unlock_irqrestore(&h->lock, flags);
36464 - h->access.submit_command(h, c);
36465 + h->access->submit_command(h, c);
36466 spin_lock_irqsave(&h->lock, flags);
36467 }
36468 spin_unlock_irqrestore(&h->lock, flags);
36469 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
36470
36471 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36472 {
36473 - return h->access.command_completed(h, q);
36474 + return h->access->command_completed(h, q);
36475 }
36476
36477 static inline bool interrupt_pending(struct ctlr_info *h)
36478 {
36479 - return h->access.intr_pending(h);
36480 + return h->access->intr_pending(h);
36481 }
36482
36483 static inline long interrupt_not_for_us(struct ctlr_info *h)
36484 {
36485 - return (h->access.intr_pending(h) == 0) ||
36486 + return (h->access->intr_pending(h) == 0) ||
36487 (h->interrupts_enabled == 0);
36488 }
36489
36490 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36491 if (prod_index < 0)
36492 return -ENODEV;
36493 h->product_name = products[prod_index].product_name;
36494 - h->access = *(products[prod_index].access);
36495 + h->access = products[prod_index].access;
36496
36497 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36498 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36499 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36500
36501 assert_spin_locked(&lockup_detector_lock);
36502 remove_ctlr_from_lockup_detector_list(h);
36503 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36504 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36505 spin_lock_irqsave(&h->lock, flags);
36506 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36507 spin_unlock_irqrestore(&h->lock, flags);
36508 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
36509 }
36510
36511 /* make sure the board interrupts are off */
36512 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36513 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36514
36515 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36516 goto clean2;
36517 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
36518 * fake ones to scoop up any residual completions.
36519 */
36520 spin_lock_irqsave(&h->lock, flags);
36521 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36522 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36523 spin_unlock_irqrestore(&h->lock, flags);
36524 free_irqs(h);
36525 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36526 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
36527 dev_info(&h->pdev->dev, "Board READY.\n");
36528 dev_info(&h->pdev->dev,
36529 "Waiting for stale completions to drain.\n");
36530 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36531 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36532 msleep(10000);
36533 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36534 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36535
36536 rc = controller_reset_failed(h->cfgtable);
36537 if (rc)
36538 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
36539 }
36540
36541 /* Turn the interrupts on so we can service requests */
36542 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36543 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36544
36545 hpsa_hba_inquiry(h);
36546 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36547 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36548 * To write all data in the battery backed cache to disks
36549 */
36550 hpsa_flush_cache(h);
36551 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36552 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36553 hpsa_free_irqs_and_disable_msix(h);
36554 }
36555
36556 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36557 return;
36558 }
36559 /* Change the access methods to the performant access methods */
36560 - h->access = SA5_performant_access;
36561 + h->access = &SA5_performant_access;
36562 h->transMethod = CFGTBL_Trans_Performant;
36563 }
36564
36565 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36566 index 9816479..c5d4e97 100644
36567 --- a/drivers/scsi/hpsa.h
36568 +++ b/drivers/scsi/hpsa.h
36569 @@ -79,7 +79,7 @@ struct ctlr_info {
36570 unsigned int msix_vector;
36571 unsigned int msi_vector;
36572 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36573 - struct access_method access;
36574 + struct access_method *access;
36575
36576 /* queue and queue Info */
36577 struct list_head reqQ;
36578 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36579 index f2df059..a3a9930 100644
36580 --- a/drivers/scsi/ips.h
36581 +++ b/drivers/scsi/ips.h
36582 @@ -1027,7 +1027,7 @@ typedef struct {
36583 int (*intr)(struct ips_ha *);
36584 void (*enableint)(struct ips_ha *);
36585 uint32_t (*statupd)(struct ips_ha *);
36586 -} ips_hw_func_t;
36587 +} __no_const ips_hw_func_t;
36588
36589 typedef struct ips_ha {
36590 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36591 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36592 index c772d8d..35c362c 100644
36593 --- a/drivers/scsi/libfc/fc_exch.c
36594 +++ b/drivers/scsi/libfc/fc_exch.c
36595 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36596 u16 pool_max_index;
36597
36598 struct {
36599 - atomic_t no_free_exch;
36600 - atomic_t no_free_exch_xid;
36601 - atomic_t xid_not_found;
36602 - atomic_t xid_busy;
36603 - atomic_t seq_not_found;
36604 - atomic_t non_bls_resp;
36605 + atomic_unchecked_t no_free_exch;
36606 + atomic_unchecked_t no_free_exch_xid;
36607 + atomic_unchecked_t xid_not_found;
36608 + atomic_unchecked_t xid_busy;
36609 + atomic_unchecked_t seq_not_found;
36610 + atomic_unchecked_t non_bls_resp;
36611 } stats;
36612 };
36613
36614 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36615 /* allocate memory for exchange */
36616 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36617 if (!ep) {
36618 - atomic_inc(&mp->stats.no_free_exch);
36619 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36620 goto out;
36621 }
36622 memset(ep, 0, sizeof(*ep));
36623 @@ -786,7 +786,7 @@ out:
36624 return ep;
36625 err:
36626 spin_unlock_bh(&pool->lock);
36627 - atomic_inc(&mp->stats.no_free_exch_xid);
36628 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36629 mempool_free(ep, mp->ep_pool);
36630 return NULL;
36631 }
36632 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36633 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36634 ep = fc_exch_find(mp, xid);
36635 if (!ep) {
36636 - atomic_inc(&mp->stats.xid_not_found);
36637 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36638 reject = FC_RJT_OX_ID;
36639 goto out;
36640 }
36641 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36642 ep = fc_exch_find(mp, xid);
36643 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36644 if (ep) {
36645 - atomic_inc(&mp->stats.xid_busy);
36646 + atomic_inc_unchecked(&mp->stats.xid_busy);
36647 reject = FC_RJT_RX_ID;
36648 goto rel;
36649 }
36650 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36651 }
36652 xid = ep->xid; /* get our XID */
36653 } else if (!ep) {
36654 - atomic_inc(&mp->stats.xid_not_found);
36655 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36656 reject = FC_RJT_RX_ID; /* XID not found */
36657 goto out;
36658 }
36659 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36660 } else {
36661 sp = &ep->seq;
36662 if (sp->id != fh->fh_seq_id) {
36663 - atomic_inc(&mp->stats.seq_not_found);
36664 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36665 if (f_ctl & FC_FC_END_SEQ) {
36666 /*
36667 * Update sequence_id based on incoming last
36668 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36669
36670 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36671 if (!ep) {
36672 - atomic_inc(&mp->stats.xid_not_found);
36673 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36674 goto out;
36675 }
36676 if (ep->esb_stat & ESB_ST_COMPLETE) {
36677 - atomic_inc(&mp->stats.xid_not_found);
36678 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36679 goto rel;
36680 }
36681 if (ep->rxid == FC_XID_UNKNOWN)
36682 ep->rxid = ntohs(fh->fh_rx_id);
36683 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36684 - atomic_inc(&mp->stats.xid_not_found);
36685 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36686 goto rel;
36687 }
36688 if (ep->did != ntoh24(fh->fh_s_id) &&
36689 ep->did != FC_FID_FLOGI) {
36690 - atomic_inc(&mp->stats.xid_not_found);
36691 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36692 goto rel;
36693 }
36694 sof = fr_sof(fp);
36695 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36696 sp->ssb_stat |= SSB_ST_RESP;
36697 sp->id = fh->fh_seq_id;
36698 } else if (sp->id != fh->fh_seq_id) {
36699 - atomic_inc(&mp->stats.seq_not_found);
36700 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36701 goto rel;
36702 }
36703
36704 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36705 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36706
36707 if (!sp)
36708 - atomic_inc(&mp->stats.xid_not_found);
36709 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36710 else
36711 - atomic_inc(&mp->stats.non_bls_resp);
36712 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36713
36714 fc_frame_free(fp);
36715 }
36716 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36717
36718 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36719 mp = ema->mp;
36720 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36721 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36722 st->fc_no_free_exch_xid +=
36723 - atomic_read(&mp->stats.no_free_exch_xid);
36724 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36725 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36726 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36727 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36728 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36729 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36730 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36731 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36732 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36733 }
36734 }
36735 EXPORT_SYMBOL(fc_exch_update_stats);
36736 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36737 index bdb81cd..d3c7c2c 100644
36738 --- a/drivers/scsi/libsas/sas_ata.c
36739 +++ b/drivers/scsi/libsas/sas_ata.c
36740 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36741 .postreset = ata_std_postreset,
36742 .error_handler = ata_std_error_handler,
36743 .post_internal_cmd = sas_ata_post_internal,
36744 - .qc_defer = ata_std_qc_defer,
36745 + .qc_defer = ata_std_qc_defer,
36746 .qc_prep = ata_noop_qc_prep,
36747 .qc_issue = sas_ata_qc_issue,
36748 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36749 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36750 index 69b5993..1ac9dce 100644
36751 --- a/drivers/scsi/lpfc/lpfc.h
36752 +++ b/drivers/scsi/lpfc/lpfc.h
36753 @@ -424,7 +424,7 @@ struct lpfc_vport {
36754 struct dentry *debug_nodelist;
36755 struct dentry *vport_debugfs_root;
36756 struct lpfc_debugfs_trc *disc_trc;
36757 - atomic_t disc_trc_cnt;
36758 + atomic_unchecked_t disc_trc_cnt;
36759 #endif
36760 uint8_t stat_data_enabled;
36761 uint8_t stat_data_blocked;
36762 @@ -840,8 +840,8 @@ struct lpfc_hba {
36763 struct timer_list fabric_block_timer;
36764 unsigned long bit_flags;
36765 #define FABRIC_COMANDS_BLOCKED 0
36766 - atomic_t num_rsrc_err;
36767 - atomic_t num_cmd_success;
36768 + atomic_unchecked_t num_rsrc_err;
36769 + atomic_unchecked_t num_cmd_success;
36770 unsigned long last_rsrc_error_time;
36771 unsigned long last_ramp_down_time;
36772 unsigned long last_ramp_up_time;
36773 @@ -877,7 +877,7 @@ struct lpfc_hba {
36774
36775 struct dentry *debug_slow_ring_trc;
36776 struct lpfc_debugfs_trc *slow_ring_trc;
36777 - atomic_t slow_ring_trc_cnt;
36778 + atomic_unchecked_t slow_ring_trc_cnt;
36779 /* iDiag debugfs sub-directory */
36780 struct dentry *idiag_root;
36781 struct dentry *idiag_pci_cfg;
36782 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36783 index f63f5ff..de29189 100644
36784 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36785 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36786 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36787
36788 #include <linux/debugfs.h>
36789
36790 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36791 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36792 static unsigned long lpfc_debugfs_start_time = 0L;
36793
36794 /* iDiag */
36795 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36796 lpfc_debugfs_enable = 0;
36797
36798 len = 0;
36799 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36800 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36801 (lpfc_debugfs_max_disc_trc - 1);
36802 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36803 dtp = vport->disc_trc + i;
36804 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36805 lpfc_debugfs_enable = 0;
36806
36807 len = 0;
36808 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36809 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36810 (lpfc_debugfs_max_slow_ring_trc - 1);
36811 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36812 dtp = phba->slow_ring_trc + i;
36813 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36814 !vport || !vport->disc_trc)
36815 return;
36816
36817 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36818 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36819 (lpfc_debugfs_max_disc_trc - 1);
36820 dtp = vport->disc_trc + index;
36821 dtp->fmt = fmt;
36822 dtp->data1 = data1;
36823 dtp->data2 = data2;
36824 dtp->data3 = data3;
36825 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36826 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36827 dtp->jif = jiffies;
36828 #endif
36829 return;
36830 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36831 !phba || !phba->slow_ring_trc)
36832 return;
36833
36834 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36835 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36836 (lpfc_debugfs_max_slow_ring_trc - 1);
36837 dtp = phba->slow_ring_trc + index;
36838 dtp->fmt = fmt;
36839 dtp->data1 = data1;
36840 dtp->data2 = data2;
36841 dtp->data3 = data3;
36842 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36843 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36844 dtp->jif = jiffies;
36845 #endif
36846 return;
36847 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36848 "slow_ring buffer\n");
36849 goto debug_failed;
36850 }
36851 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36852 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36853 memset(phba->slow_ring_trc, 0,
36854 (sizeof(struct lpfc_debugfs_trc) *
36855 lpfc_debugfs_max_slow_ring_trc));
36856 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36857 "buffer\n");
36858 goto debug_failed;
36859 }
36860 - atomic_set(&vport->disc_trc_cnt, 0);
36861 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36862
36863 snprintf(name, sizeof(name), "discovery_trace");
36864 vport->debug_disc_trc =
36865 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36866 index 7dc4218..3436f08 100644
36867 --- a/drivers/scsi/lpfc/lpfc_init.c
36868 +++ b/drivers/scsi/lpfc/lpfc_init.c
36869 @@ -10589,8 +10589,10 @@ lpfc_init(void)
36870 "misc_register returned with status %d", error);
36871
36872 if (lpfc_enable_npiv) {
36873 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36874 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36875 + pax_open_kernel();
36876 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36877 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36878 + pax_close_kernel();
36879 }
36880 lpfc_transport_template =
36881 fc_attach_transport(&lpfc_transport_functions);
36882 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36883 index 7f45ac9..cf62eda 100644
36884 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36885 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36886 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36887 uint32_t evt_posted;
36888
36889 spin_lock_irqsave(&phba->hbalock, flags);
36890 - atomic_inc(&phba->num_rsrc_err);
36891 + atomic_inc_unchecked(&phba->num_rsrc_err);
36892 phba->last_rsrc_error_time = jiffies;
36893
36894 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36895 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36896 unsigned long flags;
36897 struct lpfc_hba *phba = vport->phba;
36898 uint32_t evt_posted;
36899 - atomic_inc(&phba->num_cmd_success);
36900 + atomic_inc_unchecked(&phba->num_cmd_success);
36901
36902 if (vport->cfg_lun_queue_depth <= queue_depth)
36903 return;
36904 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36905 unsigned long num_rsrc_err, num_cmd_success;
36906 int i;
36907
36908 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36909 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36910 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36911 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36912
36913 /*
36914 * The error and success command counters are global per
36915 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36916 }
36917 }
36918 lpfc_destroy_vport_work_array(phba, vports);
36919 - atomic_set(&phba->num_rsrc_err, 0);
36920 - atomic_set(&phba->num_cmd_success, 0);
36921 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36922 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36923 }
36924
36925 /**
36926 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36927 }
36928 }
36929 lpfc_destroy_vport_work_array(phba, vports);
36930 - atomic_set(&phba->num_rsrc_err, 0);
36931 - atomic_set(&phba->num_cmd_success, 0);
36932 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36933 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36934 }
36935
36936 /**
36937 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36938 index af763ea..41904f7 100644
36939 --- a/drivers/scsi/pmcraid.c
36940 +++ b/drivers/scsi/pmcraid.c
36941 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36942 res->scsi_dev = scsi_dev;
36943 scsi_dev->hostdata = res;
36944 res->change_detected = 0;
36945 - atomic_set(&res->read_failures, 0);
36946 - atomic_set(&res->write_failures, 0);
36947 + atomic_set_unchecked(&res->read_failures, 0);
36948 + atomic_set_unchecked(&res->write_failures, 0);
36949 rc = 0;
36950 }
36951 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36952 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36953
36954 /* If this was a SCSI read/write command keep count of errors */
36955 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36956 - atomic_inc(&res->read_failures);
36957 + atomic_inc_unchecked(&res->read_failures);
36958 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36959 - atomic_inc(&res->write_failures);
36960 + atomic_inc_unchecked(&res->write_failures);
36961
36962 if (!RES_IS_GSCSI(res->cfg_entry) &&
36963 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36964 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36965 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36966 * hrrq_id assigned here in queuecommand
36967 */
36968 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36969 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36970 pinstance->num_hrrq;
36971 cmd->cmd_done = pmcraid_io_done;
36972
36973 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36974 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36975 * hrrq_id assigned here in queuecommand
36976 */
36977 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36978 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36979 pinstance->num_hrrq;
36980
36981 if (request_size) {
36982 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36983
36984 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36985 /* add resources only after host is added into system */
36986 - if (!atomic_read(&pinstance->expose_resources))
36987 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36988 return;
36989
36990 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36991 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36992 init_waitqueue_head(&pinstance->reset_wait_q);
36993
36994 atomic_set(&pinstance->outstanding_cmds, 0);
36995 - atomic_set(&pinstance->last_message_id, 0);
36996 - atomic_set(&pinstance->expose_resources, 0);
36997 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36998 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36999
37000 INIT_LIST_HEAD(&pinstance->free_res_q);
37001 INIT_LIST_HEAD(&pinstance->used_res_q);
37002 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37003 /* Schedule worker thread to handle CCN and take care of adding and
37004 * removing devices to OS
37005 */
37006 - atomic_set(&pinstance->expose_resources, 1);
37007 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37008 schedule_work(&pinstance->worker_q);
37009 return rc;
37010
37011 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37012 index e1d150f..6c6df44 100644
37013 --- a/drivers/scsi/pmcraid.h
37014 +++ b/drivers/scsi/pmcraid.h
37015 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37016 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37017
37018 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37019 - atomic_t last_message_id;
37020 + atomic_unchecked_t last_message_id;
37021
37022 /* configuration table */
37023 struct pmcraid_config_table *cfg_table;
37024 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37025 atomic_t outstanding_cmds;
37026
37027 /* should add/delete resources to mid-layer now ?*/
37028 - atomic_t expose_resources;
37029 + atomic_unchecked_t expose_resources;
37030
37031
37032
37033 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37034 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37035 };
37036 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37037 - atomic_t read_failures; /* count of failed READ commands */
37038 - atomic_t write_failures; /* count of failed WRITE commands */
37039 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37040 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37041
37042 /* To indicate add/delete/modify during CCN */
37043 u8 change_detected;
37044 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37045 index 1c28215..86991a1 100644
37046 --- a/drivers/scsi/qla2xxx/qla_attr.c
37047 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37048 @@ -1970,7 +1970,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37049 return 0;
37050 }
37051
37052 -struct fc_function_template qla2xxx_transport_functions = {
37053 +fc_function_template_no_const qla2xxx_transport_functions = {
37054
37055 .show_host_node_name = 1,
37056 .show_host_port_name = 1,
37057 @@ -2017,7 +2017,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37058 .bsg_timeout = qla24xx_bsg_timeout,
37059 };
37060
37061 -struct fc_function_template qla2xxx_transport_vport_functions = {
37062 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37063
37064 .show_host_node_name = 1,
37065 .show_host_port_name = 1,
37066 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37067 index a9725bf..18eeb73 100644
37068 --- a/drivers/scsi/qla2xxx/qla_def.h
37069 +++ b/drivers/scsi/qla2xxx/qla_def.h
37070 @@ -2385,7 +2385,7 @@ struct isp_operations {
37071 int (*start_scsi) (srb_t *);
37072 int (*abort_isp) (struct scsi_qla_host *);
37073 int (*iospace_config)(struct qla_hw_data*);
37074 -};
37075 +} __no_const;
37076
37077 /* MSI-X Support *************************************************************/
37078
37079 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37080 index 6acb397..d86e3e0 100644
37081 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37082 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37083 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37084 struct device_attribute;
37085 extern struct device_attribute *qla2x00_host_attrs[];
37086 struct fc_function_template;
37087 -extern struct fc_function_template qla2xxx_transport_functions;
37088 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37089 +extern fc_function_template_no_const qla2xxx_transport_functions;
37090 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37091 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37092 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37093 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37094 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37095 index 329d553..f20d31d 100644
37096 --- a/drivers/scsi/qla4xxx/ql4_def.h
37097 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37098 @@ -273,7 +273,7 @@ struct ddb_entry {
37099 * (4000 only) */
37100 atomic_t relogin_timer; /* Max Time to wait for
37101 * relogin to complete */
37102 - atomic_t relogin_retry_count; /* Num of times relogin has been
37103 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37104 * retried */
37105 uint32_t default_time2wait; /* Default Min time between
37106 * relogins (+aens) */
37107 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37108 index fbc546e..c7d1b48 100644
37109 --- a/drivers/scsi/qla4xxx/ql4_os.c
37110 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37111 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37112 */
37113 if (!iscsi_is_session_online(cls_sess)) {
37114 /* Reset retry relogin timer */
37115 - atomic_inc(&ddb_entry->relogin_retry_count);
37116 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37117 DEBUG2(ql4_printk(KERN_INFO, ha,
37118 "%s: index[%d] relogin timed out-retrying"
37119 " relogin (%d), retry (%d)\n", __func__,
37120 ddb_entry->fw_ddb_index,
37121 - atomic_read(&ddb_entry->relogin_retry_count),
37122 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37123 ddb_entry->default_time2wait + 4));
37124 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37125 atomic_set(&ddb_entry->retry_relogin_timer,
37126 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37127
37128 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37129 atomic_set(&ddb_entry->relogin_timer, 0);
37130 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37131 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37132 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37133 ddb_entry->default_relogin_timeout =
37134 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37135 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37136 index 2c0d0ec..4e8681a 100644
37137 --- a/drivers/scsi/scsi.c
37138 +++ b/drivers/scsi/scsi.c
37139 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37140 unsigned long timeout;
37141 int rtn = 0;
37142
37143 - atomic_inc(&cmd->device->iorequest_cnt);
37144 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37145
37146 /* check if the device is still usable */
37147 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37148 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37149 index 9032e91..7a805d0 100644
37150 --- a/drivers/scsi/scsi_lib.c
37151 +++ b/drivers/scsi/scsi_lib.c
37152 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37153 shost = sdev->host;
37154 scsi_init_cmd_errh(cmd);
37155 cmd->result = DID_NO_CONNECT << 16;
37156 - atomic_inc(&cmd->device->iorequest_cnt);
37157 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37158
37159 /*
37160 * SCSI request completion path will do scsi_device_unbusy(),
37161 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
37162
37163 INIT_LIST_HEAD(&cmd->eh_entry);
37164
37165 - atomic_inc(&cmd->device->iodone_cnt);
37166 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37167 if (cmd->result)
37168 - atomic_inc(&cmd->device->ioerr_cnt);
37169 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37170
37171 disposition = scsi_decide_disposition(cmd);
37172 if (disposition != SUCCESS &&
37173 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37174 index ce5224c..8c6d071 100644
37175 --- a/drivers/scsi/scsi_sysfs.c
37176 +++ b/drivers/scsi/scsi_sysfs.c
37177 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37178 char *buf) \
37179 { \
37180 struct scsi_device *sdev = to_scsi_device(dev); \
37181 - unsigned long long count = atomic_read(&sdev->field); \
37182 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37183 return snprintf(buf, 20, "0x%llx\n", count); \
37184 } \
37185 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37186 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37187 index 84a1fdf..693b0d6 100644
37188 --- a/drivers/scsi/scsi_tgt_lib.c
37189 +++ b/drivers/scsi/scsi_tgt_lib.c
37190 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37191 int err;
37192
37193 dprintk("%lx %u\n", uaddr, len);
37194 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37195 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37196 if (err) {
37197 /*
37198 * TODO: need to fixup sg_tablesize, max_segment_size,
37199 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37200 index e894ca7..de9d7660 100644
37201 --- a/drivers/scsi/scsi_transport_fc.c
37202 +++ b/drivers/scsi/scsi_transport_fc.c
37203 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37204 * Netlink Infrastructure
37205 */
37206
37207 -static atomic_t fc_event_seq;
37208 +static atomic_unchecked_t fc_event_seq;
37209
37210 /**
37211 * fc_get_event_number - Obtain the next sequential FC event number
37212 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37213 u32
37214 fc_get_event_number(void)
37215 {
37216 - return atomic_add_return(1, &fc_event_seq);
37217 + return atomic_add_return_unchecked(1, &fc_event_seq);
37218 }
37219 EXPORT_SYMBOL(fc_get_event_number);
37220
37221 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37222 {
37223 int error;
37224
37225 - atomic_set(&fc_event_seq, 0);
37226 + atomic_set_unchecked(&fc_event_seq, 0);
37227
37228 error = transport_class_register(&fc_host_class);
37229 if (error)
37230 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37231 char *cp;
37232
37233 *val = simple_strtoul(buf, &cp, 0);
37234 - if ((*cp && (*cp != '\n')) || (*val < 0))
37235 + if (*cp && (*cp != '\n'))
37236 return -EINVAL;
37237 /*
37238 * Check for overflow; dev_loss_tmo is u32
37239 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37240 index 31969f2..2b348f0 100644
37241 --- a/drivers/scsi/scsi_transport_iscsi.c
37242 +++ b/drivers/scsi/scsi_transport_iscsi.c
37243 @@ -79,7 +79,7 @@ struct iscsi_internal {
37244 struct transport_container session_cont;
37245 };
37246
37247 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37248 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37249 static struct workqueue_struct *iscsi_eh_timer_workq;
37250
37251 static DEFINE_IDA(iscsi_sess_ida);
37252 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37253 int err;
37254
37255 ihost = shost->shost_data;
37256 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37257 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37258
37259 if (target_id == ISCSI_MAX_TARGET) {
37260 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37261 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37262 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37263 ISCSI_TRANSPORT_VERSION);
37264
37265 - atomic_set(&iscsi_session_nr, 0);
37266 + atomic_set_unchecked(&iscsi_session_nr, 0);
37267
37268 err = class_register(&iscsi_transport_class);
37269 if (err)
37270 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37271 index 21a045e..ec89e03 100644
37272 --- a/drivers/scsi/scsi_transport_srp.c
37273 +++ b/drivers/scsi/scsi_transport_srp.c
37274 @@ -33,7 +33,7 @@
37275 #include "scsi_transport_srp_internal.h"
37276
37277 struct srp_host_attrs {
37278 - atomic_t next_port_id;
37279 + atomic_unchecked_t next_port_id;
37280 };
37281 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37282
37283 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37284 struct Scsi_Host *shost = dev_to_shost(dev);
37285 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37286
37287 - atomic_set(&srp_host->next_port_id, 0);
37288 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37289 return 0;
37290 }
37291
37292 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37293 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37294 rport->roles = ids->roles;
37295
37296 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37297 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37298 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37299
37300 transport_setup_device(&rport->dev);
37301 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37302 index 352bc77..c049b14 100644
37303 --- a/drivers/scsi/sd.c
37304 +++ b/drivers/scsi/sd.c
37305 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
37306 sdkp->disk = gd;
37307 sdkp->index = index;
37308 atomic_set(&sdkp->openers, 0);
37309 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37310 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37311
37312 if (!sdp->request_queue->rq_timeout) {
37313 if (sdp->type != TYPE_MOD)
37314 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37315 index be2c9a6..275525c 100644
37316 --- a/drivers/scsi/sg.c
37317 +++ b/drivers/scsi/sg.c
37318 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37319 sdp->disk->disk_name,
37320 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37321 NULL,
37322 - (char *)arg);
37323 + (char __user *)arg);
37324 case BLKTRACESTART:
37325 return blk_trace_startstop(sdp->device->request_queue, 1);
37326 case BLKTRACESTOP:
37327 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37328 index 84c2861..ece0a31 100644
37329 --- a/drivers/spi/spi.c
37330 +++ b/drivers/spi/spi.c
37331 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37332 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37333
37334 /* portable code must never pass more than 32 bytes */
37335 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37336 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37337
37338 static u8 *buf;
37339
37340 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37341 index 34afc16..ffe44dd 100644
37342 --- a/drivers/staging/octeon/ethernet-rx.c
37343 +++ b/drivers/staging/octeon/ethernet-rx.c
37344 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37345 /* Increment RX stats for virtual ports */
37346 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37347 #ifdef CONFIG_64BIT
37348 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37349 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37350 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37351 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37352 #else
37353 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37354 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37355 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37356 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37357 #endif
37358 }
37359 netif_receive_skb(skb);
37360 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37361 dev->name);
37362 */
37363 #ifdef CONFIG_64BIT
37364 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37365 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37366 #else
37367 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37368 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37369 #endif
37370 dev_kfree_skb_irq(skb);
37371 }
37372 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37373 index 683bedc..86dba9a 100644
37374 --- a/drivers/staging/octeon/ethernet.c
37375 +++ b/drivers/staging/octeon/ethernet.c
37376 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37377 * since the RX tasklet also increments it.
37378 */
37379 #ifdef CONFIG_64BIT
37380 - atomic64_add(rx_status.dropped_packets,
37381 - (atomic64_t *)&priv->stats.rx_dropped);
37382 + atomic64_add_unchecked(rx_status.dropped_packets,
37383 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37384 #else
37385 - atomic_add(rx_status.dropped_packets,
37386 - (atomic_t *)&priv->stats.rx_dropped);
37387 + atomic_add_unchecked(rx_status.dropped_packets,
37388 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37389 #endif
37390 }
37391
37392 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
37393 index a2b7e03..aaf3630 100644
37394 --- a/drivers/staging/ramster/tmem.c
37395 +++ b/drivers/staging/ramster/tmem.c
37396 @@ -50,25 +50,25 @@
37397 * A tmem host implementation must use this function to register callbacks
37398 * for memory allocation.
37399 */
37400 -static struct tmem_hostops tmem_hostops;
37401 +static struct tmem_hostops *tmem_hostops;
37402
37403 static void tmem_objnode_tree_init(void);
37404
37405 void tmem_register_hostops(struct tmem_hostops *m)
37406 {
37407 tmem_objnode_tree_init();
37408 - tmem_hostops = *m;
37409 + tmem_hostops = m;
37410 }
37411
37412 /*
37413 * A tmem host implementation must use this function to register
37414 * callbacks for a page-accessible memory (PAM) implementation.
37415 */
37416 -static struct tmem_pamops tmem_pamops;
37417 +static struct tmem_pamops *tmem_pamops;
37418
37419 void tmem_register_pamops(struct tmem_pamops *m)
37420 {
37421 - tmem_pamops = *m;
37422 + tmem_pamops = m;
37423 }
37424
37425 /*
37426 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
37427 obj->pampd_count = 0;
37428 #ifdef CONFIG_RAMSTER
37429 if (tmem_pamops.new_obj != NULL)
37430 - (*tmem_pamops.new_obj)(obj);
37431 + (tmem_pamops->new_obj)(obj);
37432 #endif
37433 SET_SENTINEL(obj, OBJ);
37434
37435 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
37436 rbnode = rb_next(rbnode);
37437 tmem_pampd_destroy_all_in_obj(obj, true);
37438 tmem_obj_free(obj, hb);
37439 - (*tmem_hostops.obj_free)(obj, pool);
37440 + (tmem_hostops->obj_free)(obj, pool);
37441 }
37442 spin_unlock(&hb->lock);
37443 }
37444 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
37445 ASSERT_SENTINEL(obj, OBJ);
37446 BUG_ON(obj->pool == NULL);
37447 ASSERT_SENTINEL(obj->pool, POOL);
37448 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
37449 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
37450 if (unlikely(objnode == NULL))
37451 goto out;
37452 objnode->obj = obj;
37453 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
37454 ASSERT_SENTINEL(pool, POOL);
37455 objnode->obj->objnode_count--;
37456 objnode->obj = NULL;
37457 - (*tmem_hostops.objnode_free)(objnode, pool);
37458 + (tmem_hostops->objnode_free)(objnode, pool);
37459 }
37460
37461 /*
37462 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
37463 void *old_pampd = *(void **)slot;
37464 *(void **)slot = new_pampd;
37465 if (!no_free)
37466 - (*tmem_pamops.free)(old_pampd, obj->pool,
37467 + (tmem_pamops->free)(old_pampd, obj->pool,
37468 NULL, 0, false);
37469 ret = new_pampd;
37470 }
37471 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
37472 if (objnode->slots[i]) {
37473 if (ht == 1) {
37474 obj->pampd_count--;
37475 - (*tmem_pamops.free)(objnode->slots[i],
37476 + (tmem_pamops->free)(objnode->slots[i],
37477 obj->pool, NULL, 0, true);
37478 objnode->slots[i] = NULL;
37479 continue;
37480 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
37481 return;
37482 if (obj->objnode_tree_height == 0) {
37483 obj->pampd_count--;
37484 - (*tmem_pamops.free)(obj->objnode_tree_root,
37485 + (tmem_pamops->free)(obj->objnode_tree_root,
37486 obj->pool, NULL, 0, true);
37487 } else {
37488 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
37489 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
37490 obj->objnode_tree_root = NULL;
37491 #ifdef CONFIG_RAMSTER
37492 if (tmem_pamops.free_obj != NULL)
37493 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
37494 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
37495 #endif
37496 }
37497
37498 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37499 /* if found, is a dup put, flush the old one */
37500 pampd_del = tmem_pampd_delete_from_obj(obj, index);
37501 BUG_ON(pampd_del != pampd);
37502 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
37503 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
37504 if (obj->pampd_count == 0) {
37505 objnew = obj;
37506 objfound = NULL;
37507 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37508 pampd = NULL;
37509 }
37510 } else {
37511 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
37512 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
37513 if (unlikely(obj == NULL)) {
37514 ret = -ENOMEM;
37515 goto out;
37516 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37517 if (unlikely(ret == -ENOMEM))
37518 /* may have partially built objnode tree ("stump") */
37519 goto delete_and_free;
37520 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
37521 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
37522 goto out;
37523
37524 delete_and_free:
37525 (void)tmem_pampd_delete_from_obj(obj, index);
37526 if (pampd)
37527 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
37528 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
37529 if (objnew) {
37530 tmem_obj_free(objnew, hb);
37531 - (*tmem_hostops.obj_free)(objnew, pool);
37532 + (tmem_hostops->obj_free)(objnew, pool);
37533 }
37534 out:
37535 spin_unlock(&hb->lock);
37536 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
37537 if (pampd != NULL) {
37538 BUG_ON(obj == NULL);
37539 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
37540 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
37541 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
37542 } else if (delete) {
37543 BUG_ON(obj == NULL);
37544 (void)tmem_pampd_delete_from_obj(obj, index);
37545 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
37546 int ret = 0;
37547
37548 if (!is_ephemeral(pool))
37549 - new_pampd = (*tmem_pamops.repatriate_preload)(
37550 + new_pampd = (tmem_pamops->repatriate_preload)(
37551 old_pampd, pool, oidp, index, &intransit);
37552 if (intransit)
37553 ret = -EAGAIN;
37554 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
37555 /* must release the hb->lock else repatriate can't sleep */
37556 spin_unlock(&hb->lock);
37557 if (!intransit)
37558 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
37559 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
37560 oidp, index, free, data);
37561 if (ret == -EAGAIN) {
37562 /* rare I think, but should cond_resched()??? */
37563 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
37564 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
37565 /* if we bug here, pamops wasn't properly set up for ramster */
37566 BUG_ON(tmem_pamops.replace_in_obj == NULL);
37567 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
37568 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
37569 out:
37570 spin_unlock(&hb->lock);
37571 return ret;
37572 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37573 if (free) {
37574 if (obj->pampd_count == 0) {
37575 tmem_obj_free(obj, hb);
37576 - (*tmem_hostops.obj_free)(obj, pool);
37577 + (tmem_hostops->obj_free)(obj, pool);
37578 obj = NULL;
37579 }
37580 }
37581 if (free)
37582 - ret = (*tmem_pamops.get_data_and_free)(
37583 + ret = (tmem_pamops->get_data_and_free)(
37584 data, sizep, raw, pampd, pool, oidp, index);
37585 else
37586 - ret = (*tmem_pamops.get_data)(
37587 + ret = (tmem_pamops->get_data)(
37588 data, sizep, raw, pampd, pool, oidp, index);
37589 if (ret < 0)
37590 goto out;
37591 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
37592 pampd = tmem_pampd_delete_from_obj(obj, index);
37593 if (pampd == NULL)
37594 goto out;
37595 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
37596 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
37597 if (obj->pampd_count == 0) {
37598 tmem_obj_free(obj, hb);
37599 - (*tmem_hostops.obj_free)(obj, pool);
37600 + (tmem_hostops->obj_free)(obj, pool);
37601 }
37602 ret = 0;
37603
37604 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
37605 goto out;
37606 tmem_pampd_destroy_all_in_obj(obj, false);
37607 tmem_obj_free(obj, hb);
37608 - (*tmem_hostops.obj_free)(obj, pool);
37609 + (tmem_hostops->obj_free)(obj, pool);
37610 ret = 0;
37611
37612 out:
37613 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37614 index dc23395..cf7e9b1 100644
37615 --- a/drivers/staging/rtl8712/rtl871x_io.h
37616 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37617 @@ -108,7 +108,7 @@ struct _io_ops {
37618 u8 *pmem);
37619 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37620 u8 *pmem);
37621 -};
37622 +} __no_const;
37623
37624 struct io_req {
37625 struct list_head list;
37626 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37627 index 180c963..1f18377 100644
37628 --- a/drivers/staging/sbe-2t3e3/netdev.c
37629 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37630 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37631 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37632
37633 if (rlen)
37634 - if (copy_to_user(data, &resp, rlen))
37635 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37636 return -EFAULT;
37637
37638 return 0;
37639 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37640 index 5d89c0f..9261317 100644
37641 --- a/drivers/staging/usbip/usbip_common.h
37642 +++ b/drivers/staging/usbip/usbip_common.h
37643 @@ -289,7 +289,7 @@ struct usbip_device {
37644 void (*shutdown)(struct usbip_device *);
37645 void (*reset)(struct usbip_device *);
37646 void (*unusable)(struct usbip_device *);
37647 - } eh_ops;
37648 + } __no_const eh_ops;
37649 };
37650
37651 #define kthread_get_run(threadfn, data, namefmt, ...) \
37652 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37653 index c66b8b3..a4a035b 100644
37654 --- a/drivers/staging/usbip/vhci.h
37655 +++ b/drivers/staging/usbip/vhci.h
37656 @@ -83,7 +83,7 @@ struct vhci_hcd {
37657 unsigned resuming:1;
37658 unsigned long re_timeout;
37659
37660 - atomic_t seqnum;
37661 + atomic_unchecked_t seqnum;
37662
37663 /*
37664 * NOTE:
37665 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37666 index 620d1be..1cd6711 100644
37667 --- a/drivers/staging/usbip/vhci_hcd.c
37668 +++ b/drivers/staging/usbip/vhci_hcd.c
37669 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37670 return;
37671 }
37672
37673 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37674 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37675 if (priv->seqnum == 0xffff)
37676 dev_info(&urb->dev->dev, "seqnum max\n");
37677
37678 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37679 return -ENOMEM;
37680 }
37681
37682 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37683 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37684 if (unlink->seqnum == 0xffff)
37685 pr_info("seqnum max\n");
37686
37687 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
37688 vdev->rhport = rhport;
37689 }
37690
37691 - atomic_set(&vhci->seqnum, 0);
37692 + atomic_set_unchecked(&vhci->seqnum, 0);
37693 spin_lock_init(&vhci->lock);
37694
37695 hcd->power_budget = 0; /* no limit */
37696 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37697 index f0eaf04..5a82e06 100644
37698 --- a/drivers/staging/usbip/vhci_rx.c
37699 +++ b/drivers/staging/usbip/vhci_rx.c
37700 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37701 if (!urb) {
37702 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37703 pr_info("max seqnum %d\n",
37704 - atomic_read(&the_controller->seqnum));
37705 + atomic_read_unchecked(&the_controller->seqnum));
37706 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37707 return;
37708 }
37709 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37710 index 67b1b88..6392fe9 100644
37711 --- a/drivers/staging/vt6655/hostap.c
37712 +++ b/drivers/staging/vt6655/hostap.c
37713 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37714 *
37715 */
37716
37717 +static net_device_ops_no_const apdev_netdev_ops;
37718 +
37719 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37720 {
37721 PSDevice apdev_priv;
37722 struct net_device *dev = pDevice->dev;
37723 int ret;
37724 - const struct net_device_ops apdev_netdev_ops = {
37725 - .ndo_start_xmit = pDevice->tx_80211,
37726 - };
37727
37728 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37729
37730 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37731 *apdev_priv = *pDevice;
37732 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37733
37734 + /* only half broken now */
37735 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37736 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37737
37738 pDevice->apdev->type = ARPHRD_IEEE80211;
37739 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37740 index 0a73d40..6fda560 100644
37741 --- a/drivers/staging/vt6656/hostap.c
37742 +++ b/drivers/staging/vt6656/hostap.c
37743 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37744 *
37745 */
37746
37747 +static net_device_ops_no_const apdev_netdev_ops;
37748 +
37749 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37750 {
37751 PSDevice apdev_priv;
37752 struct net_device *dev = pDevice->dev;
37753 int ret;
37754 - const struct net_device_ops apdev_netdev_ops = {
37755 - .ndo_start_xmit = pDevice->tx_80211,
37756 - };
37757
37758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37759
37760 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37761 *apdev_priv = *pDevice;
37762 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37763
37764 + /* only half broken now */
37765 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37766 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37767
37768 pDevice->apdev->type = ARPHRD_IEEE80211;
37769 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37770 index f180c3d..4b9ecfc 100644
37771 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37772 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37773 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37774
37775 struct usbctlx_completor {
37776 int (*complete) (struct usbctlx_completor *);
37777 -};
37778 +} __no_const;
37779
37780 static int
37781 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37782 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37783 index 56c8e60..1920c63 100644
37784 --- a/drivers/staging/zcache/tmem.c
37785 +++ b/drivers/staging/zcache/tmem.c
37786 @@ -39,7 +39,7 @@
37787 * A tmem host implementation must use this function to register callbacks
37788 * for memory allocation.
37789 */
37790 -static struct tmem_hostops tmem_hostops;
37791 +static tmem_hostops_no_const tmem_hostops;
37792
37793 static void tmem_objnode_tree_init(void);
37794
37795 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37796 * A tmem host implementation must use this function to register
37797 * callbacks for a page-accessible memory (PAM) implementation
37798 */
37799 -static struct tmem_pamops tmem_pamops;
37800 +static tmem_pamops_no_const tmem_pamops;
37801
37802 void tmem_register_pamops(struct tmem_pamops *m)
37803 {
37804 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37805 index 0d4aa82..f7832d4 100644
37806 --- a/drivers/staging/zcache/tmem.h
37807 +++ b/drivers/staging/zcache/tmem.h
37808 @@ -180,6 +180,7 @@ struct tmem_pamops {
37809 void (*new_obj)(struct tmem_obj *);
37810 int (*replace_in_obj)(void *, struct tmem_obj *);
37811 };
37812 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37813 extern void tmem_register_pamops(struct tmem_pamops *m);
37814
37815 /* memory allocation methods provided by the host implementation */
37816 @@ -189,6 +190,7 @@ struct tmem_hostops {
37817 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37818 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37819 };
37820 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37821 extern void tmem_register_hostops(struct tmem_hostops *m);
37822
37823 /* core tmem accessor functions */
37824 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37825 index dcecbfb..4fad7d5 100644
37826 --- a/drivers/target/target_core_transport.c
37827 +++ b/drivers/target/target_core_transport.c
37828 @@ -1087,7 +1087,7 @@ struct se_device *transport_add_device_to_core_hba(
37829 spin_lock_init(&dev->se_port_lock);
37830 spin_lock_init(&dev->se_tmr_lock);
37831 spin_lock_init(&dev->qf_cmd_lock);
37832 - atomic_set(&dev->dev_ordered_id, 0);
37833 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37834
37835 se_dev_set_default_attribs(dev, dev_limits);
37836
37837 @@ -1277,7 +1277,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37838 * Used to determine when ORDERED commands should go from
37839 * Dormant to Active status.
37840 */
37841 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37842 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37843 smp_mb__after_atomic_inc();
37844 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37845 cmd->se_ordered_id, cmd->sam_task_attr,
37846 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37847 index 0a6a0bc..5501b06 100644
37848 --- a/drivers/tty/cyclades.c
37849 +++ b/drivers/tty/cyclades.c
37850 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37851 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37852 info->port.count);
37853 #endif
37854 - info->port.count++;
37855 + atomic_inc(&info->port.count);
37856 #ifdef CY_DEBUG_COUNT
37857 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37858 - current->pid, info->port.count);
37859 + current->pid, atomic_read(&info->port.count));
37860 #endif
37861
37862 /*
37863 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37864 for (j = 0; j < cy_card[i].nports; j++) {
37865 info = &cy_card[i].ports[j];
37866
37867 - if (info->port.count) {
37868 + if (atomic_read(&info->port.count)) {
37869 /* XXX is the ldisc num worth this? */
37870 struct tty_struct *tty;
37871 struct tty_ldisc *ld;
37872 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37873 index 13ee53b..418d164 100644
37874 --- a/drivers/tty/hvc/hvc_console.c
37875 +++ b/drivers/tty/hvc/hvc_console.c
37876 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37877
37878 spin_lock_irqsave(&hp->port.lock, flags);
37879 /* Check and then increment for fast path open. */
37880 - if (hp->port.count++ > 0) {
37881 + if (atomic_inc_return(&hp->port.count) > 1) {
37882 spin_unlock_irqrestore(&hp->port.lock, flags);
37883 hvc_kick();
37884 return 0;
37885 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37886
37887 spin_lock_irqsave(&hp->port.lock, flags);
37888
37889 - if (--hp->port.count == 0) {
37890 + if (atomic_dec_return(&hp->port.count) == 0) {
37891 spin_unlock_irqrestore(&hp->port.lock, flags);
37892 /* We are done with the tty pointer now. */
37893 tty_port_tty_set(&hp->port, NULL);
37894 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37895 */
37896 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37897 } else {
37898 - if (hp->port.count < 0)
37899 + if (atomic_read(&hp->port.count) < 0)
37900 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37901 - hp->vtermno, hp->port.count);
37902 + hp->vtermno, atomic_read(&hp->port.count));
37903 spin_unlock_irqrestore(&hp->port.lock, flags);
37904 }
37905 }
37906 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
37907 * open->hangup case this can be called after the final close so prevent
37908 * that from happening for now.
37909 */
37910 - if (hp->port.count <= 0) {
37911 + if (atomic_read(&hp->port.count) <= 0) {
37912 spin_unlock_irqrestore(&hp->port.lock, flags);
37913 return;
37914 }
37915
37916 - hp->port.count = 0;
37917 + atomic_set(&hp->port.count, 0);
37918 spin_unlock_irqrestore(&hp->port.lock, flags);
37919 tty_port_tty_set(&hp->port, NULL);
37920
37921 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37922 return -EPIPE;
37923
37924 /* FIXME what's this (unprotected) check for? */
37925 - if (hp->port.count <= 0)
37926 + if (atomic_read(&hp->port.count) <= 0)
37927 return -EIO;
37928
37929 spin_lock_irqsave(&hp->lock, flags);
37930 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37931 index cab5c7a..4cc66ea 100644
37932 --- a/drivers/tty/hvc/hvcs.c
37933 +++ b/drivers/tty/hvc/hvcs.c
37934 @@ -83,6 +83,7 @@
37935 #include <asm/hvcserver.h>
37936 #include <asm/uaccess.h>
37937 #include <asm/vio.h>
37938 +#include <asm/local.h>
37939
37940 /*
37941 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37942 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37943
37944 spin_lock_irqsave(&hvcsd->lock, flags);
37945
37946 - if (hvcsd->port.count > 0) {
37947 + if (atomic_read(&hvcsd->port.count) > 0) {
37948 spin_unlock_irqrestore(&hvcsd->lock, flags);
37949 printk(KERN_INFO "HVCS: vterm state unchanged. "
37950 "The hvcs device node is still in use.\n");
37951 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
37952 }
37953 }
37954
37955 - hvcsd->port.count = 0;
37956 + atomic_set(&hvcsd->port.count, 0);
37957 hvcsd->port.tty = tty;
37958 tty->driver_data = hvcsd;
37959
37960 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37961 unsigned long flags;
37962
37963 spin_lock_irqsave(&hvcsd->lock, flags);
37964 - hvcsd->port.count++;
37965 + atomic_inc(&hvcsd->port.count);
37966 hvcsd->todo_mask |= HVCS_SCHED_READ;
37967 spin_unlock_irqrestore(&hvcsd->lock, flags);
37968
37969 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37970 hvcsd = tty->driver_data;
37971
37972 spin_lock_irqsave(&hvcsd->lock, flags);
37973 - if (--hvcsd->port.count == 0) {
37974 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37975
37976 vio_disable_interrupts(hvcsd->vdev);
37977
37978 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37979
37980 free_irq(irq, hvcsd);
37981 return;
37982 - } else if (hvcsd->port.count < 0) {
37983 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37984 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37985 " is missmanaged.\n",
37986 - hvcsd->vdev->unit_address, hvcsd->port.count);
37987 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37988 }
37989
37990 spin_unlock_irqrestore(&hvcsd->lock, flags);
37991 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37992
37993 spin_lock_irqsave(&hvcsd->lock, flags);
37994 /* Preserve this so that we know how many kref refs to put */
37995 - temp_open_count = hvcsd->port.count;
37996 + temp_open_count = atomic_read(&hvcsd->port.count);
37997
37998 /*
37999 * Don't kref put inside the spinlock because the destruction
38000 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38001 tty->driver_data = NULL;
38002 hvcsd->port.tty = NULL;
38003
38004 - hvcsd->port.count = 0;
38005 + atomic_set(&hvcsd->port.count, 0);
38006
38007 /* This will drop any buffered data on the floor which is OK in a hangup
38008 * scenario. */
38009 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
38010 * the middle of a write operation? This is a crummy place to do this
38011 * but we want to keep it all in the spinlock.
38012 */
38013 - if (hvcsd->port.count <= 0) {
38014 + if (atomic_read(&hvcsd->port.count) <= 0) {
38015 spin_unlock_irqrestore(&hvcsd->lock, flags);
38016 return -ENODEV;
38017 }
38018 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38019 {
38020 struct hvcs_struct *hvcsd = tty->driver_data;
38021
38022 - if (!hvcsd || hvcsd->port.count <= 0)
38023 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38024 return 0;
38025
38026 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38027 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38028 index 160f0ad..588b853 100644
38029 --- a/drivers/tty/ipwireless/tty.c
38030 +++ b/drivers/tty/ipwireless/tty.c
38031 @@ -29,6 +29,7 @@
38032 #include <linux/tty_driver.h>
38033 #include <linux/tty_flip.h>
38034 #include <linux/uaccess.h>
38035 +#include <asm/local.h>
38036
38037 #include "tty.h"
38038 #include "network.h"
38039 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38040 mutex_unlock(&tty->ipw_tty_mutex);
38041 return -ENODEV;
38042 }
38043 - if (tty->port.count == 0)
38044 + if (atomic_read(&tty->port.count) == 0)
38045 tty->tx_bytes_queued = 0;
38046
38047 - tty->port.count++;
38048 + atomic_inc(&tty->port.count);
38049
38050 tty->port.tty = linux_tty;
38051 linux_tty->driver_data = tty;
38052 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38053
38054 static void do_ipw_close(struct ipw_tty *tty)
38055 {
38056 - tty->port.count--;
38057 -
38058 - if (tty->port.count == 0) {
38059 + if (atomic_dec_return(&tty->port.count) == 0) {
38060 struct tty_struct *linux_tty = tty->port.tty;
38061
38062 if (linux_tty != NULL) {
38063 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38064 return;
38065
38066 mutex_lock(&tty->ipw_tty_mutex);
38067 - if (tty->port.count == 0) {
38068 + if (atomic_read(&tty->port.count) == 0) {
38069 mutex_unlock(&tty->ipw_tty_mutex);
38070 return;
38071 }
38072 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38073 return;
38074 }
38075
38076 - if (!tty->port.count) {
38077 + if (!atomic_read(&tty->port.count)) {
38078 mutex_unlock(&tty->ipw_tty_mutex);
38079 return;
38080 }
38081 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38082 return -ENODEV;
38083
38084 mutex_lock(&tty->ipw_tty_mutex);
38085 - if (!tty->port.count) {
38086 + if (!atomic_read(&tty->port.count)) {
38087 mutex_unlock(&tty->ipw_tty_mutex);
38088 return -EINVAL;
38089 }
38090 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38091 if (!tty)
38092 return -ENODEV;
38093
38094 - if (!tty->port.count)
38095 + if (!atomic_read(&tty->port.count))
38096 return -EINVAL;
38097
38098 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38099 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38100 if (!tty)
38101 return 0;
38102
38103 - if (!tty->port.count)
38104 + if (!atomic_read(&tty->port.count))
38105 return 0;
38106
38107 return tty->tx_bytes_queued;
38108 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38109 if (!tty)
38110 return -ENODEV;
38111
38112 - if (!tty->port.count)
38113 + if (!atomic_read(&tty->port.count))
38114 return -EINVAL;
38115
38116 return get_control_lines(tty);
38117 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38118 if (!tty)
38119 return -ENODEV;
38120
38121 - if (!tty->port.count)
38122 + if (!atomic_read(&tty->port.count))
38123 return -EINVAL;
38124
38125 return set_control_lines(tty, set, clear);
38126 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38127 if (!tty)
38128 return -ENODEV;
38129
38130 - if (!tty->port.count)
38131 + if (!atomic_read(&tty->port.count))
38132 return -EINVAL;
38133
38134 /* FIXME: Exactly how is the tty object locked here .. */
38135 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38136 * are gone */
38137 mutex_lock(&ttyj->ipw_tty_mutex);
38138 }
38139 - while (ttyj->port.count)
38140 + while (atomic_read(&ttyj->port.count))
38141 do_ipw_close(ttyj);
38142 ipwireless_disassociate_network_ttys(network,
38143 ttyj->channel_idx);
38144 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38145 index 56e616b..9d9f10a 100644
38146 --- a/drivers/tty/moxa.c
38147 +++ b/drivers/tty/moxa.c
38148 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38149 }
38150
38151 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38152 - ch->port.count++;
38153 + atomic_inc(&ch->port.count);
38154 tty->driver_data = ch;
38155 tty_port_tty_set(&ch->port, tty);
38156 mutex_lock(&ch->port.mutex);
38157 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38158 index 1e8e8ce..a9efc93 100644
38159 --- a/drivers/tty/n_gsm.c
38160 +++ b/drivers/tty/n_gsm.c
38161 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38162 kref_init(&dlci->ref);
38163 mutex_init(&dlci->mutex);
38164 dlci->fifo = &dlci->_fifo;
38165 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38166 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38167 kfree(dlci);
38168 return NULL;
38169 }
38170 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38171 struct gsm_dlci *dlci = tty->driver_data;
38172 struct tty_port *port = &dlci->port;
38173
38174 - port->count++;
38175 + atomic_inc(&port->count);
38176 dlci_get(dlci);
38177 dlci_get(dlci->gsm->dlci[0]);
38178 mux_get(dlci->gsm);
38179 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38180 index 8c0b7b4..e88f052 100644
38181 --- a/drivers/tty/n_tty.c
38182 +++ b/drivers/tty/n_tty.c
38183 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38184 {
38185 *ops = tty_ldisc_N_TTY;
38186 ops->owner = NULL;
38187 - ops->refcount = ops->flags = 0;
38188 + atomic_set(&ops->refcount, 0);
38189 + ops->flags = 0;
38190 }
38191 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38192 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38193 index a82b399..331a220 100644
38194 --- a/drivers/tty/pty.c
38195 +++ b/drivers/tty/pty.c
38196 @@ -728,8 +728,10 @@ static void __init unix98_pty_init(void)
38197 panic("Couldn't register Unix98 pts driver");
38198
38199 /* Now create the /dev/ptmx special device */
38200 + pax_open_kernel();
38201 tty_default_fops(&ptmx_fops);
38202 - ptmx_fops.open = ptmx_open;
38203 + *(void **)&ptmx_fops.open = ptmx_open;
38204 + pax_close_kernel();
38205
38206 cdev_init(&ptmx_cdev, &ptmx_fops);
38207 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38208 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38209 index 9700d34..df7520c 100644
38210 --- a/drivers/tty/rocket.c
38211 +++ b/drivers/tty/rocket.c
38212 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38213 tty->driver_data = info;
38214 tty_port_tty_set(port, tty);
38215
38216 - if (port->count++ == 0) {
38217 + if (atomic_inc_return(&port->count) == 1) {
38218 atomic_inc(&rp_num_ports_open);
38219
38220 #ifdef ROCKET_DEBUG_OPEN
38221 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38222 #endif
38223 }
38224 #ifdef ROCKET_DEBUG_OPEN
38225 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38226 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38227 #endif
38228
38229 /*
38230 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38231 spin_unlock_irqrestore(&info->port.lock, flags);
38232 return;
38233 }
38234 - if (info->port.count)
38235 + if (atomic_read(&info->port.count))
38236 atomic_dec(&rp_num_ports_open);
38237 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38238 spin_unlock_irqrestore(&info->port.lock, flags);
38239 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38240 index 1002054..dd644a8 100644
38241 --- a/drivers/tty/serial/kgdboc.c
38242 +++ b/drivers/tty/serial/kgdboc.c
38243 @@ -24,8 +24,9 @@
38244 #define MAX_CONFIG_LEN 40
38245
38246 static struct kgdb_io kgdboc_io_ops;
38247 +static struct kgdb_io kgdboc_io_ops_console;
38248
38249 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38250 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38251 static int configured = -1;
38252
38253 static char config[MAX_CONFIG_LEN];
38254 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
38255 kgdboc_unregister_kbd();
38256 if (configured == 1)
38257 kgdb_unregister_io_module(&kgdboc_io_ops);
38258 + else if (configured == 2)
38259 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38260 }
38261
38262 static int configure_kgdboc(void)
38263 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
38264 int err;
38265 char *cptr = config;
38266 struct console *cons;
38267 + int is_console = 0;
38268
38269 err = kgdboc_option_setup(config);
38270 if (err || !strlen(config) || isspace(config[0]))
38271 goto noconfig;
38272
38273 err = -ENODEV;
38274 - kgdboc_io_ops.is_console = 0;
38275 kgdb_tty_driver = NULL;
38276
38277 kgdboc_use_kms = 0;
38278 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
38279 int idx;
38280 if (cons->device && cons->device(cons, &idx) == p &&
38281 idx == tty_line) {
38282 - kgdboc_io_ops.is_console = 1;
38283 + is_console = 1;
38284 break;
38285 }
38286 cons = cons->next;
38287 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
38288 kgdb_tty_line = tty_line;
38289
38290 do_register:
38291 - err = kgdb_register_io_module(&kgdboc_io_ops);
38292 + if (is_console) {
38293 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38294 + configured = 2;
38295 + } else {
38296 + err = kgdb_register_io_module(&kgdboc_io_ops);
38297 + configured = 1;
38298 + }
38299 if (err)
38300 goto noconfig;
38301
38302 @@ -205,8 +214,6 @@ do_register:
38303 if (err)
38304 goto nmi_con_failed;
38305
38306 - configured = 1;
38307 -
38308 return 0;
38309
38310 nmi_con_failed:
38311 @@ -223,7 +230,7 @@ noconfig:
38312 static int __init init_kgdboc(void)
38313 {
38314 /* Already configured? */
38315 - if (configured == 1)
38316 + if (configured >= 1)
38317 return 0;
38318
38319 return configure_kgdboc();
38320 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38321 if (config[len - 1] == '\n')
38322 config[len - 1] = '\0';
38323
38324 - if (configured == 1)
38325 + if (configured >= 1)
38326 cleanup_kgdboc();
38327
38328 /* Go and configure with the new params. */
38329 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
38330 .post_exception = kgdboc_post_exp_handler,
38331 };
38332
38333 +static struct kgdb_io kgdboc_io_ops_console = {
38334 + .name = "kgdboc",
38335 + .read_char = kgdboc_get_char,
38336 + .write_char = kgdboc_put_char,
38337 + .pre_exception = kgdboc_pre_exp_handler,
38338 + .post_exception = kgdboc_post_exp_handler,
38339 + .is_console = 1
38340 +};
38341 +
38342 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38343 /* This is only available if kgdboc is a built in for early debugging */
38344 static int __init kgdboc_early_init(char *opt)
38345 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38346 index 0fcfd98..8244fce 100644
38347 --- a/drivers/tty/serial/serial_core.c
38348 +++ b/drivers/tty/serial/serial_core.c
38349 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
38350 uart_flush_buffer(tty);
38351 uart_shutdown(tty, state);
38352 spin_lock_irqsave(&port->lock, flags);
38353 - port->count = 0;
38354 + atomic_set(&port->count, 0);
38355 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38356 spin_unlock_irqrestore(&port->lock, flags);
38357 tty_port_tty_set(port, NULL);
38358 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38359 goto end;
38360 }
38361
38362 - port->count++;
38363 + atomic_inc(&port->count);
38364 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38365 retval = -ENXIO;
38366 goto err_dec_count;
38367 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38368 /*
38369 * Make sure the device is in D0 state.
38370 */
38371 - if (port->count == 1)
38372 + if (atomic_read(&port->count) == 1)
38373 uart_change_pm(state, 0);
38374
38375 /*
38376 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38377 end:
38378 return retval;
38379 err_dec_count:
38380 - port->count--;
38381 + atomic_inc(&port->count);
38382 mutex_unlock(&port->mutex);
38383 goto end;
38384 }
38385 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38386 index 70e3a52..5742052 100644
38387 --- a/drivers/tty/synclink.c
38388 +++ b/drivers/tty/synclink.c
38389 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38390
38391 if (debug_level >= DEBUG_LEVEL_INFO)
38392 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38393 - __FILE__,__LINE__, info->device_name, info->port.count);
38394 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38395
38396 if (tty_port_close_start(&info->port, tty, filp) == 0)
38397 goto cleanup;
38398 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38399 cleanup:
38400 if (debug_level >= DEBUG_LEVEL_INFO)
38401 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38402 - tty->driver->name, info->port.count);
38403 + tty->driver->name, atomic_read(&info->port.count));
38404
38405 } /* end of mgsl_close() */
38406
38407 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38408
38409 mgsl_flush_buffer(tty);
38410 shutdown(info);
38411 -
38412 - info->port.count = 0;
38413 +
38414 + atomic_set(&info->port.count, 0);
38415 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38416 info->port.tty = NULL;
38417
38418 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38419
38420 if (debug_level >= DEBUG_LEVEL_INFO)
38421 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38422 - __FILE__,__LINE__, tty->driver->name, port->count );
38423 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38424
38425 spin_lock_irqsave(&info->irq_spinlock, flags);
38426 if (!tty_hung_up_p(filp)) {
38427 extra_count = true;
38428 - port->count--;
38429 + atomic_dec(&port->count);
38430 }
38431 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38432 port->blocked_open++;
38433 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38434
38435 if (debug_level >= DEBUG_LEVEL_INFO)
38436 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38437 - __FILE__,__LINE__, tty->driver->name, port->count );
38438 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38439
38440 tty_unlock(tty);
38441 schedule();
38442 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38443
38444 /* FIXME: Racy on hangup during close wait */
38445 if (extra_count)
38446 - port->count++;
38447 + atomic_inc(&port->count);
38448 port->blocked_open--;
38449
38450 if (debug_level >= DEBUG_LEVEL_INFO)
38451 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38452 - __FILE__,__LINE__, tty->driver->name, port->count );
38453 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38454
38455 if (!retval)
38456 port->flags |= ASYNC_NORMAL_ACTIVE;
38457 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38458
38459 if (debug_level >= DEBUG_LEVEL_INFO)
38460 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38461 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38462 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38463
38464 /* If port is closing, signal caller to try again */
38465 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38466 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38467 spin_unlock_irqrestore(&info->netlock, flags);
38468 goto cleanup;
38469 }
38470 - info->port.count++;
38471 + atomic_inc(&info->port.count);
38472 spin_unlock_irqrestore(&info->netlock, flags);
38473
38474 - if (info->port.count == 1) {
38475 + if (atomic_read(&info->port.count) == 1) {
38476 /* 1st open on this device, init hardware */
38477 retval = startup(info);
38478 if (retval < 0)
38479 @@ -3451,8 +3451,8 @@ cleanup:
38480 if (retval) {
38481 if (tty->count == 1)
38482 info->port.tty = NULL; /* tty layer will release tty struct */
38483 - if(info->port.count)
38484 - info->port.count--;
38485 + if (atomic_read(&info->port.count))
38486 + atomic_dec(&info->port.count);
38487 }
38488
38489 return retval;
38490 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38491 unsigned short new_crctype;
38492
38493 /* return error if TTY interface open */
38494 - if (info->port.count)
38495 + if (atomic_read(&info->port.count))
38496 return -EBUSY;
38497
38498 switch (encoding)
38499 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
38500
38501 /* arbitrate between network and tty opens */
38502 spin_lock_irqsave(&info->netlock, flags);
38503 - if (info->port.count != 0 || info->netcount != 0) {
38504 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38505 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38506 spin_unlock_irqrestore(&info->netlock, flags);
38507 return -EBUSY;
38508 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38509 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38510
38511 /* return error if TTY interface open */
38512 - if (info->port.count)
38513 + if (atomic_read(&info->port.count))
38514 return -EBUSY;
38515
38516 if (cmd != SIOCWANDEV)
38517 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38518 index b38e954..ce45b38 100644
38519 --- a/drivers/tty/synclink_gt.c
38520 +++ b/drivers/tty/synclink_gt.c
38521 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38522 tty->driver_data = info;
38523 info->port.tty = tty;
38524
38525 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38526 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38527
38528 /* If port is closing, signal caller to try again */
38529 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38530 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38531 mutex_unlock(&info->port.mutex);
38532 goto cleanup;
38533 }
38534 - info->port.count++;
38535 + atomic_inc(&info->port.count);
38536 spin_unlock_irqrestore(&info->netlock, flags);
38537
38538 - if (info->port.count == 1) {
38539 + if (atomic_read(&info->port.count) == 1) {
38540 /* 1st open on this device, init hardware */
38541 retval = startup(info);
38542 if (retval < 0) {
38543 @@ -716,8 +716,8 @@ cleanup:
38544 if (retval) {
38545 if (tty->count == 1)
38546 info->port.tty = NULL; /* tty layer will release tty struct */
38547 - if(info->port.count)
38548 - info->port.count--;
38549 + if(atomic_read(&info->port.count))
38550 + atomic_dec(&info->port.count);
38551 }
38552
38553 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38554 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38555
38556 if (sanity_check(info, tty->name, "close"))
38557 return;
38558 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38559 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38560
38561 if (tty_port_close_start(&info->port, tty, filp) == 0)
38562 goto cleanup;
38563 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38564 tty_port_close_end(&info->port, tty);
38565 info->port.tty = NULL;
38566 cleanup:
38567 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38568 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38569 }
38570
38571 static void hangup(struct tty_struct *tty)
38572 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38573 shutdown(info);
38574
38575 spin_lock_irqsave(&info->port.lock, flags);
38576 - info->port.count = 0;
38577 + atomic_set(&info->port.count, 0);
38578 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38579 info->port.tty = NULL;
38580 spin_unlock_irqrestore(&info->port.lock, flags);
38581 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38582 unsigned short new_crctype;
38583
38584 /* return error if TTY interface open */
38585 - if (info->port.count)
38586 + if (atomic_read(&info->port.count))
38587 return -EBUSY;
38588
38589 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38590 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38591
38592 /* arbitrate between network and tty opens */
38593 spin_lock_irqsave(&info->netlock, flags);
38594 - if (info->port.count != 0 || info->netcount != 0) {
38595 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38596 DBGINFO(("%s hdlc_open busy\n", dev->name));
38597 spin_unlock_irqrestore(&info->netlock, flags);
38598 return -EBUSY;
38599 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38600 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38601
38602 /* return error if TTY interface open */
38603 - if (info->port.count)
38604 + if (atomic_read(&info->port.count))
38605 return -EBUSY;
38606
38607 if (cmd != SIOCWANDEV)
38608 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38609 if (port == NULL)
38610 continue;
38611 spin_lock(&port->lock);
38612 - if ((port->port.count || port->netcount) &&
38613 + if ((atomic_read(&port->port.count) || port->netcount) &&
38614 port->pending_bh && !port->bh_running &&
38615 !port->bh_requested) {
38616 DBGISR(("%s bh queued\n", port->device_name));
38617 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38618 spin_lock_irqsave(&info->lock, flags);
38619 if (!tty_hung_up_p(filp)) {
38620 extra_count = true;
38621 - port->count--;
38622 + atomic_dec(&port->count);
38623 }
38624 spin_unlock_irqrestore(&info->lock, flags);
38625 port->blocked_open++;
38626 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38627 remove_wait_queue(&port->open_wait, &wait);
38628
38629 if (extra_count)
38630 - port->count++;
38631 + atomic_inc(&port->count);
38632 port->blocked_open--;
38633
38634 if (!retval)
38635 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38636 index f17d9f3..27a041b 100644
38637 --- a/drivers/tty/synclinkmp.c
38638 +++ b/drivers/tty/synclinkmp.c
38639 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38640
38641 if (debug_level >= DEBUG_LEVEL_INFO)
38642 printk("%s(%d):%s open(), old ref count = %d\n",
38643 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38644 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38645
38646 /* If port is closing, signal caller to try again */
38647 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38648 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38649 spin_unlock_irqrestore(&info->netlock, flags);
38650 goto cleanup;
38651 }
38652 - info->port.count++;
38653 + atomic_inc(&info->port.count);
38654 spin_unlock_irqrestore(&info->netlock, flags);
38655
38656 - if (info->port.count == 1) {
38657 + if (atomic_read(&info->port.count) == 1) {
38658 /* 1st open on this device, init hardware */
38659 retval = startup(info);
38660 if (retval < 0)
38661 @@ -797,8 +797,8 @@ cleanup:
38662 if (retval) {
38663 if (tty->count == 1)
38664 info->port.tty = NULL; /* tty layer will release tty struct */
38665 - if(info->port.count)
38666 - info->port.count--;
38667 + if(atomic_read(&info->port.count))
38668 + atomic_dec(&info->port.count);
38669 }
38670
38671 return retval;
38672 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38673
38674 if (debug_level >= DEBUG_LEVEL_INFO)
38675 printk("%s(%d):%s close() entry, count=%d\n",
38676 - __FILE__,__LINE__, info->device_name, info->port.count);
38677 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38678
38679 if (tty_port_close_start(&info->port, tty, filp) == 0)
38680 goto cleanup;
38681 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38682 cleanup:
38683 if (debug_level >= DEBUG_LEVEL_INFO)
38684 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38685 - tty->driver->name, info->port.count);
38686 + tty->driver->name, atomic_read(&info->port.count));
38687 }
38688
38689 /* Called by tty_hangup() when a hangup is signaled.
38690 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
38691 shutdown(info);
38692
38693 spin_lock_irqsave(&info->port.lock, flags);
38694 - info->port.count = 0;
38695 + atomic_set(&info->port.count, 0);
38696 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38697 info->port.tty = NULL;
38698 spin_unlock_irqrestore(&info->port.lock, flags);
38699 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38700 unsigned short new_crctype;
38701
38702 /* return error if TTY interface open */
38703 - if (info->port.count)
38704 + if (atomic_read(&info->port.count))
38705 return -EBUSY;
38706
38707 switch (encoding)
38708 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
38709
38710 /* arbitrate between network and tty opens */
38711 spin_lock_irqsave(&info->netlock, flags);
38712 - if (info->port.count != 0 || info->netcount != 0) {
38713 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38714 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38715 spin_unlock_irqrestore(&info->netlock, flags);
38716 return -EBUSY;
38717 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38718 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38719
38720 /* return error if TTY interface open */
38721 - if (info->port.count)
38722 + if (atomic_read(&info->port.count))
38723 return -EBUSY;
38724
38725 if (cmd != SIOCWANDEV)
38726 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38727 * do not request bottom half processing if the
38728 * device is not open in a normal mode.
38729 */
38730 - if ( port && (port->port.count || port->netcount) &&
38731 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38732 port->pending_bh && !port->bh_running &&
38733 !port->bh_requested ) {
38734 if ( debug_level >= DEBUG_LEVEL_ISR )
38735 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38736
38737 if (debug_level >= DEBUG_LEVEL_INFO)
38738 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38739 - __FILE__,__LINE__, tty->driver->name, port->count );
38740 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38741
38742 spin_lock_irqsave(&info->lock, flags);
38743 if (!tty_hung_up_p(filp)) {
38744 extra_count = true;
38745 - port->count--;
38746 + atomic_dec(&port->count);
38747 }
38748 spin_unlock_irqrestore(&info->lock, flags);
38749 port->blocked_open++;
38750 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38751
38752 if (debug_level >= DEBUG_LEVEL_INFO)
38753 printk("%s(%d):%s block_til_ready() count=%d\n",
38754 - __FILE__,__LINE__, tty->driver->name, port->count );
38755 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38756
38757 tty_unlock(tty);
38758 schedule();
38759 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38760 remove_wait_queue(&port->open_wait, &wait);
38761
38762 if (extra_count)
38763 - port->count++;
38764 + atomic_inc(&port->count);
38765 port->blocked_open--;
38766
38767 if (debug_level >= DEBUG_LEVEL_INFO)
38768 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38769 - __FILE__,__LINE__, tty->driver->name, port->count );
38770 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38771
38772 if (!retval)
38773 port->flags |= ASYNC_NORMAL_ACTIVE;
38774 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38775 index 16ee6ce..bfcac57 100644
38776 --- a/drivers/tty/sysrq.c
38777 +++ b/drivers/tty/sysrq.c
38778 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38779 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38780 size_t count, loff_t *ppos)
38781 {
38782 - if (count) {
38783 + if (count && capable(CAP_SYS_ADMIN)) {
38784 char c;
38785
38786 if (get_user(c, buf))
38787 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38788 index 2ea176b..2877bc8 100644
38789 --- a/drivers/tty/tty_io.c
38790 +++ b/drivers/tty/tty_io.c
38791 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38792
38793 void tty_default_fops(struct file_operations *fops)
38794 {
38795 - *fops = tty_fops;
38796 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38797 }
38798
38799 /*
38800 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38801 index 0f2a2c5..471e228 100644
38802 --- a/drivers/tty/tty_ldisc.c
38803 +++ b/drivers/tty/tty_ldisc.c
38804 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38805 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38806 struct tty_ldisc_ops *ldo = ld->ops;
38807
38808 - ldo->refcount--;
38809 + atomic_dec(&ldo->refcount);
38810 module_put(ldo->owner);
38811 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38812
38813 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38814 spin_lock_irqsave(&tty_ldisc_lock, flags);
38815 tty_ldiscs[disc] = new_ldisc;
38816 new_ldisc->num = disc;
38817 - new_ldisc->refcount = 0;
38818 + atomic_set(&new_ldisc->refcount, 0);
38819 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38820
38821 return ret;
38822 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38823 return -EINVAL;
38824
38825 spin_lock_irqsave(&tty_ldisc_lock, flags);
38826 - if (tty_ldiscs[disc]->refcount)
38827 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38828 ret = -EBUSY;
38829 else
38830 tty_ldiscs[disc] = NULL;
38831 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38832 if (ldops) {
38833 ret = ERR_PTR(-EAGAIN);
38834 if (try_module_get(ldops->owner)) {
38835 - ldops->refcount++;
38836 + atomic_inc(&ldops->refcount);
38837 ret = ldops;
38838 }
38839 }
38840 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38841 unsigned long flags;
38842
38843 spin_lock_irqsave(&tty_ldisc_lock, flags);
38844 - ldops->refcount--;
38845 + atomic_dec(&ldops->refcount);
38846 module_put(ldops->owner);
38847 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38848 }
38849 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38850 index d7bdd8d..feaef30 100644
38851 --- a/drivers/tty/tty_port.c
38852 +++ b/drivers/tty/tty_port.c
38853 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
38854 unsigned long flags;
38855
38856 spin_lock_irqsave(&port->lock, flags);
38857 - port->count = 0;
38858 + atomic_set(&port->count, 0);
38859 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38860 if (port->tty) {
38861 set_bit(TTY_IO_ERROR, &port->tty->flags);
38862 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38863 /* The port lock protects the port counts */
38864 spin_lock_irqsave(&port->lock, flags);
38865 if (!tty_hung_up_p(filp))
38866 - port->count--;
38867 + atomic_dec(&port->count);
38868 port->blocked_open++;
38869 spin_unlock_irqrestore(&port->lock, flags);
38870
38871 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38872 we must not mess that up further */
38873 spin_lock_irqsave(&port->lock, flags);
38874 if (!tty_hung_up_p(filp))
38875 - port->count++;
38876 + atomic_inc(&port->count);
38877 port->blocked_open--;
38878 if (retval == 0)
38879 port->flags |= ASYNC_NORMAL_ACTIVE;
38880 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
38881 return 0;
38882 }
38883
38884 - if (tty->count == 1 && port->count != 1) {
38885 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38886 printk(KERN_WARNING
38887 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38888 - port->count);
38889 - port->count = 1;
38890 + atomic_read(&port->count));
38891 + atomic_set(&port->count, 1);
38892 }
38893 - if (--port->count < 0) {
38894 + if (atomic_dec_return(&port->count) < 0) {
38895 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38896 - port->count);
38897 - port->count = 0;
38898 + atomic_read(&port->count));
38899 + atomic_set(&port->count, 0);
38900 }
38901
38902 - if (port->count) {
38903 + if (atomic_read(&port->count)) {
38904 spin_unlock_irqrestore(&port->lock, flags);
38905 if (port->ops->drop)
38906 port->ops->drop(port);
38907 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38908 {
38909 spin_lock_irq(&port->lock);
38910 if (!tty_hung_up_p(filp))
38911 - ++port->count;
38912 + atomic_inc(&port->count);
38913 spin_unlock_irq(&port->lock);
38914 tty_port_tty_set(port, tty);
38915
38916 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38917 index 681765b..d3ccdf2 100644
38918 --- a/drivers/tty/vt/keyboard.c
38919 +++ b/drivers/tty/vt/keyboard.c
38920 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38921 kbd->kbdmode == VC_OFF) &&
38922 value != KVAL(K_SAK))
38923 return; /* SAK is allowed even in raw mode */
38924 +
38925 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38926 + {
38927 + void *func = fn_handler[value];
38928 + if (func == fn_show_state || func == fn_show_ptregs ||
38929 + func == fn_show_mem)
38930 + return;
38931 + }
38932 +#endif
38933 +
38934 fn_handler[value](vc);
38935 }
38936
38937 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38938 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38939 return -EFAULT;
38940
38941 - if (!capable(CAP_SYS_TTY_CONFIG))
38942 - perm = 0;
38943 -
38944 switch (cmd) {
38945 case KDGKBENT:
38946 /* Ensure another thread doesn't free it under us */
38947 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38948 spin_unlock_irqrestore(&kbd_event_lock, flags);
38949 return put_user(val, &user_kbe->kb_value);
38950 case KDSKBENT:
38951 + if (!capable(CAP_SYS_TTY_CONFIG))
38952 + perm = 0;
38953 +
38954 if (!perm)
38955 return -EPERM;
38956 if (!i && v == K_NOSUCHMAP) {
38957 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38958 int i, j, k;
38959 int ret;
38960
38961 - if (!capable(CAP_SYS_TTY_CONFIG))
38962 - perm = 0;
38963 -
38964 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38965 if (!kbs) {
38966 ret = -ENOMEM;
38967 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38968 kfree(kbs);
38969 return ((p && *p) ? -EOVERFLOW : 0);
38970 case KDSKBSENT:
38971 + if (!capable(CAP_SYS_TTY_CONFIG))
38972 + perm = 0;
38973 +
38974 if (!perm) {
38975 ret = -EPERM;
38976 goto reterr;
38977 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38978 index 5110f36..8dc0a74 100644
38979 --- a/drivers/uio/uio.c
38980 +++ b/drivers/uio/uio.c
38981 @@ -25,6 +25,7 @@
38982 #include <linux/kobject.h>
38983 #include <linux/cdev.h>
38984 #include <linux/uio_driver.h>
38985 +#include <asm/local.h>
38986
38987 #define UIO_MAX_DEVICES (1U << MINORBITS)
38988
38989 @@ -32,10 +33,10 @@ struct uio_device {
38990 struct module *owner;
38991 struct device *dev;
38992 int minor;
38993 - atomic_t event;
38994 + atomic_unchecked_t event;
38995 struct fasync_struct *async_queue;
38996 wait_queue_head_t wait;
38997 - int vma_count;
38998 + local_t vma_count;
38999 struct uio_info *info;
39000 struct kobject *map_dir;
39001 struct kobject *portio_dir;
39002 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39003 struct device_attribute *attr, char *buf)
39004 {
39005 struct uio_device *idev = dev_get_drvdata(dev);
39006 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39007 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39008 }
39009
39010 static struct device_attribute uio_class_attributes[] = {
39011 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39012 {
39013 struct uio_device *idev = info->uio_dev;
39014
39015 - atomic_inc(&idev->event);
39016 + atomic_inc_unchecked(&idev->event);
39017 wake_up_interruptible(&idev->wait);
39018 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39019 }
39020 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39021 }
39022
39023 listener->dev = idev;
39024 - listener->event_count = atomic_read(&idev->event);
39025 + listener->event_count = atomic_read_unchecked(&idev->event);
39026 filep->private_data = listener;
39027
39028 if (idev->info->open) {
39029 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39030 return -EIO;
39031
39032 poll_wait(filep, &idev->wait, wait);
39033 - if (listener->event_count != atomic_read(&idev->event))
39034 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39035 return POLLIN | POLLRDNORM;
39036 return 0;
39037 }
39038 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39039 do {
39040 set_current_state(TASK_INTERRUPTIBLE);
39041
39042 - event_count = atomic_read(&idev->event);
39043 + event_count = atomic_read_unchecked(&idev->event);
39044 if (event_count != listener->event_count) {
39045 if (copy_to_user(buf, &event_count, count))
39046 retval = -EFAULT;
39047 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39048 static void uio_vma_open(struct vm_area_struct *vma)
39049 {
39050 struct uio_device *idev = vma->vm_private_data;
39051 - idev->vma_count++;
39052 + local_inc(&idev->vma_count);
39053 }
39054
39055 static void uio_vma_close(struct vm_area_struct *vma)
39056 {
39057 struct uio_device *idev = vma->vm_private_data;
39058 - idev->vma_count--;
39059 + local_dec(&idev->vma_count);
39060 }
39061
39062 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39063 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
39064 idev->owner = owner;
39065 idev->info = info;
39066 init_waitqueue_head(&idev->wait);
39067 - atomic_set(&idev->event, 0);
39068 + atomic_set_unchecked(&idev->event, 0);
39069
39070 ret = uio_get_minor(idev);
39071 if (ret)
39072 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39073 index b7eb86a..36d28af 100644
39074 --- a/drivers/usb/atm/cxacru.c
39075 +++ b/drivers/usb/atm/cxacru.c
39076 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39077 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39078 if (ret < 2)
39079 return -EINVAL;
39080 - if (index < 0 || index > 0x7f)
39081 + if (index > 0x7f)
39082 return -EINVAL;
39083 pos += tmp;
39084
39085 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39086 index 35f10bf..6a38a0b 100644
39087 --- a/drivers/usb/atm/usbatm.c
39088 +++ b/drivers/usb/atm/usbatm.c
39089 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39090 if (printk_ratelimit())
39091 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39092 __func__, vpi, vci);
39093 - atomic_inc(&vcc->stats->rx_err);
39094 + atomic_inc_unchecked(&vcc->stats->rx_err);
39095 return;
39096 }
39097
39098 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39099 if (length > ATM_MAX_AAL5_PDU) {
39100 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39101 __func__, length, vcc);
39102 - atomic_inc(&vcc->stats->rx_err);
39103 + atomic_inc_unchecked(&vcc->stats->rx_err);
39104 goto out;
39105 }
39106
39107 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39108 if (sarb->len < pdu_length) {
39109 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39110 __func__, pdu_length, sarb->len, vcc);
39111 - atomic_inc(&vcc->stats->rx_err);
39112 + atomic_inc_unchecked(&vcc->stats->rx_err);
39113 goto out;
39114 }
39115
39116 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39117 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39118 __func__, vcc);
39119 - atomic_inc(&vcc->stats->rx_err);
39120 + atomic_inc_unchecked(&vcc->stats->rx_err);
39121 goto out;
39122 }
39123
39124 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39125 if (printk_ratelimit())
39126 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39127 __func__, length);
39128 - atomic_inc(&vcc->stats->rx_drop);
39129 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39130 goto out;
39131 }
39132
39133 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39134
39135 vcc->push(vcc, skb);
39136
39137 - atomic_inc(&vcc->stats->rx);
39138 + atomic_inc_unchecked(&vcc->stats->rx);
39139 out:
39140 skb_trim(sarb, 0);
39141 }
39142 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
39143 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39144
39145 usbatm_pop(vcc, skb);
39146 - atomic_inc(&vcc->stats->tx);
39147 + atomic_inc_unchecked(&vcc->stats->tx);
39148
39149 skb = skb_dequeue(&instance->sndqueue);
39150 }
39151 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39152 if (!left--)
39153 return sprintf(page,
39154 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39155 - atomic_read(&atm_dev->stats.aal5.tx),
39156 - atomic_read(&atm_dev->stats.aal5.tx_err),
39157 - atomic_read(&atm_dev->stats.aal5.rx),
39158 - atomic_read(&atm_dev->stats.aal5.rx_err),
39159 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39160 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39161 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39162 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39163 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39164 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39165
39166 if (!left--) {
39167 if (instance->disconnected)
39168 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39169 index f460de3..95ba1f6 100644
39170 --- a/drivers/usb/core/devices.c
39171 +++ b/drivers/usb/core/devices.c
39172 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39173 * time it gets called.
39174 */
39175 static struct device_connect_event {
39176 - atomic_t count;
39177 + atomic_unchecked_t count;
39178 wait_queue_head_t wait;
39179 } device_event = {
39180 .count = ATOMIC_INIT(1),
39181 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39182
39183 void usbfs_conn_disc_event(void)
39184 {
39185 - atomic_add(2, &device_event.count);
39186 + atomic_add_unchecked(2, &device_event.count);
39187 wake_up(&device_event.wait);
39188 }
39189
39190 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
39191
39192 poll_wait(file, &device_event.wait, wait);
39193
39194 - event_count = atomic_read(&device_event.count);
39195 + event_count = atomic_read_unchecked(&device_event.count);
39196 if (file->f_version != event_count) {
39197 file->f_version = event_count;
39198 return POLLIN | POLLRDNORM;
39199 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
39200 index f034716..aed0368 100644
39201 --- a/drivers/usb/core/hcd.c
39202 +++ b/drivers/usb/core/hcd.c
39203 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39204 */
39205 usb_get_urb(urb);
39206 atomic_inc(&urb->use_count);
39207 - atomic_inc(&urb->dev->urbnum);
39208 + atomic_inc_unchecked(&urb->dev->urbnum);
39209 usbmon_urb_submit(&hcd->self, urb);
39210
39211 /* NOTE requirements on root-hub callers (usbfs and the hub
39212 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39213 urb->hcpriv = NULL;
39214 INIT_LIST_HEAD(&urb->urb_list);
39215 atomic_dec(&urb->use_count);
39216 - atomic_dec(&urb->dev->urbnum);
39217 + atomic_dec_unchecked(&urb->dev->urbnum);
39218 if (atomic_read(&urb->reject))
39219 wake_up(&usb_kill_urb_queue);
39220 usb_put_urb(urb);
39221 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
39222 index 818e4a0..0fc9589 100644
39223 --- a/drivers/usb/core/sysfs.c
39224 +++ b/drivers/usb/core/sysfs.c
39225 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
39226 struct usb_device *udev;
39227
39228 udev = to_usb_device(dev);
39229 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
39230 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
39231 }
39232 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
39233
39234 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
39235 index cd8fb44..17fbe0c 100644
39236 --- a/drivers/usb/core/usb.c
39237 +++ b/drivers/usb/core/usb.c
39238 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
39239 set_dev_node(&dev->dev, dev_to_node(bus->controller));
39240 dev->state = USB_STATE_ATTACHED;
39241 dev->lpm_disable_count = 1;
39242 - atomic_set(&dev->urbnum, 0);
39243 + atomic_set_unchecked(&dev->urbnum, 0);
39244
39245 INIT_LIST_HEAD(&dev->ep0.urb_list);
39246 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
39247 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39248 index 4bfa78a..902bfbd 100644
39249 --- a/drivers/usb/early/ehci-dbgp.c
39250 +++ b/drivers/usb/early/ehci-dbgp.c
39251 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39252
39253 #ifdef CONFIG_KGDB
39254 static struct kgdb_io kgdbdbgp_io_ops;
39255 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39256 +static struct kgdb_io kgdbdbgp_io_ops_console;
39257 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39258 #else
39259 #define dbgp_kgdb_mode (0)
39260 #endif
39261 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39262 .write_char = kgdbdbgp_write_char,
39263 };
39264
39265 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39266 + .name = "kgdbdbgp",
39267 + .read_char = kgdbdbgp_read_char,
39268 + .write_char = kgdbdbgp_write_char,
39269 + .is_console = 1
39270 +};
39271 +
39272 static int kgdbdbgp_wait_time;
39273
39274 static int __init kgdbdbgp_parse_config(char *str)
39275 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39276 ptr++;
39277 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39278 }
39279 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39280 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39281 + if (early_dbgp_console.index != -1)
39282 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39283 + else
39284 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39285
39286 return 0;
39287 }
39288 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39289 index f173952..83d6ec0 100644
39290 --- a/drivers/usb/gadget/u_serial.c
39291 +++ b/drivers/usb/gadget/u_serial.c
39292 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39293 spin_lock_irq(&port->port_lock);
39294
39295 /* already open? Great. */
39296 - if (port->port.count) {
39297 + if (atomic_read(&port->port.count)) {
39298 status = 0;
39299 - port->port.count++;
39300 + atomic_inc(&port->port.count);
39301
39302 /* currently opening/closing? wait ... */
39303 } else if (port->openclose) {
39304 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39305 tty->driver_data = port;
39306 port->port.tty = tty;
39307
39308 - port->port.count = 1;
39309 + atomic_set(&port->port.count, 1);
39310 port->openclose = false;
39311
39312 /* if connected, start the I/O stream */
39313 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39314
39315 spin_lock_irq(&port->port_lock);
39316
39317 - if (port->port.count != 1) {
39318 - if (port->port.count == 0)
39319 + if (atomic_read(&port->port.count) != 1) {
39320 + if (atomic_read(&port->port.count) == 0)
39321 WARN_ON(1);
39322 else
39323 - --port->port.count;
39324 + atomic_dec(&port->port.count);
39325 goto exit;
39326 }
39327
39328 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39329 * and sleep if necessary
39330 */
39331 port->openclose = true;
39332 - port->port.count = 0;
39333 + atomic_set(&port->port.count, 0);
39334
39335 gser = port->port_usb;
39336 if (gser && gser->disconnect)
39337 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
39338 int cond;
39339
39340 spin_lock_irq(&port->port_lock);
39341 - cond = (port->port.count == 0) && !port->openclose;
39342 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39343 spin_unlock_irq(&port->port_lock);
39344 return cond;
39345 }
39346 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39347 /* if it's already open, start I/O ... and notify the serial
39348 * protocol about open/close status (connect/disconnect).
39349 */
39350 - if (port->port.count) {
39351 + if (atomic_read(&port->port.count)) {
39352 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39353 gs_start_io(port);
39354 if (gser->connect)
39355 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
39356
39357 port->port_usb = NULL;
39358 gser->ioport = NULL;
39359 - if (port->port.count > 0 || port->openclose) {
39360 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39361 wake_up_interruptible(&port->drain_wait);
39362 if (port->port.tty)
39363 tty_hangup(port->port.tty);
39364 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
39365
39366 /* finally, free any unused/unusable I/O buffers */
39367 spin_lock_irqsave(&port->port_lock, flags);
39368 - if (port->port.count == 0 && !port->openclose)
39369 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39370 gs_buf_free(&port->port_write_buf);
39371 gs_free_requests(gser->out, &port->read_pool, NULL);
39372 gs_free_requests(gser->out, &port->read_queue, NULL);
39373 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39374 index 5f3bcd3..bfca43f 100644
39375 --- a/drivers/usb/serial/console.c
39376 +++ b/drivers/usb/serial/console.c
39377 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
39378
39379 info->port = port;
39380
39381 - ++port->port.count;
39382 + atomic_inc(&port->port.count);
39383 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39384 if (serial->type->set_termios) {
39385 /*
39386 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
39387 }
39388 /* Now that any required fake tty operations are completed restore
39389 * the tty port count */
39390 - --port->port.count;
39391 + atomic_dec(&port->port.count);
39392 /* The console is special in terms of closing the device so
39393 * indicate this port is now acting as a system console. */
39394 port->port.console = 1;
39395 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
39396 free_tty:
39397 kfree(tty);
39398 reset_open_count:
39399 - port->port.count = 0;
39400 + atomic_set(&port->port.count, 0);
39401 usb_autopm_put_interface(serial->interface);
39402 error_get_interface:
39403 usb_serial_put(serial);
39404 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39405 index d6bea3e..60b250e 100644
39406 --- a/drivers/usb/wusbcore/wa-hc.h
39407 +++ b/drivers/usb/wusbcore/wa-hc.h
39408 @@ -192,7 +192,7 @@ struct wahc {
39409 struct list_head xfer_delayed_list;
39410 spinlock_t xfer_list_lock;
39411 struct work_struct xfer_work;
39412 - atomic_t xfer_id_count;
39413 + atomic_unchecked_t xfer_id_count;
39414 };
39415
39416
39417 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39418 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39419 spin_lock_init(&wa->xfer_list_lock);
39420 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39421 - atomic_set(&wa->xfer_id_count, 1);
39422 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39423 }
39424
39425 /**
39426 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39427 index 57c01ab..8a05959 100644
39428 --- a/drivers/usb/wusbcore/wa-xfer.c
39429 +++ b/drivers/usb/wusbcore/wa-xfer.c
39430 @@ -296,7 +296,7 @@ out:
39431 */
39432 static void wa_xfer_id_init(struct wa_xfer *xfer)
39433 {
39434 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39435 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39436 }
39437
39438 /*
39439 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39440 index dedaf81..b0f11ab 100644
39441 --- a/drivers/vhost/vhost.c
39442 +++ b/drivers/vhost/vhost.c
39443 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39444 return 0;
39445 }
39446
39447 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39448 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39449 {
39450 struct file *eventfp, *filep = NULL;
39451 bool pollstart = false, pollstop = false;
39452 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39453 index 0fefa84..7a9d581 100644
39454 --- a/drivers/video/aty/aty128fb.c
39455 +++ b/drivers/video/aty/aty128fb.c
39456 @@ -149,7 +149,7 @@ enum {
39457 };
39458
39459 /* Must match above enum */
39460 -static char * const r128_family[] __devinitconst = {
39461 +static const char * const r128_family[] __devinitconst = {
39462 "AGP",
39463 "PCI",
39464 "PRO AGP",
39465 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39466 index 5c3960d..15cf8fc 100644
39467 --- a/drivers/video/fbcmap.c
39468 +++ b/drivers/video/fbcmap.c
39469 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39470 rc = -ENODEV;
39471 goto out;
39472 }
39473 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39474 - !info->fbops->fb_setcmap)) {
39475 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39476 rc = -EINVAL;
39477 goto out1;
39478 }
39479 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39480 index 3ff0105..7589d98 100644
39481 --- a/drivers/video/fbmem.c
39482 +++ b/drivers/video/fbmem.c
39483 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39484 image->dx += image->width + 8;
39485 }
39486 } else if (rotate == FB_ROTATE_UD) {
39487 - for (x = 0; x < num && image->dx >= 0; x++) {
39488 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39489 info->fbops->fb_imageblit(info, image);
39490 image->dx -= image->width + 8;
39491 }
39492 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39493 image->dy += image->height + 8;
39494 }
39495 } else if (rotate == FB_ROTATE_CCW) {
39496 - for (x = 0; x < num && image->dy >= 0; x++) {
39497 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39498 info->fbops->fb_imageblit(info, image);
39499 image->dy -= image->height + 8;
39500 }
39501 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39502 return -EFAULT;
39503 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39504 return -EINVAL;
39505 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39506 + if (con2fb.framebuffer >= FB_MAX)
39507 return -EINVAL;
39508 if (!registered_fb[con2fb.framebuffer])
39509 request_module("fb%d", con2fb.framebuffer);
39510 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39511 index 7672d2e..b56437f 100644
39512 --- a/drivers/video/i810/i810_accel.c
39513 +++ b/drivers/video/i810/i810_accel.c
39514 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39515 }
39516 }
39517 printk("ringbuffer lockup!!!\n");
39518 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39519 i810_report_error(mmio);
39520 par->dev_flags |= LOCKUP;
39521 info->pixmap.scan_align = 1;
39522 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39523 index 3c14e43..eafa544 100644
39524 --- a/drivers/video/logo/logo_linux_clut224.ppm
39525 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39526 @@ -1,1604 +1,1123 @@
39527 P3
39528 -# Standard 224-color Linux logo
39529 80 80
39530 255
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 0 0 0 0
39535 - 0 0 0 0 0 0 0 0 0 0 0 0
39536 - 0 0 0 0 0 0 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 0 0 0 0
39539 - 0 0 0 0 0 0 0 0 0 0 0 0
39540 - 6 6 6 6 6 6 10 10 10 10 10 10
39541 - 10 10 10 6 6 6 6 6 6 6 6 6
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 6 6 6 10 10 10 14 14 14
39560 - 22 22 22 26 26 26 30 30 30 34 34 34
39561 - 30 30 30 30 30 30 26 26 26 18 18 18
39562 - 14 14 14 10 10 10 6 6 6 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 1 0 0 1 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 0 0 0
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 6 6 6 14 14 14 26 26 26 42 42 42
39580 - 54 54 54 66 66 66 78 78 78 78 78 78
39581 - 78 78 78 74 74 74 66 66 66 54 54 54
39582 - 42 42 42 26 26 26 18 18 18 10 10 10
39583 - 6 6 6 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 1 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 10 10 10
39599 - 22 22 22 42 42 42 66 66 66 86 86 86
39600 - 66 66 66 38 38 38 38 38 38 22 22 22
39601 - 26 26 26 34 34 34 54 54 54 66 66 66
39602 - 86 86 86 70 70 70 46 46 46 26 26 26
39603 - 14 14 14 6 6 6 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 1 0 0 1 0 0 1 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 10 10 10 26 26 26
39619 - 50 50 50 82 82 82 58 58 58 6 6 6
39620 - 2 2 6 2 2 6 2 2 6 2 2 6
39621 - 2 2 6 2 2 6 2 2 6 2 2 6
39622 - 6 6 6 54 54 54 86 86 86 66 66 66
39623 - 38 38 38 18 18 18 6 6 6 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 6 6 6 22 22 22 50 50 50
39639 - 78 78 78 34 34 34 2 2 6 2 2 6
39640 - 2 2 6 2 2 6 2 2 6 2 2 6
39641 - 2 2 6 2 2 6 2 2 6 2 2 6
39642 - 2 2 6 2 2 6 6 6 6 70 70 70
39643 - 78 78 78 46 46 46 22 22 22 6 6 6
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 1 0 0 1 0 0 1 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 6 6 6 18 18 18 42 42 42 82 82 82
39659 - 26 26 26 2 2 6 2 2 6 2 2 6
39660 - 2 2 6 2 2 6 2 2 6 2 2 6
39661 - 2 2 6 2 2 6 2 2 6 14 14 14
39662 - 46 46 46 34 34 34 6 6 6 2 2 6
39663 - 42 42 42 78 78 78 42 42 42 18 18 18
39664 - 6 6 6 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 1 0 0 0 0 0 1 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 0 0 0 0 0 0
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 10 10 10 30 30 30 66 66 66 58 58 58
39679 - 2 2 6 2 2 6 2 2 6 2 2 6
39680 - 2 2 6 2 2 6 2 2 6 2 2 6
39681 - 2 2 6 2 2 6 2 2 6 26 26 26
39682 - 86 86 86 101 101 101 46 46 46 10 10 10
39683 - 2 2 6 58 58 58 70 70 70 34 34 34
39684 - 10 10 10 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 1 0 0 1 0 0 1 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 14 14 14 42 42 42 86 86 86 10 10 10
39699 - 2 2 6 2 2 6 2 2 6 2 2 6
39700 - 2 2 6 2 2 6 2 2 6 2 2 6
39701 - 2 2 6 2 2 6 2 2 6 30 30 30
39702 - 94 94 94 94 94 94 58 58 58 26 26 26
39703 - 2 2 6 6 6 6 78 78 78 54 54 54
39704 - 22 22 22 6 6 6 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 6 6 6
39718 - 22 22 22 62 62 62 62 62 62 2 2 6
39719 - 2 2 6 2 2 6 2 2 6 2 2 6
39720 - 2 2 6 2 2 6 2 2 6 2 2 6
39721 - 2 2 6 2 2 6 2 2 6 26 26 26
39722 - 54 54 54 38 38 38 18 18 18 10 10 10
39723 - 2 2 6 2 2 6 34 34 34 82 82 82
39724 - 38 38 38 14 14 14 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 1 0 0 1 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 6 6 6
39738 - 30 30 30 78 78 78 30 30 30 2 2 6
39739 - 2 2 6 2 2 6 2 2 6 2 2 6
39740 - 2 2 6 2 2 6 2 2 6 2 2 6
39741 - 2 2 6 2 2 6 2 2 6 10 10 10
39742 - 10 10 10 2 2 6 2 2 6 2 2 6
39743 - 2 2 6 2 2 6 2 2 6 78 78 78
39744 - 50 50 50 18 18 18 6 6 6 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 1 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 10 10 10
39758 - 38 38 38 86 86 86 14 14 14 2 2 6
39759 - 2 2 6 2 2 6 2 2 6 2 2 6
39760 - 2 2 6 2 2 6 2 2 6 2 2 6
39761 - 2 2 6 2 2 6 2 2 6 2 2 6
39762 - 2 2 6 2 2 6 2 2 6 2 2 6
39763 - 2 2 6 2 2 6 2 2 6 54 54 54
39764 - 66 66 66 26 26 26 6 6 6 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 1 0 0 1 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 14 14 14
39778 - 42 42 42 82 82 82 2 2 6 2 2 6
39779 - 2 2 6 6 6 6 10 10 10 2 2 6
39780 - 2 2 6 2 2 6 2 2 6 2 2 6
39781 - 2 2 6 2 2 6 2 2 6 6 6 6
39782 - 14 14 14 10 10 10 2 2 6 2 2 6
39783 - 2 2 6 2 2 6 2 2 6 18 18 18
39784 - 82 82 82 34 34 34 10 10 10 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 1 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 14 14 14
39798 - 46 46 46 86 86 86 2 2 6 2 2 6
39799 - 6 6 6 6 6 6 22 22 22 34 34 34
39800 - 6 6 6 2 2 6 2 2 6 2 2 6
39801 - 2 2 6 2 2 6 18 18 18 34 34 34
39802 - 10 10 10 50 50 50 22 22 22 2 2 6
39803 - 2 2 6 2 2 6 2 2 6 10 10 10
39804 - 86 86 86 42 42 42 14 14 14 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 1 0 0 1 0 0 1 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 14 14 14
39818 - 46 46 46 86 86 86 2 2 6 2 2 6
39819 - 38 38 38 116 116 116 94 94 94 22 22 22
39820 - 22 22 22 2 2 6 2 2 6 2 2 6
39821 - 14 14 14 86 86 86 138 138 138 162 162 162
39822 -154 154 154 38 38 38 26 26 26 6 6 6
39823 - 2 2 6 2 2 6 2 2 6 2 2 6
39824 - 86 86 86 46 46 46 14 14 14 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 14 14 14
39838 - 46 46 46 86 86 86 2 2 6 14 14 14
39839 -134 134 134 198 198 198 195 195 195 116 116 116
39840 - 10 10 10 2 2 6 2 2 6 6 6 6
39841 -101 98 89 187 187 187 210 210 210 218 218 218
39842 -214 214 214 134 134 134 14 14 14 6 6 6
39843 - 2 2 6 2 2 6 2 2 6 2 2 6
39844 - 86 86 86 50 50 50 18 18 18 6 6 6
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 1 0 0 0
39852 - 0 0 1 0 0 1 0 0 1 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 14 14 14
39858 - 46 46 46 86 86 86 2 2 6 54 54 54
39859 -218 218 218 195 195 195 226 226 226 246 246 246
39860 - 58 58 58 2 2 6 2 2 6 30 30 30
39861 -210 210 210 253 253 253 174 174 174 123 123 123
39862 -221 221 221 234 234 234 74 74 74 2 2 6
39863 - 2 2 6 2 2 6 2 2 6 2 2 6
39864 - 70 70 70 58 58 58 22 22 22 6 6 6
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 14 14 14
39878 - 46 46 46 82 82 82 2 2 6 106 106 106
39879 -170 170 170 26 26 26 86 86 86 226 226 226
39880 -123 123 123 10 10 10 14 14 14 46 46 46
39881 -231 231 231 190 190 190 6 6 6 70 70 70
39882 - 90 90 90 238 238 238 158 158 158 2 2 6
39883 - 2 2 6 2 2 6 2 2 6 2 2 6
39884 - 70 70 70 58 58 58 22 22 22 6 6 6
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 1 0 0 0
39892 - 0 0 1 0 0 1 0 0 1 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 14 14 14
39898 - 42 42 42 86 86 86 6 6 6 116 116 116
39899 -106 106 106 6 6 6 70 70 70 149 149 149
39900 -128 128 128 18 18 18 38 38 38 54 54 54
39901 -221 221 221 106 106 106 2 2 6 14 14 14
39902 - 46 46 46 190 190 190 198 198 198 2 2 6
39903 - 2 2 6 2 2 6 2 2 6 2 2 6
39904 - 74 74 74 62 62 62 22 22 22 6 6 6
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 1 0 0 0
39912 - 0 0 1 0 0 0 0 0 1 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 14 14 14
39918 - 42 42 42 94 94 94 14 14 14 101 101 101
39919 -128 128 128 2 2 6 18 18 18 116 116 116
39920 -118 98 46 121 92 8 121 92 8 98 78 10
39921 -162 162 162 106 106 106 2 2 6 2 2 6
39922 - 2 2 6 195 195 195 195 195 195 6 6 6
39923 - 2 2 6 2 2 6 2 2 6 2 2 6
39924 - 74 74 74 62 62 62 22 22 22 6 6 6
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 1 0 0 1
39932 - 0 0 1 0 0 0 0 0 1 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 10 10 10
39938 - 38 38 38 90 90 90 14 14 14 58 58 58
39939 -210 210 210 26 26 26 54 38 6 154 114 10
39940 -226 170 11 236 186 11 225 175 15 184 144 12
39941 -215 174 15 175 146 61 37 26 9 2 2 6
39942 - 70 70 70 246 246 246 138 138 138 2 2 6
39943 - 2 2 6 2 2 6 2 2 6 2 2 6
39944 - 70 70 70 66 66 66 26 26 26 6 6 6
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 10 10 10
39958 - 38 38 38 86 86 86 14 14 14 10 10 10
39959 -195 195 195 188 164 115 192 133 9 225 175 15
39960 -239 182 13 234 190 10 232 195 16 232 200 30
39961 -245 207 45 241 208 19 232 195 16 184 144 12
39962 -218 194 134 211 206 186 42 42 42 2 2 6
39963 - 2 2 6 2 2 6 2 2 6 2 2 6
39964 - 50 50 50 74 74 74 30 30 30 6 6 6
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 10 10 10
39978 - 34 34 34 86 86 86 14 14 14 2 2 6
39979 -121 87 25 192 133 9 219 162 10 239 182 13
39980 -236 186 11 232 195 16 241 208 19 244 214 54
39981 -246 218 60 246 218 38 246 215 20 241 208 19
39982 -241 208 19 226 184 13 121 87 25 2 2 6
39983 - 2 2 6 2 2 6 2 2 6 2 2 6
39984 - 50 50 50 82 82 82 34 34 34 10 10 10
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 10 10 10
39998 - 34 34 34 82 82 82 30 30 30 61 42 6
39999 -180 123 7 206 145 10 230 174 11 239 182 13
40000 -234 190 10 238 202 15 241 208 19 246 218 74
40001 -246 218 38 246 215 20 246 215 20 246 215 20
40002 -226 184 13 215 174 15 184 144 12 6 6 6
40003 - 2 2 6 2 2 6 2 2 6 2 2 6
40004 - 26 26 26 94 94 94 42 42 42 14 14 14
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 10 10 10
40018 - 30 30 30 78 78 78 50 50 50 104 69 6
40019 -192 133 9 216 158 10 236 178 12 236 186 11
40020 -232 195 16 241 208 19 244 214 54 245 215 43
40021 -246 215 20 246 215 20 241 208 19 198 155 10
40022 -200 144 11 216 158 10 156 118 10 2 2 6
40023 - 2 2 6 2 2 6 2 2 6 2 2 6
40024 - 6 6 6 90 90 90 54 54 54 18 18 18
40025 - 6 6 6 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 10 10 10
40038 - 30 30 30 78 78 78 46 46 46 22 22 22
40039 -137 92 6 210 162 10 239 182 13 238 190 10
40040 -238 202 15 241 208 19 246 215 20 246 215 20
40041 -241 208 19 203 166 17 185 133 11 210 150 10
40042 -216 158 10 210 150 10 102 78 10 2 2 6
40043 - 6 6 6 54 54 54 14 14 14 2 2 6
40044 - 2 2 6 62 62 62 74 74 74 30 30 30
40045 - 10 10 10 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 10 10 10
40058 - 34 34 34 78 78 78 50 50 50 6 6 6
40059 - 94 70 30 139 102 15 190 146 13 226 184 13
40060 -232 200 30 232 195 16 215 174 15 190 146 13
40061 -168 122 10 192 133 9 210 150 10 213 154 11
40062 -202 150 34 182 157 106 101 98 89 2 2 6
40063 - 2 2 6 78 78 78 116 116 116 58 58 58
40064 - 2 2 6 22 22 22 90 90 90 46 46 46
40065 - 18 18 18 6 6 6 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 10 10 10
40078 - 38 38 38 86 86 86 50 50 50 6 6 6
40079 -128 128 128 174 154 114 156 107 11 168 122 10
40080 -198 155 10 184 144 12 197 138 11 200 144 11
40081 -206 145 10 206 145 10 197 138 11 188 164 115
40082 -195 195 195 198 198 198 174 174 174 14 14 14
40083 - 2 2 6 22 22 22 116 116 116 116 116 116
40084 - 22 22 22 2 2 6 74 74 74 70 70 70
40085 - 30 30 30 10 10 10 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 6 6 6 18 18 18
40098 - 50 50 50 101 101 101 26 26 26 10 10 10
40099 -138 138 138 190 190 190 174 154 114 156 107 11
40100 -197 138 11 200 144 11 197 138 11 192 133 9
40101 -180 123 7 190 142 34 190 178 144 187 187 187
40102 -202 202 202 221 221 221 214 214 214 66 66 66
40103 - 2 2 6 2 2 6 50 50 50 62 62 62
40104 - 6 6 6 2 2 6 10 10 10 90 90 90
40105 - 50 50 50 18 18 18 6 6 6 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 10 10 10 34 34 34
40118 - 74 74 74 74 74 74 2 2 6 6 6 6
40119 -144 144 144 198 198 198 190 190 190 178 166 146
40120 -154 121 60 156 107 11 156 107 11 168 124 44
40121 -174 154 114 187 187 187 190 190 190 210 210 210
40122 -246 246 246 253 253 253 253 253 253 182 182 182
40123 - 6 6 6 2 2 6 2 2 6 2 2 6
40124 - 2 2 6 2 2 6 2 2 6 62 62 62
40125 - 74 74 74 34 34 34 14 14 14 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 10 10 10 22 22 22 54 54 54
40138 - 94 94 94 18 18 18 2 2 6 46 46 46
40139 -234 234 234 221 221 221 190 190 190 190 190 190
40140 -190 190 190 187 187 187 187 187 187 190 190 190
40141 -190 190 190 195 195 195 214 214 214 242 242 242
40142 -253 253 253 253 253 253 253 253 253 253 253 253
40143 - 82 82 82 2 2 6 2 2 6 2 2 6
40144 - 2 2 6 2 2 6 2 2 6 14 14 14
40145 - 86 86 86 54 54 54 22 22 22 6 6 6
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 6 6 6 18 18 18 46 46 46 90 90 90
40158 - 46 46 46 18 18 18 6 6 6 182 182 182
40159 -253 253 253 246 246 246 206 206 206 190 190 190
40160 -190 190 190 190 190 190 190 190 190 190 190 190
40161 -206 206 206 231 231 231 250 250 250 253 253 253
40162 -253 253 253 253 253 253 253 253 253 253 253 253
40163 -202 202 202 14 14 14 2 2 6 2 2 6
40164 - 2 2 6 2 2 6 2 2 6 2 2 6
40165 - 42 42 42 86 86 86 42 42 42 18 18 18
40166 - 6 6 6 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 6 6 6
40177 - 14 14 14 38 38 38 74 74 74 66 66 66
40178 - 2 2 6 6 6 6 90 90 90 250 250 250
40179 -253 253 253 253 253 253 238 238 238 198 198 198
40180 -190 190 190 190 190 190 195 195 195 221 221 221
40181 -246 246 246 253 253 253 253 253 253 253 253 253
40182 -253 253 253 253 253 253 253 253 253 253 253 253
40183 -253 253 253 82 82 82 2 2 6 2 2 6
40184 - 2 2 6 2 2 6 2 2 6 2 2 6
40185 - 2 2 6 78 78 78 70 70 70 34 34 34
40186 - 14 14 14 6 6 6 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 14 14 14
40197 - 34 34 34 66 66 66 78 78 78 6 6 6
40198 - 2 2 6 18 18 18 218 218 218 253 253 253
40199 -253 253 253 253 253 253 253 253 253 246 246 246
40200 -226 226 226 231 231 231 246 246 246 253 253 253
40201 -253 253 253 253 253 253 253 253 253 253 253 253
40202 -253 253 253 253 253 253 253 253 253 253 253 253
40203 -253 253 253 178 178 178 2 2 6 2 2 6
40204 - 2 2 6 2 2 6 2 2 6 2 2 6
40205 - 2 2 6 18 18 18 90 90 90 62 62 62
40206 - 30 30 30 10 10 10 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 10 10 10 26 26 26
40217 - 58 58 58 90 90 90 18 18 18 2 2 6
40218 - 2 2 6 110 110 110 253 253 253 253 253 253
40219 -253 253 253 253 253 253 253 253 253 253 253 253
40220 -250 250 250 253 253 253 253 253 253 253 253 253
40221 -253 253 253 253 253 253 253 253 253 253 253 253
40222 -253 253 253 253 253 253 253 253 253 253 253 253
40223 -253 253 253 231 231 231 18 18 18 2 2 6
40224 - 2 2 6 2 2 6 2 2 6 2 2 6
40225 - 2 2 6 2 2 6 18 18 18 94 94 94
40226 - 54 54 54 26 26 26 10 10 10 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 6 6 6 22 22 22 50 50 50
40237 - 90 90 90 26 26 26 2 2 6 2 2 6
40238 - 14 14 14 195 195 195 250 250 250 253 253 253
40239 -253 253 253 253 253 253 253 253 253 253 253 253
40240 -253 253 253 253 253 253 253 253 253 253 253 253
40241 -253 253 253 253 253 253 253 253 253 253 253 253
40242 -253 253 253 253 253 253 253 253 253 253 253 253
40243 -250 250 250 242 242 242 54 54 54 2 2 6
40244 - 2 2 6 2 2 6 2 2 6 2 2 6
40245 - 2 2 6 2 2 6 2 2 6 38 38 38
40246 - 86 86 86 50 50 50 22 22 22 6 6 6
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 6 6 6 14 14 14 38 38 38 82 82 82
40257 - 34 34 34 2 2 6 2 2 6 2 2 6
40258 - 42 42 42 195 195 195 246 246 246 253 253 253
40259 -253 253 253 253 253 253 253 253 253 250 250 250
40260 -242 242 242 242 242 242 250 250 250 253 253 253
40261 -253 253 253 253 253 253 253 253 253 253 253 253
40262 -253 253 253 250 250 250 246 246 246 238 238 238
40263 -226 226 226 231 231 231 101 101 101 6 6 6
40264 - 2 2 6 2 2 6 2 2 6 2 2 6
40265 - 2 2 6 2 2 6 2 2 6 2 2 6
40266 - 38 38 38 82 82 82 42 42 42 14 14 14
40267 - 6 6 6 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 10 10 10 26 26 26 62 62 62 66 66 66
40277 - 2 2 6 2 2 6 2 2 6 6 6 6
40278 - 70 70 70 170 170 170 206 206 206 234 234 234
40279 -246 246 246 250 250 250 250 250 250 238 238 238
40280 -226 226 226 231 231 231 238 238 238 250 250 250
40281 -250 250 250 250 250 250 246 246 246 231 231 231
40282 -214 214 214 206 206 206 202 202 202 202 202 202
40283 -198 198 198 202 202 202 182 182 182 18 18 18
40284 - 2 2 6 2 2 6 2 2 6 2 2 6
40285 - 2 2 6 2 2 6 2 2 6 2 2 6
40286 - 2 2 6 62 62 62 66 66 66 30 30 30
40287 - 10 10 10 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 14 14 14 42 42 42 82 82 82 18 18 18
40297 - 2 2 6 2 2 6 2 2 6 10 10 10
40298 - 94 94 94 182 182 182 218 218 218 242 242 242
40299 -250 250 250 253 253 253 253 253 253 250 250 250
40300 -234 234 234 253 253 253 253 253 253 253 253 253
40301 -253 253 253 253 253 253 253 253 253 246 246 246
40302 -238 238 238 226 226 226 210 210 210 202 202 202
40303 -195 195 195 195 195 195 210 210 210 158 158 158
40304 - 6 6 6 14 14 14 50 50 50 14 14 14
40305 - 2 2 6 2 2 6 2 2 6 2 2 6
40306 - 2 2 6 6 6 6 86 86 86 46 46 46
40307 - 18 18 18 6 6 6 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 6 6 6
40316 - 22 22 22 54 54 54 70 70 70 2 2 6
40317 - 2 2 6 10 10 10 2 2 6 22 22 22
40318 -166 166 166 231 231 231 250 250 250 253 253 253
40319 -253 253 253 253 253 253 253 253 253 250 250 250
40320 -242 242 242 253 253 253 253 253 253 253 253 253
40321 -253 253 253 253 253 253 253 253 253 253 253 253
40322 -253 253 253 253 253 253 253 253 253 246 246 246
40323 -231 231 231 206 206 206 198 198 198 226 226 226
40324 - 94 94 94 2 2 6 6 6 6 38 38 38
40325 - 30 30 30 2 2 6 2 2 6 2 2 6
40326 - 2 2 6 2 2 6 62 62 62 66 66 66
40327 - 26 26 26 10 10 10 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 10 10 10
40336 - 30 30 30 74 74 74 50 50 50 2 2 6
40337 - 26 26 26 26 26 26 2 2 6 106 106 106
40338 -238 238 238 253 253 253 253 253 253 253 253 253
40339 -253 253 253 253 253 253 253 253 253 253 253 253
40340 -253 253 253 253 253 253 253 253 253 253 253 253
40341 -253 253 253 253 253 253 253 253 253 253 253 253
40342 -253 253 253 253 253 253 253 253 253 253 253 253
40343 -253 253 253 246 246 246 218 218 218 202 202 202
40344 -210 210 210 14 14 14 2 2 6 2 2 6
40345 - 30 30 30 22 22 22 2 2 6 2 2 6
40346 - 2 2 6 2 2 6 18 18 18 86 86 86
40347 - 42 42 42 14 14 14 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 14 14 14
40356 - 42 42 42 90 90 90 22 22 22 2 2 6
40357 - 42 42 42 2 2 6 18 18 18 218 218 218
40358 -253 253 253 253 253 253 253 253 253 253 253 253
40359 -253 253 253 253 253 253 253 253 253 253 253 253
40360 -253 253 253 253 253 253 253 253 253 253 253 253
40361 -253 253 253 253 253 253 253 253 253 253 253 253
40362 -253 253 253 253 253 253 253 253 253 253 253 253
40363 -253 253 253 253 253 253 250 250 250 221 221 221
40364 -218 218 218 101 101 101 2 2 6 14 14 14
40365 - 18 18 18 38 38 38 10 10 10 2 2 6
40366 - 2 2 6 2 2 6 2 2 6 78 78 78
40367 - 58 58 58 22 22 22 6 6 6 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 6 6 6 18 18 18
40376 - 54 54 54 82 82 82 2 2 6 26 26 26
40377 - 22 22 22 2 2 6 123 123 123 253 253 253
40378 -253 253 253 253 253 253 253 253 253 253 253 253
40379 -253 253 253 253 253 253 253 253 253 253 253 253
40380 -253 253 253 253 253 253 253 253 253 253 253 253
40381 -253 253 253 253 253 253 253 253 253 253 253 253
40382 -253 253 253 253 253 253 253 253 253 253 253 253
40383 -253 253 253 253 253 253 253 253 253 250 250 250
40384 -238 238 238 198 198 198 6 6 6 38 38 38
40385 - 58 58 58 26 26 26 38 38 38 2 2 6
40386 - 2 2 6 2 2 6 2 2 6 46 46 46
40387 - 78 78 78 30 30 30 10 10 10 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 10 10 10 30 30 30
40396 - 74 74 74 58 58 58 2 2 6 42 42 42
40397 - 2 2 6 22 22 22 231 231 231 253 253 253
40398 -253 253 253 253 253 253 253 253 253 253 253 253
40399 -253 253 253 253 253 253 253 253 253 250 250 250
40400 -253 253 253 253 253 253 253 253 253 253 253 253
40401 -253 253 253 253 253 253 253 253 253 253 253 253
40402 -253 253 253 253 253 253 253 253 253 253 253 253
40403 -253 253 253 253 253 253 253 253 253 253 253 253
40404 -253 253 253 246 246 246 46 46 46 38 38 38
40405 - 42 42 42 14 14 14 38 38 38 14 14 14
40406 - 2 2 6 2 2 6 2 2 6 6 6 6
40407 - 86 86 86 46 46 46 14 14 14 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 6 6 6 14 14 14 42 42 42
40416 - 90 90 90 18 18 18 18 18 18 26 26 26
40417 - 2 2 6 116 116 116 253 253 253 253 253 253
40418 -253 253 253 253 253 253 253 253 253 253 253 253
40419 -253 253 253 253 253 253 250 250 250 238 238 238
40420 -253 253 253 253 253 253 253 253 253 253 253 253
40421 -253 253 253 253 253 253 253 253 253 253 253 253
40422 -253 253 253 253 253 253 253 253 253 253 253 253
40423 -253 253 253 253 253 253 253 253 253 253 253 253
40424 -253 253 253 253 253 253 94 94 94 6 6 6
40425 - 2 2 6 2 2 6 10 10 10 34 34 34
40426 - 2 2 6 2 2 6 2 2 6 2 2 6
40427 - 74 74 74 58 58 58 22 22 22 6 6 6
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 10 10 10 26 26 26 66 66 66
40436 - 82 82 82 2 2 6 38 38 38 6 6 6
40437 - 14 14 14 210 210 210 253 253 253 253 253 253
40438 -253 253 253 253 253 253 253 253 253 253 253 253
40439 -253 253 253 253 253 253 246 246 246 242 242 242
40440 -253 253 253 253 253 253 253 253 253 253 253 253
40441 -253 253 253 253 253 253 253 253 253 253 253 253
40442 -253 253 253 253 253 253 253 253 253 253 253 253
40443 -253 253 253 253 253 253 253 253 253 253 253 253
40444 -253 253 253 253 253 253 144 144 144 2 2 6
40445 - 2 2 6 2 2 6 2 2 6 46 46 46
40446 - 2 2 6 2 2 6 2 2 6 2 2 6
40447 - 42 42 42 74 74 74 30 30 30 10 10 10
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 6 6 6 14 14 14 42 42 42 90 90 90
40456 - 26 26 26 6 6 6 42 42 42 2 2 6
40457 - 74 74 74 250 250 250 253 253 253 253 253 253
40458 -253 253 253 253 253 253 253 253 253 253 253 253
40459 -253 253 253 253 253 253 242 242 242 242 242 242
40460 -253 253 253 253 253 253 253 253 253 253 253 253
40461 -253 253 253 253 253 253 253 253 253 253 253 253
40462 -253 253 253 253 253 253 253 253 253 253 253 253
40463 -253 253 253 253 253 253 253 253 253 253 253 253
40464 -253 253 253 253 253 253 182 182 182 2 2 6
40465 - 2 2 6 2 2 6 2 2 6 46 46 46
40466 - 2 2 6 2 2 6 2 2 6 2 2 6
40467 - 10 10 10 86 86 86 38 38 38 10 10 10
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 0 0 0 0 0 0
40470 - 0 0 0 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 0 0 0
40472 - 0 0 0 0 0 0 0 0 0 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 10 10 10 26 26 26 66 66 66 82 82 82
40476 - 2 2 6 22 22 22 18 18 18 2 2 6
40477 -149 149 149 253 253 253 253 253 253 253 253 253
40478 -253 253 253 253 253 253 253 253 253 253 253 253
40479 -253 253 253 253 253 253 234 234 234 242 242 242
40480 -253 253 253 253 253 253 253 253 253 253 253 253
40481 -253 253 253 253 253 253 253 253 253 253 253 253
40482 -253 253 253 253 253 253 253 253 253 253 253 253
40483 -253 253 253 253 253 253 253 253 253 253 253 253
40484 -253 253 253 253 253 253 206 206 206 2 2 6
40485 - 2 2 6 2 2 6 2 2 6 38 38 38
40486 - 2 2 6 2 2 6 2 2 6 2 2 6
40487 - 6 6 6 86 86 86 46 46 46 14 14 14
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 0 0 0 0 0 0
40490 - 0 0 0 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 0 0 0
40492 - 0 0 0 0 0 0 0 0 0 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 6 6 6
40495 - 18 18 18 46 46 46 86 86 86 18 18 18
40496 - 2 2 6 34 34 34 10 10 10 6 6 6
40497 -210 210 210 253 253 253 253 253 253 253 253 253
40498 -253 253 253 253 253 253 253 253 253 253 253 253
40499 -253 253 253 253 253 253 234 234 234 242 242 242
40500 -253 253 253 253 253 253 253 253 253 253 253 253
40501 -253 253 253 253 253 253 253 253 253 253 253 253
40502 -253 253 253 253 253 253 253 253 253 253 253 253
40503 -253 253 253 253 253 253 253 253 253 253 253 253
40504 -253 253 253 253 253 253 221 221 221 6 6 6
40505 - 2 2 6 2 2 6 6 6 6 30 30 30
40506 - 2 2 6 2 2 6 2 2 6 2 2 6
40507 - 2 2 6 82 82 82 54 54 54 18 18 18
40508 - 6 6 6 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 0 0 0
40512 - 0 0 0 0 0 0 0 0 0 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 10 10 10
40515 - 26 26 26 66 66 66 62 62 62 2 2 6
40516 - 2 2 6 38 38 38 10 10 10 26 26 26
40517 -238 238 238 253 253 253 253 253 253 253 253 253
40518 -253 253 253 253 253 253 253 253 253 253 253 253
40519 -253 253 253 253 253 253 231 231 231 238 238 238
40520 -253 253 253 253 253 253 253 253 253 253 253 253
40521 -253 253 253 253 253 253 253 253 253 253 253 253
40522 -253 253 253 253 253 253 253 253 253 253 253 253
40523 -253 253 253 253 253 253 253 253 253 253 253 253
40524 -253 253 253 253 253 253 231 231 231 6 6 6
40525 - 2 2 6 2 2 6 10 10 10 30 30 30
40526 - 2 2 6 2 2 6 2 2 6 2 2 6
40527 - 2 2 6 66 66 66 58 58 58 22 22 22
40528 - 6 6 6 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 10 10 10
40535 - 38 38 38 78 78 78 6 6 6 2 2 6
40536 - 2 2 6 46 46 46 14 14 14 42 42 42
40537 -246 246 246 253 253 253 253 253 253 253 253 253
40538 -253 253 253 253 253 253 253 253 253 253 253 253
40539 -253 253 253 253 253 253 231 231 231 242 242 242
40540 -253 253 253 253 253 253 253 253 253 253 253 253
40541 -253 253 253 253 253 253 253 253 253 253 253 253
40542 -253 253 253 253 253 253 253 253 253 253 253 253
40543 -253 253 253 253 253 253 253 253 253 253 253 253
40544 -253 253 253 253 253 253 234 234 234 10 10 10
40545 - 2 2 6 2 2 6 22 22 22 14 14 14
40546 - 2 2 6 2 2 6 2 2 6 2 2 6
40547 - 2 2 6 66 66 66 62 62 62 22 22 22
40548 - 6 6 6 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 6 6 6 18 18 18
40555 - 50 50 50 74 74 74 2 2 6 2 2 6
40556 - 14 14 14 70 70 70 34 34 34 62 62 62
40557 -250 250 250 253 253 253 253 253 253 253 253 253
40558 -253 253 253 253 253 253 253 253 253 253 253 253
40559 -253 253 253 253 253 253 231 231 231 246 246 246
40560 -253 253 253 253 253 253 253 253 253 253 253 253
40561 -253 253 253 253 253 253 253 253 253 253 253 253
40562 -253 253 253 253 253 253 253 253 253 253 253 253
40563 -253 253 253 253 253 253 253 253 253 253 253 253
40564 -253 253 253 253 253 253 234 234 234 14 14 14
40565 - 2 2 6 2 2 6 30 30 30 2 2 6
40566 - 2 2 6 2 2 6 2 2 6 2 2 6
40567 - 2 2 6 66 66 66 62 62 62 22 22 22
40568 - 6 6 6 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 0 0 0 0 0 0
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 0 0 0 0 0 0
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 6 6 6 18 18 18
40575 - 54 54 54 62 62 62 2 2 6 2 2 6
40576 - 2 2 6 30 30 30 46 46 46 70 70 70
40577 -250 250 250 253 253 253 253 253 253 253 253 253
40578 -253 253 253 253 253 253 253 253 253 253 253 253
40579 -253 253 253 253 253 253 231 231 231 246 246 246
40580 -253 253 253 253 253 253 253 253 253 253 253 253
40581 -253 253 253 253 253 253 253 253 253 253 253 253
40582 -253 253 253 253 253 253 253 253 253 253 253 253
40583 -253 253 253 253 253 253 253 253 253 253 253 253
40584 -253 253 253 253 253 253 226 226 226 10 10 10
40585 - 2 2 6 6 6 6 30 30 30 2 2 6
40586 - 2 2 6 2 2 6 2 2 6 2 2 6
40587 - 2 2 6 66 66 66 58 58 58 22 22 22
40588 - 6 6 6 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 0 0 0 0 0 0
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 0 0 0 0 0 0 0 0 0
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 6 6 6 22 22 22
40595 - 58 58 58 62 62 62 2 2 6 2 2 6
40596 - 2 2 6 2 2 6 30 30 30 78 78 78
40597 -250 250 250 253 253 253 253 253 253 253 253 253
40598 -253 253 253 253 253 253 253 253 253 253 253 253
40599 -253 253 253 253 253 253 231 231 231 246 246 246
40600 -253 253 253 253 253 253 253 253 253 253 253 253
40601 -253 253 253 253 253 253 253 253 253 253 253 253
40602 -253 253 253 253 253 253 253 253 253 253 253 253
40603 -253 253 253 253 253 253 253 253 253 253 253 253
40604 -253 253 253 253 253 253 206 206 206 2 2 6
40605 - 22 22 22 34 34 34 18 14 6 22 22 22
40606 - 26 26 26 18 18 18 6 6 6 2 2 6
40607 - 2 2 6 82 82 82 54 54 54 18 18 18
40608 - 6 6 6 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 0 0 0 0 0 0
40610 - 0 0 0 0 0 0 0 0 0 0 0 0
40611 - 0 0 0 0 0 0 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 6 6 6 26 26 26
40615 - 62 62 62 106 106 106 74 54 14 185 133 11
40616 -210 162 10 121 92 8 6 6 6 62 62 62
40617 -238 238 238 253 253 253 253 253 253 253 253 253
40618 -253 253 253 253 253 253 253 253 253 253 253 253
40619 -253 253 253 253 253 253 231 231 231 246 246 246
40620 -253 253 253 253 253 253 253 253 253 253 253 253
40621 -253 253 253 253 253 253 253 253 253 253 253 253
40622 -253 253 253 253 253 253 253 253 253 253 253 253
40623 -253 253 253 253 253 253 253 253 253 253 253 253
40624 -253 253 253 253 253 253 158 158 158 18 18 18
40625 - 14 14 14 2 2 6 2 2 6 2 2 6
40626 - 6 6 6 18 18 18 66 66 66 38 38 38
40627 - 6 6 6 94 94 94 50 50 50 18 18 18
40628 - 6 6 6 0 0 0 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 0 0 0 0 0 0
40630 - 0 0 0 0 0 0 0 0 0 0 0 0
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 6 6 6
40634 - 10 10 10 10 10 10 18 18 18 38 38 38
40635 - 78 78 78 142 134 106 216 158 10 242 186 14
40636 -246 190 14 246 190 14 156 118 10 10 10 10
40637 - 90 90 90 238 238 238 253 253 253 253 253 253
40638 -253 253 253 253 253 253 253 253 253 253 253 253
40639 -253 253 253 253 253 253 231 231 231 250 250 250
40640 -253 253 253 253 253 253 253 253 253 253 253 253
40641 -253 253 253 253 253 253 253 253 253 253 253 253
40642 -253 253 253 253 253 253 253 253 253 253 253 253
40643 -253 253 253 253 253 253 253 253 253 246 230 190
40644 -238 204 91 238 204 91 181 142 44 37 26 9
40645 - 2 2 6 2 2 6 2 2 6 2 2 6
40646 - 2 2 6 2 2 6 38 38 38 46 46 46
40647 - 26 26 26 106 106 106 54 54 54 18 18 18
40648 - 6 6 6 0 0 0 0 0 0 0 0 0
40649 - 0 0 0 0 0 0 0 0 0 0 0 0
40650 - 0 0 0 0 0 0 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 6 6 6 14 14 14 22 22 22
40654 - 30 30 30 38 38 38 50 50 50 70 70 70
40655 -106 106 106 190 142 34 226 170 11 242 186 14
40656 -246 190 14 246 190 14 246 190 14 154 114 10
40657 - 6 6 6 74 74 74 226 226 226 253 253 253
40658 -253 253 253 253 253 253 253 253 253 253 253 253
40659 -253 253 253 253 253 253 231 231 231 250 250 250
40660 -253 253 253 253 253 253 253 253 253 253 253 253
40661 -253 253 253 253 253 253 253 253 253 253 253 253
40662 -253 253 253 253 253 253 253 253 253 253 253 253
40663 -253 253 253 253 253 253 253 253 253 228 184 62
40664 -241 196 14 241 208 19 232 195 16 38 30 10
40665 - 2 2 6 2 2 6 2 2 6 2 2 6
40666 - 2 2 6 6 6 6 30 30 30 26 26 26
40667 -203 166 17 154 142 90 66 66 66 26 26 26
40668 - 6 6 6 0 0 0 0 0 0 0 0 0
40669 - 0 0 0 0 0 0 0 0 0 0 0 0
40670 - 0 0 0 0 0 0 0 0 0 0 0 0
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 6 6 6 18 18 18 38 38 38 58 58 58
40674 - 78 78 78 86 86 86 101 101 101 123 123 123
40675 -175 146 61 210 150 10 234 174 13 246 186 14
40676 -246 190 14 246 190 14 246 190 14 238 190 10
40677 -102 78 10 2 2 6 46 46 46 198 198 198
40678 -253 253 253 253 253 253 253 253 253 253 253 253
40679 -253 253 253 253 253 253 234 234 234 242 242 242
40680 -253 253 253 253 253 253 253 253 253 253 253 253
40681 -253 253 253 253 253 253 253 253 253 253 253 253
40682 -253 253 253 253 253 253 253 253 253 253 253 253
40683 -253 253 253 253 253 253 253 253 253 224 178 62
40684 -242 186 14 241 196 14 210 166 10 22 18 6
40685 - 2 2 6 2 2 6 2 2 6 2 2 6
40686 - 2 2 6 2 2 6 6 6 6 121 92 8
40687 -238 202 15 232 195 16 82 82 82 34 34 34
40688 - 10 10 10 0 0 0 0 0 0 0 0 0
40689 - 0 0 0 0 0 0 0 0 0 0 0 0
40690 - 0 0 0 0 0 0 0 0 0 0 0 0
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 14 14 14 38 38 38 70 70 70 154 122 46
40694 -190 142 34 200 144 11 197 138 11 197 138 11
40695 -213 154 11 226 170 11 242 186 14 246 190 14
40696 -246 190 14 246 190 14 246 190 14 246 190 14
40697 -225 175 15 46 32 6 2 2 6 22 22 22
40698 -158 158 158 250 250 250 253 253 253 253 253 253
40699 -253 253 253 253 253 253 253 253 253 253 253 253
40700 -253 253 253 253 253 253 253 253 253 253 253 253
40701 -253 253 253 253 253 253 253 253 253 253 253 253
40702 -253 253 253 253 253 253 253 253 253 253 253 253
40703 -253 253 253 250 250 250 242 242 242 224 178 62
40704 -239 182 13 236 186 11 213 154 11 46 32 6
40705 - 2 2 6 2 2 6 2 2 6 2 2 6
40706 - 2 2 6 2 2 6 61 42 6 225 175 15
40707 -238 190 10 236 186 11 112 100 78 42 42 42
40708 - 14 14 14 0 0 0 0 0 0 0 0 0
40709 - 0 0 0 0 0 0 0 0 0 0 0 0
40710 - 0 0 0 0 0 0 0 0 0 0 0 0
40711 - 0 0 0 0 0 0 0 0 0 0 0 0
40712 - 0 0 0 0 0 0 0 0 0 6 6 6
40713 - 22 22 22 54 54 54 154 122 46 213 154 11
40714 -226 170 11 230 174 11 226 170 11 226 170 11
40715 -236 178 12 242 186 14 246 190 14 246 190 14
40716 -246 190 14 246 190 14 246 190 14 246 190 14
40717 -241 196 14 184 144 12 10 10 10 2 2 6
40718 - 6 6 6 116 116 116 242 242 242 253 253 253
40719 -253 253 253 253 253 253 253 253 253 253 253 253
40720 -253 253 253 253 253 253 253 253 253 253 253 253
40721 -253 253 253 253 253 253 253 253 253 253 253 253
40722 -253 253 253 253 253 253 253 253 253 253 253 253
40723 -253 253 253 231 231 231 198 198 198 214 170 54
40724 -236 178 12 236 178 12 210 150 10 137 92 6
40725 - 18 14 6 2 2 6 2 2 6 2 2 6
40726 - 6 6 6 70 47 6 200 144 11 236 178 12
40727 -239 182 13 239 182 13 124 112 88 58 58 58
40728 - 22 22 22 6 6 6 0 0 0 0 0 0
40729 - 0 0 0 0 0 0 0 0 0 0 0 0
40730 - 0 0 0 0 0 0 0 0 0 0 0 0
40731 - 0 0 0 0 0 0 0 0 0 0 0 0
40732 - 0 0 0 0 0 0 0 0 0 10 10 10
40733 - 30 30 30 70 70 70 180 133 36 226 170 11
40734 -239 182 13 242 186 14 242 186 14 246 186 14
40735 -246 190 14 246 190 14 246 190 14 246 190 14
40736 -246 190 14 246 190 14 246 190 14 246 190 14
40737 -246 190 14 232 195 16 98 70 6 2 2 6
40738 - 2 2 6 2 2 6 66 66 66 221 221 221
40739 -253 253 253 253 253 253 253 253 253 253 253 253
40740 -253 253 253 253 253 253 253 253 253 253 253 253
40741 -253 253 253 253 253 253 253 253 253 253 253 253
40742 -253 253 253 253 253 253 253 253 253 253 253 253
40743 -253 253 253 206 206 206 198 198 198 214 166 58
40744 -230 174 11 230 174 11 216 158 10 192 133 9
40745 -163 110 8 116 81 8 102 78 10 116 81 8
40746 -167 114 7 197 138 11 226 170 11 239 182 13
40747 -242 186 14 242 186 14 162 146 94 78 78 78
40748 - 34 34 34 14 14 14 6 6 6 0 0 0
40749 - 0 0 0 0 0 0 0 0 0 0 0 0
40750 - 0 0 0 0 0 0 0 0 0 0 0 0
40751 - 0 0 0 0 0 0 0 0 0 0 0 0
40752 - 0 0 0 0 0 0 0 0 0 6 6 6
40753 - 30 30 30 78 78 78 190 142 34 226 170 11
40754 -239 182 13 246 190 14 246 190 14 246 190 14
40755 -246 190 14 246 190 14 246 190 14 246 190 14
40756 -246 190 14 246 190 14 246 190 14 246 190 14
40757 -246 190 14 241 196 14 203 166 17 22 18 6
40758 - 2 2 6 2 2 6 2 2 6 38 38 38
40759 -218 218 218 253 253 253 253 253 253 253 253 253
40760 -253 253 253 253 253 253 253 253 253 253 253 253
40761 -253 253 253 253 253 253 253 253 253 253 253 253
40762 -253 253 253 253 253 253 253 253 253 253 253 253
40763 -250 250 250 206 206 206 198 198 198 202 162 69
40764 -226 170 11 236 178 12 224 166 10 210 150 10
40765 -200 144 11 197 138 11 192 133 9 197 138 11
40766 -210 150 10 226 170 11 242 186 14 246 190 14
40767 -246 190 14 246 186 14 225 175 15 124 112 88
40768 - 62 62 62 30 30 30 14 14 14 6 6 6
40769 - 0 0 0 0 0 0 0 0 0 0 0 0
40770 - 0 0 0 0 0 0 0 0 0 0 0 0
40771 - 0 0 0 0 0 0 0 0 0 0 0 0
40772 - 0 0 0 0 0 0 0 0 0 10 10 10
40773 - 30 30 30 78 78 78 174 135 50 224 166 10
40774 -239 182 13 246 190 14 246 190 14 246 190 14
40775 -246 190 14 246 190 14 246 190 14 246 190 14
40776 -246 190 14 246 190 14 246 190 14 246 190 14
40777 -246 190 14 246 190 14 241 196 14 139 102 15
40778 - 2 2 6 2 2 6 2 2 6 2 2 6
40779 - 78 78 78 250 250 250 253 253 253 253 253 253
40780 -253 253 253 253 253 253 253 253 253 253 253 253
40781 -253 253 253 253 253 253 253 253 253 253 253 253
40782 -253 253 253 253 253 253 253 253 253 253 253 253
40783 -250 250 250 214 214 214 198 198 198 190 150 46
40784 -219 162 10 236 178 12 234 174 13 224 166 10
40785 -216 158 10 213 154 11 213 154 11 216 158 10
40786 -226 170 11 239 182 13 246 190 14 246 190 14
40787 -246 190 14 246 190 14 242 186 14 206 162 42
40788 -101 101 101 58 58 58 30 30 30 14 14 14
40789 - 6 6 6 0 0 0 0 0 0 0 0 0
40790 - 0 0 0 0 0 0 0 0 0 0 0 0
40791 - 0 0 0 0 0 0 0 0 0 0 0 0
40792 - 0 0 0 0 0 0 0 0 0 10 10 10
40793 - 30 30 30 74 74 74 174 135 50 216 158 10
40794 -236 178 12 246 190 14 246 190 14 246 190 14
40795 -246 190 14 246 190 14 246 190 14 246 190 14
40796 -246 190 14 246 190 14 246 190 14 246 190 14
40797 -246 190 14 246 190 14 241 196 14 226 184 13
40798 - 61 42 6 2 2 6 2 2 6 2 2 6
40799 - 22 22 22 238 238 238 253 253 253 253 253 253
40800 -253 253 253 253 253 253 253 253 253 253 253 253
40801 -253 253 253 253 253 253 253 253 253 253 253 253
40802 -253 253 253 253 253 253 253 253 253 253 253 253
40803 -253 253 253 226 226 226 187 187 187 180 133 36
40804 -216 158 10 236 178 12 239 182 13 236 178 12
40805 -230 174 11 226 170 11 226 170 11 230 174 11
40806 -236 178 12 242 186 14 246 190 14 246 190 14
40807 -246 190 14 246 190 14 246 186 14 239 182 13
40808 -206 162 42 106 106 106 66 66 66 34 34 34
40809 - 14 14 14 6 6 6 0 0 0 0 0 0
40810 - 0 0 0 0 0 0 0 0 0 0 0 0
40811 - 0 0 0 0 0 0 0 0 0 0 0 0
40812 - 0 0 0 0 0 0 0 0 0 6 6 6
40813 - 26 26 26 70 70 70 163 133 67 213 154 11
40814 -236 178 12 246 190 14 246 190 14 246 190 14
40815 -246 190 14 246 190 14 246 190 14 246 190 14
40816 -246 190 14 246 190 14 246 190 14 246 190 14
40817 -246 190 14 246 190 14 246 190 14 241 196 14
40818 -190 146 13 18 14 6 2 2 6 2 2 6
40819 - 46 46 46 246 246 246 253 253 253 253 253 253
40820 -253 253 253 253 253 253 253 253 253 253 253 253
40821 -253 253 253 253 253 253 253 253 253 253 253 253
40822 -253 253 253 253 253 253 253 253 253 253 253 253
40823 -253 253 253 221 221 221 86 86 86 156 107 11
40824 -216 158 10 236 178 12 242 186 14 246 186 14
40825 -242 186 14 239 182 13 239 182 13 242 186 14
40826 -242 186 14 246 186 14 246 190 14 246 190 14
40827 -246 190 14 246 190 14 246 190 14 246 190 14
40828 -242 186 14 225 175 15 142 122 72 66 66 66
40829 - 30 30 30 10 10 10 0 0 0 0 0 0
40830 - 0 0 0 0 0 0 0 0 0 0 0 0
40831 - 0 0 0 0 0 0 0 0 0 0 0 0
40832 - 0 0 0 0 0 0 0 0 0 6 6 6
40833 - 26 26 26 70 70 70 163 133 67 210 150 10
40834 -236 178 12 246 190 14 246 190 14 246 190 14
40835 -246 190 14 246 190 14 246 190 14 246 190 14
40836 -246 190 14 246 190 14 246 190 14 246 190 14
40837 -246 190 14 246 190 14 246 190 14 246 190 14
40838 -232 195 16 121 92 8 34 34 34 106 106 106
40839 -221 221 221 253 253 253 253 253 253 253 253 253
40840 -253 253 253 253 253 253 253 253 253 253 253 253
40841 -253 253 253 253 253 253 253 253 253 253 253 253
40842 -253 253 253 253 253 253 253 253 253 253 253 253
40843 -242 242 242 82 82 82 18 14 6 163 110 8
40844 -216 158 10 236 178 12 242 186 14 246 190 14
40845 -246 190 14 246 190 14 246 190 14 246 190 14
40846 -246 190 14 246 190 14 246 190 14 246 190 14
40847 -246 190 14 246 190 14 246 190 14 246 190 14
40848 -246 190 14 246 190 14 242 186 14 163 133 67
40849 - 46 46 46 18 18 18 6 6 6 0 0 0
40850 - 0 0 0 0 0 0 0 0 0 0 0 0
40851 - 0 0 0 0 0 0 0 0 0 0 0 0
40852 - 0 0 0 0 0 0 0 0 0 10 10 10
40853 - 30 30 30 78 78 78 163 133 67 210 150 10
40854 -236 178 12 246 186 14 246 190 14 246 190 14
40855 -246 190 14 246 190 14 246 190 14 246 190 14
40856 -246 190 14 246 190 14 246 190 14 246 190 14
40857 -246 190 14 246 190 14 246 190 14 246 190 14
40858 -241 196 14 215 174 15 190 178 144 253 253 253
40859 -253 253 253 253 253 253 253 253 253 253 253 253
40860 -253 253 253 253 253 253 253 253 253 253 253 253
40861 -253 253 253 253 253 253 253 253 253 253 253 253
40862 -253 253 253 253 253 253 253 253 253 218 218 218
40863 - 58 58 58 2 2 6 22 18 6 167 114 7
40864 -216 158 10 236 178 12 246 186 14 246 190 14
40865 -246 190 14 246 190 14 246 190 14 246 190 14
40866 -246 190 14 246 190 14 246 190 14 246 190 14
40867 -246 190 14 246 190 14 246 190 14 246 190 14
40868 -246 190 14 246 186 14 242 186 14 190 150 46
40869 - 54 54 54 22 22 22 6 6 6 0 0 0
40870 - 0 0 0 0 0 0 0 0 0 0 0 0
40871 - 0 0 0 0 0 0 0 0 0 0 0 0
40872 - 0 0 0 0 0 0 0 0 0 14 14 14
40873 - 38 38 38 86 86 86 180 133 36 213 154 11
40874 -236 178 12 246 186 14 246 190 14 246 190 14
40875 -246 190 14 246 190 14 246 190 14 246 190 14
40876 -246 190 14 246 190 14 246 190 14 246 190 14
40877 -246 190 14 246 190 14 246 190 14 246 190 14
40878 -246 190 14 232 195 16 190 146 13 214 214 214
40879 -253 253 253 253 253 253 253 253 253 253 253 253
40880 -253 253 253 253 253 253 253 253 253 253 253 253
40881 -253 253 253 253 253 253 253 253 253 253 253 253
40882 -253 253 253 250 250 250 170 170 170 26 26 26
40883 - 2 2 6 2 2 6 37 26 9 163 110 8
40884 -219 162 10 239 182 13 246 186 14 246 190 14
40885 -246 190 14 246 190 14 246 190 14 246 190 14
40886 -246 190 14 246 190 14 246 190 14 246 190 14
40887 -246 190 14 246 190 14 246 190 14 246 190 14
40888 -246 186 14 236 178 12 224 166 10 142 122 72
40889 - 46 46 46 18 18 18 6 6 6 0 0 0
40890 - 0 0 0 0 0 0 0 0 0 0 0 0
40891 - 0 0 0 0 0 0 0 0 0 0 0 0
40892 - 0 0 0 0 0 0 6 6 6 18 18 18
40893 - 50 50 50 109 106 95 192 133 9 224 166 10
40894 -242 186 14 246 190 14 246 190 14 246 190 14
40895 -246 190 14 246 190 14 246 190 14 246 190 14
40896 -246 190 14 246 190 14 246 190 14 246 190 14
40897 -246 190 14 246 190 14 246 190 14 246 190 14
40898 -242 186 14 226 184 13 210 162 10 142 110 46
40899 -226 226 226 253 253 253 253 253 253 253 253 253
40900 -253 253 253 253 253 253 253 253 253 253 253 253
40901 -253 253 253 253 253 253 253 253 253 253 253 253
40902 -198 198 198 66 66 66 2 2 6 2 2 6
40903 - 2 2 6 2 2 6 50 34 6 156 107 11
40904 -219 162 10 239 182 13 246 186 14 246 190 14
40905 -246 190 14 246 190 14 246 190 14 246 190 14
40906 -246 190 14 246 190 14 246 190 14 246 190 14
40907 -246 190 14 246 190 14 246 190 14 242 186 14
40908 -234 174 13 213 154 11 154 122 46 66 66 66
40909 - 30 30 30 10 10 10 0 0 0 0 0 0
40910 - 0 0 0 0 0 0 0 0 0 0 0 0
40911 - 0 0 0 0 0 0 0 0 0 0 0 0
40912 - 0 0 0 0 0 0 6 6 6 22 22 22
40913 - 58 58 58 154 121 60 206 145 10 234 174 13
40914 -242 186 14 246 186 14 246 190 14 246 190 14
40915 -246 190 14 246 190 14 246 190 14 246 190 14
40916 -246 190 14 246 190 14 246 190 14 246 190 14
40917 -246 190 14 246 190 14 246 190 14 246 190 14
40918 -246 186 14 236 178 12 210 162 10 163 110 8
40919 - 61 42 6 138 138 138 218 218 218 250 250 250
40920 -253 253 253 253 253 253 253 253 253 250 250 250
40921 -242 242 242 210 210 210 144 144 144 66 66 66
40922 - 6 6 6 2 2 6 2 2 6 2 2 6
40923 - 2 2 6 2 2 6 61 42 6 163 110 8
40924 -216 158 10 236 178 12 246 190 14 246 190 14
40925 -246 190 14 246 190 14 246 190 14 246 190 14
40926 -246 190 14 246 190 14 246 190 14 246 190 14
40927 -246 190 14 239 182 13 230 174 11 216 158 10
40928 -190 142 34 124 112 88 70 70 70 38 38 38
40929 - 18 18 18 6 6 6 0 0 0 0 0 0
40930 - 0 0 0 0 0 0 0 0 0 0 0 0
40931 - 0 0 0 0 0 0 0 0 0 0 0 0
40932 - 0 0 0 0 0 0 6 6 6 22 22 22
40933 - 62 62 62 168 124 44 206 145 10 224 166 10
40934 -236 178 12 239 182 13 242 186 14 242 186 14
40935 -246 186 14 246 190 14 246 190 14 246 190 14
40936 -246 190 14 246 190 14 246 190 14 246 190 14
40937 -246 190 14 246 190 14 246 190 14 246 190 14
40938 -246 190 14 236 178 12 216 158 10 175 118 6
40939 - 80 54 7 2 2 6 6 6 6 30 30 30
40940 - 54 54 54 62 62 62 50 50 50 38 38 38
40941 - 14 14 14 2 2 6 2 2 6 2 2 6
40942 - 2 2 6 2 2 6 2 2 6 2 2 6
40943 - 2 2 6 6 6 6 80 54 7 167 114 7
40944 -213 154 11 236 178 12 246 190 14 246 190 14
40945 -246 190 14 246 190 14 246 190 14 246 190 14
40946 -246 190 14 242 186 14 239 182 13 239 182 13
40947 -230 174 11 210 150 10 174 135 50 124 112 88
40948 - 82 82 82 54 54 54 34 34 34 18 18 18
40949 - 6 6 6 0 0 0 0 0 0 0 0 0
40950 - 0 0 0 0 0 0 0 0 0 0 0 0
40951 - 0 0 0 0 0 0 0 0 0 0 0 0
40952 - 0 0 0 0 0 0 6 6 6 18 18 18
40953 - 50 50 50 158 118 36 192 133 9 200 144 11
40954 -216 158 10 219 162 10 224 166 10 226 170 11
40955 -230 174 11 236 178 12 239 182 13 239 182 13
40956 -242 186 14 246 186 14 246 190 14 246 190 14
40957 -246 190 14 246 190 14 246 190 14 246 190 14
40958 -246 186 14 230 174 11 210 150 10 163 110 8
40959 -104 69 6 10 10 10 2 2 6 2 2 6
40960 - 2 2 6 2 2 6 2 2 6 2 2 6
40961 - 2 2 6 2 2 6 2 2 6 2 2 6
40962 - 2 2 6 2 2 6 2 2 6 2 2 6
40963 - 2 2 6 6 6 6 91 60 6 167 114 7
40964 -206 145 10 230 174 11 242 186 14 246 190 14
40965 -246 190 14 246 190 14 246 186 14 242 186 14
40966 -239 182 13 230 174 11 224 166 10 213 154 11
40967 -180 133 36 124 112 88 86 86 86 58 58 58
40968 - 38 38 38 22 22 22 10 10 10 6 6 6
40969 - 0 0 0 0 0 0 0 0 0 0 0 0
40970 - 0 0 0 0 0 0 0 0 0 0 0 0
40971 - 0 0 0 0 0 0 0 0 0 0 0 0
40972 - 0 0 0 0 0 0 0 0 0 14 14 14
40973 - 34 34 34 70 70 70 138 110 50 158 118 36
40974 -167 114 7 180 123 7 192 133 9 197 138 11
40975 -200 144 11 206 145 10 213 154 11 219 162 10
40976 -224 166 10 230 174 11 239 182 13 242 186 14
40977 -246 186 14 246 186 14 246 186 14 246 186 14
40978 -239 182 13 216 158 10 185 133 11 152 99 6
40979 -104 69 6 18 14 6 2 2 6 2 2 6
40980 - 2 2 6 2 2 6 2 2 6 2 2 6
40981 - 2 2 6 2 2 6 2 2 6 2 2 6
40982 - 2 2 6 2 2 6 2 2 6 2 2 6
40983 - 2 2 6 6 6 6 80 54 7 152 99 6
40984 -192 133 9 219 162 10 236 178 12 239 182 13
40985 -246 186 14 242 186 14 239 182 13 236 178 12
40986 -224 166 10 206 145 10 192 133 9 154 121 60
40987 - 94 94 94 62 62 62 42 42 42 22 22 22
40988 - 14 14 14 6 6 6 0 0 0 0 0 0
40989 - 0 0 0 0 0 0 0 0 0 0 0 0
40990 - 0 0 0 0 0 0 0 0 0 0 0 0
40991 - 0 0 0 0 0 0 0 0 0 0 0 0
40992 - 0 0 0 0 0 0 0 0 0 6 6 6
40993 - 18 18 18 34 34 34 58 58 58 78 78 78
40994 -101 98 89 124 112 88 142 110 46 156 107 11
40995 -163 110 8 167 114 7 175 118 6 180 123 7
40996 -185 133 11 197 138 11 210 150 10 219 162 10
40997 -226 170 11 236 178 12 236 178 12 234 174 13
40998 -219 162 10 197 138 11 163 110 8 130 83 6
40999 - 91 60 6 10 10 10 2 2 6 2 2 6
41000 - 18 18 18 38 38 38 38 38 38 38 38 38
41001 - 38 38 38 38 38 38 38 38 38 38 38 38
41002 - 38 38 38 38 38 38 26 26 26 2 2 6
41003 - 2 2 6 6 6 6 70 47 6 137 92 6
41004 -175 118 6 200 144 11 219 162 10 230 174 11
41005 -234 174 13 230 174 11 219 162 10 210 150 10
41006 -192 133 9 163 110 8 124 112 88 82 82 82
41007 - 50 50 50 30 30 30 14 14 14 6 6 6
41008 - 0 0 0 0 0 0 0 0 0 0 0 0
41009 - 0 0 0 0 0 0 0 0 0 0 0 0
41010 - 0 0 0 0 0 0 0 0 0 0 0 0
41011 - 0 0 0 0 0 0 0 0 0 0 0 0
41012 - 0 0 0 0 0 0 0 0 0 0 0 0
41013 - 6 6 6 14 14 14 22 22 22 34 34 34
41014 - 42 42 42 58 58 58 74 74 74 86 86 86
41015 -101 98 89 122 102 70 130 98 46 121 87 25
41016 -137 92 6 152 99 6 163 110 8 180 123 7
41017 -185 133 11 197 138 11 206 145 10 200 144 11
41018 -180 123 7 156 107 11 130 83 6 104 69 6
41019 - 50 34 6 54 54 54 110 110 110 101 98 89
41020 - 86 86 86 82 82 82 78 78 78 78 78 78
41021 - 78 78 78 78 78 78 78 78 78 78 78 78
41022 - 78 78 78 82 82 82 86 86 86 94 94 94
41023 -106 106 106 101 101 101 86 66 34 124 80 6
41024 -156 107 11 180 123 7 192 133 9 200 144 11
41025 -206 145 10 200 144 11 192 133 9 175 118 6
41026 -139 102 15 109 106 95 70 70 70 42 42 42
41027 - 22 22 22 10 10 10 0 0 0 0 0 0
41028 - 0 0 0 0 0 0 0 0 0 0 0 0
41029 - 0 0 0 0 0 0 0 0 0 0 0 0
41030 - 0 0 0 0 0 0 0 0 0 0 0 0
41031 - 0 0 0 0 0 0 0 0 0 0 0 0
41032 - 0 0 0 0 0 0 0 0 0 0 0 0
41033 - 0 0 0 0 0 0 6 6 6 10 10 10
41034 - 14 14 14 22 22 22 30 30 30 38 38 38
41035 - 50 50 50 62 62 62 74 74 74 90 90 90
41036 -101 98 89 112 100 78 121 87 25 124 80 6
41037 -137 92 6 152 99 6 152 99 6 152 99 6
41038 -138 86 6 124 80 6 98 70 6 86 66 30
41039 -101 98 89 82 82 82 58 58 58 46 46 46
41040 - 38 38 38 34 34 34 34 34 34 34 34 34
41041 - 34 34 34 34 34 34 34 34 34 34 34 34
41042 - 34 34 34 34 34 34 38 38 38 42 42 42
41043 - 54 54 54 82 82 82 94 86 76 91 60 6
41044 -134 86 6 156 107 11 167 114 7 175 118 6
41045 -175 118 6 167 114 7 152 99 6 121 87 25
41046 -101 98 89 62 62 62 34 34 34 18 18 18
41047 - 6 6 6 0 0 0 0 0 0 0 0 0
41048 - 0 0 0 0 0 0 0 0 0 0 0 0
41049 - 0 0 0 0 0 0 0 0 0 0 0 0
41050 - 0 0 0 0 0 0 0 0 0 0 0 0
41051 - 0 0 0 0 0 0 0 0 0 0 0 0
41052 - 0 0 0 0 0 0 0 0 0 0 0 0
41053 - 0 0 0 0 0 0 0 0 0 0 0 0
41054 - 0 0 0 6 6 6 6 6 6 10 10 10
41055 - 18 18 18 22 22 22 30 30 30 42 42 42
41056 - 50 50 50 66 66 66 86 86 86 101 98 89
41057 -106 86 58 98 70 6 104 69 6 104 69 6
41058 -104 69 6 91 60 6 82 62 34 90 90 90
41059 - 62 62 62 38 38 38 22 22 22 14 14 14
41060 - 10 10 10 10 10 10 10 10 10 10 10 10
41061 - 10 10 10 10 10 10 6 6 6 10 10 10
41062 - 10 10 10 10 10 10 10 10 10 14 14 14
41063 - 22 22 22 42 42 42 70 70 70 89 81 66
41064 - 80 54 7 104 69 6 124 80 6 137 92 6
41065 -134 86 6 116 81 8 100 82 52 86 86 86
41066 - 58 58 58 30 30 30 14 14 14 6 6 6
41067 - 0 0 0 0 0 0 0 0 0 0 0 0
41068 - 0 0 0 0 0 0 0 0 0 0 0 0
41069 - 0 0 0 0 0 0 0 0 0 0 0 0
41070 - 0 0 0 0 0 0 0 0 0 0 0 0
41071 - 0 0 0 0 0 0 0 0 0 0 0 0
41072 - 0 0 0 0 0 0 0 0 0 0 0 0
41073 - 0 0 0 0 0 0 0 0 0 0 0 0
41074 - 0 0 0 0 0 0 0 0 0 0 0 0
41075 - 0 0 0 6 6 6 10 10 10 14 14 14
41076 - 18 18 18 26 26 26 38 38 38 54 54 54
41077 - 70 70 70 86 86 86 94 86 76 89 81 66
41078 - 89 81 66 86 86 86 74 74 74 50 50 50
41079 - 30 30 30 14 14 14 6 6 6 0 0 0
41080 - 0 0 0 0 0 0 0 0 0 0 0 0
41081 - 0 0 0 0 0 0 0 0 0 0 0 0
41082 - 0 0 0 0 0 0 0 0 0 0 0 0
41083 - 6 6 6 18 18 18 34 34 34 58 58 58
41084 - 82 82 82 89 81 66 89 81 66 89 81 66
41085 - 94 86 66 94 86 76 74 74 74 50 50 50
41086 - 26 26 26 14 14 14 6 6 6 0 0 0
41087 - 0 0 0 0 0 0 0 0 0 0 0 0
41088 - 0 0 0 0 0 0 0 0 0 0 0 0
41089 - 0 0 0 0 0 0 0 0 0 0 0 0
41090 - 0 0 0 0 0 0 0 0 0 0 0 0
41091 - 0 0 0 0 0 0 0 0 0 0 0 0
41092 - 0 0 0 0 0 0 0 0 0 0 0 0
41093 - 0 0 0 0 0 0 0 0 0 0 0 0
41094 - 0 0 0 0 0 0 0 0 0 0 0 0
41095 - 0 0 0 0 0 0 0 0 0 0 0 0
41096 - 6 6 6 6 6 6 14 14 14 18 18 18
41097 - 30 30 30 38 38 38 46 46 46 54 54 54
41098 - 50 50 50 42 42 42 30 30 30 18 18 18
41099 - 10 10 10 0 0 0 0 0 0 0 0 0
41100 - 0 0 0 0 0 0 0 0 0 0 0 0
41101 - 0 0 0 0 0 0 0 0 0 0 0 0
41102 - 0 0 0 0 0 0 0 0 0 0 0 0
41103 - 0 0 0 6 6 6 14 14 14 26 26 26
41104 - 38 38 38 50 50 50 58 58 58 58 58 58
41105 - 54 54 54 42 42 42 30 30 30 18 18 18
41106 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41111 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
41117 - 6 6 6 10 10 10 14 14 14 18 18 18
41118 - 18 18 18 14 14 14 10 10 10 6 6 6
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 6 6 6
41124 - 14 14 14 18 18 18 22 22 22 22 22 22
41125 - 18 18 18 14 14 14 10 10 10 6 6 6
41126 - 0 0 0 0 0 0 0 0 0 0 0 0
41127 - 0 0 0 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 0 0 0
41129 - 0 0 0 0 0 0 0 0 0 0 0 0
41130 - 0 0 0 0 0 0 0 0 0 0 0 0
41131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144 +4 4 4 4 4 4
41145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4
41159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4
41173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4
41187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4
41201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4
41215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41220 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41225 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4
41229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41234 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41235 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41239 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41240 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41241 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41248 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41249 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41253 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41254 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41255 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41261 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41262 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41263 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41266 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41267 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41268 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41269 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41270 +4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41275 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41276 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41277 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41278 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41280 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41281 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41282 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41283 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41288 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41289 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41290 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41291 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41292 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41293 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41294 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41295 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41296 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41297 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41298 +4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41302 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41303 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41304 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41305 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41306 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41307 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41308 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41309 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41310 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41311 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41316 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41317 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41318 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41319 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41320 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41321 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41322 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41323 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41324 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41325 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41330 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41331 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41332 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41333 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41334 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41335 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41336 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41337 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41338 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41339 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41344 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41345 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41346 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41347 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41348 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41349 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41350 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41351 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41352 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41353 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41354 +4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41357 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41358 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41359 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41360 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41361 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41362 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41363 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41364 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41365 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41366 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41367 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41368 +4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41371 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41372 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41373 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41374 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41375 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41376 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41377 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41378 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41379 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41380 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41381 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41382 +0 0 0 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41384 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41385 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41386 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41387 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41388 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41389 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41390 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41391 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41392 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41393 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41394 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41395 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41396 +2 0 0 0 0 0
41397 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41398 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41399 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41400 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41401 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41402 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41403 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41404 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41405 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41406 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41407 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41408 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41409 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41410 +37 38 37 0 0 0
41411 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41412 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41413 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41414 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41415 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41416 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41417 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41418 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41419 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41420 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41421 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41422 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41423 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41424 +85 115 134 4 0 0
41425 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41426 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41427 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41428 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41429 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41430 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41431 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41432 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41433 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41434 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41435 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41436 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41437 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41438 +60 73 81 4 0 0
41439 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41440 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41441 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41442 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41443 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41444 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41445 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41446 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41447 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41448 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41449 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41450 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41451 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41452 +16 19 21 4 0 0
41453 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41454 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41455 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41456 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41457 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41458 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41459 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41460 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41461 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41462 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41463 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41464 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41465 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41466 +4 0 0 4 3 3
41467 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41468 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41469 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41471 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41472 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41473 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41474 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41475 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41476 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41477 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41478 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41479 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41480 +3 2 2 4 4 4
41481 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41482 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41483 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41484 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41485 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41486 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41487 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41488 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41489 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41490 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41491 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41492 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41493 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41494 +4 4 4 4 4 4
41495 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41496 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41497 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41498 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41499 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41500 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41501 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41502 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41503 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41504 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41505 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41506 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41507 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41508 +4 4 4 4 4 4
41509 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41510 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41511 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41512 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41513 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41514 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41515 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41516 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41517 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41518 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41519 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41520 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41521 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41522 +5 5 5 5 5 5
41523 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41524 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41525 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41526 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41527 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41528 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41529 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41530 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41531 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41532 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41533 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41534 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41535 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41536 +5 5 5 4 4 4
41537 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41538 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41539 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41540 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41541 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41542 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41543 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41544 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41545 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41546 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41547 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41548 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550 +4 4 4 4 4 4
41551 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41552 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41553 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41554 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41555 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41556 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41557 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41558 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41559 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41560 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41561 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41562 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564 +4 4 4 4 4 4
41565 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41566 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41567 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41568 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41569 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41570 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41571 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41572 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41573 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41574 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41575 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4
41579 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41580 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41581 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41582 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41583 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41584 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41585 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41586 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41587 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41588 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41589 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4
41593 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41594 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41595 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41596 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41597 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41598 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41599 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41600 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41601 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41602 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41603 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4
41607 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41608 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41609 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41610 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41611 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41612 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41613 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41614 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41615 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41616 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41617 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4
41621 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41622 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41623 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41624 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41625 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41626 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41627 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41628 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41629 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41630 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41631 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4
41635 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41636 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41637 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41638 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41639 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41640 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41641 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41642 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41643 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41644 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41645 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4
41649 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41650 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41651 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41652 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41653 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41654 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41655 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41656 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41657 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41658 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41659 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4
41663 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41664 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41665 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41666 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41667 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41668 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41669 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41670 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41671 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41672 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41673 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4
41677 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41678 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41679 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41680 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41681 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41682 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41683 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41684 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41685 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41686 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41687 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4
41691 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41692 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41693 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41694 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41695 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41696 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41697 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41698 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41699 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41700 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41701 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4
41705 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41706 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41707 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41708 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41709 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41710 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41711 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41712 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41713 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41714 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41715 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4
41719 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41720 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41721 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41722 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41723 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41724 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41725 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41726 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41727 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41728 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41729 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4
41733 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41734 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41735 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41736 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41737 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41738 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41739 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41740 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41741 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41742 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41743 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4
41747 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41748 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41749 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41750 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41751 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41752 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41753 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41754 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41755 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41756 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41757 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4
41761 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41762 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41763 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41764 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41765 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41766 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41767 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41768 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41769 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41770 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41771 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4
41775 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41776 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41777 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41778 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41779 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41780 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41781 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41782 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41783 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41784 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41785 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4
41789 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41790 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41791 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41792 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41793 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41794 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41795 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41796 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41797 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41798 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41799 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4
41803 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41804 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41805 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41806 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41807 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41808 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41809 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41810 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41811 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41812 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41813 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4
41817 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41818 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41819 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41820 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41821 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41822 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41823 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41824 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41825 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41826 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41827 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4
41831 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41832 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41833 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41834 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41835 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41836 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41837 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41838 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41839 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41840 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41841 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4
41845 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41846 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41847 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41848 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41849 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41850 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41851 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41852 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41853 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41854 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41855 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4
41859 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41860 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41861 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41862 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41863 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41864 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41865 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41866 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41867 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41868 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41869 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4
41873 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41874 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41875 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41876 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41877 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41878 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41879 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41880 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41881 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41882 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41883 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4
41887 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41888 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41889 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41890 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41891 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41892 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41893 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41894 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41895 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41896 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41897 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4
41901 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41902 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41903 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41904 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41905 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41906 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41907 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41908 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41909 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41910 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41911 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4
41915 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41916 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41917 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41918 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41919 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41920 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41921 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41922 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41923 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41924 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41925 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4
41929 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41930 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41931 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41932 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41933 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41934 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41935 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41936 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41937 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41938 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41939 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4
41943 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41944 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41945 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41946 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41947 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41948 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41949 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41950 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41951 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41952 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4
41957 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41958 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41959 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41960 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41961 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41962 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41963 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41964 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41965 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41966 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4
41971 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41972 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41973 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41974 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41975 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41976 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41977 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41978 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41979 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41980 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4
41985 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41986 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41987 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41988 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41989 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41990 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41991 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41992 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41993 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41994 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4
41999 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42000 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42001 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42002 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42003 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42004 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42005 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42006 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42007 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4
42013 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42014 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42015 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42016 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42017 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42018 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42019 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42020 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42021 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4
42027 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42028 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42029 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42030 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42031 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42032 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42033 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42034 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42035 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4
42041 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42042 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42043 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42044 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42045 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42046 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42047 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42048 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4
42055 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42056 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42057 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42058 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42059 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42060 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42061 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42062 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4
42069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42070 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42071 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42072 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42073 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42074 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42075 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42076 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4
42083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42084 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42085 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42086 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42087 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42088 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42089 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42090 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4
42097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42098 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42099 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42100 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42101 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42102 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42103 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42104 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110 +4 4 4 4 4 4
42111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42113 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42114 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42115 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42116 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42117 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42118 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124 +4 4 4 4 4 4
42125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42128 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42129 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42130 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42131 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138 +4 4 4 4 4 4
42139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42142 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42143 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42144 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42145 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4
42153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42156 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42157 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42158 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42159 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4
42167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42170 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42171 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42172 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42173 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4
42181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42185 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42186 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42187 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4
42195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42200 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42201 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4
42209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42214 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42215 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4
42223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42228 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4
42237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42242 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4
42251 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42252 index 86d449e..af6a7f7 100644
42253 --- a/drivers/video/udlfb.c
42254 +++ b/drivers/video/udlfb.c
42255 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42256 dlfb_urb_completion(urb);
42257
42258 error:
42259 - atomic_add(bytes_sent, &dev->bytes_sent);
42260 - atomic_add(bytes_identical, &dev->bytes_identical);
42261 - atomic_add(width*height*2, &dev->bytes_rendered);
42262 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42263 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42264 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42265 end_cycles = get_cycles();
42266 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42267 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42268 >> 10)), /* Kcycles */
42269 &dev->cpu_kcycles_used);
42270
42271 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42272 dlfb_urb_completion(urb);
42273
42274 error:
42275 - atomic_add(bytes_sent, &dev->bytes_sent);
42276 - atomic_add(bytes_identical, &dev->bytes_identical);
42277 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42278 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42279 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42280 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42281 end_cycles = get_cycles();
42282 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42283 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42284 >> 10)), /* Kcycles */
42285 &dev->cpu_kcycles_used);
42286 }
42287 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42288 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42289 struct dlfb_data *dev = fb_info->par;
42290 return snprintf(buf, PAGE_SIZE, "%u\n",
42291 - atomic_read(&dev->bytes_rendered));
42292 + atomic_read_unchecked(&dev->bytes_rendered));
42293 }
42294
42295 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42296 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42297 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42298 struct dlfb_data *dev = fb_info->par;
42299 return snprintf(buf, PAGE_SIZE, "%u\n",
42300 - atomic_read(&dev->bytes_identical));
42301 + atomic_read_unchecked(&dev->bytes_identical));
42302 }
42303
42304 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42305 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42306 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42307 struct dlfb_data *dev = fb_info->par;
42308 return snprintf(buf, PAGE_SIZE, "%u\n",
42309 - atomic_read(&dev->bytes_sent));
42310 + atomic_read_unchecked(&dev->bytes_sent));
42311 }
42312
42313 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42314 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42315 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42316 struct dlfb_data *dev = fb_info->par;
42317 return snprintf(buf, PAGE_SIZE, "%u\n",
42318 - atomic_read(&dev->cpu_kcycles_used));
42319 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42320 }
42321
42322 static ssize_t edid_show(
42323 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42324 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42325 struct dlfb_data *dev = fb_info->par;
42326
42327 - atomic_set(&dev->bytes_rendered, 0);
42328 - atomic_set(&dev->bytes_identical, 0);
42329 - atomic_set(&dev->bytes_sent, 0);
42330 - atomic_set(&dev->cpu_kcycles_used, 0);
42331 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42332 + atomic_set_unchecked(&dev->bytes_identical, 0);
42333 + atomic_set_unchecked(&dev->bytes_sent, 0);
42334 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42335
42336 return count;
42337 }
42338 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42339 index 2f8f82d..191de37 100644
42340 --- a/drivers/video/uvesafb.c
42341 +++ b/drivers/video/uvesafb.c
42342 @@ -19,6 +19,7 @@
42343 #include <linux/io.h>
42344 #include <linux/mutex.h>
42345 #include <linux/slab.h>
42346 +#include <linux/moduleloader.h>
42347 #include <video/edid.h>
42348 #include <video/uvesafb.h>
42349 #ifdef CONFIG_X86
42350 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42351 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42352 par->pmi_setpal = par->ypan = 0;
42353 } else {
42354 +
42355 +#ifdef CONFIG_PAX_KERNEXEC
42356 +#ifdef CONFIG_MODULES
42357 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42358 +#endif
42359 + if (!par->pmi_code) {
42360 + par->pmi_setpal = par->ypan = 0;
42361 + return 0;
42362 + }
42363 +#endif
42364 +
42365 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42366 + task->t.regs.edi);
42367 +
42368 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42369 + pax_open_kernel();
42370 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42371 + pax_close_kernel();
42372 +
42373 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42374 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42375 +#else
42376 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42377 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42378 +#endif
42379 +
42380 printk(KERN_INFO "uvesafb: protected mode interface info at "
42381 "%04x:%04x\n",
42382 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42383 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42384 par->ypan = ypan;
42385
42386 if (par->pmi_setpal || par->ypan) {
42387 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42388 if (__supported_pte_mask & _PAGE_NX) {
42389 par->pmi_setpal = par->ypan = 0;
42390 printk(KERN_WARNING "uvesafb: NX protection is actively."
42391 "We have better not to use the PMI.\n");
42392 - } else {
42393 + } else
42394 +#endif
42395 uvesafb_vbe_getpmi(task, par);
42396 - }
42397 }
42398 #else
42399 /* The protected mode interface is not available on non-x86. */
42400 @@ -1838,6 +1862,11 @@ out:
42401 if (par->vbe_modes)
42402 kfree(par->vbe_modes);
42403
42404 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42405 + if (par->pmi_code)
42406 + module_free_exec(NULL, par->pmi_code);
42407 +#endif
42408 +
42409 framebuffer_release(info);
42410 return err;
42411 }
42412 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
42413 kfree(par->vbe_state_orig);
42414 if (par->vbe_state_saved)
42415 kfree(par->vbe_state_saved);
42416 +
42417 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42418 + if (par->pmi_code)
42419 + module_free_exec(NULL, par->pmi_code);
42420 +#endif
42421 +
42422 }
42423
42424 framebuffer_release(info);
42425 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42426 index 501b340..86bd4cf 100644
42427 --- a/drivers/video/vesafb.c
42428 +++ b/drivers/video/vesafb.c
42429 @@ -9,6 +9,7 @@
42430 */
42431
42432 #include <linux/module.h>
42433 +#include <linux/moduleloader.h>
42434 #include <linux/kernel.h>
42435 #include <linux/errno.h>
42436 #include <linux/string.h>
42437 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42438 static int vram_total __initdata; /* Set total amount of memory */
42439 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42440 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42441 -static void (*pmi_start)(void) __read_mostly;
42442 -static void (*pmi_pal) (void) __read_mostly;
42443 +static void (*pmi_start)(void) __read_only;
42444 +static void (*pmi_pal) (void) __read_only;
42445 static int depth __read_mostly;
42446 static int vga_compat __read_mostly;
42447 /* --------------------------------------------------------------------- */
42448 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42449 unsigned int size_vmode;
42450 unsigned int size_remap;
42451 unsigned int size_total;
42452 + void *pmi_code = NULL;
42453
42454 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42455 return -ENODEV;
42456 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42457 size_remap = size_total;
42458 vesafb_fix.smem_len = size_remap;
42459
42460 -#ifndef __i386__
42461 - screen_info.vesapm_seg = 0;
42462 -#endif
42463 -
42464 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42465 printk(KERN_WARNING
42466 "vesafb: cannot reserve video memory at 0x%lx\n",
42467 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42468 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42469 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42470
42471 +#ifdef __i386__
42472 +
42473 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42474 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42475 + if (!pmi_code)
42476 +#elif !defined(CONFIG_PAX_KERNEXEC)
42477 + if (0)
42478 +#endif
42479 +
42480 +#endif
42481 + screen_info.vesapm_seg = 0;
42482 +
42483 if (screen_info.vesapm_seg) {
42484 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42485 - screen_info.vesapm_seg,screen_info.vesapm_off);
42486 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42487 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42488 }
42489
42490 if (screen_info.vesapm_seg < 0xc000)
42491 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42492
42493 if (ypan || pmi_setpal) {
42494 unsigned short *pmi_base;
42495 +
42496 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42497 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42498 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42499 +
42500 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42501 + pax_open_kernel();
42502 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42503 +#else
42504 + pmi_code = pmi_base;
42505 +#endif
42506 +
42507 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42508 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42509 +
42510 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42511 + pmi_start = ktva_ktla(pmi_start);
42512 + pmi_pal = ktva_ktla(pmi_pal);
42513 + pax_close_kernel();
42514 +#endif
42515 +
42516 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42517 if (pmi_base[3]) {
42518 printk(KERN_INFO "vesafb: pmi: ports = ");
42519 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42520 info->node, info->fix.id);
42521 return 0;
42522 err:
42523 +
42524 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42525 + module_free_exec(NULL, pmi_code);
42526 +#endif
42527 +
42528 if (info->screen_base)
42529 iounmap(info->screen_base);
42530 framebuffer_release(info);
42531 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42532 index 88714ae..16c2e11 100644
42533 --- a/drivers/video/via/via_clock.h
42534 +++ b/drivers/video/via/via_clock.h
42535 @@ -56,7 +56,7 @@ struct via_clock {
42536
42537 void (*set_engine_pll_state)(u8 state);
42538 void (*set_engine_pll)(struct via_pll_config config);
42539 -};
42540 +} __no_const;
42541
42542
42543 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42544 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42545 index 6b1b7e1..b2fa4d5 100644
42546 --- a/drivers/virtio/virtio_mmio.c
42547 +++ b/drivers/virtio/virtio_mmio.c
42548 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
42549
42550 resources[0].end = memparse(device, &str) - 1;
42551
42552 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42553 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42554 &base, &resources[1].start, &consumed,
42555 &vm_cmdline_id, &consumed);
42556
42557 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42558 index e56c934..fc22f4b 100644
42559 --- a/drivers/xen/xen-pciback/conf_space.h
42560 +++ b/drivers/xen/xen-pciback/conf_space.h
42561 @@ -44,15 +44,15 @@ struct config_field {
42562 struct {
42563 conf_dword_write write;
42564 conf_dword_read read;
42565 - } dw;
42566 + } __no_const dw;
42567 struct {
42568 conf_word_write write;
42569 conf_word_read read;
42570 - } w;
42571 + } __no_const w;
42572 struct {
42573 conf_byte_write write;
42574 conf_byte_read read;
42575 - } b;
42576 + } __no_const b;
42577 } u;
42578 struct list_head list;
42579 };
42580 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42581 index fef20db..d28b1ab 100644
42582 --- a/drivers/xen/xenfs/xenstored.c
42583 +++ b/drivers/xen/xenfs/xenstored.c
42584 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42585 static int xsd_kva_open(struct inode *inode, struct file *file)
42586 {
42587 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42588 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42589 + NULL);
42590 +#else
42591 xen_store_interface);
42592 +#endif
42593 +
42594 if (!file->private_data)
42595 return -ENOMEM;
42596 return 0;
42597 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42598 index 890bed5..17ae73e 100644
42599 --- a/fs/9p/vfs_inode.c
42600 +++ b/fs/9p/vfs_inode.c
42601 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42602 void
42603 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42604 {
42605 - char *s = nd_get_link(nd);
42606 + const char *s = nd_get_link(nd);
42607
42608 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42609 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42610 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42611 index 0efd152..b5802ad 100644
42612 --- a/fs/Kconfig.binfmt
42613 +++ b/fs/Kconfig.binfmt
42614 @@ -89,7 +89,7 @@ config HAVE_AOUT
42615
42616 config BINFMT_AOUT
42617 tristate "Kernel support for a.out and ECOFF binaries"
42618 - depends on HAVE_AOUT
42619 + depends on HAVE_AOUT && BROKEN
42620 ---help---
42621 A.out (Assembler.OUTput) is a set of formats for libraries and
42622 executables used in the earliest versions of UNIX. Linux used
42623 diff --git a/fs/aio.c b/fs/aio.c
42624 index 71f613c..9d01f1f 100644
42625 --- a/fs/aio.c
42626 +++ b/fs/aio.c
42627 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42628 size += sizeof(struct io_event) * nr_events;
42629 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42630
42631 - if (nr_pages < 0)
42632 + if (nr_pages <= 0)
42633 return -EINVAL;
42634
42635 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42636 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42637 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42638 {
42639 ssize_t ret;
42640 + struct iovec iovstack;
42641
42642 #ifdef CONFIG_COMPAT
42643 if (compat)
42644 ret = compat_rw_copy_check_uvector(type,
42645 (struct compat_iovec __user *)kiocb->ki_buf,
42646 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42647 + kiocb->ki_nbytes, 1, &iovstack,
42648 &kiocb->ki_iovec);
42649 else
42650 #endif
42651 ret = rw_copy_check_uvector(type,
42652 (struct iovec __user *)kiocb->ki_buf,
42653 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42654 + kiocb->ki_nbytes, 1, &iovstack,
42655 &kiocb->ki_iovec);
42656 if (ret < 0)
42657 goto out;
42658 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42659 if (ret < 0)
42660 goto out;
42661
42662 + if (kiocb->ki_iovec == &iovstack) {
42663 + kiocb->ki_inline_vec = iovstack;
42664 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42665 + }
42666 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42667 kiocb->ki_cur_seg = 0;
42668 /* ki_nbytes/left now reflect bytes instead of segs */
42669 diff --git a/fs/attr.c b/fs/attr.c
42670 index cce7df5..eaa2731 100644
42671 --- a/fs/attr.c
42672 +++ b/fs/attr.c
42673 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42674 unsigned long limit;
42675
42676 limit = rlimit(RLIMIT_FSIZE);
42677 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42678 if (limit != RLIM_INFINITY && offset > limit)
42679 goto out_sig;
42680 if (offset > inode->i_sb->s_maxbytes)
42681 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42682 index dce436e..378404b 100644
42683 --- a/fs/autofs4/waitq.c
42684 +++ b/fs/autofs4/waitq.c
42685 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42686 {
42687 unsigned long sigpipe, flags;
42688 mm_segment_t fs;
42689 - const char *data = (const char *)addr;
42690 + const char __user *data = (const char __force_user *)addr;
42691 ssize_t wr = 0;
42692
42693 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42694 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42695 return 1;
42696 }
42697
42698 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42699 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42700 +#endif
42701 +
42702 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42703 enum autofs_notify notify)
42704 {
42705 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42706
42707 /* If this is a direct mount request create a dummy name */
42708 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42709 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42710 + /* this name does get written to userland via autofs4_write() */
42711 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42712 +#else
42713 qstr.len = sprintf(name, "%p", dentry);
42714 +#endif
42715 else {
42716 qstr.len = autofs4_getpath(sbi, dentry, &name);
42717 if (!qstr.len) {
42718 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42719 index 2b3bda8..6a2d4be 100644
42720 --- a/fs/befs/linuxvfs.c
42721 +++ b/fs/befs/linuxvfs.c
42722 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42723 {
42724 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42725 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42726 - char *link = nd_get_link(nd);
42727 + const char *link = nd_get_link(nd);
42728 if (!IS_ERR(link))
42729 kfree(link);
42730 }
42731 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42732 index 0e7a6f8..332b1ca 100644
42733 --- a/fs/binfmt_aout.c
42734 +++ b/fs/binfmt_aout.c
42735 @@ -16,6 +16,7 @@
42736 #include <linux/string.h>
42737 #include <linux/fs.h>
42738 #include <linux/file.h>
42739 +#include <linux/security.h>
42740 #include <linux/stat.h>
42741 #include <linux/fcntl.h>
42742 #include <linux/ptrace.h>
42743 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42744 #endif
42745 # define START_STACK(u) ((void __user *)u.start_stack)
42746
42747 + memset(&dump, 0, sizeof(dump));
42748 +
42749 fs = get_fs();
42750 set_fs(KERNEL_DS);
42751 has_dumped = 1;
42752 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42753
42754 /* If the size of the dump file exceeds the rlimit, then see what would happen
42755 if we wrote the stack, but not the data area. */
42756 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42757 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42758 dump.u_dsize = 0;
42759
42760 /* Make sure we have enough room to write the stack and data areas. */
42761 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42762 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42763 dump.u_ssize = 0;
42764
42765 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42766 rlim = rlimit(RLIMIT_DATA);
42767 if (rlim >= RLIM_INFINITY)
42768 rlim = ~0;
42769 +
42770 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42771 if (ex.a_data + ex.a_bss > rlim)
42772 return -ENOMEM;
42773
42774 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42775
42776 install_exec_creds(bprm);
42777
42778 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42779 + current->mm->pax_flags = 0UL;
42780 +#endif
42781 +
42782 +#ifdef CONFIG_PAX_PAGEEXEC
42783 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42784 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42785 +
42786 +#ifdef CONFIG_PAX_EMUTRAMP
42787 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42788 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42789 +#endif
42790 +
42791 +#ifdef CONFIG_PAX_MPROTECT
42792 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42793 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42794 +#endif
42795 +
42796 + }
42797 +#endif
42798 +
42799 if (N_MAGIC(ex) == OMAGIC) {
42800 unsigned long text_addr, map_size;
42801 loff_t pos;
42802 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42803 }
42804
42805 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42806 - PROT_READ | PROT_WRITE | PROT_EXEC,
42807 + PROT_READ | PROT_WRITE,
42808 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42809 fd_offset + ex.a_text);
42810 if (error != N_DATADDR(ex)) {
42811 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42812 index fbd9f60..d4edac0 100644
42813 --- a/fs/binfmt_elf.c
42814 +++ b/fs/binfmt_elf.c
42815 @@ -33,6 +33,7 @@
42816 #include <linux/elf.h>
42817 #include <linux/utsname.h>
42818 #include <linux/coredump.h>
42819 +#include <linux/xattr.h>
42820 #include <asm/uaccess.h>
42821 #include <asm/param.h>
42822 #include <asm/page.h>
42823 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42824 #define elf_core_dump NULL
42825 #endif
42826
42827 +#ifdef CONFIG_PAX_MPROTECT
42828 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42829 +#endif
42830 +
42831 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42832 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42833 #else
42834 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
42835 .load_binary = load_elf_binary,
42836 .load_shlib = load_elf_library,
42837 .core_dump = elf_core_dump,
42838 +
42839 +#ifdef CONFIG_PAX_MPROTECT
42840 + .handle_mprotect= elf_handle_mprotect,
42841 +#endif
42842 +
42843 .min_coredump = ELF_EXEC_PAGESIZE,
42844 };
42845
42846 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
42847
42848 static int set_brk(unsigned long start, unsigned long end)
42849 {
42850 + unsigned long e = end;
42851 +
42852 start = ELF_PAGEALIGN(start);
42853 end = ELF_PAGEALIGN(end);
42854 if (end > start) {
42855 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
42856 if (BAD_ADDR(addr))
42857 return addr;
42858 }
42859 - current->mm->start_brk = current->mm->brk = end;
42860 + current->mm->start_brk = current->mm->brk = e;
42861 return 0;
42862 }
42863
42864 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42865 elf_addr_t __user *u_rand_bytes;
42866 const char *k_platform = ELF_PLATFORM;
42867 const char *k_base_platform = ELF_BASE_PLATFORM;
42868 - unsigned char k_rand_bytes[16];
42869 + u32 k_rand_bytes[4];
42870 int items;
42871 elf_addr_t *elf_info;
42872 int ei_index = 0;
42873 const struct cred *cred = current_cred();
42874 struct vm_area_struct *vma;
42875 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42876
42877 /*
42878 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42879 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42880 * Generate 16 random bytes for userspace PRNG seeding.
42881 */
42882 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42883 - u_rand_bytes = (elf_addr_t __user *)
42884 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42885 + srandom32(k_rand_bytes[0] ^ random32());
42886 + srandom32(k_rand_bytes[1] ^ random32());
42887 + srandom32(k_rand_bytes[2] ^ random32());
42888 + srandom32(k_rand_bytes[3] ^ random32());
42889 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42890 + u_rand_bytes = (elf_addr_t __user *) p;
42891 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42892 return -EFAULT;
42893
42894 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42895 return -EFAULT;
42896 current->mm->env_end = p;
42897
42898 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42899 +
42900 /* Put the elf_info on the stack in the right place. */
42901 sp = (elf_addr_t __user *)envp + 1;
42902 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42903 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42904 return -EFAULT;
42905 return 0;
42906 }
42907 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
42908 an ELF header */
42909
42910 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42911 - struct file *interpreter, unsigned long *interp_map_addr,
42912 - unsigned long no_base)
42913 + struct file *interpreter, unsigned long no_base)
42914 {
42915 struct elf_phdr *elf_phdata;
42916 struct elf_phdr *eppnt;
42917 - unsigned long load_addr = 0;
42918 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42919 int load_addr_set = 0;
42920 unsigned long last_bss = 0, elf_bss = 0;
42921 - unsigned long error = ~0UL;
42922 + unsigned long error = -EINVAL;
42923 unsigned long total_size;
42924 int retval, i, size;
42925
42926 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42927 goto out_close;
42928 }
42929
42930 +#ifdef CONFIG_PAX_SEGMEXEC
42931 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42932 + pax_task_size = SEGMEXEC_TASK_SIZE;
42933 +#endif
42934 +
42935 eppnt = elf_phdata;
42936 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42937 if (eppnt->p_type == PT_LOAD) {
42938 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42939 map_addr = elf_map(interpreter, load_addr + vaddr,
42940 eppnt, elf_prot, elf_type, total_size);
42941 total_size = 0;
42942 - if (!*interp_map_addr)
42943 - *interp_map_addr = map_addr;
42944 error = map_addr;
42945 if (BAD_ADDR(map_addr))
42946 goto out_close;
42947 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42948 k = load_addr + eppnt->p_vaddr;
42949 if (BAD_ADDR(k) ||
42950 eppnt->p_filesz > eppnt->p_memsz ||
42951 - eppnt->p_memsz > TASK_SIZE ||
42952 - TASK_SIZE - eppnt->p_memsz < k) {
42953 + eppnt->p_memsz > pax_task_size ||
42954 + pax_task_size - eppnt->p_memsz < k) {
42955 error = -ENOMEM;
42956 goto out_close;
42957 }
42958 @@ -530,6 +551,315 @@ out:
42959 return error;
42960 }
42961
42962 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42963 +#ifdef CONFIG_PAX_SOFTMODE
42964 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42965 +{
42966 + unsigned long pax_flags = 0UL;
42967 +
42968 +#ifdef CONFIG_PAX_PAGEEXEC
42969 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42970 + pax_flags |= MF_PAX_PAGEEXEC;
42971 +#endif
42972 +
42973 +#ifdef CONFIG_PAX_SEGMEXEC
42974 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42975 + pax_flags |= MF_PAX_SEGMEXEC;
42976 +#endif
42977 +
42978 +#ifdef CONFIG_PAX_EMUTRAMP
42979 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42980 + pax_flags |= MF_PAX_EMUTRAMP;
42981 +#endif
42982 +
42983 +#ifdef CONFIG_PAX_MPROTECT
42984 + if (elf_phdata->p_flags & PF_MPROTECT)
42985 + pax_flags |= MF_PAX_MPROTECT;
42986 +#endif
42987 +
42988 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42989 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42990 + pax_flags |= MF_PAX_RANDMMAP;
42991 +#endif
42992 +
42993 + return pax_flags;
42994 +}
42995 +#endif
42996 +
42997 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42998 +{
42999 + unsigned long pax_flags = 0UL;
43000 +
43001 +#ifdef CONFIG_PAX_PAGEEXEC
43002 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43003 + pax_flags |= MF_PAX_PAGEEXEC;
43004 +#endif
43005 +
43006 +#ifdef CONFIG_PAX_SEGMEXEC
43007 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43008 + pax_flags |= MF_PAX_SEGMEXEC;
43009 +#endif
43010 +
43011 +#ifdef CONFIG_PAX_EMUTRAMP
43012 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43013 + pax_flags |= MF_PAX_EMUTRAMP;
43014 +#endif
43015 +
43016 +#ifdef CONFIG_PAX_MPROTECT
43017 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43018 + pax_flags |= MF_PAX_MPROTECT;
43019 +#endif
43020 +
43021 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43022 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43023 + pax_flags |= MF_PAX_RANDMMAP;
43024 +#endif
43025 +
43026 + return pax_flags;
43027 +}
43028 +#endif
43029 +
43030 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43031 +#ifdef CONFIG_PAX_SOFTMODE
43032 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43033 +{
43034 + unsigned long pax_flags = 0UL;
43035 +
43036 +#ifdef CONFIG_PAX_PAGEEXEC
43037 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43038 + pax_flags |= MF_PAX_PAGEEXEC;
43039 +#endif
43040 +
43041 +#ifdef CONFIG_PAX_SEGMEXEC
43042 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43043 + pax_flags |= MF_PAX_SEGMEXEC;
43044 +#endif
43045 +
43046 +#ifdef CONFIG_PAX_EMUTRAMP
43047 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43048 + pax_flags |= MF_PAX_EMUTRAMP;
43049 +#endif
43050 +
43051 +#ifdef CONFIG_PAX_MPROTECT
43052 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43053 + pax_flags |= MF_PAX_MPROTECT;
43054 +#endif
43055 +
43056 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43057 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43058 + pax_flags |= MF_PAX_RANDMMAP;
43059 +#endif
43060 +
43061 + return pax_flags;
43062 +}
43063 +#endif
43064 +
43065 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43066 +{
43067 + unsigned long pax_flags = 0UL;
43068 +
43069 +#ifdef CONFIG_PAX_PAGEEXEC
43070 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43071 + pax_flags |= MF_PAX_PAGEEXEC;
43072 +#endif
43073 +
43074 +#ifdef CONFIG_PAX_SEGMEXEC
43075 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43076 + pax_flags |= MF_PAX_SEGMEXEC;
43077 +#endif
43078 +
43079 +#ifdef CONFIG_PAX_EMUTRAMP
43080 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43081 + pax_flags |= MF_PAX_EMUTRAMP;
43082 +#endif
43083 +
43084 +#ifdef CONFIG_PAX_MPROTECT
43085 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43086 + pax_flags |= MF_PAX_MPROTECT;
43087 +#endif
43088 +
43089 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43090 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43091 + pax_flags |= MF_PAX_RANDMMAP;
43092 +#endif
43093 +
43094 + return pax_flags;
43095 +}
43096 +#endif
43097 +
43098 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43099 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43100 +{
43101 + unsigned long pax_flags = 0UL;
43102 +
43103 +#ifdef CONFIG_PAX_EI_PAX
43104 +
43105 +#ifdef CONFIG_PAX_PAGEEXEC
43106 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43107 + pax_flags |= MF_PAX_PAGEEXEC;
43108 +#endif
43109 +
43110 +#ifdef CONFIG_PAX_SEGMEXEC
43111 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43112 + pax_flags |= MF_PAX_SEGMEXEC;
43113 +#endif
43114 +
43115 +#ifdef CONFIG_PAX_EMUTRAMP
43116 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43117 + pax_flags |= MF_PAX_EMUTRAMP;
43118 +#endif
43119 +
43120 +#ifdef CONFIG_PAX_MPROTECT
43121 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43122 + pax_flags |= MF_PAX_MPROTECT;
43123 +#endif
43124 +
43125 +#ifdef CONFIG_PAX_ASLR
43126 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43127 + pax_flags |= MF_PAX_RANDMMAP;
43128 +#endif
43129 +
43130 +#else
43131 +
43132 +#ifdef CONFIG_PAX_PAGEEXEC
43133 + pax_flags |= MF_PAX_PAGEEXEC;
43134 +#endif
43135 +
43136 +#ifdef CONFIG_PAX_SEGMEXEC
43137 + pax_flags |= MF_PAX_SEGMEXEC;
43138 +#endif
43139 +
43140 +#ifdef CONFIG_PAX_MPROTECT
43141 + pax_flags |= MF_PAX_MPROTECT;
43142 +#endif
43143 +
43144 +#ifdef CONFIG_PAX_RANDMMAP
43145 + if (randomize_va_space)
43146 + pax_flags |= MF_PAX_RANDMMAP;
43147 +#endif
43148 +
43149 +#endif
43150 +
43151 + return pax_flags;
43152 +}
43153 +
43154 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43155 +{
43156 +
43157 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43158 + unsigned long i;
43159 +
43160 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43161 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43162 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43163 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43164 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43165 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43166 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43167 + return ~0UL;
43168 +
43169 +#ifdef CONFIG_PAX_SOFTMODE
43170 + if (pax_softmode)
43171 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43172 + else
43173 +#endif
43174 +
43175 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43176 + break;
43177 + }
43178 +#endif
43179 +
43180 + return ~0UL;
43181 +}
43182 +
43183 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43184 +{
43185 +
43186 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43187 + ssize_t xattr_size, i;
43188 + unsigned char xattr_value[5];
43189 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43190 +
43191 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43192 + if (xattr_size <= 0 || xattr_size > 5)
43193 + return ~0UL;
43194 +
43195 + for (i = 0; i < xattr_size; i++)
43196 + switch (xattr_value[i]) {
43197 + default:
43198 + return ~0UL;
43199 +
43200 +#define parse_flag(option1, option2, flag) \
43201 + case option1: \
43202 + if (pax_flags_hardmode & MF_PAX_##flag) \
43203 + return ~0UL; \
43204 + pax_flags_hardmode |= MF_PAX_##flag; \
43205 + break; \
43206 + case option2: \
43207 + if (pax_flags_softmode & MF_PAX_##flag) \
43208 + return ~0UL; \
43209 + pax_flags_softmode |= MF_PAX_##flag; \
43210 + break;
43211 +
43212 + parse_flag('p', 'P', PAGEEXEC);
43213 + parse_flag('e', 'E', EMUTRAMP);
43214 + parse_flag('m', 'M', MPROTECT);
43215 + parse_flag('r', 'R', RANDMMAP);
43216 + parse_flag('s', 'S', SEGMEXEC);
43217 +
43218 +#undef parse_flag
43219 + }
43220 +
43221 + if (pax_flags_hardmode & pax_flags_softmode)
43222 + return ~0UL;
43223 +
43224 +#ifdef CONFIG_PAX_SOFTMODE
43225 + if (pax_softmode)
43226 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43227 + else
43228 +#endif
43229 +
43230 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43231 +#else
43232 + return ~0UL;
43233 +#endif
43234 +
43235 +}
43236 +
43237 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43238 +{
43239 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43240 +
43241 + pax_flags = pax_parse_ei_pax(elf_ex);
43242 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43243 + xattr_pax_flags = pax_parse_xattr_pax(file);
43244 +
43245 + if (pt_pax_flags == ~0UL)
43246 + pt_pax_flags = xattr_pax_flags;
43247 + else if (xattr_pax_flags == ~0UL)
43248 + xattr_pax_flags = pt_pax_flags;
43249 + if (pt_pax_flags != xattr_pax_flags)
43250 + return -EINVAL;
43251 + if (pt_pax_flags != ~0UL)
43252 + pax_flags = pt_pax_flags;
43253 +
43254 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43255 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43256 + if ((__supported_pte_mask & _PAGE_NX))
43257 + pax_flags &= ~MF_PAX_SEGMEXEC;
43258 + else
43259 + pax_flags &= ~MF_PAX_PAGEEXEC;
43260 + }
43261 +#endif
43262 +
43263 + if (0 > pax_check_flags(&pax_flags))
43264 + return -EINVAL;
43265 +
43266 + current->mm->pax_flags = pax_flags;
43267 + return 0;
43268 +}
43269 +#endif
43270 +
43271 /*
43272 * These are the functions used to load ELF style executables and shared
43273 * libraries. There is no binary dependent code anywhere else.
43274 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43275 {
43276 unsigned int random_variable = 0;
43277
43278 +#ifdef CONFIG_PAX_RANDUSTACK
43279 + if (randomize_va_space)
43280 + return stack_top - current->mm->delta_stack;
43281 +#endif
43282 +
43283 if ((current->flags & PF_RANDOMIZE) &&
43284 !(current->personality & ADDR_NO_RANDOMIZE)) {
43285 random_variable = get_random_int() & STACK_RND_MASK;
43286 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43287 unsigned long load_addr = 0, load_bias = 0;
43288 int load_addr_set = 0;
43289 char * elf_interpreter = NULL;
43290 - unsigned long error;
43291 + unsigned long error = 0;
43292 struct elf_phdr *elf_ppnt, *elf_phdata;
43293 unsigned long elf_bss, elf_brk;
43294 int retval, i;
43295 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43296 unsigned long start_code, end_code, start_data, end_data;
43297 unsigned long reloc_func_desc __maybe_unused = 0;
43298 int executable_stack = EXSTACK_DEFAULT;
43299 - unsigned long def_flags = 0;
43300 struct {
43301 struct elfhdr elf_ex;
43302 struct elfhdr interp_elf_ex;
43303 } *loc;
43304 + unsigned long pax_task_size = TASK_SIZE;
43305
43306 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43307 if (!loc) {
43308 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43309 goto out_free_dentry;
43310
43311 /* OK, This is the point of no return */
43312 - current->mm->def_flags = def_flags;
43313 +
43314 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43315 + current->mm->pax_flags = 0UL;
43316 +#endif
43317 +
43318 +#ifdef CONFIG_PAX_DLRESOLVE
43319 + current->mm->call_dl_resolve = 0UL;
43320 +#endif
43321 +
43322 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43323 + current->mm->call_syscall = 0UL;
43324 +#endif
43325 +
43326 +#ifdef CONFIG_PAX_ASLR
43327 + current->mm->delta_mmap = 0UL;
43328 + current->mm->delta_stack = 0UL;
43329 +#endif
43330 +
43331 + current->mm->def_flags = 0;
43332 +
43333 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43334 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43335 + send_sig(SIGKILL, current, 0);
43336 + goto out_free_dentry;
43337 + }
43338 +#endif
43339 +
43340 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43341 + pax_set_initial_flags(bprm);
43342 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43343 + if (pax_set_initial_flags_func)
43344 + (pax_set_initial_flags_func)(bprm);
43345 +#endif
43346 +
43347 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43348 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43349 + current->mm->context.user_cs_limit = PAGE_SIZE;
43350 + current->mm->def_flags |= VM_PAGEEXEC;
43351 + }
43352 +#endif
43353 +
43354 +#ifdef CONFIG_PAX_SEGMEXEC
43355 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43356 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43357 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43358 + pax_task_size = SEGMEXEC_TASK_SIZE;
43359 + current->mm->def_flags |= VM_NOHUGEPAGE;
43360 + }
43361 +#endif
43362 +
43363 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43364 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43365 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43366 + put_cpu();
43367 + }
43368 +#endif
43369
43370 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43371 may depend on the personality. */
43372 SET_PERSONALITY(loc->elf_ex);
43373 +
43374 +#ifdef CONFIG_PAX_ASLR
43375 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43376 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43377 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43378 + }
43379 +#endif
43380 +
43381 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43382 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43383 + executable_stack = EXSTACK_DISABLE_X;
43384 + current->personality &= ~READ_IMPLIES_EXEC;
43385 + } else
43386 +#endif
43387 +
43388 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43389 current->personality |= READ_IMPLIES_EXEC;
43390
43391 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43392 #else
43393 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43394 #endif
43395 +
43396 +#ifdef CONFIG_PAX_RANDMMAP
43397 + /* PaX: randomize base address at the default exe base if requested */
43398 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43399 +#ifdef CONFIG_SPARC64
43400 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43401 +#else
43402 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43403 +#endif
43404 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43405 + elf_flags |= MAP_FIXED;
43406 + }
43407 +#endif
43408 +
43409 }
43410
43411 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43412 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43413 * allowed task size. Note that p_filesz must always be
43414 * <= p_memsz so it is only necessary to check p_memsz.
43415 */
43416 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43417 - elf_ppnt->p_memsz > TASK_SIZE ||
43418 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43419 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43420 + elf_ppnt->p_memsz > pax_task_size ||
43421 + pax_task_size - elf_ppnt->p_memsz < k) {
43422 /* set_brk can never work. Avoid overflows. */
43423 send_sig(SIGKILL, current, 0);
43424 retval = -EINVAL;
43425 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43426 goto out_free_dentry;
43427 }
43428 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43429 - send_sig(SIGSEGV, current, 0);
43430 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43431 - goto out_free_dentry;
43432 + /*
43433 + * This bss-zeroing can fail if the ELF
43434 + * file specifies odd protections. So
43435 + * we don't check the return value
43436 + */
43437 }
43438
43439 +#ifdef CONFIG_PAX_RANDMMAP
43440 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43441 + unsigned long start, size;
43442 +
43443 + start = ELF_PAGEALIGN(elf_brk);
43444 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43445 + down_read(&current->mm->mmap_sem);
43446 + retval = -ENOMEM;
43447 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43448 + unsigned long prot = PROT_NONE;
43449 +
43450 + up_read(&current->mm->mmap_sem);
43451 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43452 +// if (current->personality & ADDR_NO_RANDOMIZE)
43453 +// prot = PROT_READ;
43454 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43455 + retval = IS_ERR_VALUE(start) ? start : 0;
43456 + } else
43457 + up_read(&current->mm->mmap_sem);
43458 + if (retval == 0)
43459 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43460 + if (retval < 0) {
43461 + send_sig(SIGKILL, current, 0);
43462 + goto out_free_dentry;
43463 + }
43464 + }
43465 +#endif
43466 +
43467 if (elf_interpreter) {
43468 - unsigned long interp_map_addr = 0;
43469 -
43470 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43471 interpreter,
43472 - &interp_map_addr,
43473 load_bias);
43474 if (!IS_ERR((void *)elf_entry)) {
43475 /*
43476 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43477 * Decide what to dump of a segment, part, all or none.
43478 */
43479 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43480 - unsigned long mm_flags)
43481 + unsigned long mm_flags, long signr)
43482 {
43483 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43484
43485 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43486 if (vma->vm_file == NULL)
43487 return 0;
43488
43489 - if (FILTER(MAPPED_PRIVATE))
43490 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43491 goto whole;
43492
43493 /*
43494 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43495 {
43496 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43497 int i = 0;
43498 - do
43499 + do {
43500 i += 2;
43501 - while (auxv[i - 2] != AT_NULL);
43502 + } while (auxv[i - 2] != AT_NULL);
43503 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43504 }
43505
43506 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43507 }
43508
43509 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43510 - unsigned long mm_flags)
43511 + struct coredump_params *cprm)
43512 {
43513 struct vm_area_struct *vma;
43514 size_t size = 0;
43515
43516 for (vma = first_vma(current, gate_vma); vma != NULL;
43517 vma = next_vma(vma, gate_vma))
43518 - size += vma_dump_size(vma, mm_flags);
43519 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43520 return size;
43521 }
43522
43523 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43524
43525 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43526
43527 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43528 + offset += elf_core_vma_data_size(gate_vma, cprm);
43529 offset += elf_core_extra_data_size();
43530 e_shoff = offset;
43531
43532 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43533 offset = dataoff;
43534
43535 size += sizeof(*elf);
43536 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43537 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43538 goto end_coredump;
43539
43540 size += sizeof(*phdr4note);
43541 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43542 if (size > cprm->limit
43543 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43544 goto end_coredump;
43545 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43546 phdr.p_offset = offset;
43547 phdr.p_vaddr = vma->vm_start;
43548 phdr.p_paddr = 0;
43549 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43550 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43551 phdr.p_memsz = vma->vm_end - vma->vm_start;
43552 offset += phdr.p_filesz;
43553 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43554 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43555 phdr.p_align = ELF_EXEC_PAGESIZE;
43556
43557 size += sizeof(phdr);
43558 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43559 if (size > cprm->limit
43560 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43561 goto end_coredump;
43562 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43563 unsigned long addr;
43564 unsigned long end;
43565
43566 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43567 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43568
43569 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43570 struct page *page;
43571 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43572 page = get_dump_page(addr);
43573 if (page) {
43574 void *kaddr = kmap(page);
43575 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43576 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43577 !dump_write(cprm->file, kaddr,
43578 PAGE_SIZE);
43579 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43580
43581 if (e_phnum == PN_XNUM) {
43582 size += sizeof(*shdr4extnum);
43583 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43584 if (size > cprm->limit
43585 || !dump_write(cprm->file, shdr4extnum,
43586 sizeof(*shdr4extnum)))
43587 @@ -2216,6 +2667,97 @@ out:
43588
43589 #endif /* CONFIG_ELF_CORE */
43590
43591 +#ifdef CONFIG_PAX_MPROTECT
43592 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43593 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43594 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43595 + *
43596 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43597 + * basis because we want to allow the common case and not the special ones.
43598 + */
43599 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43600 +{
43601 + struct elfhdr elf_h;
43602 + struct elf_phdr elf_p;
43603 + unsigned long i;
43604 + unsigned long oldflags;
43605 + bool is_textrel_rw, is_textrel_rx, is_relro;
43606 +
43607 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43608 + return;
43609 +
43610 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43611 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43612 +
43613 +#ifdef CONFIG_PAX_ELFRELOCS
43614 + /* possible TEXTREL */
43615 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43616 + 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);
43617 +#else
43618 + is_textrel_rw = false;
43619 + is_textrel_rx = false;
43620 +#endif
43621 +
43622 + /* possible RELRO */
43623 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43624 +
43625 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43626 + return;
43627 +
43628 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43629 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43630 +
43631 +#ifdef CONFIG_PAX_ETEXECRELOCS
43632 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43633 +#else
43634 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43635 +#endif
43636 +
43637 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43638 + !elf_check_arch(&elf_h) ||
43639 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43640 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43641 + return;
43642 +
43643 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43644 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43645 + return;
43646 + switch (elf_p.p_type) {
43647 + case PT_DYNAMIC:
43648 + if (!is_textrel_rw && !is_textrel_rx)
43649 + continue;
43650 + i = 0UL;
43651 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43652 + elf_dyn dyn;
43653 +
43654 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43655 + return;
43656 + if (dyn.d_tag == DT_NULL)
43657 + return;
43658 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43659 + gr_log_textrel(vma);
43660 + if (is_textrel_rw)
43661 + vma->vm_flags |= VM_MAYWRITE;
43662 + else
43663 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43664 + vma->vm_flags &= ~VM_MAYWRITE;
43665 + return;
43666 + }
43667 + i++;
43668 + }
43669 + return;
43670 +
43671 + case PT_GNU_RELRO:
43672 + if (!is_relro)
43673 + continue;
43674 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43675 + vma->vm_flags &= ~VM_MAYWRITE;
43676 + return;
43677 + }
43678 + }
43679 +}
43680 +#endif
43681 +
43682 static int __init init_elf_binfmt(void)
43683 {
43684 register_binfmt(&elf_format);
43685 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43686 index e280352..7b2f231 100644
43687 --- a/fs/binfmt_flat.c
43688 +++ b/fs/binfmt_flat.c
43689 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43690 realdatastart = (unsigned long) -ENOMEM;
43691 printk("Unable to allocate RAM for process data, errno %d\n",
43692 (int)-realdatastart);
43693 + down_write(&current->mm->mmap_sem);
43694 vm_munmap(textpos, text_len);
43695 + up_write(&current->mm->mmap_sem);
43696 ret = realdatastart;
43697 goto err;
43698 }
43699 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43700 }
43701 if (IS_ERR_VALUE(result)) {
43702 printk("Unable to read data+bss, errno %d\n", (int)-result);
43703 + down_write(&current->mm->mmap_sem);
43704 vm_munmap(textpos, text_len);
43705 vm_munmap(realdatastart, len);
43706 + up_write(&current->mm->mmap_sem);
43707 ret = result;
43708 goto err;
43709 }
43710 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43711 }
43712 if (IS_ERR_VALUE(result)) {
43713 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43714 + down_write(&current->mm->mmap_sem);
43715 vm_munmap(textpos, text_len + data_len + extra +
43716 MAX_SHARED_LIBS * sizeof(unsigned long));
43717 + up_write(&current->mm->mmap_sem);
43718 ret = result;
43719 goto err;
43720 }
43721 diff --git a/fs/bio.c b/fs/bio.c
43722 index b96fc6c..431d628 100644
43723 --- a/fs/bio.c
43724 +++ b/fs/bio.c
43725 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43726 /*
43727 * Overflow, abort
43728 */
43729 - if (end < start)
43730 + if (end < start || end - start > INT_MAX - nr_pages)
43731 return ERR_PTR(-EINVAL);
43732
43733 nr_pages += end - start;
43734 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43735 /*
43736 * Overflow, abort
43737 */
43738 - if (end < start)
43739 + if (end < start || end - start > INT_MAX - nr_pages)
43740 return ERR_PTR(-EINVAL);
43741
43742 nr_pages += end - start;
43743 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43744 const int read = bio_data_dir(bio) == READ;
43745 struct bio_map_data *bmd = bio->bi_private;
43746 int i;
43747 - char *p = bmd->sgvecs[0].iov_base;
43748 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43749
43750 __bio_for_each_segment(bvec, bio, i, 0) {
43751 char *addr = page_address(bvec->bv_page);
43752 diff --git a/fs/block_dev.c b/fs/block_dev.c
43753 index ab3a456..7da538b 100644
43754 --- a/fs/block_dev.c
43755 +++ b/fs/block_dev.c
43756 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43757 else if (bdev->bd_contains == bdev)
43758 return true; /* is a whole device which isn't held */
43759
43760 - else if (whole->bd_holder == bd_may_claim)
43761 + else if (whole->bd_holder == (void *)bd_may_claim)
43762 return true; /* is a partition of a device that is being partitioned */
43763 else if (whole->bd_holder != NULL)
43764 return false; /* is a partition of a held device */
43765 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43766 index 5a3e45d..ad19cc3 100644
43767 --- a/fs/btrfs/check-integrity.c
43768 +++ b/fs/btrfs/check-integrity.c
43769 @@ -156,7 +156,7 @@ struct btrfsic_block {
43770 union {
43771 bio_end_io_t *bio;
43772 bh_end_io_t *bh;
43773 - } orig_bio_bh_end_io;
43774 + } __no_const orig_bio_bh_end_io;
43775 int submit_bio_bh_rw;
43776 u64 flush_gen; /* only valid if !never_written */
43777 };
43778 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43779 index cdfb4c4..da736d4 100644
43780 --- a/fs/btrfs/ctree.c
43781 +++ b/fs/btrfs/ctree.c
43782 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43783 free_extent_buffer(buf);
43784 add_root_to_dirty_list(root);
43785 } else {
43786 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43787 - parent_start = parent->start;
43788 - else
43789 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43790 + if (parent)
43791 + parent_start = parent->start;
43792 + else
43793 + parent_start = 0;
43794 + } else
43795 parent_start = 0;
43796
43797 WARN_ON(trans->transid != btrfs_header_generation(parent));
43798 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43799 index 95542a1..95a8727 100644
43800 --- a/fs/btrfs/inode.c
43801 +++ b/fs/btrfs/inode.c
43802 @@ -7243,7 +7243,7 @@ fail:
43803 return -ENOMEM;
43804 }
43805
43806 -static int btrfs_getattr(struct vfsmount *mnt,
43807 +int btrfs_getattr(struct vfsmount *mnt,
43808 struct dentry *dentry, struct kstat *stat)
43809 {
43810 struct inode *inode = dentry->d_inode;
43811 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43812 return 0;
43813 }
43814
43815 +EXPORT_SYMBOL(btrfs_getattr);
43816 +
43817 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43818 +{
43819 + return BTRFS_I(inode)->root->anon_dev;
43820 +}
43821 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43822 +
43823 /*
43824 * If a file is moved, it will inherit the cow and compression flags of the new
43825 * directory.
43826 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43827 index 8fcf9a5..a200000 100644
43828 --- a/fs/btrfs/ioctl.c
43829 +++ b/fs/btrfs/ioctl.c
43830 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43831 for (i = 0; i < num_types; i++) {
43832 struct btrfs_space_info *tmp;
43833
43834 + /* Don't copy in more than we allocated */
43835 if (!slot_count)
43836 break;
43837
43838 + slot_count--;
43839 +
43840 info = NULL;
43841 rcu_read_lock();
43842 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43843 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43844 memcpy(dest, &space, sizeof(space));
43845 dest++;
43846 space_args.total_spaces++;
43847 - slot_count--;
43848 }
43849 - if (!slot_count)
43850 - break;
43851 }
43852 up_read(&info->groups_sem);
43853 }
43854 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43855 index 776f0aa..3aad281 100644
43856 --- a/fs/btrfs/relocation.c
43857 +++ b/fs/btrfs/relocation.c
43858 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43859 }
43860 spin_unlock(&rc->reloc_root_tree.lock);
43861
43862 - BUG_ON((struct btrfs_root *)node->data != root);
43863 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43864
43865 if (!del) {
43866 spin_lock(&rc->reloc_root_tree.lock);
43867 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43868 index 622f469..e8d2d55 100644
43869 --- a/fs/cachefiles/bind.c
43870 +++ b/fs/cachefiles/bind.c
43871 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43872 args);
43873
43874 /* start by checking things over */
43875 - ASSERT(cache->fstop_percent >= 0 &&
43876 - cache->fstop_percent < cache->fcull_percent &&
43877 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43878 cache->fcull_percent < cache->frun_percent &&
43879 cache->frun_percent < 100);
43880
43881 - ASSERT(cache->bstop_percent >= 0 &&
43882 - cache->bstop_percent < cache->bcull_percent &&
43883 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43884 cache->bcull_percent < cache->brun_percent &&
43885 cache->brun_percent < 100);
43886
43887 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43888 index 0a1467b..6a53245 100644
43889 --- a/fs/cachefiles/daemon.c
43890 +++ b/fs/cachefiles/daemon.c
43891 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43892 if (n > buflen)
43893 return -EMSGSIZE;
43894
43895 - if (copy_to_user(_buffer, buffer, n) != 0)
43896 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43897 return -EFAULT;
43898
43899 return n;
43900 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43901 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43902 return -EIO;
43903
43904 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43905 + if (datalen > PAGE_SIZE - 1)
43906 return -EOPNOTSUPP;
43907
43908 /* drag the command string into the kernel so we can parse it */
43909 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43910 if (args[0] != '%' || args[1] != '\0')
43911 return -EINVAL;
43912
43913 - if (fstop < 0 || fstop >= cache->fcull_percent)
43914 + if (fstop >= cache->fcull_percent)
43915 return cachefiles_daemon_range_error(cache, args);
43916
43917 cache->fstop_percent = fstop;
43918 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43919 if (args[0] != '%' || args[1] != '\0')
43920 return -EINVAL;
43921
43922 - if (bstop < 0 || bstop >= cache->bcull_percent)
43923 + if (bstop >= cache->bcull_percent)
43924 return cachefiles_daemon_range_error(cache, args);
43925
43926 cache->bstop_percent = bstop;
43927 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43928 index bd6bc1b..b627b53 100644
43929 --- a/fs/cachefiles/internal.h
43930 +++ b/fs/cachefiles/internal.h
43931 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43932 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43933 struct rb_root active_nodes; /* active nodes (can't be culled) */
43934 rwlock_t active_lock; /* lock for active_nodes */
43935 - atomic_t gravecounter; /* graveyard uniquifier */
43936 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43937 unsigned frun_percent; /* when to stop culling (% files) */
43938 unsigned fcull_percent; /* when to start culling (% files) */
43939 unsigned fstop_percent; /* when to stop allocating (% files) */
43940 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43941 * proc.c
43942 */
43943 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43944 -extern atomic_t cachefiles_lookup_histogram[HZ];
43945 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43946 -extern atomic_t cachefiles_create_histogram[HZ];
43947 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43948 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43949 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43950
43951 extern int __init cachefiles_proc_init(void);
43952 extern void cachefiles_proc_cleanup(void);
43953 static inline
43954 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43955 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43956 {
43957 unsigned long jif = jiffies - start_jif;
43958 if (jif >= HZ)
43959 jif = HZ - 1;
43960 - atomic_inc(&histogram[jif]);
43961 + atomic_inc_unchecked(&histogram[jif]);
43962 }
43963
43964 #else
43965 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43966 index b0b5f7c..039bb26 100644
43967 --- a/fs/cachefiles/namei.c
43968 +++ b/fs/cachefiles/namei.c
43969 @@ -318,7 +318,7 @@ try_again:
43970 /* first step is to make up a grave dentry in the graveyard */
43971 sprintf(nbuffer, "%08x%08x",
43972 (uint32_t) get_seconds(),
43973 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43974 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43975
43976 /* do the multiway lock magic */
43977 trap = lock_rename(cache->graveyard, dir);
43978 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43979 index eccd339..4c1d995 100644
43980 --- a/fs/cachefiles/proc.c
43981 +++ b/fs/cachefiles/proc.c
43982 @@ -14,9 +14,9 @@
43983 #include <linux/seq_file.h>
43984 #include "internal.h"
43985
43986 -atomic_t cachefiles_lookup_histogram[HZ];
43987 -atomic_t cachefiles_mkdir_histogram[HZ];
43988 -atomic_t cachefiles_create_histogram[HZ];
43989 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43990 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43991 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43992
43993 /*
43994 * display the latency histogram
43995 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43996 return 0;
43997 default:
43998 index = (unsigned long) v - 3;
43999 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44000 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44001 - z = atomic_read(&cachefiles_create_histogram[index]);
44002 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44003 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44004 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44005 if (x == 0 && y == 0 && z == 0)
44006 return 0;
44007
44008 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44009 index c994691..2a1537f 100644
44010 --- a/fs/cachefiles/rdwr.c
44011 +++ b/fs/cachefiles/rdwr.c
44012 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44013 old_fs = get_fs();
44014 set_fs(KERNEL_DS);
44015 ret = file->f_op->write(
44016 - file, (const void __user *) data, len, &pos);
44017 + file, (const void __force_user *) data, len, &pos);
44018 set_fs(old_fs);
44019 kunmap(page);
44020 if (ret != len)
44021 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44022 index e5b7731..b9c59fb 100644
44023 --- a/fs/ceph/dir.c
44024 +++ b/fs/ceph/dir.c
44025 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44026 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44027 struct ceph_mds_client *mdsc = fsc->mdsc;
44028 unsigned frag = fpos_frag(filp->f_pos);
44029 - int off = fpos_off(filp->f_pos);
44030 + unsigned int off = fpos_off(filp->f_pos);
44031 int err;
44032 u32 ftype;
44033 struct ceph_mds_reply_info_parsed *rinfo;
44034 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44035 index d9ea6ed..1e6c8ac 100644
44036 --- a/fs/cifs/cifs_debug.c
44037 +++ b/fs/cifs/cifs_debug.c
44038 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44039
44040 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44041 #ifdef CONFIG_CIFS_STATS2
44042 - atomic_set(&totBufAllocCount, 0);
44043 - atomic_set(&totSmBufAllocCount, 0);
44044 + atomic_set_unchecked(&totBufAllocCount, 0);
44045 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44046 #endif /* CONFIG_CIFS_STATS2 */
44047 spin_lock(&cifs_tcp_ses_lock);
44048 list_for_each(tmp1, &cifs_tcp_ses_list) {
44049 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44050 tcon = list_entry(tmp3,
44051 struct cifs_tcon,
44052 tcon_list);
44053 - atomic_set(&tcon->num_smbs_sent, 0);
44054 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44055 if (server->ops->clear_stats)
44056 server->ops->clear_stats(tcon);
44057 }
44058 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44059 smBufAllocCount.counter, cifs_min_small);
44060 #ifdef CONFIG_CIFS_STATS2
44061 seq_printf(m, "Total Large %d Small %d Allocations\n",
44062 - atomic_read(&totBufAllocCount),
44063 - atomic_read(&totSmBufAllocCount));
44064 + atomic_read_unchecked(&totBufAllocCount),
44065 + atomic_read_unchecked(&totSmBufAllocCount));
44066 #endif /* CONFIG_CIFS_STATS2 */
44067
44068 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44069 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44070 if (tcon->need_reconnect)
44071 seq_puts(m, "\tDISCONNECTED ");
44072 seq_printf(m, "\nSMBs: %d",
44073 - atomic_read(&tcon->num_smbs_sent));
44074 + atomic_read_unchecked(&tcon->num_smbs_sent));
44075 if (server->ops->print_stats)
44076 server->ops->print_stats(m, tcon);
44077 }
44078 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44079 index e7931cc..76a1ab9 100644
44080 --- a/fs/cifs/cifsfs.c
44081 +++ b/fs/cifs/cifsfs.c
44082 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
44083 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44084 cifs_req_cachep = kmem_cache_create("cifs_request",
44085 CIFSMaxBufSize + max_hdr_size, 0,
44086 - SLAB_HWCACHE_ALIGN, NULL);
44087 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44088 if (cifs_req_cachep == NULL)
44089 return -ENOMEM;
44090
44091 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
44092 efficient to alloc 1 per page off the slab compared to 17K (5page)
44093 alloc of large cifs buffers even when page debugging is on */
44094 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44095 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44096 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44097 NULL);
44098 if (cifs_sm_req_cachep == NULL) {
44099 mempool_destroy(cifs_req_poolp);
44100 @@ -1111,8 +1111,8 @@ init_cifs(void)
44101 atomic_set(&bufAllocCount, 0);
44102 atomic_set(&smBufAllocCount, 0);
44103 #ifdef CONFIG_CIFS_STATS2
44104 - atomic_set(&totBufAllocCount, 0);
44105 - atomic_set(&totSmBufAllocCount, 0);
44106 + atomic_set_unchecked(&totBufAllocCount, 0);
44107 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44108 #endif /* CONFIG_CIFS_STATS2 */
44109
44110 atomic_set(&midCount, 0);
44111 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44112 index f5af252..489b5f2 100644
44113 --- a/fs/cifs/cifsglob.h
44114 +++ b/fs/cifs/cifsglob.h
44115 @@ -751,35 +751,35 @@ struct cifs_tcon {
44116 __u16 Flags; /* optional support bits */
44117 enum statusEnum tidStatus;
44118 #ifdef CONFIG_CIFS_STATS
44119 - atomic_t num_smbs_sent;
44120 + atomic_unchecked_t num_smbs_sent;
44121 union {
44122 struct {
44123 - atomic_t num_writes;
44124 - atomic_t num_reads;
44125 - atomic_t num_flushes;
44126 - atomic_t num_oplock_brks;
44127 - atomic_t num_opens;
44128 - atomic_t num_closes;
44129 - atomic_t num_deletes;
44130 - atomic_t num_mkdirs;
44131 - atomic_t num_posixopens;
44132 - atomic_t num_posixmkdirs;
44133 - atomic_t num_rmdirs;
44134 - atomic_t num_renames;
44135 - atomic_t num_t2renames;
44136 - atomic_t num_ffirst;
44137 - atomic_t num_fnext;
44138 - atomic_t num_fclose;
44139 - atomic_t num_hardlinks;
44140 - atomic_t num_symlinks;
44141 - atomic_t num_locks;
44142 - atomic_t num_acl_get;
44143 - atomic_t num_acl_set;
44144 + atomic_unchecked_t num_writes;
44145 + atomic_unchecked_t num_reads;
44146 + atomic_unchecked_t num_flushes;
44147 + atomic_unchecked_t num_oplock_brks;
44148 + atomic_unchecked_t num_opens;
44149 + atomic_unchecked_t num_closes;
44150 + atomic_unchecked_t num_deletes;
44151 + atomic_unchecked_t num_mkdirs;
44152 + atomic_unchecked_t num_posixopens;
44153 + atomic_unchecked_t num_posixmkdirs;
44154 + atomic_unchecked_t num_rmdirs;
44155 + atomic_unchecked_t num_renames;
44156 + atomic_unchecked_t num_t2renames;
44157 + atomic_unchecked_t num_ffirst;
44158 + atomic_unchecked_t num_fnext;
44159 + atomic_unchecked_t num_fclose;
44160 + atomic_unchecked_t num_hardlinks;
44161 + atomic_unchecked_t num_symlinks;
44162 + atomic_unchecked_t num_locks;
44163 + atomic_unchecked_t num_acl_get;
44164 + atomic_unchecked_t num_acl_set;
44165 } cifs_stats;
44166 #ifdef CONFIG_CIFS_SMB2
44167 struct {
44168 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44169 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44170 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44171 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44172 } smb2_stats;
44173 #endif /* CONFIG_CIFS_SMB2 */
44174 } stats;
44175 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44176 }
44177
44178 #ifdef CONFIG_CIFS_STATS
44179 -#define cifs_stats_inc atomic_inc
44180 +#define cifs_stats_inc atomic_inc_unchecked
44181
44182 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44183 unsigned int bytes)
44184 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44185 /* Various Debug counters */
44186 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44187 #ifdef CONFIG_CIFS_STATS2
44188 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44189 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44190 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44191 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44192 #endif
44193 GLOBAL_EXTERN atomic_t smBufAllocCount;
44194 GLOBAL_EXTERN atomic_t midCount;
44195 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44196 index 51dc2fb..1e12a33 100644
44197 --- a/fs/cifs/link.c
44198 +++ b/fs/cifs/link.c
44199 @@ -616,7 +616,7 @@ symlink_exit:
44200
44201 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44202 {
44203 - char *p = nd_get_link(nd);
44204 + const char *p = nd_get_link(nd);
44205 if (!IS_ERR(p))
44206 kfree(p);
44207 }
44208 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44209 index 3a00c0d..42d901c 100644
44210 --- a/fs/cifs/misc.c
44211 +++ b/fs/cifs/misc.c
44212 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44213 memset(ret_buf, 0, buf_size + 3);
44214 atomic_inc(&bufAllocCount);
44215 #ifdef CONFIG_CIFS_STATS2
44216 - atomic_inc(&totBufAllocCount);
44217 + atomic_inc_unchecked(&totBufAllocCount);
44218 #endif /* CONFIG_CIFS_STATS2 */
44219 }
44220
44221 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44222 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44223 atomic_inc(&smBufAllocCount);
44224 #ifdef CONFIG_CIFS_STATS2
44225 - atomic_inc(&totSmBufAllocCount);
44226 + atomic_inc_unchecked(&totSmBufAllocCount);
44227 #endif /* CONFIG_CIFS_STATS2 */
44228
44229 }
44230 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44231 index 34cea27..3fbdf6f 100644
44232 --- a/fs/cifs/smb1ops.c
44233 +++ b/fs/cifs/smb1ops.c
44234 @@ -610,27 +610,27 @@ static void
44235 cifs_clear_stats(struct cifs_tcon *tcon)
44236 {
44237 #ifdef CONFIG_CIFS_STATS
44238 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44239 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44240 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44241 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44242 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44243 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44244 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44245 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44246 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44247 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44248 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44249 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44250 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44251 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44252 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44253 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44254 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44255 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44256 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44257 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44258 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44259 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44260 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44261 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44262 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44263 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44264 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44265 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44266 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44267 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44268 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44269 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44270 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44271 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44272 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44273 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44274 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44275 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44276 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44277 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44278 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44279 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44280 #endif
44281 }
44282
44283 @@ -639,36 +639,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44284 {
44285 #ifdef CONFIG_CIFS_STATS
44286 seq_printf(m, " Oplocks breaks: %d",
44287 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44288 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44289 seq_printf(m, "\nReads: %d Bytes: %llu",
44290 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44291 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44292 (long long)(tcon->bytes_read));
44293 seq_printf(m, "\nWrites: %d Bytes: %llu",
44294 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44295 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44296 (long long)(tcon->bytes_written));
44297 seq_printf(m, "\nFlushes: %d",
44298 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44299 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44300 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44301 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44302 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44303 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44304 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44305 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44306 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44307 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44308 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44309 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44310 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44311 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44312 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44313 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44314 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44315 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44316 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44317 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44318 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44319 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44320 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44321 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44322 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44323 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44324 seq_printf(m, "\nRenames: %d T2 Renames %d",
44325 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44326 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44327 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44328 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44329 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44330 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44331 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44332 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44333 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44334 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44335 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44336 #endif
44337 }
44338
44339 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44340 index 4d9dbe0..0af4601 100644
44341 --- a/fs/cifs/smb2ops.c
44342 +++ b/fs/cifs/smb2ops.c
44343 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44344 #ifdef CONFIG_CIFS_STATS
44345 int i;
44346 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44347 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44348 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44349 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44350 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44351 }
44352 #endif
44353 }
44354 @@ -301,66 +301,66 @@ static void
44355 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44356 {
44357 #ifdef CONFIG_CIFS_STATS
44358 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44359 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44360 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44361 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44362 seq_printf(m, "\nNegotiates: %d sent %d failed",
44363 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44364 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44365 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44366 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44367 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44368 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44369 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44370 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44371 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44372 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44373 seq_printf(m, "\nLogoffs: %d sent %d failed",
44374 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44375 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44376 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44377 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44378 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44379 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44380 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44381 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44382 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44383 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44384 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44385 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44386 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44387 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44388 seq_printf(m, "\nCreates: %d sent %d failed",
44389 - atomic_read(&sent[SMB2_CREATE_HE]),
44390 - atomic_read(&failed[SMB2_CREATE_HE]));
44391 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44392 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44393 seq_printf(m, "\nCloses: %d sent %d failed",
44394 - atomic_read(&sent[SMB2_CLOSE_HE]),
44395 - atomic_read(&failed[SMB2_CLOSE_HE]));
44396 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44397 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44398 seq_printf(m, "\nFlushes: %d sent %d failed",
44399 - atomic_read(&sent[SMB2_FLUSH_HE]),
44400 - atomic_read(&failed[SMB2_FLUSH_HE]));
44401 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44402 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44403 seq_printf(m, "\nReads: %d sent %d failed",
44404 - atomic_read(&sent[SMB2_READ_HE]),
44405 - atomic_read(&failed[SMB2_READ_HE]));
44406 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44407 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44408 seq_printf(m, "\nWrites: %d sent %d failed",
44409 - atomic_read(&sent[SMB2_WRITE_HE]),
44410 - atomic_read(&failed[SMB2_WRITE_HE]));
44411 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44412 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44413 seq_printf(m, "\nLocks: %d sent %d failed",
44414 - atomic_read(&sent[SMB2_LOCK_HE]),
44415 - atomic_read(&failed[SMB2_LOCK_HE]));
44416 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44417 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44418 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44419 - atomic_read(&sent[SMB2_IOCTL_HE]),
44420 - atomic_read(&failed[SMB2_IOCTL_HE]));
44421 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44422 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44423 seq_printf(m, "\nCancels: %d sent %d failed",
44424 - atomic_read(&sent[SMB2_CANCEL_HE]),
44425 - atomic_read(&failed[SMB2_CANCEL_HE]));
44426 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44427 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44428 seq_printf(m, "\nEchos: %d sent %d failed",
44429 - atomic_read(&sent[SMB2_ECHO_HE]),
44430 - atomic_read(&failed[SMB2_ECHO_HE]));
44431 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44432 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44433 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44434 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44435 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44436 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44437 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44438 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44439 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44440 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44441 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44442 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44443 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44444 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44445 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44446 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44447 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44448 seq_printf(m, "\nSetInfos: %d sent %d failed",
44449 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44450 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44451 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44452 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44453 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44454 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44455 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44456 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44457 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44458 #endif
44459 }
44460
44461 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44462 index 958ae0e..505c9d0 100644
44463 --- a/fs/coda/cache.c
44464 +++ b/fs/coda/cache.c
44465 @@ -24,7 +24,7 @@
44466 #include "coda_linux.h"
44467 #include "coda_cache.h"
44468
44469 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44470 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44471
44472 /* replace or extend an acl cache hit */
44473 void coda_cache_enter(struct inode *inode, int mask)
44474 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44475 struct coda_inode_info *cii = ITOC(inode);
44476
44477 spin_lock(&cii->c_lock);
44478 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44479 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44480 if (cii->c_uid != current_fsuid()) {
44481 cii->c_uid = current_fsuid();
44482 cii->c_cached_perm = mask;
44483 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44484 {
44485 struct coda_inode_info *cii = ITOC(inode);
44486 spin_lock(&cii->c_lock);
44487 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44488 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44489 spin_unlock(&cii->c_lock);
44490 }
44491
44492 /* remove all acl caches */
44493 void coda_cache_clear_all(struct super_block *sb)
44494 {
44495 - atomic_inc(&permission_epoch);
44496 + atomic_inc_unchecked(&permission_epoch);
44497 }
44498
44499
44500 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44501 spin_lock(&cii->c_lock);
44502 hit = (mask & cii->c_cached_perm) == mask &&
44503 cii->c_uid == current_fsuid() &&
44504 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44505 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44506 spin_unlock(&cii->c_lock);
44507
44508 return hit;
44509 diff --git a/fs/compat.c b/fs/compat.c
44510 index 015e1e1..5ce8e54 100644
44511 --- a/fs/compat.c
44512 +++ b/fs/compat.c
44513 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44514
44515 set_fs(KERNEL_DS);
44516 /* The __user pointer cast is valid because of the set_fs() */
44517 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44518 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44519 set_fs(oldfs);
44520 /* truncating is ok because it's a user address */
44521 if (!ret)
44522 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44523 goto out;
44524
44525 ret = -EINVAL;
44526 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44527 + if (nr_segs > UIO_MAXIOV)
44528 goto out;
44529 if (nr_segs > fast_segs) {
44530 ret = -ENOMEM;
44531 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44532
44533 struct compat_readdir_callback {
44534 struct compat_old_linux_dirent __user *dirent;
44535 + struct file * file;
44536 int result;
44537 };
44538
44539 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44540 buf->result = -EOVERFLOW;
44541 return -EOVERFLOW;
44542 }
44543 +
44544 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44545 + return 0;
44546 +
44547 buf->result++;
44548 dirent = buf->dirent;
44549 if (!access_ok(VERIFY_WRITE, dirent,
44550 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44551
44552 buf.result = 0;
44553 buf.dirent = dirent;
44554 + buf.file = f.file;
44555
44556 error = vfs_readdir(f.file, compat_fillonedir, &buf);
44557 if (buf.result)
44558 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
44559 struct compat_getdents_callback {
44560 struct compat_linux_dirent __user *current_dir;
44561 struct compat_linux_dirent __user *previous;
44562 + struct file * file;
44563 int count;
44564 int error;
44565 };
44566 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44567 buf->error = -EOVERFLOW;
44568 return -EOVERFLOW;
44569 }
44570 +
44571 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44572 + return 0;
44573 +
44574 dirent = buf->previous;
44575 if (dirent) {
44576 if (__put_user(offset, &dirent->d_off))
44577 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44578 buf.previous = NULL;
44579 buf.count = count;
44580 buf.error = 0;
44581 + buf.file = f.file;
44582
44583 error = vfs_readdir(f.file, compat_filldir, &buf);
44584 if (error >= 0)
44585 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44586 struct compat_getdents_callback64 {
44587 struct linux_dirent64 __user *current_dir;
44588 struct linux_dirent64 __user *previous;
44589 + struct file * file;
44590 int count;
44591 int error;
44592 };
44593 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44594 buf->error = -EINVAL; /* only used if we fail.. */
44595 if (reclen > buf->count)
44596 return -EINVAL;
44597 +
44598 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44599 + return 0;
44600 +
44601 dirent = buf->previous;
44602
44603 if (dirent) {
44604 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44605 buf.previous = NULL;
44606 buf.count = count;
44607 buf.error = 0;
44608 + buf.file = f.file;
44609
44610 error = vfs_readdir(f.file, compat_filldir64, &buf);
44611 if (error >= 0)
44612 error = buf.error;
44613 lastdirent = buf.previous;
44614 if (lastdirent) {
44615 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
44616 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
44617 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44618 error = -EFAULT;
44619 else
44620 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44621 index a81147e..20bf2b5 100644
44622 --- a/fs/compat_binfmt_elf.c
44623 +++ b/fs/compat_binfmt_elf.c
44624 @@ -30,11 +30,13 @@
44625 #undef elf_phdr
44626 #undef elf_shdr
44627 #undef elf_note
44628 +#undef elf_dyn
44629 #undef elf_addr_t
44630 #define elfhdr elf32_hdr
44631 #define elf_phdr elf32_phdr
44632 #define elf_shdr elf32_shdr
44633 #define elf_note elf32_note
44634 +#define elf_dyn Elf32_Dyn
44635 #define elf_addr_t Elf32_Addr
44636
44637 /*
44638 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44639 index 4c6285f..b7a2411 100644
44640 --- a/fs/compat_ioctl.c
44641 +++ b/fs/compat_ioctl.c
44642 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44643 return -EFAULT;
44644 if (__get_user(udata, &ss32->iomem_base))
44645 return -EFAULT;
44646 - ss.iomem_base = compat_ptr(udata);
44647 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44648 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44649 __get_user(ss.port_high, &ss32->port_high))
44650 return -EFAULT;
44651 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44652 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44653 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44654 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44655 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44656 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44657 return -EFAULT;
44658
44659 return ioctl_preallocate(file, p);
44660 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44661 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44662 {
44663 unsigned int a, b;
44664 - a = *(unsigned int *)p;
44665 - b = *(unsigned int *)q;
44666 + a = *(const unsigned int *)p;
44667 + b = *(const unsigned int *)q;
44668 if (a > b)
44669 return 1;
44670 if (a < b)
44671 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44672 index 7414ae2..d98ad6d 100644
44673 --- a/fs/configfs/dir.c
44674 +++ b/fs/configfs/dir.c
44675 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44676 }
44677 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44678 struct configfs_dirent *next;
44679 - const char * name;
44680 + const unsigned char * name;
44681 + char d_name[sizeof(next->s_dentry->d_iname)];
44682 int len;
44683 struct inode *inode = NULL;
44684
44685 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44686 continue;
44687
44688 name = configfs_get_name(next);
44689 - len = strlen(name);
44690 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44691 + len = next->s_dentry->d_name.len;
44692 + memcpy(d_name, name, len);
44693 + name = d_name;
44694 + } else
44695 + len = strlen(name);
44696
44697 /*
44698 * We'll have a dentry and an inode for
44699 diff --git a/fs/coredump.c b/fs/coredump.c
44700 index ce47379..68c8e43 100644
44701 --- a/fs/coredump.c
44702 +++ b/fs/coredump.c
44703 @@ -52,7 +52,7 @@ struct core_name {
44704 char *corename;
44705 int used, size;
44706 };
44707 -static atomic_t call_count = ATOMIC_INIT(1);
44708 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44709
44710 /* The maximal length of core_pattern is also specified in sysctl.c */
44711
44712 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
44713 {
44714 char *old_corename = cn->corename;
44715
44716 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44717 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44718 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44719
44720 if (!cn->corename) {
44721 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
44722 int pid_in_pattern = 0;
44723 int err = 0;
44724
44725 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44726 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44727 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44728 cn->used = 0;
44729
44730 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
44731 pipe = file->f_path.dentry->d_inode->i_pipe;
44732
44733 pipe_lock(pipe);
44734 - pipe->readers++;
44735 - pipe->writers--;
44736 + atomic_inc(&pipe->readers);
44737 + atomic_dec(&pipe->writers);
44738
44739 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44740 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44741 wake_up_interruptible_sync(&pipe->wait);
44742 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44743 pipe_wait(pipe);
44744 }
44745
44746 - pipe->readers--;
44747 - pipe->writers++;
44748 + atomic_dec(&pipe->readers);
44749 + atomic_inc(&pipe->writers);
44750 pipe_unlock(pipe);
44751
44752 }
44753 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44754 int ispipe;
44755 struct files_struct *displaced;
44756 bool need_nonrelative = false;
44757 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44758 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44759 + long signr = siginfo->si_signo;
44760 struct coredump_params cprm = {
44761 .siginfo = siginfo,
44762 .regs = regs,
44763 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44764 .mm_flags = mm->flags,
44765 };
44766
44767 - audit_core_dumps(siginfo->si_signo);
44768 + audit_core_dumps(signr);
44769 +
44770 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44771 + gr_handle_brute_attach(cprm.mm_flags);
44772
44773 binfmt = mm->binfmt;
44774 if (!binfmt || !binfmt->core_dump)
44775 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44776 need_nonrelative = true;
44777 }
44778
44779 - retval = coredump_wait(siginfo->si_signo, &core_state);
44780 + retval = coredump_wait(signr, &core_state);
44781 if (retval < 0)
44782 goto fail_creds;
44783
44784 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44785 }
44786 cprm.limit = RLIM_INFINITY;
44787
44788 - dump_count = atomic_inc_return(&core_dump_count);
44789 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44790 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44791 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44792 task_tgid_vnr(current), current->comm);
44793 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44794 } else {
44795 struct inode *inode;
44796
44797 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44798 +
44799 if (cprm.limit < binfmt->min_coredump)
44800 goto fail_unlock;
44801
44802 @@ -640,7 +646,7 @@ close_fail:
44803 filp_close(cprm.file, NULL);
44804 fail_dropcount:
44805 if (ispipe)
44806 - atomic_dec(&core_dump_count);
44807 + atomic_dec_unchecked(&core_dump_count);
44808 fail_unlock:
44809 kfree(cn.corename);
44810 fail_corename:
44811 @@ -659,7 +665,7 @@ fail:
44812 */
44813 int dump_write(struct file *file, const void *addr, int nr)
44814 {
44815 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44816 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44817 }
44818 EXPORT_SYMBOL(dump_write);
44819
44820 diff --git a/fs/dcache.c b/fs/dcache.c
44821 index 3a463d0..9f345c8 100644
44822 --- a/fs/dcache.c
44823 +++ b/fs/dcache.c
44824 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44825 mempages -= reserve;
44826
44827 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44828 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44829 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44830
44831 dcache_init();
44832 inode_init();
44833 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44834 index b607d92..41fda09 100644
44835 --- a/fs/debugfs/inode.c
44836 +++ b/fs/debugfs/inode.c
44837 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44838 */
44839 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44840 {
44841 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44842 + return __create_file(name, S_IFDIR | S_IRWXU,
44843 +#else
44844 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44845 +#endif
44846 parent, NULL, NULL);
44847 }
44848 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44849 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44850 index cc7709e..7e7211f 100644
44851 --- a/fs/ecryptfs/inode.c
44852 +++ b/fs/ecryptfs/inode.c
44853 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44854 old_fs = get_fs();
44855 set_fs(get_ds());
44856 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44857 - (char __user *)lower_buf,
44858 + (char __force_user *)lower_buf,
44859 PATH_MAX);
44860 set_fs(old_fs);
44861 if (rc < 0)
44862 @@ -706,7 +706,7 @@ out:
44863 static void
44864 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44865 {
44866 - char *buf = nd_get_link(nd);
44867 + const char *buf = nd_get_link(nd);
44868 if (!IS_ERR(buf)) {
44869 /* Free the char* */
44870 kfree(buf);
44871 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44872 index 412e6ed..4292d22 100644
44873 --- a/fs/ecryptfs/miscdev.c
44874 +++ b/fs/ecryptfs/miscdev.c
44875 @@ -315,7 +315,7 @@ check_list:
44876 goto out_unlock_msg_ctx;
44877 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44878 if (msg_ctx->msg) {
44879 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44880 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44881 goto out_unlock_msg_ctx;
44882 i += packet_length_size;
44883 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44884 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44885 index b2a34a1..162fa69 100644
44886 --- a/fs/ecryptfs/read_write.c
44887 +++ b/fs/ecryptfs/read_write.c
44888 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44889 return -EIO;
44890 fs_save = get_fs();
44891 set_fs(get_ds());
44892 - rc = vfs_write(lower_file, data, size, &offset);
44893 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44894 set_fs(fs_save);
44895 mark_inode_dirty_sync(ecryptfs_inode);
44896 return rc;
44897 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44898 return -EIO;
44899 fs_save = get_fs();
44900 set_fs(get_ds());
44901 - rc = vfs_read(lower_file, data, size, &offset);
44902 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44903 set_fs(fs_save);
44904 return rc;
44905 }
44906 diff --git a/fs/exec.c b/fs/exec.c
44907 index 0039055..ffc560c 100644
44908 --- a/fs/exec.c
44909 +++ b/fs/exec.c
44910 @@ -55,6 +55,16 @@
44911 #include <linux/pipe_fs_i.h>
44912 #include <linux/oom.h>
44913 #include <linux/compat.h>
44914 +#include <linux/random.h>
44915 +#include <linux/seq_file.h>
44916 +#include <linux/coredump.h>
44917 +
44918 +#ifdef CONFIG_PAX_REFCOUNT
44919 +#include <linux/kallsyms.h>
44920 +#include <linux/kdebug.h>
44921 +#endif
44922 +
44923 +#include <trace/events/fs.h>
44924
44925 #include <asm/uaccess.h>
44926 #include <asm/mmu_context.h>
44927 @@ -66,6 +76,18 @@
44928
44929 #include <trace/events/sched.h>
44930
44931 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44932 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44933 +{
44934 + 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");
44935 +}
44936 +#endif
44937 +
44938 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44939 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44940 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44941 +#endif
44942 +
44943 int suid_dumpable = 0;
44944
44945 static LIST_HEAD(formats);
44946 @@ -180,18 +202,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44947 int write)
44948 {
44949 struct page *page;
44950 - int ret;
44951
44952 -#ifdef CONFIG_STACK_GROWSUP
44953 - if (write) {
44954 - ret = expand_downwards(bprm->vma, pos);
44955 - if (ret < 0)
44956 - return NULL;
44957 - }
44958 -#endif
44959 - ret = get_user_pages(current, bprm->mm, pos,
44960 - 1, write, 1, &page, NULL);
44961 - if (ret <= 0)
44962 + if (0 > expand_downwards(bprm->vma, pos))
44963 + return NULL;
44964 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44965 return NULL;
44966
44967 if (write) {
44968 @@ -207,6 +221,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44969 if (size <= ARG_MAX)
44970 return page;
44971
44972 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44973 + // only allow 512KB for argv+env on suid/sgid binaries
44974 + // to prevent easy ASLR exhaustion
44975 + if (((bprm->cred->euid != current_euid()) ||
44976 + (bprm->cred->egid != current_egid())) &&
44977 + (size > (512 * 1024))) {
44978 + put_page(page);
44979 + return NULL;
44980 + }
44981 +#endif
44982 +
44983 /*
44984 * Limit to 1/4-th the stack size for the argv+env strings.
44985 * This ensures that:
44986 @@ -266,6 +291,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44987 vma->vm_end = STACK_TOP_MAX;
44988 vma->vm_start = vma->vm_end - PAGE_SIZE;
44989 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44990 +
44991 +#ifdef CONFIG_PAX_SEGMEXEC
44992 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44993 +#endif
44994 +
44995 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44996 INIT_LIST_HEAD(&vma->anon_vma_chain);
44997
44998 @@ -276,6 +306,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44999 mm->stack_vm = mm->total_vm = 1;
45000 up_write(&mm->mmap_sem);
45001 bprm->p = vma->vm_end - sizeof(void *);
45002 +
45003 +#ifdef CONFIG_PAX_RANDUSTACK
45004 + if (randomize_va_space)
45005 + bprm->p ^= random32() & ~PAGE_MASK;
45006 +#endif
45007 +
45008 return 0;
45009 err:
45010 up_write(&mm->mmap_sem);
45011 @@ -384,19 +420,7 @@ err:
45012 return err;
45013 }
45014
45015 -struct user_arg_ptr {
45016 -#ifdef CONFIG_COMPAT
45017 - bool is_compat;
45018 -#endif
45019 - union {
45020 - const char __user *const __user *native;
45021 -#ifdef CONFIG_COMPAT
45022 - const compat_uptr_t __user *compat;
45023 -#endif
45024 - } ptr;
45025 -};
45026 -
45027 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45028 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45029 {
45030 const char __user *native;
45031
45032 @@ -405,14 +429,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45033 compat_uptr_t compat;
45034
45035 if (get_user(compat, argv.ptr.compat + nr))
45036 - return ERR_PTR(-EFAULT);
45037 + return (const char __force_user *)ERR_PTR(-EFAULT);
45038
45039 return compat_ptr(compat);
45040 }
45041 #endif
45042
45043 if (get_user(native, argv.ptr.native + nr))
45044 - return ERR_PTR(-EFAULT);
45045 + return (const char __force_user *)ERR_PTR(-EFAULT);
45046
45047 return native;
45048 }
45049 @@ -431,7 +455,7 @@ static int count(struct user_arg_ptr argv, int max)
45050 if (!p)
45051 break;
45052
45053 - if (IS_ERR(p))
45054 + if (IS_ERR((const char __force_kernel *)p))
45055 return -EFAULT;
45056
45057 if (i++ >= max)
45058 @@ -465,7 +489,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45059
45060 ret = -EFAULT;
45061 str = get_user_arg_ptr(argv, argc);
45062 - if (IS_ERR(str))
45063 + if (IS_ERR((const char __force_kernel *)str))
45064 goto out;
45065
45066 len = strnlen_user(str, MAX_ARG_STRLEN);
45067 @@ -547,7 +571,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45068 int r;
45069 mm_segment_t oldfs = get_fs();
45070 struct user_arg_ptr argv = {
45071 - .ptr.native = (const char __user *const __user *)__argv,
45072 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45073 };
45074
45075 set_fs(KERNEL_DS);
45076 @@ -582,7 +606,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45077 unsigned long new_end = old_end - shift;
45078 struct mmu_gather tlb;
45079
45080 - BUG_ON(new_start > new_end);
45081 + if (new_start >= new_end || new_start < mmap_min_addr)
45082 + return -ENOMEM;
45083
45084 /*
45085 * ensure there are no vmas between where we want to go
45086 @@ -591,6 +616,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45087 if (vma != find_vma(mm, new_start))
45088 return -EFAULT;
45089
45090 +#ifdef CONFIG_PAX_SEGMEXEC
45091 + BUG_ON(pax_find_mirror_vma(vma));
45092 +#endif
45093 +
45094 /*
45095 * cover the whole range: [new_start, old_end)
45096 */
45097 @@ -671,10 +700,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45098 stack_top = arch_align_stack(stack_top);
45099 stack_top = PAGE_ALIGN(stack_top);
45100
45101 - if (unlikely(stack_top < mmap_min_addr) ||
45102 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45103 - return -ENOMEM;
45104 -
45105 stack_shift = vma->vm_end - stack_top;
45106
45107 bprm->p -= stack_shift;
45108 @@ -686,8 +711,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45109 bprm->exec -= stack_shift;
45110
45111 down_write(&mm->mmap_sem);
45112 +
45113 + /* Move stack pages down in memory. */
45114 + if (stack_shift) {
45115 + ret = shift_arg_pages(vma, stack_shift);
45116 + if (ret)
45117 + goto out_unlock;
45118 + }
45119 +
45120 vm_flags = VM_STACK_FLAGS;
45121
45122 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45123 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45124 + vm_flags &= ~VM_EXEC;
45125 +
45126 +#ifdef CONFIG_PAX_MPROTECT
45127 + if (mm->pax_flags & MF_PAX_MPROTECT)
45128 + vm_flags &= ~VM_MAYEXEC;
45129 +#endif
45130 +
45131 + }
45132 +#endif
45133 +
45134 /*
45135 * Adjust stack execute permissions; explicitly enable for
45136 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45137 @@ -706,13 +751,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45138 goto out_unlock;
45139 BUG_ON(prev != vma);
45140
45141 - /* Move stack pages down in memory. */
45142 - if (stack_shift) {
45143 - ret = shift_arg_pages(vma, stack_shift);
45144 - if (ret)
45145 - goto out_unlock;
45146 - }
45147 -
45148 /* mprotect_fixup is overkill to remove the temporary stack flags */
45149 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45150
45151 @@ -771,6 +809,8 @@ struct file *open_exec(const char *name)
45152
45153 fsnotify_open(file);
45154
45155 + trace_open_exec(name);
45156 +
45157 err = deny_write_access(file);
45158 if (err)
45159 goto exit;
45160 @@ -794,7 +834,7 @@ int kernel_read(struct file *file, loff_t offset,
45161 old_fs = get_fs();
45162 set_fs(get_ds());
45163 /* The cast to a user pointer is valid due to the set_fs() */
45164 - result = vfs_read(file, (void __user *)addr, count, &pos);
45165 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45166 set_fs(old_fs);
45167 return result;
45168 }
45169 @@ -1231,7 +1271,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45170 }
45171 rcu_read_unlock();
45172
45173 - if (p->fs->users > n_fs) {
45174 + if (atomic_read(&p->fs->users) > n_fs) {
45175 bprm->unsafe |= LSM_UNSAFE_SHARE;
45176 } else {
45177 res = -EAGAIN;
45178 @@ -1434,6 +1474,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45179
45180 EXPORT_SYMBOL(search_binary_handler);
45181
45182 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45183 +static DEFINE_PER_CPU(u64, exec_counter);
45184 +static int __init init_exec_counters(void)
45185 +{
45186 + unsigned int cpu;
45187 +
45188 + for_each_possible_cpu(cpu) {
45189 + per_cpu(exec_counter, cpu) = (u64)cpu;
45190 + }
45191 +
45192 + return 0;
45193 +}
45194 +early_initcall(init_exec_counters);
45195 +static inline void increment_exec_counter(void)
45196 +{
45197 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45198 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45199 +}
45200 +#else
45201 +static inline void increment_exec_counter(void) {}
45202 +#endif
45203 +
45204 /*
45205 * sys_execve() executes a new program.
45206 */
45207 @@ -1442,6 +1504,11 @@ static int do_execve_common(const char *filename,
45208 struct user_arg_ptr envp,
45209 struct pt_regs *regs)
45210 {
45211 +#ifdef CONFIG_GRKERNSEC
45212 + struct file *old_exec_file;
45213 + struct acl_subject_label *old_acl;
45214 + struct rlimit old_rlim[RLIM_NLIMITS];
45215 +#endif
45216 struct linux_binprm *bprm;
45217 struct file *file;
45218 struct files_struct *displaced;
45219 @@ -1449,6 +1516,8 @@ static int do_execve_common(const char *filename,
45220 int retval;
45221 const struct cred *cred = current_cred();
45222
45223 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45224 +
45225 /*
45226 * We move the actual failure in case of RLIMIT_NPROC excess from
45227 * set*uid() to execve() because too many poorly written programs
45228 @@ -1489,12 +1558,27 @@ static int do_execve_common(const char *filename,
45229 if (IS_ERR(file))
45230 goto out_unmark;
45231
45232 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45233 + retval = -EPERM;
45234 + goto out_file;
45235 + }
45236 +
45237 sched_exec();
45238
45239 bprm->file = file;
45240 bprm->filename = filename;
45241 bprm->interp = filename;
45242
45243 + if (gr_process_user_ban()) {
45244 + retval = -EPERM;
45245 + goto out_file;
45246 + }
45247 +
45248 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45249 + retval = -EACCES;
45250 + goto out_file;
45251 + }
45252 +
45253 retval = bprm_mm_init(bprm);
45254 if (retval)
45255 goto out_file;
45256 @@ -1511,24 +1595,65 @@ static int do_execve_common(const char *filename,
45257 if (retval < 0)
45258 goto out;
45259
45260 +#ifdef CONFIG_GRKERNSEC
45261 + old_acl = current->acl;
45262 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45263 + old_exec_file = current->exec_file;
45264 + get_file(file);
45265 + current->exec_file = file;
45266 +#endif
45267 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45268 + /* limit suid stack to 8MB
45269 + we saved the old limits above and will restore them if this exec fails
45270 + */
45271 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45272 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45273 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45274 +#endif
45275 +
45276 + if (!gr_tpe_allow(file)) {
45277 + retval = -EACCES;
45278 + goto out_fail;
45279 + }
45280 +
45281 + if (gr_check_crash_exec(file)) {
45282 + retval = -EACCES;
45283 + goto out_fail;
45284 + }
45285 +
45286 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45287 + bprm->unsafe);
45288 + if (retval < 0)
45289 + goto out_fail;
45290 +
45291 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45292 if (retval < 0)
45293 - goto out;
45294 + goto out_fail;
45295
45296 bprm->exec = bprm->p;
45297 retval = copy_strings(bprm->envc, envp, bprm);
45298 if (retval < 0)
45299 - goto out;
45300 + goto out_fail;
45301
45302 retval = copy_strings(bprm->argc, argv, bprm);
45303 if (retval < 0)
45304 - goto out;
45305 + goto out_fail;
45306 +
45307 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45308 +
45309 + gr_handle_exec_args(bprm, argv);
45310
45311 retval = search_binary_handler(bprm,regs);
45312 if (retval < 0)
45313 - goto out;
45314 + goto out_fail;
45315 +#ifdef CONFIG_GRKERNSEC
45316 + if (old_exec_file)
45317 + fput(old_exec_file);
45318 +#endif
45319
45320 /* execve succeeded */
45321 +
45322 + increment_exec_counter();
45323 current->fs->in_exec = 0;
45324 current->in_execve = 0;
45325 acct_update_integrals(current);
45326 @@ -1537,6 +1662,14 @@ static int do_execve_common(const char *filename,
45327 put_files_struct(displaced);
45328 return retval;
45329
45330 +out_fail:
45331 +#ifdef CONFIG_GRKERNSEC
45332 + current->acl = old_acl;
45333 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45334 + fput(current->exec_file);
45335 + current->exec_file = old_exec_file;
45336 +#endif
45337 +
45338 out:
45339 if (bprm->mm) {
45340 acct_arg_size(bprm, 0);
45341 @@ -1712,3 +1845,253 @@ int kernel_execve(const char *filename,
45342 ret_from_kernel_execve(p);
45343 }
45344 #endif
45345 +
45346 +int pax_check_flags(unsigned long *flags)
45347 +{
45348 + int retval = 0;
45349 +
45350 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45351 + if (*flags & MF_PAX_SEGMEXEC)
45352 + {
45353 + *flags &= ~MF_PAX_SEGMEXEC;
45354 + retval = -EINVAL;
45355 + }
45356 +#endif
45357 +
45358 + if ((*flags & MF_PAX_PAGEEXEC)
45359 +
45360 +#ifdef CONFIG_PAX_PAGEEXEC
45361 + && (*flags & MF_PAX_SEGMEXEC)
45362 +#endif
45363 +
45364 + )
45365 + {
45366 + *flags &= ~MF_PAX_PAGEEXEC;
45367 + retval = -EINVAL;
45368 + }
45369 +
45370 + if ((*flags & MF_PAX_MPROTECT)
45371 +
45372 +#ifdef CONFIG_PAX_MPROTECT
45373 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45374 +#endif
45375 +
45376 + )
45377 + {
45378 + *flags &= ~MF_PAX_MPROTECT;
45379 + retval = -EINVAL;
45380 + }
45381 +
45382 + if ((*flags & MF_PAX_EMUTRAMP)
45383 +
45384 +#ifdef CONFIG_PAX_EMUTRAMP
45385 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45386 +#endif
45387 +
45388 + )
45389 + {
45390 + *flags &= ~MF_PAX_EMUTRAMP;
45391 + retval = -EINVAL;
45392 + }
45393 +
45394 + return retval;
45395 +}
45396 +
45397 +EXPORT_SYMBOL(pax_check_flags);
45398 +
45399 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45400 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45401 +{
45402 + struct task_struct *tsk = current;
45403 + struct mm_struct *mm = current->mm;
45404 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45405 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45406 + char *path_exec = NULL;
45407 + char *path_fault = NULL;
45408 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45409 + siginfo_t info = { };
45410 +
45411 + if (buffer_exec && buffer_fault) {
45412 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45413 +
45414 + down_read(&mm->mmap_sem);
45415 + vma = mm->mmap;
45416 + while (vma && (!vma_exec || !vma_fault)) {
45417 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
45418 + vma_exec = vma;
45419 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45420 + vma_fault = vma;
45421 + vma = vma->vm_next;
45422 + }
45423 + if (vma_exec) {
45424 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45425 + if (IS_ERR(path_exec))
45426 + path_exec = "<path too long>";
45427 + else {
45428 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45429 + if (path_exec) {
45430 + *path_exec = 0;
45431 + path_exec = buffer_exec;
45432 + } else
45433 + path_exec = "<path too long>";
45434 + }
45435 + }
45436 + if (vma_fault) {
45437 + start = vma_fault->vm_start;
45438 + end = vma_fault->vm_end;
45439 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45440 + if (vma_fault->vm_file) {
45441 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45442 + if (IS_ERR(path_fault))
45443 + path_fault = "<path too long>";
45444 + else {
45445 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45446 + if (path_fault) {
45447 + *path_fault = 0;
45448 + path_fault = buffer_fault;
45449 + } else
45450 + path_fault = "<path too long>";
45451 + }
45452 + } else
45453 + path_fault = "<anonymous mapping>";
45454 + }
45455 + up_read(&mm->mmap_sem);
45456 + }
45457 + if (tsk->signal->curr_ip)
45458 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45459 + else
45460 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45461 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45462 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45463 + task_uid(tsk), task_euid(tsk), pc, sp);
45464 + free_page((unsigned long)buffer_exec);
45465 + free_page((unsigned long)buffer_fault);
45466 + pax_report_insns(regs, pc, sp);
45467 + info.si_signo = SIGKILL;
45468 + info.si_errno = 0;
45469 + info.si_code = SI_KERNEL;
45470 + info.si_pid = 0;
45471 + info.si_uid = 0;
45472 + do_coredump(&info, regs);
45473 +}
45474 +#endif
45475 +
45476 +#ifdef CONFIG_PAX_REFCOUNT
45477 +void pax_report_refcount_overflow(struct pt_regs *regs)
45478 +{
45479 + if (current->signal->curr_ip)
45480 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45481 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45482 + else
45483 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45484 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45485 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45486 + show_regs(regs);
45487 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45488 +}
45489 +#endif
45490 +
45491 +#ifdef CONFIG_PAX_USERCOPY
45492 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45493 +static noinline int check_stack_object(const void *obj, unsigned long len)
45494 +{
45495 + const void * const stack = task_stack_page(current);
45496 + const void * const stackend = stack + THREAD_SIZE;
45497 +
45498 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45499 + const void *frame = NULL;
45500 + const void *oldframe;
45501 +#endif
45502 +
45503 + if (obj + len < obj)
45504 + return -1;
45505 +
45506 + if (obj + len <= stack || stackend <= obj)
45507 + return 0;
45508 +
45509 + if (obj < stack || stackend < obj + len)
45510 + return -1;
45511 +
45512 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45513 + oldframe = __builtin_frame_address(1);
45514 + if (oldframe)
45515 + frame = __builtin_frame_address(2);
45516 + /*
45517 + low ----------------------------------------------> high
45518 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45519 + ^----------------^
45520 + allow copies only within here
45521 + */
45522 + while (stack <= frame && frame < stackend) {
45523 + /* if obj + len extends past the last frame, this
45524 + check won't pass and the next frame will be 0,
45525 + causing us to bail out and correctly report
45526 + the copy as invalid
45527 + */
45528 + if (obj + len <= frame)
45529 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45530 + oldframe = frame;
45531 + frame = *(const void * const *)frame;
45532 + }
45533 + return -1;
45534 +#else
45535 + return 1;
45536 +#endif
45537 +}
45538 +
45539 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45540 +{
45541 + if (current->signal->curr_ip)
45542 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45543 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45544 + else
45545 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45546 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45547 + dump_stack();
45548 + gr_handle_kernel_exploit();
45549 + do_group_exit(SIGKILL);
45550 +}
45551 +#endif
45552 +
45553 +void check_object_size(const void *ptr, unsigned long n, bool to)
45554 +{
45555 +
45556 +#ifdef CONFIG_PAX_USERCOPY
45557 + const char *type;
45558 +
45559 + if (!n)
45560 + return;
45561 +
45562 + type = check_heap_object(ptr, n, to);
45563 + if (!type) {
45564 + if (check_stack_object(ptr, n) != -1)
45565 + return;
45566 + type = "<process stack>";
45567 + }
45568 +
45569 + pax_report_usercopy(ptr, n, to, type);
45570 +#endif
45571 +
45572 +}
45573 +EXPORT_SYMBOL(check_object_size);
45574 +
45575 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45576 +void pax_track_stack(void)
45577 +{
45578 + unsigned long sp = (unsigned long)&sp;
45579 + if (sp < current_thread_info()->lowest_stack &&
45580 + sp > (unsigned long)task_stack_page(current))
45581 + current_thread_info()->lowest_stack = sp;
45582 +}
45583 +EXPORT_SYMBOL(pax_track_stack);
45584 +#endif
45585 +
45586 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45587 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45588 +{
45589 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45590 + dump_stack();
45591 + do_group_exit(SIGKILL);
45592 +}
45593 +EXPORT_SYMBOL(report_size_overflow);
45594 +#endif
45595 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45596 index 2616d0e..2ffdec9 100644
45597 --- a/fs/ext2/balloc.c
45598 +++ b/fs/ext2/balloc.c
45599 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45600
45601 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45602 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45603 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45604 + if (free_blocks < root_blocks + 1 &&
45605 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45606 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45607 - !in_group_p (sbi->s_resgid))) {
45608 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45609 return 0;
45610 }
45611 return 1;
45612 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45613 index 22548f5..41521d8 100644
45614 --- a/fs/ext3/balloc.c
45615 +++ b/fs/ext3/balloc.c
45616 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45617
45618 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45619 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45620 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45621 + if (free_blocks < root_blocks + 1 &&
45622 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45623 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45624 - !in_group_p (sbi->s_resgid))) {
45625 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45626 return 0;
45627 }
45628 return 1;
45629 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45630 index cf18217..8f6b9c3 100644
45631 --- a/fs/ext4/balloc.c
45632 +++ b/fs/ext4/balloc.c
45633 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45634 /* Hm, nope. Are (enough) root reserved clusters available? */
45635 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45636 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45637 - capable(CAP_SYS_RESOURCE) ||
45638 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45639 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45640 + capable_nolog(CAP_SYS_RESOURCE)) {
45641
45642 if (free_clusters >= (nclusters + dirty_clusters))
45643 return 1;
45644 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45645 index 3c20de1..6ff2460 100644
45646 --- a/fs/ext4/ext4.h
45647 +++ b/fs/ext4/ext4.h
45648 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45649 unsigned long s_mb_last_start;
45650
45651 /* stats for buddy allocator */
45652 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45653 - atomic_t s_bal_success; /* we found long enough chunks */
45654 - atomic_t s_bal_allocated; /* in blocks */
45655 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45656 - atomic_t s_bal_goals; /* goal hits */
45657 - atomic_t s_bal_breaks; /* too long searches */
45658 - atomic_t s_bal_2orders; /* 2^order hits */
45659 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45660 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45661 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45662 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45663 + atomic_unchecked_t s_bal_goals; /* goal hits */
45664 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45665 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45666 spinlock_t s_bal_lock;
45667 unsigned long s_mb_buddies_generated;
45668 unsigned long long s_mb_generation_time;
45669 - atomic_t s_mb_lost_chunks;
45670 - atomic_t s_mb_preallocated;
45671 - atomic_t s_mb_discarded;
45672 + atomic_unchecked_t s_mb_lost_chunks;
45673 + atomic_unchecked_t s_mb_preallocated;
45674 + atomic_unchecked_t s_mb_discarded;
45675 atomic_t s_lock_busy;
45676
45677 /* locality groups */
45678 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45679 index 526e553..3f2de85 100644
45680 --- a/fs/ext4/mballoc.c
45681 +++ b/fs/ext4/mballoc.c
45682 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45683 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45684
45685 if (EXT4_SB(sb)->s_mb_stats)
45686 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45687 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45688
45689 break;
45690 }
45691 @@ -2044,7 +2044,7 @@ repeat:
45692 ac->ac_status = AC_STATUS_CONTINUE;
45693 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45694 cr = 3;
45695 - atomic_inc(&sbi->s_mb_lost_chunks);
45696 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45697 goto repeat;
45698 }
45699 }
45700 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
45701 if (sbi->s_mb_stats) {
45702 ext4_msg(sb, KERN_INFO,
45703 "mballoc: %u blocks %u reqs (%u success)",
45704 - atomic_read(&sbi->s_bal_allocated),
45705 - atomic_read(&sbi->s_bal_reqs),
45706 - atomic_read(&sbi->s_bal_success));
45707 + atomic_read_unchecked(&sbi->s_bal_allocated),
45708 + atomic_read_unchecked(&sbi->s_bal_reqs),
45709 + atomic_read_unchecked(&sbi->s_bal_success));
45710 ext4_msg(sb, KERN_INFO,
45711 "mballoc: %u extents scanned, %u goal hits, "
45712 "%u 2^N hits, %u breaks, %u lost",
45713 - atomic_read(&sbi->s_bal_ex_scanned),
45714 - atomic_read(&sbi->s_bal_goals),
45715 - atomic_read(&sbi->s_bal_2orders),
45716 - atomic_read(&sbi->s_bal_breaks),
45717 - atomic_read(&sbi->s_mb_lost_chunks));
45718 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45719 + atomic_read_unchecked(&sbi->s_bal_goals),
45720 + atomic_read_unchecked(&sbi->s_bal_2orders),
45721 + atomic_read_unchecked(&sbi->s_bal_breaks),
45722 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45723 ext4_msg(sb, KERN_INFO,
45724 "mballoc: %lu generated and it took %Lu",
45725 sbi->s_mb_buddies_generated,
45726 sbi->s_mb_generation_time);
45727 ext4_msg(sb, KERN_INFO,
45728 "mballoc: %u preallocated, %u discarded",
45729 - atomic_read(&sbi->s_mb_preallocated),
45730 - atomic_read(&sbi->s_mb_discarded));
45731 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45732 + atomic_read_unchecked(&sbi->s_mb_discarded));
45733 }
45734
45735 free_percpu(sbi->s_locality_groups);
45736 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45737 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45738
45739 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45740 - atomic_inc(&sbi->s_bal_reqs);
45741 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45742 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45743 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45744 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45745 - atomic_inc(&sbi->s_bal_success);
45746 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45747 + atomic_inc_unchecked(&sbi->s_bal_success);
45748 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45749 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45750 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45751 - atomic_inc(&sbi->s_bal_goals);
45752 + atomic_inc_unchecked(&sbi->s_bal_goals);
45753 if (ac->ac_found > sbi->s_mb_max_to_scan)
45754 - atomic_inc(&sbi->s_bal_breaks);
45755 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45756 }
45757
45758 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45759 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45760 trace_ext4_mb_new_inode_pa(ac, pa);
45761
45762 ext4_mb_use_inode_pa(ac, pa);
45763 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45764 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45765
45766 ei = EXT4_I(ac->ac_inode);
45767 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45768 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45769 trace_ext4_mb_new_group_pa(ac, pa);
45770
45771 ext4_mb_use_group_pa(ac, pa);
45772 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45773 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45774
45775 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45776 lg = ac->ac_lg;
45777 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45778 * from the bitmap and continue.
45779 */
45780 }
45781 - atomic_add(free, &sbi->s_mb_discarded);
45782 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45783
45784 return err;
45785 }
45786 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45787 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45788 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45789 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45790 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45791 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45792 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45793
45794 return 0;
45795 diff --git a/fs/fcntl.c b/fs/fcntl.c
45796 index 71a600a..20d87b1 100644
45797 --- a/fs/fcntl.c
45798 +++ b/fs/fcntl.c
45799 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45800 if (err)
45801 return err;
45802
45803 + if (gr_handle_chroot_fowner(pid, type))
45804 + return -ENOENT;
45805 + if (gr_check_protected_task_fowner(pid, type))
45806 + return -EACCES;
45807 +
45808 f_modown(filp, pid, type, force);
45809 return 0;
45810 }
45811 diff --git a/fs/fifo.c b/fs/fifo.c
45812 index cf6f434..3d7942c 100644
45813 --- a/fs/fifo.c
45814 +++ b/fs/fifo.c
45815 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45816 */
45817 filp->f_op = &read_pipefifo_fops;
45818 pipe->r_counter++;
45819 - if (pipe->readers++ == 0)
45820 + if (atomic_inc_return(&pipe->readers) == 1)
45821 wake_up_partner(inode);
45822
45823 - if (!pipe->writers) {
45824 + if (!atomic_read(&pipe->writers)) {
45825 if ((filp->f_flags & O_NONBLOCK)) {
45826 /* suppress POLLHUP until we have
45827 * seen a writer */
45828 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45829 * errno=ENXIO when there is no process reading the FIFO.
45830 */
45831 ret = -ENXIO;
45832 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45833 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45834 goto err;
45835
45836 filp->f_op = &write_pipefifo_fops;
45837 pipe->w_counter++;
45838 - if (!pipe->writers++)
45839 + if (atomic_inc_return(&pipe->writers) == 1)
45840 wake_up_partner(inode);
45841
45842 - if (!pipe->readers) {
45843 + if (!atomic_read(&pipe->readers)) {
45844 if (wait_for_partner(inode, &pipe->r_counter))
45845 goto err_wr;
45846 }
45847 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45848 */
45849 filp->f_op = &rdwr_pipefifo_fops;
45850
45851 - pipe->readers++;
45852 - pipe->writers++;
45853 + atomic_inc(&pipe->readers);
45854 + atomic_inc(&pipe->writers);
45855 pipe->r_counter++;
45856 pipe->w_counter++;
45857 - if (pipe->readers == 1 || pipe->writers == 1)
45858 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45859 wake_up_partner(inode);
45860 break;
45861
45862 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45863 return 0;
45864
45865 err_rd:
45866 - if (!--pipe->readers)
45867 + if (atomic_dec_and_test(&pipe->readers))
45868 wake_up_interruptible(&pipe->wait);
45869 ret = -ERESTARTSYS;
45870 goto err;
45871
45872 err_wr:
45873 - if (!--pipe->writers)
45874 + if (atomic_dec_and_test(&pipe->writers))
45875 wake_up_interruptible(&pipe->wait);
45876 ret = -ERESTARTSYS;
45877 goto err;
45878
45879 err:
45880 - if (!pipe->readers && !pipe->writers)
45881 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45882 free_pipe_info(inode);
45883
45884 err_nocleanup:
45885 diff --git a/fs/file.c b/fs/file.c
45886 index eff2316..8c8930c 100644
45887 --- a/fs/file.c
45888 +++ b/fs/file.c
45889 @@ -16,6 +16,7 @@
45890 #include <linux/slab.h>
45891 #include <linux/vmalloc.h>
45892 #include <linux/file.h>
45893 +#include <linux/security.h>
45894 #include <linux/fdtable.h>
45895 #include <linux/bitops.h>
45896 #include <linux/interrupt.h>
45897 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
45898 if (!file)
45899 return __close_fd(files, fd);
45900
45901 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
45902 if (fd >= rlimit(RLIMIT_NOFILE))
45903 return -EBADF;
45904
45905 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
45906 if (unlikely(oldfd == newfd))
45907 return -EINVAL;
45908
45909 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
45910 if (newfd >= rlimit(RLIMIT_NOFILE))
45911 return -EBADF;
45912
45913 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
45914 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
45915 {
45916 int err;
45917 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
45918 if (from >= rlimit(RLIMIT_NOFILE))
45919 return -EINVAL;
45920 err = alloc_fd(from, flags);
45921 diff --git a/fs/filesystems.c b/fs/filesystems.c
45922 index da165f6..3671bdb 100644
45923 --- a/fs/filesystems.c
45924 +++ b/fs/filesystems.c
45925 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45926 int len = dot ? dot - name : strlen(name);
45927
45928 fs = __get_fs_type(name, len);
45929 +
45930 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45931 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45932 +#else
45933 if (!fs && (request_module("%.*s", len, name) == 0))
45934 +#endif
45935 fs = __get_fs_type(name, len);
45936
45937 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45938 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45939 index 5df4775..f656176 100644
45940 --- a/fs/fs_struct.c
45941 +++ b/fs/fs_struct.c
45942 @@ -4,6 +4,7 @@
45943 #include <linux/path.h>
45944 #include <linux/slab.h>
45945 #include <linux/fs_struct.h>
45946 +#include <linux/grsecurity.h>
45947 #include "internal.h"
45948
45949 /*
45950 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45951 write_seqcount_begin(&fs->seq);
45952 old_root = fs->root;
45953 fs->root = *path;
45954 + gr_set_chroot_entries(current, path);
45955 write_seqcount_end(&fs->seq);
45956 spin_unlock(&fs->lock);
45957 if (old_root.dentry)
45958 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45959 return 1;
45960 }
45961
45962 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45963 +{
45964 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45965 + return 0;
45966 + *p = *new;
45967 +
45968 + /* This function is only called from pivot_root(). Leave our
45969 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45970 + pivoted root isn't treated as a chroot
45971 + */
45972 + //gr_set_chroot_entries(task, new);
45973 +
45974 + return 1;
45975 +}
45976 +
45977 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45978 {
45979 struct task_struct *g, *p;
45980 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45981 int hits = 0;
45982 spin_lock(&fs->lock);
45983 write_seqcount_begin(&fs->seq);
45984 - hits += replace_path(&fs->root, old_root, new_root);
45985 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45986 hits += replace_path(&fs->pwd, old_root, new_root);
45987 write_seqcount_end(&fs->seq);
45988 while (hits--) {
45989 @@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
45990 {
45991 struct fs_struct *fs = tsk->fs;
45992
45993 + gr_put_exec_file(tsk);
45994 +
45995 if (fs) {
45996 int kill;
45997 task_lock(tsk);
45998 spin_lock(&fs->lock);
45999 tsk->fs = NULL;
46000 - kill = !--fs->users;
46001 + gr_clear_chroot_entries(tsk);
46002 + kill = !atomic_dec_return(&fs->users);
46003 spin_unlock(&fs->lock);
46004 task_unlock(tsk);
46005 if (kill)
46006 @@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46007 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46008 /* We don't need to lock fs - think why ;-) */
46009 if (fs) {
46010 - fs->users = 1;
46011 + atomic_set(&fs->users, 1);
46012 fs->in_exec = 0;
46013 spin_lock_init(&fs->lock);
46014 seqcount_init(&fs->seq);
46015 @@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46016 spin_lock(&old->lock);
46017 fs->root = old->root;
46018 path_get(&fs->root);
46019 + /* instead of calling gr_set_chroot_entries here,
46020 + we call it from every caller of this function
46021 + */
46022 fs->pwd = old->pwd;
46023 path_get(&fs->pwd);
46024 spin_unlock(&old->lock);
46025 @@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46026
46027 task_lock(current);
46028 spin_lock(&fs->lock);
46029 - kill = !--fs->users;
46030 + kill = !atomic_dec_return(&fs->users);
46031 current->fs = new_fs;
46032 + gr_set_chroot_entries(current, &new_fs->root);
46033 spin_unlock(&fs->lock);
46034 task_unlock(current);
46035
46036 @@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46037
46038 int current_umask(void)
46039 {
46040 - return current->fs->umask;
46041 + return current->fs->umask | gr_acl_umask();
46042 }
46043 EXPORT_SYMBOL(current_umask);
46044
46045 /* to be mentioned only in INIT_TASK */
46046 struct fs_struct init_fs = {
46047 - .users = 1,
46048 + .users = ATOMIC_INIT(1),
46049 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46050 .seq = SEQCNT_ZERO,
46051 .umask = 0022,
46052 @@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46053 {
46054 struct fs_struct *fs = current->fs;
46055
46056 + gr_put_exec_file(current);
46057 +
46058 if (fs) {
46059 int kill;
46060
46061 task_lock(current);
46062
46063 spin_lock(&init_fs.lock);
46064 - init_fs.users++;
46065 + atomic_inc(&init_fs.users);
46066 spin_unlock(&init_fs.lock);
46067
46068 spin_lock(&fs->lock);
46069 current->fs = &init_fs;
46070 - kill = !--fs->users;
46071 + gr_set_chroot_entries(current, &current->fs->root);
46072 + kill = !atomic_dec_return(&fs->users);
46073 spin_unlock(&fs->lock);
46074
46075 task_unlock(current);
46076 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46077 index 9905350..02eaec4 100644
46078 --- a/fs/fscache/cookie.c
46079 +++ b/fs/fscache/cookie.c
46080 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46081 parent ? (char *) parent->def->name : "<no-parent>",
46082 def->name, netfs_data);
46083
46084 - fscache_stat(&fscache_n_acquires);
46085 + fscache_stat_unchecked(&fscache_n_acquires);
46086
46087 /* if there's no parent cookie, then we don't create one here either */
46088 if (!parent) {
46089 - fscache_stat(&fscache_n_acquires_null);
46090 + fscache_stat_unchecked(&fscache_n_acquires_null);
46091 _leave(" [no parent]");
46092 return NULL;
46093 }
46094 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46095 /* allocate and initialise a cookie */
46096 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46097 if (!cookie) {
46098 - fscache_stat(&fscache_n_acquires_oom);
46099 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46100 _leave(" [ENOMEM]");
46101 return NULL;
46102 }
46103 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46104
46105 switch (cookie->def->type) {
46106 case FSCACHE_COOKIE_TYPE_INDEX:
46107 - fscache_stat(&fscache_n_cookie_index);
46108 + fscache_stat_unchecked(&fscache_n_cookie_index);
46109 break;
46110 case FSCACHE_COOKIE_TYPE_DATAFILE:
46111 - fscache_stat(&fscache_n_cookie_data);
46112 + fscache_stat_unchecked(&fscache_n_cookie_data);
46113 break;
46114 default:
46115 - fscache_stat(&fscache_n_cookie_special);
46116 + fscache_stat_unchecked(&fscache_n_cookie_special);
46117 break;
46118 }
46119
46120 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46121 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46122 atomic_dec(&parent->n_children);
46123 __fscache_cookie_put(cookie);
46124 - fscache_stat(&fscache_n_acquires_nobufs);
46125 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46126 _leave(" = NULL");
46127 return NULL;
46128 }
46129 }
46130
46131 - fscache_stat(&fscache_n_acquires_ok);
46132 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46133 _leave(" = %p", cookie);
46134 return cookie;
46135 }
46136 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46137 cache = fscache_select_cache_for_object(cookie->parent);
46138 if (!cache) {
46139 up_read(&fscache_addremove_sem);
46140 - fscache_stat(&fscache_n_acquires_no_cache);
46141 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46142 _leave(" = -ENOMEDIUM [no cache]");
46143 return -ENOMEDIUM;
46144 }
46145 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46146 object = cache->ops->alloc_object(cache, cookie);
46147 fscache_stat_d(&fscache_n_cop_alloc_object);
46148 if (IS_ERR(object)) {
46149 - fscache_stat(&fscache_n_object_no_alloc);
46150 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46151 ret = PTR_ERR(object);
46152 goto error;
46153 }
46154
46155 - fscache_stat(&fscache_n_object_alloc);
46156 + fscache_stat_unchecked(&fscache_n_object_alloc);
46157
46158 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46159
46160 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46161 struct fscache_object *object;
46162 struct hlist_node *_p;
46163
46164 - fscache_stat(&fscache_n_updates);
46165 + fscache_stat_unchecked(&fscache_n_updates);
46166
46167 if (!cookie) {
46168 - fscache_stat(&fscache_n_updates_null);
46169 + fscache_stat_unchecked(&fscache_n_updates_null);
46170 _leave(" [no cookie]");
46171 return;
46172 }
46173 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46174 struct fscache_object *object;
46175 unsigned long event;
46176
46177 - fscache_stat(&fscache_n_relinquishes);
46178 + fscache_stat_unchecked(&fscache_n_relinquishes);
46179 if (retire)
46180 - fscache_stat(&fscache_n_relinquishes_retire);
46181 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46182
46183 if (!cookie) {
46184 - fscache_stat(&fscache_n_relinquishes_null);
46185 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46186 _leave(" [no cookie]");
46187 return;
46188 }
46189 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46190
46191 /* wait for the cookie to finish being instantiated (or to fail) */
46192 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46193 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46194 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46195 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46196 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46197 }
46198 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46199 index f6aad48..88dcf26 100644
46200 --- a/fs/fscache/internal.h
46201 +++ b/fs/fscache/internal.h
46202 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46203 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46204 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46205
46206 -extern atomic_t fscache_n_op_pend;
46207 -extern atomic_t fscache_n_op_run;
46208 -extern atomic_t fscache_n_op_enqueue;
46209 -extern atomic_t fscache_n_op_deferred_release;
46210 -extern atomic_t fscache_n_op_release;
46211 -extern atomic_t fscache_n_op_gc;
46212 -extern atomic_t fscache_n_op_cancelled;
46213 -extern atomic_t fscache_n_op_rejected;
46214 +extern atomic_unchecked_t fscache_n_op_pend;
46215 +extern atomic_unchecked_t fscache_n_op_run;
46216 +extern atomic_unchecked_t fscache_n_op_enqueue;
46217 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46218 +extern atomic_unchecked_t fscache_n_op_release;
46219 +extern atomic_unchecked_t fscache_n_op_gc;
46220 +extern atomic_unchecked_t fscache_n_op_cancelled;
46221 +extern atomic_unchecked_t fscache_n_op_rejected;
46222
46223 -extern atomic_t fscache_n_attr_changed;
46224 -extern atomic_t fscache_n_attr_changed_ok;
46225 -extern atomic_t fscache_n_attr_changed_nobufs;
46226 -extern atomic_t fscache_n_attr_changed_nomem;
46227 -extern atomic_t fscache_n_attr_changed_calls;
46228 +extern atomic_unchecked_t fscache_n_attr_changed;
46229 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46230 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46231 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46232 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46233
46234 -extern atomic_t fscache_n_allocs;
46235 -extern atomic_t fscache_n_allocs_ok;
46236 -extern atomic_t fscache_n_allocs_wait;
46237 -extern atomic_t fscache_n_allocs_nobufs;
46238 -extern atomic_t fscache_n_allocs_intr;
46239 -extern atomic_t fscache_n_allocs_object_dead;
46240 -extern atomic_t fscache_n_alloc_ops;
46241 -extern atomic_t fscache_n_alloc_op_waits;
46242 +extern atomic_unchecked_t fscache_n_allocs;
46243 +extern atomic_unchecked_t fscache_n_allocs_ok;
46244 +extern atomic_unchecked_t fscache_n_allocs_wait;
46245 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46246 +extern atomic_unchecked_t fscache_n_allocs_intr;
46247 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46248 +extern atomic_unchecked_t fscache_n_alloc_ops;
46249 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46250
46251 -extern atomic_t fscache_n_retrievals;
46252 -extern atomic_t fscache_n_retrievals_ok;
46253 -extern atomic_t fscache_n_retrievals_wait;
46254 -extern atomic_t fscache_n_retrievals_nodata;
46255 -extern atomic_t fscache_n_retrievals_nobufs;
46256 -extern atomic_t fscache_n_retrievals_intr;
46257 -extern atomic_t fscache_n_retrievals_nomem;
46258 -extern atomic_t fscache_n_retrievals_object_dead;
46259 -extern atomic_t fscache_n_retrieval_ops;
46260 -extern atomic_t fscache_n_retrieval_op_waits;
46261 +extern atomic_unchecked_t fscache_n_retrievals;
46262 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46263 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46264 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46265 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46266 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46267 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46268 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46269 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46270 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46271
46272 -extern atomic_t fscache_n_stores;
46273 -extern atomic_t fscache_n_stores_ok;
46274 -extern atomic_t fscache_n_stores_again;
46275 -extern atomic_t fscache_n_stores_nobufs;
46276 -extern atomic_t fscache_n_stores_oom;
46277 -extern atomic_t fscache_n_store_ops;
46278 -extern atomic_t fscache_n_store_calls;
46279 -extern atomic_t fscache_n_store_pages;
46280 -extern atomic_t fscache_n_store_radix_deletes;
46281 -extern atomic_t fscache_n_store_pages_over_limit;
46282 +extern atomic_unchecked_t fscache_n_stores;
46283 +extern atomic_unchecked_t fscache_n_stores_ok;
46284 +extern atomic_unchecked_t fscache_n_stores_again;
46285 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46286 +extern atomic_unchecked_t fscache_n_stores_oom;
46287 +extern atomic_unchecked_t fscache_n_store_ops;
46288 +extern atomic_unchecked_t fscache_n_store_calls;
46289 +extern atomic_unchecked_t fscache_n_store_pages;
46290 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46291 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46292
46293 -extern atomic_t fscache_n_store_vmscan_not_storing;
46294 -extern atomic_t fscache_n_store_vmscan_gone;
46295 -extern atomic_t fscache_n_store_vmscan_busy;
46296 -extern atomic_t fscache_n_store_vmscan_cancelled;
46297 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46298 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46299 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46300 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46301
46302 -extern atomic_t fscache_n_marks;
46303 -extern atomic_t fscache_n_uncaches;
46304 +extern atomic_unchecked_t fscache_n_marks;
46305 +extern atomic_unchecked_t fscache_n_uncaches;
46306
46307 -extern atomic_t fscache_n_acquires;
46308 -extern atomic_t fscache_n_acquires_null;
46309 -extern atomic_t fscache_n_acquires_no_cache;
46310 -extern atomic_t fscache_n_acquires_ok;
46311 -extern atomic_t fscache_n_acquires_nobufs;
46312 -extern atomic_t fscache_n_acquires_oom;
46313 +extern atomic_unchecked_t fscache_n_acquires;
46314 +extern atomic_unchecked_t fscache_n_acquires_null;
46315 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46316 +extern atomic_unchecked_t fscache_n_acquires_ok;
46317 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46318 +extern atomic_unchecked_t fscache_n_acquires_oom;
46319
46320 -extern atomic_t fscache_n_updates;
46321 -extern atomic_t fscache_n_updates_null;
46322 -extern atomic_t fscache_n_updates_run;
46323 +extern atomic_unchecked_t fscache_n_updates;
46324 +extern atomic_unchecked_t fscache_n_updates_null;
46325 +extern atomic_unchecked_t fscache_n_updates_run;
46326
46327 -extern atomic_t fscache_n_relinquishes;
46328 -extern atomic_t fscache_n_relinquishes_null;
46329 -extern atomic_t fscache_n_relinquishes_waitcrt;
46330 -extern atomic_t fscache_n_relinquishes_retire;
46331 +extern atomic_unchecked_t fscache_n_relinquishes;
46332 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46333 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46334 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46335
46336 -extern atomic_t fscache_n_cookie_index;
46337 -extern atomic_t fscache_n_cookie_data;
46338 -extern atomic_t fscache_n_cookie_special;
46339 +extern atomic_unchecked_t fscache_n_cookie_index;
46340 +extern atomic_unchecked_t fscache_n_cookie_data;
46341 +extern atomic_unchecked_t fscache_n_cookie_special;
46342
46343 -extern atomic_t fscache_n_object_alloc;
46344 -extern atomic_t fscache_n_object_no_alloc;
46345 -extern atomic_t fscache_n_object_lookups;
46346 -extern atomic_t fscache_n_object_lookups_negative;
46347 -extern atomic_t fscache_n_object_lookups_positive;
46348 -extern atomic_t fscache_n_object_lookups_timed_out;
46349 -extern atomic_t fscache_n_object_created;
46350 -extern atomic_t fscache_n_object_avail;
46351 -extern atomic_t fscache_n_object_dead;
46352 +extern atomic_unchecked_t fscache_n_object_alloc;
46353 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46354 +extern atomic_unchecked_t fscache_n_object_lookups;
46355 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46356 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46357 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46358 +extern atomic_unchecked_t fscache_n_object_created;
46359 +extern atomic_unchecked_t fscache_n_object_avail;
46360 +extern atomic_unchecked_t fscache_n_object_dead;
46361
46362 -extern atomic_t fscache_n_checkaux_none;
46363 -extern atomic_t fscache_n_checkaux_okay;
46364 -extern atomic_t fscache_n_checkaux_update;
46365 -extern atomic_t fscache_n_checkaux_obsolete;
46366 +extern atomic_unchecked_t fscache_n_checkaux_none;
46367 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46368 +extern atomic_unchecked_t fscache_n_checkaux_update;
46369 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46370
46371 extern atomic_t fscache_n_cop_alloc_object;
46372 extern atomic_t fscache_n_cop_lookup_object;
46373 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46374 atomic_inc(stat);
46375 }
46376
46377 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46378 +{
46379 + atomic_inc_unchecked(stat);
46380 +}
46381 +
46382 static inline void fscache_stat_d(atomic_t *stat)
46383 {
46384 atomic_dec(stat);
46385 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46386
46387 #define __fscache_stat(stat) (NULL)
46388 #define fscache_stat(stat) do {} while (0)
46389 +#define fscache_stat_unchecked(stat) do {} while (0)
46390 #define fscache_stat_d(stat) do {} while (0)
46391 #endif
46392
46393 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46394 index b6b897c..0ffff9c 100644
46395 --- a/fs/fscache/object.c
46396 +++ b/fs/fscache/object.c
46397 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46398 /* update the object metadata on disk */
46399 case FSCACHE_OBJECT_UPDATING:
46400 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46401 - fscache_stat(&fscache_n_updates_run);
46402 + fscache_stat_unchecked(&fscache_n_updates_run);
46403 fscache_stat(&fscache_n_cop_update_object);
46404 object->cache->ops->update_object(object);
46405 fscache_stat_d(&fscache_n_cop_update_object);
46406 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46407 spin_lock(&object->lock);
46408 object->state = FSCACHE_OBJECT_DEAD;
46409 spin_unlock(&object->lock);
46410 - fscache_stat(&fscache_n_object_dead);
46411 + fscache_stat_unchecked(&fscache_n_object_dead);
46412 goto terminal_transit;
46413
46414 /* handle the parent cache of this object being withdrawn from
46415 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46416 spin_lock(&object->lock);
46417 object->state = FSCACHE_OBJECT_DEAD;
46418 spin_unlock(&object->lock);
46419 - fscache_stat(&fscache_n_object_dead);
46420 + fscache_stat_unchecked(&fscache_n_object_dead);
46421 goto terminal_transit;
46422
46423 /* complain about the object being woken up once it is
46424 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46425 parent->cookie->def->name, cookie->def->name,
46426 object->cache->tag->name);
46427
46428 - fscache_stat(&fscache_n_object_lookups);
46429 + fscache_stat_unchecked(&fscache_n_object_lookups);
46430 fscache_stat(&fscache_n_cop_lookup_object);
46431 ret = object->cache->ops->lookup_object(object);
46432 fscache_stat_d(&fscache_n_cop_lookup_object);
46433 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46434 if (ret == -ETIMEDOUT) {
46435 /* probably stuck behind another object, so move this one to
46436 * the back of the queue */
46437 - fscache_stat(&fscache_n_object_lookups_timed_out);
46438 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46439 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46440 }
46441
46442 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46443
46444 spin_lock(&object->lock);
46445 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46446 - fscache_stat(&fscache_n_object_lookups_negative);
46447 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46448
46449 /* transit here to allow write requests to begin stacking up
46450 * and read requests to begin returning ENODATA */
46451 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46452 * result, in which case there may be data available */
46453 spin_lock(&object->lock);
46454 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46455 - fscache_stat(&fscache_n_object_lookups_positive);
46456 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46457
46458 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46459
46460 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46461 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46462 } else {
46463 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46464 - fscache_stat(&fscache_n_object_created);
46465 + fscache_stat_unchecked(&fscache_n_object_created);
46466
46467 object->state = FSCACHE_OBJECT_AVAILABLE;
46468 spin_unlock(&object->lock);
46469 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46470 fscache_enqueue_dependents(object);
46471
46472 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46473 - fscache_stat(&fscache_n_object_avail);
46474 + fscache_stat_unchecked(&fscache_n_object_avail);
46475
46476 _leave("");
46477 }
46478 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46479 enum fscache_checkaux result;
46480
46481 if (!object->cookie->def->check_aux) {
46482 - fscache_stat(&fscache_n_checkaux_none);
46483 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46484 return FSCACHE_CHECKAUX_OKAY;
46485 }
46486
46487 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46488 switch (result) {
46489 /* entry okay as is */
46490 case FSCACHE_CHECKAUX_OKAY:
46491 - fscache_stat(&fscache_n_checkaux_okay);
46492 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46493 break;
46494
46495 /* entry requires update */
46496 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46497 - fscache_stat(&fscache_n_checkaux_update);
46498 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46499 break;
46500
46501 /* entry requires deletion */
46502 case FSCACHE_CHECKAUX_OBSOLETE:
46503 - fscache_stat(&fscache_n_checkaux_obsolete);
46504 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46505 break;
46506
46507 default:
46508 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46509 index 30afdfa..2256596 100644
46510 --- a/fs/fscache/operation.c
46511 +++ b/fs/fscache/operation.c
46512 @@ -17,7 +17,7 @@
46513 #include <linux/slab.h>
46514 #include "internal.h"
46515
46516 -atomic_t fscache_op_debug_id;
46517 +atomic_unchecked_t fscache_op_debug_id;
46518 EXPORT_SYMBOL(fscache_op_debug_id);
46519
46520 /**
46521 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46522 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46523 ASSERTCMP(atomic_read(&op->usage), >, 0);
46524
46525 - fscache_stat(&fscache_n_op_enqueue);
46526 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46527 switch (op->flags & FSCACHE_OP_TYPE) {
46528 case FSCACHE_OP_ASYNC:
46529 _debug("queue async");
46530 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46531 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46532 if (op->processor)
46533 fscache_enqueue_operation(op);
46534 - fscache_stat(&fscache_n_op_run);
46535 + fscache_stat_unchecked(&fscache_n_op_run);
46536 }
46537
46538 /*
46539 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46540 if (object->n_ops > 1) {
46541 atomic_inc(&op->usage);
46542 list_add_tail(&op->pend_link, &object->pending_ops);
46543 - fscache_stat(&fscache_n_op_pend);
46544 + fscache_stat_unchecked(&fscache_n_op_pend);
46545 } else if (!list_empty(&object->pending_ops)) {
46546 atomic_inc(&op->usage);
46547 list_add_tail(&op->pend_link, &object->pending_ops);
46548 - fscache_stat(&fscache_n_op_pend);
46549 + fscache_stat_unchecked(&fscache_n_op_pend);
46550 fscache_start_operations(object);
46551 } else {
46552 ASSERTCMP(object->n_in_progress, ==, 0);
46553 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46554 object->n_exclusive++; /* reads and writes must wait */
46555 atomic_inc(&op->usage);
46556 list_add_tail(&op->pend_link, &object->pending_ops);
46557 - fscache_stat(&fscache_n_op_pend);
46558 + fscache_stat_unchecked(&fscache_n_op_pend);
46559 ret = 0;
46560 } else {
46561 /* not allowed to submit ops in any other state */
46562 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46563 if (object->n_exclusive > 0) {
46564 atomic_inc(&op->usage);
46565 list_add_tail(&op->pend_link, &object->pending_ops);
46566 - fscache_stat(&fscache_n_op_pend);
46567 + fscache_stat_unchecked(&fscache_n_op_pend);
46568 } else if (!list_empty(&object->pending_ops)) {
46569 atomic_inc(&op->usage);
46570 list_add_tail(&op->pend_link, &object->pending_ops);
46571 - fscache_stat(&fscache_n_op_pend);
46572 + fscache_stat_unchecked(&fscache_n_op_pend);
46573 fscache_start_operations(object);
46574 } else {
46575 ASSERTCMP(object->n_exclusive, ==, 0);
46576 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46577 object->n_ops++;
46578 atomic_inc(&op->usage);
46579 list_add_tail(&op->pend_link, &object->pending_ops);
46580 - fscache_stat(&fscache_n_op_pend);
46581 + fscache_stat_unchecked(&fscache_n_op_pend);
46582 ret = 0;
46583 } else if (object->state == FSCACHE_OBJECT_DYING ||
46584 object->state == FSCACHE_OBJECT_LC_DYING ||
46585 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46586 - fscache_stat(&fscache_n_op_rejected);
46587 + fscache_stat_unchecked(&fscache_n_op_rejected);
46588 ret = -ENOBUFS;
46589 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46590 fscache_report_unexpected_submission(object, op, ostate);
46591 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46592
46593 ret = -EBUSY;
46594 if (!list_empty(&op->pend_link)) {
46595 - fscache_stat(&fscache_n_op_cancelled);
46596 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46597 list_del_init(&op->pend_link);
46598 object->n_ops--;
46599 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46600 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46601 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46602 BUG();
46603
46604 - fscache_stat(&fscache_n_op_release);
46605 + fscache_stat_unchecked(&fscache_n_op_release);
46606
46607 if (op->release) {
46608 op->release(op);
46609 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46610 * lock, and defer it otherwise */
46611 if (!spin_trylock(&object->lock)) {
46612 _debug("defer put");
46613 - fscache_stat(&fscache_n_op_deferred_release);
46614 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46615
46616 cache = object->cache;
46617 spin_lock(&cache->op_gc_list_lock);
46618 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46619
46620 _debug("GC DEFERRED REL OBJ%x OP%x",
46621 object->debug_id, op->debug_id);
46622 - fscache_stat(&fscache_n_op_gc);
46623 + fscache_stat_unchecked(&fscache_n_op_gc);
46624
46625 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46626
46627 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46628 index 3f7a59b..cf196cc 100644
46629 --- a/fs/fscache/page.c
46630 +++ b/fs/fscache/page.c
46631 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46632 val = radix_tree_lookup(&cookie->stores, page->index);
46633 if (!val) {
46634 rcu_read_unlock();
46635 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46636 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46637 __fscache_uncache_page(cookie, page);
46638 return true;
46639 }
46640 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46641 spin_unlock(&cookie->stores_lock);
46642
46643 if (xpage) {
46644 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46645 - fscache_stat(&fscache_n_store_radix_deletes);
46646 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46647 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46648 ASSERTCMP(xpage, ==, page);
46649 } else {
46650 - fscache_stat(&fscache_n_store_vmscan_gone);
46651 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46652 }
46653
46654 wake_up_bit(&cookie->flags, 0);
46655 @@ -107,7 +107,7 @@ page_busy:
46656 /* we might want to wait here, but that could deadlock the allocator as
46657 * the work threads writing to the cache may all end up sleeping
46658 * on memory allocation */
46659 - fscache_stat(&fscache_n_store_vmscan_busy);
46660 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46661 return false;
46662 }
46663 EXPORT_SYMBOL(__fscache_maybe_release_page);
46664 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46665 FSCACHE_COOKIE_STORING_TAG);
46666 if (!radix_tree_tag_get(&cookie->stores, page->index,
46667 FSCACHE_COOKIE_PENDING_TAG)) {
46668 - fscache_stat(&fscache_n_store_radix_deletes);
46669 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46670 xpage = radix_tree_delete(&cookie->stores, page->index);
46671 }
46672 spin_unlock(&cookie->stores_lock);
46673 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46674
46675 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46676
46677 - fscache_stat(&fscache_n_attr_changed_calls);
46678 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46679
46680 if (fscache_object_is_active(object)) {
46681 fscache_stat(&fscache_n_cop_attr_changed);
46682 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46683
46684 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46685
46686 - fscache_stat(&fscache_n_attr_changed);
46687 + fscache_stat_unchecked(&fscache_n_attr_changed);
46688
46689 op = kzalloc(sizeof(*op), GFP_KERNEL);
46690 if (!op) {
46691 - fscache_stat(&fscache_n_attr_changed_nomem);
46692 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46693 _leave(" = -ENOMEM");
46694 return -ENOMEM;
46695 }
46696 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46697 if (fscache_submit_exclusive_op(object, op) < 0)
46698 goto nobufs;
46699 spin_unlock(&cookie->lock);
46700 - fscache_stat(&fscache_n_attr_changed_ok);
46701 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46702 fscache_put_operation(op);
46703 _leave(" = 0");
46704 return 0;
46705 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46706 nobufs:
46707 spin_unlock(&cookie->lock);
46708 kfree(op);
46709 - fscache_stat(&fscache_n_attr_changed_nobufs);
46710 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46711 _leave(" = %d", -ENOBUFS);
46712 return -ENOBUFS;
46713 }
46714 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46715 /* allocate a retrieval operation and attempt to submit it */
46716 op = kzalloc(sizeof(*op), GFP_NOIO);
46717 if (!op) {
46718 - fscache_stat(&fscache_n_retrievals_nomem);
46719 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46720 return NULL;
46721 }
46722
46723 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46724 return 0;
46725 }
46726
46727 - fscache_stat(&fscache_n_retrievals_wait);
46728 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46729
46730 jif = jiffies;
46731 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46732 fscache_wait_bit_interruptible,
46733 TASK_INTERRUPTIBLE) != 0) {
46734 - fscache_stat(&fscache_n_retrievals_intr);
46735 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46736 _leave(" = -ERESTARTSYS");
46737 return -ERESTARTSYS;
46738 }
46739 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46740 */
46741 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46742 struct fscache_retrieval *op,
46743 - atomic_t *stat_op_waits,
46744 - atomic_t *stat_object_dead)
46745 + atomic_unchecked_t *stat_op_waits,
46746 + atomic_unchecked_t *stat_object_dead)
46747 {
46748 int ret;
46749
46750 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46751 goto check_if_dead;
46752
46753 _debug(">>> WT");
46754 - fscache_stat(stat_op_waits);
46755 + fscache_stat_unchecked(stat_op_waits);
46756 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46757 fscache_wait_bit_interruptible,
46758 TASK_INTERRUPTIBLE) < 0) {
46759 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46760
46761 check_if_dead:
46762 if (unlikely(fscache_object_is_dead(object))) {
46763 - fscache_stat(stat_object_dead);
46764 + fscache_stat_unchecked(stat_object_dead);
46765 return -ENOBUFS;
46766 }
46767 return 0;
46768 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46769
46770 _enter("%p,%p,,,", cookie, page);
46771
46772 - fscache_stat(&fscache_n_retrievals);
46773 + fscache_stat_unchecked(&fscache_n_retrievals);
46774
46775 if (hlist_empty(&cookie->backing_objects))
46776 goto nobufs;
46777 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46778 goto nobufs_unlock;
46779 spin_unlock(&cookie->lock);
46780
46781 - fscache_stat(&fscache_n_retrieval_ops);
46782 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46783
46784 /* pin the netfs read context in case we need to do the actual netfs
46785 * read because we've encountered a cache read failure */
46786 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46787
46788 error:
46789 if (ret == -ENOMEM)
46790 - fscache_stat(&fscache_n_retrievals_nomem);
46791 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46792 else if (ret == -ERESTARTSYS)
46793 - fscache_stat(&fscache_n_retrievals_intr);
46794 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46795 else if (ret == -ENODATA)
46796 - fscache_stat(&fscache_n_retrievals_nodata);
46797 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46798 else if (ret < 0)
46799 - fscache_stat(&fscache_n_retrievals_nobufs);
46800 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46801 else
46802 - fscache_stat(&fscache_n_retrievals_ok);
46803 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46804
46805 fscache_put_retrieval(op);
46806 _leave(" = %d", ret);
46807 @@ -429,7 +429,7 @@ nobufs_unlock:
46808 spin_unlock(&cookie->lock);
46809 kfree(op);
46810 nobufs:
46811 - fscache_stat(&fscache_n_retrievals_nobufs);
46812 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46813 _leave(" = -ENOBUFS");
46814 return -ENOBUFS;
46815 }
46816 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46817
46818 _enter("%p,,%d,,,", cookie, *nr_pages);
46819
46820 - fscache_stat(&fscache_n_retrievals);
46821 + fscache_stat_unchecked(&fscache_n_retrievals);
46822
46823 if (hlist_empty(&cookie->backing_objects))
46824 goto nobufs;
46825 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46826 goto nobufs_unlock;
46827 spin_unlock(&cookie->lock);
46828
46829 - fscache_stat(&fscache_n_retrieval_ops);
46830 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46831
46832 /* pin the netfs read context in case we need to do the actual netfs
46833 * read because we've encountered a cache read failure */
46834 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46835
46836 error:
46837 if (ret == -ENOMEM)
46838 - fscache_stat(&fscache_n_retrievals_nomem);
46839 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46840 else if (ret == -ERESTARTSYS)
46841 - fscache_stat(&fscache_n_retrievals_intr);
46842 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46843 else if (ret == -ENODATA)
46844 - fscache_stat(&fscache_n_retrievals_nodata);
46845 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46846 else if (ret < 0)
46847 - fscache_stat(&fscache_n_retrievals_nobufs);
46848 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46849 else
46850 - fscache_stat(&fscache_n_retrievals_ok);
46851 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46852
46853 fscache_put_retrieval(op);
46854 _leave(" = %d", ret);
46855 @@ -545,7 +545,7 @@ nobufs_unlock:
46856 spin_unlock(&cookie->lock);
46857 kfree(op);
46858 nobufs:
46859 - fscache_stat(&fscache_n_retrievals_nobufs);
46860 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46861 _leave(" = -ENOBUFS");
46862 return -ENOBUFS;
46863 }
46864 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46865
46866 _enter("%p,%p,,,", cookie, page);
46867
46868 - fscache_stat(&fscache_n_allocs);
46869 + fscache_stat_unchecked(&fscache_n_allocs);
46870
46871 if (hlist_empty(&cookie->backing_objects))
46872 goto nobufs;
46873 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46874 goto nobufs_unlock;
46875 spin_unlock(&cookie->lock);
46876
46877 - fscache_stat(&fscache_n_alloc_ops);
46878 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46879
46880 ret = fscache_wait_for_retrieval_activation(
46881 object, op,
46882 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46883
46884 error:
46885 if (ret == -ERESTARTSYS)
46886 - fscache_stat(&fscache_n_allocs_intr);
46887 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46888 else if (ret < 0)
46889 - fscache_stat(&fscache_n_allocs_nobufs);
46890 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46891 else
46892 - fscache_stat(&fscache_n_allocs_ok);
46893 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46894
46895 fscache_put_retrieval(op);
46896 _leave(" = %d", ret);
46897 @@ -625,7 +625,7 @@ nobufs_unlock:
46898 spin_unlock(&cookie->lock);
46899 kfree(op);
46900 nobufs:
46901 - fscache_stat(&fscache_n_allocs_nobufs);
46902 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46903 _leave(" = -ENOBUFS");
46904 return -ENOBUFS;
46905 }
46906 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46907
46908 spin_lock(&cookie->stores_lock);
46909
46910 - fscache_stat(&fscache_n_store_calls);
46911 + fscache_stat_unchecked(&fscache_n_store_calls);
46912
46913 /* find a page to store */
46914 page = NULL;
46915 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46916 page = results[0];
46917 _debug("gang %d [%lx]", n, page->index);
46918 if (page->index > op->store_limit) {
46919 - fscache_stat(&fscache_n_store_pages_over_limit);
46920 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46921 goto superseded;
46922 }
46923
46924 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46925 spin_unlock(&cookie->stores_lock);
46926 spin_unlock(&object->lock);
46927
46928 - fscache_stat(&fscache_n_store_pages);
46929 + fscache_stat_unchecked(&fscache_n_store_pages);
46930 fscache_stat(&fscache_n_cop_write_page);
46931 ret = object->cache->ops->write_page(op, page);
46932 fscache_stat_d(&fscache_n_cop_write_page);
46933 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46934 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46935 ASSERT(PageFsCache(page));
46936
46937 - fscache_stat(&fscache_n_stores);
46938 + fscache_stat_unchecked(&fscache_n_stores);
46939
46940 op = kzalloc(sizeof(*op), GFP_NOIO);
46941 if (!op)
46942 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46943 spin_unlock(&cookie->stores_lock);
46944 spin_unlock(&object->lock);
46945
46946 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46947 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46948 op->store_limit = object->store_limit;
46949
46950 if (fscache_submit_op(object, &op->op) < 0)
46951 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46952
46953 spin_unlock(&cookie->lock);
46954 radix_tree_preload_end();
46955 - fscache_stat(&fscache_n_store_ops);
46956 - fscache_stat(&fscache_n_stores_ok);
46957 + fscache_stat_unchecked(&fscache_n_store_ops);
46958 + fscache_stat_unchecked(&fscache_n_stores_ok);
46959
46960 /* the work queue now carries its own ref on the object */
46961 fscache_put_operation(&op->op);
46962 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46963 return 0;
46964
46965 already_queued:
46966 - fscache_stat(&fscache_n_stores_again);
46967 + fscache_stat_unchecked(&fscache_n_stores_again);
46968 already_pending:
46969 spin_unlock(&cookie->stores_lock);
46970 spin_unlock(&object->lock);
46971 spin_unlock(&cookie->lock);
46972 radix_tree_preload_end();
46973 kfree(op);
46974 - fscache_stat(&fscache_n_stores_ok);
46975 + fscache_stat_unchecked(&fscache_n_stores_ok);
46976 _leave(" = 0");
46977 return 0;
46978
46979 @@ -851,14 +851,14 @@ nobufs:
46980 spin_unlock(&cookie->lock);
46981 radix_tree_preload_end();
46982 kfree(op);
46983 - fscache_stat(&fscache_n_stores_nobufs);
46984 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46985 _leave(" = -ENOBUFS");
46986 return -ENOBUFS;
46987
46988 nomem_free:
46989 kfree(op);
46990 nomem:
46991 - fscache_stat(&fscache_n_stores_oom);
46992 + fscache_stat_unchecked(&fscache_n_stores_oom);
46993 _leave(" = -ENOMEM");
46994 return -ENOMEM;
46995 }
46996 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46997 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46998 ASSERTCMP(page, !=, NULL);
46999
47000 - fscache_stat(&fscache_n_uncaches);
47001 + fscache_stat_unchecked(&fscache_n_uncaches);
47002
47003 /* cache withdrawal may beat us to it */
47004 if (!PageFsCache(page))
47005 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47006 unsigned long loop;
47007
47008 #ifdef CONFIG_FSCACHE_STATS
47009 - atomic_add(pagevec->nr, &fscache_n_marks);
47010 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47011 #endif
47012
47013 for (loop = 0; loop < pagevec->nr; loop++) {
47014 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47015 index 4765190..2a067f2 100644
47016 --- a/fs/fscache/stats.c
47017 +++ b/fs/fscache/stats.c
47018 @@ -18,95 +18,95 @@
47019 /*
47020 * operation counters
47021 */
47022 -atomic_t fscache_n_op_pend;
47023 -atomic_t fscache_n_op_run;
47024 -atomic_t fscache_n_op_enqueue;
47025 -atomic_t fscache_n_op_requeue;
47026 -atomic_t fscache_n_op_deferred_release;
47027 -atomic_t fscache_n_op_release;
47028 -atomic_t fscache_n_op_gc;
47029 -atomic_t fscache_n_op_cancelled;
47030 -atomic_t fscache_n_op_rejected;
47031 +atomic_unchecked_t fscache_n_op_pend;
47032 +atomic_unchecked_t fscache_n_op_run;
47033 +atomic_unchecked_t fscache_n_op_enqueue;
47034 +atomic_unchecked_t fscache_n_op_requeue;
47035 +atomic_unchecked_t fscache_n_op_deferred_release;
47036 +atomic_unchecked_t fscache_n_op_release;
47037 +atomic_unchecked_t fscache_n_op_gc;
47038 +atomic_unchecked_t fscache_n_op_cancelled;
47039 +atomic_unchecked_t fscache_n_op_rejected;
47040
47041 -atomic_t fscache_n_attr_changed;
47042 -atomic_t fscache_n_attr_changed_ok;
47043 -atomic_t fscache_n_attr_changed_nobufs;
47044 -atomic_t fscache_n_attr_changed_nomem;
47045 -atomic_t fscache_n_attr_changed_calls;
47046 +atomic_unchecked_t fscache_n_attr_changed;
47047 +atomic_unchecked_t fscache_n_attr_changed_ok;
47048 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47049 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47050 +atomic_unchecked_t fscache_n_attr_changed_calls;
47051
47052 -atomic_t fscache_n_allocs;
47053 -atomic_t fscache_n_allocs_ok;
47054 -atomic_t fscache_n_allocs_wait;
47055 -atomic_t fscache_n_allocs_nobufs;
47056 -atomic_t fscache_n_allocs_intr;
47057 -atomic_t fscache_n_allocs_object_dead;
47058 -atomic_t fscache_n_alloc_ops;
47059 -atomic_t fscache_n_alloc_op_waits;
47060 +atomic_unchecked_t fscache_n_allocs;
47061 +atomic_unchecked_t fscache_n_allocs_ok;
47062 +atomic_unchecked_t fscache_n_allocs_wait;
47063 +atomic_unchecked_t fscache_n_allocs_nobufs;
47064 +atomic_unchecked_t fscache_n_allocs_intr;
47065 +atomic_unchecked_t fscache_n_allocs_object_dead;
47066 +atomic_unchecked_t fscache_n_alloc_ops;
47067 +atomic_unchecked_t fscache_n_alloc_op_waits;
47068
47069 -atomic_t fscache_n_retrievals;
47070 -atomic_t fscache_n_retrievals_ok;
47071 -atomic_t fscache_n_retrievals_wait;
47072 -atomic_t fscache_n_retrievals_nodata;
47073 -atomic_t fscache_n_retrievals_nobufs;
47074 -atomic_t fscache_n_retrievals_intr;
47075 -atomic_t fscache_n_retrievals_nomem;
47076 -atomic_t fscache_n_retrievals_object_dead;
47077 -atomic_t fscache_n_retrieval_ops;
47078 -atomic_t fscache_n_retrieval_op_waits;
47079 +atomic_unchecked_t fscache_n_retrievals;
47080 +atomic_unchecked_t fscache_n_retrievals_ok;
47081 +atomic_unchecked_t fscache_n_retrievals_wait;
47082 +atomic_unchecked_t fscache_n_retrievals_nodata;
47083 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47084 +atomic_unchecked_t fscache_n_retrievals_intr;
47085 +atomic_unchecked_t fscache_n_retrievals_nomem;
47086 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47087 +atomic_unchecked_t fscache_n_retrieval_ops;
47088 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47089
47090 -atomic_t fscache_n_stores;
47091 -atomic_t fscache_n_stores_ok;
47092 -atomic_t fscache_n_stores_again;
47093 -atomic_t fscache_n_stores_nobufs;
47094 -atomic_t fscache_n_stores_oom;
47095 -atomic_t fscache_n_store_ops;
47096 -atomic_t fscache_n_store_calls;
47097 -atomic_t fscache_n_store_pages;
47098 -atomic_t fscache_n_store_radix_deletes;
47099 -atomic_t fscache_n_store_pages_over_limit;
47100 +atomic_unchecked_t fscache_n_stores;
47101 +atomic_unchecked_t fscache_n_stores_ok;
47102 +atomic_unchecked_t fscache_n_stores_again;
47103 +atomic_unchecked_t fscache_n_stores_nobufs;
47104 +atomic_unchecked_t fscache_n_stores_oom;
47105 +atomic_unchecked_t fscache_n_store_ops;
47106 +atomic_unchecked_t fscache_n_store_calls;
47107 +atomic_unchecked_t fscache_n_store_pages;
47108 +atomic_unchecked_t fscache_n_store_radix_deletes;
47109 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47110
47111 -atomic_t fscache_n_store_vmscan_not_storing;
47112 -atomic_t fscache_n_store_vmscan_gone;
47113 -atomic_t fscache_n_store_vmscan_busy;
47114 -atomic_t fscache_n_store_vmscan_cancelled;
47115 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47116 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47117 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47118 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47119
47120 -atomic_t fscache_n_marks;
47121 -atomic_t fscache_n_uncaches;
47122 +atomic_unchecked_t fscache_n_marks;
47123 +atomic_unchecked_t fscache_n_uncaches;
47124
47125 -atomic_t fscache_n_acquires;
47126 -atomic_t fscache_n_acquires_null;
47127 -atomic_t fscache_n_acquires_no_cache;
47128 -atomic_t fscache_n_acquires_ok;
47129 -atomic_t fscache_n_acquires_nobufs;
47130 -atomic_t fscache_n_acquires_oom;
47131 +atomic_unchecked_t fscache_n_acquires;
47132 +atomic_unchecked_t fscache_n_acquires_null;
47133 +atomic_unchecked_t fscache_n_acquires_no_cache;
47134 +atomic_unchecked_t fscache_n_acquires_ok;
47135 +atomic_unchecked_t fscache_n_acquires_nobufs;
47136 +atomic_unchecked_t fscache_n_acquires_oom;
47137
47138 -atomic_t fscache_n_updates;
47139 -atomic_t fscache_n_updates_null;
47140 -atomic_t fscache_n_updates_run;
47141 +atomic_unchecked_t fscache_n_updates;
47142 +atomic_unchecked_t fscache_n_updates_null;
47143 +atomic_unchecked_t fscache_n_updates_run;
47144
47145 -atomic_t fscache_n_relinquishes;
47146 -atomic_t fscache_n_relinquishes_null;
47147 -atomic_t fscache_n_relinquishes_waitcrt;
47148 -atomic_t fscache_n_relinquishes_retire;
47149 +atomic_unchecked_t fscache_n_relinquishes;
47150 +atomic_unchecked_t fscache_n_relinquishes_null;
47151 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47152 +atomic_unchecked_t fscache_n_relinquishes_retire;
47153
47154 -atomic_t fscache_n_cookie_index;
47155 -atomic_t fscache_n_cookie_data;
47156 -atomic_t fscache_n_cookie_special;
47157 +atomic_unchecked_t fscache_n_cookie_index;
47158 +atomic_unchecked_t fscache_n_cookie_data;
47159 +atomic_unchecked_t fscache_n_cookie_special;
47160
47161 -atomic_t fscache_n_object_alloc;
47162 -atomic_t fscache_n_object_no_alloc;
47163 -atomic_t fscache_n_object_lookups;
47164 -atomic_t fscache_n_object_lookups_negative;
47165 -atomic_t fscache_n_object_lookups_positive;
47166 -atomic_t fscache_n_object_lookups_timed_out;
47167 -atomic_t fscache_n_object_created;
47168 -atomic_t fscache_n_object_avail;
47169 -atomic_t fscache_n_object_dead;
47170 +atomic_unchecked_t fscache_n_object_alloc;
47171 +atomic_unchecked_t fscache_n_object_no_alloc;
47172 +atomic_unchecked_t fscache_n_object_lookups;
47173 +atomic_unchecked_t fscache_n_object_lookups_negative;
47174 +atomic_unchecked_t fscache_n_object_lookups_positive;
47175 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47176 +atomic_unchecked_t fscache_n_object_created;
47177 +atomic_unchecked_t fscache_n_object_avail;
47178 +atomic_unchecked_t fscache_n_object_dead;
47179
47180 -atomic_t fscache_n_checkaux_none;
47181 -atomic_t fscache_n_checkaux_okay;
47182 -atomic_t fscache_n_checkaux_update;
47183 -atomic_t fscache_n_checkaux_obsolete;
47184 +atomic_unchecked_t fscache_n_checkaux_none;
47185 +atomic_unchecked_t fscache_n_checkaux_okay;
47186 +atomic_unchecked_t fscache_n_checkaux_update;
47187 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47188
47189 atomic_t fscache_n_cop_alloc_object;
47190 atomic_t fscache_n_cop_lookup_object;
47191 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47192 seq_puts(m, "FS-Cache statistics\n");
47193
47194 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47195 - atomic_read(&fscache_n_cookie_index),
47196 - atomic_read(&fscache_n_cookie_data),
47197 - atomic_read(&fscache_n_cookie_special));
47198 + atomic_read_unchecked(&fscache_n_cookie_index),
47199 + atomic_read_unchecked(&fscache_n_cookie_data),
47200 + atomic_read_unchecked(&fscache_n_cookie_special));
47201
47202 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47203 - atomic_read(&fscache_n_object_alloc),
47204 - atomic_read(&fscache_n_object_no_alloc),
47205 - atomic_read(&fscache_n_object_avail),
47206 - atomic_read(&fscache_n_object_dead));
47207 + atomic_read_unchecked(&fscache_n_object_alloc),
47208 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47209 + atomic_read_unchecked(&fscache_n_object_avail),
47210 + atomic_read_unchecked(&fscache_n_object_dead));
47211 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47212 - atomic_read(&fscache_n_checkaux_none),
47213 - atomic_read(&fscache_n_checkaux_okay),
47214 - atomic_read(&fscache_n_checkaux_update),
47215 - atomic_read(&fscache_n_checkaux_obsolete));
47216 + atomic_read_unchecked(&fscache_n_checkaux_none),
47217 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47218 + atomic_read_unchecked(&fscache_n_checkaux_update),
47219 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47220
47221 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47222 - atomic_read(&fscache_n_marks),
47223 - atomic_read(&fscache_n_uncaches));
47224 + atomic_read_unchecked(&fscache_n_marks),
47225 + atomic_read_unchecked(&fscache_n_uncaches));
47226
47227 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47228 " oom=%u\n",
47229 - atomic_read(&fscache_n_acquires),
47230 - atomic_read(&fscache_n_acquires_null),
47231 - atomic_read(&fscache_n_acquires_no_cache),
47232 - atomic_read(&fscache_n_acquires_ok),
47233 - atomic_read(&fscache_n_acquires_nobufs),
47234 - atomic_read(&fscache_n_acquires_oom));
47235 + atomic_read_unchecked(&fscache_n_acquires),
47236 + atomic_read_unchecked(&fscache_n_acquires_null),
47237 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47238 + atomic_read_unchecked(&fscache_n_acquires_ok),
47239 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47240 + atomic_read_unchecked(&fscache_n_acquires_oom));
47241
47242 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47243 - atomic_read(&fscache_n_object_lookups),
47244 - atomic_read(&fscache_n_object_lookups_negative),
47245 - atomic_read(&fscache_n_object_lookups_positive),
47246 - atomic_read(&fscache_n_object_created),
47247 - atomic_read(&fscache_n_object_lookups_timed_out));
47248 + atomic_read_unchecked(&fscache_n_object_lookups),
47249 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47250 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47251 + atomic_read_unchecked(&fscache_n_object_created),
47252 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47253
47254 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47255 - atomic_read(&fscache_n_updates),
47256 - atomic_read(&fscache_n_updates_null),
47257 - atomic_read(&fscache_n_updates_run));
47258 + atomic_read_unchecked(&fscache_n_updates),
47259 + atomic_read_unchecked(&fscache_n_updates_null),
47260 + atomic_read_unchecked(&fscache_n_updates_run));
47261
47262 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47263 - atomic_read(&fscache_n_relinquishes),
47264 - atomic_read(&fscache_n_relinquishes_null),
47265 - atomic_read(&fscache_n_relinquishes_waitcrt),
47266 - atomic_read(&fscache_n_relinquishes_retire));
47267 + atomic_read_unchecked(&fscache_n_relinquishes),
47268 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47269 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47270 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47271
47272 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47273 - atomic_read(&fscache_n_attr_changed),
47274 - atomic_read(&fscache_n_attr_changed_ok),
47275 - atomic_read(&fscache_n_attr_changed_nobufs),
47276 - atomic_read(&fscache_n_attr_changed_nomem),
47277 - atomic_read(&fscache_n_attr_changed_calls));
47278 + atomic_read_unchecked(&fscache_n_attr_changed),
47279 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47280 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47281 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47282 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47283
47284 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47285 - atomic_read(&fscache_n_allocs),
47286 - atomic_read(&fscache_n_allocs_ok),
47287 - atomic_read(&fscache_n_allocs_wait),
47288 - atomic_read(&fscache_n_allocs_nobufs),
47289 - atomic_read(&fscache_n_allocs_intr));
47290 + atomic_read_unchecked(&fscache_n_allocs),
47291 + atomic_read_unchecked(&fscache_n_allocs_ok),
47292 + atomic_read_unchecked(&fscache_n_allocs_wait),
47293 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47294 + atomic_read_unchecked(&fscache_n_allocs_intr));
47295 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47296 - atomic_read(&fscache_n_alloc_ops),
47297 - atomic_read(&fscache_n_alloc_op_waits),
47298 - atomic_read(&fscache_n_allocs_object_dead));
47299 + atomic_read_unchecked(&fscache_n_alloc_ops),
47300 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47301 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47302
47303 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47304 " int=%u oom=%u\n",
47305 - atomic_read(&fscache_n_retrievals),
47306 - atomic_read(&fscache_n_retrievals_ok),
47307 - atomic_read(&fscache_n_retrievals_wait),
47308 - atomic_read(&fscache_n_retrievals_nodata),
47309 - atomic_read(&fscache_n_retrievals_nobufs),
47310 - atomic_read(&fscache_n_retrievals_intr),
47311 - atomic_read(&fscache_n_retrievals_nomem));
47312 + atomic_read_unchecked(&fscache_n_retrievals),
47313 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47314 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47315 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47316 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47317 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47318 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47319 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47320 - atomic_read(&fscache_n_retrieval_ops),
47321 - atomic_read(&fscache_n_retrieval_op_waits),
47322 - atomic_read(&fscache_n_retrievals_object_dead));
47323 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47324 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47325 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47326
47327 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47328 - atomic_read(&fscache_n_stores),
47329 - atomic_read(&fscache_n_stores_ok),
47330 - atomic_read(&fscache_n_stores_again),
47331 - atomic_read(&fscache_n_stores_nobufs),
47332 - atomic_read(&fscache_n_stores_oom));
47333 + atomic_read_unchecked(&fscache_n_stores),
47334 + atomic_read_unchecked(&fscache_n_stores_ok),
47335 + atomic_read_unchecked(&fscache_n_stores_again),
47336 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47337 + atomic_read_unchecked(&fscache_n_stores_oom));
47338 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47339 - atomic_read(&fscache_n_store_ops),
47340 - atomic_read(&fscache_n_store_calls),
47341 - atomic_read(&fscache_n_store_pages),
47342 - atomic_read(&fscache_n_store_radix_deletes),
47343 - atomic_read(&fscache_n_store_pages_over_limit));
47344 + atomic_read_unchecked(&fscache_n_store_ops),
47345 + atomic_read_unchecked(&fscache_n_store_calls),
47346 + atomic_read_unchecked(&fscache_n_store_pages),
47347 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47348 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47349
47350 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47351 - atomic_read(&fscache_n_store_vmscan_not_storing),
47352 - atomic_read(&fscache_n_store_vmscan_gone),
47353 - atomic_read(&fscache_n_store_vmscan_busy),
47354 - atomic_read(&fscache_n_store_vmscan_cancelled));
47355 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47356 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47357 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47358 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47359
47360 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47361 - atomic_read(&fscache_n_op_pend),
47362 - atomic_read(&fscache_n_op_run),
47363 - atomic_read(&fscache_n_op_enqueue),
47364 - atomic_read(&fscache_n_op_cancelled),
47365 - atomic_read(&fscache_n_op_rejected));
47366 + atomic_read_unchecked(&fscache_n_op_pend),
47367 + atomic_read_unchecked(&fscache_n_op_run),
47368 + atomic_read_unchecked(&fscache_n_op_enqueue),
47369 + atomic_read_unchecked(&fscache_n_op_cancelled),
47370 + atomic_read_unchecked(&fscache_n_op_rejected));
47371 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47372 - atomic_read(&fscache_n_op_deferred_release),
47373 - atomic_read(&fscache_n_op_release),
47374 - atomic_read(&fscache_n_op_gc));
47375 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47376 + atomic_read_unchecked(&fscache_n_op_release),
47377 + atomic_read_unchecked(&fscache_n_op_gc));
47378
47379 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47380 atomic_read(&fscache_n_cop_alloc_object),
47381 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47382 index ee8d550..7189d8c 100644
47383 --- a/fs/fuse/cuse.c
47384 +++ b/fs/fuse/cuse.c
47385 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47386 INIT_LIST_HEAD(&cuse_conntbl[i]);
47387
47388 /* inherit and extend fuse_dev_operations */
47389 - cuse_channel_fops = fuse_dev_operations;
47390 - cuse_channel_fops.owner = THIS_MODULE;
47391 - cuse_channel_fops.open = cuse_channel_open;
47392 - cuse_channel_fops.release = cuse_channel_release;
47393 + pax_open_kernel();
47394 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47395 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47396 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47397 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47398 + pax_close_kernel();
47399
47400 cuse_class = class_create(THIS_MODULE, "cuse");
47401 if (IS_ERR(cuse_class))
47402 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47403 index 8c23fa7..0e3aac7 100644
47404 --- a/fs/fuse/dev.c
47405 +++ b/fs/fuse/dev.c
47406 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47407 ret = 0;
47408 pipe_lock(pipe);
47409
47410 - if (!pipe->readers) {
47411 + if (!atomic_read(&pipe->readers)) {
47412 send_sig(SIGPIPE, current, 0);
47413 if (!ret)
47414 ret = -EPIPE;
47415 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47416 index 324bc08..4fdd56e 100644
47417 --- a/fs/fuse/dir.c
47418 +++ b/fs/fuse/dir.c
47419 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47420 return link;
47421 }
47422
47423 -static void free_link(char *link)
47424 +static void free_link(const char *link)
47425 {
47426 if (!IS_ERR(link))
47427 free_page((unsigned long) link);
47428 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47429 index 381893c..3793318 100644
47430 --- a/fs/gfs2/inode.c
47431 +++ b/fs/gfs2/inode.c
47432 @@ -1490,7 +1490,7 @@ out:
47433
47434 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47435 {
47436 - char *s = nd_get_link(nd);
47437 + const char *s = nd_get_link(nd);
47438 if (!IS_ERR(s))
47439 kfree(s);
47440 }
47441 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47442 index c5bc355..5a513bb 100644
47443 --- a/fs/hugetlbfs/inode.c
47444 +++ b/fs/hugetlbfs/inode.c
47445 @@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47446 .kill_sb = kill_litter_super,
47447 };
47448
47449 -static struct vfsmount *hugetlbfs_vfsmount;
47450 +struct vfsmount *hugetlbfs_vfsmount;
47451
47452 static int can_do_hugetlb_shm(void)
47453 {
47454 diff --git a/fs/inode.c b/fs/inode.c
47455 index 64999f1..8fad608 100644
47456 --- a/fs/inode.c
47457 +++ b/fs/inode.c
47458 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
47459
47460 #ifdef CONFIG_SMP
47461 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47462 - static atomic_t shared_last_ino;
47463 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47464 + static atomic_unchecked_t shared_last_ino;
47465 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47466
47467 res = next - LAST_INO_BATCH;
47468 }
47469 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47470 index 4a6cf28..d3a29d3 100644
47471 --- a/fs/jffs2/erase.c
47472 +++ b/fs/jffs2/erase.c
47473 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47474 struct jffs2_unknown_node marker = {
47475 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47476 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47477 - .totlen = cpu_to_je32(c->cleanmarker_size)
47478 + .totlen = cpu_to_je32(c->cleanmarker_size),
47479 + .hdr_crc = cpu_to_je32(0)
47480 };
47481
47482 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47483 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47484 index a6597d6..41b30ec 100644
47485 --- a/fs/jffs2/wbuf.c
47486 +++ b/fs/jffs2/wbuf.c
47487 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47488 {
47489 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47490 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47491 - .totlen = constant_cpu_to_je32(8)
47492 + .totlen = constant_cpu_to_je32(8),
47493 + .hdr_crc = constant_cpu_to_je32(0)
47494 };
47495
47496 /*
47497 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47498 index 1a543be..d803c40 100644
47499 --- a/fs/jfs/super.c
47500 +++ b/fs/jfs/super.c
47501 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
47502
47503 jfs_inode_cachep =
47504 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47505 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47506 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47507 init_once);
47508 if (jfs_inode_cachep == NULL)
47509 return -ENOMEM;
47510 diff --git a/fs/libfs.c b/fs/libfs.c
47511 index 7cc37ca..b3e3eec 100644
47512 --- a/fs/libfs.c
47513 +++ b/fs/libfs.c
47514 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47515
47516 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47517 struct dentry *next;
47518 + char d_name[sizeof(next->d_iname)];
47519 + const unsigned char *name;
47520 +
47521 next = list_entry(p, struct dentry, d_u.d_child);
47522 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47523 if (!simple_positive(next)) {
47524 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47525
47526 spin_unlock(&next->d_lock);
47527 spin_unlock(&dentry->d_lock);
47528 - if (filldir(dirent, next->d_name.name,
47529 + name = next->d_name.name;
47530 + if (name == next->d_iname) {
47531 + memcpy(d_name, name, next->d_name.len);
47532 + name = d_name;
47533 + }
47534 + if (filldir(dirent, name,
47535 next->d_name.len, filp->f_pos,
47536 next->d_inode->i_ino,
47537 dt_type(next->d_inode)) < 0)
47538 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47539 index 05d2912..760abfa 100644
47540 --- a/fs/lockd/clntproc.c
47541 +++ b/fs/lockd/clntproc.c
47542 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47543 /*
47544 * Cookie counter for NLM requests
47545 */
47546 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47547 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47548
47549 void nlmclnt_next_cookie(struct nlm_cookie *c)
47550 {
47551 - u32 cookie = atomic_inc_return(&nlm_cookie);
47552 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47553
47554 memcpy(c->data, &cookie, 4);
47555 c->len=4;
47556 diff --git a/fs/locks.c b/fs/locks.c
47557 index a94e331..060bce3 100644
47558 --- a/fs/locks.c
47559 +++ b/fs/locks.c
47560 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
47561 return;
47562
47563 if (filp->f_op && filp->f_op->flock) {
47564 - struct file_lock fl = {
47565 + struct file_lock flock = {
47566 .fl_pid = current->tgid,
47567 .fl_file = filp,
47568 .fl_flags = FL_FLOCK,
47569 .fl_type = F_UNLCK,
47570 .fl_end = OFFSET_MAX,
47571 };
47572 - filp->f_op->flock(filp, F_SETLKW, &fl);
47573 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47574 - fl.fl_ops->fl_release_private(&fl);
47575 + filp->f_op->flock(filp, F_SETLKW, &flock);
47576 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47577 + flock.fl_ops->fl_release_private(&flock);
47578 }
47579
47580 lock_flocks();
47581 diff --git a/fs/namei.c b/fs/namei.c
47582 index 5f4cdf3..959a013 100644
47583 --- a/fs/namei.c
47584 +++ b/fs/namei.c
47585 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
47586 if (ret != -EACCES)
47587 return ret;
47588
47589 +#ifdef CONFIG_GRKERNSEC
47590 + /* we'll block if we have to log due to a denied capability use */
47591 + if (mask & MAY_NOT_BLOCK)
47592 + return -ECHILD;
47593 +#endif
47594 +
47595 if (S_ISDIR(inode->i_mode)) {
47596 /* DACs are overridable for directories */
47597 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47598 - return 0;
47599 if (!(mask & MAY_WRITE))
47600 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47601 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47602 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47603 return 0;
47604 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47605 + return 0;
47606 return -EACCES;
47607 }
47608 /*
47609 + * Searching includes executable on directories, else just read.
47610 + */
47611 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47612 + if (mask == MAY_READ)
47613 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47614 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47615 + return 0;
47616 +
47617 + /*
47618 * Read/write DACs are always overridable.
47619 * Executable DACs are overridable when there is
47620 * at least one exec bit set.
47621 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
47622 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47623 return 0;
47624
47625 - /*
47626 - * Searching includes executable on directories, else just read.
47627 - */
47628 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47629 - if (mask == MAY_READ)
47630 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47631 - return 0;
47632 -
47633 return -EACCES;
47634 }
47635
47636 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47637 {
47638 struct dentry *dentry = link->dentry;
47639 int error;
47640 - char *s;
47641 + const char *s;
47642
47643 BUG_ON(nd->flags & LOOKUP_RCU);
47644
47645 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47646 if (error)
47647 goto out_put_nd_path;
47648
47649 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47650 + dentry->d_inode, dentry, nd->path.mnt)) {
47651 + error = -EACCES;
47652 + goto out_put_nd_path;
47653 + }
47654 +
47655 nd->last_type = LAST_BIND;
47656 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47657 error = PTR_ERR(*p);
47658 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47659 break;
47660 res = walk_component(nd, path, &nd->last,
47661 nd->last_type, LOOKUP_FOLLOW);
47662 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47663 + res = -EACCES;
47664 put_link(nd, &link, cookie);
47665 } while (res > 0);
47666
47667 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
47668 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47669 {
47670 unsigned long a, b, adata, bdata, mask, hash, len;
47671 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47672 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47673
47674 hash = a = 0;
47675 len = -sizeof(unsigned long);
47676 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
47677 if (err)
47678 break;
47679 err = lookup_last(nd, &path);
47680 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47681 + err = -EACCES;
47682 put_link(nd, &link, cookie);
47683 }
47684 }
47685 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
47686 if (!err)
47687 err = complete_walk(nd);
47688
47689 + if (!(nd->flags & LOOKUP_PARENT)) {
47690 +#ifdef CONFIG_GRKERNSEC
47691 + if (flags & LOOKUP_RCU) {
47692 + if (!err)
47693 + path_put(&nd->path);
47694 + err = -ECHILD;
47695 + } else
47696 +#endif
47697 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47698 + if (!err)
47699 + path_put(&nd->path);
47700 + err = -ENOENT;
47701 + }
47702 + }
47703 +
47704 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47705 if (!nd->inode->i_op->lookup) {
47706 path_put(&nd->path);
47707 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
47708 retval = path_lookupat(dfd, name->name,
47709 flags | LOOKUP_REVAL, nd);
47710
47711 - if (likely(!retval))
47712 + if (likely(!retval)) {
47713 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
47714 +#ifdef CONFIG_GRKERNSEC
47715 + if (flags & LOOKUP_RCU)
47716 + return -ECHILD;
47717 +#endif
47718 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47719 + return -ENOENT;
47720 + }
47721 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
47722 + }
47723 return retval;
47724 }
47725
47726 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47727 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47728 return -EPERM;
47729
47730 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47731 + return -EPERM;
47732 + if (gr_handle_rawio(inode))
47733 + return -EPERM;
47734 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47735 + return -EACCES;
47736 +
47737 return 0;
47738 }
47739
47740 @@ -2623,7 +2672,7 @@ looked_up:
47741 * cleared otherwise prior to returning.
47742 */
47743 static int lookup_open(struct nameidata *nd, struct path *path,
47744 - struct file *file,
47745 + struct path *link, struct file *file,
47746 const struct open_flags *op,
47747 bool got_write, int *opened)
47748 {
47749 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47750 /* Negative dentry, just create the file */
47751 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47752 umode_t mode = op->mode;
47753 +
47754 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47755 + error = -EACCES;
47756 + goto out_dput;
47757 + }
47758 +
47759 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47760 + error = -EACCES;
47761 + goto out_dput;
47762 + }
47763 +
47764 if (!IS_POSIXACL(dir->d_inode))
47765 mode &= ~current_umask();
47766 /*
47767 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47768 nd->flags & LOOKUP_EXCL);
47769 if (error)
47770 goto out_dput;
47771 + else
47772 + gr_handle_create(dentry, nd->path.mnt);
47773 }
47774 out_no_open:
47775 path->dentry = dentry;
47776 @@ -2693,7 +2755,7 @@ out_dput:
47777 /*
47778 * Handle the last step of open()
47779 */
47780 -static int do_last(struct nameidata *nd, struct path *path,
47781 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47782 struct file *file, const struct open_flags *op,
47783 int *opened, struct filename *name)
47784 {
47785 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47786 error = complete_walk(nd);
47787 if (error)
47788 return error;
47789 +#ifdef CONFIG_GRKERNSEC
47790 + if (nd->flags & LOOKUP_RCU) {
47791 + error = -ECHILD;
47792 + goto out;
47793 + }
47794 +#endif
47795 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47796 + error = -ENOENT;
47797 + goto out;
47798 + }
47799 audit_inode(name, nd->path.dentry, 0);
47800 if (open_flag & O_CREAT) {
47801 error = -EISDIR;
47802 goto out;
47803 }
47804 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47805 + error = -EACCES;
47806 + goto out;
47807 + }
47808 goto finish_open;
47809 case LAST_BIND:
47810 error = complete_walk(nd);
47811 if (error)
47812 return error;
47813 +#ifdef CONFIG_GRKERNSEC
47814 + if (nd->flags & LOOKUP_RCU) {
47815 + error = -ECHILD;
47816 + goto out;
47817 + }
47818 +#endif
47819 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47820 + error = -ENOENT;
47821 + goto out;
47822 + }
47823 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47824 + error = -EACCES;
47825 + goto out;
47826 + }
47827 audit_inode(name, dir, 0);
47828 goto finish_open;
47829 }
47830 @@ -2780,7 +2870,7 @@ retry_lookup:
47831 */
47832 }
47833 mutex_lock(&dir->d_inode->i_mutex);
47834 - error = lookup_open(nd, path, file, op, got_write, opened);
47835 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47836 mutex_unlock(&dir->d_inode->i_mutex);
47837
47838 if (error <= 0) {
47839 @@ -2804,11 +2894,28 @@ retry_lookup:
47840 goto finish_open_created;
47841 }
47842
47843 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47844 + error = -ENOENT;
47845 + goto exit_dput;
47846 + }
47847 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47848 + error = -EACCES;
47849 + goto exit_dput;
47850 + }
47851 +
47852 /*
47853 * create/update audit record if it already exists.
47854 */
47855 - if (path->dentry->d_inode)
47856 + if (path->dentry->d_inode) {
47857 + /* only check if O_CREAT is specified, all other checks need to go
47858 + into may_open */
47859 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47860 + error = -EACCES;
47861 + goto exit_dput;
47862 + }
47863 +
47864 audit_inode(name, path->dentry, 0);
47865 + }
47866
47867 /*
47868 * If atomic_open() acquired write access it is dropped now due to
47869 @@ -2849,6 +2956,11 @@ finish_lookup:
47870 }
47871 }
47872 BUG_ON(inode != path->dentry->d_inode);
47873 + /* if we're resolving a symlink to another symlink */
47874 + if (link && gr_handle_symlink_owner(link, inode)) {
47875 + error = -EACCES;
47876 + goto out;
47877 + }
47878 return 1;
47879 }
47880
47881 @@ -2858,7 +2970,6 @@ finish_lookup:
47882 save_parent.dentry = nd->path.dentry;
47883 save_parent.mnt = mntget(path->mnt);
47884 nd->path.dentry = path->dentry;
47885 -
47886 }
47887 nd->inode = inode;
47888 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47889 @@ -2867,6 +2978,22 @@ finish_lookup:
47890 path_put(&save_parent);
47891 return error;
47892 }
47893 +
47894 +#ifdef CONFIG_GRKERNSEC
47895 + if (nd->flags & LOOKUP_RCU) {
47896 + error = -ECHILD;
47897 + goto out;
47898 + }
47899 +#endif
47900 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47901 + error = -ENOENT;
47902 + goto out;
47903 + }
47904 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47905 + error = -EACCES;
47906 + goto out;
47907 + }
47908 +
47909 error = -EISDIR;
47910 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47911 goto out;
47912 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
47913 if (unlikely(error))
47914 goto out;
47915
47916 - error = do_last(nd, &path, file, op, &opened, pathname);
47917 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47918 while (unlikely(error > 0)) { /* trailing symlink */
47919 struct path link = path;
47920 void *cookie;
47921 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
47922 error = follow_link(&link, nd, &cookie);
47923 if (unlikely(error))
47924 break;
47925 - error = do_last(nd, &path, file, op, &opened, pathname);
47926 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47927 put_link(nd, &link, cookie);
47928 }
47929 out:
47930 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47931 goto unlock;
47932
47933 error = -EEXIST;
47934 - if (dentry->d_inode)
47935 + if (dentry->d_inode) {
47936 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47937 + error = -ENOENT;
47938 + }
47939 goto fail;
47940 + }
47941 /*
47942 * Special case - lookup gave negative, but... we had foo/bar/
47943 * From the vfs_mknod() POV we just have a negative dentry -
47944 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47945 }
47946 EXPORT_SYMBOL(user_path_create);
47947
47948 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
47949 +{
47950 + struct filename *tmp = getname(pathname);
47951 + struct dentry *res;
47952 + if (IS_ERR(tmp))
47953 + return ERR_CAST(tmp);
47954 + res = kern_path_create(dfd, tmp->name, path, is_dir);
47955 + if (IS_ERR(res))
47956 + putname(tmp);
47957 + else
47958 + *to = tmp;
47959 + return res;
47960 +}
47961 +
47962 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47963 {
47964 int error = may_create(dir, dentry);
47965 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47966
47967 if (!IS_POSIXACL(path.dentry->d_inode))
47968 mode &= ~current_umask();
47969 +
47970 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47971 + error = -EPERM;
47972 + goto out;
47973 + }
47974 +
47975 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47976 + error = -EACCES;
47977 + goto out;
47978 + }
47979 +
47980 error = security_path_mknod(&path, dentry, mode, dev);
47981 if (error)
47982 goto out;
47983 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47984 break;
47985 }
47986 out:
47987 + if (!error)
47988 + gr_handle_create(dentry, path.mnt);
47989 done_path_create(&path, dentry);
47990 return error;
47991 }
47992 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47993
47994 if (!IS_POSIXACL(path.dentry->d_inode))
47995 mode &= ~current_umask();
47996 +
47997 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47998 + error = -EACCES;
47999 + goto out;
48000 + }
48001 +
48002 error = security_path_mkdir(&path, dentry, mode);
48003 if (!error)
48004 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48005 + if (!error)
48006 + gr_handle_create(dentry, path.mnt);
48007 +out:
48008 done_path_create(&path, dentry);
48009 return error;
48010 }
48011 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48012 struct filename *name;
48013 struct dentry *dentry;
48014 struct nameidata nd;
48015 + ino_t saved_ino = 0;
48016 + dev_t saved_dev = 0;
48017
48018 name = user_path_parent(dfd, pathname, &nd);
48019 if (IS_ERR(name))
48020 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48021 error = -ENOENT;
48022 goto exit3;
48023 }
48024 +
48025 + saved_ino = dentry->d_inode->i_ino;
48026 + saved_dev = gr_get_dev_from_dentry(dentry);
48027 +
48028 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48029 + error = -EACCES;
48030 + goto exit3;
48031 + }
48032 +
48033 error = security_path_rmdir(&nd.path, dentry);
48034 if (error)
48035 goto exit3;
48036 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48037 + if (!error && (saved_dev || saved_ino))
48038 + gr_handle_delete(saved_ino, saved_dev);
48039 exit3:
48040 dput(dentry);
48041 exit2:
48042 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48043 struct dentry *dentry;
48044 struct nameidata nd;
48045 struct inode *inode = NULL;
48046 + ino_t saved_ino = 0;
48047 + dev_t saved_dev = 0;
48048
48049 name = user_path_parent(dfd, pathname, &nd);
48050 if (IS_ERR(name))
48051 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48052 if (!inode)
48053 goto slashes;
48054 ihold(inode);
48055 +
48056 + if (inode->i_nlink <= 1) {
48057 + saved_ino = inode->i_ino;
48058 + saved_dev = gr_get_dev_from_dentry(dentry);
48059 + }
48060 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48061 + error = -EACCES;
48062 + goto exit2;
48063 + }
48064 +
48065 error = security_path_unlink(&nd.path, dentry);
48066 if (error)
48067 goto exit2;
48068 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48069 + if (!error && (saved_ino || saved_dev))
48070 + gr_handle_delete(saved_ino, saved_dev);
48071 exit2:
48072 dput(dentry);
48073 }
48074 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48075 if (IS_ERR(dentry))
48076 goto out_putname;
48077
48078 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48079 + error = -EACCES;
48080 + goto out;
48081 + }
48082 +
48083 error = security_path_symlink(&path, dentry, from->name);
48084 if (!error)
48085 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
48086 + if (!error)
48087 + gr_handle_create(dentry, path.mnt);
48088 +out:
48089 done_path_create(&path, dentry);
48090 out_putname:
48091 putname(from);
48092 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48093 {
48094 struct dentry *new_dentry;
48095 struct path old_path, new_path;
48096 + struct filename *to = NULL;
48097 int how = 0;
48098 int error;
48099
48100 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48101 if (error)
48102 return error;
48103
48104 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48105 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48106 error = PTR_ERR(new_dentry);
48107 if (IS_ERR(new_dentry))
48108 goto out;
48109 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48110 error = may_linkat(&old_path);
48111 if (unlikely(error))
48112 goto out_dput;
48113 +
48114 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48115 + old_path.dentry->d_inode,
48116 + old_path.dentry->d_inode->i_mode, to)) {
48117 + error = -EACCES;
48118 + goto out_dput;
48119 + }
48120 +
48121 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48122 + old_path.dentry, old_path.mnt, to)) {
48123 + error = -EACCES;
48124 + goto out_dput;
48125 + }
48126 +
48127 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48128 if (error)
48129 goto out_dput;
48130 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48131 + if (!error)
48132 + gr_handle_create(new_dentry, new_path.mnt);
48133 out_dput:
48134 + putname(to);
48135 done_path_create(&new_path, new_dentry);
48136 out:
48137 path_put(&old_path);
48138 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48139 if (new_dentry == trap)
48140 goto exit5;
48141
48142 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48143 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48144 + to);
48145 + if (error)
48146 + goto exit5;
48147 +
48148 error = security_path_rename(&oldnd.path, old_dentry,
48149 &newnd.path, new_dentry);
48150 if (error)
48151 goto exit5;
48152 error = vfs_rename(old_dir->d_inode, old_dentry,
48153 new_dir->d_inode, new_dentry);
48154 + if (!error)
48155 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48156 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48157 exit5:
48158 dput(new_dentry);
48159 exit4:
48160 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48161
48162 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48163 {
48164 + char tmpbuf[64];
48165 + const char *newlink;
48166 int len;
48167
48168 len = PTR_ERR(link);
48169 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48170 len = strlen(link);
48171 if (len > (unsigned) buflen)
48172 len = buflen;
48173 - if (copy_to_user(buffer, link, len))
48174 +
48175 + if (len < sizeof(tmpbuf)) {
48176 + memcpy(tmpbuf, link, len);
48177 + newlink = tmpbuf;
48178 + } else
48179 + newlink = link;
48180 +
48181 + if (copy_to_user(buffer, newlink, len))
48182 len = -EFAULT;
48183 out:
48184 return len;
48185 diff --git a/fs/namespace.c b/fs/namespace.c
48186 index 2496062..e26f6d6 100644
48187 --- a/fs/namespace.c
48188 +++ b/fs/namespace.c
48189 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48190 if (!(sb->s_flags & MS_RDONLY))
48191 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48192 up_write(&sb->s_umount);
48193 +
48194 + gr_log_remount(mnt->mnt_devname, retval);
48195 +
48196 return retval;
48197 }
48198
48199 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48200 br_write_unlock(&vfsmount_lock);
48201 up_write(&namespace_sem);
48202 release_mounts(&umount_list);
48203 +
48204 + gr_log_unmount(mnt->mnt_devname, retval);
48205 +
48206 return retval;
48207 }
48208
48209 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
48210 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48211 MS_STRICTATIME);
48212
48213 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48214 + retval = -EPERM;
48215 + goto dput_out;
48216 + }
48217 +
48218 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48219 + retval = -EPERM;
48220 + goto dput_out;
48221 + }
48222 +
48223 if (flags & MS_REMOUNT)
48224 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48225 data_page);
48226 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
48227 dev_name, data_page);
48228 dput_out:
48229 path_put(&path);
48230 +
48231 + gr_log_mount(dev_name, dir_name, retval);
48232 +
48233 return retval;
48234 }
48235
48236 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48237 if (error)
48238 goto out2;
48239
48240 + if (gr_handle_chroot_pivot()) {
48241 + error = -EPERM;
48242 + goto out2;
48243 + }
48244 +
48245 get_fs_root(current->fs, &root);
48246 error = lock_mount(&old);
48247 if (error)
48248 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48249 index 6fa01ae..2790820 100644
48250 --- a/fs/nfs/inode.c
48251 +++ b/fs/nfs/inode.c
48252 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48253 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48254 }
48255
48256 -static atomic_long_t nfs_attr_generation_counter;
48257 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48258
48259 static unsigned long nfs_read_attr_generation_counter(void)
48260 {
48261 - return atomic_long_read(&nfs_attr_generation_counter);
48262 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48263 }
48264
48265 unsigned long nfs_inc_attr_generation_counter(void)
48266 {
48267 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48268 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48269 }
48270
48271 void nfs_fattr_init(struct nfs_fattr *fattr)
48272 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48273 index c120b48..8ac4140 100644
48274 --- a/fs/nfsd/vfs.c
48275 +++ b/fs/nfsd/vfs.c
48276 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48277 } else {
48278 oldfs = get_fs();
48279 set_fs(KERNEL_DS);
48280 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48281 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48282 set_fs(oldfs);
48283 }
48284
48285 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48286
48287 /* Write the data. */
48288 oldfs = get_fs(); set_fs(KERNEL_DS);
48289 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48290 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48291 set_fs(oldfs);
48292 if (host_err < 0)
48293 goto out_nfserr;
48294 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48295 */
48296
48297 oldfs = get_fs(); set_fs(KERNEL_DS);
48298 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
48299 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48300 set_fs(oldfs);
48301
48302 if (host_err < 0)
48303 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48304 index 6fcaeb8..9d16d04 100644
48305 --- a/fs/notify/fanotify/fanotify_user.c
48306 +++ b/fs/notify/fanotify/fanotify_user.c
48307 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48308
48309 fd = fanotify_event_metadata.fd;
48310 ret = -EFAULT;
48311 - if (copy_to_user(buf, &fanotify_event_metadata,
48312 - fanotify_event_metadata.event_len))
48313 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48314 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
48315 goto out_close_fd;
48316
48317 ret = prepare_for_access_response(group, event, fd);
48318 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48319 index c887b13..0fdf472 100644
48320 --- a/fs/notify/notification.c
48321 +++ b/fs/notify/notification.c
48322 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48323 * get set to 0 so it will never get 'freed'
48324 */
48325 static struct fsnotify_event *q_overflow_event;
48326 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48327 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48328
48329 /**
48330 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48331 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48332 */
48333 u32 fsnotify_get_cookie(void)
48334 {
48335 - return atomic_inc_return(&fsnotify_sync_cookie);
48336 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48337 }
48338 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48339
48340 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48341 index 99e3610..02c1068 100644
48342 --- a/fs/ntfs/dir.c
48343 +++ b/fs/ntfs/dir.c
48344 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48345 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48346 ~(s64)(ndir->itype.index.block_size - 1)));
48347 /* Bounds checks. */
48348 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48349 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48350 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48351 "inode 0x%lx or driver bug.", vdir->i_ino);
48352 goto err_out;
48353 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48354 index 1ecf464..e1ff8bf 100644
48355 --- a/fs/ntfs/file.c
48356 +++ b/fs/ntfs/file.c
48357 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48358 #endif /* NTFS_RW */
48359 };
48360
48361 -const struct file_operations ntfs_empty_file_ops = {};
48362 +const struct file_operations ntfs_empty_file_ops __read_only;
48363
48364 -const struct inode_operations ntfs_empty_inode_ops = {};
48365 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48366 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48367 index a9f78c7..ed8a381 100644
48368 --- a/fs/ocfs2/localalloc.c
48369 +++ b/fs/ocfs2/localalloc.c
48370 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48371 goto bail;
48372 }
48373
48374 - atomic_inc(&osb->alloc_stats.moves);
48375 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48376
48377 bail:
48378 if (handle)
48379 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48380 index d355e6e..578d905 100644
48381 --- a/fs/ocfs2/ocfs2.h
48382 +++ b/fs/ocfs2/ocfs2.h
48383 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48384
48385 struct ocfs2_alloc_stats
48386 {
48387 - atomic_t moves;
48388 - atomic_t local_data;
48389 - atomic_t bitmap_data;
48390 - atomic_t bg_allocs;
48391 - atomic_t bg_extends;
48392 + atomic_unchecked_t moves;
48393 + atomic_unchecked_t local_data;
48394 + atomic_unchecked_t bitmap_data;
48395 + atomic_unchecked_t bg_allocs;
48396 + atomic_unchecked_t bg_extends;
48397 };
48398
48399 enum ocfs2_local_alloc_state
48400 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48401 index f169da4..9112253 100644
48402 --- a/fs/ocfs2/suballoc.c
48403 +++ b/fs/ocfs2/suballoc.c
48404 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48405 mlog_errno(status);
48406 goto bail;
48407 }
48408 - atomic_inc(&osb->alloc_stats.bg_extends);
48409 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48410
48411 /* You should never ask for this much metadata */
48412 BUG_ON(bits_wanted >
48413 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48414 mlog_errno(status);
48415 goto bail;
48416 }
48417 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48418 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48419
48420 *suballoc_loc = res.sr_bg_blkno;
48421 *suballoc_bit_start = res.sr_bit_offset;
48422 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48423 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48424 res->sr_bits);
48425
48426 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48427 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48428
48429 BUG_ON(res->sr_bits != 1);
48430
48431 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48432 mlog_errno(status);
48433 goto bail;
48434 }
48435 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48436 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48437
48438 BUG_ON(res.sr_bits != 1);
48439
48440 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48441 cluster_start,
48442 num_clusters);
48443 if (!status)
48444 - atomic_inc(&osb->alloc_stats.local_data);
48445 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48446 } else {
48447 if (min_clusters > (osb->bitmap_cpg - 1)) {
48448 /* The only paths asking for contiguousness
48449 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48450 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48451 res.sr_bg_blkno,
48452 res.sr_bit_offset);
48453 - atomic_inc(&osb->alloc_stats.bitmap_data);
48454 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48455 *num_clusters = res.sr_bits;
48456 }
48457 }
48458 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48459 index 0e91ec2..f4b3fc6 100644
48460 --- a/fs/ocfs2/super.c
48461 +++ b/fs/ocfs2/super.c
48462 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48463 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48464 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48465 "Stats",
48466 - atomic_read(&osb->alloc_stats.bitmap_data),
48467 - atomic_read(&osb->alloc_stats.local_data),
48468 - atomic_read(&osb->alloc_stats.bg_allocs),
48469 - atomic_read(&osb->alloc_stats.moves),
48470 - atomic_read(&osb->alloc_stats.bg_extends));
48471 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48472 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48473 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48474 + atomic_read_unchecked(&osb->alloc_stats.moves),
48475 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48476
48477 out += snprintf(buf + out, len - out,
48478 "%10s => State: %u Descriptor: %llu Size: %u bits "
48479 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48480 spin_lock_init(&osb->osb_xattr_lock);
48481 ocfs2_init_steal_slots(osb);
48482
48483 - atomic_set(&osb->alloc_stats.moves, 0);
48484 - atomic_set(&osb->alloc_stats.local_data, 0);
48485 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48486 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48487 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48488 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48489 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48490 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48491 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48492 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48493
48494 /* Copy the blockcheck stats from the superblock probe */
48495 osb->osb_ecc_stats = *stats;
48496 diff --git a/fs/open.c b/fs/open.c
48497 index 59071f5..c6229a0 100644
48498 --- a/fs/open.c
48499 +++ b/fs/open.c
48500 @@ -31,6 +31,8 @@
48501 #include <linux/ima.h>
48502 #include <linux/dnotify.h>
48503
48504 +#define CREATE_TRACE_POINTS
48505 +#include <trace/events/fs.h>
48506 #include "internal.h"
48507
48508 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48509 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48510 error = locks_verify_truncate(inode, NULL, length);
48511 if (!error)
48512 error = security_path_truncate(&path);
48513 +
48514 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48515 + error = -EACCES;
48516 +
48517 if (!error)
48518 error = do_truncate(path.dentry, length, 0, NULL);
48519
48520 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48521 if (__mnt_is_readonly(path.mnt))
48522 res = -EROFS;
48523
48524 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48525 + res = -EACCES;
48526 +
48527 out_path_release:
48528 path_put(&path);
48529 out:
48530 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48531 if (error)
48532 goto dput_and_out;
48533
48534 + gr_log_chdir(path.dentry, path.mnt);
48535 +
48536 set_fs_pwd(current->fs, &path);
48537
48538 dput_and_out:
48539 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48540 goto out_putf;
48541
48542 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48543 +
48544 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
48545 + error = -EPERM;
48546 +
48547 + if (!error)
48548 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
48549 +
48550 if (!error)
48551 set_fs_pwd(current->fs, &f.file->f_path);
48552 out_putf:
48553 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48554 if (error)
48555 goto dput_and_out;
48556
48557 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48558 + goto dput_and_out;
48559 +
48560 set_fs_root(current->fs, &path);
48561 +
48562 + gr_handle_chroot_chdir(&path);
48563 +
48564 error = 0;
48565 dput_and_out:
48566 path_put(&path);
48567 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
48568 if (error)
48569 return error;
48570 mutex_lock(&inode->i_mutex);
48571 +
48572 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48573 + error = -EACCES;
48574 + goto out_unlock;
48575 + }
48576 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48577 + error = -EACCES;
48578 + goto out_unlock;
48579 + }
48580 +
48581 error = security_path_chmod(path, mode);
48582 if (error)
48583 goto out_unlock;
48584 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48585 uid = make_kuid(current_user_ns(), user);
48586 gid = make_kgid(current_user_ns(), group);
48587
48588 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48589 + return -EACCES;
48590 +
48591 newattrs.ia_valid = ATTR_CTIME;
48592 if (user != (uid_t) -1) {
48593 if (!uid_valid(uid))
48594 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48595 } else {
48596 fsnotify_open(f);
48597 fd_install(fd, f);
48598 + trace_do_sys_open(tmp->name, flags, mode);
48599 }
48600 }
48601 putname(tmp);
48602 diff --git a/fs/pipe.c b/fs/pipe.c
48603 index bd3479d..fb92c4d 100644
48604 --- a/fs/pipe.c
48605 +++ b/fs/pipe.c
48606 @@ -438,9 +438,9 @@ redo:
48607 }
48608 if (bufs) /* More to do? */
48609 continue;
48610 - if (!pipe->writers)
48611 + if (!atomic_read(&pipe->writers))
48612 break;
48613 - if (!pipe->waiting_writers) {
48614 + if (!atomic_read(&pipe->waiting_writers)) {
48615 /* syscall merging: Usually we must not sleep
48616 * if O_NONBLOCK is set, or if we got some data.
48617 * But if a writer sleeps in kernel space, then
48618 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48619 mutex_lock(&inode->i_mutex);
48620 pipe = inode->i_pipe;
48621
48622 - if (!pipe->readers) {
48623 + if (!atomic_read(&pipe->readers)) {
48624 send_sig(SIGPIPE, current, 0);
48625 ret = -EPIPE;
48626 goto out;
48627 @@ -553,7 +553,7 @@ redo1:
48628 for (;;) {
48629 int bufs;
48630
48631 - if (!pipe->readers) {
48632 + if (!atomic_read(&pipe->readers)) {
48633 send_sig(SIGPIPE, current, 0);
48634 if (!ret)
48635 ret = -EPIPE;
48636 @@ -644,9 +644,9 @@ redo2:
48637 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48638 do_wakeup = 0;
48639 }
48640 - pipe->waiting_writers++;
48641 + atomic_inc(&pipe->waiting_writers);
48642 pipe_wait(pipe);
48643 - pipe->waiting_writers--;
48644 + atomic_dec(&pipe->waiting_writers);
48645 }
48646 out:
48647 mutex_unlock(&inode->i_mutex);
48648 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48649 mask = 0;
48650 if (filp->f_mode & FMODE_READ) {
48651 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48652 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48653 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48654 mask |= POLLHUP;
48655 }
48656
48657 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48658 * Most Unices do not set POLLERR for FIFOs but on Linux they
48659 * behave exactly like pipes for poll().
48660 */
48661 - if (!pipe->readers)
48662 + if (!atomic_read(&pipe->readers))
48663 mask |= POLLERR;
48664 }
48665
48666 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48667
48668 mutex_lock(&inode->i_mutex);
48669 pipe = inode->i_pipe;
48670 - pipe->readers -= decr;
48671 - pipe->writers -= decw;
48672 + atomic_sub(decr, &pipe->readers);
48673 + atomic_sub(decw, &pipe->writers);
48674
48675 - if (!pipe->readers && !pipe->writers) {
48676 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48677 free_pipe_info(inode);
48678 } else {
48679 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48680 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48681
48682 if (inode->i_pipe) {
48683 ret = 0;
48684 - inode->i_pipe->readers++;
48685 + atomic_inc(&inode->i_pipe->readers);
48686 }
48687
48688 mutex_unlock(&inode->i_mutex);
48689 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48690
48691 if (inode->i_pipe) {
48692 ret = 0;
48693 - inode->i_pipe->writers++;
48694 + atomic_inc(&inode->i_pipe->writers);
48695 }
48696
48697 mutex_unlock(&inode->i_mutex);
48698 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48699 if (inode->i_pipe) {
48700 ret = 0;
48701 if (filp->f_mode & FMODE_READ)
48702 - inode->i_pipe->readers++;
48703 + atomic_inc(&inode->i_pipe->readers);
48704 if (filp->f_mode & FMODE_WRITE)
48705 - inode->i_pipe->writers++;
48706 + atomic_inc(&inode->i_pipe->writers);
48707 }
48708
48709 mutex_unlock(&inode->i_mutex);
48710 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48711 inode->i_pipe = NULL;
48712 }
48713
48714 -static struct vfsmount *pipe_mnt __read_mostly;
48715 +struct vfsmount *pipe_mnt __read_mostly;
48716
48717 /*
48718 * pipefs_dname() is called from d_path().
48719 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48720 goto fail_iput;
48721 inode->i_pipe = pipe;
48722
48723 - pipe->readers = pipe->writers = 1;
48724 + atomic_set(&pipe->readers, 1);
48725 + atomic_set(&pipe->writers, 1);
48726 inode->i_fop = &rdwr_pipefifo_fops;
48727
48728 /*
48729 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48730 index 15af622..0e9f4467 100644
48731 --- a/fs/proc/Kconfig
48732 +++ b/fs/proc/Kconfig
48733 @@ -30,12 +30,12 @@ config PROC_FS
48734
48735 config PROC_KCORE
48736 bool "/proc/kcore support" if !ARM
48737 - depends on PROC_FS && MMU
48738 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48739
48740 config PROC_VMCORE
48741 bool "/proc/vmcore support"
48742 - depends on PROC_FS && CRASH_DUMP
48743 - default y
48744 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48745 + default n
48746 help
48747 Exports the dump image of crashed kernel in ELF format.
48748
48749 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48750 limited in memory.
48751
48752 config PROC_PAGE_MONITOR
48753 - default y
48754 - depends on PROC_FS && MMU
48755 + default n
48756 + depends on PROC_FS && MMU && !GRKERNSEC
48757 bool "Enable /proc page monitoring" if EXPERT
48758 help
48759 Various /proc files exist to monitor process memory utilization:
48760 diff --git a/fs/proc/array.c b/fs/proc/array.c
48761 index c1c207c..01ce725 100644
48762 --- a/fs/proc/array.c
48763 +++ b/fs/proc/array.c
48764 @@ -60,6 +60,7 @@
48765 #include <linux/tty.h>
48766 #include <linux/string.h>
48767 #include <linux/mman.h>
48768 +#include <linux/grsecurity.h>
48769 #include <linux/proc_fs.h>
48770 #include <linux/ioport.h>
48771 #include <linux/uaccess.h>
48772 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48773 seq_putc(m, '\n');
48774 }
48775
48776 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48777 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48778 +{
48779 + if (p->mm)
48780 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48781 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48782 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48783 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48784 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48785 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48786 + else
48787 + seq_printf(m, "PaX:\t-----\n");
48788 +}
48789 +#endif
48790 +
48791 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48792 struct pid *pid, struct task_struct *task)
48793 {
48794 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48795 task_cpus_allowed(m, task);
48796 cpuset_task_status_allowed(m, task);
48797 task_context_switch_counts(m, task);
48798 +
48799 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48800 + task_pax(m, task);
48801 +#endif
48802 +
48803 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48804 + task_grsec_rbac(m, task);
48805 +#endif
48806 +
48807 return 0;
48808 }
48809
48810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48811 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48812 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48813 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48814 +#endif
48815 +
48816 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48817 struct pid *pid, struct task_struct *task, int whole)
48818 {
48819 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48820 char tcomm[sizeof(task->comm)];
48821 unsigned long flags;
48822
48823 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48824 + if (current->exec_id != m->exec_id) {
48825 + gr_log_badprocpid("stat");
48826 + return 0;
48827 + }
48828 +#endif
48829 +
48830 state = *get_task_state(task);
48831 vsize = eip = esp = 0;
48832 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48833 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48834 gtime = task->gtime;
48835 }
48836
48837 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48838 + if (PAX_RAND_FLAGS(mm)) {
48839 + eip = 0;
48840 + esp = 0;
48841 + wchan = 0;
48842 + }
48843 +#endif
48844 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48845 + wchan = 0;
48846 + eip =0;
48847 + esp =0;
48848 +#endif
48849 +
48850 /* scale priority and nice values from timeslices to -20..20 */
48851 /* to make it look like a "normal" Unix priority/nice value */
48852 priority = task_prio(task);
48853 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48854 seq_put_decimal_ull(m, ' ', vsize);
48855 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48856 seq_put_decimal_ull(m, ' ', rsslim);
48857 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48858 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48859 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48860 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48861 +#else
48862 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48863 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48864 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48865 +#endif
48866 seq_put_decimal_ull(m, ' ', esp);
48867 seq_put_decimal_ull(m, ' ', eip);
48868 /* The signal information here is obsolete.
48869 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48870 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48871 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48872
48873 - if (mm && permitted) {
48874 + if (mm && permitted
48875 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48876 + && !PAX_RAND_FLAGS(mm)
48877 +#endif
48878 + ) {
48879 seq_put_decimal_ull(m, ' ', mm->start_data);
48880 seq_put_decimal_ull(m, ' ', mm->end_data);
48881 seq_put_decimal_ull(m, ' ', mm->start_brk);
48882 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48883 struct pid *pid, struct task_struct *task)
48884 {
48885 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48886 - struct mm_struct *mm = get_task_mm(task);
48887 + struct mm_struct *mm;
48888
48889 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48890 + if (current->exec_id != m->exec_id) {
48891 + gr_log_badprocpid("statm");
48892 + return 0;
48893 + }
48894 +#endif
48895 + mm = get_task_mm(task);
48896 if (mm) {
48897 size = task_statm(mm, &shared, &text, &data, &resident);
48898 mmput(mm);
48899 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48900 return 0;
48901 }
48902
48903 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48904 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48905 +{
48906 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48907 +}
48908 +#endif
48909 +
48910 #ifdef CONFIG_CHECKPOINT_RESTORE
48911 static struct pid *
48912 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48913 diff --git a/fs/proc/base.c b/fs/proc/base.c
48914 index 9e28356..c485b3c 100644
48915 --- a/fs/proc/base.c
48916 +++ b/fs/proc/base.c
48917 @@ -111,6 +111,14 @@ struct pid_entry {
48918 union proc_op op;
48919 };
48920
48921 +struct getdents_callback {
48922 + struct linux_dirent __user * current_dir;
48923 + struct linux_dirent __user * previous;
48924 + struct file * file;
48925 + int count;
48926 + int error;
48927 +};
48928 +
48929 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48930 .name = (NAME), \
48931 .len = sizeof(NAME) - 1, \
48932 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48933 if (!mm->arg_end)
48934 goto out_mm; /* Shh! No looking before we're done */
48935
48936 + if (gr_acl_handle_procpidmem(task))
48937 + goto out_mm;
48938 +
48939 len = mm->arg_end - mm->arg_start;
48940
48941 if (len > PAGE_SIZE)
48942 @@ -235,12 +246,28 @@ out:
48943 return res;
48944 }
48945
48946 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48947 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48948 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48949 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48950 +#endif
48951 +
48952 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48953 {
48954 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48955 int res = PTR_ERR(mm);
48956 if (mm && !IS_ERR(mm)) {
48957 unsigned int nwords = 0;
48958 +
48959 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48960 + /* allow if we're currently ptracing this task */
48961 + if (PAX_RAND_FLAGS(mm) &&
48962 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48963 + mmput(mm);
48964 + return 0;
48965 + }
48966 +#endif
48967 +
48968 do {
48969 nwords += 2;
48970 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48971 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48972 }
48973
48974
48975 -#ifdef CONFIG_KALLSYMS
48976 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48977 /*
48978 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48979 * Returns the resolved symbol. If that fails, simply return the address.
48980 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
48981 mutex_unlock(&task->signal->cred_guard_mutex);
48982 }
48983
48984 -#ifdef CONFIG_STACKTRACE
48985 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48986
48987 #define MAX_STACK_TRACE_DEPTH 64
48988
48989 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48990 return count;
48991 }
48992
48993 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48994 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48995 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48996 {
48997 long nr;
48998 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48999 /************************************************************************/
49000
49001 /* permission checks */
49002 -static int proc_fd_access_allowed(struct inode *inode)
49003 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49004 {
49005 struct task_struct *task;
49006 int allowed = 0;
49007 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49008 */
49009 task = get_proc_task(inode);
49010 if (task) {
49011 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49012 + if (log)
49013 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49014 + else
49015 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49016 put_task_struct(task);
49017 }
49018 return allowed;
49019 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49020 struct task_struct *task,
49021 int hide_pid_min)
49022 {
49023 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49024 + return false;
49025 +
49026 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49027 + rcu_read_lock();
49028 + {
49029 + const struct cred *tmpcred = current_cred();
49030 + const struct cred *cred = __task_cred(task);
49031 +
49032 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49033 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49034 + || in_group_p(grsec_proc_gid)
49035 +#endif
49036 + ) {
49037 + rcu_read_unlock();
49038 + return true;
49039 + }
49040 + }
49041 + rcu_read_unlock();
49042 +
49043 + if (!pid->hide_pid)
49044 + return false;
49045 +#endif
49046 +
49047 if (pid->hide_pid < hide_pid_min)
49048 return true;
49049 if (in_group_p(pid->pid_gid))
49050 return true;
49051 +
49052 return ptrace_may_access(task, PTRACE_MODE_READ);
49053 }
49054
49055 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49056 put_task_struct(task);
49057
49058 if (!has_perms) {
49059 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49060 + {
49061 +#else
49062 if (pid->hide_pid == 2) {
49063 +#endif
49064 /*
49065 * Let's make getdents(), stat(), and open()
49066 * consistent with each other. If a process
49067 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49068 if (!task)
49069 return -ESRCH;
49070
49071 + if (gr_acl_handle_procpidmem(task)) {
49072 + put_task_struct(task);
49073 + return -EPERM;
49074 + }
49075 +
49076 mm = mm_access(task, mode);
49077 put_task_struct(task);
49078
49079 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49080
49081 file->private_data = mm;
49082
49083 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49084 + file->f_version = current->exec_id;
49085 +#endif
49086 +
49087 return 0;
49088 }
49089
49090 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49091 ssize_t copied;
49092 char *page;
49093
49094 +#ifdef CONFIG_GRKERNSEC
49095 + if (write)
49096 + return -EPERM;
49097 +#endif
49098 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49099 + if (file->f_version != current->exec_id) {
49100 + gr_log_badprocpid("mem");
49101 + return 0;
49102 + }
49103 +#endif
49104 +
49105 if (!mm)
49106 return 0;
49107
49108 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49109 if (!mm)
49110 return 0;
49111
49112 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49113 + if (file->f_version != current->exec_id) {
49114 + gr_log_badprocpid("environ");
49115 + return 0;
49116 + }
49117 +#endif
49118 +
49119 page = (char *)__get_free_page(GFP_TEMPORARY);
49120 if (!page)
49121 return -ENOMEM;
49122 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49123 int error = -EACCES;
49124
49125 /* Are we allowed to snoop on the tasks file descriptors? */
49126 - if (!proc_fd_access_allowed(inode))
49127 + if (!proc_fd_access_allowed(inode, 0))
49128 goto out;
49129
49130 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49131 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49132 struct path path;
49133
49134 /* Are we allowed to snoop on the tasks file descriptors? */
49135 - if (!proc_fd_access_allowed(inode))
49136 - goto out;
49137 + /* logging this is needed for learning on chromium to work properly,
49138 + but we don't want to flood the logs from 'ps' which does a readlink
49139 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49140 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49141 + */
49142 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49143 + if (!proc_fd_access_allowed(inode,0))
49144 + goto out;
49145 + } else {
49146 + if (!proc_fd_access_allowed(inode,1))
49147 + goto out;
49148 + }
49149
49150 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49151 if (error)
49152 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49153 rcu_read_lock();
49154 cred = __task_cred(task);
49155 inode->i_uid = cred->euid;
49156 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49157 + inode->i_gid = grsec_proc_gid;
49158 +#else
49159 inode->i_gid = cred->egid;
49160 +#endif
49161 rcu_read_unlock();
49162 }
49163 security_task_to_inode(task, inode);
49164 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49165 return -ENOENT;
49166 }
49167 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49168 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49169 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49170 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49171 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49172 +#endif
49173 task_dumpable(task)) {
49174 cred = __task_cred(task);
49175 stat->uid = cred->euid;
49176 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49177 + stat->gid = grsec_proc_gid;
49178 +#else
49179 stat->gid = cred->egid;
49180 +#endif
49181 }
49182 }
49183 rcu_read_unlock();
49184 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49185
49186 if (task) {
49187 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49188 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49189 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49190 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49191 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49192 +#endif
49193 task_dumpable(task)) {
49194 rcu_read_lock();
49195 cred = __task_cred(task);
49196 inode->i_uid = cred->euid;
49197 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49198 + inode->i_gid = grsec_proc_gid;
49199 +#else
49200 inode->i_gid = cred->egid;
49201 +#endif
49202 rcu_read_unlock();
49203 } else {
49204 inode->i_uid = GLOBAL_ROOT_UID;
49205 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49206 if (!task)
49207 goto out_no_task;
49208
49209 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49210 + goto out;
49211 +
49212 /*
49213 * Yes, it does not scale. And it should not. Don't add
49214 * new entries into /proc/<tgid>/ without very good reasons.
49215 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
49216 if (!task)
49217 goto out_no_task;
49218
49219 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49220 + goto out;
49221 +
49222 ret = 0;
49223 i = filp->f_pos;
49224 switch (i) {
49225 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49226 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49227 void *cookie)
49228 {
49229 - char *s = nd_get_link(nd);
49230 + const char *s = nd_get_link(nd);
49231 if (!IS_ERR(s))
49232 kfree(s);
49233 }
49234 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49235 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49236 #endif
49237 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49238 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49239 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49240 INF("syscall", S_IRUGO, proc_pid_syscall),
49241 #endif
49242 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49243 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49244 #ifdef CONFIG_SECURITY
49245 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49246 #endif
49247 -#ifdef CONFIG_KALLSYMS
49248 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49249 INF("wchan", S_IRUGO, proc_pid_wchan),
49250 #endif
49251 -#ifdef CONFIG_STACKTRACE
49252 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49253 ONE("stack", S_IRUGO, proc_pid_stack),
49254 #endif
49255 #ifdef CONFIG_SCHEDSTATS
49256 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49257 #ifdef CONFIG_HARDWALL
49258 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49259 #endif
49260 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49261 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49262 +#endif
49263 #ifdef CONFIG_USER_NS
49264 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49265 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49266 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49267 if (!inode)
49268 goto out;
49269
49270 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49271 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49272 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49273 + inode->i_gid = grsec_proc_gid;
49274 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49275 +#else
49276 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49277 +#endif
49278 inode->i_op = &proc_tgid_base_inode_operations;
49279 inode->i_fop = &proc_tgid_base_operations;
49280 inode->i_flags|=S_IMMUTABLE;
49281 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49282 if (!task)
49283 goto out;
49284
49285 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49286 + goto out_put_task;
49287 +
49288 result = proc_pid_instantiate(dir, dentry, task, NULL);
49289 +out_put_task:
49290 put_task_struct(task);
49291 out:
49292 return result;
49293 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49294 static int fake_filldir(void *buf, const char *name, int namelen,
49295 loff_t offset, u64 ino, unsigned d_type)
49296 {
49297 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49298 + __buf->error = -EINVAL;
49299 return 0;
49300 }
49301
49302 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
49303 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49304 #endif
49305 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49306 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49307 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49308 INF("syscall", S_IRUGO, proc_pid_syscall),
49309 #endif
49310 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49311 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
49312 #ifdef CONFIG_SECURITY
49313 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49314 #endif
49315 -#ifdef CONFIG_KALLSYMS
49316 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49317 INF("wchan", S_IRUGO, proc_pid_wchan),
49318 #endif
49319 -#ifdef CONFIG_STACKTRACE
49320 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49321 ONE("stack", S_IRUGO, proc_pid_stack),
49322 #endif
49323 #ifdef CONFIG_SCHEDSTATS
49324 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49325 index 82676e3..5f8518a 100644
49326 --- a/fs/proc/cmdline.c
49327 +++ b/fs/proc/cmdline.c
49328 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49329
49330 static int __init proc_cmdline_init(void)
49331 {
49332 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49333 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49334 +#else
49335 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49336 +#endif
49337 return 0;
49338 }
49339 module_init(proc_cmdline_init);
49340 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49341 index b143471..bb105e5 100644
49342 --- a/fs/proc/devices.c
49343 +++ b/fs/proc/devices.c
49344 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49345
49346 static int __init proc_devices_init(void)
49347 {
49348 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49349 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49350 +#else
49351 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49352 +#endif
49353 return 0;
49354 }
49355 module_init(proc_devices_init);
49356 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
49357 index f28a875..c467953 100644
49358 --- a/fs/proc/fd.c
49359 +++ b/fs/proc/fd.c
49360 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
49361 if (!task)
49362 return -ENOENT;
49363
49364 - files = get_files_struct(task);
49365 + if (!gr_acl_handle_procpidmem(task))
49366 + files = get_files_struct(task);
49367 put_task_struct(task);
49368
49369 if (files) {
49370 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
49371 */
49372 int proc_fd_permission(struct inode *inode, int mask)
49373 {
49374 + struct task_struct *task;
49375 int rv = generic_permission(inode, mask);
49376 - if (rv == 0)
49377 - return 0;
49378 +
49379 if (task_pid(current) == proc_pid(inode))
49380 rv = 0;
49381 +
49382 + task = get_proc_task(inode);
49383 + if (task == NULL)
49384 + return rv;
49385 +
49386 + if (gr_acl_handle_procpidmem(task))
49387 + rv = -EACCES;
49388 +
49389 + put_task_struct(task);
49390 +
49391 return rv;
49392 }
49393
49394 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49395 index 3b22bbd..895b58c 100644
49396 --- a/fs/proc/inode.c
49397 +++ b/fs/proc/inode.c
49398 @@ -21,11 +21,17 @@
49399 #include <linux/seq_file.h>
49400 #include <linux/slab.h>
49401 #include <linux/mount.h>
49402 +#include <linux/grsecurity.h>
49403
49404 #include <asm/uaccess.h>
49405
49406 #include "internal.h"
49407
49408 +#ifdef CONFIG_PROC_SYSCTL
49409 +extern const struct inode_operations proc_sys_inode_operations;
49410 +extern const struct inode_operations proc_sys_dir_operations;
49411 +#endif
49412 +
49413 static void proc_evict_inode(struct inode *inode)
49414 {
49415 struct proc_dir_entry *de;
49416 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49417 ns_ops = PROC_I(inode)->ns_ops;
49418 if (ns_ops && ns_ops->put)
49419 ns_ops->put(PROC_I(inode)->ns);
49420 +
49421 +#ifdef CONFIG_PROC_SYSCTL
49422 + if (inode->i_op == &proc_sys_inode_operations ||
49423 + inode->i_op == &proc_sys_dir_operations)
49424 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49425 +#endif
49426 +
49427 }
49428
49429 static struct kmem_cache * proc_inode_cachep;
49430 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49431 if (de->mode) {
49432 inode->i_mode = de->mode;
49433 inode->i_uid = de->uid;
49434 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49435 + inode->i_gid = grsec_proc_gid;
49436 +#else
49437 inode->i_gid = de->gid;
49438 +#endif
49439 }
49440 if (de->size)
49441 inode->i_size = de->size;
49442 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49443 index 43973b0..a20e704 100644
49444 --- a/fs/proc/internal.h
49445 +++ b/fs/proc/internal.h
49446 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49447 struct pid *pid, struct task_struct *task);
49448 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49449 struct pid *pid, struct task_struct *task);
49450 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49451 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49452 +#endif
49453 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49454
49455 extern const struct file_operations proc_tid_children_operations;
49456 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49457 index 86c67ee..cdca321 100644
49458 --- a/fs/proc/kcore.c
49459 +++ b/fs/proc/kcore.c
49460 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49461 * the addresses in the elf_phdr on our list.
49462 */
49463 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49464 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49465 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49466 + if (tsz > buflen)
49467 tsz = buflen;
49468 -
49469 +
49470 while (buflen) {
49471 struct kcore_list *m;
49472
49473 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49474 kfree(elf_buf);
49475 } else {
49476 if (kern_addr_valid(start)) {
49477 - unsigned long n;
49478 + char *elf_buf;
49479 + mm_segment_t oldfs;
49480
49481 - n = copy_to_user(buffer, (char *)start, tsz);
49482 - /*
49483 - * We cannot distinguish between fault on source
49484 - * and fault on destination. When this happens
49485 - * we clear too and hope it will trigger the
49486 - * EFAULT again.
49487 - */
49488 - if (n) {
49489 - if (clear_user(buffer + tsz - n,
49490 - n))
49491 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49492 + if (!elf_buf)
49493 + return -ENOMEM;
49494 + oldfs = get_fs();
49495 + set_fs(KERNEL_DS);
49496 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49497 + set_fs(oldfs);
49498 + if (copy_to_user(buffer, elf_buf, tsz)) {
49499 + kfree(elf_buf);
49500 return -EFAULT;
49501 + }
49502 }
49503 + set_fs(oldfs);
49504 + kfree(elf_buf);
49505 } else {
49506 if (clear_user(buffer, tsz))
49507 return -EFAULT;
49508 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49509
49510 static int open_kcore(struct inode *inode, struct file *filp)
49511 {
49512 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49513 + return -EPERM;
49514 +#endif
49515 if (!capable(CAP_SYS_RAWIO))
49516 return -EPERM;
49517 if (kcore_need_update)
49518 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49519 index 80e4645..53e5fcf 100644
49520 --- a/fs/proc/meminfo.c
49521 +++ b/fs/proc/meminfo.c
49522 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49523 vmi.used >> 10,
49524 vmi.largest_chunk >> 10
49525 #ifdef CONFIG_MEMORY_FAILURE
49526 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49527 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49528 #endif
49529 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49530 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49531 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49532 index b1822dd..df622cb 100644
49533 --- a/fs/proc/nommu.c
49534 +++ b/fs/proc/nommu.c
49535 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49536 if (len < 1)
49537 len = 1;
49538 seq_printf(m, "%*c", len, ' ');
49539 - seq_path(m, &file->f_path, "");
49540 + seq_path(m, &file->f_path, "\n\\");
49541 }
49542
49543 seq_putc(m, '\n');
49544 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49545 index fe72cd0..cb9b67d 100644
49546 --- a/fs/proc/proc_net.c
49547 +++ b/fs/proc/proc_net.c
49548 @@ -23,6 +23,7 @@
49549 #include <linux/nsproxy.h>
49550 #include <net/net_namespace.h>
49551 #include <linux/seq_file.h>
49552 +#include <linux/grsecurity.h>
49553
49554 #include "internal.h"
49555
49556 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49557 struct task_struct *task;
49558 struct nsproxy *ns;
49559 struct net *net = NULL;
49560 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49561 + const struct cred *cred = current_cred();
49562 +#endif
49563 +
49564 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49565 + if (cred->fsuid)
49566 + return net;
49567 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49568 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49569 + return net;
49570 +#endif
49571
49572 rcu_read_lock();
49573 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49574 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49575 index a781bdf..6665284 100644
49576 --- a/fs/proc/proc_sysctl.c
49577 +++ b/fs/proc/proc_sysctl.c
49578 @@ -12,11 +12,15 @@
49579 #include <linux/module.h>
49580 #include "internal.h"
49581
49582 +extern int gr_handle_chroot_sysctl(const int op);
49583 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49584 + const int op);
49585 +
49586 static const struct dentry_operations proc_sys_dentry_operations;
49587 static const struct file_operations proc_sys_file_operations;
49588 -static const struct inode_operations proc_sys_inode_operations;
49589 +const struct inode_operations proc_sys_inode_operations;
49590 static const struct file_operations proc_sys_dir_file_operations;
49591 -static const struct inode_operations proc_sys_dir_operations;
49592 +const struct inode_operations proc_sys_dir_operations;
49593
49594 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49595 {
49596 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49597
49598 err = NULL;
49599 d_set_d_op(dentry, &proc_sys_dentry_operations);
49600 +
49601 + gr_handle_proc_create(dentry, inode);
49602 +
49603 d_add(dentry, inode);
49604
49605 out:
49606 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49607 struct inode *inode = filp->f_path.dentry->d_inode;
49608 struct ctl_table_header *head = grab_header(inode);
49609 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49610 + int op = write ? MAY_WRITE : MAY_READ;
49611 ssize_t error;
49612 size_t res;
49613
49614 if (IS_ERR(head))
49615 return PTR_ERR(head);
49616
49617 +
49618 /*
49619 * At this point we know that the sysctl was not unregistered
49620 * and won't be until we finish.
49621 */
49622 error = -EPERM;
49623 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49624 + if (sysctl_perm(head->root, table, op))
49625 goto out;
49626
49627 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49628 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49629 if (!table->proc_handler)
49630 goto out;
49631
49632 +#ifdef CONFIG_GRKERNSEC
49633 + error = -EPERM;
49634 + if (gr_handle_chroot_sysctl(op))
49635 + goto out;
49636 + dget(filp->f_path.dentry);
49637 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49638 + dput(filp->f_path.dentry);
49639 + goto out;
49640 + }
49641 + dput(filp->f_path.dentry);
49642 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49643 + goto out;
49644 + if (write && !capable(CAP_SYS_ADMIN))
49645 + goto out;
49646 +#endif
49647 +
49648 /* careful: calling conventions are nasty here */
49649 res = count;
49650 error = table->proc_handler(table, write, buf, &res, ppos);
49651 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49652 return -ENOMEM;
49653 } else {
49654 d_set_d_op(child, &proc_sys_dentry_operations);
49655 +
49656 + gr_handle_proc_create(child, inode);
49657 +
49658 d_add(child, inode);
49659 }
49660 } else {
49661 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49662 if ((*pos)++ < file->f_pos)
49663 return 0;
49664
49665 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49666 + return 0;
49667 +
49668 if (unlikely(S_ISLNK(table->mode)))
49669 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49670 else
49671 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49672 if (IS_ERR(head))
49673 return PTR_ERR(head);
49674
49675 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49676 + return -ENOENT;
49677 +
49678 generic_fillattr(inode, stat);
49679 if (table)
49680 stat->mode = (stat->mode & S_IFMT) | table->mode;
49681 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49682 .llseek = generic_file_llseek,
49683 };
49684
49685 -static const struct inode_operations proc_sys_inode_operations = {
49686 +const struct inode_operations proc_sys_inode_operations = {
49687 .permission = proc_sys_permission,
49688 .setattr = proc_sys_setattr,
49689 .getattr = proc_sys_getattr,
49690 };
49691
49692 -static const struct inode_operations proc_sys_dir_operations = {
49693 +const struct inode_operations proc_sys_dir_operations = {
49694 .lookup = proc_sys_lookup,
49695 .permission = proc_sys_permission,
49696 .setattr = proc_sys_setattr,
49697 diff --git a/fs/proc/root.c b/fs/proc/root.c
49698 index 9889a92..2613b48 100644
49699 --- a/fs/proc/root.c
49700 +++ b/fs/proc/root.c
49701 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49702 #ifdef CONFIG_PROC_DEVICETREE
49703 proc_device_tree_init();
49704 #endif
49705 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49706 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49707 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49708 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49709 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49710 +#endif
49711 +#else
49712 proc_mkdir("bus", NULL);
49713 +#endif
49714 proc_sys_init();
49715 }
49716
49717 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49718 index 90c63f9..e662cfc 100644
49719 --- a/fs/proc/task_mmu.c
49720 +++ b/fs/proc/task_mmu.c
49721 @@ -11,12 +11,19 @@
49722 #include <linux/rmap.h>
49723 #include <linux/swap.h>
49724 #include <linux/swapops.h>
49725 +#include <linux/grsecurity.h>
49726
49727 #include <asm/elf.h>
49728 #include <asm/uaccess.h>
49729 #include <asm/tlbflush.h>
49730 #include "internal.h"
49731
49732 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49733 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49734 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49735 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49736 +#endif
49737 +
49738 void task_mem(struct seq_file *m, struct mm_struct *mm)
49739 {
49740 unsigned long data, text, lib, swap;
49741 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49742 "VmExe:\t%8lu kB\n"
49743 "VmLib:\t%8lu kB\n"
49744 "VmPTE:\t%8lu kB\n"
49745 - "VmSwap:\t%8lu kB\n",
49746 - hiwater_vm << (PAGE_SHIFT-10),
49747 + "VmSwap:\t%8lu kB\n"
49748 +
49749 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49750 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49751 +#endif
49752 +
49753 + ,hiwater_vm << (PAGE_SHIFT-10),
49754 total_vm << (PAGE_SHIFT-10),
49755 mm->locked_vm << (PAGE_SHIFT-10),
49756 mm->pinned_vm << (PAGE_SHIFT-10),
49757 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49758 data << (PAGE_SHIFT-10),
49759 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49760 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49761 - swap << (PAGE_SHIFT-10));
49762 + swap << (PAGE_SHIFT-10)
49763 +
49764 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49765 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49766 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49767 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49768 +#else
49769 + , mm->context.user_cs_base
49770 + , mm->context.user_cs_limit
49771 +#endif
49772 +#endif
49773 +
49774 + );
49775 }
49776
49777 unsigned long task_vsize(struct mm_struct *mm)
49778 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49779 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49780 }
49781
49782 - /* We don't show the stack guard page in /proc/maps */
49783 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49784 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49785 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49786 +#else
49787 start = vma->vm_start;
49788 - if (stack_guard_page_start(vma, start))
49789 - start += PAGE_SIZE;
49790 end = vma->vm_end;
49791 - if (stack_guard_page_end(vma, end))
49792 - end -= PAGE_SIZE;
49793 +#endif
49794
49795 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49796 start,
49797 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49798 flags & VM_WRITE ? 'w' : '-',
49799 flags & VM_EXEC ? 'x' : '-',
49800 flags & VM_MAYSHARE ? 's' : 'p',
49801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49802 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49803 +#else
49804 pgoff,
49805 +#endif
49806 MAJOR(dev), MINOR(dev), ino, &len);
49807
49808 /*
49809 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49810 */
49811 if (file) {
49812 pad_len_spaces(m, len);
49813 - seq_path(m, &file->f_path, "\n");
49814 + seq_path(m, &file->f_path, "\n\\");
49815 goto done;
49816 }
49817
49818 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49819 * Thread stack in /proc/PID/task/TID/maps or
49820 * the main process stack.
49821 */
49822 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49823 - vma->vm_end >= mm->start_stack)) {
49824 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49825 + (vma->vm_start <= mm->start_stack &&
49826 + vma->vm_end >= mm->start_stack)) {
49827 name = "[stack]";
49828 } else {
49829 /* Thread stack in /proc/PID/maps */
49830 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49831 struct proc_maps_private *priv = m->private;
49832 struct task_struct *task = priv->task;
49833
49834 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49835 + if (current->exec_id != m->exec_id) {
49836 + gr_log_badprocpid("maps");
49837 + return 0;
49838 + }
49839 +#endif
49840 +
49841 show_map_vma(m, vma, is_pid);
49842
49843 if (m->count < m->size) /* vma is copied successfully */
49844 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49845 .private = &mss,
49846 };
49847
49848 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49849 + if (current->exec_id != m->exec_id) {
49850 + gr_log_badprocpid("smaps");
49851 + return 0;
49852 + }
49853 +#endif
49854 memset(&mss, 0, sizeof mss);
49855 - mss.vma = vma;
49856 - /* mmap_sem is held in m_start */
49857 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49858 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49859 -
49860 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49861 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49862 +#endif
49863 + mss.vma = vma;
49864 + /* mmap_sem is held in m_start */
49865 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49866 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49867 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49868 + }
49869 +#endif
49870 show_map_vma(m, vma, is_pid);
49871
49872 seq_printf(m,
49873 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49874 "KernelPageSize: %8lu kB\n"
49875 "MMUPageSize: %8lu kB\n"
49876 "Locked: %8lu kB\n",
49877 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49878 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49879 +#else
49880 (vma->vm_end - vma->vm_start) >> 10,
49881 +#endif
49882 mss.resident >> 10,
49883 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49884 mss.shared_clean >> 10,
49885 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49886 int n;
49887 char buffer[50];
49888
49889 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49890 + if (current->exec_id != m->exec_id) {
49891 + gr_log_badprocpid("numa_maps");
49892 + return 0;
49893 + }
49894 +#endif
49895 +
49896 if (!mm)
49897 return 0;
49898
49899 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49900 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49901 mpol_cond_put(pol);
49902
49903 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49904 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49905 +#else
49906 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49907 +#endif
49908
49909 if (file) {
49910 seq_printf(m, " file=");
49911 - seq_path(m, &file->f_path, "\n\t= ");
49912 + seq_path(m, &file->f_path, "\n\t\\= ");
49913 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49914 seq_printf(m, " heap");
49915 } else {
49916 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49917 index 1ccfa53..0848f95 100644
49918 --- a/fs/proc/task_nommu.c
49919 +++ b/fs/proc/task_nommu.c
49920 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49921 else
49922 bytes += kobjsize(mm);
49923
49924 - if (current->fs && current->fs->users > 1)
49925 + if (current->fs && atomic_read(&current->fs->users) > 1)
49926 sbytes += kobjsize(current->fs);
49927 else
49928 bytes += kobjsize(current->fs);
49929 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49930
49931 if (file) {
49932 pad_len_spaces(m, len);
49933 - seq_path(m, &file->f_path, "");
49934 + seq_path(m, &file->f_path, "\n\\");
49935 } else if (mm) {
49936 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49937
49938 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49939 index 16e8abb..2dcf914 100644
49940 --- a/fs/quota/netlink.c
49941 +++ b/fs/quota/netlink.c
49942 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49943 void quota_send_warning(struct kqid qid, dev_t dev,
49944 const char warntype)
49945 {
49946 - static atomic_t seq;
49947 + static atomic_unchecked_t seq;
49948 struct sk_buff *skb;
49949 void *msg_head;
49950 int ret;
49951 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
49952 "VFS: Not enough memory to send quota warning.\n");
49953 return;
49954 }
49955 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49956 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49957 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49958 if (!msg_head) {
49959 printk(KERN_ERR
49960 diff --git a/fs/readdir.c b/fs/readdir.c
49961 index 5e69ef5..e5d9099 100644
49962 --- a/fs/readdir.c
49963 +++ b/fs/readdir.c
49964 @@ -17,6 +17,7 @@
49965 #include <linux/security.h>
49966 #include <linux/syscalls.h>
49967 #include <linux/unistd.h>
49968 +#include <linux/namei.h>
49969
49970 #include <asm/uaccess.h>
49971
49972 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49973
49974 struct readdir_callback {
49975 struct old_linux_dirent __user * dirent;
49976 + struct file * file;
49977 int result;
49978 };
49979
49980 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49981 buf->result = -EOVERFLOW;
49982 return -EOVERFLOW;
49983 }
49984 +
49985 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49986 + return 0;
49987 +
49988 buf->result++;
49989 dirent = buf->dirent;
49990 if (!access_ok(VERIFY_WRITE, dirent,
49991 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49992
49993 buf.result = 0;
49994 buf.dirent = dirent;
49995 + buf.file = f.file;
49996
49997 error = vfs_readdir(f.file, fillonedir, &buf);
49998 if (buf.result)
49999 @@ -139,6 +146,7 @@ struct linux_dirent {
50000 struct getdents_callback {
50001 struct linux_dirent __user * current_dir;
50002 struct linux_dirent __user * previous;
50003 + struct file * file;
50004 int count;
50005 int error;
50006 };
50007 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50008 buf->error = -EOVERFLOW;
50009 return -EOVERFLOW;
50010 }
50011 +
50012 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50013 + return 0;
50014 +
50015 dirent = buf->previous;
50016 if (dirent) {
50017 if (__put_user(offset, &dirent->d_off))
50018 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50019 buf.previous = NULL;
50020 buf.count = count;
50021 buf.error = 0;
50022 + buf.file = f.file;
50023
50024 error = vfs_readdir(f.file, filldir, &buf);
50025 if (error >= 0)
50026 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50027 struct getdents_callback64 {
50028 struct linux_dirent64 __user * current_dir;
50029 struct linux_dirent64 __user * previous;
50030 + struct file *file;
50031 int count;
50032 int error;
50033 };
50034 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50035 buf->error = -EINVAL; /* only used if we fail.. */
50036 if (reclen > buf->count)
50037 return -EINVAL;
50038 +
50039 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50040 + return 0;
50041 +
50042 dirent = buf->previous;
50043 if (dirent) {
50044 if (__put_user(offset, &dirent->d_off))
50045 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50046
50047 buf.current_dir = dirent;
50048 buf.previous = NULL;
50049 + buf.file = f.file;
50050 buf.count = count;
50051 buf.error = 0;
50052
50053 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50054 error = buf.error;
50055 lastdirent = buf.previous;
50056 if (lastdirent) {
50057 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
50058 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50059 if (__put_user(d_off, &lastdirent->d_off))
50060 error = -EFAULT;
50061 else
50062 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50063 index 2b7882b..1c5ef48 100644
50064 --- a/fs/reiserfs/do_balan.c
50065 +++ b/fs/reiserfs/do_balan.c
50066 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50067 return;
50068 }
50069
50070 - atomic_inc(&(fs_generation(tb->tb_sb)));
50071 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50072 do_balance_starts(tb);
50073
50074 /* balance leaf returns 0 except if combining L R and S into
50075 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50076 index e60e870..f40ac16 100644
50077 --- a/fs/reiserfs/procfs.c
50078 +++ b/fs/reiserfs/procfs.c
50079 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50080 "SMALL_TAILS " : "NO_TAILS ",
50081 replay_only(sb) ? "REPLAY_ONLY " : "",
50082 convert_reiserfs(sb) ? "CONV " : "",
50083 - atomic_read(&r->s_generation_counter),
50084 + atomic_read_unchecked(&r->s_generation_counter),
50085 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50086 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50087 SF(s_good_search_by_key_reada), SF(s_bmaps),
50088 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50089 index 33215f5..c5d427a 100644
50090 --- a/fs/reiserfs/reiserfs.h
50091 +++ b/fs/reiserfs/reiserfs.h
50092 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50093 /* Comment? -Hans */
50094 wait_queue_head_t s_wait;
50095 /* To be obsoleted soon by per buffer seals.. -Hans */
50096 - atomic_t s_generation_counter; // increased by one every time the
50097 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50098 // tree gets re-balanced
50099 unsigned long s_properties; /* File system properties. Currently holds
50100 on-disk FS format */
50101 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50102 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50103
50104 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50105 -#define get_generation(s) atomic_read (&fs_generation(s))
50106 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50107 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50108 #define __fs_changed(gen,s) (gen != get_generation (s))
50109 #define fs_changed(gen,s) \
50110 diff --git a/fs/select.c b/fs/select.c
50111 index 2ef72d9..f213b17 100644
50112 --- a/fs/select.c
50113 +++ b/fs/select.c
50114 @@ -20,6 +20,7 @@
50115 #include <linux/export.h>
50116 #include <linux/slab.h>
50117 #include <linux/poll.h>
50118 +#include <linux/security.h>
50119 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50120 #include <linux/file.h>
50121 #include <linux/fdtable.h>
50122 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50123 struct poll_list *walk = head;
50124 unsigned long todo = nfds;
50125
50126 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50127 if (nfds > rlimit(RLIMIT_NOFILE))
50128 return -EINVAL;
50129
50130 diff --git a/fs/seq_file.c b/fs/seq_file.c
50131 index 99dffab..884a1eb 100644
50132 --- a/fs/seq_file.c
50133 +++ b/fs/seq_file.c
50134 @@ -10,6 +10,7 @@
50135 #include <linux/seq_file.h>
50136 #include <linux/slab.h>
50137 #include <linux/cred.h>
50138 +#include <linux/sched.h>
50139
50140 #include <asm/uaccess.h>
50141 #include <asm/page.h>
50142 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50143 #ifdef CONFIG_USER_NS
50144 p->user_ns = file->f_cred->user_ns;
50145 #endif
50146 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50147 + p->exec_id = current->exec_id;
50148 +#endif
50149
50150 /*
50151 * Wrappers around seq_open(e.g. swaps_open) need to be
50152 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50153 return 0;
50154 }
50155 if (!m->buf) {
50156 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50157 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50158 if (!m->buf)
50159 return -ENOMEM;
50160 }
50161 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50162 Eoverflow:
50163 m->op->stop(m, p);
50164 kfree(m->buf);
50165 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50166 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50167 return !m->buf ? -ENOMEM : -EAGAIN;
50168 }
50169
50170 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50171
50172 /* grab buffer if we didn't have one */
50173 if (!m->buf) {
50174 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50175 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50176 if (!m->buf)
50177 goto Enomem;
50178 }
50179 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50180 goto Fill;
50181 m->op->stop(m, p);
50182 kfree(m->buf);
50183 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50184 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50185 if (!m->buf)
50186 goto Enomem;
50187 m->count = 0;
50188 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
50189 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50190 void *data)
50191 {
50192 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50193 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50194 int res = -ENOMEM;
50195
50196 if (op) {
50197 diff --git a/fs/splice.c b/fs/splice.c
50198 index 13e5b47..2262998 100644
50199 --- a/fs/splice.c
50200 +++ b/fs/splice.c
50201 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50202 pipe_lock(pipe);
50203
50204 for (;;) {
50205 - if (!pipe->readers) {
50206 + if (!atomic_read(&pipe->readers)) {
50207 send_sig(SIGPIPE, current, 0);
50208 if (!ret)
50209 ret = -EPIPE;
50210 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50211 do_wakeup = 0;
50212 }
50213
50214 - pipe->waiting_writers++;
50215 + atomic_inc(&pipe->waiting_writers);
50216 pipe_wait(pipe);
50217 - pipe->waiting_writers--;
50218 + atomic_dec(&pipe->waiting_writers);
50219 }
50220
50221 pipe_unlock(pipe);
50222 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50223 old_fs = get_fs();
50224 set_fs(get_ds());
50225 /* The cast to a user pointer is valid due to the set_fs() */
50226 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50227 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50228 set_fs(old_fs);
50229
50230 return res;
50231 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50232 old_fs = get_fs();
50233 set_fs(get_ds());
50234 /* The cast to a user pointer is valid due to the set_fs() */
50235 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50236 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50237 set_fs(old_fs);
50238
50239 return res;
50240 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50241 goto err;
50242
50243 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50244 - vec[i].iov_base = (void __user *) page_address(page);
50245 + vec[i].iov_base = (void __force_user *) page_address(page);
50246 vec[i].iov_len = this_len;
50247 spd.pages[i] = page;
50248 spd.nr_pages++;
50249 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50250 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50251 {
50252 while (!pipe->nrbufs) {
50253 - if (!pipe->writers)
50254 + if (!atomic_read(&pipe->writers))
50255 return 0;
50256
50257 - if (!pipe->waiting_writers && sd->num_spliced)
50258 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50259 return 0;
50260
50261 if (sd->flags & SPLICE_F_NONBLOCK)
50262 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50263 * out of the pipe right after the splice_to_pipe(). So set
50264 * PIPE_READERS appropriately.
50265 */
50266 - pipe->readers = 1;
50267 + atomic_set(&pipe->readers, 1);
50268
50269 current->splice_pipe = pipe;
50270 }
50271 @@ -1739,9 +1739,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50272 ret = -ERESTARTSYS;
50273 break;
50274 }
50275 - if (!pipe->writers)
50276 + if (!atomic_read(&pipe->writers))
50277 break;
50278 - if (!pipe->waiting_writers) {
50279 + if (!atomic_read(&pipe->waiting_writers)) {
50280 if (flags & SPLICE_F_NONBLOCK) {
50281 ret = -EAGAIN;
50282 break;
50283 @@ -1773,7 +1773,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50284 pipe_lock(pipe);
50285
50286 while (pipe->nrbufs >= pipe->buffers) {
50287 - if (!pipe->readers) {
50288 + if (!atomic_read(&pipe->readers)) {
50289 send_sig(SIGPIPE, current, 0);
50290 ret = -EPIPE;
50291 break;
50292 @@ -1786,9 +1786,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50293 ret = -ERESTARTSYS;
50294 break;
50295 }
50296 - pipe->waiting_writers++;
50297 + atomic_inc(&pipe->waiting_writers);
50298 pipe_wait(pipe);
50299 - pipe->waiting_writers--;
50300 + atomic_dec(&pipe->waiting_writers);
50301 }
50302
50303 pipe_unlock(pipe);
50304 @@ -1824,14 +1824,14 @@ retry:
50305 pipe_double_lock(ipipe, opipe);
50306
50307 do {
50308 - if (!opipe->readers) {
50309 + if (!atomic_read(&opipe->readers)) {
50310 send_sig(SIGPIPE, current, 0);
50311 if (!ret)
50312 ret = -EPIPE;
50313 break;
50314 }
50315
50316 - if (!ipipe->nrbufs && !ipipe->writers)
50317 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50318 break;
50319
50320 /*
50321 @@ -1928,7 +1928,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50322 pipe_double_lock(ipipe, opipe);
50323
50324 do {
50325 - if (!opipe->readers) {
50326 + if (!atomic_read(&opipe->readers)) {
50327 send_sig(SIGPIPE, current, 0);
50328 if (!ret)
50329 ret = -EPIPE;
50330 @@ -1973,7 +1973,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50331 * return EAGAIN if we have the potential of some data in the
50332 * future, otherwise just return 0
50333 */
50334 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50335 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50336 ret = -EAGAIN;
50337
50338 pipe_unlock(ipipe);
50339 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50340 index 2fbdff6..5530a61 100644
50341 --- a/fs/sysfs/dir.c
50342 +++ b/fs/sysfs/dir.c
50343 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50344 struct sysfs_dirent *sd;
50345 int rc;
50346
50347 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50348 + const char *parent_name = parent_sd->s_name;
50349 +
50350 + mode = S_IFDIR | S_IRWXU;
50351 +
50352 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50353 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50354 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50355 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50356 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50357 +#endif
50358 +
50359 /* allocate */
50360 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50361 if (!sd)
50362 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50363 index 00012e3..8392349 100644
50364 --- a/fs/sysfs/file.c
50365 +++ b/fs/sysfs/file.c
50366 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50367
50368 struct sysfs_open_dirent {
50369 atomic_t refcnt;
50370 - atomic_t event;
50371 + atomic_unchecked_t event;
50372 wait_queue_head_t poll;
50373 struct list_head buffers; /* goes through sysfs_buffer.list */
50374 };
50375 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50376 if (!sysfs_get_active(attr_sd))
50377 return -ENODEV;
50378
50379 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50380 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50381 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50382
50383 sysfs_put_active(attr_sd);
50384 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50385 return -ENOMEM;
50386
50387 atomic_set(&new_od->refcnt, 0);
50388 - atomic_set(&new_od->event, 1);
50389 + atomic_set_unchecked(&new_od->event, 1);
50390 init_waitqueue_head(&new_od->poll);
50391 INIT_LIST_HEAD(&new_od->buffers);
50392 goto retry;
50393 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50394
50395 sysfs_put_active(attr_sd);
50396
50397 - if (buffer->event != atomic_read(&od->event))
50398 + if (buffer->event != atomic_read_unchecked(&od->event))
50399 goto trigger;
50400
50401 return DEFAULT_POLLMASK;
50402 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50403
50404 od = sd->s_attr.open;
50405 if (od) {
50406 - atomic_inc(&od->event);
50407 + atomic_inc_unchecked(&od->event);
50408 wake_up_interruptible(&od->poll);
50409 }
50410
50411 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50412 index 3c9eb56..9dea5be 100644
50413 --- a/fs/sysfs/symlink.c
50414 +++ b/fs/sysfs/symlink.c
50415 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50416
50417 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50418 {
50419 - char *page = nd_get_link(nd);
50420 + const char *page = nd_get_link(nd);
50421 if (!IS_ERR(page))
50422 free_page((unsigned long)page);
50423 }
50424 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50425 index c175b4d..8f36a16 100644
50426 --- a/fs/udf/misc.c
50427 +++ b/fs/udf/misc.c
50428 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50429
50430 u8 udf_tag_checksum(const struct tag *t)
50431 {
50432 - u8 *data = (u8 *)t;
50433 + const u8 *data = (const u8 *)t;
50434 u8 checksum = 0;
50435 int i;
50436 for (i = 0; i < sizeof(struct tag); ++i)
50437 diff --git a/fs/utimes.c b/fs/utimes.c
50438 index bb0696a..552054b 100644
50439 --- a/fs/utimes.c
50440 +++ b/fs/utimes.c
50441 @@ -1,6 +1,7 @@
50442 #include <linux/compiler.h>
50443 #include <linux/file.h>
50444 #include <linux/fs.h>
50445 +#include <linux/security.h>
50446 #include <linux/linkage.h>
50447 #include <linux/mount.h>
50448 #include <linux/namei.h>
50449 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50450 goto mnt_drop_write_and_out;
50451 }
50452 }
50453 +
50454 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50455 + error = -EACCES;
50456 + goto mnt_drop_write_and_out;
50457 + }
50458 +
50459 mutex_lock(&inode->i_mutex);
50460 error = notify_change(path->dentry, &newattrs);
50461 mutex_unlock(&inode->i_mutex);
50462 diff --git a/fs/xattr.c b/fs/xattr.c
50463 index e21c119..21dfc7c 100644
50464 --- a/fs/xattr.c
50465 +++ b/fs/xattr.c
50466 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50467 * Extended attribute SET operations
50468 */
50469 static long
50470 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50471 +setxattr(struct path *path, const char __user *name, const void __user *value,
50472 size_t size, int flags)
50473 {
50474 int error;
50475 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50476 posix_acl_fix_xattr_from_user(kvalue, size);
50477 }
50478
50479 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50480 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50481 + error = -EACCES;
50482 + goto out;
50483 + }
50484 +
50485 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50486 out:
50487 if (vvalue)
50488 vfree(vvalue);
50489 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50490 return error;
50491 error = mnt_want_write(path.mnt);
50492 if (!error) {
50493 - error = setxattr(path.dentry, name, value, size, flags);
50494 + error = setxattr(&path, name, value, size, flags);
50495 mnt_drop_write(path.mnt);
50496 }
50497 path_put(&path);
50498 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50499 return error;
50500 error = mnt_want_write(path.mnt);
50501 if (!error) {
50502 - error = setxattr(path.dentry, name, value, size, flags);
50503 + error = setxattr(&path, name, value, size, flags);
50504 mnt_drop_write(path.mnt);
50505 }
50506 path_put(&path);
50507 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50508 const void __user *,value, size_t, size, int, flags)
50509 {
50510 struct fd f = fdget(fd);
50511 - struct dentry *dentry;
50512 int error = -EBADF;
50513
50514 if (!f.file)
50515 return error;
50516 - dentry = f.file->f_path.dentry;
50517 - audit_inode(NULL, dentry, 0);
50518 + audit_inode(NULL, f.file->f_path.dentry, 0);
50519 error = mnt_want_write_file(f.file);
50520 if (!error) {
50521 - error = setxattr(dentry, name, value, size, flags);
50522 + error = setxattr(&f.file->f_path, name, value, size, flags);
50523 mnt_drop_write_file(f.file);
50524 }
50525 fdput(f);
50526 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50527 index 9fbea87..6b19972 100644
50528 --- a/fs/xattr_acl.c
50529 +++ b/fs/xattr_acl.c
50530 @@ -76,8 +76,8 @@ struct posix_acl *
50531 posix_acl_from_xattr(struct user_namespace *user_ns,
50532 const void *value, size_t size)
50533 {
50534 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50535 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50536 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50537 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50538 int count;
50539 struct posix_acl *acl;
50540 struct posix_acl_entry *acl_e;
50541 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50542 index 83d0cf3..2ef526b 100644
50543 --- a/fs/xfs/xfs_bmap.c
50544 +++ b/fs/xfs/xfs_bmap.c
50545 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50546 int nmap,
50547 int ret_nmap);
50548 #else
50549 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50550 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50551 #endif /* DEBUG */
50552
50553 STATIC int
50554 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50555 index 1b9fc3e..e1bdde0 100644
50556 --- a/fs/xfs/xfs_dir2_sf.c
50557 +++ b/fs/xfs/xfs_dir2_sf.c
50558 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50559 }
50560
50561 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50562 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50563 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50564 + char name[sfep->namelen];
50565 + memcpy(name, sfep->name, sfep->namelen);
50566 + if (filldir(dirent, name, sfep->namelen,
50567 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50568 + *offset = off & 0x7fffffff;
50569 + return 0;
50570 + }
50571 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50572 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50573 *offset = off & 0x7fffffff;
50574 return 0;
50575 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50576 index c1df3c6..f987db6 100644
50577 --- a/fs/xfs/xfs_ioctl.c
50578 +++ b/fs/xfs/xfs_ioctl.c
50579 @@ -126,7 +126,7 @@ xfs_find_handle(
50580 }
50581
50582 error = -EFAULT;
50583 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50584 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50585 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50586 goto out_put;
50587
50588 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50589 index 4e00cf0..3374374 100644
50590 --- a/fs/xfs/xfs_iops.c
50591 +++ b/fs/xfs/xfs_iops.c
50592 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50593 struct nameidata *nd,
50594 void *p)
50595 {
50596 - char *s = nd_get_link(nd);
50597 + const char *s = nd_get_link(nd);
50598
50599 if (!IS_ERR(s))
50600 kfree(s);
50601 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50602 new file mode 100644
50603 index 0000000..10c36fb
50604 --- /dev/null
50605 +++ b/grsecurity/Kconfig
50606 @@ -0,0 +1,964 @@
50607 +#
50608 +# grecurity configuration
50609 +#
50610 +menu "Memory Protections"
50611 +depends on GRKERNSEC
50612 +
50613 +config GRKERNSEC_KMEM
50614 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50615 + default y if GRKERNSEC_CONFIG_AUTO
50616 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50617 + help
50618 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50619 + be written to or read from to modify or leak the contents of the running
50620 + kernel. /dev/port will also not be allowed to be opened. If you have module
50621 + support disabled, enabling this will close up four ways that are
50622 + currently used to insert malicious code into the running kernel.
50623 + Even with all these features enabled, we still highly recommend that
50624 + you use the RBAC system, as it is still possible for an attacker to
50625 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50626 + If you are not using XFree86, you may be able to stop this additional
50627 + case by enabling the 'Disable privileged I/O' option. Though nothing
50628 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50629 + but only to video memory, which is the only writing we allow in this
50630 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50631 + not be allowed to mprotect it with PROT_WRITE later.
50632 + It is highly recommended that you say Y here if you meet all the
50633 + conditions above.
50634 +
50635 +config GRKERNSEC_VM86
50636 + bool "Restrict VM86 mode"
50637 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50638 + depends on X86_32
50639 +
50640 + help
50641 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50642 + make use of a special execution mode on 32bit x86 processors called
50643 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50644 + video cards and will still work with this option enabled. The purpose
50645 + of the option is to prevent exploitation of emulation errors in
50646 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50647 + Nearly all users should be able to enable this option.
50648 +
50649 +config GRKERNSEC_IO
50650 + bool "Disable privileged I/O"
50651 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50652 + depends on X86
50653 + select RTC_CLASS
50654 + select RTC_INTF_DEV
50655 + select RTC_DRV_CMOS
50656 +
50657 + help
50658 + If you say Y here, all ioperm and iopl calls will return an error.
50659 + Ioperm and iopl can be used to modify the running kernel.
50660 + Unfortunately, some programs need this access to operate properly,
50661 + the most notable of which are XFree86 and hwclock. hwclock can be
50662 + remedied by having RTC support in the kernel, so real-time
50663 + clock support is enabled if this option is enabled, to ensure
50664 + that hwclock operates correctly. XFree86 still will not
50665 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50666 + IF YOU USE XFree86. If you use XFree86 and you still want to
50667 + protect your kernel against modification, use the RBAC system.
50668 +
50669 +config GRKERNSEC_JIT_HARDEN
50670 + bool "Harden BPF JIT against spray attacks"
50671 + default y if GRKERNSEC_CONFIG_AUTO
50672 + depends on BPF_JIT
50673 + help
50674 + If you say Y here, the native code generated by the kernel's Berkeley
50675 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
50676 + attacks that attempt to fit attacker-beneficial instructions in
50677 + 32bit immediate fields of JIT-generated native instructions. The
50678 + attacker will generally aim to cause an unintended instruction sequence
50679 + of JIT-generated native code to execute by jumping into the middle of
50680 + a generated instruction. This feature effectively randomizes the 32bit
50681 + immediate constants present in the generated code to thwart such attacks.
50682 +
50683 + If you're using KERNEXEC, it's recommended that you enable this option
50684 + to supplement the hardening of the kernel.
50685 +
50686 +config GRKERNSEC_PROC_MEMMAP
50687 + bool "Harden ASLR against information leaks and entropy reduction"
50688 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50689 + depends on PAX_NOEXEC || PAX_ASLR
50690 + help
50691 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50692 + give no information about the addresses of its mappings if
50693 + PaX features that rely on random addresses are enabled on the task.
50694 + In addition to sanitizing this information and disabling other
50695 + dangerous sources of information, this option causes reads of sensitive
50696 + /proc/<pid> entries where the file descriptor was opened in a different
50697 + task than the one performing the read. Such attempts are logged.
50698 + This option also limits argv/env strings for suid/sgid binaries
50699 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50700 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50701 + binaries to prevent alternative mmap layouts from being abused.
50702 +
50703 + If you use PaX it is essential that you say Y here as it closes up
50704 + several holes that make full ASLR useless locally.
50705 +
50706 +config GRKERNSEC_BRUTE
50707 + bool "Deter exploit bruteforcing"
50708 + default y if GRKERNSEC_CONFIG_AUTO
50709 + help
50710 + If you say Y here, attempts to bruteforce exploits against forking
50711 + daemons such as apache or sshd, as well as against suid/sgid binaries
50712 + will be deterred. When a child of a forking daemon is killed by PaX
50713 + or crashes due to an illegal instruction or other suspicious signal,
50714 + the parent process will be delayed 30 seconds upon every subsequent
50715 + fork until the administrator is able to assess the situation and
50716 + restart the daemon.
50717 + In the suid/sgid case, the attempt is logged, the user has all their
50718 + processes terminated, and they are prevented from executing any further
50719 + processes for 15 minutes.
50720 + It is recommended that you also enable signal logging in the auditing
50721 + section so that logs are generated when a process triggers a suspicious
50722 + signal.
50723 + If the sysctl option is enabled, a sysctl option with name
50724 + "deter_bruteforce" is created.
50725 +
50726 +
50727 +config GRKERNSEC_MODHARDEN
50728 + bool "Harden module auto-loading"
50729 + default y if GRKERNSEC_CONFIG_AUTO
50730 + depends on MODULES
50731 + help
50732 + If you say Y here, module auto-loading in response to use of some
50733 + feature implemented by an unloaded module will be restricted to
50734 + root users. Enabling this option helps defend against attacks
50735 + by unprivileged users who abuse the auto-loading behavior to
50736 + cause a vulnerable module to load that is then exploited.
50737 +
50738 + If this option prevents a legitimate use of auto-loading for a
50739 + non-root user, the administrator can execute modprobe manually
50740 + with the exact name of the module mentioned in the alert log.
50741 + Alternatively, the administrator can add the module to the list
50742 + of modules loaded at boot by modifying init scripts.
50743 +
50744 + Modification of init scripts will most likely be needed on
50745 + Ubuntu servers with encrypted home directory support enabled,
50746 + as the first non-root user logging in will cause the ecb(aes),
50747 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50748 +
50749 +config GRKERNSEC_HIDESYM
50750 + bool "Hide kernel symbols"
50751 + default y if GRKERNSEC_CONFIG_AUTO
50752 + select PAX_USERCOPY_SLABS
50753 + help
50754 + If you say Y here, getting information on loaded modules, and
50755 + displaying all kernel symbols through a syscall will be restricted
50756 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50757 + /proc/kallsyms will be restricted to the root user. The RBAC
50758 + system can hide that entry even from root.
50759 +
50760 + This option also prevents leaking of kernel addresses through
50761 + several /proc entries.
50762 +
50763 + Note that this option is only effective provided the following
50764 + conditions are met:
50765 + 1) The kernel using grsecurity is not precompiled by some distribution
50766 + 2) You have also enabled GRKERNSEC_DMESG
50767 + 3) You are using the RBAC system and hiding other files such as your
50768 + kernel image and System.map. Alternatively, enabling this option
50769 + causes the permissions on /boot, /lib/modules, and the kernel
50770 + source directory to change at compile time to prevent
50771 + reading by non-root users.
50772 + If the above conditions are met, this option will aid in providing a
50773 + useful protection against local kernel exploitation of overflows
50774 + and arbitrary read/write vulnerabilities.
50775 +
50776 +config GRKERNSEC_KERN_LOCKOUT
50777 + bool "Active kernel exploit response"
50778 + default y if GRKERNSEC_CONFIG_AUTO
50779 + depends on X86 || ARM || PPC || SPARC
50780 + help
50781 + If you say Y here, when a PaX alert is triggered due to suspicious
50782 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50783 + or an OOPS occurs due to bad memory accesses, instead of just
50784 + terminating the offending process (and potentially allowing
50785 + a subsequent exploit from the same user), we will take one of two
50786 + actions:
50787 + If the user was root, we will panic the system
50788 + If the user was non-root, we will log the attempt, terminate
50789 + all processes owned by the user, then prevent them from creating
50790 + any new processes until the system is restarted
50791 + This deters repeated kernel exploitation/bruteforcing attempts
50792 + and is useful for later forensics.
50793 +
50794 +endmenu
50795 +menu "Role Based Access Control Options"
50796 +depends on GRKERNSEC
50797 +
50798 +config GRKERNSEC_RBAC_DEBUG
50799 + bool
50800 +
50801 +config GRKERNSEC_NO_RBAC
50802 + bool "Disable RBAC system"
50803 + help
50804 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50805 + preventing the RBAC system from being enabled. You should only say Y
50806 + here if you have no intention of using the RBAC system, so as to prevent
50807 + an attacker with root access from misusing the RBAC system to hide files
50808 + and processes when loadable module support and /dev/[k]mem have been
50809 + locked down.
50810 +
50811 +config GRKERNSEC_ACL_HIDEKERN
50812 + bool "Hide kernel processes"
50813 + help
50814 + If you say Y here, all kernel threads will be hidden to all
50815 + processes but those whose subject has the "view hidden processes"
50816 + flag.
50817 +
50818 +config GRKERNSEC_ACL_MAXTRIES
50819 + int "Maximum tries before password lockout"
50820 + default 3
50821 + help
50822 + This option enforces the maximum number of times a user can attempt
50823 + to authorize themselves with the grsecurity RBAC system before being
50824 + denied the ability to attempt authorization again for a specified time.
50825 + The lower the number, the harder it will be to brute-force a password.
50826 +
50827 +config GRKERNSEC_ACL_TIMEOUT
50828 + int "Time to wait after max password tries, in seconds"
50829 + default 30
50830 + help
50831 + This option specifies the time the user must wait after attempting to
50832 + authorize to the RBAC system with the maximum number of invalid
50833 + passwords. The higher the number, the harder it will be to brute-force
50834 + a password.
50835 +
50836 +endmenu
50837 +menu "Filesystem Protections"
50838 +depends on GRKERNSEC
50839 +
50840 +config GRKERNSEC_PROC
50841 + bool "Proc restrictions"
50842 + default y if GRKERNSEC_CONFIG_AUTO
50843 + help
50844 + If you say Y here, the permissions of the /proc filesystem
50845 + will be altered to enhance system security and privacy. You MUST
50846 + choose either a user only restriction or a user and group restriction.
50847 + Depending upon the option you choose, you can either restrict users to
50848 + see only the processes they themselves run, or choose a group that can
50849 + view all processes and files normally restricted to root if you choose
50850 + the "restrict to user only" option. NOTE: If you're running identd or
50851 + ntpd as a non-root user, you will have to run it as the group you
50852 + specify here.
50853 +
50854 +config GRKERNSEC_PROC_USER
50855 + bool "Restrict /proc to user only"
50856 + depends on GRKERNSEC_PROC
50857 + help
50858 + If you say Y here, non-root users will only be able to view their own
50859 + processes, and restricts them from viewing network-related information,
50860 + and viewing kernel symbol and module information.
50861 +
50862 +config GRKERNSEC_PROC_USERGROUP
50863 + bool "Allow special group"
50864 + default y if GRKERNSEC_CONFIG_AUTO
50865 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50866 + help
50867 + If you say Y here, you will be able to select a group that will be
50868 + able to view all processes and network-related information. If you've
50869 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50870 + remain hidden. This option is useful if you want to run identd as
50871 + a non-root user. The group you select may also be chosen at boot time
50872 + via "grsec_proc_gid=" on the kernel commandline.
50873 +
50874 +config GRKERNSEC_PROC_GID
50875 + int "GID for special group"
50876 + depends on GRKERNSEC_PROC_USERGROUP
50877 + default 1001
50878 +
50879 +config GRKERNSEC_PROC_ADD
50880 + bool "Additional restrictions"
50881 + default y if GRKERNSEC_CONFIG_AUTO
50882 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50883 + help
50884 + If you say Y here, additional restrictions will be placed on
50885 + /proc that keep normal users from viewing device information and
50886 + slabinfo information that could be useful for exploits.
50887 +
50888 +config GRKERNSEC_LINK
50889 + bool "Linking restrictions"
50890 + default y if GRKERNSEC_CONFIG_AUTO
50891 + help
50892 + If you say Y here, /tmp race exploits will be prevented, since users
50893 + will no longer be able to follow symlinks owned by other users in
50894 + world-writable +t directories (e.g. /tmp), unless the owner of the
50895 + symlink is the owner of the directory. users will also not be
50896 + able to hardlink to files they do not own. If the sysctl option is
50897 + enabled, a sysctl option with name "linking_restrictions" is created.
50898 +
50899 +config GRKERNSEC_SYMLINKOWN
50900 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50901 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50902 + help
50903 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50904 + that prevents it from being used as a security feature. As Apache
50905 + verifies the symlink by performing a stat() against the target of
50906 + the symlink before it is followed, an attacker can setup a symlink
50907 + to point to a same-owned file, then replace the symlink with one
50908 + that targets another user's file just after Apache "validates" the
50909 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50910 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50911 + will be in place for the group you specify. If the sysctl option
50912 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50913 + created.
50914 +
50915 +config GRKERNSEC_SYMLINKOWN_GID
50916 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50917 + depends on GRKERNSEC_SYMLINKOWN
50918 + default 1006
50919 + help
50920 + Setting this GID determines what group kernel-enforced
50921 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50922 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50923 +
50924 +config GRKERNSEC_FIFO
50925 + bool "FIFO restrictions"
50926 + default y if GRKERNSEC_CONFIG_AUTO
50927 + help
50928 + If you say Y here, users will not be able to write to FIFOs they don't
50929 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50930 + the FIFO is the same owner of the directory it's held in. If the sysctl
50931 + option is enabled, a sysctl option with name "fifo_restrictions" is
50932 + created.
50933 +
50934 +config GRKERNSEC_SYSFS_RESTRICT
50935 + bool "Sysfs/debugfs restriction"
50936 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50937 + depends on SYSFS
50938 + help
50939 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50940 + any filesystem normally mounted under it (e.g. debugfs) will be
50941 + mostly accessible only by root. These filesystems generally provide access
50942 + to hardware and debug information that isn't appropriate for unprivileged
50943 + users of the system. Sysfs and debugfs have also become a large source
50944 + of new vulnerabilities, ranging from infoleaks to local compromise.
50945 + There has been very little oversight with an eye toward security involved
50946 + in adding new exporters of information to these filesystems, so their
50947 + use is discouraged.
50948 + For reasons of compatibility, a few directories have been whitelisted
50949 + for access by non-root users:
50950 + /sys/fs/selinux
50951 + /sys/fs/fuse
50952 + /sys/devices/system/cpu
50953 +
50954 +config GRKERNSEC_ROFS
50955 + bool "Runtime read-only mount protection"
50956 + help
50957 + If you say Y here, a sysctl option with name "romount_protect" will
50958 + be created. By setting this option to 1 at runtime, filesystems
50959 + will be protected in the following ways:
50960 + * No new writable mounts will be allowed
50961 + * Existing read-only mounts won't be able to be remounted read/write
50962 + * Write operations will be denied on all block devices
50963 + This option acts independently of grsec_lock: once it is set to 1,
50964 + it cannot be turned off. Therefore, please be mindful of the resulting
50965 + behavior if this option is enabled in an init script on a read-only
50966 + filesystem. This feature is mainly intended for secure embedded systems.
50967 +
50968 +config GRKERNSEC_CHROOT
50969 + bool "Chroot jail restrictions"
50970 + default y if GRKERNSEC_CONFIG_AUTO
50971 + help
50972 + If you say Y here, you will be able to choose several options that will
50973 + make breaking out of a chrooted jail much more difficult. If you
50974 + encounter no software incompatibilities with the following options, it
50975 + is recommended that you enable each one.
50976 +
50977 +config GRKERNSEC_CHROOT_MOUNT
50978 + bool "Deny mounts"
50979 + default y if GRKERNSEC_CONFIG_AUTO
50980 + depends on GRKERNSEC_CHROOT
50981 + help
50982 + If you say Y here, processes inside a chroot will not be able to
50983 + mount or remount filesystems. If the sysctl option is enabled, a
50984 + sysctl option with name "chroot_deny_mount" is created.
50985 +
50986 +config GRKERNSEC_CHROOT_DOUBLE
50987 + bool "Deny double-chroots"
50988 + default y if GRKERNSEC_CONFIG_AUTO
50989 + depends on GRKERNSEC_CHROOT
50990 + help
50991 + If you say Y here, processes inside a chroot will not be able to chroot
50992 + again outside the chroot. This is a widely used method of breaking
50993 + out of a chroot jail and should not be allowed. If the sysctl
50994 + option is enabled, a sysctl option with name
50995 + "chroot_deny_chroot" is created.
50996 +
50997 +config GRKERNSEC_CHROOT_PIVOT
50998 + bool "Deny pivot_root in chroot"
50999 + default y if GRKERNSEC_CONFIG_AUTO
51000 + depends on GRKERNSEC_CHROOT
51001 + help
51002 + If you say Y here, processes inside a chroot will not be able to use
51003 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51004 + works similar to chroot in that it changes the root filesystem. This
51005 + function could be misused in a chrooted process to attempt to break out
51006 + of the chroot, and therefore should not be allowed. If the sysctl
51007 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51008 + created.
51009 +
51010 +config GRKERNSEC_CHROOT_CHDIR
51011 + bool "Enforce chdir(\"/\") on all chroots"
51012 + default y if GRKERNSEC_CONFIG_AUTO
51013 + depends on GRKERNSEC_CHROOT
51014 + help
51015 + If you say Y here, the current working directory of all newly-chrooted
51016 + applications will be set to the the root directory of the chroot.
51017 + The man page on chroot(2) states:
51018 + Note that this call does not change the current working
51019 + directory, so that `.' can be outside the tree rooted at
51020 + `/'. In particular, the super-user can escape from a
51021 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51022 +
51023 + It is recommended that you say Y here, since it's not known to break
51024 + any software. If the sysctl option is enabled, a sysctl option with
51025 + name "chroot_enforce_chdir" is created.
51026 +
51027 +config GRKERNSEC_CHROOT_CHMOD
51028 + bool "Deny (f)chmod +s"
51029 + default y if GRKERNSEC_CONFIG_AUTO
51030 + depends on GRKERNSEC_CHROOT
51031 + help
51032 + If you say Y here, processes inside a chroot will not be able to chmod
51033 + or fchmod files to make them have suid or sgid bits. This protects
51034 + against another published method of breaking a chroot. If the sysctl
51035 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51036 + created.
51037 +
51038 +config GRKERNSEC_CHROOT_FCHDIR
51039 + bool "Deny fchdir out of chroot"
51040 + default y if GRKERNSEC_CONFIG_AUTO
51041 + depends on GRKERNSEC_CHROOT
51042 + help
51043 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51044 + to a file descriptor of the chrooting process that points to a directory
51045 + outside the filesystem will be stopped. If the sysctl option
51046 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51047 +
51048 +config GRKERNSEC_CHROOT_MKNOD
51049 + bool "Deny mknod"
51050 + default y if GRKERNSEC_CONFIG_AUTO
51051 + depends on GRKERNSEC_CHROOT
51052 + help
51053 + If you say Y here, processes inside a chroot will not be allowed to
51054 + mknod. The problem with using mknod inside a chroot is that it
51055 + would allow an attacker to create a device entry that is the same
51056 + as one on the physical root of your system, which could range from
51057 + anything from the console device to a device for your harddrive (which
51058 + they could then use to wipe the drive or steal data). It is recommended
51059 + that you say Y here, unless you run into software incompatibilities.
51060 + If the sysctl option is enabled, a sysctl option with name
51061 + "chroot_deny_mknod" is created.
51062 +
51063 +config GRKERNSEC_CHROOT_SHMAT
51064 + bool "Deny shmat() out of chroot"
51065 + default y if GRKERNSEC_CONFIG_AUTO
51066 + depends on GRKERNSEC_CHROOT
51067 + help
51068 + If you say Y here, processes inside a chroot will not be able to attach
51069 + to shared memory segments that were created outside of the chroot jail.
51070 + It is recommended that you say Y here. If the sysctl option is enabled,
51071 + a sysctl option with name "chroot_deny_shmat" is created.
51072 +
51073 +config GRKERNSEC_CHROOT_UNIX
51074 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51075 + default y if GRKERNSEC_CONFIG_AUTO
51076 + depends on GRKERNSEC_CHROOT
51077 + help
51078 + If you say Y here, processes inside a chroot will not be able to
51079 + connect to abstract (meaning not belonging to a filesystem) Unix
51080 + domain sockets that were bound outside of a chroot. It is recommended
51081 + that you say Y here. If the sysctl option is enabled, a sysctl option
51082 + with name "chroot_deny_unix" is created.
51083 +
51084 +config GRKERNSEC_CHROOT_FINDTASK
51085 + bool "Protect outside processes"
51086 + default y if GRKERNSEC_CONFIG_AUTO
51087 + depends on GRKERNSEC_CHROOT
51088 + help
51089 + If you say Y here, processes inside a chroot will not be able to
51090 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51091 + getsid, or view any process outside of the chroot. If the sysctl
51092 + option is enabled, a sysctl option with name "chroot_findtask" is
51093 + created.
51094 +
51095 +config GRKERNSEC_CHROOT_NICE
51096 + bool "Restrict priority changes"
51097 + default y if GRKERNSEC_CONFIG_AUTO
51098 + depends on GRKERNSEC_CHROOT
51099 + help
51100 + If you say Y here, processes inside a chroot will not be able to raise
51101 + the priority of processes in the chroot, or alter the priority of
51102 + processes outside the chroot. This provides more security than simply
51103 + removing CAP_SYS_NICE from the process' capability set. If the
51104 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51105 + is created.
51106 +
51107 +config GRKERNSEC_CHROOT_SYSCTL
51108 + bool "Deny sysctl writes"
51109 + default y if GRKERNSEC_CONFIG_AUTO
51110 + depends on GRKERNSEC_CHROOT
51111 + help
51112 + If you say Y here, an attacker in a chroot will not be able to
51113 + write to sysctl entries, either by sysctl(2) or through a /proc
51114 + interface. It is strongly recommended that you say Y here. If the
51115 + sysctl option is enabled, a sysctl option with name
51116 + "chroot_deny_sysctl" is created.
51117 +
51118 +config GRKERNSEC_CHROOT_CAPS
51119 + bool "Capability restrictions"
51120 + default y if GRKERNSEC_CONFIG_AUTO
51121 + depends on GRKERNSEC_CHROOT
51122 + help
51123 + If you say Y here, the capabilities on all processes within a
51124 + chroot jail will be lowered to stop module insertion, raw i/o,
51125 + system and net admin tasks, rebooting the system, modifying immutable
51126 + files, modifying IPC owned by another, and changing the system time.
51127 + This is left an option because it can break some apps. Disable this
51128 + if your chrooted apps are having problems performing those kinds of
51129 + tasks. If the sysctl option is enabled, a sysctl option with
51130 + name "chroot_caps" is created.
51131 +
51132 +endmenu
51133 +menu "Kernel Auditing"
51134 +depends on GRKERNSEC
51135 +
51136 +config GRKERNSEC_AUDIT_GROUP
51137 + bool "Single group for auditing"
51138 + help
51139 + If you say Y here, the exec, chdir, and (un)mount logging features
51140 + will only operate on a group you specify. This option is recommended
51141 + if you only want to watch certain users instead of having a large
51142 + amount of logs from the entire system. If the sysctl option is enabled,
51143 + a sysctl option with name "audit_group" is created.
51144 +
51145 +config GRKERNSEC_AUDIT_GID
51146 + int "GID for auditing"
51147 + depends on GRKERNSEC_AUDIT_GROUP
51148 + default 1007
51149 +
51150 +config GRKERNSEC_EXECLOG
51151 + bool "Exec logging"
51152 + help
51153 + If you say Y here, all execve() calls will be logged (since the
51154 + other exec*() calls are frontends to execve(), all execution
51155 + will be logged). Useful for shell-servers that like to keep track
51156 + of their users. If the sysctl option is enabled, a sysctl option with
51157 + name "exec_logging" is created.
51158 + WARNING: This option when enabled will produce a LOT of logs, especially
51159 + on an active system.
51160 +
51161 +config GRKERNSEC_RESLOG
51162 + bool "Resource logging"
51163 + default y if GRKERNSEC_CONFIG_AUTO
51164 + help
51165 + If you say Y here, all attempts to overstep resource limits will
51166 + be logged with the resource name, the requested size, and the current
51167 + limit. It is highly recommended that you say Y here. If the sysctl
51168 + option is enabled, a sysctl option with name "resource_logging" is
51169 + created. If the RBAC system is enabled, the sysctl value is ignored.
51170 +
51171 +config GRKERNSEC_CHROOT_EXECLOG
51172 + bool "Log execs within chroot"
51173 + help
51174 + If you say Y here, all executions inside a chroot jail will be logged
51175 + to syslog. This can cause a large amount of logs if certain
51176 + applications (eg. djb's daemontools) are installed on the system, and
51177 + is therefore left as an option. If the sysctl option is enabled, a
51178 + sysctl option with name "chroot_execlog" is created.
51179 +
51180 +config GRKERNSEC_AUDIT_PTRACE
51181 + bool "Ptrace logging"
51182 + help
51183 + If you say Y here, all attempts to attach to a process via ptrace
51184 + will be logged. If the sysctl option is enabled, a sysctl option
51185 + with name "audit_ptrace" is created.
51186 +
51187 +config GRKERNSEC_AUDIT_CHDIR
51188 + bool "Chdir logging"
51189 + help
51190 + If you say Y here, all chdir() calls will be logged. If the sysctl
51191 + option is enabled, a sysctl option with name "audit_chdir" is created.
51192 +
51193 +config GRKERNSEC_AUDIT_MOUNT
51194 + bool "(Un)Mount logging"
51195 + help
51196 + If you say Y here, all mounts and unmounts will be logged. If the
51197 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51198 + created.
51199 +
51200 +config GRKERNSEC_SIGNAL
51201 + bool "Signal logging"
51202 + default y if GRKERNSEC_CONFIG_AUTO
51203 + help
51204 + If you say Y here, certain important signals will be logged, such as
51205 + SIGSEGV, which will as a result inform you of when a error in a program
51206 + occurred, which in some cases could mean a possible exploit attempt.
51207 + If the sysctl option is enabled, a sysctl option with name
51208 + "signal_logging" is created.
51209 +
51210 +config GRKERNSEC_FORKFAIL
51211 + bool "Fork failure logging"
51212 + help
51213 + If you say Y here, all failed fork() attempts will be logged.
51214 + This could suggest a fork bomb, or someone attempting to overstep
51215 + their process limit. If the sysctl option is enabled, a sysctl option
51216 + with name "forkfail_logging" is created.
51217 +
51218 +config GRKERNSEC_TIME
51219 + bool "Time change logging"
51220 + default y if GRKERNSEC_CONFIG_AUTO
51221 + help
51222 + If you say Y here, any changes of the system clock will be logged.
51223 + If the sysctl option is enabled, a sysctl option with name
51224 + "timechange_logging" is created.
51225 +
51226 +config GRKERNSEC_PROC_IPADDR
51227 + bool "/proc/<pid>/ipaddr support"
51228 + default y if GRKERNSEC_CONFIG_AUTO
51229 + help
51230 + If you say Y here, a new entry will be added to each /proc/<pid>
51231 + directory that contains the IP address of the person using the task.
51232 + The IP is carried across local TCP and AF_UNIX stream sockets.
51233 + This information can be useful for IDS/IPSes to perform remote response
51234 + to a local attack. The entry is readable by only the owner of the
51235 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51236 + the RBAC system), and thus does not create privacy concerns.
51237 +
51238 +config GRKERNSEC_RWXMAP_LOG
51239 + bool 'Denied RWX mmap/mprotect logging'
51240 + default y if GRKERNSEC_CONFIG_AUTO
51241 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51242 + help
51243 + If you say Y here, calls to mmap() and mprotect() with explicit
51244 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51245 + denied by the PAX_MPROTECT feature. If the sysctl option is
51246 + enabled, a sysctl option with name "rwxmap_logging" is created.
51247 +
51248 +config GRKERNSEC_AUDIT_TEXTREL
51249 + bool 'ELF text relocations logging (READ HELP)'
51250 + depends on PAX_MPROTECT
51251 + help
51252 + If you say Y here, text relocations will be logged with the filename
51253 + of the offending library or binary. The purpose of the feature is
51254 + to help Linux distribution developers get rid of libraries and
51255 + binaries that need text relocations which hinder the future progress
51256 + of PaX. Only Linux distribution developers should say Y here, and
51257 + never on a production machine, as this option creates an information
51258 + leak that could aid an attacker in defeating the randomization of
51259 + a single memory region. If the sysctl option is enabled, a sysctl
51260 + option with name "audit_textrel" is created.
51261 +
51262 +endmenu
51263 +
51264 +menu "Executable Protections"
51265 +depends on GRKERNSEC
51266 +
51267 +config GRKERNSEC_DMESG
51268 + bool "Dmesg(8) restriction"
51269 + default y if GRKERNSEC_CONFIG_AUTO
51270 + help
51271 + If you say Y here, non-root users will not be able to use dmesg(8)
51272 + to view up to the last 4kb of messages in the kernel's log buffer.
51273 + The kernel's log buffer often contains kernel addresses and other
51274 + identifying information useful to an attacker in fingerprinting a
51275 + system for a targeted exploit.
51276 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51277 + created.
51278 +
51279 +config GRKERNSEC_HARDEN_PTRACE
51280 + bool "Deter ptrace-based process snooping"
51281 + default y if GRKERNSEC_CONFIG_AUTO
51282 + help
51283 + If you say Y here, TTY sniffers and other malicious monitoring
51284 + programs implemented through ptrace will be defeated. If you
51285 + have been using the RBAC system, this option has already been
51286 + enabled for several years for all users, with the ability to make
51287 + fine-grained exceptions.
51288 +
51289 + This option only affects the ability of non-root users to ptrace
51290 + processes that are not a descendent of the ptracing process.
51291 + This means that strace ./binary and gdb ./binary will still work,
51292 + but attaching to arbitrary processes will not. If the sysctl
51293 + option is enabled, a sysctl option with name "harden_ptrace" is
51294 + created.
51295 +
51296 +config GRKERNSEC_PTRACE_READEXEC
51297 + bool "Require read access to ptrace sensitive binaries"
51298 + default y if GRKERNSEC_CONFIG_AUTO
51299 + help
51300 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51301 + binaries. This option is useful in environments that
51302 + remove the read bits (e.g. file mode 4711) from suid binaries to
51303 + prevent infoleaking of their contents. This option adds
51304 + consistency to the use of that file mode, as the binary could normally
51305 + be read out when run without privileges while ptracing.
51306 +
51307 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51308 + is created.
51309 +
51310 +config GRKERNSEC_SETXID
51311 + bool "Enforce consistent multithreaded privileges"
51312 + default y if GRKERNSEC_CONFIG_AUTO
51313 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51314 + help
51315 + If you say Y here, a change from a root uid to a non-root uid
51316 + in a multithreaded application will cause the resulting uids,
51317 + gids, supplementary groups, and capabilities in that thread
51318 + to be propagated to the other threads of the process. In most
51319 + cases this is unnecessary, as glibc will emulate this behavior
51320 + on behalf of the application. Other libcs do not act in the
51321 + same way, allowing the other threads of the process to continue
51322 + running with root privileges. If the sysctl option is enabled,
51323 + a sysctl option with name "consistent_setxid" is created.
51324 +
51325 +config GRKERNSEC_TPE
51326 + bool "Trusted Path Execution (TPE)"
51327 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51328 + help
51329 + If you say Y here, you will be able to choose a gid to add to the
51330 + supplementary groups of users you want to mark as "untrusted."
51331 + These users will not be able to execute any files that are not in
51332 + root-owned directories writable only by root. If the sysctl option
51333 + is enabled, a sysctl option with name "tpe" is created.
51334 +
51335 +config GRKERNSEC_TPE_ALL
51336 + bool "Partially restrict all non-root users"
51337 + depends on GRKERNSEC_TPE
51338 + help
51339 + If you say Y here, all non-root users will be covered under
51340 + a weaker TPE restriction. This is separate from, and in addition to,
51341 + the main TPE options that you have selected elsewhere. Thus, if a
51342 + "trusted" GID is chosen, this restriction applies to even that GID.
51343 + Under this restriction, all non-root users will only be allowed to
51344 + execute files in directories they own that are not group or
51345 + world-writable, or in directories owned by root and writable only by
51346 + root. If the sysctl option is enabled, a sysctl option with name
51347 + "tpe_restrict_all" is created.
51348 +
51349 +config GRKERNSEC_TPE_INVERT
51350 + bool "Invert GID option"
51351 + depends on GRKERNSEC_TPE
51352 + help
51353 + If you say Y here, the group you specify in the TPE configuration will
51354 + decide what group TPE restrictions will be *disabled* for. This
51355 + option is useful if you want TPE restrictions to be applied to most
51356 + users on the system. If the sysctl option is enabled, a sysctl option
51357 + with name "tpe_invert" is created. Unlike other sysctl options, this
51358 + entry will default to on for backward-compatibility.
51359 +
51360 +config GRKERNSEC_TPE_GID
51361 + int
51362 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51363 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51364 +
51365 +config GRKERNSEC_TPE_UNTRUSTED_GID
51366 + int "GID for TPE-untrusted users"
51367 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51368 + default 1005
51369 + help
51370 + Setting this GID determines what group TPE restrictions will be
51371 + *enabled* for. If the sysctl option is enabled, a sysctl option
51372 + with name "tpe_gid" is created.
51373 +
51374 +config GRKERNSEC_TPE_TRUSTED_GID
51375 + int "GID for TPE-trusted users"
51376 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51377 + default 1005
51378 + help
51379 + Setting this GID determines what group TPE restrictions will be
51380 + *disabled* for. If the sysctl option is enabled, a sysctl option
51381 + with name "tpe_gid" is created.
51382 +
51383 +endmenu
51384 +menu "Network Protections"
51385 +depends on GRKERNSEC
51386 +
51387 +config GRKERNSEC_RANDNET
51388 + bool "Larger entropy pools"
51389 + default y if GRKERNSEC_CONFIG_AUTO
51390 + help
51391 + If you say Y here, the entropy pools used for many features of Linux
51392 + and grsecurity will be doubled in size. Since several grsecurity
51393 + features use additional randomness, it is recommended that you say Y
51394 + here. Saying Y here has a similar effect as modifying
51395 + /proc/sys/kernel/random/poolsize.
51396 +
51397 +config GRKERNSEC_BLACKHOLE
51398 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51399 + default y if GRKERNSEC_CONFIG_AUTO
51400 + depends on NET
51401 + help
51402 + If you say Y here, neither TCP resets nor ICMP
51403 + destination-unreachable packets will be sent in response to packets
51404 + sent to ports for which no associated listening process exists.
51405 + This feature supports both IPV4 and IPV6 and exempts the
51406 + loopback interface from blackholing. Enabling this feature
51407 + makes a host more resilient to DoS attacks and reduces network
51408 + visibility against scanners.
51409 +
51410 + The blackhole feature as-implemented is equivalent to the FreeBSD
51411 + blackhole feature, as it prevents RST responses to all packets, not
51412 + just SYNs. Under most application behavior this causes no
51413 + problems, but applications (like haproxy) may not close certain
51414 + connections in a way that cleanly terminates them on the remote
51415 + end, leaving the remote host in LAST_ACK state. Because of this
51416 + side-effect and to prevent intentional LAST_ACK DoSes, this
51417 + feature also adds automatic mitigation against such attacks.
51418 + The mitigation drastically reduces the amount of time a socket
51419 + can spend in LAST_ACK state. If you're using haproxy and not
51420 + all servers it connects to have this option enabled, consider
51421 + disabling this feature on the haproxy host.
51422 +
51423 + If the sysctl option is enabled, two sysctl options with names
51424 + "ip_blackhole" and "lastack_retries" will be created.
51425 + While "ip_blackhole" takes the standard zero/non-zero on/off
51426 + toggle, "lastack_retries" uses the same kinds of values as
51427 + "tcp_retries1" and "tcp_retries2". The default value of 4
51428 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51429 + state.
51430 +
51431 +config GRKERNSEC_SOCKET
51432 + bool "Socket restrictions"
51433 + depends on NET
51434 + help
51435 + If you say Y here, you will be able to choose from several options.
51436 + If you assign a GID on your system and add it to the supplementary
51437 + groups of users you want to restrict socket access to, this patch
51438 + will perform up to three things, based on the option(s) you choose.
51439 +
51440 +config GRKERNSEC_SOCKET_ALL
51441 + bool "Deny any sockets to group"
51442 + depends on GRKERNSEC_SOCKET
51443 + help
51444 + If you say Y here, you will be able to choose a GID of whose users will
51445 + be unable to connect to other hosts from your machine or run server
51446 + applications from your machine. If the sysctl option is enabled, a
51447 + sysctl option with name "socket_all" is created.
51448 +
51449 +config GRKERNSEC_SOCKET_ALL_GID
51450 + int "GID to deny all sockets for"
51451 + depends on GRKERNSEC_SOCKET_ALL
51452 + default 1004
51453 + help
51454 + Here you can choose the GID to disable socket access for. Remember to
51455 + add the users you want socket access disabled for to the GID
51456 + specified here. If the sysctl option is enabled, a sysctl option
51457 + with name "socket_all_gid" is created.
51458 +
51459 +config GRKERNSEC_SOCKET_CLIENT
51460 + bool "Deny client sockets to group"
51461 + depends on GRKERNSEC_SOCKET
51462 + help
51463 + If you say Y here, you will be able to choose a GID of whose users will
51464 + be unable to connect to other hosts from your machine, but will be
51465 + able to run servers. If this option is enabled, all users in the group
51466 + you specify will have to use passive mode when initiating ftp transfers
51467 + from the shell on your machine. If the sysctl option is enabled, a
51468 + sysctl option with name "socket_client" is created.
51469 +
51470 +config GRKERNSEC_SOCKET_CLIENT_GID
51471 + int "GID to deny client sockets for"
51472 + depends on GRKERNSEC_SOCKET_CLIENT
51473 + default 1003
51474 + help
51475 + Here you can choose the GID to disable client socket access for.
51476 + Remember to add the users you want client socket access disabled for to
51477 + the GID specified here. If the sysctl option is enabled, a sysctl
51478 + option with name "socket_client_gid" is created.
51479 +
51480 +config GRKERNSEC_SOCKET_SERVER
51481 + bool "Deny server sockets to group"
51482 + depends on GRKERNSEC_SOCKET
51483 + help
51484 + If you say Y here, you will be able to choose a GID of whose users will
51485 + be unable to run server applications from your machine. If the sysctl
51486 + option is enabled, a sysctl option with name "socket_server" is created.
51487 +
51488 +config GRKERNSEC_SOCKET_SERVER_GID
51489 + int "GID to deny server sockets for"
51490 + depends on GRKERNSEC_SOCKET_SERVER
51491 + default 1002
51492 + help
51493 + Here you can choose the GID to disable server socket access for.
51494 + Remember to add the users you want server socket access disabled for to
51495 + the GID specified here. If the sysctl option is enabled, a sysctl
51496 + option with name "socket_server_gid" is created.
51497 +
51498 +endmenu
51499 +menu "Sysctl Support"
51500 +depends on GRKERNSEC && SYSCTL
51501 +
51502 +config GRKERNSEC_SYSCTL
51503 + bool "Sysctl support"
51504 + default y if GRKERNSEC_CONFIG_AUTO
51505 + help
51506 + If you say Y here, you will be able to change the options that
51507 + grsecurity runs with at bootup, without having to recompile your
51508 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51509 + to enable (1) or disable (0) various features. All the sysctl entries
51510 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51511 + All features enabled in the kernel configuration are disabled at boot
51512 + if you do not say Y to the "Turn on features by default" option.
51513 + All options should be set at startup, and the grsec_lock entry should
51514 + be set to a non-zero value after all the options are set.
51515 + *THIS IS EXTREMELY IMPORTANT*
51516 +
51517 +config GRKERNSEC_SYSCTL_DISTRO
51518 + bool "Extra sysctl support for distro makers (READ HELP)"
51519 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51520 + help
51521 + If you say Y here, additional sysctl options will be created
51522 + for features that affect processes running as root. Therefore,
51523 + it is critical when using this option that the grsec_lock entry be
51524 + enabled after boot. Only distros with prebuilt kernel packages
51525 + with this option enabled that can ensure grsec_lock is enabled
51526 + after boot should use this option.
51527 + *Failure to set grsec_lock after boot makes all grsec features
51528 + this option covers useless*
51529 +
51530 + Currently this option creates the following sysctl entries:
51531 + "Disable Privileged I/O": "disable_priv_io"
51532 +
51533 +config GRKERNSEC_SYSCTL_ON
51534 + bool "Turn on features by default"
51535 + default y if GRKERNSEC_CONFIG_AUTO
51536 + depends on GRKERNSEC_SYSCTL
51537 + help
51538 + If you say Y here, instead of having all features enabled in the
51539 + kernel configuration disabled at boot time, the features will be
51540 + enabled at boot time. It is recommended you say Y here unless
51541 + there is some reason you would want all sysctl-tunable features to
51542 + be disabled by default. As mentioned elsewhere, it is important
51543 + to enable the grsec_lock entry once you have finished modifying
51544 + the sysctl entries.
51545 +
51546 +endmenu
51547 +menu "Logging Options"
51548 +depends on GRKERNSEC
51549 +
51550 +config GRKERNSEC_FLOODTIME
51551 + int "Seconds in between log messages (minimum)"
51552 + default 10
51553 + help
51554 + This option allows you to enforce the number of seconds between
51555 + grsecurity log messages. The default should be suitable for most
51556 + people, however, if you choose to change it, choose a value small enough
51557 + to allow informative logs to be produced, but large enough to
51558 + prevent flooding.
51559 +
51560 +config GRKERNSEC_FLOODBURST
51561 + int "Number of messages in a burst (maximum)"
51562 + default 6
51563 + help
51564 + This option allows you to choose the maximum number of messages allowed
51565 + within the flood time interval you chose in a separate option. The
51566 + default should be suitable for most people, however if you find that
51567 + many of your logs are being interpreted as flooding, you may want to
51568 + raise this value.
51569 +
51570 +endmenu
51571 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51572 new file mode 100644
51573 index 0000000..1b9afa9
51574 --- /dev/null
51575 +++ b/grsecurity/Makefile
51576 @@ -0,0 +1,38 @@
51577 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51578 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51579 +# into an RBAC system
51580 +#
51581 +# All code in this directory and various hooks inserted throughout the kernel
51582 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51583 +# under the GPL v2 or higher
51584 +
51585 +KBUILD_CFLAGS += -Werror
51586 +
51587 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51588 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51589 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51590 +
51591 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51592 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51593 + gracl_learn.o grsec_log.o
51594 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51595 +
51596 +ifdef CONFIG_NET
51597 +obj-y += grsec_sock.o
51598 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51599 +endif
51600 +
51601 +ifndef CONFIG_GRKERNSEC
51602 +obj-y += grsec_disabled.o
51603 +endif
51604 +
51605 +ifdef CONFIG_GRKERNSEC_HIDESYM
51606 +extra-y := grsec_hidesym.o
51607 +$(obj)/grsec_hidesym.o:
51608 + @-chmod -f 500 /boot
51609 + @-chmod -f 500 /lib/modules
51610 + @-chmod -f 500 /lib64/modules
51611 + @-chmod -f 500 /lib32/modules
51612 + @-chmod -f 700 .
51613 + @echo ' grsec: protected kernel image paths'
51614 +endif
51615 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51616 new file mode 100644
51617 index 0000000..b1810d9
51618 --- /dev/null
51619 +++ b/grsecurity/gracl.c
51620 @@ -0,0 +1,4056 @@
51621 +#include <linux/kernel.h>
51622 +#include <linux/module.h>
51623 +#include <linux/sched.h>
51624 +#include <linux/mm.h>
51625 +#include <linux/file.h>
51626 +#include <linux/fs.h>
51627 +#include <linux/namei.h>
51628 +#include <linux/mount.h>
51629 +#include <linux/tty.h>
51630 +#include <linux/proc_fs.h>
51631 +#include <linux/lglock.h>
51632 +#include <linux/slab.h>
51633 +#include <linux/vmalloc.h>
51634 +#include <linux/types.h>
51635 +#include <linux/sysctl.h>
51636 +#include <linux/netdevice.h>
51637 +#include <linux/ptrace.h>
51638 +#include <linux/gracl.h>
51639 +#include <linux/gralloc.h>
51640 +#include <linux/security.h>
51641 +#include <linux/grinternal.h>
51642 +#include <linux/pid_namespace.h>
51643 +#include <linux/stop_machine.h>
51644 +#include <linux/fdtable.h>
51645 +#include <linux/percpu.h>
51646 +#include <linux/lglock.h>
51647 +#include "../fs/mount.h"
51648 +
51649 +#include <asm/uaccess.h>
51650 +#include <asm/errno.h>
51651 +#include <asm/mman.h>
51652 +
51653 +extern struct lglock vfsmount_lock;
51654 +
51655 +static struct acl_role_db acl_role_set;
51656 +static struct name_db name_set;
51657 +static struct inodev_db inodev_set;
51658 +
51659 +/* for keeping track of userspace pointers used for subjects, so we
51660 + can share references in the kernel as well
51661 +*/
51662 +
51663 +static struct path real_root;
51664 +
51665 +static struct acl_subj_map_db subj_map_set;
51666 +
51667 +static struct acl_role_label *default_role;
51668 +
51669 +static struct acl_role_label *role_list;
51670 +
51671 +static u16 acl_sp_role_value;
51672 +
51673 +extern char *gr_shared_page[4];
51674 +static DEFINE_MUTEX(gr_dev_mutex);
51675 +DEFINE_RWLOCK(gr_inode_lock);
51676 +
51677 +struct gr_arg *gr_usermode;
51678 +
51679 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51680 +
51681 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51682 +extern void gr_clear_learn_entries(void);
51683 +
51684 +#ifdef CONFIG_GRKERNSEC_RESLOG
51685 +extern void gr_log_resource(const struct task_struct *task,
51686 + const int res, const unsigned long wanted, const int gt);
51687 +#endif
51688 +
51689 +unsigned char *gr_system_salt;
51690 +unsigned char *gr_system_sum;
51691 +
51692 +static struct sprole_pw **acl_special_roles = NULL;
51693 +static __u16 num_sprole_pws = 0;
51694 +
51695 +static struct acl_role_label *kernel_role = NULL;
51696 +
51697 +static unsigned int gr_auth_attempts = 0;
51698 +static unsigned long gr_auth_expires = 0UL;
51699 +
51700 +#ifdef CONFIG_NET
51701 +extern struct vfsmount *sock_mnt;
51702 +#endif
51703 +
51704 +extern struct vfsmount *pipe_mnt;
51705 +extern struct vfsmount *shm_mnt;
51706 +#ifdef CONFIG_HUGETLBFS
51707 +extern struct vfsmount *hugetlbfs_vfsmount;
51708 +#endif
51709 +
51710 +static struct acl_object_label *fakefs_obj_rw;
51711 +static struct acl_object_label *fakefs_obj_rwx;
51712 +
51713 +extern int gr_init_uidset(void);
51714 +extern void gr_free_uidset(void);
51715 +extern void gr_remove_uid(uid_t uid);
51716 +extern int gr_find_uid(uid_t uid);
51717 +
51718 +__inline__ int
51719 +gr_acl_is_enabled(void)
51720 +{
51721 + return (gr_status & GR_READY);
51722 +}
51723 +
51724 +#ifdef CONFIG_BTRFS_FS
51725 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51726 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51727 +#endif
51728 +
51729 +static inline dev_t __get_dev(const struct dentry *dentry)
51730 +{
51731 +#ifdef CONFIG_BTRFS_FS
51732 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51733 + return get_btrfs_dev_from_inode(dentry->d_inode);
51734 + else
51735 +#endif
51736 + return dentry->d_inode->i_sb->s_dev;
51737 +}
51738 +
51739 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51740 +{
51741 + return __get_dev(dentry);
51742 +}
51743 +
51744 +static char gr_task_roletype_to_char(struct task_struct *task)
51745 +{
51746 + switch (task->role->roletype &
51747 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51748 + GR_ROLE_SPECIAL)) {
51749 + case GR_ROLE_DEFAULT:
51750 + return 'D';
51751 + case GR_ROLE_USER:
51752 + return 'U';
51753 + case GR_ROLE_GROUP:
51754 + return 'G';
51755 + case GR_ROLE_SPECIAL:
51756 + return 'S';
51757 + }
51758 +
51759 + return 'X';
51760 +}
51761 +
51762 +char gr_roletype_to_char(void)
51763 +{
51764 + return gr_task_roletype_to_char(current);
51765 +}
51766 +
51767 +__inline__ int
51768 +gr_acl_tpe_check(void)
51769 +{
51770 + if (unlikely(!(gr_status & GR_READY)))
51771 + return 0;
51772 + if (current->role->roletype & GR_ROLE_TPE)
51773 + return 1;
51774 + else
51775 + return 0;
51776 +}
51777 +
51778 +int
51779 +gr_handle_rawio(const struct inode *inode)
51780 +{
51781 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51782 + if (inode && S_ISBLK(inode->i_mode) &&
51783 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51784 + !capable(CAP_SYS_RAWIO))
51785 + return 1;
51786 +#endif
51787 + return 0;
51788 +}
51789 +
51790 +static int
51791 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51792 +{
51793 + if (likely(lena != lenb))
51794 + return 0;
51795 +
51796 + return !memcmp(a, b, lena);
51797 +}
51798 +
51799 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51800 +{
51801 + *buflen -= namelen;
51802 + if (*buflen < 0)
51803 + return -ENAMETOOLONG;
51804 + *buffer -= namelen;
51805 + memcpy(*buffer, str, namelen);
51806 + return 0;
51807 +}
51808 +
51809 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51810 +{
51811 + return prepend(buffer, buflen, name->name, name->len);
51812 +}
51813 +
51814 +static int prepend_path(const struct path *path, struct path *root,
51815 + char **buffer, int *buflen)
51816 +{
51817 + struct dentry *dentry = path->dentry;
51818 + struct vfsmount *vfsmnt = path->mnt;
51819 + struct mount *mnt = real_mount(vfsmnt);
51820 + bool slash = false;
51821 + int error = 0;
51822 +
51823 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51824 + struct dentry * parent;
51825 +
51826 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51827 + /* Global root? */
51828 + if (!mnt_has_parent(mnt)) {
51829 + goto out;
51830 + }
51831 + dentry = mnt->mnt_mountpoint;
51832 + mnt = mnt->mnt_parent;
51833 + vfsmnt = &mnt->mnt;
51834 + continue;
51835 + }
51836 + parent = dentry->d_parent;
51837 + prefetch(parent);
51838 + spin_lock(&dentry->d_lock);
51839 + error = prepend_name(buffer, buflen, &dentry->d_name);
51840 + spin_unlock(&dentry->d_lock);
51841 + if (!error)
51842 + error = prepend(buffer, buflen, "/", 1);
51843 + if (error)
51844 + break;
51845 +
51846 + slash = true;
51847 + dentry = parent;
51848 + }
51849 +
51850 +out:
51851 + if (!error && !slash)
51852 + error = prepend(buffer, buflen, "/", 1);
51853 +
51854 + return error;
51855 +}
51856 +
51857 +/* this must be called with vfsmount_lock and rename_lock held */
51858 +
51859 +static char *__our_d_path(const struct path *path, struct path *root,
51860 + char *buf, int buflen)
51861 +{
51862 + char *res = buf + buflen;
51863 + int error;
51864 +
51865 + prepend(&res, &buflen, "\0", 1);
51866 + error = prepend_path(path, root, &res, &buflen);
51867 + if (error)
51868 + return ERR_PTR(error);
51869 +
51870 + return res;
51871 +}
51872 +
51873 +static char *
51874 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51875 +{
51876 + char *retval;
51877 +
51878 + retval = __our_d_path(path, root, buf, buflen);
51879 + if (unlikely(IS_ERR(retval)))
51880 + retval = strcpy(buf, "<path too long>");
51881 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51882 + retval[1] = '\0';
51883 +
51884 + return retval;
51885 +}
51886 +
51887 +static char *
51888 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51889 + char *buf, int buflen)
51890 +{
51891 + struct path path;
51892 + char *res;
51893 +
51894 + path.dentry = (struct dentry *)dentry;
51895 + path.mnt = (struct vfsmount *)vfsmnt;
51896 +
51897 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51898 + by the RBAC system */
51899 + res = gen_full_path(&path, &real_root, buf, buflen);
51900 +
51901 + return res;
51902 +}
51903 +
51904 +static char *
51905 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51906 + char *buf, int buflen)
51907 +{
51908 + char *res;
51909 + struct path path;
51910 + struct path root;
51911 + struct task_struct *reaper = init_pid_ns.child_reaper;
51912 +
51913 + path.dentry = (struct dentry *)dentry;
51914 + path.mnt = (struct vfsmount *)vfsmnt;
51915 +
51916 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51917 + get_fs_root(reaper->fs, &root);
51918 +
51919 + write_seqlock(&rename_lock);
51920 + br_read_lock(&vfsmount_lock);
51921 + res = gen_full_path(&path, &root, buf, buflen);
51922 + br_read_unlock(&vfsmount_lock);
51923 + write_sequnlock(&rename_lock);
51924 +
51925 + path_put(&root);
51926 + return res;
51927 +}
51928 +
51929 +static char *
51930 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51931 +{
51932 + char *ret;
51933 + write_seqlock(&rename_lock);
51934 + br_read_lock(&vfsmount_lock);
51935 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51936 + PAGE_SIZE);
51937 + br_read_unlock(&vfsmount_lock);
51938 + write_sequnlock(&rename_lock);
51939 + return ret;
51940 +}
51941 +
51942 +static char *
51943 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51944 +{
51945 + char *ret;
51946 + char *buf;
51947 + int buflen;
51948 +
51949 + write_seqlock(&rename_lock);
51950 + br_read_lock(&vfsmount_lock);
51951 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51952 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51953 + buflen = (int)(ret - buf);
51954 + if (buflen >= 5)
51955 + prepend(&ret, &buflen, "/proc", 5);
51956 + else
51957 + ret = strcpy(buf, "<path too long>");
51958 + br_read_unlock(&vfsmount_lock);
51959 + write_sequnlock(&rename_lock);
51960 + return ret;
51961 +}
51962 +
51963 +char *
51964 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51965 +{
51966 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51967 + PAGE_SIZE);
51968 +}
51969 +
51970 +char *
51971 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51972 +{
51973 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51974 + PAGE_SIZE);
51975 +}
51976 +
51977 +char *
51978 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51979 +{
51980 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51981 + PAGE_SIZE);
51982 +}
51983 +
51984 +char *
51985 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51986 +{
51987 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51988 + PAGE_SIZE);
51989 +}
51990 +
51991 +char *
51992 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51993 +{
51994 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51995 + PAGE_SIZE);
51996 +}
51997 +
51998 +__inline__ __u32
51999 +to_gr_audit(const __u32 reqmode)
52000 +{
52001 + /* masks off auditable permission flags, then shifts them to create
52002 + auditing flags, and adds the special case of append auditing if
52003 + we're requesting write */
52004 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52005 +}
52006 +
52007 +struct acl_subject_label *
52008 +lookup_subject_map(const struct acl_subject_label *userp)
52009 +{
52010 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
52011 + struct subject_map *match;
52012 +
52013 + match = subj_map_set.s_hash[index];
52014 +
52015 + while (match && match->user != userp)
52016 + match = match->next;
52017 +
52018 + if (match != NULL)
52019 + return match->kernel;
52020 + else
52021 + return NULL;
52022 +}
52023 +
52024 +static void
52025 +insert_subj_map_entry(struct subject_map *subjmap)
52026 +{
52027 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
52028 + struct subject_map **curr;
52029 +
52030 + subjmap->prev = NULL;
52031 +
52032 + curr = &subj_map_set.s_hash[index];
52033 + if (*curr != NULL)
52034 + (*curr)->prev = subjmap;
52035 +
52036 + subjmap->next = *curr;
52037 + *curr = subjmap;
52038 +
52039 + return;
52040 +}
52041 +
52042 +static struct acl_role_label *
52043 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52044 + const gid_t gid)
52045 +{
52046 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52047 + struct acl_role_label *match;
52048 + struct role_allowed_ip *ipp;
52049 + unsigned int x;
52050 + u32 curr_ip = task->signal->curr_ip;
52051 +
52052 + task->signal->saved_ip = curr_ip;
52053 +
52054 + match = acl_role_set.r_hash[index];
52055 +
52056 + while (match) {
52057 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52058 + for (x = 0; x < match->domain_child_num; x++) {
52059 + if (match->domain_children[x] == uid)
52060 + goto found;
52061 + }
52062 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52063 + break;
52064 + match = match->next;
52065 + }
52066 +found:
52067 + if (match == NULL) {
52068 + try_group:
52069 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52070 + match = acl_role_set.r_hash[index];
52071 +
52072 + while (match) {
52073 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52074 + for (x = 0; x < match->domain_child_num; x++) {
52075 + if (match->domain_children[x] == gid)
52076 + goto found2;
52077 + }
52078 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52079 + break;
52080 + match = match->next;
52081 + }
52082 +found2:
52083 + if (match == NULL)
52084 + match = default_role;
52085 + if (match->allowed_ips == NULL)
52086 + return match;
52087 + else {
52088 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52089 + if (likely
52090 + ((ntohl(curr_ip) & ipp->netmask) ==
52091 + (ntohl(ipp->addr) & ipp->netmask)))
52092 + return match;
52093 + }
52094 + match = default_role;
52095 + }
52096 + } else if (match->allowed_ips == NULL) {
52097 + return match;
52098 + } else {
52099 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52100 + if (likely
52101 + ((ntohl(curr_ip) & ipp->netmask) ==
52102 + (ntohl(ipp->addr) & ipp->netmask)))
52103 + return match;
52104 + }
52105 + goto try_group;
52106 + }
52107 +
52108 + return match;
52109 +}
52110 +
52111 +struct acl_subject_label *
52112 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52113 + const struct acl_role_label *role)
52114 +{
52115 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
52116 + struct acl_subject_label *match;
52117 +
52118 + match = role->subj_hash[index];
52119 +
52120 + while (match && (match->inode != ino || match->device != dev ||
52121 + (match->mode & GR_DELETED))) {
52122 + match = match->next;
52123 + }
52124 +
52125 + if (match && !(match->mode & GR_DELETED))
52126 + return match;
52127 + else
52128 + return NULL;
52129 +}
52130 +
52131 +struct acl_subject_label *
52132 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52133 + const struct acl_role_label *role)
52134 +{
52135 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
52136 + struct acl_subject_label *match;
52137 +
52138 + match = role->subj_hash[index];
52139 +
52140 + while (match && (match->inode != ino || match->device != dev ||
52141 + !(match->mode & GR_DELETED))) {
52142 + match = match->next;
52143 + }
52144 +
52145 + if (match && (match->mode & GR_DELETED))
52146 + return match;
52147 + else
52148 + return NULL;
52149 +}
52150 +
52151 +static struct acl_object_label *
52152 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52153 + const struct acl_subject_label *subj)
52154 +{
52155 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
52156 + struct acl_object_label *match;
52157 +
52158 + match = subj->obj_hash[index];
52159 +
52160 + while (match && (match->inode != ino || match->device != dev ||
52161 + (match->mode & GR_DELETED))) {
52162 + match = match->next;
52163 + }
52164 +
52165 + if (match && !(match->mode & GR_DELETED))
52166 + return match;
52167 + else
52168 + return NULL;
52169 +}
52170 +
52171 +static struct acl_object_label *
52172 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52173 + const struct acl_subject_label *subj)
52174 +{
52175 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
52176 + struct acl_object_label *match;
52177 +
52178 + match = subj->obj_hash[index];
52179 +
52180 + while (match && (match->inode != ino || match->device != dev ||
52181 + !(match->mode & GR_DELETED))) {
52182 + match = match->next;
52183 + }
52184 +
52185 + if (match && (match->mode & GR_DELETED))
52186 + return match;
52187 +
52188 + match = subj->obj_hash[index];
52189 +
52190 + while (match && (match->inode != ino || match->device != dev ||
52191 + (match->mode & GR_DELETED))) {
52192 + match = match->next;
52193 + }
52194 +
52195 + if (match && !(match->mode & GR_DELETED))
52196 + return match;
52197 + else
52198 + return NULL;
52199 +}
52200 +
52201 +static struct name_entry *
52202 +lookup_name_entry(const char *name)
52203 +{
52204 + unsigned int len = strlen(name);
52205 + unsigned int key = full_name_hash(name, len);
52206 + unsigned int index = key % name_set.n_size;
52207 + struct name_entry *match;
52208 +
52209 + match = name_set.n_hash[index];
52210 +
52211 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52212 + match = match->next;
52213 +
52214 + return match;
52215 +}
52216 +
52217 +static struct name_entry *
52218 +lookup_name_entry_create(const char *name)
52219 +{
52220 + unsigned int len = strlen(name);
52221 + unsigned int key = full_name_hash(name, len);
52222 + unsigned int index = key % name_set.n_size;
52223 + struct name_entry *match;
52224 +
52225 + match = name_set.n_hash[index];
52226 +
52227 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52228 + !match->deleted))
52229 + match = match->next;
52230 +
52231 + if (match && match->deleted)
52232 + return match;
52233 +
52234 + match = name_set.n_hash[index];
52235 +
52236 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52237 + match->deleted))
52238 + match = match->next;
52239 +
52240 + if (match && !match->deleted)
52241 + return match;
52242 + else
52243 + return NULL;
52244 +}
52245 +
52246 +static struct inodev_entry *
52247 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52248 +{
52249 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
52250 + struct inodev_entry *match;
52251 +
52252 + match = inodev_set.i_hash[index];
52253 +
52254 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52255 + match = match->next;
52256 +
52257 + return match;
52258 +}
52259 +
52260 +static void
52261 +insert_inodev_entry(struct inodev_entry *entry)
52262 +{
52263 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
52264 + inodev_set.i_size);
52265 + struct inodev_entry **curr;
52266 +
52267 + entry->prev = NULL;
52268 +
52269 + curr = &inodev_set.i_hash[index];
52270 + if (*curr != NULL)
52271 + (*curr)->prev = entry;
52272 +
52273 + entry->next = *curr;
52274 + *curr = entry;
52275 +
52276 + return;
52277 +}
52278 +
52279 +static void
52280 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52281 +{
52282 + unsigned int index =
52283 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52284 + struct acl_role_label **curr;
52285 + struct acl_role_label *tmp, *tmp2;
52286 +
52287 + curr = &acl_role_set.r_hash[index];
52288 +
52289 + /* simple case, slot is empty, just set it to our role */
52290 + if (*curr == NULL) {
52291 + *curr = role;
52292 + } else {
52293 + /* example:
52294 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52295 + 2 -> 3
52296 + */
52297 + /* first check to see if we can already be reached via this slot */
52298 + tmp = *curr;
52299 + while (tmp && tmp != role)
52300 + tmp = tmp->next;
52301 + if (tmp == role) {
52302 + /* we don't need to add ourselves to this slot's chain */
52303 + return;
52304 + }
52305 + /* we need to add ourselves to this chain, two cases */
52306 + if (role->next == NULL) {
52307 + /* simple case, append the current chain to our role */
52308 + role->next = *curr;
52309 + *curr = role;
52310 + } else {
52311 + /* 1 -> 2 -> 3 -> 4
52312 + 2 -> 3 -> 4
52313 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52314 + */
52315 + /* trickier case: walk our role's chain until we find
52316 + the role for the start of the current slot's chain */
52317 + tmp = role;
52318 + tmp2 = *curr;
52319 + while (tmp->next && tmp->next != tmp2)
52320 + tmp = tmp->next;
52321 + if (tmp->next == tmp2) {
52322 + /* from example above, we found 3, so just
52323 + replace this slot's chain with ours */
52324 + *curr = role;
52325 + } else {
52326 + /* we didn't find a subset of our role's chain
52327 + in the current slot's chain, so append their
52328 + chain to ours, and set us as the first role in
52329 + the slot's chain
52330 +
52331 + we could fold this case with the case above,
52332 + but making it explicit for clarity
52333 + */
52334 + tmp->next = tmp2;
52335 + *curr = role;
52336 + }
52337 + }
52338 + }
52339 +
52340 + return;
52341 +}
52342 +
52343 +static void
52344 +insert_acl_role_label(struct acl_role_label *role)
52345 +{
52346 + int i;
52347 +
52348 + if (role_list == NULL) {
52349 + role_list = role;
52350 + role->prev = NULL;
52351 + } else {
52352 + role->prev = role_list;
52353 + role_list = role;
52354 + }
52355 +
52356 + /* used for hash chains */
52357 + role->next = NULL;
52358 +
52359 + if (role->roletype & GR_ROLE_DOMAIN) {
52360 + for (i = 0; i < role->domain_child_num; i++)
52361 + __insert_acl_role_label(role, role->domain_children[i]);
52362 + } else
52363 + __insert_acl_role_label(role, role->uidgid);
52364 +}
52365 +
52366 +static int
52367 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52368 +{
52369 + struct name_entry **curr, *nentry;
52370 + struct inodev_entry *ientry;
52371 + unsigned int len = strlen(name);
52372 + unsigned int key = full_name_hash(name, len);
52373 + unsigned int index = key % name_set.n_size;
52374 +
52375 + curr = &name_set.n_hash[index];
52376 +
52377 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52378 + curr = &((*curr)->next);
52379 +
52380 + if (*curr != NULL)
52381 + return 1;
52382 +
52383 + nentry = acl_alloc(sizeof (struct name_entry));
52384 + if (nentry == NULL)
52385 + return 0;
52386 + ientry = acl_alloc(sizeof (struct inodev_entry));
52387 + if (ientry == NULL)
52388 + return 0;
52389 + ientry->nentry = nentry;
52390 +
52391 + nentry->key = key;
52392 + nentry->name = name;
52393 + nentry->inode = inode;
52394 + nentry->device = device;
52395 + nentry->len = len;
52396 + nentry->deleted = deleted;
52397 +
52398 + nentry->prev = NULL;
52399 + curr = &name_set.n_hash[index];
52400 + if (*curr != NULL)
52401 + (*curr)->prev = nentry;
52402 + nentry->next = *curr;
52403 + *curr = nentry;
52404 +
52405 + /* insert us into the table searchable by inode/dev */
52406 + insert_inodev_entry(ientry);
52407 +
52408 + return 1;
52409 +}
52410 +
52411 +static void
52412 +insert_acl_obj_label(struct acl_object_label *obj,
52413 + struct acl_subject_label *subj)
52414 +{
52415 + unsigned int index =
52416 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
52417 + struct acl_object_label **curr;
52418 +
52419 +
52420 + obj->prev = NULL;
52421 +
52422 + curr = &subj->obj_hash[index];
52423 + if (*curr != NULL)
52424 + (*curr)->prev = obj;
52425 +
52426 + obj->next = *curr;
52427 + *curr = obj;
52428 +
52429 + return;
52430 +}
52431 +
52432 +static void
52433 +insert_acl_subj_label(struct acl_subject_label *obj,
52434 + struct acl_role_label *role)
52435 +{
52436 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
52437 + struct acl_subject_label **curr;
52438 +
52439 + obj->prev = NULL;
52440 +
52441 + curr = &role->subj_hash[index];
52442 + if (*curr != NULL)
52443 + (*curr)->prev = obj;
52444 +
52445 + obj->next = *curr;
52446 + *curr = obj;
52447 +
52448 + return;
52449 +}
52450 +
52451 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52452 +
52453 +static void *
52454 +create_table(__u32 * len, int elementsize)
52455 +{
52456 + unsigned int table_sizes[] = {
52457 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52458 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52459 + 4194301, 8388593, 16777213, 33554393, 67108859
52460 + };
52461 + void *newtable = NULL;
52462 + unsigned int pwr = 0;
52463 +
52464 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52465 + table_sizes[pwr] <= *len)
52466 + pwr++;
52467 +
52468 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52469 + return newtable;
52470 +
52471 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52472 + newtable =
52473 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52474 + else
52475 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52476 +
52477 + *len = table_sizes[pwr];
52478 +
52479 + return newtable;
52480 +}
52481 +
52482 +static int
52483 +init_variables(const struct gr_arg *arg)
52484 +{
52485 + struct task_struct *reaper = init_pid_ns.child_reaper;
52486 + unsigned int stacksize;
52487 +
52488 + subj_map_set.s_size = arg->role_db.num_subjects;
52489 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52490 + name_set.n_size = arg->role_db.num_objects;
52491 + inodev_set.i_size = arg->role_db.num_objects;
52492 +
52493 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52494 + !name_set.n_size || !inodev_set.i_size)
52495 + return 1;
52496 +
52497 + if (!gr_init_uidset())
52498 + return 1;
52499 +
52500 + /* set up the stack that holds allocation info */
52501 +
52502 + stacksize = arg->role_db.num_pointers + 5;
52503 +
52504 + if (!acl_alloc_stack_init(stacksize))
52505 + return 1;
52506 +
52507 + /* grab reference for the real root dentry and vfsmount */
52508 + get_fs_root(reaper->fs, &real_root);
52509 +
52510 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52511 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52512 +#endif
52513 +
52514 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52515 + if (fakefs_obj_rw == NULL)
52516 + return 1;
52517 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52518 +
52519 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52520 + if (fakefs_obj_rwx == NULL)
52521 + return 1;
52522 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52523 +
52524 + subj_map_set.s_hash =
52525 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52526 + acl_role_set.r_hash =
52527 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52528 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52529 + inodev_set.i_hash =
52530 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52531 +
52532 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52533 + !name_set.n_hash || !inodev_set.i_hash)
52534 + return 1;
52535 +
52536 + memset(subj_map_set.s_hash, 0,
52537 + sizeof(struct subject_map *) * subj_map_set.s_size);
52538 + memset(acl_role_set.r_hash, 0,
52539 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52540 + memset(name_set.n_hash, 0,
52541 + sizeof (struct name_entry *) * name_set.n_size);
52542 + memset(inodev_set.i_hash, 0,
52543 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52544 +
52545 + return 0;
52546 +}
52547 +
52548 +/* free information not needed after startup
52549 + currently contains user->kernel pointer mappings for subjects
52550 +*/
52551 +
52552 +static void
52553 +free_init_variables(void)
52554 +{
52555 + __u32 i;
52556 +
52557 + if (subj_map_set.s_hash) {
52558 + for (i = 0; i < subj_map_set.s_size; i++) {
52559 + if (subj_map_set.s_hash[i]) {
52560 + kfree(subj_map_set.s_hash[i]);
52561 + subj_map_set.s_hash[i] = NULL;
52562 + }
52563 + }
52564 +
52565 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52566 + PAGE_SIZE)
52567 + kfree(subj_map_set.s_hash);
52568 + else
52569 + vfree(subj_map_set.s_hash);
52570 + }
52571 +
52572 + return;
52573 +}
52574 +
52575 +static void
52576 +free_variables(void)
52577 +{
52578 + struct acl_subject_label *s;
52579 + struct acl_role_label *r;
52580 + struct task_struct *task, *task2;
52581 + unsigned int x;
52582 +
52583 + gr_clear_learn_entries();
52584 +
52585 + read_lock(&tasklist_lock);
52586 + do_each_thread(task2, task) {
52587 + task->acl_sp_role = 0;
52588 + task->acl_role_id = 0;
52589 + task->acl = NULL;
52590 + task->role = NULL;
52591 + } while_each_thread(task2, task);
52592 + read_unlock(&tasklist_lock);
52593 +
52594 + /* release the reference to the real root dentry and vfsmount */
52595 + path_put(&real_root);
52596 + memset(&real_root, 0, sizeof(real_root));
52597 +
52598 + /* free all object hash tables */
52599 +
52600 + FOR_EACH_ROLE_START(r)
52601 + if (r->subj_hash == NULL)
52602 + goto next_role;
52603 + FOR_EACH_SUBJECT_START(r, s, x)
52604 + if (s->obj_hash == NULL)
52605 + break;
52606 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52607 + kfree(s->obj_hash);
52608 + else
52609 + vfree(s->obj_hash);
52610 + FOR_EACH_SUBJECT_END(s, x)
52611 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52612 + if (s->obj_hash == NULL)
52613 + break;
52614 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52615 + kfree(s->obj_hash);
52616 + else
52617 + vfree(s->obj_hash);
52618 + FOR_EACH_NESTED_SUBJECT_END(s)
52619 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52620 + kfree(r->subj_hash);
52621 + else
52622 + vfree(r->subj_hash);
52623 + r->subj_hash = NULL;
52624 +next_role:
52625 + FOR_EACH_ROLE_END(r)
52626 +
52627 + acl_free_all();
52628 +
52629 + if (acl_role_set.r_hash) {
52630 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52631 + PAGE_SIZE)
52632 + kfree(acl_role_set.r_hash);
52633 + else
52634 + vfree(acl_role_set.r_hash);
52635 + }
52636 + if (name_set.n_hash) {
52637 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52638 + PAGE_SIZE)
52639 + kfree(name_set.n_hash);
52640 + else
52641 + vfree(name_set.n_hash);
52642 + }
52643 +
52644 + if (inodev_set.i_hash) {
52645 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52646 + PAGE_SIZE)
52647 + kfree(inodev_set.i_hash);
52648 + else
52649 + vfree(inodev_set.i_hash);
52650 + }
52651 +
52652 + gr_free_uidset();
52653 +
52654 + memset(&name_set, 0, sizeof (struct name_db));
52655 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52656 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52657 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52658 +
52659 + default_role = NULL;
52660 + kernel_role = NULL;
52661 + role_list = NULL;
52662 +
52663 + return;
52664 +}
52665 +
52666 +static __u32
52667 +count_user_objs(struct acl_object_label *userp)
52668 +{
52669 + struct acl_object_label o_tmp;
52670 + __u32 num = 0;
52671 +
52672 + while (userp) {
52673 + if (copy_from_user(&o_tmp, userp,
52674 + sizeof (struct acl_object_label)))
52675 + break;
52676 +
52677 + userp = o_tmp.prev;
52678 + num++;
52679 + }
52680 +
52681 + return num;
52682 +}
52683 +
52684 +static struct acl_subject_label *
52685 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
52686 +
52687 +static int
52688 +copy_user_glob(struct acl_object_label *obj)
52689 +{
52690 + struct acl_object_label *g_tmp, **guser;
52691 + unsigned int len;
52692 + char *tmp;
52693 +
52694 + if (obj->globbed == NULL)
52695 + return 0;
52696 +
52697 + guser = &obj->globbed;
52698 + while (*guser) {
52699 + g_tmp = (struct acl_object_label *)
52700 + acl_alloc(sizeof (struct acl_object_label));
52701 + if (g_tmp == NULL)
52702 + return -ENOMEM;
52703 +
52704 + if (copy_from_user(g_tmp, *guser,
52705 + sizeof (struct acl_object_label)))
52706 + return -EFAULT;
52707 +
52708 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52709 +
52710 + if (!len || len >= PATH_MAX)
52711 + return -EINVAL;
52712 +
52713 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52714 + return -ENOMEM;
52715 +
52716 + if (copy_from_user(tmp, g_tmp->filename, len))
52717 + return -EFAULT;
52718 + tmp[len-1] = '\0';
52719 + g_tmp->filename = tmp;
52720 +
52721 + *guser = g_tmp;
52722 + guser = &(g_tmp->next);
52723 + }
52724 +
52725 + return 0;
52726 +}
52727 +
52728 +static int
52729 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52730 + struct acl_role_label *role)
52731 +{
52732 + struct acl_object_label *o_tmp;
52733 + unsigned int len;
52734 + int ret;
52735 + char *tmp;
52736 +
52737 + while (userp) {
52738 + if ((o_tmp = (struct acl_object_label *)
52739 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52740 + return -ENOMEM;
52741 +
52742 + if (copy_from_user(o_tmp, userp,
52743 + sizeof (struct acl_object_label)))
52744 + return -EFAULT;
52745 +
52746 + userp = o_tmp->prev;
52747 +
52748 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52749 +
52750 + if (!len || len >= PATH_MAX)
52751 + return -EINVAL;
52752 +
52753 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52754 + return -ENOMEM;
52755 +
52756 + if (copy_from_user(tmp, o_tmp->filename, len))
52757 + return -EFAULT;
52758 + tmp[len-1] = '\0';
52759 + o_tmp->filename = tmp;
52760 +
52761 + insert_acl_obj_label(o_tmp, subj);
52762 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52763 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52764 + return -ENOMEM;
52765 +
52766 + ret = copy_user_glob(o_tmp);
52767 + if (ret)
52768 + return ret;
52769 +
52770 + if (o_tmp->nested) {
52771 + int already_copied;
52772 +
52773 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
52774 + if (IS_ERR(o_tmp->nested))
52775 + return PTR_ERR(o_tmp->nested);
52776 +
52777 + /* insert into nested subject list if we haven't copied this one yet
52778 + to prevent duplicate entries */
52779 + if (!already_copied) {
52780 + o_tmp->nested->next = role->hash->first;
52781 + role->hash->first = o_tmp->nested;
52782 + }
52783 + }
52784 + }
52785 +
52786 + return 0;
52787 +}
52788 +
52789 +static __u32
52790 +count_user_subjs(struct acl_subject_label *userp)
52791 +{
52792 + struct acl_subject_label s_tmp;
52793 + __u32 num = 0;
52794 +
52795 + while (userp) {
52796 + if (copy_from_user(&s_tmp, userp,
52797 + sizeof (struct acl_subject_label)))
52798 + break;
52799 +
52800 + userp = s_tmp.prev;
52801 + /* do not count nested subjects against this count, since
52802 + they are not included in the hash table, but are
52803 + attached to objects. We have already counted
52804 + the subjects in userspace for the allocation
52805 + stack
52806 + */
52807 + if (!(s_tmp.mode & GR_NESTED))
52808 + num++;
52809 + }
52810 +
52811 + return num;
52812 +}
52813 +
52814 +static int
52815 +copy_user_allowedips(struct acl_role_label *rolep)
52816 +{
52817 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52818 +
52819 + ruserip = rolep->allowed_ips;
52820 +
52821 + while (ruserip) {
52822 + rlast = rtmp;
52823 +
52824 + if ((rtmp = (struct role_allowed_ip *)
52825 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52826 + return -ENOMEM;
52827 +
52828 + if (copy_from_user(rtmp, ruserip,
52829 + sizeof (struct role_allowed_ip)))
52830 + return -EFAULT;
52831 +
52832 + ruserip = rtmp->prev;
52833 +
52834 + if (!rlast) {
52835 + rtmp->prev = NULL;
52836 + rolep->allowed_ips = rtmp;
52837 + } else {
52838 + rlast->next = rtmp;
52839 + rtmp->prev = rlast;
52840 + }
52841 +
52842 + if (!ruserip)
52843 + rtmp->next = NULL;
52844 + }
52845 +
52846 + return 0;
52847 +}
52848 +
52849 +static int
52850 +copy_user_transitions(struct acl_role_label *rolep)
52851 +{
52852 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52853 +
52854 + unsigned int len;
52855 + char *tmp;
52856 +
52857 + rusertp = rolep->transitions;
52858 +
52859 + while (rusertp) {
52860 + rlast = rtmp;
52861 +
52862 + if ((rtmp = (struct role_transition *)
52863 + acl_alloc(sizeof (struct role_transition))) == NULL)
52864 + return -ENOMEM;
52865 +
52866 + if (copy_from_user(rtmp, rusertp,
52867 + sizeof (struct role_transition)))
52868 + return -EFAULT;
52869 +
52870 + rusertp = rtmp->prev;
52871 +
52872 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52873 +
52874 + if (!len || len >= GR_SPROLE_LEN)
52875 + return -EINVAL;
52876 +
52877 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52878 + return -ENOMEM;
52879 +
52880 + if (copy_from_user(tmp, rtmp->rolename, len))
52881 + return -EFAULT;
52882 + tmp[len-1] = '\0';
52883 + rtmp->rolename = tmp;
52884 +
52885 + if (!rlast) {
52886 + rtmp->prev = NULL;
52887 + rolep->transitions = rtmp;
52888 + } else {
52889 + rlast->next = rtmp;
52890 + rtmp->prev = rlast;
52891 + }
52892 +
52893 + if (!rusertp)
52894 + rtmp->next = NULL;
52895 + }
52896 +
52897 + return 0;
52898 +}
52899 +
52900 +static struct acl_subject_label *
52901 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
52902 +{
52903 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52904 + unsigned int len;
52905 + char *tmp;
52906 + __u32 num_objs;
52907 + struct acl_ip_label **i_tmp, *i_utmp2;
52908 + struct gr_hash_struct ghash;
52909 + struct subject_map *subjmap;
52910 + unsigned int i_num;
52911 + int err;
52912 +
52913 + if (already_copied != NULL)
52914 + *already_copied = 0;
52915 +
52916 + s_tmp = lookup_subject_map(userp);
52917 +
52918 + /* we've already copied this subject into the kernel, just return
52919 + the reference to it, and don't copy it over again
52920 + */
52921 + if (s_tmp) {
52922 + if (already_copied != NULL)
52923 + *already_copied = 1;
52924 + return(s_tmp);
52925 + }
52926 +
52927 + if ((s_tmp = (struct acl_subject_label *)
52928 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52929 + return ERR_PTR(-ENOMEM);
52930 +
52931 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52932 + if (subjmap == NULL)
52933 + return ERR_PTR(-ENOMEM);
52934 +
52935 + subjmap->user = userp;
52936 + subjmap->kernel = s_tmp;
52937 + insert_subj_map_entry(subjmap);
52938 +
52939 + if (copy_from_user(s_tmp, userp,
52940 + sizeof (struct acl_subject_label)))
52941 + return ERR_PTR(-EFAULT);
52942 +
52943 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52944 +
52945 + if (!len || len >= PATH_MAX)
52946 + return ERR_PTR(-EINVAL);
52947 +
52948 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52949 + return ERR_PTR(-ENOMEM);
52950 +
52951 + if (copy_from_user(tmp, s_tmp->filename, len))
52952 + return ERR_PTR(-EFAULT);
52953 + tmp[len-1] = '\0';
52954 + s_tmp->filename = tmp;
52955 +
52956 + if (!strcmp(s_tmp->filename, "/"))
52957 + role->root_label = s_tmp;
52958 +
52959 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52960 + return ERR_PTR(-EFAULT);
52961 +
52962 + /* copy user and group transition tables */
52963 +
52964 + if (s_tmp->user_trans_num) {
52965 + uid_t *uidlist;
52966 +
52967 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52968 + if (uidlist == NULL)
52969 + return ERR_PTR(-ENOMEM);
52970 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52971 + return ERR_PTR(-EFAULT);
52972 +
52973 + s_tmp->user_transitions = uidlist;
52974 + }
52975 +
52976 + if (s_tmp->group_trans_num) {
52977 + gid_t *gidlist;
52978 +
52979 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52980 + if (gidlist == NULL)
52981 + return ERR_PTR(-ENOMEM);
52982 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52983 + return ERR_PTR(-EFAULT);
52984 +
52985 + s_tmp->group_transitions = gidlist;
52986 + }
52987 +
52988 + /* set up object hash table */
52989 + num_objs = count_user_objs(ghash.first);
52990 +
52991 + s_tmp->obj_hash_size = num_objs;
52992 + s_tmp->obj_hash =
52993 + (struct acl_object_label **)
52994 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52995 +
52996 + if (!s_tmp->obj_hash)
52997 + return ERR_PTR(-ENOMEM);
52998 +
52999 + memset(s_tmp->obj_hash, 0,
53000 + s_tmp->obj_hash_size *
53001 + sizeof (struct acl_object_label *));
53002 +
53003 + /* add in objects */
53004 + err = copy_user_objs(ghash.first, s_tmp, role);
53005 +
53006 + if (err)
53007 + return ERR_PTR(err);
53008 +
53009 + /* set pointer for parent subject */
53010 + if (s_tmp->parent_subject) {
53011 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53012 +
53013 + if (IS_ERR(s_tmp2))
53014 + return s_tmp2;
53015 +
53016 + s_tmp->parent_subject = s_tmp2;
53017 + }
53018 +
53019 + /* add in ip acls */
53020 +
53021 + if (!s_tmp->ip_num) {
53022 + s_tmp->ips = NULL;
53023 + goto insert;
53024 + }
53025 +
53026 + i_tmp =
53027 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53028 + sizeof (struct acl_ip_label *));
53029 +
53030 + if (!i_tmp)
53031 + return ERR_PTR(-ENOMEM);
53032 +
53033 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53034 + *(i_tmp + i_num) =
53035 + (struct acl_ip_label *)
53036 + acl_alloc(sizeof (struct acl_ip_label));
53037 + if (!*(i_tmp + i_num))
53038 + return ERR_PTR(-ENOMEM);
53039 +
53040 + if (copy_from_user
53041 + (&i_utmp2, s_tmp->ips + i_num,
53042 + sizeof (struct acl_ip_label *)))
53043 + return ERR_PTR(-EFAULT);
53044 +
53045 + if (copy_from_user
53046 + (*(i_tmp + i_num), i_utmp2,
53047 + sizeof (struct acl_ip_label)))
53048 + return ERR_PTR(-EFAULT);
53049 +
53050 + if ((*(i_tmp + i_num))->iface == NULL)
53051 + continue;
53052 +
53053 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53054 + if (!len || len >= IFNAMSIZ)
53055 + return ERR_PTR(-EINVAL);
53056 + tmp = acl_alloc(len);
53057 + if (tmp == NULL)
53058 + return ERR_PTR(-ENOMEM);
53059 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53060 + return ERR_PTR(-EFAULT);
53061 + (*(i_tmp + i_num))->iface = tmp;
53062 + }
53063 +
53064 + s_tmp->ips = i_tmp;
53065 +
53066 +insert:
53067 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53068 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53069 + return ERR_PTR(-ENOMEM);
53070 +
53071 + return s_tmp;
53072 +}
53073 +
53074 +static int
53075 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53076 +{
53077 + struct acl_subject_label s_pre;
53078 + struct acl_subject_label * ret;
53079 + int err;
53080 +
53081 + while (userp) {
53082 + if (copy_from_user(&s_pre, userp,
53083 + sizeof (struct acl_subject_label)))
53084 + return -EFAULT;
53085 +
53086 + /* do not add nested subjects here, add
53087 + while parsing objects
53088 + */
53089 +
53090 + if (s_pre.mode & GR_NESTED) {
53091 + userp = s_pre.prev;
53092 + continue;
53093 + }
53094 +
53095 + ret = do_copy_user_subj(userp, role, NULL);
53096 +
53097 + err = PTR_ERR(ret);
53098 + if (IS_ERR(ret))
53099 + return err;
53100 +
53101 + insert_acl_subj_label(ret, role);
53102 +
53103 + userp = s_pre.prev;
53104 + }
53105 +
53106 + return 0;
53107 +}
53108 +
53109 +static int
53110 +copy_user_acl(struct gr_arg *arg)
53111 +{
53112 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53113 + struct acl_subject_label *subj_list;
53114 + struct sprole_pw *sptmp;
53115 + struct gr_hash_struct *ghash;
53116 + uid_t *domainlist;
53117 + unsigned int r_num;
53118 + unsigned int len;
53119 + char *tmp;
53120 + int err = 0;
53121 + __u16 i;
53122 + __u32 num_subjs;
53123 +
53124 + /* we need a default and kernel role */
53125 + if (arg->role_db.num_roles < 2)
53126 + return -EINVAL;
53127 +
53128 + /* copy special role authentication info from userspace */
53129 +
53130 + num_sprole_pws = arg->num_sprole_pws;
53131 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53132 +
53133 + if (!acl_special_roles && num_sprole_pws)
53134 + return -ENOMEM;
53135 +
53136 + for (i = 0; i < num_sprole_pws; i++) {
53137 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53138 + if (!sptmp)
53139 + return -ENOMEM;
53140 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53141 + sizeof (struct sprole_pw)))
53142 + return -EFAULT;
53143 +
53144 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53145 +
53146 + if (!len || len >= GR_SPROLE_LEN)
53147 + return -EINVAL;
53148 +
53149 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53150 + return -ENOMEM;
53151 +
53152 + if (copy_from_user(tmp, sptmp->rolename, len))
53153 + return -EFAULT;
53154 +
53155 + tmp[len-1] = '\0';
53156 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53157 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53158 +#endif
53159 + sptmp->rolename = tmp;
53160 + acl_special_roles[i] = sptmp;
53161 + }
53162 +
53163 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53164 +
53165 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53166 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53167 +
53168 + if (!r_tmp)
53169 + return -ENOMEM;
53170 +
53171 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53172 + sizeof (struct acl_role_label *)))
53173 + return -EFAULT;
53174 +
53175 + if (copy_from_user(r_tmp, r_utmp2,
53176 + sizeof (struct acl_role_label)))
53177 + return -EFAULT;
53178 +
53179 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53180 +
53181 + if (!len || len >= PATH_MAX)
53182 + return -EINVAL;
53183 +
53184 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53185 + return -ENOMEM;
53186 +
53187 + if (copy_from_user(tmp, r_tmp->rolename, len))
53188 + return -EFAULT;
53189 +
53190 + tmp[len-1] = '\0';
53191 + r_tmp->rolename = tmp;
53192 +
53193 + if (!strcmp(r_tmp->rolename, "default")
53194 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53195 + default_role = r_tmp;
53196 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53197 + kernel_role = r_tmp;
53198 + }
53199 +
53200 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53201 + return -ENOMEM;
53202 +
53203 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53204 + return -EFAULT;
53205 +
53206 + r_tmp->hash = ghash;
53207 +
53208 + num_subjs = count_user_subjs(r_tmp->hash->first);
53209 +
53210 + r_tmp->subj_hash_size = num_subjs;
53211 + r_tmp->subj_hash =
53212 + (struct acl_subject_label **)
53213 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53214 +
53215 + if (!r_tmp->subj_hash)
53216 + return -ENOMEM;
53217 +
53218 + err = copy_user_allowedips(r_tmp);
53219 + if (err)
53220 + return err;
53221 +
53222 + /* copy domain info */
53223 + if (r_tmp->domain_children != NULL) {
53224 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53225 + if (domainlist == NULL)
53226 + return -ENOMEM;
53227 +
53228 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53229 + return -EFAULT;
53230 +
53231 + r_tmp->domain_children = domainlist;
53232 + }
53233 +
53234 + err = copy_user_transitions(r_tmp);
53235 + if (err)
53236 + return err;
53237 +
53238 + memset(r_tmp->subj_hash, 0,
53239 + r_tmp->subj_hash_size *
53240 + sizeof (struct acl_subject_label *));
53241 +
53242 + /* acquire the list of subjects, then NULL out
53243 + the list prior to parsing the subjects for this role,
53244 + as during this parsing the list is replaced with a list
53245 + of *nested* subjects for the role
53246 + */
53247 + subj_list = r_tmp->hash->first;
53248 +
53249 + /* set nested subject list to null */
53250 + r_tmp->hash->first = NULL;
53251 +
53252 + err = copy_user_subjs(subj_list, r_tmp);
53253 +
53254 + if (err)
53255 + return err;
53256 +
53257 + insert_acl_role_label(r_tmp);
53258 + }
53259 +
53260 + if (default_role == NULL || kernel_role == NULL)
53261 + return -EINVAL;
53262 +
53263 + return err;
53264 +}
53265 +
53266 +static int
53267 +gracl_init(struct gr_arg *args)
53268 +{
53269 + int error = 0;
53270 +
53271 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53272 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53273 +
53274 + if (init_variables(args)) {
53275 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53276 + error = -ENOMEM;
53277 + free_variables();
53278 + goto out;
53279 + }
53280 +
53281 + error = copy_user_acl(args);
53282 + free_init_variables();
53283 + if (error) {
53284 + free_variables();
53285 + goto out;
53286 + }
53287 +
53288 + if ((error = gr_set_acls(0))) {
53289 + free_variables();
53290 + goto out;
53291 + }
53292 +
53293 + pax_open_kernel();
53294 + gr_status |= GR_READY;
53295 + pax_close_kernel();
53296 +
53297 + out:
53298 + return error;
53299 +}
53300 +
53301 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53302 +
53303 +static int
53304 +glob_match(const char *p, const char *n)
53305 +{
53306 + char c;
53307 +
53308 + while ((c = *p++) != '\0') {
53309 + switch (c) {
53310 + case '?':
53311 + if (*n == '\0')
53312 + return 1;
53313 + else if (*n == '/')
53314 + return 1;
53315 + break;
53316 + case '\\':
53317 + if (*n != c)
53318 + return 1;
53319 + break;
53320 + case '*':
53321 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53322 + if (*n == '/')
53323 + return 1;
53324 + else if (c == '?') {
53325 + if (*n == '\0')
53326 + return 1;
53327 + else
53328 + ++n;
53329 + }
53330 + }
53331 + if (c == '\0') {
53332 + return 0;
53333 + } else {
53334 + const char *endp;
53335 +
53336 + if ((endp = strchr(n, '/')) == NULL)
53337 + endp = n + strlen(n);
53338 +
53339 + if (c == '[') {
53340 + for (--p; n < endp; ++n)
53341 + if (!glob_match(p, n))
53342 + return 0;
53343 + } else if (c == '/') {
53344 + while (*n != '\0' && *n != '/')
53345 + ++n;
53346 + if (*n == '/' && !glob_match(p, n + 1))
53347 + return 0;
53348 + } else {
53349 + for (--p; n < endp; ++n)
53350 + if (*n == c && !glob_match(p, n))
53351 + return 0;
53352 + }
53353 +
53354 + return 1;
53355 + }
53356 + case '[':
53357 + {
53358 + int not;
53359 + char cold;
53360 +
53361 + if (*n == '\0' || *n == '/')
53362 + return 1;
53363 +
53364 + not = (*p == '!' || *p == '^');
53365 + if (not)
53366 + ++p;
53367 +
53368 + c = *p++;
53369 + for (;;) {
53370 + unsigned char fn = (unsigned char)*n;
53371 +
53372 + if (c == '\0')
53373 + return 1;
53374 + else {
53375 + if (c == fn)
53376 + goto matched;
53377 + cold = c;
53378 + c = *p++;
53379 +
53380 + if (c == '-' && *p != ']') {
53381 + unsigned char cend = *p++;
53382 +
53383 + if (cend == '\0')
53384 + return 1;
53385 +
53386 + if (cold <= fn && fn <= cend)
53387 + goto matched;
53388 +
53389 + c = *p++;
53390 + }
53391 + }
53392 +
53393 + if (c == ']')
53394 + break;
53395 + }
53396 + if (!not)
53397 + return 1;
53398 + break;
53399 + matched:
53400 + while (c != ']') {
53401 + if (c == '\0')
53402 + return 1;
53403 +
53404 + c = *p++;
53405 + }
53406 + if (not)
53407 + return 1;
53408 + }
53409 + break;
53410 + default:
53411 + if (c != *n)
53412 + return 1;
53413 + }
53414 +
53415 + ++n;
53416 + }
53417 +
53418 + if (*n == '\0')
53419 + return 0;
53420 +
53421 + if (*n == '/')
53422 + return 0;
53423 +
53424 + return 1;
53425 +}
53426 +
53427 +static struct acl_object_label *
53428 +chk_glob_label(struct acl_object_label *globbed,
53429 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53430 +{
53431 + struct acl_object_label *tmp;
53432 +
53433 + if (*path == NULL)
53434 + *path = gr_to_filename_nolock(dentry, mnt);
53435 +
53436 + tmp = globbed;
53437 +
53438 + while (tmp) {
53439 + if (!glob_match(tmp->filename, *path))
53440 + return tmp;
53441 + tmp = tmp->next;
53442 + }
53443 +
53444 + return NULL;
53445 +}
53446 +
53447 +static struct acl_object_label *
53448 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53449 + const ino_t curr_ino, const dev_t curr_dev,
53450 + const struct acl_subject_label *subj, char **path, const int checkglob)
53451 +{
53452 + struct acl_subject_label *tmpsubj;
53453 + struct acl_object_label *retval;
53454 + struct acl_object_label *retval2;
53455 +
53456 + tmpsubj = (struct acl_subject_label *) subj;
53457 + read_lock(&gr_inode_lock);
53458 + do {
53459 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53460 + if (retval) {
53461 + if (checkglob && retval->globbed) {
53462 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53463 + if (retval2)
53464 + retval = retval2;
53465 + }
53466 + break;
53467 + }
53468 + } while ((tmpsubj = tmpsubj->parent_subject));
53469 + read_unlock(&gr_inode_lock);
53470 +
53471 + return retval;
53472 +}
53473 +
53474 +static __inline__ struct acl_object_label *
53475 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53476 + struct dentry *curr_dentry,
53477 + const struct acl_subject_label *subj, char **path, const int checkglob)
53478 +{
53479 + int newglob = checkglob;
53480 + ino_t inode;
53481 + dev_t device;
53482 +
53483 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53484 + as we don't want a / * rule to match instead of the / object
53485 + don't do this for create lookups that call this function though, since they're looking up
53486 + on the parent and thus need globbing checks on all paths
53487 + */
53488 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53489 + newglob = GR_NO_GLOB;
53490 +
53491 + spin_lock(&curr_dentry->d_lock);
53492 + inode = curr_dentry->d_inode->i_ino;
53493 + device = __get_dev(curr_dentry);
53494 + spin_unlock(&curr_dentry->d_lock);
53495 +
53496 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53497 +}
53498 +
53499 +static struct acl_object_label *
53500 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53501 + const struct acl_subject_label *subj, char *path, const int checkglob)
53502 +{
53503 + struct dentry *dentry = (struct dentry *) l_dentry;
53504 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53505 + struct mount *real_mnt = real_mount(mnt);
53506 + struct acl_object_label *retval;
53507 + struct dentry *parent;
53508 +
53509 + write_seqlock(&rename_lock);
53510 + br_read_lock(&vfsmount_lock);
53511 +
53512 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53513 +#ifdef CONFIG_NET
53514 + mnt == sock_mnt ||
53515 +#endif
53516 +#ifdef CONFIG_HUGETLBFS
53517 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53518 +#endif
53519 + /* ignore Eric Biederman */
53520 + IS_PRIVATE(l_dentry->d_inode))) {
53521 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53522 + goto out;
53523 + }
53524 +
53525 + for (;;) {
53526 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53527 + break;
53528 +
53529 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53530 + if (!mnt_has_parent(real_mnt))
53531 + break;
53532 +
53533 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53534 + if (retval != NULL)
53535 + goto out;
53536 +
53537 + dentry = real_mnt->mnt_mountpoint;
53538 + real_mnt = real_mnt->mnt_parent;
53539 + mnt = &real_mnt->mnt;
53540 + continue;
53541 + }
53542 +
53543 + parent = dentry->d_parent;
53544 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53545 + if (retval != NULL)
53546 + goto out;
53547 +
53548 + dentry = parent;
53549 + }
53550 +
53551 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53552 +
53553 + /* real_root is pinned so we don't have to hold a reference */
53554 + if (retval == NULL)
53555 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53556 +out:
53557 + br_read_unlock(&vfsmount_lock);
53558 + write_sequnlock(&rename_lock);
53559 +
53560 + BUG_ON(retval == NULL);
53561 +
53562 + return retval;
53563 +}
53564 +
53565 +static __inline__ struct acl_object_label *
53566 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53567 + const struct acl_subject_label *subj)
53568 +{
53569 + char *path = NULL;
53570 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53571 +}
53572 +
53573 +static __inline__ struct acl_object_label *
53574 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53575 + const struct acl_subject_label *subj)
53576 +{
53577 + char *path = NULL;
53578 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53579 +}
53580 +
53581 +static __inline__ struct acl_object_label *
53582 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53583 + const struct acl_subject_label *subj, char *path)
53584 +{
53585 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53586 +}
53587 +
53588 +static struct acl_subject_label *
53589 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53590 + const struct acl_role_label *role)
53591 +{
53592 + struct dentry *dentry = (struct dentry *) l_dentry;
53593 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53594 + struct mount *real_mnt = real_mount(mnt);
53595 + struct acl_subject_label *retval;
53596 + struct dentry *parent;
53597 +
53598 + write_seqlock(&rename_lock);
53599 + br_read_lock(&vfsmount_lock);
53600 +
53601 + for (;;) {
53602 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53603 + break;
53604 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53605 + if (!mnt_has_parent(real_mnt))
53606 + break;
53607 +
53608 + spin_lock(&dentry->d_lock);
53609 + read_lock(&gr_inode_lock);
53610 + retval =
53611 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53612 + __get_dev(dentry), role);
53613 + read_unlock(&gr_inode_lock);
53614 + spin_unlock(&dentry->d_lock);
53615 + if (retval != NULL)
53616 + goto out;
53617 +
53618 + dentry = real_mnt->mnt_mountpoint;
53619 + real_mnt = real_mnt->mnt_parent;
53620 + mnt = &real_mnt->mnt;
53621 + continue;
53622 + }
53623 +
53624 + spin_lock(&dentry->d_lock);
53625 + read_lock(&gr_inode_lock);
53626 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53627 + __get_dev(dentry), role);
53628 + read_unlock(&gr_inode_lock);
53629 + parent = dentry->d_parent;
53630 + spin_unlock(&dentry->d_lock);
53631 +
53632 + if (retval != NULL)
53633 + goto out;
53634 +
53635 + dentry = parent;
53636 + }
53637 +
53638 + spin_lock(&dentry->d_lock);
53639 + read_lock(&gr_inode_lock);
53640 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53641 + __get_dev(dentry), role);
53642 + read_unlock(&gr_inode_lock);
53643 + spin_unlock(&dentry->d_lock);
53644 +
53645 + if (unlikely(retval == NULL)) {
53646 + /* real_root is pinned, we don't need to hold a reference */
53647 + read_lock(&gr_inode_lock);
53648 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53649 + __get_dev(real_root.dentry), role);
53650 + read_unlock(&gr_inode_lock);
53651 + }
53652 +out:
53653 + br_read_unlock(&vfsmount_lock);
53654 + write_sequnlock(&rename_lock);
53655 +
53656 + BUG_ON(retval == NULL);
53657 +
53658 + return retval;
53659 +}
53660 +
53661 +static void
53662 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53663 +{
53664 + struct task_struct *task = current;
53665 + const struct cred *cred = current_cred();
53666 +
53667 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53668 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53669 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53670 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53671 +
53672 + return;
53673 +}
53674 +
53675 +static void
53676 +gr_log_learn_id_change(const char type, const unsigned int real,
53677 + const unsigned int effective, const unsigned int fs)
53678 +{
53679 + struct task_struct *task = current;
53680 + const struct cred *cred = current_cred();
53681 +
53682 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53683 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53684 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53685 + type, real, effective, fs, &task->signal->saved_ip);
53686 +
53687 + return;
53688 +}
53689 +
53690 +__u32
53691 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53692 + const struct vfsmount * mnt)
53693 +{
53694 + __u32 retval = mode;
53695 + struct acl_subject_label *curracl;
53696 + struct acl_object_label *currobj;
53697 +
53698 + if (unlikely(!(gr_status & GR_READY)))
53699 + return (mode & ~GR_AUDITS);
53700 +
53701 + curracl = current->acl;
53702 +
53703 + currobj = chk_obj_label(dentry, mnt, curracl);
53704 + retval = currobj->mode & mode;
53705 +
53706 + /* if we're opening a specified transfer file for writing
53707 + (e.g. /dev/initctl), then transfer our role to init
53708 + */
53709 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53710 + current->role->roletype & GR_ROLE_PERSIST)) {
53711 + struct task_struct *task = init_pid_ns.child_reaper;
53712 +
53713 + if (task->role != current->role) {
53714 + task->acl_sp_role = 0;
53715 + task->acl_role_id = current->acl_role_id;
53716 + task->role = current->role;
53717 + rcu_read_lock();
53718 + read_lock(&grsec_exec_file_lock);
53719 + gr_apply_subject_to_task(task);
53720 + read_unlock(&grsec_exec_file_lock);
53721 + rcu_read_unlock();
53722 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53723 + }
53724 + }
53725 +
53726 + if (unlikely
53727 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53728 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53729 + __u32 new_mode = mode;
53730 +
53731 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53732 +
53733 + retval = new_mode;
53734 +
53735 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53736 + new_mode |= GR_INHERIT;
53737 +
53738 + if (!(mode & GR_NOLEARN))
53739 + gr_log_learn(dentry, mnt, new_mode);
53740 + }
53741 +
53742 + return retval;
53743 +}
53744 +
53745 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53746 + const struct dentry *parent,
53747 + const struct vfsmount *mnt)
53748 +{
53749 + struct name_entry *match;
53750 + struct acl_object_label *matchpo;
53751 + struct acl_subject_label *curracl;
53752 + char *path;
53753 +
53754 + if (unlikely(!(gr_status & GR_READY)))
53755 + return NULL;
53756 +
53757 + preempt_disable();
53758 + path = gr_to_filename_rbac(new_dentry, mnt);
53759 + match = lookup_name_entry_create(path);
53760 +
53761 + curracl = current->acl;
53762 +
53763 + if (match) {
53764 + read_lock(&gr_inode_lock);
53765 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53766 + read_unlock(&gr_inode_lock);
53767 +
53768 + if (matchpo) {
53769 + preempt_enable();
53770 + return matchpo;
53771 + }
53772 + }
53773 +
53774 + // lookup parent
53775 +
53776 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53777 +
53778 + preempt_enable();
53779 + return matchpo;
53780 +}
53781 +
53782 +__u32
53783 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53784 + const struct vfsmount * mnt, const __u32 mode)
53785 +{
53786 + struct acl_object_label *matchpo;
53787 + __u32 retval;
53788 +
53789 + if (unlikely(!(gr_status & GR_READY)))
53790 + return (mode & ~GR_AUDITS);
53791 +
53792 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53793 +
53794 + retval = matchpo->mode & mode;
53795 +
53796 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53797 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53798 + __u32 new_mode = mode;
53799 +
53800 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53801 +
53802 + gr_log_learn(new_dentry, mnt, new_mode);
53803 + return new_mode;
53804 + }
53805 +
53806 + return retval;
53807 +}
53808 +
53809 +__u32
53810 +gr_check_link(const struct dentry * new_dentry,
53811 + const struct dentry * parent_dentry,
53812 + const struct vfsmount * parent_mnt,
53813 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53814 +{
53815 + struct acl_object_label *obj;
53816 + __u32 oldmode, newmode;
53817 + __u32 needmode;
53818 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53819 + GR_DELETE | GR_INHERIT;
53820 +
53821 + if (unlikely(!(gr_status & GR_READY)))
53822 + return (GR_CREATE | GR_LINK);
53823 +
53824 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53825 + oldmode = obj->mode;
53826 +
53827 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53828 + newmode = obj->mode;
53829 +
53830 + needmode = newmode & checkmodes;
53831 +
53832 + // old name for hardlink must have at least the permissions of the new name
53833 + if ((oldmode & needmode) != needmode)
53834 + goto bad;
53835 +
53836 + // if old name had restrictions/auditing, make sure the new name does as well
53837 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53838 +
53839 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53840 + if (is_privileged_binary(old_dentry))
53841 + needmode |= GR_SETID;
53842 +
53843 + if ((newmode & needmode) != needmode)
53844 + goto bad;
53845 +
53846 + // enforce minimum permissions
53847 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53848 + return newmode;
53849 +bad:
53850 + needmode = oldmode;
53851 + if (is_privileged_binary(old_dentry))
53852 + needmode |= GR_SETID;
53853 +
53854 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53855 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53856 + return (GR_CREATE | GR_LINK);
53857 + } else if (newmode & GR_SUPPRESS)
53858 + return GR_SUPPRESS;
53859 + else
53860 + return 0;
53861 +}
53862 +
53863 +int
53864 +gr_check_hidden_task(const struct task_struct *task)
53865 +{
53866 + if (unlikely(!(gr_status & GR_READY)))
53867 + return 0;
53868 +
53869 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53870 + return 1;
53871 +
53872 + return 0;
53873 +}
53874 +
53875 +int
53876 +gr_check_protected_task(const struct task_struct *task)
53877 +{
53878 + if (unlikely(!(gr_status & GR_READY) || !task))
53879 + return 0;
53880 +
53881 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53882 + task->acl != current->acl)
53883 + return 1;
53884 +
53885 + return 0;
53886 +}
53887 +
53888 +int
53889 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53890 +{
53891 + struct task_struct *p;
53892 + int ret = 0;
53893 +
53894 + if (unlikely(!(gr_status & GR_READY) || !pid))
53895 + return ret;
53896 +
53897 + read_lock(&tasklist_lock);
53898 + do_each_pid_task(pid, type, p) {
53899 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53900 + p->acl != current->acl) {
53901 + ret = 1;
53902 + goto out;
53903 + }
53904 + } while_each_pid_task(pid, type, p);
53905 +out:
53906 + read_unlock(&tasklist_lock);
53907 +
53908 + return ret;
53909 +}
53910 +
53911 +void
53912 +gr_copy_label(struct task_struct *tsk)
53913 +{
53914 + tsk->signal->used_accept = 0;
53915 + tsk->acl_sp_role = 0;
53916 + tsk->acl_role_id = current->acl_role_id;
53917 + tsk->acl = current->acl;
53918 + tsk->role = current->role;
53919 + tsk->signal->curr_ip = current->signal->curr_ip;
53920 + tsk->signal->saved_ip = current->signal->saved_ip;
53921 + if (current->exec_file)
53922 + get_file(current->exec_file);
53923 + tsk->exec_file = current->exec_file;
53924 + tsk->is_writable = current->is_writable;
53925 + if (unlikely(current->signal->used_accept)) {
53926 + current->signal->curr_ip = 0;
53927 + current->signal->saved_ip = 0;
53928 + }
53929 +
53930 + return;
53931 +}
53932 +
53933 +static void
53934 +gr_set_proc_res(struct task_struct *task)
53935 +{
53936 + struct acl_subject_label *proc;
53937 + unsigned short i;
53938 +
53939 + proc = task->acl;
53940 +
53941 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53942 + return;
53943 +
53944 + for (i = 0; i < RLIM_NLIMITS; i++) {
53945 + if (!(proc->resmask & (1 << i)))
53946 + continue;
53947 +
53948 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53949 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53950 + }
53951 +
53952 + return;
53953 +}
53954 +
53955 +extern int __gr_process_user_ban(struct user_struct *user);
53956 +
53957 +int
53958 +gr_check_user_change(int real, int effective, int fs)
53959 +{
53960 + unsigned int i;
53961 + __u16 num;
53962 + uid_t *uidlist;
53963 + int curuid;
53964 + int realok = 0;
53965 + int effectiveok = 0;
53966 + int fsok = 0;
53967 +
53968 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53969 + struct user_struct *user;
53970 +
53971 + if (real == -1)
53972 + goto skipit;
53973 +
53974 + user = find_user(real);
53975 + if (user == NULL)
53976 + goto skipit;
53977 +
53978 + if (__gr_process_user_ban(user)) {
53979 + /* for find_user */
53980 + free_uid(user);
53981 + return 1;
53982 + }
53983 +
53984 + /* for find_user */
53985 + free_uid(user);
53986 +
53987 +skipit:
53988 +#endif
53989 +
53990 + if (unlikely(!(gr_status & GR_READY)))
53991 + return 0;
53992 +
53993 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53994 + gr_log_learn_id_change('u', real, effective, fs);
53995 +
53996 + num = current->acl->user_trans_num;
53997 + uidlist = current->acl->user_transitions;
53998 +
53999 + if (uidlist == NULL)
54000 + return 0;
54001 +
54002 + if (real == -1)
54003 + realok = 1;
54004 + if (effective == -1)
54005 + effectiveok = 1;
54006 + if (fs == -1)
54007 + fsok = 1;
54008 +
54009 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54010 + for (i = 0; i < num; i++) {
54011 + curuid = (int)uidlist[i];
54012 + if (real == curuid)
54013 + realok = 1;
54014 + if (effective == curuid)
54015 + effectiveok = 1;
54016 + if (fs == curuid)
54017 + fsok = 1;
54018 + }
54019 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54020 + for (i = 0; i < num; i++) {
54021 + curuid = (int)uidlist[i];
54022 + if (real == curuid)
54023 + break;
54024 + if (effective == curuid)
54025 + break;
54026 + if (fs == curuid)
54027 + break;
54028 + }
54029 + /* not in deny list */
54030 + if (i == num) {
54031 + realok = 1;
54032 + effectiveok = 1;
54033 + fsok = 1;
54034 + }
54035 + }
54036 +
54037 + if (realok && effectiveok && fsok)
54038 + return 0;
54039 + else {
54040 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54041 + return 1;
54042 + }
54043 +}
54044 +
54045 +int
54046 +gr_check_group_change(int real, int effective, int fs)
54047 +{
54048 + unsigned int i;
54049 + __u16 num;
54050 + gid_t *gidlist;
54051 + int curgid;
54052 + int realok = 0;
54053 + int effectiveok = 0;
54054 + int fsok = 0;
54055 +
54056 + if (unlikely(!(gr_status & GR_READY)))
54057 + return 0;
54058 +
54059 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54060 + gr_log_learn_id_change('g', real, effective, fs);
54061 +
54062 + num = current->acl->group_trans_num;
54063 + gidlist = current->acl->group_transitions;
54064 +
54065 + if (gidlist == NULL)
54066 + return 0;
54067 +
54068 + if (real == -1)
54069 + realok = 1;
54070 + if (effective == -1)
54071 + effectiveok = 1;
54072 + if (fs == -1)
54073 + fsok = 1;
54074 +
54075 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54076 + for (i = 0; i < num; i++) {
54077 + curgid = (int)gidlist[i];
54078 + if (real == curgid)
54079 + realok = 1;
54080 + if (effective == curgid)
54081 + effectiveok = 1;
54082 + if (fs == curgid)
54083 + fsok = 1;
54084 + }
54085 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54086 + for (i = 0; i < num; i++) {
54087 + curgid = (int)gidlist[i];
54088 + if (real == curgid)
54089 + break;
54090 + if (effective == curgid)
54091 + break;
54092 + if (fs == curgid)
54093 + break;
54094 + }
54095 + /* not in deny list */
54096 + if (i == num) {
54097 + realok = 1;
54098 + effectiveok = 1;
54099 + fsok = 1;
54100 + }
54101 + }
54102 +
54103 + if (realok && effectiveok && fsok)
54104 + return 0;
54105 + else {
54106 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54107 + return 1;
54108 + }
54109 +}
54110 +
54111 +extern int gr_acl_is_capable(const int cap);
54112 +
54113 +void
54114 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54115 +{
54116 + struct acl_role_label *role = task->role;
54117 + struct acl_subject_label *subj = NULL;
54118 + struct acl_object_label *obj;
54119 + struct file *filp;
54120 +
54121 + if (unlikely(!(gr_status & GR_READY)))
54122 + return;
54123 +
54124 + filp = task->exec_file;
54125 +
54126 + /* kernel process, we'll give them the kernel role */
54127 + if (unlikely(!filp)) {
54128 + task->role = kernel_role;
54129 + task->acl = kernel_role->root_label;
54130 + return;
54131 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54132 + role = lookup_acl_role_label(task, uid, gid);
54133 +
54134 + /* don't change the role if we're not a privileged process */
54135 + if (role && task->role != role &&
54136 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54137 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54138 + return;
54139 +
54140 + /* perform subject lookup in possibly new role
54141 + we can use this result below in the case where role == task->role
54142 + */
54143 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54144 +
54145 + /* if we changed uid/gid, but result in the same role
54146 + and are using inheritance, don't lose the inherited subject
54147 + if current subject is other than what normal lookup
54148 + would result in, we arrived via inheritance, don't
54149 + lose subject
54150 + */
54151 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54152 + (subj == task->acl)))
54153 + task->acl = subj;
54154 +
54155 + task->role = role;
54156 +
54157 + task->is_writable = 0;
54158 +
54159 + /* ignore additional mmap checks for processes that are writable
54160 + by the default ACL */
54161 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54162 + if (unlikely(obj->mode & GR_WRITE))
54163 + task->is_writable = 1;
54164 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54165 + if (unlikely(obj->mode & GR_WRITE))
54166 + task->is_writable = 1;
54167 +
54168 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54169 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54170 +#endif
54171 +
54172 + gr_set_proc_res(task);
54173 +
54174 + return;
54175 +}
54176 +
54177 +int
54178 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54179 + const int unsafe_flags)
54180 +{
54181 + struct task_struct *task = current;
54182 + struct acl_subject_label *newacl;
54183 + struct acl_object_label *obj;
54184 + __u32 retmode;
54185 +
54186 + if (unlikely(!(gr_status & GR_READY)))
54187 + return 0;
54188 +
54189 + newacl = chk_subj_label(dentry, mnt, task->role);
54190 +
54191 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54192 + did an exec
54193 + */
54194 + rcu_read_lock();
54195 + read_lock(&tasklist_lock);
54196 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54197 + (task->parent->acl->mode & GR_POVERRIDE))) {
54198 + read_unlock(&tasklist_lock);
54199 + rcu_read_unlock();
54200 + goto skip_check;
54201 + }
54202 + read_unlock(&tasklist_lock);
54203 + rcu_read_unlock();
54204 +
54205 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54206 + !(task->role->roletype & GR_ROLE_GOD) &&
54207 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54208 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54209 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54210 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54211 + else
54212 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54213 + return -EACCES;
54214 + }
54215 +
54216 +skip_check:
54217 +
54218 + obj = chk_obj_label(dentry, mnt, task->acl);
54219 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54220 +
54221 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54222 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54223 + if (obj->nested)
54224 + task->acl = obj->nested;
54225 + else
54226 + task->acl = newacl;
54227 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54228 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54229 +
54230 + task->is_writable = 0;
54231 +
54232 + /* ignore additional mmap checks for processes that are writable
54233 + by the default ACL */
54234 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54235 + if (unlikely(obj->mode & GR_WRITE))
54236 + task->is_writable = 1;
54237 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54238 + if (unlikely(obj->mode & GR_WRITE))
54239 + task->is_writable = 1;
54240 +
54241 + gr_set_proc_res(task);
54242 +
54243 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54244 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54245 +#endif
54246 + return 0;
54247 +}
54248 +
54249 +/* always called with valid inodev ptr */
54250 +static void
54251 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54252 +{
54253 + struct acl_object_label *matchpo;
54254 + struct acl_subject_label *matchps;
54255 + struct acl_subject_label *subj;
54256 + struct acl_role_label *role;
54257 + unsigned int x;
54258 +
54259 + FOR_EACH_ROLE_START(role)
54260 + FOR_EACH_SUBJECT_START(role, subj, x)
54261 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54262 + matchpo->mode |= GR_DELETED;
54263 + FOR_EACH_SUBJECT_END(subj,x)
54264 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54265 + /* nested subjects aren't in the role's subj_hash table */
54266 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54267 + matchpo->mode |= GR_DELETED;
54268 + FOR_EACH_NESTED_SUBJECT_END(subj)
54269 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54270 + matchps->mode |= GR_DELETED;
54271 + FOR_EACH_ROLE_END(role)
54272 +
54273 + inodev->nentry->deleted = 1;
54274 +
54275 + return;
54276 +}
54277 +
54278 +void
54279 +gr_handle_delete(const ino_t ino, const dev_t dev)
54280 +{
54281 + struct inodev_entry *inodev;
54282 +
54283 + if (unlikely(!(gr_status & GR_READY)))
54284 + return;
54285 +
54286 + write_lock(&gr_inode_lock);
54287 + inodev = lookup_inodev_entry(ino, dev);
54288 + if (inodev != NULL)
54289 + do_handle_delete(inodev, ino, dev);
54290 + write_unlock(&gr_inode_lock);
54291 +
54292 + return;
54293 +}
54294 +
54295 +static void
54296 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54297 + const ino_t newinode, const dev_t newdevice,
54298 + struct acl_subject_label *subj)
54299 +{
54300 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
54301 + struct acl_object_label *match;
54302 +
54303 + match = subj->obj_hash[index];
54304 +
54305 + while (match && (match->inode != oldinode ||
54306 + match->device != olddevice ||
54307 + !(match->mode & GR_DELETED)))
54308 + match = match->next;
54309 +
54310 + if (match && (match->inode == oldinode)
54311 + && (match->device == olddevice)
54312 + && (match->mode & GR_DELETED)) {
54313 + if (match->prev == NULL) {
54314 + subj->obj_hash[index] = match->next;
54315 + if (match->next != NULL)
54316 + match->next->prev = NULL;
54317 + } else {
54318 + match->prev->next = match->next;
54319 + if (match->next != NULL)
54320 + match->next->prev = match->prev;
54321 + }
54322 + match->prev = NULL;
54323 + match->next = NULL;
54324 + match->inode = newinode;
54325 + match->device = newdevice;
54326 + match->mode &= ~GR_DELETED;
54327 +
54328 + insert_acl_obj_label(match, subj);
54329 + }
54330 +
54331 + return;
54332 +}
54333 +
54334 +static void
54335 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54336 + const ino_t newinode, const dev_t newdevice,
54337 + struct acl_role_label *role)
54338 +{
54339 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
54340 + struct acl_subject_label *match;
54341 +
54342 + match = role->subj_hash[index];
54343 +
54344 + while (match && (match->inode != oldinode ||
54345 + match->device != olddevice ||
54346 + !(match->mode & GR_DELETED)))
54347 + match = match->next;
54348 +
54349 + if (match && (match->inode == oldinode)
54350 + && (match->device == olddevice)
54351 + && (match->mode & GR_DELETED)) {
54352 + if (match->prev == NULL) {
54353 + role->subj_hash[index] = match->next;
54354 + if (match->next != NULL)
54355 + match->next->prev = NULL;
54356 + } else {
54357 + match->prev->next = match->next;
54358 + if (match->next != NULL)
54359 + match->next->prev = match->prev;
54360 + }
54361 + match->prev = NULL;
54362 + match->next = NULL;
54363 + match->inode = newinode;
54364 + match->device = newdevice;
54365 + match->mode &= ~GR_DELETED;
54366 +
54367 + insert_acl_subj_label(match, role);
54368 + }
54369 +
54370 + return;
54371 +}
54372 +
54373 +static void
54374 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54375 + const ino_t newinode, const dev_t newdevice)
54376 +{
54377 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
54378 + struct inodev_entry *match;
54379 +
54380 + match = inodev_set.i_hash[index];
54381 +
54382 + while (match && (match->nentry->inode != oldinode ||
54383 + match->nentry->device != olddevice || !match->nentry->deleted))
54384 + match = match->next;
54385 +
54386 + if (match && (match->nentry->inode == oldinode)
54387 + && (match->nentry->device == olddevice) &&
54388 + match->nentry->deleted) {
54389 + if (match->prev == NULL) {
54390 + inodev_set.i_hash[index] = match->next;
54391 + if (match->next != NULL)
54392 + match->next->prev = NULL;
54393 + } else {
54394 + match->prev->next = match->next;
54395 + if (match->next != NULL)
54396 + match->next->prev = match->prev;
54397 + }
54398 + match->prev = NULL;
54399 + match->next = NULL;
54400 + match->nentry->inode = newinode;
54401 + match->nentry->device = newdevice;
54402 + match->nentry->deleted = 0;
54403 +
54404 + insert_inodev_entry(match);
54405 + }
54406 +
54407 + return;
54408 +}
54409 +
54410 +static void
54411 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54412 +{
54413 + struct acl_subject_label *subj;
54414 + struct acl_role_label *role;
54415 + unsigned int x;
54416 +
54417 + FOR_EACH_ROLE_START(role)
54418 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54419 +
54420 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54421 + if ((subj->inode == ino) && (subj->device == dev)) {
54422 + subj->inode = ino;
54423 + subj->device = dev;
54424 + }
54425 + /* nested subjects aren't in the role's subj_hash table */
54426 + update_acl_obj_label(matchn->inode, matchn->device,
54427 + ino, dev, subj);
54428 + FOR_EACH_NESTED_SUBJECT_END(subj)
54429 + FOR_EACH_SUBJECT_START(role, subj, x)
54430 + update_acl_obj_label(matchn->inode, matchn->device,
54431 + ino, dev, subj);
54432 + FOR_EACH_SUBJECT_END(subj,x)
54433 + FOR_EACH_ROLE_END(role)
54434 +
54435 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54436 +
54437 + return;
54438 +}
54439 +
54440 +static void
54441 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54442 + const struct vfsmount *mnt)
54443 +{
54444 + ino_t ino = dentry->d_inode->i_ino;
54445 + dev_t dev = __get_dev(dentry);
54446 +
54447 + __do_handle_create(matchn, ino, dev);
54448 +
54449 + return;
54450 +}
54451 +
54452 +void
54453 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54454 +{
54455 + struct name_entry *matchn;
54456 +
54457 + if (unlikely(!(gr_status & GR_READY)))
54458 + return;
54459 +
54460 + preempt_disable();
54461 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54462 +
54463 + if (unlikely((unsigned long)matchn)) {
54464 + write_lock(&gr_inode_lock);
54465 + do_handle_create(matchn, dentry, mnt);
54466 + write_unlock(&gr_inode_lock);
54467 + }
54468 + preempt_enable();
54469 +
54470 + return;
54471 +}
54472 +
54473 +void
54474 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54475 +{
54476 + struct name_entry *matchn;
54477 +
54478 + if (unlikely(!(gr_status & GR_READY)))
54479 + return;
54480 +
54481 + preempt_disable();
54482 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54483 +
54484 + if (unlikely((unsigned long)matchn)) {
54485 + write_lock(&gr_inode_lock);
54486 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54487 + write_unlock(&gr_inode_lock);
54488 + }
54489 + preempt_enable();
54490 +
54491 + return;
54492 +}
54493 +
54494 +void
54495 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54496 + struct dentry *old_dentry,
54497 + struct dentry *new_dentry,
54498 + struct vfsmount *mnt, const __u8 replace)
54499 +{
54500 + struct name_entry *matchn;
54501 + struct inodev_entry *inodev;
54502 + struct inode *inode = new_dentry->d_inode;
54503 + ino_t old_ino = old_dentry->d_inode->i_ino;
54504 + dev_t old_dev = __get_dev(old_dentry);
54505 +
54506 + /* vfs_rename swaps the name and parent link for old_dentry and
54507 + new_dentry
54508 + at this point, old_dentry has the new name, parent link, and inode
54509 + for the renamed file
54510 + if a file is being replaced by a rename, new_dentry has the inode
54511 + and name for the replaced file
54512 + */
54513 +
54514 + if (unlikely(!(gr_status & GR_READY)))
54515 + return;
54516 +
54517 + preempt_disable();
54518 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54519 +
54520 + /* we wouldn't have to check d_inode if it weren't for
54521 + NFS silly-renaming
54522 + */
54523 +
54524 + write_lock(&gr_inode_lock);
54525 + if (unlikely(replace && inode)) {
54526 + ino_t new_ino = inode->i_ino;
54527 + dev_t new_dev = __get_dev(new_dentry);
54528 +
54529 + inodev = lookup_inodev_entry(new_ino, new_dev);
54530 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54531 + do_handle_delete(inodev, new_ino, new_dev);
54532 + }
54533 +
54534 + inodev = lookup_inodev_entry(old_ino, old_dev);
54535 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54536 + do_handle_delete(inodev, old_ino, old_dev);
54537 +
54538 + if (unlikely((unsigned long)matchn))
54539 + do_handle_create(matchn, old_dentry, mnt);
54540 +
54541 + write_unlock(&gr_inode_lock);
54542 + preempt_enable();
54543 +
54544 + return;
54545 +}
54546 +
54547 +static int
54548 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54549 + unsigned char **sum)
54550 +{
54551 + struct acl_role_label *r;
54552 + struct role_allowed_ip *ipp;
54553 + struct role_transition *trans;
54554 + unsigned int i;
54555 + int found = 0;
54556 + u32 curr_ip = current->signal->curr_ip;
54557 +
54558 + current->signal->saved_ip = curr_ip;
54559 +
54560 + /* check transition table */
54561 +
54562 + for (trans = current->role->transitions; trans; trans = trans->next) {
54563 + if (!strcmp(rolename, trans->rolename)) {
54564 + found = 1;
54565 + break;
54566 + }
54567 + }
54568 +
54569 + if (!found)
54570 + return 0;
54571 +
54572 + /* handle special roles that do not require authentication
54573 + and check ip */
54574 +
54575 + FOR_EACH_ROLE_START(r)
54576 + if (!strcmp(rolename, r->rolename) &&
54577 + (r->roletype & GR_ROLE_SPECIAL)) {
54578 + found = 0;
54579 + if (r->allowed_ips != NULL) {
54580 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54581 + if ((ntohl(curr_ip) & ipp->netmask) ==
54582 + (ntohl(ipp->addr) & ipp->netmask))
54583 + found = 1;
54584 + }
54585 + } else
54586 + found = 2;
54587 + if (!found)
54588 + return 0;
54589 +
54590 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54591 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54592 + *salt = NULL;
54593 + *sum = NULL;
54594 + return 1;
54595 + }
54596 + }
54597 + FOR_EACH_ROLE_END(r)
54598 +
54599 + for (i = 0; i < num_sprole_pws; i++) {
54600 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54601 + *salt = acl_special_roles[i]->salt;
54602 + *sum = acl_special_roles[i]->sum;
54603 + return 1;
54604 + }
54605 + }
54606 +
54607 + return 0;
54608 +}
54609 +
54610 +static void
54611 +assign_special_role(char *rolename)
54612 +{
54613 + struct acl_object_label *obj;
54614 + struct acl_role_label *r;
54615 + struct acl_role_label *assigned = NULL;
54616 + struct task_struct *tsk;
54617 + struct file *filp;
54618 +
54619 + FOR_EACH_ROLE_START(r)
54620 + if (!strcmp(rolename, r->rolename) &&
54621 + (r->roletype & GR_ROLE_SPECIAL)) {
54622 + assigned = r;
54623 + break;
54624 + }
54625 + FOR_EACH_ROLE_END(r)
54626 +
54627 + if (!assigned)
54628 + return;
54629 +
54630 + read_lock(&tasklist_lock);
54631 + read_lock(&grsec_exec_file_lock);
54632 +
54633 + tsk = current->real_parent;
54634 + if (tsk == NULL)
54635 + goto out_unlock;
54636 +
54637 + filp = tsk->exec_file;
54638 + if (filp == NULL)
54639 + goto out_unlock;
54640 +
54641 + tsk->is_writable = 0;
54642 +
54643 + tsk->acl_sp_role = 1;
54644 + tsk->acl_role_id = ++acl_sp_role_value;
54645 + tsk->role = assigned;
54646 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54647 +
54648 + /* ignore additional mmap checks for processes that are writable
54649 + by the default ACL */
54650 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54651 + if (unlikely(obj->mode & GR_WRITE))
54652 + tsk->is_writable = 1;
54653 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54654 + if (unlikely(obj->mode & GR_WRITE))
54655 + tsk->is_writable = 1;
54656 +
54657 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54658 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54659 +#endif
54660 +
54661 +out_unlock:
54662 + read_unlock(&grsec_exec_file_lock);
54663 + read_unlock(&tasklist_lock);
54664 + return;
54665 +}
54666 +
54667 +int gr_check_secure_terminal(struct task_struct *task)
54668 +{
54669 + struct task_struct *p, *p2, *p3;
54670 + struct files_struct *files;
54671 + struct fdtable *fdt;
54672 + struct file *our_file = NULL, *file;
54673 + int i;
54674 +
54675 + if (task->signal->tty == NULL)
54676 + return 1;
54677 +
54678 + files = get_files_struct(task);
54679 + if (files != NULL) {
54680 + rcu_read_lock();
54681 + fdt = files_fdtable(files);
54682 + for (i=0; i < fdt->max_fds; i++) {
54683 + file = fcheck_files(files, i);
54684 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54685 + get_file(file);
54686 + our_file = file;
54687 + }
54688 + }
54689 + rcu_read_unlock();
54690 + put_files_struct(files);
54691 + }
54692 +
54693 + if (our_file == NULL)
54694 + return 1;
54695 +
54696 + read_lock(&tasklist_lock);
54697 + do_each_thread(p2, p) {
54698 + files = get_files_struct(p);
54699 + if (files == NULL ||
54700 + (p->signal && p->signal->tty == task->signal->tty)) {
54701 + if (files != NULL)
54702 + put_files_struct(files);
54703 + continue;
54704 + }
54705 + rcu_read_lock();
54706 + fdt = files_fdtable(files);
54707 + for (i=0; i < fdt->max_fds; i++) {
54708 + file = fcheck_files(files, i);
54709 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54710 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54711 + p3 = task;
54712 + while (p3->pid > 0) {
54713 + if (p3 == p)
54714 + break;
54715 + p3 = p3->real_parent;
54716 + }
54717 + if (p3 == p)
54718 + break;
54719 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54720 + gr_handle_alertkill(p);
54721 + rcu_read_unlock();
54722 + put_files_struct(files);
54723 + read_unlock(&tasklist_lock);
54724 + fput(our_file);
54725 + return 0;
54726 + }
54727 + }
54728 + rcu_read_unlock();
54729 + put_files_struct(files);
54730 + } while_each_thread(p2, p);
54731 + read_unlock(&tasklist_lock);
54732 +
54733 + fput(our_file);
54734 + return 1;
54735 +}
54736 +
54737 +static int gr_rbac_disable(void *unused)
54738 +{
54739 + pax_open_kernel();
54740 + gr_status &= ~GR_READY;
54741 + pax_close_kernel();
54742 +
54743 + return 0;
54744 +}
54745 +
54746 +ssize_t
54747 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54748 +{
54749 + struct gr_arg_wrapper uwrap;
54750 + unsigned char *sprole_salt = NULL;
54751 + unsigned char *sprole_sum = NULL;
54752 + int error = sizeof (struct gr_arg_wrapper);
54753 + int error2 = 0;
54754 +
54755 + mutex_lock(&gr_dev_mutex);
54756 +
54757 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54758 + error = -EPERM;
54759 + goto out;
54760 + }
54761 +
54762 + if (count != sizeof (struct gr_arg_wrapper)) {
54763 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54764 + error = -EINVAL;
54765 + goto out;
54766 + }
54767 +
54768 +
54769 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54770 + gr_auth_expires = 0;
54771 + gr_auth_attempts = 0;
54772 + }
54773 +
54774 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54775 + error = -EFAULT;
54776 + goto out;
54777 + }
54778 +
54779 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54780 + error = -EINVAL;
54781 + goto out;
54782 + }
54783 +
54784 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54785 + error = -EFAULT;
54786 + goto out;
54787 + }
54788 +
54789 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54790 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54791 + time_after(gr_auth_expires, get_seconds())) {
54792 + error = -EBUSY;
54793 + goto out;
54794 + }
54795 +
54796 + /* if non-root trying to do anything other than use a special role,
54797 + do not attempt authentication, do not count towards authentication
54798 + locking
54799 + */
54800 +
54801 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54802 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54803 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54804 + error = -EPERM;
54805 + goto out;
54806 + }
54807 +
54808 + /* ensure pw and special role name are null terminated */
54809 +
54810 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54811 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54812 +
54813 + /* Okay.
54814 + * We have our enough of the argument structure..(we have yet
54815 + * to copy_from_user the tables themselves) . Copy the tables
54816 + * only if we need them, i.e. for loading operations. */
54817 +
54818 + switch (gr_usermode->mode) {
54819 + case GR_STATUS:
54820 + if (gr_status & GR_READY) {
54821 + error = 1;
54822 + if (!gr_check_secure_terminal(current))
54823 + error = 3;
54824 + } else
54825 + error = 2;
54826 + goto out;
54827 + case GR_SHUTDOWN:
54828 + if ((gr_status & GR_READY)
54829 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54830 + stop_machine(gr_rbac_disable, NULL, NULL);
54831 + free_variables();
54832 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54833 + memset(gr_system_salt, 0, GR_SALT_LEN);
54834 + memset(gr_system_sum, 0, GR_SHA_LEN);
54835 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54836 + } else if (gr_status & GR_READY) {
54837 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54838 + error = -EPERM;
54839 + } else {
54840 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54841 + error = -EAGAIN;
54842 + }
54843 + break;
54844 + case GR_ENABLE:
54845 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54846 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54847 + else {
54848 + if (gr_status & GR_READY)
54849 + error = -EAGAIN;
54850 + else
54851 + error = error2;
54852 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54853 + }
54854 + break;
54855 + case GR_RELOAD:
54856 + if (!(gr_status & GR_READY)) {
54857 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54858 + error = -EAGAIN;
54859 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54860 + stop_machine(gr_rbac_disable, NULL, NULL);
54861 + free_variables();
54862 + error2 = gracl_init(gr_usermode);
54863 + if (!error2)
54864 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54865 + else {
54866 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54867 + error = error2;
54868 + }
54869 + } else {
54870 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54871 + error = -EPERM;
54872 + }
54873 + break;
54874 + case GR_SEGVMOD:
54875 + if (unlikely(!(gr_status & GR_READY))) {
54876 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54877 + error = -EAGAIN;
54878 + break;
54879 + }
54880 +
54881 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54882 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54883 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54884 + struct acl_subject_label *segvacl;
54885 + segvacl =
54886 + lookup_acl_subj_label(gr_usermode->segv_inode,
54887 + gr_usermode->segv_device,
54888 + current->role);
54889 + if (segvacl) {
54890 + segvacl->crashes = 0;
54891 + segvacl->expires = 0;
54892 + }
54893 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54894 + gr_remove_uid(gr_usermode->segv_uid);
54895 + }
54896 + } else {
54897 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54898 + error = -EPERM;
54899 + }
54900 + break;
54901 + case GR_SPROLE:
54902 + case GR_SPROLEPAM:
54903 + if (unlikely(!(gr_status & GR_READY))) {
54904 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54905 + error = -EAGAIN;
54906 + break;
54907 + }
54908 +
54909 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54910 + current->role->expires = 0;
54911 + current->role->auth_attempts = 0;
54912 + }
54913 +
54914 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54915 + time_after(current->role->expires, get_seconds())) {
54916 + error = -EBUSY;
54917 + goto out;
54918 + }
54919 +
54920 + if (lookup_special_role_auth
54921 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54922 + && ((!sprole_salt && !sprole_sum)
54923 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54924 + char *p = "";
54925 + assign_special_role(gr_usermode->sp_role);
54926 + read_lock(&tasklist_lock);
54927 + if (current->real_parent)
54928 + p = current->real_parent->role->rolename;
54929 + read_unlock(&tasklist_lock);
54930 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54931 + p, acl_sp_role_value);
54932 + } else {
54933 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54934 + error = -EPERM;
54935 + if(!(current->role->auth_attempts++))
54936 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54937 +
54938 + goto out;
54939 + }
54940 + break;
54941 + case GR_UNSPROLE:
54942 + if (unlikely(!(gr_status & GR_READY))) {
54943 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54944 + error = -EAGAIN;
54945 + break;
54946 + }
54947 +
54948 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54949 + char *p = "";
54950 + int i = 0;
54951 +
54952 + read_lock(&tasklist_lock);
54953 + if (current->real_parent) {
54954 + p = current->real_parent->role->rolename;
54955 + i = current->real_parent->acl_role_id;
54956 + }
54957 + read_unlock(&tasklist_lock);
54958 +
54959 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54960 + gr_set_acls(1);
54961 + } else {
54962 + error = -EPERM;
54963 + goto out;
54964 + }
54965 + break;
54966 + default:
54967 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54968 + error = -EINVAL;
54969 + break;
54970 + }
54971 +
54972 + if (error != -EPERM)
54973 + goto out;
54974 +
54975 + if(!(gr_auth_attempts++))
54976 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54977 +
54978 + out:
54979 + mutex_unlock(&gr_dev_mutex);
54980 + return error;
54981 +}
54982 +
54983 +/* must be called with
54984 + rcu_read_lock();
54985 + read_lock(&tasklist_lock);
54986 + read_lock(&grsec_exec_file_lock);
54987 +*/
54988 +int gr_apply_subject_to_task(struct task_struct *task)
54989 +{
54990 + struct acl_object_label *obj;
54991 + char *tmpname;
54992 + struct acl_subject_label *tmpsubj;
54993 + struct file *filp;
54994 + struct name_entry *nmatch;
54995 +
54996 + filp = task->exec_file;
54997 + if (filp == NULL)
54998 + return 0;
54999 +
55000 + /* the following is to apply the correct subject
55001 + on binaries running when the RBAC system
55002 + is enabled, when the binaries have been
55003 + replaced or deleted since their execution
55004 + -----
55005 + when the RBAC system starts, the inode/dev
55006 + from exec_file will be one the RBAC system
55007 + is unaware of. It only knows the inode/dev
55008 + of the present file on disk, or the absence
55009 + of it.
55010 + */
55011 + preempt_disable();
55012 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55013 +
55014 + nmatch = lookup_name_entry(tmpname);
55015 + preempt_enable();
55016 + tmpsubj = NULL;
55017 + if (nmatch) {
55018 + if (nmatch->deleted)
55019 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55020 + else
55021 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55022 + if (tmpsubj != NULL)
55023 + task->acl = tmpsubj;
55024 + }
55025 + if (tmpsubj == NULL)
55026 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55027 + task->role);
55028 + if (task->acl) {
55029 + task->is_writable = 0;
55030 + /* ignore additional mmap checks for processes that are writable
55031 + by the default ACL */
55032 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55033 + if (unlikely(obj->mode & GR_WRITE))
55034 + task->is_writable = 1;
55035 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55036 + if (unlikely(obj->mode & GR_WRITE))
55037 + task->is_writable = 1;
55038 +
55039 + gr_set_proc_res(task);
55040 +
55041 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55042 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55043 +#endif
55044 + } else {
55045 + return 1;
55046 + }
55047 +
55048 + return 0;
55049 +}
55050 +
55051 +int
55052 +gr_set_acls(const int type)
55053 +{
55054 + struct task_struct *task, *task2;
55055 + struct acl_role_label *role = current->role;
55056 + __u16 acl_role_id = current->acl_role_id;
55057 + const struct cred *cred;
55058 + int ret;
55059 +
55060 + rcu_read_lock();
55061 + read_lock(&tasklist_lock);
55062 + read_lock(&grsec_exec_file_lock);
55063 + do_each_thread(task2, task) {
55064 + /* check to see if we're called from the exit handler,
55065 + if so, only replace ACLs that have inherited the admin
55066 + ACL */
55067 +
55068 + if (type && (task->role != role ||
55069 + task->acl_role_id != acl_role_id))
55070 + continue;
55071 +
55072 + task->acl_role_id = 0;
55073 + task->acl_sp_role = 0;
55074 +
55075 + if (task->exec_file) {
55076 + cred = __task_cred(task);
55077 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55078 + ret = gr_apply_subject_to_task(task);
55079 + if (ret) {
55080 + read_unlock(&grsec_exec_file_lock);
55081 + read_unlock(&tasklist_lock);
55082 + rcu_read_unlock();
55083 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55084 + return ret;
55085 + }
55086 + } else {
55087 + // it's a kernel process
55088 + task->role = kernel_role;
55089 + task->acl = kernel_role->root_label;
55090 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55091 + task->acl->mode &= ~GR_PROCFIND;
55092 +#endif
55093 + }
55094 + } while_each_thread(task2, task);
55095 + read_unlock(&grsec_exec_file_lock);
55096 + read_unlock(&tasklist_lock);
55097 + rcu_read_unlock();
55098 +
55099 + return 0;
55100 +}
55101 +
55102 +void
55103 +gr_learn_resource(const struct task_struct *task,
55104 + const int res, const unsigned long wanted, const int gt)
55105 +{
55106 + struct acl_subject_label *acl;
55107 + const struct cred *cred;
55108 +
55109 + if (unlikely((gr_status & GR_READY) &&
55110 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55111 + goto skip_reslog;
55112 +
55113 +#ifdef CONFIG_GRKERNSEC_RESLOG
55114 + gr_log_resource(task, res, wanted, gt);
55115 +#endif
55116 + skip_reslog:
55117 +
55118 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55119 + return;
55120 +
55121 + acl = task->acl;
55122 +
55123 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55124 + !(acl->resmask & (1 << (unsigned short) res))))
55125 + return;
55126 +
55127 + if (wanted >= acl->res[res].rlim_cur) {
55128 + unsigned long res_add;
55129 +
55130 + res_add = wanted;
55131 + switch (res) {
55132 + case RLIMIT_CPU:
55133 + res_add += GR_RLIM_CPU_BUMP;
55134 + break;
55135 + case RLIMIT_FSIZE:
55136 + res_add += GR_RLIM_FSIZE_BUMP;
55137 + break;
55138 + case RLIMIT_DATA:
55139 + res_add += GR_RLIM_DATA_BUMP;
55140 + break;
55141 + case RLIMIT_STACK:
55142 + res_add += GR_RLIM_STACK_BUMP;
55143 + break;
55144 + case RLIMIT_CORE:
55145 + res_add += GR_RLIM_CORE_BUMP;
55146 + break;
55147 + case RLIMIT_RSS:
55148 + res_add += GR_RLIM_RSS_BUMP;
55149 + break;
55150 + case RLIMIT_NPROC:
55151 + res_add += GR_RLIM_NPROC_BUMP;
55152 + break;
55153 + case RLIMIT_NOFILE:
55154 + res_add += GR_RLIM_NOFILE_BUMP;
55155 + break;
55156 + case RLIMIT_MEMLOCK:
55157 + res_add += GR_RLIM_MEMLOCK_BUMP;
55158 + break;
55159 + case RLIMIT_AS:
55160 + res_add += GR_RLIM_AS_BUMP;
55161 + break;
55162 + case RLIMIT_LOCKS:
55163 + res_add += GR_RLIM_LOCKS_BUMP;
55164 + break;
55165 + case RLIMIT_SIGPENDING:
55166 + res_add += GR_RLIM_SIGPENDING_BUMP;
55167 + break;
55168 + case RLIMIT_MSGQUEUE:
55169 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55170 + break;
55171 + case RLIMIT_NICE:
55172 + res_add += GR_RLIM_NICE_BUMP;
55173 + break;
55174 + case RLIMIT_RTPRIO:
55175 + res_add += GR_RLIM_RTPRIO_BUMP;
55176 + break;
55177 + case RLIMIT_RTTIME:
55178 + res_add += GR_RLIM_RTTIME_BUMP;
55179 + break;
55180 + }
55181 +
55182 + acl->res[res].rlim_cur = res_add;
55183 +
55184 + if (wanted > acl->res[res].rlim_max)
55185 + acl->res[res].rlim_max = res_add;
55186 +
55187 + /* only log the subject filename, since resource logging is supported for
55188 + single-subject learning only */
55189 + rcu_read_lock();
55190 + cred = __task_cred(task);
55191 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55192 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55193 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55194 + "", (unsigned long) res, &task->signal->saved_ip);
55195 + rcu_read_unlock();
55196 + }
55197 +
55198 + return;
55199 +}
55200 +
55201 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55202 +void
55203 +pax_set_initial_flags(struct linux_binprm *bprm)
55204 +{
55205 + struct task_struct *task = current;
55206 + struct acl_subject_label *proc;
55207 + unsigned long flags;
55208 +
55209 + if (unlikely(!(gr_status & GR_READY)))
55210 + return;
55211 +
55212 + flags = pax_get_flags(task);
55213 +
55214 + proc = task->acl;
55215 +
55216 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55217 + flags &= ~MF_PAX_PAGEEXEC;
55218 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55219 + flags &= ~MF_PAX_SEGMEXEC;
55220 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55221 + flags &= ~MF_PAX_RANDMMAP;
55222 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55223 + flags &= ~MF_PAX_EMUTRAMP;
55224 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55225 + flags &= ~MF_PAX_MPROTECT;
55226 +
55227 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55228 + flags |= MF_PAX_PAGEEXEC;
55229 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55230 + flags |= MF_PAX_SEGMEXEC;
55231 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55232 + flags |= MF_PAX_RANDMMAP;
55233 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55234 + flags |= MF_PAX_EMUTRAMP;
55235 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55236 + flags |= MF_PAX_MPROTECT;
55237 +
55238 + pax_set_flags(task, flags);
55239 +
55240 + return;
55241 +}
55242 +#endif
55243 +
55244 +int
55245 +gr_handle_proc_ptrace(struct task_struct *task)
55246 +{
55247 + struct file *filp;
55248 + struct task_struct *tmp = task;
55249 + struct task_struct *curtemp = current;
55250 + __u32 retmode;
55251 +
55252 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55253 + if (unlikely(!(gr_status & GR_READY)))
55254 + return 0;
55255 +#endif
55256 +
55257 + read_lock(&tasklist_lock);
55258 + read_lock(&grsec_exec_file_lock);
55259 + filp = task->exec_file;
55260 +
55261 + while (tmp->pid > 0) {
55262 + if (tmp == curtemp)
55263 + break;
55264 + tmp = tmp->real_parent;
55265 + }
55266 +
55267 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55268 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55269 + read_unlock(&grsec_exec_file_lock);
55270 + read_unlock(&tasklist_lock);
55271 + return 1;
55272 + }
55273 +
55274 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55275 + if (!(gr_status & GR_READY)) {
55276 + read_unlock(&grsec_exec_file_lock);
55277 + read_unlock(&tasklist_lock);
55278 + return 0;
55279 + }
55280 +#endif
55281 +
55282 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55283 + read_unlock(&grsec_exec_file_lock);
55284 + read_unlock(&tasklist_lock);
55285 +
55286 + if (retmode & GR_NOPTRACE)
55287 + return 1;
55288 +
55289 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55290 + && (current->acl != task->acl || (current->acl != current->role->root_label
55291 + && current->pid != task->pid)))
55292 + return 1;
55293 +
55294 + return 0;
55295 +}
55296 +
55297 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55298 +{
55299 + if (unlikely(!(gr_status & GR_READY)))
55300 + return;
55301 +
55302 + if (!(current->role->roletype & GR_ROLE_GOD))
55303 + return;
55304 +
55305 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55306 + p->role->rolename, gr_task_roletype_to_char(p),
55307 + p->acl->filename);
55308 +}
55309 +
55310 +int
55311 +gr_handle_ptrace(struct task_struct *task, const long request)
55312 +{
55313 + struct task_struct *tmp = task;
55314 + struct task_struct *curtemp = current;
55315 + __u32 retmode;
55316 +
55317 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55318 + if (unlikely(!(gr_status & GR_READY)))
55319 + return 0;
55320 +#endif
55321 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55322 + read_lock(&tasklist_lock);
55323 + while (tmp->pid > 0) {
55324 + if (tmp == curtemp)
55325 + break;
55326 + tmp = tmp->real_parent;
55327 + }
55328 +
55329 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55330 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55331 + read_unlock(&tasklist_lock);
55332 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55333 + return 1;
55334 + }
55335 + read_unlock(&tasklist_lock);
55336 + }
55337 +
55338 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55339 + if (!(gr_status & GR_READY))
55340 + return 0;
55341 +#endif
55342 +
55343 + read_lock(&grsec_exec_file_lock);
55344 + if (unlikely(!task->exec_file)) {
55345 + read_unlock(&grsec_exec_file_lock);
55346 + return 0;
55347 + }
55348 +
55349 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55350 + read_unlock(&grsec_exec_file_lock);
55351 +
55352 + if (retmode & GR_NOPTRACE) {
55353 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55354 + return 1;
55355 + }
55356 +
55357 + if (retmode & GR_PTRACERD) {
55358 + switch (request) {
55359 + case PTRACE_SEIZE:
55360 + case PTRACE_POKETEXT:
55361 + case PTRACE_POKEDATA:
55362 + case PTRACE_POKEUSR:
55363 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55364 + case PTRACE_SETREGS:
55365 + case PTRACE_SETFPREGS:
55366 +#endif
55367 +#ifdef CONFIG_X86
55368 + case PTRACE_SETFPXREGS:
55369 +#endif
55370 +#ifdef CONFIG_ALTIVEC
55371 + case PTRACE_SETVRREGS:
55372 +#endif
55373 + return 1;
55374 + default:
55375 + return 0;
55376 + }
55377 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55378 + !(current->role->roletype & GR_ROLE_GOD) &&
55379 + (current->acl != task->acl)) {
55380 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55381 + return 1;
55382 + }
55383 +
55384 + return 0;
55385 +}
55386 +
55387 +static int is_writable_mmap(const struct file *filp)
55388 +{
55389 + struct task_struct *task = current;
55390 + struct acl_object_label *obj, *obj2;
55391 +
55392 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55393 + !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))) {
55394 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55395 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55396 + task->role->root_label);
55397 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55398 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55399 + return 1;
55400 + }
55401 + }
55402 + return 0;
55403 +}
55404 +
55405 +int
55406 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55407 +{
55408 + __u32 mode;
55409 +
55410 + if (unlikely(!file || !(prot & PROT_EXEC)))
55411 + return 1;
55412 +
55413 + if (is_writable_mmap(file))
55414 + return 0;
55415 +
55416 + mode =
55417 + gr_search_file(file->f_path.dentry,
55418 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55419 + file->f_path.mnt);
55420 +
55421 + if (!gr_tpe_allow(file))
55422 + return 0;
55423 +
55424 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55425 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55426 + return 0;
55427 + } else if (unlikely(!(mode & GR_EXEC))) {
55428 + return 0;
55429 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55430 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55431 + return 1;
55432 + }
55433 +
55434 + return 1;
55435 +}
55436 +
55437 +int
55438 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55439 +{
55440 + __u32 mode;
55441 +
55442 + if (unlikely(!file || !(prot & PROT_EXEC)))
55443 + return 1;
55444 +
55445 + if (is_writable_mmap(file))
55446 + return 0;
55447 +
55448 + mode =
55449 + gr_search_file(file->f_path.dentry,
55450 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55451 + file->f_path.mnt);
55452 +
55453 + if (!gr_tpe_allow(file))
55454 + return 0;
55455 +
55456 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55457 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55458 + return 0;
55459 + } else if (unlikely(!(mode & GR_EXEC))) {
55460 + return 0;
55461 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55462 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55463 + return 1;
55464 + }
55465 +
55466 + return 1;
55467 +}
55468 +
55469 +void
55470 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55471 +{
55472 + unsigned long runtime;
55473 + unsigned long cputime;
55474 + unsigned int wday, cday;
55475 + __u8 whr, chr;
55476 + __u8 wmin, cmin;
55477 + __u8 wsec, csec;
55478 + struct timespec timeval;
55479 +
55480 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55481 + !(task->acl->mode & GR_PROCACCT)))
55482 + return;
55483 +
55484 + do_posix_clock_monotonic_gettime(&timeval);
55485 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55486 + wday = runtime / (3600 * 24);
55487 + runtime -= wday * (3600 * 24);
55488 + whr = runtime / 3600;
55489 + runtime -= whr * 3600;
55490 + wmin = runtime / 60;
55491 + runtime -= wmin * 60;
55492 + wsec = runtime;
55493 +
55494 + cputime = (task->utime + task->stime) / HZ;
55495 + cday = cputime / (3600 * 24);
55496 + cputime -= cday * (3600 * 24);
55497 + chr = cputime / 3600;
55498 + cputime -= chr * 3600;
55499 + cmin = cputime / 60;
55500 + cputime -= cmin * 60;
55501 + csec = cputime;
55502 +
55503 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55504 +
55505 + return;
55506 +}
55507 +
55508 +void gr_set_kernel_label(struct task_struct *task)
55509 +{
55510 + if (gr_status & GR_READY) {
55511 + task->role = kernel_role;
55512 + task->acl = kernel_role->root_label;
55513 + }
55514 + return;
55515 +}
55516 +
55517 +#ifdef CONFIG_TASKSTATS
55518 +int gr_is_taskstats_denied(int pid)
55519 +{
55520 + struct task_struct *task;
55521 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55522 + const struct cred *cred;
55523 +#endif
55524 + int ret = 0;
55525 +
55526 + /* restrict taskstats viewing to un-chrooted root users
55527 + who have the 'view' subject flag if the RBAC system is enabled
55528 + */
55529 +
55530 + rcu_read_lock();
55531 + read_lock(&tasklist_lock);
55532 + task = find_task_by_vpid(pid);
55533 + if (task) {
55534 +#ifdef CONFIG_GRKERNSEC_CHROOT
55535 + if (proc_is_chrooted(task))
55536 + ret = -EACCES;
55537 +#endif
55538 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55539 + cred = __task_cred(task);
55540 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55541 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55542 + ret = -EACCES;
55543 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55544 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55545 + ret = -EACCES;
55546 +#endif
55547 +#endif
55548 + if (gr_status & GR_READY) {
55549 + if (!(task->acl->mode & GR_VIEW))
55550 + ret = -EACCES;
55551 + }
55552 + } else
55553 + ret = -ENOENT;
55554 +
55555 + read_unlock(&tasklist_lock);
55556 + rcu_read_unlock();
55557 +
55558 + return ret;
55559 +}
55560 +#endif
55561 +
55562 +/* AUXV entries are filled via a descendant of search_binary_handler
55563 + after we've already applied the subject for the target
55564 +*/
55565 +int gr_acl_enable_at_secure(void)
55566 +{
55567 + if (unlikely(!(gr_status & GR_READY)))
55568 + return 0;
55569 +
55570 + if (current->acl->mode & GR_ATSECURE)
55571 + return 1;
55572 +
55573 + return 0;
55574 +}
55575 +
55576 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55577 +{
55578 + struct task_struct *task = current;
55579 + struct dentry *dentry = file->f_path.dentry;
55580 + struct vfsmount *mnt = file->f_path.mnt;
55581 + struct acl_object_label *obj, *tmp;
55582 + struct acl_subject_label *subj;
55583 + unsigned int bufsize;
55584 + int is_not_root;
55585 + char *path;
55586 + dev_t dev = __get_dev(dentry);
55587 +
55588 + if (unlikely(!(gr_status & GR_READY)))
55589 + return 1;
55590 +
55591 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55592 + return 1;
55593 +
55594 + /* ignore Eric Biederman */
55595 + if (IS_PRIVATE(dentry->d_inode))
55596 + return 1;
55597 +
55598 + subj = task->acl;
55599 + read_lock(&gr_inode_lock);
55600 + do {
55601 + obj = lookup_acl_obj_label(ino, dev, subj);
55602 + if (obj != NULL) {
55603 + read_unlock(&gr_inode_lock);
55604 + return (obj->mode & GR_FIND) ? 1 : 0;
55605 + }
55606 + } while ((subj = subj->parent_subject));
55607 + read_unlock(&gr_inode_lock);
55608 +
55609 + /* this is purely an optimization since we're looking for an object
55610 + for the directory we're doing a readdir on
55611 + if it's possible for any globbed object to match the entry we're
55612 + filling into the directory, then the object we find here will be
55613 + an anchor point with attached globbed objects
55614 + */
55615 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55616 + if (obj->globbed == NULL)
55617 + return (obj->mode & GR_FIND) ? 1 : 0;
55618 +
55619 + is_not_root = ((obj->filename[0] == '/') &&
55620 + (obj->filename[1] == '\0')) ? 0 : 1;
55621 + bufsize = PAGE_SIZE - namelen - is_not_root;
55622 +
55623 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55624 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55625 + return 1;
55626 +
55627 + preempt_disable();
55628 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55629 + bufsize);
55630 +
55631 + bufsize = strlen(path);
55632 +
55633 + /* if base is "/", don't append an additional slash */
55634 + if (is_not_root)
55635 + *(path + bufsize) = '/';
55636 + memcpy(path + bufsize + is_not_root, name, namelen);
55637 + *(path + bufsize + namelen + is_not_root) = '\0';
55638 +
55639 + tmp = obj->globbed;
55640 + while (tmp) {
55641 + if (!glob_match(tmp->filename, path)) {
55642 + preempt_enable();
55643 + return (tmp->mode & GR_FIND) ? 1 : 0;
55644 + }
55645 + tmp = tmp->next;
55646 + }
55647 + preempt_enable();
55648 + return (obj->mode & GR_FIND) ? 1 : 0;
55649 +}
55650 +
55651 +void gr_put_exec_file(struct task_struct *task)
55652 +{
55653 + struct file *filp;
55654 +
55655 + write_lock(&grsec_exec_file_lock);
55656 + filp = task->exec_file;
55657 + task->exec_file = NULL;
55658 + write_unlock(&grsec_exec_file_lock);
55659 +
55660 + if (filp)
55661 + fput(filp);
55662 +
55663 + return;
55664 +}
55665 +
55666 +
55667 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55668 +EXPORT_SYMBOL(gr_acl_is_enabled);
55669 +#endif
55670 +EXPORT_SYMBOL(gr_learn_resource);
55671 +EXPORT_SYMBOL(gr_set_kernel_label);
55672 +#ifdef CONFIG_SECURITY
55673 +EXPORT_SYMBOL(gr_check_user_change);
55674 +EXPORT_SYMBOL(gr_check_group_change);
55675 +#endif
55676 +
55677 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55678 new file mode 100644
55679 index 0000000..34fefda
55680 --- /dev/null
55681 +++ b/grsecurity/gracl_alloc.c
55682 @@ -0,0 +1,105 @@
55683 +#include <linux/kernel.h>
55684 +#include <linux/mm.h>
55685 +#include <linux/slab.h>
55686 +#include <linux/vmalloc.h>
55687 +#include <linux/gracl.h>
55688 +#include <linux/grsecurity.h>
55689 +
55690 +static unsigned long alloc_stack_next = 1;
55691 +static unsigned long alloc_stack_size = 1;
55692 +static void **alloc_stack;
55693 +
55694 +static __inline__ int
55695 +alloc_pop(void)
55696 +{
55697 + if (alloc_stack_next == 1)
55698 + return 0;
55699 +
55700 + kfree(alloc_stack[alloc_stack_next - 2]);
55701 +
55702 + alloc_stack_next--;
55703 +
55704 + return 1;
55705 +}
55706 +
55707 +static __inline__ int
55708 +alloc_push(void *buf)
55709 +{
55710 + if (alloc_stack_next >= alloc_stack_size)
55711 + return 1;
55712 +
55713 + alloc_stack[alloc_stack_next - 1] = buf;
55714 +
55715 + alloc_stack_next++;
55716 +
55717 + return 0;
55718 +}
55719 +
55720 +void *
55721 +acl_alloc(unsigned long len)
55722 +{
55723 + void *ret = NULL;
55724 +
55725 + if (!len || len > PAGE_SIZE)
55726 + goto out;
55727 +
55728 + ret = kmalloc(len, GFP_KERNEL);
55729 +
55730 + if (ret) {
55731 + if (alloc_push(ret)) {
55732 + kfree(ret);
55733 + ret = NULL;
55734 + }
55735 + }
55736 +
55737 +out:
55738 + return ret;
55739 +}
55740 +
55741 +void *
55742 +acl_alloc_num(unsigned long num, unsigned long len)
55743 +{
55744 + if (!len || (num > (PAGE_SIZE / len)))
55745 + return NULL;
55746 +
55747 + return acl_alloc(num * len);
55748 +}
55749 +
55750 +void
55751 +acl_free_all(void)
55752 +{
55753 + if (gr_acl_is_enabled() || !alloc_stack)
55754 + return;
55755 +
55756 + while (alloc_pop()) ;
55757 +
55758 + if (alloc_stack) {
55759 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55760 + kfree(alloc_stack);
55761 + else
55762 + vfree(alloc_stack);
55763 + }
55764 +
55765 + alloc_stack = NULL;
55766 + alloc_stack_size = 1;
55767 + alloc_stack_next = 1;
55768 +
55769 + return;
55770 +}
55771 +
55772 +int
55773 +acl_alloc_stack_init(unsigned long size)
55774 +{
55775 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55776 + alloc_stack =
55777 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55778 + else
55779 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55780 +
55781 + alloc_stack_size = size;
55782 +
55783 + if (!alloc_stack)
55784 + return 0;
55785 + else
55786 + return 1;
55787 +}
55788 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55789 new file mode 100644
55790 index 0000000..6d21049
55791 --- /dev/null
55792 +++ b/grsecurity/gracl_cap.c
55793 @@ -0,0 +1,110 @@
55794 +#include <linux/kernel.h>
55795 +#include <linux/module.h>
55796 +#include <linux/sched.h>
55797 +#include <linux/gracl.h>
55798 +#include <linux/grsecurity.h>
55799 +#include <linux/grinternal.h>
55800 +
55801 +extern const char *captab_log[];
55802 +extern int captab_log_entries;
55803 +
55804 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55805 +{
55806 + struct acl_subject_label *curracl;
55807 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55808 + kernel_cap_t cap_audit = __cap_empty_set;
55809 +
55810 + if (!gr_acl_is_enabled())
55811 + return 1;
55812 +
55813 + curracl = task->acl;
55814 +
55815 + cap_drop = curracl->cap_lower;
55816 + cap_mask = curracl->cap_mask;
55817 + cap_audit = curracl->cap_invert_audit;
55818 +
55819 + while ((curracl = curracl->parent_subject)) {
55820 + /* if the cap isn't specified in the current computed mask but is specified in the
55821 + current level subject, and is lowered in the current level subject, then add
55822 + it to the set of dropped capabilities
55823 + otherwise, add the current level subject's mask to the current computed mask
55824 + */
55825 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55826 + cap_raise(cap_mask, cap);
55827 + if (cap_raised(curracl->cap_lower, cap))
55828 + cap_raise(cap_drop, cap);
55829 + if (cap_raised(curracl->cap_invert_audit, cap))
55830 + cap_raise(cap_audit, cap);
55831 + }
55832 + }
55833 +
55834 + if (!cap_raised(cap_drop, cap)) {
55835 + if (cap_raised(cap_audit, cap))
55836 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55837 + return 1;
55838 + }
55839 +
55840 + curracl = task->acl;
55841 +
55842 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55843 + && cap_raised(cred->cap_effective, cap)) {
55844 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55845 + task->role->roletype, cred->uid,
55846 + cred->gid, task->exec_file ?
55847 + gr_to_filename(task->exec_file->f_path.dentry,
55848 + task->exec_file->f_path.mnt) : curracl->filename,
55849 + curracl->filename, 0UL,
55850 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55851 + return 1;
55852 + }
55853 +
55854 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55855 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55856 +
55857 + return 0;
55858 +}
55859 +
55860 +int
55861 +gr_acl_is_capable(const int cap)
55862 +{
55863 + return gr_task_acl_is_capable(current, current_cred(), cap);
55864 +}
55865 +
55866 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55867 +{
55868 + struct acl_subject_label *curracl;
55869 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55870 +
55871 + if (!gr_acl_is_enabled())
55872 + return 1;
55873 +
55874 + curracl = task->acl;
55875 +
55876 + cap_drop = curracl->cap_lower;
55877 + cap_mask = curracl->cap_mask;
55878 +
55879 + while ((curracl = curracl->parent_subject)) {
55880 + /* if the cap isn't specified in the current computed mask but is specified in the
55881 + current level subject, and is lowered in the current level subject, then add
55882 + it to the set of dropped capabilities
55883 + otherwise, add the current level subject's mask to the current computed mask
55884 + */
55885 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55886 + cap_raise(cap_mask, cap);
55887 + if (cap_raised(curracl->cap_lower, cap))
55888 + cap_raise(cap_drop, cap);
55889 + }
55890 + }
55891 +
55892 + if (!cap_raised(cap_drop, cap))
55893 + return 1;
55894 +
55895 + return 0;
55896 +}
55897 +
55898 +int
55899 +gr_acl_is_capable_nolog(const int cap)
55900 +{
55901 + return gr_task_acl_is_capable_nolog(current, cap);
55902 +}
55903 +
55904 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55905 new file mode 100644
55906 index 0000000..decb035
55907 --- /dev/null
55908 +++ b/grsecurity/gracl_fs.c
55909 @@ -0,0 +1,437 @@
55910 +#include <linux/kernel.h>
55911 +#include <linux/sched.h>
55912 +#include <linux/types.h>
55913 +#include <linux/fs.h>
55914 +#include <linux/file.h>
55915 +#include <linux/stat.h>
55916 +#include <linux/grsecurity.h>
55917 +#include <linux/grinternal.h>
55918 +#include <linux/gracl.h>
55919 +
55920 +umode_t
55921 +gr_acl_umask(void)
55922 +{
55923 + if (unlikely(!gr_acl_is_enabled()))
55924 + return 0;
55925 +
55926 + return current->role->umask;
55927 +}
55928 +
55929 +__u32
55930 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55931 + const struct vfsmount * mnt)
55932 +{
55933 + __u32 mode;
55934 +
55935 + if (unlikely(!dentry->d_inode))
55936 + return GR_FIND;
55937 +
55938 + mode =
55939 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55940 +
55941 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55942 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55943 + return mode;
55944 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55945 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55946 + return 0;
55947 + } else if (unlikely(!(mode & GR_FIND)))
55948 + return 0;
55949 +
55950 + return GR_FIND;
55951 +}
55952 +
55953 +__u32
55954 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55955 + int acc_mode)
55956 +{
55957 + __u32 reqmode = GR_FIND;
55958 + __u32 mode;
55959 +
55960 + if (unlikely(!dentry->d_inode))
55961 + return reqmode;
55962 +
55963 + if (acc_mode & MAY_APPEND)
55964 + reqmode |= GR_APPEND;
55965 + else if (acc_mode & MAY_WRITE)
55966 + reqmode |= GR_WRITE;
55967 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55968 + reqmode |= GR_READ;
55969 +
55970 + mode =
55971 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55972 + mnt);
55973 +
55974 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55975 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55976 + reqmode & GR_READ ? " reading" : "",
55977 + reqmode & GR_WRITE ? " writing" : reqmode &
55978 + GR_APPEND ? " appending" : "");
55979 + return reqmode;
55980 + } else
55981 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55982 + {
55983 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55984 + reqmode & GR_READ ? " reading" : "",
55985 + reqmode & GR_WRITE ? " writing" : reqmode &
55986 + GR_APPEND ? " appending" : "");
55987 + return 0;
55988 + } else if (unlikely((mode & reqmode) != reqmode))
55989 + return 0;
55990 +
55991 + return reqmode;
55992 +}
55993 +
55994 +__u32
55995 +gr_acl_handle_creat(const struct dentry * dentry,
55996 + const struct dentry * p_dentry,
55997 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55998 + const int imode)
55999 +{
56000 + __u32 reqmode = GR_WRITE | GR_CREATE;
56001 + __u32 mode;
56002 +
56003 + if (acc_mode & MAY_APPEND)
56004 + reqmode |= GR_APPEND;
56005 + // if a directory was required or the directory already exists, then
56006 + // don't count this open as a read
56007 + if ((acc_mode & MAY_READ) &&
56008 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56009 + reqmode |= GR_READ;
56010 + if ((open_flags & O_CREAT) &&
56011 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56012 + reqmode |= GR_SETID;
56013 +
56014 + mode =
56015 + gr_check_create(dentry, p_dentry, p_mnt,
56016 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56017 +
56018 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56019 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56020 + reqmode & GR_READ ? " reading" : "",
56021 + reqmode & GR_WRITE ? " writing" : reqmode &
56022 + GR_APPEND ? " appending" : "");
56023 + return reqmode;
56024 + } else
56025 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56026 + {
56027 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56028 + reqmode & GR_READ ? " reading" : "",
56029 + reqmode & GR_WRITE ? " writing" : reqmode &
56030 + GR_APPEND ? " appending" : "");
56031 + return 0;
56032 + } else if (unlikely((mode & reqmode) != reqmode))
56033 + return 0;
56034 +
56035 + return reqmode;
56036 +}
56037 +
56038 +__u32
56039 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56040 + const int fmode)
56041 +{
56042 + __u32 mode, reqmode = GR_FIND;
56043 +
56044 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56045 + reqmode |= GR_EXEC;
56046 + if (fmode & S_IWOTH)
56047 + reqmode |= GR_WRITE;
56048 + if (fmode & S_IROTH)
56049 + reqmode |= GR_READ;
56050 +
56051 + mode =
56052 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56053 + mnt);
56054 +
56055 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56056 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56057 + reqmode & GR_READ ? " reading" : "",
56058 + reqmode & GR_WRITE ? " writing" : "",
56059 + reqmode & GR_EXEC ? " executing" : "");
56060 + return reqmode;
56061 + } else
56062 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56063 + {
56064 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56065 + reqmode & GR_READ ? " reading" : "",
56066 + reqmode & GR_WRITE ? " writing" : "",
56067 + reqmode & GR_EXEC ? " executing" : "");
56068 + return 0;
56069 + } else if (unlikely((mode & reqmode) != reqmode))
56070 + return 0;
56071 +
56072 + return reqmode;
56073 +}
56074 +
56075 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56076 +{
56077 + __u32 mode;
56078 +
56079 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56080 +
56081 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56082 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56083 + return mode;
56084 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56085 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56086 + return 0;
56087 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56088 + return 0;
56089 +
56090 + return (reqmode);
56091 +}
56092 +
56093 +__u32
56094 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56095 +{
56096 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56097 +}
56098 +
56099 +__u32
56100 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56101 +{
56102 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56103 +}
56104 +
56105 +__u32
56106 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56107 +{
56108 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56109 +}
56110 +
56111 +__u32
56112 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56113 +{
56114 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56115 +}
56116 +
56117 +__u32
56118 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56119 + umode_t *modeptr)
56120 +{
56121 + umode_t mode;
56122 +
56123 + *modeptr &= ~gr_acl_umask();
56124 + mode = *modeptr;
56125 +
56126 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56127 + return 1;
56128 +
56129 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56130 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56131 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56132 + GR_CHMOD_ACL_MSG);
56133 + } else {
56134 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56135 + }
56136 +}
56137 +
56138 +__u32
56139 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56140 +{
56141 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56142 +}
56143 +
56144 +__u32
56145 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56146 +{
56147 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56148 +}
56149 +
56150 +__u32
56151 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56152 +{
56153 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56154 +}
56155 +
56156 +__u32
56157 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56158 +{
56159 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56160 + GR_UNIXCONNECT_ACL_MSG);
56161 +}
56162 +
56163 +/* hardlinks require at minimum create and link permission,
56164 + any additional privilege required is based on the
56165 + privilege of the file being linked to
56166 +*/
56167 +__u32
56168 +gr_acl_handle_link(const struct dentry * new_dentry,
56169 + const struct dentry * parent_dentry,
56170 + const struct vfsmount * parent_mnt,
56171 + const struct dentry * old_dentry,
56172 + const struct vfsmount * old_mnt, const struct filename *to)
56173 +{
56174 + __u32 mode;
56175 + __u32 needmode = GR_CREATE | GR_LINK;
56176 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56177 +
56178 + mode =
56179 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56180 + old_mnt);
56181 +
56182 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56183 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
56184 + return mode;
56185 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56186 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
56187 + return 0;
56188 + } else if (unlikely((mode & needmode) != needmode))
56189 + return 0;
56190 +
56191 + return 1;
56192 +}
56193 +
56194 +__u32
56195 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56196 + const struct dentry * parent_dentry,
56197 + const struct vfsmount * parent_mnt, const struct filename *from)
56198 +{
56199 + __u32 needmode = GR_WRITE | GR_CREATE;
56200 + __u32 mode;
56201 +
56202 + mode =
56203 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56204 + GR_CREATE | GR_AUDIT_CREATE |
56205 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56206 +
56207 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56208 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
56209 + return mode;
56210 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56211 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
56212 + return 0;
56213 + } else if (unlikely((mode & needmode) != needmode))
56214 + return 0;
56215 +
56216 + return (GR_WRITE | GR_CREATE);
56217 +}
56218 +
56219 +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)
56220 +{
56221 + __u32 mode;
56222 +
56223 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56224 +
56225 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56226 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56227 + return mode;
56228 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56229 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56230 + return 0;
56231 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56232 + return 0;
56233 +
56234 + return (reqmode);
56235 +}
56236 +
56237 +__u32
56238 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56239 + const struct dentry * parent_dentry,
56240 + const struct vfsmount * parent_mnt,
56241 + const int mode)
56242 +{
56243 + __u32 reqmode = GR_WRITE | GR_CREATE;
56244 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56245 + reqmode |= GR_SETID;
56246 +
56247 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56248 + reqmode, GR_MKNOD_ACL_MSG);
56249 +}
56250 +
56251 +__u32
56252 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56253 + const struct dentry *parent_dentry,
56254 + const struct vfsmount *parent_mnt)
56255 +{
56256 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56257 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56258 +}
56259 +
56260 +#define RENAME_CHECK_SUCCESS(old, new) \
56261 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56262 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56263 +
56264 +int
56265 +gr_acl_handle_rename(struct dentry *new_dentry,
56266 + struct dentry *parent_dentry,
56267 + const struct vfsmount *parent_mnt,
56268 + struct dentry *old_dentry,
56269 + struct inode *old_parent_inode,
56270 + struct vfsmount *old_mnt, const struct filename *newname)
56271 +{
56272 + __u32 comp1, comp2;
56273 + int error = 0;
56274 +
56275 + if (unlikely(!gr_acl_is_enabled()))
56276 + return 0;
56277 +
56278 + if (!new_dentry->d_inode) {
56279 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56280 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56281 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56282 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56283 + GR_DELETE | GR_AUDIT_DELETE |
56284 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56285 + GR_SUPPRESS, old_mnt);
56286 + } else {
56287 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56288 + GR_CREATE | GR_DELETE |
56289 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56290 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56291 + GR_SUPPRESS, parent_mnt);
56292 + comp2 =
56293 + gr_search_file(old_dentry,
56294 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56295 + GR_DELETE | GR_AUDIT_DELETE |
56296 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56297 + }
56298 +
56299 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56300 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56301 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
56302 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56303 + && !(comp2 & GR_SUPPRESS)) {
56304 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
56305 + error = -EACCES;
56306 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56307 + error = -EACCES;
56308 +
56309 + return error;
56310 +}
56311 +
56312 +void
56313 +gr_acl_handle_exit(void)
56314 +{
56315 + u16 id;
56316 + char *rolename;
56317 + struct file *exec_file;
56318 +
56319 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56320 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56321 + id = current->acl_role_id;
56322 + rolename = current->role->rolename;
56323 + gr_set_acls(1);
56324 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56325 + }
56326 +
56327 + write_lock(&grsec_exec_file_lock);
56328 + exec_file = current->exec_file;
56329 + current->exec_file = NULL;
56330 + write_unlock(&grsec_exec_file_lock);
56331 +
56332 + if (exec_file)
56333 + fput(exec_file);
56334 +}
56335 +
56336 +int
56337 +gr_acl_handle_procpidmem(const struct task_struct *task)
56338 +{
56339 + if (unlikely(!gr_acl_is_enabled()))
56340 + return 0;
56341 +
56342 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56343 + return -EACCES;
56344 +
56345 + return 0;
56346 +}
56347 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56348 new file mode 100644
56349 index 0000000..58800a7
56350 --- /dev/null
56351 +++ b/grsecurity/gracl_ip.c
56352 @@ -0,0 +1,384 @@
56353 +#include <linux/kernel.h>
56354 +#include <asm/uaccess.h>
56355 +#include <asm/errno.h>
56356 +#include <net/sock.h>
56357 +#include <linux/file.h>
56358 +#include <linux/fs.h>
56359 +#include <linux/net.h>
56360 +#include <linux/in.h>
56361 +#include <linux/skbuff.h>
56362 +#include <linux/ip.h>
56363 +#include <linux/udp.h>
56364 +#include <linux/types.h>
56365 +#include <linux/sched.h>
56366 +#include <linux/netdevice.h>
56367 +#include <linux/inetdevice.h>
56368 +#include <linux/gracl.h>
56369 +#include <linux/grsecurity.h>
56370 +#include <linux/grinternal.h>
56371 +
56372 +#define GR_BIND 0x01
56373 +#define GR_CONNECT 0x02
56374 +#define GR_INVERT 0x04
56375 +#define GR_BINDOVERRIDE 0x08
56376 +#define GR_CONNECTOVERRIDE 0x10
56377 +#define GR_SOCK_FAMILY 0x20
56378 +
56379 +static const char * gr_protocols[IPPROTO_MAX] = {
56380 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56381 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56382 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56383 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56384 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56385 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56386 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56387 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56388 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56389 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56390 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56391 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56392 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56393 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56394 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56395 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56396 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56397 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56398 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56399 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56400 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56401 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56402 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56403 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56404 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56405 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56406 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56407 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56408 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56409 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56410 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56411 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56412 + };
56413 +
56414 +static const char * gr_socktypes[SOCK_MAX] = {
56415 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56416 + "unknown:7", "unknown:8", "unknown:9", "packet"
56417 + };
56418 +
56419 +static const char * gr_sockfamilies[AF_MAX+1] = {
56420 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56421 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56422 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56423 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56424 + };
56425 +
56426 +const char *
56427 +gr_proto_to_name(unsigned char proto)
56428 +{
56429 + return gr_protocols[proto];
56430 +}
56431 +
56432 +const char *
56433 +gr_socktype_to_name(unsigned char type)
56434 +{
56435 + return gr_socktypes[type];
56436 +}
56437 +
56438 +const char *
56439 +gr_sockfamily_to_name(unsigned char family)
56440 +{
56441 + return gr_sockfamilies[family];
56442 +}
56443 +
56444 +int
56445 +gr_search_socket(const int domain, const int type, const int protocol)
56446 +{
56447 + struct acl_subject_label *curr;
56448 + const struct cred *cred = current_cred();
56449 +
56450 + if (unlikely(!gr_acl_is_enabled()))
56451 + goto exit;
56452 +
56453 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56454 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56455 + goto exit; // let the kernel handle it
56456 +
56457 + curr = current->acl;
56458 +
56459 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56460 + /* the family is allowed, if this is PF_INET allow it only if
56461 + the extra sock type/protocol checks pass */
56462 + if (domain == PF_INET)
56463 + goto inet_check;
56464 + goto exit;
56465 + } else {
56466 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56467 + __u32 fakeip = 0;
56468 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56469 + current->role->roletype, cred->uid,
56470 + cred->gid, current->exec_file ?
56471 + gr_to_filename(current->exec_file->f_path.dentry,
56472 + current->exec_file->f_path.mnt) :
56473 + curr->filename, curr->filename,
56474 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56475 + &current->signal->saved_ip);
56476 + goto exit;
56477 + }
56478 + goto exit_fail;
56479 + }
56480 +
56481 +inet_check:
56482 + /* the rest of this checking is for IPv4 only */
56483 + if (!curr->ips)
56484 + goto exit;
56485 +
56486 + if ((curr->ip_type & (1 << type)) &&
56487 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56488 + goto exit;
56489 +
56490 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56491 + /* we don't place acls on raw sockets , and sometimes
56492 + dgram/ip sockets are opened for ioctl and not
56493 + bind/connect, so we'll fake a bind learn log */
56494 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56495 + __u32 fakeip = 0;
56496 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56497 + current->role->roletype, cred->uid,
56498 + cred->gid, current->exec_file ?
56499 + gr_to_filename(current->exec_file->f_path.dentry,
56500 + current->exec_file->f_path.mnt) :
56501 + curr->filename, curr->filename,
56502 + &fakeip, 0, type,
56503 + protocol, GR_CONNECT, &current->signal->saved_ip);
56504 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56505 + __u32 fakeip = 0;
56506 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56507 + current->role->roletype, cred->uid,
56508 + cred->gid, current->exec_file ?
56509 + gr_to_filename(current->exec_file->f_path.dentry,
56510 + current->exec_file->f_path.mnt) :
56511 + curr->filename, curr->filename,
56512 + &fakeip, 0, type,
56513 + protocol, GR_BIND, &current->signal->saved_ip);
56514 + }
56515 + /* we'll log when they use connect or bind */
56516 + goto exit;
56517 + }
56518 +
56519 +exit_fail:
56520 + if (domain == PF_INET)
56521 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56522 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56523 + else
56524 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56525 + gr_socktype_to_name(type), protocol);
56526 +
56527 + return 0;
56528 +exit:
56529 + return 1;
56530 +}
56531 +
56532 +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)
56533 +{
56534 + if ((ip->mode & mode) &&
56535 + (ip_port >= ip->low) &&
56536 + (ip_port <= ip->high) &&
56537 + ((ntohl(ip_addr) & our_netmask) ==
56538 + (ntohl(our_addr) & our_netmask))
56539 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56540 + && (ip->type & (1 << type))) {
56541 + if (ip->mode & GR_INVERT)
56542 + return 2; // specifically denied
56543 + else
56544 + return 1; // allowed
56545 + }
56546 +
56547 + return 0; // not specifically allowed, may continue parsing
56548 +}
56549 +
56550 +static int
56551 +gr_search_connectbind(const int full_mode, struct sock *sk,
56552 + struct sockaddr_in *addr, const int type)
56553 +{
56554 + char iface[IFNAMSIZ] = {0};
56555 + struct acl_subject_label *curr;
56556 + struct acl_ip_label *ip;
56557 + struct inet_sock *isk;
56558 + struct net_device *dev;
56559 + struct in_device *idev;
56560 + unsigned long i;
56561 + int ret;
56562 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56563 + __u32 ip_addr = 0;
56564 + __u32 our_addr;
56565 + __u32 our_netmask;
56566 + char *p;
56567 + __u16 ip_port = 0;
56568 + const struct cred *cred = current_cred();
56569 +
56570 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56571 + return 0;
56572 +
56573 + curr = current->acl;
56574 + isk = inet_sk(sk);
56575 +
56576 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56577 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56578 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56579 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56580 + struct sockaddr_in saddr;
56581 + int err;
56582 +
56583 + saddr.sin_family = AF_INET;
56584 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56585 + saddr.sin_port = isk->inet_sport;
56586 +
56587 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56588 + if (err)
56589 + return err;
56590 +
56591 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56592 + if (err)
56593 + return err;
56594 + }
56595 +
56596 + if (!curr->ips)
56597 + return 0;
56598 +
56599 + ip_addr = addr->sin_addr.s_addr;
56600 + ip_port = ntohs(addr->sin_port);
56601 +
56602 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56603 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56604 + current->role->roletype, cred->uid,
56605 + cred->gid, current->exec_file ?
56606 + gr_to_filename(current->exec_file->f_path.dentry,
56607 + current->exec_file->f_path.mnt) :
56608 + curr->filename, curr->filename,
56609 + &ip_addr, ip_port, type,
56610 + sk->sk_protocol, mode, &current->signal->saved_ip);
56611 + return 0;
56612 + }
56613 +
56614 + for (i = 0; i < curr->ip_num; i++) {
56615 + ip = *(curr->ips + i);
56616 + if (ip->iface != NULL) {
56617 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56618 + p = strchr(iface, ':');
56619 + if (p != NULL)
56620 + *p = '\0';
56621 + dev = dev_get_by_name(sock_net(sk), iface);
56622 + if (dev == NULL)
56623 + continue;
56624 + idev = in_dev_get(dev);
56625 + if (idev == NULL) {
56626 + dev_put(dev);
56627 + continue;
56628 + }
56629 + rcu_read_lock();
56630 + for_ifa(idev) {
56631 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56632 + our_addr = ifa->ifa_address;
56633 + our_netmask = 0xffffffff;
56634 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56635 + if (ret == 1) {
56636 + rcu_read_unlock();
56637 + in_dev_put(idev);
56638 + dev_put(dev);
56639 + return 0;
56640 + } else if (ret == 2) {
56641 + rcu_read_unlock();
56642 + in_dev_put(idev);
56643 + dev_put(dev);
56644 + goto denied;
56645 + }
56646 + }
56647 + } endfor_ifa(idev);
56648 + rcu_read_unlock();
56649 + in_dev_put(idev);
56650 + dev_put(dev);
56651 + } else {
56652 + our_addr = ip->addr;
56653 + our_netmask = ip->netmask;
56654 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56655 + if (ret == 1)
56656 + return 0;
56657 + else if (ret == 2)
56658 + goto denied;
56659 + }
56660 + }
56661 +
56662 +denied:
56663 + if (mode == GR_BIND)
56664 + 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));
56665 + else if (mode == GR_CONNECT)
56666 + 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));
56667 +
56668 + return -EACCES;
56669 +}
56670 +
56671 +int
56672 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56673 +{
56674 + /* always allow disconnection of dgram sockets with connect */
56675 + if (addr->sin_family == AF_UNSPEC)
56676 + return 0;
56677 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56678 +}
56679 +
56680 +int
56681 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56682 +{
56683 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56684 +}
56685 +
56686 +int gr_search_listen(struct socket *sock)
56687 +{
56688 + struct sock *sk = sock->sk;
56689 + struct sockaddr_in addr;
56690 +
56691 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56692 + addr.sin_port = inet_sk(sk)->inet_sport;
56693 +
56694 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56695 +}
56696 +
56697 +int gr_search_accept(struct socket *sock)
56698 +{
56699 + struct sock *sk = sock->sk;
56700 + struct sockaddr_in addr;
56701 +
56702 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56703 + addr.sin_port = inet_sk(sk)->inet_sport;
56704 +
56705 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56706 +}
56707 +
56708 +int
56709 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56710 +{
56711 + if (addr)
56712 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56713 + else {
56714 + struct sockaddr_in sin;
56715 + const struct inet_sock *inet = inet_sk(sk);
56716 +
56717 + sin.sin_addr.s_addr = inet->inet_daddr;
56718 + sin.sin_port = inet->inet_dport;
56719 +
56720 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56721 + }
56722 +}
56723 +
56724 +int
56725 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56726 +{
56727 + struct sockaddr_in sin;
56728 +
56729 + if (unlikely(skb->len < sizeof (struct udphdr)))
56730 + return 0; // skip this packet
56731 +
56732 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56733 + sin.sin_port = udp_hdr(skb)->source;
56734 +
56735 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56736 +}
56737 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56738 new file mode 100644
56739 index 0000000..25f54ef
56740 --- /dev/null
56741 +++ b/grsecurity/gracl_learn.c
56742 @@ -0,0 +1,207 @@
56743 +#include <linux/kernel.h>
56744 +#include <linux/mm.h>
56745 +#include <linux/sched.h>
56746 +#include <linux/poll.h>
56747 +#include <linux/string.h>
56748 +#include <linux/file.h>
56749 +#include <linux/types.h>
56750 +#include <linux/vmalloc.h>
56751 +#include <linux/grinternal.h>
56752 +
56753 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56754 + size_t count, loff_t *ppos);
56755 +extern int gr_acl_is_enabled(void);
56756 +
56757 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56758 +static int gr_learn_attached;
56759 +
56760 +/* use a 512k buffer */
56761 +#define LEARN_BUFFER_SIZE (512 * 1024)
56762 +
56763 +static DEFINE_SPINLOCK(gr_learn_lock);
56764 +static DEFINE_MUTEX(gr_learn_user_mutex);
56765 +
56766 +/* we need to maintain two buffers, so that the kernel context of grlearn
56767 + uses a semaphore around the userspace copying, and the other kernel contexts
56768 + use a spinlock when copying into the buffer, since they cannot sleep
56769 +*/
56770 +static char *learn_buffer;
56771 +static char *learn_buffer_user;
56772 +static int learn_buffer_len;
56773 +static int learn_buffer_user_len;
56774 +
56775 +static ssize_t
56776 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56777 +{
56778 + DECLARE_WAITQUEUE(wait, current);
56779 + ssize_t retval = 0;
56780 +
56781 + add_wait_queue(&learn_wait, &wait);
56782 + set_current_state(TASK_INTERRUPTIBLE);
56783 + do {
56784 + mutex_lock(&gr_learn_user_mutex);
56785 + spin_lock(&gr_learn_lock);
56786 + if (learn_buffer_len)
56787 + break;
56788 + spin_unlock(&gr_learn_lock);
56789 + mutex_unlock(&gr_learn_user_mutex);
56790 + if (file->f_flags & O_NONBLOCK) {
56791 + retval = -EAGAIN;
56792 + goto out;
56793 + }
56794 + if (signal_pending(current)) {
56795 + retval = -ERESTARTSYS;
56796 + goto out;
56797 + }
56798 +
56799 + schedule();
56800 + } while (1);
56801 +
56802 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56803 + learn_buffer_user_len = learn_buffer_len;
56804 + retval = learn_buffer_len;
56805 + learn_buffer_len = 0;
56806 +
56807 + spin_unlock(&gr_learn_lock);
56808 +
56809 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56810 + retval = -EFAULT;
56811 +
56812 + mutex_unlock(&gr_learn_user_mutex);
56813 +out:
56814 + set_current_state(TASK_RUNNING);
56815 + remove_wait_queue(&learn_wait, &wait);
56816 + return retval;
56817 +}
56818 +
56819 +static unsigned int
56820 +poll_learn(struct file * file, poll_table * wait)
56821 +{
56822 + poll_wait(file, &learn_wait, wait);
56823 +
56824 + if (learn_buffer_len)
56825 + return (POLLIN | POLLRDNORM);
56826 +
56827 + return 0;
56828 +}
56829 +
56830 +void
56831 +gr_clear_learn_entries(void)
56832 +{
56833 + char *tmp;
56834 +
56835 + mutex_lock(&gr_learn_user_mutex);
56836 + spin_lock(&gr_learn_lock);
56837 + tmp = learn_buffer;
56838 + learn_buffer = NULL;
56839 + spin_unlock(&gr_learn_lock);
56840 + if (tmp)
56841 + vfree(tmp);
56842 + if (learn_buffer_user != NULL) {
56843 + vfree(learn_buffer_user);
56844 + learn_buffer_user = NULL;
56845 + }
56846 + learn_buffer_len = 0;
56847 + mutex_unlock(&gr_learn_user_mutex);
56848 +
56849 + return;
56850 +}
56851 +
56852 +void
56853 +gr_add_learn_entry(const char *fmt, ...)
56854 +{
56855 + va_list args;
56856 + unsigned int len;
56857 +
56858 + if (!gr_learn_attached)
56859 + return;
56860 +
56861 + spin_lock(&gr_learn_lock);
56862 +
56863 + /* leave a gap at the end so we know when it's "full" but don't have to
56864 + compute the exact length of the string we're trying to append
56865 + */
56866 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56867 + spin_unlock(&gr_learn_lock);
56868 + wake_up_interruptible(&learn_wait);
56869 + return;
56870 + }
56871 + if (learn_buffer == NULL) {
56872 + spin_unlock(&gr_learn_lock);
56873 + return;
56874 + }
56875 +
56876 + va_start(args, fmt);
56877 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56878 + va_end(args);
56879 +
56880 + learn_buffer_len += len + 1;
56881 +
56882 + spin_unlock(&gr_learn_lock);
56883 + wake_up_interruptible(&learn_wait);
56884 +
56885 + return;
56886 +}
56887 +
56888 +static int
56889 +open_learn(struct inode *inode, struct file *file)
56890 +{
56891 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56892 + return -EBUSY;
56893 + if (file->f_mode & FMODE_READ) {
56894 + int retval = 0;
56895 + mutex_lock(&gr_learn_user_mutex);
56896 + if (learn_buffer == NULL)
56897 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56898 + if (learn_buffer_user == NULL)
56899 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56900 + if (learn_buffer == NULL) {
56901 + retval = -ENOMEM;
56902 + goto out_error;
56903 + }
56904 + if (learn_buffer_user == NULL) {
56905 + retval = -ENOMEM;
56906 + goto out_error;
56907 + }
56908 + learn_buffer_len = 0;
56909 + learn_buffer_user_len = 0;
56910 + gr_learn_attached = 1;
56911 +out_error:
56912 + mutex_unlock(&gr_learn_user_mutex);
56913 + return retval;
56914 + }
56915 + return 0;
56916 +}
56917 +
56918 +static int
56919 +close_learn(struct inode *inode, struct file *file)
56920 +{
56921 + if (file->f_mode & FMODE_READ) {
56922 + char *tmp = NULL;
56923 + mutex_lock(&gr_learn_user_mutex);
56924 + spin_lock(&gr_learn_lock);
56925 + tmp = learn_buffer;
56926 + learn_buffer = NULL;
56927 + spin_unlock(&gr_learn_lock);
56928 + if (tmp)
56929 + vfree(tmp);
56930 + if (learn_buffer_user != NULL) {
56931 + vfree(learn_buffer_user);
56932 + learn_buffer_user = NULL;
56933 + }
56934 + learn_buffer_len = 0;
56935 + learn_buffer_user_len = 0;
56936 + gr_learn_attached = 0;
56937 + mutex_unlock(&gr_learn_user_mutex);
56938 + }
56939 +
56940 + return 0;
56941 +}
56942 +
56943 +const struct file_operations grsec_fops = {
56944 + .read = read_learn,
56945 + .write = write_grsec_handler,
56946 + .open = open_learn,
56947 + .release = close_learn,
56948 + .poll = poll_learn,
56949 +};
56950 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56951 new file mode 100644
56952 index 0000000..39645c9
56953 --- /dev/null
56954 +++ b/grsecurity/gracl_res.c
56955 @@ -0,0 +1,68 @@
56956 +#include <linux/kernel.h>
56957 +#include <linux/sched.h>
56958 +#include <linux/gracl.h>
56959 +#include <linux/grinternal.h>
56960 +
56961 +static const char *restab_log[] = {
56962 + [RLIMIT_CPU] = "RLIMIT_CPU",
56963 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56964 + [RLIMIT_DATA] = "RLIMIT_DATA",
56965 + [RLIMIT_STACK] = "RLIMIT_STACK",
56966 + [RLIMIT_CORE] = "RLIMIT_CORE",
56967 + [RLIMIT_RSS] = "RLIMIT_RSS",
56968 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56969 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56970 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56971 + [RLIMIT_AS] = "RLIMIT_AS",
56972 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56973 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56974 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56975 + [RLIMIT_NICE] = "RLIMIT_NICE",
56976 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56977 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56978 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56979 +};
56980 +
56981 +void
56982 +gr_log_resource(const struct task_struct *task,
56983 + const int res, const unsigned long wanted, const int gt)
56984 +{
56985 + const struct cred *cred;
56986 + unsigned long rlim;
56987 +
56988 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56989 + return;
56990 +
56991 + // not yet supported resource
56992 + if (unlikely(!restab_log[res]))
56993 + return;
56994 +
56995 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56996 + rlim = task_rlimit_max(task, res);
56997 + else
56998 + rlim = task_rlimit(task, res);
56999 +
57000 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57001 + return;
57002 +
57003 + rcu_read_lock();
57004 + cred = __task_cred(task);
57005 +
57006 + if (res == RLIMIT_NPROC &&
57007 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57008 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57009 + goto out_rcu_unlock;
57010 + else if (res == RLIMIT_MEMLOCK &&
57011 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57012 + goto out_rcu_unlock;
57013 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57014 + goto out_rcu_unlock;
57015 + rcu_read_unlock();
57016 +
57017 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57018 +
57019 + return;
57020 +out_rcu_unlock:
57021 + rcu_read_unlock();
57022 + return;
57023 +}
57024 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57025 new file mode 100644
57026 index 0000000..25197e9
57027 --- /dev/null
57028 +++ b/grsecurity/gracl_segv.c
57029 @@ -0,0 +1,299 @@
57030 +#include <linux/kernel.h>
57031 +#include <linux/mm.h>
57032 +#include <asm/uaccess.h>
57033 +#include <asm/errno.h>
57034 +#include <asm/mman.h>
57035 +#include <net/sock.h>
57036 +#include <linux/file.h>
57037 +#include <linux/fs.h>
57038 +#include <linux/net.h>
57039 +#include <linux/in.h>
57040 +#include <linux/slab.h>
57041 +#include <linux/types.h>
57042 +#include <linux/sched.h>
57043 +#include <linux/timer.h>
57044 +#include <linux/gracl.h>
57045 +#include <linux/grsecurity.h>
57046 +#include <linux/grinternal.h>
57047 +
57048 +static struct crash_uid *uid_set;
57049 +static unsigned short uid_used;
57050 +static DEFINE_SPINLOCK(gr_uid_lock);
57051 +extern rwlock_t gr_inode_lock;
57052 +extern struct acl_subject_label *
57053 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57054 + struct acl_role_label *role);
57055 +
57056 +#ifdef CONFIG_BTRFS_FS
57057 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57058 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57059 +#endif
57060 +
57061 +static inline dev_t __get_dev(const struct dentry *dentry)
57062 +{
57063 +#ifdef CONFIG_BTRFS_FS
57064 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57065 + return get_btrfs_dev_from_inode(dentry->d_inode);
57066 + else
57067 +#endif
57068 + return dentry->d_inode->i_sb->s_dev;
57069 +}
57070 +
57071 +int
57072 +gr_init_uidset(void)
57073 +{
57074 + uid_set =
57075 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57076 + uid_used = 0;
57077 +
57078 + return uid_set ? 1 : 0;
57079 +}
57080 +
57081 +void
57082 +gr_free_uidset(void)
57083 +{
57084 + if (uid_set)
57085 + kfree(uid_set);
57086 +
57087 + return;
57088 +}
57089 +
57090 +int
57091 +gr_find_uid(const uid_t uid)
57092 +{
57093 + struct crash_uid *tmp = uid_set;
57094 + uid_t buid;
57095 + int low = 0, high = uid_used - 1, mid;
57096 +
57097 + while (high >= low) {
57098 + mid = (low + high) >> 1;
57099 + buid = tmp[mid].uid;
57100 + if (buid == uid)
57101 + return mid;
57102 + if (buid > uid)
57103 + high = mid - 1;
57104 + if (buid < uid)
57105 + low = mid + 1;
57106 + }
57107 +
57108 + return -1;
57109 +}
57110 +
57111 +static __inline__ void
57112 +gr_insertsort(void)
57113 +{
57114 + unsigned short i, j;
57115 + struct crash_uid index;
57116 +
57117 + for (i = 1; i < uid_used; i++) {
57118 + index = uid_set[i];
57119 + j = i;
57120 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57121 + uid_set[j] = uid_set[j - 1];
57122 + j--;
57123 + }
57124 + uid_set[j] = index;
57125 + }
57126 +
57127 + return;
57128 +}
57129 +
57130 +static __inline__ void
57131 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57132 +{
57133 + int loc;
57134 +
57135 + if (uid_used == GR_UIDTABLE_MAX)
57136 + return;
57137 +
57138 + loc = gr_find_uid(uid);
57139 +
57140 + if (loc >= 0) {
57141 + uid_set[loc].expires = expires;
57142 + return;
57143 + }
57144 +
57145 + uid_set[uid_used].uid = uid;
57146 + uid_set[uid_used].expires = expires;
57147 + uid_used++;
57148 +
57149 + gr_insertsort();
57150 +
57151 + return;
57152 +}
57153 +
57154 +void
57155 +gr_remove_uid(const unsigned short loc)
57156 +{
57157 + unsigned short i;
57158 +
57159 + for (i = loc + 1; i < uid_used; i++)
57160 + uid_set[i - 1] = uid_set[i];
57161 +
57162 + uid_used--;
57163 +
57164 + return;
57165 +}
57166 +
57167 +int
57168 +gr_check_crash_uid(const uid_t uid)
57169 +{
57170 + int loc;
57171 + int ret = 0;
57172 +
57173 + if (unlikely(!gr_acl_is_enabled()))
57174 + return 0;
57175 +
57176 + spin_lock(&gr_uid_lock);
57177 + loc = gr_find_uid(uid);
57178 +
57179 + if (loc < 0)
57180 + goto out_unlock;
57181 +
57182 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57183 + gr_remove_uid(loc);
57184 + else
57185 + ret = 1;
57186 +
57187 +out_unlock:
57188 + spin_unlock(&gr_uid_lock);
57189 + return ret;
57190 +}
57191 +
57192 +static __inline__ int
57193 +proc_is_setxid(const struct cred *cred)
57194 +{
57195 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57196 + !uid_eq(cred->uid, cred->fsuid))
57197 + return 1;
57198 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57199 + !uid_eq(cred->gid, cred->fsgid))
57200 + return 1;
57201 +
57202 + return 0;
57203 +}
57204 +
57205 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57206 +
57207 +void
57208 +gr_handle_crash(struct task_struct *task, const int sig)
57209 +{
57210 + struct acl_subject_label *curr;
57211 + struct task_struct *tsk, *tsk2;
57212 + const struct cred *cred;
57213 + const struct cred *cred2;
57214 +
57215 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57216 + return;
57217 +
57218 + if (unlikely(!gr_acl_is_enabled()))
57219 + return;
57220 +
57221 + curr = task->acl;
57222 +
57223 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57224 + return;
57225 +
57226 + if (time_before_eq(curr->expires, get_seconds())) {
57227 + curr->expires = 0;
57228 + curr->crashes = 0;
57229 + }
57230 +
57231 + curr->crashes++;
57232 +
57233 + if (!curr->expires)
57234 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57235 +
57236 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57237 + time_after(curr->expires, get_seconds())) {
57238 + rcu_read_lock();
57239 + cred = __task_cred(task);
57240 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57241 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57242 + spin_lock(&gr_uid_lock);
57243 + gr_insert_uid(cred->uid, curr->expires);
57244 + spin_unlock(&gr_uid_lock);
57245 + curr->expires = 0;
57246 + curr->crashes = 0;
57247 + read_lock(&tasklist_lock);
57248 + do_each_thread(tsk2, tsk) {
57249 + cred2 = __task_cred(tsk);
57250 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57251 + gr_fake_force_sig(SIGKILL, tsk);
57252 + } while_each_thread(tsk2, tsk);
57253 + read_unlock(&tasklist_lock);
57254 + } else {
57255 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57256 + read_lock(&tasklist_lock);
57257 + read_lock(&grsec_exec_file_lock);
57258 + do_each_thread(tsk2, tsk) {
57259 + if (likely(tsk != task)) {
57260 + // if this thread has the same subject as the one that triggered
57261 + // RES_CRASH and it's the same binary, kill it
57262 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57263 + gr_fake_force_sig(SIGKILL, tsk);
57264 + }
57265 + } while_each_thread(tsk2, tsk);
57266 + read_unlock(&grsec_exec_file_lock);
57267 + read_unlock(&tasklist_lock);
57268 + }
57269 + rcu_read_unlock();
57270 + }
57271 +
57272 + return;
57273 +}
57274 +
57275 +int
57276 +gr_check_crash_exec(const struct file *filp)
57277 +{
57278 + struct acl_subject_label *curr;
57279 +
57280 + if (unlikely(!gr_acl_is_enabled()))
57281 + return 0;
57282 +
57283 + read_lock(&gr_inode_lock);
57284 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57285 + __get_dev(filp->f_path.dentry),
57286 + current->role);
57287 + read_unlock(&gr_inode_lock);
57288 +
57289 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57290 + (!curr->crashes && !curr->expires))
57291 + return 0;
57292 +
57293 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57294 + time_after(curr->expires, get_seconds()))
57295 + return 1;
57296 + else if (time_before_eq(curr->expires, get_seconds())) {
57297 + curr->crashes = 0;
57298 + curr->expires = 0;
57299 + }
57300 +
57301 + return 0;
57302 +}
57303 +
57304 +void
57305 +gr_handle_alertkill(struct task_struct *task)
57306 +{
57307 + struct acl_subject_label *curracl;
57308 + __u32 curr_ip;
57309 + struct task_struct *p, *p2;
57310 +
57311 + if (unlikely(!gr_acl_is_enabled()))
57312 + return;
57313 +
57314 + curracl = task->acl;
57315 + curr_ip = task->signal->curr_ip;
57316 +
57317 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57318 + read_lock(&tasklist_lock);
57319 + do_each_thread(p2, p) {
57320 + if (p->signal->curr_ip == curr_ip)
57321 + gr_fake_force_sig(SIGKILL, p);
57322 + } while_each_thread(p2, p);
57323 + read_unlock(&tasklist_lock);
57324 + } else if (curracl->mode & GR_KILLPROC)
57325 + gr_fake_force_sig(SIGKILL, task);
57326 +
57327 + return;
57328 +}
57329 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57330 new file mode 100644
57331 index 0000000..9d83a69
57332 --- /dev/null
57333 +++ b/grsecurity/gracl_shm.c
57334 @@ -0,0 +1,40 @@
57335 +#include <linux/kernel.h>
57336 +#include <linux/mm.h>
57337 +#include <linux/sched.h>
57338 +#include <linux/file.h>
57339 +#include <linux/ipc.h>
57340 +#include <linux/gracl.h>
57341 +#include <linux/grsecurity.h>
57342 +#include <linux/grinternal.h>
57343 +
57344 +int
57345 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57346 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57347 +{
57348 + struct task_struct *task;
57349 +
57350 + if (!gr_acl_is_enabled())
57351 + return 1;
57352 +
57353 + rcu_read_lock();
57354 + read_lock(&tasklist_lock);
57355 +
57356 + task = find_task_by_vpid(shm_cprid);
57357 +
57358 + if (unlikely(!task))
57359 + task = find_task_by_vpid(shm_lapid);
57360 +
57361 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57362 + (task->pid == shm_lapid)) &&
57363 + (task->acl->mode & GR_PROTSHM) &&
57364 + (task->acl != current->acl))) {
57365 + read_unlock(&tasklist_lock);
57366 + rcu_read_unlock();
57367 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57368 + return 0;
57369 + }
57370 + read_unlock(&tasklist_lock);
57371 + rcu_read_unlock();
57372 +
57373 + return 1;
57374 +}
57375 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57376 new file mode 100644
57377 index 0000000..bc0be01
57378 --- /dev/null
57379 +++ b/grsecurity/grsec_chdir.c
57380 @@ -0,0 +1,19 @@
57381 +#include <linux/kernel.h>
57382 +#include <linux/sched.h>
57383 +#include <linux/fs.h>
57384 +#include <linux/file.h>
57385 +#include <linux/grsecurity.h>
57386 +#include <linux/grinternal.h>
57387 +
57388 +void
57389 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57390 +{
57391 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57392 + if ((grsec_enable_chdir && grsec_enable_group &&
57393 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57394 + !grsec_enable_group)) {
57395 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57396 + }
57397 +#endif
57398 + return;
57399 +}
57400 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57401 new file mode 100644
57402 index 0000000..9807ee2
57403 --- /dev/null
57404 +++ b/grsecurity/grsec_chroot.c
57405 @@ -0,0 +1,368 @@
57406 +#include <linux/kernel.h>
57407 +#include <linux/module.h>
57408 +#include <linux/sched.h>
57409 +#include <linux/file.h>
57410 +#include <linux/fs.h>
57411 +#include <linux/mount.h>
57412 +#include <linux/types.h>
57413 +#include "../fs/mount.h"
57414 +#include <linux/grsecurity.h>
57415 +#include <linux/grinternal.h>
57416 +
57417 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57418 +{
57419 +#ifdef CONFIG_GRKERNSEC
57420 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57421 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57422 + task->gr_is_chrooted = 1;
57423 + else
57424 + task->gr_is_chrooted = 0;
57425 +
57426 + task->gr_chroot_dentry = path->dentry;
57427 +#endif
57428 + return;
57429 +}
57430 +
57431 +void gr_clear_chroot_entries(struct task_struct *task)
57432 +{
57433 +#ifdef CONFIG_GRKERNSEC
57434 + task->gr_is_chrooted = 0;
57435 + task->gr_chroot_dentry = NULL;
57436 +#endif
57437 + return;
57438 +}
57439 +
57440 +int
57441 +gr_handle_chroot_unix(const pid_t pid)
57442 +{
57443 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57444 + struct task_struct *p;
57445 +
57446 + if (unlikely(!grsec_enable_chroot_unix))
57447 + return 1;
57448 +
57449 + if (likely(!proc_is_chrooted(current)))
57450 + return 1;
57451 +
57452 + rcu_read_lock();
57453 + read_lock(&tasklist_lock);
57454 + p = find_task_by_vpid_unrestricted(pid);
57455 + if (unlikely(p && !have_same_root(current, p))) {
57456 + read_unlock(&tasklist_lock);
57457 + rcu_read_unlock();
57458 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57459 + return 0;
57460 + }
57461 + read_unlock(&tasklist_lock);
57462 + rcu_read_unlock();
57463 +#endif
57464 + return 1;
57465 +}
57466 +
57467 +int
57468 +gr_handle_chroot_nice(void)
57469 +{
57470 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57471 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57472 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57473 + return -EPERM;
57474 + }
57475 +#endif
57476 + return 0;
57477 +}
57478 +
57479 +int
57480 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57481 +{
57482 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57483 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57484 + && proc_is_chrooted(current)) {
57485 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57486 + return -EACCES;
57487 + }
57488 +#endif
57489 + return 0;
57490 +}
57491 +
57492 +int
57493 +gr_handle_chroot_rawio(const struct inode *inode)
57494 +{
57495 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57496 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57497 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57498 + return 1;
57499 +#endif
57500 + return 0;
57501 +}
57502 +
57503 +int
57504 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57505 +{
57506 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57507 + struct task_struct *p;
57508 + int ret = 0;
57509 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57510 + return ret;
57511 +
57512 + read_lock(&tasklist_lock);
57513 + do_each_pid_task(pid, type, p) {
57514 + if (!have_same_root(current, p)) {
57515 + ret = 1;
57516 + goto out;
57517 + }
57518 + } while_each_pid_task(pid, type, p);
57519 +out:
57520 + read_unlock(&tasklist_lock);
57521 + return ret;
57522 +#endif
57523 + return 0;
57524 +}
57525 +
57526 +int
57527 +gr_pid_is_chrooted(struct task_struct *p)
57528 +{
57529 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57530 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57531 + return 0;
57532 +
57533 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57534 + !have_same_root(current, p)) {
57535 + return 1;
57536 + }
57537 +#endif
57538 + return 0;
57539 +}
57540 +
57541 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57542 +
57543 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57544 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57545 +{
57546 + struct path path, currentroot;
57547 + int ret = 0;
57548 +
57549 + path.dentry = (struct dentry *)u_dentry;
57550 + path.mnt = (struct vfsmount *)u_mnt;
57551 + get_fs_root(current->fs, &currentroot);
57552 + if (path_is_under(&path, &currentroot))
57553 + ret = 1;
57554 + path_put(&currentroot);
57555 +
57556 + return ret;
57557 +}
57558 +#endif
57559 +
57560 +int
57561 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57562 +{
57563 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57564 + if (!grsec_enable_chroot_fchdir)
57565 + return 1;
57566 +
57567 + if (!proc_is_chrooted(current))
57568 + return 1;
57569 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57570 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57571 + return 0;
57572 + }
57573 +#endif
57574 + return 1;
57575 +}
57576 +
57577 +int
57578 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57579 + const time_t shm_createtime)
57580 +{
57581 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57582 + struct task_struct *p;
57583 + time_t starttime;
57584 +
57585 + if (unlikely(!grsec_enable_chroot_shmat))
57586 + return 1;
57587 +
57588 + if (likely(!proc_is_chrooted(current)))
57589 + return 1;
57590 +
57591 + rcu_read_lock();
57592 + read_lock(&tasklist_lock);
57593 +
57594 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57595 + starttime = p->start_time.tv_sec;
57596 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57597 + if (have_same_root(current, p)) {
57598 + goto allow;
57599 + } else {
57600 + read_unlock(&tasklist_lock);
57601 + rcu_read_unlock();
57602 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57603 + return 0;
57604 + }
57605 + }
57606 + /* creator exited, pid reuse, fall through to next check */
57607 + }
57608 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57609 + if (unlikely(!have_same_root(current, p))) {
57610 + read_unlock(&tasklist_lock);
57611 + rcu_read_unlock();
57612 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57613 + return 0;
57614 + }
57615 + }
57616 +
57617 +allow:
57618 + read_unlock(&tasklist_lock);
57619 + rcu_read_unlock();
57620 +#endif
57621 + return 1;
57622 +}
57623 +
57624 +void
57625 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57626 +{
57627 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57628 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57629 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57630 +#endif
57631 + return;
57632 +}
57633 +
57634 +int
57635 +gr_handle_chroot_mknod(const struct dentry *dentry,
57636 + const struct vfsmount *mnt, const int mode)
57637 +{
57638 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57639 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57640 + proc_is_chrooted(current)) {
57641 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57642 + return -EPERM;
57643 + }
57644 +#endif
57645 + return 0;
57646 +}
57647 +
57648 +int
57649 +gr_handle_chroot_mount(const struct dentry *dentry,
57650 + const struct vfsmount *mnt, const char *dev_name)
57651 +{
57652 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57653 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57654 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57655 + return -EPERM;
57656 + }
57657 +#endif
57658 + return 0;
57659 +}
57660 +
57661 +int
57662 +gr_handle_chroot_pivot(void)
57663 +{
57664 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57665 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57666 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57667 + return -EPERM;
57668 + }
57669 +#endif
57670 + return 0;
57671 +}
57672 +
57673 +int
57674 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57675 +{
57676 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57677 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57678 + !gr_is_outside_chroot(dentry, mnt)) {
57679 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57680 + return -EPERM;
57681 + }
57682 +#endif
57683 + return 0;
57684 +}
57685 +
57686 +extern const char *captab_log[];
57687 +extern int captab_log_entries;
57688 +
57689 +int
57690 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57691 +{
57692 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57693 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57694 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57695 + if (cap_raised(chroot_caps, cap)) {
57696 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57697 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57698 + }
57699 + return 0;
57700 + }
57701 + }
57702 +#endif
57703 + return 1;
57704 +}
57705 +
57706 +int
57707 +gr_chroot_is_capable(const int cap)
57708 +{
57709 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57710 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57711 +#endif
57712 + return 1;
57713 +}
57714 +
57715 +int
57716 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57717 +{
57718 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57719 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57720 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57721 + if (cap_raised(chroot_caps, cap)) {
57722 + return 0;
57723 + }
57724 + }
57725 +#endif
57726 + return 1;
57727 +}
57728 +
57729 +int
57730 +gr_chroot_is_capable_nolog(const int cap)
57731 +{
57732 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57733 + return gr_task_chroot_is_capable_nolog(current, cap);
57734 +#endif
57735 + return 1;
57736 +}
57737 +
57738 +int
57739 +gr_handle_chroot_sysctl(const int op)
57740 +{
57741 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57742 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57743 + proc_is_chrooted(current))
57744 + return -EACCES;
57745 +#endif
57746 + return 0;
57747 +}
57748 +
57749 +void
57750 +gr_handle_chroot_chdir(struct path *path)
57751 +{
57752 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57753 + if (grsec_enable_chroot_chdir)
57754 + set_fs_pwd(current->fs, path);
57755 +#endif
57756 + return;
57757 +}
57758 +
57759 +int
57760 +gr_handle_chroot_chmod(const struct dentry *dentry,
57761 + const struct vfsmount *mnt, const int mode)
57762 +{
57763 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57764 + /* allow chmod +s on directories, but not files */
57765 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57766 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57767 + proc_is_chrooted(current)) {
57768 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57769 + return -EPERM;
57770 + }
57771 +#endif
57772 + return 0;
57773 +}
57774 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57775 new file mode 100644
57776 index 0000000..7de2055
57777 --- /dev/null
57778 +++ b/grsecurity/grsec_disabled.c
57779 @@ -0,0 +1,442 @@
57780 +#include <linux/kernel.h>
57781 +#include <linux/module.h>
57782 +#include <linux/sched.h>
57783 +#include <linux/file.h>
57784 +#include <linux/fs.h>
57785 +#include <linux/kdev_t.h>
57786 +#include <linux/net.h>
57787 +#include <linux/in.h>
57788 +#include <linux/ip.h>
57789 +#include <linux/skbuff.h>
57790 +#include <linux/sysctl.h>
57791 +
57792 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57793 +void
57794 +pax_set_initial_flags(struct linux_binprm *bprm)
57795 +{
57796 + return;
57797 +}
57798 +#endif
57799 +
57800 +#ifdef CONFIG_SYSCTL
57801 +__u32
57802 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57803 +{
57804 + return 0;
57805 +}
57806 +#endif
57807 +
57808 +#ifdef CONFIG_TASKSTATS
57809 +int gr_is_taskstats_denied(int pid)
57810 +{
57811 + return 0;
57812 +}
57813 +#endif
57814 +
57815 +int
57816 +gr_acl_is_enabled(void)
57817 +{
57818 + return 0;
57819 +}
57820 +
57821 +void
57822 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57823 +{
57824 + return;
57825 +}
57826 +
57827 +int
57828 +gr_handle_rawio(const struct inode *inode)
57829 +{
57830 + return 0;
57831 +}
57832 +
57833 +void
57834 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57835 +{
57836 + return;
57837 +}
57838 +
57839 +int
57840 +gr_handle_ptrace(struct task_struct *task, const long request)
57841 +{
57842 + return 0;
57843 +}
57844 +
57845 +int
57846 +gr_handle_proc_ptrace(struct task_struct *task)
57847 +{
57848 + return 0;
57849 +}
57850 +
57851 +void
57852 +gr_learn_resource(const struct task_struct *task,
57853 + const int res, const unsigned long wanted, const int gt)
57854 +{
57855 + return;
57856 +}
57857 +
57858 +int
57859 +gr_set_acls(const int type)
57860 +{
57861 + return 0;
57862 +}
57863 +
57864 +int
57865 +gr_check_hidden_task(const struct task_struct *tsk)
57866 +{
57867 + return 0;
57868 +}
57869 +
57870 +int
57871 +gr_check_protected_task(const struct task_struct *task)
57872 +{
57873 + return 0;
57874 +}
57875 +
57876 +int
57877 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57878 +{
57879 + return 0;
57880 +}
57881 +
57882 +void
57883 +gr_copy_label(struct task_struct *tsk)
57884 +{
57885 + return;
57886 +}
57887 +
57888 +void
57889 +gr_set_pax_flags(struct task_struct *task)
57890 +{
57891 + return;
57892 +}
57893 +
57894 +int
57895 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57896 + const int unsafe_share)
57897 +{
57898 + return 0;
57899 +}
57900 +
57901 +void
57902 +gr_handle_delete(const ino_t ino, const dev_t dev)
57903 +{
57904 + return;
57905 +}
57906 +
57907 +void
57908 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57909 +{
57910 + return;
57911 +}
57912 +
57913 +void
57914 +gr_handle_crash(struct task_struct *task, const int sig)
57915 +{
57916 + return;
57917 +}
57918 +
57919 +int
57920 +gr_check_crash_exec(const struct file *filp)
57921 +{
57922 + return 0;
57923 +}
57924 +
57925 +int
57926 +gr_check_crash_uid(const uid_t uid)
57927 +{
57928 + return 0;
57929 +}
57930 +
57931 +void
57932 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57933 + struct dentry *old_dentry,
57934 + struct dentry *new_dentry,
57935 + struct vfsmount *mnt, const __u8 replace)
57936 +{
57937 + return;
57938 +}
57939 +
57940 +int
57941 +gr_search_socket(const int family, const int type, const int protocol)
57942 +{
57943 + return 1;
57944 +}
57945 +
57946 +int
57947 +gr_search_connectbind(const int mode, const struct socket *sock,
57948 + const struct sockaddr_in *addr)
57949 +{
57950 + return 0;
57951 +}
57952 +
57953 +void
57954 +gr_handle_alertkill(struct task_struct *task)
57955 +{
57956 + return;
57957 +}
57958 +
57959 +__u32
57960 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57961 +{
57962 + return 1;
57963 +}
57964 +
57965 +__u32
57966 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57967 + const struct vfsmount * mnt)
57968 +{
57969 + return 1;
57970 +}
57971 +
57972 +__u32
57973 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57974 + int acc_mode)
57975 +{
57976 + return 1;
57977 +}
57978 +
57979 +__u32
57980 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57981 +{
57982 + return 1;
57983 +}
57984 +
57985 +__u32
57986 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57987 +{
57988 + return 1;
57989 +}
57990 +
57991 +int
57992 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57993 + unsigned int *vm_flags)
57994 +{
57995 + return 1;
57996 +}
57997 +
57998 +__u32
57999 +gr_acl_handle_truncate(const struct dentry * dentry,
58000 + const struct vfsmount * mnt)
58001 +{
58002 + return 1;
58003 +}
58004 +
58005 +__u32
58006 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58007 +{
58008 + return 1;
58009 +}
58010 +
58011 +__u32
58012 +gr_acl_handle_access(const struct dentry * dentry,
58013 + const struct vfsmount * mnt, const int fmode)
58014 +{
58015 + return 1;
58016 +}
58017 +
58018 +__u32
58019 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58020 + umode_t *mode)
58021 +{
58022 + return 1;
58023 +}
58024 +
58025 +__u32
58026 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58027 +{
58028 + return 1;
58029 +}
58030 +
58031 +__u32
58032 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58033 +{
58034 + return 1;
58035 +}
58036 +
58037 +void
58038 +grsecurity_init(void)
58039 +{
58040 + return;
58041 +}
58042 +
58043 +umode_t gr_acl_umask(void)
58044 +{
58045 + return 0;
58046 +}
58047 +
58048 +__u32
58049 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58050 + const struct dentry * parent_dentry,
58051 + const struct vfsmount * parent_mnt,
58052 + const int mode)
58053 +{
58054 + return 1;
58055 +}
58056 +
58057 +__u32
58058 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58059 + const struct dentry * parent_dentry,
58060 + const struct vfsmount * parent_mnt)
58061 +{
58062 + return 1;
58063 +}
58064 +
58065 +__u32
58066 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58067 + const struct dentry * parent_dentry,
58068 + const struct vfsmount * parent_mnt, const struct filename *from)
58069 +{
58070 + return 1;
58071 +}
58072 +
58073 +__u32
58074 +gr_acl_handle_link(const struct dentry * new_dentry,
58075 + const struct dentry * parent_dentry,
58076 + const struct vfsmount * parent_mnt,
58077 + const struct dentry * old_dentry,
58078 + const struct vfsmount * old_mnt, const struct filename *to)
58079 +{
58080 + return 1;
58081 +}
58082 +
58083 +int
58084 +gr_acl_handle_rename(const struct dentry *new_dentry,
58085 + const struct dentry *parent_dentry,
58086 + const struct vfsmount *parent_mnt,
58087 + const struct dentry *old_dentry,
58088 + const struct inode *old_parent_inode,
58089 + const struct vfsmount *old_mnt, const struct filename *newname)
58090 +{
58091 + return 0;
58092 +}
58093 +
58094 +int
58095 +gr_acl_handle_filldir(const struct file *file, const char *name,
58096 + const int namelen, const ino_t ino)
58097 +{
58098 + return 1;
58099 +}
58100 +
58101 +int
58102 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58103 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58104 +{
58105 + return 1;
58106 +}
58107 +
58108 +int
58109 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58110 +{
58111 + return 0;
58112 +}
58113 +
58114 +int
58115 +gr_search_accept(const struct socket *sock)
58116 +{
58117 + return 0;
58118 +}
58119 +
58120 +int
58121 +gr_search_listen(const struct socket *sock)
58122 +{
58123 + return 0;
58124 +}
58125 +
58126 +int
58127 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58128 +{
58129 + return 0;
58130 +}
58131 +
58132 +__u32
58133 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58134 +{
58135 + return 1;
58136 +}
58137 +
58138 +__u32
58139 +gr_acl_handle_creat(const struct dentry * dentry,
58140 + const struct dentry * p_dentry,
58141 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58142 + const int imode)
58143 +{
58144 + return 1;
58145 +}
58146 +
58147 +void
58148 +gr_acl_handle_exit(void)
58149 +{
58150 + return;
58151 +}
58152 +
58153 +int
58154 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58155 +{
58156 + return 1;
58157 +}
58158 +
58159 +void
58160 +gr_set_role_label(const uid_t uid, const gid_t gid)
58161 +{
58162 + return;
58163 +}
58164 +
58165 +int
58166 +gr_acl_handle_procpidmem(const struct task_struct *task)
58167 +{
58168 + return 0;
58169 +}
58170 +
58171 +int
58172 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58173 +{
58174 + return 0;
58175 +}
58176 +
58177 +int
58178 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58179 +{
58180 + return 0;
58181 +}
58182 +
58183 +void
58184 +gr_set_kernel_label(struct task_struct *task)
58185 +{
58186 + return;
58187 +}
58188 +
58189 +int
58190 +gr_check_user_change(int real, int effective, int fs)
58191 +{
58192 + return 0;
58193 +}
58194 +
58195 +int
58196 +gr_check_group_change(int real, int effective, int fs)
58197 +{
58198 + return 0;
58199 +}
58200 +
58201 +int gr_acl_enable_at_secure(void)
58202 +{
58203 + return 0;
58204 +}
58205 +
58206 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58207 +{
58208 + return dentry->d_inode->i_sb->s_dev;
58209 +}
58210 +
58211 +void gr_put_exec_file(struct task_struct *task)
58212 +{
58213 + return;
58214 +}
58215 +
58216 +EXPORT_SYMBOL(gr_learn_resource);
58217 +EXPORT_SYMBOL(gr_set_kernel_label);
58218 +#ifdef CONFIG_SECURITY
58219 +EXPORT_SYMBOL(gr_check_user_change);
58220 +EXPORT_SYMBOL(gr_check_group_change);
58221 +#endif
58222 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58223 new file mode 100644
58224 index 0000000..abfa971
58225 --- /dev/null
58226 +++ b/grsecurity/grsec_exec.c
58227 @@ -0,0 +1,174 @@
58228 +#include <linux/kernel.h>
58229 +#include <linux/sched.h>
58230 +#include <linux/file.h>
58231 +#include <linux/binfmts.h>
58232 +#include <linux/fs.h>
58233 +#include <linux/types.h>
58234 +#include <linux/grdefs.h>
58235 +#include <linux/grsecurity.h>
58236 +#include <linux/grinternal.h>
58237 +#include <linux/capability.h>
58238 +#include <linux/module.h>
58239 +
58240 +#include <asm/uaccess.h>
58241 +
58242 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58243 +static char gr_exec_arg_buf[132];
58244 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58245 +#endif
58246 +
58247 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58248 +
58249 +void
58250 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58251 +{
58252 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58253 + char *grarg = gr_exec_arg_buf;
58254 + unsigned int i, x, execlen = 0;
58255 + char c;
58256 +
58257 + if (!((grsec_enable_execlog && grsec_enable_group &&
58258 + in_group_p(grsec_audit_gid))
58259 + || (grsec_enable_execlog && !grsec_enable_group)))
58260 + return;
58261 +
58262 + mutex_lock(&gr_exec_arg_mutex);
58263 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58264 +
58265 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58266 + const char __user *p;
58267 + unsigned int len;
58268 +
58269 + p = get_user_arg_ptr(argv, i);
58270 + if (IS_ERR(p))
58271 + goto log;
58272 +
58273 + len = strnlen_user(p, 128 - execlen);
58274 + if (len > 128 - execlen)
58275 + len = 128 - execlen;
58276 + else if (len > 0)
58277 + len--;
58278 + if (copy_from_user(grarg + execlen, p, len))
58279 + goto log;
58280 +
58281 + /* rewrite unprintable characters */
58282 + for (x = 0; x < len; x++) {
58283 + c = *(grarg + execlen + x);
58284 + if (c < 32 || c > 126)
58285 + *(grarg + execlen + x) = ' ';
58286 + }
58287 +
58288 + execlen += len;
58289 + *(grarg + execlen) = ' ';
58290 + *(grarg + execlen + 1) = '\0';
58291 + execlen++;
58292 + }
58293 +
58294 + log:
58295 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58296 + bprm->file->f_path.mnt, grarg);
58297 + mutex_unlock(&gr_exec_arg_mutex);
58298 +#endif
58299 + return;
58300 +}
58301 +
58302 +#ifdef CONFIG_GRKERNSEC
58303 +extern int gr_acl_is_capable(const int cap);
58304 +extern int gr_acl_is_capable_nolog(const int cap);
58305 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58306 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58307 +extern int gr_chroot_is_capable(const int cap);
58308 +extern int gr_chroot_is_capable_nolog(const int cap);
58309 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58310 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58311 +#endif
58312 +
58313 +const char *captab_log[] = {
58314 + "CAP_CHOWN",
58315 + "CAP_DAC_OVERRIDE",
58316 + "CAP_DAC_READ_SEARCH",
58317 + "CAP_FOWNER",
58318 + "CAP_FSETID",
58319 + "CAP_KILL",
58320 + "CAP_SETGID",
58321 + "CAP_SETUID",
58322 + "CAP_SETPCAP",
58323 + "CAP_LINUX_IMMUTABLE",
58324 + "CAP_NET_BIND_SERVICE",
58325 + "CAP_NET_BROADCAST",
58326 + "CAP_NET_ADMIN",
58327 + "CAP_NET_RAW",
58328 + "CAP_IPC_LOCK",
58329 + "CAP_IPC_OWNER",
58330 + "CAP_SYS_MODULE",
58331 + "CAP_SYS_RAWIO",
58332 + "CAP_SYS_CHROOT",
58333 + "CAP_SYS_PTRACE",
58334 + "CAP_SYS_PACCT",
58335 + "CAP_SYS_ADMIN",
58336 + "CAP_SYS_BOOT",
58337 + "CAP_SYS_NICE",
58338 + "CAP_SYS_RESOURCE",
58339 + "CAP_SYS_TIME",
58340 + "CAP_SYS_TTY_CONFIG",
58341 + "CAP_MKNOD",
58342 + "CAP_LEASE",
58343 + "CAP_AUDIT_WRITE",
58344 + "CAP_AUDIT_CONTROL",
58345 + "CAP_SETFCAP",
58346 + "CAP_MAC_OVERRIDE",
58347 + "CAP_MAC_ADMIN",
58348 + "CAP_SYSLOG",
58349 + "CAP_WAKE_ALARM"
58350 +};
58351 +
58352 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58353 +
58354 +int gr_is_capable(const int cap)
58355 +{
58356 +#ifdef CONFIG_GRKERNSEC
58357 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58358 + return 1;
58359 + return 0;
58360 +#else
58361 + return 1;
58362 +#endif
58363 +}
58364 +
58365 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58366 +{
58367 +#ifdef CONFIG_GRKERNSEC
58368 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58369 + return 1;
58370 + return 0;
58371 +#else
58372 + return 1;
58373 +#endif
58374 +}
58375 +
58376 +int gr_is_capable_nolog(const int cap)
58377 +{
58378 +#ifdef CONFIG_GRKERNSEC
58379 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58380 + return 1;
58381 + return 0;
58382 +#else
58383 + return 1;
58384 +#endif
58385 +}
58386 +
58387 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58388 +{
58389 +#ifdef CONFIG_GRKERNSEC
58390 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58391 + return 1;
58392 + return 0;
58393 +#else
58394 + return 1;
58395 +#endif
58396 +}
58397 +
58398 +EXPORT_SYMBOL(gr_is_capable);
58399 +EXPORT_SYMBOL(gr_is_capable_nolog);
58400 +EXPORT_SYMBOL(gr_task_is_capable);
58401 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58402 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58403 new file mode 100644
58404 index 0000000..d3ee748
58405 --- /dev/null
58406 +++ b/grsecurity/grsec_fifo.c
58407 @@ -0,0 +1,24 @@
58408 +#include <linux/kernel.h>
58409 +#include <linux/sched.h>
58410 +#include <linux/fs.h>
58411 +#include <linux/file.h>
58412 +#include <linux/grinternal.h>
58413 +
58414 +int
58415 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58416 + const struct dentry *dir, const int flag, const int acc_mode)
58417 +{
58418 +#ifdef CONFIG_GRKERNSEC_FIFO
58419 + const struct cred *cred = current_cred();
58420 +
58421 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58422 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58423 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58424 + (cred->fsuid != dentry->d_inode->i_uid)) {
58425 + if (!inode_permission(dentry->d_inode, acc_mode))
58426 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58427 + return -EACCES;
58428 + }
58429 +#endif
58430 + return 0;
58431 +}
58432 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58433 new file mode 100644
58434 index 0000000..8ca18bf
58435 --- /dev/null
58436 +++ b/grsecurity/grsec_fork.c
58437 @@ -0,0 +1,23 @@
58438 +#include <linux/kernel.h>
58439 +#include <linux/sched.h>
58440 +#include <linux/grsecurity.h>
58441 +#include <linux/grinternal.h>
58442 +#include <linux/errno.h>
58443 +
58444 +void
58445 +gr_log_forkfail(const int retval)
58446 +{
58447 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58448 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58449 + switch (retval) {
58450 + case -EAGAIN:
58451 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58452 + break;
58453 + case -ENOMEM:
58454 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58455 + break;
58456 + }
58457 + }
58458 +#endif
58459 + return;
58460 +}
58461 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58462 new file mode 100644
58463 index 0000000..05a6015
58464 --- /dev/null
58465 +++ b/grsecurity/grsec_init.c
58466 @@ -0,0 +1,283 @@
58467 +#include <linux/kernel.h>
58468 +#include <linux/sched.h>
58469 +#include <linux/mm.h>
58470 +#include <linux/gracl.h>
58471 +#include <linux/slab.h>
58472 +#include <linux/vmalloc.h>
58473 +#include <linux/percpu.h>
58474 +#include <linux/module.h>
58475 +
58476 +int grsec_enable_ptrace_readexec;
58477 +int grsec_enable_setxid;
58478 +int grsec_enable_symlinkown;
58479 +int grsec_symlinkown_gid;
58480 +int grsec_enable_brute;
58481 +int grsec_enable_link;
58482 +int grsec_enable_dmesg;
58483 +int grsec_enable_harden_ptrace;
58484 +int grsec_enable_fifo;
58485 +int grsec_enable_execlog;
58486 +int grsec_enable_signal;
58487 +int grsec_enable_forkfail;
58488 +int grsec_enable_audit_ptrace;
58489 +int grsec_enable_time;
58490 +int grsec_enable_audit_textrel;
58491 +int grsec_enable_group;
58492 +int grsec_audit_gid;
58493 +int grsec_enable_chdir;
58494 +int grsec_enable_mount;
58495 +int grsec_enable_rofs;
58496 +int grsec_enable_chroot_findtask;
58497 +int grsec_enable_chroot_mount;
58498 +int grsec_enable_chroot_shmat;
58499 +int grsec_enable_chroot_fchdir;
58500 +int grsec_enable_chroot_double;
58501 +int grsec_enable_chroot_pivot;
58502 +int grsec_enable_chroot_chdir;
58503 +int grsec_enable_chroot_chmod;
58504 +int grsec_enable_chroot_mknod;
58505 +int grsec_enable_chroot_nice;
58506 +int grsec_enable_chroot_execlog;
58507 +int grsec_enable_chroot_caps;
58508 +int grsec_enable_chroot_sysctl;
58509 +int grsec_enable_chroot_unix;
58510 +int grsec_enable_tpe;
58511 +int grsec_tpe_gid;
58512 +int grsec_enable_blackhole;
58513 +#ifdef CONFIG_IPV6_MODULE
58514 +EXPORT_SYMBOL(grsec_enable_blackhole);
58515 +#endif
58516 +int grsec_lastack_retries;
58517 +int grsec_enable_tpe_all;
58518 +int grsec_enable_tpe_invert;
58519 +int grsec_enable_socket_all;
58520 +int grsec_socket_all_gid;
58521 +int grsec_enable_socket_client;
58522 +int grsec_socket_client_gid;
58523 +int grsec_enable_socket_server;
58524 +int grsec_socket_server_gid;
58525 +int grsec_resource_logging;
58526 +int grsec_disable_privio;
58527 +int grsec_enable_log_rwxmaps;
58528 +int grsec_lock;
58529 +
58530 +DEFINE_SPINLOCK(grsec_alert_lock);
58531 +unsigned long grsec_alert_wtime = 0;
58532 +unsigned long grsec_alert_fyet = 0;
58533 +
58534 +DEFINE_SPINLOCK(grsec_audit_lock);
58535 +
58536 +DEFINE_RWLOCK(grsec_exec_file_lock);
58537 +
58538 +char *gr_shared_page[4];
58539 +
58540 +char *gr_alert_log_fmt;
58541 +char *gr_audit_log_fmt;
58542 +char *gr_alert_log_buf;
58543 +char *gr_audit_log_buf;
58544 +
58545 +extern struct gr_arg *gr_usermode;
58546 +extern unsigned char *gr_system_salt;
58547 +extern unsigned char *gr_system_sum;
58548 +
58549 +void __init
58550 +grsecurity_init(void)
58551 +{
58552 + int j;
58553 + /* create the per-cpu shared pages */
58554 +
58555 +#ifdef CONFIG_X86
58556 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58557 +#endif
58558 +
58559 + for (j = 0; j < 4; j++) {
58560 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58561 + if (gr_shared_page[j] == NULL) {
58562 + panic("Unable to allocate grsecurity shared page");
58563 + return;
58564 + }
58565 + }
58566 +
58567 + /* allocate log buffers */
58568 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58569 + if (!gr_alert_log_fmt) {
58570 + panic("Unable to allocate grsecurity alert log format buffer");
58571 + return;
58572 + }
58573 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58574 + if (!gr_audit_log_fmt) {
58575 + panic("Unable to allocate grsecurity audit log format buffer");
58576 + return;
58577 + }
58578 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58579 + if (!gr_alert_log_buf) {
58580 + panic("Unable to allocate grsecurity alert log buffer");
58581 + return;
58582 + }
58583 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58584 + if (!gr_audit_log_buf) {
58585 + panic("Unable to allocate grsecurity audit log buffer");
58586 + return;
58587 + }
58588 +
58589 + /* allocate memory for authentication structure */
58590 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58591 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58592 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58593 +
58594 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58595 + panic("Unable to allocate grsecurity authentication structure");
58596 + return;
58597 + }
58598 +
58599 +
58600 +#ifdef CONFIG_GRKERNSEC_IO
58601 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58602 + grsec_disable_privio = 1;
58603 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58604 + grsec_disable_privio = 1;
58605 +#else
58606 + grsec_disable_privio = 0;
58607 +#endif
58608 +#endif
58609 +
58610 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58611 + /* for backward compatibility, tpe_invert always defaults to on if
58612 + enabled in the kernel
58613 + */
58614 + grsec_enable_tpe_invert = 1;
58615 +#endif
58616 +
58617 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58618 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58619 + grsec_lock = 1;
58620 +#endif
58621 +
58622 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58623 + grsec_enable_audit_textrel = 1;
58624 +#endif
58625 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58626 + grsec_enable_log_rwxmaps = 1;
58627 +#endif
58628 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58629 + grsec_enable_group = 1;
58630 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58631 +#endif
58632 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58633 + grsec_enable_ptrace_readexec = 1;
58634 +#endif
58635 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58636 + grsec_enable_chdir = 1;
58637 +#endif
58638 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58639 + grsec_enable_harden_ptrace = 1;
58640 +#endif
58641 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58642 + grsec_enable_mount = 1;
58643 +#endif
58644 +#ifdef CONFIG_GRKERNSEC_LINK
58645 + grsec_enable_link = 1;
58646 +#endif
58647 +#ifdef CONFIG_GRKERNSEC_BRUTE
58648 + grsec_enable_brute = 1;
58649 +#endif
58650 +#ifdef CONFIG_GRKERNSEC_DMESG
58651 + grsec_enable_dmesg = 1;
58652 +#endif
58653 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58654 + grsec_enable_blackhole = 1;
58655 + grsec_lastack_retries = 4;
58656 +#endif
58657 +#ifdef CONFIG_GRKERNSEC_FIFO
58658 + grsec_enable_fifo = 1;
58659 +#endif
58660 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58661 + grsec_enable_execlog = 1;
58662 +#endif
58663 +#ifdef CONFIG_GRKERNSEC_SETXID
58664 + grsec_enable_setxid = 1;
58665 +#endif
58666 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58667 + grsec_enable_signal = 1;
58668 +#endif
58669 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58670 + grsec_enable_forkfail = 1;
58671 +#endif
58672 +#ifdef CONFIG_GRKERNSEC_TIME
58673 + grsec_enable_time = 1;
58674 +#endif
58675 +#ifdef CONFIG_GRKERNSEC_RESLOG
58676 + grsec_resource_logging = 1;
58677 +#endif
58678 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58679 + grsec_enable_chroot_findtask = 1;
58680 +#endif
58681 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58682 + grsec_enable_chroot_unix = 1;
58683 +#endif
58684 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58685 + grsec_enable_chroot_mount = 1;
58686 +#endif
58687 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58688 + grsec_enable_chroot_fchdir = 1;
58689 +#endif
58690 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58691 + grsec_enable_chroot_shmat = 1;
58692 +#endif
58693 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58694 + grsec_enable_audit_ptrace = 1;
58695 +#endif
58696 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58697 + grsec_enable_chroot_double = 1;
58698 +#endif
58699 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58700 + grsec_enable_chroot_pivot = 1;
58701 +#endif
58702 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58703 + grsec_enable_chroot_chdir = 1;
58704 +#endif
58705 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58706 + grsec_enable_chroot_chmod = 1;
58707 +#endif
58708 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58709 + grsec_enable_chroot_mknod = 1;
58710 +#endif
58711 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58712 + grsec_enable_chroot_nice = 1;
58713 +#endif
58714 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58715 + grsec_enable_chroot_execlog = 1;
58716 +#endif
58717 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58718 + grsec_enable_chroot_caps = 1;
58719 +#endif
58720 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58721 + grsec_enable_chroot_sysctl = 1;
58722 +#endif
58723 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58724 + grsec_enable_symlinkown = 1;
58725 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58726 +#endif
58727 +#ifdef CONFIG_GRKERNSEC_TPE
58728 + grsec_enable_tpe = 1;
58729 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58730 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58731 + grsec_enable_tpe_all = 1;
58732 +#endif
58733 +#endif
58734 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58735 + grsec_enable_socket_all = 1;
58736 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58737 +#endif
58738 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58739 + grsec_enable_socket_client = 1;
58740 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58741 +#endif
58742 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58743 + grsec_enable_socket_server = 1;
58744 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58745 +#endif
58746 +#endif
58747 +
58748 + return;
58749 +}
58750 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58751 new file mode 100644
58752 index 0000000..6095407
58753 --- /dev/null
58754 +++ b/grsecurity/grsec_link.c
58755 @@ -0,0 +1,58 @@
58756 +#include <linux/kernel.h>
58757 +#include <linux/sched.h>
58758 +#include <linux/fs.h>
58759 +#include <linux/file.h>
58760 +#include <linux/grinternal.h>
58761 +
58762 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58763 +{
58764 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58765 + const struct inode *link_inode = link->dentry->d_inode;
58766 +
58767 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58768 + /* ignore root-owned links, e.g. /proc/self */
58769 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58770 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58771 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58772 + return 1;
58773 + }
58774 +#endif
58775 + return 0;
58776 +}
58777 +
58778 +int
58779 +gr_handle_follow_link(const struct inode *parent,
58780 + const struct inode *inode,
58781 + const struct dentry *dentry, const struct vfsmount *mnt)
58782 +{
58783 +#ifdef CONFIG_GRKERNSEC_LINK
58784 + const struct cred *cred = current_cred();
58785 +
58786 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58787 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58788 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58789 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58790 + return -EACCES;
58791 + }
58792 +#endif
58793 + return 0;
58794 +}
58795 +
58796 +int
58797 +gr_handle_hardlink(const struct dentry *dentry,
58798 + const struct vfsmount *mnt,
58799 + struct inode *inode, const int mode, const struct filename *to)
58800 +{
58801 +#ifdef CONFIG_GRKERNSEC_LINK
58802 + const struct cred *cred = current_cred();
58803 +
58804 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58805 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58806 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58807 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58808 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
58809 + return -EPERM;
58810 + }
58811 +#endif
58812 + return 0;
58813 +}
58814 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58815 new file mode 100644
58816 index 0000000..a45d2e9
58817 --- /dev/null
58818 +++ b/grsecurity/grsec_log.c
58819 @@ -0,0 +1,322 @@
58820 +#include <linux/kernel.h>
58821 +#include <linux/sched.h>
58822 +#include <linux/file.h>
58823 +#include <linux/tty.h>
58824 +#include <linux/fs.h>
58825 +#include <linux/grinternal.h>
58826 +
58827 +#ifdef CONFIG_TREE_PREEMPT_RCU
58828 +#define DISABLE_PREEMPT() preempt_disable()
58829 +#define ENABLE_PREEMPT() preempt_enable()
58830 +#else
58831 +#define DISABLE_PREEMPT()
58832 +#define ENABLE_PREEMPT()
58833 +#endif
58834 +
58835 +#define BEGIN_LOCKS(x) \
58836 + DISABLE_PREEMPT(); \
58837 + rcu_read_lock(); \
58838 + read_lock(&tasklist_lock); \
58839 + read_lock(&grsec_exec_file_lock); \
58840 + if (x != GR_DO_AUDIT) \
58841 + spin_lock(&grsec_alert_lock); \
58842 + else \
58843 + spin_lock(&grsec_audit_lock)
58844 +
58845 +#define END_LOCKS(x) \
58846 + if (x != GR_DO_AUDIT) \
58847 + spin_unlock(&grsec_alert_lock); \
58848 + else \
58849 + spin_unlock(&grsec_audit_lock); \
58850 + read_unlock(&grsec_exec_file_lock); \
58851 + read_unlock(&tasklist_lock); \
58852 + rcu_read_unlock(); \
58853 + ENABLE_PREEMPT(); \
58854 + if (x == GR_DONT_AUDIT) \
58855 + gr_handle_alertkill(current)
58856 +
58857 +enum {
58858 + FLOODING,
58859 + NO_FLOODING
58860 +};
58861 +
58862 +extern char *gr_alert_log_fmt;
58863 +extern char *gr_audit_log_fmt;
58864 +extern char *gr_alert_log_buf;
58865 +extern char *gr_audit_log_buf;
58866 +
58867 +static int gr_log_start(int audit)
58868 +{
58869 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58870 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58871 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58872 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58873 + unsigned long curr_secs = get_seconds();
58874 +
58875 + if (audit == GR_DO_AUDIT)
58876 + goto set_fmt;
58877 +
58878 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58879 + grsec_alert_wtime = curr_secs;
58880 + grsec_alert_fyet = 0;
58881 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58882 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58883 + grsec_alert_fyet++;
58884 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58885 + grsec_alert_wtime = curr_secs;
58886 + grsec_alert_fyet++;
58887 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58888 + return FLOODING;
58889 + }
58890 + else return FLOODING;
58891 +
58892 +set_fmt:
58893 +#endif
58894 + memset(buf, 0, PAGE_SIZE);
58895 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58896 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58897 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58898 + } else if (current->signal->curr_ip) {
58899 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58900 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58901 + } else if (gr_acl_is_enabled()) {
58902 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58903 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58904 + } else {
58905 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58906 + strcpy(buf, fmt);
58907 + }
58908 +
58909 + return NO_FLOODING;
58910 +}
58911 +
58912 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58913 + __attribute__ ((format (printf, 2, 0)));
58914 +
58915 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58916 +{
58917 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58918 + unsigned int len = strlen(buf);
58919 +
58920 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58921 +
58922 + return;
58923 +}
58924 +
58925 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58926 + __attribute__ ((format (printf, 2, 3)));
58927 +
58928 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58929 +{
58930 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58931 + unsigned int len = strlen(buf);
58932 + va_list ap;
58933 +
58934 + va_start(ap, msg);
58935 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58936 + va_end(ap);
58937 +
58938 + return;
58939 +}
58940 +
58941 +static void gr_log_end(int audit, int append_default)
58942 +{
58943 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58944 +
58945 + if (append_default) {
58946 + unsigned int len = strlen(buf);
58947 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58948 + }
58949 +
58950 + printk("%s\n", buf);
58951 +
58952 + return;
58953 +}
58954 +
58955 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58956 +{
58957 + int logtype;
58958 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58959 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58960 + void *voidptr = NULL;
58961 + int num1 = 0, num2 = 0;
58962 + unsigned long ulong1 = 0, ulong2 = 0;
58963 + struct dentry *dentry = NULL;
58964 + struct vfsmount *mnt = NULL;
58965 + struct file *file = NULL;
58966 + struct task_struct *task = NULL;
58967 + const struct cred *cred, *pcred;
58968 + va_list ap;
58969 +
58970 + BEGIN_LOCKS(audit);
58971 + logtype = gr_log_start(audit);
58972 + if (logtype == FLOODING) {
58973 + END_LOCKS(audit);
58974 + return;
58975 + }
58976 + va_start(ap, argtypes);
58977 + switch (argtypes) {
58978 + case GR_TTYSNIFF:
58979 + task = va_arg(ap, struct task_struct *);
58980 + 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);
58981 + break;
58982 + case GR_SYSCTL_HIDDEN:
58983 + str1 = va_arg(ap, char *);
58984 + gr_log_middle_varargs(audit, msg, result, str1);
58985 + break;
58986 + case GR_RBAC:
58987 + dentry = va_arg(ap, struct dentry *);
58988 + mnt = va_arg(ap, struct vfsmount *);
58989 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58990 + break;
58991 + case GR_RBAC_STR:
58992 + dentry = va_arg(ap, struct dentry *);
58993 + mnt = va_arg(ap, struct vfsmount *);
58994 + str1 = va_arg(ap, char *);
58995 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58996 + break;
58997 + case GR_STR_RBAC:
58998 + str1 = va_arg(ap, char *);
58999 + dentry = va_arg(ap, struct dentry *);
59000 + mnt = va_arg(ap, struct vfsmount *);
59001 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59002 + break;
59003 + case GR_RBAC_MODE2:
59004 + dentry = va_arg(ap, struct dentry *);
59005 + mnt = va_arg(ap, struct vfsmount *);
59006 + str1 = va_arg(ap, char *);
59007 + str2 = va_arg(ap, char *);
59008 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59009 + break;
59010 + case GR_RBAC_MODE3:
59011 + dentry = va_arg(ap, struct dentry *);
59012 + mnt = va_arg(ap, struct vfsmount *);
59013 + str1 = va_arg(ap, char *);
59014 + str2 = va_arg(ap, char *);
59015 + str3 = va_arg(ap, char *);
59016 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59017 + break;
59018 + case GR_FILENAME:
59019 + dentry = va_arg(ap, struct dentry *);
59020 + mnt = va_arg(ap, struct vfsmount *);
59021 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59022 + break;
59023 + case GR_STR_FILENAME:
59024 + str1 = va_arg(ap, char *);
59025 + dentry = va_arg(ap, struct dentry *);
59026 + mnt = va_arg(ap, struct vfsmount *);
59027 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59028 + break;
59029 + case GR_FILENAME_STR:
59030 + dentry = va_arg(ap, struct dentry *);
59031 + mnt = va_arg(ap, struct vfsmount *);
59032 + str1 = va_arg(ap, char *);
59033 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59034 + break;
59035 + case GR_FILENAME_TWO_INT:
59036 + dentry = va_arg(ap, struct dentry *);
59037 + mnt = va_arg(ap, struct vfsmount *);
59038 + num1 = va_arg(ap, int);
59039 + num2 = va_arg(ap, int);
59040 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59041 + break;
59042 + case GR_FILENAME_TWO_INT_STR:
59043 + dentry = va_arg(ap, struct dentry *);
59044 + mnt = va_arg(ap, struct vfsmount *);
59045 + num1 = va_arg(ap, int);
59046 + num2 = va_arg(ap, int);
59047 + str1 = va_arg(ap, char *);
59048 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59049 + break;
59050 + case GR_TEXTREL:
59051 + file = va_arg(ap, struct file *);
59052 + ulong1 = va_arg(ap, unsigned long);
59053 + ulong2 = va_arg(ap, unsigned long);
59054 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59055 + break;
59056 + case GR_PTRACE:
59057 + task = va_arg(ap, struct task_struct *);
59058 + 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);
59059 + break;
59060 + case GR_RESOURCE:
59061 + task = va_arg(ap, struct task_struct *);
59062 + cred = __task_cred(task);
59063 + pcred = __task_cred(task->real_parent);
59064 + ulong1 = va_arg(ap, unsigned long);
59065 + str1 = va_arg(ap, char *);
59066 + ulong2 = va_arg(ap, unsigned long);
59067 + 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);
59068 + break;
59069 + case GR_CAP:
59070 + task = va_arg(ap, struct task_struct *);
59071 + cred = __task_cred(task);
59072 + pcred = __task_cred(task->real_parent);
59073 + str1 = va_arg(ap, char *);
59074 + 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);
59075 + break;
59076 + case GR_SIG:
59077 + str1 = va_arg(ap, char *);
59078 + voidptr = va_arg(ap, void *);
59079 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59080 + break;
59081 + case GR_SIG2:
59082 + task = va_arg(ap, struct task_struct *);
59083 + cred = __task_cred(task);
59084 + pcred = __task_cred(task->real_parent);
59085 + num1 = va_arg(ap, int);
59086 + 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);
59087 + break;
59088 + case GR_CRASH1:
59089 + task = va_arg(ap, struct task_struct *);
59090 + cred = __task_cred(task);
59091 + pcred = __task_cred(task->real_parent);
59092 + ulong1 = va_arg(ap, unsigned long);
59093 + 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);
59094 + break;
59095 + case GR_CRASH2:
59096 + task = va_arg(ap, struct task_struct *);
59097 + cred = __task_cred(task);
59098 + pcred = __task_cred(task->real_parent);
59099 + ulong1 = va_arg(ap, unsigned long);
59100 + 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);
59101 + break;
59102 + case GR_RWXMAP:
59103 + file = va_arg(ap, struct file *);
59104 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59105 + break;
59106 + case GR_PSACCT:
59107 + {
59108 + unsigned int wday, cday;
59109 + __u8 whr, chr;
59110 + __u8 wmin, cmin;
59111 + __u8 wsec, csec;
59112 + char cur_tty[64] = { 0 };
59113 + char parent_tty[64] = { 0 };
59114 +
59115 + task = va_arg(ap, struct task_struct *);
59116 + wday = va_arg(ap, unsigned int);
59117 + cday = va_arg(ap, unsigned int);
59118 + whr = va_arg(ap, int);
59119 + chr = va_arg(ap, int);
59120 + wmin = va_arg(ap, int);
59121 + cmin = va_arg(ap, int);
59122 + wsec = va_arg(ap, int);
59123 + csec = va_arg(ap, int);
59124 + ulong1 = va_arg(ap, unsigned long);
59125 + cred = __task_cred(task);
59126 + pcred = __task_cred(task->real_parent);
59127 +
59128 + 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);
59129 + }
59130 + break;
59131 + default:
59132 + gr_log_middle(audit, msg, ap);
59133 + }
59134 + va_end(ap);
59135 + // these don't need DEFAULTSECARGS printed on the end
59136 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59137 + gr_log_end(audit, 0);
59138 + else
59139 + gr_log_end(audit, 1);
59140 + END_LOCKS(audit);
59141 +}
59142 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59143 new file mode 100644
59144 index 0000000..f536303
59145 --- /dev/null
59146 +++ b/grsecurity/grsec_mem.c
59147 @@ -0,0 +1,40 @@
59148 +#include <linux/kernel.h>
59149 +#include <linux/sched.h>
59150 +#include <linux/mm.h>
59151 +#include <linux/mman.h>
59152 +#include <linux/grinternal.h>
59153 +
59154 +void
59155 +gr_handle_ioperm(void)
59156 +{
59157 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59158 + return;
59159 +}
59160 +
59161 +void
59162 +gr_handle_iopl(void)
59163 +{
59164 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59165 + return;
59166 +}
59167 +
59168 +void
59169 +gr_handle_mem_readwrite(u64 from, u64 to)
59170 +{
59171 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59172 + return;
59173 +}
59174 +
59175 +void
59176 +gr_handle_vm86(void)
59177 +{
59178 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59179 + return;
59180 +}
59181 +
59182 +void
59183 +gr_log_badprocpid(const char *entry)
59184 +{
59185 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59186 + return;
59187 +}
59188 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59189 new file mode 100644
59190 index 0000000..2131422
59191 --- /dev/null
59192 +++ b/grsecurity/grsec_mount.c
59193 @@ -0,0 +1,62 @@
59194 +#include <linux/kernel.h>
59195 +#include <linux/sched.h>
59196 +#include <linux/mount.h>
59197 +#include <linux/grsecurity.h>
59198 +#include <linux/grinternal.h>
59199 +
59200 +void
59201 +gr_log_remount(const char *devname, const int retval)
59202 +{
59203 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59204 + if (grsec_enable_mount && (retval >= 0))
59205 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59206 +#endif
59207 + return;
59208 +}
59209 +
59210 +void
59211 +gr_log_unmount(const char *devname, const int retval)
59212 +{
59213 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59214 + if (grsec_enable_mount && (retval >= 0))
59215 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59216 +#endif
59217 + return;
59218 +}
59219 +
59220 +void
59221 +gr_log_mount(const char *from, const char *to, const int retval)
59222 +{
59223 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59224 + if (grsec_enable_mount && (retval >= 0))
59225 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59226 +#endif
59227 + return;
59228 +}
59229 +
59230 +int
59231 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59232 +{
59233 +#ifdef CONFIG_GRKERNSEC_ROFS
59234 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59235 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59236 + return -EPERM;
59237 + } else
59238 + return 0;
59239 +#endif
59240 + return 0;
59241 +}
59242 +
59243 +int
59244 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59245 +{
59246 +#ifdef CONFIG_GRKERNSEC_ROFS
59247 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59248 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59249 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59250 + return -EPERM;
59251 + } else
59252 + return 0;
59253 +#endif
59254 + return 0;
59255 +}
59256 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59257 new file mode 100644
59258 index 0000000..a3b12a0
59259 --- /dev/null
59260 +++ b/grsecurity/grsec_pax.c
59261 @@ -0,0 +1,36 @@
59262 +#include <linux/kernel.h>
59263 +#include <linux/sched.h>
59264 +#include <linux/mm.h>
59265 +#include <linux/file.h>
59266 +#include <linux/grinternal.h>
59267 +#include <linux/grsecurity.h>
59268 +
59269 +void
59270 +gr_log_textrel(struct vm_area_struct * vma)
59271 +{
59272 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59273 + if (grsec_enable_audit_textrel)
59274 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59275 +#endif
59276 + return;
59277 +}
59278 +
59279 +void
59280 +gr_log_rwxmmap(struct file *file)
59281 +{
59282 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59283 + if (grsec_enable_log_rwxmaps)
59284 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59285 +#endif
59286 + return;
59287 +}
59288 +
59289 +void
59290 +gr_log_rwxmprotect(struct file *file)
59291 +{
59292 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59293 + if (grsec_enable_log_rwxmaps)
59294 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59295 +#endif
59296 + return;
59297 +}
59298 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59299 new file mode 100644
59300 index 0000000..f7f29aa
59301 --- /dev/null
59302 +++ b/grsecurity/grsec_ptrace.c
59303 @@ -0,0 +1,30 @@
59304 +#include <linux/kernel.h>
59305 +#include <linux/sched.h>
59306 +#include <linux/grinternal.h>
59307 +#include <linux/security.h>
59308 +
59309 +void
59310 +gr_audit_ptrace(struct task_struct *task)
59311 +{
59312 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59313 + if (grsec_enable_audit_ptrace)
59314 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59315 +#endif
59316 + return;
59317 +}
59318 +
59319 +int
59320 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59321 +{
59322 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59323 + const struct dentry *dentry = file->f_path.dentry;
59324 + const struct vfsmount *mnt = file->f_path.mnt;
59325 +
59326 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59327 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59328 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59329 + return -EACCES;
59330 + }
59331 +#endif
59332 + return 0;
59333 +}
59334 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59335 new file mode 100644
59336 index 0000000..5c00416
59337 --- /dev/null
59338 +++ b/grsecurity/grsec_sig.c
59339 @@ -0,0 +1,222 @@
59340 +#include <linux/kernel.h>
59341 +#include <linux/sched.h>
59342 +#include <linux/delay.h>
59343 +#include <linux/grsecurity.h>
59344 +#include <linux/grinternal.h>
59345 +#include <linux/hardirq.h>
59346 +
59347 +char *signames[] = {
59348 + [SIGSEGV] = "Segmentation fault",
59349 + [SIGILL] = "Illegal instruction",
59350 + [SIGABRT] = "Abort",
59351 + [SIGBUS] = "Invalid alignment/Bus error"
59352 +};
59353 +
59354 +void
59355 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59356 +{
59357 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59358 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59359 + (sig == SIGABRT) || (sig == SIGBUS))) {
59360 + if (t->pid == current->pid) {
59361 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59362 + } else {
59363 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59364 + }
59365 + }
59366 +#endif
59367 + return;
59368 +}
59369 +
59370 +int
59371 +gr_handle_signal(const struct task_struct *p, const int sig)
59372 +{
59373 +#ifdef CONFIG_GRKERNSEC
59374 + /* ignore the 0 signal for protected task checks */
59375 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59376 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59377 + return -EPERM;
59378 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59379 + return -EPERM;
59380 + }
59381 +#endif
59382 + return 0;
59383 +}
59384 +
59385 +#ifdef CONFIG_GRKERNSEC
59386 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59387 +
59388 +int gr_fake_force_sig(int sig, struct task_struct *t)
59389 +{
59390 + unsigned long int flags;
59391 + int ret, blocked, ignored;
59392 + struct k_sigaction *action;
59393 +
59394 + spin_lock_irqsave(&t->sighand->siglock, flags);
59395 + action = &t->sighand->action[sig-1];
59396 + ignored = action->sa.sa_handler == SIG_IGN;
59397 + blocked = sigismember(&t->blocked, sig);
59398 + if (blocked || ignored) {
59399 + action->sa.sa_handler = SIG_DFL;
59400 + if (blocked) {
59401 + sigdelset(&t->blocked, sig);
59402 + recalc_sigpending_and_wake(t);
59403 + }
59404 + }
59405 + if (action->sa.sa_handler == SIG_DFL)
59406 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59407 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59408 +
59409 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59410 +
59411 + return ret;
59412 +}
59413 +#endif
59414 +
59415 +#ifdef CONFIG_GRKERNSEC_BRUTE
59416 +#define GR_USER_BAN_TIME (15 * 60)
59417 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
59418 +
59419 +static int __get_dumpable(unsigned long mm_flags)
59420 +{
59421 + int ret;
59422 +
59423 + ret = mm_flags & MMF_DUMPABLE_MASK;
59424 + return (ret >= 2) ? 2 : ret;
59425 +}
59426 +#endif
59427 +
59428 +void gr_handle_brute_attach(unsigned long mm_flags)
59429 +{
59430 +#ifdef CONFIG_GRKERNSEC_BRUTE
59431 + struct task_struct *p = current;
59432 + kuid_t uid = GLOBAL_ROOT_UID;
59433 + int daemon = 0;
59434 +
59435 + if (!grsec_enable_brute)
59436 + return;
59437 +
59438 + rcu_read_lock();
59439 + read_lock(&tasklist_lock);
59440 + read_lock(&grsec_exec_file_lock);
59441 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
59442 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
59443 + p->real_parent->brute = 1;
59444 + daemon = 1;
59445 + } else {
59446 + const struct cred *cred = __task_cred(p), *cred2;
59447 + struct task_struct *tsk, *tsk2;
59448 +
59449 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59450 + struct user_struct *user;
59451 +
59452 + uid = cred->uid;
59453 +
59454 + /* this is put upon execution past expiration */
59455 + user = find_user(uid);
59456 + if (user == NULL)
59457 + goto unlock;
59458 + user->banned = 1;
59459 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59460 + if (user->ban_expires == ~0UL)
59461 + user->ban_expires--;
59462 +
59463 + do_each_thread(tsk2, tsk) {
59464 + cred2 = __task_cred(tsk);
59465 + if (tsk != p && uid_eq(cred2->uid, uid))
59466 + gr_fake_force_sig(SIGKILL, tsk);
59467 + } while_each_thread(tsk2, tsk);
59468 + }
59469 + }
59470 +unlock:
59471 + read_unlock(&grsec_exec_file_lock);
59472 + read_unlock(&tasklist_lock);
59473 + rcu_read_unlock();
59474 +
59475 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59476 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59477 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59478 + else if (daemon)
59479 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
59480 +
59481 +#endif
59482 + return;
59483 +}
59484 +
59485 +void gr_handle_brute_check(void)
59486 +{
59487 +#ifdef CONFIG_GRKERNSEC_BRUTE
59488 + struct task_struct *p = current;
59489 +
59490 + if (unlikely(p->brute)) {
59491 + if (!grsec_enable_brute)
59492 + p->brute = 0;
59493 + else if (time_before(get_seconds(), p->brute_expires))
59494 + msleep(30 * 1000);
59495 + }
59496 +#endif
59497 + return;
59498 +}
59499 +
59500 +void gr_handle_kernel_exploit(void)
59501 +{
59502 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59503 + const struct cred *cred;
59504 + struct task_struct *tsk, *tsk2;
59505 + struct user_struct *user;
59506 + kuid_t uid;
59507 +
59508 + if (in_irq() || in_serving_softirq() || in_nmi())
59509 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59510 +
59511 + uid = current_uid();
59512 +
59513 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59514 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59515 + else {
59516 + /* kill all the processes of this user, hold a reference
59517 + to their creds struct, and prevent them from creating
59518 + another process until system reset
59519 + */
59520 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59521 + from_kuid_munged(&init_user_ns, uid));
59522 + /* we intentionally leak this ref */
59523 + user = get_uid(current->cred->user);
59524 + if (user) {
59525 + user->banned = 1;
59526 + user->ban_expires = ~0UL;
59527 + }
59528 +
59529 + read_lock(&tasklist_lock);
59530 + do_each_thread(tsk2, tsk) {
59531 + cred = __task_cred(tsk);
59532 + if (uid_eq(cred->uid, uid))
59533 + gr_fake_force_sig(SIGKILL, tsk);
59534 + } while_each_thread(tsk2, tsk);
59535 + read_unlock(&tasklist_lock);
59536 + }
59537 +#endif
59538 +}
59539 +
59540 +int __gr_process_user_ban(struct user_struct *user)
59541 +{
59542 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59543 + if (unlikely(user->banned)) {
59544 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59545 + user->banned = 0;
59546 + user->ban_expires = 0;
59547 + free_uid(user);
59548 + } else
59549 + return -EPERM;
59550 + }
59551 +#endif
59552 + return 0;
59553 +}
59554 +
59555 +int gr_process_user_ban(void)
59556 +{
59557 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59558 + return __gr_process_user_ban(current->cred->user);
59559 +#endif
59560 + return 0;
59561 +}
59562 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59563 new file mode 100644
59564 index 0000000..4030d57
59565 --- /dev/null
59566 +++ b/grsecurity/grsec_sock.c
59567 @@ -0,0 +1,244 @@
59568 +#include <linux/kernel.h>
59569 +#include <linux/module.h>
59570 +#include <linux/sched.h>
59571 +#include <linux/file.h>
59572 +#include <linux/net.h>
59573 +#include <linux/in.h>
59574 +#include <linux/ip.h>
59575 +#include <net/sock.h>
59576 +#include <net/inet_sock.h>
59577 +#include <linux/grsecurity.h>
59578 +#include <linux/grinternal.h>
59579 +#include <linux/gracl.h>
59580 +
59581 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59582 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59583 +
59584 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59585 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59586 +
59587 +#ifdef CONFIG_UNIX_MODULE
59588 +EXPORT_SYMBOL(gr_acl_handle_unix);
59589 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59590 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59591 +EXPORT_SYMBOL(gr_handle_create);
59592 +#endif
59593 +
59594 +#ifdef CONFIG_GRKERNSEC
59595 +#define gr_conn_table_size 32749
59596 +struct conn_table_entry {
59597 + struct conn_table_entry *next;
59598 + struct signal_struct *sig;
59599 +};
59600 +
59601 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59602 +DEFINE_SPINLOCK(gr_conn_table_lock);
59603 +
59604 +extern const char * gr_socktype_to_name(unsigned char type);
59605 +extern const char * gr_proto_to_name(unsigned char proto);
59606 +extern const char * gr_sockfamily_to_name(unsigned char family);
59607 +
59608 +static __inline__ int
59609 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59610 +{
59611 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59612 +}
59613 +
59614 +static __inline__ int
59615 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59616 + __u16 sport, __u16 dport)
59617 +{
59618 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59619 + sig->gr_sport == sport && sig->gr_dport == dport))
59620 + return 1;
59621 + else
59622 + return 0;
59623 +}
59624 +
59625 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59626 +{
59627 + struct conn_table_entry **match;
59628 + unsigned int index;
59629 +
59630 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59631 + sig->gr_sport, sig->gr_dport,
59632 + gr_conn_table_size);
59633 +
59634 + newent->sig = sig;
59635 +
59636 + match = &gr_conn_table[index];
59637 + newent->next = *match;
59638 + *match = newent;
59639 +
59640 + return;
59641 +}
59642 +
59643 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59644 +{
59645 + struct conn_table_entry *match, *last = NULL;
59646 + unsigned int index;
59647 +
59648 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59649 + sig->gr_sport, sig->gr_dport,
59650 + gr_conn_table_size);
59651 +
59652 + match = gr_conn_table[index];
59653 + while (match && !conn_match(match->sig,
59654 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59655 + sig->gr_dport)) {
59656 + last = match;
59657 + match = match->next;
59658 + }
59659 +
59660 + if (match) {
59661 + if (last)
59662 + last->next = match->next;
59663 + else
59664 + gr_conn_table[index] = NULL;
59665 + kfree(match);
59666 + }
59667 +
59668 + return;
59669 +}
59670 +
59671 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59672 + __u16 sport, __u16 dport)
59673 +{
59674 + struct conn_table_entry *match;
59675 + unsigned int index;
59676 +
59677 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59678 +
59679 + match = gr_conn_table[index];
59680 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59681 + match = match->next;
59682 +
59683 + if (match)
59684 + return match->sig;
59685 + else
59686 + return NULL;
59687 +}
59688 +
59689 +#endif
59690 +
59691 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59692 +{
59693 +#ifdef CONFIG_GRKERNSEC
59694 + struct signal_struct *sig = task->signal;
59695 + struct conn_table_entry *newent;
59696 +
59697 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59698 + if (newent == NULL)
59699 + return;
59700 + /* no bh lock needed since we are called with bh disabled */
59701 + spin_lock(&gr_conn_table_lock);
59702 + gr_del_task_from_ip_table_nolock(sig);
59703 + sig->gr_saddr = inet->inet_rcv_saddr;
59704 + sig->gr_daddr = inet->inet_daddr;
59705 + sig->gr_sport = inet->inet_sport;
59706 + sig->gr_dport = inet->inet_dport;
59707 + gr_add_to_task_ip_table_nolock(sig, newent);
59708 + spin_unlock(&gr_conn_table_lock);
59709 +#endif
59710 + return;
59711 +}
59712 +
59713 +void gr_del_task_from_ip_table(struct task_struct *task)
59714 +{
59715 +#ifdef CONFIG_GRKERNSEC
59716 + spin_lock_bh(&gr_conn_table_lock);
59717 + gr_del_task_from_ip_table_nolock(task->signal);
59718 + spin_unlock_bh(&gr_conn_table_lock);
59719 +#endif
59720 + return;
59721 +}
59722 +
59723 +void
59724 +gr_attach_curr_ip(const struct sock *sk)
59725 +{
59726 +#ifdef CONFIG_GRKERNSEC
59727 + struct signal_struct *p, *set;
59728 + const struct inet_sock *inet = inet_sk(sk);
59729 +
59730 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59731 + return;
59732 +
59733 + set = current->signal;
59734 +
59735 + spin_lock_bh(&gr_conn_table_lock);
59736 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59737 + inet->inet_dport, inet->inet_sport);
59738 + if (unlikely(p != NULL)) {
59739 + set->curr_ip = p->curr_ip;
59740 + set->used_accept = 1;
59741 + gr_del_task_from_ip_table_nolock(p);
59742 + spin_unlock_bh(&gr_conn_table_lock);
59743 + return;
59744 + }
59745 + spin_unlock_bh(&gr_conn_table_lock);
59746 +
59747 + set->curr_ip = inet->inet_daddr;
59748 + set->used_accept = 1;
59749 +#endif
59750 + return;
59751 +}
59752 +
59753 +int
59754 +gr_handle_sock_all(const int family, const int type, const int protocol)
59755 +{
59756 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59757 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59758 + (family != AF_UNIX)) {
59759 + if (family == AF_INET)
59760 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59761 + else
59762 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59763 + return -EACCES;
59764 + }
59765 +#endif
59766 + return 0;
59767 +}
59768 +
59769 +int
59770 +gr_handle_sock_server(const struct sockaddr *sck)
59771 +{
59772 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59773 + if (grsec_enable_socket_server &&
59774 + in_group_p(grsec_socket_server_gid) &&
59775 + sck && (sck->sa_family != AF_UNIX) &&
59776 + (sck->sa_family != AF_LOCAL)) {
59777 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59778 + return -EACCES;
59779 + }
59780 +#endif
59781 + return 0;
59782 +}
59783 +
59784 +int
59785 +gr_handle_sock_server_other(const struct sock *sck)
59786 +{
59787 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59788 + if (grsec_enable_socket_server &&
59789 + in_group_p(grsec_socket_server_gid) &&
59790 + sck && (sck->sk_family != AF_UNIX) &&
59791 + (sck->sk_family != AF_LOCAL)) {
59792 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59793 + return -EACCES;
59794 + }
59795 +#endif
59796 + return 0;
59797 +}
59798 +
59799 +int
59800 +gr_handle_sock_client(const struct sockaddr *sck)
59801 +{
59802 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59803 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59804 + sck && (sck->sa_family != AF_UNIX) &&
59805 + (sck->sa_family != AF_LOCAL)) {
59806 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59807 + return -EACCES;
59808 + }
59809 +#endif
59810 + return 0;
59811 +}
59812 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59813 new file mode 100644
59814 index 0000000..f55ef0f
59815 --- /dev/null
59816 +++ b/grsecurity/grsec_sysctl.c
59817 @@ -0,0 +1,469 @@
59818 +#include <linux/kernel.h>
59819 +#include <linux/sched.h>
59820 +#include <linux/sysctl.h>
59821 +#include <linux/grsecurity.h>
59822 +#include <linux/grinternal.h>
59823 +
59824 +int
59825 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59826 +{
59827 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59828 + if (dirname == NULL || name == NULL)
59829 + return 0;
59830 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59831 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59832 + return -EACCES;
59833 + }
59834 +#endif
59835 + return 0;
59836 +}
59837 +
59838 +#ifdef CONFIG_GRKERNSEC_ROFS
59839 +static int __maybe_unused one = 1;
59840 +#endif
59841 +
59842 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59843 +struct ctl_table grsecurity_table[] = {
59844 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59845 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59846 +#ifdef CONFIG_GRKERNSEC_IO
59847 + {
59848 + .procname = "disable_priv_io",
59849 + .data = &grsec_disable_privio,
59850 + .maxlen = sizeof(int),
59851 + .mode = 0600,
59852 + .proc_handler = &proc_dointvec,
59853 + },
59854 +#endif
59855 +#endif
59856 +#ifdef CONFIG_GRKERNSEC_LINK
59857 + {
59858 + .procname = "linking_restrictions",
59859 + .data = &grsec_enable_link,
59860 + .maxlen = sizeof(int),
59861 + .mode = 0600,
59862 + .proc_handler = &proc_dointvec,
59863 + },
59864 +#endif
59865 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59866 + {
59867 + .procname = "enforce_symlinksifowner",
59868 + .data = &grsec_enable_symlinkown,
59869 + .maxlen = sizeof(int),
59870 + .mode = 0600,
59871 + .proc_handler = &proc_dointvec,
59872 + },
59873 + {
59874 + .procname = "symlinkown_gid",
59875 + .data = &grsec_symlinkown_gid,
59876 + .maxlen = sizeof(int),
59877 + .mode = 0600,
59878 + .proc_handler = &proc_dointvec,
59879 + },
59880 +#endif
59881 +#ifdef CONFIG_GRKERNSEC_BRUTE
59882 + {
59883 + .procname = "deter_bruteforce",
59884 + .data = &grsec_enable_brute,
59885 + .maxlen = sizeof(int),
59886 + .mode = 0600,
59887 + .proc_handler = &proc_dointvec,
59888 + },
59889 +#endif
59890 +#ifdef CONFIG_GRKERNSEC_FIFO
59891 + {
59892 + .procname = "fifo_restrictions",
59893 + .data = &grsec_enable_fifo,
59894 + .maxlen = sizeof(int),
59895 + .mode = 0600,
59896 + .proc_handler = &proc_dointvec,
59897 + },
59898 +#endif
59899 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59900 + {
59901 + .procname = "ptrace_readexec",
59902 + .data = &grsec_enable_ptrace_readexec,
59903 + .maxlen = sizeof(int),
59904 + .mode = 0600,
59905 + .proc_handler = &proc_dointvec,
59906 + },
59907 +#endif
59908 +#ifdef CONFIG_GRKERNSEC_SETXID
59909 + {
59910 + .procname = "consistent_setxid",
59911 + .data = &grsec_enable_setxid,
59912 + .maxlen = sizeof(int),
59913 + .mode = 0600,
59914 + .proc_handler = &proc_dointvec,
59915 + },
59916 +#endif
59917 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59918 + {
59919 + .procname = "ip_blackhole",
59920 + .data = &grsec_enable_blackhole,
59921 + .maxlen = sizeof(int),
59922 + .mode = 0600,
59923 + .proc_handler = &proc_dointvec,
59924 + },
59925 + {
59926 + .procname = "lastack_retries",
59927 + .data = &grsec_lastack_retries,
59928 + .maxlen = sizeof(int),
59929 + .mode = 0600,
59930 + .proc_handler = &proc_dointvec,
59931 + },
59932 +#endif
59933 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59934 + {
59935 + .procname = "exec_logging",
59936 + .data = &grsec_enable_execlog,
59937 + .maxlen = sizeof(int),
59938 + .mode = 0600,
59939 + .proc_handler = &proc_dointvec,
59940 + },
59941 +#endif
59942 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59943 + {
59944 + .procname = "rwxmap_logging",
59945 + .data = &grsec_enable_log_rwxmaps,
59946 + .maxlen = sizeof(int),
59947 + .mode = 0600,
59948 + .proc_handler = &proc_dointvec,
59949 + },
59950 +#endif
59951 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59952 + {
59953 + .procname = "signal_logging",
59954 + .data = &grsec_enable_signal,
59955 + .maxlen = sizeof(int),
59956 + .mode = 0600,
59957 + .proc_handler = &proc_dointvec,
59958 + },
59959 +#endif
59960 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59961 + {
59962 + .procname = "forkfail_logging",
59963 + .data = &grsec_enable_forkfail,
59964 + .maxlen = sizeof(int),
59965 + .mode = 0600,
59966 + .proc_handler = &proc_dointvec,
59967 + },
59968 +#endif
59969 +#ifdef CONFIG_GRKERNSEC_TIME
59970 + {
59971 + .procname = "timechange_logging",
59972 + .data = &grsec_enable_time,
59973 + .maxlen = sizeof(int),
59974 + .mode = 0600,
59975 + .proc_handler = &proc_dointvec,
59976 + },
59977 +#endif
59978 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59979 + {
59980 + .procname = "chroot_deny_shmat",
59981 + .data = &grsec_enable_chroot_shmat,
59982 + .maxlen = sizeof(int),
59983 + .mode = 0600,
59984 + .proc_handler = &proc_dointvec,
59985 + },
59986 +#endif
59987 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59988 + {
59989 + .procname = "chroot_deny_unix",
59990 + .data = &grsec_enable_chroot_unix,
59991 + .maxlen = sizeof(int),
59992 + .mode = 0600,
59993 + .proc_handler = &proc_dointvec,
59994 + },
59995 +#endif
59996 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59997 + {
59998 + .procname = "chroot_deny_mount",
59999 + .data = &grsec_enable_chroot_mount,
60000 + .maxlen = sizeof(int),
60001 + .mode = 0600,
60002 + .proc_handler = &proc_dointvec,
60003 + },
60004 +#endif
60005 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60006 + {
60007 + .procname = "chroot_deny_fchdir",
60008 + .data = &grsec_enable_chroot_fchdir,
60009 + .maxlen = sizeof(int),
60010 + .mode = 0600,
60011 + .proc_handler = &proc_dointvec,
60012 + },
60013 +#endif
60014 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60015 + {
60016 + .procname = "chroot_deny_chroot",
60017 + .data = &grsec_enable_chroot_double,
60018 + .maxlen = sizeof(int),
60019 + .mode = 0600,
60020 + .proc_handler = &proc_dointvec,
60021 + },
60022 +#endif
60023 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60024 + {
60025 + .procname = "chroot_deny_pivot",
60026 + .data = &grsec_enable_chroot_pivot,
60027 + .maxlen = sizeof(int),
60028 + .mode = 0600,
60029 + .proc_handler = &proc_dointvec,
60030 + },
60031 +#endif
60032 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60033 + {
60034 + .procname = "chroot_enforce_chdir",
60035 + .data = &grsec_enable_chroot_chdir,
60036 + .maxlen = sizeof(int),
60037 + .mode = 0600,
60038 + .proc_handler = &proc_dointvec,
60039 + },
60040 +#endif
60041 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60042 + {
60043 + .procname = "chroot_deny_chmod",
60044 + .data = &grsec_enable_chroot_chmod,
60045 + .maxlen = sizeof(int),
60046 + .mode = 0600,
60047 + .proc_handler = &proc_dointvec,
60048 + },
60049 +#endif
60050 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60051 + {
60052 + .procname = "chroot_deny_mknod",
60053 + .data = &grsec_enable_chroot_mknod,
60054 + .maxlen = sizeof(int),
60055 + .mode = 0600,
60056 + .proc_handler = &proc_dointvec,
60057 + },
60058 +#endif
60059 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60060 + {
60061 + .procname = "chroot_restrict_nice",
60062 + .data = &grsec_enable_chroot_nice,
60063 + .maxlen = sizeof(int),
60064 + .mode = 0600,
60065 + .proc_handler = &proc_dointvec,
60066 + },
60067 +#endif
60068 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60069 + {
60070 + .procname = "chroot_execlog",
60071 + .data = &grsec_enable_chroot_execlog,
60072 + .maxlen = sizeof(int),
60073 + .mode = 0600,
60074 + .proc_handler = &proc_dointvec,
60075 + },
60076 +#endif
60077 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60078 + {
60079 + .procname = "chroot_caps",
60080 + .data = &grsec_enable_chroot_caps,
60081 + .maxlen = sizeof(int),
60082 + .mode = 0600,
60083 + .proc_handler = &proc_dointvec,
60084 + },
60085 +#endif
60086 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60087 + {
60088 + .procname = "chroot_deny_sysctl",
60089 + .data = &grsec_enable_chroot_sysctl,
60090 + .maxlen = sizeof(int),
60091 + .mode = 0600,
60092 + .proc_handler = &proc_dointvec,
60093 + },
60094 +#endif
60095 +#ifdef CONFIG_GRKERNSEC_TPE
60096 + {
60097 + .procname = "tpe",
60098 + .data = &grsec_enable_tpe,
60099 + .maxlen = sizeof(int),
60100 + .mode = 0600,
60101 + .proc_handler = &proc_dointvec,
60102 + },
60103 + {
60104 + .procname = "tpe_gid",
60105 + .data = &grsec_tpe_gid,
60106 + .maxlen = sizeof(int),
60107 + .mode = 0600,
60108 + .proc_handler = &proc_dointvec,
60109 + },
60110 +#endif
60111 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60112 + {
60113 + .procname = "tpe_invert",
60114 + .data = &grsec_enable_tpe_invert,
60115 + .maxlen = sizeof(int),
60116 + .mode = 0600,
60117 + .proc_handler = &proc_dointvec,
60118 + },
60119 +#endif
60120 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60121 + {
60122 + .procname = "tpe_restrict_all",
60123 + .data = &grsec_enable_tpe_all,
60124 + .maxlen = sizeof(int),
60125 + .mode = 0600,
60126 + .proc_handler = &proc_dointvec,
60127 + },
60128 +#endif
60129 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60130 + {
60131 + .procname = "socket_all",
60132 + .data = &grsec_enable_socket_all,
60133 + .maxlen = sizeof(int),
60134 + .mode = 0600,
60135 + .proc_handler = &proc_dointvec,
60136 + },
60137 + {
60138 + .procname = "socket_all_gid",
60139 + .data = &grsec_socket_all_gid,
60140 + .maxlen = sizeof(int),
60141 + .mode = 0600,
60142 + .proc_handler = &proc_dointvec,
60143 + },
60144 +#endif
60145 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60146 + {
60147 + .procname = "socket_client",
60148 + .data = &grsec_enable_socket_client,
60149 + .maxlen = sizeof(int),
60150 + .mode = 0600,
60151 + .proc_handler = &proc_dointvec,
60152 + },
60153 + {
60154 + .procname = "socket_client_gid",
60155 + .data = &grsec_socket_client_gid,
60156 + .maxlen = sizeof(int),
60157 + .mode = 0600,
60158 + .proc_handler = &proc_dointvec,
60159 + },
60160 +#endif
60161 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60162 + {
60163 + .procname = "socket_server",
60164 + .data = &grsec_enable_socket_server,
60165 + .maxlen = sizeof(int),
60166 + .mode = 0600,
60167 + .proc_handler = &proc_dointvec,
60168 + },
60169 + {
60170 + .procname = "socket_server_gid",
60171 + .data = &grsec_socket_server_gid,
60172 + .maxlen = sizeof(int),
60173 + .mode = 0600,
60174 + .proc_handler = &proc_dointvec,
60175 + },
60176 +#endif
60177 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60178 + {
60179 + .procname = "audit_group",
60180 + .data = &grsec_enable_group,
60181 + .maxlen = sizeof(int),
60182 + .mode = 0600,
60183 + .proc_handler = &proc_dointvec,
60184 + },
60185 + {
60186 + .procname = "audit_gid",
60187 + .data = &grsec_audit_gid,
60188 + .maxlen = sizeof(int),
60189 + .mode = 0600,
60190 + .proc_handler = &proc_dointvec,
60191 + },
60192 +#endif
60193 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60194 + {
60195 + .procname = "audit_chdir",
60196 + .data = &grsec_enable_chdir,
60197 + .maxlen = sizeof(int),
60198 + .mode = 0600,
60199 + .proc_handler = &proc_dointvec,
60200 + },
60201 +#endif
60202 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60203 + {
60204 + .procname = "audit_mount",
60205 + .data = &grsec_enable_mount,
60206 + .maxlen = sizeof(int),
60207 + .mode = 0600,
60208 + .proc_handler = &proc_dointvec,
60209 + },
60210 +#endif
60211 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60212 + {
60213 + .procname = "audit_textrel",
60214 + .data = &grsec_enable_audit_textrel,
60215 + .maxlen = sizeof(int),
60216 + .mode = 0600,
60217 + .proc_handler = &proc_dointvec,
60218 + },
60219 +#endif
60220 +#ifdef CONFIG_GRKERNSEC_DMESG
60221 + {
60222 + .procname = "dmesg",
60223 + .data = &grsec_enable_dmesg,
60224 + .maxlen = sizeof(int),
60225 + .mode = 0600,
60226 + .proc_handler = &proc_dointvec,
60227 + },
60228 +#endif
60229 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60230 + {
60231 + .procname = "chroot_findtask",
60232 + .data = &grsec_enable_chroot_findtask,
60233 + .maxlen = sizeof(int),
60234 + .mode = 0600,
60235 + .proc_handler = &proc_dointvec,
60236 + },
60237 +#endif
60238 +#ifdef CONFIG_GRKERNSEC_RESLOG
60239 + {
60240 + .procname = "resource_logging",
60241 + .data = &grsec_resource_logging,
60242 + .maxlen = sizeof(int),
60243 + .mode = 0600,
60244 + .proc_handler = &proc_dointvec,
60245 + },
60246 +#endif
60247 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60248 + {
60249 + .procname = "audit_ptrace",
60250 + .data = &grsec_enable_audit_ptrace,
60251 + .maxlen = sizeof(int),
60252 + .mode = 0600,
60253 + .proc_handler = &proc_dointvec,
60254 + },
60255 +#endif
60256 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60257 + {
60258 + .procname = "harden_ptrace",
60259 + .data = &grsec_enable_harden_ptrace,
60260 + .maxlen = sizeof(int),
60261 + .mode = 0600,
60262 + .proc_handler = &proc_dointvec,
60263 + },
60264 +#endif
60265 + {
60266 + .procname = "grsec_lock",
60267 + .data = &grsec_lock,
60268 + .maxlen = sizeof(int),
60269 + .mode = 0600,
60270 + .proc_handler = &proc_dointvec,
60271 + },
60272 +#endif
60273 +#ifdef CONFIG_GRKERNSEC_ROFS
60274 + {
60275 + .procname = "romount_protect",
60276 + .data = &grsec_enable_rofs,
60277 + .maxlen = sizeof(int),
60278 + .mode = 0600,
60279 + .proc_handler = &proc_dointvec_minmax,
60280 + .extra1 = &one,
60281 + .extra2 = &one,
60282 + },
60283 +#endif
60284 + { }
60285 +};
60286 +#endif
60287 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60288 new file mode 100644
60289 index 0000000..0dc13c3
60290 --- /dev/null
60291 +++ b/grsecurity/grsec_time.c
60292 @@ -0,0 +1,16 @@
60293 +#include <linux/kernel.h>
60294 +#include <linux/sched.h>
60295 +#include <linux/grinternal.h>
60296 +#include <linux/module.h>
60297 +
60298 +void
60299 +gr_log_timechange(void)
60300 +{
60301 +#ifdef CONFIG_GRKERNSEC_TIME
60302 + if (grsec_enable_time)
60303 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60304 +#endif
60305 + return;
60306 +}
60307 +
60308 +EXPORT_SYMBOL(gr_log_timechange);
60309 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60310 new file mode 100644
60311 index 0000000..07e0dc0
60312 --- /dev/null
60313 +++ b/grsecurity/grsec_tpe.c
60314 @@ -0,0 +1,73 @@
60315 +#include <linux/kernel.h>
60316 +#include <linux/sched.h>
60317 +#include <linux/file.h>
60318 +#include <linux/fs.h>
60319 +#include <linux/grinternal.h>
60320 +
60321 +extern int gr_acl_tpe_check(void);
60322 +
60323 +int
60324 +gr_tpe_allow(const struct file *file)
60325 +{
60326 +#ifdef CONFIG_GRKERNSEC
60327 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60328 + const struct cred *cred = current_cred();
60329 + char *msg = NULL;
60330 + char *msg2 = NULL;
60331 +
60332 + // never restrict root
60333 + if (!cred->uid)
60334 + return 1;
60335 +
60336 + if (grsec_enable_tpe) {
60337 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60338 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60339 + msg = "not being in trusted group";
60340 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60341 + msg = "being in untrusted group";
60342 +#else
60343 + if (in_group_p(grsec_tpe_gid))
60344 + msg = "being in untrusted group";
60345 +#endif
60346 + }
60347 + if (!msg && gr_acl_tpe_check())
60348 + msg = "being in untrusted role";
60349 +
60350 + // not in any affected group/role
60351 + if (!msg)
60352 + goto next_check;
60353 +
60354 + if (inode->i_uid)
60355 + msg2 = "file in non-root-owned directory";
60356 + else if (inode->i_mode & S_IWOTH)
60357 + msg2 = "file in world-writable directory";
60358 + else if (inode->i_mode & S_IWGRP)
60359 + msg2 = "file in group-writable directory";
60360 +
60361 + if (msg && msg2) {
60362 + char fullmsg[70] = {0};
60363 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60364 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60365 + return 0;
60366 + }
60367 + msg = NULL;
60368 +next_check:
60369 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60370 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60371 + return 1;
60372 +
60373 + if (inode->i_uid && (inode->i_uid != cred->uid))
60374 + msg = "directory not owned by user";
60375 + else if (inode->i_mode & S_IWOTH)
60376 + msg = "file in world-writable directory";
60377 + else if (inode->i_mode & S_IWGRP)
60378 + msg = "file in group-writable directory";
60379 +
60380 + if (msg) {
60381 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60382 + return 0;
60383 + }
60384 +#endif
60385 +#endif
60386 + return 1;
60387 +}
60388 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60389 new file mode 100644
60390 index 0000000..9f7b1ac
60391 --- /dev/null
60392 +++ b/grsecurity/grsum.c
60393 @@ -0,0 +1,61 @@
60394 +#include <linux/err.h>
60395 +#include <linux/kernel.h>
60396 +#include <linux/sched.h>
60397 +#include <linux/mm.h>
60398 +#include <linux/scatterlist.h>
60399 +#include <linux/crypto.h>
60400 +#include <linux/gracl.h>
60401 +
60402 +
60403 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60404 +#error "crypto and sha256 must be built into the kernel"
60405 +#endif
60406 +
60407 +int
60408 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60409 +{
60410 + char *p;
60411 + struct crypto_hash *tfm;
60412 + struct hash_desc desc;
60413 + struct scatterlist sg;
60414 + unsigned char temp_sum[GR_SHA_LEN];
60415 + volatile int retval = 0;
60416 + volatile int dummy = 0;
60417 + unsigned int i;
60418 +
60419 + sg_init_table(&sg, 1);
60420 +
60421 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60422 + if (IS_ERR(tfm)) {
60423 + /* should never happen, since sha256 should be built in */
60424 + return 1;
60425 + }
60426 +
60427 + desc.tfm = tfm;
60428 + desc.flags = 0;
60429 +
60430 + crypto_hash_init(&desc);
60431 +
60432 + p = salt;
60433 + sg_set_buf(&sg, p, GR_SALT_LEN);
60434 + crypto_hash_update(&desc, &sg, sg.length);
60435 +
60436 + p = entry->pw;
60437 + sg_set_buf(&sg, p, strlen(p));
60438 +
60439 + crypto_hash_update(&desc, &sg, sg.length);
60440 +
60441 + crypto_hash_final(&desc, temp_sum);
60442 +
60443 + memset(entry->pw, 0, GR_PW_LEN);
60444 +
60445 + for (i = 0; i < GR_SHA_LEN; i++)
60446 + if (sum[i] != temp_sum[i])
60447 + retval = 1;
60448 + else
60449 + dummy = 1; // waste a cycle
60450 +
60451 + crypto_free_hash(tfm);
60452 +
60453 + return retval;
60454 +}
60455 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60456 index 0daa0fb..f548aa4 100644
60457 --- a/include/acpi/acpi_bus.h
60458 +++ b/include/acpi/acpi_bus.h
60459 @@ -107,7 +107,7 @@ struct acpi_device_ops {
60460 acpi_op_bind bind;
60461 acpi_op_unbind unbind;
60462 acpi_op_notify notify;
60463 -};
60464 +} __no_const;
60465
60466 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60467
60468 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60469 index 77ff547..181834f 100644
60470 --- a/include/asm-generic/4level-fixup.h
60471 +++ b/include/asm-generic/4level-fixup.h
60472 @@ -13,8 +13,10 @@
60473 #define pmd_alloc(mm, pud, address) \
60474 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60475 NULL: pmd_offset(pud, address))
60476 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60477
60478 #define pud_alloc(mm, pgd, address) (pgd)
60479 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60480 #define pud_offset(pgd, start) (pgd)
60481 #define pud_none(pud) 0
60482 #define pud_bad(pud) 0
60483 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60484 index b7babf0..04ad282 100644
60485 --- a/include/asm-generic/atomic-long.h
60486 +++ b/include/asm-generic/atomic-long.h
60487 @@ -22,6 +22,12 @@
60488
60489 typedef atomic64_t atomic_long_t;
60490
60491 +#ifdef CONFIG_PAX_REFCOUNT
60492 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60493 +#else
60494 +typedef atomic64_t atomic_long_unchecked_t;
60495 +#endif
60496 +
60497 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60498
60499 static inline long atomic_long_read(atomic_long_t *l)
60500 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60501 return (long)atomic64_read(v);
60502 }
60503
60504 +#ifdef CONFIG_PAX_REFCOUNT
60505 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60506 +{
60507 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60508 +
60509 + return (long)atomic64_read_unchecked(v);
60510 +}
60511 +#endif
60512 +
60513 static inline void atomic_long_set(atomic_long_t *l, long i)
60514 {
60515 atomic64_t *v = (atomic64_t *)l;
60516 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60517 atomic64_set(v, i);
60518 }
60519
60520 +#ifdef CONFIG_PAX_REFCOUNT
60521 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60522 +{
60523 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60524 +
60525 + atomic64_set_unchecked(v, i);
60526 +}
60527 +#endif
60528 +
60529 static inline void atomic_long_inc(atomic_long_t *l)
60530 {
60531 atomic64_t *v = (atomic64_t *)l;
60532 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60533 atomic64_inc(v);
60534 }
60535
60536 +#ifdef CONFIG_PAX_REFCOUNT
60537 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60538 +{
60539 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60540 +
60541 + atomic64_inc_unchecked(v);
60542 +}
60543 +#endif
60544 +
60545 static inline void atomic_long_dec(atomic_long_t *l)
60546 {
60547 atomic64_t *v = (atomic64_t *)l;
60548 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60549 atomic64_dec(v);
60550 }
60551
60552 +#ifdef CONFIG_PAX_REFCOUNT
60553 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60554 +{
60555 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60556 +
60557 + atomic64_dec_unchecked(v);
60558 +}
60559 +#endif
60560 +
60561 static inline void atomic_long_add(long i, atomic_long_t *l)
60562 {
60563 atomic64_t *v = (atomic64_t *)l;
60564 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60565 atomic64_add(i, v);
60566 }
60567
60568 +#ifdef CONFIG_PAX_REFCOUNT
60569 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60570 +{
60571 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60572 +
60573 + atomic64_add_unchecked(i, v);
60574 +}
60575 +#endif
60576 +
60577 static inline void atomic_long_sub(long i, atomic_long_t *l)
60578 {
60579 atomic64_t *v = (atomic64_t *)l;
60580 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60581 atomic64_sub(i, v);
60582 }
60583
60584 +#ifdef CONFIG_PAX_REFCOUNT
60585 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60586 +{
60587 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60588 +
60589 + atomic64_sub_unchecked(i, v);
60590 +}
60591 +#endif
60592 +
60593 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60594 {
60595 atomic64_t *v = (atomic64_t *)l;
60596 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
60597 return (long)atomic64_add_return(i, v);
60598 }
60599
60600 +#ifdef CONFIG_PAX_REFCOUNT
60601 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
60602 +{
60603 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60604 +
60605 + return (long)atomic64_add_return_unchecked(i, v);
60606 +}
60607 +#endif
60608 +
60609 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
60610 {
60611 atomic64_t *v = (atomic64_t *)l;
60612 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60613 return (long)atomic64_inc_return(v);
60614 }
60615
60616 +#ifdef CONFIG_PAX_REFCOUNT
60617 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60618 +{
60619 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60620 +
60621 + return (long)atomic64_inc_return_unchecked(v);
60622 +}
60623 +#endif
60624 +
60625 static inline long atomic_long_dec_return(atomic_long_t *l)
60626 {
60627 atomic64_t *v = (atomic64_t *)l;
60628 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60629
60630 typedef atomic_t atomic_long_t;
60631
60632 +#ifdef CONFIG_PAX_REFCOUNT
60633 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60634 +#else
60635 +typedef atomic_t atomic_long_unchecked_t;
60636 +#endif
60637 +
60638 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60639 static inline long atomic_long_read(atomic_long_t *l)
60640 {
60641 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60642 return (long)atomic_read(v);
60643 }
60644
60645 +#ifdef CONFIG_PAX_REFCOUNT
60646 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60647 +{
60648 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60649 +
60650 + return (long)atomic_read_unchecked(v);
60651 +}
60652 +#endif
60653 +
60654 static inline void atomic_long_set(atomic_long_t *l, long i)
60655 {
60656 atomic_t *v = (atomic_t *)l;
60657 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60658 atomic_set(v, i);
60659 }
60660
60661 +#ifdef CONFIG_PAX_REFCOUNT
60662 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60663 +{
60664 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60665 +
60666 + atomic_set_unchecked(v, i);
60667 +}
60668 +#endif
60669 +
60670 static inline void atomic_long_inc(atomic_long_t *l)
60671 {
60672 atomic_t *v = (atomic_t *)l;
60673 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60674 atomic_inc(v);
60675 }
60676
60677 +#ifdef CONFIG_PAX_REFCOUNT
60678 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60679 +{
60680 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60681 +
60682 + atomic_inc_unchecked(v);
60683 +}
60684 +#endif
60685 +
60686 static inline void atomic_long_dec(atomic_long_t *l)
60687 {
60688 atomic_t *v = (atomic_t *)l;
60689 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60690 atomic_dec(v);
60691 }
60692
60693 +#ifdef CONFIG_PAX_REFCOUNT
60694 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60695 +{
60696 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60697 +
60698 + atomic_dec_unchecked(v);
60699 +}
60700 +#endif
60701 +
60702 static inline void atomic_long_add(long i, atomic_long_t *l)
60703 {
60704 atomic_t *v = (atomic_t *)l;
60705 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60706 atomic_add(i, v);
60707 }
60708
60709 +#ifdef CONFIG_PAX_REFCOUNT
60710 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60711 +{
60712 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60713 +
60714 + atomic_add_unchecked(i, v);
60715 +}
60716 +#endif
60717 +
60718 static inline void atomic_long_sub(long i, atomic_long_t *l)
60719 {
60720 atomic_t *v = (atomic_t *)l;
60721 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60722 atomic_sub(i, v);
60723 }
60724
60725 +#ifdef CONFIG_PAX_REFCOUNT
60726 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60727 +{
60728 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60729 +
60730 + atomic_sub_unchecked(i, v);
60731 +}
60732 +#endif
60733 +
60734 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60735 {
60736 atomic_t *v = (atomic_t *)l;
60737 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
60738 return (long)atomic_add_return(i, v);
60739 }
60740
60741 +#ifdef CONFIG_PAX_REFCOUNT
60742 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
60743 +{
60744 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60745 +
60746 + return (long)atomic_add_return_unchecked(i, v);
60747 +}
60748 +
60749 +#endif
60750 +
60751 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
60752 {
60753 atomic_t *v = (atomic_t *)l;
60754 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60755 return (long)atomic_inc_return(v);
60756 }
60757
60758 +#ifdef CONFIG_PAX_REFCOUNT
60759 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60760 +{
60761 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60762 +
60763 + return (long)atomic_inc_return_unchecked(v);
60764 +}
60765 +#endif
60766 +
60767 static inline long atomic_long_dec_return(atomic_long_t *l)
60768 {
60769 atomic_t *v = (atomic_t *)l;
60770 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60771
60772 #endif /* BITS_PER_LONG == 64 */
60773
60774 +#ifdef CONFIG_PAX_REFCOUNT
60775 +static inline void pax_refcount_needs_these_functions(void)
60776 +{
60777 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60778 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60779 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60780 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60781 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60782 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60783 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60784 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60785 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60786 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60787 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60788 +#ifdef CONFIG_X86
60789 + atomic_clear_mask_unchecked(0, NULL);
60790 + atomic_set_mask_unchecked(0, NULL);
60791 +#endif
60792 +
60793 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60794 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60795 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60796 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60797 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60798 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
60799 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60800 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60801 +}
60802 +#else
60803 +#define atomic_read_unchecked(v) atomic_read(v)
60804 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60805 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60806 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60807 +#define atomic_inc_unchecked(v) atomic_inc(v)
60808 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60809 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60810 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60811 +#define atomic_dec_unchecked(v) atomic_dec(v)
60812 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60813 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60814 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60815 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60816 +
60817 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60818 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60819 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60820 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60821 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60822 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
60823 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60824 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60825 +#endif
60826 +
60827 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60828 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60829 index 1ced641..c896ee8 100644
60830 --- a/include/asm-generic/atomic.h
60831 +++ b/include/asm-generic/atomic.h
60832 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60833 * Atomically clears the bits set in @mask from @v
60834 */
60835 #ifndef atomic_clear_mask
60836 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60837 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60838 {
60839 unsigned long flags;
60840
60841 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60842 index b18ce4f..2ee2843 100644
60843 --- a/include/asm-generic/atomic64.h
60844 +++ b/include/asm-generic/atomic64.h
60845 @@ -16,6 +16,8 @@ typedef struct {
60846 long long counter;
60847 } atomic64_t;
60848
60849 +typedef atomic64_t atomic64_unchecked_t;
60850 +
60851 #define ATOMIC64_INIT(i) { (i) }
60852
60853 extern long long atomic64_read(const atomic64_t *v);
60854 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60855 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60856 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60857
60858 +#define atomic64_read_unchecked(v) atomic64_read(v)
60859 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60860 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60861 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60862 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60863 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60864 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60865 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60866 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60867 +
60868 #endif /* _ASM_GENERIC_ATOMIC64_H */
60869 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60870 index 1bfcfe5..e04c5c9 100644
60871 --- a/include/asm-generic/cache.h
60872 +++ b/include/asm-generic/cache.h
60873 @@ -6,7 +6,7 @@
60874 * cache lines need to provide their own cache.h.
60875 */
60876
60877 -#define L1_CACHE_SHIFT 5
60878 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60879 +#define L1_CACHE_SHIFT 5UL
60880 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60881
60882 #endif /* __ASM_GENERIC_CACHE_H */
60883 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60884 index 0d68a1e..b74a761 100644
60885 --- a/include/asm-generic/emergency-restart.h
60886 +++ b/include/asm-generic/emergency-restart.h
60887 @@ -1,7 +1,7 @@
60888 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60889 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60890
60891 -static inline void machine_emergency_restart(void)
60892 +static inline __noreturn void machine_emergency_restart(void)
60893 {
60894 machine_restart(NULL);
60895 }
60896 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60897 index 90f99c7..00ce236 100644
60898 --- a/include/asm-generic/kmap_types.h
60899 +++ b/include/asm-generic/kmap_types.h
60900 @@ -2,9 +2,9 @@
60901 #define _ASM_GENERIC_KMAP_TYPES_H
60902
60903 #ifdef __WITH_KM_FENCE
60904 -# define KM_TYPE_NR 41
60905 +# define KM_TYPE_NR 42
60906 #else
60907 -# define KM_TYPE_NR 20
60908 +# define KM_TYPE_NR 21
60909 #endif
60910
60911 #endif
60912 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60913 index 9ceb03b..62b0b8f 100644
60914 --- a/include/asm-generic/local.h
60915 +++ b/include/asm-generic/local.h
60916 @@ -23,24 +23,37 @@ typedef struct
60917 atomic_long_t a;
60918 } local_t;
60919
60920 +typedef struct {
60921 + atomic_long_unchecked_t a;
60922 +} local_unchecked_t;
60923 +
60924 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
60925
60926 #define local_read(l) atomic_long_read(&(l)->a)
60927 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
60928 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
60929 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
60930 #define local_inc(l) atomic_long_inc(&(l)->a)
60931 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
60932 #define local_dec(l) atomic_long_dec(&(l)->a)
60933 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
60934 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
60935 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
60936 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
60937 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
60938
60939 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
60940 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
60941 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
60942 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
60943 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60944 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
60945 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60946 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60947 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60948
60949 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60950 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60951 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60952 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
60953 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
60954 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60955 index 725612b..9cc513a 100644
60956 --- a/include/asm-generic/pgtable-nopmd.h
60957 +++ b/include/asm-generic/pgtable-nopmd.h
60958 @@ -1,14 +1,19 @@
60959 #ifndef _PGTABLE_NOPMD_H
60960 #define _PGTABLE_NOPMD_H
60961
60962 -#ifndef __ASSEMBLY__
60963 -
60964 #include <asm-generic/pgtable-nopud.h>
60965
60966 -struct mm_struct;
60967 -
60968 #define __PAGETABLE_PMD_FOLDED
60969
60970 +#define PMD_SHIFT PUD_SHIFT
60971 +#define PTRS_PER_PMD 1
60972 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60973 +#define PMD_MASK (~(PMD_SIZE-1))
60974 +
60975 +#ifndef __ASSEMBLY__
60976 +
60977 +struct mm_struct;
60978 +
60979 /*
60980 * Having the pmd type consist of a pud gets the size right, and allows
60981 * us to conceptually access the pud entry that this pmd is folded into
60982 @@ -16,11 +21,6 @@ struct mm_struct;
60983 */
60984 typedef struct { pud_t pud; } pmd_t;
60985
60986 -#define PMD_SHIFT PUD_SHIFT
60987 -#define PTRS_PER_PMD 1
60988 -#define PMD_SIZE (1UL << PMD_SHIFT)
60989 -#define PMD_MASK (~(PMD_SIZE-1))
60990 -
60991 /*
60992 * The "pud_xxx()" functions here are trivial for a folded two-level
60993 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60994 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60995 index 810431d..0ec4804f 100644
60996 --- a/include/asm-generic/pgtable-nopud.h
60997 +++ b/include/asm-generic/pgtable-nopud.h
60998 @@ -1,10 +1,15 @@
60999 #ifndef _PGTABLE_NOPUD_H
61000 #define _PGTABLE_NOPUD_H
61001
61002 -#ifndef __ASSEMBLY__
61003 -
61004 #define __PAGETABLE_PUD_FOLDED
61005
61006 +#define PUD_SHIFT PGDIR_SHIFT
61007 +#define PTRS_PER_PUD 1
61008 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61009 +#define PUD_MASK (~(PUD_SIZE-1))
61010 +
61011 +#ifndef __ASSEMBLY__
61012 +
61013 /*
61014 * Having the pud type consist of a pgd gets the size right, and allows
61015 * us to conceptually access the pgd entry that this pud is folded into
61016 @@ -12,11 +17,6 @@
61017 */
61018 typedef struct { pgd_t pgd; } pud_t;
61019
61020 -#define PUD_SHIFT PGDIR_SHIFT
61021 -#define PTRS_PER_PUD 1
61022 -#define PUD_SIZE (1UL << PUD_SHIFT)
61023 -#define PUD_MASK (~(PUD_SIZE-1))
61024 -
61025 /*
61026 * The "pgd_xxx()" functions here are trivial for a folded two-level
61027 * setup: the pud is never bad, and a pud always exists (as it's folded
61028 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61029 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61030
61031 #define pgd_populate(mm, pgd, pud) do { } while (0)
61032 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61033 /*
61034 * (puds are folded into pgds so this doesn't get actually called,
61035 * but the define is needed for a generic inline function.)
61036 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61037 index b36ce40..019426d 100644
61038 --- a/include/asm-generic/pgtable.h
61039 +++ b/include/asm-generic/pgtable.h
61040 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61041 #endif
61042 }
61043
61044 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61045 +static inline unsigned long pax_open_kernel(void) { return 0; }
61046 +#endif
61047 +
61048 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61049 +static inline unsigned long pax_close_kernel(void) { return 0; }
61050 +#endif
61051 +
61052 #endif /* CONFIG_MMU */
61053
61054 #endif /* !__ASSEMBLY__ */
61055 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61056 index d1ea7ce..b1ebf2a 100644
61057 --- a/include/asm-generic/vmlinux.lds.h
61058 +++ b/include/asm-generic/vmlinux.lds.h
61059 @@ -218,6 +218,7 @@
61060 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61061 VMLINUX_SYMBOL(__start_rodata) = .; \
61062 *(.rodata) *(.rodata.*) \
61063 + *(.data..read_only) \
61064 *(__vermagic) /* Kernel version magic */ \
61065 . = ALIGN(8); \
61066 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61067 @@ -725,17 +726,18 @@
61068 * section in the linker script will go there too. @phdr should have
61069 * a leading colon.
61070 *
61071 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61072 + * Note that this macros defines per_cpu_load as an absolute symbol.
61073 * If there is no need to put the percpu section at a predetermined
61074 * address, use PERCPU_SECTION.
61075 */
61076 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61077 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61078 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61079 + per_cpu_load = .; \
61080 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61081 - LOAD_OFFSET) { \
61082 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61083 PERCPU_INPUT(cacheline) \
61084 } phdr \
61085 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61086 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61087
61088 /**
61089 * PERCPU_SECTION - define output section for percpu area, simple version
61090 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61091 index 3fd8280..2b3c415 100644
61092 --- a/include/drm/drmP.h
61093 +++ b/include/drm/drmP.h
61094 @@ -72,6 +72,7 @@
61095 #include <linux/workqueue.h>
61096 #include <linux/poll.h>
61097 #include <asm/pgalloc.h>
61098 +#include <asm/local.h>
61099 #include <drm/drm.h>
61100 #include <drm/drm_sarea.h>
61101
61102 @@ -1068,7 +1069,7 @@ struct drm_device {
61103
61104 /** \name Usage Counters */
61105 /*@{ */
61106 - int open_count; /**< Outstanding files open */
61107 + local_t open_count; /**< Outstanding files open */
61108 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61109 atomic_t vma_count; /**< Outstanding vma areas open */
61110 int buf_use; /**< Buffers in use -- cannot alloc */
61111 @@ -1079,7 +1080,7 @@ struct drm_device {
61112 /*@{ */
61113 unsigned long counters;
61114 enum drm_stat_type types[15];
61115 - atomic_t counts[15];
61116 + atomic_unchecked_t counts[15];
61117 /*@} */
61118
61119 struct list_head filelist;
61120 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61121 index e01cc80..319855d 100644
61122 --- a/include/drm/drm_crtc_helper.h
61123 +++ b/include/drm/drm_crtc_helper.h
61124 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61125
61126 /* disable crtc when not in use - more explicit than dpms off */
61127 void (*disable)(struct drm_crtc *crtc);
61128 -};
61129 +} __no_const;
61130
61131 /**
61132 * drm_encoder_helper_funcs - helper operations for encoders
61133 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61134 struct drm_connector *connector);
61135 /* disable encoder when not in use - more explicit than dpms off */
61136 void (*disable)(struct drm_encoder *encoder);
61137 -};
61138 +} __no_const;
61139
61140 /**
61141 * drm_connector_helper_funcs - helper operations for connectors
61142 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61143 index d6d1da4..fdd1ac5 100644
61144 --- a/include/drm/ttm/ttm_memory.h
61145 +++ b/include/drm/ttm/ttm_memory.h
61146 @@ -48,7 +48,7 @@
61147
61148 struct ttm_mem_shrink {
61149 int (*do_shrink) (struct ttm_mem_shrink *);
61150 -};
61151 +} __no_const;
61152
61153 /**
61154 * struct ttm_mem_global - Global memory accounting structure.
61155 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61156 index 22ef21c..75904ba 100644
61157 --- a/include/linux/atmdev.h
61158 +++ b/include/linux/atmdev.h
61159 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
61160 #endif
61161
61162 struct k_atm_aal_stats {
61163 -#define __HANDLE_ITEM(i) atomic_t i
61164 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61165 __AAL_STAT_ITEMS
61166 #undef __HANDLE_ITEM
61167 };
61168 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61169 index cfcc6bf..9a7c73e 100644
61170 --- a/include/linux/binfmts.h
61171 +++ b/include/linux/binfmts.h
61172 @@ -75,6 +75,7 @@ struct linux_binfmt {
61173 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61174 int (*load_shlib)(struct file *);
61175 int (*core_dump)(struct coredump_params *cprm);
61176 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61177 unsigned long min_coredump; /* minimal dump size */
61178 };
61179
61180 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61181 index 1756001..ab117ec 100644
61182 --- a/include/linux/blkdev.h
61183 +++ b/include/linux/blkdev.h
61184 @@ -1478,7 +1478,7 @@ struct block_device_operations {
61185 /* this callback is with swap_lock and sometimes page table lock held */
61186 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61187 struct module *owner;
61188 -};
61189 +} __do_const;
61190
61191 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61192 unsigned long);
61193 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61194 index 7c2e030..b72475d 100644
61195 --- a/include/linux/blktrace_api.h
61196 +++ b/include/linux/blktrace_api.h
61197 @@ -23,7 +23,7 @@ struct blk_trace {
61198 struct dentry *dir;
61199 struct dentry *dropped_file;
61200 struct dentry *msg_file;
61201 - atomic_t dropped;
61202 + atomic_unchecked_t dropped;
61203 };
61204
61205 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61206 diff --git a/include/linux/cache.h b/include/linux/cache.h
61207 index 4c57065..4307975 100644
61208 --- a/include/linux/cache.h
61209 +++ b/include/linux/cache.h
61210 @@ -16,6 +16,10 @@
61211 #define __read_mostly
61212 #endif
61213
61214 +#ifndef __read_only
61215 +#define __read_only __read_mostly
61216 +#endif
61217 +
61218 #ifndef ____cacheline_aligned
61219 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61220 #endif
61221 diff --git a/include/linux/capability.h b/include/linux/capability.h
61222 index 98503b7..cc36d18 100644
61223 --- a/include/linux/capability.h
61224 +++ b/include/linux/capability.h
61225 @@ -211,8 +211,13 @@ extern bool capable(int cap);
61226 extern bool ns_capable(struct user_namespace *ns, int cap);
61227 extern bool nsown_capable(int cap);
61228 extern bool inode_capable(const struct inode *inode, int cap);
61229 +extern bool capable_nolog(int cap);
61230 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61231 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61232
61233 /* audit system wants to get cap info from files as well */
61234 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61235
61236 +extern int is_privileged_binary(const struct dentry *dentry);
61237 +
61238 #endif /* !_LINUX_CAPABILITY_H */
61239 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61240 index 42e55de..1cd0e66 100644
61241 --- a/include/linux/cleancache.h
61242 +++ b/include/linux/cleancache.h
61243 @@ -31,7 +31,7 @@ struct cleancache_ops {
61244 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61245 void (*invalidate_inode)(int, struct cleancache_filekey);
61246 void (*invalidate_fs)(int);
61247 -};
61248 +} __no_const;
61249
61250 extern struct cleancache_ops
61251 cleancache_register_ops(struct cleancache_ops *ops);
61252 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61253 index f9f5e9e..9fb4d36 100644
61254 --- a/include/linux/clk-provider.h
61255 +++ b/include/linux/clk-provider.h
61256 @@ -112,6 +112,7 @@ struct clk_ops {
61257 unsigned long);
61258 void (*init)(struct clk_hw *hw);
61259 };
61260 +typedef struct clk_ops __no_const clk_ops_no_const;
61261
61262 /**
61263 * struct clk_init_data - holds init data that's common to all clocks and is
61264 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61265 index 412bc6c..c31666e 100644
61266 --- a/include/linux/compiler-gcc4.h
61267 +++ b/include/linux/compiler-gcc4.h
61268 @@ -32,6 +32,21 @@
61269 #define __linktime_error(message) __attribute__((__error__(message)))
61270
61271 #if __GNUC_MINOR__ >= 5
61272 +
61273 +#ifdef CONSTIFY_PLUGIN
61274 +#define __no_const __attribute__((no_const))
61275 +#define __do_const __attribute__((do_const))
61276 +#endif
61277 +
61278 +#ifdef SIZE_OVERFLOW_PLUGIN
61279 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61280 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61281 +#endif
61282 +
61283 +#ifdef LATENT_ENTROPY_PLUGIN
61284 +#define __latent_entropy __attribute__((latent_entropy))
61285 +#endif
61286 +
61287 /*
61288 * Mark a position in code as unreachable. This can be used to
61289 * suppress control flow warnings after asm blocks that transfer
61290 @@ -47,6 +62,11 @@
61291 #define __noclone __attribute__((__noclone__))
61292
61293 #endif
61294 +
61295 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61296 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61297 +#define __bos0(ptr) __bos((ptr), 0)
61298 +#define __bos1(ptr) __bos((ptr), 1)
61299 #endif
61300
61301 #if __GNUC_MINOR__ >= 6
61302 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61303 index f430e41..38be90f 100644
61304 --- a/include/linux/compiler.h
61305 +++ b/include/linux/compiler.h
61306 @@ -5,31 +5,62 @@
61307
61308 #ifdef __CHECKER__
61309 # define __user __attribute__((noderef, address_space(1)))
61310 +# define __force_user __force __user
61311 # define __kernel __attribute__((address_space(0)))
61312 +# define __force_kernel __force __kernel
61313 # define __safe __attribute__((safe))
61314 # define __force __attribute__((force))
61315 # define __nocast __attribute__((nocast))
61316 # define __iomem __attribute__((noderef, address_space(2)))
61317 +# define __force_iomem __force __iomem
61318 # define __acquires(x) __attribute__((context(x,0,1)))
61319 # define __releases(x) __attribute__((context(x,1,0)))
61320 # define __acquire(x) __context__(x,1)
61321 # define __release(x) __context__(x,-1)
61322 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61323 # define __percpu __attribute__((noderef, address_space(3)))
61324 +# define __force_percpu __force __percpu
61325 #ifdef CONFIG_SPARSE_RCU_POINTER
61326 # define __rcu __attribute__((noderef, address_space(4)))
61327 +# define __force_rcu __force __rcu
61328 #else
61329 # define __rcu
61330 +# define __force_rcu
61331 #endif
61332 extern void __chk_user_ptr(const volatile void __user *);
61333 extern void __chk_io_ptr(const volatile void __iomem *);
61334 +#elif defined(CHECKER_PLUGIN)
61335 +//# define __user
61336 +//# define __force_user
61337 +//# define __kernel
61338 +//# define __force_kernel
61339 +# define __safe
61340 +# define __force
61341 +# define __nocast
61342 +# define __iomem
61343 +# define __force_iomem
61344 +# define __chk_user_ptr(x) (void)0
61345 +# define __chk_io_ptr(x) (void)0
61346 +# define __builtin_warning(x, y...) (1)
61347 +# define __acquires(x)
61348 +# define __releases(x)
61349 +# define __acquire(x) (void)0
61350 +# define __release(x) (void)0
61351 +# define __cond_lock(x,c) (c)
61352 +# define __percpu
61353 +# define __force_percpu
61354 +# define __rcu
61355 +# define __force_rcu
61356 #else
61357 # define __user
61358 +# define __force_user
61359 # define __kernel
61360 +# define __force_kernel
61361 # define __safe
61362 # define __force
61363 # define __nocast
61364 # define __iomem
61365 +# define __force_iomem
61366 # define __chk_user_ptr(x) (void)0
61367 # define __chk_io_ptr(x) (void)0
61368 # define __builtin_warning(x, y...) (1)
61369 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61370 # define __release(x) (void)0
61371 # define __cond_lock(x,c) (c)
61372 # define __percpu
61373 +# define __force_percpu
61374 # define __rcu
61375 +# define __force_rcu
61376 #endif
61377
61378 #ifdef __KERNEL__
61379 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61380 # define __attribute_const__ /* unimplemented */
61381 #endif
61382
61383 +#ifndef __no_const
61384 +# define __no_const
61385 +#endif
61386 +
61387 +#ifndef __do_const
61388 +# define __do_const
61389 +#endif
61390 +
61391 +#ifndef __size_overflow
61392 +# define __size_overflow(...)
61393 +#endif
61394 +
61395 +#ifndef __intentional_overflow
61396 +# define __intentional_overflow(...)
61397 +#endif
61398 +
61399 +#ifndef __latent_entropy
61400 +# define __latent_entropy
61401 +#endif
61402 +
61403 /*
61404 * Tell gcc if a function is cold. The compiler will assume any path
61405 * directly leading to the call is unlikely.
61406 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61407 #define __cold
61408 #endif
61409
61410 +#ifndef __alloc_size
61411 +#define __alloc_size(...)
61412 +#endif
61413 +
61414 +#ifndef __bos
61415 +#define __bos(ptr, arg)
61416 +#endif
61417 +
61418 +#ifndef __bos0
61419 +#define __bos0(ptr)
61420 +#endif
61421 +
61422 +#ifndef __bos1
61423 +#define __bos1(ptr)
61424 +#endif
61425 +
61426 /* Simple shorthand for a section definition */
61427 #ifndef __section
61428 # define __section(S) __attribute__ ((__section__(#S)))
61429 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61430 * use is to mediate communication between process-level code and irq/NMI
61431 * handlers, all running on the same CPU.
61432 */
61433 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61434 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61435 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61436
61437 #endif /* __LINUX_COMPILER_H */
61438 diff --git a/include/linux/cred.h b/include/linux/cred.h
61439 index ebbed2c..908cc2c 100644
61440 --- a/include/linux/cred.h
61441 +++ b/include/linux/cred.h
61442 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61443 static inline void validate_process_creds(void)
61444 {
61445 }
61446 +static inline void validate_task_creds(struct task_struct *task)
61447 +{
61448 +}
61449 #endif
61450
61451 /**
61452 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61453 index b92eadf..b4ecdc1 100644
61454 --- a/include/linux/crypto.h
61455 +++ b/include/linux/crypto.h
61456 @@ -373,7 +373,7 @@ struct cipher_tfm {
61457 const u8 *key, unsigned int keylen);
61458 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61459 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61460 -};
61461 +} __no_const;
61462
61463 struct hash_tfm {
61464 int (*init)(struct hash_desc *desc);
61465 @@ -394,13 +394,13 @@ struct compress_tfm {
61466 int (*cot_decompress)(struct crypto_tfm *tfm,
61467 const u8 *src, unsigned int slen,
61468 u8 *dst, unsigned int *dlen);
61469 -};
61470 +} __no_const;
61471
61472 struct rng_tfm {
61473 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61474 unsigned int dlen);
61475 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61476 -};
61477 +} __no_const;
61478
61479 #define crt_ablkcipher crt_u.ablkcipher
61480 #define crt_aead crt_u.aead
61481 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61482 index 7925bf0..d5143d2 100644
61483 --- a/include/linux/decompress/mm.h
61484 +++ b/include/linux/decompress/mm.h
61485 @@ -77,7 +77,7 @@ static void free(void *where)
61486 * warnings when not needed (indeed large_malloc / large_free are not
61487 * needed by inflate */
61488
61489 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61490 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61491 #define free(a) kfree(a)
61492
61493 #define large_malloc(a) vmalloc(a)
61494 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61495 index 94af418..b1ca7a2 100644
61496 --- a/include/linux/dma-mapping.h
61497 +++ b/include/linux/dma-mapping.h
61498 @@ -54,7 +54,7 @@ struct dma_map_ops {
61499 u64 (*get_required_mask)(struct device *dev);
61500 #endif
61501 int is_phys;
61502 -};
61503 +} __do_const;
61504
61505 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61506
61507 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61508 index d3201e4..8281e63 100644
61509 --- a/include/linux/dmaengine.h
61510 +++ b/include/linux/dmaengine.h
61511 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
61512 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61513 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61514
61515 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61516 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61517 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61518 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61519 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61520 struct dma_pinned_list *pinned_list, struct page *page,
61521 unsigned int offset, size_t len);
61522
61523 diff --git a/include/linux/efi.h b/include/linux/efi.h
61524 index 8670eb1..7eb3ade 100644
61525 --- a/include/linux/efi.h
61526 +++ b/include/linux/efi.h
61527 @@ -643,7 +643,7 @@ struct efivar_operations {
61528 efi_get_variable_t *get_variable;
61529 efi_get_next_variable_t *get_next_variable;
61530 efi_set_variable_t *set_variable;
61531 -};
61532 +} __no_const;
61533
61534 struct efivars {
61535 /*
61536 diff --git a/include/linux/elf.h b/include/linux/elf.h
61537 index 8c9048e..16a4665 100644
61538 --- a/include/linux/elf.h
61539 +++ b/include/linux/elf.h
61540 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
61541 #define elf_note elf32_note
61542 #define elf_addr_t Elf32_Off
61543 #define Elf_Half Elf32_Half
61544 +#define elf_dyn Elf32_Dyn
61545
61546 #else
61547
61548 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
61549 #define elf_note elf64_note
61550 #define elf_addr_t Elf64_Off
61551 #define Elf_Half Elf64_Half
61552 +#define elf_dyn Elf64_Dyn
61553
61554 #endif
61555
61556 diff --git a/include/linux/filter.h b/include/linux/filter.h
61557 index 24d251f..7afb83d 100644
61558 --- a/include/linux/filter.h
61559 +++ b/include/linux/filter.h
61560 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
61561
61562 struct sk_buff;
61563 struct sock;
61564 +struct bpf_jit_work;
61565
61566 struct sk_filter
61567 {
61568 @@ -27,6 +28,9 @@ struct sk_filter
61569 unsigned int len; /* Number of filter blocks */
61570 unsigned int (*bpf_func)(const struct sk_buff *skb,
61571 const struct sock_filter *filter);
61572 +#ifdef CONFIG_BPF_JIT
61573 + struct bpf_jit_work *work;
61574 +#endif
61575 struct rcu_head rcu;
61576 struct sock_filter insns[0];
61577 };
61578 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61579 index 191501a..3952e37 100644
61580 --- a/include/linux/firewire.h
61581 +++ b/include/linux/firewire.h
61582 @@ -438,7 +438,7 @@ struct fw_iso_context {
61583 union {
61584 fw_iso_callback_t sc;
61585 fw_iso_mc_callback_t mc;
61586 - } callback;
61587 + } __no_const callback;
61588 void *callback_data;
61589 };
61590
61591 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61592 index 3044254..9767f41 100644
61593 --- a/include/linux/frontswap.h
61594 +++ b/include/linux/frontswap.h
61595 @@ -11,7 +11,7 @@ struct frontswap_ops {
61596 int (*load)(unsigned, pgoff_t, struct page *);
61597 void (*invalidate_page)(unsigned, pgoff_t);
61598 void (*invalidate_area)(unsigned);
61599 -};
61600 +} __no_const;
61601
61602 extern bool frontswap_enabled;
61603 extern struct frontswap_ops
61604 diff --git a/include/linux/fs.h b/include/linux/fs.h
61605 index 75fe9a1..72a4a6b 100644
61606 --- a/include/linux/fs.h
61607 +++ b/include/linux/fs.h
61608 @@ -1543,7 +1543,8 @@ struct file_operations {
61609 int (*setlease)(struct file *, long, struct file_lock **);
61610 long (*fallocate)(struct file *file, int mode, loff_t offset,
61611 loff_t len);
61612 -};
61613 +} __do_const;
61614 +typedef struct file_operations __no_const file_operations_no_const;
61615
61616 struct inode_operations {
61617 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61618 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61619 index 003dc0f..3c4ea97 100644
61620 --- a/include/linux/fs_struct.h
61621 +++ b/include/linux/fs_struct.h
61622 @@ -6,7 +6,7 @@
61623 #include <linux/seqlock.h>
61624
61625 struct fs_struct {
61626 - int users;
61627 + atomic_t users;
61628 spinlock_t lock;
61629 seqcount_t seq;
61630 int umask;
61631 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61632 index ce31408..b1ad003 100644
61633 --- a/include/linux/fscache-cache.h
61634 +++ b/include/linux/fscache-cache.h
61635 @@ -102,7 +102,7 @@ struct fscache_operation {
61636 fscache_operation_release_t release;
61637 };
61638
61639 -extern atomic_t fscache_op_debug_id;
61640 +extern atomic_unchecked_t fscache_op_debug_id;
61641 extern void fscache_op_work_func(struct work_struct *work);
61642
61643 extern void fscache_enqueue_operation(struct fscache_operation *);
61644 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61645 {
61646 INIT_WORK(&op->work, fscache_op_work_func);
61647 atomic_set(&op->usage, 1);
61648 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61649 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61650 op->processor = processor;
61651 op->release = release;
61652 INIT_LIST_HEAD(&op->pend_link);
61653 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61654 index 0fbfb46..52a6556 100644
61655 --- a/include/linux/fsnotify.h
61656 +++ b/include/linux/fsnotify.h
61657 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61658 */
61659 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61660 {
61661 - return kstrdup(name, GFP_KERNEL);
61662 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61663 }
61664
61665 /*
61666 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61667 index 63d966d..cdcb717 100644
61668 --- a/include/linux/fsnotify_backend.h
61669 +++ b/include/linux/fsnotify_backend.h
61670 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61671 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61672 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61673 };
61674 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61675
61676 /*
61677 * A group is a "thing" that wants to receive notification about filesystem
61678 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61679 index 642928c..e6c83a7 100644
61680 --- a/include/linux/ftrace_event.h
61681 +++ b/include/linux/ftrace_event.h
61682 @@ -97,7 +97,7 @@ struct trace_event_functions {
61683 trace_print_func raw;
61684 trace_print_func hex;
61685 trace_print_func binary;
61686 -};
61687 +} __no_const;
61688
61689 struct trace_event {
61690 struct hlist_node node;
61691 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61692 extern int trace_add_event_call(struct ftrace_event_call *call);
61693 extern void trace_remove_event_call(struct ftrace_event_call *call);
61694
61695 -#define is_signed_type(type) (((type)(-1)) < 0)
61696 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61697
61698 int trace_set_clr_event(const char *system, const char *event, int set);
61699
61700 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61701 index 4f440b3..342233a 100644
61702 --- a/include/linux/genhd.h
61703 +++ b/include/linux/genhd.h
61704 @@ -190,7 +190,7 @@ struct gendisk {
61705 struct kobject *slave_dir;
61706
61707 struct timer_rand_state *random;
61708 - atomic_t sync_io; /* RAID */
61709 + atomic_unchecked_t sync_io; /* RAID */
61710 struct disk_events *ev;
61711 #ifdef CONFIG_BLK_DEV_INTEGRITY
61712 struct blk_integrity *integrity;
61713 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61714 index d0a7967..63c4c47 100644
61715 --- a/include/linux/gfp.h
61716 +++ b/include/linux/gfp.h
61717 @@ -35,6 +35,12 @@ struct vm_area_struct;
61718 #define ___GFP_OTHER_NODE 0x800000u
61719 #define ___GFP_WRITE 0x1000000u
61720
61721 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61722 +#define ___GFP_USERCOPY 0x2000000u
61723 +#else
61724 +#define ___GFP_USERCOPY 0
61725 +#endif
61726 +
61727 /*
61728 * GFP bitmasks..
61729 *
61730 @@ -89,6 +95,7 @@ struct vm_area_struct;
61731 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61732 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61733 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61734 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61735
61736 /*
61737 * This may seem redundant, but it's a way of annotating false positives vs.
61738 @@ -96,7 +103,7 @@ struct vm_area_struct;
61739 */
61740 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61741
61742 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61743 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61744 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61745
61746 /* This equals 0, but use constants in case they ever change */
61747 @@ -150,6 +157,8 @@ struct vm_area_struct;
61748 /* 4GB DMA on some platforms */
61749 #define GFP_DMA32 __GFP_DMA32
61750
61751 +#define GFP_USERCOPY __GFP_USERCOPY
61752 +
61753 /* Convert GFP flags to their corresponding migrate type */
61754 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61755 {
61756 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61757 new file mode 100644
61758 index 0000000..ebe6d72
61759 --- /dev/null
61760 +++ b/include/linux/gracl.h
61761 @@ -0,0 +1,319 @@
61762 +#ifndef GR_ACL_H
61763 +#define GR_ACL_H
61764 +
61765 +#include <linux/grdefs.h>
61766 +#include <linux/resource.h>
61767 +#include <linux/capability.h>
61768 +#include <linux/dcache.h>
61769 +#include <asm/resource.h>
61770 +
61771 +/* Major status information */
61772 +
61773 +#define GR_VERSION "grsecurity 2.9.1"
61774 +#define GRSECURITY_VERSION 0x2901
61775 +
61776 +enum {
61777 + GR_SHUTDOWN = 0,
61778 + GR_ENABLE = 1,
61779 + GR_SPROLE = 2,
61780 + GR_RELOAD = 3,
61781 + GR_SEGVMOD = 4,
61782 + GR_STATUS = 5,
61783 + GR_UNSPROLE = 6,
61784 + GR_PASSSET = 7,
61785 + GR_SPROLEPAM = 8,
61786 +};
61787 +
61788 +/* Password setup definitions
61789 + * kernel/grhash.c */
61790 +enum {
61791 + GR_PW_LEN = 128,
61792 + GR_SALT_LEN = 16,
61793 + GR_SHA_LEN = 32,
61794 +};
61795 +
61796 +enum {
61797 + GR_SPROLE_LEN = 64,
61798 +};
61799 +
61800 +enum {
61801 + GR_NO_GLOB = 0,
61802 + GR_REG_GLOB,
61803 + GR_CREATE_GLOB
61804 +};
61805 +
61806 +#define GR_NLIMITS 32
61807 +
61808 +/* Begin Data Structures */
61809 +
61810 +struct sprole_pw {
61811 + unsigned char *rolename;
61812 + unsigned char salt[GR_SALT_LEN];
61813 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61814 +};
61815 +
61816 +struct name_entry {
61817 + __u32 key;
61818 + ino_t inode;
61819 + dev_t device;
61820 + char *name;
61821 + __u16 len;
61822 + __u8 deleted;
61823 + struct name_entry *prev;
61824 + struct name_entry *next;
61825 +};
61826 +
61827 +struct inodev_entry {
61828 + struct name_entry *nentry;
61829 + struct inodev_entry *prev;
61830 + struct inodev_entry *next;
61831 +};
61832 +
61833 +struct acl_role_db {
61834 + struct acl_role_label **r_hash;
61835 + __u32 r_size;
61836 +};
61837 +
61838 +struct inodev_db {
61839 + struct inodev_entry **i_hash;
61840 + __u32 i_size;
61841 +};
61842 +
61843 +struct name_db {
61844 + struct name_entry **n_hash;
61845 + __u32 n_size;
61846 +};
61847 +
61848 +struct crash_uid {
61849 + uid_t uid;
61850 + unsigned long expires;
61851 +};
61852 +
61853 +struct gr_hash_struct {
61854 + void **table;
61855 + void **nametable;
61856 + void *first;
61857 + __u32 table_size;
61858 + __u32 used_size;
61859 + int type;
61860 +};
61861 +
61862 +/* Userspace Grsecurity ACL data structures */
61863 +
61864 +struct acl_subject_label {
61865 + char *filename;
61866 + ino_t inode;
61867 + dev_t device;
61868 + __u32 mode;
61869 + kernel_cap_t cap_mask;
61870 + kernel_cap_t cap_lower;
61871 + kernel_cap_t cap_invert_audit;
61872 +
61873 + struct rlimit res[GR_NLIMITS];
61874 + __u32 resmask;
61875 +
61876 + __u8 user_trans_type;
61877 + __u8 group_trans_type;
61878 + uid_t *user_transitions;
61879 + gid_t *group_transitions;
61880 + __u16 user_trans_num;
61881 + __u16 group_trans_num;
61882 +
61883 + __u32 sock_families[2];
61884 + __u32 ip_proto[8];
61885 + __u32 ip_type;
61886 + struct acl_ip_label **ips;
61887 + __u32 ip_num;
61888 + __u32 inaddr_any_override;
61889 +
61890 + __u32 crashes;
61891 + unsigned long expires;
61892 +
61893 + struct acl_subject_label *parent_subject;
61894 + struct gr_hash_struct *hash;
61895 + struct acl_subject_label *prev;
61896 + struct acl_subject_label *next;
61897 +
61898 + struct acl_object_label **obj_hash;
61899 + __u32 obj_hash_size;
61900 + __u16 pax_flags;
61901 +};
61902 +
61903 +struct role_allowed_ip {
61904 + __u32 addr;
61905 + __u32 netmask;
61906 +
61907 + struct role_allowed_ip *prev;
61908 + struct role_allowed_ip *next;
61909 +};
61910 +
61911 +struct role_transition {
61912 + char *rolename;
61913 +
61914 + struct role_transition *prev;
61915 + struct role_transition *next;
61916 +};
61917 +
61918 +struct acl_role_label {
61919 + char *rolename;
61920 + uid_t uidgid;
61921 + __u16 roletype;
61922 +
61923 + __u16 auth_attempts;
61924 + unsigned long expires;
61925 +
61926 + struct acl_subject_label *root_label;
61927 + struct gr_hash_struct *hash;
61928 +
61929 + struct acl_role_label *prev;
61930 + struct acl_role_label *next;
61931 +
61932 + struct role_transition *transitions;
61933 + struct role_allowed_ip *allowed_ips;
61934 + uid_t *domain_children;
61935 + __u16 domain_child_num;
61936 +
61937 + umode_t umask;
61938 +
61939 + struct acl_subject_label **subj_hash;
61940 + __u32 subj_hash_size;
61941 +};
61942 +
61943 +struct user_acl_role_db {
61944 + struct acl_role_label **r_table;
61945 + __u32 num_pointers; /* Number of allocations to track */
61946 + __u32 num_roles; /* Number of roles */
61947 + __u32 num_domain_children; /* Number of domain children */
61948 + __u32 num_subjects; /* Number of subjects */
61949 + __u32 num_objects; /* Number of objects */
61950 +};
61951 +
61952 +struct acl_object_label {
61953 + char *filename;
61954 + ino_t inode;
61955 + dev_t device;
61956 + __u32 mode;
61957 +
61958 + struct acl_subject_label *nested;
61959 + struct acl_object_label *globbed;
61960 +
61961 + /* next two structures not used */
61962 +
61963 + struct acl_object_label *prev;
61964 + struct acl_object_label *next;
61965 +};
61966 +
61967 +struct acl_ip_label {
61968 + char *iface;
61969 + __u32 addr;
61970 + __u32 netmask;
61971 + __u16 low, high;
61972 + __u8 mode;
61973 + __u32 type;
61974 + __u32 proto[8];
61975 +
61976 + /* next two structures not used */
61977 +
61978 + struct acl_ip_label *prev;
61979 + struct acl_ip_label *next;
61980 +};
61981 +
61982 +struct gr_arg {
61983 + struct user_acl_role_db role_db;
61984 + unsigned char pw[GR_PW_LEN];
61985 + unsigned char salt[GR_SALT_LEN];
61986 + unsigned char sum[GR_SHA_LEN];
61987 + unsigned char sp_role[GR_SPROLE_LEN];
61988 + struct sprole_pw *sprole_pws;
61989 + dev_t segv_device;
61990 + ino_t segv_inode;
61991 + uid_t segv_uid;
61992 + __u16 num_sprole_pws;
61993 + __u16 mode;
61994 +};
61995 +
61996 +struct gr_arg_wrapper {
61997 + struct gr_arg *arg;
61998 + __u32 version;
61999 + __u32 size;
62000 +};
62001 +
62002 +struct subject_map {
62003 + struct acl_subject_label *user;
62004 + struct acl_subject_label *kernel;
62005 + struct subject_map *prev;
62006 + struct subject_map *next;
62007 +};
62008 +
62009 +struct acl_subj_map_db {
62010 + struct subject_map **s_hash;
62011 + __u32 s_size;
62012 +};
62013 +
62014 +/* End Data Structures Section */
62015 +
62016 +/* Hash functions generated by empirical testing by Brad Spengler
62017 + Makes good use of the low bits of the inode. Generally 0-1 times
62018 + in loop for successful match. 0-3 for unsuccessful match.
62019 + Shift/add algorithm with modulus of table size and an XOR*/
62020 +
62021 +static __inline__ unsigned int
62022 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62023 +{
62024 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62025 +}
62026 +
62027 + static __inline__ unsigned int
62028 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
62029 +{
62030 + return ((const unsigned long)userp % sz);
62031 +}
62032 +
62033 +static __inline__ unsigned int
62034 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62035 +{
62036 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62037 +}
62038 +
62039 +static __inline__ unsigned int
62040 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
62041 +{
62042 + return full_name_hash((const unsigned char *)name, len) % sz;
62043 +}
62044 +
62045 +#define FOR_EACH_ROLE_START(role) \
62046 + role = role_list; \
62047 + while (role) {
62048 +
62049 +#define FOR_EACH_ROLE_END(role) \
62050 + role = role->prev; \
62051 + }
62052 +
62053 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62054 + subj = NULL; \
62055 + iter = 0; \
62056 + while (iter < role->subj_hash_size) { \
62057 + if (subj == NULL) \
62058 + subj = role->subj_hash[iter]; \
62059 + if (subj == NULL) { \
62060 + iter++; \
62061 + continue; \
62062 + }
62063 +
62064 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62065 + subj = subj->next; \
62066 + if (subj == NULL) \
62067 + iter++; \
62068 + }
62069 +
62070 +
62071 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62072 + subj = role->hash->first; \
62073 + while (subj != NULL) {
62074 +
62075 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62076 + subj = subj->next; \
62077 + }
62078 +
62079 +#endif
62080 +
62081 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62082 new file mode 100644
62083 index 0000000..323ecf2
62084 --- /dev/null
62085 +++ b/include/linux/gralloc.h
62086 @@ -0,0 +1,9 @@
62087 +#ifndef __GRALLOC_H
62088 +#define __GRALLOC_H
62089 +
62090 +void acl_free_all(void);
62091 +int acl_alloc_stack_init(unsigned long size);
62092 +void *acl_alloc(unsigned long len);
62093 +void *acl_alloc_num(unsigned long num, unsigned long len);
62094 +
62095 +#endif
62096 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62097 new file mode 100644
62098 index 0000000..b30e9bc
62099 --- /dev/null
62100 +++ b/include/linux/grdefs.h
62101 @@ -0,0 +1,140 @@
62102 +#ifndef GRDEFS_H
62103 +#define GRDEFS_H
62104 +
62105 +/* Begin grsecurity status declarations */
62106 +
62107 +enum {
62108 + GR_READY = 0x01,
62109 + GR_STATUS_INIT = 0x00 // disabled state
62110 +};
62111 +
62112 +/* Begin ACL declarations */
62113 +
62114 +/* Role flags */
62115 +
62116 +enum {
62117 + GR_ROLE_USER = 0x0001,
62118 + GR_ROLE_GROUP = 0x0002,
62119 + GR_ROLE_DEFAULT = 0x0004,
62120 + GR_ROLE_SPECIAL = 0x0008,
62121 + GR_ROLE_AUTH = 0x0010,
62122 + GR_ROLE_NOPW = 0x0020,
62123 + GR_ROLE_GOD = 0x0040,
62124 + GR_ROLE_LEARN = 0x0080,
62125 + GR_ROLE_TPE = 0x0100,
62126 + GR_ROLE_DOMAIN = 0x0200,
62127 + GR_ROLE_PAM = 0x0400,
62128 + GR_ROLE_PERSIST = 0x0800
62129 +};
62130 +
62131 +/* ACL Subject and Object mode flags */
62132 +enum {
62133 + GR_DELETED = 0x80000000
62134 +};
62135 +
62136 +/* ACL Object-only mode flags */
62137 +enum {
62138 + GR_READ = 0x00000001,
62139 + GR_APPEND = 0x00000002,
62140 + GR_WRITE = 0x00000004,
62141 + GR_EXEC = 0x00000008,
62142 + GR_FIND = 0x00000010,
62143 + GR_INHERIT = 0x00000020,
62144 + GR_SETID = 0x00000040,
62145 + GR_CREATE = 0x00000080,
62146 + GR_DELETE = 0x00000100,
62147 + GR_LINK = 0x00000200,
62148 + GR_AUDIT_READ = 0x00000400,
62149 + GR_AUDIT_APPEND = 0x00000800,
62150 + GR_AUDIT_WRITE = 0x00001000,
62151 + GR_AUDIT_EXEC = 0x00002000,
62152 + GR_AUDIT_FIND = 0x00004000,
62153 + GR_AUDIT_INHERIT= 0x00008000,
62154 + GR_AUDIT_SETID = 0x00010000,
62155 + GR_AUDIT_CREATE = 0x00020000,
62156 + GR_AUDIT_DELETE = 0x00040000,
62157 + GR_AUDIT_LINK = 0x00080000,
62158 + GR_PTRACERD = 0x00100000,
62159 + GR_NOPTRACE = 0x00200000,
62160 + GR_SUPPRESS = 0x00400000,
62161 + GR_NOLEARN = 0x00800000,
62162 + GR_INIT_TRANSFER= 0x01000000
62163 +};
62164 +
62165 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62166 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62167 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62168 +
62169 +/* ACL subject-only mode flags */
62170 +enum {
62171 + GR_KILL = 0x00000001,
62172 + GR_VIEW = 0x00000002,
62173 + GR_PROTECTED = 0x00000004,
62174 + GR_LEARN = 0x00000008,
62175 + GR_OVERRIDE = 0x00000010,
62176 + /* just a placeholder, this mode is only used in userspace */
62177 + GR_DUMMY = 0x00000020,
62178 + GR_PROTSHM = 0x00000040,
62179 + GR_KILLPROC = 0x00000080,
62180 + GR_KILLIPPROC = 0x00000100,
62181 + /* just a placeholder, this mode is only used in userspace */
62182 + GR_NOTROJAN = 0x00000200,
62183 + GR_PROTPROCFD = 0x00000400,
62184 + GR_PROCACCT = 0x00000800,
62185 + GR_RELAXPTRACE = 0x00001000,
62186 + GR_NESTED = 0x00002000,
62187 + GR_INHERITLEARN = 0x00004000,
62188 + GR_PROCFIND = 0x00008000,
62189 + GR_POVERRIDE = 0x00010000,
62190 + GR_KERNELAUTH = 0x00020000,
62191 + GR_ATSECURE = 0x00040000,
62192 + GR_SHMEXEC = 0x00080000
62193 +};
62194 +
62195 +enum {
62196 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62197 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62198 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62199 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62200 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62201 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62202 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62203 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62204 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62205 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62206 +};
62207 +
62208 +enum {
62209 + GR_ID_USER = 0x01,
62210 + GR_ID_GROUP = 0x02,
62211 +};
62212 +
62213 +enum {
62214 + GR_ID_ALLOW = 0x01,
62215 + GR_ID_DENY = 0x02,
62216 +};
62217 +
62218 +#define GR_CRASH_RES 31
62219 +#define GR_UIDTABLE_MAX 500
62220 +
62221 +/* begin resource learning section */
62222 +enum {
62223 + GR_RLIM_CPU_BUMP = 60,
62224 + GR_RLIM_FSIZE_BUMP = 50000,
62225 + GR_RLIM_DATA_BUMP = 10000,
62226 + GR_RLIM_STACK_BUMP = 1000,
62227 + GR_RLIM_CORE_BUMP = 10000,
62228 + GR_RLIM_RSS_BUMP = 500000,
62229 + GR_RLIM_NPROC_BUMP = 1,
62230 + GR_RLIM_NOFILE_BUMP = 5,
62231 + GR_RLIM_MEMLOCK_BUMP = 50000,
62232 + GR_RLIM_AS_BUMP = 500000,
62233 + GR_RLIM_LOCKS_BUMP = 2,
62234 + GR_RLIM_SIGPENDING_BUMP = 5,
62235 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62236 + GR_RLIM_NICE_BUMP = 1,
62237 + GR_RLIM_RTPRIO_BUMP = 1,
62238 + GR_RLIM_RTTIME_BUMP = 1000000
62239 +};
62240 +
62241 +#endif
62242 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62243 new file mode 100644
62244 index 0000000..c9292f7
62245 --- /dev/null
62246 +++ b/include/linux/grinternal.h
62247 @@ -0,0 +1,223 @@
62248 +#ifndef __GRINTERNAL_H
62249 +#define __GRINTERNAL_H
62250 +
62251 +#ifdef CONFIG_GRKERNSEC
62252 +
62253 +#include <linux/fs.h>
62254 +#include <linux/mnt_namespace.h>
62255 +#include <linux/nsproxy.h>
62256 +#include <linux/gracl.h>
62257 +#include <linux/grdefs.h>
62258 +#include <linux/grmsg.h>
62259 +
62260 +void gr_add_learn_entry(const char *fmt, ...)
62261 + __attribute__ ((format (printf, 1, 2)));
62262 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62263 + const struct vfsmount *mnt);
62264 +__u32 gr_check_create(const struct dentry *new_dentry,
62265 + const struct dentry *parent,
62266 + const struct vfsmount *mnt, const __u32 mode);
62267 +int gr_check_protected_task(const struct task_struct *task);
62268 +__u32 to_gr_audit(const __u32 reqmode);
62269 +int gr_set_acls(const int type);
62270 +int gr_apply_subject_to_task(struct task_struct *task);
62271 +int gr_acl_is_enabled(void);
62272 +char gr_roletype_to_char(void);
62273 +
62274 +void gr_handle_alertkill(struct task_struct *task);
62275 +char *gr_to_filename(const struct dentry *dentry,
62276 + const struct vfsmount *mnt);
62277 +char *gr_to_filename1(const struct dentry *dentry,
62278 + const struct vfsmount *mnt);
62279 +char *gr_to_filename2(const struct dentry *dentry,
62280 + const struct vfsmount *mnt);
62281 +char *gr_to_filename3(const struct dentry *dentry,
62282 + const struct vfsmount *mnt);
62283 +
62284 +extern int grsec_enable_ptrace_readexec;
62285 +extern int grsec_enable_harden_ptrace;
62286 +extern int grsec_enable_link;
62287 +extern int grsec_enable_fifo;
62288 +extern int grsec_enable_execve;
62289 +extern int grsec_enable_shm;
62290 +extern int grsec_enable_execlog;
62291 +extern int grsec_enable_signal;
62292 +extern int grsec_enable_audit_ptrace;
62293 +extern int grsec_enable_forkfail;
62294 +extern int grsec_enable_time;
62295 +extern int grsec_enable_rofs;
62296 +extern int grsec_enable_chroot_shmat;
62297 +extern int grsec_enable_chroot_mount;
62298 +extern int grsec_enable_chroot_double;
62299 +extern int grsec_enable_chroot_pivot;
62300 +extern int grsec_enable_chroot_chdir;
62301 +extern int grsec_enable_chroot_chmod;
62302 +extern int grsec_enable_chroot_mknod;
62303 +extern int grsec_enable_chroot_fchdir;
62304 +extern int grsec_enable_chroot_nice;
62305 +extern int grsec_enable_chroot_execlog;
62306 +extern int grsec_enable_chroot_caps;
62307 +extern int grsec_enable_chroot_sysctl;
62308 +extern int grsec_enable_chroot_unix;
62309 +extern int grsec_enable_symlinkown;
62310 +extern int grsec_symlinkown_gid;
62311 +extern int grsec_enable_tpe;
62312 +extern int grsec_tpe_gid;
62313 +extern int grsec_enable_tpe_all;
62314 +extern int grsec_enable_tpe_invert;
62315 +extern int grsec_enable_socket_all;
62316 +extern int grsec_socket_all_gid;
62317 +extern int grsec_enable_socket_client;
62318 +extern int grsec_socket_client_gid;
62319 +extern int grsec_enable_socket_server;
62320 +extern int grsec_socket_server_gid;
62321 +extern int grsec_audit_gid;
62322 +extern int grsec_enable_group;
62323 +extern int grsec_enable_audit_textrel;
62324 +extern int grsec_enable_log_rwxmaps;
62325 +extern int grsec_enable_mount;
62326 +extern int grsec_enable_chdir;
62327 +extern int grsec_resource_logging;
62328 +extern int grsec_enable_blackhole;
62329 +extern int grsec_lastack_retries;
62330 +extern int grsec_enable_brute;
62331 +extern int grsec_lock;
62332 +
62333 +extern spinlock_t grsec_alert_lock;
62334 +extern unsigned long grsec_alert_wtime;
62335 +extern unsigned long grsec_alert_fyet;
62336 +
62337 +extern spinlock_t grsec_audit_lock;
62338 +
62339 +extern rwlock_t grsec_exec_file_lock;
62340 +
62341 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62342 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62343 + (tsk)->exec_file->f_vfsmnt) : "/")
62344 +
62345 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62346 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62347 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62348 +
62349 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62350 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62351 + (tsk)->exec_file->f_vfsmnt) : "/")
62352 +
62353 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62354 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62355 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62356 +
62357 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62358 +
62359 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62360 +
62361 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62362 + (task)->pid, (cred)->uid, \
62363 + (cred)->euid, (cred)->gid, (cred)->egid, \
62364 + gr_parent_task_fullpath(task), \
62365 + (task)->real_parent->comm, (task)->real_parent->pid, \
62366 + (pcred)->uid, (pcred)->euid, \
62367 + (pcred)->gid, (pcred)->egid
62368 +
62369 +#define GR_CHROOT_CAPS {{ \
62370 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62371 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62372 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62373 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62374 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62375 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62376 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62377 +
62378 +#define security_learn(normal_msg,args...) \
62379 +({ \
62380 + read_lock(&grsec_exec_file_lock); \
62381 + gr_add_learn_entry(normal_msg "\n", ## args); \
62382 + read_unlock(&grsec_exec_file_lock); \
62383 +})
62384 +
62385 +enum {
62386 + GR_DO_AUDIT,
62387 + GR_DONT_AUDIT,
62388 + /* used for non-audit messages that we shouldn't kill the task on */
62389 + GR_DONT_AUDIT_GOOD
62390 +};
62391 +
62392 +enum {
62393 + GR_TTYSNIFF,
62394 + GR_RBAC,
62395 + GR_RBAC_STR,
62396 + GR_STR_RBAC,
62397 + GR_RBAC_MODE2,
62398 + GR_RBAC_MODE3,
62399 + GR_FILENAME,
62400 + GR_SYSCTL_HIDDEN,
62401 + GR_NOARGS,
62402 + GR_ONE_INT,
62403 + GR_ONE_INT_TWO_STR,
62404 + GR_ONE_STR,
62405 + GR_STR_INT,
62406 + GR_TWO_STR_INT,
62407 + GR_TWO_INT,
62408 + GR_TWO_U64,
62409 + GR_THREE_INT,
62410 + GR_FIVE_INT_TWO_STR,
62411 + GR_TWO_STR,
62412 + GR_THREE_STR,
62413 + GR_FOUR_STR,
62414 + GR_STR_FILENAME,
62415 + GR_FILENAME_STR,
62416 + GR_FILENAME_TWO_INT,
62417 + GR_FILENAME_TWO_INT_STR,
62418 + GR_TEXTREL,
62419 + GR_PTRACE,
62420 + GR_RESOURCE,
62421 + GR_CAP,
62422 + GR_SIG,
62423 + GR_SIG2,
62424 + GR_CRASH1,
62425 + GR_CRASH2,
62426 + GR_PSACCT,
62427 + GR_RWXMAP
62428 +};
62429 +
62430 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62431 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62432 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62433 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62434 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62435 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62436 +#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)
62437 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62438 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62439 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62440 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62441 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62442 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62443 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62444 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62445 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62446 +#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)
62447 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62448 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62449 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62450 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62451 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62452 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62453 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62454 +#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)
62455 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62456 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62457 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62458 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62459 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62460 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62461 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62462 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62463 +#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)
62464 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62465 +
62466 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62467 +
62468 +#endif
62469 +
62470 +#endif
62471 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62472 new file mode 100644
62473 index 0000000..2bd4c8d
62474 --- /dev/null
62475 +++ b/include/linux/grmsg.h
62476 @@ -0,0 +1,111 @@
62477 +#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"
62478 +#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"
62479 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62480 +#define GR_STOPMOD_MSG "denied modification of module state by "
62481 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62482 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62483 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62484 +#define GR_IOPL_MSG "denied use of iopl() by "
62485 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62486 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62487 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62488 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62489 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62490 +#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"
62491 +#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"
62492 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62493 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62494 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62495 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62496 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62497 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62498 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62499 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62500 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62501 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62502 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62503 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62504 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62505 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62506 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62507 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62508 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62509 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62510 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62511 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62512 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62513 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62514 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62515 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62516 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62517 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62518 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62519 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62520 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62521 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62522 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62523 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62524 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62525 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62526 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62527 +#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"
62528 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62529 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62530 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62531 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62532 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62533 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62534 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62535 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62536 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62537 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62538 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62539 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62540 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62541 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62542 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62543 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62544 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62545 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62546 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62547 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62548 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62549 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62550 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62551 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62552 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62553 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62554 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62555 +#define GR_TIME_MSG "time set by "
62556 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62557 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62558 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62559 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62560 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62561 +#define GR_BIND_MSG "denied bind() by "
62562 +#define GR_CONNECT_MSG "denied connect() by "
62563 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62564 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62565 +#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"
62566 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62567 +#define GR_CAP_ACL_MSG "use of %s denied for "
62568 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62569 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62570 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62571 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62572 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62573 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62574 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62575 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62576 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62577 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62578 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62579 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62580 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62581 +#define GR_VM86_MSG "denied use of vm86 by "
62582 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62583 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62584 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62585 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62586 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62587 +#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 "
62588 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62589 new file mode 100644
62590 index 0000000..f2f5d5b
62591 --- /dev/null
62592 +++ b/include/linux/grsecurity.h
62593 @@ -0,0 +1,239 @@
62594 +#ifndef GR_SECURITY_H
62595 +#define GR_SECURITY_H
62596 +#include <linux/fs.h>
62597 +#include <linux/fs_struct.h>
62598 +#include <linux/binfmts.h>
62599 +#include <linux/gracl.h>
62600 +
62601 +/* notify of brain-dead configs */
62602 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62603 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62604 +#endif
62605 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62606 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62607 +#endif
62608 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62609 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62610 +#endif
62611 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62612 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62613 +#endif
62614 +
62615 +#include <linux/compat.h>
62616 +
62617 +struct user_arg_ptr {
62618 +#ifdef CONFIG_COMPAT
62619 + bool is_compat;
62620 +#endif
62621 + union {
62622 + const char __user *const __user *native;
62623 +#ifdef CONFIG_COMPAT
62624 + const compat_uptr_t __user *compat;
62625 +#endif
62626 + } ptr;
62627 +};
62628 +
62629 +void gr_handle_brute_attach(unsigned long mm_flags);
62630 +void gr_handle_brute_check(void);
62631 +void gr_handle_kernel_exploit(void);
62632 +int gr_process_user_ban(void);
62633 +
62634 +char gr_roletype_to_char(void);
62635 +
62636 +int gr_acl_enable_at_secure(void);
62637 +
62638 +int gr_check_user_change(int real, int effective, int fs);
62639 +int gr_check_group_change(int real, int effective, int fs);
62640 +
62641 +void gr_del_task_from_ip_table(struct task_struct *p);
62642 +
62643 +int gr_pid_is_chrooted(struct task_struct *p);
62644 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62645 +int gr_handle_chroot_nice(void);
62646 +int gr_handle_chroot_sysctl(const int op);
62647 +int gr_handle_chroot_setpriority(struct task_struct *p,
62648 + const int niceval);
62649 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62650 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62651 + const struct vfsmount *mnt);
62652 +void gr_handle_chroot_chdir(struct path *path);
62653 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62654 + const struct vfsmount *mnt, const int mode);
62655 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62656 + const struct vfsmount *mnt, const int mode);
62657 +int gr_handle_chroot_mount(const struct dentry *dentry,
62658 + const struct vfsmount *mnt,
62659 + const char *dev_name);
62660 +int gr_handle_chroot_pivot(void);
62661 +int gr_handle_chroot_unix(const pid_t pid);
62662 +
62663 +int gr_handle_rawio(const struct inode *inode);
62664 +
62665 +void gr_handle_ioperm(void);
62666 +void gr_handle_iopl(void);
62667 +
62668 +umode_t gr_acl_umask(void);
62669 +
62670 +int gr_tpe_allow(const struct file *file);
62671 +
62672 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62673 +void gr_clear_chroot_entries(struct task_struct *task);
62674 +
62675 +void gr_log_forkfail(const int retval);
62676 +void gr_log_timechange(void);
62677 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62678 +void gr_log_chdir(const struct dentry *dentry,
62679 + const struct vfsmount *mnt);
62680 +void gr_log_chroot_exec(const struct dentry *dentry,
62681 + const struct vfsmount *mnt);
62682 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62683 +void gr_log_remount(const char *devname, const int retval);
62684 +void gr_log_unmount(const char *devname, const int retval);
62685 +void gr_log_mount(const char *from, const char *to, const int retval);
62686 +void gr_log_textrel(struct vm_area_struct *vma);
62687 +void gr_log_rwxmmap(struct file *file);
62688 +void gr_log_rwxmprotect(struct file *file);
62689 +
62690 +int gr_handle_follow_link(const struct inode *parent,
62691 + const struct inode *inode,
62692 + const struct dentry *dentry,
62693 + const struct vfsmount *mnt);
62694 +int gr_handle_fifo(const struct dentry *dentry,
62695 + const struct vfsmount *mnt,
62696 + const struct dentry *dir, const int flag,
62697 + const int acc_mode);
62698 +int gr_handle_hardlink(const struct dentry *dentry,
62699 + const struct vfsmount *mnt,
62700 + struct inode *inode,
62701 + const int mode, const struct filename *to);
62702 +
62703 +int gr_is_capable(const int cap);
62704 +int gr_is_capable_nolog(const int cap);
62705 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62706 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62707 +
62708 +void gr_learn_resource(const struct task_struct *task, const int limit,
62709 + const unsigned long wanted, const int gt);
62710 +void gr_copy_label(struct task_struct *tsk);
62711 +void gr_handle_crash(struct task_struct *task, const int sig);
62712 +int gr_handle_signal(const struct task_struct *p, const int sig);
62713 +int gr_check_crash_uid(const uid_t uid);
62714 +int gr_check_protected_task(const struct task_struct *task);
62715 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62716 +int gr_acl_handle_mmap(const struct file *file,
62717 + const unsigned long prot);
62718 +int gr_acl_handle_mprotect(const struct file *file,
62719 + const unsigned long prot);
62720 +int gr_check_hidden_task(const struct task_struct *tsk);
62721 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62722 + const struct vfsmount *mnt);
62723 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62724 + const struct vfsmount *mnt);
62725 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62726 + const struct vfsmount *mnt, const int fmode);
62727 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62728 + const struct vfsmount *mnt, umode_t *mode);
62729 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62730 + const struct vfsmount *mnt);
62731 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62732 + const struct vfsmount *mnt);
62733 +int gr_handle_ptrace(struct task_struct *task, const long request);
62734 +int gr_handle_proc_ptrace(struct task_struct *task);
62735 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62736 + const struct vfsmount *mnt);
62737 +int gr_check_crash_exec(const struct file *filp);
62738 +int gr_acl_is_enabled(void);
62739 +void gr_set_kernel_label(struct task_struct *task);
62740 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62741 + const gid_t gid);
62742 +int gr_set_proc_label(const struct dentry *dentry,
62743 + const struct vfsmount *mnt,
62744 + const int unsafe_flags);
62745 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62746 + const struct vfsmount *mnt);
62747 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62748 + const struct vfsmount *mnt, int acc_mode);
62749 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62750 + const struct dentry *p_dentry,
62751 + const struct vfsmount *p_mnt,
62752 + int open_flags, int acc_mode, const int imode);
62753 +void gr_handle_create(const struct dentry *dentry,
62754 + const struct vfsmount *mnt);
62755 +void gr_handle_proc_create(const struct dentry *dentry,
62756 + const struct inode *inode);
62757 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62758 + const struct dentry *parent_dentry,
62759 + const struct vfsmount *parent_mnt,
62760 + const int mode);
62761 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62762 + const struct dentry *parent_dentry,
62763 + const struct vfsmount *parent_mnt);
62764 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62765 + const struct vfsmount *mnt);
62766 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62767 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62768 + const struct vfsmount *mnt);
62769 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62770 + const struct dentry *parent_dentry,
62771 + const struct vfsmount *parent_mnt,
62772 + const struct filename *from);
62773 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62774 + const struct dentry *parent_dentry,
62775 + const struct vfsmount *parent_mnt,
62776 + const struct dentry *old_dentry,
62777 + const struct vfsmount *old_mnt, const struct filename *to);
62778 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62779 +int gr_acl_handle_rename(struct dentry *new_dentry,
62780 + struct dentry *parent_dentry,
62781 + const struct vfsmount *parent_mnt,
62782 + struct dentry *old_dentry,
62783 + struct inode *old_parent_inode,
62784 + struct vfsmount *old_mnt, const struct filename *newname);
62785 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62786 + struct dentry *old_dentry,
62787 + struct dentry *new_dentry,
62788 + struct vfsmount *mnt, const __u8 replace);
62789 +__u32 gr_check_link(const struct dentry *new_dentry,
62790 + const struct dentry *parent_dentry,
62791 + const struct vfsmount *parent_mnt,
62792 + const struct dentry *old_dentry,
62793 + const struct vfsmount *old_mnt);
62794 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62795 + const unsigned int namelen, const ino_t ino);
62796 +
62797 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62798 + const struct vfsmount *mnt);
62799 +void gr_acl_handle_exit(void);
62800 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62801 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62802 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62803 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62804 +void gr_audit_ptrace(struct task_struct *task);
62805 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62806 +void gr_put_exec_file(struct task_struct *task);
62807 +
62808 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62809 +
62810 +#ifdef CONFIG_GRKERNSEC
62811 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62812 +void gr_handle_vm86(void);
62813 +void gr_handle_mem_readwrite(u64 from, u64 to);
62814 +
62815 +void gr_log_badprocpid(const char *entry);
62816 +
62817 +extern int grsec_enable_dmesg;
62818 +extern int grsec_disable_privio;
62819 +
62820 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62821 +extern int grsec_proc_gid;
62822 +#endif
62823 +
62824 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62825 +extern int grsec_enable_chroot_findtask;
62826 +#endif
62827 +#ifdef CONFIG_GRKERNSEC_SETXID
62828 +extern int grsec_enable_setxid;
62829 +#endif
62830 +#endif
62831 +
62832 +#endif
62833 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62834 new file mode 100644
62835 index 0000000..e7ffaaf
62836 --- /dev/null
62837 +++ b/include/linux/grsock.h
62838 @@ -0,0 +1,19 @@
62839 +#ifndef __GRSOCK_H
62840 +#define __GRSOCK_H
62841 +
62842 +extern void gr_attach_curr_ip(const struct sock *sk);
62843 +extern int gr_handle_sock_all(const int family, const int type,
62844 + const int protocol);
62845 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62846 +extern int gr_handle_sock_server_other(const struct sock *sck);
62847 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62848 +extern int gr_search_connect(struct socket * sock,
62849 + struct sockaddr_in * addr);
62850 +extern int gr_search_bind(struct socket * sock,
62851 + struct sockaddr_in * addr);
62852 +extern int gr_search_listen(struct socket * sock);
62853 +extern int gr_search_accept(struct socket * sock);
62854 +extern int gr_search_socket(const int domain, const int type,
62855 + const int protocol);
62856 +
62857 +#endif
62858 diff --git a/include/linux/hid.h b/include/linux/hid.h
62859 index c076041..6f54d73 100644
62860 --- a/include/linux/hid.h
62861 +++ b/include/linux/hid.h
62862 @@ -671,7 +671,7 @@ struct hid_ll_driver {
62863 unsigned int code, int value);
62864
62865 int (*parse)(struct hid_device *hdev);
62866 -};
62867 +} __no_const;
62868
62869 #define PM_HINT_FULLON 1<<5
62870 #define PM_HINT_NORMAL 1<<1
62871 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62872 index ef788b5..ac41b7b 100644
62873 --- a/include/linux/highmem.h
62874 +++ b/include/linux/highmem.h
62875 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62876 kunmap_atomic(kaddr);
62877 }
62878
62879 +static inline void sanitize_highpage(struct page *page)
62880 +{
62881 + void *kaddr;
62882 + unsigned long flags;
62883 +
62884 + local_irq_save(flags);
62885 + kaddr = kmap_atomic(page);
62886 + clear_page(kaddr);
62887 + kunmap_atomic(kaddr);
62888 + local_irq_restore(flags);
62889 +}
62890 +
62891 static inline void zero_user_segments(struct page *page,
62892 unsigned start1, unsigned end1,
62893 unsigned start2, unsigned end2)
62894 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62895 index 800de22..7a2fa46 100644
62896 --- a/include/linux/i2c.h
62897 +++ b/include/linux/i2c.h
62898 @@ -367,6 +367,7 @@ struct i2c_algorithm {
62899 /* To determine what the adapter supports */
62900 u32 (*functionality) (struct i2c_adapter *);
62901 };
62902 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62903
62904 /*
62905 * i2c_adapter is the structure used to identify a physical i2c bus along
62906 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62907 index d23c3c2..eb63c81 100644
62908 --- a/include/linux/i2o.h
62909 +++ b/include/linux/i2o.h
62910 @@ -565,7 +565,7 @@ struct i2o_controller {
62911 struct i2o_device *exec; /* Executive */
62912 #if BITS_PER_LONG == 64
62913 spinlock_t context_list_lock; /* lock for context_list */
62914 - atomic_t context_list_counter; /* needed for unique contexts */
62915 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62916 struct list_head context_list; /* list of context id's
62917 and pointers */
62918 #endif
62919 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62920 index 0245def..1199c5a 100644
62921 --- a/include/linux/if_team.h
62922 +++ b/include/linux/if_team.h
62923 @@ -111,6 +111,7 @@ struct team_mode_ops {
62924 void (*port_enabled)(struct team *team, struct team_port *port);
62925 void (*port_disabled)(struct team *team, struct team_port *port);
62926 };
62927 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62928
62929 enum team_option_type {
62930 TEAM_OPTION_TYPE_U32,
62931 @@ -185,7 +186,7 @@ struct team {
62932 struct list_head option_inst_list; /* list of option instances */
62933
62934 const struct team_mode *mode;
62935 - struct team_mode_ops ops;
62936 + team_mode_ops_no_const ops;
62937 bool queue_override_enabled;
62938 struct list_head *qom_lists; /* array of queue override mapping lists */
62939 long mode_priv[TEAM_MODE_PRIV_LONGS];
62940 diff --git a/include/linux/init.h b/include/linux/init.h
62941 index e59041e..df0a975 100644
62942 --- a/include/linux/init.h
62943 +++ b/include/linux/init.h
62944 @@ -39,9 +39,36 @@
62945 * Also note, that this data cannot be "const".
62946 */
62947
62948 +#ifdef MODULE
62949 +#define add_init_latent_entropy
62950 +#define add_devinit_latent_entropy
62951 +#define add_cpuinit_latent_entropy
62952 +#define add_meminit_latent_entropy
62953 +#else
62954 +#define add_init_latent_entropy __latent_entropy
62955 +
62956 +#ifdef CONFIG_HOTPLUG
62957 +#define add_devinit_latent_entropy
62958 +#else
62959 +#define add_devinit_latent_entropy __latent_entropy
62960 +#endif
62961 +
62962 +#ifdef CONFIG_HOTPLUG_CPU
62963 +#define add_cpuinit_latent_entropy
62964 +#else
62965 +#define add_cpuinit_latent_entropy __latent_entropy
62966 +#endif
62967 +
62968 +#ifdef CONFIG_MEMORY_HOTPLUG
62969 +#define add_meminit_latent_entropy
62970 +#else
62971 +#define add_meminit_latent_entropy __latent_entropy
62972 +#endif
62973 +#endif
62974 +
62975 /* These are for everybody (although not all archs will actually
62976 discard it in modules) */
62977 -#define __init __section(.init.text) __cold notrace
62978 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
62979 #define __initdata __section(.init.data)
62980 #define __initconst __constsection(.init.rodata)
62981 #define __exitdata __section(.exit.data)
62982 @@ -94,7 +121,7 @@
62983 #define __exit __section(.exit.text) __exitused __cold notrace
62984
62985 /* Used for HOTPLUG */
62986 -#define __devinit __section(.devinit.text) __cold notrace
62987 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
62988 #define __devinitdata __section(.devinit.data)
62989 #define __devinitconst __constsection(.devinit.rodata)
62990 #define __devexit __section(.devexit.text) __exitused __cold notrace
62991 @@ -102,7 +129,7 @@
62992 #define __devexitconst __constsection(.devexit.rodata)
62993
62994 /* Used for HOTPLUG_CPU */
62995 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62996 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
62997 #define __cpuinitdata __section(.cpuinit.data)
62998 #define __cpuinitconst __constsection(.cpuinit.rodata)
62999 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63000 @@ -110,7 +137,7 @@
63001 #define __cpuexitconst __constsection(.cpuexit.rodata)
63002
63003 /* Used for MEMORY_HOTPLUG */
63004 -#define __meminit __section(.meminit.text) __cold notrace
63005 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63006 #define __meminitdata __section(.meminit.data)
63007 #define __meminitconst __constsection(.meminit.rodata)
63008 #define __memexit __section(.memexit.text) __exitused __cold notrace
63009 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63010 index 6d087c5..401cab8 100644
63011 --- a/include/linux/init_task.h
63012 +++ b/include/linux/init_task.h
63013 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63014
63015 #define INIT_TASK_COMM "swapper"
63016
63017 +#ifdef CONFIG_X86
63018 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63019 +#else
63020 +#define INIT_TASK_THREAD_INFO
63021 +#endif
63022 +
63023 /*
63024 * INIT_TASK is used to set up the first task table, touch at
63025 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63026 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63027 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63028 .comm = INIT_TASK_COMM, \
63029 .thread = INIT_THREAD, \
63030 + INIT_TASK_THREAD_INFO \
63031 .fs = &init_fs, \
63032 .files = &init_files, \
63033 .signal = &init_signals, \
63034 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63035 index 78e2ada..745564d 100644
63036 --- a/include/linux/intel-iommu.h
63037 +++ b/include/linux/intel-iommu.h
63038 @@ -296,7 +296,7 @@ struct iommu_flush {
63039 u8 fm, u64 type);
63040 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63041 unsigned int size_order, u64 type);
63042 -};
63043 +} __no_const;
63044
63045 enum {
63046 SR_DMAR_FECTL_REG,
63047 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63048 index 5e4e617..eee383d 100644
63049 --- a/include/linux/interrupt.h
63050 +++ b/include/linux/interrupt.h
63051 @@ -435,7 +435,7 @@ enum
63052 /* map softirq index to softirq name. update 'softirq_to_name' in
63053 * kernel/softirq.c when adding a new softirq.
63054 */
63055 -extern char *softirq_to_name[NR_SOFTIRQS];
63056 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63057
63058 /* softirq mask and active fields moved to irq_cpustat_t in
63059 * asm/hardirq.h to get better cache usage. KAO
63060 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63061
63062 struct softirq_action
63063 {
63064 - void (*action)(struct softirq_action *);
63065 + void (*action)(void);
63066 };
63067
63068 asmlinkage void do_softirq(void);
63069 asmlinkage void __do_softirq(void);
63070 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63071 +extern void open_softirq(int nr, void (*action)(void));
63072 extern void softirq_init(void);
63073 extern void __raise_softirq_irqoff(unsigned int nr);
63074
63075 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63076 index 6883e19..06992b1 100644
63077 --- a/include/linux/kallsyms.h
63078 +++ b/include/linux/kallsyms.h
63079 @@ -15,7 +15,8 @@
63080
63081 struct module;
63082
63083 -#ifdef CONFIG_KALLSYMS
63084 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63085 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63086 /* Lookup the address for a symbol. Returns 0 if not found. */
63087 unsigned long kallsyms_lookup_name(const char *name);
63088
63089 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63090 /* Stupid that this does nothing, but I didn't create this mess. */
63091 #define __print_symbol(fmt, addr)
63092 #endif /*CONFIG_KALLSYMS*/
63093 +#else /* when included by kallsyms.c, vsnprintf.c, or
63094 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63095 +extern void __print_symbol(const char *fmt, unsigned long address);
63096 +extern int sprint_backtrace(char *buffer, unsigned long address);
63097 +extern int sprint_symbol(char *buffer, unsigned long address);
63098 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63099 +const char *kallsyms_lookup(unsigned long addr,
63100 + unsigned long *symbolsize,
63101 + unsigned long *offset,
63102 + char **modname, char *namebuf);
63103 +#endif
63104
63105 /* This macro allows us to keep printk typechecking */
63106 static __printf(1, 2)
63107 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63108 index 4dff0c6..1ca9b72 100644
63109 --- a/include/linux/kgdb.h
63110 +++ b/include/linux/kgdb.h
63111 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63112 extern int kgdb_io_module_registered;
63113
63114 extern atomic_t kgdb_setting_breakpoint;
63115 -extern atomic_t kgdb_cpu_doing_single_step;
63116 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63117
63118 extern struct task_struct *kgdb_usethread;
63119 extern struct task_struct *kgdb_contthread;
63120 @@ -255,7 +255,7 @@ struct kgdb_arch {
63121 void (*correct_hw_break)(void);
63122
63123 void (*enable_nmi)(bool on);
63124 -};
63125 +} __do_const;
63126
63127 /**
63128 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63129 @@ -280,7 +280,7 @@ struct kgdb_io {
63130 void (*pre_exception) (void);
63131 void (*post_exception) (void);
63132 int is_console;
63133 -};
63134 +} __do_const;
63135
63136 extern struct kgdb_arch arch_kgdb_ops;
63137
63138 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63139 index 5398d58..5883a34 100644
63140 --- a/include/linux/kmod.h
63141 +++ b/include/linux/kmod.h
63142 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63143 * usually useless though. */
63144 extern __printf(2, 3)
63145 int __request_module(bool wait, const char *name, ...);
63146 +extern __printf(3, 4)
63147 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63148 #define request_module(mod...) __request_module(true, mod)
63149 #define request_module_nowait(mod...) __request_module(false, mod)
63150 #define try_then_request_module(x, mod...) \
63151 diff --git a/include/linux/kref.h b/include/linux/kref.h
63152 index 65af688..0592677 100644
63153 --- a/include/linux/kref.h
63154 +++ b/include/linux/kref.h
63155 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63156 static inline int kref_sub(struct kref *kref, unsigned int count,
63157 void (*release)(struct kref *kref))
63158 {
63159 - WARN_ON(release == NULL);
63160 + BUG_ON(release == NULL);
63161
63162 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63163 release(kref);
63164 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63165 index ecc5543..0e96bcc 100644
63166 --- a/include/linux/kvm_host.h
63167 +++ b/include/linux/kvm_host.h
63168 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63169 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
63170 void vcpu_put(struct kvm_vcpu *vcpu);
63171
63172 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63173 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63174 struct module *module);
63175 void kvm_exit(void);
63176
63177 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63178 struct kvm_guest_debug *dbg);
63179 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63180
63181 -int kvm_arch_init(void *opaque);
63182 +int kvm_arch_init(const void *opaque);
63183 void kvm_arch_exit(void);
63184
63185 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63186 diff --git a/include/linux/libata.h b/include/linux/libata.h
63187 index 77eeeda..062ed69c 100644
63188 --- a/include/linux/libata.h
63189 +++ b/include/linux/libata.h
63190 @@ -914,7 +914,7 @@ struct ata_port_operations {
63191 * fields must be pointers.
63192 */
63193 const struct ata_port_operations *inherits;
63194 -};
63195 +} __do_const;
63196
63197 struct ata_port_info {
63198 unsigned long flags;
63199 diff --git a/include/linux/memory.h b/include/linux/memory.h
63200 index ff9a9f8..c715deb 100644
63201 --- a/include/linux/memory.h
63202 +++ b/include/linux/memory.h
63203 @@ -143,7 +143,7 @@ struct memory_accessor {
63204 size_t count);
63205 ssize_t (*write)(struct memory_accessor *, const char *buf,
63206 off_t offset, size_t count);
63207 -};
63208 +} __no_const;
63209
63210 /*
63211 * Kernel text modification mutex, used for code patching. Users of this lock
63212 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63213 index 5d5298d..e3e5a2e 100644
63214 --- a/include/linux/mfd/abx500.h
63215 +++ b/include/linux/mfd/abx500.h
63216 @@ -337,6 +337,7 @@ struct abx500_ops {
63217 int (*event_registers_startup_state_get) (struct device *, u8 *);
63218 int (*startup_irq_enabled) (struct device *, unsigned int);
63219 };
63220 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63221
63222 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63223 void abx500_remove_ops(struct device *dev);
63224 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63225 index 9b07725..3d55001 100644
63226 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63227 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63228 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63229 int (*enable) (struct ux500_charger *, int, int, int);
63230 int (*kick_wd) (struct ux500_charger *);
63231 int (*update_curr) (struct ux500_charger *, int);
63232 -};
63233 +} __no_const;
63234
63235 /**
63236 * struct ux500_charger - power supply ux500 charger sub class
63237 diff --git a/include/linux/mm.h b/include/linux/mm.h
63238 index bcaab4e..f842186 100644
63239 --- a/include/linux/mm.h
63240 +++ b/include/linux/mm.h
63241 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
63242 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
63243 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
63244 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
63245 +
63246 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63247 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
63248 +#endif
63249 +
63250 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
63251
63252 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63253 @@ -1040,34 +1045,6 @@ int set_page_dirty(struct page *page);
63254 int set_page_dirty_lock(struct page *page);
63255 int clear_page_dirty_for_io(struct page *page);
63256
63257 -/* Is the vma a continuation of the stack vma above it? */
63258 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63259 -{
63260 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63261 -}
63262 -
63263 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63264 - unsigned long addr)
63265 -{
63266 - return (vma->vm_flags & VM_GROWSDOWN) &&
63267 - (vma->vm_start == addr) &&
63268 - !vma_growsdown(vma->vm_prev, addr);
63269 -}
63270 -
63271 -/* Is the vma a continuation of the stack vma below it? */
63272 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63273 -{
63274 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63275 -}
63276 -
63277 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63278 - unsigned long addr)
63279 -{
63280 - return (vma->vm_flags & VM_GROWSUP) &&
63281 - (vma->vm_end == addr) &&
63282 - !vma_growsup(vma->vm_next, addr);
63283 -}
63284 -
63285 extern pid_t
63286 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63287
63288 @@ -1167,6 +1144,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63289 }
63290 #endif
63291
63292 +#ifdef CONFIG_MMU
63293 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63294 +#else
63295 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63296 +{
63297 + return __pgprot(0);
63298 +}
63299 +#endif
63300 +
63301 int vma_wants_writenotify(struct vm_area_struct *vma);
63302
63303 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63304 @@ -1185,8 +1171,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63305 {
63306 return 0;
63307 }
63308 +
63309 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63310 + unsigned long address)
63311 +{
63312 + return 0;
63313 +}
63314 #else
63315 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63316 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63317 #endif
63318
63319 #ifdef __PAGETABLE_PMD_FOLDED
63320 @@ -1195,8 +1188,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63321 {
63322 return 0;
63323 }
63324 +
63325 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63326 + unsigned long address)
63327 +{
63328 + return 0;
63329 +}
63330 #else
63331 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63332 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63333 #endif
63334
63335 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63336 @@ -1214,11 +1214,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63337 NULL: pud_offset(pgd, address);
63338 }
63339
63340 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63341 +{
63342 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63343 + NULL: pud_offset(pgd, address);
63344 +}
63345 +
63346 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63347 {
63348 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63349 NULL: pmd_offset(pud, address);
63350 }
63351 +
63352 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63353 +{
63354 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63355 + NULL: pmd_offset(pud, address);
63356 +}
63357 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63358
63359 #if USE_SPLIT_PTLOCKS
63360 @@ -1448,6 +1460,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63361 unsigned long, unsigned long,
63362 unsigned long, unsigned long);
63363 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63364 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63365
63366 /* These take the mm semaphore themselves */
63367 extern unsigned long vm_brk(unsigned long, unsigned long);
63368 @@ -1511,6 +1524,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63369 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63370 struct vm_area_struct **pprev);
63371
63372 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63373 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63374 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63375 +
63376 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63377 NULL if none. Assume start_addr < end_addr. */
63378 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63379 @@ -1539,15 +1556,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63380 return vma;
63381 }
63382
63383 -#ifdef CONFIG_MMU
63384 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63385 -#else
63386 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63387 -{
63388 - return __pgprot(0);
63389 -}
63390 -#endif
63391 -
63392 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63393 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63394 unsigned long pfn, unsigned long size, pgprot_t);
63395 @@ -1653,7 +1661,7 @@ extern int unpoison_memory(unsigned long pfn);
63396 extern int sysctl_memory_failure_early_kill;
63397 extern int sysctl_memory_failure_recovery;
63398 extern void shake_page(struct page *p, int access);
63399 -extern atomic_long_t mce_bad_pages;
63400 +extern atomic_long_unchecked_t mce_bad_pages;
63401 extern int soft_offline_page(struct page *page, int flags);
63402
63403 extern void dump_page(struct page *page);
63404 @@ -1684,5 +1692,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63405 static inline bool page_is_guard(struct page *page) { return false; }
63406 #endif /* CONFIG_DEBUG_PAGEALLOC */
63407
63408 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63409 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63410 +#else
63411 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63412 +#endif
63413 +
63414 #endif /* __KERNEL__ */
63415 #endif /* _LINUX_MM_H */
63416 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63417 index 31f8a3a..499f1db 100644
63418 --- a/include/linux/mm_types.h
63419 +++ b/include/linux/mm_types.h
63420 @@ -275,6 +275,8 @@ struct vm_area_struct {
63421 #ifdef CONFIG_NUMA
63422 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63423 #endif
63424 +
63425 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63426 };
63427
63428 struct core_thread {
63429 @@ -348,7 +350,7 @@ struct mm_struct {
63430 unsigned long def_flags;
63431 unsigned long nr_ptes; /* Page table pages */
63432 unsigned long start_code, end_code, start_data, end_data;
63433 - unsigned long start_brk, brk, start_stack;
63434 + unsigned long brk_gap, start_brk, brk, start_stack;
63435 unsigned long arg_start, arg_end, env_start, env_end;
63436
63437 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63438 @@ -399,6 +401,24 @@ struct mm_struct {
63439 struct cpumask cpumask_allocation;
63440 #endif
63441 struct uprobes_state uprobes_state;
63442 +
63443 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63444 + unsigned long pax_flags;
63445 +#endif
63446 +
63447 +#ifdef CONFIG_PAX_DLRESOLVE
63448 + unsigned long call_dl_resolve;
63449 +#endif
63450 +
63451 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63452 + unsigned long call_syscall;
63453 +#endif
63454 +
63455 +#ifdef CONFIG_PAX_ASLR
63456 + unsigned long delta_mmap; /* randomized offset */
63457 + unsigned long delta_stack; /* randomized offset */
63458 +#endif
63459 +
63460 };
63461
63462 static inline void mm_init_cpumask(struct mm_struct *mm)
63463 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63464 index a23923b..073fee4 100644
63465 --- a/include/linux/mmzone.h
63466 +++ b/include/linux/mmzone.h
63467 @@ -421,7 +421,7 @@ struct zone {
63468 unsigned long flags; /* zone flags, see below */
63469
63470 /* Zone statistics */
63471 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63472 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63473
63474 /*
63475 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63476 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63477 index fed3def..7cc3f93 100644
63478 --- a/include/linux/mod_devicetable.h
63479 +++ b/include/linux/mod_devicetable.h
63480 @@ -12,7 +12,7 @@
63481 typedef unsigned long kernel_ulong_t;
63482 #endif
63483
63484 -#define PCI_ANY_ID (~0)
63485 +#define PCI_ANY_ID ((__u16)~0)
63486
63487 struct pci_device_id {
63488 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63489 @@ -139,7 +139,7 @@ struct usb_device_id {
63490 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63491 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63492
63493 -#define HID_ANY_ID (~0)
63494 +#define HID_ANY_ID (~0U)
63495 #define HID_BUS_ANY 0xffff
63496 #define HID_GROUP_ANY 0x0000
63497
63498 diff --git a/include/linux/module.h b/include/linux/module.h
63499 index 7760c6d..07a2d3d 100644
63500 --- a/include/linux/module.h
63501 +++ b/include/linux/module.h
63502 @@ -17,6 +17,7 @@
63503 #include <linux/moduleparam.h>
63504 #include <linux/tracepoint.h>
63505 #include <linux/export.h>
63506 +#include <linux/fs.h>
63507
63508 #include <linux/percpu.h>
63509 #include <asm/module.h>
63510 @@ -281,19 +282,16 @@ struct module
63511 int (*init)(void);
63512
63513 /* If this is non-NULL, vfree after init() returns */
63514 - void *module_init;
63515 + void *module_init_rx, *module_init_rw;
63516
63517 /* Here is the actual code + data, vfree'd on unload. */
63518 - void *module_core;
63519 + void *module_core_rx, *module_core_rw;
63520
63521 /* Here are the sizes of the init and core sections */
63522 - unsigned int init_size, core_size;
63523 + unsigned int init_size_rw, core_size_rw;
63524
63525 /* The size of the executable code in each section. */
63526 - unsigned int init_text_size, core_text_size;
63527 -
63528 - /* Size of RO sections of the module (text+rodata) */
63529 - unsigned int init_ro_size, core_ro_size;
63530 + unsigned int init_size_rx, core_size_rx;
63531
63532 /* Arch-specific module values */
63533 struct mod_arch_specific arch;
63534 @@ -349,6 +347,10 @@ struct module
63535 #ifdef CONFIG_EVENT_TRACING
63536 struct ftrace_event_call **trace_events;
63537 unsigned int num_trace_events;
63538 + struct file_operations trace_id;
63539 + struct file_operations trace_enable;
63540 + struct file_operations trace_format;
63541 + struct file_operations trace_filter;
63542 #endif
63543 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63544 unsigned int num_ftrace_callsites;
63545 @@ -396,16 +398,46 @@ bool is_module_address(unsigned long addr);
63546 bool is_module_percpu_address(unsigned long addr);
63547 bool is_module_text_address(unsigned long addr);
63548
63549 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63550 +{
63551 +
63552 +#ifdef CONFIG_PAX_KERNEXEC
63553 + if (ktla_ktva(addr) >= (unsigned long)start &&
63554 + ktla_ktva(addr) < (unsigned long)start + size)
63555 + return 1;
63556 +#endif
63557 +
63558 + return ((void *)addr >= start && (void *)addr < start + size);
63559 +}
63560 +
63561 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63562 +{
63563 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63564 +}
63565 +
63566 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63567 +{
63568 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63569 +}
63570 +
63571 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63572 +{
63573 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63574 +}
63575 +
63576 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63577 +{
63578 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63579 +}
63580 +
63581 static inline int within_module_core(unsigned long addr, struct module *mod)
63582 {
63583 - return (unsigned long)mod->module_core <= addr &&
63584 - addr < (unsigned long)mod->module_core + mod->core_size;
63585 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63586 }
63587
63588 static inline int within_module_init(unsigned long addr, struct module *mod)
63589 {
63590 - return (unsigned long)mod->module_init <= addr &&
63591 - addr < (unsigned long)mod->module_init + mod->init_size;
63592 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63593 }
63594
63595 /* Search for module by name: must hold module_mutex. */
63596 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63597 index 560ca53..16968cc 100644
63598 --- a/include/linux/moduleloader.h
63599 +++ b/include/linux/moduleloader.h
63600 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63601
63602 /* Allocator used for allocating struct module, core sections and init
63603 sections. Returns NULL on failure. */
63604 -void *module_alloc(unsigned long size);
63605 +void *module_alloc(unsigned long size) __size_overflow(1);
63606 +
63607 +#ifdef CONFIG_PAX_KERNEXEC
63608 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63609 +#else
63610 +#define module_alloc_exec(x) module_alloc(x)
63611 +#endif
63612
63613 /* Free memory returned from module_alloc. */
63614 void module_free(struct module *mod, void *module_region);
63615
63616 +#ifdef CONFIG_PAX_KERNEXEC
63617 +void module_free_exec(struct module *mod, void *module_region);
63618 +#else
63619 +#define module_free_exec(x, y) module_free((x), (y))
63620 +#endif
63621 +
63622 /*
63623 * Apply the given relocation to the (simplified) ELF. Return -error
63624 * or 0.
63625 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63626 index d6a5806..7c13347 100644
63627 --- a/include/linux/moduleparam.h
63628 +++ b/include/linux/moduleparam.h
63629 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63630 * @len is usually just sizeof(string).
63631 */
63632 #define module_param_string(name, string, len, perm) \
63633 - static const struct kparam_string __param_string_##name \
63634 + static const struct kparam_string __param_string_##name __used \
63635 = { len, string }; \
63636 __module_param_call(MODULE_PARAM_PREFIX, name, \
63637 &param_ops_string, \
63638 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63639 */
63640 #define module_param_array_named(name, array, type, nump, perm) \
63641 param_check_##type(name, &(array)[0]); \
63642 - static const struct kparam_array __param_arr_##name \
63643 + static const struct kparam_array __param_arr_##name __used \
63644 = { .max = ARRAY_SIZE(array), .num = nump, \
63645 .ops = &param_ops_##type, \
63646 .elemsize = sizeof(array[0]), .elem = array }; \
63647 diff --git a/include/linux/namei.h b/include/linux/namei.h
63648 index 4bf19d8..5268cea 100644
63649 --- a/include/linux/namei.h
63650 +++ b/include/linux/namei.h
63651 @@ -18,7 +18,7 @@ struct nameidata {
63652 unsigned seq;
63653 int last_type;
63654 unsigned depth;
63655 - char *saved_names[MAX_NESTED_LINKS + 1];
63656 + const char *saved_names[MAX_NESTED_LINKS + 1];
63657 };
63658
63659 /*
63660 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63661
63662 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63663
63664 -static inline void nd_set_link(struct nameidata *nd, char *path)
63665 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63666 {
63667 nd->saved_names[nd->depth] = path;
63668 }
63669
63670 -static inline char *nd_get_link(struct nameidata *nd)
63671 +static inline const char *nd_get_link(const struct nameidata *nd)
63672 {
63673 return nd->saved_names[nd->depth];
63674 }
63675 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63676 index a848ffc..3bbbaee 100644
63677 --- a/include/linux/netdevice.h
63678 +++ b/include/linux/netdevice.h
63679 @@ -999,6 +999,7 @@ struct net_device_ops {
63680 struct net_device *dev,
63681 int idx);
63682 };
63683 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63684
63685 /*
63686 * The DEVICE structure.
63687 @@ -1059,7 +1060,7 @@ struct net_device {
63688 int iflink;
63689
63690 struct net_device_stats stats;
63691 - atomic_long_t rx_dropped; /* dropped packets by core network
63692 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63693 * Do not use this in drivers.
63694 */
63695
63696 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63697 new file mode 100644
63698 index 0000000..33f4af8
63699 --- /dev/null
63700 +++ b/include/linux/netfilter/xt_gradm.h
63701 @@ -0,0 +1,9 @@
63702 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63703 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63704 +
63705 +struct xt_gradm_mtinfo {
63706 + __u16 flags;
63707 + __u16 invflags;
63708 +};
63709 +
63710 +#endif
63711 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63712 index c65a18a..0c05f3a 100644
63713 --- a/include/linux/of_pdt.h
63714 +++ b/include/linux/of_pdt.h
63715 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63716
63717 /* return 0 on success; fill in 'len' with number of bytes in path */
63718 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63719 -};
63720 +} __no_const;
63721
63722 extern void *prom_early_alloc(unsigned long size);
63723
63724 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63725 index a4c5624..79d6d88 100644
63726 --- a/include/linux/oprofile.h
63727 +++ b/include/linux/oprofile.h
63728 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63729 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63730 char const * name, ulong * val);
63731
63732 -/** Create a file for read-only access to an atomic_t. */
63733 +/** Create a file for read-only access to an atomic_unchecked_t. */
63734 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63735 - char const * name, atomic_t * val);
63736 + char const * name, atomic_unchecked_t * val);
63737
63738 /** create a directory */
63739 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63740 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63741 index 6bfb2faa..1204767 100644
63742 --- a/include/linux/perf_event.h
63743 +++ b/include/linux/perf_event.h
63744 @@ -328,8 +328,8 @@ struct perf_event {
63745
63746 enum perf_event_active_state state;
63747 unsigned int attach_state;
63748 - local64_t count;
63749 - atomic64_t child_count;
63750 + local64_t count; /* PaX: fix it one day */
63751 + atomic64_unchecked_t child_count;
63752
63753 /*
63754 * These are the total time in nanoseconds that the event
63755 @@ -380,8 +380,8 @@ struct perf_event {
63756 * These accumulate total time (in nanoseconds) that children
63757 * events have been enabled and running, respectively.
63758 */
63759 - atomic64_t child_total_time_enabled;
63760 - atomic64_t child_total_time_running;
63761 + atomic64_unchecked_t child_total_time_enabled;
63762 + atomic64_unchecked_t child_total_time_running;
63763
63764 /*
63765 * Protect attach/detach and child_list:
63766 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63767 index ad1a427..6419649 100644
63768 --- a/include/linux/pipe_fs_i.h
63769 +++ b/include/linux/pipe_fs_i.h
63770 @@ -45,9 +45,9 @@ struct pipe_buffer {
63771 struct pipe_inode_info {
63772 wait_queue_head_t wait;
63773 unsigned int nrbufs, curbuf, buffers;
63774 - unsigned int readers;
63775 - unsigned int writers;
63776 - unsigned int waiting_writers;
63777 + atomic_t readers;
63778 + atomic_t writers;
63779 + atomic_t waiting_writers;
63780 unsigned int r_counter;
63781 unsigned int w_counter;
63782 struct page *tmp_page;
63783 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
63784 index 5f28cae..3d23723 100644
63785 --- a/include/linux/platform_data/usb-ehci-s5p.h
63786 +++ b/include/linux/platform_data/usb-ehci-s5p.h
63787 @@ -14,7 +14,7 @@
63788 struct s5p_ehci_platdata {
63789 int (*phy_init)(struct platform_device *pdev, int type);
63790 int (*phy_exit)(struct platform_device *pdev, int type);
63791 -};
63792 +} __no_const;
63793
63794 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
63795
63796 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63797 index f271860..6b3bec5 100644
63798 --- a/include/linux/pm_runtime.h
63799 +++ b/include/linux/pm_runtime.h
63800 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63801
63802 static inline void pm_runtime_mark_last_busy(struct device *dev)
63803 {
63804 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63805 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63806 }
63807
63808 #else /* !CONFIG_PM_RUNTIME */
63809 diff --git a/include/linux/poison.h b/include/linux/poison.h
63810 index 2110a81..13a11bb 100644
63811 --- a/include/linux/poison.h
63812 +++ b/include/linux/poison.h
63813 @@ -19,8 +19,8 @@
63814 * under normal circumstances, used to verify that nobody uses
63815 * non-initialized list entries.
63816 */
63817 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63818 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63819 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63820 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63821
63822 /********** include/linux/timer.h **********/
63823 /*
63824 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63825 index 5a710b9..0b0dab9 100644
63826 --- a/include/linux/preempt.h
63827 +++ b/include/linux/preempt.h
63828 @@ -126,7 +126,7 @@ struct preempt_ops {
63829 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63830 void (*sched_out)(struct preempt_notifier *notifier,
63831 struct task_struct *next);
63832 -};
63833 +} __no_const;
63834
63835 /**
63836 * preempt_notifier - key for installing preemption notifiers
63837 diff --git a/include/linux/printk.h b/include/linux/printk.h
63838 index 9afc01e..92c32e8 100644
63839 --- a/include/linux/printk.h
63840 +++ b/include/linux/printk.h
63841 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63842 extern int printk_needs_cpu(int cpu);
63843 extern void printk_tick(void);
63844
63845 +extern int kptr_restrict;
63846 +
63847 #ifdef CONFIG_PRINTK
63848 asmlinkage __printf(5, 0)
63849 int vprintk_emit(int facility, int level,
63850 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63851
63852 extern int printk_delay_msec;
63853 extern int dmesg_restrict;
63854 -extern int kptr_restrict;
63855
63856 void log_buf_kexec_setup(void);
63857 void __init setup_log_buf(int early);
63858 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63859 index 3fd2e87..d93a721 100644
63860 --- a/include/linux/proc_fs.h
63861 +++ b/include/linux/proc_fs.h
63862 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63863 return proc_create_data(name, mode, parent, proc_fops, NULL);
63864 }
63865
63866 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63867 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63868 +{
63869 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63870 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63871 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63872 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63873 +#else
63874 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63875 +#endif
63876 +}
63877 +
63878 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63879 umode_t mode, struct proc_dir_entry *base,
63880 read_proc_t *read_proc, void * data)
63881 @@ -258,7 +270,7 @@ union proc_op {
63882 int (*proc_show)(struct seq_file *m,
63883 struct pid_namespace *ns, struct pid *pid,
63884 struct task_struct *task);
63885 -};
63886 +} __no_const;
63887
63888 struct ctl_table_header;
63889 struct ctl_table;
63890 diff --git a/include/linux/random.h b/include/linux/random.h
63891 index 6330ed4..6faf63b 100644
63892 --- a/include/linux/random.h
63893 +++ b/include/linux/random.h
63894 @@ -14,6 +14,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63895 unsigned int value);
63896 extern void add_interrupt_randomness(int irq, int irq_flags);
63897
63898 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63899 +extern void transfer_latent_entropy(void);
63900 +#endif
63901 +
63902 extern void get_random_bytes(void *buf, int nbytes);
63903 extern void get_random_bytes_arch(void *buf, int nbytes);
63904 void generate_random_uuid(unsigned char uuid_out[16]);
63905 @@ -30,12 +34,17 @@ void srandom32(u32 seed);
63906
63907 u32 prandom32(struct rnd_state *);
63908
63909 +static inline unsigned long pax_get_random_long(void)
63910 +{
63911 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63912 +}
63913 +
63914 /*
63915 * Handle minimum values for seeds
63916 */
63917 static inline u32 __seed(u32 x, u32 m)
63918 {
63919 - return (x < m) ? x + m : x;
63920 + return (x <= m) ? x + m + 1 : x;
63921 }
63922
63923 /**
63924 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63925 index 23b3630..e1bc12b 100644
63926 --- a/include/linux/reboot.h
63927 +++ b/include/linux/reboot.h
63928 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63929 * Architecture-specific implementations of sys_reboot commands.
63930 */
63931
63932 -extern void machine_restart(char *cmd);
63933 -extern void machine_halt(void);
63934 -extern void machine_power_off(void);
63935 +extern void machine_restart(char *cmd) __noreturn;
63936 +extern void machine_halt(void) __noreturn;
63937 +extern void machine_power_off(void) __noreturn;
63938
63939 extern void machine_shutdown(void);
63940 struct pt_regs;
63941 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63942 */
63943
63944 extern void kernel_restart_prepare(char *cmd);
63945 -extern void kernel_restart(char *cmd);
63946 -extern void kernel_halt(void);
63947 -extern void kernel_power_off(void);
63948 +extern void kernel_restart(char *cmd) __noreturn;
63949 +extern void kernel_halt(void) __noreturn;
63950 +extern void kernel_power_off(void) __noreturn;
63951
63952 extern int C_A_D; /* for sysctl */
63953 void ctrl_alt_del(void);
63954 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
63955 * Emergency restart, callable from an interrupt handler.
63956 */
63957
63958 -extern void emergency_restart(void);
63959 +extern void emergency_restart(void) __noreturn;
63960 #include <asm/emergency-restart.h>
63961
63962 #endif /* _LINUX_REBOOT_H */
63963 diff --git a/include/linux/relay.h b/include/linux/relay.h
63964 index 91cacc3..b55ff74 100644
63965 --- a/include/linux/relay.h
63966 +++ b/include/linux/relay.h
63967 @@ -160,7 +160,7 @@ struct rchan_callbacks
63968 * The callback should return 0 if successful, negative if not.
63969 */
63970 int (*remove_buf_file)(struct dentry *dentry);
63971 -};
63972 +} __no_const;
63973
63974 /*
63975 * CONFIG_RELAY kernel API, kernel/relay.c
63976 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63977 index d901078..0b7d00e 100644
63978 --- a/include/linux/rfkill.h
63979 +++ b/include/linux/rfkill.h
63980 @@ -63,6 +63,7 @@ struct rfkill_ops {
63981 void (*query)(struct rfkill *rfkill, void *data);
63982 int (*set_block)(void *data, bool blocked);
63983 };
63984 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63985
63986 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63987 /**
63988 diff --git a/include/linux/rio.h b/include/linux/rio.h
63989 index a3e7842..d973ca6 100644
63990 --- a/include/linux/rio.h
63991 +++ b/include/linux/rio.h
63992 @@ -339,7 +339,7 @@ struct rio_ops {
63993 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
63994 u64 rstart, u32 size, u32 flags);
63995 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
63996 -};
63997 +} __no_const;
63998
63999 #define RIO_RESOURCE_MEM 0x00000100
64000 #define RIO_RESOURCE_DOORBELL 0x00000200
64001 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64002 index bfe1f47..6a33ee3 100644
64003 --- a/include/linux/rmap.h
64004 +++ b/include/linux/rmap.h
64005 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64006 void anon_vma_init(void); /* create anon_vma_cachep */
64007 int anon_vma_prepare(struct vm_area_struct *);
64008 void unlink_anon_vmas(struct vm_area_struct *);
64009 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64010 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64011 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64012 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64013
64014 static inline void anon_vma_merge(struct vm_area_struct *vma,
64015 struct vm_area_struct *next)
64016 diff --git a/include/linux/sched.h b/include/linux/sched.h
64017 index 0dd42a0..cc9bffb 100644
64018 --- a/include/linux/sched.h
64019 +++ b/include/linux/sched.h
64020 @@ -61,6 +61,7 @@ struct bio_list;
64021 struct fs_struct;
64022 struct perf_event_context;
64023 struct blk_plug;
64024 +struct linux_binprm;
64025
64026 /*
64027 * List of flags we want to share for kernel threads,
64028 @@ -344,10 +345,13 @@ struct user_namespace;
64029 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64030
64031 extern int sysctl_max_map_count;
64032 +extern unsigned long sysctl_heap_stack_gap;
64033
64034 #include <linux/aio.h>
64035
64036 #ifdef CONFIG_MMU
64037 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64038 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64039 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64040 extern unsigned long
64041 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64042 @@ -614,6 +618,17 @@ struct signal_struct {
64043 #ifdef CONFIG_TASKSTATS
64044 struct taskstats *stats;
64045 #endif
64046 +
64047 +#ifdef CONFIG_GRKERNSEC
64048 + u32 curr_ip;
64049 + u32 saved_ip;
64050 + u32 gr_saddr;
64051 + u32 gr_daddr;
64052 + u16 gr_sport;
64053 + u16 gr_dport;
64054 + u8 used_accept:1;
64055 +#endif
64056 +
64057 #ifdef CONFIG_AUDIT
64058 unsigned audit_tty;
64059 struct tty_audit_buf *tty_audit_buf;
64060 @@ -691,6 +706,11 @@ struct user_struct {
64061 struct key *session_keyring; /* UID's default session keyring */
64062 #endif
64063
64064 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64065 + unsigned int banned;
64066 + unsigned long ban_expires;
64067 +#endif
64068 +
64069 /* Hash table maintenance information */
64070 struct hlist_node uidhash_node;
64071 kuid_t uid;
64072 @@ -1312,8 +1332,8 @@ struct task_struct {
64073 struct list_head thread_group;
64074
64075 struct completion *vfork_done; /* for vfork() */
64076 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64077 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64078 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64079 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64080
64081 cputime_t utime, stime, utimescaled, stimescaled;
64082 cputime_t gtime;
64083 @@ -1329,11 +1349,6 @@ struct task_struct {
64084 struct task_cputime cputime_expires;
64085 struct list_head cpu_timers[3];
64086
64087 -/* process credentials */
64088 - const struct cred __rcu *real_cred; /* objective and real subjective task
64089 - * credentials (COW) */
64090 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64091 - * credentials (COW) */
64092 char comm[TASK_COMM_LEN]; /* executable name excluding path
64093 - access with [gs]et_task_comm (which lock
64094 it with task_lock())
64095 @@ -1350,6 +1365,10 @@ struct task_struct {
64096 #endif
64097 /* CPU-specific state of this task */
64098 struct thread_struct thread;
64099 +/* thread_info moved to task_struct */
64100 +#ifdef CONFIG_X86
64101 + struct thread_info tinfo;
64102 +#endif
64103 /* filesystem information */
64104 struct fs_struct *fs;
64105 /* open file information */
64106 @@ -1423,6 +1442,10 @@ struct task_struct {
64107 gfp_t lockdep_reclaim_gfp;
64108 #endif
64109
64110 +/* process credentials */
64111 + const struct cred __rcu *real_cred; /* objective and real subjective task
64112 + * credentials (COW) */
64113 +
64114 /* journalling filesystem info */
64115 void *journal_info;
64116
64117 @@ -1461,6 +1484,10 @@ struct task_struct {
64118 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64119 struct list_head cg_list;
64120 #endif
64121 +
64122 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64123 + * credentials (COW) */
64124 +
64125 #ifdef CONFIG_FUTEX
64126 struct robust_list_head __user *robust_list;
64127 #ifdef CONFIG_COMPAT
64128 @@ -1548,8 +1575,75 @@ struct task_struct {
64129 #ifdef CONFIG_UPROBES
64130 struct uprobe_task *utask;
64131 #endif
64132 +
64133 +#ifdef CONFIG_GRKERNSEC
64134 + /* grsecurity */
64135 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64136 + u64 exec_id;
64137 +#endif
64138 +#ifdef CONFIG_GRKERNSEC_SETXID
64139 + const struct cred *delayed_cred;
64140 +#endif
64141 + struct dentry *gr_chroot_dentry;
64142 + struct acl_subject_label *acl;
64143 + struct acl_role_label *role;
64144 + struct file *exec_file;
64145 + unsigned long brute_expires;
64146 + u16 acl_role_id;
64147 + /* is this the task that authenticated to the special role */
64148 + u8 acl_sp_role;
64149 + u8 is_writable;
64150 + u8 brute;
64151 + u8 gr_is_chrooted;
64152 +#endif
64153 +
64154 };
64155
64156 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64157 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64158 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64159 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64160 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64161 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64162 +
64163 +#ifdef CONFIG_PAX_SOFTMODE
64164 +extern int pax_softmode;
64165 +#endif
64166 +
64167 +extern int pax_check_flags(unsigned long *);
64168 +
64169 +/* if tsk != current then task_lock must be held on it */
64170 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64171 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64172 +{
64173 + if (likely(tsk->mm))
64174 + return tsk->mm->pax_flags;
64175 + else
64176 + return 0UL;
64177 +}
64178 +
64179 +/* if tsk != current then task_lock must be held on it */
64180 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64181 +{
64182 + if (likely(tsk->mm)) {
64183 + tsk->mm->pax_flags = flags;
64184 + return 0;
64185 + }
64186 + return -EINVAL;
64187 +}
64188 +#endif
64189 +
64190 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64191 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64192 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64193 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64194 +#endif
64195 +
64196 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64197 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64198 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64199 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64200 +
64201 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64202 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64203
64204 @@ -2092,7 +2186,9 @@ void yield(void);
64205 extern struct exec_domain default_exec_domain;
64206
64207 union thread_union {
64208 +#ifndef CONFIG_X86
64209 struct thread_info thread_info;
64210 +#endif
64211 unsigned long stack[THREAD_SIZE/sizeof(long)];
64212 };
64213
64214 @@ -2125,6 +2221,7 @@ extern struct pid_namespace init_pid_ns;
64215 */
64216
64217 extern struct task_struct *find_task_by_vpid(pid_t nr);
64218 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64219 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64220 struct pid_namespace *ns);
64221
64222 @@ -2281,7 +2378,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64223 extern void exit_itimers(struct signal_struct *);
64224 extern void flush_itimer_signals(void);
64225
64226 -extern void do_group_exit(int);
64227 +extern __noreturn void do_group_exit(int);
64228
64229 extern void daemonize(const char *, ...);
64230 extern int allow_signal(int);
64231 @@ -2485,9 +2582,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64232
64233 #endif
64234
64235 -static inline int object_is_on_stack(void *obj)
64236 +static inline int object_starts_on_stack(void *obj)
64237 {
64238 - void *stack = task_stack_page(current);
64239 + const void *stack = task_stack_page(current);
64240
64241 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64242 }
64243 diff --git a/include/linux/security.h b/include/linux/security.h
64244 index 05e88bd..5cda002 100644
64245 --- a/include/linux/security.h
64246 +++ b/include/linux/security.h
64247 @@ -26,6 +26,7 @@
64248 #include <linux/capability.h>
64249 #include <linux/slab.h>
64250 #include <linux/err.h>
64251 +#include <linux/grsecurity.h>
64252
64253 struct linux_binprm;
64254 struct cred;
64255 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64256 index 68a04a3..866e6a1 100644
64257 --- a/include/linux/seq_file.h
64258 +++ b/include/linux/seq_file.h
64259 @@ -26,6 +26,9 @@ struct seq_file {
64260 struct mutex lock;
64261 const struct seq_operations *op;
64262 int poll_event;
64263 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64264 + u64 exec_id;
64265 +#endif
64266 #ifdef CONFIG_USER_NS
64267 struct user_namespace *user_ns;
64268 #endif
64269 @@ -38,6 +41,7 @@ struct seq_operations {
64270 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64271 int (*show) (struct seq_file *m, void *v);
64272 };
64273 +typedef struct seq_operations __no_const seq_operations_no_const;
64274
64275 #define SEQ_SKIP 1
64276
64277 diff --git a/include/linux/shm.h b/include/linux/shm.h
64278 index bcf8a6a..4d0af77 100644
64279 --- a/include/linux/shm.h
64280 +++ b/include/linux/shm.h
64281 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
64282
64283 /* The task created the shm object. NULL if the task is dead. */
64284 struct task_struct *shm_creator;
64285 +#ifdef CONFIG_GRKERNSEC
64286 + time_t shm_createtime;
64287 + pid_t shm_lapid;
64288 +#endif
64289 };
64290
64291 /* shm_mode upper byte flags */
64292 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64293 index 6a2c34e..a1f320f 100644
64294 --- a/include/linux/skbuff.h
64295 +++ b/include/linux/skbuff.h
64296 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64297 extern struct sk_buff *__alloc_skb(unsigned int size,
64298 gfp_t priority, int flags, int node);
64299 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64300 -static inline struct sk_buff *alloc_skb(unsigned int size,
64301 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64302 gfp_t priority)
64303 {
64304 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64305 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64306 */
64307 static inline int skb_queue_empty(const struct sk_buff_head *list)
64308 {
64309 - return list->next == (struct sk_buff *)list;
64310 + return list->next == (const struct sk_buff *)list;
64311 }
64312
64313 /**
64314 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64315 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64316 const struct sk_buff *skb)
64317 {
64318 - return skb->next == (struct sk_buff *)list;
64319 + return skb->next == (const struct sk_buff *)list;
64320 }
64321
64322 /**
64323 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64324 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64325 const struct sk_buff *skb)
64326 {
64327 - return skb->prev == (struct sk_buff *)list;
64328 + return skb->prev == (const struct sk_buff *)list;
64329 }
64330
64331 /**
64332 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64333 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64334 */
64335 #ifndef NET_SKB_PAD
64336 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64337 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64338 #endif
64339
64340 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64341 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64342 int noblock, int *err);
64343 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64344 struct poll_table_struct *wait);
64345 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64346 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64347 int offset, struct iovec *to,
64348 int size);
64349 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64350 diff --git a/include/linux/slab.h b/include/linux/slab.h
64351 index 83d1a14..cbce507 100644
64352 --- a/include/linux/slab.h
64353 +++ b/include/linux/slab.h
64354 @@ -11,12 +11,20 @@
64355
64356 #include <linux/gfp.h>
64357 #include <linux/types.h>
64358 +#include <linux/err.h>
64359
64360 /*
64361 * Flags to pass to kmem_cache_create().
64362 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64363 */
64364 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64365 +
64366 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64367 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64368 +#else
64369 +#define SLAB_USERCOPY 0x00000000UL
64370 +#endif
64371 +
64372 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64373 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64374 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64375 @@ -87,10 +95,13 @@
64376 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64377 * Both make kfree a no-op.
64378 */
64379 -#define ZERO_SIZE_PTR ((void *)16)
64380 +#define ZERO_SIZE_PTR \
64381 +({ \
64382 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64383 + (void *)(-MAX_ERRNO-1L); \
64384 +})
64385
64386 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64387 - (unsigned long)ZERO_SIZE_PTR)
64388 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64389
64390 /*
64391 * Common fields provided in kmem_cache by all slab allocators
64392 @@ -110,7 +121,7 @@ struct kmem_cache {
64393 unsigned int align; /* Alignment as calculated */
64394 unsigned long flags; /* Active flags on the slab */
64395 const char *name; /* Slab name for sysfs */
64396 - int refcount; /* Use counter */
64397 + atomic_t refcount; /* Use counter */
64398 void (*ctor)(void *); /* Called on object slot creation */
64399 struct list_head list; /* List of all slab caches on the system */
64400 };
64401 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64402 void kfree(const void *);
64403 void kzfree(const void *);
64404 size_t ksize(const void *);
64405 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64406 +bool is_usercopy_object(const void *ptr);
64407
64408 /*
64409 * Allocator specific definitions. These are mainly used to establish optimized
64410 @@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64411 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64412 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
64413 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
64414 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64415 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64416 #define kmalloc_track_caller(size, flags) \
64417 __kmalloc_track_caller(size, flags, _RET_IP_)
64418 #else
64419 @@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64420 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64421 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
64422 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
64423 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64424 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64425 #define kmalloc_node_track_caller(size, flags, node) \
64426 __kmalloc_node_track_caller(size, flags, node, \
64427 _RET_IP_)
64428 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64429 index cc290f0..0ba60931 100644
64430 --- a/include/linux/slab_def.h
64431 +++ b/include/linux/slab_def.h
64432 @@ -52,7 +52,7 @@ struct kmem_cache {
64433 /* 4) cache creation/removal */
64434 const char *name;
64435 struct list_head list;
64436 - int refcount;
64437 + atomic_t refcount;
64438 int object_size;
64439 int align;
64440
64441 @@ -68,10 +68,10 @@ struct kmem_cache {
64442 unsigned long node_allocs;
64443 unsigned long node_frees;
64444 unsigned long node_overflow;
64445 - atomic_t allochit;
64446 - atomic_t allocmiss;
64447 - atomic_t freehit;
64448 - atomic_t freemiss;
64449 + atomic_unchecked_t allochit;
64450 + atomic_unchecked_t allocmiss;
64451 + atomic_unchecked_t freehit;
64452 + atomic_unchecked_t freemiss;
64453
64454 /*
64455 * If debugging is enabled, then the allocator can add additional
64456 @@ -104,11 +104,16 @@ struct cache_sizes {
64457 #ifdef CONFIG_ZONE_DMA
64458 struct kmem_cache *cs_dmacachep;
64459 #endif
64460 +
64461 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64462 + struct kmem_cache *cs_usercopycachep;
64463 +#endif
64464 +
64465 };
64466 extern struct cache_sizes malloc_sizes[];
64467
64468 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64469 -void *__kmalloc(size_t size, gfp_t flags);
64470 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64471
64472 #ifdef CONFIG_TRACING
64473 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
64474 @@ -145,6 +150,13 @@ found:
64475 cachep = malloc_sizes[i].cs_dmacachep;
64476 else
64477 #endif
64478 +
64479 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64480 + if (flags & GFP_USERCOPY)
64481 + cachep = malloc_sizes[i].cs_usercopycachep;
64482 + else
64483 +#endif
64484 +
64485 cachep = malloc_sizes[i].cs_cachep;
64486
64487 ret = kmem_cache_alloc_trace(cachep, flags, size);
64488 @@ -155,7 +167,7 @@ found:
64489 }
64490
64491 #ifdef CONFIG_NUMA
64492 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64493 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64494 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64495
64496 #ifdef CONFIG_TRACING
64497 @@ -198,6 +210,13 @@ found:
64498 cachep = malloc_sizes[i].cs_dmacachep;
64499 else
64500 #endif
64501 +
64502 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64503 + if (flags & GFP_USERCOPY)
64504 + cachep = malloc_sizes[i].cs_usercopycachep;
64505 + else
64506 +#endif
64507 +
64508 cachep = malloc_sizes[i].cs_cachep;
64509
64510 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
64511 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64512 index f28e14a..7831211 100644
64513 --- a/include/linux/slob_def.h
64514 +++ b/include/linux/slob_def.h
64515 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64516 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
64517 }
64518
64519 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64520 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64521
64522 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64523 {
64524 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64525 return __kmalloc_node(size, flags, NUMA_NO_NODE);
64526 }
64527
64528 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64529 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64530 {
64531 return kmalloc(size, flags);
64532 }
64533 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64534 index df448ad..b99e7f6 100644
64535 --- a/include/linux/slub_def.h
64536 +++ b/include/linux/slub_def.h
64537 @@ -91,7 +91,7 @@ struct kmem_cache {
64538 struct kmem_cache_order_objects max;
64539 struct kmem_cache_order_objects min;
64540 gfp_t allocflags; /* gfp flags to use on each alloc */
64541 - int refcount; /* Refcount for slab cache destroy */
64542 + atomic_t refcount; /* Refcount for slab cache destroy */
64543 void (*ctor)(void *);
64544 int inuse; /* Offset to metadata */
64545 int align; /* Alignment */
64546 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64547 * Sorry that the following has to be that ugly but some versions of GCC
64548 * have trouble with constant propagation and loops.
64549 */
64550 -static __always_inline int kmalloc_index(size_t size)
64551 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64552 {
64553 if (!size)
64554 return 0;
64555 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64556 }
64557
64558 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64559 -void *__kmalloc(size_t size, gfp_t flags);
64560 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64561
64562 static __always_inline void *
64563 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64564 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64565 }
64566 #endif
64567
64568 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64569 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64570 {
64571 unsigned int order = get_order(size);
64572 return kmalloc_order_trace(size, flags, order);
64573 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64574 }
64575
64576 #ifdef CONFIG_NUMA
64577 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64578 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64579 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64580
64581 #ifdef CONFIG_TRACING
64582 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64583 index 680f9a3..f13aeb0 100644
64584 --- a/include/linux/sonet.h
64585 +++ b/include/linux/sonet.h
64586 @@ -7,7 +7,7 @@
64587 #include <uapi/linux/sonet.h>
64588
64589 struct k_sonet_stats {
64590 -#define __HANDLE_ITEM(i) atomic_t i
64591 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64592 __SONET_ITEMS
64593 #undef __HANDLE_ITEM
64594 };
64595 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64596 index 34206b8..f019e06 100644
64597 --- a/include/linux/sunrpc/clnt.h
64598 +++ b/include/linux/sunrpc/clnt.h
64599 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64600 {
64601 switch (sap->sa_family) {
64602 case AF_INET:
64603 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64604 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64605 case AF_INET6:
64606 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64607 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64608 }
64609 return 0;
64610 }
64611 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64612 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64613 const struct sockaddr *src)
64614 {
64615 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64616 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64617 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64618
64619 dsin->sin_family = ssin->sin_family;
64620 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64621 if (sa->sa_family != AF_INET6)
64622 return 0;
64623
64624 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64625 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64626 }
64627
64628 #endif /* __KERNEL__ */
64629 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64630 index dc0c3cc..8503fb6 100644
64631 --- a/include/linux/sunrpc/sched.h
64632 +++ b/include/linux/sunrpc/sched.h
64633 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64634 void (*rpc_count_stats)(struct rpc_task *, void *);
64635 void (*rpc_release)(void *);
64636 };
64637 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64638
64639 struct rpc_task_setup {
64640 struct rpc_task *task;
64641 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64642 index 0b8e3e6..33e0a01 100644
64643 --- a/include/linux/sunrpc/svc_rdma.h
64644 +++ b/include/linux/sunrpc/svc_rdma.h
64645 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64646 extern unsigned int svcrdma_max_requests;
64647 extern unsigned int svcrdma_max_req_size;
64648
64649 -extern atomic_t rdma_stat_recv;
64650 -extern atomic_t rdma_stat_read;
64651 -extern atomic_t rdma_stat_write;
64652 -extern atomic_t rdma_stat_sq_starve;
64653 -extern atomic_t rdma_stat_rq_starve;
64654 -extern atomic_t rdma_stat_rq_poll;
64655 -extern atomic_t rdma_stat_rq_prod;
64656 -extern atomic_t rdma_stat_sq_poll;
64657 -extern atomic_t rdma_stat_sq_prod;
64658 +extern atomic_unchecked_t rdma_stat_recv;
64659 +extern atomic_unchecked_t rdma_stat_read;
64660 +extern atomic_unchecked_t rdma_stat_write;
64661 +extern atomic_unchecked_t rdma_stat_sq_starve;
64662 +extern atomic_unchecked_t rdma_stat_rq_starve;
64663 +extern atomic_unchecked_t rdma_stat_rq_poll;
64664 +extern atomic_unchecked_t rdma_stat_rq_prod;
64665 +extern atomic_unchecked_t rdma_stat_sq_poll;
64666 +extern atomic_unchecked_t rdma_stat_sq_prod;
64667
64668 #define RPCRDMA_VERSION 1
64669
64670 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64671 index cd844a6..3ca3592 100644
64672 --- a/include/linux/sysctl.h
64673 +++ b/include/linux/sysctl.h
64674 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64675
64676 extern int proc_dostring(struct ctl_table *, int,
64677 void __user *, size_t *, loff_t *);
64678 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64679 + void __user *, size_t *, loff_t *);
64680 extern int proc_dointvec(struct ctl_table *, int,
64681 void __user *, size_t *, loff_t *);
64682 extern int proc_dointvec_minmax(struct ctl_table *, int,
64683 diff --git a/include/linux/tty.h b/include/linux/tty.h
64684 index f0b4eb4..1c4854e 100644
64685 --- a/include/linux/tty.h
64686 +++ b/include/linux/tty.h
64687 @@ -192,7 +192,7 @@ struct tty_port {
64688 const struct tty_port_operations *ops; /* Port operations */
64689 spinlock_t lock; /* Lock protecting tty field */
64690 int blocked_open; /* Waiting to open */
64691 - int count; /* Usage count */
64692 + atomic_t count; /* Usage count */
64693 wait_queue_head_t open_wait; /* Open waiters */
64694 wait_queue_head_t close_wait; /* Close waiters */
64695 wait_queue_head_t delta_msr_wait; /* Modem status change */
64696 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
64697 struct tty_struct *tty, struct file *filp);
64698 static inline int tty_port_users(struct tty_port *port)
64699 {
64700 - return port->count + port->blocked_open;
64701 + return atomic_read(&port->count) + port->blocked_open;
64702 }
64703
64704 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64705 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64706 index fb79dd8d..07d4773 100644
64707 --- a/include/linux/tty_ldisc.h
64708 +++ b/include/linux/tty_ldisc.h
64709 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64710
64711 struct module *owner;
64712
64713 - int refcount;
64714 + atomic_t refcount;
64715 };
64716
64717 struct tty_ldisc {
64718 diff --git a/include/linux/types.h b/include/linux/types.h
64719 index 1cc0e4b..0d50edf 100644
64720 --- a/include/linux/types.h
64721 +++ b/include/linux/types.h
64722 @@ -175,10 +175,26 @@ typedef struct {
64723 int counter;
64724 } atomic_t;
64725
64726 +#ifdef CONFIG_PAX_REFCOUNT
64727 +typedef struct {
64728 + int counter;
64729 +} atomic_unchecked_t;
64730 +#else
64731 +typedef atomic_t atomic_unchecked_t;
64732 +#endif
64733 +
64734 #ifdef CONFIG_64BIT
64735 typedef struct {
64736 long counter;
64737 } atomic64_t;
64738 +
64739 +#ifdef CONFIG_PAX_REFCOUNT
64740 +typedef struct {
64741 + long counter;
64742 +} atomic64_unchecked_t;
64743 +#else
64744 +typedef atomic64_t atomic64_unchecked_t;
64745 +#endif
64746 #endif
64747
64748 struct list_head {
64749 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64750 index 5ca0951..ab496a5 100644
64751 --- a/include/linux/uaccess.h
64752 +++ b/include/linux/uaccess.h
64753 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64754 long ret; \
64755 mm_segment_t old_fs = get_fs(); \
64756 \
64757 - set_fs(KERNEL_DS); \
64758 pagefault_disable(); \
64759 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64760 - pagefault_enable(); \
64761 + set_fs(KERNEL_DS); \
64762 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64763 set_fs(old_fs); \
64764 + pagefault_enable(); \
64765 ret; \
64766 })
64767
64768 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64769 index 99c1b4d..bb94261 100644
64770 --- a/include/linux/unaligned/access_ok.h
64771 +++ b/include/linux/unaligned/access_ok.h
64772 @@ -6,32 +6,32 @@
64773
64774 static inline u16 get_unaligned_le16(const void *p)
64775 {
64776 - return le16_to_cpup((__le16 *)p);
64777 + return le16_to_cpup((const __le16 *)p);
64778 }
64779
64780 static inline u32 get_unaligned_le32(const void *p)
64781 {
64782 - return le32_to_cpup((__le32 *)p);
64783 + return le32_to_cpup((const __le32 *)p);
64784 }
64785
64786 static inline u64 get_unaligned_le64(const void *p)
64787 {
64788 - return le64_to_cpup((__le64 *)p);
64789 + return le64_to_cpup((const __le64 *)p);
64790 }
64791
64792 static inline u16 get_unaligned_be16(const void *p)
64793 {
64794 - return be16_to_cpup((__be16 *)p);
64795 + return be16_to_cpup((const __be16 *)p);
64796 }
64797
64798 static inline u32 get_unaligned_be32(const void *p)
64799 {
64800 - return be32_to_cpup((__be32 *)p);
64801 + return be32_to_cpup((const __be32 *)p);
64802 }
64803
64804 static inline u64 get_unaligned_be64(const void *p)
64805 {
64806 - return be64_to_cpup((__be64 *)p);
64807 + return be64_to_cpup((const __be64 *)p);
64808 }
64809
64810 static inline void put_unaligned_le16(u16 val, void *p)
64811 diff --git a/include/linux/usb.h b/include/linux/usb.h
64812 index 10278d1..e21ec3c 100644
64813 --- a/include/linux/usb.h
64814 +++ b/include/linux/usb.h
64815 @@ -551,7 +551,7 @@ struct usb_device {
64816 int maxchild;
64817
64818 u32 quirks;
64819 - atomic_t urbnum;
64820 + atomic_unchecked_t urbnum;
64821
64822 unsigned long active_duration;
64823
64824 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64825 index c5d36c6..8478c90 100644
64826 --- a/include/linux/usb/renesas_usbhs.h
64827 +++ b/include/linux/usb/renesas_usbhs.h
64828 @@ -39,7 +39,7 @@ enum {
64829 */
64830 struct renesas_usbhs_driver_callback {
64831 int (*notify_hotplug)(struct platform_device *pdev);
64832 -};
64833 +} __no_const;
64834
64835 /*
64836 * callback functions for platform
64837 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64838 * VBUS control is needed for Host
64839 */
64840 int (*set_vbus)(struct platform_device *pdev, int enable);
64841 -};
64842 +} __no_const;
64843
64844 /*
64845 * parameters for renesas usbhs
64846 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64847 index 6f8fbcf..8259001 100644
64848 --- a/include/linux/vermagic.h
64849 +++ b/include/linux/vermagic.h
64850 @@ -25,9 +25,35 @@
64851 #define MODULE_ARCH_VERMAGIC ""
64852 #endif
64853
64854 +#ifdef CONFIG_PAX_REFCOUNT
64855 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64856 +#else
64857 +#define MODULE_PAX_REFCOUNT ""
64858 +#endif
64859 +
64860 +#ifdef CONSTIFY_PLUGIN
64861 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64862 +#else
64863 +#define MODULE_CONSTIFY_PLUGIN ""
64864 +#endif
64865 +
64866 +#ifdef STACKLEAK_PLUGIN
64867 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64868 +#else
64869 +#define MODULE_STACKLEAK_PLUGIN ""
64870 +#endif
64871 +
64872 +#ifdef CONFIG_GRKERNSEC
64873 +#define MODULE_GRSEC "GRSEC "
64874 +#else
64875 +#define MODULE_GRSEC ""
64876 +#endif
64877 +
64878 #define VERMAGIC_STRING \
64879 UTS_RELEASE " " \
64880 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64881 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64882 - MODULE_ARCH_VERMAGIC
64883 + MODULE_ARCH_VERMAGIC \
64884 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64885 + MODULE_GRSEC
64886
64887 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64888 index 6071e91..ca6a489 100644
64889 --- a/include/linux/vmalloc.h
64890 +++ b/include/linux/vmalloc.h
64891 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64892 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64893 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64894 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64895 +
64896 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64897 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64898 +#endif
64899 +
64900 /* bits [20..32] reserved for arch specific ioremap internals */
64901
64902 /*
64903 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64904 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64905 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64906 unsigned long start, unsigned long end, gfp_t gfp_mask,
64907 - pgprot_t prot, int node, const void *caller);
64908 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64909 extern void vfree(const void *addr);
64910
64911 extern void *vmap(struct page **pages, unsigned int count,
64912 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64913 extern void free_vm_area(struct vm_struct *area);
64914
64915 /* for /dev/kmem */
64916 -extern long vread(char *buf, char *addr, unsigned long count);
64917 -extern long vwrite(char *buf, char *addr, unsigned long count);
64918 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64919 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64920
64921 /*
64922 * Internals. Dont't use..
64923 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64924 index 92a86b2..1d9eb3c 100644
64925 --- a/include/linux/vmstat.h
64926 +++ b/include/linux/vmstat.h
64927 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64928 /*
64929 * Zone based page accounting with per cpu differentials.
64930 */
64931 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64932 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64933
64934 static inline void zone_page_state_add(long x, struct zone *zone,
64935 enum zone_stat_item item)
64936 {
64937 - atomic_long_add(x, &zone->vm_stat[item]);
64938 - atomic_long_add(x, &vm_stat[item]);
64939 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64940 + atomic_long_add_unchecked(x, &vm_stat[item]);
64941 }
64942
64943 static inline unsigned long global_page_state(enum zone_stat_item item)
64944 {
64945 - long x = atomic_long_read(&vm_stat[item]);
64946 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64947 #ifdef CONFIG_SMP
64948 if (x < 0)
64949 x = 0;
64950 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64951 static inline unsigned long zone_page_state(struct zone *zone,
64952 enum zone_stat_item item)
64953 {
64954 - long x = atomic_long_read(&zone->vm_stat[item]);
64955 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64956 #ifdef CONFIG_SMP
64957 if (x < 0)
64958 x = 0;
64959 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64960 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64961 enum zone_stat_item item)
64962 {
64963 - long x = atomic_long_read(&zone->vm_stat[item]);
64964 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64965
64966 #ifdef CONFIG_SMP
64967 int cpu;
64968 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64969
64970 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64971 {
64972 - atomic_long_inc(&zone->vm_stat[item]);
64973 - atomic_long_inc(&vm_stat[item]);
64974 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64975 + atomic_long_inc_unchecked(&vm_stat[item]);
64976 }
64977
64978 static inline void __inc_zone_page_state(struct page *page,
64979 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
64980
64981 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64982 {
64983 - atomic_long_dec(&zone->vm_stat[item]);
64984 - atomic_long_dec(&vm_stat[item]);
64985 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64986 + atomic_long_dec_unchecked(&vm_stat[item]);
64987 }
64988
64989 static inline void __dec_zone_page_state(struct page *page,
64990 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64991 index 944ecdf..a3994fc 100644
64992 --- a/include/media/saa7146_vv.h
64993 +++ b/include/media/saa7146_vv.h
64994 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64995 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64996
64997 /* the extension can override this */
64998 - struct v4l2_ioctl_ops vid_ops;
64999 - struct v4l2_ioctl_ops vbi_ops;
65000 + v4l2_ioctl_ops_no_const vid_ops;
65001 + v4l2_ioctl_ops_no_const vbi_ops;
65002 /* pointer to the saa7146 core ops */
65003 const struct v4l2_ioctl_ops *core_ops;
65004
65005 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65006 index 95d1c91..19a5d94 100644
65007 --- a/include/media/v4l2-dev.h
65008 +++ b/include/media/v4l2-dev.h
65009 @@ -76,7 +76,8 @@ struct v4l2_file_operations {
65010 int (*mmap) (struct file *, struct vm_area_struct *);
65011 int (*open) (struct file *);
65012 int (*release) (struct file *);
65013 -};
65014 +} __do_const;
65015 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65016
65017 /*
65018 * Newer version of video_device, handled by videodev2.c
65019 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65020 index e48b571..cec1748 100644
65021 --- a/include/media/v4l2-ioctl.h
65022 +++ b/include/media/v4l2-ioctl.h
65023 @@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
65024 long (*vidioc_default) (struct file *file, void *fh,
65025 bool valid_prio, int cmd, void *arg);
65026 };
65027 -
65028 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65029
65030 /* v4l debugging and diagnostics */
65031
65032 diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
65033 index ede0369..067cf12 100644
65034 --- a/include/net/bluetooth/bluetooth.h
65035 +++ b/include/net/bluetooth/bluetooth.h
65036 @@ -204,7 +204,7 @@ struct bt_sock_list {
65037 struct hlist_head head;
65038 rwlock_t lock;
65039 #ifdef CONFIG_PROC_FS
65040 - struct file_operations fops;
65041 + file_operations_no_const fops;
65042 int (* custom_seq_show)(struct seq_file *, void *);
65043 #endif
65044 };
65045 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65046 index bcb9cc3..f4ec722e 100644
65047 --- a/include/net/caif/caif_hsi.h
65048 +++ b/include/net/caif/caif_hsi.h
65049 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65050 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65051 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65052 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65053 -};
65054 +} __no_const;
65055
65056 /* Structure implemented by HSI device. */
65057 struct cfhsi_ops {
65058 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65059 index 9e5425b..8136ffc 100644
65060 --- a/include/net/caif/cfctrl.h
65061 +++ b/include/net/caif/cfctrl.h
65062 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65063 void (*radioset_rsp)(void);
65064 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65065 struct cflayer *client_layer);
65066 -};
65067 +} __no_const;
65068
65069 /* Link Setup Parameters for CAIF-Links. */
65070 struct cfctrl_link_param {
65071 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65072 struct cfctrl {
65073 struct cfsrvl serv;
65074 struct cfctrl_rsp res;
65075 - atomic_t req_seq_no;
65076 - atomic_t rsp_seq_no;
65077 + atomic_unchecked_t req_seq_no;
65078 + atomic_unchecked_t rsp_seq_no;
65079 struct list_head list;
65080 /* Protects from simultaneous access to first_req list */
65081 spinlock_t info_list_lock;
65082 diff --git a/include/net/flow.h b/include/net/flow.h
65083 index 628e11b..4c475df 100644
65084 --- a/include/net/flow.h
65085 +++ b/include/net/flow.h
65086 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65087
65088 extern void flow_cache_flush(void);
65089 extern void flow_cache_flush_deferred(void);
65090 -extern atomic_t flow_cache_genid;
65091 +extern atomic_unchecked_t flow_cache_genid;
65092
65093 #endif
65094 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
65095 index 4fd8a4b..123e31a 100644
65096 --- a/include/net/gro_cells.h
65097 +++ b/include/net/gro_cells.h
65098 @@ -30,7 +30,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
65099 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
65100
65101 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
65102 - atomic_long_inc(&dev->rx_dropped);
65103 + atomic_long_inc_unchecked(&dev->rx_dropped);
65104 kfree_skb(skb);
65105 return;
65106 }
65107 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65108 index 53f464d..ba76aaa 100644
65109 --- a/include/net/inetpeer.h
65110 +++ b/include/net/inetpeer.h
65111 @@ -47,8 +47,8 @@ struct inet_peer {
65112 */
65113 union {
65114 struct {
65115 - atomic_t rid; /* Frag reception counter */
65116 - atomic_t ip_id_count; /* IP ID for the next packet */
65117 + atomic_unchecked_t rid; /* Frag reception counter */
65118 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65119 };
65120 struct rcu_head rcu;
65121 struct inet_peer *gc_next;
65122 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65123 more++;
65124 inet_peer_refcheck(p);
65125 do {
65126 - old = atomic_read(&p->ip_id_count);
65127 + old = atomic_read_unchecked(&p->ip_id_count);
65128 new = old + more;
65129 if (!new)
65130 new = 1;
65131 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65132 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65133 return new;
65134 }
65135
65136 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65137 index 9497be1..5a4fafe 100644
65138 --- a/include/net/ip_fib.h
65139 +++ b/include/net/ip_fib.h
65140 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65141
65142 #define FIB_RES_SADDR(net, res) \
65143 ((FIB_RES_NH(res).nh_saddr_genid == \
65144 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65145 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65146 FIB_RES_NH(res).nh_saddr : \
65147 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65148 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65149 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65150 index ee75ccd..2cc2b95 100644
65151 --- a/include/net/ip_vs.h
65152 +++ b/include/net/ip_vs.h
65153 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65154 struct ip_vs_conn *control; /* Master control connection */
65155 atomic_t n_control; /* Number of controlled ones */
65156 struct ip_vs_dest *dest; /* real server */
65157 - atomic_t in_pkts; /* incoming packet counter */
65158 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65159
65160 /* packet transmitter for different forwarding methods. If it
65161 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65162 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65163 __be16 port; /* port number of the server */
65164 union nf_inet_addr addr; /* IP address of the server */
65165 volatile unsigned int flags; /* dest status flags */
65166 - atomic_t conn_flags; /* flags to copy to conn */
65167 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65168 atomic_t weight; /* server weight */
65169
65170 atomic_t refcnt; /* reference counter */
65171 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65172 index 69b610a..fe3962c 100644
65173 --- a/include/net/irda/ircomm_core.h
65174 +++ b/include/net/irda/ircomm_core.h
65175 @@ -51,7 +51,7 @@ typedef struct {
65176 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65177 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65178 struct ircomm_info *);
65179 -} call_t;
65180 +} __no_const call_t;
65181
65182 struct ircomm_cb {
65183 irda_queue_t queue;
65184 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65185 index 80ffde3..968b0f4 100644
65186 --- a/include/net/irda/ircomm_tty.h
65187 +++ b/include/net/irda/ircomm_tty.h
65188 @@ -35,6 +35,7 @@
65189 #include <linux/termios.h>
65190 #include <linux/timer.h>
65191 #include <linux/tty.h> /* struct tty_struct */
65192 +#include <asm/local.h>
65193
65194 #include <net/irda/irias_object.h>
65195 #include <net/irda/ircomm_core.h>
65196 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65197 index cc7c197..9f2da2a 100644
65198 --- a/include/net/iucv/af_iucv.h
65199 +++ b/include/net/iucv/af_iucv.h
65200 @@ -141,7 +141,7 @@ struct iucv_sock {
65201 struct iucv_sock_list {
65202 struct hlist_head head;
65203 rwlock_t lock;
65204 - atomic_t autobind_name;
65205 + atomic_unchecked_t autobind_name;
65206 };
65207
65208 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65209 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65210 index 0dab173..1b76af0 100644
65211 --- a/include/net/neighbour.h
65212 +++ b/include/net/neighbour.h
65213 @@ -123,7 +123,7 @@ struct neigh_ops {
65214 void (*error_report)(struct neighbour *, struct sk_buff *);
65215 int (*output)(struct neighbour *, struct sk_buff *);
65216 int (*connected_output)(struct neighbour *, struct sk_buff *);
65217 -};
65218 +} __do_const;
65219
65220 struct pneigh_entry {
65221 struct pneigh_entry *next;
65222 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65223 index 95e6466..251016d 100644
65224 --- a/include/net/net_namespace.h
65225 +++ b/include/net/net_namespace.h
65226 @@ -110,7 +110,7 @@ struct net {
65227 #endif
65228 struct netns_ipvs *ipvs;
65229 struct sock *diag_nlsk;
65230 - atomic_t rt_genid;
65231 + atomic_unchecked_t rt_genid;
65232 };
65233
65234 /*
65235 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65236
65237 static inline int rt_genid(struct net *net)
65238 {
65239 - return atomic_read(&net->rt_genid);
65240 + return atomic_read_unchecked(&net->rt_genid);
65241 }
65242
65243 static inline void rt_genid_bump(struct net *net)
65244 {
65245 - atomic_inc(&net->rt_genid);
65246 + atomic_inc_unchecked(&net->rt_genid);
65247 }
65248
65249 #endif /* __NET_NET_NAMESPACE_H */
65250 diff --git a/include/net/netdma.h b/include/net/netdma.h
65251 index 8ba8ce2..99b7fff 100644
65252 --- a/include/net/netdma.h
65253 +++ b/include/net/netdma.h
65254 @@ -24,7 +24,7 @@
65255 #include <linux/dmaengine.h>
65256 #include <linux/skbuff.h>
65257
65258 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65259 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65260 struct sk_buff *skb, int offset, struct iovec *to,
65261 size_t len, struct dma_pinned_list *pinned_list);
65262
65263 diff --git a/include/net/netlink.h b/include/net/netlink.h
65264 index 9690b0f..87aded7 100644
65265 --- a/include/net/netlink.h
65266 +++ b/include/net/netlink.h
65267 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65268 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65269 {
65270 if (mark)
65271 - skb_trim(skb, (unsigned char *) mark - skb->data);
65272 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65273 }
65274
65275 /**
65276 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65277 index 2ae2b83..dbdc85e 100644
65278 --- a/include/net/netns/ipv4.h
65279 +++ b/include/net/netns/ipv4.h
65280 @@ -64,7 +64,7 @@ struct netns_ipv4 {
65281 kgid_t sysctl_ping_group_range[2];
65282 long sysctl_tcp_mem[3];
65283
65284 - atomic_t dev_addr_genid;
65285 + atomic_unchecked_t dev_addr_genid;
65286
65287 #ifdef CONFIG_IP_MROUTE
65288 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65289 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65290 index 9c6414f..fbd0524 100644
65291 --- a/include/net/sctp/sctp.h
65292 +++ b/include/net/sctp/sctp.h
65293 @@ -318,9 +318,9 @@ do { \
65294
65295 #else /* SCTP_DEBUG */
65296
65297 -#define SCTP_DEBUG_PRINTK(whatever...)
65298 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65299 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65300 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65301 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65302 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65303 #define SCTP_ENABLE_DEBUG
65304 #define SCTP_DISABLE_DEBUG
65305 #define SCTP_ASSERT(expr, str, func)
65306 diff --git a/include/net/sock.h b/include/net/sock.h
65307 index c945fba..e162e56 100644
65308 --- a/include/net/sock.h
65309 +++ b/include/net/sock.h
65310 @@ -304,7 +304,7 @@ struct sock {
65311 #ifdef CONFIG_RPS
65312 __u32 sk_rxhash;
65313 #endif
65314 - atomic_t sk_drops;
65315 + atomic_unchecked_t sk_drops;
65316 int sk_rcvbuf;
65317
65318 struct sk_filter __rcu *sk_filter;
65319 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65320 }
65321
65322 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65323 - char __user *from, char *to,
65324 + char __user *from, unsigned char *to,
65325 int copy, int offset)
65326 {
65327 if (skb->ip_summed == CHECKSUM_NONE) {
65328 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65329 }
65330 }
65331
65332 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65333 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65334
65335 /**
65336 * sk_page_frag - return an appropriate page_frag
65337 diff --git a/include/net/tcp.h b/include/net/tcp.h
65338 index 4af45e3..32163a9 100644
65339 --- a/include/net/tcp.h
65340 +++ b/include/net/tcp.h
65341 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65342 extern void tcp_xmit_retransmit_queue(struct sock *);
65343 extern void tcp_simple_retransmit(struct sock *);
65344 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65345 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65346 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65347
65348 extern void tcp_send_probe0(struct sock *);
65349 extern void tcp_send_partial(struct sock *);
65350 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
65351 struct inet6_skb_parm h6;
65352 #endif
65353 } header; /* For incoming frames */
65354 - __u32 seq; /* Starting sequence number */
65355 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65356 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65357 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65358 __u32 when; /* used to compute rtt's */
65359 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65360
65361 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
65362
65363 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65364 /* 1 byte hole */
65365 - __u32 ack_seq; /* Sequence number ACK'd */
65366 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65367 };
65368
65369 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65370 @@ -1563,7 +1563,7 @@ struct tcp_seq_afinfo {
65371 char *name;
65372 sa_family_t family;
65373 const struct file_operations *seq_fops;
65374 - struct seq_operations seq_ops;
65375 + seq_operations_no_const seq_ops;
65376 };
65377
65378 struct tcp_iter_state {
65379 diff --git a/include/net/udp.h b/include/net/udp.h
65380 index 065f379..b661b40 100644
65381 --- a/include/net/udp.h
65382 +++ b/include/net/udp.h
65383 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65384 sa_family_t family;
65385 struct udp_table *udp_table;
65386 const struct file_operations *seq_fops;
65387 - struct seq_operations seq_ops;
65388 + seq_operations_no_const seq_ops;
65389 };
65390
65391 struct udp_iter_state {
65392 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65393 index 63445ed..01ddc62 100644
65394 --- a/include/net/xfrm.h
65395 +++ b/include/net/xfrm.h
65396 @@ -514,7 +514,7 @@ struct xfrm_policy {
65397 struct timer_list timer;
65398
65399 struct flow_cache_object flo;
65400 - atomic_t genid;
65401 + atomic_unchecked_t genid;
65402 u32 priority;
65403 u32 index;
65404 struct xfrm_mark mark;
65405 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65406 index 1a046b1..ee0bef0 100644
65407 --- a/include/rdma/iw_cm.h
65408 +++ b/include/rdma/iw_cm.h
65409 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65410 int backlog);
65411
65412 int (*destroy_listen)(struct iw_cm_id *cm_id);
65413 -};
65414 +} __no_const;
65415
65416 /**
65417 * iw_create_cm_id - Create an IW CM identifier.
65418 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65419 index 399162b..b337f1a 100644
65420 --- a/include/scsi/libfc.h
65421 +++ b/include/scsi/libfc.h
65422 @@ -762,6 +762,7 @@ struct libfc_function_template {
65423 */
65424 void (*disc_stop_final) (struct fc_lport *);
65425 };
65426 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65427
65428 /**
65429 * struct fc_disc - Discovery context
65430 @@ -866,7 +867,7 @@ struct fc_lport {
65431 struct fc_vport *vport;
65432
65433 /* Operational Information */
65434 - struct libfc_function_template tt;
65435 + libfc_function_template_no_const tt;
65436 u8 link_up;
65437 u8 qfull;
65438 enum fc_lport_state state;
65439 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65440 index 55367b0..d97bd2a 100644
65441 --- a/include/scsi/scsi_device.h
65442 +++ b/include/scsi/scsi_device.h
65443 @@ -169,9 +169,9 @@ struct scsi_device {
65444 unsigned int max_device_blocked; /* what device_blocked counts down from */
65445 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65446
65447 - atomic_t iorequest_cnt;
65448 - atomic_t iodone_cnt;
65449 - atomic_t ioerr_cnt;
65450 + atomic_unchecked_t iorequest_cnt;
65451 + atomic_unchecked_t iodone_cnt;
65452 + atomic_unchecked_t ioerr_cnt;
65453
65454 struct device sdev_gendev,
65455 sdev_dev;
65456 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65457 index b797e8f..8e2c3aa 100644
65458 --- a/include/scsi/scsi_transport_fc.h
65459 +++ b/include/scsi/scsi_transport_fc.h
65460 @@ -751,7 +751,8 @@ struct fc_function_template {
65461 unsigned long show_host_system_hostname:1;
65462
65463 unsigned long disable_target_scan:1;
65464 -};
65465 +} __do_const;
65466 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65467
65468
65469 /**
65470 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65471 index 030b87c..98a6954 100644
65472 --- a/include/sound/ak4xxx-adda.h
65473 +++ b/include/sound/ak4xxx-adda.h
65474 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65475 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65476 unsigned char val);
65477 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65478 -};
65479 +} __no_const;
65480
65481 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65482
65483 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65484 index 8c05e47..2b5df97 100644
65485 --- a/include/sound/hwdep.h
65486 +++ b/include/sound/hwdep.h
65487 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65488 struct snd_hwdep_dsp_status *status);
65489 int (*dsp_load)(struct snd_hwdep *hw,
65490 struct snd_hwdep_dsp_image *image);
65491 -};
65492 +} __no_const;
65493
65494 struct snd_hwdep {
65495 struct snd_card *card;
65496 diff --git a/include/sound/info.h b/include/sound/info.h
65497 index 9ca1a49..aba1728 100644
65498 --- a/include/sound/info.h
65499 +++ b/include/sound/info.h
65500 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65501 struct snd_info_buffer *buffer);
65502 void (*write)(struct snd_info_entry *entry,
65503 struct snd_info_buffer *buffer);
65504 -};
65505 +} __no_const;
65506
65507 struct snd_info_entry_ops {
65508 int (*open)(struct snd_info_entry *entry,
65509 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65510 index 6268a41..de9b9d1 100644
65511 --- a/include/sound/pcm.h
65512 +++ b/include/sound/pcm.h
65513 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65514 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65515 int (*ack)(struct snd_pcm_substream *substream);
65516 };
65517 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65518
65519 /*
65520 *
65521 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65522 index 7e95056..52df55a 100644
65523 --- a/include/sound/sb16_csp.h
65524 +++ b/include/sound/sb16_csp.h
65525 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65526 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65527 int (*csp_stop) (struct snd_sb_csp * p);
65528 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65529 -};
65530 +} __no_const;
65531
65532 /*
65533 * CSP private data
65534 diff --git a/include/sound/soc.h b/include/sound/soc.h
65535 index 91244a0..4534aae 100644
65536 --- a/include/sound/soc.h
65537 +++ b/include/sound/soc.h
65538 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
65539 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65540 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65541 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65542 -};
65543 +} __do_const;
65544
65545 struct snd_soc_platform {
65546 const char *name;
65547 @@ -1031,7 +1031,7 @@ struct snd_soc_pcm_runtime {
65548 struct snd_soc_dai_link *dai_link;
65549 struct mutex pcm_mutex;
65550 enum snd_soc_pcm_subclass pcm_subclass;
65551 - struct snd_pcm_ops ops;
65552 + snd_pcm_ops_no_const ops;
65553
65554 unsigned int dev_registered:1;
65555
65556 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65557 index 098c4de..171054b 100644
65558 --- a/include/sound/tea575x-tuner.h
65559 +++ b/include/sound/tea575x-tuner.h
65560 @@ -49,7 +49,7 @@ struct snd_tea575x_ops {
65561
65562 struct snd_tea575x {
65563 struct v4l2_device *v4l2_dev;
65564 - struct v4l2_file_operations fops;
65565 + v4l2_file_operations_no_const fops;
65566 struct video_device vd; /* video device */
65567 int radio_nr; /* radio_nr */
65568 bool tea5759; /* 5759 chip is present */
65569 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65570 index 5be8937..a8e46e9 100644
65571 --- a/include/target/target_core_base.h
65572 +++ b/include/target/target_core_base.h
65573 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65574 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65575 int (*t10_pr_register)(struct se_cmd *);
65576 int (*t10_pr_clear)(struct se_cmd *);
65577 -};
65578 +} __no_const;
65579
65580 struct t10_reservation {
65581 /* Reservation effects all target ports */
65582 @@ -758,7 +758,7 @@ struct se_device {
65583 spinlock_t stats_lock;
65584 /* Active commands on this virtual SE device */
65585 atomic_t simple_cmds;
65586 - atomic_t dev_ordered_id;
65587 + atomic_unchecked_t dev_ordered_id;
65588 atomic_t dev_ordered_sync;
65589 atomic_t dev_qf_count;
65590 struct se_obj dev_obj;
65591 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65592 new file mode 100644
65593 index 0000000..fb634b7
65594 --- /dev/null
65595 +++ b/include/trace/events/fs.h
65596 @@ -0,0 +1,53 @@
65597 +#undef TRACE_SYSTEM
65598 +#define TRACE_SYSTEM fs
65599 +
65600 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65601 +#define _TRACE_FS_H
65602 +
65603 +#include <linux/fs.h>
65604 +#include <linux/tracepoint.h>
65605 +
65606 +TRACE_EVENT(do_sys_open,
65607 +
65608 + TP_PROTO(const char *filename, int flags, int mode),
65609 +
65610 + TP_ARGS(filename, flags, mode),
65611 +
65612 + TP_STRUCT__entry(
65613 + __string( filename, filename )
65614 + __field( int, flags )
65615 + __field( int, mode )
65616 + ),
65617 +
65618 + TP_fast_assign(
65619 + __assign_str(filename, filename);
65620 + __entry->flags = flags;
65621 + __entry->mode = mode;
65622 + ),
65623 +
65624 + TP_printk("\"%s\" %x %o",
65625 + __get_str(filename), __entry->flags, __entry->mode)
65626 +);
65627 +
65628 +TRACE_EVENT(open_exec,
65629 +
65630 + TP_PROTO(const char *filename),
65631 +
65632 + TP_ARGS(filename),
65633 +
65634 + TP_STRUCT__entry(
65635 + __string( filename, filename )
65636 + ),
65637 +
65638 + TP_fast_assign(
65639 + __assign_str(filename, filename);
65640 + ),
65641 +
65642 + TP_printk("\"%s\"",
65643 + __get_str(filename))
65644 +);
65645 +
65646 +#endif /* _TRACE_FS_H */
65647 +
65648 +/* This part must be outside protection */
65649 +#include <trace/define_trace.h>
65650 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65651 index 1c09820..7f5ec79 100644
65652 --- a/include/trace/events/irq.h
65653 +++ b/include/trace/events/irq.h
65654 @@ -36,7 +36,7 @@ struct softirq_action;
65655 */
65656 TRACE_EVENT(irq_handler_entry,
65657
65658 - TP_PROTO(int irq, struct irqaction *action),
65659 + TP_PROTO(int irq, const struct irqaction *action),
65660
65661 TP_ARGS(irq, action),
65662
65663 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65664 */
65665 TRACE_EVENT(irq_handler_exit,
65666
65667 - TP_PROTO(int irq, struct irqaction *action, int ret),
65668 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65669
65670 TP_ARGS(irq, action, ret),
65671
65672 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
65673 index 7caf44c..23c6f27 100644
65674 --- a/include/uapi/linux/a.out.h
65675 +++ b/include/uapi/linux/a.out.h
65676 @@ -39,6 +39,14 @@ enum machine_type {
65677 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65678 };
65679
65680 +/* Constants for the N_FLAGS field */
65681 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65682 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65683 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65684 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65685 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65686 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65687 +
65688 #if !defined (N_MAGIC)
65689 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65690 #endif
65691 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
65692 index d876736..b36014e 100644
65693 --- a/include/uapi/linux/byteorder/little_endian.h
65694 +++ b/include/uapi/linux/byteorder/little_endian.h
65695 @@ -42,51 +42,51 @@
65696
65697 static inline __le64 __cpu_to_le64p(const __u64 *p)
65698 {
65699 - return (__force __le64)*p;
65700 + return (__force const __le64)*p;
65701 }
65702 static inline __u64 __le64_to_cpup(const __le64 *p)
65703 {
65704 - return (__force __u64)*p;
65705 + return (__force const __u64)*p;
65706 }
65707 static inline __le32 __cpu_to_le32p(const __u32 *p)
65708 {
65709 - return (__force __le32)*p;
65710 + return (__force const __le32)*p;
65711 }
65712 static inline __u32 __le32_to_cpup(const __le32 *p)
65713 {
65714 - return (__force __u32)*p;
65715 + return (__force const __u32)*p;
65716 }
65717 static inline __le16 __cpu_to_le16p(const __u16 *p)
65718 {
65719 - return (__force __le16)*p;
65720 + return (__force const __le16)*p;
65721 }
65722 static inline __u16 __le16_to_cpup(const __le16 *p)
65723 {
65724 - return (__force __u16)*p;
65725 + return (__force const __u16)*p;
65726 }
65727 static inline __be64 __cpu_to_be64p(const __u64 *p)
65728 {
65729 - return (__force __be64)__swab64p(p);
65730 + return (__force const __be64)__swab64p(p);
65731 }
65732 static inline __u64 __be64_to_cpup(const __be64 *p)
65733 {
65734 - return __swab64p((__u64 *)p);
65735 + return __swab64p((const __u64 *)p);
65736 }
65737 static inline __be32 __cpu_to_be32p(const __u32 *p)
65738 {
65739 - return (__force __be32)__swab32p(p);
65740 + return (__force const __be32)__swab32p(p);
65741 }
65742 static inline __u32 __be32_to_cpup(const __be32 *p)
65743 {
65744 - return __swab32p((__u32 *)p);
65745 + return __swab32p((const __u32 *)p);
65746 }
65747 static inline __be16 __cpu_to_be16p(const __u16 *p)
65748 {
65749 - return (__force __be16)__swab16p(p);
65750 + return (__force const __be16)__swab16p(p);
65751 }
65752 static inline __u16 __be16_to_cpup(const __be16 *p)
65753 {
65754 - return __swab16p((__u16 *)p);
65755 + return __swab16p((const __u16 *)p);
65756 }
65757 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65758 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65759 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
65760 index 126a817..d522bd1 100644
65761 --- a/include/uapi/linux/elf.h
65762 +++ b/include/uapi/linux/elf.h
65763 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
65764 #define PT_GNU_EH_FRAME 0x6474e550
65765
65766 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65767 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65768 +
65769 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65770 +
65771 +/* Constants for the e_flags field */
65772 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65773 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65774 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65775 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65776 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65777 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65778
65779 /*
65780 * Extended Numbering
65781 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
65782 #define DT_DEBUG 21
65783 #define DT_TEXTREL 22
65784 #define DT_JMPREL 23
65785 +#define DT_FLAGS 30
65786 + #define DF_TEXTREL 0x00000004
65787 #define DT_ENCODING 32
65788 #define OLD_DT_LOOS 0x60000000
65789 #define DT_LOOS 0x6000000d
65790 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
65791 #define PF_W 0x2
65792 #define PF_X 0x1
65793
65794 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65795 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65796 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65797 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65798 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65799 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65800 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65801 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65802 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65803 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65804 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65805 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65806 +
65807 typedef struct elf32_phdr{
65808 Elf32_Word p_type;
65809 Elf32_Off p_offset;
65810 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
65811 #define EI_OSABI 7
65812 #define EI_PAD 8
65813
65814 +#define EI_PAX 14
65815 +
65816 #define ELFMAG0 0x7f /* EI_MAG */
65817 #define ELFMAG1 'E'
65818 #define ELFMAG2 'L'
65819 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
65820 index aa169c4..6a2771d 100644
65821 --- a/include/uapi/linux/personality.h
65822 +++ b/include/uapi/linux/personality.h
65823 @@ -30,6 +30,7 @@ enum {
65824 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
65825 ADDR_NO_RANDOMIZE | \
65826 ADDR_COMPAT_LAYOUT | \
65827 + ADDR_LIMIT_3GB | \
65828 MMAP_PAGE_ZERO)
65829
65830 /*
65831 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
65832 index 7530e74..e714828 100644
65833 --- a/include/uapi/linux/screen_info.h
65834 +++ b/include/uapi/linux/screen_info.h
65835 @@ -43,7 +43,8 @@ struct screen_info {
65836 __u16 pages; /* 0x32 */
65837 __u16 vesa_attributes; /* 0x34 */
65838 __u32 capabilities; /* 0x36 */
65839 - __u8 _reserved[6]; /* 0x3a */
65840 + __u16 vesapm_size; /* 0x3a */
65841 + __u8 _reserved[4]; /* 0x3c */
65842 } __attribute__((packed));
65843
65844 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
65845 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
65846 index 6d67213..8dab561 100644
65847 --- a/include/uapi/linux/sysctl.h
65848 +++ b/include/uapi/linux/sysctl.h
65849 @@ -155,7 +155,11 @@ enum
65850 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65851 };
65852
65853 -
65854 +#ifdef CONFIG_PAX_SOFTMODE
65855 +enum {
65856 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65857 +};
65858 +#endif
65859
65860 /* CTL_VM names: */
65861 enum
65862 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
65863 index 26607bd..588b65f 100644
65864 --- a/include/uapi/linux/xattr.h
65865 +++ b/include/uapi/linux/xattr.h
65866 @@ -60,5 +60,9 @@
65867 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65868 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65869
65870 +/* User namespace */
65871 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65872 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65873 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65874
65875 #endif /* _UAPI_LINUX_XATTR_H */
65876 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65877 index f9466fa..f4e2b81 100644
65878 --- a/include/video/udlfb.h
65879 +++ b/include/video/udlfb.h
65880 @@ -53,10 +53,10 @@ struct dlfb_data {
65881 u32 pseudo_palette[256];
65882 int blank_mode; /*one of FB_BLANK_ */
65883 /* blit-only rendering path metrics, exposed through sysfs */
65884 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65885 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65886 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65887 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65888 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65889 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65890 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65891 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65892 };
65893
65894 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65895 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65896 index 0993a22..32ba2fe 100644
65897 --- a/include/video/uvesafb.h
65898 +++ b/include/video/uvesafb.h
65899 @@ -177,6 +177,7 @@ struct uvesafb_par {
65900 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65901 u8 pmi_setpal; /* PMI for palette changes */
65902 u16 *pmi_base; /* protected mode interface location */
65903 + u8 *pmi_code; /* protected mode code location */
65904 void *pmi_start;
65905 void *pmi_pal;
65906 u8 *vbe_state_orig; /*
65907 diff --git a/init/Kconfig b/init/Kconfig
65908 index 6fdd6e3..5b01610 100644
65909 --- a/init/Kconfig
65910 +++ b/init/Kconfig
65911 @@ -925,6 +925,7 @@ endif # CGROUPS
65912
65913 config CHECKPOINT_RESTORE
65914 bool "Checkpoint/restore support" if EXPERT
65915 + depends on !GRKERNSEC
65916 default n
65917 help
65918 Enables additional kernel features in a sake of checkpoint/restore.
65919 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
65920 depends on OCFS2_FS = n
65921 depends on XFS_FS = n
65922
65923 + depends on GRKERNSEC = n
65924 +
65925 config UIDGID_STRICT_TYPE_CHECKS
65926 bool "Require conversions between uid/gids and their internal representation"
65927 depends on UIDGID_CONVERTED
65928 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
65929
65930 config COMPAT_BRK
65931 bool "Disable heap randomization"
65932 - default y
65933 + default n
65934 help
65935 Randomizing heap placement makes heap exploits harder, but it
65936 also breaks ancient binaries (including anything libc5 based).
65937 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
65938 config STOP_MACHINE
65939 bool
65940 default y
65941 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65942 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65943 help
65944 Need stop_machine() primitive.
65945
65946 diff --git a/init/Makefile b/init/Makefile
65947 index 7bc47ee..6da2dc7 100644
65948 --- a/init/Makefile
65949 +++ b/init/Makefile
65950 @@ -2,6 +2,9 @@
65951 # Makefile for the linux kernel.
65952 #
65953
65954 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65955 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65956 +
65957 obj-y := main.o version.o mounts.o
65958 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65959 obj-y += noinitramfs.o
65960 diff --git a/init/do_mounts.c b/init/do_mounts.c
65961 index f8a6642..4e5ee1b 100644
65962 --- a/init/do_mounts.c
65963 +++ b/init/do_mounts.c
65964 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65965 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65966 {
65967 struct super_block *s;
65968 - int err = sys_mount(name, "/root", fs, flags, data);
65969 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65970 if (err)
65971 return err;
65972
65973 - sys_chdir("/root");
65974 + sys_chdir((const char __force_user *)"/root");
65975 s = current->fs->pwd.dentry->d_sb;
65976 ROOT_DEV = s->s_dev;
65977 printk(KERN_INFO
65978 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
65979 va_start(args, fmt);
65980 vsprintf(buf, fmt, args);
65981 va_end(args);
65982 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65983 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65984 if (fd >= 0) {
65985 sys_ioctl(fd, FDEJECT, 0);
65986 sys_close(fd);
65987 }
65988 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65989 - fd = sys_open("/dev/console", O_RDWR, 0);
65990 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65991 if (fd >= 0) {
65992 sys_ioctl(fd, TCGETS, (long)&termios);
65993 termios.c_lflag &= ~ICANON;
65994 sys_ioctl(fd, TCSETSF, (long)&termios);
65995 - sys_read(fd, &c, 1);
65996 + sys_read(fd, (char __user *)&c, 1);
65997 termios.c_lflag |= ICANON;
65998 sys_ioctl(fd, TCSETSF, (long)&termios);
65999 sys_close(fd);
66000 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
66001 mount_root();
66002 out:
66003 devtmpfs_mount("dev");
66004 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66005 - sys_chroot(".");
66006 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66007 + sys_chroot((const char __force_user *)".");
66008 }
66009 diff --git a/init/do_mounts.h b/init/do_mounts.h
66010 index f5b978a..69dbfe8 100644
66011 --- a/init/do_mounts.h
66012 +++ b/init/do_mounts.h
66013 @@ -15,15 +15,15 @@ extern int root_mountflags;
66014
66015 static inline int create_dev(char *name, dev_t dev)
66016 {
66017 - sys_unlink(name);
66018 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66019 + sys_unlink((char __force_user *)name);
66020 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66021 }
66022
66023 #if BITS_PER_LONG == 32
66024 static inline u32 bstat(char *name)
66025 {
66026 struct stat64 stat;
66027 - if (sys_stat64(name, &stat) != 0)
66028 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66029 return 0;
66030 if (!S_ISBLK(stat.st_mode))
66031 return 0;
66032 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66033 static inline u32 bstat(char *name)
66034 {
66035 struct stat stat;
66036 - if (sys_newstat(name, &stat) != 0)
66037 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66038 return 0;
66039 if (!S_ISBLK(stat.st_mode))
66040 return 0;
66041 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66042 index 5e4ded5..aa3cd7e 100644
66043 --- a/init/do_mounts_initrd.c
66044 +++ b/init/do_mounts_initrd.c
66045 @@ -54,8 +54,8 @@ static void __init handle_initrd(void)
66046 create_dev("/dev/root.old", Root_RAM0);
66047 /* mount initrd on rootfs' /root */
66048 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66049 - sys_mkdir("/old", 0700);
66050 - sys_chdir("/old");
66051 + sys_mkdir((const char __force_user *)"/old", 0700);
66052 + sys_chdir((const char __force_user *)"/old");
66053
66054 /*
66055 * In case that a resume from disk is carried out by linuxrc or one of
66056 @@ -69,31 +69,31 @@ static void __init handle_initrd(void)
66057 current->flags &= ~PF_FREEZER_SKIP;
66058
66059 /* move initrd to rootfs' /old */
66060 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
66061 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
66062 /* switch root and cwd back to / of rootfs */
66063 - sys_chroot("..");
66064 + sys_chroot((const char __force_user *)"..");
66065
66066 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66067 - sys_chdir("/old");
66068 + sys_chdir((const char __force_user *)"/old");
66069 return;
66070 }
66071
66072 - sys_chdir("/");
66073 + sys_chdir((const char __force_user *)"/");
66074 ROOT_DEV = new_decode_dev(real_root_dev);
66075 mount_root();
66076
66077 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66078 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66079 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66080 if (!error)
66081 printk("okay\n");
66082 else {
66083 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66084 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66085 if (error == -ENOENT)
66086 printk("/initrd does not exist. Ignored.\n");
66087 else
66088 printk("failed\n");
66089 printk(KERN_NOTICE "Unmounting old root\n");
66090 - sys_umount("/old", MNT_DETACH);
66091 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66092 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66093 if (fd < 0) {
66094 error = fd;
66095 @@ -116,11 +116,11 @@ int __init initrd_load(void)
66096 * mounted in the normal path.
66097 */
66098 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66099 - sys_unlink("/initrd.image");
66100 + sys_unlink((const char __force_user *)"/initrd.image");
66101 handle_initrd();
66102 return 1;
66103 }
66104 }
66105 - sys_unlink("/initrd.image");
66106 + sys_unlink((const char __force_user *)"/initrd.image");
66107 return 0;
66108 }
66109 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66110 index 8cb6db5..d729f50 100644
66111 --- a/init/do_mounts_md.c
66112 +++ b/init/do_mounts_md.c
66113 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66114 partitioned ? "_d" : "", minor,
66115 md_setup_args[ent].device_names);
66116
66117 - fd = sys_open(name, 0, 0);
66118 + fd = sys_open((char __force_user *)name, 0, 0);
66119 if (fd < 0) {
66120 printk(KERN_ERR "md: open failed - cannot start "
66121 "array %s\n", name);
66122 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66123 * array without it
66124 */
66125 sys_close(fd);
66126 - fd = sys_open(name, 0, 0);
66127 + fd = sys_open((char __force_user *)name, 0, 0);
66128 sys_ioctl(fd, BLKRRPART, 0);
66129 }
66130 sys_close(fd);
66131 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66132
66133 wait_for_device_probe();
66134
66135 - fd = sys_open("/dev/md0", 0, 0);
66136 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66137 if (fd >= 0) {
66138 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66139 sys_close(fd);
66140 diff --git a/init/init_task.c b/init/init_task.c
66141 index 8b2f399..f0797c9 100644
66142 --- a/init/init_task.c
66143 +++ b/init/init_task.c
66144 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66145 * Initial thread structure. Alignment of this is handled by a special
66146 * linker map entry.
66147 */
66148 +#ifdef CONFIG_X86
66149 +union thread_union init_thread_union __init_task_data;
66150 +#else
66151 union thread_union init_thread_union __init_task_data =
66152 { INIT_THREAD_INFO(init_task) };
66153 +#endif
66154 diff --git a/init/initramfs.c b/init/initramfs.c
66155 index 84c6bf1..8899338 100644
66156 --- a/init/initramfs.c
66157 +++ b/init/initramfs.c
66158 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66159 }
66160 }
66161
66162 -static long __init do_utime(char *filename, time_t mtime)
66163 +static long __init do_utime(char __force_user *filename, time_t mtime)
66164 {
66165 struct timespec t[2];
66166
66167 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66168 struct dir_entry *de, *tmp;
66169 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66170 list_del(&de->list);
66171 - do_utime(de->name, de->mtime);
66172 + do_utime((char __force_user *)de->name, de->mtime);
66173 kfree(de->name);
66174 kfree(de);
66175 }
66176 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66177 if (nlink >= 2) {
66178 char *old = find_link(major, minor, ino, mode, collected);
66179 if (old)
66180 - return (sys_link(old, collected) < 0) ? -1 : 1;
66181 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66182 }
66183 return 0;
66184 }
66185 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66186 {
66187 struct stat st;
66188
66189 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66190 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66191 if (S_ISDIR(st.st_mode))
66192 - sys_rmdir(path);
66193 + sys_rmdir((char __force_user *)path);
66194 else
66195 - sys_unlink(path);
66196 + sys_unlink((char __force_user *)path);
66197 }
66198 }
66199
66200 @@ -315,7 +315,7 @@ static int __init do_name(void)
66201 int openflags = O_WRONLY|O_CREAT;
66202 if (ml != 1)
66203 openflags |= O_TRUNC;
66204 - wfd = sys_open(collected, openflags, mode);
66205 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66206
66207 if (wfd >= 0) {
66208 sys_fchown(wfd, uid, gid);
66209 @@ -327,17 +327,17 @@ static int __init do_name(void)
66210 }
66211 }
66212 } else if (S_ISDIR(mode)) {
66213 - sys_mkdir(collected, mode);
66214 - sys_chown(collected, uid, gid);
66215 - sys_chmod(collected, mode);
66216 + sys_mkdir((char __force_user *)collected, mode);
66217 + sys_chown((char __force_user *)collected, uid, gid);
66218 + sys_chmod((char __force_user *)collected, mode);
66219 dir_add(collected, mtime);
66220 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66221 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66222 if (maybe_link() == 0) {
66223 - sys_mknod(collected, mode, rdev);
66224 - sys_chown(collected, uid, gid);
66225 - sys_chmod(collected, mode);
66226 - do_utime(collected, mtime);
66227 + sys_mknod((char __force_user *)collected, mode, rdev);
66228 + sys_chown((char __force_user *)collected, uid, gid);
66229 + sys_chmod((char __force_user *)collected, mode);
66230 + do_utime((char __force_user *)collected, mtime);
66231 }
66232 }
66233 return 0;
66234 @@ -346,15 +346,15 @@ static int __init do_name(void)
66235 static int __init do_copy(void)
66236 {
66237 if (count >= body_len) {
66238 - sys_write(wfd, victim, body_len);
66239 + sys_write(wfd, (char __force_user *)victim, body_len);
66240 sys_close(wfd);
66241 - do_utime(vcollected, mtime);
66242 + do_utime((char __force_user *)vcollected, mtime);
66243 kfree(vcollected);
66244 eat(body_len);
66245 state = SkipIt;
66246 return 0;
66247 } else {
66248 - sys_write(wfd, victim, count);
66249 + sys_write(wfd, (char __force_user *)victim, count);
66250 body_len -= count;
66251 eat(count);
66252 return 1;
66253 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66254 {
66255 collected[N_ALIGN(name_len) + body_len] = '\0';
66256 clean_path(collected, 0);
66257 - sys_symlink(collected + N_ALIGN(name_len), collected);
66258 - sys_lchown(collected, uid, gid);
66259 - do_utime(collected, mtime);
66260 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66261 + sys_lchown((char __force_user *)collected, uid, gid);
66262 + do_utime((char __force_user *)collected, mtime);
66263 state = SkipIt;
66264 next_state = Reset;
66265 return 0;
66266 diff --git a/init/main.c b/init/main.c
66267 index e33e09d..8544e50 100644
66268 --- a/init/main.c
66269 +++ b/init/main.c
66270 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66271 extern void tc_init(void);
66272 #endif
66273
66274 +extern void grsecurity_init(void);
66275 +
66276 /*
66277 * Debug helper: via this flag we know that we are in 'early bootup code'
66278 * where only the boot processor is running with IRQ disabled. This means
66279 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66280
66281 __setup("reset_devices", set_reset_devices);
66282
66283 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66284 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66285 +static int __init setup_grsec_proc_gid(char *str)
66286 +{
66287 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66288 + return 1;
66289 +}
66290 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66291 +#endif
66292 +
66293 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66294 +extern char pax_enter_kernel_user[];
66295 +extern char pax_exit_kernel_user[];
66296 +extern pgdval_t clone_pgd_mask;
66297 +#endif
66298 +
66299 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66300 +static int __init setup_pax_nouderef(char *str)
66301 +{
66302 +#ifdef CONFIG_X86_32
66303 + unsigned int cpu;
66304 + struct desc_struct *gdt;
66305 +
66306 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66307 + gdt = get_cpu_gdt_table(cpu);
66308 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66309 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66310 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66311 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66312 + }
66313 + loadsegment(ds, __KERNEL_DS);
66314 + loadsegment(es, __KERNEL_DS);
66315 + loadsegment(ss, __KERNEL_DS);
66316 +#else
66317 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66318 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66319 + clone_pgd_mask = ~(pgdval_t)0UL;
66320 +#endif
66321 +
66322 + return 0;
66323 +}
66324 +early_param("pax_nouderef", setup_pax_nouderef);
66325 +#endif
66326 +
66327 +#ifdef CONFIG_PAX_SOFTMODE
66328 +int pax_softmode;
66329 +
66330 +static int __init setup_pax_softmode(char *str)
66331 +{
66332 + get_option(&str, &pax_softmode);
66333 + return 1;
66334 +}
66335 +__setup("pax_softmode=", setup_pax_softmode);
66336 +#endif
66337 +
66338 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66339 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66340 static const char *panic_later, *panic_param;
66341 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66342 {
66343 int count = preempt_count();
66344 int ret;
66345 + const char *msg1 = "", *msg2 = "";
66346
66347 if (initcall_debug)
66348 ret = do_one_initcall_debug(fn);
66349 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66350 sprintf(msgbuf, "error code %d ", ret);
66351
66352 if (preempt_count() != count) {
66353 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66354 + msg1 = " preemption imbalance";
66355 preempt_count() = count;
66356 }
66357 if (irqs_disabled()) {
66358 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66359 + msg2 = " disabled interrupts";
66360 local_irq_enable();
66361 }
66362 - if (msgbuf[0]) {
66363 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66364 + if (msgbuf[0] || *msg1 || *msg2) {
66365 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66366 }
66367
66368 return ret;
66369 @@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
66370 level, level,
66371 &repair_env_string);
66372
66373 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66374 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66375 do_one_initcall(*fn);
66376 +
66377 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66378 + transfer_latent_entropy();
66379 +#endif
66380 +
66381 + }
66382 }
66383
66384 static void __init do_initcalls(void)
66385 @@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
66386 {
66387 initcall_t *fn;
66388
66389 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66390 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66391 do_one_initcall(*fn);
66392 +
66393 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66394 + transfer_latent_entropy();
66395 +#endif
66396 +
66397 + }
66398 }
66399
66400 static int run_init_process(const char *init_filename)
66401 @@ -876,7 +946,7 @@ static void __init kernel_init_freeable(void)
66402 do_basic_setup();
66403
66404 /* Open the /dev/console on the rootfs, this should never fail */
66405 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66406 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66407 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66408
66409 (void) sys_dup(0);
66410 @@ -889,11 +959,13 @@ static void __init kernel_init_freeable(void)
66411 if (!ramdisk_execute_command)
66412 ramdisk_execute_command = "/init";
66413
66414 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66415 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66416 ramdisk_execute_command = NULL;
66417 prepare_namespace();
66418 }
66419
66420 + grsecurity_init();
66421 +
66422 /*
66423 * Ok, we have completed the initial bootup, and
66424 * we're essentially up and running. Get rid of the
66425 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66426 index 71a3ca1..cc330ee 100644
66427 --- a/ipc/mqueue.c
66428 +++ b/ipc/mqueue.c
66429 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66430 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66431 info->attr.mq_msgsize);
66432
66433 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66434 spin_lock(&mq_lock);
66435 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66436 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66437 diff --git a/ipc/msg.c b/ipc/msg.c
66438 index a71af5a..a90a110 100644
66439 --- a/ipc/msg.c
66440 +++ b/ipc/msg.c
66441 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66442 return security_msg_queue_associate(msq, msgflg);
66443 }
66444
66445 +static struct ipc_ops msg_ops = {
66446 + .getnew = newque,
66447 + .associate = msg_security,
66448 + .more_checks = NULL
66449 +};
66450 +
66451 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66452 {
66453 struct ipc_namespace *ns;
66454 - struct ipc_ops msg_ops;
66455 struct ipc_params msg_params;
66456
66457 ns = current->nsproxy->ipc_ns;
66458
66459 - msg_ops.getnew = newque;
66460 - msg_ops.associate = msg_security;
66461 - msg_ops.more_checks = NULL;
66462 -
66463 msg_params.key = key;
66464 msg_params.flg = msgflg;
66465
66466 diff --git a/ipc/sem.c b/ipc/sem.c
66467 index 58d31f1..cce7a55 100644
66468 --- a/ipc/sem.c
66469 +++ b/ipc/sem.c
66470 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66471 return 0;
66472 }
66473
66474 +static struct ipc_ops sem_ops = {
66475 + .getnew = newary,
66476 + .associate = sem_security,
66477 + .more_checks = sem_more_checks
66478 +};
66479 +
66480 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66481 {
66482 struct ipc_namespace *ns;
66483 - struct ipc_ops sem_ops;
66484 struct ipc_params sem_params;
66485
66486 ns = current->nsproxy->ipc_ns;
66487 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66488 if (nsems < 0 || nsems > ns->sc_semmsl)
66489 return -EINVAL;
66490
66491 - sem_ops.getnew = newary;
66492 - sem_ops.associate = sem_security;
66493 - sem_ops.more_checks = sem_more_checks;
66494 -
66495 sem_params.key = key;
66496 sem_params.flg = semflg;
66497 sem_params.u.nsems = nsems;
66498 diff --git a/ipc/shm.c b/ipc/shm.c
66499 index dff40c9..9450e27 100644
66500 --- a/ipc/shm.c
66501 +++ b/ipc/shm.c
66502 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66503 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66504 #endif
66505
66506 +#ifdef CONFIG_GRKERNSEC
66507 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66508 + const time_t shm_createtime, const uid_t cuid,
66509 + const int shmid);
66510 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66511 + const time_t shm_createtime);
66512 +#endif
66513 +
66514 void shm_init_ns(struct ipc_namespace *ns)
66515 {
66516 ns->shm_ctlmax = SHMMAX;
66517 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66518 shp->shm_lprid = 0;
66519 shp->shm_atim = shp->shm_dtim = 0;
66520 shp->shm_ctim = get_seconds();
66521 +#ifdef CONFIG_GRKERNSEC
66522 + {
66523 + struct timespec timeval;
66524 + do_posix_clock_monotonic_gettime(&timeval);
66525 +
66526 + shp->shm_createtime = timeval.tv_sec;
66527 + }
66528 +#endif
66529 shp->shm_segsz = size;
66530 shp->shm_nattch = 0;
66531 shp->shm_file = file;
66532 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66533 return 0;
66534 }
66535
66536 +static struct ipc_ops shm_ops = {
66537 + .getnew = newseg,
66538 + .associate = shm_security,
66539 + .more_checks = shm_more_checks
66540 +};
66541 +
66542 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66543 {
66544 struct ipc_namespace *ns;
66545 - struct ipc_ops shm_ops;
66546 struct ipc_params shm_params;
66547
66548 ns = current->nsproxy->ipc_ns;
66549
66550 - shm_ops.getnew = newseg;
66551 - shm_ops.associate = shm_security;
66552 - shm_ops.more_checks = shm_more_checks;
66553 -
66554 shm_params.key = key;
66555 shm_params.flg = shmflg;
66556 shm_params.u.size = size;
66557 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66558 f_mode = FMODE_READ | FMODE_WRITE;
66559 }
66560 if (shmflg & SHM_EXEC) {
66561 +
66562 +#ifdef CONFIG_PAX_MPROTECT
66563 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66564 + goto out;
66565 +#endif
66566 +
66567 prot |= PROT_EXEC;
66568 acc_mode |= S_IXUGO;
66569 }
66570 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66571 if (err)
66572 goto out_unlock;
66573
66574 +#ifdef CONFIG_GRKERNSEC
66575 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66576 + shp->shm_perm.cuid, shmid) ||
66577 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66578 + err = -EACCES;
66579 + goto out_unlock;
66580 + }
66581 +#endif
66582 +
66583 path = shp->shm_file->f_path;
66584 path_get(&path);
66585 shp->shm_nattch++;
66586 +#ifdef CONFIG_GRKERNSEC
66587 + shp->shm_lapid = current->pid;
66588 +#endif
66589 size = i_size_read(path.dentry->d_inode);
66590 shm_unlock(shp);
66591
66592 diff --git a/kernel/acct.c b/kernel/acct.c
66593 index 051e071..15e0920 100644
66594 --- a/kernel/acct.c
66595 +++ b/kernel/acct.c
66596 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66597 */
66598 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66599 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66600 - file->f_op->write(file, (char *)&ac,
66601 + file->f_op->write(file, (char __force_user *)&ac,
66602 sizeof(acct_t), &file->f_pos);
66603 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66604 set_fs(fs);
66605 diff --git a/kernel/audit.c b/kernel/audit.c
66606 index 40414e9..c920b72 100644
66607 --- a/kernel/audit.c
66608 +++ b/kernel/audit.c
66609 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
66610 3) suppressed due to audit_rate_limit
66611 4) suppressed due to audit_backlog_limit
66612 */
66613 -static atomic_t audit_lost = ATOMIC_INIT(0);
66614 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66615
66616 /* The netlink socket. */
66617 static struct sock *audit_sock;
66618 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
66619 unsigned long now;
66620 int print;
66621
66622 - atomic_inc(&audit_lost);
66623 + atomic_inc_unchecked(&audit_lost);
66624
66625 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66626
66627 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
66628 printk(KERN_WARNING
66629 "audit: audit_lost=%d audit_rate_limit=%d "
66630 "audit_backlog_limit=%d\n",
66631 - atomic_read(&audit_lost),
66632 + atomic_read_unchecked(&audit_lost),
66633 audit_rate_limit,
66634 audit_backlog_limit);
66635 audit_panic(message);
66636 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66637 status_set.pid = audit_pid;
66638 status_set.rate_limit = audit_rate_limit;
66639 status_set.backlog_limit = audit_backlog_limit;
66640 - status_set.lost = atomic_read(&audit_lost);
66641 + status_set.lost = atomic_read_unchecked(&audit_lost);
66642 status_set.backlog = skb_queue_len(&audit_skb_queue);
66643 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
66644 &status_set, sizeof(status_set));
66645 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66646 index 2f186ed..afb42c2 100644
66647 --- a/kernel/auditsc.c
66648 +++ b/kernel/auditsc.c
66649 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66650 }
66651
66652 /* global counter which is incremented every time something logs in */
66653 -static atomic_t session_id = ATOMIC_INIT(0);
66654 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66655
66656 /**
66657 * audit_set_loginuid - set current task's audit_context loginuid
66658 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
66659 return -EPERM;
66660 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66661
66662 - sessionid = atomic_inc_return(&session_id);
66663 + sessionid = atomic_inc_return_unchecked(&session_id);
66664 if (context && context->in_syscall) {
66665 struct audit_buffer *ab;
66666
66667 diff --git a/kernel/capability.c b/kernel/capability.c
66668 index 493d972..ea17248 100644
66669 --- a/kernel/capability.c
66670 +++ b/kernel/capability.c
66671 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66672 * before modification is attempted and the application
66673 * fails.
66674 */
66675 + if (tocopy > ARRAY_SIZE(kdata))
66676 + return -EFAULT;
66677 +
66678 if (copy_to_user(dataptr, kdata, tocopy
66679 * sizeof(struct __user_cap_data_struct))) {
66680 return -EFAULT;
66681 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66682 int ret;
66683
66684 rcu_read_lock();
66685 - ret = security_capable(__task_cred(t), ns, cap);
66686 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66687 + gr_task_is_capable(t, __task_cred(t), cap);
66688 rcu_read_unlock();
66689
66690 - return (ret == 0);
66691 + return ret;
66692 }
66693
66694 /**
66695 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66696 int ret;
66697
66698 rcu_read_lock();
66699 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66700 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66701 rcu_read_unlock();
66702
66703 - return (ret == 0);
66704 + return ret;
66705 }
66706
66707 /**
66708 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66709 BUG();
66710 }
66711
66712 - if (security_capable(current_cred(), ns, cap) == 0) {
66713 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66714 current->flags |= PF_SUPERPRIV;
66715 return true;
66716 }
66717 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66718 }
66719 EXPORT_SYMBOL(ns_capable);
66720
66721 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66722 +{
66723 + if (unlikely(!cap_valid(cap))) {
66724 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66725 + BUG();
66726 + }
66727 +
66728 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66729 + current->flags |= PF_SUPERPRIV;
66730 + return true;
66731 + }
66732 + return false;
66733 +}
66734 +EXPORT_SYMBOL(ns_capable_nolog);
66735 +
66736 /**
66737 * capable - Determine if the current task has a superior capability in effect
66738 * @cap: The capability to be tested for
66739 @@ -408,6 +427,12 @@ bool capable(int cap)
66740 }
66741 EXPORT_SYMBOL(capable);
66742
66743 +bool capable_nolog(int cap)
66744 +{
66745 + return ns_capable_nolog(&init_user_ns, cap);
66746 +}
66747 +EXPORT_SYMBOL(capable_nolog);
66748 +
66749 /**
66750 * nsown_capable - Check superior capability to one's own user_ns
66751 * @cap: The capability in question
66752 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66753
66754 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66755 }
66756 +
66757 +bool inode_capable_nolog(const struct inode *inode, int cap)
66758 +{
66759 + struct user_namespace *ns = current_user_ns();
66760 +
66761 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66762 +}
66763 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66764 index f24f724..0612ec45 100644
66765 --- a/kernel/cgroup.c
66766 +++ b/kernel/cgroup.c
66767 @@ -5518,7 +5518,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66768 struct css_set *cg = link->cg;
66769 struct task_struct *task;
66770 int count = 0;
66771 - seq_printf(seq, "css_set %p\n", cg);
66772 + seq_printf(seq, "css_set %pK\n", cg);
66773 list_for_each_entry(task, &cg->tasks, cg_list) {
66774 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66775 seq_puts(seq, " ...\n");
66776 diff --git a/kernel/compat.c b/kernel/compat.c
66777 index c28a306..b4d0cf3 100644
66778 --- a/kernel/compat.c
66779 +++ b/kernel/compat.c
66780 @@ -13,6 +13,7 @@
66781
66782 #include <linux/linkage.h>
66783 #include <linux/compat.h>
66784 +#include <linux/module.h>
66785 #include <linux/errno.h>
66786 #include <linux/time.h>
66787 #include <linux/signal.h>
66788 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66789 mm_segment_t oldfs;
66790 long ret;
66791
66792 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66793 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66794 oldfs = get_fs();
66795 set_fs(KERNEL_DS);
66796 ret = hrtimer_nanosleep_restart(restart);
66797 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66798 oldfs = get_fs();
66799 set_fs(KERNEL_DS);
66800 ret = hrtimer_nanosleep(&tu,
66801 - rmtp ? (struct timespec __user *)&rmt : NULL,
66802 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66803 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66804 set_fs(oldfs);
66805
66806 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66807 mm_segment_t old_fs = get_fs();
66808
66809 set_fs(KERNEL_DS);
66810 - ret = sys_sigpending((old_sigset_t __user *) &s);
66811 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66812 set_fs(old_fs);
66813 if (ret == 0)
66814 ret = put_user(s, set);
66815 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66816 mm_segment_t old_fs = get_fs();
66817
66818 set_fs(KERNEL_DS);
66819 - ret = sys_old_getrlimit(resource, &r);
66820 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66821 set_fs(old_fs);
66822
66823 if (!ret) {
66824 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66825 mm_segment_t old_fs = get_fs();
66826
66827 set_fs(KERNEL_DS);
66828 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66829 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66830 set_fs(old_fs);
66831
66832 if (ret)
66833 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66834 set_fs (KERNEL_DS);
66835 ret = sys_wait4(pid,
66836 (stat_addr ?
66837 - (unsigned int __user *) &status : NULL),
66838 - options, (struct rusage __user *) &r);
66839 + (unsigned int __force_user *) &status : NULL),
66840 + options, (struct rusage __force_user *) &r);
66841 set_fs (old_fs);
66842
66843 if (ret > 0) {
66844 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66845 memset(&info, 0, sizeof(info));
66846
66847 set_fs(KERNEL_DS);
66848 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66849 - uru ? (struct rusage __user *)&ru : NULL);
66850 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66851 + uru ? (struct rusage __force_user *)&ru : NULL);
66852 set_fs(old_fs);
66853
66854 if ((ret < 0) || (info.si_signo == 0))
66855 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66856 oldfs = get_fs();
66857 set_fs(KERNEL_DS);
66858 err = sys_timer_settime(timer_id, flags,
66859 - (struct itimerspec __user *) &newts,
66860 - (struct itimerspec __user *) &oldts);
66861 + (struct itimerspec __force_user *) &newts,
66862 + (struct itimerspec __force_user *) &oldts);
66863 set_fs(oldfs);
66864 if (!err && old && put_compat_itimerspec(old, &oldts))
66865 return -EFAULT;
66866 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66867 oldfs = get_fs();
66868 set_fs(KERNEL_DS);
66869 err = sys_timer_gettime(timer_id,
66870 - (struct itimerspec __user *) &ts);
66871 + (struct itimerspec __force_user *) &ts);
66872 set_fs(oldfs);
66873 if (!err && put_compat_itimerspec(setting, &ts))
66874 return -EFAULT;
66875 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66876 oldfs = get_fs();
66877 set_fs(KERNEL_DS);
66878 err = sys_clock_settime(which_clock,
66879 - (struct timespec __user *) &ts);
66880 + (struct timespec __force_user *) &ts);
66881 set_fs(oldfs);
66882 return err;
66883 }
66884 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66885 oldfs = get_fs();
66886 set_fs(KERNEL_DS);
66887 err = sys_clock_gettime(which_clock,
66888 - (struct timespec __user *) &ts);
66889 + (struct timespec __force_user *) &ts);
66890 set_fs(oldfs);
66891 if (!err && put_compat_timespec(&ts, tp))
66892 return -EFAULT;
66893 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66894
66895 oldfs = get_fs();
66896 set_fs(KERNEL_DS);
66897 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66898 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66899 set_fs(oldfs);
66900
66901 err = compat_put_timex(utp, &txc);
66902 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66903 oldfs = get_fs();
66904 set_fs(KERNEL_DS);
66905 err = sys_clock_getres(which_clock,
66906 - (struct timespec __user *) &ts);
66907 + (struct timespec __force_user *) &ts);
66908 set_fs(oldfs);
66909 if (!err && tp && put_compat_timespec(&ts, tp))
66910 return -EFAULT;
66911 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66912 long err;
66913 mm_segment_t oldfs;
66914 struct timespec tu;
66915 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66916 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66917
66918 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66919 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66920 oldfs = get_fs();
66921 set_fs(KERNEL_DS);
66922 err = clock_nanosleep_restart(restart);
66923 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66924 oldfs = get_fs();
66925 set_fs(KERNEL_DS);
66926 err = sys_clock_nanosleep(which_clock, flags,
66927 - (struct timespec __user *) &in,
66928 - (struct timespec __user *) &out);
66929 + (struct timespec __force_user *) &in,
66930 + (struct timespec __force_user *) &out);
66931 set_fs(oldfs);
66932
66933 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66934 diff --git a/kernel/configs.c b/kernel/configs.c
66935 index 42e8fa0..9e7406b 100644
66936 --- a/kernel/configs.c
66937 +++ b/kernel/configs.c
66938 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66939 struct proc_dir_entry *entry;
66940
66941 /* create the current config file */
66942 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66943 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66944 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66945 + &ikconfig_file_ops);
66946 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66947 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66948 + &ikconfig_file_ops);
66949 +#endif
66950 +#else
66951 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66952 &ikconfig_file_ops);
66953 +#endif
66954 +
66955 if (!entry)
66956 return -ENOMEM;
66957
66958 diff --git a/kernel/cred.c b/kernel/cred.c
66959 index 48cea3d..3476734 100644
66960 --- a/kernel/cred.c
66961 +++ b/kernel/cred.c
66962 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66963 validate_creds(cred);
66964 alter_cred_subscribers(cred, -1);
66965 put_cred(cred);
66966 +
66967 +#ifdef CONFIG_GRKERNSEC_SETXID
66968 + cred = (struct cred *) tsk->delayed_cred;
66969 + if (cred != NULL) {
66970 + tsk->delayed_cred = NULL;
66971 + validate_creds(cred);
66972 + alter_cred_subscribers(cred, -1);
66973 + put_cred(cred);
66974 + }
66975 +#endif
66976 }
66977
66978 /**
66979 @@ -469,7 +479,7 @@ error_put:
66980 * Always returns 0 thus allowing this function to be tail-called at the end
66981 * of, say, sys_setgid().
66982 */
66983 -int commit_creds(struct cred *new)
66984 +static int __commit_creds(struct cred *new)
66985 {
66986 struct task_struct *task = current;
66987 const struct cred *old = task->real_cred;
66988 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66989
66990 get_cred(new); /* we will require a ref for the subj creds too */
66991
66992 + gr_set_role_label(task, new->uid, new->gid);
66993 +
66994 /* dumpability changes */
66995 if (!uid_eq(old->euid, new->euid) ||
66996 !gid_eq(old->egid, new->egid) ||
66997 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66998 put_cred(old);
66999 return 0;
67000 }
67001 +#ifdef CONFIG_GRKERNSEC_SETXID
67002 +extern int set_user(struct cred *new);
67003 +
67004 +void gr_delayed_cred_worker(void)
67005 +{
67006 + const struct cred *new = current->delayed_cred;
67007 + struct cred *ncred;
67008 +
67009 + current->delayed_cred = NULL;
67010 +
67011 + if (current_uid() && new != NULL) {
67012 + // from doing get_cred on it when queueing this
67013 + put_cred(new);
67014 + return;
67015 + } else if (new == NULL)
67016 + return;
67017 +
67018 + ncred = prepare_creds();
67019 + if (!ncred)
67020 + goto die;
67021 + // uids
67022 + ncred->uid = new->uid;
67023 + ncred->euid = new->euid;
67024 + ncred->suid = new->suid;
67025 + ncred->fsuid = new->fsuid;
67026 + // gids
67027 + ncred->gid = new->gid;
67028 + ncred->egid = new->egid;
67029 + ncred->sgid = new->sgid;
67030 + ncred->fsgid = new->fsgid;
67031 + // groups
67032 + if (set_groups(ncred, new->group_info) < 0) {
67033 + abort_creds(ncred);
67034 + goto die;
67035 + }
67036 + // caps
67037 + ncred->securebits = new->securebits;
67038 + ncred->cap_inheritable = new->cap_inheritable;
67039 + ncred->cap_permitted = new->cap_permitted;
67040 + ncred->cap_effective = new->cap_effective;
67041 + ncred->cap_bset = new->cap_bset;
67042 +
67043 + if (set_user(ncred)) {
67044 + abort_creds(ncred);
67045 + goto die;
67046 + }
67047 +
67048 + // from doing get_cred on it when queueing this
67049 + put_cred(new);
67050 +
67051 + __commit_creds(ncred);
67052 + return;
67053 +die:
67054 + // from doing get_cred on it when queueing this
67055 + put_cred(new);
67056 + do_group_exit(SIGKILL);
67057 +}
67058 +#endif
67059 +
67060 +int commit_creds(struct cred *new)
67061 +{
67062 +#ifdef CONFIG_GRKERNSEC_SETXID
67063 + int ret;
67064 + int schedule_it = 0;
67065 + struct task_struct *t;
67066 +
67067 + /* we won't get called with tasklist_lock held for writing
67068 + and interrupts disabled as the cred struct in that case is
67069 + init_cred
67070 + */
67071 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67072 + !current_uid() && new->uid) {
67073 + schedule_it = 1;
67074 + }
67075 + ret = __commit_creds(new);
67076 + if (schedule_it) {
67077 + rcu_read_lock();
67078 + read_lock(&tasklist_lock);
67079 + for (t = next_thread(current); t != current;
67080 + t = next_thread(t)) {
67081 + if (t->delayed_cred == NULL) {
67082 + t->delayed_cred = get_cred(new);
67083 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67084 + set_tsk_need_resched(t);
67085 + }
67086 + }
67087 + read_unlock(&tasklist_lock);
67088 + rcu_read_unlock();
67089 + }
67090 + return ret;
67091 +#else
67092 + return __commit_creds(new);
67093 +#endif
67094 +}
67095 +
67096 EXPORT_SYMBOL(commit_creds);
67097
67098 /**
67099 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67100 index 9a61738..c5c8f3a 100644
67101 --- a/kernel/debug/debug_core.c
67102 +++ b/kernel/debug/debug_core.c
67103 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67104 */
67105 static atomic_t masters_in_kgdb;
67106 static atomic_t slaves_in_kgdb;
67107 -static atomic_t kgdb_break_tasklet_var;
67108 +static atomic_unchecked_t kgdb_break_tasklet_var;
67109 atomic_t kgdb_setting_breakpoint;
67110
67111 struct task_struct *kgdb_usethread;
67112 @@ -132,7 +132,7 @@ int kgdb_single_step;
67113 static pid_t kgdb_sstep_pid;
67114
67115 /* to keep track of the CPU which is doing the single stepping*/
67116 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67117 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67118
67119 /*
67120 * If you are debugging a problem where roundup (the collection of
67121 @@ -540,7 +540,7 @@ return_normal:
67122 * kernel will only try for the value of sstep_tries before
67123 * giving up and continuing on.
67124 */
67125 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67126 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67127 (kgdb_info[cpu].task &&
67128 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67129 atomic_set(&kgdb_active, -1);
67130 @@ -634,8 +634,8 @@ cpu_master_loop:
67131 }
67132
67133 kgdb_restore:
67134 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67135 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67136 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67137 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67138 if (kgdb_info[sstep_cpu].task)
67139 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67140 else
67141 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
67142 static void kgdb_tasklet_bpt(unsigned long ing)
67143 {
67144 kgdb_breakpoint();
67145 - atomic_set(&kgdb_break_tasklet_var, 0);
67146 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67147 }
67148
67149 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67150
67151 void kgdb_schedule_breakpoint(void)
67152 {
67153 - if (atomic_read(&kgdb_break_tasklet_var) ||
67154 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67155 atomic_read(&kgdb_active) != -1 ||
67156 atomic_read(&kgdb_setting_breakpoint))
67157 return;
67158 - atomic_inc(&kgdb_break_tasklet_var);
67159 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67160 tasklet_schedule(&kgdb_tasklet_breakpoint);
67161 }
67162 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67163 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67164 index 4d5f8d5..4743f33 100644
67165 --- a/kernel/debug/kdb/kdb_main.c
67166 +++ b/kernel/debug/kdb/kdb_main.c
67167 @@ -1972,7 +1972,7 @@ static int kdb_lsmod(int argc, const char **argv)
67168 list_for_each_entry(mod, kdb_modules, list) {
67169
67170 kdb_printf("%-20s%8u 0x%p ", mod->name,
67171 - mod->core_size, (void *)mod);
67172 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67173 #ifdef CONFIG_MODULE_UNLOAD
67174 kdb_printf("%4ld ", module_refcount(mod));
67175 #endif
67176 @@ -1982,7 +1982,7 @@ static int kdb_lsmod(int argc, const char **argv)
67177 kdb_printf(" (Loading)");
67178 else
67179 kdb_printf(" (Live)");
67180 - kdb_printf(" 0x%p", mod->module_core);
67181 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67182
67183 #ifdef CONFIG_MODULE_UNLOAD
67184 {
67185 diff --git a/kernel/events/core.c b/kernel/events/core.c
67186 index dbccf83..8c66482 100644
67187 --- a/kernel/events/core.c
67188 +++ b/kernel/events/core.c
67189 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67190 return 0;
67191 }
67192
67193 -static atomic64_t perf_event_id;
67194 +static atomic64_unchecked_t perf_event_id;
67195
67196 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67197 enum event_type_t event_type);
67198 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
67199
67200 static inline u64 perf_event_count(struct perf_event *event)
67201 {
67202 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67203 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67204 }
67205
67206 static u64 perf_event_read(struct perf_event *event)
67207 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67208 mutex_lock(&event->child_mutex);
67209 total += perf_event_read(event);
67210 *enabled += event->total_time_enabled +
67211 - atomic64_read(&event->child_total_time_enabled);
67212 + atomic64_read_unchecked(&event->child_total_time_enabled);
67213 *running += event->total_time_running +
67214 - atomic64_read(&event->child_total_time_running);
67215 + atomic64_read_unchecked(&event->child_total_time_running);
67216
67217 list_for_each_entry(child, &event->child_list, child_list) {
67218 total += perf_event_read(child);
67219 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
67220 userpg->offset -= local64_read(&event->hw.prev_count);
67221
67222 userpg->time_enabled = enabled +
67223 - atomic64_read(&event->child_total_time_enabled);
67224 + atomic64_read_unchecked(&event->child_total_time_enabled);
67225
67226 userpg->time_running = running +
67227 - atomic64_read(&event->child_total_time_running);
67228 + atomic64_read_unchecked(&event->child_total_time_running);
67229
67230 arch_perf_update_userpage(userpg, now);
67231
67232 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67233 values[n++] = perf_event_count(event);
67234 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67235 values[n++] = enabled +
67236 - atomic64_read(&event->child_total_time_enabled);
67237 + atomic64_read_unchecked(&event->child_total_time_enabled);
67238 }
67239 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67240 values[n++] = running +
67241 - atomic64_read(&event->child_total_time_running);
67242 + atomic64_read_unchecked(&event->child_total_time_running);
67243 }
67244 if (read_format & PERF_FORMAT_ID)
67245 values[n++] = primary_event_id(event);
67246 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67247 * need to add enough zero bytes after the string to handle
67248 * the 64bit alignment we do later.
67249 */
67250 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67251 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67252 if (!buf) {
67253 name = strncpy(tmp, "//enomem", sizeof(tmp));
67254 goto got_name;
67255 }
67256 - name = d_path(&file->f_path, buf, PATH_MAX);
67257 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67258 if (IS_ERR(name)) {
67259 name = strncpy(tmp, "//toolong", sizeof(tmp));
67260 goto got_name;
67261 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67262 event->parent = parent_event;
67263
67264 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67265 - event->id = atomic64_inc_return(&perf_event_id);
67266 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67267
67268 event->state = PERF_EVENT_STATE_INACTIVE;
67269
67270 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
67271 /*
67272 * Add back the child's count to the parent's count:
67273 */
67274 - atomic64_add(child_val, &parent_event->child_count);
67275 - atomic64_add(child_event->total_time_enabled,
67276 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67277 + atomic64_add_unchecked(child_event->total_time_enabled,
67278 &parent_event->child_total_time_enabled);
67279 - atomic64_add(child_event->total_time_running,
67280 + atomic64_add_unchecked(child_event->total_time_running,
67281 &parent_event->child_total_time_running);
67282
67283 /*
67284 diff --git a/kernel/exit.c b/kernel/exit.c
67285 index 346616c..a86ec83 100644
67286 --- a/kernel/exit.c
67287 +++ b/kernel/exit.c
67288 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67289 struct task_struct *leader;
67290 int zap_leader;
67291 repeat:
67292 +#ifdef CONFIG_NET
67293 + gr_del_task_from_ip_table(p);
67294 +#endif
67295 +
67296 /* don't need to get the RCU readlock here - the process is dead and
67297 * can't be modifying its own credentials. But shut RCU-lockdep up */
67298 rcu_read_lock();
67299 @@ -394,7 +398,7 @@ int allow_signal(int sig)
67300 * know it'll be handled, so that they don't get converted to
67301 * SIGKILL or just silently dropped.
67302 */
67303 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67304 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67305 recalc_sigpending();
67306 spin_unlock_irq(&current->sighand->siglock);
67307 return 0;
67308 @@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67309 vsnprintf(current->comm, sizeof(current->comm), name, args);
67310 va_end(args);
67311
67312 + gr_set_kernel_label(current);
67313 +
67314 /*
67315 * If we were started as result of loading a module, close all of the
67316 * user space pages. We don't need them, and if we didn't close them
67317 @@ -812,6 +818,8 @@ void do_exit(long code)
67318 struct task_struct *tsk = current;
67319 int group_dead;
67320
67321 + set_fs(USER_DS);
67322 +
67323 profile_task_exit(tsk);
67324
67325 WARN_ON(blk_needs_flush_plug(tsk));
67326 @@ -828,7 +836,6 @@ void do_exit(long code)
67327 * mm_release()->clear_child_tid() from writing to a user-controlled
67328 * kernel address.
67329 */
67330 - set_fs(USER_DS);
67331
67332 ptrace_event(PTRACE_EVENT_EXIT, code);
67333
67334 @@ -887,6 +894,9 @@ void do_exit(long code)
67335 tsk->exit_code = code;
67336 taskstats_exit(tsk, group_dead);
67337
67338 + gr_acl_handle_psacct(tsk, code);
67339 + gr_acl_handle_exit();
67340 +
67341 exit_mm(tsk);
67342
67343 if (group_dead)
67344 @@ -1007,7 +1017,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67345 * Take down every thread in the group. This is called by fatal signals
67346 * as well as by sys_exit_group (below).
67347 */
67348 -void
67349 +__noreturn void
67350 do_group_exit(int exit_code)
67351 {
67352 struct signal_struct *sig = current->signal;
67353 diff --git a/kernel/fork.c b/kernel/fork.c
67354 index 8b20ab7..58f2e45 100644
67355 --- a/kernel/fork.c
67356 +++ b/kernel/fork.c
67357 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67358 *stackend = STACK_END_MAGIC; /* for overflow detection */
67359
67360 #ifdef CONFIG_CC_STACKPROTECTOR
67361 - tsk->stack_canary = get_random_int();
67362 + tsk->stack_canary = pax_get_random_long();
67363 #endif
67364
67365 /*
67366 @@ -344,13 +344,81 @@ free_tsk:
67367 }
67368
67369 #ifdef CONFIG_MMU
67370 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67371 +{
67372 + struct vm_area_struct *tmp;
67373 + unsigned long charge;
67374 + struct mempolicy *pol;
67375 + struct file *file;
67376 +
67377 + charge = 0;
67378 + if (mpnt->vm_flags & VM_ACCOUNT) {
67379 + unsigned long len = vma_pages(mpnt);
67380 +
67381 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67382 + goto fail_nomem;
67383 + charge = len;
67384 + }
67385 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67386 + if (!tmp)
67387 + goto fail_nomem;
67388 + *tmp = *mpnt;
67389 + tmp->vm_mm = mm;
67390 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67391 + pol = mpol_dup(vma_policy(mpnt));
67392 + if (IS_ERR(pol))
67393 + goto fail_nomem_policy;
67394 + vma_set_policy(tmp, pol);
67395 + if (anon_vma_fork(tmp, mpnt))
67396 + goto fail_nomem_anon_vma_fork;
67397 + tmp->vm_flags &= ~VM_LOCKED;
67398 + tmp->vm_next = tmp->vm_prev = NULL;
67399 + tmp->vm_mirror = NULL;
67400 + file = tmp->vm_file;
67401 + if (file) {
67402 + struct inode *inode = file->f_path.dentry->d_inode;
67403 + struct address_space *mapping = file->f_mapping;
67404 +
67405 + get_file(file);
67406 + if (tmp->vm_flags & VM_DENYWRITE)
67407 + atomic_dec(&inode->i_writecount);
67408 + mutex_lock(&mapping->i_mmap_mutex);
67409 + if (tmp->vm_flags & VM_SHARED)
67410 + mapping->i_mmap_writable++;
67411 + flush_dcache_mmap_lock(mapping);
67412 + /* insert tmp into the share list, just after mpnt */
67413 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
67414 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
67415 + else
67416 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
67417 + flush_dcache_mmap_unlock(mapping);
67418 + mutex_unlock(&mapping->i_mmap_mutex);
67419 + }
67420 +
67421 + /*
67422 + * Clear hugetlb-related page reserves for children. This only
67423 + * affects MAP_PRIVATE mappings. Faults generated by the child
67424 + * are not guaranteed to succeed, even if read-only
67425 + */
67426 + if (is_vm_hugetlb_page(tmp))
67427 + reset_vma_resv_huge_pages(tmp);
67428 +
67429 + return tmp;
67430 +
67431 +fail_nomem_anon_vma_fork:
67432 + mpol_put(pol);
67433 +fail_nomem_policy:
67434 + kmem_cache_free(vm_area_cachep, tmp);
67435 +fail_nomem:
67436 + vm_unacct_memory(charge);
67437 + return NULL;
67438 +}
67439 +
67440 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67441 {
67442 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67443 struct rb_node **rb_link, *rb_parent;
67444 int retval;
67445 - unsigned long charge;
67446 - struct mempolicy *pol;
67447
67448 down_write(&oldmm->mmap_sem);
67449 flush_cache_dup_mm(oldmm);
67450 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67451 mm->locked_vm = 0;
67452 mm->mmap = NULL;
67453 mm->mmap_cache = NULL;
67454 - mm->free_area_cache = oldmm->mmap_base;
67455 - mm->cached_hole_size = ~0UL;
67456 + mm->free_area_cache = oldmm->free_area_cache;
67457 + mm->cached_hole_size = oldmm->cached_hole_size;
67458 mm->map_count = 0;
67459 cpumask_clear(mm_cpumask(mm));
67460 mm->mm_rb = RB_ROOT;
67461 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67462
67463 prev = NULL;
67464 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67465 - struct file *file;
67466 -
67467 if (mpnt->vm_flags & VM_DONTCOPY) {
67468 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67469 -vma_pages(mpnt));
67470 continue;
67471 }
67472 - charge = 0;
67473 - if (mpnt->vm_flags & VM_ACCOUNT) {
67474 - unsigned long len = vma_pages(mpnt);
67475 -
67476 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67477 - goto fail_nomem;
67478 - charge = len;
67479 - }
67480 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67481 - if (!tmp)
67482 - goto fail_nomem;
67483 - *tmp = *mpnt;
67484 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67485 - pol = mpol_dup(vma_policy(mpnt));
67486 - retval = PTR_ERR(pol);
67487 - if (IS_ERR(pol))
67488 - goto fail_nomem_policy;
67489 - vma_set_policy(tmp, pol);
67490 - tmp->vm_mm = mm;
67491 - if (anon_vma_fork(tmp, mpnt))
67492 - goto fail_nomem_anon_vma_fork;
67493 - tmp->vm_flags &= ~VM_LOCKED;
67494 - tmp->vm_next = tmp->vm_prev = NULL;
67495 - file = tmp->vm_file;
67496 - if (file) {
67497 - struct inode *inode = file->f_path.dentry->d_inode;
67498 - struct address_space *mapping = file->f_mapping;
67499 -
67500 - get_file(file);
67501 - if (tmp->vm_flags & VM_DENYWRITE)
67502 - atomic_dec(&inode->i_writecount);
67503 - mutex_lock(&mapping->i_mmap_mutex);
67504 - if (tmp->vm_flags & VM_SHARED)
67505 - mapping->i_mmap_writable++;
67506 - flush_dcache_mmap_lock(mapping);
67507 - /* insert tmp into the share list, just after mpnt */
67508 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
67509 - vma_nonlinear_insert(tmp,
67510 - &mapping->i_mmap_nonlinear);
67511 - else
67512 - vma_interval_tree_insert_after(tmp, mpnt,
67513 - &mapping->i_mmap);
67514 - flush_dcache_mmap_unlock(mapping);
67515 - mutex_unlock(&mapping->i_mmap_mutex);
67516 + tmp = dup_vma(mm, oldmm, mpnt);
67517 + if (!tmp) {
67518 + retval = -ENOMEM;
67519 + goto out;
67520 }
67521
67522 /*
67523 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67524 if (retval)
67525 goto out;
67526 }
67527 +
67528 +#ifdef CONFIG_PAX_SEGMEXEC
67529 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67530 + struct vm_area_struct *mpnt_m;
67531 +
67532 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67533 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67534 +
67535 + if (!mpnt->vm_mirror)
67536 + continue;
67537 +
67538 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67539 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67540 + mpnt->vm_mirror = mpnt_m;
67541 + } else {
67542 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67543 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67544 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67545 + mpnt->vm_mirror->vm_mirror = mpnt;
67546 + }
67547 + }
67548 + BUG_ON(mpnt_m);
67549 + }
67550 +#endif
67551 +
67552 /* a new mm has just been created */
67553 arch_dup_mmap(oldmm, mm);
67554 retval = 0;
67555 @@ -470,14 +521,6 @@ out:
67556 flush_tlb_mm(oldmm);
67557 up_write(&oldmm->mmap_sem);
67558 return retval;
67559 -fail_nomem_anon_vma_fork:
67560 - mpol_put(pol);
67561 -fail_nomem_policy:
67562 - kmem_cache_free(vm_area_cachep, tmp);
67563 -fail_nomem:
67564 - retval = -ENOMEM;
67565 - vm_unacct_memory(charge);
67566 - goto out;
67567 }
67568
67569 static inline int mm_alloc_pgd(struct mm_struct *mm)
67570 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67571 return ERR_PTR(err);
67572
67573 mm = get_task_mm(task);
67574 - if (mm && mm != current->mm &&
67575 - !ptrace_may_access(task, mode)) {
67576 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67577 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67578 mmput(mm);
67579 mm = ERR_PTR(-EACCES);
67580 }
67581 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67582 spin_unlock(&fs->lock);
67583 return -EAGAIN;
67584 }
67585 - fs->users++;
67586 + atomic_inc(&fs->users);
67587 spin_unlock(&fs->lock);
67588 return 0;
67589 }
67590 tsk->fs = copy_fs_struct(fs);
67591 if (!tsk->fs)
67592 return -ENOMEM;
67593 + /* Carry through gr_chroot_dentry and is_chrooted instead
67594 + of recomputing it here. Already copied when the task struct
67595 + is duplicated. This allows pivot_root to not be treated as
67596 + a chroot
67597 + */
67598 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67599 +
67600 return 0;
67601 }
67602
67603 @@ -1184,6 +1234,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67604 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67605 #endif
67606 retval = -EAGAIN;
67607 +
67608 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67609 +
67610 if (atomic_read(&p->real_cred->user->processes) >=
67611 task_rlimit(p, RLIMIT_NPROC)) {
67612 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67613 @@ -1402,6 +1455,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67614 /* Need tasklist lock for parent etc handling! */
67615 write_lock_irq(&tasklist_lock);
67616
67617 + /* synchronizes with gr_set_acls() */
67618 + gr_copy_label(p);
67619 +
67620 /* CLONE_PARENT re-uses the old parent */
67621 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67622 p->real_parent = current->real_parent;
67623 @@ -1512,6 +1568,8 @@ bad_fork_cleanup_count:
67624 bad_fork_free:
67625 free_task(p);
67626 fork_out:
67627 + gr_log_forkfail(retval);
67628 +
67629 return ERR_PTR(retval);
67630 }
67631
67632 @@ -1612,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
67633 if (clone_flags & CLONE_PARENT_SETTID)
67634 put_user(nr, parent_tidptr);
67635
67636 + gr_handle_brute_check();
67637 +
67638 if (clone_flags & CLONE_VFORK) {
67639 p->vfork_done = &vfork;
67640 init_completion(&vfork);
67641 @@ -1721,7 +1781,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67642 return 0;
67643
67644 /* don't need lock here; in the worst case we'll do useless copy */
67645 - if (fs->users == 1)
67646 + if (atomic_read(&fs->users) == 1)
67647 return 0;
67648
67649 *new_fsp = copy_fs_struct(fs);
67650 @@ -1810,7 +1870,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67651 fs = current->fs;
67652 spin_lock(&fs->lock);
67653 current->fs = new_fs;
67654 - if (--fs->users)
67655 + gr_set_chroot_entries(current, &current->fs->root);
67656 + if (atomic_dec_return(&fs->users))
67657 new_fs = NULL;
67658 else
67659 new_fs = fs;
67660 diff --git a/kernel/futex.c b/kernel/futex.c
67661 index 19eb089..b8c65ea 100644
67662 --- a/kernel/futex.c
67663 +++ b/kernel/futex.c
67664 @@ -54,6 +54,7 @@
67665 #include <linux/mount.h>
67666 #include <linux/pagemap.h>
67667 #include <linux/syscalls.h>
67668 +#include <linux/ptrace.h>
67669 #include <linux/signal.h>
67670 #include <linux/export.h>
67671 #include <linux/magic.h>
67672 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67673 struct page *page, *page_head;
67674 int err, ro = 0;
67675
67676 +#ifdef CONFIG_PAX_SEGMEXEC
67677 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67678 + return -EFAULT;
67679 +#endif
67680 +
67681 /*
67682 * The futex address must be "naturally" aligned.
67683 */
67684 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
67685 {
67686 u32 curval;
67687 int i;
67688 + mm_segment_t oldfs;
67689
67690 /*
67691 * This will fail and we want it. Some arch implementations do
67692 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
67693 * implementation, the non-functional ones will return
67694 * -ENOSYS.
67695 */
67696 + oldfs = get_fs();
67697 + set_fs(USER_DS);
67698 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67699 futex_cmpxchg_enabled = 1;
67700 + set_fs(oldfs);
67701
67702 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67703 plist_head_init(&futex_queues[i].chain);
67704 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67705 index 9b22d03..6295b62 100644
67706 --- a/kernel/gcov/base.c
67707 +++ b/kernel/gcov/base.c
67708 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67709 }
67710
67711 #ifdef CONFIG_MODULES
67712 -static inline int within(void *addr, void *start, unsigned long size)
67713 -{
67714 - return ((addr >= start) && (addr < start + size));
67715 -}
67716 -
67717 /* Update list and generate events when modules are unloaded. */
67718 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67719 void *data)
67720 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67721 prev = NULL;
67722 /* Remove entries located in module from linked list. */
67723 for (info = gcov_info_head; info; info = info->next) {
67724 - if (within(info, mod->module_core, mod->core_size)) {
67725 + if (within_module_core_rw((unsigned long)info, mod)) {
67726 if (prev)
67727 prev->next = info->next;
67728 else
67729 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67730 index 6db7a5e..25b6648 100644
67731 --- a/kernel/hrtimer.c
67732 +++ b/kernel/hrtimer.c
67733 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67734 local_irq_restore(flags);
67735 }
67736
67737 -static void run_hrtimer_softirq(struct softirq_action *h)
67738 +static void run_hrtimer_softirq(void)
67739 {
67740 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67741
67742 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67743 index 60f48fa..7f3a770 100644
67744 --- a/kernel/jump_label.c
67745 +++ b/kernel/jump_label.c
67746 @@ -13,6 +13,7 @@
67747 #include <linux/sort.h>
67748 #include <linux/err.h>
67749 #include <linux/static_key.h>
67750 +#include <linux/mm.h>
67751
67752 #ifdef HAVE_JUMP_LABEL
67753
67754 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67755
67756 size = (((unsigned long)stop - (unsigned long)start)
67757 / sizeof(struct jump_entry));
67758 + pax_open_kernel();
67759 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67760 + pax_close_kernel();
67761 }
67762
67763 static void jump_label_update(struct static_key *key, int enable);
67764 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67765 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67766 struct jump_entry *iter;
67767
67768 + pax_open_kernel();
67769 for (iter = iter_start; iter < iter_stop; iter++) {
67770 if (within_module_init(iter->code, mod))
67771 iter->code = 0;
67772 }
67773 + pax_close_kernel();
67774 }
67775
67776 static int
67777 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67778 index 2169fee..45c017a 100644
67779 --- a/kernel/kallsyms.c
67780 +++ b/kernel/kallsyms.c
67781 @@ -11,6 +11,9 @@
67782 * Changed the compression method from stem compression to "table lookup"
67783 * compression (see scripts/kallsyms.c for a more complete description)
67784 */
67785 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67786 +#define __INCLUDED_BY_HIDESYM 1
67787 +#endif
67788 #include <linux/kallsyms.h>
67789 #include <linux/module.h>
67790 #include <linux/init.h>
67791 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67792
67793 static inline int is_kernel_inittext(unsigned long addr)
67794 {
67795 + if (system_state != SYSTEM_BOOTING)
67796 + return 0;
67797 +
67798 if (addr >= (unsigned long)_sinittext
67799 && addr <= (unsigned long)_einittext)
67800 return 1;
67801 return 0;
67802 }
67803
67804 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67805 +#ifdef CONFIG_MODULES
67806 +static inline int is_module_text(unsigned long addr)
67807 +{
67808 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67809 + return 1;
67810 +
67811 + addr = ktla_ktva(addr);
67812 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67813 +}
67814 +#else
67815 +static inline int is_module_text(unsigned long addr)
67816 +{
67817 + return 0;
67818 +}
67819 +#endif
67820 +#endif
67821 +
67822 static inline int is_kernel_text(unsigned long addr)
67823 {
67824 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67825 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67826
67827 static inline int is_kernel(unsigned long addr)
67828 {
67829 +
67830 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67831 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67832 + return 1;
67833 +
67834 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67835 +#else
67836 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67837 +#endif
67838 +
67839 return 1;
67840 return in_gate_area_no_mm(addr);
67841 }
67842
67843 static int is_ksym_addr(unsigned long addr)
67844 {
67845 +
67846 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67847 + if (is_module_text(addr))
67848 + return 0;
67849 +#endif
67850 +
67851 if (all_var)
67852 return is_kernel(addr);
67853
67854 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67855
67856 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67857 {
67858 - iter->name[0] = '\0';
67859 iter->nameoff = get_symbol_offset(new_pos);
67860 iter->pos = new_pos;
67861 }
67862 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67863 {
67864 struct kallsym_iter *iter = m->private;
67865
67866 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67867 + if (current_uid())
67868 + return 0;
67869 +#endif
67870 +
67871 /* Some debugging symbols have no name. Ignore them. */
67872 if (!iter->name[0])
67873 return 0;
67874 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67875 */
67876 type = iter->exported ? toupper(iter->type) :
67877 tolower(iter->type);
67878 +
67879 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67880 type, iter->name, iter->module_name);
67881 } else
67882 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67883 struct kallsym_iter *iter;
67884 int ret;
67885
67886 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67887 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67888 if (!iter)
67889 return -ENOMEM;
67890 reset_iter(iter, 0);
67891 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67892 index 30b7b22..c726387 100644
67893 --- a/kernel/kcmp.c
67894 +++ b/kernel/kcmp.c
67895 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67896 struct task_struct *task1, *task2;
67897 int ret;
67898
67899 +#ifdef CONFIG_GRKERNSEC
67900 + return -ENOSYS;
67901 +#endif
67902 +
67903 rcu_read_lock();
67904
67905 /*
67906 diff --git a/kernel/kexec.c b/kernel/kexec.c
67907 index 5e4bd78..00c5b91 100644
67908 --- a/kernel/kexec.c
67909 +++ b/kernel/kexec.c
67910 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67911 unsigned long flags)
67912 {
67913 struct compat_kexec_segment in;
67914 - struct kexec_segment out, __user *ksegments;
67915 + struct kexec_segment out;
67916 + struct kexec_segment __user *ksegments;
67917 unsigned long i, result;
67918
67919 /* Don't allow clients that don't understand the native
67920 diff --git a/kernel/kmod.c b/kernel/kmod.c
67921 index 1c317e3..4a92a55 100644
67922 --- a/kernel/kmod.c
67923 +++ b/kernel/kmod.c
67924 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67925 kfree(info->argv);
67926 }
67927
67928 -static int call_modprobe(char *module_name, int wait)
67929 +static int call_modprobe(char *module_name, char *module_param, int wait)
67930 {
67931 static char *envp[] = {
67932 "HOME=/",
67933 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
67934 NULL
67935 };
67936
67937 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67938 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67939 if (!argv)
67940 goto out;
67941
67942 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
67943 argv[1] = "-q";
67944 argv[2] = "--";
67945 argv[3] = module_name; /* check free_modprobe_argv() */
67946 - argv[4] = NULL;
67947 + argv[4] = module_param;
67948 + argv[5] = NULL;
67949
67950 return call_usermodehelper_fns(modprobe_path, argv, envp,
67951 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67952 @@ -120,9 +121,8 @@ out:
67953 * If module auto-loading support is disabled then this function
67954 * becomes a no-operation.
67955 */
67956 -int __request_module(bool wait, const char *fmt, ...)
67957 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67958 {
67959 - va_list args;
67960 char module_name[MODULE_NAME_LEN];
67961 unsigned int max_modprobes;
67962 int ret;
67963 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
67964 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67965 static int kmod_loop_msg;
67966
67967 - va_start(args, fmt);
67968 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67969 - va_end(args);
67970 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67971 if (ret >= MODULE_NAME_LEN)
67972 return -ENAMETOOLONG;
67973
67974 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
67975 if (ret)
67976 return ret;
67977
67978 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67979 + if (!current_uid()) {
67980 + /* hack to workaround consolekit/udisks stupidity */
67981 + read_lock(&tasklist_lock);
67982 + if (!strcmp(current->comm, "mount") &&
67983 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67984 + read_unlock(&tasklist_lock);
67985 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67986 + return -EPERM;
67987 + }
67988 + read_unlock(&tasklist_lock);
67989 + }
67990 +#endif
67991 +
67992 /* If modprobe needs a service that is in a module, we get a recursive
67993 * loop. Limit the number of running kmod threads to max_threads/2 or
67994 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67995 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
67996
67997 trace_module_request(module_name, wait, _RET_IP_);
67998
67999 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68000 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68001
68002 atomic_dec(&kmod_concurrent);
68003 return ret;
68004 }
68005 +
68006 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68007 +{
68008 + va_list args;
68009 + int ret;
68010 +
68011 + va_start(args, fmt);
68012 + ret = ____request_module(wait, module_param, fmt, args);
68013 + va_end(args);
68014 +
68015 + return ret;
68016 +}
68017 +
68018 +int __request_module(bool wait, const char *fmt, ...)
68019 +{
68020 + va_list args;
68021 + int ret;
68022 +
68023 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68024 + if (current_uid()) {
68025 + char module_param[MODULE_NAME_LEN];
68026 +
68027 + memset(module_param, 0, sizeof(module_param));
68028 +
68029 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68030 +
68031 + va_start(args, fmt);
68032 + ret = ____request_module(wait, module_param, fmt, args);
68033 + va_end(args);
68034 +
68035 + return ret;
68036 + }
68037 +#endif
68038 +
68039 + va_start(args, fmt);
68040 + ret = ____request_module(wait, NULL, fmt, args);
68041 + va_end(args);
68042 +
68043 + return ret;
68044 +}
68045 +
68046 EXPORT_SYMBOL(__request_module);
68047 #endif /* CONFIG_MODULES */
68048
68049 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
68050 *
68051 * Thus the __user pointer cast is valid here.
68052 */
68053 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68054 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68055
68056 /*
68057 * If ret is 0, either ____call_usermodehelper failed and the
68058 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68059 index 098f396..fe85ff1 100644
68060 --- a/kernel/kprobes.c
68061 +++ b/kernel/kprobes.c
68062 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68063 * kernel image and loaded module images reside. This is required
68064 * so x86_64 can correctly handle the %rip-relative fixups.
68065 */
68066 - kip->insns = module_alloc(PAGE_SIZE);
68067 + kip->insns = module_alloc_exec(PAGE_SIZE);
68068 if (!kip->insns) {
68069 kfree(kip);
68070 return NULL;
68071 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68072 */
68073 if (!list_is_singular(&kip->list)) {
68074 list_del(&kip->list);
68075 - module_free(NULL, kip->insns);
68076 + module_free_exec(NULL, kip->insns);
68077 kfree(kip);
68078 }
68079 return 1;
68080 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
68081 {
68082 int i, err = 0;
68083 unsigned long offset = 0, size = 0;
68084 - char *modname, namebuf[128];
68085 + char *modname, namebuf[KSYM_NAME_LEN];
68086 const char *symbol_name;
68087 void *addr;
68088 struct kprobe_blackpoint *kb;
68089 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68090 kprobe_type = "k";
68091
68092 if (sym)
68093 - seq_printf(pi, "%p %s %s+0x%x %s ",
68094 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68095 p->addr, kprobe_type, sym, offset,
68096 (modname ? modname : " "));
68097 else
68098 - seq_printf(pi, "%p %s %p ",
68099 + seq_printf(pi, "%pK %s %pK ",
68100 p->addr, kprobe_type, p->addr);
68101
68102 if (!pp)
68103 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68104 const char *sym = NULL;
68105 unsigned int i = *(loff_t *) v;
68106 unsigned long offset = 0;
68107 - char *modname, namebuf[128];
68108 + char *modname, namebuf[KSYM_NAME_LEN];
68109
68110 head = &kprobe_table[i];
68111 preempt_disable();
68112 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68113 index 4e316e1..5501eef 100644
68114 --- a/kernel/ksysfs.c
68115 +++ b/kernel/ksysfs.c
68116 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68117 {
68118 if (count+1 > UEVENT_HELPER_PATH_LEN)
68119 return -ENOENT;
68120 + if (!capable(CAP_SYS_ADMIN))
68121 + return -EPERM;
68122 memcpy(uevent_helper, buf, count);
68123 uevent_helper[count] = '\0';
68124 if (count && uevent_helper[count-1] == '\n')
68125 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68126 index 7981e5b..7f2105c 100644
68127 --- a/kernel/lockdep.c
68128 +++ b/kernel/lockdep.c
68129 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68130 end = (unsigned long) &_end,
68131 addr = (unsigned long) obj;
68132
68133 +#ifdef CONFIG_PAX_KERNEXEC
68134 + start = ktla_ktva(start);
68135 +#endif
68136 +
68137 /*
68138 * static variable?
68139 */
68140 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68141 if (!static_obj(lock->key)) {
68142 debug_locks_off();
68143 printk("INFO: trying to register non-static key.\n");
68144 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68145 printk("the code is fine but needs lockdep annotation.\n");
68146 printk("turning off the locking correctness validator.\n");
68147 dump_stack();
68148 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68149 if (!class)
68150 return 0;
68151 }
68152 - atomic_inc((atomic_t *)&class->ops);
68153 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68154 if (very_verbose(class)) {
68155 printk("\nacquire class [%p] %s", class->key, class->name);
68156 if (class->name_version > 1)
68157 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68158 index 91c32a0..7b88d63 100644
68159 --- a/kernel/lockdep_proc.c
68160 +++ b/kernel/lockdep_proc.c
68161 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68162
68163 static void print_name(struct seq_file *m, struct lock_class *class)
68164 {
68165 - char str[128];
68166 + char str[KSYM_NAME_LEN];
68167 const char *name = class->name;
68168
68169 if (!name) {
68170 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68171 return 0;
68172 }
68173
68174 - seq_printf(m, "%p", class->key);
68175 + seq_printf(m, "%pK", class->key);
68176 #ifdef CONFIG_DEBUG_LOCKDEP
68177 seq_printf(m, " OPS:%8ld", class->ops);
68178 #endif
68179 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68180
68181 list_for_each_entry(entry, &class->locks_after, entry) {
68182 if (entry->distance == 1) {
68183 - seq_printf(m, " -> [%p] ", entry->class->key);
68184 + seq_printf(m, " -> [%pK] ", entry->class->key);
68185 print_name(m, entry->class);
68186 seq_puts(m, "\n");
68187 }
68188 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68189 if (!class->key)
68190 continue;
68191
68192 - seq_printf(m, "[%p] ", class->key);
68193 + seq_printf(m, "[%pK] ", class->key);
68194 print_name(m, class);
68195 seq_puts(m, "\n");
68196 }
68197 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68198 if (!i)
68199 seq_line(m, '-', 40-namelen, namelen);
68200
68201 - snprintf(ip, sizeof(ip), "[<%p>]",
68202 + snprintf(ip, sizeof(ip), "[<%pK>]",
68203 (void *)class->contention_point[i]);
68204 seq_printf(m, "%40s %14lu %29s %pS\n",
68205 name, stats->contention_point[i],
68206 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68207 if (!i)
68208 seq_line(m, '-', 40-namelen, namelen);
68209
68210 - snprintf(ip, sizeof(ip), "[<%p>]",
68211 + snprintf(ip, sizeof(ip), "[<%pK>]",
68212 (void *)class->contending_point[i]);
68213 seq_printf(m, "%40s %14lu %29s %pS\n",
68214 name, stats->contending_point[i],
68215 diff --git a/kernel/module.c b/kernel/module.c
68216 index 6e48c3a..ac2ef5b 100644
68217 --- a/kernel/module.c
68218 +++ b/kernel/module.c
68219 @@ -59,6 +59,7 @@
68220 #include <linux/pfn.h>
68221 #include <linux/bsearch.h>
68222 #include <linux/fips.h>
68223 +#include <linux/grsecurity.h>
68224 #include "module-internal.h"
68225
68226 #define CREATE_TRACE_POINTS
68227 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68228
68229 /* Bounds of module allocation, for speeding __module_address.
68230 * Protected by module_mutex. */
68231 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68232 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68233 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68234
68235 int register_module_notifier(struct notifier_block * nb)
68236 {
68237 @@ -318,7 +320,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68238 return true;
68239
68240 list_for_each_entry_rcu(mod, &modules, list) {
68241 - struct symsearch arr[] = {
68242 + struct symsearch modarr[] = {
68243 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68244 NOT_GPL_ONLY, false },
68245 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68246 @@ -340,7 +342,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68247 #endif
68248 };
68249
68250 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68251 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68252 return true;
68253 }
68254 return false;
68255 @@ -472,7 +474,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68256 static int percpu_modalloc(struct module *mod,
68257 unsigned long size, unsigned long align)
68258 {
68259 - if (align > PAGE_SIZE) {
68260 + if (align-1 >= PAGE_SIZE) {
68261 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68262 mod->name, align, PAGE_SIZE);
68263 align = PAGE_SIZE;
68264 @@ -1072,7 +1074,7 @@ struct module_attribute module_uevent =
68265 static ssize_t show_coresize(struct module_attribute *mattr,
68266 struct module_kobject *mk, char *buffer)
68267 {
68268 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68269 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68270 }
68271
68272 static struct module_attribute modinfo_coresize =
68273 @@ -1081,7 +1083,7 @@ static struct module_attribute modinfo_coresize =
68274 static ssize_t show_initsize(struct module_attribute *mattr,
68275 struct module_kobject *mk, char *buffer)
68276 {
68277 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68278 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68279 }
68280
68281 static struct module_attribute modinfo_initsize =
68282 @@ -1295,7 +1297,7 @@ resolve_symbol_wait(struct module *mod,
68283 */
68284 #ifdef CONFIG_SYSFS
68285
68286 -#ifdef CONFIG_KALLSYMS
68287 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68288 static inline bool sect_empty(const Elf_Shdr *sect)
68289 {
68290 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68291 @@ -1761,21 +1763,21 @@ static void set_section_ro_nx(void *base,
68292
68293 static void unset_module_core_ro_nx(struct module *mod)
68294 {
68295 - set_page_attributes(mod->module_core + mod->core_text_size,
68296 - mod->module_core + mod->core_size,
68297 + set_page_attributes(mod->module_core_rw,
68298 + mod->module_core_rw + mod->core_size_rw,
68299 set_memory_x);
68300 - set_page_attributes(mod->module_core,
68301 - mod->module_core + mod->core_ro_size,
68302 + set_page_attributes(mod->module_core_rx,
68303 + mod->module_core_rx + mod->core_size_rx,
68304 set_memory_rw);
68305 }
68306
68307 static void unset_module_init_ro_nx(struct module *mod)
68308 {
68309 - set_page_attributes(mod->module_init + mod->init_text_size,
68310 - mod->module_init + mod->init_size,
68311 + set_page_attributes(mod->module_init_rw,
68312 + mod->module_init_rw + mod->init_size_rw,
68313 set_memory_x);
68314 - set_page_attributes(mod->module_init,
68315 - mod->module_init + mod->init_ro_size,
68316 + set_page_attributes(mod->module_init_rx,
68317 + mod->module_init_rx + mod->init_size_rx,
68318 set_memory_rw);
68319 }
68320
68321 @@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
68322
68323 mutex_lock(&module_mutex);
68324 list_for_each_entry_rcu(mod, &modules, list) {
68325 - if ((mod->module_core) && (mod->core_text_size)) {
68326 - set_page_attributes(mod->module_core,
68327 - mod->module_core + mod->core_text_size,
68328 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68329 + set_page_attributes(mod->module_core_rx,
68330 + mod->module_core_rx + mod->core_size_rx,
68331 set_memory_rw);
68332 }
68333 - if ((mod->module_init) && (mod->init_text_size)) {
68334 - set_page_attributes(mod->module_init,
68335 - mod->module_init + mod->init_text_size,
68336 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68337 + set_page_attributes(mod->module_init_rx,
68338 + mod->module_init_rx + mod->init_size_rx,
68339 set_memory_rw);
68340 }
68341 }
68342 @@ -1807,14 +1809,14 @@ void set_all_modules_text_ro(void)
68343
68344 mutex_lock(&module_mutex);
68345 list_for_each_entry_rcu(mod, &modules, list) {
68346 - if ((mod->module_core) && (mod->core_text_size)) {
68347 - set_page_attributes(mod->module_core,
68348 - mod->module_core + mod->core_text_size,
68349 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68350 + set_page_attributes(mod->module_core_rx,
68351 + mod->module_core_rx + mod->core_size_rx,
68352 set_memory_ro);
68353 }
68354 - if ((mod->module_init) && (mod->init_text_size)) {
68355 - set_page_attributes(mod->module_init,
68356 - mod->module_init + mod->init_text_size,
68357 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68358 + set_page_attributes(mod->module_init_rx,
68359 + mod->module_init_rx + mod->init_size_rx,
68360 set_memory_ro);
68361 }
68362 }
68363 @@ -1860,16 +1862,19 @@ static void free_module(struct module *mod)
68364
68365 /* This may be NULL, but that's OK */
68366 unset_module_init_ro_nx(mod);
68367 - module_free(mod, mod->module_init);
68368 + module_free(mod, mod->module_init_rw);
68369 + module_free_exec(mod, mod->module_init_rx);
68370 kfree(mod->args);
68371 percpu_modfree(mod);
68372
68373 /* Free lock-classes: */
68374 - lockdep_free_key_range(mod->module_core, mod->core_size);
68375 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68376 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68377
68378 /* Finally, free the core (containing the module structure) */
68379 unset_module_core_ro_nx(mod);
68380 - module_free(mod, mod->module_core);
68381 + module_free_exec(mod, mod->module_core_rx);
68382 + module_free(mod, mod->module_core_rw);
68383
68384 #ifdef CONFIG_MPU
68385 update_protections(current->mm);
68386 @@ -1939,9 +1944,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68387 int ret = 0;
68388 const struct kernel_symbol *ksym;
68389
68390 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68391 + int is_fs_load = 0;
68392 + int register_filesystem_found = 0;
68393 + char *p;
68394 +
68395 + p = strstr(mod->args, "grsec_modharden_fs");
68396 + if (p) {
68397 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68398 + /* copy \0 as well */
68399 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68400 + is_fs_load = 1;
68401 + }
68402 +#endif
68403 +
68404 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68405 const char *name = info->strtab + sym[i].st_name;
68406
68407 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68408 + /* it's a real shame this will never get ripped and copied
68409 + upstream! ;(
68410 + */
68411 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68412 + register_filesystem_found = 1;
68413 +#endif
68414 +
68415 switch (sym[i].st_shndx) {
68416 case SHN_COMMON:
68417 /* We compiled with -fno-common. These are not
68418 @@ -1962,7 +1989,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68419 ksym = resolve_symbol_wait(mod, info, name);
68420 /* Ok if resolved. */
68421 if (ksym && !IS_ERR(ksym)) {
68422 + pax_open_kernel();
68423 sym[i].st_value = ksym->value;
68424 + pax_close_kernel();
68425 break;
68426 }
68427
68428 @@ -1981,11 +2010,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68429 secbase = (unsigned long)mod_percpu(mod);
68430 else
68431 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68432 + pax_open_kernel();
68433 sym[i].st_value += secbase;
68434 + pax_close_kernel();
68435 break;
68436 }
68437 }
68438
68439 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68440 + if (is_fs_load && !register_filesystem_found) {
68441 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68442 + ret = -EPERM;
68443 + }
68444 +#endif
68445 +
68446 return ret;
68447 }
68448
68449 @@ -2069,22 +2107,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68450 || s->sh_entsize != ~0UL
68451 || strstarts(sname, ".init"))
68452 continue;
68453 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68454 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68455 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68456 + else
68457 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68458 pr_debug("\t%s\n", sname);
68459 }
68460 - switch (m) {
68461 - case 0: /* executable */
68462 - mod->core_size = debug_align(mod->core_size);
68463 - mod->core_text_size = mod->core_size;
68464 - break;
68465 - case 1: /* RO: text and ro-data */
68466 - mod->core_size = debug_align(mod->core_size);
68467 - mod->core_ro_size = mod->core_size;
68468 - break;
68469 - case 3: /* whole core */
68470 - mod->core_size = debug_align(mod->core_size);
68471 - break;
68472 - }
68473 }
68474
68475 pr_debug("Init section allocation order:\n");
68476 @@ -2098,23 +2126,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68477 || s->sh_entsize != ~0UL
68478 || !strstarts(sname, ".init"))
68479 continue;
68480 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68481 - | INIT_OFFSET_MASK);
68482 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68483 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68484 + else
68485 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68486 + s->sh_entsize |= INIT_OFFSET_MASK;
68487 pr_debug("\t%s\n", sname);
68488 }
68489 - switch (m) {
68490 - case 0: /* executable */
68491 - mod->init_size = debug_align(mod->init_size);
68492 - mod->init_text_size = mod->init_size;
68493 - break;
68494 - case 1: /* RO: text and ro-data */
68495 - mod->init_size = debug_align(mod->init_size);
68496 - mod->init_ro_size = mod->init_size;
68497 - break;
68498 - case 3: /* whole init */
68499 - mod->init_size = debug_align(mod->init_size);
68500 - break;
68501 - }
68502 }
68503 }
68504
68505 @@ -2286,7 +2304,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68506
68507 /* Put symbol section at end of init part of module. */
68508 symsect->sh_flags |= SHF_ALLOC;
68509 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68510 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68511 info->index.sym) | INIT_OFFSET_MASK;
68512 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68513
68514 @@ -2306,13 +2324,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68515 }
68516
68517 /* Append room for core symbols at end of core part. */
68518 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68519 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68520 - mod->core_size += strtab_size;
68521 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68522 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68523 + mod->core_size_rx += strtab_size;
68524
68525 /* Put string table section at end of init part of module. */
68526 strsect->sh_flags |= SHF_ALLOC;
68527 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68528 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68529 info->index.str) | INIT_OFFSET_MASK;
68530 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68531 }
68532 @@ -2330,12 +2348,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68533 /* Make sure we get permanent strtab: don't use info->strtab. */
68534 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68535
68536 + pax_open_kernel();
68537 +
68538 /* Set types up while we still have access to sections. */
68539 for (i = 0; i < mod->num_symtab; i++)
68540 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68541
68542 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68543 - mod->core_strtab = s = mod->module_core + info->stroffs;
68544 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68545 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68546 src = mod->symtab;
68547 *s++ = 0;
68548 for (ndst = i = 0; i < mod->num_symtab; i++) {
68549 @@ -2348,6 +2368,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68550 }
68551 }
68552 mod->core_num_syms = ndst;
68553 +
68554 + pax_close_kernel();
68555 }
68556 #else
68557 static inline void layout_symtab(struct module *mod, struct load_info *info)
68558 @@ -2381,17 +2403,33 @@ void * __weak module_alloc(unsigned long size)
68559 return size == 0 ? NULL : vmalloc_exec(size);
68560 }
68561
68562 -static void *module_alloc_update_bounds(unsigned long size)
68563 +static void *module_alloc_update_bounds_rw(unsigned long size)
68564 {
68565 void *ret = module_alloc(size);
68566
68567 if (ret) {
68568 mutex_lock(&module_mutex);
68569 /* Update module bounds. */
68570 - if ((unsigned long)ret < module_addr_min)
68571 - module_addr_min = (unsigned long)ret;
68572 - if ((unsigned long)ret + size > module_addr_max)
68573 - module_addr_max = (unsigned long)ret + size;
68574 + if ((unsigned long)ret < module_addr_min_rw)
68575 + module_addr_min_rw = (unsigned long)ret;
68576 + if ((unsigned long)ret + size > module_addr_max_rw)
68577 + module_addr_max_rw = (unsigned long)ret + size;
68578 + mutex_unlock(&module_mutex);
68579 + }
68580 + return ret;
68581 +}
68582 +
68583 +static void *module_alloc_update_bounds_rx(unsigned long size)
68584 +{
68585 + void *ret = module_alloc_exec(size);
68586 +
68587 + if (ret) {
68588 + mutex_lock(&module_mutex);
68589 + /* Update module bounds. */
68590 + if ((unsigned long)ret < module_addr_min_rx)
68591 + module_addr_min_rx = (unsigned long)ret;
68592 + if ((unsigned long)ret + size > module_addr_max_rx)
68593 + module_addr_max_rx = (unsigned long)ret + size;
68594 mutex_unlock(&module_mutex);
68595 }
68596 return ret;
68597 @@ -2610,8 +2648,14 @@ static struct module *setup_load_info(struct load_info *info)
68598 static int check_modinfo(struct module *mod, struct load_info *info)
68599 {
68600 const char *modmagic = get_modinfo(info, "vermagic");
68601 + const char *license = get_modinfo(info, "license");
68602 int err;
68603
68604 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68605 + if (!license || !license_is_gpl_compatible(license))
68606 + return -ENOEXEC;
68607 +#endif
68608 +
68609 /* This is allowed: modprobe --force will invalidate it. */
68610 if (!modmagic) {
68611 err = try_to_force_load(mod, "bad vermagic");
68612 @@ -2634,7 +2678,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68613 }
68614
68615 /* Set up license info based on the info section */
68616 - set_license(mod, get_modinfo(info, "license"));
68617 + set_license(mod, license);
68618
68619 return 0;
68620 }
68621 @@ -2728,7 +2772,7 @@ static int move_module(struct module *mod, struct load_info *info)
68622 void *ptr;
68623
68624 /* Do the allocs. */
68625 - ptr = module_alloc_update_bounds(mod->core_size);
68626 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68627 /*
68628 * The pointer to this block is stored in the module structure
68629 * which is inside the block. Just mark it as not being a
68630 @@ -2738,23 +2782,50 @@ static int move_module(struct module *mod, struct load_info *info)
68631 if (!ptr)
68632 return -ENOMEM;
68633
68634 - memset(ptr, 0, mod->core_size);
68635 - mod->module_core = ptr;
68636 + memset(ptr, 0, mod->core_size_rw);
68637 + mod->module_core_rw = ptr;
68638
68639 - ptr = module_alloc_update_bounds(mod->init_size);
68640 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68641 /*
68642 * The pointer to this block is stored in the module structure
68643 * which is inside the block. This block doesn't need to be
68644 * scanned as it contains data and code that will be freed
68645 * after the module is initialized.
68646 */
68647 - kmemleak_ignore(ptr);
68648 - if (!ptr && mod->init_size) {
68649 - module_free(mod, mod->module_core);
68650 + kmemleak_not_leak(ptr);
68651 + if (!ptr && mod->init_size_rw) {
68652 + module_free(mod, mod->module_core_rw);
68653 return -ENOMEM;
68654 }
68655 - memset(ptr, 0, mod->init_size);
68656 - mod->module_init = ptr;
68657 + memset(ptr, 0, mod->init_size_rw);
68658 + mod->module_init_rw = ptr;
68659 +
68660 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68661 + kmemleak_not_leak(ptr);
68662 + if (!ptr) {
68663 + module_free(mod, mod->module_init_rw);
68664 + module_free(mod, mod->module_core_rw);
68665 + return -ENOMEM;
68666 + }
68667 +
68668 + pax_open_kernel();
68669 + memset(ptr, 0, mod->core_size_rx);
68670 + pax_close_kernel();
68671 + mod->module_core_rx = ptr;
68672 +
68673 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68674 + kmemleak_not_leak(ptr);
68675 + if (!ptr && mod->init_size_rx) {
68676 + module_free_exec(mod, mod->module_core_rx);
68677 + module_free(mod, mod->module_init_rw);
68678 + module_free(mod, mod->module_core_rw);
68679 + return -ENOMEM;
68680 + }
68681 +
68682 + pax_open_kernel();
68683 + memset(ptr, 0, mod->init_size_rx);
68684 + pax_close_kernel();
68685 + mod->module_init_rx = ptr;
68686
68687 /* Transfer each section which specifies SHF_ALLOC */
68688 pr_debug("final section addresses:\n");
68689 @@ -2765,16 +2836,45 @@ static int move_module(struct module *mod, struct load_info *info)
68690 if (!(shdr->sh_flags & SHF_ALLOC))
68691 continue;
68692
68693 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68694 - dest = mod->module_init
68695 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68696 - else
68697 - dest = mod->module_core + shdr->sh_entsize;
68698 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68699 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68700 + dest = mod->module_init_rw
68701 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68702 + else
68703 + dest = mod->module_init_rx
68704 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68705 + } else {
68706 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68707 + dest = mod->module_core_rw + shdr->sh_entsize;
68708 + else
68709 + dest = mod->module_core_rx + shdr->sh_entsize;
68710 + }
68711 +
68712 + if (shdr->sh_type != SHT_NOBITS) {
68713 +
68714 +#ifdef CONFIG_PAX_KERNEXEC
68715 +#ifdef CONFIG_X86_64
68716 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68717 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68718 +#endif
68719 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68720 + pax_open_kernel();
68721 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68722 + pax_close_kernel();
68723 + } else
68724 +#endif
68725
68726 - if (shdr->sh_type != SHT_NOBITS)
68727 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68728 + }
68729 /* Update sh_addr to point to copy in image. */
68730 - shdr->sh_addr = (unsigned long)dest;
68731 +
68732 +#ifdef CONFIG_PAX_KERNEXEC
68733 + if (shdr->sh_flags & SHF_EXECINSTR)
68734 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68735 + else
68736 +#endif
68737 +
68738 + shdr->sh_addr = (unsigned long)dest;
68739 pr_debug("\t0x%lx %s\n",
68740 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68741 }
68742 @@ -2829,12 +2929,12 @@ static void flush_module_icache(const struct module *mod)
68743 * Do it before processing of module parameters, so the module
68744 * can provide parameter accessor functions of its own.
68745 */
68746 - if (mod->module_init)
68747 - flush_icache_range((unsigned long)mod->module_init,
68748 - (unsigned long)mod->module_init
68749 - + mod->init_size);
68750 - flush_icache_range((unsigned long)mod->module_core,
68751 - (unsigned long)mod->module_core + mod->core_size);
68752 + if (mod->module_init_rx)
68753 + flush_icache_range((unsigned long)mod->module_init_rx,
68754 + (unsigned long)mod->module_init_rx
68755 + + mod->init_size_rx);
68756 + flush_icache_range((unsigned long)mod->module_core_rx,
68757 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68758
68759 set_fs(old_fs);
68760 }
68761 @@ -2904,8 +3004,10 @@ out:
68762 static void module_deallocate(struct module *mod, struct load_info *info)
68763 {
68764 percpu_modfree(mod);
68765 - module_free(mod, mod->module_init);
68766 - module_free(mod, mod->module_core);
68767 + module_free_exec(mod, mod->module_init_rx);
68768 + module_free_exec(mod, mod->module_core_rx);
68769 + module_free(mod, mod->module_init_rw);
68770 + module_free(mod, mod->module_core_rw);
68771 }
68772
68773 int __weak module_finalize(const Elf_Ehdr *hdr,
68774 @@ -2918,7 +3020,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68775 static int post_relocation(struct module *mod, const struct load_info *info)
68776 {
68777 /* Sort exception table now relocations are done. */
68778 + pax_open_kernel();
68779 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68780 + pax_close_kernel();
68781
68782 /* Copy relocated percpu area over. */
68783 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68784 @@ -2989,9 +3093,38 @@ static struct module *load_module(void __user *umod,
68785 if (err)
68786 goto free_unload;
68787
68788 + /* Now copy in args */
68789 + mod->args = strndup_user(uargs, ~0UL >> 1);
68790 + if (IS_ERR(mod->args)) {
68791 + err = PTR_ERR(mod->args);
68792 + goto free_unload;
68793 + }
68794 +
68795 /* Set up MODINFO_ATTR fields */
68796 setup_modinfo(mod, &info);
68797
68798 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68799 + {
68800 + char *p, *p2;
68801 +
68802 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68803 + 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);
68804 + err = -EPERM;
68805 + goto free_modinfo;
68806 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68807 + p += sizeof("grsec_modharden_normal") - 1;
68808 + p2 = strstr(p, "_");
68809 + if (p2) {
68810 + *p2 = '\0';
68811 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68812 + *p2 = '_';
68813 + }
68814 + err = -EPERM;
68815 + goto free_modinfo;
68816 + }
68817 + }
68818 +#endif
68819 +
68820 /* Fix up syms, so that st_value is a pointer to location. */
68821 err = simplify_symbols(mod, &info);
68822 if (err < 0)
68823 @@ -3007,13 +3140,6 @@ static struct module *load_module(void __user *umod,
68824
68825 flush_module_icache(mod);
68826
68827 - /* Now copy in args */
68828 - mod->args = strndup_user(uargs, ~0UL >> 1);
68829 - if (IS_ERR(mod->args)) {
68830 - err = PTR_ERR(mod->args);
68831 - goto free_arch_cleanup;
68832 - }
68833 -
68834 /* Mark state as coming so strong_try_module_get() ignores us. */
68835 mod->state = MODULE_STATE_COMING;
68836
68837 @@ -3081,11 +3207,11 @@ again:
68838 unlock:
68839 mutex_unlock(&module_mutex);
68840 synchronize_sched();
68841 - kfree(mod->args);
68842 free_arch_cleanup:
68843 module_arch_cleanup(mod);
68844 free_modinfo:
68845 free_modinfo(mod);
68846 + kfree(mod->args);
68847 free_unload:
68848 module_unload_free(mod);
68849 free_module:
68850 @@ -3126,16 +3252,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68851 MODULE_STATE_COMING, mod);
68852
68853 /* Set RO and NX regions for core */
68854 - set_section_ro_nx(mod->module_core,
68855 - mod->core_text_size,
68856 - mod->core_ro_size,
68857 - mod->core_size);
68858 + set_section_ro_nx(mod->module_core_rx,
68859 + mod->core_size_rx,
68860 + mod->core_size_rx,
68861 + mod->core_size_rx);
68862
68863 /* Set RO and NX regions for init */
68864 - set_section_ro_nx(mod->module_init,
68865 - mod->init_text_size,
68866 - mod->init_ro_size,
68867 - mod->init_size);
68868 + set_section_ro_nx(mod->module_init_rx,
68869 + mod->init_size_rx,
68870 + mod->init_size_rx,
68871 + mod->init_size_rx);
68872
68873 do_mod_ctors(mod);
68874 /* Start the module */
68875 @@ -3180,11 +3306,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68876 mod->strtab = mod->core_strtab;
68877 #endif
68878 unset_module_init_ro_nx(mod);
68879 - module_free(mod, mod->module_init);
68880 - mod->module_init = NULL;
68881 - mod->init_size = 0;
68882 - mod->init_ro_size = 0;
68883 - mod->init_text_size = 0;
68884 + module_free(mod, mod->module_init_rw);
68885 + module_free_exec(mod, mod->module_init_rx);
68886 + mod->module_init_rw = NULL;
68887 + mod->module_init_rx = NULL;
68888 + mod->init_size_rw = 0;
68889 + mod->init_size_rx = 0;
68890 mutex_unlock(&module_mutex);
68891 wake_up_all(&module_wq);
68892
68893 @@ -3216,10 +3343,16 @@ static const char *get_ksymbol(struct module *mod,
68894 unsigned long nextval;
68895
68896 /* At worse, next value is at end of module */
68897 - if (within_module_init(addr, mod))
68898 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68899 + if (within_module_init_rx(addr, mod))
68900 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68901 + else if (within_module_init_rw(addr, mod))
68902 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68903 + else if (within_module_core_rx(addr, mod))
68904 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68905 + else if (within_module_core_rw(addr, mod))
68906 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68907 else
68908 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68909 + return NULL;
68910
68911 /* Scan for closest preceding symbol, and next symbol. (ELF
68912 starts real symbols at 1). */
68913 @@ -3454,7 +3587,7 @@ static int m_show(struct seq_file *m, void *p)
68914 char buf[8];
68915
68916 seq_printf(m, "%s %u",
68917 - mod->name, mod->init_size + mod->core_size);
68918 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68919 print_unload_info(m, mod);
68920
68921 /* Informative for users. */
68922 @@ -3463,7 +3596,7 @@ static int m_show(struct seq_file *m, void *p)
68923 mod->state == MODULE_STATE_COMING ? "Loading":
68924 "Live");
68925 /* Used by oprofile and other similar tools. */
68926 - seq_printf(m, " 0x%pK", mod->module_core);
68927 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68928
68929 /* Taints info */
68930 if (mod->taints)
68931 @@ -3499,7 +3632,17 @@ static const struct file_operations proc_modules_operations = {
68932
68933 static int __init proc_modules_init(void)
68934 {
68935 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68936 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68937 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68938 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68939 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68940 +#else
68941 proc_create("modules", 0, NULL, &proc_modules_operations);
68942 +#endif
68943 +#else
68944 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68945 +#endif
68946 return 0;
68947 }
68948 module_init(proc_modules_init);
68949 @@ -3558,12 +3701,12 @@ struct module *__module_address(unsigned long addr)
68950 {
68951 struct module *mod;
68952
68953 - if (addr < module_addr_min || addr > module_addr_max)
68954 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68955 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68956 return NULL;
68957
68958 list_for_each_entry_rcu(mod, &modules, list)
68959 - if (within_module_core(addr, mod)
68960 - || within_module_init(addr, mod))
68961 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68962 return mod;
68963 return NULL;
68964 }
68965 @@ -3597,11 +3740,20 @@ bool is_module_text_address(unsigned long addr)
68966 */
68967 struct module *__module_text_address(unsigned long addr)
68968 {
68969 - struct module *mod = __module_address(addr);
68970 + struct module *mod;
68971 +
68972 +#ifdef CONFIG_X86_32
68973 + addr = ktla_ktva(addr);
68974 +#endif
68975 +
68976 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68977 + return NULL;
68978 +
68979 + mod = __module_address(addr);
68980 +
68981 if (mod) {
68982 /* Make sure it's within the text section. */
68983 - if (!within(addr, mod->module_init, mod->init_text_size)
68984 - && !within(addr, mod->module_core, mod->core_text_size))
68985 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68986 mod = NULL;
68987 }
68988 return mod;
68989 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68990 index 7e3443f..b2a1e6b 100644
68991 --- a/kernel/mutex-debug.c
68992 +++ b/kernel/mutex-debug.c
68993 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68994 }
68995
68996 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68997 - struct thread_info *ti)
68998 + struct task_struct *task)
68999 {
69000 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69001
69002 /* Mark the current thread as blocked on the lock: */
69003 - ti->task->blocked_on = waiter;
69004 + task->blocked_on = waiter;
69005 }
69006
69007 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69008 - struct thread_info *ti)
69009 + struct task_struct *task)
69010 {
69011 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69012 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69013 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69014 - ti->task->blocked_on = NULL;
69015 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69016 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69017 + task->blocked_on = NULL;
69018
69019 list_del_init(&waiter->list);
69020 waiter->task = NULL;
69021 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69022 index 0799fd3..d06ae3b 100644
69023 --- a/kernel/mutex-debug.h
69024 +++ b/kernel/mutex-debug.h
69025 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69026 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69027 extern void debug_mutex_add_waiter(struct mutex *lock,
69028 struct mutex_waiter *waiter,
69029 - struct thread_info *ti);
69030 + struct task_struct *task);
69031 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69032 - struct thread_info *ti);
69033 + struct task_struct *task);
69034 extern void debug_mutex_unlock(struct mutex *lock);
69035 extern void debug_mutex_init(struct mutex *lock, const char *name,
69036 struct lock_class_key *key);
69037 diff --git a/kernel/mutex.c b/kernel/mutex.c
69038 index a307cc9..27fd2e9 100644
69039 --- a/kernel/mutex.c
69040 +++ b/kernel/mutex.c
69041 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69042 spin_lock_mutex(&lock->wait_lock, flags);
69043
69044 debug_mutex_lock_common(lock, &waiter);
69045 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69046 + debug_mutex_add_waiter(lock, &waiter, task);
69047
69048 /* add waiting tasks to the end of the waitqueue (FIFO): */
69049 list_add_tail(&waiter.list, &lock->wait_list);
69050 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69051 * TASK_UNINTERRUPTIBLE case.)
69052 */
69053 if (unlikely(signal_pending_state(state, task))) {
69054 - mutex_remove_waiter(lock, &waiter,
69055 - task_thread_info(task));
69056 + mutex_remove_waiter(lock, &waiter, task);
69057 mutex_release(&lock->dep_map, 1, ip);
69058 spin_unlock_mutex(&lock->wait_lock, flags);
69059
69060 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69061 done:
69062 lock_acquired(&lock->dep_map, ip);
69063 /* got the lock - rejoice! */
69064 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69065 + mutex_remove_waiter(lock, &waiter, task);
69066 mutex_set_owner(lock);
69067
69068 /* set it to 0 if there are no waiters left: */
69069 diff --git a/kernel/panic.c b/kernel/panic.c
69070 index e1b2822..5edc1d9 100644
69071 --- a/kernel/panic.c
69072 +++ b/kernel/panic.c
69073 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69074 const char *board;
69075
69076 printk(KERN_WARNING "------------[ cut here ]------------\n");
69077 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69078 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69079 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69080 if (board)
69081 printk(KERN_WARNING "Hardware name: %s\n", board);
69082 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69083 */
69084 void __stack_chk_fail(void)
69085 {
69086 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69087 + dump_stack();
69088 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69089 __builtin_return_address(0));
69090 }
69091 EXPORT_SYMBOL(__stack_chk_fail);
69092 diff --git a/kernel/pid.c b/kernel/pid.c
69093 index aebd4f5..1693c13 100644
69094 --- a/kernel/pid.c
69095 +++ b/kernel/pid.c
69096 @@ -33,6 +33,7 @@
69097 #include <linux/rculist.h>
69098 #include <linux/bootmem.h>
69099 #include <linux/hash.h>
69100 +#include <linux/security.h>
69101 #include <linux/pid_namespace.h>
69102 #include <linux/init_task.h>
69103 #include <linux/syscalls.h>
69104 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69105
69106 int pid_max = PID_MAX_DEFAULT;
69107
69108 -#define RESERVED_PIDS 300
69109 +#define RESERVED_PIDS 500
69110
69111 int pid_max_min = RESERVED_PIDS + 1;
69112 int pid_max_max = PID_MAX_LIMIT;
69113 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69114 */
69115 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69116 {
69117 + struct task_struct *task;
69118 +
69119 rcu_lockdep_assert(rcu_read_lock_held(),
69120 "find_task_by_pid_ns() needs rcu_read_lock()"
69121 " protection");
69122 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69123 +
69124 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69125 +
69126 + if (gr_pid_is_chrooted(task))
69127 + return NULL;
69128 +
69129 + return task;
69130 }
69131
69132 struct task_struct *find_task_by_vpid(pid_t vnr)
69133 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69134 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69135 }
69136
69137 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69138 +{
69139 + rcu_lockdep_assert(rcu_read_lock_held(),
69140 + "find_task_by_pid_ns() needs rcu_read_lock()"
69141 + " protection");
69142 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69143 +}
69144 +
69145 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69146 {
69147 struct pid *pid;
69148 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69149 index 125cb67..a4d1c30 100644
69150 --- a/kernel/posix-cpu-timers.c
69151 +++ b/kernel/posix-cpu-timers.c
69152 @@ -6,6 +6,7 @@
69153 #include <linux/posix-timers.h>
69154 #include <linux/errno.h>
69155 #include <linux/math64.h>
69156 +#include <linux/security.h>
69157 #include <asm/uaccess.h>
69158 #include <linux/kernel_stat.h>
69159 #include <trace/events/timer.h>
69160 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69161
69162 static __init int init_posix_cpu_timers(void)
69163 {
69164 - struct k_clock process = {
69165 + static struct k_clock process = {
69166 .clock_getres = process_cpu_clock_getres,
69167 .clock_get = process_cpu_clock_get,
69168 .timer_create = process_cpu_timer_create,
69169 .nsleep = process_cpu_nsleep,
69170 .nsleep_restart = process_cpu_nsleep_restart,
69171 };
69172 - struct k_clock thread = {
69173 + static struct k_clock thread = {
69174 .clock_getres = thread_cpu_clock_getres,
69175 .clock_get = thread_cpu_clock_get,
69176 .timer_create = thread_cpu_timer_create,
69177 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69178 index 69185ae..cc2847a 100644
69179 --- a/kernel/posix-timers.c
69180 +++ b/kernel/posix-timers.c
69181 @@ -43,6 +43,7 @@
69182 #include <linux/idr.h>
69183 #include <linux/posix-clock.h>
69184 #include <linux/posix-timers.h>
69185 +#include <linux/grsecurity.h>
69186 #include <linux/syscalls.h>
69187 #include <linux/wait.h>
69188 #include <linux/workqueue.h>
69189 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69190 * which we beg off on and pass to do_sys_settimeofday().
69191 */
69192
69193 -static struct k_clock posix_clocks[MAX_CLOCKS];
69194 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69195
69196 /*
69197 * These ones are defined below.
69198 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69199 */
69200 static __init int init_posix_timers(void)
69201 {
69202 - struct k_clock clock_realtime = {
69203 + static struct k_clock clock_realtime = {
69204 .clock_getres = hrtimer_get_res,
69205 .clock_get = posix_clock_realtime_get,
69206 .clock_set = posix_clock_realtime_set,
69207 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69208 .timer_get = common_timer_get,
69209 .timer_del = common_timer_del,
69210 };
69211 - struct k_clock clock_monotonic = {
69212 + static struct k_clock clock_monotonic = {
69213 .clock_getres = hrtimer_get_res,
69214 .clock_get = posix_ktime_get_ts,
69215 .nsleep = common_nsleep,
69216 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69217 .timer_get = common_timer_get,
69218 .timer_del = common_timer_del,
69219 };
69220 - struct k_clock clock_monotonic_raw = {
69221 + static struct k_clock clock_monotonic_raw = {
69222 .clock_getres = hrtimer_get_res,
69223 .clock_get = posix_get_monotonic_raw,
69224 };
69225 - struct k_clock clock_realtime_coarse = {
69226 + static struct k_clock clock_realtime_coarse = {
69227 .clock_getres = posix_get_coarse_res,
69228 .clock_get = posix_get_realtime_coarse,
69229 };
69230 - struct k_clock clock_monotonic_coarse = {
69231 + static struct k_clock clock_monotonic_coarse = {
69232 .clock_getres = posix_get_coarse_res,
69233 .clock_get = posix_get_monotonic_coarse,
69234 };
69235 - struct k_clock clock_boottime = {
69236 + static struct k_clock clock_boottime = {
69237 .clock_getres = hrtimer_get_res,
69238 .clock_get = posix_get_boottime,
69239 .nsleep = common_nsleep,
69240 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69241 return;
69242 }
69243
69244 - posix_clocks[clock_id] = *new_clock;
69245 + posix_clocks[clock_id] = new_clock;
69246 }
69247 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69248
69249 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69250 return (id & CLOCKFD_MASK) == CLOCKFD ?
69251 &clock_posix_dynamic : &clock_posix_cpu;
69252
69253 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69254 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69255 return NULL;
69256 - return &posix_clocks[id];
69257 + return posix_clocks[id];
69258 }
69259
69260 static int common_timer_create(struct k_itimer *new_timer)
69261 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69262 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69263 return -EFAULT;
69264
69265 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69266 + have their clock_set fptr set to a nosettime dummy function
69267 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69268 + call common_clock_set, which calls do_sys_settimeofday, which
69269 + we hook
69270 + */
69271 +
69272 return kc->clock_set(which_clock, &new_tp);
69273 }
69274
69275 diff --git a/kernel/power/process.c b/kernel/power/process.c
69276 index 87da817..30ddd13 100644
69277 --- a/kernel/power/process.c
69278 +++ b/kernel/power/process.c
69279 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69280 u64 elapsed_csecs64;
69281 unsigned int elapsed_csecs;
69282 bool wakeup = false;
69283 + bool timedout = false;
69284
69285 do_gettimeofday(&start);
69286
69287 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69288
69289 while (true) {
69290 todo = 0;
69291 + if (time_after(jiffies, end_time))
69292 + timedout = true;
69293 read_lock(&tasklist_lock);
69294 do_each_thread(g, p) {
69295 if (p == current || !freeze_task(p))
69296 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69297 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69298 * transition can't race with task state testing here.
69299 */
69300 - if (!task_is_stopped_or_traced(p) &&
69301 - !freezer_should_skip(p))
69302 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69303 todo++;
69304 + if (timedout) {
69305 + printk(KERN_ERR "Task refusing to freeze:\n");
69306 + sched_show_task(p);
69307 + }
69308 + }
69309 } while_each_thread(g, p);
69310 read_unlock(&tasklist_lock);
69311
69312 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69313 todo += wq_busy;
69314 }
69315
69316 - if (!todo || time_after(jiffies, end_time))
69317 + if (!todo || timedout)
69318 break;
69319
69320 if (pm_wakeup_pending()) {
69321 diff --git a/kernel/printk.c b/kernel/printk.c
69322 index 2d607f4..7413773 100644
69323 --- a/kernel/printk.c
69324 +++ b/kernel/printk.c
69325 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69326 if (from_file && type != SYSLOG_ACTION_OPEN)
69327 return 0;
69328
69329 +#ifdef CONFIG_GRKERNSEC_DMESG
69330 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69331 + return -EPERM;
69332 +#endif
69333 +
69334 if (syslog_action_restricted(type)) {
69335 if (capable(CAP_SYSLOG))
69336 return 0;
69337 diff --git a/kernel/profile.c b/kernel/profile.c
69338 index 76b8e77..a2930e8 100644
69339 --- a/kernel/profile.c
69340 +++ b/kernel/profile.c
69341 @@ -39,7 +39,7 @@ struct profile_hit {
69342 /* Oprofile timer tick hook */
69343 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69344
69345 -static atomic_t *prof_buffer;
69346 +static atomic_unchecked_t *prof_buffer;
69347 static unsigned long prof_len, prof_shift;
69348
69349 int prof_on __read_mostly;
69350 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69351 hits[i].pc = 0;
69352 continue;
69353 }
69354 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69355 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69356 hits[i].hits = hits[i].pc = 0;
69357 }
69358 }
69359 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69360 * Add the current hit(s) and flush the write-queue out
69361 * to the global buffer:
69362 */
69363 - atomic_add(nr_hits, &prof_buffer[pc]);
69364 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69365 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69366 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69367 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69368 hits[i].pc = hits[i].hits = 0;
69369 }
69370 out:
69371 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69372 {
69373 unsigned long pc;
69374 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69375 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69376 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69377 }
69378 #endif /* !CONFIG_SMP */
69379
69380 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69381 return -EFAULT;
69382 buf++; p++; count--; read++;
69383 }
69384 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69385 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69386 if (copy_to_user(buf, (void *)pnt, count))
69387 return -EFAULT;
69388 read += count;
69389 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69390 }
69391 #endif
69392 profile_discard_flip_buffers();
69393 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69394 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69395 return count;
69396 }
69397
69398 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69399 index 1f5e55d..8b8f969 100644
69400 --- a/kernel/ptrace.c
69401 +++ b/kernel/ptrace.c
69402 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69403
69404 if (seize)
69405 flags |= PT_SEIZED;
69406 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69407 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69408 flags |= PT_PTRACE_CAP;
69409 task->ptrace = flags;
69410
69411 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69412 break;
69413 return -EIO;
69414 }
69415 - if (copy_to_user(dst, buf, retval))
69416 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69417 return -EFAULT;
69418 copied += retval;
69419 src += retval;
69420 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
69421 bool seized = child->ptrace & PT_SEIZED;
69422 int ret = -EIO;
69423 siginfo_t siginfo, *si;
69424 - void __user *datavp = (void __user *) data;
69425 + void __user *datavp = (__force void __user *) data;
69426 unsigned long __user *datalp = datavp;
69427 unsigned long flags;
69428
69429 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69430 goto out;
69431 }
69432
69433 + if (gr_handle_ptrace(child, request)) {
69434 + ret = -EPERM;
69435 + goto out_put_task_struct;
69436 + }
69437 +
69438 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69439 ret = ptrace_attach(child, request, addr, data);
69440 /*
69441 * Some architectures need to do book-keeping after
69442 * a ptrace attach.
69443 */
69444 - if (!ret)
69445 + if (!ret) {
69446 arch_ptrace_attach(child);
69447 + gr_audit_ptrace(child);
69448 + }
69449 goto out_put_task_struct;
69450 }
69451
69452 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69453 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69454 if (copied != sizeof(tmp))
69455 return -EIO;
69456 - return put_user(tmp, (unsigned long __user *)data);
69457 + return put_user(tmp, (__force unsigned long __user *)data);
69458 }
69459
69460 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69461 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69462 goto out;
69463 }
69464
69465 + if (gr_handle_ptrace(child, request)) {
69466 + ret = -EPERM;
69467 + goto out_put_task_struct;
69468 + }
69469 +
69470 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69471 ret = ptrace_attach(child, request, addr, data);
69472 /*
69473 * Some architectures need to do book-keeping after
69474 * a ptrace attach.
69475 */
69476 - if (!ret)
69477 + if (!ret) {
69478 arch_ptrace_attach(child);
69479 + gr_audit_ptrace(child);
69480 + }
69481 goto out_put_task_struct;
69482 }
69483
69484 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69485 index e4c6a59..c86621a 100644
69486 --- a/kernel/rcutiny.c
69487 +++ b/kernel/rcutiny.c
69488 @@ -46,7 +46,7 @@
69489 struct rcu_ctrlblk;
69490 static void invoke_rcu_callbacks(void);
69491 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69492 -static void rcu_process_callbacks(struct softirq_action *unused);
69493 +static void rcu_process_callbacks(void);
69494 static void __call_rcu(struct rcu_head *head,
69495 void (*func)(struct rcu_head *rcu),
69496 struct rcu_ctrlblk *rcp);
69497 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69498 rcu_is_callbacks_kthread()));
69499 }
69500
69501 -static void rcu_process_callbacks(struct softirq_action *unused)
69502 +static void rcu_process_callbacks(void)
69503 {
69504 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69505 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69506 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69507 index 3d01902..afbf46e 100644
69508 --- a/kernel/rcutiny_plugin.h
69509 +++ b/kernel/rcutiny_plugin.h
69510 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69511 have_rcu_kthread_work = morework;
69512 local_irq_restore(flags);
69513 if (work)
69514 - rcu_process_callbacks(NULL);
69515 + rcu_process_callbacks();
69516 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69517 }
69518
69519 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69520 index aaa7b9f..055ff1e 100644
69521 --- a/kernel/rcutorture.c
69522 +++ b/kernel/rcutorture.c
69523 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69524 { 0 };
69525 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69526 { 0 };
69527 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69528 -static atomic_t n_rcu_torture_alloc;
69529 -static atomic_t n_rcu_torture_alloc_fail;
69530 -static atomic_t n_rcu_torture_free;
69531 -static atomic_t n_rcu_torture_mberror;
69532 -static atomic_t n_rcu_torture_error;
69533 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69534 +static atomic_unchecked_t n_rcu_torture_alloc;
69535 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69536 +static atomic_unchecked_t n_rcu_torture_free;
69537 +static atomic_unchecked_t n_rcu_torture_mberror;
69538 +static atomic_unchecked_t n_rcu_torture_error;
69539 static long n_rcu_torture_barrier_error;
69540 static long n_rcu_torture_boost_ktrerror;
69541 static long n_rcu_torture_boost_rterror;
69542 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
69543
69544 spin_lock_bh(&rcu_torture_lock);
69545 if (list_empty(&rcu_torture_freelist)) {
69546 - atomic_inc(&n_rcu_torture_alloc_fail);
69547 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69548 spin_unlock_bh(&rcu_torture_lock);
69549 return NULL;
69550 }
69551 - atomic_inc(&n_rcu_torture_alloc);
69552 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69553 p = rcu_torture_freelist.next;
69554 list_del_init(p);
69555 spin_unlock_bh(&rcu_torture_lock);
69556 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
69557 static void
69558 rcu_torture_free(struct rcu_torture *p)
69559 {
69560 - atomic_inc(&n_rcu_torture_free);
69561 + atomic_inc_unchecked(&n_rcu_torture_free);
69562 spin_lock_bh(&rcu_torture_lock);
69563 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69564 spin_unlock_bh(&rcu_torture_lock);
69565 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
69566 i = rp->rtort_pipe_count;
69567 if (i > RCU_TORTURE_PIPE_LEN)
69568 i = RCU_TORTURE_PIPE_LEN;
69569 - atomic_inc(&rcu_torture_wcount[i]);
69570 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69571 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69572 rp->rtort_mbtest = 0;
69573 rcu_torture_free(rp);
69574 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69575 i = rp->rtort_pipe_count;
69576 if (i > RCU_TORTURE_PIPE_LEN)
69577 i = RCU_TORTURE_PIPE_LEN;
69578 - atomic_inc(&rcu_torture_wcount[i]);
69579 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69580 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69581 rp->rtort_mbtest = 0;
69582 list_del(&rp->rtort_free);
69583 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
69584 i = old_rp->rtort_pipe_count;
69585 if (i > RCU_TORTURE_PIPE_LEN)
69586 i = RCU_TORTURE_PIPE_LEN;
69587 - atomic_inc(&rcu_torture_wcount[i]);
69588 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69589 old_rp->rtort_pipe_count++;
69590 cur_ops->deferred_free(old_rp);
69591 }
69592 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
69593 }
69594 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69595 if (p->rtort_mbtest == 0)
69596 - atomic_inc(&n_rcu_torture_mberror);
69597 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69598 spin_lock(&rand_lock);
69599 cur_ops->read_delay(&rand);
69600 n_rcu_torture_timers++;
69601 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
69602 }
69603 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69604 if (p->rtort_mbtest == 0)
69605 - atomic_inc(&n_rcu_torture_mberror);
69606 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69607 cur_ops->read_delay(&rand);
69608 preempt_disable();
69609 pipe_count = p->rtort_pipe_count;
69610 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
69611 rcu_torture_current,
69612 rcu_torture_current_version,
69613 list_empty(&rcu_torture_freelist),
69614 - atomic_read(&n_rcu_torture_alloc),
69615 - atomic_read(&n_rcu_torture_alloc_fail),
69616 - atomic_read(&n_rcu_torture_free));
69617 + atomic_read_unchecked(&n_rcu_torture_alloc),
69618 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69619 + atomic_read_unchecked(&n_rcu_torture_free));
69620 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69621 - atomic_read(&n_rcu_torture_mberror),
69622 + atomic_read_unchecked(&n_rcu_torture_mberror),
69623 n_rcu_torture_boost_ktrerror,
69624 n_rcu_torture_boost_rterror);
69625 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69626 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
69627 n_barrier_attempts,
69628 n_rcu_torture_barrier_error);
69629 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69630 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69631 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69632 n_rcu_torture_barrier_error != 0 ||
69633 n_rcu_torture_boost_ktrerror != 0 ||
69634 n_rcu_torture_boost_rterror != 0 ||
69635 n_rcu_torture_boost_failure != 0 ||
69636 i > 1) {
69637 cnt += sprintf(&page[cnt], "!!! ");
69638 - atomic_inc(&n_rcu_torture_error);
69639 + atomic_inc_unchecked(&n_rcu_torture_error);
69640 WARN_ON_ONCE(1);
69641 }
69642 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69643 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
69644 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69645 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69646 cnt += sprintf(&page[cnt], " %d",
69647 - atomic_read(&rcu_torture_wcount[i]));
69648 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69649 }
69650 cnt += sprintf(&page[cnt], "\n");
69651 if (cur_ops->stats)
69652 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
69653
69654 if (cur_ops->cleanup)
69655 cur_ops->cleanup();
69656 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69657 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69658 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69659 else if (n_online_successes != n_online_attempts ||
69660 n_offline_successes != n_offline_attempts)
69661 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
69662
69663 rcu_torture_current = NULL;
69664 rcu_torture_current_version = 0;
69665 - atomic_set(&n_rcu_torture_alloc, 0);
69666 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69667 - atomic_set(&n_rcu_torture_free, 0);
69668 - atomic_set(&n_rcu_torture_mberror, 0);
69669 - atomic_set(&n_rcu_torture_error, 0);
69670 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69671 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69672 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69673 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69674 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69675 n_rcu_torture_barrier_error = 0;
69676 n_rcu_torture_boost_ktrerror = 0;
69677 n_rcu_torture_boost_rterror = 0;
69678 n_rcu_torture_boost_failure = 0;
69679 n_rcu_torture_boosts = 0;
69680 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69681 - atomic_set(&rcu_torture_wcount[i], 0);
69682 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69683 for_each_possible_cpu(cpu) {
69684 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69685 per_cpu(rcu_torture_count, cpu)[i] = 0;
69686 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69687 index 74df86b..e0702bb 100644
69688 --- a/kernel/rcutree.c
69689 +++ b/kernel/rcutree.c
69690 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
69691 rcu_prepare_for_idle(smp_processor_id());
69692 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69693 smp_mb__before_atomic_inc(); /* See above. */
69694 - atomic_inc(&rdtp->dynticks);
69695 + atomic_inc_unchecked(&rdtp->dynticks);
69696 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69697 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69698 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69699
69700 /*
69701 * It is illegal to enter an extended quiescent state while
69702 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
69703 int user)
69704 {
69705 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69706 - atomic_inc(&rdtp->dynticks);
69707 + atomic_inc_unchecked(&rdtp->dynticks);
69708 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69709 smp_mb__after_atomic_inc(); /* See above. */
69710 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69711 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69712 rcu_cleanup_after_idle(smp_processor_id());
69713 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69714 if (!user && !is_idle_task(current)) {
69715 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
69716 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69717
69718 if (rdtp->dynticks_nmi_nesting == 0 &&
69719 - (atomic_read(&rdtp->dynticks) & 0x1))
69720 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69721 return;
69722 rdtp->dynticks_nmi_nesting++;
69723 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69724 - atomic_inc(&rdtp->dynticks);
69725 + atomic_inc_unchecked(&rdtp->dynticks);
69726 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69727 smp_mb__after_atomic_inc(); /* See above. */
69728 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69729 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69730 }
69731
69732 /**
69733 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
69734 return;
69735 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69736 smp_mb__before_atomic_inc(); /* See above. */
69737 - atomic_inc(&rdtp->dynticks);
69738 + atomic_inc_unchecked(&rdtp->dynticks);
69739 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69740 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69741 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69742 }
69743
69744 /**
69745 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
69746 int ret;
69747
69748 preempt_disable();
69749 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69750 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69751 preempt_enable();
69752 return ret;
69753 }
69754 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69755 */
69756 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69757 {
69758 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69759 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69760 return (rdp->dynticks_snap & 0x1) == 0;
69761 }
69762
69763 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69764 unsigned int curr;
69765 unsigned int snap;
69766
69767 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69768 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69769 snap = (unsigned int)rdp->dynticks_snap;
69770
69771 /*
69772 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
69773 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69774 */
69775 if (till_stall_check < 3) {
69776 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69777 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69778 till_stall_check = 3;
69779 } else if (till_stall_check > 300) {
69780 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69781 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69782 till_stall_check = 300;
69783 }
69784 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69785 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69786 rsp->qlen += rdp->qlen;
69787 rdp->n_cbs_orphaned += rdp->qlen;
69788 rdp->qlen_lazy = 0;
69789 - ACCESS_ONCE(rdp->qlen) = 0;
69790 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69791 }
69792
69793 /*
69794 @@ -1830,7 +1830,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69795 }
69796 smp_mb(); /* List handling before counting for rcu_barrier(). */
69797 rdp->qlen_lazy -= count_lazy;
69798 - ACCESS_ONCE(rdp->qlen) -= count;
69799 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69800 rdp->n_cbs_invoked += count;
69801
69802 /* Reinstate batch limit if we have worked down the excess. */
69803 @@ -2023,7 +2023,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69804 /*
69805 * Do RCU core processing for the current CPU.
69806 */
69807 -static void rcu_process_callbacks(struct softirq_action *unused)
69808 +static void rcu_process_callbacks(void)
69809 {
69810 struct rcu_state *rsp;
69811
69812 @@ -2135,7 +2135,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69813 local_irq_restore(flags);
69814 return;
69815 }
69816 - ACCESS_ONCE(rdp->qlen)++;
69817 + ACCESS_ONCE_RW(rdp->qlen)++;
69818 if (lazy)
69819 rdp->qlen_lazy++;
69820 else
69821 @@ -2249,8 +2249,8 @@ void synchronize_rcu_bh(void)
69822 }
69823 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69824
69825 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69826 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69827 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69828 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69829
69830 static int synchronize_sched_expedited_cpu_stop(void *data)
69831 {
69832 @@ -2311,7 +2311,7 @@ void synchronize_sched_expedited(void)
69833 int firstsnap, s, snap, trycount = 0;
69834
69835 /* Note that atomic_inc_return() implies full memory barrier. */
69836 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69837 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69838 get_online_cpus();
69839 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69840
69841 @@ -2333,7 +2333,7 @@ void synchronize_sched_expedited(void)
69842 }
69843
69844 /* Check to see if someone else did our work for us. */
69845 - s = atomic_read(&sync_sched_expedited_done);
69846 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69847 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69848 smp_mb(); /* ensure test happens before caller kfree */
69849 return;
69850 @@ -2348,7 +2348,7 @@ void synchronize_sched_expedited(void)
69851 * grace period works for us.
69852 */
69853 get_online_cpus();
69854 - snap = atomic_read(&sync_sched_expedited_started);
69855 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69856 smp_mb(); /* ensure read is before try_stop_cpus(). */
69857 }
69858
69859 @@ -2359,12 +2359,12 @@ void synchronize_sched_expedited(void)
69860 * than we did beat us to the punch.
69861 */
69862 do {
69863 - s = atomic_read(&sync_sched_expedited_done);
69864 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69865 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69866 smp_mb(); /* ensure test happens before caller kfree */
69867 break;
69868 }
69869 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69870 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69871
69872 put_online_cpus();
69873 }
69874 @@ -2538,7 +2538,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69875 * ACCESS_ONCE() to prevent the compiler from speculating
69876 * the increment to precede the early-exit check.
69877 */
69878 - ACCESS_ONCE(rsp->n_barrier_done)++;
69879 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69880 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69881 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69882 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69883 @@ -2580,7 +2580,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69884
69885 /* Increment ->n_barrier_done to prevent duplicate work. */
69886 smp_mb(); /* Keep increment after above mechanism. */
69887 - ACCESS_ONCE(rsp->n_barrier_done)++;
69888 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69889 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69890 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69891 smp_mb(); /* Keep increment before caller's subsequent code. */
69892 @@ -2625,10 +2625,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69893 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69894 init_callback_list(rdp);
69895 rdp->qlen_lazy = 0;
69896 - ACCESS_ONCE(rdp->qlen) = 0;
69897 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69898 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69899 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69900 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69901 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69902 #ifdef CONFIG_RCU_USER_QS
69903 WARN_ON_ONCE(rdp->dynticks->in_user);
69904 #endif
69905 @@ -2663,8 +2663,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69906 rdp->blimit = blimit;
69907 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
69908 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69909 - atomic_set(&rdp->dynticks->dynticks,
69910 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69911 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69912 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69913 rcu_prepare_for_idle_init(cpu);
69914 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69915
69916 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69917 index a240f03..d469618 100644
69918 --- a/kernel/rcutree.h
69919 +++ b/kernel/rcutree.h
69920 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69921 long long dynticks_nesting; /* Track irq/process nesting level. */
69922 /* Process level is worth LLONG_MAX/2. */
69923 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69924 - atomic_t dynticks; /* Even value for idle, else odd. */
69925 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69926 #ifdef CONFIG_RCU_FAST_NO_HZ
69927 int dyntick_drain; /* Prepare-for-idle state variable. */
69928 unsigned long dyntick_holdoff;
69929 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69930 index f921154..34c4873 100644
69931 --- a/kernel/rcutree_plugin.h
69932 +++ b/kernel/rcutree_plugin.h
69933 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
69934
69935 /* Clean up and exit. */
69936 smp_mb(); /* ensure expedited GP seen before counter increment. */
69937 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69938 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69939 unlock_mb_ret:
69940 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69941 mb_ret:
69942 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
69943 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
69944 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
69945 cpu, ticks_value, ticks_title,
69946 - atomic_read(&rdtp->dynticks) & 0xfff,
69947 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
69948 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
69949 fast_no_hz);
69950 }
69951 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69952 index 693513b..b9f1d63 100644
69953 --- a/kernel/rcutree_trace.c
69954 +++ b/kernel/rcutree_trace.c
69955 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69956 rdp->completed, rdp->gpnum,
69957 rdp->passed_quiesce, rdp->qs_pending);
69958 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69959 - atomic_read(&rdp->dynticks->dynticks),
69960 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69961 rdp->dynticks->dynticks_nesting,
69962 rdp->dynticks->dynticks_nmi_nesting,
69963 rdp->dynticks_fqs);
69964 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69965 rdp->completed, rdp->gpnum,
69966 rdp->passed_quiesce, rdp->qs_pending);
69967 seq_printf(m, ",%d,%llx,%d,%lu",
69968 - atomic_read(&rdp->dynticks->dynticks),
69969 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69970 rdp->dynticks->dynticks_nesting,
69971 rdp->dynticks->dynticks_nmi_nesting,
69972 rdp->dynticks_fqs);
69973 diff --git a/kernel/resource.c b/kernel/resource.c
69974 index 73f35d4..4684fc4 100644
69975 --- a/kernel/resource.c
69976 +++ b/kernel/resource.c
69977 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69978
69979 static int __init ioresources_init(void)
69980 {
69981 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69982 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69983 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69984 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69985 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69986 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69987 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69988 +#endif
69989 +#else
69990 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69991 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69992 +#endif
69993 return 0;
69994 }
69995 __initcall(ioresources_init);
69996 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69997 index 98ec494..4241d6d 100644
69998 --- a/kernel/rtmutex-tester.c
69999 +++ b/kernel/rtmutex-tester.c
70000 @@ -20,7 +20,7 @@
70001 #define MAX_RT_TEST_MUTEXES 8
70002
70003 static spinlock_t rttest_lock;
70004 -static atomic_t rttest_event;
70005 +static atomic_unchecked_t rttest_event;
70006
70007 struct test_thread_data {
70008 int opcode;
70009 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70010
70011 case RTTEST_LOCKCONT:
70012 td->mutexes[td->opdata] = 1;
70013 - td->event = atomic_add_return(1, &rttest_event);
70014 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70015 return 0;
70016
70017 case RTTEST_RESET:
70018 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70019 return 0;
70020
70021 case RTTEST_RESETEVENT:
70022 - atomic_set(&rttest_event, 0);
70023 + atomic_set_unchecked(&rttest_event, 0);
70024 return 0;
70025
70026 default:
70027 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70028 return ret;
70029
70030 td->mutexes[id] = 1;
70031 - td->event = atomic_add_return(1, &rttest_event);
70032 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70033 rt_mutex_lock(&mutexes[id]);
70034 - td->event = atomic_add_return(1, &rttest_event);
70035 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70036 td->mutexes[id] = 4;
70037 return 0;
70038
70039 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70040 return ret;
70041
70042 td->mutexes[id] = 1;
70043 - td->event = atomic_add_return(1, &rttest_event);
70044 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70045 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70046 - td->event = atomic_add_return(1, &rttest_event);
70047 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70048 td->mutexes[id] = ret ? 0 : 4;
70049 return ret ? -EINTR : 0;
70050
70051 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70052 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70053 return ret;
70054
70055 - td->event = atomic_add_return(1, &rttest_event);
70056 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70057 rt_mutex_unlock(&mutexes[id]);
70058 - td->event = atomic_add_return(1, &rttest_event);
70059 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70060 td->mutexes[id] = 0;
70061 return 0;
70062
70063 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70064 break;
70065
70066 td->mutexes[dat] = 2;
70067 - td->event = atomic_add_return(1, &rttest_event);
70068 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70069 break;
70070
70071 default:
70072 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70073 return;
70074
70075 td->mutexes[dat] = 3;
70076 - td->event = atomic_add_return(1, &rttest_event);
70077 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70078 break;
70079
70080 case RTTEST_LOCKNOWAIT:
70081 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70082 return;
70083
70084 td->mutexes[dat] = 1;
70085 - td->event = atomic_add_return(1, &rttest_event);
70086 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70087 return;
70088
70089 default:
70090 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70091 index 15f60d0..7e50319 100644
70092 --- a/kernel/sched/auto_group.c
70093 +++ b/kernel/sched/auto_group.c
70094 @@ -11,7 +11,7 @@
70095
70096 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70097 static struct autogroup autogroup_default;
70098 -static atomic_t autogroup_seq_nr;
70099 +static atomic_unchecked_t autogroup_seq_nr;
70100
70101 void __init autogroup_init(struct task_struct *init_task)
70102 {
70103 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70104
70105 kref_init(&ag->kref);
70106 init_rwsem(&ag->lock);
70107 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70108 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70109 ag->tg = tg;
70110 #ifdef CONFIG_RT_GROUP_SCHED
70111 /*
70112 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70113 index 2d8927f..f617765 100644
70114 --- a/kernel/sched/core.c
70115 +++ b/kernel/sched/core.c
70116 @@ -3562,6 +3562,8 @@ int can_nice(const struct task_struct *p, const int nice)
70117 /* convert nice value [19,-20] to rlimit style value [1,40] */
70118 int nice_rlim = 20 - nice;
70119
70120 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70121 +
70122 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70123 capable(CAP_SYS_NICE));
70124 }
70125 @@ -3595,7 +3597,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70126 if (nice > 19)
70127 nice = 19;
70128
70129 - if (increment < 0 && !can_nice(current, nice))
70130 + if (increment < 0 && (!can_nice(current, nice) ||
70131 + gr_handle_chroot_nice()))
70132 return -EPERM;
70133
70134 retval = security_task_setnice(current, nice);
70135 @@ -3749,6 +3752,7 @@ recheck:
70136 unsigned long rlim_rtprio =
70137 task_rlimit(p, RLIMIT_RTPRIO);
70138
70139 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70140 /* can't set/change the rt policy */
70141 if (policy != p->policy && !rlim_rtprio)
70142 return -EPERM;
70143 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70144 index 6b800a1..0c36227 100644
70145 --- a/kernel/sched/fair.c
70146 +++ b/kernel/sched/fair.c
70147 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70148 * run_rebalance_domains is triggered when needed from the scheduler tick.
70149 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70150 */
70151 -static void run_rebalance_domains(struct softirq_action *h)
70152 +static void run_rebalance_domains(void)
70153 {
70154 int this_cpu = smp_processor_id();
70155 struct rq *this_rq = cpu_rq(this_cpu);
70156 diff --git a/kernel/signal.c b/kernel/signal.c
70157 index 0af8868..a00119d 100644
70158 --- a/kernel/signal.c
70159 +++ b/kernel/signal.c
70160 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
70161
70162 int print_fatal_signals __read_mostly;
70163
70164 -static void __user *sig_handler(struct task_struct *t, int sig)
70165 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70166 {
70167 return t->sighand->action[sig - 1].sa.sa_handler;
70168 }
70169
70170 -static int sig_handler_ignored(void __user *handler, int sig)
70171 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70172 {
70173 /* Is it explicitly or implicitly ignored? */
70174 return handler == SIG_IGN ||
70175 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70176
70177 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70178 {
70179 - void __user *handler;
70180 + __sighandler_t handler;
70181
70182 handler = sig_handler(t, sig);
70183
70184 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70185 atomic_inc(&user->sigpending);
70186 rcu_read_unlock();
70187
70188 + if (!override_rlimit)
70189 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70190 +
70191 if (override_rlimit ||
70192 atomic_read(&user->sigpending) <=
70193 task_rlimit(t, RLIMIT_SIGPENDING)) {
70194 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70195
70196 int unhandled_signal(struct task_struct *tsk, int sig)
70197 {
70198 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70199 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70200 if (is_global_init(tsk))
70201 return 1;
70202 if (handler != SIG_IGN && handler != SIG_DFL)
70203 @@ -817,6 +820,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70204 }
70205 }
70206
70207 + /* allow glibc communication via tgkill to other threads in our
70208 + thread group */
70209 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70210 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70211 + && gr_handle_signal(t, sig))
70212 + return -EPERM;
70213 +
70214 return security_task_kill(t, info, sig, 0);
70215 }
70216
70217 @@ -1198,7 +1208,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70218 return send_signal(sig, info, p, 1);
70219 }
70220
70221 -static int
70222 +int
70223 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70224 {
70225 return send_signal(sig, info, t, 0);
70226 @@ -1235,6 +1245,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70227 unsigned long int flags;
70228 int ret, blocked, ignored;
70229 struct k_sigaction *action;
70230 + int is_unhandled = 0;
70231
70232 spin_lock_irqsave(&t->sighand->siglock, flags);
70233 action = &t->sighand->action[sig-1];
70234 @@ -1249,9 +1260,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70235 }
70236 if (action->sa.sa_handler == SIG_DFL)
70237 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70238 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70239 + is_unhandled = 1;
70240 ret = specific_send_sig_info(sig, info, t);
70241 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70242
70243 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70244 + normal operation */
70245 + if (is_unhandled) {
70246 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70247 + gr_handle_crash(t, sig);
70248 + }
70249 +
70250 return ret;
70251 }
70252
70253 @@ -1318,8 +1338,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70254 ret = check_kill_permission(sig, info, p);
70255 rcu_read_unlock();
70256
70257 - if (!ret && sig)
70258 + if (!ret && sig) {
70259 ret = do_send_sig_info(sig, info, p, true);
70260 + if (!ret)
70261 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70262 + }
70263
70264 return ret;
70265 }
70266 @@ -2864,7 +2887,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70267 int error = -ESRCH;
70268
70269 rcu_read_lock();
70270 - p = find_task_by_vpid(pid);
70271 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70272 + /* allow glibc communication via tgkill to other threads in our
70273 + thread group */
70274 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70275 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70276 + p = find_task_by_vpid_unrestricted(pid);
70277 + else
70278 +#endif
70279 + p = find_task_by_vpid(pid);
70280 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70281 error = check_kill_permission(sig, info, p);
70282 /*
70283 diff --git a/kernel/softirq.c b/kernel/softirq.c
70284 index cc96bdc..8bb9750 100644
70285 --- a/kernel/softirq.c
70286 +++ b/kernel/softirq.c
70287 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70288
70289 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70290
70291 -char *softirq_to_name[NR_SOFTIRQS] = {
70292 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70293 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70294 "TASKLET", "SCHED", "HRTIMER", "RCU"
70295 };
70296 @@ -244,7 +244,7 @@ restart:
70297 kstat_incr_softirqs_this_cpu(vec_nr);
70298
70299 trace_softirq_entry(vec_nr);
70300 - h->action(h);
70301 + h->action();
70302 trace_softirq_exit(vec_nr);
70303 if (unlikely(prev_count != preempt_count())) {
70304 printk(KERN_ERR "huh, entered softirq %u %s %p"
70305 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70306 or_softirq_pending(1UL << nr);
70307 }
70308
70309 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70310 +void open_softirq(int nr, void (*action)(void))
70311 {
70312 - softirq_vec[nr].action = action;
70313 + pax_open_kernel();
70314 + *(void **)&softirq_vec[nr].action = action;
70315 + pax_close_kernel();
70316 }
70317
70318 /*
70319 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70320
70321 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70322
70323 -static void tasklet_action(struct softirq_action *a)
70324 +static void tasklet_action(void)
70325 {
70326 struct tasklet_struct *list;
70327
70328 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
70329 }
70330 }
70331
70332 -static void tasklet_hi_action(struct softirq_action *a)
70333 +static void tasklet_hi_action(void)
70334 {
70335 struct tasklet_struct *list;
70336
70337 diff --git a/kernel/srcu.c b/kernel/srcu.c
70338 index 97c465e..d83f3bb 100644
70339 --- a/kernel/srcu.c
70340 +++ b/kernel/srcu.c
70341 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70342 preempt_disable();
70343 idx = rcu_dereference_index_check(sp->completed,
70344 rcu_read_lock_sched_held()) & 0x1;
70345 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70346 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70347 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70348 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70349 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70350 preempt_enable();
70351 return idx;
70352 }
70353 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70354 {
70355 preempt_disable();
70356 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70357 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70358 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70359 preempt_enable();
70360 }
70361 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70362 diff --git a/kernel/sys.c b/kernel/sys.c
70363 index e6e0ece..1f2e413 100644
70364 --- a/kernel/sys.c
70365 +++ b/kernel/sys.c
70366 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70367 error = -EACCES;
70368 goto out;
70369 }
70370 +
70371 + if (gr_handle_chroot_setpriority(p, niceval)) {
70372 + error = -EACCES;
70373 + goto out;
70374 + }
70375 +
70376 no_nice = security_task_setnice(p, niceval);
70377 if (no_nice) {
70378 error = no_nice;
70379 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70380 goto error;
70381 }
70382
70383 + if (gr_check_group_change(new->gid, new->egid, -1))
70384 + goto error;
70385 +
70386 if (rgid != (gid_t) -1 ||
70387 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70388 new->sgid = new->egid;
70389 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70390 old = current_cred();
70391
70392 retval = -EPERM;
70393 +
70394 + if (gr_check_group_change(kgid, kgid, kgid))
70395 + goto error;
70396 +
70397 if (nsown_capable(CAP_SETGID))
70398 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70399 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70400 @@ -647,7 +660,7 @@ error:
70401 /*
70402 * change the user struct in a credentials set to match the new UID
70403 */
70404 -static int set_user(struct cred *new)
70405 +int set_user(struct cred *new)
70406 {
70407 struct user_struct *new_user;
70408
70409 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70410 goto error;
70411 }
70412
70413 + if (gr_check_user_change(new->uid, new->euid, -1))
70414 + goto error;
70415 +
70416 if (!uid_eq(new->uid, old->uid)) {
70417 retval = set_user(new);
70418 if (retval < 0)
70419 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70420 old = current_cred();
70421
70422 retval = -EPERM;
70423 +
70424 + if (gr_check_crash_uid(kuid))
70425 + goto error;
70426 + if (gr_check_user_change(kuid, kuid, kuid))
70427 + goto error;
70428 +
70429 if (nsown_capable(CAP_SETUID)) {
70430 new->suid = new->uid = kuid;
70431 if (!uid_eq(kuid, old->uid)) {
70432 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70433 goto error;
70434 }
70435
70436 + if (gr_check_user_change(kruid, keuid, -1))
70437 + goto error;
70438 +
70439 if (ruid != (uid_t) -1) {
70440 new->uid = kruid;
70441 if (!uid_eq(kruid, old->uid)) {
70442 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70443 goto error;
70444 }
70445
70446 + if (gr_check_group_change(krgid, kegid, -1))
70447 + goto error;
70448 +
70449 if (rgid != (gid_t) -1)
70450 new->gid = krgid;
70451 if (egid != (gid_t) -1)
70452 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70453 if (!uid_valid(kuid))
70454 return old_fsuid;
70455
70456 + if (gr_check_user_change(-1, -1, kuid))
70457 + goto error;
70458 +
70459 new = prepare_creds();
70460 if (!new)
70461 return old_fsuid;
70462 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70463 }
70464 }
70465
70466 +error:
70467 abort_creds(new);
70468 return old_fsuid;
70469
70470 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70471 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70472 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70473 nsown_capable(CAP_SETGID)) {
70474 + if (gr_check_group_change(-1, -1, kgid))
70475 + goto error;
70476 +
70477 if (!gid_eq(kgid, old->fsgid)) {
70478 new->fsgid = kgid;
70479 goto change_okay;
70480 }
70481 }
70482
70483 +error:
70484 abort_creds(new);
70485 return old_fsgid;
70486
70487 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70488 return -EFAULT;
70489
70490 down_read(&uts_sem);
70491 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70492 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70493 __OLD_UTS_LEN);
70494 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70495 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70496 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70497 __OLD_UTS_LEN);
70498 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70499 - error |= __copy_to_user(&name->release, &utsname()->release,
70500 + error |= __copy_to_user(name->release, &utsname()->release,
70501 __OLD_UTS_LEN);
70502 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70503 - error |= __copy_to_user(&name->version, &utsname()->version,
70504 + error |= __copy_to_user(name->version, &utsname()->version,
70505 __OLD_UTS_LEN);
70506 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70507 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70508 + error |= __copy_to_user(name->machine, &utsname()->machine,
70509 __OLD_UTS_LEN);
70510 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70511 up_read(&uts_sem);
70512 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70513 error = get_dumpable(me->mm);
70514 break;
70515 case PR_SET_DUMPABLE:
70516 - if (arg2 < 0 || arg2 > 1) {
70517 + if (arg2 > 1) {
70518 error = -EINVAL;
70519 break;
70520 }
70521 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70522 index 26f65ea..df8e5ad 100644
70523 --- a/kernel/sysctl.c
70524 +++ b/kernel/sysctl.c
70525 @@ -92,7 +92,6 @@
70526
70527
70528 #if defined(CONFIG_SYSCTL)
70529 -
70530 /* External variables not in a header file. */
70531 extern int sysctl_overcommit_memory;
70532 extern int sysctl_overcommit_ratio;
70533 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
70534 void __user *buffer, size_t *lenp, loff_t *ppos);
70535 #endif
70536
70537 -#ifdef CONFIG_PRINTK
70538 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70539 void __user *buffer, size_t *lenp, loff_t *ppos);
70540 -#endif
70541
70542 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70543 void __user *buffer, size_t *lenp, loff_t *ppos);
70544 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70545
70546 #endif
70547
70548 +extern struct ctl_table grsecurity_table[];
70549 +
70550 static struct ctl_table kern_table[];
70551 static struct ctl_table vm_table[];
70552 static struct ctl_table fs_table[];
70553 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
70554 int sysctl_legacy_va_layout;
70555 #endif
70556
70557 +#ifdef CONFIG_PAX_SOFTMODE
70558 +static ctl_table pax_table[] = {
70559 + {
70560 + .procname = "softmode",
70561 + .data = &pax_softmode,
70562 + .maxlen = sizeof(unsigned int),
70563 + .mode = 0600,
70564 + .proc_handler = &proc_dointvec,
70565 + },
70566 +
70567 + { }
70568 +};
70569 +#endif
70570 +
70571 /* The default sysctl tables: */
70572
70573 static struct ctl_table sysctl_base_table[] = {
70574 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
70575 #endif
70576
70577 static struct ctl_table kern_table[] = {
70578 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70579 + {
70580 + .procname = "grsecurity",
70581 + .mode = 0500,
70582 + .child = grsecurity_table,
70583 + },
70584 +#endif
70585 +
70586 +#ifdef CONFIG_PAX_SOFTMODE
70587 + {
70588 + .procname = "pax",
70589 + .mode = 0500,
70590 + .child = pax_table,
70591 + },
70592 +#endif
70593 +
70594 {
70595 .procname = "sched_child_runs_first",
70596 .data = &sysctl_sched_child_runs_first,
70597 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
70598 .data = &modprobe_path,
70599 .maxlen = KMOD_PATH_LEN,
70600 .mode = 0644,
70601 - .proc_handler = proc_dostring,
70602 + .proc_handler = proc_dostring_modpriv,
70603 },
70604 {
70605 .procname = "modules_disabled",
70606 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
70607 .extra1 = &zero,
70608 .extra2 = &one,
70609 },
70610 +#endif
70611 {
70612 .procname = "kptr_restrict",
70613 .data = &kptr_restrict,
70614 .maxlen = sizeof(int),
70615 .mode = 0644,
70616 .proc_handler = proc_dointvec_minmax_sysadmin,
70617 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70618 + .extra1 = &two,
70619 +#else
70620 .extra1 = &zero,
70621 +#endif
70622 .extra2 = &two,
70623 },
70624 -#endif
70625 {
70626 .procname = "ngroups_max",
70627 .data = &ngroups_max,
70628 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
70629 .proc_handler = proc_dointvec_minmax,
70630 .extra1 = &zero,
70631 },
70632 + {
70633 + .procname = "heap_stack_gap",
70634 + .data = &sysctl_heap_stack_gap,
70635 + .maxlen = sizeof(sysctl_heap_stack_gap),
70636 + .mode = 0644,
70637 + .proc_handler = proc_doulongvec_minmax,
70638 + },
70639 #else
70640 {
70641 .procname = "nr_trim_pages",
70642 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
70643 buffer, lenp, ppos);
70644 }
70645
70646 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70647 + void __user *buffer, size_t *lenp, loff_t *ppos)
70648 +{
70649 + if (write && !capable(CAP_SYS_MODULE))
70650 + return -EPERM;
70651 +
70652 + return _proc_do_string(table->data, table->maxlen, write,
70653 + buffer, lenp, ppos);
70654 +}
70655 +
70656 static size_t proc_skip_spaces(char **buf)
70657 {
70658 size_t ret;
70659 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70660 len = strlen(tmp);
70661 if (len > *size)
70662 len = *size;
70663 + if (len > sizeof(tmp))
70664 + len = sizeof(tmp);
70665 if (copy_to_user(*buf, tmp, len))
70666 return -EFAULT;
70667 *size -= len;
70668 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
70669 return err;
70670 }
70671
70672 -#ifdef CONFIG_PRINTK
70673 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70674 void __user *buffer, size_t *lenp, loff_t *ppos)
70675 {
70676 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70677
70678 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70679 }
70680 -#endif
70681
70682 struct do_proc_dointvec_minmax_conv_param {
70683 int *min;
70684 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70685 *i = val;
70686 } else {
70687 val = convdiv * (*i) / convmul;
70688 - if (!first)
70689 + if (!first) {
70690 err = proc_put_char(&buffer, &left, '\t');
70691 + if (err)
70692 + break;
70693 + }
70694 err = proc_put_long(&buffer, &left, val, false);
70695 if (err)
70696 break;
70697 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
70698 return -ENOSYS;
70699 }
70700
70701 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70702 + void __user *buffer, size_t *lenp, loff_t *ppos)
70703 +{
70704 + return -ENOSYS;
70705 +}
70706 +
70707 int proc_dointvec(struct ctl_table *table, int write,
70708 void __user *buffer, size_t *lenp, loff_t *ppos)
70709 {
70710 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70711 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70712 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70713 EXPORT_SYMBOL(proc_dostring);
70714 +EXPORT_SYMBOL(proc_dostring_modpriv);
70715 EXPORT_SYMBOL(proc_doulongvec_minmax);
70716 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70717 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70718 index 65bdcf1..21eb831 100644
70719 --- a/kernel/sysctl_binary.c
70720 +++ b/kernel/sysctl_binary.c
70721 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70722 int i;
70723
70724 set_fs(KERNEL_DS);
70725 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70726 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70727 set_fs(old_fs);
70728 if (result < 0)
70729 goto out_kfree;
70730 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70731 }
70732
70733 set_fs(KERNEL_DS);
70734 - result = vfs_write(file, buffer, str - buffer, &pos);
70735 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70736 set_fs(old_fs);
70737 if (result < 0)
70738 goto out_kfree;
70739 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70740 int i;
70741
70742 set_fs(KERNEL_DS);
70743 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70744 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70745 set_fs(old_fs);
70746 if (result < 0)
70747 goto out_kfree;
70748 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70749 }
70750
70751 set_fs(KERNEL_DS);
70752 - result = vfs_write(file, buffer, str - buffer, &pos);
70753 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70754 set_fs(old_fs);
70755 if (result < 0)
70756 goto out_kfree;
70757 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70758 int i;
70759
70760 set_fs(KERNEL_DS);
70761 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70762 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70763 set_fs(old_fs);
70764 if (result < 0)
70765 goto out;
70766 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70767 __le16 dnaddr;
70768
70769 set_fs(KERNEL_DS);
70770 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70771 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70772 set_fs(old_fs);
70773 if (result < 0)
70774 goto out;
70775 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70776 le16_to_cpu(dnaddr) & 0x3ff);
70777
70778 set_fs(KERNEL_DS);
70779 - result = vfs_write(file, buf, len, &pos);
70780 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70781 set_fs(old_fs);
70782 if (result < 0)
70783 goto out;
70784 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70785 index 145bb4d..b2aa969 100644
70786 --- a/kernel/taskstats.c
70787 +++ b/kernel/taskstats.c
70788 @@ -28,9 +28,12 @@
70789 #include <linux/fs.h>
70790 #include <linux/file.h>
70791 #include <linux/pid_namespace.h>
70792 +#include <linux/grsecurity.h>
70793 #include <net/genetlink.h>
70794 #include <linux/atomic.h>
70795
70796 +extern int gr_is_taskstats_denied(int pid);
70797 +
70798 /*
70799 * Maximum length of a cpumask that can be specified in
70800 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70801 @@ -570,6 +573,9 @@ err:
70802
70803 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70804 {
70805 + if (gr_is_taskstats_denied(current->pid))
70806 + return -EACCES;
70807 +
70808 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70809 return cmd_attr_register_cpumask(info);
70810 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70811 diff --git a/kernel/time.c b/kernel/time.c
70812 index d226c6a..c7c0960 100644
70813 --- a/kernel/time.c
70814 +++ b/kernel/time.c
70815 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70816 return error;
70817
70818 if (tz) {
70819 + /* we log in do_settimeofday called below, so don't log twice
70820 + */
70821 + if (!tv)
70822 + gr_log_timechange();
70823 +
70824 sys_tz = *tz;
70825 update_vsyscall_tz();
70826 if (firsttime) {
70827 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70828 index f11d83b..d016d91 100644
70829 --- a/kernel/time/alarmtimer.c
70830 +++ b/kernel/time/alarmtimer.c
70831 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
70832 struct platform_device *pdev;
70833 int error = 0;
70834 int i;
70835 - struct k_clock alarm_clock = {
70836 + static struct k_clock alarm_clock = {
70837 .clock_getres = alarm_clock_getres,
70838 .clock_get = alarm_clock_get,
70839 .timer_create = alarm_timer_create,
70840 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70841 index f113755..ec24223 100644
70842 --- a/kernel/time/tick-broadcast.c
70843 +++ b/kernel/time/tick-broadcast.c
70844 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70845 * then clear the broadcast bit.
70846 */
70847 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70848 - int cpu = smp_processor_id();
70849 + cpu = smp_processor_id();
70850
70851 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70852 tick_broadcast_clear_oneshot(cpu);
70853 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70854 index e424970..4c7962b 100644
70855 --- a/kernel/time/timekeeping.c
70856 +++ b/kernel/time/timekeeping.c
70857 @@ -15,6 +15,7 @@
70858 #include <linux/init.h>
70859 #include <linux/mm.h>
70860 #include <linux/sched.h>
70861 +#include <linux/grsecurity.h>
70862 #include <linux/syscore_ops.h>
70863 #include <linux/clocksource.h>
70864 #include <linux/jiffies.h>
70865 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
70866 if (!timespec_valid_strict(tv))
70867 return -EINVAL;
70868
70869 + gr_log_timechange();
70870 +
70871 write_seqlock_irqsave(&tk->lock, flags);
70872
70873 timekeeping_forward_now(tk);
70874 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70875 index af5a7e9..715611a 100644
70876 --- a/kernel/time/timer_list.c
70877 +++ b/kernel/time/timer_list.c
70878 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70879
70880 static void print_name_offset(struct seq_file *m, void *sym)
70881 {
70882 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70883 + SEQ_printf(m, "<%p>", NULL);
70884 +#else
70885 char symname[KSYM_NAME_LEN];
70886
70887 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70888 SEQ_printf(m, "<%pK>", sym);
70889 else
70890 SEQ_printf(m, "%s", symname);
70891 +#endif
70892 }
70893
70894 static void
70895 @@ -112,7 +116,11 @@ next_one:
70896 static void
70897 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70898 {
70899 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70900 + SEQ_printf(m, " .base: %p\n", NULL);
70901 +#else
70902 SEQ_printf(m, " .base: %pK\n", base);
70903 +#endif
70904 SEQ_printf(m, " .index: %d\n",
70905 base->index);
70906 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70907 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70908 {
70909 struct proc_dir_entry *pe;
70910
70911 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70912 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70913 +#else
70914 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70915 +#endif
70916 if (!pe)
70917 return -ENOMEM;
70918 return 0;
70919 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70920 index 0b537f2..40d6c20 100644
70921 --- a/kernel/time/timer_stats.c
70922 +++ b/kernel/time/timer_stats.c
70923 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70924 static unsigned long nr_entries;
70925 static struct entry entries[MAX_ENTRIES];
70926
70927 -static atomic_t overflow_count;
70928 +static atomic_unchecked_t overflow_count;
70929
70930 /*
70931 * The entries are in a hash-table, for fast lookup:
70932 @@ -140,7 +140,7 @@ static void reset_entries(void)
70933 nr_entries = 0;
70934 memset(entries, 0, sizeof(entries));
70935 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70936 - atomic_set(&overflow_count, 0);
70937 + atomic_set_unchecked(&overflow_count, 0);
70938 }
70939
70940 static struct entry *alloc_entry(void)
70941 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70942 if (likely(entry))
70943 entry->count++;
70944 else
70945 - atomic_inc(&overflow_count);
70946 + atomic_inc_unchecked(&overflow_count);
70947
70948 out_unlock:
70949 raw_spin_unlock_irqrestore(lock, flags);
70950 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70951
70952 static void print_name_offset(struct seq_file *m, unsigned long addr)
70953 {
70954 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70955 + seq_printf(m, "<%p>", NULL);
70956 +#else
70957 char symname[KSYM_NAME_LEN];
70958
70959 if (lookup_symbol_name(addr, symname) < 0)
70960 - seq_printf(m, "<%p>", (void *)addr);
70961 + seq_printf(m, "<%pK>", (void *)addr);
70962 else
70963 seq_printf(m, "%s", symname);
70964 +#endif
70965 }
70966
70967 static int tstats_show(struct seq_file *m, void *v)
70968 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70969
70970 seq_puts(m, "Timer Stats Version: v0.2\n");
70971 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70972 - if (atomic_read(&overflow_count))
70973 + if (atomic_read_unchecked(&overflow_count))
70974 seq_printf(m, "Overflow: %d entries\n",
70975 - atomic_read(&overflow_count));
70976 + atomic_read_unchecked(&overflow_count));
70977
70978 for (i = 0; i < nr_entries; i++) {
70979 entry = entries + i;
70980 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70981 {
70982 struct proc_dir_entry *pe;
70983
70984 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70985 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70986 +#else
70987 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70988 +#endif
70989 if (!pe)
70990 return -ENOMEM;
70991 return 0;
70992 diff --git a/kernel/timer.c b/kernel/timer.c
70993 index 367d008..6e2ac71 100644
70994 --- a/kernel/timer.c
70995 +++ b/kernel/timer.c
70996 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
70997 /*
70998 * This function runs timers and the timer-tq in bottom half context.
70999 */
71000 -static void run_timer_softirq(struct softirq_action *h)
71001 +static void run_timer_softirq(void)
71002 {
71003 struct tvec_base *base = __this_cpu_read(tvec_bases);
71004
71005 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71006 index c0bd030..62a1927 100644
71007 --- a/kernel/trace/blktrace.c
71008 +++ b/kernel/trace/blktrace.c
71009 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71010 struct blk_trace *bt = filp->private_data;
71011 char buf[16];
71012
71013 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71014 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71015
71016 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71017 }
71018 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71019 return 1;
71020
71021 bt = buf->chan->private_data;
71022 - atomic_inc(&bt->dropped);
71023 + atomic_inc_unchecked(&bt->dropped);
71024 return 0;
71025 }
71026
71027 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71028
71029 bt->dir = dir;
71030 bt->dev = dev;
71031 - atomic_set(&bt->dropped, 0);
71032 + atomic_set_unchecked(&bt->dropped, 0);
71033
71034 ret = -EIO;
71035 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71036 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71037 index 9dcf15d..9bab704 100644
71038 --- a/kernel/trace/ftrace.c
71039 +++ b/kernel/trace/ftrace.c
71040 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71041 if (unlikely(ftrace_disabled))
71042 return 0;
71043
71044 + ret = ftrace_arch_code_modify_prepare();
71045 + FTRACE_WARN_ON(ret);
71046 + if (ret)
71047 + return 0;
71048 +
71049 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71050 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71051 if (ret) {
71052 ftrace_bug(ret, ip);
71053 - return 0;
71054 }
71055 - return 1;
71056 + return ret ? 0 : 1;
71057 }
71058
71059 /*
71060 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71061
71062 int
71063 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71064 - void *data)
71065 + void *data)
71066 {
71067 struct ftrace_func_probe *entry;
71068 struct ftrace_page *pg;
71069 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
71070 if (!count)
71071 return 0;
71072
71073 + pax_open_kernel();
71074 sort(start, count, sizeof(*start),
71075 ftrace_cmp_ips, ftrace_swap_ips);
71076 + pax_close_kernel();
71077
71078 start_pg = ftrace_allocate_pages(count);
71079 if (!start_pg)
71080 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
71081 index b979426..c54ff13 100644
71082 --- a/kernel/trace/ring_buffer.c
71083 +++ b/kernel/trace/ring_buffer.c
71084 @@ -346,9 +346,9 @@ struct buffer_data_page {
71085 */
71086 struct buffer_page {
71087 struct list_head list; /* list of buffer pages */
71088 - local_t write; /* index for next write */
71089 + local_unchecked_t write; /* index for next write */
71090 unsigned read; /* index for next read */
71091 - local_t entries; /* entries on this page */
71092 + local_unchecked_t entries; /* entries on this page */
71093 unsigned long real_end; /* real end of data */
71094 struct buffer_data_page *page; /* Actual data page */
71095 };
71096 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
71097 unsigned long lost_events;
71098 unsigned long last_overrun;
71099 local_t entries_bytes;
71100 - local_t commit_overrun;
71101 - local_t overrun;
71102 + local_unchecked_t commit_overrun;
71103 + local_unchecked_t overrun;
71104 local_t entries;
71105 local_t committing;
71106 local_t commits;
71107 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
71108 *
71109 * We add a counter to the write field to denote this.
71110 */
71111 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
71112 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
71113 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
71114 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
71115
71116 /*
71117 * Just make sure we have seen our old_write and synchronize
71118 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
71119 * cmpxchg to only update if an interrupt did not already
71120 * do it for us. If the cmpxchg fails, we don't care.
71121 */
71122 - (void)local_cmpxchg(&next_page->write, old_write, val);
71123 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
71124 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
71125 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
71126
71127 /*
71128 * No need to worry about races with clearing out the commit.
71129 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
71130
71131 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
71132 {
71133 - return local_read(&bpage->entries) & RB_WRITE_MASK;
71134 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
71135 }
71136
71137 static inline unsigned long rb_page_write(struct buffer_page *bpage)
71138 {
71139 - return local_read(&bpage->write) & RB_WRITE_MASK;
71140 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
71141 }
71142
71143 static int
71144 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
71145 * bytes consumed in ring buffer from here.
71146 * Increment overrun to account for the lost events.
71147 */
71148 - local_add(page_entries, &cpu_buffer->overrun);
71149 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
71150 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
71151 }
71152
71153 @@ -1903,7 +1903,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
71154 * it is our responsibility to update
71155 * the counters.
71156 */
71157 - local_add(entries, &cpu_buffer->overrun);
71158 + local_add_unchecked(entries, &cpu_buffer->overrun);
71159 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
71160
71161 /*
71162 @@ -2053,7 +2053,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71163 if (tail == BUF_PAGE_SIZE)
71164 tail_page->real_end = 0;
71165
71166 - local_sub(length, &tail_page->write);
71167 + local_sub_unchecked(length, &tail_page->write);
71168 return;
71169 }
71170
71171 @@ -2088,7 +2088,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71172 rb_event_set_padding(event);
71173
71174 /* Set the write back to the previous setting */
71175 - local_sub(length, &tail_page->write);
71176 + local_sub_unchecked(length, &tail_page->write);
71177 return;
71178 }
71179
71180 @@ -2100,7 +2100,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71181
71182 /* Set write to end of buffer */
71183 length = (tail + length) - BUF_PAGE_SIZE;
71184 - local_sub(length, &tail_page->write);
71185 + local_sub_unchecked(length, &tail_page->write);
71186 }
71187
71188 /*
71189 @@ -2126,7 +2126,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
71190 * about it.
71191 */
71192 if (unlikely(next_page == commit_page)) {
71193 - local_inc(&cpu_buffer->commit_overrun);
71194 + local_inc_unchecked(&cpu_buffer->commit_overrun);
71195 goto out_reset;
71196 }
71197
71198 @@ -2180,7 +2180,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
71199 cpu_buffer->tail_page) &&
71200 (cpu_buffer->commit_page ==
71201 cpu_buffer->reader_page))) {
71202 - local_inc(&cpu_buffer->commit_overrun);
71203 + local_inc_unchecked(&cpu_buffer->commit_overrun);
71204 goto out_reset;
71205 }
71206 }
71207 @@ -2228,7 +2228,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
71208 length += RB_LEN_TIME_EXTEND;
71209
71210 tail_page = cpu_buffer->tail_page;
71211 - write = local_add_return(length, &tail_page->write);
71212 + write = local_add_return_unchecked(length, &tail_page->write);
71213
71214 /* set write to only the index of the write */
71215 write &= RB_WRITE_MASK;
71216 @@ -2245,7 +2245,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
71217 kmemcheck_annotate_bitfield(event, bitfield);
71218 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
71219
71220 - local_inc(&tail_page->entries);
71221 + local_inc_unchecked(&tail_page->entries);
71222
71223 /*
71224 * If this is the first commit on the page, then update
71225 @@ -2278,7 +2278,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
71226
71227 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
71228 unsigned long write_mask =
71229 - local_read(&bpage->write) & ~RB_WRITE_MASK;
71230 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
71231 unsigned long event_length = rb_event_length(event);
71232 /*
71233 * This is on the tail page. It is possible that
71234 @@ -2288,7 +2288,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
71235 */
71236 old_index += write_mask;
71237 new_index += write_mask;
71238 - index = local_cmpxchg(&bpage->write, old_index, new_index);
71239 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
71240 if (index == old_index) {
71241 /* update counters */
71242 local_sub(event_length, &cpu_buffer->entries_bytes);
71243 @@ -2627,7 +2627,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
71244
71245 /* Do the likely case first */
71246 if (likely(bpage->page == (void *)addr)) {
71247 - local_dec(&bpage->entries);
71248 + local_dec_unchecked(&bpage->entries);
71249 return;
71250 }
71251
71252 @@ -2639,7 +2639,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
71253 start = bpage;
71254 do {
71255 if (bpage->page == (void *)addr) {
71256 - local_dec(&bpage->entries);
71257 + local_dec_unchecked(&bpage->entries);
71258 return;
71259 }
71260 rb_inc_page(cpu_buffer, &bpage);
71261 @@ -2921,7 +2921,7 @@ static inline unsigned long
71262 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
71263 {
71264 return local_read(&cpu_buffer->entries) -
71265 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
71266 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
71267 }
71268
71269 /**
71270 @@ -3008,7 +3008,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
71271 return 0;
71272
71273 cpu_buffer = buffer->buffers[cpu];
71274 - ret = local_read(&cpu_buffer->overrun);
71275 + ret = local_read_unchecked(&cpu_buffer->overrun);
71276
71277 return ret;
71278 }
71279 @@ -3029,7 +3029,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
71280 return 0;
71281
71282 cpu_buffer = buffer->buffers[cpu];
71283 - ret = local_read(&cpu_buffer->commit_overrun);
71284 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
71285
71286 return ret;
71287 }
71288 @@ -3074,7 +3074,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
71289 /* if you care about this being correct, lock the buffer */
71290 for_each_buffer_cpu(buffer, cpu) {
71291 cpu_buffer = buffer->buffers[cpu];
71292 - overruns += local_read(&cpu_buffer->overrun);
71293 + overruns += local_read_unchecked(&cpu_buffer->overrun);
71294 }
71295
71296 return overruns;
71297 @@ -3250,8 +3250,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
71298 /*
71299 * Reset the reader page to size zero.
71300 */
71301 - local_set(&cpu_buffer->reader_page->write, 0);
71302 - local_set(&cpu_buffer->reader_page->entries, 0);
71303 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
71304 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
71305 local_set(&cpu_buffer->reader_page->page->commit, 0);
71306 cpu_buffer->reader_page->real_end = 0;
71307
71308 @@ -3283,7 +3283,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
71309 * want to compare with the last_overrun.
71310 */
71311 smp_mb();
71312 - overwrite = local_read(&(cpu_buffer->overrun));
71313 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
71314
71315 /*
71316 * Here's the tricky part.
71317 @@ -3848,8 +3848,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
71318
71319 cpu_buffer->head_page
71320 = list_entry(cpu_buffer->pages, struct buffer_page, list);
71321 - local_set(&cpu_buffer->head_page->write, 0);
71322 - local_set(&cpu_buffer->head_page->entries, 0);
71323 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
71324 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
71325 local_set(&cpu_buffer->head_page->page->commit, 0);
71326
71327 cpu_buffer->head_page->read = 0;
71328 @@ -3859,14 +3859,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
71329
71330 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
71331 INIT_LIST_HEAD(&cpu_buffer->new_pages);
71332 - local_set(&cpu_buffer->reader_page->write, 0);
71333 - local_set(&cpu_buffer->reader_page->entries, 0);
71334 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
71335 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
71336 local_set(&cpu_buffer->reader_page->page->commit, 0);
71337 cpu_buffer->reader_page->read = 0;
71338
71339 - local_set(&cpu_buffer->commit_overrun, 0);
71340 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
71341 local_set(&cpu_buffer->entries_bytes, 0);
71342 - local_set(&cpu_buffer->overrun, 0);
71343 + local_set_unchecked(&cpu_buffer->overrun, 0);
71344 local_set(&cpu_buffer->entries, 0);
71345 local_set(&cpu_buffer->committing, 0);
71346 local_set(&cpu_buffer->commits, 0);
71347 @@ -4269,8 +4269,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
71348 rb_init_page(bpage);
71349 bpage = reader->page;
71350 reader->page = *data_page;
71351 - local_set(&reader->write, 0);
71352 - local_set(&reader->entries, 0);
71353 + local_set_unchecked(&reader->write, 0);
71354 + local_set_unchecked(&reader->entries, 0);
71355 reader->read = 0;
71356 *data_page = bpage;
71357
71358 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71359 index 31e4f55..62da00f 100644
71360 --- a/kernel/trace/trace.c
71361 +++ b/kernel/trace/trace.c
71362 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71363 };
71364 #endif
71365
71366 -static struct dentry *d_tracer;
71367 -
71368 struct dentry *tracing_init_dentry(void)
71369 {
71370 + static struct dentry *d_tracer;
71371 static int once;
71372
71373 if (d_tracer)
71374 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
71375 return d_tracer;
71376 }
71377
71378 -static struct dentry *d_percpu;
71379 -
71380 struct dentry *tracing_dentry_percpu(void)
71381 {
71382 + static struct dentry *d_percpu;
71383 static int once;
71384 struct dentry *d_tracer;
71385
71386 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71387 index d608d09..7eddcb1 100644
71388 --- a/kernel/trace/trace_events.c
71389 +++ b/kernel/trace/trace_events.c
71390 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
71391 struct ftrace_module_file_ops {
71392 struct list_head list;
71393 struct module *mod;
71394 - struct file_operations id;
71395 - struct file_operations enable;
71396 - struct file_operations format;
71397 - struct file_operations filter;
71398 };
71399
71400 static struct ftrace_module_file_ops *
71401 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
71402
71403 file_ops->mod = mod;
71404
71405 - file_ops->id = ftrace_event_id_fops;
71406 - file_ops->id.owner = mod;
71407 -
71408 - file_ops->enable = ftrace_enable_fops;
71409 - file_ops->enable.owner = mod;
71410 -
71411 - file_ops->filter = ftrace_event_filter_fops;
71412 - file_ops->filter.owner = mod;
71413 -
71414 - file_ops->format = ftrace_event_format_fops;
71415 - file_ops->format.owner = mod;
71416 + pax_open_kernel();
71417 + *(void **)&mod->trace_id.owner = mod;
71418 + *(void **)&mod->trace_enable.owner = mod;
71419 + *(void **)&mod->trace_filter.owner = mod;
71420 + *(void **)&mod->trace_format.owner = mod;
71421 + pax_close_kernel();
71422
71423 list_add(&file_ops->list, &ftrace_module_file_list);
71424
71425 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
71426
71427 for_each_event(call, start, end) {
71428 __trace_add_event_call(*call, mod,
71429 - &file_ops->id, &file_ops->enable,
71430 - &file_ops->filter, &file_ops->format);
71431 + &mod->trace_id, &mod->trace_enable,
71432 + &mod->trace_filter, &mod->trace_format);
71433 }
71434 }
71435
71436 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71437 index fd3c8aa..5f324a6 100644
71438 --- a/kernel/trace/trace_mmiotrace.c
71439 +++ b/kernel/trace/trace_mmiotrace.c
71440 @@ -24,7 +24,7 @@ struct header_iter {
71441 static struct trace_array *mmio_trace_array;
71442 static bool overrun_detected;
71443 static unsigned long prev_overruns;
71444 -static atomic_t dropped_count;
71445 +static atomic_unchecked_t dropped_count;
71446
71447 static void mmio_reset_data(struct trace_array *tr)
71448 {
71449 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71450
71451 static unsigned long count_overruns(struct trace_iterator *iter)
71452 {
71453 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71454 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71455 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71456
71457 if (over > prev_overruns)
71458 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71459 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71460 sizeof(*entry), 0, pc);
71461 if (!event) {
71462 - atomic_inc(&dropped_count);
71463 + atomic_inc_unchecked(&dropped_count);
71464 return;
71465 }
71466 entry = ring_buffer_event_data(event);
71467 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71468 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71469 sizeof(*entry), 0, pc);
71470 if (!event) {
71471 - atomic_inc(&dropped_count);
71472 + atomic_inc_unchecked(&dropped_count);
71473 return;
71474 }
71475 entry = ring_buffer_event_data(event);
71476 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71477 index 123b189..97b81f5 100644
71478 --- a/kernel/trace/trace_output.c
71479 +++ b/kernel/trace/trace_output.c
71480 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71481
71482 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71483 if (!IS_ERR(p)) {
71484 - p = mangle_path(s->buffer + s->len, p, "\n");
71485 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71486 if (p) {
71487 s->len = p - s->buffer;
71488 return 1;
71489 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71490 index 0c1b1657..95337e9 100644
71491 --- a/kernel/trace/trace_stack.c
71492 +++ b/kernel/trace/trace_stack.c
71493 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71494 return;
71495
71496 /* we do not handle interrupt stacks yet */
71497 - if (!object_is_on_stack(&this_size))
71498 + if (!object_starts_on_stack(&this_size))
71499 return;
71500
71501 local_irq_save(flags);
71502 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71503 index 28e9d6c9..50381bd 100644
71504 --- a/lib/Kconfig.debug
71505 +++ b/lib/Kconfig.debug
71506 @@ -1278,6 +1278,7 @@ config LATENCYTOP
71507 depends on DEBUG_KERNEL
71508 depends on STACKTRACE_SUPPORT
71509 depends on PROC_FS
71510 + depends on !GRKERNSEC_HIDESYM
71511 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71512 select KALLSYMS
71513 select KALLSYMS_ALL
71514 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
71515
71516 config PROVIDE_OHCI1394_DMA_INIT
71517 bool "Remote debugging over FireWire early on boot"
71518 - depends on PCI && X86
71519 + depends on PCI && X86 && !GRKERNSEC
71520 help
71521 If you want to debug problems which hang or crash the kernel early
71522 on boot and the crashing machine has a FireWire port, you can use
71523 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71524
71525 config FIREWIRE_OHCI_REMOTE_DMA
71526 bool "Remote debugging over FireWire with firewire-ohci"
71527 - depends on FIREWIRE_OHCI
71528 + depends on FIREWIRE_OHCI && !GRKERNSEC
71529 help
71530 This option lets you use the FireWire bus for remote debugging
71531 with help of the firewire-ohci driver. It enables unfiltered
71532 diff --git a/lib/bitmap.c b/lib/bitmap.c
71533 index 06fdfa1..97c5c7d 100644
71534 --- a/lib/bitmap.c
71535 +++ b/lib/bitmap.c
71536 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71537 {
71538 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71539 u32 chunk;
71540 - const char __user __force *ubuf = (const char __user __force *)buf;
71541 + const char __user *ubuf = (const char __force_user *)buf;
71542
71543 bitmap_zero(maskp, nmaskbits);
71544
71545 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71546 {
71547 if (!access_ok(VERIFY_READ, ubuf, ulen))
71548 return -EFAULT;
71549 - return __bitmap_parse((const char __force *)ubuf,
71550 + return __bitmap_parse((const char __force_kernel *)ubuf,
71551 ulen, 1, maskp, nmaskbits);
71552
71553 }
71554 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71555 {
71556 unsigned a, b;
71557 int c, old_c, totaldigits;
71558 - const char __user __force *ubuf = (const char __user __force *)buf;
71559 + const char __user *ubuf = (const char __force_user *)buf;
71560 int exp_digit, in_range;
71561
71562 totaldigits = c = 0;
71563 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71564 {
71565 if (!access_ok(VERIFY_READ, ubuf, ulen))
71566 return -EFAULT;
71567 - return __bitmap_parselist((const char __force *)ubuf,
71568 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71569 ulen, 1, maskp, nmaskbits);
71570 }
71571 EXPORT_SYMBOL(bitmap_parselist_user);
71572 diff --git a/lib/bug.c b/lib/bug.c
71573 index a28c141..2bd3d95 100644
71574 --- a/lib/bug.c
71575 +++ b/lib/bug.c
71576 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71577 return BUG_TRAP_TYPE_NONE;
71578
71579 bug = find_bug(bugaddr);
71580 + if (!bug)
71581 + return BUG_TRAP_TYPE_NONE;
71582
71583 file = NULL;
71584 line = 0;
71585 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71586 index d11808c..dc2d6f8 100644
71587 --- a/lib/debugobjects.c
71588 +++ b/lib/debugobjects.c
71589 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71590 if (limit > 4)
71591 return;
71592
71593 - is_on_stack = object_is_on_stack(addr);
71594 + is_on_stack = object_starts_on_stack(addr);
71595 if (is_on_stack == onstack)
71596 return;
71597
71598 diff --git a/lib/devres.c b/lib/devres.c
71599 index 80b9c76..9e32279 100644
71600 --- a/lib/devres.c
71601 +++ b/lib/devres.c
71602 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71603 void devm_iounmap(struct device *dev, void __iomem *addr)
71604 {
71605 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71606 - (void *)addr));
71607 + (void __force *)addr));
71608 iounmap(addr);
71609 }
71610 EXPORT_SYMBOL(devm_iounmap);
71611 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71612 {
71613 ioport_unmap(addr);
71614 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71615 - devm_ioport_map_match, (void *)addr));
71616 + devm_ioport_map_match, (void __force *)addr));
71617 }
71618 EXPORT_SYMBOL(devm_ioport_unmap);
71619
71620 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71621 index d84beb9..10a4749 100644
71622 --- a/lib/dma-debug.c
71623 +++ b/lib/dma-debug.c
71624 @@ -919,7 +919,7 @@ out:
71625
71626 static void check_for_stack(struct device *dev, void *addr)
71627 {
71628 - if (object_is_on_stack(addr))
71629 + if (object_starts_on_stack(addr))
71630 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71631 "stack [addr=%p]\n", addr);
71632 }
71633 diff --git a/lib/inflate.c b/lib/inflate.c
71634 index 013a761..c28f3fc 100644
71635 --- a/lib/inflate.c
71636 +++ b/lib/inflate.c
71637 @@ -269,7 +269,7 @@ static void free(void *where)
71638 malloc_ptr = free_mem_ptr;
71639 }
71640 #else
71641 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71642 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71643 #define free(a) kfree(a)
71644 #endif
71645
71646 diff --git a/lib/ioremap.c b/lib/ioremap.c
71647 index 0c9216c..863bd89 100644
71648 --- a/lib/ioremap.c
71649 +++ b/lib/ioremap.c
71650 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71651 unsigned long next;
71652
71653 phys_addr -= addr;
71654 - pmd = pmd_alloc(&init_mm, pud, addr);
71655 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71656 if (!pmd)
71657 return -ENOMEM;
71658 do {
71659 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71660 unsigned long next;
71661
71662 phys_addr -= addr;
71663 - pud = pud_alloc(&init_mm, pgd, addr);
71664 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71665 if (!pud)
71666 return -ENOMEM;
71667 do {
71668 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71669 index bd2bea9..6b3c95e 100644
71670 --- a/lib/is_single_threaded.c
71671 +++ b/lib/is_single_threaded.c
71672 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71673 struct task_struct *p, *t;
71674 bool ret;
71675
71676 + if (!mm)
71677 + return true;
71678 +
71679 if (atomic_read(&task->signal->live) != 1)
71680 return false;
71681
71682 diff --git a/lib/list_debug.c b/lib/list_debug.c
71683 index c24c2f7..bef49ee 100644
71684 --- a/lib/list_debug.c
71685 +++ b/lib/list_debug.c
71686 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71687 struct list_head *prev,
71688 struct list_head *next)
71689 {
71690 - WARN(next->prev != prev,
71691 + if (WARN(next->prev != prev,
71692 "list_add corruption. next->prev should be "
71693 "prev (%p), but was %p. (next=%p).\n",
71694 - prev, next->prev, next);
71695 - WARN(prev->next != next,
71696 + prev, next->prev, next) ||
71697 + WARN(prev->next != next,
71698 "list_add corruption. prev->next should be "
71699 "next (%p), but was %p. (prev=%p).\n",
71700 - next, prev->next, prev);
71701 - WARN(new == prev || new == next,
71702 + next, prev->next, prev) ||
71703 + WARN(new == prev || new == next,
71704 "list_add double add: new=%p, prev=%p, next=%p.\n",
71705 - new, prev, next);
71706 + new, prev, next))
71707 + return;
71708 +
71709 next->prev = new;
71710 new->next = next;
71711 new->prev = prev;
71712 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71713 void __list_add_rcu(struct list_head *new,
71714 struct list_head *prev, struct list_head *next)
71715 {
71716 - WARN(next->prev != prev,
71717 + if (WARN(next->prev != prev,
71718 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71719 - prev, next->prev, next);
71720 - WARN(prev->next != next,
71721 + prev, next->prev, next) ||
71722 + WARN(prev->next != next,
71723 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71724 - next, prev->next, prev);
71725 + next, prev->next, prev))
71726 + return;
71727 +
71728 new->next = next;
71729 new->prev = prev;
71730 rcu_assign_pointer(list_next_rcu(prev), new);
71731 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71732 index e796429..6e38f9f 100644
71733 --- a/lib/radix-tree.c
71734 +++ b/lib/radix-tree.c
71735 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71736 int nr;
71737 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71738 };
71739 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71740 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71741
71742 static inline void *ptr_to_indirect(void *ptr)
71743 {
71744 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71745 index bb2b201..46abaf9 100644
71746 --- a/lib/strncpy_from_user.c
71747 +++ b/lib/strncpy_from_user.c
71748 @@ -21,7 +21,7 @@
71749 */
71750 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71751 {
71752 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71753 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71754 long res = 0;
71755
71756 /*
71757 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71758 index a28df52..3d55877 100644
71759 --- a/lib/strnlen_user.c
71760 +++ b/lib/strnlen_user.c
71761 @@ -26,7 +26,7 @@
71762 */
71763 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71764 {
71765 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71766 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71767 long align, res = 0;
71768 unsigned long c;
71769
71770 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71771 index 39c99fe..ba3f00d 100644
71772 --- a/lib/vsprintf.c
71773 +++ b/lib/vsprintf.c
71774 @@ -16,6 +16,9 @@
71775 * - scnprintf and vscnprintf
71776 */
71777
71778 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71779 +#define __INCLUDED_BY_HIDESYM 1
71780 +#endif
71781 #include <stdarg.h>
71782 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71783 #include <linux/types.h>
71784 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71785 char sym[KSYM_SYMBOL_LEN];
71786 if (ext == 'B')
71787 sprint_backtrace(sym, value);
71788 - else if (ext != 'f' && ext != 's')
71789 + else if (ext != 'f' && ext != 's' && ext != 'a')
71790 sprint_symbol(sym, value);
71791 else
71792 sprint_symbol_no_offset(sym, value);
71793 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71794 return number(buf, end, *(const netdev_features_t *)addr, spec);
71795 }
71796
71797 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71798 +int kptr_restrict __read_mostly = 2;
71799 +#else
71800 int kptr_restrict __read_mostly;
71801 +#endif
71802
71803 /*
71804 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71805 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
71806 * - 'S' For symbolic direct pointers with offset
71807 * - 's' For symbolic direct pointers without offset
71808 * - 'B' For backtraced symbolic direct pointers with offset
71809 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71810 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71811 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71812 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71813 * - 'M' For a 6-byte MAC address, it prints the address in the
71814 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71815
71816 if (!ptr && *fmt != 'K') {
71817 /*
71818 - * Print (null) with the same width as a pointer so it makes
71819 + * Print (nil) with the same width as a pointer so it makes
71820 * tabular output look nice.
71821 */
71822 if (spec.field_width == -1)
71823 spec.field_width = default_width;
71824 - return string(buf, end, "(null)", spec);
71825 + return string(buf, end, "(nil)", spec);
71826 }
71827
71828 switch (*fmt) {
71829 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71830 /* Fallthrough */
71831 case 'S':
71832 case 's':
71833 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71834 + break;
71835 +#else
71836 + return symbol_string(buf, end, ptr, spec, *fmt);
71837 +#endif
71838 + case 'A':
71839 + case 'a':
71840 case 'B':
71841 return symbol_string(buf, end, ptr, spec, *fmt);
71842 case 'R':
71843 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71844 va_end(va);
71845 return buf;
71846 }
71847 + case 'P':
71848 + break;
71849 case 'K':
71850 /*
71851 * %pK cannot be used in IRQ context because its test
71852 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71853 }
71854 break;
71855 }
71856 +
71857 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71858 + /* 'P' = approved pointers to copy to userland,
71859 + as in the /proc/kallsyms case, as we make it display nothing
71860 + for non-root users, and the real contents for root users
71861 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71862 + above
71863 + */
71864 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71865 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71866 + dump_stack();
71867 + ptr = NULL;
71868 + }
71869 +#endif
71870 +
71871 spec.flags |= SMALL;
71872 if (spec.field_width == -1) {
71873 spec.field_width = default_width;
71874 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71875 typeof(type) value; \
71876 if (sizeof(type) == 8) { \
71877 args = PTR_ALIGN(args, sizeof(u32)); \
71878 - *(u32 *)&value = *(u32 *)args; \
71879 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71880 + *(u32 *)&value = *(const u32 *)args; \
71881 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71882 } else { \
71883 args = PTR_ALIGN(args, sizeof(type)); \
71884 - value = *(typeof(type) *)args; \
71885 + value = *(const typeof(type) *)args; \
71886 } \
71887 args += sizeof(type); \
71888 value; \
71889 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71890 case FORMAT_TYPE_STR: {
71891 const char *str_arg = args;
71892 args += strlen(str_arg) + 1;
71893 - str = string(str, end, (char *)str_arg, spec);
71894 + str = string(str, end, str_arg, spec);
71895 break;
71896 }
71897
71898 diff --git a/localversion-grsec b/localversion-grsec
71899 new file mode 100644
71900 index 0000000..7cd6065
71901 --- /dev/null
71902 +++ b/localversion-grsec
71903 @@ -0,0 +1 @@
71904 +-grsec
71905 diff --git a/mm/Kconfig b/mm/Kconfig
71906 index a3f8ddd..f31e92e 100644
71907 --- a/mm/Kconfig
71908 +++ b/mm/Kconfig
71909 @@ -252,10 +252,10 @@ config KSM
71910 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71911
71912 config DEFAULT_MMAP_MIN_ADDR
71913 - int "Low address space to protect from user allocation"
71914 + int "Low address space to protect from user allocation"
71915 depends on MMU
71916 - default 4096
71917 - help
71918 + default 65536
71919 + help
71920 This is the portion of low virtual memory which should be protected
71921 from userspace allocation. Keeping a user from writing to low pages
71922 can help reduce the impact of kernel NULL pointer bugs.
71923 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
71924
71925 config HWPOISON_INJECT
71926 tristate "HWPoison pages injector"
71927 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71928 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71929 select PROC_PAGE_MONITOR
71930
71931 config NOMMU_INITIAL_TRIM_EXCESS
71932 diff --git a/mm/filemap.c b/mm/filemap.c
71933 index 83efee7..3f99381 100644
71934 --- a/mm/filemap.c
71935 +++ b/mm/filemap.c
71936 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71937 struct address_space *mapping = file->f_mapping;
71938
71939 if (!mapping->a_ops->readpage)
71940 - return -ENOEXEC;
71941 + return -ENODEV;
71942 file_accessed(file);
71943 vma->vm_ops = &generic_file_vm_ops;
71944 return 0;
71945 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71946 *pos = i_size_read(inode);
71947
71948 if (limit != RLIM_INFINITY) {
71949 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71950 if (*pos >= limit) {
71951 send_sig(SIGXFSZ, current, 0);
71952 return -EFBIG;
71953 diff --git a/mm/fremap.c b/mm/fremap.c
71954 index a0aaf0e..20325c3 100644
71955 --- a/mm/fremap.c
71956 +++ b/mm/fremap.c
71957 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71958 retry:
71959 vma = find_vma(mm, start);
71960
71961 +#ifdef CONFIG_PAX_SEGMEXEC
71962 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71963 + goto out;
71964 +#endif
71965 +
71966 /*
71967 * Make sure the vma is shared, that it supports prefaulting,
71968 * and that the remapped range is valid and fully within
71969 diff --git a/mm/highmem.c b/mm/highmem.c
71970 index 2da13a5..9568fec 100644
71971 --- a/mm/highmem.c
71972 +++ b/mm/highmem.c
71973 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71974 * So no dangers, even with speculative execution.
71975 */
71976 page = pte_page(pkmap_page_table[i]);
71977 + pax_open_kernel();
71978 pte_clear(&init_mm, (unsigned long)page_address(page),
71979 &pkmap_page_table[i]);
71980 -
71981 + pax_close_kernel();
71982 set_page_address(page, NULL);
71983 need_flush = 1;
71984 }
71985 @@ -198,9 +199,11 @@ start:
71986 }
71987 }
71988 vaddr = PKMAP_ADDR(last_pkmap_nr);
71989 +
71990 + pax_open_kernel();
71991 set_pte_at(&init_mm, vaddr,
71992 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71993 -
71994 + pax_close_kernel();
71995 pkmap_count[last_pkmap_nr] = 1;
71996 set_page_address(page, (void *)vaddr);
71997
71998 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71999 index 40f17c3..c1cc011 100644
72000 --- a/mm/huge_memory.c
72001 +++ b/mm/huge_memory.c
72002 @@ -710,7 +710,7 @@ out:
72003 * run pte_offset_map on the pmd, if an huge pmd could
72004 * materialize from under us from a different thread.
72005 */
72006 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72007 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72008 return VM_FAULT_OOM;
72009 /* if an huge pmd materialized from under us just retry later */
72010 if (unlikely(pmd_trans_huge(*pmd)))
72011 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72012 index 59a0059..b3f3d86 100644
72013 --- a/mm/hugetlb.c
72014 +++ b/mm/hugetlb.c
72015 @@ -2518,6 +2518,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72016 return 1;
72017 }
72018
72019 +#ifdef CONFIG_PAX_SEGMEXEC
72020 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72021 +{
72022 + struct mm_struct *mm = vma->vm_mm;
72023 + struct vm_area_struct *vma_m;
72024 + unsigned long address_m;
72025 + pte_t *ptep_m;
72026 +
72027 + vma_m = pax_find_mirror_vma(vma);
72028 + if (!vma_m)
72029 + return;
72030 +
72031 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72032 + address_m = address + SEGMEXEC_TASK_SIZE;
72033 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72034 + get_page(page_m);
72035 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
72036 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72037 +}
72038 +#endif
72039 +
72040 /*
72041 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72042 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72043 @@ -2636,6 +2657,11 @@ retry_avoidcopy:
72044 make_huge_pte(vma, new_page, 1));
72045 page_remove_rmap(old_page);
72046 hugepage_add_new_anon_rmap(new_page, vma, address);
72047 +
72048 +#ifdef CONFIG_PAX_SEGMEXEC
72049 + pax_mirror_huge_pte(vma, address, new_page);
72050 +#endif
72051 +
72052 /* Make the old page be freed below */
72053 new_page = old_page;
72054 }
72055 @@ -2795,6 +2821,10 @@ retry:
72056 && (vma->vm_flags & VM_SHARED)));
72057 set_huge_pte_at(mm, address, ptep, new_pte);
72058
72059 +#ifdef CONFIG_PAX_SEGMEXEC
72060 + pax_mirror_huge_pte(vma, address, page);
72061 +#endif
72062 +
72063 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72064 /* Optimization, do the COW without a second fault */
72065 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72066 @@ -2824,6 +2854,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72067 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72068 struct hstate *h = hstate_vma(vma);
72069
72070 +#ifdef CONFIG_PAX_SEGMEXEC
72071 + struct vm_area_struct *vma_m;
72072 +#endif
72073 +
72074 address &= huge_page_mask(h);
72075
72076 ptep = huge_pte_offset(mm, address);
72077 @@ -2837,6 +2871,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72078 VM_FAULT_SET_HINDEX(hstate_index(h));
72079 }
72080
72081 +#ifdef CONFIG_PAX_SEGMEXEC
72082 + vma_m = pax_find_mirror_vma(vma);
72083 + if (vma_m) {
72084 + unsigned long address_m;
72085 +
72086 + if (vma->vm_start > vma_m->vm_start) {
72087 + address_m = address;
72088 + address -= SEGMEXEC_TASK_SIZE;
72089 + vma = vma_m;
72090 + h = hstate_vma(vma);
72091 + } else
72092 + address_m = address + SEGMEXEC_TASK_SIZE;
72093 +
72094 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72095 + return VM_FAULT_OOM;
72096 + address_m &= HPAGE_MASK;
72097 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72098 + }
72099 +#endif
72100 +
72101 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72102 if (!ptep)
72103 return VM_FAULT_OOM;
72104 diff --git a/mm/internal.h b/mm/internal.h
72105 index a4fa284..9a02499 100644
72106 --- a/mm/internal.h
72107 +++ b/mm/internal.h
72108 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72109 * in mm/page_alloc.c
72110 */
72111 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72112 +extern void free_compound_page(struct page *page);
72113 extern void prep_compound_page(struct page *page, unsigned long order);
72114 #ifdef CONFIG_MEMORY_FAILURE
72115 extern bool is_free_buddy_page(struct page *page);
72116 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72117 index a217cc5..74c9ec0 100644
72118 --- a/mm/kmemleak.c
72119 +++ b/mm/kmemleak.c
72120 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72121
72122 for (i = 0; i < object->trace_len; i++) {
72123 void *ptr = (void *)object->trace[i];
72124 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72125 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72126 }
72127 }
72128
72129 diff --git a/mm/maccess.c b/mm/maccess.c
72130 index d53adf9..03a24bf 100644
72131 --- a/mm/maccess.c
72132 +++ b/mm/maccess.c
72133 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72134 set_fs(KERNEL_DS);
72135 pagefault_disable();
72136 ret = __copy_from_user_inatomic(dst,
72137 - (__force const void __user *)src, size);
72138 + (const void __force_user *)src, size);
72139 pagefault_enable();
72140 set_fs(old_fs);
72141
72142 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72143
72144 set_fs(KERNEL_DS);
72145 pagefault_disable();
72146 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72147 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72148 pagefault_enable();
72149 set_fs(old_fs);
72150
72151 diff --git a/mm/madvise.c b/mm/madvise.c
72152 index 03dfa5c..b032917 100644
72153 --- a/mm/madvise.c
72154 +++ b/mm/madvise.c
72155 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72156 pgoff_t pgoff;
72157 unsigned long new_flags = vma->vm_flags;
72158
72159 +#ifdef CONFIG_PAX_SEGMEXEC
72160 + struct vm_area_struct *vma_m;
72161 +#endif
72162 +
72163 switch (behavior) {
72164 case MADV_NORMAL:
72165 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72166 @@ -123,6 +127,13 @@ success:
72167 /*
72168 * vm_flags is protected by the mmap_sem held in write mode.
72169 */
72170 +
72171 +#ifdef CONFIG_PAX_SEGMEXEC
72172 + vma_m = pax_find_mirror_vma(vma);
72173 + if (vma_m)
72174 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72175 +#endif
72176 +
72177 vma->vm_flags = new_flags;
72178
72179 out:
72180 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72181 struct vm_area_struct ** prev,
72182 unsigned long start, unsigned long end)
72183 {
72184 +
72185 +#ifdef CONFIG_PAX_SEGMEXEC
72186 + struct vm_area_struct *vma_m;
72187 +#endif
72188 +
72189 *prev = vma;
72190 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72191 return -EINVAL;
72192 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72193 zap_page_range(vma, start, end - start, &details);
72194 } else
72195 zap_page_range(vma, start, end - start, NULL);
72196 +
72197 +#ifdef CONFIG_PAX_SEGMEXEC
72198 + vma_m = pax_find_mirror_vma(vma);
72199 + if (vma_m) {
72200 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72201 + struct zap_details details = {
72202 + .nonlinear_vma = vma_m,
72203 + .last_index = ULONG_MAX,
72204 + };
72205 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72206 + } else
72207 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72208 + }
72209 +#endif
72210 +
72211 return 0;
72212 }
72213
72214 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72215 if (end < start)
72216 goto out;
72217
72218 +#ifdef CONFIG_PAX_SEGMEXEC
72219 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72220 + if (end > SEGMEXEC_TASK_SIZE)
72221 + goto out;
72222 + } else
72223 +#endif
72224 +
72225 + if (end > TASK_SIZE)
72226 + goto out;
72227 +
72228 error = 0;
72229 if (end == start)
72230 goto out;
72231 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72232 index 8b20278..05dac18 100644
72233 --- a/mm/memory-failure.c
72234 +++ b/mm/memory-failure.c
72235 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72236
72237 int sysctl_memory_failure_recovery __read_mostly = 1;
72238
72239 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72240 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72241
72242 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72243
72244 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72245 pfn, t->comm, t->pid);
72246 si.si_signo = SIGBUS;
72247 si.si_errno = 0;
72248 - si.si_addr = (void *)addr;
72249 + si.si_addr = (void __user *)addr;
72250 #ifdef __ARCH_SI_TRAPNO
72251 si.si_trapno = trapno;
72252 #endif
72253 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72254 }
72255
72256 nr_pages = 1 << compound_trans_order(hpage);
72257 - atomic_long_add(nr_pages, &mce_bad_pages);
72258 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72259
72260 /*
72261 * We need/can do nothing about count=0 pages.
72262 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72263 if (!PageHWPoison(hpage)
72264 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72265 || (p != hpage && TestSetPageHWPoison(hpage))) {
72266 - atomic_long_sub(nr_pages, &mce_bad_pages);
72267 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72268 return 0;
72269 }
72270 set_page_hwpoison_huge_page(hpage);
72271 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72272 }
72273 if (hwpoison_filter(p)) {
72274 if (TestClearPageHWPoison(p))
72275 - atomic_long_sub(nr_pages, &mce_bad_pages);
72276 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72277 unlock_page(hpage);
72278 put_page(hpage);
72279 return 0;
72280 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
72281 return 0;
72282 }
72283 if (TestClearPageHWPoison(p))
72284 - atomic_long_sub(nr_pages, &mce_bad_pages);
72285 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72286 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72287 return 0;
72288 }
72289 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
72290 */
72291 if (TestClearPageHWPoison(page)) {
72292 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72293 - atomic_long_sub(nr_pages, &mce_bad_pages);
72294 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72295 freeit = 1;
72296 if (PageHuge(page))
72297 clear_page_hwpoison_huge_page(page);
72298 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72299 }
72300 done:
72301 if (!PageHWPoison(hpage))
72302 - atomic_long_add(1 << compound_trans_order(hpage),
72303 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72304 &mce_bad_pages);
72305 set_page_hwpoison_huge_page(hpage);
72306 dequeue_hwpoisoned_huge_page(hpage);
72307 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
72308 return ret;
72309
72310 done:
72311 - atomic_long_add(1, &mce_bad_pages);
72312 + atomic_long_add_unchecked(1, &mce_bad_pages);
72313 SetPageHWPoison(page);
72314 /* keep elevated page count for bad page */
72315 return ret;
72316 diff --git a/mm/memory.c b/mm/memory.c
72317 index 221fc9f..d1d4db1 100644
72318 --- a/mm/memory.c
72319 +++ b/mm/memory.c
72320 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72321 free_pte_range(tlb, pmd, addr);
72322 } while (pmd++, addr = next, addr != end);
72323
72324 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72325 start &= PUD_MASK;
72326 if (start < floor)
72327 return;
72328 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72329 pmd = pmd_offset(pud, start);
72330 pud_clear(pud);
72331 pmd_free_tlb(tlb, pmd, start);
72332 +#endif
72333 +
72334 }
72335
72336 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72337 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72338 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72339 } while (pud++, addr = next, addr != end);
72340
72341 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72342 start &= PGDIR_MASK;
72343 if (start < floor)
72344 return;
72345 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72346 pud = pud_offset(pgd, start);
72347 pgd_clear(pgd);
72348 pud_free_tlb(tlb, pud, start);
72349 +#endif
72350 +
72351 }
72352
72353 /*
72354 @@ -1621,12 +1627,6 @@ no_page_table:
72355 return page;
72356 }
72357
72358 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72359 -{
72360 - return stack_guard_page_start(vma, addr) ||
72361 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72362 -}
72363 -
72364 /**
72365 * __get_user_pages() - pin user pages in memory
72366 * @tsk: task_struct of target task
72367 @@ -1699,10 +1699,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72368 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72369 i = 0;
72370
72371 - do {
72372 + while (nr_pages) {
72373 struct vm_area_struct *vma;
72374
72375 - vma = find_extend_vma(mm, start);
72376 + vma = find_vma(mm, start);
72377 if (!vma && in_gate_area(mm, start)) {
72378 unsigned long pg = start & PAGE_MASK;
72379 pgd_t *pgd;
72380 @@ -1750,7 +1750,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72381 goto next_page;
72382 }
72383
72384 - if (!vma ||
72385 + if (!vma || start < vma->vm_start ||
72386 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72387 !(vm_flags & vma->vm_flags))
72388 return i ? : -EFAULT;
72389 @@ -1777,11 +1777,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72390 int ret;
72391 unsigned int fault_flags = 0;
72392
72393 - /* For mlock, just skip the stack guard page. */
72394 - if (foll_flags & FOLL_MLOCK) {
72395 - if (stack_guard_page(vma, start))
72396 - goto next_page;
72397 - }
72398 if (foll_flags & FOLL_WRITE)
72399 fault_flags |= FAULT_FLAG_WRITE;
72400 if (nonblocking)
72401 @@ -1855,7 +1850,7 @@ next_page:
72402 start += PAGE_SIZE;
72403 nr_pages--;
72404 } while (nr_pages && start < vma->vm_end);
72405 - } while (nr_pages);
72406 + }
72407 return i;
72408 }
72409 EXPORT_SYMBOL(__get_user_pages);
72410 @@ -2062,6 +2057,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72411 page_add_file_rmap(page);
72412 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72413
72414 +#ifdef CONFIG_PAX_SEGMEXEC
72415 + pax_mirror_file_pte(vma, addr, page, ptl);
72416 +#endif
72417 +
72418 retval = 0;
72419 pte_unmap_unlock(pte, ptl);
72420 return retval;
72421 @@ -2106,9 +2105,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72422 if (!page_count(page))
72423 return -EINVAL;
72424 if (!(vma->vm_flags & VM_MIXEDMAP)) {
72425 +
72426 +#ifdef CONFIG_PAX_SEGMEXEC
72427 + struct vm_area_struct *vma_m;
72428 +#endif
72429 +
72430 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
72431 BUG_ON(vma->vm_flags & VM_PFNMAP);
72432 vma->vm_flags |= VM_MIXEDMAP;
72433 +
72434 +#ifdef CONFIG_PAX_SEGMEXEC
72435 + vma_m = pax_find_mirror_vma(vma);
72436 + if (vma_m)
72437 + vma_m->vm_flags |= VM_MIXEDMAP;
72438 +#endif
72439 +
72440 }
72441 return insert_page(vma, addr, page, vma->vm_page_prot);
72442 }
72443 @@ -2191,6 +2202,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72444 unsigned long pfn)
72445 {
72446 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72447 + BUG_ON(vma->vm_mirror);
72448
72449 if (addr < vma->vm_start || addr >= vma->vm_end)
72450 return -EFAULT;
72451 @@ -2391,7 +2403,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72452
72453 BUG_ON(pud_huge(*pud));
72454
72455 - pmd = pmd_alloc(mm, pud, addr);
72456 + pmd = (mm == &init_mm) ?
72457 + pmd_alloc_kernel(mm, pud, addr) :
72458 + pmd_alloc(mm, pud, addr);
72459 if (!pmd)
72460 return -ENOMEM;
72461 do {
72462 @@ -2411,7 +2425,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72463 unsigned long next;
72464 int err;
72465
72466 - pud = pud_alloc(mm, pgd, addr);
72467 + pud = (mm == &init_mm) ?
72468 + pud_alloc_kernel(mm, pgd, addr) :
72469 + pud_alloc(mm, pgd, addr);
72470 if (!pud)
72471 return -ENOMEM;
72472 do {
72473 @@ -2499,6 +2515,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72474 copy_user_highpage(dst, src, va, vma);
72475 }
72476
72477 +#ifdef CONFIG_PAX_SEGMEXEC
72478 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72479 +{
72480 + struct mm_struct *mm = vma->vm_mm;
72481 + spinlock_t *ptl;
72482 + pte_t *pte, entry;
72483 +
72484 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72485 + entry = *pte;
72486 + if (!pte_present(entry)) {
72487 + if (!pte_none(entry)) {
72488 + BUG_ON(pte_file(entry));
72489 + free_swap_and_cache(pte_to_swp_entry(entry));
72490 + pte_clear_not_present_full(mm, address, pte, 0);
72491 + }
72492 + } else {
72493 + struct page *page;
72494 +
72495 + flush_cache_page(vma, address, pte_pfn(entry));
72496 + entry = ptep_clear_flush(vma, address, pte);
72497 + BUG_ON(pte_dirty(entry));
72498 + page = vm_normal_page(vma, address, entry);
72499 + if (page) {
72500 + update_hiwater_rss(mm);
72501 + if (PageAnon(page))
72502 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72503 + else
72504 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72505 + page_remove_rmap(page);
72506 + page_cache_release(page);
72507 + }
72508 + }
72509 + pte_unmap_unlock(pte, ptl);
72510 +}
72511 +
72512 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72513 + *
72514 + * the ptl of the lower mapped page is held on entry and is not released on exit
72515 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72516 + */
72517 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72518 +{
72519 + struct mm_struct *mm = vma->vm_mm;
72520 + unsigned long address_m;
72521 + spinlock_t *ptl_m;
72522 + struct vm_area_struct *vma_m;
72523 + pmd_t *pmd_m;
72524 + pte_t *pte_m, entry_m;
72525 +
72526 + BUG_ON(!page_m || !PageAnon(page_m));
72527 +
72528 + vma_m = pax_find_mirror_vma(vma);
72529 + if (!vma_m)
72530 + return;
72531 +
72532 + BUG_ON(!PageLocked(page_m));
72533 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72534 + address_m = address + SEGMEXEC_TASK_SIZE;
72535 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72536 + pte_m = pte_offset_map(pmd_m, address_m);
72537 + ptl_m = pte_lockptr(mm, pmd_m);
72538 + if (ptl != ptl_m) {
72539 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72540 + if (!pte_none(*pte_m))
72541 + goto out;
72542 + }
72543 +
72544 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72545 + page_cache_get(page_m);
72546 + page_add_anon_rmap(page_m, vma_m, address_m);
72547 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72548 + set_pte_at(mm, address_m, pte_m, entry_m);
72549 + update_mmu_cache(vma_m, address_m, entry_m);
72550 +out:
72551 + if (ptl != ptl_m)
72552 + spin_unlock(ptl_m);
72553 + pte_unmap(pte_m);
72554 + unlock_page(page_m);
72555 +}
72556 +
72557 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72558 +{
72559 + struct mm_struct *mm = vma->vm_mm;
72560 + unsigned long address_m;
72561 + spinlock_t *ptl_m;
72562 + struct vm_area_struct *vma_m;
72563 + pmd_t *pmd_m;
72564 + pte_t *pte_m, entry_m;
72565 +
72566 + BUG_ON(!page_m || PageAnon(page_m));
72567 +
72568 + vma_m = pax_find_mirror_vma(vma);
72569 + if (!vma_m)
72570 + return;
72571 +
72572 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72573 + address_m = address + SEGMEXEC_TASK_SIZE;
72574 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72575 + pte_m = pte_offset_map(pmd_m, address_m);
72576 + ptl_m = pte_lockptr(mm, pmd_m);
72577 + if (ptl != ptl_m) {
72578 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72579 + if (!pte_none(*pte_m))
72580 + goto out;
72581 + }
72582 +
72583 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72584 + page_cache_get(page_m);
72585 + page_add_file_rmap(page_m);
72586 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72587 + set_pte_at(mm, address_m, pte_m, entry_m);
72588 + update_mmu_cache(vma_m, address_m, entry_m);
72589 +out:
72590 + if (ptl != ptl_m)
72591 + spin_unlock(ptl_m);
72592 + pte_unmap(pte_m);
72593 +}
72594 +
72595 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72596 +{
72597 + struct mm_struct *mm = vma->vm_mm;
72598 + unsigned long address_m;
72599 + spinlock_t *ptl_m;
72600 + struct vm_area_struct *vma_m;
72601 + pmd_t *pmd_m;
72602 + pte_t *pte_m, entry_m;
72603 +
72604 + vma_m = pax_find_mirror_vma(vma);
72605 + if (!vma_m)
72606 + return;
72607 +
72608 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72609 + address_m = address + SEGMEXEC_TASK_SIZE;
72610 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72611 + pte_m = pte_offset_map(pmd_m, address_m);
72612 + ptl_m = pte_lockptr(mm, pmd_m);
72613 + if (ptl != ptl_m) {
72614 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72615 + if (!pte_none(*pte_m))
72616 + goto out;
72617 + }
72618 +
72619 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72620 + set_pte_at(mm, address_m, pte_m, entry_m);
72621 +out:
72622 + if (ptl != ptl_m)
72623 + spin_unlock(ptl_m);
72624 + pte_unmap(pte_m);
72625 +}
72626 +
72627 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72628 +{
72629 + struct page *page_m;
72630 + pte_t entry;
72631 +
72632 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72633 + goto out;
72634 +
72635 + entry = *pte;
72636 + page_m = vm_normal_page(vma, address, entry);
72637 + if (!page_m)
72638 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72639 + else if (PageAnon(page_m)) {
72640 + if (pax_find_mirror_vma(vma)) {
72641 + pte_unmap_unlock(pte, ptl);
72642 + lock_page(page_m);
72643 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72644 + if (pte_same(entry, *pte))
72645 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72646 + else
72647 + unlock_page(page_m);
72648 + }
72649 + } else
72650 + pax_mirror_file_pte(vma, address, page_m, ptl);
72651 +
72652 +out:
72653 + pte_unmap_unlock(pte, ptl);
72654 +}
72655 +#endif
72656 +
72657 /*
72658 * This routine handles present pages, when users try to write
72659 * to a shared page. It is done by copying the page to a new address
72660 @@ -2715,6 +2911,12 @@ gotten:
72661 */
72662 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72663 if (likely(pte_same(*page_table, orig_pte))) {
72664 +
72665 +#ifdef CONFIG_PAX_SEGMEXEC
72666 + if (pax_find_mirror_vma(vma))
72667 + BUG_ON(!trylock_page(new_page));
72668 +#endif
72669 +
72670 if (old_page) {
72671 if (!PageAnon(old_page)) {
72672 dec_mm_counter_fast(mm, MM_FILEPAGES);
72673 @@ -2766,6 +2968,10 @@ gotten:
72674 page_remove_rmap(old_page);
72675 }
72676
72677 +#ifdef CONFIG_PAX_SEGMEXEC
72678 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72679 +#endif
72680 +
72681 /* Free the old page.. */
72682 new_page = old_page;
72683 ret |= VM_FAULT_WRITE;
72684 @@ -3046,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72685 swap_free(entry);
72686 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72687 try_to_free_swap(page);
72688 +
72689 +#ifdef CONFIG_PAX_SEGMEXEC
72690 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72691 +#endif
72692 +
72693 unlock_page(page);
72694 if (swapcache) {
72695 /*
72696 @@ -3069,6 +3280,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72697
72698 /* No need to invalidate - it was non-present before */
72699 update_mmu_cache(vma, address, page_table);
72700 +
72701 +#ifdef CONFIG_PAX_SEGMEXEC
72702 + pax_mirror_anon_pte(vma, address, page, ptl);
72703 +#endif
72704 +
72705 unlock:
72706 pte_unmap_unlock(page_table, ptl);
72707 out:
72708 @@ -3088,40 +3304,6 @@ out_release:
72709 }
72710
72711 /*
72712 - * This is like a special single-page "expand_{down|up}wards()",
72713 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72714 - * doesn't hit another vma.
72715 - */
72716 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72717 -{
72718 - address &= PAGE_MASK;
72719 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72720 - struct vm_area_struct *prev = vma->vm_prev;
72721 -
72722 - /*
72723 - * Is there a mapping abutting this one below?
72724 - *
72725 - * That's only ok if it's the same stack mapping
72726 - * that has gotten split..
72727 - */
72728 - if (prev && prev->vm_end == address)
72729 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72730 -
72731 - expand_downwards(vma, address - PAGE_SIZE);
72732 - }
72733 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72734 - struct vm_area_struct *next = vma->vm_next;
72735 -
72736 - /* As VM_GROWSDOWN but s/below/above/ */
72737 - if (next && next->vm_start == address + PAGE_SIZE)
72738 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72739 -
72740 - expand_upwards(vma, address + PAGE_SIZE);
72741 - }
72742 - return 0;
72743 -}
72744 -
72745 -/*
72746 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72747 * but allow concurrent faults), and pte mapped but not yet locked.
72748 * We return with mmap_sem still held, but pte unmapped and unlocked.
72749 @@ -3130,27 +3312,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72750 unsigned long address, pte_t *page_table, pmd_t *pmd,
72751 unsigned int flags)
72752 {
72753 - struct page *page;
72754 + struct page *page = NULL;
72755 spinlock_t *ptl;
72756 pte_t entry;
72757
72758 - pte_unmap(page_table);
72759 -
72760 - /* Check if we need to add a guard page to the stack */
72761 - if (check_stack_guard_page(vma, address) < 0)
72762 - return VM_FAULT_SIGBUS;
72763 -
72764 - /* Use the zero-page for reads */
72765 if (!(flags & FAULT_FLAG_WRITE)) {
72766 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72767 vma->vm_page_prot));
72768 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72769 + ptl = pte_lockptr(mm, pmd);
72770 + spin_lock(ptl);
72771 if (!pte_none(*page_table))
72772 goto unlock;
72773 goto setpte;
72774 }
72775
72776 /* Allocate our own private page. */
72777 + pte_unmap(page_table);
72778 +
72779 if (unlikely(anon_vma_prepare(vma)))
72780 goto oom;
72781 page = alloc_zeroed_user_highpage_movable(vma, address);
72782 @@ -3169,6 +3347,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72783 if (!pte_none(*page_table))
72784 goto release;
72785
72786 +#ifdef CONFIG_PAX_SEGMEXEC
72787 + if (pax_find_mirror_vma(vma))
72788 + BUG_ON(!trylock_page(page));
72789 +#endif
72790 +
72791 inc_mm_counter_fast(mm, MM_ANONPAGES);
72792 page_add_new_anon_rmap(page, vma, address);
72793 setpte:
72794 @@ -3176,6 +3359,12 @@ setpte:
72795
72796 /* No need to invalidate - it was non-present before */
72797 update_mmu_cache(vma, address, page_table);
72798 +
72799 +#ifdef CONFIG_PAX_SEGMEXEC
72800 + if (page)
72801 + pax_mirror_anon_pte(vma, address, page, ptl);
72802 +#endif
72803 +
72804 unlock:
72805 pte_unmap_unlock(page_table, ptl);
72806 return 0;
72807 @@ -3319,6 +3508,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72808 */
72809 /* Only go through if we didn't race with anybody else... */
72810 if (likely(pte_same(*page_table, orig_pte))) {
72811 +
72812 +#ifdef CONFIG_PAX_SEGMEXEC
72813 + if (anon && pax_find_mirror_vma(vma))
72814 + BUG_ON(!trylock_page(page));
72815 +#endif
72816 +
72817 flush_icache_page(vma, page);
72818 entry = mk_pte(page, vma->vm_page_prot);
72819 if (flags & FAULT_FLAG_WRITE)
72820 @@ -3338,6 +3533,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72821
72822 /* no need to invalidate: a not-present page won't be cached */
72823 update_mmu_cache(vma, address, page_table);
72824 +
72825 +#ifdef CONFIG_PAX_SEGMEXEC
72826 + if (anon)
72827 + pax_mirror_anon_pte(vma, address, page, ptl);
72828 + else
72829 + pax_mirror_file_pte(vma, address, page, ptl);
72830 +#endif
72831 +
72832 } else {
72833 if (cow_page)
72834 mem_cgroup_uncharge_page(cow_page);
72835 @@ -3492,6 +3695,12 @@ int handle_pte_fault(struct mm_struct *mm,
72836 if (flags & FAULT_FLAG_WRITE)
72837 flush_tlb_fix_spurious_fault(vma, address);
72838 }
72839 +
72840 +#ifdef CONFIG_PAX_SEGMEXEC
72841 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72842 + return 0;
72843 +#endif
72844 +
72845 unlock:
72846 pte_unmap_unlock(pte, ptl);
72847 return 0;
72848 @@ -3508,6 +3717,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72849 pmd_t *pmd;
72850 pte_t *pte;
72851
72852 +#ifdef CONFIG_PAX_SEGMEXEC
72853 + struct vm_area_struct *vma_m;
72854 +#endif
72855 +
72856 __set_current_state(TASK_RUNNING);
72857
72858 count_vm_event(PGFAULT);
72859 @@ -3519,6 +3732,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72860 if (unlikely(is_vm_hugetlb_page(vma)))
72861 return hugetlb_fault(mm, vma, address, flags);
72862
72863 +#ifdef CONFIG_PAX_SEGMEXEC
72864 + vma_m = pax_find_mirror_vma(vma);
72865 + if (vma_m) {
72866 + unsigned long address_m;
72867 + pgd_t *pgd_m;
72868 + pud_t *pud_m;
72869 + pmd_t *pmd_m;
72870 +
72871 + if (vma->vm_start > vma_m->vm_start) {
72872 + address_m = address;
72873 + address -= SEGMEXEC_TASK_SIZE;
72874 + vma = vma_m;
72875 + } else
72876 + address_m = address + SEGMEXEC_TASK_SIZE;
72877 +
72878 + pgd_m = pgd_offset(mm, address_m);
72879 + pud_m = pud_alloc(mm, pgd_m, address_m);
72880 + if (!pud_m)
72881 + return VM_FAULT_OOM;
72882 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72883 + if (!pmd_m)
72884 + return VM_FAULT_OOM;
72885 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72886 + return VM_FAULT_OOM;
72887 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72888 + }
72889 +#endif
72890 +
72891 retry:
72892 pgd = pgd_offset(mm, address);
72893 pud = pud_alloc(mm, pgd, address);
72894 @@ -3560,7 +3801,7 @@ retry:
72895 * run pte_offset_map on the pmd, if an huge pmd could
72896 * materialize from under us from a different thread.
72897 */
72898 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72899 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72900 return VM_FAULT_OOM;
72901 /* if an huge pmd materialized from under us just retry later */
72902 if (unlikely(pmd_trans_huge(*pmd)))
72903 @@ -3597,6 +3838,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72904 spin_unlock(&mm->page_table_lock);
72905 return 0;
72906 }
72907 +
72908 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72909 +{
72910 + pud_t *new = pud_alloc_one(mm, address);
72911 + if (!new)
72912 + return -ENOMEM;
72913 +
72914 + smp_wmb(); /* See comment in __pte_alloc */
72915 +
72916 + spin_lock(&mm->page_table_lock);
72917 + if (pgd_present(*pgd)) /* Another has populated it */
72918 + pud_free(mm, new);
72919 + else
72920 + pgd_populate_kernel(mm, pgd, new);
72921 + spin_unlock(&mm->page_table_lock);
72922 + return 0;
72923 +}
72924 #endif /* __PAGETABLE_PUD_FOLDED */
72925
72926 #ifndef __PAGETABLE_PMD_FOLDED
72927 @@ -3627,6 +3885,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72928 spin_unlock(&mm->page_table_lock);
72929 return 0;
72930 }
72931 +
72932 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72933 +{
72934 + pmd_t *new = pmd_alloc_one(mm, address);
72935 + if (!new)
72936 + return -ENOMEM;
72937 +
72938 + smp_wmb(); /* See comment in __pte_alloc */
72939 +
72940 + spin_lock(&mm->page_table_lock);
72941 +#ifndef __ARCH_HAS_4LEVEL_HACK
72942 + if (pud_present(*pud)) /* Another has populated it */
72943 + pmd_free(mm, new);
72944 + else
72945 + pud_populate_kernel(mm, pud, new);
72946 +#else
72947 + if (pgd_present(*pud)) /* Another has populated it */
72948 + pmd_free(mm, new);
72949 + else
72950 + pgd_populate_kernel(mm, pud, new);
72951 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72952 + spin_unlock(&mm->page_table_lock);
72953 + return 0;
72954 +}
72955 #endif /* __PAGETABLE_PMD_FOLDED */
72956
72957 int make_pages_present(unsigned long addr, unsigned long end)
72958 @@ -3664,7 +3946,7 @@ static int __init gate_vma_init(void)
72959 gate_vma.vm_start = FIXADDR_USER_START;
72960 gate_vma.vm_end = FIXADDR_USER_END;
72961 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72962 - gate_vma.vm_page_prot = __P101;
72963 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72964
72965 return 0;
72966 }
72967 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72968 index 4ea600d..1cd61c2 100644
72969 --- a/mm/mempolicy.c
72970 +++ b/mm/mempolicy.c
72971 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72972 unsigned long vmstart;
72973 unsigned long vmend;
72974
72975 +#ifdef CONFIG_PAX_SEGMEXEC
72976 + struct vm_area_struct *vma_m;
72977 +#endif
72978 +
72979 vma = find_vma(mm, start);
72980 if (!vma || vma->vm_start > start)
72981 return -EFAULT;
72982 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72983 if (err)
72984 goto out;
72985 }
72986 +
72987 err = vma_replace_policy(vma, new_pol);
72988 if (err)
72989 goto out;
72990 +
72991 +#ifdef CONFIG_PAX_SEGMEXEC
72992 + vma_m = pax_find_mirror_vma(vma);
72993 + if (vma_m) {
72994 + err = vma_replace_policy(vma_m, new_pol);
72995 + if (err)
72996 + goto out;
72997 + }
72998 +#endif
72999 +
73000 }
73001
73002 out:
73003 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73004
73005 if (end < start)
73006 return -EINVAL;
73007 +
73008 +#ifdef CONFIG_PAX_SEGMEXEC
73009 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73010 + if (end > SEGMEXEC_TASK_SIZE)
73011 + return -EINVAL;
73012 + } else
73013 +#endif
73014 +
73015 + if (end > TASK_SIZE)
73016 + return -EINVAL;
73017 +
73018 if (end == start)
73019 return 0;
73020
73021 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73022 */
73023 tcred = __task_cred(task);
73024 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73025 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73026 - !capable(CAP_SYS_NICE)) {
73027 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73028 rcu_read_unlock();
73029 err = -EPERM;
73030 goto out_put;
73031 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73032 goto out;
73033 }
73034
73035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73036 + if (mm != current->mm &&
73037 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73038 + mmput(mm);
73039 + err = -EPERM;
73040 + goto out;
73041 + }
73042 +#endif
73043 +
73044 err = do_migrate_pages(mm, old, new,
73045 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73046
73047 diff --git a/mm/migrate.c b/mm/migrate.c
73048 index 77ed2d7..317d528 100644
73049 --- a/mm/migrate.c
73050 +++ b/mm/migrate.c
73051 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73052 */
73053 tcred = __task_cred(task);
73054 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73055 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73056 - !capable(CAP_SYS_NICE)) {
73057 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73058 rcu_read_unlock();
73059 err = -EPERM;
73060 goto out;
73061 diff --git a/mm/mlock.c b/mm/mlock.c
73062 index f0b9ce5..da8d069 100644
73063 --- a/mm/mlock.c
73064 +++ b/mm/mlock.c
73065 @@ -13,6 +13,7 @@
73066 #include <linux/pagemap.h>
73067 #include <linux/mempolicy.h>
73068 #include <linux/syscalls.h>
73069 +#include <linux/security.h>
73070 #include <linux/sched.h>
73071 #include <linux/export.h>
73072 #include <linux/rmap.h>
73073 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73074 {
73075 unsigned long nstart, end, tmp;
73076 struct vm_area_struct * vma, * prev;
73077 - int error;
73078 + int error = 0;
73079
73080 VM_BUG_ON(start & ~PAGE_MASK);
73081 VM_BUG_ON(len != PAGE_ALIGN(len));
73082 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73083 return -EINVAL;
73084 if (end == start)
73085 return 0;
73086 + if (end > TASK_SIZE)
73087 + return -EINVAL;
73088 +
73089 vma = find_vma(current->mm, start);
73090 if (!vma || vma->vm_start > start)
73091 return -ENOMEM;
73092 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73093 for (nstart = start ; ; ) {
73094 vm_flags_t newflags;
73095
73096 +#ifdef CONFIG_PAX_SEGMEXEC
73097 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73098 + break;
73099 +#endif
73100 +
73101 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73102
73103 newflags = vma->vm_flags | VM_LOCKED;
73104 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73105 lock_limit >>= PAGE_SHIFT;
73106
73107 /* check against resource limits */
73108 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73109 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73110 error = do_mlock(start, len, 1);
73111 up_write(&current->mm->mmap_sem);
73112 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73113 static int do_mlockall(int flags)
73114 {
73115 struct vm_area_struct * vma, * prev = NULL;
73116 - unsigned int def_flags = 0;
73117
73118 if (flags & MCL_FUTURE)
73119 - def_flags = VM_LOCKED;
73120 - current->mm->def_flags = def_flags;
73121 + current->mm->def_flags |= VM_LOCKED;
73122 + else
73123 + current->mm->def_flags &= ~VM_LOCKED;
73124 if (flags == MCL_FUTURE)
73125 goto out;
73126
73127 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73128 vm_flags_t newflags;
73129
73130 +#ifdef CONFIG_PAX_SEGMEXEC
73131 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73132 + break;
73133 +#endif
73134 +
73135 + BUG_ON(vma->vm_end > TASK_SIZE);
73136 newflags = vma->vm_flags | VM_LOCKED;
73137 if (!(flags & MCL_CURRENT))
73138 newflags &= ~VM_LOCKED;
73139 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73140 lock_limit >>= PAGE_SHIFT;
73141
73142 ret = -ENOMEM;
73143 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73144 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73145 capable(CAP_IPC_LOCK))
73146 ret = do_mlockall(flags);
73147 diff --git a/mm/mmap.c b/mm/mmap.c
73148 index 9a796c4..4fba820 100644
73149 --- a/mm/mmap.c
73150 +++ b/mm/mmap.c
73151 @@ -47,6 +47,16 @@
73152 #define arch_rebalance_pgtables(addr, len) (addr)
73153 #endif
73154
73155 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73156 +{
73157 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73158 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73159 + up_read(&mm->mmap_sem);
73160 + BUG();
73161 + }
73162 +#endif
73163 +}
73164 +
73165 static void unmap_region(struct mm_struct *mm,
73166 struct vm_area_struct *vma, struct vm_area_struct *prev,
73167 unsigned long start, unsigned long end);
73168 @@ -66,22 +76,32 @@ static void unmap_region(struct mm_struct *mm,
73169 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73170 *
73171 */
73172 -pgprot_t protection_map[16] = {
73173 +pgprot_t protection_map[16] __read_only = {
73174 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73175 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73176 };
73177
73178 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73179 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73180 {
73181 - return __pgprot(pgprot_val(protection_map[vm_flags &
73182 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73183 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73184 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73185 +
73186 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73187 + if (!(__supported_pte_mask & _PAGE_NX) &&
73188 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73189 + (vm_flags & (VM_READ | VM_WRITE)))
73190 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73191 +#endif
73192 +
73193 + return prot;
73194 }
73195 EXPORT_SYMBOL(vm_get_page_prot);
73196
73197 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73198 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73199 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73200 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73201 /*
73202 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73203 * other variables. It can be updated by several CPUs frequently.
73204 @@ -223,6 +243,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73205 struct vm_area_struct *next = vma->vm_next;
73206
73207 might_sleep();
73208 + BUG_ON(vma->vm_mirror);
73209 if (vma->vm_ops && vma->vm_ops->close)
73210 vma->vm_ops->close(vma);
73211 if (vma->vm_file)
73212 @@ -266,6 +287,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73213 * not page aligned -Ram Gupta
73214 */
73215 rlim = rlimit(RLIMIT_DATA);
73216 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73217 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73218 (mm->end_data - mm->start_data) > rlim)
73219 goto out;
73220 @@ -736,6 +758,12 @@ static int
73221 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73222 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73223 {
73224 +
73225 +#ifdef CONFIG_PAX_SEGMEXEC
73226 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73227 + return 0;
73228 +#endif
73229 +
73230 if (is_mergeable_vma(vma, file, vm_flags) &&
73231 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73232 if (vma->vm_pgoff == vm_pgoff)
73233 @@ -755,6 +783,12 @@ static int
73234 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73235 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73236 {
73237 +
73238 +#ifdef CONFIG_PAX_SEGMEXEC
73239 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73240 + return 0;
73241 +#endif
73242 +
73243 if (is_mergeable_vma(vma, file, vm_flags) &&
73244 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73245 pgoff_t vm_pglen;
73246 @@ -797,13 +831,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73247 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73248 struct vm_area_struct *prev, unsigned long addr,
73249 unsigned long end, unsigned long vm_flags,
73250 - struct anon_vma *anon_vma, struct file *file,
73251 + struct anon_vma *anon_vma, struct file *file,
73252 pgoff_t pgoff, struct mempolicy *policy)
73253 {
73254 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73255 struct vm_area_struct *area, *next;
73256 int err;
73257
73258 +#ifdef CONFIG_PAX_SEGMEXEC
73259 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73260 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73261 +
73262 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73263 +#endif
73264 +
73265 /*
73266 * We later require that vma->vm_flags == vm_flags,
73267 * so this tests vma->vm_flags & VM_SPECIAL, too.
73268 @@ -819,6 +860,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73269 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73270 next = next->vm_next;
73271
73272 +#ifdef CONFIG_PAX_SEGMEXEC
73273 + if (prev)
73274 + prev_m = pax_find_mirror_vma(prev);
73275 + if (area)
73276 + area_m = pax_find_mirror_vma(area);
73277 + if (next)
73278 + next_m = pax_find_mirror_vma(next);
73279 +#endif
73280 +
73281 /*
73282 * Can it merge with the predecessor?
73283 */
73284 @@ -838,9 +888,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73285 /* cases 1, 6 */
73286 err = vma_adjust(prev, prev->vm_start,
73287 next->vm_end, prev->vm_pgoff, NULL);
73288 - } else /* cases 2, 5, 7 */
73289 +
73290 +#ifdef CONFIG_PAX_SEGMEXEC
73291 + if (!err && prev_m)
73292 + err = vma_adjust(prev_m, prev_m->vm_start,
73293 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73294 +#endif
73295 +
73296 + } else { /* cases 2, 5, 7 */
73297 err = vma_adjust(prev, prev->vm_start,
73298 end, prev->vm_pgoff, NULL);
73299 +
73300 +#ifdef CONFIG_PAX_SEGMEXEC
73301 + if (!err && prev_m)
73302 + err = vma_adjust(prev_m, prev_m->vm_start,
73303 + end_m, prev_m->vm_pgoff, NULL);
73304 +#endif
73305 +
73306 + }
73307 if (err)
73308 return NULL;
73309 khugepaged_enter_vma_merge(prev);
73310 @@ -854,12 +919,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73311 mpol_equal(policy, vma_policy(next)) &&
73312 can_vma_merge_before(next, vm_flags,
73313 anon_vma, file, pgoff+pglen)) {
73314 - if (prev && addr < prev->vm_end) /* case 4 */
73315 + if (prev && addr < prev->vm_end) { /* case 4 */
73316 err = vma_adjust(prev, prev->vm_start,
73317 addr, prev->vm_pgoff, NULL);
73318 - else /* cases 3, 8 */
73319 +
73320 +#ifdef CONFIG_PAX_SEGMEXEC
73321 + if (!err && prev_m)
73322 + err = vma_adjust(prev_m, prev_m->vm_start,
73323 + addr_m, prev_m->vm_pgoff, NULL);
73324 +#endif
73325 +
73326 + } else { /* cases 3, 8 */
73327 err = vma_adjust(area, addr, next->vm_end,
73328 next->vm_pgoff - pglen, NULL);
73329 +
73330 +#ifdef CONFIG_PAX_SEGMEXEC
73331 + if (!err && area_m)
73332 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73333 + next_m->vm_pgoff - pglen, NULL);
73334 +#endif
73335 +
73336 + }
73337 if (err)
73338 return NULL;
73339 khugepaged_enter_vma_merge(area);
73340 @@ -968,16 +1048,13 @@ none:
73341 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73342 struct file *file, long pages)
73343 {
73344 - const unsigned long stack_flags
73345 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73346 -
73347 mm->total_vm += pages;
73348
73349 if (file) {
73350 mm->shared_vm += pages;
73351 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73352 mm->exec_vm += pages;
73353 - } else if (flags & stack_flags)
73354 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73355 mm->stack_vm += pages;
73356 }
73357 #endif /* CONFIG_PROC_FS */
73358 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73359 * (the exception is when the underlying filesystem is noexec
73360 * mounted, in which case we dont add PROT_EXEC.)
73361 */
73362 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73363 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73364 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73365 prot |= PROT_EXEC;
73366
73367 @@ -1039,7 +1116,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73368 /* Obtain the address to map to. we verify (or select) it and ensure
73369 * that it represents a valid section of the address space.
73370 */
73371 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73372 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73373 if (addr & ~PAGE_MASK)
73374 return addr;
73375
73376 @@ -1050,6 +1127,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73377 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73378 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73379
73380 +#ifdef CONFIG_PAX_MPROTECT
73381 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73382 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73383 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73384 + gr_log_rwxmmap(file);
73385 +
73386 +#ifdef CONFIG_PAX_EMUPLT
73387 + vm_flags &= ~VM_EXEC;
73388 +#else
73389 + return -EPERM;
73390 +#endif
73391 +
73392 + }
73393 +
73394 + if (!(vm_flags & VM_EXEC))
73395 + vm_flags &= ~VM_MAYEXEC;
73396 +#else
73397 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73398 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73399 +#endif
73400 + else
73401 + vm_flags &= ~VM_MAYWRITE;
73402 + }
73403 +#endif
73404 +
73405 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73406 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73407 + vm_flags &= ~VM_PAGEEXEC;
73408 +#endif
73409 +
73410 if (flags & MAP_LOCKED)
73411 if (!can_do_mlock())
73412 return -EPERM;
73413 @@ -1061,6 +1168,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73414 locked += mm->locked_vm;
73415 lock_limit = rlimit(RLIMIT_MEMLOCK);
73416 lock_limit >>= PAGE_SHIFT;
73417 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73418 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73419 return -EAGAIN;
73420 }
73421 @@ -1127,6 +1235,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73422 }
73423 }
73424
73425 + if (!gr_acl_handle_mmap(file, prot))
73426 + return -EACCES;
73427 +
73428 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73429 }
73430
73431 @@ -1203,7 +1314,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73432 vm_flags_t vm_flags = vma->vm_flags;
73433
73434 /* If it was private or non-writable, the write bit is already clear */
73435 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73436 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73437 return 0;
73438
73439 /* The backer wishes to know when pages are first written to? */
73440 @@ -1252,13 +1363,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73441 unsigned long charged = 0;
73442 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73443
73444 +#ifdef CONFIG_PAX_SEGMEXEC
73445 + struct vm_area_struct *vma_m = NULL;
73446 +#endif
73447 +
73448 + /*
73449 + * mm->mmap_sem is required to protect against another thread
73450 + * changing the mappings in case we sleep.
73451 + */
73452 + verify_mm_writelocked(mm);
73453 +
73454 /* Clear old maps */
73455 error = -ENOMEM;
73456 -munmap_back:
73457 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
73458 if (do_munmap(mm, addr, len))
73459 return -ENOMEM;
73460 - goto munmap_back;
73461 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
73462 }
73463
73464 /* Check against address space limit. */
73465 @@ -1307,6 +1427,16 @@ munmap_back:
73466 goto unacct_error;
73467 }
73468
73469 +#ifdef CONFIG_PAX_SEGMEXEC
73470 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73471 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73472 + if (!vma_m) {
73473 + error = -ENOMEM;
73474 + goto free_vma;
73475 + }
73476 + }
73477 +#endif
73478 +
73479 vma->vm_mm = mm;
73480 vma->vm_start = addr;
73481 vma->vm_end = addr + len;
73482 @@ -1331,6 +1461,13 @@ munmap_back:
73483 if (error)
73484 goto unmap_and_free_vma;
73485
73486 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73487 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73488 + vma->vm_flags |= VM_PAGEEXEC;
73489 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73490 + }
73491 +#endif
73492 +
73493 /* Can addr have changed??
73494 *
73495 * Answer: Yes, several device drivers can do it in their
73496 @@ -1365,6 +1502,11 @@ munmap_back:
73497 vma_link(mm, vma, prev, rb_link, rb_parent);
73498 file = vma->vm_file;
73499
73500 +#ifdef CONFIG_PAX_SEGMEXEC
73501 + if (vma_m)
73502 + BUG_ON(pax_mirror_vma(vma_m, vma));
73503 +#endif
73504 +
73505 /* Once vma denies write, undo our temporary denial count */
73506 if (correct_wcount)
73507 atomic_inc(&inode->i_writecount);
73508 @@ -1372,6 +1514,7 @@ out:
73509 perf_event_mmap(vma);
73510
73511 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73512 + track_exec_limit(mm, addr, addr + len, vm_flags);
73513 if (vm_flags & VM_LOCKED) {
73514 if (!mlock_vma_pages_range(vma, addr, addr + len))
73515 mm->locked_vm += (len >> PAGE_SHIFT);
73516 @@ -1393,6 +1536,12 @@ unmap_and_free_vma:
73517 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73518 charged = 0;
73519 free_vma:
73520 +
73521 +#ifdef CONFIG_PAX_SEGMEXEC
73522 + if (vma_m)
73523 + kmem_cache_free(vm_area_cachep, vma_m);
73524 +#endif
73525 +
73526 kmem_cache_free(vm_area_cachep, vma);
73527 unacct_error:
73528 if (charged)
73529 @@ -1400,6 +1549,44 @@ unacct_error:
73530 return error;
73531 }
73532
73533 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73534 +{
73535 + if (!vma) {
73536 +#ifdef CONFIG_STACK_GROWSUP
73537 + if (addr > sysctl_heap_stack_gap)
73538 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73539 + else
73540 + vma = find_vma(current->mm, 0);
73541 + if (vma && (vma->vm_flags & VM_GROWSUP))
73542 + return false;
73543 +#endif
73544 + return true;
73545 + }
73546 +
73547 + if (addr + len > vma->vm_start)
73548 + return false;
73549 +
73550 + if (vma->vm_flags & VM_GROWSDOWN)
73551 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73552 +#ifdef CONFIG_STACK_GROWSUP
73553 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73554 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73555 +#endif
73556 +
73557 + return true;
73558 +}
73559 +
73560 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73561 +{
73562 + if (vma->vm_start < len)
73563 + return -ENOMEM;
73564 + if (!(vma->vm_flags & VM_GROWSDOWN))
73565 + return vma->vm_start - len;
73566 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73567 + return vma->vm_start - len - sysctl_heap_stack_gap;
73568 + return -ENOMEM;
73569 +}
73570 +
73571 /* Get an address range which is currently unmapped.
73572 * For shmat() with addr=0.
73573 *
73574 @@ -1426,18 +1613,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73575 if (flags & MAP_FIXED)
73576 return addr;
73577
73578 +#ifdef CONFIG_PAX_RANDMMAP
73579 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73580 +#endif
73581 +
73582 if (addr) {
73583 addr = PAGE_ALIGN(addr);
73584 - vma = find_vma(mm, addr);
73585 - if (TASK_SIZE - len >= addr &&
73586 - (!vma || addr + len <= vma->vm_start))
73587 - return addr;
73588 + if (TASK_SIZE - len >= addr) {
73589 + vma = find_vma(mm, addr);
73590 + if (check_heap_stack_gap(vma, addr, len))
73591 + return addr;
73592 + }
73593 }
73594 if (len > mm->cached_hole_size) {
73595 - start_addr = addr = mm->free_area_cache;
73596 + start_addr = addr = mm->free_area_cache;
73597 } else {
73598 - start_addr = addr = TASK_UNMAPPED_BASE;
73599 - mm->cached_hole_size = 0;
73600 + start_addr = addr = mm->mmap_base;
73601 + mm->cached_hole_size = 0;
73602 }
73603
73604 full_search:
73605 @@ -1448,34 +1640,40 @@ full_search:
73606 * Start a new search - just in case we missed
73607 * some holes.
73608 */
73609 - if (start_addr != TASK_UNMAPPED_BASE) {
73610 - addr = TASK_UNMAPPED_BASE;
73611 - start_addr = addr;
73612 + if (start_addr != mm->mmap_base) {
73613 + start_addr = addr = mm->mmap_base;
73614 mm->cached_hole_size = 0;
73615 goto full_search;
73616 }
73617 return -ENOMEM;
73618 }
73619 - if (!vma || addr + len <= vma->vm_start) {
73620 - /*
73621 - * Remember the place where we stopped the search:
73622 - */
73623 - mm->free_area_cache = addr + len;
73624 - return addr;
73625 - }
73626 + if (check_heap_stack_gap(vma, addr, len))
73627 + break;
73628 if (addr + mm->cached_hole_size < vma->vm_start)
73629 mm->cached_hole_size = vma->vm_start - addr;
73630 addr = vma->vm_end;
73631 }
73632 +
73633 + /*
73634 + * Remember the place where we stopped the search:
73635 + */
73636 + mm->free_area_cache = addr + len;
73637 + return addr;
73638 }
73639 #endif
73640
73641 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73642 {
73643 +
73644 +#ifdef CONFIG_PAX_SEGMEXEC
73645 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73646 + return;
73647 +#endif
73648 +
73649 /*
73650 * Is this a new hole at the lowest possible address?
73651 */
73652 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73653 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73654 mm->free_area_cache = addr;
73655 }
73656
73657 @@ -1491,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73658 {
73659 struct vm_area_struct *vma;
73660 struct mm_struct *mm = current->mm;
73661 - unsigned long addr = addr0, start_addr;
73662 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73663
73664 /* requested length too big for entire address space */
73665 if (len > TASK_SIZE)
73666 @@ -1500,13 +1698,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73667 if (flags & MAP_FIXED)
73668 return addr;
73669
73670 +#ifdef CONFIG_PAX_RANDMMAP
73671 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73672 +#endif
73673 +
73674 /* requesting a specific address */
73675 if (addr) {
73676 addr = PAGE_ALIGN(addr);
73677 - vma = find_vma(mm, addr);
73678 - if (TASK_SIZE - len >= addr &&
73679 - (!vma || addr + len <= vma->vm_start))
73680 - return addr;
73681 + if (TASK_SIZE - len >= addr) {
73682 + vma = find_vma(mm, addr);
73683 + if (check_heap_stack_gap(vma, addr, len))
73684 + return addr;
73685 + }
73686 }
73687
73688 /* check if free_area_cache is useful for us */
73689 @@ -1530,7 +1733,7 @@ try_again:
73690 * return with success:
73691 */
73692 vma = find_vma(mm, addr);
73693 - if (!vma || addr+len <= vma->vm_start)
73694 + if (check_heap_stack_gap(vma, addr, len))
73695 /* remember the address as a hint for next time */
73696 return (mm->free_area_cache = addr);
73697
73698 @@ -1539,8 +1742,8 @@ try_again:
73699 mm->cached_hole_size = vma->vm_start - addr;
73700
73701 /* try just below the current vma->vm_start */
73702 - addr = vma->vm_start-len;
73703 - } while (len < vma->vm_start);
73704 + addr = skip_heap_stack_gap(vma, len);
73705 + } while (!IS_ERR_VALUE(addr));
73706
73707 fail:
73708 /*
73709 @@ -1563,13 +1766,21 @@ fail:
73710 * can happen with large stack limits and large mmap()
73711 * allocations.
73712 */
73713 + mm->mmap_base = TASK_UNMAPPED_BASE;
73714 +
73715 +#ifdef CONFIG_PAX_RANDMMAP
73716 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73717 + mm->mmap_base += mm->delta_mmap;
73718 +#endif
73719 +
73720 + mm->free_area_cache = mm->mmap_base;
73721 mm->cached_hole_size = ~0UL;
73722 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73723 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73724 /*
73725 * Restore the topdown base:
73726 */
73727 - mm->free_area_cache = mm->mmap_base;
73728 + mm->mmap_base = base;
73729 + mm->free_area_cache = base;
73730 mm->cached_hole_size = ~0UL;
73731
73732 return addr;
73733 @@ -1578,6 +1789,12 @@ fail:
73734
73735 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73736 {
73737 +
73738 +#ifdef CONFIG_PAX_SEGMEXEC
73739 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73740 + return;
73741 +#endif
73742 +
73743 /*
73744 * Is this a new hole at the highest possible address?
73745 */
73746 @@ -1585,8 +1802,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73747 mm->free_area_cache = addr;
73748
73749 /* dont allow allocations above current base */
73750 - if (mm->free_area_cache > mm->mmap_base)
73751 + if (mm->free_area_cache > mm->mmap_base) {
73752 mm->free_area_cache = mm->mmap_base;
73753 + mm->cached_hole_size = ~0UL;
73754 + }
73755 }
73756
73757 unsigned long
73758 @@ -1685,6 +1904,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73759 return vma;
73760 }
73761
73762 +#ifdef CONFIG_PAX_SEGMEXEC
73763 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73764 +{
73765 + struct vm_area_struct *vma_m;
73766 +
73767 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73768 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73769 + BUG_ON(vma->vm_mirror);
73770 + return NULL;
73771 + }
73772 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73773 + vma_m = vma->vm_mirror;
73774 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73775 + BUG_ON(vma->vm_file != vma_m->vm_file);
73776 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73777 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73778 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73779 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
73780 + return vma_m;
73781 +}
73782 +#endif
73783 +
73784 /*
73785 * Verify that the stack growth is acceptable and
73786 * update accounting. This is shared with both the
73787 @@ -1701,6 +1942,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73788 return -ENOMEM;
73789
73790 /* Stack limit test */
73791 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73792 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73793 return -ENOMEM;
73794
73795 @@ -1711,6 +1953,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73796 locked = mm->locked_vm + grow;
73797 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73798 limit >>= PAGE_SHIFT;
73799 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73800 if (locked > limit && !capable(CAP_IPC_LOCK))
73801 return -ENOMEM;
73802 }
73803 @@ -1740,37 +1983,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73804 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73805 * vma is the last one with address > vma->vm_end. Have to extend vma.
73806 */
73807 +#ifndef CONFIG_IA64
73808 +static
73809 +#endif
73810 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73811 {
73812 int error;
73813 + bool locknext;
73814
73815 if (!(vma->vm_flags & VM_GROWSUP))
73816 return -EFAULT;
73817
73818 + /* Also guard against wrapping around to address 0. */
73819 + if (address < PAGE_ALIGN(address+1))
73820 + address = PAGE_ALIGN(address+1);
73821 + else
73822 + return -ENOMEM;
73823 +
73824 /*
73825 * We must make sure the anon_vma is allocated
73826 * so that the anon_vma locking is not a noop.
73827 */
73828 if (unlikely(anon_vma_prepare(vma)))
73829 return -ENOMEM;
73830 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73831 + if (locknext && anon_vma_prepare(vma->vm_next))
73832 + return -ENOMEM;
73833 vma_lock_anon_vma(vma);
73834 + if (locknext)
73835 + vma_lock_anon_vma(vma->vm_next);
73836
73837 /*
73838 * vma->vm_start/vm_end cannot change under us because the caller
73839 * is required to hold the mmap_sem in read mode. We need the
73840 - * anon_vma lock to serialize against concurrent expand_stacks.
73841 - * Also guard against wrapping around to address 0.
73842 + * anon_vma locks to serialize against concurrent expand_stacks
73843 + * and expand_upwards.
73844 */
73845 - if (address < PAGE_ALIGN(address+4))
73846 - address = PAGE_ALIGN(address+4);
73847 - else {
73848 - vma_unlock_anon_vma(vma);
73849 - return -ENOMEM;
73850 - }
73851 error = 0;
73852
73853 /* Somebody else might have raced and expanded it already */
73854 - if (address > vma->vm_end) {
73855 + 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)
73856 + error = -ENOMEM;
73857 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73858 unsigned long size, grow;
73859
73860 size = address - vma->vm_start;
73861 @@ -1787,6 +2041,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73862 }
73863 }
73864 }
73865 + if (locknext)
73866 + vma_unlock_anon_vma(vma->vm_next);
73867 vma_unlock_anon_vma(vma);
73868 khugepaged_enter_vma_merge(vma);
73869 validate_mm(vma->vm_mm);
73870 @@ -1801,6 +2057,8 @@ int expand_downwards(struct vm_area_struct *vma,
73871 unsigned long address)
73872 {
73873 int error;
73874 + bool lockprev = false;
73875 + struct vm_area_struct *prev;
73876
73877 /*
73878 * We must make sure the anon_vma is allocated
73879 @@ -1814,6 +2072,15 @@ int expand_downwards(struct vm_area_struct *vma,
73880 if (error)
73881 return error;
73882
73883 + prev = vma->vm_prev;
73884 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73885 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73886 +#endif
73887 + if (lockprev && anon_vma_prepare(prev))
73888 + return -ENOMEM;
73889 + if (lockprev)
73890 + vma_lock_anon_vma(prev);
73891 +
73892 vma_lock_anon_vma(vma);
73893
73894 /*
73895 @@ -1823,9 +2090,17 @@ int expand_downwards(struct vm_area_struct *vma,
73896 */
73897
73898 /* Somebody else might have raced and expanded it already */
73899 - if (address < vma->vm_start) {
73900 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73901 + error = -ENOMEM;
73902 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73903 unsigned long size, grow;
73904
73905 +#ifdef CONFIG_PAX_SEGMEXEC
73906 + struct vm_area_struct *vma_m;
73907 +
73908 + vma_m = pax_find_mirror_vma(vma);
73909 +#endif
73910 +
73911 size = vma->vm_end - address;
73912 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73913
73914 @@ -1837,6 +2112,17 @@ int expand_downwards(struct vm_area_struct *vma,
73915 vma->vm_start = address;
73916 vma->vm_pgoff -= grow;
73917 anon_vma_interval_tree_post_update_vma(vma);
73918 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73919 +
73920 +#ifdef CONFIG_PAX_SEGMEXEC
73921 + if (vma_m) {
73922 + anon_vma_interval_tree_pre_update_vma(vma_m);
73923 + vma_m->vm_start -= grow << PAGE_SHIFT;
73924 + vma_m->vm_pgoff -= grow;
73925 + anon_vma_interval_tree_post_update_vma(vma_m);
73926 + }
73927 +#endif
73928 +
73929 perf_event_mmap(vma);
73930 }
73931 }
73932 @@ -1914,6 +2200,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73933 do {
73934 long nrpages = vma_pages(vma);
73935
73936 +#ifdef CONFIG_PAX_SEGMEXEC
73937 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73938 + vma = remove_vma(vma);
73939 + continue;
73940 + }
73941 +#endif
73942 +
73943 if (vma->vm_flags & VM_ACCOUNT)
73944 nr_accounted += nrpages;
73945 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73946 @@ -1959,6 +2252,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73947 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73948 vma->vm_prev = NULL;
73949 do {
73950 +
73951 +#ifdef CONFIG_PAX_SEGMEXEC
73952 + if (vma->vm_mirror) {
73953 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73954 + vma->vm_mirror->vm_mirror = NULL;
73955 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73956 + vma->vm_mirror = NULL;
73957 + }
73958 +#endif
73959 +
73960 rb_erase(&vma->vm_rb, &mm->mm_rb);
73961 mm->map_count--;
73962 tail_vma = vma;
73963 @@ -1987,14 +2290,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73964 struct vm_area_struct *new;
73965 int err = -ENOMEM;
73966
73967 +#ifdef CONFIG_PAX_SEGMEXEC
73968 + struct vm_area_struct *vma_m, *new_m = NULL;
73969 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73970 +#endif
73971 +
73972 if (is_vm_hugetlb_page(vma) && (addr &
73973 ~(huge_page_mask(hstate_vma(vma)))))
73974 return -EINVAL;
73975
73976 +#ifdef CONFIG_PAX_SEGMEXEC
73977 + vma_m = pax_find_mirror_vma(vma);
73978 +#endif
73979 +
73980 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73981 if (!new)
73982 goto out_err;
73983
73984 +#ifdef CONFIG_PAX_SEGMEXEC
73985 + if (vma_m) {
73986 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73987 + if (!new_m) {
73988 + kmem_cache_free(vm_area_cachep, new);
73989 + goto out_err;
73990 + }
73991 + }
73992 +#endif
73993 +
73994 /* most fields are the same, copy all, and then fixup */
73995 *new = *vma;
73996
73997 @@ -2007,6 +2329,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73998 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73999 }
74000
74001 +#ifdef CONFIG_PAX_SEGMEXEC
74002 + if (vma_m) {
74003 + *new_m = *vma_m;
74004 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
74005 + new_m->vm_mirror = new;
74006 + new->vm_mirror = new_m;
74007 +
74008 + if (new_below)
74009 + new_m->vm_end = addr_m;
74010 + else {
74011 + new_m->vm_start = addr_m;
74012 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74013 + }
74014 + }
74015 +#endif
74016 +
74017 pol = mpol_dup(vma_policy(vma));
74018 if (IS_ERR(pol)) {
74019 err = PTR_ERR(pol);
74020 @@ -2029,6 +2367,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74021 else
74022 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74023
74024 +#ifdef CONFIG_PAX_SEGMEXEC
74025 + if (!err && vma_m) {
74026 + if (anon_vma_clone(new_m, vma_m))
74027 + goto out_free_mpol;
74028 +
74029 + mpol_get(pol);
74030 + vma_set_policy(new_m, pol);
74031 +
74032 + if (new_m->vm_file)
74033 + get_file(new_m->vm_file);
74034 +
74035 + if (new_m->vm_ops && new_m->vm_ops->open)
74036 + new_m->vm_ops->open(new_m);
74037 +
74038 + if (new_below)
74039 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74040 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74041 + else
74042 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74043 +
74044 + if (err) {
74045 + if (new_m->vm_ops && new_m->vm_ops->close)
74046 + new_m->vm_ops->close(new_m);
74047 + if (new_m->vm_file)
74048 + fput(new_m->vm_file);
74049 + mpol_put(pol);
74050 + }
74051 + }
74052 +#endif
74053 +
74054 /* Success. */
74055 if (!err)
74056 return 0;
74057 @@ -2038,10 +2406,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74058 new->vm_ops->close(new);
74059 if (new->vm_file)
74060 fput(new->vm_file);
74061 - unlink_anon_vmas(new);
74062 out_free_mpol:
74063 mpol_put(pol);
74064 out_free_vma:
74065 +
74066 +#ifdef CONFIG_PAX_SEGMEXEC
74067 + if (new_m) {
74068 + unlink_anon_vmas(new_m);
74069 + kmem_cache_free(vm_area_cachep, new_m);
74070 + }
74071 +#endif
74072 +
74073 + unlink_anon_vmas(new);
74074 kmem_cache_free(vm_area_cachep, new);
74075 out_err:
74076 return err;
74077 @@ -2054,6 +2430,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74078 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74079 unsigned long addr, int new_below)
74080 {
74081 +
74082 +#ifdef CONFIG_PAX_SEGMEXEC
74083 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74084 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74085 + if (mm->map_count >= sysctl_max_map_count-1)
74086 + return -ENOMEM;
74087 + } else
74088 +#endif
74089 +
74090 if (mm->map_count >= sysctl_max_map_count)
74091 return -ENOMEM;
74092
74093 @@ -2065,11 +2450,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74094 * work. This now handles partial unmappings.
74095 * Jeremy Fitzhardinge <jeremy@goop.org>
74096 */
74097 +#ifdef CONFIG_PAX_SEGMEXEC
74098 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74099 {
74100 + int ret = __do_munmap(mm, start, len);
74101 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74102 + return ret;
74103 +
74104 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74105 +}
74106 +
74107 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74108 +#else
74109 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74110 +#endif
74111 +{
74112 unsigned long end;
74113 struct vm_area_struct *vma, *prev, *last;
74114
74115 + /*
74116 + * mm->mmap_sem is required to protect against another thread
74117 + * changing the mappings in case we sleep.
74118 + */
74119 + verify_mm_writelocked(mm);
74120 +
74121 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74122 return -EINVAL;
74123
74124 @@ -2144,6 +2548,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74125 /* Fix up all other VM information */
74126 remove_vma_list(mm, vma);
74127
74128 + track_exec_limit(mm, start, end, 0UL);
74129 +
74130 return 0;
74131 }
74132
74133 @@ -2152,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
74134 int ret;
74135 struct mm_struct *mm = current->mm;
74136
74137 +
74138 +#ifdef CONFIG_PAX_SEGMEXEC
74139 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74140 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74141 + return -EINVAL;
74142 +#endif
74143 +
74144 down_write(&mm->mmap_sem);
74145 ret = do_munmap(mm, start, len);
74146 up_write(&mm->mmap_sem);
74147 @@ -2165,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74148 return vm_munmap(addr, len);
74149 }
74150
74151 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74152 -{
74153 -#ifdef CONFIG_DEBUG_VM
74154 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74155 - WARN_ON(1);
74156 - up_read(&mm->mmap_sem);
74157 - }
74158 -#endif
74159 -}
74160 -
74161 /*
74162 * this is really a simplified "do_mmap". it only handles
74163 * anonymous maps. eventually we may be able to do some
74164 @@ -2188,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74165 struct rb_node ** rb_link, * rb_parent;
74166 pgoff_t pgoff = addr >> PAGE_SHIFT;
74167 int error;
74168 + unsigned long charged;
74169
74170 len = PAGE_ALIGN(len);
74171 if (!len)
74172 @@ -2195,16 +2599,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74173
74174 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74175
74176 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74177 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74178 + flags &= ~VM_EXEC;
74179 +
74180 +#ifdef CONFIG_PAX_MPROTECT
74181 + if (mm->pax_flags & MF_PAX_MPROTECT)
74182 + flags &= ~VM_MAYEXEC;
74183 +#endif
74184 +
74185 + }
74186 +#endif
74187 +
74188 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74189 if (error & ~PAGE_MASK)
74190 return error;
74191
74192 + charged = len >> PAGE_SHIFT;
74193 +
74194 /*
74195 * mlock MCL_FUTURE?
74196 */
74197 if (mm->def_flags & VM_LOCKED) {
74198 unsigned long locked, lock_limit;
74199 - locked = len >> PAGE_SHIFT;
74200 + locked = charged;
74201 locked += mm->locked_vm;
74202 lock_limit = rlimit(RLIMIT_MEMLOCK);
74203 lock_limit >>= PAGE_SHIFT;
74204 @@ -2221,21 +2639,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74205 /*
74206 * Clear old maps. this also does some error checking for us
74207 */
74208 - munmap_back:
74209 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
74210 if (do_munmap(mm, addr, len))
74211 return -ENOMEM;
74212 - goto munmap_back;
74213 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
74214 }
74215
74216 /* Check against address space limits *after* clearing old maps... */
74217 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74218 + if (!may_expand_vm(mm, charged))
74219 return -ENOMEM;
74220
74221 if (mm->map_count > sysctl_max_map_count)
74222 return -ENOMEM;
74223
74224 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74225 + if (security_vm_enough_memory_mm(mm, charged))
74226 return -ENOMEM;
74227
74228 /* Can we just expand an old private anonymous mapping? */
74229 @@ -2249,7 +2666,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74230 */
74231 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74232 if (!vma) {
74233 - vm_unacct_memory(len >> PAGE_SHIFT);
74234 + vm_unacct_memory(charged);
74235 return -ENOMEM;
74236 }
74237
74238 @@ -2263,11 +2680,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74239 vma_link(mm, vma, prev, rb_link, rb_parent);
74240 out:
74241 perf_event_mmap(vma);
74242 - mm->total_vm += len >> PAGE_SHIFT;
74243 + mm->total_vm += charged;
74244 if (flags & VM_LOCKED) {
74245 if (!mlock_vma_pages_range(vma, addr, addr + len))
74246 - mm->locked_vm += (len >> PAGE_SHIFT);
74247 + mm->locked_vm += charged;
74248 }
74249 + track_exec_limit(mm, addr, addr + len, flags);
74250 return addr;
74251 }
74252
74253 @@ -2325,6 +2743,7 @@ void exit_mmap(struct mm_struct *mm)
74254 while (vma) {
74255 if (vma->vm_flags & VM_ACCOUNT)
74256 nr_accounted += vma_pages(vma);
74257 + vma->vm_mirror = NULL;
74258 vma = remove_vma(vma);
74259 }
74260 vm_unacct_memory(nr_accounted);
74261 @@ -2341,6 +2760,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
74262 struct vm_area_struct *prev;
74263 struct rb_node **rb_link, *rb_parent;
74264
74265 +#ifdef CONFIG_PAX_SEGMEXEC
74266 + struct vm_area_struct *vma_m = NULL;
74267 +#endif
74268 +
74269 + if (security_mmap_addr(vma->vm_start))
74270 + return -EPERM;
74271 +
74272 /*
74273 * The vm_pgoff of a purely anonymous vma should be irrelevant
74274 * until its first write fault, when page's anon_vma and index
74275 @@ -2364,7 +2790,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
74276 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74277 return -ENOMEM;
74278
74279 +#ifdef CONFIG_PAX_SEGMEXEC
74280 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74281 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74282 + if (!vma_m)
74283 + return -ENOMEM;
74284 + }
74285 +#endif
74286 +
74287 vma_link(mm, vma, prev, rb_link, rb_parent);
74288 +
74289 +#ifdef CONFIG_PAX_SEGMEXEC
74290 + if (vma_m)
74291 + BUG_ON(pax_mirror_vma(vma_m, vma));
74292 +#endif
74293 +
74294 return 0;
74295 }
74296
74297 @@ -2384,6 +2824,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74298 struct mempolicy *pol;
74299 bool faulted_in_anon_vma = true;
74300
74301 + BUG_ON(vma->vm_mirror);
74302 +
74303 /*
74304 * If anonymous vma has not yet been faulted, update new pgoff
74305 * to match new location, to increase its chance of merging.
74306 @@ -2450,6 +2892,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74307 return NULL;
74308 }
74309
74310 +#ifdef CONFIG_PAX_SEGMEXEC
74311 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74312 +{
74313 + struct vm_area_struct *prev_m;
74314 + struct rb_node **rb_link_m, *rb_parent_m;
74315 + struct mempolicy *pol_m;
74316 +
74317 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74318 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74319 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74320 + *vma_m = *vma;
74321 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74322 + if (anon_vma_clone(vma_m, vma))
74323 + return -ENOMEM;
74324 + pol_m = vma_policy(vma_m);
74325 + mpol_get(pol_m);
74326 + vma_set_policy(vma_m, pol_m);
74327 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74328 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74329 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74330 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74331 + if (vma_m->vm_file)
74332 + get_file(vma_m->vm_file);
74333 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74334 + vma_m->vm_ops->open(vma_m);
74335 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
74336 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74337 + vma_m->vm_mirror = vma;
74338 + vma->vm_mirror = vma_m;
74339 + return 0;
74340 +}
74341 +#endif
74342 +
74343 /*
74344 * Return true if the calling process may expand its vm space by the passed
74345 * number of pages
74346 @@ -2461,6 +2936,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74347
74348 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74349
74350 +#ifdef CONFIG_PAX_RANDMMAP
74351 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74352 + cur -= mm->brk_gap;
74353 +#endif
74354 +
74355 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74356 if (cur + npages > lim)
74357 return 0;
74358 return 1;
74359 @@ -2531,6 +3012,22 @@ int install_special_mapping(struct mm_struct *mm,
74360 vma->vm_start = addr;
74361 vma->vm_end = addr + len;
74362
74363 +#ifdef CONFIG_PAX_MPROTECT
74364 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74365 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74366 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74367 + return -EPERM;
74368 + if (!(vm_flags & VM_EXEC))
74369 + vm_flags &= ~VM_MAYEXEC;
74370 +#else
74371 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74372 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74373 +#endif
74374 + else
74375 + vm_flags &= ~VM_MAYWRITE;
74376 + }
74377 +#endif
74378 +
74379 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74380 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74381
74382 diff --git a/mm/mprotect.c b/mm/mprotect.c
74383 index a409926..8b32e6d 100644
74384 --- a/mm/mprotect.c
74385 +++ b/mm/mprotect.c
74386 @@ -23,10 +23,17 @@
74387 #include <linux/mmu_notifier.h>
74388 #include <linux/migrate.h>
74389 #include <linux/perf_event.h>
74390 +
74391 +#ifdef CONFIG_PAX_MPROTECT
74392 +#include <linux/elf.h>
74393 +#include <linux/binfmts.h>
74394 +#endif
74395 +
74396 #include <asm/uaccess.h>
74397 #include <asm/pgtable.h>
74398 #include <asm/cacheflush.h>
74399 #include <asm/tlbflush.h>
74400 +#include <asm/mmu_context.h>
74401
74402 #ifndef pgprot_modify
74403 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74404 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74405 flush_tlb_range(vma, start, end);
74406 }
74407
74408 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74409 +/* called while holding the mmap semaphor for writing except stack expansion */
74410 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74411 +{
74412 + unsigned long oldlimit, newlimit = 0UL;
74413 +
74414 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74415 + return;
74416 +
74417 + spin_lock(&mm->page_table_lock);
74418 + oldlimit = mm->context.user_cs_limit;
74419 + if ((prot & VM_EXEC) && oldlimit < end)
74420 + /* USER_CS limit moved up */
74421 + newlimit = end;
74422 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74423 + /* USER_CS limit moved down */
74424 + newlimit = start;
74425 +
74426 + if (newlimit) {
74427 + mm->context.user_cs_limit = newlimit;
74428 +
74429 +#ifdef CONFIG_SMP
74430 + wmb();
74431 + cpus_clear(mm->context.cpu_user_cs_mask);
74432 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74433 +#endif
74434 +
74435 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74436 + }
74437 + spin_unlock(&mm->page_table_lock);
74438 + if (newlimit == end) {
74439 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74440 +
74441 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74442 + if (is_vm_hugetlb_page(vma))
74443 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74444 + else
74445 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74446 + }
74447 +}
74448 +#endif
74449 +
74450 int
74451 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74452 unsigned long start, unsigned long end, unsigned long newflags)
74453 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74454 int error;
74455 int dirty_accountable = 0;
74456
74457 +#ifdef CONFIG_PAX_SEGMEXEC
74458 + struct vm_area_struct *vma_m = NULL;
74459 + unsigned long start_m, end_m;
74460 +
74461 + start_m = start + SEGMEXEC_TASK_SIZE;
74462 + end_m = end + SEGMEXEC_TASK_SIZE;
74463 +#endif
74464 +
74465 if (newflags == oldflags) {
74466 *pprev = vma;
74467 return 0;
74468 }
74469
74470 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74471 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74472 +
74473 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74474 + return -ENOMEM;
74475 +
74476 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74477 + return -ENOMEM;
74478 + }
74479 +
74480 /*
74481 * If we make a private mapping writable we increase our commit;
74482 * but (without finer accounting) cannot reduce our commit if we
74483 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74484 }
74485 }
74486
74487 +#ifdef CONFIG_PAX_SEGMEXEC
74488 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74489 + if (start != vma->vm_start) {
74490 + error = split_vma(mm, vma, start, 1);
74491 + if (error)
74492 + goto fail;
74493 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74494 + *pprev = (*pprev)->vm_next;
74495 + }
74496 +
74497 + if (end != vma->vm_end) {
74498 + error = split_vma(mm, vma, end, 0);
74499 + if (error)
74500 + goto fail;
74501 + }
74502 +
74503 + if (pax_find_mirror_vma(vma)) {
74504 + error = __do_munmap(mm, start_m, end_m - start_m);
74505 + if (error)
74506 + goto fail;
74507 + } else {
74508 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74509 + if (!vma_m) {
74510 + error = -ENOMEM;
74511 + goto fail;
74512 + }
74513 + vma->vm_flags = newflags;
74514 + error = pax_mirror_vma(vma_m, vma);
74515 + if (error) {
74516 + vma->vm_flags = oldflags;
74517 + goto fail;
74518 + }
74519 + }
74520 + }
74521 +#endif
74522 +
74523 /*
74524 * First try to merge with previous and/or next vma.
74525 */
74526 @@ -204,9 +307,21 @@ success:
74527 * vm_flags and vm_page_prot are protected by the mmap_sem
74528 * held in write mode.
74529 */
74530 +
74531 +#ifdef CONFIG_PAX_SEGMEXEC
74532 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74533 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74534 +#endif
74535 +
74536 vma->vm_flags = newflags;
74537 +
74538 +#ifdef CONFIG_PAX_MPROTECT
74539 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74540 + mm->binfmt->handle_mprotect(vma, newflags);
74541 +#endif
74542 +
74543 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74544 - vm_get_page_prot(newflags));
74545 + vm_get_page_prot(vma->vm_flags));
74546
74547 if (vma_wants_writenotify(vma)) {
74548 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74549 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74550 end = start + len;
74551 if (end <= start)
74552 return -ENOMEM;
74553 +
74554 +#ifdef CONFIG_PAX_SEGMEXEC
74555 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74556 + if (end > SEGMEXEC_TASK_SIZE)
74557 + return -EINVAL;
74558 + } else
74559 +#endif
74560 +
74561 + if (end > TASK_SIZE)
74562 + return -EINVAL;
74563 +
74564 if (!arch_validate_prot(prot))
74565 return -EINVAL;
74566
74567 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74568 /*
74569 * Does the application expect PROT_READ to imply PROT_EXEC:
74570 */
74571 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74572 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74573 prot |= PROT_EXEC;
74574
74575 vm_flags = calc_vm_prot_bits(prot);
74576 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74577 if (start > vma->vm_start)
74578 prev = vma;
74579
74580 +#ifdef CONFIG_PAX_MPROTECT
74581 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74582 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74583 +#endif
74584 +
74585 for (nstart = start ; ; ) {
74586 unsigned long newflags;
74587
74588 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74589
74590 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74591 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74592 + if (prot & (PROT_WRITE | PROT_EXEC))
74593 + gr_log_rwxmprotect(vma->vm_file);
74594 +
74595 + error = -EACCES;
74596 + goto out;
74597 + }
74598 +
74599 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74600 error = -EACCES;
74601 goto out;
74602 }
74603 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74604 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74605 if (error)
74606 goto out;
74607 +
74608 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74609 +
74610 nstart = tmp;
74611
74612 if (nstart < prev->vm_end)
74613 diff --git a/mm/mremap.c b/mm/mremap.c
74614 index 1b61c2d..1cc0e3c 100644
74615 --- a/mm/mremap.c
74616 +++ b/mm/mremap.c
74617 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74618 continue;
74619 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74620 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74621 +
74622 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74623 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74624 + pte = pte_exprotect(pte);
74625 +#endif
74626 +
74627 set_pte_at(mm, new_addr, new_pte, pte);
74628 }
74629
74630 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74631 if (is_vm_hugetlb_page(vma))
74632 goto Einval;
74633
74634 +#ifdef CONFIG_PAX_SEGMEXEC
74635 + if (pax_find_mirror_vma(vma))
74636 + goto Einval;
74637 +#endif
74638 +
74639 /* We can't remap across vm area boundaries */
74640 if (old_len > vma->vm_end - addr)
74641 goto Efault;
74642 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
74643 unsigned long ret = -EINVAL;
74644 unsigned long charged = 0;
74645 unsigned long map_flags;
74646 + unsigned long pax_task_size = TASK_SIZE;
74647
74648 if (new_addr & ~PAGE_MASK)
74649 goto out;
74650
74651 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74652 +#ifdef CONFIG_PAX_SEGMEXEC
74653 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74654 + pax_task_size = SEGMEXEC_TASK_SIZE;
74655 +#endif
74656 +
74657 + pax_task_size -= PAGE_SIZE;
74658 +
74659 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74660 goto out;
74661
74662 /* Check if the location we're moving into overlaps the
74663 * old location at all, and fail if it does.
74664 */
74665 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74666 - goto out;
74667 -
74668 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74669 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74670 goto out;
74671
74672 ret = do_munmap(mm, new_addr, new_len);
74673 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74674 struct vm_area_struct *vma;
74675 unsigned long ret = -EINVAL;
74676 unsigned long charged = 0;
74677 + unsigned long pax_task_size = TASK_SIZE;
74678
74679 down_write(&current->mm->mmap_sem);
74680
74681 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74682 if (!new_len)
74683 goto out;
74684
74685 +#ifdef CONFIG_PAX_SEGMEXEC
74686 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74687 + pax_task_size = SEGMEXEC_TASK_SIZE;
74688 +#endif
74689 +
74690 + pax_task_size -= PAGE_SIZE;
74691 +
74692 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74693 + old_len > pax_task_size || addr > pax_task_size-old_len)
74694 + goto out;
74695 +
74696 if (flags & MREMAP_FIXED) {
74697 if (flags & MREMAP_MAYMOVE)
74698 ret = mremap_to(addr, old_len, new_addr, new_len);
74699 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74700 addr + new_len);
74701 }
74702 ret = addr;
74703 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74704 goto out;
74705 }
74706 }
74707 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74708 goto out;
74709 }
74710
74711 + map_flags = vma->vm_flags;
74712 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74713 + if (!(ret & ~PAGE_MASK)) {
74714 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74715 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74716 + }
74717 }
74718 out:
74719 if (ret & ~PAGE_MASK)
74720 diff --git a/mm/nommu.c b/mm/nommu.c
74721 index 45131b4..c521665 100644
74722 --- a/mm/nommu.c
74723 +++ b/mm/nommu.c
74724 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74725 int sysctl_overcommit_ratio = 50; /* default is 50% */
74726 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74727 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74728 -int heap_stack_gap = 0;
74729
74730 atomic_long_t mmap_pages_allocated;
74731
74732 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74733 EXPORT_SYMBOL(find_vma);
74734
74735 /*
74736 - * find a VMA
74737 - * - we don't extend stack VMAs under NOMMU conditions
74738 - */
74739 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74740 -{
74741 - return find_vma(mm, addr);
74742 -}
74743 -
74744 -/*
74745 * expand a stack to a given address
74746 * - not supported under NOMMU conditions
74747 */
74748 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74749
74750 /* most fields are the same, copy all, and then fixup */
74751 *new = *vma;
74752 + INIT_LIST_HEAD(&new->anon_vma_chain);
74753 *region = *vma->vm_region;
74754 new->vm_region = region;
74755
74756 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74757 index 7e208f0..d96f232 100644
74758 --- a/mm/page_alloc.c
74759 +++ b/mm/page_alloc.c
74760 @@ -340,7 +340,7 @@ out:
74761 * This usage means that zero-order pages may not be compound.
74762 */
74763
74764 -static void free_compound_page(struct page *page)
74765 +void free_compound_page(struct page *page)
74766 {
74767 __free_pages_ok(page, compound_order(page));
74768 }
74769 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74770 int i;
74771 int bad = 0;
74772
74773 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74774 + unsigned long index = 1UL << order;
74775 +#endif
74776 +
74777 trace_mm_page_free(page, order);
74778 kmemcheck_free_shadow(page, order);
74779
74780 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74781 debug_check_no_obj_freed(page_address(page),
74782 PAGE_SIZE << order);
74783 }
74784 +
74785 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74786 + for (; index; --index)
74787 + sanitize_highpage(page + index - 1);
74788 +#endif
74789 +
74790 arch_free_page(page, order);
74791 kernel_map_pages(page, 1 << order, 0);
74792
74793 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74794 arch_alloc_page(page, order);
74795 kernel_map_pages(page, 1 << order, 1);
74796
74797 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74798 if (gfp_flags & __GFP_ZERO)
74799 prep_zero_page(page, order, gfp_flags);
74800 +#endif
74801
74802 if (order && (gfp_flags & __GFP_COMP))
74803 prep_compound_page(page, order);
74804 @@ -3703,7 +3715,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74805 unsigned long pfn;
74806
74807 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74808 +#ifdef CONFIG_X86_32
74809 + /* boot failures in VMware 8 on 32bit vanilla since
74810 + this change */
74811 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74812 +#else
74813 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74814 +#endif
74815 return 1;
74816 }
74817 return 0;
74818 diff --git a/mm/percpu.c b/mm/percpu.c
74819 index ddc5efb..f632d2c 100644
74820 --- a/mm/percpu.c
74821 +++ b/mm/percpu.c
74822 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74823 static unsigned int pcpu_high_unit_cpu __read_mostly;
74824
74825 /* the address of the first chunk which starts with the kernel static area */
74826 -void *pcpu_base_addr __read_mostly;
74827 +void *pcpu_base_addr __read_only;
74828 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74829
74830 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74831 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74832 index 926b466..b23df53 100644
74833 --- a/mm/process_vm_access.c
74834 +++ b/mm/process_vm_access.c
74835 @@ -13,6 +13,7 @@
74836 #include <linux/uio.h>
74837 #include <linux/sched.h>
74838 #include <linux/highmem.h>
74839 +#include <linux/security.h>
74840 #include <linux/ptrace.h>
74841 #include <linux/slab.h>
74842 #include <linux/syscalls.h>
74843 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74844 size_t iov_l_curr_offset = 0;
74845 ssize_t iov_len;
74846
74847 + return -ENOSYS; // PaX: until properly audited
74848 +
74849 /*
74850 * Work out how many pages of struct pages we're going to need
74851 * when eventually calling get_user_pages
74852 */
74853 for (i = 0; i < riovcnt; i++) {
74854 iov_len = rvec[i].iov_len;
74855 - if (iov_len > 0) {
74856 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74857 - + iov_len)
74858 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74859 - / PAGE_SIZE + 1;
74860 - nr_pages = max(nr_pages, nr_pages_iov);
74861 - }
74862 + if (iov_len <= 0)
74863 + continue;
74864 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74865 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74866 + nr_pages = max(nr_pages, nr_pages_iov);
74867 }
74868
74869 if (nr_pages == 0)
74870 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74871 goto free_proc_pages;
74872 }
74873
74874 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74875 + rc = -EPERM;
74876 + goto put_task_struct;
74877 + }
74878 +
74879 mm = mm_access(task, PTRACE_MODE_ATTACH);
74880 if (!mm || IS_ERR(mm)) {
74881 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74882 diff --git a/mm/rmap.c b/mm/rmap.c
74883 index 2ee1ef0..2e175ba 100644
74884 --- a/mm/rmap.c
74885 +++ b/mm/rmap.c
74886 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74887 struct anon_vma *anon_vma = vma->anon_vma;
74888 struct anon_vma_chain *avc;
74889
74890 +#ifdef CONFIG_PAX_SEGMEXEC
74891 + struct anon_vma_chain *avc_m = NULL;
74892 +#endif
74893 +
74894 might_sleep();
74895 if (unlikely(!anon_vma)) {
74896 struct mm_struct *mm = vma->vm_mm;
74897 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74898 if (!avc)
74899 goto out_enomem;
74900
74901 +#ifdef CONFIG_PAX_SEGMEXEC
74902 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74903 + if (!avc_m)
74904 + goto out_enomem_free_avc;
74905 +#endif
74906 +
74907 anon_vma = find_mergeable_anon_vma(vma);
74908 allocated = NULL;
74909 if (!anon_vma) {
74910 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74911 /* page_table_lock to protect against threads */
74912 spin_lock(&mm->page_table_lock);
74913 if (likely(!vma->anon_vma)) {
74914 +
74915 +#ifdef CONFIG_PAX_SEGMEXEC
74916 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74917 +
74918 + if (vma_m) {
74919 + BUG_ON(vma_m->anon_vma);
74920 + vma_m->anon_vma = anon_vma;
74921 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74922 + avc_m = NULL;
74923 + }
74924 +#endif
74925 +
74926 vma->anon_vma = anon_vma;
74927 anon_vma_chain_link(vma, avc, anon_vma);
74928 allocated = NULL;
74929 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74930
74931 if (unlikely(allocated))
74932 put_anon_vma(allocated);
74933 +
74934 +#ifdef CONFIG_PAX_SEGMEXEC
74935 + if (unlikely(avc_m))
74936 + anon_vma_chain_free(avc_m);
74937 +#endif
74938 +
74939 if (unlikely(avc))
74940 anon_vma_chain_free(avc);
74941 }
74942 return 0;
74943
74944 out_enomem_free_avc:
74945 +
74946 +#ifdef CONFIG_PAX_SEGMEXEC
74947 + if (avc_m)
74948 + anon_vma_chain_free(avc_m);
74949 +#endif
74950 +
74951 anon_vma_chain_free(avc);
74952 out_enomem:
74953 return -ENOMEM;
74954 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74955 * Attach the anon_vmas from src to dst.
74956 * Returns 0 on success, -ENOMEM on failure.
74957 */
74958 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74959 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74960 {
74961 struct anon_vma_chain *avc, *pavc;
74962 struct anon_vma *root = NULL;
74963 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74964 * the corresponding VMA in the parent process is attached to.
74965 * Returns 0 on success, non-zero on failure.
74966 */
74967 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74968 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74969 {
74970 struct anon_vma_chain *avc;
74971 struct anon_vma *anon_vma;
74972 diff --git a/mm/shmem.c b/mm/shmem.c
74973 index 50c5b8f..0bc87f7 100644
74974 --- a/mm/shmem.c
74975 +++ b/mm/shmem.c
74976 @@ -31,7 +31,7 @@
74977 #include <linux/export.h>
74978 #include <linux/swap.h>
74979
74980 -static struct vfsmount *shm_mnt;
74981 +struct vfsmount *shm_mnt;
74982
74983 #ifdef CONFIG_SHMEM
74984 /*
74985 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74986 #define BOGO_DIRENT_SIZE 20
74987
74988 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74989 -#define SHORT_SYMLINK_LEN 128
74990 +#define SHORT_SYMLINK_LEN 64
74991
74992 /*
74993 * shmem_fallocate and shmem_writepage communicate via inode->i_private
74994 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
74995 static int shmem_xattr_validate(const char *name)
74996 {
74997 struct { const char *prefix; size_t len; } arr[] = {
74998 +
74999 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75000 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75001 +#endif
75002 +
75003 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75004 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75005 };
75006 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75007 if (err)
75008 return err;
75009
75010 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75011 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75012 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75013 + return -EOPNOTSUPP;
75014 + if (size > 8)
75015 + return -EINVAL;
75016 + }
75017 +#endif
75018 +
75019 return simple_xattr_set(&info->xattrs, name, value, size, flags);
75020 }
75021
75022 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75023 int err = -ENOMEM;
75024
75025 /* Round up to L1_CACHE_BYTES to resist false sharing */
75026 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75027 - L1_CACHE_BYTES), GFP_KERNEL);
75028 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75029 if (!sbinfo)
75030 return -ENOMEM;
75031
75032 diff --git a/mm/slab.c b/mm/slab.c
75033 index 33d3363..69ffb8a 100644
75034 --- a/mm/slab.c
75035 +++ b/mm/slab.c
75036 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75037
75038 /* Legal flag mask for kmem_cache_create(). */
75039 #if DEBUG
75040 -# define CREATE_MASK (SLAB_RED_ZONE | \
75041 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75042 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75043 SLAB_CACHE_DMA | \
75044 SLAB_STORE_USER | \
75045 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75046 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75047 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75048 #else
75049 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75050 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75051 SLAB_CACHE_DMA | \
75052 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75053 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75054 @@ -322,7 +322,7 @@ struct kmem_list3 {
75055 * Need this for bootstrapping a per node allocator.
75056 */
75057 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75058 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75059 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75060 #define CACHE_CACHE 0
75061 #define SIZE_AC MAX_NUMNODES
75062 #define SIZE_L3 (2 * MAX_NUMNODES)
75063 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75064 if ((x)->max_freeable < i) \
75065 (x)->max_freeable = i; \
75066 } while (0)
75067 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75068 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75069 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75070 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75071 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75072 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75073 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75074 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75075 #else
75076 #define STATS_INC_ACTIVE(x) do { } while (0)
75077 #define STATS_DEC_ACTIVE(x) do { } while (0)
75078 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75079 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75080 */
75081 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75082 - const struct slab *slab, void *obj)
75083 + const struct slab *slab, const void *obj)
75084 {
75085 u32 offset = (obj - slab->s_mem);
75086 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75087 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
75088 struct cache_names {
75089 char *name;
75090 char *name_dma;
75091 + char *name_usercopy;
75092 };
75093
75094 static struct cache_names __initdata cache_names[] = {
75095 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75096 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75097 #include <linux/kmalloc_sizes.h>
75098 - {NULL,}
75099 + {NULL}
75100 #undef CACHE
75101 };
75102
75103 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75104 if (unlikely(gfpflags & GFP_DMA))
75105 return csizep->cs_dmacachep;
75106 #endif
75107 +
75108 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75109 + if (unlikely(gfpflags & GFP_USERCOPY))
75110 + return csizep->cs_usercopycachep;
75111 +#endif
75112 +
75113 return csizep->cs_cachep;
75114 }
75115
75116 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
75117 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
75118 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
75119 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75120 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75121 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75122 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
75123
75124 if (INDEX_AC != INDEX_L3) {
75125 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
75126 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
75127 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
75128 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75129 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75130 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75131 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
75132 }
75133
75134 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
75135 sizes->cs_cachep->size = sizes->cs_size;
75136 sizes->cs_cachep->object_size = sizes->cs_size;
75137 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75138 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75139 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75140 list_add(&sizes->cs_cachep->list, &slab_caches);
75141 }
75142 #ifdef CONFIG_ZONE_DMA
75143 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
75144 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
75145 list_add(&sizes->cs_dmacachep->list, &slab_caches);
75146 #endif
75147 +
75148 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75149 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
75150 + sizes->cs_usercopycachep->name = names->name_dma;
75151 + sizes->cs_usercopycachep->size = sizes->cs_size;
75152 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
75153 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
75154 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
75155 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
75156 +#endif
75157 +
75158 sizes++;
75159 names++;
75160 }
75161 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
75162 }
75163 /* cpu stats */
75164 {
75165 - unsigned long allochit = atomic_read(&cachep->allochit);
75166 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75167 - unsigned long freehit = atomic_read(&cachep->freehit);
75168 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75169 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75170 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75171 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75172 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75173
75174 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75175 allochit, allocmiss, freehit, freemiss);
75176 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
75177 {
75178 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75179 #ifdef CONFIG_DEBUG_SLAB_LEAK
75180 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75181 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75182 #endif
75183 return 0;
75184 }
75185 module_init(slab_proc_init);
75186 #endif
75187
75188 +bool is_usercopy_object(const void *ptr)
75189 +{
75190 + struct page *page;
75191 + struct kmem_cache *cachep;
75192 +
75193 + if (ZERO_OR_NULL_PTR(ptr))
75194 + return false;
75195 +
75196 + if (!slab_is_available())
75197 + return false;
75198 +
75199 + if (!virt_addr_valid(ptr))
75200 + return false;
75201 +
75202 + page = virt_to_head_page(ptr);
75203 +
75204 + if (!PageSlab(page))
75205 + return false;
75206 +
75207 + cachep = page->slab_cache;
75208 + return cachep->flags & SLAB_USERCOPY;
75209 +}
75210 +
75211 +#ifdef CONFIG_PAX_USERCOPY
75212 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75213 +{
75214 + struct page *page;
75215 + struct kmem_cache *cachep;
75216 + struct slab *slabp;
75217 + unsigned int objnr;
75218 + unsigned long offset;
75219 +
75220 + if (ZERO_OR_NULL_PTR(ptr))
75221 + return "<null>";
75222 +
75223 + if (!virt_addr_valid(ptr))
75224 + return NULL;
75225 +
75226 + page = virt_to_head_page(ptr);
75227 +
75228 + if (!PageSlab(page))
75229 + return NULL;
75230 +
75231 + cachep = page->slab_cache;
75232 + if (!(cachep->flags & SLAB_USERCOPY))
75233 + return cachep->name;
75234 +
75235 + slabp = page->slab_page;
75236 + objnr = obj_to_index(cachep, slabp, ptr);
75237 + BUG_ON(objnr >= cachep->num);
75238 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75239 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75240 + return NULL;
75241 +
75242 + return cachep->name;
75243 +}
75244 +#endif
75245 +
75246 /**
75247 * ksize - get the actual amount of memory allocated for a given object
75248 * @objp: Pointer to the object
75249 diff --git a/mm/slab_common.c b/mm/slab_common.c
75250 index 069a24e6..226a310 100644
75251 --- a/mm/slab_common.c
75252 +++ b/mm/slab_common.c
75253 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
75254 err = __kmem_cache_create(s, flags);
75255 if (!err) {
75256
75257 - s->refcount = 1;
75258 + atomic_set(&s->refcount, 1);
75259 list_add(&s->list, &slab_caches);
75260
75261 } else {
75262 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
75263 {
75264 get_online_cpus();
75265 mutex_lock(&slab_mutex);
75266 - s->refcount--;
75267 - if (!s->refcount) {
75268 + if (atomic_dec_and_test(&s->refcount)) {
75269 list_del(&s->list);
75270
75271 if (!__kmem_cache_shutdown(s)) {
75272 diff --git a/mm/slob.c b/mm/slob.c
75273 index 1e921c5..7042228 100644
75274 --- a/mm/slob.c
75275 +++ b/mm/slob.c
75276 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75277 /*
75278 * Return the size of a slob block.
75279 */
75280 -static slobidx_t slob_units(slob_t *s)
75281 +static slobidx_t slob_units(const slob_t *s)
75282 {
75283 if (s->units > 0)
75284 return s->units;
75285 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75286 /*
75287 * Return the next free slob block pointer after this one.
75288 */
75289 -static slob_t *slob_next(slob_t *s)
75290 +static slob_t *slob_next(const slob_t *s)
75291 {
75292 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75293 slobidx_t next;
75294 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75295 /*
75296 * Returns true if s is the last free block in its page.
75297 */
75298 -static int slob_last(slob_t *s)
75299 +static int slob_last(const slob_t *s)
75300 {
75301 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75302 }
75303
75304 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75305 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75306 {
75307 - void *page;
75308 + struct page *page;
75309
75310 #ifdef CONFIG_NUMA
75311 if (node != NUMA_NO_NODE)
75312 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75313 if (!page)
75314 return NULL;
75315
75316 - return page_address(page);
75317 + __SetPageSlab(page);
75318 + return page;
75319 }
75320
75321 -static void slob_free_pages(void *b, int order)
75322 +static void slob_free_pages(struct page *sp, int order)
75323 {
75324 if (current->reclaim_state)
75325 current->reclaim_state->reclaimed_slab += 1 << order;
75326 - free_pages((unsigned long)b, order);
75327 + __ClearPageSlab(sp);
75328 + reset_page_mapcount(sp);
75329 + sp->private = 0;
75330 + __free_pages(sp, order);
75331 }
75332
75333 /*
75334 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75335
75336 /* Not enough space: must allocate a new page */
75337 if (!b) {
75338 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75339 - if (!b)
75340 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75341 + if (!sp)
75342 return NULL;
75343 - sp = virt_to_page(b);
75344 - __SetPageSlab(sp);
75345 + b = page_address(sp);
75346
75347 spin_lock_irqsave(&slob_lock, flags);
75348 sp->units = SLOB_UNITS(PAGE_SIZE);
75349 sp->freelist = b;
75350 + sp->private = 0;
75351 INIT_LIST_HEAD(&sp->list);
75352 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75353 set_slob_page_free(sp, slob_list);
75354 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75355 if (slob_page_free(sp))
75356 clear_slob_page_free(sp);
75357 spin_unlock_irqrestore(&slob_lock, flags);
75358 - __ClearPageSlab(sp);
75359 - reset_page_mapcount(sp);
75360 - slob_free_pages(b, 0);
75361 + slob_free_pages(sp, 0);
75362 return;
75363 }
75364
75365 @@ -426,11 +428,10 @@ out:
75366 */
75367
75368 static __always_inline void *
75369 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75370 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
75371 {
75372 - unsigned int *m;
75373 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75374 - void *ret;
75375 + slob_t *m;
75376 + void *ret = NULL;
75377
75378 gfp &= gfp_allowed_mask;
75379
75380 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75381
75382 if (!m)
75383 return NULL;
75384 - *m = size;
75385 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75386 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75387 + m[0].units = size;
75388 + m[1].units = align;
75389 ret = (void *)m + align;
75390
75391 trace_kmalloc_node(caller, ret,
75392 size, size + align, gfp, node);
75393 } else {
75394 unsigned int order = get_order(size);
75395 + struct page *page;
75396
75397 if (likely(order))
75398 gfp |= __GFP_COMP;
75399 - ret = slob_new_pages(gfp, order, node);
75400 - if (ret) {
75401 - struct page *page;
75402 - page = virt_to_page(ret);
75403 + page = slob_new_pages(gfp, order, node);
75404 + if (page) {
75405 + ret = page_address(page);
75406 page->private = size;
75407 }
75408
75409 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75410 size, PAGE_SIZE << order, gfp, node);
75411 }
75412
75413 - kmemleak_alloc(ret, size, 1, gfp);
75414 + return ret;
75415 +}
75416 +
75417 +static __always_inline void *
75418 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75419 +{
75420 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75421 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
75422 +
75423 + if (!ZERO_OR_NULL_PTR(ret))
75424 + kmemleak_alloc(ret, size, 1, gfp);
75425 return ret;
75426 }
75427
75428 @@ -501,15 +515,91 @@ void kfree(const void *block)
75429 kmemleak_free(block);
75430
75431 sp = virt_to_page(block);
75432 - if (PageSlab(sp)) {
75433 + VM_BUG_ON(!PageSlab(sp));
75434 + if (!sp->private) {
75435 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75436 - unsigned int *m = (unsigned int *)(block - align);
75437 - slob_free(m, *m + align);
75438 - } else
75439 + slob_t *m = (slob_t *)(block - align);
75440 + slob_free(m, m[0].units + align);
75441 + } else {
75442 + __ClearPageSlab(sp);
75443 + reset_page_mapcount(sp);
75444 + sp->private = 0;
75445 put_page(sp);
75446 + }
75447 }
75448 EXPORT_SYMBOL(kfree);
75449
75450 +bool is_usercopy_object(const void *ptr)
75451 +{
75452 + if (!slab_is_available())
75453 + return false;
75454 +
75455 + // PAX: TODO
75456 +
75457 + return false;
75458 +}
75459 +
75460 +#ifdef CONFIG_PAX_USERCOPY
75461 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75462 +{
75463 + struct page *page;
75464 + const slob_t *free;
75465 + const void *base;
75466 + unsigned long flags;
75467 +
75468 + if (ZERO_OR_NULL_PTR(ptr))
75469 + return "<null>";
75470 +
75471 + if (!virt_addr_valid(ptr))
75472 + return NULL;
75473 +
75474 + page = virt_to_head_page(ptr);
75475 + if (!PageSlab(page))
75476 + return NULL;
75477 +
75478 + if (page->private) {
75479 + base = page;
75480 + if (base <= ptr && n <= page->private - (ptr - base))
75481 + return NULL;
75482 + return "<slob>";
75483 + }
75484 +
75485 + /* some tricky double walking to find the chunk */
75486 + spin_lock_irqsave(&slob_lock, flags);
75487 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75488 + free = page->freelist;
75489 +
75490 + while (!slob_last(free) && (void *)free <= ptr) {
75491 + base = free + slob_units(free);
75492 + free = slob_next(free);
75493 + }
75494 +
75495 + while (base < (void *)free) {
75496 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75497 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75498 + int offset;
75499 +
75500 + if (ptr < base + align)
75501 + break;
75502 +
75503 + offset = ptr - base - align;
75504 + if (offset >= m) {
75505 + base += size;
75506 + continue;
75507 + }
75508 +
75509 + if (n > m - offset)
75510 + break;
75511 +
75512 + spin_unlock_irqrestore(&slob_lock, flags);
75513 + return NULL;
75514 + }
75515 +
75516 + spin_unlock_irqrestore(&slob_lock, flags);
75517 + return "<slob>";
75518 +}
75519 +#endif
75520 +
75521 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75522 size_t ksize(const void *block)
75523 {
75524 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
75525 return 0;
75526
75527 sp = virt_to_page(block);
75528 - if (PageSlab(sp)) {
75529 + VM_BUG_ON(!PageSlab(sp));
75530 + if (!sp->private) {
75531 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75532 - unsigned int *m = (unsigned int *)(block - align);
75533 - return SLOB_UNITS(*m) * SLOB_UNIT;
75534 + slob_t *m = (slob_t *)(block - align);
75535 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75536 } else
75537 return sp->private;
75538 }
75539 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
75540
75541 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75542 {
75543 - void *b;
75544 + void *b = NULL;
75545
75546 flags &= gfp_allowed_mask;
75547
75548 lockdep_trace_alloc(flags);
75549
75550 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75551 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
75552 +#else
75553 if (c->size < PAGE_SIZE) {
75554 b = slob_alloc(c->size, flags, c->align, node);
75555 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75556 SLOB_UNITS(c->size) * SLOB_UNIT,
75557 flags, node);
75558 } else {
75559 - b = slob_new_pages(flags, get_order(c->size), node);
75560 + struct page *sp;
75561 +
75562 + sp = slob_new_pages(flags, get_order(c->size), node);
75563 + if (sp) {
75564 + b = page_address(sp);
75565 + sp->private = c->size;
75566 + }
75567 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75568 PAGE_SIZE << get_order(c->size),
75569 flags, node);
75570 }
75571 +#endif
75572
75573 if (c->ctor)
75574 c->ctor(b);
75575 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75576
75577 static void __kmem_cache_free(void *b, int size)
75578 {
75579 - if (size < PAGE_SIZE)
75580 + struct page *sp;
75581 +
75582 + sp = virt_to_page(b);
75583 + BUG_ON(!PageSlab(sp));
75584 + if (!sp->private)
75585 slob_free(b, size);
75586 else
75587 - slob_free_pages(b, get_order(size));
75588 + slob_free_pages(sp, get_order(size));
75589 }
75590
75591 static void kmem_rcu_free(struct rcu_head *head)
75592 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75593
75594 void kmem_cache_free(struct kmem_cache *c, void *b)
75595 {
75596 + int size = c->size;
75597 +
75598 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75599 + if (size + c->align < PAGE_SIZE) {
75600 + size += c->align;
75601 + b -= c->align;
75602 + }
75603 +#endif
75604 +
75605 kmemleak_free_recursive(b, c->flags);
75606 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75607 struct slob_rcu *slob_rcu;
75608 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75609 - slob_rcu->size = c->size;
75610 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75611 + slob_rcu->size = size;
75612 call_rcu(&slob_rcu->head, kmem_rcu_free);
75613 } else {
75614 - __kmem_cache_free(b, c->size);
75615 + __kmem_cache_free(b, size);
75616 }
75617
75618 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75619 + trace_kfree(_RET_IP_, b);
75620 +#else
75621 trace_kmem_cache_free(_RET_IP_, b);
75622 +#endif
75623 +
75624 }
75625 EXPORT_SYMBOL(kmem_cache_free);
75626
75627 diff --git a/mm/slub.c b/mm/slub.c
75628 index a0d6984..b77d8c9 100644
75629 --- a/mm/slub.c
75630 +++ b/mm/slub.c
75631 @@ -201,7 +201,7 @@ struct track {
75632
75633 enum track_item { TRACK_ALLOC, TRACK_FREE };
75634
75635 -#ifdef CONFIG_SYSFS
75636 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75637 static int sysfs_slab_add(struct kmem_cache *);
75638 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75639 static void sysfs_slab_remove(struct kmem_cache *);
75640 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
75641 if (!t->addr)
75642 return;
75643
75644 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75645 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75646 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75647 #ifdef CONFIG_STACKTRACE
75648 {
75649 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75650
75651 page = virt_to_head_page(x);
75652
75653 + BUG_ON(!PageSlab(page));
75654 +
75655 if (kmem_cache_debug(s) && page->slab != s) {
75656 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
75657 " is from %s\n", page->slab->name, s->name);
75658 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
75659 * Merge control. If this is set then no merging of slab caches will occur.
75660 * (Could be removed. This was introduced to pacify the merge skeptics.)
75661 */
75662 -static int slub_nomerge;
75663 +static int slub_nomerge = 1;
75664
75665 /*
75666 * Calculate the order of allocation given an slab object size.
75667 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
75668 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75669 #endif
75670
75671 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75672 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75673 +#endif
75674 +
75675 static int __init setup_slub_min_order(char *str)
75676 {
75677 get_option(&str, &slub_min_order);
75678 @@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75679 return kmalloc_dma_caches[index];
75680
75681 #endif
75682 +
75683 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75684 + if (flags & SLAB_USERCOPY)
75685 + return kmalloc_usercopy_caches[index];
75686 +
75687 +#endif
75688 +
75689 return kmalloc_caches[index];
75690 }
75691
75692 @@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75693 EXPORT_SYMBOL(__kmalloc_node);
75694 #endif
75695
75696 +bool is_usercopy_object(const void *ptr)
75697 +{
75698 + struct page *page;
75699 + struct kmem_cache *s;
75700 +
75701 + if (ZERO_OR_NULL_PTR(ptr))
75702 + return false;
75703 +
75704 + if (!slab_is_available())
75705 + return false;
75706 +
75707 + if (!virt_addr_valid(ptr))
75708 + return false;
75709 +
75710 + page = virt_to_head_page(ptr);
75711 +
75712 + if (!PageSlab(page))
75713 + return false;
75714 +
75715 + s = page->slab;
75716 + return s->flags & SLAB_USERCOPY;
75717 +}
75718 +
75719 +#ifdef CONFIG_PAX_USERCOPY
75720 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75721 +{
75722 + struct page *page;
75723 + struct kmem_cache *s;
75724 + unsigned long offset;
75725 +
75726 + if (ZERO_OR_NULL_PTR(ptr))
75727 + return "<null>";
75728 +
75729 + if (!virt_addr_valid(ptr))
75730 + return NULL;
75731 +
75732 + page = virt_to_head_page(ptr);
75733 +
75734 + if (!PageSlab(page))
75735 + return NULL;
75736 +
75737 + s = page->slab;
75738 + if (!(s->flags & SLAB_USERCOPY))
75739 + return s->name;
75740 +
75741 + offset = (ptr - page_address(page)) % s->size;
75742 + if (offset <= s->object_size && n <= s->object_size - offset)
75743 + return NULL;
75744 +
75745 + return s->name;
75746 +}
75747 +#endif
75748 +
75749 size_t ksize(const void *object)
75750 {
75751 struct page *page;
75752 @@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75753 int node;
75754
75755 list_add(&s->list, &slab_caches);
75756 - s->refcount = -1;
75757 + atomic_set(&s->refcount, -1);
75758
75759 for_each_node_state(node, N_NORMAL_MEMORY) {
75760 struct kmem_cache_node *n = get_node(s, node);
75761 @@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
75762
75763 /* Caches that are not of the two-to-the-power-of size */
75764 if (KMALLOC_MIN_SIZE <= 32) {
75765 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75766 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75767 caches++;
75768 }
75769
75770 if (KMALLOC_MIN_SIZE <= 64) {
75771 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75772 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75773 caches++;
75774 }
75775
75776 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75777 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75778 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75779 caches++;
75780 }
75781
75782 @@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
75783 }
75784 }
75785 #endif
75786 +
75787 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75788 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75789 + struct kmem_cache *s = kmalloc_caches[i];
75790 +
75791 + if (s && s->size) {
75792 + char *name = kasprintf(GFP_NOWAIT,
75793 + "usercopy-kmalloc-%d", s->object_size);
75794 +
75795 + BUG_ON(!name);
75796 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75797 + s->object_size, SLAB_USERCOPY);
75798 + }
75799 + }
75800 +#endif
75801 +
75802 printk(KERN_INFO
75803 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75804 " CPUs=%d, Nodes=%d\n",
75805 @@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75806 /*
75807 * We may have set a slab to be unmergeable during bootstrap.
75808 */
75809 - if (s->refcount < 0)
75810 + if (atomic_read(&s->refcount) < 0)
75811 return 1;
75812
75813 return 0;
75814 @@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
75815
75816 s = find_mergeable(size, align, flags, name, ctor);
75817 if (s) {
75818 - s->refcount++;
75819 + atomic_inc(&s->refcount);
75820 /*
75821 * Adjust the object sizes so that we clear
75822 * the complete object on kzalloc.
75823 @@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
75824 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75825
75826 if (sysfs_slab_alias(s, name)) {
75827 - s->refcount--;
75828 + atomic_dec(&s->refcount);
75829 s = NULL;
75830 }
75831 }
75832 @@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75833 }
75834 #endif
75835
75836 -#ifdef CONFIG_SYSFS
75837 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75838 static int count_inuse(struct page *page)
75839 {
75840 return page->inuse;
75841 @@ -4450,12 +4532,12 @@ static void resiliency_test(void)
75842 validate_slab_cache(kmalloc_caches[9]);
75843 }
75844 #else
75845 -#ifdef CONFIG_SYSFS
75846 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75847 static void resiliency_test(void) {};
75848 #endif
75849 #endif
75850
75851 -#ifdef CONFIG_SYSFS
75852 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75853 enum slab_stat_type {
75854 SL_ALL, /* All slabs */
75855 SL_PARTIAL, /* Only partially allocated slabs */
75856 @@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
75857
75858 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75859 {
75860 - return sprintf(buf, "%d\n", s->refcount - 1);
75861 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75862 }
75863 SLAB_ATTR_RO(aliases);
75864
75865 @@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
75866 return name;
75867 }
75868
75869 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75870 static int sysfs_slab_add(struct kmem_cache *s)
75871 {
75872 int err;
75873 @@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75874 kobject_del(&s->kobj);
75875 kobject_put(&s->kobj);
75876 }
75877 +#endif
75878
75879 /*
75880 * Need to buffer aliases during bootup until sysfs becomes
75881 @@ -5336,6 +5420,7 @@ struct saved_alias {
75882
75883 static struct saved_alias *alias_list;
75884
75885 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75886 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75887 {
75888 struct saved_alias *al;
75889 @@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75890 alias_list = al;
75891 return 0;
75892 }
75893 +#endif
75894
75895 static int __init slab_sysfs_init(void)
75896 {
75897 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75898 index 1b7e22a..3fcd4f3 100644
75899 --- a/mm/sparse-vmemmap.c
75900 +++ b/mm/sparse-vmemmap.c
75901 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75902 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75903 if (!p)
75904 return NULL;
75905 - pud_populate(&init_mm, pud, p);
75906 + pud_populate_kernel(&init_mm, pud, p);
75907 }
75908 return pud;
75909 }
75910 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75911 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75912 if (!p)
75913 return NULL;
75914 - pgd_populate(&init_mm, pgd, p);
75915 + pgd_populate_kernel(&init_mm, pgd, p);
75916 }
75917 return pgd;
75918 }
75919 diff --git a/mm/swap.c b/mm/swap.c
75920 index 6310dc2..3662b3f 100644
75921 --- a/mm/swap.c
75922 +++ b/mm/swap.c
75923 @@ -30,6 +30,7 @@
75924 #include <linux/backing-dev.h>
75925 #include <linux/memcontrol.h>
75926 #include <linux/gfp.h>
75927 +#include <linux/hugetlb.h>
75928
75929 #include "internal.h"
75930
75931 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75932
75933 __page_cache_release(page);
75934 dtor = get_compound_page_dtor(page);
75935 + if (!PageHuge(page))
75936 + BUG_ON(dtor != free_compound_page);
75937 (*dtor)(page);
75938 }
75939
75940 diff --git a/mm/swapfile.c b/mm/swapfile.c
75941 index f91a255..9dcac21 100644
75942 --- a/mm/swapfile.c
75943 +++ b/mm/swapfile.c
75944 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75945
75946 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75947 /* Activity counter to indicate that a swapon or swapoff has occurred */
75948 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75949 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75950
75951 static inline unsigned char swap_count(unsigned char ent)
75952 {
75953 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75954 }
75955 filp_close(swap_file, NULL);
75956 err = 0;
75957 - atomic_inc(&proc_poll_event);
75958 + atomic_inc_unchecked(&proc_poll_event);
75959 wake_up_interruptible(&proc_poll_wait);
75960
75961 out_dput:
75962 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75963
75964 poll_wait(file, &proc_poll_wait, wait);
75965
75966 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75967 - seq->poll_event = atomic_read(&proc_poll_event);
75968 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75969 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75970 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75971 }
75972
75973 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75974 return ret;
75975
75976 seq = file->private_data;
75977 - seq->poll_event = atomic_read(&proc_poll_event);
75978 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75979 return 0;
75980 }
75981
75982 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75983 (frontswap_map) ? "FS" : "");
75984
75985 mutex_unlock(&swapon_mutex);
75986 - atomic_inc(&proc_poll_event);
75987 + atomic_inc_unchecked(&proc_poll_event);
75988 wake_up_interruptible(&proc_poll_wait);
75989
75990 if (S_ISREG(inode->i_mode))
75991 diff --git a/mm/util.c b/mm/util.c
75992 index dc3036c..b6c7c9d 100644
75993 --- a/mm/util.c
75994 +++ b/mm/util.c
75995 @@ -292,6 +292,12 @@ done:
75996 void arch_pick_mmap_layout(struct mm_struct *mm)
75997 {
75998 mm->mmap_base = TASK_UNMAPPED_BASE;
75999 +
76000 +#ifdef CONFIG_PAX_RANDMMAP
76001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76002 + mm->mmap_base += mm->delta_mmap;
76003 +#endif
76004 +
76005 mm->get_unmapped_area = arch_get_unmapped_area;
76006 mm->unmap_area = arch_unmap_area;
76007 }
76008 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76009 index 78e0830..8bfb8bd 100644
76010 --- a/mm/vmalloc.c
76011 +++ b/mm/vmalloc.c
76012 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76013
76014 pte = pte_offset_kernel(pmd, addr);
76015 do {
76016 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76017 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76018 +
76019 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76020 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76021 + BUG_ON(!pte_exec(*pte));
76022 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76023 + continue;
76024 + }
76025 +#endif
76026 +
76027 + {
76028 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76029 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76030 + }
76031 } while (pte++, addr += PAGE_SIZE, addr != end);
76032 }
76033
76034 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76035 pte = pte_alloc_kernel(pmd, addr);
76036 if (!pte)
76037 return -ENOMEM;
76038 +
76039 + pax_open_kernel();
76040 do {
76041 struct page *page = pages[*nr];
76042
76043 - if (WARN_ON(!pte_none(*pte)))
76044 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76045 + if (pgprot_val(prot) & _PAGE_NX)
76046 +#endif
76047 +
76048 + if (!pte_none(*pte)) {
76049 + pax_close_kernel();
76050 + WARN_ON(1);
76051 return -EBUSY;
76052 - if (WARN_ON(!page))
76053 + }
76054 + if (!page) {
76055 + pax_close_kernel();
76056 + WARN_ON(1);
76057 return -ENOMEM;
76058 + }
76059 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76060 (*nr)++;
76061 } while (pte++, addr += PAGE_SIZE, addr != end);
76062 + pax_close_kernel();
76063 return 0;
76064 }
76065
76066 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76067 pmd_t *pmd;
76068 unsigned long next;
76069
76070 - pmd = pmd_alloc(&init_mm, pud, addr);
76071 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76072 if (!pmd)
76073 return -ENOMEM;
76074 do {
76075 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76076 pud_t *pud;
76077 unsigned long next;
76078
76079 - pud = pud_alloc(&init_mm, pgd, addr);
76080 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76081 if (!pud)
76082 return -ENOMEM;
76083 do {
76084 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76085 * and fall back on vmalloc() if that fails. Others
76086 * just put it in the vmalloc space.
76087 */
76088 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76089 +#ifdef CONFIG_MODULES
76090 +#ifdef MODULES_VADDR
76091 unsigned long addr = (unsigned long)x;
76092 if (addr >= MODULES_VADDR && addr < MODULES_END)
76093 return 1;
76094 #endif
76095 +
76096 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76097 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76098 + return 1;
76099 +#endif
76100 +
76101 +#endif
76102 +
76103 return is_vmalloc_addr(x);
76104 }
76105
76106 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76107
76108 if (!pgd_none(*pgd)) {
76109 pud_t *pud = pud_offset(pgd, addr);
76110 +#ifdef CONFIG_X86
76111 + if (!pud_large(*pud))
76112 +#endif
76113 if (!pud_none(*pud)) {
76114 pmd_t *pmd = pmd_offset(pud, addr);
76115 +#ifdef CONFIG_X86
76116 + if (!pmd_large(*pmd))
76117 +#endif
76118 if (!pmd_none(*pmd)) {
76119 pte_t *ptep, pte;
76120
76121 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76122 * Allocate a region of KVA of the specified size and alignment, within the
76123 * vstart and vend.
76124 */
76125 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76126 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76127 unsigned long align,
76128 unsigned long vstart, unsigned long vend,
76129 int node, gfp_t gfp_mask)
76130 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76131 struct vm_struct *area;
76132
76133 BUG_ON(in_interrupt());
76134 +
76135 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76136 + if (flags & VM_KERNEXEC) {
76137 + if (start != VMALLOC_START || end != VMALLOC_END)
76138 + return NULL;
76139 + start = (unsigned long)MODULES_EXEC_VADDR;
76140 + end = (unsigned long)MODULES_EXEC_END;
76141 + }
76142 +#endif
76143 +
76144 if (flags & VM_IOREMAP) {
76145 int bit = fls(size);
76146
76147 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76148 if (count > totalram_pages)
76149 return NULL;
76150
76151 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76152 + if (!(pgprot_val(prot) & _PAGE_NX))
76153 + flags |= VM_KERNEXEC;
76154 +#endif
76155 +
76156 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76157 __builtin_return_address(0));
76158 if (!area)
76159 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76160 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76161 goto fail;
76162
76163 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76164 + if (!(pgprot_val(prot) & _PAGE_NX))
76165 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76166 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76167 + else
76168 +#endif
76169 +
76170 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76171 start, end, node, gfp_mask, caller);
76172 if (!area)
76173 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76174 * For tight control over page level allocator and protection flags
76175 * use __vmalloc() instead.
76176 */
76177 -
76178 void *vmalloc_exec(unsigned long size)
76179 {
76180 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76181 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76182 -1, __builtin_return_address(0));
76183 }
76184
76185 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76186 unsigned long uaddr = vma->vm_start;
76187 unsigned long usize = vma->vm_end - vma->vm_start;
76188
76189 + BUG_ON(vma->vm_mirror);
76190 +
76191 if ((PAGE_SIZE-1) & (unsigned long)addr)
76192 return -EINVAL;
76193
76194 diff --git a/mm/vmstat.c b/mm/vmstat.c
76195 index c737057..a49753a 100644
76196 --- a/mm/vmstat.c
76197 +++ b/mm/vmstat.c
76198 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76199 *
76200 * vm_stat contains the global counters
76201 */
76202 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76203 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76204 EXPORT_SYMBOL(vm_stat);
76205
76206 #ifdef CONFIG_SMP
76207 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76208 v = p->vm_stat_diff[i];
76209 p->vm_stat_diff[i] = 0;
76210 local_irq_restore(flags);
76211 - atomic_long_add(v, &zone->vm_stat[i]);
76212 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76213 global_diff[i] += v;
76214 #ifdef CONFIG_NUMA
76215 /* 3 seconds idle till flush */
76216 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76217
76218 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76219 if (global_diff[i])
76220 - atomic_long_add(global_diff[i], &vm_stat[i]);
76221 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76222 }
76223
76224 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
76225 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
76226 if (pset->vm_stat_diff[i]) {
76227 int v = pset->vm_stat_diff[i];
76228 pset->vm_stat_diff[i] = 0;
76229 - atomic_long_add(v, &zone->vm_stat[i]);
76230 - atomic_long_add(v, &vm_stat[i]);
76231 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76232 + atomic_long_add_unchecked(v, &vm_stat[i]);
76233 }
76234 }
76235 #endif
76236 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
76237 start_cpu_timer(cpu);
76238 #endif
76239 #ifdef CONFIG_PROC_FS
76240 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76241 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76242 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76243 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76244 + {
76245 + mode_t gr_mode = S_IRUGO;
76246 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76247 + gr_mode = S_IRUSR;
76248 +#endif
76249 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76250 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76251 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76252 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76253 +#else
76254 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76255 +#endif
76256 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76257 + }
76258 #endif
76259 return 0;
76260 }
76261 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76262 index ee07072..e280bfa 100644
76263 --- a/net/8021q/vlan.c
76264 +++ b/net/8021q/vlan.c
76265 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76266 err = -EPERM;
76267 if (!capable(CAP_NET_ADMIN))
76268 break;
76269 - if ((args.u.name_type >= 0) &&
76270 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76271 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76272 struct vlan_net *vn;
76273
76274 vn = net_generic(net, vlan_net_id);
76275 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76276 index 02efb25..41541a9 100644
76277 --- a/net/9p/trans_fd.c
76278 +++ b/net/9p/trans_fd.c
76279 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76280 oldfs = get_fs();
76281 set_fs(get_ds());
76282 /* The cast to a user pointer is valid due to the set_fs() */
76283 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76284 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76285 set_fs(oldfs);
76286
76287 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76288 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76289 index 876fbe8..8bbea9f 100644
76290 --- a/net/atm/atm_misc.c
76291 +++ b/net/atm/atm_misc.c
76292 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76293 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76294 return 1;
76295 atm_return(vcc, truesize);
76296 - atomic_inc(&vcc->stats->rx_drop);
76297 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76298 return 0;
76299 }
76300 EXPORT_SYMBOL(atm_charge);
76301 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76302 }
76303 }
76304 atm_return(vcc, guess);
76305 - atomic_inc(&vcc->stats->rx_drop);
76306 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76307 return NULL;
76308 }
76309 EXPORT_SYMBOL(atm_alloc_charge);
76310 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76311
76312 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76313 {
76314 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76315 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76316 __SONET_ITEMS
76317 #undef __HANDLE_ITEM
76318 }
76319 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76320
76321 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76322 {
76323 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76324 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76325 __SONET_ITEMS
76326 #undef __HANDLE_ITEM
76327 }
76328 diff --git a/net/atm/lec.h b/net/atm/lec.h
76329 index a86aff9..3a0d6f6 100644
76330 --- a/net/atm/lec.h
76331 +++ b/net/atm/lec.h
76332 @@ -48,7 +48,7 @@ struct lane2_ops {
76333 const u8 *tlvs, u32 sizeoftlvs);
76334 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76335 const u8 *tlvs, u32 sizeoftlvs);
76336 -};
76337 +} __no_const;
76338
76339 /*
76340 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76341 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76342 index 0919a88..a23d54e 100644
76343 --- a/net/atm/mpc.h
76344 +++ b/net/atm/mpc.h
76345 @@ -33,7 +33,7 @@ struct mpoa_client {
76346 struct mpc_parameters parameters; /* parameters for this client */
76347
76348 const struct net_device_ops *old_ops;
76349 - struct net_device_ops new_ops;
76350 + net_device_ops_no_const new_ops;
76351 };
76352
76353
76354 diff --git a/net/atm/proc.c b/net/atm/proc.c
76355 index 0d020de..011c7bb 100644
76356 --- a/net/atm/proc.c
76357 +++ b/net/atm/proc.c
76358 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76359 const struct k_atm_aal_stats *stats)
76360 {
76361 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76362 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76363 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76364 - atomic_read(&stats->rx_drop));
76365 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76366 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76367 + atomic_read_unchecked(&stats->rx_drop));
76368 }
76369
76370 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76371 diff --git a/net/atm/resources.c b/net/atm/resources.c
76372 index 0447d5d..3cf4728 100644
76373 --- a/net/atm/resources.c
76374 +++ b/net/atm/resources.c
76375 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76376 static void copy_aal_stats(struct k_atm_aal_stats *from,
76377 struct atm_aal_stats *to)
76378 {
76379 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76380 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76381 __AAL_STAT_ITEMS
76382 #undef __HANDLE_ITEM
76383 }
76384 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76385 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76386 struct atm_aal_stats *to)
76387 {
76388 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76389 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76390 __AAL_STAT_ITEMS
76391 #undef __HANDLE_ITEM
76392 }
76393 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76394 index b02b75d..0a9636e 100644
76395 --- a/net/batman-adv/bat_iv_ogm.c
76396 +++ b/net/batman-adv/bat_iv_ogm.c
76397 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76398
76399 /* randomize initial seqno to avoid collision */
76400 get_random_bytes(&random_seqno, sizeof(random_seqno));
76401 - atomic_set(&hard_iface->seqno, random_seqno);
76402 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76403
76404 hard_iface->packet_len = BATADV_OGM_HLEN;
76405 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76406 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76407 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
76408
76409 /* change sequence number to network order */
76410 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
76411 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
76412 batadv_ogm_packet->seqno = htonl(seqno);
76413 - atomic_inc(&hard_iface->seqno);
76414 + atomic_inc_unchecked(&hard_iface->seqno);
76415
76416 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
76417 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
76418 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76419 return;
76420
76421 /* could be changed by schedule_own_packet() */
76422 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76423 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76424
76425 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76426 has_directlink_flag = 1;
76427 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76428 index d112fd6..686a447 100644
76429 --- a/net/batman-adv/hard-interface.c
76430 +++ b/net/batman-adv/hard-interface.c
76431 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76432 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76433 dev_add_pack(&hard_iface->batman_adv_ptype);
76434
76435 - atomic_set(&hard_iface->frag_seqno, 1);
76436 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76437 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76438 hard_iface->net_dev->name);
76439
76440 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76441 /* This can't be called via a bat_priv callback because
76442 * we have no bat_priv yet.
76443 */
76444 - atomic_set(&hard_iface->seqno, 1);
76445 + atomic_set_unchecked(&hard_iface->seqno, 1);
76446 hard_iface->packet_buff = NULL;
76447
76448 return hard_iface;
76449 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76450 index ce0684a..4a0cbf1 100644
76451 --- a/net/batman-adv/soft-interface.c
76452 +++ b/net/batman-adv/soft-interface.c
76453 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76454 primary_if->net_dev->dev_addr, ETH_ALEN);
76455
76456 /* set broadcast sequence number */
76457 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
76458 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
76459 bcast_packet->seqno = htonl(seqno);
76460
76461 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76462 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
76463 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76464
76465 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76466 - atomic_set(&bat_priv->bcast_seqno, 1);
76467 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76468 atomic_set(&bat_priv->tt.vn, 0);
76469 atomic_set(&bat_priv->tt.local_changes, 0);
76470 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
76471 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76472 index ac1e07a..4c846e2 100644
76473 --- a/net/batman-adv/types.h
76474 +++ b/net/batman-adv/types.h
76475 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76476 int16_t if_num;
76477 char if_status;
76478 struct net_device *net_dev;
76479 - atomic_t seqno;
76480 - atomic_t frag_seqno;
76481 + atomic_unchecked_t seqno;
76482 + atomic_unchecked_t frag_seqno;
76483 unsigned char *packet_buff;
76484 int packet_len;
76485 struct kobject *hardif_obj;
76486 @@ -244,7 +244,7 @@ struct batadv_priv {
76487 atomic_t orig_interval; /* uint */
76488 atomic_t hop_penalty; /* uint */
76489 atomic_t log_level; /* uint */
76490 - atomic_t bcast_seqno;
76491 + atomic_unchecked_t bcast_seqno;
76492 atomic_t bcast_queue_left;
76493 atomic_t batman_queue_left;
76494 char num_ifaces;
76495 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76496 index f397232..3206a33 100644
76497 --- a/net/batman-adv/unicast.c
76498 +++ b/net/batman-adv/unicast.c
76499 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76500 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76501 frag2->flags = large_tail;
76502
76503 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76504 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76505 frag1->seqno = htons(seqno - 1);
76506 frag2->seqno = htons(seqno);
76507
76508 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76509 index 07f0739..3c42e34 100644
76510 --- a/net/bluetooth/hci_sock.c
76511 +++ b/net/bluetooth/hci_sock.c
76512 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76513 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76514 }
76515
76516 - len = min_t(unsigned int, len, sizeof(uf));
76517 + len = min((size_t)len, sizeof(uf));
76518 if (copy_from_user(&uf, optval, len)) {
76519 err = -EFAULT;
76520 break;
76521 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76522 index a91239d..d7ed533 100644
76523 --- a/net/bluetooth/l2cap_core.c
76524 +++ b/net/bluetooth/l2cap_core.c
76525 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76526 break;
76527
76528 case L2CAP_CONF_RFC:
76529 - if (olen == sizeof(rfc))
76530 - memcpy(&rfc, (void *)val, olen);
76531 + if (olen != sizeof(rfc))
76532 + break;
76533 +
76534 + memcpy(&rfc, (void *)val, olen);
76535
76536 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76537 rfc.mode != chan->mode)
76538 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76539 index 083f2bf..799f9448 100644
76540 --- a/net/bluetooth/l2cap_sock.c
76541 +++ b/net/bluetooth/l2cap_sock.c
76542 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76543 struct sock *sk = sock->sk;
76544 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76545 struct l2cap_options opts;
76546 - int len, err = 0;
76547 + int err = 0;
76548 + size_t len = optlen;
76549 u32 opt;
76550
76551 BT_DBG("sk %p", sk);
76552 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76553 opts.max_tx = chan->max_tx;
76554 opts.txwin_size = chan->tx_win;
76555
76556 - len = min_t(unsigned int, sizeof(opts), optlen);
76557 + len = min(sizeof(opts), len);
76558 if (copy_from_user((char *) &opts, optval, len)) {
76559 err = -EFAULT;
76560 break;
76561 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76562 struct bt_security sec;
76563 struct bt_power pwr;
76564 struct l2cap_conn *conn;
76565 - int len, err = 0;
76566 + int err = 0;
76567 + size_t len = optlen;
76568 u32 opt;
76569
76570 BT_DBG("sk %p", sk);
76571 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76572
76573 sec.level = BT_SECURITY_LOW;
76574
76575 - len = min_t(unsigned int, sizeof(sec), optlen);
76576 + len = min(sizeof(sec), len);
76577 if (copy_from_user((char *) &sec, optval, len)) {
76578 err = -EFAULT;
76579 break;
76580 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76581
76582 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76583
76584 - len = min_t(unsigned int, sizeof(pwr), optlen);
76585 + len = min(sizeof(pwr), len);
76586 if (copy_from_user((char *) &pwr, optval, len)) {
76587 err = -EFAULT;
76588 break;
76589 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76590 index b3226f3..8916f43 100644
76591 --- a/net/bluetooth/rfcomm/sock.c
76592 +++ b/net/bluetooth/rfcomm/sock.c
76593 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76594 struct sock *sk = sock->sk;
76595 struct bt_security sec;
76596 int err = 0;
76597 - size_t len;
76598 + size_t len = optlen;
76599 u32 opt;
76600
76601 BT_DBG("sk %p", sk);
76602 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76603
76604 sec.level = BT_SECURITY_LOW;
76605
76606 - len = min_t(unsigned int, sizeof(sec), optlen);
76607 + len = min(sizeof(sec), len);
76608 if (copy_from_user((char *) &sec, optval, len)) {
76609 err = -EFAULT;
76610 break;
76611 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76612 index ccc2487..921073d 100644
76613 --- a/net/bluetooth/rfcomm/tty.c
76614 +++ b/net/bluetooth/rfcomm/tty.c
76615 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76616 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76617
76618 spin_lock_irqsave(&dev->port.lock, flags);
76619 - if (dev->port.count > 0) {
76620 + if (atomic_read(&dev->port.count) > 0) {
76621 spin_unlock_irqrestore(&dev->port.lock, flags);
76622 return;
76623 }
76624 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76625 return -ENODEV;
76626
76627 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76628 - dev->channel, dev->port.count);
76629 + dev->channel, atomic_read(&dev->port.count));
76630
76631 spin_lock_irqsave(&dev->port.lock, flags);
76632 - if (++dev->port.count > 1) {
76633 + if (atomic_inc_return(&dev->port.count) > 1) {
76634 spin_unlock_irqrestore(&dev->port.lock, flags);
76635 return 0;
76636 }
76637 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76638 return;
76639
76640 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76641 - dev->port.count);
76642 + atomic_read(&dev->port.count));
76643
76644 spin_lock_irqsave(&dev->port.lock, flags);
76645 - if (!--dev->port.count) {
76646 + if (!atomic_dec_return(&dev->port.count)) {
76647 spin_unlock_irqrestore(&dev->port.lock, flags);
76648 if (dev->tty_dev->parent)
76649 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76650 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76651 index 5fe2ff3..121d696 100644
76652 --- a/net/bridge/netfilter/ebtables.c
76653 +++ b/net/bridge/netfilter/ebtables.c
76654 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76655 tmp.valid_hooks = t->table->valid_hooks;
76656 }
76657 mutex_unlock(&ebt_mutex);
76658 - if (copy_to_user(user, &tmp, *len) != 0){
76659 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76660 BUGPRINT("c2u Didn't work\n");
76661 ret = -EFAULT;
76662 break;
76663 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76664 goto out;
76665 tmp.valid_hooks = t->valid_hooks;
76666
76667 - if (copy_to_user(user, &tmp, *len) != 0) {
76668 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76669 ret = -EFAULT;
76670 break;
76671 }
76672 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76673 tmp.entries_size = t->table->entries_size;
76674 tmp.valid_hooks = t->table->valid_hooks;
76675
76676 - if (copy_to_user(user, &tmp, *len) != 0) {
76677 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76678 ret = -EFAULT;
76679 break;
76680 }
76681 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76682 index 44f270f..1f5602d 100644
76683 --- a/net/caif/cfctrl.c
76684 +++ b/net/caif/cfctrl.c
76685 @@ -10,6 +10,7 @@
76686 #include <linux/spinlock.h>
76687 #include <linux/slab.h>
76688 #include <linux/pkt_sched.h>
76689 +#include <linux/sched.h>
76690 #include <net/caif/caif_layer.h>
76691 #include <net/caif/cfpkt.h>
76692 #include <net/caif/cfctrl.h>
76693 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76694 memset(&dev_info, 0, sizeof(dev_info));
76695 dev_info.id = 0xff;
76696 cfsrvl_init(&this->serv, 0, &dev_info, false);
76697 - atomic_set(&this->req_seq_no, 1);
76698 - atomic_set(&this->rsp_seq_no, 1);
76699 + atomic_set_unchecked(&this->req_seq_no, 1);
76700 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76701 this->serv.layer.receive = cfctrl_recv;
76702 sprintf(this->serv.layer.name, "ctrl");
76703 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76704 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76705 struct cfctrl_request_info *req)
76706 {
76707 spin_lock_bh(&ctrl->info_list_lock);
76708 - atomic_inc(&ctrl->req_seq_no);
76709 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76710 + atomic_inc_unchecked(&ctrl->req_seq_no);
76711 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76712 list_add_tail(&req->list, &ctrl->list);
76713 spin_unlock_bh(&ctrl->info_list_lock);
76714 }
76715 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76716 if (p != first)
76717 pr_warn("Requests are not received in order\n");
76718
76719 - atomic_set(&ctrl->rsp_seq_no,
76720 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76721 p->sequence_no);
76722 list_del(&p->list);
76723 goto out;
76724 diff --git a/net/can/gw.c b/net/can/gw.c
76725 index 1f5c978..522e050 100644
76726 --- a/net/can/gw.c
76727 +++ b/net/can/gw.c
76728 @@ -96,7 +96,7 @@ struct cf_mod {
76729 struct {
76730 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76731 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76732 - } csumfunc;
76733 + } __no_const csumfunc;
76734 };
76735
76736
76737 diff --git a/net/compat.c b/net/compat.c
76738 index 79ae884..17c5c09 100644
76739 --- a/net/compat.c
76740 +++ b/net/compat.c
76741 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76742 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76743 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76744 return -EFAULT;
76745 - kmsg->msg_name = compat_ptr(tmp1);
76746 - kmsg->msg_iov = compat_ptr(tmp2);
76747 - kmsg->msg_control = compat_ptr(tmp3);
76748 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76749 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76750 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76751 return 0;
76752 }
76753
76754 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76755
76756 if (kern_msg->msg_namelen) {
76757 if (mode == VERIFY_READ) {
76758 - int err = move_addr_to_kernel(kern_msg->msg_name,
76759 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76760 kern_msg->msg_namelen,
76761 kern_address);
76762 if (err < 0)
76763 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76764 kern_msg->msg_name = NULL;
76765
76766 tot_len = iov_from_user_compat_to_kern(kern_iov,
76767 - (struct compat_iovec __user *)kern_msg->msg_iov,
76768 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76769 kern_msg->msg_iovlen);
76770 if (tot_len >= 0)
76771 kern_msg->msg_iov = kern_iov;
76772 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76773
76774 #define CMSG_COMPAT_FIRSTHDR(msg) \
76775 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76776 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76777 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76778 (struct compat_cmsghdr __user *)NULL)
76779
76780 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76781 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76782 (ucmlen) <= (unsigned long) \
76783 ((mhdr)->msg_controllen - \
76784 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76785 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76786
76787 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76788 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76789 {
76790 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76791 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76792 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76793 msg->msg_controllen)
76794 return NULL;
76795 return (struct compat_cmsghdr __user *)ptr;
76796 @@ -219,7 +219,7 @@ Efault:
76797
76798 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76799 {
76800 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76801 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76802 struct compat_cmsghdr cmhdr;
76803 struct compat_timeval ctv;
76804 struct compat_timespec cts[3];
76805 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76806
76807 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76808 {
76809 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76810 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76811 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76812 int fdnum = scm->fp->count;
76813 struct file **fp = scm->fp->fp;
76814 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76815 return -EFAULT;
76816 old_fs = get_fs();
76817 set_fs(KERNEL_DS);
76818 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76819 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76820 set_fs(old_fs);
76821
76822 return err;
76823 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76824 len = sizeof(ktime);
76825 old_fs = get_fs();
76826 set_fs(KERNEL_DS);
76827 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76828 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76829 set_fs(old_fs);
76830
76831 if (!err) {
76832 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76833 case MCAST_JOIN_GROUP:
76834 case MCAST_LEAVE_GROUP:
76835 {
76836 - struct compat_group_req __user *gr32 = (void *)optval;
76837 + struct compat_group_req __user *gr32 = (void __user *)optval;
76838 struct group_req __user *kgr =
76839 compat_alloc_user_space(sizeof(struct group_req));
76840 u32 interface;
76841 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76842 case MCAST_BLOCK_SOURCE:
76843 case MCAST_UNBLOCK_SOURCE:
76844 {
76845 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76846 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76847 struct group_source_req __user *kgsr = compat_alloc_user_space(
76848 sizeof(struct group_source_req));
76849 u32 interface;
76850 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76851 }
76852 case MCAST_MSFILTER:
76853 {
76854 - struct compat_group_filter __user *gf32 = (void *)optval;
76855 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76856 struct group_filter __user *kgf;
76857 u32 interface, fmode, numsrc;
76858
76859 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76860 char __user *optval, int __user *optlen,
76861 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76862 {
76863 - struct compat_group_filter __user *gf32 = (void *)optval;
76864 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76865 struct group_filter __user *kgf;
76866 int __user *koptlen;
76867 u32 interface, fmode, numsrc;
76868 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76869
76870 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76871 return -EINVAL;
76872 - if (copy_from_user(a, args, nas[call]))
76873 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76874 return -EFAULT;
76875 a0 = a[0];
76876 a1 = a[1];
76877 diff --git a/net/core/datagram.c b/net/core/datagram.c
76878 index 0337e2b..47914a0 100644
76879 --- a/net/core/datagram.c
76880 +++ b/net/core/datagram.c
76881 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76882 }
76883
76884 kfree_skb(skb);
76885 - atomic_inc(&sk->sk_drops);
76886 + atomic_inc_unchecked(&sk->sk_drops);
76887 sk_mem_reclaim_partial(sk);
76888
76889 return err;
76890 diff --git a/net/core/dev.c b/net/core/dev.c
76891 index e5942bf..25998c3 100644
76892 --- a/net/core/dev.c
76893 +++ b/net/core/dev.c
76894 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
76895 if (no_module && capable(CAP_NET_ADMIN))
76896 no_module = request_module("netdev-%s", name);
76897 if (no_module && capable(CAP_SYS_MODULE)) {
76898 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76899 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76900 +#else
76901 if (!request_module("%s", name))
76902 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76903 name);
76904 +#endif
76905 }
76906 }
76907 EXPORT_SYMBOL(dev_load);
76908 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76909 {
76910 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76911 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76912 - atomic_long_inc(&dev->rx_dropped);
76913 + atomic_long_inc_unchecked(&dev->rx_dropped);
76914 kfree_skb(skb);
76915 return NET_RX_DROP;
76916 }
76917 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76918 nf_reset(skb);
76919
76920 if (unlikely(!is_skb_forwardable(dev, skb))) {
76921 - atomic_long_inc(&dev->rx_dropped);
76922 + atomic_long_inc_unchecked(&dev->rx_dropped);
76923 kfree_skb(skb);
76924 return NET_RX_DROP;
76925 }
76926 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76927
76928 struct dev_gso_cb {
76929 void (*destructor)(struct sk_buff *skb);
76930 -};
76931 +} __no_const;
76932
76933 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76934
76935 @@ -2955,7 +2959,7 @@ enqueue:
76936
76937 local_irq_restore(flags);
76938
76939 - atomic_long_inc(&skb->dev->rx_dropped);
76940 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76941 kfree_skb(skb);
76942 return NET_RX_DROP;
76943 }
76944 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
76945 }
76946 EXPORT_SYMBOL(netif_rx_ni);
76947
76948 -static void net_tx_action(struct softirq_action *h)
76949 +static void net_tx_action(void)
76950 {
76951 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76952
76953 @@ -3358,7 +3362,7 @@ ncls:
76954 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76955 } else {
76956 drop:
76957 - atomic_long_inc(&skb->dev->rx_dropped);
76958 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76959 kfree_skb(skb);
76960 /* Jamal, now you will not able to escape explaining
76961 * me how you were going to use this. :-)
76962 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
76963 }
76964 EXPORT_SYMBOL(netif_napi_del);
76965
76966 -static void net_rx_action(struct softirq_action *h)
76967 +static void net_rx_action(void)
76968 {
76969 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76970 unsigned long time_limit = jiffies + 2;
76971 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76972 else
76973 seq_printf(seq, "%04x", ntohs(pt->type));
76974
76975 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76976 + seq_printf(seq, " %-8s %p\n",
76977 + pt->dev ? pt->dev->name : "", NULL);
76978 +#else
76979 seq_printf(seq, " %-8s %pF\n",
76980 pt->dev ? pt->dev->name : "", pt->func);
76981 +#endif
76982 }
76983
76984 return 0;
76985 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76986 } else {
76987 netdev_stats_to_stats64(storage, &dev->stats);
76988 }
76989 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76990 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76991 return storage;
76992 }
76993 EXPORT_SYMBOL(dev_get_stats);
76994 diff --git a/net/core/flow.c b/net/core/flow.c
76995 index e318c7e..168b1d0 100644
76996 --- a/net/core/flow.c
76997 +++ b/net/core/flow.c
76998 @@ -61,7 +61,7 @@ struct flow_cache {
76999 struct timer_list rnd_timer;
77000 };
77001
77002 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
77003 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77004 EXPORT_SYMBOL(flow_cache_genid);
77005 static struct flow_cache flow_cache_global;
77006 static struct kmem_cache *flow_cachep __read_mostly;
77007 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77008
77009 static int flow_entry_valid(struct flow_cache_entry *fle)
77010 {
77011 - if (atomic_read(&flow_cache_genid) != fle->genid)
77012 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77013 return 0;
77014 if (fle->object && !fle->object->ops->check(fle->object))
77015 return 0;
77016 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77017 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77018 fcp->hash_count++;
77019 }
77020 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77021 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77022 flo = fle->object;
77023 if (!flo)
77024 goto ret_object;
77025 @@ -280,7 +280,7 @@ nocache:
77026 }
77027 flo = resolver(net, key, family, dir, flo, ctx);
77028 if (fle) {
77029 - fle->genid = atomic_read(&flow_cache_genid);
77030 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
77031 if (!IS_ERR(flo))
77032 fle->object = flo;
77033 else
77034 diff --git a/net/core/iovec.c b/net/core/iovec.c
77035 index 7e7aeb0..2a998cb 100644
77036 --- a/net/core/iovec.c
77037 +++ b/net/core/iovec.c
77038 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77039 if (m->msg_namelen) {
77040 if (mode == VERIFY_READ) {
77041 void __user *namep;
77042 - namep = (void __user __force *) m->msg_name;
77043 + namep = (void __force_user *) m->msg_name;
77044 err = move_addr_to_kernel(namep, m->msg_namelen,
77045 address);
77046 if (err < 0)
77047 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77048 }
77049
77050 size = m->msg_iovlen * sizeof(struct iovec);
77051 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77052 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77053 return -EFAULT;
77054
77055 m->msg_iov = iov;
77056 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77057 index fad649a..df5891e 100644
77058 --- a/net/core/rtnetlink.c
77059 +++ b/net/core/rtnetlink.c
77060 @@ -58,7 +58,7 @@ struct rtnl_link {
77061 rtnl_doit_func doit;
77062 rtnl_dumpit_func dumpit;
77063 rtnl_calcit_func calcit;
77064 -};
77065 +} __no_const;
77066
77067 static DEFINE_MUTEX(rtnl_mutex);
77068
77069 diff --git a/net/core/scm.c b/net/core/scm.c
77070 index ab57084..0190c8f 100644
77071 --- a/net/core/scm.c
77072 +++ b/net/core/scm.c
77073 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
77074 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77075 {
77076 struct cmsghdr __user *cm
77077 - = (__force struct cmsghdr __user *)msg->msg_control;
77078 + = (struct cmsghdr __force_user *)msg->msg_control;
77079 struct cmsghdr cmhdr;
77080 int cmlen = CMSG_LEN(len);
77081 int err;
77082 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77083 err = -EFAULT;
77084 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77085 goto out;
77086 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77087 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77088 goto out;
77089 cmlen = CMSG_SPACE(len);
77090 if (msg->msg_controllen < cmlen)
77091 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
77092 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77093 {
77094 struct cmsghdr __user *cm
77095 - = (__force struct cmsghdr __user*)msg->msg_control;
77096 + = (struct cmsghdr __force_user *)msg->msg_control;
77097
77098 int fdmax = 0;
77099 int fdnum = scm->fp->count;
77100 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77101 if (fdnum < fdmax)
77102 fdmax = fdnum;
77103
77104 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77105 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77106 i++, cmfptr++)
77107 {
77108 struct socket *sock;
77109 diff --git a/net/core/sock.c b/net/core/sock.c
77110 index 8a146cf..ee08914d 100644
77111 --- a/net/core/sock.c
77112 +++ b/net/core/sock.c
77113 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77114 struct sk_buff_head *list = &sk->sk_receive_queue;
77115
77116 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77117 - atomic_inc(&sk->sk_drops);
77118 + atomic_inc_unchecked(&sk->sk_drops);
77119 trace_sock_rcvqueue_full(sk, skb);
77120 return -ENOMEM;
77121 }
77122 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77123 return err;
77124
77125 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77126 - atomic_inc(&sk->sk_drops);
77127 + atomic_inc_unchecked(&sk->sk_drops);
77128 return -ENOBUFS;
77129 }
77130
77131 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77132 skb_dst_force(skb);
77133
77134 spin_lock_irqsave(&list->lock, flags);
77135 - skb->dropcount = atomic_read(&sk->sk_drops);
77136 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77137 __skb_queue_tail(list, skb);
77138 spin_unlock_irqrestore(&list->lock, flags);
77139
77140 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77141 skb->dev = NULL;
77142
77143 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77144 - atomic_inc(&sk->sk_drops);
77145 + atomic_inc_unchecked(&sk->sk_drops);
77146 goto discard_and_relse;
77147 }
77148 if (nested)
77149 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77150 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77151 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77152 bh_unlock_sock(sk);
77153 - atomic_inc(&sk->sk_drops);
77154 + atomic_inc_unchecked(&sk->sk_drops);
77155 goto discard_and_relse;
77156 }
77157
77158 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77159 struct timeval tm;
77160 } v;
77161
77162 - int lv = sizeof(int);
77163 - int len;
77164 + unsigned int lv = sizeof(int);
77165 + unsigned int len;
77166
77167 if (get_user(len, optlen))
77168 return -EFAULT;
77169 - if (len < 0)
77170 + if (len > INT_MAX)
77171 return -EINVAL;
77172
77173 memset(&v, 0, sizeof(v));
77174 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77175
77176 case SO_PEERNAME:
77177 {
77178 - char address[128];
77179 + char address[_K_SS_MAXSIZE];
77180
77181 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77182 return -ENOTCONN;
77183 - if (lv < len)
77184 + if (lv < len || sizeof address < len)
77185 return -EINVAL;
77186 if (copy_to_user(optval, address, len))
77187 return -EFAULT;
77188 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77189
77190 if (len > lv)
77191 len = lv;
77192 - if (copy_to_user(optval, &v, len))
77193 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77194 return -EFAULT;
77195 lenout:
77196 if (put_user(len, optlen))
77197 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77198 */
77199 smp_wmb();
77200 atomic_set(&sk->sk_refcnt, 1);
77201 - atomic_set(&sk->sk_drops, 0);
77202 + atomic_set_unchecked(&sk->sk_drops, 0);
77203 }
77204 EXPORT_SYMBOL(sock_init_data);
77205
77206 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77207 index 602cd63..05c6c60 100644
77208 --- a/net/core/sock_diag.c
77209 +++ b/net/core/sock_diag.c
77210 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77211
77212 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77213 {
77214 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77215 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77216 cookie[1] != INET_DIAG_NOCOOKIE) &&
77217 ((u32)(unsigned long)sk != cookie[0] ||
77218 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77219 return -ESTALE;
77220 else
77221 +#endif
77222 return 0;
77223 }
77224 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77225
77226 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77227 {
77228 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77229 + cookie[0] = 0;
77230 + cookie[1] = 0;
77231 +#else
77232 cookie[0] = (u32)(unsigned long)sk;
77233 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77234 +#endif
77235 }
77236 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77237
77238 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77239 index a55eecc..dd8428c 100644
77240 --- a/net/decnet/sysctl_net_decnet.c
77241 +++ b/net/decnet/sysctl_net_decnet.c
77242 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77243
77244 if (len > *lenp) len = *lenp;
77245
77246 - if (copy_to_user(buffer, addr, len))
77247 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77248 return -EFAULT;
77249
77250 *lenp = len;
77251 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77252
77253 if (len > *lenp) len = *lenp;
77254
77255 - if (copy_to_user(buffer, devname, len))
77256 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77257 return -EFAULT;
77258
77259 *lenp = len;
77260 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77261 index 825c608..750ff29 100644
77262 --- a/net/ipv4/fib_frontend.c
77263 +++ b/net/ipv4/fib_frontend.c
77264 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77265 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77266 fib_sync_up(dev);
77267 #endif
77268 - atomic_inc(&net->ipv4.dev_addr_genid);
77269 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77270 rt_cache_flush(dev_net(dev));
77271 break;
77272 case NETDEV_DOWN:
77273 fib_del_ifaddr(ifa, NULL);
77274 - atomic_inc(&net->ipv4.dev_addr_genid);
77275 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77276 if (ifa->ifa_dev->ifa_list == NULL) {
77277 /* Last address was deleted from this interface.
77278 * Disable IP.
77279 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77280 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77281 fib_sync_up(dev);
77282 #endif
77283 - atomic_inc(&net->ipv4.dev_addr_genid);
77284 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77285 rt_cache_flush(net);
77286 break;
77287 case NETDEV_DOWN:
77288 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77289 index 71b125c..f4c70b0 100644
77290 --- a/net/ipv4/fib_semantics.c
77291 +++ b/net/ipv4/fib_semantics.c
77292 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77293 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77294 nh->nh_gw,
77295 nh->nh_parent->fib_scope);
77296 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77297 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77298
77299 return nh->nh_saddr;
77300 }
77301 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77302 index 7880af9..70f92a3 100644
77303 --- a/net/ipv4/inet_hashtables.c
77304 +++ b/net/ipv4/inet_hashtables.c
77305 @@ -18,12 +18,15 @@
77306 #include <linux/sched.h>
77307 #include <linux/slab.h>
77308 #include <linux/wait.h>
77309 +#include <linux/security.h>
77310
77311 #include <net/inet_connection_sock.h>
77312 #include <net/inet_hashtables.h>
77313 #include <net/secure_seq.h>
77314 #include <net/ip.h>
77315
77316 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77317 +
77318 /*
77319 * Allocate and initialize a new local port bind bucket.
77320 * The bindhash mutex for snum's hash chain must be held here.
77321 @@ -530,6 +533,8 @@ ok:
77322 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77323 spin_unlock(&head->lock);
77324
77325 + gr_update_task_in_ip_table(current, inet_sk(sk));
77326 +
77327 if (tw) {
77328 inet_twsk_deschedule(tw, death_row);
77329 while (twrefcnt) {
77330 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77331 index 000e3d2..5472da3 100644
77332 --- a/net/ipv4/inetpeer.c
77333 +++ b/net/ipv4/inetpeer.c
77334 @@ -503,8 +503,8 @@ relookup:
77335 if (p) {
77336 p->daddr = *daddr;
77337 atomic_set(&p->refcnt, 1);
77338 - atomic_set(&p->rid, 0);
77339 - atomic_set(&p->ip_id_count,
77340 + atomic_set_unchecked(&p->rid, 0);
77341 + atomic_set_unchecked(&p->ip_id_count,
77342 (daddr->family == AF_INET) ?
77343 secure_ip_id(daddr->addr.a4) :
77344 secure_ipv6_id(daddr->addr.a6));
77345 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77346 index 8d5cc75..821fd11 100644
77347 --- a/net/ipv4/ip_fragment.c
77348 +++ b/net/ipv4/ip_fragment.c
77349 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77350 return 0;
77351
77352 start = qp->rid;
77353 - end = atomic_inc_return(&peer->rid);
77354 + end = atomic_inc_return_unchecked(&peer->rid);
77355 qp->rid = end;
77356
77357 rc = qp->q.fragments && (end - start) > max;
77358 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77359 index 14bbfcf..644f472 100644
77360 --- a/net/ipv4/ip_sockglue.c
77361 +++ b/net/ipv4/ip_sockglue.c
77362 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77363 len = min_t(unsigned int, len, opt->optlen);
77364 if (put_user(len, optlen))
77365 return -EFAULT;
77366 - if (copy_to_user(optval, opt->__data, len))
77367 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77368 + copy_to_user(optval, opt->__data, len))
77369 return -EFAULT;
77370 return 0;
77371 }
77372 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77373 if (sk->sk_type != SOCK_STREAM)
77374 return -ENOPROTOOPT;
77375
77376 - msg.msg_control = optval;
77377 + msg.msg_control = (void __force_kernel *)optval;
77378 msg.msg_controllen = len;
77379 msg.msg_flags = flags;
77380
77381 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77382 index 798358b..73570b7 100644
77383 --- a/net/ipv4/ipconfig.c
77384 +++ b/net/ipv4/ipconfig.c
77385 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77386
77387 mm_segment_t oldfs = get_fs();
77388 set_fs(get_ds());
77389 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77390 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77391 set_fs(oldfs);
77392 return res;
77393 }
77394 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77395
77396 mm_segment_t oldfs = get_fs();
77397 set_fs(get_ds());
77398 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77399 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77400 set_fs(oldfs);
77401 return res;
77402 }
77403 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77404
77405 mm_segment_t oldfs = get_fs();
77406 set_fs(get_ds());
77407 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77408 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77409 set_fs(oldfs);
77410 return res;
77411 }
77412 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77413 index 97e61ea..cac1bbb 100644
77414 --- a/net/ipv4/netfilter/arp_tables.c
77415 +++ b/net/ipv4/netfilter/arp_tables.c
77416 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77417 #endif
77418
77419 static int get_info(struct net *net, void __user *user,
77420 - const int *len, int compat)
77421 + int len, int compat)
77422 {
77423 char name[XT_TABLE_MAXNAMELEN];
77424 struct xt_table *t;
77425 int ret;
77426
77427 - if (*len != sizeof(struct arpt_getinfo)) {
77428 - duprintf("length %u != %Zu\n", *len,
77429 + if (len != sizeof(struct arpt_getinfo)) {
77430 + duprintf("length %u != %Zu\n", len,
77431 sizeof(struct arpt_getinfo));
77432 return -EINVAL;
77433 }
77434 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77435 info.size = private->size;
77436 strcpy(info.name, name);
77437
77438 - if (copy_to_user(user, &info, *len) != 0)
77439 + if (copy_to_user(user, &info, len) != 0)
77440 ret = -EFAULT;
77441 else
77442 ret = 0;
77443 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77444
77445 switch (cmd) {
77446 case ARPT_SO_GET_INFO:
77447 - ret = get_info(sock_net(sk), user, len, 1);
77448 + ret = get_info(sock_net(sk), user, *len, 1);
77449 break;
77450 case ARPT_SO_GET_ENTRIES:
77451 ret = compat_get_entries(sock_net(sk), user, len);
77452 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77453
77454 switch (cmd) {
77455 case ARPT_SO_GET_INFO:
77456 - ret = get_info(sock_net(sk), user, len, 0);
77457 + ret = get_info(sock_net(sk), user, *len, 0);
77458 break;
77459
77460 case ARPT_SO_GET_ENTRIES:
77461 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77462 index 170b1fd..6105b91 100644
77463 --- a/net/ipv4/netfilter/ip_tables.c
77464 +++ b/net/ipv4/netfilter/ip_tables.c
77465 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77466 #endif
77467
77468 static int get_info(struct net *net, void __user *user,
77469 - const int *len, int compat)
77470 + int len, int compat)
77471 {
77472 char name[XT_TABLE_MAXNAMELEN];
77473 struct xt_table *t;
77474 int ret;
77475
77476 - if (*len != sizeof(struct ipt_getinfo)) {
77477 - duprintf("length %u != %zu\n", *len,
77478 + if (len != sizeof(struct ipt_getinfo)) {
77479 + duprintf("length %u != %zu\n", len,
77480 sizeof(struct ipt_getinfo));
77481 return -EINVAL;
77482 }
77483 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77484 info.size = private->size;
77485 strcpy(info.name, name);
77486
77487 - if (copy_to_user(user, &info, *len) != 0)
77488 + if (copy_to_user(user, &info, len) != 0)
77489 ret = -EFAULT;
77490 else
77491 ret = 0;
77492 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77493
77494 switch (cmd) {
77495 case IPT_SO_GET_INFO:
77496 - ret = get_info(sock_net(sk), user, len, 1);
77497 + ret = get_info(sock_net(sk), user, *len, 1);
77498 break;
77499 case IPT_SO_GET_ENTRIES:
77500 ret = compat_get_entries(sock_net(sk), user, len);
77501 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77502
77503 switch (cmd) {
77504 case IPT_SO_GET_INFO:
77505 - ret = get_info(sock_net(sk), user, len, 0);
77506 + ret = get_info(sock_net(sk), user, *len, 0);
77507 break;
77508
77509 case IPT_SO_GET_ENTRIES:
77510 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77511 index 8f3d054..c58d05d 100644
77512 --- a/net/ipv4/ping.c
77513 +++ b/net/ipv4/ping.c
77514 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77515 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
77516 0, sock_i_ino(sp),
77517 atomic_read(&sp->sk_refcnt), sp,
77518 - atomic_read(&sp->sk_drops), len);
77519 + atomic_read_unchecked(&sp->sk_drops), len);
77520 }
77521
77522 static int ping_seq_show(struct seq_file *seq, void *v)
77523 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77524 index 73d1e4d..3af0e8f 100644
77525 --- a/net/ipv4/raw.c
77526 +++ b/net/ipv4/raw.c
77527 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77528 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77529 {
77530 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77531 - atomic_inc(&sk->sk_drops);
77532 + atomic_inc_unchecked(&sk->sk_drops);
77533 kfree_skb(skb);
77534 return NET_RX_DROP;
77535 }
77536 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77537
77538 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77539 {
77540 + struct icmp_filter filter;
77541 +
77542 if (optlen > sizeof(struct icmp_filter))
77543 optlen = sizeof(struct icmp_filter);
77544 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77545 + if (copy_from_user(&filter, optval, optlen))
77546 return -EFAULT;
77547 + raw_sk(sk)->filter = filter;
77548 return 0;
77549 }
77550
77551 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77552 {
77553 int len, ret = -EFAULT;
77554 + struct icmp_filter filter;
77555
77556 if (get_user(len, optlen))
77557 goto out;
77558 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77559 if (len > sizeof(struct icmp_filter))
77560 len = sizeof(struct icmp_filter);
77561 ret = -EFAULT;
77562 - if (put_user(len, optlen) ||
77563 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77564 + filter = raw_sk(sk)->filter;
77565 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77566 goto out;
77567 ret = 0;
77568 out: return ret;
77569 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77570 0, 0L, 0,
77571 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
77572 0, sock_i_ino(sp),
77573 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77574 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
77575 }
77576
77577 static int raw_seq_show(struct seq_file *seq, void *v)
77578 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77579 index df25142..e92a82a 100644
77580 --- a/net/ipv4/route.c
77581 +++ b/net/ipv4/route.c
77582 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77583
77584 static __net_init int rt_genid_init(struct net *net)
77585 {
77586 - atomic_set(&net->rt_genid, 0);
77587 + atomic_set_unchecked(&net->rt_genid, 0);
77588 get_random_bytes(&net->ipv4.dev_addr_genid,
77589 sizeof(net->ipv4.dev_addr_genid));
77590 return 0;
77591 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77592 index 181fc82..57da08d 100644
77593 --- a/net/ipv4/tcp_input.c
77594 +++ b/net/ipv4/tcp_input.c
77595 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77596 * simplifies code)
77597 */
77598 static void
77599 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77600 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77601 struct sk_buff *head, struct sk_buff *tail,
77602 u32 start, u32 end)
77603 {
77604 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77605 index 0c4a643..e584990 100644
77606 --- a/net/ipv4/tcp_ipv4.c
77607 +++ b/net/ipv4/tcp_ipv4.c
77608 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77609 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77610
77611
77612 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77613 +extern int grsec_enable_blackhole;
77614 +#endif
77615 +
77616 #ifdef CONFIG_TCP_MD5SIG
77617 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77618 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77619 @@ -1901,6 +1905,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77620 return 0;
77621
77622 reset:
77623 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77624 + if (!grsec_enable_blackhole)
77625 +#endif
77626 tcp_v4_send_reset(rsk, skb);
77627 discard:
77628 kfree_skb(skb);
77629 @@ -2001,12 +2008,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77630 TCP_SKB_CB(skb)->sacked = 0;
77631
77632 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77633 - if (!sk)
77634 + if (!sk) {
77635 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77636 + ret = 1;
77637 +#endif
77638 goto no_tcp_socket;
77639 -
77640 + }
77641 process:
77642 - if (sk->sk_state == TCP_TIME_WAIT)
77643 + if (sk->sk_state == TCP_TIME_WAIT) {
77644 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77645 + ret = 2;
77646 +#endif
77647 goto do_time_wait;
77648 + }
77649
77650 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77651 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77652 @@ -2057,6 +2071,10 @@ no_tcp_socket:
77653 bad_packet:
77654 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77655 } else {
77656 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77657 + if (!grsec_enable_blackhole || (ret == 1 &&
77658 + (skb->dev->flags & IFF_LOOPBACK)))
77659 +#endif
77660 tcp_v4_send_reset(NULL, skb);
77661 }
77662
77663 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77664 index a7302d9..e3ec754 100644
77665 --- a/net/ipv4/tcp_minisocks.c
77666 +++ b/net/ipv4/tcp_minisocks.c
77667 @@ -27,6 +27,10 @@
77668 #include <net/inet_common.h>
77669 #include <net/xfrm.h>
77670
77671 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77672 +extern int grsec_enable_blackhole;
77673 +#endif
77674 +
77675 int sysctl_tcp_syncookies __read_mostly = 1;
77676 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77677
77678 @@ -742,7 +746,10 @@ embryonic_reset:
77679 * avoid becoming vulnerable to outside attack aiming at
77680 * resetting legit local connections.
77681 */
77682 - req->rsk_ops->send_reset(sk, skb);
77683 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77684 + if (!grsec_enable_blackhole)
77685 +#endif
77686 + req->rsk_ops->send_reset(sk, skb);
77687 } else if (fastopen) { /* received a valid RST pkt */
77688 reqsk_fastopen_remove(sk, req, true);
77689 tcp_reset(sk);
77690 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77691 index 4526fe6..1a34e43 100644
77692 --- a/net/ipv4/tcp_probe.c
77693 +++ b/net/ipv4/tcp_probe.c
77694 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77695 if (cnt + width >= len)
77696 break;
77697
77698 - if (copy_to_user(buf + cnt, tbuf, width))
77699 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77700 return -EFAULT;
77701 cnt += width;
77702 }
77703 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77704 index d47c1b4..b0584de 100644
77705 --- a/net/ipv4/tcp_timer.c
77706 +++ b/net/ipv4/tcp_timer.c
77707 @@ -22,6 +22,10 @@
77708 #include <linux/gfp.h>
77709 #include <net/tcp.h>
77710
77711 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77712 +extern int grsec_lastack_retries;
77713 +#endif
77714 +
77715 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77716 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77717 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77718 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77719 }
77720 }
77721
77722 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77723 + if ((sk->sk_state == TCP_LAST_ACK) &&
77724 + (grsec_lastack_retries > 0) &&
77725 + (grsec_lastack_retries < retry_until))
77726 + retry_until = grsec_lastack_retries;
77727 +#endif
77728 +
77729 if (retransmits_timed_out(sk, retry_until,
77730 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77731 /* Has it gone just too far? */
77732 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77733 index 79c8dbe..aceb1b6 100644
77734 --- a/net/ipv4/udp.c
77735 +++ b/net/ipv4/udp.c
77736 @@ -87,6 +87,7 @@
77737 #include <linux/types.h>
77738 #include <linux/fcntl.h>
77739 #include <linux/module.h>
77740 +#include <linux/security.h>
77741 #include <linux/socket.h>
77742 #include <linux/sockios.h>
77743 #include <linux/igmp.h>
77744 @@ -111,6 +112,10 @@
77745 #include <trace/events/skb.h>
77746 #include "udp_impl.h"
77747
77748 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77749 +extern int grsec_enable_blackhole;
77750 +#endif
77751 +
77752 struct udp_table udp_table __read_mostly;
77753 EXPORT_SYMBOL(udp_table);
77754
77755 @@ -569,6 +574,9 @@ found:
77756 return s;
77757 }
77758
77759 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77760 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77761 +
77762 /*
77763 * This routine is called by the ICMP module when it gets some
77764 * sort of error condition. If err < 0 then the socket should
77765 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77766 dport = usin->sin_port;
77767 if (dport == 0)
77768 return -EINVAL;
77769 +
77770 + err = gr_search_udp_sendmsg(sk, usin);
77771 + if (err)
77772 + return err;
77773 } else {
77774 if (sk->sk_state != TCP_ESTABLISHED)
77775 return -EDESTADDRREQ;
77776 +
77777 + err = gr_search_udp_sendmsg(sk, NULL);
77778 + if (err)
77779 + return err;
77780 +
77781 daddr = inet->inet_daddr;
77782 dport = inet->inet_dport;
77783 /* Open fast path for connected socket.
77784 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77785 udp_lib_checksum_complete(skb)) {
77786 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77787 IS_UDPLITE(sk));
77788 - atomic_inc(&sk->sk_drops);
77789 + atomic_inc_unchecked(&sk->sk_drops);
77790 __skb_unlink(skb, rcvq);
77791 __skb_queue_tail(&list_kill, skb);
77792 }
77793 @@ -1194,6 +1211,10 @@ try_again:
77794 if (!skb)
77795 goto out;
77796
77797 + err = gr_search_udp_recvmsg(sk, skb);
77798 + if (err)
77799 + goto out_free;
77800 +
77801 ulen = skb->len - sizeof(struct udphdr);
77802 copied = len;
77803 if (copied > ulen)
77804 @@ -1227,7 +1248,7 @@ try_again:
77805 if (unlikely(err)) {
77806 trace_kfree_skb(skb, udp_recvmsg);
77807 if (!peeked) {
77808 - atomic_inc(&sk->sk_drops);
77809 + atomic_inc_unchecked(&sk->sk_drops);
77810 UDP_INC_STATS_USER(sock_net(sk),
77811 UDP_MIB_INERRORS, is_udplite);
77812 }
77813 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77814
77815 drop:
77816 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77817 - atomic_inc(&sk->sk_drops);
77818 + atomic_inc_unchecked(&sk->sk_drops);
77819 kfree_skb(skb);
77820 return -1;
77821 }
77822 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77823 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77824
77825 if (!skb1) {
77826 - atomic_inc(&sk->sk_drops);
77827 + atomic_inc_unchecked(&sk->sk_drops);
77828 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77829 IS_UDPLITE(sk));
77830 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77831 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77832 goto csum_error;
77833
77834 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77835 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77836 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77837 +#endif
77838 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77839
77840 /*
77841 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77842 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
77843 0, sock_i_ino(sp),
77844 atomic_read(&sp->sk_refcnt), sp,
77845 - atomic_read(&sp->sk_drops), len);
77846 + atomic_read_unchecked(&sp->sk_drops), len);
77847 }
77848
77849 int udp4_seq_show(struct seq_file *seq, void *v)
77850 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77851 index 0424e4e..308dd43 100644
77852 --- a/net/ipv6/addrconf.c
77853 +++ b/net/ipv6/addrconf.c
77854 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77855 p.iph.ihl = 5;
77856 p.iph.protocol = IPPROTO_IPV6;
77857 p.iph.ttl = 64;
77858 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77859 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77860
77861 if (ops->ndo_do_ioctl) {
77862 mm_segment_t oldfs = get_fs();
77863 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77864 index e02faed..9780f28 100644
77865 --- a/net/ipv6/ipv6_sockglue.c
77866 +++ b/net/ipv6/ipv6_sockglue.c
77867 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77868 if (sk->sk_type != SOCK_STREAM)
77869 return -ENOPROTOOPT;
77870
77871 - msg.msg_control = optval;
77872 + msg.msg_control = (void __force_kernel *)optval;
77873 msg.msg_controllen = len;
77874 msg.msg_flags = flags;
77875
77876 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77877 index d7cb045..8c0ded6 100644
77878 --- a/net/ipv6/netfilter/ip6_tables.c
77879 +++ b/net/ipv6/netfilter/ip6_tables.c
77880 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77881 #endif
77882
77883 static int get_info(struct net *net, void __user *user,
77884 - const int *len, int compat)
77885 + int len, int compat)
77886 {
77887 char name[XT_TABLE_MAXNAMELEN];
77888 struct xt_table *t;
77889 int ret;
77890
77891 - if (*len != sizeof(struct ip6t_getinfo)) {
77892 - duprintf("length %u != %zu\n", *len,
77893 + if (len != sizeof(struct ip6t_getinfo)) {
77894 + duprintf("length %u != %zu\n", len,
77895 sizeof(struct ip6t_getinfo));
77896 return -EINVAL;
77897 }
77898 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77899 info.size = private->size;
77900 strcpy(info.name, name);
77901
77902 - if (copy_to_user(user, &info, *len) != 0)
77903 + if (copy_to_user(user, &info, len) != 0)
77904 ret = -EFAULT;
77905 else
77906 ret = 0;
77907 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77908
77909 switch (cmd) {
77910 case IP6T_SO_GET_INFO:
77911 - ret = get_info(sock_net(sk), user, len, 1);
77912 + ret = get_info(sock_net(sk), user, *len, 1);
77913 break;
77914 case IP6T_SO_GET_ENTRIES:
77915 ret = compat_get_entries(sock_net(sk), user, len);
77916 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77917
77918 switch (cmd) {
77919 case IP6T_SO_GET_INFO:
77920 - ret = get_info(sock_net(sk), user, len, 0);
77921 + ret = get_info(sock_net(sk), user, *len, 0);
77922 break;
77923
77924 case IP6T_SO_GET_ENTRIES:
77925 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77926 index d8e95c7..81422bc 100644
77927 --- a/net/ipv6/raw.c
77928 +++ b/net/ipv6/raw.c
77929 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77930 {
77931 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77932 skb_checksum_complete(skb)) {
77933 - atomic_inc(&sk->sk_drops);
77934 + atomic_inc_unchecked(&sk->sk_drops);
77935 kfree_skb(skb);
77936 return NET_RX_DROP;
77937 }
77938 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77939 struct raw6_sock *rp = raw6_sk(sk);
77940
77941 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77942 - atomic_inc(&sk->sk_drops);
77943 + atomic_inc_unchecked(&sk->sk_drops);
77944 kfree_skb(skb);
77945 return NET_RX_DROP;
77946 }
77947 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77948
77949 if (inet->hdrincl) {
77950 if (skb_checksum_complete(skb)) {
77951 - atomic_inc(&sk->sk_drops);
77952 + atomic_inc_unchecked(&sk->sk_drops);
77953 kfree_skb(skb);
77954 return NET_RX_DROP;
77955 }
77956 @@ -604,7 +604,7 @@ out:
77957 return err;
77958 }
77959
77960 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77961 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77962 struct flowi6 *fl6, struct dst_entry **dstp,
77963 unsigned int flags)
77964 {
77965 @@ -916,12 +916,15 @@ do_confirm:
77966 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77967 char __user *optval, int optlen)
77968 {
77969 + struct icmp6_filter filter;
77970 +
77971 switch (optname) {
77972 case ICMPV6_FILTER:
77973 if (optlen > sizeof(struct icmp6_filter))
77974 optlen = sizeof(struct icmp6_filter);
77975 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77976 + if (copy_from_user(&filter, optval, optlen))
77977 return -EFAULT;
77978 + raw6_sk(sk)->filter = filter;
77979 return 0;
77980 default:
77981 return -ENOPROTOOPT;
77982 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77983 char __user *optval, int __user *optlen)
77984 {
77985 int len;
77986 + struct icmp6_filter filter;
77987
77988 switch (optname) {
77989 case ICMPV6_FILTER:
77990 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77991 len = sizeof(struct icmp6_filter);
77992 if (put_user(len, optlen))
77993 return -EFAULT;
77994 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77995 + filter = raw6_sk(sk)->filter;
77996 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77997 return -EFAULT;
77998 return 0;
77999 default:
78000 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78001 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
78002 0,
78003 sock_i_ino(sp),
78004 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78005 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
78006 }
78007
78008 static int raw6_seq_show(struct seq_file *seq, void *v)
78009 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78010 index 26175bf..fc3e4fb 100644
78011 --- a/net/ipv6/tcp_ipv6.c
78012 +++ b/net/ipv6/tcp_ipv6.c
78013 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78014 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78015 }
78016
78017 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78018 +extern int grsec_enable_blackhole;
78019 +#endif
78020 +
78021 static void tcp_v6_hash(struct sock *sk)
78022 {
78023 if (sk->sk_state != TCP_CLOSE) {
78024 @@ -1524,6 +1528,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78025 return 0;
78026
78027 reset:
78028 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78029 + if (!grsec_enable_blackhole)
78030 +#endif
78031 tcp_v6_send_reset(sk, skb);
78032 discard:
78033 if (opt_skb)
78034 @@ -1605,12 +1612,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78035 TCP_SKB_CB(skb)->sacked = 0;
78036
78037 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78038 - if (!sk)
78039 + if (!sk) {
78040 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78041 + ret = 1;
78042 +#endif
78043 goto no_tcp_socket;
78044 + }
78045
78046 process:
78047 - if (sk->sk_state == TCP_TIME_WAIT)
78048 + if (sk->sk_state == TCP_TIME_WAIT) {
78049 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78050 + ret = 2;
78051 +#endif
78052 goto do_time_wait;
78053 + }
78054
78055 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78056 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78057 @@ -1659,6 +1674,10 @@ no_tcp_socket:
78058 bad_packet:
78059 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78060 } else {
78061 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78062 + if (!grsec_enable_blackhole || (ret == 1 &&
78063 + (skb->dev->flags & IFF_LOOPBACK)))
78064 +#endif
78065 tcp_v6_send_reset(NULL, skb);
78066 }
78067
78068 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78069 index fc99972..69397e8 100644
78070 --- a/net/ipv6/udp.c
78071 +++ b/net/ipv6/udp.c
78072 @@ -51,6 +51,10 @@
78073 #include <trace/events/skb.h>
78074 #include "udp_impl.h"
78075
78076 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78077 +extern int grsec_enable_blackhole;
78078 +#endif
78079 +
78080 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78081 {
78082 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78083 @@ -395,7 +399,7 @@ try_again:
78084 if (unlikely(err)) {
78085 trace_kfree_skb(skb, udpv6_recvmsg);
78086 if (!peeked) {
78087 - atomic_inc(&sk->sk_drops);
78088 + atomic_inc_unchecked(&sk->sk_drops);
78089 if (is_udp4)
78090 UDP_INC_STATS_USER(sock_net(sk),
78091 UDP_MIB_INERRORS,
78092 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78093 return rc;
78094 drop:
78095 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78096 - atomic_inc(&sk->sk_drops);
78097 + atomic_inc_unchecked(&sk->sk_drops);
78098 kfree_skb(skb);
78099 return -1;
78100 }
78101 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78102 if (likely(skb1 == NULL))
78103 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78104 if (!skb1) {
78105 - atomic_inc(&sk->sk_drops);
78106 + atomic_inc_unchecked(&sk->sk_drops);
78107 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78108 IS_UDPLITE(sk));
78109 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78110 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78111 goto discard;
78112
78113 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78114 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78115 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78116 +#endif
78117 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78118
78119 kfree_skb(skb);
78120 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78121 0,
78122 sock_i_ino(sp),
78123 atomic_read(&sp->sk_refcnt), sp,
78124 - atomic_read(&sp->sk_drops));
78125 + atomic_read_unchecked(&sp->sk_drops));
78126 }
78127
78128 int udp6_seq_show(struct seq_file *seq, void *v)
78129 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78130 index 496ce2c..f79fac8 100644
78131 --- a/net/irda/ircomm/ircomm_tty.c
78132 +++ b/net/irda/ircomm/ircomm_tty.c
78133 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78134 add_wait_queue(&port->open_wait, &wait);
78135
78136 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78137 - __FILE__, __LINE__, tty->driver->name, port->count);
78138 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78139
78140 spin_lock_irqsave(&port->lock, flags);
78141 if (!tty_hung_up_p(filp)) {
78142 extra_count = 1;
78143 - port->count--;
78144 + atomic_dec(&port->count);
78145 }
78146 spin_unlock_irqrestore(&port->lock, flags);
78147 port->blocked_open++;
78148 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78149 }
78150
78151 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78152 - __FILE__, __LINE__, tty->driver->name, port->count);
78153 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78154
78155 schedule();
78156 }
78157 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78158 if (extra_count) {
78159 /* ++ is not atomic, so this should be protected - Jean II */
78160 spin_lock_irqsave(&port->lock, flags);
78161 - port->count++;
78162 + atomic_inc(&port->count);
78163 spin_unlock_irqrestore(&port->lock, flags);
78164 }
78165 port->blocked_open--;
78166
78167 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78168 - __FILE__, __LINE__, tty->driver->name, port->count);
78169 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78170
78171 if (!retval)
78172 port->flags |= ASYNC_NORMAL_ACTIVE;
78173 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78174
78175 /* ++ is not atomic, so this should be protected - Jean II */
78176 spin_lock_irqsave(&self->port.lock, flags);
78177 - self->port.count++;
78178 + atomic_inc(&self->port.count);
78179 spin_unlock_irqrestore(&self->port.lock, flags);
78180 tty_port_tty_set(&self->port, tty);
78181
78182 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78183 - self->line, self->port.count);
78184 + self->line, atomic_read(&self->port.count));
78185
78186 /* Not really used by us, but lets do it anyway */
78187 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78188 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78189 tty_kref_put(port->tty);
78190 }
78191 port->tty = NULL;
78192 - port->count = 0;
78193 + atomic_set(&port->count, 0);
78194 spin_unlock_irqrestore(&port->lock, flags);
78195
78196 wake_up_interruptible(&port->open_wait);
78197 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78198 seq_putc(m, '\n');
78199
78200 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78201 - seq_printf(m, "Open count: %d\n", self->port.count);
78202 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
78203 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78204 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78205
78206 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78207 index cd6f7a9..e63fe89 100644
78208 --- a/net/iucv/af_iucv.c
78209 +++ b/net/iucv/af_iucv.c
78210 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78211
78212 write_lock_bh(&iucv_sk_list.lock);
78213
78214 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78215 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78216 while (__iucv_get_sock_by_name(name)) {
78217 sprintf(name, "%08x",
78218 - atomic_inc_return(&iucv_sk_list.autobind_name));
78219 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78220 }
78221
78222 write_unlock_bh(&iucv_sk_list.lock);
78223 diff --git a/net/key/af_key.c b/net/key/af_key.c
78224 index 08897a3..0b812ab 100644
78225 --- a/net/key/af_key.c
78226 +++ b/net/key/af_key.c
78227 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78228 static u32 get_acqseq(void)
78229 {
78230 u32 res;
78231 - static atomic_t acqseq;
78232 + static atomic_unchecked_t acqseq;
78233
78234 do {
78235 - res = atomic_inc_return(&acqseq);
78236 + res = atomic_inc_return_unchecked(&acqseq);
78237 } while (!res);
78238 return res;
78239 }
78240 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
78241 index 7371f67..9897314 100644
78242 --- a/net/mac80211/cfg.c
78243 +++ b/net/mac80211/cfg.c
78244 @@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
78245 else
78246 local->probe_req_reg--;
78247
78248 - if (!local->open_count)
78249 + if (!local_read(&local->open_count))
78250 break;
78251
78252 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
78253 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78254 index 156e583..900a7c7 100644
78255 --- a/net/mac80211/ieee80211_i.h
78256 +++ b/net/mac80211/ieee80211_i.h
78257 @@ -28,6 +28,7 @@
78258 #include <net/ieee80211_radiotap.h>
78259 #include <net/cfg80211.h>
78260 #include <net/mac80211.h>
78261 +#include <asm/local.h>
78262 #include "key.h"
78263 #include "sta_info.h"
78264 #include "debug.h"
78265 @@ -848,7 +849,7 @@ struct ieee80211_local {
78266 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78267 spinlock_t queue_stop_reason_lock;
78268
78269 - int open_count;
78270 + local_t open_count;
78271 int monitors, cooked_mntrs;
78272 /* number of interfaces with corresponding FIF_ flags */
78273 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78274 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78275 index 7de7717..3de8e97 100644
78276 --- a/net/mac80211/iface.c
78277 +++ b/net/mac80211/iface.c
78278 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78279 break;
78280 }
78281
78282 - if (local->open_count == 0) {
78283 + if (local_read(&local->open_count) == 0) {
78284 res = drv_start(local);
78285 if (res)
78286 goto err_del_bss;
78287 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78288 break;
78289 }
78290
78291 - if (local->monitors == 0 && local->open_count == 0) {
78292 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78293 res = ieee80211_add_virtual_monitor(local);
78294 if (res)
78295 goto err_stop;
78296 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78297 mutex_unlock(&local->mtx);
78298
78299 if (coming_up)
78300 - local->open_count++;
78301 + local_inc(&local->open_count);
78302
78303 if (hw_reconf_flags)
78304 ieee80211_hw_config(local, hw_reconf_flags);
78305 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78306 err_del_interface:
78307 drv_remove_interface(local, sdata);
78308 err_stop:
78309 - if (!local->open_count)
78310 + if (!local_read(&local->open_count))
78311 drv_stop(local);
78312 err_del_bss:
78313 sdata->bss = NULL;
78314 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78315 }
78316
78317 if (going_down)
78318 - local->open_count--;
78319 + local_dec(&local->open_count);
78320
78321 switch (sdata->vif.type) {
78322 case NL80211_IFTYPE_AP_VLAN:
78323 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78324
78325 ieee80211_recalc_ps(local, -1);
78326
78327 - if (local->open_count == 0) {
78328 + if (local_read(&local->open_count) == 0) {
78329 if (local->ops->napi_poll)
78330 napi_disable(&local->napi);
78331 ieee80211_clear_tx_pending(local);
78332 @@ -859,7 +859,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78333 }
78334 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78335
78336 - if (local->monitors == local->open_count && local->monitors > 0)
78337 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78338 ieee80211_add_virtual_monitor(local);
78339 }
78340
78341 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78342 index f57f597..e0a7c03 100644
78343 --- a/net/mac80211/main.c
78344 +++ b/net/mac80211/main.c
78345 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78346 local->hw.conf.power_level = power;
78347 }
78348
78349 - if (changed && local->open_count) {
78350 + if (changed && local_read(&local->open_count)) {
78351 ret = drv_config(local, changed);
78352 /*
78353 * Goal:
78354 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78355 index 5c572e7..ecf75ce 100644
78356 --- a/net/mac80211/pm.c
78357 +++ b/net/mac80211/pm.c
78358 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78359 struct ieee80211_sub_if_data *sdata;
78360 struct sta_info *sta;
78361
78362 - if (!local->open_count)
78363 + if (!local_read(&local->open_count))
78364 goto suspend;
78365
78366 ieee80211_scan_cancel(local);
78367 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78368 cancel_work_sync(&local->dynamic_ps_enable_work);
78369 del_timer_sync(&local->dynamic_ps_timer);
78370
78371 - local->wowlan = wowlan && local->open_count;
78372 + local->wowlan = wowlan && local_read(&local->open_count);
78373 if (local->wowlan) {
78374 int err = drv_suspend(local, wowlan);
78375 if (err < 0) {
78376 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78377 drv_remove_interface(local, sdata);
78378
78379 /* stop hardware - this must stop RX */
78380 - if (local->open_count)
78381 + if (local_read(&local->open_count))
78382 ieee80211_stop_device(local);
78383
78384 suspend:
78385 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78386 index 3313c11..bec9f17 100644
78387 --- a/net/mac80211/rate.c
78388 +++ b/net/mac80211/rate.c
78389 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78390
78391 ASSERT_RTNL();
78392
78393 - if (local->open_count)
78394 + if (local_read(&local->open_count))
78395 return -EBUSY;
78396
78397 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78398 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78399 index c97a065..ff61928 100644
78400 --- a/net/mac80211/rc80211_pid_debugfs.c
78401 +++ b/net/mac80211/rc80211_pid_debugfs.c
78402 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78403
78404 spin_unlock_irqrestore(&events->lock, status);
78405
78406 - if (copy_to_user(buf, pb, p))
78407 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78408 return -EFAULT;
78409
78410 return p;
78411 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78412 index 0151ae3..26709d3 100644
78413 --- a/net/mac80211/util.c
78414 +++ b/net/mac80211/util.c
78415 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78416 }
78417 #endif
78418 /* everything else happens only if HW was up & running */
78419 - if (!local->open_count)
78420 + if (!local_read(&local->open_count))
78421 goto wake_up;
78422
78423 /*
78424 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78425 index fefa514..0755f23 100644
78426 --- a/net/netfilter/Kconfig
78427 +++ b/net/netfilter/Kconfig
78428 @@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
78429
78430 To compile it as a module, choose M here. If unsure, say N.
78431
78432 +config NETFILTER_XT_MATCH_GRADM
78433 + tristate '"gradm" match support'
78434 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78435 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78436 + ---help---
78437 + The gradm match allows to match on grsecurity RBAC being enabled.
78438 + It is useful when iptables rules are applied early on bootup to
78439 + prevent connections to the machine (except from a trusted host)
78440 + while the RBAC system is disabled.
78441 +
78442 config NETFILTER_XT_MATCH_HASHLIMIT
78443 tristate '"hashlimit" match support'
78444 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78445 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78446 index 3259697..54d5393 100644
78447 --- a/net/netfilter/Makefile
78448 +++ b/net/netfilter/Makefile
78449 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78450 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78451 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78452 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78453 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78454 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78455 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78456 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78457 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78458 index 1548df9..98ad9b4 100644
78459 --- a/net/netfilter/ipvs/ip_vs_conn.c
78460 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78461 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78462 /* Increase the refcnt counter of the dest */
78463 atomic_inc(&dest->refcnt);
78464
78465 - conn_flags = atomic_read(&dest->conn_flags);
78466 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78467 if (cp->protocol != IPPROTO_UDP)
78468 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78469 flags = cp->flags;
78470 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78471 atomic_set(&cp->refcnt, 1);
78472
78473 atomic_set(&cp->n_control, 0);
78474 - atomic_set(&cp->in_pkts, 0);
78475 + atomic_set_unchecked(&cp->in_pkts, 0);
78476
78477 atomic_inc(&ipvs->conn_count);
78478 if (flags & IP_VS_CONN_F_NO_CPORT)
78479 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78480
78481 /* Don't drop the entry if its number of incoming packets is not
78482 located in [0, 8] */
78483 - i = atomic_read(&cp->in_pkts);
78484 + i = atomic_read_unchecked(&cp->in_pkts);
78485 if (i > 8 || i < 0) return 0;
78486
78487 if (!todrop_rate[i]) return 0;
78488 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78489 index 58918e2..4d177a9 100644
78490 --- a/net/netfilter/ipvs/ip_vs_core.c
78491 +++ b/net/netfilter/ipvs/ip_vs_core.c
78492 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78493 ret = cp->packet_xmit(skb, cp, pd->pp);
78494 /* do not touch skb anymore */
78495
78496 - atomic_inc(&cp->in_pkts);
78497 + atomic_inc_unchecked(&cp->in_pkts);
78498 ip_vs_conn_put(cp);
78499 return ret;
78500 }
78501 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78502 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78503 pkts = sysctl_sync_threshold(ipvs);
78504 else
78505 - pkts = atomic_add_return(1, &cp->in_pkts);
78506 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78507
78508 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78509 ip_vs_sync_conn(net, cp, pkts);
78510 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78511 index c4ee437..a774a74 100644
78512 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78513 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78514 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78515 ip_vs_rs_hash(ipvs, dest);
78516 write_unlock_bh(&ipvs->rs_lock);
78517 }
78518 - atomic_set(&dest->conn_flags, conn_flags);
78519 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78520
78521 /* bind the service */
78522 if (!dest->svc) {
78523 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78524 " %-7s %-6d %-10d %-10d\n",
78525 &dest->addr.in6,
78526 ntohs(dest->port),
78527 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78528 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78529 atomic_read(&dest->weight),
78530 atomic_read(&dest->activeconns),
78531 atomic_read(&dest->inactconns));
78532 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78533 "%-7s %-6d %-10d %-10d\n",
78534 ntohl(dest->addr.ip),
78535 ntohs(dest->port),
78536 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78537 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78538 atomic_read(&dest->weight),
78539 atomic_read(&dest->activeconns),
78540 atomic_read(&dest->inactconns));
78541 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78542
78543 entry.addr = dest->addr.ip;
78544 entry.port = dest->port;
78545 - entry.conn_flags = atomic_read(&dest->conn_flags);
78546 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78547 entry.weight = atomic_read(&dest->weight);
78548 entry.u_threshold = dest->u_threshold;
78549 entry.l_threshold = dest->l_threshold;
78550 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78551 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78552 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78553 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78554 - (atomic_read(&dest->conn_flags) &
78555 + (atomic_read_unchecked(&dest->conn_flags) &
78556 IP_VS_CONN_F_FWD_MASK)) ||
78557 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78558 atomic_read(&dest->weight)) ||
78559 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78560 index effa10c..9058928 100644
78561 --- a/net/netfilter/ipvs/ip_vs_sync.c
78562 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78563 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78564 cp = cp->control;
78565 if (cp) {
78566 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78567 - pkts = atomic_add_return(1, &cp->in_pkts);
78568 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78569 else
78570 pkts = sysctl_sync_threshold(ipvs);
78571 ip_vs_sync_conn(net, cp->control, pkts);
78572 @@ -758,7 +758,7 @@ control:
78573 if (!cp)
78574 return;
78575 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78576 - pkts = atomic_add_return(1, &cp->in_pkts);
78577 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78578 else
78579 pkts = sysctl_sync_threshold(ipvs);
78580 goto sloop;
78581 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78582
78583 if (opt)
78584 memcpy(&cp->in_seq, opt, sizeof(*opt));
78585 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78586 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78587 cp->state = state;
78588 cp->old_state = cp->state;
78589 /*
78590 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78591 index cc4c809..50f8fe5 100644
78592 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78593 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78594 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78595 else
78596 rc = NF_ACCEPT;
78597 /* do not touch skb anymore */
78598 - atomic_inc(&cp->in_pkts);
78599 + atomic_inc_unchecked(&cp->in_pkts);
78600 goto out;
78601 }
78602
78603 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78604 else
78605 rc = NF_ACCEPT;
78606 /* do not touch skb anymore */
78607 - atomic_inc(&cp->in_pkts);
78608 + atomic_inc_unchecked(&cp->in_pkts);
78609 goto out;
78610 }
78611
78612 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78613 index 0f241be..2c9be6d 100644
78614 --- a/net/netfilter/nf_conntrack_core.c
78615 +++ b/net/netfilter/nf_conntrack_core.c
78616 @@ -1532,6 +1532,10 @@ err_extend:
78617 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78618 #define DYING_NULLS_VAL ((1<<30)+1)
78619
78620 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78621 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78622 +#endif
78623 +
78624 static int nf_conntrack_init_net(struct net *net)
78625 {
78626 int ret;
78627 @@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
78628 goto err_stat;
78629 }
78630
78631 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78632 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78633 +#else
78634 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78635 +#endif
78636 if (!net->ct.slabname) {
78637 ret = -ENOMEM;
78638 goto err_slabname;
78639 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78640 index 9f199f2..719ad23 100644
78641 --- a/net/netfilter/nfnetlink_log.c
78642 +++ b/net/netfilter/nfnetlink_log.c
78643 @@ -71,7 +71,7 @@ struct nfulnl_instance {
78644 };
78645
78646 static DEFINE_SPINLOCK(instances_lock);
78647 -static atomic_t global_seq;
78648 +static atomic_unchecked_t global_seq;
78649
78650 #define INSTANCE_BUCKETS 16
78651 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78652 @@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78653 /* global sequence number */
78654 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78655 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78656 - htonl(atomic_inc_return(&global_seq))))
78657 + htonl(atomic_inc_return_unchecked(&global_seq))))
78658 goto nla_put_failure;
78659
78660 if (data_len) {
78661 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78662 new file mode 100644
78663 index 0000000..c566332
78664 --- /dev/null
78665 +++ b/net/netfilter/xt_gradm.c
78666 @@ -0,0 +1,51 @@
78667 +/*
78668 + * gradm match for netfilter
78669 + * Copyright © Zbigniew Krzystolik, 2010
78670 + *
78671 + * This program is free software; you can redistribute it and/or modify
78672 + * it under the terms of the GNU General Public License; either version
78673 + * 2 or 3 as published by the Free Software Foundation.
78674 + */
78675 +#include <linux/module.h>
78676 +#include <linux/moduleparam.h>
78677 +#include <linux/skbuff.h>
78678 +#include <linux/netfilter/x_tables.h>
78679 +#include <linux/grsecurity.h>
78680 +#include <linux/netfilter/xt_gradm.h>
78681 +
78682 +static bool
78683 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78684 +{
78685 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78686 + bool retval = false;
78687 + if (gr_acl_is_enabled())
78688 + retval = true;
78689 + return retval ^ info->invflags;
78690 +}
78691 +
78692 +static struct xt_match gradm_mt_reg __read_mostly = {
78693 + .name = "gradm",
78694 + .revision = 0,
78695 + .family = NFPROTO_UNSPEC,
78696 + .match = gradm_mt,
78697 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78698 + .me = THIS_MODULE,
78699 +};
78700 +
78701 +static int __init gradm_mt_init(void)
78702 +{
78703 + return xt_register_match(&gradm_mt_reg);
78704 +}
78705 +
78706 +static void __exit gradm_mt_exit(void)
78707 +{
78708 + xt_unregister_match(&gradm_mt_reg);
78709 +}
78710 +
78711 +module_init(gradm_mt_init);
78712 +module_exit(gradm_mt_exit);
78713 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78714 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78715 +MODULE_LICENSE("GPL");
78716 +MODULE_ALIAS("ipt_gradm");
78717 +MODULE_ALIAS("ip6t_gradm");
78718 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78719 index 4fe4fb4..87a89e5 100644
78720 --- a/net/netfilter/xt_statistic.c
78721 +++ b/net/netfilter/xt_statistic.c
78722 @@ -19,7 +19,7 @@
78723 #include <linux/module.h>
78724
78725 struct xt_statistic_priv {
78726 - atomic_t count;
78727 + atomic_unchecked_t count;
78728 } ____cacheline_aligned_in_smp;
78729
78730 MODULE_LICENSE("GPL");
78731 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78732 break;
78733 case XT_STATISTIC_MODE_NTH:
78734 do {
78735 - oval = atomic_read(&info->master->count);
78736 + oval = atomic_read_unchecked(&info->master->count);
78737 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78738 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78739 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78740 if (nval == 0)
78741 ret = !ret;
78742 break;
78743 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78744 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78745 if (info->master == NULL)
78746 return -ENOMEM;
78747 - atomic_set(&info->master->count, info->u.nth.count);
78748 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78749
78750 return 0;
78751 }
78752 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78753 index 4da797f..eb1df70 100644
78754 --- a/net/netlink/af_netlink.c
78755 +++ b/net/netlink/af_netlink.c
78756 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
78757 sk->sk_error_report(sk);
78758 }
78759 }
78760 - atomic_inc(&sk->sk_drops);
78761 + atomic_inc_unchecked(&sk->sk_drops);
78762 }
78763
78764 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
78765 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78766 sk_wmem_alloc_get(s),
78767 nlk->cb,
78768 atomic_read(&s->sk_refcnt),
78769 - atomic_read(&s->sk_drops),
78770 + atomic_read_unchecked(&s->sk_drops),
78771 sock_i_ino(s)
78772 );
78773
78774 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78775 index 7261eb8..44e8ac6 100644
78776 --- a/net/netrom/af_netrom.c
78777 +++ b/net/netrom/af_netrom.c
78778 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78779 struct sock *sk = sock->sk;
78780 struct nr_sock *nr = nr_sk(sk);
78781
78782 + memset(sax, 0, sizeof(*sax));
78783 lock_sock(sk);
78784 if (peer != 0) {
78785 if (sk->sk_state != TCP_ESTABLISHED) {
78786 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78787 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78788 } else {
78789 sax->fsa_ax25.sax25_family = AF_NETROM;
78790 - sax->fsa_ax25.sax25_ndigis = 0;
78791 sax->fsa_ax25.sax25_call = nr->source_addr;
78792 *uaddr_len = sizeof(struct sockaddr_ax25);
78793 }
78794 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78795 index 94060ed..9c066f3 100644
78796 --- a/net/packet/af_packet.c
78797 +++ b/net/packet/af_packet.c
78798 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78799
78800 spin_lock(&sk->sk_receive_queue.lock);
78801 po->stats.tp_packets++;
78802 - skb->dropcount = atomic_read(&sk->sk_drops);
78803 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78804 __skb_queue_tail(&sk->sk_receive_queue, skb);
78805 spin_unlock(&sk->sk_receive_queue.lock);
78806 sk->sk_data_ready(sk, skb->len);
78807 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78808 drop_n_acct:
78809 spin_lock(&sk->sk_receive_queue.lock);
78810 po->stats.tp_drops++;
78811 - atomic_inc(&sk->sk_drops);
78812 + atomic_inc_unchecked(&sk->sk_drops);
78813 spin_unlock(&sk->sk_receive_queue.lock);
78814
78815 drop_n_restore:
78816 @@ -2537,6 +2537,7 @@ out:
78817
78818 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78819 {
78820 + struct sock_extended_err ee;
78821 struct sock_exterr_skb *serr;
78822 struct sk_buff *skb, *skb2;
78823 int copied, err;
78824 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78825 sock_recv_timestamp(msg, sk, skb);
78826
78827 serr = SKB_EXT_ERR(skb);
78828 + ee = serr->ee;
78829 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78830 - sizeof(serr->ee), &serr->ee);
78831 + sizeof ee, &ee);
78832
78833 msg->msg_flags |= MSG_ERRQUEUE;
78834 err = copied;
78835 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78836 case PACKET_HDRLEN:
78837 if (len > sizeof(int))
78838 len = sizeof(int);
78839 - if (copy_from_user(&val, optval, len))
78840 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78841 return -EFAULT;
78842 switch (val) {
78843 case TPACKET_V1:
78844 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78845 len = lv;
78846 if (put_user(len, optlen))
78847 return -EFAULT;
78848 - if (copy_to_user(optval, data, len))
78849 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78850 return -EFAULT;
78851 return 0;
78852 }
78853 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78854 index 5a940db..f0b9c12 100644
78855 --- a/net/phonet/af_phonet.c
78856 +++ b/net/phonet/af_phonet.c
78857 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78858 {
78859 struct phonet_protocol *pp;
78860
78861 - if (protocol >= PHONET_NPROTO)
78862 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78863 return NULL;
78864
78865 rcu_read_lock();
78866 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78867 {
78868 int err = 0;
78869
78870 - if (protocol >= PHONET_NPROTO)
78871 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78872 return -EINVAL;
78873
78874 err = proto_register(pp->prot, 1);
78875 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78876 index 576f22c..bc7a71b 100644
78877 --- a/net/phonet/pep.c
78878 +++ b/net/phonet/pep.c
78879 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78880
78881 case PNS_PEP_CTRL_REQ:
78882 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78883 - atomic_inc(&sk->sk_drops);
78884 + atomic_inc_unchecked(&sk->sk_drops);
78885 break;
78886 }
78887 __skb_pull(skb, 4);
78888 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78889 }
78890
78891 if (pn->rx_credits == 0) {
78892 - atomic_inc(&sk->sk_drops);
78893 + atomic_inc_unchecked(&sk->sk_drops);
78894 err = -ENOBUFS;
78895 break;
78896 }
78897 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78898 }
78899
78900 if (pn->rx_credits == 0) {
78901 - atomic_inc(&sk->sk_drops);
78902 + atomic_inc_unchecked(&sk->sk_drops);
78903 err = NET_RX_DROP;
78904 break;
78905 }
78906 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78907 index b7e9827..c264c85 100644
78908 --- a/net/phonet/socket.c
78909 +++ b/net/phonet/socket.c
78910 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78911 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
78912 sock_i_ino(sk),
78913 atomic_read(&sk->sk_refcnt), sk,
78914 - atomic_read(&sk->sk_drops), &len);
78915 + atomic_read_unchecked(&sk->sk_drops), &len);
78916 }
78917 seq_printf(seq, "%*s\n", 127 - len, "");
78918 return 0;
78919 diff --git a/net/rds/cong.c b/net/rds/cong.c
78920 index e5b65ac..f3b6fb7 100644
78921 --- a/net/rds/cong.c
78922 +++ b/net/rds/cong.c
78923 @@ -78,7 +78,7 @@
78924 * finds that the saved generation number is smaller than the global generation
78925 * number, it wakes up the process.
78926 */
78927 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78928 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78929
78930 /*
78931 * Congestion monitoring
78932 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78933 rdsdebug("waking map %p for %pI4\n",
78934 map, &map->m_addr);
78935 rds_stats_inc(s_cong_update_received);
78936 - atomic_inc(&rds_cong_generation);
78937 + atomic_inc_unchecked(&rds_cong_generation);
78938 if (waitqueue_active(&map->m_waitq))
78939 wake_up(&map->m_waitq);
78940 if (waitqueue_active(&rds_poll_waitq))
78941 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78942
78943 int rds_cong_updated_since(unsigned long *recent)
78944 {
78945 - unsigned long gen = atomic_read(&rds_cong_generation);
78946 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78947
78948 if (likely(*recent == gen))
78949 return 0;
78950 diff --git a/net/rds/ib.h b/net/rds/ib.h
78951 index 8d2b3d5..227ec5b 100644
78952 --- a/net/rds/ib.h
78953 +++ b/net/rds/ib.h
78954 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78955 /* sending acks */
78956 unsigned long i_ack_flags;
78957 #ifdef KERNEL_HAS_ATOMIC64
78958 - atomic64_t i_ack_next; /* next ACK to send */
78959 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78960 #else
78961 spinlock_t i_ack_lock; /* protect i_ack_next */
78962 u64 i_ack_next; /* next ACK to send */
78963 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78964 index a1e1162..265e129 100644
78965 --- a/net/rds/ib_cm.c
78966 +++ b/net/rds/ib_cm.c
78967 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78968 /* Clear the ACK state */
78969 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78970 #ifdef KERNEL_HAS_ATOMIC64
78971 - atomic64_set(&ic->i_ack_next, 0);
78972 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78973 #else
78974 ic->i_ack_next = 0;
78975 #endif
78976 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78977 index 8d19491..05a3e65 100644
78978 --- a/net/rds/ib_recv.c
78979 +++ b/net/rds/ib_recv.c
78980 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78981 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78982 int ack_required)
78983 {
78984 - atomic64_set(&ic->i_ack_next, seq);
78985 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78986 if (ack_required) {
78987 smp_mb__before_clear_bit();
78988 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78989 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78990 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78991 smp_mb__after_clear_bit();
78992
78993 - return atomic64_read(&ic->i_ack_next);
78994 + return atomic64_read_unchecked(&ic->i_ack_next);
78995 }
78996 #endif
78997
78998 diff --git a/net/rds/iw.h b/net/rds/iw.h
78999 index 04ce3b1..48119a6 100644
79000 --- a/net/rds/iw.h
79001 +++ b/net/rds/iw.h
79002 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79003 /* sending acks */
79004 unsigned long i_ack_flags;
79005 #ifdef KERNEL_HAS_ATOMIC64
79006 - atomic64_t i_ack_next; /* next ACK to send */
79007 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79008 #else
79009 spinlock_t i_ack_lock; /* protect i_ack_next */
79010 u64 i_ack_next; /* next ACK to send */
79011 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79012 index a91e1db..cf3053f 100644
79013 --- a/net/rds/iw_cm.c
79014 +++ b/net/rds/iw_cm.c
79015 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79016 /* Clear the ACK state */
79017 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79018 #ifdef KERNEL_HAS_ATOMIC64
79019 - atomic64_set(&ic->i_ack_next, 0);
79020 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79021 #else
79022 ic->i_ack_next = 0;
79023 #endif
79024 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79025 index 4503335..db566b4 100644
79026 --- a/net/rds/iw_recv.c
79027 +++ b/net/rds/iw_recv.c
79028 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79029 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79030 int ack_required)
79031 {
79032 - atomic64_set(&ic->i_ack_next, seq);
79033 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79034 if (ack_required) {
79035 smp_mb__before_clear_bit();
79036 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79037 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79038 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79039 smp_mb__after_clear_bit();
79040
79041 - return atomic64_read(&ic->i_ack_next);
79042 + return atomic64_read_unchecked(&ic->i_ack_next);
79043 }
79044 #endif
79045
79046 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79047 index edac9ef..16bcb98 100644
79048 --- a/net/rds/tcp.c
79049 +++ b/net/rds/tcp.c
79050 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79051 int val = 1;
79052
79053 set_fs(KERNEL_DS);
79054 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79055 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79056 sizeof(val));
79057 set_fs(oldfs);
79058 }
79059 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79060 index 81cf5a4..b5826ff 100644
79061 --- a/net/rds/tcp_send.c
79062 +++ b/net/rds/tcp_send.c
79063 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79064
79065 oldfs = get_fs();
79066 set_fs(KERNEL_DS);
79067 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79068 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79069 sizeof(val));
79070 set_fs(oldfs);
79071 }
79072 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79073 index 05996d0..5a1dfe0 100644
79074 --- a/net/rxrpc/af_rxrpc.c
79075 +++ b/net/rxrpc/af_rxrpc.c
79076 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79077 __be32 rxrpc_epoch;
79078
79079 /* current debugging ID */
79080 -atomic_t rxrpc_debug_id;
79081 +atomic_unchecked_t rxrpc_debug_id;
79082
79083 /* count of skbs currently in use */
79084 atomic_t rxrpc_n_skbs;
79085 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79086 index e4d9cbc..b229649 100644
79087 --- a/net/rxrpc/ar-ack.c
79088 +++ b/net/rxrpc/ar-ack.c
79089 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79090
79091 _enter("{%d,%d,%d,%d},",
79092 call->acks_hard, call->acks_unacked,
79093 - atomic_read(&call->sequence),
79094 + atomic_read_unchecked(&call->sequence),
79095 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79096
79097 stop = 0;
79098 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79099
79100 /* each Tx packet has a new serial number */
79101 sp->hdr.serial =
79102 - htonl(atomic_inc_return(&call->conn->serial));
79103 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79104
79105 hdr = (struct rxrpc_header *) txb->head;
79106 hdr->serial = sp->hdr.serial;
79107 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79108 */
79109 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79110 {
79111 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79112 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79113 }
79114
79115 /*
79116 @@ -629,7 +629,7 @@ process_further:
79117
79118 latest = ntohl(sp->hdr.serial);
79119 hard = ntohl(ack.firstPacket);
79120 - tx = atomic_read(&call->sequence);
79121 + tx = atomic_read_unchecked(&call->sequence);
79122
79123 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79124 latest,
79125 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79126 goto maybe_reschedule;
79127
79128 send_ACK_with_skew:
79129 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79130 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79131 ntohl(ack.serial));
79132 send_ACK:
79133 mtu = call->conn->trans->peer->if_mtu;
79134 @@ -1173,7 +1173,7 @@ send_ACK:
79135 ackinfo.rxMTU = htonl(5692);
79136 ackinfo.jumbo_max = htonl(4);
79137
79138 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79139 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79140 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79141 ntohl(hdr.serial),
79142 ntohs(ack.maxSkew),
79143 @@ -1191,7 +1191,7 @@ send_ACK:
79144 send_message:
79145 _debug("send message");
79146
79147 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79148 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79149 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79150 send_message_2:
79151
79152 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79153 index a3bbb36..3341fb9 100644
79154 --- a/net/rxrpc/ar-call.c
79155 +++ b/net/rxrpc/ar-call.c
79156 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79157 spin_lock_init(&call->lock);
79158 rwlock_init(&call->state_lock);
79159 atomic_set(&call->usage, 1);
79160 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79161 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79162 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79163
79164 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79165 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79166 index 4106ca9..a338d7a 100644
79167 --- a/net/rxrpc/ar-connection.c
79168 +++ b/net/rxrpc/ar-connection.c
79169 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79170 rwlock_init(&conn->lock);
79171 spin_lock_init(&conn->state_lock);
79172 atomic_set(&conn->usage, 1);
79173 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79174 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79175 conn->avail_calls = RXRPC_MAXCALLS;
79176 conn->size_align = 4;
79177 conn->header_size = sizeof(struct rxrpc_header);
79178 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79179 index e7ed43a..6afa140 100644
79180 --- a/net/rxrpc/ar-connevent.c
79181 +++ b/net/rxrpc/ar-connevent.c
79182 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79183
79184 len = iov[0].iov_len + iov[1].iov_len;
79185
79186 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79187 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79188 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79189
79190 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79191 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79192 index 529572f..c758ca7 100644
79193 --- a/net/rxrpc/ar-input.c
79194 +++ b/net/rxrpc/ar-input.c
79195 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79196 /* track the latest serial number on this connection for ACK packet
79197 * information */
79198 serial = ntohl(sp->hdr.serial);
79199 - hi_serial = atomic_read(&call->conn->hi_serial);
79200 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79201 while (serial > hi_serial)
79202 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79203 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79204 serial);
79205
79206 /* request ACK generation for any ACK or DATA packet that requests
79207 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79208 index a693aca..81e7293 100644
79209 --- a/net/rxrpc/ar-internal.h
79210 +++ b/net/rxrpc/ar-internal.h
79211 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79212 int error; /* error code for local abort */
79213 int debug_id; /* debug ID for printks */
79214 unsigned int call_counter; /* call ID counter */
79215 - atomic_t serial; /* packet serial number counter */
79216 - atomic_t hi_serial; /* highest serial number received */
79217 + atomic_unchecked_t serial; /* packet serial number counter */
79218 + atomic_unchecked_t hi_serial; /* highest serial number received */
79219 u8 avail_calls; /* number of calls available */
79220 u8 size_align; /* data size alignment (for security) */
79221 u8 header_size; /* rxrpc + security header size */
79222 @@ -346,7 +346,7 @@ struct rxrpc_call {
79223 spinlock_t lock;
79224 rwlock_t state_lock; /* lock for state transition */
79225 atomic_t usage;
79226 - atomic_t sequence; /* Tx data packet sequence counter */
79227 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79228 u32 abort_code; /* local/remote abort code */
79229 enum { /* current state of call */
79230 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79231 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79232 */
79233 extern atomic_t rxrpc_n_skbs;
79234 extern __be32 rxrpc_epoch;
79235 -extern atomic_t rxrpc_debug_id;
79236 +extern atomic_unchecked_t rxrpc_debug_id;
79237 extern struct workqueue_struct *rxrpc_workqueue;
79238
79239 /*
79240 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79241 index 87f7135..74d3703 100644
79242 --- a/net/rxrpc/ar-local.c
79243 +++ b/net/rxrpc/ar-local.c
79244 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79245 spin_lock_init(&local->lock);
79246 rwlock_init(&local->services_lock);
79247 atomic_set(&local->usage, 1);
79248 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79249 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79250 memcpy(&local->srx, srx, sizeof(*srx));
79251 }
79252
79253 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79254 index e1ac183..b43e10e 100644
79255 --- a/net/rxrpc/ar-output.c
79256 +++ b/net/rxrpc/ar-output.c
79257 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79258 sp->hdr.cid = call->cid;
79259 sp->hdr.callNumber = call->call_id;
79260 sp->hdr.seq =
79261 - htonl(atomic_inc_return(&call->sequence));
79262 + htonl(atomic_inc_return_unchecked(&call->sequence));
79263 sp->hdr.serial =
79264 - htonl(atomic_inc_return(&conn->serial));
79265 + htonl(atomic_inc_return_unchecked(&conn->serial));
79266 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79267 sp->hdr.userStatus = 0;
79268 sp->hdr.securityIndex = conn->security_ix;
79269 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79270 index bebaa43..2644591 100644
79271 --- a/net/rxrpc/ar-peer.c
79272 +++ b/net/rxrpc/ar-peer.c
79273 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79274 INIT_LIST_HEAD(&peer->error_targets);
79275 spin_lock_init(&peer->lock);
79276 atomic_set(&peer->usage, 1);
79277 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79278 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79279 memcpy(&peer->srx, srx, sizeof(*srx));
79280
79281 rxrpc_assess_MTU_size(peer);
79282 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79283 index 38047f7..9f48511 100644
79284 --- a/net/rxrpc/ar-proc.c
79285 +++ b/net/rxrpc/ar-proc.c
79286 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79287 atomic_read(&conn->usage),
79288 rxrpc_conn_states[conn->state],
79289 key_serial(conn->key),
79290 - atomic_read(&conn->serial),
79291 - atomic_read(&conn->hi_serial));
79292 + atomic_read_unchecked(&conn->serial),
79293 + atomic_read_unchecked(&conn->hi_serial));
79294
79295 return 0;
79296 }
79297 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79298 index 92df566..87ec1bf 100644
79299 --- a/net/rxrpc/ar-transport.c
79300 +++ b/net/rxrpc/ar-transport.c
79301 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79302 spin_lock_init(&trans->client_lock);
79303 rwlock_init(&trans->conn_lock);
79304 atomic_set(&trans->usage, 1);
79305 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79306 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79307
79308 if (peer->srx.transport.family == AF_INET) {
79309 switch (peer->srx.transport_type) {
79310 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79311 index f226709..0e735a8 100644
79312 --- a/net/rxrpc/rxkad.c
79313 +++ b/net/rxrpc/rxkad.c
79314 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79315
79316 len = iov[0].iov_len + iov[1].iov_len;
79317
79318 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79319 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79320 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79321
79322 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79323 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79324
79325 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79326
79327 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79328 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79329 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79330
79331 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79332 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79333 index 9966e7b..540c575 100644
79334 --- a/net/sctp/proc.c
79335 +++ b/net/sctp/proc.c
79336 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79337 seq_printf(seq,
79338 "%8pK %8pK %-3d %-3d %-2d %-4d "
79339 "%4d %8d %8d %7d %5lu %-5d %5d ",
79340 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79341 + assoc, sk,
79342 + sctp_sk(sk)->type, sk->sk_state,
79343 assoc->state, hash,
79344 assoc->assoc_id,
79345 assoc->sndbuf_used,
79346 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79347 index 406d957..543c737 100644
79348 --- a/net/sctp/socket.c
79349 +++ b/net/sctp/socket.c
79350 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79351 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79352 if (space_left < addrlen)
79353 return -ENOMEM;
79354 + if (addrlen > sizeof(temp) || addrlen < 0)
79355 + return -EFAULT;
79356 if (copy_to_user(to, &temp, addrlen))
79357 return -EFAULT;
79358 to += addrlen;
79359 diff --git a/net/socket.c b/net/socket.c
79360 index d92c490..b4bc863 100644
79361 --- a/net/socket.c
79362 +++ b/net/socket.c
79363 @@ -89,6 +89,7 @@
79364 #include <linux/magic.h>
79365 #include <linux/slab.h>
79366 #include <linux/xattr.h>
79367 +#include <linux/in.h>
79368
79369 #include <asm/uaccess.h>
79370 #include <asm/unistd.h>
79371 @@ -106,6 +107,8 @@
79372 #include <linux/sockios.h>
79373 #include <linux/atalk.h>
79374
79375 +#include <linux/grsock.h>
79376 +
79377 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79378 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79379 unsigned long nr_segs, loff_t pos);
79380 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79381 &sockfs_dentry_operations, SOCKFS_MAGIC);
79382 }
79383
79384 -static struct vfsmount *sock_mnt __read_mostly;
79385 +struct vfsmount *sock_mnt __read_mostly;
79386
79387 static struct file_system_type sock_fs_type = {
79388 .name = "sockfs",
79389 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79390 return -EAFNOSUPPORT;
79391 if (type < 0 || type >= SOCK_MAX)
79392 return -EINVAL;
79393 + if (protocol < 0)
79394 + return -EINVAL;
79395
79396 /* Compatibility.
79397
79398 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79399 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79400 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79401
79402 + if(!gr_search_socket(family, type, protocol)) {
79403 + retval = -EACCES;
79404 + goto out;
79405 + }
79406 +
79407 + if (gr_handle_sock_all(family, type, protocol)) {
79408 + retval = -EACCES;
79409 + goto out;
79410 + }
79411 +
79412 retval = sock_create(family, type, protocol, &sock);
79413 if (retval < 0)
79414 goto out;
79415 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79416 if (sock) {
79417 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79418 if (err >= 0) {
79419 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79420 + err = -EACCES;
79421 + goto error;
79422 + }
79423 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79424 + if (err)
79425 + goto error;
79426 +
79427 err = security_socket_bind(sock,
79428 (struct sockaddr *)&address,
79429 addrlen);
79430 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79431 (struct sockaddr *)
79432 &address, addrlen);
79433 }
79434 +error:
79435 fput_light(sock->file, fput_needed);
79436 }
79437 return err;
79438 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79439 if ((unsigned int)backlog > somaxconn)
79440 backlog = somaxconn;
79441
79442 + if (gr_handle_sock_server_other(sock->sk)) {
79443 + err = -EPERM;
79444 + goto error;
79445 + }
79446 +
79447 + err = gr_search_listen(sock);
79448 + if (err)
79449 + goto error;
79450 +
79451 err = security_socket_listen(sock, backlog);
79452 if (!err)
79453 err = sock->ops->listen(sock, backlog);
79454
79455 +error:
79456 fput_light(sock->file, fput_needed);
79457 }
79458 return err;
79459 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79460 newsock->type = sock->type;
79461 newsock->ops = sock->ops;
79462
79463 + if (gr_handle_sock_server_other(sock->sk)) {
79464 + err = -EPERM;
79465 + sock_release(newsock);
79466 + goto out_put;
79467 + }
79468 +
79469 + err = gr_search_accept(sock);
79470 + if (err) {
79471 + sock_release(newsock);
79472 + goto out_put;
79473 + }
79474 +
79475 /*
79476 * We don't need try_module_get here, as the listening socket (sock)
79477 * has the protocol module (sock->ops->owner) held.
79478 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79479 fd_install(newfd, newfile);
79480 err = newfd;
79481
79482 + gr_attach_curr_ip(newsock->sk);
79483 +
79484 out_put:
79485 fput_light(sock->file, fput_needed);
79486 out:
79487 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79488 int, addrlen)
79489 {
79490 struct socket *sock;
79491 + struct sockaddr *sck;
79492 struct sockaddr_storage address;
79493 int err, fput_needed;
79494
79495 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79496 if (err < 0)
79497 goto out_put;
79498
79499 + sck = (struct sockaddr *)&address;
79500 +
79501 + if (gr_handle_sock_client(sck)) {
79502 + err = -EACCES;
79503 + goto out_put;
79504 + }
79505 +
79506 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79507 + if (err)
79508 + goto out_put;
79509 +
79510 err =
79511 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79512 if (err)
79513 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79514 * checking falls down on this.
79515 */
79516 if (copy_from_user(ctl_buf,
79517 - (void __user __force *)msg_sys->msg_control,
79518 + (void __force_user *)msg_sys->msg_control,
79519 ctl_len))
79520 goto out_freectl;
79521 msg_sys->msg_control = ctl_buf;
79522 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79523 * kernel msghdr to use the kernel address space)
79524 */
79525
79526 - uaddr = (__force void __user *)msg_sys->msg_name;
79527 + uaddr = (void __force_user *)msg_sys->msg_name;
79528 uaddr_len = COMPAT_NAMELEN(msg);
79529 if (MSG_CMSG_COMPAT & flags) {
79530 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79531 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79532 }
79533
79534 ifr = compat_alloc_user_space(buf_size);
79535 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79536 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79537
79538 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79539 return -EFAULT;
79540 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79541 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79542
79543 if (copy_in_user(rxnfc, compat_rxnfc,
79544 - (void *)(&rxnfc->fs.m_ext + 1) -
79545 - (void *)rxnfc) ||
79546 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79547 + (void __user *)rxnfc) ||
79548 copy_in_user(&rxnfc->fs.ring_cookie,
79549 &compat_rxnfc->fs.ring_cookie,
79550 - (void *)(&rxnfc->fs.location + 1) -
79551 - (void *)&rxnfc->fs.ring_cookie) ||
79552 + (void __user *)(&rxnfc->fs.location + 1) -
79553 + (void __user *)&rxnfc->fs.ring_cookie) ||
79554 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79555 sizeof(rxnfc->rule_cnt)))
79556 return -EFAULT;
79557 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79558
79559 if (convert_out) {
79560 if (copy_in_user(compat_rxnfc, rxnfc,
79561 - (const void *)(&rxnfc->fs.m_ext + 1) -
79562 - (const void *)rxnfc) ||
79563 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79564 + (const void __user *)rxnfc) ||
79565 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79566 &rxnfc->fs.ring_cookie,
79567 - (const void *)(&rxnfc->fs.location + 1) -
79568 - (const void *)&rxnfc->fs.ring_cookie) ||
79569 + (const void __user *)(&rxnfc->fs.location + 1) -
79570 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79571 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79572 sizeof(rxnfc->rule_cnt)))
79573 return -EFAULT;
79574 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79575 old_fs = get_fs();
79576 set_fs(KERNEL_DS);
79577 err = dev_ioctl(net, cmd,
79578 - (struct ifreq __user __force *) &kifr);
79579 + (struct ifreq __force_user *) &kifr);
79580 set_fs(old_fs);
79581
79582 return err;
79583 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79584
79585 old_fs = get_fs();
79586 set_fs(KERNEL_DS);
79587 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79588 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79589 set_fs(old_fs);
79590
79591 if (cmd == SIOCGIFMAP && !err) {
79592 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79593 ret |= __get_user(rtdev, &(ur4->rt_dev));
79594 if (rtdev) {
79595 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79596 - r4.rt_dev = (char __user __force *)devname;
79597 + r4.rt_dev = (char __force_user *)devname;
79598 devname[15] = 0;
79599 } else
79600 r4.rt_dev = NULL;
79601 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79602 int __user *uoptlen;
79603 int err;
79604
79605 - uoptval = (char __user __force *) optval;
79606 - uoptlen = (int __user __force *) optlen;
79607 + uoptval = (char __force_user *) optval;
79608 + uoptlen = (int __force_user *) optlen;
79609
79610 set_fs(KERNEL_DS);
79611 if (level == SOL_SOCKET)
79612 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79613 char __user *uoptval;
79614 int err;
79615
79616 - uoptval = (char __user __force *) optval;
79617 + uoptval = (char __force_user *) optval;
79618
79619 set_fs(KERNEL_DS);
79620 if (level == SOL_SOCKET)
79621 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79622 index 6357fcb..244c7db 100644
79623 --- a/net/sunrpc/sched.c
79624 +++ b/net/sunrpc/sched.c
79625 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79626 #ifdef RPC_DEBUG
79627 static void rpc_task_set_debuginfo(struct rpc_task *task)
79628 {
79629 - static atomic_t rpc_pid;
79630 + static atomic_unchecked_t rpc_pid;
79631
79632 - task->tk_pid = atomic_inc_return(&rpc_pid);
79633 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79634 }
79635 #else
79636 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79637 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79638 index 8343737..677025e 100644
79639 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79640 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79641 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79642 static unsigned int min_max_inline = 4096;
79643 static unsigned int max_max_inline = 65536;
79644
79645 -atomic_t rdma_stat_recv;
79646 -atomic_t rdma_stat_read;
79647 -atomic_t rdma_stat_write;
79648 -atomic_t rdma_stat_sq_starve;
79649 -atomic_t rdma_stat_rq_starve;
79650 -atomic_t rdma_stat_rq_poll;
79651 -atomic_t rdma_stat_rq_prod;
79652 -atomic_t rdma_stat_sq_poll;
79653 -atomic_t rdma_stat_sq_prod;
79654 +atomic_unchecked_t rdma_stat_recv;
79655 +atomic_unchecked_t rdma_stat_read;
79656 +atomic_unchecked_t rdma_stat_write;
79657 +atomic_unchecked_t rdma_stat_sq_starve;
79658 +atomic_unchecked_t rdma_stat_rq_starve;
79659 +atomic_unchecked_t rdma_stat_rq_poll;
79660 +atomic_unchecked_t rdma_stat_rq_prod;
79661 +atomic_unchecked_t rdma_stat_sq_poll;
79662 +atomic_unchecked_t rdma_stat_sq_prod;
79663
79664 /* Temporary NFS request map and context caches */
79665 struct kmem_cache *svc_rdma_map_cachep;
79666 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79667 len -= *ppos;
79668 if (len > *lenp)
79669 len = *lenp;
79670 - if (len && copy_to_user(buffer, str_buf, len))
79671 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79672 return -EFAULT;
79673 *lenp = len;
79674 *ppos += len;
79675 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79676 {
79677 .procname = "rdma_stat_read",
79678 .data = &rdma_stat_read,
79679 - .maxlen = sizeof(atomic_t),
79680 + .maxlen = sizeof(atomic_unchecked_t),
79681 .mode = 0644,
79682 .proc_handler = read_reset_stat,
79683 },
79684 {
79685 .procname = "rdma_stat_recv",
79686 .data = &rdma_stat_recv,
79687 - .maxlen = sizeof(atomic_t),
79688 + .maxlen = sizeof(atomic_unchecked_t),
79689 .mode = 0644,
79690 .proc_handler = read_reset_stat,
79691 },
79692 {
79693 .procname = "rdma_stat_write",
79694 .data = &rdma_stat_write,
79695 - .maxlen = sizeof(atomic_t),
79696 + .maxlen = sizeof(atomic_unchecked_t),
79697 .mode = 0644,
79698 .proc_handler = read_reset_stat,
79699 },
79700 {
79701 .procname = "rdma_stat_sq_starve",
79702 .data = &rdma_stat_sq_starve,
79703 - .maxlen = sizeof(atomic_t),
79704 + .maxlen = sizeof(atomic_unchecked_t),
79705 .mode = 0644,
79706 .proc_handler = read_reset_stat,
79707 },
79708 {
79709 .procname = "rdma_stat_rq_starve",
79710 .data = &rdma_stat_rq_starve,
79711 - .maxlen = sizeof(atomic_t),
79712 + .maxlen = sizeof(atomic_unchecked_t),
79713 .mode = 0644,
79714 .proc_handler = read_reset_stat,
79715 },
79716 {
79717 .procname = "rdma_stat_rq_poll",
79718 .data = &rdma_stat_rq_poll,
79719 - .maxlen = sizeof(atomic_t),
79720 + .maxlen = sizeof(atomic_unchecked_t),
79721 .mode = 0644,
79722 .proc_handler = read_reset_stat,
79723 },
79724 {
79725 .procname = "rdma_stat_rq_prod",
79726 .data = &rdma_stat_rq_prod,
79727 - .maxlen = sizeof(atomic_t),
79728 + .maxlen = sizeof(atomic_unchecked_t),
79729 .mode = 0644,
79730 .proc_handler = read_reset_stat,
79731 },
79732 {
79733 .procname = "rdma_stat_sq_poll",
79734 .data = &rdma_stat_sq_poll,
79735 - .maxlen = sizeof(atomic_t),
79736 + .maxlen = sizeof(atomic_unchecked_t),
79737 .mode = 0644,
79738 .proc_handler = read_reset_stat,
79739 },
79740 {
79741 .procname = "rdma_stat_sq_prod",
79742 .data = &rdma_stat_sq_prod,
79743 - .maxlen = sizeof(atomic_t),
79744 + .maxlen = sizeof(atomic_unchecked_t),
79745 .mode = 0644,
79746 .proc_handler = read_reset_stat,
79747 },
79748 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79749 index 41cb63b..c4a1489 100644
79750 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79751 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79752 @@ -501,7 +501,7 @@ next_sge:
79753 svc_rdma_put_context(ctxt, 0);
79754 goto out;
79755 }
79756 - atomic_inc(&rdma_stat_read);
79757 + atomic_inc_unchecked(&rdma_stat_read);
79758
79759 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79760 chl_map->ch[ch_no].count -= read_wr.num_sge;
79761 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79762 dto_q);
79763 list_del_init(&ctxt->dto_q);
79764 } else {
79765 - atomic_inc(&rdma_stat_rq_starve);
79766 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79767 clear_bit(XPT_DATA, &xprt->xpt_flags);
79768 ctxt = NULL;
79769 }
79770 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79771 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79772 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79773 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79774 - atomic_inc(&rdma_stat_recv);
79775 + atomic_inc_unchecked(&rdma_stat_recv);
79776
79777 /* Build up the XDR from the receive buffers. */
79778 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79779 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79780 index 42eb7ba..c887c45 100644
79781 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79782 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79783 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79784 write_wr.wr.rdma.remote_addr = to;
79785
79786 /* Post It */
79787 - atomic_inc(&rdma_stat_write);
79788 + atomic_inc_unchecked(&rdma_stat_write);
79789 if (svc_rdma_send(xprt, &write_wr))
79790 goto err;
79791 return 0;
79792 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79793 index 62e4f9b..dd3f2d7 100644
79794 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79795 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79796 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79797 return;
79798
79799 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79800 - atomic_inc(&rdma_stat_rq_poll);
79801 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79802
79803 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79804 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79805 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79806 }
79807
79808 if (ctxt)
79809 - atomic_inc(&rdma_stat_rq_prod);
79810 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79811
79812 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79813 /*
79814 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79815 return;
79816
79817 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79818 - atomic_inc(&rdma_stat_sq_poll);
79819 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79820 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79821 if (wc.status != IB_WC_SUCCESS)
79822 /* Close the transport */
79823 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79824 }
79825
79826 if (ctxt)
79827 - atomic_inc(&rdma_stat_sq_prod);
79828 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79829 }
79830
79831 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79832 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79833 spin_lock_bh(&xprt->sc_lock);
79834 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79835 spin_unlock_bh(&xprt->sc_lock);
79836 - atomic_inc(&rdma_stat_sq_starve);
79837 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79838
79839 /* See if we can opportunistically reap SQ WR to make room */
79840 sq_cq_reap(xprt);
79841 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79842 index e3a6e37..be2ea77 100644
79843 --- a/net/sysctl_net.c
79844 +++ b/net/sysctl_net.c
79845 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79846 struct ctl_table *table)
79847 {
79848 /* Allow network administrator to have same access as root. */
79849 - if (capable(CAP_NET_ADMIN)) {
79850 + if (capable_nolog(CAP_NET_ADMIN)) {
79851 int mode = (table->mode >> 6) & 7;
79852 return (mode << 6) | (mode << 3) | mode;
79853 }
79854 diff --git a/net/tipc/link.c b/net/tipc/link.c
79855 index a79c755..eca357d 100644
79856 --- a/net/tipc/link.c
79857 +++ b/net/tipc/link.c
79858 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79859 struct tipc_msg fragm_hdr;
79860 struct sk_buff *buf, *buf_chain, *prev;
79861 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79862 - const unchar *sect_crs;
79863 + const unchar __user *sect_crs;
79864 int curr_sect;
79865 u32 fragm_no;
79866
79867 @@ -1210,7 +1210,7 @@ again:
79868
79869 if (!sect_rest) {
79870 sect_rest = msg_sect[++curr_sect].iov_len;
79871 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79872 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79873 }
79874
79875 if (sect_rest < fragm_rest)
79876 @@ -1229,7 +1229,7 @@ error:
79877 }
79878 } else
79879 skb_copy_to_linear_data_offset(buf, fragm_crs,
79880 - sect_crs, sz);
79881 + (const void __force_kernel *)sect_crs, sz);
79882 sect_crs += sz;
79883 sect_rest -= sz;
79884 fragm_crs += sz;
79885 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79886 index f2db8a8..9245aa4 100644
79887 --- a/net/tipc/msg.c
79888 +++ b/net/tipc/msg.c
79889 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79890 msg_sect[cnt].iov_len);
79891 else
79892 skb_copy_to_linear_data_offset(*buf, pos,
79893 - msg_sect[cnt].iov_base,
79894 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79895 msg_sect[cnt].iov_len);
79896 pos += msg_sect[cnt].iov_len;
79897 }
79898 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79899 index 0f7d0d0..00f89bf 100644
79900 --- a/net/tipc/subscr.c
79901 +++ b/net/tipc/subscr.c
79902 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79903 {
79904 struct iovec msg_sect;
79905
79906 - msg_sect.iov_base = (void *)&sub->evt;
79907 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79908 msg_sect.iov_len = sizeof(struct tipc_event);
79909
79910 sub->evt.event = htohl(event, sub->swap);
79911 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79912 index 5b5c876..3127bf7 100644
79913 --- a/net/unix/af_unix.c
79914 +++ b/net/unix/af_unix.c
79915 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
79916 err = -ECONNREFUSED;
79917 if (!S_ISSOCK(inode->i_mode))
79918 goto put_fail;
79919 +
79920 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79921 + err = -EACCES;
79922 + goto put_fail;
79923 + }
79924 +
79925 u = unix_find_socket_byinode(inode);
79926 if (!u)
79927 goto put_fail;
79928 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
79929 if (u) {
79930 struct dentry *dentry;
79931 dentry = unix_sk(u)->path.dentry;
79932 +
79933 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79934 + err = -EPERM;
79935 + sock_put(u);
79936 + goto fail;
79937 + }
79938 +
79939 if (dentry)
79940 touch_atime(&unix_sk(u)->path);
79941 } else
79942 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79943 */
79944 err = security_path_mknod(&path, dentry, mode, 0);
79945 if (!err) {
79946 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79947 + err = -EACCES;
79948 + goto out;
79949 + }
79950 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79951 if (!err) {
79952 res->mnt = mntget(path.mnt);
79953 res->dentry = dget(dentry);
79954 + gr_handle_create(dentry, path.mnt);
79955 }
79956 }
79957 +out:
79958 done_path_create(&path, dentry);
79959 return err;
79960 }
79961 diff --git a/net/wireless/core.h b/net/wireless/core.h
79962 index a343be4..0c6e081 100644
79963 --- a/net/wireless/core.h
79964 +++ b/net/wireless/core.h
79965 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79966 struct mutex mtx;
79967
79968 /* rfkill support */
79969 - struct rfkill_ops rfkill_ops;
79970 + rfkill_ops_no_const rfkill_ops;
79971 struct rfkill *rfkill;
79972 struct work_struct rfkill_sync;
79973
79974 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79975 index c8717c1..08539f5 100644
79976 --- a/net/wireless/wext-core.c
79977 +++ b/net/wireless/wext-core.c
79978 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79979 */
79980
79981 /* Support for very large requests */
79982 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79983 - (user_length > descr->max_tokens)) {
79984 + if (user_length > descr->max_tokens) {
79985 /* Allow userspace to GET more than max so
79986 * we can support any size GET requests.
79987 * There is still a limit : -ENOMEM.
79988 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79989 }
79990 }
79991
79992 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79993 - /*
79994 - * If this is a GET, but not NOMAX, it means that the extra
79995 - * data is not bounded by userspace, but by max_tokens. Thus
79996 - * set the length to max_tokens. This matches the extra data
79997 - * allocation.
79998 - * The driver should fill it with the number of tokens it
79999 - * provided, and it may check iwp->length rather than having
80000 - * knowledge of max_tokens. If the driver doesn't change the
80001 - * iwp->length, this ioctl just copies back max_token tokens
80002 - * filled with zeroes. Hopefully the driver isn't claiming
80003 - * them to be valid data.
80004 - */
80005 - iwp->length = descr->max_tokens;
80006 - }
80007 -
80008 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80009
80010 iwp->length += essid_compat;
80011 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80012 index 41eabc4..8d4e6d6 100644
80013 --- a/net/xfrm/xfrm_policy.c
80014 +++ b/net/xfrm/xfrm_policy.c
80015 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80016 {
80017 policy->walk.dead = 1;
80018
80019 - atomic_inc(&policy->genid);
80020 + atomic_inc_unchecked(&policy->genid);
80021
80022 if (del_timer(&policy->timer))
80023 xfrm_pol_put(policy);
80024 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80025 hlist_add_head(&policy->bydst, chain);
80026 xfrm_pol_hold(policy);
80027 net->xfrm.policy_count[dir]++;
80028 - atomic_inc(&flow_cache_genid);
80029 + atomic_inc_unchecked(&flow_cache_genid);
80030 rt_genid_bump(net);
80031 if (delpol)
80032 __xfrm_policy_unlink(delpol, dir);
80033 @@ -1550,7 +1550,7 @@ free_dst:
80034 goto out;
80035 }
80036
80037 -static int inline
80038 +static inline int
80039 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80040 {
80041 if (!*target) {
80042 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80043 return 0;
80044 }
80045
80046 -static int inline
80047 +static inline int
80048 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80049 {
80050 #ifdef CONFIG_XFRM_SUB_POLICY
80051 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80052 #endif
80053 }
80054
80055 -static int inline
80056 +static inline int
80057 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80058 {
80059 #ifdef CONFIG_XFRM_SUB_POLICY
80060 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80061
80062 xdst->num_pols = num_pols;
80063 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80064 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80065 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80066
80067 return xdst;
80068 }
80069 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80070 if (xdst->xfrm_genid != dst->xfrm->genid)
80071 return 0;
80072 if (xdst->num_pols > 0 &&
80073 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80074 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80075 return 0;
80076
80077 mtu = dst_mtu(dst->child);
80078 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80079 sizeof(pol->xfrm_vec[i].saddr));
80080 pol->xfrm_vec[i].encap_family = mp->new_family;
80081 /* flush bundles */
80082 - atomic_inc(&pol->genid);
80083 + atomic_inc_unchecked(&pol->genid);
80084 }
80085 }
80086
80087 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80088 index 0e801c3..5c8ad3b 100644
80089 --- a/scripts/Makefile.build
80090 +++ b/scripts/Makefile.build
80091 @@ -111,7 +111,7 @@ endif
80092 endif
80093
80094 # Do not include host rules unless needed
80095 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80096 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80097 include scripts/Makefile.host
80098 endif
80099
80100 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80101 index 686cb0d..9d653bf 100644
80102 --- a/scripts/Makefile.clean
80103 +++ b/scripts/Makefile.clean
80104 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80105 __clean-files := $(extra-y) $(always) \
80106 $(targets) $(clean-files) \
80107 $(host-progs) \
80108 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80109 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80110 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80111
80112 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80113
80114 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80115 index 1ac414f..38575f7 100644
80116 --- a/scripts/Makefile.host
80117 +++ b/scripts/Makefile.host
80118 @@ -31,6 +31,8 @@
80119 # Note: Shared libraries consisting of C++ files are not supported
80120
80121 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80122 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80123 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80124
80125 # C code
80126 # Executables compiled from a single .c file
80127 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80128 # Shared libaries (only .c supported)
80129 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80130 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80131 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80132 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80133 # Remove .so files from "xxx-objs"
80134 host-cobjs := $(filter-out %.so,$(host-cobjs))
80135 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80136
80137 -#Object (.o) files used by the shared libaries
80138 +# Object (.o) files used by the shared libaries
80139 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80140 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80141
80142 # output directory for programs/.o files
80143 # hostprogs-y := tools/build may have been specified. Retrieve directory
80144 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80145 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80146 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80147 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80148 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80149 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80150 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80151 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80152
80153 obj-dirs += $(host-objdirs)
80154 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80155 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80156 $(call if_changed_dep,host-cshobjs)
80157
80158 +# Compile .c file, create position independent .o file
80159 +# host-cxxshobjs -> .o
80160 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80161 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80162 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80163 + $(call if_changed_dep,host-cxxshobjs)
80164 +
80165 # Link a shared library, based on position independent .o files
80166 # *.o -> .so shared library (host-cshlib)
80167 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80168 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80169 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80170 $(call if_changed,host-cshlib)
80171
80172 +# Link a shared library, based on position independent .o files
80173 +# *.o -> .so shared library (host-cxxshlib)
80174 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80175 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80176 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80177 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80178 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80179 + $(call if_changed,host-cxxshlib)
80180 +
80181 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80182 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80183 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80184
80185 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80186 index cb1f50c..cef2a7c 100644
80187 --- a/scripts/basic/fixdep.c
80188 +++ b/scripts/basic/fixdep.c
80189 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80190 /*
80191 * Lookup a value in the configuration string.
80192 */
80193 -static int is_defined_config(const char *name, int len, unsigned int hash)
80194 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80195 {
80196 struct item *aux;
80197
80198 @@ -211,10 +211,10 @@ static void clear_config(void)
80199 /*
80200 * Record the use of a CONFIG_* word.
80201 */
80202 -static void use_config(const char *m, int slen)
80203 +static void use_config(const char *m, unsigned int slen)
80204 {
80205 unsigned int hash = strhash(m, slen);
80206 - int c, i;
80207 + unsigned int c, i;
80208
80209 if (is_defined_config(m, slen, hash))
80210 return;
80211 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80212
80213 static void parse_config_file(const char *map, size_t len)
80214 {
80215 - const int *end = (const int *) (map + len);
80216 + const unsigned int *end = (const unsigned int *) (map + len);
80217 /* start at +1, so that p can never be < map */
80218 - const int *m = (const int *) map + 1;
80219 + const unsigned int *m = (const unsigned int *) map + 1;
80220 const char *p, *q;
80221
80222 for (; m < end; m++) {
80223 @@ -406,7 +406,7 @@ static void print_deps(void)
80224 static void traps(void)
80225 {
80226 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80227 - int *p = (int *)test;
80228 + unsigned int *p = (unsigned int *)test;
80229
80230 if (*p != INT_CONF) {
80231 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80232 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80233 new file mode 100644
80234 index 0000000..008ac1a
80235 --- /dev/null
80236 +++ b/scripts/gcc-plugin.sh
80237 @@ -0,0 +1,17 @@
80238 +#!/bin/bash
80239 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80240 +#include "gcc-plugin.h"
80241 +#include "tree.h"
80242 +#include "tm.h"
80243 +#include "rtl.h"
80244 +#ifdef ENABLE_BUILD_WITH_CXX
80245 +#warning $2
80246 +#else
80247 +#warning $1
80248 +#endif
80249 +EOF`
80250 +if [ $? -eq 0 ]
80251 +then
80252 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80253 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80254 +fi
80255 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80256 index b3d907e..a4782ab 100644
80257 --- a/scripts/link-vmlinux.sh
80258 +++ b/scripts/link-vmlinux.sh
80259 @@ -152,7 +152,7 @@ else
80260 fi;
80261
80262 # final build of init/
80263 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80264 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80265
80266 kallsymso=""
80267 kallsyms_vmlinux=""
80268 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80269 index df4fc23..0ea719d 100644
80270 --- a/scripts/mod/file2alias.c
80271 +++ b/scripts/mod/file2alias.c
80272 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80273 unsigned long size, unsigned long id_size,
80274 void *symval)
80275 {
80276 - int i;
80277 + unsigned int i;
80278
80279 if (size % id_size || size < id_size) {
80280 if (cross_build != 0)
80281 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80282 /* USB is special because the bcdDevice can be matched against a numeric range */
80283 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80284 static void do_usb_entry(struct usb_device_id *id,
80285 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80286 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80287 unsigned char range_lo, unsigned char range_hi,
80288 unsigned char max, struct module *mod)
80289 {
80290 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80291 {
80292 unsigned int devlo, devhi;
80293 unsigned char chi, clo, max;
80294 - int ndigits;
80295 + unsigned int ndigits;
80296
80297 id->match_flags = TO_NATIVE(id->match_flags);
80298 id->idVendor = TO_NATIVE(id->idVendor);
80299 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80300 for (i = 0; i < count; i++) {
80301 const char *id = (char *)devs[i].id;
80302 char acpi_id[sizeof(devs[0].id)];
80303 - int j;
80304 + unsigned int j;
80305
80306 buf_printf(&mod->dev_table_buf,
80307 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80308 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80309
80310 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80311 const char *id = (char *)card->devs[j].id;
80312 - int i2, j2;
80313 + unsigned int i2, j2;
80314 int dup = 0;
80315
80316 if (!id[0])
80317 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80318 /* add an individual alias for every device entry */
80319 if (!dup) {
80320 char acpi_id[sizeof(card->devs[0].id)];
80321 - int k;
80322 + unsigned int k;
80323
80324 buf_printf(&mod->dev_table_buf,
80325 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80326 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80327 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80328 char *alias)
80329 {
80330 - int i, j;
80331 + unsigned int i, j;
80332
80333 sprintf(alias, "dmi*");
80334
80335 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80336 index 0d93856..e828363 100644
80337 --- a/scripts/mod/modpost.c
80338 +++ b/scripts/mod/modpost.c
80339 @@ -933,6 +933,7 @@ enum mismatch {
80340 ANY_INIT_TO_ANY_EXIT,
80341 ANY_EXIT_TO_ANY_INIT,
80342 EXPORT_TO_INIT_EXIT,
80343 + DATA_TO_TEXT
80344 };
80345
80346 struct sectioncheck {
80347 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
80348 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80349 .mismatch = EXPORT_TO_INIT_EXIT,
80350 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80351 +},
80352 +/* Do not reference code from writable data */
80353 +{
80354 + .fromsec = { DATA_SECTIONS, NULL },
80355 + .tosec = { TEXT_SECTIONS, NULL },
80356 + .mismatch = DATA_TO_TEXT
80357 }
80358 };
80359
80360 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80361 continue;
80362 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80363 continue;
80364 - if (sym->st_value == addr)
80365 - return sym;
80366 /* Find a symbol nearby - addr are maybe negative */
80367 d = sym->st_value - addr;
80368 + if (d == 0)
80369 + return sym;
80370 if (d < 0)
80371 d = addr - sym->st_value;
80372 if (d < distance) {
80373 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
80374 tosym, prl_to, prl_to, tosym);
80375 free(prl_to);
80376 break;
80377 + case DATA_TO_TEXT:
80378 +#if 0
80379 + fprintf(stderr,
80380 + "The %s %s:%s references\n"
80381 + "the %s %s:%s%s\n",
80382 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80383 +#endif
80384 + break;
80385 }
80386 fprintf(stderr, "\n");
80387 }
80388 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80389 static void check_sec_ref(struct module *mod, const char *modname,
80390 struct elf_info *elf)
80391 {
80392 - int i;
80393 + unsigned int i;
80394 Elf_Shdr *sechdrs = elf->sechdrs;
80395
80396 /* Walk through all sections */
80397 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80398 va_end(ap);
80399 }
80400
80401 -void buf_write(struct buffer *buf, const char *s, int len)
80402 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80403 {
80404 if (buf->size - buf->pos < len) {
80405 buf->size += len + SZ;
80406 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80407 if (fstat(fileno(file), &st) < 0)
80408 goto close_write;
80409
80410 - if (st.st_size != b->pos)
80411 + if (st.st_size != (off_t)b->pos)
80412 goto close_write;
80413
80414 tmp = NOFAIL(malloc(b->pos));
80415 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80416 index 51207e4..f7d603d 100644
80417 --- a/scripts/mod/modpost.h
80418 +++ b/scripts/mod/modpost.h
80419 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80420
80421 struct buffer {
80422 char *p;
80423 - int pos;
80424 - int size;
80425 + unsigned int pos;
80426 + unsigned int size;
80427 };
80428
80429 void __attribute__((format(printf, 2, 3)))
80430 buf_printf(struct buffer *buf, const char *fmt, ...);
80431
80432 void
80433 -buf_write(struct buffer *buf, const char *s, int len);
80434 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80435
80436 struct module {
80437 struct module *next;
80438 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80439 index 9dfcd6d..099068e 100644
80440 --- a/scripts/mod/sumversion.c
80441 +++ b/scripts/mod/sumversion.c
80442 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80443 goto out;
80444 }
80445
80446 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80447 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80448 warn("writing sum in %s failed: %s\n",
80449 filename, strerror(errno));
80450 goto out;
80451 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80452 index 5c11312..72742b5 100644
80453 --- a/scripts/pnmtologo.c
80454 +++ b/scripts/pnmtologo.c
80455 @@ -237,14 +237,14 @@ static void write_header(void)
80456 fprintf(out, " * Linux logo %s\n", logoname);
80457 fputs(" */\n\n", out);
80458 fputs("#include <linux/linux_logo.h>\n\n", out);
80459 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80460 + fprintf(out, "static unsigned char %s_data[] = {\n",
80461 logoname);
80462 }
80463
80464 static void write_footer(void)
80465 {
80466 fputs("\n};\n\n", out);
80467 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80468 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80469 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80470 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80471 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80472 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80473 fputs("\n};\n\n", out);
80474
80475 /* write logo clut */
80476 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80477 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80478 logoname);
80479 write_hex_cnt = 0;
80480 for (i = 0; i < logo_clutsize; i++) {
80481 diff --git a/security/Kconfig b/security/Kconfig
80482 index e9c6ac7..152c2e3 100644
80483 --- a/security/Kconfig
80484 +++ b/security/Kconfig
80485 @@ -4,6 +4,896 @@
80486
80487 menu "Security options"
80488
80489 +menu "Grsecurity"
80490 +
80491 + config ARCH_TRACK_EXEC_LIMIT
80492 + bool
80493 +
80494 + config PAX_KERNEXEC_PLUGIN
80495 + bool
80496 +
80497 + config PAX_PER_CPU_PGD
80498 + bool
80499 +
80500 + config TASK_SIZE_MAX_SHIFT
80501 + int
80502 + depends on X86_64
80503 + default 47 if !PAX_PER_CPU_PGD
80504 + default 42 if PAX_PER_CPU_PGD
80505 +
80506 + config PAX_ENABLE_PAE
80507 + bool
80508 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80509 +
80510 + config PAX_USERCOPY_SLABS
80511 + bool
80512 +
80513 +config GRKERNSEC
80514 + bool "Grsecurity"
80515 + select CRYPTO
80516 + select CRYPTO_SHA256
80517 + select PROC_FS
80518 + select STOP_MACHINE
80519 + help
80520 + If you say Y here, you will be able to configure many features
80521 + that will enhance the security of your system. It is highly
80522 + recommended that you say Y here and read through the help
80523 + for each option so that you fully understand the features and
80524 + can evaluate their usefulness for your machine.
80525 +
80526 +choice
80527 + prompt "Configuration Method"
80528 + depends on GRKERNSEC
80529 + default GRKERNSEC_CONFIG_CUSTOM
80530 + help
80531 +
80532 +config GRKERNSEC_CONFIG_AUTO
80533 + bool "Automatic"
80534 + help
80535 + If you choose this configuration method, you'll be able to answer a small
80536 + number of simple questions about how you plan to use this kernel.
80537 + The settings of grsecurity and PaX will be automatically configured for
80538 + the highest commonly-used settings within the provided constraints.
80539 +
80540 + If you require additional configuration, custom changes can still be made
80541 + from the "custom configuration" menu.
80542 +
80543 +config GRKERNSEC_CONFIG_CUSTOM
80544 + bool "Custom"
80545 + help
80546 + If you choose this configuration method, you'll be able to configure all
80547 + grsecurity and PaX settings manually. Via this method, no options are
80548 + automatically enabled.
80549 +
80550 +endchoice
80551 +
80552 +choice
80553 + prompt "Usage Type"
80554 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80555 + default GRKERNSEC_CONFIG_SERVER
80556 + help
80557 +
80558 +config GRKERNSEC_CONFIG_SERVER
80559 + bool "Server"
80560 + help
80561 + Choose this option if you plan to use this kernel on a server.
80562 +
80563 +config GRKERNSEC_CONFIG_DESKTOP
80564 + bool "Desktop"
80565 + help
80566 + Choose this option if you plan to use this kernel on a desktop.
80567 +
80568 +endchoice
80569 +
80570 +choice
80571 + prompt "Virtualization Type"
80572 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80573 + default GRKERNSEC_CONFIG_VIRT_NONE
80574 + help
80575 +
80576 +config GRKERNSEC_CONFIG_VIRT_NONE
80577 + bool "None"
80578 + help
80579 + Choose this option if this kernel will be run on bare metal.
80580 +
80581 +config GRKERNSEC_CONFIG_VIRT_GUEST
80582 + bool "Guest"
80583 + help
80584 + Choose this option if this kernel will be run as a VM guest.
80585 +
80586 +config GRKERNSEC_CONFIG_VIRT_HOST
80587 + bool "Host"
80588 + help
80589 + Choose this option if this kernel will be run as a VM host.
80590 +
80591 +endchoice
80592 +
80593 +choice
80594 + prompt "Virtualization Hardware"
80595 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80596 + help
80597 +
80598 +config GRKERNSEC_CONFIG_VIRT_EPT
80599 + bool "EPT/RVI Processor Support"
80600 + depends on X86
80601 + help
80602 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80603 + hardware virtualization. This allows for additional kernel hardening protections
80604 + to operate without additional performance impact.
80605 +
80606 + To see if your Intel processor supports EPT, see:
80607 + http://ark.intel.com/Products/VirtualizationTechnology
80608 + (Most Core i3/5/7 support EPT)
80609 +
80610 + To see if your AMD processor supports RVI, see:
80611 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80612 +
80613 +config GRKERNSEC_CONFIG_VIRT_SOFT
80614 + bool "First-gen/No Hardware Virtualization"
80615 + help
80616 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80617 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80618 +
80619 +endchoice
80620 +
80621 +choice
80622 + prompt "Virtualization Software"
80623 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80624 + help
80625 +
80626 +config GRKERNSEC_CONFIG_VIRT_XEN
80627 + bool "Xen"
80628 + help
80629 + Choose this option if this kernel is running as a Xen guest or host.
80630 +
80631 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80632 + bool "VMWare"
80633 + help
80634 + Choose this option if this kernel is running as a VMWare guest or host.
80635 +
80636 +config GRKERNSEC_CONFIG_VIRT_KVM
80637 + bool "KVM"
80638 + help
80639 + Choose this option if this kernel is running as a KVM guest or host.
80640 +
80641 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80642 + bool "VirtualBox"
80643 + help
80644 + Choose this option if this kernel is running as a VirtualBox guest or host.
80645 +
80646 +endchoice
80647 +
80648 +choice
80649 + prompt "Required Priorities"
80650 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80651 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80652 + help
80653 +
80654 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80655 + bool "Performance"
80656 + help
80657 + Choose this option if performance is of highest priority for this deployment
80658 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80659 + and freed memory sanitizing will be disabled.
80660 +
80661 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80662 + bool "Security"
80663 + help
80664 + Choose this option if security is of highest priority for this deployment of
80665 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80666 + be enabled for this kernel. In a worst-case scenario, these features can
80667 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80668 +
80669 +endchoice
80670 +
80671 +menu "Default Special Groups"
80672 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80673 +
80674 +config GRKERNSEC_PROC_GID
80675 + int "GID exempted from /proc restrictions"
80676 + default 1001
80677 + help
80678 + Setting this GID determines which group will be exempted from
80679 + grsecurity's /proc restrictions, allowing users of the specified
80680 + group to view network statistics and the existence of other users'
80681 + processes on the system. This GID may also be chosen at boot time
80682 + via "grsec_proc_gid=" on the kernel commandline.
80683 +
80684 +config GRKERNSEC_TPE_UNTRUSTED_GID
80685 + int "GID for TPE-untrusted users"
80686 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80687 + default 1005
80688 + help
80689 + Setting this GID determines which group untrusted users should
80690 + be added to. These users will be placed under grsecurity's Trusted Path
80691 + Execution mechanism, preventing them from executing their own binaries.
80692 + The users will only be able to execute binaries in directories owned and
80693 + writable only by the root user. If the sysctl option is enabled, a sysctl
80694 + option with name "tpe_gid" is created.
80695 +
80696 +config GRKERNSEC_TPE_TRUSTED_GID
80697 + int "GID for TPE-trusted users"
80698 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80699 + default 1005
80700 + help
80701 + Setting this GID determines what group TPE restrictions will be
80702 + *disabled* for. If the sysctl option is enabled, a sysctl option
80703 + with name "tpe_gid" is created.
80704 +
80705 +config GRKERNSEC_SYMLINKOWN_GID
80706 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80707 + depends on GRKERNSEC_CONFIG_SERVER
80708 + default 1006
80709 + help
80710 + Setting this GID determines what group kernel-enforced
80711 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80712 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80713 +
80714 +
80715 +endmenu
80716 +
80717 +menu "Customize Configuration"
80718 +depends on GRKERNSEC
80719 +
80720 +menu "PaX"
80721 +
80722 +config PAX
80723 + bool "Enable various PaX features"
80724 + default y if GRKERNSEC_CONFIG_AUTO
80725 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80726 + help
80727 + This allows you to enable various PaX features. PaX adds
80728 + intrusion prevention mechanisms to the kernel that reduce
80729 + the risks posed by exploitable memory corruption bugs.
80730 +
80731 +menu "PaX Control"
80732 + depends on PAX
80733 +
80734 +config PAX_SOFTMODE
80735 + bool 'Support soft mode'
80736 + help
80737 + Enabling this option will allow you to run PaX in soft mode, that
80738 + is, PaX features will not be enforced by default, only on executables
80739 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80740 + support as they are the only way to mark executables for soft mode use.
80741 +
80742 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80743 + line option on boot. Furthermore you can control various PaX features
80744 + at runtime via the entries in /proc/sys/kernel/pax.
80745 +
80746 +config PAX_EI_PAX
80747 + bool 'Use legacy ELF header marking'
80748 + default y if GRKERNSEC_CONFIG_AUTO
80749 + help
80750 + Enabling this option will allow you to control PaX features on
80751 + a per executable basis via the 'chpax' utility available at
80752 + http://pax.grsecurity.net/. The control flags will be read from
80753 + an otherwise reserved part of the ELF header. This marking has
80754 + numerous drawbacks (no support for soft-mode, toolchain does not
80755 + know about the non-standard use of the ELF header) therefore it
80756 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80757 + support.
80758 +
80759 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80760 + support as well, they will override the legacy EI_PAX marks.
80761 +
80762 + If you enable none of the marking options then all applications
80763 + will run with PaX enabled on them by default.
80764 +
80765 +config PAX_PT_PAX_FLAGS
80766 + bool 'Use ELF program header marking'
80767 + default y if GRKERNSEC_CONFIG_AUTO
80768 + help
80769 + Enabling this option will allow you to control PaX features on
80770 + a per executable basis via the 'paxctl' utility available at
80771 + http://pax.grsecurity.net/. The control flags will be read from
80772 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80773 + has the benefits of supporting both soft mode and being fully
80774 + integrated into the toolchain (the binutils patch is available
80775 + from http://pax.grsecurity.net).
80776 +
80777 + Note that if you enable the legacy EI_PAX marking support as well,
80778 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80779 +
80780 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80781 + must make sure that the marks are the same if a binary has both marks.
80782 +
80783 + If you enable none of the marking options then all applications
80784 + will run with PaX enabled on them by default.
80785 +
80786 +config PAX_XATTR_PAX_FLAGS
80787 + bool 'Use filesystem extended attributes marking'
80788 + default y if GRKERNSEC_CONFIG_AUTO
80789 + select CIFS_XATTR if CIFS
80790 + select EXT2_FS_XATTR if EXT2_FS
80791 + select EXT3_FS_XATTR if EXT3_FS
80792 + select EXT4_FS_XATTR if EXT4_FS
80793 + select JFFS2_FS_XATTR if JFFS2_FS
80794 + select REISERFS_FS_XATTR if REISERFS_FS
80795 + select SQUASHFS_XATTR if SQUASHFS
80796 + select TMPFS_XATTR if TMPFS
80797 + select UBIFS_FS_XATTR if UBIFS_FS
80798 + help
80799 + Enabling this option will allow you to control PaX features on
80800 + a per executable basis via the 'setfattr' utility. The control
80801 + flags will be read from the user.pax.flags extended attribute of
80802 + the file. This marking has the benefit of supporting binary-only
80803 + applications that self-check themselves (e.g., skype) and would
80804 + not tolerate chpax/paxctl changes. The main drawback is that
80805 + extended attributes are not supported by some filesystems (e.g.,
80806 + isofs, udf, vfat) so copying files through such filesystems will
80807 + lose the extended attributes and these PaX markings.
80808 +
80809 + Note that if you enable the legacy EI_PAX marking support as well,
80810 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80811 +
80812 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80813 + must make sure that the marks are the same if a binary has both marks.
80814 +
80815 + If you enable none of the marking options then all applications
80816 + will run with PaX enabled on them by default.
80817 +
80818 +choice
80819 + prompt 'MAC system integration'
80820 + default PAX_HAVE_ACL_FLAGS
80821 + help
80822 + Mandatory Access Control systems have the option of controlling
80823 + PaX flags on a per executable basis, choose the method supported
80824 + by your particular system.
80825 +
80826 + - "none": if your MAC system does not interact with PaX,
80827 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80828 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80829 +
80830 + NOTE: this option is for developers/integrators only.
80831 +
80832 + config PAX_NO_ACL_FLAGS
80833 + bool 'none'
80834 +
80835 + config PAX_HAVE_ACL_FLAGS
80836 + bool 'direct'
80837 +
80838 + config PAX_HOOK_ACL_FLAGS
80839 + bool 'hook'
80840 +endchoice
80841 +
80842 +endmenu
80843 +
80844 +menu "Non-executable pages"
80845 + depends on PAX
80846 +
80847 +config PAX_NOEXEC
80848 + bool "Enforce non-executable pages"
80849 + default y if GRKERNSEC_CONFIG_AUTO
80850 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80851 + help
80852 + By design some architectures do not allow for protecting memory
80853 + pages against execution or even if they do, Linux does not make
80854 + use of this feature. In practice this means that if a page is
80855 + readable (such as the stack or heap) it is also executable.
80856 +
80857 + There is a well known exploit technique that makes use of this
80858 + fact and a common programming mistake where an attacker can
80859 + introduce code of his choice somewhere in the attacked program's
80860 + memory (typically the stack or the heap) and then execute it.
80861 +
80862 + If the attacked program was running with different (typically
80863 + higher) privileges than that of the attacker, then he can elevate
80864 + his own privilege level (e.g. get a root shell, write to files for
80865 + which he does not have write access to, etc).
80866 +
80867 + Enabling this option will let you choose from various features
80868 + that prevent the injection and execution of 'foreign' code in
80869 + a program.
80870 +
80871 + This will also break programs that rely on the old behaviour and
80872 + expect that dynamically allocated memory via the malloc() family
80873 + of functions is executable (which it is not). Notable examples
80874 + are the XFree86 4.x server, the java runtime and wine.
80875 +
80876 +config PAX_PAGEEXEC
80877 + bool "Paging based non-executable pages"
80878 + default y if GRKERNSEC_CONFIG_AUTO
80879 + 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)
80880 + select S390_SWITCH_AMODE if S390
80881 + select S390_EXEC_PROTECT if S390
80882 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80883 + help
80884 + This implementation is based on the paging feature of the CPU.
80885 + On i386 without hardware non-executable bit support there is a
80886 + variable but usually low performance impact, however on Intel's
80887 + P4 core based CPUs it is very high so you should not enable this
80888 + for kernels meant to be used on such CPUs.
80889 +
80890 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80891 + with hardware non-executable bit support there is no performance
80892 + impact, on ppc the impact is negligible.
80893 +
80894 + Note that several architectures require various emulations due to
80895 + badly designed userland ABIs, this will cause a performance impact
80896 + but will disappear as soon as userland is fixed. For example, ppc
80897 + userland MUST have been built with secure-plt by a recent toolchain.
80898 +
80899 +config PAX_SEGMEXEC
80900 + bool "Segmentation based non-executable pages"
80901 + default y if GRKERNSEC_CONFIG_AUTO
80902 + depends on PAX_NOEXEC && X86_32
80903 + help
80904 + This implementation is based on the segmentation feature of the
80905 + CPU and has a very small performance impact, however applications
80906 + will be limited to a 1.5 GB address space instead of the normal
80907 + 3 GB.
80908 +
80909 +config PAX_EMUTRAMP
80910 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80911 + default y if PARISC
80912 + help
80913 + There are some programs and libraries that for one reason or
80914 + another attempt to execute special small code snippets from
80915 + non-executable memory pages. Most notable examples are the
80916 + signal handler return code generated by the kernel itself and
80917 + the GCC trampolines.
80918 +
80919 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80920 + such programs will no longer work under your kernel.
80921 +
80922 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80923 + utilities to enable trampoline emulation for the affected programs
80924 + yet still have the protection provided by the non-executable pages.
80925 +
80926 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80927 + your system will not even boot.
80928 +
80929 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80930 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80931 + for the affected files.
80932 +
80933 + NOTE: enabling this feature *may* open up a loophole in the
80934 + protection provided by non-executable pages that an attacker
80935 + could abuse. Therefore the best solution is to not have any
80936 + files on your system that would require this option. This can
80937 + be achieved by not using libc5 (which relies on the kernel
80938 + signal handler return code) and not using or rewriting programs
80939 + that make use of the nested function implementation of GCC.
80940 + Skilled users can just fix GCC itself so that it implements
80941 + nested function calls in a way that does not interfere with PaX.
80942 +
80943 +config PAX_EMUSIGRT
80944 + bool "Automatically emulate sigreturn trampolines"
80945 + depends on PAX_EMUTRAMP && PARISC
80946 + default y
80947 + help
80948 + Enabling this option will have the kernel automatically detect
80949 + and emulate signal return trampolines executing on the stack
80950 + that would otherwise lead to task termination.
80951 +
80952 + This solution is intended as a temporary one for users with
80953 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80954 + Modula-3 runtime, etc) or executables linked to such, basically
80955 + everything that does not specify its own SA_RESTORER function in
80956 + normal executable memory like glibc 2.1+ does.
80957 +
80958 + On parisc you MUST enable this option, otherwise your system will
80959 + not even boot.
80960 +
80961 + NOTE: this feature cannot be disabled on a per executable basis
80962 + and since it *does* open up a loophole in the protection provided
80963 + by non-executable pages, the best solution is to not have any
80964 + files on your system that would require this option.
80965 +
80966 +config PAX_MPROTECT
80967 + bool "Restrict mprotect()"
80968 + default y if GRKERNSEC_CONFIG_AUTO
80969 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80970 + help
80971 + Enabling this option will prevent programs from
80972 + - changing the executable status of memory pages that were
80973 + not originally created as executable,
80974 + - making read-only executable pages writable again,
80975 + - creating executable pages from anonymous memory,
80976 + - making read-only-after-relocations (RELRO) data pages writable again.
80977 +
80978 + You should say Y here to complete the protection provided by
80979 + the enforcement of non-executable pages.
80980 +
80981 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80982 + this feature on a per file basis.
80983 +
80984 +config PAX_MPROTECT_COMPAT
80985 + bool "Use legacy/compat protection demoting (read help)"
80986 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80987 + depends on PAX_MPROTECT
80988 + help
80989 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80990 + by sending the proper error code to the application. For some broken
80991 + userland, this can cause problems with Python or other applications. The
80992 + current implementation however allows for applications like clamav to
80993 + detect if JIT compilation/execution is allowed and to fall back gracefully
80994 + to an interpreter-based mode if it does not. While we encourage everyone
80995 + to use the current implementation as-is and push upstream to fix broken
80996 + userland (note that the RWX logging option can assist with this), in some
80997 + environments this may not be possible. Having to disable MPROTECT
80998 + completely on certain binaries reduces the security benefit of PaX,
80999 + so this option is provided for those environments to revert to the old
81000 + behavior.
81001 +
81002 +config PAX_ELFRELOCS
81003 + bool "Allow ELF text relocations (read help)"
81004 + depends on PAX_MPROTECT
81005 + default n
81006 + help
81007 + Non-executable pages and mprotect() restrictions are effective
81008 + in preventing the introduction of new executable code into an
81009 + attacked task's address space. There remain only two venues
81010 + for this kind of attack: if the attacker can execute already
81011 + existing code in the attacked task then he can either have it
81012 + create and mmap() a file containing his code or have it mmap()
81013 + an already existing ELF library that does not have position
81014 + independent code in it and use mprotect() on it to make it
81015 + writable and copy his code there. While protecting against
81016 + the former approach is beyond PaX, the latter can be prevented
81017 + by having only PIC ELF libraries on one's system (which do not
81018 + need to relocate their code). If you are sure this is your case,
81019 + as is the case with all modern Linux distributions, then leave
81020 + this option disabled. You should say 'n' here.
81021 +
81022 +config PAX_ETEXECRELOCS
81023 + bool "Allow ELF ET_EXEC text relocations"
81024 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81025 + select PAX_ELFRELOCS
81026 + default y
81027 + help
81028 + On some architectures there are incorrectly created applications
81029 + that require text relocations and would not work without enabling
81030 + this option. If you are an alpha, ia64 or parisc user, you should
81031 + enable this option and disable it once you have made sure that
81032 + none of your applications need it.
81033 +
81034 +config PAX_EMUPLT
81035 + bool "Automatically emulate ELF PLT"
81036 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81037 + default y
81038 + help
81039 + Enabling this option will have the kernel automatically detect
81040 + and emulate the Procedure Linkage Table entries in ELF files.
81041 + On some architectures such entries are in writable memory, and
81042 + become non-executable leading to task termination. Therefore
81043 + it is mandatory that you enable this option on alpha, parisc,
81044 + sparc and sparc64, otherwise your system would not even boot.
81045 +
81046 + NOTE: this feature *does* open up a loophole in the protection
81047 + provided by the non-executable pages, therefore the proper
81048 + solution is to modify the toolchain to produce a PLT that does
81049 + not need to be writable.
81050 +
81051 +config PAX_DLRESOLVE
81052 + bool 'Emulate old glibc resolver stub'
81053 + depends on PAX_EMUPLT && SPARC
81054 + default n
81055 + help
81056 + This option is needed if userland has an old glibc (before 2.4)
81057 + that puts a 'save' instruction into the runtime generated resolver
81058 + stub that needs special emulation.
81059 +
81060 +config PAX_KERNEXEC
81061 + bool "Enforce non-executable kernel pages"
81062 + 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))
81063 + depends on X86 && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81064 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81065 + select PAX_KERNEXEC_PLUGIN if X86_64
81066 + help
81067 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81068 + that is, enabling this option will make it harder to inject
81069 + and execute 'foreign' code in kernel memory itself.
81070 +
81071 +choice
81072 + prompt "Return Address Instrumentation Method"
81073 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81074 + depends on PAX_KERNEXEC_PLUGIN
81075 + help
81076 + Select the method used to instrument function pointer dereferences.
81077 + Note that binary modules cannot be instrumented by this approach.
81078 +
81079 + Note that the implementation requires a gcc with plugin support,
81080 + i.e., gcc 4.5 or newer. You may need to install the supporting
81081 + headers explicitly in addition to the normal gcc package.
81082 +
81083 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81084 + bool "bts"
81085 + help
81086 + This method is compatible with binary only modules but has
81087 + a higher runtime overhead.
81088 +
81089 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81090 + bool "or"
81091 + depends on !PARAVIRT
81092 + help
81093 + This method is incompatible with binary only modules but has
81094 + a lower runtime overhead.
81095 +endchoice
81096 +
81097 +config PAX_KERNEXEC_PLUGIN_METHOD
81098 + string
81099 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81100 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81101 + default ""
81102 +
81103 +config PAX_KERNEXEC_MODULE_TEXT
81104 + int "Minimum amount of memory reserved for module code"
81105 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81106 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81107 + depends on PAX_KERNEXEC && X86_32 && MODULES
81108 + help
81109 + Due to implementation details the kernel must reserve a fixed
81110 + amount of memory for module code at compile time that cannot be
81111 + changed at runtime. Here you can specify the minimum amount
81112 + in MB that will be reserved. Due to the same implementation
81113 + details this size will always be rounded up to the next 2/4 MB
81114 + boundary (depends on PAE) so the actually available memory for
81115 + module code will usually be more than this minimum.
81116 +
81117 + The default 4 MB should be enough for most users but if you have
81118 + an excessive number of modules (e.g., most distribution configs
81119 + compile many drivers as modules) or use huge modules such as
81120 + nvidia's kernel driver, you will need to adjust this amount.
81121 + A good rule of thumb is to look at your currently loaded kernel
81122 + modules and add up their sizes.
81123 +
81124 +endmenu
81125 +
81126 +menu "Address Space Layout Randomization"
81127 + depends on PAX
81128 +
81129 +config PAX_ASLR
81130 + bool "Address Space Layout Randomization"
81131 + default y if GRKERNSEC_CONFIG_AUTO
81132 + help
81133 + Many if not most exploit techniques rely on the knowledge of
81134 + certain addresses in the attacked program. The following options
81135 + will allow the kernel to apply a certain amount of randomization
81136 + to specific parts of the program thereby forcing an attacker to
81137 + guess them in most cases. Any failed guess will most likely crash
81138 + the attacked program which allows the kernel to detect such attempts
81139 + and react on them. PaX itself provides no reaction mechanisms,
81140 + instead it is strongly encouraged that you make use of Nergal's
81141 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81142 + (http://www.grsecurity.net/) built-in crash detection features or
81143 + develop one yourself.
81144 +
81145 + By saying Y here you can choose to randomize the following areas:
81146 + - top of the task's kernel stack
81147 + - top of the task's userland stack
81148 + - base address for mmap() requests that do not specify one
81149 + (this includes all libraries)
81150 + - base address of the main executable
81151 +
81152 + It is strongly recommended to say Y here as address space layout
81153 + randomization has negligible impact on performance yet it provides
81154 + a very effective protection.
81155 +
81156 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81157 + this feature on a per file basis.
81158 +
81159 +config PAX_RANDKSTACK
81160 + bool "Randomize kernel stack base"
81161 + default y if GRKERNSEC_CONFIG_AUTO
81162 + depends on X86_TSC && X86
81163 + help
81164 + By saying Y here the kernel will randomize every task's kernel
81165 + stack on every system call. This will not only force an attacker
81166 + to guess it but also prevent him from making use of possible
81167 + leaked information about it.
81168 +
81169 + Since the kernel stack is a rather scarce resource, randomization
81170 + may cause unexpected stack overflows, therefore you should very
81171 + carefully test your system. Note that once enabled in the kernel
81172 + configuration, this feature cannot be disabled on a per file basis.
81173 +
81174 +config PAX_RANDUSTACK
81175 + bool "Randomize user stack base"
81176 + default y if GRKERNSEC_CONFIG_AUTO
81177 + depends on PAX_ASLR
81178 + help
81179 + By saying Y here the kernel will randomize every task's userland
81180 + stack. The randomization is done in two steps where the second
81181 + one may apply a big amount of shift to the top of the stack and
81182 + cause problems for programs that want to use lots of memory (more
81183 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81184 + For this reason the second step can be controlled by 'chpax' or
81185 + 'paxctl' on a per file basis.
81186 +
81187 +config PAX_RANDMMAP
81188 + bool "Randomize mmap() base"
81189 + default y if GRKERNSEC_CONFIG_AUTO
81190 + depends on PAX_ASLR
81191 + help
81192 + By saying Y here the kernel will use a randomized base address for
81193 + mmap() requests that do not specify one themselves. As a result
81194 + all dynamically loaded libraries will appear at random addresses
81195 + and therefore be harder to exploit by a technique where an attacker
81196 + attempts to execute library code for his purposes (e.g. spawn a
81197 + shell from an exploited program that is running at an elevated
81198 + privilege level).
81199 +
81200 + Furthermore, if a program is relinked as a dynamic ELF file, its
81201 + base address will be randomized as well, completing the full
81202 + randomization of the address space layout. Attacking such programs
81203 + becomes a guess game. You can find an example of doing this at
81204 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81205 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81206 +
81207 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81208 + feature on a per file basis.
81209 +
81210 +endmenu
81211 +
81212 +menu "Miscellaneous hardening features"
81213 +
81214 +config PAX_MEMORY_SANITIZE
81215 + bool "Sanitize all freed memory"
81216 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81217 + depends on !HIBERNATION
81218 + help
81219 + By saying Y here the kernel will erase memory pages as soon as they
81220 + are freed. This in turn reduces the lifetime of data stored in the
81221 + pages, making it less likely that sensitive information such as
81222 + passwords, cryptographic secrets, etc stay in memory for too long.
81223 +
81224 + This is especially useful for programs whose runtime is short, long
81225 + lived processes and the kernel itself benefit from this as long as
81226 + they operate on whole memory pages and ensure timely freeing of pages
81227 + that may hold sensitive information.
81228 +
81229 + The tradeoff is performance impact, on a single CPU system kernel
81230 + compilation sees a 3% slowdown, other systems and workloads may vary
81231 + and you are advised to test this feature on your expected workload
81232 + before deploying it.
81233 +
81234 + Note that this feature does not protect data stored in live pages,
81235 + e.g., process memory swapped to disk may stay there for a long time.
81236 +
81237 +config PAX_MEMORY_STACKLEAK
81238 + bool "Sanitize kernel stack"
81239 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81240 + depends on X86
81241 + help
81242 + By saying Y here the kernel will erase the kernel stack before it
81243 + returns from a system call. This in turn reduces the information
81244 + that a kernel stack leak bug can reveal.
81245 +
81246 + Note that such a bug can still leak information that was put on
81247 + the stack by the current system call (the one eventually triggering
81248 + the bug) but traces of earlier system calls on the kernel stack
81249 + cannot leak anymore.
81250 +
81251 + The tradeoff is performance impact: on a single CPU system kernel
81252 + compilation sees a 1% slowdown, other systems and workloads may vary
81253 + and you are advised to test this feature on your expected workload
81254 + before deploying it.
81255 +
81256 + Note that the full feature requires a gcc with plugin support,
81257 + i.e., gcc 4.5 or newer. You may need to install the supporting
81258 + headers explicitly in addition to the normal gcc package. Using
81259 + older gcc versions means that functions with large enough stack
81260 + frames may leave uninitialized memory behind that may be exposed
81261 + to a later syscall leaking the stack.
81262 +
81263 +config PAX_MEMORY_UDEREF
81264 + bool "Prevent invalid userland pointer dereference"
81265 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81266 + depends on X86 && !UML_X86 && !XEN
81267 + select PAX_PER_CPU_PGD if X86_64
81268 + help
81269 + By saying Y here the kernel will be prevented from dereferencing
81270 + userland pointers in contexts where the kernel expects only kernel
81271 + pointers. This is both a useful runtime debugging feature and a
81272 + security measure that prevents exploiting a class of kernel bugs.
81273 +
81274 + The tradeoff is that some virtualization solutions may experience
81275 + a huge slowdown and therefore you should not enable this feature
81276 + for kernels meant to run in such environments. Whether a given VM
81277 + solution is affected or not is best determined by simply trying it
81278 + out, the performance impact will be obvious right on boot as this
81279 + mechanism engages from very early on. A good rule of thumb is that
81280 + VMs running on CPUs without hardware virtualization support (i.e.,
81281 + the majority of IA-32 CPUs) will likely experience the slowdown.
81282 +
81283 +config PAX_REFCOUNT
81284 + bool "Prevent various kernel object reference counter overflows"
81285 + default y if GRKERNSEC_CONFIG_AUTO
81286 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81287 + help
81288 + By saying Y here the kernel will detect and prevent overflowing
81289 + various (but not all) kinds of object reference counters. Such
81290 + overflows can normally occur due to bugs only and are often, if
81291 + not always, exploitable.
81292 +
81293 + The tradeoff is that data structures protected by an overflowed
81294 + refcount will never be freed and therefore will leak memory. Note
81295 + that this leak also happens even without this protection but in
81296 + that case the overflow can eventually trigger the freeing of the
81297 + data structure while it is still being used elsewhere, resulting
81298 + in the exploitable situation that this feature prevents.
81299 +
81300 + Since this has a negligible performance impact, you should enable
81301 + this feature.
81302 +
81303 +config PAX_USERCOPY
81304 + bool "Harden heap object copies between kernel and userland"
81305 + default y if GRKERNSEC_CONFIG_AUTO
81306 + depends on X86 || PPC || SPARC || ARM
81307 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81308 + select PAX_USERCOPY_SLABS
81309 + help
81310 + By saying Y here the kernel will enforce the size of heap objects
81311 + when they are copied in either direction between the kernel and
81312 + userland, even if only a part of the heap object is copied.
81313 +
81314 + Specifically, this checking prevents information leaking from the
81315 + kernel heap during kernel to userland copies (if the kernel heap
81316 + object is otherwise fully initialized) and prevents kernel heap
81317 + overflows during userland to kernel copies.
81318 +
81319 + Note that the current implementation provides the strictest bounds
81320 + checks for the SLUB allocator.
81321 +
81322 + Enabling this option also enables per-slab cache protection against
81323 + data in a given cache being copied into/out of via userland
81324 + accessors. Though the whitelist of regions will be reduced over
81325 + time, it notably protects important data structures like task structs.
81326 +
81327 + If frame pointers are enabled on x86, this option will also restrict
81328 + copies into and out of the kernel stack to local variables within a
81329 + single frame.
81330 +
81331 + Since this has a negligible performance impact, you should enable
81332 + this feature.
81333 +
81334 +config PAX_SIZE_OVERFLOW
81335 + bool "Prevent various integer overflows in function size parameters"
81336 + default y if GRKERNSEC_CONFIG_AUTO
81337 + depends on X86
81338 + help
81339 + By saying Y here the kernel recomputes expressions of function
81340 + arguments marked by a size_overflow attribute with double integer
81341 + precision (DImode/TImode for 32/64 bit integer types).
81342 +
81343 + The recomputed argument is checked against TYPE_MAX and an event
81344 + is logged on overflow and the triggering process is killed.
81345 +
81346 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81347 +
81348 + Note that the implementation requires a gcc with plugin support,
81349 + i.e., gcc 4.5 or newer. You may need to install the supporting
81350 + headers explicitly in addition to the normal gcc package.
81351 +
81352 +config PAX_LATENT_ENTROPY
81353 + bool "Generate some entropy during boot"
81354 + default y if GRKERNSEC_CONFIG_AUTO
81355 + help
81356 + By saying Y here the kernel will instrument early boot code to
81357 + extract some entropy from both original and artificially created
81358 + program state. This will help especially embedded systems where
81359 + there is little 'natural' source of entropy normally. The cost
81360 + is some slowdown of the boot process.
81361 +
81362 + Note that the implementation requires a gcc with plugin support,
81363 + i.e., gcc 4.5 or newer. You may need to install the supporting
81364 + headers explicitly in addition to the normal gcc package.
81365 +
81366 + Note that entropy extracted this way is not cryptographically
81367 + secure!
81368 +
81369 +endmenu
81370 +
81371 +endmenu
81372 +
81373 +source grsecurity/Kconfig
81374 +
81375 +endmenu
81376 +
81377 +endmenu
81378 +
81379 source security/keys/Kconfig
81380
81381 config SECURITY_DMESG_RESTRICT
81382 @@ -103,7 +993,7 @@ config INTEL_TXT
81383 config LSM_MMAP_MIN_ADDR
81384 int "Low address space for LSM to protect from user allocation"
81385 depends on SECURITY && SECURITY_SELINUX
81386 - default 32768 if ARM
81387 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81388 default 65536
81389 help
81390 This is the portion of low virtual memory which should be protected
81391 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81392 index 8c2a7f6..b133ac9 100644
81393 --- a/security/apparmor/lsm.c
81394 +++ b/security/apparmor/lsm.c
81395 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81396 return error;
81397 }
81398
81399 -static struct security_operations apparmor_ops = {
81400 +static struct security_operations apparmor_ops __read_only = {
81401 .name = "apparmor",
81402
81403 .ptrace_access_check = apparmor_ptrace_access_check,
81404 diff --git a/security/commoncap.c b/security/commoncap.c
81405 index 6dbae46..d5611fd 100644
81406 --- a/security/commoncap.c
81407 +++ b/security/commoncap.c
81408 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81409 return 0;
81410 }
81411
81412 +/* returns:
81413 + 1 for suid privilege
81414 + 2 for sgid privilege
81415 + 3 for fscap privilege
81416 +*/
81417 +int is_privileged_binary(const struct dentry *dentry)
81418 +{
81419 + struct cpu_vfs_cap_data capdata;
81420 + struct inode *inode = dentry->d_inode;
81421 +
81422 + if (!inode || S_ISDIR(inode->i_mode))
81423 + return 0;
81424 +
81425 + if (inode->i_mode & S_ISUID)
81426 + return 1;
81427 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81428 + return 2;
81429 +
81430 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81431 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81432 + return 3;
81433 + }
81434 +
81435 + return 0;
81436 +}
81437 +
81438 /*
81439 * Attempt to get the on-exec apply capability sets for an executable file from
81440 * its xattrs and, if present, apply them to the proposed credentials being
81441 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81442 const struct cred *cred = current_cred();
81443 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81444
81445 + if (gr_acl_enable_at_secure())
81446 + return 1;
81447 +
81448 if (!uid_eq(cred->uid, root_uid)) {
81449 if (bprm->cap_effective)
81450 return 1;
81451 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81452 index 6ee8826..6350060 100644
81453 --- a/security/integrity/ima/ima.h
81454 +++ b/security/integrity/ima/ima.h
81455 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81456 extern spinlock_t ima_queue_lock;
81457
81458 struct ima_h_table {
81459 - atomic_long_t len; /* number of stored measurements in the list */
81460 - atomic_long_t violations;
81461 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81462 + atomic_long_unchecked_t violations;
81463 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81464 };
81465 extern struct ima_h_table ima_htable;
81466 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81467 index b356884..fd9676e 100644
81468 --- a/security/integrity/ima/ima_api.c
81469 +++ b/security/integrity/ima/ima_api.c
81470 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81471 int result;
81472
81473 /* can overflow, only indicator */
81474 - atomic_long_inc(&ima_htable.violations);
81475 + atomic_long_inc_unchecked(&ima_htable.violations);
81476
81477 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81478 if (!entry) {
81479 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81480 index 38477c9..87a60c7 100644
81481 --- a/security/integrity/ima/ima_fs.c
81482 +++ b/security/integrity/ima/ima_fs.c
81483 @@ -28,12 +28,12 @@
81484 static int valid_policy = 1;
81485 #define TMPBUFLEN 12
81486 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81487 - loff_t *ppos, atomic_long_t *val)
81488 + loff_t *ppos, atomic_long_unchecked_t *val)
81489 {
81490 char tmpbuf[TMPBUFLEN];
81491 ssize_t len;
81492
81493 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81494 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81495 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81496 }
81497
81498 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81499 index 55a6271..ad829c3 100644
81500 --- a/security/integrity/ima/ima_queue.c
81501 +++ b/security/integrity/ima/ima_queue.c
81502 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81503 INIT_LIST_HEAD(&qe->later);
81504 list_add_tail_rcu(&qe->later, &ima_measurements);
81505
81506 - atomic_long_inc(&ima_htable.len);
81507 + atomic_long_inc_unchecked(&ima_htable.len);
81508 key = ima_hash_key(entry->digest);
81509 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81510 return 0;
81511 diff --git a/security/keys/compat.c b/security/keys/compat.c
81512 index 1c26176..64a1ba2 100644
81513 --- a/security/keys/compat.c
81514 +++ b/security/keys/compat.c
81515 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81516 if (ret == 0)
81517 goto no_payload_free;
81518
81519 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81520 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81521
81522 if (iov != iovstack)
81523 kfree(iov);
81524 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81525 index 5d34b4e..2456674 100644
81526 --- a/security/keys/keyctl.c
81527 +++ b/security/keys/keyctl.c
81528 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81529 /*
81530 * Copy the iovec data from userspace
81531 */
81532 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81533 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81534 unsigned ioc)
81535 {
81536 for (; ioc > 0; ioc--) {
81537 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81538 * If successful, 0 will be returned.
81539 */
81540 long keyctl_instantiate_key_common(key_serial_t id,
81541 - const struct iovec *payload_iov,
81542 + const struct iovec __user *payload_iov,
81543 unsigned ioc,
81544 size_t plen,
81545 key_serial_t ringid)
81546 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
81547 [0].iov_len = plen
81548 };
81549
81550 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81551 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81552 }
81553
81554 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81555 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81556 if (ret == 0)
81557 goto no_payload_free;
81558
81559 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81560 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81561
81562 if (iov != iovstack)
81563 kfree(iov);
81564 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81565 index 6e42df1..aba52bd 100644
81566 --- a/security/keys/keyring.c
81567 +++ b/security/keys/keyring.c
81568 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81569 ret = -EFAULT;
81570
81571 for (loop = 0; loop < klist->nkeys; loop++) {
81572 + key_serial_t serial;
81573 key = rcu_deref_link_locked(klist, loop,
81574 keyring);
81575 + serial = key->serial;
81576
81577 tmp = sizeof(key_serial_t);
81578 if (tmp > buflen)
81579 tmp = buflen;
81580
81581 - if (copy_to_user(buffer,
81582 - &key->serial,
81583 - tmp) != 0)
81584 + if (copy_to_user(buffer, &serial, tmp))
81585 goto error;
81586
81587 buflen -= tmp;
81588 diff --git a/security/min_addr.c b/security/min_addr.c
81589 index f728728..6457a0c 100644
81590 --- a/security/min_addr.c
81591 +++ b/security/min_addr.c
81592 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81593 */
81594 static void update_mmap_min_addr(void)
81595 {
81596 +#ifndef SPARC
81597 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81598 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81599 mmap_min_addr = dac_mmap_min_addr;
81600 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81601 #else
81602 mmap_min_addr = dac_mmap_min_addr;
81603 #endif
81604 +#endif
81605 }
81606
81607 /*
81608 diff --git a/security/security.c b/security/security.c
81609 index 8dcd4ae..1124de7 100644
81610 --- a/security/security.c
81611 +++ b/security/security.c
81612 @@ -20,6 +20,7 @@
81613 #include <linux/ima.h>
81614 #include <linux/evm.h>
81615 #include <linux/fsnotify.h>
81616 +#include <linux/mm.h>
81617 #include <linux/mman.h>
81618 #include <linux/mount.h>
81619 #include <linux/personality.h>
81620 @@ -32,8 +33,8 @@
81621 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81622 CONFIG_DEFAULT_SECURITY;
81623
81624 -static struct security_operations *security_ops;
81625 -static struct security_operations default_security_ops = {
81626 +static struct security_operations *security_ops __read_only;
81627 +static struct security_operations default_security_ops __read_only = {
81628 .name = "default",
81629 };
81630
81631 @@ -74,7 +75,9 @@ int __init security_init(void)
81632
81633 void reset_security_ops(void)
81634 {
81635 + pax_open_kernel();
81636 security_ops = &default_security_ops;
81637 + pax_close_kernel();
81638 }
81639
81640 /* Save user chosen LSM */
81641 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81642 index 61a5336..27215d8 100644
81643 --- a/security/selinux/hooks.c
81644 +++ b/security/selinux/hooks.c
81645 @@ -95,8 +95,6 @@
81646
81647 #define NUM_SEL_MNT_OPTS 5
81648
81649 -extern struct security_operations *security_ops;
81650 -
81651 /* SECMARK reference count */
81652 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81653
81654 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81655
81656 #endif
81657
81658 -static struct security_operations selinux_ops = {
81659 +static struct security_operations selinux_ops __read_only = {
81660 .name = "selinux",
81661
81662 .ptrace_access_check = selinux_ptrace_access_check,
81663 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81664 index 65f67cb..3f141ef 100644
81665 --- a/security/selinux/include/xfrm.h
81666 +++ b/security/selinux/include/xfrm.h
81667 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81668
81669 static inline void selinux_xfrm_notify_policyload(void)
81670 {
81671 - atomic_inc(&flow_cache_genid);
81672 + atomic_inc_unchecked(&flow_cache_genid);
81673 rt_genid_bump(&init_net);
81674 }
81675 #else
81676 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81677 index 38be92c..21f49ee 100644
81678 --- a/security/smack/smack_lsm.c
81679 +++ b/security/smack/smack_lsm.c
81680 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81681 return 0;
81682 }
81683
81684 -struct security_operations smack_ops = {
81685 +struct security_operations smack_ops __read_only = {
81686 .name = "smack",
81687
81688 .ptrace_access_check = smack_ptrace_access_check,
81689 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81690 index a2ee362..5754f34 100644
81691 --- a/security/tomoyo/tomoyo.c
81692 +++ b/security/tomoyo/tomoyo.c
81693 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81694 * tomoyo_security_ops is a "struct security_operations" which is used for
81695 * registering TOMOYO.
81696 */
81697 -static struct security_operations tomoyo_security_ops = {
81698 +static struct security_operations tomoyo_security_ops __read_only = {
81699 .name = "tomoyo",
81700 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81701 .cred_prepare = tomoyo_cred_prepare,
81702 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81703 index 20ef514..4182bed 100644
81704 --- a/security/yama/Kconfig
81705 +++ b/security/yama/Kconfig
81706 @@ -1,6 +1,6 @@
81707 config SECURITY_YAMA
81708 bool "Yama support"
81709 - depends on SECURITY
81710 + depends on SECURITY && !GRKERNSEC
81711 select SECURITYFS
81712 select SECURITY_PATH
81713 default n
81714 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81715 index 4cedc69..e59d8a3 100644
81716 --- a/sound/aoa/codecs/onyx.c
81717 +++ b/sound/aoa/codecs/onyx.c
81718 @@ -54,7 +54,7 @@ struct onyx {
81719 spdif_locked:1,
81720 analog_locked:1,
81721 original_mute:2;
81722 - int open_count;
81723 + local_t open_count;
81724 struct codec_info *codec_info;
81725
81726 /* mutex serializes concurrent access to the device
81727 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81728 struct onyx *onyx = cii->codec_data;
81729
81730 mutex_lock(&onyx->mutex);
81731 - onyx->open_count++;
81732 + local_inc(&onyx->open_count);
81733 mutex_unlock(&onyx->mutex);
81734
81735 return 0;
81736 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81737 struct onyx *onyx = cii->codec_data;
81738
81739 mutex_lock(&onyx->mutex);
81740 - onyx->open_count--;
81741 - if (!onyx->open_count)
81742 + if (local_dec_and_test(&onyx->open_count))
81743 onyx->spdif_locked = onyx->analog_locked = 0;
81744 mutex_unlock(&onyx->mutex);
81745
81746 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81747 index ffd2025..df062c9 100644
81748 --- a/sound/aoa/codecs/onyx.h
81749 +++ b/sound/aoa/codecs/onyx.h
81750 @@ -11,6 +11,7 @@
81751 #include <linux/i2c.h>
81752 #include <asm/pmac_low_i2c.h>
81753 #include <asm/prom.h>
81754 +#include <asm/local.h>
81755
81756 /* PCM3052 register definitions */
81757
81758 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81759 index 4c1cc51..16040040 100644
81760 --- a/sound/core/oss/pcm_oss.c
81761 +++ b/sound/core/oss/pcm_oss.c
81762 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81763 if (in_kernel) {
81764 mm_segment_t fs;
81765 fs = snd_enter_user();
81766 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81767 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81768 snd_leave_user(fs);
81769 } else {
81770 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81771 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81772 }
81773 if (ret != -EPIPE && ret != -ESTRPIPE)
81774 break;
81775 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81776 if (in_kernel) {
81777 mm_segment_t fs;
81778 fs = snd_enter_user();
81779 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81780 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81781 snd_leave_user(fs);
81782 } else {
81783 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81784 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81785 }
81786 if (ret == -EPIPE) {
81787 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81788 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81789 struct snd_pcm_plugin_channel *channels;
81790 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81791 if (!in_kernel) {
81792 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81793 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81794 return -EFAULT;
81795 buf = runtime->oss.buffer;
81796 }
81797 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81798 }
81799 } else {
81800 tmp = snd_pcm_oss_write2(substream,
81801 - (const char __force *)buf,
81802 + (const char __force_kernel *)buf,
81803 runtime->oss.period_bytes, 0);
81804 if (tmp <= 0)
81805 goto err;
81806 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81807 struct snd_pcm_runtime *runtime = substream->runtime;
81808 snd_pcm_sframes_t frames, frames1;
81809 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81810 - char __user *final_dst = (char __force __user *)buf;
81811 + char __user *final_dst = (char __force_user *)buf;
81812 if (runtime->oss.plugin_first) {
81813 struct snd_pcm_plugin_channel *channels;
81814 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81815 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81816 xfer += tmp;
81817 runtime->oss.buffer_used -= tmp;
81818 } else {
81819 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81820 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81821 runtime->oss.period_bytes, 0);
81822 if (tmp <= 0)
81823 goto err;
81824 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81825 size1);
81826 size1 /= runtime->channels; /* frames */
81827 fs = snd_enter_user();
81828 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81829 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81830 snd_leave_user(fs);
81831 }
81832 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81833 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81834 index 91cdf943..4085161 100644
81835 --- a/sound/core/pcm_compat.c
81836 +++ b/sound/core/pcm_compat.c
81837 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81838 int err;
81839
81840 fs = snd_enter_user();
81841 - err = snd_pcm_delay(substream, &delay);
81842 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81843 snd_leave_user(fs);
81844 if (err < 0)
81845 return err;
81846 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81847 index f9ddecf..e27404d 100644
81848 --- a/sound/core/pcm_native.c
81849 +++ b/sound/core/pcm_native.c
81850 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81851 switch (substream->stream) {
81852 case SNDRV_PCM_STREAM_PLAYBACK:
81853 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81854 - (void __user *)arg);
81855 + (void __force_user *)arg);
81856 break;
81857 case SNDRV_PCM_STREAM_CAPTURE:
81858 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81859 - (void __user *)arg);
81860 + (void __force_user *)arg);
81861 break;
81862 default:
81863 result = -EINVAL;
81864 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81865 index 60e8fc1..786abcb 100644
81866 --- a/sound/core/seq/seq_device.c
81867 +++ b/sound/core/seq/seq_device.c
81868 @@ -64,7 +64,7 @@ struct ops_list {
81869 int argsize; /* argument size */
81870
81871 /* operators */
81872 - struct snd_seq_dev_ops ops;
81873 + struct snd_seq_dev_ops *ops;
81874
81875 /* registred devices */
81876 struct list_head dev_list; /* list of devices */
81877 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81878
81879 mutex_lock(&ops->reg_mutex);
81880 /* copy driver operators */
81881 - ops->ops = *entry;
81882 + ops->ops = entry;
81883 ops->driver |= DRIVER_LOADED;
81884 ops->argsize = argsize;
81885
81886 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81887 dev->name, ops->id, ops->argsize, dev->argsize);
81888 return -EINVAL;
81889 }
81890 - if (ops->ops.init_device(dev) >= 0) {
81891 + if (ops->ops->init_device(dev) >= 0) {
81892 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81893 ops->num_init_devices++;
81894 } else {
81895 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81896 dev->name, ops->id, ops->argsize, dev->argsize);
81897 return -EINVAL;
81898 }
81899 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81900 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81901 dev->status = SNDRV_SEQ_DEVICE_FREE;
81902 dev->driver_data = NULL;
81903 ops->num_init_devices--;
81904 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81905 index 2d5514b..3afae9c 100644
81906 --- a/sound/drivers/mts64.c
81907 +++ b/sound/drivers/mts64.c
81908 @@ -29,6 +29,7 @@
81909 #include <sound/initval.h>
81910 #include <sound/rawmidi.h>
81911 #include <sound/control.h>
81912 +#include <asm/local.h>
81913
81914 #define CARD_NAME "Miditerminal 4140"
81915 #define DRIVER_NAME "MTS64"
81916 @@ -67,7 +68,7 @@ struct mts64 {
81917 struct pardevice *pardev;
81918 int pardev_claimed;
81919
81920 - int open_count;
81921 + local_t open_count;
81922 int current_midi_output_port;
81923 int current_midi_input_port;
81924 u8 mode[MTS64_NUM_INPUT_PORTS];
81925 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81926 {
81927 struct mts64 *mts = substream->rmidi->private_data;
81928
81929 - if (mts->open_count == 0) {
81930 + if (local_read(&mts->open_count) == 0) {
81931 /* We don't need a spinlock here, because this is just called
81932 if the device has not been opened before.
81933 So there aren't any IRQs from the device */
81934 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81935
81936 msleep(50);
81937 }
81938 - ++(mts->open_count);
81939 + local_inc(&mts->open_count);
81940
81941 return 0;
81942 }
81943 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81944 struct mts64 *mts = substream->rmidi->private_data;
81945 unsigned long flags;
81946
81947 - --(mts->open_count);
81948 - if (mts->open_count == 0) {
81949 + if (local_dec_return(&mts->open_count) == 0) {
81950 /* We need the spinlock_irqsave here because we can still
81951 have IRQs at this point */
81952 spin_lock_irqsave(&mts->lock, flags);
81953 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81954
81955 msleep(500);
81956
81957 - } else if (mts->open_count < 0)
81958 - mts->open_count = 0;
81959 + } else if (local_read(&mts->open_count) < 0)
81960 + local_set(&mts->open_count, 0);
81961
81962 return 0;
81963 }
81964 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81965 index b953fb4..1999c01 100644
81966 --- a/sound/drivers/opl4/opl4_lib.c
81967 +++ b/sound/drivers/opl4/opl4_lib.c
81968 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81969 MODULE_DESCRIPTION("OPL4 driver");
81970 MODULE_LICENSE("GPL");
81971
81972 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81973 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81974 {
81975 int timeout = 10;
81976 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81977 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81978 index 8364855..59f2e2b 100644
81979 --- a/sound/drivers/portman2x4.c
81980 +++ b/sound/drivers/portman2x4.c
81981 @@ -48,6 +48,7 @@
81982 #include <sound/initval.h>
81983 #include <sound/rawmidi.h>
81984 #include <sound/control.h>
81985 +#include <asm/local.h>
81986
81987 #define CARD_NAME "Portman 2x4"
81988 #define DRIVER_NAME "portman"
81989 @@ -85,7 +86,7 @@ struct portman {
81990 struct pardevice *pardev;
81991 int pardev_claimed;
81992
81993 - int open_count;
81994 + local_t open_count;
81995 int mode[PORTMAN_NUM_INPUT_PORTS];
81996 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81997 };
81998 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81999 index ea995af..f1bfa37 100644
82000 --- a/sound/firewire/amdtp.c
82001 +++ b/sound/firewire/amdtp.c
82002 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82003 ptr = s->pcm_buffer_pointer + data_blocks;
82004 if (ptr >= pcm->runtime->buffer_size)
82005 ptr -= pcm->runtime->buffer_size;
82006 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82007 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82008
82009 s->pcm_period_pointer += data_blocks;
82010 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82011 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82012 */
82013 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82014 {
82015 - ACCESS_ONCE(s->source_node_id_field) =
82016 + ACCESS_ONCE_RW(s->source_node_id_field) =
82017 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82018 }
82019 EXPORT_SYMBOL(amdtp_out_stream_update);
82020 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82021 index b680c5e..061b7a0 100644
82022 --- a/sound/firewire/amdtp.h
82023 +++ b/sound/firewire/amdtp.h
82024 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82025 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82026 struct snd_pcm_substream *pcm)
82027 {
82028 - ACCESS_ONCE(s->pcm) = pcm;
82029 + ACCESS_ONCE_RW(s->pcm) = pcm;
82030 }
82031
82032 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82033 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82034 index d428ffe..751ef78 100644
82035 --- a/sound/firewire/isight.c
82036 +++ b/sound/firewire/isight.c
82037 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82038 ptr += count;
82039 if (ptr >= runtime->buffer_size)
82040 ptr -= runtime->buffer_size;
82041 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82042 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82043
82044 isight->period_counter += count;
82045 if (isight->period_counter >= runtime->period_size) {
82046 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82047 if (err < 0)
82048 return err;
82049
82050 - ACCESS_ONCE(isight->pcm_active) = true;
82051 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82052
82053 return 0;
82054 }
82055 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82056 {
82057 struct isight *isight = substream->private_data;
82058
82059 - ACCESS_ONCE(isight->pcm_active) = false;
82060 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82061
82062 mutex_lock(&isight->mutex);
82063 isight_stop_streaming(isight);
82064 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82065
82066 switch (cmd) {
82067 case SNDRV_PCM_TRIGGER_START:
82068 - ACCESS_ONCE(isight->pcm_running) = true;
82069 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82070 break;
82071 case SNDRV_PCM_TRIGGER_STOP:
82072 - ACCESS_ONCE(isight->pcm_running) = false;
82073 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82074 break;
82075 default:
82076 return -EINVAL;
82077 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82078 index 7bd5e33..1fcab12 100644
82079 --- a/sound/isa/cmi8330.c
82080 +++ b/sound/isa/cmi8330.c
82081 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82082
82083 struct snd_pcm *pcm;
82084 struct snd_cmi8330_stream {
82085 - struct snd_pcm_ops ops;
82086 + snd_pcm_ops_no_const ops;
82087 snd_pcm_open_callback_t open;
82088 void *private_data; /* sb or wss */
82089 } streams[2];
82090 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82091 index b2b3c01..e1c1e1f 100644
82092 --- a/sound/oss/sb_audio.c
82093 +++ b/sound/oss/sb_audio.c
82094 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82095 buf16 = (signed short *)(localbuf + localoffs);
82096 while (c)
82097 {
82098 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82099 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82100 if (copy_from_user(lbuf8,
82101 userbuf+useroffs + p,
82102 locallen))
82103 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82104 index 7d8803a..559f8d0 100644
82105 --- a/sound/oss/swarm_cs4297a.c
82106 +++ b/sound/oss/swarm_cs4297a.c
82107 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82108 {
82109 struct cs4297a_state *s;
82110 u32 pwr, id;
82111 - mm_segment_t fs;
82112 int rval;
82113 #ifndef CONFIG_BCM_CS4297A_CSWARM
82114 u64 cfg;
82115 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82116 if (!rval) {
82117 char *sb1250_duart_present;
82118
82119 +#if 0
82120 + mm_segment_t fs;
82121 fs = get_fs();
82122 set_fs(KERNEL_DS);
82123 -#if 0
82124 val = SOUND_MASK_LINE;
82125 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82126 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82127 val = initvol[i].vol;
82128 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82129 }
82130 + set_fs(fs);
82131 // cs4297a_write_ac97(s, 0x18, 0x0808);
82132 #else
82133 // cs4297a_write_ac97(s, 0x5e, 0x180);
82134 cs4297a_write_ac97(s, 0x02, 0x0808);
82135 cs4297a_write_ac97(s, 0x18, 0x0808);
82136 #endif
82137 - set_fs(fs);
82138
82139 list_add(&s->list, &cs4297a_devs);
82140
82141 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82142 index 4f4e545..9b75d10 100644
82143 --- a/sound/pci/hda/hda_codec.h
82144 +++ b/sound/pci/hda/hda_codec.h
82145 @@ -618,7 +618,7 @@ struct hda_bus_ops {
82146 /* notify power-up/down from codec to controller */
82147 void (*pm_notify)(struct hda_bus *bus, bool power_up);
82148 #endif
82149 -};
82150 +} __no_const;
82151
82152 /* template to pass to the bus constructor */
82153 struct hda_bus_template {
82154 @@ -716,6 +716,7 @@ struct hda_codec_ops {
82155 #endif
82156 void (*reboot_notify)(struct hda_codec *codec);
82157 };
82158 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82159
82160 /* record for amp information cache */
82161 struct hda_cache_head {
82162 @@ -746,7 +747,7 @@ struct hda_pcm_ops {
82163 struct snd_pcm_substream *substream);
82164 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82165 struct snd_pcm_substream *substream);
82166 -};
82167 +} __no_const;
82168
82169 /* PCM information for each substream */
82170 struct hda_pcm_stream {
82171 @@ -805,7 +806,7 @@ struct hda_codec {
82172 const char *modelname; /* model name for preset */
82173
82174 /* set by patch */
82175 - struct hda_codec_ops patch_ops;
82176 + hda_codec_ops_no_const patch_ops;
82177
82178 /* PCM to create, set by patch_ops.build_pcms callback */
82179 unsigned int num_pcms;
82180 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82181 index d0e7d87..49ec1bb 100644
82182 --- a/sound/pci/ice1712/ice1712.h
82183 +++ b/sound/pci/ice1712/ice1712.h
82184 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82185 unsigned int mask_flags; /* total mask bits */
82186 struct snd_akm4xxx_ops {
82187 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82188 - } ops;
82189 + } __no_const ops;
82190 };
82191
82192 struct snd_ice1712_spdif {
82193 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82194 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82195 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82196 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82197 - } ops;
82198 + } __no_const ops;
82199 };
82200
82201
82202 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82203 index 4631a23..001ae57 100644
82204 --- a/sound/pci/ymfpci/ymfpci.h
82205 +++ b/sound/pci/ymfpci/ymfpci.h
82206 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82207 spinlock_t reg_lock;
82208 spinlock_t voice_lock;
82209 wait_queue_head_t interrupt_sleep;
82210 - atomic_t interrupt_sleep_count;
82211 + atomic_unchecked_t interrupt_sleep_count;
82212 struct snd_info_entry *proc_entry;
82213 const struct firmware *dsp_microcode;
82214 const struct firmware *controller_microcode;
82215 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82216 index 3a6f03f..bc5c86c 100644
82217 --- a/sound/pci/ymfpci/ymfpci_main.c
82218 +++ b/sound/pci/ymfpci/ymfpci_main.c
82219 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82220 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82221 break;
82222 }
82223 - if (atomic_read(&chip->interrupt_sleep_count)) {
82224 - atomic_set(&chip->interrupt_sleep_count, 0);
82225 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82226 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82227 wake_up(&chip->interrupt_sleep);
82228 }
82229 __end:
82230 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82231 continue;
82232 init_waitqueue_entry(&wait, current);
82233 add_wait_queue(&chip->interrupt_sleep, &wait);
82234 - atomic_inc(&chip->interrupt_sleep_count);
82235 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82236 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82237 remove_wait_queue(&chip->interrupt_sleep, &wait);
82238 }
82239 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82240 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82241 spin_unlock(&chip->reg_lock);
82242
82243 - if (atomic_read(&chip->interrupt_sleep_count)) {
82244 - atomic_set(&chip->interrupt_sleep_count, 0);
82245 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82246 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82247 wake_up(&chip->interrupt_sleep);
82248 }
82249 }
82250 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82251 spin_lock_init(&chip->reg_lock);
82252 spin_lock_init(&chip->voice_lock);
82253 init_waitqueue_head(&chip->interrupt_sleep);
82254 - atomic_set(&chip->interrupt_sleep_count, 0);
82255 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82256 chip->card = card;
82257 chip->pci = pci;
82258 chip->irq = -1;
82259 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82260 new file mode 100644
82261 index 0000000..50f2f2f
82262 --- /dev/null
82263 +++ b/tools/gcc/.gitignore
82264 @@ -0,0 +1 @@
82265 +size_overflow_hash.h
82266 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82267 new file mode 100644
82268 index 0000000..1d09b7e
82269 --- /dev/null
82270 +++ b/tools/gcc/Makefile
82271 @@ -0,0 +1,43 @@
82272 +#CC := gcc
82273 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82274 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82275 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82276 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82277 +
82278 +ifeq ($(PLUGINCC),$(HOSTCC))
82279 +HOSTLIBS := hostlibs
82280 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82281 +else
82282 +HOSTLIBS := hostcxxlibs
82283 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82284 +endif
82285 +
82286 +$(HOSTLIBS)-y := constify_plugin.so
82287 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82288 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82289 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82290 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82291 +$(HOSTLIBS)-y += colorize_plugin.so
82292 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82293 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82294 +
82295 +always := $($(HOSTLIBS)-y)
82296 +
82297 +constify_plugin-objs := constify_plugin.o
82298 +stackleak_plugin-objs := stackleak_plugin.o
82299 +kallocstat_plugin-objs := kallocstat_plugin.o
82300 +kernexec_plugin-objs := kernexec_plugin.o
82301 +checker_plugin-objs := checker_plugin.o
82302 +colorize_plugin-objs := colorize_plugin.o
82303 +size_overflow_plugin-objs := size_overflow_plugin.o
82304 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82305 +
82306 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82307 +
82308 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82309 + cmd_build_size_overflow_hash = \
82310 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82311 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82312 + $(call if_changed,build_size_overflow_hash)
82313 +
82314 +targets += size_overflow_hash.h
82315 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82316 new file mode 100644
82317 index 0000000..d41b5af
82318 --- /dev/null
82319 +++ b/tools/gcc/checker_plugin.c
82320 @@ -0,0 +1,171 @@
82321 +/*
82322 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82323 + * Licensed under the GPL v2
82324 + *
82325 + * Note: the choice of the license means that the compilation process is
82326 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82327 + * but for the kernel it doesn't matter since it doesn't link against
82328 + * any of the gcc libraries
82329 + *
82330 + * gcc plugin to implement various sparse (source code checker) features
82331 + *
82332 + * TODO:
82333 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82334 + *
82335 + * BUGS:
82336 + * - none known
82337 + */
82338 +#include "gcc-plugin.h"
82339 +#include "config.h"
82340 +#include "system.h"
82341 +#include "coretypes.h"
82342 +#include "tree.h"
82343 +#include "tree-pass.h"
82344 +#include "flags.h"
82345 +#include "intl.h"
82346 +#include "toplev.h"
82347 +#include "plugin.h"
82348 +//#include "expr.h" where are you...
82349 +#include "diagnostic.h"
82350 +#include "plugin-version.h"
82351 +#include "tm.h"
82352 +#include "function.h"
82353 +#include "basic-block.h"
82354 +#include "gimple.h"
82355 +#include "rtl.h"
82356 +#include "emit-rtl.h"
82357 +#include "tree-flow.h"
82358 +#include "target.h"
82359 +
82360 +extern void c_register_addr_space (const char *str, addr_space_t as);
82361 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82362 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82363 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82364 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82365 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82366 +
82367 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82368 +extern rtx emit_move_insn(rtx x, rtx y);
82369 +
82370 +int plugin_is_GPL_compatible;
82371 +
82372 +static struct plugin_info checker_plugin_info = {
82373 + .version = "201111150100",
82374 +};
82375 +
82376 +#define ADDR_SPACE_KERNEL 0
82377 +#define ADDR_SPACE_FORCE_KERNEL 1
82378 +#define ADDR_SPACE_USER 2
82379 +#define ADDR_SPACE_FORCE_USER 3
82380 +#define ADDR_SPACE_IOMEM 0
82381 +#define ADDR_SPACE_FORCE_IOMEM 0
82382 +#define ADDR_SPACE_PERCPU 0
82383 +#define ADDR_SPACE_FORCE_PERCPU 0
82384 +#define ADDR_SPACE_RCU 0
82385 +#define ADDR_SPACE_FORCE_RCU 0
82386 +
82387 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82388 +{
82389 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82390 +}
82391 +
82392 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82393 +{
82394 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82395 +}
82396 +
82397 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82398 +{
82399 + return default_addr_space_valid_pointer_mode(mode, as);
82400 +}
82401 +
82402 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82403 +{
82404 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82405 +}
82406 +
82407 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82408 +{
82409 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82410 +}
82411 +
82412 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82413 +{
82414 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82415 + return true;
82416 +
82417 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82418 + return true;
82419 +
82420 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82421 + return true;
82422 +
82423 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82424 + return true;
82425 +
82426 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82427 + return true;
82428 +
82429 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82430 + return true;
82431 +
82432 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82433 + return true;
82434 +
82435 + return subset == superset;
82436 +}
82437 +
82438 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82439 +{
82440 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82441 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82442 +
82443 + return op;
82444 +}
82445 +
82446 +static void register_checker_address_spaces(void *event_data, void *data)
82447 +{
82448 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82449 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82450 + c_register_addr_space("__user", ADDR_SPACE_USER);
82451 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82452 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82453 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82454 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82455 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82456 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82457 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82458 +
82459 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82460 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82461 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82462 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82463 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82464 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82465 + targetm.addr_space.convert = checker_addr_space_convert;
82466 +}
82467 +
82468 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82469 +{
82470 + const char * const plugin_name = plugin_info->base_name;
82471 + const int argc = plugin_info->argc;
82472 + const struct plugin_argument * const argv = plugin_info->argv;
82473 + int i;
82474 +
82475 + if (!plugin_default_version_check(version, &gcc_version)) {
82476 + error(G_("incompatible gcc/plugin versions"));
82477 + return 1;
82478 + }
82479 +
82480 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82481 +
82482 + for (i = 0; i < argc; ++i)
82483 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82484 +
82485 + if (TARGET_64BIT == 0)
82486 + return 0;
82487 +
82488 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82489 +
82490 + return 0;
82491 +}
82492 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82493 new file mode 100644
82494 index 0000000..846aeb0
82495 --- /dev/null
82496 +++ b/tools/gcc/colorize_plugin.c
82497 @@ -0,0 +1,148 @@
82498 +/*
82499 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82500 + * Licensed under the GPL v2
82501 + *
82502 + * Note: the choice of the license means that the compilation process is
82503 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82504 + * but for the kernel it doesn't matter since it doesn't link against
82505 + * any of the gcc libraries
82506 + *
82507 + * gcc plugin to colorize diagnostic output
82508 + *
82509 + */
82510 +
82511 +#include "gcc-plugin.h"
82512 +#include "config.h"
82513 +#include "system.h"
82514 +#include "coretypes.h"
82515 +#include "tree.h"
82516 +#include "tree-pass.h"
82517 +#include "flags.h"
82518 +#include "intl.h"
82519 +#include "toplev.h"
82520 +#include "plugin.h"
82521 +#include "diagnostic.h"
82522 +#include "plugin-version.h"
82523 +#include "tm.h"
82524 +
82525 +int plugin_is_GPL_compatible;
82526 +
82527 +static struct plugin_info colorize_plugin_info = {
82528 + .version = "201203092200",
82529 + .help = NULL,
82530 +};
82531 +
82532 +#define GREEN "\033[32m\033[2m"
82533 +#define LIGHTGREEN "\033[32m\033[1m"
82534 +#define YELLOW "\033[33m\033[2m"
82535 +#define LIGHTYELLOW "\033[33m\033[1m"
82536 +#define RED "\033[31m\033[2m"
82537 +#define LIGHTRED "\033[31m\033[1m"
82538 +#define BLUE "\033[34m\033[2m"
82539 +#define LIGHTBLUE "\033[34m\033[1m"
82540 +#define BRIGHT "\033[m\033[1m"
82541 +#define NORMAL "\033[m"
82542 +
82543 +static diagnostic_starter_fn old_starter;
82544 +static diagnostic_finalizer_fn old_finalizer;
82545 +
82546 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82547 +{
82548 + const char *color;
82549 + char *newprefix;
82550 +
82551 + switch (diagnostic->kind) {
82552 + case DK_NOTE:
82553 + color = LIGHTBLUE;
82554 + break;
82555 +
82556 + case DK_PEDWARN:
82557 + case DK_WARNING:
82558 + color = LIGHTYELLOW;
82559 + break;
82560 +
82561 + case DK_ERROR:
82562 + case DK_FATAL:
82563 + case DK_ICE:
82564 + case DK_PERMERROR:
82565 + case DK_SORRY:
82566 + color = LIGHTRED;
82567 + break;
82568 +
82569 + default:
82570 + color = NORMAL;
82571 + }
82572 +
82573 + old_starter(context, diagnostic);
82574 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82575 + return;
82576 + pp_destroy_prefix(context->printer);
82577 + pp_set_prefix(context->printer, newprefix);
82578 +}
82579 +
82580 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82581 +{
82582 + old_finalizer(context, diagnostic);
82583 +}
82584 +
82585 +static void colorize_arm(void)
82586 +{
82587 + old_starter = diagnostic_starter(global_dc);
82588 + old_finalizer = diagnostic_finalizer(global_dc);
82589 +
82590 + diagnostic_starter(global_dc) = start_colorize;
82591 + diagnostic_finalizer(global_dc) = finalize_colorize;
82592 +}
82593 +
82594 +static unsigned int execute_colorize_rearm(void)
82595 +{
82596 + if (diagnostic_starter(global_dc) == start_colorize)
82597 + return 0;
82598 +
82599 + colorize_arm();
82600 + return 0;
82601 +}
82602 +
82603 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82604 + .pass = {
82605 + .type = SIMPLE_IPA_PASS,
82606 + .name = "colorize_rearm",
82607 + .gate = NULL,
82608 + .execute = execute_colorize_rearm,
82609 + .sub = NULL,
82610 + .next = NULL,
82611 + .static_pass_number = 0,
82612 + .tv_id = TV_NONE,
82613 + .properties_required = 0,
82614 + .properties_provided = 0,
82615 + .properties_destroyed = 0,
82616 + .todo_flags_start = 0,
82617 + .todo_flags_finish = 0
82618 + }
82619 +};
82620 +
82621 +static void colorize_start_unit(void *gcc_data, void *user_data)
82622 +{
82623 + colorize_arm();
82624 +}
82625 +
82626 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82627 +{
82628 + const char * const plugin_name = plugin_info->base_name;
82629 + struct register_pass_info colorize_rearm_pass_info = {
82630 + .pass = &pass_ipa_colorize_rearm.pass,
82631 + .reference_pass_name = "*free_lang_data",
82632 + .ref_pass_instance_number = 1,
82633 + .pos_op = PASS_POS_INSERT_AFTER
82634 + };
82635 +
82636 + if (!plugin_default_version_check(version, &gcc_version)) {
82637 + error(G_("incompatible gcc/plugin versions"));
82638 + return 1;
82639 + }
82640 +
82641 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82642 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82643 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82644 + return 0;
82645 +}
82646 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82647 new file mode 100644
82648 index 0000000..92ed719
82649 --- /dev/null
82650 +++ b/tools/gcc/constify_plugin.c
82651 @@ -0,0 +1,331 @@
82652 +/*
82653 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82654 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82655 + * Licensed under the GPL v2, or (at your option) v3
82656 + *
82657 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82658 + *
82659 + * Homepage:
82660 + * http://www.grsecurity.net/~ephox/const_plugin/
82661 + *
82662 + * Usage:
82663 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82664 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82665 + */
82666 +
82667 +#include "gcc-plugin.h"
82668 +#include "config.h"
82669 +#include "system.h"
82670 +#include "coretypes.h"
82671 +#include "tree.h"
82672 +#include "tree-pass.h"
82673 +#include "flags.h"
82674 +#include "intl.h"
82675 +#include "toplev.h"
82676 +#include "plugin.h"
82677 +#include "diagnostic.h"
82678 +#include "plugin-version.h"
82679 +#include "tm.h"
82680 +#include "function.h"
82681 +#include "basic-block.h"
82682 +#include "gimple.h"
82683 +#include "rtl.h"
82684 +#include "emit-rtl.h"
82685 +#include "tree-flow.h"
82686 +
82687 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82688 +
82689 +int plugin_is_GPL_compatible;
82690 +
82691 +static struct plugin_info const_plugin_info = {
82692 + .version = "201205300030",
82693 + .help = "no-constify\tturn off constification\n",
82694 +};
82695 +
82696 +static void deconstify_tree(tree node);
82697 +
82698 +static void deconstify_type(tree type)
82699 +{
82700 + tree field;
82701 +
82702 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82703 + tree type = TREE_TYPE(field);
82704 +
82705 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82706 + continue;
82707 + if (!TYPE_READONLY(type))
82708 + continue;
82709 +
82710 + deconstify_tree(field);
82711 + }
82712 + TYPE_READONLY(type) = 0;
82713 + C_TYPE_FIELDS_READONLY(type) = 0;
82714 +}
82715 +
82716 +static void deconstify_tree(tree node)
82717 +{
82718 + tree old_type, new_type, field;
82719 +
82720 + old_type = TREE_TYPE(node);
82721 +
82722 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82723 +
82724 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82725 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82726 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82727 + DECL_FIELD_CONTEXT(field) = new_type;
82728 +
82729 + deconstify_type(new_type);
82730 +
82731 + TREE_READONLY(node) = 0;
82732 + TREE_TYPE(node) = new_type;
82733 +}
82734 +
82735 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82736 +{
82737 + tree type;
82738 +
82739 + *no_add_attrs = true;
82740 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82741 + error("%qE attribute does not apply to functions", name);
82742 + return NULL_TREE;
82743 + }
82744 +
82745 + if (TREE_CODE(*node) == VAR_DECL) {
82746 + error("%qE attribute does not apply to variables", name);
82747 + return NULL_TREE;
82748 + }
82749 +
82750 + if (TYPE_P(*node)) {
82751 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82752 + *no_add_attrs = false;
82753 + else
82754 + error("%qE attribute applies to struct and union types only", name);
82755 + return NULL_TREE;
82756 + }
82757 +
82758 + type = TREE_TYPE(*node);
82759 +
82760 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82761 + error("%qE attribute applies to struct and union types only", name);
82762 + return NULL_TREE;
82763 + }
82764 +
82765 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82766 + error("%qE attribute is already applied to the type", name);
82767 + return NULL_TREE;
82768 + }
82769 +
82770 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82771 + error("%qE attribute used on type that is not constified", name);
82772 + return NULL_TREE;
82773 + }
82774 +
82775 + if (TREE_CODE(*node) == TYPE_DECL) {
82776 + deconstify_tree(*node);
82777 + return NULL_TREE;
82778 + }
82779 +
82780 + return NULL_TREE;
82781 +}
82782 +
82783 +static void constify_type(tree type)
82784 +{
82785 + TYPE_READONLY(type) = 1;
82786 + C_TYPE_FIELDS_READONLY(type) = 1;
82787 +}
82788 +
82789 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82790 +{
82791 + *no_add_attrs = true;
82792 + if (!TYPE_P(*node)) {
82793 + error("%qE attribute applies to types only", name);
82794 + return NULL_TREE;
82795 + }
82796 +
82797 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82798 + error("%qE attribute applies to struct and union types only", name);
82799 + return NULL_TREE;
82800 + }
82801 +
82802 + *no_add_attrs = false;
82803 + constify_type(*node);
82804 + return NULL_TREE;
82805 +}
82806 +
82807 +static struct attribute_spec no_const_attr = {
82808 + .name = "no_const",
82809 + .min_length = 0,
82810 + .max_length = 0,
82811 + .decl_required = false,
82812 + .type_required = false,
82813 + .function_type_required = false,
82814 + .handler = handle_no_const_attribute,
82815 +#if BUILDING_GCC_VERSION >= 4007
82816 + .affects_type_identity = true
82817 +#endif
82818 +};
82819 +
82820 +static struct attribute_spec do_const_attr = {
82821 + .name = "do_const",
82822 + .min_length = 0,
82823 + .max_length = 0,
82824 + .decl_required = false,
82825 + .type_required = false,
82826 + .function_type_required = false,
82827 + .handler = handle_do_const_attribute,
82828 +#if BUILDING_GCC_VERSION >= 4007
82829 + .affects_type_identity = true
82830 +#endif
82831 +};
82832 +
82833 +static void register_attributes(void *event_data, void *data)
82834 +{
82835 + register_attribute(&no_const_attr);
82836 + register_attribute(&do_const_attr);
82837 +}
82838 +
82839 +static bool is_fptr(tree field)
82840 +{
82841 + tree ptr = TREE_TYPE(field);
82842 +
82843 + if (TREE_CODE(ptr) != POINTER_TYPE)
82844 + return false;
82845 +
82846 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82847 +}
82848 +
82849 +static bool walk_struct(tree node)
82850 +{
82851 + tree field;
82852 +
82853 + if (TYPE_FIELDS(node) == NULL_TREE)
82854 + return false;
82855 +
82856 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82857 + gcc_assert(!TYPE_READONLY(node));
82858 + deconstify_type(node);
82859 + return false;
82860 + }
82861 +
82862 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82863 + tree type = TREE_TYPE(field);
82864 + enum tree_code code = TREE_CODE(type);
82865 +
82866 + if (node == type)
82867 + return false;
82868 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82869 + if (!(walk_struct(type)))
82870 + return false;
82871 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82872 + return false;
82873 + }
82874 + return true;
82875 +}
82876 +
82877 +static void finish_type(void *event_data, void *data)
82878 +{
82879 + tree type = (tree)event_data;
82880 +
82881 + if (type == NULL_TREE || type == error_mark_node)
82882 + return;
82883 +
82884 + if (TYPE_READONLY(type))
82885 + return;
82886 +
82887 + if (walk_struct(type))
82888 + constify_type(type);
82889 +}
82890 +
82891 +static unsigned int check_local_variables(void);
82892 +
82893 +struct gimple_opt_pass pass_local_variable = {
82894 + {
82895 + .type = GIMPLE_PASS,
82896 + .name = "check_local_variables",
82897 + .gate = NULL,
82898 + .execute = check_local_variables,
82899 + .sub = NULL,
82900 + .next = NULL,
82901 + .static_pass_number = 0,
82902 + .tv_id = TV_NONE,
82903 + .properties_required = 0,
82904 + .properties_provided = 0,
82905 + .properties_destroyed = 0,
82906 + .todo_flags_start = 0,
82907 + .todo_flags_finish = 0
82908 + }
82909 +};
82910 +
82911 +static unsigned int check_local_variables(void)
82912 +{
82913 + tree var;
82914 + referenced_var_iterator rvi;
82915 +
82916 +#if BUILDING_GCC_VERSION == 4005
82917 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82918 +#else
82919 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82920 +#endif
82921 + tree type = TREE_TYPE(var);
82922 +
82923 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82924 + continue;
82925 +
82926 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82927 + continue;
82928 +
82929 + if (!TYPE_READONLY(type))
82930 + continue;
82931 +
82932 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82933 +// continue;
82934 +
82935 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82936 +// continue;
82937 +
82938 + if (walk_struct(type)) {
82939 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82940 + return 1;
82941 + }
82942 + }
82943 + return 0;
82944 +}
82945 +
82946 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82947 +{
82948 + const char * const plugin_name = plugin_info->base_name;
82949 + const int argc = plugin_info->argc;
82950 + const struct plugin_argument * const argv = plugin_info->argv;
82951 + int i;
82952 + bool constify = true;
82953 +
82954 + struct register_pass_info local_variable_pass_info = {
82955 + .pass = &pass_local_variable.pass,
82956 + .reference_pass_name = "*referenced_vars",
82957 + .ref_pass_instance_number = 1,
82958 + .pos_op = PASS_POS_INSERT_AFTER
82959 + };
82960 +
82961 + if (!plugin_default_version_check(version, &gcc_version)) {
82962 + error(G_("incompatible gcc/plugin versions"));
82963 + return 1;
82964 + }
82965 +
82966 + for (i = 0; i < argc; ++i) {
82967 + if (!(strcmp(argv[i].key, "no-constify"))) {
82968 + constify = false;
82969 + continue;
82970 + }
82971 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82972 + }
82973 +
82974 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82975 + if (constify) {
82976 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82977 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82978 + }
82979 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82980 +
82981 + return 0;
82982 +}
82983 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82984 new file mode 100644
82985 index 0000000..e518932
82986 --- /dev/null
82987 +++ b/tools/gcc/generate_size_overflow_hash.sh
82988 @@ -0,0 +1,94 @@
82989 +#!/bin/bash
82990 +
82991 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82992 +
82993 +header1="size_overflow_hash.h"
82994 +database="size_overflow_hash.data"
82995 +n=65536
82996 +
82997 +usage() {
82998 +cat <<EOF
82999 +usage: $0 options
83000 +OPTIONS:
83001 + -h|--help help
83002 + -o header file
83003 + -d database file
83004 + -n hash array size
83005 +EOF
83006 + return 0
83007 +}
83008 +
83009 +while true
83010 +do
83011 + case "$1" in
83012 + -h|--help) usage && exit 0;;
83013 + -n) n=$2; shift 2;;
83014 + -o) header1="$2"; shift 2;;
83015 + -d) database="$2"; shift 2;;
83016 + --) shift 1; break ;;
83017 + *) break ;;
83018 + esac
83019 +done
83020 +
83021 +create_defines() {
83022 + for i in `seq 0 31`
83023 + do
83024 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83025 + done
83026 + echo >> "$header1"
83027 +}
83028 +
83029 +create_structs() {
83030 + rm -f "$header1"
83031 +
83032 + create_defines
83033 +
83034 + cat "$database" | while read data
83035 + do
83036 + data_array=($data)
83037 + struct_hash_name="${data_array[0]}"
83038 + funcn="${data_array[1]}"
83039 + params="${data_array[2]}"
83040 + next="${data_array[4]}"
83041 +
83042 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83043 +
83044 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83045 + echo -en "\t.param\t= " >> "$header1"
83046 + line=
83047 + for param_num in ${params//-/ };
83048 + do
83049 + line="${line}PARAM"$param_num"|"
83050 + done
83051 +
83052 + echo -e "${line%?},\n};\n" >> "$header1"
83053 + done
83054 +}
83055 +
83056 +create_headers() {
83057 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83058 +}
83059 +
83060 +create_array_elements() {
83061 + index=0
83062 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83063 + do
83064 + data_array=($data)
83065 + i="${data_array[3]}"
83066 + hash="${data_array[0]}"
83067 + while [[ $index -lt $i ]]
83068 + do
83069 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83070 + index=$(($index + 1))
83071 + done
83072 + index=$(($index + 1))
83073 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83074 + done
83075 + echo '};' >> $header1
83076 +}
83077 +
83078 +create_structs
83079 +create_headers
83080 +create_array_elements
83081 +
83082 +exit 0
83083 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83084 new file mode 100644
83085 index 0000000..a86e422
83086 --- /dev/null
83087 +++ b/tools/gcc/kallocstat_plugin.c
83088 @@ -0,0 +1,167 @@
83089 +/*
83090 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83091 + * Licensed under the GPL v2
83092 + *
83093 + * Note: the choice of the license means that the compilation process is
83094 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83095 + * but for the kernel it doesn't matter since it doesn't link against
83096 + * any of the gcc libraries
83097 + *
83098 + * gcc plugin to find the distribution of k*alloc sizes
83099 + *
83100 + * TODO:
83101 + *
83102 + * BUGS:
83103 + * - none known
83104 + */
83105 +#include "gcc-plugin.h"
83106 +#include "config.h"
83107 +#include "system.h"
83108 +#include "coretypes.h"
83109 +#include "tree.h"
83110 +#include "tree-pass.h"
83111 +#include "flags.h"
83112 +#include "intl.h"
83113 +#include "toplev.h"
83114 +#include "plugin.h"
83115 +//#include "expr.h" where are you...
83116 +#include "diagnostic.h"
83117 +#include "plugin-version.h"
83118 +#include "tm.h"
83119 +#include "function.h"
83120 +#include "basic-block.h"
83121 +#include "gimple.h"
83122 +#include "rtl.h"
83123 +#include "emit-rtl.h"
83124 +
83125 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83126 +
83127 +int plugin_is_GPL_compatible;
83128 +
83129 +static const char * const kalloc_functions[] = {
83130 + "__kmalloc",
83131 + "kmalloc",
83132 + "kmalloc_large",
83133 + "kmalloc_node",
83134 + "kmalloc_order",
83135 + "kmalloc_order_trace",
83136 + "kmalloc_slab",
83137 + "kzalloc",
83138 + "kzalloc_node",
83139 +};
83140 +
83141 +static struct plugin_info kallocstat_plugin_info = {
83142 + .version = "201111150100",
83143 +};
83144 +
83145 +static unsigned int execute_kallocstat(void);
83146 +
83147 +static struct gimple_opt_pass kallocstat_pass = {
83148 + .pass = {
83149 + .type = GIMPLE_PASS,
83150 + .name = "kallocstat",
83151 + .gate = NULL,
83152 + .execute = execute_kallocstat,
83153 + .sub = NULL,
83154 + .next = NULL,
83155 + .static_pass_number = 0,
83156 + .tv_id = TV_NONE,
83157 + .properties_required = 0,
83158 + .properties_provided = 0,
83159 + .properties_destroyed = 0,
83160 + .todo_flags_start = 0,
83161 + .todo_flags_finish = 0
83162 + }
83163 +};
83164 +
83165 +static bool is_kalloc(const char *fnname)
83166 +{
83167 + size_t i;
83168 +
83169 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83170 + if (!strcmp(fnname, kalloc_functions[i]))
83171 + return true;
83172 + return false;
83173 +}
83174 +
83175 +static unsigned int execute_kallocstat(void)
83176 +{
83177 + basic_block bb;
83178 +
83179 + // 1. loop through BBs and GIMPLE statements
83180 + FOR_EACH_BB(bb) {
83181 + gimple_stmt_iterator gsi;
83182 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83183 + // gimple match:
83184 + tree fndecl, size;
83185 + gimple call_stmt;
83186 + const char *fnname;
83187 +
83188 + // is it a call
83189 + call_stmt = gsi_stmt(gsi);
83190 + if (!is_gimple_call(call_stmt))
83191 + continue;
83192 + fndecl = gimple_call_fndecl(call_stmt);
83193 + if (fndecl == NULL_TREE)
83194 + continue;
83195 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83196 + continue;
83197 +
83198 + // is it a call to k*alloc
83199 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83200 + if (!is_kalloc(fnname))
83201 + continue;
83202 +
83203 + // is the size arg the result of a simple const assignment
83204 + size = gimple_call_arg(call_stmt, 0);
83205 + while (true) {
83206 + gimple def_stmt;
83207 + expanded_location xloc;
83208 + size_t size_val;
83209 +
83210 + if (TREE_CODE(size) != SSA_NAME)
83211 + break;
83212 + def_stmt = SSA_NAME_DEF_STMT(size);
83213 + if (!def_stmt || !is_gimple_assign(def_stmt))
83214 + break;
83215 + if (gimple_num_ops(def_stmt) != 2)
83216 + break;
83217 + size = gimple_assign_rhs1(def_stmt);
83218 + if (!TREE_CONSTANT(size))
83219 + continue;
83220 + xloc = expand_location(gimple_location(def_stmt));
83221 + if (!xloc.file)
83222 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83223 + size_val = TREE_INT_CST_LOW(size);
83224 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83225 + break;
83226 + }
83227 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83228 +//debug_tree(gimple_call_fn(call_stmt));
83229 +//print_node(stderr, "pax", fndecl, 4);
83230 + }
83231 + }
83232 +
83233 + return 0;
83234 +}
83235 +
83236 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83237 +{
83238 + const char * const plugin_name = plugin_info->base_name;
83239 + struct register_pass_info kallocstat_pass_info = {
83240 + .pass = &kallocstat_pass.pass,
83241 + .reference_pass_name = "ssa",
83242 + .ref_pass_instance_number = 1,
83243 + .pos_op = PASS_POS_INSERT_AFTER
83244 + };
83245 +
83246 + if (!plugin_default_version_check(version, &gcc_version)) {
83247 + error(G_("incompatible gcc/plugin versions"));
83248 + return 1;
83249 + }
83250 +
83251 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83252 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83253 +
83254 + return 0;
83255 +}
83256 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83257 new file mode 100644
83258 index 0000000..8856202
83259 --- /dev/null
83260 +++ b/tools/gcc/kernexec_plugin.c
83261 @@ -0,0 +1,432 @@
83262 +/*
83263 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83264 + * Licensed under the GPL v2
83265 + *
83266 + * Note: the choice of the license means that the compilation process is
83267 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83268 + * but for the kernel it doesn't matter since it doesn't link against
83269 + * any of the gcc libraries
83270 + *
83271 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83272 + *
83273 + * TODO:
83274 + *
83275 + * BUGS:
83276 + * - none known
83277 + */
83278 +#include "gcc-plugin.h"
83279 +#include "config.h"
83280 +#include "system.h"
83281 +#include "coretypes.h"
83282 +#include "tree.h"
83283 +#include "tree-pass.h"
83284 +#include "flags.h"
83285 +#include "intl.h"
83286 +#include "toplev.h"
83287 +#include "plugin.h"
83288 +//#include "expr.h" where are you...
83289 +#include "diagnostic.h"
83290 +#include "plugin-version.h"
83291 +#include "tm.h"
83292 +#include "function.h"
83293 +#include "basic-block.h"
83294 +#include "gimple.h"
83295 +#include "rtl.h"
83296 +#include "emit-rtl.h"
83297 +#include "tree-flow.h"
83298 +
83299 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83300 +extern rtx emit_move_insn(rtx x, rtx y);
83301 +
83302 +#if BUILDING_GCC_VERSION <= 4006
83303 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
83304 +#endif
83305 +
83306 +int plugin_is_GPL_compatible;
83307 +
83308 +static struct plugin_info kernexec_plugin_info = {
83309 + .version = "201111291120",
83310 + .help = "method=[bts|or]\tinstrumentation method\n"
83311 +};
83312 +
83313 +static unsigned int execute_kernexec_reload(void);
83314 +static unsigned int execute_kernexec_fptr(void);
83315 +static unsigned int execute_kernexec_retaddr(void);
83316 +static bool kernexec_cmodel_check(void);
83317 +
83318 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83319 +static void (*kernexec_instrument_retaddr)(rtx);
83320 +
83321 +static struct gimple_opt_pass kernexec_reload_pass = {
83322 + .pass = {
83323 + .type = GIMPLE_PASS,
83324 + .name = "kernexec_reload",
83325 + .gate = kernexec_cmodel_check,
83326 + .execute = execute_kernexec_reload,
83327 + .sub = NULL,
83328 + .next = NULL,
83329 + .static_pass_number = 0,
83330 + .tv_id = TV_NONE,
83331 + .properties_required = 0,
83332 + .properties_provided = 0,
83333 + .properties_destroyed = 0,
83334 + .todo_flags_start = 0,
83335 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83336 + }
83337 +};
83338 +
83339 +static struct gimple_opt_pass kernexec_fptr_pass = {
83340 + .pass = {
83341 + .type = GIMPLE_PASS,
83342 + .name = "kernexec_fptr",
83343 + .gate = kernexec_cmodel_check,
83344 + .execute = execute_kernexec_fptr,
83345 + .sub = NULL,
83346 + .next = NULL,
83347 + .static_pass_number = 0,
83348 + .tv_id = TV_NONE,
83349 + .properties_required = 0,
83350 + .properties_provided = 0,
83351 + .properties_destroyed = 0,
83352 + .todo_flags_start = 0,
83353 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83354 + }
83355 +};
83356 +
83357 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83358 + .pass = {
83359 + .type = RTL_PASS,
83360 + .name = "kernexec_retaddr",
83361 + .gate = kernexec_cmodel_check,
83362 + .execute = execute_kernexec_retaddr,
83363 + .sub = NULL,
83364 + .next = NULL,
83365 + .static_pass_number = 0,
83366 + .tv_id = TV_NONE,
83367 + .properties_required = 0,
83368 + .properties_provided = 0,
83369 + .properties_destroyed = 0,
83370 + .todo_flags_start = 0,
83371 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83372 + }
83373 +};
83374 +
83375 +static bool kernexec_cmodel_check(void)
83376 +{
83377 + tree section;
83378 +
83379 + if (ix86_cmodel != CM_KERNEL)
83380 + return false;
83381 +
83382 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83383 + if (!section || !TREE_VALUE(section))
83384 + return true;
83385 +
83386 + section = TREE_VALUE(TREE_VALUE(section));
83387 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83388 + return true;
83389 +
83390 + return false;
83391 +}
83392 +
83393 +/*
83394 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83395 + */
83396 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83397 +{
83398 + gimple asm_movabs_stmt;
83399 +
83400 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83401 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83402 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83403 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83404 + update_stmt(asm_movabs_stmt);
83405 +}
83406 +
83407 +/*
83408 + * find all asm() stmts that clobber r10 and add a reload of r10
83409 + */
83410 +static unsigned int execute_kernexec_reload(void)
83411 +{
83412 + basic_block bb;
83413 +
83414 + // 1. loop through BBs and GIMPLE statements
83415 + FOR_EACH_BB(bb) {
83416 + gimple_stmt_iterator gsi;
83417 +
83418 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83419 + // gimple match: __asm__ ("" : : : "r10");
83420 + gimple asm_stmt;
83421 + size_t nclobbers;
83422 +
83423 + // is it an asm ...
83424 + asm_stmt = gsi_stmt(gsi);
83425 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83426 + continue;
83427 +
83428 + // ... clobbering r10
83429 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83430 + while (nclobbers--) {
83431 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83432 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83433 + continue;
83434 + kernexec_reload_fptr_mask(&gsi);
83435 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83436 + break;
83437 + }
83438 + }
83439 + }
83440 +
83441 + return 0;
83442 +}
83443 +
83444 +/*
83445 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83446 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83447 + */
83448 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83449 +{
83450 + gimple assign_intptr, assign_new_fptr, call_stmt;
83451 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83452 +
83453 + call_stmt = gsi_stmt(*gsi);
83454 + old_fptr = gimple_call_fn(call_stmt);
83455 +
83456 + // create temporary unsigned long variable used for bitops and cast fptr to it
83457 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83458 + add_referenced_var(intptr);
83459 + mark_sym_for_renaming(intptr);
83460 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83461 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83462 + update_stmt(assign_intptr);
83463 +
83464 + // apply logical or to temporary unsigned long and bitmask
83465 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83466 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83467 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83468 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83469 + update_stmt(assign_intptr);
83470 +
83471 + // cast temporary unsigned long back to a temporary fptr variable
83472 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83473 + add_referenced_var(new_fptr);
83474 + mark_sym_for_renaming(new_fptr);
83475 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83476 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83477 + update_stmt(assign_new_fptr);
83478 +
83479 + // replace call stmt fn with the new fptr
83480 + gimple_call_set_fn(call_stmt, new_fptr);
83481 + update_stmt(call_stmt);
83482 +}
83483 +
83484 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83485 +{
83486 + gimple asm_or_stmt, call_stmt;
83487 + tree old_fptr, new_fptr, input, output;
83488 + VEC(tree, gc) *inputs = NULL;
83489 + VEC(tree, gc) *outputs = NULL;
83490 +
83491 + call_stmt = gsi_stmt(*gsi);
83492 + old_fptr = gimple_call_fn(call_stmt);
83493 +
83494 + // create temporary fptr variable
83495 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83496 + add_referenced_var(new_fptr);
83497 + mark_sym_for_renaming(new_fptr);
83498 +
83499 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83500 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83501 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83502 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83503 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83504 + VEC_safe_push(tree, gc, inputs, input);
83505 + VEC_safe_push(tree, gc, outputs, output);
83506 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83507 + gimple_asm_set_volatile(asm_or_stmt, true);
83508 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83509 + update_stmt(asm_or_stmt);
83510 +
83511 + // replace call stmt fn with the new fptr
83512 + gimple_call_set_fn(call_stmt, new_fptr);
83513 + update_stmt(call_stmt);
83514 +}
83515 +
83516 +/*
83517 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83518 + */
83519 +static unsigned int execute_kernexec_fptr(void)
83520 +{
83521 + basic_block bb;
83522 +
83523 + // 1. loop through BBs and GIMPLE statements
83524 + FOR_EACH_BB(bb) {
83525 + gimple_stmt_iterator gsi;
83526 +
83527 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83528 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83529 + tree fn;
83530 + gimple call_stmt;
83531 +
83532 + // is it a call ...
83533 + call_stmt = gsi_stmt(gsi);
83534 + if (!is_gimple_call(call_stmt))
83535 + continue;
83536 + fn = gimple_call_fn(call_stmt);
83537 + if (TREE_CODE(fn) == ADDR_EXPR)
83538 + continue;
83539 + if (TREE_CODE(fn) != SSA_NAME)
83540 + gcc_unreachable();
83541 +
83542 + // ... through a function pointer
83543 + fn = SSA_NAME_VAR(fn);
83544 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83545 + continue;
83546 + fn = TREE_TYPE(fn);
83547 + if (TREE_CODE(fn) != POINTER_TYPE)
83548 + continue;
83549 + fn = TREE_TYPE(fn);
83550 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83551 + continue;
83552 +
83553 + kernexec_instrument_fptr(&gsi);
83554 +
83555 +//debug_tree(gimple_call_fn(call_stmt));
83556 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83557 + }
83558 + }
83559 +
83560 + return 0;
83561 +}
83562 +
83563 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83564 +static void kernexec_instrument_retaddr_bts(rtx insn)
83565 +{
83566 + rtx btsq;
83567 + rtvec argvec, constraintvec, labelvec;
83568 + int line;
83569 +
83570 + // create asm volatile("btsq $63,(%%rsp)":::)
83571 + argvec = rtvec_alloc(0);
83572 + constraintvec = rtvec_alloc(0);
83573 + labelvec = rtvec_alloc(0);
83574 + line = expand_location(RTL_LOCATION(insn)).line;
83575 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83576 + MEM_VOLATILE_P(btsq) = 1;
83577 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83578 + emit_insn_before(btsq, insn);
83579 +}
83580 +
83581 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83582 +static void kernexec_instrument_retaddr_or(rtx insn)
83583 +{
83584 + rtx orq;
83585 + rtvec argvec, constraintvec, labelvec;
83586 + int line;
83587 +
83588 + // create asm volatile("orq %%r10,(%%rsp)":::)
83589 + argvec = rtvec_alloc(0);
83590 + constraintvec = rtvec_alloc(0);
83591 + labelvec = rtvec_alloc(0);
83592 + line = expand_location(RTL_LOCATION(insn)).line;
83593 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83594 + MEM_VOLATILE_P(orq) = 1;
83595 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83596 + emit_insn_before(orq, insn);
83597 +}
83598 +
83599 +/*
83600 + * find all asm level function returns and forcibly set the highest bit of the return address
83601 + */
83602 +static unsigned int execute_kernexec_retaddr(void)
83603 +{
83604 + rtx insn;
83605 +
83606 + // 1. find function returns
83607 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83608 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83609 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83610 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
83611 + rtx body;
83612 +
83613 + // is it a retn
83614 + if (!JUMP_P(insn))
83615 + continue;
83616 + body = PATTERN(insn);
83617 + if (GET_CODE(body) == PARALLEL)
83618 + body = XVECEXP(body, 0, 0);
83619 + if (!ANY_RETURN_P(body))
83620 + continue;
83621 + kernexec_instrument_retaddr(insn);
83622 + }
83623 +
83624 +// print_simple_rtl(stderr, get_insns());
83625 +// print_rtl(stderr, get_insns());
83626 +
83627 + return 0;
83628 +}
83629 +
83630 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83631 +{
83632 + const char * const plugin_name = plugin_info->base_name;
83633 + const int argc = plugin_info->argc;
83634 + const struct plugin_argument * const argv = plugin_info->argv;
83635 + int i;
83636 + struct register_pass_info kernexec_reload_pass_info = {
83637 + .pass = &kernexec_reload_pass.pass,
83638 + .reference_pass_name = "ssa",
83639 + .ref_pass_instance_number = 1,
83640 + .pos_op = PASS_POS_INSERT_AFTER
83641 + };
83642 + struct register_pass_info kernexec_fptr_pass_info = {
83643 + .pass = &kernexec_fptr_pass.pass,
83644 + .reference_pass_name = "ssa",
83645 + .ref_pass_instance_number = 1,
83646 + .pos_op = PASS_POS_INSERT_AFTER
83647 + };
83648 + struct register_pass_info kernexec_retaddr_pass_info = {
83649 + .pass = &kernexec_retaddr_pass.pass,
83650 + .reference_pass_name = "pro_and_epilogue",
83651 + .ref_pass_instance_number = 1,
83652 + .pos_op = PASS_POS_INSERT_AFTER
83653 + };
83654 +
83655 + if (!plugin_default_version_check(version, &gcc_version)) {
83656 + error(G_("incompatible gcc/plugin versions"));
83657 + return 1;
83658 + }
83659 +
83660 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83661 +
83662 + if (TARGET_64BIT == 0)
83663 + return 0;
83664 +
83665 + for (i = 0; i < argc; ++i) {
83666 + if (!strcmp(argv[i].key, "method")) {
83667 + if (!argv[i].value) {
83668 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83669 + continue;
83670 + }
83671 + if (!strcmp(argv[i].value, "bts")) {
83672 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83673 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83674 + } else if (!strcmp(argv[i].value, "or")) {
83675 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83676 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83677 + fix_register("r10", 1, 1);
83678 + } else
83679 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83680 + continue;
83681 + }
83682 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83683 + }
83684 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83685 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83686 +
83687 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83688 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83689 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83690 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83691 +
83692 + return 0;
83693 +}
83694 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83695 new file mode 100644
83696 index 0000000..b8008f7
83697 --- /dev/null
83698 +++ b/tools/gcc/latent_entropy_plugin.c
83699 @@ -0,0 +1,295 @@
83700 +/*
83701 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83702 + * Licensed under the GPL v2
83703 + *
83704 + * Note: the choice of the license means that the compilation process is
83705 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83706 + * but for the kernel it doesn't matter since it doesn't link against
83707 + * any of the gcc libraries
83708 + *
83709 + * gcc plugin to help generate a little bit of entropy from program state,
83710 + * used during boot in the kernel
83711 + *
83712 + * TODO:
83713 + * - add ipa pass to identify not explicitly marked candidate functions
83714 + * - mix in more program state (function arguments/return values, loop variables, etc)
83715 + * - more instrumentation control via attribute parameters
83716 + *
83717 + * BUGS:
83718 + * - LTO needs -flto-partition=none for now
83719 + */
83720 +#include "gcc-plugin.h"
83721 +#include "config.h"
83722 +#include "system.h"
83723 +#include "coretypes.h"
83724 +#include "tree.h"
83725 +#include "tree-pass.h"
83726 +#include "flags.h"
83727 +#include "intl.h"
83728 +#include "toplev.h"
83729 +#include "plugin.h"
83730 +//#include "expr.h" where are you...
83731 +#include "diagnostic.h"
83732 +#include "plugin-version.h"
83733 +#include "tm.h"
83734 +#include "function.h"
83735 +#include "basic-block.h"
83736 +#include "gimple.h"
83737 +#include "rtl.h"
83738 +#include "emit-rtl.h"
83739 +#include "tree-flow.h"
83740 +
83741 +int plugin_is_GPL_compatible;
83742 +
83743 +static tree latent_entropy_decl;
83744 +
83745 +static struct plugin_info latent_entropy_plugin_info = {
83746 + .version = "201207271820",
83747 + .help = NULL
83748 +};
83749 +
83750 +static unsigned int execute_latent_entropy(void);
83751 +static bool gate_latent_entropy(void);
83752 +
83753 +static struct gimple_opt_pass latent_entropy_pass = {
83754 + .pass = {
83755 + .type = GIMPLE_PASS,
83756 + .name = "latent_entropy",
83757 + .gate = gate_latent_entropy,
83758 + .execute = execute_latent_entropy,
83759 + .sub = NULL,
83760 + .next = NULL,
83761 + .static_pass_number = 0,
83762 + .tv_id = TV_NONE,
83763 + .properties_required = PROP_gimple_leh | PROP_cfg,
83764 + .properties_provided = 0,
83765 + .properties_destroyed = 0,
83766 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83767 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83768 + }
83769 +};
83770 +
83771 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83772 +{
83773 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83774 + *no_add_attrs = true;
83775 + error("%qE attribute only applies to functions", name);
83776 + }
83777 + return NULL_TREE;
83778 +}
83779 +
83780 +static struct attribute_spec latent_entropy_attr = {
83781 + .name = "latent_entropy",
83782 + .min_length = 0,
83783 + .max_length = 0,
83784 + .decl_required = true,
83785 + .type_required = false,
83786 + .function_type_required = false,
83787 + .handler = handle_latent_entropy_attribute,
83788 +#if BUILDING_GCC_VERSION >= 4007
83789 + .affects_type_identity = false
83790 +#endif
83791 +};
83792 +
83793 +static void register_attributes(void *event_data, void *data)
83794 +{
83795 + register_attribute(&latent_entropy_attr);
83796 +}
83797 +
83798 +static bool gate_latent_entropy(void)
83799 +{
83800 + tree latent_entropy_attr;
83801 +
83802 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83803 + return latent_entropy_attr != NULL_TREE;
83804 +}
83805 +
83806 +static unsigned HOST_WIDE_INT seed;
83807 +static unsigned HOST_WIDE_INT get_random_const(void)
83808 +{
83809 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83810 + return seed;
83811 +}
83812 +
83813 +static enum tree_code get_op(tree *rhs)
83814 +{
83815 + static enum tree_code op;
83816 + unsigned HOST_WIDE_INT random_const;
83817 +
83818 + random_const = get_random_const();
83819 +
83820 + switch (op) {
83821 + case BIT_XOR_EXPR:
83822 + op = PLUS_EXPR;
83823 + break;
83824 +
83825 + case PLUS_EXPR:
83826 + if (rhs) {
83827 + op = LROTATE_EXPR;
83828 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83829 + break;
83830 + }
83831 +
83832 + case LROTATE_EXPR:
83833 + default:
83834 + op = BIT_XOR_EXPR;
83835 + break;
83836 + }
83837 + if (rhs)
83838 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83839 + return op;
83840 +}
83841 +
83842 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83843 +{
83844 + gimple_stmt_iterator gsi;
83845 + gimple assign;
83846 + tree addxorrol, rhs;
83847 + enum tree_code op;
83848 +
83849 + op = get_op(&rhs);
83850 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83851 + assign = gimple_build_assign(local_entropy, addxorrol);
83852 + find_referenced_vars_in(assign);
83853 +//debug_bb(bb);
83854 + gsi = gsi_after_labels(bb);
83855 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83856 + update_stmt(assign);
83857 +}
83858 +
83859 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83860 +{
83861 + gimple_stmt_iterator gsi;
83862 + gimple assign;
83863 + tree addxorrol, temp;
83864 +
83865 + // 1. create temporary copy of latent_entropy
83866 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83867 + add_referenced_var(temp);
83868 + mark_sym_for_renaming(temp);
83869 +
83870 + // 2. read...
83871 + assign = gimple_build_assign(temp, latent_entropy_decl);
83872 + find_referenced_vars_in(assign);
83873 + gsi = gsi_after_labels(bb);
83874 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83875 + update_stmt(assign);
83876 +
83877 + // 3. ...modify...
83878 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83879 + assign = gimple_build_assign(temp, addxorrol);
83880 + find_referenced_vars_in(assign);
83881 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83882 + update_stmt(assign);
83883 +
83884 + // 4. ...write latent_entropy
83885 + assign = gimple_build_assign(latent_entropy_decl, temp);
83886 + find_referenced_vars_in(assign);
83887 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83888 + update_stmt(assign);
83889 +}
83890 +
83891 +static unsigned int execute_latent_entropy(void)
83892 +{
83893 + basic_block bb;
83894 + gimple assign;
83895 + gimple_stmt_iterator gsi;
83896 + tree local_entropy;
83897 +
83898 + if (!latent_entropy_decl) {
83899 + struct varpool_node *node;
83900 +
83901 + for (node = varpool_nodes; node; node = node->next) {
83902 + tree var = node->decl;
83903 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83904 + continue;
83905 + latent_entropy_decl = var;
83906 +// debug_tree(var);
83907 + break;
83908 + }
83909 + if (!latent_entropy_decl) {
83910 +// debug_tree(current_function_decl);
83911 + return 0;
83912 + }
83913 + }
83914 +
83915 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83916 +
83917 + // 1. create local entropy variable
83918 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83919 + add_referenced_var(local_entropy);
83920 + mark_sym_for_renaming(local_entropy);
83921 +
83922 + // 2. initialize local entropy variable
83923 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83924 + if (dom_info_available_p(CDI_DOMINATORS))
83925 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83926 + gsi = gsi_start_bb(bb);
83927 +
83928 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83929 +// gimple_set_location(assign, loc);
83930 + find_referenced_vars_in(assign);
83931 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83932 + update_stmt(assign);
83933 + bb = bb->next_bb;
83934 +
83935 + // 3. instrument each BB with an operation on the local entropy variable
83936 + while (bb != EXIT_BLOCK_PTR) {
83937 + perturb_local_entropy(bb, local_entropy);
83938 + bb = bb->next_bb;
83939 + };
83940 +
83941 + // 4. mix local entropy into the global entropy variable
83942 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83943 + return 0;
83944 +}
83945 +
83946 +static void start_unit_callback(void *gcc_data, void *user_data)
83947 +{
83948 +#if BUILDING_GCC_VERSION >= 4007
83949 + seed = get_random_seed(false);
83950 +#else
83951 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83952 + seed *= seed;
83953 +#endif
83954 +
83955 + if (in_lto_p)
83956 + return;
83957 +
83958 + // extern u64 latent_entropy
83959 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83960 +
83961 + TREE_STATIC(latent_entropy_decl) = 1;
83962 + TREE_PUBLIC(latent_entropy_decl) = 1;
83963 + TREE_USED(latent_entropy_decl) = 1;
83964 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83965 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83966 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83967 + DECL_INITIAL(latent_entropy_decl) = NULL;
83968 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83969 +// varpool_finalize_decl(latent_entropy_decl);
83970 +// varpool_mark_needed_node(latent_entropy_decl);
83971 +}
83972 +
83973 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83974 +{
83975 + const char * const plugin_name = plugin_info->base_name;
83976 + struct register_pass_info latent_entropy_pass_info = {
83977 + .pass = &latent_entropy_pass.pass,
83978 + .reference_pass_name = "optimized",
83979 + .ref_pass_instance_number = 1,
83980 + .pos_op = PASS_POS_INSERT_BEFORE
83981 + };
83982 +
83983 + if (!plugin_default_version_check(version, &gcc_version)) {
83984 + error(G_("incompatible gcc/plugin versions"));
83985 + return 1;
83986 + }
83987 +
83988 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83989 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83990 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83991 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83992 +
83993 + return 0;
83994 +}
83995 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83996 new file mode 100644
83997 index 0000000..afebc99
83998 --- /dev/null
83999 +++ b/tools/gcc/size_overflow_hash.data
84000 @@ -0,0 +1,3709 @@
84001 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
84002 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
84003 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
84004 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
84005 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
84006 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
84007 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
84008 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
84009 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
84010 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
84011 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
84012 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
84013 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
84014 +create_log_8225 create_log 2 8225 NULL
84015 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
84016 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
84017 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
84018 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
84019 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
84020 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
84021 +padzero_55 padzero 1 55 &sel_read_policyvers_55
84022 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
84023 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
84024 +read_file_blob_57406 read_file_blob 3 57406 NULL
84025 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
84026 +enclosure_register_57412 enclosure_register 3 57412 NULL
84027 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
84028 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
84029 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
84030 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
84031 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
84032 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
84033 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
84034 +init_cdev_8274 init_cdev 1 8274 NULL
84035 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
84036 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
84037 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
84038 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
84039 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
84040 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
84041 +load_msg_95 load_msg 2 95 NULL
84042 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
84043 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
84044 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
84045 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
84046 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
84047 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
84048 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
84049 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
84050 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
84051 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
84052 +send_midi_async_57463 send_midi_async 3 57463 NULL
84053 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
84054 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
84055 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
84056 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
84057 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
84058 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
84059 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
84060 +init_q_132 init_q 4 132 NULL
84061 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
84062 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
84063 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
84064 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
84065 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
84066 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
84067 +uio_read_49300 uio_read 3 49300 NULL
84068 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
84069 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
84070 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
84071 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
84072 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
84073 +play_iframe_8219 play_iframe 3 8219 NULL
84074 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
84075 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
84076 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
84077 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
84078 +init_tag_map_57515 init_tag_map 3 57515 NULL
84079 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
84080 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
84081 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
84082 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
84083 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
84084 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
84085 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
84086 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
84087 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
84088 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
84089 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
84090 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
84091 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
84092 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
84093 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
84094 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
84095 +cache_read_24790 cache_read 3 24790 NULL
84096 +px_raw_event_49371 px_raw_event 4 49371 NULL
84097 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
84098 +compat_filldir_32999 compat_filldir 3 32999 NULL
84099 +hci_si_event_1404 hci_si_event 3 1404 NULL
84100 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
84101 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
84102 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
84103 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
84104 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
84105 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
84106 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
84107 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
84108 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
84109 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
84110 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
84111 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
84112 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
84113 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
84114 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
84115 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
84116 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
84117 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
84118 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
84119 +mem_read_57631 mem_read 3 57631 NULL
84120 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
84121 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
84122 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
84123 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
84124 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
84125 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
84126 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
84127 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
84128 +queues_read_24877 queues_read 3 24877 NULL
84129 +__fprog_create_41263 __fprog_create 2 41263 NULL
84130 +syslog_print_307 syslog_print 2 307 NULL
84131 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
84132 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
84133 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
84134 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
84135 +r3964_write_57662 r3964_write 4 57662 NULL
84136 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
84137 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
84138 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
84139 +alloc_context_41283 alloc_context 1 41283 NULL
84140 +__lgwrite_57669 __lgwrite 4 57669 NULL
84141 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
84142 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
84143 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
84144 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
84145 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
84146 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
84147 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
84148 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
84149 +write_node_33121 write_node 4 33121 NULL
84150 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
84151 +profile_remove_8556 profile_remove 3 8556 NULL
84152 +evm_read_key_54674 evm_read_key 3 54674 NULL
84153 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
84154 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
84155 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
84156 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
84157 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
84158 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
84159 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
84160 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
84161 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
84162 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
84163 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
84164 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
84165 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
84166 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
84167 +smk_write_access_49561 smk_write_access 3 49561 NULL
84168 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
84169 +kmp_init_41373 kmp_init 2 41373 NULL
84170 +context_alloc_24645 context_alloc 3 24645 NULL
84171 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
84172 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
84173 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
84174 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
84175 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
84176 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
84177 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
84178 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
84179 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
84180 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
84181 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
84182 +pp_read_33210 pp_read 3 33210 NULL
84183 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
84184 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
84185 +ivtv_read_57796 ivtv_read 3 57796 NULL
84186 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
84187 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
84188 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
84189 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
84190 +heap_init_49617 heap_init 2 49617 NULL
84191 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
84192 +aoechr_write_62883 aoechr_write 3 62883 NULL nohasharray
84193 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 &aoechr_write_62883
84194 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
84195 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
84196 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
84197 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
84198 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
84199 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
84200 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
84201 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
84202 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
84203 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
84204 +st_write_16874 st_write 3 16874 NULL
84205 +copy_to_user_57835 copy_to_user 3 57835 NULL
84206 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
84207 +pidlist_resize_496 pidlist_resize 2 496 NULL
84208 +flash_read_57843 flash_read 3 57843 NULL
84209 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
84210 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
84211 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
84212 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
84213 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
84214 +arcfb_write_8702 arcfb_write 3 8702 NULL
84215 +send_to_tty_45141 send_to_tty 3 45141 NULL
84216 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
84217 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
84218 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
84219 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
84220 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
84221 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
84222 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
84223 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
84224 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
84225 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
84226 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
84227 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
84228 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
84229 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
84230 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
84231 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
84232 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
84233 +vhci_read_47878 vhci_read 3 47878 NULL
84234 +devres_alloc_551 devres_alloc 2 551 NULL
84235 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
84236 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
84237 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
84238 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
84239 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
84240 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
84241 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
84242 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
84243 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
84244 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
84245 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
84246 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
84247 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
84248 +sys_prctl_8766 sys_prctl 4 8766 NULL
84249 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
84250 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
84251 +insert_one_name_61668 insert_one_name 7 61668 NULL
84252 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
84253 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
84254 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
84255 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
84256 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
84257 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
84258 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
84259 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
84260 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
84261 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
84262 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
84263 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
84264 +gserial_setup_41558 gserial_setup 2 41558 NULL
84265 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
84266 +rx_57944 rx 4 57944 NULL
84267 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
84268 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
84269 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
84270 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
84271 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
84272 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
84273 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
84274 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
84275 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
84276 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
84277 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
84278 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
84279 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
84280 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
84281 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
84282 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
84283 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
84284 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
84285 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
84286 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
84287 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
84288 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
84289 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
84290 +a2mp_send_41615 a2mp_send 4 41615 NULL
84291 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
84292 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
84293 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
84294 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
84295 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
84296 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
84297 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
84298 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
84299 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
84300 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
84301 +add_uuid_49831 add_uuid 4 49831 NULL
84302 +send_pages_8872 send_pages 3 8872 NULL
84303 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
84304 +read_file_recv_48232 read_file_recv 3 48232 NULL
84305 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
84306 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
84307 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
84308 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
84309 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
84310 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
84311 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
84312 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
84313 +vfs_writev_25278 vfs_writev 3 25278 NULL
84314 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
84315 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
84316 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
84317 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
84318 +create_entry_33479 create_entry 2 33479 NULL
84319 +mce_async_out_58056 mce_async_out 3 58056 NULL
84320 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
84321 +sys_preadv_17100 sys_preadv 3 17100 NULL
84322 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
84323 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
84324 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
84325 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
84326 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
84327 +res_counter_read_33499 res_counter_read 4 33499 NULL
84328 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
84329 +cm4040_write_58079 cm4040_write 3 58079 NULL
84330 +fb_read_33506 fb_read 3 33506 NULL
84331 +help_25316 help 5 25316 NULL nohasharray
84332 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
84333 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
84334 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
84335 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
84336 +ddp_set_map_751 ddp_set_map 4 751 NULL
84337 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
84338 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
84339 +dvb_video_write_754 dvb_video_write 3 754 NULL
84340 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
84341 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
84342 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
84343 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
84344 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
84345 +udi_log_event_58105 udi_log_event 3 58105 NULL
84346 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
84347 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
84348 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
84349 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
84350 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
84351 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
84352 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
84353 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
84354 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
84355 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
84356 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
84357 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
84358 +sep_read_17161 sep_read 3 17161 NULL
84359 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
84360 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
84361 +dup_array_33551 dup_array 3 33551 NULL
84362 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
84363 +fillonedir_41746 fillonedir 3 41746 NULL
84364 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
84365 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
84366 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
84367 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
84368 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
84369 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
84370 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
84371 +if_writecmd_815 if_writecmd 2 815 NULL
84372 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
84373 +read_fifo_826 read_fifo 3 826 NULL
84374 +scsi_execute_33596 scsi_execute 5 33596 NULL
84375 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
84376 +ms_rw_17220 ms_rw 3-4 17220 NULL
84377 +read_tree_block_841 read_tree_block 3 841 NULL
84378 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
84379 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
84380 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
84381 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
84382 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
84383 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
84384 +um_idi_read_850 um_idi_read 3 850 NULL
84385 +__module_alloc_50004 __module_alloc 1 50004 NULL
84386 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
84387 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
84388 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
84389 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
84390 +provide_user_output_41105 provide_user_output 3 41105 NULL
84391 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
84392 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
84393 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
84394 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
84395 +alloc_ep_17269 alloc_ep 1 17269 NULL
84396 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
84397 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
84398 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
84399 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
84400 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
84401 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
84402 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
84403 +create_queues_9088 create_queues 2-3 9088 NULL
84404 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
84405 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
84406 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
84407 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
84408 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
84409 +read_file_debug_58256 read_file_debug 3 58256 NULL
84410 +skb_pad_17302 skb_pad 2 17302 NULL
84411 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
84412 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
84413 +profile_load_58267 profile_load 3 58267 NULL
84414 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
84415 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
84416 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
84417 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
84418 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
84419 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
84420 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
84421 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
84422 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
84423 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
84424 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
84425 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
84426 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
84427 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
84428 +get_packet_41914 get_packet 3 41914 NULL
84429 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
84430 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
84431 +read_file_slot_50111 read_file_slot 3 50111 NULL
84432 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
84433 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
84434 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
84435 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
84436 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
84437 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
84438 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
84439 +copy_items_50140 copy_items 6 50140 NULL
84440 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
84441 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
84442 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
84443 +ts_write_64336 ts_write 3 64336 NULL
84444 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
84445 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
84446 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
84447 +portnames_read_41958 portnames_read 3 41958 NULL
84448 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
84449 +hashtab_create_33769 hashtab_create 3 33769 NULL
84450 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
84451 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
84452 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
84453 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
84454 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
84455 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
84456 +odev_update_50169 odev_update 2 50169 NULL
84457 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
84458 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
84459 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
84460 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
84461 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
84462 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
84463 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
84464 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
84465 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
84466 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
84467 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
84468 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
84469 +lguest_map_42008 lguest_map 1-2 42008 NULL
84470 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
84471 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
84472 +pool_allocate_42012 pool_allocate 3 42012 NULL
84473 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
84474 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
84475 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
84476 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
84477 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
84478 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
84479 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
84480 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
84481 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
84482 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
84483 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
84484 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
84485 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
84486 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
84487 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
84488 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
84489 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
84490 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
84491 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
84492 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
84493 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
84494 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
84495 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
84496 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
84497 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
84498 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
84499 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
84500 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
84501 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
84502 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
84503 +config_proc_write_33878 config_proc_write 3 33878 NULL
84504 +capabilities_read_58457 capabilities_read 3 58457 NULL
84505 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
84506 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
84507 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
84508 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
84509 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
84510 +dm_table_create_35687 dm_table_create 3 35687 NULL
84511 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
84512 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
84513 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
84514 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
84515 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
84516 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
84517 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
84518 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
84519 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
84520 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
84521 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
84522 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
84523 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
84524 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
84525 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
84526 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
84527 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
84528 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
84529 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
84530 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
84531 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
84532 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
84533 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
84534 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
84535 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
84536 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
84537 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
84538 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
84539 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
84540 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
84541 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
84542 +read_9397 read 3 9397 NULL
84543 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
84544 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
84545 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
84546 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
84547 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
84548 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
84549 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
84550 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
84551 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
84552 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
84553 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
84554 +osst_execute_17607 osst_execute 7-6 17607 NULL
84555 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
84556 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
84557 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
84558 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
84559 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
84560 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
84561 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
84562 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
84563 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
84564 +xip_file_read_58592 xip_file_read 3 58592 NULL
84565 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
84566 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
84567 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
84568 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
84569 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
84570 +ppp_write_34034 ppp_write 3 34034 NULL
84571 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
84572 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
84573 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
84574 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
84575 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
84576 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
84577 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
84578 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
84579 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
84580 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
84581 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
84582 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
84583 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
84584 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
84585 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
84586 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
84587 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
84588 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
84589 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
84590 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
84591 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
84592 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
84593 +lp_write_9511 lp_write 3 9511 NULL
84594 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
84595 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
84596 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
84597 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
84598 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
84599 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
84600 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
84601 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
84602 +read_file_dma_9530 read_file_dma 3 9530 NULL
84603 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
84604 +rcname_read_25919 rcname_read 3 25919 NULL
84605 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
84606 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
84607 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
84608 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
84609 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
84610 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
84611 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
84612 +key_flags_read_25931 key_flags_read 3 25931 NULL
84613 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
84614 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
84615 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
84616 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
84617 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
84618 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
84619 +fw_node_create_9559 fw_node_create 2 9559 NULL
84620 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
84621 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
84622 +kobj_map_9566 kobj_map 2-3 9566 NULL
84623 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
84624 +acpi_map_58725 acpi_map 1-2 58725 NULL
84625 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
84626 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
84627 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
84628 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
84629 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
84630 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
84631 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
84632 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
84633 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
84634 +file_read_actor_1401 file_read_actor 4 1401 NULL
84635 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
84636 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
84637 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
84638 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
84639 +do_sync_9604 do_sync 1 9604 NULL
84640 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
84641 +compat_readv_30273 compat_readv 3 30273 NULL
84642 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
84643 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
84644 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
84645 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
84646 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
84647 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
84648 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
84649 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
84650 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
84651 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
84652 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
84653 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
84654 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
84655 +sge_rx_50594 sge_rx 3 50594 NULL
84656 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
84657 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
84658 +skb_padto_50759 skb_padto 2 50759 NULL
84659 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
84660 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
84661 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
84662 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
84663 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
84664 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
84665 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
84666 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
84667 +ep_read_58813 ep_read 3 58813 NULL
84668 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
84669 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
84670 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
84671 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
84672 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
84673 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
84674 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
84675 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
84676 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
84677 +dns_query_9676 dns_query 3 9676 NULL
84678 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
84679 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
84680 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
84681 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
84682 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
84683 +command_write_58841 command_write 3 58841 NULL
84684 +dev_config_8506 dev_config 3 8506 NULL
84685 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
84686 +sys_readv_50664 sys_readv 3 50664 NULL
84687 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
84688 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
84689 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
84690 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
84691 +recover_head_17904 recover_head 3 17904 NULL
84692 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
84693 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
84694 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
84695 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
84696 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
84697 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
84698 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
84699 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
84700 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
84701 +skb_cow_26138 skb_cow 2 26138 NULL
84702 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
84703 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
84704 +do_sigpending_9766 do_sigpending 2 9766 NULL
84705 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
84706 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
84707 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
84708 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
84709 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
84710 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
84711 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
84712 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
84713 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
84714 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
84715 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
84716 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
84717 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
84718 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
84719 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
84720 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
84721 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
84722 +get_registers_26187 get_registers 3 26187 NULL
84723 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
84724 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
84725 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
84726 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
84727 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
84728 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
84729 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
84730 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
84731 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
84732 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
84733 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
84734 +mce_write_26201 mce_write 3 26201 NULL
84735 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
84736 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
84737 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
84738 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
84739 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
84740 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
84741 +tpm_write_50798 tpm_write 3 50798 NULL
84742 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
84743 +tun_do_read_50800 tun_do_read 4 50800 NULL
84744 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
84745 +write_flush_50803 write_flush 3 50803 NULL
84746 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
84747 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
84748 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
84749 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
84750 +dvb_play_50814 dvb_play 3 50814 NULL
84751 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
84752 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
84753 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
84754 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
84755 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
84756 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
84757 +dma_attach_50831 dma_attach 6-7 50831 NULL
84758 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
84759 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
84760 +packet_came_18072 packet_came 3 18072 NULL
84761 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
84762 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
84763 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
84764 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
84765 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
84766 +get_vm_area_18080 get_vm_area 1 18080 NULL
84767 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
84768 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
84769 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
84770 +self_check_write_50856 self_check_write 5 50856 NULL
84771 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
84772 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
84773 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
84774 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
84775 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
84776 +get_packet_5747 get_packet 3 5747 NULL
84777 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
84778 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
84779 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
84780 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
84781 +vb2_read_42703 vb2_read 3 42703 NULL
84782 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
84783 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
84784 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
84785 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
84786 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
84787 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
84788 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
84789 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
84790 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
84791 +alloc_buf_34532 alloc_buf 1 34532 NULL
84792 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
84793 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
84794 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
84795 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
84796 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
84797 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
84798 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
84799 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
84800 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
84801 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
84802 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
84803 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
84804 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
84805 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
84806 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
84807 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
84808 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
84809 +mld_newpack_50950 mld_newpack 2 50950 NULL
84810 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
84811 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
84812 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
84813 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
84814 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
84815 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
84816 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
84817 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
84818 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
84819 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
84820 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
84821 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
84822 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
84823 +timeout_write_50991 timeout_write 3 50991 NULL
84824 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
84825 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
84826 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
84827 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
84828 +proc_write_51003 proc_write 3 51003 NULL
84829 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
84830 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
84831 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
84832 +set_arg_42824 set_arg 3 42824 NULL
84833 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
84834 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
84835 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
84836 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
84837 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
84838 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
84839 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
84840 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
84841 +dt3155_read_59226 dt3155_read 3 59226 NULL
84842 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
84843 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
84844 +dump_midi_51040 dump_midi 3 51040 NULL
84845 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
84846 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
84847 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
84848 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
84849 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
84850 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
84851 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
84852 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
84853 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
84854 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
84855 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
84856 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
84857 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
84858 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
84859 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
84860 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
84861 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
84862 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
84863 +read_vmcore_26501 read_vmcore 3 26501 NULL
84864 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
84865 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
84866 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
84867 +alloc_skb_55439 alloc_skb 1 55439 NULL
84868 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
84869 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
84870 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
84871 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
84872 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
84873 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
84874 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
84875 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
84876 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
84877 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
84878 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
84879 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
84880 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
84881 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
84882 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
84883 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
84884 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
84885 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
84886 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
84887 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
84888 +fd_copyout_59323 fd_copyout 3 59323 NULL
84889 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
84890 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
84891 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
84892 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
84893 +solos_param_store_34755 solos_param_store 4 34755 NULL
84894 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
84895 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
84896 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
84897 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
84898 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
84899 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
84900 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
84901 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
84902 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
84903 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
84904 +set_registers_53582 set_registers 3 53582 NULL
84905 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
84906 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
84907 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
84908 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
84909 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
84910 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
84911 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
84912 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
84913 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
84914 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
84915 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
84916 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
84917 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
84918 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
84919 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
84920 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
84921 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
84922 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
84923 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
84924 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
84925 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
84926 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
84927 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
84928 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
84929 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
84930 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
84931 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
84932 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
84933 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
84934 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
84935 +tipc_send_51238 tipc_send 4 51238 NULL
84936 +drm_property_create_51239 drm_property_create 4 51239 NULL
84937 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
84938 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
84939 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
84940 +audit_expand_2098 audit_expand 2 2098 NULL
84941 +st_read_51251 st_read 3 51251 NULL
84942 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
84943 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
84944 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
84945 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
84946 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
84947 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
84948 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
84949 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
84950 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
84951 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
84952 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
84953 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
84954 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
84955 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
84956 +pkt_add_39897 pkt_add 3 39897 NULL
84957 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
84958 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
84959 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
84960 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
84961 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
84962 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
84963 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
84964 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
84965 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
84966 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
84967 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
84968 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
84969 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
84970 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
84971 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
84972 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
84973 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
84974 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
84975 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
84976 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
84977 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
84978 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
84979 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
84980 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
84981 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
84982 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
84983 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
84984 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
84985 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
84986 +debug_output_18575 debug_output 3 18575 NULL
84987 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
84988 +Realloc_34961 Realloc 2 34961 NULL
84989 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
84990 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
84991 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
84992 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
84993 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
84994 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
84995 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
84996 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
84997 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
84998 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
84999 +vhci_write_2224 vhci_write 3 2224 NULL
85000 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
85001 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
85002 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
85003 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
85004 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
85005 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
85006 +write_pbl_59583 write_pbl 4 59583 NULL
85007 +from_buffer_18625 from_buffer 3 18625 NULL
85008 +uio_write_43202 uio_write 3 43202 NULL
85009 +memdup_user_59590 memdup_user 2 59590 NULL
85010 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
85011 +iso_callback_43208 iso_callback 3 43208 NULL
85012 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
85013 +smk_write_load_26829 smk_write_load 3 26829 NULL
85014 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
85015 +do_update_counters_2259 do_update_counters 4 2259 NULL
85016 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
85017 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
85018 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
85019 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
85020 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
85021 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
85022 +mtrr_write_59622 mtrr_write 3 59622 NULL
85023 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
85024 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
85025 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
85026 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
85027 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
85028 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
85029 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
85030 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
85031 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
85032 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
85033 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
85034 +fixup_leb_43256 fixup_leb 3 43256 NULL
85035 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
85036 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
85037 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
85038 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
85039 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
85040 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
85041 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
85042 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
85043 +evtchn_write_43278 evtchn_write 3 43278 NULL
85044 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
85045 +store_ifalias_35088 store_ifalias 4 35088 NULL
85046 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
85047 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
85048 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
85049 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
85050 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
85051 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
85052 +tower_write_8580 tower_write 3 8580 NULL
85053 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
85054 +capi_write_35104 capi_write 3 35104 NULL nohasharray
85055 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
85056 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
85057 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
85058 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
85059 +dev_read_56369 dev_read 3 56369 NULL
85060 +read_file_misc_9948 read_file_misc 3 9948 NULL
85061 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
85062 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
85063 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
85064 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
85065 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
85066 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
85067 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
85068 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
85069 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
85070 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
85071 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
85072 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
85073 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
85074 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
85075 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
85076 +do_trimming_26952 do_trimming 3 26952 NULL
85077 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
85078 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
85079 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
85080 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
85081 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
85082 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
85083 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
85084 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
85085 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
85086 +otp_read_10594 otp_read 2-4-5 10594 NULL
85087 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
85088 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
85089 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
85090 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
85091 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
85092 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
85093 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
85094 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
85095 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
85096 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
85097 +venus_remove_59781 venus_remove 4 59781 NULL
85098 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
85099 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
85100 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
85101 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
85102 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
85103 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
85104 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
85105 +xenfb_write_43412 xenfb_write 3 43412 NULL
85106 +cosa_write_1774 cosa_write 3 1774 NULL
85107 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
85108 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
85109 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
85110 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
85111 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 NULL nohasharray
85112 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 &gdm_wimax_netif_rx_43423
85113 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
85114 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
85115 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
85116 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
85117 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
85118 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
85119 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
85120 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
85121 +cmd_complete_51629 cmd_complete 6 51629 NULL
85122 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
85123 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
85124 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
85125 +set_fd_set_35249 set_fd_set 1 35249 NULL
85126 +wiphy_new_2482 wiphy_new 2 2482 NULL
85127 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
85128 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
85129 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
85130 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
85131 +tcp_push_10680 tcp_push 3 10680 NULL
85132 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
85133 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
85134 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
85135 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
85136 +tun_put_user_59849 tun_put_user 4 59849 NULL
85137 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
85138 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
85139 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
85140 +dm_write_2513 dm_write 3 2513 NULL
85141 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
85142 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
85143 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
85144 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
85145 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
85146 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
85147 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
85148 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
85149 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
85150 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
85151 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
85152 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
85153 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
85154 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
85155 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
85156 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
85157 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
85158 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
85159 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
85160 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
85161 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
85162 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
85163 +sel_write_access_51704 sel_write_access 3 51704 NULL
85164 +sys_syslog_10746 sys_syslog 3 10746 NULL
85165 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
85166 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
85167 +do_readlink_43518 do_readlink 2 43518 NULL
85168 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
85169 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
85170 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
85171 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
85172 +pms_capture_27142 pms_capture 4 27142 NULL
85173 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
85174 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
85175 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
85176 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
85177 +msg_set_51725 msg_set 3 51725 NULL
85178 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
85179 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
85180 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
85181 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
85182 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
85183 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
85184 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
85185 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
85186 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
85187 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
85188 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
85189 +sys_bind_10799 sys_bind 3 10799 NULL
85190 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
85191 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
85192 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
85193 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
85194 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
85195 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
85196 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
85197 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
85198 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
85199 +send_command_10832 send_command 4 10832 NULL
85200 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
85201 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
85202 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
85203 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
85204 +proc_read_43614 proc_read 3 43614 NULL
85205 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
85206 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
85207 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
85208 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
85209 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
85210 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
85211 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
85212 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
85213 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
85214 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
85215 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
85216 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
85217 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
85218 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
85219 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
85220 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
85221 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
85222 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
85223 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
85224 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
85225 +unifi_write_65012 unifi_write 3 65012 NULL
85226 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
85227 +get_scq_10897 get_scq 2 10897 NULL
85228 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
85229 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
85230 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
85231 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
85232 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
85233 +load_module_60056 load_module 2 60056 NULL nohasharray
85234 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
85235 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
85236 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
85237 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
85238 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
85239 +nfsd_read_19568 nfsd_read 5 19568 NULL
85240 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
85241 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
85242 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
85243 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
85244 +user_read_51881 user_read 3 51881 NULL
85245 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
85246 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
85247 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
85248 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
85249 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
85250 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
85251 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
85252 +async_setkey_35521 async_setkey 3 35521 NULL
85253 +send_msg_37323 send_msg 4 37323 NULL
85254 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
85255 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
85256 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
85257 +gnttab_map_56439 gnttab_map 2 56439 NULL
85258 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
85259 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
85260 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
85261 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
85262 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
85263 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
85264 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
85265 +kcalloc_27770 kcalloc 1-2 27770 NULL
85266 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
85267 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
85268 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
85269 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
85270 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
85271 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
85272 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
85273 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
85274 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
85275 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
85276 +handle_request_10024 handle_request 9 10024 NULL
85277 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
85278 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
85279 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
85280 +init_state_60165 init_state 2 60165 NULL
85281 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
85282 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
85283 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
85284 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
85285 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
85286 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
85287 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
85288 +read_dma_55086 read_dma 3 55086 NULL
85289 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
85290 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
85291 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
85292 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
85293 +kernel_readv_35617 kernel_readv 3 35617 NULL
85294 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
85295 +reshape_ring_29147 reshape_ring 2 29147 NULL
85296 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
85297 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
85298 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
85299 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
85300 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
85301 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
85302 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
85303 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
85304 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
85305 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
85306 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
85307 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
85308 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
85309 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
85310 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
85311 +store_debug_level_35652 store_debug_level 3 35652 NULL
85312 +read_flush_43851 read_flush 3 43851 NULL
85313 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
85314 +cmm_write_2896 cmm_write 3 2896 NULL
85315 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
85316 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
85317 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
85318 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
85319 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
85320 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
85321 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
85322 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
85323 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
85324 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
85325 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
85326 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
85327 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
85328 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
85329 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
85330 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
85331 +printer_write_60276 printer_write 3 60276 NULL
85332 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
85333 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
85334 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
85335 +debug_read_19322 debug_read 3 19322 NULL
85336 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
85337 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
85338 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
85339 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
85340 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
85341 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
85342 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
85343 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
85344 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
85345 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
85346 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
85347 +SendString_43928 SendString 3 43928 NULL
85348 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
85349 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
85350 +retry_count_read_52129 retry_count_read 3 52129 NULL
85351 +trace_options_read_11419 trace_options_read 3 11419 NULL
85352 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
85353 +read_zero_19366 read_zero 3 19366 NULL
85354 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
85355 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
85356 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
85357 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
85358 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
85359 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
85360 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
85361 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
85362 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
85363 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
85364 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
85365 +depth_write_3021 depth_write 3 3021 NULL
85366 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
85367 +read_file_stations_35795 read_file_stations 3 35795 NULL
85368 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
85369 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
85370 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
85371 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
85372 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
85373 +copy_from_user_17559 copy_from_user 3 17559 NULL
85374 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
85375 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
85376 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
85377 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
85378 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
85379 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
85380 +driver_names_read_60399 driver_names_read 3 60399 NULL
85381 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
85382 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
85383 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
85384 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
85385 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
85386 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
85387 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
85388 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
85389 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
85390 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
85391 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
85392 +rx_data_60442 rx_data 4 60442 NULL
85393 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
85394 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
85395 +rb_alloc_3102 rb_alloc 1 3102 NULL
85396 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
85397 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
85398 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
85399 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
85400 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
85401 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
85402 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
85403 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
85404 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
85405 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
85406 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
85407 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
85408 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
85409 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
85410 +construct_key_11329 construct_key 3 11329 NULL
85411 +evm_write_key_27715 evm_write_key 3 27715 NULL
85412 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
85413 +xsd_read_15653 xsd_read 3 15653 NULL
85414 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
85415 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
85416 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
85417 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
85418 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
85419 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
85420 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
85421 +read_file_reset_52310 read_file_reset 3 52310 NULL
85422 +sel_write_create_11353 sel_write_create 3 11353 NULL
85423 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
85424 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
85425 +hwflags_read_52318 hwflags_read 3 52318 NULL
85426 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
85427 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
85428 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
85429 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
85430 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
85431 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
85432 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
85433 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
85434 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
85435 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
85436 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
85437 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
85438 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
85439 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
85440 +alloc_context_3194 alloc_context 1 3194 NULL
85441 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
85442 +bm_status_read_19583 bm_status_read 3 19583 NULL
85443 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
85444 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
85445 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
85446 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
85447 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
85448 +str_to_user_11411 str_to_user 2 11411 NULL
85449 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
85450 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
85451 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
85452 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
85453 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
85454 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
85455 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
85456 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
85457 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
85458 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
85459 +console_store_36007 console_store 4 36007 NULL
85460 +bttv_read_11432 bttv_read 3 11432 NULL
85461 +key_key_read_3241 key_key_read 3 3241 NULL
85462 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
85463 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
85464 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
85465 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
85466 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
85467 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
85468 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
85469 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
85470 +um_idi_write_18293 um_idi_write 3 18293 NULL
85471 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
85472 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
85473 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
85474 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
85475 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
85476 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
85477 +sys_init_module_36047 sys_init_module 2 36047 NULL
85478 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
85479 +read_profile_27859 read_profile 3 27859 NULL
85480 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
85481 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
85482 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
85483 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
85484 +refill_pool_19477 refill_pool 2 19477 NULL
85485 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
85486 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
85487 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
85488 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
85489 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
85490 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
85491 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
85492 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
85493 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
85494 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
85495 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
85496 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
85497 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
85498 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
85499 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
85500 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
85501 +alloc_async_14208 alloc_async 1 14208 NULL
85502 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
85503 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
85504 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
85505 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
85506 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
85507 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
85508 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
85509 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
85510 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
85511 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
85512 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
85513 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
85514 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
85515 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
85516 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
85517 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
85518 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
85519 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
85520 +init_data_container_60709 init_data_container 1 60709 NULL
85521 +p9_client_read_19750 p9_client_read 5 19750 NULL
85522 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
85523 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
85524 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
85525 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
85526 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
85527 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
85528 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
85529 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
85530 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
85531 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
85532 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
85533 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
85534 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
85535 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
85536 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
85537 +send_stream_3397 send_stream 4 3397 NULL
85538 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
85539 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
85540 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
85541 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
85542 +msix_map_region_3411 msix_map_region 3 3411 NULL
85543 +idmouse_read_63374 idmouse_read 3 63374 NULL
85544 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
85545 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
85546 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
85547 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
85548 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
85549 +opticon_write_60775 opticon_write 4 60775 NULL
85550 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
85551 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
85552 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
85553 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
85554 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
85555 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
85556 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
85557 +vip_read_19832 vip_read 3 19832 NULL
85558 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
85559 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
85560 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
85561 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
85562 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
85563 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
85564 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
85565 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
85566 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
85567 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
85568 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
85569 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
85570 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
85571 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
85572 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
85573 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
85574 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
85575 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
85576 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
85577 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
85578 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
85579 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
85580 +split_11691 split 2 11691 NULL
85581 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
85582 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
85583 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
85584 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
85585 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
85586 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
85587 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
85588 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
85589 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
85590 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
85591 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
85592 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
85593 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
85594 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
85595 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
85596 +dsp_write_46218 dsp_write 2 46218 NULL
85597 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
85598 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
85599 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
85600 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
85601 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
85602 +spidev_write_44510 spidev_write 3 44510 NULL
85603 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
85604 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
85605 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
85606 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
85607 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
85608 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
85609 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
85610 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
85611 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
85612 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
85613 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
85614 +evtchn_read_3569 evtchn_read 3 3569 NULL
85615 +video_read_28148 video_read 3 28148 NULL
85616 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
85617 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
85618 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
85619 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
85620 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
85621 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
85622 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
85623 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
85624 +vc_resize_3585 vc_resize 2-3 3585 NULL
85625 +sys_select_38827 sys_select 1 38827 NULL
85626 +gluebi_write_27905 gluebi_write 3 27905 NULL
85627 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
85628 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
85629 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
85630 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
85631 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
85632 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
85633 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
85634 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
85635 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
85636 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
85637 +pti_char_write_60960 pti_char_write 3 60960 NULL
85638 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
85639 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
85640 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
85641 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
85642 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
85643 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
85644 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
85645 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
85646 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
85647 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
85648 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
85649 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
85650 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
85651 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
85652 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
85653 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
85654 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
85655 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
85656 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
85657 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
85658 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
85659 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
85660 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
85661 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
85662 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
85663 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
85664 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
85665 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
85666 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
85667 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
85668 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
85669 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
85670 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
85671 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
85672 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
85673 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
85674 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
85675 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
85676 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
85677 +symtab_init_61050 symtab_init 2 61050 NULL
85678 +team_options_register_20091 team_options_register 3 20091 NULL
85679 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
85680 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
85681 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
85682 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
85683 +mpi_resize_44674 mpi_resize 2 44674 NULL
85684 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
85685 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
85686 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
85687 +interfaces_38859 interfaces 2 38859 NULL
85688 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
85689 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
85690 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
85691 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
85692 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
85693 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
85694 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
85695 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
85696 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
85697 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
85698 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
85699 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
85700 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
85701 +get_derived_key_61100 get_derived_key 4 61100 NULL
85702 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
85703 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
85704 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
85705 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
85706 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
85707 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
85708 +fs_path_add_15648 fs_path_add 3 15648 NULL
85709 +kone_send_63435 kone_send 4 63435 NULL
85710 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
85711 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
85712 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
85713 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
85714 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
85715 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
85716 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
85717 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
85718 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
85719 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
85720 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
85721 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
85722 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
85723 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
85724 +send_packet_52960 send_packet 4 52960 NULL
85725 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
85726 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
85727 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
85728 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
85729 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
85730 +put_cmsg_36589 put_cmsg 4 36589 NULL
85731 +__vmalloc_61168 __vmalloc 1 61168 NULL
85732 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
85733 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
85734 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
85735 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
85736 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
85737 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
85738 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
85739 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
85740 +p54_init_common_23850 p54_init_common 1 23850 NULL
85741 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
85742 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
85743 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
85744 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
85745 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
85746 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
85747 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
85748 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
85749 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
85750 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
85751 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
85752 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
85753 +garp_request_join_7471 garp_request_join 4 7471 NULL
85754 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
85755 +unlink_queued_645 unlink_queued 3-4 645 NULL
85756 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
85757 +sisusb_write_44834 sisusb_write 3 44834 NULL
85758 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
85759 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
85760 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
85761 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
85762 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
85763 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
85764 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
85765 +nvram_write_3894 nvram_write 3 3894 NULL
85766 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
85767 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
85768 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
85769 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
85770 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
85771 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
85772 +vcs_write_3910 vcs_write 3 3910 NULL
85773 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
85774 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
85775 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
85776 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
85777 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
85778 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
85779 +do_tty_write_44896 do_tty_write 5 44896 NULL
85780 +set_powered_12129 set_powered 4 12129 NULL
85781 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
85782 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
85783 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
85784 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
85785 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
85786 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
85787 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
85788 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
85789 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
85790 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
85791 +udf_readpages_38761 udf_readpages 4 38761 NULL
85792 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
85793 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
85794 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
85795 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
85796 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
85797 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
85798 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
85799 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
85800 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
85801 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
85802 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
85803 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
85804 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
85805 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
85806 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
85807 +do_add_counters_3992 do_add_counters 3 3992 NULL
85808 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
85809 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
85810 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
85811 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
85812 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
85813 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
85814 +mei_write_4005 mei_write 3 4005 NULL
85815 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
85816 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
85817 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
85818 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
85819 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
85820 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
85821 +receive_copy_12216 receive_copy 3 12216 NULL
85822 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
85823 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
85824 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
85825 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
85826 +change_xattr_61390 change_xattr 5 61390 NULL
85827 +find_skb_20431 find_skb 2 20431 NULL
85828 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
85829 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
85830 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
85831 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
85832 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
85833 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
85834 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
85835 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
85836 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
85837 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
85838 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
85839 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
85840 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
85841 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
85842 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
85843 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
85844 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
85845 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
85846 +cm_write_36858 cm_write 3 36858 NULL
85847 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
85848 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
85849 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
85850 +sel_write_user_45060 sel_write_user 3 45060 NULL
85851 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
85852 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
85853 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
85854 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
85855 +fast_user_write_20494 fast_user_write 5 20494 NULL
85856 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
85857 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
85858 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
85859 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
85860 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
85861 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
85862 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
85863 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
85864 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
85865 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
85866 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
85867 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
85868 +tm6000_read_4151 tm6000_read 3 4151 NULL
85869 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
85870 +usbdev_read_45114 usbdev_read 3 45114 NULL
85871 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
85872 +spi_execute_28736 spi_execute 5 28736 NULL
85873 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
85874 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
85875 +get_alua_req_4166 get_alua_req 3 4166 NULL
85876 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
85877 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
85878 +venus_create_20555 venus_create 4 20555 NULL
85879 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
85880 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
85881 +receive_packet_12367 receive_packet 2 12367 NULL
85882 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
85883 +mem_write_22232 mem_write 3 22232 NULL
85884 +read_file_bool_4180 read_file_bool 3 4180 NULL
85885 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
85886 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
85887 +write_leb_36957 write_leb 5 36957 NULL
85888 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
85889 +device_write_45156 device_write 3 45156 NULL
85890 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
85891 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
85892 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
85893 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
85894 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
85895 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
85896 +isp1760_register_628 isp1760_register 1-2 628 NULL
85897 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
85898 +lirc_write_20604 lirc_write 3 20604 NULL
85899 +sel_write_member_28800 sel_write_member 3 28800 NULL
85900 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
85901 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
85902 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
85903 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
85904 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
85905 +setxattr_37006 setxattr 4 37006 NULL
85906 +add_child_45201 add_child 4 45201 NULL
85907 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
85908 +seq_open_private_61589 seq_open_private 3 61589 NULL
85909 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
85910 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
85911 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
85912 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
85913 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
85914 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
85915 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
85916 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
85917 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
85918 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
85919 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
85920 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
85921 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
85922 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
85923 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
85924 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
85925 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
85926 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
85927 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
85928 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
85929 +resize_stripes_61650 resize_stripes 2 61650 NULL
85930 +n2_run_53459 n2_run 3 53459 NULL
85931 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
85932 +parse_command_37079 parse_command 2 37079 NULL
85933 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
85934 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
85935 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
85936 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
85937 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
85938 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
85939 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
85940 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
85941 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
85942 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
85943 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
85944 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
85945 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
85946 +lock_loop_61681 lock_loop 1 61681 NULL
85947 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
85948 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
85949 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
85950 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
85951 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
85952 +push_rx_28939 push_rx 3 28939 NULL
85953 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
85954 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
85955 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
85956 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
85957 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
85958 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
85959 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
85960 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
85961 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
85962 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
85963 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
85964 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
85965 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
85966 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
85967 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
85968 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
85969 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
85970 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
85971 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
85972 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
85973 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
85974 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
85975 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
85976 +bin_uuid_28999 bin_uuid 3 28999 NULL
85977 +sys_sendto_20809 sys_sendto 6 20809 NULL
85978 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
85979 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
85980 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
85981 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
85982 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
85983 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
85984 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
85985 +keymap_store_45406 keymap_store 4 45406 NULL
85986 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
85987 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
85988 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
85989 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
85990 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
85991 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
85992 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
85993 +__do_replace_37227 __do_replace 5 37227 NULL
85994 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
85995 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
85996 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
85997 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
85998 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
85999 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
86000 +tso_fragment_29050 tso_fragment 3 29050 NULL
86001 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
86002 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
86003 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
86004 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
86005 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
86006 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
86007 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
86008 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
86009 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
86010 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
86011 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
86012 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
86013 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
86014 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
86015 +set_link_security_4502 set_link_security 4 4502 NULL
86016 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
86017 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
86018 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
86019 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
86020 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
86021 +c101_run_37279 c101_run 2 37279 NULL
86022 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
86023 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
86024 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
86025 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
86026 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
86027 +ivtv_write_12721 ivtv_write 3 12721 NULL
86028 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
86029 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
86030 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
86031 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
86032 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
86033 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
86034 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
86035 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
86036 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
86037 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
86038 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
86039 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
86040 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
86041 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
86042 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
86043 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
86044 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
86045 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
86046 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
86047 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
86048 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
86049 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
86050 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
86051 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
86052 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
86053 +copy_macs_45534 copy_macs 4 45534 NULL
86054 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
86055 +listxattr_12769 listxattr 3 12769 NULL
86056 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
86057 +wdm_write_53735 wdm_write 3 53735 NULL
86058 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
86059 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
86060 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
86061 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
86062 +bch_alloc_4593 bch_alloc 1 4593 NULL
86063 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
86064 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
86065 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
86066 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
86067 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
86068 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
86069 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
86070 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
86071 +mgmt_event_12810 mgmt_event 4 12810 NULL
86072 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
86073 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
86074 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
86075 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
86076 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
86077 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
86078 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
86079 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
86080 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
86081 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
86082 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86083 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
86084 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
86085 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
86086 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
86087 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
86088 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
86089 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
86090 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
86091 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
86092 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
86093 +recover_peb_29238 recover_peb 6-7 29238 NULL
86094 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
86095 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
86096 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
86097 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
86098 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
86099 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
86100 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
86101 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86102 +kone_receive_4690 kone_receive 4 4690 NULL
86103 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
86104 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
86105 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
86106 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
86107 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
86108 +savemem_58129 savemem 3 58129 NULL
86109 +do_pselect_62061 do_pselect 1 62061 NULL
86110 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
86111 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
86112 +pms_read_53873 pms_read 3 53873 NULL
86113 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
86114 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
86115 +groups_alloc_7614 groups_alloc 1 7614 NULL
86116 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
86117 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
86118 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
86119 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
86120 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
86121 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
86122 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
86123 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
86124 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
86125 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
86126 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
86127 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
86128 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
86129 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
86130 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
86131 +new_skb_21148 new_skb 1 21148 NULL
86132 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
86133 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
86134 +bm_status_write_12964 bm_status_write 3 12964 NULL
86135 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
86136 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
86137 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
86138 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
86139 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
86140 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
86141 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
86142 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
86143 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
86144 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
86145 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
86146 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
86147 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
86148 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
86149 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
86150 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
86151 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
86152 +video_usercopy_62151 video_usercopy 2 62151 NULL
86153 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
86154 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
86155 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
86156 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
86157 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
86158 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
86159 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
86160 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
86161 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
86162 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
86163 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
86164 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
86165 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
86166 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
86167 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
86168 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
86169 +input_ff_create_21240 input_ff_create 2 21240 NULL
86170 +mempool_create_29437 mempool_create 1 29437 NULL
86171 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
86172 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
86173 +amthi_read_45831 amthi_read 4 45831 NULL
86174 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
86175 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
86176 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
86177 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
86178 +sys_ipc_4889 sys_ipc 3 4889 NULL
86179 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
86180 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86181 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86182 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
86183 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
86184 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
86185 +do_register_entry_29478 do_register_entry 4 29478 NULL
86186 +isdn_write_45863 isdn_write 3 45863 NULL
86187 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
86188 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
86189 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
86190 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
86191 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
86192 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
86193 +_malloc_54077 _malloc 1 54077 NULL
86194 +add_res_range_21310 add_res_range 4 21310 NULL
86195 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
86196 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
86197 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
86198 +vb2_write_31948 vb2_write 3 31948 NULL
86199 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
86200 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
86201 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
86202 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
86203 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
86204 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
86205 +create_xattr_54106 create_xattr 5 54106 NULL
86206 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
86207 +ep_write_59008 ep_write 3 59008 NULL
86208 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
86209 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
86210 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
86211 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
86212 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
86213 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
86214 +alloc_mr_45935 alloc_mr 1 45935 NULL
86215 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
86216 +isku_receive_54130 isku_receive 4 54130 NULL
86217 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
86218 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
86219 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
86220 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
86221 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
86222 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
86223 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
86224 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
86225 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
86226 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
86227 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
86228 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
86229 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
86230 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
86231 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
86232 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
86233 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
86234 +comedi_read_13199 comedi_read 3 13199 NULL
86235 +flash_write_62354 flash_write 3 62354 NULL
86236 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
86237 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
86238 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
86239 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
86240 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
86241 +proc_file_read_53905 proc_file_read 3 53905 NULL
86242 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
86243 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
86244 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
86245 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
86246 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
86247 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
86248 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
86249 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
86250 +cru_detect_11272 cru_detect 1 11272 NULL
86251 +altera_irscan_62396 altera_irscan 2 62396 NULL
86252 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
86253 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
86254 +fw_download_code_13249 fw_download_code 3 13249 NULL
86255 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
86256 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
86257 +set_ssp_62411 set_ssp 4 62411 NULL
86258 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
86259 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
86260 +get_free_entries_46030 get_free_entries 1 46030 NULL
86261 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
86262 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
86263 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
86264 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
86265 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
86266 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
86267 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
86268 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
86269 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
86270 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
86271 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
86272 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
86273 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
86274 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
86275 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
86276 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
86277 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
86278 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
86279 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
86280 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
86281 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
86282 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
86283 +tunables_write_59563 tunables_write 3 59563 NULL
86284 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
86285 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
86286 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
86287 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
86288 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
86289 +probes_write_29711 probes_write 3 29711 NULL
86290 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
86291 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
86292 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
86293 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86294 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
86295 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
86296 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
86297 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
86298 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
86299 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
86300 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
86301 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
86302 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
86303 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
86304 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
86305 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
86306 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
86307 +event_filter_write_56609 event_filter_write 3 56609 NULL
86308 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
86309 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
86310 +insert_dent_65034 insert_dent 7 65034 NULL
86311 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
86312 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
86313 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
86314 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
86315 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
86316 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
86317 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
86318 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
86319 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
86320 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
86321 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
86322 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
86323 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
86324 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
86325 +isdn_read_50021 isdn_read 3 50021 NULL
86326 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
86327 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
86328 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
86329 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
86330 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
86331 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
86332 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
86333 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
86334 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
86335 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
86336 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
86337 +get_subdir_62581 get_subdir 3 62581 NULL
86338 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
86339 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
86340 +vfs_readv_38011 vfs_readv 3 38011 NULL
86341 +keyring_read_13438 keyring_read 3 13438 NULL
86342 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
86343 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
86344 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
86345 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
86346 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
86347 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
86348 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
86349 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
86350 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
86351 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
86352 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
86353 +ftrace_write_29551 ftrace_write 3 29551 NULL
86354 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
86355 +port_show_regs_5904 port_show_regs 3 5904 NULL
86356 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
86357 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
86358 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
86359 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
86360 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
86361 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
86362 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
86363 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
86364 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
86365 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
86366 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
86367 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
86368 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
86369 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
86370 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
86371 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
86372 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
86373 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
86374 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
86375 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
86376 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
86377 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
86378 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
86379 +bm_init_13529 bm_init 2 13529 NULL
86380 +check586_29914 check586 2 29914 NULL
86381 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
86382 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
86383 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
86384 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
86385 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
86386 +pg_read_17276 pg_read 3 17276 NULL
86387 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
86388 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
86389 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
86390 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
86391 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
86392 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
86393 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
86394 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
86395 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
86396 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
86397 +l2down_create_21755 l2down_create 4 21755 NULL
86398 +alloc_tio_13564 alloc_tio 3 13564 NULL
86399 +viacam_read_54526 viacam_read 3 54526 NULL
86400 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
86401 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
86402 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
86403 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
86404 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
86405 +setsockopt_54539 setsockopt 5 54539 NULL
86406 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
86407 +bio_alloc_32095 bio_alloc 2 32095 NULL
86408 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
86409 +tty_register_device_4544 tty_register_device 2 4544 NULL
86410 +cache_write_13589 cache_write 3 13589 NULL
86411 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
86412 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
86413 +key_replays_read_62746 key_replays_read 3 62746 NULL
86414 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
86415 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
86416 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
86417 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
86418 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
86419 +cdev_add_38176 cdev_add 2-3 38176 NULL
86420 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
86421 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
86422 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
86423 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
86424 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
86425 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
86426 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
86427 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
86428 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
86429 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
86430 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
86431 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
86432 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
86433 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
86434 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
86435 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
86436 +packet_snd_13634 packet_snd 3 13634 NULL
86437 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
86438 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
86439 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
86440 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
86441 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
86442 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
86443 +drp_wmove_30043 drp_wmove 4 30043 NULL
86444 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
86445 +cache_downcall_13666 cache_downcall 3 13666 NULL
86446 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
86447 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86448 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
86449 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
86450 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
86451 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
86452 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
86453 +tty_write_5494 tty_write 3 5494 NULL
86454 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
86455 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
86456 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
86457 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
86458 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
86459 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
86460 +filldir64_46469 filldir64 3 46469 NULL
86461 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
86462 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
86463 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
86464 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
86465 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
86466 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
86467 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
86468 +spidev_message_5518 spidev_message 3 5518 NULL
86469 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
86470 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
86471 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86472 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86473 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
86474 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
86475 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
86476 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86477 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
86478 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
86479 +u32_array_read_2219 u32_array_read 3 2219 NULL
86480 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
86481 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
86482 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
86483 +kmsg_read_46514 kmsg_read 3 46514 NULL
86484 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86485 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
86486 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
86487 +recv_stream_30138 recv_stream 4 30138 NULL
86488 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86489 +getdqbuf_62908 getdqbuf 1 62908 NULL
86490 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
86491 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
86492 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
86493 +fir16_create_5574 fir16_create 3 5574 NULL
86494 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
86495 +pt_write_40159 pt_write 3 40159 NULL
86496 +bioset_create_5580 bioset_create 1 5580 NULL
86497 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
86498 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
86499 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
86500 +kzalloc_54740 kzalloc 1 54740 NULL
86501 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
86502 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
86503 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
86504 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
86505 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
86506 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
86507 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
86508 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
86509 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
86510 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
86511 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
86512 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
86513 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86514 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
86515 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
86516 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
86517 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86518 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
86519 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
86520 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
86521 +ti_recv_22027 ti_recv 4 22027 NULL
86522 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
86523 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
86524 +nfsd_write_54809 nfsd_write 6 54809 NULL
86525 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
86526 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
86527 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
86528 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
86529 +get_skb_63008 get_skb 2 63008 NULL
86530 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
86531 +netlink_send_38434 netlink_send 5 38434 NULL
86532 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
86533 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
86534 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
86535 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
86536 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
86537 +write_rio_54837 write_rio 3 54837 NULL
86538 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
86539 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
86540 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
86541 +get_arg_5694 get_arg 3 5694 NULL
86542 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86543 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
86544 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86545 +printer_read_54851 printer_read 3 54851 NULL
86546 +mem_rw_22085 mem_rw 3 22085 NULL
86547 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
86548 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
86549 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
86550 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
86551 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
86552 +unlink1_63059 unlink1 3 63059 NULL
86553 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
86554 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
86555 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
86556 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
86557 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
86558 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
86559 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
86560 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
86561 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
86562 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
86563 +dev_names_read_38509 dev_names_read 3 38509 NULL
86564 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
86565 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
86566 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
86567 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
86568 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
86569 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
86570 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
86571 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
86572 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
86573 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
86574 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
86575 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
86576 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
86577 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
86578 +resource_from_user_30341 resource_from_user 3 30341 NULL
86579 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
86580 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
86581 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
86582 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
86583 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
86584 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
86585 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
86586 +com90xx_found_13974 com90xx_found 3 13974 NULL
86587 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
86588 +qcam_read_13977 qcam_read 3 13977 NULL
86589 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
86590 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
86591 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
86592 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
86593 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
86594 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
86595 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
86596 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
86597 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
86598 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
86599 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
86600 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
86601 +l2up_create_6430 l2up_create 3 6430 NULL
86602 +c4_add_card_54968 c4_add_card 3 54968 NULL
86603 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
86604 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
86605 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
86606 +concat_writev_21451 concat_writev 3 21451 NULL
86607 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
86608 +_queue_data_54983 _queue_data 4 54983 NULL
86609 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
86610 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
86611 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
86612 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
86613 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
86614 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
86615 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
86616 +setup_req_5848 setup_req 3 5848 NULL
86617 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
86618 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
86619 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
86620 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
86621 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
86622 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
86623 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
86624 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
86625 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
86626 +cma_create_area_38642 cma_create_area 2 38642 NULL
86627 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
86628 +sriov_enable_59689 sriov_enable 2 59689 NULL
86629 +enable_write_30456 enable_write 3 30456 NULL
86630 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
86631 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
86632 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
86633 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
86634 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
86635 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
86636 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
86637 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
86638 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
86639 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
86640 +ptp_read_63251 ptp_read 4 63251 NULL
86641 +adu_write_30487 adu_write 3 30487 NULL
86642 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
86643 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
86644 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
86645 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
86646 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
86647 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
86648 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
86649 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
86650 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
86651 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
86652 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
86653 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
86654 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
86655 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
86656 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
86657 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
86658 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
86659 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
86660 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
86661 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
86662 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
86663 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
86664 +em_canid_change_14150 em_canid_change 3 14150 NULL
86665 +raid5_resize_63306 raid5_resize 2 63306 NULL
86666 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
86667 +fb_write_46924 fb_write 3 46924 NULL
86668 +ts_read_44687 ts_read 3 44687 NULL
86669 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
86670 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
86671 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
86672 +filldir_55137 filldir 3 55137 NULL
86673 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
86674 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
86675 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86676 +reada_add_block_54247 reada_add_block 2 54247 NULL
86677 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
86678 +proc_info_read_63344 proc_info_read 3 63344 NULL
86679 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
86680 +pep_indicate_38611 pep_indicate 5 38611 NULL
86681 +set_le_30581 set_le 4 30581 NULL
86682 +write_62671 write 3 62671 NULL
86683 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
86684 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
86685 +alloc_private_22399 alloc_private 2 22399 NULL
86686 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
86687 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
86688 +zoran_write_22404 zoran_write 3 22404 NULL
86689 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
86690 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
86691 +queue_reply_22416 queue_reply 3 22416 NULL
86692 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
86693 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
86694 +sound_write_5102 sound_write 3 5102 NULL
86695 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
86696 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
86697 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
86698 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
86699 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
86700 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
86701 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
86702 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
86703 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
86704 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
86705 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
86706 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
86707 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
86708 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
86709 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
86710 +direct_entry_38836 direct_entry 3 38836 NULL
86711 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
86712 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
86713 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
86714 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
86715 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
86716 +write_head_30481 write_head 4 30481 NULL
86717 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
86718 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
86719 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
86720 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
86721 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
86722 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
86723 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
86724 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
86725 +agp_remap_30665 agp_remap 2 30665 NULL
86726 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
86727 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
86728 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
86729 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
86730 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
86731 +qc_capture_19298 qc_capture 3 19298 NULL
86732 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
86733 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
86734 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
86735 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
86736 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
86737 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
86738 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
86739 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
86740 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
86741 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
86742 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
86743 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
86744 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
86745 +read_kcore_63488 read_kcore 3 63488 NULL
86746 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
86747 +sel_write_load_63830 sel_write_load 3 63830 NULL
86748 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
86749 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
86750 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
86751 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
86752 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
86753 +mousedev_read_47123 mousedev_read 3 47123 NULL
86754 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
86755 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
86756 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
86757 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
86758 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
86759 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
86760 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
86761 +vme_user_read_55338 vme_user_read 3 55338 NULL
86762 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
86763 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
86764 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
86765 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
86766 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
86767 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
86768 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
86769 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
86770 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
86771 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
86772 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
86773 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
86774 +snapshot_read_22601 snapshot_read 3 22601 NULL
86775 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
86776 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
86777 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
86778 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
86779 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
86780 +__send_to_port_55383 __send_to_port 3 55383 NULL
86781 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
86782 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
86783 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
86784 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
86785 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
86786 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
86787 +get_nodes_39012 get_nodes 3 39012 NULL
86788 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
86789 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
86790 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
86791 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
86792 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
86793 +create_subvol_30836 create_subvol 4 30836 NULL
86794 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
86795 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
86796 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
86797 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
86798 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
86799 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
86800 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
86801 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
86802 +options_write_47243 options_write 3 47243 NULL
86803 +module_alloc_63630 module_alloc 1 63630 NULL
86804 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
86805 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
86806 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
86807 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
86808 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
86809 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
86810 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
86811 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
86812 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
86813 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
86814 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
86815 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
86816 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
86817 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
86818 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
86819 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
86820 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
86821 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
86822 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
86823 +vbi_read_63673 vbi_read 3 63673 NULL
86824 +tun_get_user_39099 tun_get_user 4 39099 NULL
86825 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
86826 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
86827 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
86828 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
86829 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
86830 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
86831 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
86832 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 NULL nohasharray
86833 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
86834 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
86835 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
86836 +ax25_output_22736 ax25_output 2 22736 NULL
86837 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
86838 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
86839 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
86840 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
86841 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
86842 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
86843 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
86844 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
86845 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
86846 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
86847 +hid_input_report_32458 hid_input_report 4 32458 NULL
86848 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
86849 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
86850 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
86851 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
86852 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
86853 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
86854 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
86855 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
86856 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
86857 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
86858 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
86859 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
86860 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
86861 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
86862 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
86863 +setkey_14987 setkey 3 14987 NULL
86864 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
86865 +init_list_set_39188 init_list_set 2-3 39188 NULL
86866 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
86867 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
86868 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
86869 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
86870 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
86871 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
86872 +add_partition_55588 add_partition 2 55588 NULL
86873 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
86874 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
86875 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
86876 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
86877 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
86878 +profile_replace_14652 profile_replace 3 14652 NULL
86879 +vzalloc_47421 vzalloc 1 47421 NULL
86880 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
86881 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
86882 +sys_writev_28384 sys_writev 3 28384 NULL
86883 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
86884 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
86885 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
86886 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
86887 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
86888 +create_attr_set_22861 create_attr_set 1 22861 NULL
86889 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
86890 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
86891 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
86892 +__skb_cow_39254 __skb_cow 2 39254 NULL
86893 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
86894 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
86895 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
86896 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
86897 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
86898 +probe_bios_17467 probe_bios 1 17467 NULL
86899 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
86900 +read_oldmem_55658 read_oldmem 3 55658 NULL
86901 +mei_read_6507 mei_read 3 6507 NULL
86902 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
86903 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
86904 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
86905 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
86906 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
86907 +SetArea_50835 SetArea 4 50835 NULL
86908 +tpm_read_50344 tpm_read 3 50344 NULL
86909 +newpart_47485 newpart 6 47485 NULL
86910 +get_info_55681 get_info 3 55681 NULL
86911 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
86912 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
86913 +core_sys_select_47494 core_sys_select 1 47494 NULL
86914 +depth_read_31112 depth_read 3 31112 NULL
86915 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
86916 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
86917 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
86918 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
86919 +unlink_simple_47506 unlink_simple 3 47506 NULL
86920 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
86921 +wdm_read_6549 wdm_read 3 6549 NULL
86922 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
86923 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
86924 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
86925 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
86926 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
86927 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
86928 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
86929 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
86930 +filter_read_61692 filter_read 3 61692 NULL
86931 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
86932 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
86933 +debugfs_read_62535 debugfs_read 3 62535 NULL
86934 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
86935 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
86936 +divas_write_63901 divas_write 3 63901 NULL
86937 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
86938 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
86939 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
86940 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
86941 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
86942 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
86943 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
86944 +ipw_write_59807 ipw_write 3 59807 NULL
86945 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
86946 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
86947 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
86948 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
86949 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
86950 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
86951 +cycx_setup_47562 cycx_setup 4 47562 NULL
86952 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
86953 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
86954 +set_local_name_55757 set_local_name 4 55757 NULL
86955 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
86956 +read_ldt_47570 read_ldt 2 47570 NULL
86957 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
86958 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
86959 +pci_iomap_47575 pci_iomap 3 47575 NULL
86960 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
86961 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
86962 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
86963 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
86964 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
86965 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
86966 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
86967 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
86968 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
86969 +conf_read_55786 conf_read 3 55786 NULL
86970 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
86971 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
86972 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
86973 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
86974 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
86975 +user_power_read_39414 user_power_read 3 39414 NULL
86976 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
86977 +uea_request_47613 uea_request 4 47613 NULL
86978 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
86979 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
86980 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
86981 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
86982 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
86983 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
86984 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
86985 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
86986 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
86987 +kmemdup_64015 kmemdup 2 64015 NULL
86988 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
86989 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
86990 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
86991 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
86992 +oz_events_read_47535 oz_events_read 3 47535 NULL
86993 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
86994 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
86995 +sys_semop_39457 sys_semop 3 39457 NULL
86996 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
86997 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
86998 +update_pmkid_2481 update_pmkid 4 2481 NULL
86999 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
87000 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
87001 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
87002 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
87003 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
87004 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
87005 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
87006 +mpeg_read_6708 mpeg_read 3 6708 NULL
87007 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
87008 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
87009 +sky2_receive_13407 sky2_receive 2 13407 NULL
87010 +krealloc_14908 krealloc 2 14908 NULL
87011 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
87012 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
87013 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
87014 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
87015 +video_proc_write_6724 video_proc_write 3 6724 NULL
87016 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
87017 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
87018 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
87019 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
87020 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
87021 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
87022 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
87023 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
87024 +command_file_write_31318 command_file_write 3 31318 NULL
87025 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
87026 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
87027 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
87028 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
87029 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
87030 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
87031 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
87032 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
87033 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
87034 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87035 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
87036 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
87037 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
87038 +int_proc_write_39542 int_proc_write 3 39542 NULL
87039 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
87040 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
87041 +read_file_ani_23161 read_file_ani 3 23161 NULL
87042 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
87043 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
87044 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
87045 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
87046 +init_bch_64130 init_bch 1-2 64130 NULL
87047 +ioremap_23172 ioremap 1-2 23172 NULL
87048 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
87049 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
87050 +usblp_write_23178 usblp_write 3 23178 NULL
87051 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
87052 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
87053 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
87054 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
87055 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
87056 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
87057 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
87058 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
87059 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
87060 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
87061 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
87062 +get_fd_set_3866 get_fd_set 1 3866 NULL
87063 +__team_options_register_63941 __team_options_register 3 63941 NULL
87064 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
87065 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
87066 +rvmalloc_46873 rvmalloc 1 46873 NULL
87067 +vmap_15025 vmap 2 15025 NULL
87068 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
87069 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
87070 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
87071 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87072 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
87073 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
87074 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
87075 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
87076 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
87077 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
87078 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
87079 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
87080 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
87081 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
87082 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
87083 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
87084 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
87085 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
87086 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 NULL nohasharray
87087 +set_dev_class_39645 set_dev_class 4 39645 &dm_exception_table_init_39645
87088 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
87089 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
87090 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87091 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
87092 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
87093 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
87094 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
87095 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
87096 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
87097 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
87098 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
87099 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
87100 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
87101 +doc_probe_23285 doc_probe 1 23285 NULL
87102 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
87103 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
87104 +alg_setkey_31485 alg_setkey 3 31485 NULL
87105 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
87106 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
87107 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
87108 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
87109 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
87110 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
87111 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
87112 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
87113 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
87114 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
87115 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
87116 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
87117 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
87118 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
87119 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
87120 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
87121 +timeout_read_47915 timeout_read 3 47915 NULL
87122 +hidraw_write_31536 hidraw_write 3 31536 NULL
87123 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
87124 +page_readlink_23346 page_readlink 3 23346 NULL
87125 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
87126 +comedi_write_47926 comedi_write 3 47926 NULL
87127 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
87128 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
87129 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
87130 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
87131 +usbvision_read_31555 usbvision_read 3 31555 NULL
87132 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
87133 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
87134 +request_key_async_6990 request_key_async 4 6990 NULL
87135 +map_addr_56144 map_addr 7 56144 NULL
87136 +handle_response_55951 handle_response 5 55951 NULL
87137 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
87138 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87139 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
87140 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
87141 +osst_write_31581 osst_write 3 31581 NULL
87142 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
87143 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
87144 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
87145 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
87146 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
87147 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
87148 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
87149 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
87150 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
87151 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
87152 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
87153 +ilo_write_64378 ilo_write 3 64378 NULL
87154 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
87155 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
87156 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
87157 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
87158 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
87159 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
87160 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
87161 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
87162 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
87163 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
87164 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
87165 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
87166 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
87167 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
87168 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
87169 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
87170 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
87171 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
87172 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
87173 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
87174 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
87175 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
87176 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
87177 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
87178 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
87179 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
87180 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
87181 +__lgread_31668 __lgread 4 31668 NULL
87182 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
87183 +fd_copyin_56247 fd_copyin 3 56247 NULL
87184 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
87185 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
87186 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
87187 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
87188 +teiup_create_43201 teiup_create 3 43201 NULL
87189 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
87190 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
87191 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
87192 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
87193 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
87194 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
87195 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
87196 +event_filter_read_23494 event_filter_read 3 23494 NULL
87197 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
87198 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
87199 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
87200 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
87201 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
87202 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87203 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87204 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
87205 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
87206 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
87207 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
87208 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
87209 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
87210 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
87211 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
87212 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
87213 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
87214 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87215 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87216 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87217 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87218 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
87219 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
87220 +remove_uuid_64505 remove_uuid 4 64505 NULL
87221 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
87222 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
87223 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
87224 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
87225 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
87226 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
87227 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
87228 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
87229 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
87230 +set_discoverable_48141 set_discoverable 4 48141 NULL
87231 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
87232 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
87233 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
87234 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
87235 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87236 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
87237 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
87238 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
87239 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
87240 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
87241 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
87242 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
87243 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
87244 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
87245 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
87246 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
87247 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
87248 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
87249 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
87250 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
87251 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
87252 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
87253 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
87254 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
87255 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
87256 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
87257 +init_ipath_48187 init_ipath 1 48187 NULL
87258 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
87259 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
87260 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
87261 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
87262 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
87263 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
87264 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
87265 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
87266 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
87267 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
87268 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
87269 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
87270 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
87271 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
87272 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
87273 +use_pool_64607 use_pool 2 64607 NULL
87274 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
87275 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
87276 +store_msg_56417 store_msg 3 56417 NULL
87277 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87278 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
87279 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
87280 +vmalloc_15464 vmalloc 1 15464 NULL
87281 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
87282 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
87283 +fanotify_write_64623 fanotify_write 3 64623 NULL
87284 +sys_add_key_61288 sys_add_key 4 61288 NULL
87285 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
87286 +fl_create_56435 fl_create 5 56435 NULL
87287 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87288 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87289 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
87290 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
87291 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
87292 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
87293 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
87294 +set_connectable_56458 set_connectable 4 56458 NULL
87295 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
87296 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
87297 +add_port_54941 add_port 2 54941 NULL
87298 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
87299 +cx18_read_23699 cx18_read 3 23699 NULL
87300 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
87301 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
87302 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
87303 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
87304 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
87305 +send_set_info_48288 send_set_info 7 48288 NULL
87306 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
87307 +sg_read_25799 sg_read 3 25799 NULL
87308 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
87309 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
87310 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
87311 +new_dir_31919 new_dir 3 31919 NULL
87312 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
87313 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
87314 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
87315 +mgmt_control_7349 mgmt_control 3 7349 NULL
87316 +hash_setkey_48310 hash_setkey 3 48310 NULL
87317 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
87318 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
87319 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
87320 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
87321 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
87322 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
87323 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
87324 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
87325 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
87326 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87327 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
87328 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
87329 +smk_user_access_24440 smk_user_access 3 24440 NULL
87330 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
87331 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87332 +ip_options_get_56538 ip_options_get 4 56538 NULL
87333 +ep0_read_38095 ep0_read 3 38095 NULL
87334 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
87335 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
87336 +vme_user_write_15587 vme_user_write 3 15587 NULL
87337 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
87338 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
87339 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
87340 +skb_add_data_48363 skb_add_data 3 48363 NULL
87341 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
87342 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87343 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
87344 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87345 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
87346 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
87347 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
87348 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
87349 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
87350 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
87351 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
87352 +calc_hmac_32010 calc_hmac 3 32010 NULL
87353 +system_enable_read_25815 system_enable_read 3 25815 NULL
87354 +allocate_probes_40204 allocate_probes 1 40204 NULL
87355 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
87356 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
87357 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
87358 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
87359 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
87360 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
87361 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
87362 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
87363 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
87364 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
87365 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
87366 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
87367 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
87368 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
87369 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
87370 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
87371 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
87372 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87373 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
87374 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
87375 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
87376 +osst_read_40237 osst_read 3 40237 NULL
87377 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
87378 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
87379 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
87380 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
87381 +unifi_read_14899 unifi_read 3 14899 NULL
87382 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
87383 +dm_read_15674 dm_read 3 15674 NULL
87384 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
87385 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
87386 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
87387 +gather_array_56641 gather_array 3 56641 NULL
87388 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
87389 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
87390 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
87391 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
87392 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
87393 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
87394 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
87395 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
87396 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
87397 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
87398 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
87399 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
87400 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
87401 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
87402 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
87403 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
87404 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
87405 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
87406 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
87407 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
87408 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
87409 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
87410 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
87411 +send_control_msg_48498 send_control_msg 6 48498 NULL
87412 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
87413 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
87414 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
87415 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
87416 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
87417 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
87418 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
87419 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
87420 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
87421 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
87422 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
87423 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
87424 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
87425 +alloc_tx_32143 alloc_tx 2 32143 NULL
87426 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
87427 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
87428 +hsc_write_55875 hsc_write 3 55875 NULL
87429 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
87430 +do_test_15766 do_test 1 15766 NULL
87431 +mmio_read_40348 mmio_read 4 40348 NULL
87432 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
87433 +named_distribute_48544 named_distribute 4 48544 NULL
87434 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
87435 +venus_link_32165 venus_link 5 32165 NULL
87436 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
87437 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
87438 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
87439 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
87440 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
87441 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
87442 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
87443 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
87444 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
87445 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
87446 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
87447 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
87448 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
87449 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
87450 +tunables_read_36385 tunables_read 3 36385 NULL
87451 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
87452 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
87453 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
87454 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
87455 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
87456 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
87457 +snapshot_write_28351 snapshot_write 3 28351 NULL
87458 +event_enable_read_7074 event_enable_read 3 7074 NULL
87459 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
87460 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
87461 +do_syslog_56807 do_syslog 3 56807 NULL
87462 +pskb_pull_65005 pskb_pull 2 65005 NULL
87463 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
87464 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
87465 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
87466 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
87467 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
87468 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
87469 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
87470 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
87471 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
87472 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
87473 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
87474 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
87475 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
87476 +if_write_51756 if_write 3 51756 NULL
87477 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
87478 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
87479 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
87480 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
87481 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
87482 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
87483 +lc_create_48662 lc_create 3 48662 NULL
87484 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
87485 +dev_write_7708 dev_write 3 7708 NULL
87486 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
87487 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87488 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
87489 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
87490 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
87491 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
87492 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
87493 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
87494 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
87495 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
87496 +altera_drscan_48698 altera_drscan 2 48698 NULL
87497 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
87498 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
87499 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
87500 +power_read_15939 power_read 3 15939 NULL
87501 +recv_msg_48709 recv_msg 4 48709 NULL
87502 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
87503 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
87504 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
87505 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
87506 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
87507 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87508 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
87509 +revalidate_19043 revalidate 2 19043 NULL
87510 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
87511 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
87512 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
87513 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
87514 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
87515 +check_header_56930 check_header 2 56930 NULL
87516 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
87517 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
87518 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
87519 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
87520 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
87521 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
87522 +frame_alloc_15981 frame_alloc 4 15981 NULL
87523 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
87524 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
87525 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
87526 +adu_read_24177 adu_read 3 24177 NULL
87527 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
87528 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
87529 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
87530 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
87531 +vfd_write_14717 vfd_write 3 14717 NULL
87532 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
87533 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
87534 +read_file_queue_40895 read_file_queue 3 40895 NULL
87535 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
87536 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
87537 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
87538 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
87539 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
87540 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
87541 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
87542 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
87543 +register_device_60015 register_device 2-3 60015 NULL
87544 +got_frame_16028 got_frame 2 16028 NULL
87545 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
87546 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
87547 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
87548 +waiters_read_40902 waiters_read 3 40902 NULL
87549 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
87550 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
87551 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
87552 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
87553 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
87554 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
87555 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
87556 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
87557 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
87558 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
87559 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
87560 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
87561 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
87562 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
87563 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
87564 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
87565 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
87566 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
87567 +fops_read_40672 fops_read 3 40672 NULL
87568 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
87569 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
87570 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
87571 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
87572 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
87573 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
87574 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
87575 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87576 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
87577 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
87578 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
87579 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
87580 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
87581 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
87582 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
87583 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
87584 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
87585 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
87586 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
87587 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
87588 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
87589 +fsm_init_16134 fsm_init 2 16134 NULL
87590 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
87591 +disconnect_32521 disconnect 4 32521 NULL
87592 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
87593 +pp_write_39554 pp_write 3 39554 NULL
87594 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
87595 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
87596 +ilo_read_32531 ilo_read 3 32531 NULL
87597 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
87598 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
87599 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
87600 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
87601 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
87602 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
87603 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
87604 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
87605 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
87606 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
87607 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
87608 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
87609 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
87610 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
87611 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87612 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
87613 +card_send_command_40757 card_send_command 3 40757 NULL
87614 +sys_mbind_7990 sys_mbind 5 7990 NULL
87615 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
87616 +pg_write_40766 pg_write 3 40766 NULL
87617 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
87618 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
87619 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
87620 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
87621 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
87622 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
87623 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
87624 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87625 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
87626 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
87627 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
87628 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
87629 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
87630 +vcs_read_8017 vcs_read 3 8017 NULL
87631 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
87632 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
87633 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
87634 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
87635 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
87636 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
87637 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
87638 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
87639 +copy_and_check_19089 copy_and_check 3 19089 NULL
87640 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
87641 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
87642 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
87643 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
87644 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
87645 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
87646 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
87647 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
87648 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
87649 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
87650 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
87651 +xd_rw_49020 xd_rw 3-4 49020 NULL
87652 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
87653 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
87654 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
87655 +kvmalloc_32646 kvmalloc 1 32646 NULL
87656 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
87657 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
87658 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
87659 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
87660 +generic_readlink_32654 generic_readlink 3 32654 NULL
87661 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
87662 +rbd_add_16366 rbd_add 3 16366 NULL
87663 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
87664 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
87665 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
87666 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
87667 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
87668 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
87669 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
87670 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
87671 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
87672 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
87673 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
87674 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
87675 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
87676 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
87677 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
87678 +venus_lookup_8121 venus_lookup 4 8121 NULL
87679 +compat_writev_60063 compat_writev 3 60063 NULL
87680 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
87681 +pd_video_read_24510 pd_video_read 3 24510 NULL
87682 +read_buf_20469 read_buf 2 20469 NULL
87683 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
87684 +scsi_register_49094 scsi_register 2 49094 NULL
87685 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
87686 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
87687 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
87688 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
87689 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
87690 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
87691 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
87692 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
87693 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
87694 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
87695 +alloc_dr_65495 alloc_dr 2 65495 NULL
87696 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
87697 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
87698 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
87699 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
87700 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
87701 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
87702 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
87703 +pt_read_49136 pt_read 3 49136 NULL
87704 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
87705 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
87706 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
87707 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
87708 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
87709 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
87710 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87711 new file mode 100644
87712 index 0000000..6387ddc
87713 --- /dev/null
87714 +++ b/tools/gcc/size_overflow_plugin.c
87715 @@ -0,0 +1,1918 @@
87716 +/*
87717 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87718 + * Licensed under the GPL v2, or (at your option) v3
87719 + *
87720 + * Homepage:
87721 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87722 + *
87723 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87724 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87725 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87726 + *
87727 + * Usage:
87728 + * $ 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
87729 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87730 + */
87731 +
87732 +#include "gcc-plugin.h"
87733 +#include "config.h"
87734 +#include "system.h"
87735 +#include "coretypes.h"
87736 +#include "tree.h"
87737 +#include "tree-pass.h"
87738 +#include "intl.h"
87739 +#include "plugin-version.h"
87740 +#include "tm.h"
87741 +#include "toplev.h"
87742 +#include "function.h"
87743 +#include "tree-flow.h"
87744 +#include "plugin.h"
87745 +#include "gimple.h"
87746 +#include "c-common.h"
87747 +#include "diagnostic.h"
87748 +#include "cfgloop.h"
87749 +
87750 +#if BUILDING_GCC_VERSION >= 4007
87751 +#include "c-tree.h"
87752 +#else
87753 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87754 +#endif
87755 +
87756 +struct size_overflow_hash {
87757 + const struct size_overflow_hash * const next;
87758 + const char * const name;
87759 + const unsigned int param;
87760 +};
87761 +
87762 +#include "size_overflow_hash.h"
87763 +
87764 +enum marked {
87765 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87766 +};
87767 +
87768 +#define __unused __attribute__((__unused__))
87769 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87770 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87771 +#define BEFORE_STMT true
87772 +#define AFTER_STMT false
87773 +#define CREATE_NEW_VAR NULL_TREE
87774 +#define CODES_LIMIT 32
87775 +#define MAX_PARAM 32
87776 +#define MY_STMT GF_PLF_1
87777 +#define NO_CAST_CHECK GF_PLF_2
87778 +
87779 +#if BUILDING_GCC_VERSION == 4005
87780 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87781 +#endif
87782 +
87783 +int plugin_is_GPL_compatible;
87784 +void debug_gimple_stmt(gimple gs);
87785 +
87786 +static tree expand(struct pointer_set_t *visited, tree lhs);
87787 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87788 +static tree report_size_overflow_decl;
87789 +static const_tree const_char_ptr_type_node;
87790 +static unsigned int handle_function(void);
87791 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87792 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87793 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
87794 +
87795 +static unsigned int call_count=0;
87796 +
87797 +static struct plugin_info size_overflow_plugin_info = {
87798 + .version = "20121212beta",
87799 + .help = "no-size-overflow\tturn off size overflow checking\n",
87800 +};
87801 +
87802 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87803 +{
87804 + unsigned int arg_count;
87805 + enum tree_code code = TREE_CODE(*node);
87806 +
87807 + switch (code) {
87808 + case FUNCTION_DECL:
87809 + arg_count = type_num_arguments(TREE_TYPE(*node));
87810 + break;
87811 + case FUNCTION_TYPE:
87812 + case METHOD_TYPE:
87813 + arg_count = type_num_arguments(*node);
87814 + break;
87815 + default:
87816 + *no_add_attrs = true;
87817 + error("%s: %qE attribute only applies to functions", __func__, name);
87818 + return NULL_TREE;
87819 + }
87820 +
87821 + for (; args; args = TREE_CHAIN(args)) {
87822 + tree position = TREE_VALUE(args);
87823 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87824 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87825 + *no_add_attrs = true;
87826 + }
87827 + }
87828 + return NULL_TREE;
87829 +}
87830 +
87831 +static const char* get_asm_name(tree node)
87832 +{
87833 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87834 +}
87835 +
87836 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87837 +{
87838 + unsigned int arg_count, arg_num;
87839 + enum tree_code code = TREE_CODE(*node);
87840 +
87841 + switch (code) {
87842 + case FUNCTION_DECL:
87843 + arg_count = type_num_arguments(TREE_TYPE(*node));
87844 + break;
87845 + case FUNCTION_TYPE:
87846 + case METHOD_TYPE:
87847 + arg_count = type_num_arguments(*node);
87848 + break;
87849 + case FIELD_DECL:
87850 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87851 + if (arg_num != 0) {
87852 + *no_add_attrs = true;
87853 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87854 + }
87855 + return NULL_TREE;
87856 + default:
87857 + *no_add_attrs = true;
87858 + error("%qE attribute only applies to functions", name);
87859 + return NULL_TREE;
87860 + }
87861 +
87862 + for (; args; args = TREE_CHAIN(args)) {
87863 + tree position = TREE_VALUE(args);
87864 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87865 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87866 + *no_add_attrs = true;
87867 + }
87868 + }
87869 + return NULL_TREE;
87870 +}
87871 +
87872 +static struct attribute_spec size_overflow_attr = {
87873 + .name = "size_overflow",
87874 + .min_length = 1,
87875 + .max_length = -1,
87876 + .decl_required = true,
87877 + .type_required = false,
87878 + .function_type_required = false,
87879 + .handler = handle_size_overflow_attribute,
87880 +#if BUILDING_GCC_VERSION >= 4007
87881 + .affects_type_identity = false
87882 +#endif
87883 +};
87884 +
87885 +static struct attribute_spec intentional_overflow_attr = {
87886 + .name = "intentional_overflow",
87887 + .min_length = 1,
87888 + .max_length = -1,
87889 + .decl_required = true,
87890 + .type_required = false,
87891 + .function_type_required = false,
87892 + .handler = handle_intentional_overflow_attribute,
87893 +#if BUILDING_GCC_VERSION >= 4007
87894 + .affects_type_identity = false
87895 +#endif
87896 +};
87897 +
87898 +static void register_attributes(void __unused *event_data, void __unused *data)
87899 +{
87900 + register_attribute(&size_overflow_attr);
87901 + register_attribute(&intentional_overflow_attr);
87902 +}
87903 +
87904 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87905 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87906 +{
87907 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87908 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87909 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87910 +
87911 + unsigned int m = 0x57559429;
87912 + unsigned int n = 0x5052acdb;
87913 + const unsigned int *key4 = (const unsigned int *)key;
87914 + unsigned int h = len;
87915 + unsigned int k = len + seed + n;
87916 + unsigned long long p;
87917 +
87918 + while (len >= 8) {
87919 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87920 + len -= 8;
87921 + }
87922 + if (len >= 4) {
87923 + cwmixb(key4[0]) key4 += 1;
87924 + len -= 4;
87925 + }
87926 + if (len)
87927 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87928 + cwmixb(h ^ (k + n));
87929 + return k ^ h;
87930 +
87931 +#undef cwfold
87932 +#undef cwmixa
87933 +#undef cwmixb
87934 +}
87935 +
87936 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87937 +{
87938 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87939 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87940 + return fn ^ codes;
87941 +}
87942 +
87943 +static inline tree get_original_function_decl(tree fndecl)
87944 +{
87945 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87946 + return DECL_ABSTRACT_ORIGIN(fndecl);
87947 + return fndecl;
87948 +}
87949 +
87950 +static inline gimple get_def_stmt(const_tree node)
87951 +{
87952 + gcc_assert(node != NULL_TREE);
87953 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87954 + return SSA_NAME_DEF_STMT(node);
87955 +}
87956 +
87957 +static unsigned char get_tree_code(const_tree type)
87958 +{
87959 + switch (TREE_CODE(type)) {
87960 + case ARRAY_TYPE:
87961 + return 0;
87962 + case BOOLEAN_TYPE:
87963 + return 1;
87964 + case ENUMERAL_TYPE:
87965 + return 2;
87966 + case FUNCTION_TYPE:
87967 + return 3;
87968 + case INTEGER_TYPE:
87969 + return 4;
87970 + case POINTER_TYPE:
87971 + return 5;
87972 + case RECORD_TYPE:
87973 + return 6;
87974 + case UNION_TYPE:
87975 + return 7;
87976 + case VOID_TYPE:
87977 + return 8;
87978 + case REAL_TYPE:
87979 + return 9;
87980 + case VECTOR_TYPE:
87981 + return 10;
87982 + case REFERENCE_TYPE:
87983 + return 11;
87984 + case OFFSET_TYPE:
87985 + return 12;
87986 + case COMPLEX_TYPE:
87987 + return 13;
87988 + default:
87989 + debug_tree((tree)type);
87990 + gcc_unreachable();
87991 + }
87992 +}
87993 +
87994 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87995 +{
87996 + gcc_assert(type != NULL_TREE);
87997 +
87998 + while (type && len < CODES_LIMIT) {
87999 + tree_codes[len] = get_tree_code(type);
88000 + len++;
88001 + type = TREE_TYPE(type);
88002 + }
88003 + return len;
88004 +}
88005 +
88006 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
88007 +{
88008 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88009 + enum tree_code code = TREE_CODE(type);
88010 + size_t len = 0;
88011 +
88012 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88013 +
88014 + arg = TYPE_ARG_TYPES(type);
88015 + // skip builtins __builtin_constant_p
88016 + if (!arg && DECL_BUILT_IN(fndecl))
88017 + return 0;
88018 +
88019 + if (TREE_CODE_CLASS(code) == tcc_type)
88020 + result = type;
88021 + else
88022 + result = DECL_RESULT(fndecl);
88023 +
88024 + gcc_assert(result != NULL_TREE);
88025 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88026 +
88027 + if (arg == NULL_TREE) {
88028 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88029 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88030 + if (arg_field == NULL_TREE)
88031 + return 0;
88032 + arg = TREE_TYPE(arg_field);
88033 + len = add_type_codes(arg, tree_codes, len);
88034 + gcc_assert(len != 0);
88035 + return len;
88036 + }
88037 +
88038 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88039 + while (arg && len < CODES_LIMIT) {
88040 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88041 + arg = TREE_CHAIN(arg);
88042 + }
88043 +
88044 + gcc_assert(len != 0);
88045 + return len;
88046 +}
88047 +
88048 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88049 +{
88050 + unsigned int hash;
88051 + const struct size_overflow_hash *entry;
88052 + unsigned char tree_codes[CODES_LIMIT];
88053 + size_t len;
88054 + const char *func_name = get_asm_name(fndecl);
88055 +
88056 + len = get_function_decl(fndecl, tree_codes);
88057 + if (len == 0)
88058 + return NULL;
88059 +
88060 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88061 +
88062 + entry = size_overflow_hash[hash];
88063 + while (entry) {
88064 + if (!strcmp(entry->name, func_name))
88065 + return entry;
88066 + entry = entry->next;
88067 + }
88068 +
88069 + return NULL;
88070 +}
88071 +
88072 +static void check_arg_type(const_tree arg)
88073 +{
88074 + const_tree type = TREE_TYPE(arg);
88075 + enum tree_code code = TREE_CODE(type);
88076 +
88077 + if (code == BOOLEAN_TYPE)
88078 + return;
88079 +
88080 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88081 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88082 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88083 +}
88084 +
88085 +static int find_arg_number(const_tree arg, tree func)
88086 +{
88087 + tree var;
88088 + unsigned int argnum = 1;
88089 +
88090 + if (TREE_CODE(arg) == SSA_NAME)
88091 + arg = SSA_NAME_VAR(arg);
88092 +
88093 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88094 + if (strcmp(NAME(arg), NAME(var))) {
88095 + argnum++;
88096 + continue;
88097 + }
88098 + check_arg_type(var);
88099 + return argnum;
88100 + }
88101 + gcc_unreachable();
88102 +}
88103 +
88104 +static tree create_new_var(tree type)
88105 +{
88106 + tree new_var = create_tmp_var(type, "cicus");
88107 +
88108 + add_referenced_var(new_var);
88109 + mark_sym_for_renaming(new_var);
88110 + return new_var;
88111 +}
88112 +
88113 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88114 +{
88115 + gimple assign;
88116 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88117 + tree type = TREE_TYPE(rhs1);
88118 + tree lhs = create_new_var(type);
88119 +
88120 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88121 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88122 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88123 +
88124 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88125 + update_stmt(assign);
88126 + gimple_set_plf(assign, MY_STMT, true);
88127 + return assign;
88128 +}
88129 +
88130 +static bool is_bool(const_tree node)
88131 +{
88132 + const_tree type;
88133 +
88134 + if (node == NULL_TREE)
88135 + return false;
88136 +
88137 + type = TREE_TYPE(node);
88138 + if (!INTEGRAL_TYPE_P(type))
88139 + return false;
88140 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88141 + return true;
88142 + if (TYPE_PRECISION(type) == 1)
88143 + return true;
88144 + return false;
88145 +}
88146 +
88147 +static tree cast_a_tree(tree type, tree var)
88148 +{
88149 + gcc_assert(type != NULL_TREE);
88150 + gcc_assert(var != NULL_TREE);
88151 + gcc_assert(fold_convertible_p(type, var));
88152 +
88153 + return fold_convert(type, var);
88154 +}
88155 +
88156 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88157 +{
88158 + gimple assign;
88159 +
88160 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88161 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88162 + gcc_unreachable();
88163 +
88164 + if (lhs == CREATE_NEW_VAR)
88165 + lhs = create_new_var(dst_type);
88166 +
88167 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88168 +
88169 + if (!gsi_end_p(*gsi)) {
88170 + location_t loc = gimple_location(gsi_stmt(*gsi));
88171 + gimple_set_location(assign, loc);
88172 + }
88173 +
88174 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88175 +
88176 + if (before)
88177 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88178 + else
88179 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88180 + update_stmt(assign);
88181 + gimple_set_plf(assign, MY_STMT, true);
88182 +
88183 + return assign;
88184 +}
88185 +
88186 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88187 +{
88188 + gimple assign;
88189 + gimple_stmt_iterator gsi;
88190 +
88191 + if (rhs == NULL_TREE)
88192 + return NULL_TREE;
88193 +
88194 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88195 + return rhs;
88196 +
88197 + gsi = gsi_for_stmt(stmt);
88198 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88199 + gimple_set_plf(assign, MY_STMT, true);
88200 + return gimple_get_lhs(assign);
88201 +}
88202 +
88203 +static tree cast_to_TI_type(gimple stmt, tree node)
88204 +{
88205 + gimple_stmt_iterator gsi;
88206 + gimple cast_stmt;
88207 + tree type = TREE_TYPE(node);
88208 +
88209 + if (types_compatible_p(type, intTI_type_node))
88210 + return node;
88211 +
88212 + gsi = gsi_for_stmt(stmt);
88213 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88214 + gimple_set_plf(cast_stmt, MY_STMT, true);
88215 + return gimple_get_lhs(cast_stmt);
88216 +}
88217 +
88218 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88219 +{
88220 + tree lhs;
88221 + gimple_stmt_iterator gsi;
88222 +
88223 + if (rhs1 == NULL_TREE) {
88224 + debug_gimple_stmt(oldstmt);
88225 + error("%s: rhs1 is NULL_TREE", __func__);
88226 + gcc_unreachable();
88227 + }
88228 +
88229 + switch (gimple_code(oldstmt)) {
88230 + case GIMPLE_ASM:
88231 + lhs = rhs1;
88232 + break;
88233 + case GIMPLE_CALL:
88234 + lhs = gimple_call_lhs(oldstmt);
88235 + break;
88236 + case GIMPLE_ASSIGN:
88237 + lhs = gimple_get_lhs(oldstmt);
88238 + break;
88239 + default:
88240 + debug_gimple_stmt(oldstmt);
88241 + gcc_unreachable();
88242 + }
88243 +
88244 + gsi = gsi_for_stmt(oldstmt);
88245 + pointer_set_insert(visited, oldstmt);
88246 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88247 + basic_block next_bb, cur_bb;
88248 + const_edge e;
88249 +
88250 + gcc_assert(before == false);
88251 + gcc_assert(stmt_can_throw_internal(oldstmt));
88252 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88253 + gcc_assert(!gsi_end_p(gsi));
88254 +
88255 + cur_bb = gimple_bb(oldstmt);
88256 + next_bb = cur_bb->next_bb;
88257 + e = find_edge(cur_bb, next_bb);
88258 + gcc_assert(e != NULL);
88259 + gcc_assert(e->flags & EDGE_FALLTHRU);
88260 +
88261 + gsi = gsi_after_labels(next_bb);
88262 + gcc_assert(!gsi_end_p(gsi));
88263 +
88264 + before = true;
88265 + oldstmt = gsi_stmt(gsi);
88266 + }
88267 +
88268 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88269 +}
88270 +
88271 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88272 +{
88273 + gimple stmt;
88274 + gimple_stmt_iterator gsi;
88275 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88276 +
88277 + if (gimple_plf(oldstmt, MY_STMT))
88278 + return lhs;
88279 +
88280 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88281 + rhs1 = gimple_assign_rhs1(oldstmt);
88282 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88283 + }
88284 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88285 + rhs2 = gimple_assign_rhs2(oldstmt);
88286 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88287 + }
88288 +
88289 + stmt = gimple_copy(oldstmt);
88290 + gimple_set_location(stmt, gimple_location(oldstmt));
88291 + gimple_set_plf(stmt, MY_STMT, true);
88292 +
88293 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88294 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88295 +
88296 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88297 +
88298 + if (is_bool(lhs))
88299 + new_var = SSA_NAME_VAR(lhs);
88300 + else
88301 + new_var = create_new_var(size_overflow_type);
88302 + new_var = make_ssa_name(new_var, stmt);
88303 + gimple_set_lhs(stmt, new_var);
88304 +
88305 + if (rhs1 != NULL_TREE)
88306 + gimple_assign_set_rhs1(stmt, rhs1);
88307 +
88308 + if (rhs2 != NULL_TREE)
88309 + gimple_assign_set_rhs2(stmt, rhs2);
88310 +#if BUILDING_GCC_VERSION >= 4007
88311 + if (rhs3 != NULL_TREE)
88312 + gimple_assign_set_rhs3(stmt, rhs3);
88313 +#endif
88314 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88315 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88316 +
88317 + gsi = gsi_for_stmt(oldstmt);
88318 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88319 + update_stmt(stmt);
88320 + pointer_set_insert(visited, oldstmt);
88321 + return gimple_get_lhs(stmt);
88322 +}
88323 +
88324 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88325 +{
88326 + basic_block bb;
88327 + gimple phi;
88328 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88329 +
88330 + bb = gsi_bb(gsi);
88331 +
88332 + phi = create_phi_node(result, bb);
88333 + gsi = gsi_last(phi_nodes(bb));
88334 + gsi_remove(&gsi, false);
88335 +
88336 + gsi = gsi_for_stmt(oldstmt);
88337 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88338 + gimple_set_bb(phi, bb);
88339 + gimple_set_plf(phi, MY_STMT, true);
88340 + return phi;
88341 +}
88342 +
88343 +static basic_block create_a_first_bb(void)
88344 +{
88345 + basic_block first_bb;
88346 +
88347 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88348 + if (dom_info_available_p(CDI_DOMINATORS))
88349 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88350 + return first_bb;
88351 +}
88352 +
88353 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88354 +{
88355 + basic_block bb;
88356 + const_gimple newstmt;
88357 + gimple_stmt_iterator gsi;
88358 + bool before = BEFORE_STMT;
88359 +
88360 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88361 + gsi = gsi_for_stmt(get_def_stmt(arg));
88362 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88363 + return gimple_get_lhs(newstmt);
88364 + }
88365 +
88366 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88367 + gsi = gsi_after_labels(bb);
88368 + if (bb->index == 0) {
88369 + bb = create_a_first_bb();
88370 + gsi = gsi_start_bb(bb);
88371 + }
88372 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88373 + return gimple_get_lhs(newstmt);
88374 +}
88375 +
88376 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88377 +{
88378 + gimple newstmt;
88379 + gimple_stmt_iterator gsi;
88380 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88381 + gimple def_newstmt = get_def_stmt(new_rhs);
88382 +
88383 + gsi_insert = gsi_insert_after;
88384 + gsi = gsi_for_stmt(def_newstmt);
88385 +
88386 + switch (gimple_code(get_def_stmt(arg))) {
88387 + case GIMPLE_PHI:
88388 + newstmt = gimple_build_assign(new_var, new_rhs);
88389 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88390 + gsi_insert = gsi_insert_before;
88391 + break;
88392 + case GIMPLE_ASM:
88393 + case GIMPLE_CALL:
88394 + newstmt = gimple_build_assign(new_var, new_rhs);
88395 + break;
88396 + case GIMPLE_ASSIGN:
88397 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88398 + break;
88399 + default:
88400 + /* unknown gimple_code (handle_build_new_phi_arg) */
88401 + gcc_unreachable();
88402 + }
88403 +
88404 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88405 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88406 + gimple_set_plf(newstmt, MY_STMT, true);
88407 + update_stmt(newstmt);
88408 + return newstmt;
88409 +}
88410 +
88411 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88412 +{
88413 + const_gimple newstmt;
88414 + gimple def_stmt;
88415 + tree new_rhs;
88416 +
88417 + new_rhs = expand(visited, arg);
88418 + if (new_rhs == NULL_TREE)
88419 + return NULL_TREE;
88420 +
88421 + def_stmt = get_def_stmt(new_rhs);
88422 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88423 + return NULL_TREE;
88424 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88425 +
88426 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88427 + return gimple_get_lhs(newstmt);
88428 +}
88429 +
88430 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88431 +{
88432 + gimple phi, oldstmt = get_def_stmt(orig_result);
88433 + tree new_result, size_overflow_type;
88434 + unsigned int i;
88435 + unsigned int n = gimple_phi_num_args(oldstmt);
88436 +
88437 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88438 +
88439 + new_result = create_new_var(size_overflow_type);
88440 +
88441 + pointer_set_insert(visited, oldstmt);
88442 + phi = overflow_create_phi_node(oldstmt, new_result);
88443 + for (i = 0; i < n; i++) {
88444 + tree arg, lhs;
88445 +
88446 + arg = gimple_phi_arg_def(oldstmt, i);
88447 + if (is_gimple_constant(arg))
88448 + arg = cast_a_tree(size_overflow_type, arg);
88449 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88450 + if (lhs == NULL_TREE)
88451 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88452 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88453 + }
88454 +
88455 + update_stmt(phi);
88456 + return gimple_phi_result(phi);
88457 +}
88458 +
88459 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88460 +{
88461 + const_gimple assign;
88462 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88463 + tree origtype = TREE_TYPE(orig_rhs);
88464 +
88465 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88466 +
88467 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88468 + return gimple_get_lhs(assign);
88469 +}
88470 +
88471 +static void change_rhs1(gimple stmt, tree new_rhs1)
88472 +{
88473 + tree assign_rhs;
88474 + const_tree rhs = gimple_assign_rhs1(stmt);
88475 +
88476 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88477 + gimple_assign_set_rhs1(stmt, assign_rhs);
88478 + update_stmt(stmt);
88479 +}
88480 +
88481 +static bool check_mode_type(const_gimple stmt)
88482 +{
88483 + const_tree lhs = gimple_get_lhs(stmt);
88484 + const_tree lhs_type = TREE_TYPE(lhs);
88485 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88486 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88487 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88488 +
88489 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88490 + return false;
88491 +
88492 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88493 + return false;
88494 +
88495 + return true;
88496 +}
88497 +
88498 +static bool check_undefined_integer_operation(const_gimple stmt)
88499 +{
88500 + const_gimple def_stmt;
88501 + const_tree lhs = gimple_get_lhs(stmt);
88502 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88503 + const_tree rhs1_type = TREE_TYPE(rhs1);
88504 + const_tree lhs_type = TREE_TYPE(lhs);
88505 +
88506 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88507 + return false;
88508 +
88509 + def_stmt = get_def_stmt(rhs1);
88510 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88511 + return false;
88512 +
88513 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88514 + return false;
88515 + return true;
88516 +}
88517 +
88518 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88519 +{
88520 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88521 + enum machine_mode lhs_mode, rhs_mode;
88522 + gimple def_stmt = get_def_stmt(no_const_rhs);
88523 +
88524 + if (!gimple_assign_cast_p(def_stmt))
88525 + return false;
88526 +
88527 + rhs1 = gimple_assign_rhs1(def_stmt);
88528 + lhs = gimple_get_lhs(def_stmt);
88529 + rhs1_type = TREE_TYPE(rhs1);
88530 + lhs_type = TREE_TYPE(lhs);
88531 + rhs_mode = TYPE_MODE(rhs1_type);
88532 + lhs_mode = TYPE_MODE(lhs_type);
88533 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88534 + return false;
88535 +
88536 + return true;
88537 +}
88538 +
88539 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88540 +{
88541 + gimple def_stmt;
88542 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88543 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88544 + const_tree rhs1_type = TREE_TYPE(rhs1);
88545 + const_tree lhs_type = TREE_TYPE(lhs);
88546 +
88547 + new_rhs1 = expand(visited, rhs1);
88548 +
88549 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88550 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88551 +
88552 + if (gimple_plf(stmt, MY_STMT))
88553 + return lhs;
88554 +
88555 + if (gimple_plf(stmt, NO_CAST_CHECK))
88556 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88557 +
88558 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88559 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88560 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88561 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88562 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88563 + }
88564 +
88565 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88566 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88567 +
88568 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88569 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88570 +
88571 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88572 +
88573 + rhs1 = gimple_assign_rhs1(stmt);
88574 + rhs1_type = TREE_TYPE(rhs1);
88575 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type)) {
88576 + def_stmt = get_def_stmt(new_rhs1);
88577 + rhs1 = gimple_assign_rhs1(def_stmt);
88578 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88579 + }
88580 + change_rhs1(stmt, new_rhs1);
88581 +
88582 + if (!check_mode_type(stmt))
88583 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88584 +
88585 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88586 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88587 +
88588 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88589 +
88590 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88591 +}
88592 +
88593 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
88594 +{
88595 + tree rhs1, lhs = gimple_get_lhs(stmt);
88596 + gimple def_stmt = get_def_stmt(lhs);
88597 +
88598 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
88599 + rhs1 = gimple_assign_rhs1(def_stmt);
88600 +
88601 + if (is_gimple_constant(rhs1))
88602 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88603 +
88604 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88605 + switch (TREE_CODE(rhs1)) {
88606 + case SSA_NAME:
88607 + return handle_unary_rhs(visited, def_stmt);
88608 + case ARRAY_REF:
88609 + case BIT_FIELD_REF:
88610 + case ADDR_EXPR:
88611 + case COMPONENT_REF:
88612 + case INDIRECT_REF:
88613 +#if BUILDING_GCC_VERSION >= 4006
88614 + case MEM_REF:
88615 +#endif
88616 + case TARGET_MEM_REF:
88617 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88618 + case PARM_DECL:
88619 + case VAR_DECL:
88620 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88621 +
88622 + default:
88623 + debug_gimple_stmt(def_stmt);
88624 + debug_tree(rhs1);
88625 + gcc_unreachable();
88626 + }
88627 +}
88628 +
88629 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88630 +{
88631 + gimple cond_stmt;
88632 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88633 +
88634 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88635 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88636 + update_stmt(cond_stmt);
88637 +}
88638 +
88639 +static tree create_string_param(tree string)
88640 +{
88641 + tree i_type, a_type;
88642 + const int length = TREE_STRING_LENGTH(string);
88643 +
88644 + gcc_assert(length > 0);
88645 +
88646 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88647 + a_type = build_array_type(char_type_node, i_type);
88648 +
88649 + TREE_TYPE(string) = a_type;
88650 + TREE_CONSTANT(string) = 1;
88651 + TREE_READONLY(string) = 1;
88652 +
88653 + return build1(ADDR_EXPR, ptr_type_node, string);
88654 +}
88655 +
88656 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88657 +{
88658 + gimple func_stmt;
88659 + const_gimple def_stmt;
88660 + const_tree loc_line;
88661 + tree loc_file, ssa_name, current_func;
88662 + expanded_location xloc;
88663 + char *ssa_name_buf;
88664 + int len;
88665 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88666 +
88667 + def_stmt = get_def_stmt(arg);
88668 + xloc = expand_location(gimple_location(def_stmt));
88669 +
88670 + if (!gimple_has_location(def_stmt)) {
88671 + xloc = expand_location(gimple_location(stmt));
88672 + if (!gimple_has_location(stmt))
88673 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88674 + }
88675 +
88676 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88677 +
88678 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88679 + loc_file = create_string_param(loc_file);
88680 +
88681 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88682 + current_func = create_string_param(current_func);
88683 +
88684 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
88685 + call_count++;
88686 + 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);
88687 + gcc_assert(len > 0);
88688 + ssa_name = build_string(len + 1, ssa_name_buf);
88689 + free(ssa_name_buf);
88690 + ssa_name = create_string_param(ssa_name);
88691 +
88692 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88693 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88694 +
88695 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88696 +}
88697 +
88698 +static void __unused print_the_code_insertions(const_gimple stmt)
88699 +{
88700 + location_t loc = gimple_location(stmt);
88701 +
88702 + inform(loc, "Integer size_overflow check applied here.");
88703 +}
88704 +
88705 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88706 +{
88707 + basic_block cond_bb, join_bb, bb_true;
88708 + edge e;
88709 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88710 +
88711 + cond_bb = gimple_bb(stmt);
88712 + if (before)
88713 + gsi_prev(&gsi);
88714 + if (gsi_end_p(gsi))
88715 + e = split_block_after_labels(cond_bb);
88716 + else
88717 + e = split_block(cond_bb, gsi_stmt(gsi));
88718 + cond_bb = e->src;
88719 + join_bb = e->dest;
88720 + e->flags = EDGE_FALSE_VALUE;
88721 + e->probability = REG_BR_PROB_BASE;
88722 +
88723 + bb_true = create_empty_bb(cond_bb);
88724 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88725 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88726 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88727 +
88728 + if (dom_info_available_p(CDI_DOMINATORS)) {
88729 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88730 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88731 + }
88732 +
88733 + if (current_loops != NULL) {
88734 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88735 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88736 + }
88737 +
88738 + insert_cond(cond_bb, arg, cond_code, type_value);
88739 + insert_cond_result(bb_true, stmt, arg, min);
88740 +
88741 +// print_the_code_insertions(stmt);
88742 +}
88743 +
88744 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88745 +{
88746 + const_tree rhs_type = TREE_TYPE(rhs);
88747 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88748 +
88749 + gcc_assert(rhs_type != NULL_TREE);
88750 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88751 + return;
88752 +
88753 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88754 +
88755 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88756 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88757 +
88758 + gcc_assert(!TREE_OVERFLOW(type_max));
88759 +
88760 + cast_rhs_type = TREE_TYPE(cast_rhs);
88761 + type_max_type = TREE_TYPE(type_max);
88762 + type_min_type = TREE_TYPE(type_min);
88763 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
88764 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
88765 +
88766 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88767 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88768 +}
88769 +
88770 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88771 +{
88772 + gimple change_rhs_def_stmt;
88773 + tree lhs = gimple_get_lhs(def_stmt);
88774 + tree lhs_type = TREE_TYPE(lhs);
88775 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88776 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88777 +
88778 + if (change_rhs == NULL_TREE)
88779 + return get_size_overflow_type(def_stmt, lhs);
88780 +
88781 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88782 +
88783 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88784 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88785 +
88786 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88787 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88788 +
88789 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88790 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88791 +
88792 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
88793 + debug_gimple_stmt(def_stmt);
88794 + gcc_unreachable();
88795 + }
88796 +
88797 + return get_size_overflow_type(def_stmt, lhs);
88798 +}
88799 +
88800 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88801 +{
88802 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88803 + return false;
88804 + if (!is_gimple_constant(rhs))
88805 + return false;
88806 + return true;
88807 +}
88808 +
88809 +static bool is_subtraction_special(const_gimple stmt)
88810 +{
88811 + gimple rhs1_def_stmt, rhs2_def_stmt;
88812 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
88813 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
88814 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88815 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88816 +
88817 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88818 + return false;
88819 +
88820 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88821 +
88822 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
88823 + return false;
88824 +
88825 + rhs1_def_stmt = get_def_stmt(rhs1);
88826 + rhs2_def_stmt = get_def_stmt(rhs2);
88827 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88828 + return false;
88829 +
88830 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88831 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88832 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
88833 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
88834 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88835 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88836 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
88837 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
88838 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
88839 + return false;
88840 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
88841 + return false;
88842 +
88843 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88844 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88845 + return true;
88846 +}
88847 +
88848 +static tree get_def_stmt_rhs(const_tree var)
88849 +{
88850 + tree rhs1, def_stmt_rhs1;
88851 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
88852 +
88853 + def_stmt = get_def_stmt(var);
88854 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
88855 +
88856 + rhs1 = gimple_assign_rhs1(def_stmt);
88857 + rhs1_def_stmt = get_def_stmt(rhs1);
88858 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
88859 + if (!gimple_assign_cast_p(rhs1_def_stmt))
88860 + return rhs1;
88861 +
88862 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88863 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
88864 +
88865 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
88866 + case GIMPLE_CALL:
88867 + case GIMPLE_NOP:
88868 + case GIMPLE_ASM:
88869 + return def_stmt_rhs1;
88870 + case GIMPLE_ASSIGN:
88871 + return rhs1;
88872 + default:
88873 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
88874 + gcc_unreachable();
88875 + }
88876 +}
88877 +
88878 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88879 +{
88880 + tree new_rhs1, new_rhs2;
88881 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88882 + gimple assign, stmt = get_def_stmt(lhs);
88883 + tree rhs1 = gimple_assign_rhs1(stmt);
88884 + tree rhs2 = gimple_assign_rhs2(stmt);
88885 +
88886 + if (!is_subtraction_special(stmt))
88887 + return NULL_TREE;
88888 +
88889 + new_rhs1 = expand(visited, rhs1);
88890 + new_rhs2 = expand(visited, rhs2);
88891 +
88892 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
88893 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
88894 +
88895 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
88896 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
88897 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
88898 + }
88899 +
88900 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88901 + new_lhs = gimple_get_lhs(assign);
88902 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88903 +
88904 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88905 +}
88906 +
88907 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88908 +{
88909 + const_gimple def_stmt;
88910 +
88911 + if (TREE_CODE(rhs) != SSA_NAME)
88912 + return false;
88913 +
88914 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88915 + return false;
88916 +
88917 + def_stmt = get_def_stmt(rhs);
88918 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88919 + return false;
88920 +
88921 + return true;
88922 +}
88923 +
88924 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88925 +{
88926 + tree new_rhs, size_overflow_type, orig_rhs;
88927 + void (*gimple_assign_set_rhs)(gimple, tree);
88928 + tree rhs1 = gimple_assign_rhs1(stmt);
88929 + tree rhs2 = gimple_assign_rhs2(stmt);
88930 + tree lhs = gimple_get_lhs(stmt);
88931 +
88932 + if (change_rhs == NULL_TREE)
88933 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88934 +
88935 + if (new_rhs2 == NULL_TREE) {
88936 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88937 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88938 + orig_rhs = rhs1;
88939 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88940 + } else {
88941 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88942 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88943 + orig_rhs = rhs2;
88944 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88945 + }
88946 +
88947 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88948 +
88949 + if (check_overflow)
88950 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88951 +
88952 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88953 + gimple_assign_set_rhs(stmt, new_rhs);
88954 + update_stmt(stmt);
88955 +
88956 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88957 +}
88958 +
88959 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88960 +{
88961 + tree rhs1, rhs2, new_lhs;
88962 + gimple def_stmt = get_def_stmt(lhs);
88963 + tree new_rhs1 = NULL_TREE;
88964 + tree new_rhs2 = NULL_TREE;
88965 +
88966 + rhs1 = gimple_assign_rhs1(def_stmt);
88967 + rhs2 = gimple_assign_rhs2(def_stmt);
88968 +
88969 + /* no DImode/TImode division in the 32/64 bit kernel */
88970 + switch (gimple_assign_rhs_code(def_stmt)) {
88971 + case RDIV_EXPR:
88972 + case TRUNC_DIV_EXPR:
88973 + case CEIL_DIV_EXPR:
88974 + case FLOOR_DIV_EXPR:
88975 + case ROUND_DIV_EXPR:
88976 + case TRUNC_MOD_EXPR:
88977 + case CEIL_MOD_EXPR:
88978 + case FLOOR_MOD_EXPR:
88979 + case ROUND_MOD_EXPR:
88980 + case EXACT_DIV_EXPR:
88981 + case POINTER_PLUS_EXPR:
88982 + case BIT_AND_EXPR:
88983 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88984 + default:
88985 + break;
88986 + }
88987 +
88988 + new_lhs = handle_integer_truncation(visited, lhs);
88989 + if (new_lhs != NULL_TREE)
88990 + return new_lhs;
88991 +
88992 + if (TREE_CODE(rhs1) == SSA_NAME)
88993 + new_rhs1 = expand(visited, rhs1);
88994 + if (TREE_CODE(rhs2) == SSA_NAME)
88995 + new_rhs2 = expand(visited, rhs2);
88996 +
88997 + if (is_a_neg_overflow(def_stmt, rhs2))
88998 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88999 + if (is_a_neg_overflow(def_stmt, rhs1))
89000 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89001 +
89002 + if (is_a_constant_overflow(def_stmt, rhs2))
89003 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89004 + if (is_a_constant_overflow(def_stmt, rhs1))
89005 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89006 +
89007 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89008 +}
89009 +
89010 +#if BUILDING_GCC_VERSION >= 4007
89011 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
89012 +{
89013 + if (is_gimple_constant(rhs))
89014 + return cast_a_tree(size_overflow_type, rhs);
89015 + if (TREE_CODE(rhs) != SSA_NAME)
89016 + return NULL_TREE;
89017 + return expand(visited, rhs);
89018 +}
89019 +
89020 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
89021 +{
89022 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
89023 + gimple def_stmt = get_def_stmt(lhs);
89024 +
89025 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
89026 +
89027 + rhs1 = gimple_assign_rhs1(def_stmt);
89028 + rhs2 = gimple_assign_rhs2(def_stmt);
89029 + rhs3 = gimple_assign_rhs3(def_stmt);
89030 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
89031 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89032 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89033 +
89034 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89035 +}
89036 +#endif
89037 +
89038 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89039 +{
89040 + const_tree type;
89041 + tree new_type;
89042 +
89043 + gcc_assert(node != NULL_TREE);
89044 +
89045 + type = TREE_TYPE(node);
89046 +
89047 + if (gimple_plf(stmt, MY_STMT))
89048 + return TREE_TYPE(node);
89049 +
89050 + switch (TYPE_MODE(type)) {
89051 + case QImode:
89052 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89053 + break;
89054 + case HImode:
89055 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89056 + break;
89057 + case SImode:
89058 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89059 + break;
89060 + case DImode:
89061 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89062 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89063 + else
89064 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89065 + break;
89066 + default:
89067 + debug_tree((tree)node);
89068 + error("%s: unsupported gcc configuration.", __func__);
89069 + gcc_unreachable();
89070 + }
89071 +
89072 + if (TYPE_QUALS(type) != 0)
89073 + return build_qualified_type(new_type, TYPE_QUALS(type));
89074 + return new_type;
89075 +}
89076 +
89077 +static tree expand_visited(gimple def_stmt)
89078 +{
89079 + const_gimple next_stmt;
89080 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89081 +
89082 + gsi_next(&gsi);
89083 + next_stmt = gsi_stmt(gsi);
89084 +
89085 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89086 +
89087 + switch (gimple_code(next_stmt)) {
89088 + case GIMPLE_ASSIGN:
89089 + return gimple_get_lhs(next_stmt);
89090 + case GIMPLE_PHI:
89091 + return gimple_phi_result(next_stmt);
89092 + case GIMPLE_CALL:
89093 + return gimple_call_lhs(next_stmt);
89094 + default:
89095 + return NULL_TREE;
89096 + }
89097 +}
89098 +
89099 +static tree expand(struct pointer_set_t *visited, tree lhs)
89100 +{
89101 + gimple def_stmt;
89102 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89103 +
89104 + if (is_gimple_constant(lhs))
89105 + return NULL_TREE;
89106 +
89107 + if (TREE_CODE(lhs) == ADDR_EXPR)
89108 + return NULL_TREE;
89109 +
89110 + if (code == REAL_TYPE)
89111 + return NULL_TREE;
89112 +
89113 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89114 +
89115 + def_stmt = get_def_stmt(lhs);
89116 +
89117 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
89118 + return NULL_TREE;
89119 +
89120 + if (gimple_plf(def_stmt, MY_STMT))
89121 + return lhs;
89122 +
89123 + // skip char type, except PHI (FIXME: only kernel)
89124 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode && gimple_code(def_stmt) != GIMPLE_PHI)
89125 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89126 +
89127 + if (pointer_set_contains(visited, def_stmt))
89128 + return expand_visited(def_stmt);
89129 +
89130 + switch (gimple_code(def_stmt)) {
89131 + case GIMPLE_PHI:
89132 + return build_new_phi(visited, lhs);
89133 + case GIMPLE_CALL:
89134 + case GIMPLE_ASM:
89135 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89136 + case GIMPLE_ASSIGN:
89137 + switch (gimple_num_ops(def_stmt)) {
89138 + case 2:
89139 + return handle_unary_ops(visited, def_stmt);
89140 + case 3:
89141 + return handle_binary_ops(visited, lhs);
89142 +#if BUILDING_GCC_VERSION >= 4007
89143 + case 4:
89144 + return handle_ternary_ops(visited, lhs);
89145 +#endif
89146 + }
89147 + default:
89148 + debug_gimple_stmt(def_stmt);
89149 + error("%s: unknown gimple code", __func__);
89150 + gcc_unreachable();
89151 + }
89152 +}
89153 +
89154 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89155 +{
89156 + const_gimple assign;
89157 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89158 + tree origtype = TREE_TYPE(origarg);
89159 +
89160 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89161 +
89162 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89163 +
89164 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89165 + update_stmt(stmt);
89166 +}
89167 +
89168 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89169 +{
89170 + const char *origid;
89171 + tree arg;
89172 + const_tree origarg;
89173 +
89174 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89175 + return true;
89176 +
89177 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89178 + while (origarg && *argnum) {
89179 + (*argnum)--;
89180 + origarg = TREE_CHAIN(origarg);
89181 + }
89182 +
89183 + gcc_assert(*argnum == 0);
89184 +
89185 + gcc_assert(origarg != NULL_TREE);
89186 + origid = NAME(origarg);
89187 + *argnum = 0;
89188 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89189 + if (!strcmp(origid, NAME(arg)))
89190 + return true;
89191 + (*argnum)++;
89192 + }
89193 + return false;
89194 +}
89195 +
89196 +static bool skip_types(const_tree var)
89197 +{
89198 + const_tree type;
89199 +
89200 + switch (TREE_CODE(var)) {
89201 + case ADDR_EXPR:
89202 +#if BUILDING_GCC_VERSION >= 4006
89203 + case MEM_REF:
89204 +#endif
89205 + case ARRAY_REF:
89206 + case BIT_FIELD_REF:
89207 + case INDIRECT_REF:
89208 + case TARGET_MEM_REF:
89209 + case VAR_DECL:
89210 + return true;
89211 + default:
89212 + break;
89213 + }
89214 +
89215 + type = TREE_TYPE(TREE_TYPE(var));
89216 + if (!type)
89217 + return false;
89218 + switch (TREE_CODE(type)) {
89219 + case RECORD_TYPE:
89220 + return true;
89221 + default:
89222 + break;
89223 + }
89224 +
89225 + return false;
89226 +}
89227 +
89228 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89229 +{
89230 + gimple phi = get_def_stmt(result);
89231 + unsigned int i, n = gimple_phi_num_args(phi);
89232 +
89233 + if (!phi)
89234 + return false;
89235 +
89236 + pointer_set_insert(visited, phi);
89237 + for (i = 0; i < n; i++) {
89238 + const_tree arg = gimple_phi_arg_def(phi, i);
89239 + if (pre_expand(visited, arg))
89240 + return true;
89241 + }
89242 + return false;
89243 +}
89244 +
89245 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89246 +{
89247 + gimple def_stmt = get_def_stmt(lhs);
89248 + const_tree rhs;
89249 +
89250 + if (!def_stmt)
89251 + return false;
89252 +
89253 + rhs = gimple_assign_rhs1(def_stmt);
89254 + if (pre_expand(visited, rhs))
89255 + return true;
89256 + return false;
89257 +}
89258 +
89259 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89260 +{
89261 + bool rhs1_found, rhs2_found;
89262 + gimple def_stmt = get_def_stmt(lhs);
89263 + const_tree rhs1, rhs2;
89264 +
89265 + if (!def_stmt)
89266 + return false;
89267 +
89268 + rhs1 = gimple_assign_rhs1(def_stmt);
89269 + rhs2 = gimple_assign_rhs2(def_stmt);
89270 + rhs1_found = pre_expand(visited, rhs1);
89271 + rhs2_found = pre_expand(visited, rhs2);
89272 +
89273 + return rhs1_found || rhs2_found;
89274 +}
89275 +
89276 +static const_tree search_field_decl(const_tree comp_ref)
89277 +{
89278 + const_tree field = NULL_TREE;
89279 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89280 +
89281 + for (i = 0; i < len; i++) {
89282 + field = TREE_OPERAND(comp_ref, i);
89283 + if (TREE_CODE(field) == FIELD_DECL)
89284 + break;
89285 + }
89286 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89287 + return field;
89288 +}
89289 +
89290 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89291 +{
89292 + const_tree attr, p;
89293 +
89294 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89295 + if (!attr || !TREE_VALUE(attr))
89296 + return MARKED_NO;
89297 +
89298 + p = TREE_VALUE(attr);
89299 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89300 + return MARKED_NOT_INTENTIONAL;
89301 +
89302 + do {
89303 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89304 + return MARKED_YES;
89305 + p = TREE_CHAIN(p);
89306 + } while (p);
89307 +
89308 + return MARKED_NO;
89309 +}
89310 +
89311 +static void print_missing_msg(tree func, unsigned int argnum)
89312 +{
89313 + unsigned int new_hash;
89314 + size_t len;
89315 + unsigned char tree_codes[CODES_LIMIT];
89316 + location_t loc = DECL_SOURCE_LOCATION(func);
89317 + const char *curfunc = get_asm_name(func);
89318 +
89319 + len = get_function_decl(func, tree_codes);
89320 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89321 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89322 +}
89323 +
89324 +static unsigned int search_missing_attribute(const_tree arg)
89325 +{
89326 + const_tree type = TREE_TYPE(arg);
89327 + tree func = get_original_function_decl(current_function_decl);
89328 + unsigned int argnum;
89329 + const struct size_overflow_hash *hash;
89330 +
89331 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89332 +
89333 + if (TREE_CODE(type) == POINTER_TYPE)
89334 + return 0;
89335 +
89336 + argnum = find_arg_number(arg, func);
89337 + if (argnum == 0)
89338 + return 0;
89339 +
89340 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89341 + return argnum;
89342 +
89343 + hash = get_function_hash(func);
89344 + if (!hash || !(hash->param & (1U << argnum))) {
89345 + print_missing_msg(func, argnum);
89346 + return 0;
89347 + }
89348 + return argnum;
89349 +}
89350 +
89351 +static bool is_already_marked(const_tree lhs)
89352 +{
89353 + unsigned int argnum;
89354 + const_tree fndecl;
89355 +
89356 + argnum = search_missing_attribute(lhs);
89357 + fndecl = get_original_function_decl(current_function_decl);
89358 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89359 + return true;
89360 + return false;
89361 +}
89362 +
89363 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89364 +{
89365 + const_gimple def_stmt;
89366 +
89367 + if (is_gimple_constant(lhs))
89368 + return false;
89369 +
89370 + if (skip_types(lhs))
89371 + return false;
89372 +
89373 + // skip char type (FIXME: only kernel)
89374 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
89375 + return false;
89376 +
89377 + if (TREE_CODE(lhs) == PARM_DECL)
89378 + return is_already_marked(lhs);
89379 +
89380 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89381 + const_tree field, attr;
89382 +
89383 + field = search_field_decl(lhs);
89384 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89385 + if (!attr || !TREE_VALUE(attr))
89386 + return false;
89387 + return true;
89388 + }
89389 +
89390 + def_stmt = get_def_stmt(lhs);
89391 +
89392 + if (!def_stmt)
89393 + return false;
89394 +
89395 + if (pointer_set_contains(visited, def_stmt))
89396 + return false;
89397 +
89398 + switch (gimple_code(def_stmt)) {
89399 + case GIMPLE_NOP:
89400 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89401 + return is_already_marked(lhs);
89402 + return false;
89403 + case GIMPLE_PHI:
89404 + return walk_phi(visited, lhs);
89405 + case GIMPLE_CALL:
89406 + case GIMPLE_ASM:
89407 + return false;
89408 + case GIMPLE_ASSIGN:
89409 + switch (gimple_num_ops(def_stmt)) {
89410 + case 2:
89411 + return walk_unary_ops(visited, lhs);
89412 + case 3:
89413 + return walk_binary_ops(visited, lhs);
89414 + }
89415 + default:
89416 + debug_gimple_stmt((gimple)def_stmt);
89417 + error("%s: unknown gimple code", __func__);
89418 + gcc_unreachable();
89419 + }
89420 +}
89421 +
89422 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89423 +{
89424 + struct pointer_set_t *visited;
89425 + bool is_found;
89426 + enum marked is_marked;
89427 + location_t loc;
89428 +
89429 + visited = pointer_set_create();
89430 + is_found = pre_expand(visited, arg);
89431 + pointer_set_destroy(visited);
89432 +
89433 + is_marked = mark_status(fndecl, argnum + 1);
89434 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89435 + return true;
89436 +
89437 + if (is_found) {
89438 + loc = DECL_SOURCE_LOCATION(fndecl);
89439 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89440 + return true;
89441 + }
89442 + return false;
89443 +}
89444 +
89445 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89446 +{
89447 + struct pointer_set_t *visited;
89448 + tree arg, newarg;
89449 + bool match;
89450 +
89451 + match = get_function_arg(&argnum, fndecl);
89452 + if (!match)
89453 + return;
89454 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89455 + arg = gimple_call_arg(stmt, argnum);
89456 + if (arg == NULL_TREE)
89457 + return;
89458 +
89459 + if (is_gimple_constant(arg))
89460 + return;
89461 +
89462 + if (search_attributes(fndecl, arg, argnum))
89463 + return;
89464 +
89465 + if (TREE_CODE(arg) != SSA_NAME)
89466 + return;
89467 +
89468 + check_arg_type(arg);
89469 +
89470 + visited = pointer_set_create();
89471 + newarg = expand(visited, arg);
89472 + pointer_set_destroy(visited);
89473 +
89474 + if (newarg == NULL_TREE)
89475 + return;
89476 +
89477 + change_function_arg(stmt, arg, argnum, newarg);
89478 +
89479 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89480 +}
89481 +
89482 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89483 +{
89484 + tree p = TREE_VALUE(attr);
89485 + do {
89486 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89487 + p = TREE_CHAIN(p);
89488 + } while (p);
89489 +}
89490 +
89491 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89492 +{
89493 + tree orig_fndecl;
89494 + unsigned int num;
89495 + const struct size_overflow_hash *hash;
89496 +
89497 + orig_fndecl = get_original_function_decl(fndecl);
89498 + if (C_DECL_IMPLICIT(orig_fndecl))
89499 + return;
89500 + hash = get_function_hash(orig_fndecl);
89501 + if (!hash)
89502 + return;
89503 +
89504 + for (num = 1; num <= MAX_PARAM; num++)
89505 + if (hash->param & (1U << num))
89506 + handle_function_arg(stmt, fndecl, num - 1);
89507 +}
89508 +
89509 +static void set_plf_false(void)
89510 +{
89511 + basic_block bb;
89512 +
89513 + FOR_ALL_BB(bb) {
89514 + gimple_stmt_iterator si;
89515 +
89516 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89517 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89518 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89519 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89520 + }
89521 +}
89522 +
89523 +static unsigned int handle_function(void)
89524 +{
89525 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89526 +
89527 + set_plf_false();
89528 +
89529 + do {
89530 + gimple_stmt_iterator gsi;
89531 + next = bb->next_bb;
89532 +
89533 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89534 + tree fndecl, attr;
89535 + gimple stmt = gsi_stmt(gsi);
89536 +
89537 + if (!(is_gimple_call(stmt)))
89538 + continue;
89539 + fndecl = gimple_call_fndecl(stmt);
89540 + if (fndecl == NULL_TREE)
89541 + continue;
89542 + if (gimple_call_num_args(stmt) == 0)
89543 + continue;
89544 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89545 + if (!attr || !TREE_VALUE(attr))
89546 + handle_function_by_hash(stmt, fndecl);
89547 + else
89548 + handle_function_by_attribute(stmt, attr, fndecl);
89549 + gsi = gsi_for_stmt(stmt);
89550 + next = gimple_bb(stmt)->next_bb;
89551 + }
89552 + bb = next;
89553 + } while (bb);
89554 + return 0;
89555 +}
89556 +
89557 +static struct gimple_opt_pass size_overflow_pass = {
89558 + .pass = {
89559 + .type = GIMPLE_PASS,
89560 + .name = "size_overflow",
89561 + .gate = NULL,
89562 + .execute = handle_function,
89563 + .sub = NULL,
89564 + .next = NULL,
89565 + .static_pass_number = 0,
89566 + .tv_id = TV_NONE,
89567 + .properties_required = PROP_cfg | PROP_referenced_vars,
89568 + .properties_provided = 0,
89569 + .properties_destroyed = 0,
89570 + .todo_flags_start = 0,
89571 + .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
89572 + }
89573 +};
89574 +
89575 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89576 +{
89577 + tree fntype;
89578 +
89579 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89580 +
89581 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89582 + fntype = build_function_type_list(void_type_node,
89583 + const_char_ptr_type_node,
89584 + unsigned_type_node,
89585 + const_char_ptr_type_node,
89586 + const_char_ptr_type_node,
89587 + NULL_TREE);
89588 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89589 +
89590 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89591 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89592 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89593 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89594 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89595 +}
89596 +
89597 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89598 +{
89599 + int i;
89600 + const char * const plugin_name = plugin_info->base_name;
89601 + const int argc = plugin_info->argc;
89602 + const struct plugin_argument * const argv = plugin_info->argv;
89603 + bool enable = true;
89604 +
89605 + struct register_pass_info size_overflow_pass_info = {
89606 + .pass = &size_overflow_pass.pass,
89607 + .reference_pass_name = "ssa",
89608 + .ref_pass_instance_number = 1,
89609 + .pos_op = PASS_POS_INSERT_AFTER
89610 + };
89611 +
89612 + if (!plugin_default_version_check(version, &gcc_version)) {
89613 + error(G_("incompatible gcc/plugin versions"));
89614 + return 1;
89615 + }
89616 +
89617 + for (i = 0; i < argc; ++i) {
89618 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89619 + enable = false;
89620 + continue;
89621 + }
89622 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89623 + }
89624 +
89625 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89626 + if (enable) {
89627 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89628 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89629 + }
89630 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89631 +
89632 + return 0;
89633 +}
89634 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89635 new file mode 100644
89636 index 0000000..38d2014
89637 --- /dev/null
89638 +++ b/tools/gcc/stackleak_plugin.c
89639 @@ -0,0 +1,313 @@
89640 +/*
89641 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89642 + * Licensed under the GPL v2
89643 + *
89644 + * Note: the choice of the license means that the compilation process is
89645 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89646 + * but for the kernel it doesn't matter since it doesn't link against
89647 + * any of the gcc libraries
89648 + *
89649 + * gcc plugin to help implement various PaX features
89650 + *
89651 + * - track lowest stack pointer
89652 + *
89653 + * TODO:
89654 + * - initialize all local variables
89655 + *
89656 + * BUGS:
89657 + * - none known
89658 + */
89659 +#include "gcc-plugin.h"
89660 +#include "config.h"
89661 +#include "system.h"
89662 +#include "coretypes.h"
89663 +#include "tree.h"
89664 +#include "tree-pass.h"
89665 +#include "flags.h"
89666 +#include "intl.h"
89667 +#include "toplev.h"
89668 +#include "plugin.h"
89669 +//#include "expr.h" where are you...
89670 +#include "diagnostic.h"
89671 +#include "plugin-version.h"
89672 +#include "tm.h"
89673 +#include "function.h"
89674 +#include "basic-block.h"
89675 +#include "gimple.h"
89676 +#include "rtl.h"
89677 +#include "emit-rtl.h"
89678 +
89679 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89680 +
89681 +int plugin_is_GPL_compatible;
89682 +
89683 +static int track_frame_size = -1;
89684 +static const char track_function[] = "pax_track_stack";
89685 +static const char check_function[] = "pax_check_alloca";
89686 +static bool init_locals;
89687 +
89688 +static struct plugin_info stackleak_plugin_info = {
89689 + .version = "201203140940",
89690 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89691 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89692 +};
89693 +
89694 +static bool gate_stackleak_track_stack(void);
89695 +static unsigned int execute_stackleak_tree_instrument(void);
89696 +static unsigned int execute_stackleak_final(void);
89697 +
89698 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89699 + .pass = {
89700 + .type = GIMPLE_PASS,
89701 + .name = "stackleak_tree_instrument",
89702 + .gate = gate_stackleak_track_stack,
89703 + .execute = execute_stackleak_tree_instrument,
89704 + .sub = NULL,
89705 + .next = NULL,
89706 + .static_pass_number = 0,
89707 + .tv_id = TV_NONE,
89708 + .properties_required = PROP_gimple_leh | PROP_cfg,
89709 + .properties_provided = 0,
89710 + .properties_destroyed = 0,
89711 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89712 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89713 + }
89714 +};
89715 +
89716 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89717 + .pass = {
89718 + .type = RTL_PASS,
89719 + .name = "stackleak_final",
89720 + .gate = gate_stackleak_track_stack,
89721 + .execute = execute_stackleak_final,
89722 + .sub = NULL,
89723 + .next = NULL,
89724 + .static_pass_number = 0,
89725 + .tv_id = TV_NONE,
89726 + .properties_required = 0,
89727 + .properties_provided = 0,
89728 + .properties_destroyed = 0,
89729 + .todo_flags_start = 0,
89730 + .todo_flags_finish = TODO_dump_func
89731 + }
89732 +};
89733 +
89734 +static bool gate_stackleak_track_stack(void)
89735 +{
89736 + return track_frame_size >= 0;
89737 +}
89738 +
89739 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89740 +{
89741 + gimple check_alloca;
89742 + tree fntype, fndecl, alloca_size;
89743 +
89744 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89745 + fndecl = build_fn_decl(check_function, fntype);
89746 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89747 +
89748 + // insert call to void pax_check_alloca(unsigned long size)
89749 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89750 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89751 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89752 +}
89753 +
89754 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89755 +{
89756 + gimple track_stack;
89757 + tree fntype, fndecl;
89758 +
89759 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89760 + fndecl = build_fn_decl(track_function, fntype);
89761 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89762 +
89763 + // insert call to void pax_track_stack(void)
89764 + track_stack = gimple_build_call(fndecl, 0);
89765 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89766 +}
89767 +
89768 +#if BUILDING_GCC_VERSION == 4005
89769 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89770 +{
89771 + tree fndecl;
89772 +
89773 + if (!is_gimple_call(stmt))
89774 + return false;
89775 + fndecl = gimple_call_fndecl(stmt);
89776 + if (!fndecl)
89777 + return false;
89778 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89779 + return false;
89780 +// print_node(stderr, "pax", fndecl, 4);
89781 + return DECL_FUNCTION_CODE(fndecl) == code;
89782 +}
89783 +#endif
89784 +
89785 +static bool is_alloca(gimple stmt)
89786 +{
89787 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89788 + return true;
89789 +
89790 +#if BUILDING_GCC_VERSION >= 4007
89791 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89792 + return true;
89793 +#endif
89794 +
89795 + return false;
89796 +}
89797 +
89798 +static unsigned int execute_stackleak_tree_instrument(void)
89799 +{
89800 + basic_block bb, entry_bb;
89801 + bool prologue_instrumented = false, is_leaf = true;
89802 +
89803 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89804 +
89805 + // 1. loop through BBs and GIMPLE statements
89806 + FOR_EACH_BB(bb) {
89807 + gimple_stmt_iterator gsi;
89808 +
89809 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89810 + gimple stmt;
89811 +
89812 + stmt = gsi_stmt(gsi);
89813 +
89814 + if (is_gimple_call(stmt))
89815 + is_leaf = false;
89816 +
89817 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89818 + if (!is_alloca(stmt))
89819 + continue;
89820 +
89821 + // 2. insert stack overflow check before each __builtin_alloca call
89822 + stackleak_check_alloca(&gsi);
89823 +
89824 + // 3. insert track call after each __builtin_alloca call
89825 + stackleak_add_instrumentation(&gsi);
89826 + if (bb == entry_bb)
89827 + prologue_instrumented = true;
89828 + }
89829 + }
89830 +
89831 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89832 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89833 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89834 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89835 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89836 + return 0;
89837 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89838 + return 0;
89839 +
89840 + // 4. insert track call at the beginning
89841 + if (!prologue_instrumented) {
89842 + gimple_stmt_iterator gsi;
89843 +
89844 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89845 + if (dom_info_available_p(CDI_DOMINATORS))
89846 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89847 + gsi = gsi_start_bb(bb);
89848 + stackleak_add_instrumentation(&gsi);
89849 + }
89850 +
89851 + return 0;
89852 +}
89853 +
89854 +static unsigned int execute_stackleak_final(void)
89855 +{
89856 + rtx insn;
89857 +
89858 + if (cfun->calls_alloca)
89859 + return 0;
89860 +
89861 + // keep calls only if function frame is big enough
89862 + if (get_frame_size() >= track_frame_size)
89863 + return 0;
89864 +
89865 + // 1. find pax_track_stack calls
89866 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89867 + // 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))
89868 + rtx body;
89869 +
89870 + if (!CALL_P(insn))
89871 + continue;
89872 + body = PATTERN(insn);
89873 + if (GET_CODE(body) != CALL)
89874 + continue;
89875 + body = XEXP(body, 0);
89876 + if (GET_CODE(body) != MEM)
89877 + continue;
89878 + body = XEXP(body, 0);
89879 + if (GET_CODE(body) != SYMBOL_REF)
89880 + continue;
89881 + if (strcmp(XSTR(body, 0), track_function))
89882 + continue;
89883 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89884 + // 2. delete call
89885 + insn = delete_insn_and_edges(insn);
89886 +#if BUILDING_GCC_VERSION >= 4007
89887 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89888 + insn = delete_insn_and_edges(insn);
89889 +#endif
89890 + }
89891 +
89892 +// print_simple_rtl(stderr, get_insns());
89893 +// print_rtl(stderr, get_insns());
89894 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89895 +
89896 + return 0;
89897 +}
89898 +
89899 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89900 +{
89901 + const char * const plugin_name = plugin_info->base_name;
89902 + const int argc = plugin_info->argc;
89903 + const struct plugin_argument * const argv = plugin_info->argv;
89904 + int i;
89905 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89906 + .pass = &stackleak_tree_instrument_pass.pass,
89907 +// .reference_pass_name = "tree_profile",
89908 + .reference_pass_name = "optimized",
89909 + .ref_pass_instance_number = 1,
89910 + .pos_op = PASS_POS_INSERT_BEFORE
89911 + };
89912 + struct register_pass_info stackleak_final_pass_info = {
89913 + .pass = &stackleak_final_rtl_opt_pass.pass,
89914 + .reference_pass_name = "final",
89915 + .ref_pass_instance_number = 1,
89916 + .pos_op = PASS_POS_INSERT_BEFORE
89917 + };
89918 +
89919 + if (!plugin_default_version_check(version, &gcc_version)) {
89920 + error(G_("incompatible gcc/plugin versions"));
89921 + return 1;
89922 + }
89923 +
89924 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89925 +
89926 + for (i = 0; i < argc; ++i) {
89927 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89928 + if (!argv[i].value) {
89929 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89930 + continue;
89931 + }
89932 + track_frame_size = atoi(argv[i].value);
89933 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89934 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89935 + continue;
89936 + }
89937 + if (!strcmp(argv[i].key, "initialize-locals")) {
89938 + if (argv[i].value) {
89939 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89940 + continue;
89941 + }
89942 + init_locals = true;
89943 + continue;
89944 + }
89945 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89946 + }
89947 +
89948 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89949 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89950 +
89951 + return 0;
89952 +}
89953 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89954 index 6789d78..4afd019e 100644
89955 --- a/tools/perf/util/include/asm/alternative-asm.h
89956 +++ b/tools/perf/util/include/asm/alternative-asm.h
89957 @@ -5,4 +5,7 @@
89958
89959 #define altinstruction_entry #
89960
89961 + .macro pax_force_retaddr rip=0, reload=0
89962 + .endm
89963 +
89964 #endif
89965 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89966 index be70035..739990f 100644
89967 --- a/virt/kvm/kvm_main.c
89968 +++ b/virt/kvm/kvm_main.c
89969 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89970
89971 static cpumask_var_t cpus_hardware_enabled;
89972 static int kvm_usage_count = 0;
89973 -static atomic_t hardware_enable_failed;
89974 +static atomic_unchecked_t hardware_enable_failed;
89975
89976 struct kmem_cache *kvm_vcpu_cache;
89977 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89978 @@ -727,7 +727,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89979 /* We can read the guest memory with __xxx_user() later on. */
89980 if (user_alloc &&
89981 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89982 - !access_ok(VERIFY_WRITE,
89983 + !__access_ok(VERIFY_WRITE,
89984 (void __user *)(unsigned long)mem->userspace_addr,
89985 mem->memory_size)))
89986 goto out;
89987 @@ -2453,7 +2453,7 @@ static void hardware_enable_nolock(void *junk)
89988
89989 if (r) {
89990 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89991 - atomic_inc(&hardware_enable_failed);
89992 + atomic_inc_unchecked(&hardware_enable_failed);
89993 printk(KERN_INFO "kvm: enabling virtualization on "
89994 "CPU%d failed\n", cpu);
89995 }
89996 @@ -2507,10 +2507,10 @@ static int hardware_enable_all(void)
89997
89998 kvm_usage_count++;
89999 if (kvm_usage_count == 1) {
90000 - atomic_set(&hardware_enable_failed, 0);
90001 + atomic_set_unchecked(&hardware_enable_failed, 0);
90002 on_each_cpu(hardware_enable_nolock, NULL, 1);
90003
90004 - if (atomic_read(&hardware_enable_failed)) {
90005 + if (atomic_read_unchecked(&hardware_enable_failed)) {
90006 hardware_disable_all_nolock();
90007 r = -EBUSY;
90008 }
90009 @@ -2868,7 +2868,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
90010 kvm_arch_vcpu_put(vcpu);
90011 }
90012
90013 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90014 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90015 struct module *module)
90016 {
90017 int r;
90018 @@ -2904,7 +2904,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90019 if (!vcpu_align)
90020 vcpu_align = __alignof__(struct kvm_vcpu);
90021 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
90022 - 0, NULL);
90023 + SLAB_USERCOPY, NULL);
90024 if (!kvm_vcpu_cache) {
90025 r = -ENOMEM;
90026 goto out_free_3;
90027 @@ -2914,9 +2914,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90028 if (r)
90029 goto out_free;
90030
90031 - kvm_chardev_ops.owner = module;
90032 - kvm_vm_fops.owner = module;
90033 - kvm_vcpu_fops.owner = module;
90034 + pax_open_kernel();
90035 + *(void **)&kvm_chardev_ops.owner = module;
90036 + *(void **)&kvm_vm_fops.owner = module;
90037 + *(void **)&kvm_vcpu_fops.owner = module;
90038 + pax_close_kernel();
90039
90040 r = misc_register(&kvm_dev);
90041 if (r) {