]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.1-201212171734.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.1-201212171734.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 fbf84a4..339f6de 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..4ab7dba 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 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
20705 native_store_idt(&dt);
20706 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20707
20708 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
20709 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
20710
20711 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20712 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20713 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20714 "jmp 2f \n\t"
20715 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
20716 "2: "
20717 +
20718 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20719 + "ljmp %[cs],$3f\n\t"
20720 + "3: "
20721 +#endif
20722 +
20723 /* Save guest registers, load host registers, keep flags */
20724 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
20725 "pop %0 \n\t"
20726 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20727 #endif
20728 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20729 [wordsize]"i"(sizeof(ulong))
20730 +
20731 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20732 + ,[cs]"i"(__KERNEL_CS)
20733 +#endif
20734 +
20735 : "cc", "memory"
20736 #ifdef CONFIG_X86_64
20737 , "rax", "rbx", "rdi", "rsi"
20738 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20739 if (debugctlmsr)
20740 update_debugctlmsr(debugctlmsr);
20741
20742 -#ifndef CONFIG_X86_64
20743 +#ifdef CONFIG_X86_32
20744 /*
20745 * The sysexit path does not restore ds/es, so we must set them to
20746 * a reasonable value ourselves.
20747 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20748 * may be executed in interrupt context, which saves and restore segments
20749 * around it, nullifying its effect.
20750 */
20751 - loadsegment(ds, __USER_DS);
20752 - loadsegment(es, __USER_DS);
20753 + loadsegment(ds, __KERNEL_DS);
20754 + loadsegment(es, __KERNEL_DS);
20755 + loadsegment(ss, __KERNEL_DS);
20756 +
20757 +#ifdef CONFIG_PAX_KERNEXEC
20758 + loadsegment(fs, __KERNEL_PERCPU);
20759 +#endif
20760 +
20761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20762 + __set_fs(current_thread_info()->addr_limit);
20763 +#endif
20764 +
20765 #endif
20766
20767 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20768 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20769 index 4f76417..93429b5 100644
20770 --- a/arch/x86/kvm/x86.c
20771 +++ b/arch/x86/kvm/x86.c
20772 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20773 {
20774 struct kvm *kvm = vcpu->kvm;
20775 int lm = is_long_mode(vcpu);
20776 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20777 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20778 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20779 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20780 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20781 : kvm->arch.xen_hvm_config.blob_size_32;
20782 u32 page_num = data & ~PAGE_MASK;
20783 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20784 if (n < msr_list.nmsrs)
20785 goto out;
20786 r = -EFAULT;
20787 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20788 + goto out;
20789 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20790 num_msrs_to_save * sizeof(u32)))
20791 goto out;
20792 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20793 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20794 struct kvm_interrupt *irq)
20795 {
20796 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
20797 + if (irq->irq >= KVM_NR_INTERRUPTS)
20798 return -EINVAL;
20799 if (irqchip_in_kernel(vcpu->kvm))
20800 return -ENXIO;
20801 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
20802 kvm_mmu_set_mmio_spte_mask(mask);
20803 }
20804
20805 -int kvm_arch_init(void *opaque)
20806 +int kvm_arch_init(const void *opaque)
20807 {
20808 int r;
20809 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20810 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20811 index 642d880..cc9ebac 100644
20812 --- a/arch/x86/lguest/boot.c
20813 +++ b/arch/x86/lguest/boot.c
20814 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20815
20816 static void set_lguest_basic_apic_ops(void)
20817 {
20818 - apic->read = lguest_apic_read;
20819 - apic->write = lguest_apic_write;
20820 - apic->icr_read = lguest_apic_icr_read;
20821 - apic->icr_write = lguest_apic_icr_write;
20822 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20823 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20824 + *(void **)&apic->read = lguest_apic_read;
20825 + *(void **)&apic->write = lguest_apic_write;
20826 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20827 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20828 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20829 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20830 };
20831 #endif
20832
20833 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20834 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20835 * Launcher to reboot us.
20836 */
20837 -static void lguest_restart(char *reason)
20838 +static __noreturn void lguest_restart(char *reason)
20839 {
20840 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20841 + BUG();
20842 }
20843
20844 /*G:050
20845 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20846 index 00933d5..3a64af9 100644
20847 --- a/arch/x86/lib/atomic64_386_32.S
20848 +++ b/arch/x86/lib/atomic64_386_32.S
20849 @@ -48,6 +48,10 @@ BEGIN(read)
20850 movl (v), %eax
20851 movl 4(v), %edx
20852 RET_ENDP
20853 +BEGIN(read_unchecked)
20854 + movl (v), %eax
20855 + movl 4(v), %edx
20856 +RET_ENDP
20857 #undef v
20858
20859 #define v %esi
20860 @@ -55,6 +59,10 @@ BEGIN(set)
20861 movl %ebx, (v)
20862 movl %ecx, 4(v)
20863 RET_ENDP
20864 +BEGIN(set_unchecked)
20865 + movl %ebx, (v)
20866 + movl %ecx, 4(v)
20867 +RET_ENDP
20868 #undef v
20869
20870 #define v %esi
20871 @@ -70,6 +78,20 @@ RET_ENDP
20872 BEGIN(add)
20873 addl %eax, (v)
20874 adcl %edx, 4(v)
20875 +
20876 +#ifdef CONFIG_PAX_REFCOUNT
20877 + jno 0f
20878 + subl %eax, (v)
20879 + sbbl %edx, 4(v)
20880 + int $4
20881 +0:
20882 + _ASM_EXTABLE(0b, 0b)
20883 +#endif
20884 +
20885 +RET_ENDP
20886 +BEGIN(add_unchecked)
20887 + addl %eax, (v)
20888 + adcl %edx, 4(v)
20889 RET_ENDP
20890 #undef v
20891
20892 @@ -77,6 +99,24 @@ RET_ENDP
20893 BEGIN(add_return)
20894 addl (v), %eax
20895 adcl 4(v), %edx
20896 +
20897 +#ifdef CONFIG_PAX_REFCOUNT
20898 + into
20899 +1234:
20900 + _ASM_EXTABLE(1234b, 2f)
20901 +#endif
20902 +
20903 + movl %eax, (v)
20904 + movl %edx, 4(v)
20905 +
20906 +#ifdef CONFIG_PAX_REFCOUNT
20907 +2:
20908 +#endif
20909 +
20910 +RET_ENDP
20911 +BEGIN(add_return_unchecked)
20912 + addl (v), %eax
20913 + adcl 4(v), %edx
20914 movl %eax, (v)
20915 movl %edx, 4(v)
20916 RET_ENDP
20917 @@ -86,6 +126,20 @@ RET_ENDP
20918 BEGIN(sub)
20919 subl %eax, (v)
20920 sbbl %edx, 4(v)
20921 +
20922 +#ifdef CONFIG_PAX_REFCOUNT
20923 + jno 0f
20924 + addl %eax, (v)
20925 + adcl %edx, 4(v)
20926 + int $4
20927 +0:
20928 + _ASM_EXTABLE(0b, 0b)
20929 +#endif
20930 +
20931 +RET_ENDP
20932 +BEGIN(sub_unchecked)
20933 + subl %eax, (v)
20934 + sbbl %edx, 4(v)
20935 RET_ENDP
20936 #undef v
20937
20938 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20939 sbbl $0, %edx
20940 addl (v), %eax
20941 adcl 4(v), %edx
20942 +
20943 +#ifdef CONFIG_PAX_REFCOUNT
20944 + into
20945 +1234:
20946 + _ASM_EXTABLE(1234b, 2f)
20947 +#endif
20948 +
20949 + movl %eax, (v)
20950 + movl %edx, 4(v)
20951 +
20952 +#ifdef CONFIG_PAX_REFCOUNT
20953 +2:
20954 +#endif
20955 +
20956 +RET_ENDP
20957 +BEGIN(sub_return_unchecked)
20958 + negl %edx
20959 + negl %eax
20960 + sbbl $0, %edx
20961 + addl (v), %eax
20962 + adcl 4(v), %edx
20963 movl %eax, (v)
20964 movl %edx, 4(v)
20965 RET_ENDP
20966 @@ -105,6 +180,20 @@ RET_ENDP
20967 BEGIN(inc)
20968 addl $1, (v)
20969 adcl $0, 4(v)
20970 +
20971 +#ifdef CONFIG_PAX_REFCOUNT
20972 + jno 0f
20973 + subl $1, (v)
20974 + sbbl $0, 4(v)
20975 + int $4
20976 +0:
20977 + _ASM_EXTABLE(0b, 0b)
20978 +#endif
20979 +
20980 +RET_ENDP
20981 +BEGIN(inc_unchecked)
20982 + addl $1, (v)
20983 + adcl $0, 4(v)
20984 RET_ENDP
20985 #undef v
20986
20987 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20988 movl 4(v), %edx
20989 addl $1, %eax
20990 adcl $0, %edx
20991 +
20992 +#ifdef CONFIG_PAX_REFCOUNT
20993 + into
20994 +1234:
20995 + _ASM_EXTABLE(1234b, 2f)
20996 +#endif
20997 +
20998 + movl %eax, (v)
20999 + movl %edx, 4(v)
21000 +
21001 +#ifdef CONFIG_PAX_REFCOUNT
21002 +2:
21003 +#endif
21004 +
21005 +RET_ENDP
21006 +BEGIN(inc_return_unchecked)
21007 + movl (v), %eax
21008 + movl 4(v), %edx
21009 + addl $1, %eax
21010 + adcl $0, %edx
21011 movl %eax, (v)
21012 movl %edx, 4(v)
21013 RET_ENDP
21014 @@ -123,6 +232,20 @@ RET_ENDP
21015 BEGIN(dec)
21016 subl $1, (v)
21017 sbbl $0, 4(v)
21018 +
21019 +#ifdef CONFIG_PAX_REFCOUNT
21020 + jno 0f
21021 + addl $1, (v)
21022 + adcl $0, 4(v)
21023 + int $4
21024 +0:
21025 + _ASM_EXTABLE(0b, 0b)
21026 +#endif
21027 +
21028 +RET_ENDP
21029 +BEGIN(dec_unchecked)
21030 + subl $1, (v)
21031 + sbbl $0, 4(v)
21032 RET_ENDP
21033 #undef v
21034
21035 @@ -132,6 +255,26 @@ BEGIN(dec_return)
21036 movl 4(v), %edx
21037 subl $1, %eax
21038 sbbl $0, %edx
21039 +
21040 +#ifdef CONFIG_PAX_REFCOUNT
21041 + into
21042 +1234:
21043 + _ASM_EXTABLE(1234b, 2f)
21044 +#endif
21045 +
21046 + movl %eax, (v)
21047 + movl %edx, 4(v)
21048 +
21049 +#ifdef CONFIG_PAX_REFCOUNT
21050 +2:
21051 +#endif
21052 +
21053 +RET_ENDP
21054 +BEGIN(dec_return_unchecked)
21055 + movl (v), %eax
21056 + movl 4(v), %edx
21057 + subl $1, %eax
21058 + sbbl $0, %edx
21059 movl %eax, (v)
21060 movl %edx, 4(v)
21061 RET_ENDP
21062 @@ -143,6 +286,13 @@ BEGIN(add_unless)
21063 adcl %edx, %edi
21064 addl (v), %eax
21065 adcl 4(v), %edx
21066 +
21067 +#ifdef CONFIG_PAX_REFCOUNT
21068 + into
21069 +1234:
21070 + _ASM_EXTABLE(1234b, 2f)
21071 +#endif
21072 +
21073 cmpl %eax, %ecx
21074 je 3f
21075 1:
21076 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21077 1:
21078 addl $1, %eax
21079 adcl $0, %edx
21080 +
21081 +#ifdef CONFIG_PAX_REFCOUNT
21082 + into
21083 +1234:
21084 + _ASM_EXTABLE(1234b, 2f)
21085 +#endif
21086 +
21087 movl %eax, (v)
21088 movl %edx, 4(v)
21089 movl $1, %eax
21090 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21091 movl 4(v), %edx
21092 subl $1, %eax
21093 sbbl $0, %edx
21094 +
21095 +#ifdef CONFIG_PAX_REFCOUNT
21096 + into
21097 +1234:
21098 + _ASM_EXTABLE(1234b, 1f)
21099 +#endif
21100 +
21101 js 1f
21102 movl %eax, (v)
21103 movl %edx, 4(v)
21104 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21105 index f5cc9eb..51fa319 100644
21106 --- a/arch/x86/lib/atomic64_cx8_32.S
21107 +++ b/arch/x86/lib/atomic64_cx8_32.S
21108 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21109 CFI_STARTPROC
21110
21111 read64 %ecx
21112 + pax_force_retaddr
21113 ret
21114 CFI_ENDPROC
21115 ENDPROC(atomic64_read_cx8)
21116
21117 +ENTRY(atomic64_read_unchecked_cx8)
21118 + CFI_STARTPROC
21119 +
21120 + read64 %ecx
21121 + pax_force_retaddr
21122 + ret
21123 + CFI_ENDPROC
21124 +ENDPROC(atomic64_read_unchecked_cx8)
21125 +
21126 ENTRY(atomic64_set_cx8)
21127 CFI_STARTPROC
21128
21129 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21130 cmpxchg8b (%esi)
21131 jne 1b
21132
21133 + pax_force_retaddr
21134 ret
21135 CFI_ENDPROC
21136 ENDPROC(atomic64_set_cx8)
21137
21138 +ENTRY(atomic64_set_unchecked_cx8)
21139 + CFI_STARTPROC
21140 +
21141 +1:
21142 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21143 + * are atomic on 586 and newer */
21144 + cmpxchg8b (%esi)
21145 + jne 1b
21146 +
21147 + pax_force_retaddr
21148 + ret
21149 + CFI_ENDPROC
21150 +ENDPROC(atomic64_set_unchecked_cx8)
21151 +
21152 ENTRY(atomic64_xchg_cx8)
21153 CFI_STARTPROC
21154
21155 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21156 cmpxchg8b (%esi)
21157 jne 1b
21158
21159 + pax_force_retaddr
21160 ret
21161 CFI_ENDPROC
21162 ENDPROC(atomic64_xchg_cx8)
21163
21164 -.macro addsub_return func ins insc
21165 -ENTRY(atomic64_\func\()_return_cx8)
21166 +.macro addsub_return func ins insc unchecked=""
21167 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21168 CFI_STARTPROC
21169 SAVE ebp
21170 SAVE ebx
21171 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21172 movl %edx, %ecx
21173 \ins\()l %esi, %ebx
21174 \insc\()l %edi, %ecx
21175 +
21176 +.ifb \unchecked
21177 +#ifdef CONFIG_PAX_REFCOUNT
21178 + into
21179 +2:
21180 + _ASM_EXTABLE(2b, 3f)
21181 +#endif
21182 +.endif
21183 +
21184 LOCK_PREFIX
21185 cmpxchg8b (%ebp)
21186 jne 1b
21187 -
21188 -10:
21189 movl %ebx, %eax
21190 movl %ecx, %edx
21191 +
21192 +.ifb \unchecked
21193 +#ifdef CONFIG_PAX_REFCOUNT
21194 +3:
21195 +#endif
21196 +.endif
21197 +
21198 RESTORE edi
21199 RESTORE esi
21200 RESTORE ebx
21201 RESTORE ebp
21202 + pax_force_retaddr
21203 ret
21204 CFI_ENDPROC
21205 -ENDPROC(atomic64_\func\()_return_cx8)
21206 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21207 .endm
21208
21209 addsub_return add add adc
21210 addsub_return sub sub sbb
21211 +addsub_return add add adc _unchecked
21212 +addsub_return sub sub sbb _unchecked
21213
21214 -.macro incdec_return func ins insc
21215 -ENTRY(atomic64_\func\()_return_cx8)
21216 +.macro incdec_return func ins insc unchecked=""
21217 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21218 CFI_STARTPROC
21219 SAVE ebx
21220
21221 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21222 movl %edx, %ecx
21223 \ins\()l $1, %ebx
21224 \insc\()l $0, %ecx
21225 +
21226 +.ifb \unchecked
21227 +#ifdef CONFIG_PAX_REFCOUNT
21228 + into
21229 +2:
21230 + _ASM_EXTABLE(2b, 3f)
21231 +#endif
21232 +.endif
21233 +
21234 LOCK_PREFIX
21235 cmpxchg8b (%esi)
21236 jne 1b
21237
21238 -10:
21239 movl %ebx, %eax
21240 movl %ecx, %edx
21241 +
21242 +.ifb \unchecked
21243 +#ifdef CONFIG_PAX_REFCOUNT
21244 +3:
21245 +#endif
21246 +.endif
21247 +
21248 RESTORE ebx
21249 + pax_force_retaddr
21250 ret
21251 CFI_ENDPROC
21252 -ENDPROC(atomic64_\func\()_return_cx8)
21253 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21254 .endm
21255
21256 incdec_return inc add adc
21257 incdec_return dec sub sbb
21258 +incdec_return inc add adc _unchecked
21259 +incdec_return dec sub sbb _unchecked
21260
21261 ENTRY(atomic64_dec_if_positive_cx8)
21262 CFI_STARTPROC
21263 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21264 movl %edx, %ecx
21265 subl $1, %ebx
21266 sbb $0, %ecx
21267 +
21268 +#ifdef CONFIG_PAX_REFCOUNT
21269 + into
21270 +1234:
21271 + _ASM_EXTABLE(1234b, 2f)
21272 +#endif
21273 +
21274 js 2f
21275 LOCK_PREFIX
21276 cmpxchg8b (%esi)
21277 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21278 movl %ebx, %eax
21279 movl %ecx, %edx
21280 RESTORE ebx
21281 + pax_force_retaddr
21282 ret
21283 CFI_ENDPROC
21284 ENDPROC(atomic64_dec_if_positive_cx8)
21285 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21286 movl %edx, %ecx
21287 addl %ebp, %ebx
21288 adcl %edi, %ecx
21289 +
21290 +#ifdef CONFIG_PAX_REFCOUNT
21291 + into
21292 +1234:
21293 + _ASM_EXTABLE(1234b, 3f)
21294 +#endif
21295 +
21296 LOCK_PREFIX
21297 cmpxchg8b (%esi)
21298 jne 1b
21299 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21300 CFI_ADJUST_CFA_OFFSET -8
21301 RESTORE ebx
21302 RESTORE ebp
21303 + pax_force_retaddr
21304 ret
21305 4:
21306 cmpl %edx, 4(%esp)
21307 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21308 xorl %ecx, %ecx
21309 addl $1, %ebx
21310 adcl %edx, %ecx
21311 +
21312 +#ifdef CONFIG_PAX_REFCOUNT
21313 + into
21314 +1234:
21315 + _ASM_EXTABLE(1234b, 3f)
21316 +#endif
21317 +
21318 LOCK_PREFIX
21319 cmpxchg8b (%esi)
21320 jne 1b
21321 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21322 movl $1, %eax
21323 3:
21324 RESTORE ebx
21325 + pax_force_retaddr
21326 ret
21327 CFI_ENDPROC
21328 ENDPROC(atomic64_inc_not_zero_cx8)
21329 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21330 index 2af5df3..62b1a5a 100644
21331 --- a/arch/x86/lib/checksum_32.S
21332 +++ b/arch/x86/lib/checksum_32.S
21333 @@ -29,7 +29,8 @@
21334 #include <asm/dwarf2.h>
21335 #include <asm/errno.h>
21336 #include <asm/asm.h>
21337 -
21338 +#include <asm/segment.h>
21339 +
21340 /*
21341 * computes a partial checksum, e.g. for TCP/UDP fragments
21342 */
21343 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21344
21345 #define ARGBASE 16
21346 #define FP 12
21347 -
21348 -ENTRY(csum_partial_copy_generic)
21349 +
21350 +ENTRY(csum_partial_copy_generic_to_user)
21351 CFI_STARTPROC
21352 +
21353 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21354 + pushl_cfi %gs
21355 + popl_cfi %es
21356 + jmp csum_partial_copy_generic
21357 +#endif
21358 +
21359 +ENTRY(csum_partial_copy_generic_from_user)
21360 +
21361 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21362 + pushl_cfi %gs
21363 + popl_cfi %ds
21364 +#endif
21365 +
21366 +ENTRY(csum_partial_copy_generic)
21367 subl $4,%esp
21368 CFI_ADJUST_CFA_OFFSET 4
21369 pushl_cfi %edi
21370 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21371 jmp 4f
21372 SRC(1: movw (%esi), %bx )
21373 addl $2, %esi
21374 -DST( movw %bx, (%edi) )
21375 +DST( movw %bx, %es:(%edi) )
21376 addl $2, %edi
21377 addw %bx, %ax
21378 adcl $0, %eax
21379 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21380 SRC(1: movl (%esi), %ebx )
21381 SRC( movl 4(%esi), %edx )
21382 adcl %ebx, %eax
21383 -DST( movl %ebx, (%edi) )
21384 +DST( movl %ebx, %es:(%edi) )
21385 adcl %edx, %eax
21386 -DST( movl %edx, 4(%edi) )
21387 +DST( movl %edx, %es:4(%edi) )
21388
21389 SRC( movl 8(%esi), %ebx )
21390 SRC( movl 12(%esi), %edx )
21391 adcl %ebx, %eax
21392 -DST( movl %ebx, 8(%edi) )
21393 +DST( movl %ebx, %es:8(%edi) )
21394 adcl %edx, %eax
21395 -DST( movl %edx, 12(%edi) )
21396 +DST( movl %edx, %es:12(%edi) )
21397
21398 SRC( movl 16(%esi), %ebx )
21399 SRC( movl 20(%esi), %edx )
21400 adcl %ebx, %eax
21401 -DST( movl %ebx, 16(%edi) )
21402 +DST( movl %ebx, %es:16(%edi) )
21403 adcl %edx, %eax
21404 -DST( movl %edx, 20(%edi) )
21405 +DST( movl %edx, %es:20(%edi) )
21406
21407 SRC( movl 24(%esi), %ebx )
21408 SRC( movl 28(%esi), %edx )
21409 adcl %ebx, %eax
21410 -DST( movl %ebx, 24(%edi) )
21411 +DST( movl %ebx, %es:24(%edi) )
21412 adcl %edx, %eax
21413 -DST( movl %edx, 28(%edi) )
21414 +DST( movl %edx, %es:28(%edi) )
21415
21416 lea 32(%esi), %esi
21417 lea 32(%edi), %edi
21418 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21419 shrl $2, %edx # This clears CF
21420 SRC(3: movl (%esi), %ebx )
21421 adcl %ebx, %eax
21422 -DST( movl %ebx, (%edi) )
21423 +DST( movl %ebx, %es:(%edi) )
21424 lea 4(%esi), %esi
21425 lea 4(%edi), %edi
21426 dec %edx
21427 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21428 jb 5f
21429 SRC( movw (%esi), %cx )
21430 leal 2(%esi), %esi
21431 -DST( movw %cx, (%edi) )
21432 +DST( movw %cx, %es:(%edi) )
21433 leal 2(%edi), %edi
21434 je 6f
21435 shll $16,%ecx
21436 SRC(5: movb (%esi), %cl )
21437 -DST( movb %cl, (%edi) )
21438 +DST( movb %cl, %es:(%edi) )
21439 6: addl %ecx, %eax
21440 adcl $0, %eax
21441 7:
21442 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21443
21444 6001:
21445 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21446 - movl $-EFAULT, (%ebx)
21447 + movl $-EFAULT, %ss:(%ebx)
21448
21449 # zero the complete destination - computing the rest
21450 # is too much work
21451 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21452
21453 6002:
21454 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21455 - movl $-EFAULT,(%ebx)
21456 + movl $-EFAULT,%ss:(%ebx)
21457 jmp 5000b
21458
21459 .previous
21460
21461 + pushl_cfi %ss
21462 + popl_cfi %ds
21463 + pushl_cfi %ss
21464 + popl_cfi %es
21465 popl_cfi %ebx
21466 CFI_RESTORE ebx
21467 popl_cfi %esi
21468 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21469 popl_cfi %ecx # equivalent to addl $4,%esp
21470 ret
21471 CFI_ENDPROC
21472 -ENDPROC(csum_partial_copy_generic)
21473 +ENDPROC(csum_partial_copy_generic_to_user)
21474
21475 #else
21476
21477 /* Version for PentiumII/PPro */
21478
21479 #define ROUND1(x) \
21480 + nop; nop; nop; \
21481 SRC(movl x(%esi), %ebx ) ; \
21482 addl %ebx, %eax ; \
21483 - DST(movl %ebx, x(%edi) ) ;
21484 + DST(movl %ebx, %es:x(%edi)) ;
21485
21486 #define ROUND(x) \
21487 + nop; nop; nop; \
21488 SRC(movl x(%esi), %ebx ) ; \
21489 adcl %ebx, %eax ; \
21490 - DST(movl %ebx, x(%edi) ) ;
21491 + DST(movl %ebx, %es:x(%edi)) ;
21492
21493 #define ARGBASE 12
21494 -
21495 -ENTRY(csum_partial_copy_generic)
21496 +
21497 +ENTRY(csum_partial_copy_generic_to_user)
21498 CFI_STARTPROC
21499 +
21500 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21501 + pushl_cfi %gs
21502 + popl_cfi %es
21503 + jmp csum_partial_copy_generic
21504 +#endif
21505 +
21506 +ENTRY(csum_partial_copy_generic_from_user)
21507 +
21508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21509 + pushl_cfi %gs
21510 + popl_cfi %ds
21511 +#endif
21512 +
21513 +ENTRY(csum_partial_copy_generic)
21514 pushl_cfi %ebx
21515 CFI_REL_OFFSET ebx, 0
21516 pushl_cfi %edi
21517 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21518 subl %ebx, %edi
21519 lea -1(%esi),%edx
21520 andl $-32,%edx
21521 - lea 3f(%ebx,%ebx), %ebx
21522 + lea 3f(%ebx,%ebx,2), %ebx
21523 testl %esi, %esi
21524 jmp *%ebx
21525 1: addl $64,%esi
21526 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21527 jb 5f
21528 SRC( movw (%esi), %dx )
21529 leal 2(%esi), %esi
21530 -DST( movw %dx, (%edi) )
21531 +DST( movw %dx, %es:(%edi) )
21532 leal 2(%edi), %edi
21533 je 6f
21534 shll $16,%edx
21535 5:
21536 SRC( movb (%esi), %dl )
21537 -DST( movb %dl, (%edi) )
21538 +DST( movb %dl, %es:(%edi) )
21539 6: addl %edx, %eax
21540 adcl $0, %eax
21541 7:
21542 .section .fixup, "ax"
21543 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21544 - movl $-EFAULT, (%ebx)
21545 + movl $-EFAULT, %ss:(%ebx)
21546 # zero the complete destination (computing the rest is too much work)
21547 movl ARGBASE+8(%esp),%edi # dst
21548 movl ARGBASE+12(%esp),%ecx # len
21549 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21550 rep; stosb
21551 jmp 7b
21552 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21553 - movl $-EFAULT, (%ebx)
21554 + movl $-EFAULT, %ss:(%ebx)
21555 jmp 7b
21556 .previous
21557
21558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21559 + pushl_cfi %ss
21560 + popl_cfi %ds
21561 + pushl_cfi %ss
21562 + popl_cfi %es
21563 +#endif
21564 +
21565 popl_cfi %esi
21566 CFI_RESTORE esi
21567 popl_cfi %edi
21568 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21569 CFI_RESTORE ebx
21570 ret
21571 CFI_ENDPROC
21572 -ENDPROC(csum_partial_copy_generic)
21573 +ENDPROC(csum_partial_copy_generic_to_user)
21574
21575 #undef ROUND
21576 #undef ROUND1
21577 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21578 index f2145cf..cea889d 100644
21579 --- a/arch/x86/lib/clear_page_64.S
21580 +++ b/arch/x86/lib/clear_page_64.S
21581 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21582 movl $4096/8,%ecx
21583 xorl %eax,%eax
21584 rep stosq
21585 + pax_force_retaddr
21586 ret
21587 CFI_ENDPROC
21588 ENDPROC(clear_page_c)
21589 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21590 movl $4096,%ecx
21591 xorl %eax,%eax
21592 rep stosb
21593 + pax_force_retaddr
21594 ret
21595 CFI_ENDPROC
21596 ENDPROC(clear_page_c_e)
21597 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21598 leaq 64(%rdi),%rdi
21599 jnz .Lloop
21600 nop
21601 + pax_force_retaddr
21602 ret
21603 CFI_ENDPROC
21604 .Lclear_page_end:
21605 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21606
21607 #include <asm/cpufeature.h>
21608
21609 - .section .altinstr_replacement,"ax"
21610 + .section .altinstr_replacement,"a"
21611 1: .byte 0xeb /* jmp <disp8> */
21612 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21613 2: .byte 0xeb /* jmp <disp8> */
21614 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21615 index 1e572c5..2a162cd 100644
21616 --- a/arch/x86/lib/cmpxchg16b_emu.S
21617 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21618 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21619
21620 popf
21621 mov $1, %al
21622 + pax_force_retaddr
21623 ret
21624
21625 not_same:
21626 popf
21627 xor %al,%al
21628 + pax_force_retaddr
21629 ret
21630
21631 CFI_ENDPROC
21632 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21633 index 6b34d04..dccb07f 100644
21634 --- a/arch/x86/lib/copy_page_64.S
21635 +++ b/arch/x86/lib/copy_page_64.S
21636 @@ -9,6 +9,7 @@ copy_page_c:
21637 CFI_STARTPROC
21638 movl $4096/8,%ecx
21639 rep movsq
21640 + pax_force_retaddr
21641 ret
21642 CFI_ENDPROC
21643 ENDPROC(copy_page_c)
21644 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21645
21646 ENTRY(copy_page)
21647 CFI_STARTPROC
21648 - subq $2*8,%rsp
21649 - CFI_ADJUST_CFA_OFFSET 2*8
21650 + subq $3*8,%rsp
21651 + CFI_ADJUST_CFA_OFFSET 3*8
21652 movq %rbx,(%rsp)
21653 CFI_REL_OFFSET rbx, 0
21654 movq %r12,1*8(%rsp)
21655 CFI_REL_OFFSET r12, 1*8
21656 + movq %r13,2*8(%rsp)
21657 + CFI_REL_OFFSET r13, 2*8
21658
21659 movl $(4096/64)-5,%ecx
21660 .p2align 4
21661 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21662 movq 16 (%rsi), %rdx
21663 movq 24 (%rsi), %r8
21664 movq 32 (%rsi), %r9
21665 - movq 40 (%rsi), %r10
21666 + movq 40 (%rsi), %r13
21667 movq 48 (%rsi), %r11
21668 movq 56 (%rsi), %r12
21669
21670 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21671 movq %rdx, 16 (%rdi)
21672 movq %r8, 24 (%rdi)
21673 movq %r9, 32 (%rdi)
21674 - movq %r10, 40 (%rdi)
21675 + movq %r13, 40 (%rdi)
21676 movq %r11, 48 (%rdi)
21677 movq %r12, 56 (%rdi)
21678
21679 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21680 movq 16 (%rsi), %rdx
21681 movq 24 (%rsi), %r8
21682 movq 32 (%rsi), %r9
21683 - movq 40 (%rsi), %r10
21684 + movq 40 (%rsi), %r13
21685 movq 48 (%rsi), %r11
21686 movq 56 (%rsi), %r12
21687
21688 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21689 movq %rdx, 16 (%rdi)
21690 movq %r8, 24 (%rdi)
21691 movq %r9, 32 (%rdi)
21692 - movq %r10, 40 (%rdi)
21693 + movq %r13, 40 (%rdi)
21694 movq %r11, 48 (%rdi)
21695 movq %r12, 56 (%rdi)
21696
21697 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21698 CFI_RESTORE rbx
21699 movq 1*8(%rsp),%r12
21700 CFI_RESTORE r12
21701 - addq $2*8,%rsp
21702 - CFI_ADJUST_CFA_OFFSET -2*8
21703 + movq 2*8(%rsp),%r13
21704 + CFI_RESTORE r13
21705 + addq $3*8,%rsp
21706 + CFI_ADJUST_CFA_OFFSET -3*8
21707 + pax_force_retaddr
21708 ret
21709 .Lcopy_page_end:
21710 CFI_ENDPROC
21711 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21712
21713 #include <asm/cpufeature.h>
21714
21715 - .section .altinstr_replacement,"ax"
21716 + .section .altinstr_replacement,"a"
21717 1: .byte 0xeb /* jmp <disp8> */
21718 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21719 2:
21720 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21721 index a30ca15..d25fab6 100644
21722 --- a/arch/x86/lib/copy_user_64.S
21723 +++ b/arch/x86/lib/copy_user_64.S
21724 @@ -18,6 +18,7 @@
21725 #include <asm/alternative-asm.h>
21726 #include <asm/asm.h>
21727 #include <asm/smap.h>
21728 +#include <asm/pgtable.h>
21729
21730 /*
21731 * By placing feature2 after feature1 in altinstructions section, we logically
21732 @@ -31,7 +32,7 @@
21733 .byte 0xe9 /* 32bit jump */
21734 .long \orig-1f /* by default jump to orig */
21735 1:
21736 - .section .altinstr_replacement,"ax"
21737 + .section .altinstr_replacement,"a"
21738 2: .byte 0xe9 /* near jump with 32bit immediate */
21739 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21740 3: .byte 0xe9 /* near jump with 32bit immediate */
21741 @@ -70,47 +71,20 @@
21742 #endif
21743 .endm
21744
21745 -/* Standard copy_to_user with segment limit checking */
21746 -ENTRY(_copy_to_user)
21747 - CFI_STARTPROC
21748 - GET_THREAD_INFO(%rax)
21749 - movq %rdi,%rcx
21750 - addq %rdx,%rcx
21751 - jc bad_to_user
21752 - cmpq TI_addr_limit(%rax),%rcx
21753 - ja bad_to_user
21754 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21755 - copy_user_generic_unrolled,copy_user_generic_string, \
21756 - copy_user_enhanced_fast_string
21757 - CFI_ENDPROC
21758 -ENDPROC(_copy_to_user)
21759 -
21760 -/* Standard copy_from_user with segment limit checking */
21761 -ENTRY(_copy_from_user)
21762 - CFI_STARTPROC
21763 - GET_THREAD_INFO(%rax)
21764 - movq %rsi,%rcx
21765 - addq %rdx,%rcx
21766 - jc bad_from_user
21767 - cmpq TI_addr_limit(%rax),%rcx
21768 - ja bad_from_user
21769 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21770 - copy_user_generic_unrolled,copy_user_generic_string, \
21771 - copy_user_enhanced_fast_string
21772 - CFI_ENDPROC
21773 -ENDPROC(_copy_from_user)
21774 -
21775 .section .fixup,"ax"
21776 /* must zero dest */
21777 ENTRY(bad_from_user)
21778 bad_from_user:
21779 CFI_STARTPROC
21780 + testl %edx,%edx
21781 + js bad_to_user
21782 movl %edx,%ecx
21783 xorl %eax,%eax
21784 rep
21785 stosb
21786 bad_to_user:
21787 movl %edx,%eax
21788 + pax_force_retaddr
21789 ret
21790 CFI_ENDPROC
21791 ENDPROC(bad_from_user)
21792 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21793 jz 17f
21794 1: movq (%rsi),%r8
21795 2: movq 1*8(%rsi),%r9
21796 -3: movq 2*8(%rsi),%r10
21797 +3: movq 2*8(%rsi),%rax
21798 4: movq 3*8(%rsi),%r11
21799 5: movq %r8,(%rdi)
21800 6: movq %r9,1*8(%rdi)
21801 -7: movq %r10,2*8(%rdi)
21802 +7: movq %rax,2*8(%rdi)
21803 8: movq %r11,3*8(%rdi)
21804 9: movq 4*8(%rsi),%r8
21805 10: movq 5*8(%rsi),%r9
21806 -11: movq 6*8(%rsi),%r10
21807 +11: movq 6*8(%rsi),%rax
21808 12: movq 7*8(%rsi),%r11
21809 13: movq %r8,4*8(%rdi)
21810 14: movq %r9,5*8(%rdi)
21811 -15: movq %r10,6*8(%rdi)
21812 +15: movq %rax,6*8(%rdi)
21813 16: movq %r11,7*8(%rdi)
21814 leaq 64(%rsi),%rsi
21815 leaq 64(%rdi),%rdi
21816 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
21817 jnz 21b
21818 23: xor %eax,%eax
21819 ASM_CLAC
21820 + pax_force_retaddr
21821 ret
21822
21823 .section .fixup,"ax"
21824 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21825 movsb
21826 4: xorl %eax,%eax
21827 ASM_CLAC
21828 + pax_force_retaddr
21829 ret
21830
21831 .section .fixup,"ax"
21832 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
21833 movsb
21834 2: xorl %eax,%eax
21835 ASM_CLAC
21836 + pax_force_retaddr
21837 ret
21838
21839 .section .fixup,"ax"
21840 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21841 index 6a4f43c..f5f9e26 100644
21842 --- a/arch/x86/lib/copy_user_nocache_64.S
21843 +++ b/arch/x86/lib/copy_user_nocache_64.S
21844 @@ -8,6 +8,7 @@
21845
21846 #include <linux/linkage.h>
21847 #include <asm/dwarf2.h>
21848 +#include <asm/alternative-asm.h>
21849
21850 #define FIX_ALIGNMENT 1
21851
21852 @@ -16,6 +17,7 @@
21853 #include <asm/thread_info.h>
21854 #include <asm/asm.h>
21855 #include <asm/smap.h>
21856 +#include <asm/pgtable.h>
21857
21858 .macro ALIGN_DESTINATION
21859 #ifdef FIX_ALIGNMENT
21860 @@ -49,6 +51,15 @@
21861 */
21862 ENTRY(__copy_user_nocache)
21863 CFI_STARTPROC
21864 +
21865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21866 + mov $PAX_USER_SHADOW_BASE,%rcx
21867 + cmp %rcx,%rsi
21868 + jae 1f
21869 + add %rcx,%rsi
21870 +1:
21871 +#endif
21872 +
21873 ASM_STAC
21874 cmpl $8,%edx
21875 jb 20f /* less then 8 bytes, go to byte copy loop */
21876 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21877 jz 17f
21878 1: movq (%rsi),%r8
21879 2: movq 1*8(%rsi),%r9
21880 -3: movq 2*8(%rsi),%r10
21881 +3: movq 2*8(%rsi),%rax
21882 4: movq 3*8(%rsi),%r11
21883 5: movnti %r8,(%rdi)
21884 6: movnti %r9,1*8(%rdi)
21885 -7: movnti %r10,2*8(%rdi)
21886 +7: movnti %rax,2*8(%rdi)
21887 8: movnti %r11,3*8(%rdi)
21888 9: movq 4*8(%rsi),%r8
21889 10: movq 5*8(%rsi),%r9
21890 -11: movq 6*8(%rsi),%r10
21891 +11: movq 6*8(%rsi),%rax
21892 12: movq 7*8(%rsi),%r11
21893 13: movnti %r8,4*8(%rdi)
21894 14: movnti %r9,5*8(%rdi)
21895 -15: movnti %r10,6*8(%rdi)
21896 +15: movnti %rax,6*8(%rdi)
21897 16: movnti %r11,7*8(%rdi)
21898 leaq 64(%rsi),%rsi
21899 leaq 64(%rdi),%rdi
21900 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
21901 23: xorl %eax,%eax
21902 ASM_CLAC
21903 sfence
21904 + pax_force_retaddr
21905 ret
21906
21907 .section .fixup,"ax"
21908 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21909 index 2419d5f..953ee51 100644
21910 --- a/arch/x86/lib/csum-copy_64.S
21911 +++ b/arch/x86/lib/csum-copy_64.S
21912 @@ -9,6 +9,7 @@
21913 #include <asm/dwarf2.h>
21914 #include <asm/errno.h>
21915 #include <asm/asm.h>
21916 +#include <asm/alternative-asm.h>
21917
21918 /*
21919 * Checksum copy with exception handling.
21920 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21921 CFI_RESTORE rbp
21922 addq $7*8, %rsp
21923 CFI_ADJUST_CFA_OFFSET -7*8
21924 + pax_force_retaddr 0, 1
21925 ret
21926 CFI_RESTORE_STATE
21927
21928 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21929 index 25b7ae8..169fafc 100644
21930 --- a/arch/x86/lib/csum-wrappers_64.c
21931 +++ b/arch/x86/lib/csum-wrappers_64.c
21932 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21933 len -= 2;
21934 }
21935 }
21936 - isum = csum_partial_copy_generic((__force const void *)src,
21937 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
21938 dst, len, isum, errp, NULL);
21939 if (unlikely(*errp))
21940 goto out_err;
21941 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21942 }
21943
21944 *errp = 0;
21945 - return csum_partial_copy_generic(src, (void __force *)dst,
21946 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
21947 len, isum, NULL, errp);
21948 }
21949 EXPORT_SYMBOL(csum_partial_copy_to_user);
21950 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21951 index 156b9c8..b144132 100644
21952 --- a/arch/x86/lib/getuser.S
21953 +++ b/arch/x86/lib/getuser.S
21954 @@ -34,17 +34,40 @@
21955 #include <asm/thread_info.h>
21956 #include <asm/asm.h>
21957 #include <asm/smap.h>
21958 +#include <asm/segment.h>
21959 +#include <asm/pgtable.h>
21960 +#include <asm/alternative-asm.h>
21961 +
21962 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21963 +#define __copyuser_seg gs;
21964 +#else
21965 +#define __copyuser_seg
21966 +#endif
21967
21968 .text
21969 ENTRY(__get_user_1)
21970 CFI_STARTPROC
21971 +
21972 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21973 GET_THREAD_INFO(%_ASM_DX)
21974 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21975 jae bad_get_user
21976 ASM_STAC
21977 -1: movzb (%_ASM_AX),%edx
21978 +
21979 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21980 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21981 + cmp %_ASM_DX,%_ASM_AX
21982 + jae 1234f
21983 + add %_ASM_DX,%_ASM_AX
21984 +1234:
21985 +#endif
21986 +
21987 +#endif
21988 +
21989 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21990 xor %eax,%eax
21991 ASM_CLAC
21992 + pax_force_retaddr
21993 ret
21994 CFI_ENDPROC
21995 ENDPROC(__get_user_1)
21996 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
21997 ENTRY(__get_user_2)
21998 CFI_STARTPROC
21999 add $1,%_ASM_AX
22000 +
22001 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22002 jc bad_get_user
22003 GET_THREAD_INFO(%_ASM_DX)
22004 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22005 jae bad_get_user
22006 ASM_STAC
22007 -2: movzwl -1(%_ASM_AX),%edx
22008 +
22009 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22010 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22011 + cmp %_ASM_DX,%_ASM_AX
22012 + jae 1234f
22013 + add %_ASM_DX,%_ASM_AX
22014 +1234:
22015 +#endif
22016 +
22017 +#endif
22018 +
22019 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22020 xor %eax,%eax
22021 ASM_CLAC
22022 + pax_force_retaddr
22023 ret
22024 CFI_ENDPROC
22025 ENDPROC(__get_user_2)
22026 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
22027 ENTRY(__get_user_4)
22028 CFI_STARTPROC
22029 add $3,%_ASM_AX
22030 +
22031 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22032 jc bad_get_user
22033 GET_THREAD_INFO(%_ASM_DX)
22034 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22035 jae bad_get_user
22036 ASM_STAC
22037 -3: mov -3(%_ASM_AX),%edx
22038 +
22039 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22040 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22041 + cmp %_ASM_DX,%_ASM_AX
22042 + jae 1234f
22043 + add %_ASM_DX,%_ASM_AX
22044 +1234:
22045 +#endif
22046 +
22047 +#endif
22048 +
22049 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
22050 xor %eax,%eax
22051 ASM_CLAC
22052 + pax_force_retaddr
22053 ret
22054 CFI_ENDPROC
22055 ENDPROC(__get_user_4)
22056 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
22057 GET_THREAD_INFO(%_ASM_DX)
22058 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22059 jae bad_get_user
22060 +
22061 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22062 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22063 + cmp %_ASM_DX,%_ASM_AX
22064 + jae 1234f
22065 + add %_ASM_DX,%_ASM_AX
22066 +1234:
22067 +#endif
22068 +
22069 ASM_STAC
22070 4: movq -7(%_ASM_AX),%_ASM_DX
22071 xor %eax,%eax
22072 ASM_CLAC
22073 + pax_force_retaddr
22074 ret
22075 CFI_ENDPROC
22076 ENDPROC(__get_user_8)
22077 @@ -101,6 +162,7 @@ bad_get_user:
22078 xor %edx,%edx
22079 mov $(-EFAULT),%_ASM_AX
22080 ASM_CLAC
22081 + pax_force_retaddr
22082 ret
22083 CFI_ENDPROC
22084 END(bad_get_user)
22085 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22086 index 54fcffe..7be149e 100644
22087 --- a/arch/x86/lib/insn.c
22088 +++ b/arch/x86/lib/insn.c
22089 @@ -20,8 +20,10 @@
22090
22091 #ifdef __KERNEL__
22092 #include <linux/string.h>
22093 +#include <asm/pgtable_types.h>
22094 #else
22095 #include <string.h>
22096 +#define ktla_ktva(addr) addr
22097 #endif
22098 #include <asm/inat.h>
22099 #include <asm/insn.h>
22100 @@ -53,8 +55,8 @@
22101 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22102 {
22103 memset(insn, 0, sizeof(*insn));
22104 - insn->kaddr = kaddr;
22105 - insn->next_byte = kaddr;
22106 + insn->kaddr = ktla_ktva(kaddr);
22107 + insn->next_byte = ktla_ktva(kaddr);
22108 insn->x86_64 = x86_64 ? 1 : 0;
22109 insn->opnd_bytes = 4;
22110 if (x86_64)
22111 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22112 index 05a95e7..326f2fa 100644
22113 --- a/arch/x86/lib/iomap_copy_64.S
22114 +++ b/arch/x86/lib/iomap_copy_64.S
22115 @@ -17,6 +17,7 @@
22116
22117 #include <linux/linkage.h>
22118 #include <asm/dwarf2.h>
22119 +#include <asm/alternative-asm.h>
22120
22121 /*
22122 * override generic version in lib/iomap_copy.c
22123 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22124 CFI_STARTPROC
22125 movl %edx,%ecx
22126 rep movsd
22127 + pax_force_retaddr
22128 ret
22129 CFI_ENDPROC
22130 ENDPROC(__iowrite32_copy)
22131 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22132 index 1c273be..da9cc0e 100644
22133 --- a/arch/x86/lib/memcpy_64.S
22134 +++ b/arch/x86/lib/memcpy_64.S
22135 @@ -33,6 +33,7 @@
22136 rep movsq
22137 movl %edx, %ecx
22138 rep movsb
22139 + pax_force_retaddr
22140 ret
22141 .Lmemcpy_e:
22142 .previous
22143 @@ -49,6 +50,7 @@
22144 movq %rdi, %rax
22145 movq %rdx, %rcx
22146 rep movsb
22147 + pax_force_retaddr
22148 ret
22149 .Lmemcpy_e_e:
22150 .previous
22151 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22152 */
22153 movq 0*8(%rsi), %r8
22154 movq 1*8(%rsi), %r9
22155 - movq 2*8(%rsi), %r10
22156 + movq 2*8(%rsi), %rcx
22157 movq 3*8(%rsi), %r11
22158 leaq 4*8(%rsi), %rsi
22159
22160 movq %r8, 0*8(%rdi)
22161 movq %r9, 1*8(%rdi)
22162 - movq %r10, 2*8(%rdi)
22163 + movq %rcx, 2*8(%rdi)
22164 movq %r11, 3*8(%rdi)
22165 leaq 4*8(%rdi), %rdi
22166 jae .Lcopy_forward_loop
22167 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22168 subq $0x20, %rdx
22169 movq -1*8(%rsi), %r8
22170 movq -2*8(%rsi), %r9
22171 - movq -3*8(%rsi), %r10
22172 + movq -3*8(%rsi), %rcx
22173 movq -4*8(%rsi), %r11
22174 leaq -4*8(%rsi), %rsi
22175 movq %r8, -1*8(%rdi)
22176 movq %r9, -2*8(%rdi)
22177 - movq %r10, -3*8(%rdi)
22178 + movq %rcx, -3*8(%rdi)
22179 movq %r11, -4*8(%rdi)
22180 leaq -4*8(%rdi), %rdi
22181 jae .Lcopy_backward_loop
22182 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22183 */
22184 movq 0*8(%rsi), %r8
22185 movq 1*8(%rsi), %r9
22186 - movq -2*8(%rsi, %rdx), %r10
22187 + movq -2*8(%rsi, %rdx), %rcx
22188 movq -1*8(%rsi, %rdx), %r11
22189 movq %r8, 0*8(%rdi)
22190 movq %r9, 1*8(%rdi)
22191 - movq %r10, -2*8(%rdi, %rdx)
22192 + movq %rcx, -2*8(%rdi, %rdx)
22193 movq %r11, -1*8(%rdi, %rdx)
22194 + pax_force_retaddr
22195 retq
22196 .p2align 4
22197 .Lless_16bytes:
22198 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22199 movq -1*8(%rsi, %rdx), %r9
22200 movq %r8, 0*8(%rdi)
22201 movq %r9, -1*8(%rdi, %rdx)
22202 + pax_force_retaddr
22203 retq
22204 .p2align 4
22205 .Lless_8bytes:
22206 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22207 movl -4(%rsi, %rdx), %r8d
22208 movl %ecx, (%rdi)
22209 movl %r8d, -4(%rdi, %rdx)
22210 + pax_force_retaddr
22211 retq
22212 .p2align 4
22213 .Lless_3bytes:
22214 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22215 movb %cl, (%rdi)
22216
22217 .Lend:
22218 + pax_force_retaddr
22219 retq
22220 CFI_ENDPROC
22221 ENDPROC(memcpy)
22222 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22223 index ee16461..c39c199 100644
22224 --- a/arch/x86/lib/memmove_64.S
22225 +++ b/arch/x86/lib/memmove_64.S
22226 @@ -61,13 +61,13 @@ ENTRY(memmove)
22227 5:
22228 sub $0x20, %rdx
22229 movq 0*8(%rsi), %r11
22230 - movq 1*8(%rsi), %r10
22231 + movq 1*8(%rsi), %rcx
22232 movq 2*8(%rsi), %r9
22233 movq 3*8(%rsi), %r8
22234 leaq 4*8(%rsi), %rsi
22235
22236 movq %r11, 0*8(%rdi)
22237 - movq %r10, 1*8(%rdi)
22238 + movq %rcx, 1*8(%rdi)
22239 movq %r9, 2*8(%rdi)
22240 movq %r8, 3*8(%rdi)
22241 leaq 4*8(%rdi), %rdi
22242 @@ -81,10 +81,10 @@ ENTRY(memmove)
22243 4:
22244 movq %rdx, %rcx
22245 movq -8(%rsi, %rdx), %r11
22246 - lea -8(%rdi, %rdx), %r10
22247 + lea -8(%rdi, %rdx), %r9
22248 shrq $3, %rcx
22249 rep movsq
22250 - movq %r11, (%r10)
22251 + movq %r11, (%r9)
22252 jmp 13f
22253 .Lmemmove_end_forward:
22254
22255 @@ -95,14 +95,14 @@ ENTRY(memmove)
22256 7:
22257 movq %rdx, %rcx
22258 movq (%rsi), %r11
22259 - movq %rdi, %r10
22260 + movq %rdi, %r9
22261 leaq -8(%rsi, %rdx), %rsi
22262 leaq -8(%rdi, %rdx), %rdi
22263 shrq $3, %rcx
22264 std
22265 rep movsq
22266 cld
22267 - movq %r11, (%r10)
22268 + movq %r11, (%r9)
22269 jmp 13f
22270
22271 /*
22272 @@ -127,13 +127,13 @@ ENTRY(memmove)
22273 8:
22274 subq $0x20, %rdx
22275 movq -1*8(%rsi), %r11
22276 - movq -2*8(%rsi), %r10
22277 + movq -2*8(%rsi), %rcx
22278 movq -3*8(%rsi), %r9
22279 movq -4*8(%rsi), %r8
22280 leaq -4*8(%rsi), %rsi
22281
22282 movq %r11, -1*8(%rdi)
22283 - movq %r10, -2*8(%rdi)
22284 + movq %rcx, -2*8(%rdi)
22285 movq %r9, -3*8(%rdi)
22286 movq %r8, -4*8(%rdi)
22287 leaq -4*8(%rdi), %rdi
22288 @@ -151,11 +151,11 @@ ENTRY(memmove)
22289 * Move data from 16 bytes to 31 bytes.
22290 */
22291 movq 0*8(%rsi), %r11
22292 - movq 1*8(%rsi), %r10
22293 + movq 1*8(%rsi), %rcx
22294 movq -2*8(%rsi, %rdx), %r9
22295 movq -1*8(%rsi, %rdx), %r8
22296 movq %r11, 0*8(%rdi)
22297 - movq %r10, 1*8(%rdi)
22298 + movq %rcx, 1*8(%rdi)
22299 movq %r9, -2*8(%rdi, %rdx)
22300 movq %r8, -1*8(%rdi, %rdx)
22301 jmp 13f
22302 @@ -167,9 +167,9 @@ ENTRY(memmove)
22303 * Move data from 8 bytes to 15 bytes.
22304 */
22305 movq 0*8(%rsi), %r11
22306 - movq -1*8(%rsi, %rdx), %r10
22307 + movq -1*8(%rsi, %rdx), %r9
22308 movq %r11, 0*8(%rdi)
22309 - movq %r10, -1*8(%rdi, %rdx)
22310 + movq %r9, -1*8(%rdi, %rdx)
22311 jmp 13f
22312 10:
22313 cmpq $4, %rdx
22314 @@ -178,9 +178,9 @@ ENTRY(memmove)
22315 * Move data from 4 bytes to 7 bytes.
22316 */
22317 movl (%rsi), %r11d
22318 - movl -4(%rsi, %rdx), %r10d
22319 + movl -4(%rsi, %rdx), %r9d
22320 movl %r11d, (%rdi)
22321 - movl %r10d, -4(%rdi, %rdx)
22322 + movl %r9d, -4(%rdi, %rdx)
22323 jmp 13f
22324 11:
22325 cmp $2, %rdx
22326 @@ -189,9 +189,9 @@ ENTRY(memmove)
22327 * Move data from 2 bytes to 3 bytes.
22328 */
22329 movw (%rsi), %r11w
22330 - movw -2(%rsi, %rdx), %r10w
22331 + movw -2(%rsi, %rdx), %r9w
22332 movw %r11w, (%rdi)
22333 - movw %r10w, -2(%rdi, %rdx)
22334 + movw %r9w, -2(%rdi, %rdx)
22335 jmp 13f
22336 12:
22337 cmp $1, %rdx
22338 @@ -202,6 +202,7 @@ ENTRY(memmove)
22339 movb (%rsi), %r11b
22340 movb %r11b, (%rdi)
22341 13:
22342 + pax_force_retaddr
22343 retq
22344 CFI_ENDPROC
22345
22346 @@ -210,6 +211,7 @@ ENTRY(memmove)
22347 /* Forward moving data. */
22348 movq %rdx, %rcx
22349 rep movsb
22350 + pax_force_retaddr
22351 retq
22352 .Lmemmove_end_forward_efs:
22353 .previous
22354 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22355 index 2dcb380..963660a 100644
22356 --- a/arch/x86/lib/memset_64.S
22357 +++ b/arch/x86/lib/memset_64.S
22358 @@ -30,6 +30,7 @@
22359 movl %edx,%ecx
22360 rep stosb
22361 movq %r9,%rax
22362 + pax_force_retaddr
22363 ret
22364 .Lmemset_e:
22365 .previous
22366 @@ -52,6 +53,7 @@
22367 movq %rdx,%rcx
22368 rep stosb
22369 movq %r9,%rax
22370 + pax_force_retaddr
22371 ret
22372 .Lmemset_e_e:
22373 .previous
22374 @@ -59,7 +61,7 @@
22375 ENTRY(memset)
22376 ENTRY(__memset)
22377 CFI_STARTPROC
22378 - movq %rdi,%r10
22379 + movq %rdi,%r11
22380
22381 /* expand byte value */
22382 movzbl %sil,%ecx
22383 @@ -117,7 +119,8 @@ ENTRY(__memset)
22384 jnz .Lloop_1
22385
22386 .Lende:
22387 - movq %r10,%rax
22388 + movq %r11,%rax
22389 + pax_force_retaddr
22390 ret
22391
22392 CFI_RESTORE_STATE
22393 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22394 index c9f2d9b..e7fd2c0 100644
22395 --- a/arch/x86/lib/mmx_32.c
22396 +++ b/arch/x86/lib/mmx_32.c
22397 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22398 {
22399 void *p;
22400 int i;
22401 + unsigned long cr0;
22402
22403 if (unlikely(in_interrupt()))
22404 return __memcpy(to, from, len);
22405 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22406 kernel_fpu_begin();
22407
22408 __asm__ __volatile__ (
22409 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22410 - " prefetch 64(%0)\n"
22411 - " prefetch 128(%0)\n"
22412 - " prefetch 192(%0)\n"
22413 - " prefetch 256(%0)\n"
22414 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22415 + " prefetch 64(%1)\n"
22416 + " prefetch 128(%1)\n"
22417 + " prefetch 192(%1)\n"
22418 + " prefetch 256(%1)\n"
22419 "2: \n"
22420 ".section .fixup, \"ax\"\n"
22421 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22422 + "3: \n"
22423 +
22424 +#ifdef CONFIG_PAX_KERNEXEC
22425 + " movl %%cr0, %0\n"
22426 + " movl %0, %%eax\n"
22427 + " andl $0xFFFEFFFF, %%eax\n"
22428 + " movl %%eax, %%cr0\n"
22429 +#endif
22430 +
22431 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22432 +
22433 +#ifdef CONFIG_PAX_KERNEXEC
22434 + " movl %0, %%cr0\n"
22435 +#endif
22436 +
22437 " jmp 2b\n"
22438 ".previous\n"
22439 _ASM_EXTABLE(1b, 3b)
22440 - : : "r" (from));
22441 + : "=&r" (cr0) : "r" (from) : "ax");
22442
22443 for ( ; i > 5; i--) {
22444 __asm__ __volatile__ (
22445 - "1: prefetch 320(%0)\n"
22446 - "2: movq (%0), %%mm0\n"
22447 - " movq 8(%0), %%mm1\n"
22448 - " movq 16(%0), %%mm2\n"
22449 - " movq 24(%0), %%mm3\n"
22450 - " movq %%mm0, (%1)\n"
22451 - " movq %%mm1, 8(%1)\n"
22452 - " movq %%mm2, 16(%1)\n"
22453 - " movq %%mm3, 24(%1)\n"
22454 - " movq 32(%0), %%mm0\n"
22455 - " movq 40(%0), %%mm1\n"
22456 - " movq 48(%0), %%mm2\n"
22457 - " movq 56(%0), %%mm3\n"
22458 - " movq %%mm0, 32(%1)\n"
22459 - " movq %%mm1, 40(%1)\n"
22460 - " movq %%mm2, 48(%1)\n"
22461 - " movq %%mm3, 56(%1)\n"
22462 + "1: prefetch 320(%1)\n"
22463 + "2: movq (%1), %%mm0\n"
22464 + " movq 8(%1), %%mm1\n"
22465 + " movq 16(%1), %%mm2\n"
22466 + " movq 24(%1), %%mm3\n"
22467 + " movq %%mm0, (%2)\n"
22468 + " movq %%mm1, 8(%2)\n"
22469 + " movq %%mm2, 16(%2)\n"
22470 + " movq %%mm3, 24(%2)\n"
22471 + " movq 32(%1), %%mm0\n"
22472 + " movq 40(%1), %%mm1\n"
22473 + " movq 48(%1), %%mm2\n"
22474 + " movq 56(%1), %%mm3\n"
22475 + " movq %%mm0, 32(%2)\n"
22476 + " movq %%mm1, 40(%2)\n"
22477 + " movq %%mm2, 48(%2)\n"
22478 + " movq %%mm3, 56(%2)\n"
22479 ".section .fixup, \"ax\"\n"
22480 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22481 + "3:\n"
22482 +
22483 +#ifdef CONFIG_PAX_KERNEXEC
22484 + " movl %%cr0, %0\n"
22485 + " movl %0, %%eax\n"
22486 + " andl $0xFFFEFFFF, %%eax\n"
22487 + " movl %%eax, %%cr0\n"
22488 +#endif
22489 +
22490 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22491 +
22492 +#ifdef CONFIG_PAX_KERNEXEC
22493 + " movl %0, %%cr0\n"
22494 +#endif
22495 +
22496 " jmp 2b\n"
22497 ".previous\n"
22498 _ASM_EXTABLE(1b, 3b)
22499 - : : "r" (from), "r" (to) : "memory");
22500 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22501
22502 from += 64;
22503 to += 64;
22504 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22505 static void fast_copy_page(void *to, void *from)
22506 {
22507 int i;
22508 + unsigned long cr0;
22509
22510 kernel_fpu_begin();
22511
22512 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22513 * but that is for later. -AV
22514 */
22515 __asm__ __volatile__(
22516 - "1: prefetch (%0)\n"
22517 - " prefetch 64(%0)\n"
22518 - " prefetch 128(%0)\n"
22519 - " prefetch 192(%0)\n"
22520 - " prefetch 256(%0)\n"
22521 + "1: prefetch (%1)\n"
22522 + " prefetch 64(%1)\n"
22523 + " prefetch 128(%1)\n"
22524 + " prefetch 192(%1)\n"
22525 + " prefetch 256(%1)\n"
22526 "2: \n"
22527 ".section .fixup, \"ax\"\n"
22528 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22529 + "3: \n"
22530 +
22531 +#ifdef CONFIG_PAX_KERNEXEC
22532 + " movl %%cr0, %0\n"
22533 + " movl %0, %%eax\n"
22534 + " andl $0xFFFEFFFF, %%eax\n"
22535 + " movl %%eax, %%cr0\n"
22536 +#endif
22537 +
22538 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22539 +
22540 +#ifdef CONFIG_PAX_KERNEXEC
22541 + " movl %0, %%cr0\n"
22542 +#endif
22543 +
22544 " jmp 2b\n"
22545 ".previous\n"
22546 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22547 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22548
22549 for (i = 0; i < (4096-320)/64; i++) {
22550 __asm__ __volatile__ (
22551 - "1: prefetch 320(%0)\n"
22552 - "2: movq (%0), %%mm0\n"
22553 - " movntq %%mm0, (%1)\n"
22554 - " movq 8(%0), %%mm1\n"
22555 - " movntq %%mm1, 8(%1)\n"
22556 - " movq 16(%0), %%mm2\n"
22557 - " movntq %%mm2, 16(%1)\n"
22558 - " movq 24(%0), %%mm3\n"
22559 - " movntq %%mm3, 24(%1)\n"
22560 - " movq 32(%0), %%mm4\n"
22561 - " movntq %%mm4, 32(%1)\n"
22562 - " movq 40(%0), %%mm5\n"
22563 - " movntq %%mm5, 40(%1)\n"
22564 - " movq 48(%0), %%mm6\n"
22565 - " movntq %%mm6, 48(%1)\n"
22566 - " movq 56(%0), %%mm7\n"
22567 - " movntq %%mm7, 56(%1)\n"
22568 + "1: prefetch 320(%1)\n"
22569 + "2: movq (%1), %%mm0\n"
22570 + " movntq %%mm0, (%2)\n"
22571 + " movq 8(%1), %%mm1\n"
22572 + " movntq %%mm1, 8(%2)\n"
22573 + " movq 16(%1), %%mm2\n"
22574 + " movntq %%mm2, 16(%2)\n"
22575 + " movq 24(%1), %%mm3\n"
22576 + " movntq %%mm3, 24(%2)\n"
22577 + " movq 32(%1), %%mm4\n"
22578 + " movntq %%mm4, 32(%2)\n"
22579 + " movq 40(%1), %%mm5\n"
22580 + " movntq %%mm5, 40(%2)\n"
22581 + " movq 48(%1), %%mm6\n"
22582 + " movntq %%mm6, 48(%2)\n"
22583 + " movq 56(%1), %%mm7\n"
22584 + " movntq %%mm7, 56(%2)\n"
22585 ".section .fixup, \"ax\"\n"
22586 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22587 + "3:\n"
22588 +
22589 +#ifdef CONFIG_PAX_KERNEXEC
22590 + " movl %%cr0, %0\n"
22591 + " movl %0, %%eax\n"
22592 + " andl $0xFFFEFFFF, %%eax\n"
22593 + " movl %%eax, %%cr0\n"
22594 +#endif
22595 +
22596 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22597 +
22598 +#ifdef CONFIG_PAX_KERNEXEC
22599 + " movl %0, %%cr0\n"
22600 +#endif
22601 +
22602 " jmp 2b\n"
22603 ".previous\n"
22604 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22605 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22606
22607 from += 64;
22608 to += 64;
22609 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22610 static void fast_copy_page(void *to, void *from)
22611 {
22612 int i;
22613 + unsigned long cr0;
22614
22615 kernel_fpu_begin();
22616
22617 __asm__ __volatile__ (
22618 - "1: prefetch (%0)\n"
22619 - " prefetch 64(%0)\n"
22620 - " prefetch 128(%0)\n"
22621 - " prefetch 192(%0)\n"
22622 - " prefetch 256(%0)\n"
22623 + "1: prefetch (%1)\n"
22624 + " prefetch 64(%1)\n"
22625 + " prefetch 128(%1)\n"
22626 + " prefetch 192(%1)\n"
22627 + " prefetch 256(%1)\n"
22628 "2: \n"
22629 ".section .fixup, \"ax\"\n"
22630 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22631 + "3: \n"
22632 +
22633 +#ifdef CONFIG_PAX_KERNEXEC
22634 + " movl %%cr0, %0\n"
22635 + " movl %0, %%eax\n"
22636 + " andl $0xFFFEFFFF, %%eax\n"
22637 + " movl %%eax, %%cr0\n"
22638 +#endif
22639 +
22640 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22641 +
22642 +#ifdef CONFIG_PAX_KERNEXEC
22643 + " movl %0, %%cr0\n"
22644 +#endif
22645 +
22646 " jmp 2b\n"
22647 ".previous\n"
22648 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22649 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22650
22651 for (i = 0; i < 4096/64; i++) {
22652 __asm__ __volatile__ (
22653 - "1: prefetch 320(%0)\n"
22654 - "2: movq (%0), %%mm0\n"
22655 - " movq 8(%0), %%mm1\n"
22656 - " movq 16(%0), %%mm2\n"
22657 - " movq 24(%0), %%mm3\n"
22658 - " movq %%mm0, (%1)\n"
22659 - " movq %%mm1, 8(%1)\n"
22660 - " movq %%mm2, 16(%1)\n"
22661 - " movq %%mm3, 24(%1)\n"
22662 - " movq 32(%0), %%mm0\n"
22663 - " movq 40(%0), %%mm1\n"
22664 - " movq 48(%0), %%mm2\n"
22665 - " movq 56(%0), %%mm3\n"
22666 - " movq %%mm0, 32(%1)\n"
22667 - " movq %%mm1, 40(%1)\n"
22668 - " movq %%mm2, 48(%1)\n"
22669 - " movq %%mm3, 56(%1)\n"
22670 + "1: prefetch 320(%1)\n"
22671 + "2: movq (%1), %%mm0\n"
22672 + " movq 8(%1), %%mm1\n"
22673 + " movq 16(%1), %%mm2\n"
22674 + " movq 24(%1), %%mm3\n"
22675 + " movq %%mm0, (%2)\n"
22676 + " movq %%mm1, 8(%2)\n"
22677 + " movq %%mm2, 16(%2)\n"
22678 + " movq %%mm3, 24(%2)\n"
22679 + " movq 32(%1), %%mm0\n"
22680 + " movq 40(%1), %%mm1\n"
22681 + " movq 48(%1), %%mm2\n"
22682 + " movq 56(%1), %%mm3\n"
22683 + " movq %%mm0, 32(%2)\n"
22684 + " movq %%mm1, 40(%2)\n"
22685 + " movq %%mm2, 48(%2)\n"
22686 + " movq %%mm3, 56(%2)\n"
22687 ".section .fixup, \"ax\"\n"
22688 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22689 + "3:\n"
22690 +
22691 +#ifdef CONFIG_PAX_KERNEXEC
22692 + " movl %%cr0, %0\n"
22693 + " movl %0, %%eax\n"
22694 + " andl $0xFFFEFFFF, %%eax\n"
22695 + " movl %%eax, %%cr0\n"
22696 +#endif
22697 +
22698 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22699 +
22700 +#ifdef CONFIG_PAX_KERNEXEC
22701 + " movl %0, %%cr0\n"
22702 +#endif
22703 +
22704 " jmp 2b\n"
22705 ".previous\n"
22706 _ASM_EXTABLE(1b, 3b)
22707 - : : "r" (from), "r" (to) : "memory");
22708 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22709
22710 from += 64;
22711 to += 64;
22712 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22713 index f6d13ee..aca5f0b 100644
22714 --- a/arch/x86/lib/msr-reg.S
22715 +++ b/arch/x86/lib/msr-reg.S
22716 @@ -3,6 +3,7 @@
22717 #include <asm/dwarf2.h>
22718 #include <asm/asm.h>
22719 #include <asm/msr.h>
22720 +#include <asm/alternative-asm.h>
22721
22722 #ifdef CONFIG_X86_64
22723 /*
22724 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22725 CFI_STARTPROC
22726 pushq_cfi %rbx
22727 pushq_cfi %rbp
22728 - movq %rdi, %r10 /* Save pointer */
22729 + movq %rdi, %r9 /* Save pointer */
22730 xorl %r11d, %r11d /* Return value */
22731 movl (%rdi), %eax
22732 movl 4(%rdi), %ecx
22733 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22734 movl 28(%rdi), %edi
22735 CFI_REMEMBER_STATE
22736 1: \op
22737 -2: movl %eax, (%r10)
22738 +2: movl %eax, (%r9)
22739 movl %r11d, %eax /* Return value */
22740 - movl %ecx, 4(%r10)
22741 - movl %edx, 8(%r10)
22742 - movl %ebx, 12(%r10)
22743 - movl %ebp, 20(%r10)
22744 - movl %esi, 24(%r10)
22745 - movl %edi, 28(%r10)
22746 + movl %ecx, 4(%r9)
22747 + movl %edx, 8(%r9)
22748 + movl %ebx, 12(%r9)
22749 + movl %ebp, 20(%r9)
22750 + movl %esi, 24(%r9)
22751 + movl %edi, 28(%r9)
22752 popq_cfi %rbp
22753 popq_cfi %rbx
22754 + pax_force_retaddr
22755 ret
22756 3:
22757 CFI_RESTORE_STATE
22758 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22759 index fc6ba17..04471c5 100644
22760 --- a/arch/x86/lib/putuser.S
22761 +++ b/arch/x86/lib/putuser.S
22762 @@ -16,7 +16,9 @@
22763 #include <asm/errno.h>
22764 #include <asm/asm.h>
22765 #include <asm/smap.h>
22766 -
22767 +#include <asm/segment.h>
22768 +#include <asm/pgtable.h>
22769 +#include <asm/alternative-asm.h>
22770
22771 /*
22772 * __put_user_X
22773 @@ -30,57 +32,125 @@
22774 * as they get called from within inline assembly.
22775 */
22776
22777 -#define ENTER CFI_STARTPROC ; \
22778 - GET_THREAD_INFO(%_ASM_BX)
22779 -#define EXIT ASM_CLAC ; \
22780 - ret ; \
22781 +#define ENTER CFI_STARTPROC
22782 +#define EXIT ASM_CLAC ; \
22783 + pax_force_retaddr ; \
22784 + ret ; \
22785 CFI_ENDPROC
22786
22787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22788 +#define _DEST %_ASM_CX,%_ASM_BX
22789 +#else
22790 +#define _DEST %_ASM_CX
22791 +#endif
22792 +
22793 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22794 +#define __copyuser_seg gs;
22795 +#else
22796 +#define __copyuser_seg
22797 +#endif
22798 +
22799 .text
22800 ENTRY(__put_user_1)
22801 ENTER
22802 +
22803 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22804 + GET_THREAD_INFO(%_ASM_BX)
22805 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22806 jae bad_put_user
22807 ASM_STAC
22808 -1: movb %al,(%_ASM_CX)
22809 +
22810 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22811 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22812 + cmp %_ASM_BX,%_ASM_CX
22813 + jb 1234f
22814 + xor %ebx,%ebx
22815 +1234:
22816 +#endif
22817 +
22818 +#endif
22819 +
22820 +1: __copyuser_seg movb %al,(_DEST)
22821 xor %eax,%eax
22822 EXIT
22823 ENDPROC(__put_user_1)
22824
22825 ENTRY(__put_user_2)
22826 ENTER
22827 +
22828 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22829 + GET_THREAD_INFO(%_ASM_BX)
22830 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22831 sub $1,%_ASM_BX
22832 cmp %_ASM_BX,%_ASM_CX
22833 jae bad_put_user
22834 ASM_STAC
22835 -2: movw %ax,(%_ASM_CX)
22836 +
22837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22838 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22839 + cmp %_ASM_BX,%_ASM_CX
22840 + jb 1234f
22841 + xor %ebx,%ebx
22842 +1234:
22843 +#endif
22844 +
22845 +#endif
22846 +
22847 +2: __copyuser_seg movw %ax,(_DEST)
22848 xor %eax,%eax
22849 EXIT
22850 ENDPROC(__put_user_2)
22851
22852 ENTRY(__put_user_4)
22853 ENTER
22854 +
22855 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22856 + GET_THREAD_INFO(%_ASM_BX)
22857 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22858 sub $3,%_ASM_BX
22859 cmp %_ASM_BX,%_ASM_CX
22860 jae bad_put_user
22861 ASM_STAC
22862 -3: movl %eax,(%_ASM_CX)
22863 +
22864 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22865 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22866 + cmp %_ASM_BX,%_ASM_CX
22867 + jb 1234f
22868 + xor %ebx,%ebx
22869 +1234:
22870 +#endif
22871 +
22872 +#endif
22873 +
22874 +3: __copyuser_seg movl %eax,(_DEST)
22875 xor %eax,%eax
22876 EXIT
22877 ENDPROC(__put_user_4)
22878
22879 ENTRY(__put_user_8)
22880 ENTER
22881 +
22882 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22883 + GET_THREAD_INFO(%_ASM_BX)
22884 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22885 sub $7,%_ASM_BX
22886 cmp %_ASM_BX,%_ASM_CX
22887 jae bad_put_user
22888 ASM_STAC
22889 -4: mov %_ASM_AX,(%_ASM_CX)
22890 +
22891 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22892 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22893 + cmp %_ASM_BX,%_ASM_CX
22894 + jb 1234f
22895 + xor %ebx,%ebx
22896 +1234:
22897 +#endif
22898 +
22899 +#endif
22900 +
22901 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22902 #ifdef CONFIG_X86_32
22903 -5: movl %edx,4(%_ASM_CX)
22904 +5: __copyuser_seg movl %edx,4(_DEST)
22905 #endif
22906 xor %eax,%eax
22907 EXIT
22908 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22909 index 1cad221..de671ee 100644
22910 --- a/arch/x86/lib/rwlock.S
22911 +++ b/arch/x86/lib/rwlock.S
22912 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22913 FRAME
22914 0: LOCK_PREFIX
22915 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22916 +
22917 +#ifdef CONFIG_PAX_REFCOUNT
22918 + jno 1234f
22919 + LOCK_PREFIX
22920 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22921 + int $4
22922 +1234:
22923 + _ASM_EXTABLE(1234b, 1234b)
22924 +#endif
22925 +
22926 1: rep; nop
22927 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22928 jne 1b
22929 LOCK_PREFIX
22930 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22931 +
22932 +#ifdef CONFIG_PAX_REFCOUNT
22933 + jno 1234f
22934 + LOCK_PREFIX
22935 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22936 + int $4
22937 +1234:
22938 + _ASM_EXTABLE(1234b, 1234b)
22939 +#endif
22940 +
22941 jnz 0b
22942 ENDFRAME
22943 + pax_force_retaddr
22944 ret
22945 CFI_ENDPROC
22946 END(__write_lock_failed)
22947 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22948 FRAME
22949 0: LOCK_PREFIX
22950 READ_LOCK_SIZE(inc) (%__lock_ptr)
22951 +
22952 +#ifdef CONFIG_PAX_REFCOUNT
22953 + jno 1234f
22954 + LOCK_PREFIX
22955 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22956 + int $4
22957 +1234:
22958 + _ASM_EXTABLE(1234b, 1234b)
22959 +#endif
22960 +
22961 1: rep; nop
22962 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22963 js 1b
22964 LOCK_PREFIX
22965 READ_LOCK_SIZE(dec) (%__lock_ptr)
22966 +
22967 +#ifdef CONFIG_PAX_REFCOUNT
22968 + jno 1234f
22969 + LOCK_PREFIX
22970 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22971 + int $4
22972 +1234:
22973 + _ASM_EXTABLE(1234b, 1234b)
22974 +#endif
22975 +
22976 js 0b
22977 ENDFRAME
22978 + pax_force_retaddr
22979 ret
22980 CFI_ENDPROC
22981 END(__read_lock_failed)
22982 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22983 index 5dff5f0..cadebf4 100644
22984 --- a/arch/x86/lib/rwsem.S
22985 +++ b/arch/x86/lib/rwsem.S
22986 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22987 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22988 CFI_RESTORE __ASM_REG(dx)
22989 restore_common_regs
22990 + pax_force_retaddr
22991 ret
22992 CFI_ENDPROC
22993 ENDPROC(call_rwsem_down_read_failed)
22994 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22995 movq %rax,%rdi
22996 call rwsem_down_write_failed
22997 restore_common_regs
22998 + pax_force_retaddr
22999 ret
23000 CFI_ENDPROC
23001 ENDPROC(call_rwsem_down_write_failed)
23002 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
23003 movq %rax,%rdi
23004 call rwsem_wake
23005 restore_common_regs
23006 -1: ret
23007 +1: pax_force_retaddr
23008 + ret
23009 CFI_ENDPROC
23010 ENDPROC(call_rwsem_wake)
23011
23012 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
23013 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23014 CFI_RESTORE __ASM_REG(dx)
23015 restore_common_regs
23016 + pax_force_retaddr
23017 ret
23018 CFI_ENDPROC
23019 ENDPROC(call_rwsem_downgrade_wake)
23020 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23021 index a63efd6..ccecad8 100644
23022 --- a/arch/x86/lib/thunk_64.S
23023 +++ b/arch/x86/lib/thunk_64.S
23024 @@ -8,6 +8,7 @@
23025 #include <linux/linkage.h>
23026 #include <asm/dwarf2.h>
23027 #include <asm/calling.h>
23028 +#include <asm/alternative-asm.h>
23029
23030 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23031 .macro THUNK name, func, put_ret_addr_in_rdi=0
23032 @@ -41,5 +42,6 @@
23033 SAVE_ARGS
23034 restore:
23035 RESTORE_ARGS
23036 + pax_force_retaddr
23037 ret
23038 CFI_ENDPROC
23039 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23040 index 98f6d6b6..d27f045 100644
23041 --- a/arch/x86/lib/usercopy_32.c
23042 +++ b/arch/x86/lib/usercopy_32.c
23043 @@ -42,11 +42,13 @@ do { \
23044 int __d0; \
23045 might_fault(); \
23046 __asm__ __volatile__( \
23047 + __COPYUSER_SET_ES \
23048 ASM_STAC "\n" \
23049 "0: rep; stosl\n" \
23050 " movl %2,%0\n" \
23051 "1: rep; stosb\n" \
23052 "2: " ASM_CLAC "\n" \
23053 + __COPYUSER_RESTORE_ES \
23054 ".section .fixup,\"ax\"\n" \
23055 "3: lea 0(%2,%0,4),%0\n" \
23056 " jmp 2b\n" \
23057 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
23058
23059 #ifdef CONFIG_X86_INTEL_USERCOPY
23060 static unsigned long
23061 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
23062 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23063 {
23064 int d0, d1;
23065 __asm__ __volatile__(
23066 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23067 " .align 2,0x90\n"
23068 "3: movl 0(%4), %%eax\n"
23069 "4: movl 4(%4), %%edx\n"
23070 - "5: movl %%eax, 0(%3)\n"
23071 - "6: movl %%edx, 4(%3)\n"
23072 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23073 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23074 "7: movl 8(%4), %%eax\n"
23075 "8: movl 12(%4),%%edx\n"
23076 - "9: movl %%eax, 8(%3)\n"
23077 - "10: movl %%edx, 12(%3)\n"
23078 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23079 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23080 "11: movl 16(%4), %%eax\n"
23081 "12: movl 20(%4), %%edx\n"
23082 - "13: movl %%eax, 16(%3)\n"
23083 - "14: movl %%edx, 20(%3)\n"
23084 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23085 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23086 "15: movl 24(%4), %%eax\n"
23087 "16: movl 28(%4), %%edx\n"
23088 - "17: movl %%eax, 24(%3)\n"
23089 - "18: movl %%edx, 28(%3)\n"
23090 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23091 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23092 "19: movl 32(%4), %%eax\n"
23093 "20: movl 36(%4), %%edx\n"
23094 - "21: movl %%eax, 32(%3)\n"
23095 - "22: movl %%edx, 36(%3)\n"
23096 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23097 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23098 "23: movl 40(%4), %%eax\n"
23099 "24: movl 44(%4), %%edx\n"
23100 - "25: movl %%eax, 40(%3)\n"
23101 - "26: movl %%edx, 44(%3)\n"
23102 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23103 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23104 "27: movl 48(%4), %%eax\n"
23105 "28: movl 52(%4), %%edx\n"
23106 - "29: movl %%eax, 48(%3)\n"
23107 - "30: movl %%edx, 52(%3)\n"
23108 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23109 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23110 "31: movl 56(%4), %%eax\n"
23111 "32: movl 60(%4), %%edx\n"
23112 - "33: movl %%eax, 56(%3)\n"
23113 - "34: movl %%edx, 60(%3)\n"
23114 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23115 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23116 " addl $-64, %0\n"
23117 " addl $64, %4\n"
23118 " addl $64, %3\n"
23119 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23120 " shrl $2, %0\n"
23121 " andl $3, %%eax\n"
23122 " cld\n"
23123 + __COPYUSER_SET_ES
23124 "99: rep; movsl\n"
23125 "36: movl %%eax, %0\n"
23126 "37: rep; movsb\n"
23127 "100:\n"
23128 + __COPYUSER_RESTORE_ES
23129 ".section .fixup,\"ax\"\n"
23130 "101: lea 0(%%eax,%0,4),%0\n"
23131 " jmp 100b\n"
23132 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23133 }
23134
23135 static unsigned long
23136 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23137 +{
23138 + int d0, d1;
23139 + __asm__ __volatile__(
23140 + " .align 2,0x90\n"
23141 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23142 + " cmpl $67, %0\n"
23143 + " jbe 3f\n"
23144 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23145 + " .align 2,0x90\n"
23146 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23147 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23148 + "5: movl %%eax, 0(%3)\n"
23149 + "6: movl %%edx, 4(%3)\n"
23150 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23151 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23152 + "9: movl %%eax, 8(%3)\n"
23153 + "10: movl %%edx, 12(%3)\n"
23154 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23155 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23156 + "13: movl %%eax, 16(%3)\n"
23157 + "14: movl %%edx, 20(%3)\n"
23158 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23159 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23160 + "17: movl %%eax, 24(%3)\n"
23161 + "18: movl %%edx, 28(%3)\n"
23162 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23163 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23164 + "21: movl %%eax, 32(%3)\n"
23165 + "22: movl %%edx, 36(%3)\n"
23166 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23167 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23168 + "25: movl %%eax, 40(%3)\n"
23169 + "26: movl %%edx, 44(%3)\n"
23170 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23171 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23172 + "29: movl %%eax, 48(%3)\n"
23173 + "30: movl %%edx, 52(%3)\n"
23174 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23175 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23176 + "33: movl %%eax, 56(%3)\n"
23177 + "34: movl %%edx, 60(%3)\n"
23178 + " addl $-64, %0\n"
23179 + " addl $64, %4\n"
23180 + " addl $64, %3\n"
23181 + " cmpl $63, %0\n"
23182 + " ja 1b\n"
23183 + "35: movl %0, %%eax\n"
23184 + " shrl $2, %0\n"
23185 + " andl $3, %%eax\n"
23186 + " cld\n"
23187 + "99: rep; "__copyuser_seg" movsl\n"
23188 + "36: movl %%eax, %0\n"
23189 + "37: rep; "__copyuser_seg" movsb\n"
23190 + "100:\n"
23191 + ".section .fixup,\"ax\"\n"
23192 + "101: lea 0(%%eax,%0,4),%0\n"
23193 + " jmp 100b\n"
23194 + ".previous\n"
23195 + _ASM_EXTABLE(1b,100b)
23196 + _ASM_EXTABLE(2b,100b)
23197 + _ASM_EXTABLE(3b,100b)
23198 + _ASM_EXTABLE(4b,100b)
23199 + _ASM_EXTABLE(5b,100b)
23200 + _ASM_EXTABLE(6b,100b)
23201 + _ASM_EXTABLE(7b,100b)
23202 + _ASM_EXTABLE(8b,100b)
23203 + _ASM_EXTABLE(9b,100b)
23204 + _ASM_EXTABLE(10b,100b)
23205 + _ASM_EXTABLE(11b,100b)
23206 + _ASM_EXTABLE(12b,100b)
23207 + _ASM_EXTABLE(13b,100b)
23208 + _ASM_EXTABLE(14b,100b)
23209 + _ASM_EXTABLE(15b,100b)
23210 + _ASM_EXTABLE(16b,100b)
23211 + _ASM_EXTABLE(17b,100b)
23212 + _ASM_EXTABLE(18b,100b)
23213 + _ASM_EXTABLE(19b,100b)
23214 + _ASM_EXTABLE(20b,100b)
23215 + _ASM_EXTABLE(21b,100b)
23216 + _ASM_EXTABLE(22b,100b)
23217 + _ASM_EXTABLE(23b,100b)
23218 + _ASM_EXTABLE(24b,100b)
23219 + _ASM_EXTABLE(25b,100b)
23220 + _ASM_EXTABLE(26b,100b)
23221 + _ASM_EXTABLE(27b,100b)
23222 + _ASM_EXTABLE(28b,100b)
23223 + _ASM_EXTABLE(29b,100b)
23224 + _ASM_EXTABLE(30b,100b)
23225 + _ASM_EXTABLE(31b,100b)
23226 + _ASM_EXTABLE(32b,100b)
23227 + _ASM_EXTABLE(33b,100b)
23228 + _ASM_EXTABLE(34b,100b)
23229 + _ASM_EXTABLE(35b,100b)
23230 + _ASM_EXTABLE(36b,100b)
23231 + _ASM_EXTABLE(37b,100b)
23232 + _ASM_EXTABLE(99b,101b)
23233 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23234 + : "1"(to), "2"(from), "0"(size)
23235 + : "eax", "edx", "memory");
23236 + return size;
23237 +}
23238 +
23239 +static unsigned long __size_overflow(3)
23240 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23241 {
23242 int d0, d1;
23243 __asm__ __volatile__(
23244 " .align 2,0x90\n"
23245 - "0: movl 32(%4), %%eax\n"
23246 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23247 " cmpl $67, %0\n"
23248 " jbe 2f\n"
23249 - "1: movl 64(%4), %%eax\n"
23250 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23251 " .align 2,0x90\n"
23252 - "2: movl 0(%4), %%eax\n"
23253 - "21: movl 4(%4), %%edx\n"
23254 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23255 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23256 " movl %%eax, 0(%3)\n"
23257 " movl %%edx, 4(%3)\n"
23258 - "3: movl 8(%4), %%eax\n"
23259 - "31: movl 12(%4),%%edx\n"
23260 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23261 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23262 " movl %%eax, 8(%3)\n"
23263 " movl %%edx, 12(%3)\n"
23264 - "4: movl 16(%4), %%eax\n"
23265 - "41: movl 20(%4), %%edx\n"
23266 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23267 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23268 " movl %%eax, 16(%3)\n"
23269 " movl %%edx, 20(%3)\n"
23270 - "10: movl 24(%4), %%eax\n"
23271 - "51: movl 28(%4), %%edx\n"
23272 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23273 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23274 " movl %%eax, 24(%3)\n"
23275 " movl %%edx, 28(%3)\n"
23276 - "11: movl 32(%4), %%eax\n"
23277 - "61: movl 36(%4), %%edx\n"
23278 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23279 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23280 " movl %%eax, 32(%3)\n"
23281 " movl %%edx, 36(%3)\n"
23282 - "12: movl 40(%4), %%eax\n"
23283 - "71: movl 44(%4), %%edx\n"
23284 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23285 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23286 " movl %%eax, 40(%3)\n"
23287 " movl %%edx, 44(%3)\n"
23288 - "13: movl 48(%4), %%eax\n"
23289 - "81: movl 52(%4), %%edx\n"
23290 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23291 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23292 " movl %%eax, 48(%3)\n"
23293 " movl %%edx, 52(%3)\n"
23294 - "14: movl 56(%4), %%eax\n"
23295 - "91: movl 60(%4), %%edx\n"
23296 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23297 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23298 " movl %%eax, 56(%3)\n"
23299 " movl %%edx, 60(%3)\n"
23300 " addl $-64, %0\n"
23301 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23302 " shrl $2, %0\n"
23303 " andl $3, %%eax\n"
23304 " cld\n"
23305 - "6: rep; movsl\n"
23306 + "6: rep; "__copyuser_seg" movsl\n"
23307 " movl %%eax,%0\n"
23308 - "7: rep; movsb\n"
23309 + "7: rep; "__copyuser_seg" movsb\n"
23310 "8:\n"
23311 ".section .fixup,\"ax\"\n"
23312 "9: lea 0(%%eax,%0,4),%0\n"
23313 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23314 * hyoshiok@miraclelinux.com
23315 */
23316
23317 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23318 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23319 const void __user *from, unsigned long size)
23320 {
23321 int d0, d1;
23322
23323 __asm__ __volatile__(
23324 " .align 2,0x90\n"
23325 - "0: movl 32(%4), %%eax\n"
23326 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23327 " cmpl $67, %0\n"
23328 " jbe 2f\n"
23329 - "1: movl 64(%4), %%eax\n"
23330 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23331 " .align 2,0x90\n"
23332 - "2: movl 0(%4), %%eax\n"
23333 - "21: movl 4(%4), %%edx\n"
23334 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23335 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23336 " movnti %%eax, 0(%3)\n"
23337 " movnti %%edx, 4(%3)\n"
23338 - "3: movl 8(%4), %%eax\n"
23339 - "31: movl 12(%4),%%edx\n"
23340 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23341 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23342 " movnti %%eax, 8(%3)\n"
23343 " movnti %%edx, 12(%3)\n"
23344 - "4: movl 16(%4), %%eax\n"
23345 - "41: movl 20(%4), %%edx\n"
23346 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23347 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23348 " movnti %%eax, 16(%3)\n"
23349 " movnti %%edx, 20(%3)\n"
23350 - "10: movl 24(%4), %%eax\n"
23351 - "51: movl 28(%4), %%edx\n"
23352 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23353 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23354 " movnti %%eax, 24(%3)\n"
23355 " movnti %%edx, 28(%3)\n"
23356 - "11: movl 32(%4), %%eax\n"
23357 - "61: movl 36(%4), %%edx\n"
23358 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23359 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23360 " movnti %%eax, 32(%3)\n"
23361 " movnti %%edx, 36(%3)\n"
23362 - "12: movl 40(%4), %%eax\n"
23363 - "71: movl 44(%4), %%edx\n"
23364 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23365 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23366 " movnti %%eax, 40(%3)\n"
23367 " movnti %%edx, 44(%3)\n"
23368 - "13: movl 48(%4), %%eax\n"
23369 - "81: movl 52(%4), %%edx\n"
23370 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23371 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23372 " movnti %%eax, 48(%3)\n"
23373 " movnti %%edx, 52(%3)\n"
23374 - "14: movl 56(%4), %%eax\n"
23375 - "91: movl 60(%4), %%edx\n"
23376 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23377 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23378 " movnti %%eax, 56(%3)\n"
23379 " movnti %%edx, 60(%3)\n"
23380 " addl $-64, %0\n"
23381 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23382 " shrl $2, %0\n"
23383 " andl $3, %%eax\n"
23384 " cld\n"
23385 - "6: rep; movsl\n"
23386 + "6: rep; "__copyuser_seg" movsl\n"
23387 " movl %%eax,%0\n"
23388 - "7: rep; movsb\n"
23389 + "7: rep; "__copyuser_seg" movsb\n"
23390 "8:\n"
23391 ".section .fixup,\"ax\"\n"
23392 "9: lea 0(%%eax,%0,4),%0\n"
23393 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23394 return size;
23395 }
23396
23397 -static unsigned long __copy_user_intel_nocache(void *to,
23398 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23399 const void __user *from, unsigned long size)
23400 {
23401 int d0, d1;
23402
23403 __asm__ __volatile__(
23404 " .align 2,0x90\n"
23405 - "0: movl 32(%4), %%eax\n"
23406 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23407 " cmpl $67, %0\n"
23408 " jbe 2f\n"
23409 - "1: movl 64(%4), %%eax\n"
23410 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23411 " .align 2,0x90\n"
23412 - "2: movl 0(%4), %%eax\n"
23413 - "21: movl 4(%4), %%edx\n"
23414 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23415 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23416 " movnti %%eax, 0(%3)\n"
23417 " movnti %%edx, 4(%3)\n"
23418 - "3: movl 8(%4), %%eax\n"
23419 - "31: movl 12(%4),%%edx\n"
23420 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23421 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23422 " movnti %%eax, 8(%3)\n"
23423 " movnti %%edx, 12(%3)\n"
23424 - "4: movl 16(%4), %%eax\n"
23425 - "41: movl 20(%4), %%edx\n"
23426 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23427 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23428 " movnti %%eax, 16(%3)\n"
23429 " movnti %%edx, 20(%3)\n"
23430 - "10: movl 24(%4), %%eax\n"
23431 - "51: movl 28(%4), %%edx\n"
23432 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23433 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23434 " movnti %%eax, 24(%3)\n"
23435 " movnti %%edx, 28(%3)\n"
23436 - "11: movl 32(%4), %%eax\n"
23437 - "61: movl 36(%4), %%edx\n"
23438 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23439 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23440 " movnti %%eax, 32(%3)\n"
23441 " movnti %%edx, 36(%3)\n"
23442 - "12: movl 40(%4), %%eax\n"
23443 - "71: movl 44(%4), %%edx\n"
23444 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23445 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23446 " movnti %%eax, 40(%3)\n"
23447 " movnti %%edx, 44(%3)\n"
23448 - "13: movl 48(%4), %%eax\n"
23449 - "81: movl 52(%4), %%edx\n"
23450 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23451 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23452 " movnti %%eax, 48(%3)\n"
23453 " movnti %%edx, 52(%3)\n"
23454 - "14: movl 56(%4), %%eax\n"
23455 - "91: movl 60(%4), %%edx\n"
23456 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23457 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23458 " movnti %%eax, 56(%3)\n"
23459 " movnti %%edx, 60(%3)\n"
23460 " addl $-64, %0\n"
23461 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23462 " shrl $2, %0\n"
23463 " andl $3, %%eax\n"
23464 " cld\n"
23465 - "6: rep; movsl\n"
23466 + "6: rep; "__copyuser_seg" movsl\n"
23467 " movl %%eax,%0\n"
23468 - "7: rep; movsb\n"
23469 + "7: rep; "__copyuser_seg" movsb\n"
23470 "8:\n"
23471 ".section .fixup,\"ax\"\n"
23472 "9: lea 0(%%eax,%0,4),%0\n"
23473 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23474 */
23475 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23476 unsigned long size);
23477 -unsigned long __copy_user_intel(void __user *to, const void *from,
23478 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23479 + unsigned long size);
23480 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23481 unsigned long size);
23482 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23483 const void __user *from, unsigned long size);
23484 #endif /* CONFIG_X86_INTEL_USERCOPY */
23485
23486 /* Generic arbitrary sized copy. */
23487 -#define __copy_user(to, from, size) \
23488 +#define __copy_user(to, from, size, prefix, set, restore) \
23489 do { \
23490 int __d0, __d1, __d2; \
23491 __asm__ __volatile__( \
23492 + set \
23493 " cmp $7,%0\n" \
23494 " jbe 1f\n" \
23495 " movl %1,%0\n" \
23496 " negl %0\n" \
23497 " andl $7,%0\n" \
23498 " subl %0,%3\n" \
23499 - "4: rep; movsb\n" \
23500 + "4: rep; "prefix"movsb\n" \
23501 " movl %3,%0\n" \
23502 " shrl $2,%0\n" \
23503 " andl $3,%3\n" \
23504 " .align 2,0x90\n" \
23505 - "0: rep; movsl\n" \
23506 + "0: rep; "prefix"movsl\n" \
23507 " movl %3,%0\n" \
23508 - "1: rep; movsb\n" \
23509 + "1: rep; "prefix"movsb\n" \
23510 "2:\n" \
23511 + restore \
23512 ".section .fixup,\"ax\"\n" \
23513 "5: addl %3,%0\n" \
23514 " jmp 2b\n" \
23515 @@ -538,14 +650,14 @@ do { \
23516 " negl %0\n" \
23517 " andl $7,%0\n" \
23518 " subl %0,%3\n" \
23519 - "4: rep; movsb\n" \
23520 + "4: rep; "__copyuser_seg"movsb\n" \
23521 " movl %3,%0\n" \
23522 " shrl $2,%0\n" \
23523 " andl $3,%3\n" \
23524 " .align 2,0x90\n" \
23525 - "0: rep; movsl\n" \
23526 + "0: rep; "__copyuser_seg"movsl\n" \
23527 " movl %3,%0\n" \
23528 - "1: rep; movsb\n" \
23529 + "1: rep; "__copyuser_seg"movsb\n" \
23530 "2:\n" \
23531 ".section .fixup,\"ax\"\n" \
23532 "5: addl %3,%0\n" \
23533 @@ -629,9 +741,9 @@ survive:
23534 #endif
23535 stac();
23536 if (movsl_is_ok(to, from, n))
23537 - __copy_user(to, from, n);
23538 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23539 else
23540 - n = __copy_user_intel(to, from, n);
23541 + n = __generic_copy_to_user_intel(to, from, n);
23542 clac();
23543 return n;
23544 }
23545 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23546 {
23547 stac();
23548 if (movsl_is_ok(to, from, n))
23549 - __copy_user(to, from, n);
23550 + __copy_user(to, from, n, __copyuser_seg, "", "");
23551 else
23552 - n = __copy_user_intel((void __user *)to,
23553 - (const void *)from, n);
23554 + n = __generic_copy_from_user_intel(to, from, n);
23555 clac();
23556 return n;
23557 }
23558 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23559 if (n > 64 && cpu_has_xmm2)
23560 n = __copy_user_intel_nocache(to, from, n);
23561 else
23562 - __copy_user(to, from, n);
23563 + __copy_user(to, from, n, __copyuser_seg, "", "");
23564 #else
23565 - __copy_user(to, from, n);
23566 + __copy_user(to, from, n, __copyuser_seg, "", "");
23567 #endif
23568 clac();
23569 return n;
23570 }
23571 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23572
23573 -/**
23574 - * copy_to_user: - Copy a block of data into user space.
23575 - * @to: Destination address, in user space.
23576 - * @from: Source address, in kernel space.
23577 - * @n: Number of bytes to copy.
23578 - *
23579 - * Context: User context only. This function may sleep.
23580 - *
23581 - * Copy data from kernel space to user space.
23582 - *
23583 - * Returns number of bytes that could not be copied.
23584 - * On success, this will be zero.
23585 - */
23586 -unsigned long
23587 -copy_to_user(void __user *to, const void *from, unsigned long n)
23588 -{
23589 - if (access_ok(VERIFY_WRITE, to, n))
23590 - n = __copy_to_user(to, from, n);
23591 - return n;
23592 -}
23593 -EXPORT_SYMBOL(copy_to_user);
23594 -
23595 -/**
23596 - * copy_from_user: - Copy a block of data from user space.
23597 - * @to: Destination address, in kernel space.
23598 - * @from: Source address, in user space.
23599 - * @n: Number of bytes to copy.
23600 - *
23601 - * Context: User context only. This function may sleep.
23602 - *
23603 - * Copy data from user space to kernel space.
23604 - *
23605 - * Returns number of bytes that could not be copied.
23606 - * On success, this will be zero.
23607 - *
23608 - * If some data could not be copied, this function will pad the copied
23609 - * data to the requested size using zero bytes.
23610 - */
23611 -unsigned long
23612 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23613 -{
23614 - if (access_ok(VERIFY_READ, from, n))
23615 - n = __copy_from_user(to, from, n);
23616 - else
23617 - memset(to, 0, n);
23618 - return n;
23619 -}
23620 -EXPORT_SYMBOL(_copy_from_user);
23621 -
23622 void copy_from_user_overflow(void)
23623 {
23624 WARN(1, "Buffer overflow detected!\n");
23625 }
23626 EXPORT_SYMBOL(copy_from_user_overflow);
23627 +
23628 +void copy_to_user_overflow(void)
23629 +{
23630 + WARN(1, "Buffer overflow detected!\n");
23631 +}
23632 +EXPORT_SYMBOL(copy_to_user_overflow);
23633 +
23634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23635 +void __set_fs(mm_segment_t x)
23636 +{
23637 + switch (x.seg) {
23638 + case 0:
23639 + loadsegment(gs, 0);
23640 + break;
23641 + case TASK_SIZE_MAX:
23642 + loadsegment(gs, __USER_DS);
23643 + break;
23644 + case -1UL:
23645 + loadsegment(gs, __KERNEL_DS);
23646 + break;
23647 + default:
23648 + BUG();
23649 + }
23650 + return;
23651 +}
23652 +EXPORT_SYMBOL(__set_fs);
23653 +
23654 +void set_fs(mm_segment_t x)
23655 +{
23656 + current_thread_info()->addr_limit = x;
23657 + __set_fs(x);
23658 +}
23659 +EXPORT_SYMBOL(set_fs);
23660 +#endif
23661 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23662 index 05928aa..b33dea1 100644
23663 --- a/arch/x86/lib/usercopy_64.c
23664 +++ b/arch/x86/lib/usercopy_64.c
23665 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23666 _ASM_EXTABLE(0b,3b)
23667 _ASM_EXTABLE(1b,2b)
23668 : [size8] "=&c"(size), [dst] "=&D" (__d0)
23669 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
23670 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
23671 [zero] "r" (0UL), [eight] "r" (8UL));
23672 clac();
23673 return size;
23674 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
23675 }
23676 EXPORT_SYMBOL(clear_user);
23677
23678 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23679 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23680 {
23681 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23682 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23683 - }
23684 - return len;
23685 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
23686 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
23687 + return len;
23688 }
23689 EXPORT_SYMBOL(copy_in_user);
23690
23691 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
23692 * it is not necessary to optimize tail handling.
23693 */
23694 unsigned long
23695 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23696 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23697 {
23698 char c;
23699 unsigned zero_len;
23700 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23701 clac();
23702 return len;
23703 }
23704 +
23705 +void copy_from_user_overflow(void)
23706 +{
23707 + WARN(1, "Buffer overflow detected!\n");
23708 +}
23709 +EXPORT_SYMBOL(copy_from_user_overflow);
23710 +
23711 +void copy_to_user_overflow(void)
23712 +{
23713 + WARN(1, "Buffer overflow detected!\n");
23714 +}
23715 +EXPORT_SYMBOL(copy_to_user_overflow);
23716 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23717 index 903ec1e..c4166b2 100644
23718 --- a/arch/x86/mm/extable.c
23719 +++ b/arch/x86/mm/extable.c
23720 @@ -6,12 +6,24 @@
23721 static inline unsigned long
23722 ex_insn_addr(const struct exception_table_entry *x)
23723 {
23724 - return (unsigned long)&x->insn + x->insn;
23725 + unsigned long reloc = 0;
23726 +
23727 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23728 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23729 +#endif
23730 +
23731 + return (unsigned long)&x->insn + x->insn + reloc;
23732 }
23733 static inline unsigned long
23734 ex_fixup_addr(const struct exception_table_entry *x)
23735 {
23736 - return (unsigned long)&x->fixup + x->fixup;
23737 + unsigned long reloc = 0;
23738 +
23739 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23740 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23741 +#endif
23742 +
23743 + return (unsigned long)&x->fixup + x->fixup + reloc;
23744 }
23745
23746 int fixup_exception(struct pt_regs *regs)
23747 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23748 unsigned long new_ip;
23749
23750 #ifdef CONFIG_PNPBIOS
23751 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23752 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23753 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23754 extern u32 pnp_bios_is_utter_crap;
23755 pnp_bios_is_utter_crap = 1;
23756 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23757 i += 4;
23758 p->fixup -= i;
23759 i += 4;
23760 +
23761 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23762 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23763 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23764 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23765 +#endif
23766 +
23767 }
23768 }
23769
23770 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23771 index 8e13ecb..831f2d0 100644
23772 --- a/arch/x86/mm/fault.c
23773 +++ b/arch/x86/mm/fault.c
23774 @@ -13,12 +13,19 @@
23775 #include <linux/perf_event.h> /* perf_sw_event */
23776 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23777 #include <linux/prefetch.h> /* prefetchw */
23778 +#include <linux/unistd.h>
23779 +#include <linux/compiler.h>
23780
23781 #include <asm/traps.h> /* dotraplinkage, ... */
23782 #include <asm/pgalloc.h> /* pgd_*(), ... */
23783 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23784 #include <asm/fixmap.h> /* VSYSCALL_START */
23785 #include <asm/rcu.h> /* exception_enter(), ... */
23786 +#include <asm/tlbflush.h>
23787 +
23788 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23789 +#include <asm/stacktrace.h>
23790 +#endif
23791
23792 /*
23793 * Page fault error code bits:
23794 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23795 int ret = 0;
23796
23797 /* kprobe_running() needs smp_processor_id() */
23798 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23799 + if (kprobes_built_in() && !user_mode(regs)) {
23800 preempt_disable();
23801 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23802 ret = 1;
23803 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23804 return !instr_lo || (instr_lo>>1) == 1;
23805 case 0x00:
23806 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23807 - if (probe_kernel_address(instr, opcode))
23808 + if (user_mode(regs)) {
23809 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23810 + return 0;
23811 + } else if (probe_kernel_address(instr, opcode))
23812 return 0;
23813
23814 *prefetch = (instr_lo == 0xF) &&
23815 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23816 while (instr < max_instr) {
23817 unsigned char opcode;
23818
23819 - if (probe_kernel_address(instr, opcode))
23820 + if (user_mode(regs)) {
23821 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23822 + break;
23823 + } else if (probe_kernel_address(instr, opcode))
23824 break;
23825
23826 instr++;
23827 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23828 force_sig_info(si_signo, &info, tsk);
23829 }
23830
23831 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23832 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23833 +#endif
23834 +
23835 +#ifdef CONFIG_PAX_EMUTRAMP
23836 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23837 +#endif
23838 +
23839 +#ifdef CONFIG_PAX_PAGEEXEC
23840 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23841 +{
23842 + pgd_t *pgd;
23843 + pud_t *pud;
23844 + pmd_t *pmd;
23845 +
23846 + pgd = pgd_offset(mm, address);
23847 + if (!pgd_present(*pgd))
23848 + return NULL;
23849 + pud = pud_offset(pgd, address);
23850 + if (!pud_present(*pud))
23851 + return NULL;
23852 + pmd = pmd_offset(pud, address);
23853 + if (!pmd_present(*pmd))
23854 + return NULL;
23855 + return pmd;
23856 +}
23857 +#endif
23858 +
23859 DEFINE_SPINLOCK(pgd_lock);
23860 LIST_HEAD(pgd_list);
23861
23862 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
23863 for (address = VMALLOC_START & PMD_MASK;
23864 address >= TASK_SIZE && address < FIXADDR_TOP;
23865 address += PMD_SIZE) {
23866 +
23867 +#ifdef CONFIG_PAX_PER_CPU_PGD
23868 + unsigned long cpu;
23869 +#else
23870 struct page *page;
23871 +#endif
23872
23873 spin_lock(&pgd_lock);
23874 +
23875 +#ifdef CONFIG_PAX_PER_CPU_PGD
23876 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23877 + pgd_t *pgd = get_cpu_pgd(cpu);
23878 + pmd_t *ret;
23879 +#else
23880 list_for_each_entry(page, &pgd_list, lru) {
23881 + pgd_t *pgd = page_address(page);
23882 spinlock_t *pgt_lock;
23883 pmd_t *ret;
23884
23885 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
23886 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23887
23888 spin_lock(pgt_lock);
23889 - ret = vmalloc_sync_one(page_address(page), address);
23890 +#endif
23891 +
23892 + ret = vmalloc_sync_one(pgd, address);
23893 +
23894 +#ifndef CONFIG_PAX_PER_CPU_PGD
23895 spin_unlock(pgt_lock);
23896 +#endif
23897
23898 if (!ret)
23899 break;
23900 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23901 * an interrupt in the middle of a task switch..
23902 */
23903 pgd_paddr = read_cr3();
23904 +
23905 +#ifdef CONFIG_PAX_PER_CPU_PGD
23906 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23907 +#endif
23908 +
23909 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23910 if (!pmd_k)
23911 return -1;
23912 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23913 * happen within a race in page table update. In the later
23914 * case just flush:
23915 */
23916 +
23917 +#ifdef CONFIG_PAX_PER_CPU_PGD
23918 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23919 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23920 +#else
23921 pgd = pgd_offset(current->active_mm, address);
23922 +#endif
23923 +
23924 pgd_ref = pgd_offset_k(address);
23925 if (pgd_none(*pgd_ref))
23926 return -1;
23927 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23928 static int is_errata100(struct pt_regs *regs, unsigned long address)
23929 {
23930 #ifdef CONFIG_X86_64
23931 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23932 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23933 return 1;
23934 #endif
23935 return 0;
23936 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23937 }
23938
23939 static const char nx_warning[] = KERN_CRIT
23940 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23941 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23942
23943 static void
23944 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23945 @@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23946 if (!oops_may_print())
23947 return;
23948
23949 - if (error_code & PF_INSTR) {
23950 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23951 unsigned int level;
23952
23953 pte_t *pte = lookup_address(address, &level);
23954
23955 if (pte && pte_present(*pte) && !pte_exec(*pte))
23956 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23957 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23958 }
23959
23960 +#ifdef CONFIG_PAX_KERNEXEC
23961 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23962 + if (current->signal->curr_ip)
23963 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23964 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23965 + else
23966 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23967 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23968 + }
23969 +#endif
23970 +
23971 printk(KERN_ALERT "BUG: unable to handle kernel ");
23972 if (address < PAGE_SIZE)
23973 printk(KERN_CONT "NULL pointer dereference");
23974 @@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23975 }
23976 #endif
23977
23978 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23979 + if (pax_is_fetch_fault(regs, error_code, address)) {
23980 +
23981 +#ifdef CONFIG_PAX_EMUTRAMP
23982 + switch (pax_handle_fetch_fault(regs)) {
23983 + case 2:
23984 + return;
23985 + }
23986 +#endif
23987 +
23988 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23989 + do_group_exit(SIGKILL);
23990 + }
23991 +#endif
23992 +
23993 if (unlikely(show_unhandled_signals))
23994 show_signal_msg(regs, error_code, address, tsk);
23995
23996 @@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23997 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23998 printk(KERN_ERR
23999 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24000 - tsk->comm, tsk->pid, address);
24001 + tsk->comm, task_pid_nr(tsk), address);
24002 code = BUS_MCEERR_AR;
24003 }
24004 #endif
24005 @@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24006 return 1;
24007 }
24008
24009 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24010 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24011 +{
24012 + pte_t *pte;
24013 + pmd_t *pmd;
24014 + spinlock_t *ptl;
24015 + unsigned char pte_mask;
24016 +
24017 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24018 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
24019 + return 0;
24020 +
24021 + /* PaX: it's our fault, let's handle it if we can */
24022 +
24023 + /* PaX: take a look at read faults before acquiring any locks */
24024 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24025 + /* instruction fetch attempt from a protected page in user mode */
24026 + up_read(&mm->mmap_sem);
24027 +
24028 +#ifdef CONFIG_PAX_EMUTRAMP
24029 + switch (pax_handle_fetch_fault(regs)) {
24030 + case 2:
24031 + return 1;
24032 + }
24033 +#endif
24034 +
24035 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24036 + do_group_exit(SIGKILL);
24037 + }
24038 +
24039 + pmd = pax_get_pmd(mm, address);
24040 + if (unlikely(!pmd))
24041 + return 0;
24042 +
24043 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24044 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24045 + pte_unmap_unlock(pte, ptl);
24046 + return 0;
24047 + }
24048 +
24049 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24050 + /* write attempt to a protected page in user mode */
24051 + pte_unmap_unlock(pte, ptl);
24052 + return 0;
24053 + }
24054 +
24055 +#ifdef CONFIG_SMP
24056 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24057 +#else
24058 + if (likely(address > get_limit(regs->cs)))
24059 +#endif
24060 + {
24061 + set_pte(pte, pte_mkread(*pte));
24062 + __flush_tlb_one(address);
24063 + pte_unmap_unlock(pte, ptl);
24064 + up_read(&mm->mmap_sem);
24065 + return 1;
24066 + }
24067 +
24068 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24069 +
24070 + /*
24071 + * PaX: fill DTLB with user rights and retry
24072 + */
24073 + __asm__ __volatile__ (
24074 + "orb %2,(%1)\n"
24075 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24076 +/*
24077 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24078 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24079 + * page fault when examined during a TLB load attempt. this is true not only
24080 + * for PTEs holding a non-present entry but also present entries that will
24081 + * raise a page fault (such as those set up by PaX, or the copy-on-write
24082 + * mechanism). in effect it means that we do *not* need to flush the TLBs
24083 + * for our target pages since their PTEs are simply not in the TLBs at all.
24084 +
24085 + * the best thing in omitting it is that we gain around 15-20% speed in the
24086 + * fast path of the page fault handler and can get rid of tracing since we
24087 + * can no longer flush unintended entries.
24088 + */
24089 + "invlpg (%0)\n"
24090 +#endif
24091 + __copyuser_seg"testb $0,(%0)\n"
24092 + "xorb %3,(%1)\n"
24093 + :
24094 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24095 + : "memory", "cc");
24096 + pte_unmap_unlock(pte, ptl);
24097 + up_read(&mm->mmap_sem);
24098 + return 1;
24099 +}
24100 +#endif
24101 +
24102 /*
24103 * Handle a spurious fault caused by a stale TLB entry.
24104 *
24105 @@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
24106 static inline int
24107 access_error(unsigned long error_code, struct vm_area_struct *vma)
24108 {
24109 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24110 + return 1;
24111 +
24112 if (error_code & PF_WRITE) {
24113 /* write, present and write, not present: */
24114 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24115 @@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
24116 if (error_code & PF_USER)
24117 return false;
24118
24119 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
24120 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
24121 return false;
24122
24123 return true;
24124 @@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
24125 {
24126 struct vm_area_struct *vma;
24127 struct task_struct *tsk;
24128 - unsigned long address;
24129 struct mm_struct *mm;
24130 int fault;
24131 int write = error_code & PF_WRITE;
24132 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24133 (write ? FAULT_FLAG_WRITE : 0);
24134
24135 - tsk = current;
24136 - mm = tsk->mm;
24137 -
24138 /* Get the faulting address: */
24139 - address = read_cr2();
24140 + unsigned long address = read_cr2();
24141 +
24142 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24143 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24144 + if (!search_exception_tables(regs->ip)) {
24145 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24146 + bad_area_nosemaphore(regs, error_code, address);
24147 + return;
24148 + }
24149 + if (address < PAX_USER_SHADOW_BASE) {
24150 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24151 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24152 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24153 + } else
24154 + address -= PAX_USER_SHADOW_BASE;
24155 + }
24156 +#endif
24157 +
24158 + tsk = current;
24159 + mm = tsk->mm;
24160
24161 /*
24162 * Detect and handle instructions that would cause a page fault for
24163 @@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
24164 * User-mode registers count as a user access even for any
24165 * potential system fault or CPU buglet:
24166 */
24167 - if (user_mode_vm(regs)) {
24168 + if (user_mode(regs)) {
24169 local_irq_enable();
24170 error_code |= PF_USER;
24171 } else {
24172 @@ -1151,6 +1358,11 @@ retry:
24173 might_sleep();
24174 }
24175
24176 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24177 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24178 + return;
24179 +#endif
24180 +
24181 vma = find_vma(mm, address);
24182 if (unlikely(!vma)) {
24183 bad_area(regs, error_code, address);
24184 @@ -1162,18 +1374,24 @@ retry:
24185 bad_area(regs, error_code, address);
24186 return;
24187 }
24188 - if (error_code & PF_USER) {
24189 - /*
24190 - * Accessing the stack below %sp is always a bug.
24191 - * The large cushion allows instructions like enter
24192 - * and pusha to work. ("enter $65535, $31" pushes
24193 - * 32 pointers and then decrements %sp by 65535.)
24194 - */
24195 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24196 - bad_area(regs, error_code, address);
24197 - return;
24198 - }
24199 + /*
24200 + * Accessing the stack below %sp is always a bug.
24201 + * The large cushion allows instructions like enter
24202 + * and pusha to work. ("enter $65535, $31" pushes
24203 + * 32 pointers and then decrements %sp by 65535.)
24204 + */
24205 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24206 + bad_area(regs, error_code, address);
24207 + return;
24208 }
24209 +
24210 +#ifdef CONFIG_PAX_SEGMEXEC
24211 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24212 + bad_area(regs, error_code, address);
24213 + return;
24214 + }
24215 +#endif
24216 +
24217 if (unlikely(expand_stack(vma, address))) {
24218 bad_area(regs, error_code, address);
24219 return;
24220 @@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24221 __do_page_fault(regs, error_code);
24222 exception_exit(regs);
24223 }
24224 +
24225 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24226 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24227 +{
24228 + struct mm_struct *mm = current->mm;
24229 + unsigned long ip = regs->ip;
24230 +
24231 + if (v8086_mode(regs))
24232 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24233 +
24234 +#ifdef CONFIG_PAX_PAGEEXEC
24235 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24236 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24237 + return true;
24238 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24239 + return true;
24240 + return false;
24241 + }
24242 +#endif
24243 +
24244 +#ifdef CONFIG_PAX_SEGMEXEC
24245 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24246 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24247 + return true;
24248 + return false;
24249 + }
24250 +#endif
24251 +
24252 + return false;
24253 +}
24254 +#endif
24255 +
24256 +#ifdef CONFIG_PAX_EMUTRAMP
24257 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24258 +{
24259 + int err;
24260 +
24261 + do { /* PaX: libffi trampoline emulation */
24262 + unsigned char mov, jmp;
24263 + unsigned int addr1, addr2;
24264 +
24265 +#ifdef CONFIG_X86_64
24266 + if ((regs->ip + 9) >> 32)
24267 + break;
24268 +#endif
24269 +
24270 + err = get_user(mov, (unsigned char __user *)regs->ip);
24271 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24272 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24273 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24274 +
24275 + if (err)
24276 + break;
24277 +
24278 + if (mov == 0xB8 && jmp == 0xE9) {
24279 + regs->ax = addr1;
24280 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24281 + return 2;
24282 + }
24283 + } while (0);
24284 +
24285 + do { /* PaX: gcc trampoline emulation #1 */
24286 + unsigned char mov1, mov2;
24287 + unsigned short jmp;
24288 + unsigned int addr1, addr2;
24289 +
24290 +#ifdef CONFIG_X86_64
24291 + if ((regs->ip + 11) >> 32)
24292 + break;
24293 +#endif
24294 +
24295 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24296 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24297 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24298 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24299 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24300 +
24301 + if (err)
24302 + break;
24303 +
24304 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24305 + regs->cx = addr1;
24306 + regs->ax = addr2;
24307 + regs->ip = addr2;
24308 + return 2;
24309 + }
24310 + } while (0);
24311 +
24312 + do { /* PaX: gcc trampoline emulation #2 */
24313 + unsigned char mov, jmp;
24314 + unsigned int addr1, addr2;
24315 +
24316 +#ifdef CONFIG_X86_64
24317 + if ((regs->ip + 9) >> 32)
24318 + break;
24319 +#endif
24320 +
24321 + err = get_user(mov, (unsigned char __user *)regs->ip);
24322 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24323 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24324 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24325 +
24326 + if (err)
24327 + break;
24328 +
24329 + if (mov == 0xB9 && jmp == 0xE9) {
24330 + regs->cx = addr1;
24331 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24332 + return 2;
24333 + }
24334 + } while (0);
24335 +
24336 + return 1; /* PaX in action */
24337 +}
24338 +
24339 +#ifdef CONFIG_X86_64
24340 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24341 +{
24342 + int err;
24343 +
24344 + do { /* PaX: libffi trampoline emulation */
24345 + unsigned short mov1, mov2, jmp1;
24346 + unsigned char stcclc, jmp2;
24347 + unsigned long addr1, addr2;
24348 +
24349 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24350 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24351 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24352 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24353 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24354 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24355 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24356 +
24357 + if (err)
24358 + break;
24359 +
24360 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24361 + regs->r11 = addr1;
24362 + regs->r10 = addr2;
24363 + if (stcclc == 0xF8)
24364 + regs->flags &= ~X86_EFLAGS_CF;
24365 + else
24366 + regs->flags |= X86_EFLAGS_CF;
24367 + regs->ip = addr1;
24368 + return 2;
24369 + }
24370 + } while (0);
24371 +
24372 + do { /* PaX: gcc trampoline emulation #1 */
24373 + unsigned short mov1, mov2, jmp1;
24374 + unsigned char jmp2;
24375 + unsigned int addr1;
24376 + unsigned long addr2;
24377 +
24378 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24379 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24380 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24381 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24382 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24383 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24384 +
24385 + if (err)
24386 + break;
24387 +
24388 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24389 + regs->r11 = addr1;
24390 + regs->r10 = addr2;
24391 + regs->ip = addr1;
24392 + return 2;
24393 + }
24394 + } while (0);
24395 +
24396 + do { /* PaX: gcc trampoline emulation #2 */
24397 + unsigned short mov1, mov2, jmp1;
24398 + unsigned char jmp2;
24399 + unsigned long addr1, addr2;
24400 +
24401 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24402 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24403 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24404 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24405 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24406 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24407 +
24408 + if (err)
24409 + break;
24410 +
24411 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24412 + regs->r11 = addr1;
24413 + regs->r10 = addr2;
24414 + regs->ip = addr1;
24415 + return 2;
24416 + }
24417 + } while (0);
24418 +
24419 + return 1; /* PaX in action */
24420 +}
24421 +#endif
24422 +
24423 +/*
24424 + * PaX: decide what to do with offenders (regs->ip = fault address)
24425 + *
24426 + * returns 1 when task should be killed
24427 + * 2 when gcc trampoline was detected
24428 + */
24429 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24430 +{
24431 + if (v8086_mode(regs))
24432 + return 1;
24433 +
24434 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24435 + return 1;
24436 +
24437 +#ifdef CONFIG_X86_32
24438 + return pax_handle_fetch_fault_32(regs);
24439 +#else
24440 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24441 + return pax_handle_fetch_fault_32(regs);
24442 + else
24443 + return pax_handle_fetch_fault_64(regs);
24444 +#endif
24445 +}
24446 +#endif
24447 +
24448 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24449 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24450 +{
24451 + long i;
24452 +
24453 + printk(KERN_ERR "PAX: bytes at PC: ");
24454 + for (i = 0; i < 20; i++) {
24455 + unsigned char c;
24456 + if (get_user(c, (unsigned char __force_user *)pc+i))
24457 + printk(KERN_CONT "?? ");
24458 + else
24459 + printk(KERN_CONT "%02x ", c);
24460 + }
24461 + printk("\n");
24462 +
24463 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24464 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24465 + unsigned long c;
24466 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24467 +#ifdef CONFIG_X86_32
24468 + printk(KERN_CONT "???????? ");
24469 +#else
24470 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24471 + printk(KERN_CONT "???????? ???????? ");
24472 + else
24473 + printk(KERN_CONT "???????????????? ");
24474 +#endif
24475 + } else {
24476 +#ifdef CONFIG_X86_64
24477 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24478 + printk(KERN_CONT "%08x ", (unsigned int)c);
24479 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24480 + } else
24481 +#endif
24482 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24483 + }
24484 + }
24485 + printk("\n");
24486 +}
24487 +#endif
24488 +
24489 +/**
24490 + * probe_kernel_write(): safely attempt to write to a location
24491 + * @dst: address to write to
24492 + * @src: pointer to the data that shall be written
24493 + * @size: size of the data chunk
24494 + *
24495 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24496 + * happens, handle that and return -EFAULT.
24497 + */
24498 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24499 +{
24500 + long ret;
24501 + mm_segment_t old_fs = get_fs();
24502 +
24503 + set_fs(KERNEL_DS);
24504 + pagefault_disable();
24505 + pax_open_kernel();
24506 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24507 + pax_close_kernel();
24508 + pagefault_enable();
24509 + set_fs(old_fs);
24510 +
24511 + return ret ? -EFAULT : 0;
24512 +}
24513 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24514 index dd74e46..7d26398 100644
24515 --- a/arch/x86/mm/gup.c
24516 +++ b/arch/x86/mm/gup.c
24517 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24518 addr = start;
24519 len = (unsigned long) nr_pages << PAGE_SHIFT;
24520 end = start + len;
24521 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24522 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24523 (void __user *)start, len)))
24524 return 0;
24525
24526 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24527 index 6f31ee5..8ee4164 100644
24528 --- a/arch/x86/mm/highmem_32.c
24529 +++ b/arch/x86/mm/highmem_32.c
24530 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24531 idx = type + KM_TYPE_NR*smp_processor_id();
24532 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24533 BUG_ON(!pte_none(*(kmap_pte-idx)));
24534 +
24535 + pax_open_kernel();
24536 set_pte(kmap_pte-idx, mk_pte(page, prot));
24537 + pax_close_kernel();
24538 +
24539 arch_flush_lazy_mmu_mode();
24540
24541 return (void *)vaddr;
24542 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24543 index 937bff5..d777418 100644
24544 --- a/arch/x86/mm/hugetlbpage.c
24545 +++ b/arch/x86/mm/hugetlbpage.c
24546 @@ -276,13 +276,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24547 struct hstate *h = hstate_file(file);
24548 struct mm_struct *mm = current->mm;
24549 struct vm_area_struct *vma;
24550 - unsigned long start_addr;
24551 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24552 +
24553 +#ifdef CONFIG_PAX_SEGMEXEC
24554 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24555 + pax_task_size = SEGMEXEC_TASK_SIZE;
24556 +#endif
24557 +
24558 + pax_task_size -= PAGE_SIZE;
24559
24560 if (len > mm->cached_hole_size) {
24561 - start_addr = mm->free_area_cache;
24562 + start_addr = mm->free_area_cache;
24563 } else {
24564 - start_addr = TASK_UNMAPPED_BASE;
24565 - mm->cached_hole_size = 0;
24566 + start_addr = mm->mmap_base;
24567 + mm->cached_hole_size = 0;
24568 }
24569
24570 full_search:
24571 @@ -290,26 +297,27 @@ full_search:
24572
24573 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24574 /* At this point: (!vma || addr < vma->vm_end). */
24575 - if (TASK_SIZE - len < addr) {
24576 + if (pax_task_size - len < addr) {
24577 /*
24578 * Start a new search - just in case we missed
24579 * some holes.
24580 */
24581 - if (start_addr != TASK_UNMAPPED_BASE) {
24582 - start_addr = TASK_UNMAPPED_BASE;
24583 + if (start_addr != mm->mmap_base) {
24584 + start_addr = mm->mmap_base;
24585 mm->cached_hole_size = 0;
24586 goto full_search;
24587 }
24588 return -ENOMEM;
24589 }
24590 - if (!vma || addr + len <= vma->vm_start) {
24591 - mm->free_area_cache = addr + len;
24592 - return addr;
24593 - }
24594 + if (check_heap_stack_gap(vma, addr, len))
24595 + break;
24596 if (addr + mm->cached_hole_size < vma->vm_start)
24597 mm->cached_hole_size = vma->vm_start - addr;
24598 addr = ALIGN(vma->vm_end, huge_page_size(h));
24599 }
24600 +
24601 + mm->free_area_cache = addr + len;
24602 + return addr;
24603 }
24604
24605 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24606 @@ -320,9 +328,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24607 struct mm_struct *mm = current->mm;
24608 struct vm_area_struct *vma;
24609 unsigned long base = mm->mmap_base;
24610 - unsigned long addr = addr0;
24611 + unsigned long addr;
24612 unsigned long largest_hole = mm->cached_hole_size;
24613 - unsigned long start_addr;
24614
24615 /* don't allow allocations above current base */
24616 if (mm->free_area_cache > base)
24617 @@ -332,16 +339,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24618 largest_hole = 0;
24619 mm->free_area_cache = base;
24620 }
24621 -try_again:
24622 - start_addr = mm->free_area_cache;
24623
24624 /* make sure it can fit in the remaining address space */
24625 if (mm->free_area_cache < len)
24626 goto fail;
24627
24628 /* either no address requested or can't fit in requested address hole */
24629 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24630 + addr = mm->free_area_cache - len;
24631 do {
24632 + addr &= huge_page_mask(h);
24633 /*
24634 * Lookup failure means no vma is above this address,
24635 * i.e. return with success:
24636 @@ -350,10 +356,10 @@ try_again:
24637 if (!vma)
24638 return addr;
24639
24640 - if (addr + len <= vma->vm_start) {
24641 + if (check_heap_stack_gap(vma, addr, len)) {
24642 /* remember the address as a hint for next time */
24643 - mm->cached_hole_size = largest_hole;
24644 - return (mm->free_area_cache = addr);
24645 + mm->cached_hole_size = largest_hole;
24646 + return (mm->free_area_cache = addr);
24647 } else if (mm->free_area_cache == vma->vm_end) {
24648 /* pull free_area_cache down to the first hole */
24649 mm->free_area_cache = vma->vm_start;
24650 @@ -362,29 +368,34 @@ try_again:
24651
24652 /* remember the largest hole we saw so far */
24653 if (addr + largest_hole < vma->vm_start)
24654 - largest_hole = vma->vm_start - addr;
24655 + largest_hole = vma->vm_start - addr;
24656
24657 /* try just below the current vma->vm_start */
24658 - addr = (vma->vm_start - len) & huge_page_mask(h);
24659 - } while (len <= vma->vm_start);
24660 + addr = skip_heap_stack_gap(vma, len);
24661 + } while (!IS_ERR_VALUE(addr));
24662
24663 fail:
24664 /*
24665 - * if hint left us with no space for the requested
24666 - * mapping then try again:
24667 - */
24668 - if (start_addr != base) {
24669 - mm->free_area_cache = base;
24670 - largest_hole = 0;
24671 - goto try_again;
24672 - }
24673 - /*
24674 * A failed mmap() very likely causes application failure,
24675 * so fall back to the bottom-up function here. This scenario
24676 * can happen with large stack limits and large mmap()
24677 * allocations.
24678 */
24679 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24680 +
24681 +#ifdef CONFIG_PAX_SEGMEXEC
24682 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24683 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24684 + else
24685 +#endif
24686 +
24687 + mm->mmap_base = TASK_UNMAPPED_BASE;
24688 +
24689 +#ifdef CONFIG_PAX_RANDMMAP
24690 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24691 + mm->mmap_base += mm->delta_mmap;
24692 +#endif
24693 +
24694 + mm->free_area_cache = mm->mmap_base;
24695 mm->cached_hole_size = ~0UL;
24696 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24697 len, pgoff, flags);
24698 @@ -392,6 +403,7 @@ fail:
24699 /*
24700 * Restore the topdown base:
24701 */
24702 + mm->mmap_base = base;
24703 mm->free_area_cache = base;
24704 mm->cached_hole_size = ~0UL;
24705
24706 @@ -405,10 +417,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24707 struct hstate *h = hstate_file(file);
24708 struct mm_struct *mm = current->mm;
24709 struct vm_area_struct *vma;
24710 + unsigned long pax_task_size = TASK_SIZE;
24711
24712 if (len & ~huge_page_mask(h))
24713 return -EINVAL;
24714 - if (len > TASK_SIZE)
24715 +
24716 +#ifdef CONFIG_PAX_SEGMEXEC
24717 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24718 + pax_task_size = SEGMEXEC_TASK_SIZE;
24719 +#endif
24720 +
24721 + pax_task_size -= PAGE_SIZE;
24722 +
24723 + if (len > pax_task_size)
24724 return -ENOMEM;
24725
24726 if (flags & MAP_FIXED) {
24727 @@ -420,8 +441,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24728 if (addr) {
24729 addr = ALIGN(addr, huge_page_size(h));
24730 vma = find_vma(mm, addr);
24731 - if (TASK_SIZE - len >= addr &&
24732 - (!vma || addr + len <= vma->vm_start))
24733 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24734 return addr;
24735 }
24736 if (mm->get_unmapped_area == arch_get_unmapped_area)
24737 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24738 index d7aea41..0fc945b 100644
24739 --- a/arch/x86/mm/init.c
24740 +++ b/arch/x86/mm/init.c
24741 @@ -4,6 +4,7 @@
24742 #include <linux/swap.h>
24743 #include <linux/memblock.h>
24744 #include <linux/bootmem.h> /* for max_low_pfn */
24745 +#include <linux/tboot.h>
24746
24747 #include <asm/cacheflush.h>
24748 #include <asm/e820.h>
24749 @@ -16,6 +17,8 @@
24750 #include <asm/tlb.h>
24751 #include <asm/proto.h>
24752 #include <asm/dma.h> /* for MAX_DMA_PFN */
24753 +#include <asm/desc.h>
24754 +#include <asm/bios_ebda.h>
24755
24756 unsigned long __initdata pgt_buf_start;
24757 unsigned long __meminitdata pgt_buf_end;
24758 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24759 {
24760 int i;
24761 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24762 - unsigned long start = 0, good_end;
24763 + unsigned long start = 0x100000, good_end;
24764 phys_addr_t base;
24765
24766 for (i = 0; i < nr_range; i++) {
24767 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24768 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24769 * mmio resources as well as potential bios/acpi data regions.
24770 */
24771 +
24772 +#ifdef CONFIG_GRKERNSEC_KMEM
24773 +static unsigned int ebda_start __read_only;
24774 +static unsigned int ebda_end __read_only;
24775 +#endif
24776 +
24777 int devmem_is_allowed(unsigned long pagenr)
24778 {
24779 - if (pagenr < 256)
24780 +#ifdef CONFIG_GRKERNSEC_KMEM
24781 + /* allow BDA */
24782 + if (!pagenr)
24783 return 1;
24784 + /* allow EBDA */
24785 + if (pagenr >= ebda_start && pagenr < ebda_end)
24786 + return 1;
24787 + /* if tboot is in use, allow access to its hardcoded serial log range */
24788 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24789 + return 1;
24790 +#else
24791 + if (!pagenr)
24792 + return 1;
24793 +#ifdef CONFIG_VM86
24794 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24795 + return 1;
24796 +#endif
24797 +#endif
24798 +
24799 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24800 + return 1;
24801 +#ifdef CONFIG_GRKERNSEC_KMEM
24802 + /* throw out everything else below 1MB */
24803 + if (pagenr <= 256)
24804 + return 0;
24805 +#endif
24806 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24807 return 0;
24808 if (!page_is_ram(pagenr))
24809 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24810 #endif
24811 }
24812
24813 +#ifdef CONFIG_GRKERNSEC_KMEM
24814 +static inline void gr_init_ebda(void)
24815 +{
24816 + unsigned int ebda_addr;
24817 + unsigned int ebda_size = 0;
24818 +
24819 + ebda_addr = get_bios_ebda();
24820 + if (ebda_addr) {
24821 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24822 + ebda_size <<= 10;
24823 + }
24824 + if (ebda_addr && ebda_size) {
24825 + ebda_start = ebda_addr >> PAGE_SHIFT;
24826 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24827 + } else {
24828 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24829 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24830 + }
24831 +}
24832 +#else
24833 +static inline void gr_init_ebda(void) { }
24834 +#endif
24835 +
24836 void free_initmem(void)
24837 {
24838 +#ifdef CONFIG_PAX_KERNEXEC
24839 +#ifdef CONFIG_X86_32
24840 + /* PaX: limit KERNEL_CS to actual size */
24841 + unsigned long addr, limit;
24842 + struct desc_struct d;
24843 + int cpu;
24844 +#else
24845 + pgd_t *pgd;
24846 + pud_t *pud;
24847 + pmd_t *pmd;
24848 + unsigned long addr, end;
24849 +#endif
24850 +#endif
24851 +
24852 + gr_init_ebda();
24853 +
24854 +#ifdef CONFIG_PAX_KERNEXEC
24855 +#ifdef CONFIG_X86_32
24856 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24857 + limit = (limit - 1UL) >> PAGE_SHIFT;
24858 +
24859 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24860 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24861 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24862 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24863 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24864 + }
24865 +
24866 + /* PaX: make KERNEL_CS read-only */
24867 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24868 + if (!paravirt_enabled())
24869 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24870 +/*
24871 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24872 + pgd = pgd_offset_k(addr);
24873 + pud = pud_offset(pgd, addr);
24874 + pmd = pmd_offset(pud, addr);
24875 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24876 + }
24877 +*/
24878 +#ifdef CONFIG_X86_PAE
24879 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24880 +/*
24881 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24882 + pgd = pgd_offset_k(addr);
24883 + pud = pud_offset(pgd, addr);
24884 + pmd = pmd_offset(pud, addr);
24885 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24886 + }
24887 +*/
24888 +#endif
24889 +
24890 +#ifdef CONFIG_MODULES
24891 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24892 +#endif
24893 +
24894 +#else
24895 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24896 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24897 + pgd = pgd_offset_k(addr);
24898 + pud = pud_offset(pgd, addr);
24899 + pmd = pmd_offset(pud, addr);
24900 + if (!pmd_present(*pmd))
24901 + continue;
24902 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24903 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24904 + else
24905 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24906 + }
24907 +
24908 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24909 + end = addr + KERNEL_IMAGE_SIZE;
24910 + for (; addr < end; addr += PMD_SIZE) {
24911 + pgd = pgd_offset_k(addr);
24912 + pud = pud_offset(pgd, addr);
24913 + pmd = pmd_offset(pud, addr);
24914 + if (!pmd_present(*pmd))
24915 + continue;
24916 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24917 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24918 + }
24919 +#endif
24920 +
24921 + flush_tlb_all();
24922 +#endif
24923 +
24924 free_init_pages("unused kernel memory",
24925 (unsigned long)(&__init_begin),
24926 (unsigned long)(&__init_end));
24927 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24928 index 11a5800..4bd9977 100644
24929 --- a/arch/x86/mm/init_32.c
24930 +++ b/arch/x86/mm/init_32.c
24931 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24932 }
24933
24934 /*
24935 - * Creates a middle page table and puts a pointer to it in the
24936 - * given global directory entry. This only returns the gd entry
24937 - * in non-PAE compilation mode, since the middle layer is folded.
24938 - */
24939 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24940 -{
24941 - pud_t *pud;
24942 - pmd_t *pmd_table;
24943 -
24944 -#ifdef CONFIG_X86_PAE
24945 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24946 - if (after_bootmem)
24947 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24948 - else
24949 - pmd_table = (pmd_t *)alloc_low_page();
24950 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24951 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24952 - pud = pud_offset(pgd, 0);
24953 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24954 -
24955 - return pmd_table;
24956 - }
24957 -#endif
24958 - pud = pud_offset(pgd, 0);
24959 - pmd_table = pmd_offset(pud, 0);
24960 -
24961 - return pmd_table;
24962 -}
24963 -
24964 -/*
24965 * Create a page table and place a pointer to it in a middle page
24966 * directory entry:
24967 */
24968 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24969 page_table = (pte_t *)alloc_low_page();
24970
24971 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24972 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24973 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24974 +#else
24975 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24976 +#endif
24977 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24978 }
24979
24980 return pte_offset_kernel(pmd, 0);
24981 }
24982
24983 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24984 +{
24985 + pud_t *pud;
24986 + pmd_t *pmd_table;
24987 +
24988 + pud = pud_offset(pgd, 0);
24989 + pmd_table = pmd_offset(pud, 0);
24990 +
24991 + return pmd_table;
24992 +}
24993 +
24994 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24995 {
24996 int pgd_idx = pgd_index(vaddr);
24997 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24998 int pgd_idx, pmd_idx;
24999 unsigned long vaddr;
25000 pgd_t *pgd;
25001 + pud_t *pud;
25002 pmd_t *pmd;
25003 pte_t *pte = NULL;
25004
25005 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25006 pgd = pgd_base + pgd_idx;
25007
25008 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25009 - pmd = one_md_table_init(pgd);
25010 - pmd = pmd + pmd_index(vaddr);
25011 + pud = pud_offset(pgd, vaddr);
25012 + pmd = pmd_offset(pud, vaddr);
25013 +
25014 +#ifdef CONFIG_X86_PAE
25015 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25016 +#endif
25017 +
25018 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25019 pmd++, pmd_idx++) {
25020 pte = page_table_kmap_check(one_page_table_init(pmd),
25021 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25022 }
25023 }
25024
25025 -static inline int is_kernel_text(unsigned long addr)
25026 +static inline int is_kernel_text(unsigned long start, unsigned long end)
25027 {
25028 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
25029 - return 1;
25030 - return 0;
25031 + if ((start > ktla_ktva((unsigned long)_etext) ||
25032 + end <= ktla_ktva((unsigned long)_stext)) &&
25033 + (start > ktla_ktva((unsigned long)_einittext) ||
25034 + end <= ktla_ktva((unsigned long)_sinittext)) &&
25035 +
25036 +#ifdef CONFIG_ACPI_SLEEP
25037 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25038 +#endif
25039 +
25040 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25041 + return 0;
25042 + return 1;
25043 }
25044
25045 /*
25046 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
25047 unsigned long last_map_addr = end;
25048 unsigned long start_pfn, end_pfn;
25049 pgd_t *pgd_base = swapper_pg_dir;
25050 - int pgd_idx, pmd_idx, pte_ofs;
25051 + unsigned int pgd_idx, pmd_idx, pte_ofs;
25052 unsigned long pfn;
25053 pgd_t *pgd;
25054 + pud_t *pud;
25055 pmd_t *pmd;
25056 pte_t *pte;
25057 unsigned pages_2m, pages_4k;
25058 @@ -280,8 +281,13 @@ repeat:
25059 pfn = start_pfn;
25060 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25061 pgd = pgd_base + pgd_idx;
25062 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25063 - pmd = one_md_table_init(pgd);
25064 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25065 + pud = pud_offset(pgd, 0);
25066 + pmd = pmd_offset(pud, 0);
25067 +
25068 +#ifdef CONFIG_X86_PAE
25069 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25070 +#endif
25071
25072 if (pfn >= end_pfn)
25073 continue;
25074 @@ -293,14 +299,13 @@ repeat:
25075 #endif
25076 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25077 pmd++, pmd_idx++) {
25078 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25079 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25080
25081 /*
25082 * Map with big pages if possible, otherwise
25083 * create normal page tables:
25084 */
25085 if (use_pse) {
25086 - unsigned int addr2;
25087 pgprot_t prot = PAGE_KERNEL_LARGE;
25088 /*
25089 * first pass will use the same initial
25090 @@ -310,11 +315,7 @@ repeat:
25091 __pgprot(PTE_IDENT_ATTR |
25092 _PAGE_PSE);
25093
25094 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25095 - PAGE_OFFSET + PAGE_SIZE-1;
25096 -
25097 - if (is_kernel_text(addr) ||
25098 - is_kernel_text(addr2))
25099 + if (is_kernel_text(address, address + PMD_SIZE))
25100 prot = PAGE_KERNEL_LARGE_EXEC;
25101
25102 pages_2m++;
25103 @@ -331,7 +332,7 @@ repeat:
25104 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25105 pte += pte_ofs;
25106 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25107 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25108 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25109 pgprot_t prot = PAGE_KERNEL;
25110 /*
25111 * first pass will use the same initial
25112 @@ -339,7 +340,7 @@ repeat:
25113 */
25114 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25115
25116 - if (is_kernel_text(addr))
25117 + if (is_kernel_text(address, address + PAGE_SIZE))
25118 prot = PAGE_KERNEL_EXEC;
25119
25120 pages_4k++;
25121 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
25122
25123 pud = pud_offset(pgd, va);
25124 pmd = pmd_offset(pud, va);
25125 - if (!pmd_present(*pmd))
25126 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25127 break;
25128
25129 pte = pte_offset_kernel(pmd, va);
25130 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
25131
25132 static void __init pagetable_init(void)
25133 {
25134 - pgd_t *pgd_base = swapper_pg_dir;
25135 -
25136 - permanent_kmaps_init(pgd_base);
25137 + permanent_kmaps_init(swapper_pg_dir);
25138 }
25139
25140 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25141 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25142 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25143
25144 /* user-defined highmem size */
25145 @@ -731,6 +730,12 @@ void __init mem_init(void)
25146
25147 pci_iommu_alloc();
25148
25149 +#ifdef CONFIG_PAX_PER_CPU_PGD
25150 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25151 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25152 + KERNEL_PGD_PTRS);
25153 +#endif
25154 +
25155 #ifdef CONFIG_FLATMEM
25156 BUG_ON(!mem_map);
25157 #endif
25158 @@ -757,7 +762,7 @@ void __init mem_init(void)
25159 reservedpages++;
25160
25161 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25162 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25163 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25164 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25165
25166 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25167 @@ -798,10 +803,10 @@ void __init mem_init(void)
25168 ((unsigned long)&__init_end -
25169 (unsigned long)&__init_begin) >> 10,
25170
25171 - (unsigned long)&_etext, (unsigned long)&_edata,
25172 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25173 + (unsigned long)&_sdata, (unsigned long)&_edata,
25174 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25175
25176 - (unsigned long)&_text, (unsigned long)&_etext,
25177 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25178 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25179
25180 /*
25181 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
25182 if (!kernel_set_to_readonly)
25183 return;
25184
25185 + start = ktla_ktva(start);
25186 pr_debug("Set kernel text: %lx - %lx for read write\n",
25187 start, start+size);
25188
25189 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
25190 if (!kernel_set_to_readonly)
25191 return;
25192
25193 + start = ktla_ktva(start);
25194 pr_debug("Set kernel text: %lx - %lx for read only\n",
25195 start, start+size);
25196
25197 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
25198 unsigned long start = PFN_ALIGN(_text);
25199 unsigned long size = PFN_ALIGN(_etext) - start;
25200
25201 + start = ktla_ktva(start);
25202 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25203 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25204 size >> 10);
25205 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25206 index 3baff25..8b37564 100644
25207 --- a/arch/x86/mm/init_64.c
25208 +++ b/arch/x86/mm/init_64.c
25209 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25210 * around without checking the pgd every time.
25211 */
25212
25213 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25214 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25215 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25216
25217 int force_personality32;
25218 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25219
25220 for (address = start; address <= end; address += PGDIR_SIZE) {
25221 const pgd_t *pgd_ref = pgd_offset_k(address);
25222 +
25223 +#ifdef CONFIG_PAX_PER_CPU_PGD
25224 + unsigned long cpu;
25225 +#else
25226 struct page *page;
25227 +#endif
25228
25229 if (pgd_none(*pgd_ref))
25230 continue;
25231
25232 spin_lock(&pgd_lock);
25233 +
25234 +#ifdef CONFIG_PAX_PER_CPU_PGD
25235 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25236 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25237 +#else
25238 list_for_each_entry(page, &pgd_list, lru) {
25239 pgd_t *pgd;
25240 spinlock_t *pgt_lock;
25241 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25242 /* the pgt_lock only for Xen */
25243 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25244 spin_lock(pgt_lock);
25245 +#endif
25246
25247 if (pgd_none(*pgd))
25248 set_pgd(pgd, *pgd_ref);
25249 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25250 BUG_ON(pgd_page_vaddr(*pgd)
25251 != pgd_page_vaddr(*pgd_ref));
25252
25253 +#ifndef CONFIG_PAX_PER_CPU_PGD
25254 spin_unlock(pgt_lock);
25255 +#endif
25256 +
25257 }
25258 spin_unlock(&pgd_lock);
25259 }
25260 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25261 {
25262 if (pgd_none(*pgd)) {
25263 pud_t *pud = (pud_t *)spp_getpage();
25264 - pgd_populate(&init_mm, pgd, pud);
25265 + pgd_populate_kernel(&init_mm, pgd, pud);
25266 if (pud != pud_offset(pgd, 0))
25267 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25268 pud, pud_offset(pgd, 0));
25269 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25270 {
25271 if (pud_none(*pud)) {
25272 pmd_t *pmd = (pmd_t *) spp_getpage();
25273 - pud_populate(&init_mm, pud, pmd);
25274 + pud_populate_kernel(&init_mm, pud, pmd);
25275 if (pmd != pmd_offset(pud, 0))
25276 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25277 pmd, pmd_offset(pud, 0));
25278 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25279 pmd = fill_pmd(pud, vaddr);
25280 pte = fill_pte(pmd, vaddr);
25281
25282 + pax_open_kernel();
25283 set_pte(pte, new_pte);
25284 + pax_close_kernel();
25285
25286 /*
25287 * It's enough to flush this one mapping.
25288 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25289 pgd = pgd_offset_k((unsigned long)__va(phys));
25290 if (pgd_none(*pgd)) {
25291 pud = (pud_t *) spp_getpage();
25292 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25293 - _PAGE_USER));
25294 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25295 }
25296 pud = pud_offset(pgd, (unsigned long)__va(phys));
25297 if (pud_none(*pud)) {
25298 pmd = (pmd_t *) spp_getpage();
25299 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25300 - _PAGE_USER));
25301 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25302 }
25303 pmd = pmd_offset(pud, phys);
25304 BUG_ON(!pmd_none(*pmd));
25305 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25306 if (pfn >= pgt_buf_top)
25307 panic("alloc_low_page: ran out of memory");
25308
25309 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25310 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25311 clear_page(adr);
25312 *phys = pfn * PAGE_SIZE;
25313 return adr;
25314 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25315
25316 phys = __pa(virt);
25317 left = phys & (PAGE_SIZE - 1);
25318 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25319 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25320 adr = (void *)(((unsigned long)adr) | left);
25321
25322 return adr;
25323 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25324 unmap_low_page(pmd);
25325
25326 spin_lock(&init_mm.page_table_lock);
25327 - pud_populate(&init_mm, pud, __va(pmd_phys));
25328 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25329 spin_unlock(&init_mm.page_table_lock);
25330 }
25331 __flush_tlb_all();
25332 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25333 unmap_low_page(pud);
25334
25335 spin_lock(&init_mm.page_table_lock);
25336 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25337 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25338 spin_unlock(&init_mm.page_table_lock);
25339 pgd_changed = true;
25340 }
25341 @@ -691,6 +705,12 @@ void __init mem_init(void)
25342
25343 pci_iommu_alloc();
25344
25345 +#ifdef CONFIG_PAX_PER_CPU_PGD
25346 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25347 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25348 + KERNEL_PGD_PTRS);
25349 +#endif
25350 +
25351 /* clear_bss() already clear the empty_zero_page */
25352
25353 reservedpages = 0;
25354 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25355 static struct vm_area_struct gate_vma = {
25356 .vm_start = VSYSCALL_START,
25357 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25358 - .vm_page_prot = PAGE_READONLY_EXEC,
25359 - .vm_flags = VM_READ | VM_EXEC
25360 + .vm_page_prot = PAGE_READONLY,
25361 + .vm_flags = VM_READ
25362 };
25363
25364 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25365 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25366
25367 const char *arch_vma_name(struct vm_area_struct *vma)
25368 {
25369 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25370 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25371 return "[vdso]";
25372 if (vma == &gate_vma)
25373 return "[vsyscall]";
25374 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25375 index 7b179b4..6bd1777 100644
25376 --- a/arch/x86/mm/iomap_32.c
25377 +++ b/arch/x86/mm/iomap_32.c
25378 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25379 type = kmap_atomic_idx_push();
25380 idx = type + KM_TYPE_NR * smp_processor_id();
25381 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25382 +
25383 + pax_open_kernel();
25384 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25385 + pax_close_kernel();
25386 +
25387 arch_flush_lazy_mmu_mode();
25388
25389 return (void *)vaddr;
25390 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25391 index 78fe3f1..8293b6f 100644
25392 --- a/arch/x86/mm/ioremap.c
25393 +++ b/arch/x86/mm/ioremap.c
25394 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25395 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25396 int is_ram = page_is_ram(pfn);
25397
25398 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25399 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25400 return NULL;
25401 WARN_ON_ONCE(is_ram);
25402 }
25403 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25404
25405 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25406 if (page_is_ram(start >> PAGE_SHIFT))
25407 +#ifdef CONFIG_HIGHMEM
25408 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25409 +#endif
25410 return __va(phys);
25411
25412 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25413 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25414 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25415
25416 static __initdata int after_paging_init;
25417 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25418 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25419
25420 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25421 {
25422 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25423 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25424
25425 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25426 - memset(bm_pte, 0, sizeof(bm_pte));
25427 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25428 + pmd_populate_user(&init_mm, pmd, bm_pte);
25429
25430 /*
25431 * The boot-ioremap range spans multiple pmds, for which
25432 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25433 index d87dd6d..bf3fa66 100644
25434 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25435 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25436 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25437 * memory (e.g. tracked pages)? For now, we need this to avoid
25438 * invoking kmemcheck for PnP BIOS calls.
25439 */
25440 - if (regs->flags & X86_VM_MASK)
25441 + if (v8086_mode(regs))
25442 return false;
25443 - if (regs->cs != __KERNEL_CS)
25444 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25445 return false;
25446
25447 pte = kmemcheck_pte_lookup(address);
25448 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25449 index 845df68..1d8d29f 100644
25450 --- a/arch/x86/mm/mmap.c
25451 +++ b/arch/x86/mm/mmap.c
25452 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25453 * Leave an at least ~128 MB hole with possible stack randomization.
25454 */
25455 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25456 -#define MAX_GAP (TASK_SIZE/6*5)
25457 +#define MAX_GAP (pax_task_size/6*5)
25458
25459 static int mmap_is_legacy(void)
25460 {
25461 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25462 return rnd << PAGE_SHIFT;
25463 }
25464
25465 -static unsigned long mmap_base(void)
25466 +static unsigned long mmap_base(struct mm_struct *mm)
25467 {
25468 unsigned long gap = rlimit(RLIMIT_STACK);
25469 + unsigned long pax_task_size = TASK_SIZE;
25470 +
25471 +#ifdef CONFIG_PAX_SEGMEXEC
25472 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25473 + pax_task_size = SEGMEXEC_TASK_SIZE;
25474 +#endif
25475
25476 if (gap < MIN_GAP)
25477 gap = MIN_GAP;
25478 else if (gap > MAX_GAP)
25479 gap = MAX_GAP;
25480
25481 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25482 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25483 }
25484
25485 /*
25486 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25487 * does, but not when emulating X86_32
25488 */
25489 -static unsigned long mmap_legacy_base(void)
25490 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25491 {
25492 - if (mmap_is_ia32())
25493 + if (mmap_is_ia32()) {
25494 +
25495 +#ifdef CONFIG_PAX_SEGMEXEC
25496 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25497 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25498 + else
25499 +#endif
25500 +
25501 return TASK_UNMAPPED_BASE;
25502 - else
25503 + } else
25504 return TASK_UNMAPPED_BASE + mmap_rnd();
25505 }
25506
25507 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25508 void arch_pick_mmap_layout(struct mm_struct *mm)
25509 {
25510 if (mmap_is_legacy()) {
25511 - mm->mmap_base = mmap_legacy_base();
25512 + mm->mmap_base = mmap_legacy_base(mm);
25513 +
25514 +#ifdef CONFIG_PAX_RANDMMAP
25515 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25516 + mm->mmap_base += mm->delta_mmap;
25517 +#endif
25518 +
25519 mm->get_unmapped_area = arch_get_unmapped_area;
25520 mm->unmap_area = arch_unmap_area;
25521 } else {
25522 - mm->mmap_base = mmap_base();
25523 + mm->mmap_base = mmap_base(mm);
25524 +
25525 +#ifdef CONFIG_PAX_RANDMMAP
25526 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25527 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25528 +#endif
25529 +
25530 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25531 mm->unmap_area = arch_unmap_area_topdown;
25532 }
25533 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25534 index dc0b727..dc9d71a 100644
25535 --- a/arch/x86/mm/mmio-mod.c
25536 +++ b/arch/x86/mm/mmio-mod.c
25537 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25538 break;
25539 default:
25540 {
25541 - unsigned char *ip = (unsigned char *)instptr;
25542 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25543 my_trace->opcode = MMIO_UNKNOWN_OP;
25544 my_trace->width = 0;
25545 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25546 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25547 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25548 void __iomem *addr)
25549 {
25550 - static atomic_t next_id;
25551 + static atomic_unchecked_t next_id;
25552 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25553 /* These are page-unaligned. */
25554 struct mmiotrace_map map = {
25555 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25556 .private = trace
25557 },
25558 .phys = offset,
25559 - .id = atomic_inc_return(&next_id)
25560 + .id = atomic_inc_return_unchecked(&next_id)
25561 };
25562 map.map_id = trace->id;
25563
25564 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25565 index b008656..773eac2 100644
25566 --- a/arch/x86/mm/pageattr-test.c
25567 +++ b/arch/x86/mm/pageattr-test.c
25568 @@ -36,7 +36,7 @@ enum {
25569
25570 static int pte_testbit(pte_t pte)
25571 {
25572 - return pte_flags(pte) & _PAGE_UNUSED1;
25573 + return pte_flags(pte) & _PAGE_CPA_TEST;
25574 }
25575
25576 struct split_state {
25577 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25578 index a718e0d..77419bc 100644
25579 --- a/arch/x86/mm/pageattr.c
25580 +++ b/arch/x86/mm/pageattr.c
25581 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25582 */
25583 #ifdef CONFIG_PCI_BIOS
25584 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25585 - pgprot_val(forbidden) |= _PAGE_NX;
25586 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25587 #endif
25588
25589 /*
25590 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25591 * Does not cover __inittext since that is gone later on. On
25592 * 64bit we do not enforce !NX on the low mapping
25593 */
25594 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25595 - pgprot_val(forbidden) |= _PAGE_NX;
25596 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25597 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25598
25599 +#ifdef CONFIG_DEBUG_RODATA
25600 /*
25601 * The .rodata section needs to be read-only. Using the pfn
25602 * catches all aliases.
25603 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25604 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25605 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25606 pgprot_val(forbidden) |= _PAGE_RW;
25607 +#endif
25608
25609 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25610 /*
25611 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25612 }
25613 #endif
25614
25615 +#ifdef CONFIG_PAX_KERNEXEC
25616 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
25617 + pgprot_val(forbidden) |= _PAGE_RW;
25618 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25619 + }
25620 +#endif
25621 +
25622 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25623
25624 return prot;
25625 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25626 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25627 {
25628 /* change init_mm */
25629 + pax_open_kernel();
25630 set_pte_atomic(kpte, pte);
25631 +
25632 #ifdef CONFIG_X86_32
25633 if (!SHARED_KERNEL_PMD) {
25634 +
25635 +#ifdef CONFIG_PAX_PER_CPU_PGD
25636 + unsigned long cpu;
25637 +#else
25638 struct page *page;
25639 +#endif
25640
25641 +#ifdef CONFIG_PAX_PER_CPU_PGD
25642 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25643 + pgd_t *pgd = get_cpu_pgd(cpu);
25644 +#else
25645 list_for_each_entry(page, &pgd_list, lru) {
25646 - pgd_t *pgd;
25647 + pgd_t *pgd = (pgd_t *)page_address(page);
25648 +#endif
25649 +
25650 pud_t *pud;
25651 pmd_t *pmd;
25652
25653 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25654 + pgd += pgd_index(address);
25655 pud = pud_offset(pgd, address);
25656 pmd = pmd_offset(pud, address);
25657 set_pte_atomic((pte_t *)pmd, pte);
25658 }
25659 }
25660 #endif
25661 + pax_close_kernel();
25662 }
25663
25664 static int
25665 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25666 index 0eb572e..92f5c1e 100644
25667 --- a/arch/x86/mm/pat.c
25668 +++ b/arch/x86/mm/pat.c
25669 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25670
25671 if (!entry) {
25672 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25673 - current->comm, current->pid, start, end - 1);
25674 + current->comm, task_pid_nr(current), start, end - 1);
25675 return -EINVAL;
25676 }
25677
25678 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25679
25680 while (cursor < to) {
25681 if (!devmem_is_allowed(pfn)) {
25682 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25683 - current->comm, from, to - 1);
25684 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25685 + current->comm, from, to - 1, cursor);
25686 return 0;
25687 }
25688 cursor += PAGE_SIZE;
25689 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25690 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25691 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25692 "for [mem %#010Lx-%#010Lx]\n",
25693 - current->comm, current->pid,
25694 + current->comm, task_pid_nr(current),
25695 cattr_name(flags),
25696 base, (unsigned long long)(base + size-1));
25697 return -EINVAL;
25698 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25699 flags = lookup_memtype(paddr);
25700 if (want_flags != flags) {
25701 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25702 - current->comm, current->pid,
25703 + current->comm, task_pid_nr(current),
25704 cattr_name(want_flags),
25705 (unsigned long long)paddr,
25706 (unsigned long long)(paddr + size - 1),
25707 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25708 free_memtype(paddr, paddr + size);
25709 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25710 " for [mem %#010Lx-%#010Lx], got %s\n",
25711 - current->comm, current->pid,
25712 + current->comm, task_pid_nr(current),
25713 cattr_name(want_flags),
25714 (unsigned long long)paddr,
25715 (unsigned long long)(paddr + size - 1),
25716 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25717 index 9f0614d..92ae64a 100644
25718 --- a/arch/x86/mm/pf_in.c
25719 +++ b/arch/x86/mm/pf_in.c
25720 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25721 int i;
25722 enum reason_type rv = OTHERS;
25723
25724 - p = (unsigned char *)ins_addr;
25725 + p = (unsigned char *)ktla_ktva(ins_addr);
25726 p += skip_prefix(p, &prf);
25727 p += get_opcode(p, &opcode);
25728
25729 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25730 struct prefix_bits prf;
25731 int i;
25732
25733 - p = (unsigned char *)ins_addr;
25734 + p = (unsigned char *)ktla_ktva(ins_addr);
25735 p += skip_prefix(p, &prf);
25736 p += get_opcode(p, &opcode);
25737
25738 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25739 struct prefix_bits prf;
25740 int i;
25741
25742 - p = (unsigned char *)ins_addr;
25743 + p = (unsigned char *)ktla_ktva(ins_addr);
25744 p += skip_prefix(p, &prf);
25745 p += get_opcode(p, &opcode);
25746
25747 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25748 struct prefix_bits prf;
25749 int i;
25750
25751 - p = (unsigned char *)ins_addr;
25752 + p = (unsigned char *)ktla_ktva(ins_addr);
25753 p += skip_prefix(p, &prf);
25754 p += get_opcode(p, &opcode);
25755 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25756 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25757 struct prefix_bits prf;
25758 int i;
25759
25760 - p = (unsigned char *)ins_addr;
25761 + p = (unsigned char *)ktla_ktva(ins_addr);
25762 p += skip_prefix(p, &prf);
25763 p += get_opcode(p, &opcode);
25764 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25765 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25766 index 8573b83..4f3ed7e 100644
25767 --- a/arch/x86/mm/pgtable.c
25768 +++ b/arch/x86/mm/pgtable.c
25769 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25770 list_del(&page->lru);
25771 }
25772
25773 -#define UNSHARED_PTRS_PER_PGD \
25774 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25775 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25776 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25777
25778 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25779 +{
25780 + unsigned int count = USER_PGD_PTRS;
25781
25782 + while (count--)
25783 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25784 +}
25785 +#endif
25786 +
25787 +#ifdef CONFIG_PAX_PER_CPU_PGD
25788 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25789 +{
25790 + unsigned int count = USER_PGD_PTRS;
25791 +
25792 + while (count--) {
25793 + pgd_t pgd;
25794 +
25795 +#ifdef CONFIG_X86_64
25796 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25797 +#else
25798 + pgd = *src++;
25799 +#endif
25800 +
25801 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25802 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25803 +#endif
25804 +
25805 + *dst++ = pgd;
25806 + }
25807 +
25808 +}
25809 +#endif
25810 +
25811 +#ifdef CONFIG_X86_64
25812 +#define pxd_t pud_t
25813 +#define pyd_t pgd_t
25814 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25815 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25816 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25817 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25818 +#define PYD_SIZE PGDIR_SIZE
25819 +#else
25820 +#define pxd_t pmd_t
25821 +#define pyd_t pud_t
25822 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25823 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25824 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25825 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25826 +#define PYD_SIZE PUD_SIZE
25827 +#endif
25828 +
25829 +#ifdef CONFIG_PAX_PER_CPU_PGD
25830 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25831 +static inline void pgd_dtor(pgd_t *pgd) {}
25832 +#else
25833 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25834 {
25835 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25836 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25837 pgd_list_del(pgd);
25838 spin_unlock(&pgd_lock);
25839 }
25840 +#endif
25841
25842 /*
25843 * List of all pgd's needed for non-PAE so it can invalidate entries
25844 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25845 * -- wli
25846 */
25847
25848 -#ifdef CONFIG_X86_PAE
25849 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25850 /*
25851 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25852 * updating the top-level pagetable entries to guarantee the
25853 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25854 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25855 * and initialize the kernel pmds here.
25856 */
25857 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25858 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25859
25860 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25861 {
25862 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25863 */
25864 flush_tlb_mm(mm);
25865 }
25866 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25867 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25868 #else /* !CONFIG_X86_PAE */
25869
25870 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25871 -#define PREALLOCATED_PMDS 0
25872 +#define PREALLOCATED_PXDS 0
25873
25874 #endif /* CONFIG_X86_PAE */
25875
25876 -static void free_pmds(pmd_t *pmds[])
25877 +static void free_pxds(pxd_t *pxds[])
25878 {
25879 int i;
25880
25881 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25882 - if (pmds[i])
25883 - free_page((unsigned long)pmds[i]);
25884 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25885 + if (pxds[i])
25886 + free_page((unsigned long)pxds[i]);
25887 }
25888
25889 -static int preallocate_pmds(pmd_t *pmds[])
25890 +static int preallocate_pxds(pxd_t *pxds[])
25891 {
25892 int i;
25893 bool failed = false;
25894
25895 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25896 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25897 - if (pmd == NULL)
25898 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25899 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25900 + if (pxd == NULL)
25901 failed = true;
25902 - pmds[i] = pmd;
25903 + pxds[i] = pxd;
25904 }
25905
25906 if (failed) {
25907 - free_pmds(pmds);
25908 + free_pxds(pxds);
25909 return -ENOMEM;
25910 }
25911
25912 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25913 * preallocate which never got a corresponding vma will need to be
25914 * freed manually.
25915 */
25916 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25917 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25918 {
25919 int i;
25920
25921 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25922 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25923 pgd_t pgd = pgdp[i];
25924
25925 if (pgd_val(pgd) != 0) {
25926 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25927 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25928
25929 - pgdp[i] = native_make_pgd(0);
25930 + set_pgd(pgdp + i, native_make_pgd(0));
25931
25932 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25933 - pmd_free(mm, pmd);
25934 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25935 + pxd_free(mm, pxd);
25936 }
25937 }
25938 }
25939
25940 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25941 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25942 {
25943 - pud_t *pud;
25944 + pyd_t *pyd;
25945 unsigned long addr;
25946 int i;
25947
25948 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25949 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25950 return;
25951
25952 - pud = pud_offset(pgd, 0);
25953 +#ifdef CONFIG_X86_64
25954 + pyd = pyd_offset(mm, 0L);
25955 +#else
25956 + pyd = pyd_offset(pgd, 0L);
25957 +#endif
25958
25959 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25960 - i++, pud++, addr += PUD_SIZE) {
25961 - pmd_t *pmd = pmds[i];
25962 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25963 + i++, pyd++, addr += PYD_SIZE) {
25964 + pxd_t *pxd = pxds[i];
25965
25966 if (i >= KERNEL_PGD_BOUNDARY)
25967 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25968 - sizeof(pmd_t) * PTRS_PER_PMD);
25969 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25970 + sizeof(pxd_t) * PTRS_PER_PMD);
25971
25972 - pud_populate(mm, pud, pmd);
25973 + pyd_populate(mm, pyd, pxd);
25974 }
25975 }
25976
25977 pgd_t *pgd_alloc(struct mm_struct *mm)
25978 {
25979 pgd_t *pgd;
25980 - pmd_t *pmds[PREALLOCATED_PMDS];
25981 + pxd_t *pxds[PREALLOCATED_PXDS];
25982
25983 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25984
25985 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25986
25987 mm->pgd = pgd;
25988
25989 - if (preallocate_pmds(pmds) != 0)
25990 + if (preallocate_pxds(pxds) != 0)
25991 goto out_free_pgd;
25992
25993 if (paravirt_pgd_alloc(mm) != 0)
25994 - goto out_free_pmds;
25995 + goto out_free_pxds;
25996
25997 /*
25998 * Make sure that pre-populating the pmds is atomic with
25999 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26000 spin_lock(&pgd_lock);
26001
26002 pgd_ctor(mm, pgd);
26003 - pgd_prepopulate_pmd(mm, pgd, pmds);
26004 + pgd_prepopulate_pxd(mm, pgd, pxds);
26005
26006 spin_unlock(&pgd_lock);
26007
26008 return pgd;
26009
26010 -out_free_pmds:
26011 - free_pmds(pmds);
26012 +out_free_pxds:
26013 + free_pxds(pxds);
26014 out_free_pgd:
26015 free_page((unsigned long)pgd);
26016 out:
26017 @@ -295,7 +356,7 @@ out:
26018
26019 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
26020 {
26021 - pgd_mop_up_pmds(mm, pgd);
26022 + pgd_mop_up_pxds(mm, pgd);
26023 pgd_dtor(pgd);
26024 paravirt_pgd_free(mm, pgd);
26025 free_page((unsigned long)pgd);
26026 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
26027 index a69bcb8..19068ab 100644
26028 --- a/arch/x86/mm/pgtable_32.c
26029 +++ b/arch/x86/mm/pgtable_32.c
26030 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
26031 return;
26032 }
26033 pte = pte_offset_kernel(pmd, vaddr);
26034 +
26035 + pax_open_kernel();
26036 if (pte_val(pteval))
26037 set_pte_at(&init_mm, vaddr, pte, pteval);
26038 else
26039 pte_clear(&init_mm, vaddr, pte);
26040 + pax_close_kernel();
26041
26042 /*
26043 * It's enough to flush this one mapping.
26044 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26045 index 410531d..0f16030 100644
26046 --- a/arch/x86/mm/setup_nx.c
26047 +++ b/arch/x86/mm/setup_nx.c
26048 @@ -5,8 +5,10 @@
26049 #include <asm/pgtable.h>
26050 #include <asm/proto.h>
26051
26052 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26053 static int disable_nx __cpuinitdata;
26054
26055 +#ifndef CONFIG_PAX_PAGEEXEC
26056 /*
26057 * noexec = on|off
26058 *
26059 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
26060 return 0;
26061 }
26062 early_param("noexec", noexec_setup);
26063 +#endif
26064 +
26065 +#endif
26066
26067 void __cpuinit x86_configure_nx(void)
26068 {
26069 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26070 if (cpu_has_nx && !disable_nx)
26071 __supported_pte_mask |= _PAGE_NX;
26072 else
26073 +#endif
26074 __supported_pte_mask &= ~_PAGE_NX;
26075 }
26076
26077 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26078 index 60f926c..a710970 100644
26079 --- a/arch/x86/mm/tlb.c
26080 +++ b/arch/x86/mm/tlb.c
26081 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
26082 BUG();
26083 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
26084 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
26085 +
26086 +#ifndef CONFIG_PAX_PER_CPU_PGD
26087 load_cr3(swapper_pg_dir);
26088 +#endif
26089 +
26090 }
26091 }
26092 EXPORT_SYMBOL_GPL(leave_mm);
26093 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26094 index 877b9a1..a8ecf42 100644
26095 --- a/arch/x86/net/bpf_jit.S
26096 +++ b/arch/x86/net/bpf_jit.S
26097 @@ -9,6 +9,7 @@
26098 */
26099 #include <linux/linkage.h>
26100 #include <asm/dwarf2.h>
26101 +#include <asm/alternative-asm.h>
26102
26103 /*
26104 * Calling convention :
26105 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26106 jle bpf_slow_path_word
26107 mov (SKBDATA,%rsi),%eax
26108 bswap %eax /* ntohl() */
26109 + pax_force_retaddr
26110 ret
26111
26112 sk_load_half:
26113 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26114 jle bpf_slow_path_half
26115 movzwl (SKBDATA,%rsi),%eax
26116 rol $8,%ax # ntohs()
26117 + pax_force_retaddr
26118 ret
26119
26120 sk_load_byte:
26121 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26122 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26123 jle bpf_slow_path_byte
26124 movzbl (SKBDATA,%rsi),%eax
26125 + pax_force_retaddr
26126 ret
26127
26128 /**
26129 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26130 movzbl (SKBDATA,%rsi),%ebx
26131 and $15,%bl
26132 shl $2,%bl
26133 + pax_force_retaddr
26134 ret
26135
26136 /* rsi contains offset and can be scratched */
26137 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26138 js bpf_error
26139 mov -12(%rbp),%eax
26140 bswap %eax
26141 + pax_force_retaddr
26142 ret
26143
26144 bpf_slow_path_half:
26145 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26146 mov -12(%rbp),%ax
26147 rol $8,%ax
26148 movzwl %ax,%eax
26149 + pax_force_retaddr
26150 ret
26151
26152 bpf_slow_path_byte:
26153 bpf_slow_path_common(1)
26154 js bpf_error
26155 movzbl -12(%rbp),%eax
26156 + pax_force_retaddr
26157 ret
26158
26159 bpf_slow_path_byte_msh:
26160 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26161 and $15,%al
26162 shl $2,%al
26163 xchg %eax,%ebx
26164 + pax_force_retaddr
26165 ret
26166
26167 #define sk_negative_common(SIZE) \
26168 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26169 sk_negative_common(4)
26170 mov (%rax), %eax
26171 bswap %eax
26172 + pax_force_retaddr
26173 ret
26174
26175 bpf_slow_path_half_neg:
26176 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26177 mov (%rax),%ax
26178 rol $8,%ax
26179 movzwl %ax,%eax
26180 + pax_force_retaddr
26181 ret
26182
26183 bpf_slow_path_byte_neg:
26184 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26185 .globl sk_load_byte_negative_offset
26186 sk_negative_common(1)
26187 movzbl (%rax), %eax
26188 + pax_force_retaddr
26189 ret
26190
26191 bpf_slow_path_byte_msh_neg:
26192 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26193 and $15,%al
26194 shl $2,%al
26195 xchg %eax,%ebx
26196 + pax_force_retaddr
26197 ret
26198
26199 bpf_error:
26200 @@ -197,4 +210,5 @@ bpf_error:
26201 xor %eax,%eax
26202 mov -8(%rbp),%rbx
26203 leaveq
26204 + pax_force_retaddr
26205 ret
26206 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26207 index 520d2bd..b895ef4 100644
26208 --- a/arch/x86/net/bpf_jit_comp.c
26209 +++ b/arch/x86/net/bpf_jit_comp.c
26210 @@ -11,6 +11,7 @@
26211 #include <asm/cacheflush.h>
26212 #include <linux/netdevice.h>
26213 #include <linux/filter.h>
26214 +#include <linux/random.h>
26215
26216 /*
26217 * Conventions :
26218 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26219 return ptr + len;
26220 }
26221
26222 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26223 +#define MAX_INSTR_CODE_SIZE 96
26224 +#else
26225 +#define MAX_INSTR_CODE_SIZE 64
26226 +#endif
26227 +
26228 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26229
26230 #define EMIT1(b1) EMIT(b1, 1)
26231 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26232 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26233 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26234 +
26235 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26236 +/* original constant will appear in ecx */
26237 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
26238 +do { \
26239 + /* mov ecx, randkey */ \
26240 + EMIT1(0xb9); \
26241 + EMIT(_key, 4); \
26242 + /* xor ecx, randkey ^ off */ \
26243 + EMIT2(0x81, 0xf1); \
26244 + EMIT((_key) ^ (_off), 4); \
26245 +} while (0)
26246 +
26247 +#define EMIT1_off32(b1, _off) \
26248 +do { \
26249 + switch (b1) { \
26250 + case 0x05: /* add eax, imm32 */ \
26251 + case 0x2d: /* sub eax, imm32 */ \
26252 + case 0x25: /* and eax, imm32 */ \
26253 + case 0x0d: /* or eax, imm32 */ \
26254 + case 0xb8: /* mov eax, imm32 */ \
26255 + case 0x3d: /* cmp eax, imm32 */ \
26256 + case 0xa9: /* test eax, imm32 */ \
26257 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26258 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26259 + break; \
26260 + case 0xbb: /* mov ebx, imm32 */ \
26261 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26262 + /* mov ebx, ecx */ \
26263 + EMIT2(0x89, 0xcb); \
26264 + break; \
26265 + case 0xbe: /* mov esi, imm32 */ \
26266 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26267 + /* mov esi, ecx */ \
26268 + EMIT2(0x89, 0xce); \
26269 + break; \
26270 + case 0xe9: /* jmp rel imm32 */ \
26271 + EMIT1(b1); \
26272 + EMIT(_off, 4); \
26273 + /* prevent fall-through, we're not called if off = 0 */ \
26274 + EMIT(0xcccccccc, 4); \
26275 + EMIT(0xcccccccc, 4); \
26276 + break; \
26277 + default: \
26278 + EMIT1(b1); \
26279 + EMIT(_off, 4); \
26280 + } \
26281 +} while (0)
26282 +
26283 +#define EMIT2_off32(b1, b2, _off) \
26284 +do { \
26285 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26286 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26287 + EMIT(randkey, 4); \
26288 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26289 + EMIT((_off) - randkey, 4); \
26290 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26291 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26292 + /* imul eax, ecx */ \
26293 + EMIT3(0x0f, 0xaf, 0xc1); \
26294 + } else { \
26295 + EMIT2(b1, b2); \
26296 + EMIT(_off, 4); \
26297 + } \
26298 +} while (0)
26299 +#else
26300 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26301 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26302 +#endif
26303
26304 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26305 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26306 @@ -89,6 +164,24 @@ do { \
26307 #define X86_JBE 0x76
26308 #define X86_JA 0x77
26309
26310 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26311 +#define APPEND_FLOW_VERIFY() \
26312 +do { \
26313 + /* mov ecx, randkey */ \
26314 + EMIT1(0xb9); \
26315 + EMIT(randkey, 4); \
26316 + /* cmp ecx, randkey */ \
26317 + EMIT2(0x81, 0xf9); \
26318 + EMIT(randkey, 4); \
26319 + /* jz after 8 int 3s */ \
26320 + EMIT2(0x74, 0x08); \
26321 + EMIT(0xcccccccc, 4); \
26322 + EMIT(0xcccccccc, 4); \
26323 +} while (0)
26324 +#else
26325 +#define APPEND_FLOW_VERIFY() do { } while (0)
26326 +#endif
26327 +
26328 #define EMIT_COND_JMP(op, offset) \
26329 do { \
26330 if (is_near(offset)) \
26331 @@ -96,6 +189,7 @@ do { \
26332 else { \
26333 EMIT2(0x0f, op + 0x10); \
26334 EMIT(offset, 4); /* jxx .+off32 */ \
26335 + APPEND_FLOW_VERIFY(); \
26336 } \
26337 } while (0)
26338
26339 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26340 set_fs(old_fs);
26341 }
26342
26343 +struct bpf_jit_work {
26344 + struct work_struct work;
26345 + void *image;
26346 +};
26347 +
26348 #define CHOOSE_LOAD_FUNC(K, func) \
26349 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26350
26351 void bpf_jit_compile(struct sk_filter *fp)
26352 {
26353 - u8 temp[64];
26354 + u8 temp[MAX_INSTR_CODE_SIZE];
26355 u8 *prog;
26356 unsigned int proglen, oldproglen = 0;
26357 int ilen, i;
26358 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26359 unsigned int *addrs;
26360 const struct sock_filter *filter = fp->insns;
26361 int flen = fp->len;
26362 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26363 + unsigned int randkey;
26364 +#endif
26365
26366 if (!bpf_jit_enable)
26367 return;
26368 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26369 if (addrs == NULL)
26370 return;
26371
26372 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26373 + if (!fp->work)
26374 + goto out;
26375 +
26376 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26377 + randkey = get_random_int();
26378 +#endif
26379 +
26380 /* Before first pass, make a rough estimation of addrs[]
26381 - * each bpf instruction is translated to less than 64 bytes
26382 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26383 */
26384 for (proglen = 0, i = 0; i < flen; i++) {
26385 - proglen += 64;
26386 + proglen += MAX_INSTR_CODE_SIZE;
26387 addrs[i] = proglen;
26388 }
26389 cleanup_addr = proglen; /* epilogue address */
26390 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26391 case BPF_S_ALU_MUL_K: /* A *= K */
26392 if (is_imm8(K))
26393 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26394 - else {
26395 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26396 - EMIT(K, 4);
26397 - }
26398 + else
26399 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26400 break;
26401 case BPF_S_ALU_DIV_X: /* A /= X; */
26402 seen |= SEEN_XREG;
26403 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
26404 break;
26405 case BPF_S_ALU_MOD_K: /* A %= K; */
26406 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
26407 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26408 + DILUTE_CONST_SEQUENCE(K, randkey);
26409 +#else
26410 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
26411 +#endif
26412 EMIT2(0xf7, 0xf1); /* div %ecx */
26413 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
26414 break;
26415 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26416 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26417 + DILUTE_CONST_SEQUENCE(K, randkey);
26418 + // imul rax, rcx
26419 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26420 +#else
26421 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26422 EMIT(K, 4);
26423 +#endif
26424 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26425 break;
26426 case BPF_S_ALU_AND_X:
26427 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26428 if (is_imm8(K)) {
26429 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26430 } else {
26431 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26432 - EMIT(K, 4);
26433 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26434 }
26435 } else {
26436 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26437 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26438 break;
26439 default:
26440 /* hmm, too complex filter, give up with jit compiler */
26441 - goto out;
26442 + goto error;
26443 }
26444 ilen = prog - temp;
26445 if (image) {
26446 if (unlikely(proglen + ilen > oldproglen)) {
26447 pr_err("bpb_jit_compile fatal error\n");
26448 - kfree(addrs);
26449 - module_free(NULL, image);
26450 - return;
26451 + module_free_exec(NULL, image);
26452 + goto error;
26453 }
26454 + pax_open_kernel();
26455 memcpy(image + proglen, temp, ilen);
26456 + pax_close_kernel();
26457 }
26458 proglen += ilen;
26459 addrs[i] = proglen;
26460 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26461 break;
26462 }
26463 if (proglen == oldproglen) {
26464 - image = module_alloc(max_t(unsigned int,
26465 - proglen,
26466 - sizeof(struct work_struct)));
26467 + image = module_alloc_exec(proglen);
26468 if (!image)
26469 - goto out;
26470 + goto error;
26471 }
26472 oldproglen = proglen;
26473 }
26474 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26475 bpf_flush_icache(image, image + proglen);
26476
26477 fp->bpf_func = (void *)image;
26478 - }
26479 + } else
26480 +error:
26481 + kfree(fp->work);
26482 +
26483 out:
26484 kfree(addrs);
26485 return;
26486 @@ -686,18 +805,20 @@ out:
26487
26488 static void jit_free_defer(struct work_struct *arg)
26489 {
26490 - module_free(NULL, arg);
26491 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26492 + kfree(arg);
26493 }
26494
26495 /* run from softirq, we must use a work_struct to call
26496 - * module_free() from process context
26497 + * module_free_exec() from process context
26498 */
26499 void bpf_jit_free(struct sk_filter *fp)
26500 {
26501 if (fp->bpf_func != sk_run_filter) {
26502 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26503 + struct work_struct *work = &fp->work->work;
26504
26505 INIT_WORK(work, jit_free_defer);
26506 + fp->work->image = fp->bpf_func;
26507 schedule_work(work);
26508 }
26509 }
26510 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26511 index d6aa6e8..266395a 100644
26512 --- a/arch/x86/oprofile/backtrace.c
26513 +++ b/arch/x86/oprofile/backtrace.c
26514 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26515 struct stack_frame_ia32 *fp;
26516 unsigned long bytes;
26517
26518 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26519 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26520 if (bytes != sizeof(bufhead))
26521 return NULL;
26522
26523 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26524 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26525
26526 oprofile_add_trace(bufhead[0].return_address);
26527
26528 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26529 struct stack_frame bufhead[2];
26530 unsigned long bytes;
26531
26532 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26533 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26534 if (bytes != sizeof(bufhead))
26535 return NULL;
26536
26537 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26538 {
26539 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26540
26541 - if (!user_mode_vm(regs)) {
26542 + if (!user_mode(regs)) {
26543 unsigned long stack = kernel_stack_pointer(regs);
26544 if (depth)
26545 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26546 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26547 index e14a2ff..3fd6b58 100644
26548 --- a/arch/x86/pci/mrst.c
26549 +++ b/arch/x86/pci/mrst.c
26550 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26551 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26552 pci_mmcfg_late_init();
26553 pcibios_enable_irq = mrst_pci_irq_enable;
26554 - pci_root_ops = pci_mrst_ops;
26555 + pax_open_kernel();
26556 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26557 + pax_close_kernel();
26558 pci_soc_mode = 1;
26559 /* Continue with standard init */
26560 return 1;
26561 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26562 index da8fe05..7ee6704 100644
26563 --- a/arch/x86/pci/pcbios.c
26564 +++ b/arch/x86/pci/pcbios.c
26565 @@ -79,50 +79,93 @@ union bios32 {
26566 static struct {
26567 unsigned long address;
26568 unsigned short segment;
26569 -} bios32_indirect = { 0, __KERNEL_CS };
26570 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26571
26572 /*
26573 * Returns the entry point for the given service, NULL on error
26574 */
26575
26576 -static unsigned long bios32_service(unsigned long service)
26577 +static unsigned long __devinit bios32_service(unsigned long service)
26578 {
26579 unsigned char return_code; /* %al */
26580 unsigned long address; /* %ebx */
26581 unsigned long length; /* %ecx */
26582 unsigned long entry; /* %edx */
26583 unsigned long flags;
26584 + struct desc_struct d, *gdt;
26585
26586 local_irq_save(flags);
26587 - __asm__("lcall *(%%edi); cld"
26588 +
26589 + gdt = get_cpu_gdt_table(smp_processor_id());
26590 +
26591 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26592 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26593 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26594 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26595 +
26596 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26597 : "=a" (return_code),
26598 "=b" (address),
26599 "=c" (length),
26600 "=d" (entry)
26601 : "0" (service),
26602 "1" (0),
26603 - "D" (&bios32_indirect));
26604 + "D" (&bios32_indirect),
26605 + "r"(__PCIBIOS_DS)
26606 + : "memory");
26607 +
26608 + pax_open_kernel();
26609 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26610 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26611 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26612 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26613 + pax_close_kernel();
26614 +
26615 local_irq_restore(flags);
26616
26617 switch (return_code) {
26618 - case 0:
26619 - return address + entry;
26620 - case 0x80: /* Not present */
26621 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26622 - return 0;
26623 - default: /* Shouldn't happen */
26624 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26625 - service, return_code);
26626 + case 0: {
26627 + int cpu;
26628 + unsigned char flags;
26629 +
26630 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26631 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26632 + printk(KERN_WARNING "bios32_service: not valid\n");
26633 return 0;
26634 + }
26635 + address = address + PAGE_OFFSET;
26636 + length += 16UL; /* some BIOSs underreport this... */
26637 + flags = 4;
26638 + if (length >= 64*1024*1024) {
26639 + length >>= PAGE_SHIFT;
26640 + flags |= 8;
26641 + }
26642 +
26643 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26644 + gdt = get_cpu_gdt_table(cpu);
26645 + pack_descriptor(&d, address, length, 0x9b, flags);
26646 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26647 + pack_descriptor(&d, address, length, 0x93, flags);
26648 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26649 + }
26650 + return entry;
26651 + }
26652 + case 0x80: /* Not present */
26653 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26654 + return 0;
26655 + default: /* Shouldn't happen */
26656 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26657 + service, return_code);
26658 + return 0;
26659 }
26660 }
26661
26662 static struct {
26663 unsigned long address;
26664 unsigned short segment;
26665 -} pci_indirect = { 0, __KERNEL_CS };
26666 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26667
26668 -static int pci_bios_present;
26669 +static int pci_bios_present __read_only;
26670
26671 static int __devinit check_pcibios(void)
26672 {
26673 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26674 unsigned long flags, pcibios_entry;
26675
26676 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26677 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26678 + pci_indirect.address = pcibios_entry;
26679
26680 local_irq_save(flags);
26681 - __asm__(
26682 - "lcall *(%%edi); cld\n\t"
26683 + __asm__("movw %w6, %%ds\n\t"
26684 + "lcall *%%ss:(%%edi); cld\n\t"
26685 + "push %%ss\n\t"
26686 + "pop %%ds\n\t"
26687 "jc 1f\n\t"
26688 "xor %%ah, %%ah\n"
26689 "1:"
26690 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26691 "=b" (ebx),
26692 "=c" (ecx)
26693 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26694 - "D" (&pci_indirect)
26695 + "D" (&pci_indirect),
26696 + "r" (__PCIBIOS_DS)
26697 : "memory");
26698 local_irq_restore(flags);
26699
26700 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26701
26702 switch (len) {
26703 case 1:
26704 - __asm__("lcall *(%%esi); cld\n\t"
26705 + __asm__("movw %w6, %%ds\n\t"
26706 + "lcall *%%ss:(%%esi); cld\n\t"
26707 + "push %%ss\n\t"
26708 + "pop %%ds\n\t"
26709 "jc 1f\n\t"
26710 "xor %%ah, %%ah\n"
26711 "1:"
26712 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26713 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26714 "b" (bx),
26715 "D" ((long)reg),
26716 - "S" (&pci_indirect));
26717 + "S" (&pci_indirect),
26718 + "r" (__PCIBIOS_DS));
26719 /*
26720 * Zero-extend the result beyond 8 bits, do not trust the
26721 * BIOS having done it:
26722 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26723 *value &= 0xff;
26724 break;
26725 case 2:
26726 - __asm__("lcall *(%%esi); cld\n\t"
26727 + __asm__("movw %w6, %%ds\n\t"
26728 + "lcall *%%ss:(%%esi); cld\n\t"
26729 + "push %%ss\n\t"
26730 + "pop %%ds\n\t"
26731 "jc 1f\n\t"
26732 "xor %%ah, %%ah\n"
26733 "1:"
26734 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26735 : "1" (PCIBIOS_READ_CONFIG_WORD),
26736 "b" (bx),
26737 "D" ((long)reg),
26738 - "S" (&pci_indirect));
26739 + "S" (&pci_indirect),
26740 + "r" (__PCIBIOS_DS));
26741 /*
26742 * Zero-extend the result beyond 16 bits, do not trust the
26743 * BIOS having done it:
26744 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26745 *value &= 0xffff;
26746 break;
26747 case 4:
26748 - __asm__("lcall *(%%esi); cld\n\t"
26749 + __asm__("movw %w6, %%ds\n\t"
26750 + "lcall *%%ss:(%%esi); cld\n\t"
26751 + "push %%ss\n\t"
26752 + "pop %%ds\n\t"
26753 "jc 1f\n\t"
26754 "xor %%ah, %%ah\n"
26755 "1:"
26756 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26757 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26758 "b" (bx),
26759 "D" ((long)reg),
26760 - "S" (&pci_indirect));
26761 + "S" (&pci_indirect),
26762 + "r" (__PCIBIOS_DS));
26763 break;
26764 }
26765
26766 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26767
26768 switch (len) {
26769 case 1:
26770 - __asm__("lcall *(%%esi); cld\n\t"
26771 + __asm__("movw %w6, %%ds\n\t"
26772 + "lcall *%%ss:(%%esi); cld\n\t"
26773 + "push %%ss\n\t"
26774 + "pop %%ds\n\t"
26775 "jc 1f\n\t"
26776 "xor %%ah, %%ah\n"
26777 "1:"
26778 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26779 "c" (value),
26780 "b" (bx),
26781 "D" ((long)reg),
26782 - "S" (&pci_indirect));
26783 + "S" (&pci_indirect),
26784 + "r" (__PCIBIOS_DS));
26785 break;
26786 case 2:
26787 - __asm__("lcall *(%%esi); cld\n\t"
26788 + __asm__("movw %w6, %%ds\n\t"
26789 + "lcall *%%ss:(%%esi); cld\n\t"
26790 + "push %%ss\n\t"
26791 + "pop %%ds\n\t"
26792 "jc 1f\n\t"
26793 "xor %%ah, %%ah\n"
26794 "1:"
26795 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26796 "c" (value),
26797 "b" (bx),
26798 "D" ((long)reg),
26799 - "S" (&pci_indirect));
26800 + "S" (&pci_indirect),
26801 + "r" (__PCIBIOS_DS));
26802 break;
26803 case 4:
26804 - __asm__("lcall *(%%esi); cld\n\t"
26805 + __asm__("movw %w6, %%ds\n\t"
26806 + "lcall *%%ss:(%%esi); cld\n\t"
26807 + "push %%ss\n\t"
26808 + "pop %%ds\n\t"
26809 "jc 1f\n\t"
26810 "xor %%ah, %%ah\n"
26811 "1:"
26812 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26813 "c" (value),
26814 "b" (bx),
26815 "D" ((long)reg),
26816 - "S" (&pci_indirect));
26817 + "S" (&pci_indirect),
26818 + "r" (__PCIBIOS_DS));
26819 break;
26820 }
26821
26822 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26823
26824 DBG("PCI: Fetching IRQ routing table... ");
26825 __asm__("push %%es\n\t"
26826 + "movw %w8, %%ds\n\t"
26827 "push %%ds\n\t"
26828 "pop %%es\n\t"
26829 - "lcall *(%%esi); cld\n\t"
26830 + "lcall *%%ss:(%%esi); cld\n\t"
26831 "pop %%es\n\t"
26832 + "push %%ss\n\t"
26833 + "pop %%ds\n"
26834 "jc 1f\n\t"
26835 "xor %%ah, %%ah\n"
26836 "1:"
26837 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26838 "1" (0),
26839 "D" ((long) &opt),
26840 "S" (&pci_indirect),
26841 - "m" (opt)
26842 + "m" (opt),
26843 + "r" (__PCIBIOS_DS)
26844 : "memory");
26845 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26846 if (ret & 0xff00)
26847 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26848 {
26849 int ret;
26850
26851 - __asm__("lcall *(%%esi); cld\n\t"
26852 + __asm__("movw %w5, %%ds\n\t"
26853 + "lcall *%%ss:(%%esi); cld\n\t"
26854 + "push %%ss\n\t"
26855 + "pop %%ds\n"
26856 "jc 1f\n\t"
26857 "xor %%ah, %%ah\n"
26858 "1:"
26859 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26860 : "0" (PCIBIOS_SET_PCI_HW_INT),
26861 "b" ((dev->bus->number << 8) | dev->devfn),
26862 "c" ((irq << 8) | (pin + 10)),
26863 - "S" (&pci_indirect));
26864 + "S" (&pci_indirect),
26865 + "r" (__PCIBIOS_DS));
26866 return !(ret & 0xff00);
26867 }
26868 EXPORT_SYMBOL(pcibios_set_irq_routing);
26869 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26870 index 40e4469..1ab536e 100644
26871 --- a/arch/x86/platform/efi/efi_32.c
26872 +++ b/arch/x86/platform/efi/efi_32.c
26873 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26874 {
26875 struct desc_ptr gdt_descr;
26876
26877 +#ifdef CONFIG_PAX_KERNEXEC
26878 + struct desc_struct d;
26879 +#endif
26880 +
26881 local_irq_save(efi_rt_eflags);
26882
26883 load_cr3(initial_page_table);
26884 __flush_tlb_all();
26885
26886 +#ifdef CONFIG_PAX_KERNEXEC
26887 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26888 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26889 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26890 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26891 +#endif
26892 +
26893 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26894 gdt_descr.size = GDT_SIZE - 1;
26895 load_gdt(&gdt_descr);
26896 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26897 {
26898 struct desc_ptr gdt_descr;
26899
26900 +#ifdef CONFIG_PAX_KERNEXEC
26901 + struct desc_struct d;
26902 +
26903 + memset(&d, 0, sizeof d);
26904 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26905 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26906 +#endif
26907 +
26908 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26909 gdt_descr.size = GDT_SIZE - 1;
26910 load_gdt(&gdt_descr);
26911 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26912 index fbe66e6..eae5e38 100644
26913 --- a/arch/x86/platform/efi/efi_stub_32.S
26914 +++ b/arch/x86/platform/efi/efi_stub_32.S
26915 @@ -6,7 +6,9 @@
26916 */
26917
26918 #include <linux/linkage.h>
26919 +#include <linux/init.h>
26920 #include <asm/page_types.h>
26921 +#include <asm/segment.h>
26922
26923 /*
26924 * efi_call_phys(void *, ...) is a function with variable parameters.
26925 @@ -20,7 +22,7 @@
26926 * service functions will comply with gcc calling convention, too.
26927 */
26928
26929 -.text
26930 +__INIT
26931 ENTRY(efi_call_phys)
26932 /*
26933 * 0. The function can only be called in Linux kernel. So CS has been
26934 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26935 * The mapping of lower virtual memory has been created in prelog and
26936 * epilog.
26937 */
26938 - movl $1f, %edx
26939 - subl $__PAGE_OFFSET, %edx
26940 - jmp *%edx
26941 +#ifdef CONFIG_PAX_KERNEXEC
26942 + movl $(__KERNEXEC_EFI_DS), %edx
26943 + mov %edx, %ds
26944 + mov %edx, %es
26945 + mov %edx, %ss
26946 + addl $2f,(1f)
26947 + ljmp *(1f)
26948 +
26949 +__INITDATA
26950 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26951 +.previous
26952 +
26953 +2:
26954 + subl $2b,(1b)
26955 +#else
26956 + jmp 1f-__PAGE_OFFSET
26957 1:
26958 +#endif
26959
26960 /*
26961 * 2. Now on the top of stack is the return
26962 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26963 * parameter 2, ..., param n. To make things easy, we save the return
26964 * address of efi_call_phys in a global variable.
26965 */
26966 - popl %edx
26967 - movl %edx, saved_return_addr
26968 - /* get the function pointer into ECX*/
26969 - popl %ecx
26970 - movl %ecx, efi_rt_function_ptr
26971 - movl $2f, %edx
26972 - subl $__PAGE_OFFSET, %edx
26973 - pushl %edx
26974 + popl (saved_return_addr)
26975 + popl (efi_rt_function_ptr)
26976
26977 /*
26978 * 3. Clear PG bit in %CR0.
26979 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26980 /*
26981 * 5. Call the physical function.
26982 */
26983 - jmp *%ecx
26984 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26985
26986 -2:
26987 /*
26988 * 6. After EFI runtime service returns, control will return to
26989 * following instruction. We'd better readjust stack pointer first.
26990 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26991 movl %cr0, %edx
26992 orl $0x80000000, %edx
26993 movl %edx, %cr0
26994 - jmp 1f
26995 -1:
26996 +
26997 /*
26998 * 8. Now restore the virtual mode from flat mode by
26999 * adding EIP with PAGE_OFFSET.
27000 */
27001 - movl $1f, %edx
27002 - jmp *%edx
27003 +#ifdef CONFIG_PAX_KERNEXEC
27004 + movl $(__KERNEL_DS), %edx
27005 + mov %edx, %ds
27006 + mov %edx, %es
27007 + mov %edx, %ss
27008 + ljmp $(__KERNEL_CS),$1f
27009 +#else
27010 + jmp 1f+__PAGE_OFFSET
27011 +#endif
27012 1:
27013
27014 /*
27015 * 9. Balance the stack. And because EAX contain the return value,
27016 * we'd better not clobber it.
27017 */
27018 - leal efi_rt_function_ptr, %edx
27019 - movl (%edx), %ecx
27020 - pushl %ecx
27021 + pushl (efi_rt_function_ptr)
27022
27023 /*
27024 - * 10. Push the saved return address onto the stack and return.
27025 + * 10. Return to the saved return address.
27026 */
27027 - leal saved_return_addr, %edx
27028 - movl (%edx), %ecx
27029 - pushl %ecx
27030 - ret
27031 + jmpl *(saved_return_addr)
27032 ENDPROC(efi_call_phys)
27033 .previous
27034
27035 -.data
27036 +__INITDATA
27037 saved_return_addr:
27038 .long 0
27039 efi_rt_function_ptr:
27040 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
27041 index 4c07cca..2c8427d 100644
27042 --- a/arch/x86/platform/efi/efi_stub_64.S
27043 +++ b/arch/x86/platform/efi/efi_stub_64.S
27044 @@ -7,6 +7,7 @@
27045 */
27046
27047 #include <linux/linkage.h>
27048 +#include <asm/alternative-asm.h>
27049
27050 #define SAVE_XMM \
27051 mov %rsp, %rax; \
27052 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
27053 call *%rdi
27054 addq $32, %rsp
27055 RESTORE_XMM
27056 + pax_force_retaddr 0, 1
27057 ret
27058 ENDPROC(efi_call0)
27059
27060 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
27061 call *%rdi
27062 addq $32, %rsp
27063 RESTORE_XMM
27064 + pax_force_retaddr 0, 1
27065 ret
27066 ENDPROC(efi_call1)
27067
27068 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
27069 call *%rdi
27070 addq $32, %rsp
27071 RESTORE_XMM
27072 + pax_force_retaddr 0, 1
27073 ret
27074 ENDPROC(efi_call2)
27075
27076 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
27077 call *%rdi
27078 addq $32, %rsp
27079 RESTORE_XMM
27080 + pax_force_retaddr 0, 1
27081 ret
27082 ENDPROC(efi_call3)
27083
27084 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
27085 call *%rdi
27086 addq $32, %rsp
27087 RESTORE_XMM
27088 + pax_force_retaddr 0, 1
27089 ret
27090 ENDPROC(efi_call4)
27091
27092 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
27093 call *%rdi
27094 addq $48, %rsp
27095 RESTORE_XMM
27096 + pax_force_retaddr 0, 1
27097 ret
27098 ENDPROC(efi_call5)
27099
27100 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
27101 call *%rdi
27102 addq $48, %rsp
27103 RESTORE_XMM
27104 + pax_force_retaddr 0, 1
27105 ret
27106 ENDPROC(efi_call6)
27107 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
27108 index fd41a92..9c33628 100644
27109 --- a/arch/x86/platform/mrst/mrst.c
27110 +++ b/arch/x86/platform/mrst/mrst.c
27111 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
27112 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27113 int sfi_mrtc_num;
27114
27115 -static void mrst_power_off(void)
27116 +static __noreturn void mrst_power_off(void)
27117 {
27118 + BUG();
27119 }
27120
27121 -static void mrst_reboot(void)
27122 +static __noreturn void mrst_reboot(void)
27123 {
27124 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27125 + BUG();
27126 }
27127
27128 /* parse all the mtimer info to a static mtimer array */
27129 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27130 index 218cdb1..c1178eb 100644
27131 --- a/arch/x86/power/cpu.c
27132 +++ b/arch/x86/power/cpu.c
27133 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
27134 static void fix_processor_context(void)
27135 {
27136 int cpu = smp_processor_id();
27137 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27138 + struct tss_struct *t = init_tss + cpu;
27139
27140 set_tss_desc(cpu, t); /*
27141 * This just modifies memory; should not be
27142 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
27143 */
27144
27145 #ifdef CONFIG_X86_64
27146 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27147 -
27148 syscall_init(); /* This sets MSR_*STAR and related */
27149 #endif
27150 load_TR_desc(); /* This does ltr */
27151 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27152 index cbca565..bae7133 100644
27153 --- a/arch/x86/realmode/init.c
27154 +++ b/arch/x86/realmode/init.c
27155 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27156 __va(real_mode_header->trampoline_header);
27157
27158 #ifdef CONFIG_X86_32
27159 - trampoline_header->start = __pa(startup_32_smp);
27160 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27161 +
27162 +#ifdef CONFIG_PAX_KERNEXEC
27163 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27164 +#endif
27165 +
27166 + trampoline_header->boot_cs = __BOOT_CS;
27167 trampoline_header->gdt_limit = __BOOT_DS + 7;
27168 trampoline_header->gdt_base = __pa(boot_gdt);
27169 #else
27170 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27171 index 8869287..d577672 100644
27172 --- a/arch/x86/realmode/rm/Makefile
27173 +++ b/arch/x86/realmode/rm/Makefile
27174 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27175 $(call cc-option, -fno-unit-at-a-time)) \
27176 $(call cc-option, -fno-stack-protector) \
27177 $(call cc-option, -mpreferred-stack-boundary=2)
27178 +ifdef CONSTIFY_PLUGIN
27179 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27180 +endif
27181 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27182 GCOV_PROFILE := n
27183 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27184 index a28221d..93c40f1 100644
27185 --- a/arch/x86/realmode/rm/header.S
27186 +++ b/arch/x86/realmode/rm/header.S
27187 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27188 #endif
27189 /* APM/BIOS reboot */
27190 .long pa_machine_real_restart_asm
27191 -#ifdef CONFIG_X86_64
27192 +#ifdef CONFIG_X86_32
27193 + .long __KERNEL_CS
27194 +#else
27195 .long __KERNEL32_CS
27196 #endif
27197 END(real_mode_header)
27198 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27199 index c1b2791..f9e31c7 100644
27200 --- a/arch/x86/realmode/rm/trampoline_32.S
27201 +++ b/arch/x86/realmode/rm/trampoline_32.S
27202 @@ -25,6 +25,12 @@
27203 #include <asm/page_types.h>
27204 #include "realmode.h"
27205
27206 +#ifdef CONFIG_PAX_KERNEXEC
27207 +#define ta(X) (X)
27208 +#else
27209 +#define ta(X) (pa_ ## X)
27210 +#endif
27211 +
27212 .text
27213 .code16
27214
27215 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27216
27217 cli # We should be safe anyway
27218
27219 - movl tr_start, %eax # where we need to go
27220 -
27221 movl $0xA5A5A5A5, trampoline_status
27222 # write marker for master knows we're running
27223
27224 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27225 movw $1, %dx # protected mode (PE) bit
27226 lmsw %dx # into protected mode
27227
27228 - ljmpl $__BOOT_CS, $pa_startup_32
27229 + ljmpl *(trampoline_header)
27230
27231 .section ".text32","ax"
27232 .code32
27233 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27234 .balign 8
27235 GLOBAL(trampoline_header)
27236 tr_start: .space 4
27237 - tr_gdt_pad: .space 2
27238 + tr_boot_cs: .space 2
27239 tr_gdt: .space 6
27240 END(trampoline_header)
27241
27242 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27243 index bb360dc..3e5945f 100644
27244 --- a/arch/x86/realmode/rm/trampoline_64.S
27245 +++ b/arch/x86/realmode/rm/trampoline_64.S
27246 @@ -107,7 +107,7 @@ ENTRY(startup_32)
27247 wrmsr
27248
27249 # Enable paging and in turn activate Long Mode
27250 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27251 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
27252 movl %eax, %cr0
27253
27254 /*
27255 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27256 index 5a1847d..deccb30 100644
27257 --- a/arch/x86/tools/relocs.c
27258 +++ b/arch/x86/tools/relocs.c
27259 @@ -12,10 +12,13 @@
27260 #include <regex.h>
27261 #include <tools/le_byteshift.h>
27262
27263 +#include "../../../include/generated/autoconf.h"
27264 +
27265 static void die(char *fmt, ...);
27266
27267 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27268 static Elf32_Ehdr ehdr;
27269 +static Elf32_Phdr *phdr;
27270 static unsigned long reloc_count, reloc_idx;
27271 static unsigned long *relocs;
27272 static unsigned long reloc16_count, reloc16_idx;
27273 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27274 }
27275 }
27276
27277 +static void read_phdrs(FILE *fp)
27278 +{
27279 + unsigned int i;
27280 +
27281 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27282 + if (!phdr) {
27283 + die("Unable to allocate %d program headers\n",
27284 + ehdr.e_phnum);
27285 + }
27286 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27287 + die("Seek to %d failed: %s\n",
27288 + ehdr.e_phoff, strerror(errno));
27289 + }
27290 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27291 + die("Cannot read ELF program headers: %s\n",
27292 + strerror(errno));
27293 + }
27294 + for(i = 0; i < ehdr.e_phnum; i++) {
27295 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27296 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27297 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27298 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27299 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27300 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27301 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27302 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27303 + }
27304 +
27305 +}
27306 +
27307 static void read_shdrs(FILE *fp)
27308 {
27309 - int i;
27310 + unsigned int i;
27311 Elf32_Shdr shdr;
27312
27313 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27314 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27315
27316 static void read_strtabs(FILE *fp)
27317 {
27318 - int i;
27319 + unsigned int i;
27320 for (i = 0; i < ehdr.e_shnum; i++) {
27321 struct section *sec = &secs[i];
27322 if (sec->shdr.sh_type != SHT_STRTAB) {
27323 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27324
27325 static void read_symtabs(FILE *fp)
27326 {
27327 - int i,j;
27328 + unsigned int i,j;
27329 for (i = 0; i < ehdr.e_shnum; i++) {
27330 struct section *sec = &secs[i];
27331 if (sec->shdr.sh_type != SHT_SYMTAB) {
27332 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27333 }
27334
27335
27336 -static void read_relocs(FILE *fp)
27337 +static void read_relocs(FILE *fp, int use_real_mode)
27338 {
27339 - int i,j;
27340 + unsigned int i,j;
27341 + uint32_t base;
27342 +
27343 for (i = 0; i < ehdr.e_shnum; i++) {
27344 struct section *sec = &secs[i];
27345 if (sec->shdr.sh_type != SHT_REL) {
27346 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27347 die("Cannot read symbol table: %s\n",
27348 strerror(errno));
27349 }
27350 + base = 0;
27351 +
27352 +#ifdef CONFIG_X86_32
27353 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27354 + if (phdr[j].p_type != PT_LOAD )
27355 + continue;
27356 + 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)
27357 + continue;
27358 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27359 + break;
27360 + }
27361 +#endif
27362 +
27363 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27364 Elf32_Rel *rel = &sec->reltab[j];
27365 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27366 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27367 rel->r_info = elf32_to_cpu(rel->r_info);
27368 }
27369 }
27370 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27371
27372 static void print_absolute_symbols(void)
27373 {
27374 - int i;
27375 + unsigned int i;
27376 printf("Absolute symbols\n");
27377 printf(" Num: Value Size Type Bind Visibility Name\n");
27378 for (i = 0; i < ehdr.e_shnum; i++) {
27379 struct section *sec = &secs[i];
27380 char *sym_strtab;
27381 - int j;
27382 + unsigned int j;
27383
27384 if (sec->shdr.sh_type != SHT_SYMTAB) {
27385 continue;
27386 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27387
27388 static void print_absolute_relocs(void)
27389 {
27390 - int i, printed = 0;
27391 + unsigned int i, printed = 0;
27392
27393 for (i = 0; i < ehdr.e_shnum; i++) {
27394 struct section *sec = &secs[i];
27395 struct section *sec_applies, *sec_symtab;
27396 char *sym_strtab;
27397 Elf32_Sym *sh_symtab;
27398 - int j;
27399 + unsigned int j;
27400 if (sec->shdr.sh_type != SHT_REL) {
27401 continue;
27402 }
27403 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27404 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27405 int use_real_mode)
27406 {
27407 - int i;
27408 + unsigned int i;
27409 /* Walk through the relocations */
27410 for (i = 0; i < ehdr.e_shnum; i++) {
27411 char *sym_strtab;
27412 Elf32_Sym *sh_symtab;
27413 struct section *sec_applies, *sec_symtab;
27414 - int j;
27415 + unsigned int j;
27416 struct section *sec = &secs[i];
27417
27418 if (sec->shdr.sh_type != SHT_REL) {
27419 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27420 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27421 r_type = ELF32_R_TYPE(rel->r_info);
27422
27423 + if (!use_real_mode) {
27424 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27425 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27426 + continue;
27427 +
27428 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27429 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27430 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27431 + continue;
27432 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27433 + continue;
27434 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27435 + continue;
27436 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27437 + continue;
27438 +#endif
27439 + }
27440 +
27441 shn_abs = sym->st_shndx == SHN_ABS;
27442
27443 switch (r_type) {
27444 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27445
27446 static void emit_relocs(int as_text, int use_real_mode)
27447 {
27448 - int i;
27449 + unsigned int i;
27450 /* Count how many relocations I have and allocate space for them. */
27451 reloc_count = 0;
27452 walk_relocs(count_reloc, use_real_mode);
27453 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27454 fname, strerror(errno));
27455 }
27456 read_ehdr(fp);
27457 + read_phdrs(fp);
27458 read_shdrs(fp);
27459 read_strtabs(fp);
27460 read_symtabs(fp);
27461 - read_relocs(fp);
27462 + read_relocs(fp, use_real_mode);
27463 if (show_absolute_syms) {
27464 print_absolute_symbols();
27465 return 0;
27466 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27467 index fd14be1..e3c79c0 100644
27468 --- a/arch/x86/vdso/Makefile
27469 +++ b/arch/x86/vdso/Makefile
27470 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27471 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27472 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27473
27474 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27475 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27476 GCOV_PROFILE := n
27477
27478 #
27479 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27480 index 0faad64..39ef157 100644
27481 --- a/arch/x86/vdso/vdso32-setup.c
27482 +++ b/arch/x86/vdso/vdso32-setup.c
27483 @@ -25,6 +25,7 @@
27484 #include <asm/tlbflush.h>
27485 #include <asm/vdso.h>
27486 #include <asm/proto.h>
27487 +#include <asm/mman.h>
27488
27489 enum {
27490 VDSO_DISABLED = 0,
27491 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27492 void enable_sep_cpu(void)
27493 {
27494 int cpu = get_cpu();
27495 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27496 + struct tss_struct *tss = init_tss + cpu;
27497
27498 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27499 put_cpu();
27500 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27501 gate_vma.vm_start = FIXADDR_USER_START;
27502 gate_vma.vm_end = FIXADDR_USER_END;
27503 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27504 - gate_vma.vm_page_prot = __P101;
27505 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27506
27507 return 0;
27508 }
27509 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27510 if (compat)
27511 addr = VDSO_HIGH_BASE;
27512 else {
27513 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27514 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27515 if (IS_ERR_VALUE(addr)) {
27516 ret = addr;
27517 goto up_fail;
27518 }
27519 }
27520
27521 - current->mm->context.vdso = (void *)addr;
27522 + current->mm->context.vdso = addr;
27523
27524 if (compat_uses_vma || !compat) {
27525 /*
27526 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27527 }
27528
27529 current_thread_info()->sysenter_return =
27530 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27531 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27532
27533 up_fail:
27534 if (ret)
27535 - current->mm->context.vdso = NULL;
27536 + current->mm->context.vdso = 0;
27537
27538 up_write(&mm->mmap_sem);
27539
27540 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27541
27542 const char *arch_vma_name(struct vm_area_struct *vma)
27543 {
27544 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27545 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27546 return "[vdso]";
27547 +
27548 +#ifdef CONFIG_PAX_SEGMEXEC
27549 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27550 + return "[vdso]";
27551 +#endif
27552 +
27553 return NULL;
27554 }
27555
27556 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27557 * Check to see if the corresponding task was created in compat vdso
27558 * mode.
27559 */
27560 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27561 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27562 return &gate_vma;
27563 return NULL;
27564 }
27565 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27566 index 00aaf04..4a26505 100644
27567 --- a/arch/x86/vdso/vma.c
27568 +++ b/arch/x86/vdso/vma.c
27569 @@ -16,8 +16,6 @@
27570 #include <asm/vdso.h>
27571 #include <asm/page.h>
27572
27573 -unsigned int __read_mostly vdso_enabled = 1;
27574 -
27575 extern char vdso_start[], vdso_end[];
27576 extern unsigned short vdso_sync_cpuid;
27577
27578 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27579 * unaligned here as a result of stack start randomization.
27580 */
27581 addr = PAGE_ALIGN(addr);
27582 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27583
27584 return addr;
27585 }
27586 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27587 unsigned size)
27588 {
27589 struct mm_struct *mm = current->mm;
27590 - unsigned long addr;
27591 + unsigned long addr = 0;
27592 int ret;
27593
27594 - if (!vdso_enabled)
27595 - return 0;
27596 -
27597 down_write(&mm->mmap_sem);
27598 +
27599 +#ifdef CONFIG_PAX_RANDMMAP
27600 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27601 +#endif
27602 +
27603 addr = vdso_addr(mm->start_stack, size);
27604 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27605 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27606 if (IS_ERR_VALUE(addr)) {
27607 ret = addr;
27608 goto up_fail;
27609 }
27610
27611 - current->mm->context.vdso = (void *)addr;
27612 + mm->context.vdso = addr;
27613
27614 ret = install_special_mapping(mm, addr, size,
27615 VM_READ|VM_EXEC|
27616 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27617 pages);
27618 - if (ret) {
27619 - current->mm->context.vdso = NULL;
27620 - goto up_fail;
27621 - }
27622 + if (ret)
27623 + mm->context.vdso = 0;
27624
27625 up_fail:
27626 up_write(&mm->mmap_sem);
27627 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27628 vdsox32_size);
27629 }
27630 #endif
27631 -
27632 -static __init int vdso_setup(char *s)
27633 -{
27634 - vdso_enabled = simple_strtoul(s, NULL, 0);
27635 - return 0;
27636 -}
27637 -__setup("vdso=", vdso_setup);
27638 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27639 index 586d838..38cb3ff 100644
27640 --- a/arch/x86/xen/enlighten.c
27641 +++ b/arch/x86/xen/enlighten.c
27642 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27643
27644 struct shared_info xen_dummy_shared_info;
27645
27646 -void *xen_initial_gdt;
27647 -
27648 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27649 __read_mostly int xen_have_vector_callback;
27650 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27651 @@ -918,21 +916,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27652
27653 static void set_xen_basic_apic_ops(void)
27654 {
27655 - apic->read = xen_apic_read;
27656 - apic->write = xen_apic_write;
27657 - apic->icr_read = xen_apic_icr_read;
27658 - apic->icr_write = xen_apic_icr_write;
27659 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27660 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27661 - apic->set_apic_id = xen_set_apic_id;
27662 - apic->get_apic_id = xen_get_apic_id;
27663 + *(void **)&apic->read = xen_apic_read;
27664 + *(void **)&apic->write = xen_apic_write;
27665 + *(void **)&apic->icr_read = xen_apic_icr_read;
27666 + *(void **)&apic->icr_write = xen_apic_icr_write;
27667 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27668 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27669 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27670 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27671
27672 #ifdef CONFIG_SMP
27673 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27674 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27675 - apic->send_IPI_mask = xen_send_IPI_mask;
27676 - apic->send_IPI_all = xen_send_IPI_all;
27677 - apic->send_IPI_self = xen_send_IPI_self;
27678 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27679 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27680 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27681 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27682 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27683 #endif
27684 }
27685
27686 @@ -1222,30 +1220,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27687 #endif
27688 };
27689
27690 -static void xen_reboot(int reason)
27691 +static __noreturn void xen_reboot(int reason)
27692 {
27693 struct sched_shutdown r = { .reason = reason };
27694
27695 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27696 - BUG();
27697 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27698 + BUG();
27699 }
27700
27701 -static void xen_restart(char *msg)
27702 +static __noreturn void xen_restart(char *msg)
27703 {
27704 xen_reboot(SHUTDOWN_reboot);
27705 }
27706
27707 -static void xen_emergency_restart(void)
27708 +static __noreturn void xen_emergency_restart(void)
27709 {
27710 xen_reboot(SHUTDOWN_reboot);
27711 }
27712
27713 -static void xen_machine_halt(void)
27714 +static __noreturn void xen_machine_halt(void)
27715 {
27716 xen_reboot(SHUTDOWN_poweroff);
27717 }
27718
27719 -static void xen_machine_power_off(void)
27720 +static __noreturn void xen_machine_power_off(void)
27721 {
27722 if (pm_power_off)
27723 pm_power_off();
27724 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27725 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27726
27727 /* Work out if we support NX */
27728 - x86_configure_nx();
27729 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27730 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27731 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27732 + unsigned l, h;
27733 +
27734 + __supported_pte_mask |= _PAGE_NX;
27735 + rdmsr(MSR_EFER, l, h);
27736 + l |= EFER_NX;
27737 + wrmsr(MSR_EFER, l, h);
27738 + }
27739 +#endif
27740
27741 xen_setup_features();
27742
27743 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27744
27745 machine_ops = xen_machine_ops;
27746
27747 - /*
27748 - * The only reliable way to retain the initial address of the
27749 - * percpu gdt_page is to remember it here, so we can go and
27750 - * mark it RW later, when the initial percpu area is freed.
27751 - */
27752 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27753 -
27754 xen_smp_init();
27755
27756 #ifdef CONFIG_ACPI_NUMA
27757 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27758 index dcf5f2d..d804c25 100644
27759 --- a/arch/x86/xen/mmu.c
27760 +++ b/arch/x86/xen/mmu.c
27761 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
27762 /* L3_k[510] -> level2_kernel_pgt
27763 * L3_i[511] -> level2_fixmap_pgt */
27764 convert_pfn_mfn(level3_kernel_pgt);
27765 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27766 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27767 + convert_pfn_mfn(level3_vmemmap_pgt);
27768
27769 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
27770 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27771 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
27772 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27773 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27774 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27775 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27776 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27777 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27778 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27779 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
27780 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27781 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27782 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27783
27784 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
27785 pv_mmu_ops.set_pud = xen_set_pud;
27786 #if PAGETABLE_LEVELS == 4
27787 pv_mmu_ops.set_pgd = xen_set_pgd;
27788 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27789 #endif
27790
27791 /* This will work as long as patching hasn't happened yet
27792 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27793 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27794 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27795 .set_pgd = xen_set_pgd_hyper,
27796 + .set_pgd_batched = xen_set_pgd_hyper,
27797
27798 .alloc_pud = xen_alloc_pmd_init,
27799 .release_pud = xen_release_pmd_init,
27800 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27801 index 353c50f..5b7cb95 100644
27802 --- a/arch/x86/xen/smp.c
27803 +++ b/arch/x86/xen/smp.c
27804 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27805 {
27806 BUG_ON(smp_processor_id() != 0);
27807 native_smp_prepare_boot_cpu();
27808 -
27809 - /* We've switched to the "real" per-cpu gdt, so make sure the
27810 - old memory can be recycled */
27811 - make_lowmem_page_readwrite(xen_initial_gdt);
27812 -
27813 xen_filter_cpu_maps();
27814 xen_setup_vcpu_info_placement();
27815 }
27816 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27817 gdt = get_cpu_gdt_table(cpu);
27818
27819 ctxt->flags = VGCF_IN_KERNEL;
27820 - ctxt->user_regs.ds = __USER_DS;
27821 - ctxt->user_regs.es = __USER_DS;
27822 + ctxt->user_regs.ds = __KERNEL_DS;
27823 + ctxt->user_regs.es = __KERNEL_DS;
27824 ctxt->user_regs.ss = __KERNEL_DS;
27825 #ifdef CONFIG_X86_32
27826 ctxt->user_regs.fs = __KERNEL_PERCPU;
27827 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27828 + savesegment(gs, ctxt->user_regs.gs);
27829 #else
27830 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27831 #endif
27832 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27833 int rc;
27834
27835 per_cpu(current_task, cpu) = idle;
27836 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27837 #ifdef CONFIG_X86_32
27838 irq_ctx_init(cpu);
27839 #else
27840 clear_tsk_thread_flag(idle, TIF_FORK);
27841 - per_cpu(kernel_stack, cpu) =
27842 - (unsigned long)task_stack_page(idle) -
27843 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27844 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27845 #endif
27846 xen_setup_runstate_info(cpu);
27847 xen_setup_timer(cpu);
27848 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27849 index f9643fc..602e8af 100644
27850 --- a/arch/x86/xen/xen-asm_32.S
27851 +++ b/arch/x86/xen/xen-asm_32.S
27852 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27853 ESP_OFFSET=4 # bytes pushed onto stack
27854
27855 /*
27856 - * Store vcpu_info pointer for easy access. Do it this way to
27857 - * avoid having to reload %fs
27858 + * Store vcpu_info pointer for easy access.
27859 */
27860 #ifdef CONFIG_SMP
27861 - GET_THREAD_INFO(%eax)
27862 - movl TI_cpu(%eax), %eax
27863 - movl __per_cpu_offset(,%eax,4), %eax
27864 - mov xen_vcpu(%eax), %eax
27865 + push %fs
27866 + mov $(__KERNEL_PERCPU), %eax
27867 + mov %eax, %fs
27868 + mov PER_CPU_VAR(xen_vcpu), %eax
27869 + pop %fs
27870 #else
27871 movl xen_vcpu, %eax
27872 #endif
27873 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27874 index 7faed58..ba4427c 100644
27875 --- a/arch/x86/xen/xen-head.S
27876 +++ b/arch/x86/xen/xen-head.S
27877 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27878 #ifdef CONFIG_X86_32
27879 mov %esi,xen_start_info
27880 mov $init_thread_union+THREAD_SIZE,%esp
27881 +#ifdef CONFIG_SMP
27882 + movl $cpu_gdt_table,%edi
27883 + movl $__per_cpu_load,%eax
27884 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27885 + rorl $16,%eax
27886 + movb %al,__KERNEL_PERCPU + 4(%edi)
27887 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27888 + movl $__per_cpu_end - 1,%eax
27889 + subl $__per_cpu_start,%eax
27890 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27891 +#endif
27892 #else
27893 mov %rsi,xen_start_info
27894 mov $init_thread_union+THREAD_SIZE,%rsp
27895 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27896 index a95b417..b6dbd0b 100644
27897 --- a/arch/x86/xen/xen-ops.h
27898 +++ b/arch/x86/xen/xen-ops.h
27899 @@ -10,8 +10,6 @@
27900 extern const char xen_hypervisor_callback[];
27901 extern const char xen_failsafe_callback[];
27902
27903 -extern void *xen_initial_gdt;
27904 -
27905 struct trap_info;
27906 void xen_copy_trap_info(struct trap_info *traps);
27907
27908 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27909 index 525bd3d..ef888b1 100644
27910 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27911 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27912 @@ -119,9 +119,9 @@
27913 ----------------------------------------------------------------------*/
27914
27915 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27916 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27917 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27918 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27919 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27920
27921 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27922 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27923 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27924 index 2f33760..835e50a 100644
27925 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27926 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27927 @@ -11,6 +11,7 @@
27928 #ifndef _XTENSA_CORE_H
27929 #define _XTENSA_CORE_H
27930
27931 +#include <linux/const.h>
27932
27933 /****************************************************************************
27934 Parameters Useful for Any Code, USER or PRIVILEGED
27935 @@ -112,9 +113,9 @@
27936 ----------------------------------------------------------------------*/
27937
27938 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27939 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27940 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27941 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27942 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27943
27944 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27945 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27946 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27947 index af00795..2bb8105 100644
27948 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27949 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27950 @@ -11,6 +11,7 @@
27951 #ifndef _XTENSA_CORE_CONFIGURATION_H
27952 #define _XTENSA_CORE_CONFIGURATION_H
27953
27954 +#include <linux/const.h>
27955
27956 /****************************************************************************
27957 Parameters Useful for Any Code, USER or PRIVILEGED
27958 @@ -118,9 +119,9 @@
27959 ----------------------------------------------------------------------*/
27960
27961 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27962 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27963 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27964 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27965 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27966
27967 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27968 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27969 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27970 index 58916af..9cb880b 100644
27971 --- a/block/blk-iopoll.c
27972 +++ b/block/blk-iopoll.c
27973 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27974 }
27975 EXPORT_SYMBOL(blk_iopoll_complete);
27976
27977 -static void blk_iopoll_softirq(struct softirq_action *h)
27978 +static void blk_iopoll_softirq(void)
27979 {
27980 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27981 int rearm = 0, budget = blk_iopoll_budget;
27982 diff --git a/block/blk-map.c b/block/blk-map.c
27983 index 623e1cd..ca1e109 100644
27984 --- a/block/blk-map.c
27985 +++ b/block/blk-map.c
27986 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27987 if (!len || !kbuf)
27988 return -EINVAL;
27989
27990 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27991 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27992 if (do_copy)
27993 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27994 else
27995 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27996 index 467c8de..4bddc6d 100644
27997 --- a/block/blk-softirq.c
27998 +++ b/block/blk-softirq.c
27999 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
28000 * Softirq action handler - move entries to local list and loop over them
28001 * while passing them to the queue registered handler.
28002 */
28003 -static void blk_done_softirq(struct softirq_action *h)
28004 +static void blk_done_softirq(void)
28005 {
28006 struct list_head *cpu_list, local_list;
28007
28008 diff --git a/block/bsg.c b/block/bsg.c
28009 index ff64ae3..593560c 100644
28010 --- a/block/bsg.c
28011 +++ b/block/bsg.c
28012 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
28013 struct sg_io_v4 *hdr, struct bsg_device *bd,
28014 fmode_t has_write_perm)
28015 {
28016 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28017 + unsigned char *cmdptr;
28018 +
28019 if (hdr->request_len > BLK_MAX_CDB) {
28020 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
28021 if (!rq->cmd)
28022 return -ENOMEM;
28023 - }
28024 + cmdptr = rq->cmd;
28025 + } else
28026 + cmdptr = tmpcmd;
28027
28028 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
28029 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
28030 hdr->request_len))
28031 return -EFAULT;
28032
28033 + if (cmdptr != rq->cmd)
28034 + memcpy(rq->cmd, cmdptr, hdr->request_len);
28035 +
28036 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
28037 if (blk_verify_command(rq->cmd, has_write_perm))
28038 return -EPERM;
28039 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
28040 index 7c668c8..db3521c 100644
28041 --- a/block/compat_ioctl.c
28042 +++ b/block/compat_ioctl.c
28043 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
28044 err |= __get_user(f->spec1, &uf->spec1);
28045 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
28046 err |= __get_user(name, &uf->name);
28047 - f->name = compat_ptr(name);
28048 + f->name = (void __force_kernel *)compat_ptr(name);
28049 if (err) {
28050 err = -EFAULT;
28051 goto out;
28052 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
28053 index 6296b40..417c00f 100644
28054 --- a/block/partitions/efi.c
28055 +++ b/block/partitions/efi.c
28056 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
28057 if (!gpt)
28058 return NULL;
28059
28060 + if (!le32_to_cpu(gpt->num_partition_entries))
28061 + return NULL;
28062 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
28063 + if (!pte)
28064 + return NULL;
28065 +
28066 count = le32_to_cpu(gpt->num_partition_entries) *
28067 le32_to_cpu(gpt->sizeof_partition_entry);
28068 - if (!count)
28069 - return NULL;
28070 - pte = kzalloc(count, GFP_KERNEL);
28071 - if (!pte)
28072 - return NULL;
28073 -
28074 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
28075 (u8 *) pte,
28076 count) < count) {
28077 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
28078 index 9a87daa..fb17486 100644
28079 --- a/block/scsi_ioctl.c
28080 +++ b/block/scsi_ioctl.c
28081 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
28082 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
28083 struct sg_io_hdr *hdr, fmode_t mode)
28084 {
28085 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
28086 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28087 + unsigned char *cmdptr;
28088 +
28089 + if (rq->cmd != rq->__cmd)
28090 + cmdptr = rq->cmd;
28091 + else
28092 + cmdptr = tmpcmd;
28093 +
28094 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
28095 return -EFAULT;
28096 +
28097 + if (cmdptr != rq->cmd)
28098 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
28099 +
28100 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
28101 return -EPERM;
28102
28103 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28104 int err;
28105 unsigned int in_len, out_len, bytes, opcode, cmdlen;
28106 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
28107 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28108 + unsigned char *cmdptr;
28109
28110 if (!sic)
28111 return -EINVAL;
28112 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28113 */
28114 err = -EFAULT;
28115 rq->cmd_len = cmdlen;
28116 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
28117 +
28118 + if (rq->cmd != rq->__cmd)
28119 + cmdptr = rq->cmd;
28120 + else
28121 + cmdptr = tmpcmd;
28122 +
28123 + if (copy_from_user(cmdptr, sic->data, cmdlen))
28124 goto error;
28125
28126 + if (rq->cmd != cmdptr)
28127 + memcpy(rq->cmd, cmdptr, cmdlen);
28128 +
28129 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28130 goto error;
28131
28132 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28133 index 7bdd61b..afec999 100644
28134 --- a/crypto/cryptd.c
28135 +++ b/crypto/cryptd.c
28136 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28137
28138 struct cryptd_blkcipher_request_ctx {
28139 crypto_completion_t complete;
28140 -};
28141 +} __no_const;
28142
28143 struct cryptd_hash_ctx {
28144 struct crypto_shash *child;
28145 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28146
28147 struct cryptd_aead_request_ctx {
28148 crypto_completion_t complete;
28149 -};
28150 +} __no_const;
28151
28152 static void cryptd_queue_worker(struct work_struct *work);
28153
28154 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28155 index e6defd8..c26a225 100644
28156 --- a/drivers/acpi/apei/cper.c
28157 +++ b/drivers/acpi/apei/cper.c
28158 @@ -38,12 +38,12 @@
28159 */
28160 u64 cper_next_record_id(void)
28161 {
28162 - static atomic64_t seq;
28163 + static atomic64_unchecked_t seq;
28164
28165 - if (!atomic64_read(&seq))
28166 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
28167 + if (!atomic64_read_unchecked(&seq))
28168 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28169
28170 - return atomic64_inc_return(&seq);
28171 + return atomic64_inc_return_unchecked(&seq);
28172 }
28173 EXPORT_SYMBOL_GPL(cper_next_record_id);
28174
28175 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28176 index 7586544..636a2f0 100644
28177 --- a/drivers/acpi/ec_sys.c
28178 +++ b/drivers/acpi/ec_sys.c
28179 @@ -12,6 +12,7 @@
28180 #include <linux/acpi.h>
28181 #include <linux/debugfs.h>
28182 #include <linux/module.h>
28183 +#include <linux/uaccess.h>
28184 #include "internal.h"
28185
28186 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28187 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28188 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28189 */
28190 unsigned int size = EC_SPACE_SIZE;
28191 - u8 *data = (u8 *) buf;
28192 + u8 data;
28193 loff_t init_off = *off;
28194 int err = 0;
28195
28196 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28197 size = count;
28198
28199 while (size) {
28200 - err = ec_read(*off, &data[*off - init_off]);
28201 + err = ec_read(*off, &data);
28202 if (err)
28203 return err;
28204 + if (put_user(data, &buf[*off - init_off]))
28205 + return -EFAULT;
28206 *off += 1;
28207 size--;
28208 }
28209 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28210
28211 unsigned int size = count;
28212 loff_t init_off = *off;
28213 - u8 *data = (u8 *) buf;
28214 int err = 0;
28215
28216 if (*off >= EC_SPACE_SIZE)
28217 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28218 }
28219
28220 while (size) {
28221 - u8 byte_write = data[*off - init_off];
28222 + u8 byte_write;
28223 + if (get_user(byte_write, &buf[*off - init_off]))
28224 + return -EFAULT;
28225 err = ec_write(*off, byte_write);
28226 if (err)
28227 return err;
28228 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28229 index 27adb09..1ed412d 100644
28230 --- a/drivers/acpi/proc.c
28231 +++ b/drivers/acpi/proc.c
28232 @@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
28233 size_t count, loff_t * ppos)
28234 {
28235 struct list_head *node, *next;
28236 - char strbuf[5];
28237 - char str[5] = "";
28238 - unsigned int len = count;
28239 + char strbuf[5] = {0};
28240
28241 - if (len > 4)
28242 - len = 4;
28243 - if (len < 0)
28244 + if (count > 4)
28245 + count = 4;
28246 + if (copy_from_user(strbuf, buffer, count))
28247 return -EFAULT;
28248 -
28249 - if (copy_from_user(strbuf, buffer, len))
28250 - return -EFAULT;
28251 - strbuf[len] = '\0';
28252 - sscanf(strbuf, "%s", str);
28253 + strbuf[count] = '\0';
28254
28255 mutex_lock(&acpi_device_lock);
28256 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28257 @@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
28258 if (!dev->wakeup.flags.valid)
28259 continue;
28260
28261 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28262 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28263 if (device_can_wakeup(&dev->dev)) {
28264 bool enable = !device_may_wakeup(&dev->dev);
28265 device_set_wakeup_enable(&dev->dev, enable);
28266 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28267 index bd4e5dc..0497b66 100644
28268 --- a/drivers/acpi/processor_driver.c
28269 +++ b/drivers/acpi/processor_driver.c
28270 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28271 return 0;
28272 #endif
28273
28274 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28275 + BUG_ON(pr->id >= nr_cpu_ids);
28276
28277 /*
28278 * Buggy BIOS check
28279 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28280 index f46fbd3..b8341f3 100644
28281 --- a/drivers/ata/libata-core.c
28282 +++ b/drivers/ata/libata-core.c
28283 @@ -4774,7 +4774,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28284 struct ata_port *ap;
28285 unsigned int tag;
28286
28287 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28288 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28289 ap = qc->ap;
28290
28291 qc->flags = 0;
28292 @@ -4790,7 +4790,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28293 struct ata_port *ap;
28294 struct ata_link *link;
28295
28296 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28297 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28298 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28299 ap = qc->ap;
28300 link = qc->dev->link;
28301 @@ -5886,6 +5886,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28302 return;
28303
28304 spin_lock(&lock);
28305 + pax_open_kernel();
28306
28307 for (cur = ops->inherits; cur; cur = cur->inherits) {
28308 void **inherit = (void **)cur;
28309 @@ -5899,8 +5900,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28310 if (IS_ERR(*pp))
28311 *pp = NULL;
28312
28313 - ops->inherits = NULL;
28314 + *(struct ata_port_operations **)&ops->inherits = NULL;
28315
28316 + pax_close_kernel();
28317 spin_unlock(&lock);
28318 }
28319
28320 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28321 index 371fd2c..0836c78 100644
28322 --- a/drivers/ata/pata_arasan_cf.c
28323 +++ b/drivers/ata/pata_arasan_cf.c
28324 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28325 /* Handle platform specific quirks */
28326 if (pdata->quirk) {
28327 if (pdata->quirk & CF_BROKEN_PIO) {
28328 - ap->ops->set_piomode = NULL;
28329 + pax_open_kernel();
28330 + *(void **)&ap->ops->set_piomode = NULL;
28331 + pax_close_kernel();
28332 ap->pio_mask = 0;
28333 }
28334 if (pdata->quirk & CF_BROKEN_MWDMA)
28335 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28336 index f9b983a..887b9d8 100644
28337 --- a/drivers/atm/adummy.c
28338 +++ b/drivers/atm/adummy.c
28339 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28340 vcc->pop(vcc, skb);
28341 else
28342 dev_kfree_skb_any(skb);
28343 - atomic_inc(&vcc->stats->tx);
28344 + atomic_inc_unchecked(&vcc->stats->tx);
28345
28346 return 0;
28347 }
28348 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28349 index ff7bb8a..568fc0b 100644
28350 --- a/drivers/atm/ambassador.c
28351 +++ b/drivers/atm/ambassador.c
28352 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28353 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28354
28355 // VC layer stats
28356 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28357 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28358
28359 // free the descriptor
28360 kfree (tx_descr);
28361 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28362 dump_skb ("<<<", vc, skb);
28363
28364 // VC layer stats
28365 - atomic_inc(&atm_vcc->stats->rx);
28366 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28367 __net_timestamp(skb);
28368 // end of our responsibility
28369 atm_vcc->push (atm_vcc, skb);
28370 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28371 } else {
28372 PRINTK (KERN_INFO, "dropped over-size frame");
28373 // should we count this?
28374 - atomic_inc(&atm_vcc->stats->rx_drop);
28375 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28376 }
28377
28378 } else {
28379 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28380 }
28381
28382 if (check_area (skb->data, skb->len)) {
28383 - atomic_inc(&atm_vcc->stats->tx_err);
28384 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28385 return -ENOMEM; // ?
28386 }
28387
28388 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28389 index b22d71c..d6e1049 100644
28390 --- a/drivers/atm/atmtcp.c
28391 +++ b/drivers/atm/atmtcp.c
28392 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28393 if (vcc->pop) vcc->pop(vcc,skb);
28394 else dev_kfree_skb(skb);
28395 if (dev_data) return 0;
28396 - atomic_inc(&vcc->stats->tx_err);
28397 + atomic_inc_unchecked(&vcc->stats->tx_err);
28398 return -ENOLINK;
28399 }
28400 size = skb->len+sizeof(struct atmtcp_hdr);
28401 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28402 if (!new_skb) {
28403 if (vcc->pop) vcc->pop(vcc,skb);
28404 else dev_kfree_skb(skb);
28405 - atomic_inc(&vcc->stats->tx_err);
28406 + atomic_inc_unchecked(&vcc->stats->tx_err);
28407 return -ENOBUFS;
28408 }
28409 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28410 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28411 if (vcc->pop) vcc->pop(vcc,skb);
28412 else dev_kfree_skb(skb);
28413 out_vcc->push(out_vcc,new_skb);
28414 - atomic_inc(&vcc->stats->tx);
28415 - atomic_inc(&out_vcc->stats->rx);
28416 + atomic_inc_unchecked(&vcc->stats->tx);
28417 + atomic_inc_unchecked(&out_vcc->stats->rx);
28418 return 0;
28419 }
28420
28421 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28422 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28423 read_unlock(&vcc_sklist_lock);
28424 if (!out_vcc) {
28425 - atomic_inc(&vcc->stats->tx_err);
28426 + atomic_inc_unchecked(&vcc->stats->tx_err);
28427 goto done;
28428 }
28429 skb_pull(skb,sizeof(struct atmtcp_hdr));
28430 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28431 __net_timestamp(new_skb);
28432 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28433 out_vcc->push(out_vcc,new_skb);
28434 - atomic_inc(&vcc->stats->tx);
28435 - atomic_inc(&out_vcc->stats->rx);
28436 + atomic_inc_unchecked(&vcc->stats->tx);
28437 + atomic_inc_unchecked(&out_vcc->stats->rx);
28438 done:
28439 if (vcc->pop) vcc->pop(vcc,skb);
28440 else dev_kfree_skb(skb);
28441 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28442 index 81e44f7..498ea36 100644
28443 --- a/drivers/atm/eni.c
28444 +++ b/drivers/atm/eni.c
28445 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28446 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28447 vcc->dev->number);
28448 length = 0;
28449 - atomic_inc(&vcc->stats->rx_err);
28450 + atomic_inc_unchecked(&vcc->stats->rx_err);
28451 }
28452 else {
28453 length = ATM_CELL_SIZE-1; /* no HEC */
28454 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28455 size);
28456 }
28457 eff = length = 0;
28458 - atomic_inc(&vcc->stats->rx_err);
28459 + atomic_inc_unchecked(&vcc->stats->rx_err);
28460 }
28461 else {
28462 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28463 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28464 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28465 vcc->dev->number,vcc->vci,length,size << 2,descr);
28466 length = eff = 0;
28467 - atomic_inc(&vcc->stats->rx_err);
28468 + atomic_inc_unchecked(&vcc->stats->rx_err);
28469 }
28470 }
28471 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28472 @@ -767,7 +767,7 @@ rx_dequeued++;
28473 vcc->push(vcc,skb);
28474 pushed++;
28475 }
28476 - atomic_inc(&vcc->stats->rx);
28477 + atomic_inc_unchecked(&vcc->stats->rx);
28478 }
28479 wake_up(&eni_dev->rx_wait);
28480 }
28481 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28482 PCI_DMA_TODEVICE);
28483 if (vcc->pop) vcc->pop(vcc,skb);
28484 else dev_kfree_skb_irq(skb);
28485 - atomic_inc(&vcc->stats->tx);
28486 + atomic_inc_unchecked(&vcc->stats->tx);
28487 wake_up(&eni_dev->tx_wait);
28488 dma_complete++;
28489 }
28490 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28491 index 86fed1b..6dc4721 100644
28492 --- a/drivers/atm/firestream.c
28493 +++ b/drivers/atm/firestream.c
28494 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28495 }
28496 }
28497
28498 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28499 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28500
28501 fs_dprintk (FS_DEBUG_TXMEM, "i");
28502 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28503 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28504 #endif
28505 skb_put (skb, qe->p1 & 0xffff);
28506 ATM_SKB(skb)->vcc = atm_vcc;
28507 - atomic_inc(&atm_vcc->stats->rx);
28508 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28509 __net_timestamp(skb);
28510 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28511 atm_vcc->push (atm_vcc, skb);
28512 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28513 kfree (pe);
28514 }
28515 if (atm_vcc)
28516 - atomic_inc(&atm_vcc->stats->rx_drop);
28517 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28518 break;
28519 case 0x1f: /* Reassembly abort: no buffers. */
28520 /* Silently increment error counter. */
28521 if (atm_vcc)
28522 - atomic_inc(&atm_vcc->stats->rx_drop);
28523 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28524 break;
28525 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28526 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28527 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28528 index 361f5ae..7fc552d 100644
28529 --- a/drivers/atm/fore200e.c
28530 +++ b/drivers/atm/fore200e.c
28531 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28532 #endif
28533 /* check error condition */
28534 if (*entry->status & STATUS_ERROR)
28535 - atomic_inc(&vcc->stats->tx_err);
28536 + atomic_inc_unchecked(&vcc->stats->tx_err);
28537 else
28538 - atomic_inc(&vcc->stats->tx);
28539 + atomic_inc_unchecked(&vcc->stats->tx);
28540 }
28541 }
28542
28543 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28544 if (skb == NULL) {
28545 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28546
28547 - atomic_inc(&vcc->stats->rx_drop);
28548 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28549 return -ENOMEM;
28550 }
28551
28552 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28553
28554 dev_kfree_skb_any(skb);
28555
28556 - atomic_inc(&vcc->stats->rx_drop);
28557 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28558 return -ENOMEM;
28559 }
28560
28561 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28562
28563 vcc->push(vcc, skb);
28564 - atomic_inc(&vcc->stats->rx);
28565 + atomic_inc_unchecked(&vcc->stats->rx);
28566
28567 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28568
28569 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28570 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28571 fore200e->atm_dev->number,
28572 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28573 - atomic_inc(&vcc->stats->rx_err);
28574 + atomic_inc_unchecked(&vcc->stats->rx_err);
28575 }
28576 }
28577
28578 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28579 goto retry_here;
28580 }
28581
28582 - atomic_inc(&vcc->stats->tx_err);
28583 + atomic_inc_unchecked(&vcc->stats->tx_err);
28584
28585 fore200e->tx_sat++;
28586 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28587 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28588 index b182c2f..1c6fa8a 100644
28589 --- a/drivers/atm/he.c
28590 +++ b/drivers/atm/he.c
28591 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28592
28593 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28594 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28595 - atomic_inc(&vcc->stats->rx_drop);
28596 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28597 goto return_host_buffers;
28598 }
28599
28600 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28601 RBRQ_LEN_ERR(he_dev->rbrq_head)
28602 ? "LEN_ERR" : "",
28603 vcc->vpi, vcc->vci);
28604 - atomic_inc(&vcc->stats->rx_err);
28605 + atomic_inc_unchecked(&vcc->stats->rx_err);
28606 goto return_host_buffers;
28607 }
28608
28609 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28610 vcc->push(vcc, skb);
28611 spin_lock(&he_dev->global_lock);
28612
28613 - atomic_inc(&vcc->stats->rx);
28614 + atomic_inc_unchecked(&vcc->stats->rx);
28615
28616 return_host_buffers:
28617 ++pdus_assembled;
28618 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28619 tpd->vcc->pop(tpd->vcc, tpd->skb);
28620 else
28621 dev_kfree_skb_any(tpd->skb);
28622 - atomic_inc(&tpd->vcc->stats->tx_err);
28623 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28624 }
28625 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28626 return;
28627 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28628 vcc->pop(vcc, skb);
28629 else
28630 dev_kfree_skb_any(skb);
28631 - atomic_inc(&vcc->stats->tx_err);
28632 + atomic_inc_unchecked(&vcc->stats->tx_err);
28633 return -EINVAL;
28634 }
28635
28636 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28637 vcc->pop(vcc, skb);
28638 else
28639 dev_kfree_skb_any(skb);
28640 - atomic_inc(&vcc->stats->tx_err);
28641 + atomic_inc_unchecked(&vcc->stats->tx_err);
28642 return -EINVAL;
28643 }
28644 #endif
28645 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28646 vcc->pop(vcc, skb);
28647 else
28648 dev_kfree_skb_any(skb);
28649 - atomic_inc(&vcc->stats->tx_err);
28650 + atomic_inc_unchecked(&vcc->stats->tx_err);
28651 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28652 return -ENOMEM;
28653 }
28654 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28655 vcc->pop(vcc, skb);
28656 else
28657 dev_kfree_skb_any(skb);
28658 - atomic_inc(&vcc->stats->tx_err);
28659 + atomic_inc_unchecked(&vcc->stats->tx_err);
28660 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28661 return -ENOMEM;
28662 }
28663 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28664 __enqueue_tpd(he_dev, tpd, cid);
28665 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28666
28667 - atomic_inc(&vcc->stats->tx);
28668 + atomic_inc_unchecked(&vcc->stats->tx);
28669
28670 return 0;
28671 }
28672 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28673 index 7d01c2a..4e3ac01 100644
28674 --- a/drivers/atm/horizon.c
28675 +++ b/drivers/atm/horizon.c
28676 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28677 {
28678 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28679 // VC layer stats
28680 - atomic_inc(&vcc->stats->rx);
28681 + atomic_inc_unchecked(&vcc->stats->rx);
28682 __net_timestamp(skb);
28683 // end of our responsibility
28684 vcc->push (vcc, skb);
28685 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28686 dev->tx_iovec = NULL;
28687
28688 // VC layer stats
28689 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28690 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28691
28692 // free the skb
28693 hrz_kfree_skb (skb);
28694 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28695 index 8974bd2..b856f85 100644
28696 --- a/drivers/atm/idt77252.c
28697 +++ b/drivers/atm/idt77252.c
28698 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28699 else
28700 dev_kfree_skb(skb);
28701
28702 - atomic_inc(&vcc->stats->tx);
28703 + atomic_inc_unchecked(&vcc->stats->tx);
28704 }
28705
28706 atomic_dec(&scq->used);
28707 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28708 if ((sb = dev_alloc_skb(64)) == NULL) {
28709 printk("%s: Can't allocate buffers for aal0.\n",
28710 card->name);
28711 - atomic_add(i, &vcc->stats->rx_drop);
28712 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28713 break;
28714 }
28715 if (!atm_charge(vcc, sb->truesize)) {
28716 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28717 card->name);
28718 - atomic_add(i - 1, &vcc->stats->rx_drop);
28719 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28720 dev_kfree_skb(sb);
28721 break;
28722 }
28723 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28724 ATM_SKB(sb)->vcc = vcc;
28725 __net_timestamp(sb);
28726 vcc->push(vcc, sb);
28727 - atomic_inc(&vcc->stats->rx);
28728 + atomic_inc_unchecked(&vcc->stats->rx);
28729
28730 cell += ATM_CELL_PAYLOAD;
28731 }
28732 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28733 "(CDC: %08x)\n",
28734 card->name, len, rpp->len, readl(SAR_REG_CDC));
28735 recycle_rx_pool_skb(card, rpp);
28736 - atomic_inc(&vcc->stats->rx_err);
28737 + atomic_inc_unchecked(&vcc->stats->rx_err);
28738 return;
28739 }
28740 if (stat & SAR_RSQE_CRC) {
28741 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28742 recycle_rx_pool_skb(card, rpp);
28743 - atomic_inc(&vcc->stats->rx_err);
28744 + atomic_inc_unchecked(&vcc->stats->rx_err);
28745 return;
28746 }
28747 if (skb_queue_len(&rpp->queue) > 1) {
28748 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28749 RXPRINTK("%s: Can't alloc RX skb.\n",
28750 card->name);
28751 recycle_rx_pool_skb(card, rpp);
28752 - atomic_inc(&vcc->stats->rx_err);
28753 + atomic_inc_unchecked(&vcc->stats->rx_err);
28754 return;
28755 }
28756 if (!atm_charge(vcc, skb->truesize)) {
28757 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28758 __net_timestamp(skb);
28759
28760 vcc->push(vcc, skb);
28761 - atomic_inc(&vcc->stats->rx);
28762 + atomic_inc_unchecked(&vcc->stats->rx);
28763
28764 return;
28765 }
28766 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28767 __net_timestamp(skb);
28768
28769 vcc->push(vcc, skb);
28770 - atomic_inc(&vcc->stats->rx);
28771 + atomic_inc_unchecked(&vcc->stats->rx);
28772
28773 if (skb->truesize > SAR_FB_SIZE_3)
28774 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28775 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28776 if (vcc->qos.aal != ATM_AAL0) {
28777 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28778 card->name, vpi, vci);
28779 - atomic_inc(&vcc->stats->rx_drop);
28780 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28781 goto drop;
28782 }
28783
28784 if ((sb = dev_alloc_skb(64)) == NULL) {
28785 printk("%s: Can't allocate buffers for AAL0.\n",
28786 card->name);
28787 - atomic_inc(&vcc->stats->rx_err);
28788 + atomic_inc_unchecked(&vcc->stats->rx_err);
28789 goto drop;
28790 }
28791
28792 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28793 ATM_SKB(sb)->vcc = vcc;
28794 __net_timestamp(sb);
28795 vcc->push(vcc, sb);
28796 - atomic_inc(&vcc->stats->rx);
28797 + atomic_inc_unchecked(&vcc->stats->rx);
28798
28799 drop:
28800 skb_pull(queue, 64);
28801 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28802
28803 if (vc == NULL) {
28804 printk("%s: NULL connection in send().\n", card->name);
28805 - atomic_inc(&vcc->stats->tx_err);
28806 + atomic_inc_unchecked(&vcc->stats->tx_err);
28807 dev_kfree_skb(skb);
28808 return -EINVAL;
28809 }
28810 if (!test_bit(VCF_TX, &vc->flags)) {
28811 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28812 - atomic_inc(&vcc->stats->tx_err);
28813 + atomic_inc_unchecked(&vcc->stats->tx_err);
28814 dev_kfree_skb(skb);
28815 return -EINVAL;
28816 }
28817 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28818 break;
28819 default:
28820 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28821 - atomic_inc(&vcc->stats->tx_err);
28822 + atomic_inc_unchecked(&vcc->stats->tx_err);
28823 dev_kfree_skb(skb);
28824 return -EINVAL;
28825 }
28826
28827 if (skb_shinfo(skb)->nr_frags != 0) {
28828 printk("%s: No scatter-gather yet.\n", card->name);
28829 - atomic_inc(&vcc->stats->tx_err);
28830 + atomic_inc_unchecked(&vcc->stats->tx_err);
28831 dev_kfree_skb(skb);
28832 return -EINVAL;
28833 }
28834 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28835
28836 err = queue_skb(card, vc, skb, oam);
28837 if (err) {
28838 - atomic_inc(&vcc->stats->tx_err);
28839 + atomic_inc_unchecked(&vcc->stats->tx_err);
28840 dev_kfree_skb(skb);
28841 return err;
28842 }
28843 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28844 skb = dev_alloc_skb(64);
28845 if (!skb) {
28846 printk("%s: Out of memory in send_oam().\n", card->name);
28847 - atomic_inc(&vcc->stats->tx_err);
28848 + atomic_inc_unchecked(&vcc->stats->tx_err);
28849 return -ENOMEM;
28850 }
28851 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28852 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28853 index 96cce6d..62c3ec5 100644
28854 --- a/drivers/atm/iphase.c
28855 +++ b/drivers/atm/iphase.c
28856 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28857 status = (u_short) (buf_desc_ptr->desc_mode);
28858 if (status & (RX_CER | RX_PTE | RX_OFL))
28859 {
28860 - atomic_inc(&vcc->stats->rx_err);
28861 + atomic_inc_unchecked(&vcc->stats->rx_err);
28862 IF_ERR(printk("IA: bad packet, dropping it");)
28863 if (status & RX_CER) {
28864 IF_ERR(printk(" cause: packet CRC error\n");)
28865 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28866 len = dma_addr - buf_addr;
28867 if (len > iadev->rx_buf_sz) {
28868 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28869 - atomic_inc(&vcc->stats->rx_err);
28870 + atomic_inc_unchecked(&vcc->stats->rx_err);
28871 goto out_free_desc;
28872 }
28873
28874 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28875 ia_vcc = INPH_IA_VCC(vcc);
28876 if (ia_vcc == NULL)
28877 {
28878 - atomic_inc(&vcc->stats->rx_err);
28879 + atomic_inc_unchecked(&vcc->stats->rx_err);
28880 atm_return(vcc, skb->truesize);
28881 dev_kfree_skb_any(skb);
28882 goto INCR_DLE;
28883 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28884 if ((length > iadev->rx_buf_sz) || (length >
28885 (skb->len - sizeof(struct cpcs_trailer))))
28886 {
28887 - atomic_inc(&vcc->stats->rx_err);
28888 + atomic_inc_unchecked(&vcc->stats->rx_err);
28889 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28890 length, skb->len);)
28891 atm_return(vcc, skb->truesize);
28892 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28893
28894 IF_RX(printk("rx_dle_intr: skb push");)
28895 vcc->push(vcc,skb);
28896 - atomic_inc(&vcc->stats->rx);
28897 + atomic_inc_unchecked(&vcc->stats->rx);
28898 iadev->rx_pkt_cnt++;
28899 }
28900 INCR_DLE:
28901 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28902 {
28903 struct k_sonet_stats *stats;
28904 stats = &PRIV(_ia_dev[board])->sonet_stats;
28905 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28906 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28907 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28908 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28909 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28910 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28911 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28912 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28913 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28914 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28915 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28916 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28917 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28918 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28919 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28920 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28921 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28922 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28923 }
28924 ia_cmds.status = 0;
28925 break;
28926 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28927 if ((desc == 0) || (desc > iadev->num_tx_desc))
28928 {
28929 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28930 - atomic_inc(&vcc->stats->tx);
28931 + atomic_inc_unchecked(&vcc->stats->tx);
28932 if (vcc->pop)
28933 vcc->pop(vcc, skb);
28934 else
28935 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28936 ATM_DESC(skb) = vcc->vci;
28937 skb_queue_tail(&iadev->tx_dma_q, skb);
28938
28939 - atomic_inc(&vcc->stats->tx);
28940 + atomic_inc_unchecked(&vcc->stats->tx);
28941 iadev->tx_pkt_cnt++;
28942 /* Increment transaction counter */
28943 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28944
28945 #if 0
28946 /* add flow control logic */
28947 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28948 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28949 if (iavcc->vc_desc_cnt > 10) {
28950 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28951 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28952 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28953 index 68c7588..7036683 100644
28954 --- a/drivers/atm/lanai.c
28955 +++ b/drivers/atm/lanai.c
28956 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28957 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28958 lanai_endtx(lanai, lvcc);
28959 lanai_free_skb(lvcc->tx.atmvcc, skb);
28960 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28961 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28962 }
28963
28964 /* Try to fill the buffer - don't call unless there is backlog */
28965 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28966 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28967 __net_timestamp(skb);
28968 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28969 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28970 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28971 out:
28972 lvcc->rx.buf.ptr = end;
28973 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28974 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28975 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28976 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28977 lanai->stats.service_rxnotaal5++;
28978 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28979 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28980 return 0;
28981 }
28982 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28983 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28984 int bytes;
28985 read_unlock(&vcc_sklist_lock);
28986 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28987 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28988 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28989 lvcc->stats.x.aal5.service_trash++;
28990 bytes = (SERVICE_GET_END(s) * 16) -
28991 (((unsigned long) lvcc->rx.buf.ptr) -
28992 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28993 }
28994 if (s & SERVICE_STREAM) {
28995 read_unlock(&vcc_sklist_lock);
28996 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28997 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28998 lvcc->stats.x.aal5.service_stream++;
28999 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29000 "PDU on VCI %d!\n", lanai->number, vci);
29001 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29002 return 0;
29003 }
29004 DPRINTK("got rx crc error on vci %d\n", vci);
29005 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29006 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29007 lvcc->stats.x.aal5.service_rxcrc++;
29008 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29009 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29010 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29011 index 1c70c45..300718d 100644
29012 --- a/drivers/atm/nicstar.c
29013 +++ b/drivers/atm/nicstar.c
29014 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29015 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
29016 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
29017 card->index);
29018 - atomic_inc(&vcc->stats->tx_err);
29019 + atomic_inc_unchecked(&vcc->stats->tx_err);
29020 dev_kfree_skb_any(skb);
29021 return -EINVAL;
29022 }
29023 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29024 if (!vc->tx) {
29025 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
29026 card->index);
29027 - atomic_inc(&vcc->stats->tx_err);
29028 + atomic_inc_unchecked(&vcc->stats->tx_err);
29029 dev_kfree_skb_any(skb);
29030 return -EINVAL;
29031 }
29032 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29033 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
29034 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
29035 card->index);
29036 - atomic_inc(&vcc->stats->tx_err);
29037 + atomic_inc_unchecked(&vcc->stats->tx_err);
29038 dev_kfree_skb_any(skb);
29039 return -EINVAL;
29040 }
29041
29042 if (skb_shinfo(skb)->nr_frags != 0) {
29043 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29044 - atomic_inc(&vcc->stats->tx_err);
29045 + atomic_inc_unchecked(&vcc->stats->tx_err);
29046 dev_kfree_skb_any(skb);
29047 return -EINVAL;
29048 }
29049 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29050 }
29051
29052 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
29053 - atomic_inc(&vcc->stats->tx_err);
29054 + atomic_inc_unchecked(&vcc->stats->tx_err);
29055 dev_kfree_skb_any(skb);
29056 return -EIO;
29057 }
29058 - atomic_inc(&vcc->stats->tx);
29059 + atomic_inc_unchecked(&vcc->stats->tx);
29060
29061 return 0;
29062 }
29063 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29064 printk
29065 ("nicstar%d: Can't allocate buffers for aal0.\n",
29066 card->index);
29067 - atomic_add(i, &vcc->stats->rx_drop);
29068 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
29069 break;
29070 }
29071 if (!atm_charge(vcc, sb->truesize)) {
29072 RXPRINTK
29073 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
29074 card->index);
29075 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29076 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29077 dev_kfree_skb_any(sb);
29078 break;
29079 }
29080 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29081 ATM_SKB(sb)->vcc = vcc;
29082 __net_timestamp(sb);
29083 vcc->push(vcc, sb);
29084 - atomic_inc(&vcc->stats->rx);
29085 + atomic_inc_unchecked(&vcc->stats->rx);
29086 cell += ATM_CELL_PAYLOAD;
29087 }
29088
29089 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29090 if (iovb == NULL) {
29091 printk("nicstar%d: Out of iovec buffers.\n",
29092 card->index);
29093 - atomic_inc(&vcc->stats->rx_drop);
29094 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29095 recycle_rx_buf(card, skb);
29096 return;
29097 }
29098 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29099 small or large buffer itself. */
29100 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
29101 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29102 - atomic_inc(&vcc->stats->rx_err);
29103 + atomic_inc_unchecked(&vcc->stats->rx_err);
29104 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29105 NS_MAX_IOVECS);
29106 NS_PRV_IOVCNT(iovb) = 0;
29107 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29108 ("nicstar%d: Expected a small buffer, and this is not one.\n",
29109 card->index);
29110 which_list(card, skb);
29111 - atomic_inc(&vcc->stats->rx_err);
29112 + atomic_inc_unchecked(&vcc->stats->rx_err);
29113 recycle_rx_buf(card, skb);
29114 vc->rx_iov = NULL;
29115 recycle_iov_buf(card, iovb);
29116 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29117 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29118 card->index);
29119 which_list(card, skb);
29120 - atomic_inc(&vcc->stats->rx_err);
29121 + atomic_inc_unchecked(&vcc->stats->rx_err);
29122 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29123 NS_PRV_IOVCNT(iovb));
29124 vc->rx_iov = NULL;
29125 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29126 printk(" - PDU size mismatch.\n");
29127 else
29128 printk(".\n");
29129 - atomic_inc(&vcc->stats->rx_err);
29130 + atomic_inc_unchecked(&vcc->stats->rx_err);
29131 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29132 NS_PRV_IOVCNT(iovb));
29133 vc->rx_iov = NULL;
29134 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29135 /* skb points to a small buffer */
29136 if (!atm_charge(vcc, skb->truesize)) {
29137 push_rxbufs(card, skb);
29138 - atomic_inc(&vcc->stats->rx_drop);
29139 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29140 } else {
29141 skb_put(skb, len);
29142 dequeue_sm_buf(card, skb);
29143 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29144 ATM_SKB(skb)->vcc = vcc;
29145 __net_timestamp(skb);
29146 vcc->push(vcc, skb);
29147 - atomic_inc(&vcc->stats->rx);
29148 + atomic_inc_unchecked(&vcc->stats->rx);
29149 }
29150 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29151 struct sk_buff *sb;
29152 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29153 if (len <= NS_SMBUFSIZE) {
29154 if (!atm_charge(vcc, sb->truesize)) {
29155 push_rxbufs(card, sb);
29156 - atomic_inc(&vcc->stats->rx_drop);
29157 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29158 } else {
29159 skb_put(sb, len);
29160 dequeue_sm_buf(card, sb);
29161 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29162 ATM_SKB(sb)->vcc = vcc;
29163 __net_timestamp(sb);
29164 vcc->push(vcc, sb);
29165 - atomic_inc(&vcc->stats->rx);
29166 + atomic_inc_unchecked(&vcc->stats->rx);
29167 }
29168
29169 push_rxbufs(card, skb);
29170 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29171
29172 if (!atm_charge(vcc, skb->truesize)) {
29173 push_rxbufs(card, skb);
29174 - atomic_inc(&vcc->stats->rx_drop);
29175 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29176 } else {
29177 dequeue_lg_buf(card, skb);
29178 #ifdef NS_USE_DESTRUCTORS
29179 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29180 ATM_SKB(skb)->vcc = vcc;
29181 __net_timestamp(skb);
29182 vcc->push(vcc, skb);
29183 - atomic_inc(&vcc->stats->rx);
29184 + atomic_inc_unchecked(&vcc->stats->rx);
29185 }
29186
29187 push_rxbufs(card, sb);
29188 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29189 printk
29190 ("nicstar%d: Out of huge buffers.\n",
29191 card->index);
29192 - atomic_inc(&vcc->stats->rx_drop);
29193 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29194 recycle_iovec_rx_bufs(card,
29195 (struct iovec *)
29196 iovb->data,
29197 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29198 card->hbpool.count++;
29199 } else
29200 dev_kfree_skb_any(hb);
29201 - atomic_inc(&vcc->stats->rx_drop);
29202 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29203 } else {
29204 /* Copy the small buffer to the huge buffer */
29205 sb = (struct sk_buff *)iov->iov_base;
29206 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29207 #endif /* NS_USE_DESTRUCTORS */
29208 __net_timestamp(hb);
29209 vcc->push(vcc, hb);
29210 - atomic_inc(&vcc->stats->rx);
29211 + atomic_inc_unchecked(&vcc->stats->rx);
29212 }
29213 }
29214
29215 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29216 index 9851093..adb2b1e 100644
29217 --- a/drivers/atm/solos-pci.c
29218 +++ b/drivers/atm/solos-pci.c
29219 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29220 }
29221 atm_charge(vcc, skb->truesize);
29222 vcc->push(vcc, skb);
29223 - atomic_inc(&vcc->stats->rx);
29224 + atomic_inc_unchecked(&vcc->stats->rx);
29225 break;
29226
29227 case PKT_STATUS:
29228 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29229 vcc = SKB_CB(oldskb)->vcc;
29230
29231 if (vcc) {
29232 - atomic_inc(&vcc->stats->tx);
29233 + atomic_inc_unchecked(&vcc->stats->tx);
29234 solos_pop(vcc, oldskb);
29235 } else
29236 dev_kfree_skb_irq(oldskb);
29237 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29238 index 0215934..ce9f5b1 100644
29239 --- a/drivers/atm/suni.c
29240 +++ b/drivers/atm/suni.c
29241 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29242
29243
29244 #define ADD_LIMITED(s,v) \
29245 - atomic_add((v),&stats->s); \
29246 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29247 + atomic_add_unchecked((v),&stats->s); \
29248 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29249
29250
29251 static void suni_hz(unsigned long from_timer)
29252 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29253 index 5120a96..e2572bd 100644
29254 --- a/drivers/atm/uPD98402.c
29255 +++ b/drivers/atm/uPD98402.c
29256 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29257 struct sonet_stats tmp;
29258 int error = 0;
29259
29260 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29261 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29262 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29263 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29264 if (zero && !error) {
29265 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29266
29267
29268 #define ADD_LIMITED(s,v) \
29269 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29270 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29271 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29272 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29273 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29274 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29275
29276
29277 static void stat_event(struct atm_dev *dev)
29278 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29279 if (reason & uPD98402_INT_PFM) stat_event(dev);
29280 if (reason & uPD98402_INT_PCO) {
29281 (void) GET(PCOCR); /* clear interrupt cause */
29282 - atomic_add(GET(HECCT),
29283 + atomic_add_unchecked(GET(HECCT),
29284 &PRIV(dev)->sonet_stats.uncorr_hcs);
29285 }
29286 if ((reason & uPD98402_INT_RFO) &&
29287 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29288 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29289 uPD98402_INT_LOS),PIMR); /* enable them */
29290 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29291 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29292 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29293 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29294 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29295 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29296 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29297 return 0;
29298 }
29299
29300 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29301 index abe4e20..83c4727 100644
29302 --- a/drivers/atm/zatm.c
29303 +++ b/drivers/atm/zatm.c
29304 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29305 }
29306 if (!size) {
29307 dev_kfree_skb_irq(skb);
29308 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29309 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29310 continue;
29311 }
29312 if (!atm_charge(vcc,skb->truesize)) {
29313 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29314 skb->len = size;
29315 ATM_SKB(skb)->vcc = vcc;
29316 vcc->push(vcc,skb);
29317 - atomic_inc(&vcc->stats->rx);
29318 + atomic_inc_unchecked(&vcc->stats->rx);
29319 }
29320 zout(pos & 0xffff,MTA(mbx));
29321 #if 0 /* probably a stupid idea */
29322 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29323 skb_queue_head(&zatm_vcc->backlog,skb);
29324 break;
29325 }
29326 - atomic_inc(&vcc->stats->tx);
29327 + atomic_inc_unchecked(&vcc->stats->tx);
29328 wake_up(&zatm_vcc->tx_wait);
29329 }
29330
29331 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29332 index 147d1a4..d0fd4b0 100644
29333 --- a/drivers/base/devtmpfs.c
29334 +++ b/drivers/base/devtmpfs.c
29335 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29336 if (!thread)
29337 return 0;
29338
29339 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29340 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29341 if (err)
29342 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29343 else
29344 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29345 index e6ee5e8..98ad7fc 100644
29346 --- a/drivers/base/power/wakeup.c
29347 +++ b/drivers/base/power/wakeup.c
29348 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29349 * They need to be modified together atomically, so it's better to use one
29350 * atomic variable to hold them both.
29351 */
29352 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29353 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29354
29355 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29356 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29357
29358 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29359 {
29360 - unsigned int comb = atomic_read(&combined_event_count);
29361 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29362
29363 *cnt = (comb >> IN_PROGRESS_BITS);
29364 *inpr = comb & MAX_IN_PROGRESS;
29365 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29366 ws->start_prevent_time = ws->last_time;
29367
29368 /* Increment the counter of events in progress. */
29369 - cec = atomic_inc_return(&combined_event_count);
29370 + cec = atomic_inc_return_unchecked(&combined_event_count);
29371
29372 trace_wakeup_source_activate(ws->name, cec);
29373 }
29374 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29375 * Increment the counter of registered wakeup events and decrement the
29376 * couter of wakeup events in progress simultaneously.
29377 */
29378 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29379 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29380 trace_wakeup_source_deactivate(ws->name, cec);
29381
29382 split_counters(&cnt, &inpr);
29383 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29384 index ca83f96..69d4ea9 100644
29385 --- a/drivers/block/cciss.c
29386 +++ b/drivers/block/cciss.c
29387 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29388 int err;
29389 u32 cp;
29390
29391 + memset(&arg64, 0, sizeof(arg64));
29392 +
29393 err = 0;
29394 err |=
29395 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29396 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29397 while (!list_empty(&h->reqQ)) {
29398 c = list_entry(h->reqQ.next, CommandList_struct, list);
29399 /* can't do anything if fifo is full */
29400 - if ((h->access.fifo_full(h))) {
29401 + if ((h->access->fifo_full(h))) {
29402 dev_warn(&h->pdev->dev, "fifo full\n");
29403 break;
29404 }
29405 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29406 h->Qdepth--;
29407
29408 /* Tell the controller execute command */
29409 - h->access.submit_command(h, c);
29410 + h->access->submit_command(h, c);
29411
29412 /* Put job onto the completed Q */
29413 addQ(&h->cmpQ, c);
29414 @@ -3443,17 +3445,17 @@ startio:
29415
29416 static inline unsigned long get_next_completion(ctlr_info_t *h)
29417 {
29418 - return h->access.command_completed(h);
29419 + return h->access->command_completed(h);
29420 }
29421
29422 static inline int interrupt_pending(ctlr_info_t *h)
29423 {
29424 - return h->access.intr_pending(h);
29425 + return h->access->intr_pending(h);
29426 }
29427
29428 static inline long interrupt_not_for_us(ctlr_info_t *h)
29429 {
29430 - return ((h->access.intr_pending(h) == 0) ||
29431 + return ((h->access->intr_pending(h) == 0) ||
29432 (h->interrupts_enabled == 0));
29433 }
29434
29435 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29436 u32 a;
29437
29438 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29439 - return h->access.command_completed(h);
29440 + return h->access->command_completed(h);
29441
29442 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29443 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29444 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29445 trans_support & CFGTBL_Trans_use_short_tags);
29446
29447 /* Change the access methods to the performant access methods */
29448 - h->access = SA5_performant_access;
29449 + h->access = &SA5_performant_access;
29450 h->transMethod = CFGTBL_Trans_Performant;
29451
29452 return;
29453 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29454 if (prod_index < 0)
29455 return -ENODEV;
29456 h->product_name = products[prod_index].product_name;
29457 - h->access = *(products[prod_index].access);
29458 + h->access = products[prod_index].access;
29459
29460 if (cciss_board_disabled(h)) {
29461 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29462 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29463 }
29464
29465 /* make sure the board interrupts are off */
29466 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29467 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29468 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29469 if (rc)
29470 goto clean2;
29471 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29472 * fake ones to scoop up any residual completions.
29473 */
29474 spin_lock_irqsave(&h->lock, flags);
29475 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29476 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29477 spin_unlock_irqrestore(&h->lock, flags);
29478 free_irq(h->intr[h->intr_mode], h);
29479 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29480 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29481 dev_info(&h->pdev->dev, "Board READY.\n");
29482 dev_info(&h->pdev->dev,
29483 "Waiting for stale completions to drain.\n");
29484 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29485 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29486 msleep(10000);
29487 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29488 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29489
29490 rc = controller_reset_failed(h->cfgtable);
29491 if (rc)
29492 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29493 cciss_scsi_setup(h);
29494
29495 /* Turn the interrupts on so we can service requests */
29496 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29497 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29498
29499 /* Get the firmware version */
29500 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29501 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29502 kfree(flush_buf);
29503 if (return_code != IO_OK)
29504 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29505 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29506 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29507 free_irq(h->intr[h->intr_mode], h);
29508 }
29509
29510 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29511 index 7fda30e..eb5dfe0 100644
29512 --- a/drivers/block/cciss.h
29513 +++ b/drivers/block/cciss.h
29514 @@ -101,7 +101,7 @@ struct ctlr_info
29515 /* information about each logical volume */
29516 drive_info_struct *drv[CISS_MAX_LUN];
29517
29518 - struct access_method access;
29519 + struct access_method *access;
29520
29521 /* queue and queue Info */
29522 struct list_head reqQ;
29523 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29524 index 9125bbe..eede5c8 100644
29525 --- a/drivers/block/cpqarray.c
29526 +++ b/drivers/block/cpqarray.c
29527 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29528 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29529 goto Enomem4;
29530 }
29531 - hba[i]->access.set_intr_mask(hba[i], 0);
29532 + hba[i]->access->set_intr_mask(hba[i], 0);
29533 if (request_irq(hba[i]->intr, do_ida_intr,
29534 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29535 {
29536 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29537 add_timer(&hba[i]->timer);
29538
29539 /* Enable IRQ now that spinlock and rate limit timer are set up */
29540 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29541 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29542
29543 for(j=0; j<NWD; j++) {
29544 struct gendisk *disk = ida_gendisk[i][j];
29545 @@ -694,7 +694,7 @@ DBGINFO(
29546 for(i=0; i<NR_PRODUCTS; i++) {
29547 if (board_id == products[i].board_id) {
29548 c->product_name = products[i].product_name;
29549 - c->access = *(products[i].access);
29550 + c->access = products[i].access;
29551 break;
29552 }
29553 }
29554 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29555 hba[ctlr]->intr = intr;
29556 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29557 hba[ctlr]->product_name = products[j].product_name;
29558 - hba[ctlr]->access = *(products[j].access);
29559 + hba[ctlr]->access = products[j].access;
29560 hba[ctlr]->ctlr = ctlr;
29561 hba[ctlr]->board_id = board_id;
29562 hba[ctlr]->pci_dev = NULL; /* not PCI */
29563 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29564
29565 while((c = h->reqQ) != NULL) {
29566 /* Can't do anything if we're busy */
29567 - if (h->access.fifo_full(h) == 0)
29568 + if (h->access->fifo_full(h) == 0)
29569 return;
29570
29571 /* Get the first entry from the request Q */
29572 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29573 h->Qdepth--;
29574
29575 /* Tell the controller to do our bidding */
29576 - h->access.submit_command(h, c);
29577 + h->access->submit_command(h, c);
29578
29579 /* Get onto the completion Q */
29580 addQ(&h->cmpQ, c);
29581 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29582 unsigned long flags;
29583 __u32 a,a1;
29584
29585 - istat = h->access.intr_pending(h);
29586 + istat = h->access->intr_pending(h);
29587 /* Is this interrupt for us? */
29588 if (istat == 0)
29589 return IRQ_NONE;
29590 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29591 */
29592 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29593 if (istat & FIFO_NOT_EMPTY) {
29594 - while((a = h->access.command_completed(h))) {
29595 + while((a = h->access->command_completed(h))) {
29596 a1 = a; a &= ~3;
29597 if ((c = h->cmpQ) == NULL)
29598 {
29599 @@ -1449,11 +1449,11 @@ static int sendcmd(
29600 /*
29601 * Disable interrupt
29602 */
29603 - info_p->access.set_intr_mask(info_p, 0);
29604 + info_p->access->set_intr_mask(info_p, 0);
29605 /* Make sure there is room in the command FIFO */
29606 /* Actually it should be completely empty at this time. */
29607 for (i = 200000; i > 0; i--) {
29608 - temp = info_p->access.fifo_full(info_p);
29609 + temp = info_p->access->fifo_full(info_p);
29610 if (temp != 0) {
29611 break;
29612 }
29613 @@ -1466,7 +1466,7 @@ DBG(
29614 /*
29615 * Send the cmd
29616 */
29617 - info_p->access.submit_command(info_p, c);
29618 + info_p->access->submit_command(info_p, c);
29619 complete = pollcomplete(ctlr);
29620
29621 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29622 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29623 * we check the new geometry. Then turn interrupts back on when
29624 * we're done.
29625 */
29626 - host->access.set_intr_mask(host, 0);
29627 + host->access->set_intr_mask(host, 0);
29628 getgeometry(ctlr);
29629 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29630 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29631
29632 for(i=0; i<NWD; i++) {
29633 struct gendisk *disk = ida_gendisk[ctlr][i];
29634 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29635 /* Wait (up to 2 seconds) for a command to complete */
29636
29637 for (i = 200000; i > 0; i--) {
29638 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29639 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29640 if (done == 0) {
29641 udelay(10); /* a short fixed delay */
29642 } else
29643 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29644 index be73e9d..7fbf140 100644
29645 --- a/drivers/block/cpqarray.h
29646 +++ b/drivers/block/cpqarray.h
29647 @@ -99,7 +99,7 @@ struct ctlr_info {
29648 drv_info_t drv[NWD];
29649 struct proc_dir_entry *proc;
29650
29651 - struct access_method access;
29652 + struct access_method *access;
29653
29654 cmdlist_t *reqQ;
29655 cmdlist_t *cmpQ;
29656 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29657 index b953cc7..e3dc580 100644
29658 --- a/drivers/block/drbd/drbd_int.h
29659 +++ b/drivers/block/drbd/drbd_int.h
29660 @@ -735,7 +735,7 @@ struct drbd_request;
29661 struct drbd_epoch {
29662 struct list_head list;
29663 unsigned int barrier_nr;
29664 - atomic_t epoch_size; /* increased on every request added. */
29665 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29666 atomic_t active; /* increased on every req. added, and dec on every finished. */
29667 unsigned long flags;
29668 };
29669 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29670 void *int_dig_in;
29671 void *int_dig_vv;
29672 wait_queue_head_t seq_wait;
29673 - atomic_t packet_seq;
29674 + atomic_unchecked_t packet_seq;
29675 unsigned int peer_seq;
29676 spinlock_t peer_seq_lock;
29677 unsigned int minor;
29678 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29679
29680 static inline void drbd_tcp_cork(struct socket *sock)
29681 {
29682 - int __user val = 1;
29683 + int val = 1;
29684 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29685 - (char __user *)&val, sizeof(val));
29686 + (char __force_user *)&val, sizeof(val));
29687 }
29688
29689 static inline void drbd_tcp_uncork(struct socket *sock)
29690 {
29691 - int __user val = 0;
29692 + int val = 0;
29693 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29694 - (char __user *)&val, sizeof(val));
29695 + (char __force_user *)&val, sizeof(val));
29696 }
29697
29698 static inline void drbd_tcp_nodelay(struct socket *sock)
29699 {
29700 - int __user val = 1;
29701 + int val = 1;
29702 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29703 - (char __user *)&val, sizeof(val));
29704 + (char __force_user *)&val, sizeof(val));
29705 }
29706
29707 static inline void drbd_tcp_quickack(struct socket *sock)
29708 {
29709 - int __user val = 2;
29710 + int val = 2;
29711 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29712 - (char __user *)&val, sizeof(val));
29713 + (char __force_user *)&val, sizeof(val));
29714 }
29715
29716 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29717 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29718 index f55683a..2101b96 100644
29719 --- a/drivers/block/drbd/drbd_main.c
29720 +++ b/drivers/block/drbd/drbd_main.c
29721 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29722 p.sector = sector;
29723 p.block_id = block_id;
29724 p.blksize = blksize;
29725 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29726 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29727
29728 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29729 return false;
29730 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29731
29732 p.sector = cpu_to_be64(req->sector);
29733 p.block_id = (unsigned long)req;
29734 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29735 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29736
29737 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29738
29739 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29740 atomic_set(&mdev->unacked_cnt, 0);
29741 atomic_set(&mdev->local_cnt, 0);
29742 atomic_set(&mdev->net_cnt, 0);
29743 - atomic_set(&mdev->packet_seq, 0);
29744 + atomic_set_unchecked(&mdev->packet_seq, 0);
29745 atomic_set(&mdev->pp_in_use, 0);
29746 atomic_set(&mdev->pp_in_use_by_net, 0);
29747 atomic_set(&mdev->rs_sect_in, 0);
29748 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29749 mdev->receiver.t_state);
29750
29751 /* no need to lock it, I'm the only thread alive */
29752 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29753 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29754 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29755 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29756 mdev->al_writ_cnt =
29757 mdev->bm_writ_cnt =
29758 mdev->read_cnt =
29759 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29760 index edb490a..ecd69da 100644
29761 --- a/drivers/block/drbd/drbd_nl.c
29762 +++ b/drivers/block/drbd/drbd_nl.c
29763 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29764 module_put(THIS_MODULE);
29765 }
29766
29767 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29768 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29769
29770 static unsigned short *
29771 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29772 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29773 cn_reply->id.idx = CN_IDX_DRBD;
29774 cn_reply->id.val = CN_VAL_DRBD;
29775
29776 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29777 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29778 cn_reply->ack = 0; /* not used here. */
29779 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29780 (int)((char *)tl - (char *)reply->tag_list);
29781 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29782 cn_reply->id.idx = CN_IDX_DRBD;
29783 cn_reply->id.val = CN_VAL_DRBD;
29784
29785 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29786 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29787 cn_reply->ack = 0; /* not used here. */
29788 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29789 (int)((char *)tl - (char *)reply->tag_list);
29790 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29791 cn_reply->id.idx = CN_IDX_DRBD;
29792 cn_reply->id.val = CN_VAL_DRBD;
29793
29794 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29795 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29796 cn_reply->ack = 0; // not used here.
29797 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29798 (int)((char*)tl - (char*)reply->tag_list);
29799 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29800 cn_reply->id.idx = CN_IDX_DRBD;
29801 cn_reply->id.val = CN_VAL_DRBD;
29802
29803 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29804 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29805 cn_reply->ack = 0; /* not used here. */
29806 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29807 (int)((char *)tl - (char *)reply->tag_list);
29808 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29809 index c74ca2d..860c819 100644
29810 --- a/drivers/block/drbd/drbd_receiver.c
29811 +++ b/drivers/block/drbd/drbd_receiver.c
29812 @@ -898,7 +898,7 @@ retry:
29813 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29814 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29815
29816 - atomic_set(&mdev->packet_seq, 0);
29817 + atomic_set_unchecked(&mdev->packet_seq, 0);
29818 mdev->peer_seq = 0;
29819
29820 if (drbd_send_protocol(mdev) == -1)
29821 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29822 do {
29823 next_epoch = NULL;
29824
29825 - epoch_size = atomic_read(&epoch->epoch_size);
29826 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29827
29828 switch (ev & ~EV_CLEANUP) {
29829 case EV_PUT:
29830 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29831 rv = FE_DESTROYED;
29832 } else {
29833 epoch->flags = 0;
29834 - atomic_set(&epoch->epoch_size, 0);
29835 + atomic_set_unchecked(&epoch->epoch_size, 0);
29836 /* atomic_set(&epoch->active, 0); is already zero */
29837 if (rv == FE_STILL_LIVE)
29838 rv = FE_RECYCLED;
29839 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29840 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29841 drbd_flush(mdev);
29842
29843 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29844 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29845 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29846 if (epoch)
29847 break;
29848 }
29849
29850 epoch = mdev->current_epoch;
29851 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29852 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29853
29854 D_ASSERT(atomic_read(&epoch->active) == 0);
29855 D_ASSERT(epoch->flags == 0);
29856 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29857 }
29858
29859 epoch->flags = 0;
29860 - atomic_set(&epoch->epoch_size, 0);
29861 + atomic_set_unchecked(&epoch->epoch_size, 0);
29862 atomic_set(&epoch->active, 0);
29863
29864 spin_lock(&mdev->epoch_lock);
29865 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29866 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29867 list_add(&epoch->list, &mdev->current_epoch->list);
29868 mdev->current_epoch = epoch;
29869 mdev->epochs++;
29870 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29871 spin_unlock(&mdev->peer_seq_lock);
29872
29873 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29874 - atomic_inc(&mdev->current_epoch->epoch_size);
29875 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29876 return drbd_drain_block(mdev, data_size);
29877 }
29878
29879 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29880
29881 spin_lock(&mdev->epoch_lock);
29882 e->epoch = mdev->current_epoch;
29883 - atomic_inc(&e->epoch->epoch_size);
29884 + atomic_inc_unchecked(&e->epoch->epoch_size);
29885 atomic_inc(&e->epoch->active);
29886 spin_unlock(&mdev->epoch_lock);
29887
29888 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29889 D_ASSERT(list_empty(&mdev->done_ee));
29890
29891 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29892 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29893 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29894 D_ASSERT(list_empty(&mdev->current_epoch->list));
29895 }
29896
29897 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29898 index 54046e5..7759c55 100644
29899 --- a/drivers/block/loop.c
29900 +++ b/drivers/block/loop.c
29901 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29902 mm_segment_t old_fs = get_fs();
29903
29904 set_fs(get_ds());
29905 - bw = file->f_op->write(file, buf, len, &pos);
29906 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29907 set_fs(old_fs);
29908 if (likely(bw == len))
29909 return 0;
29910 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29911 index 72bedad..8181ce1 100644
29912 --- a/drivers/char/Kconfig
29913 +++ b/drivers/char/Kconfig
29914 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29915
29916 config DEVKMEM
29917 bool "/dev/kmem virtual device support"
29918 - default y
29919 + default n
29920 + depends on !GRKERNSEC_KMEM
29921 help
29922 Say Y here if you want to support the /dev/kmem device. The
29923 /dev/kmem device is rarely used, but can be used for certain
29924 @@ -581,6 +582,7 @@ config DEVPORT
29925 bool
29926 depends on !M68K
29927 depends on ISA || PCI
29928 + depends on !GRKERNSEC_KMEM
29929 default y
29930
29931 source "drivers/s390/char/Kconfig"
29932 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29933 index 2e04433..22afc64 100644
29934 --- a/drivers/char/agp/frontend.c
29935 +++ b/drivers/char/agp/frontend.c
29936 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29937 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29938 return -EFAULT;
29939
29940 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29941 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29942 return -EFAULT;
29943
29944 client = agp_find_client_by_pid(reserve.pid);
29945 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29946 index 21cb980..f15107c 100644
29947 --- a/drivers/char/genrtc.c
29948 +++ b/drivers/char/genrtc.c
29949 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29950 switch (cmd) {
29951
29952 case RTC_PLL_GET:
29953 + memset(&pll, 0, sizeof(pll));
29954 if (get_rtc_pll(&pll))
29955 return -EINVAL;
29956 else
29957 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29958 index dfd7876..c0b0885 100644
29959 --- a/drivers/char/hpet.c
29960 +++ b/drivers/char/hpet.c
29961 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29962 }
29963
29964 static int
29965 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29966 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29967 struct hpet_info *info)
29968 {
29969 struct hpet_timer __iomem *timer;
29970 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29971 index a0c84bb..9edcf60 100644
29972 --- a/drivers/char/ipmi/ipmi_msghandler.c
29973 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29974 @@ -420,7 +420,7 @@ struct ipmi_smi {
29975 struct proc_dir_entry *proc_dir;
29976 char proc_dir_name[10];
29977
29978 - atomic_t stats[IPMI_NUM_STATS];
29979 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29980
29981 /*
29982 * run_to_completion duplicate of smb_info, smi_info
29983 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29984
29985
29986 #define ipmi_inc_stat(intf, stat) \
29987 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29988 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29989 #define ipmi_get_stat(intf, stat) \
29990 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29991 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29992
29993 static int is_lan_addr(struct ipmi_addr *addr)
29994 {
29995 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29996 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29997 init_waitqueue_head(&intf->waitq);
29998 for (i = 0; i < IPMI_NUM_STATS; i++)
29999 - atomic_set(&intf->stats[i], 0);
30000 + atomic_set_unchecked(&intf->stats[i], 0);
30001
30002 intf->proc_dir = NULL;
30003
30004 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
30005 index 32a6c7e..f6966a9 100644
30006 --- a/drivers/char/ipmi/ipmi_si_intf.c
30007 +++ b/drivers/char/ipmi/ipmi_si_intf.c
30008 @@ -275,7 +275,7 @@ struct smi_info {
30009 unsigned char slave_addr;
30010
30011 /* Counters and things for the proc filesystem. */
30012 - atomic_t stats[SI_NUM_STATS];
30013 + atomic_unchecked_t stats[SI_NUM_STATS];
30014
30015 struct task_struct *thread;
30016
30017 @@ -284,9 +284,9 @@ struct smi_info {
30018 };
30019
30020 #define smi_inc_stat(smi, stat) \
30021 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
30022 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
30023 #define smi_get_stat(smi, stat) \
30024 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
30025 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
30026
30027 #define SI_MAX_PARMS 4
30028
30029 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
30030 atomic_set(&new_smi->req_events, 0);
30031 new_smi->run_to_completion = 0;
30032 for (i = 0; i < SI_NUM_STATS; i++)
30033 - atomic_set(&new_smi->stats[i], 0);
30034 + atomic_set_unchecked(&new_smi->stats[i], 0);
30035
30036 new_smi->interrupt_disabled = 1;
30037 atomic_set(&new_smi->stop_operation, 0);
30038 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
30039 index 0537903..121c699 100644
30040 --- a/drivers/char/mem.c
30041 +++ b/drivers/char/mem.c
30042 @@ -18,6 +18,7 @@
30043 #include <linux/raw.h>
30044 #include <linux/tty.h>
30045 #include <linux/capability.h>
30046 +#include <linux/security.h>
30047 #include <linux/ptrace.h>
30048 #include <linux/device.h>
30049 #include <linux/highmem.h>
30050 @@ -37,6 +38,10 @@
30051
30052 #define DEVPORT_MINOR 4
30053
30054 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30055 +extern const struct file_operations grsec_fops;
30056 +#endif
30057 +
30058 static inline unsigned long size_inside_page(unsigned long start,
30059 unsigned long size)
30060 {
30061 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30062
30063 while (cursor < to) {
30064 if (!devmem_is_allowed(pfn)) {
30065 +#ifdef CONFIG_GRKERNSEC_KMEM
30066 + gr_handle_mem_readwrite(from, to);
30067 +#else
30068 printk(KERN_INFO
30069 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
30070 current->comm, from, to);
30071 +#endif
30072 return 0;
30073 }
30074 cursor += PAGE_SIZE;
30075 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30076 }
30077 return 1;
30078 }
30079 +#elif defined(CONFIG_GRKERNSEC_KMEM)
30080 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30081 +{
30082 + return 0;
30083 +}
30084 #else
30085 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30086 {
30087 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30088
30089 while (count > 0) {
30090 unsigned long remaining;
30091 + char *temp;
30092
30093 sz = size_inside_page(p, count);
30094
30095 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30096 if (!ptr)
30097 return -EFAULT;
30098
30099 - remaining = copy_to_user(buf, ptr, sz);
30100 +#ifdef CONFIG_PAX_USERCOPY
30101 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30102 + if (!temp) {
30103 + unxlate_dev_mem_ptr(p, ptr);
30104 + return -ENOMEM;
30105 + }
30106 + memcpy(temp, ptr, sz);
30107 +#else
30108 + temp = ptr;
30109 +#endif
30110 +
30111 + remaining = copy_to_user(buf, temp, sz);
30112 +
30113 +#ifdef CONFIG_PAX_USERCOPY
30114 + kfree(temp);
30115 +#endif
30116 +
30117 unxlate_dev_mem_ptr(p, ptr);
30118 if (remaining)
30119 return -EFAULT;
30120 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30121 size_t count, loff_t *ppos)
30122 {
30123 unsigned long p = *ppos;
30124 - ssize_t low_count, read, sz;
30125 + ssize_t low_count, read, sz, err = 0;
30126 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30127 - int err = 0;
30128
30129 read = 0;
30130 if (p < (unsigned long) high_memory) {
30131 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30132 }
30133 #endif
30134 while (low_count > 0) {
30135 + char *temp;
30136 +
30137 sz = size_inside_page(p, low_count);
30138
30139 /*
30140 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30141 */
30142 kbuf = xlate_dev_kmem_ptr((char *)p);
30143
30144 - if (copy_to_user(buf, kbuf, sz))
30145 +#ifdef CONFIG_PAX_USERCOPY
30146 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30147 + if (!temp)
30148 + return -ENOMEM;
30149 + memcpy(temp, kbuf, sz);
30150 +#else
30151 + temp = kbuf;
30152 +#endif
30153 +
30154 + err = copy_to_user(buf, temp, sz);
30155 +
30156 +#ifdef CONFIG_PAX_USERCOPY
30157 + kfree(temp);
30158 +#endif
30159 +
30160 + if (err)
30161 return -EFAULT;
30162 buf += sz;
30163 p += sz;
30164 @@ -833,6 +880,9 @@ static const struct memdev {
30165 #ifdef CONFIG_CRASH_DUMP
30166 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30167 #endif
30168 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30169 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30170 +#endif
30171 };
30172
30173 static int memory_open(struct inode *inode, struct file *filp)
30174 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30175 index 9df78e2..01ba9ae 100644
30176 --- a/drivers/char/nvram.c
30177 +++ b/drivers/char/nvram.c
30178 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30179
30180 spin_unlock_irq(&rtc_lock);
30181
30182 - if (copy_to_user(buf, contents, tmp - contents))
30183 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30184 return -EFAULT;
30185
30186 *ppos = i;
30187 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30188 index 21721d2..4e98777 100644
30189 --- a/drivers/char/pcmcia/synclink_cs.c
30190 +++ b/drivers/char/pcmcia/synclink_cs.c
30191 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30192
30193 if (debug_level >= DEBUG_LEVEL_INFO)
30194 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30195 - __FILE__,__LINE__, info->device_name, port->count);
30196 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30197
30198 - WARN_ON(!port->count);
30199 + WARN_ON(!atomic_read(&port->count));
30200
30201 if (tty_port_close_start(port, tty, filp) == 0)
30202 goto cleanup;
30203 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30204 cleanup:
30205 if (debug_level >= DEBUG_LEVEL_INFO)
30206 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30207 - tty->driver->name, port->count);
30208 + tty->driver->name, atomic_read(&port->count));
30209 }
30210
30211 /* Wait until the transmitter is empty.
30212 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30213
30214 if (debug_level >= DEBUG_LEVEL_INFO)
30215 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30216 - __FILE__,__LINE__,tty->driver->name, port->count);
30217 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30218
30219 /* If port is closing, signal caller to try again */
30220 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30221 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30222 goto cleanup;
30223 }
30224 spin_lock(&port->lock);
30225 - port->count++;
30226 + atomic_inc(&port->count);
30227 spin_unlock(&port->lock);
30228 spin_unlock_irqrestore(&info->netlock, flags);
30229
30230 - if (port->count == 1) {
30231 + if (atomic_read(&port->count) == 1) {
30232 /* 1st open on this device, init hardware */
30233 retval = startup(info, tty);
30234 if (retval < 0)
30235 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30236 unsigned short new_crctype;
30237
30238 /* return error if TTY interface open */
30239 - if (info->port.count)
30240 + if (atomic_read(&info->port.count))
30241 return -EBUSY;
30242
30243 switch (encoding)
30244 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
30245
30246 /* arbitrate between network and tty opens */
30247 spin_lock_irqsave(&info->netlock, flags);
30248 - if (info->port.count != 0 || info->netcount != 0) {
30249 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30250 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30251 spin_unlock_irqrestore(&info->netlock, flags);
30252 return -EBUSY;
30253 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30254 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30255
30256 /* return error if TTY interface open */
30257 - if (info->port.count)
30258 + if (atomic_read(&info->port.count))
30259 return -EBUSY;
30260
30261 if (cmd != SIOCWANDEV)
30262 diff --git a/drivers/char/random.c b/drivers/char/random.c
30263 index b86eae9..4192a7a 100644
30264 --- a/drivers/char/random.c
30265 +++ b/drivers/char/random.c
30266 @@ -272,8 +272,13 @@
30267 /*
30268 * Configuration information
30269 */
30270 +#ifdef CONFIG_GRKERNSEC_RANDNET
30271 +#define INPUT_POOL_WORDS 512
30272 +#define OUTPUT_POOL_WORDS 128
30273 +#else
30274 #define INPUT_POOL_WORDS 128
30275 #define OUTPUT_POOL_WORDS 32
30276 +#endif
30277 #define SEC_XFER_SIZE 512
30278 #define EXTRACT_SIZE 10
30279
30280 @@ -313,10 +318,17 @@ static struct poolinfo {
30281 int poolwords;
30282 int tap1, tap2, tap3, tap4, tap5;
30283 } poolinfo_table[] = {
30284 +#ifdef CONFIG_GRKERNSEC_RANDNET
30285 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30286 + { 512, 411, 308, 208, 104, 1 },
30287 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30288 + { 128, 103, 76, 51, 25, 1 },
30289 +#else
30290 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30291 { 128, 103, 76, 51, 25, 1 },
30292 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30293 { 32, 26, 20, 14, 7, 1 },
30294 +#endif
30295 #if 0
30296 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30297 { 2048, 1638, 1231, 819, 411, 1 },
30298 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30299 input_rotate += i ? 7 : 14;
30300 }
30301
30302 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30303 - ACCESS_ONCE(r->add_ptr) = i;
30304 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30305 + ACCESS_ONCE_RW(r->add_ptr) = i;
30306 smp_wmb();
30307
30308 if (out)
30309 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30310 }
30311 #endif
30312
30313 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30314 +u64 latent_entropy;
30315 +
30316 +__init void transfer_latent_entropy(void)
30317 +{
30318 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30319 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30320 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30321 +}
30322 +#endif
30323 +
30324 /*********************************************************************
30325 *
30326 * Entropy extraction routines
30327 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30328
30329 extract_buf(r, tmp);
30330 i = min_t(int, nbytes, EXTRACT_SIZE);
30331 - if (copy_to_user(buf, tmp, i)) {
30332 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30333 ret = -EFAULT;
30334 break;
30335 }
30336 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30337 #include <linux/sysctl.h>
30338
30339 static int min_read_thresh = 8, min_write_thresh;
30340 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30341 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30342 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30343 static char sysctl_bootid[16];
30344
30345 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30346 index 9b4f011..b7e0a1a 100644
30347 --- a/drivers/char/sonypi.c
30348 +++ b/drivers/char/sonypi.c
30349 @@ -54,6 +54,7 @@
30350
30351 #include <asm/uaccess.h>
30352 #include <asm/io.h>
30353 +#include <asm/local.h>
30354
30355 #include <linux/sonypi.h>
30356
30357 @@ -490,7 +491,7 @@ static struct sonypi_device {
30358 spinlock_t fifo_lock;
30359 wait_queue_head_t fifo_proc_list;
30360 struct fasync_struct *fifo_async;
30361 - int open_count;
30362 + local_t open_count;
30363 int model;
30364 struct input_dev *input_jog_dev;
30365 struct input_dev *input_key_dev;
30366 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30367 static int sonypi_misc_release(struct inode *inode, struct file *file)
30368 {
30369 mutex_lock(&sonypi_device.lock);
30370 - sonypi_device.open_count--;
30371 + local_dec(&sonypi_device.open_count);
30372 mutex_unlock(&sonypi_device.lock);
30373 return 0;
30374 }
30375 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30376 {
30377 mutex_lock(&sonypi_device.lock);
30378 /* Flush input queue on first open */
30379 - if (!sonypi_device.open_count)
30380 + if (!local_read(&sonypi_device.open_count))
30381 kfifo_reset(&sonypi_device.fifo);
30382 - sonypi_device.open_count++;
30383 + local_inc(&sonypi_device.open_count);
30384 mutex_unlock(&sonypi_device.lock);
30385
30386 return 0;
30387 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30388 index 93211df..c7805f7 100644
30389 --- a/drivers/char/tpm/tpm.c
30390 +++ b/drivers/char/tpm/tpm.c
30391 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30392 chip->vendor.req_complete_val)
30393 goto out_recv;
30394
30395 - if ((status == chip->vendor.req_canceled)) {
30396 + if (status == chip->vendor.req_canceled) {
30397 dev_err(chip->dev, "Operation Canceled\n");
30398 rc = -ECANCELED;
30399 goto out;
30400 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
30401 index 56051d0..11cf3b7 100644
30402 --- a/drivers/char/tpm/tpm_acpi.c
30403 +++ b/drivers/char/tpm/tpm_acpi.c
30404 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
30405 virt = acpi_os_map_memory(start, len);
30406 if (!virt) {
30407 kfree(log->bios_event_log);
30408 + log->bios_event_log = NULL;
30409 printk("%s: ERROR - Unable to map memory\n", __func__);
30410 return -EIO;
30411 }
30412
30413 - memcpy_fromio(log->bios_event_log, virt, len);
30414 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
30415
30416 acpi_os_unmap_memory(virt, len);
30417 return 0;
30418 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
30419 index 84ddc55..1d32f1e 100644
30420 --- a/drivers/char/tpm/tpm_eventlog.c
30421 +++ b/drivers/char/tpm/tpm_eventlog.c
30422 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30423 event = addr;
30424
30425 if ((event->event_type == 0 && event->event_size == 0) ||
30426 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30427 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30428 return NULL;
30429
30430 return addr;
30431 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30432 return NULL;
30433
30434 if ((event->event_type == 0 && event->event_size == 0) ||
30435 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30436 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30437 return NULL;
30438
30439 (*pos)++;
30440 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30441 int i;
30442
30443 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30444 - seq_putc(m, data[i]);
30445 + if (!seq_putc(m, data[i]))
30446 + return -EFAULT;
30447
30448 return 0;
30449 }
30450 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30451 index 8ab9c3d..c3e65d3 100644
30452 --- a/drivers/char/virtio_console.c
30453 +++ b/drivers/char/virtio_console.c
30454 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30455 if (to_user) {
30456 ssize_t ret;
30457
30458 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30459 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30460 if (ret)
30461 return -EFAULT;
30462 } else {
30463 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30464 if (!port_has_data(port) && !port->host_connected)
30465 return 0;
30466
30467 - return fill_readbuf(port, ubuf, count, true);
30468 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30469 }
30470
30471 static int wait_port_writable(struct port *port, bool nonblock)
30472 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30473 index e164c55..3aabb50 100644
30474 --- a/drivers/edac/edac_pci_sysfs.c
30475 +++ b/drivers/edac/edac_pci_sysfs.c
30476 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30477 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30478 static int edac_pci_poll_msec = 1000; /* one second workq period */
30479
30480 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30481 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30482 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30483 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30484
30485 static struct kobject *edac_pci_top_main_kobj;
30486 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30487 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30488 edac_printk(KERN_CRIT, EDAC_PCI,
30489 "Signaled System Error on %s\n",
30490 pci_name(dev));
30491 - atomic_inc(&pci_nonparity_count);
30492 + atomic_inc_unchecked(&pci_nonparity_count);
30493 }
30494
30495 if (status & (PCI_STATUS_PARITY)) {
30496 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30497 "Master Data Parity Error on %s\n",
30498 pci_name(dev));
30499
30500 - atomic_inc(&pci_parity_count);
30501 + atomic_inc_unchecked(&pci_parity_count);
30502 }
30503
30504 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30505 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30506 "Detected Parity Error on %s\n",
30507 pci_name(dev));
30508
30509 - atomic_inc(&pci_parity_count);
30510 + atomic_inc_unchecked(&pci_parity_count);
30511 }
30512 }
30513
30514 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30515 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30516 "Signaled System Error on %s\n",
30517 pci_name(dev));
30518 - atomic_inc(&pci_nonparity_count);
30519 + atomic_inc_unchecked(&pci_nonparity_count);
30520 }
30521
30522 if (status & (PCI_STATUS_PARITY)) {
30523 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30524 "Master Data Parity Error on "
30525 "%s\n", pci_name(dev));
30526
30527 - atomic_inc(&pci_parity_count);
30528 + atomic_inc_unchecked(&pci_parity_count);
30529 }
30530
30531 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30532 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30533 "Detected Parity Error on %s\n",
30534 pci_name(dev));
30535
30536 - atomic_inc(&pci_parity_count);
30537 + atomic_inc_unchecked(&pci_parity_count);
30538 }
30539 }
30540 }
30541 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30542 if (!check_pci_errors)
30543 return;
30544
30545 - before_count = atomic_read(&pci_parity_count);
30546 + before_count = atomic_read_unchecked(&pci_parity_count);
30547
30548 /* scan all PCI devices looking for a Parity Error on devices and
30549 * bridges.
30550 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30551 /* Only if operator has selected panic on PCI Error */
30552 if (edac_pci_get_panic_on_pe()) {
30553 /* If the count is different 'after' from 'before' */
30554 - if (before_count != atomic_read(&pci_parity_count))
30555 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30556 panic("EDAC: PCI Parity Error");
30557 }
30558 }
30559 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30560 index 8c87a5e..a19cbd7 100644
30561 --- a/drivers/edac/mce_amd.h
30562 +++ b/drivers/edac/mce_amd.h
30563 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30564 struct amd_decoder_ops {
30565 bool (*dc_mce)(u16, u8);
30566 bool (*ic_mce)(u16, u8);
30567 -};
30568 +} __no_const;
30569
30570 void amd_report_gart_errors(bool);
30571 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30572 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30573 index 57ea7f4..789e3c3 100644
30574 --- a/drivers/firewire/core-card.c
30575 +++ b/drivers/firewire/core-card.c
30576 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30577
30578 void fw_core_remove_card(struct fw_card *card)
30579 {
30580 - struct fw_card_driver dummy_driver = dummy_driver_template;
30581 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30582
30583 card->driver->update_phy_reg(card, 4,
30584 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30585 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30586 index f8d2287..5aaf4db 100644
30587 --- a/drivers/firewire/core-cdev.c
30588 +++ b/drivers/firewire/core-cdev.c
30589 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30590 int ret;
30591
30592 if ((request->channels == 0 && request->bandwidth == 0) ||
30593 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30594 - request->bandwidth < 0)
30595 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30596 return -EINVAL;
30597
30598 r = kmalloc(sizeof(*r), GFP_KERNEL);
30599 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30600 index 28a94c7..58da63a 100644
30601 --- a/drivers/firewire/core-transaction.c
30602 +++ b/drivers/firewire/core-transaction.c
30603 @@ -38,6 +38,7 @@
30604 #include <linux/timer.h>
30605 #include <linux/types.h>
30606 #include <linux/workqueue.h>
30607 +#include <linux/sched.h>
30608
30609 #include <asm/byteorder.h>
30610
30611 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30612 index 515a42c..5ecf3ba 100644
30613 --- a/drivers/firewire/core.h
30614 +++ b/drivers/firewire/core.h
30615 @@ -111,6 +111,7 @@ struct fw_card_driver {
30616
30617 int (*stop_iso)(struct fw_iso_context *ctx);
30618 };
30619 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30620
30621 void fw_card_initialize(struct fw_card *card,
30622 const struct fw_card_driver *driver, struct device *device);
30623 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30624 index b298158..7ed8432 100644
30625 --- a/drivers/firmware/dmi_scan.c
30626 +++ b/drivers/firmware/dmi_scan.c
30627 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30628 }
30629 }
30630 else {
30631 - /*
30632 - * no iounmap() for that ioremap(); it would be a no-op, but
30633 - * it's so early in setup that sucker gets confused into doing
30634 - * what it shouldn't if we actually call it.
30635 - */
30636 p = dmi_ioremap(0xF0000, 0x10000);
30637 if (p == NULL)
30638 goto error;
30639 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30640 if (buf == NULL)
30641 return -1;
30642
30643 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30644 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30645
30646 iounmap(buf);
30647 return 0;
30648 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30649 index 82d5c20..44a7177 100644
30650 --- a/drivers/gpio/gpio-vr41xx.c
30651 +++ b/drivers/gpio/gpio-vr41xx.c
30652 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30653 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30654 maskl, pendl, maskh, pendh);
30655
30656 - atomic_inc(&irq_err_count);
30657 + atomic_inc_unchecked(&irq_err_count);
30658
30659 return -EINVAL;
30660 }
30661 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30662 index 1227adf..f2301c2 100644
30663 --- a/drivers/gpu/drm/drm_crtc_helper.c
30664 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30665 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30666 struct drm_crtc *tmp;
30667 int crtc_mask = 1;
30668
30669 - WARN(!crtc, "checking null crtc?\n");
30670 + BUG_ON(!crtc);
30671
30672 dev = crtc->dev;
30673
30674 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30675 index be174ca..0bcbb71 100644
30676 --- a/drivers/gpu/drm/drm_drv.c
30677 +++ b/drivers/gpu/drm/drm_drv.c
30678 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30679 /**
30680 * Copy and IOCTL return string to user space
30681 */
30682 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30683 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30684 {
30685 int len;
30686
30687 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30688 return -ENODEV;
30689
30690 atomic_inc(&dev->ioctl_count);
30691 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30692 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30693 ++file_priv->ioctl_count;
30694
30695 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30696 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30697 index 133b413..fd68225 100644
30698 --- a/drivers/gpu/drm/drm_fops.c
30699 +++ b/drivers/gpu/drm/drm_fops.c
30700 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30701 }
30702
30703 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30704 - atomic_set(&dev->counts[i], 0);
30705 + atomic_set_unchecked(&dev->counts[i], 0);
30706
30707 dev->sigdata.lock = NULL;
30708
30709 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30710 if (drm_device_is_unplugged(dev))
30711 return -ENODEV;
30712
30713 - if (!dev->open_count++)
30714 + if (local_inc_return(&dev->open_count) == 1)
30715 need_setup = 1;
30716 mutex_lock(&dev->struct_mutex);
30717 old_mapping = dev->dev_mapping;
30718 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30719 retcode = drm_open_helper(inode, filp, dev);
30720 if (retcode)
30721 goto err_undo;
30722 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30723 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30724 if (need_setup) {
30725 retcode = drm_setup(dev);
30726 if (retcode)
30727 @@ -164,7 +164,7 @@ err_undo:
30728 iput(container_of(dev->dev_mapping, struct inode, i_data));
30729 dev->dev_mapping = old_mapping;
30730 mutex_unlock(&dev->struct_mutex);
30731 - dev->open_count--;
30732 + local_dec(&dev->open_count);
30733 return retcode;
30734 }
30735 EXPORT_SYMBOL(drm_open);
30736 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30737
30738 mutex_lock(&drm_global_mutex);
30739
30740 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30741 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30742
30743 if (dev->driver->preclose)
30744 dev->driver->preclose(dev, file_priv);
30745 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30746 * Begin inline drm_release
30747 */
30748
30749 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30750 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30751 task_pid_nr(current),
30752 (long)old_encode_dev(file_priv->minor->device),
30753 - dev->open_count);
30754 + local_read(&dev->open_count));
30755
30756 /* Release any auth tokens that might point to this file_priv,
30757 (do that under the drm_global_mutex) */
30758 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
30759 * End inline drm_release
30760 */
30761
30762 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30763 - if (!--dev->open_count) {
30764 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30765 + if (local_dec_and_test(&dev->open_count)) {
30766 if (atomic_read(&dev->ioctl_count)) {
30767 DRM_ERROR("Device busy: %d\n",
30768 atomic_read(&dev->ioctl_count));
30769 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30770 index f731116..629842c 100644
30771 --- a/drivers/gpu/drm/drm_global.c
30772 +++ b/drivers/gpu/drm/drm_global.c
30773 @@ -36,7 +36,7 @@
30774 struct drm_global_item {
30775 struct mutex mutex;
30776 void *object;
30777 - int refcount;
30778 + atomic_t refcount;
30779 };
30780
30781 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30782 @@ -49,7 +49,7 @@ void drm_global_init(void)
30783 struct drm_global_item *item = &glob[i];
30784 mutex_init(&item->mutex);
30785 item->object = NULL;
30786 - item->refcount = 0;
30787 + atomic_set(&item->refcount, 0);
30788 }
30789 }
30790
30791 @@ -59,7 +59,7 @@ void drm_global_release(void)
30792 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30793 struct drm_global_item *item = &glob[i];
30794 BUG_ON(item->object != NULL);
30795 - BUG_ON(item->refcount != 0);
30796 + BUG_ON(atomic_read(&item->refcount) != 0);
30797 }
30798 }
30799
30800 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30801 void *object;
30802
30803 mutex_lock(&item->mutex);
30804 - if (item->refcount == 0) {
30805 + if (atomic_read(&item->refcount) == 0) {
30806 item->object = kzalloc(ref->size, GFP_KERNEL);
30807 if (unlikely(item->object == NULL)) {
30808 ret = -ENOMEM;
30809 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30810 goto out_err;
30811
30812 }
30813 - ++item->refcount;
30814 + atomic_inc(&item->refcount);
30815 ref->object = item->object;
30816 object = item->object;
30817 mutex_unlock(&item->mutex);
30818 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30819 struct drm_global_item *item = &glob[ref->global_type];
30820
30821 mutex_lock(&item->mutex);
30822 - BUG_ON(item->refcount == 0);
30823 + BUG_ON(atomic_read(&item->refcount) == 0);
30824 BUG_ON(ref->object != item->object);
30825 - if (--item->refcount == 0) {
30826 + if (atomic_dec_and_test(&item->refcount)) {
30827 ref->release(ref);
30828 item->object = NULL;
30829 }
30830 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30831 index d4b20ce..77a8d41 100644
30832 --- a/drivers/gpu/drm/drm_info.c
30833 +++ b/drivers/gpu/drm/drm_info.c
30834 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30835 struct drm_local_map *map;
30836 struct drm_map_list *r_list;
30837
30838 - /* Hardcoded from _DRM_FRAME_BUFFER,
30839 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30840 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30841 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30842 + static const char * const types[] = {
30843 + [_DRM_FRAME_BUFFER] = "FB",
30844 + [_DRM_REGISTERS] = "REG",
30845 + [_DRM_SHM] = "SHM",
30846 + [_DRM_AGP] = "AGP",
30847 + [_DRM_SCATTER_GATHER] = "SG",
30848 + [_DRM_CONSISTENT] = "PCI",
30849 + [_DRM_GEM] = "GEM" };
30850 const char *type;
30851 int i;
30852
30853 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30854 map = r_list->map;
30855 if (!map)
30856 continue;
30857 - if (map->type < 0 || map->type > 5)
30858 + if (map->type >= ARRAY_SIZE(types))
30859 type = "??";
30860 else
30861 type = types[map->type];
30862 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30863 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30864 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30865 vma->vm_flags & VM_IO ? 'i' : '-',
30866 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30867 + 0);
30868 +#else
30869 vma->vm_pgoff);
30870 +#endif
30871
30872 #if defined(__i386__)
30873 pgprot = pgprot_val(vma->vm_page_prot);
30874 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30875 index 2f4c434..764794b 100644
30876 --- a/drivers/gpu/drm/drm_ioc32.c
30877 +++ b/drivers/gpu/drm/drm_ioc32.c
30878 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30879 request = compat_alloc_user_space(nbytes);
30880 if (!access_ok(VERIFY_WRITE, request, nbytes))
30881 return -EFAULT;
30882 - list = (struct drm_buf_desc *) (request + 1);
30883 + list = (struct drm_buf_desc __user *) (request + 1);
30884
30885 if (__put_user(count, &request->count)
30886 || __put_user(list, &request->list))
30887 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30888 request = compat_alloc_user_space(nbytes);
30889 if (!access_ok(VERIFY_WRITE, request, nbytes))
30890 return -EFAULT;
30891 - list = (struct drm_buf_pub *) (request + 1);
30892 + list = (struct drm_buf_pub __user *) (request + 1);
30893
30894 if (__put_user(count, &request->count)
30895 || __put_user(list, &request->list))
30896 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30897 index 23dd975..63e9801 100644
30898 --- a/drivers/gpu/drm/drm_ioctl.c
30899 +++ b/drivers/gpu/drm/drm_ioctl.c
30900 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30901 stats->data[i].value =
30902 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30903 else
30904 - stats->data[i].value = atomic_read(&dev->counts[i]);
30905 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30906 stats->data[i].type = dev->types[i];
30907 }
30908
30909 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30910 index d752c96..fe08455 100644
30911 --- a/drivers/gpu/drm/drm_lock.c
30912 +++ b/drivers/gpu/drm/drm_lock.c
30913 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30914 if (drm_lock_take(&master->lock, lock->context)) {
30915 master->lock.file_priv = file_priv;
30916 master->lock.lock_time = jiffies;
30917 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30918 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30919 break; /* Got lock */
30920 }
30921
30922 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30923 return -EINVAL;
30924 }
30925
30926 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30927 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30928
30929 if (drm_lock_free(&master->lock, lock->context)) {
30930 /* FIXME: Should really bail out here. */
30931 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30932 index c236fd2..6b5f2e7 100644
30933 --- a/drivers/gpu/drm/drm_stub.c
30934 +++ b/drivers/gpu/drm/drm_stub.c
30935 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30936
30937 drm_device_set_unplugged(dev);
30938
30939 - if (dev->open_count == 0) {
30940 + if (local_read(&dev->open_count) == 0) {
30941 drm_put_dev(dev);
30942 }
30943 mutex_unlock(&drm_global_mutex);
30944 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30945 index 004ecdf..db1f6e0 100644
30946 --- a/drivers/gpu/drm/i810/i810_dma.c
30947 +++ b/drivers/gpu/drm/i810/i810_dma.c
30948 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30949 dma->buflist[vertex->idx],
30950 vertex->discard, vertex->used);
30951
30952 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30953 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30954 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30955 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30956 sarea_priv->last_enqueue = dev_priv->counter - 1;
30957 sarea_priv->last_dispatch = (int)hw_status[5];
30958
30959 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30960 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30961 mc->last_render);
30962
30963 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30964 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30965 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30966 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30967 sarea_priv->last_enqueue = dev_priv->counter - 1;
30968 sarea_priv->last_dispatch = (int)hw_status[5];
30969
30970 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30971 index 6e0acad..93c8289 100644
30972 --- a/drivers/gpu/drm/i810/i810_drv.h
30973 +++ b/drivers/gpu/drm/i810/i810_drv.h
30974 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30975 int page_flipping;
30976
30977 wait_queue_head_t irq_queue;
30978 - atomic_t irq_received;
30979 - atomic_t irq_emitted;
30980 + atomic_unchecked_t irq_received;
30981 + atomic_unchecked_t irq_emitted;
30982
30983 int front_offset;
30984 } drm_i810_private_t;
30985 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30986 index dde8b50..da88e32 100644
30987 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30988 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30989 @@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30990 I915_READ(GTIMR));
30991 }
30992 seq_printf(m, "Interrupts received: %d\n",
30993 - atomic_read(&dev_priv->irq_received));
30994 + atomic_read_unchecked(&dev_priv->irq_received));
30995 for_each_ring(ring, dev_priv, i) {
30996 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30997 seq_printf(m,
30998 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30999 index 61ae104..f8a4bc1 100644
31000 --- a/drivers/gpu/drm/i915/i915_dma.c
31001 +++ b/drivers/gpu/drm/i915/i915_dma.c
31002 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
31003 bool can_switch;
31004
31005 spin_lock(&dev->count_lock);
31006 - can_switch = (dev->open_count == 0);
31007 + can_switch = (local_read(&dev->open_count) == 0);
31008 spin_unlock(&dev->count_lock);
31009 return can_switch;
31010 }
31011 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
31012 index f511fa2..4c11773 100644
31013 --- a/drivers/gpu/drm/i915/i915_drv.h
31014 +++ b/drivers/gpu/drm/i915/i915_drv.h
31015 @@ -274,12 +274,12 @@ struct drm_i915_display_funcs {
31016 /* render clock increase/decrease */
31017 /* display clock increase/decrease */
31018 /* pll clock increase/decrease */
31019 -};
31020 +} __no_const;
31021
31022 struct drm_i915_gt_funcs {
31023 void (*force_wake_get)(struct drm_i915_private *dev_priv);
31024 void (*force_wake_put)(struct drm_i915_private *dev_priv);
31025 -};
31026 +} __no_const;
31027
31028 #define DEV_INFO_FLAGS \
31029 DEV_INFO_FLAG(is_mobile) DEV_INFO_SEP \
31030 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
31031
31032 struct resource mch_res;
31033
31034 - atomic_t irq_received;
31035 + atomic_unchecked_t irq_received;
31036
31037 /* protects the irq masks */
31038 spinlock_t irq_lock;
31039 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
31040 * will be page flipped away on the next vblank. When it
31041 * reaches 0, dev_priv->pending_flip_queue will be woken up.
31042 */
31043 - atomic_t pending_flip;
31044 + atomic_unchecked_t pending_flip;
31045 };
31046
31047 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
31048 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
31049 struct drm_i915_private *dev_priv, unsigned port);
31050 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
31051 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
31052 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31053 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31054 {
31055 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
31056 }
31057 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31058 index 3eea143..a0b77db 100644
31059 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31060 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31061 @@ -660,7 +660,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
31062 i915_gem_clflush_object(obj);
31063
31064 if (obj->base.pending_write_domain)
31065 - flips |= atomic_read(&obj->pending_flip);
31066 + flips |= atomic_read_unchecked(&obj->pending_flip);
31067
31068 flush_domains |= obj->base.write_domain;
31069 }
31070 @@ -691,9 +691,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
31071
31072 static int
31073 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
31074 - int count)
31075 + unsigned int count)
31076 {
31077 - int i;
31078 + unsigned int i;
31079
31080 for (i = 0; i < count; i++) {
31081 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
31082 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
31083 index 32e1bda..9b2ca91 100644
31084 --- a/drivers/gpu/drm/i915/i915_irq.c
31085 +++ b/drivers/gpu/drm/i915/i915_irq.c
31086 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
31087 u32 pipe_stats[I915_MAX_PIPES];
31088 bool blc_event;
31089
31090 - atomic_inc(&dev_priv->irq_received);
31091 + atomic_inc_unchecked(&dev_priv->irq_received);
31092
31093 while (true) {
31094 iir = I915_READ(VLV_IIR);
31095 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31096 irqreturn_t ret = IRQ_NONE;
31097 int i;
31098
31099 - atomic_inc(&dev_priv->irq_received);
31100 + atomic_inc_unchecked(&dev_priv->irq_received);
31101
31102 /* disable master interrupt before clearing iir */
31103 de_ier = I915_READ(DEIER);
31104 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31105 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31106 u32 hotplug_mask;
31107
31108 - atomic_inc(&dev_priv->irq_received);
31109 + atomic_inc_unchecked(&dev_priv->irq_received);
31110
31111 /* disable master interrupt before clearing iir */
31112 de_ier = I915_READ(DEIER);
31113 @@ -1760,7 +1760,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31114 {
31115 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31116
31117 - atomic_set(&dev_priv->irq_received, 0);
31118 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31119
31120 I915_WRITE(HWSTAM, 0xeffe);
31121
31122 @@ -1786,7 +1786,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31123 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31124 int pipe;
31125
31126 - atomic_set(&dev_priv->irq_received, 0);
31127 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31128
31129 /* VLV magic */
31130 I915_WRITE(VLV_IMR, 0);
31131 @@ -2091,7 +2091,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31132 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31133 int pipe;
31134
31135 - atomic_set(&dev_priv->irq_received, 0);
31136 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31137
31138 for_each_pipe(pipe)
31139 I915_WRITE(PIPESTAT(pipe), 0);
31140 @@ -2142,7 +2142,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31141 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31142 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31143
31144 - atomic_inc(&dev_priv->irq_received);
31145 + atomic_inc_unchecked(&dev_priv->irq_received);
31146
31147 iir = I915_READ16(IIR);
31148 if (iir == 0)
31149 @@ -2227,7 +2227,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31150 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31151 int pipe;
31152
31153 - atomic_set(&dev_priv->irq_received, 0);
31154 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31155
31156 if (I915_HAS_HOTPLUG(dev)) {
31157 I915_WRITE(PORT_HOTPLUG_EN, 0);
31158 @@ -2322,7 +2322,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31159 };
31160 int pipe, ret = IRQ_NONE;
31161
31162 - atomic_inc(&dev_priv->irq_received);
31163 + atomic_inc_unchecked(&dev_priv->irq_received);
31164
31165 iir = I915_READ(IIR);
31166 do {
31167 @@ -2448,7 +2448,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31168 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31169 int pipe;
31170
31171 - atomic_set(&dev_priv->irq_received, 0);
31172 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31173
31174 I915_WRITE(PORT_HOTPLUG_EN, 0);
31175 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31176 @@ -2555,7 +2555,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31177 int irq_received;
31178 int ret = IRQ_NONE, pipe;
31179
31180 - atomic_inc(&dev_priv->irq_received);
31181 + atomic_inc_unchecked(&dev_priv->irq_received);
31182
31183 iir = I915_READ(IIR);
31184
31185 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31186 index b426d44..1b9038d 100644
31187 --- a/drivers/gpu/drm/i915/intel_display.c
31188 +++ b/drivers/gpu/drm/i915/intel_display.c
31189 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31190
31191 wait_event(dev_priv->pending_flip_queue,
31192 atomic_read(&dev_priv->mm.wedged) ||
31193 - atomic_read(&obj->pending_flip) == 0);
31194 + atomic_read_unchecked(&obj->pending_flip) == 0);
31195
31196 /* Big Hammer, we also need to ensure that any pending
31197 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31198 @@ -6236,8 +6236,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31199
31200 obj = work->old_fb_obj;
31201
31202 - atomic_clear_mask(1 << intel_crtc->plane,
31203 - &obj->pending_flip.counter);
31204 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31205
31206 wake_up(&dev_priv->pending_flip_queue);
31207 schedule_work(&work->work);
31208 @@ -6583,7 +6582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31209 /* Block clients from rendering to the new back buffer until
31210 * the flip occurs and the object is no longer visible.
31211 */
31212 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31213 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31214
31215 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31216 if (ret)
31217 @@ -6598,7 +6597,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31218 return 0;
31219
31220 cleanup_pending:
31221 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31222 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31223 drm_gem_object_unreference(&work->old_fb_obj->base);
31224 drm_gem_object_unreference(&obj->base);
31225 mutex_unlock(&dev->struct_mutex);
31226 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31227 index 54558a0..2d97005 100644
31228 --- a/drivers/gpu/drm/mga/mga_drv.h
31229 +++ b/drivers/gpu/drm/mga/mga_drv.h
31230 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31231 u32 clear_cmd;
31232 u32 maccess;
31233
31234 - atomic_t vbl_received; /**< Number of vblanks received. */
31235 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31236 wait_queue_head_t fence_queue;
31237 - atomic_t last_fence_retired;
31238 + atomic_unchecked_t last_fence_retired;
31239 u32 next_fence_to_post;
31240
31241 unsigned int fb_cpp;
31242 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31243 index 598c281..60d590e 100644
31244 --- a/drivers/gpu/drm/mga/mga_irq.c
31245 +++ b/drivers/gpu/drm/mga/mga_irq.c
31246 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31247 if (crtc != 0)
31248 return 0;
31249
31250 - return atomic_read(&dev_priv->vbl_received);
31251 + return atomic_read_unchecked(&dev_priv->vbl_received);
31252 }
31253
31254
31255 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31256 /* VBLANK interrupt */
31257 if (status & MGA_VLINEPEN) {
31258 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31259 - atomic_inc(&dev_priv->vbl_received);
31260 + atomic_inc_unchecked(&dev_priv->vbl_received);
31261 drm_handle_vblank(dev, 0);
31262 handled = 1;
31263 }
31264 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31265 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31266 MGA_WRITE(MGA_PRIMEND, prim_end);
31267
31268 - atomic_inc(&dev_priv->last_fence_retired);
31269 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31270 DRM_WAKEUP(&dev_priv->fence_queue);
31271 handled = 1;
31272 }
31273 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31274 * using fences.
31275 */
31276 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31277 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31278 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31279 - *sequence) <= (1 << 23)));
31280
31281 *sequence = cur_fence;
31282 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31283 index 09fdef2..57f5c3b 100644
31284 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31285 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31286 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31287 struct bit_table {
31288 const char id;
31289 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31290 -};
31291 +} __no_const;
31292
31293 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31294
31295 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
31296 index a101699..a163f0a 100644
31297 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
31298 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
31299 @@ -80,7 +80,7 @@ struct nouveau_drm {
31300 struct drm_global_reference mem_global_ref;
31301 struct ttm_bo_global_ref bo_global_ref;
31302 struct ttm_bo_device bdev;
31303 - atomic_t validate_sequence;
31304 + atomic_unchecked_t validate_sequence;
31305 int (*move)(struct nouveau_channel *,
31306 struct ttm_buffer_object *,
31307 struct ttm_mem_reg *, struct ttm_mem_reg *);
31308 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
31309 index bedafd1..ca5330a 100644
31310 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
31311 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
31312 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
31313 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
31314 struct nouveau_channel *);
31315 u32 (*read)(struct nouveau_channel *);
31316 -};
31317 +} __no_const;
31318
31319 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
31320
31321 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31322 index 5e2f521..0d21436 100644
31323 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31324 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31325 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31326 int trycnt = 0;
31327 int ret, i;
31328
31329 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
31330 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
31331 retry:
31332 if (++trycnt > 100000) {
31333 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
31334 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
31335 index 6f0ac64..9c2dfb4 100644
31336 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
31337 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
31338 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31339 bool can_switch;
31340
31341 spin_lock(&dev->count_lock);
31342 - can_switch = (dev->open_count == 0);
31343 + can_switch = (local_read(&dev->open_count) == 0);
31344 spin_unlock(&dev->count_lock);
31345 return can_switch;
31346 }
31347 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
31348 index 9f6f55c..30e3a29 100644
31349 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
31350 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
31351 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
31352 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
31353 evo->object->oclass->ofuncs =
31354 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
31355 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
31356 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
31357 - evo->object->oclass->ofuncs->rd08 =
31358 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
31359 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
31360 + *(void**)&evo->object->oclass->ofuncs->rd08 =
31361 ioremap(pci_resource_start(dev->pdev, 0) +
31362 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
31363 return 0;
31364 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31365 index b562b59..9d725a8 100644
31366 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31367 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31368 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31369 }
31370
31371 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
31372 - struct dp_train_func func = {
31373 + static struct dp_train_func func = {
31374 .link_set = nv50_sor_dp_link_set,
31375 .train_set = nv50_sor_dp_train_set,
31376 .train_adj = nv50_sor_dp_train_adj
31377 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31378 index c402fca..f1d694b 100644
31379 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31380 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31381 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31382 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31383
31384 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
31385 - struct dp_train_func func = {
31386 + static struct dp_train_func func = {
31387 .link_set = nvd0_sor_dp_link_set,
31388 .train_set = nvd0_sor_dp_train_set,
31389 .train_adj = nvd0_sor_dp_train_adj
31390 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31391 index d4660cf..70dbe65 100644
31392 --- a/drivers/gpu/drm/r128/r128_cce.c
31393 +++ b/drivers/gpu/drm/r128/r128_cce.c
31394 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31395
31396 /* GH: Simple idle check.
31397 */
31398 - atomic_set(&dev_priv->idle_count, 0);
31399 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31400
31401 /* We don't support anything other than bus-mastering ring mode,
31402 * but the ring can be in either AGP or PCI space for the ring
31403 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31404 index 930c71b..499aded 100644
31405 --- a/drivers/gpu/drm/r128/r128_drv.h
31406 +++ b/drivers/gpu/drm/r128/r128_drv.h
31407 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31408 int is_pci;
31409 unsigned long cce_buffers_offset;
31410
31411 - atomic_t idle_count;
31412 + atomic_unchecked_t idle_count;
31413
31414 int page_flipping;
31415 int current_page;
31416 u32 crtc_offset;
31417 u32 crtc_offset_cntl;
31418
31419 - atomic_t vbl_received;
31420 + atomic_unchecked_t vbl_received;
31421
31422 u32 color_fmt;
31423 unsigned int front_offset;
31424 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31425 index 2ea4f09..d391371 100644
31426 --- a/drivers/gpu/drm/r128/r128_irq.c
31427 +++ b/drivers/gpu/drm/r128/r128_irq.c
31428 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31429 if (crtc != 0)
31430 return 0;
31431
31432 - return atomic_read(&dev_priv->vbl_received);
31433 + return atomic_read_unchecked(&dev_priv->vbl_received);
31434 }
31435
31436 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31437 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31438 /* VBLANK interrupt */
31439 if (status & R128_CRTC_VBLANK_INT) {
31440 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31441 - atomic_inc(&dev_priv->vbl_received);
31442 + atomic_inc_unchecked(&dev_priv->vbl_received);
31443 drm_handle_vblank(dev, 0);
31444 return IRQ_HANDLED;
31445 }
31446 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31447 index 19bb7e6..de7e2a2 100644
31448 --- a/drivers/gpu/drm/r128/r128_state.c
31449 +++ b/drivers/gpu/drm/r128/r128_state.c
31450 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31451
31452 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31453 {
31454 - if (atomic_read(&dev_priv->idle_count) == 0)
31455 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31456 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31457 else
31458 - atomic_set(&dev_priv->idle_count, 0);
31459 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31460 }
31461
31462 #endif
31463 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31464 index 5a82b6b..9e69c73 100644
31465 --- a/drivers/gpu/drm/radeon/mkregtable.c
31466 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31467 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31468 regex_t mask_rex;
31469 regmatch_t match[4];
31470 char buf[1024];
31471 - size_t end;
31472 + long end;
31473 int len;
31474 int done = 0;
31475 int r;
31476 unsigned o;
31477 struct offset *offset;
31478 char last_reg_s[10];
31479 - int last_reg;
31480 + unsigned long last_reg;
31481
31482 if (regcomp
31483 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31484 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31485 index 8c42d54..5ef3789 100644
31486 --- a/drivers/gpu/drm/radeon/radeon.h
31487 +++ b/drivers/gpu/drm/radeon/radeon.h
31488 @@ -728,7 +728,7 @@ struct r600_blit_cp_primitives {
31489 int x2, int y2);
31490 void (*draw_auto)(struct radeon_device *rdev);
31491 void (*set_default_state)(struct radeon_device *rdev);
31492 -};
31493 +} __no_const;
31494
31495 struct r600_blit {
31496 struct radeon_bo *shader_obj;
31497 @@ -1248,7 +1248,7 @@ struct radeon_asic {
31498 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31499 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31500 } pflip;
31501 -};
31502 +} __no_const;
31503
31504 /*
31505 * Asic structures
31506 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31507 index e2f5f88..82f22da 100644
31508 --- a/drivers/gpu/drm/radeon/radeon_device.c
31509 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31510 @@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31511 bool can_switch;
31512
31513 spin_lock(&dev->count_lock);
31514 - can_switch = (dev->open_count == 0);
31515 + can_switch = (local_read(&dev->open_count) == 0);
31516 spin_unlock(&dev->count_lock);
31517 return can_switch;
31518 }
31519 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31520 index a1b59ca..86f2d44 100644
31521 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31522 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31523 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31524
31525 /* SW interrupt */
31526 wait_queue_head_t swi_queue;
31527 - atomic_t swi_emitted;
31528 + atomic_unchecked_t swi_emitted;
31529 int vblank_crtc;
31530 uint32_t irq_enable_reg;
31531 uint32_t r500_disp_irq_reg;
31532 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31533 index c180df8..cd80dd2d 100644
31534 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31535 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31536 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31537 request = compat_alloc_user_space(sizeof(*request));
31538 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31539 || __put_user(req32.param, &request->param)
31540 - || __put_user((void __user *)(unsigned long)req32.value,
31541 + || __put_user((unsigned long)req32.value,
31542 &request->value))
31543 return -EFAULT;
31544
31545 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31546 index e771033..a0bc6b3 100644
31547 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31548 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31549 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31550 unsigned int ret;
31551 RING_LOCALS;
31552
31553 - atomic_inc(&dev_priv->swi_emitted);
31554 - ret = atomic_read(&dev_priv->swi_emitted);
31555 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31556 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31557
31558 BEGIN_RING(4);
31559 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31560 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31561 drm_radeon_private_t *dev_priv =
31562 (drm_radeon_private_t *) dev->dev_private;
31563
31564 - atomic_set(&dev_priv->swi_emitted, 0);
31565 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31566 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31567
31568 dev->max_vblank_count = 0x001fffff;
31569 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31570 index 8e9057b..af6dacb 100644
31571 --- a/drivers/gpu/drm/radeon/radeon_state.c
31572 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31573 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31574 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31575 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31576
31577 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31578 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31579 sarea_priv->nbox * sizeof(depth_boxes[0])))
31580 return -EFAULT;
31581
31582 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31583 {
31584 drm_radeon_private_t *dev_priv = dev->dev_private;
31585 drm_radeon_getparam_t *param = data;
31586 - int value;
31587 + int value = 0;
31588
31589 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31590
31591 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31592 index 5ebe1b3..1ed9426 100644
31593 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31594 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31595 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31596 }
31597 if (unlikely(ttm_vm_ops == NULL)) {
31598 ttm_vm_ops = vma->vm_ops;
31599 - radeon_ttm_vm_ops = *ttm_vm_ops;
31600 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31601 + pax_open_kernel();
31602 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31603 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31604 + pax_close_kernel();
31605 }
31606 vma->vm_ops = &radeon_ttm_vm_ops;
31607 return 0;
31608 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31609 index 5706d2a..17aedaa 100644
31610 --- a/drivers/gpu/drm/radeon/rs690.c
31611 +++ b/drivers/gpu/drm/radeon/rs690.c
31612 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31613 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31614 rdev->pm.sideport_bandwidth.full)
31615 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31616 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31617 + read_delay_latency.full = dfixed_const(800 * 1000);
31618 read_delay_latency.full = dfixed_div(read_delay_latency,
31619 rdev->pm.igp_sideport_mclk);
31620 + a.full = dfixed_const(370);
31621 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31622 } else {
31623 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31624 rdev->pm.k8_bandwidth.full)
31625 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31626 index bd2a3b4..122d9ad 100644
31627 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31628 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31629 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31630 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31631 struct shrink_control *sc)
31632 {
31633 - static atomic_t start_pool = ATOMIC_INIT(0);
31634 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31635 unsigned i;
31636 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31637 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31638 struct ttm_page_pool *pool;
31639 int shrink_pages = sc->nr_to_scan;
31640
31641 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31642 index 893a650..6190d3b 100644
31643 --- a/drivers/gpu/drm/via/via_drv.h
31644 +++ b/drivers/gpu/drm/via/via_drv.h
31645 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31646 typedef uint32_t maskarray_t[5];
31647
31648 typedef struct drm_via_irq {
31649 - atomic_t irq_received;
31650 + atomic_unchecked_t irq_received;
31651 uint32_t pending_mask;
31652 uint32_t enable_mask;
31653 wait_queue_head_t irq_queue;
31654 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31655 struct timeval last_vblank;
31656 int last_vblank_valid;
31657 unsigned usec_per_vblank;
31658 - atomic_t vbl_received;
31659 + atomic_unchecked_t vbl_received;
31660 drm_via_state_t hc_state;
31661 char pci_buf[VIA_PCI_BUF_SIZE];
31662 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31663 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31664 index ac98964..5dbf512 100644
31665 --- a/drivers/gpu/drm/via/via_irq.c
31666 +++ b/drivers/gpu/drm/via/via_irq.c
31667 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31668 if (crtc != 0)
31669 return 0;
31670
31671 - return atomic_read(&dev_priv->vbl_received);
31672 + return atomic_read_unchecked(&dev_priv->vbl_received);
31673 }
31674
31675 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31676 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31677
31678 status = VIA_READ(VIA_REG_INTERRUPT);
31679 if (status & VIA_IRQ_VBLANK_PENDING) {
31680 - atomic_inc(&dev_priv->vbl_received);
31681 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31682 + atomic_inc_unchecked(&dev_priv->vbl_received);
31683 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31684 do_gettimeofday(&cur_vblank);
31685 if (dev_priv->last_vblank_valid) {
31686 dev_priv->usec_per_vblank =
31687 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31688 dev_priv->last_vblank = cur_vblank;
31689 dev_priv->last_vblank_valid = 1;
31690 }
31691 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31692 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31693 DRM_DEBUG("US per vblank is: %u\n",
31694 dev_priv->usec_per_vblank);
31695 }
31696 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31697
31698 for (i = 0; i < dev_priv->num_irqs; ++i) {
31699 if (status & cur_irq->pending_mask) {
31700 - atomic_inc(&cur_irq->irq_received);
31701 + atomic_inc_unchecked(&cur_irq->irq_received);
31702 DRM_WAKEUP(&cur_irq->irq_queue);
31703 handled = 1;
31704 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31705 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31706 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31707 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31708 masks[irq][4]));
31709 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31710 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31711 } else {
31712 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31713 (((cur_irq_sequence =
31714 - atomic_read(&cur_irq->irq_received)) -
31715 + atomic_read_unchecked(&cur_irq->irq_received)) -
31716 *sequence) <= (1 << 23)));
31717 }
31718 *sequence = cur_irq_sequence;
31719 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31720 }
31721
31722 for (i = 0; i < dev_priv->num_irqs; ++i) {
31723 - atomic_set(&cur_irq->irq_received, 0);
31724 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31725 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31726 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31727 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31728 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31729 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31730 case VIA_IRQ_RELATIVE:
31731 irqwait->request.sequence +=
31732 - atomic_read(&cur_irq->irq_received);
31733 + atomic_read_unchecked(&cur_irq->irq_received);
31734 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31735 case VIA_IRQ_ABSOLUTE:
31736 break;
31737 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31738 index 88a179e..57fe50481c 100644
31739 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31740 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31741 @@ -263,7 +263,7 @@ struct vmw_private {
31742 * Fencing and IRQs.
31743 */
31744
31745 - atomic_t marker_seq;
31746 + atomic_unchecked_t marker_seq;
31747 wait_queue_head_t fence_queue;
31748 wait_queue_head_t fifo_queue;
31749 int fence_queue_waiters; /* Protected by hw_mutex */
31750 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31751 index 3eb1486..0a47ee9 100644
31752 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31753 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31754 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31755 (unsigned int) min,
31756 (unsigned int) fifo->capabilities);
31757
31758 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31759 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31760 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31761 vmw_marker_queue_init(&fifo->marker_queue);
31762 return vmw_fifo_send_fence(dev_priv, &dummy);
31763 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31764 if (reserveable)
31765 iowrite32(bytes, fifo_mem +
31766 SVGA_FIFO_RESERVED);
31767 - return fifo_mem + (next_cmd >> 2);
31768 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31769 } else {
31770 need_bounce = true;
31771 }
31772 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31773
31774 fm = vmw_fifo_reserve(dev_priv, bytes);
31775 if (unlikely(fm == NULL)) {
31776 - *seqno = atomic_read(&dev_priv->marker_seq);
31777 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31778 ret = -ENOMEM;
31779 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31780 false, 3*HZ);
31781 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31782 }
31783
31784 do {
31785 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31786 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31787 } while (*seqno == 0);
31788
31789 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31790 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31791 index 4640adb..e1384ed 100644
31792 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31793 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31794 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31795 * emitted. Then the fence is stale and signaled.
31796 */
31797
31798 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31799 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31800 > VMW_FENCE_WRAP);
31801
31802 return ret;
31803 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31804
31805 if (fifo_idle)
31806 down_read(&fifo_state->rwsem);
31807 - signal_seq = atomic_read(&dev_priv->marker_seq);
31808 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31809 ret = 0;
31810
31811 for (;;) {
31812 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31813 index 8a8725c..afed796 100644
31814 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31815 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31816 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31817 while (!vmw_lag_lt(queue, us)) {
31818 spin_lock(&queue->lock);
31819 if (list_empty(&queue->head))
31820 - seqno = atomic_read(&dev_priv->marker_seq);
31821 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31822 else {
31823 marker = list_first_entry(&queue->head,
31824 struct vmw_marker, head);
31825 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31826 index f4109fd..7c62889 100644
31827 --- a/drivers/hid/hid-core.c
31828 +++ b/drivers/hid/hid-core.c
31829 @@ -2200,7 +2200,7 @@ static bool hid_ignore(struct hid_device *hdev)
31830
31831 int hid_add_device(struct hid_device *hdev)
31832 {
31833 - static atomic_t id = ATOMIC_INIT(0);
31834 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31835 int ret;
31836
31837 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31838 @@ -2235,7 +2235,7 @@ int hid_add_device(struct hid_device *hdev)
31839 /* XXX hack, any other cleaner solution after the driver core
31840 * is converted to allow more than 20 bytes as the device name? */
31841 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31842 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31843 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31844
31845 hid_debug_register(hdev, dev_name(&hdev->dev));
31846 ret = device_add(&hdev->dev);
31847 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31848 index eec3291..8ed706b 100644
31849 --- a/drivers/hid/hid-wiimote-debug.c
31850 +++ b/drivers/hid/hid-wiimote-debug.c
31851 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31852 else if (size == 0)
31853 return -EIO;
31854
31855 - if (copy_to_user(u, buf, size))
31856 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31857 return -EFAULT;
31858
31859 *off += size;
31860 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31861 index 14599e2..711c965 100644
31862 --- a/drivers/hid/usbhid/hiddev.c
31863 +++ b/drivers/hid/usbhid/hiddev.c
31864 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31865 break;
31866
31867 case HIDIOCAPPLICATION:
31868 - if (arg < 0 || arg >= hid->maxapplication)
31869 + if (arg >= hid->maxapplication)
31870 break;
31871
31872 for (i = 0; i < hid->maxcollection; i++)
31873 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31874 index f4c3d28..82f45a9 100644
31875 --- a/drivers/hv/channel.c
31876 +++ b/drivers/hv/channel.c
31877 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31878 int ret = 0;
31879 int t;
31880
31881 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31882 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31883 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31884 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31885
31886 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31887 if (ret)
31888 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31889 index 3648f8f..30ef30d 100644
31890 --- a/drivers/hv/hv.c
31891 +++ b/drivers/hv/hv.c
31892 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31893 u64 output_address = (output) ? virt_to_phys(output) : 0;
31894 u32 output_address_hi = output_address >> 32;
31895 u32 output_address_lo = output_address & 0xFFFFFFFF;
31896 - void *hypercall_page = hv_context.hypercall_page;
31897 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31898
31899 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31900 "=a"(hv_status_lo) : "d" (control_hi),
31901 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31902 index d8d1fad..b91caf7 100644
31903 --- a/drivers/hv/hyperv_vmbus.h
31904 +++ b/drivers/hv/hyperv_vmbus.h
31905 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
31906 struct vmbus_connection {
31907 enum vmbus_connect_state conn_state;
31908
31909 - atomic_t next_gpadl_handle;
31910 + atomic_unchecked_t next_gpadl_handle;
31911
31912 /*
31913 * Represents channel interrupts. Each bit position represents a
31914 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31915 index 8e1a9ec..4687821 100644
31916 --- a/drivers/hv/vmbus_drv.c
31917 +++ b/drivers/hv/vmbus_drv.c
31918 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31919 {
31920 int ret = 0;
31921
31922 - static atomic_t device_num = ATOMIC_INIT(0);
31923 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31924
31925 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31926 - atomic_inc_return(&device_num));
31927 + atomic_inc_return_unchecked(&device_num));
31928
31929 child_device_obj->device.bus = &hv_bus;
31930 child_device_obj->device.parent = &hv_acpi_dev->dev;
31931 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31932 index 07a0c1a..0cac334 100644
31933 --- a/drivers/hwmon/sht15.c
31934 +++ b/drivers/hwmon/sht15.c
31935 @@ -169,7 +169,7 @@ struct sht15_data {
31936 int supply_uV;
31937 bool supply_uV_valid;
31938 struct work_struct update_supply_work;
31939 - atomic_t interrupt_handled;
31940 + atomic_unchecked_t interrupt_handled;
31941 };
31942
31943 /**
31944 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
31945 return ret;
31946
31947 gpio_direction_input(data->pdata->gpio_data);
31948 - atomic_set(&data->interrupt_handled, 0);
31949 + atomic_set_unchecked(&data->interrupt_handled, 0);
31950
31951 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31952 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31953 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31954 /* Only relevant if the interrupt hasn't occurred. */
31955 - if (!atomic_read(&data->interrupt_handled))
31956 + if (!atomic_read_unchecked(&data->interrupt_handled))
31957 schedule_work(&data->read_work);
31958 }
31959 ret = wait_event_timeout(data->wait_queue,
31960 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31961
31962 /* First disable the interrupt */
31963 disable_irq_nosync(irq);
31964 - atomic_inc(&data->interrupt_handled);
31965 + atomic_inc_unchecked(&data->interrupt_handled);
31966 /* Then schedule a reading work struct */
31967 if (data->state != SHT15_READING_NOTHING)
31968 schedule_work(&data->read_work);
31969 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31970 * If not, then start the interrupt again - care here as could
31971 * have gone low in meantime so verify it hasn't!
31972 */
31973 - atomic_set(&data->interrupt_handled, 0);
31974 + atomic_set_unchecked(&data->interrupt_handled, 0);
31975 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31976 /* If still not occurred or another handler was scheduled */
31977 if (gpio_get_value(data->pdata->gpio_data)
31978 - || atomic_read(&data->interrupt_handled))
31979 + || atomic_read_unchecked(&data->interrupt_handled))
31980 return;
31981 }
31982
31983 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31984 index 378fcb5..5e91fa8 100644
31985 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31986 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31987 @@ -43,7 +43,7 @@
31988 extern struct i2c_adapter amd756_smbus;
31989
31990 static struct i2c_adapter *s4882_adapter;
31991 -static struct i2c_algorithm *s4882_algo;
31992 +static i2c_algorithm_no_const *s4882_algo;
31993
31994 /* Wrapper access functions for multiplexed SMBus */
31995 static DEFINE_MUTEX(amd756_lock);
31996 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31997 index 29015eb..af2d8e9 100644
31998 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31999 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
32000 @@ -41,7 +41,7 @@
32001 extern struct i2c_adapter *nforce2_smbus;
32002
32003 static struct i2c_adapter *s4985_adapter;
32004 -static struct i2c_algorithm *s4985_algo;
32005 +static i2c_algorithm_no_const *s4985_algo;
32006
32007 /* Wrapper access functions for multiplexed SMBus */
32008 static DEFINE_MUTEX(nforce2_lock);
32009 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
32010 index d94e0ce..7055125 100644
32011 --- a/drivers/i2c/i2c-mux.c
32012 +++ b/drivers/i2c/i2c-mux.c
32013 @@ -30,7 +30,7 @@
32014 /* multiplexer per channel data */
32015 struct i2c_mux_priv {
32016 struct i2c_adapter adap;
32017 - struct i2c_algorithm algo;
32018 + i2c_algorithm_no_const algo;
32019
32020 struct i2c_adapter *parent;
32021 void *mux_priv; /* the mux chip/device */
32022 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32023 index 8126824..55a2798 100644
32024 --- a/drivers/ide/ide-cd.c
32025 +++ b/drivers/ide/ide-cd.c
32026 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32027 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32028 if ((unsigned long)buf & alignment
32029 || blk_rq_bytes(rq) & q->dma_pad_mask
32030 - || object_is_on_stack(buf))
32031 + || object_starts_on_stack(buf))
32032 drive->dma = 0;
32033 }
32034 }
32035 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32036 index 394fea2..c833880 100644
32037 --- a/drivers/infiniband/core/cm.c
32038 +++ b/drivers/infiniband/core/cm.c
32039 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32040
32041 struct cm_counter_group {
32042 struct kobject obj;
32043 - atomic_long_t counter[CM_ATTR_COUNT];
32044 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32045 };
32046
32047 struct cm_counter_attribute {
32048 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32049 struct ib_mad_send_buf *msg = NULL;
32050 int ret;
32051
32052 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32053 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32054 counter[CM_REQ_COUNTER]);
32055
32056 /* Quick state check to discard duplicate REQs. */
32057 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32058 if (!cm_id_priv)
32059 return;
32060
32061 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32062 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32063 counter[CM_REP_COUNTER]);
32064 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32065 if (ret)
32066 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32067 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32068 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32069 spin_unlock_irq(&cm_id_priv->lock);
32070 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32071 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32072 counter[CM_RTU_COUNTER]);
32073 goto out;
32074 }
32075 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32076 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32077 dreq_msg->local_comm_id);
32078 if (!cm_id_priv) {
32079 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32080 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32081 counter[CM_DREQ_COUNTER]);
32082 cm_issue_drep(work->port, work->mad_recv_wc);
32083 return -EINVAL;
32084 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32085 case IB_CM_MRA_REP_RCVD:
32086 break;
32087 case IB_CM_TIMEWAIT:
32088 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32089 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32090 counter[CM_DREQ_COUNTER]);
32091 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32092 goto unlock;
32093 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32094 cm_free_msg(msg);
32095 goto deref;
32096 case IB_CM_DREQ_RCVD:
32097 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32098 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32099 counter[CM_DREQ_COUNTER]);
32100 goto unlock;
32101 default:
32102 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32103 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32104 cm_id_priv->msg, timeout)) {
32105 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32106 - atomic_long_inc(&work->port->
32107 + atomic_long_inc_unchecked(&work->port->
32108 counter_group[CM_RECV_DUPLICATES].
32109 counter[CM_MRA_COUNTER]);
32110 goto out;
32111 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32112 break;
32113 case IB_CM_MRA_REQ_RCVD:
32114 case IB_CM_MRA_REP_RCVD:
32115 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32116 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32117 counter[CM_MRA_COUNTER]);
32118 /* fall through */
32119 default:
32120 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32121 case IB_CM_LAP_IDLE:
32122 break;
32123 case IB_CM_MRA_LAP_SENT:
32124 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32125 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32126 counter[CM_LAP_COUNTER]);
32127 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32128 goto unlock;
32129 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32130 cm_free_msg(msg);
32131 goto deref;
32132 case IB_CM_LAP_RCVD:
32133 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32134 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32135 counter[CM_LAP_COUNTER]);
32136 goto unlock;
32137 default:
32138 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32139 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32140 if (cur_cm_id_priv) {
32141 spin_unlock_irq(&cm.lock);
32142 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32143 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32144 counter[CM_SIDR_REQ_COUNTER]);
32145 goto out; /* Duplicate message. */
32146 }
32147 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32148 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32149 msg->retries = 1;
32150
32151 - atomic_long_add(1 + msg->retries,
32152 + atomic_long_add_unchecked(1 + msg->retries,
32153 &port->counter_group[CM_XMIT].counter[attr_index]);
32154 if (msg->retries)
32155 - atomic_long_add(msg->retries,
32156 + atomic_long_add_unchecked(msg->retries,
32157 &port->counter_group[CM_XMIT_RETRIES].
32158 counter[attr_index]);
32159
32160 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32161 }
32162
32163 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32164 - atomic_long_inc(&port->counter_group[CM_RECV].
32165 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32166 counter[attr_id - CM_ATTR_ID_OFFSET]);
32167
32168 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32169 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32170 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32171
32172 return sprintf(buf, "%ld\n",
32173 - atomic_long_read(&group->counter[cm_attr->index]));
32174 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32175 }
32176
32177 static const struct sysfs_ops cm_counter_ops = {
32178 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32179 index 176c8f9..2627b62 100644
32180 --- a/drivers/infiniband/core/fmr_pool.c
32181 +++ b/drivers/infiniband/core/fmr_pool.c
32182 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32183
32184 struct task_struct *thread;
32185
32186 - atomic_t req_ser;
32187 - atomic_t flush_ser;
32188 + atomic_unchecked_t req_ser;
32189 + atomic_unchecked_t flush_ser;
32190
32191 wait_queue_head_t force_wait;
32192 };
32193 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32194 struct ib_fmr_pool *pool = pool_ptr;
32195
32196 do {
32197 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32198 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32199 ib_fmr_batch_release(pool);
32200
32201 - atomic_inc(&pool->flush_ser);
32202 + atomic_inc_unchecked(&pool->flush_ser);
32203 wake_up_interruptible(&pool->force_wait);
32204
32205 if (pool->flush_function)
32206 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32207 }
32208
32209 set_current_state(TASK_INTERRUPTIBLE);
32210 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32211 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32212 !kthread_should_stop())
32213 schedule();
32214 __set_current_state(TASK_RUNNING);
32215 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32216 pool->dirty_watermark = params->dirty_watermark;
32217 pool->dirty_len = 0;
32218 spin_lock_init(&pool->pool_lock);
32219 - atomic_set(&pool->req_ser, 0);
32220 - atomic_set(&pool->flush_ser, 0);
32221 + atomic_set_unchecked(&pool->req_ser, 0);
32222 + atomic_set_unchecked(&pool->flush_ser, 0);
32223 init_waitqueue_head(&pool->force_wait);
32224
32225 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32226 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32227 }
32228 spin_unlock_irq(&pool->pool_lock);
32229
32230 - serial = atomic_inc_return(&pool->req_ser);
32231 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32232 wake_up_process(pool->thread);
32233
32234 if (wait_event_interruptible(pool->force_wait,
32235 - atomic_read(&pool->flush_ser) - serial >= 0))
32236 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32237 return -EINTR;
32238
32239 return 0;
32240 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32241 } else {
32242 list_add_tail(&fmr->list, &pool->dirty_list);
32243 if (++pool->dirty_len >= pool->dirty_watermark) {
32244 - atomic_inc(&pool->req_ser);
32245 + atomic_inc_unchecked(&pool->req_ser);
32246 wake_up_process(pool->thread);
32247 }
32248 }
32249 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32250 index afd8179..598063f 100644
32251 --- a/drivers/infiniband/hw/cxgb4/mem.c
32252 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32253 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32254 int err;
32255 struct fw_ri_tpte tpt;
32256 u32 stag_idx;
32257 - static atomic_t key;
32258 + static atomic_unchecked_t key;
32259
32260 if (c4iw_fatal_error(rdev))
32261 return -EIO;
32262 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32263 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32264 rdev->stats.stag.max = rdev->stats.stag.cur;
32265 mutex_unlock(&rdev->stats.lock);
32266 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32267 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32268 }
32269 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32270 __func__, stag_state, type, pdid, stag_idx);
32271 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32272 index 79b3dbc..96e5fcc 100644
32273 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32274 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32275 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32276 struct ib_atomic_eth *ateth;
32277 struct ipath_ack_entry *e;
32278 u64 vaddr;
32279 - atomic64_t *maddr;
32280 + atomic64_unchecked_t *maddr;
32281 u64 sdata;
32282 u32 rkey;
32283 u8 next;
32284 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32285 IB_ACCESS_REMOTE_ATOMIC)))
32286 goto nack_acc_unlck;
32287 /* Perform atomic OP and save result. */
32288 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32289 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32290 sdata = be64_to_cpu(ateth->swap_data);
32291 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32292 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32293 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32294 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32295 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32296 be64_to_cpu(ateth->compare_data),
32297 sdata);
32298 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32299 index 1f95bba..9530f87 100644
32300 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32301 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32302 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32303 unsigned long flags;
32304 struct ib_wc wc;
32305 u64 sdata;
32306 - atomic64_t *maddr;
32307 + atomic64_unchecked_t *maddr;
32308 enum ib_wc_status send_status;
32309
32310 /*
32311 @@ -382,11 +382,11 @@ again:
32312 IB_ACCESS_REMOTE_ATOMIC)))
32313 goto acc_err;
32314 /* Perform atomic OP and save result. */
32315 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32316 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32317 sdata = wqe->wr.wr.atomic.compare_add;
32318 *(u64 *) sqp->s_sge.sge.vaddr =
32319 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32320 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32321 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32322 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32323 sdata, wqe->wr.wr.atomic.swap);
32324 goto send_comp;
32325 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32326 index 748db2d..5f75cc3 100644
32327 --- a/drivers/infiniband/hw/nes/nes.c
32328 +++ b/drivers/infiniband/hw/nes/nes.c
32329 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32330 LIST_HEAD(nes_adapter_list);
32331 static LIST_HEAD(nes_dev_list);
32332
32333 -atomic_t qps_destroyed;
32334 +atomic_unchecked_t qps_destroyed;
32335
32336 static unsigned int ee_flsh_adapter;
32337 static unsigned int sysfs_nonidx_addr;
32338 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32339 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32340 struct nes_adapter *nesadapter = nesdev->nesadapter;
32341
32342 - atomic_inc(&qps_destroyed);
32343 + atomic_inc_unchecked(&qps_destroyed);
32344
32345 /* Free the control structures */
32346
32347 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32348 index 5cac29e..c471744 100644
32349 --- a/drivers/infiniband/hw/nes/nes.h
32350 +++ b/drivers/infiniband/hw/nes/nes.h
32351 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
32352 extern unsigned int wqm_quanta;
32353 extern struct list_head nes_adapter_list;
32354
32355 -extern atomic_t cm_connects;
32356 -extern atomic_t cm_accepts;
32357 -extern atomic_t cm_disconnects;
32358 -extern atomic_t cm_closes;
32359 -extern atomic_t cm_connecteds;
32360 -extern atomic_t cm_connect_reqs;
32361 -extern atomic_t cm_rejects;
32362 -extern atomic_t mod_qp_timouts;
32363 -extern atomic_t qps_created;
32364 -extern atomic_t qps_destroyed;
32365 -extern atomic_t sw_qps_destroyed;
32366 +extern atomic_unchecked_t cm_connects;
32367 +extern atomic_unchecked_t cm_accepts;
32368 +extern atomic_unchecked_t cm_disconnects;
32369 +extern atomic_unchecked_t cm_closes;
32370 +extern atomic_unchecked_t cm_connecteds;
32371 +extern atomic_unchecked_t cm_connect_reqs;
32372 +extern atomic_unchecked_t cm_rejects;
32373 +extern atomic_unchecked_t mod_qp_timouts;
32374 +extern atomic_unchecked_t qps_created;
32375 +extern atomic_unchecked_t qps_destroyed;
32376 +extern atomic_unchecked_t sw_qps_destroyed;
32377 extern u32 mh_detected;
32378 extern u32 mh_pauses_sent;
32379 extern u32 cm_packets_sent;
32380 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
32381 extern u32 cm_packets_received;
32382 extern u32 cm_packets_dropped;
32383 extern u32 cm_packets_retrans;
32384 -extern atomic_t cm_listens_created;
32385 -extern atomic_t cm_listens_destroyed;
32386 +extern atomic_unchecked_t cm_listens_created;
32387 +extern atomic_unchecked_t cm_listens_destroyed;
32388 extern u32 cm_backlog_drops;
32389 -extern atomic_t cm_loopbacks;
32390 -extern atomic_t cm_nodes_created;
32391 -extern atomic_t cm_nodes_destroyed;
32392 -extern atomic_t cm_accel_dropped_pkts;
32393 -extern atomic_t cm_resets_recvd;
32394 -extern atomic_t pau_qps_created;
32395 -extern atomic_t pau_qps_destroyed;
32396 +extern atomic_unchecked_t cm_loopbacks;
32397 +extern atomic_unchecked_t cm_nodes_created;
32398 +extern atomic_unchecked_t cm_nodes_destroyed;
32399 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32400 +extern atomic_unchecked_t cm_resets_recvd;
32401 +extern atomic_unchecked_t pau_qps_created;
32402 +extern atomic_unchecked_t pau_qps_destroyed;
32403
32404 extern u32 int_mod_timer_init;
32405 extern u32 int_mod_cq_depth_256;
32406 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32407 index cfaacaf..fa0722e 100644
32408 --- a/drivers/infiniband/hw/nes/nes_cm.c
32409 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32410 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32411 u32 cm_packets_retrans;
32412 u32 cm_packets_created;
32413 u32 cm_packets_received;
32414 -atomic_t cm_listens_created;
32415 -atomic_t cm_listens_destroyed;
32416 +atomic_unchecked_t cm_listens_created;
32417 +atomic_unchecked_t cm_listens_destroyed;
32418 u32 cm_backlog_drops;
32419 -atomic_t cm_loopbacks;
32420 -atomic_t cm_nodes_created;
32421 -atomic_t cm_nodes_destroyed;
32422 -atomic_t cm_accel_dropped_pkts;
32423 -atomic_t cm_resets_recvd;
32424 +atomic_unchecked_t cm_loopbacks;
32425 +atomic_unchecked_t cm_nodes_created;
32426 +atomic_unchecked_t cm_nodes_destroyed;
32427 +atomic_unchecked_t cm_accel_dropped_pkts;
32428 +atomic_unchecked_t cm_resets_recvd;
32429
32430 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32431 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32432 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32433
32434 static struct nes_cm_core *g_cm_core;
32435
32436 -atomic_t cm_connects;
32437 -atomic_t cm_accepts;
32438 -atomic_t cm_disconnects;
32439 -atomic_t cm_closes;
32440 -atomic_t cm_connecteds;
32441 -atomic_t cm_connect_reqs;
32442 -atomic_t cm_rejects;
32443 +atomic_unchecked_t cm_connects;
32444 +atomic_unchecked_t cm_accepts;
32445 +atomic_unchecked_t cm_disconnects;
32446 +atomic_unchecked_t cm_closes;
32447 +atomic_unchecked_t cm_connecteds;
32448 +atomic_unchecked_t cm_connect_reqs;
32449 +atomic_unchecked_t cm_rejects;
32450
32451 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32452 {
32453 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32454 kfree(listener);
32455 listener = NULL;
32456 ret = 0;
32457 - atomic_inc(&cm_listens_destroyed);
32458 + atomic_inc_unchecked(&cm_listens_destroyed);
32459 } else {
32460 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32461 }
32462 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32463 cm_node->rem_mac);
32464
32465 add_hte_node(cm_core, cm_node);
32466 - atomic_inc(&cm_nodes_created);
32467 + atomic_inc_unchecked(&cm_nodes_created);
32468
32469 return cm_node;
32470 }
32471 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32472 }
32473
32474 atomic_dec(&cm_core->node_cnt);
32475 - atomic_inc(&cm_nodes_destroyed);
32476 + atomic_inc_unchecked(&cm_nodes_destroyed);
32477 nesqp = cm_node->nesqp;
32478 if (nesqp) {
32479 nesqp->cm_node = NULL;
32480 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32481
32482 static void drop_packet(struct sk_buff *skb)
32483 {
32484 - atomic_inc(&cm_accel_dropped_pkts);
32485 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32486 dev_kfree_skb_any(skb);
32487 }
32488
32489 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32490 {
32491
32492 int reset = 0; /* whether to send reset in case of err.. */
32493 - atomic_inc(&cm_resets_recvd);
32494 + atomic_inc_unchecked(&cm_resets_recvd);
32495 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32496 " refcnt=%d\n", cm_node, cm_node->state,
32497 atomic_read(&cm_node->ref_count));
32498 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32499 rem_ref_cm_node(cm_node->cm_core, cm_node);
32500 return NULL;
32501 }
32502 - atomic_inc(&cm_loopbacks);
32503 + atomic_inc_unchecked(&cm_loopbacks);
32504 loopbackremotenode->loopbackpartner = cm_node;
32505 loopbackremotenode->tcp_cntxt.rcv_wscale =
32506 NES_CM_DEFAULT_RCV_WND_SCALE;
32507 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32508 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32509 else {
32510 rem_ref_cm_node(cm_core, cm_node);
32511 - atomic_inc(&cm_accel_dropped_pkts);
32512 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32513 dev_kfree_skb_any(skb);
32514 }
32515 break;
32516 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32517
32518 if ((cm_id) && (cm_id->event_handler)) {
32519 if (issue_disconn) {
32520 - atomic_inc(&cm_disconnects);
32521 + atomic_inc_unchecked(&cm_disconnects);
32522 cm_event.event = IW_CM_EVENT_DISCONNECT;
32523 cm_event.status = disconn_status;
32524 cm_event.local_addr = cm_id->local_addr;
32525 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32526 }
32527
32528 if (issue_close) {
32529 - atomic_inc(&cm_closes);
32530 + atomic_inc_unchecked(&cm_closes);
32531 nes_disconnect(nesqp, 1);
32532
32533 cm_id->provider_data = nesqp;
32534 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32535
32536 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32537 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32538 - atomic_inc(&cm_accepts);
32539 + atomic_inc_unchecked(&cm_accepts);
32540
32541 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32542 netdev_refcnt_read(nesvnic->netdev));
32543 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32544 struct nes_cm_core *cm_core;
32545 u8 *start_buff;
32546
32547 - atomic_inc(&cm_rejects);
32548 + atomic_inc_unchecked(&cm_rejects);
32549 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32550 loopback = cm_node->loopbackpartner;
32551 cm_core = cm_node->cm_core;
32552 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32553 ntohl(cm_id->local_addr.sin_addr.s_addr),
32554 ntohs(cm_id->local_addr.sin_port));
32555
32556 - atomic_inc(&cm_connects);
32557 + atomic_inc_unchecked(&cm_connects);
32558 nesqp->active_conn = 1;
32559
32560 /* cache the cm_id in the qp */
32561 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32562 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32563 return err;
32564 }
32565 - atomic_inc(&cm_listens_created);
32566 + atomic_inc_unchecked(&cm_listens_created);
32567 }
32568
32569 cm_id->add_ref(cm_id);
32570 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32571
32572 if (nesqp->destroyed)
32573 return;
32574 - atomic_inc(&cm_connecteds);
32575 + atomic_inc_unchecked(&cm_connecteds);
32576 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32577 " local port 0x%04X. jiffies = %lu.\n",
32578 nesqp->hwqp.qp_id,
32579 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32580
32581 cm_id->add_ref(cm_id);
32582 ret = cm_id->event_handler(cm_id, &cm_event);
32583 - atomic_inc(&cm_closes);
32584 + atomic_inc_unchecked(&cm_closes);
32585 cm_event.event = IW_CM_EVENT_CLOSE;
32586 cm_event.status = 0;
32587 cm_event.provider_data = cm_id->provider_data;
32588 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32589 return;
32590 cm_id = cm_node->cm_id;
32591
32592 - atomic_inc(&cm_connect_reqs);
32593 + atomic_inc_unchecked(&cm_connect_reqs);
32594 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32595 cm_node, cm_id, jiffies);
32596
32597 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32598 return;
32599 cm_id = cm_node->cm_id;
32600
32601 - atomic_inc(&cm_connect_reqs);
32602 + atomic_inc_unchecked(&cm_connect_reqs);
32603 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32604 cm_node, cm_id, jiffies);
32605
32606 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32607 index 3ba7be3..c81f6ff 100644
32608 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32609 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32610 @@ -40,8 +40,8 @@
32611 #include "nes.h"
32612 #include "nes_mgt.h"
32613
32614 -atomic_t pau_qps_created;
32615 -atomic_t pau_qps_destroyed;
32616 +atomic_unchecked_t pau_qps_created;
32617 +atomic_unchecked_t pau_qps_destroyed;
32618
32619 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32620 {
32621 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32622 {
32623 struct sk_buff *skb;
32624 unsigned long flags;
32625 - atomic_inc(&pau_qps_destroyed);
32626 + atomic_inc_unchecked(&pau_qps_destroyed);
32627
32628 /* Free packets that have not yet been forwarded */
32629 /* Lock is acquired by skb_dequeue when removing the skb */
32630 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32631 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32632 skb_queue_head_init(&nesqp->pau_list);
32633 spin_lock_init(&nesqp->pau_lock);
32634 - atomic_inc(&pau_qps_created);
32635 + atomic_inc_unchecked(&pau_qps_created);
32636 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32637 }
32638
32639 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32640 index 0564be7..f68b0f1 100644
32641 --- a/drivers/infiniband/hw/nes/nes_nic.c
32642 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32643 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32644 target_stat_values[++index] = mh_detected;
32645 target_stat_values[++index] = mh_pauses_sent;
32646 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32647 - target_stat_values[++index] = atomic_read(&cm_connects);
32648 - target_stat_values[++index] = atomic_read(&cm_accepts);
32649 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32650 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32651 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32652 - target_stat_values[++index] = atomic_read(&cm_rejects);
32653 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32654 - target_stat_values[++index] = atomic_read(&qps_created);
32655 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32656 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32657 - target_stat_values[++index] = atomic_read(&cm_closes);
32658 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32659 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32660 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32661 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32662 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32663 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32664 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32665 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32666 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32667 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32668 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32669 target_stat_values[++index] = cm_packets_sent;
32670 target_stat_values[++index] = cm_packets_bounced;
32671 target_stat_values[++index] = cm_packets_created;
32672 target_stat_values[++index] = cm_packets_received;
32673 target_stat_values[++index] = cm_packets_dropped;
32674 target_stat_values[++index] = cm_packets_retrans;
32675 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32676 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32677 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32678 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32679 target_stat_values[++index] = cm_backlog_drops;
32680 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32681 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32682 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32683 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32684 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32685 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32686 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32687 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32688 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32689 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32690 target_stat_values[++index] = nesadapter->free_4kpbl;
32691 target_stat_values[++index] = nesadapter->free_256pbl;
32692 target_stat_values[++index] = int_mod_timer_init;
32693 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32694 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32695 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32696 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32697 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32698 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32699 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32700 }
32701
32702 /**
32703 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32704 index cd0ecb2..7099ff0 100644
32705 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32706 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32707 @@ -46,9 +46,9 @@
32708
32709 #include <rdma/ib_umem.h>
32710
32711 -atomic_t mod_qp_timouts;
32712 -atomic_t qps_created;
32713 -atomic_t sw_qps_destroyed;
32714 +atomic_unchecked_t mod_qp_timouts;
32715 +atomic_unchecked_t qps_created;
32716 +atomic_unchecked_t sw_qps_destroyed;
32717
32718 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32719
32720 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32721 if (init_attr->create_flags)
32722 return ERR_PTR(-EINVAL);
32723
32724 - atomic_inc(&qps_created);
32725 + atomic_inc_unchecked(&qps_created);
32726 switch (init_attr->qp_type) {
32727 case IB_QPT_RC:
32728 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32729 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32730 struct iw_cm_event cm_event;
32731 int ret = 0;
32732
32733 - atomic_inc(&sw_qps_destroyed);
32734 + atomic_inc_unchecked(&sw_qps_destroyed);
32735 nesqp->destroyed = 1;
32736
32737 /* Blow away the connection if it exists. */
32738 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32739 index 4d11575..3e890e5 100644
32740 --- a/drivers/infiniband/hw/qib/qib.h
32741 +++ b/drivers/infiniband/hw/qib/qib.h
32742 @@ -51,6 +51,7 @@
32743 #include <linux/completion.h>
32744 #include <linux/kref.h>
32745 #include <linux/sched.h>
32746 +#include <linux/slab.h>
32747
32748 #include "qib_common.h"
32749 #include "qib_verbs.h"
32750 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32751 index da739d9..da1c7f4 100644
32752 --- a/drivers/input/gameport/gameport.c
32753 +++ b/drivers/input/gameport/gameport.c
32754 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32755 */
32756 static void gameport_init_port(struct gameport *gameport)
32757 {
32758 - static atomic_t gameport_no = ATOMIC_INIT(0);
32759 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32760
32761 __module_get(THIS_MODULE);
32762
32763 mutex_init(&gameport->drv_mutex);
32764 device_initialize(&gameport->dev);
32765 dev_set_name(&gameport->dev, "gameport%lu",
32766 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32767 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32768 gameport->dev.bus = &gameport_bus;
32769 gameport->dev.release = gameport_release_port;
32770 if (gameport->parent)
32771 diff --git a/drivers/input/input.c b/drivers/input/input.c
32772 index 53a0dde..abffda7 100644
32773 --- a/drivers/input/input.c
32774 +++ b/drivers/input/input.c
32775 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32776 */
32777 int input_register_device(struct input_dev *dev)
32778 {
32779 - static atomic_t input_no = ATOMIC_INIT(0);
32780 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32781 struct input_handler *handler;
32782 unsigned int packet_size;
32783 const char *path;
32784 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
32785 dev->setkeycode = input_default_setkeycode;
32786
32787 dev_set_name(&dev->dev, "input%ld",
32788 - (unsigned long) atomic_inc_return(&input_no) - 1);
32789 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32790
32791 error = device_add(&dev->dev);
32792 if (error)
32793 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32794 index 04c69af..5f92d00 100644
32795 --- a/drivers/input/joystick/sidewinder.c
32796 +++ b/drivers/input/joystick/sidewinder.c
32797 @@ -30,6 +30,7 @@
32798 #include <linux/kernel.h>
32799 #include <linux/module.h>
32800 #include <linux/slab.h>
32801 +#include <linux/sched.h>
32802 #include <linux/init.h>
32803 #include <linux/input.h>
32804 #include <linux/gameport.h>
32805 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32806 index 83811e4..0822b90 100644
32807 --- a/drivers/input/joystick/xpad.c
32808 +++ b/drivers/input/joystick/xpad.c
32809 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32810
32811 static int xpad_led_probe(struct usb_xpad *xpad)
32812 {
32813 - static atomic_t led_seq = ATOMIC_INIT(0);
32814 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32815 long led_no;
32816 struct xpad_led *led;
32817 struct led_classdev *led_cdev;
32818 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32819 if (!led)
32820 return -ENOMEM;
32821
32822 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32823 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32824
32825 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32826 led->xpad = xpad;
32827 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32828 index 4c842c3..590b0bf 100644
32829 --- a/drivers/input/mousedev.c
32830 +++ b/drivers/input/mousedev.c
32831 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32832
32833 spin_unlock_irq(&client->packet_lock);
32834
32835 - if (copy_to_user(buffer, data, count))
32836 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32837 return -EFAULT;
32838
32839 return count;
32840 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32841 index d0f7533..fb8215b 100644
32842 --- a/drivers/input/serio/serio.c
32843 +++ b/drivers/input/serio/serio.c
32844 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32845 */
32846 static void serio_init_port(struct serio *serio)
32847 {
32848 - static atomic_t serio_no = ATOMIC_INIT(0);
32849 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32850
32851 __module_get(THIS_MODULE);
32852
32853 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32854 mutex_init(&serio->drv_mutex);
32855 device_initialize(&serio->dev);
32856 dev_set_name(&serio->dev, "serio%ld",
32857 - (long)atomic_inc_return(&serio_no) - 1);
32858 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32859 serio->dev.bus = &serio_bus;
32860 serio->dev.release = serio_release_port;
32861 serio->dev.groups = serio_device_attr_groups;
32862 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32863 index c679867..6e2e34d 100644
32864 --- a/drivers/isdn/capi/capi.c
32865 +++ b/drivers/isdn/capi/capi.c
32866 @@ -83,8 +83,8 @@ struct capiminor {
32867
32868 struct capi20_appl *ap;
32869 u32 ncci;
32870 - atomic_t datahandle;
32871 - atomic_t msgid;
32872 + atomic_unchecked_t datahandle;
32873 + atomic_unchecked_t msgid;
32874
32875 struct tty_port port;
32876 int ttyinstop;
32877 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32878 capimsg_setu16(s, 2, mp->ap->applid);
32879 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32880 capimsg_setu8 (s, 5, CAPI_RESP);
32881 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32882 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32883 capimsg_setu32(s, 8, mp->ncci);
32884 capimsg_setu16(s, 12, datahandle);
32885 }
32886 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
32887 mp->outbytes -= len;
32888 spin_unlock_bh(&mp->outlock);
32889
32890 - datahandle = atomic_inc_return(&mp->datahandle);
32891 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32892 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32893 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32894 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32895 capimsg_setu16(skb->data, 2, mp->ap->applid);
32896 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32897 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32898 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32899 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32900 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32901 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32902 capimsg_setu16(skb->data, 16, len); /* Data length */
32903 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32904 index 67abf3f..076b3a6 100644
32905 --- a/drivers/isdn/gigaset/interface.c
32906 +++ b/drivers/isdn/gigaset/interface.c
32907 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32908 }
32909 tty->driver_data = cs;
32910
32911 - ++cs->port.count;
32912 + atomic_inc(&cs->port.count);
32913
32914 - if (cs->port.count == 1) {
32915 + if (atomic_read(&cs->port.count) == 1) {
32916 tty_port_tty_set(&cs->port, tty);
32917 tty->low_latency = 1;
32918 }
32919 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32920
32921 if (!cs->connected)
32922 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32923 - else if (!cs->port.count)
32924 + else if (!atomic_read(&cs->port.count))
32925 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32926 - else if (!--cs->port.count)
32927 + else if (!atomic_dec_return(&cs->port.count))
32928 tty_port_tty_set(&cs->port, NULL);
32929
32930 mutex_unlock(&cs->mutex);
32931 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32932 index 821f7ac..28d4030 100644
32933 --- a/drivers/isdn/hardware/avm/b1.c
32934 +++ b/drivers/isdn/hardware/avm/b1.c
32935 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32936 }
32937 if (left) {
32938 if (t4file->user) {
32939 - if (copy_from_user(buf, dp, left))
32940 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32941 return -EFAULT;
32942 } else {
32943 memcpy(buf, dp, left);
32944 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32945 }
32946 if (left) {
32947 if (config->user) {
32948 - if (copy_from_user(buf, dp, left))
32949 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32950 return -EFAULT;
32951 } else {
32952 memcpy(buf, dp, left);
32953 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32954 index dd6b53a..19d9ee6 100644
32955 --- a/drivers/isdn/hardware/eicon/divasync.h
32956 +++ b/drivers/isdn/hardware/eicon/divasync.h
32957 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32958 } diva_didd_add_adapter_t;
32959 typedef struct _diva_didd_remove_adapter {
32960 IDI_CALL p_request;
32961 -} diva_didd_remove_adapter_t;
32962 +} __no_const diva_didd_remove_adapter_t;
32963 typedef struct _diva_didd_read_adapter_array {
32964 void *buffer;
32965 dword length;
32966 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32967 index d303e65..28bcb7b 100644
32968 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32969 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32970 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32971 typedef struct _diva_os_idi_adapter_interface {
32972 diva_init_card_proc_t cleanup_adapter_proc;
32973 diva_cmd_card_proc_t cmd_proc;
32974 -} diva_os_idi_adapter_interface_t;
32975 +} __no_const diva_os_idi_adapter_interface_t;
32976
32977 typedef struct _diva_os_xdi_adapter {
32978 struct list_head link;
32979 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32980 index b817809..409caff 100644
32981 --- a/drivers/isdn/i4l/isdn_tty.c
32982 +++ b/drivers/isdn/i4l/isdn_tty.c
32983 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32984
32985 #ifdef ISDN_DEBUG_MODEM_OPEN
32986 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32987 - port->count);
32988 + atomic_read(&port->count));
32989 #endif
32990 - port->count++;
32991 + atomic_inc(&port->count);
32992 port->tty = tty;
32993 /*
32994 * Start up serial port
32995 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32996 #endif
32997 return;
32998 }
32999 - if ((tty->count == 1) && (port->count != 1)) {
33000 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33001 /*
33002 * Uh, oh. tty->count is 1, which means that the tty
33003 * structure will be freed. Info->count should always
33004 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33005 * serial port won't be shutdown.
33006 */
33007 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33008 - "info->count is %d\n", port->count);
33009 - port->count = 1;
33010 + "info->count is %d\n", atomic_read(&port->count));
33011 + atomic_set(&port->count, 1);
33012 }
33013 - if (--port->count < 0) {
33014 + if (atomic_dec_return(&port->count) < 0) {
33015 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33016 - info->line, port->count);
33017 - port->count = 0;
33018 + info->line, atomic_read(&port->count));
33019 + atomic_set(&port->count, 0);
33020 }
33021 - if (port->count) {
33022 + if (atomic_read(&port->count)) {
33023 #ifdef ISDN_DEBUG_MODEM_OPEN
33024 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33025 #endif
33026 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33027 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33028 return;
33029 isdn_tty_shutdown(info);
33030 - port->count = 0;
33031 + atomic_set(&port->count, 0);
33032 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33033 port->tty = NULL;
33034 wake_up_interruptible(&port->open_wait);
33035 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33036 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33037 modem_info *info = &dev->mdm.info[i];
33038
33039 - if (info->port.count == 0)
33040 + if (atomic_read(&info->port.count) == 0)
33041 continue;
33042 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33043 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33044 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33045 index e74df7c..03a03ba 100644
33046 --- a/drivers/isdn/icn/icn.c
33047 +++ b/drivers/isdn/icn/icn.c
33048 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33049 if (count > len)
33050 count = len;
33051 if (user) {
33052 - if (copy_from_user(msg, buf, count))
33053 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33054 return -EFAULT;
33055 } else
33056 memcpy(msg, buf, count);
33057 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33058 index b5fdcb7..5b6c59f 100644
33059 --- a/drivers/lguest/core.c
33060 +++ b/drivers/lguest/core.c
33061 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33062 * it's worked so far. The end address needs +1 because __get_vm_area
33063 * allocates an extra guard page, so we need space for that.
33064 */
33065 +
33066 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33067 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33068 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33069 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33070 +#else
33071 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33072 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33073 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33074 +#endif
33075 +
33076 if (!switcher_vma) {
33077 err = -ENOMEM;
33078 printk("lguest: could not map switcher pages high\n");
33079 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33080 * Now the Switcher is mapped at the right address, we can't fail!
33081 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33082 */
33083 - memcpy(switcher_vma->addr, start_switcher_text,
33084 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33085 end_switcher_text - start_switcher_text);
33086
33087 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33088 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33089 index 4af12e1..0e89afe 100644
33090 --- a/drivers/lguest/x86/core.c
33091 +++ b/drivers/lguest/x86/core.c
33092 @@ -59,7 +59,7 @@ static struct {
33093 /* Offset from where switcher.S was compiled to where we've copied it */
33094 static unsigned long switcher_offset(void)
33095 {
33096 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33097 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33098 }
33099
33100 /* This cpu's struct lguest_pages. */
33101 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33102 * These copies are pretty cheap, so we do them unconditionally: */
33103 /* Save the current Host top-level page directory.
33104 */
33105 +
33106 +#ifdef CONFIG_PAX_PER_CPU_PGD
33107 + pages->state.host_cr3 = read_cr3();
33108 +#else
33109 pages->state.host_cr3 = __pa(current->mm->pgd);
33110 +#endif
33111 +
33112 /*
33113 * Set up the Guest's page tables to see this CPU's pages (and no
33114 * other CPU's pages).
33115 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
33116 * compiled-in switcher code and the high-mapped copy we just made.
33117 */
33118 for (i = 0; i < IDT_ENTRIES; i++)
33119 - default_idt_entries[i] += switcher_offset();
33120 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33121
33122 /*
33123 * Set up the Switcher's per-cpu areas.
33124 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
33125 * it will be undisturbed when we switch. To change %cs and jump we
33126 * need this structure to feed to Intel's "lcall" instruction.
33127 */
33128 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33129 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33130 lguest_entry.segment = LGUEST_CS;
33131
33132 /*
33133 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33134 index 40634b0..4f5855e 100644
33135 --- a/drivers/lguest/x86/switcher_32.S
33136 +++ b/drivers/lguest/x86/switcher_32.S
33137 @@ -87,6 +87,7 @@
33138 #include <asm/page.h>
33139 #include <asm/segment.h>
33140 #include <asm/lguest.h>
33141 +#include <asm/processor-flags.h>
33142
33143 // We mark the start of the code to copy
33144 // It's placed in .text tho it's never run here
33145 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33146 // Changes type when we load it: damn Intel!
33147 // For after we switch over our page tables
33148 // That entry will be read-only: we'd crash.
33149 +
33150 +#ifdef CONFIG_PAX_KERNEXEC
33151 + mov %cr0, %edx
33152 + xor $X86_CR0_WP, %edx
33153 + mov %edx, %cr0
33154 +#endif
33155 +
33156 movl $(GDT_ENTRY_TSS*8), %edx
33157 ltr %dx
33158
33159 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33160 // Let's clear it again for our return.
33161 // The GDT descriptor of the Host
33162 // Points to the table after two "size" bytes
33163 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33164 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33165 // Clear "used" from type field (byte 5, bit 2)
33166 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33167 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33168 +
33169 +#ifdef CONFIG_PAX_KERNEXEC
33170 + mov %cr0, %eax
33171 + xor $X86_CR0_WP, %eax
33172 + mov %eax, %cr0
33173 +#endif
33174
33175 // Once our page table's switched, the Guest is live!
33176 // The Host fades as we run this final step.
33177 @@ -295,13 +309,12 @@ deliver_to_host:
33178 // I consulted gcc, and it gave
33179 // These instructions, which I gladly credit:
33180 leal (%edx,%ebx,8), %eax
33181 - movzwl (%eax),%edx
33182 - movl 4(%eax), %eax
33183 - xorw %ax, %ax
33184 - orl %eax, %edx
33185 + movl 4(%eax), %edx
33186 + movw (%eax), %dx
33187 // Now the address of the handler's in %edx
33188 // We call it now: its "iret" drops us home.
33189 - jmp *%edx
33190 + ljmp $__KERNEL_CS, $1f
33191 +1: jmp *%edx
33192
33193 // Every interrupt can come to us here
33194 // But we must truly tell each apart.
33195 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33196 index 7155945..4bcc562 100644
33197 --- a/drivers/md/bitmap.c
33198 +++ b/drivers/md/bitmap.c
33199 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33200 chunk_kb ? "KB" : "B");
33201 if (bitmap->storage.file) {
33202 seq_printf(seq, ", file: ");
33203 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33204 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33205 }
33206
33207 seq_printf(seq, "\n");
33208 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33209 index afd9598..528d8f9 100644
33210 --- a/drivers/md/dm-ioctl.c
33211 +++ b/drivers/md/dm-ioctl.c
33212 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33213 cmd == DM_LIST_VERSIONS_CMD)
33214 return 0;
33215
33216 - if ((cmd == DM_DEV_CREATE_CMD)) {
33217 + if (cmd == DM_DEV_CREATE_CMD) {
33218 if (!*param->name) {
33219 DMWARN("name not supplied when creating device");
33220 return -EINVAL;
33221 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33222 index fd61f98..8050783 100644
33223 --- a/drivers/md/dm-raid1.c
33224 +++ b/drivers/md/dm-raid1.c
33225 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33226
33227 struct mirror {
33228 struct mirror_set *ms;
33229 - atomic_t error_count;
33230 + atomic_unchecked_t error_count;
33231 unsigned long error_type;
33232 struct dm_dev *dev;
33233 sector_t offset;
33234 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33235 struct mirror *m;
33236
33237 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33238 - if (!atomic_read(&m->error_count))
33239 + if (!atomic_read_unchecked(&m->error_count))
33240 return m;
33241
33242 return NULL;
33243 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33244 * simple way to tell if a device has encountered
33245 * errors.
33246 */
33247 - atomic_inc(&m->error_count);
33248 + atomic_inc_unchecked(&m->error_count);
33249
33250 if (test_and_set_bit(error_type, &m->error_type))
33251 return;
33252 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33253 struct mirror *m = get_default_mirror(ms);
33254
33255 do {
33256 - if (likely(!atomic_read(&m->error_count)))
33257 + if (likely(!atomic_read_unchecked(&m->error_count)))
33258 return m;
33259
33260 if (m-- == ms->mirror)
33261 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33262 {
33263 struct mirror *default_mirror = get_default_mirror(m->ms);
33264
33265 - return !atomic_read(&default_mirror->error_count);
33266 + return !atomic_read_unchecked(&default_mirror->error_count);
33267 }
33268
33269 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33270 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33271 */
33272 if (likely(region_in_sync(ms, region, 1)))
33273 m = choose_mirror(ms, bio->bi_sector);
33274 - else if (m && atomic_read(&m->error_count))
33275 + else if (m && atomic_read_unchecked(&m->error_count))
33276 m = NULL;
33277
33278 if (likely(m))
33279 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33280 }
33281
33282 ms->mirror[mirror].ms = ms;
33283 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33284 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33285 ms->mirror[mirror].error_type = 0;
33286 ms->mirror[mirror].offset = offset;
33287
33288 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33289 */
33290 static char device_status_char(struct mirror *m)
33291 {
33292 - if (!atomic_read(&(m->error_count)))
33293 + if (!atomic_read_unchecked(&(m->error_count)))
33294 return 'A';
33295
33296 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33297 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33298 index e2f87653..f279abe 100644
33299 --- a/drivers/md/dm-stripe.c
33300 +++ b/drivers/md/dm-stripe.c
33301 @@ -20,7 +20,7 @@ struct stripe {
33302 struct dm_dev *dev;
33303 sector_t physical_start;
33304
33305 - atomic_t error_count;
33306 + atomic_unchecked_t error_count;
33307 };
33308
33309 struct stripe_c {
33310 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33311 kfree(sc);
33312 return r;
33313 }
33314 - atomic_set(&(sc->stripe[i].error_count), 0);
33315 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33316 }
33317
33318 ti->private = sc;
33319 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33320 DMEMIT("%d ", sc->stripes);
33321 for (i = 0; i < sc->stripes; i++) {
33322 DMEMIT("%s ", sc->stripe[i].dev->name);
33323 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33324 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33325 'D' : 'A';
33326 }
33327 buffer[i] = '\0';
33328 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33329 */
33330 for (i = 0; i < sc->stripes; i++)
33331 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33332 - atomic_inc(&(sc->stripe[i].error_count));
33333 - if (atomic_read(&(sc->stripe[i].error_count)) <
33334 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33335 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33336 DM_IO_ERROR_THRESHOLD)
33337 schedule_work(&sc->trigger_event);
33338 }
33339 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33340 index 100368e..64262ce 100644
33341 --- a/drivers/md/dm-table.c
33342 +++ b/drivers/md/dm-table.c
33343 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33344 if (!dev_size)
33345 return 0;
33346
33347 - if ((start >= dev_size) || (start + len > dev_size)) {
33348 + if ((start >= dev_size) || (len > dev_size - start)) {
33349 DMWARN("%s: %s too small for target: "
33350 "start=%llu, len=%llu, dev_size=%llu",
33351 dm_device_name(ti->table->md), bdevname(bdev, b),
33352 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33353 index 693e149..b7e0fde 100644
33354 --- a/drivers/md/dm-thin-metadata.c
33355 +++ b/drivers/md/dm-thin-metadata.c
33356 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33357 {
33358 pmd->info.tm = pmd->tm;
33359 pmd->info.levels = 2;
33360 - pmd->info.value_type.context = pmd->data_sm;
33361 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33362 pmd->info.value_type.size = sizeof(__le64);
33363 pmd->info.value_type.inc = data_block_inc;
33364 pmd->info.value_type.dec = data_block_dec;
33365 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33366
33367 pmd->bl_info.tm = pmd->tm;
33368 pmd->bl_info.levels = 1;
33369 - pmd->bl_info.value_type.context = pmd->data_sm;
33370 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33371 pmd->bl_info.value_type.size = sizeof(__le64);
33372 pmd->bl_info.value_type.inc = data_block_inc;
33373 pmd->bl_info.value_type.dec = data_block_dec;
33374 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33375 index 77e6eff..913d695 100644
33376 --- a/drivers/md/dm.c
33377 +++ b/drivers/md/dm.c
33378 @@ -182,9 +182,9 @@ struct mapped_device {
33379 /*
33380 * Event handling.
33381 */
33382 - atomic_t event_nr;
33383 + atomic_unchecked_t event_nr;
33384 wait_queue_head_t eventq;
33385 - atomic_t uevent_seq;
33386 + atomic_unchecked_t uevent_seq;
33387 struct list_head uevent_list;
33388 spinlock_t uevent_lock; /* Protect access to uevent_list */
33389
33390 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
33391 rwlock_init(&md->map_lock);
33392 atomic_set(&md->holders, 1);
33393 atomic_set(&md->open_count, 0);
33394 - atomic_set(&md->event_nr, 0);
33395 - atomic_set(&md->uevent_seq, 0);
33396 + atomic_set_unchecked(&md->event_nr, 0);
33397 + atomic_set_unchecked(&md->uevent_seq, 0);
33398 INIT_LIST_HEAD(&md->uevent_list);
33399 spin_lock_init(&md->uevent_lock);
33400
33401 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
33402
33403 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33404
33405 - atomic_inc(&md->event_nr);
33406 + atomic_inc_unchecked(&md->event_nr);
33407 wake_up(&md->eventq);
33408 }
33409
33410 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33411
33412 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33413 {
33414 - return atomic_add_return(1, &md->uevent_seq);
33415 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33416 }
33417
33418 uint32_t dm_get_event_nr(struct mapped_device *md)
33419 {
33420 - return atomic_read(&md->event_nr);
33421 + return atomic_read_unchecked(&md->event_nr);
33422 }
33423
33424 int dm_wait_event(struct mapped_device *md, int event_nr)
33425 {
33426 return wait_event_interruptible(md->eventq,
33427 - (event_nr != atomic_read(&md->event_nr)));
33428 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33429 }
33430
33431 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33432 diff --git a/drivers/md/md.c b/drivers/md/md.c
33433 index 6120071..31d9be2 100644
33434 --- a/drivers/md/md.c
33435 +++ b/drivers/md/md.c
33436 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33437 * start build, activate spare
33438 */
33439 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33440 -static atomic_t md_event_count;
33441 +static atomic_unchecked_t md_event_count;
33442 void md_new_event(struct mddev *mddev)
33443 {
33444 - atomic_inc(&md_event_count);
33445 + atomic_inc_unchecked(&md_event_count);
33446 wake_up(&md_event_waiters);
33447 }
33448 EXPORT_SYMBOL_GPL(md_new_event);
33449 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33450 */
33451 static void md_new_event_inintr(struct mddev *mddev)
33452 {
33453 - atomic_inc(&md_event_count);
33454 + atomic_inc_unchecked(&md_event_count);
33455 wake_up(&md_event_waiters);
33456 }
33457
33458 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33459 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33460 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33461 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33462 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33463 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33464
33465 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33466 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33467 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33468 else
33469 sb->resync_offset = cpu_to_le64(0);
33470
33471 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33472 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33473
33474 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33475 sb->size = cpu_to_le64(mddev->dev_sectors);
33476 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33477 static ssize_t
33478 errors_show(struct md_rdev *rdev, char *page)
33479 {
33480 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33481 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33482 }
33483
33484 static ssize_t
33485 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33486 char *e;
33487 unsigned long n = simple_strtoul(buf, &e, 10);
33488 if (*buf && (*e == 0 || *e == '\n')) {
33489 - atomic_set(&rdev->corrected_errors, n);
33490 + atomic_set_unchecked(&rdev->corrected_errors, n);
33491 return len;
33492 }
33493 return -EINVAL;
33494 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
33495 rdev->sb_loaded = 0;
33496 rdev->bb_page = NULL;
33497 atomic_set(&rdev->nr_pending, 0);
33498 - atomic_set(&rdev->read_errors, 0);
33499 - atomic_set(&rdev->corrected_errors, 0);
33500 + atomic_set_unchecked(&rdev->read_errors, 0);
33501 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33502
33503 INIT_LIST_HEAD(&rdev->same_set);
33504 init_waitqueue_head(&rdev->blocked_wait);
33505 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33506
33507 spin_unlock(&pers_lock);
33508 seq_printf(seq, "\n");
33509 - seq->poll_event = atomic_read(&md_event_count);
33510 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33511 return 0;
33512 }
33513 if (v == (void*)2) {
33514 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33515 return error;
33516
33517 seq = file->private_data;
33518 - seq->poll_event = atomic_read(&md_event_count);
33519 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33520 return error;
33521 }
33522
33523 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33524 /* always allow read */
33525 mask = POLLIN | POLLRDNORM;
33526
33527 - if (seq->poll_event != atomic_read(&md_event_count))
33528 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33529 mask |= POLLERR | POLLPRI;
33530 return mask;
33531 }
33532 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33533 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33534 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33535 (int)part_stat_read(&disk->part0, sectors[1]) -
33536 - atomic_read(&disk->sync_io);
33537 + atomic_read_unchecked(&disk->sync_io);
33538 /* sync IO will cause sync_io to increase before the disk_stats
33539 * as sync_io is counted when a request starts, and
33540 * disk_stats is counted when it completes.
33541 diff --git a/drivers/md/md.h b/drivers/md/md.h
33542 index af443ab..0f93be3 100644
33543 --- a/drivers/md/md.h
33544 +++ b/drivers/md/md.h
33545 @@ -94,13 +94,13 @@ struct md_rdev {
33546 * only maintained for arrays that
33547 * support hot removal
33548 */
33549 - atomic_t read_errors; /* number of consecutive read errors that
33550 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33551 * we have tried to ignore.
33552 */
33553 struct timespec last_read_error; /* monotonic time since our
33554 * last read error
33555 */
33556 - atomic_t corrected_errors; /* number of corrected read errors,
33557 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33558 * for reporting to userspace and storing
33559 * in superblock.
33560 */
33561 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33562
33563 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33564 {
33565 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33566 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33567 }
33568
33569 struct md_personality
33570 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33571 index f6d29e6..7917f5e 100644
33572 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33573 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33574 @@ -22,7 +22,7 @@
33575 * Space map interface.
33576 */
33577 struct sm_disk {
33578 - struct dm_space_map sm;
33579 + dm_space_map_no_const sm;
33580
33581 struct ll_disk ll;
33582 struct ll_disk old_ll;
33583 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33584 index e89ae5e..062e4c2 100644
33585 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33586 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33587 @@ -43,7 +43,7 @@ struct block_op {
33588 };
33589
33590 struct sm_metadata {
33591 - struct dm_space_map sm;
33592 + dm_space_map_no_const sm;
33593
33594 struct ll_disk ll;
33595 struct ll_disk old_ll;
33596 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33597 index 1cbfc6b..56e1dbb 100644
33598 --- a/drivers/md/persistent-data/dm-space-map.h
33599 +++ b/drivers/md/persistent-data/dm-space-map.h
33600 @@ -60,6 +60,7 @@ struct dm_space_map {
33601 int (*root_size)(struct dm_space_map *sm, size_t *result);
33602 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33603 };
33604 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33605
33606 /*----------------------------------------------------------------*/
33607
33608 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33609 index a0f7309..5599dbc 100644
33610 --- a/drivers/md/raid1.c
33611 +++ b/drivers/md/raid1.c
33612 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33613 if (r1_sync_page_io(rdev, sect, s,
33614 bio->bi_io_vec[idx].bv_page,
33615 READ) != 0)
33616 - atomic_add(s, &rdev->corrected_errors);
33617 + atomic_add_unchecked(s, &rdev->corrected_errors);
33618 }
33619 sectors -= s;
33620 sect += s;
33621 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33622 test_bit(In_sync, &rdev->flags)) {
33623 if (r1_sync_page_io(rdev, sect, s,
33624 conf->tmppage, READ)) {
33625 - atomic_add(s, &rdev->corrected_errors);
33626 + atomic_add_unchecked(s, &rdev->corrected_errors);
33627 printk(KERN_INFO
33628 "md/raid1:%s: read error corrected "
33629 "(%d sectors at %llu on %s)\n",
33630 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33631 index c9acbd7..386cd3e 100644
33632 --- a/drivers/md/raid10.c
33633 +++ b/drivers/md/raid10.c
33634 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
33635 /* The write handler will notice the lack of
33636 * R10BIO_Uptodate and record any errors etc
33637 */
33638 - atomic_add(r10_bio->sectors,
33639 + atomic_add_unchecked(r10_bio->sectors,
33640 &conf->mirrors[d].rdev->corrected_errors);
33641
33642 /* for reconstruct, we always reschedule after a read.
33643 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33644 {
33645 struct timespec cur_time_mon;
33646 unsigned long hours_since_last;
33647 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33648 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33649
33650 ktime_get_ts(&cur_time_mon);
33651
33652 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33653 * overflowing the shift of read_errors by hours_since_last.
33654 */
33655 if (hours_since_last >= 8 * sizeof(read_errors))
33656 - atomic_set(&rdev->read_errors, 0);
33657 + atomic_set_unchecked(&rdev->read_errors, 0);
33658 else
33659 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33660 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33661 }
33662
33663 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33664 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33665 return;
33666
33667 check_decay_read_errors(mddev, rdev);
33668 - atomic_inc(&rdev->read_errors);
33669 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33670 + atomic_inc_unchecked(&rdev->read_errors);
33671 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33672 char b[BDEVNAME_SIZE];
33673 bdevname(rdev->bdev, b);
33674
33675 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33676 "md/raid10:%s: %s: Raid device exceeded "
33677 "read_error threshold [cur %d:max %d]\n",
33678 mdname(mddev), b,
33679 - atomic_read(&rdev->read_errors), max_read_errors);
33680 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33681 printk(KERN_NOTICE
33682 "md/raid10:%s: %s: Failing raid device\n",
33683 mdname(mddev), b);
33684 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33685 sect +
33686 choose_data_offset(r10_bio, rdev)),
33687 bdevname(rdev->bdev, b));
33688 - atomic_add(s, &rdev->corrected_errors);
33689 + atomic_add_unchecked(s, &rdev->corrected_errors);
33690 }
33691
33692 rdev_dec_pending(rdev, mddev);
33693 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33694 index a450268..c4168a9 100644
33695 --- a/drivers/md/raid5.c
33696 +++ b/drivers/md/raid5.c
33697 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33698 mdname(conf->mddev), STRIPE_SECTORS,
33699 (unsigned long long)s,
33700 bdevname(rdev->bdev, b));
33701 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33702 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33703 clear_bit(R5_ReadError, &sh->dev[i].flags);
33704 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33705 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33706 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33707
33708 - if (atomic_read(&rdev->read_errors))
33709 - atomic_set(&rdev->read_errors, 0);
33710 + if (atomic_read_unchecked(&rdev->read_errors))
33711 + atomic_set_unchecked(&rdev->read_errors, 0);
33712 } else {
33713 const char *bdn = bdevname(rdev->bdev, b);
33714 int retry = 0;
33715 int set_bad = 0;
33716
33717 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33718 - atomic_inc(&rdev->read_errors);
33719 + atomic_inc_unchecked(&rdev->read_errors);
33720 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33721 printk_ratelimited(
33722 KERN_WARNING
33723 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33724 mdname(conf->mddev),
33725 (unsigned long long)s,
33726 bdn);
33727 - } else if (atomic_read(&rdev->read_errors)
33728 + } else if (atomic_read_unchecked(&rdev->read_errors)
33729 > conf->max_nr_stripes)
33730 printk(KERN_WARNING
33731 "md/raid:%s: Too many read errors, failing device %s.\n",
33732 diff --git a/drivers/media/dvb-core/dvb_demux.h b/drivers/media/dvb-core/dvb_demux.h
33733 index fa7188a..04a045e 100644
33734 --- a/drivers/media/dvb-core/dvb_demux.h
33735 +++ b/drivers/media/dvb-core/dvb_demux.h
33736 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33737 union {
33738 dmx_ts_cb ts;
33739 dmx_section_cb sec;
33740 - } cb;
33741 + } __no_const cb;
33742
33743 struct dvb_demux *demux;
33744 void *priv;
33745 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
33746 index d33101a..6b13069 100644
33747 --- a/drivers/media/dvb-core/dvbdev.c
33748 +++ b/drivers/media/dvb-core/dvbdev.c
33749 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33750 const struct dvb_device *template, void *priv, int type)
33751 {
33752 struct dvb_device *dvbdev;
33753 - struct file_operations *dvbdevfops;
33754 + file_operations_no_const *dvbdevfops;
33755 struct device *clsdev;
33756 int minor;
33757 int id;
33758 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
33759 index 404f63a..4796533 100644
33760 --- a/drivers/media/dvb-frontends/dib3000.h
33761 +++ b/drivers/media/dvb-frontends/dib3000.h
33762 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33763 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33764 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33765 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33766 -};
33767 +} __no_const;
33768
33769 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33770 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33771 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
33772 index 3aa6856..435ad25 100644
33773 --- a/drivers/media/pci/cx88/cx88-alsa.c
33774 +++ b/drivers/media/pci/cx88/cx88-alsa.c
33775 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33776 * Only boards with eeprom and byte 1 at eeprom=1 have it
33777 */
33778
33779 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
33780 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
33781 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33782 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33783 {0, }
33784 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
33785 index feff57e..66a2c67 100644
33786 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
33787 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
33788 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33789 .subvendor = _subvend, .subdevice = _subdev, \
33790 .driver_data = (unsigned long)&_driverdata }
33791
33792 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33793 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33794 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33795 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33796 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33797 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
33798 index 96a13ed..6df45b4 100644
33799 --- a/drivers/media/pci/ngene/ngene-cards.c
33800 +++ b/drivers/media/pci/ngene/ngene-cards.c
33801 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
33802
33803 /****************************************************************************/
33804
33805 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33806 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33807 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33808 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33809 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33810 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
33811 index a3b1a34..71ce0e3 100644
33812 --- a/drivers/media/platform/omap/omap_vout.c
33813 +++ b/drivers/media/platform/omap/omap_vout.c
33814 @@ -65,7 +65,6 @@ enum omap_vout_channels {
33815 OMAP_VIDEO2,
33816 };
33817
33818 -static struct videobuf_queue_ops video_vbq_ops;
33819 /* Variables configurable through module params*/
33820 static u32 video1_numbuffers = 3;
33821 static u32 video2_numbuffers = 3;
33822 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
33823 {
33824 struct videobuf_queue *q;
33825 struct omap_vout_device *vout = NULL;
33826 + static struct videobuf_queue_ops video_vbq_ops = {
33827 + .buf_setup = omap_vout_buffer_setup,
33828 + .buf_prepare = omap_vout_buffer_prepare,
33829 + .buf_release = omap_vout_buffer_release,
33830 + .buf_queue = omap_vout_buffer_queue,
33831 + };
33832
33833 vout = video_drvdata(file);
33834 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33835 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
33836 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33837
33838 q = &vout->vbq;
33839 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33840 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33841 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33842 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33843 spin_lock_init(&vout->vbq_lock);
33844
33845 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33846 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
33847 index 02194c0..091733b 100644
33848 --- a/drivers/media/platform/timblogiw.c
33849 +++ b/drivers/media/platform/timblogiw.c
33850 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33851
33852 /* Platform device functions */
33853
33854 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33855 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33856 .vidioc_querycap = timblogiw_querycap,
33857 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33858 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33859 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33860 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33861 };
33862
33863 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33864 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33865 .owner = THIS_MODULE,
33866 .open = timblogiw_open,
33867 .release = timblogiw_close,
33868 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33869 index 697a421..16c5a5f 100644
33870 --- a/drivers/media/radio/radio-cadet.c
33871 +++ b/drivers/media/radio/radio-cadet.c
33872 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33873 unsigned char readbuf[RDS_BUFFER];
33874 int i = 0;
33875
33876 + if (count > RDS_BUFFER)
33877 + return -EFAULT;
33878 mutex_lock(&dev->lock);
33879 if (dev->rdsstat == 0)
33880 cadet_start_rds(dev);
33881 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33882 while (i < count && dev->rdsin != dev->rdsout)
33883 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33884
33885 - if (i && copy_to_user(data, readbuf, i))
33886 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33887 i = -EFAULT;
33888 unlock:
33889 mutex_unlock(&dev->lock);
33890 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
33891 index 4ea43a9..66f4a8f 100644
33892 --- a/drivers/media/radio/radio-tea5777.h
33893 +++ b/drivers/media/radio/radio-tea5777.h
33894 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
33895
33896 struct radio_tea5777 {
33897 struct v4l2_device *v4l2_dev;
33898 - struct v4l2_file_operations fops;
33899 + v4l2_file_operations_no_const fops;
33900 struct video_device vd; /* video device */
33901 bool has_am; /* Device can tune to AM freqs */
33902 bool write_before_read; /* must write before read quirk */
33903 diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
33904 index 66a56ef..d139911 100644
33905 --- a/drivers/media/usb/au0828/au0828.h
33906 +++ b/drivers/media/usb/au0828/au0828.h
33907 @@ -191,7 +191,7 @@ struct au0828_dev {
33908
33909 /* I2C */
33910 struct i2c_adapter i2c_adap;
33911 - struct i2c_algorithm i2c_algo;
33912 + i2c_algorithm_no_const i2c_algo;
33913 struct i2c_client i2c_client;
33914 u32 i2c_rc;
33915
33916 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
33917 index 3940bb0..fb3952a 100644
33918 --- a/drivers/media/usb/dvb-usb/cxusb.c
33919 +++ b/drivers/media/usb/dvb-usb/cxusb.c
33920 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33921
33922 struct dib0700_adapter_state {
33923 int (*set_param_save) (struct dvb_frontend *);
33924 -};
33925 +} __no_const;
33926
33927 static int dib7070_set_param_override(struct dvb_frontend *fe)
33928 {
33929 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
33930 index 9382895..ac8093c 100644
33931 --- a/drivers/media/usb/dvb-usb/dw2102.c
33932 +++ b/drivers/media/usb/dvb-usb/dw2102.c
33933 @@ -95,7 +95,7 @@ struct su3000_state {
33934
33935 struct s6x0_state {
33936 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33937 -};
33938 +} __no_const;
33939
33940 /* debug */
33941 static int dvb_usb_dw2102_debug;
33942 diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
33943 index 036952f..80d356d 100644
33944 --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
33945 +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
33946 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33947
33948 /* I2C stuff */
33949 struct i2c_adapter i2c_adap;
33950 - struct i2c_algorithm i2c_algo;
33951 + i2c_algorithm_no_const i2c_algo;
33952 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33953 int i2c_cx25840_hack_state;
33954 int i2c_linked;
33955 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33956 index fb69baa..cf7ad22 100644
33957 --- a/drivers/message/fusion/mptbase.c
33958 +++ b/drivers/message/fusion/mptbase.c
33959 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33960 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33961 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33962
33963 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33964 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33965 +#else
33966 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33967 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33968 +#endif
33969 +
33970 /*
33971 * Rounding UP to nearest 4-kB boundary here...
33972 */
33973 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33974 index 551262e..7551198 100644
33975 --- a/drivers/message/fusion/mptsas.c
33976 +++ b/drivers/message/fusion/mptsas.c
33977 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33978 return 0;
33979 }
33980
33981 +static inline void
33982 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33983 +{
33984 + if (phy_info->port_details) {
33985 + phy_info->port_details->rphy = rphy;
33986 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33987 + ioc->name, rphy));
33988 + }
33989 +
33990 + if (rphy) {
33991 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33992 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33993 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33994 + ioc->name, rphy, rphy->dev.release));
33995 + }
33996 +}
33997 +
33998 /* no mutex */
33999 static void
34000 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34001 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34002 return NULL;
34003 }
34004
34005 -static inline void
34006 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34007 -{
34008 - if (phy_info->port_details) {
34009 - phy_info->port_details->rphy = rphy;
34010 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34011 - ioc->name, rphy));
34012 - }
34013 -
34014 - if (rphy) {
34015 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34016 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34017 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34018 - ioc->name, rphy, rphy->dev.release));
34019 - }
34020 -}
34021 -
34022 static inline struct sas_port *
34023 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34024 {
34025 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34026 index 0c3ced7..1fe34ec 100644
34027 --- a/drivers/message/fusion/mptscsih.c
34028 +++ b/drivers/message/fusion/mptscsih.c
34029 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34030
34031 h = shost_priv(SChost);
34032
34033 - if (h) {
34034 - if (h->info_kbuf == NULL)
34035 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34036 - return h->info_kbuf;
34037 - h->info_kbuf[0] = '\0';
34038 + if (!h)
34039 + return NULL;
34040
34041 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34042 - h->info_kbuf[size-1] = '\0';
34043 - }
34044 + if (h->info_kbuf == NULL)
34045 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34046 + return h->info_kbuf;
34047 + h->info_kbuf[0] = '\0';
34048 +
34049 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34050 + h->info_kbuf[size-1] = '\0';
34051
34052 return h->info_kbuf;
34053 }
34054 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34055 index 8001aa6..b137580 100644
34056 --- a/drivers/message/i2o/i2o_proc.c
34057 +++ b/drivers/message/i2o/i2o_proc.c
34058 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34059 "Array Controller Device"
34060 };
34061
34062 -static char *chtostr(char *tmp, u8 *chars, int n)
34063 -{
34064 - tmp[0] = 0;
34065 - return strncat(tmp, (char *)chars, n);
34066 -}
34067 -
34068 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34069 char *group)
34070 {
34071 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34072 } *result;
34073
34074 i2o_exec_execute_ddm_table ddm_table;
34075 - char tmp[28 + 1];
34076
34077 result = kmalloc(sizeof(*result), GFP_KERNEL);
34078 if (!result)
34079 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34080
34081 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34082 seq_printf(seq, "%-#8x", ddm_table.module_id);
34083 - seq_printf(seq, "%-29s",
34084 - chtostr(tmp, ddm_table.module_name_version, 28));
34085 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34086 seq_printf(seq, "%9d ", ddm_table.data_size);
34087 seq_printf(seq, "%8d", ddm_table.code_size);
34088
34089 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34090
34091 i2o_driver_result_table *result;
34092 i2o_driver_store_table *dst;
34093 - char tmp[28 + 1];
34094
34095 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34096 if (result == NULL)
34097 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34098
34099 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34100 seq_printf(seq, "%-#8x", dst->module_id);
34101 - seq_printf(seq, "%-29s",
34102 - chtostr(tmp, dst->module_name_version, 28));
34103 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34104 + seq_printf(seq, "%-.28s", dst->module_name_version);
34105 + seq_printf(seq, "%-.8s", dst->date);
34106 seq_printf(seq, "%8d ", dst->module_size);
34107 seq_printf(seq, "%8d ", dst->mpb_size);
34108 seq_printf(seq, "0x%04x", dst->module_flags);
34109 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34110 // == (allow) 512d bytes (max)
34111 static u16 *work16 = (u16 *) work32;
34112 int token;
34113 - char tmp[16 + 1];
34114
34115 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34116
34117 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34118 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34119 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34120 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34121 - seq_printf(seq, "Vendor info : %s\n",
34122 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34123 - seq_printf(seq, "Product info : %s\n",
34124 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34125 - seq_printf(seq, "Description : %s\n",
34126 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34127 - seq_printf(seq, "Product rev. : %s\n",
34128 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34129 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34130 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34131 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34132 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34133
34134 seq_printf(seq, "Serial number : ");
34135 print_serial_number(seq, (u8 *) (work32 + 16),
34136 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34137 u8 pad[256]; // allow up to 256 byte (max) serial number
34138 } result;
34139
34140 - char tmp[24 + 1];
34141 -
34142 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34143
34144 if (token < 0) {
34145 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34146 }
34147
34148 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34149 - seq_printf(seq, "Module name : %s\n",
34150 - chtostr(tmp, result.module_name, 24));
34151 - seq_printf(seq, "Module revision : %s\n",
34152 - chtostr(tmp, result.module_rev, 8));
34153 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34154 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34155
34156 seq_printf(seq, "Serial number : ");
34157 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34158 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34159 u8 instance_number[4];
34160 } result;
34161
34162 - char tmp[64 + 1];
34163 -
34164 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34165
34166 if (token < 0) {
34167 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34168 return 0;
34169 }
34170
34171 - seq_printf(seq, "Device name : %s\n",
34172 - chtostr(tmp, result.device_name, 64));
34173 - seq_printf(seq, "Service name : %s\n",
34174 - chtostr(tmp, result.service_name, 64));
34175 - seq_printf(seq, "Physical name : %s\n",
34176 - chtostr(tmp, result.physical_location, 64));
34177 - seq_printf(seq, "Instance number : %s\n",
34178 - chtostr(tmp, result.instance_number, 4));
34179 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34180 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34181 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34182 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34183
34184 return 0;
34185 }
34186 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34187 index a8c08f3..155fe3d 100644
34188 --- a/drivers/message/i2o/iop.c
34189 +++ b/drivers/message/i2o/iop.c
34190 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34191
34192 spin_lock_irqsave(&c->context_list_lock, flags);
34193
34194 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34195 - atomic_inc(&c->context_list_counter);
34196 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34197 + atomic_inc_unchecked(&c->context_list_counter);
34198
34199 - entry->context = atomic_read(&c->context_list_counter);
34200 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34201
34202 list_add(&entry->list, &c->context_list);
34203
34204 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34205
34206 #if BITS_PER_LONG == 64
34207 spin_lock_init(&c->context_list_lock);
34208 - atomic_set(&c->context_list_counter, 0);
34209 + atomic_set_unchecked(&c->context_list_counter, 0);
34210 INIT_LIST_HEAD(&c->context_list);
34211 #endif
34212
34213 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34214 index 7ce65f4..e66e9bc 100644
34215 --- a/drivers/mfd/abx500-core.c
34216 +++ b/drivers/mfd/abx500-core.c
34217 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34218
34219 struct abx500_device_entry {
34220 struct list_head list;
34221 - struct abx500_ops ops;
34222 + abx500_ops_no_const ops;
34223 struct device *dev;
34224 };
34225
34226 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34227 index 965c480..71f2db9 100644
34228 --- a/drivers/mfd/janz-cmodio.c
34229 +++ b/drivers/mfd/janz-cmodio.c
34230 @@ -13,6 +13,7 @@
34231
34232 #include <linux/kernel.h>
34233 #include <linux/module.h>
34234 +#include <linux/slab.h>
34235 #include <linux/init.h>
34236 #include <linux/pci.h>
34237 #include <linux/interrupt.h>
34238 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
34239 index 3aa9a96..59cf685 100644
34240 --- a/drivers/misc/kgdbts.c
34241 +++ b/drivers/misc/kgdbts.c
34242 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
34243 char before[BREAK_INSTR_SIZE];
34244 char after[BREAK_INSTR_SIZE];
34245
34246 - probe_kernel_read(before, (char *)kgdbts_break_test,
34247 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
34248 BREAK_INSTR_SIZE);
34249 init_simple_test();
34250 ts.tst = plant_and_detach_test;
34251 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
34252 /* Activate test with initial breakpoint */
34253 if (!is_early)
34254 kgdb_breakpoint();
34255 - probe_kernel_read(after, (char *)kgdbts_break_test,
34256 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
34257 BREAK_INSTR_SIZE);
34258 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
34259 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
34260 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34261 index 4a87e5c..76bdf5c 100644
34262 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34263 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34264 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34265 * the lid is closed. This leads to interrupts as soon as a little move
34266 * is done.
34267 */
34268 - atomic_inc(&lis3->count);
34269 + atomic_inc_unchecked(&lis3->count);
34270
34271 wake_up_interruptible(&lis3->misc_wait);
34272 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34273 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34274 if (lis3->pm_dev)
34275 pm_runtime_get_sync(lis3->pm_dev);
34276
34277 - atomic_set(&lis3->count, 0);
34278 + atomic_set_unchecked(&lis3->count, 0);
34279 return 0;
34280 }
34281
34282 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34283 add_wait_queue(&lis3->misc_wait, &wait);
34284 while (true) {
34285 set_current_state(TASK_INTERRUPTIBLE);
34286 - data = atomic_xchg(&lis3->count, 0);
34287 + data = atomic_xchg_unchecked(&lis3->count, 0);
34288 if (data)
34289 break;
34290
34291 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34292 struct lis3lv02d, miscdev);
34293
34294 poll_wait(file, &lis3->misc_wait, wait);
34295 - if (atomic_read(&lis3->count))
34296 + if (atomic_read_unchecked(&lis3->count))
34297 return POLLIN | POLLRDNORM;
34298 return 0;
34299 }
34300 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34301 index c439c82..1f20f57 100644
34302 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34303 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34304 @@ -297,7 +297,7 @@ struct lis3lv02d {
34305 struct input_polled_dev *idev; /* input device */
34306 struct platform_device *pdev; /* platform device */
34307 struct regulator_bulk_data regulators[2];
34308 - atomic_t count; /* interrupt count after last read */
34309 + atomic_unchecked_t count; /* interrupt count after last read */
34310 union axis_conversion ac; /* hw -> logical axis */
34311 int mapped_btns[3];
34312
34313 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34314 index 2f30bad..c4c13d0 100644
34315 --- a/drivers/misc/sgi-gru/gruhandles.c
34316 +++ b/drivers/misc/sgi-gru/gruhandles.c
34317 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34318 unsigned long nsec;
34319
34320 nsec = CLKS2NSEC(clks);
34321 - atomic_long_inc(&mcs_op_statistics[op].count);
34322 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34323 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34324 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34325 if (mcs_op_statistics[op].max < nsec)
34326 mcs_op_statistics[op].max = nsec;
34327 }
34328 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34329 index 950dbe9..eeef0f8 100644
34330 --- a/drivers/misc/sgi-gru/gruprocfs.c
34331 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34332 @@ -32,9 +32,9 @@
34333
34334 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34335
34336 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34337 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34338 {
34339 - unsigned long val = atomic_long_read(v);
34340 + unsigned long val = atomic_long_read_unchecked(v);
34341
34342 seq_printf(s, "%16lu %s\n", val, id);
34343 }
34344 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34345
34346 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34347 for (op = 0; op < mcsop_last; op++) {
34348 - count = atomic_long_read(&mcs_op_statistics[op].count);
34349 - total = atomic_long_read(&mcs_op_statistics[op].total);
34350 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34351 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34352 max = mcs_op_statistics[op].max;
34353 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34354 count ? total / count : 0, max);
34355 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34356 index 5c3ce24..4915ccb 100644
34357 --- a/drivers/misc/sgi-gru/grutables.h
34358 +++ b/drivers/misc/sgi-gru/grutables.h
34359 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34360 * GRU statistics.
34361 */
34362 struct gru_stats_s {
34363 - atomic_long_t vdata_alloc;
34364 - atomic_long_t vdata_free;
34365 - atomic_long_t gts_alloc;
34366 - atomic_long_t gts_free;
34367 - atomic_long_t gms_alloc;
34368 - atomic_long_t gms_free;
34369 - atomic_long_t gts_double_allocate;
34370 - atomic_long_t assign_context;
34371 - atomic_long_t assign_context_failed;
34372 - atomic_long_t free_context;
34373 - atomic_long_t load_user_context;
34374 - atomic_long_t load_kernel_context;
34375 - atomic_long_t lock_kernel_context;
34376 - atomic_long_t unlock_kernel_context;
34377 - atomic_long_t steal_user_context;
34378 - atomic_long_t steal_kernel_context;
34379 - atomic_long_t steal_context_failed;
34380 - atomic_long_t nopfn;
34381 - atomic_long_t asid_new;
34382 - atomic_long_t asid_next;
34383 - atomic_long_t asid_wrap;
34384 - atomic_long_t asid_reuse;
34385 - atomic_long_t intr;
34386 - atomic_long_t intr_cbr;
34387 - atomic_long_t intr_tfh;
34388 - atomic_long_t intr_spurious;
34389 - atomic_long_t intr_mm_lock_failed;
34390 - atomic_long_t call_os;
34391 - atomic_long_t call_os_wait_queue;
34392 - atomic_long_t user_flush_tlb;
34393 - atomic_long_t user_unload_context;
34394 - atomic_long_t user_exception;
34395 - atomic_long_t set_context_option;
34396 - atomic_long_t check_context_retarget_intr;
34397 - atomic_long_t check_context_unload;
34398 - atomic_long_t tlb_dropin;
34399 - atomic_long_t tlb_preload_page;
34400 - atomic_long_t tlb_dropin_fail_no_asid;
34401 - atomic_long_t tlb_dropin_fail_upm;
34402 - atomic_long_t tlb_dropin_fail_invalid;
34403 - atomic_long_t tlb_dropin_fail_range_active;
34404 - atomic_long_t tlb_dropin_fail_idle;
34405 - atomic_long_t tlb_dropin_fail_fmm;
34406 - atomic_long_t tlb_dropin_fail_no_exception;
34407 - atomic_long_t tfh_stale_on_fault;
34408 - atomic_long_t mmu_invalidate_range;
34409 - atomic_long_t mmu_invalidate_page;
34410 - atomic_long_t flush_tlb;
34411 - atomic_long_t flush_tlb_gru;
34412 - atomic_long_t flush_tlb_gru_tgh;
34413 - atomic_long_t flush_tlb_gru_zero_asid;
34414 + atomic_long_unchecked_t vdata_alloc;
34415 + atomic_long_unchecked_t vdata_free;
34416 + atomic_long_unchecked_t gts_alloc;
34417 + atomic_long_unchecked_t gts_free;
34418 + atomic_long_unchecked_t gms_alloc;
34419 + atomic_long_unchecked_t gms_free;
34420 + atomic_long_unchecked_t gts_double_allocate;
34421 + atomic_long_unchecked_t assign_context;
34422 + atomic_long_unchecked_t assign_context_failed;
34423 + atomic_long_unchecked_t free_context;
34424 + atomic_long_unchecked_t load_user_context;
34425 + atomic_long_unchecked_t load_kernel_context;
34426 + atomic_long_unchecked_t lock_kernel_context;
34427 + atomic_long_unchecked_t unlock_kernel_context;
34428 + atomic_long_unchecked_t steal_user_context;
34429 + atomic_long_unchecked_t steal_kernel_context;
34430 + atomic_long_unchecked_t steal_context_failed;
34431 + atomic_long_unchecked_t nopfn;
34432 + atomic_long_unchecked_t asid_new;
34433 + atomic_long_unchecked_t asid_next;
34434 + atomic_long_unchecked_t asid_wrap;
34435 + atomic_long_unchecked_t asid_reuse;
34436 + atomic_long_unchecked_t intr;
34437 + atomic_long_unchecked_t intr_cbr;
34438 + atomic_long_unchecked_t intr_tfh;
34439 + atomic_long_unchecked_t intr_spurious;
34440 + atomic_long_unchecked_t intr_mm_lock_failed;
34441 + atomic_long_unchecked_t call_os;
34442 + atomic_long_unchecked_t call_os_wait_queue;
34443 + atomic_long_unchecked_t user_flush_tlb;
34444 + atomic_long_unchecked_t user_unload_context;
34445 + atomic_long_unchecked_t user_exception;
34446 + atomic_long_unchecked_t set_context_option;
34447 + atomic_long_unchecked_t check_context_retarget_intr;
34448 + atomic_long_unchecked_t check_context_unload;
34449 + atomic_long_unchecked_t tlb_dropin;
34450 + atomic_long_unchecked_t tlb_preload_page;
34451 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34452 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34453 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34454 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34455 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34456 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34457 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34458 + atomic_long_unchecked_t tfh_stale_on_fault;
34459 + atomic_long_unchecked_t mmu_invalidate_range;
34460 + atomic_long_unchecked_t mmu_invalidate_page;
34461 + atomic_long_unchecked_t flush_tlb;
34462 + atomic_long_unchecked_t flush_tlb_gru;
34463 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34464 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34465
34466 - atomic_long_t copy_gpa;
34467 - atomic_long_t read_gpa;
34468 + atomic_long_unchecked_t copy_gpa;
34469 + atomic_long_unchecked_t read_gpa;
34470
34471 - atomic_long_t mesq_receive;
34472 - atomic_long_t mesq_receive_none;
34473 - atomic_long_t mesq_send;
34474 - atomic_long_t mesq_send_failed;
34475 - atomic_long_t mesq_noop;
34476 - atomic_long_t mesq_send_unexpected_error;
34477 - atomic_long_t mesq_send_lb_overflow;
34478 - atomic_long_t mesq_send_qlimit_reached;
34479 - atomic_long_t mesq_send_amo_nacked;
34480 - atomic_long_t mesq_send_put_nacked;
34481 - atomic_long_t mesq_page_overflow;
34482 - atomic_long_t mesq_qf_locked;
34483 - atomic_long_t mesq_qf_noop_not_full;
34484 - atomic_long_t mesq_qf_switch_head_failed;
34485 - atomic_long_t mesq_qf_unexpected_error;
34486 - atomic_long_t mesq_noop_unexpected_error;
34487 - atomic_long_t mesq_noop_lb_overflow;
34488 - atomic_long_t mesq_noop_qlimit_reached;
34489 - atomic_long_t mesq_noop_amo_nacked;
34490 - atomic_long_t mesq_noop_put_nacked;
34491 - atomic_long_t mesq_noop_page_overflow;
34492 + atomic_long_unchecked_t mesq_receive;
34493 + atomic_long_unchecked_t mesq_receive_none;
34494 + atomic_long_unchecked_t mesq_send;
34495 + atomic_long_unchecked_t mesq_send_failed;
34496 + atomic_long_unchecked_t mesq_noop;
34497 + atomic_long_unchecked_t mesq_send_unexpected_error;
34498 + atomic_long_unchecked_t mesq_send_lb_overflow;
34499 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34500 + atomic_long_unchecked_t mesq_send_amo_nacked;
34501 + atomic_long_unchecked_t mesq_send_put_nacked;
34502 + atomic_long_unchecked_t mesq_page_overflow;
34503 + atomic_long_unchecked_t mesq_qf_locked;
34504 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34505 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34506 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34507 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34508 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34509 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34510 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34511 + atomic_long_unchecked_t mesq_noop_put_nacked;
34512 + atomic_long_unchecked_t mesq_noop_page_overflow;
34513
34514 };
34515
34516 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34517 tghop_invalidate, mcsop_last};
34518
34519 struct mcs_op_statistic {
34520 - atomic_long_t count;
34521 - atomic_long_t total;
34522 + atomic_long_unchecked_t count;
34523 + atomic_long_unchecked_t total;
34524 unsigned long max;
34525 };
34526
34527 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34528
34529 #define STAT(id) do { \
34530 if (gru_options & OPT_STATS) \
34531 - atomic_long_inc(&gru_stats.id); \
34532 + atomic_long_inc_unchecked(&gru_stats.id); \
34533 } while (0)
34534
34535 #ifdef CONFIG_SGI_GRU_DEBUG
34536 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34537 index c862cd4..0d176fe 100644
34538 --- a/drivers/misc/sgi-xp/xp.h
34539 +++ b/drivers/misc/sgi-xp/xp.h
34540 @@ -288,7 +288,7 @@ struct xpc_interface {
34541 xpc_notify_func, void *);
34542 void (*received) (short, int, void *);
34543 enum xp_retval (*partid_to_nasids) (short, void *);
34544 -};
34545 +} __no_const;
34546
34547 extern struct xpc_interface xpc_interface;
34548
34549 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34550 index b94d5f7..7f494c5 100644
34551 --- a/drivers/misc/sgi-xp/xpc.h
34552 +++ b/drivers/misc/sgi-xp/xpc.h
34553 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34554 void (*received_payload) (struct xpc_channel *, void *);
34555 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34556 };
34557 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34558
34559 /* struct xpc_partition act_state values (for XPC HB) */
34560
34561 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34562 /* found in xpc_main.c */
34563 extern struct device *xpc_part;
34564 extern struct device *xpc_chan;
34565 -extern struct xpc_arch_operations xpc_arch_ops;
34566 +extern xpc_arch_operations_no_const xpc_arch_ops;
34567 extern int xpc_disengage_timelimit;
34568 extern int xpc_disengage_timedout;
34569 extern int xpc_activate_IRQ_rcvd;
34570 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34571 index 8d082b4..aa749ae 100644
34572 --- a/drivers/misc/sgi-xp/xpc_main.c
34573 +++ b/drivers/misc/sgi-xp/xpc_main.c
34574 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34575 .notifier_call = xpc_system_die,
34576 };
34577
34578 -struct xpc_arch_operations xpc_arch_ops;
34579 +xpc_arch_operations_no_const xpc_arch_ops;
34580
34581 /*
34582 * Timer function to enforce the timelimit on the partition disengage.
34583 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
34584 index a0e1720..ee63d0b 100644
34585 --- a/drivers/mmc/core/mmc_ops.c
34586 +++ b/drivers/mmc/core/mmc_ops.c
34587 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
34588 void *data_buf;
34589 int is_on_stack;
34590
34591 - is_on_stack = object_is_on_stack(buf);
34592 + is_on_stack = object_starts_on_stack(buf);
34593 if (is_on_stack) {
34594 /*
34595 * dma onto stack is unsafe/nonportable, but callers to this
34596 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34597 index a4eb8b5..8c0628f 100644
34598 --- a/drivers/mtd/devices/doc2000.c
34599 +++ b/drivers/mtd/devices/doc2000.c
34600 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34601
34602 /* The ECC will not be calculated correctly if less than 512 is written */
34603 /* DBB-
34604 - if (len != 0x200 && eccbuf)
34605 + if (len != 0x200)
34606 printk(KERN_WARNING
34607 "ECC needs a full sector write (adr: %lx size %lx)\n",
34608 (long) to, (long) len);
34609 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34610 index e706a23..b3d262f 100644
34611 --- a/drivers/mtd/nand/denali.c
34612 +++ b/drivers/mtd/nand/denali.c
34613 @@ -26,6 +26,7 @@
34614 #include <linux/pci.h>
34615 #include <linux/mtd/mtd.h>
34616 #include <linux/module.h>
34617 +#include <linux/slab.h>
34618
34619 #include "denali.h"
34620
34621 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34622 index 51b9d6a..52af9a7 100644
34623 --- a/drivers/mtd/nftlmount.c
34624 +++ b/drivers/mtd/nftlmount.c
34625 @@ -24,6 +24,7 @@
34626 #include <asm/errno.h>
34627 #include <linux/delay.h>
34628 #include <linux/slab.h>
34629 +#include <linux/sched.h>
34630 #include <linux/mtd/mtd.h>
34631 #include <linux/mtd/nand.h>
34632 #include <linux/mtd/nftl.h>
34633 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34634 index acf2fe4..25cf8fd 100644
34635 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34636 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34637 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34638
34639 int (*wait_comp)(struct bnx2x *bp,
34640 struct bnx2x_rx_mode_ramrod_params *p);
34641 -};
34642 +} __no_const;
34643
34644 /********************** Set multicast group ***********************************/
34645
34646 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34647 index d9308c32..d87b824 100644
34648 --- a/drivers/net/ethernet/broadcom/tg3.h
34649 +++ b/drivers/net/ethernet/broadcom/tg3.h
34650 @@ -140,6 +140,7 @@
34651 #define CHIPREV_ID_5750_A0 0x4000
34652 #define CHIPREV_ID_5750_A1 0x4001
34653 #define CHIPREV_ID_5750_A3 0x4003
34654 +#define CHIPREV_ID_5750_C1 0x4201
34655 #define CHIPREV_ID_5750_C2 0x4202
34656 #define CHIPREV_ID_5752_A0_HW 0x5000
34657 #define CHIPREV_ID_5752_A0 0x6000
34658 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34659 index 8cffcdf..aadf043 100644
34660 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34661 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34662 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34663 */
34664 struct l2t_skb_cb {
34665 arp_failure_handler_func arp_failure_handler;
34666 -};
34667 +} __no_const;
34668
34669 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34670
34671 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34672 index f879e92..726f20f 100644
34673 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34674 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34675 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34676 for (i=0; i<ETH_ALEN; i++) {
34677 tmp.addr[i] = dev->dev_addr[i];
34678 }
34679 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34680 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34681 break;
34682
34683 case DE4X5_SET_HWADDR: /* Set the hardware address */
34684 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34685 spin_lock_irqsave(&lp->lock, flags);
34686 memcpy(&statbuf, &lp->pktStats, ioc->len);
34687 spin_unlock_irqrestore(&lp->lock, flags);
34688 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34689 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34690 return -EFAULT;
34691 break;
34692 }
34693 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34694 index 75d45f8..3d9c55b 100644
34695 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34696 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34697 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34698 struct uli_phy_ops {
34699 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34700 u16 (*read)(struct uli526x_board_info *, u8, u8);
34701 - } phy;
34702 + } __no_const phy;
34703 struct net_device *next_dev; /* next device */
34704 struct pci_dev *pdev; /* PCI device */
34705 spinlock_t lock;
34706 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34707 index d1b6cc5..cde0d97 100644
34708 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34709 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34710 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34711
34712 if (wrapped)
34713 newacc += 65536;
34714 - ACCESS_ONCE(*acc) = newacc;
34715 + ACCESS_ONCE_RW(*acc) = newacc;
34716 }
34717
34718 void be_parse_stats(struct be_adapter *adapter)
34719 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34720 index 74d749e..eefb1bd 100644
34721 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34722 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34723 @@ -31,6 +31,8 @@
34724 #include <linux/netdevice.h>
34725 #include <linux/phy.h>
34726 #include <linux/platform_device.h>
34727 +#include <linux/interrupt.h>
34728 +#include <linux/irqreturn.h>
34729 #include <net/ip.h>
34730
34731 #include "ftgmac100.h"
34732 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34733 index b901a01..1ff32ee 100644
34734 --- a/drivers/net/ethernet/faraday/ftmac100.c
34735 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34736 @@ -31,6 +31,8 @@
34737 #include <linux/module.h>
34738 #include <linux/netdevice.h>
34739 #include <linux/platform_device.h>
34740 +#include <linux/interrupt.h>
34741 +#include <linux/irqreturn.h>
34742
34743 #include "ftmac100.h"
34744
34745 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34746 index d37bfd9..5e13032 100644
34747 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34748 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34749 @@ -799,6 +799,7 @@ struct e1000_mac_operations {
34750 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34751 s32 (*read_mac_addr)(struct e1000_hw *);
34752 };
34753 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34754
34755 /*
34756 * When to use various PHY register access functions:
34757 @@ -839,6 +840,7 @@ struct e1000_phy_operations {
34758 void (*power_up)(struct e1000_hw *);
34759 void (*power_down)(struct e1000_hw *);
34760 };
34761 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34762
34763 /* Function pointers for the NVM. */
34764 struct e1000_nvm_operations {
34765 @@ -851,9 +853,10 @@ struct e1000_nvm_operations {
34766 s32 (*validate)(struct e1000_hw *);
34767 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34768 };
34769 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34770
34771 struct e1000_mac_info {
34772 - struct e1000_mac_operations ops;
34773 + e1000_mac_operations_no_const ops;
34774 u8 addr[ETH_ALEN];
34775 u8 perm_addr[ETH_ALEN];
34776
34777 @@ -894,7 +897,7 @@ struct e1000_mac_info {
34778 };
34779
34780 struct e1000_phy_info {
34781 - struct e1000_phy_operations ops;
34782 + e1000_phy_operations_no_const ops;
34783
34784 enum e1000_phy_type type;
34785
34786 @@ -928,7 +931,7 @@ struct e1000_phy_info {
34787 };
34788
34789 struct e1000_nvm_info {
34790 - struct e1000_nvm_operations ops;
34791 + e1000_nvm_operations_no_const ops;
34792
34793 enum e1000_nvm_type type;
34794 enum e1000_nvm_override override;
34795 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34796 index c2a51dc..c2bd262 100644
34797 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34798 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34799 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34800 void (*release_swfw_sync)(struct e1000_hw *, u16);
34801
34802 };
34803 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34804
34805 struct e1000_phy_operations {
34806 s32 (*acquire)(struct e1000_hw *);
34807 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34808 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34809 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34810 };
34811 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34812
34813 struct e1000_nvm_operations {
34814 s32 (*acquire)(struct e1000_hw *);
34815 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34816 s32 (*validate)(struct e1000_hw *);
34817 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34818 };
34819 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34820
34821 struct e1000_info {
34822 s32 (*get_invariants)(struct e1000_hw *);
34823 @@ -364,7 +367,7 @@ struct e1000_info {
34824 extern const struct e1000_info e1000_82575_info;
34825
34826 struct e1000_mac_info {
34827 - struct e1000_mac_operations ops;
34828 + e1000_mac_operations_no_const ops;
34829
34830 u8 addr[6];
34831 u8 perm_addr[6];
34832 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34833 };
34834
34835 struct e1000_phy_info {
34836 - struct e1000_phy_operations ops;
34837 + e1000_phy_operations_no_const ops;
34838
34839 enum e1000_phy_type type;
34840
34841 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34842 };
34843
34844 struct e1000_nvm_info {
34845 - struct e1000_nvm_operations ops;
34846 + e1000_nvm_operations_no_const ops;
34847 enum e1000_nvm_type type;
34848 enum e1000_nvm_override override;
34849
34850 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34851 s32 (*check_for_ack)(struct e1000_hw *, u16);
34852 s32 (*check_for_rst)(struct e1000_hw *, u16);
34853 };
34854 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34855
34856 struct e1000_mbx_stats {
34857 u32 msgs_tx;
34858 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34859 };
34860
34861 struct e1000_mbx_info {
34862 - struct e1000_mbx_operations ops;
34863 + e1000_mbx_operations_no_const ops;
34864 struct e1000_mbx_stats stats;
34865 u32 timeout;
34866 u32 usec_delay;
34867 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34868 index 57db3c6..aa825fc 100644
34869 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34870 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34871 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34872 s32 (*read_mac_addr)(struct e1000_hw *);
34873 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34874 };
34875 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34876
34877 struct e1000_mac_info {
34878 - struct e1000_mac_operations ops;
34879 + e1000_mac_operations_no_const ops;
34880 u8 addr[6];
34881 u8 perm_addr[6];
34882
34883 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34884 s32 (*check_for_ack)(struct e1000_hw *);
34885 s32 (*check_for_rst)(struct e1000_hw *);
34886 };
34887 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34888
34889 struct e1000_mbx_stats {
34890 u32 msgs_tx;
34891 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34892 };
34893
34894 struct e1000_mbx_info {
34895 - struct e1000_mbx_operations ops;
34896 + e1000_mbx_operations_no_const ops;
34897 struct e1000_mbx_stats stats;
34898 u32 timeout;
34899 u32 usec_delay;
34900 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34901 index d929131..aed108f 100644
34902 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34903 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34904 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34905 /* store the new cycle speed */
34906 adapter->cycle_speed = cycle_speed;
34907
34908 - ACCESS_ONCE(adapter->base_incval) = incval;
34909 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34910 smp_mb();
34911
34912 /* grab the ptp lock */
34913 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34914 index 0722f33..771758a 100644
34915 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34916 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34917 @@ -2800,6 +2800,7 @@ struct ixgbe_eeprom_operations {
34918 s32 (*update_checksum)(struct ixgbe_hw *);
34919 u16 (*calc_checksum)(struct ixgbe_hw *);
34920 };
34921 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34922
34923 struct ixgbe_mac_operations {
34924 s32 (*init_hw)(struct ixgbe_hw *);
34925 @@ -2866,6 +2867,7 @@ struct ixgbe_mac_operations {
34926 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34927 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34928 };
34929 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34930
34931 struct ixgbe_phy_operations {
34932 s32 (*identify)(struct ixgbe_hw *);
34933 @@ -2885,9 +2887,10 @@ struct ixgbe_phy_operations {
34934 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34935 s32 (*check_overtemp)(struct ixgbe_hw *);
34936 };
34937 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34938
34939 struct ixgbe_eeprom_info {
34940 - struct ixgbe_eeprom_operations ops;
34941 + ixgbe_eeprom_operations_no_const ops;
34942 enum ixgbe_eeprom_type type;
34943 u32 semaphore_delay;
34944 u16 word_size;
34945 @@ -2897,7 +2900,7 @@ struct ixgbe_eeprom_info {
34946
34947 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34948 struct ixgbe_mac_info {
34949 - struct ixgbe_mac_operations ops;
34950 + ixgbe_mac_operations_no_const ops;
34951 enum ixgbe_mac_type type;
34952 u8 addr[ETH_ALEN];
34953 u8 perm_addr[ETH_ALEN];
34954 @@ -2927,7 +2930,7 @@ struct ixgbe_mac_info {
34955 };
34956
34957 struct ixgbe_phy_info {
34958 - struct ixgbe_phy_operations ops;
34959 + ixgbe_phy_operations_no_const ops;
34960 struct mdio_if_info mdio;
34961 enum ixgbe_phy_type type;
34962 u32 id;
34963 @@ -2955,6 +2958,7 @@ struct ixgbe_mbx_operations {
34964 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34965 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34966 };
34967 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34968
34969 struct ixgbe_mbx_stats {
34970 u32 msgs_tx;
34971 @@ -2966,7 +2970,7 @@ struct ixgbe_mbx_stats {
34972 };
34973
34974 struct ixgbe_mbx_info {
34975 - struct ixgbe_mbx_operations ops;
34976 + ixgbe_mbx_operations_no_const ops;
34977 struct ixgbe_mbx_stats stats;
34978 u32 timeout;
34979 u32 usec_delay;
34980 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34981 index 47f11a5..c817d97 100644
34982 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34983 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34984 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34985 s32 (*clear_vfta)(struct ixgbe_hw *);
34986 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34987 };
34988 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34989
34990 enum ixgbe_mac_type {
34991 ixgbe_mac_unknown = 0,
34992 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34993 };
34994
34995 struct ixgbe_mac_info {
34996 - struct ixgbe_mac_operations ops;
34997 + ixgbe_mac_operations_no_const ops;
34998 u8 addr[6];
34999 u8 perm_addr[6];
35000
35001 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35002 s32 (*check_for_ack)(struct ixgbe_hw *);
35003 s32 (*check_for_rst)(struct ixgbe_hw *);
35004 };
35005 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35006
35007 struct ixgbe_mbx_stats {
35008 u32 msgs_tx;
35009 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35010 };
35011
35012 struct ixgbe_mbx_info {
35013 - struct ixgbe_mbx_operations ops;
35014 + ixgbe_mbx_operations_no_const ops;
35015 struct ixgbe_mbx_stats stats;
35016 u32 timeout;
35017 u32 udelay;
35018 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35019 index 9e0c1ee..8471f77 100644
35020 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35021 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35022 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35023 void (*link_down)(struct __vxge_hw_device *devh);
35024 void (*crit_err)(struct __vxge_hw_device *devh,
35025 enum vxge_hw_event type, u64 ext_data);
35026 -};
35027 +} __no_const;
35028
35029 /*
35030 * struct __vxge_hw_blockpool_entry - Block private data structure
35031 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35032 index 4a518a3..936b334 100644
35033 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35034 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35035 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35036 struct vxge_hw_mempool_dma *dma_object,
35037 u32 index,
35038 u32 is_last);
35039 -};
35040 +} __no_const;
35041
35042 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35043 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35044 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35045 index 927aa33..a6c2518 100644
35046 --- a/drivers/net/ethernet/realtek/r8169.c
35047 +++ b/drivers/net/ethernet/realtek/r8169.c
35048 @@ -747,22 +747,22 @@ struct rtl8169_private {
35049 struct mdio_ops {
35050 void (*write)(struct rtl8169_private *, int, int);
35051 int (*read)(struct rtl8169_private *, int);
35052 - } mdio_ops;
35053 + } __no_const mdio_ops;
35054
35055 struct pll_power_ops {
35056 void (*down)(struct rtl8169_private *);
35057 void (*up)(struct rtl8169_private *);
35058 - } pll_power_ops;
35059 + } __no_const pll_power_ops;
35060
35061 struct jumbo_ops {
35062 void (*enable)(struct rtl8169_private *);
35063 void (*disable)(struct rtl8169_private *);
35064 - } jumbo_ops;
35065 + } __no_const jumbo_ops;
35066
35067 struct csi_ops {
35068 void (*write)(struct rtl8169_private *, int, int);
35069 u32 (*read)(struct rtl8169_private *, int);
35070 - } csi_ops;
35071 + } __no_const csi_ops;
35072
35073 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35074 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35075 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
35076 index 0767043f..08c2553 100644
35077 --- a/drivers/net/ethernet/sfc/ptp.c
35078 +++ b/drivers/net/ethernet/sfc/ptp.c
35079 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
35080 (u32)((u64)ptp->start.dma_addr >> 32));
35081
35082 /* Clear flag that signals MC ready */
35083 - ACCESS_ONCE(*start) = 0;
35084 + ACCESS_ONCE_RW(*start) = 0;
35085 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
35086 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
35087
35088 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35089 index 0c74a70..3bc6f68 100644
35090 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35091 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35092 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35093
35094 writel(value, ioaddr + MMC_CNTRL);
35095
35096 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35097 - MMC_CNTRL, value);
35098 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35099 +// MMC_CNTRL, value);
35100 }
35101
35102 /* To mask all all interrupts.*/
35103 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35104 index 5fd6f46..ee1f265 100644
35105 --- a/drivers/net/hyperv/hyperv_net.h
35106 +++ b/drivers/net/hyperv/hyperv_net.h
35107 @@ -101,7 +101,7 @@ struct rndis_device {
35108
35109 enum rndis_device_state state;
35110 bool link_state;
35111 - atomic_t new_req_id;
35112 + atomic_unchecked_t new_req_id;
35113
35114 spinlock_t request_lock;
35115 struct list_head req_list;
35116 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35117 index 928148c..d83298e 100644
35118 --- a/drivers/net/hyperv/rndis_filter.c
35119 +++ b/drivers/net/hyperv/rndis_filter.c
35120 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35121 * template
35122 */
35123 set = &rndis_msg->msg.set_req;
35124 - set->req_id = atomic_inc_return(&dev->new_req_id);
35125 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35126
35127 /* Add to the request list */
35128 spin_lock_irqsave(&dev->request_lock, flags);
35129 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35130
35131 /* Setup the rndis set */
35132 halt = &request->request_msg.msg.halt_req;
35133 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35134 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35135
35136 /* Ignore return since this msg is optional. */
35137 rndis_filter_send_request(dev, request);
35138 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
35139 index 7d39add..037e1da 100644
35140 --- a/drivers/net/ieee802154/fakehard.c
35141 +++ b/drivers/net/ieee802154/fakehard.c
35142 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
35143 phy->transmit_power = 0xbf;
35144
35145 dev->netdev_ops = &fake_ops;
35146 - dev->ml_priv = &fake_mlme;
35147 + dev->ml_priv = (void *)&fake_mlme;
35148
35149 priv = netdev_priv(dev);
35150 priv->phy = phy;
35151 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35152 index daec9b0..6428fcb 100644
35153 --- a/drivers/net/phy/mdio-bitbang.c
35154 +++ b/drivers/net/phy/mdio-bitbang.c
35155 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35156 struct mdiobb_ctrl *ctrl = bus->priv;
35157
35158 module_put(ctrl->ops->owner);
35159 + mdiobus_unregister(bus);
35160 mdiobus_free(bus);
35161 }
35162 EXPORT_SYMBOL(free_mdio_bitbang);
35163 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35164 index eb3f5ce..d773730 100644
35165 --- a/drivers/net/ppp/ppp_generic.c
35166 +++ b/drivers/net/ppp/ppp_generic.c
35167 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35168 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35169 struct ppp_stats stats;
35170 struct ppp_comp_stats cstats;
35171 - char *vers;
35172
35173 switch (cmd) {
35174 case SIOCGPPPSTATS:
35175 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35176 break;
35177
35178 case SIOCGPPPVER:
35179 - vers = PPP_VERSION;
35180 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35181 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35182 break;
35183 err = 0;
35184 break;
35185 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35186 index 0873cdc..ddb178e 100644
35187 --- a/drivers/net/tun.c
35188 +++ b/drivers/net/tun.c
35189 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35190 }
35191
35192 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35193 - unsigned long arg, int ifreq_len)
35194 + unsigned long arg, size_t ifreq_len)
35195 {
35196 struct tun_file *tfile = file->private_data;
35197 struct tun_struct *tun;
35198 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35199 int vnet_hdr_sz;
35200 int ret;
35201
35202 + if (ifreq_len > sizeof ifr)
35203 + return -EFAULT;
35204 +
35205 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35206 if (copy_from_user(&ifr, argp, ifreq_len))
35207 return -EFAULT;
35208 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35209 index 605a4ba..a883dd1 100644
35210 --- a/drivers/net/usb/hso.c
35211 +++ b/drivers/net/usb/hso.c
35212 @@ -71,7 +71,7 @@
35213 #include <asm/byteorder.h>
35214 #include <linux/serial_core.h>
35215 #include <linux/serial.h>
35216 -
35217 +#include <asm/local.h>
35218
35219 #define MOD_AUTHOR "Option Wireless"
35220 #define MOD_DESCRIPTION "USB High Speed Option driver"
35221 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35222 struct urb *urb;
35223
35224 urb = serial->rx_urb[0];
35225 - if (serial->port.count > 0) {
35226 + if (atomic_read(&serial->port.count) > 0) {
35227 count = put_rxbuf_data(urb, serial);
35228 if (count == -1)
35229 return;
35230 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35231 DUMP1(urb->transfer_buffer, urb->actual_length);
35232
35233 /* Anyone listening? */
35234 - if (serial->port.count == 0)
35235 + if (atomic_read(&serial->port.count) == 0)
35236 return;
35237
35238 if (status == 0) {
35239 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35240 tty_port_tty_set(&serial->port, tty);
35241
35242 /* check for port already opened, if not set the termios */
35243 - serial->port.count++;
35244 - if (serial->port.count == 1) {
35245 + if (atomic_inc_return(&serial->port.count) == 1) {
35246 serial->rx_state = RX_IDLE;
35247 /* Force default termio settings */
35248 _hso_serial_set_termios(tty, NULL);
35249 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35250 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35251 if (result) {
35252 hso_stop_serial_device(serial->parent);
35253 - serial->port.count--;
35254 + atomic_dec(&serial->port.count);
35255 kref_put(&serial->parent->ref, hso_serial_ref_free);
35256 }
35257 } else {
35258 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35259
35260 /* reset the rts and dtr */
35261 /* do the actual close */
35262 - serial->port.count--;
35263 + atomic_dec(&serial->port.count);
35264
35265 - if (serial->port.count <= 0) {
35266 - serial->port.count = 0;
35267 + if (atomic_read(&serial->port.count) <= 0) {
35268 + atomic_set(&serial->port.count, 0);
35269 tty_port_tty_set(&serial->port, NULL);
35270 if (!usb_gone)
35271 hso_stop_serial_device(serial->parent);
35272 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35273
35274 /* the actual setup */
35275 spin_lock_irqsave(&serial->serial_lock, flags);
35276 - if (serial->port.count)
35277 + if (atomic_read(&serial->port.count))
35278 _hso_serial_set_termios(tty, old);
35279 else
35280 tty->termios = *old;
35281 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
35282 D1("Pending read interrupt on port %d\n", i);
35283 spin_lock(&serial->serial_lock);
35284 if (serial->rx_state == RX_IDLE &&
35285 - serial->port.count > 0) {
35286 + atomic_read(&serial->port.count) > 0) {
35287 /* Setup and send a ctrl req read on
35288 * port i */
35289 if (!serial->rx_urb_filled[0]) {
35290 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
35291 /* Start all serial ports */
35292 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35293 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35294 - if (dev2ser(serial_table[i])->port.count) {
35295 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35296 result =
35297 hso_start_serial_device(serial_table[i], GFP_NOIO);
35298 hso_kick_transmit(dev2ser(serial_table[i]));
35299 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35300 index 4521342..9f0a994d 100644
35301 --- a/drivers/net/wireless/ath/ath.h
35302 +++ b/drivers/net/wireless/ath/ath.h
35303 @@ -119,6 +119,7 @@ struct ath_ops {
35304 void (*write_flush) (void *);
35305 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35306 };
35307 +typedef struct ath_ops __no_const ath_ops_no_const;
35308
35309 struct ath_common;
35310 struct ath_bus_ops;
35311 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35312 index 8d78253..bebbb68 100644
35313 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35314 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35315 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35316 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35317 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35318
35319 - ACCESS_ONCE(ads->ds_link) = i->link;
35320 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35321 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35322 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35323
35324 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35325 ctl6 = SM(i->keytype, AR_EncrType);
35326 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35327
35328 if ((i->is_first || i->is_last) &&
35329 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35330 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35331 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35332 | set11nTries(i->rates, 1)
35333 | set11nTries(i->rates, 2)
35334 | set11nTries(i->rates, 3)
35335 | (i->dur_update ? AR_DurUpdateEna : 0)
35336 | SM(0, AR_BurstDur);
35337
35338 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35339 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35340 | set11nRate(i->rates, 1)
35341 | set11nRate(i->rates, 2)
35342 | set11nRate(i->rates, 3);
35343 } else {
35344 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35345 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35346 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35347 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35348 }
35349
35350 if (!i->is_first) {
35351 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35352 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35353 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35354 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35355 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35356 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35357 return;
35358 }
35359
35360 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35361 break;
35362 }
35363
35364 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35365 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35366 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35367 | SM(i->txpower, AR_XmitPower)
35368 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35369 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35370 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35371 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35372
35373 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35374 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35375 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35376 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35377
35378 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35379 return;
35380
35381 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35382 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35383 | set11nPktDurRTSCTS(i->rates, 1);
35384
35385 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35386 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35387 | set11nPktDurRTSCTS(i->rates, 3);
35388
35389 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35390 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35391 | set11nRateFlags(i->rates, 1)
35392 | set11nRateFlags(i->rates, 2)
35393 | set11nRateFlags(i->rates, 3)
35394 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35395 index 301bf72..3f5654f 100644
35396 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35397 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35398 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35399 (i->qcu << AR_TxQcuNum_S) | desc_len;
35400
35401 checksum += val;
35402 - ACCESS_ONCE(ads->info) = val;
35403 + ACCESS_ONCE_RW(ads->info) = val;
35404
35405 checksum += i->link;
35406 - ACCESS_ONCE(ads->link) = i->link;
35407 + ACCESS_ONCE_RW(ads->link) = i->link;
35408
35409 checksum += i->buf_addr[0];
35410 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35411 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35412 checksum += i->buf_addr[1];
35413 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35414 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35415 checksum += i->buf_addr[2];
35416 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35417 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35418 checksum += i->buf_addr[3];
35419 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35420 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35421
35422 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35423 - ACCESS_ONCE(ads->ctl3) = val;
35424 + ACCESS_ONCE_RW(ads->ctl3) = val;
35425 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35426 - ACCESS_ONCE(ads->ctl5) = val;
35427 + ACCESS_ONCE_RW(ads->ctl5) = val;
35428 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35429 - ACCESS_ONCE(ads->ctl7) = val;
35430 + ACCESS_ONCE_RW(ads->ctl7) = val;
35431 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35432 - ACCESS_ONCE(ads->ctl9) = val;
35433 + ACCESS_ONCE_RW(ads->ctl9) = val;
35434
35435 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35436 - ACCESS_ONCE(ads->ctl10) = checksum;
35437 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35438
35439 if (i->is_first || i->is_last) {
35440 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35441 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35442 | set11nTries(i->rates, 1)
35443 | set11nTries(i->rates, 2)
35444 | set11nTries(i->rates, 3)
35445 | (i->dur_update ? AR_DurUpdateEna : 0)
35446 | SM(0, AR_BurstDur);
35447
35448 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35449 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35450 | set11nRate(i->rates, 1)
35451 | set11nRate(i->rates, 2)
35452 | set11nRate(i->rates, 3);
35453 } else {
35454 - ACCESS_ONCE(ads->ctl13) = 0;
35455 - ACCESS_ONCE(ads->ctl14) = 0;
35456 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35457 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35458 }
35459
35460 ads->ctl20 = 0;
35461 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35462
35463 ctl17 = SM(i->keytype, AR_EncrType);
35464 if (!i->is_first) {
35465 - ACCESS_ONCE(ads->ctl11) = 0;
35466 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35467 - ACCESS_ONCE(ads->ctl15) = 0;
35468 - ACCESS_ONCE(ads->ctl16) = 0;
35469 - ACCESS_ONCE(ads->ctl17) = ctl17;
35470 - ACCESS_ONCE(ads->ctl18) = 0;
35471 - ACCESS_ONCE(ads->ctl19) = 0;
35472 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35473 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35474 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35475 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35476 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35477 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35478 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35479 return;
35480 }
35481
35482 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35483 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35484 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35485 | SM(i->txpower, AR_XmitPower)
35486 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35487 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35488 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35489 ctl12 |= SM(val, AR_PAPRDChainMask);
35490
35491 - ACCESS_ONCE(ads->ctl12) = ctl12;
35492 - ACCESS_ONCE(ads->ctl17) = ctl17;
35493 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35494 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35495
35496 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35497 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35498 | set11nPktDurRTSCTS(i->rates, 1);
35499
35500 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35501 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35502 | set11nPktDurRTSCTS(i->rates, 3);
35503
35504 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35505 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35506 | set11nRateFlags(i->rates, 1)
35507 | set11nRateFlags(i->rates, 2)
35508 | set11nRateFlags(i->rates, 3)
35509 | SM(i->rtscts_rate, AR_RTSCTSRate);
35510
35511 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35512 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35513 }
35514
35515 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35516 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35517 index dbc1b7a..addccc0 100644
35518 --- a/drivers/net/wireless/ath/ath9k/hw.h
35519 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35520 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
35521
35522 /* ANI */
35523 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35524 -};
35525 +} __no_const;
35526
35527 /**
35528 * struct ath_hw_ops - callbacks used by hardware code and driver code
35529 @@ -687,7 +687,7 @@ struct ath_hw_ops {
35530 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35531 struct ath_hw_antcomb_conf *antconf);
35532 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
35533 -};
35534 +} __no_const;
35535
35536 struct ath_nf_limits {
35537 s16 max;
35538 @@ -707,7 +707,7 @@ enum ath_cal_list {
35539 #define AH_FASTCC 0x4
35540
35541 struct ath_hw {
35542 - struct ath_ops reg_ops;
35543 + ath_ops_no_const reg_ops;
35544
35545 struct ieee80211_hw *hw;
35546 struct ath_common common;
35547 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35548 index af00e2c..ab04d34 100644
35549 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35550 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35551 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35552 void (*carrsuppr)(struct brcms_phy *);
35553 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35554 void (*detach)(struct brcms_phy *);
35555 -};
35556 +} __no_const;
35557
35558 struct brcms_phy {
35559 struct brcms_phy_pub pubpi_ro;
35560 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35561 index e252acb..6ad1e65 100644
35562 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35563 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35564 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35565 */
35566 if (il3945_mod_params.disable_hw_scan) {
35567 D_INFO("Disabling hw_scan\n");
35568 - il3945_mac_ops.hw_scan = NULL;
35569 + pax_open_kernel();
35570 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35571 + pax_close_kernel();
35572 }
35573
35574 D_INFO("*** LOAD DRIVER ***\n");
35575 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35576 index 1a98fa3..51e6661 100644
35577 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35578 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35579 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35580 {
35581 struct iwl_priv *priv = file->private_data;
35582 char buf[64];
35583 - int buf_size;
35584 + size_t buf_size;
35585 u32 offset, len;
35586
35587 memset(buf, 0, sizeof(buf));
35588 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35589 struct iwl_priv *priv = file->private_data;
35590
35591 char buf[8];
35592 - int buf_size;
35593 + size_t buf_size;
35594 u32 reset_flag;
35595
35596 memset(buf, 0, sizeof(buf));
35597 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35598 {
35599 struct iwl_priv *priv = file->private_data;
35600 char buf[8];
35601 - int buf_size;
35602 + size_t buf_size;
35603 int ht40;
35604
35605 memset(buf, 0, sizeof(buf));
35606 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35607 {
35608 struct iwl_priv *priv = file->private_data;
35609 char buf[8];
35610 - int buf_size;
35611 + size_t buf_size;
35612 int value;
35613
35614 memset(buf, 0, sizeof(buf));
35615 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35616 {
35617 struct iwl_priv *priv = file->private_data;
35618 char buf[8];
35619 - int buf_size;
35620 + size_t buf_size;
35621 int clear;
35622
35623 memset(buf, 0, sizeof(buf));
35624 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35625 {
35626 struct iwl_priv *priv = file->private_data;
35627 char buf[8];
35628 - int buf_size;
35629 + size_t buf_size;
35630 int trace;
35631
35632 memset(buf, 0, sizeof(buf));
35633 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35634 {
35635 struct iwl_priv *priv = file->private_data;
35636 char buf[8];
35637 - int buf_size;
35638 + size_t buf_size;
35639 int missed;
35640
35641 memset(buf, 0, sizeof(buf));
35642 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35643
35644 struct iwl_priv *priv = file->private_data;
35645 char buf[8];
35646 - int buf_size;
35647 + size_t buf_size;
35648 int plcp;
35649
35650 memset(buf, 0, sizeof(buf));
35651 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35652
35653 struct iwl_priv *priv = file->private_data;
35654 char buf[8];
35655 - int buf_size;
35656 + size_t buf_size;
35657 int flush;
35658
35659 memset(buf, 0, sizeof(buf));
35660 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35661
35662 struct iwl_priv *priv = file->private_data;
35663 char buf[8];
35664 - int buf_size;
35665 + size_t buf_size;
35666 int rts;
35667
35668 if (!priv->cfg->ht_params)
35669 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35670 {
35671 struct iwl_priv *priv = file->private_data;
35672 char buf[8];
35673 - int buf_size;
35674 + size_t buf_size;
35675
35676 memset(buf, 0, sizeof(buf));
35677 buf_size = min(count, sizeof(buf) - 1);
35678 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35679 struct iwl_priv *priv = file->private_data;
35680 u32 event_log_flag;
35681 char buf[8];
35682 - int buf_size;
35683 + size_t buf_size;
35684
35685 /* check that the interface is up */
35686 if (!iwl_is_ready(priv))
35687 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35688 struct iwl_priv *priv = file->private_data;
35689 char buf[8];
35690 u32 calib_disabled;
35691 - int buf_size;
35692 + size_t buf_size;
35693
35694 memset(buf, 0, sizeof(buf));
35695 buf_size = min(count, sizeof(buf) - 1);
35696 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35697 index fe0fffd..b4c5724 100644
35698 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35699 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35700 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35701 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35702
35703 char buf[8];
35704 - int buf_size;
35705 + size_t buf_size;
35706 u32 reset_flag;
35707
35708 memset(buf, 0, sizeof(buf));
35709 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35710 {
35711 struct iwl_trans *trans = file->private_data;
35712 char buf[8];
35713 - int buf_size;
35714 + size_t buf_size;
35715 int csr;
35716
35717 memset(buf, 0, sizeof(buf));
35718 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35719 index 429ca32..f86236b 100644
35720 --- a/drivers/net/wireless/mac80211_hwsim.c
35721 +++ b/drivers/net/wireless/mac80211_hwsim.c
35722 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
35723 return -EINVAL;
35724
35725 if (fake_hw_scan) {
35726 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35727 - mac80211_hwsim_ops.sw_scan_start = NULL;
35728 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35729 + pax_open_kernel();
35730 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35731 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35732 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35733 + pax_close_kernel();
35734 }
35735
35736 spin_lock_init(&hwsim_radio_lock);
35737 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35738 index c2d0ab1..fb9afe2 100644
35739 --- a/drivers/net/wireless/mwifiex/main.h
35740 +++ b/drivers/net/wireless/mwifiex/main.h
35741 @@ -603,7 +603,7 @@ struct mwifiex_if_ops {
35742 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35743 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35744 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35745 -};
35746 +} __no_const;
35747
35748 struct mwifiex_adapter {
35749 u8 iface_type;
35750 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35751 index bd1f0cb..db85ab0 100644
35752 --- a/drivers/net/wireless/rndis_wlan.c
35753 +++ b/drivers/net/wireless/rndis_wlan.c
35754 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35755
35756 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35757
35758 - if (rts_threshold < 0 || rts_threshold > 2347)
35759 + if (rts_threshold > 2347)
35760 rts_threshold = 2347;
35761
35762 tmp = cpu_to_le32(rts_threshold);
35763 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35764 index 0751b35..246ba3e 100644
35765 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35766 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35767 @@ -398,7 +398,7 @@ struct rt2x00_intf {
35768 * for hardware which doesn't support hardware
35769 * sequence counting.
35770 */
35771 - atomic_t seqno;
35772 + atomic_unchecked_t seqno;
35773 };
35774
35775 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35776 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35777 index e488b94..14b6a0c 100644
35778 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35779 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35780 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35781 * sequence counter given by mac80211.
35782 */
35783 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35784 - seqno = atomic_add_return(0x10, &intf->seqno);
35785 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35786 else
35787 - seqno = atomic_read(&intf->seqno);
35788 + seqno = atomic_read_unchecked(&intf->seqno);
35789
35790 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35791 hdr->seq_ctrl |= cpu_to_le16(seqno);
35792 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35793 index fd02060..74ee481 100644
35794 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35795 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35796 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35797 void (*reset)(struct wl1251 *wl);
35798 void (*enable_irq)(struct wl1251 *wl);
35799 void (*disable_irq)(struct wl1251 *wl);
35800 -};
35801 +} __no_const;
35802
35803 struct wl1251 {
35804 struct ieee80211_hw *hw;
35805 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35806 index 68584aa..10fc178 100644
35807 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35808 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35809 @@ -88,7 +88,7 @@ struct wlcore_ops {
35810 struct ieee80211_sta *sta,
35811 struct ieee80211_key_conf *key_conf);
35812 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
35813 -};
35814 +} __no_const;
35815
35816 enum wlcore_partitions {
35817 PART_DOWN,
35818 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35819 index d93b2b6..ae50401 100644
35820 --- a/drivers/oprofile/buffer_sync.c
35821 +++ b/drivers/oprofile/buffer_sync.c
35822 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35823 if (cookie == NO_COOKIE)
35824 offset = pc;
35825 if (cookie == INVALID_COOKIE) {
35826 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35827 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35828 offset = pc;
35829 }
35830 if (cookie != last_cookie) {
35831 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35832 /* add userspace sample */
35833
35834 if (!mm) {
35835 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35836 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35837 return 0;
35838 }
35839
35840 cookie = lookup_dcookie(mm, s->eip, &offset);
35841
35842 if (cookie == INVALID_COOKIE) {
35843 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35844 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35845 return 0;
35846 }
35847
35848 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
35849 /* ignore backtraces if failed to add a sample */
35850 if (state == sb_bt_start) {
35851 state = sb_bt_ignore;
35852 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35853 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35854 }
35855 }
35856 release_mm(mm);
35857 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35858 index c0cc4e7..44d4e54 100644
35859 --- a/drivers/oprofile/event_buffer.c
35860 +++ b/drivers/oprofile/event_buffer.c
35861 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35862 }
35863
35864 if (buffer_pos == buffer_size) {
35865 - atomic_inc(&oprofile_stats.event_lost_overflow);
35866 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35867 return;
35868 }
35869
35870 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35871 index ed2c3ec..deda85a 100644
35872 --- a/drivers/oprofile/oprof.c
35873 +++ b/drivers/oprofile/oprof.c
35874 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35875 if (oprofile_ops.switch_events())
35876 return;
35877
35878 - atomic_inc(&oprofile_stats.multiplex_counter);
35879 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35880 start_switch_worker();
35881 }
35882
35883 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35884 index 917d28e..d62d981 100644
35885 --- a/drivers/oprofile/oprofile_stats.c
35886 +++ b/drivers/oprofile/oprofile_stats.c
35887 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35888 cpu_buf->sample_invalid_eip = 0;
35889 }
35890
35891 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35892 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35893 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35894 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35895 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35896 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35897 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35898 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35899 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35900 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35901 }
35902
35903
35904 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35905 index 38b6fc0..b5cbfce 100644
35906 --- a/drivers/oprofile/oprofile_stats.h
35907 +++ b/drivers/oprofile/oprofile_stats.h
35908 @@ -13,11 +13,11 @@
35909 #include <linux/atomic.h>
35910
35911 struct oprofile_stat_struct {
35912 - atomic_t sample_lost_no_mm;
35913 - atomic_t sample_lost_no_mapping;
35914 - atomic_t bt_lost_no_mapping;
35915 - atomic_t event_lost_overflow;
35916 - atomic_t multiplex_counter;
35917 + atomic_unchecked_t sample_lost_no_mm;
35918 + atomic_unchecked_t sample_lost_no_mapping;
35919 + atomic_unchecked_t bt_lost_no_mapping;
35920 + atomic_unchecked_t event_lost_overflow;
35921 + atomic_unchecked_t multiplex_counter;
35922 };
35923
35924 extern struct oprofile_stat_struct oprofile_stats;
35925 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35926 index 849357c..b83c1e0 100644
35927 --- a/drivers/oprofile/oprofilefs.c
35928 +++ b/drivers/oprofile/oprofilefs.c
35929 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35930
35931
35932 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35933 - char const *name, atomic_t *val)
35934 + char const *name, atomic_unchecked_t *val)
35935 {
35936 return __oprofilefs_create_file(sb, root, name,
35937 &atomic_ro_fops, 0444, val);
35938 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35939 index 3f56bc0..707d642 100644
35940 --- a/drivers/parport/procfs.c
35941 +++ b/drivers/parport/procfs.c
35942 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35943
35944 *ppos += len;
35945
35946 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35947 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35948 }
35949
35950 #ifdef CONFIG_PARPORT_1284
35951 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35952
35953 *ppos += len;
35954
35955 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35956 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35957 }
35958 #endif /* IEEE1284.3 support. */
35959
35960 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35961 index 9fff878..ad0ad53 100644
35962 --- a/drivers/pci/hotplug/cpci_hotplug.h
35963 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35964 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35965 int (*hardware_test) (struct slot* slot, u32 value);
35966 u8 (*get_power) (struct slot* slot);
35967 int (*set_power) (struct slot* slot, int value);
35968 -};
35969 +} __no_const;
35970
35971 struct cpci_hp_controller {
35972 unsigned int irq;
35973 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35974 index 76ba8a1..20ca857 100644
35975 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35976 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35977 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35978
35979 void compaq_nvram_init (void __iomem *rom_start)
35980 {
35981 +
35982 +#ifndef CONFIG_PAX_KERNEXEC
35983 if (rom_start) {
35984 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35985 }
35986 +#endif
35987 +
35988 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35989
35990 /* initialize our int15 lock */
35991 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35992 index 213753b..b4abaac 100644
35993 --- a/drivers/pci/pcie/aspm.c
35994 +++ b/drivers/pci/pcie/aspm.c
35995 @@ -27,9 +27,9 @@
35996 #define MODULE_PARAM_PREFIX "pcie_aspm."
35997
35998 /* Note: those are not register definitions */
35999 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36000 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36001 -#define ASPM_STATE_L1 (4) /* L1 state */
36002 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36003 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36004 +#define ASPM_STATE_L1 (4U) /* L1 state */
36005 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36006 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36007
36008 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36009 index ec909af..e7517f3 100644
36010 --- a/drivers/pci/probe.c
36011 +++ b/drivers/pci/probe.c
36012 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36013 struct pci_bus_region region;
36014 bool bar_too_big = false, bar_disabled = false;
36015
36016 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36017 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36018
36019 /* No printks while decoding is disabled! */
36020 if (!dev->mmio_always_on) {
36021 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36022 index 9b8505c..f00870a 100644
36023 --- a/drivers/pci/proc.c
36024 +++ b/drivers/pci/proc.c
36025 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36026 static int __init pci_proc_init(void)
36027 {
36028 struct pci_dev *dev = NULL;
36029 +
36030 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36031 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36032 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36033 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36034 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36035 +#endif
36036 +#else
36037 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36038 +#endif
36039 proc_create("devices", 0, proc_bus_pci_dir,
36040 &proc_bus_pci_dev_operations);
36041 proc_initialized = 1;
36042 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36043 index 75dd651..2af4c9a 100644
36044 --- a/drivers/platform/x86/thinkpad_acpi.c
36045 +++ b/drivers/platform/x86/thinkpad_acpi.c
36046 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36047 return 0;
36048 }
36049
36050 -void static hotkey_mask_warn_incomplete_mask(void)
36051 +static void hotkey_mask_warn_incomplete_mask(void)
36052 {
36053 /* log only what the user can fix... */
36054 const u32 wantedmask = hotkey_driver_mask &
36055 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36056 }
36057 }
36058
36059 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36060 - struct tp_nvram_state *newn,
36061 - const u32 event_mask)
36062 -{
36063 -
36064 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36065 do { \
36066 if ((event_mask & (1 << __scancode)) && \
36067 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36068 tpacpi_hotkey_send_key(__scancode); \
36069 } while (0)
36070
36071 - void issue_volchange(const unsigned int oldvol,
36072 - const unsigned int newvol)
36073 - {
36074 - unsigned int i = oldvol;
36075 +static void issue_volchange(const unsigned int oldvol,
36076 + const unsigned int newvol,
36077 + const u32 event_mask)
36078 +{
36079 + unsigned int i = oldvol;
36080
36081 - while (i > newvol) {
36082 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36083 - i--;
36084 - }
36085 - while (i < newvol) {
36086 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36087 - i++;
36088 - }
36089 + while (i > newvol) {
36090 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36091 + i--;
36092 }
36093 + while (i < newvol) {
36094 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36095 + i++;
36096 + }
36097 +}
36098
36099 - void issue_brightnesschange(const unsigned int oldbrt,
36100 - const unsigned int newbrt)
36101 - {
36102 - unsigned int i = oldbrt;
36103 +static void issue_brightnesschange(const unsigned int oldbrt,
36104 + const unsigned int newbrt,
36105 + const u32 event_mask)
36106 +{
36107 + unsigned int i = oldbrt;
36108
36109 - while (i > newbrt) {
36110 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36111 - i--;
36112 - }
36113 - while (i < newbrt) {
36114 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36115 - i++;
36116 - }
36117 + while (i > newbrt) {
36118 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36119 + i--;
36120 + }
36121 + while (i < newbrt) {
36122 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36123 + i++;
36124 }
36125 +}
36126
36127 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36128 + struct tp_nvram_state *newn,
36129 + const u32 event_mask)
36130 +{
36131 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36132 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36133 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36134 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36135 oldn->volume_level != newn->volume_level) {
36136 /* recently muted, or repeated mute keypress, or
36137 * multiple presses ending in mute */
36138 - issue_volchange(oldn->volume_level, newn->volume_level);
36139 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36140 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36141 }
36142 } else {
36143 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36144 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36145 }
36146 if (oldn->volume_level != newn->volume_level) {
36147 - issue_volchange(oldn->volume_level, newn->volume_level);
36148 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36149 } else if (oldn->volume_toggle != newn->volume_toggle) {
36150 /* repeated vol up/down keypress at end of scale ? */
36151 if (newn->volume_level == 0)
36152 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36153 /* handle brightness */
36154 if (oldn->brightness_level != newn->brightness_level) {
36155 issue_brightnesschange(oldn->brightness_level,
36156 - newn->brightness_level);
36157 + newn->brightness_level,
36158 + event_mask);
36159 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36160 /* repeated key presses that didn't change state */
36161 if (newn->brightness_level == 0)
36162 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36163 && !tp_features.bright_unkfw)
36164 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36165 }
36166 +}
36167
36168 #undef TPACPI_COMPARE_KEY
36169 #undef TPACPI_MAY_SEND_KEY
36170 -}
36171
36172 /*
36173 * Polling driver
36174 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36175 index 769d265..a3a05ca 100644
36176 --- a/drivers/pnp/pnpbios/bioscalls.c
36177 +++ b/drivers/pnp/pnpbios/bioscalls.c
36178 @@ -58,7 +58,7 @@ do { \
36179 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36180 } while(0)
36181
36182 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36183 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36184 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36185
36186 /*
36187 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36188
36189 cpu = get_cpu();
36190 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36191 +
36192 + pax_open_kernel();
36193 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36194 + pax_close_kernel();
36195
36196 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36197 spin_lock_irqsave(&pnp_bios_lock, flags);
36198 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36199 :"memory");
36200 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36201
36202 + pax_open_kernel();
36203 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36204 + pax_close_kernel();
36205 +
36206 put_cpu();
36207
36208 /* If we get here and this is set then the PnP BIOS faulted on us. */
36209 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36210 return status;
36211 }
36212
36213 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36214 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36215 {
36216 int i;
36217
36218 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36219 pnp_bios_callpoint.offset = header->fields.pm16offset;
36220 pnp_bios_callpoint.segment = PNP_CS16;
36221
36222 + pax_open_kernel();
36223 +
36224 for_each_possible_cpu(i) {
36225 struct desc_struct *gdt = get_cpu_gdt_table(i);
36226 if (!gdt)
36227 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36228 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36229 (unsigned long)__va(header->fields.pm16dseg));
36230 }
36231 +
36232 + pax_close_kernel();
36233 }
36234 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36235 index b0ecacb..7c9da2e 100644
36236 --- a/drivers/pnp/resource.c
36237 +++ b/drivers/pnp/resource.c
36238 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36239 return 1;
36240
36241 /* check if the resource is valid */
36242 - if (*irq < 0 || *irq > 15)
36243 + if (*irq > 15)
36244 return 0;
36245
36246 /* check if the resource is reserved */
36247 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36248 return 1;
36249
36250 /* check if the resource is valid */
36251 - if (*dma < 0 || *dma == 4 || *dma > 7)
36252 + if (*dma == 4 || *dma > 7)
36253 return 0;
36254
36255 /* check if the resource is reserved */
36256 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36257 index 5860d4d..d90d268 100644
36258 --- a/drivers/power/bq27x00_battery.c
36259 +++ b/drivers/power/bq27x00_battery.c
36260 @@ -80,7 +80,7 @@
36261 struct bq27x00_device_info;
36262 struct bq27x00_access_methods {
36263 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36264 -};
36265 +} __no_const;
36266
36267 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36268
36269 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36270 index 8d53174..04c65de 100644
36271 --- a/drivers/regulator/max8660.c
36272 +++ b/drivers/regulator/max8660.c
36273 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36274 max8660->shadow_regs[MAX8660_OVER1] = 5;
36275 } else {
36276 /* Otherwise devices can be toggled via software */
36277 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36278 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36279 + pax_open_kernel();
36280 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36281 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36282 + pax_close_kernel();
36283 }
36284
36285 /*
36286 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36287 index 1fa6381..f58834e 100644
36288 --- a/drivers/regulator/mc13892-regulator.c
36289 +++ b/drivers/regulator/mc13892-regulator.c
36290 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36291 }
36292 mc13xxx_unlock(mc13892);
36293
36294 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36295 + pax_open_kernel();
36296 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36297 = mc13892_vcam_set_mode;
36298 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36299 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36300 = mc13892_vcam_get_mode;
36301 + pax_close_kernel();
36302
36303 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36304 ARRAY_SIZE(mc13892_regulators));
36305 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36306 index cace6d3..f623fda 100644
36307 --- a/drivers/rtc/rtc-dev.c
36308 +++ b/drivers/rtc/rtc-dev.c
36309 @@ -14,6 +14,7 @@
36310 #include <linux/module.h>
36311 #include <linux/rtc.h>
36312 #include <linux/sched.h>
36313 +#include <linux/grsecurity.h>
36314 #include "rtc-core.h"
36315
36316 static dev_t rtc_devt;
36317 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36318 if (copy_from_user(&tm, uarg, sizeof(tm)))
36319 return -EFAULT;
36320
36321 + gr_log_timechange();
36322 +
36323 return rtc_set_time(rtc, &tm);
36324
36325 case RTC_PIE_ON:
36326 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36327 index 9e933a8..4f969f7 100644
36328 --- a/drivers/scsi/aacraid/aacraid.h
36329 +++ b/drivers/scsi/aacraid/aacraid.h
36330 @@ -503,7 +503,7 @@ struct adapter_ops
36331 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36332 /* Administrative operations */
36333 int (*adapter_comm)(struct aac_dev * dev, int comm);
36334 -};
36335 +} __no_const;
36336
36337 /*
36338 * Define which interrupt handler needs to be installed
36339 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36340 index 4ad7e36..d004679 100644
36341 --- a/drivers/scsi/bfa/bfa.h
36342 +++ b/drivers/scsi/bfa/bfa.h
36343 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36344 u32 *end);
36345 int cpe_vec_q0;
36346 int rme_vec_q0;
36347 -};
36348 +} __no_const;
36349 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36350
36351 struct bfa_faa_cbfn_s {
36352 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36353 index 27b5609..e08d9c4 100644
36354 --- a/drivers/scsi/bfa/bfa_fcpim.c
36355 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36356 @@ -3731,7 +3731,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36357
36358 bfa_iotag_attach(fcp);
36359
36360 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36361 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36362 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36363 (fcp->num_itns * sizeof(struct bfa_itn_s));
36364 memset(fcp->itn_arr, 0,
36365 @@ -3799,7 +3799,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36366 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36367 {
36368 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36369 - struct bfa_itn_s *itn;
36370 + bfa_itn_s_no_const *itn;
36371
36372 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36373 itn->isr = isr;
36374 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36375 index e693af6..4faba24 100644
36376 --- a/drivers/scsi/bfa/bfa_fcpim.h
36377 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36378 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36379 struct bfa_itn_s {
36380 bfa_isr_func_t isr;
36381 };
36382 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36383
36384 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36385 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36386 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
36387 struct list_head iotag_tio_free_q; /* free IO resources */
36388 struct list_head iotag_unused_q; /* unused IO resources*/
36389 struct bfa_iotag_s *iotag_arr;
36390 - struct bfa_itn_s *itn_arr;
36391 + bfa_itn_s_no_const *itn_arr;
36392 int max_ioim_reqs;
36393 int num_ioim_reqs;
36394 int num_fwtio_reqs;
36395 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36396 index 23a90e7..9cf04ee 100644
36397 --- a/drivers/scsi/bfa/bfa_ioc.h
36398 +++ b/drivers/scsi/bfa/bfa_ioc.h
36399 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36400 bfa_ioc_disable_cbfn_t disable_cbfn;
36401 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36402 bfa_ioc_reset_cbfn_t reset_cbfn;
36403 -};
36404 +} __no_const;
36405
36406 /*
36407 * IOC event notification mechanism.
36408 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36409 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36410 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36411 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36412 -};
36413 +} __no_const;
36414
36415 /*
36416 * Queue element to wait for room in request queue. FIFO order is
36417 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36418 index 593085a..47aa999 100644
36419 --- a/drivers/scsi/hosts.c
36420 +++ b/drivers/scsi/hosts.c
36421 @@ -42,7 +42,7 @@
36422 #include "scsi_logging.h"
36423
36424
36425 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36426 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36427
36428
36429 static void scsi_host_cls_release(struct device *dev)
36430 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36431 * subtract one because we increment first then return, but we need to
36432 * know what the next host number was before increment
36433 */
36434 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36435 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36436 shost->dma_channel = 0xff;
36437
36438 /* These three are default values which can be overridden */
36439 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36440 index 4217e49..9c77e3e 100644
36441 --- a/drivers/scsi/hpsa.c
36442 +++ b/drivers/scsi/hpsa.c
36443 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36444 unsigned long flags;
36445
36446 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36447 - return h->access.command_completed(h, q);
36448 + return h->access->command_completed(h, q);
36449
36450 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36451 a = rq->head[rq->current_entry];
36452 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
36453 while (!list_empty(&h->reqQ)) {
36454 c = list_entry(h->reqQ.next, struct CommandList, list);
36455 /* can't do anything if fifo is full */
36456 - if ((h->access.fifo_full(h))) {
36457 + if ((h->access->fifo_full(h))) {
36458 dev_warn(&h->pdev->dev, "fifo full\n");
36459 break;
36460 }
36461 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
36462
36463 /* Tell the controller execute command */
36464 spin_unlock_irqrestore(&h->lock, flags);
36465 - h->access.submit_command(h, c);
36466 + h->access->submit_command(h, c);
36467 spin_lock_irqsave(&h->lock, flags);
36468 }
36469 spin_unlock_irqrestore(&h->lock, flags);
36470 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
36471
36472 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36473 {
36474 - return h->access.command_completed(h, q);
36475 + return h->access->command_completed(h, q);
36476 }
36477
36478 static inline bool interrupt_pending(struct ctlr_info *h)
36479 {
36480 - return h->access.intr_pending(h);
36481 + return h->access->intr_pending(h);
36482 }
36483
36484 static inline long interrupt_not_for_us(struct ctlr_info *h)
36485 {
36486 - return (h->access.intr_pending(h) == 0) ||
36487 + return (h->access->intr_pending(h) == 0) ||
36488 (h->interrupts_enabled == 0);
36489 }
36490
36491 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36492 if (prod_index < 0)
36493 return -ENODEV;
36494 h->product_name = products[prod_index].product_name;
36495 - h->access = *(products[prod_index].access);
36496 + h->access = products[prod_index].access;
36497
36498 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36499 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36500 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36501
36502 assert_spin_locked(&lockup_detector_lock);
36503 remove_ctlr_from_lockup_detector_list(h);
36504 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36505 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36506 spin_lock_irqsave(&h->lock, flags);
36507 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36508 spin_unlock_irqrestore(&h->lock, flags);
36509 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
36510 }
36511
36512 /* make sure the board interrupts are off */
36513 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36514 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36515
36516 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36517 goto clean2;
36518 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
36519 * fake ones to scoop up any residual completions.
36520 */
36521 spin_lock_irqsave(&h->lock, flags);
36522 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36523 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36524 spin_unlock_irqrestore(&h->lock, flags);
36525 free_irqs(h);
36526 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36527 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
36528 dev_info(&h->pdev->dev, "Board READY.\n");
36529 dev_info(&h->pdev->dev,
36530 "Waiting for stale completions to drain.\n");
36531 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36532 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36533 msleep(10000);
36534 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36535 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36536
36537 rc = controller_reset_failed(h->cfgtable);
36538 if (rc)
36539 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
36540 }
36541
36542 /* Turn the interrupts on so we can service requests */
36543 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36544 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36545
36546 hpsa_hba_inquiry(h);
36547 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36548 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36549 * To write all data in the battery backed cache to disks
36550 */
36551 hpsa_flush_cache(h);
36552 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36553 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36554 hpsa_free_irqs_and_disable_msix(h);
36555 }
36556
36557 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36558 return;
36559 }
36560 /* Change the access methods to the performant access methods */
36561 - h->access = SA5_performant_access;
36562 + h->access = &SA5_performant_access;
36563 h->transMethod = CFGTBL_Trans_Performant;
36564 }
36565
36566 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36567 index 9816479..c5d4e97 100644
36568 --- a/drivers/scsi/hpsa.h
36569 +++ b/drivers/scsi/hpsa.h
36570 @@ -79,7 +79,7 @@ struct ctlr_info {
36571 unsigned int msix_vector;
36572 unsigned int msi_vector;
36573 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36574 - struct access_method access;
36575 + struct access_method *access;
36576
36577 /* queue and queue Info */
36578 struct list_head reqQ;
36579 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36580 index f2df059..a3a9930 100644
36581 --- a/drivers/scsi/ips.h
36582 +++ b/drivers/scsi/ips.h
36583 @@ -1027,7 +1027,7 @@ typedef struct {
36584 int (*intr)(struct ips_ha *);
36585 void (*enableint)(struct ips_ha *);
36586 uint32_t (*statupd)(struct ips_ha *);
36587 -} ips_hw_func_t;
36588 +} __no_const ips_hw_func_t;
36589
36590 typedef struct ips_ha {
36591 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36592 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36593 index c772d8d..35c362c 100644
36594 --- a/drivers/scsi/libfc/fc_exch.c
36595 +++ b/drivers/scsi/libfc/fc_exch.c
36596 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36597 u16 pool_max_index;
36598
36599 struct {
36600 - atomic_t no_free_exch;
36601 - atomic_t no_free_exch_xid;
36602 - atomic_t xid_not_found;
36603 - atomic_t xid_busy;
36604 - atomic_t seq_not_found;
36605 - atomic_t non_bls_resp;
36606 + atomic_unchecked_t no_free_exch;
36607 + atomic_unchecked_t no_free_exch_xid;
36608 + atomic_unchecked_t xid_not_found;
36609 + atomic_unchecked_t xid_busy;
36610 + atomic_unchecked_t seq_not_found;
36611 + atomic_unchecked_t non_bls_resp;
36612 } stats;
36613 };
36614
36615 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36616 /* allocate memory for exchange */
36617 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36618 if (!ep) {
36619 - atomic_inc(&mp->stats.no_free_exch);
36620 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36621 goto out;
36622 }
36623 memset(ep, 0, sizeof(*ep));
36624 @@ -786,7 +786,7 @@ out:
36625 return ep;
36626 err:
36627 spin_unlock_bh(&pool->lock);
36628 - atomic_inc(&mp->stats.no_free_exch_xid);
36629 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36630 mempool_free(ep, mp->ep_pool);
36631 return NULL;
36632 }
36633 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36634 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36635 ep = fc_exch_find(mp, xid);
36636 if (!ep) {
36637 - atomic_inc(&mp->stats.xid_not_found);
36638 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36639 reject = FC_RJT_OX_ID;
36640 goto out;
36641 }
36642 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36643 ep = fc_exch_find(mp, xid);
36644 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36645 if (ep) {
36646 - atomic_inc(&mp->stats.xid_busy);
36647 + atomic_inc_unchecked(&mp->stats.xid_busy);
36648 reject = FC_RJT_RX_ID;
36649 goto rel;
36650 }
36651 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36652 }
36653 xid = ep->xid; /* get our XID */
36654 } else if (!ep) {
36655 - atomic_inc(&mp->stats.xid_not_found);
36656 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36657 reject = FC_RJT_RX_ID; /* XID not found */
36658 goto out;
36659 }
36660 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36661 } else {
36662 sp = &ep->seq;
36663 if (sp->id != fh->fh_seq_id) {
36664 - atomic_inc(&mp->stats.seq_not_found);
36665 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36666 if (f_ctl & FC_FC_END_SEQ) {
36667 /*
36668 * Update sequence_id based on incoming last
36669 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36670
36671 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36672 if (!ep) {
36673 - atomic_inc(&mp->stats.xid_not_found);
36674 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36675 goto out;
36676 }
36677 if (ep->esb_stat & ESB_ST_COMPLETE) {
36678 - atomic_inc(&mp->stats.xid_not_found);
36679 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36680 goto rel;
36681 }
36682 if (ep->rxid == FC_XID_UNKNOWN)
36683 ep->rxid = ntohs(fh->fh_rx_id);
36684 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36685 - atomic_inc(&mp->stats.xid_not_found);
36686 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36687 goto rel;
36688 }
36689 if (ep->did != ntoh24(fh->fh_s_id) &&
36690 ep->did != FC_FID_FLOGI) {
36691 - atomic_inc(&mp->stats.xid_not_found);
36692 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36693 goto rel;
36694 }
36695 sof = fr_sof(fp);
36696 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36697 sp->ssb_stat |= SSB_ST_RESP;
36698 sp->id = fh->fh_seq_id;
36699 } else if (sp->id != fh->fh_seq_id) {
36700 - atomic_inc(&mp->stats.seq_not_found);
36701 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36702 goto rel;
36703 }
36704
36705 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36706 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36707
36708 if (!sp)
36709 - atomic_inc(&mp->stats.xid_not_found);
36710 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36711 else
36712 - atomic_inc(&mp->stats.non_bls_resp);
36713 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36714
36715 fc_frame_free(fp);
36716 }
36717 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36718
36719 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36720 mp = ema->mp;
36721 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36722 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36723 st->fc_no_free_exch_xid +=
36724 - atomic_read(&mp->stats.no_free_exch_xid);
36725 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36726 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36727 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36728 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36729 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36730 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36731 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36732 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36733 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36734 }
36735 }
36736 EXPORT_SYMBOL(fc_exch_update_stats);
36737 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36738 index bdb81cd..d3c7c2c 100644
36739 --- a/drivers/scsi/libsas/sas_ata.c
36740 +++ b/drivers/scsi/libsas/sas_ata.c
36741 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36742 .postreset = ata_std_postreset,
36743 .error_handler = ata_std_error_handler,
36744 .post_internal_cmd = sas_ata_post_internal,
36745 - .qc_defer = ata_std_qc_defer,
36746 + .qc_defer = ata_std_qc_defer,
36747 .qc_prep = ata_noop_qc_prep,
36748 .qc_issue = sas_ata_qc_issue,
36749 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36750 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36751 index 69b5993..1ac9dce 100644
36752 --- a/drivers/scsi/lpfc/lpfc.h
36753 +++ b/drivers/scsi/lpfc/lpfc.h
36754 @@ -424,7 +424,7 @@ struct lpfc_vport {
36755 struct dentry *debug_nodelist;
36756 struct dentry *vport_debugfs_root;
36757 struct lpfc_debugfs_trc *disc_trc;
36758 - atomic_t disc_trc_cnt;
36759 + atomic_unchecked_t disc_trc_cnt;
36760 #endif
36761 uint8_t stat_data_enabled;
36762 uint8_t stat_data_blocked;
36763 @@ -840,8 +840,8 @@ struct lpfc_hba {
36764 struct timer_list fabric_block_timer;
36765 unsigned long bit_flags;
36766 #define FABRIC_COMANDS_BLOCKED 0
36767 - atomic_t num_rsrc_err;
36768 - atomic_t num_cmd_success;
36769 + atomic_unchecked_t num_rsrc_err;
36770 + atomic_unchecked_t num_cmd_success;
36771 unsigned long last_rsrc_error_time;
36772 unsigned long last_ramp_down_time;
36773 unsigned long last_ramp_up_time;
36774 @@ -877,7 +877,7 @@ struct lpfc_hba {
36775
36776 struct dentry *debug_slow_ring_trc;
36777 struct lpfc_debugfs_trc *slow_ring_trc;
36778 - atomic_t slow_ring_trc_cnt;
36779 + atomic_unchecked_t slow_ring_trc_cnt;
36780 /* iDiag debugfs sub-directory */
36781 struct dentry *idiag_root;
36782 struct dentry *idiag_pci_cfg;
36783 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36784 index f63f5ff..de29189 100644
36785 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36786 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36787 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36788
36789 #include <linux/debugfs.h>
36790
36791 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36792 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36793 static unsigned long lpfc_debugfs_start_time = 0L;
36794
36795 /* iDiag */
36796 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36797 lpfc_debugfs_enable = 0;
36798
36799 len = 0;
36800 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36801 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36802 (lpfc_debugfs_max_disc_trc - 1);
36803 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36804 dtp = vport->disc_trc + i;
36805 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36806 lpfc_debugfs_enable = 0;
36807
36808 len = 0;
36809 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36810 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36811 (lpfc_debugfs_max_slow_ring_trc - 1);
36812 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36813 dtp = phba->slow_ring_trc + i;
36814 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36815 !vport || !vport->disc_trc)
36816 return;
36817
36818 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36819 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36820 (lpfc_debugfs_max_disc_trc - 1);
36821 dtp = vport->disc_trc + index;
36822 dtp->fmt = fmt;
36823 dtp->data1 = data1;
36824 dtp->data2 = data2;
36825 dtp->data3 = data3;
36826 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36827 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36828 dtp->jif = jiffies;
36829 #endif
36830 return;
36831 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36832 !phba || !phba->slow_ring_trc)
36833 return;
36834
36835 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36836 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36837 (lpfc_debugfs_max_slow_ring_trc - 1);
36838 dtp = phba->slow_ring_trc + index;
36839 dtp->fmt = fmt;
36840 dtp->data1 = data1;
36841 dtp->data2 = data2;
36842 dtp->data3 = data3;
36843 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36844 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36845 dtp->jif = jiffies;
36846 #endif
36847 return;
36848 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36849 "slow_ring buffer\n");
36850 goto debug_failed;
36851 }
36852 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36853 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36854 memset(phba->slow_ring_trc, 0,
36855 (sizeof(struct lpfc_debugfs_trc) *
36856 lpfc_debugfs_max_slow_ring_trc));
36857 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36858 "buffer\n");
36859 goto debug_failed;
36860 }
36861 - atomic_set(&vport->disc_trc_cnt, 0);
36862 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36863
36864 snprintf(name, sizeof(name), "discovery_trace");
36865 vport->debug_disc_trc =
36866 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36867 index 7dc4218..3436f08 100644
36868 --- a/drivers/scsi/lpfc/lpfc_init.c
36869 +++ b/drivers/scsi/lpfc/lpfc_init.c
36870 @@ -10589,8 +10589,10 @@ lpfc_init(void)
36871 "misc_register returned with status %d", error);
36872
36873 if (lpfc_enable_npiv) {
36874 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36875 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36876 + pax_open_kernel();
36877 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36878 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36879 + pax_close_kernel();
36880 }
36881 lpfc_transport_template =
36882 fc_attach_transport(&lpfc_transport_functions);
36883 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36884 index 7f45ac9..cf62eda 100644
36885 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36886 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36887 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36888 uint32_t evt_posted;
36889
36890 spin_lock_irqsave(&phba->hbalock, flags);
36891 - atomic_inc(&phba->num_rsrc_err);
36892 + atomic_inc_unchecked(&phba->num_rsrc_err);
36893 phba->last_rsrc_error_time = jiffies;
36894
36895 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36896 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36897 unsigned long flags;
36898 struct lpfc_hba *phba = vport->phba;
36899 uint32_t evt_posted;
36900 - atomic_inc(&phba->num_cmd_success);
36901 + atomic_inc_unchecked(&phba->num_cmd_success);
36902
36903 if (vport->cfg_lun_queue_depth <= queue_depth)
36904 return;
36905 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36906 unsigned long num_rsrc_err, num_cmd_success;
36907 int i;
36908
36909 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36910 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36911 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36912 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36913
36914 /*
36915 * The error and success command counters are global per
36916 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36917 }
36918 }
36919 lpfc_destroy_vport_work_array(phba, vports);
36920 - atomic_set(&phba->num_rsrc_err, 0);
36921 - atomic_set(&phba->num_cmd_success, 0);
36922 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36923 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36924 }
36925
36926 /**
36927 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36928 }
36929 }
36930 lpfc_destroy_vport_work_array(phba, vports);
36931 - atomic_set(&phba->num_rsrc_err, 0);
36932 - atomic_set(&phba->num_cmd_success, 0);
36933 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36934 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36935 }
36936
36937 /**
36938 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36939 index af763ea..41904f7 100644
36940 --- a/drivers/scsi/pmcraid.c
36941 +++ b/drivers/scsi/pmcraid.c
36942 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36943 res->scsi_dev = scsi_dev;
36944 scsi_dev->hostdata = res;
36945 res->change_detected = 0;
36946 - atomic_set(&res->read_failures, 0);
36947 - atomic_set(&res->write_failures, 0);
36948 + atomic_set_unchecked(&res->read_failures, 0);
36949 + atomic_set_unchecked(&res->write_failures, 0);
36950 rc = 0;
36951 }
36952 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36953 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36954
36955 /* If this was a SCSI read/write command keep count of errors */
36956 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36957 - atomic_inc(&res->read_failures);
36958 + atomic_inc_unchecked(&res->read_failures);
36959 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36960 - atomic_inc(&res->write_failures);
36961 + atomic_inc_unchecked(&res->write_failures);
36962
36963 if (!RES_IS_GSCSI(res->cfg_entry) &&
36964 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36965 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36966 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36967 * hrrq_id assigned here in queuecommand
36968 */
36969 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36970 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36971 pinstance->num_hrrq;
36972 cmd->cmd_done = pmcraid_io_done;
36973
36974 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36975 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36976 * hrrq_id assigned here in queuecommand
36977 */
36978 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36979 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36980 pinstance->num_hrrq;
36981
36982 if (request_size) {
36983 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36984
36985 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36986 /* add resources only after host is added into system */
36987 - if (!atomic_read(&pinstance->expose_resources))
36988 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36989 return;
36990
36991 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36992 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36993 init_waitqueue_head(&pinstance->reset_wait_q);
36994
36995 atomic_set(&pinstance->outstanding_cmds, 0);
36996 - atomic_set(&pinstance->last_message_id, 0);
36997 - atomic_set(&pinstance->expose_resources, 0);
36998 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36999 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37000
37001 INIT_LIST_HEAD(&pinstance->free_res_q);
37002 INIT_LIST_HEAD(&pinstance->used_res_q);
37003 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37004 /* Schedule worker thread to handle CCN and take care of adding and
37005 * removing devices to OS
37006 */
37007 - atomic_set(&pinstance->expose_resources, 1);
37008 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37009 schedule_work(&pinstance->worker_q);
37010 return rc;
37011
37012 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37013 index e1d150f..6c6df44 100644
37014 --- a/drivers/scsi/pmcraid.h
37015 +++ b/drivers/scsi/pmcraid.h
37016 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37017 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37018
37019 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37020 - atomic_t last_message_id;
37021 + atomic_unchecked_t last_message_id;
37022
37023 /* configuration table */
37024 struct pmcraid_config_table *cfg_table;
37025 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37026 atomic_t outstanding_cmds;
37027
37028 /* should add/delete resources to mid-layer now ?*/
37029 - atomic_t expose_resources;
37030 + atomic_unchecked_t expose_resources;
37031
37032
37033
37034 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37035 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37036 };
37037 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37038 - atomic_t read_failures; /* count of failed READ commands */
37039 - atomic_t write_failures; /* count of failed WRITE commands */
37040 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37041 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37042
37043 /* To indicate add/delete/modify during CCN */
37044 u8 change_detected;
37045 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37046 index 1c28215..86991a1 100644
37047 --- a/drivers/scsi/qla2xxx/qla_attr.c
37048 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37049 @@ -1970,7 +1970,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37050 return 0;
37051 }
37052
37053 -struct fc_function_template qla2xxx_transport_functions = {
37054 +fc_function_template_no_const qla2xxx_transport_functions = {
37055
37056 .show_host_node_name = 1,
37057 .show_host_port_name = 1,
37058 @@ -2017,7 +2017,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37059 .bsg_timeout = qla24xx_bsg_timeout,
37060 };
37061
37062 -struct fc_function_template qla2xxx_transport_vport_functions = {
37063 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37064
37065 .show_host_node_name = 1,
37066 .show_host_port_name = 1,
37067 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37068 index a9725bf..18eeb73 100644
37069 --- a/drivers/scsi/qla2xxx/qla_def.h
37070 +++ b/drivers/scsi/qla2xxx/qla_def.h
37071 @@ -2385,7 +2385,7 @@ struct isp_operations {
37072 int (*start_scsi) (srb_t *);
37073 int (*abort_isp) (struct scsi_qla_host *);
37074 int (*iospace_config)(struct qla_hw_data*);
37075 -};
37076 +} __no_const;
37077
37078 /* MSI-X Support *************************************************************/
37079
37080 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37081 index 6acb397..d86e3e0 100644
37082 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37083 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37084 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37085 struct device_attribute;
37086 extern struct device_attribute *qla2x00_host_attrs[];
37087 struct fc_function_template;
37088 -extern struct fc_function_template qla2xxx_transport_functions;
37089 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37090 +extern fc_function_template_no_const qla2xxx_transport_functions;
37091 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37092 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37093 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37094 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37095 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37096 index 329d553..f20d31d 100644
37097 --- a/drivers/scsi/qla4xxx/ql4_def.h
37098 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37099 @@ -273,7 +273,7 @@ struct ddb_entry {
37100 * (4000 only) */
37101 atomic_t relogin_timer; /* Max Time to wait for
37102 * relogin to complete */
37103 - atomic_t relogin_retry_count; /* Num of times relogin has been
37104 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37105 * retried */
37106 uint32_t default_time2wait; /* Default Min time between
37107 * relogins (+aens) */
37108 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37109 index fbc546e..c7d1b48 100644
37110 --- a/drivers/scsi/qla4xxx/ql4_os.c
37111 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37112 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37113 */
37114 if (!iscsi_is_session_online(cls_sess)) {
37115 /* Reset retry relogin timer */
37116 - atomic_inc(&ddb_entry->relogin_retry_count);
37117 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37118 DEBUG2(ql4_printk(KERN_INFO, ha,
37119 "%s: index[%d] relogin timed out-retrying"
37120 " relogin (%d), retry (%d)\n", __func__,
37121 ddb_entry->fw_ddb_index,
37122 - atomic_read(&ddb_entry->relogin_retry_count),
37123 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37124 ddb_entry->default_time2wait + 4));
37125 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37126 atomic_set(&ddb_entry->retry_relogin_timer,
37127 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37128
37129 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37130 atomic_set(&ddb_entry->relogin_timer, 0);
37131 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37132 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37133 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37134 ddb_entry->default_relogin_timeout =
37135 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37136 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37137 index 2c0d0ec..4e8681a 100644
37138 --- a/drivers/scsi/scsi.c
37139 +++ b/drivers/scsi/scsi.c
37140 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37141 unsigned long timeout;
37142 int rtn = 0;
37143
37144 - atomic_inc(&cmd->device->iorequest_cnt);
37145 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37146
37147 /* check if the device is still usable */
37148 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37149 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37150 index 9032e91..7a805d0 100644
37151 --- a/drivers/scsi/scsi_lib.c
37152 +++ b/drivers/scsi/scsi_lib.c
37153 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37154 shost = sdev->host;
37155 scsi_init_cmd_errh(cmd);
37156 cmd->result = DID_NO_CONNECT << 16;
37157 - atomic_inc(&cmd->device->iorequest_cnt);
37158 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37159
37160 /*
37161 * SCSI request completion path will do scsi_device_unbusy(),
37162 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
37163
37164 INIT_LIST_HEAD(&cmd->eh_entry);
37165
37166 - atomic_inc(&cmd->device->iodone_cnt);
37167 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37168 if (cmd->result)
37169 - atomic_inc(&cmd->device->ioerr_cnt);
37170 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37171
37172 disposition = scsi_decide_disposition(cmd);
37173 if (disposition != SUCCESS &&
37174 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37175 index ce5224c..8c6d071 100644
37176 --- a/drivers/scsi/scsi_sysfs.c
37177 +++ b/drivers/scsi/scsi_sysfs.c
37178 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37179 char *buf) \
37180 { \
37181 struct scsi_device *sdev = to_scsi_device(dev); \
37182 - unsigned long long count = atomic_read(&sdev->field); \
37183 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37184 return snprintf(buf, 20, "0x%llx\n", count); \
37185 } \
37186 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37187 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37188 index 84a1fdf..693b0d6 100644
37189 --- a/drivers/scsi/scsi_tgt_lib.c
37190 +++ b/drivers/scsi/scsi_tgt_lib.c
37191 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37192 int err;
37193
37194 dprintk("%lx %u\n", uaddr, len);
37195 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37196 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37197 if (err) {
37198 /*
37199 * TODO: need to fixup sg_tablesize, max_segment_size,
37200 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37201 index e894ca7..de9d7660 100644
37202 --- a/drivers/scsi/scsi_transport_fc.c
37203 +++ b/drivers/scsi/scsi_transport_fc.c
37204 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37205 * Netlink Infrastructure
37206 */
37207
37208 -static atomic_t fc_event_seq;
37209 +static atomic_unchecked_t fc_event_seq;
37210
37211 /**
37212 * fc_get_event_number - Obtain the next sequential FC event number
37213 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37214 u32
37215 fc_get_event_number(void)
37216 {
37217 - return atomic_add_return(1, &fc_event_seq);
37218 + return atomic_add_return_unchecked(1, &fc_event_seq);
37219 }
37220 EXPORT_SYMBOL(fc_get_event_number);
37221
37222 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37223 {
37224 int error;
37225
37226 - atomic_set(&fc_event_seq, 0);
37227 + atomic_set_unchecked(&fc_event_seq, 0);
37228
37229 error = transport_class_register(&fc_host_class);
37230 if (error)
37231 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37232 char *cp;
37233
37234 *val = simple_strtoul(buf, &cp, 0);
37235 - if ((*cp && (*cp != '\n')) || (*val < 0))
37236 + if (*cp && (*cp != '\n'))
37237 return -EINVAL;
37238 /*
37239 * Check for overflow; dev_loss_tmo is u32
37240 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37241 index 31969f2..2b348f0 100644
37242 --- a/drivers/scsi/scsi_transport_iscsi.c
37243 +++ b/drivers/scsi/scsi_transport_iscsi.c
37244 @@ -79,7 +79,7 @@ struct iscsi_internal {
37245 struct transport_container session_cont;
37246 };
37247
37248 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37249 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37250 static struct workqueue_struct *iscsi_eh_timer_workq;
37251
37252 static DEFINE_IDA(iscsi_sess_ida);
37253 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37254 int err;
37255
37256 ihost = shost->shost_data;
37257 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37258 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37259
37260 if (target_id == ISCSI_MAX_TARGET) {
37261 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37262 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37263 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37264 ISCSI_TRANSPORT_VERSION);
37265
37266 - atomic_set(&iscsi_session_nr, 0);
37267 + atomic_set_unchecked(&iscsi_session_nr, 0);
37268
37269 err = class_register(&iscsi_transport_class);
37270 if (err)
37271 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37272 index 21a045e..ec89e03 100644
37273 --- a/drivers/scsi/scsi_transport_srp.c
37274 +++ b/drivers/scsi/scsi_transport_srp.c
37275 @@ -33,7 +33,7 @@
37276 #include "scsi_transport_srp_internal.h"
37277
37278 struct srp_host_attrs {
37279 - atomic_t next_port_id;
37280 + atomic_unchecked_t next_port_id;
37281 };
37282 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37283
37284 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37285 struct Scsi_Host *shost = dev_to_shost(dev);
37286 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37287
37288 - atomic_set(&srp_host->next_port_id, 0);
37289 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37290 return 0;
37291 }
37292
37293 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37294 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37295 rport->roles = ids->roles;
37296
37297 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37298 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37299 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37300
37301 transport_setup_device(&rport->dev);
37302 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37303 index 352bc77..c049b14 100644
37304 --- a/drivers/scsi/sd.c
37305 +++ b/drivers/scsi/sd.c
37306 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
37307 sdkp->disk = gd;
37308 sdkp->index = index;
37309 atomic_set(&sdkp->openers, 0);
37310 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37311 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37312
37313 if (!sdp->request_queue->rq_timeout) {
37314 if (sdp->type != TYPE_MOD)
37315 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37316 index be2c9a6..275525c 100644
37317 --- a/drivers/scsi/sg.c
37318 +++ b/drivers/scsi/sg.c
37319 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37320 sdp->disk->disk_name,
37321 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37322 NULL,
37323 - (char *)arg);
37324 + (char __user *)arg);
37325 case BLKTRACESTART:
37326 return blk_trace_startstop(sdp->device->request_queue, 1);
37327 case BLKTRACESTOP:
37328 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37329 index 84c2861..ece0a31 100644
37330 --- a/drivers/spi/spi.c
37331 +++ b/drivers/spi/spi.c
37332 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37333 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37334
37335 /* portable code must never pass more than 32 bytes */
37336 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37337 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37338
37339 static u8 *buf;
37340
37341 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37342 index 34afc16..ffe44dd 100644
37343 --- a/drivers/staging/octeon/ethernet-rx.c
37344 +++ b/drivers/staging/octeon/ethernet-rx.c
37345 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37346 /* Increment RX stats for virtual ports */
37347 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37348 #ifdef CONFIG_64BIT
37349 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37350 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37351 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37352 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37353 #else
37354 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37355 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37356 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37357 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37358 #endif
37359 }
37360 netif_receive_skb(skb);
37361 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37362 dev->name);
37363 */
37364 #ifdef CONFIG_64BIT
37365 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37366 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37367 #else
37368 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37369 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37370 #endif
37371 dev_kfree_skb_irq(skb);
37372 }
37373 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37374 index 683bedc..86dba9a 100644
37375 --- a/drivers/staging/octeon/ethernet.c
37376 +++ b/drivers/staging/octeon/ethernet.c
37377 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37378 * since the RX tasklet also increments it.
37379 */
37380 #ifdef CONFIG_64BIT
37381 - atomic64_add(rx_status.dropped_packets,
37382 - (atomic64_t *)&priv->stats.rx_dropped);
37383 + atomic64_add_unchecked(rx_status.dropped_packets,
37384 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37385 #else
37386 - atomic_add(rx_status.dropped_packets,
37387 - (atomic_t *)&priv->stats.rx_dropped);
37388 + atomic_add_unchecked(rx_status.dropped_packets,
37389 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37390 #endif
37391 }
37392
37393 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
37394 index a2b7e03..aaf3630 100644
37395 --- a/drivers/staging/ramster/tmem.c
37396 +++ b/drivers/staging/ramster/tmem.c
37397 @@ -50,25 +50,25 @@
37398 * A tmem host implementation must use this function to register callbacks
37399 * for memory allocation.
37400 */
37401 -static struct tmem_hostops tmem_hostops;
37402 +static struct tmem_hostops *tmem_hostops;
37403
37404 static void tmem_objnode_tree_init(void);
37405
37406 void tmem_register_hostops(struct tmem_hostops *m)
37407 {
37408 tmem_objnode_tree_init();
37409 - tmem_hostops = *m;
37410 + tmem_hostops = m;
37411 }
37412
37413 /*
37414 * A tmem host implementation must use this function to register
37415 * callbacks for a page-accessible memory (PAM) implementation.
37416 */
37417 -static struct tmem_pamops tmem_pamops;
37418 +static struct tmem_pamops *tmem_pamops;
37419
37420 void tmem_register_pamops(struct tmem_pamops *m)
37421 {
37422 - tmem_pamops = *m;
37423 + tmem_pamops = m;
37424 }
37425
37426 /*
37427 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
37428 obj->pampd_count = 0;
37429 #ifdef CONFIG_RAMSTER
37430 if (tmem_pamops.new_obj != NULL)
37431 - (*tmem_pamops.new_obj)(obj);
37432 + (tmem_pamops->new_obj)(obj);
37433 #endif
37434 SET_SENTINEL(obj, OBJ);
37435
37436 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
37437 rbnode = rb_next(rbnode);
37438 tmem_pampd_destroy_all_in_obj(obj, true);
37439 tmem_obj_free(obj, hb);
37440 - (*tmem_hostops.obj_free)(obj, pool);
37441 + (tmem_hostops->obj_free)(obj, pool);
37442 }
37443 spin_unlock(&hb->lock);
37444 }
37445 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
37446 ASSERT_SENTINEL(obj, OBJ);
37447 BUG_ON(obj->pool == NULL);
37448 ASSERT_SENTINEL(obj->pool, POOL);
37449 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
37450 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
37451 if (unlikely(objnode == NULL))
37452 goto out;
37453 objnode->obj = obj;
37454 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
37455 ASSERT_SENTINEL(pool, POOL);
37456 objnode->obj->objnode_count--;
37457 objnode->obj = NULL;
37458 - (*tmem_hostops.objnode_free)(objnode, pool);
37459 + (tmem_hostops->objnode_free)(objnode, pool);
37460 }
37461
37462 /*
37463 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
37464 void *old_pampd = *(void **)slot;
37465 *(void **)slot = new_pampd;
37466 if (!no_free)
37467 - (*tmem_pamops.free)(old_pampd, obj->pool,
37468 + (tmem_pamops->free)(old_pampd, obj->pool,
37469 NULL, 0, false);
37470 ret = new_pampd;
37471 }
37472 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
37473 if (objnode->slots[i]) {
37474 if (ht == 1) {
37475 obj->pampd_count--;
37476 - (*tmem_pamops.free)(objnode->slots[i],
37477 + (tmem_pamops->free)(objnode->slots[i],
37478 obj->pool, NULL, 0, true);
37479 objnode->slots[i] = NULL;
37480 continue;
37481 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
37482 return;
37483 if (obj->objnode_tree_height == 0) {
37484 obj->pampd_count--;
37485 - (*tmem_pamops.free)(obj->objnode_tree_root,
37486 + (tmem_pamops->free)(obj->objnode_tree_root,
37487 obj->pool, NULL, 0, true);
37488 } else {
37489 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
37490 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
37491 obj->objnode_tree_root = NULL;
37492 #ifdef CONFIG_RAMSTER
37493 if (tmem_pamops.free_obj != NULL)
37494 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
37495 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
37496 #endif
37497 }
37498
37499 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37500 /* if found, is a dup put, flush the old one */
37501 pampd_del = tmem_pampd_delete_from_obj(obj, index);
37502 BUG_ON(pampd_del != pampd);
37503 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
37504 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
37505 if (obj->pampd_count == 0) {
37506 objnew = obj;
37507 objfound = NULL;
37508 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37509 pampd = NULL;
37510 }
37511 } else {
37512 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
37513 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
37514 if (unlikely(obj == NULL)) {
37515 ret = -ENOMEM;
37516 goto out;
37517 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37518 if (unlikely(ret == -ENOMEM))
37519 /* may have partially built objnode tree ("stump") */
37520 goto delete_and_free;
37521 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
37522 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
37523 goto out;
37524
37525 delete_and_free:
37526 (void)tmem_pampd_delete_from_obj(obj, index);
37527 if (pampd)
37528 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
37529 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
37530 if (objnew) {
37531 tmem_obj_free(objnew, hb);
37532 - (*tmem_hostops.obj_free)(objnew, pool);
37533 + (tmem_hostops->obj_free)(objnew, pool);
37534 }
37535 out:
37536 spin_unlock(&hb->lock);
37537 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
37538 if (pampd != NULL) {
37539 BUG_ON(obj == NULL);
37540 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
37541 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
37542 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
37543 } else if (delete) {
37544 BUG_ON(obj == NULL);
37545 (void)tmem_pampd_delete_from_obj(obj, index);
37546 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
37547 int ret = 0;
37548
37549 if (!is_ephemeral(pool))
37550 - new_pampd = (*tmem_pamops.repatriate_preload)(
37551 + new_pampd = (tmem_pamops->repatriate_preload)(
37552 old_pampd, pool, oidp, index, &intransit);
37553 if (intransit)
37554 ret = -EAGAIN;
37555 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
37556 /* must release the hb->lock else repatriate can't sleep */
37557 spin_unlock(&hb->lock);
37558 if (!intransit)
37559 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
37560 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
37561 oidp, index, free, data);
37562 if (ret == -EAGAIN) {
37563 /* rare I think, but should cond_resched()??? */
37564 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
37565 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
37566 /* if we bug here, pamops wasn't properly set up for ramster */
37567 BUG_ON(tmem_pamops.replace_in_obj == NULL);
37568 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
37569 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
37570 out:
37571 spin_unlock(&hb->lock);
37572 return ret;
37573 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37574 if (free) {
37575 if (obj->pampd_count == 0) {
37576 tmem_obj_free(obj, hb);
37577 - (*tmem_hostops.obj_free)(obj, pool);
37578 + (tmem_hostops->obj_free)(obj, pool);
37579 obj = NULL;
37580 }
37581 }
37582 if (free)
37583 - ret = (*tmem_pamops.get_data_and_free)(
37584 + ret = (tmem_pamops->get_data_and_free)(
37585 data, sizep, raw, pampd, pool, oidp, index);
37586 else
37587 - ret = (*tmem_pamops.get_data)(
37588 + ret = (tmem_pamops->get_data)(
37589 data, sizep, raw, pampd, pool, oidp, index);
37590 if (ret < 0)
37591 goto out;
37592 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
37593 pampd = tmem_pampd_delete_from_obj(obj, index);
37594 if (pampd == NULL)
37595 goto out;
37596 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
37597 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
37598 if (obj->pampd_count == 0) {
37599 tmem_obj_free(obj, hb);
37600 - (*tmem_hostops.obj_free)(obj, pool);
37601 + (tmem_hostops->obj_free)(obj, pool);
37602 }
37603 ret = 0;
37604
37605 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
37606 goto out;
37607 tmem_pampd_destroy_all_in_obj(obj, false);
37608 tmem_obj_free(obj, hb);
37609 - (*tmem_hostops.obj_free)(obj, pool);
37610 + (tmem_hostops->obj_free)(obj, pool);
37611 ret = 0;
37612
37613 out:
37614 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37615 index dc23395..cf7e9b1 100644
37616 --- a/drivers/staging/rtl8712/rtl871x_io.h
37617 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37618 @@ -108,7 +108,7 @@ struct _io_ops {
37619 u8 *pmem);
37620 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37621 u8 *pmem);
37622 -};
37623 +} __no_const;
37624
37625 struct io_req {
37626 struct list_head list;
37627 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37628 index 180c963..1f18377 100644
37629 --- a/drivers/staging/sbe-2t3e3/netdev.c
37630 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37631 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37632 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37633
37634 if (rlen)
37635 - if (copy_to_user(data, &resp, rlen))
37636 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37637 return -EFAULT;
37638
37639 return 0;
37640 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37641 index 5d89c0f..9261317 100644
37642 --- a/drivers/staging/usbip/usbip_common.h
37643 +++ b/drivers/staging/usbip/usbip_common.h
37644 @@ -289,7 +289,7 @@ struct usbip_device {
37645 void (*shutdown)(struct usbip_device *);
37646 void (*reset)(struct usbip_device *);
37647 void (*unusable)(struct usbip_device *);
37648 - } eh_ops;
37649 + } __no_const eh_ops;
37650 };
37651
37652 #define kthread_get_run(threadfn, data, namefmt, ...) \
37653 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37654 index c66b8b3..a4a035b 100644
37655 --- a/drivers/staging/usbip/vhci.h
37656 +++ b/drivers/staging/usbip/vhci.h
37657 @@ -83,7 +83,7 @@ struct vhci_hcd {
37658 unsigned resuming:1;
37659 unsigned long re_timeout;
37660
37661 - atomic_t seqnum;
37662 + atomic_unchecked_t seqnum;
37663
37664 /*
37665 * NOTE:
37666 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37667 index 620d1be..1cd6711 100644
37668 --- a/drivers/staging/usbip/vhci_hcd.c
37669 +++ b/drivers/staging/usbip/vhci_hcd.c
37670 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37671 return;
37672 }
37673
37674 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37675 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37676 if (priv->seqnum == 0xffff)
37677 dev_info(&urb->dev->dev, "seqnum max\n");
37678
37679 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37680 return -ENOMEM;
37681 }
37682
37683 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37684 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37685 if (unlink->seqnum == 0xffff)
37686 pr_info("seqnum max\n");
37687
37688 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
37689 vdev->rhport = rhport;
37690 }
37691
37692 - atomic_set(&vhci->seqnum, 0);
37693 + atomic_set_unchecked(&vhci->seqnum, 0);
37694 spin_lock_init(&vhci->lock);
37695
37696 hcd->power_budget = 0; /* no limit */
37697 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37698 index f0eaf04..5a82e06 100644
37699 --- a/drivers/staging/usbip/vhci_rx.c
37700 +++ b/drivers/staging/usbip/vhci_rx.c
37701 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37702 if (!urb) {
37703 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37704 pr_info("max seqnum %d\n",
37705 - atomic_read(&the_controller->seqnum));
37706 + atomic_read_unchecked(&the_controller->seqnum));
37707 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37708 return;
37709 }
37710 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37711 index 67b1b88..6392fe9 100644
37712 --- a/drivers/staging/vt6655/hostap.c
37713 +++ b/drivers/staging/vt6655/hostap.c
37714 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37715 *
37716 */
37717
37718 +static net_device_ops_no_const apdev_netdev_ops;
37719 +
37720 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37721 {
37722 PSDevice apdev_priv;
37723 struct net_device *dev = pDevice->dev;
37724 int ret;
37725 - const struct net_device_ops apdev_netdev_ops = {
37726 - .ndo_start_xmit = pDevice->tx_80211,
37727 - };
37728
37729 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37730
37731 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37732 *apdev_priv = *pDevice;
37733 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37734
37735 + /* only half broken now */
37736 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37737 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37738
37739 pDevice->apdev->type = ARPHRD_IEEE80211;
37740 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37741 index 0a73d40..6fda560 100644
37742 --- a/drivers/staging/vt6656/hostap.c
37743 +++ b/drivers/staging/vt6656/hostap.c
37744 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37745 *
37746 */
37747
37748 +static net_device_ops_no_const apdev_netdev_ops;
37749 +
37750 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37751 {
37752 PSDevice apdev_priv;
37753 struct net_device *dev = pDevice->dev;
37754 int ret;
37755 - const struct net_device_ops apdev_netdev_ops = {
37756 - .ndo_start_xmit = pDevice->tx_80211,
37757 - };
37758
37759 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37760
37761 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37762 *apdev_priv = *pDevice;
37763 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37764
37765 + /* only half broken now */
37766 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37767 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37768
37769 pDevice->apdev->type = ARPHRD_IEEE80211;
37770 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37771 index f180c3d..4b9ecfc 100644
37772 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37773 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37774 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37775
37776 struct usbctlx_completor {
37777 int (*complete) (struct usbctlx_completor *);
37778 -};
37779 +} __no_const;
37780
37781 static int
37782 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37783 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37784 index 56c8e60..1920c63 100644
37785 --- a/drivers/staging/zcache/tmem.c
37786 +++ b/drivers/staging/zcache/tmem.c
37787 @@ -39,7 +39,7 @@
37788 * A tmem host implementation must use this function to register callbacks
37789 * for memory allocation.
37790 */
37791 -static struct tmem_hostops tmem_hostops;
37792 +static tmem_hostops_no_const tmem_hostops;
37793
37794 static void tmem_objnode_tree_init(void);
37795
37796 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37797 * A tmem host implementation must use this function to register
37798 * callbacks for a page-accessible memory (PAM) implementation
37799 */
37800 -static struct tmem_pamops tmem_pamops;
37801 +static tmem_pamops_no_const tmem_pamops;
37802
37803 void tmem_register_pamops(struct tmem_pamops *m)
37804 {
37805 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37806 index 0d4aa82..f7832d4 100644
37807 --- a/drivers/staging/zcache/tmem.h
37808 +++ b/drivers/staging/zcache/tmem.h
37809 @@ -180,6 +180,7 @@ struct tmem_pamops {
37810 void (*new_obj)(struct tmem_obj *);
37811 int (*replace_in_obj)(void *, struct tmem_obj *);
37812 };
37813 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37814 extern void tmem_register_pamops(struct tmem_pamops *m);
37815
37816 /* memory allocation methods provided by the host implementation */
37817 @@ -189,6 +190,7 @@ struct tmem_hostops {
37818 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37819 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37820 };
37821 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37822 extern void tmem_register_hostops(struct tmem_hostops *m);
37823
37824 /* core tmem accessor functions */
37825 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37826 index dcecbfb..4fad7d5 100644
37827 --- a/drivers/target/target_core_transport.c
37828 +++ b/drivers/target/target_core_transport.c
37829 @@ -1087,7 +1087,7 @@ struct se_device *transport_add_device_to_core_hba(
37830 spin_lock_init(&dev->se_port_lock);
37831 spin_lock_init(&dev->se_tmr_lock);
37832 spin_lock_init(&dev->qf_cmd_lock);
37833 - atomic_set(&dev->dev_ordered_id, 0);
37834 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37835
37836 se_dev_set_default_attribs(dev, dev_limits);
37837
37838 @@ -1277,7 +1277,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37839 * Used to determine when ORDERED commands should go from
37840 * Dormant to Active status.
37841 */
37842 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37843 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37844 smp_mb__after_atomic_inc();
37845 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37846 cmd->se_ordered_id, cmd->sam_task_attr,
37847 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37848 index 0a6a0bc..5501b06 100644
37849 --- a/drivers/tty/cyclades.c
37850 +++ b/drivers/tty/cyclades.c
37851 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37852 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37853 info->port.count);
37854 #endif
37855 - info->port.count++;
37856 + atomic_inc(&info->port.count);
37857 #ifdef CY_DEBUG_COUNT
37858 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37859 - current->pid, info->port.count);
37860 + current->pid, atomic_read(&info->port.count));
37861 #endif
37862
37863 /*
37864 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37865 for (j = 0; j < cy_card[i].nports; j++) {
37866 info = &cy_card[i].ports[j];
37867
37868 - if (info->port.count) {
37869 + if (atomic_read(&info->port.count)) {
37870 /* XXX is the ldisc num worth this? */
37871 struct tty_struct *tty;
37872 struct tty_ldisc *ld;
37873 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37874 index 13ee53b..418d164 100644
37875 --- a/drivers/tty/hvc/hvc_console.c
37876 +++ b/drivers/tty/hvc/hvc_console.c
37877 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37878
37879 spin_lock_irqsave(&hp->port.lock, flags);
37880 /* Check and then increment for fast path open. */
37881 - if (hp->port.count++ > 0) {
37882 + if (atomic_inc_return(&hp->port.count) > 1) {
37883 spin_unlock_irqrestore(&hp->port.lock, flags);
37884 hvc_kick();
37885 return 0;
37886 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37887
37888 spin_lock_irqsave(&hp->port.lock, flags);
37889
37890 - if (--hp->port.count == 0) {
37891 + if (atomic_dec_return(&hp->port.count) == 0) {
37892 spin_unlock_irqrestore(&hp->port.lock, flags);
37893 /* We are done with the tty pointer now. */
37894 tty_port_tty_set(&hp->port, NULL);
37895 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37896 */
37897 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37898 } else {
37899 - if (hp->port.count < 0)
37900 + if (atomic_read(&hp->port.count) < 0)
37901 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37902 - hp->vtermno, hp->port.count);
37903 + hp->vtermno, atomic_read(&hp->port.count));
37904 spin_unlock_irqrestore(&hp->port.lock, flags);
37905 }
37906 }
37907 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
37908 * open->hangup case this can be called after the final close so prevent
37909 * that from happening for now.
37910 */
37911 - if (hp->port.count <= 0) {
37912 + if (atomic_read(&hp->port.count) <= 0) {
37913 spin_unlock_irqrestore(&hp->port.lock, flags);
37914 return;
37915 }
37916
37917 - hp->port.count = 0;
37918 + atomic_set(&hp->port.count, 0);
37919 spin_unlock_irqrestore(&hp->port.lock, flags);
37920 tty_port_tty_set(&hp->port, NULL);
37921
37922 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37923 return -EPIPE;
37924
37925 /* FIXME what's this (unprotected) check for? */
37926 - if (hp->port.count <= 0)
37927 + if (atomic_read(&hp->port.count) <= 0)
37928 return -EIO;
37929
37930 spin_lock_irqsave(&hp->lock, flags);
37931 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37932 index cab5c7a..4cc66ea 100644
37933 --- a/drivers/tty/hvc/hvcs.c
37934 +++ b/drivers/tty/hvc/hvcs.c
37935 @@ -83,6 +83,7 @@
37936 #include <asm/hvcserver.h>
37937 #include <asm/uaccess.h>
37938 #include <asm/vio.h>
37939 +#include <asm/local.h>
37940
37941 /*
37942 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37943 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37944
37945 spin_lock_irqsave(&hvcsd->lock, flags);
37946
37947 - if (hvcsd->port.count > 0) {
37948 + if (atomic_read(&hvcsd->port.count) > 0) {
37949 spin_unlock_irqrestore(&hvcsd->lock, flags);
37950 printk(KERN_INFO "HVCS: vterm state unchanged. "
37951 "The hvcs device node is still in use.\n");
37952 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
37953 }
37954 }
37955
37956 - hvcsd->port.count = 0;
37957 + atomic_set(&hvcsd->port.count, 0);
37958 hvcsd->port.tty = tty;
37959 tty->driver_data = hvcsd;
37960
37961 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37962 unsigned long flags;
37963
37964 spin_lock_irqsave(&hvcsd->lock, flags);
37965 - hvcsd->port.count++;
37966 + atomic_inc(&hvcsd->port.count);
37967 hvcsd->todo_mask |= HVCS_SCHED_READ;
37968 spin_unlock_irqrestore(&hvcsd->lock, flags);
37969
37970 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37971 hvcsd = tty->driver_data;
37972
37973 spin_lock_irqsave(&hvcsd->lock, flags);
37974 - if (--hvcsd->port.count == 0) {
37975 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37976
37977 vio_disable_interrupts(hvcsd->vdev);
37978
37979 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37980
37981 free_irq(irq, hvcsd);
37982 return;
37983 - } else if (hvcsd->port.count < 0) {
37984 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37985 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37986 " is missmanaged.\n",
37987 - hvcsd->vdev->unit_address, hvcsd->port.count);
37988 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37989 }
37990
37991 spin_unlock_irqrestore(&hvcsd->lock, flags);
37992 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37993
37994 spin_lock_irqsave(&hvcsd->lock, flags);
37995 /* Preserve this so that we know how many kref refs to put */
37996 - temp_open_count = hvcsd->port.count;
37997 + temp_open_count = atomic_read(&hvcsd->port.count);
37998
37999 /*
38000 * Don't kref put inside the spinlock because the destruction
38001 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38002 tty->driver_data = NULL;
38003 hvcsd->port.tty = NULL;
38004
38005 - hvcsd->port.count = 0;
38006 + atomic_set(&hvcsd->port.count, 0);
38007
38008 /* This will drop any buffered data on the floor which is OK in a hangup
38009 * scenario. */
38010 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
38011 * the middle of a write operation? This is a crummy place to do this
38012 * but we want to keep it all in the spinlock.
38013 */
38014 - if (hvcsd->port.count <= 0) {
38015 + if (atomic_read(&hvcsd->port.count) <= 0) {
38016 spin_unlock_irqrestore(&hvcsd->lock, flags);
38017 return -ENODEV;
38018 }
38019 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38020 {
38021 struct hvcs_struct *hvcsd = tty->driver_data;
38022
38023 - if (!hvcsd || hvcsd->port.count <= 0)
38024 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38025 return 0;
38026
38027 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38028 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38029 index 160f0ad..588b853 100644
38030 --- a/drivers/tty/ipwireless/tty.c
38031 +++ b/drivers/tty/ipwireless/tty.c
38032 @@ -29,6 +29,7 @@
38033 #include <linux/tty_driver.h>
38034 #include <linux/tty_flip.h>
38035 #include <linux/uaccess.h>
38036 +#include <asm/local.h>
38037
38038 #include "tty.h"
38039 #include "network.h"
38040 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38041 mutex_unlock(&tty->ipw_tty_mutex);
38042 return -ENODEV;
38043 }
38044 - if (tty->port.count == 0)
38045 + if (atomic_read(&tty->port.count) == 0)
38046 tty->tx_bytes_queued = 0;
38047
38048 - tty->port.count++;
38049 + atomic_inc(&tty->port.count);
38050
38051 tty->port.tty = linux_tty;
38052 linux_tty->driver_data = tty;
38053 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38054
38055 static void do_ipw_close(struct ipw_tty *tty)
38056 {
38057 - tty->port.count--;
38058 -
38059 - if (tty->port.count == 0) {
38060 + if (atomic_dec_return(&tty->port.count) == 0) {
38061 struct tty_struct *linux_tty = tty->port.tty;
38062
38063 if (linux_tty != NULL) {
38064 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38065 return;
38066
38067 mutex_lock(&tty->ipw_tty_mutex);
38068 - if (tty->port.count == 0) {
38069 + if (atomic_read(&tty->port.count) == 0) {
38070 mutex_unlock(&tty->ipw_tty_mutex);
38071 return;
38072 }
38073 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38074 return;
38075 }
38076
38077 - if (!tty->port.count) {
38078 + if (!atomic_read(&tty->port.count)) {
38079 mutex_unlock(&tty->ipw_tty_mutex);
38080 return;
38081 }
38082 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38083 return -ENODEV;
38084
38085 mutex_lock(&tty->ipw_tty_mutex);
38086 - if (!tty->port.count) {
38087 + if (!atomic_read(&tty->port.count)) {
38088 mutex_unlock(&tty->ipw_tty_mutex);
38089 return -EINVAL;
38090 }
38091 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38092 if (!tty)
38093 return -ENODEV;
38094
38095 - if (!tty->port.count)
38096 + if (!atomic_read(&tty->port.count))
38097 return -EINVAL;
38098
38099 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38100 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38101 if (!tty)
38102 return 0;
38103
38104 - if (!tty->port.count)
38105 + if (!atomic_read(&tty->port.count))
38106 return 0;
38107
38108 return tty->tx_bytes_queued;
38109 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38110 if (!tty)
38111 return -ENODEV;
38112
38113 - if (!tty->port.count)
38114 + if (!atomic_read(&tty->port.count))
38115 return -EINVAL;
38116
38117 return get_control_lines(tty);
38118 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38119 if (!tty)
38120 return -ENODEV;
38121
38122 - if (!tty->port.count)
38123 + if (!atomic_read(&tty->port.count))
38124 return -EINVAL;
38125
38126 return set_control_lines(tty, set, clear);
38127 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38128 if (!tty)
38129 return -ENODEV;
38130
38131 - if (!tty->port.count)
38132 + if (!atomic_read(&tty->port.count))
38133 return -EINVAL;
38134
38135 /* FIXME: Exactly how is the tty object locked here .. */
38136 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38137 * are gone */
38138 mutex_lock(&ttyj->ipw_tty_mutex);
38139 }
38140 - while (ttyj->port.count)
38141 + while (atomic_read(&ttyj->port.count))
38142 do_ipw_close(ttyj);
38143 ipwireless_disassociate_network_ttys(network,
38144 ttyj->channel_idx);
38145 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38146 index 56e616b..9d9f10a 100644
38147 --- a/drivers/tty/moxa.c
38148 +++ b/drivers/tty/moxa.c
38149 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38150 }
38151
38152 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38153 - ch->port.count++;
38154 + atomic_inc(&ch->port.count);
38155 tty->driver_data = ch;
38156 tty_port_tty_set(&ch->port, tty);
38157 mutex_lock(&ch->port.mutex);
38158 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38159 index 1e8e8ce..a9efc93 100644
38160 --- a/drivers/tty/n_gsm.c
38161 +++ b/drivers/tty/n_gsm.c
38162 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38163 kref_init(&dlci->ref);
38164 mutex_init(&dlci->mutex);
38165 dlci->fifo = &dlci->_fifo;
38166 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38167 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38168 kfree(dlci);
38169 return NULL;
38170 }
38171 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38172 struct gsm_dlci *dlci = tty->driver_data;
38173 struct tty_port *port = &dlci->port;
38174
38175 - port->count++;
38176 + atomic_inc(&port->count);
38177 dlci_get(dlci);
38178 dlci_get(dlci->gsm->dlci[0]);
38179 mux_get(dlci->gsm);
38180 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38181 index 8c0b7b4..e88f052 100644
38182 --- a/drivers/tty/n_tty.c
38183 +++ b/drivers/tty/n_tty.c
38184 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38185 {
38186 *ops = tty_ldisc_N_TTY;
38187 ops->owner = NULL;
38188 - ops->refcount = ops->flags = 0;
38189 + atomic_set(&ops->refcount, 0);
38190 + ops->flags = 0;
38191 }
38192 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38193 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38194 index a82b399..331a220 100644
38195 --- a/drivers/tty/pty.c
38196 +++ b/drivers/tty/pty.c
38197 @@ -728,8 +728,10 @@ static void __init unix98_pty_init(void)
38198 panic("Couldn't register Unix98 pts driver");
38199
38200 /* Now create the /dev/ptmx special device */
38201 + pax_open_kernel();
38202 tty_default_fops(&ptmx_fops);
38203 - ptmx_fops.open = ptmx_open;
38204 + *(void **)&ptmx_fops.open = ptmx_open;
38205 + pax_close_kernel();
38206
38207 cdev_init(&ptmx_cdev, &ptmx_fops);
38208 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38209 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38210 index 9700d34..df7520c 100644
38211 --- a/drivers/tty/rocket.c
38212 +++ b/drivers/tty/rocket.c
38213 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38214 tty->driver_data = info;
38215 tty_port_tty_set(port, tty);
38216
38217 - if (port->count++ == 0) {
38218 + if (atomic_inc_return(&port->count) == 1) {
38219 atomic_inc(&rp_num_ports_open);
38220
38221 #ifdef ROCKET_DEBUG_OPEN
38222 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38223 #endif
38224 }
38225 #ifdef ROCKET_DEBUG_OPEN
38226 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38227 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38228 #endif
38229
38230 /*
38231 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38232 spin_unlock_irqrestore(&info->port.lock, flags);
38233 return;
38234 }
38235 - if (info->port.count)
38236 + if (atomic_read(&info->port.count))
38237 atomic_dec(&rp_num_ports_open);
38238 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38239 spin_unlock_irqrestore(&info->port.lock, flags);
38240 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38241 index 1002054..dd644a8 100644
38242 --- a/drivers/tty/serial/kgdboc.c
38243 +++ b/drivers/tty/serial/kgdboc.c
38244 @@ -24,8 +24,9 @@
38245 #define MAX_CONFIG_LEN 40
38246
38247 static struct kgdb_io kgdboc_io_ops;
38248 +static struct kgdb_io kgdboc_io_ops_console;
38249
38250 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38251 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38252 static int configured = -1;
38253
38254 static char config[MAX_CONFIG_LEN];
38255 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
38256 kgdboc_unregister_kbd();
38257 if (configured == 1)
38258 kgdb_unregister_io_module(&kgdboc_io_ops);
38259 + else if (configured == 2)
38260 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38261 }
38262
38263 static int configure_kgdboc(void)
38264 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
38265 int err;
38266 char *cptr = config;
38267 struct console *cons;
38268 + int is_console = 0;
38269
38270 err = kgdboc_option_setup(config);
38271 if (err || !strlen(config) || isspace(config[0]))
38272 goto noconfig;
38273
38274 err = -ENODEV;
38275 - kgdboc_io_ops.is_console = 0;
38276 kgdb_tty_driver = NULL;
38277
38278 kgdboc_use_kms = 0;
38279 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
38280 int idx;
38281 if (cons->device && cons->device(cons, &idx) == p &&
38282 idx == tty_line) {
38283 - kgdboc_io_ops.is_console = 1;
38284 + is_console = 1;
38285 break;
38286 }
38287 cons = cons->next;
38288 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
38289 kgdb_tty_line = tty_line;
38290
38291 do_register:
38292 - err = kgdb_register_io_module(&kgdboc_io_ops);
38293 + if (is_console) {
38294 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38295 + configured = 2;
38296 + } else {
38297 + err = kgdb_register_io_module(&kgdboc_io_ops);
38298 + configured = 1;
38299 + }
38300 if (err)
38301 goto noconfig;
38302
38303 @@ -205,8 +214,6 @@ do_register:
38304 if (err)
38305 goto nmi_con_failed;
38306
38307 - configured = 1;
38308 -
38309 return 0;
38310
38311 nmi_con_failed:
38312 @@ -223,7 +230,7 @@ noconfig:
38313 static int __init init_kgdboc(void)
38314 {
38315 /* Already configured? */
38316 - if (configured == 1)
38317 + if (configured >= 1)
38318 return 0;
38319
38320 return configure_kgdboc();
38321 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38322 if (config[len - 1] == '\n')
38323 config[len - 1] = '\0';
38324
38325 - if (configured == 1)
38326 + if (configured >= 1)
38327 cleanup_kgdboc();
38328
38329 /* Go and configure with the new params. */
38330 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
38331 .post_exception = kgdboc_post_exp_handler,
38332 };
38333
38334 +static struct kgdb_io kgdboc_io_ops_console = {
38335 + .name = "kgdboc",
38336 + .read_char = kgdboc_get_char,
38337 + .write_char = kgdboc_put_char,
38338 + .pre_exception = kgdboc_pre_exp_handler,
38339 + .post_exception = kgdboc_post_exp_handler,
38340 + .is_console = 1
38341 +};
38342 +
38343 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38344 /* This is only available if kgdboc is a built in for early debugging */
38345 static int __init kgdboc_early_init(char *opt)
38346 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38347 index 0fcfd98..8244fce 100644
38348 --- a/drivers/tty/serial/serial_core.c
38349 +++ b/drivers/tty/serial/serial_core.c
38350 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
38351 uart_flush_buffer(tty);
38352 uart_shutdown(tty, state);
38353 spin_lock_irqsave(&port->lock, flags);
38354 - port->count = 0;
38355 + atomic_set(&port->count, 0);
38356 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38357 spin_unlock_irqrestore(&port->lock, flags);
38358 tty_port_tty_set(port, NULL);
38359 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38360 goto end;
38361 }
38362
38363 - port->count++;
38364 + atomic_inc(&port->count);
38365 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38366 retval = -ENXIO;
38367 goto err_dec_count;
38368 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38369 /*
38370 * Make sure the device is in D0 state.
38371 */
38372 - if (port->count == 1)
38373 + if (atomic_read(&port->count) == 1)
38374 uart_change_pm(state, 0);
38375
38376 /*
38377 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38378 end:
38379 return retval;
38380 err_dec_count:
38381 - port->count--;
38382 + atomic_inc(&port->count);
38383 mutex_unlock(&port->mutex);
38384 goto end;
38385 }
38386 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38387 index 70e3a52..5742052 100644
38388 --- a/drivers/tty/synclink.c
38389 +++ b/drivers/tty/synclink.c
38390 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38391
38392 if (debug_level >= DEBUG_LEVEL_INFO)
38393 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38394 - __FILE__,__LINE__, info->device_name, info->port.count);
38395 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38396
38397 if (tty_port_close_start(&info->port, tty, filp) == 0)
38398 goto cleanup;
38399 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38400 cleanup:
38401 if (debug_level >= DEBUG_LEVEL_INFO)
38402 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38403 - tty->driver->name, info->port.count);
38404 + tty->driver->name, atomic_read(&info->port.count));
38405
38406 } /* end of mgsl_close() */
38407
38408 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38409
38410 mgsl_flush_buffer(tty);
38411 shutdown(info);
38412 -
38413 - info->port.count = 0;
38414 +
38415 + atomic_set(&info->port.count, 0);
38416 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38417 info->port.tty = NULL;
38418
38419 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38420
38421 if (debug_level >= DEBUG_LEVEL_INFO)
38422 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38423 - __FILE__,__LINE__, tty->driver->name, port->count );
38424 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38425
38426 spin_lock_irqsave(&info->irq_spinlock, flags);
38427 if (!tty_hung_up_p(filp)) {
38428 extra_count = true;
38429 - port->count--;
38430 + atomic_dec(&port->count);
38431 }
38432 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38433 port->blocked_open++;
38434 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38435
38436 if (debug_level >= DEBUG_LEVEL_INFO)
38437 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38438 - __FILE__,__LINE__, tty->driver->name, port->count );
38439 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38440
38441 tty_unlock(tty);
38442 schedule();
38443 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38444
38445 /* FIXME: Racy on hangup during close wait */
38446 if (extra_count)
38447 - port->count++;
38448 + atomic_inc(&port->count);
38449 port->blocked_open--;
38450
38451 if (debug_level >= DEBUG_LEVEL_INFO)
38452 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38453 - __FILE__,__LINE__, tty->driver->name, port->count );
38454 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38455
38456 if (!retval)
38457 port->flags |= ASYNC_NORMAL_ACTIVE;
38458 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38459
38460 if (debug_level >= DEBUG_LEVEL_INFO)
38461 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38462 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38463 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38464
38465 /* If port is closing, signal caller to try again */
38466 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38467 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38468 spin_unlock_irqrestore(&info->netlock, flags);
38469 goto cleanup;
38470 }
38471 - info->port.count++;
38472 + atomic_inc(&info->port.count);
38473 spin_unlock_irqrestore(&info->netlock, flags);
38474
38475 - if (info->port.count == 1) {
38476 + if (atomic_read(&info->port.count) == 1) {
38477 /* 1st open on this device, init hardware */
38478 retval = startup(info);
38479 if (retval < 0)
38480 @@ -3451,8 +3451,8 @@ cleanup:
38481 if (retval) {
38482 if (tty->count == 1)
38483 info->port.tty = NULL; /* tty layer will release tty struct */
38484 - if(info->port.count)
38485 - info->port.count--;
38486 + if (atomic_read(&info->port.count))
38487 + atomic_dec(&info->port.count);
38488 }
38489
38490 return retval;
38491 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38492 unsigned short new_crctype;
38493
38494 /* return error if TTY interface open */
38495 - if (info->port.count)
38496 + if (atomic_read(&info->port.count))
38497 return -EBUSY;
38498
38499 switch (encoding)
38500 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
38501
38502 /* arbitrate between network and tty opens */
38503 spin_lock_irqsave(&info->netlock, flags);
38504 - if (info->port.count != 0 || info->netcount != 0) {
38505 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38506 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38507 spin_unlock_irqrestore(&info->netlock, flags);
38508 return -EBUSY;
38509 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38510 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38511
38512 /* return error if TTY interface open */
38513 - if (info->port.count)
38514 + if (atomic_read(&info->port.count))
38515 return -EBUSY;
38516
38517 if (cmd != SIOCWANDEV)
38518 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38519 index b38e954..ce45b38 100644
38520 --- a/drivers/tty/synclink_gt.c
38521 +++ b/drivers/tty/synclink_gt.c
38522 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38523 tty->driver_data = info;
38524 info->port.tty = tty;
38525
38526 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38527 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38528
38529 /* If port is closing, signal caller to try again */
38530 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38531 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38532 mutex_unlock(&info->port.mutex);
38533 goto cleanup;
38534 }
38535 - info->port.count++;
38536 + atomic_inc(&info->port.count);
38537 spin_unlock_irqrestore(&info->netlock, flags);
38538
38539 - if (info->port.count == 1) {
38540 + if (atomic_read(&info->port.count) == 1) {
38541 /* 1st open on this device, init hardware */
38542 retval = startup(info);
38543 if (retval < 0) {
38544 @@ -716,8 +716,8 @@ cleanup:
38545 if (retval) {
38546 if (tty->count == 1)
38547 info->port.tty = NULL; /* tty layer will release tty struct */
38548 - if(info->port.count)
38549 - info->port.count--;
38550 + if(atomic_read(&info->port.count))
38551 + atomic_dec(&info->port.count);
38552 }
38553
38554 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38555 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38556
38557 if (sanity_check(info, tty->name, "close"))
38558 return;
38559 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38560 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38561
38562 if (tty_port_close_start(&info->port, tty, filp) == 0)
38563 goto cleanup;
38564 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38565 tty_port_close_end(&info->port, tty);
38566 info->port.tty = NULL;
38567 cleanup:
38568 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38569 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38570 }
38571
38572 static void hangup(struct tty_struct *tty)
38573 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38574 shutdown(info);
38575
38576 spin_lock_irqsave(&info->port.lock, flags);
38577 - info->port.count = 0;
38578 + atomic_set(&info->port.count, 0);
38579 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38580 info->port.tty = NULL;
38581 spin_unlock_irqrestore(&info->port.lock, flags);
38582 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38583 unsigned short new_crctype;
38584
38585 /* return error if TTY interface open */
38586 - if (info->port.count)
38587 + if (atomic_read(&info->port.count))
38588 return -EBUSY;
38589
38590 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38591 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38592
38593 /* arbitrate between network and tty opens */
38594 spin_lock_irqsave(&info->netlock, flags);
38595 - if (info->port.count != 0 || info->netcount != 0) {
38596 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38597 DBGINFO(("%s hdlc_open busy\n", dev->name));
38598 spin_unlock_irqrestore(&info->netlock, flags);
38599 return -EBUSY;
38600 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38601 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38602
38603 /* return error if TTY interface open */
38604 - if (info->port.count)
38605 + if (atomic_read(&info->port.count))
38606 return -EBUSY;
38607
38608 if (cmd != SIOCWANDEV)
38609 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38610 if (port == NULL)
38611 continue;
38612 spin_lock(&port->lock);
38613 - if ((port->port.count || port->netcount) &&
38614 + if ((atomic_read(&port->port.count) || port->netcount) &&
38615 port->pending_bh && !port->bh_running &&
38616 !port->bh_requested) {
38617 DBGISR(("%s bh queued\n", port->device_name));
38618 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38619 spin_lock_irqsave(&info->lock, flags);
38620 if (!tty_hung_up_p(filp)) {
38621 extra_count = true;
38622 - port->count--;
38623 + atomic_dec(&port->count);
38624 }
38625 spin_unlock_irqrestore(&info->lock, flags);
38626 port->blocked_open++;
38627 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38628 remove_wait_queue(&port->open_wait, &wait);
38629
38630 if (extra_count)
38631 - port->count++;
38632 + atomic_inc(&port->count);
38633 port->blocked_open--;
38634
38635 if (!retval)
38636 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38637 index f17d9f3..27a041b 100644
38638 --- a/drivers/tty/synclinkmp.c
38639 +++ b/drivers/tty/synclinkmp.c
38640 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38641
38642 if (debug_level >= DEBUG_LEVEL_INFO)
38643 printk("%s(%d):%s open(), old ref count = %d\n",
38644 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38645 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38646
38647 /* If port is closing, signal caller to try again */
38648 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38649 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38650 spin_unlock_irqrestore(&info->netlock, flags);
38651 goto cleanup;
38652 }
38653 - info->port.count++;
38654 + atomic_inc(&info->port.count);
38655 spin_unlock_irqrestore(&info->netlock, flags);
38656
38657 - if (info->port.count == 1) {
38658 + if (atomic_read(&info->port.count) == 1) {
38659 /* 1st open on this device, init hardware */
38660 retval = startup(info);
38661 if (retval < 0)
38662 @@ -797,8 +797,8 @@ cleanup:
38663 if (retval) {
38664 if (tty->count == 1)
38665 info->port.tty = NULL; /* tty layer will release tty struct */
38666 - if(info->port.count)
38667 - info->port.count--;
38668 + if(atomic_read(&info->port.count))
38669 + atomic_dec(&info->port.count);
38670 }
38671
38672 return retval;
38673 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38674
38675 if (debug_level >= DEBUG_LEVEL_INFO)
38676 printk("%s(%d):%s close() entry, count=%d\n",
38677 - __FILE__,__LINE__, info->device_name, info->port.count);
38678 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38679
38680 if (tty_port_close_start(&info->port, tty, filp) == 0)
38681 goto cleanup;
38682 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38683 cleanup:
38684 if (debug_level >= DEBUG_LEVEL_INFO)
38685 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38686 - tty->driver->name, info->port.count);
38687 + tty->driver->name, atomic_read(&info->port.count));
38688 }
38689
38690 /* Called by tty_hangup() when a hangup is signaled.
38691 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
38692 shutdown(info);
38693
38694 spin_lock_irqsave(&info->port.lock, flags);
38695 - info->port.count = 0;
38696 + atomic_set(&info->port.count, 0);
38697 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38698 info->port.tty = NULL;
38699 spin_unlock_irqrestore(&info->port.lock, flags);
38700 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38701 unsigned short new_crctype;
38702
38703 /* return error if TTY interface open */
38704 - if (info->port.count)
38705 + if (atomic_read(&info->port.count))
38706 return -EBUSY;
38707
38708 switch (encoding)
38709 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
38710
38711 /* arbitrate between network and tty opens */
38712 spin_lock_irqsave(&info->netlock, flags);
38713 - if (info->port.count != 0 || info->netcount != 0) {
38714 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38715 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38716 spin_unlock_irqrestore(&info->netlock, flags);
38717 return -EBUSY;
38718 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38719 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38720
38721 /* return error if TTY interface open */
38722 - if (info->port.count)
38723 + if (atomic_read(&info->port.count))
38724 return -EBUSY;
38725
38726 if (cmd != SIOCWANDEV)
38727 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38728 * do not request bottom half processing if the
38729 * device is not open in a normal mode.
38730 */
38731 - if ( port && (port->port.count || port->netcount) &&
38732 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38733 port->pending_bh && !port->bh_running &&
38734 !port->bh_requested ) {
38735 if ( debug_level >= DEBUG_LEVEL_ISR )
38736 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38737
38738 if (debug_level >= DEBUG_LEVEL_INFO)
38739 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38740 - __FILE__,__LINE__, tty->driver->name, port->count );
38741 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38742
38743 spin_lock_irqsave(&info->lock, flags);
38744 if (!tty_hung_up_p(filp)) {
38745 extra_count = true;
38746 - port->count--;
38747 + atomic_dec(&port->count);
38748 }
38749 spin_unlock_irqrestore(&info->lock, flags);
38750 port->blocked_open++;
38751 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38752
38753 if (debug_level >= DEBUG_LEVEL_INFO)
38754 printk("%s(%d):%s block_til_ready() count=%d\n",
38755 - __FILE__,__LINE__, tty->driver->name, port->count );
38756 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38757
38758 tty_unlock(tty);
38759 schedule();
38760 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38761 remove_wait_queue(&port->open_wait, &wait);
38762
38763 if (extra_count)
38764 - port->count++;
38765 + atomic_inc(&port->count);
38766 port->blocked_open--;
38767
38768 if (debug_level >= DEBUG_LEVEL_INFO)
38769 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38770 - __FILE__,__LINE__, tty->driver->name, port->count );
38771 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38772
38773 if (!retval)
38774 port->flags |= ASYNC_NORMAL_ACTIVE;
38775 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38776 index 16ee6ce..bfcac57 100644
38777 --- a/drivers/tty/sysrq.c
38778 +++ b/drivers/tty/sysrq.c
38779 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38780 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38781 size_t count, loff_t *ppos)
38782 {
38783 - if (count) {
38784 + if (count && capable(CAP_SYS_ADMIN)) {
38785 char c;
38786
38787 if (get_user(c, buf))
38788 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38789 index 2ea176b..2877bc8 100644
38790 --- a/drivers/tty/tty_io.c
38791 +++ b/drivers/tty/tty_io.c
38792 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38793
38794 void tty_default_fops(struct file_operations *fops)
38795 {
38796 - *fops = tty_fops;
38797 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38798 }
38799
38800 /*
38801 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38802 index 0f2a2c5..471e228 100644
38803 --- a/drivers/tty/tty_ldisc.c
38804 +++ b/drivers/tty/tty_ldisc.c
38805 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38806 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38807 struct tty_ldisc_ops *ldo = ld->ops;
38808
38809 - ldo->refcount--;
38810 + atomic_dec(&ldo->refcount);
38811 module_put(ldo->owner);
38812 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38813
38814 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38815 spin_lock_irqsave(&tty_ldisc_lock, flags);
38816 tty_ldiscs[disc] = new_ldisc;
38817 new_ldisc->num = disc;
38818 - new_ldisc->refcount = 0;
38819 + atomic_set(&new_ldisc->refcount, 0);
38820 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38821
38822 return ret;
38823 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38824 return -EINVAL;
38825
38826 spin_lock_irqsave(&tty_ldisc_lock, flags);
38827 - if (tty_ldiscs[disc]->refcount)
38828 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38829 ret = -EBUSY;
38830 else
38831 tty_ldiscs[disc] = NULL;
38832 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38833 if (ldops) {
38834 ret = ERR_PTR(-EAGAIN);
38835 if (try_module_get(ldops->owner)) {
38836 - ldops->refcount++;
38837 + atomic_inc(&ldops->refcount);
38838 ret = ldops;
38839 }
38840 }
38841 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38842 unsigned long flags;
38843
38844 spin_lock_irqsave(&tty_ldisc_lock, flags);
38845 - ldops->refcount--;
38846 + atomic_dec(&ldops->refcount);
38847 module_put(ldops->owner);
38848 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38849 }
38850 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38851 index d7bdd8d..feaef30 100644
38852 --- a/drivers/tty/tty_port.c
38853 +++ b/drivers/tty/tty_port.c
38854 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
38855 unsigned long flags;
38856
38857 spin_lock_irqsave(&port->lock, flags);
38858 - port->count = 0;
38859 + atomic_set(&port->count, 0);
38860 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38861 if (port->tty) {
38862 set_bit(TTY_IO_ERROR, &port->tty->flags);
38863 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38864 /* The port lock protects the port counts */
38865 spin_lock_irqsave(&port->lock, flags);
38866 if (!tty_hung_up_p(filp))
38867 - port->count--;
38868 + atomic_dec(&port->count);
38869 port->blocked_open++;
38870 spin_unlock_irqrestore(&port->lock, flags);
38871
38872 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38873 we must not mess that up further */
38874 spin_lock_irqsave(&port->lock, flags);
38875 if (!tty_hung_up_p(filp))
38876 - port->count++;
38877 + atomic_inc(&port->count);
38878 port->blocked_open--;
38879 if (retval == 0)
38880 port->flags |= ASYNC_NORMAL_ACTIVE;
38881 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
38882 return 0;
38883 }
38884
38885 - if (tty->count == 1 && port->count != 1) {
38886 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38887 printk(KERN_WARNING
38888 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38889 - port->count);
38890 - port->count = 1;
38891 + atomic_read(&port->count));
38892 + atomic_set(&port->count, 1);
38893 }
38894 - if (--port->count < 0) {
38895 + if (atomic_dec_return(&port->count) < 0) {
38896 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38897 - port->count);
38898 - port->count = 0;
38899 + atomic_read(&port->count));
38900 + atomic_set(&port->count, 0);
38901 }
38902
38903 - if (port->count) {
38904 + if (atomic_read(&port->count)) {
38905 spin_unlock_irqrestore(&port->lock, flags);
38906 if (port->ops->drop)
38907 port->ops->drop(port);
38908 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38909 {
38910 spin_lock_irq(&port->lock);
38911 if (!tty_hung_up_p(filp))
38912 - ++port->count;
38913 + atomic_inc(&port->count);
38914 spin_unlock_irq(&port->lock);
38915 tty_port_tty_set(port, tty);
38916
38917 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38918 index 681765b..d3ccdf2 100644
38919 --- a/drivers/tty/vt/keyboard.c
38920 +++ b/drivers/tty/vt/keyboard.c
38921 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38922 kbd->kbdmode == VC_OFF) &&
38923 value != KVAL(K_SAK))
38924 return; /* SAK is allowed even in raw mode */
38925 +
38926 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38927 + {
38928 + void *func = fn_handler[value];
38929 + if (func == fn_show_state || func == fn_show_ptregs ||
38930 + func == fn_show_mem)
38931 + return;
38932 + }
38933 +#endif
38934 +
38935 fn_handler[value](vc);
38936 }
38937
38938 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38939 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38940 return -EFAULT;
38941
38942 - if (!capable(CAP_SYS_TTY_CONFIG))
38943 - perm = 0;
38944 -
38945 switch (cmd) {
38946 case KDGKBENT:
38947 /* Ensure another thread doesn't free it under us */
38948 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38949 spin_unlock_irqrestore(&kbd_event_lock, flags);
38950 return put_user(val, &user_kbe->kb_value);
38951 case KDSKBENT:
38952 + if (!capable(CAP_SYS_TTY_CONFIG))
38953 + perm = 0;
38954 +
38955 if (!perm)
38956 return -EPERM;
38957 if (!i && v == K_NOSUCHMAP) {
38958 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38959 int i, j, k;
38960 int ret;
38961
38962 - if (!capable(CAP_SYS_TTY_CONFIG))
38963 - perm = 0;
38964 -
38965 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38966 if (!kbs) {
38967 ret = -ENOMEM;
38968 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38969 kfree(kbs);
38970 return ((p && *p) ? -EOVERFLOW : 0);
38971 case KDSKBSENT:
38972 + if (!capable(CAP_SYS_TTY_CONFIG))
38973 + perm = 0;
38974 +
38975 if (!perm) {
38976 ret = -EPERM;
38977 goto reterr;
38978 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38979 index 5110f36..8dc0a74 100644
38980 --- a/drivers/uio/uio.c
38981 +++ b/drivers/uio/uio.c
38982 @@ -25,6 +25,7 @@
38983 #include <linux/kobject.h>
38984 #include <linux/cdev.h>
38985 #include <linux/uio_driver.h>
38986 +#include <asm/local.h>
38987
38988 #define UIO_MAX_DEVICES (1U << MINORBITS)
38989
38990 @@ -32,10 +33,10 @@ struct uio_device {
38991 struct module *owner;
38992 struct device *dev;
38993 int minor;
38994 - atomic_t event;
38995 + atomic_unchecked_t event;
38996 struct fasync_struct *async_queue;
38997 wait_queue_head_t wait;
38998 - int vma_count;
38999 + local_t vma_count;
39000 struct uio_info *info;
39001 struct kobject *map_dir;
39002 struct kobject *portio_dir;
39003 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39004 struct device_attribute *attr, char *buf)
39005 {
39006 struct uio_device *idev = dev_get_drvdata(dev);
39007 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39008 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39009 }
39010
39011 static struct device_attribute uio_class_attributes[] = {
39012 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39013 {
39014 struct uio_device *idev = info->uio_dev;
39015
39016 - atomic_inc(&idev->event);
39017 + atomic_inc_unchecked(&idev->event);
39018 wake_up_interruptible(&idev->wait);
39019 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39020 }
39021 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39022 }
39023
39024 listener->dev = idev;
39025 - listener->event_count = atomic_read(&idev->event);
39026 + listener->event_count = atomic_read_unchecked(&idev->event);
39027 filep->private_data = listener;
39028
39029 if (idev->info->open) {
39030 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39031 return -EIO;
39032
39033 poll_wait(filep, &idev->wait, wait);
39034 - if (listener->event_count != atomic_read(&idev->event))
39035 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39036 return POLLIN | POLLRDNORM;
39037 return 0;
39038 }
39039 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39040 do {
39041 set_current_state(TASK_INTERRUPTIBLE);
39042
39043 - event_count = atomic_read(&idev->event);
39044 + event_count = atomic_read_unchecked(&idev->event);
39045 if (event_count != listener->event_count) {
39046 if (copy_to_user(buf, &event_count, count))
39047 retval = -EFAULT;
39048 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39049 static void uio_vma_open(struct vm_area_struct *vma)
39050 {
39051 struct uio_device *idev = vma->vm_private_data;
39052 - idev->vma_count++;
39053 + local_inc(&idev->vma_count);
39054 }
39055
39056 static void uio_vma_close(struct vm_area_struct *vma)
39057 {
39058 struct uio_device *idev = vma->vm_private_data;
39059 - idev->vma_count--;
39060 + local_dec(&idev->vma_count);
39061 }
39062
39063 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39064 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
39065 idev->owner = owner;
39066 idev->info = info;
39067 init_waitqueue_head(&idev->wait);
39068 - atomic_set(&idev->event, 0);
39069 + atomic_set_unchecked(&idev->event, 0);
39070
39071 ret = uio_get_minor(idev);
39072 if (ret)
39073 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39074 index b7eb86a..36d28af 100644
39075 --- a/drivers/usb/atm/cxacru.c
39076 +++ b/drivers/usb/atm/cxacru.c
39077 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39078 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39079 if (ret < 2)
39080 return -EINVAL;
39081 - if (index < 0 || index > 0x7f)
39082 + if (index > 0x7f)
39083 return -EINVAL;
39084 pos += tmp;
39085
39086 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39087 index 35f10bf..6a38a0b 100644
39088 --- a/drivers/usb/atm/usbatm.c
39089 +++ b/drivers/usb/atm/usbatm.c
39090 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39091 if (printk_ratelimit())
39092 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39093 __func__, vpi, vci);
39094 - atomic_inc(&vcc->stats->rx_err);
39095 + atomic_inc_unchecked(&vcc->stats->rx_err);
39096 return;
39097 }
39098
39099 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39100 if (length > ATM_MAX_AAL5_PDU) {
39101 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39102 __func__, length, vcc);
39103 - atomic_inc(&vcc->stats->rx_err);
39104 + atomic_inc_unchecked(&vcc->stats->rx_err);
39105 goto out;
39106 }
39107
39108 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39109 if (sarb->len < pdu_length) {
39110 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39111 __func__, pdu_length, sarb->len, vcc);
39112 - atomic_inc(&vcc->stats->rx_err);
39113 + atomic_inc_unchecked(&vcc->stats->rx_err);
39114 goto out;
39115 }
39116
39117 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39118 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39119 __func__, vcc);
39120 - atomic_inc(&vcc->stats->rx_err);
39121 + atomic_inc_unchecked(&vcc->stats->rx_err);
39122 goto out;
39123 }
39124
39125 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39126 if (printk_ratelimit())
39127 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39128 __func__, length);
39129 - atomic_inc(&vcc->stats->rx_drop);
39130 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39131 goto out;
39132 }
39133
39134 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39135
39136 vcc->push(vcc, skb);
39137
39138 - atomic_inc(&vcc->stats->rx);
39139 + atomic_inc_unchecked(&vcc->stats->rx);
39140 out:
39141 skb_trim(sarb, 0);
39142 }
39143 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
39144 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39145
39146 usbatm_pop(vcc, skb);
39147 - atomic_inc(&vcc->stats->tx);
39148 + atomic_inc_unchecked(&vcc->stats->tx);
39149
39150 skb = skb_dequeue(&instance->sndqueue);
39151 }
39152 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39153 if (!left--)
39154 return sprintf(page,
39155 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39156 - atomic_read(&atm_dev->stats.aal5.tx),
39157 - atomic_read(&atm_dev->stats.aal5.tx_err),
39158 - atomic_read(&atm_dev->stats.aal5.rx),
39159 - atomic_read(&atm_dev->stats.aal5.rx_err),
39160 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39161 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39162 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39163 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39164 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39165 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39166
39167 if (!left--) {
39168 if (instance->disconnected)
39169 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39170 index f460de3..95ba1f6 100644
39171 --- a/drivers/usb/core/devices.c
39172 +++ b/drivers/usb/core/devices.c
39173 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39174 * time it gets called.
39175 */
39176 static struct device_connect_event {
39177 - atomic_t count;
39178 + atomic_unchecked_t count;
39179 wait_queue_head_t wait;
39180 } device_event = {
39181 .count = ATOMIC_INIT(1),
39182 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39183
39184 void usbfs_conn_disc_event(void)
39185 {
39186 - atomic_add(2, &device_event.count);
39187 + atomic_add_unchecked(2, &device_event.count);
39188 wake_up(&device_event.wait);
39189 }
39190
39191 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
39192
39193 poll_wait(file, &device_event.wait, wait);
39194
39195 - event_count = atomic_read(&device_event.count);
39196 + event_count = atomic_read_unchecked(&device_event.count);
39197 if (file->f_version != event_count) {
39198 file->f_version = event_count;
39199 return POLLIN | POLLRDNORM;
39200 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
39201 index f034716..aed0368 100644
39202 --- a/drivers/usb/core/hcd.c
39203 +++ b/drivers/usb/core/hcd.c
39204 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39205 */
39206 usb_get_urb(urb);
39207 atomic_inc(&urb->use_count);
39208 - atomic_inc(&urb->dev->urbnum);
39209 + atomic_inc_unchecked(&urb->dev->urbnum);
39210 usbmon_urb_submit(&hcd->self, urb);
39211
39212 /* NOTE requirements on root-hub callers (usbfs and the hub
39213 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39214 urb->hcpriv = NULL;
39215 INIT_LIST_HEAD(&urb->urb_list);
39216 atomic_dec(&urb->use_count);
39217 - atomic_dec(&urb->dev->urbnum);
39218 + atomic_dec_unchecked(&urb->dev->urbnum);
39219 if (atomic_read(&urb->reject))
39220 wake_up(&usb_kill_urb_queue);
39221 usb_put_urb(urb);
39222 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
39223 index 818e4a0..0fc9589 100644
39224 --- a/drivers/usb/core/sysfs.c
39225 +++ b/drivers/usb/core/sysfs.c
39226 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
39227 struct usb_device *udev;
39228
39229 udev = to_usb_device(dev);
39230 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
39231 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
39232 }
39233 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
39234
39235 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
39236 index cd8fb44..17fbe0c 100644
39237 --- a/drivers/usb/core/usb.c
39238 +++ b/drivers/usb/core/usb.c
39239 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
39240 set_dev_node(&dev->dev, dev_to_node(bus->controller));
39241 dev->state = USB_STATE_ATTACHED;
39242 dev->lpm_disable_count = 1;
39243 - atomic_set(&dev->urbnum, 0);
39244 + atomic_set_unchecked(&dev->urbnum, 0);
39245
39246 INIT_LIST_HEAD(&dev->ep0.urb_list);
39247 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
39248 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39249 index 4bfa78a..902bfbd 100644
39250 --- a/drivers/usb/early/ehci-dbgp.c
39251 +++ b/drivers/usb/early/ehci-dbgp.c
39252 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39253
39254 #ifdef CONFIG_KGDB
39255 static struct kgdb_io kgdbdbgp_io_ops;
39256 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39257 +static struct kgdb_io kgdbdbgp_io_ops_console;
39258 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39259 #else
39260 #define dbgp_kgdb_mode (0)
39261 #endif
39262 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39263 .write_char = kgdbdbgp_write_char,
39264 };
39265
39266 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39267 + .name = "kgdbdbgp",
39268 + .read_char = kgdbdbgp_read_char,
39269 + .write_char = kgdbdbgp_write_char,
39270 + .is_console = 1
39271 +};
39272 +
39273 static int kgdbdbgp_wait_time;
39274
39275 static int __init kgdbdbgp_parse_config(char *str)
39276 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39277 ptr++;
39278 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39279 }
39280 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39281 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39282 + if (early_dbgp_console.index != -1)
39283 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39284 + else
39285 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39286
39287 return 0;
39288 }
39289 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39290 index f173952..83d6ec0 100644
39291 --- a/drivers/usb/gadget/u_serial.c
39292 +++ b/drivers/usb/gadget/u_serial.c
39293 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39294 spin_lock_irq(&port->port_lock);
39295
39296 /* already open? Great. */
39297 - if (port->port.count) {
39298 + if (atomic_read(&port->port.count)) {
39299 status = 0;
39300 - port->port.count++;
39301 + atomic_inc(&port->port.count);
39302
39303 /* currently opening/closing? wait ... */
39304 } else if (port->openclose) {
39305 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39306 tty->driver_data = port;
39307 port->port.tty = tty;
39308
39309 - port->port.count = 1;
39310 + atomic_set(&port->port.count, 1);
39311 port->openclose = false;
39312
39313 /* if connected, start the I/O stream */
39314 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39315
39316 spin_lock_irq(&port->port_lock);
39317
39318 - if (port->port.count != 1) {
39319 - if (port->port.count == 0)
39320 + if (atomic_read(&port->port.count) != 1) {
39321 + if (atomic_read(&port->port.count) == 0)
39322 WARN_ON(1);
39323 else
39324 - --port->port.count;
39325 + atomic_dec(&port->port.count);
39326 goto exit;
39327 }
39328
39329 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39330 * and sleep if necessary
39331 */
39332 port->openclose = true;
39333 - port->port.count = 0;
39334 + atomic_set(&port->port.count, 0);
39335
39336 gser = port->port_usb;
39337 if (gser && gser->disconnect)
39338 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
39339 int cond;
39340
39341 spin_lock_irq(&port->port_lock);
39342 - cond = (port->port.count == 0) && !port->openclose;
39343 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39344 spin_unlock_irq(&port->port_lock);
39345 return cond;
39346 }
39347 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39348 /* if it's already open, start I/O ... and notify the serial
39349 * protocol about open/close status (connect/disconnect).
39350 */
39351 - if (port->port.count) {
39352 + if (atomic_read(&port->port.count)) {
39353 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39354 gs_start_io(port);
39355 if (gser->connect)
39356 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
39357
39358 port->port_usb = NULL;
39359 gser->ioport = NULL;
39360 - if (port->port.count > 0 || port->openclose) {
39361 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39362 wake_up_interruptible(&port->drain_wait);
39363 if (port->port.tty)
39364 tty_hangup(port->port.tty);
39365 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
39366
39367 /* finally, free any unused/unusable I/O buffers */
39368 spin_lock_irqsave(&port->port_lock, flags);
39369 - if (port->port.count == 0 && !port->openclose)
39370 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39371 gs_buf_free(&port->port_write_buf);
39372 gs_free_requests(gser->out, &port->read_pool, NULL);
39373 gs_free_requests(gser->out, &port->read_queue, NULL);
39374 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39375 index 5f3bcd3..bfca43f 100644
39376 --- a/drivers/usb/serial/console.c
39377 +++ b/drivers/usb/serial/console.c
39378 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
39379
39380 info->port = port;
39381
39382 - ++port->port.count;
39383 + atomic_inc(&port->port.count);
39384 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39385 if (serial->type->set_termios) {
39386 /*
39387 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
39388 }
39389 /* Now that any required fake tty operations are completed restore
39390 * the tty port count */
39391 - --port->port.count;
39392 + atomic_dec(&port->port.count);
39393 /* The console is special in terms of closing the device so
39394 * indicate this port is now acting as a system console. */
39395 port->port.console = 1;
39396 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
39397 free_tty:
39398 kfree(tty);
39399 reset_open_count:
39400 - port->port.count = 0;
39401 + atomic_set(&port->port.count, 0);
39402 usb_autopm_put_interface(serial->interface);
39403 error_get_interface:
39404 usb_serial_put(serial);
39405 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39406 index d6bea3e..60b250e 100644
39407 --- a/drivers/usb/wusbcore/wa-hc.h
39408 +++ b/drivers/usb/wusbcore/wa-hc.h
39409 @@ -192,7 +192,7 @@ struct wahc {
39410 struct list_head xfer_delayed_list;
39411 spinlock_t xfer_list_lock;
39412 struct work_struct xfer_work;
39413 - atomic_t xfer_id_count;
39414 + atomic_unchecked_t xfer_id_count;
39415 };
39416
39417
39418 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39419 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39420 spin_lock_init(&wa->xfer_list_lock);
39421 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39422 - atomic_set(&wa->xfer_id_count, 1);
39423 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39424 }
39425
39426 /**
39427 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39428 index 57c01ab..8a05959 100644
39429 --- a/drivers/usb/wusbcore/wa-xfer.c
39430 +++ b/drivers/usb/wusbcore/wa-xfer.c
39431 @@ -296,7 +296,7 @@ out:
39432 */
39433 static void wa_xfer_id_init(struct wa_xfer *xfer)
39434 {
39435 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39436 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39437 }
39438
39439 /*
39440 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39441 index dedaf81..b0f11ab 100644
39442 --- a/drivers/vhost/vhost.c
39443 +++ b/drivers/vhost/vhost.c
39444 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39445 return 0;
39446 }
39447
39448 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39449 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39450 {
39451 struct file *eventfp, *filep = NULL;
39452 bool pollstart = false, pollstop = false;
39453 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39454 index 0fefa84..7a9d581 100644
39455 --- a/drivers/video/aty/aty128fb.c
39456 +++ b/drivers/video/aty/aty128fb.c
39457 @@ -149,7 +149,7 @@ enum {
39458 };
39459
39460 /* Must match above enum */
39461 -static char * const r128_family[] __devinitconst = {
39462 +static const char * const r128_family[] __devinitconst = {
39463 "AGP",
39464 "PCI",
39465 "PRO AGP",
39466 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39467 index 5c3960d..15cf8fc 100644
39468 --- a/drivers/video/fbcmap.c
39469 +++ b/drivers/video/fbcmap.c
39470 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39471 rc = -ENODEV;
39472 goto out;
39473 }
39474 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39475 - !info->fbops->fb_setcmap)) {
39476 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39477 rc = -EINVAL;
39478 goto out1;
39479 }
39480 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39481 index 3ff0105..7589d98 100644
39482 --- a/drivers/video/fbmem.c
39483 +++ b/drivers/video/fbmem.c
39484 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39485 image->dx += image->width + 8;
39486 }
39487 } else if (rotate == FB_ROTATE_UD) {
39488 - for (x = 0; x < num && image->dx >= 0; x++) {
39489 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39490 info->fbops->fb_imageblit(info, image);
39491 image->dx -= image->width + 8;
39492 }
39493 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39494 image->dy += image->height + 8;
39495 }
39496 } else if (rotate == FB_ROTATE_CCW) {
39497 - for (x = 0; x < num && image->dy >= 0; x++) {
39498 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39499 info->fbops->fb_imageblit(info, image);
39500 image->dy -= image->height + 8;
39501 }
39502 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39503 return -EFAULT;
39504 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39505 return -EINVAL;
39506 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39507 + if (con2fb.framebuffer >= FB_MAX)
39508 return -EINVAL;
39509 if (!registered_fb[con2fb.framebuffer])
39510 request_module("fb%d", con2fb.framebuffer);
39511 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39512 index 7672d2e..b56437f 100644
39513 --- a/drivers/video/i810/i810_accel.c
39514 +++ b/drivers/video/i810/i810_accel.c
39515 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39516 }
39517 }
39518 printk("ringbuffer lockup!!!\n");
39519 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39520 i810_report_error(mmio);
39521 par->dev_flags |= LOCKUP;
39522 info->pixmap.scan_align = 1;
39523 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39524 index 3c14e43..eafa544 100644
39525 --- a/drivers/video/logo/logo_linux_clut224.ppm
39526 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39527 @@ -1,1604 +1,1123 @@
39528 P3
39529 -# Standard 224-color Linux logo
39530 80 80
39531 255
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 6 6 6 6 6 6 10 10 10 10 10 10
39542 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 6 6 6 10 10 10 14 14 14
39561 - 22 22 22 26 26 26 30 30 30 34 34 34
39562 - 30 30 30 30 30 30 26 26 26 18 18 18
39563 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 6 6 6 14 14 14 26 26 26 42 42 42
39581 - 54 54 54 66 66 66 78 78 78 78 78 78
39582 - 78 78 78 74 74 74 66 66 66 54 54 54
39583 - 42 42 42 26 26 26 18 18 18 10 10 10
39584 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 1 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 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 10 10 10
39600 - 22 22 22 42 42 42 66 66 66 86 86 86
39601 - 66 66 66 38 38 38 38 38 38 22 22 22
39602 - 26 26 26 34 34 34 54 54 54 66 66 66
39603 - 86 86 86 70 70 70 46 46 46 26 26 26
39604 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 10 10 10 26 26 26
39620 - 50 50 50 82 82 82 58 58 58 6 6 6
39621 - 2 2 6 2 2 6 2 2 6 2 2 6
39622 - 2 2 6 2 2 6 2 2 6 2 2 6
39623 - 6 6 6 54 54 54 86 86 86 66 66 66
39624 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 6 6 6 22 22 22 50 50 50
39640 - 78 78 78 34 34 34 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 2 2 6 2 2 6
39643 - 2 2 6 2 2 6 6 6 6 70 70 70
39644 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 6 6 6 18 18 18 42 42 42 82 82 82
39660 - 26 26 26 2 2 6 2 2 6 2 2 6
39661 - 2 2 6 2 2 6 2 2 6 2 2 6
39662 - 2 2 6 2 2 6 2 2 6 14 14 14
39663 - 46 46 46 34 34 34 6 6 6 2 2 6
39664 - 42 42 42 78 78 78 42 42 42 18 18 18
39665 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 1 0 0 0 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 10 10 10 30 30 30 66 66 66 58 58 58
39680 - 2 2 6 2 2 6 2 2 6 2 2 6
39681 - 2 2 6 2 2 6 2 2 6 2 2 6
39682 - 2 2 6 2 2 6 2 2 6 26 26 26
39683 - 86 86 86 101 101 101 46 46 46 10 10 10
39684 - 2 2 6 58 58 58 70 70 70 34 34 34
39685 - 10 10 10 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 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 14 14 14 42 42 42 86 86 86 10 10 10
39700 - 2 2 6 2 2 6 2 2 6 2 2 6
39701 - 2 2 6 2 2 6 2 2 6 2 2 6
39702 - 2 2 6 2 2 6 2 2 6 30 30 30
39703 - 94 94 94 94 94 94 58 58 58 26 26 26
39704 - 2 2 6 6 6 6 78 78 78 54 54 54
39705 - 22 22 22 6 6 6 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 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 6 6 6
39719 - 22 22 22 62 62 62 62 62 62 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 2 2 6
39722 - 2 2 6 2 2 6 2 2 6 26 26 26
39723 - 54 54 54 38 38 38 18 18 18 10 10 10
39724 - 2 2 6 2 2 6 34 34 34 82 82 82
39725 - 38 38 38 14 14 14 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 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 1 0 0 1 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 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 6 6 6
39739 - 30 30 30 78 78 78 30 30 30 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 2 2 6
39742 - 2 2 6 2 2 6 2 2 6 10 10 10
39743 - 10 10 10 2 2 6 2 2 6 2 2 6
39744 - 2 2 6 2 2 6 2 2 6 78 78 78
39745 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 1 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 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 10 10 10
39759 - 38 38 38 86 86 86 14 14 14 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 2 2 6
39764 - 2 2 6 2 2 6 2 2 6 54 54 54
39765 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 1 0 0 1 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 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 14 14 14
39779 - 42 42 42 82 82 82 2 2 6 2 2 6
39780 - 2 2 6 6 6 6 10 10 10 2 2 6
39781 - 2 2 6 2 2 6 2 2 6 2 2 6
39782 - 2 2 6 2 2 6 2 2 6 6 6 6
39783 - 14 14 14 10 10 10 2 2 6 2 2 6
39784 - 2 2 6 2 2 6 2 2 6 18 18 18
39785 - 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 1 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 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 14 14 14
39799 - 46 46 46 86 86 86 2 2 6 2 2 6
39800 - 6 6 6 6 6 6 22 22 22 34 34 34
39801 - 6 6 6 2 2 6 2 2 6 2 2 6
39802 - 2 2 6 2 2 6 18 18 18 34 34 34
39803 - 10 10 10 50 50 50 22 22 22 2 2 6
39804 - 2 2 6 2 2 6 2 2 6 10 10 10
39805 - 86 86 86 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 14 14 14
39819 - 46 46 46 86 86 86 2 2 6 2 2 6
39820 - 38 38 38 116 116 116 94 94 94 22 22 22
39821 - 22 22 22 2 2 6 2 2 6 2 2 6
39822 - 14 14 14 86 86 86 138 138 138 162 162 162
39823 -154 154 154 38 38 38 26 26 26 6 6 6
39824 - 2 2 6 2 2 6 2 2 6 2 2 6
39825 - 86 86 86 46 46 46 14 14 14 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 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 14 14 14
39839 - 46 46 46 86 86 86 2 2 6 14 14 14
39840 -134 134 134 198 198 198 195 195 195 116 116 116
39841 - 10 10 10 2 2 6 2 2 6 6 6 6
39842 -101 98 89 187 187 187 210 210 210 218 218 218
39843 -214 214 214 134 134 134 14 14 14 6 6 6
39844 - 2 2 6 2 2 6 2 2 6 2 2 6
39845 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 1 0 0 0
39853 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 14 14 14
39859 - 46 46 46 86 86 86 2 2 6 54 54 54
39860 -218 218 218 195 195 195 226 226 226 246 246 246
39861 - 58 58 58 2 2 6 2 2 6 30 30 30
39862 -210 210 210 253 253 253 174 174 174 123 123 123
39863 -221 221 221 234 234 234 74 74 74 2 2 6
39864 - 2 2 6 2 2 6 2 2 6 2 2 6
39865 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 14 14 14
39879 - 46 46 46 82 82 82 2 2 6 106 106 106
39880 -170 170 170 26 26 26 86 86 86 226 226 226
39881 -123 123 123 10 10 10 14 14 14 46 46 46
39882 -231 231 231 190 190 190 6 6 6 70 70 70
39883 - 90 90 90 238 238 238 158 158 158 2 2 6
39884 - 2 2 6 2 2 6 2 2 6 2 2 6
39885 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 1 0 0 0
39893 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 14 14 14
39899 - 42 42 42 86 86 86 6 6 6 116 116 116
39900 -106 106 106 6 6 6 70 70 70 149 149 149
39901 -128 128 128 18 18 18 38 38 38 54 54 54
39902 -221 221 221 106 106 106 2 2 6 14 14 14
39903 - 46 46 46 190 190 190 198 198 198 2 2 6
39904 - 2 2 6 2 2 6 2 2 6 2 2 6
39905 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 1 0 0 0
39913 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 14 14 14
39919 - 42 42 42 94 94 94 14 14 14 101 101 101
39920 -128 128 128 2 2 6 18 18 18 116 116 116
39921 -118 98 46 121 92 8 121 92 8 98 78 10
39922 -162 162 162 106 106 106 2 2 6 2 2 6
39923 - 2 2 6 195 195 195 195 195 195 6 6 6
39924 - 2 2 6 2 2 6 2 2 6 2 2 6
39925 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 1 0 0 1
39933 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 10 10 10
39939 - 38 38 38 90 90 90 14 14 14 58 58 58
39940 -210 210 210 26 26 26 54 38 6 154 114 10
39941 -226 170 11 236 186 11 225 175 15 184 144 12
39942 -215 174 15 175 146 61 37 26 9 2 2 6
39943 - 70 70 70 246 246 246 138 138 138 2 2 6
39944 - 2 2 6 2 2 6 2 2 6 2 2 6
39945 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 10 10 10
39959 - 38 38 38 86 86 86 14 14 14 10 10 10
39960 -195 195 195 188 164 115 192 133 9 225 175 15
39961 -239 182 13 234 190 10 232 195 16 232 200 30
39962 -245 207 45 241 208 19 232 195 16 184 144 12
39963 -218 194 134 211 206 186 42 42 42 2 2 6
39964 - 2 2 6 2 2 6 2 2 6 2 2 6
39965 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 10 10 10
39979 - 34 34 34 86 86 86 14 14 14 2 2 6
39980 -121 87 25 192 133 9 219 162 10 239 182 13
39981 -236 186 11 232 195 16 241 208 19 244 214 54
39982 -246 218 60 246 218 38 246 215 20 241 208 19
39983 -241 208 19 226 184 13 121 87 25 2 2 6
39984 - 2 2 6 2 2 6 2 2 6 2 2 6
39985 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 10 10 10
39999 - 34 34 34 82 82 82 30 30 30 61 42 6
40000 -180 123 7 206 145 10 230 174 11 239 182 13
40001 -234 190 10 238 202 15 241 208 19 246 218 74
40002 -246 218 38 246 215 20 246 215 20 246 215 20
40003 -226 184 13 215 174 15 184 144 12 6 6 6
40004 - 2 2 6 2 2 6 2 2 6 2 2 6
40005 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 10 10 10
40019 - 30 30 30 78 78 78 50 50 50 104 69 6
40020 -192 133 9 216 158 10 236 178 12 236 186 11
40021 -232 195 16 241 208 19 244 214 54 245 215 43
40022 -246 215 20 246 215 20 241 208 19 198 155 10
40023 -200 144 11 216 158 10 156 118 10 2 2 6
40024 - 2 2 6 2 2 6 2 2 6 2 2 6
40025 - 6 6 6 90 90 90 54 54 54 18 18 18
40026 - 6 6 6 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 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 10 10 10
40039 - 30 30 30 78 78 78 46 46 46 22 22 22
40040 -137 92 6 210 162 10 239 182 13 238 190 10
40041 -238 202 15 241 208 19 246 215 20 246 215 20
40042 -241 208 19 203 166 17 185 133 11 210 150 10
40043 -216 158 10 210 150 10 102 78 10 2 2 6
40044 - 6 6 6 54 54 54 14 14 14 2 2 6
40045 - 2 2 6 62 62 62 74 74 74 30 30 30
40046 - 10 10 10 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 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 10 10 10
40059 - 34 34 34 78 78 78 50 50 50 6 6 6
40060 - 94 70 30 139 102 15 190 146 13 226 184 13
40061 -232 200 30 232 195 16 215 174 15 190 146 13
40062 -168 122 10 192 133 9 210 150 10 213 154 11
40063 -202 150 34 182 157 106 101 98 89 2 2 6
40064 - 2 2 6 78 78 78 116 116 116 58 58 58
40065 - 2 2 6 22 22 22 90 90 90 46 46 46
40066 - 18 18 18 6 6 6 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 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 10 10 10
40079 - 38 38 38 86 86 86 50 50 50 6 6 6
40080 -128 128 128 174 154 114 156 107 11 168 122 10
40081 -198 155 10 184 144 12 197 138 11 200 144 11
40082 -206 145 10 206 145 10 197 138 11 188 164 115
40083 -195 195 195 198 198 198 174 174 174 14 14 14
40084 - 2 2 6 22 22 22 116 116 116 116 116 116
40085 - 22 22 22 2 2 6 74 74 74 70 70 70
40086 - 30 30 30 10 10 10 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 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 6 6 6 18 18 18
40099 - 50 50 50 101 101 101 26 26 26 10 10 10
40100 -138 138 138 190 190 190 174 154 114 156 107 11
40101 -197 138 11 200 144 11 197 138 11 192 133 9
40102 -180 123 7 190 142 34 190 178 144 187 187 187
40103 -202 202 202 221 221 221 214 214 214 66 66 66
40104 - 2 2 6 2 2 6 50 50 50 62 62 62
40105 - 6 6 6 2 2 6 10 10 10 90 90 90
40106 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 10 10 10 34 34 34
40119 - 74 74 74 74 74 74 2 2 6 6 6 6
40120 -144 144 144 198 198 198 190 190 190 178 166 146
40121 -154 121 60 156 107 11 156 107 11 168 124 44
40122 -174 154 114 187 187 187 190 190 190 210 210 210
40123 -246 246 246 253 253 253 253 253 253 182 182 182
40124 - 6 6 6 2 2 6 2 2 6 2 2 6
40125 - 2 2 6 2 2 6 2 2 6 62 62 62
40126 - 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 10 10 10 22 22 22 54 54 54
40139 - 94 94 94 18 18 18 2 2 6 46 46 46
40140 -234 234 234 221 221 221 190 190 190 190 190 190
40141 -190 190 190 187 187 187 187 187 187 190 190 190
40142 -190 190 190 195 195 195 214 214 214 242 242 242
40143 -253 253 253 253 253 253 253 253 253 253 253 253
40144 - 82 82 82 2 2 6 2 2 6 2 2 6
40145 - 2 2 6 2 2 6 2 2 6 14 14 14
40146 - 86 86 86 54 54 54 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 6 6 6 18 18 18 46 46 46 90 90 90
40159 - 46 46 46 18 18 18 6 6 6 182 182 182
40160 -253 253 253 246 246 246 206 206 206 190 190 190
40161 -190 190 190 190 190 190 190 190 190 190 190 190
40162 -206 206 206 231 231 231 250 250 250 253 253 253
40163 -253 253 253 253 253 253 253 253 253 253 253 253
40164 -202 202 202 14 14 14 2 2 6 2 2 6
40165 - 2 2 6 2 2 6 2 2 6 2 2 6
40166 - 42 42 42 86 86 86 42 42 42 18 18 18
40167 - 6 6 6 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 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 6 6 6
40178 - 14 14 14 38 38 38 74 74 74 66 66 66
40179 - 2 2 6 6 6 6 90 90 90 250 250 250
40180 -253 253 253 253 253 253 238 238 238 198 198 198
40181 -190 190 190 190 190 190 195 195 195 221 221 221
40182 -246 246 246 253 253 253 253 253 253 253 253 253
40183 -253 253 253 253 253 253 253 253 253 253 253 253
40184 -253 253 253 82 82 82 2 2 6 2 2 6
40185 - 2 2 6 2 2 6 2 2 6 2 2 6
40186 - 2 2 6 78 78 78 70 70 70 34 34 34
40187 - 14 14 14 6 6 6 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 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 14 14 14
40198 - 34 34 34 66 66 66 78 78 78 6 6 6
40199 - 2 2 6 18 18 18 218 218 218 253 253 253
40200 -253 253 253 253 253 253 253 253 253 246 246 246
40201 -226 226 226 231 231 231 246 246 246 253 253 253
40202 -253 253 253 253 253 253 253 253 253 253 253 253
40203 -253 253 253 253 253 253 253 253 253 253 253 253
40204 -253 253 253 178 178 178 2 2 6 2 2 6
40205 - 2 2 6 2 2 6 2 2 6 2 2 6
40206 - 2 2 6 18 18 18 90 90 90 62 62 62
40207 - 30 30 30 10 10 10 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 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 10 10 10 26 26 26
40218 - 58 58 58 90 90 90 18 18 18 2 2 6
40219 - 2 2 6 110 110 110 253 253 253 253 253 253
40220 -253 253 253 253 253 253 253 253 253 253 253 253
40221 -250 250 250 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 253 253 253 253 253 253 253 253 253
40224 -253 253 253 231 231 231 18 18 18 2 2 6
40225 - 2 2 6 2 2 6 2 2 6 2 2 6
40226 - 2 2 6 2 2 6 18 18 18 94 94 94
40227 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 6 6 6 22 22 22 50 50 50
40238 - 90 90 90 26 26 26 2 2 6 2 2 6
40239 - 14 14 14 195 195 195 250 250 250 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 -253 253 253 253 253 253 253 253 253 253 253 253
40244 -250 250 250 242 242 242 54 54 54 2 2 6
40245 - 2 2 6 2 2 6 2 2 6 2 2 6
40246 - 2 2 6 2 2 6 2 2 6 38 38 38
40247 - 86 86 86 50 50 50 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 6 6 6 14 14 14 38 38 38 82 82 82
40258 - 34 34 34 2 2 6 2 2 6 2 2 6
40259 - 42 42 42 195 195 195 246 246 246 253 253 253
40260 -253 253 253 253 253 253 253 253 253 250 250 250
40261 -242 242 242 242 242 242 250 250 250 253 253 253
40262 -253 253 253 253 253 253 253 253 253 253 253 253
40263 -253 253 253 250 250 250 246 246 246 238 238 238
40264 -226 226 226 231 231 231 101 101 101 6 6 6
40265 - 2 2 6 2 2 6 2 2 6 2 2 6
40266 - 2 2 6 2 2 6 2 2 6 2 2 6
40267 - 38 38 38 82 82 82 42 42 42 14 14 14
40268 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 10 10 10 26 26 26 62 62 62 66 66 66
40278 - 2 2 6 2 2 6 2 2 6 6 6 6
40279 - 70 70 70 170 170 170 206 206 206 234 234 234
40280 -246 246 246 250 250 250 250 250 250 238 238 238
40281 -226 226 226 231 231 231 238 238 238 250 250 250
40282 -250 250 250 250 250 250 246 246 246 231 231 231
40283 -214 214 214 206 206 206 202 202 202 202 202 202
40284 -198 198 198 202 202 202 182 182 182 18 18 18
40285 - 2 2 6 2 2 6 2 2 6 2 2 6
40286 - 2 2 6 2 2 6 2 2 6 2 2 6
40287 - 2 2 6 62 62 62 66 66 66 30 30 30
40288 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 14 14 14 42 42 42 82 82 82 18 18 18
40298 - 2 2 6 2 2 6 2 2 6 10 10 10
40299 - 94 94 94 182 182 182 218 218 218 242 242 242
40300 -250 250 250 253 253 253 253 253 253 250 250 250
40301 -234 234 234 253 253 253 253 253 253 253 253 253
40302 -253 253 253 253 253 253 253 253 253 246 246 246
40303 -238 238 238 226 226 226 210 210 210 202 202 202
40304 -195 195 195 195 195 195 210 210 210 158 158 158
40305 - 6 6 6 14 14 14 50 50 50 14 14 14
40306 - 2 2 6 2 2 6 2 2 6 2 2 6
40307 - 2 2 6 6 6 6 86 86 86 46 46 46
40308 - 18 18 18 6 6 6 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 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 6 6 6
40317 - 22 22 22 54 54 54 70 70 70 2 2 6
40318 - 2 2 6 10 10 10 2 2 6 22 22 22
40319 -166 166 166 231 231 231 250 250 250 253 253 253
40320 -253 253 253 253 253 253 253 253 253 250 250 250
40321 -242 242 242 253 253 253 253 253 253 253 253 253
40322 -253 253 253 253 253 253 253 253 253 253 253 253
40323 -253 253 253 253 253 253 253 253 253 246 246 246
40324 -231 231 231 206 206 206 198 198 198 226 226 226
40325 - 94 94 94 2 2 6 6 6 6 38 38 38
40326 - 30 30 30 2 2 6 2 2 6 2 2 6
40327 - 2 2 6 2 2 6 62 62 62 66 66 66
40328 - 26 26 26 10 10 10 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 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 10 10 10
40337 - 30 30 30 74 74 74 50 50 50 2 2 6
40338 - 26 26 26 26 26 26 2 2 6 106 106 106
40339 -238 238 238 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 253 253 253 253 253 253 253 253 253
40344 -253 253 253 246 246 246 218 218 218 202 202 202
40345 -210 210 210 14 14 14 2 2 6 2 2 6
40346 - 30 30 30 22 22 22 2 2 6 2 2 6
40347 - 2 2 6 2 2 6 18 18 18 86 86 86
40348 - 42 42 42 14 14 14 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 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 14 14 14
40357 - 42 42 42 90 90 90 22 22 22 2 2 6
40358 - 42 42 42 2 2 6 18 18 18 218 218 218
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 253 253 253 253 253 253
40364 -253 253 253 253 253 253 250 250 250 221 221 221
40365 -218 218 218 101 101 101 2 2 6 14 14 14
40366 - 18 18 18 38 38 38 10 10 10 2 2 6
40367 - 2 2 6 2 2 6 2 2 6 78 78 78
40368 - 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 6 6 6 18 18 18
40377 - 54 54 54 82 82 82 2 2 6 26 26 26
40378 - 22 22 22 2 2 6 123 123 123 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 253 253 253
40384 -253 253 253 253 253 253 253 253 253 250 250 250
40385 -238 238 238 198 198 198 6 6 6 38 38 38
40386 - 58 58 58 26 26 26 38 38 38 2 2 6
40387 - 2 2 6 2 2 6 2 2 6 46 46 46
40388 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 10 10 10 30 30 30
40397 - 74 74 74 58 58 58 2 2 6 42 42 42
40398 - 2 2 6 22 22 22 231 231 231 253 253 253
40399 -253 253 253 253 253 253 253 253 253 253 253 253
40400 -253 253 253 253 253 253 253 253 253 250 250 250
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 253 253 253 253 253 253 253 253 253
40405 -253 253 253 246 246 246 46 46 46 38 38 38
40406 - 42 42 42 14 14 14 38 38 38 14 14 14
40407 - 2 2 6 2 2 6 2 2 6 6 6 6
40408 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 6 6 6 14 14 14 42 42 42
40417 - 90 90 90 18 18 18 18 18 18 26 26 26
40418 - 2 2 6 116 116 116 253 253 253 253 253 253
40419 -253 253 253 253 253 253 253 253 253 253 253 253
40420 -253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253 253 253 253
40425 -253 253 253 253 253 253 94 94 94 6 6 6
40426 - 2 2 6 2 2 6 10 10 10 34 34 34
40427 - 2 2 6 2 2 6 2 2 6 2 2 6
40428 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 10 10 10 26 26 26 66 66 66
40437 - 82 82 82 2 2 6 38 38 38 6 6 6
40438 - 14 14 14 210 210 210 253 253 253 253 253 253
40439 -253 253 253 253 253 253 253 253 253 253 253 253
40440 -253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253 253 253 253
40445 -253 253 253 253 253 253 144 144 144 2 2 6
40446 - 2 2 6 2 2 6 2 2 6 46 46 46
40447 - 2 2 6 2 2 6 2 2 6 2 2 6
40448 - 42 42 42 74 74 74 30 30 30 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 6 6 6 14 14 14 42 42 42 90 90 90
40457 - 26 26 26 6 6 6 42 42 42 2 2 6
40458 - 74 74 74 250 250 250 253 253 253 253 253 253
40459 -253 253 253 253 253 253 253 253 253 253 253 253
40460 -253 253 253 253 253 253 242 242 242 242 242 242
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 253 253 253 253 253 253
40465 -253 253 253 253 253 253 182 182 182 2 2 6
40466 - 2 2 6 2 2 6 2 2 6 46 46 46
40467 - 2 2 6 2 2 6 2 2 6 2 2 6
40468 - 10 10 10 86 86 86 38 38 38 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 10 10 10 26 26 26 66 66 66 82 82 82
40477 - 2 2 6 22 22 22 18 18 18 2 2 6
40478 -149 149 149 253 253 253 253 253 253 253 253 253
40479 -253 253 253 253 253 253 253 253 253 253 253 253
40480 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
40485 -253 253 253 253 253 253 206 206 206 2 2 6
40486 - 2 2 6 2 2 6 2 2 6 38 38 38
40487 - 2 2 6 2 2 6 2 2 6 2 2 6
40488 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 6 6 6
40496 - 18 18 18 46 46 46 86 86 86 18 18 18
40497 - 2 2 6 34 34 34 10 10 10 6 6 6
40498 -210 210 210 253 253 253 253 253 253 253 253 253
40499 -253 253 253 253 253 253 253 253 253 253 253 253
40500 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
40505 -253 253 253 253 253 253 221 221 221 6 6 6
40506 - 2 2 6 2 2 6 6 6 6 30 30 30
40507 - 2 2 6 2 2 6 2 2 6 2 2 6
40508 - 2 2 6 82 82 82 54 54 54 18 18 18
40509 - 6 6 6 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 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 10 10 10
40516 - 26 26 26 66 66 66 62 62 62 2 2 6
40517 - 2 2 6 38 38 38 10 10 10 26 26 26
40518 -238 238 238 253 253 253 253 253 253 253 253 253
40519 -253 253 253 253 253 253 253 253 253 253 253 253
40520 -253 253 253 253 253 253 231 231 231 238 238 238
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 253 253 253 253 253 253
40525 -253 253 253 253 253 253 231 231 231 6 6 6
40526 - 2 2 6 2 2 6 10 10 10 30 30 30
40527 - 2 2 6 2 2 6 2 2 6 2 2 6
40528 - 2 2 6 66 66 66 58 58 58 22 22 22
40529 - 6 6 6 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 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 10 10 10
40536 - 38 38 38 78 78 78 6 6 6 2 2 6
40537 - 2 2 6 46 46 46 14 14 14 42 42 42
40538 -246 246 246 253 253 253 253 253 253 253 253 253
40539 -253 253 253 253 253 253 253 253 253 253 253 253
40540 -253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253
40545 -253 253 253 253 253 253 234 234 234 10 10 10
40546 - 2 2 6 2 2 6 22 22 22 14 14 14
40547 - 2 2 6 2 2 6 2 2 6 2 2 6
40548 - 2 2 6 66 66 66 62 62 62 22 22 22
40549 - 6 6 6 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 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 6 6 6 18 18 18
40556 - 50 50 50 74 74 74 2 2 6 2 2 6
40557 - 14 14 14 70 70 70 34 34 34 62 62 62
40558 -250 250 250 253 253 253 253 253 253 253 253 253
40559 -253 253 253 253 253 253 253 253 253 253 253 253
40560 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
40565 -253 253 253 253 253 253 234 234 234 14 14 14
40566 - 2 2 6 2 2 6 30 30 30 2 2 6
40567 - 2 2 6 2 2 6 2 2 6 2 2 6
40568 - 2 2 6 66 66 66 62 62 62 22 22 22
40569 - 6 6 6 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 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 6 6 6 18 18 18
40576 - 54 54 54 62 62 62 2 2 6 2 2 6
40577 - 2 2 6 30 30 30 46 46 46 70 70 70
40578 -250 250 250 253 253 253 253 253 253 253 253 253
40579 -253 253 253 253 253 253 253 253 253 253 253 253
40580 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
40585 -253 253 253 253 253 253 226 226 226 10 10 10
40586 - 2 2 6 6 6 6 30 30 30 2 2 6
40587 - 2 2 6 2 2 6 2 2 6 2 2 6
40588 - 2 2 6 66 66 66 58 58 58 22 22 22
40589 - 6 6 6 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 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 6 6 6 22 22 22
40596 - 58 58 58 62 62 62 2 2 6 2 2 6
40597 - 2 2 6 2 2 6 30 30 30 78 78 78
40598 -250 250 250 253 253 253 253 253 253 253 253 253
40599 -253 253 253 253 253 253 253 253 253 253 253 253
40600 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
40605 -253 253 253 253 253 253 206 206 206 2 2 6
40606 - 22 22 22 34 34 34 18 14 6 22 22 22
40607 - 26 26 26 18 18 18 6 6 6 2 2 6
40608 - 2 2 6 82 82 82 54 54 54 18 18 18
40609 - 6 6 6 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 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 6 6 6 26 26 26
40616 - 62 62 62 106 106 106 74 54 14 185 133 11
40617 -210 162 10 121 92 8 6 6 6 62 62 62
40618 -238 238 238 253 253 253 253 253 253 253 253 253
40619 -253 253 253 253 253 253 253 253 253 253 253 253
40620 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
40625 -253 253 253 253 253 253 158 158 158 18 18 18
40626 - 14 14 14 2 2 6 2 2 6 2 2 6
40627 - 6 6 6 18 18 18 66 66 66 38 38 38
40628 - 6 6 6 94 94 94 50 50 50 18 18 18
40629 - 6 6 6 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 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 6 6 6
40635 - 10 10 10 10 10 10 18 18 18 38 38 38
40636 - 78 78 78 142 134 106 216 158 10 242 186 14
40637 -246 190 14 246 190 14 156 118 10 10 10 10
40638 - 90 90 90 238 238 238 253 253 253 253 253 253
40639 -253 253 253 253 253 253 253 253 253 253 253 253
40640 -253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253
40644 -253 253 253 253 253 253 253 253 253 246 230 190
40645 -238 204 91 238 204 91 181 142 44 37 26 9
40646 - 2 2 6 2 2 6 2 2 6 2 2 6
40647 - 2 2 6 2 2 6 38 38 38 46 46 46
40648 - 26 26 26 106 106 106 54 54 54 18 18 18
40649 - 6 6 6 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 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 6 6 6 14 14 14 22 22 22
40655 - 30 30 30 38 38 38 50 50 50 70 70 70
40656 -106 106 106 190 142 34 226 170 11 242 186 14
40657 -246 190 14 246 190 14 246 190 14 154 114 10
40658 - 6 6 6 74 74 74 226 226 226 253 253 253
40659 -253 253 253 253 253 253 253 253 253 253 253 253
40660 -253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253
40664 -253 253 253 253 253 253 253 253 253 228 184 62
40665 -241 196 14 241 208 19 232 195 16 38 30 10
40666 - 2 2 6 2 2 6 2 2 6 2 2 6
40667 - 2 2 6 6 6 6 30 30 30 26 26 26
40668 -203 166 17 154 142 90 66 66 66 26 26 26
40669 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 6 6 6 18 18 18 38 38 38 58 58 58
40675 - 78 78 78 86 86 86 101 101 101 123 123 123
40676 -175 146 61 210 150 10 234 174 13 246 186 14
40677 -246 190 14 246 190 14 246 190 14 238 190 10
40678 -102 78 10 2 2 6 46 46 46 198 198 198
40679 -253 253 253 253 253 253 253 253 253 253 253 253
40680 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253
40684 -253 253 253 253 253 253 253 253 253 224 178 62
40685 -242 186 14 241 196 14 210 166 10 22 18 6
40686 - 2 2 6 2 2 6 2 2 6 2 2 6
40687 - 2 2 6 2 2 6 6 6 6 121 92 8
40688 -238 202 15 232 195 16 82 82 82 34 34 34
40689 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 14 14 14 38 38 38 70 70 70 154 122 46
40695 -190 142 34 200 144 11 197 138 11 197 138 11
40696 -213 154 11 226 170 11 242 186 14 246 190 14
40697 -246 190 14 246 190 14 246 190 14 246 190 14
40698 -225 175 15 46 32 6 2 2 6 22 22 22
40699 -158 158 158 250 250 250 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 253 253 253 253 253 253 253 253 253
40704 -253 253 253 250 250 250 242 242 242 224 178 62
40705 -239 182 13 236 186 11 213 154 11 46 32 6
40706 - 2 2 6 2 2 6 2 2 6 2 2 6
40707 - 2 2 6 2 2 6 61 42 6 225 175 15
40708 -238 190 10 236 186 11 112 100 78 42 42 42
40709 - 14 14 14 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 0 0 0
40713 - 0 0 0 0 0 0 0 0 0 6 6 6
40714 - 22 22 22 54 54 54 154 122 46 213 154 11
40715 -226 170 11 230 174 11 226 170 11 226 170 11
40716 -236 178 12 242 186 14 246 190 14 246 190 14
40717 -246 190 14 246 190 14 246 190 14 246 190 14
40718 -241 196 14 184 144 12 10 10 10 2 2 6
40719 - 6 6 6 116 116 116 242 242 242 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 253 253 253 253 253 253 253 253 253
40724 -253 253 253 231 231 231 198 198 198 214 170 54
40725 -236 178 12 236 178 12 210 150 10 137 92 6
40726 - 18 14 6 2 2 6 2 2 6 2 2 6
40727 - 6 6 6 70 47 6 200 144 11 236 178 12
40728 -239 182 13 239 182 13 124 112 88 58 58 58
40729 - 22 22 22 6 6 6 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 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 10 10 10
40734 - 30 30 30 70 70 70 180 133 36 226 170 11
40735 -239 182 13 242 186 14 242 186 14 246 186 14
40736 -246 190 14 246 190 14 246 190 14 246 190 14
40737 -246 190 14 246 190 14 246 190 14 246 190 14
40738 -246 190 14 232 195 16 98 70 6 2 2 6
40739 - 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253 253 253 253 253 253 253
40744 -253 253 253 206 206 206 198 198 198 214 166 58
40745 -230 174 11 230 174 11 216 158 10 192 133 9
40746 -163 110 8 116 81 8 102 78 10 116 81 8
40747 -167 114 7 197 138 11 226 170 11 239 182 13
40748 -242 186 14 242 186 14 162 146 94 78 78 78
40749 - 34 34 34 14 14 14 6 6 6 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 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 6 6 6
40754 - 30 30 30 78 78 78 190 142 34 226 170 11
40755 -239 182 13 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 246 190 14 246 190 14 246 190 14
40758 -246 190 14 241 196 14 203 166 17 22 18 6
40759 - 2 2 6 2 2 6 2 2 6 38 38 38
40760 -218 218 218 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 -253 253 253 253 253 253 253 253 253 253 253 253
40764 -250 250 250 206 206 206 198 198 198 202 162 69
40765 -226 170 11 236 178 12 224 166 10 210 150 10
40766 -200 144 11 197 138 11 192 133 9 197 138 11
40767 -210 150 10 226 170 11 242 186 14 246 190 14
40768 -246 190 14 246 186 14 225 175 15 124 112 88
40769 - 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 10 10 10
40774 - 30 30 30 78 78 78 174 135 50 224 166 10
40775 -239 182 13 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 246 190 14 246 190 14
40778 -246 190 14 246 190 14 241 196 14 139 102 15
40779 - 2 2 6 2 2 6 2 2 6 2 2 6
40780 - 78 78 78 250 250 250 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 -253 253 253 253 253 253 253 253 253 253 253 253
40784 -250 250 250 214 214 214 198 198 198 190 150 46
40785 -219 162 10 236 178 12 234 174 13 224 166 10
40786 -216 158 10 213 154 11 213 154 11 216 158 10
40787 -226 170 11 239 182 13 246 190 14 246 190 14
40788 -246 190 14 246 190 14 242 186 14 206 162 42
40789 -101 101 101 58 58 58 30 30 30 14 14 14
40790 - 6 6 6 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 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 10 10 10
40794 - 30 30 30 74 74 74 174 135 50 216 158 10
40795 -236 178 12 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 246 190 14 246 190 14
40798 -246 190 14 246 190 14 241 196 14 226 184 13
40799 - 61 42 6 2 2 6 2 2 6 2 2 6
40800 - 22 22 22 238 238 238 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 253 253 253 253 253 253 253 253 253
40804 -253 253 253 226 226 226 187 187 187 180 133 36
40805 -216 158 10 236 178 12 239 182 13 236 178 12
40806 -230 174 11 226 170 11 226 170 11 230 174 11
40807 -236 178 12 242 186 14 246 190 14 246 190 14
40808 -246 190 14 246 190 14 246 186 14 239 182 13
40809 -206 162 42 106 106 106 66 66 66 34 34 34
40810 - 14 14 14 6 6 6 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 0 0 0
40813 - 0 0 0 0 0 0 0 0 0 6 6 6
40814 - 26 26 26 70 70 70 163 133 67 213 154 11
40815 -236 178 12 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 246 190 14
40818 -246 190 14 246 190 14 246 190 14 241 196 14
40819 -190 146 13 18 14 6 2 2 6 2 2 6
40820 - 46 46 46 246 246 246 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 253 253 253 253 253 253 253 253 253
40824 -253 253 253 221 221 221 86 86 86 156 107 11
40825 -216 158 10 236 178 12 242 186 14 246 186 14
40826 -242 186 14 239 182 13 239 182 13 242 186 14
40827 -242 186 14 246 186 14 246 190 14 246 190 14
40828 -246 190 14 246 190 14 246 190 14 246 190 14
40829 -242 186 14 225 175 15 142 122 72 66 66 66
40830 - 30 30 30 10 10 10 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 0 0 0
40833 - 0 0 0 0 0 0 0 0 0 6 6 6
40834 - 26 26 26 70 70 70 163 133 67 210 150 10
40835 -236 178 12 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 -246 190 14 246 190 14 246 190 14 246 190 14
40839 -232 195 16 121 92 8 34 34 34 106 106 106
40840 -221 221 221 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 -253 253 253 253 253 253 253 253 253 253 253 253
40844 -242 242 242 82 82 82 18 14 6 163 110 8
40845 -216 158 10 236 178 12 242 186 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 246 190 14 246 190 14
40849 -246 190 14 246 190 14 242 186 14 163 133 67
40850 - 46 46 46 18 18 18 6 6 6 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 0 0 0
40853 - 0 0 0 0 0 0 0 0 0 10 10 10
40854 - 30 30 30 78 78 78 163 133 67 210 150 10
40855 -236 178 12 246 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
40859 -241 196 14 215 174 15 190 178 144 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 253 253 253
40863 -253 253 253 253 253 253 253 253 253 218 218 218
40864 - 58 58 58 2 2 6 22 18 6 167 114 7
40865 -216 158 10 236 178 12 246 186 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 190 14 246 190 14 246 190 14
40869 -246 190 14 246 186 14 242 186 14 190 150 46
40870 - 54 54 54 22 22 22 6 6 6 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 0 0 0
40873 - 0 0 0 0 0 0 0 0 0 14 14 14
40874 - 38 38 38 86 86 86 180 133 36 213 154 11
40875 -236 178 12 246 186 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 246 190 14 246 190 14 246 190 14
40879 -246 190 14 232 195 16 190 146 13 214 214 214
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 253 253 253 253 253 253 253 253 253
40883 -253 253 253 250 250 250 170 170 170 26 26 26
40884 - 2 2 6 2 2 6 37 26 9 163 110 8
40885 -219 162 10 239 182 13 246 186 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 190 14 246 190 14 246 190 14 246 190 14
40889 -246 186 14 236 178 12 224 166 10 142 122 72
40890 - 46 46 46 18 18 18 6 6 6 0 0 0
40891 - 0 0 0 0 0 0 0 0 0 0 0 0
40892 - 0 0 0 0 0 0 0 0 0 0 0 0
40893 - 0 0 0 0 0 0 6 6 6 18 18 18
40894 - 50 50 50 109 106 95 192 133 9 224 166 10
40895 -242 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
40899 -242 186 14 226 184 13 210 162 10 142 110 46
40900 -226 226 226 253 253 253 253 253 253 253 253 253
40901 -253 253 253 253 253 253 253 253 253 253 253 253
40902 -253 253 253 253 253 253 253 253 253 253 253 253
40903 -198 198 198 66 66 66 2 2 6 2 2 6
40904 - 2 2 6 2 2 6 50 34 6 156 107 11
40905 -219 162 10 239 182 13 246 186 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 246 190 14
40908 -246 190 14 246 190 14 246 190 14 242 186 14
40909 -234 174 13 213 154 11 154 122 46 66 66 66
40910 - 30 30 30 10 10 10 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 0 0 0 0 0 0
40913 - 0 0 0 0 0 0 6 6 6 22 22 22
40914 - 58 58 58 154 121 60 206 145 10 234 174 13
40915 -242 186 14 246 186 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 190 14 246 190 14 246 190 14 246 190 14
40919 -246 186 14 236 178 12 210 162 10 163 110 8
40920 - 61 42 6 138 138 138 218 218 218 250 250 250
40921 -253 253 253 253 253 253 253 253 253 250 250 250
40922 -242 242 242 210 210 210 144 144 144 66 66 66
40923 - 6 6 6 2 2 6 2 2 6 2 2 6
40924 - 2 2 6 2 2 6 61 42 6 163 110 8
40925 -216 158 10 236 178 12 246 190 14 246 190 14
40926 -246 190 14 246 190 14 246 190 14 246 190 14
40927 -246 190 14 246 190 14 246 190 14 246 190 14
40928 -246 190 14 239 182 13 230 174 11 216 158 10
40929 -190 142 34 124 112 88 70 70 70 38 38 38
40930 - 18 18 18 6 6 6 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 0 0 0 0 0 0
40933 - 0 0 0 0 0 0 6 6 6 22 22 22
40934 - 62 62 62 168 124 44 206 145 10 224 166 10
40935 -236 178 12 239 182 13 242 186 14 242 186 14
40936 -246 186 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 246 190 14 246 190 14 246 190 14
40939 -246 190 14 236 178 12 216 158 10 175 118 6
40940 - 80 54 7 2 2 6 6 6 6 30 30 30
40941 - 54 54 54 62 62 62 50 50 50 38 38 38
40942 - 14 14 14 2 2 6 2 2 6 2 2 6
40943 - 2 2 6 2 2 6 2 2 6 2 2 6
40944 - 2 2 6 6 6 6 80 54 7 167 114 7
40945 -213 154 11 236 178 12 246 190 14 246 190 14
40946 -246 190 14 246 190 14 246 190 14 246 190 14
40947 -246 190 14 242 186 14 239 182 13 239 182 13
40948 -230 174 11 210 150 10 174 135 50 124 112 88
40949 - 82 82 82 54 54 54 34 34 34 18 18 18
40950 - 6 6 6 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 0 0 0 0 0 0
40953 - 0 0 0 0 0 0 6 6 6 18 18 18
40954 - 50 50 50 158 118 36 192 133 9 200 144 11
40955 -216 158 10 219 162 10 224 166 10 226 170 11
40956 -230 174 11 236 178 12 239 182 13 239 182 13
40957 -242 186 14 246 186 14 246 190 14 246 190 14
40958 -246 190 14 246 190 14 246 190 14 246 190 14
40959 -246 186 14 230 174 11 210 150 10 163 110 8
40960 -104 69 6 10 10 10 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 2 2 6 2 2 6 2 2 6
40964 - 2 2 6 6 6 6 91 60 6 167 114 7
40965 -206 145 10 230 174 11 242 186 14 246 190 14
40966 -246 190 14 246 190 14 246 186 14 242 186 14
40967 -239 182 13 230 174 11 224 166 10 213 154 11
40968 -180 133 36 124 112 88 86 86 86 58 58 58
40969 - 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0
40973 - 0 0 0 0 0 0 0 0 0 14 14 14
40974 - 34 34 34 70 70 70 138 110 50 158 118 36
40975 -167 114 7 180 123 7 192 133 9 197 138 11
40976 -200 144 11 206 145 10 213 154 11 219 162 10
40977 -224 166 10 230 174 11 239 182 13 242 186 14
40978 -246 186 14 246 186 14 246 186 14 246 186 14
40979 -239 182 13 216 158 10 185 133 11 152 99 6
40980 -104 69 6 18 14 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 2 2 6 2 2 6 2 2 6
40984 - 2 2 6 6 6 6 80 54 7 152 99 6
40985 -192 133 9 219 162 10 236 178 12 239 182 13
40986 -246 186 14 242 186 14 239 182 13 236 178 12
40987 -224 166 10 206 145 10 192 133 9 154 121 60
40988 - 94 94 94 62 62 62 42 42 42 22 22 22
40989 - 14 14 14 6 6 6 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 0 0 0
40993 - 0 0 0 0 0 0 0 0 0 6 6 6
40994 - 18 18 18 34 34 34 58 58 58 78 78 78
40995 -101 98 89 124 112 88 142 110 46 156 107 11
40996 -163 110 8 167 114 7 175 118 6 180 123 7
40997 -185 133 11 197 138 11 210 150 10 219 162 10
40998 -226 170 11 236 178 12 236 178 12 234 174 13
40999 -219 162 10 197 138 11 163 110 8 130 83 6
41000 - 91 60 6 10 10 10 2 2 6 2 2 6
41001 - 18 18 18 38 38 38 38 38 38 38 38 38
41002 - 38 38 38 38 38 38 38 38 38 38 38 38
41003 - 38 38 38 38 38 38 26 26 26 2 2 6
41004 - 2 2 6 6 6 6 70 47 6 137 92 6
41005 -175 118 6 200 144 11 219 162 10 230 174 11
41006 -234 174 13 230 174 11 219 162 10 210 150 10
41007 -192 133 9 163 110 8 124 112 88 82 82 82
41008 - 50 50 50 30 30 30 14 14 14 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41014 - 6 6 6 14 14 14 22 22 22 34 34 34
41015 - 42 42 42 58 58 58 74 74 74 86 86 86
41016 -101 98 89 122 102 70 130 98 46 121 87 25
41017 -137 92 6 152 99 6 163 110 8 180 123 7
41018 -185 133 11 197 138 11 206 145 10 200 144 11
41019 -180 123 7 156 107 11 130 83 6 104 69 6
41020 - 50 34 6 54 54 54 110 110 110 101 98 89
41021 - 86 86 86 82 82 82 78 78 78 78 78 78
41022 - 78 78 78 78 78 78 78 78 78 78 78 78
41023 - 78 78 78 82 82 82 86 86 86 94 94 94
41024 -106 106 106 101 101 101 86 66 34 124 80 6
41025 -156 107 11 180 123 7 192 133 9 200 144 11
41026 -206 145 10 200 144 11 192 133 9 175 118 6
41027 -139 102 15 109 106 95 70 70 70 42 42 42
41028 - 22 22 22 10 10 10 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 0 0 0 0 0 0
41034 - 0 0 0 0 0 0 6 6 6 10 10 10
41035 - 14 14 14 22 22 22 30 30 30 38 38 38
41036 - 50 50 50 62 62 62 74 74 74 90 90 90
41037 -101 98 89 112 100 78 121 87 25 124 80 6
41038 -137 92 6 152 99 6 152 99 6 152 99 6
41039 -138 86 6 124 80 6 98 70 6 86 66 30
41040 -101 98 89 82 82 82 58 58 58 46 46 46
41041 - 38 38 38 34 34 34 34 34 34 34 34 34
41042 - 34 34 34 34 34 34 34 34 34 34 34 34
41043 - 34 34 34 34 34 34 38 38 38 42 42 42
41044 - 54 54 54 82 82 82 94 86 76 91 60 6
41045 -134 86 6 156 107 11 167 114 7 175 118 6
41046 -175 118 6 167 114 7 152 99 6 121 87 25
41047 -101 98 89 62 62 62 34 34 34 18 18 18
41048 - 6 6 6 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 0 0 0 0 0 0 0 0 0
41055 - 0 0 0 6 6 6 6 6 6 10 10 10
41056 - 18 18 18 22 22 22 30 30 30 42 42 42
41057 - 50 50 50 66 66 66 86 86 86 101 98 89
41058 -106 86 58 98 70 6 104 69 6 104 69 6
41059 -104 69 6 91 60 6 82 62 34 90 90 90
41060 - 62 62 62 38 38 38 22 22 22 14 14 14
41061 - 10 10 10 10 10 10 10 10 10 10 10 10
41062 - 10 10 10 10 10 10 6 6 6 10 10 10
41063 - 10 10 10 10 10 10 10 10 10 14 14 14
41064 - 22 22 22 42 42 42 70 70 70 89 81 66
41065 - 80 54 7 104 69 6 124 80 6 137 92 6
41066 -134 86 6 116 81 8 100 82 52 86 86 86
41067 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
41076 - 0 0 0 6 6 6 10 10 10 14 14 14
41077 - 18 18 18 26 26 26 38 38 38 54 54 54
41078 - 70 70 70 86 86 86 94 86 76 89 81 66
41079 - 89 81 66 86 86 86 74 74 74 50 50 50
41080 - 30 30 30 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41084 - 6 6 6 18 18 18 34 34 34 58 58 58
41085 - 82 82 82 89 81 66 89 81 66 89 81 66
41086 - 94 86 66 94 86 76 74 74 74 50 50 50
41087 - 26 26 26 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41097 - 6 6 6 6 6 6 14 14 14 18 18 18
41098 - 30 30 30 38 38 38 46 46 46 54 54 54
41099 - 50 50 50 42 42 42 30 30 30 18 18 18
41100 - 10 10 10 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 0 0 0 0 0 0 0 0 0
41104 - 0 0 0 6 6 6 14 14 14 26 26 26
41105 - 38 38 38 50 50 50 58 58 58 58 58 58
41106 - 54 54 54 42 42 42 30 30 30 18 18 18
41107 - 10 10 10 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 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 6 6 6
41118 - 6 6 6 10 10 10 14 14 14 18 18 18
41119 - 18 18 18 14 14 14 10 10 10 6 6 6
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 0 0 0
41123 - 0 0 0 0 0 0 0 0 0 0 0 0
41124 - 0 0 0 0 0 0 0 0 0 6 6 6
41125 - 14 14 14 18 18 18 22 22 22 22 22 22
41126 - 18 18 18 14 14 14 10 10 10 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
41145 +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 4 4 4 4 4 4 4 4 4 4 4 4
41159 +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 4 4 4 4 4 4 4 4 4 4 4 4
41173 +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 4 4 4 4 4 4 4 4 4 4 4 4
41187 +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 4 4 4 4 4 4 4 4 4 4 4 4
41201 +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 4 4 4 4 4 4 4 4 4 4 4 4
41215 +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 4 4 4 4 4 4 4 4 4
41220 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41221 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4
41225 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41226 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +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 4 4 4 4 4 4 4 4 4 4 4 4
41234 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41235 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41236 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41240 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41241 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41242 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41249 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41250 +0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41254 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41255 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41256 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41257 +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 4 4 4 4 4 4 4 4 4 4 4 4
41261 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41262 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41263 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41264 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41267 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41268 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41269 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41270 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41271 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41276 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41277 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41278 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41279 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41281 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41282 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41283 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41284 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41285 +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 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41289 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41290 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41291 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41292 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41293 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41294 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41295 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41296 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41297 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41298 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41299 +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 4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41303 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41304 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41305 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41306 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41307 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41308 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41309 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41310 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41311 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41312 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41313 +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 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41317 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41318 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41319 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41320 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41321 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41322 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41323 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41324 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41325 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41326 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41327 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41331 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41332 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41333 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41334 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41335 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41336 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41337 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41338 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41339 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41340 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41341 +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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41345 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41346 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41347 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41348 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41349 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41350 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41351 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41352 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41353 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41354 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41355 +4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41358 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41359 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41360 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41361 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41362 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41363 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41364 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41365 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41366 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41367 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41368 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41369 +4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41372 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41373 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41374 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41375 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41376 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41377 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41378 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41379 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41380 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41381 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41382 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41383 +0 0 0 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41385 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41386 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41387 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41388 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41389 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41390 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41391 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41392 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41393 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41394 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41395 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41396 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41397 +2 0 0 0 0 0
41398 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41399 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41400 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41401 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41402 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41403 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41404 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41405 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41406 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41407 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41408 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41409 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41410 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41411 +37 38 37 0 0 0
41412 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41413 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41414 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41415 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41416 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41417 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41418 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41419 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41420 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41421 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41422 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41423 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41424 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41425 +85 115 134 4 0 0
41426 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41427 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41428 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41429 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41430 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41431 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41432 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41433 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41434 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41435 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41436 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41437 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41438 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41439 +60 73 81 4 0 0
41440 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41441 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41442 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41443 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41444 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41445 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41446 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41447 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41448 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41449 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41450 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41451 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41452 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41453 +16 19 21 4 0 0
41454 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41455 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41456 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41457 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41458 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41459 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41460 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41461 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41462 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41463 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41464 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41465 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41466 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41467 +4 0 0 4 3 3
41468 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41469 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41470 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41472 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41473 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41474 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41475 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41476 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41477 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41478 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41479 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41480 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41481 +3 2 2 4 4 4
41482 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41483 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41484 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41485 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41486 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41487 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41488 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41489 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41490 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41491 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41492 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41493 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41494 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41495 +4 4 4 4 4 4
41496 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41497 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41498 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41499 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41500 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41501 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41502 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41503 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41504 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41505 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41506 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41507 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41508 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41509 +4 4 4 4 4 4
41510 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41511 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41512 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41513 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41514 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41515 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41516 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41517 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41518 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41519 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41520 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41521 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41522 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41523 +5 5 5 5 5 5
41524 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41525 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41526 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41527 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41528 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41529 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41530 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41531 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41532 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41533 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41534 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41535 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41536 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41537 +5 5 5 4 4 4
41538 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41539 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41540 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41541 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41542 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41543 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41544 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41545 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41546 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41547 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41548 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41549 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551 +4 4 4 4 4 4
41552 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41553 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41554 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41555 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41556 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41557 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41558 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41559 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41560 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41561 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41562 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41563 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565 +4 4 4 4 4 4
41566 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41567 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41568 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41569 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41570 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41571 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41572 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41573 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41574 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41575 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41576 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4
41579 +4 4 4 4 4 4
41580 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41581 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41582 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41583 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41584 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41585 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41586 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41587 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41588 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41589 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41590 +6 6 6 4 0 0 4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 4 4 4
41594 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41595 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41596 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41597 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41598 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41599 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41600 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41601 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41602 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41603 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41604 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4
41608 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41609 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41610 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41611 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41612 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41613 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41614 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41615 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41616 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41617 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41618 +6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4
41622 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41623 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41624 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41625 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41626 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41627 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41628 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41629 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41630 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41631 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41632 +4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4
41636 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41637 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41638 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41639 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41640 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41641 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41642 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41643 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41644 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41645 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41646 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4
41650 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41651 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41652 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41653 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41654 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41655 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41656 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41657 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41658 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41659 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41660 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4
41664 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41665 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41666 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41667 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41668 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41669 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41670 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41671 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41672 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41673 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41674 +4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4
41678 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41679 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41680 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41681 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41682 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41683 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41684 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41685 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41686 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41687 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41688 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4
41692 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41693 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41694 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41695 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41696 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41697 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41698 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41699 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41700 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41701 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41702 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41705 +4 4 4 4 4 4
41706 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41707 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41708 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41709 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41710 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41711 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41712 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41713 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41714 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41715 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41716 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41719 +4 4 4 4 4 4
41720 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41721 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41722 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41723 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41724 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41725 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41726 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41727 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41728 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41729 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41730 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4
41734 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41735 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41736 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41737 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41738 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41739 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41740 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41741 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41742 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41743 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41744 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4
41748 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41749 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41750 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41751 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41752 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41753 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41754 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41755 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41756 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41757 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41758 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4
41762 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41763 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41764 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41765 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41766 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41767 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41768 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41769 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41770 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41771 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41772 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4
41776 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41777 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41778 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41779 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41780 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41781 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41782 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41783 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41784 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41785 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41786 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4
41790 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41791 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41792 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41793 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41794 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41795 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41796 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41797 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41798 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41799 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41800 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4
41804 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41805 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41806 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41807 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41808 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41809 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41810 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41811 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41812 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41813 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41814 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4
41818 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41819 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41820 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41821 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41822 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41823 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41824 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41825 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41826 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41827 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41828 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41831 +4 4 4 4 4 4
41832 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41833 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41834 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41835 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41836 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41837 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41838 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41839 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41840 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41841 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41842 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41845 +4 4 4 4 4 4
41846 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41847 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41848 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41849 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41850 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41851 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41852 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41853 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41854 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41855 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41856 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41859 +4 4 4 4 4 4
41860 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41861 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41862 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41863 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41864 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41865 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41866 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41867 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41868 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41869 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41870 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41873 +4 4 4 4 4 4
41874 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41875 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41876 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41877 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41878 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41879 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41880 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41881 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41882 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41883 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41884 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41887 +4 4 4 4 4 4
41888 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41889 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41890 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41891 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41892 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41893 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41894 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41895 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41896 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41897 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41898 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41901 +4 4 4 4 4 4
41902 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41903 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41904 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41905 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41906 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41907 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41908 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41909 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41910 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41911 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41912 +0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
41915 +4 4 4 4 4 4
41916 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41917 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41918 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41919 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41920 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41921 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41922 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41923 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41924 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41925 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41926 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41929 +4 4 4 4 4 4
41930 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41931 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41932 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41933 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41934 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41935 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41936 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41937 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41938 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41939 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41940 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41943 +4 4 4 4 4 4
41944 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41945 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41946 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41947 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41948 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41949 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41950 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41951 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41952 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41953 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41957 +4 4 4 4 4 4
41958 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41959 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41960 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41961 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41962 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41963 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41964 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41965 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41966 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41967 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
41971 +4 4 4 4 4 4
41972 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41973 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41974 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41975 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41976 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41977 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41978 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41979 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41980 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41981 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41985 +4 4 4 4 4 4
41986 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41987 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41988 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41989 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41990 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41991 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41992 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41993 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41994 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41995 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41999 +4 4 4 4 4 4
42000 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42001 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42002 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42003 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42004 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42005 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42006 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42007 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42008 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
42013 +4 4 4 4 4 4
42014 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42015 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42016 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42017 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42018 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42019 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42020 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42021 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42022 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
42027 +4 4 4 4 4 4
42028 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42029 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42030 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42031 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42032 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42033 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42034 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42035 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42036 +4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
42041 +4 4 4 4 4 4
42042 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42043 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42044 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42045 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42046 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42047 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42048 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42049 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
42055 +4 4 4 4 4 4
42056 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42057 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42058 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42059 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42060 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42061 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42062 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42063 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
42069 +4 4 4 4 4 4
42070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42071 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42072 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42073 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42074 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42075 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42076 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42077 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
42083 +4 4 4 4 4 4
42084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42085 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42086 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42087 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42088 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42089 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42090 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42091 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42097 +4 4 4 4 4 4
42098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42099 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42100 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42101 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42102 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42103 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42104 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42105 +5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42111 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42114 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42115 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42116 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42117 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42118 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42119 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42125 +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 4 4 4
42128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42129 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42130 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42131 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42132 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
42139 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42143 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42144 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42145 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42146 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
42153 +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 4 4 4 4 4 4 4 4 4 4 4 4
42157 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42158 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42159 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42160 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42167 +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 4 4 4 4 4 4 4 4 4
42171 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42172 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42173 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42174 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42181 +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 4 4 4
42185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42186 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42187 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42188 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42195 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42201 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42202 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42209 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42215 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42216 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42223 +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 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42229 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
42237 +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 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42243 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 4 4 4
42252 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42253 index 86d449e..af6a7f7 100644
42254 --- a/drivers/video/udlfb.c
42255 +++ b/drivers/video/udlfb.c
42256 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42257 dlfb_urb_completion(urb);
42258
42259 error:
42260 - atomic_add(bytes_sent, &dev->bytes_sent);
42261 - atomic_add(bytes_identical, &dev->bytes_identical);
42262 - atomic_add(width*height*2, &dev->bytes_rendered);
42263 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42264 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42265 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42266 end_cycles = get_cycles();
42267 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42268 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42269 >> 10)), /* Kcycles */
42270 &dev->cpu_kcycles_used);
42271
42272 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42273 dlfb_urb_completion(urb);
42274
42275 error:
42276 - atomic_add(bytes_sent, &dev->bytes_sent);
42277 - atomic_add(bytes_identical, &dev->bytes_identical);
42278 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42279 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42280 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42281 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42282 end_cycles = get_cycles();
42283 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42284 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42285 >> 10)), /* Kcycles */
42286 &dev->cpu_kcycles_used);
42287 }
42288 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42289 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42290 struct dlfb_data *dev = fb_info->par;
42291 return snprintf(buf, PAGE_SIZE, "%u\n",
42292 - atomic_read(&dev->bytes_rendered));
42293 + atomic_read_unchecked(&dev->bytes_rendered));
42294 }
42295
42296 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42297 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42298 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42299 struct dlfb_data *dev = fb_info->par;
42300 return snprintf(buf, PAGE_SIZE, "%u\n",
42301 - atomic_read(&dev->bytes_identical));
42302 + atomic_read_unchecked(&dev->bytes_identical));
42303 }
42304
42305 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42306 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42307 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42308 struct dlfb_data *dev = fb_info->par;
42309 return snprintf(buf, PAGE_SIZE, "%u\n",
42310 - atomic_read(&dev->bytes_sent));
42311 + atomic_read_unchecked(&dev->bytes_sent));
42312 }
42313
42314 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42315 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42316 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42317 struct dlfb_data *dev = fb_info->par;
42318 return snprintf(buf, PAGE_SIZE, "%u\n",
42319 - atomic_read(&dev->cpu_kcycles_used));
42320 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42321 }
42322
42323 static ssize_t edid_show(
42324 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42325 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42326 struct dlfb_data *dev = fb_info->par;
42327
42328 - atomic_set(&dev->bytes_rendered, 0);
42329 - atomic_set(&dev->bytes_identical, 0);
42330 - atomic_set(&dev->bytes_sent, 0);
42331 - atomic_set(&dev->cpu_kcycles_used, 0);
42332 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42333 + atomic_set_unchecked(&dev->bytes_identical, 0);
42334 + atomic_set_unchecked(&dev->bytes_sent, 0);
42335 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42336
42337 return count;
42338 }
42339 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42340 index 2f8f82d..191de37 100644
42341 --- a/drivers/video/uvesafb.c
42342 +++ b/drivers/video/uvesafb.c
42343 @@ -19,6 +19,7 @@
42344 #include <linux/io.h>
42345 #include <linux/mutex.h>
42346 #include <linux/slab.h>
42347 +#include <linux/moduleloader.h>
42348 #include <video/edid.h>
42349 #include <video/uvesafb.h>
42350 #ifdef CONFIG_X86
42351 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42352 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42353 par->pmi_setpal = par->ypan = 0;
42354 } else {
42355 +
42356 +#ifdef CONFIG_PAX_KERNEXEC
42357 +#ifdef CONFIG_MODULES
42358 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42359 +#endif
42360 + if (!par->pmi_code) {
42361 + par->pmi_setpal = par->ypan = 0;
42362 + return 0;
42363 + }
42364 +#endif
42365 +
42366 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42367 + task->t.regs.edi);
42368 +
42369 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42370 + pax_open_kernel();
42371 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42372 + pax_close_kernel();
42373 +
42374 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42375 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42376 +#else
42377 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42378 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42379 +#endif
42380 +
42381 printk(KERN_INFO "uvesafb: protected mode interface info at "
42382 "%04x:%04x\n",
42383 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42384 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42385 par->ypan = ypan;
42386
42387 if (par->pmi_setpal || par->ypan) {
42388 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42389 if (__supported_pte_mask & _PAGE_NX) {
42390 par->pmi_setpal = par->ypan = 0;
42391 printk(KERN_WARNING "uvesafb: NX protection is actively."
42392 "We have better not to use the PMI.\n");
42393 - } else {
42394 + } else
42395 +#endif
42396 uvesafb_vbe_getpmi(task, par);
42397 - }
42398 }
42399 #else
42400 /* The protected mode interface is not available on non-x86. */
42401 @@ -1838,6 +1862,11 @@ out:
42402 if (par->vbe_modes)
42403 kfree(par->vbe_modes);
42404
42405 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42406 + if (par->pmi_code)
42407 + module_free_exec(NULL, par->pmi_code);
42408 +#endif
42409 +
42410 framebuffer_release(info);
42411 return err;
42412 }
42413 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
42414 kfree(par->vbe_state_orig);
42415 if (par->vbe_state_saved)
42416 kfree(par->vbe_state_saved);
42417 +
42418 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42419 + if (par->pmi_code)
42420 + module_free_exec(NULL, par->pmi_code);
42421 +#endif
42422 +
42423 }
42424
42425 framebuffer_release(info);
42426 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42427 index 501b340..86bd4cf 100644
42428 --- a/drivers/video/vesafb.c
42429 +++ b/drivers/video/vesafb.c
42430 @@ -9,6 +9,7 @@
42431 */
42432
42433 #include <linux/module.h>
42434 +#include <linux/moduleloader.h>
42435 #include <linux/kernel.h>
42436 #include <linux/errno.h>
42437 #include <linux/string.h>
42438 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42439 static int vram_total __initdata; /* Set total amount of memory */
42440 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42441 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42442 -static void (*pmi_start)(void) __read_mostly;
42443 -static void (*pmi_pal) (void) __read_mostly;
42444 +static void (*pmi_start)(void) __read_only;
42445 +static void (*pmi_pal) (void) __read_only;
42446 static int depth __read_mostly;
42447 static int vga_compat __read_mostly;
42448 /* --------------------------------------------------------------------- */
42449 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42450 unsigned int size_vmode;
42451 unsigned int size_remap;
42452 unsigned int size_total;
42453 + void *pmi_code = NULL;
42454
42455 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42456 return -ENODEV;
42457 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42458 size_remap = size_total;
42459 vesafb_fix.smem_len = size_remap;
42460
42461 -#ifndef __i386__
42462 - screen_info.vesapm_seg = 0;
42463 -#endif
42464 -
42465 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42466 printk(KERN_WARNING
42467 "vesafb: cannot reserve video memory at 0x%lx\n",
42468 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42469 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42470 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42471
42472 +#ifdef __i386__
42473 +
42474 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42475 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42476 + if (!pmi_code)
42477 +#elif !defined(CONFIG_PAX_KERNEXEC)
42478 + if (0)
42479 +#endif
42480 +
42481 +#endif
42482 + screen_info.vesapm_seg = 0;
42483 +
42484 if (screen_info.vesapm_seg) {
42485 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42486 - screen_info.vesapm_seg,screen_info.vesapm_off);
42487 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42488 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42489 }
42490
42491 if (screen_info.vesapm_seg < 0xc000)
42492 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42493
42494 if (ypan || pmi_setpal) {
42495 unsigned short *pmi_base;
42496 +
42497 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42498 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42499 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42500 +
42501 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42502 + pax_open_kernel();
42503 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42504 +#else
42505 + pmi_code = pmi_base;
42506 +#endif
42507 +
42508 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42509 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42510 +
42511 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42512 + pmi_start = ktva_ktla(pmi_start);
42513 + pmi_pal = ktva_ktla(pmi_pal);
42514 + pax_close_kernel();
42515 +#endif
42516 +
42517 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42518 if (pmi_base[3]) {
42519 printk(KERN_INFO "vesafb: pmi: ports = ");
42520 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42521 info->node, info->fix.id);
42522 return 0;
42523 err:
42524 +
42525 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42526 + module_free_exec(NULL, pmi_code);
42527 +#endif
42528 +
42529 if (info->screen_base)
42530 iounmap(info->screen_base);
42531 framebuffer_release(info);
42532 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42533 index 88714ae..16c2e11 100644
42534 --- a/drivers/video/via/via_clock.h
42535 +++ b/drivers/video/via/via_clock.h
42536 @@ -56,7 +56,7 @@ struct via_clock {
42537
42538 void (*set_engine_pll_state)(u8 state);
42539 void (*set_engine_pll)(struct via_pll_config config);
42540 -};
42541 +} __no_const;
42542
42543
42544 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42545 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42546 index 6b1b7e1..b2fa4d5 100644
42547 --- a/drivers/virtio/virtio_mmio.c
42548 +++ b/drivers/virtio/virtio_mmio.c
42549 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
42550
42551 resources[0].end = memparse(device, &str) - 1;
42552
42553 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42554 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42555 &base, &resources[1].start, &consumed,
42556 &vm_cmdline_id, &consumed);
42557
42558 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42559 index e56c934..fc22f4b 100644
42560 --- a/drivers/xen/xen-pciback/conf_space.h
42561 +++ b/drivers/xen/xen-pciback/conf_space.h
42562 @@ -44,15 +44,15 @@ struct config_field {
42563 struct {
42564 conf_dword_write write;
42565 conf_dword_read read;
42566 - } dw;
42567 + } __no_const dw;
42568 struct {
42569 conf_word_write write;
42570 conf_word_read read;
42571 - } w;
42572 + } __no_const w;
42573 struct {
42574 conf_byte_write write;
42575 conf_byte_read read;
42576 - } b;
42577 + } __no_const b;
42578 } u;
42579 struct list_head list;
42580 };
42581 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42582 index fef20db..d28b1ab 100644
42583 --- a/drivers/xen/xenfs/xenstored.c
42584 +++ b/drivers/xen/xenfs/xenstored.c
42585 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42586 static int xsd_kva_open(struct inode *inode, struct file *file)
42587 {
42588 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42589 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42590 + NULL);
42591 +#else
42592 xen_store_interface);
42593 +#endif
42594 +
42595 if (!file->private_data)
42596 return -ENOMEM;
42597 return 0;
42598 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42599 index 890bed5..17ae73e 100644
42600 --- a/fs/9p/vfs_inode.c
42601 +++ b/fs/9p/vfs_inode.c
42602 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42603 void
42604 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42605 {
42606 - char *s = nd_get_link(nd);
42607 + const char *s = nd_get_link(nd);
42608
42609 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42610 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42611 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42612 index 0efd152..b5802ad 100644
42613 --- a/fs/Kconfig.binfmt
42614 +++ b/fs/Kconfig.binfmt
42615 @@ -89,7 +89,7 @@ config HAVE_AOUT
42616
42617 config BINFMT_AOUT
42618 tristate "Kernel support for a.out and ECOFF binaries"
42619 - depends on HAVE_AOUT
42620 + depends on HAVE_AOUT && BROKEN
42621 ---help---
42622 A.out (Assembler.OUTput) is a set of formats for libraries and
42623 executables used in the earliest versions of UNIX. Linux used
42624 diff --git a/fs/aio.c b/fs/aio.c
42625 index 71f613c..9d01f1f 100644
42626 --- a/fs/aio.c
42627 +++ b/fs/aio.c
42628 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42629 size += sizeof(struct io_event) * nr_events;
42630 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42631
42632 - if (nr_pages < 0)
42633 + if (nr_pages <= 0)
42634 return -EINVAL;
42635
42636 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42637 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42638 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42639 {
42640 ssize_t ret;
42641 + struct iovec iovstack;
42642
42643 #ifdef CONFIG_COMPAT
42644 if (compat)
42645 ret = compat_rw_copy_check_uvector(type,
42646 (struct compat_iovec __user *)kiocb->ki_buf,
42647 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42648 + kiocb->ki_nbytes, 1, &iovstack,
42649 &kiocb->ki_iovec);
42650 else
42651 #endif
42652 ret = rw_copy_check_uvector(type,
42653 (struct iovec __user *)kiocb->ki_buf,
42654 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42655 + kiocb->ki_nbytes, 1, &iovstack,
42656 &kiocb->ki_iovec);
42657 if (ret < 0)
42658 goto out;
42659 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42660 if (ret < 0)
42661 goto out;
42662
42663 + if (kiocb->ki_iovec == &iovstack) {
42664 + kiocb->ki_inline_vec = iovstack;
42665 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42666 + }
42667 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42668 kiocb->ki_cur_seg = 0;
42669 /* ki_nbytes/left now reflect bytes instead of segs */
42670 diff --git a/fs/attr.c b/fs/attr.c
42671 index cce7df5..eaa2731 100644
42672 --- a/fs/attr.c
42673 +++ b/fs/attr.c
42674 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42675 unsigned long limit;
42676
42677 limit = rlimit(RLIMIT_FSIZE);
42678 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42679 if (limit != RLIM_INFINITY && offset > limit)
42680 goto out_sig;
42681 if (offset > inode->i_sb->s_maxbytes)
42682 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42683 index dce436e..378404b 100644
42684 --- a/fs/autofs4/waitq.c
42685 +++ b/fs/autofs4/waitq.c
42686 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42687 {
42688 unsigned long sigpipe, flags;
42689 mm_segment_t fs;
42690 - const char *data = (const char *)addr;
42691 + const char __user *data = (const char __force_user *)addr;
42692 ssize_t wr = 0;
42693
42694 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42695 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42696 return 1;
42697 }
42698
42699 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42700 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42701 +#endif
42702 +
42703 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42704 enum autofs_notify notify)
42705 {
42706 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42707
42708 /* If this is a direct mount request create a dummy name */
42709 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42710 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42711 + /* this name does get written to userland via autofs4_write() */
42712 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42713 +#else
42714 qstr.len = sprintf(name, "%p", dentry);
42715 +#endif
42716 else {
42717 qstr.len = autofs4_getpath(sbi, dentry, &name);
42718 if (!qstr.len) {
42719 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42720 index 2b3bda8..6a2d4be 100644
42721 --- a/fs/befs/linuxvfs.c
42722 +++ b/fs/befs/linuxvfs.c
42723 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42724 {
42725 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42726 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42727 - char *link = nd_get_link(nd);
42728 + const char *link = nd_get_link(nd);
42729 if (!IS_ERR(link))
42730 kfree(link);
42731 }
42732 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42733 index 0e7a6f8..332b1ca 100644
42734 --- a/fs/binfmt_aout.c
42735 +++ b/fs/binfmt_aout.c
42736 @@ -16,6 +16,7 @@
42737 #include <linux/string.h>
42738 #include <linux/fs.h>
42739 #include <linux/file.h>
42740 +#include <linux/security.h>
42741 #include <linux/stat.h>
42742 #include <linux/fcntl.h>
42743 #include <linux/ptrace.h>
42744 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42745 #endif
42746 # define START_STACK(u) ((void __user *)u.start_stack)
42747
42748 + memset(&dump, 0, sizeof(dump));
42749 +
42750 fs = get_fs();
42751 set_fs(KERNEL_DS);
42752 has_dumped = 1;
42753 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42754
42755 /* If the size of the dump file exceeds the rlimit, then see what would happen
42756 if we wrote the stack, but not the data area. */
42757 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42758 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42759 dump.u_dsize = 0;
42760
42761 /* Make sure we have enough room to write the stack and data areas. */
42762 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42763 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42764 dump.u_ssize = 0;
42765
42766 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42767 rlim = rlimit(RLIMIT_DATA);
42768 if (rlim >= RLIM_INFINITY)
42769 rlim = ~0;
42770 +
42771 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42772 if (ex.a_data + ex.a_bss > rlim)
42773 return -ENOMEM;
42774
42775 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42776
42777 install_exec_creds(bprm);
42778
42779 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42780 + current->mm->pax_flags = 0UL;
42781 +#endif
42782 +
42783 +#ifdef CONFIG_PAX_PAGEEXEC
42784 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42785 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42786 +
42787 +#ifdef CONFIG_PAX_EMUTRAMP
42788 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42789 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42790 +#endif
42791 +
42792 +#ifdef CONFIG_PAX_MPROTECT
42793 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42794 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42795 +#endif
42796 +
42797 + }
42798 +#endif
42799 +
42800 if (N_MAGIC(ex) == OMAGIC) {
42801 unsigned long text_addr, map_size;
42802 loff_t pos;
42803 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42804 }
42805
42806 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42807 - PROT_READ | PROT_WRITE | PROT_EXEC,
42808 + PROT_READ | PROT_WRITE,
42809 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42810 fd_offset + ex.a_text);
42811 if (error != N_DATADDR(ex)) {
42812 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42813 index fbd9f60..d4edac0 100644
42814 --- a/fs/binfmt_elf.c
42815 +++ b/fs/binfmt_elf.c
42816 @@ -33,6 +33,7 @@
42817 #include <linux/elf.h>
42818 #include <linux/utsname.h>
42819 #include <linux/coredump.h>
42820 +#include <linux/xattr.h>
42821 #include <asm/uaccess.h>
42822 #include <asm/param.h>
42823 #include <asm/page.h>
42824 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42825 #define elf_core_dump NULL
42826 #endif
42827
42828 +#ifdef CONFIG_PAX_MPROTECT
42829 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42830 +#endif
42831 +
42832 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42833 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42834 #else
42835 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
42836 .load_binary = load_elf_binary,
42837 .load_shlib = load_elf_library,
42838 .core_dump = elf_core_dump,
42839 +
42840 +#ifdef CONFIG_PAX_MPROTECT
42841 + .handle_mprotect= elf_handle_mprotect,
42842 +#endif
42843 +
42844 .min_coredump = ELF_EXEC_PAGESIZE,
42845 };
42846
42847 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
42848
42849 static int set_brk(unsigned long start, unsigned long end)
42850 {
42851 + unsigned long e = end;
42852 +
42853 start = ELF_PAGEALIGN(start);
42854 end = ELF_PAGEALIGN(end);
42855 if (end > start) {
42856 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
42857 if (BAD_ADDR(addr))
42858 return addr;
42859 }
42860 - current->mm->start_brk = current->mm->brk = end;
42861 + current->mm->start_brk = current->mm->brk = e;
42862 return 0;
42863 }
42864
42865 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42866 elf_addr_t __user *u_rand_bytes;
42867 const char *k_platform = ELF_PLATFORM;
42868 const char *k_base_platform = ELF_BASE_PLATFORM;
42869 - unsigned char k_rand_bytes[16];
42870 + u32 k_rand_bytes[4];
42871 int items;
42872 elf_addr_t *elf_info;
42873 int ei_index = 0;
42874 const struct cred *cred = current_cred();
42875 struct vm_area_struct *vma;
42876 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42877
42878 /*
42879 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42880 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42881 * Generate 16 random bytes for userspace PRNG seeding.
42882 */
42883 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42884 - u_rand_bytes = (elf_addr_t __user *)
42885 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42886 + srandom32(k_rand_bytes[0] ^ random32());
42887 + srandom32(k_rand_bytes[1] ^ random32());
42888 + srandom32(k_rand_bytes[2] ^ random32());
42889 + srandom32(k_rand_bytes[3] ^ random32());
42890 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42891 + u_rand_bytes = (elf_addr_t __user *) p;
42892 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42893 return -EFAULT;
42894
42895 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42896 return -EFAULT;
42897 current->mm->env_end = p;
42898
42899 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42900 +
42901 /* Put the elf_info on the stack in the right place. */
42902 sp = (elf_addr_t __user *)envp + 1;
42903 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42904 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42905 return -EFAULT;
42906 return 0;
42907 }
42908 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
42909 an ELF header */
42910
42911 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42912 - struct file *interpreter, unsigned long *interp_map_addr,
42913 - unsigned long no_base)
42914 + struct file *interpreter, unsigned long no_base)
42915 {
42916 struct elf_phdr *elf_phdata;
42917 struct elf_phdr *eppnt;
42918 - unsigned long load_addr = 0;
42919 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42920 int load_addr_set = 0;
42921 unsigned long last_bss = 0, elf_bss = 0;
42922 - unsigned long error = ~0UL;
42923 + unsigned long error = -EINVAL;
42924 unsigned long total_size;
42925 int retval, i, size;
42926
42927 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42928 goto out_close;
42929 }
42930
42931 +#ifdef CONFIG_PAX_SEGMEXEC
42932 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42933 + pax_task_size = SEGMEXEC_TASK_SIZE;
42934 +#endif
42935 +
42936 eppnt = elf_phdata;
42937 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42938 if (eppnt->p_type == PT_LOAD) {
42939 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42940 map_addr = elf_map(interpreter, load_addr + vaddr,
42941 eppnt, elf_prot, elf_type, total_size);
42942 total_size = 0;
42943 - if (!*interp_map_addr)
42944 - *interp_map_addr = map_addr;
42945 error = map_addr;
42946 if (BAD_ADDR(map_addr))
42947 goto out_close;
42948 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42949 k = load_addr + eppnt->p_vaddr;
42950 if (BAD_ADDR(k) ||
42951 eppnt->p_filesz > eppnt->p_memsz ||
42952 - eppnt->p_memsz > TASK_SIZE ||
42953 - TASK_SIZE - eppnt->p_memsz < k) {
42954 + eppnt->p_memsz > pax_task_size ||
42955 + pax_task_size - eppnt->p_memsz < k) {
42956 error = -ENOMEM;
42957 goto out_close;
42958 }
42959 @@ -530,6 +551,315 @@ out:
42960 return error;
42961 }
42962
42963 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42964 +#ifdef CONFIG_PAX_SOFTMODE
42965 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42966 +{
42967 + unsigned long pax_flags = 0UL;
42968 +
42969 +#ifdef CONFIG_PAX_PAGEEXEC
42970 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42971 + pax_flags |= MF_PAX_PAGEEXEC;
42972 +#endif
42973 +
42974 +#ifdef CONFIG_PAX_SEGMEXEC
42975 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42976 + pax_flags |= MF_PAX_SEGMEXEC;
42977 +#endif
42978 +
42979 +#ifdef CONFIG_PAX_EMUTRAMP
42980 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42981 + pax_flags |= MF_PAX_EMUTRAMP;
42982 +#endif
42983 +
42984 +#ifdef CONFIG_PAX_MPROTECT
42985 + if (elf_phdata->p_flags & PF_MPROTECT)
42986 + pax_flags |= MF_PAX_MPROTECT;
42987 +#endif
42988 +
42989 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42990 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42991 + pax_flags |= MF_PAX_RANDMMAP;
42992 +#endif
42993 +
42994 + return pax_flags;
42995 +}
42996 +#endif
42997 +
42998 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42999 +{
43000 + unsigned long pax_flags = 0UL;
43001 +
43002 +#ifdef CONFIG_PAX_PAGEEXEC
43003 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43004 + pax_flags |= MF_PAX_PAGEEXEC;
43005 +#endif
43006 +
43007 +#ifdef CONFIG_PAX_SEGMEXEC
43008 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43009 + pax_flags |= MF_PAX_SEGMEXEC;
43010 +#endif
43011 +
43012 +#ifdef CONFIG_PAX_EMUTRAMP
43013 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43014 + pax_flags |= MF_PAX_EMUTRAMP;
43015 +#endif
43016 +
43017 +#ifdef CONFIG_PAX_MPROTECT
43018 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43019 + pax_flags |= MF_PAX_MPROTECT;
43020 +#endif
43021 +
43022 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43023 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43024 + pax_flags |= MF_PAX_RANDMMAP;
43025 +#endif
43026 +
43027 + return pax_flags;
43028 +}
43029 +#endif
43030 +
43031 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43032 +#ifdef CONFIG_PAX_SOFTMODE
43033 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43034 +{
43035 + unsigned long pax_flags = 0UL;
43036 +
43037 +#ifdef CONFIG_PAX_PAGEEXEC
43038 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43039 + pax_flags |= MF_PAX_PAGEEXEC;
43040 +#endif
43041 +
43042 +#ifdef CONFIG_PAX_SEGMEXEC
43043 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43044 + pax_flags |= MF_PAX_SEGMEXEC;
43045 +#endif
43046 +
43047 +#ifdef CONFIG_PAX_EMUTRAMP
43048 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43049 + pax_flags |= MF_PAX_EMUTRAMP;
43050 +#endif
43051 +
43052 +#ifdef CONFIG_PAX_MPROTECT
43053 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43054 + pax_flags |= MF_PAX_MPROTECT;
43055 +#endif
43056 +
43057 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43058 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43059 + pax_flags |= MF_PAX_RANDMMAP;
43060 +#endif
43061 +
43062 + return pax_flags;
43063 +}
43064 +#endif
43065 +
43066 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43067 +{
43068 + unsigned long pax_flags = 0UL;
43069 +
43070 +#ifdef CONFIG_PAX_PAGEEXEC
43071 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43072 + pax_flags |= MF_PAX_PAGEEXEC;
43073 +#endif
43074 +
43075 +#ifdef CONFIG_PAX_SEGMEXEC
43076 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43077 + pax_flags |= MF_PAX_SEGMEXEC;
43078 +#endif
43079 +
43080 +#ifdef CONFIG_PAX_EMUTRAMP
43081 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43082 + pax_flags |= MF_PAX_EMUTRAMP;
43083 +#endif
43084 +
43085 +#ifdef CONFIG_PAX_MPROTECT
43086 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43087 + pax_flags |= MF_PAX_MPROTECT;
43088 +#endif
43089 +
43090 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43091 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43092 + pax_flags |= MF_PAX_RANDMMAP;
43093 +#endif
43094 +
43095 + return pax_flags;
43096 +}
43097 +#endif
43098 +
43099 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43100 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43101 +{
43102 + unsigned long pax_flags = 0UL;
43103 +
43104 +#ifdef CONFIG_PAX_EI_PAX
43105 +
43106 +#ifdef CONFIG_PAX_PAGEEXEC
43107 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43108 + pax_flags |= MF_PAX_PAGEEXEC;
43109 +#endif
43110 +
43111 +#ifdef CONFIG_PAX_SEGMEXEC
43112 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43113 + pax_flags |= MF_PAX_SEGMEXEC;
43114 +#endif
43115 +
43116 +#ifdef CONFIG_PAX_EMUTRAMP
43117 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43118 + pax_flags |= MF_PAX_EMUTRAMP;
43119 +#endif
43120 +
43121 +#ifdef CONFIG_PAX_MPROTECT
43122 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43123 + pax_flags |= MF_PAX_MPROTECT;
43124 +#endif
43125 +
43126 +#ifdef CONFIG_PAX_ASLR
43127 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43128 + pax_flags |= MF_PAX_RANDMMAP;
43129 +#endif
43130 +
43131 +#else
43132 +
43133 +#ifdef CONFIG_PAX_PAGEEXEC
43134 + pax_flags |= MF_PAX_PAGEEXEC;
43135 +#endif
43136 +
43137 +#ifdef CONFIG_PAX_SEGMEXEC
43138 + pax_flags |= MF_PAX_SEGMEXEC;
43139 +#endif
43140 +
43141 +#ifdef CONFIG_PAX_MPROTECT
43142 + pax_flags |= MF_PAX_MPROTECT;
43143 +#endif
43144 +
43145 +#ifdef CONFIG_PAX_RANDMMAP
43146 + if (randomize_va_space)
43147 + pax_flags |= MF_PAX_RANDMMAP;
43148 +#endif
43149 +
43150 +#endif
43151 +
43152 + return pax_flags;
43153 +}
43154 +
43155 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43156 +{
43157 +
43158 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43159 + unsigned long i;
43160 +
43161 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43162 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43163 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43164 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43165 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43166 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43167 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43168 + return ~0UL;
43169 +
43170 +#ifdef CONFIG_PAX_SOFTMODE
43171 + if (pax_softmode)
43172 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43173 + else
43174 +#endif
43175 +
43176 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43177 + break;
43178 + }
43179 +#endif
43180 +
43181 + return ~0UL;
43182 +}
43183 +
43184 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43185 +{
43186 +
43187 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43188 + ssize_t xattr_size, i;
43189 + unsigned char xattr_value[5];
43190 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43191 +
43192 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43193 + if (xattr_size <= 0 || xattr_size > 5)
43194 + return ~0UL;
43195 +
43196 + for (i = 0; i < xattr_size; i++)
43197 + switch (xattr_value[i]) {
43198 + default:
43199 + return ~0UL;
43200 +
43201 +#define parse_flag(option1, option2, flag) \
43202 + case option1: \
43203 + if (pax_flags_hardmode & MF_PAX_##flag) \
43204 + return ~0UL; \
43205 + pax_flags_hardmode |= MF_PAX_##flag; \
43206 + break; \
43207 + case option2: \
43208 + if (pax_flags_softmode & MF_PAX_##flag) \
43209 + return ~0UL; \
43210 + pax_flags_softmode |= MF_PAX_##flag; \
43211 + break;
43212 +
43213 + parse_flag('p', 'P', PAGEEXEC);
43214 + parse_flag('e', 'E', EMUTRAMP);
43215 + parse_flag('m', 'M', MPROTECT);
43216 + parse_flag('r', 'R', RANDMMAP);
43217 + parse_flag('s', 'S', SEGMEXEC);
43218 +
43219 +#undef parse_flag
43220 + }
43221 +
43222 + if (pax_flags_hardmode & pax_flags_softmode)
43223 + return ~0UL;
43224 +
43225 +#ifdef CONFIG_PAX_SOFTMODE
43226 + if (pax_softmode)
43227 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43228 + else
43229 +#endif
43230 +
43231 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43232 +#else
43233 + return ~0UL;
43234 +#endif
43235 +
43236 +}
43237 +
43238 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43239 +{
43240 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43241 +
43242 + pax_flags = pax_parse_ei_pax(elf_ex);
43243 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43244 + xattr_pax_flags = pax_parse_xattr_pax(file);
43245 +
43246 + if (pt_pax_flags == ~0UL)
43247 + pt_pax_flags = xattr_pax_flags;
43248 + else if (xattr_pax_flags == ~0UL)
43249 + xattr_pax_flags = pt_pax_flags;
43250 + if (pt_pax_flags != xattr_pax_flags)
43251 + return -EINVAL;
43252 + if (pt_pax_flags != ~0UL)
43253 + pax_flags = pt_pax_flags;
43254 +
43255 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43256 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43257 + if ((__supported_pte_mask & _PAGE_NX))
43258 + pax_flags &= ~MF_PAX_SEGMEXEC;
43259 + else
43260 + pax_flags &= ~MF_PAX_PAGEEXEC;
43261 + }
43262 +#endif
43263 +
43264 + if (0 > pax_check_flags(&pax_flags))
43265 + return -EINVAL;
43266 +
43267 + current->mm->pax_flags = pax_flags;
43268 + return 0;
43269 +}
43270 +#endif
43271 +
43272 /*
43273 * These are the functions used to load ELF style executables and shared
43274 * libraries. There is no binary dependent code anywhere else.
43275 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43276 {
43277 unsigned int random_variable = 0;
43278
43279 +#ifdef CONFIG_PAX_RANDUSTACK
43280 + if (randomize_va_space)
43281 + return stack_top - current->mm->delta_stack;
43282 +#endif
43283 +
43284 if ((current->flags & PF_RANDOMIZE) &&
43285 !(current->personality & ADDR_NO_RANDOMIZE)) {
43286 random_variable = get_random_int() & STACK_RND_MASK;
43287 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43288 unsigned long load_addr = 0, load_bias = 0;
43289 int load_addr_set = 0;
43290 char * elf_interpreter = NULL;
43291 - unsigned long error;
43292 + unsigned long error = 0;
43293 struct elf_phdr *elf_ppnt, *elf_phdata;
43294 unsigned long elf_bss, elf_brk;
43295 int retval, i;
43296 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43297 unsigned long start_code, end_code, start_data, end_data;
43298 unsigned long reloc_func_desc __maybe_unused = 0;
43299 int executable_stack = EXSTACK_DEFAULT;
43300 - unsigned long def_flags = 0;
43301 struct {
43302 struct elfhdr elf_ex;
43303 struct elfhdr interp_elf_ex;
43304 } *loc;
43305 + unsigned long pax_task_size = TASK_SIZE;
43306
43307 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43308 if (!loc) {
43309 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43310 goto out_free_dentry;
43311
43312 /* OK, This is the point of no return */
43313 - current->mm->def_flags = def_flags;
43314 +
43315 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43316 + current->mm->pax_flags = 0UL;
43317 +#endif
43318 +
43319 +#ifdef CONFIG_PAX_DLRESOLVE
43320 + current->mm->call_dl_resolve = 0UL;
43321 +#endif
43322 +
43323 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43324 + current->mm->call_syscall = 0UL;
43325 +#endif
43326 +
43327 +#ifdef CONFIG_PAX_ASLR
43328 + current->mm->delta_mmap = 0UL;
43329 + current->mm->delta_stack = 0UL;
43330 +#endif
43331 +
43332 + current->mm->def_flags = 0;
43333 +
43334 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43335 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43336 + send_sig(SIGKILL, current, 0);
43337 + goto out_free_dentry;
43338 + }
43339 +#endif
43340 +
43341 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43342 + pax_set_initial_flags(bprm);
43343 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43344 + if (pax_set_initial_flags_func)
43345 + (pax_set_initial_flags_func)(bprm);
43346 +#endif
43347 +
43348 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43349 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43350 + current->mm->context.user_cs_limit = PAGE_SIZE;
43351 + current->mm->def_flags |= VM_PAGEEXEC;
43352 + }
43353 +#endif
43354 +
43355 +#ifdef CONFIG_PAX_SEGMEXEC
43356 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43357 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43358 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43359 + pax_task_size = SEGMEXEC_TASK_SIZE;
43360 + current->mm->def_flags |= VM_NOHUGEPAGE;
43361 + }
43362 +#endif
43363 +
43364 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43365 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43366 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43367 + put_cpu();
43368 + }
43369 +#endif
43370
43371 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43372 may depend on the personality. */
43373 SET_PERSONALITY(loc->elf_ex);
43374 +
43375 +#ifdef CONFIG_PAX_ASLR
43376 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43377 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43378 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43379 + }
43380 +#endif
43381 +
43382 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43383 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43384 + executable_stack = EXSTACK_DISABLE_X;
43385 + current->personality &= ~READ_IMPLIES_EXEC;
43386 + } else
43387 +#endif
43388 +
43389 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43390 current->personality |= READ_IMPLIES_EXEC;
43391
43392 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43393 #else
43394 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43395 #endif
43396 +
43397 +#ifdef CONFIG_PAX_RANDMMAP
43398 + /* PaX: randomize base address at the default exe base if requested */
43399 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43400 +#ifdef CONFIG_SPARC64
43401 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43402 +#else
43403 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43404 +#endif
43405 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43406 + elf_flags |= MAP_FIXED;
43407 + }
43408 +#endif
43409 +
43410 }
43411
43412 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43413 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43414 * allowed task size. Note that p_filesz must always be
43415 * <= p_memsz so it is only necessary to check p_memsz.
43416 */
43417 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43418 - elf_ppnt->p_memsz > TASK_SIZE ||
43419 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43420 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43421 + elf_ppnt->p_memsz > pax_task_size ||
43422 + pax_task_size - elf_ppnt->p_memsz < k) {
43423 /* set_brk can never work. Avoid overflows. */
43424 send_sig(SIGKILL, current, 0);
43425 retval = -EINVAL;
43426 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43427 goto out_free_dentry;
43428 }
43429 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43430 - send_sig(SIGSEGV, current, 0);
43431 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43432 - goto out_free_dentry;
43433 + /*
43434 + * This bss-zeroing can fail if the ELF
43435 + * file specifies odd protections. So
43436 + * we don't check the return value
43437 + */
43438 }
43439
43440 +#ifdef CONFIG_PAX_RANDMMAP
43441 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43442 + unsigned long start, size;
43443 +
43444 + start = ELF_PAGEALIGN(elf_brk);
43445 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43446 + down_read(&current->mm->mmap_sem);
43447 + retval = -ENOMEM;
43448 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43449 + unsigned long prot = PROT_NONE;
43450 +
43451 + up_read(&current->mm->mmap_sem);
43452 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43453 +// if (current->personality & ADDR_NO_RANDOMIZE)
43454 +// prot = PROT_READ;
43455 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43456 + retval = IS_ERR_VALUE(start) ? start : 0;
43457 + } else
43458 + up_read(&current->mm->mmap_sem);
43459 + if (retval == 0)
43460 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43461 + if (retval < 0) {
43462 + send_sig(SIGKILL, current, 0);
43463 + goto out_free_dentry;
43464 + }
43465 + }
43466 +#endif
43467 +
43468 if (elf_interpreter) {
43469 - unsigned long interp_map_addr = 0;
43470 -
43471 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43472 interpreter,
43473 - &interp_map_addr,
43474 load_bias);
43475 if (!IS_ERR((void *)elf_entry)) {
43476 /*
43477 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43478 * Decide what to dump of a segment, part, all or none.
43479 */
43480 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43481 - unsigned long mm_flags)
43482 + unsigned long mm_flags, long signr)
43483 {
43484 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43485
43486 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43487 if (vma->vm_file == NULL)
43488 return 0;
43489
43490 - if (FILTER(MAPPED_PRIVATE))
43491 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43492 goto whole;
43493
43494 /*
43495 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43496 {
43497 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43498 int i = 0;
43499 - do
43500 + do {
43501 i += 2;
43502 - while (auxv[i - 2] != AT_NULL);
43503 + } while (auxv[i - 2] != AT_NULL);
43504 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43505 }
43506
43507 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43508 }
43509
43510 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43511 - unsigned long mm_flags)
43512 + struct coredump_params *cprm)
43513 {
43514 struct vm_area_struct *vma;
43515 size_t size = 0;
43516
43517 for (vma = first_vma(current, gate_vma); vma != NULL;
43518 vma = next_vma(vma, gate_vma))
43519 - size += vma_dump_size(vma, mm_flags);
43520 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43521 return size;
43522 }
43523
43524 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43525
43526 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43527
43528 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43529 + offset += elf_core_vma_data_size(gate_vma, cprm);
43530 offset += elf_core_extra_data_size();
43531 e_shoff = offset;
43532
43533 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43534 offset = dataoff;
43535
43536 size += sizeof(*elf);
43537 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43538 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43539 goto end_coredump;
43540
43541 size += sizeof(*phdr4note);
43542 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43543 if (size > cprm->limit
43544 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43545 goto end_coredump;
43546 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43547 phdr.p_offset = offset;
43548 phdr.p_vaddr = vma->vm_start;
43549 phdr.p_paddr = 0;
43550 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43551 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43552 phdr.p_memsz = vma->vm_end - vma->vm_start;
43553 offset += phdr.p_filesz;
43554 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43555 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43556 phdr.p_align = ELF_EXEC_PAGESIZE;
43557
43558 size += sizeof(phdr);
43559 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43560 if (size > cprm->limit
43561 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43562 goto end_coredump;
43563 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43564 unsigned long addr;
43565 unsigned long end;
43566
43567 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43568 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43569
43570 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43571 struct page *page;
43572 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43573 page = get_dump_page(addr);
43574 if (page) {
43575 void *kaddr = kmap(page);
43576 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43577 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43578 !dump_write(cprm->file, kaddr,
43579 PAGE_SIZE);
43580 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43581
43582 if (e_phnum == PN_XNUM) {
43583 size += sizeof(*shdr4extnum);
43584 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43585 if (size > cprm->limit
43586 || !dump_write(cprm->file, shdr4extnum,
43587 sizeof(*shdr4extnum)))
43588 @@ -2216,6 +2667,97 @@ out:
43589
43590 #endif /* CONFIG_ELF_CORE */
43591
43592 +#ifdef CONFIG_PAX_MPROTECT
43593 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43594 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43595 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43596 + *
43597 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43598 + * basis because we want to allow the common case and not the special ones.
43599 + */
43600 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43601 +{
43602 + struct elfhdr elf_h;
43603 + struct elf_phdr elf_p;
43604 + unsigned long i;
43605 + unsigned long oldflags;
43606 + bool is_textrel_rw, is_textrel_rx, is_relro;
43607 +
43608 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43609 + return;
43610 +
43611 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43612 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43613 +
43614 +#ifdef CONFIG_PAX_ELFRELOCS
43615 + /* possible TEXTREL */
43616 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43617 + 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);
43618 +#else
43619 + is_textrel_rw = false;
43620 + is_textrel_rx = false;
43621 +#endif
43622 +
43623 + /* possible RELRO */
43624 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43625 +
43626 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43627 + return;
43628 +
43629 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43630 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43631 +
43632 +#ifdef CONFIG_PAX_ETEXECRELOCS
43633 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43634 +#else
43635 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43636 +#endif
43637 +
43638 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43639 + !elf_check_arch(&elf_h) ||
43640 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43641 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43642 + return;
43643 +
43644 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43645 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43646 + return;
43647 + switch (elf_p.p_type) {
43648 + case PT_DYNAMIC:
43649 + if (!is_textrel_rw && !is_textrel_rx)
43650 + continue;
43651 + i = 0UL;
43652 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43653 + elf_dyn dyn;
43654 +
43655 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43656 + return;
43657 + if (dyn.d_tag == DT_NULL)
43658 + return;
43659 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43660 + gr_log_textrel(vma);
43661 + if (is_textrel_rw)
43662 + vma->vm_flags |= VM_MAYWRITE;
43663 + else
43664 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43665 + vma->vm_flags &= ~VM_MAYWRITE;
43666 + return;
43667 + }
43668 + i++;
43669 + }
43670 + return;
43671 +
43672 + case PT_GNU_RELRO:
43673 + if (!is_relro)
43674 + continue;
43675 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43676 + vma->vm_flags &= ~VM_MAYWRITE;
43677 + return;
43678 + }
43679 + }
43680 +}
43681 +#endif
43682 +
43683 static int __init init_elf_binfmt(void)
43684 {
43685 register_binfmt(&elf_format);
43686 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43687 index e280352..7b2f231 100644
43688 --- a/fs/binfmt_flat.c
43689 +++ b/fs/binfmt_flat.c
43690 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43691 realdatastart = (unsigned long) -ENOMEM;
43692 printk("Unable to allocate RAM for process data, errno %d\n",
43693 (int)-realdatastart);
43694 + down_write(&current->mm->mmap_sem);
43695 vm_munmap(textpos, text_len);
43696 + up_write(&current->mm->mmap_sem);
43697 ret = realdatastart;
43698 goto err;
43699 }
43700 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43701 }
43702 if (IS_ERR_VALUE(result)) {
43703 printk("Unable to read data+bss, errno %d\n", (int)-result);
43704 + down_write(&current->mm->mmap_sem);
43705 vm_munmap(textpos, text_len);
43706 vm_munmap(realdatastart, len);
43707 + up_write(&current->mm->mmap_sem);
43708 ret = result;
43709 goto err;
43710 }
43711 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43712 }
43713 if (IS_ERR_VALUE(result)) {
43714 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43715 + down_write(&current->mm->mmap_sem);
43716 vm_munmap(textpos, text_len + data_len + extra +
43717 MAX_SHARED_LIBS * sizeof(unsigned long));
43718 + up_write(&current->mm->mmap_sem);
43719 ret = result;
43720 goto err;
43721 }
43722 diff --git a/fs/bio.c b/fs/bio.c
43723 index b96fc6c..431d628 100644
43724 --- a/fs/bio.c
43725 +++ b/fs/bio.c
43726 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43727 /*
43728 * Overflow, abort
43729 */
43730 - if (end < start)
43731 + if (end < start || end - start > INT_MAX - nr_pages)
43732 return ERR_PTR(-EINVAL);
43733
43734 nr_pages += end - start;
43735 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43736 /*
43737 * Overflow, abort
43738 */
43739 - if (end < start)
43740 + if (end < start || end - start > INT_MAX - nr_pages)
43741 return ERR_PTR(-EINVAL);
43742
43743 nr_pages += end - start;
43744 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43745 const int read = bio_data_dir(bio) == READ;
43746 struct bio_map_data *bmd = bio->bi_private;
43747 int i;
43748 - char *p = bmd->sgvecs[0].iov_base;
43749 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43750
43751 __bio_for_each_segment(bvec, bio, i, 0) {
43752 char *addr = page_address(bvec->bv_page);
43753 diff --git a/fs/block_dev.c b/fs/block_dev.c
43754 index ab3a456..7da538b 100644
43755 --- a/fs/block_dev.c
43756 +++ b/fs/block_dev.c
43757 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43758 else if (bdev->bd_contains == bdev)
43759 return true; /* is a whole device which isn't held */
43760
43761 - else if (whole->bd_holder == bd_may_claim)
43762 + else if (whole->bd_holder == (void *)bd_may_claim)
43763 return true; /* is a partition of a device that is being partitioned */
43764 else if (whole->bd_holder != NULL)
43765 return false; /* is a partition of a held device */
43766 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43767 index 5a3e45d..ad19cc3 100644
43768 --- a/fs/btrfs/check-integrity.c
43769 +++ b/fs/btrfs/check-integrity.c
43770 @@ -156,7 +156,7 @@ struct btrfsic_block {
43771 union {
43772 bio_end_io_t *bio;
43773 bh_end_io_t *bh;
43774 - } orig_bio_bh_end_io;
43775 + } __no_const orig_bio_bh_end_io;
43776 int submit_bio_bh_rw;
43777 u64 flush_gen; /* only valid if !never_written */
43778 };
43779 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43780 index cdfb4c4..da736d4 100644
43781 --- a/fs/btrfs/ctree.c
43782 +++ b/fs/btrfs/ctree.c
43783 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43784 free_extent_buffer(buf);
43785 add_root_to_dirty_list(root);
43786 } else {
43787 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43788 - parent_start = parent->start;
43789 - else
43790 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43791 + if (parent)
43792 + parent_start = parent->start;
43793 + else
43794 + parent_start = 0;
43795 + } else
43796 parent_start = 0;
43797
43798 WARN_ON(trans->transid != btrfs_header_generation(parent));
43799 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43800 index 95542a1..95a8727 100644
43801 --- a/fs/btrfs/inode.c
43802 +++ b/fs/btrfs/inode.c
43803 @@ -7243,7 +7243,7 @@ fail:
43804 return -ENOMEM;
43805 }
43806
43807 -static int btrfs_getattr(struct vfsmount *mnt,
43808 +int btrfs_getattr(struct vfsmount *mnt,
43809 struct dentry *dentry, struct kstat *stat)
43810 {
43811 struct inode *inode = dentry->d_inode;
43812 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43813 return 0;
43814 }
43815
43816 +EXPORT_SYMBOL(btrfs_getattr);
43817 +
43818 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43819 +{
43820 + return BTRFS_I(inode)->root->anon_dev;
43821 +}
43822 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43823 +
43824 /*
43825 * If a file is moved, it will inherit the cow and compression flags of the new
43826 * directory.
43827 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43828 index 8fcf9a5..a200000 100644
43829 --- a/fs/btrfs/ioctl.c
43830 +++ b/fs/btrfs/ioctl.c
43831 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43832 for (i = 0; i < num_types; i++) {
43833 struct btrfs_space_info *tmp;
43834
43835 + /* Don't copy in more than we allocated */
43836 if (!slot_count)
43837 break;
43838
43839 + slot_count--;
43840 +
43841 info = NULL;
43842 rcu_read_lock();
43843 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43844 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43845 memcpy(dest, &space, sizeof(space));
43846 dest++;
43847 space_args.total_spaces++;
43848 - slot_count--;
43849 }
43850 - if (!slot_count)
43851 - break;
43852 }
43853 up_read(&info->groups_sem);
43854 }
43855 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43856 index 776f0aa..3aad281 100644
43857 --- a/fs/btrfs/relocation.c
43858 +++ b/fs/btrfs/relocation.c
43859 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43860 }
43861 spin_unlock(&rc->reloc_root_tree.lock);
43862
43863 - BUG_ON((struct btrfs_root *)node->data != root);
43864 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43865
43866 if (!del) {
43867 spin_lock(&rc->reloc_root_tree.lock);
43868 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43869 index 622f469..e8d2d55 100644
43870 --- a/fs/cachefiles/bind.c
43871 +++ b/fs/cachefiles/bind.c
43872 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43873 args);
43874
43875 /* start by checking things over */
43876 - ASSERT(cache->fstop_percent >= 0 &&
43877 - cache->fstop_percent < cache->fcull_percent &&
43878 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43879 cache->fcull_percent < cache->frun_percent &&
43880 cache->frun_percent < 100);
43881
43882 - ASSERT(cache->bstop_percent >= 0 &&
43883 - cache->bstop_percent < cache->bcull_percent &&
43884 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43885 cache->bcull_percent < cache->brun_percent &&
43886 cache->brun_percent < 100);
43887
43888 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43889 index 0a1467b..6a53245 100644
43890 --- a/fs/cachefiles/daemon.c
43891 +++ b/fs/cachefiles/daemon.c
43892 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43893 if (n > buflen)
43894 return -EMSGSIZE;
43895
43896 - if (copy_to_user(_buffer, buffer, n) != 0)
43897 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43898 return -EFAULT;
43899
43900 return n;
43901 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43902 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43903 return -EIO;
43904
43905 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43906 + if (datalen > PAGE_SIZE - 1)
43907 return -EOPNOTSUPP;
43908
43909 /* drag the command string into the kernel so we can parse it */
43910 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43911 if (args[0] != '%' || args[1] != '\0')
43912 return -EINVAL;
43913
43914 - if (fstop < 0 || fstop >= cache->fcull_percent)
43915 + if (fstop >= cache->fcull_percent)
43916 return cachefiles_daemon_range_error(cache, args);
43917
43918 cache->fstop_percent = fstop;
43919 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43920 if (args[0] != '%' || args[1] != '\0')
43921 return -EINVAL;
43922
43923 - if (bstop < 0 || bstop >= cache->bcull_percent)
43924 + if (bstop >= cache->bcull_percent)
43925 return cachefiles_daemon_range_error(cache, args);
43926
43927 cache->bstop_percent = bstop;
43928 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43929 index bd6bc1b..b627b53 100644
43930 --- a/fs/cachefiles/internal.h
43931 +++ b/fs/cachefiles/internal.h
43932 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43933 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43934 struct rb_root active_nodes; /* active nodes (can't be culled) */
43935 rwlock_t active_lock; /* lock for active_nodes */
43936 - atomic_t gravecounter; /* graveyard uniquifier */
43937 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43938 unsigned frun_percent; /* when to stop culling (% files) */
43939 unsigned fcull_percent; /* when to start culling (% files) */
43940 unsigned fstop_percent; /* when to stop allocating (% files) */
43941 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43942 * proc.c
43943 */
43944 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43945 -extern atomic_t cachefiles_lookup_histogram[HZ];
43946 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43947 -extern atomic_t cachefiles_create_histogram[HZ];
43948 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43949 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43950 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43951
43952 extern int __init cachefiles_proc_init(void);
43953 extern void cachefiles_proc_cleanup(void);
43954 static inline
43955 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43956 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43957 {
43958 unsigned long jif = jiffies - start_jif;
43959 if (jif >= HZ)
43960 jif = HZ - 1;
43961 - atomic_inc(&histogram[jif]);
43962 + atomic_inc_unchecked(&histogram[jif]);
43963 }
43964
43965 #else
43966 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43967 index b0b5f7c..039bb26 100644
43968 --- a/fs/cachefiles/namei.c
43969 +++ b/fs/cachefiles/namei.c
43970 @@ -318,7 +318,7 @@ try_again:
43971 /* first step is to make up a grave dentry in the graveyard */
43972 sprintf(nbuffer, "%08x%08x",
43973 (uint32_t) get_seconds(),
43974 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43975 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43976
43977 /* do the multiway lock magic */
43978 trap = lock_rename(cache->graveyard, dir);
43979 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43980 index eccd339..4c1d995 100644
43981 --- a/fs/cachefiles/proc.c
43982 +++ b/fs/cachefiles/proc.c
43983 @@ -14,9 +14,9 @@
43984 #include <linux/seq_file.h>
43985 #include "internal.h"
43986
43987 -atomic_t cachefiles_lookup_histogram[HZ];
43988 -atomic_t cachefiles_mkdir_histogram[HZ];
43989 -atomic_t cachefiles_create_histogram[HZ];
43990 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43991 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43992 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43993
43994 /*
43995 * display the latency histogram
43996 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43997 return 0;
43998 default:
43999 index = (unsigned long) v - 3;
44000 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44001 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44002 - z = atomic_read(&cachefiles_create_histogram[index]);
44003 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44004 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44005 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44006 if (x == 0 && y == 0 && z == 0)
44007 return 0;
44008
44009 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44010 index c994691..2a1537f 100644
44011 --- a/fs/cachefiles/rdwr.c
44012 +++ b/fs/cachefiles/rdwr.c
44013 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44014 old_fs = get_fs();
44015 set_fs(KERNEL_DS);
44016 ret = file->f_op->write(
44017 - file, (const void __user *) data, len, &pos);
44018 + file, (const void __force_user *) data, len, &pos);
44019 set_fs(old_fs);
44020 kunmap(page);
44021 if (ret != len)
44022 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44023 index e5b7731..b9c59fb 100644
44024 --- a/fs/ceph/dir.c
44025 +++ b/fs/ceph/dir.c
44026 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44027 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44028 struct ceph_mds_client *mdsc = fsc->mdsc;
44029 unsigned frag = fpos_frag(filp->f_pos);
44030 - int off = fpos_off(filp->f_pos);
44031 + unsigned int off = fpos_off(filp->f_pos);
44032 int err;
44033 u32 ftype;
44034 struct ceph_mds_reply_info_parsed *rinfo;
44035 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44036 index d9ea6ed..1e6c8ac 100644
44037 --- a/fs/cifs/cifs_debug.c
44038 +++ b/fs/cifs/cifs_debug.c
44039 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44040
44041 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44042 #ifdef CONFIG_CIFS_STATS2
44043 - atomic_set(&totBufAllocCount, 0);
44044 - atomic_set(&totSmBufAllocCount, 0);
44045 + atomic_set_unchecked(&totBufAllocCount, 0);
44046 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44047 #endif /* CONFIG_CIFS_STATS2 */
44048 spin_lock(&cifs_tcp_ses_lock);
44049 list_for_each(tmp1, &cifs_tcp_ses_list) {
44050 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44051 tcon = list_entry(tmp3,
44052 struct cifs_tcon,
44053 tcon_list);
44054 - atomic_set(&tcon->num_smbs_sent, 0);
44055 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44056 if (server->ops->clear_stats)
44057 server->ops->clear_stats(tcon);
44058 }
44059 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44060 smBufAllocCount.counter, cifs_min_small);
44061 #ifdef CONFIG_CIFS_STATS2
44062 seq_printf(m, "Total Large %d Small %d Allocations\n",
44063 - atomic_read(&totBufAllocCount),
44064 - atomic_read(&totSmBufAllocCount));
44065 + atomic_read_unchecked(&totBufAllocCount),
44066 + atomic_read_unchecked(&totSmBufAllocCount));
44067 #endif /* CONFIG_CIFS_STATS2 */
44068
44069 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44070 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44071 if (tcon->need_reconnect)
44072 seq_puts(m, "\tDISCONNECTED ");
44073 seq_printf(m, "\nSMBs: %d",
44074 - atomic_read(&tcon->num_smbs_sent));
44075 + atomic_read_unchecked(&tcon->num_smbs_sent));
44076 if (server->ops->print_stats)
44077 server->ops->print_stats(m, tcon);
44078 }
44079 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44080 index e7931cc..76a1ab9 100644
44081 --- a/fs/cifs/cifsfs.c
44082 +++ b/fs/cifs/cifsfs.c
44083 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
44084 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44085 cifs_req_cachep = kmem_cache_create("cifs_request",
44086 CIFSMaxBufSize + max_hdr_size, 0,
44087 - SLAB_HWCACHE_ALIGN, NULL);
44088 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44089 if (cifs_req_cachep == NULL)
44090 return -ENOMEM;
44091
44092 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
44093 efficient to alloc 1 per page off the slab compared to 17K (5page)
44094 alloc of large cifs buffers even when page debugging is on */
44095 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44096 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44097 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44098 NULL);
44099 if (cifs_sm_req_cachep == NULL) {
44100 mempool_destroy(cifs_req_poolp);
44101 @@ -1111,8 +1111,8 @@ init_cifs(void)
44102 atomic_set(&bufAllocCount, 0);
44103 atomic_set(&smBufAllocCount, 0);
44104 #ifdef CONFIG_CIFS_STATS2
44105 - atomic_set(&totBufAllocCount, 0);
44106 - atomic_set(&totSmBufAllocCount, 0);
44107 + atomic_set_unchecked(&totBufAllocCount, 0);
44108 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44109 #endif /* CONFIG_CIFS_STATS2 */
44110
44111 atomic_set(&midCount, 0);
44112 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44113 index f5af252..489b5f2 100644
44114 --- a/fs/cifs/cifsglob.h
44115 +++ b/fs/cifs/cifsglob.h
44116 @@ -751,35 +751,35 @@ struct cifs_tcon {
44117 __u16 Flags; /* optional support bits */
44118 enum statusEnum tidStatus;
44119 #ifdef CONFIG_CIFS_STATS
44120 - atomic_t num_smbs_sent;
44121 + atomic_unchecked_t num_smbs_sent;
44122 union {
44123 struct {
44124 - atomic_t num_writes;
44125 - atomic_t num_reads;
44126 - atomic_t num_flushes;
44127 - atomic_t num_oplock_brks;
44128 - atomic_t num_opens;
44129 - atomic_t num_closes;
44130 - atomic_t num_deletes;
44131 - atomic_t num_mkdirs;
44132 - atomic_t num_posixopens;
44133 - atomic_t num_posixmkdirs;
44134 - atomic_t num_rmdirs;
44135 - atomic_t num_renames;
44136 - atomic_t num_t2renames;
44137 - atomic_t num_ffirst;
44138 - atomic_t num_fnext;
44139 - atomic_t num_fclose;
44140 - atomic_t num_hardlinks;
44141 - atomic_t num_symlinks;
44142 - atomic_t num_locks;
44143 - atomic_t num_acl_get;
44144 - atomic_t num_acl_set;
44145 + atomic_unchecked_t num_writes;
44146 + atomic_unchecked_t num_reads;
44147 + atomic_unchecked_t num_flushes;
44148 + atomic_unchecked_t num_oplock_brks;
44149 + atomic_unchecked_t num_opens;
44150 + atomic_unchecked_t num_closes;
44151 + atomic_unchecked_t num_deletes;
44152 + atomic_unchecked_t num_mkdirs;
44153 + atomic_unchecked_t num_posixopens;
44154 + atomic_unchecked_t num_posixmkdirs;
44155 + atomic_unchecked_t num_rmdirs;
44156 + atomic_unchecked_t num_renames;
44157 + atomic_unchecked_t num_t2renames;
44158 + atomic_unchecked_t num_ffirst;
44159 + atomic_unchecked_t num_fnext;
44160 + atomic_unchecked_t num_fclose;
44161 + atomic_unchecked_t num_hardlinks;
44162 + atomic_unchecked_t num_symlinks;
44163 + atomic_unchecked_t num_locks;
44164 + atomic_unchecked_t num_acl_get;
44165 + atomic_unchecked_t num_acl_set;
44166 } cifs_stats;
44167 #ifdef CONFIG_CIFS_SMB2
44168 struct {
44169 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44170 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44171 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44172 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44173 } smb2_stats;
44174 #endif /* CONFIG_CIFS_SMB2 */
44175 } stats;
44176 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44177 }
44178
44179 #ifdef CONFIG_CIFS_STATS
44180 -#define cifs_stats_inc atomic_inc
44181 +#define cifs_stats_inc atomic_inc_unchecked
44182
44183 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44184 unsigned int bytes)
44185 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44186 /* Various Debug counters */
44187 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44188 #ifdef CONFIG_CIFS_STATS2
44189 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44190 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44191 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44192 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44193 #endif
44194 GLOBAL_EXTERN atomic_t smBufAllocCount;
44195 GLOBAL_EXTERN atomic_t midCount;
44196 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44197 index 51dc2fb..1e12a33 100644
44198 --- a/fs/cifs/link.c
44199 +++ b/fs/cifs/link.c
44200 @@ -616,7 +616,7 @@ symlink_exit:
44201
44202 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44203 {
44204 - char *p = nd_get_link(nd);
44205 + const char *p = nd_get_link(nd);
44206 if (!IS_ERR(p))
44207 kfree(p);
44208 }
44209 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44210 index 3a00c0d..42d901c 100644
44211 --- a/fs/cifs/misc.c
44212 +++ b/fs/cifs/misc.c
44213 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44214 memset(ret_buf, 0, buf_size + 3);
44215 atomic_inc(&bufAllocCount);
44216 #ifdef CONFIG_CIFS_STATS2
44217 - atomic_inc(&totBufAllocCount);
44218 + atomic_inc_unchecked(&totBufAllocCount);
44219 #endif /* CONFIG_CIFS_STATS2 */
44220 }
44221
44222 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44223 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44224 atomic_inc(&smBufAllocCount);
44225 #ifdef CONFIG_CIFS_STATS2
44226 - atomic_inc(&totSmBufAllocCount);
44227 + atomic_inc_unchecked(&totSmBufAllocCount);
44228 #endif /* CONFIG_CIFS_STATS2 */
44229
44230 }
44231 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44232 index 34cea27..3fbdf6f 100644
44233 --- a/fs/cifs/smb1ops.c
44234 +++ b/fs/cifs/smb1ops.c
44235 @@ -610,27 +610,27 @@ static void
44236 cifs_clear_stats(struct cifs_tcon *tcon)
44237 {
44238 #ifdef CONFIG_CIFS_STATS
44239 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44240 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44241 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44242 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44243 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44244 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44245 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44246 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44247 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44248 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44249 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44250 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44251 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44252 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44253 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44254 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44255 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44256 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44257 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44258 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44259 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44260 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44261 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44262 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44263 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44264 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44265 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44266 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44267 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44268 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44269 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44270 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44271 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44272 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44273 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44274 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44275 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44276 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44277 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44278 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44279 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44280 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44281 #endif
44282 }
44283
44284 @@ -639,36 +639,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44285 {
44286 #ifdef CONFIG_CIFS_STATS
44287 seq_printf(m, " Oplocks breaks: %d",
44288 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44289 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44290 seq_printf(m, "\nReads: %d Bytes: %llu",
44291 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44292 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44293 (long long)(tcon->bytes_read));
44294 seq_printf(m, "\nWrites: %d Bytes: %llu",
44295 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44296 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44297 (long long)(tcon->bytes_written));
44298 seq_printf(m, "\nFlushes: %d",
44299 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44300 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44301 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44302 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44303 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44304 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44305 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44306 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44307 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44308 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44309 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44310 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44311 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44312 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44313 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44314 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44315 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44316 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44317 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44318 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44319 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44320 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44321 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44322 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44323 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44324 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44325 seq_printf(m, "\nRenames: %d T2 Renames %d",
44326 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44327 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44328 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44329 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44330 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44331 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44332 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44333 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44334 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44335 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44336 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44337 #endif
44338 }
44339
44340 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44341 index 4d9dbe0..0af4601 100644
44342 --- a/fs/cifs/smb2ops.c
44343 +++ b/fs/cifs/smb2ops.c
44344 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44345 #ifdef CONFIG_CIFS_STATS
44346 int i;
44347 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44348 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44349 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44350 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44351 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44352 }
44353 #endif
44354 }
44355 @@ -301,66 +301,66 @@ static void
44356 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44357 {
44358 #ifdef CONFIG_CIFS_STATS
44359 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44360 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44361 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44362 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44363 seq_printf(m, "\nNegotiates: %d sent %d failed",
44364 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44365 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44366 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44367 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44368 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44369 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44370 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44371 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44372 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44373 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44374 seq_printf(m, "\nLogoffs: %d sent %d failed",
44375 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44376 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44377 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44378 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44379 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44380 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44381 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44382 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44383 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44384 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44385 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44386 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44387 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44388 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44389 seq_printf(m, "\nCreates: %d sent %d failed",
44390 - atomic_read(&sent[SMB2_CREATE_HE]),
44391 - atomic_read(&failed[SMB2_CREATE_HE]));
44392 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44393 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44394 seq_printf(m, "\nCloses: %d sent %d failed",
44395 - atomic_read(&sent[SMB2_CLOSE_HE]),
44396 - atomic_read(&failed[SMB2_CLOSE_HE]));
44397 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44398 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44399 seq_printf(m, "\nFlushes: %d sent %d failed",
44400 - atomic_read(&sent[SMB2_FLUSH_HE]),
44401 - atomic_read(&failed[SMB2_FLUSH_HE]));
44402 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44403 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44404 seq_printf(m, "\nReads: %d sent %d failed",
44405 - atomic_read(&sent[SMB2_READ_HE]),
44406 - atomic_read(&failed[SMB2_READ_HE]));
44407 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44408 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44409 seq_printf(m, "\nWrites: %d sent %d failed",
44410 - atomic_read(&sent[SMB2_WRITE_HE]),
44411 - atomic_read(&failed[SMB2_WRITE_HE]));
44412 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44413 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44414 seq_printf(m, "\nLocks: %d sent %d failed",
44415 - atomic_read(&sent[SMB2_LOCK_HE]),
44416 - atomic_read(&failed[SMB2_LOCK_HE]));
44417 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44418 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44419 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44420 - atomic_read(&sent[SMB2_IOCTL_HE]),
44421 - atomic_read(&failed[SMB2_IOCTL_HE]));
44422 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44423 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44424 seq_printf(m, "\nCancels: %d sent %d failed",
44425 - atomic_read(&sent[SMB2_CANCEL_HE]),
44426 - atomic_read(&failed[SMB2_CANCEL_HE]));
44427 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44428 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44429 seq_printf(m, "\nEchos: %d sent %d failed",
44430 - atomic_read(&sent[SMB2_ECHO_HE]),
44431 - atomic_read(&failed[SMB2_ECHO_HE]));
44432 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44433 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44434 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44435 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44436 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44437 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44438 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44439 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44440 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44441 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44442 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44443 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44444 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44445 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44446 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44447 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44448 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44449 seq_printf(m, "\nSetInfos: %d sent %d failed",
44450 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44451 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44452 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44453 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44454 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44455 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44456 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44457 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44458 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44459 #endif
44460 }
44461
44462 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44463 index 958ae0e..505c9d0 100644
44464 --- a/fs/coda/cache.c
44465 +++ b/fs/coda/cache.c
44466 @@ -24,7 +24,7 @@
44467 #include "coda_linux.h"
44468 #include "coda_cache.h"
44469
44470 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44471 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44472
44473 /* replace or extend an acl cache hit */
44474 void coda_cache_enter(struct inode *inode, int mask)
44475 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44476 struct coda_inode_info *cii = ITOC(inode);
44477
44478 spin_lock(&cii->c_lock);
44479 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44480 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44481 if (cii->c_uid != current_fsuid()) {
44482 cii->c_uid = current_fsuid();
44483 cii->c_cached_perm = mask;
44484 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44485 {
44486 struct coda_inode_info *cii = ITOC(inode);
44487 spin_lock(&cii->c_lock);
44488 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44489 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44490 spin_unlock(&cii->c_lock);
44491 }
44492
44493 /* remove all acl caches */
44494 void coda_cache_clear_all(struct super_block *sb)
44495 {
44496 - atomic_inc(&permission_epoch);
44497 + atomic_inc_unchecked(&permission_epoch);
44498 }
44499
44500
44501 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44502 spin_lock(&cii->c_lock);
44503 hit = (mask & cii->c_cached_perm) == mask &&
44504 cii->c_uid == current_fsuid() &&
44505 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44506 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44507 spin_unlock(&cii->c_lock);
44508
44509 return hit;
44510 diff --git a/fs/compat.c b/fs/compat.c
44511 index 015e1e1..5ce8e54 100644
44512 --- a/fs/compat.c
44513 +++ b/fs/compat.c
44514 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44515
44516 set_fs(KERNEL_DS);
44517 /* The __user pointer cast is valid because of the set_fs() */
44518 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44519 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44520 set_fs(oldfs);
44521 /* truncating is ok because it's a user address */
44522 if (!ret)
44523 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44524 goto out;
44525
44526 ret = -EINVAL;
44527 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44528 + if (nr_segs > UIO_MAXIOV)
44529 goto out;
44530 if (nr_segs > fast_segs) {
44531 ret = -ENOMEM;
44532 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44533
44534 struct compat_readdir_callback {
44535 struct compat_old_linux_dirent __user *dirent;
44536 + struct file * file;
44537 int result;
44538 };
44539
44540 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44541 buf->result = -EOVERFLOW;
44542 return -EOVERFLOW;
44543 }
44544 +
44545 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44546 + return 0;
44547 +
44548 buf->result++;
44549 dirent = buf->dirent;
44550 if (!access_ok(VERIFY_WRITE, dirent,
44551 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44552
44553 buf.result = 0;
44554 buf.dirent = dirent;
44555 + buf.file = f.file;
44556
44557 error = vfs_readdir(f.file, compat_fillonedir, &buf);
44558 if (buf.result)
44559 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
44560 struct compat_getdents_callback {
44561 struct compat_linux_dirent __user *current_dir;
44562 struct compat_linux_dirent __user *previous;
44563 + struct file * file;
44564 int count;
44565 int error;
44566 };
44567 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44568 buf->error = -EOVERFLOW;
44569 return -EOVERFLOW;
44570 }
44571 +
44572 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44573 + return 0;
44574 +
44575 dirent = buf->previous;
44576 if (dirent) {
44577 if (__put_user(offset, &dirent->d_off))
44578 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44579 buf.previous = NULL;
44580 buf.count = count;
44581 buf.error = 0;
44582 + buf.file = f.file;
44583
44584 error = vfs_readdir(f.file, compat_filldir, &buf);
44585 if (error >= 0)
44586 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44587 struct compat_getdents_callback64 {
44588 struct linux_dirent64 __user *current_dir;
44589 struct linux_dirent64 __user *previous;
44590 + struct file * file;
44591 int count;
44592 int error;
44593 };
44594 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44595 buf->error = -EINVAL; /* only used if we fail.. */
44596 if (reclen > buf->count)
44597 return -EINVAL;
44598 +
44599 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44600 + return 0;
44601 +
44602 dirent = buf->previous;
44603
44604 if (dirent) {
44605 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44606 buf.previous = NULL;
44607 buf.count = count;
44608 buf.error = 0;
44609 + buf.file = f.file;
44610
44611 error = vfs_readdir(f.file, compat_filldir64, &buf);
44612 if (error >= 0)
44613 error = buf.error;
44614 lastdirent = buf.previous;
44615 if (lastdirent) {
44616 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
44617 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
44618 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44619 error = -EFAULT;
44620 else
44621 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44622 index a81147e..20bf2b5 100644
44623 --- a/fs/compat_binfmt_elf.c
44624 +++ b/fs/compat_binfmt_elf.c
44625 @@ -30,11 +30,13 @@
44626 #undef elf_phdr
44627 #undef elf_shdr
44628 #undef elf_note
44629 +#undef elf_dyn
44630 #undef elf_addr_t
44631 #define elfhdr elf32_hdr
44632 #define elf_phdr elf32_phdr
44633 #define elf_shdr elf32_shdr
44634 #define elf_note elf32_note
44635 +#define elf_dyn Elf32_Dyn
44636 #define elf_addr_t Elf32_Addr
44637
44638 /*
44639 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44640 index 4c6285f..b7a2411 100644
44641 --- a/fs/compat_ioctl.c
44642 +++ b/fs/compat_ioctl.c
44643 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44644 return -EFAULT;
44645 if (__get_user(udata, &ss32->iomem_base))
44646 return -EFAULT;
44647 - ss.iomem_base = compat_ptr(udata);
44648 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44649 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44650 __get_user(ss.port_high, &ss32->port_high))
44651 return -EFAULT;
44652 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44653 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44654 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44655 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44656 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44657 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44658 return -EFAULT;
44659
44660 return ioctl_preallocate(file, p);
44661 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44662 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44663 {
44664 unsigned int a, b;
44665 - a = *(unsigned int *)p;
44666 - b = *(unsigned int *)q;
44667 + a = *(const unsigned int *)p;
44668 + b = *(const unsigned int *)q;
44669 if (a > b)
44670 return 1;
44671 if (a < b)
44672 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44673 index 7414ae2..d98ad6d 100644
44674 --- a/fs/configfs/dir.c
44675 +++ b/fs/configfs/dir.c
44676 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44677 }
44678 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44679 struct configfs_dirent *next;
44680 - const char * name;
44681 + const unsigned char * name;
44682 + char d_name[sizeof(next->s_dentry->d_iname)];
44683 int len;
44684 struct inode *inode = NULL;
44685
44686 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44687 continue;
44688
44689 name = configfs_get_name(next);
44690 - len = strlen(name);
44691 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44692 + len = next->s_dentry->d_name.len;
44693 + memcpy(d_name, name, len);
44694 + name = d_name;
44695 + } else
44696 + len = strlen(name);
44697
44698 /*
44699 * We'll have a dentry and an inode for
44700 diff --git a/fs/coredump.c b/fs/coredump.c
44701 index ce47379..68c8e43 100644
44702 --- a/fs/coredump.c
44703 +++ b/fs/coredump.c
44704 @@ -52,7 +52,7 @@ struct core_name {
44705 char *corename;
44706 int used, size;
44707 };
44708 -static atomic_t call_count = ATOMIC_INIT(1);
44709 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44710
44711 /* The maximal length of core_pattern is also specified in sysctl.c */
44712
44713 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
44714 {
44715 char *old_corename = cn->corename;
44716
44717 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44718 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44719 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44720
44721 if (!cn->corename) {
44722 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
44723 int pid_in_pattern = 0;
44724 int err = 0;
44725
44726 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44727 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44728 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44729 cn->used = 0;
44730
44731 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
44732 pipe = file->f_path.dentry->d_inode->i_pipe;
44733
44734 pipe_lock(pipe);
44735 - pipe->readers++;
44736 - pipe->writers--;
44737 + atomic_inc(&pipe->readers);
44738 + atomic_dec(&pipe->writers);
44739
44740 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44741 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44742 wake_up_interruptible_sync(&pipe->wait);
44743 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44744 pipe_wait(pipe);
44745 }
44746
44747 - pipe->readers--;
44748 - pipe->writers++;
44749 + atomic_dec(&pipe->readers);
44750 + atomic_inc(&pipe->writers);
44751 pipe_unlock(pipe);
44752
44753 }
44754 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44755 int ispipe;
44756 struct files_struct *displaced;
44757 bool need_nonrelative = false;
44758 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44759 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44760 + long signr = siginfo->si_signo;
44761 struct coredump_params cprm = {
44762 .siginfo = siginfo,
44763 .regs = regs,
44764 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44765 .mm_flags = mm->flags,
44766 };
44767
44768 - audit_core_dumps(siginfo->si_signo);
44769 + audit_core_dumps(signr);
44770 +
44771 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44772 + gr_handle_brute_attach(cprm.mm_flags);
44773
44774 binfmt = mm->binfmt;
44775 if (!binfmt || !binfmt->core_dump)
44776 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44777 need_nonrelative = true;
44778 }
44779
44780 - retval = coredump_wait(siginfo->si_signo, &core_state);
44781 + retval = coredump_wait(signr, &core_state);
44782 if (retval < 0)
44783 goto fail_creds;
44784
44785 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44786 }
44787 cprm.limit = RLIM_INFINITY;
44788
44789 - dump_count = atomic_inc_return(&core_dump_count);
44790 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44791 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44792 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44793 task_tgid_vnr(current), current->comm);
44794 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44795 } else {
44796 struct inode *inode;
44797
44798 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44799 +
44800 if (cprm.limit < binfmt->min_coredump)
44801 goto fail_unlock;
44802
44803 @@ -640,7 +646,7 @@ close_fail:
44804 filp_close(cprm.file, NULL);
44805 fail_dropcount:
44806 if (ispipe)
44807 - atomic_dec(&core_dump_count);
44808 + atomic_dec_unchecked(&core_dump_count);
44809 fail_unlock:
44810 kfree(cn.corename);
44811 fail_corename:
44812 @@ -659,7 +665,7 @@ fail:
44813 */
44814 int dump_write(struct file *file, const void *addr, int nr)
44815 {
44816 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44817 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44818 }
44819 EXPORT_SYMBOL(dump_write);
44820
44821 diff --git a/fs/dcache.c b/fs/dcache.c
44822 index 3a463d0..9f345c8 100644
44823 --- a/fs/dcache.c
44824 +++ b/fs/dcache.c
44825 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44826 mempages -= reserve;
44827
44828 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44829 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44830 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44831
44832 dcache_init();
44833 inode_init();
44834 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44835 index b607d92..41fda09 100644
44836 --- a/fs/debugfs/inode.c
44837 +++ b/fs/debugfs/inode.c
44838 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44839 */
44840 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44841 {
44842 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44843 + return __create_file(name, S_IFDIR | S_IRWXU,
44844 +#else
44845 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44846 +#endif
44847 parent, NULL, NULL);
44848 }
44849 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44850 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44851 index cc7709e..7e7211f 100644
44852 --- a/fs/ecryptfs/inode.c
44853 +++ b/fs/ecryptfs/inode.c
44854 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44855 old_fs = get_fs();
44856 set_fs(get_ds());
44857 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44858 - (char __user *)lower_buf,
44859 + (char __force_user *)lower_buf,
44860 PATH_MAX);
44861 set_fs(old_fs);
44862 if (rc < 0)
44863 @@ -706,7 +706,7 @@ out:
44864 static void
44865 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44866 {
44867 - char *buf = nd_get_link(nd);
44868 + const char *buf = nd_get_link(nd);
44869 if (!IS_ERR(buf)) {
44870 /* Free the char* */
44871 kfree(buf);
44872 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44873 index 412e6ed..4292d22 100644
44874 --- a/fs/ecryptfs/miscdev.c
44875 +++ b/fs/ecryptfs/miscdev.c
44876 @@ -315,7 +315,7 @@ check_list:
44877 goto out_unlock_msg_ctx;
44878 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44879 if (msg_ctx->msg) {
44880 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44881 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44882 goto out_unlock_msg_ctx;
44883 i += packet_length_size;
44884 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44885 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44886 index b2a34a1..162fa69 100644
44887 --- a/fs/ecryptfs/read_write.c
44888 +++ b/fs/ecryptfs/read_write.c
44889 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44890 return -EIO;
44891 fs_save = get_fs();
44892 set_fs(get_ds());
44893 - rc = vfs_write(lower_file, data, size, &offset);
44894 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44895 set_fs(fs_save);
44896 mark_inode_dirty_sync(ecryptfs_inode);
44897 return rc;
44898 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44899 return -EIO;
44900 fs_save = get_fs();
44901 set_fs(get_ds());
44902 - rc = vfs_read(lower_file, data, size, &offset);
44903 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44904 set_fs(fs_save);
44905 return rc;
44906 }
44907 diff --git a/fs/exec.c b/fs/exec.c
44908 index 0039055..ffc560c 100644
44909 --- a/fs/exec.c
44910 +++ b/fs/exec.c
44911 @@ -55,6 +55,16 @@
44912 #include <linux/pipe_fs_i.h>
44913 #include <linux/oom.h>
44914 #include <linux/compat.h>
44915 +#include <linux/random.h>
44916 +#include <linux/seq_file.h>
44917 +#include <linux/coredump.h>
44918 +
44919 +#ifdef CONFIG_PAX_REFCOUNT
44920 +#include <linux/kallsyms.h>
44921 +#include <linux/kdebug.h>
44922 +#endif
44923 +
44924 +#include <trace/events/fs.h>
44925
44926 #include <asm/uaccess.h>
44927 #include <asm/mmu_context.h>
44928 @@ -66,6 +76,18 @@
44929
44930 #include <trace/events/sched.h>
44931
44932 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44933 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44934 +{
44935 + 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");
44936 +}
44937 +#endif
44938 +
44939 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44940 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44941 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44942 +#endif
44943 +
44944 int suid_dumpable = 0;
44945
44946 static LIST_HEAD(formats);
44947 @@ -180,18 +202,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44948 int write)
44949 {
44950 struct page *page;
44951 - int ret;
44952
44953 -#ifdef CONFIG_STACK_GROWSUP
44954 - if (write) {
44955 - ret = expand_downwards(bprm->vma, pos);
44956 - if (ret < 0)
44957 - return NULL;
44958 - }
44959 -#endif
44960 - ret = get_user_pages(current, bprm->mm, pos,
44961 - 1, write, 1, &page, NULL);
44962 - if (ret <= 0)
44963 + if (0 > expand_downwards(bprm->vma, pos))
44964 + return NULL;
44965 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44966 return NULL;
44967
44968 if (write) {
44969 @@ -207,6 +221,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44970 if (size <= ARG_MAX)
44971 return page;
44972
44973 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44974 + // only allow 512KB for argv+env on suid/sgid binaries
44975 + // to prevent easy ASLR exhaustion
44976 + if (((bprm->cred->euid != current_euid()) ||
44977 + (bprm->cred->egid != current_egid())) &&
44978 + (size > (512 * 1024))) {
44979 + put_page(page);
44980 + return NULL;
44981 + }
44982 +#endif
44983 +
44984 /*
44985 * Limit to 1/4-th the stack size for the argv+env strings.
44986 * This ensures that:
44987 @@ -266,6 +291,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44988 vma->vm_end = STACK_TOP_MAX;
44989 vma->vm_start = vma->vm_end - PAGE_SIZE;
44990 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44991 +
44992 +#ifdef CONFIG_PAX_SEGMEXEC
44993 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44994 +#endif
44995 +
44996 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44997 INIT_LIST_HEAD(&vma->anon_vma_chain);
44998
44999 @@ -276,6 +306,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45000 mm->stack_vm = mm->total_vm = 1;
45001 up_write(&mm->mmap_sem);
45002 bprm->p = vma->vm_end - sizeof(void *);
45003 +
45004 +#ifdef CONFIG_PAX_RANDUSTACK
45005 + if (randomize_va_space)
45006 + bprm->p ^= random32() & ~PAGE_MASK;
45007 +#endif
45008 +
45009 return 0;
45010 err:
45011 up_write(&mm->mmap_sem);
45012 @@ -384,19 +420,7 @@ err:
45013 return err;
45014 }
45015
45016 -struct user_arg_ptr {
45017 -#ifdef CONFIG_COMPAT
45018 - bool is_compat;
45019 -#endif
45020 - union {
45021 - const char __user *const __user *native;
45022 -#ifdef CONFIG_COMPAT
45023 - const compat_uptr_t __user *compat;
45024 -#endif
45025 - } ptr;
45026 -};
45027 -
45028 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45029 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45030 {
45031 const char __user *native;
45032
45033 @@ -405,14 +429,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45034 compat_uptr_t compat;
45035
45036 if (get_user(compat, argv.ptr.compat + nr))
45037 - return ERR_PTR(-EFAULT);
45038 + return (const char __force_user *)ERR_PTR(-EFAULT);
45039
45040 return compat_ptr(compat);
45041 }
45042 #endif
45043
45044 if (get_user(native, argv.ptr.native + nr))
45045 - return ERR_PTR(-EFAULT);
45046 + return (const char __force_user *)ERR_PTR(-EFAULT);
45047
45048 return native;
45049 }
45050 @@ -431,7 +455,7 @@ static int count(struct user_arg_ptr argv, int max)
45051 if (!p)
45052 break;
45053
45054 - if (IS_ERR(p))
45055 + if (IS_ERR((const char __force_kernel *)p))
45056 return -EFAULT;
45057
45058 if (i++ >= max)
45059 @@ -465,7 +489,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45060
45061 ret = -EFAULT;
45062 str = get_user_arg_ptr(argv, argc);
45063 - if (IS_ERR(str))
45064 + if (IS_ERR((const char __force_kernel *)str))
45065 goto out;
45066
45067 len = strnlen_user(str, MAX_ARG_STRLEN);
45068 @@ -547,7 +571,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45069 int r;
45070 mm_segment_t oldfs = get_fs();
45071 struct user_arg_ptr argv = {
45072 - .ptr.native = (const char __user *const __user *)__argv,
45073 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45074 };
45075
45076 set_fs(KERNEL_DS);
45077 @@ -582,7 +606,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45078 unsigned long new_end = old_end - shift;
45079 struct mmu_gather tlb;
45080
45081 - BUG_ON(new_start > new_end);
45082 + if (new_start >= new_end || new_start < mmap_min_addr)
45083 + return -ENOMEM;
45084
45085 /*
45086 * ensure there are no vmas between where we want to go
45087 @@ -591,6 +616,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45088 if (vma != find_vma(mm, new_start))
45089 return -EFAULT;
45090
45091 +#ifdef CONFIG_PAX_SEGMEXEC
45092 + BUG_ON(pax_find_mirror_vma(vma));
45093 +#endif
45094 +
45095 /*
45096 * cover the whole range: [new_start, old_end)
45097 */
45098 @@ -671,10 +700,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45099 stack_top = arch_align_stack(stack_top);
45100 stack_top = PAGE_ALIGN(stack_top);
45101
45102 - if (unlikely(stack_top < mmap_min_addr) ||
45103 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45104 - return -ENOMEM;
45105 -
45106 stack_shift = vma->vm_end - stack_top;
45107
45108 bprm->p -= stack_shift;
45109 @@ -686,8 +711,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45110 bprm->exec -= stack_shift;
45111
45112 down_write(&mm->mmap_sem);
45113 +
45114 + /* Move stack pages down in memory. */
45115 + if (stack_shift) {
45116 + ret = shift_arg_pages(vma, stack_shift);
45117 + if (ret)
45118 + goto out_unlock;
45119 + }
45120 +
45121 vm_flags = VM_STACK_FLAGS;
45122
45123 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45124 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45125 + vm_flags &= ~VM_EXEC;
45126 +
45127 +#ifdef CONFIG_PAX_MPROTECT
45128 + if (mm->pax_flags & MF_PAX_MPROTECT)
45129 + vm_flags &= ~VM_MAYEXEC;
45130 +#endif
45131 +
45132 + }
45133 +#endif
45134 +
45135 /*
45136 * Adjust stack execute permissions; explicitly enable for
45137 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45138 @@ -706,13 +751,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45139 goto out_unlock;
45140 BUG_ON(prev != vma);
45141
45142 - /* Move stack pages down in memory. */
45143 - if (stack_shift) {
45144 - ret = shift_arg_pages(vma, stack_shift);
45145 - if (ret)
45146 - goto out_unlock;
45147 - }
45148 -
45149 /* mprotect_fixup is overkill to remove the temporary stack flags */
45150 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45151
45152 @@ -771,6 +809,8 @@ struct file *open_exec(const char *name)
45153
45154 fsnotify_open(file);
45155
45156 + trace_open_exec(name);
45157 +
45158 err = deny_write_access(file);
45159 if (err)
45160 goto exit;
45161 @@ -794,7 +834,7 @@ int kernel_read(struct file *file, loff_t offset,
45162 old_fs = get_fs();
45163 set_fs(get_ds());
45164 /* The cast to a user pointer is valid due to the set_fs() */
45165 - result = vfs_read(file, (void __user *)addr, count, &pos);
45166 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45167 set_fs(old_fs);
45168 return result;
45169 }
45170 @@ -1231,7 +1271,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45171 }
45172 rcu_read_unlock();
45173
45174 - if (p->fs->users > n_fs) {
45175 + if (atomic_read(&p->fs->users) > n_fs) {
45176 bprm->unsafe |= LSM_UNSAFE_SHARE;
45177 } else {
45178 res = -EAGAIN;
45179 @@ -1434,6 +1474,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45180
45181 EXPORT_SYMBOL(search_binary_handler);
45182
45183 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45184 +static DEFINE_PER_CPU(u64, exec_counter);
45185 +static int __init init_exec_counters(void)
45186 +{
45187 + unsigned int cpu;
45188 +
45189 + for_each_possible_cpu(cpu) {
45190 + per_cpu(exec_counter, cpu) = (u64)cpu;
45191 + }
45192 +
45193 + return 0;
45194 +}
45195 +early_initcall(init_exec_counters);
45196 +static inline void increment_exec_counter(void)
45197 +{
45198 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45199 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45200 +}
45201 +#else
45202 +static inline void increment_exec_counter(void) {}
45203 +#endif
45204 +
45205 /*
45206 * sys_execve() executes a new program.
45207 */
45208 @@ -1442,6 +1504,11 @@ static int do_execve_common(const char *filename,
45209 struct user_arg_ptr envp,
45210 struct pt_regs *regs)
45211 {
45212 +#ifdef CONFIG_GRKERNSEC
45213 + struct file *old_exec_file;
45214 + struct acl_subject_label *old_acl;
45215 + struct rlimit old_rlim[RLIM_NLIMITS];
45216 +#endif
45217 struct linux_binprm *bprm;
45218 struct file *file;
45219 struct files_struct *displaced;
45220 @@ -1449,6 +1516,8 @@ static int do_execve_common(const char *filename,
45221 int retval;
45222 const struct cred *cred = current_cred();
45223
45224 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45225 +
45226 /*
45227 * We move the actual failure in case of RLIMIT_NPROC excess from
45228 * set*uid() to execve() because too many poorly written programs
45229 @@ -1489,12 +1558,27 @@ static int do_execve_common(const char *filename,
45230 if (IS_ERR(file))
45231 goto out_unmark;
45232
45233 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45234 + retval = -EPERM;
45235 + goto out_file;
45236 + }
45237 +
45238 sched_exec();
45239
45240 bprm->file = file;
45241 bprm->filename = filename;
45242 bprm->interp = filename;
45243
45244 + if (gr_process_user_ban()) {
45245 + retval = -EPERM;
45246 + goto out_file;
45247 + }
45248 +
45249 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45250 + retval = -EACCES;
45251 + goto out_file;
45252 + }
45253 +
45254 retval = bprm_mm_init(bprm);
45255 if (retval)
45256 goto out_file;
45257 @@ -1511,24 +1595,65 @@ static int do_execve_common(const char *filename,
45258 if (retval < 0)
45259 goto out;
45260
45261 +#ifdef CONFIG_GRKERNSEC
45262 + old_acl = current->acl;
45263 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45264 + old_exec_file = current->exec_file;
45265 + get_file(file);
45266 + current->exec_file = file;
45267 +#endif
45268 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45269 + /* limit suid stack to 8MB
45270 + we saved the old limits above and will restore them if this exec fails
45271 + */
45272 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45273 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45274 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45275 +#endif
45276 +
45277 + if (!gr_tpe_allow(file)) {
45278 + retval = -EACCES;
45279 + goto out_fail;
45280 + }
45281 +
45282 + if (gr_check_crash_exec(file)) {
45283 + retval = -EACCES;
45284 + goto out_fail;
45285 + }
45286 +
45287 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45288 + bprm->unsafe);
45289 + if (retval < 0)
45290 + goto out_fail;
45291 +
45292 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45293 if (retval < 0)
45294 - goto out;
45295 + goto out_fail;
45296
45297 bprm->exec = bprm->p;
45298 retval = copy_strings(bprm->envc, envp, bprm);
45299 if (retval < 0)
45300 - goto out;
45301 + goto out_fail;
45302
45303 retval = copy_strings(bprm->argc, argv, bprm);
45304 if (retval < 0)
45305 - goto out;
45306 + goto out_fail;
45307 +
45308 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45309 +
45310 + gr_handle_exec_args(bprm, argv);
45311
45312 retval = search_binary_handler(bprm,regs);
45313 if (retval < 0)
45314 - goto out;
45315 + goto out_fail;
45316 +#ifdef CONFIG_GRKERNSEC
45317 + if (old_exec_file)
45318 + fput(old_exec_file);
45319 +#endif
45320
45321 /* execve succeeded */
45322 +
45323 + increment_exec_counter();
45324 current->fs->in_exec = 0;
45325 current->in_execve = 0;
45326 acct_update_integrals(current);
45327 @@ -1537,6 +1662,14 @@ static int do_execve_common(const char *filename,
45328 put_files_struct(displaced);
45329 return retval;
45330
45331 +out_fail:
45332 +#ifdef CONFIG_GRKERNSEC
45333 + current->acl = old_acl;
45334 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45335 + fput(current->exec_file);
45336 + current->exec_file = old_exec_file;
45337 +#endif
45338 +
45339 out:
45340 if (bprm->mm) {
45341 acct_arg_size(bprm, 0);
45342 @@ -1712,3 +1845,253 @@ int kernel_execve(const char *filename,
45343 ret_from_kernel_execve(p);
45344 }
45345 #endif
45346 +
45347 +int pax_check_flags(unsigned long *flags)
45348 +{
45349 + int retval = 0;
45350 +
45351 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45352 + if (*flags & MF_PAX_SEGMEXEC)
45353 + {
45354 + *flags &= ~MF_PAX_SEGMEXEC;
45355 + retval = -EINVAL;
45356 + }
45357 +#endif
45358 +
45359 + if ((*flags & MF_PAX_PAGEEXEC)
45360 +
45361 +#ifdef CONFIG_PAX_PAGEEXEC
45362 + && (*flags & MF_PAX_SEGMEXEC)
45363 +#endif
45364 +
45365 + )
45366 + {
45367 + *flags &= ~MF_PAX_PAGEEXEC;
45368 + retval = -EINVAL;
45369 + }
45370 +
45371 + if ((*flags & MF_PAX_MPROTECT)
45372 +
45373 +#ifdef CONFIG_PAX_MPROTECT
45374 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45375 +#endif
45376 +
45377 + )
45378 + {
45379 + *flags &= ~MF_PAX_MPROTECT;
45380 + retval = -EINVAL;
45381 + }
45382 +
45383 + if ((*flags & MF_PAX_EMUTRAMP)
45384 +
45385 +#ifdef CONFIG_PAX_EMUTRAMP
45386 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45387 +#endif
45388 +
45389 + )
45390 + {
45391 + *flags &= ~MF_PAX_EMUTRAMP;
45392 + retval = -EINVAL;
45393 + }
45394 +
45395 + return retval;
45396 +}
45397 +
45398 +EXPORT_SYMBOL(pax_check_flags);
45399 +
45400 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45401 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45402 +{
45403 + struct task_struct *tsk = current;
45404 + struct mm_struct *mm = current->mm;
45405 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45406 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45407 + char *path_exec = NULL;
45408 + char *path_fault = NULL;
45409 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45410 + siginfo_t info = { };
45411 +
45412 + if (buffer_exec && buffer_fault) {
45413 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45414 +
45415 + down_read(&mm->mmap_sem);
45416 + vma = mm->mmap;
45417 + while (vma && (!vma_exec || !vma_fault)) {
45418 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
45419 + vma_exec = vma;
45420 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45421 + vma_fault = vma;
45422 + vma = vma->vm_next;
45423 + }
45424 + if (vma_exec) {
45425 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45426 + if (IS_ERR(path_exec))
45427 + path_exec = "<path too long>";
45428 + else {
45429 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45430 + if (path_exec) {
45431 + *path_exec = 0;
45432 + path_exec = buffer_exec;
45433 + } else
45434 + path_exec = "<path too long>";
45435 + }
45436 + }
45437 + if (vma_fault) {
45438 + start = vma_fault->vm_start;
45439 + end = vma_fault->vm_end;
45440 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45441 + if (vma_fault->vm_file) {
45442 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45443 + if (IS_ERR(path_fault))
45444 + path_fault = "<path too long>";
45445 + else {
45446 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45447 + if (path_fault) {
45448 + *path_fault = 0;
45449 + path_fault = buffer_fault;
45450 + } else
45451 + path_fault = "<path too long>";
45452 + }
45453 + } else
45454 + path_fault = "<anonymous mapping>";
45455 + }
45456 + up_read(&mm->mmap_sem);
45457 + }
45458 + if (tsk->signal->curr_ip)
45459 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45460 + else
45461 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45462 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45463 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45464 + task_uid(tsk), task_euid(tsk), pc, sp);
45465 + free_page((unsigned long)buffer_exec);
45466 + free_page((unsigned long)buffer_fault);
45467 + pax_report_insns(regs, pc, sp);
45468 + info.si_signo = SIGKILL;
45469 + info.si_errno = 0;
45470 + info.si_code = SI_KERNEL;
45471 + info.si_pid = 0;
45472 + info.si_uid = 0;
45473 + do_coredump(&info, regs);
45474 +}
45475 +#endif
45476 +
45477 +#ifdef CONFIG_PAX_REFCOUNT
45478 +void pax_report_refcount_overflow(struct pt_regs *regs)
45479 +{
45480 + if (current->signal->curr_ip)
45481 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45482 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45483 + else
45484 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45485 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45486 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45487 + show_regs(regs);
45488 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45489 +}
45490 +#endif
45491 +
45492 +#ifdef CONFIG_PAX_USERCOPY
45493 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45494 +static noinline int check_stack_object(const void *obj, unsigned long len)
45495 +{
45496 + const void * const stack = task_stack_page(current);
45497 + const void * const stackend = stack + THREAD_SIZE;
45498 +
45499 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45500 + const void *frame = NULL;
45501 + const void *oldframe;
45502 +#endif
45503 +
45504 + if (obj + len < obj)
45505 + return -1;
45506 +
45507 + if (obj + len <= stack || stackend <= obj)
45508 + return 0;
45509 +
45510 + if (obj < stack || stackend < obj + len)
45511 + return -1;
45512 +
45513 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45514 + oldframe = __builtin_frame_address(1);
45515 + if (oldframe)
45516 + frame = __builtin_frame_address(2);
45517 + /*
45518 + low ----------------------------------------------> high
45519 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45520 + ^----------------^
45521 + allow copies only within here
45522 + */
45523 + while (stack <= frame && frame < stackend) {
45524 + /* if obj + len extends past the last frame, this
45525 + check won't pass and the next frame will be 0,
45526 + causing us to bail out and correctly report
45527 + the copy as invalid
45528 + */
45529 + if (obj + len <= frame)
45530 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45531 + oldframe = frame;
45532 + frame = *(const void * const *)frame;
45533 + }
45534 + return -1;
45535 +#else
45536 + return 1;
45537 +#endif
45538 +}
45539 +
45540 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45541 +{
45542 + if (current->signal->curr_ip)
45543 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45544 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45545 + else
45546 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45547 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45548 + dump_stack();
45549 + gr_handle_kernel_exploit();
45550 + do_group_exit(SIGKILL);
45551 +}
45552 +#endif
45553 +
45554 +void check_object_size(const void *ptr, unsigned long n, bool to)
45555 +{
45556 +
45557 +#ifdef CONFIG_PAX_USERCOPY
45558 + const char *type;
45559 +
45560 + if (!n)
45561 + return;
45562 +
45563 + type = check_heap_object(ptr, n, to);
45564 + if (!type) {
45565 + if (check_stack_object(ptr, n) != -1)
45566 + return;
45567 + type = "<process stack>";
45568 + }
45569 +
45570 + pax_report_usercopy(ptr, n, to, type);
45571 +#endif
45572 +
45573 +}
45574 +EXPORT_SYMBOL(check_object_size);
45575 +
45576 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45577 +void pax_track_stack(void)
45578 +{
45579 + unsigned long sp = (unsigned long)&sp;
45580 + if (sp < current_thread_info()->lowest_stack &&
45581 + sp > (unsigned long)task_stack_page(current))
45582 + current_thread_info()->lowest_stack = sp;
45583 +}
45584 +EXPORT_SYMBOL(pax_track_stack);
45585 +#endif
45586 +
45587 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45588 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45589 +{
45590 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45591 + dump_stack();
45592 + do_group_exit(SIGKILL);
45593 +}
45594 +EXPORT_SYMBOL(report_size_overflow);
45595 +#endif
45596 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45597 index 2616d0e..2ffdec9 100644
45598 --- a/fs/ext2/balloc.c
45599 +++ b/fs/ext2/balloc.c
45600 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45601
45602 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45603 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45604 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45605 + if (free_blocks < root_blocks + 1 &&
45606 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45607 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45608 - !in_group_p (sbi->s_resgid))) {
45609 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45610 return 0;
45611 }
45612 return 1;
45613 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45614 index 22548f5..41521d8 100644
45615 --- a/fs/ext3/balloc.c
45616 +++ b/fs/ext3/balloc.c
45617 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45618
45619 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45620 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45621 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45622 + if (free_blocks < root_blocks + 1 &&
45623 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45624 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45625 - !in_group_p (sbi->s_resgid))) {
45626 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45627 return 0;
45628 }
45629 return 1;
45630 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45631 index cf18217..8f6b9c3 100644
45632 --- a/fs/ext4/balloc.c
45633 +++ b/fs/ext4/balloc.c
45634 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45635 /* Hm, nope. Are (enough) root reserved clusters available? */
45636 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45637 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45638 - capable(CAP_SYS_RESOURCE) ||
45639 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45640 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45641 + capable_nolog(CAP_SYS_RESOURCE)) {
45642
45643 if (free_clusters >= (nclusters + dirty_clusters))
45644 return 1;
45645 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45646 index 3c20de1..6ff2460 100644
45647 --- a/fs/ext4/ext4.h
45648 +++ b/fs/ext4/ext4.h
45649 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45650 unsigned long s_mb_last_start;
45651
45652 /* stats for buddy allocator */
45653 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45654 - atomic_t s_bal_success; /* we found long enough chunks */
45655 - atomic_t s_bal_allocated; /* in blocks */
45656 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45657 - atomic_t s_bal_goals; /* goal hits */
45658 - atomic_t s_bal_breaks; /* too long searches */
45659 - atomic_t s_bal_2orders; /* 2^order hits */
45660 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45661 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45662 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45663 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45664 + atomic_unchecked_t s_bal_goals; /* goal hits */
45665 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45666 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45667 spinlock_t s_bal_lock;
45668 unsigned long s_mb_buddies_generated;
45669 unsigned long long s_mb_generation_time;
45670 - atomic_t s_mb_lost_chunks;
45671 - atomic_t s_mb_preallocated;
45672 - atomic_t s_mb_discarded;
45673 + atomic_unchecked_t s_mb_lost_chunks;
45674 + atomic_unchecked_t s_mb_preallocated;
45675 + atomic_unchecked_t s_mb_discarded;
45676 atomic_t s_lock_busy;
45677
45678 /* locality groups */
45679 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45680 index 526e553..3f2de85 100644
45681 --- a/fs/ext4/mballoc.c
45682 +++ b/fs/ext4/mballoc.c
45683 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45684 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45685
45686 if (EXT4_SB(sb)->s_mb_stats)
45687 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45688 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45689
45690 break;
45691 }
45692 @@ -2044,7 +2044,7 @@ repeat:
45693 ac->ac_status = AC_STATUS_CONTINUE;
45694 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45695 cr = 3;
45696 - atomic_inc(&sbi->s_mb_lost_chunks);
45697 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45698 goto repeat;
45699 }
45700 }
45701 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
45702 if (sbi->s_mb_stats) {
45703 ext4_msg(sb, KERN_INFO,
45704 "mballoc: %u blocks %u reqs (%u success)",
45705 - atomic_read(&sbi->s_bal_allocated),
45706 - atomic_read(&sbi->s_bal_reqs),
45707 - atomic_read(&sbi->s_bal_success));
45708 + atomic_read_unchecked(&sbi->s_bal_allocated),
45709 + atomic_read_unchecked(&sbi->s_bal_reqs),
45710 + atomic_read_unchecked(&sbi->s_bal_success));
45711 ext4_msg(sb, KERN_INFO,
45712 "mballoc: %u extents scanned, %u goal hits, "
45713 "%u 2^N hits, %u breaks, %u lost",
45714 - atomic_read(&sbi->s_bal_ex_scanned),
45715 - atomic_read(&sbi->s_bal_goals),
45716 - atomic_read(&sbi->s_bal_2orders),
45717 - atomic_read(&sbi->s_bal_breaks),
45718 - atomic_read(&sbi->s_mb_lost_chunks));
45719 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45720 + atomic_read_unchecked(&sbi->s_bal_goals),
45721 + atomic_read_unchecked(&sbi->s_bal_2orders),
45722 + atomic_read_unchecked(&sbi->s_bal_breaks),
45723 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45724 ext4_msg(sb, KERN_INFO,
45725 "mballoc: %lu generated and it took %Lu",
45726 sbi->s_mb_buddies_generated,
45727 sbi->s_mb_generation_time);
45728 ext4_msg(sb, KERN_INFO,
45729 "mballoc: %u preallocated, %u discarded",
45730 - atomic_read(&sbi->s_mb_preallocated),
45731 - atomic_read(&sbi->s_mb_discarded));
45732 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45733 + atomic_read_unchecked(&sbi->s_mb_discarded));
45734 }
45735
45736 free_percpu(sbi->s_locality_groups);
45737 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45738 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45739
45740 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45741 - atomic_inc(&sbi->s_bal_reqs);
45742 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45743 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45744 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45745 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45746 - atomic_inc(&sbi->s_bal_success);
45747 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45748 + atomic_inc_unchecked(&sbi->s_bal_success);
45749 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45750 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45751 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45752 - atomic_inc(&sbi->s_bal_goals);
45753 + atomic_inc_unchecked(&sbi->s_bal_goals);
45754 if (ac->ac_found > sbi->s_mb_max_to_scan)
45755 - atomic_inc(&sbi->s_bal_breaks);
45756 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45757 }
45758
45759 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45760 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45761 trace_ext4_mb_new_inode_pa(ac, pa);
45762
45763 ext4_mb_use_inode_pa(ac, pa);
45764 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45765 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45766
45767 ei = EXT4_I(ac->ac_inode);
45768 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45769 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45770 trace_ext4_mb_new_group_pa(ac, pa);
45771
45772 ext4_mb_use_group_pa(ac, pa);
45773 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45774 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45775
45776 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45777 lg = ac->ac_lg;
45778 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45779 * from the bitmap and continue.
45780 */
45781 }
45782 - atomic_add(free, &sbi->s_mb_discarded);
45783 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45784
45785 return err;
45786 }
45787 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45788 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45789 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45790 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45791 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45792 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45793 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45794
45795 return 0;
45796 diff --git a/fs/fcntl.c b/fs/fcntl.c
45797 index 71a600a..20d87b1 100644
45798 --- a/fs/fcntl.c
45799 +++ b/fs/fcntl.c
45800 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45801 if (err)
45802 return err;
45803
45804 + if (gr_handle_chroot_fowner(pid, type))
45805 + return -ENOENT;
45806 + if (gr_check_protected_task_fowner(pid, type))
45807 + return -EACCES;
45808 +
45809 f_modown(filp, pid, type, force);
45810 return 0;
45811 }
45812 diff --git a/fs/fifo.c b/fs/fifo.c
45813 index cf6f434..3d7942c 100644
45814 --- a/fs/fifo.c
45815 +++ b/fs/fifo.c
45816 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45817 */
45818 filp->f_op = &read_pipefifo_fops;
45819 pipe->r_counter++;
45820 - if (pipe->readers++ == 0)
45821 + if (atomic_inc_return(&pipe->readers) == 1)
45822 wake_up_partner(inode);
45823
45824 - if (!pipe->writers) {
45825 + if (!atomic_read(&pipe->writers)) {
45826 if ((filp->f_flags & O_NONBLOCK)) {
45827 /* suppress POLLHUP until we have
45828 * seen a writer */
45829 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45830 * errno=ENXIO when there is no process reading the FIFO.
45831 */
45832 ret = -ENXIO;
45833 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45834 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45835 goto err;
45836
45837 filp->f_op = &write_pipefifo_fops;
45838 pipe->w_counter++;
45839 - if (!pipe->writers++)
45840 + if (atomic_inc_return(&pipe->writers) == 1)
45841 wake_up_partner(inode);
45842
45843 - if (!pipe->readers) {
45844 + if (!atomic_read(&pipe->readers)) {
45845 if (wait_for_partner(inode, &pipe->r_counter))
45846 goto err_wr;
45847 }
45848 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45849 */
45850 filp->f_op = &rdwr_pipefifo_fops;
45851
45852 - pipe->readers++;
45853 - pipe->writers++;
45854 + atomic_inc(&pipe->readers);
45855 + atomic_inc(&pipe->writers);
45856 pipe->r_counter++;
45857 pipe->w_counter++;
45858 - if (pipe->readers == 1 || pipe->writers == 1)
45859 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45860 wake_up_partner(inode);
45861 break;
45862
45863 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45864 return 0;
45865
45866 err_rd:
45867 - if (!--pipe->readers)
45868 + if (atomic_dec_and_test(&pipe->readers))
45869 wake_up_interruptible(&pipe->wait);
45870 ret = -ERESTARTSYS;
45871 goto err;
45872
45873 err_wr:
45874 - if (!--pipe->writers)
45875 + if (atomic_dec_and_test(&pipe->writers))
45876 wake_up_interruptible(&pipe->wait);
45877 ret = -ERESTARTSYS;
45878 goto err;
45879
45880 err:
45881 - if (!pipe->readers && !pipe->writers)
45882 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45883 free_pipe_info(inode);
45884
45885 err_nocleanup:
45886 diff --git a/fs/file.c b/fs/file.c
45887 index eff2316..8c8930c 100644
45888 --- a/fs/file.c
45889 +++ b/fs/file.c
45890 @@ -16,6 +16,7 @@
45891 #include <linux/slab.h>
45892 #include <linux/vmalloc.h>
45893 #include <linux/file.h>
45894 +#include <linux/security.h>
45895 #include <linux/fdtable.h>
45896 #include <linux/bitops.h>
45897 #include <linux/interrupt.h>
45898 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
45899 if (!file)
45900 return __close_fd(files, fd);
45901
45902 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
45903 if (fd >= rlimit(RLIMIT_NOFILE))
45904 return -EBADF;
45905
45906 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
45907 if (unlikely(oldfd == newfd))
45908 return -EINVAL;
45909
45910 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
45911 if (newfd >= rlimit(RLIMIT_NOFILE))
45912 return -EBADF;
45913
45914 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
45915 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
45916 {
45917 int err;
45918 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
45919 if (from >= rlimit(RLIMIT_NOFILE))
45920 return -EINVAL;
45921 err = alloc_fd(from, flags);
45922 diff --git a/fs/filesystems.c b/fs/filesystems.c
45923 index da165f6..3671bdb 100644
45924 --- a/fs/filesystems.c
45925 +++ b/fs/filesystems.c
45926 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45927 int len = dot ? dot - name : strlen(name);
45928
45929 fs = __get_fs_type(name, len);
45930 +
45931 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45932 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45933 +#else
45934 if (!fs && (request_module("%.*s", len, name) == 0))
45935 +#endif
45936 fs = __get_fs_type(name, len);
45937
45938 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45939 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45940 index 5df4775..f656176 100644
45941 --- a/fs/fs_struct.c
45942 +++ b/fs/fs_struct.c
45943 @@ -4,6 +4,7 @@
45944 #include <linux/path.h>
45945 #include <linux/slab.h>
45946 #include <linux/fs_struct.h>
45947 +#include <linux/grsecurity.h>
45948 #include "internal.h"
45949
45950 /*
45951 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45952 write_seqcount_begin(&fs->seq);
45953 old_root = fs->root;
45954 fs->root = *path;
45955 + gr_set_chroot_entries(current, path);
45956 write_seqcount_end(&fs->seq);
45957 spin_unlock(&fs->lock);
45958 if (old_root.dentry)
45959 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45960 return 1;
45961 }
45962
45963 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45964 +{
45965 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45966 + return 0;
45967 + *p = *new;
45968 +
45969 + /* This function is only called from pivot_root(). Leave our
45970 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45971 + pivoted root isn't treated as a chroot
45972 + */
45973 + //gr_set_chroot_entries(task, new);
45974 +
45975 + return 1;
45976 +}
45977 +
45978 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45979 {
45980 struct task_struct *g, *p;
45981 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45982 int hits = 0;
45983 spin_lock(&fs->lock);
45984 write_seqcount_begin(&fs->seq);
45985 - hits += replace_path(&fs->root, old_root, new_root);
45986 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45987 hits += replace_path(&fs->pwd, old_root, new_root);
45988 write_seqcount_end(&fs->seq);
45989 while (hits--) {
45990 @@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
45991 {
45992 struct fs_struct *fs = tsk->fs;
45993
45994 + gr_put_exec_file(tsk);
45995 +
45996 if (fs) {
45997 int kill;
45998 task_lock(tsk);
45999 spin_lock(&fs->lock);
46000 tsk->fs = NULL;
46001 - kill = !--fs->users;
46002 + gr_clear_chroot_entries(tsk);
46003 + kill = !atomic_dec_return(&fs->users);
46004 spin_unlock(&fs->lock);
46005 task_unlock(tsk);
46006 if (kill)
46007 @@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46008 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46009 /* We don't need to lock fs - think why ;-) */
46010 if (fs) {
46011 - fs->users = 1;
46012 + atomic_set(&fs->users, 1);
46013 fs->in_exec = 0;
46014 spin_lock_init(&fs->lock);
46015 seqcount_init(&fs->seq);
46016 @@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46017 spin_lock(&old->lock);
46018 fs->root = old->root;
46019 path_get(&fs->root);
46020 + /* instead of calling gr_set_chroot_entries here,
46021 + we call it from every caller of this function
46022 + */
46023 fs->pwd = old->pwd;
46024 path_get(&fs->pwd);
46025 spin_unlock(&old->lock);
46026 @@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46027
46028 task_lock(current);
46029 spin_lock(&fs->lock);
46030 - kill = !--fs->users;
46031 + kill = !atomic_dec_return(&fs->users);
46032 current->fs = new_fs;
46033 + gr_set_chroot_entries(current, &new_fs->root);
46034 spin_unlock(&fs->lock);
46035 task_unlock(current);
46036
46037 @@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46038
46039 int current_umask(void)
46040 {
46041 - return current->fs->umask;
46042 + return current->fs->umask | gr_acl_umask();
46043 }
46044 EXPORT_SYMBOL(current_umask);
46045
46046 /* to be mentioned only in INIT_TASK */
46047 struct fs_struct init_fs = {
46048 - .users = 1,
46049 + .users = ATOMIC_INIT(1),
46050 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46051 .seq = SEQCNT_ZERO,
46052 .umask = 0022,
46053 @@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46054 {
46055 struct fs_struct *fs = current->fs;
46056
46057 + gr_put_exec_file(current);
46058 +
46059 if (fs) {
46060 int kill;
46061
46062 task_lock(current);
46063
46064 spin_lock(&init_fs.lock);
46065 - init_fs.users++;
46066 + atomic_inc(&init_fs.users);
46067 spin_unlock(&init_fs.lock);
46068
46069 spin_lock(&fs->lock);
46070 current->fs = &init_fs;
46071 - kill = !--fs->users;
46072 + gr_set_chroot_entries(current, &current->fs->root);
46073 + kill = !atomic_dec_return(&fs->users);
46074 spin_unlock(&fs->lock);
46075
46076 task_unlock(current);
46077 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46078 index 9905350..02eaec4 100644
46079 --- a/fs/fscache/cookie.c
46080 +++ b/fs/fscache/cookie.c
46081 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46082 parent ? (char *) parent->def->name : "<no-parent>",
46083 def->name, netfs_data);
46084
46085 - fscache_stat(&fscache_n_acquires);
46086 + fscache_stat_unchecked(&fscache_n_acquires);
46087
46088 /* if there's no parent cookie, then we don't create one here either */
46089 if (!parent) {
46090 - fscache_stat(&fscache_n_acquires_null);
46091 + fscache_stat_unchecked(&fscache_n_acquires_null);
46092 _leave(" [no parent]");
46093 return NULL;
46094 }
46095 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46096 /* allocate and initialise a cookie */
46097 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46098 if (!cookie) {
46099 - fscache_stat(&fscache_n_acquires_oom);
46100 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46101 _leave(" [ENOMEM]");
46102 return NULL;
46103 }
46104 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46105
46106 switch (cookie->def->type) {
46107 case FSCACHE_COOKIE_TYPE_INDEX:
46108 - fscache_stat(&fscache_n_cookie_index);
46109 + fscache_stat_unchecked(&fscache_n_cookie_index);
46110 break;
46111 case FSCACHE_COOKIE_TYPE_DATAFILE:
46112 - fscache_stat(&fscache_n_cookie_data);
46113 + fscache_stat_unchecked(&fscache_n_cookie_data);
46114 break;
46115 default:
46116 - fscache_stat(&fscache_n_cookie_special);
46117 + fscache_stat_unchecked(&fscache_n_cookie_special);
46118 break;
46119 }
46120
46121 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46122 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46123 atomic_dec(&parent->n_children);
46124 __fscache_cookie_put(cookie);
46125 - fscache_stat(&fscache_n_acquires_nobufs);
46126 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46127 _leave(" = NULL");
46128 return NULL;
46129 }
46130 }
46131
46132 - fscache_stat(&fscache_n_acquires_ok);
46133 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46134 _leave(" = %p", cookie);
46135 return cookie;
46136 }
46137 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46138 cache = fscache_select_cache_for_object(cookie->parent);
46139 if (!cache) {
46140 up_read(&fscache_addremove_sem);
46141 - fscache_stat(&fscache_n_acquires_no_cache);
46142 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46143 _leave(" = -ENOMEDIUM [no cache]");
46144 return -ENOMEDIUM;
46145 }
46146 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46147 object = cache->ops->alloc_object(cache, cookie);
46148 fscache_stat_d(&fscache_n_cop_alloc_object);
46149 if (IS_ERR(object)) {
46150 - fscache_stat(&fscache_n_object_no_alloc);
46151 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46152 ret = PTR_ERR(object);
46153 goto error;
46154 }
46155
46156 - fscache_stat(&fscache_n_object_alloc);
46157 + fscache_stat_unchecked(&fscache_n_object_alloc);
46158
46159 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46160
46161 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46162 struct fscache_object *object;
46163 struct hlist_node *_p;
46164
46165 - fscache_stat(&fscache_n_updates);
46166 + fscache_stat_unchecked(&fscache_n_updates);
46167
46168 if (!cookie) {
46169 - fscache_stat(&fscache_n_updates_null);
46170 + fscache_stat_unchecked(&fscache_n_updates_null);
46171 _leave(" [no cookie]");
46172 return;
46173 }
46174 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46175 struct fscache_object *object;
46176 unsigned long event;
46177
46178 - fscache_stat(&fscache_n_relinquishes);
46179 + fscache_stat_unchecked(&fscache_n_relinquishes);
46180 if (retire)
46181 - fscache_stat(&fscache_n_relinquishes_retire);
46182 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46183
46184 if (!cookie) {
46185 - fscache_stat(&fscache_n_relinquishes_null);
46186 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46187 _leave(" [no cookie]");
46188 return;
46189 }
46190 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46191
46192 /* wait for the cookie to finish being instantiated (or to fail) */
46193 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46194 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46195 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46196 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46197 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46198 }
46199 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46200 index f6aad48..88dcf26 100644
46201 --- a/fs/fscache/internal.h
46202 +++ b/fs/fscache/internal.h
46203 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46204 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46205 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46206
46207 -extern atomic_t fscache_n_op_pend;
46208 -extern atomic_t fscache_n_op_run;
46209 -extern atomic_t fscache_n_op_enqueue;
46210 -extern atomic_t fscache_n_op_deferred_release;
46211 -extern atomic_t fscache_n_op_release;
46212 -extern atomic_t fscache_n_op_gc;
46213 -extern atomic_t fscache_n_op_cancelled;
46214 -extern atomic_t fscache_n_op_rejected;
46215 +extern atomic_unchecked_t fscache_n_op_pend;
46216 +extern atomic_unchecked_t fscache_n_op_run;
46217 +extern atomic_unchecked_t fscache_n_op_enqueue;
46218 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46219 +extern atomic_unchecked_t fscache_n_op_release;
46220 +extern atomic_unchecked_t fscache_n_op_gc;
46221 +extern atomic_unchecked_t fscache_n_op_cancelled;
46222 +extern atomic_unchecked_t fscache_n_op_rejected;
46223
46224 -extern atomic_t fscache_n_attr_changed;
46225 -extern atomic_t fscache_n_attr_changed_ok;
46226 -extern atomic_t fscache_n_attr_changed_nobufs;
46227 -extern atomic_t fscache_n_attr_changed_nomem;
46228 -extern atomic_t fscache_n_attr_changed_calls;
46229 +extern atomic_unchecked_t fscache_n_attr_changed;
46230 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46231 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46232 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46233 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46234
46235 -extern atomic_t fscache_n_allocs;
46236 -extern atomic_t fscache_n_allocs_ok;
46237 -extern atomic_t fscache_n_allocs_wait;
46238 -extern atomic_t fscache_n_allocs_nobufs;
46239 -extern atomic_t fscache_n_allocs_intr;
46240 -extern atomic_t fscache_n_allocs_object_dead;
46241 -extern atomic_t fscache_n_alloc_ops;
46242 -extern atomic_t fscache_n_alloc_op_waits;
46243 +extern atomic_unchecked_t fscache_n_allocs;
46244 +extern atomic_unchecked_t fscache_n_allocs_ok;
46245 +extern atomic_unchecked_t fscache_n_allocs_wait;
46246 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46247 +extern atomic_unchecked_t fscache_n_allocs_intr;
46248 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46249 +extern atomic_unchecked_t fscache_n_alloc_ops;
46250 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46251
46252 -extern atomic_t fscache_n_retrievals;
46253 -extern atomic_t fscache_n_retrievals_ok;
46254 -extern atomic_t fscache_n_retrievals_wait;
46255 -extern atomic_t fscache_n_retrievals_nodata;
46256 -extern atomic_t fscache_n_retrievals_nobufs;
46257 -extern atomic_t fscache_n_retrievals_intr;
46258 -extern atomic_t fscache_n_retrievals_nomem;
46259 -extern atomic_t fscache_n_retrievals_object_dead;
46260 -extern atomic_t fscache_n_retrieval_ops;
46261 -extern atomic_t fscache_n_retrieval_op_waits;
46262 +extern atomic_unchecked_t fscache_n_retrievals;
46263 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46264 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46265 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46266 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46267 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46268 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46269 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46270 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46271 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46272
46273 -extern atomic_t fscache_n_stores;
46274 -extern atomic_t fscache_n_stores_ok;
46275 -extern atomic_t fscache_n_stores_again;
46276 -extern atomic_t fscache_n_stores_nobufs;
46277 -extern atomic_t fscache_n_stores_oom;
46278 -extern atomic_t fscache_n_store_ops;
46279 -extern atomic_t fscache_n_store_calls;
46280 -extern atomic_t fscache_n_store_pages;
46281 -extern atomic_t fscache_n_store_radix_deletes;
46282 -extern atomic_t fscache_n_store_pages_over_limit;
46283 +extern atomic_unchecked_t fscache_n_stores;
46284 +extern atomic_unchecked_t fscache_n_stores_ok;
46285 +extern atomic_unchecked_t fscache_n_stores_again;
46286 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46287 +extern atomic_unchecked_t fscache_n_stores_oom;
46288 +extern atomic_unchecked_t fscache_n_store_ops;
46289 +extern atomic_unchecked_t fscache_n_store_calls;
46290 +extern atomic_unchecked_t fscache_n_store_pages;
46291 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46292 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46293
46294 -extern atomic_t fscache_n_store_vmscan_not_storing;
46295 -extern atomic_t fscache_n_store_vmscan_gone;
46296 -extern atomic_t fscache_n_store_vmscan_busy;
46297 -extern atomic_t fscache_n_store_vmscan_cancelled;
46298 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46299 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46300 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46301 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46302
46303 -extern atomic_t fscache_n_marks;
46304 -extern atomic_t fscache_n_uncaches;
46305 +extern atomic_unchecked_t fscache_n_marks;
46306 +extern atomic_unchecked_t fscache_n_uncaches;
46307
46308 -extern atomic_t fscache_n_acquires;
46309 -extern atomic_t fscache_n_acquires_null;
46310 -extern atomic_t fscache_n_acquires_no_cache;
46311 -extern atomic_t fscache_n_acquires_ok;
46312 -extern atomic_t fscache_n_acquires_nobufs;
46313 -extern atomic_t fscache_n_acquires_oom;
46314 +extern atomic_unchecked_t fscache_n_acquires;
46315 +extern atomic_unchecked_t fscache_n_acquires_null;
46316 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46317 +extern atomic_unchecked_t fscache_n_acquires_ok;
46318 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46319 +extern atomic_unchecked_t fscache_n_acquires_oom;
46320
46321 -extern atomic_t fscache_n_updates;
46322 -extern atomic_t fscache_n_updates_null;
46323 -extern atomic_t fscache_n_updates_run;
46324 +extern atomic_unchecked_t fscache_n_updates;
46325 +extern atomic_unchecked_t fscache_n_updates_null;
46326 +extern atomic_unchecked_t fscache_n_updates_run;
46327
46328 -extern atomic_t fscache_n_relinquishes;
46329 -extern atomic_t fscache_n_relinquishes_null;
46330 -extern atomic_t fscache_n_relinquishes_waitcrt;
46331 -extern atomic_t fscache_n_relinquishes_retire;
46332 +extern atomic_unchecked_t fscache_n_relinquishes;
46333 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46334 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46335 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46336
46337 -extern atomic_t fscache_n_cookie_index;
46338 -extern atomic_t fscache_n_cookie_data;
46339 -extern atomic_t fscache_n_cookie_special;
46340 +extern atomic_unchecked_t fscache_n_cookie_index;
46341 +extern atomic_unchecked_t fscache_n_cookie_data;
46342 +extern atomic_unchecked_t fscache_n_cookie_special;
46343
46344 -extern atomic_t fscache_n_object_alloc;
46345 -extern atomic_t fscache_n_object_no_alloc;
46346 -extern atomic_t fscache_n_object_lookups;
46347 -extern atomic_t fscache_n_object_lookups_negative;
46348 -extern atomic_t fscache_n_object_lookups_positive;
46349 -extern atomic_t fscache_n_object_lookups_timed_out;
46350 -extern atomic_t fscache_n_object_created;
46351 -extern atomic_t fscache_n_object_avail;
46352 -extern atomic_t fscache_n_object_dead;
46353 +extern atomic_unchecked_t fscache_n_object_alloc;
46354 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46355 +extern atomic_unchecked_t fscache_n_object_lookups;
46356 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46357 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46358 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46359 +extern atomic_unchecked_t fscache_n_object_created;
46360 +extern atomic_unchecked_t fscache_n_object_avail;
46361 +extern atomic_unchecked_t fscache_n_object_dead;
46362
46363 -extern atomic_t fscache_n_checkaux_none;
46364 -extern atomic_t fscache_n_checkaux_okay;
46365 -extern atomic_t fscache_n_checkaux_update;
46366 -extern atomic_t fscache_n_checkaux_obsolete;
46367 +extern atomic_unchecked_t fscache_n_checkaux_none;
46368 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46369 +extern atomic_unchecked_t fscache_n_checkaux_update;
46370 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46371
46372 extern atomic_t fscache_n_cop_alloc_object;
46373 extern atomic_t fscache_n_cop_lookup_object;
46374 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46375 atomic_inc(stat);
46376 }
46377
46378 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46379 +{
46380 + atomic_inc_unchecked(stat);
46381 +}
46382 +
46383 static inline void fscache_stat_d(atomic_t *stat)
46384 {
46385 atomic_dec(stat);
46386 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46387
46388 #define __fscache_stat(stat) (NULL)
46389 #define fscache_stat(stat) do {} while (0)
46390 +#define fscache_stat_unchecked(stat) do {} while (0)
46391 #define fscache_stat_d(stat) do {} while (0)
46392 #endif
46393
46394 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46395 index b6b897c..0ffff9c 100644
46396 --- a/fs/fscache/object.c
46397 +++ b/fs/fscache/object.c
46398 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46399 /* update the object metadata on disk */
46400 case FSCACHE_OBJECT_UPDATING:
46401 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46402 - fscache_stat(&fscache_n_updates_run);
46403 + fscache_stat_unchecked(&fscache_n_updates_run);
46404 fscache_stat(&fscache_n_cop_update_object);
46405 object->cache->ops->update_object(object);
46406 fscache_stat_d(&fscache_n_cop_update_object);
46407 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46408 spin_lock(&object->lock);
46409 object->state = FSCACHE_OBJECT_DEAD;
46410 spin_unlock(&object->lock);
46411 - fscache_stat(&fscache_n_object_dead);
46412 + fscache_stat_unchecked(&fscache_n_object_dead);
46413 goto terminal_transit;
46414
46415 /* handle the parent cache of this object being withdrawn from
46416 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46417 spin_lock(&object->lock);
46418 object->state = FSCACHE_OBJECT_DEAD;
46419 spin_unlock(&object->lock);
46420 - fscache_stat(&fscache_n_object_dead);
46421 + fscache_stat_unchecked(&fscache_n_object_dead);
46422 goto terminal_transit;
46423
46424 /* complain about the object being woken up once it is
46425 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46426 parent->cookie->def->name, cookie->def->name,
46427 object->cache->tag->name);
46428
46429 - fscache_stat(&fscache_n_object_lookups);
46430 + fscache_stat_unchecked(&fscache_n_object_lookups);
46431 fscache_stat(&fscache_n_cop_lookup_object);
46432 ret = object->cache->ops->lookup_object(object);
46433 fscache_stat_d(&fscache_n_cop_lookup_object);
46434 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46435 if (ret == -ETIMEDOUT) {
46436 /* probably stuck behind another object, so move this one to
46437 * the back of the queue */
46438 - fscache_stat(&fscache_n_object_lookups_timed_out);
46439 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46440 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46441 }
46442
46443 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46444
46445 spin_lock(&object->lock);
46446 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46447 - fscache_stat(&fscache_n_object_lookups_negative);
46448 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46449
46450 /* transit here to allow write requests to begin stacking up
46451 * and read requests to begin returning ENODATA */
46452 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46453 * result, in which case there may be data available */
46454 spin_lock(&object->lock);
46455 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46456 - fscache_stat(&fscache_n_object_lookups_positive);
46457 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46458
46459 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46460
46461 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46462 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46463 } else {
46464 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46465 - fscache_stat(&fscache_n_object_created);
46466 + fscache_stat_unchecked(&fscache_n_object_created);
46467
46468 object->state = FSCACHE_OBJECT_AVAILABLE;
46469 spin_unlock(&object->lock);
46470 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46471 fscache_enqueue_dependents(object);
46472
46473 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46474 - fscache_stat(&fscache_n_object_avail);
46475 + fscache_stat_unchecked(&fscache_n_object_avail);
46476
46477 _leave("");
46478 }
46479 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46480 enum fscache_checkaux result;
46481
46482 if (!object->cookie->def->check_aux) {
46483 - fscache_stat(&fscache_n_checkaux_none);
46484 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46485 return FSCACHE_CHECKAUX_OKAY;
46486 }
46487
46488 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46489 switch (result) {
46490 /* entry okay as is */
46491 case FSCACHE_CHECKAUX_OKAY:
46492 - fscache_stat(&fscache_n_checkaux_okay);
46493 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46494 break;
46495
46496 /* entry requires update */
46497 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46498 - fscache_stat(&fscache_n_checkaux_update);
46499 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46500 break;
46501
46502 /* entry requires deletion */
46503 case FSCACHE_CHECKAUX_OBSOLETE:
46504 - fscache_stat(&fscache_n_checkaux_obsolete);
46505 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46506 break;
46507
46508 default:
46509 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46510 index 30afdfa..2256596 100644
46511 --- a/fs/fscache/operation.c
46512 +++ b/fs/fscache/operation.c
46513 @@ -17,7 +17,7 @@
46514 #include <linux/slab.h>
46515 #include "internal.h"
46516
46517 -atomic_t fscache_op_debug_id;
46518 +atomic_unchecked_t fscache_op_debug_id;
46519 EXPORT_SYMBOL(fscache_op_debug_id);
46520
46521 /**
46522 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46523 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46524 ASSERTCMP(atomic_read(&op->usage), >, 0);
46525
46526 - fscache_stat(&fscache_n_op_enqueue);
46527 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46528 switch (op->flags & FSCACHE_OP_TYPE) {
46529 case FSCACHE_OP_ASYNC:
46530 _debug("queue async");
46531 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46532 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46533 if (op->processor)
46534 fscache_enqueue_operation(op);
46535 - fscache_stat(&fscache_n_op_run);
46536 + fscache_stat_unchecked(&fscache_n_op_run);
46537 }
46538
46539 /*
46540 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46541 if (object->n_ops > 1) {
46542 atomic_inc(&op->usage);
46543 list_add_tail(&op->pend_link, &object->pending_ops);
46544 - fscache_stat(&fscache_n_op_pend);
46545 + fscache_stat_unchecked(&fscache_n_op_pend);
46546 } else if (!list_empty(&object->pending_ops)) {
46547 atomic_inc(&op->usage);
46548 list_add_tail(&op->pend_link, &object->pending_ops);
46549 - fscache_stat(&fscache_n_op_pend);
46550 + fscache_stat_unchecked(&fscache_n_op_pend);
46551 fscache_start_operations(object);
46552 } else {
46553 ASSERTCMP(object->n_in_progress, ==, 0);
46554 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46555 object->n_exclusive++; /* reads and writes must wait */
46556 atomic_inc(&op->usage);
46557 list_add_tail(&op->pend_link, &object->pending_ops);
46558 - fscache_stat(&fscache_n_op_pend);
46559 + fscache_stat_unchecked(&fscache_n_op_pend);
46560 ret = 0;
46561 } else {
46562 /* not allowed to submit ops in any other state */
46563 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46564 if (object->n_exclusive > 0) {
46565 atomic_inc(&op->usage);
46566 list_add_tail(&op->pend_link, &object->pending_ops);
46567 - fscache_stat(&fscache_n_op_pend);
46568 + fscache_stat_unchecked(&fscache_n_op_pend);
46569 } else if (!list_empty(&object->pending_ops)) {
46570 atomic_inc(&op->usage);
46571 list_add_tail(&op->pend_link, &object->pending_ops);
46572 - fscache_stat(&fscache_n_op_pend);
46573 + fscache_stat_unchecked(&fscache_n_op_pend);
46574 fscache_start_operations(object);
46575 } else {
46576 ASSERTCMP(object->n_exclusive, ==, 0);
46577 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46578 object->n_ops++;
46579 atomic_inc(&op->usage);
46580 list_add_tail(&op->pend_link, &object->pending_ops);
46581 - fscache_stat(&fscache_n_op_pend);
46582 + fscache_stat_unchecked(&fscache_n_op_pend);
46583 ret = 0;
46584 } else if (object->state == FSCACHE_OBJECT_DYING ||
46585 object->state == FSCACHE_OBJECT_LC_DYING ||
46586 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46587 - fscache_stat(&fscache_n_op_rejected);
46588 + fscache_stat_unchecked(&fscache_n_op_rejected);
46589 ret = -ENOBUFS;
46590 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46591 fscache_report_unexpected_submission(object, op, ostate);
46592 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46593
46594 ret = -EBUSY;
46595 if (!list_empty(&op->pend_link)) {
46596 - fscache_stat(&fscache_n_op_cancelled);
46597 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46598 list_del_init(&op->pend_link);
46599 object->n_ops--;
46600 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46601 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46602 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46603 BUG();
46604
46605 - fscache_stat(&fscache_n_op_release);
46606 + fscache_stat_unchecked(&fscache_n_op_release);
46607
46608 if (op->release) {
46609 op->release(op);
46610 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46611 * lock, and defer it otherwise */
46612 if (!spin_trylock(&object->lock)) {
46613 _debug("defer put");
46614 - fscache_stat(&fscache_n_op_deferred_release);
46615 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46616
46617 cache = object->cache;
46618 spin_lock(&cache->op_gc_list_lock);
46619 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46620
46621 _debug("GC DEFERRED REL OBJ%x OP%x",
46622 object->debug_id, op->debug_id);
46623 - fscache_stat(&fscache_n_op_gc);
46624 + fscache_stat_unchecked(&fscache_n_op_gc);
46625
46626 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46627
46628 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46629 index 3f7a59b..cf196cc 100644
46630 --- a/fs/fscache/page.c
46631 +++ b/fs/fscache/page.c
46632 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46633 val = radix_tree_lookup(&cookie->stores, page->index);
46634 if (!val) {
46635 rcu_read_unlock();
46636 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46637 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46638 __fscache_uncache_page(cookie, page);
46639 return true;
46640 }
46641 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46642 spin_unlock(&cookie->stores_lock);
46643
46644 if (xpage) {
46645 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46646 - fscache_stat(&fscache_n_store_radix_deletes);
46647 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46648 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46649 ASSERTCMP(xpage, ==, page);
46650 } else {
46651 - fscache_stat(&fscache_n_store_vmscan_gone);
46652 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46653 }
46654
46655 wake_up_bit(&cookie->flags, 0);
46656 @@ -107,7 +107,7 @@ page_busy:
46657 /* we might want to wait here, but that could deadlock the allocator as
46658 * the work threads writing to the cache may all end up sleeping
46659 * on memory allocation */
46660 - fscache_stat(&fscache_n_store_vmscan_busy);
46661 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46662 return false;
46663 }
46664 EXPORT_SYMBOL(__fscache_maybe_release_page);
46665 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46666 FSCACHE_COOKIE_STORING_TAG);
46667 if (!radix_tree_tag_get(&cookie->stores, page->index,
46668 FSCACHE_COOKIE_PENDING_TAG)) {
46669 - fscache_stat(&fscache_n_store_radix_deletes);
46670 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46671 xpage = radix_tree_delete(&cookie->stores, page->index);
46672 }
46673 spin_unlock(&cookie->stores_lock);
46674 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46675
46676 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46677
46678 - fscache_stat(&fscache_n_attr_changed_calls);
46679 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46680
46681 if (fscache_object_is_active(object)) {
46682 fscache_stat(&fscache_n_cop_attr_changed);
46683 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46684
46685 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46686
46687 - fscache_stat(&fscache_n_attr_changed);
46688 + fscache_stat_unchecked(&fscache_n_attr_changed);
46689
46690 op = kzalloc(sizeof(*op), GFP_KERNEL);
46691 if (!op) {
46692 - fscache_stat(&fscache_n_attr_changed_nomem);
46693 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46694 _leave(" = -ENOMEM");
46695 return -ENOMEM;
46696 }
46697 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46698 if (fscache_submit_exclusive_op(object, op) < 0)
46699 goto nobufs;
46700 spin_unlock(&cookie->lock);
46701 - fscache_stat(&fscache_n_attr_changed_ok);
46702 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46703 fscache_put_operation(op);
46704 _leave(" = 0");
46705 return 0;
46706 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46707 nobufs:
46708 spin_unlock(&cookie->lock);
46709 kfree(op);
46710 - fscache_stat(&fscache_n_attr_changed_nobufs);
46711 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46712 _leave(" = %d", -ENOBUFS);
46713 return -ENOBUFS;
46714 }
46715 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46716 /* allocate a retrieval operation and attempt to submit it */
46717 op = kzalloc(sizeof(*op), GFP_NOIO);
46718 if (!op) {
46719 - fscache_stat(&fscache_n_retrievals_nomem);
46720 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46721 return NULL;
46722 }
46723
46724 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46725 return 0;
46726 }
46727
46728 - fscache_stat(&fscache_n_retrievals_wait);
46729 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46730
46731 jif = jiffies;
46732 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46733 fscache_wait_bit_interruptible,
46734 TASK_INTERRUPTIBLE) != 0) {
46735 - fscache_stat(&fscache_n_retrievals_intr);
46736 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46737 _leave(" = -ERESTARTSYS");
46738 return -ERESTARTSYS;
46739 }
46740 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46741 */
46742 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46743 struct fscache_retrieval *op,
46744 - atomic_t *stat_op_waits,
46745 - atomic_t *stat_object_dead)
46746 + atomic_unchecked_t *stat_op_waits,
46747 + atomic_unchecked_t *stat_object_dead)
46748 {
46749 int ret;
46750
46751 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46752 goto check_if_dead;
46753
46754 _debug(">>> WT");
46755 - fscache_stat(stat_op_waits);
46756 + fscache_stat_unchecked(stat_op_waits);
46757 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46758 fscache_wait_bit_interruptible,
46759 TASK_INTERRUPTIBLE) < 0) {
46760 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46761
46762 check_if_dead:
46763 if (unlikely(fscache_object_is_dead(object))) {
46764 - fscache_stat(stat_object_dead);
46765 + fscache_stat_unchecked(stat_object_dead);
46766 return -ENOBUFS;
46767 }
46768 return 0;
46769 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46770
46771 _enter("%p,%p,,,", cookie, page);
46772
46773 - fscache_stat(&fscache_n_retrievals);
46774 + fscache_stat_unchecked(&fscache_n_retrievals);
46775
46776 if (hlist_empty(&cookie->backing_objects))
46777 goto nobufs;
46778 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46779 goto nobufs_unlock;
46780 spin_unlock(&cookie->lock);
46781
46782 - fscache_stat(&fscache_n_retrieval_ops);
46783 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46784
46785 /* pin the netfs read context in case we need to do the actual netfs
46786 * read because we've encountered a cache read failure */
46787 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46788
46789 error:
46790 if (ret == -ENOMEM)
46791 - fscache_stat(&fscache_n_retrievals_nomem);
46792 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46793 else if (ret == -ERESTARTSYS)
46794 - fscache_stat(&fscache_n_retrievals_intr);
46795 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46796 else if (ret == -ENODATA)
46797 - fscache_stat(&fscache_n_retrievals_nodata);
46798 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46799 else if (ret < 0)
46800 - fscache_stat(&fscache_n_retrievals_nobufs);
46801 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46802 else
46803 - fscache_stat(&fscache_n_retrievals_ok);
46804 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46805
46806 fscache_put_retrieval(op);
46807 _leave(" = %d", ret);
46808 @@ -429,7 +429,7 @@ nobufs_unlock:
46809 spin_unlock(&cookie->lock);
46810 kfree(op);
46811 nobufs:
46812 - fscache_stat(&fscache_n_retrievals_nobufs);
46813 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46814 _leave(" = -ENOBUFS");
46815 return -ENOBUFS;
46816 }
46817 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46818
46819 _enter("%p,,%d,,,", cookie, *nr_pages);
46820
46821 - fscache_stat(&fscache_n_retrievals);
46822 + fscache_stat_unchecked(&fscache_n_retrievals);
46823
46824 if (hlist_empty(&cookie->backing_objects))
46825 goto nobufs;
46826 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46827 goto nobufs_unlock;
46828 spin_unlock(&cookie->lock);
46829
46830 - fscache_stat(&fscache_n_retrieval_ops);
46831 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46832
46833 /* pin the netfs read context in case we need to do the actual netfs
46834 * read because we've encountered a cache read failure */
46835 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46836
46837 error:
46838 if (ret == -ENOMEM)
46839 - fscache_stat(&fscache_n_retrievals_nomem);
46840 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46841 else if (ret == -ERESTARTSYS)
46842 - fscache_stat(&fscache_n_retrievals_intr);
46843 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46844 else if (ret == -ENODATA)
46845 - fscache_stat(&fscache_n_retrievals_nodata);
46846 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46847 else if (ret < 0)
46848 - fscache_stat(&fscache_n_retrievals_nobufs);
46849 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46850 else
46851 - fscache_stat(&fscache_n_retrievals_ok);
46852 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46853
46854 fscache_put_retrieval(op);
46855 _leave(" = %d", ret);
46856 @@ -545,7 +545,7 @@ nobufs_unlock:
46857 spin_unlock(&cookie->lock);
46858 kfree(op);
46859 nobufs:
46860 - fscache_stat(&fscache_n_retrievals_nobufs);
46861 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46862 _leave(" = -ENOBUFS");
46863 return -ENOBUFS;
46864 }
46865 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46866
46867 _enter("%p,%p,,,", cookie, page);
46868
46869 - fscache_stat(&fscache_n_allocs);
46870 + fscache_stat_unchecked(&fscache_n_allocs);
46871
46872 if (hlist_empty(&cookie->backing_objects))
46873 goto nobufs;
46874 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46875 goto nobufs_unlock;
46876 spin_unlock(&cookie->lock);
46877
46878 - fscache_stat(&fscache_n_alloc_ops);
46879 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46880
46881 ret = fscache_wait_for_retrieval_activation(
46882 object, op,
46883 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46884
46885 error:
46886 if (ret == -ERESTARTSYS)
46887 - fscache_stat(&fscache_n_allocs_intr);
46888 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46889 else if (ret < 0)
46890 - fscache_stat(&fscache_n_allocs_nobufs);
46891 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46892 else
46893 - fscache_stat(&fscache_n_allocs_ok);
46894 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46895
46896 fscache_put_retrieval(op);
46897 _leave(" = %d", ret);
46898 @@ -625,7 +625,7 @@ nobufs_unlock:
46899 spin_unlock(&cookie->lock);
46900 kfree(op);
46901 nobufs:
46902 - fscache_stat(&fscache_n_allocs_nobufs);
46903 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46904 _leave(" = -ENOBUFS");
46905 return -ENOBUFS;
46906 }
46907 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46908
46909 spin_lock(&cookie->stores_lock);
46910
46911 - fscache_stat(&fscache_n_store_calls);
46912 + fscache_stat_unchecked(&fscache_n_store_calls);
46913
46914 /* find a page to store */
46915 page = NULL;
46916 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46917 page = results[0];
46918 _debug("gang %d [%lx]", n, page->index);
46919 if (page->index > op->store_limit) {
46920 - fscache_stat(&fscache_n_store_pages_over_limit);
46921 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46922 goto superseded;
46923 }
46924
46925 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46926 spin_unlock(&cookie->stores_lock);
46927 spin_unlock(&object->lock);
46928
46929 - fscache_stat(&fscache_n_store_pages);
46930 + fscache_stat_unchecked(&fscache_n_store_pages);
46931 fscache_stat(&fscache_n_cop_write_page);
46932 ret = object->cache->ops->write_page(op, page);
46933 fscache_stat_d(&fscache_n_cop_write_page);
46934 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46935 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46936 ASSERT(PageFsCache(page));
46937
46938 - fscache_stat(&fscache_n_stores);
46939 + fscache_stat_unchecked(&fscache_n_stores);
46940
46941 op = kzalloc(sizeof(*op), GFP_NOIO);
46942 if (!op)
46943 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46944 spin_unlock(&cookie->stores_lock);
46945 spin_unlock(&object->lock);
46946
46947 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46948 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46949 op->store_limit = object->store_limit;
46950
46951 if (fscache_submit_op(object, &op->op) < 0)
46952 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46953
46954 spin_unlock(&cookie->lock);
46955 radix_tree_preload_end();
46956 - fscache_stat(&fscache_n_store_ops);
46957 - fscache_stat(&fscache_n_stores_ok);
46958 + fscache_stat_unchecked(&fscache_n_store_ops);
46959 + fscache_stat_unchecked(&fscache_n_stores_ok);
46960
46961 /* the work queue now carries its own ref on the object */
46962 fscache_put_operation(&op->op);
46963 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46964 return 0;
46965
46966 already_queued:
46967 - fscache_stat(&fscache_n_stores_again);
46968 + fscache_stat_unchecked(&fscache_n_stores_again);
46969 already_pending:
46970 spin_unlock(&cookie->stores_lock);
46971 spin_unlock(&object->lock);
46972 spin_unlock(&cookie->lock);
46973 radix_tree_preload_end();
46974 kfree(op);
46975 - fscache_stat(&fscache_n_stores_ok);
46976 + fscache_stat_unchecked(&fscache_n_stores_ok);
46977 _leave(" = 0");
46978 return 0;
46979
46980 @@ -851,14 +851,14 @@ nobufs:
46981 spin_unlock(&cookie->lock);
46982 radix_tree_preload_end();
46983 kfree(op);
46984 - fscache_stat(&fscache_n_stores_nobufs);
46985 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46986 _leave(" = -ENOBUFS");
46987 return -ENOBUFS;
46988
46989 nomem_free:
46990 kfree(op);
46991 nomem:
46992 - fscache_stat(&fscache_n_stores_oom);
46993 + fscache_stat_unchecked(&fscache_n_stores_oom);
46994 _leave(" = -ENOMEM");
46995 return -ENOMEM;
46996 }
46997 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46998 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46999 ASSERTCMP(page, !=, NULL);
47000
47001 - fscache_stat(&fscache_n_uncaches);
47002 + fscache_stat_unchecked(&fscache_n_uncaches);
47003
47004 /* cache withdrawal may beat us to it */
47005 if (!PageFsCache(page))
47006 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47007 unsigned long loop;
47008
47009 #ifdef CONFIG_FSCACHE_STATS
47010 - atomic_add(pagevec->nr, &fscache_n_marks);
47011 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47012 #endif
47013
47014 for (loop = 0; loop < pagevec->nr; loop++) {
47015 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47016 index 4765190..2a067f2 100644
47017 --- a/fs/fscache/stats.c
47018 +++ b/fs/fscache/stats.c
47019 @@ -18,95 +18,95 @@
47020 /*
47021 * operation counters
47022 */
47023 -atomic_t fscache_n_op_pend;
47024 -atomic_t fscache_n_op_run;
47025 -atomic_t fscache_n_op_enqueue;
47026 -atomic_t fscache_n_op_requeue;
47027 -atomic_t fscache_n_op_deferred_release;
47028 -atomic_t fscache_n_op_release;
47029 -atomic_t fscache_n_op_gc;
47030 -atomic_t fscache_n_op_cancelled;
47031 -atomic_t fscache_n_op_rejected;
47032 +atomic_unchecked_t fscache_n_op_pend;
47033 +atomic_unchecked_t fscache_n_op_run;
47034 +atomic_unchecked_t fscache_n_op_enqueue;
47035 +atomic_unchecked_t fscache_n_op_requeue;
47036 +atomic_unchecked_t fscache_n_op_deferred_release;
47037 +atomic_unchecked_t fscache_n_op_release;
47038 +atomic_unchecked_t fscache_n_op_gc;
47039 +atomic_unchecked_t fscache_n_op_cancelled;
47040 +atomic_unchecked_t fscache_n_op_rejected;
47041
47042 -atomic_t fscache_n_attr_changed;
47043 -atomic_t fscache_n_attr_changed_ok;
47044 -atomic_t fscache_n_attr_changed_nobufs;
47045 -atomic_t fscache_n_attr_changed_nomem;
47046 -atomic_t fscache_n_attr_changed_calls;
47047 +atomic_unchecked_t fscache_n_attr_changed;
47048 +atomic_unchecked_t fscache_n_attr_changed_ok;
47049 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47050 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47051 +atomic_unchecked_t fscache_n_attr_changed_calls;
47052
47053 -atomic_t fscache_n_allocs;
47054 -atomic_t fscache_n_allocs_ok;
47055 -atomic_t fscache_n_allocs_wait;
47056 -atomic_t fscache_n_allocs_nobufs;
47057 -atomic_t fscache_n_allocs_intr;
47058 -atomic_t fscache_n_allocs_object_dead;
47059 -atomic_t fscache_n_alloc_ops;
47060 -atomic_t fscache_n_alloc_op_waits;
47061 +atomic_unchecked_t fscache_n_allocs;
47062 +atomic_unchecked_t fscache_n_allocs_ok;
47063 +atomic_unchecked_t fscache_n_allocs_wait;
47064 +atomic_unchecked_t fscache_n_allocs_nobufs;
47065 +atomic_unchecked_t fscache_n_allocs_intr;
47066 +atomic_unchecked_t fscache_n_allocs_object_dead;
47067 +atomic_unchecked_t fscache_n_alloc_ops;
47068 +atomic_unchecked_t fscache_n_alloc_op_waits;
47069
47070 -atomic_t fscache_n_retrievals;
47071 -atomic_t fscache_n_retrievals_ok;
47072 -atomic_t fscache_n_retrievals_wait;
47073 -atomic_t fscache_n_retrievals_nodata;
47074 -atomic_t fscache_n_retrievals_nobufs;
47075 -atomic_t fscache_n_retrievals_intr;
47076 -atomic_t fscache_n_retrievals_nomem;
47077 -atomic_t fscache_n_retrievals_object_dead;
47078 -atomic_t fscache_n_retrieval_ops;
47079 -atomic_t fscache_n_retrieval_op_waits;
47080 +atomic_unchecked_t fscache_n_retrievals;
47081 +atomic_unchecked_t fscache_n_retrievals_ok;
47082 +atomic_unchecked_t fscache_n_retrievals_wait;
47083 +atomic_unchecked_t fscache_n_retrievals_nodata;
47084 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47085 +atomic_unchecked_t fscache_n_retrievals_intr;
47086 +atomic_unchecked_t fscache_n_retrievals_nomem;
47087 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47088 +atomic_unchecked_t fscache_n_retrieval_ops;
47089 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47090
47091 -atomic_t fscache_n_stores;
47092 -atomic_t fscache_n_stores_ok;
47093 -atomic_t fscache_n_stores_again;
47094 -atomic_t fscache_n_stores_nobufs;
47095 -atomic_t fscache_n_stores_oom;
47096 -atomic_t fscache_n_store_ops;
47097 -atomic_t fscache_n_store_calls;
47098 -atomic_t fscache_n_store_pages;
47099 -atomic_t fscache_n_store_radix_deletes;
47100 -atomic_t fscache_n_store_pages_over_limit;
47101 +atomic_unchecked_t fscache_n_stores;
47102 +atomic_unchecked_t fscache_n_stores_ok;
47103 +atomic_unchecked_t fscache_n_stores_again;
47104 +atomic_unchecked_t fscache_n_stores_nobufs;
47105 +atomic_unchecked_t fscache_n_stores_oom;
47106 +atomic_unchecked_t fscache_n_store_ops;
47107 +atomic_unchecked_t fscache_n_store_calls;
47108 +atomic_unchecked_t fscache_n_store_pages;
47109 +atomic_unchecked_t fscache_n_store_radix_deletes;
47110 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47111
47112 -atomic_t fscache_n_store_vmscan_not_storing;
47113 -atomic_t fscache_n_store_vmscan_gone;
47114 -atomic_t fscache_n_store_vmscan_busy;
47115 -atomic_t fscache_n_store_vmscan_cancelled;
47116 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47117 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47118 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47119 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47120
47121 -atomic_t fscache_n_marks;
47122 -atomic_t fscache_n_uncaches;
47123 +atomic_unchecked_t fscache_n_marks;
47124 +atomic_unchecked_t fscache_n_uncaches;
47125
47126 -atomic_t fscache_n_acquires;
47127 -atomic_t fscache_n_acquires_null;
47128 -atomic_t fscache_n_acquires_no_cache;
47129 -atomic_t fscache_n_acquires_ok;
47130 -atomic_t fscache_n_acquires_nobufs;
47131 -atomic_t fscache_n_acquires_oom;
47132 +atomic_unchecked_t fscache_n_acquires;
47133 +atomic_unchecked_t fscache_n_acquires_null;
47134 +atomic_unchecked_t fscache_n_acquires_no_cache;
47135 +atomic_unchecked_t fscache_n_acquires_ok;
47136 +atomic_unchecked_t fscache_n_acquires_nobufs;
47137 +atomic_unchecked_t fscache_n_acquires_oom;
47138
47139 -atomic_t fscache_n_updates;
47140 -atomic_t fscache_n_updates_null;
47141 -atomic_t fscache_n_updates_run;
47142 +atomic_unchecked_t fscache_n_updates;
47143 +atomic_unchecked_t fscache_n_updates_null;
47144 +atomic_unchecked_t fscache_n_updates_run;
47145
47146 -atomic_t fscache_n_relinquishes;
47147 -atomic_t fscache_n_relinquishes_null;
47148 -atomic_t fscache_n_relinquishes_waitcrt;
47149 -atomic_t fscache_n_relinquishes_retire;
47150 +atomic_unchecked_t fscache_n_relinquishes;
47151 +atomic_unchecked_t fscache_n_relinquishes_null;
47152 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47153 +atomic_unchecked_t fscache_n_relinquishes_retire;
47154
47155 -atomic_t fscache_n_cookie_index;
47156 -atomic_t fscache_n_cookie_data;
47157 -atomic_t fscache_n_cookie_special;
47158 +atomic_unchecked_t fscache_n_cookie_index;
47159 +atomic_unchecked_t fscache_n_cookie_data;
47160 +atomic_unchecked_t fscache_n_cookie_special;
47161
47162 -atomic_t fscache_n_object_alloc;
47163 -atomic_t fscache_n_object_no_alloc;
47164 -atomic_t fscache_n_object_lookups;
47165 -atomic_t fscache_n_object_lookups_negative;
47166 -atomic_t fscache_n_object_lookups_positive;
47167 -atomic_t fscache_n_object_lookups_timed_out;
47168 -atomic_t fscache_n_object_created;
47169 -atomic_t fscache_n_object_avail;
47170 -atomic_t fscache_n_object_dead;
47171 +atomic_unchecked_t fscache_n_object_alloc;
47172 +atomic_unchecked_t fscache_n_object_no_alloc;
47173 +atomic_unchecked_t fscache_n_object_lookups;
47174 +atomic_unchecked_t fscache_n_object_lookups_negative;
47175 +atomic_unchecked_t fscache_n_object_lookups_positive;
47176 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47177 +atomic_unchecked_t fscache_n_object_created;
47178 +atomic_unchecked_t fscache_n_object_avail;
47179 +atomic_unchecked_t fscache_n_object_dead;
47180
47181 -atomic_t fscache_n_checkaux_none;
47182 -atomic_t fscache_n_checkaux_okay;
47183 -atomic_t fscache_n_checkaux_update;
47184 -atomic_t fscache_n_checkaux_obsolete;
47185 +atomic_unchecked_t fscache_n_checkaux_none;
47186 +atomic_unchecked_t fscache_n_checkaux_okay;
47187 +atomic_unchecked_t fscache_n_checkaux_update;
47188 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47189
47190 atomic_t fscache_n_cop_alloc_object;
47191 atomic_t fscache_n_cop_lookup_object;
47192 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47193 seq_puts(m, "FS-Cache statistics\n");
47194
47195 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47196 - atomic_read(&fscache_n_cookie_index),
47197 - atomic_read(&fscache_n_cookie_data),
47198 - atomic_read(&fscache_n_cookie_special));
47199 + atomic_read_unchecked(&fscache_n_cookie_index),
47200 + atomic_read_unchecked(&fscache_n_cookie_data),
47201 + atomic_read_unchecked(&fscache_n_cookie_special));
47202
47203 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47204 - atomic_read(&fscache_n_object_alloc),
47205 - atomic_read(&fscache_n_object_no_alloc),
47206 - atomic_read(&fscache_n_object_avail),
47207 - atomic_read(&fscache_n_object_dead));
47208 + atomic_read_unchecked(&fscache_n_object_alloc),
47209 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47210 + atomic_read_unchecked(&fscache_n_object_avail),
47211 + atomic_read_unchecked(&fscache_n_object_dead));
47212 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47213 - atomic_read(&fscache_n_checkaux_none),
47214 - atomic_read(&fscache_n_checkaux_okay),
47215 - atomic_read(&fscache_n_checkaux_update),
47216 - atomic_read(&fscache_n_checkaux_obsolete));
47217 + atomic_read_unchecked(&fscache_n_checkaux_none),
47218 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47219 + atomic_read_unchecked(&fscache_n_checkaux_update),
47220 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47221
47222 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47223 - atomic_read(&fscache_n_marks),
47224 - atomic_read(&fscache_n_uncaches));
47225 + atomic_read_unchecked(&fscache_n_marks),
47226 + atomic_read_unchecked(&fscache_n_uncaches));
47227
47228 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47229 " oom=%u\n",
47230 - atomic_read(&fscache_n_acquires),
47231 - atomic_read(&fscache_n_acquires_null),
47232 - atomic_read(&fscache_n_acquires_no_cache),
47233 - atomic_read(&fscache_n_acquires_ok),
47234 - atomic_read(&fscache_n_acquires_nobufs),
47235 - atomic_read(&fscache_n_acquires_oom));
47236 + atomic_read_unchecked(&fscache_n_acquires),
47237 + atomic_read_unchecked(&fscache_n_acquires_null),
47238 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47239 + atomic_read_unchecked(&fscache_n_acquires_ok),
47240 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47241 + atomic_read_unchecked(&fscache_n_acquires_oom));
47242
47243 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47244 - atomic_read(&fscache_n_object_lookups),
47245 - atomic_read(&fscache_n_object_lookups_negative),
47246 - atomic_read(&fscache_n_object_lookups_positive),
47247 - atomic_read(&fscache_n_object_created),
47248 - atomic_read(&fscache_n_object_lookups_timed_out));
47249 + atomic_read_unchecked(&fscache_n_object_lookups),
47250 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47251 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47252 + atomic_read_unchecked(&fscache_n_object_created),
47253 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47254
47255 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47256 - atomic_read(&fscache_n_updates),
47257 - atomic_read(&fscache_n_updates_null),
47258 - atomic_read(&fscache_n_updates_run));
47259 + atomic_read_unchecked(&fscache_n_updates),
47260 + atomic_read_unchecked(&fscache_n_updates_null),
47261 + atomic_read_unchecked(&fscache_n_updates_run));
47262
47263 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47264 - atomic_read(&fscache_n_relinquishes),
47265 - atomic_read(&fscache_n_relinquishes_null),
47266 - atomic_read(&fscache_n_relinquishes_waitcrt),
47267 - atomic_read(&fscache_n_relinquishes_retire));
47268 + atomic_read_unchecked(&fscache_n_relinquishes),
47269 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47270 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47271 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47272
47273 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47274 - atomic_read(&fscache_n_attr_changed),
47275 - atomic_read(&fscache_n_attr_changed_ok),
47276 - atomic_read(&fscache_n_attr_changed_nobufs),
47277 - atomic_read(&fscache_n_attr_changed_nomem),
47278 - atomic_read(&fscache_n_attr_changed_calls));
47279 + atomic_read_unchecked(&fscache_n_attr_changed),
47280 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47281 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47282 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47283 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47284
47285 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47286 - atomic_read(&fscache_n_allocs),
47287 - atomic_read(&fscache_n_allocs_ok),
47288 - atomic_read(&fscache_n_allocs_wait),
47289 - atomic_read(&fscache_n_allocs_nobufs),
47290 - atomic_read(&fscache_n_allocs_intr));
47291 + atomic_read_unchecked(&fscache_n_allocs),
47292 + atomic_read_unchecked(&fscache_n_allocs_ok),
47293 + atomic_read_unchecked(&fscache_n_allocs_wait),
47294 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47295 + atomic_read_unchecked(&fscache_n_allocs_intr));
47296 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47297 - atomic_read(&fscache_n_alloc_ops),
47298 - atomic_read(&fscache_n_alloc_op_waits),
47299 - atomic_read(&fscache_n_allocs_object_dead));
47300 + atomic_read_unchecked(&fscache_n_alloc_ops),
47301 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47302 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47303
47304 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47305 " int=%u oom=%u\n",
47306 - atomic_read(&fscache_n_retrievals),
47307 - atomic_read(&fscache_n_retrievals_ok),
47308 - atomic_read(&fscache_n_retrievals_wait),
47309 - atomic_read(&fscache_n_retrievals_nodata),
47310 - atomic_read(&fscache_n_retrievals_nobufs),
47311 - atomic_read(&fscache_n_retrievals_intr),
47312 - atomic_read(&fscache_n_retrievals_nomem));
47313 + atomic_read_unchecked(&fscache_n_retrievals),
47314 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47315 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47316 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47317 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47318 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47319 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47320 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47321 - atomic_read(&fscache_n_retrieval_ops),
47322 - atomic_read(&fscache_n_retrieval_op_waits),
47323 - atomic_read(&fscache_n_retrievals_object_dead));
47324 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47325 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47326 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47327
47328 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47329 - atomic_read(&fscache_n_stores),
47330 - atomic_read(&fscache_n_stores_ok),
47331 - atomic_read(&fscache_n_stores_again),
47332 - atomic_read(&fscache_n_stores_nobufs),
47333 - atomic_read(&fscache_n_stores_oom));
47334 + atomic_read_unchecked(&fscache_n_stores),
47335 + atomic_read_unchecked(&fscache_n_stores_ok),
47336 + atomic_read_unchecked(&fscache_n_stores_again),
47337 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47338 + atomic_read_unchecked(&fscache_n_stores_oom));
47339 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47340 - atomic_read(&fscache_n_store_ops),
47341 - atomic_read(&fscache_n_store_calls),
47342 - atomic_read(&fscache_n_store_pages),
47343 - atomic_read(&fscache_n_store_radix_deletes),
47344 - atomic_read(&fscache_n_store_pages_over_limit));
47345 + atomic_read_unchecked(&fscache_n_store_ops),
47346 + atomic_read_unchecked(&fscache_n_store_calls),
47347 + atomic_read_unchecked(&fscache_n_store_pages),
47348 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47349 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47350
47351 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47352 - atomic_read(&fscache_n_store_vmscan_not_storing),
47353 - atomic_read(&fscache_n_store_vmscan_gone),
47354 - atomic_read(&fscache_n_store_vmscan_busy),
47355 - atomic_read(&fscache_n_store_vmscan_cancelled));
47356 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47357 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47358 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47359 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47360
47361 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47362 - atomic_read(&fscache_n_op_pend),
47363 - atomic_read(&fscache_n_op_run),
47364 - atomic_read(&fscache_n_op_enqueue),
47365 - atomic_read(&fscache_n_op_cancelled),
47366 - atomic_read(&fscache_n_op_rejected));
47367 + atomic_read_unchecked(&fscache_n_op_pend),
47368 + atomic_read_unchecked(&fscache_n_op_run),
47369 + atomic_read_unchecked(&fscache_n_op_enqueue),
47370 + atomic_read_unchecked(&fscache_n_op_cancelled),
47371 + atomic_read_unchecked(&fscache_n_op_rejected));
47372 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47373 - atomic_read(&fscache_n_op_deferred_release),
47374 - atomic_read(&fscache_n_op_release),
47375 - atomic_read(&fscache_n_op_gc));
47376 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47377 + atomic_read_unchecked(&fscache_n_op_release),
47378 + atomic_read_unchecked(&fscache_n_op_gc));
47379
47380 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47381 atomic_read(&fscache_n_cop_alloc_object),
47382 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47383 index ee8d550..7189d8c 100644
47384 --- a/fs/fuse/cuse.c
47385 +++ b/fs/fuse/cuse.c
47386 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47387 INIT_LIST_HEAD(&cuse_conntbl[i]);
47388
47389 /* inherit and extend fuse_dev_operations */
47390 - cuse_channel_fops = fuse_dev_operations;
47391 - cuse_channel_fops.owner = THIS_MODULE;
47392 - cuse_channel_fops.open = cuse_channel_open;
47393 - cuse_channel_fops.release = cuse_channel_release;
47394 + pax_open_kernel();
47395 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47396 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47397 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47398 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47399 + pax_close_kernel();
47400
47401 cuse_class = class_create(THIS_MODULE, "cuse");
47402 if (IS_ERR(cuse_class))
47403 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47404 index 8c23fa7..0e3aac7 100644
47405 --- a/fs/fuse/dev.c
47406 +++ b/fs/fuse/dev.c
47407 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47408 ret = 0;
47409 pipe_lock(pipe);
47410
47411 - if (!pipe->readers) {
47412 + if (!atomic_read(&pipe->readers)) {
47413 send_sig(SIGPIPE, current, 0);
47414 if (!ret)
47415 ret = -EPIPE;
47416 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47417 index 324bc08..4fdd56e 100644
47418 --- a/fs/fuse/dir.c
47419 +++ b/fs/fuse/dir.c
47420 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47421 return link;
47422 }
47423
47424 -static void free_link(char *link)
47425 +static void free_link(const char *link)
47426 {
47427 if (!IS_ERR(link))
47428 free_page((unsigned long) link);
47429 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47430 index 381893c..3793318 100644
47431 --- a/fs/gfs2/inode.c
47432 +++ b/fs/gfs2/inode.c
47433 @@ -1490,7 +1490,7 @@ out:
47434
47435 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47436 {
47437 - char *s = nd_get_link(nd);
47438 + const char *s = nd_get_link(nd);
47439 if (!IS_ERR(s))
47440 kfree(s);
47441 }
47442 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47443 index c5bc355..5a513bb 100644
47444 --- a/fs/hugetlbfs/inode.c
47445 +++ b/fs/hugetlbfs/inode.c
47446 @@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47447 .kill_sb = kill_litter_super,
47448 };
47449
47450 -static struct vfsmount *hugetlbfs_vfsmount;
47451 +struct vfsmount *hugetlbfs_vfsmount;
47452
47453 static int can_do_hugetlb_shm(void)
47454 {
47455 diff --git a/fs/inode.c b/fs/inode.c
47456 index 64999f1..8fad608 100644
47457 --- a/fs/inode.c
47458 +++ b/fs/inode.c
47459 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
47460
47461 #ifdef CONFIG_SMP
47462 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47463 - static atomic_t shared_last_ino;
47464 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47465 + static atomic_unchecked_t shared_last_ino;
47466 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47467
47468 res = next - LAST_INO_BATCH;
47469 }
47470 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47471 index 4a6cf28..d3a29d3 100644
47472 --- a/fs/jffs2/erase.c
47473 +++ b/fs/jffs2/erase.c
47474 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47475 struct jffs2_unknown_node marker = {
47476 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47477 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47478 - .totlen = cpu_to_je32(c->cleanmarker_size)
47479 + .totlen = cpu_to_je32(c->cleanmarker_size),
47480 + .hdr_crc = cpu_to_je32(0)
47481 };
47482
47483 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47484 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47485 index a6597d6..41b30ec 100644
47486 --- a/fs/jffs2/wbuf.c
47487 +++ b/fs/jffs2/wbuf.c
47488 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47489 {
47490 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47491 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47492 - .totlen = constant_cpu_to_je32(8)
47493 + .totlen = constant_cpu_to_je32(8),
47494 + .hdr_crc = constant_cpu_to_je32(0)
47495 };
47496
47497 /*
47498 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47499 index 1a543be..d803c40 100644
47500 --- a/fs/jfs/super.c
47501 +++ b/fs/jfs/super.c
47502 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
47503
47504 jfs_inode_cachep =
47505 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47506 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47507 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47508 init_once);
47509 if (jfs_inode_cachep == NULL)
47510 return -ENOMEM;
47511 diff --git a/fs/libfs.c b/fs/libfs.c
47512 index 7cc37ca..b3e3eec 100644
47513 --- a/fs/libfs.c
47514 +++ b/fs/libfs.c
47515 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47516
47517 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47518 struct dentry *next;
47519 + char d_name[sizeof(next->d_iname)];
47520 + const unsigned char *name;
47521 +
47522 next = list_entry(p, struct dentry, d_u.d_child);
47523 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47524 if (!simple_positive(next)) {
47525 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47526
47527 spin_unlock(&next->d_lock);
47528 spin_unlock(&dentry->d_lock);
47529 - if (filldir(dirent, next->d_name.name,
47530 + name = next->d_name.name;
47531 + if (name == next->d_iname) {
47532 + memcpy(d_name, name, next->d_name.len);
47533 + name = d_name;
47534 + }
47535 + if (filldir(dirent, name,
47536 next->d_name.len, filp->f_pos,
47537 next->d_inode->i_ino,
47538 dt_type(next->d_inode)) < 0)
47539 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47540 index 05d2912..760abfa 100644
47541 --- a/fs/lockd/clntproc.c
47542 +++ b/fs/lockd/clntproc.c
47543 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47544 /*
47545 * Cookie counter for NLM requests
47546 */
47547 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47548 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47549
47550 void nlmclnt_next_cookie(struct nlm_cookie *c)
47551 {
47552 - u32 cookie = atomic_inc_return(&nlm_cookie);
47553 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47554
47555 memcpy(c->data, &cookie, 4);
47556 c->len=4;
47557 diff --git a/fs/locks.c b/fs/locks.c
47558 index a94e331..060bce3 100644
47559 --- a/fs/locks.c
47560 +++ b/fs/locks.c
47561 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
47562 return;
47563
47564 if (filp->f_op && filp->f_op->flock) {
47565 - struct file_lock fl = {
47566 + struct file_lock flock = {
47567 .fl_pid = current->tgid,
47568 .fl_file = filp,
47569 .fl_flags = FL_FLOCK,
47570 .fl_type = F_UNLCK,
47571 .fl_end = OFFSET_MAX,
47572 };
47573 - filp->f_op->flock(filp, F_SETLKW, &fl);
47574 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47575 - fl.fl_ops->fl_release_private(&fl);
47576 + filp->f_op->flock(filp, F_SETLKW, &flock);
47577 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47578 + flock.fl_ops->fl_release_private(&flock);
47579 }
47580
47581 lock_flocks();
47582 diff --git a/fs/namei.c b/fs/namei.c
47583 index 5f4cdf3..959a013 100644
47584 --- a/fs/namei.c
47585 +++ b/fs/namei.c
47586 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
47587 if (ret != -EACCES)
47588 return ret;
47589
47590 +#ifdef CONFIG_GRKERNSEC
47591 + /* we'll block if we have to log due to a denied capability use */
47592 + if (mask & MAY_NOT_BLOCK)
47593 + return -ECHILD;
47594 +#endif
47595 +
47596 if (S_ISDIR(inode->i_mode)) {
47597 /* DACs are overridable for directories */
47598 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47599 - return 0;
47600 if (!(mask & MAY_WRITE))
47601 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47602 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47603 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47604 return 0;
47605 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47606 + return 0;
47607 return -EACCES;
47608 }
47609 /*
47610 + * Searching includes executable on directories, else just read.
47611 + */
47612 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47613 + if (mask == MAY_READ)
47614 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47615 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47616 + return 0;
47617 +
47618 + /*
47619 * Read/write DACs are always overridable.
47620 * Executable DACs are overridable when there is
47621 * at least one exec bit set.
47622 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
47623 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47624 return 0;
47625
47626 - /*
47627 - * Searching includes executable on directories, else just read.
47628 - */
47629 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47630 - if (mask == MAY_READ)
47631 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47632 - return 0;
47633 -
47634 return -EACCES;
47635 }
47636
47637 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47638 {
47639 struct dentry *dentry = link->dentry;
47640 int error;
47641 - char *s;
47642 + const char *s;
47643
47644 BUG_ON(nd->flags & LOOKUP_RCU);
47645
47646 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47647 if (error)
47648 goto out_put_nd_path;
47649
47650 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47651 + dentry->d_inode, dentry, nd->path.mnt)) {
47652 + error = -EACCES;
47653 + goto out_put_nd_path;
47654 + }
47655 +
47656 nd->last_type = LAST_BIND;
47657 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47658 error = PTR_ERR(*p);
47659 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47660 break;
47661 res = walk_component(nd, path, &nd->last,
47662 nd->last_type, LOOKUP_FOLLOW);
47663 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47664 + res = -EACCES;
47665 put_link(nd, &link, cookie);
47666 } while (res > 0);
47667
47668 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
47669 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47670 {
47671 unsigned long a, b, adata, bdata, mask, hash, len;
47672 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47673 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47674
47675 hash = a = 0;
47676 len = -sizeof(unsigned long);
47677 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
47678 if (err)
47679 break;
47680 err = lookup_last(nd, &path);
47681 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47682 + err = -EACCES;
47683 put_link(nd, &link, cookie);
47684 }
47685 }
47686 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
47687 if (!err)
47688 err = complete_walk(nd);
47689
47690 + if (!(nd->flags & LOOKUP_PARENT)) {
47691 +#ifdef CONFIG_GRKERNSEC
47692 + if (flags & LOOKUP_RCU) {
47693 + if (!err)
47694 + path_put(&nd->path);
47695 + err = -ECHILD;
47696 + } else
47697 +#endif
47698 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47699 + if (!err)
47700 + path_put(&nd->path);
47701 + err = -ENOENT;
47702 + }
47703 + }
47704 +
47705 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47706 if (!nd->inode->i_op->lookup) {
47707 path_put(&nd->path);
47708 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
47709 retval = path_lookupat(dfd, name->name,
47710 flags | LOOKUP_REVAL, nd);
47711
47712 - if (likely(!retval))
47713 + if (likely(!retval)) {
47714 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
47715 +#ifdef CONFIG_GRKERNSEC
47716 + if (flags & LOOKUP_RCU)
47717 + return -ECHILD;
47718 +#endif
47719 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47720 + return -ENOENT;
47721 + }
47722 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
47723 + }
47724 return retval;
47725 }
47726
47727 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47728 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47729 return -EPERM;
47730
47731 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47732 + return -EPERM;
47733 + if (gr_handle_rawio(inode))
47734 + return -EPERM;
47735 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47736 + return -EACCES;
47737 +
47738 return 0;
47739 }
47740
47741 @@ -2623,7 +2672,7 @@ looked_up:
47742 * cleared otherwise prior to returning.
47743 */
47744 static int lookup_open(struct nameidata *nd, struct path *path,
47745 - struct file *file,
47746 + struct path *link, struct file *file,
47747 const struct open_flags *op,
47748 bool got_write, int *opened)
47749 {
47750 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47751 /* Negative dentry, just create the file */
47752 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47753 umode_t mode = op->mode;
47754 +
47755 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47756 + error = -EACCES;
47757 + goto out_dput;
47758 + }
47759 +
47760 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47761 + error = -EACCES;
47762 + goto out_dput;
47763 + }
47764 +
47765 if (!IS_POSIXACL(dir->d_inode))
47766 mode &= ~current_umask();
47767 /*
47768 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47769 nd->flags & LOOKUP_EXCL);
47770 if (error)
47771 goto out_dput;
47772 + else
47773 + gr_handle_create(dentry, nd->path.mnt);
47774 }
47775 out_no_open:
47776 path->dentry = dentry;
47777 @@ -2693,7 +2755,7 @@ out_dput:
47778 /*
47779 * Handle the last step of open()
47780 */
47781 -static int do_last(struct nameidata *nd, struct path *path,
47782 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47783 struct file *file, const struct open_flags *op,
47784 int *opened, struct filename *name)
47785 {
47786 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47787 error = complete_walk(nd);
47788 if (error)
47789 return error;
47790 +#ifdef CONFIG_GRKERNSEC
47791 + if (nd->flags & LOOKUP_RCU) {
47792 + error = -ECHILD;
47793 + goto out;
47794 + }
47795 +#endif
47796 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47797 + error = -ENOENT;
47798 + goto out;
47799 + }
47800 audit_inode(name, nd->path.dentry, 0);
47801 if (open_flag & O_CREAT) {
47802 error = -EISDIR;
47803 goto out;
47804 }
47805 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47806 + error = -EACCES;
47807 + goto out;
47808 + }
47809 goto finish_open;
47810 case LAST_BIND:
47811 error = complete_walk(nd);
47812 if (error)
47813 return error;
47814 +#ifdef CONFIG_GRKERNSEC
47815 + if (nd->flags & LOOKUP_RCU) {
47816 + error = -ECHILD;
47817 + goto out;
47818 + }
47819 +#endif
47820 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47821 + error = -ENOENT;
47822 + goto out;
47823 + }
47824 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47825 + error = -EACCES;
47826 + goto out;
47827 + }
47828 audit_inode(name, dir, 0);
47829 goto finish_open;
47830 }
47831 @@ -2780,7 +2870,7 @@ retry_lookup:
47832 */
47833 }
47834 mutex_lock(&dir->d_inode->i_mutex);
47835 - error = lookup_open(nd, path, file, op, got_write, opened);
47836 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47837 mutex_unlock(&dir->d_inode->i_mutex);
47838
47839 if (error <= 0) {
47840 @@ -2804,11 +2894,28 @@ retry_lookup:
47841 goto finish_open_created;
47842 }
47843
47844 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47845 + error = -ENOENT;
47846 + goto exit_dput;
47847 + }
47848 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47849 + error = -EACCES;
47850 + goto exit_dput;
47851 + }
47852 +
47853 /*
47854 * create/update audit record if it already exists.
47855 */
47856 - if (path->dentry->d_inode)
47857 + if (path->dentry->d_inode) {
47858 + /* only check if O_CREAT is specified, all other checks need to go
47859 + into may_open */
47860 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47861 + error = -EACCES;
47862 + goto exit_dput;
47863 + }
47864 +
47865 audit_inode(name, path->dentry, 0);
47866 + }
47867
47868 /*
47869 * If atomic_open() acquired write access it is dropped now due to
47870 @@ -2849,6 +2956,11 @@ finish_lookup:
47871 }
47872 }
47873 BUG_ON(inode != path->dentry->d_inode);
47874 + /* if we're resolving a symlink to another symlink */
47875 + if (link && gr_handle_symlink_owner(link, inode)) {
47876 + error = -EACCES;
47877 + goto out;
47878 + }
47879 return 1;
47880 }
47881
47882 @@ -2858,7 +2970,6 @@ finish_lookup:
47883 save_parent.dentry = nd->path.dentry;
47884 save_parent.mnt = mntget(path->mnt);
47885 nd->path.dentry = path->dentry;
47886 -
47887 }
47888 nd->inode = inode;
47889 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47890 @@ -2867,6 +2978,22 @@ finish_lookup:
47891 path_put(&save_parent);
47892 return error;
47893 }
47894 +
47895 +#ifdef CONFIG_GRKERNSEC
47896 + if (nd->flags & LOOKUP_RCU) {
47897 + error = -ECHILD;
47898 + goto out;
47899 + }
47900 +#endif
47901 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47902 + error = -ENOENT;
47903 + goto out;
47904 + }
47905 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47906 + error = -EACCES;
47907 + goto out;
47908 + }
47909 +
47910 error = -EISDIR;
47911 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47912 goto out;
47913 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
47914 if (unlikely(error))
47915 goto out;
47916
47917 - error = do_last(nd, &path, file, op, &opened, pathname);
47918 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47919 while (unlikely(error > 0)) { /* trailing symlink */
47920 struct path link = path;
47921 void *cookie;
47922 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
47923 error = follow_link(&link, nd, &cookie);
47924 if (unlikely(error))
47925 break;
47926 - error = do_last(nd, &path, file, op, &opened, pathname);
47927 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47928 put_link(nd, &link, cookie);
47929 }
47930 out:
47931 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47932 goto unlock;
47933
47934 error = -EEXIST;
47935 - if (dentry->d_inode)
47936 + if (dentry->d_inode) {
47937 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47938 + error = -ENOENT;
47939 + }
47940 goto fail;
47941 + }
47942 /*
47943 * Special case - lookup gave negative, but... we had foo/bar/
47944 * From the vfs_mknod() POV we just have a negative dentry -
47945 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47946 }
47947 EXPORT_SYMBOL(user_path_create);
47948
47949 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
47950 +{
47951 + struct filename *tmp = getname(pathname);
47952 + struct dentry *res;
47953 + if (IS_ERR(tmp))
47954 + return ERR_CAST(tmp);
47955 + res = kern_path_create(dfd, tmp->name, path, is_dir);
47956 + if (IS_ERR(res))
47957 + putname(tmp);
47958 + else
47959 + *to = tmp;
47960 + return res;
47961 +}
47962 +
47963 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47964 {
47965 int error = may_create(dir, dentry);
47966 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47967
47968 if (!IS_POSIXACL(path.dentry->d_inode))
47969 mode &= ~current_umask();
47970 +
47971 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47972 + error = -EPERM;
47973 + goto out;
47974 + }
47975 +
47976 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47977 + error = -EACCES;
47978 + goto out;
47979 + }
47980 +
47981 error = security_path_mknod(&path, dentry, mode, dev);
47982 if (error)
47983 goto out;
47984 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47985 break;
47986 }
47987 out:
47988 + if (!error)
47989 + gr_handle_create(dentry, path.mnt);
47990 done_path_create(&path, dentry);
47991 return error;
47992 }
47993 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47994
47995 if (!IS_POSIXACL(path.dentry->d_inode))
47996 mode &= ~current_umask();
47997 +
47998 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47999 + error = -EACCES;
48000 + goto out;
48001 + }
48002 +
48003 error = security_path_mkdir(&path, dentry, mode);
48004 if (!error)
48005 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48006 + if (!error)
48007 + gr_handle_create(dentry, path.mnt);
48008 +out:
48009 done_path_create(&path, dentry);
48010 return error;
48011 }
48012 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48013 struct filename *name;
48014 struct dentry *dentry;
48015 struct nameidata nd;
48016 + ino_t saved_ino = 0;
48017 + dev_t saved_dev = 0;
48018
48019 name = user_path_parent(dfd, pathname, &nd);
48020 if (IS_ERR(name))
48021 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48022 error = -ENOENT;
48023 goto exit3;
48024 }
48025 +
48026 + saved_ino = dentry->d_inode->i_ino;
48027 + saved_dev = gr_get_dev_from_dentry(dentry);
48028 +
48029 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48030 + error = -EACCES;
48031 + goto exit3;
48032 + }
48033 +
48034 error = security_path_rmdir(&nd.path, dentry);
48035 if (error)
48036 goto exit3;
48037 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48038 + if (!error && (saved_dev || saved_ino))
48039 + gr_handle_delete(saved_ino, saved_dev);
48040 exit3:
48041 dput(dentry);
48042 exit2:
48043 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48044 struct dentry *dentry;
48045 struct nameidata nd;
48046 struct inode *inode = NULL;
48047 + ino_t saved_ino = 0;
48048 + dev_t saved_dev = 0;
48049
48050 name = user_path_parent(dfd, pathname, &nd);
48051 if (IS_ERR(name))
48052 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48053 if (!inode)
48054 goto slashes;
48055 ihold(inode);
48056 +
48057 + if (inode->i_nlink <= 1) {
48058 + saved_ino = inode->i_ino;
48059 + saved_dev = gr_get_dev_from_dentry(dentry);
48060 + }
48061 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48062 + error = -EACCES;
48063 + goto exit2;
48064 + }
48065 +
48066 error = security_path_unlink(&nd.path, dentry);
48067 if (error)
48068 goto exit2;
48069 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48070 + if (!error && (saved_ino || saved_dev))
48071 + gr_handle_delete(saved_ino, saved_dev);
48072 exit2:
48073 dput(dentry);
48074 }
48075 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48076 if (IS_ERR(dentry))
48077 goto out_putname;
48078
48079 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48080 + error = -EACCES;
48081 + goto out;
48082 + }
48083 +
48084 error = security_path_symlink(&path, dentry, from->name);
48085 if (!error)
48086 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
48087 + if (!error)
48088 + gr_handle_create(dentry, path.mnt);
48089 +out:
48090 done_path_create(&path, dentry);
48091 out_putname:
48092 putname(from);
48093 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48094 {
48095 struct dentry *new_dentry;
48096 struct path old_path, new_path;
48097 + struct filename *to = NULL;
48098 int how = 0;
48099 int error;
48100
48101 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48102 if (error)
48103 return error;
48104
48105 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48106 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48107 error = PTR_ERR(new_dentry);
48108 if (IS_ERR(new_dentry))
48109 goto out;
48110 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48111 error = may_linkat(&old_path);
48112 if (unlikely(error))
48113 goto out_dput;
48114 +
48115 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48116 + old_path.dentry->d_inode,
48117 + old_path.dentry->d_inode->i_mode, to)) {
48118 + error = -EACCES;
48119 + goto out_dput;
48120 + }
48121 +
48122 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48123 + old_path.dentry, old_path.mnt, to)) {
48124 + error = -EACCES;
48125 + goto out_dput;
48126 + }
48127 +
48128 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48129 if (error)
48130 goto out_dput;
48131 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48132 + if (!error)
48133 + gr_handle_create(new_dentry, new_path.mnt);
48134 out_dput:
48135 + putname(to);
48136 done_path_create(&new_path, new_dentry);
48137 out:
48138 path_put(&old_path);
48139 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48140 if (new_dentry == trap)
48141 goto exit5;
48142
48143 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48144 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48145 + to);
48146 + if (error)
48147 + goto exit5;
48148 +
48149 error = security_path_rename(&oldnd.path, old_dentry,
48150 &newnd.path, new_dentry);
48151 if (error)
48152 goto exit5;
48153 error = vfs_rename(old_dir->d_inode, old_dentry,
48154 new_dir->d_inode, new_dentry);
48155 + if (!error)
48156 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48157 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48158 exit5:
48159 dput(new_dentry);
48160 exit4:
48161 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48162
48163 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48164 {
48165 + char tmpbuf[64];
48166 + const char *newlink;
48167 int len;
48168
48169 len = PTR_ERR(link);
48170 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48171 len = strlen(link);
48172 if (len > (unsigned) buflen)
48173 len = buflen;
48174 - if (copy_to_user(buffer, link, len))
48175 +
48176 + if (len < sizeof(tmpbuf)) {
48177 + memcpy(tmpbuf, link, len);
48178 + newlink = tmpbuf;
48179 + } else
48180 + newlink = link;
48181 +
48182 + if (copy_to_user(buffer, newlink, len))
48183 len = -EFAULT;
48184 out:
48185 return len;
48186 diff --git a/fs/namespace.c b/fs/namespace.c
48187 index 2496062..e26f6d6 100644
48188 --- a/fs/namespace.c
48189 +++ b/fs/namespace.c
48190 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48191 if (!(sb->s_flags & MS_RDONLY))
48192 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48193 up_write(&sb->s_umount);
48194 +
48195 + gr_log_remount(mnt->mnt_devname, retval);
48196 +
48197 return retval;
48198 }
48199
48200 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48201 br_write_unlock(&vfsmount_lock);
48202 up_write(&namespace_sem);
48203 release_mounts(&umount_list);
48204 +
48205 + gr_log_unmount(mnt->mnt_devname, retval);
48206 +
48207 return retval;
48208 }
48209
48210 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
48211 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48212 MS_STRICTATIME);
48213
48214 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48215 + retval = -EPERM;
48216 + goto dput_out;
48217 + }
48218 +
48219 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48220 + retval = -EPERM;
48221 + goto dput_out;
48222 + }
48223 +
48224 if (flags & MS_REMOUNT)
48225 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48226 data_page);
48227 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
48228 dev_name, data_page);
48229 dput_out:
48230 path_put(&path);
48231 +
48232 + gr_log_mount(dev_name, dir_name, retval);
48233 +
48234 return retval;
48235 }
48236
48237 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48238 if (error)
48239 goto out2;
48240
48241 + if (gr_handle_chroot_pivot()) {
48242 + error = -EPERM;
48243 + goto out2;
48244 + }
48245 +
48246 get_fs_root(current->fs, &root);
48247 error = lock_mount(&old);
48248 if (error)
48249 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48250 index 6fa01ae..2790820 100644
48251 --- a/fs/nfs/inode.c
48252 +++ b/fs/nfs/inode.c
48253 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48254 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48255 }
48256
48257 -static atomic_long_t nfs_attr_generation_counter;
48258 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48259
48260 static unsigned long nfs_read_attr_generation_counter(void)
48261 {
48262 - return atomic_long_read(&nfs_attr_generation_counter);
48263 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48264 }
48265
48266 unsigned long nfs_inc_attr_generation_counter(void)
48267 {
48268 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48269 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48270 }
48271
48272 void nfs_fattr_init(struct nfs_fattr *fattr)
48273 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48274 index c120b48..8ac4140 100644
48275 --- a/fs/nfsd/vfs.c
48276 +++ b/fs/nfsd/vfs.c
48277 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48278 } else {
48279 oldfs = get_fs();
48280 set_fs(KERNEL_DS);
48281 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48282 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48283 set_fs(oldfs);
48284 }
48285
48286 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48287
48288 /* Write the data. */
48289 oldfs = get_fs(); set_fs(KERNEL_DS);
48290 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48291 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48292 set_fs(oldfs);
48293 if (host_err < 0)
48294 goto out_nfserr;
48295 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48296 */
48297
48298 oldfs = get_fs(); set_fs(KERNEL_DS);
48299 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
48300 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48301 set_fs(oldfs);
48302
48303 if (host_err < 0)
48304 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48305 index 6fcaeb8..9d16d04 100644
48306 --- a/fs/notify/fanotify/fanotify_user.c
48307 +++ b/fs/notify/fanotify/fanotify_user.c
48308 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48309
48310 fd = fanotify_event_metadata.fd;
48311 ret = -EFAULT;
48312 - if (copy_to_user(buf, &fanotify_event_metadata,
48313 - fanotify_event_metadata.event_len))
48314 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48315 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
48316 goto out_close_fd;
48317
48318 ret = prepare_for_access_response(group, event, fd);
48319 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48320 index c887b13..0fdf472 100644
48321 --- a/fs/notify/notification.c
48322 +++ b/fs/notify/notification.c
48323 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48324 * get set to 0 so it will never get 'freed'
48325 */
48326 static struct fsnotify_event *q_overflow_event;
48327 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48328 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48329
48330 /**
48331 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48332 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48333 */
48334 u32 fsnotify_get_cookie(void)
48335 {
48336 - return atomic_inc_return(&fsnotify_sync_cookie);
48337 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48338 }
48339 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48340
48341 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48342 index 99e3610..02c1068 100644
48343 --- a/fs/ntfs/dir.c
48344 +++ b/fs/ntfs/dir.c
48345 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48346 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48347 ~(s64)(ndir->itype.index.block_size - 1)));
48348 /* Bounds checks. */
48349 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48350 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48351 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48352 "inode 0x%lx or driver bug.", vdir->i_ino);
48353 goto err_out;
48354 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48355 index 1ecf464..e1ff8bf 100644
48356 --- a/fs/ntfs/file.c
48357 +++ b/fs/ntfs/file.c
48358 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48359 #endif /* NTFS_RW */
48360 };
48361
48362 -const struct file_operations ntfs_empty_file_ops = {};
48363 +const struct file_operations ntfs_empty_file_ops __read_only;
48364
48365 -const struct inode_operations ntfs_empty_inode_ops = {};
48366 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48367 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48368 index a9f78c7..ed8a381 100644
48369 --- a/fs/ocfs2/localalloc.c
48370 +++ b/fs/ocfs2/localalloc.c
48371 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48372 goto bail;
48373 }
48374
48375 - atomic_inc(&osb->alloc_stats.moves);
48376 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48377
48378 bail:
48379 if (handle)
48380 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48381 index d355e6e..578d905 100644
48382 --- a/fs/ocfs2/ocfs2.h
48383 +++ b/fs/ocfs2/ocfs2.h
48384 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48385
48386 struct ocfs2_alloc_stats
48387 {
48388 - atomic_t moves;
48389 - atomic_t local_data;
48390 - atomic_t bitmap_data;
48391 - atomic_t bg_allocs;
48392 - atomic_t bg_extends;
48393 + atomic_unchecked_t moves;
48394 + atomic_unchecked_t local_data;
48395 + atomic_unchecked_t bitmap_data;
48396 + atomic_unchecked_t bg_allocs;
48397 + atomic_unchecked_t bg_extends;
48398 };
48399
48400 enum ocfs2_local_alloc_state
48401 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48402 index f169da4..9112253 100644
48403 --- a/fs/ocfs2/suballoc.c
48404 +++ b/fs/ocfs2/suballoc.c
48405 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48406 mlog_errno(status);
48407 goto bail;
48408 }
48409 - atomic_inc(&osb->alloc_stats.bg_extends);
48410 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48411
48412 /* You should never ask for this much metadata */
48413 BUG_ON(bits_wanted >
48414 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48415 mlog_errno(status);
48416 goto bail;
48417 }
48418 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48419 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48420
48421 *suballoc_loc = res.sr_bg_blkno;
48422 *suballoc_bit_start = res.sr_bit_offset;
48423 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48424 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48425 res->sr_bits);
48426
48427 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48428 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48429
48430 BUG_ON(res->sr_bits != 1);
48431
48432 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48433 mlog_errno(status);
48434 goto bail;
48435 }
48436 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48437 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48438
48439 BUG_ON(res.sr_bits != 1);
48440
48441 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48442 cluster_start,
48443 num_clusters);
48444 if (!status)
48445 - atomic_inc(&osb->alloc_stats.local_data);
48446 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48447 } else {
48448 if (min_clusters > (osb->bitmap_cpg - 1)) {
48449 /* The only paths asking for contiguousness
48450 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48451 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48452 res.sr_bg_blkno,
48453 res.sr_bit_offset);
48454 - atomic_inc(&osb->alloc_stats.bitmap_data);
48455 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48456 *num_clusters = res.sr_bits;
48457 }
48458 }
48459 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48460 index 0e91ec2..f4b3fc6 100644
48461 --- a/fs/ocfs2/super.c
48462 +++ b/fs/ocfs2/super.c
48463 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48464 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48465 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48466 "Stats",
48467 - atomic_read(&osb->alloc_stats.bitmap_data),
48468 - atomic_read(&osb->alloc_stats.local_data),
48469 - atomic_read(&osb->alloc_stats.bg_allocs),
48470 - atomic_read(&osb->alloc_stats.moves),
48471 - atomic_read(&osb->alloc_stats.bg_extends));
48472 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48473 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48474 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48475 + atomic_read_unchecked(&osb->alloc_stats.moves),
48476 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48477
48478 out += snprintf(buf + out, len - out,
48479 "%10s => State: %u Descriptor: %llu Size: %u bits "
48480 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48481 spin_lock_init(&osb->osb_xattr_lock);
48482 ocfs2_init_steal_slots(osb);
48483
48484 - atomic_set(&osb->alloc_stats.moves, 0);
48485 - atomic_set(&osb->alloc_stats.local_data, 0);
48486 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48487 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48488 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48489 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48490 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48491 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48492 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48493 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48494
48495 /* Copy the blockcheck stats from the superblock probe */
48496 osb->osb_ecc_stats = *stats;
48497 diff --git a/fs/open.c b/fs/open.c
48498 index 59071f5..c6229a0 100644
48499 --- a/fs/open.c
48500 +++ b/fs/open.c
48501 @@ -31,6 +31,8 @@
48502 #include <linux/ima.h>
48503 #include <linux/dnotify.h>
48504
48505 +#define CREATE_TRACE_POINTS
48506 +#include <trace/events/fs.h>
48507 #include "internal.h"
48508
48509 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48510 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48511 error = locks_verify_truncate(inode, NULL, length);
48512 if (!error)
48513 error = security_path_truncate(&path);
48514 +
48515 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48516 + error = -EACCES;
48517 +
48518 if (!error)
48519 error = do_truncate(path.dentry, length, 0, NULL);
48520
48521 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48522 if (__mnt_is_readonly(path.mnt))
48523 res = -EROFS;
48524
48525 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48526 + res = -EACCES;
48527 +
48528 out_path_release:
48529 path_put(&path);
48530 out:
48531 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48532 if (error)
48533 goto dput_and_out;
48534
48535 + gr_log_chdir(path.dentry, path.mnt);
48536 +
48537 set_fs_pwd(current->fs, &path);
48538
48539 dput_and_out:
48540 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48541 goto out_putf;
48542
48543 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48544 +
48545 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
48546 + error = -EPERM;
48547 +
48548 + if (!error)
48549 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
48550 +
48551 if (!error)
48552 set_fs_pwd(current->fs, &f.file->f_path);
48553 out_putf:
48554 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48555 if (error)
48556 goto dput_and_out;
48557
48558 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48559 + goto dput_and_out;
48560 +
48561 set_fs_root(current->fs, &path);
48562 +
48563 + gr_handle_chroot_chdir(&path);
48564 +
48565 error = 0;
48566 dput_and_out:
48567 path_put(&path);
48568 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
48569 if (error)
48570 return error;
48571 mutex_lock(&inode->i_mutex);
48572 +
48573 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48574 + error = -EACCES;
48575 + goto out_unlock;
48576 + }
48577 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48578 + error = -EACCES;
48579 + goto out_unlock;
48580 + }
48581 +
48582 error = security_path_chmod(path, mode);
48583 if (error)
48584 goto out_unlock;
48585 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48586 uid = make_kuid(current_user_ns(), user);
48587 gid = make_kgid(current_user_ns(), group);
48588
48589 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48590 + return -EACCES;
48591 +
48592 newattrs.ia_valid = ATTR_CTIME;
48593 if (user != (uid_t) -1) {
48594 if (!uid_valid(uid))
48595 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48596 } else {
48597 fsnotify_open(f);
48598 fd_install(fd, f);
48599 + trace_do_sys_open(tmp->name, flags, mode);
48600 }
48601 }
48602 putname(tmp);
48603 diff --git a/fs/pipe.c b/fs/pipe.c
48604 index bd3479d..fb92c4d 100644
48605 --- a/fs/pipe.c
48606 +++ b/fs/pipe.c
48607 @@ -438,9 +438,9 @@ redo:
48608 }
48609 if (bufs) /* More to do? */
48610 continue;
48611 - if (!pipe->writers)
48612 + if (!atomic_read(&pipe->writers))
48613 break;
48614 - if (!pipe->waiting_writers) {
48615 + if (!atomic_read(&pipe->waiting_writers)) {
48616 /* syscall merging: Usually we must not sleep
48617 * if O_NONBLOCK is set, or if we got some data.
48618 * But if a writer sleeps in kernel space, then
48619 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48620 mutex_lock(&inode->i_mutex);
48621 pipe = inode->i_pipe;
48622
48623 - if (!pipe->readers) {
48624 + if (!atomic_read(&pipe->readers)) {
48625 send_sig(SIGPIPE, current, 0);
48626 ret = -EPIPE;
48627 goto out;
48628 @@ -553,7 +553,7 @@ redo1:
48629 for (;;) {
48630 int bufs;
48631
48632 - if (!pipe->readers) {
48633 + if (!atomic_read(&pipe->readers)) {
48634 send_sig(SIGPIPE, current, 0);
48635 if (!ret)
48636 ret = -EPIPE;
48637 @@ -644,9 +644,9 @@ redo2:
48638 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48639 do_wakeup = 0;
48640 }
48641 - pipe->waiting_writers++;
48642 + atomic_inc(&pipe->waiting_writers);
48643 pipe_wait(pipe);
48644 - pipe->waiting_writers--;
48645 + atomic_dec(&pipe->waiting_writers);
48646 }
48647 out:
48648 mutex_unlock(&inode->i_mutex);
48649 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48650 mask = 0;
48651 if (filp->f_mode & FMODE_READ) {
48652 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48653 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48654 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48655 mask |= POLLHUP;
48656 }
48657
48658 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48659 * Most Unices do not set POLLERR for FIFOs but on Linux they
48660 * behave exactly like pipes for poll().
48661 */
48662 - if (!pipe->readers)
48663 + if (!atomic_read(&pipe->readers))
48664 mask |= POLLERR;
48665 }
48666
48667 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48668
48669 mutex_lock(&inode->i_mutex);
48670 pipe = inode->i_pipe;
48671 - pipe->readers -= decr;
48672 - pipe->writers -= decw;
48673 + atomic_sub(decr, &pipe->readers);
48674 + atomic_sub(decw, &pipe->writers);
48675
48676 - if (!pipe->readers && !pipe->writers) {
48677 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48678 free_pipe_info(inode);
48679 } else {
48680 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48681 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48682
48683 if (inode->i_pipe) {
48684 ret = 0;
48685 - inode->i_pipe->readers++;
48686 + atomic_inc(&inode->i_pipe->readers);
48687 }
48688
48689 mutex_unlock(&inode->i_mutex);
48690 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48691
48692 if (inode->i_pipe) {
48693 ret = 0;
48694 - inode->i_pipe->writers++;
48695 + atomic_inc(&inode->i_pipe->writers);
48696 }
48697
48698 mutex_unlock(&inode->i_mutex);
48699 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48700 if (inode->i_pipe) {
48701 ret = 0;
48702 if (filp->f_mode & FMODE_READ)
48703 - inode->i_pipe->readers++;
48704 + atomic_inc(&inode->i_pipe->readers);
48705 if (filp->f_mode & FMODE_WRITE)
48706 - inode->i_pipe->writers++;
48707 + atomic_inc(&inode->i_pipe->writers);
48708 }
48709
48710 mutex_unlock(&inode->i_mutex);
48711 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48712 inode->i_pipe = NULL;
48713 }
48714
48715 -static struct vfsmount *pipe_mnt __read_mostly;
48716 +struct vfsmount *pipe_mnt __read_mostly;
48717
48718 /*
48719 * pipefs_dname() is called from d_path().
48720 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48721 goto fail_iput;
48722 inode->i_pipe = pipe;
48723
48724 - pipe->readers = pipe->writers = 1;
48725 + atomic_set(&pipe->readers, 1);
48726 + atomic_set(&pipe->writers, 1);
48727 inode->i_fop = &rdwr_pipefifo_fops;
48728
48729 /*
48730 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48731 index 15af622..0e9f4467 100644
48732 --- a/fs/proc/Kconfig
48733 +++ b/fs/proc/Kconfig
48734 @@ -30,12 +30,12 @@ config PROC_FS
48735
48736 config PROC_KCORE
48737 bool "/proc/kcore support" if !ARM
48738 - depends on PROC_FS && MMU
48739 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48740
48741 config PROC_VMCORE
48742 bool "/proc/vmcore support"
48743 - depends on PROC_FS && CRASH_DUMP
48744 - default y
48745 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48746 + default n
48747 help
48748 Exports the dump image of crashed kernel in ELF format.
48749
48750 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48751 limited in memory.
48752
48753 config PROC_PAGE_MONITOR
48754 - default y
48755 - depends on PROC_FS && MMU
48756 + default n
48757 + depends on PROC_FS && MMU && !GRKERNSEC
48758 bool "Enable /proc page monitoring" if EXPERT
48759 help
48760 Various /proc files exist to monitor process memory utilization:
48761 diff --git a/fs/proc/array.c b/fs/proc/array.c
48762 index c1c207c..01ce725 100644
48763 --- a/fs/proc/array.c
48764 +++ b/fs/proc/array.c
48765 @@ -60,6 +60,7 @@
48766 #include <linux/tty.h>
48767 #include <linux/string.h>
48768 #include <linux/mman.h>
48769 +#include <linux/grsecurity.h>
48770 #include <linux/proc_fs.h>
48771 #include <linux/ioport.h>
48772 #include <linux/uaccess.h>
48773 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48774 seq_putc(m, '\n');
48775 }
48776
48777 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48778 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48779 +{
48780 + if (p->mm)
48781 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48782 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48783 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48784 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48785 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48786 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48787 + else
48788 + seq_printf(m, "PaX:\t-----\n");
48789 +}
48790 +#endif
48791 +
48792 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48793 struct pid *pid, struct task_struct *task)
48794 {
48795 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48796 task_cpus_allowed(m, task);
48797 cpuset_task_status_allowed(m, task);
48798 task_context_switch_counts(m, task);
48799 +
48800 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48801 + task_pax(m, task);
48802 +#endif
48803 +
48804 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48805 + task_grsec_rbac(m, task);
48806 +#endif
48807 +
48808 return 0;
48809 }
48810
48811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48812 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48813 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48814 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48815 +#endif
48816 +
48817 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48818 struct pid *pid, struct task_struct *task, int whole)
48819 {
48820 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48821 char tcomm[sizeof(task->comm)];
48822 unsigned long flags;
48823
48824 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48825 + if (current->exec_id != m->exec_id) {
48826 + gr_log_badprocpid("stat");
48827 + return 0;
48828 + }
48829 +#endif
48830 +
48831 state = *get_task_state(task);
48832 vsize = eip = esp = 0;
48833 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48834 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48835 gtime = task->gtime;
48836 }
48837
48838 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48839 + if (PAX_RAND_FLAGS(mm)) {
48840 + eip = 0;
48841 + esp = 0;
48842 + wchan = 0;
48843 + }
48844 +#endif
48845 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48846 + wchan = 0;
48847 + eip =0;
48848 + esp =0;
48849 +#endif
48850 +
48851 /* scale priority and nice values from timeslices to -20..20 */
48852 /* to make it look like a "normal" Unix priority/nice value */
48853 priority = task_prio(task);
48854 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48855 seq_put_decimal_ull(m, ' ', vsize);
48856 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48857 seq_put_decimal_ull(m, ' ', rsslim);
48858 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48859 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48860 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48861 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48862 +#else
48863 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48864 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48865 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48866 +#endif
48867 seq_put_decimal_ull(m, ' ', esp);
48868 seq_put_decimal_ull(m, ' ', eip);
48869 /* The signal information here is obsolete.
48870 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48871 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48872 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48873
48874 - if (mm && permitted) {
48875 + if (mm && permitted
48876 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48877 + && !PAX_RAND_FLAGS(mm)
48878 +#endif
48879 + ) {
48880 seq_put_decimal_ull(m, ' ', mm->start_data);
48881 seq_put_decimal_ull(m, ' ', mm->end_data);
48882 seq_put_decimal_ull(m, ' ', mm->start_brk);
48883 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48884 struct pid *pid, struct task_struct *task)
48885 {
48886 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48887 - struct mm_struct *mm = get_task_mm(task);
48888 + struct mm_struct *mm;
48889
48890 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48891 + if (current->exec_id != m->exec_id) {
48892 + gr_log_badprocpid("statm");
48893 + return 0;
48894 + }
48895 +#endif
48896 + mm = get_task_mm(task);
48897 if (mm) {
48898 size = task_statm(mm, &shared, &text, &data, &resident);
48899 mmput(mm);
48900 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48901 return 0;
48902 }
48903
48904 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48905 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48906 +{
48907 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48908 +}
48909 +#endif
48910 +
48911 #ifdef CONFIG_CHECKPOINT_RESTORE
48912 static struct pid *
48913 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48914 diff --git a/fs/proc/base.c b/fs/proc/base.c
48915 index 9e28356..c485b3c 100644
48916 --- a/fs/proc/base.c
48917 +++ b/fs/proc/base.c
48918 @@ -111,6 +111,14 @@ struct pid_entry {
48919 union proc_op op;
48920 };
48921
48922 +struct getdents_callback {
48923 + struct linux_dirent __user * current_dir;
48924 + struct linux_dirent __user * previous;
48925 + struct file * file;
48926 + int count;
48927 + int error;
48928 +};
48929 +
48930 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48931 .name = (NAME), \
48932 .len = sizeof(NAME) - 1, \
48933 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48934 if (!mm->arg_end)
48935 goto out_mm; /* Shh! No looking before we're done */
48936
48937 + if (gr_acl_handle_procpidmem(task))
48938 + goto out_mm;
48939 +
48940 len = mm->arg_end - mm->arg_start;
48941
48942 if (len > PAGE_SIZE)
48943 @@ -235,12 +246,28 @@ out:
48944 return res;
48945 }
48946
48947 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48948 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48949 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48950 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48951 +#endif
48952 +
48953 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48954 {
48955 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48956 int res = PTR_ERR(mm);
48957 if (mm && !IS_ERR(mm)) {
48958 unsigned int nwords = 0;
48959 +
48960 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48961 + /* allow if we're currently ptracing this task */
48962 + if (PAX_RAND_FLAGS(mm) &&
48963 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48964 + mmput(mm);
48965 + return 0;
48966 + }
48967 +#endif
48968 +
48969 do {
48970 nwords += 2;
48971 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48972 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48973 }
48974
48975
48976 -#ifdef CONFIG_KALLSYMS
48977 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48978 /*
48979 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48980 * Returns the resolved symbol. If that fails, simply return the address.
48981 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
48982 mutex_unlock(&task->signal->cred_guard_mutex);
48983 }
48984
48985 -#ifdef CONFIG_STACKTRACE
48986 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48987
48988 #define MAX_STACK_TRACE_DEPTH 64
48989
48990 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48991 return count;
48992 }
48993
48994 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48995 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48996 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48997 {
48998 long nr;
48999 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49000 /************************************************************************/
49001
49002 /* permission checks */
49003 -static int proc_fd_access_allowed(struct inode *inode)
49004 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49005 {
49006 struct task_struct *task;
49007 int allowed = 0;
49008 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49009 */
49010 task = get_proc_task(inode);
49011 if (task) {
49012 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49013 + if (log)
49014 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49015 + else
49016 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49017 put_task_struct(task);
49018 }
49019 return allowed;
49020 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49021 struct task_struct *task,
49022 int hide_pid_min)
49023 {
49024 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49025 + return false;
49026 +
49027 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49028 + rcu_read_lock();
49029 + {
49030 + const struct cred *tmpcred = current_cred();
49031 + const struct cred *cred = __task_cred(task);
49032 +
49033 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49034 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49035 + || in_group_p(grsec_proc_gid)
49036 +#endif
49037 + ) {
49038 + rcu_read_unlock();
49039 + return true;
49040 + }
49041 + }
49042 + rcu_read_unlock();
49043 +
49044 + if (!pid->hide_pid)
49045 + return false;
49046 +#endif
49047 +
49048 if (pid->hide_pid < hide_pid_min)
49049 return true;
49050 if (in_group_p(pid->pid_gid))
49051 return true;
49052 +
49053 return ptrace_may_access(task, PTRACE_MODE_READ);
49054 }
49055
49056 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49057 put_task_struct(task);
49058
49059 if (!has_perms) {
49060 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49061 + {
49062 +#else
49063 if (pid->hide_pid == 2) {
49064 +#endif
49065 /*
49066 * Let's make getdents(), stat(), and open()
49067 * consistent with each other. If a process
49068 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49069 if (!task)
49070 return -ESRCH;
49071
49072 + if (gr_acl_handle_procpidmem(task)) {
49073 + put_task_struct(task);
49074 + return -EPERM;
49075 + }
49076 +
49077 mm = mm_access(task, mode);
49078 put_task_struct(task);
49079
49080 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49081
49082 file->private_data = mm;
49083
49084 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49085 + file->f_version = current->exec_id;
49086 +#endif
49087 +
49088 return 0;
49089 }
49090
49091 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49092 ssize_t copied;
49093 char *page;
49094
49095 +#ifdef CONFIG_GRKERNSEC
49096 + if (write)
49097 + return -EPERM;
49098 +#endif
49099 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49100 + if (file->f_version != current->exec_id) {
49101 + gr_log_badprocpid("mem");
49102 + return 0;
49103 + }
49104 +#endif
49105 +
49106 if (!mm)
49107 return 0;
49108
49109 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49110 if (!mm)
49111 return 0;
49112
49113 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49114 + if (file->f_version != current->exec_id) {
49115 + gr_log_badprocpid("environ");
49116 + return 0;
49117 + }
49118 +#endif
49119 +
49120 page = (char *)__get_free_page(GFP_TEMPORARY);
49121 if (!page)
49122 return -ENOMEM;
49123 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49124 int error = -EACCES;
49125
49126 /* Are we allowed to snoop on the tasks file descriptors? */
49127 - if (!proc_fd_access_allowed(inode))
49128 + if (!proc_fd_access_allowed(inode, 0))
49129 goto out;
49130
49131 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49132 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49133 struct path path;
49134
49135 /* Are we allowed to snoop on the tasks file descriptors? */
49136 - if (!proc_fd_access_allowed(inode))
49137 - goto out;
49138 + /* logging this is needed for learning on chromium to work properly,
49139 + but we don't want to flood the logs from 'ps' which does a readlink
49140 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49141 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49142 + */
49143 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49144 + if (!proc_fd_access_allowed(inode,0))
49145 + goto out;
49146 + } else {
49147 + if (!proc_fd_access_allowed(inode,1))
49148 + goto out;
49149 + }
49150
49151 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49152 if (error)
49153 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49154 rcu_read_lock();
49155 cred = __task_cred(task);
49156 inode->i_uid = cred->euid;
49157 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49158 + inode->i_gid = grsec_proc_gid;
49159 +#else
49160 inode->i_gid = cred->egid;
49161 +#endif
49162 rcu_read_unlock();
49163 }
49164 security_task_to_inode(task, inode);
49165 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49166 return -ENOENT;
49167 }
49168 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49169 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49170 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49171 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49172 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49173 +#endif
49174 task_dumpable(task)) {
49175 cred = __task_cred(task);
49176 stat->uid = cred->euid;
49177 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49178 + stat->gid = grsec_proc_gid;
49179 +#else
49180 stat->gid = cred->egid;
49181 +#endif
49182 }
49183 }
49184 rcu_read_unlock();
49185 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49186
49187 if (task) {
49188 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49189 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49190 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49191 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49192 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49193 +#endif
49194 task_dumpable(task)) {
49195 rcu_read_lock();
49196 cred = __task_cred(task);
49197 inode->i_uid = cred->euid;
49198 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49199 + inode->i_gid = grsec_proc_gid;
49200 +#else
49201 inode->i_gid = cred->egid;
49202 +#endif
49203 rcu_read_unlock();
49204 } else {
49205 inode->i_uid = GLOBAL_ROOT_UID;
49206 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49207 if (!task)
49208 goto out_no_task;
49209
49210 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49211 + goto out;
49212 +
49213 /*
49214 * Yes, it does not scale. And it should not. Don't add
49215 * new entries into /proc/<tgid>/ without very good reasons.
49216 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
49217 if (!task)
49218 goto out_no_task;
49219
49220 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49221 + goto out;
49222 +
49223 ret = 0;
49224 i = filp->f_pos;
49225 switch (i) {
49226 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49227 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49228 void *cookie)
49229 {
49230 - char *s = nd_get_link(nd);
49231 + const char *s = nd_get_link(nd);
49232 if (!IS_ERR(s))
49233 kfree(s);
49234 }
49235 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49236 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49237 #endif
49238 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49239 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49240 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49241 INF("syscall", S_IRUGO, proc_pid_syscall),
49242 #endif
49243 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49244 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49245 #ifdef CONFIG_SECURITY
49246 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49247 #endif
49248 -#ifdef CONFIG_KALLSYMS
49249 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49250 INF("wchan", S_IRUGO, proc_pid_wchan),
49251 #endif
49252 -#ifdef CONFIG_STACKTRACE
49253 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49254 ONE("stack", S_IRUGO, proc_pid_stack),
49255 #endif
49256 #ifdef CONFIG_SCHEDSTATS
49257 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49258 #ifdef CONFIG_HARDWALL
49259 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49260 #endif
49261 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49262 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49263 +#endif
49264 #ifdef CONFIG_USER_NS
49265 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49266 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49267 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49268 if (!inode)
49269 goto out;
49270
49271 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49272 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49273 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49274 + inode->i_gid = grsec_proc_gid;
49275 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49276 +#else
49277 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49278 +#endif
49279 inode->i_op = &proc_tgid_base_inode_operations;
49280 inode->i_fop = &proc_tgid_base_operations;
49281 inode->i_flags|=S_IMMUTABLE;
49282 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49283 if (!task)
49284 goto out;
49285
49286 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49287 + goto out_put_task;
49288 +
49289 result = proc_pid_instantiate(dir, dentry, task, NULL);
49290 +out_put_task:
49291 put_task_struct(task);
49292 out:
49293 return result;
49294 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49295 static int fake_filldir(void *buf, const char *name, int namelen,
49296 loff_t offset, u64 ino, unsigned d_type)
49297 {
49298 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49299 + __buf->error = -EINVAL;
49300 return 0;
49301 }
49302
49303 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
49304 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49305 #endif
49306 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49307 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49308 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49309 INF("syscall", S_IRUGO, proc_pid_syscall),
49310 #endif
49311 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49312 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
49313 #ifdef CONFIG_SECURITY
49314 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49315 #endif
49316 -#ifdef CONFIG_KALLSYMS
49317 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49318 INF("wchan", S_IRUGO, proc_pid_wchan),
49319 #endif
49320 -#ifdef CONFIG_STACKTRACE
49321 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49322 ONE("stack", S_IRUGO, proc_pid_stack),
49323 #endif
49324 #ifdef CONFIG_SCHEDSTATS
49325 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49326 index 82676e3..5f8518a 100644
49327 --- a/fs/proc/cmdline.c
49328 +++ b/fs/proc/cmdline.c
49329 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49330
49331 static int __init proc_cmdline_init(void)
49332 {
49333 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49334 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49335 +#else
49336 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49337 +#endif
49338 return 0;
49339 }
49340 module_init(proc_cmdline_init);
49341 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49342 index b143471..bb105e5 100644
49343 --- a/fs/proc/devices.c
49344 +++ b/fs/proc/devices.c
49345 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49346
49347 static int __init proc_devices_init(void)
49348 {
49349 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49350 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49351 +#else
49352 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49353 +#endif
49354 return 0;
49355 }
49356 module_init(proc_devices_init);
49357 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
49358 index f28a875..c467953 100644
49359 --- a/fs/proc/fd.c
49360 +++ b/fs/proc/fd.c
49361 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
49362 if (!task)
49363 return -ENOENT;
49364
49365 - files = get_files_struct(task);
49366 + if (!gr_acl_handle_procpidmem(task))
49367 + files = get_files_struct(task);
49368 put_task_struct(task);
49369
49370 if (files) {
49371 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
49372 */
49373 int proc_fd_permission(struct inode *inode, int mask)
49374 {
49375 + struct task_struct *task;
49376 int rv = generic_permission(inode, mask);
49377 - if (rv == 0)
49378 - return 0;
49379 +
49380 if (task_pid(current) == proc_pid(inode))
49381 rv = 0;
49382 +
49383 + task = get_proc_task(inode);
49384 + if (task == NULL)
49385 + return rv;
49386 +
49387 + if (gr_acl_handle_procpidmem(task))
49388 + rv = -EACCES;
49389 +
49390 + put_task_struct(task);
49391 +
49392 return rv;
49393 }
49394
49395 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49396 index 3b22bbd..895b58c 100644
49397 --- a/fs/proc/inode.c
49398 +++ b/fs/proc/inode.c
49399 @@ -21,11 +21,17 @@
49400 #include <linux/seq_file.h>
49401 #include <linux/slab.h>
49402 #include <linux/mount.h>
49403 +#include <linux/grsecurity.h>
49404
49405 #include <asm/uaccess.h>
49406
49407 #include "internal.h"
49408
49409 +#ifdef CONFIG_PROC_SYSCTL
49410 +extern const struct inode_operations proc_sys_inode_operations;
49411 +extern const struct inode_operations proc_sys_dir_operations;
49412 +#endif
49413 +
49414 static void proc_evict_inode(struct inode *inode)
49415 {
49416 struct proc_dir_entry *de;
49417 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49418 ns_ops = PROC_I(inode)->ns_ops;
49419 if (ns_ops && ns_ops->put)
49420 ns_ops->put(PROC_I(inode)->ns);
49421 +
49422 +#ifdef CONFIG_PROC_SYSCTL
49423 + if (inode->i_op == &proc_sys_inode_operations ||
49424 + inode->i_op == &proc_sys_dir_operations)
49425 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49426 +#endif
49427 +
49428 }
49429
49430 static struct kmem_cache * proc_inode_cachep;
49431 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49432 if (de->mode) {
49433 inode->i_mode = de->mode;
49434 inode->i_uid = de->uid;
49435 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49436 + inode->i_gid = grsec_proc_gid;
49437 +#else
49438 inode->i_gid = de->gid;
49439 +#endif
49440 }
49441 if (de->size)
49442 inode->i_size = de->size;
49443 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49444 index 43973b0..a20e704 100644
49445 --- a/fs/proc/internal.h
49446 +++ b/fs/proc/internal.h
49447 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49448 struct pid *pid, struct task_struct *task);
49449 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49450 struct pid *pid, struct task_struct *task);
49451 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49452 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49453 +#endif
49454 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49455
49456 extern const struct file_operations proc_tid_children_operations;
49457 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49458 index 86c67ee..cdca321 100644
49459 --- a/fs/proc/kcore.c
49460 +++ b/fs/proc/kcore.c
49461 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49462 * the addresses in the elf_phdr on our list.
49463 */
49464 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49465 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49466 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49467 + if (tsz > buflen)
49468 tsz = buflen;
49469 -
49470 +
49471 while (buflen) {
49472 struct kcore_list *m;
49473
49474 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49475 kfree(elf_buf);
49476 } else {
49477 if (kern_addr_valid(start)) {
49478 - unsigned long n;
49479 + char *elf_buf;
49480 + mm_segment_t oldfs;
49481
49482 - n = copy_to_user(buffer, (char *)start, tsz);
49483 - /*
49484 - * We cannot distinguish between fault on source
49485 - * and fault on destination. When this happens
49486 - * we clear too and hope it will trigger the
49487 - * EFAULT again.
49488 - */
49489 - if (n) {
49490 - if (clear_user(buffer + tsz - n,
49491 - n))
49492 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49493 + if (!elf_buf)
49494 + return -ENOMEM;
49495 + oldfs = get_fs();
49496 + set_fs(KERNEL_DS);
49497 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49498 + set_fs(oldfs);
49499 + if (copy_to_user(buffer, elf_buf, tsz)) {
49500 + kfree(elf_buf);
49501 return -EFAULT;
49502 + }
49503 }
49504 + set_fs(oldfs);
49505 + kfree(elf_buf);
49506 } else {
49507 if (clear_user(buffer, tsz))
49508 return -EFAULT;
49509 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49510
49511 static int open_kcore(struct inode *inode, struct file *filp)
49512 {
49513 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49514 + return -EPERM;
49515 +#endif
49516 if (!capable(CAP_SYS_RAWIO))
49517 return -EPERM;
49518 if (kcore_need_update)
49519 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49520 index 80e4645..53e5fcf 100644
49521 --- a/fs/proc/meminfo.c
49522 +++ b/fs/proc/meminfo.c
49523 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49524 vmi.used >> 10,
49525 vmi.largest_chunk >> 10
49526 #ifdef CONFIG_MEMORY_FAILURE
49527 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49528 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49529 #endif
49530 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49531 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49532 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49533 index b1822dd..df622cb 100644
49534 --- a/fs/proc/nommu.c
49535 +++ b/fs/proc/nommu.c
49536 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49537 if (len < 1)
49538 len = 1;
49539 seq_printf(m, "%*c", len, ' ');
49540 - seq_path(m, &file->f_path, "");
49541 + seq_path(m, &file->f_path, "\n\\");
49542 }
49543
49544 seq_putc(m, '\n');
49545 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49546 index fe72cd0..cb9b67d 100644
49547 --- a/fs/proc/proc_net.c
49548 +++ b/fs/proc/proc_net.c
49549 @@ -23,6 +23,7 @@
49550 #include <linux/nsproxy.h>
49551 #include <net/net_namespace.h>
49552 #include <linux/seq_file.h>
49553 +#include <linux/grsecurity.h>
49554
49555 #include "internal.h"
49556
49557 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49558 struct task_struct *task;
49559 struct nsproxy *ns;
49560 struct net *net = NULL;
49561 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49562 + const struct cred *cred = current_cred();
49563 +#endif
49564 +
49565 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49566 + if (cred->fsuid)
49567 + return net;
49568 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49569 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49570 + return net;
49571 +#endif
49572
49573 rcu_read_lock();
49574 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49575 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49576 index a781bdf..6665284 100644
49577 --- a/fs/proc/proc_sysctl.c
49578 +++ b/fs/proc/proc_sysctl.c
49579 @@ -12,11 +12,15 @@
49580 #include <linux/module.h>
49581 #include "internal.h"
49582
49583 +extern int gr_handle_chroot_sysctl(const int op);
49584 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49585 + const int op);
49586 +
49587 static const struct dentry_operations proc_sys_dentry_operations;
49588 static const struct file_operations proc_sys_file_operations;
49589 -static const struct inode_operations proc_sys_inode_operations;
49590 +const struct inode_operations proc_sys_inode_operations;
49591 static const struct file_operations proc_sys_dir_file_operations;
49592 -static const struct inode_operations proc_sys_dir_operations;
49593 +const struct inode_operations proc_sys_dir_operations;
49594
49595 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49596 {
49597 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49598
49599 err = NULL;
49600 d_set_d_op(dentry, &proc_sys_dentry_operations);
49601 +
49602 + gr_handle_proc_create(dentry, inode);
49603 +
49604 d_add(dentry, inode);
49605
49606 out:
49607 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49608 struct inode *inode = filp->f_path.dentry->d_inode;
49609 struct ctl_table_header *head = grab_header(inode);
49610 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49611 + int op = write ? MAY_WRITE : MAY_READ;
49612 ssize_t error;
49613 size_t res;
49614
49615 if (IS_ERR(head))
49616 return PTR_ERR(head);
49617
49618 +
49619 /*
49620 * At this point we know that the sysctl was not unregistered
49621 * and won't be until we finish.
49622 */
49623 error = -EPERM;
49624 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49625 + if (sysctl_perm(head->root, table, op))
49626 goto out;
49627
49628 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49629 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49630 if (!table->proc_handler)
49631 goto out;
49632
49633 +#ifdef CONFIG_GRKERNSEC
49634 + error = -EPERM;
49635 + if (gr_handle_chroot_sysctl(op))
49636 + goto out;
49637 + dget(filp->f_path.dentry);
49638 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49639 + dput(filp->f_path.dentry);
49640 + goto out;
49641 + }
49642 + dput(filp->f_path.dentry);
49643 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49644 + goto out;
49645 + if (write && !capable(CAP_SYS_ADMIN))
49646 + goto out;
49647 +#endif
49648 +
49649 /* careful: calling conventions are nasty here */
49650 res = count;
49651 error = table->proc_handler(table, write, buf, &res, ppos);
49652 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49653 return -ENOMEM;
49654 } else {
49655 d_set_d_op(child, &proc_sys_dentry_operations);
49656 +
49657 + gr_handle_proc_create(child, inode);
49658 +
49659 d_add(child, inode);
49660 }
49661 } else {
49662 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49663 if ((*pos)++ < file->f_pos)
49664 return 0;
49665
49666 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49667 + return 0;
49668 +
49669 if (unlikely(S_ISLNK(table->mode)))
49670 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49671 else
49672 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49673 if (IS_ERR(head))
49674 return PTR_ERR(head);
49675
49676 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49677 + return -ENOENT;
49678 +
49679 generic_fillattr(inode, stat);
49680 if (table)
49681 stat->mode = (stat->mode & S_IFMT) | table->mode;
49682 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49683 .llseek = generic_file_llseek,
49684 };
49685
49686 -static const struct inode_operations proc_sys_inode_operations = {
49687 +const struct inode_operations proc_sys_inode_operations = {
49688 .permission = proc_sys_permission,
49689 .setattr = proc_sys_setattr,
49690 .getattr = proc_sys_getattr,
49691 };
49692
49693 -static const struct inode_operations proc_sys_dir_operations = {
49694 +const struct inode_operations proc_sys_dir_operations = {
49695 .lookup = proc_sys_lookup,
49696 .permission = proc_sys_permission,
49697 .setattr = proc_sys_setattr,
49698 diff --git a/fs/proc/root.c b/fs/proc/root.c
49699 index 9889a92..2613b48 100644
49700 --- a/fs/proc/root.c
49701 +++ b/fs/proc/root.c
49702 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49703 #ifdef CONFIG_PROC_DEVICETREE
49704 proc_device_tree_init();
49705 #endif
49706 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49707 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49708 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49709 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49710 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49711 +#endif
49712 +#else
49713 proc_mkdir("bus", NULL);
49714 +#endif
49715 proc_sys_init();
49716 }
49717
49718 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49719 index 90c63f9..e662cfc 100644
49720 --- a/fs/proc/task_mmu.c
49721 +++ b/fs/proc/task_mmu.c
49722 @@ -11,12 +11,19 @@
49723 #include <linux/rmap.h>
49724 #include <linux/swap.h>
49725 #include <linux/swapops.h>
49726 +#include <linux/grsecurity.h>
49727
49728 #include <asm/elf.h>
49729 #include <asm/uaccess.h>
49730 #include <asm/tlbflush.h>
49731 #include "internal.h"
49732
49733 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49734 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49735 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49736 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49737 +#endif
49738 +
49739 void task_mem(struct seq_file *m, struct mm_struct *mm)
49740 {
49741 unsigned long data, text, lib, swap;
49742 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49743 "VmExe:\t%8lu kB\n"
49744 "VmLib:\t%8lu kB\n"
49745 "VmPTE:\t%8lu kB\n"
49746 - "VmSwap:\t%8lu kB\n",
49747 - hiwater_vm << (PAGE_SHIFT-10),
49748 + "VmSwap:\t%8lu kB\n"
49749 +
49750 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49751 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49752 +#endif
49753 +
49754 + ,hiwater_vm << (PAGE_SHIFT-10),
49755 total_vm << (PAGE_SHIFT-10),
49756 mm->locked_vm << (PAGE_SHIFT-10),
49757 mm->pinned_vm << (PAGE_SHIFT-10),
49758 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49759 data << (PAGE_SHIFT-10),
49760 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49761 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49762 - swap << (PAGE_SHIFT-10));
49763 + swap << (PAGE_SHIFT-10)
49764 +
49765 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49766 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49767 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49768 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49769 +#else
49770 + , mm->context.user_cs_base
49771 + , mm->context.user_cs_limit
49772 +#endif
49773 +#endif
49774 +
49775 + );
49776 }
49777
49778 unsigned long task_vsize(struct mm_struct *mm)
49779 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49780 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49781 }
49782
49783 - /* We don't show the stack guard page in /proc/maps */
49784 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49785 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49786 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49787 +#else
49788 start = vma->vm_start;
49789 - if (stack_guard_page_start(vma, start))
49790 - start += PAGE_SIZE;
49791 end = vma->vm_end;
49792 - if (stack_guard_page_end(vma, end))
49793 - end -= PAGE_SIZE;
49794 +#endif
49795
49796 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49797 start,
49798 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49799 flags & VM_WRITE ? 'w' : '-',
49800 flags & VM_EXEC ? 'x' : '-',
49801 flags & VM_MAYSHARE ? 's' : 'p',
49802 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49803 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49804 +#else
49805 pgoff,
49806 +#endif
49807 MAJOR(dev), MINOR(dev), ino, &len);
49808
49809 /*
49810 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49811 */
49812 if (file) {
49813 pad_len_spaces(m, len);
49814 - seq_path(m, &file->f_path, "\n");
49815 + seq_path(m, &file->f_path, "\n\\");
49816 goto done;
49817 }
49818
49819 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49820 * Thread stack in /proc/PID/task/TID/maps or
49821 * the main process stack.
49822 */
49823 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49824 - vma->vm_end >= mm->start_stack)) {
49825 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49826 + (vma->vm_start <= mm->start_stack &&
49827 + vma->vm_end >= mm->start_stack)) {
49828 name = "[stack]";
49829 } else {
49830 /* Thread stack in /proc/PID/maps */
49831 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49832 struct proc_maps_private *priv = m->private;
49833 struct task_struct *task = priv->task;
49834
49835 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49836 + if (current->exec_id != m->exec_id) {
49837 + gr_log_badprocpid("maps");
49838 + return 0;
49839 + }
49840 +#endif
49841 +
49842 show_map_vma(m, vma, is_pid);
49843
49844 if (m->count < m->size) /* vma is copied successfully */
49845 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49846 .private = &mss,
49847 };
49848
49849 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49850 + if (current->exec_id != m->exec_id) {
49851 + gr_log_badprocpid("smaps");
49852 + return 0;
49853 + }
49854 +#endif
49855 memset(&mss, 0, sizeof mss);
49856 - mss.vma = vma;
49857 - /* mmap_sem is held in m_start */
49858 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49859 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49860 -
49861 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49862 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49863 +#endif
49864 + mss.vma = vma;
49865 + /* mmap_sem is held in m_start */
49866 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49867 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49868 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49869 + }
49870 +#endif
49871 show_map_vma(m, vma, is_pid);
49872
49873 seq_printf(m,
49874 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49875 "KernelPageSize: %8lu kB\n"
49876 "MMUPageSize: %8lu kB\n"
49877 "Locked: %8lu kB\n",
49878 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49879 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49880 +#else
49881 (vma->vm_end - vma->vm_start) >> 10,
49882 +#endif
49883 mss.resident >> 10,
49884 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49885 mss.shared_clean >> 10,
49886 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49887 int n;
49888 char buffer[50];
49889
49890 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49891 + if (current->exec_id != m->exec_id) {
49892 + gr_log_badprocpid("numa_maps");
49893 + return 0;
49894 + }
49895 +#endif
49896 +
49897 if (!mm)
49898 return 0;
49899
49900 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49901 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49902 mpol_cond_put(pol);
49903
49904 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49905 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49906 +#else
49907 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49908 +#endif
49909
49910 if (file) {
49911 seq_printf(m, " file=");
49912 - seq_path(m, &file->f_path, "\n\t= ");
49913 + seq_path(m, &file->f_path, "\n\t\\= ");
49914 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49915 seq_printf(m, " heap");
49916 } else {
49917 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49918 index 1ccfa53..0848f95 100644
49919 --- a/fs/proc/task_nommu.c
49920 +++ b/fs/proc/task_nommu.c
49921 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49922 else
49923 bytes += kobjsize(mm);
49924
49925 - if (current->fs && current->fs->users > 1)
49926 + if (current->fs && atomic_read(&current->fs->users) > 1)
49927 sbytes += kobjsize(current->fs);
49928 else
49929 bytes += kobjsize(current->fs);
49930 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49931
49932 if (file) {
49933 pad_len_spaces(m, len);
49934 - seq_path(m, &file->f_path, "");
49935 + seq_path(m, &file->f_path, "\n\\");
49936 } else if (mm) {
49937 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49938
49939 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49940 index 16e8abb..2dcf914 100644
49941 --- a/fs/quota/netlink.c
49942 +++ b/fs/quota/netlink.c
49943 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49944 void quota_send_warning(struct kqid qid, dev_t dev,
49945 const char warntype)
49946 {
49947 - static atomic_t seq;
49948 + static atomic_unchecked_t seq;
49949 struct sk_buff *skb;
49950 void *msg_head;
49951 int ret;
49952 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
49953 "VFS: Not enough memory to send quota warning.\n");
49954 return;
49955 }
49956 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49957 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49958 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49959 if (!msg_head) {
49960 printk(KERN_ERR
49961 diff --git a/fs/readdir.c b/fs/readdir.c
49962 index 5e69ef5..e5d9099 100644
49963 --- a/fs/readdir.c
49964 +++ b/fs/readdir.c
49965 @@ -17,6 +17,7 @@
49966 #include <linux/security.h>
49967 #include <linux/syscalls.h>
49968 #include <linux/unistd.h>
49969 +#include <linux/namei.h>
49970
49971 #include <asm/uaccess.h>
49972
49973 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49974
49975 struct readdir_callback {
49976 struct old_linux_dirent __user * dirent;
49977 + struct file * file;
49978 int result;
49979 };
49980
49981 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49982 buf->result = -EOVERFLOW;
49983 return -EOVERFLOW;
49984 }
49985 +
49986 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49987 + return 0;
49988 +
49989 buf->result++;
49990 dirent = buf->dirent;
49991 if (!access_ok(VERIFY_WRITE, dirent,
49992 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49993
49994 buf.result = 0;
49995 buf.dirent = dirent;
49996 + buf.file = f.file;
49997
49998 error = vfs_readdir(f.file, fillonedir, &buf);
49999 if (buf.result)
50000 @@ -139,6 +146,7 @@ struct linux_dirent {
50001 struct getdents_callback {
50002 struct linux_dirent __user * current_dir;
50003 struct linux_dirent __user * previous;
50004 + struct file * file;
50005 int count;
50006 int error;
50007 };
50008 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50009 buf->error = -EOVERFLOW;
50010 return -EOVERFLOW;
50011 }
50012 +
50013 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50014 + return 0;
50015 +
50016 dirent = buf->previous;
50017 if (dirent) {
50018 if (__put_user(offset, &dirent->d_off))
50019 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50020 buf.previous = NULL;
50021 buf.count = count;
50022 buf.error = 0;
50023 + buf.file = f.file;
50024
50025 error = vfs_readdir(f.file, filldir, &buf);
50026 if (error >= 0)
50027 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50028 struct getdents_callback64 {
50029 struct linux_dirent64 __user * current_dir;
50030 struct linux_dirent64 __user * previous;
50031 + struct file *file;
50032 int count;
50033 int error;
50034 };
50035 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50036 buf->error = -EINVAL; /* only used if we fail.. */
50037 if (reclen > buf->count)
50038 return -EINVAL;
50039 +
50040 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50041 + return 0;
50042 +
50043 dirent = buf->previous;
50044 if (dirent) {
50045 if (__put_user(offset, &dirent->d_off))
50046 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50047
50048 buf.current_dir = dirent;
50049 buf.previous = NULL;
50050 + buf.file = f.file;
50051 buf.count = count;
50052 buf.error = 0;
50053
50054 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50055 error = buf.error;
50056 lastdirent = buf.previous;
50057 if (lastdirent) {
50058 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
50059 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50060 if (__put_user(d_off, &lastdirent->d_off))
50061 error = -EFAULT;
50062 else
50063 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50064 index 2b7882b..1c5ef48 100644
50065 --- a/fs/reiserfs/do_balan.c
50066 +++ b/fs/reiserfs/do_balan.c
50067 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50068 return;
50069 }
50070
50071 - atomic_inc(&(fs_generation(tb->tb_sb)));
50072 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50073 do_balance_starts(tb);
50074
50075 /* balance leaf returns 0 except if combining L R and S into
50076 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50077 index e60e870..f40ac16 100644
50078 --- a/fs/reiserfs/procfs.c
50079 +++ b/fs/reiserfs/procfs.c
50080 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50081 "SMALL_TAILS " : "NO_TAILS ",
50082 replay_only(sb) ? "REPLAY_ONLY " : "",
50083 convert_reiserfs(sb) ? "CONV " : "",
50084 - atomic_read(&r->s_generation_counter),
50085 + atomic_read_unchecked(&r->s_generation_counter),
50086 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50087 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50088 SF(s_good_search_by_key_reada), SF(s_bmaps),
50089 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50090 index 33215f5..c5d427a 100644
50091 --- a/fs/reiserfs/reiserfs.h
50092 +++ b/fs/reiserfs/reiserfs.h
50093 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50094 /* Comment? -Hans */
50095 wait_queue_head_t s_wait;
50096 /* To be obsoleted soon by per buffer seals.. -Hans */
50097 - atomic_t s_generation_counter; // increased by one every time the
50098 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50099 // tree gets re-balanced
50100 unsigned long s_properties; /* File system properties. Currently holds
50101 on-disk FS format */
50102 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50103 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50104
50105 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50106 -#define get_generation(s) atomic_read (&fs_generation(s))
50107 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50108 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50109 #define __fs_changed(gen,s) (gen != get_generation (s))
50110 #define fs_changed(gen,s) \
50111 diff --git a/fs/select.c b/fs/select.c
50112 index 2ef72d9..f213b17 100644
50113 --- a/fs/select.c
50114 +++ b/fs/select.c
50115 @@ -20,6 +20,7 @@
50116 #include <linux/export.h>
50117 #include <linux/slab.h>
50118 #include <linux/poll.h>
50119 +#include <linux/security.h>
50120 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50121 #include <linux/file.h>
50122 #include <linux/fdtable.h>
50123 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50124 struct poll_list *walk = head;
50125 unsigned long todo = nfds;
50126
50127 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50128 if (nfds > rlimit(RLIMIT_NOFILE))
50129 return -EINVAL;
50130
50131 diff --git a/fs/seq_file.c b/fs/seq_file.c
50132 index 99dffab..884a1eb 100644
50133 --- a/fs/seq_file.c
50134 +++ b/fs/seq_file.c
50135 @@ -10,6 +10,7 @@
50136 #include <linux/seq_file.h>
50137 #include <linux/slab.h>
50138 #include <linux/cred.h>
50139 +#include <linux/sched.h>
50140
50141 #include <asm/uaccess.h>
50142 #include <asm/page.h>
50143 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50144 #ifdef CONFIG_USER_NS
50145 p->user_ns = file->f_cred->user_ns;
50146 #endif
50147 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50148 + p->exec_id = current->exec_id;
50149 +#endif
50150
50151 /*
50152 * Wrappers around seq_open(e.g. swaps_open) need to be
50153 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50154 return 0;
50155 }
50156 if (!m->buf) {
50157 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50158 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50159 if (!m->buf)
50160 return -ENOMEM;
50161 }
50162 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50163 Eoverflow:
50164 m->op->stop(m, p);
50165 kfree(m->buf);
50166 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50167 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50168 return !m->buf ? -ENOMEM : -EAGAIN;
50169 }
50170
50171 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50172
50173 /* grab buffer if we didn't have one */
50174 if (!m->buf) {
50175 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50176 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50177 if (!m->buf)
50178 goto Enomem;
50179 }
50180 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50181 goto Fill;
50182 m->op->stop(m, p);
50183 kfree(m->buf);
50184 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50185 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50186 if (!m->buf)
50187 goto Enomem;
50188 m->count = 0;
50189 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
50190 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50191 void *data)
50192 {
50193 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50194 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50195 int res = -ENOMEM;
50196
50197 if (op) {
50198 diff --git a/fs/splice.c b/fs/splice.c
50199 index 13e5b47..2262998 100644
50200 --- a/fs/splice.c
50201 +++ b/fs/splice.c
50202 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50203 pipe_lock(pipe);
50204
50205 for (;;) {
50206 - if (!pipe->readers) {
50207 + if (!atomic_read(&pipe->readers)) {
50208 send_sig(SIGPIPE, current, 0);
50209 if (!ret)
50210 ret = -EPIPE;
50211 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50212 do_wakeup = 0;
50213 }
50214
50215 - pipe->waiting_writers++;
50216 + atomic_inc(&pipe->waiting_writers);
50217 pipe_wait(pipe);
50218 - pipe->waiting_writers--;
50219 + atomic_dec(&pipe->waiting_writers);
50220 }
50221
50222 pipe_unlock(pipe);
50223 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50224 old_fs = get_fs();
50225 set_fs(get_ds());
50226 /* The cast to a user pointer is valid due to the set_fs() */
50227 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50228 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50229 set_fs(old_fs);
50230
50231 return res;
50232 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50233 old_fs = get_fs();
50234 set_fs(get_ds());
50235 /* The cast to a user pointer is valid due to the set_fs() */
50236 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50237 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50238 set_fs(old_fs);
50239
50240 return res;
50241 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50242 goto err;
50243
50244 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50245 - vec[i].iov_base = (void __user *) page_address(page);
50246 + vec[i].iov_base = (void __force_user *) page_address(page);
50247 vec[i].iov_len = this_len;
50248 spd.pages[i] = page;
50249 spd.nr_pages++;
50250 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50251 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50252 {
50253 while (!pipe->nrbufs) {
50254 - if (!pipe->writers)
50255 + if (!atomic_read(&pipe->writers))
50256 return 0;
50257
50258 - if (!pipe->waiting_writers && sd->num_spliced)
50259 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50260 return 0;
50261
50262 if (sd->flags & SPLICE_F_NONBLOCK)
50263 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50264 * out of the pipe right after the splice_to_pipe(). So set
50265 * PIPE_READERS appropriately.
50266 */
50267 - pipe->readers = 1;
50268 + atomic_set(&pipe->readers, 1);
50269
50270 current->splice_pipe = pipe;
50271 }
50272 @@ -1739,9 +1739,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50273 ret = -ERESTARTSYS;
50274 break;
50275 }
50276 - if (!pipe->writers)
50277 + if (!atomic_read(&pipe->writers))
50278 break;
50279 - if (!pipe->waiting_writers) {
50280 + if (!atomic_read(&pipe->waiting_writers)) {
50281 if (flags & SPLICE_F_NONBLOCK) {
50282 ret = -EAGAIN;
50283 break;
50284 @@ -1773,7 +1773,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50285 pipe_lock(pipe);
50286
50287 while (pipe->nrbufs >= pipe->buffers) {
50288 - if (!pipe->readers) {
50289 + if (!atomic_read(&pipe->readers)) {
50290 send_sig(SIGPIPE, current, 0);
50291 ret = -EPIPE;
50292 break;
50293 @@ -1786,9 +1786,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50294 ret = -ERESTARTSYS;
50295 break;
50296 }
50297 - pipe->waiting_writers++;
50298 + atomic_inc(&pipe->waiting_writers);
50299 pipe_wait(pipe);
50300 - pipe->waiting_writers--;
50301 + atomic_dec(&pipe->waiting_writers);
50302 }
50303
50304 pipe_unlock(pipe);
50305 @@ -1824,14 +1824,14 @@ retry:
50306 pipe_double_lock(ipipe, opipe);
50307
50308 do {
50309 - if (!opipe->readers) {
50310 + if (!atomic_read(&opipe->readers)) {
50311 send_sig(SIGPIPE, current, 0);
50312 if (!ret)
50313 ret = -EPIPE;
50314 break;
50315 }
50316
50317 - if (!ipipe->nrbufs && !ipipe->writers)
50318 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50319 break;
50320
50321 /*
50322 @@ -1928,7 +1928,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50323 pipe_double_lock(ipipe, opipe);
50324
50325 do {
50326 - if (!opipe->readers) {
50327 + if (!atomic_read(&opipe->readers)) {
50328 send_sig(SIGPIPE, current, 0);
50329 if (!ret)
50330 ret = -EPIPE;
50331 @@ -1973,7 +1973,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50332 * return EAGAIN if we have the potential of some data in the
50333 * future, otherwise just return 0
50334 */
50335 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50336 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50337 ret = -EAGAIN;
50338
50339 pipe_unlock(ipipe);
50340 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50341 index 2fbdff6..5530a61 100644
50342 --- a/fs/sysfs/dir.c
50343 +++ b/fs/sysfs/dir.c
50344 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50345 struct sysfs_dirent *sd;
50346 int rc;
50347
50348 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50349 + const char *parent_name = parent_sd->s_name;
50350 +
50351 + mode = S_IFDIR | S_IRWXU;
50352 +
50353 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50354 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50355 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50356 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50357 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50358 +#endif
50359 +
50360 /* allocate */
50361 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50362 if (!sd)
50363 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50364 index 00012e3..8392349 100644
50365 --- a/fs/sysfs/file.c
50366 +++ b/fs/sysfs/file.c
50367 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50368
50369 struct sysfs_open_dirent {
50370 atomic_t refcnt;
50371 - atomic_t event;
50372 + atomic_unchecked_t event;
50373 wait_queue_head_t poll;
50374 struct list_head buffers; /* goes through sysfs_buffer.list */
50375 };
50376 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50377 if (!sysfs_get_active(attr_sd))
50378 return -ENODEV;
50379
50380 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50381 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50382 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50383
50384 sysfs_put_active(attr_sd);
50385 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50386 return -ENOMEM;
50387
50388 atomic_set(&new_od->refcnt, 0);
50389 - atomic_set(&new_od->event, 1);
50390 + atomic_set_unchecked(&new_od->event, 1);
50391 init_waitqueue_head(&new_od->poll);
50392 INIT_LIST_HEAD(&new_od->buffers);
50393 goto retry;
50394 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50395
50396 sysfs_put_active(attr_sd);
50397
50398 - if (buffer->event != atomic_read(&od->event))
50399 + if (buffer->event != atomic_read_unchecked(&od->event))
50400 goto trigger;
50401
50402 return DEFAULT_POLLMASK;
50403 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50404
50405 od = sd->s_attr.open;
50406 if (od) {
50407 - atomic_inc(&od->event);
50408 + atomic_inc_unchecked(&od->event);
50409 wake_up_interruptible(&od->poll);
50410 }
50411
50412 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50413 index 3c9eb56..9dea5be 100644
50414 --- a/fs/sysfs/symlink.c
50415 +++ b/fs/sysfs/symlink.c
50416 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50417
50418 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50419 {
50420 - char *page = nd_get_link(nd);
50421 + const char *page = nd_get_link(nd);
50422 if (!IS_ERR(page))
50423 free_page((unsigned long)page);
50424 }
50425 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50426 index c175b4d..8f36a16 100644
50427 --- a/fs/udf/misc.c
50428 +++ b/fs/udf/misc.c
50429 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50430
50431 u8 udf_tag_checksum(const struct tag *t)
50432 {
50433 - u8 *data = (u8 *)t;
50434 + const u8 *data = (const u8 *)t;
50435 u8 checksum = 0;
50436 int i;
50437 for (i = 0; i < sizeof(struct tag); ++i)
50438 diff --git a/fs/utimes.c b/fs/utimes.c
50439 index bb0696a..552054b 100644
50440 --- a/fs/utimes.c
50441 +++ b/fs/utimes.c
50442 @@ -1,6 +1,7 @@
50443 #include <linux/compiler.h>
50444 #include <linux/file.h>
50445 #include <linux/fs.h>
50446 +#include <linux/security.h>
50447 #include <linux/linkage.h>
50448 #include <linux/mount.h>
50449 #include <linux/namei.h>
50450 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50451 goto mnt_drop_write_and_out;
50452 }
50453 }
50454 +
50455 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50456 + error = -EACCES;
50457 + goto mnt_drop_write_and_out;
50458 + }
50459 +
50460 mutex_lock(&inode->i_mutex);
50461 error = notify_change(path->dentry, &newattrs);
50462 mutex_unlock(&inode->i_mutex);
50463 diff --git a/fs/xattr.c b/fs/xattr.c
50464 index e21c119..21dfc7c 100644
50465 --- a/fs/xattr.c
50466 +++ b/fs/xattr.c
50467 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50468 * Extended attribute SET operations
50469 */
50470 static long
50471 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50472 +setxattr(struct path *path, const char __user *name, const void __user *value,
50473 size_t size, int flags)
50474 {
50475 int error;
50476 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50477 posix_acl_fix_xattr_from_user(kvalue, size);
50478 }
50479
50480 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50481 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50482 + error = -EACCES;
50483 + goto out;
50484 + }
50485 +
50486 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50487 out:
50488 if (vvalue)
50489 vfree(vvalue);
50490 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50491 return error;
50492 error = mnt_want_write(path.mnt);
50493 if (!error) {
50494 - error = setxattr(path.dentry, name, value, size, flags);
50495 + error = setxattr(&path, name, value, size, flags);
50496 mnt_drop_write(path.mnt);
50497 }
50498 path_put(&path);
50499 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50500 return error;
50501 error = mnt_want_write(path.mnt);
50502 if (!error) {
50503 - error = setxattr(path.dentry, name, value, size, flags);
50504 + error = setxattr(&path, name, value, size, flags);
50505 mnt_drop_write(path.mnt);
50506 }
50507 path_put(&path);
50508 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50509 const void __user *,value, size_t, size, int, flags)
50510 {
50511 struct fd f = fdget(fd);
50512 - struct dentry *dentry;
50513 int error = -EBADF;
50514
50515 if (!f.file)
50516 return error;
50517 - dentry = f.file->f_path.dentry;
50518 - audit_inode(NULL, dentry, 0);
50519 + audit_inode(NULL, f.file->f_path.dentry, 0);
50520 error = mnt_want_write_file(f.file);
50521 if (!error) {
50522 - error = setxattr(dentry, name, value, size, flags);
50523 + error = setxattr(&f.file->f_path, name, value, size, flags);
50524 mnt_drop_write_file(f.file);
50525 }
50526 fdput(f);
50527 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50528 index 9fbea87..6b19972 100644
50529 --- a/fs/xattr_acl.c
50530 +++ b/fs/xattr_acl.c
50531 @@ -76,8 +76,8 @@ struct posix_acl *
50532 posix_acl_from_xattr(struct user_namespace *user_ns,
50533 const void *value, size_t size)
50534 {
50535 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50536 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50537 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50538 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50539 int count;
50540 struct posix_acl *acl;
50541 struct posix_acl_entry *acl_e;
50542 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50543 index 83d0cf3..2ef526b 100644
50544 --- a/fs/xfs/xfs_bmap.c
50545 +++ b/fs/xfs/xfs_bmap.c
50546 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50547 int nmap,
50548 int ret_nmap);
50549 #else
50550 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50551 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50552 #endif /* DEBUG */
50553
50554 STATIC int
50555 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50556 index 1b9fc3e..e1bdde0 100644
50557 --- a/fs/xfs/xfs_dir2_sf.c
50558 +++ b/fs/xfs/xfs_dir2_sf.c
50559 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50560 }
50561
50562 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50563 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50564 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50565 + char name[sfep->namelen];
50566 + memcpy(name, sfep->name, sfep->namelen);
50567 + if (filldir(dirent, name, sfep->namelen,
50568 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50569 + *offset = off & 0x7fffffff;
50570 + return 0;
50571 + }
50572 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50573 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50574 *offset = off & 0x7fffffff;
50575 return 0;
50576 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50577 index c1df3c6..f987db6 100644
50578 --- a/fs/xfs/xfs_ioctl.c
50579 +++ b/fs/xfs/xfs_ioctl.c
50580 @@ -126,7 +126,7 @@ xfs_find_handle(
50581 }
50582
50583 error = -EFAULT;
50584 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50585 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50586 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50587 goto out_put;
50588
50589 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50590 index 4e00cf0..3374374 100644
50591 --- a/fs/xfs/xfs_iops.c
50592 +++ b/fs/xfs/xfs_iops.c
50593 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50594 struct nameidata *nd,
50595 void *p)
50596 {
50597 - char *s = nd_get_link(nd);
50598 + const char *s = nd_get_link(nd);
50599
50600 if (!IS_ERR(s))
50601 kfree(s);
50602 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50603 new file mode 100644
50604 index 0000000..10c36fb
50605 --- /dev/null
50606 +++ b/grsecurity/Kconfig
50607 @@ -0,0 +1,964 @@
50608 +#
50609 +# grecurity configuration
50610 +#
50611 +menu "Memory Protections"
50612 +depends on GRKERNSEC
50613 +
50614 +config GRKERNSEC_KMEM
50615 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50616 + default y if GRKERNSEC_CONFIG_AUTO
50617 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50618 + help
50619 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50620 + be written to or read from to modify or leak the contents of the running
50621 + kernel. /dev/port will also not be allowed to be opened. If you have module
50622 + support disabled, enabling this will close up four ways that are
50623 + currently used to insert malicious code into the running kernel.
50624 + Even with all these features enabled, we still highly recommend that
50625 + you use the RBAC system, as it is still possible for an attacker to
50626 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50627 + If you are not using XFree86, you may be able to stop this additional
50628 + case by enabling the 'Disable privileged I/O' option. Though nothing
50629 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50630 + but only to video memory, which is the only writing we allow in this
50631 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50632 + not be allowed to mprotect it with PROT_WRITE later.
50633 + It is highly recommended that you say Y here if you meet all the
50634 + conditions above.
50635 +
50636 +config GRKERNSEC_VM86
50637 + bool "Restrict VM86 mode"
50638 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50639 + depends on X86_32
50640 +
50641 + help
50642 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50643 + make use of a special execution mode on 32bit x86 processors called
50644 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50645 + video cards and will still work with this option enabled. The purpose
50646 + of the option is to prevent exploitation of emulation errors in
50647 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50648 + Nearly all users should be able to enable this option.
50649 +
50650 +config GRKERNSEC_IO
50651 + bool "Disable privileged I/O"
50652 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50653 + depends on X86
50654 + select RTC_CLASS
50655 + select RTC_INTF_DEV
50656 + select RTC_DRV_CMOS
50657 +
50658 + help
50659 + If you say Y here, all ioperm and iopl calls will return an error.
50660 + Ioperm and iopl can be used to modify the running kernel.
50661 + Unfortunately, some programs need this access to operate properly,
50662 + the most notable of which are XFree86 and hwclock. hwclock can be
50663 + remedied by having RTC support in the kernel, so real-time
50664 + clock support is enabled if this option is enabled, to ensure
50665 + that hwclock operates correctly. XFree86 still will not
50666 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50667 + IF YOU USE XFree86. If you use XFree86 and you still want to
50668 + protect your kernel against modification, use the RBAC system.
50669 +
50670 +config GRKERNSEC_JIT_HARDEN
50671 + bool "Harden BPF JIT against spray attacks"
50672 + default y if GRKERNSEC_CONFIG_AUTO
50673 + depends on BPF_JIT
50674 + help
50675 + If you say Y here, the native code generated by the kernel's Berkeley
50676 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
50677 + attacks that attempt to fit attacker-beneficial instructions in
50678 + 32bit immediate fields of JIT-generated native instructions. The
50679 + attacker will generally aim to cause an unintended instruction sequence
50680 + of JIT-generated native code to execute by jumping into the middle of
50681 + a generated instruction. This feature effectively randomizes the 32bit
50682 + immediate constants present in the generated code to thwart such attacks.
50683 +
50684 + If you're using KERNEXEC, it's recommended that you enable this option
50685 + to supplement the hardening of the kernel.
50686 +
50687 +config GRKERNSEC_PROC_MEMMAP
50688 + bool "Harden ASLR against information leaks and entropy reduction"
50689 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50690 + depends on PAX_NOEXEC || PAX_ASLR
50691 + help
50692 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50693 + give no information about the addresses of its mappings if
50694 + PaX features that rely on random addresses are enabled on the task.
50695 + In addition to sanitizing this information and disabling other
50696 + dangerous sources of information, this option causes reads of sensitive
50697 + /proc/<pid> entries where the file descriptor was opened in a different
50698 + task than the one performing the read. Such attempts are logged.
50699 + This option also limits argv/env strings for suid/sgid binaries
50700 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50701 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50702 + binaries to prevent alternative mmap layouts from being abused.
50703 +
50704 + If you use PaX it is essential that you say Y here as it closes up
50705 + several holes that make full ASLR useless locally.
50706 +
50707 +config GRKERNSEC_BRUTE
50708 + bool "Deter exploit bruteforcing"
50709 + default y if GRKERNSEC_CONFIG_AUTO
50710 + help
50711 + If you say Y here, attempts to bruteforce exploits against forking
50712 + daemons such as apache or sshd, as well as against suid/sgid binaries
50713 + will be deterred. When a child of a forking daemon is killed by PaX
50714 + or crashes due to an illegal instruction or other suspicious signal,
50715 + the parent process will be delayed 30 seconds upon every subsequent
50716 + fork until the administrator is able to assess the situation and
50717 + restart the daemon.
50718 + In the suid/sgid case, the attempt is logged, the user has all their
50719 + processes terminated, and they are prevented from executing any further
50720 + processes for 15 minutes.
50721 + It is recommended that you also enable signal logging in the auditing
50722 + section so that logs are generated when a process triggers a suspicious
50723 + signal.
50724 + If the sysctl option is enabled, a sysctl option with name
50725 + "deter_bruteforce" is created.
50726 +
50727 +
50728 +config GRKERNSEC_MODHARDEN
50729 + bool "Harden module auto-loading"
50730 + default y if GRKERNSEC_CONFIG_AUTO
50731 + depends on MODULES
50732 + help
50733 + If you say Y here, module auto-loading in response to use of some
50734 + feature implemented by an unloaded module will be restricted to
50735 + root users. Enabling this option helps defend against attacks
50736 + by unprivileged users who abuse the auto-loading behavior to
50737 + cause a vulnerable module to load that is then exploited.
50738 +
50739 + If this option prevents a legitimate use of auto-loading for a
50740 + non-root user, the administrator can execute modprobe manually
50741 + with the exact name of the module mentioned in the alert log.
50742 + Alternatively, the administrator can add the module to the list
50743 + of modules loaded at boot by modifying init scripts.
50744 +
50745 + Modification of init scripts will most likely be needed on
50746 + Ubuntu servers with encrypted home directory support enabled,
50747 + as the first non-root user logging in will cause the ecb(aes),
50748 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50749 +
50750 +config GRKERNSEC_HIDESYM
50751 + bool "Hide kernel symbols"
50752 + default y if GRKERNSEC_CONFIG_AUTO
50753 + select PAX_USERCOPY_SLABS
50754 + help
50755 + If you say Y here, getting information on loaded modules, and
50756 + displaying all kernel symbols through a syscall will be restricted
50757 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50758 + /proc/kallsyms will be restricted to the root user. The RBAC
50759 + system can hide that entry even from root.
50760 +
50761 + This option also prevents leaking of kernel addresses through
50762 + several /proc entries.
50763 +
50764 + Note that this option is only effective provided the following
50765 + conditions are met:
50766 + 1) The kernel using grsecurity is not precompiled by some distribution
50767 + 2) You have also enabled GRKERNSEC_DMESG
50768 + 3) You are using the RBAC system and hiding other files such as your
50769 + kernel image and System.map. Alternatively, enabling this option
50770 + causes the permissions on /boot, /lib/modules, and the kernel
50771 + source directory to change at compile time to prevent
50772 + reading by non-root users.
50773 + If the above conditions are met, this option will aid in providing a
50774 + useful protection against local kernel exploitation of overflows
50775 + and arbitrary read/write vulnerabilities.
50776 +
50777 +config GRKERNSEC_KERN_LOCKOUT
50778 + bool "Active kernel exploit response"
50779 + default y if GRKERNSEC_CONFIG_AUTO
50780 + depends on X86 || ARM || PPC || SPARC
50781 + help
50782 + If you say Y here, when a PaX alert is triggered due to suspicious
50783 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50784 + or an OOPS occurs due to bad memory accesses, instead of just
50785 + terminating the offending process (and potentially allowing
50786 + a subsequent exploit from the same user), we will take one of two
50787 + actions:
50788 + If the user was root, we will panic the system
50789 + If the user was non-root, we will log the attempt, terminate
50790 + all processes owned by the user, then prevent them from creating
50791 + any new processes until the system is restarted
50792 + This deters repeated kernel exploitation/bruteforcing attempts
50793 + and is useful for later forensics.
50794 +
50795 +endmenu
50796 +menu "Role Based Access Control Options"
50797 +depends on GRKERNSEC
50798 +
50799 +config GRKERNSEC_RBAC_DEBUG
50800 + bool
50801 +
50802 +config GRKERNSEC_NO_RBAC
50803 + bool "Disable RBAC system"
50804 + help
50805 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50806 + preventing the RBAC system from being enabled. You should only say Y
50807 + here if you have no intention of using the RBAC system, so as to prevent
50808 + an attacker with root access from misusing the RBAC system to hide files
50809 + and processes when loadable module support and /dev/[k]mem have been
50810 + locked down.
50811 +
50812 +config GRKERNSEC_ACL_HIDEKERN
50813 + bool "Hide kernel processes"
50814 + help
50815 + If you say Y here, all kernel threads will be hidden to all
50816 + processes but those whose subject has the "view hidden processes"
50817 + flag.
50818 +
50819 +config GRKERNSEC_ACL_MAXTRIES
50820 + int "Maximum tries before password lockout"
50821 + default 3
50822 + help
50823 + This option enforces the maximum number of times a user can attempt
50824 + to authorize themselves with the grsecurity RBAC system before being
50825 + denied the ability to attempt authorization again for a specified time.
50826 + The lower the number, the harder it will be to brute-force a password.
50827 +
50828 +config GRKERNSEC_ACL_TIMEOUT
50829 + int "Time to wait after max password tries, in seconds"
50830 + default 30
50831 + help
50832 + This option specifies the time the user must wait after attempting to
50833 + authorize to the RBAC system with the maximum number of invalid
50834 + passwords. The higher the number, the harder it will be to brute-force
50835 + a password.
50836 +
50837 +endmenu
50838 +menu "Filesystem Protections"
50839 +depends on GRKERNSEC
50840 +
50841 +config GRKERNSEC_PROC
50842 + bool "Proc restrictions"
50843 + default y if GRKERNSEC_CONFIG_AUTO
50844 + help
50845 + If you say Y here, the permissions of the /proc filesystem
50846 + will be altered to enhance system security and privacy. You MUST
50847 + choose either a user only restriction or a user and group restriction.
50848 + Depending upon the option you choose, you can either restrict users to
50849 + see only the processes they themselves run, or choose a group that can
50850 + view all processes and files normally restricted to root if you choose
50851 + the "restrict to user only" option. NOTE: If you're running identd or
50852 + ntpd as a non-root user, you will have to run it as the group you
50853 + specify here.
50854 +
50855 +config GRKERNSEC_PROC_USER
50856 + bool "Restrict /proc to user only"
50857 + depends on GRKERNSEC_PROC
50858 + help
50859 + If you say Y here, non-root users will only be able to view their own
50860 + processes, and restricts them from viewing network-related information,
50861 + and viewing kernel symbol and module information.
50862 +
50863 +config GRKERNSEC_PROC_USERGROUP
50864 + bool "Allow special group"
50865 + default y if GRKERNSEC_CONFIG_AUTO
50866 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50867 + help
50868 + If you say Y here, you will be able to select a group that will be
50869 + able to view all processes and network-related information. If you've
50870 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50871 + remain hidden. This option is useful if you want to run identd as
50872 + a non-root user. The group you select may also be chosen at boot time
50873 + via "grsec_proc_gid=" on the kernel commandline.
50874 +
50875 +config GRKERNSEC_PROC_GID
50876 + int "GID for special group"
50877 + depends on GRKERNSEC_PROC_USERGROUP
50878 + default 1001
50879 +
50880 +config GRKERNSEC_PROC_ADD
50881 + bool "Additional restrictions"
50882 + default y if GRKERNSEC_CONFIG_AUTO
50883 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50884 + help
50885 + If you say Y here, additional restrictions will be placed on
50886 + /proc that keep normal users from viewing device information and
50887 + slabinfo information that could be useful for exploits.
50888 +
50889 +config GRKERNSEC_LINK
50890 + bool "Linking restrictions"
50891 + default y if GRKERNSEC_CONFIG_AUTO
50892 + help
50893 + If you say Y here, /tmp race exploits will be prevented, since users
50894 + will no longer be able to follow symlinks owned by other users in
50895 + world-writable +t directories (e.g. /tmp), unless the owner of the
50896 + symlink is the owner of the directory. users will also not be
50897 + able to hardlink to files they do not own. If the sysctl option is
50898 + enabled, a sysctl option with name "linking_restrictions" is created.
50899 +
50900 +config GRKERNSEC_SYMLINKOWN
50901 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50902 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50903 + help
50904 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50905 + that prevents it from being used as a security feature. As Apache
50906 + verifies the symlink by performing a stat() against the target of
50907 + the symlink before it is followed, an attacker can setup a symlink
50908 + to point to a same-owned file, then replace the symlink with one
50909 + that targets another user's file just after Apache "validates" the
50910 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50911 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50912 + will be in place for the group you specify. If the sysctl option
50913 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50914 + created.
50915 +
50916 +config GRKERNSEC_SYMLINKOWN_GID
50917 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50918 + depends on GRKERNSEC_SYMLINKOWN
50919 + default 1006
50920 + help
50921 + Setting this GID determines what group kernel-enforced
50922 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50923 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50924 +
50925 +config GRKERNSEC_FIFO
50926 + bool "FIFO restrictions"
50927 + default y if GRKERNSEC_CONFIG_AUTO
50928 + help
50929 + If you say Y here, users will not be able to write to FIFOs they don't
50930 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50931 + the FIFO is the same owner of the directory it's held in. If the sysctl
50932 + option is enabled, a sysctl option with name "fifo_restrictions" is
50933 + created.
50934 +
50935 +config GRKERNSEC_SYSFS_RESTRICT
50936 + bool "Sysfs/debugfs restriction"
50937 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50938 + depends on SYSFS
50939 + help
50940 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50941 + any filesystem normally mounted under it (e.g. debugfs) will be
50942 + mostly accessible only by root. These filesystems generally provide access
50943 + to hardware and debug information that isn't appropriate for unprivileged
50944 + users of the system. Sysfs and debugfs have also become a large source
50945 + of new vulnerabilities, ranging from infoleaks to local compromise.
50946 + There has been very little oversight with an eye toward security involved
50947 + in adding new exporters of information to these filesystems, so their
50948 + use is discouraged.
50949 + For reasons of compatibility, a few directories have been whitelisted
50950 + for access by non-root users:
50951 + /sys/fs/selinux
50952 + /sys/fs/fuse
50953 + /sys/devices/system/cpu
50954 +
50955 +config GRKERNSEC_ROFS
50956 + bool "Runtime read-only mount protection"
50957 + help
50958 + If you say Y here, a sysctl option with name "romount_protect" will
50959 + be created. By setting this option to 1 at runtime, filesystems
50960 + will be protected in the following ways:
50961 + * No new writable mounts will be allowed
50962 + * Existing read-only mounts won't be able to be remounted read/write
50963 + * Write operations will be denied on all block devices
50964 + This option acts independently of grsec_lock: once it is set to 1,
50965 + it cannot be turned off. Therefore, please be mindful of the resulting
50966 + behavior if this option is enabled in an init script on a read-only
50967 + filesystem. This feature is mainly intended for secure embedded systems.
50968 +
50969 +config GRKERNSEC_CHROOT
50970 + bool "Chroot jail restrictions"
50971 + default y if GRKERNSEC_CONFIG_AUTO
50972 + help
50973 + If you say Y here, you will be able to choose several options that will
50974 + make breaking out of a chrooted jail much more difficult. If you
50975 + encounter no software incompatibilities with the following options, it
50976 + is recommended that you enable each one.
50977 +
50978 +config GRKERNSEC_CHROOT_MOUNT
50979 + bool "Deny mounts"
50980 + default y if GRKERNSEC_CONFIG_AUTO
50981 + depends on GRKERNSEC_CHROOT
50982 + help
50983 + If you say Y here, processes inside a chroot will not be able to
50984 + mount or remount filesystems. If the sysctl option is enabled, a
50985 + sysctl option with name "chroot_deny_mount" is created.
50986 +
50987 +config GRKERNSEC_CHROOT_DOUBLE
50988 + bool "Deny double-chroots"
50989 + default y if GRKERNSEC_CONFIG_AUTO
50990 + depends on GRKERNSEC_CHROOT
50991 + help
50992 + If you say Y here, processes inside a chroot will not be able to chroot
50993 + again outside the chroot. This is a widely used method of breaking
50994 + out of a chroot jail and should not be allowed. If the sysctl
50995 + option is enabled, a sysctl option with name
50996 + "chroot_deny_chroot" is created.
50997 +
50998 +config GRKERNSEC_CHROOT_PIVOT
50999 + bool "Deny pivot_root in chroot"
51000 + default y if GRKERNSEC_CONFIG_AUTO
51001 + depends on GRKERNSEC_CHROOT
51002 + help
51003 + If you say Y here, processes inside a chroot will not be able to use
51004 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51005 + works similar to chroot in that it changes the root filesystem. This
51006 + function could be misused in a chrooted process to attempt to break out
51007 + of the chroot, and therefore should not be allowed. If the sysctl
51008 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51009 + created.
51010 +
51011 +config GRKERNSEC_CHROOT_CHDIR
51012 + bool "Enforce chdir(\"/\") on all chroots"
51013 + default y if GRKERNSEC_CONFIG_AUTO
51014 + depends on GRKERNSEC_CHROOT
51015 + help
51016 + If you say Y here, the current working directory of all newly-chrooted
51017 + applications will be set to the the root directory of the chroot.
51018 + The man page on chroot(2) states:
51019 + Note that this call does not change the current working
51020 + directory, so that `.' can be outside the tree rooted at
51021 + `/'. In particular, the super-user can escape from a
51022 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51023 +
51024 + It is recommended that you say Y here, since it's not known to break
51025 + any software. If the sysctl option is enabled, a sysctl option with
51026 + name "chroot_enforce_chdir" is created.
51027 +
51028 +config GRKERNSEC_CHROOT_CHMOD
51029 + bool "Deny (f)chmod +s"
51030 + default y if GRKERNSEC_CONFIG_AUTO
51031 + depends on GRKERNSEC_CHROOT
51032 + help
51033 + If you say Y here, processes inside a chroot will not be able to chmod
51034 + or fchmod files to make them have suid or sgid bits. This protects
51035 + against another published method of breaking a chroot. If the sysctl
51036 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51037 + created.
51038 +
51039 +config GRKERNSEC_CHROOT_FCHDIR
51040 + bool "Deny fchdir out of chroot"
51041 + default y if GRKERNSEC_CONFIG_AUTO
51042 + depends on GRKERNSEC_CHROOT
51043 + help
51044 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51045 + to a file descriptor of the chrooting process that points to a directory
51046 + outside the filesystem will be stopped. If the sysctl option
51047 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51048 +
51049 +config GRKERNSEC_CHROOT_MKNOD
51050 + bool "Deny mknod"
51051 + default y if GRKERNSEC_CONFIG_AUTO
51052 + depends on GRKERNSEC_CHROOT
51053 + help
51054 + If you say Y here, processes inside a chroot will not be allowed to
51055 + mknod. The problem with using mknod inside a chroot is that it
51056 + would allow an attacker to create a device entry that is the same
51057 + as one on the physical root of your system, which could range from
51058 + anything from the console device to a device for your harddrive (which
51059 + they could then use to wipe the drive or steal data). It is recommended
51060 + that you say Y here, unless you run into software incompatibilities.
51061 + If the sysctl option is enabled, a sysctl option with name
51062 + "chroot_deny_mknod" is created.
51063 +
51064 +config GRKERNSEC_CHROOT_SHMAT
51065 + bool "Deny shmat() out of chroot"
51066 + default y if GRKERNSEC_CONFIG_AUTO
51067 + depends on GRKERNSEC_CHROOT
51068 + help
51069 + If you say Y here, processes inside a chroot will not be able to attach
51070 + to shared memory segments that were created outside of the chroot jail.
51071 + It is recommended that you say Y here. If the sysctl option is enabled,
51072 + a sysctl option with name "chroot_deny_shmat" is created.
51073 +
51074 +config GRKERNSEC_CHROOT_UNIX
51075 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51076 + default y if GRKERNSEC_CONFIG_AUTO
51077 + depends on GRKERNSEC_CHROOT
51078 + help
51079 + If you say Y here, processes inside a chroot will not be able to
51080 + connect to abstract (meaning not belonging to a filesystem) Unix
51081 + domain sockets that were bound outside of a chroot. It is recommended
51082 + that you say Y here. If the sysctl option is enabled, a sysctl option
51083 + with name "chroot_deny_unix" is created.
51084 +
51085 +config GRKERNSEC_CHROOT_FINDTASK
51086 + bool "Protect outside processes"
51087 + default y if GRKERNSEC_CONFIG_AUTO
51088 + depends on GRKERNSEC_CHROOT
51089 + help
51090 + If you say Y here, processes inside a chroot will not be able to
51091 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51092 + getsid, or view any process outside of the chroot. If the sysctl
51093 + option is enabled, a sysctl option with name "chroot_findtask" is
51094 + created.
51095 +
51096 +config GRKERNSEC_CHROOT_NICE
51097 + bool "Restrict priority changes"
51098 + default y if GRKERNSEC_CONFIG_AUTO
51099 + depends on GRKERNSEC_CHROOT
51100 + help
51101 + If you say Y here, processes inside a chroot will not be able to raise
51102 + the priority of processes in the chroot, or alter the priority of
51103 + processes outside the chroot. This provides more security than simply
51104 + removing CAP_SYS_NICE from the process' capability set. If the
51105 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51106 + is created.
51107 +
51108 +config GRKERNSEC_CHROOT_SYSCTL
51109 + bool "Deny sysctl writes"
51110 + default y if GRKERNSEC_CONFIG_AUTO
51111 + depends on GRKERNSEC_CHROOT
51112 + help
51113 + If you say Y here, an attacker in a chroot will not be able to
51114 + write to sysctl entries, either by sysctl(2) or through a /proc
51115 + interface. It is strongly recommended that you say Y here. If the
51116 + sysctl option is enabled, a sysctl option with name
51117 + "chroot_deny_sysctl" is created.
51118 +
51119 +config GRKERNSEC_CHROOT_CAPS
51120 + bool "Capability restrictions"
51121 + default y if GRKERNSEC_CONFIG_AUTO
51122 + depends on GRKERNSEC_CHROOT
51123 + help
51124 + If you say Y here, the capabilities on all processes within a
51125 + chroot jail will be lowered to stop module insertion, raw i/o,
51126 + system and net admin tasks, rebooting the system, modifying immutable
51127 + files, modifying IPC owned by another, and changing the system time.
51128 + This is left an option because it can break some apps. Disable this
51129 + if your chrooted apps are having problems performing those kinds of
51130 + tasks. If the sysctl option is enabled, a sysctl option with
51131 + name "chroot_caps" is created.
51132 +
51133 +endmenu
51134 +menu "Kernel Auditing"
51135 +depends on GRKERNSEC
51136 +
51137 +config GRKERNSEC_AUDIT_GROUP
51138 + bool "Single group for auditing"
51139 + help
51140 + If you say Y here, the exec, chdir, and (un)mount logging features
51141 + will only operate on a group you specify. This option is recommended
51142 + if you only want to watch certain users instead of having a large
51143 + amount of logs from the entire system. If the sysctl option is enabled,
51144 + a sysctl option with name "audit_group" is created.
51145 +
51146 +config GRKERNSEC_AUDIT_GID
51147 + int "GID for auditing"
51148 + depends on GRKERNSEC_AUDIT_GROUP
51149 + default 1007
51150 +
51151 +config GRKERNSEC_EXECLOG
51152 + bool "Exec logging"
51153 + help
51154 + If you say Y here, all execve() calls will be logged (since the
51155 + other exec*() calls are frontends to execve(), all execution
51156 + will be logged). Useful for shell-servers that like to keep track
51157 + of their users. If the sysctl option is enabled, a sysctl option with
51158 + name "exec_logging" is created.
51159 + WARNING: This option when enabled will produce a LOT of logs, especially
51160 + on an active system.
51161 +
51162 +config GRKERNSEC_RESLOG
51163 + bool "Resource logging"
51164 + default y if GRKERNSEC_CONFIG_AUTO
51165 + help
51166 + If you say Y here, all attempts to overstep resource limits will
51167 + be logged with the resource name, the requested size, and the current
51168 + limit. It is highly recommended that you say Y here. If the sysctl
51169 + option is enabled, a sysctl option with name "resource_logging" is
51170 + created. If the RBAC system is enabled, the sysctl value is ignored.
51171 +
51172 +config GRKERNSEC_CHROOT_EXECLOG
51173 + bool "Log execs within chroot"
51174 + help
51175 + If you say Y here, all executions inside a chroot jail will be logged
51176 + to syslog. This can cause a large amount of logs if certain
51177 + applications (eg. djb's daemontools) are installed on the system, and
51178 + is therefore left as an option. If the sysctl option is enabled, a
51179 + sysctl option with name "chroot_execlog" is created.
51180 +
51181 +config GRKERNSEC_AUDIT_PTRACE
51182 + bool "Ptrace logging"
51183 + help
51184 + If you say Y here, all attempts to attach to a process via ptrace
51185 + will be logged. If the sysctl option is enabled, a sysctl option
51186 + with name "audit_ptrace" is created.
51187 +
51188 +config GRKERNSEC_AUDIT_CHDIR
51189 + bool "Chdir logging"
51190 + help
51191 + If you say Y here, all chdir() calls will be logged. If the sysctl
51192 + option is enabled, a sysctl option with name "audit_chdir" is created.
51193 +
51194 +config GRKERNSEC_AUDIT_MOUNT
51195 + bool "(Un)Mount logging"
51196 + help
51197 + If you say Y here, all mounts and unmounts will be logged. If the
51198 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51199 + created.
51200 +
51201 +config GRKERNSEC_SIGNAL
51202 + bool "Signal logging"
51203 + default y if GRKERNSEC_CONFIG_AUTO
51204 + help
51205 + If you say Y here, certain important signals will be logged, such as
51206 + SIGSEGV, which will as a result inform you of when a error in a program
51207 + occurred, which in some cases could mean a possible exploit attempt.
51208 + If the sysctl option is enabled, a sysctl option with name
51209 + "signal_logging" is created.
51210 +
51211 +config GRKERNSEC_FORKFAIL
51212 + bool "Fork failure logging"
51213 + help
51214 + If you say Y here, all failed fork() attempts will be logged.
51215 + This could suggest a fork bomb, or someone attempting to overstep
51216 + their process limit. If the sysctl option is enabled, a sysctl option
51217 + with name "forkfail_logging" is created.
51218 +
51219 +config GRKERNSEC_TIME
51220 + bool "Time change logging"
51221 + default y if GRKERNSEC_CONFIG_AUTO
51222 + help
51223 + If you say Y here, any changes of the system clock will be logged.
51224 + If the sysctl option is enabled, a sysctl option with name
51225 + "timechange_logging" is created.
51226 +
51227 +config GRKERNSEC_PROC_IPADDR
51228 + bool "/proc/<pid>/ipaddr support"
51229 + default y if GRKERNSEC_CONFIG_AUTO
51230 + help
51231 + If you say Y here, a new entry will be added to each /proc/<pid>
51232 + directory that contains the IP address of the person using the task.
51233 + The IP is carried across local TCP and AF_UNIX stream sockets.
51234 + This information can be useful for IDS/IPSes to perform remote response
51235 + to a local attack. The entry is readable by only the owner of the
51236 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51237 + the RBAC system), and thus does not create privacy concerns.
51238 +
51239 +config GRKERNSEC_RWXMAP_LOG
51240 + bool 'Denied RWX mmap/mprotect logging'
51241 + default y if GRKERNSEC_CONFIG_AUTO
51242 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51243 + help
51244 + If you say Y here, calls to mmap() and mprotect() with explicit
51245 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51246 + denied by the PAX_MPROTECT feature. If the sysctl option is
51247 + enabled, a sysctl option with name "rwxmap_logging" is created.
51248 +
51249 +config GRKERNSEC_AUDIT_TEXTREL
51250 + bool 'ELF text relocations logging (READ HELP)'
51251 + depends on PAX_MPROTECT
51252 + help
51253 + If you say Y here, text relocations will be logged with the filename
51254 + of the offending library or binary. The purpose of the feature is
51255 + to help Linux distribution developers get rid of libraries and
51256 + binaries that need text relocations which hinder the future progress
51257 + of PaX. Only Linux distribution developers should say Y here, and
51258 + never on a production machine, as this option creates an information
51259 + leak that could aid an attacker in defeating the randomization of
51260 + a single memory region. If the sysctl option is enabled, a sysctl
51261 + option with name "audit_textrel" is created.
51262 +
51263 +endmenu
51264 +
51265 +menu "Executable Protections"
51266 +depends on GRKERNSEC
51267 +
51268 +config GRKERNSEC_DMESG
51269 + bool "Dmesg(8) restriction"
51270 + default y if GRKERNSEC_CONFIG_AUTO
51271 + help
51272 + If you say Y here, non-root users will not be able to use dmesg(8)
51273 + to view up to the last 4kb of messages in the kernel's log buffer.
51274 + The kernel's log buffer often contains kernel addresses and other
51275 + identifying information useful to an attacker in fingerprinting a
51276 + system for a targeted exploit.
51277 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51278 + created.
51279 +
51280 +config GRKERNSEC_HARDEN_PTRACE
51281 + bool "Deter ptrace-based process snooping"
51282 + default y if GRKERNSEC_CONFIG_AUTO
51283 + help
51284 + If you say Y here, TTY sniffers and other malicious monitoring
51285 + programs implemented through ptrace will be defeated. If you
51286 + have been using the RBAC system, this option has already been
51287 + enabled for several years for all users, with the ability to make
51288 + fine-grained exceptions.
51289 +
51290 + This option only affects the ability of non-root users to ptrace
51291 + processes that are not a descendent of the ptracing process.
51292 + This means that strace ./binary and gdb ./binary will still work,
51293 + but attaching to arbitrary processes will not. If the sysctl
51294 + option is enabled, a sysctl option with name "harden_ptrace" is
51295 + created.
51296 +
51297 +config GRKERNSEC_PTRACE_READEXEC
51298 + bool "Require read access to ptrace sensitive binaries"
51299 + default y if GRKERNSEC_CONFIG_AUTO
51300 + help
51301 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51302 + binaries. This option is useful in environments that
51303 + remove the read bits (e.g. file mode 4711) from suid binaries to
51304 + prevent infoleaking of their contents. This option adds
51305 + consistency to the use of that file mode, as the binary could normally
51306 + be read out when run without privileges while ptracing.
51307 +
51308 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51309 + is created.
51310 +
51311 +config GRKERNSEC_SETXID
51312 + bool "Enforce consistent multithreaded privileges"
51313 + default y if GRKERNSEC_CONFIG_AUTO
51314 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51315 + help
51316 + If you say Y here, a change from a root uid to a non-root uid
51317 + in a multithreaded application will cause the resulting uids,
51318 + gids, supplementary groups, and capabilities in that thread
51319 + to be propagated to the other threads of the process. In most
51320 + cases this is unnecessary, as glibc will emulate this behavior
51321 + on behalf of the application. Other libcs do not act in the
51322 + same way, allowing the other threads of the process to continue
51323 + running with root privileges. If the sysctl option is enabled,
51324 + a sysctl option with name "consistent_setxid" is created.
51325 +
51326 +config GRKERNSEC_TPE
51327 + bool "Trusted Path Execution (TPE)"
51328 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51329 + help
51330 + If you say Y here, you will be able to choose a gid to add to the
51331 + supplementary groups of users you want to mark as "untrusted."
51332 + These users will not be able to execute any files that are not in
51333 + root-owned directories writable only by root. If the sysctl option
51334 + is enabled, a sysctl option with name "tpe" is created.
51335 +
51336 +config GRKERNSEC_TPE_ALL
51337 + bool "Partially restrict all non-root users"
51338 + depends on GRKERNSEC_TPE
51339 + help
51340 + If you say Y here, all non-root users will be covered under
51341 + a weaker TPE restriction. This is separate from, and in addition to,
51342 + the main TPE options that you have selected elsewhere. Thus, if a
51343 + "trusted" GID is chosen, this restriction applies to even that GID.
51344 + Under this restriction, all non-root users will only be allowed to
51345 + execute files in directories they own that are not group or
51346 + world-writable, or in directories owned by root and writable only by
51347 + root. If the sysctl option is enabled, a sysctl option with name
51348 + "tpe_restrict_all" is created.
51349 +
51350 +config GRKERNSEC_TPE_INVERT
51351 + bool "Invert GID option"
51352 + depends on GRKERNSEC_TPE
51353 + help
51354 + If you say Y here, the group you specify in the TPE configuration will
51355 + decide what group TPE restrictions will be *disabled* for. This
51356 + option is useful if you want TPE restrictions to be applied to most
51357 + users on the system. If the sysctl option is enabled, a sysctl option
51358 + with name "tpe_invert" is created. Unlike other sysctl options, this
51359 + entry will default to on for backward-compatibility.
51360 +
51361 +config GRKERNSEC_TPE_GID
51362 + int
51363 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51364 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51365 +
51366 +config GRKERNSEC_TPE_UNTRUSTED_GID
51367 + int "GID for TPE-untrusted users"
51368 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51369 + default 1005
51370 + help
51371 + Setting this GID determines what group TPE restrictions will be
51372 + *enabled* for. If the sysctl option is enabled, a sysctl option
51373 + with name "tpe_gid" is created.
51374 +
51375 +config GRKERNSEC_TPE_TRUSTED_GID
51376 + int "GID for TPE-trusted users"
51377 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51378 + default 1005
51379 + help
51380 + Setting this GID determines what group TPE restrictions will be
51381 + *disabled* for. If the sysctl option is enabled, a sysctl option
51382 + with name "tpe_gid" is created.
51383 +
51384 +endmenu
51385 +menu "Network Protections"
51386 +depends on GRKERNSEC
51387 +
51388 +config GRKERNSEC_RANDNET
51389 + bool "Larger entropy pools"
51390 + default y if GRKERNSEC_CONFIG_AUTO
51391 + help
51392 + If you say Y here, the entropy pools used for many features of Linux
51393 + and grsecurity will be doubled in size. Since several grsecurity
51394 + features use additional randomness, it is recommended that you say Y
51395 + here. Saying Y here has a similar effect as modifying
51396 + /proc/sys/kernel/random/poolsize.
51397 +
51398 +config GRKERNSEC_BLACKHOLE
51399 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51400 + default y if GRKERNSEC_CONFIG_AUTO
51401 + depends on NET
51402 + help
51403 + If you say Y here, neither TCP resets nor ICMP
51404 + destination-unreachable packets will be sent in response to packets
51405 + sent to ports for which no associated listening process exists.
51406 + This feature supports both IPV4 and IPV6 and exempts the
51407 + loopback interface from blackholing. Enabling this feature
51408 + makes a host more resilient to DoS attacks and reduces network
51409 + visibility against scanners.
51410 +
51411 + The blackhole feature as-implemented is equivalent to the FreeBSD
51412 + blackhole feature, as it prevents RST responses to all packets, not
51413 + just SYNs. Under most application behavior this causes no
51414 + problems, but applications (like haproxy) may not close certain
51415 + connections in a way that cleanly terminates them on the remote
51416 + end, leaving the remote host in LAST_ACK state. Because of this
51417 + side-effect and to prevent intentional LAST_ACK DoSes, this
51418 + feature also adds automatic mitigation against such attacks.
51419 + The mitigation drastically reduces the amount of time a socket
51420 + can spend in LAST_ACK state. If you're using haproxy and not
51421 + all servers it connects to have this option enabled, consider
51422 + disabling this feature on the haproxy host.
51423 +
51424 + If the sysctl option is enabled, two sysctl options with names
51425 + "ip_blackhole" and "lastack_retries" will be created.
51426 + While "ip_blackhole" takes the standard zero/non-zero on/off
51427 + toggle, "lastack_retries" uses the same kinds of values as
51428 + "tcp_retries1" and "tcp_retries2". The default value of 4
51429 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51430 + state.
51431 +
51432 +config GRKERNSEC_SOCKET
51433 + bool "Socket restrictions"
51434 + depends on NET
51435 + help
51436 + If you say Y here, you will be able to choose from several options.
51437 + If you assign a GID on your system and add it to the supplementary
51438 + groups of users you want to restrict socket access to, this patch
51439 + will perform up to three things, based on the option(s) you choose.
51440 +
51441 +config GRKERNSEC_SOCKET_ALL
51442 + bool "Deny any sockets to group"
51443 + depends on GRKERNSEC_SOCKET
51444 + help
51445 + If you say Y here, you will be able to choose a GID of whose users will
51446 + be unable to connect to other hosts from your machine or run server
51447 + applications from your machine. If the sysctl option is enabled, a
51448 + sysctl option with name "socket_all" is created.
51449 +
51450 +config GRKERNSEC_SOCKET_ALL_GID
51451 + int "GID to deny all sockets for"
51452 + depends on GRKERNSEC_SOCKET_ALL
51453 + default 1004
51454 + help
51455 + Here you can choose the GID to disable socket access for. Remember to
51456 + add the users you want socket access disabled for to the GID
51457 + specified here. If the sysctl option is enabled, a sysctl option
51458 + with name "socket_all_gid" is created.
51459 +
51460 +config GRKERNSEC_SOCKET_CLIENT
51461 + bool "Deny client sockets to group"
51462 + depends on GRKERNSEC_SOCKET
51463 + help
51464 + If you say Y here, you will be able to choose a GID of whose users will
51465 + be unable to connect to other hosts from your machine, but will be
51466 + able to run servers. If this option is enabled, all users in the group
51467 + you specify will have to use passive mode when initiating ftp transfers
51468 + from the shell on your machine. If the sysctl option is enabled, a
51469 + sysctl option with name "socket_client" is created.
51470 +
51471 +config GRKERNSEC_SOCKET_CLIENT_GID
51472 + int "GID to deny client sockets for"
51473 + depends on GRKERNSEC_SOCKET_CLIENT
51474 + default 1003
51475 + help
51476 + Here you can choose the GID to disable client socket access for.
51477 + Remember to add the users you want client socket access disabled for to
51478 + the GID specified here. If the sysctl option is enabled, a sysctl
51479 + option with name "socket_client_gid" is created.
51480 +
51481 +config GRKERNSEC_SOCKET_SERVER
51482 + bool "Deny server sockets to group"
51483 + depends on GRKERNSEC_SOCKET
51484 + help
51485 + If you say Y here, you will be able to choose a GID of whose users will
51486 + be unable to run server applications from your machine. If the sysctl
51487 + option is enabled, a sysctl option with name "socket_server" is created.
51488 +
51489 +config GRKERNSEC_SOCKET_SERVER_GID
51490 + int "GID to deny server sockets for"
51491 + depends on GRKERNSEC_SOCKET_SERVER
51492 + default 1002
51493 + help
51494 + Here you can choose the GID to disable server socket access for.
51495 + Remember to add the users you want server socket access disabled for to
51496 + the GID specified here. If the sysctl option is enabled, a sysctl
51497 + option with name "socket_server_gid" is created.
51498 +
51499 +endmenu
51500 +menu "Sysctl Support"
51501 +depends on GRKERNSEC && SYSCTL
51502 +
51503 +config GRKERNSEC_SYSCTL
51504 + bool "Sysctl support"
51505 + default y if GRKERNSEC_CONFIG_AUTO
51506 + help
51507 + If you say Y here, you will be able to change the options that
51508 + grsecurity runs with at bootup, without having to recompile your
51509 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51510 + to enable (1) or disable (0) various features. All the sysctl entries
51511 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51512 + All features enabled in the kernel configuration are disabled at boot
51513 + if you do not say Y to the "Turn on features by default" option.
51514 + All options should be set at startup, and the grsec_lock entry should
51515 + be set to a non-zero value after all the options are set.
51516 + *THIS IS EXTREMELY IMPORTANT*
51517 +
51518 +config GRKERNSEC_SYSCTL_DISTRO
51519 + bool "Extra sysctl support for distro makers (READ HELP)"
51520 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51521 + help
51522 + If you say Y here, additional sysctl options will be created
51523 + for features that affect processes running as root. Therefore,
51524 + it is critical when using this option that the grsec_lock entry be
51525 + enabled after boot. Only distros with prebuilt kernel packages
51526 + with this option enabled that can ensure grsec_lock is enabled
51527 + after boot should use this option.
51528 + *Failure to set grsec_lock after boot makes all grsec features
51529 + this option covers useless*
51530 +
51531 + Currently this option creates the following sysctl entries:
51532 + "Disable Privileged I/O": "disable_priv_io"
51533 +
51534 +config GRKERNSEC_SYSCTL_ON
51535 + bool "Turn on features by default"
51536 + default y if GRKERNSEC_CONFIG_AUTO
51537 + depends on GRKERNSEC_SYSCTL
51538 + help
51539 + If you say Y here, instead of having all features enabled in the
51540 + kernel configuration disabled at boot time, the features will be
51541 + enabled at boot time. It is recommended you say Y here unless
51542 + there is some reason you would want all sysctl-tunable features to
51543 + be disabled by default. As mentioned elsewhere, it is important
51544 + to enable the grsec_lock entry once you have finished modifying
51545 + the sysctl entries.
51546 +
51547 +endmenu
51548 +menu "Logging Options"
51549 +depends on GRKERNSEC
51550 +
51551 +config GRKERNSEC_FLOODTIME
51552 + int "Seconds in between log messages (minimum)"
51553 + default 10
51554 + help
51555 + This option allows you to enforce the number of seconds between
51556 + grsecurity log messages. The default should be suitable for most
51557 + people, however, if you choose to change it, choose a value small enough
51558 + to allow informative logs to be produced, but large enough to
51559 + prevent flooding.
51560 +
51561 +config GRKERNSEC_FLOODBURST
51562 + int "Number of messages in a burst (maximum)"
51563 + default 6
51564 + help
51565 + This option allows you to choose the maximum number of messages allowed
51566 + within the flood time interval you chose in a separate option. The
51567 + default should be suitable for most people, however if you find that
51568 + many of your logs are being interpreted as flooding, you may want to
51569 + raise this value.
51570 +
51571 +endmenu
51572 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51573 new file mode 100644
51574 index 0000000..1b9afa9
51575 --- /dev/null
51576 +++ b/grsecurity/Makefile
51577 @@ -0,0 +1,38 @@
51578 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51579 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51580 +# into an RBAC system
51581 +#
51582 +# All code in this directory and various hooks inserted throughout the kernel
51583 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51584 +# under the GPL v2 or higher
51585 +
51586 +KBUILD_CFLAGS += -Werror
51587 +
51588 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51589 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51590 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51591 +
51592 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51593 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51594 + gracl_learn.o grsec_log.o
51595 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51596 +
51597 +ifdef CONFIG_NET
51598 +obj-y += grsec_sock.o
51599 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51600 +endif
51601 +
51602 +ifndef CONFIG_GRKERNSEC
51603 +obj-y += grsec_disabled.o
51604 +endif
51605 +
51606 +ifdef CONFIG_GRKERNSEC_HIDESYM
51607 +extra-y := grsec_hidesym.o
51608 +$(obj)/grsec_hidesym.o:
51609 + @-chmod -f 500 /boot
51610 + @-chmod -f 500 /lib/modules
51611 + @-chmod -f 500 /lib64/modules
51612 + @-chmod -f 500 /lib32/modules
51613 + @-chmod -f 700 .
51614 + @echo ' grsec: protected kernel image paths'
51615 +endif
51616 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51617 new file mode 100644
51618 index 0000000..b1810d9
51619 --- /dev/null
51620 +++ b/grsecurity/gracl.c
51621 @@ -0,0 +1,4056 @@
51622 +#include <linux/kernel.h>
51623 +#include <linux/module.h>
51624 +#include <linux/sched.h>
51625 +#include <linux/mm.h>
51626 +#include <linux/file.h>
51627 +#include <linux/fs.h>
51628 +#include <linux/namei.h>
51629 +#include <linux/mount.h>
51630 +#include <linux/tty.h>
51631 +#include <linux/proc_fs.h>
51632 +#include <linux/lglock.h>
51633 +#include <linux/slab.h>
51634 +#include <linux/vmalloc.h>
51635 +#include <linux/types.h>
51636 +#include <linux/sysctl.h>
51637 +#include <linux/netdevice.h>
51638 +#include <linux/ptrace.h>
51639 +#include <linux/gracl.h>
51640 +#include <linux/gralloc.h>
51641 +#include <linux/security.h>
51642 +#include <linux/grinternal.h>
51643 +#include <linux/pid_namespace.h>
51644 +#include <linux/stop_machine.h>
51645 +#include <linux/fdtable.h>
51646 +#include <linux/percpu.h>
51647 +#include <linux/lglock.h>
51648 +#include "../fs/mount.h"
51649 +
51650 +#include <asm/uaccess.h>
51651 +#include <asm/errno.h>
51652 +#include <asm/mman.h>
51653 +
51654 +extern struct lglock vfsmount_lock;
51655 +
51656 +static struct acl_role_db acl_role_set;
51657 +static struct name_db name_set;
51658 +static struct inodev_db inodev_set;
51659 +
51660 +/* for keeping track of userspace pointers used for subjects, so we
51661 + can share references in the kernel as well
51662 +*/
51663 +
51664 +static struct path real_root;
51665 +
51666 +static struct acl_subj_map_db subj_map_set;
51667 +
51668 +static struct acl_role_label *default_role;
51669 +
51670 +static struct acl_role_label *role_list;
51671 +
51672 +static u16 acl_sp_role_value;
51673 +
51674 +extern char *gr_shared_page[4];
51675 +static DEFINE_MUTEX(gr_dev_mutex);
51676 +DEFINE_RWLOCK(gr_inode_lock);
51677 +
51678 +struct gr_arg *gr_usermode;
51679 +
51680 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51681 +
51682 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51683 +extern void gr_clear_learn_entries(void);
51684 +
51685 +#ifdef CONFIG_GRKERNSEC_RESLOG
51686 +extern void gr_log_resource(const struct task_struct *task,
51687 + const int res, const unsigned long wanted, const int gt);
51688 +#endif
51689 +
51690 +unsigned char *gr_system_salt;
51691 +unsigned char *gr_system_sum;
51692 +
51693 +static struct sprole_pw **acl_special_roles = NULL;
51694 +static __u16 num_sprole_pws = 0;
51695 +
51696 +static struct acl_role_label *kernel_role = NULL;
51697 +
51698 +static unsigned int gr_auth_attempts = 0;
51699 +static unsigned long gr_auth_expires = 0UL;
51700 +
51701 +#ifdef CONFIG_NET
51702 +extern struct vfsmount *sock_mnt;
51703 +#endif
51704 +
51705 +extern struct vfsmount *pipe_mnt;
51706 +extern struct vfsmount *shm_mnt;
51707 +#ifdef CONFIG_HUGETLBFS
51708 +extern struct vfsmount *hugetlbfs_vfsmount;
51709 +#endif
51710 +
51711 +static struct acl_object_label *fakefs_obj_rw;
51712 +static struct acl_object_label *fakefs_obj_rwx;
51713 +
51714 +extern int gr_init_uidset(void);
51715 +extern void gr_free_uidset(void);
51716 +extern void gr_remove_uid(uid_t uid);
51717 +extern int gr_find_uid(uid_t uid);
51718 +
51719 +__inline__ int
51720 +gr_acl_is_enabled(void)
51721 +{
51722 + return (gr_status & GR_READY);
51723 +}
51724 +
51725 +#ifdef CONFIG_BTRFS_FS
51726 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51727 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51728 +#endif
51729 +
51730 +static inline dev_t __get_dev(const struct dentry *dentry)
51731 +{
51732 +#ifdef CONFIG_BTRFS_FS
51733 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51734 + return get_btrfs_dev_from_inode(dentry->d_inode);
51735 + else
51736 +#endif
51737 + return dentry->d_inode->i_sb->s_dev;
51738 +}
51739 +
51740 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51741 +{
51742 + return __get_dev(dentry);
51743 +}
51744 +
51745 +static char gr_task_roletype_to_char(struct task_struct *task)
51746 +{
51747 + switch (task->role->roletype &
51748 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51749 + GR_ROLE_SPECIAL)) {
51750 + case GR_ROLE_DEFAULT:
51751 + return 'D';
51752 + case GR_ROLE_USER:
51753 + return 'U';
51754 + case GR_ROLE_GROUP:
51755 + return 'G';
51756 + case GR_ROLE_SPECIAL:
51757 + return 'S';
51758 + }
51759 +
51760 + return 'X';
51761 +}
51762 +
51763 +char gr_roletype_to_char(void)
51764 +{
51765 + return gr_task_roletype_to_char(current);
51766 +}
51767 +
51768 +__inline__ int
51769 +gr_acl_tpe_check(void)
51770 +{
51771 + if (unlikely(!(gr_status & GR_READY)))
51772 + return 0;
51773 + if (current->role->roletype & GR_ROLE_TPE)
51774 + return 1;
51775 + else
51776 + return 0;
51777 +}
51778 +
51779 +int
51780 +gr_handle_rawio(const struct inode *inode)
51781 +{
51782 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51783 + if (inode && S_ISBLK(inode->i_mode) &&
51784 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51785 + !capable(CAP_SYS_RAWIO))
51786 + return 1;
51787 +#endif
51788 + return 0;
51789 +}
51790 +
51791 +static int
51792 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51793 +{
51794 + if (likely(lena != lenb))
51795 + return 0;
51796 +
51797 + return !memcmp(a, b, lena);
51798 +}
51799 +
51800 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51801 +{
51802 + *buflen -= namelen;
51803 + if (*buflen < 0)
51804 + return -ENAMETOOLONG;
51805 + *buffer -= namelen;
51806 + memcpy(*buffer, str, namelen);
51807 + return 0;
51808 +}
51809 +
51810 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51811 +{
51812 + return prepend(buffer, buflen, name->name, name->len);
51813 +}
51814 +
51815 +static int prepend_path(const struct path *path, struct path *root,
51816 + char **buffer, int *buflen)
51817 +{
51818 + struct dentry *dentry = path->dentry;
51819 + struct vfsmount *vfsmnt = path->mnt;
51820 + struct mount *mnt = real_mount(vfsmnt);
51821 + bool slash = false;
51822 + int error = 0;
51823 +
51824 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51825 + struct dentry * parent;
51826 +
51827 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51828 + /* Global root? */
51829 + if (!mnt_has_parent(mnt)) {
51830 + goto out;
51831 + }
51832 + dentry = mnt->mnt_mountpoint;
51833 + mnt = mnt->mnt_parent;
51834 + vfsmnt = &mnt->mnt;
51835 + continue;
51836 + }
51837 + parent = dentry->d_parent;
51838 + prefetch(parent);
51839 + spin_lock(&dentry->d_lock);
51840 + error = prepend_name(buffer, buflen, &dentry->d_name);
51841 + spin_unlock(&dentry->d_lock);
51842 + if (!error)
51843 + error = prepend(buffer, buflen, "/", 1);
51844 + if (error)
51845 + break;
51846 +
51847 + slash = true;
51848 + dentry = parent;
51849 + }
51850 +
51851 +out:
51852 + if (!error && !slash)
51853 + error = prepend(buffer, buflen, "/", 1);
51854 +
51855 + return error;
51856 +}
51857 +
51858 +/* this must be called with vfsmount_lock and rename_lock held */
51859 +
51860 +static char *__our_d_path(const struct path *path, struct path *root,
51861 + char *buf, int buflen)
51862 +{
51863 + char *res = buf + buflen;
51864 + int error;
51865 +
51866 + prepend(&res, &buflen, "\0", 1);
51867 + error = prepend_path(path, root, &res, &buflen);
51868 + if (error)
51869 + return ERR_PTR(error);
51870 +
51871 + return res;
51872 +}
51873 +
51874 +static char *
51875 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51876 +{
51877 + char *retval;
51878 +
51879 + retval = __our_d_path(path, root, buf, buflen);
51880 + if (unlikely(IS_ERR(retval)))
51881 + retval = strcpy(buf, "<path too long>");
51882 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51883 + retval[1] = '\0';
51884 +
51885 + return retval;
51886 +}
51887 +
51888 +static char *
51889 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51890 + char *buf, int buflen)
51891 +{
51892 + struct path path;
51893 + char *res;
51894 +
51895 + path.dentry = (struct dentry *)dentry;
51896 + path.mnt = (struct vfsmount *)vfsmnt;
51897 +
51898 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51899 + by the RBAC system */
51900 + res = gen_full_path(&path, &real_root, buf, buflen);
51901 +
51902 + return res;
51903 +}
51904 +
51905 +static char *
51906 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51907 + char *buf, int buflen)
51908 +{
51909 + char *res;
51910 + struct path path;
51911 + struct path root;
51912 + struct task_struct *reaper = init_pid_ns.child_reaper;
51913 +
51914 + path.dentry = (struct dentry *)dentry;
51915 + path.mnt = (struct vfsmount *)vfsmnt;
51916 +
51917 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51918 + get_fs_root(reaper->fs, &root);
51919 +
51920 + write_seqlock(&rename_lock);
51921 + br_read_lock(&vfsmount_lock);
51922 + res = gen_full_path(&path, &root, buf, buflen);
51923 + br_read_unlock(&vfsmount_lock);
51924 + write_sequnlock(&rename_lock);
51925 +
51926 + path_put(&root);
51927 + return res;
51928 +}
51929 +
51930 +static char *
51931 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51932 +{
51933 + char *ret;
51934 + write_seqlock(&rename_lock);
51935 + br_read_lock(&vfsmount_lock);
51936 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51937 + PAGE_SIZE);
51938 + br_read_unlock(&vfsmount_lock);
51939 + write_sequnlock(&rename_lock);
51940 + return ret;
51941 +}
51942 +
51943 +static char *
51944 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51945 +{
51946 + char *ret;
51947 + char *buf;
51948 + int buflen;
51949 +
51950 + write_seqlock(&rename_lock);
51951 + br_read_lock(&vfsmount_lock);
51952 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51953 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51954 + buflen = (int)(ret - buf);
51955 + if (buflen >= 5)
51956 + prepend(&ret, &buflen, "/proc", 5);
51957 + else
51958 + ret = strcpy(buf, "<path too long>");
51959 + br_read_unlock(&vfsmount_lock);
51960 + write_sequnlock(&rename_lock);
51961 + return ret;
51962 +}
51963 +
51964 +char *
51965 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51966 +{
51967 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51968 + PAGE_SIZE);
51969 +}
51970 +
51971 +char *
51972 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51973 +{
51974 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51975 + PAGE_SIZE);
51976 +}
51977 +
51978 +char *
51979 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51980 +{
51981 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51982 + PAGE_SIZE);
51983 +}
51984 +
51985 +char *
51986 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51987 +{
51988 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51989 + PAGE_SIZE);
51990 +}
51991 +
51992 +char *
51993 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51994 +{
51995 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51996 + PAGE_SIZE);
51997 +}
51998 +
51999 +__inline__ __u32
52000 +to_gr_audit(const __u32 reqmode)
52001 +{
52002 + /* masks off auditable permission flags, then shifts them to create
52003 + auditing flags, and adds the special case of append auditing if
52004 + we're requesting write */
52005 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52006 +}
52007 +
52008 +struct acl_subject_label *
52009 +lookup_subject_map(const struct acl_subject_label *userp)
52010 +{
52011 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
52012 + struct subject_map *match;
52013 +
52014 + match = subj_map_set.s_hash[index];
52015 +
52016 + while (match && match->user != userp)
52017 + match = match->next;
52018 +
52019 + if (match != NULL)
52020 + return match->kernel;
52021 + else
52022 + return NULL;
52023 +}
52024 +
52025 +static void
52026 +insert_subj_map_entry(struct subject_map *subjmap)
52027 +{
52028 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
52029 + struct subject_map **curr;
52030 +
52031 + subjmap->prev = NULL;
52032 +
52033 + curr = &subj_map_set.s_hash[index];
52034 + if (*curr != NULL)
52035 + (*curr)->prev = subjmap;
52036 +
52037 + subjmap->next = *curr;
52038 + *curr = subjmap;
52039 +
52040 + return;
52041 +}
52042 +
52043 +static struct acl_role_label *
52044 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52045 + const gid_t gid)
52046 +{
52047 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52048 + struct acl_role_label *match;
52049 + struct role_allowed_ip *ipp;
52050 + unsigned int x;
52051 + u32 curr_ip = task->signal->curr_ip;
52052 +
52053 + task->signal->saved_ip = curr_ip;
52054 +
52055 + match = acl_role_set.r_hash[index];
52056 +
52057 + while (match) {
52058 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52059 + for (x = 0; x < match->domain_child_num; x++) {
52060 + if (match->domain_children[x] == uid)
52061 + goto found;
52062 + }
52063 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52064 + break;
52065 + match = match->next;
52066 + }
52067 +found:
52068 + if (match == NULL) {
52069 + try_group:
52070 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52071 + match = acl_role_set.r_hash[index];
52072 +
52073 + while (match) {
52074 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52075 + for (x = 0; x < match->domain_child_num; x++) {
52076 + if (match->domain_children[x] == gid)
52077 + goto found2;
52078 + }
52079 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52080 + break;
52081 + match = match->next;
52082 + }
52083 +found2:
52084 + if (match == NULL)
52085 + match = default_role;
52086 + if (match->allowed_ips == NULL)
52087 + return match;
52088 + else {
52089 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52090 + if (likely
52091 + ((ntohl(curr_ip) & ipp->netmask) ==
52092 + (ntohl(ipp->addr) & ipp->netmask)))
52093 + return match;
52094 + }
52095 + match = default_role;
52096 + }
52097 + } else if (match->allowed_ips == NULL) {
52098 + return match;
52099 + } else {
52100 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52101 + if (likely
52102 + ((ntohl(curr_ip) & ipp->netmask) ==
52103 + (ntohl(ipp->addr) & ipp->netmask)))
52104 + return match;
52105 + }
52106 + goto try_group;
52107 + }
52108 +
52109 + return match;
52110 +}
52111 +
52112 +struct acl_subject_label *
52113 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52114 + const struct acl_role_label *role)
52115 +{
52116 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
52117 + struct acl_subject_label *match;
52118 +
52119 + match = role->subj_hash[index];
52120 +
52121 + while (match && (match->inode != ino || match->device != dev ||
52122 + (match->mode & GR_DELETED))) {
52123 + match = match->next;
52124 + }
52125 +
52126 + if (match && !(match->mode & GR_DELETED))
52127 + return match;
52128 + else
52129 + return NULL;
52130 +}
52131 +
52132 +struct acl_subject_label *
52133 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52134 + const struct acl_role_label *role)
52135 +{
52136 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
52137 + struct acl_subject_label *match;
52138 +
52139 + match = role->subj_hash[index];
52140 +
52141 + while (match && (match->inode != ino || match->device != dev ||
52142 + !(match->mode & GR_DELETED))) {
52143 + match = match->next;
52144 + }
52145 +
52146 + if (match && (match->mode & GR_DELETED))
52147 + return match;
52148 + else
52149 + return NULL;
52150 +}
52151 +
52152 +static struct acl_object_label *
52153 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52154 + const struct acl_subject_label *subj)
52155 +{
52156 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
52157 + struct acl_object_label *match;
52158 +
52159 + match = subj->obj_hash[index];
52160 +
52161 + while (match && (match->inode != ino || match->device != dev ||
52162 + (match->mode & GR_DELETED))) {
52163 + match = match->next;
52164 + }
52165 +
52166 + if (match && !(match->mode & GR_DELETED))
52167 + return match;
52168 + else
52169 + return NULL;
52170 +}
52171 +
52172 +static struct acl_object_label *
52173 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52174 + const struct acl_subject_label *subj)
52175 +{
52176 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
52177 + struct acl_object_label *match;
52178 +
52179 + match = subj->obj_hash[index];
52180 +
52181 + while (match && (match->inode != ino || match->device != dev ||
52182 + !(match->mode & GR_DELETED))) {
52183 + match = match->next;
52184 + }
52185 +
52186 + if (match && (match->mode & GR_DELETED))
52187 + return match;
52188 +
52189 + match = subj->obj_hash[index];
52190 +
52191 + while (match && (match->inode != ino || match->device != dev ||
52192 + (match->mode & GR_DELETED))) {
52193 + match = match->next;
52194 + }
52195 +
52196 + if (match && !(match->mode & GR_DELETED))
52197 + return match;
52198 + else
52199 + return NULL;
52200 +}
52201 +
52202 +static struct name_entry *
52203 +lookup_name_entry(const char *name)
52204 +{
52205 + unsigned int len = strlen(name);
52206 + unsigned int key = full_name_hash(name, len);
52207 + unsigned int index = key % name_set.n_size;
52208 + struct name_entry *match;
52209 +
52210 + match = name_set.n_hash[index];
52211 +
52212 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52213 + match = match->next;
52214 +
52215 + return match;
52216 +}
52217 +
52218 +static struct name_entry *
52219 +lookup_name_entry_create(const char *name)
52220 +{
52221 + unsigned int len = strlen(name);
52222 + unsigned int key = full_name_hash(name, len);
52223 + unsigned int index = key % name_set.n_size;
52224 + struct name_entry *match;
52225 +
52226 + match = name_set.n_hash[index];
52227 +
52228 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52229 + !match->deleted))
52230 + match = match->next;
52231 +
52232 + if (match && match->deleted)
52233 + return match;
52234 +
52235 + match = name_set.n_hash[index];
52236 +
52237 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52238 + match->deleted))
52239 + match = match->next;
52240 +
52241 + if (match && !match->deleted)
52242 + return match;
52243 + else
52244 + return NULL;
52245 +}
52246 +
52247 +static struct inodev_entry *
52248 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52249 +{
52250 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
52251 + struct inodev_entry *match;
52252 +
52253 + match = inodev_set.i_hash[index];
52254 +
52255 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52256 + match = match->next;
52257 +
52258 + return match;
52259 +}
52260 +
52261 +static void
52262 +insert_inodev_entry(struct inodev_entry *entry)
52263 +{
52264 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
52265 + inodev_set.i_size);
52266 + struct inodev_entry **curr;
52267 +
52268 + entry->prev = NULL;
52269 +
52270 + curr = &inodev_set.i_hash[index];
52271 + if (*curr != NULL)
52272 + (*curr)->prev = entry;
52273 +
52274 + entry->next = *curr;
52275 + *curr = entry;
52276 +
52277 + return;
52278 +}
52279 +
52280 +static void
52281 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52282 +{
52283 + unsigned int index =
52284 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52285 + struct acl_role_label **curr;
52286 + struct acl_role_label *tmp, *tmp2;
52287 +
52288 + curr = &acl_role_set.r_hash[index];
52289 +
52290 + /* simple case, slot is empty, just set it to our role */
52291 + if (*curr == NULL) {
52292 + *curr = role;
52293 + } else {
52294 + /* example:
52295 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52296 + 2 -> 3
52297 + */
52298 + /* first check to see if we can already be reached via this slot */
52299 + tmp = *curr;
52300 + while (tmp && tmp != role)
52301 + tmp = tmp->next;
52302 + if (tmp == role) {
52303 + /* we don't need to add ourselves to this slot's chain */
52304 + return;
52305 + }
52306 + /* we need to add ourselves to this chain, two cases */
52307 + if (role->next == NULL) {
52308 + /* simple case, append the current chain to our role */
52309 + role->next = *curr;
52310 + *curr = role;
52311 + } else {
52312 + /* 1 -> 2 -> 3 -> 4
52313 + 2 -> 3 -> 4
52314 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52315 + */
52316 + /* trickier case: walk our role's chain until we find
52317 + the role for the start of the current slot's chain */
52318 + tmp = role;
52319 + tmp2 = *curr;
52320 + while (tmp->next && tmp->next != tmp2)
52321 + tmp = tmp->next;
52322 + if (tmp->next == tmp2) {
52323 + /* from example above, we found 3, so just
52324 + replace this slot's chain with ours */
52325 + *curr = role;
52326 + } else {
52327 + /* we didn't find a subset of our role's chain
52328 + in the current slot's chain, so append their
52329 + chain to ours, and set us as the first role in
52330 + the slot's chain
52331 +
52332 + we could fold this case with the case above,
52333 + but making it explicit for clarity
52334 + */
52335 + tmp->next = tmp2;
52336 + *curr = role;
52337 + }
52338 + }
52339 + }
52340 +
52341 + return;
52342 +}
52343 +
52344 +static void
52345 +insert_acl_role_label(struct acl_role_label *role)
52346 +{
52347 + int i;
52348 +
52349 + if (role_list == NULL) {
52350 + role_list = role;
52351 + role->prev = NULL;
52352 + } else {
52353 + role->prev = role_list;
52354 + role_list = role;
52355 + }
52356 +
52357 + /* used for hash chains */
52358 + role->next = NULL;
52359 +
52360 + if (role->roletype & GR_ROLE_DOMAIN) {
52361 + for (i = 0; i < role->domain_child_num; i++)
52362 + __insert_acl_role_label(role, role->domain_children[i]);
52363 + } else
52364 + __insert_acl_role_label(role, role->uidgid);
52365 +}
52366 +
52367 +static int
52368 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52369 +{
52370 + struct name_entry **curr, *nentry;
52371 + struct inodev_entry *ientry;
52372 + unsigned int len = strlen(name);
52373 + unsigned int key = full_name_hash(name, len);
52374 + unsigned int index = key % name_set.n_size;
52375 +
52376 + curr = &name_set.n_hash[index];
52377 +
52378 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52379 + curr = &((*curr)->next);
52380 +
52381 + if (*curr != NULL)
52382 + return 1;
52383 +
52384 + nentry = acl_alloc(sizeof (struct name_entry));
52385 + if (nentry == NULL)
52386 + return 0;
52387 + ientry = acl_alloc(sizeof (struct inodev_entry));
52388 + if (ientry == NULL)
52389 + return 0;
52390 + ientry->nentry = nentry;
52391 +
52392 + nentry->key = key;
52393 + nentry->name = name;
52394 + nentry->inode = inode;
52395 + nentry->device = device;
52396 + nentry->len = len;
52397 + nentry->deleted = deleted;
52398 +
52399 + nentry->prev = NULL;
52400 + curr = &name_set.n_hash[index];
52401 + if (*curr != NULL)
52402 + (*curr)->prev = nentry;
52403 + nentry->next = *curr;
52404 + *curr = nentry;
52405 +
52406 + /* insert us into the table searchable by inode/dev */
52407 + insert_inodev_entry(ientry);
52408 +
52409 + return 1;
52410 +}
52411 +
52412 +static void
52413 +insert_acl_obj_label(struct acl_object_label *obj,
52414 + struct acl_subject_label *subj)
52415 +{
52416 + unsigned int index =
52417 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
52418 + struct acl_object_label **curr;
52419 +
52420 +
52421 + obj->prev = NULL;
52422 +
52423 + curr = &subj->obj_hash[index];
52424 + if (*curr != NULL)
52425 + (*curr)->prev = obj;
52426 +
52427 + obj->next = *curr;
52428 + *curr = obj;
52429 +
52430 + return;
52431 +}
52432 +
52433 +static void
52434 +insert_acl_subj_label(struct acl_subject_label *obj,
52435 + struct acl_role_label *role)
52436 +{
52437 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
52438 + struct acl_subject_label **curr;
52439 +
52440 + obj->prev = NULL;
52441 +
52442 + curr = &role->subj_hash[index];
52443 + if (*curr != NULL)
52444 + (*curr)->prev = obj;
52445 +
52446 + obj->next = *curr;
52447 + *curr = obj;
52448 +
52449 + return;
52450 +}
52451 +
52452 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52453 +
52454 +static void *
52455 +create_table(__u32 * len, int elementsize)
52456 +{
52457 + unsigned int table_sizes[] = {
52458 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52459 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52460 + 4194301, 8388593, 16777213, 33554393, 67108859
52461 + };
52462 + void *newtable = NULL;
52463 + unsigned int pwr = 0;
52464 +
52465 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52466 + table_sizes[pwr] <= *len)
52467 + pwr++;
52468 +
52469 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52470 + return newtable;
52471 +
52472 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52473 + newtable =
52474 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52475 + else
52476 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52477 +
52478 + *len = table_sizes[pwr];
52479 +
52480 + return newtable;
52481 +}
52482 +
52483 +static int
52484 +init_variables(const struct gr_arg *arg)
52485 +{
52486 + struct task_struct *reaper = init_pid_ns.child_reaper;
52487 + unsigned int stacksize;
52488 +
52489 + subj_map_set.s_size = arg->role_db.num_subjects;
52490 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52491 + name_set.n_size = arg->role_db.num_objects;
52492 + inodev_set.i_size = arg->role_db.num_objects;
52493 +
52494 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52495 + !name_set.n_size || !inodev_set.i_size)
52496 + return 1;
52497 +
52498 + if (!gr_init_uidset())
52499 + return 1;
52500 +
52501 + /* set up the stack that holds allocation info */
52502 +
52503 + stacksize = arg->role_db.num_pointers + 5;
52504 +
52505 + if (!acl_alloc_stack_init(stacksize))
52506 + return 1;
52507 +
52508 + /* grab reference for the real root dentry and vfsmount */
52509 + get_fs_root(reaper->fs, &real_root);
52510 +
52511 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52512 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52513 +#endif
52514 +
52515 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52516 + if (fakefs_obj_rw == NULL)
52517 + return 1;
52518 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52519 +
52520 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52521 + if (fakefs_obj_rwx == NULL)
52522 + return 1;
52523 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52524 +
52525 + subj_map_set.s_hash =
52526 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52527 + acl_role_set.r_hash =
52528 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52529 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52530 + inodev_set.i_hash =
52531 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52532 +
52533 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52534 + !name_set.n_hash || !inodev_set.i_hash)
52535 + return 1;
52536 +
52537 + memset(subj_map_set.s_hash, 0,
52538 + sizeof(struct subject_map *) * subj_map_set.s_size);
52539 + memset(acl_role_set.r_hash, 0,
52540 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52541 + memset(name_set.n_hash, 0,
52542 + sizeof (struct name_entry *) * name_set.n_size);
52543 + memset(inodev_set.i_hash, 0,
52544 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52545 +
52546 + return 0;
52547 +}
52548 +
52549 +/* free information not needed after startup
52550 + currently contains user->kernel pointer mappings for subjects
52551 +*/
52552 +
52553 +static void
52554 +free_init_variables(void)
52555 +{
52556 + __u32 i;
52557 +
52558 + if (subj_map_set.s_hash) {
52559 + for (i = 0; i < subj_map_set.s_size; i++) {
52560 + if (subj_map_set.s_hash[i]) {
52561 + kfree(subj_map_set.s_hash[i]);
52562 + subj_map_set.s_hash[i] = NULL;
52563 + }
52564 + }
52565 +
52566 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52567 + PAGE_SIZE)
52568 + kfree(subj_map_set.s_hash);
52569 + else
52570 + vfree(subj_map_set.s_hash);
52571 + }
52572 +
52573 + return;
52574 +}
52575 +
52576 +static void
52577 +free_variables(void)
52578 +{
52579 + struct acl_subject_label *s;
52580 + struct acl_role_label *r;
52581 + struct task_struct *task, *task2;
52582 + unsigned int x;
52583 +
52584 + gr_clear_learn_entries();
52585 +
52586 + read_lock(&tasklist_lock);
52587 + do_each_thread(task2, task) {
52588 + task->acl_sp_role = 0;
52589 + task->acl_role_id = 0;
52590 + task->acl = NULL;
52591 + task->role = NULL;
52592 + } while_each_thread(task2, task);
52593 + read_unlock(&tasklist_lock);
52594 +
52595 + /* release the reference to the real root dentry and vfsmount */
52596 + path_put(&real_root);
52597 + memset(&real_root, 0, sizeof(real_root));
52598 +
52599 + /* free all object hash tables */
52600 +
52601 + FOR_EACH_ROLE_START(r)
52602 + if (r->subj_hash == NULL)
52603 + goto next_role;
52604 + FOR_EACH_SUBJECT_START(r, s, x)
52605 + if (s->obj_hash == NULL)
52606 + break;
52607 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52608 + kfree(s->obj_hash);
52609 + else
52610 + vfree(s->obj_hash);
52611 + FOR_EACH_SUBJECT_END(s, x)
52612 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52613 + if (s->obj_hash == NULL)
52614 + break;
52615 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52616 + kfree(s->obj_hash);
52617 + else
52618 + vfree(s->obj_hash);
52619 + FOR_EACH_NESTED_SUBJECT_END(s)
52620 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52621 + kfree(r->subj_hash);
52622 + else
52623 + vfree(r->subj_hash);
52624 + r->subj_hash = NULL;
52625 +next_role:
52626 + FOR_EACH_ROLE_END(r)
52627 +
52628 + acl_free_all();
52629 +
52630 + if (acl_role_set.r_hash) {
52631 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52632 + PAGE_SIZE)
52633 + kfree(acl_role_set.r_hash);
52634 + else
52635 + vfree(acl_role_set.r_hash);
52636 + }
52637 + if (name_set.n_hash) {
52638 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52639 + PAGE_SIZE)
52640 + kfree(name_set.n_hash);
52641 + else
52642 + vfree(name_set.n_hash);
52643 + }
52644 +
52645 + if (inodev_set.i_hash) {
52646 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52647 + PAGE_SIZE)
52648 + kfree(inodev_set.i_hash);
52649 + else
52650 + vfree(inodev_set.i_hash);
52651 + }
52652 +
52653 + gr_free_uidset();
52654 +
52655 + memset(&name_set, 0, sizeof (struct name_db));
52656 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52657 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52658 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52659 +
52660 + default_role = NULL;
52661 + kernel_role = NULL;
52662 + role_list = NULL;
52663 +
52664 + return;
52665 +}
52666 +
52667 +static __u32
52668 +count_user_objs(struct acl_object_label *userp)
52669 +{
52670 + struct acl_object_label o_tmp;
52671 + __u32 num = 0;
52672 +
52673 + while (userp) {
52674 + if (copy_from_user(&o_tmp, userp,
52675 + sizeof (struct acl_object_label)))
52676 + break;
52677 +
52678 + userp = o_tmp.prev;
52679 + num++;
52680 + }
52681 +
52682 + return num;
52683 +}
52684 +
52685 +static struct acl_subject_label *
52686 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
52687 +
52688 +static int
52689 +copy_user_glob(struct acl_object_label *obj)
52690 +{
52691 + struct acl_object_label *g_tmp, **guser;
52692 + unsigned int len;
52693 + char *tmp;
52694 +
52695 + if (obj->globbed == NULL)
52696 + return 0;
52697 +
52698 + guser = &obj->globbed;
52699 + while (*guser) {
52700 + g_tmp = (struct acl_object_label *)
52701 + acl_alloc(sizeof (struct acl_object_label));
52702 + if (g_tmp == NULL)
52703 + return -ENOMEM;
52704 +
52705 + if (copy_from_user(g_tmp, *guser,
52706 + sizeof (struct acl_object_label)))
52707 + return -EFAULT;
52708 +
52709 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52710 +
52711 + if (!len || len >= PATH_MAX)
52712 + return -EINVAL;
52713 +
52714 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52715 + return -ENOMEM;
52716 +
52717 + if (copy_from_user(tmp, g_tmp->filename, len))
52718 + return -EFAULT;
52719 + tmp[len-1] = '\0';
52720 + g_tmp->filename = tmp;
52721 +
52722 + *guser = g_tmp;
52723 + guser = &(g_tmp->next);
52724 + }
52725 +
52726 + return 0;
52727 +}
52728 +
52729 +static int
52730 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52731 + struct acl_role_label *role)
52732 +{
52733 + struct acl_object_label *o_tmp;
52734 + unsigned int len;
52735 + int ret;
52736 + char *tmp;
52737 +
52738 + while (userp) {
52739 + if ((o_tmp = (struct acl_object_label *)
52740 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52741 + return -ENOMEM;
52742 +
52743 + if (copy_from_user(o_tmp, userp,
52744 + sizeof (struct acl_object_label)))
52745 + return -EFAULT;
52746 +
52747 + userp = o_tmp->prev;
52748 +
52749 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52750 +
52751 + if (!len || len >= PATH_MAX)
52752 + return -EINVAL;
52753 +
52754 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52755 + return -ENOMEM;
52756 +
52757 + if (copy_from_user(tmp, o_tmp->filename, len))
52758 + return -EFAULT;
52759 + tmp[len-1] = '\0';
52760 + o_tmp->filename = tmp;
52761 +
52762 + insert_acl_obj_label(o_tmp, subj);
52763 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52764 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52765 + return -ENOMEM;
52766 +
52767 + ret = copy_user_glob(o_tmp);
52768 + if (ret)
52769 + return ret;
52770 +
52771 + if (o_tmp->nested) {
52772 + int already_copied;
52773 +
52774 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
52775 + if (IS_ERR(o_tmp->nested))
52776 + return PTR_ERR(o_tmp->nested);
52777 +
52778 + /* insert into nested subject list if we haven't copied this one yet
52779 + to prevent duplicate entries */
52780 + if (!already_copied) {
52781 + o_tmp->nested->next = role->hash->first;
52782 + role->hash->first = o_tmp->nested;
52783 + }
52784 + }
52785 + }
52786 +
52787 + return 0;
52788 +}
52789 +
52790 +static __u32
52791 +count_user_subjs(struct acl_subject_label *userp)
52792 +{
52793 + struct acl_subject_label s_tmp;
52794 + __u32 num = 0;
52795 +
52796 + while (userp) {
52797 + if (copy_from_user(&s_tmp, userp,
52798 + sizeof (struct acl_subject_label)))
52799 + break;
52800 +
52801 + userp = s_tmp.prev;
52802 + /* do not count nested subjects against this count, since
52803 + they are not included in the hash table, but are
52804 + attached to objects. We have already counted
52805 + the subjects in userspace for the allocation
52806 + stack
52807 + */
52808 + if (!(s_tmp.mode & GR_NESTED))
52809 + num++;
52810 + }
52811 +
52812 + return num;
52813 +}
52814 +
52815 +static int
52816 +copy_user_allowedips(struct acl_role_label *rolep)
52817 +{
52818 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52819 +
52820 + ruserip = rolep->allowed_ips;
52821 +
52822 + while (ruserip) {
52823 + rlast = rtmp;
52824 +
52825 + if ((rtmp = (struct role_allowed_ip *)
52826 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52827 + return -ENOMEM;
52828 +
52829 + if (copy_from_user(rtmp, ruserip,
52830 + sizeof (struct role_allowed_ip)))
52831 + return -EFAULT;
52832 +
52833 + ruserip = rtmp->prev;
52834 +
52835 + if (!rlast) {
52836 + rtmp->prev = NULL;
52837 + rolep->allowed_ips = rtmp;
52838 + } else {
52839 + rlast->next = rtmp;
52840 + rtmp->prev = rlast;
52841 + }
52842 +
52843 + if (!ruserip)
52844 + rtmp->next = NULL;
52845 + }
52846 +
52847 + return 0;
52848 +}
52849 +
52850 +static int
52851 +copy_user_transitions(struct acl_role_label *rolep)
52852 +{
52853 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52854 +
52855 + unsigned int len;
52856 + char *tmp;
52857 +
52858 + rusertp = rolep->transitions;
52859 +
52860 + while (rusertp) {
52861 + rlast = rtmp;
52862 +
52863 + if ((rtmp = (struct role_transition *)
52864 + acl_alloc(sizeof (struct role_transition))) == NULL)
52865 + return -ENOMEM;
52866 +
52867 + if (copy_from_user(rtmp, rusertp,
52868 + sizeof (struct role_transition)))
52869 + return -EFAULT;
52870 +
52871 + rusertp = rtmp->prev;
52872 +
52873 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52874 +
52875 + if (!len || len >= GR_SPROLE_LEN)
52876 + return -EINVAL;
52877 +
52878 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52879 + return -ENOMEM;
52880 +
52881 + if (copy_from_user(tmp, rtmp->rolename, len))
52882 + return -EFAULT;
52883 + tmp[len-1] = '\0';
52884 + rtmp->rolename = tmp;
52885 +
52886 + if (!rlast) {
52887 + rtmp->prev = NULL;
52888 + rolep->transitions = rtmp;
52889 + } else {
52890 + rlast->next = rtmp;
52891 + rtmp->prev = rlast;
52892 + }
52893 +
52894 + if (!rusertp)
52895 + rtmp->next = NULL;
52896 + }
52897 +
52898 + return 0;
52899 +}
52900 +
52901 +static struct acl_subject_label *
52902 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
52903 +{
52904 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52905 + unsigned int len;
52906 + char *tmp;
52907 + __u32 num_objs;
52908 + struct acl_ip_label **i_tmp, *i_utmp2;
52909 + struct gr_hash_struct ghash;
52910 + struct subject_map *subjmap;
52911 + unsigned int i_num;
52912 + int err;
52913 +
52914 + if (already_copied != NULL)
52915 + *already_copied = 0;
52916 +
52917 + s_tmp = lookup_subject_map(userp);
52918 +
52919 + /* we've already copied this subject into the kernel, just return
52920 + the reference to it, and don't copy it over again
52921 + */
52922 + if (s_tmp) {
52923 + if (already_copied != NULL)
52924 + *already_copied = 1;
52925 + return(s_tmp);
52926 + }
52927 +
52928 + if ((s_tmp = (struct acl_subject_label *)
52929 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52930 + return ERR_PTR(-ENOMEM);
52931 +
52932 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52933 + if (subjmap == NULL)
52934 + return ERR_PTR(-ENOMEM);
52935 +
52936 + subjmap->user = userp;
52937 + subjmap->kernel = s_tmp;
52938 + insert_subj_map_entry(subjmap);
52939 +
52940 + if (copy_from_user(s_tmp, userp,
52941 + sizeof (struct acl_subject_label)))
52942 + return ERR_PTR(-EFAULT);
52943 +
52944 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52945 +
52946 + if (!len || len >= PATH_MAX)
52947 + return ERR_PTR(-EINVAL);
52948 +
52949 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52950 + return ERR_PTR(-ENOMEM);
52951 +
52952 + if (copy_from_user(tmp, s_tmp->filename, len))
52953 + return ERR_PTR(-EFAULT);
52954 + tmp[len-1] = '\0';
52955 + s_tmp->filename = tmp;
52956 +
52957 + if (!strcmp(s_tmp->filename, "/"))
52958 + role->root_label = s_tmp;
52959 +
52960 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52961 + return ERR_PTR(-EFAULT);
52962 +
52963 + /* copy user and group transition tables */
52964 +
52965 + if (s_tmp->user_trans_num) {
52966 + uid_t *uidlist;
52967 +
52968 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52969 + if (uidlist == NULL)
52970 + return ERR_PTR(-ENOMEM);
52971 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52972 + return ERR_PTR(-EFAULT);
52973 +
52974 + s_tmp->user_transitions = uidlist;
52975 + }
52976 +
52977 + if (s_tmp->group_trans_num) {
52978 + gid_t *gidlist;
52979 +
52980 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52981 + if (gidlist == NULL)
52982 + return ERR_PTR(-ENOMEM);
52983 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52984 + return ERR_PTR(-EFAULT);
52985 +
52986 + s_tmp->group_transitions = gidlist;
52987 + }
52988 +
52989 + /* set up object hash table */
52990 + num_objs = count_user_objs(ghash.first);
52991 +
52992 + s_tmp->obj_hash_size = num_objs;
52993 + s_tmp->obj_hash =
52994 + (struct acl_object_label **)
52995 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52996 +
52997 + if (!s_tmp->obj_hash)
52998 + return ERR_PTR(-ENOMEM);
52999 +
53000 + memset(s_tmp->obj_hash, 0,
53001 + s_tmp->obj_hash_size *
53002 + sizeof (struct acl_object_label *));
53003 +
53004 + /* add in objects */
53005 + err = copy_user_objs(ghash.first, s_tmp, role);
53006 +
53007 + if (err)
53008 + return ERR_PTR(err);
53009 +
53010 + /* set pointer for parent subject */
53011 + if (s_tmp->parent_subject) {
53012 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53013 +
53014 + if (IS_ERR(s_tmp2))
53015 + return s_tmp2;
53016 +
53017 + s_tmp->parent_subject = s_tmp2;
53018 + }
53019 +
53020 + /* add in ip acls */
53021 +
53022 + if (!s_tmp->ip_num) {
53023 + s_tmp->ips = NULL;
53024 + goto insert;
53025 + }
53026 +
53027 + i_tmp =
53028 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53029 + sizeof (struct acl_ip_label *));
53030 +
53031 + if (!i_tmp)
53032 + return ERR_PTR(-ENOMEM);
53033 +
53034 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53035 + *(i_tmp + i_num) =
53036 + (struct acl_ip_label *)
53037 + acl_alloc(sizeof (struct acl_ip_label));
53038 + if (!*(i_tmp + i_num))
53039 + return ERR_PTR(-ENOMEM);
53040 +
53041 + if (copy_from_user
53042 + (&i_utmp2, s_tmp->ips + i_num,
53043 + sizeof (struct acl_ip_label *)))
53044 + return ERR_PTR(-EFAULT);
53045 +
53046 + if (copy_from_user
53047 + (*(i_tmp + i_num), i_utmp2,
53048 + sizeof (struct acl_ip_label)))
53049 + return ERR_PTR(-EFAULT);
53050 +
53051 + if ((*(i_tmp + i_num))->iface == NULL)
53052 + continue;
53053 +
53054 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53055 + if (!len || len >= IFNAMSIZ)
53056 + return ERR_PTR(-EINVAL);
53057 + tmp = acl_alloc(len);
53058 + if (tmp == NULL)
53059 + return ERR_PTR(-ENOMEM);
53060 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53061 + return ERR_PTR(-EFAULT);
53062 + (*(i_tmp + i_num))->iface = tmp;
53063 + }
53064 +
53065 + s_tmp->ips = i_tmp;
53066 +
53067 +insert:
53068 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53069 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53070 + return ERR_PTR(-ENOMEM);
53071 +
53072 + return s_tmp;
53073 +}
53074 +
53075 +static int
53076 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53077 +{
53078 + struct acl_subject_label s_pre;
53079 + struct acl_subject_label * ret;
53080 + int err;
53081 +
53082 + while (userp) {
53083 + if (copy_from_user(&s_pre, userp,
53084 + sizeof (struct acl_subject_label)))
53085 + return -EFAULT;
53086 +
53087 + /* do not add nested subjects here, add
53088 + while parsing objects
53089 + */
53090 +
53091 + if (s_pre.mode & GR_NESTED) {
53092 + userp = s_pre.prev;
53093 + continue;
53094 + }
53095 +
53096 + ret = do_copy_user_subj(userp, role, NULL);
53097 +
53098 + err = PTR_ERR(ret);
53099 + if (IS_ERR(ret))
53100 + return err;
53101 +
53102 + insert_acl_subj_label(ret, role);
53103 +
53104 + userp = s_pre.prev;
53105 + }
53106 +
53107 + return 0;
53108 +}
53109 +
53110 +static int
53111 +copy_user_acl(struct gr_arg *arg)
53112 +{
53113 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53114 + struct acl_subject_label *subj_list;
53115 + struct sprole_pw *sptmp;
53116 + struct gr_hash_struct *ghash;
53117 + uid_t *domainlist;
53118 + unsigned int r_num;
53119 + unsigned int len;
53120 + char *tmp;
53121 + int err = 0;
53122 + __u16 i;
53123 + __u32 num_subjs;
53124 +
53125 + /* we need a default and kernel role */
53126 + if (arg->role_db.num_roles < 2)
53127 + return -EINVAL;
53128 +
53129 + /* copy special role authentication info from userspace */
53130 +
53131 + num_sprole_pws = arg->num_sprole_pws;
53132 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53133 +
53134 + if (!acl_special_roles && num_sprole_pws)
53135 + return -ENOMEM;
53136 +
53137 + for (i = 0; i < num_sprole_pws; i++) {
53138 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53139 + if (!sptmp)
53140 + return -ENOMEM;
53141 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53142 + sizeof (struct sprole_pw)))
53143 + return -EFAULT;
53144 +
53145 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53146 +
53147 + if (!len || len >= GR_SPROLE_LEN)
53148 + return -EINVAL;
53149 +
53150 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53151 + return -ENOMEM;
53152 +
53153 + if (copy_from_user(tmp, sptmp->rolename, len))
53154 + return -EFAULT;
53155 +
53156 + tmp[len-1] = '\0';
53157 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53158 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53159 +#endif
53160 + sptmp->rolename = tmp;
53161 + acl_special_roles[i] = sptmp;
53162 + }
53163 +
53164 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53165 +
53166 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53167 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53168 +
53169 + if (!r_tmp)
53170 + return -ENOMEM;
53171 +
53172 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53173 + sizeof (struct acl_role_label *)))
53174 + return -EFAULT;
53175 +
53176 + if (copy_from_user(r_tmp, r_utmp2,
53177 + sizeof (struct acl_role_label)))
53178 + return -EFAULT;
53179 +
53180 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53181 +
53182 + if (!len || len >= PATH_MAX)
53183 + return -EINVAL;
53184 +
53185 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53186 + return -ENOMEM;
53187 +
53188 + if (copy_from_user(tmp, r_tmp->rolename, len))
53189 + return -EFAULT;
53190 +
53191 + tmp[len-1] = '\0';
53192 + r_tmp->rolename = tmp;
53193 +
53194 + if (!strcmp(r_tmp->rolename, "default")
53195 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53196 + default_role = r_tmp;
53197 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53198 + kernel_role = r_tmp;
53199 + }
53200 +
53201 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53202 + return -ENOMEM;
53203 +
53204 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53205 + return -EFAULT;
53206 +
53207 + r_tmp->hash = ghash;
53208 +
53209 + num_subjs = count_user_subjs(r_tmp->hash->first);
53210 +
53211 + r_tmp->subj_hash_size = num_subjs;
53212 + r_tmp->subj_hash =
53213 + (struct acl_subject_label **)
53214 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53215 +
53216 + if (!r_tmp->subj_hash)
53217 + return -ENOMEM;
53218 +
53219 + err = copy_user_allowedips(r_tmp);
53220 + if (err)
53221 + return err;
53222 +
53223 + /* copy domain info */
53224 + if (r_tmp->domain_children != NULL) {
53225 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53226 + if (domainlist == NULL)
53227 + return -ENOMEM;
53228 +
53229 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53230 + return -EFAULT;
53231 +
53232 + r_tmp->domain_children = domainlist;
53233 + }
53234 +
53235 + err = copy_user_transitions(r_tmp);
53236 + if (err)
53237 + return err;
53238 +
53239 + memset(r_tmp->subj_hash, 0,
53240 + r_tmp->subj_hash_size *
53241 + sizeof (struct acl_subject_label *));
53242 +
53243 + /* acquire the list of subjects, then NULL out
53244 + the list prior to parsing the subjects for this role,
53245 + as during this parsing the list is replaced with a list
53246 + of *nested* subjects for the role
53247 + */
53248 + subj_list = r_tmp->hash->first;
53249 +
53250 + /* set nested subject list to null */
53251 + r_tmp->hash->first = NULL;
53252 +
53253 + err = copy_user_subjs(subj_list, r_tmp);
53254 +
53255 + if (err)
53256 + return err;
53257 +
53258 + insert_acl_role_label(r_tmp);
53259 + }
53260 +
53261 + if (default_role == NULL || kernel_role == NULL)
53262 + return -EINVAL;
53263 +
53264 + return err;
53265 +}
53266 +
53267 +static int
53268 +gracl_init(struct gr_arg *args)
53269 +{
53270 + int error = 0;
53271 +
53272 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53273 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53274 +
53275 + if (init_variables(args)) {
53276 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53277 + error = -ENOMEM;
53278 + free_variables();
53279 + goto out;
53280 + }
53281 +
53282 + error = copy_user_acl(args);
53283 + free_init_variables();
53284 + if (error) {
53285 + free_variables();
53286 + goto out;
53287 + }
53288 +
53289 + if ((error = gr_set_acls(0))) {
53290 + free_variables();
53291 + goto out;
53292 + }
53293 +
53294 + pax_open_kernel();
53295 + gr_status |= GR_READY;
53296 + pax_close_kernel();
53297 +
53298 + out:
53299 + return error;
53300 +}
53301 +
53302 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53303 +
53304 +static int
53305 +glob_match(const char *p, const char *n)
53306 +{
53307 + char c;
53308 +
53309 + while ((c = *p++) != '\0') {
53310 + switch (c) {
53311 + case '?':
53312 + if (*n == '\0')
53313 + return 1;
53314 + else if (*n == '/')
53315 + return 1;
53316 + break;
53317 + case '\\':
53318 + if (*n != c)
53319 + return 1;
53320 + break;
53321 + case '*':
53322 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53323 + if (*n == '/')
53324 + return 1;
53325 + else if (c == '?') {
53326 + if (*n == '\0')
53327 + return 1;
53328 + else
53329 + ++n;
53330 + }
53331 + }
53332 + if (c == '\0') {
53333 + return 0;
53334 + } else {
53335 + const char *endp;
53336 +
53337 + if ((endp = strchr(n, '/')) == NULL)
53338 + endp = n + strlen(n);
53339 +
53340 + if (c == '[') {
53341 + for (--p; n < endp; ++n)
53342 + if (!glob_match(p, n))
53343 + return 0;
53344 + } else if (c == '/') {
53345 + while (*n != '\0' && *n != '/')
53346 + ++n;
53347 + if (*n == '/' && !glob_match(p, n + 1))
53348 + return 0;
53349 + } else {
53350 + for (--p; n < endp; ++n)
53351 + if (*n == c && !glob_match(p, n))
53352 + return 0;
53353 + }
53354 +
53355 + return 1;
53356 + }
53357 + case '[':
53358 + {
53359 + int not;
53360 + char cold;
53361 +
53362 + if (*n == '\0' || *n == '/')
53363 + return 1;
53364 +
53365 + not = (*p == '!' || *p == '^');
53366 + if (not)
53367 + ++p;
53368 +
53369 + c = *p++;
53370 + for (;;) {
53371 + unsigned char fn = (unsigned char)*n;
53372 +
53373 + if (c == '\0')
53374 + return 1;
53375 + else {
53376 + if (c == fn)
53377 + goto matched;
53378 + cold = c;
53379 + c = *p++;
53380 +
53381 + if (c == '-' && *p != ']') {
53382 + unsigned char cend = *p++;
53383 +
53384 + if (cend == '\0')
53385 + return 1;
53386 +
53387 + if (cold <= fn && fn <= cend)
53388 + goto matched;
53389 +
53390 + c = *p++;
53391 + }
53392 + }
53393 +
53394 + if (c == ']')
53395 + break;
53396 + }
53397 + if (!not)
53398 + return 1;
53399 + break;
53400 + matched:
53401 + while (c != ']') {
53402 + if (c == '\0')
53403 + return 1;
53404 +
53405 + c = *p++;
53406 + }
53407 + if (not)
53408 + return 1;
53409 + }
53410 + break;
53411 + default:
53412 + if (c != *n)
53413 + return 1;
53414 + }
53415 +
53416 + ++n;
53417 + }
53418 +
53419 + if (*n == '\0')
53420 + return 0;
53421 +
53422 + if (*n == '/')
53423 + return 0;
53424 +
53425 + return 1;
53426 +}
53427 +
53428 +static struct acl_object_label *
53429 +chk_glob_label(struct acl_object_label *globbed,
53430 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53431 +{
53432 + struct acl_object_label *tmp;
53433 +
53434 + if (*path == NULL)
53435 + *path = gr_to_filename_nolock(dentry, mnt);
53436 +
53437 + tmp = globbed;
53438 +
53439 + while (tmp) {
53440 + if (!glob_match(tmp->filename, *path))
53441 + return tmp;
53442 + tmp = tmp->next;
53443 + }
53444 +
53445 + return NULL;
53446 +}
53447 +
53448 +static struct acl_object_label *
53449 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53450 + const ino_t curr_ino, const dev_t curr_dev,
53451 + const struct acl_subject_label *subj, char **path, const int checkglob)
53452 +{
53453 + struct acl_subject_label *tmpsubj;
53454 + struct acl_object_label *retval;
53455 + struct acl_object_label *retval2;
53456 +
53457 + tmpsubj = (struct acl_subject_label *) subj;
53458 + read_lock(&gr_inode_lock);
53459 + do {
53460 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53461 + if (retval) {
53462 + if (checkglob && retval->globbed) {
53463 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53464 + if (retval2)
53465 + retval = retval2;
53466 + }
53467 + break;
53468 + }
53469 + } while ((tmpsubj = tmpsubj->parent_subject));
53470 + read_unlock(&gr_inode_lock);
53471 +
53472 + return retval;
53473 +}
53474 +
53475 +static __inline__ struct acl_object_label *
53476 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53477 + struct dentry *curr_dentry,
53478 + const struct acl_subject_label *subj, char **path, const int checkglob)
53479 +{
53480 + int newglob = checkglob;
53481 + ino_t inode;
53482 + dev_t device;
53483 +
53484 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53485 + as we don't want a / * rule to match instead of the / object
53486 + don't do this for create lookups that call this function though, since they're looking up
53487 + on the parent and thus need globbing checks on all paths
53488 + */
53489 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53490 + newglob = GR_NO_GLOB;
53491 +
53492 + spin_lock(&curr_dentry->d_lock);
53493 + inode = curr_dentry->d_inode->i_ino;
53494 + device = __get_dev(curr_dentry);
53495 + spin_unlock(&curr_dentry->d_lock);
53496 +
53497 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53498 +}
53499 +
53500 +static struct acl_object_label *
53501 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53502 + const struct acl_subject_label *subj, char *path, const int checkglob)
53503 +{
53504 + struct dentry *dentry = (struct dentry *) l_dentry;
53505 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53506 + struct mount *real_mnt = real_mount(mnt);
53507 + struct acl_object_label *retval;
53508 + struct dentry *parent;
53509 +
53510 + write_seqlock(&rename_lock);
53511 + br_read_lock(&vfsmount_lock);
53512 +
53513 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53514 +#ifdef CONFIG_NET
53515 + mnt == sock_mnt ||
53516 +#endif
53517 +#ifdef CONFIG_HUGETLBFS
53518 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53519 +#endif
53520 + /* ignore Eric Biederman */
53521 + IS_PRIVATE(l_dentry->d_inode))) {
53522 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53523 + goto out;
53524 + }
53525 +
53526 + for (;;) {
53527 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53528 + break;
53529 +
53530 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53531 + if (!mnt_has_parent(real_mnt))
53532 + break;
53533 +
53534 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53535 + if (retval != NULL)
53536 + goto out;
53537 +
53538 + dentry = real_mnt->mnt_mountpoint;
53539 + real_mnt = real_mnt->mnt_parent;
53540 + mnt = &real_mnt->mnt;
53541 + continue;
53542 + }
53543 +
53544 + parent = dentry->d_parent;
53545 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53546 + if (retval != NULL)
53547 + goto out;
53548 +
53549 + dentry = parent;
53550 + }
53551 +
53552 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53553 +
53554 + /* real_root is pinned so we don't have to hold a reference */
53555 + if (retval == NULL)
53556 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53557 +out:
53558 + br_read_unlock(&vfsmount_lock);
53559 + write_sequnlock(&rename_lock);
53560 +
53561 + BUG_ON(retval == NULL);
53562 +
53563 + return retval;
53564 +}
53565 +
53566 +static __inline__ struct acl_object_label *
53567 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53568 + const struct acl_subject_label *subj)
53569 +{
53570 + char *path = NULL;
53571 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53572 +}
53573 +
53574 +static __inline__ struct acl_object_label *
53575 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53576 + const struct acl_subject_label *subj)
53577 +{
53578 + char *path = NULL;
53579 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53580 +}
53581 +
53582 +static __inline__ struct acl_object_label *
53583 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53584 + const struct acl_subject_label *subj, char *path)
53585 +{
53586 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53587 +}
53588 +
53589 +static struct acl_subject_label *
53590 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53591 + const struct acl_role_label *role)
53592 +{
53593 + struct dentry *dentry = (struct dentry *) l_dentry;
53594 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53595 + struct mount *real_mnt = real_mount(mnt);
53596 + struct acl_subject_label *retval;
53597 + struct dentry *parent;
53598 +
53599 + write_seqlock(&rename_lock);
53600 + br_read_lock(&vfsmount_lock);
53601 +
53602 + for (;;) {
53603 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53604 + break;
53605 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53606 + if (!mnt_has_parent(real_mnt))
53607 + break;
53608 +
53609 + spin_lock(&dentry->d_lock);
53610 + read_lock(&gr_inode_lock);
53611 + retval =
53612 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53613 + __get_dev(dentry), role);
53614 + read_unlock(&gr_inode_lock);
53615 + spin_unlock(&dentry->d_lock);
53616 + if (retval != NULL)
53617 + goto out;
53618 +
53619 + dentry = real_mnt->mnt_mountpoint;
53620 + real_mnt = real_mnt->mnt_parent;
53621 + mnt = &real_mnt->mnt;
53622 + continue;
53623 + }
53624 +
53625 + spin_lock(&dentry->d_lock);
53626 + read_lock(&gr_inode_lock);
53627 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53628 + __get_dev(dentry), role);
53629 + read_unlock(&gr_inode_lock);
53630 + parent = dentry->d_parent;
53631 + spin_unlock(&dentry->d_lock);
53632 +
53633 + if (retval != NULL)
53634 + goto out;
53635 +
53636 + dentry = parent;
53637 + }
53638 +
53639 + spin_lock(&dentry->d_lock);
53640 + read_lock(&gr_inode_lock);
53641 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53642 + __get_dev(dentry), role);
53643 + read_unlock(&gr_inode_lock);
53644 + spin_unlock(&dentry->d_lock);
53645 +
53646 + if (unlikely(retval == NULL)) {
53647 + /* real_root is pinned, we don't need to hold a reference */
53648 + read_lock(&gr_inode_lock);
53649 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53650 + __get_dev(real_root.dentry), role);
53651 + read_unlock(&gr_inode_lock);
53652 + }
53653 +out:
53654 + br_read_unlock(&vfsmount_lock);
53655 + write_sequnlock(&rename_lock);
53656 +
53657 + BUG_ON(retval == NULL);
53658 +
53659 + return retval;
53660 +}
53661 +
53662 +static void
53663 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53664 +{
53665 + struct task_struct *task = current;
53666 + const struct cred *cred = current_cred();
53667 +
53668 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53669 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53670 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53671 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53672 +
53673 + return;
53674 +}
53675 +
53676 +static void
53677 +gr_log_learn_id_change(const char type, const unsigned int real,
53678 + const unsigned int effective, const unsigned int fs)
53679 +{
53680 + struct task_struct *task = current;
53681 + const struct cred *cred = current_cred();
53682 +
53683 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53684 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53685 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53686 + type, real, effective, fs, &task->signal->saved_ip);
53687 +
53688 + return;
53689 +}
53690 +
53691 +__u32
53692 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53693 + const struct vfsmount * mnt)
53694 +{
53695 + __u32 retval = mode;
53696 + struct acl_subject_label *curracl;
53697 + struct acl_object_label *currobj;
53698 +
53699 + if (unlikely(!(gr_status & GR_READY)))
53700 + return (mode & ~GR_AUDITS);
53701 +
53702 + curracl = current->acl;
53703 +
53704 + currobj = chk_obj_label(dentry, mnt, curracl);
53705 + retval = currobj->mode & mode;
53706 +
53707 + /* if we're opening a specified transfer file for writing
53708 + (e.g. /dev/initctl), then transfer our role to init
53709 + */
53710 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53711 + current->role->roletype & GR_ROLE_PERSIST)) {
53712 + struct task_struct *task = init_pid_ns.child_reaper;
53713 +
53714 + if (task->role != current->role) {
53715 + task->acl_sp_role = 0;
53716 + task->acl_role_id = current->acl_role_id;
53717 + task->role = current->role;
53718 + rcu_read_lock();
53719 + read_lock(&grsec_exec_file_lock);
53720 + gr_apply_subject_to_task(task);
53721 + read_unlock(&grsec_exec_file_lock);
53722 + rcu_read_unlock();
53723 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53724 + }
53725 + }
53726 +
53727 + if (unlikely
53728 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53729 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53730 + __u32 new_mode = mode;
53731 +
53732 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53733 +
53734 + retval = new_mode;
53735 +
53736 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53737 + new_mode |= GR_INHERIT;
53738 +
53739 + if (!(mode & GR_NOLEARN))
53740 + gr_log_learn(dentry, mnt, new_mode);
53741 + }
53742 +
53743 + return retval;
53744 +}
53745 +
53746 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53747 + const struct dentry *parent,
53748 + const struct vfsmount *mnt)
53749 +{
53750 + struct name_entry *match;
53751 + struct acl_object_label *matchpo;
53752 + struct acl_subject_label *curracl;
53753 + char *path;
53754 +
53755 + if (unlikely(!(gr_status & GR_READY)))
53756 + return NULL;
53757 +
53758 + preempt_disable();
53759 + path = gr_to_filename_rbac(new_dentry, mnt);
53760 + match = lookup_name_entry_create(path);
53761 +
53762 + curracl = current->acl;
53763 +
53764 + if (match) {
53765 + read_lock(&gr_inode_lock);
53766 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53767 + read_unlock(&gr_inode_lock);
53768 +
53769 + if (matchpo) {
53770 + preempt_enable();
53771 + return matchpo;
53772 + }
53773 + }
53774 +
53775 + // lookup parent
53776 +
53777 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53778 +
53779 + preempt_enable();
53780 + return matchpo;
53781 +}
53782 +
53783 +__u32
53784 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53785 + const struct vfsmount * mnt, const __u32 mode)
53786 +{
53787 + struct acl_object_label *matchpo;
53788 + __u32 retval;
53789 +
53790 + if (unlikely(!(gr_status & GR_READY)))
53791 + return (mode & ~GR_AUDITS);
53792 +
53793 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53794 +
53795 + retval = matchpo->mode & mode;
53796 +
53797 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53798 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53799 + __u32 new_mode = mode;
53800 +
53801 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53802 +
53803 + gr_log_learn(new_dentry, mnt, new_mode);
53804 + return new_mode;
53805 + }
53806 +
53807 + return retval;
53808 +}
53809 +
53810 +__u32
53811 +gr_check_link(const struct dentry * new_dentry,
53812 + const struct dentry * parent_dentry,
53813 + const struct vfsmount * parent_mnt,
53814 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53815 +{
53816 + struct acl_object_label *obj;
53817 + __u32 oldmode, newmode;
53818 + __u32 needmode;
53819 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53820 + GR_DELETE | GR_INHERIT;
53821 +
53822 + if (unlikely(!(gr_status & GR_READY)))
53823 + return (GR_CREATE | GR_LINK);
53824 +
53825 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53826 + oldmode = obj->mode;
53827 +
53828 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53829 + newmode = obj->mode;
53830 +
53831 + needmode = newmode & checkmodes;
53832 +
53833 + // old name for hardlink must have at least the permissions of the new name
53834 + if ((oldmode & needmode) != needmode)
53835 + goto bad;
53836 +
53837 + // if old name had restrictions/auditing, make sure the new name does as well
53838 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53839 +
53840 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53841 + if (is_privileged_binary(old_dentry))
53842 + needmode |= GR_SETID;
53843 +
53844 + if ((newmode & needmode) != needmode)
53845 + goto bad;
53846 +
53847 + // enforce minimum permissions
53848 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53849 + return newmode;
53850 +bad:
53851 + needmode = oldmode;
53852 + if (is_privileged_binary(old_dentry))
53853 + needmode |= GR_SETID;
53854 +
53855 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53856 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53857 + return (GR_CREATE | GR_LINK);
53858 + } else if (newmode & GR_SUPPRESS)
53859 + return GR_SUPPRESS;
53860 + else
53861 + return 0;
53862 +}
53863 +
53864 +int
53865 +gr_check_hidden_task(const struct task_struct *task)
53866 +{
53867 + if (unlikely(!(gr_status & GR_READY)))
53868 + return 0;
53869 +
53870 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53871 + return 1;
53872 +
53873 + return 0;
53874 +}
53875 +
53876 +int
53877 +gr_check_protected_task(const struct task_struct *task)
53878 +{
53879 + if (unlikely(!(gr_status & GR_READY) || !task))
53880 + return 0;
53881 +
53882 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53883 + task->acl != current->acl)
53884 + return 1;
53885 +
53886 + return 0;
53887 +}
53888 +
53889 +int
53890 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53891 +{
53892 + struct task_struct *p;
53893 + int ret = 0;
53894 +
53895 + if (unlikely(!(gr_status & GR_READY) || !pid))
53896 + return ret;
53897 +
53898 + read_lock(&tasklist_lock);
53899 + do_each_pid_task(pid, type, p) {
53900 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53901 + p->acl != current->acl) {
53902 + ret = 1;
53903 + goto out;
53904 + }
53905 + } while_each_pid_task(pid, type, p);
53906 +out:
53907 + read_unlock(&tasklist_lock);
53908 +
53909 + return ret;
53910 +}
53911 +
53912 +void
53913 +gr_copy_label(struct task_struct *tsk)
53914 +{
53915 + tsk->signal->used_accept = 0;
53916 + tsk->acl_sp_role = 0;
53917 + tsk->acl_role_id = current->acl_role_id;
53918 + tsk->acl = current->acl;
53919 + tsk->role = current->role;
53920 + tsk->signal->curr_ip = current->signal->curr_ip;
53921 + tsk->signal->saved_ip = current->signal->saved_ip;
53922 + if (current->exec_file)
53923 + get_file(current->exec_file);
53924 + tsk->exec_file = current->exec_file;
53925 + tsk->is_writable = current->is_writable;
53926 + if (unlikely(current->signal->used_accept)) {
53927 + current->signal->curr_ip = 0;
53928 + current->signal->saved_ip = 0;
53929 + }
53930 +
53931 + return;
53932 +}
53933 +
53934 +static void
53935 +gr_set_proc_res(struct task_struct *task)
53936 +{
53937 + struct acl_subject_label *proc;
53938 + unsigned short i;
53939 +
53940 + proc = task->acl;
53941 +
53942 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53943 + return;
53944 +
53945 + for (i = 0; i < RLIM_NLIMITS; i++) {
53946 + if (!(proc->resmask & (1 << i)))
53947 + continue;
53948 +
53949 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53950 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53951 + }
53952 +
53953 + return;
53954 +}
53955 +
53956 +extern int __gr_process_user_ban(struct user_struct *user);
53957 +
53958 +int
53959 +gr_check_user_change(int real, int effective, int fs)
53960 +{
53961 + unsigned int i;
53962 + __u16 num;
53963 + uid_t *uidlist;
53964 + int curuid;
53965 + int realok = 0;
53966 + int effectiveok = 0;
53967 + int fsok = 0;
53968 +
53969 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53970 + struct user_struct *user;
53971 +
53972 + if (real == -1)
53973 + goto skipit;
53974 +
53975 + user = find_user(real);
53976 + if (user == NULL)
53977 + goto skipit;
53978 +
53979 + if (__gr_process_user_ban(user)) {
53980 + /* for find_user */
53981 + free_uid(user);
53982 + return 1;
53983 + }
53984 +
53985 + /* for find_user */
53986 + free_uid(user);
53987 +
53988 +skipit:
53989 +#endif
53990 +
53991 + if (unlikely(!(gr_status & GR_READY)))
53992 + return 0;
53993 +
53994 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53995 + gr_log_learn_id_change('u', real, effective, fs);
53996 +
53997 + num = current->acl->user_trans_num;
53998 + uidlist = current->acl->user_transitions;
53999 +
54000 + if (uidlist == NULL)
54001 + return 0;
54002 +
54003 + if (real == -1)
54004 + realok = 1;
54005 + if (effective == -1)
54006 + effectiveok = 1;
54007 + if (fs == -1)
54008 + fsok = 1;
54009 +
54010 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54011 + for (i = 0; i < num; i++) {
54012 + curuid = (int)uidlist[i];
54013 + if (real == curuid)
54014 + realok = 1;
54015 + if (effective == curuid)
54016 + effectiveok = 1;
54017 + if (fs == curuid)
54018 + fsok = 1;
54019 + }
54020 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54021 + for (i = 0; i < num; i++) {
54022 + curuid = (int)uidlist[i];
54023 + if (real == curuid)
54024 + break;
54025 + if (effective == curuid)
54026 + break;
54027 + if (fs == curuid)
54028 + break;
54029 + }
54030 + /* not in deny list */
54031 + if (i == num) {
54032 + realok = 1;
54033 + effectiveok = 1;
54034 + fsok = 1;
54035 + }
54036 + }
54037 +
54038 + if (realok && effectiveok && fsok)
54039 + return 0;
54040 + else {
54041 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54042 + return 1;
54043 + }
54044 +}
54045 +
54046 +int
54047 +gr_check_group_change(int real, int effective, int fs)
54048 +{
54049 + unsigned int i;
54050 + __u16 num;
54051 + gid_t *gidlist;
54052 + int curgid;
54053 + int realok = 0;
54054 + int effectiveok = 0;
54055 + int fsok = 0;
54056 +
54057 + if (unlikely(!(gr_status & GR_READY)))
54058 + return 0;
54059 +
54060 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54061 + gr_log_learn_id_change('g', real, effective, fs);
54062 +
54063 + num = current->acl->group_trans_num;
54064 + gidlist = current->acl->group_transitions;
54065 +
54066 + if (gidlist == NULL)
54067 + return 0;
54068 +
54069 + if (real == -1)
54070 + realok = 1;
54071 + if (effective == -1)
54072 + effectiveok = 1;
54073 + if (fs == -1)
54074 + fsok = 1;
54075 +
54076 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54077 + for (i = 0; i < num; i++) {
54078 + curgid = (int)gidlist[i];
54079 + if (real == curgid)
54080 + realok = 1;
54081 + if (effective == curgid)
54082 + effectiveok = 1;
54083 + if (fs == curgid)
54084 + fsok = 1;
54085 + }
54086 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54087 + for (i = 0; i < num; i++) {
54088 + curgid = (int)gidlist[i];
54089 + if (real == curgid)
54090 + break;
54091 + if (effective == curgid)
54092 + break;
54093 + if (fs == curgid)
54094 + break;
54095 + }
54096 + /* not in deny list */
54097 + if (i == num) {
54098 + realok = 1;
54099 + effectiveok = 1;
54100 + fsok = 1;
54101 + }
54102 + }
54103 +
54104 + if (realok && effectiveok && fsok)
54105 + return 0;
54106 + else {
54107 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54108 + return 1;
54109 + }
54110 +}
54111 +
54112 +extern int gr_acl_is_capable(const int cap);
54113 +
54114 +void
54115 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54116 +{
54117 + struct acl_role_label *role = task->role;
54118 + struct acl_subject_label *subj = NULL;
54119 + struct acl_object_label *obj;
54120 + struct file *filp;
54121 +
54122 + if (unlikely(!(gr_status & GR_READY)))
54123 + return;
54124 +
54125 + filp = task->exec_file;
54126 +
54127 + /* kernel process, we'll give them the kernel role */
54128 + if (unlikely(!filp)) {
54129 + task->role = kernel_role;
54130 + task->acl = kernel_role->root_label;
54131 + return;
54132 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54133 + role = lookup_acl_role_label(task, uid, gid);
54134 +
54135 + /* don't change the role if we're not a privileged process */
54136 + if (role && task->role != role &&
54137 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54138 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54139 + return;
54140 +
54141 + /* perform subject lookup in possibly new role
54142 + we can use this result below in the case where role == task->role
54143 + */
54144 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54145 +
54146 + /* if we changed uid/gid, but result in the same role
54147 + and are using inheritance, don't lose the inherited subject
54148 + if current subject is other than what normal lookup
54149 + would result in, we arrived via inheritance, don't
54150 + lose subject
54151 + */
54152 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54153 + (subj == task->acl)))
54154 + task->acl = subj;
54155 +
54156 + task->role = role;
54157 +
54158 + task->is_writable = 0;
54159 +
54160 + /* ignore additional mmap checks for processes that are writable
54161 + by the default ACL */
54162 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54163 + if (unlikely(obj->mode & GR_WRITE))
54164 + task->is_writable = 1;
54165 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54166 + if (unlikely(obj->mode & GR_WRITE))
54167 + task->is_writable = 1;
54168 +
54169 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54170 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54171 +#endif
54172 +
54173 + gr_set_proc_res(task);
54174 +
54175 + return;
54176 +}
54177 +
54178 +int
54179 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54180 + const int unsafe_flags)
54181 +{
54182 + struct task_struct *task = current;
54183 + struct acl_subject_label *newacl;
54184 + struct acl_object_label *obj;
54185 + __u32 retmode;
54186 +
54187 + if (unlikely(!(gr_status & GR_READY)))
54188 + return 0;
54189 +
54190 + newacl = chk_subj_label(dentry, mnt, task->role);
54191 +
54192 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54193 + did an exec
54194 + */
54195 + rcu_read_lock();
54196 + read_lock(&tasklist_lock);
54197 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54198 + (task->parent->acl->mode & GR_POVERRIDE))) {
54199 + read_unlock(&tasklist_lock);
54200 + rcu_read_unlock();
54201 + goto skip_check;
54202 + }
54203 + read_unlock(&tasklist_lock);
54204 + rcu_read_unlock();
54205 +
54206 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54207 + !(task->role->roletype & GR_ROLE_GOD) &&
54208 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54209 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54210 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54211 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54212 + else
54213 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54214 + return -EACCES;
54215 + }
54216 +
54217 +skip_check:
54218 +
54219 + obj = chk_obj_label(dentry, mnt, task->acl);
54220 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54221 +
54222 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54223 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54224 + if (obj->nested)
54225 + task->acl = obj->nested;
54226 + else
54227 + task->acl = newacl;
54228 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54229 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54230 +
54231 + task->is_writable = 0;
54232 +
54233 + /* ignore additional mmap checks for processes that are writable
54234 + by the default ACL */
54235 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54236 + if (unlikely(obj->mode & GR_WRITE))
54237 + task->is_writable = 1;
54238 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54239 + if (unlikely(obj->mode & GR_WRITE))
54240 + task->is_writable = 1;
54241 +
54242 + gr_set_proc_res(task);
54243 +
54244 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54245 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54246 +#endif
54247 + return 0;
54248 +}
54249 +
54250 +/* always called with valid inodev ptr */
54251 +static void
54252 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54253 +{
54254 + struct acl_object_label *matchpo;
54255 + struct acl_subject_label *matchps;
54256 + struct acl_subject_label *subj;
54257 + struct acl_role_label *role;
54258 + unsigned int x;
54259 +
54260 + FOR_EACH_ROLE_START(role)
54261 + FOR_EACH_SUBJECT_START(role, subj, x)
54262 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54263 + matchpo->mode |= GR_DELETED;
54264 + FOR_EACH_SUBJECT_END(subj,x)
54265 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54266 + /* nested subjects aren't in the role's subj_hash table */
54267 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54268 + matchpo->mode |= GR_DELETED;
54269 + FOR_EACH_NESTED_SUBJECT_END(subj)
54270 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54271 + matchps->mode |= GR_DELETED;
54272 + FOR_EACH_ROLE_END(role)
54273 +
54274 + inodev->nentry->deleted = 1;
54275 +
54276 + return;
54277 +}
54278 +
54279 +void
54280 +gr_handle_delete(const ino_t ino, const dev_t dev)
54281 +{
54282 + struct inodev_entry *inodev;
54283 +
54284 + if (unlikely(!(gr_status & GR_READY)))
54285 + return;
54286 +
54287 + write_lock(&gr_inode_lock);
54288 + inodev = lookup_inodev_entry(ino, dev);
54289 + if (inodev != NULL)
54290 + do_handle_delete(inodev, ino, dev);
54291 + write_unlock(&gr_inode_lock);
54292 +
54293 + return;
54294 +}
54295 +
54296 +static void
54297 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54298 + const ino_t newinode, const dev_t newdevice,
54299 + struct acl_subject_label *subj)
54300 +{
54301 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
54302 + struct acl_object_label *match;
54303 +
54304 + match = subj->obj_hash[index];
54305 +
54306 + while (match && (match->inode != oldinode ||
54307 + match->device != olddevice ||
54308 + !(match->mode & GR_DELETED)))
54309 + match = match->next;
54310 +
54311 + if (match && (match->inode == oldinode)
54312 + && (match->device == olddevice)
54313 + && (match->mode & GR_DELETED)) {
54314 + if (match->prev == NULL) {
54315 + subj->obj_hash[index] = match->next;
54316 + if (match->next != NULL)
54317 + match->next->prev = NULL;
54318 + } else {
54319 + match->prev->next = match->next;
54320 + if (match->next != NULL)
54321 + match->next->prev = match->prev;
54322 + }
54323 + match->prev = NULL;
54324 + match->next = NULL;
54325 + match->inode = newinode;
54326 + match->device = newdevice;
54327 + match->mode &= ~GR_DELETED;
54328 +
54329 + insert_acl_obj_label(match, subj);
54330 + }
54331 +
54332 + return;
54333 +}
54334 +
54335 +static void
54336 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54337 + const ino_t newinode, const dev_t newdevice,
54338 + struct acl_role_label *role)
54339 +{
54340 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
54341 + struct acl_subject_label *match;
54342 +
54343 + match = role->subj_hash[index];
54344 +
54345 + while (match && (match->inode != oldinode ||
54346 + match->device != olddevice ||
54347 + !(match->mode & GR_DELETED)))
54348 + match = match->next;
54349 +
54350 + if (match && (match->inode == oldinode)
54351 + && (match->device == olddevice)
54352 + && (match->mode & GR_DELETED)) {
54353 + if (match->prev == NULL) {
54354 + role->subj_hash[index] = match->next;
54355 + if (match->next != NULL)
54356 + match->next->prev = NULL;
54357 + } else {
54358 + match->prev->next = match->next;
54359 + if (match->next != NULL)
54360 + match->next->prev = match->prev;
54361 + }
54362 + match->prev = NULL;
54363 + match->next = NULL;
54364 + match->inode = newinode;
54365 + match->device = newdevice;
54366 + match->mode &= ~GR_DELETED;
54367 +
54368 + insert_acl_subj_label(match, role);
54369 + }
54370 +
54371 + return;
54372 +}
54373 +
54374 +static void
54375 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54376 + const ino_t newinode, const dev_t newdevice)
54377 +{
54378 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
54379 + struct inodev_entry *match;
54380 +
54381 + match = inodev_set.i_hash[index];
54382 +
54383 + while (match && (match->nentry->inode != oldinode ||
54384 + match->nentry->device != olddevice || !match->nentry->deleted))
54385 + match = match->next;
54386 +
54387 + if (match && (match->nentry->inode == oldinode)
54388 + && (match->nentry->device == olddevice) &&
54389 + match->nentry->deleted) {
54390 + if (match->prev == NULL) {
54391 + inodev_set.i_hash[index] = match->next;
54392 + if (match->next != NULL)
54393 + match->next->prev = NULL;
54394 + } else {
54395 + match->prev->next = match->next;
54396 + if (match->next != NULL)
54397 + match->next->prev = match->prev;
54398 + }
54399 + match->prev = NULL;
54400 + match->next = NULL;
54401 + match->nentry->inode = newinode;
54402 + match->nentry->device = newdevice;
54403 + match->nentry->deleted = 0;
54404 +
54405 + insert_inodev_entry(match);
54406 + }
54407 +
54408 + return;
54409 +}
54410 +
54411 +static void
54412 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54413 +{
54414 + struct acl_subject_label *subj;
54415 + struct acl_role_label *role;
54416 + unsigned int x;
54417 +
54418 + FOR_EACH_ROLE_START(role)
54419 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54420 +
54421 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54422 + if ((subj->inode == ino) && (subj->device == dev)) {
54423 + subj->inode = ino;
54424 + subj->device = dev;
54425 + }
54426 + /* nested subjects aren't in the role's subj_hash table */
54427 + update_acl_obj_label(matchn->inode, matchn->device,
54428 + ino, dev, subj);
54429 + FOR_EACH_NESTED_SUBJECT_END(subj)
54430 + FOR_EACH_SUBJECT_START(role, subj, x)
54431 + update_acl_obj_label(matchn->inode, matchn->device,
54432 + ino, dev, subj);
54433 + FOR_EACH_SUBJECT_END(subj,x)
54434 + FOR_EACH_ROLE_END(role)
54435 +
54436 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54437 +
54438 + return;
54439 +}
54440 +
54441 +static void
54442 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54443 + const struct vfsmount *mnt)
54444 +{
54445 + ino_t ino = dentry->d_inode->i_ino;
54446 + dev_t dev = __get_dev(dentry);
54447 +
54448 + __do_handle_create(matchn, ino, dev);
54449 +
54450 + return;
54451 +}
54452 +
54453 +void
54454 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54455 +{
54456 + struct name_entry *matchn;
54457 +
54458 + if (unlikely(!(gr_status & GR_READY)))
54459 + return;
54460 +
54461 + preempt_disable();
54462 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54463 +
54464 + if (unlikely((unsigned long)matchn)) {
54465 + write_lock(&gr_inode_lock);
54466 + do_handle_create(matchn, dentry, mnt);
54467 + write_unlock(&gr_inode_lock);
54468 + }
54469 + preempt_enable();
54470 +
54471 + return;
54472 +}
54473 +
54474 +void
54475 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54476 +{
54477 + struct name_entry *matchn;
54478 +
54479 + if (unlikely(!(gr_status & GR_READY)))
54480 + return;
54481 +
54482 + preempt_disable();
54483 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54484 +
54485 + if (unlikely((unsigned long)matchn)) {
54486 + write_lock(&gr_inode_lock);
54487 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54488 + write_unlock(&gr_inode_lock);
54489 + }
54490 + preempt_enable();
54491 +
54492 + return;
54493 +}
54494 +
54495 +void
54496 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54497 + struct dentry *old_dentry,
54498 + struct dentry *new_dentry,
54499 + struct vfsmount *mnt, const __u8 replace)
54500 +{
54501 + struct name_entry *matchn;
54502 + struct inodev_entry *inodev;
54503 + struct inode *inode = new_dentry->d_inode;
54504 + ino_t old_ino = old_dentry->d_inode->i_ino;
54505 + dev_t old_dev = __get_dev(old_dentry);
54506 +
54507 + /* vfs_rename swaps the name and parent link for old_dentry and
54508 + new_dentry
54509 + at this point, old_dentry has the new name, parent link, and inode
54510 + for the renamed file
54511 + if a file is being replaced by a rename, new_dentry has the inode
54512 + and name for the replaced file
54513 + */
54514 +
54515 + if (unlikely(!(gr_status & GR_READY)))
54516 + return;
54517 +
54518 + preempt_disable();
54519 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54520 +
54521 + /* we wouldn't have to check d_inode if it weren't for
54522 + NFS silly-renaming
54523 + */
54524 +
54525 + write_lock(&gr_inode_lock);
54526 + if (unlikely(replace && inode)) {
54527 + ino_t new_ino = inode->i_ino;
54528 + dev_t new_dev = __get_dev(new_dentry);
54529 +
54530 + inodev = lookup_inodev_entry(new_ino, new_dev);
54531 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54532 + do_handle_delete(inodev, new_ino, new_dev);
54533 + }
54534 +
54535 + inodev = lookup_inodev_entry(old_ino, old_dev);
54536 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54537 + do_handle_delete(inodev, old_ino, old_dev);
54538 +
54539 + if (unlikely((unsigned long)matchn))
54540 + do_handle_create(matchn, old_dentry, mnt);
54541 +
54542 + write_unlock(&gr_inode_lock);
54543 + preempt_enable();
54544 +
54545 + return;
54546 +}
54547 +
54548 +static int
54549 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54550 + unsigned char **sum)
54551 +{
54552 + struct acl_role_label *r;
54553 + struct role_allowed_ip *ipp;
54554 + struct role_transition *trans;
54555 + unsigned int i;
54556 + int found = 0;
54557 + u32 curr_ip = current->signal->curr_ip;
54558 +
54559 + current->signal->saved_ip = curr_ip;
54560 +
54561 + /* check transition table */
54562 +
54563 + for (trans = current->role->transitions; trans; trans = trans->next) {
54564 + if (!strcmp(rolename, trans->rolename)) {
54565 + found = 1;
54566 + break;
54567 + }
54568 + }
54569 +
54570 + if (!found)
54571 + return 0;
54572 +
54573 + /* handle special roles that do not require authentication
54574 + and check ip */
54575 +
54576 + FOR_EACH_ROLE_START(r)
54577 + if (!strcmp(rolename, r->rolename) &&
54578 + (r->roletype & GR_ROLE_SPECIAL)) {
54579 + found = 0;
54580 + if (r->allowed_ips != NULL) {
54581 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54582 + if ((ntohl(curr_ip) & ipp->netmask) ==
54583 + (ntohl(ipp->addr) & ipp->netmask))
54584 + found = 1;
54585 + }
54586 + } else
54587 + found = 2;
54588 + if (!found)
54589 + return 0;
54590 +
54591 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54592 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54593 + *salt = NULL;
54594 + *sum = NULL;
54595 + return 1;
54596 + }
54597 + }
54598 + FOR_EACH_ROLE_END(r)
54599 +
54600 + for (i = 0; i < num_sprole_pws; i++) {
54601 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54602 + *salt = acl_special_roles[i]->salt;
54603 + *sum = acl_special_roles[i]->sum;
54604 + return 1;
54605 + }
54606 + }
54607 +
54608 + return 0;
54609 +}
54610 +
54611 +static void
54612 +assign_special_role(char *rolename)
54613 +{
54614 + struct acl_object_label *obj;
54615 + struct acl_role_label *r;
54616 + struct acl_role_label *assigned = NULL;
54617 + struct task_struct *tsk;
54618 + struct file *filp;
54619 +
54620 + FOR_EACH_ROLE_START(r)
54621 + if (!strcmp(rolename, r->rolename) &&
54622 + (r->roletype & GR_ROLE_SPECIAL)) {
54623 + assigned = r;
54624 + break;
54625 + }
54626 + FOR_EACH_ROLE_END(r)
54627 +
54628 + if (!assigned)
54629 + return;
54630 +
54631 + read_lock(&tasklist_lock);
54632 + read_lock(&grsec_exec_file_lock);
54633 +
54634 + tsk = current->real_parent;
54635 + if (tsk == NULL)
54636 + goto out_unlock;
54637 +
54638 + filp = tsk->exec_file;
54639 + if (filp == NULL)
54640 + goto out_unlock;
54641 +
54642 + tsk->is_writable = 0;
54643 +
54644 + tsk->acl_sp_role = 1;
54645 + tsk->acl_role_id = ++acl_sp_role_value;
54646 + tsk->role = assigned;
54647 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54648 +
54649 + /* ignore additional mmap checks for processes that are writable
54650 + by the default ACL */
54651 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54652 + if (unlikely(obj->mode & GR_WRITE))
54653 + tsk->is_writable = 1;
54654 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54655 + if (unlikely(obj->mode & GR_WRITE))
54656 + tsk->is_writable = 1;
54657 +
54658 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54659 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54660 +#endif
54661 +
54662 +out_unlock:
54663 + read_unlock(&grsec_exec_file_lock);
54664 + read_unlock(&tasklist_lock);
54665 + return;
54666 +}
54667 +
54668 +int gr_check_secure_terminal(struct task_struct *task)
54669 +{
54670 + struct task_struct *p, *p2, *p3;
54671 + struct files_struct *files;
54672 + struct fdtable *fdt;
54673 + struct file *our_file = NULL, *file;
54674 + int i;
54675 +
54676 + if (task->signal->tty == NULL)
54677 + return 1;
54678 +
54679 + files = get_files_struct(task);
54680 + if (files != NULL) {
54681 + rcu_read_lock();
54682 + fdt = files_fdtable(files);
54683 + for (i=0; i < fdt->max_fds; i++) {
54684 + file = fcheck_files(files, i);
54685 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54686 + get_file(file);
54687 + our_file = file;
54688 + }
54689 + }
54690 + rcu_read_unlock();
54691 + put_files_struct(files);
54692 + }
54693 +
54694 + if (our_file == NULL)
54695 + return 1;
54696 +
54697 + read_lock(&tasklist_lock);
54698 + do_each_thread(p2, p) {
54699 + files = get_files_struct(p);
54700 + if (files == NULL ||
54701 + (p->signal && p->signal->tty == task->signal->tty)) {
54702 + if (files != NULL)
54703 + put_files_struct(files);
54704 + continue;
54705 + }
54706 + rcu_read_lock();
54707 + fdt = files_fdtable(files);
54708 + for (i=0; i < fdt->max_fds; i++) {
54709 + file = fcheck_files(files, i);
54710 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54711 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54712 + p3 = task;
54713 + while (p3->pid > 0) {
54714 + if (p3 == p)
54715 + break;
54716 + p3 = p3->real_parent;
54717 + }
54718 + if (p3 == p)
54719 + break;
54720 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54721 + gr_handle_alertkill(p);
54722 + rcu_read_unlock();
54723 + put_files_struct(files);
54724 + read_unlock(&tasklist_lock);
54725 + fput(our_file);
54726 + return 0;
54727 + }
54728 + }
54729 + rcu_read_unlock();
54730 + put_files_struct(files);
54731 + } while_each_thread(p2, p);
54732 + read_unlock(&tasklist_lock);
54733 +
54734 + fput(our_file);
54735 + return 1;
54736 +}
54737 +
54738 +static int gr_rbac_disable(void *unused)
54739 +{
54740 + pax_open_kernel();
54741 + gr_status &= ~GR_READY;
54742 + pax_close_kernel();
54743 +
54744 + return 0;
54745 +}
54746 +
54747 +ssize_t
54748 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54749 +{
54750 + struct gr_arg_wrapper uwrap;
54751 + unsigned char *sprole_salt = NULL;
54752 + unsigned char *sprole_sum = NULL;
54753 + int error = sizeof (struct gr_arg_wrapper);
54754 + int error2 = 0;
54755 +
54756 + mutex_lock(&gr_dev_mutex);
54757 +
54758 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54759 + error = -EPERM;
54760 + goto out;
54761 + }
54762 +
54763 + if (count != sizeof (struct gr_arg_wrapper)) {
54764 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54765 + error = -EINVAL;
54766 + goto out;
54767 + }
54768 +
54769 +
54770 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54771 + gr_auth_expires = 0;
54772 + gr_auth_attempts = 0;
54773 + }
54774 +
54775 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54776 + error = -EFAULT;
54777 + goto out;
54778 + }
54779 +
54780 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54781 + error = -EINVAL;
54782 + goto out;
54783 + }
54784 +
54785 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54786 + error = -EFAULT;
54787 + goto out;
54788 + }
54789 +
54790 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54791 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54792 + time_after(gr_auth_expires, get_seconds())) {
54793 + error = -EBUSY;
54794 + goto out;
54795 + }
54796 +
54797 + /* if non-root trying to do anything other than use a special role,
54798 + do not attempt authentication, do not count towards authentication
54799 + locking
54800 + */
54801 +
54802 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54803 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54804 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54805 + error = -EPERM;
54806 + goto out;
54807 + }
54808 +
54809 + /* ensure pw and special role name are null terminated */
54810 +
54811 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54812 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54813 +
54814 + /* Okay.
54815 + * We have our enough of the argument structure..(we have yet
54816 + * to copy_from_user the tables themselves) . Copy the tables
54817 + * only if we need them, i.e. for loading operations. */
54818 +
54819 + switch (gr_usermode->mode) {
54820 + case GR_STATUS:
54821 + if (gr_status & GR_READY) {
54822 + error = 1;
54823 + if (!gr_check_secure_terminal(current))
54824 + error = 3;
54825 + } else
54826 + error = 2;
54827 + goto out;
54828 + case GR_SHUTDOWN:
54829 + if ((gr_status & GR_READY)
54830 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54831 + stop_machine(gr_rbac_disable, NULL, NULL);
54832 + free_variables();
54833 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54834 + memset(gr_system_salt, 0, GR_SALT_LEN);
54835 + memset(gr_system_sum, 0, GR_SHA_LEN);
54836 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54837 + } else if (gr_status & GR_READY) {
54838 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54839 + error = -EPERM;
54840 + } else {
54841 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54842 + error = -EAGAIN;
54843 + }
54844 + break;
54845 + case GR_ENABLE:
54846 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54847 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54848 + else {
54849 + if (gr_status & GR_READY)
54850 + error = -EAGAIN;
54851 + else
54852 + error = error2;
54853 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54854 + }
54855 + break;
54856 + case GR_RELOAD:
54857 + if (!(gr_status & GR_READY)) {
54858 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54859 + error = -EAGAIN;
54860 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54861 + stop_machine(gr_rbac_disable, NULL, NULL);
54862 + free_variables();
54863 + error2 = gracl_init(gr_usermode);
54864 + if (!error2)
54865 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54866 + else {
54867 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54868 + error = error2;
54869 + }
54870 + } else {
54871 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54872 + error = -EPERM;
54873 + }
54874 + break;
54875 + case GR_SEGVMOD:
54876 + if (unlikely(!(gr_status & GR_READY))) {
54877 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54878 + error = -EAGAIN;
54879 + break;
54880 + }
54881 +
54882 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54883 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54884 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54885 + struct acl_subject_label *segvacl;
54886 + segvacl =
54887 + lookup_acl_subj_label(gr_usermode->segv_inode,
54888 + gr_usermode->segv_device,
54889 + current->role);
54890 + if (segvacl) {
54891 + segvacl->crashes = 0;
54892 + segvacl->expires = 0;
54893 + }
54894 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54895 + gr_remove_uid(gr_usermode->segv_uid);
54896 + }
54897 + } else {
54898 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54899 + error = -EPERM;
54900 + }
54901 + break;
54902 + case GR_SPROLE:
54903 + case GR_SPROLEPAM:
54904 + if (unlikely(!(gr_status & GR_READY))) {
54905 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54906 + error = -EAGAIN;
54907 + break;
54908 + }
54909 +
54910 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54911 + current->role->expires = 0;
54912 + current->role->auth_attempts = 0;
54913 + }
54914 +
54915 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54916 + time_after(current->role->expires, get_seconds())) {
54917 + error = -EBUSY;
54918 + goto out;
54919 + }
54920 +
54921 + if (lookup_special_role_auth
54922 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54923 + && ((!sprole_salt && !sprole_sum)
54924 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54925 + char *p = "";
54926 + assign_special_role(gr_usermode->sp_role);
54927 + read_lock(&tasklist_lock);
54928 + if (current->real_parent)
54929 + p = current->real_parent->role->rolename;
54930 + read_unlock(&tasklist_lock);
54931 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54932 + p, acl_sp_role_value);
54933 + } else {
54934 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54935 + error = -EPERM;
54936 + if(!(current->role->auth_attempts++))
54937 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54938 +
54939 + goto out;
54940 + }
54941 + break;
54942 + case GR_UNSPROLE:
54943 + if (unlikely(!(gr_status & GR_READY))) {
54944 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54945 + error = -EAGAIN;
54946 + break;
54947 + }
54948 +
54949 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54950 + char *p = "";
54951 + int i = 0;
54952 +
54953 + read_lock(&tasklist_lock);
54954 + if (current->real_parent) {
54955 + p = current->real_parent->role->rolename;
54956 + i = current->real_parent->acl_role_id;
54957 + }
54958 + read_unlock(&tasklist_lock);
54959 +
54960 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54961 + gr_set_acls(1);
54962 + } else {
54963 + error = -EPERM;
54964 + goto out;
54965 + }
54966 + break;
54967 + default:
54968 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54969 + error = -EINVAL;
54970 + break;
54971 + }
54972 +
54973 + if (error != -EPERM)
54974 + goto out;
54975 +
54976 + if(!(gr_auth_attempts++))
54977 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54978 +
54979 + out:
54980 + mutex_unlock(&gr_dev_mutex);
54981 + return error;
54982 +}
54983 +
54984 +/* must be called with
54985 + rcu_read_lock();
54986 + read_lock(&tasklist_lock);
54987 + read_lock(&grsec_exec_file_lock);
54988 +*/
54989 +int gr_apply_subject_to_task(struct task_struct *task)
54990 +{
54991 + struct acl_object_label *obj;
54992 + char *tmpname;
54993 + struct acl_subject_label *tmpsubj;
54994 + struct file *filp;
54995 + struct name_entry *nmatch;
54996 +
54997 + filp = task->exec_file;
54998 + if (filp == NULL)
54999 + return 0;
55000 +
55001 + /* the following is to apply the correct subject
55002 + on binaries running when the RBAC system
55003 + is enabled, when the binaries have been
55004 + replaced or deleted since their execution
55005 + -----
55006 + when the RBAC system starts, the inode/dev
55007 + from exec_file will be one the RBAC system
55008 + is unaware of. It only knows the inode/dev
55009 + of the present file on disk, or the absence
55010 + of it.
55011 + */
55012 + preempt_disable();
55013 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55014 +
55015 + nmatch = lookup_name_entry(tmpname);
55016 + preempt_enable();
55017 + tmpsubj = NULL;
55018 + if (nmatch) {
55019 + if (nmatch->deleted)
55020 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55021 + else
55022 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55023 + if (tmpsubj != NULL)
55024 + task->acl = tmpsubj;
55025 + }
55026 + if (tmpsubj == NULL)
55027 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55028 + task->role);
55029 + if (task->acl) {
55030 + task->is_writable = 0;
55031 + /* ignore additional mmap checks for processes that are writable
55032 + by the default ACL */
55033 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55034 + if (unlikely(obj->mode & GR_WRITE))
55035 + task->is_writable = 1;
55036 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55037 + if (unlikely(obj->mode & GR_WRITE))
55038 + task->is_writable = 1;
55039 +
55040 + gr_set_proc_res(task);
55041 +
55042 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55043 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55044 +#endif
55045 + } else {
55046 + return 1;
55047 + }
55048 +
55049 + return 0;
55050 +}
55051 +
55052 +int
55053 +gr_set_acls(const int type)
55054 +{
55055 + struct task_struct *task, *task2;
55056 + struct acl_role_label *role = current->role;
55057 + __u16 acl_role_id = current->acl_role_id;
55058 + const struct cred *cred;
55059 + int ret;
55060 +
55061 + rcu_read_lock();
55062 + read_lock(&tasklist_lock);
55063 + read_lock(&grsec_exec_file_lock);
55064 + do_each_thread(task2, task) {
55065 + /* check to see if we're called from the exit handler,
55066 + if so, only replace ACLs that have inherited the admin
55067 + ACL */
55068 +
55069 + if (type && (task->role != role ||
55070 + task->acl_role_id != acl_role_id))
55071 + continue;
55072 +
55073 + task->acl_role_id = 0;
55074 + task->acl_sp_role = 0;
55075 +
55076 + if (task->exec_file) {
55077 + cred = __task_cred(task);
55078 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55079 + ret = gr_apply_subject_to_task(task);
55080 + if (ret) {
55081 + read_unlock(&grsec_exec_file_lock);
55082 + read_unlock(&tasklist_lock);
55083 + rcu_read_unlock();
55084 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55085 + return ret;
55086 + }
55087 + } else {
55088 + // it's a kernel process
55089 + task->role = kernel_role;
55090 + task->acl = kernel_role->root_label;
55091 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55092 + task->acl->mode &= ~GR_PROCFIND;
55093 +#endif
55094 + }
55095 + } while_each_thread(task2, task);
55096 + read_unlock(&grsec_exec_file_lock);
55097 + read_unlock(&tasklist_lock);
55098 + rcu_read_unlock();
55099 +
55100 + return 0;
55101 +}
55102 +
55103 +void
55104 +gr_learn_resource(const struct task_struct *task,
55105 + const int res, const unsigned long wanted, const int gt)
55106 +{
55107 + struct acl_subject_label *acl;
55108 + const struct cred *cred;
55109 +
55110 + if (unlikely((gr_status & GR_READY) &&
55111 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55112 + goto skip_reslog;
55113 +
55114 +#ifdef CONFIG_GRKERNSEC_RESLOG
55115 + gr_log_resource(task, res, wanted, gt);
55116 +#endif
55117 + skip_reslog:
55118 +
55119 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55120 + return;
55121 +
55122 + acl = task->acl;
55123 +
55124 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55125 + !(acl->resmask & (1 << (unsigned short) res))))
55126 + return;
55127 +
55128 + if (wanted >= acl->res[res].rlim_cur) {
55129 + unsigned long res_add;
55130 +
55131 + res_add = wanted;
55132 + switch (res) {
55133 + case RLIMIT_CPU:
55134 + res_add += GR_RLIM_CPU_BUMP;
55135 + break;
55136 + case RLIMIT_FSIZE:
55137 + res_add += GR_RLIM_FSIZE_BUMP;
55138 + break;
55139 + case RLIMIT_DATA:
55140 + res_add += GR_RLIM_DATA_BUMP;
55141 + break;
55142 + case RLIMIT_STACK:
55143 + res_add += GR_RLIM_STACK_BUMP;
55144 + break;
55145 + case RLIMIT_CORE:
55146 + res_add += GR_RLIM_CORE_BUMP;
55147 + break;
55148 + case RLIMIT_RSS:
55149 + res_add += GR_RLIM_RSS_BUMP;
55150 + break;
55151 + case RLIMIT_NPROC:
55152 + res_add += GR_RLIM_NPROC_BUMP;
55153 + break;
55154 + case RLIMIT_NOFILE:
55155 + res_add += GR_RLIM_NOFILE_BUMP;
55156 + break;
55157 + case RLIMIT_MEMLOCK:
55158 + res_add += GR_RLIM_MEMLOCK_BUMP;
55159 + break;
55160 + case RLIMIT_AS:
55161 + res_add += GR_RLIM_AS_BUMP;
55162 + break;
55163 + case RLIMIT_LOCKS:
55164 + res_add += GR_RLIM_LOCKS_BUMP;
55165 + break;
55166 + case RLIMIT_SIGPENDING:
55167 + res_add += GR_RLIM_SIGPENDING_BUMP;
55168 + break;
55169 + case RLIMIT_MSGQUEUE:
55170 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55171 + break;
55172 + case RLIMIT_NICE:
55173 + res_add += GR_RLIM_NICE_BUMP;
55174 + break;
55175 + case RLIMIT_RTPRIO:
55176 + res_add += GR_RLIM_RTPRIO_BUMP;
55177 + break;
55178 + case RLIMIT_RTTIME:
55179 + res_add += GR_RLIM_RTTIME_BUMP;
55180 + break;
55181 + }
55182 +
55183 + acl->res[res].rlim_cur = res_add;
55184 +
55185 + if (wanted > acl->res[res].rlim_max)
55186 + acl->res[res].rlim_max = res_add;
55187 +
55188 + /* only log the subject filename, since resource logging is supported for
55189 + single-subject learning only */
55190 + rcu_read_lock();
55191 + cred = __task_cred(task);
55192 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55193 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55194 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55195 + "", (unsigned long) res, &task->signal->saved_ip);
55196 + rcu_read_unlock();
55197 + }
55198 +
55199 + return;
55200 +}
55201 +
55202 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55203 +void
55204 +pax_set_initial_flags(struct linux_binprm *bprm)
55205 +{
55206 + struct task_struct *task = current;
55207 + struct acl_subject_label *proc;
55208 + unsigned long flags;
55209 +
55210 + if (unlikely(!(gr_status & GR_READY)))
55211 + return;
55212 +
55213 + flags = pax_get_flags(task);
55214 +
55215 + proc = task->acl;
55216 +
55217 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55218 + flags &= ~MF_PAX_PAGEEXEC;
55219 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55220 + flags &= ~MF_PAX_SEGMEXEC;
55221 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55222 + flags &= ~MF_PAX_RANDMMAP;
55223 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55224 + flags &= ~MF_PAX_EMUTRAMP;
55225 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55226 + flags &= ~MF_PAX_MPROTECT;
55227 +
55228 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55229 + flags |= MF_PAX_PAGEEXEC;
55230 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55231 + flags |= MF_PAX_SEGMEXEC;
55232 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55233 + flags |= MF_PAX_RANDMMAP;
55234 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55235 + flags |= MF_PAX_EMUTRAMP;
55236 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55237 + flags |= MF_PAX_MPROTECT;
55238 +
55239 + pax_set_flags(task, flags);
55240 +
55241 + return;
55242 +}
55243 +#endif
55244 +
55245 +int
55246 +gr_handle_proc_ptrace(struct task_struct *task)
55247 +{
55248 + struct file *filp;
55249 + struct task_struct *tmp = task;
55250 + struct task_struct *curtemp = current;
55251 + __u32 retmode;
55252 +
55253 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55254 + if (unlikely(!(gr_status & GR_READY)))
55255 + return 0;
55256 +#endif
55257 +
55258 + read_lock(&tasklist_lock);
55259 + read_lock(&grsec_exec_file_lock);
55260 + filp = task->exec_file;
55261 +
55262 + while (tmp->pid > 0) {
55263 + if (tmp == curtemp)
55264 + break;
55265 + tmp = tmp->real_parent;
55266 + }
55267 +
55268 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55269 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55270 + read_unlock(&grsec_exec_file_lock);
55271 + read_unlock(&tasklist_lock);
55272 + return 1;
55273 + }
55274 +
55275 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55276 + if (!(gr_status & GR_READY)) {
55277 + read_unlock(&grsec_exec_file_lock);
55278 + read_unlock(&tasklist_lock);
55279 + return 0;
55280 + }
55281 +#endif
55282 +
55283 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55284 + read_unlock(&grsec_exec_file_lock);
55285 + read_unlock(&tasklist_lock);
55286 +
55287 + if (retmode & GR_NOPTRACE)
55288 + return 1;
55289 +
55290 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55291 + && (current->acl != task->acl || (current->acl != current->role->root_label
55292 + && current->pid != task->pid)))
55293 + return 1;
55294 +
55295 + return 0;
55296 +}
55297 +
55298 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55299 +{
55300 + if (unlikely(!(gr_status & GR_READY)))
55301 + return;
55302 +
55303 + if (!(current->role->roletype & GR_ROLE_GOD))
55304 + return;
55305 +
55306 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55307 + p->role->rolename, gr_task_roletype_to_char(p),
55308 + p->acl->filename);
55309 +}
55310 +
55311 +int
55312 +gr_handle_ptrace(struct task_struct *task, const long request)
55313 +{
55314 + struct task_struct *tmp = task;
55315 + struct task_struct *curtemp = current;
55316 + __u32 retmode;
55317 +
55318 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55319 + if (unlikely(!(gr_status & GR_READY)))
55320 + return 0;
55321 +#endif
55322 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55323 + read_lock(&tasklist_lock);
55324 + while (tmp->pid > 0) {
55325 + if (tmp == curtemp)
55326 + break;
55327 + tmp = tmp->real_parent;
55328 + }
55329 +
55330 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55331 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55332 + read_unlock(&tasklist_lock);
55333 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55334 + return 1;
55335 + }
55336 + read_unlock(&tasklist_lock);
55337 + }
55338 +
55339 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55340 + if (!(gr_status & GR_READY))
55341 + return 0;
55342 +#endif
55343 +
55344 + read_lock(&grsec_exec_file_lock);
55345 + if (unlikely(!task->exec_file)) {
55346 + read_unlock(&grsec_exec_file_lock);
55347 + return 0;
55348 + }
55349 +
55350 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55351 + read_unlock(&grsec_exec_file_lock);
55352 +
55353 + if (retmode & GR_NOPTRACE) {
55354 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55355 + return 1;
55356 + }
55357 +
55358 + if (retmode & GR_PTRACERD) {
55359 + switch (request) {
55360 + case PTRACE_SEIZE:
55361 + case PTRACE_POKETEXT:
55362 + case PTRACE_POKEDATA:
55363 + case PTRACE_POKEUSR:
55364 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55365 + case PTRACE_SETREGS:
55366 + case PTRACE_SETFPREGS:
55367 +#endif
55368 +#ifdef CONFIG_X86
55369 + case PTRACE_SETFPXREGS:
55370 +#endif
55371 +#ifdef CONFIG_ALTIVEC
55372 + case PTRACE_SETVRREGS:
55373 +#endif
55374 + return 1;
55375 + default:
55376 + return 0;
55377 + }
55378 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55379 + !(current->role->roletype & GR_ROLE_GOD) &&
55380 + (current->acl != task->acl)) {
55381 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55382 + return 1;
55383 + }
55384 +
55385 + return 0;
55386 +}
55387 +
55388 +static int is_writable_mmap(const struct file *filp)
55389 +{
55390 + struct task_struct *task = current;
55391 + struct acl_object_label *obj, *obj2;
55392 +
55393 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55394 + !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))) {
55395 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55396 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55397 + task->role->root_label);
55398 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55399 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55400 + return 1;
55401 + }
55402 + }
55403 + return 0;
55404 +}
55405 +
55406 +int
55407 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55408 +{
55409 + __u32 mode;
55410 +
55411 + if (unlikely(!file || !(prot & PROT_EXEC)))
55412 + return 1;
55413 +
55414 + if (is_writable_mmap(file))
55415 + return 0;
55416 +
55417 + mode =
55418 + gr_search_file(file->f_path.dentry,
55419 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55420 + file->f_path.mnt);
55421 +
55422 + if (!gr_tpe_allow(file))
55423 + return 0;
55424 +
55425 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55426 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55427 + return 0;
55428 + } else if (unlikely(!(mode & GR_EXEC))) {
55429 + return 0;
55430 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55431 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55432 + return 1;
55433 + }
55434 +
55435 + return 1;
55436 +}
55437 +
55438 +int
55439 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55440 +{
55441 + __u32 mode;
55442 +
55443 + if (unlikely(!file || !(prot & PROT_EXEC)))
55444 + return 1;
55445 +
55446 + if (is_writable_mmap(file))
55447 + return 0;
55448 +
55449 + mode =
55450 + gr_search_file(file->f_path.dentry,
55451 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55452 + file->f_path.mnt);
55453 +
55454 + if (!gr_tpe_allow(file))
55455 + return 0;
55456 +
55457 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55458 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55459 + return 0;
55460 + } else if (unlikely(!(mode & GR_EXEC))) {
55461 + return 0;
55462 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55463 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55464 + return 1;
55465 + }
55466 +
55467 + return 1;
55468 +}
55469 +
55470 +void
55471 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55472 +{
55473 + unsigned long runtime;
55474 + unsigned long cputime;
55475 + unsigned int wday, cday;
55476 + __u8 whr, chr;
55477 + __u8 wmin, cmin;
55478 + __u8 wsec, csec;
55479 + struct timespec timeval;
55480 +
55481 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55482 + !(task->acl->mode & GR_PROCACCT)))
55483 + return;
55484 +
55485 + do_posix_clock_monotonic_gettime(&timeval);
55486 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55487 + wday = runtime / (3600 * 24);
55488 + runtime -= wday * (3600 * 24);
55489 + whr = runtime / 3600;
55490 + runtime -= whr * 3600;
55491 + wmin = runtime / 60;
55492 + runtime -= wmin * 60;
55493 + wsec = runtime;
55494 +
55495 + cputime = (task->utime + task->stime) / HZ;
55496 + cday = cputime / (3600 * 24);
55497 + cputime -= cday * (3600 * 24);
55498 + chr = cputime / 3600;
55499 + cputime -= chr * 3600;
55500 + cmin = cputime / 60;
55501 + cputime -= cmin * 60;
55502 + csec = cputime;
55503 +
55504 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55505 +
55506 + return;
55507 +}
55508 +
55509 +void gr_set_kernel_label(struct task_struct *task)
55510 +{
55511 + if (gr_status & GR_READY) {
55512 + task->role = kernel_role;
55513 + task->acl = kernel_role->root_label;
55514 + }
55515 + return;
55516 +}
55517 +
55518 +#ifdef CONFIG_TASKSTATS
55519 +int gr_is_taskstats_denied(int pid)
55520 +{
55521 + struct task_struct *task;
55522 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55523 + const struct cred *cred;
55524 +#endif
55525 + int ret = 0;
55526 +
55527 + /* restrict taskstats viewing to un-chrooted root users
55528 + who have the 'view' subject flag if the RBAC system is enabled
55529 + */
55530 +
55531 + rcu_read_lock();
55532 + read_lock(&tasklist_lock);
55533 + task = find_task_by_vpid(pid);
55534 + if (task) {
55535 +#ifdef CONFIG_GRKERNSEC_CHROOT
55536 + if (proc_is_chrooted(task))
55537 + ret = -EACCES;
55538 +#endif
55539 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55540 + cred = __task_cred(task);
55541 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55542 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55543 + ret = -EACCES;
55544 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55545 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55546 + ret = -EACCES;
55547 +#endif
55548 +#endif
55549 + if (gr_status & GR_READY) {
55550 + if (!(task->acl->mode & GR_VIEW))
55551 + ret = -EACCES;
55552 + }
55553 + } else
55554 + ret = -ENOENT;
55555 +
55556 + read_unlock(&tasklist_lock);
55557 + rcu_read_unlock();
55558 +
55559 + return ret;
55560 +}
55561 +#endif
55562 +
55563 +/* AUXV entries are filled via a descendant of search_binary_handler
55564 + after we've already applied the subject for the target
55565 +*/
55566 +int gr_acl_enable_at_secure(void)
55567 +{
55568 + if (unlikely(!(gr_status & GR_READY)))
55569 + return 0;
55570 +
55571 + if (current->acl->mode & GR_ATSECURE)
55572 + return 1;
55573 +
55574 + return 0;
55575 +}
55576 +
55577 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55578 +{
55579 + struct task_struct *task = current;
55580 + struct dentry *dentry = file->f_path.dentry;
55581 + struct vfsmount *mnt = file->f_path.mnt;
55582 + struct acl_object_label *obj, *tmp;
55583 + struct acl_subject_label *subj;
55584 + unsigned int bufsize;
55585 + int is_not_root;
55586 + char *path;
55587 + dev_t dev = __get_dev(dentry);
55588 +
55589 + if (unlikely(!(gr_status & GR_READY)))
55590 + return 1;
55591 +
55592 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55593 + return 1;
55594 +
55595 + /* ignore Eric Biederman */
55596 + if (IS_PRIVATE(dentry->d_inode))
55597 + return 1;
55598 +
55599 + subj = task->acl;
55600 + read_lock(&gr_inode_lock);
55601 + do {
55602 + obj = lookup_acl_obj_label(ino, dev, subj);
55603 + if (obj != NULL) {
55604 + read_unlock(&gr_inode_lock);
55605 + return (obj->mode & GR_FIND) ? 1 : 0;
55606 + }
55607 + } while ((subj = subj->parent_subject));
55608 + read_unlock(&gr_inode_lock);
55609 +
55610 + /* this is purely an optimization since we're looking for an object
55611 + for the directory we're doing a readdir on
55612 + if it's possible for any globbed object to match the entry we're
55613 + filling into the directory, then the object we find here will be
55614 + an anchor point with attached globbed objects
55615 + */
55616 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55617 + if (obj->globbed == NULL)
55618 + return (obj->mode & GR_FIND) ? 1 : 0;
55619 +
55620 + is_not_root = ((obj->filename[0] == '/') &&
55621 + (obj->filename[1] == '\0')) ? 0 : 1;
55622 + bufsize = PAGE_SIZE - namelen - is_not_root;
55623 +
55624 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55625 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55626 + return 1;
55627 +
55628 + preempt_disable();
55629 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55630 + bufsize);
55631 +
55632 + bufsize = strlen(path);
55633 +
55634 + /* if base is "/", don't append an additional slash */
55635 + if (is_not_root)
55636 + *(path + bufsize) = '/';
55637 + memcpy(path + bufsize + is_not_root, name, namelen);
55638 + *(path + bufsize + namelen + is_not_root) = '\0';
55639 +
55640 + tmp = obj->globbed;
55641 + while (tmp) {
55642 + if (!glob_match(tmp->filename, path)) {
55643 + preempt_enable();
55644 + return (tmp->mode & GR_FIND) ? 1 : 0;
55645 + }
55646 + tmp = tmp->next;
55647 + }
55648 + preempt_enable();
55649 + return (obj->mode & GR_FIND) ? 1 : 0;
55650 +}
55651 +
55652 +void gr_put_exec_file(struct task_struct *task)
55653 +{
55654 + struct file *filp;
55655 +
55656 + write_lock(&grsec_exec_file_lock);
55657 + filp = task->exec_file;
55658 + task->exec_file = NULL;
55659 + write_unlock(&grsec_exec_file_lock);
55660 +
55661 + if (filp)
55662 + fput(filp);
55663 +
55664 + return;
55665 +}
55666 +
55667 +
55668 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55669 +EXPORT_SYMBOL(gr_acl_is_enabled);
55670 +#endif
55671 +EXPORT_SYMBOL(gr_learn_resource);
55672 +EXPORT_SYMBOL(gr_set_kernel_label);
55673 +#ifdef CONFIG_SECURITY
55674 +EXPORT_SYMBOL(gr_check_user_change);
55675 +EXPORT_SYMBOL(gr_check_group_change);
55676 +#endif
55677 +
55678 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55679 new file mode 100644
55680 index 0000000..34fefda
55681 --- /dev/null
55682 +++ b/grsecurity/gracl_alloc.c
55683 @@ -0,0 +1,105 @@
55684 +#include <linux/kernel.h>
55685 +#include <linux/mm.h>
55686 +#include <linux/slab.h>
55687 +#include <linux/vmalloc.h>
55688 +#include <linux/gracl.h>
55689 +#include <linux/grsecurity.h>
55690 +
55691 +static unsigned long alloc_stack_next = 1;
55692 +static unsigned long alloc_stack_size = 1;
55693 +static void **alloc_stack;
55694 +
55695 +static __inline__ int
55696 +alloc_pop(void)
55697 +{
55698 + if (alloc_stack_next == 1)
55699 + return 0;
55700 +
55701 + kfree(alloc_stack[alloc_stack_next - 2]);
55702 +
55703 + alloc_stack_next--;
55704 +
55705 + return 1;
55706 +}
55707 +
55708 +static __inline__ int
55709 +alloc_push(void *buf)
55710 +{
55711 + if (alloc_stack_next >= alloc_stack_size)
55712 + return 1;
55713 +
55714 + alloc_stack[alloc_stack_next - 1] = buf;
55715 +
55716 + alloc_stack_next++;
55717 +
55718 + return 0;
55719 +}
55720 +
55721 +void *
55722 +acl_alloc(unsigned long len)
55723 +{
55724 + void *ret = NULL;
55725 +
55726 + if (!len || len > PAGE_SIZE)
55727 + goto out;
55728 +
55729 + ret = kmalloc(len, GFP_KERNEL);
55730 +
55731 + if (ret) {
55732 + if (alloc_push(ret)) {
55733 + kfree(ret);
55734 + ret = NULL;
55735 + }
55736 + }
55737 +
55738 +out:
55739 + return ret;
55740 +}
55741 +
55742 +void *
55743 +acl_alloc_num(unsigned long num, unsigned long len)
55744 +{
55745 + if (!len || (num > (PAGE_SIZE / len)))
55746 + return NULL;
55747 +
55748 + return acl_alloc(num * len);
55749 +}
55750 +
55751 +void
55752 +acl_free_all(void)
55753 +{
55754 + if (gr_acl_is_enabled() || !alloc_stack)
55755 + return;
55756 +
55757 + while (alloc_pop()) ;
55758 +
55759 + if (alloc_stack) {
55760 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55761 + kfree(alloc_stack);
55762 + else
55763 + vfree(alloc_stack);
55764 + }
55765 +
55766 + alloc_stack = NULL;
55767 + alloc_stack_size = 1;
55768 + alloc_stack_next = 1;
55769 +
55770 + return;
55771 +}
55772 +
55773 +int
55774 +acl_alloc_stack_init(unsigned long size)
55775 +{
55776 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55777 + alloc_stack =
55778 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55779 + else
55780 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55781 +
55782 + alloc_stack_size = size;
55783 +
55784 + if (!alloc_stack)
55785 + return 0;
55786 + else
55787 + return 1;
55788 +}
55789 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55790 new file mode 100644
55791 index 0000000..6d21049
55792 --- /dev/null
55793 +++ b/grsecurity/gracl_cap.c
55794 @@ -0,0 +1,110 @@
55795 +#include <linux/kernel.h>
55796 +#include <linux/module.h>
55797 +#include <linux/sched.h>
55798 +#include <linux/gracl.h>
55799 +#include <linux/grsecurity.h>
55800 +#include <linux/grinternal.h>
55801 +
55802 +extern const char *captab_log[];
55803 +extern int captab_log_entries;
55804 +
55805 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55806 +{
55807 + struct acl_subject_label *curracl;
55808 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55809 + kernel_cap_t cap_audit = __cap_empty_set;
55810 +
55811 + if (!gr_acl_is_enabled())
55812 + return 1;
55813 +
55814 + curracl = task->acl;
55815 +
55816 + cap_drop = curracl->cap_lower;
55817 + cap_mask = curracl->cap_mask;
55818 + cap_audit = curracl->cap_invert_audit;
55819 +
55820 + while ((curracl = curracl->parent_subject)) {
55821 + /* if the cap isn't specified in the current computed mask but is specified in the
55822 + current level subject, and is lowered in the current level subject, then add
55823 + it to the set of dropped capabilities
55824 + otherwise, add the current level subject's mask to the current computed mask
55825 + */
55826 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55827 + cap_raise(cap_mask, cap);
55828 + if (cap_raised(curracl->cap_lower, cap))
55829 + cap_raise(cap_drop, cap);
55830 + if (cap_raised(curracl->cap_invert_audit, cap))
55831 + cap_raise(cap_audit, cap);
55832 + }
55833 + }
55834 +
55835 + if (!cap_raised(cap_drop, cap)) {
55836 + if (cap_raised(cap_audit, cap))
55837 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55838 + return 1;
55839 + }
55840 +
55841 + curracl = task->acl;
55842 +
55843 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55844 + && cap_raised(cred->cap_effective, cap)) {
55845 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55846 + task->role->roletype, cred->uid,
55847 + cred->gid, task->exec_file ?
55848 + gr_to_filename(task->exec_file->f_path.dentry,
55849 + task->exec_file->f_path.mnt) : curracl->filename,
55850 + curracl->filename, 0UL,
55851 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55852 + return 1;
55853 + }
55854 +
55855 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55856 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55857 +
55858 + return 0;
55859 +}
55860 +
55861 +int
55862 +gr_acl_is_capable(const int cap)
55863 +{
55864 + return gr_task_acl_is_capable(current, current_cred(), cap);
55865 +}
55866 +
55867 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55868 +{
55869 + struct acl_subject_label *curracl;
55870 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55871 +
55872 + if (!gr_acl_is_enabled())
55873 + return 1;
55874 +
55875 + curracl = task->acl;
55876 +
55877 + cap_drop = curracl->cap_lower;
55878 + cap_mask = curracl->cap_mask;
55879 +
55880 + while ((curracl = curracl->parent_subject)) {
55881 + /* if the cap isn't specified in the current computed mask but is specified in the
55882 + current level subject, and is lowered in the current level subject, then add
55883 + it to the set of dropped capabilities
55884 + otherwise, add the current level subject's mask to the current computed mask
55885 + */
55886 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55887 + cap_raise(cap_mask, cap);
55888 + if (cap_raised(curracl->cap_lower, cap))
55889 + cap_raise(cap_drop, cap);
55890 + }
55891 + }
55892 +
55893 + if (!cap_raised(cap_drop, cap))
55894 + return 1;
55895 +
55896 + return 0;
55897 +}
55898 +
55899 +int
55900 +gr_acl_is_capable_nolog(const int cap)
55901 +{
55902 + return gr_task_acl_is_capable_nolog(current, cap);
55903 +}
55904 +
55905 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55906 new file mode 100644
55907 index 0000000..decb035
55908 --- /dev/null
55909 +++ b/grsecurity/gracl_fs.c
55910 @@ -0,0 +1,437 @@
55911 +#include <linux/kernel.h>
55912 +#include <linux/sched.h>
55913 +#include <linux/types.h>
55914 +#include <linux/fs.h>
55915 +#include <linux/file.h>
55916 +#include <linux/stat.h>
55917 +#include <linux/grsecurity.h>
55918 +#include <linux/grinternal.h>
55919 +#include <linux/gracl.h>
55920 +
55921 +umode_t
55922 +gr_acl_umask(void)
55923 +{
55924 + if (unlikely(!gr_acl_is_enabled()))
55925 + return 0;
55926 +
55927 + return current->role->umask;
55928 +}
55929 +
55930 +__u32
55931 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55932 + const struct vfsmount * mnt)
55933 +{
55934 + __u32 mode;
55935 +
55936 + if (unlikely(!dentry->d_inode))
55937 + return GR_FIND;
55938 +
55939 + mode =
55940 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55941 +
55942 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55943 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55944 + return mode;
55945 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55946 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55947 + return 0;
55948 + } else if (unlikely(!(mode & GR_FIND)))
55949 + return 0;
55950 +
55951 + return GR_FIND;
55952 +}
55953 +
55954 +__u32
55955 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55956 + int acc_mode)
55957 +{
55958 + __u32 reqmode = GR_FIND;
55959 + __u32 mode;
55960 +
55961 + if (unlikely(!dentry->d_inode))
55962 + return reqmode;
55963 +
55964 + if (acc_mode & MAY_APPEND)
55965 + reqmode |= GR_APPEND;
55966 + else if (acc_mode & MAY_WRITE)
55967 + reqmode |= GR_WRITE;
55968 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55969 + reqmode |= GR_READ;
55970 +
55971 + mode =
55972 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55973 + mnt);
55974 +
55975 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55976 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55977 + reqmode & GR_READ ? " reading" : "",
55978 + reqmode & GR_WRITE ? " writing" : reqmode &
55979 + GR_APPEND ? " appending" : "");
55980 + return reqmode;
55981 + } else
55982 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55983 + {
55984 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55985 + reqmode & GR_READ ? " reading" : "",
55986 + reqmode & GR_WRITE ? " writing" : reqmode &
55987 + GR_APPEND ? " appending" : "");
55988 + return 0;
55989 + } else if (unlikely((mode & reqmode) != reqmode))
55990 + return 0;
55991 +
55992 + return reqmode;
55993 +}
55994 +
55995 +__u32
55996 +gr_acl_handle_creat(const struct dentry * dentry,
55997 + const struct dentry * p_dentry,
55998 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55999 + const int imode)
56000 +{
56001 + __u32 reqmode = GR_WRITE | GR_CREATE;
56002 + __u32 mode;
56003 +
56004 + if (acc_mode & MAY_APPEND)
56005 + reqmode |= GR_APPEND;
56006 + // if a directory was required or the directory already exists, then
56007 + // don't count this open as a read
56008 + if ((acc_mode & MAY_READ) &&
56009 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56010 + reqmode |= GR_READ;
56011 + if ((open_flags & O_CREAT) &&
56012 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56013 + reqmode |= GR_SETID;
56014 +
56015 + mode =
56016 + gr_check_create(dentry, p_dentry, p_mnt,
56017 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56018 +
56019 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56020 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56021 + reqmode & GR_READ ? " reading" : "",
56022 + reqmode & GR_WRITE ? " writing" : reqmode &
56023 + GR_APPEND ? " appending" : "");
56024 + return reqmode;
56025 + } else
56026 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56027 + {
56028 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56029 + reqmode & GR_READ ? " reading" : "",
56030 + reqmode & GR_WRITE ? " writing" : reqmode &
56031 + GR_APPEND ? " appending" : "");
56032 + return 0;
56033 + } else if (unlikely((mode & reqmode) != reqmode))
56034 + return 0;
56035 +
56036 + return reqmode;
56037 +}
56038 +
56039 +__u32
56040 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56041 + const int fmode)
56042 +{
56043 + __u32 mode, reqmode = GR_FIND;
56044 +
56045 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56046 + reqmode |= GR_EXEC;
56047 + if (fmode & S_IWOTH)
56048 + reqmode |= GR_WRITE;
56049 + if (fmode & S_IROTH)
56050 + reqmode |= GR_READ;
56051 +
56052 + mode =
56053 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56054 + mnt);
56055 +
56056 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56057 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56058 + reqmode & GR_READ ? " reading" : "",
56059 + reqmode & GR_WRITE ? " writing" : "",
56060 + reqmode & GR_EXEC ? " executing" : "");
56061 + return reqmode;
56062 + } else
56063 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56064 + {
56065 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56066 + reqmode & GR_READ ? " reading" : "",
56067 + reqmode & GR_WRITE ? " writing" : "",
56068 + reqmode & GR_EXEC ? " executing" : "");
56069 + return 0;
56070 + } else if (unlikely((mode & reqmode) != reqmode))
56071 + return 0;
56072 +
56073 + return reqmode;
56074 +}
56075 +
56076 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56077 +{
56078 + __u32 mode;
56079 +
56080 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56081 +
56082 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56083 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56084 + return mode;
56085 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56086 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56087 + return 0;
56088 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56089 + return 0;
56090 +
56091 + return (reqmode);
56092 +}
56093 +
56094 +__u32
56095 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56096 +{
56097 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56098 +}
56099 +
56100 +__u32
56101 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56102 +{
56103 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56104 +}
56105 +
56106 +__u32
56107 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56108 +{
56109 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56110 +}
56111 +
56112 +__u32
56113 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56114 +{
56115 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56116 +}
56117 +
56118 +__u32
56119 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56120 + umode_t *modeptr)
56121 +{
56122 + umode_t mode;
56123 +
56124 + *modeptr &= ~gr_acl_umask();
56125 + mode = *modeptr;
56126 +
56127 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56128 + return 1;
56129 +
56130 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56131 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56132 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56133 + GR_CHMOD_ACL_MSG);
56134 + } else {
56135 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56136 + }
56137 +}
56138 +
56139 +__u32
56140 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56141 +{
56142 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56143 +}
56144 +
56145 +__u32
56146 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56147 +{
56148 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56149 +}
56150 +
56151 +__u32
56152 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56153 +{
56154 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56155 +}
56156 +
56157 +__u32
56158 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56159 +{
56160 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56161 + GR_UNIXCONNECT_ACL_MSG);
56162 +}
56163 +
56164 +/* hardlinks require at minimum create and link permission,
56165 + any additional privilege required is based on the
56166 + privilege of the file being linked to
56167 +*/
56168 +__u32
56169 +gr_acl_handle_link(const struct dentry * new_dentry,
56170 + const struct dentry * parent_dentry,
56171 + const struct vfsmount * parent_mnt,
56172 + const struct dentry * old_dentry,
56173 + const struct vfsmount * old_mnt, const struct filename *to)
56174 +{
56175 + __u32 mode;
56176 + __u32 needmode = GR_CREATE | GR_LINK;
56177 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56178 +
56179 + mode =
56180 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56181 + old_mnt);
56182 +
56183 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56184 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
56185 + return mode;
56186 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56187 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
56188 + return 0;
56189 + } else if (unlikely((mode & needmode) != needmode))
56190 + return 0;
56191 +
56192 + return 1;
56193 +}
56194 +
56195 +__u32
56196 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56197 + const struct dentry * parent_dentry,
56198 + const struct vfsmount * parent_mnt, const struct filename *from)
56199 +{
56200 + __u32 needmode = GR_WRITE | GR_CREATE;
56201 + __u32 mode;
56202 +
56203 + mode =
56204 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56205 + GR_CREATE | GR_AUDIT_CREATE |
56206 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56207 +
56208 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56209 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
56210 + return mode;
56211 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56212 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
56213 + return 0;
56214 + } else if (unlikely((mode & needmode) != needmode))
56215 + return 0;
56216 +
56217 + return (GR_WRITE | GR_CREATE);
56218 +}
56219 +
56220 +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)
56221 +{
56222 + __u32 mode;
56223 +
56224 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56225 +
56226 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56227 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56228 + return mode;
56229 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56230 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56231 + return 0;
56232 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56233 + return 0;
56234 +
56235 + return (reqmode);
56236 +}
56237 +
56238 +__u32
56239 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56240 + const struct dentry * parent_dentry,
56241 + const struct vfsmount * parent_mnt,
56242 + const int mode)
56243 +{
56244 + __u32 reqmode = GR_WRITE | GR_CREATE;
56245 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56246 + reqmode |= GR_SETID;
56247 +
56248 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56249 + reqmode, GR_MKNOD_ACL_MSG);
56250 +}
56251 +
56252 +__u32
56253 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56254 + const struct dentry *parent_dentry,
56255 + const struct vfsmount *parent_mnt)
56256 +{
56257 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56258 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56259 +}
56260 +
56261 +#define RENAME_CHECK_SUCCESS(old, new) \
56262 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56263 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56264 +
56265 +int
56266 +gr_acl_handle_rename(struct dentry *new_dentry,
56267 + struct dentry *parent_dentry,
56268 + const struct vfsmount *parent_mnt,
56269 + struct dentry *old_dentry,
56270 + struct inode *old_parent_inode,
56271 + struct vfsmount *old_mnt, const struct filename *newname)
56272 +{
56273 + __u32 comp1, comp2;
56274 + int error = 0;
56275 +
56276 + if (unlikely(!gr_acl_is_enabled()))
56277 + return 0;
56278 +
56279 + if (!new_dentry->d_inode) {
56280 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56281 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56282 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56283 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56284 + GR_DELETE | GR_AUDIT_DELETE |
56285 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56286 + GR_SUPPRESS, old_mnt);
56287 + } else {
56288 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56289 + GR_CREATE | GR_DELETE |
56290 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56291 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56292 + GR_SUPPRESS, parent_mnt);
56293 + comp2 =
56294 + gr_search_file(old_dentry,
56295 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56296 + GR_DELETE | GR_AUDIT_DELETE |
56297 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56298 + }
56299 +
56300 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56301 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56302 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
56303 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56304 + && !(comp2 & GR_SUPPRESS)) {
56305 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
56306 + error = -EACCES;
56307 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56308 + error = -EACCES;
56309 +
56310 + return error;
56311 +}
56312 +
56313 +void
56314 +gr_acl_handle_exit(void)
56315 +{
56316 + u16 id;
56317 + char *rolename;
56318 + struct file *exec_file;
56319 +
56320 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56321 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56322 + id = current->acl_role_id;
56323 + rolename = current->role->rolename;
56324 + gr_set_acls(1);
56325 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56326 + }
56327 +
56328 + write_lock(&grsec_exec_file_lock);
56329 + exec_file = current->exec_file;
56330 + current->exec_file = NULL;
56331 + write_unlock(&grsec_exec_file_lock);
56332 +
56333 + if (exec_file)
56334 + fput(exec_file);
56335 +}
56336 +
56337 +int
56338 +gr_acl_handle_procpidmem(const struct task_struct *task)
56339 +{
56340 + if (unlikely(!gr_acl_is_enabled()))
56341 + return 0;
56342 +
56343 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56344 + return -EACCES;
56345 +
56346 + return 0;
56347 +}
56348 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56349 new file mode 100644
56350 index 0000000..58800a7
56351 --- /dev/null
56352 +++ b/grsecurity/gracl_ip.c
56353 @@ -0,0 +1,384 @@
56354 +#include <linux/kernel.h>
56355 +#include <asm/uaccess.h>
56356 +#include <asm/errno.h>
56357 +#include <net/sock.h>
56358 +#include <linux/file.h>
56359 +#include <linux/fs.h>
56360 +#include <linux/net.h>
56361 +#include <linux/in.h>
56362 +#include <linux/skbuff.h>
56363 +#include <linux/ip.h>
56364 +#include <linux/udp.h>
56365 +#include <linux/types.h>
56366 +#include <linux/sched.h>
56367 +#include <linux/netdevice.h>
56368 +#include <linux/inetdevice.h>
56369 +#include <linux/gracl.h>
56370 +#include <linux/grsecurity.h>
56371 +#include <linux/grinternal.h>
56372 +
56373 +#define GR_BIND 0x01
56374 +#define GR_CONNECT 0x02
56375 +#define GR_INVERT 0x04
56376 +#define GR_BINDOVERRIDE 0x08
56377 +#define GR_CONNECTOVERRIDE 0x10
56378 +#define GR_SOCK_FAMILY 0x20
56379 +
56380 +static const char * gr_protocols[IPPROTO_MAX] = {
56381 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56382 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56383 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56384 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56385 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56386 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56387 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56388 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56389 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56390 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56391 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56392 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56393 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56394 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56395 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56396 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56397 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56398 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56399 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56400 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56401 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56402 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56403 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56404 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56405 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56406 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56407 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56408 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56409 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56410 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56411 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56412 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56413 + };
56414 +
56415 +static const char * gr_socktypes[SOCK_MAX] = {
56416 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56417 + "unknown:7", "unknown:8", "unknown:9", "packet"
56418 + };
56419 +
56420 +static const char * gr_sockfamilies[AF_MAX+1] = {
56421 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56422 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56423 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56424 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56425 + };
56426 +
56427 +const char *
56428 +gr_proto_to_name(unsigned char proto)
56429 +{
56430 + return gr_protocols[proto];
56431 +}
56432 +
56433 +const char *
56434 +gr_socktype_to_name(unsigned char type)
56435 +{
56436 + return gr_socktypes[type];
56437 +}
56438 +
56439 +const char *
56440 +gr_sockfamily_to_name(unsigned char family)
56441 +{
56442 + return gr_sockfamilies[family];
56443 +}
56444 +
56445 +int
56446 +gr_search_socket(const int domain, const int type, const int protocol)
56447 +{
56448 + struct acl_subject_label *curr;
56449 + const struct cred *cred = current_cred();
56450 +
56451 + if (unlikely(!gr_acl_is_enabled()))
56452 + goto exit;
56453 +
56454 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56455 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56456 + goto exit; // let the kernel handle it
56457 +
56458 + curr = current->acl;
56459 +
56460 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56461 + /* the family is allowed, if this is PF_INET allow it only if
56462 + the extra sock type/protocol checks pass */
56463 + if (domain == PF_INET)
56464 + goto inet_check;
56465 + goto exit;
56466 + } else {
56467 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56468 + __u32 fakeip = 0;
56469 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56470 + current->role->roletype, cred->uid,
56471 + cred->gid, current->exec_file ?
56472 + gr_to_filename(current->exec_file->f_path.dentry,
56473 + current->exec_file->f_path.mnt) :
56474 + curr->filename, curr->filename,
56475 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56476 + &current->signal->saved_ip);
56477 + goto exit;
56478 + }
56479 + goto exit_fail;
56480 + }
56481 +
56482 +inet_check:
56483 + /* the rest of this checking is for IPv4 only */
56484 + if (!curr->ips)
56485 + goto exit;
56486 +
56487 + if ((curr->ip_type & (1 << type)) &&
56488 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56489 + goto exit;
56490 +
56491 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56492 + /* we don't place acls on raw sockets , and sometimes
56493 + dgram/ip sockets are opened for ioctl and not
56494 + bind/connect, so we'll fake a bind learn log */
56495 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56496 + __u32 fakeip = 0;
56497 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56498 + current->role->roletype, cred->uid,
56499 + cred->gid, current->exec_file ?
56500 + gr_to_filename(current->exec_file->f_path.dentry,
56501 + current->exec_file->f_path.mnt) :
56502 + curr->filename, curr->filename,
56503 + &fakeip, 0, type,
56504 + protocol, GR_CONNECT, &current->signal->saved_ip);
56505 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56506 + __u32 fakeip = 0;
56507 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56508 + current->role->roletype, cred->uid,
56509 + cred->gid, current->exec_file ?
56510 + gr_to_filename(current->exec_file->f_path.dentry,
56511 + current->exec_file->f_path.mnt) :
56512 + curr->filename, curr->filename,
56513 + &fakeip, 0, type,
56514 + protocol, GR_BIND, &current->signal->saved_ip);
56515 + }
56516 + /* we'll log when they use connect or bind */
56517 + goto exit;
56518 + }
56519 +
56520 +exit_fail:
56521 + if (domain == PF_INET)
56522 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56523 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56524 + else
56525 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56526 + gr_socktype_to_name(type), protocol);
56527 +
56528 + return 0;
56529 +exit:
56530 + return 1;
56531 +}
56532 +
56533 +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)
56534 +{
56535 + if ((ip->mode & mode) &&
56536 + (ip_port >= ip->low) &&
56537 + (ip_port <= ip->high) &&
56538 + ((ntohl(ip_addr) & our_netmask) ==
56539 + (ntohl(our_addr) & our_netmask))
56540 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56541 + && (ip->type & (1 << type))) {
56542 + if (ip->mode & GR_INVERT)
56543 + return 2; // specifically denied
56544 + else
56545 + return 1; // allowed
56546 + }
56547 +
56548 + return 0; // not specifically allowed, may continue parsing
56549 +}
56550 +
56551 +static int
56552 +gr_search_connectbind(const int full_mode, struct sock *sk,
56553 + struct sockaddr_in *addr, const int type)
56554 +{
56555 + char iface[IFNAMSIZ] = {0};
56556 + struct acl_subject_label *curr;
56557 + struct acl_ip_label *ip;
56558 + struct inet_sock *isk;
56559 + struct net_device *dev;
56560 + struct in_device *idev;
56561 + unsigned long i;
56562 + int ret;
56563 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56564 + __u32 ip_addr = 0;
56565 + __u32 our_addr;
56566 + __u32 our_netmask;
56567 + char *p;
56568 + __u16 ip_port = 0;
56569 + const struct cred *cred = current_cred();
56570 +
56571 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56572 + return 0;
56573 +
56574 + curr = current->acl;
56575 + isk = inet_sk(sk);
56576 +
56577 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56578 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56579 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56580 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56581 + struct sockaddr_in saddr;
56582 + int err;
56583 +
56584 + saddr.sin_family = AF_INET;
56585 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56586 + saddr.sin_port = isk->inet_sport;
56587 +
56588 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56589 + if (err)
56590 + return err;
56591 +
56592 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56593 + if (err)
56594 + return err;
56595 + }
56596 +
56597 + if (!curr->ips)
56598 + return 0;
56599 +
56600 + ip_addr = addr->sin_addr.s_addr;
56601 + ip_port = ntohs(addr->sin_port);
56602 +
56603 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56604 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56605 + current->role->roletype, cred->uid,
56606 + cred->gid, current->exec_file ?
56607 + gr_to_filename(current->exec_file->f_path.dentry,
56608 + current->exec_file->f_path.mnt) :
56609 + curr->filename, curr->filename,
56610 + &ip_addr, ip_port, type,
56611 + sk->sk_protocol, mode, &current->signal->saved_ip);
56612 + return 0;
56613 + }
56614 +
56615 + for (i = 0; i < curr->ip_num; i++) {
56616 + ip = *(curr->ips + i);
56617 + if (ip->iface != NULL) {
56618 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56619 + p = strchr(iface, ':');
56620 + if (p != NULL)
56621 + *p = '\0';
56622 + dev = dev_get_by_name(sock_net(sk), iface);
56623 + if (dev == NULL)
56624 + continue;
56625 + idev = in_dev_get(dev);
56626 + if (idev == NULL) {
56627 + dev_put(dev);
56628 + continue;
56629 + }
56630 + rcu_read_lock();
56631 + for_ifa(idev) {
56632 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56633 + our_addr = ifa->ifa_address;
56634 + our_netmask = 0xffffffff;
56635 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56636 + if (ret == 1) {
56637 + rcu_read_unlock();
56638 + in_dev_put(idev);
56639 + dev_put(dev);
56640 + return 0;
56641 + } else if (ret == 2) {
56642 + rcu_read_unlock();
56643 + in_dev_put(idev);
56644 + dev_put(dev);
56645 + goto denied;
56646 + }
56647 + }
56648 + } endfor_ifa(idev);
56649 + rcu_read_unlock();
56650 + in_dev_put(idev);
56651 + dev_put(dev);
56652 + } else {
56653 + our_addr = ip->addr;
56654 + our_netmask = ip->netmask;
56655 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56656 + if (ret == 1)
56657 + return 0;
56658 + else if (ret == 2)
56659 + goto denied;
56660 + }
56661 + }
56662 +
56663 +denied:
56664 + if (mode == GR_BIND)
56665 + 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));
56666 + else if (mode == GR_CONNECT)
56667 + 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));
56668 +
56669 + return -EACCES;
56670 +}
56671 +
56672 +int
56673 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56674 +{
56675 + /* always allow disconnection of dgram sockets with connect */
56676 + if (addr->sin_family == AF_UNSPEC)
56677 + return 0;
56678 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56679 +}
56680 +
56681 +int
56682 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56683 +{
56684 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56685 +}
56686 +
56687 +int gr_search_listen(struct socket *sock)
56688 +{
56689 + struct sock *sk = sock->sk;
56690 + struct sockaddr_in addr;
56691 +
56692 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56693 + addr.sin_port = inet_sk(sk)->inet_sport;
56694 +
56695 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56696 +}
56697 +
56698 +int gr_search_accept(struct socket *sock)
56699 +{
56700 + struct sock *sk = sock->sk;
56701 + struct sockaddr_in addr;
56702 +
56703 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56704 + addr.sin_port = inet_sk(sk)->inet_sport;
56705 +
56706 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56707 +}
56708 +
56709 +int
56710 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56711 +{
56712 + if (addr)
56713 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56714 + else {
56715 + struct sockaddr_in sin;
56716 + const struct inet_sock *inet = inet_sk(sk);
56717 +
56718 + sin.sin_addr.s_addr = inet->inet_daddr;
56719 + sin.sin_port = inet->inet_dport;
56720 +
56721 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56722 + }
56723 +}
56724 +
56725 +int
56726 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56727 +{
56728 + struct sockaddr_in sin;
56729 +
56730 + if (unlikely(skb->len < sizeof (struct udphdr)))
56731 + return 0; // skip this packet
56732 +
56733 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56734 + sin.sin_port = udp_hdr(skb)->source;
56735 +
56736 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56737 +}
56738 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56739 new file mode 100644
56740 index 0000000..25f54ef
56741 --- /dev/null
56742 +++ b/grsecurity/gracl_learn.c
56743 @@ -0,0 +1,207 @@
56744 +#include <linux/kernel.h>
56745 +#include <linux/mm.h>
56746 +#include <linux/sched.h>
56747 +#include <linux/poll.h>
56748 +#include <linux/string.h>
56749 +#include <linux/file.h>
56750 +#include <linux/types.h>
56751 +#include <linux/vmalloc.h>
56752 +#include <linux/grinternal.h>
56753 +
56754 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56755 + size_t count, loff_t *ppos);
56756 +extern int gr_acl_is_enabled(void);
56757 +
56758 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56759 +static int gr_learn_attached;
56760 +
56761 +/* use a 512k buffer */
56762 +#define LEARN_BUFFER_SIZE (512 * 1024)
56763 +
56764 +static DEFINE_SPINLOCK(gr_learn_lock);
56765 +static DEFINE_MUTEX(gr_learn_user_mutex);
56766 +
56767 +/* we need to maintain two buffers, so that the kernel context of grlearn
56768 + uses a semaphore around the userspace copying, and the other kernel contexts
56769 + use a spinlock when copying into the buffer, since they cannot sleep
56770 +*/
56771 +static char *learn_buffer;
56772 +static char *learn_buffer_user;
56773 +static int learn_buffer_len;
56774 +static int learn_buffer_user_len;
56775 +
56776 +static ssize_t
56777 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56778 +{
56779 + DECLARE_WAITQUEUE(wait, current);
56780 + ssize_t retval = 0;
56781 +
56782 + add_wait_queue(&learn_wait, &wait);
56783 + set_current_state(TASK_INTERRUPTIBLE);
56784 + do {
56785 + mutex_lock(&gr_learn_user_mutex);
56786 + spin_lock(&gr_learn_lock);
56787 + if (learn_buffer_len)
56788 + break;
56789 + spin_unlock(&gr_learn_lock);
56790 + mutex_unlock(&gr_learn_user_mutex);
56791 + if (file->f_flags & O_NONBLOCK) {
56792 + retval = -EAGAIN;
56793 + goto out;
56794 + }
56795 + if (signal_pending(current)) {
56796 + retval = -ERESTARTSYS;
56797 + goto out;
56798 + }
56799 +
56800 + schedule();
56801 + } while (1);
56802 +
56803 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56804 + learn_buffer_user_len = learn_buffer_len;
56805 + retval = learn_buffer_len;
56806 + learn_buffer_len = 0;
56807 +
56808 + spin_unlock(&gr_learn_lock);
56809 +
56810 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56811 + retval = -EFAULT;
56812 +
56813 + mutex_unlock(&gr_learn_user_mutex);
56814 +out:
56815 + set_current_state(TASK_RUNNING);
56816 + remove_wait_queue(&learn_wait, &wait);
56817 + return retval;
56818 +}
56819 +
56820 +static unsigned int
56821 +poll_learn(struct file * file, poll_table * wait)
56822 +{
56823 + poll_wait(file, &learn_wait, wait);
56824 +
56825 + if (learn_buffer_len)
56826 + return (POLLIN | POLLRDNORM);
56827 +
56828 + return 0;
56829 +}
56830 +
56831 +void
56832 +gr_clear_learn_entries(void)
56833 +{
56834 + char *tmp;
56835 +
56836 + mutex_lock(&gr_learn_user_mutex);
56837 + spin_lock(&gr_learn_lock);
56838 + tmp = learn_buffer;
56839 + learn_buffer = NULL;
56840 + spin_unlock(&gr_learn_lock);
56841 + if (tmp)
56842 + vfree(tmp);
56843 + if (learn_buffer_user != NULL) {
56844 + vfree(learn_buffer_user);
56845 + learn_buffer_user = NULL;
56846 + }
56847 + learn_buffer_len = 0;
56848 + mutex_unlock(&gr_learn_user_mutex);
56849 +
56850 + return;
56851 +}
56852 +
56853 +void
56854 +gr_add_learn_entry(const char *fmt, ...)
56855 +{
56856 + va_list args;
56857 + unsigned int len;
56858 +
56859 + if (!gr_learn_attached)
56860 + return;
56861 +
56862 + spin_lock(&gr_learn_lock);
56863 +
56864 + /* leave a gap at the end so we know when it's "full" but don't have to
56865 + compute the exact length of the string we're trying to append
56866 + */
56867 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56868 + spin_unlock(&gr_learn_lock);
56869 + wake_up_interruptible(&learn_wait);
56870 + return;
56871 + }
56872 + if (learn_buffer == NULL) {
56873 + spin_unlock(&gr_learn_lock);
56874 + return;
56875 + }
56876 +
56877 + va_start(args, fmt);
56878 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56879 + va_end(args);
56880 +
56881 + learn_buffer_len += len + 1;
56882 +
56883 + spin_unlock(&gr_learn_lock);
56884 + wake_up_interruptible(&learn_wait);
56885 +
56886 + return;
56887 +}
56888 +
56889 +static int
56890 +open_learn(struct inode *inode, struct file *file)
56891 +{
56892 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56893 + return -EBUSY;
56894 + if (file->f_mode & FMODE_READ) {
56895 + int retval = 0;
56896 + mutex_lock(&gr_learn_user_mutex);
56897 + if (learn_buffer == NULL)
56898 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56899 + if (learn_buffer_user == NULL)
56900 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56901 + if (learn_buffer == NULL) {
56902 + retval = -ENOMEM;
56903 + goto out_error;
56904 + }
56905 + if (learn_buffer_user == NULL) {
56906 + retval = -ENOMEM;
56907 + goto out_error;
56908 + }
56909 + learn_buffer_len = 0;
56910 + learn_buffer_user_len = 0;
56911 + gr_learn_attached = 1;
56912 +out_error:
56913 + mutex_unlock(&gr_learn_user_mutex);
56914 + return retval;
56915 + }
56916 + return 0;
56917 +}
56918 +
56919 +static int
56920 +close_learn(struct inode *inode, struct file *file)
56921 +{
56922 + if (file->f_mode & FMODE_READ) {
56923 + char *tmp = NULL;
56924 + mutex_lock(&gr_learn_user_mutex);
56925 + spin_lock(&gr_learn_lock);
56926 + tmp = learn_buffer;
56927 + learn_buffer = NULL;
56928 + spin_unlock(&gr_learn_lock);
56929 + if (tmp)
56930 + vfree(tmp);
56931 + if (learn_buffer_user != NULL) {
56932 + vfree(learn_buffer_user);
56933 + learn_buffer_user = NULL;
56934 + }
56935 + learn_buffer_len = 0;
56936 + learn_buffer_user_len = 0;
56937 + gr_learn_attached = 0;
56938 + mutex_unlock(&gr_learn_user_mutex);
56939 + }
56940 +
56941 + return 0;
56942 +}
56943 +
56944 +const struct file_operations grsec_fops = {
56945 + .read = read_learn,
56946 + .write = write_grsec_handler,
56947 + .open = open_learn,
56948 + .release = close_learn,
56949 + .poll = poll_learn,
56950 +};
56951 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56952 new file mode 100644
56953 index 0000000..39645c9
56954 --- /dev/null
56955 +++ b/grsecurity/gracl_res.c
56956 @@ -0,0 +1,68 @@
56957 +#include <linux/kernel.h>
56958 +#include <linux/sched.h>
56959 +#include <linux/gracl.h>
56960 +#include <linux/grinternal.h>
56961 +
56962 +static const char *restab_log[] = {
56963 + [RLIMIT_CPU] = "RLIMIT_CPU",
56964 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56965 + [RLIMIT_DATA] = "RLIMIT_DATA",
56966 + [RLIMIT_STACK] = "RLIMIT_STACK",
56967 + [RLIMIT_CORE] = "RLIMIT_CORE",
56968 + [RLIMIT_RSS] = "RLIMIT_RSS",
56969 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56970 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56971 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56972 + [RLIMIT_AS] = "RLIMIT_AS",
56973 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56974 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56975 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56976 + [RLIMIT_NICE] = "RLIMIT_NICE",
56977 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56978 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56979 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56980 +};
56981 +
56982 +void
56983 +gr_log_resource(const struct task_struct *task,
56984 + const int res, const unsigned long wanted, const int gt)
56985 +{
56986 + const struct cred *cred;
56987 + unsigned long rlim;
56988 +
56989 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56990 + return;
56991 +
56992 + // not yet supported resource
56993 + if (unlikely(!restab_log[res]))
56994 + return;
56995 +
56996 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56997 + rlim = task_rlimit_max(task, res);
56998 + else
56999 + rlim = task_rlimit(task, res);
57000 +
57001 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57002 + return;
57003 +
57004 + rcu_read_lock();
57005 + cred = __task_cred(task);
57006 +
57007 + if (res == RLIMIT_NPROC &&
57008 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57009 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57010 + goto out_rcu_unlock;
57011 + else if (res == RLIMIT_MEMLOCK &&
57012 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57013 + goto out_rcu_unlock;
57014 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57015 + goto out_rcu_unlock;
57016 + rcu_read_unlock();
57017 +
57018 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57019 +
57020 + return;
57021 +out_rcu_unlock:
57022 + rcu_read_unlock();
57023 + return;
57024 +}
57025 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57026 new file mode 100644
57027 index 0000000..25197e9
57028 --- /dev/null
57029 +++ b/grsecurity/gracl_segv.c
57030 @@ -0,0 +1,299 @@
57031 +#include <linux/kernel.h>
57032 +#include <linux/mm.h>
57033 +#include <asm/uaccess.h>
57034 +#include <asm/errno.h>
57035 +#include <asm/mman.h>
57036 +#include <net/sock.h>
57037 +#include <linux/file.h>
57038 +#include <linux/fs.h>
57039 +#include <linux/net.h>
57040 +#include <linux/in.h>
57041 +#include <linux/slab.h>
57042 +#include <linux/types.h>
57043 +#include <linux/sched.h>
57044 +#include <linux/timer.h>
57045 +#include <linux/gracl.h>
57046 +#include <linux/grsecurity.h>
57047 +#include <linux/grinternal.h>
57048 +
57049 +static struct crash_uid *uid_set;
57050 +static unsigned short uid_used;
57051 +static DEFINE_SPINLOCK(gr_uid_lock);
57052 +extern rwlock_t gr_inode_lock;
57053 +extern struct acl_subject_label *
57054 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57055 + struct acl_role_label *role);
57056 +
57057 +#ifdef CONFIG_BTRFS_FS
57058 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57059 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57060 +#endif
57061 +
57062 +static inline dev_t __get_dev(const struct dentry *dentry)
57063 +{
57064 +#ifdef CONFIG_BTRFS_FS
57065 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57066 + return get_btrfs_dev_from_inode(dentry->d_inode);
57067 + else
57068 +#endif
57069 + return dentry->d_inode->i_sb->s_dev;
57070 +}
57071 +
57072 +int
57073 +gr_init_uidset(void)
57074 +{
57075 + uid_set =
57076 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57077 + uid_used = 0;
57078 +
57079 + return uid_set ? 1 : 0;
57080 +}
57081 +
57082 +void
57083 +gr_free_uidset(void)
57084 +{
57085 + if (uid_set)
57086 + kfree(uid_set);
57087 +
57088 + return;
57089 +}
57090 +
57091 +int
57092 +gr_find_uid(const uid_t uid)
57093 +{
57094 + struct crash_uid *tmp = uid_set;
57095 + uid_t buid;
57096 + int low = 0, high = uid_used - 1, mid;
57097 +
57098 + while (high >= low) {
57099 + mid = (low + high) >> 1;
57100 + buid = tmp[mid].uid;
57101 + if (buid == uid)
57102 + return mid;
57103 + if (buid > uid)
57104 + high = mid - 1;
57105 + if (buid < uid)
57106 + low = mid + 1;
57107 + }
57108 +
57109 + return -1;
57110 +}
57111 +
57112 +static __inline__ void
57113 +gr_insertsort(void)
57114 +{
57115 + unsigned short i, j;
57116 + struct crash_uid index;
57117 +
57118 + for (i = 1; i < uid_used; i++) {
57119 + index = uid_set[i];
57120 + j = i;
57121 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57122 + uid_set[j] = uid_set[j - 1];
57123 + j--;
57124 + }
57125 + uid_set[j] = index;
57126 + }
57127 +
57128 + return;
57129 +}
57130 +
57131 +static __inline__ void
57132 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57133 +{
57134 + int loc;
57135 +
57136 + if (uid_used == GR_UIDTABLE_MAX)
57137 + return;
57138 +
57139 + loc = gr_find_uid(uid);
57140 +
57141 + if (loc >= 0) {
57142 + uid_set[loc].expires = expires;
57143 + return;
57144 + }
57145 +
57146 + uid_set[uid_used].uid = uid;
57147 + uid_set[uid_used].expires = expires;
57148 + uid_used++;
57149 +
57150 + gr_insertsort();
57151 +
57152 + return;
57153 +}
57154 +
57155 +void
57156 +gr_remove_uid(const unsigned short loc)
57157 +{
57158 + unsigned short i;
57159 +
57160 + for (i = loc + 1; i < uid_used; i++)
57161 + uid_set[i - 1] = uid_set[i];
57162 +
57163 + uid_used--;
57164 +
57165 + return;
57166 +}
57167 +
57168 +int
57169 +gr_check_crash_uid(const uid_t uid)
57170 +{
57171 + int loc;
57172 + int ret = 0;
57173 +
57174 + if (unlikely(!gr_acl_is_enabled()))
57175 + return 0;
57176 +
57177 + spin_lock(&gr_uid_lock);
57178 + loc = gr_find_uid(uid);
57179 +
57180 + if (loc < 0)
57181 + goto out_unlock;
57182 +
57183 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57184 + gr_remove_uid(loc);
57185 + else
57186 + ret = 1;
57187 +
57188 +out_unlock:
57189 + spin_unlock(&gr_uid_lock);
57190 + return ret;
57191 +}
57192 +
57193 +static __inline__ int
57194 +proc_is_setxid(const struct cred *cred)
57195 +{
57196 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57197 + !uid_eq(cred->uid, cred->fsuid))
57198 + return 1;
57199 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57200 + !uid_eq(cred->gid, cred->fsgid))
57201 + return 1;
57202 +
57203 + return 0;
57204 +}
57205 +
57206 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57207 +
57208 +void
57209 +gr_handle_crash(struct task_struct *task, const int sig)
57210 +{
57211 + struct acl_subject_label *curr;
57212 + struct task_struct *tsk, *tsk2;
57213 + const struct cred *cred;
57214 + const struct cred *cred2;
57215 +
57216 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57217 + return;
57218 +
57219 + if (unlikely(!gr_acl_is_enabled()))
57220 + return;
57221 +
57222 + curr = task->acl;
57223 +
57224 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57225 + return;
57226 +
57227 + if (time_before_eq(curr->expires, get_seconds())) {
57228 + curr->expires = 0;
57229 + curr->crashes = 0;
57230 + }
57231 +
57232 + curr->crashes++;
57233 +
57234 + if (!curr->expires)
57235 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57236 +
57237 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57238 + time_after(curr->expires, get_seconds())) {
57239 + rcu_read_lock();
57240 + cred = __task_cred(task);
57241 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57242 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57243 + spin_lock(&gr_uid_lock);
57244 + gr_insert_uid(cred->uid, curr->expires);
57245 + spin_unlock(&gr_uid_lock);
57246 + curr->expires = 0;
57247 + curr->crashes = 0;
57248 + read_lock(&tasklist_lock);
57249 + do_each_thread(tsk2, tsk) {
57250 + cred2 = __task_cred(tsk);
57251 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57252 + gr_fake_force_sig(SIGKILL, tsk);
57253 + } while_each_thread(tsk2, tsk);
57254 + read_unlock(&tasklist_lock);
57255 + } else {
57256 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57257 + read_lock(&tasklist_lock);
57258 + read_lock(&grsec_exec_file_lock);
57259 + do_each_thread(tsk2, tsk) {
57260 + if (likely(tsk != task)) {
57261 + // if this thread has the same subject as the one that triggered
57262 + // RES_CRASH and it's the same binary, kill it
57263 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57264 + gr_fake_force_sig(SIGKILL, tsk);
57265 + }
57266 + } while_each_thread(tsk2, tsk);
57267 + read_unlock(&grsec_exec_file_lock);
57268 + read_unlock(&tasklist_lock);
57269 + }
57270 + rcu_read_unlock();
57271 + }
57272 +
57273 + return;
57274 +}
57275 +
57276 +int
57277 +gr_check_crash_exec(const struct file *filp)
57278 +{
57279 + struct acl_subject_label *curr;
57280 +
57281 + if (unlikely(!gr_acl_is_enabled()))
57282 + return 0;
57283 +
57284 + read_lock(&gr_inode_lock);
57285 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57286 + __get_dev(filp->f_path.dentry),
57287 + current->role);
57288 + read_unlock(&gr_inode_lock);
57289 +
57290 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57291 + (!curr->crashes && !curr->expires))
57292 + return 0;
57293 +
57294 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57295 + time_after(curr->expires, get_seconds()))
57296 + return 1;
57297 + else if (time_before_eq(curr->expires, get_seconds())) {
57298 + curr->crashes = 0;
57299 + curr->expires = 0;
57300 + }
57301 +
57302 + return 0;
57303 +}
57304 +
57305 +void
57306 +gr_handle_alertkill(struct task_struct *task)
57307 +{
57308 + struct acl_subject_label *curracl;
57309 + __u32 curr_ip;
57310 + struct task_struct *p, *p2;
57311 +
57312 + if (unlikely(!gr_acl_is_enabled()))
57313 + return;
57314 +
57315 + curracl = task->acl;
57316 + curr_ip = task->signal->curr_ip;
57317 +
57318 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57319 + read_lock(&tasklist_lock);
57320 + do_each_thread(p2, p) {
57321 + if (p->signal->curr_ip == curr_ip)
57322 + gr_fake_force_sig(SIGKILL, p);
57323 + } while_each_thread(p2, p);
57324 + read_unlock(&tasklist_lock);
57325 + } else if (curracl->mode & GR_KILLPROC)
57326 + gr_fake_force_sig(SIGKILL, task);
57327 +
57328 + return;
57329 +}
57330 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57331 new file mode 100644
57332 index 0000000..9d83a69
57333 --- /dev/null
57334 +++ b/grsecurity/gracl_shm.c
57335 @@ -0,0 +1,40 @@
57336 +#include <linux/kernel.h>
57337 +#include <linux/mm.h>
57338 +#include <linux/sched.h>
57339 +#include <linux/file.h>
57340 +#include <linux/ipc.h>
57341 +#include <linux/gracl.h>
57342 +#include <linux/grsecurity.h>
57343 +#include <linux/grinternal.h>
57344 +
57345 +int
57346 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57347 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57348 +{
57349 + struct task_struct *task;
57350 +
57351 + if (!gr_acl_is_enabled())
57352 + return 1;
57353 +
57354 + rcu_read_lock();
57355 + read_lock(&tasklist_lock);
57356 +
57357 + task = find_task_by_vpid(shm_cprid);
57358 +
57359 + if (unlikely(!task))
57360 + task = find_task_by_vpid(shm_lapid);
57361 +
57362 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57363 + (task->pid == shm_lapid)) &&
57364 + (task->acl->mode & GR_PROTSHM) &&
57365 + (task->acl != current->acl))) {
57366 + read_unlock(&tasklist_lock);
57367 + rcu_read_unlock();
57368 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57369 + return 0;
57370 + }
57371 + read_unlock(&tasklist_lock);
57372 + rcu_read_unlock();
57373 +
57374 + return 1;
57375 +}
57376 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57377 new file mode 100644
57378 index 0000000..bc0be01
57379 --- /dev/null
57380 +++ b/grsecurity/grsec_chdir.c
57381 @@ -0,0 +1,19 @@
57382 +#include <linux/kernel.h>
57383 +#include <linux/sched.h>
57384 +#include <linux/fs.h>
57385 +#include <linux/file.h>
57386 +#include <linux/grsecurity.h>
57387 +#include <linux/grinternal.h>
57388 +
57389 +void
57390 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57391 +{
57392 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57393 + if ((grsec_enable_chdir && grsec_enable_group &&
57394 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57395 + !grsec_enable_group)) {
57396 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57397 + }
57398 +#endif
57399 + return;
57400 +}
57401 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57402 new file mode 100644
57403 index 0000000..9807ee2
57404 --- /dev/null
57405 +++ b/grsecurity/grsec_chroot.c
57406 @@ -0,0 +1,368 @@
57407 +#include <linux/kernel.h>
57408 +#include <linux/module.h>
57409 +#include <linux/sched.h>
57410 +#include <linux/file.h>
57411 +#include <linux/fs.h>
57412 +#include <linux/mount.h>
57413 +#include <linux/types.h>
57414 +#include "../fs/mount.h"
57415 +#include <linux/grsecurity.h>
57416 +#include <linux/grinternal.h>
57417 +
57418 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57419 +{
57420 +#ifdef CONFIG_GRKERNSEC
57421 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57422 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57423 + task->gr_is_chrooted = 1;
57424 + else
57425 + task->gr_is_chrooted = 0;
57426 +
57427 + task->gr_chroot_dentry = path->dentry;
57428 +#endif
57429 + return;
57430 +}
57431 +
57432 +void gr_clear_chroot_entries(struct task_struct *task)
57433 +{
57434 +#ifdef CONFIG_GRKERNSEC
57435 + task->gr_is_chrooted = 0;
57436 + task->gr_chroot_dentry = NULL;
57437 +#endif
57438 + return;
57439 +}
57440 +
57441 +int
57442 +gr_handle_chroot_unix(const pid_t pid)
57443 +{
57444 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57445 + struct task_struct *p;
57446 +
57447 + if (unlikely(!grsec_enable_chroot_unix))
57448 + return 1;
57449 +
57450 + if (likely(!proc_is_chrooted(current)))
57451 + return 1;
57452 +
57453 + rcu_read_lock();
57454 + read_lock(&tasklist_lock);
57455 + p = find_task_by_vpid_unrestricted(pid);
57456 + if (unlikely(p && !have_same_root(current, p))) {
57457 + read_unlock(&tasklist_lock);
57458 + rcu_read_unlock();
57459 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57460 + return 0;
57461 + }
57462 + read_unlock(&tasklist_lock);
57463 + rcu_read_unlock();
57464 +#endif
57465 + return 1;
57466 +}
57467 +
57468 +int
57469 +gr_handle_chroot_nice(void)
57470 +{
57471 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57472 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57473 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57474 + return -EPERM;
57475 + }
57476 +#endif
57477 + return 0;
57478 +}
57479 +
57480 +int
57481 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57482 +{
57483 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57484 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57485 + && proc_is_chrooted(current)) {
57486 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57487 + return -EACCES;
57488 + }
57489 +#endif
57490 + return 0;
57491 +}
57492 +
57493 +int
57494 +gr_handle_chroot_rawio(const struct inode *inode)
57495 +{
57496 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57497 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57498 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57499 + return 1;
57500 +#endif
57501 + return 0;
57502 +}
57503 +
57504 +int
57505 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57506 +{
57507 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57508 + struct task_struct *p;
57509 + int ret = 0;
57510 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57511 + return ret;
57512 +
57513 + read_lock(&tasklist_lock);
57514 + do_each_pid_task(pid, type, p) {
57515 + if (!have_same_root(current, p)) {
57516 + ret = 1;
57517 + goto out;
57518 + }
57519 + } while_each_pid_task(pid, type, p);
57520 +out:
57521 + read_unlock(&tasklist_lock);
57522 + return ret;
57523 +#endif
57524 + return 0;
57525 +}
57526 +
57527 +int
57528 +gr_pid_is_chrooted(struct task_struct *p)
57529 +{
57530 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57531 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57532 + return 0;
57533 +
57534 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57535 + !have_same_root(current, p)) {
57536 + return 1;
57537 + }
57538 +#endif
57539 + return 0;
57540 +}
57541 +
57542 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57543 +
57544 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57545 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57546 +{
57547 + struct path path, currentroot;
57548 + int ret = 0;
57549 +
57550 + path.dentry = (struct dentry *)u_dentry;
57551 + path.mnt = (struct vfsmount *)u_mnt;
57552 + get_fs_root(current->fs, &currentroot);
57553 + if (path_is_under(&path, &currentroot))
57554 + ret = 1;
57555 + path_put(&currentroot);
57556 +
57557 + return ret;
57558 +}
57559 +#endif
57560 +
57561 +int
57562 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57563 +{
57564 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57565 + if (!grsec_enable_chroot_fchdir)
57566 + return 1;
57567 +
57568 + if (!proc_is_chrooted(current))
57569 + return 1;
57570 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57571 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57572 + return 0;
57573 + }
57574 +#endif
57575 + return 1;
57576 +}
57577 +
57578 +int
57579 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57580 + const time_t shm_createtime)
57581 +{
57582 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57583 + struct task_struct *p;
57584 + time_t starttime;
57585 +
57586 + if (unlikely(!grsec_enable_chroot_shmat))
57587 + return 1;
57588 +
57589 + if (likely(!proc_is_chrooted(current)))
57590 + return 1;
57591 +
57592 + rcu_read_lock();
57593 + read_lock(&tasklist_lock);
57594 +
57595 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57596 + starttime = p->start_time.tv_sec;
57597 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57598 + if (have_same_root(current, p)) {
57599 + goto allow;
57600 + } else {
57601 + read_unlock(&tasklist_lock);
57602 + rcu_read_unlock();
57603 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57604 + return 0;
57605 + }
57606 + }
57607 + /* creator exited, pid reuse, fall through to next check */
57608 + }
57609 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57610 + if (unlikely(!have_same_root(current, p))) {
57611 + read_unlock(&tasklist_lock);
57612 + rcu_read_unlock();
57613 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57614 + return 0;
57615 + }
57616 + }
57617 +
57618 +allow:
57619 + read_unlock(&tasklist_lock);
57620 + rcu_read_unlock();
57621 +#endif
57622 + return 1;
57623 +}
57624 +
57625 +void
57626 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57627 +{
57628 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57629 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57630 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57631 +#endif
57632 + return;
57633 +}
57634 +
57635 +int
57636 +gr_handle_chroot_mknod(const struct dentry *dentry,
57637 + const struct vfsmount *mnt, const int mode)
57638 +{
57639 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57640 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57641 + proc_is_chrooted(current)) {
57642 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57643 + return -EPERM;
57644 + }
57645 +#endif
57646 + return 0;
57647 +}
57648 +
57649 +int
57650 +gr_handle_chroot_mount(const struct dentry *dentry,
57651 + const struct vfsmount *mnt, const char *dev_name)
57652 +{
57653 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57654 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57655 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57656 + return -EPERM;
57657 + }
57658 +#endif
57659 + return 0;
57660 +}
57661 +
57662 +int
57663 +gr_handle_chroot_pivot(void)
57664 +{
57665 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57666 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57667 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57668 + return -EPERM;
57669 + }
57670 +#endif
57671 + return 0;
57672 +}
57673 +
57674 +int
57675 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57676 +{
57677 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57678 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57679 + !gr_is_outside_chroot(dentry, mnt)) {
57680 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57681 + return -EPERM;
57682 + }
57683 +#endif
57684 + return 0;
57685 +}
57686 +
57687 +extern const char *captab_log[];
57688 +extern int captab_log_entries;
57689 +
57690 +int
57691 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57692 +{
57693 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57694 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57695 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57696 + if (cap_raised(chroot_caps, cap)) {
57697 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57698 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57699 + }
57700 + return 0;
57701 + }
57702 + }
57703 +#endif
57704 + return 1;
57705 +}
57706 +
57707 +int
57708 +gr_chroot_is_capable(const int cap)
57709 +{
57710 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57711 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57712 +#endif
57713 + return 1;
57714 +}
57715 +
57716 +int
57717 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57718 +{
57719 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57720 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57721 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57722 + if (cap_raised(chroot_caps, cap)) {
57723 + return 0;
57724 + }
57725 + }
57726 +#endif
57727 + return 1;
57728 +}
57729 +
57730 +int
57731 +gr_chroot_is_capable_nolog(const int cap)
57732 +{
57733 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57734 + return gr_task_chroot_is_capable_nolog(current, cap);
57735 +#endif
57736 + return 1;
57737 +}
57738 +
57739 +int
57740 +gr_handle_chroot_sysctl(const int op)
57741 +{
57742 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57743 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57744 + proc_is_chrooted(current))
57745 + return -EACCES;
57746 +#endif
57747 + return 0;
57748 +}
57749 +
57750 +void
57751 +gr_handle_chroot_chdir(struct path *path)
57752 +{
57753 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57754 + if (grsec_enable_chroot_chdir)
57755 + set_fs_pwd(current->fs, path);
57756 +#endif
57757 + return;
57758 +}
57759 +
57760 +int
57761 +gr_handle_chroot_chmod(const struct dentry *dentry,
57762 + const struct vfsmount *mnt, const int mode)
57763 +{
57764 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57765 + /* allow chmod +s on directories, but not files */
57766 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57767 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57768 + proc_is_chrooted(current)) {
57769 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57770 + return -EPERM;
57771 + }
57772 +#endif
57773 + return 0;
57774 +}
57775 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57776 new file mode 100644
57777 index 0000000..7de2055
57778 --- /dev/null
57779 +++ b/grsecurity/grsec_disabled.c
57780 @@ -0,0 +1,442 @@
57781 +#include <linux/kernel.h>
57782 +#include <linux/module.h>
57783 +#include <linux/sched.h>
57784 +#include <linux/file.h>
57785 +#include <linux/fs.h>
57786 +#include <linux/kdev_t.h>
57787 +#include <linux/net.h>
57788 +#include <linux/in.h>
57789 +#include <linux/ip.h>
57790 +#include <linux/skbuff.h>
57791 +#include <linux/sysctl.h>
57792 +
57793 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57794 +void
57795 +pax_set_initial_flags(struct linux_binprm *bprm)
57796 +{
57797 + return;
57798 +}
57799 +#endif
57800 +
57801 +#ifdef CONFIG_SYSCTL
57802 +__u32
57803 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57804 +{
57805 + return 0;
57806 +}
57807 +#endif
57808 +
57809 +#ifdef CONFIG_TASKSTATS
57810 +int gr_is_taskstats_denied(int pid)
57811 +{
57812 + return 0;
57813 +}
57814 +#endif
57815 +
57816 +int
57817 +gr_acl_is_enabled(void)
57818 +{
57819 + return 0;
57820 +}
57821 +
57822 +void
57823 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57824 +{
57825 + return;
57826 +}
57827 +
57828 +int
57829 +gr_handle_rawio(const struct inode *inode)
57830 +{
57831 + return 0;
57832 +}
57833 +
57834 +void
57835 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57836 +{
57837 + return;
57838 +}
57839 +
57840 +int
57841 +gr_handle_ptrace(struct task_struct *task, const long request)
57842 +{
57843 + return 0;
57844 +}
57845 +
57846 +int
57847 +gr_handle_proc_ptrace(struct task_struct *task)
57848 +{
57849 + return 0;
57850 +}
57851 +
57852 +void
57853 +gr_learn_resource(const struct task_struct *task,
57854 + const int res, const unsigned long wanted, const int gt)
57855 +{
57856 + return;
57857 +}
57858 +
57859 +int
57860 +gr_set_acls(const int type)
57861 +{
57862 + return 0;
57863 +}
57864 +
57865 +int
57866 +gr_check_hidden_task(const struct task_struct *tsk)
57867 +{
57868 + return 0;
57869 +}
57870 +
57871 +int
57872 +gr_check_protected_task(const struct task_struct *task)
57873 +{
57874 + return 0;
57875 +}
57876 +
57877 +int
57878 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57879 +{
57880 + return 0;
57881 +}
57882 +
57883 +void
57884 +gr_copy_label(struct task_struct *tsk)
57885 +{
57886 + return;
57887 +}
57888 +
57889 +void
57890 +gr_set_pax_flags(struct task_struct *task)
57891 +{
57892 + return;
57893 +}
57894 +
57895 +int
57896 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57897 + const int unsafe_share)
57898 +{
57899 + return 0;
57900 +}
57901 +
57902 +void
57903 +gr_handle_delete(const ino_t ino, const dev_t dev)
57904 +{
57905 + return;
57906 +}
57907 +
57908 +void
57909 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57910 +{
57911 + return;
57912 +}
57913 +
57914 +void
57915 +gr_handle_crash(struct task_struct *task, const int sig)
57916 +{
57917 + return;
57918 +}
57919 +
57920 +int
57921 +gr_check_crash_exec(const struct file *filp)
57922 +{
57923 + return 0;
57924 +}
57925 +
57926 +int
57927 +gr_check_crash_uid(const uid_t uid)
57928 +{
57929 + return 0;
57930 +}
57931 +
57932 +void
57933 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57934 + struct dentry *old_dentry,
57935 + struct dentry *new_dentry,
57936 + struct vfsmount *mnt, const __u8 replace)
57937 +{
57938 + return;
57939 +}
57940 +
57941 +int
57942 +gr_search_socket(const int family, const int type, const int protocol)
57943 +{
57944 + return 1;
57945 +}
57946 +
57947 +int
57948 +gr_search_connectbind(const int mode, const struct socket *sock,
57949 + const struct sockaddr_in *addr)
57950 +{
57951 + return 0;
57952 +}
57953 +
57954 +void
57955 +gr_handle_alertkill(struct task_struct *task)
57956 +{
57957 + return;
57958 +}
57959 +
57960 +__u32
57961 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57962 +{
57963 + return 1;
57964 +}
57965 +
57966 +__u32
57967 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57968 + const struct vfsmount * mnt)
57969 +{
57970 + return 1;
57971 +}
57972 +
57973 +__u32
57974 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57975 + int acc_mode)
57976 +{
57977 + return 1;
57978 +}
57979 +
57980 +__u32
57981 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57982 +{
57983 + return 1;
57984 +}
57985 +
57986 +__u32
57987 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57988 +{
57989 + return 1;
57990 +}
57991 +
57992 +int
57993 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57994 + unsigned int *vm_flags)
57995 +{
57996 + return 1;
57997 +}
57998 +
57999 +__u32
58000 +gr_acl_handle_truncate(const struct dentry * dentry,
58001 + const struct vfsmount * mnt)
58002 +{
58003 + return 1;
58004 +}
58005 +
58006 +__u32
58007 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58008 +{
58009 + return 1;
58010 +}
58011 +
58012 +__u32
58013 +gr_acl_handle_access(const struct dentry * dentry,
58014 + const struct vfsmount * mnt, const int fmode)
58015 +{
58016 + return 1;
58017 +}
58018 +
58019 +__u32
58020 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58021 + umode_t *mode)
58022 +{
58023 + return 1;
58024 +}
58025 +
58026 +__u32
58027 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58028 +{
58029 + return 1;
58030 +}
58031 +
58032 +__u32
58033 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58034 +{
58035 + return 1;
58036 +}
58037 +
58038 +void
58039 +grsecurity_init(void)
58040 +{
58041 + return;
58042 +}
58043 +
58044 +umode_t gr_acl_umask(void)
58045 +{
58046 + return 0;
58047 +}
58048 +
58049 +__u32
58050 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58051 + const struct dentry * parent_dentry,
58052 + const struct vfsmount * parent_mnt,
58053 + const int mode)
58054 +{
58055 + return 1;
58056 +}
58057 +
58058 +__u32
58059 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58060 + const struct dentry * parent_dentry,
58061 + const struct vfsmount * parent_mnt)
58062 +{
58063 + return 1;
58064 +}
58065 +
58066 +__u32
58067 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58068 + const struct dentry * parent_dentry,
58069 + const struct vfsmount * parent_mnt, const struct filename *from)
58070 +{
58071 + return 1;
58072 +}
58073 +
58074 +__u32
58075 +gr_acl_handle_link(const struct dentry * new_dentry,
58076 + const struct dentry * parent_dentry,
58077 + const struct vfsmount * parent_mnt,
58078 + const struct dentry * old_dentry,
58079 + const struct vfsmount * old_mnt, const struct filename *to)
58080 +{
58081 + return 1;
58082 +}
58083 +
58084 +int
58085 +gr_acl_handle_rename(const struct dentry *new_dentry,
58086 + const struct dentry *parent_dentry,
58087 + const struct vfsmount *parent_mnt,
58088 + const struct dentry *old_dentry,
58089 + const struct inode *old_parent_inode,
58090 + const struct vfsmount *old_mnt, const struct filename *newname)
58091 +{
58092 + return 0;
58093 +}
58094 +
58095 +int
58096 +gr_acl_handle_filldir(const struct file *file, const char *name,
58097 + const int namelen, const ino_t ino)
58098 +{
58099 + return 1;
58100 +}
58101 +
58102 +int
58103 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58104 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58105 +{
58106 + return 1;
58107 +}
58108 +
58109 +int
58110 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58111 +{
58112 + return 0;
58113 +}
58114 +
58115 +int
58116 +gr_search_accept(const struct socket *sock)
58117 +{
58118 + return 0;
58119 +}
58120 +
58121 +int
58122 +gr_search_listen(const struct socket *sock)
58123 +{
58124 + return 0;
58125 +}
58126 +
58127 +int
58128 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58129 +{
58130 + return 0;
58131 +}
58132 +
58133 +__u32
58134 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58135 +{
58136 + return 1;
58137 +}
58138 +
58139 +__u32
58140 +gr_acl_handle_creat(const struct dentry * dentry,
58141 + const struct dentry * p_dentry,
58142 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58143 + const int imode)
58144 +{
58145 + return 1;
58146 +}
58147 +
58148 +void
58149 +gr_acl_handle_exit(void)
58150 +{
58151 + return;
58152 +}
58153 +
58154 +int
58155 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58156 +{
58157 + return 1;
58158 +}
58159 +
58160 +void
58161 +gr_set_role_label(const uid_t uid, const gid_t gid)
58162 +{
58163 + return;
58164 +}
58165 +
58166 +int
58167 +gr_acl_handle_procpidmem(const struct task_struct *task)
58168 +{
58169 + return 0;
58170 +}
58171 +
58172 +int
58173 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58174 +{
58175 + return 0;
58176 +}
58177 +
58178 +int
58179 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58180 +{
58181 + return 0;
58182 +}
58183 +
58184 +void
58185 +gr_set_kernel_label(struct task_struct *task)
58186 +{
58187 + return;
58188 +}
58189 +
58190 +int
58191 +gr_check_user_change(int real, int effective, int fs)
58192 +{
58193 + return 0;
58194 +}
58195 +
58196 +int
58197 +gr_check_group_change(int real, int effective, int fs)
58198 +{
58199 + return 0;
58200 +}
58201 +
58202 +int gr_acl_enable_at_secure(void)
58203 +{
58204 + return 0;
58205 +}
58206 +
58207 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58208 +{
58209 + return dentry->d_inode->i_sb->s_dev;
58210 +}
58211 +
58212 +void gr_put_exec_file(struct task_struct *task)
58213 +{
58214 + return;
58215 +}
58216 +
58217 +EXPORT_SYMBOL(gr_learn_resource);
58218 +EXPORT_SYMBOL(gr_set_kernel_label);
58219 +#ifdef CONFIG_SECURITY
58220 +EXPORT_SYMBOL(gr_check_user_change);
58221 +EXPORT_SYMBOL(gr_check_group_change);
58222 +#endif
58223 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58224 new file mode 100644
58225 index 0000000..abfa971
58226 --- /dev/null
58227 +++ b/grsecurity/grsec_exec.c
58228 @@ -0,0 +1,174 @@
58229 +#include <linux/kernel.h>
58230 +#include <linux/sched.h>
58231 +#include <linux/file.h>
58232 +#include <linux/binfmts.h>
58233 +#include <linux/fs.h>
58234 +#include <linux/types.h>
58235 +#include <linux/grdefs.h>
58236 +#include <linux/grsecurity.h>
58237 +#include <linux/grinternal.h>
58238 +#include <linux/capability.h>
58239 +#include <linux/module.h>
58240 +
58241 +#include <asm/uaccess.h>
58242 +
58243 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58244 +static char gr_exec_arg_buf[132];
58245 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58246 +#endif
58247 +
58248 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58249 +
58250 +void
58251 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58252 +{
58253 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58254 + char *grarg = gr_exec_arg_buf;
58255 + unsigned int i, x, execlen = 0;
58256 + char c;
58257 +
58258 + if (!((grsec_enable_execlog && grsec_enable_group &&
58259 + in_group_p(grsec_audit_gid))
58260 + || (grsec_enable_execlog && !grsec_enable_group)))
58261 + return;
58262 +
58263 + mutex_lock(&gr_exec_arg_mutex);
58264 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58265 +
58266 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58267 + const char __user *p;
58268 + unsigned int len;
58269 +
58270 + p = get_user_arg_ptr(argv, i);
58271 + if (IS_ERR(p))
58272 + goto log;
58273 +
58274 + len = strnlen_user(p, 128 - execlen);
58275 + if (len > 128 - execlen)
58276 + len = 128 - execlen;
58277 + else if (len > 0)
58278 + len--;
58279 + if (copy_from_user(grarg + execlen, p, len))
58280 + goto log;
58281 +
58282 + /* rewrite unprintable characters */
58283 + for (x = 0; x < len; x++) {
58284 + c = *(grarg + execlen + x);
58285 + if (c < 32 || c > 126)
58286 + *(grarg + execlen + x) = ' ';
58287 + }
58288 +
58289 + execlen += len;
58290 + *(grarg + execlen) = ' ';
58291 + *(grarg + execlen + 1) = '\0';
58292 + execlen++;
58293 + }
58294 +
58295 + log:
58296 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58297 + bprm->file->f_path.mnt, grarg);
58298 + mutex_unlock(&gr_exec_arg_mutex);
58299 +#endif
58300 + return;
58301 +}
58302 +
58303 +#ifdef CONFIG_GRKERNSEC
58304 +extern int gr_acl_is_capable(const int cap);
58305 +extern int gr_acl_is_capable_nolog(const int cap);
58306 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58307 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58308 +extern int gr_chroot_is_capable(const int cap);
58309 +extern int gr_chroot_is_capable_nolog(const int cap);
58310 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58311 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58312 +#endif
58313 +
58314 +const char *captab_log[] = {
58315 + "CAP_CHOWN",
58316 + "CAP_DAC_OVERRIDE",
58317 + "CAP_DAC_READ_SEARCH",
58318 + "CAP_FOWNER",
58319 + "CAP_FSETID",
58320 + "CAP_KILL",
58321 + "CAP_SETGID",
58322 + "CAP_SETUID",
58323 + "CAP_SETPCAP",
58324 + "CAP_LINUX_IMMUTABLE",
58325 + "CAP_NET_BIND_SERVICE",
58326 + "CAP_NET_BROADCAST",
58327 + "CAP_NET_ADMIN",
58328 + "CAP_NET_RAW",
58329 + "CAP_IPC_LOCK",
58330 + "CAP_IPC_OWNER",
58331 + "CAP_SYS_MODULE",
58332 + "CAP_SYS_RAWIO",
58333 + "CAP_SYS_CHROOT",
58334 + "CAP_SYS_PTRACE",
58335 + "CAP_SYS_PACCT",
58336 + "CAP_SYS_ADMIN",
58337 + "CAP_SYS_BOOT",
58338 + "CAP_SYS_NICE",
58339 + "CAP_SYS_RESOURCE",
58340 + "CAP_SYS_TIME",
58341 + "CAP_SYS_TTY_CONFIG",
58342 + "CAP_MKNOD",
58343 + "CAP_LEASE",
58344 + "CAP_AUDIT_WRITE",
58345 + "CAP_AUDIT_CONTROL",
58346 + "CAP_SETFCAP",
58347 + "CAP_MAC_OVERRIDE",
58348 + "CAP_MAC_ADMIN",
58349 + "CAP_SYSLOG",
58350 + "CAP_WAKE_ALARM"
58351 +};
58352 +
58353 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58354 +
58355 +int gr_is_capable(const int cap)
58356 +{
58357 +#ifdef CONFIG_GRKERNSEC
58358 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58359 + return 1;
58360 + return 0;
58361 +#else
58362 + return 1;
58363 +#endif
58364 +}
58365 +
58366 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58367 +{
58368 +#ifdef CONFIG_GRKERNSEC
58369 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58370 + return 1;
58371 + return 0;
58372 +#else
58373 + return 1;
58374 +#endif
58375 +}
58376 +
58377 +int gr_is_capable_nolog(const int cap)
58378 +{
58379 +#ifdef CONFIG_GRKERNSEC
58380 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58381 + return 1;
58382 + return 0;
58383 +#else
58384 + return 1;
58385 +#endif
58386 +}
58387 +
58388 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58389 +{
58390 +#ifdef CONFIG_GRKERNSEC
58391 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58392 + return 1;
58393 + return 0;
58394 +#else
58395 + return 1;
58396 +#endif
58397 +}
58398 +
58399 +EXPORT_SYMBOL(gr_is_capable);
58400 +EXPORT_SYMBOL(gr_is_capable_nolog);
58401 +EXPORT_SYMBOL(gr_task_is_capable);
58402 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58403 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58404 new file mode 100644
58405 index 0000000..d3ee748
58406 --- /dev/null
58407 +++ b/grsecurity/grsec_fifo.c
58408 @@ -0,0 +1,24 @@
58409 +#include <linux/kernel.h>
58410 +#include <linux/sched.h>
58411 +#include <linux/fs.h>
58412 +#include <linux/file.h>
58413 +#include <linux/grinternal.h>
58414 +
58415 +int
58416 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58417 + const struct dentry *dir, const int flag, const int acc_mode)
58418 +{
58419 +#ifdef CONFIG_GRKERNSEC_FIFO
58420 + const struct cred *cred = current_cred();
58421 +
58422 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58423 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58424 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58425 + (cred->fsuid != dentry->d_inode->i_uid)) {
58426 + if (!inode_permission(dentry->d_inode, acc_mode))
58427 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58428 + return -EACCES;
58429 + }
58430 +#endif
58431 + return 0;
58432 +}
58433 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58434 new file mode 100644
58435 index 0000000..8ca18bf
58436 --- /dev/null
58437 +++ b/grsecurity/grsec_fork.c
58438 @@ -0,0 +1,23 @@
58439 +#include <linux/kernel.h>
58440 +#include <linux/sched.h>
58441 +#include <linux/grsecurity.h>
58442 +#include <linux/grinternal.h>
58443 +#include <linux/errno.h>
58444 +
58445 +void
58446 +gr_log_forkfail(const int retval)
58447 +{
58448 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58449 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58450 + switch (retval) {
58451 + case -EAGAIN:
58452 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58453 + break;
58454 + case -ENOMEM:
58455 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58456 + break;
58457 + }
58458 + }
58459 +#endif
58460 + return;
58461 +}
58462 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58463 new file mode 100644
58464 index 0000000..05a6015
58465 --- /dev/null
58466 +++ b/grsecurity/grsec_init.c
58467 @@ -0,0 +1,283 @@
58468 +#include <linux/kernel.h>
58469 +#include <linux/sched.h>
58470 +#include <linux/mm.h>
58471 +#include <linux/gracl.h>
58472 +#include <linux/slab.h>
58473 +#include <linux/vmalloc.h>
58474 +#include <linux/percpu.h>
58475 +#include <linux/module.h>
58476 +
58477 +int grsec_enable_ptrace_readexec;
58478 +int grsec_enable_setxid;
58479 +int grsec_enable_symlinkown;
58480 +int grsec_symlinkown_gid;
58481 +int grsec_enable_brute;
58482 +int grsec_enable_link;
58483 +int grsec_enable_dmesg;
58484 +int grsec_enable_harden_ptrace;
58485 +int grsec_enable_fifo;
58486 +int grsec_enable_execlog;
58487 +int grsec_enable_signal;
58488 +int grsec_enable_forkfail;
58489 +int grsec_enable_audit_ptrace;
58490 +int grsec_enable_time;
58491 +int grsec_enable_audit_textrel;
58492 +int grsec_enable_group;
58493 +int grsec_audit_gid;
58494 +int grsec_enable_chdir;
58495 +int grsec_enable_mount;
58496 +int grsec_enable_rofs;
58497 +int grsec_enable_chroot_findtask;
58498 +int grsec_enable_chroot_mount;
58499 +int grsec_enable_chroot_shmat;
58500 +int grsec_enable_chroot_fchdir;
58501 +int grsec_enable_chroot_double;
58502 +int grsec_enable_chroot_pivot;
58503 +int grsec_enable_chroot_chdir;
58504 +int grsec_enable_chroot_chmod;
58505 +int grsec_enable_chroot_mknod;
58506 +int grsec_enable_chroot_nice;
58507 +int grsec_enable_chroot_execlog;
58508 +int grsec_enable_chroot_caps;
58509 +int grsec_enable_chroot_sysctl;
58510 +int grsec_enable_chroot_unix;
58511 +int grsec_enable_tpe;
58512 +int grsec_tpe_gid;
58513 +int grsec_enable_blackhole;
58514 +#ifdef CONFIG_IPV6_MODULE
58515 +EXPORT_SYMBOL(grsec_enable_blackhole);
58516 +#endif
58517 +int grsec_lastack_retries;
58518 +int grsec_enable_tpe_all;
58519 +int grsec_enable_tpe_invert;
58520 +int grsec_enable_socket_all;
58521 +int grsec_socket_all_gid;
58522 +int grsec_enable_socket_client;
58523 +int grsec_socket_client_gid;
58524 +int grsec_enable_socket_server;
58525 +int grsec_socket_server_gid;
58526 +int grsec_resource_logging;
58527 +int grsec_disable_privio;
58528 +int grsec_enable_log_rwxmaps;
58529 +int grsec_lock;
58530 +
58531 +DEFINE_SPINLOCK(grsec_alert_lock);
58532 +unsigned long grsec_alert_wtime = 0;
58533 +unsigned long grsec_alert_fyet = 0;
58534 +
58535 +DEFINE_SPINLOCK(grsec_audit_lock);
58536 +
58537 +DEFINE_RWLOCK(grsec_exec_file_lock);
58538 +
58539 +char *gr_shared_page[4];
58540 +
58541 +char *gr_alert_log_fmt;
58542 +char *gr_audit_log_fmt;
58543 +char *gr_alert_log_buf;
58544 +char *gr_audit_log_buf;
58545 +
58546 +extern struct gr_arg *gr_usermode;
58547 +extern unsigned char *gr_system_salt;
58548 +extern unsigned char *gr_system_sum;
58549 +
58550 +void __init
58551 +grsecurity_init(void)
58552 +{
58553 + int j;
58554 + /* create the per-cpu shared pages */
58555 +
58556 +#ifdef CONFIG_X86
58557 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58558 +#endif
58559 +
58560 + for (j = 0; j < 4; j++) {
58561 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58562 + if (gr_shared_page[j] == NULL) {
58563 + panic("Unable to allocate grsecurity shared page");
58564 + return;
58565 + }
58566 + }
58567 +
58568 + /* allocate log buffers */
58569 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58570 + if (!gr_alert_log_fmt) {
58571 + panic("Unable to allocate grsecurity alert log format buffer");
58572 + return;
58573 + }
58574 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58575 + if (!gr_audit_log_fmt) {
58576 + panic("Unable to allocate grsecurity audit log format buffer");
58577 + return;
58578 + }
58579 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58580 + if (!gr_alert_log_buf) {
58581 + panic("Unable to allocate grsecurity alert log buffer");
58582 + return;
58583 + }
58584 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58585 + if (!gr_audit_log_buf) {
58586 + panic("Unable to allocate grsecurity audit log buffer");
58587 + return;
58588 + }
58589 +
58590 + /* allocate memory for authentication structure */
58591 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58592 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58593 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58594 +
58595 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58596 + panic("Unable to allocate grsecurity authentication structure");
58597 + return;
58598 + }
58599 +
58600 +
58601 +#ifdef CONFIG_GRKERNSEC_IO
58602 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58603 + grsec_disable_privio = 1;
58604 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58605 + grsec_disable_privio = 1;
58606 +#else
58607 + grsec_disable_privio = 0;
58608 +#endif
58609 +#endif
58610 +
58611 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58612 + /* for backward compatibility, tpe_invert always defaults to on if
58613 + enabled in the kernel
58614 + */
58615 + grsec_enable_tpe_invert = 1;
58616 +#endif
58617 +
58618 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58619 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58620 + grsec_lock = 1;
58621 +#endif
58622 +
58623 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58624 + grsec_enable_audit_textrel = 1;
58625 +#endif
58626 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58627 + grsec_enable_log_rwxmaps = 1;
58628 +#endif
58629 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58630 + grsec_enable_group = 1;
58631 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58632 +#endif
58633 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58634 + grsec_enable_ptrace_readexec = 1;
58635 +#endif
58636 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58637 + grsec_enable_chdir = 1;
58638 +#endif
58639 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58640 + grsec_enable_harden_ptrace = 1;
58641 +#endif
58642 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58643 + grsec_enable_mount = 1;
58644 +#endif
58645 +#ifdef CONFIG_GRKERNSEC_LINK
58646 + grsec_enable_link = 1;
58647 +#endif
58648 +#ifdef CONFIG_GRKERNSEC_BRUTE
58649 + grsec_enable_brute = 1;
58650 +#endif
58651 +#ifdef CONFIG_GRKERNSEC_DMESG
58652 + grsec_enable_dmesg = 1;
58653 +#endif
58654 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58655 + grsec_enable_blackhole = 1;
58656 + grsec_lastack_retries = 4;
58657 +#endif
58658 +#ifdef CONFIG_GRKERNSEC_FIFO
58659 + grsec_enable_fifo = 1;
58660 +#endif
58661 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58662 + grsec_enable_execlog = 1;
58663 +#endif
58664 +#ifdef CONFIG_GRKERNSEC_SETXID
58665 + grsec_enable_setxid = 1;
58666 +#endif
58667 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58668 + grsec_enable_signal = 1;
58669 +#endif
58670 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58671 + grsec_enable_forkfail = 1;
58672 +#endif
58673 +#ifdef CONFIG_GRKERNSEC_TIME
58674 + grsec_enable_time = 1;
58675 +#endif
58676 +#ifdef CONFIG_GRKERNSEC_RESLOG
58677 + grsec_resource_logging = 1;
58678 +#endif
58679 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58680 + grsec_enable_chroot_findtask = 1;
58681 +#endif
58682 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58683 + grsec_enable_chroot_unix = 1;
58684 +#endif
58685 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58686 + grsec_enable_chroot_mount = 1;
58687 +#endif
58688 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58689 + grsec_enable_chroot_fchdir = 1;
58690 +#endif
58691 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58692 + grsec_enable_chroot_shmat = 1;
58693 +#endif
58694 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58695 + grsec_enable_audit_ptrace = 1;
58696 +#endif
58697 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58698 + grsec_enable_chroot_double = 1;
58699 +#endif
58700 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58701 + grsec_enable_chroot_pivot = 1;
58702 +#endif
58703 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58704 + grsec_enable_chroot_chdir = 1;
58705 +#endif
58706 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58707 + grsec_enable_chroot_chmod = 1;
58708 +#endif
58709 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58710 + grsec_enable_chroot_mknod = 1;
58711 +#endif
58712 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58713 + grsec_enable_chroot_nice = 1;
58714 +#endif
58715 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58716 + grsec_enable_chroot_execlog = 1;
58717 +#endif
58718 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58719 + grsec_enable_chroot_caps = 1;
58720 +#endif
58721 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58722 + grsec_enable_chroot_sysctl = 1;
58723 +#endif
58724 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58725 + grsec_enable_symlinkown = 1;
58726 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58727 +#endif
58728 +#ifdef CONFIG_GRKERNSEC_TPE
58729 + grsec_enable_tpe = 1;
58730 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58731 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58732 + grsec_enable_tpe_all = 1;
58733 +#endif
58734 +#endif
58735 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58736 + grsec_enable_socket_all = 1;
58737 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58738 +#endif
58739 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58740 + grsec_enable_socket_client = 1;
58741 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58742 +#endif
58743 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58744 + grsec_enable_socket_server = 1;
58745 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58746 +#endif
58747 +#endif
58748 +
58749 + return;
58750 +}
58751 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58752 new file mode 100644
58753 index 0000000..6095407
58754 --- /dev/null
58755 +++ b/grsecurity/grsec_link.c
58756 @@ -0,0 +1,58 @@
58757 +#include <linux/kernel.h>
58758 +#include <linux/sched.h>
58759 +#include <linux/fs.h>
58760 +#include <linux/file.h>
58761 +#include <linux/grinternal.h>
58762 +
58763 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58764 +{
58765 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58766 + const struct inode *link_inode = link->dentry->d_inode;
58767 +
58768 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58769 + /* ignore root-owned links, e.g. /proc/self */
58770 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58771 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58772 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58773 + return 1;
58774 + }
58775 +#endif
58776 + return 0;
58777 +}
58778 +
58779 +int
58780 +gr_handle_follow_link(const struct inode *parent,
58781 + const struct inode *inode,
58782 + const struct dentry *dentry, const struct vfsmount *mnt)
58783 +{
58784 +#ifdef CONFIG_GRKERNSEC_LINK
58785 + const struct cred *cred = current_cred();
58786 +
58787 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58788 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58789 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58790 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58791 + return -EACCES;
58792 + }
58793 +#endif
58794 + return 0;
58795 +}
58796 +
58797 +int
58798 +gr_handle_hardlink(const struct dentry *dentry,
58799 + const struct vfsmount *mnt,
58800 + struct inode *inode, const int mode, const struct filename *to)
58801 +{
58802 +#ifdef CONFIG_GRKERNSEC_LINK
58803 + const struct cred *cred = current_cred();
58804 +
58805 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58806 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58807 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58808 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58809 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
58810 + return -EPERM;
58811 + }
58812 +#endif
58813 + return 0;
58814 +}
58815 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58816 new file mode 100644
58817 index 0000000..a45d2e9
58818 --- /dev/null
58819 +++ b/grsecurity/grsec_log.c
58820 @@ -0,0 +1,322 @@
58821 +#include <linux/kernel.h>
58822 +#include <linux/sched.h>
58823 +#include <linux/file.h>
58824 +#include <linux/tty.h>
58825 +#include <linux/fs.h>
58826 +#include <linux/grinternal.h>
58827 +
58828 +#ifdef CONFIG_TREE_PREEMPT_RCU
58829 +#define DISABLE_PREEMPT() preempt_disable()
58830 +#define ENABLE_PREEMPT() preempt_enable()
58831 +#else
58832 +#define DISABLE_PREEMPT()
58833 +#define ENABLE_PREEMPT()
58834 +#endif
58835 +
58836 +#define BEGIN_LOCKS(x) \
58837 + DISABLE_PREEMPT(); \
58838 + rcu_read_lock(); \
58839 + read_lock(&tasklist_lock); \
58840 + read_lock(&grsec_exec_file_lock); \
58841 + if (x != GR_DO_AUDIT) \
58842 + spin_lock(&grsec_alert_lock); \
58843 + else \
58844 + spin_lock(&grsec_audit_lock)
58845 +
58846 +#define END_LOCKS(x) \
58847 + if (x != GR_DO_AUDIT) \
58848 + spin_unlock(&grsec_alert_lock); \
58849 + else \
58850 + spin_unlock(&grsec_audit_lock); \
58851 + read_unlock(&grsec_exec_file_lock); \
58852 + read_unlock(&tasklist_lock); \
58853 + rcu_read_unlock(); \
58854 + ENABLE_PREEMPT(); \
58855 + if (x == GR_DONT_AUDIT) \
58856 + gr_handle_alertkill(current)
58857 +
58858 +enum {
58859 + FLOODING,
58860 + NO_FLOODING
58861 +};
58862 +
58863 +extern char *gr_alert_log_fmt;
58864 +extern char *gr_audit_log_fmt;
58865 +extern char *gr_alert_log_buf;
58866 +extern char *gr_audit_log_buf;
58867 +
58868 +static int gr_log_start(int audit)
58869 +{
58870 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58871 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58872 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58873 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58874 + unsigned long curr_secs = get_seconds();
58875 +
58876 + if (audit == GR_DO_AUDIT)
58877 + goto set_fmt;
58878 +
58879 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58880 + grsec_alert_wtime = curr_secs;
58881 + grsec_alert_fyet = 0;
58882 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58883 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58884 + grsec_alert_fyet++;
58885 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58886 + grsec_alert_wtime = curr_secs;
58887 + grsec_alert_fyet++;
58888 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58889 + return FLOODING;
58890 + }
58891 + else return FLOODING;
58892 +
58893 +set_fmt:
58894 +#endif
58895 + memset(buf, 0, PAGE_SIZE);
58896 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58897 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58898 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58899 + } else if (current->signal->curr_ip) {
58900 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58901 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58902 + } else if (gr_acl_is_enabled()) {
58903 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58904 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58905 + } else {
58906 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58907 + strcpy(buf, fmt);
58908 + }
58909 +
58910 + return NO_FLOODING;
58911 +}
58912 +
58913 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58914 + __attribute__ ((format (printf, 2, 0)));
58915 +
58916 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58917 +{
58918 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58919 + unsigned int len = strlen(buf);
58920 +
58921 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58922 +
58923 + return;
58924 +}
58925 +
58926 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58927 + __attribute__ ((format (printf, 2, 3)));
58928 +
58929 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58930 +{
58931 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58932 + unsigned int len = strlen(buf);
58933 + va_list ap;
58934 +
58935 + va_start(ap, msg);
58936 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58937 + va_end(ap);
58938 +
58939 + return;
58940 +}
58941 +
58942 +static void gr_log_end(int audit, int append_default)
58943 +{
58944 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58945 +
58946 + if (append_default) {
58947 + unsigned int len = strlen(buf);
58948 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58949 + }
58950 +
58951 + printk("%s\n", buf);
58952 +
58953 + return;
58954 +}
58955 +
58956 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58957 +{
58958 + int logtype;
58959 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58960 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58961 + void *voidptr = NULL;
58962 + int num1 = 0, num2 = 0;
58963 + unsigned long ulong1 = 0, ulong2 = 0;
58964 + struct dentry *dentry = NULL;
58965 + struct vfsmount *mnt = NULL;
58966 + struct file *file = NULL;
58967 + struct task_struct *task = NULL;
58968 + const struct cred *cred, *pcred;
58969 + va_list ap;
58970 +
58971 + BEGIN_LOCKS(audit);
58972 + logtype = gr_log_start(audit);
58973 + if (logtype == FLOODING) {
58974 + END_LOCKS(audit);
58975 + return;
58976 + }
58977 + va_start(ap, argtypes);
58978 + switch (argtypes) {
58979 + case GR_TTYSNIFF:
58980 + task = va_arg(ap, struct task_struct *);
58981 + 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);
58982 + break;
58983 + case GR_SYSCTL_HIDDEN:
58984 + str1 = va_arg(ap, char *);
58985 + gr_log_middle_varargs(audit, msg, result, str1);
58986 + break;
58987 + case GR_RBAC:
58988 + dentry = va_arg(ap, struct dentry *);
58989 + mnt = va_arg(ap, struct vfsmount *);
58990 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58991 + break;
58992 + case GR_RBAC_STR:
58993 + dentry = va_arg(ap, struct dentry *);
58994 + mnt = va_arg(ap, struct vfsmount *);
58995 + str1 = va_arg(ap, char *);
58996 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58997 + break;
58998 + case GR_STR_RBAC:
58999 + str1 = va_arg(ap, char *);
59000 + dentry = va_arg(ap, struct dentry *);
59001 + mnt = va_arg(ap, struct vfsmount *);
59002 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59003 + break;
59004 + case GR_RBAC_MODE2:
59005 + dentry = va_arg(ap, struct dentry *);
59006 + mnt = va_arg(ap, struct vfsmount *);
59007 + str1 = va_arg(ap, char *);
59008 + str2 = va_arg(ap, char *);
59009 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59010 + break;
59011 + case GR_RBAC_MODE3:
59012 + dentry = va_arg(ap, struct dentry *);
59013 + mnt = va_arg(ap, struct vfsmount *);
59014 + str1 = va_arg(ap, char *);
59015 + str2 = va_arg(ap, char *);
59016 + str3 = va_arg(ap, char *);
59017 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59018 + break;
59019 + case GR_FILENAME:
59020 + dentry = va_arg(ap, struct dentry *);
59021 + mnt = va_arg(ap, struct vfsmount *);
59022 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59023 + break;
59024 + case GR_STR_FILENAME:
59025 + str1 = va_arg(ap, char *);
59026 + dentry = va_arg(ap, struct dentry *);
59027 + mnt = va_arg(ap, struct vfsmount *);
59028 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59029 + break;
59030 + case GR_FILENAME_STR:
59031 + dentry = va_arg(ap, struct dentry *);
59032 + mnt = va_arg(ap, struct vfsmount *);
59033 + str1 = va_arg(ap, char *);
59034 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59035 + break;
59036 + case GR_FILENAME_TWO_INT:
59037 + dentry = va_arg(ap, struct dentry *);
59038 + mnt = va_arg(ap, struct vfsmount *);
59039 + num1 = va_arg(ap, int);
59040 + num2 = va_arg(ap, int);
59041 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59042 + break;
59043 + case GR_FILENAME_TWO_INT_STR:
59044 + dentry = va_arg(ap, struct dentry *);
59045 + mnt = va_arg(ap, struct vfsmount *);
59046 + num1 = va_arg(ap, int);
59047 + num2 = va_arg(ap, int);
59048 + str1 = va_arg(ap, char *);
59049 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59050 + break;
59051 + case GR_TEXTREL:
59052 + file = va_arg(ap, struct file *);
59053 + ulong1 = va_arg(ap, unsigned long);
59054 + ulong2 = va_arg(ap, unsigned long);
59055 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59056 + break;
59057 + case GR_PTRACE:
59058 + task = va_arg(ap, struct task_struct *);
59059 + 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);
59060 + break;
59061 + case GR_RESOURCE:
59062 + task = va_arg(ap, struct task_struct *);
59063 + cred = __task_cred(task);
59064 + pcred = __task_cred(task->real_parent);
59065 + ulong1 = va_arg(ap, unsigned long);
59066 + str1 = va_arg(ap, char *);
59067 + ulong2 = va_arg(ap, unsigned long);
59068 + 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);
59069 + break;
59070 + case GR_CAP:
59071 + task = va_arg(ap, struct task_struct *);
59072 + cred = __task_cred(task);
59073 + pcred = __task_cred(task->real_parent);
59074 + str1 = va_arg(ap, char *);
59075 + 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);
59076 + break;
59077 + case GR_SIG:
59078 + str1 = va_arg(ap, char *);
59079 + voidptr = va_arg(ap, void *);
59080 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59081 + break;
59082 + case GR_SIG2:
59083 + task = va_arg(ap, struct task_struct *);
59084 + cred = __task_cred(task);
59085 + pcred = __task_cred(task->real_parent);
59086 + num1 = va_arg(ap, int);
59087 + 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);
59088 + break;
59089 + case GR_CRASH1:
59090 + task = va_arg(ap, struct task_struct *);
59091 + cred = __task_cred(task);
59092 + pcred = __task_cred(task->real_parent);
59093 + ulong1 = va_arg(ap, unsigned long);
59094 + 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);
59095 + break;
59096 + case GR_CRASH2:
59097 + task = va_arg(ap, struct task_struct *);
59098 + cred = __task_cred(task);
59099 + pcred = __task_cred(task->real_parent);
59100 + ulong1 = va_arg(ap, unsigned long);
59101 + 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);
59102 + break;
59103 + case GR_RWXMAP:
59104 + file = va_arg(ap, struct file *);
59105 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59106 + break;
59107 + case GR_PSACCT:
59108 + {
59109 + unsigned int wday, cday;
59110 + __u8 whr, chr;
59111 + __u8 wmin, cmin;
59112 + __u8 wsec, csec;
59113 + char cur_tty[64] = { 0 };
59114 + char parent_tty[64] = { 0 };
59115 +
59116 + task = va_arg(ap, struct task_struct *);
59117 + wday = va_arg(ap, unsigned int);
59118 + cday = va_arg(ap, unsigned int);
59119 + whr = va_arg(ap, int);
59120 + chr = va_arg(ap, int);
59121 + wmin = va_arg(ap, int);
59122 + cmin = va_arg(ap, int);
59123 + wsec = va_arg(ap, int);
59124 + csec = va_arg(ap, int);
59125 + ulong1 = va_arg(ap, unsigned long);
59126 + cred = __task_cred(task);
59127 + pcred = __task_cred(task->real_parent);
59128 +
59129 + 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);
59130 + }
59131 + break;
59132 + default:
59133 + gr_log_middle(audit, msg, ap);
59134 + }
59135 + va_end(ap);
59136 + // these don't need DEFAULTSECARGS printed on the end
59137 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59138 + gr_log_end(audit, 0);
59139 + else
59140 + gr_log_end(audit, 1);
59141 + END_LOCKS(audit);
59142 +}
59143 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59144 new file mode 100644
59145 index 0000000..f536303
59146 --- /dev/null
59147 +++ b/grsecurity/grsec_mem.c
59148 @@ -0,0 +1,40 @@
59149 +#include <linux/kernel.h>
59150 +#include <linux/sched.h>
59151 +#include <linux/mm.h>
59152 +#include <linux/mman.h>
59153 +#include <linux/grinternal.h>
59154 +
59155 +void
59156 +gr_handle_ioperm(void)
59157 +{
59158 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59159 + return;
59160 +}
59161 +
59162 +void
59163 +gr_handle_iopl(void)
59164 +{
59165 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59166 + return;
59167 +}
59168 +
59169 +void
59170 +gr_handle_mem_readwrite(u64 from, u64 to)
59171 +{
59172 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59173 + return;
59174 +}
59175 +
59176 +void
59177 +gr_handle_vm86(void)
59178 +{
59179 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59180 + return;
59181 +}
59182 +
59183 +void
59184 +gr_log_badprocpid(const char *entry)
59185 +{
59186 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59187 + return;
59188 +}
59189 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59190 new file mode 100644
59191 index 0000000..2131422
59192 --- /dev/null
59193 +++ b/grsecurity/grsec_mount.c
59194 @@ -0,0 +1,62 @@
59195 +#include <linux/kernel.h>
59196 +#include <linux/sched.h>
59197 +#include <linux/mount.h>
59198 +#include <linux/grsecurity.h>
59199 +#include <linux/grinternal.h>
59200 +
59201 +void
59202 +gr_log_remount(const char *devname, const int retval)
59203 +{
59204 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59205 + if (grsec_enable_mount && (retval >= 0))
59206 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59207 +#endif
59208 + return;
59209 +}
59210 +
59211 +void
59212 +gr_log_unmount(const char *devname, const int retval)
59213 +{
59214 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59215 + if (grsec_enable_mount && (retval >= 0))
59216 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59217 +#endif
59218 + return;
59219 +}
59220 +
59221 +void
59222 +gr_log_mount(const char *from, const char *to, const int retval)
59223 +{
59224 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59225 + if (grsec_enable_mount && (retval >= 0))
59226 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59227 +#endif
59228 + return;
59229 +}
59230 +
59231 +int
59232 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59233 +{
59234 +#ifdef CONFIG_GRKERNSEC_ROFS
59235 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59236 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59237 + return -EPERM;
59238 + } else
59239 + return 0;
59240 +#endif
59241 + return 0;
59242 +}
59243 +
59244 +int
59245 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59246 +{
59247 +#ifdef CONFIG_GRKERNSEC_ROFS
59248 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59249 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59250 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59251 + return -EPERM;
59252 + } else
59253 + return 0;
59254 +#endif
59255 + return 0;
59256 +}
59257 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59258 new file mode 100644
59259 index 0000000..a3b12a0
59260 --- /dev/null
59261 +++ b/grsecurity/grsec_pax.c
59262 @@ -0,0 +1,36 @@
59263 +#include <linux/kernel.h>
59264 +#include <linux/sched.h>
59265 +#include <linux/mm.h>
59266 +#include <linux/file.h>
59267 +#include <linux/grinternal.h>
59268 +#include <linux/grsecurity.h>
59269 +
59270 +void
59271 +gr_log_textrel(struct vm_area_struct * vma)
59272 +{
59273 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59274 + if (grsec_enable_audit_textrel)
59275 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59276 +#endif
59277 + return;
59278 +}
59279 +
59280 +void
59281 +gr_log_rwxmmap(struct file *file)
59282 +{
59283 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59284 + if (grsec_enable_log_rwxmaps)
59285 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59286 +#endif
59287 + return;
59288 +}
59289 +
59290 +void
59291 +gr_log_rwxmprotect(struct file *file)
59292 +{
59293 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59294 + if (grsec_enable_log_rwxmaps)
59295 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59296 +#endif
59297 + return;
59298 +}
59299 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59300 new file mode 100644
59301 index 0000000..f7f29aa
59302 --- /dev/null
59303 +++ b/grsecurity/grsec_ptrace.c
59304 @@ -0,0 +1,30 @@
59305 +#include <linux/kernel.h>
59306 +#include <linux/sched.h>
59307 +#include <linux/grinternal.h>
59308 +#include <linux/security.h>
59309 +
59310 +void
59311 +gr_audit_ptrace(struct task_struct *task)
59312 +{
59313 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59314 + if (grsec_enable_audit_ptrace)
59315 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59316 +#endif
59317 + return;
59318 +}
59319 +
59320 +int
59321 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59322 +{
59323 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59324 + const struct dentry *dentry = file->f_path.dentry;
59325 + const struct vfsmount *mnt = file->f_path.mnt;
59326 +
59327 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59328 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59329 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59330 + return -EACCES;
59331 + }
59332 +#endif
59333 + return 0;
59334 +}
59335 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59336 new file mode 100644
59337 index 0000000..5c00416
59338 --- /dev/null
59339 +++ b/grsecurity/grsec_sig.c
59340 @@ -0,0 +1,222 @@
59341 +#include <linux/kernel.h>
59342 +#include <linux/sched.h>
59343 +#include <linux/delay.h>
59344 +#include <linux/grsecurity.h>
59345 +#include <linux/grinternal.h>
59346 +#include <linux/hardirq.h>
59347 +
59348 +char *signames[] = {
59349 + [SIGSEGV] = "Segmentation fault",
59350 + [SIGILL] = "Illegal instruction",
59351 + [SIGABRT] = "Abort",
59352 + [SIGBUS] = "Invalid alignment/Bus error"
59353 +};
59354 +
59355 +void
59356 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59357 +{
59358 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59359 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59360 + (sig == SIGABRT) || (sig == SIGBUS))) {
59361 + if (t->pid == current->pid) {
59362 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59363 + } else {
59364 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59365 + }
59366 + }
59367 +#endif
59368 + return;
59369 +}
59370 +
59371 +int
59372 +gr_handle_signal(const struct task_struct *p, const int sig)
59373 +{
59374 +#ifdef CONFIG_GRKERNSEC
59375 + /* ignore the 0 signal for protected task checks */
59376 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59377 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59378 + return -EPERM;
59379 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59380 + return -EPERM;
59381 + }
59382 +#endif
59383 + return 0;
59384 +}
59385 +
59386 +#ifdef CONFIG_GRKERNSEC
59387 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59388 +
59389 +int gr_fake_force_sig(int sig, struct task_struct *t)
59390 +{
59391 + unsigned long int flags;
59392 + int ret, blocked, ignored;
59393 + struct k_sigaction *action;
59394 +
59395 + spin_lock_irqsave(&t->sighand->siglock, flags);
59396 + action = &t->sighand->action[sig-1];
59397 + ignored = action->sa.sa_handler == SIG_IGN;
59398 + blocked = sigismember(&t->blocked, sig);
59399 + if (blocked || ignored) {
59400 + action->sa.sa_handler = SIG_DFL;
59401 + if (blocked) {
59402 + sigdelset(&t->blocked, sig);
59403 + recalc_sigpending_and_wake(t);
59404 + }
59405 + }
59406 + if (action->sa.sa_handler == SIG_DFL)
59407 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59408 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59409 +
59410 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59411 +
59412 + return ret;
59413 +}
59414 +#endif
59415 +
59416 +#ifdef CONFIG_GRKERNSEC_BRUTE
59417 +#define GR_USER_BAN_TIME (15 * 60)
59418 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
59419 +
59420 +static int __get_dumpable(unsigned long mm_flags)
59421 +{
59422 + int ret;
59423 +
59424 + ret = mm_flags & MMF_DUMPABLE_MASK;
59425 + return (ret >= 2) ? 2 : ret;
59426 +}
59427 +#endif
59428 +
59429 +void gr_handle_brute_attach(unsigned long mm_flags)
59430 +{
59431 +#ifdef CONFIG_GRKERNSEC_BRUTE
59432 + struct task_struct *p = current;
59433 + kuid_t uid = GLOBAL_ROOT_UID;
59434 + int daemon = 0;
59435 +
59436 + if (!grsec_enable_brute)
59437 + return;
59438 +
59439 + rcu_read_lock();
59440 + read_lock(&tasklist_lock);
59441 + read_lock(&grsec_exec_file_lock);
59442 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
59443 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
59444 + p->real_parent->brute = 1;
59445 + daemon = 1;
59446 + } else {
59447 + const struct cred *cred = __task_cred(p), *cred2;
59448 + struct task_struct *tsk, *tsk2;
59449 +
59450 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59451 + struct user_struct *user;
59452 +
59453 + uid = cred->uid;
59454 +
59455 + /* this is put upon execution past expiration */
59456 + user = find_user(uid);
59457 + if (user == NULL)
59458 + goto unlock;
59459 + user->banned = 1;
59460 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59461 + if (user->ban_expires == ~0UL)
59462 + user->ban_expires--;
59463 +
59464 + do_each_thread(tsk2, tsk) {
59465 + cred2 = __task_cred(tsk);
59466 + if (tsk != p && uid_eq(cred2->uid, uid))
59467 + gr_fake_force_sig(SIGKILL, tsk);
59468 + } while_each_thread(tsk2, tsk);
59469 + }
59470 + }
59471 +unlock:
59472 + read_unlock(&grsec_exec_file_lock);
59473 + read_unlock(&tasklist_lock);
59474 + rcu_read_unlock();
59475 +
59476 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59477 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59478 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59479 + else if (daemon)
59480 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
59481 +
59482 +#endif
59483 + return;
59484 +}
59485 +
59486 +void gr_handle_brute_check(void)
59487 +{
59488 +#ifdef CONFIG_GRKERNSEC_BRUTE
59489 + struct task_struct *p = current;
59490 +
59491 + if (unlikely(p->brute)) {
59492 + if (!grsec_enable_brute)
59493 + p->brute = 0;
59494 + else if (time_before(get_seconds(), p->brute_expires))
59495 + msleep(30 * 1000);
59496 + }
59497 +#endif
59498 + return;
59499 +}
59500 +
59501 +void gr_handle_kernel_exploit(void)
59502 +{
59503 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59504 + const struct cred *cred;
59505 + struct task_struct *tsk, *tsk2;
59506 + struct user_struct *user;
59507 + kuid_t uid;
59508 +
59509 + if (in_irq() || in_serving_softirq() || in_nmi())
59510 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59511 +
59512 + uid = current_uid();
59513 +
59514 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59515 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59516 + else {
59517 + /* kill all the processes of this user, hold a reference
59518 + to their creds struct, and prevent them from creating
59519 + another process until system reset
59520 + */
59521 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59522 + from_kuid_munged(&init_user_ns, uid));
59523 + /* we intentionally leak this ref */
59524 + user = get_uid(current->cred->user);
59525 + if (user) {
59526 + user->banned = 1;
59527 + user->ban_expires = ~0UL;
59528 + }
59529 +
59530 + read_lock(&tasklist_lock);
59531 + do_each_thread(tsk2, tsk) {
59532 + cred = __task_cred(tsk);
59533 + if (uid_eq(cred->uid, uid))
59534 + gr_fake_force_sig(SIGKILL, tsk);
59535 + } while_each_thread(tsk2, tsk);
59536 + read_unlock(&tasklist_lock);
59537 + }
59538 +#endif
59539 +}
59540 +
59541 +int __gr_process_user_ban(struct user_struct *user)
59542 +{
59543 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59544 + if (unlikely(user->banned)) {
59545 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59546 + user->banned = 0;
59547 + user->ban_expires = 0;
59548 + free_uid(user);
59549 + } else
59550 + return -EPERM;
59551 + }
59552 +#endif
59553 + return 0;
59554 +}
59555 +
59556 +int gr_process_user_ban(void)
59557 +{
59558 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59559 + return __gr_process_user_ban(current->cred->user);
59560 +#endif
59561 + return 0;
59562 +}
59563 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59564 new file mode 100644
59565 index 0000000..4030d57
59566 --- /dev/null
59567 +++ b/grsecurity/grsec_sock.c
59568 @@ -0,0 +1,244 @@
59569 +#include <linux/kernel.h>
59570 +#include <linux/module.h>
59571 +#include <linux/sched.h>
59572 +#include <linux/file.h>
59573 +#include <linux/net.h>
59574 +#include <linux/in.h>
59575 +#include <linux/ip.h>
59576 +#include <net/sock.h>
59577 +#include <net/inet_sock.h>
59578 +#include <linux/grsecurity.h>
59579 +#include <linux/grinternal.h>
59580 +#include <linux/gracl.h>
59581 +
59582 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59583 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59584 +
59585 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59586 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59587 +
59588 +#ifdef CONFIG_UNIX_MODULE
59589 +EXPORT_SYMBOL(gr_acl_handle_unix);
59590 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59591 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59592 +EXPORT_SYMBOL(gr_handle_create);
59593 +#endif
59594 +
59595 +#ifdef CONFIG_GRKERNSEC
59596 +#define gr_conn_table_size 32749
59597 +struct conn_table_entry {
59598 + struct conn_table_entry *next;
59599 + struct signal_struct *sig;
59600 +};
59601 +
59602 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59603 +DEFINE_SPINLOCK(gr_conn_table_lock);
59604 +
59605 +extern const char * gr_socktype_to_name(unsigned char type);
59606 +extern const char * gr_proto_to_name(unsigned char proto);
59607 +extern const char * gr_sockfamily_to_name(unsigned char family);
59608 +
59609 +static __inline__ int
59610 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59611 +{
59612 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59613 +}
59614 +
59615 +static __inline__ int
59616 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59617 + __u16 sport, __u16 dport)
59618 +{
59619 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59620 + sig->gr_sport == sport && sig->gr_dport == dport))
59621 + return 1;
59622 + else
59623 + return 0;
59624 +}
59625 +
59626 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59627 +{
59628 + struct conn_table_entry **match;
59629 + unsigned int index;
59630 +
59631 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59632 + sig->gr_sport, sig->gr_dport,
59633 + gr_conn_table_size);
59634 +
59635 + newent->sig = sig;
59636 +
59637 + match = &gr_conn_table[index];
59638 + newent->next = *match;
59639 + *match = newent;
59640 +
59641 + return;
59642 +}
59643 +
59644 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59645 +{
59646 + struct conn_table_entry *match, *last = NULL;
59647 + unsigned int index;
59648 +
59649 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59650 + sig->gr_sport, sig->gr_dport,
59651 + gr_conn_table_size);
59652 +
59653 + match = gr_conn_table[index];
59654 + while (match && !conn_match(match->sig,
59655 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59656 + sig->gr_dport)) {
59657 + last = match;
59658 + match = match->next;
59659 + }
59660 +
59661 + if (match) {
59662 + if (last)
59663 + last->next = match->next;
59664 + else
59665 + gr_conn_table[index] = NULL;
59666 + kfree(match);
59667 + }
59668 +
59669 + return;
59670 +}
59671 +
59672 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59673 + __u16 sport, __u16 dport)
59674 +{
59675 + struct conn_table_entry *match;
59676 + unsigned int index;
59677 +
59678 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59679 +
59680 + match = gr_conn_table[index];
59681 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59682 + match = match->next;
59683 +
59684 + if (match)
59685 + return match->sig;
59686 + else
59687 + return NULL;
59688 +}
59689 +
59690 +#endif
59691 +
59692 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59693 +{
59694 +#ifdef CONFIG_GRKERNSEC
59695 + struct signal_struct *sig = task->signal;
59696 + struct conn_table_entry *newent;
59697 +
59698 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59699 + if (newent == NULL)
59700 + return;
59701 + /* no bh lock needed since we are called with bh disabled */
59702 + spin_lock(&gr_conn_table_lock);
59703 + gr_del_task_from_ip_table_nolock(sig);
59704 + sig->gr_saddr = inet->inet_rcv_saddr;
59705 + sig->gr_daddr = inet->inet_daddr;
59706 + sig->gr_sport = inet->inet_sport;
59707 + sig->gr_dport = inet->inet_dport;
59708 + gr_add_to_task_ip_table_nolock(sig, newent);
59709 + spin_unlock(&gr_conn_table_lock);
59710 +#endif
59711 + return;
59712 +}
59713 +
59714 +void gr_del_task_from_ip_table(struct task_struct *task)
59715 +{
59716 +#ifdef CONFIG_GRKERNSEC
59717 + spin_lock_bh(&gr_conn_table_lock);
59718 + gr_del_task_from_ip_table_nolock(task->signal);
59719 + spin_unlock_bh(&gr_conn_table_lock);
59720 +#endif
59721 + return;
59722 +}
59723 +
59724 +void
59725 +gr_attach_curr_ip(const struct sock *sk)
59726 +{
59727 +#ifdef CONFIG_GRKERNSEC
59728 + struct signal_struct *p, *set;
59729 + const struct inet_sock *inet = inet_sk(sk);
59730 +
59731 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59732 + return;
59733 +
59734 + set = current->signal;
59735 +
59736 + spin_lock_bh(&gr_conn_table_lock);
59737 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59738 + inet->inet_dport, inet->inet_sport);
59739 + if (unlikely(p != NULL)) {
59740 + set->curr_ip = p->curr_ip;
59741 + set->used_accept = 1;
59742 + gr_del_task_from_ip_table_nolock(p);
59743 + spin_unlock_bh(&gr_conn_table_lock);
59744 + return;
59745 + }
59746 + spin_unlock_bh(&gr_conn_table_lock);
59747 +
59748 + set->curr_ip = inet->inet_daddr;
59749 + set->used_accept = 1;
59750 +#endif
59751 + return;
59752 +}
59753 +
59754 +int
59755 +gr_handle_sock_all(const int family, const int type, const int protocol)
59756 +{
59757 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59758 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59759 + (family != AF_UNIX)) {
59760 + if (family == AF_INET)
59761 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59762 + else
59763 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59764 + return -EACCES;
59765 + }
59766 +#endif
59767 + return 0;
59768 +}
59769 +
59770 +int
59771 +gr_handle_sock_server(const struct sockaddr *sck)
59772 +{
59773 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59774 + if (grsec_enable_socket_server &&
59775 + in_group_p(grsec_socket_server_gid) &&
59776 + sck && (sck->sa_family != AF_UNIX) &&
59777 + (sck->sa_family != AF_LOCAL)) {
59778 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59779 + return -EACCES;
59780 + }
59781 +#endif
59782 + return 0;
59783 +}
59784 +
59785 +int
59786 +gr_handle_sock_server_other(const struct sock *sck)
59787 +{
59788 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59789 + if (grsec_enable_socket_server &&
59790 + in_group_p(grsec_socket_server_gid) &&
59791 + sck && (sck->sk_family != AF_UNIX) &&
59792 + (sck->sk_family != AF_LOCAL)) {
59793 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59794 + return -EACCES;
59795 + }
59796 +#endif
59797 + return 0;
59798 +}
59799 +
59800 +int
59801 +gr_handle_sock_client(const struct sockaddr *sck)
59802 +{
59803 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59804 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59805 + sck && (sck->sa_family != AF_UNIX) &&
59806 + (sck->sa_family != AF_LOCAL)) {
59807 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59808 + return -EACCES;
59809 + }
59810 +#endif
59811 + return 0;
59812 +}
59813 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59814 new file mode 100644
59815 index 0000000..f55ef0f
59816 --- /dev/null
59817 +++ b/grsecurity/grsec_sysctl.c
59818 @@ -0,0 +1,469 @@
59819 +#include <linux/kernel.h>
59820 +#include <linux/sched.h>
59821 +#include <linux/sysctl.h>
59822 +#include <linux/grsecurity.h>
59823 +#include <linux/grinternal.h>
59824 +
59825 +int
59826 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59827 +{
59828 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59829 + if (dirname == NULL || name == NULL)
59830 + return 0;
59831 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59832 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59833 + return -EACCES;
59834 + }
59835 +#endif
59836 + return 0;
59837 +}
59838 +
59839 +#ifdef CONFIG_GRKERNSEC_ROFS
59840 +static int __maybe_unused one = 1;
59841 +#endif
59842 +
59843 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59844 +struct ctl_table grsecurity_table[] = {
59845 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59846 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59847 +#ifdef CONFIG_GRKERNSEC_IO
59848 + {
59849 + .procname = "disable_priv_io",
59850 + .data = &grsec_disable_privio,
59851 + .maxlen = sizeof(int),
59852 + .mode = 0600,
59853 + .proc_handler = &proc_dointvec,
59854 + },
59855 +#endif
59856 +#endif
59857 +#ifdef CONFIG_GRKERNSEC_LINK
59858 + {
59859 + .procname = "linking_restrictions",
59860 + .data = &grsec_enable_link,
59861 + .maxlen = sizeof(int),
59862 + .mode = 0600,
59863 + .proc_handler = &proc_dointvec,
59864 + },
59865 +#endif
59866 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59867 + {
59868 + .procname = "enforce_symlinksifowner",
59869 + .data = &grsec_enable_symlinkown,
59870 + .maxlen = sizeof(int),
59871 + .mode = 0600,
59872 + .proc_handler = &proc_dointvec,
59873 + },
59874 + {
59875 + .procname = "symlinkown_gid",
59876 + .data = &grsec_symlinkown_gid,
59877 + .maxlen = sizeof(int),
59878 + .mode = 0600,
59879 + .proc_handler = &proc_dointvec,
59880 + },
59881 +#endif
59882 +#ifdef CONFIG_GRKERNSEC_BRUTE
59883 + {
59884 + .procname = "deter_bruteforce",
59885 + .data = &grsec_enable_brute,
59886 + .maxlen = sizeof(int),
59887 + .mode = 0600,
59888 + .proc_handler = &proc_dointvec,
59889 + },
59890 +#endif
59891 +#ifdef CONFIG_GRKERNSEC_FIFO
59892 + {
59893 + .procname = "fifo_restrictions",
59894 + .data = &grsec_enable_fifo,
59895 + .maxlen = sizeof(int),
59896 + .mode = 0600,
59897 + .proc_handler = &proc_dointvec,
59898 + },
59899 +#endif
59900 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59901 + {
59902 + .procname = "ptrace_readexec",
59903 + .data = &grsec_enable_ptrace_readexec,
59904 + .maxlen = sizeof(int),
59905 + .mode = 0600,
59906 + .proc_handler = &proc_dointvec,
59907 + },
59908 +#endif
59909 +#ifdef CONFIG_GRKERNSEC_SETXID
59910 + {
59911 + .procname = "consistent_setxid",
59912 + .data = &grsec_enable_setxid,
59913 + .maxlen = sizeof(int),
59914 + .mode = 0600,
59915 + .proc_handler = &proc_dointvec,
59916 + },
59917 +#endif
59918 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59919 + {
59920 + .procname = "ip_blackhole",
59921 + .data = &grsec_enable_blackhole,
59922 + .maxlen = sizeof(int),
59923 + .mode = 0600,
59924 + .proc_handler = &proc_dointvec,
59925 + },
59926 + {
59927 + .procname = "lastack_retries",
59928 + .data = &grsec_lastack_retries,
59929 + .maxlen = sizeof(int),
59930 + .mode = 0600,
59931 + .proc_handler = &proc_dointvec,
59932 + },
59933 +#endif
59934 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59935 + {
59936 + .procname = "exec_logging",
59937 + .data = &grsec_enable_execlog,
59938 + .maxlen = sizeof(int),
59939 + .mode = 0600,
59940 + .proc_handler = &proc_dointvec,
59941 + },
59942 +#endif
59943 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59944 + {
59945 + .procname = "rwxmap_logging",
59946 + .data = &grsec_enable_log_rwxmaps,
59947 + .maxlen = sizeof(int),
59948 + .mode = 0600,
59949 + .proc_handler = &proc_dointvec,
59950 + },
59951 +#endif
59952 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59953 + {
59954 + .procname = "signal_logging",
59955 + .data = &grsec_enable_signal,
59956 + .maxlen = sizeof(int),
59957 + .mode = 0600,
59958 + .proc_handler = &proc_dointvec,
59959 + },
59960 +#endif
59961 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59962 + {
59963 + .procname = "forkfail_logging",
59964 + .data = &grsec_enable_forkfail,
59965 + .maxlen = sizeof(int),
59966 + .mode = 0600,
59967 + .proc_handler = &proc_dointvec,
59968 + },
59969 +#endif
59970 +#ifdef CONFIG_GRKERNSEC_TIME
59971 + {
59972 + .procname = "timechange_logging",
59973 + .data = &grsec_enable_time,
59974 + .maxlen = sizeof(int),
59975 + .mode = 0600,
59976 + .proc_handler = &proc_dointvec,
59977 + },
59978 +#endif
59979 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59980 + {
59981 + .procname = "chroot_deny_shmat",
59982 + .data = &grsec_enable_chroot_shmat,
59983 + .maxlen = sizeof(int),
59984 + .mode = 0600,
59985 + .proc_handler = &proc_dointvec,
59986 + },
59987 +#endif
59988 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59989 + {
59990 + .procname = "chroot_deny_unix",
59991 + .data = &grsec_enable_chroot_unix,
59992 + .maxlen = sizeof(int),
59993 + .mode = 0600,
59994 + .proc_handler = &proc_dointvec,
59995 + },
59996 +#endif
59997 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59998 + {
59999 + .procname = "chroot_deny_mount",
60000 + .data = &grsec_enable_chroot_mount,
60001 + .maxlen = sizeof(int),
60002 + .mode = 0600,
60003 + .proc_handler = &proc_dointvec,
60004 + },
60005 +#endif
60006 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60007 + {
60008 + .procname = "chroot_deny_fchdir",
60009 + .data = &grsec_enable_chroot_fchdir,
60010 + .maxlen = sizeof(int),
60011 + .mode = 0600,
60012 + .proc_handler = &proc_dointvec,
60013 + },
60014 +#endif
60015 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60016 + {
60017 + .procname = "chroot_deny_chroot",
60018 + .data = &grsec_enable_chroot_double,
60019 + .maxlen = sizeof(int),
60020 + .mode = 0600,
60021 + .proc_handler = &proc_dointvec,
60022 + },
60023 +#endif
60024 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60025 + {
60026 + .procname = "chroot_deny_pivot",
60027 + .data = &grsec_enable_chroot_pivot,
60028 + .maxlen = sizeof(int),
60029 + .mode = 0600,
60030 + .proc_handler = &proc_dointvec,
60031 + },
60032 +#endif
60033 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60034 + {
60035 + .procname = "chroot_enforce_chdir",
60036 + .data = &grsec_enable_chroot_chdir,
60037 + .maxlen = sizeof(int),
60038 + .mode = 0600,
60039 + .proc_handler = &proc_dointvec,
60040 + },
60041 +#endif
60042 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60043 + {
60044 + .procname = "chroot_deny_chmod",
60045 + .data = &grsec_enable_chroot_chmod,
60046 + .maxlen = sizeof(int),
60047 + .mode = 0600,
60048 + .proc_handler = &proc_dointvec,
60049 + },
60050 +#endif
60051 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60052 + {
60053 + .procname = "chroot_deny_mknod",
60054 + .data = &grsec_enable_chroot_mknod,
60055 + .maxlen = sizeof(int),
60056 + .mode = 0600,
60057 + .proc_handler = &proc_dointvec,
60058 + },
60059 +#endif
60060 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60061 + {
60062 + .procname = "chroot_restrict_nice",
60063 + .data = &grsec_enable_chroot_nice,
60064 + .maxlen = sizeof(int),
60065 + .mode = 0600,
60066 + .proc_handler = &proc_dointvec,
60067 + },
60068 +#endif
60069 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60070 + {
60071 + .procname = "chroot_execlog",
60072 + .data = &grsec_enable_chroot_execlog,
60073 + .maxlen = sizeof(int),
60074 + .mode = 0600,
60075 + .proc_handler = &proc_dointvec,
60076 + },
60077 +#endif
60078 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60079 + {
60080 + .procname = "chroot_caps",
60081 + .data = &grsec_enable_chroot_caps,
60082 + .maxlen = sizeof(int),
60083 + .mode = 0600,
60084 + .proc_handler = &proc_dointvec,
60085 + },
60086 +#endif
60087 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60088 + {
60089 + .procname = "chroot_deny_sysctl",
60090 + .data = &grsec_enable_chroot_sysctl,
60091 + .maxlen = sizeof(int),
60092 + .mode = 0600,
60093 + .proc_handler = &proc_dointvec,
60094 + },
60095 +#endif
60096 +#ifdef CONFIG_GRKERNSEC_TPE
60097 + {
60098 + .procname = "tpe",
60099 + .data = &grsec_enable_tpe,
60100 + .maxlen = sizeof(int),
60101 + .mode = 0600,
60102 + .proc_handler = &proc_dointvec,
60103 + },
60104 + {
60105 + .procname = "tpe_gid",
60106 + .data = &grsec_tpe_gid,
60107 + .maxlen = sizeof(int),
60108 + .mode = 0600,
60109 + .proc_handler = &proc_dointvec,
60110 + },
60111 +#endif
60112 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60113 + {
60114 + .procname = "tpe_invert",
60115 + .data = &grsec_enable_tpe_invert,
60116 + .maxlen = sizeof(int),
60117 + .mode = 0600,
60118 + .proc_handler = &proc_dointvec,
60119 + },
60120 +#endif
60121 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60122 + {
60123 + .procname = "tpe_restrict_all",
60124 + .data = &grsec_enable_tpe_all,
60125 + .maxlen = sizeof(int),
60126 + .mode = 0600,
60127 + .proc_handler = &proc_dointvec,
60128 + },
60129 +#endif
60130 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60131 + {
60132 + .procname = "socket_all",
60133 + .data = &grsec_enable_socket_all,
60134 + .maxlen = sizeof(int),
60135 + .mode = 0600,
60136 + .proc_handler = &proc_dointvec,
60137 + },
60138 + {
60139 + .procname = "socket_all_gid",
60140 + .data = &grsec_socket_all_gid,
60141 + .maxlen = sizeof(int),
60142 + .mode = 0600,
60143 + .proc_handler = &proc_dointvec,
60144 + },
60145 +#endif
60146 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60147 + {
60148 + .procname = "socket_client",
60149 + .data = &grsec_enable_socket_client,
60150 + .maxlen = sizeof(int),
60151 + .mode = 0600,
60152 + .proc_handler = &proc_dointvec,
60153 + },
60154 + {
60155 + .procname = "socket_client_gid",
60156 + .data = &grsec_socket_client_gid,
60157 + .maxlen = sizeof(int),
60158 + .mode = 0600,
60159 + .proc_handler = &proc_dointvec,
60160 + },
60161 +#endif
60162 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60163 + {
60164 + .procname = "socket_server",
60165 + .data = &grsec_enable_socket_server,
60166 + .maxlen = sizeof(int),
60167 + .mode = 0600,
60168 + .proc_handler = &proc_dointvec,
60169 + },
60170 + {
60171 + .procname = "socket_server_gid",
60172 + .data = &grsec_socket_server_gid,
60173 + .maxlen = sizeof(int),
60174 + .mode = 0600,
60175 + .proc_handler = &proc_dointvec,
60176 + },
60177 +#endif
60178 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60179 + {
60180 + .procname = "audit_group",
60181 + .data = &grsec_enable_group,
60182 + .maxlen = sizeof(int),
60183 + .mode = 0600,
60184 + .proc_handler = &proc_dointvec,
60185 + },
60186 + {
60187 + .procname = "audit_gid",
60188 + .data = &grsec_audit_gid,
60189 + .maxlen = sizeof(int),
60190 + .mode = 0600,
60191 + .proc_handler = &proc_dointvec,
60192 + },
60193 +#endif
60194 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60195 + {
60196 + .procname = "audit_chdir",
60197 + .data = &grsec_enable_chdir,
60198 + .maxlen = sizeof(int),
60199 + .mode = 0600,
60200 + .proc_handler = &proc_dointvec,
60201 + },
60202 +#endif
60203 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60204 + {
60205 + .procname = "audit_mount",
60206 + .data = &grsec_enable_mount,
60207 + .maxlen = sizeof(int),
60208 + .mode = 0600,
60209 + .proc_handler = &proc_dointvec,
60210 + },
60211 +#endif
60212 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60213 + {
60214 + .procname = "audit_textrel",
60215 + .data = &grsec_enable_audit_textrel,
60216 + .maxlen = sizeof(int),
60217 + .mode = 0600,
60218 + .proc_handler = &proc_dointvec,
60219 + },
60220 +#endif
60221 +#ifdef CONFIG_GRKERNSEC_DMESG
60222 + {
60223 + .procname = "dmesg",
60224 + .data = &grsec_enable_dmesg,
60225 + .maxlen = sizeof(int),
60226 + .mode = 0600,
60227 + .proc_handler = &proc_dointvec,
60228 + },
60229 +#endif
60230 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60231 + {
60232 + .procname = "chroot_findtask",
60233 + .data = &grsec_enable_chroot_findtask,
60234 + .maxlen = sizeof(int),
60235 + .mode = 0600,
60236 + .proc_handler = &proc_dointvec,
60237 + },
60238 +#endif
60239 +#ifdef CONFIG_GRKERNSEC_RESLOG
60240 + {
60241 + .procname = "resource_logging",
60242 + .data = &grsec_resource_logging,
60243 + .maxlen = sizeof(int),
60244 + .mode = 0600,
60245 + .proc_handler = &proc_dointvec,
60246 + },
60247 +#endif
60248 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60249 + {
60250 + .procname = "audit_ptrace",
60251 + .data = &grsec_enable_audit_ptrace,
60252 + .maxlen = sizeof(int),
60253 + .mode = 0600,
60254 + .proc_handler = &proc_dointvec,
60255 + },
60256 +#endif
60257 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60258 + {
60259 + .procname = "harden_ptrace",
60260 + .data = &grsec_enable_harden_ptrace,
60261 + .maxlen = sizeof(int),
60262 + .mode = 0600,
60263 + .proc_handler = &proc_dointvec,
60264 + },
60265 +#endif
60266 + {
60267 + .procname = "grsec_lock",
60268 + .data = &grsec_lock,
60269 + .maxlen = sizeof(int),
60270 + .mode = 0600,
60271 + .proc_handler = &proc_dointvec,
60272 + },
60273 +#endif
60274 +#ifdef CONFIG_GRKERNSEC_ROFS
60275 + {
60276 + .procname = "romount_protect",
60277 + .data = &grsec_enable_rofs,
60278 + .maxlen = sizeof(int),
60279 + .mode = 0600,
60280 + .proc_handler = &proc_dointvec_minmax,
60281 + .extra1 = &one,
60282 + .extra2 = &one,
60283 + },
60284 +#endif
60285 + { }
60286 +};
60287 +#endif
60288 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60289 new file mode 100644
60290 index 0000000..0dc13c3
60291 --- /dev/null
60292 +++ b/grsecurity/grsec_time.c
60293 @@ -0,0 +1,16 @@
60294 +#include <linux/kernel.h>
60295 +#include <linux/sched.h>
60296 +#include <linux/grinternal.h>
60297 +#include <linux/module.h>
60298 +
60299 +void
60300 +gr_log_timechange(void)
60301 +{
60302 +#ifdef CONFIG_GRKERNSEC_TIME
60303 + if (grsec_enable_time)
60304 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60305 +#endif
60306 + return;
60307 +}
60308 +
60309 +EXPORT_SYMBOL(gr_log_timechange);
60310 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60311 new file mode 100644
60312 index 0000000..07e0dc0
60313 --- /dev/null
60314 +++ b/grsecurity/grsec_tpe.c
60315 @@ -0,0 +1,73 @@
60316 +#include <linux/kernel.h>
60317 +#include <linux/sched.h>
60318 +#include <linux/file.h>
60319 +#include <linux/fs.h>
60320 +#include <linux/grinternal.h>
60321 +
60322 +extern int gr_acl_tpe_check(void);
60323 +
60324 +int
60325 +gr_tpe_allow(const struct file *file)
60326 +{
60327 +#ifdef CONFIG_GRKERNSEC
60328 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60329 + const struct cred *cred = current_cred();
60330 + char *msg = NULL;
60331 + char *msg2 = NULL;
60332 +
60333 + // never restrict root
60334 + if (!cred->uid)
60335 + return 1;
60336 +
60337 + if (grsec_enable_tpe) {
60338 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60339 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60340 + msg = "not being in trusted group";
60341 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60342 + msg = "being in untrusted group";
60343 +#else
60344 + if (in_group_p(grsec_tpe_gid))
60345 + msg = "being in untrusted group";
60346 +#endif
60347 + }
60348 + if (!msg && gr_acl_tpe_check())
60349 + msg = "being in untrusted role";
60350 +
60351 + // not in any affected group/role
60352 + if (!msg)
60353 + goto next_check;
60354 +
60355 + if (inode->i_uid)
60356 + msg2 = "file in non-root-owned directory";
60357 + else if (inode->i_mode & S_IWOTH)
60358 + msg2 = "file in world-writable directory";
60359 + else if (inode->i_mode & S_IWGRP)
60360 + msg2 = "file in group-writable directory";
60361 +
60362 + if (msg && msg2) {
60363 + char fullmsg[70] = {0};
60364 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60365 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60366 + return 0;
60367 + }
60368 + msg = NULL;
60369 +next_check:
60370 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60371 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60372 + return 1;
60373 +
60374 + if (inode->i_uid && (inode->i_uid != cred->uid))
60375 + msg = "directory not owned by user";
60376 + else if (inode->i_mode & S_IWOTH)
60377 + msg = "file in world-writable directory";
60378 + else if (inode->i_mode & S_IWGRP)
60379 + msg = "file in group-writable directory";
60380 +
60381 + if (msg) {
60382 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60383 + return 0;
60384 + }
60385 +#endif
60386 +#endif
60387 + return 1;
60388 +}
60389 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60390 new file mode 100644
60391 index 0000000..9f7b1ac
60392 --- /dev/null
60393 +++ b/grsecurity/grsum.c
60394 @@ -0,0 +1,61 @@
60395 +#include <linux/err.h>
60396 +#include <linux/kernel.h>
60397 +#include <linux/sched.h>
60398 +#include <linux/mm.h>
60399 +#include <linux/scatterlist.h>
60400 +#include <linux/crypto.h>
60401 +#include <linux/gracl.h>
60402 +
60403 +
60404 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60405 +#error "crypto and sha256 must be built into the kernel"
60406 +#endif
60407 +
60408 +int
60409 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60410 +{
60411 + char *p;
60412 + struct crypto_hash *tfm;
60413 + struct hash_desc desc;
60414 + struct scatterlist sg;
60415 + unsigned char temp_sum[GR_SHA_LEN];
60416 + volatile int retval = 0;
60417 + volatile int dummy = 0;
60418 + unsigned int i;
60419 +
60420 + sg_init_table(&sg, 1);
60421 +
60422 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60423 + if (IS_ERR(tfm)) {
60424 + /* should never happen, since sha256 should be built in */
60425 + return 1;
60426 + }
60427 +
60428 + desc.tfm = tfm;
60429 + desc.flags = 0;
60430 +
60431 + crypto_hash_init(&desc);
60432 +
60433 + p = salt;
60434 + sg_set_buf(&sg, p, GR_SALT_LEN);
60435 + crypto_hash_update(&desc, &sg, sg.length);
60436 +
60437 + p = entry->pw;
60438 + sg_set_buf(&sg, p, strlen(p));
60439 +
60440 + crypto_hash_update(&desc, &sg, sg.length);
60441 +
60442 + crypto_hash_final(&desc, temp_sum);
60443 +
60444 + memset(entry->pw, 0, GR_PW_LEN);
60445 +
60446 + for (i = 0; i < GR_SHA_LEN; i++)
60447 + if (sum[i] != temp_sum[i])
60448 + retval = 1;
60449 + else
60450 + dummy = 1; // waste a cycle
60451 +
60452 + crypto_free_hash(tfm);
60453 +
60454 + return retval;
60455 +}
60456 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60457 index 0daa0fb..f548aa4 100644
60458 --- a/include/acpi/acpi_bus.h
60459 +++ b/include/acpi/acpi_bus.h
60460 @@ -107,7 +107,7 @@ struct acpi_device_ops {
60461 acpi_op_bind bind;
60462 acpi_op_unbind unbind;
60463 acpi_op_notify notify;
60464 -};
60465 +} __no_const;
60466
60467 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60468
60469 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60470 index 77ff547..181834f 100644
60471 --- a/include/asm-generic/4level-fixup.h
60472 +++ b/include/asm-generic/4level-fixup.h
60473 @@ -13,8 +13,10 @@
60474 #define pmd_alloc(mm, pud, address) \
60475 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60476 NULL: pmd_offset(pud, address))
60477 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60478
60479 #define pud_alloc(mm, pgd, address) (pgd)
60480 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60481 #define pud_offset(pgd, start) (pgd)
60482 #define pud_none(pud) 0
60483 #define pud_bad(pud) 0
60484 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60485 index b7babf0..04ad282 100644
60486 --- a/include/asm-generic/atomic-long.h
60487 +++ b/include/asm-generic/atomic-long.h
60488 @@ -22,6 +22,12 @@
60489
60490 typedef atomic64_t atomic_long_t;
60491
60492 +#ifdef CONFIG_PAX_REFCOUNT
60493 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60494 +#else
60495 +typedef atomic64_t atomic_long_unchecked_t;
60496 +#endif
60497 +
60498 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60499
60500 static inline long atomic_long_read(atomic_long_t *l)
60501 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60502 return (long)atomic64_read(v);
60503 }
60504
60505 +#ifdef CONFIG_PAX_REFCOUNT
60506 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60507 +{
60508 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60509 +
60510 + return (long)atomic64_read_unchecked(v);
60511 +}
60512 +#endif
60513 +
60514 static inline void atomic_long_set(atomic_long_t *l, long i)
60515 {
60516 atomic64_t *v = (atomic64_t *)l;
60517 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60518 atomic64_set(v, i);
60519 }
60520
60521 +#ifdef CONFIG_PAX_REFCOUNT
60522 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60523 +{
60524 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60525 +
60526 + atomic64_set_unchecked(v, i);
60527 +}
60528 +#endif
60529 +
60530 static inline void atomic_long_inc(atomic_long_t *l)
60531 {
60532 atomic64_t *v = (atomic64_t *)l;
60533 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60534 atomic64_inc(v);
60535 }
60536
60537 +#ifdef CONFIG_PAX_REFCOUNT
60538 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60539 +{
60540 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60541 +
60542 + atomic64_inc_unchecked(v);
60543 +}
60544 +#endif
60545 +
60546 static inline void atomic_long_dec(atomic_long_t *l)
60547 {
60548 atomic64_t *v = (atomic64_t *)l;
60549 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60550 atomic64_dec(v);
60551 }
60552
60553 +#ifdef CONFIG_PAX_REFCOUNT
60554 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60555 +{
60556 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60557 +
60558 + atomic64_dec_unchecked(v);
60559 +}
60560 +#endif
60561 +
60562 static inline void atomic_long_add(long i, atomic_long_t *l)
60563 {
60564 atomic64_t *v = (atomic64_t *)l;
60565 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60566 atomic64_add(i, v);
60567 }
60568
60569 +#ifdef CONFIG_PAX_REFCOUNT
60570 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60571 +{
60572 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60573 +
60574 + atomic64_add_unchecked(i, v);
60575 +}
60576 +#endif
60577 +
60578 static inline void atomic_long_sub(long i, atomic_long_t *l)
60579 {
60580 atomic64_t *v = (atomic64_t *)l;
60581 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60582 atomic64_sub(i, v);
60583 }
60584
60585 +#ifdef CONFIG_PAX_REFCOUNT
60586 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60587 +{
60588 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60589 +
60590 + atomic64_sub_unchecked(i, v);
60591 +}
60592 +#endif
60593 +
60594 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60595 {
60596 atomic64_t *v = (atomic64_t *)l;
60597 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
60598 return (long)atomic64_add_return(i, v);
60599 }
60600
60601 +#ifdef CONFIG_PAX_REFCOUNT
60602 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
60603 +{
60604 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60605 +
60606 + return (long)atomic64_add_return_unchecked(i, v);
60607 +}
60608 +#endif
60609 +
60610 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
60611 {
60612 atomic64_t *v = (atomic64_t *)l;
60613 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60614 return (long)atomic64_inc_return(v);
60615 }
60616
60617 +#ifdef CONFIG_PAX_REFCOUNT
60618 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60619 +{
60620 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60621 +
60622 + return (long)atomic64_inc_return_unchecked(v);
60623 +}
60624 +#endif
60625 +
60626 static inline long atomic_long_dec_return(atomic_long_t *l)
60627 {
60628 atomic64_t *v = (atomic64_t *)l;
60629 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60630
60631 typedef atomic_t atomic_long_t;
60632
60633 +#ifdef CONFIG_PAX_REFCOUNT
60634 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60635 +#else
60636 +typedef atomic_t atomic_long_unchecked_t;
60637 +#endif
60638 +
60639 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60640 static inline long atomic_long_read(atomic_long_t *l)
60641 {
60642 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60643 return (long)atomic_read(v);
60644 }
60645
60646 +#ifdef CONFIG_PAX_REFCOUNT
60647 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60648 +{
60649 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60650 +
60651 + return (long)atomic_read_unchecked(v);
60652 +}
60653 +#endif
60654 +
60655 static inline void atomic_long_set(atomic_long_t *l, long i)
60656 {
60657 atomic_t *v = (atomic_t *)l;
60658 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60659 atomic_set(v, i);
60660 }
60661
60662 +#ifdef CONFIG_PAX_REFCOUNT
60663 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60664 +{
60665 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60666 +
60667 + atomic_set_unchecked(v, i);
60668 +}
60669 +#endif
60670 +
60671 static inline void atomic_long_inc(atomic_long_t *l)
60672 {
60673 atomic_t *v = (atomic_t *)l;
60674 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60675 atomic_inc(v);
60676 }
60677
60678 +#ifdef CONFIG_PAX_REFCOUNT
60679 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60680 +{
60681 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60682 +
60683 + atomic_inc_unchecked(v);
60684 +}
60685 +#endif
60686 +
60687 static inline void atomic_long_dec(atomic_long_t *l)
60688 {
60689 atomic_t *v = (atomic_t *)l;
60690 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60691 atomic_dec(v);
60692 }
60693
60694 +#ifdef CONFIG_PAX_REFCOUNT
60695 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60696 +{
60697 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60698 +
60699 + atomic_dec_unchecked(v);
60700 +}
60701 +#endif
60702 +
60703 static inline void atomic_long_add(long i, atomic_long_t *l)
60704 {
60705 atomic_t *v = (atomic_t *)l;
60706 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60707 atomic_add(i, v);
60708 }
60709
60710 +#ifdef CONFIG_PAX_REFCOUNT
60711 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60712 +{
60713 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60714 +
60715 + atomic_add_unchecked(i, v);
60716 +}
60717 +#endif
60718 +
60719 static inline void atomic_long_sub(long i, atomic_long_t *l)
60720 {
60721 atomic_t *v = (atomic_t *)l;
60722 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60723 atomic_sub(i, v);
60724 }
60725
60726 +#ifdef CONFIG_PAX_REFCOUNT
60727 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60728 +{
60729 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60730 +
60731 + atomic_sub_unchecked(i, v);
60732 +}
60733 +#endif
60734 +
60735 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60736 {
60737 atomic_t *v = (atomic_t *)l;
60738 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
60739 return (long)atomic_add_return(i, v);
60740 }
60741
60742 +#ifdef CONFIG_PAX_REFCOUNT
60743 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
60744 +{
60745 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60746 +
60747 + return (long)atomic_add_return_unchecked(i, v);
60748 +}
60749 +
60750 +#endif
60751 +
60752 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
60753 {
60754 atomic_t *v = (atomic_t *)l;
60755 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60756 return (long)atomic_inc_return(v);
60757 }
60758
60759 +#ifdef CONFIG_PAX_REFCOUNT
60760 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60761 +{
60762 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60763 +
60764 + return (long)atomic_inc_return_unchecked(v);
60765 +}
60766 +#endif
60767 +
60768 static inline long atomic_long_dec_return(atomic_long_t *l)
60769 {
60770 atomic_t *v = (atomic_t *)l;
60771 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60772
60773 #endif /* BITS_PER_LONG == 64 */
60774
60775 +#ifdef CONFIG_PAX_REFCOUNT
60776 +static inline void pax_refcount_needs_these_functions(void)
60777 +{
60778 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60779 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60780 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60781 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60782 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60783 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60784 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60785 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60786 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60787 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60788 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60789 +#ifdef CONFIG_X86
60790 + atomic_clear_mask_unchecked(0, NULL);
60791 + atomic_set_mask_unchecked(0, NULL);
60792 +#endif
60793 +
60794 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60795 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60796 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60797 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60798 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60799 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
60800 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60801 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60802 +}
60803 +#else
60804 +#define atomic_read_unchecked(v) atomic_read(v)
60805 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60806 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60807 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60808 +#define atomic_inc_unchecked(v) atomic_inc(v)
60809 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60810 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60811 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60812 +#define atomic_dec_unchecked(v) atomic_dec(v)
60813 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60814 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60815 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60816 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60817 +
60818 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60819 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60820 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60821 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60822 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60823 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
60824 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60825 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60826 +#endif
60827 +
60828 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60829 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60830 index 1ced641..c896ee8 100644
60831 --- a/include/asm-generic/atomic.h
60832 +++ b/include/asm-generic/atomic.h
60833 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60834 * Atomically clears the bits set in @mask from @v
60835 */
60836 #ifndef atomic_clear_mask
60837 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60838 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60839 {
60840 unsigned long flags;
60841
60842 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60843 index b18ce4f..2ee2843 100644
60844 --- a/include/asm-generic/atomic64.h
60845 +++ b/include/asm-generic/atomic64.h
60846 @@ -16,6 +16,8 @@ typedef struct {
60847 long long counter;
60848 } atomic64_t;
60849
60850 +typedef atomic64_t atomic64_unchecked_t;
60851 +
60852 #define ATOMIC64_INIT(i) { (i) }
60853
60854 extern long long atomic64_read(const atomic64_t *v);
60855 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60856 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60857 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60858
60859 +#define atomic64_read_unchecked(v) atomic64_read(v)
60860 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60861 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60862 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60863 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60864 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60865 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60866 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60867 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60868 +
60869 #endif /* _ASM_GENERIC_ATOMIC64_H */
60870 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60871 index 1bfcfe5..e04c5c9 100644
60872 --- a/include/asm-generic/cache.h
60873 +++ b/include/asm-generic/cache.h
60874 @@ -6,7 +6,7 @@
60875 * cache lines need to provide their own cache.h.
60876 */
60877
60878 -#define L1_CACHE_SHIFT 5
60879 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60880 +#define L1_CACHE_SHIFT 5UL
60881 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60882
60883 #endif /* __ASM_GENERIC_CACHE_H */
60884 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60885 index 0d68a1e..b74a761 100644
60886 --- a/include/asm-generic/emergency-restart.h
60887 +++ b/include/asm-generic/emergency-restart.h
60888 @@ -1,7 +1,7 @@
60889 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60890 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60891
60892 -static inline void machine_emergency_restart(void)
60893 +static inline __noreturn void machine_emergency_restart(void)
60894 {
60895 machine_restart(NULL);
60896 }
60897 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60898 index 90f99c7..00ce236 100644
60899 --- a/include/asm-generic/kmap_types.h
60900 +++ b/include/asm-generic/kmap_types.h
60901 @@ -2,9 +2,9 @@
60902 #define _ASM_GENERIC_KMAP_TYPES_H
60903
60904 #ifdef __WITH_KM_FENCE
60905 -# define KM_TYPE_NR 41
60906 +# define KM_TYPE_NR 42
60907 #else
60908 -# define KM_TYPE_NR 20
60909 +# define KM_TYPE_NR 21
60910 #endif
60911
60912 #endif
60913 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60914 index 9ceb03b..62b0b8f 100644
60915 --- a/include/asm-generic/local.h
60916 +++ b/include/asm-generic/local.h
60917 @@ -23,24 +23,37 @@ typedef struct
60918 atomic_long_t a;
60919 } local_t;
60920
60921 +typedef struct {
60922 + atomic_long_unchecked_t a;
60923 +} local_unchecked_t;
60924 +
60925 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
60926
60927 #define local_read(l) atomic_long_read(&(l)->a)
60928 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
60929 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
60930 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
60931 #define local_inc(l) atomic_long_inc(&(l)->a)
60932 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
60933 #define local_dec(l) atomic_long_dec(&(l)->a)
60934 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
60935 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
60936 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
60937 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
60938 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
60939
60940 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
60941 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
60942 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
60943 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
60944 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60945 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
60946 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60947 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60948 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60949
60950 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60951 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60952 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60953 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
60954 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
60955 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60956 index 725612b..9cc513a 100644
60957 --- a/include/asm-generic/pgtable-nopmd.h
60958 +++ b/include/asm-generic/pgtable-nopmd.h
60959 @@ -1,14 +1,19 @@
60960 #ifndef _PGTABLE_NOPMD_H
60961 #define _PGTABLE_NOPMD_H
60962
60963 -#ifndef __ASSEMBLY__
60964 -
60965 #include <asm-generic/pgtable-nopud.h>
60966
60967 -struct mm_struct;
60968 -
60969 #define __PAGETABLE_PMD_FOLDED
60970
60971 +#define PMD_SHIFT PUD_SHIFT
60972 +#define PTRS_PER_PMD 1
60973 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60974 +#define PMD_MASK (~(PMD_SIZE-1))
60975 +
60976 +#ifndef __ASSEMBLY__
60977 +
60978 +struct mm_struct;
60979 +
60980 /*
60981 * Having the pmd type consist of a pud gets the size right, and allows
60982 * us to conceptually access the pud entry that this pmd is folded into
60983 @@ -16,11 +21,6 @@ struct mm_struct;
60984 */
60985 typedef struct { pud_t pud; } pmd_t;
60986
60987 -#define PMD_SHIFT PUD_SHIFT
60988 -#define PTRS_PER_PMD 1
60989 -#define PMD_SIZE (1UL << PMD_SHIFT)
60990 -#define PMD_MASK (~(PMD_SIZE-1))
60991 -
60992 /*
60993 * The "pud_xxx()" functions here are trivial for a folded two-level
60994 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60995 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60996 index 810431d..0ec4804f 100644
60997 --- a/include/asm-generic/pgtable-nopud.h
60998 +++ b/include/asm-generic/pgtable-nopud.h
60999 @@ -1,10 +1,15 @@
61000 #ifndef _PGTABLE_NOPUD_H
61001 #define _PGTABLE_NOPUD_H
61002
61003 -#ifndef __ASSEMBLY__
61004 -
61005 #define __PAGETABLE_PUD_FOLDED
61006
61007 +#define PUD_SHIFT PGDIR_SHIFT
61008 +#define PTRS_PER_PUD 1
61009 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61010 +#define PUD_MASK (~(PUD_SIZE-1))
61011 +
61012 +#ifndef __ASSEMBLY__
61013 +
61014 /*
61015 * Having the pud type consist of a pgd gets the size right, and allows
61016 * us to conceptually access the pgd entry that this pud is folded into
61017 @@ -12,11 +17,6 @@
61018 */
61019 typedef struct { pgd_t pgd; } pud_t;
61020
61021 -#define PUD_SHIFT PGDIR_SHIFT
61022 -#define PTRS_PER_PUD 1
61023 -#define PUD_SIZE (1UL << PUD_SHIFT)
61024 -#define PUD_MASK (~(PUD_SIZE-1))
61025 -
61026 /*
61027 * The "pgd_xxx()" functions here are trivial for a folded two-level
61028 * setup: the pud is never bad, and a pud always exists (as it's folded
61029 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61030 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61031
61032 #define pgd_populate(mm, pgd, pud) do { } while (0)
61033 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61034 /*
61035 * (puds are folded into pgds so this doesn't get actually called,
61036 * but the define is needed for a generic inline function.)
61037 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61038 index b36ce40..019426d 100644
61039 --- a/include/asm-generic/pgtable.h
61040 +++ b/include/asm-generic/pgtable.h
61041 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61042 #endif
61043 }
61044
61045 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61046 +static inline unsigned long pax_open_kernel(void) { return 0; }
61047 +#endif
61048 +
61049 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61050 +static inline unsigned long pax_close_kernel(void) { return 0; }
61051 +#endif
61052 +
61053 #endif /* CONFIG_MMU */
61054
61055 #endif /* !__ASSEMBLY__ */
61056 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61057 index d1ea7ce..b1ebf2a 100644
61058 --- a/include/asm-generic/vmlinux.lds.h
61059 +++ b/include/asm-generic/vmlinux.lds.h
61060 @@ -218,6 +218,7 @@
61061 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61062 VMLINUX_SYMBOL(__start_rodata) = .; \
61063 *(.rodata) *(.rodata.*) \
61064 + *(.data..read_only) \
61065 *(__vermagic) /* Kernel version magic */ \
61066 . = ALIGN(8); \
61067 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61068 @@ -725,17 +726,18 @@
61069 * section in the linker script will go there too. @phdr should have
61070 * a leading colon.
61071 *
61072 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61073 + * Note that this macros defines per_cpu_load as an absolute symbol.
61074 * If there is no need to put the percpu section at a predetermined
61075 * address, use PERCPU_SECTION.
61076 */
61077 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61078 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61079 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61080 + per_cpu_load = .; \
61081 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61082 - LOAD_OFFSET) { \
61083 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61084 PERCPU_INPUT(cacheline) \
61085 } phdr \
61086 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61087 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61088
61089 /**
61090 * PERCPU_SECTION - define output section for percpu area, simple version
61091 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61092 index 3fd8280..2b3c415 100644
61093 --- a/include/drm/drmP.h
61094 +++ b/include/drm/drmP.h
61095 @@ -72,6 +72,7 @@
61096 #include <linux/workqueue.h>
61097 #include <linux/poll.h>
61098 #include <asm/pgalloc.h>
61099 +#include <asm/local.h>
61100 #include <drm/drm.h>
61101 #include <drm/drm_sarea.h>
61102
61103 @@ -1068,7 +1069,7 @@ struct drm_device {
61104
61105 /** \name Usage Counters */
61106 /*@{ */
61107 - int open_count; /**< Outstanding files open */
61108 + local_t open_count; /**< Outstanding files open */
61109 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61110 atomic_t vma_count; /**< Outstanding vma areas open */
61111 int buf_use; /**< Buffers in use -- cannot alloc */
61112 @@ -1079,7 +1080,7 @@ struct drm_device {
61113 /*@{ */
61114 unsigned long counters;
61115 enum drm_stat_type types[15];
61116 - atomic_t counts[15];
61117 + atomic_unchecked_t counts[15];
61118 /*@} */
61119
61120 struct list_head filelist;
61121 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61122 index e01cc80..319855d 100644
61123 --- a/include/drm/drm_crtc_helper.h
61124 +++ b/include/drm/drm_crtc_helper.h
61125 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61126
61127 /* disable crtc when not in use - more explicit than dpms off */
61128 void (*disable)(struct drm_crtc *crtc);
61129 -};
61130 +} __no_const;
61131
61132 /**
61133 * drm_encoder_helper_funcs - helper operations for encoders
61134 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61135 struct drm_connector *connector);
61136 /* disable encoder when not in use - more explicit than dpms off */
61137 void (*disable)(struct drm_encoder *encoder);
61138 -};
61139 +} __no_const;
61140
61141 /**
61142 * drm_connector_helper_funcs - helper operations for connectors
61143 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61144 index d6d1da4..fdd1ac5 100644
61145 --- a/include/drm/ttm/ttm_memory.h
61146 +++ b/include/drm/ttm/ttm_memory.h
61147 @@ -48,7 +48,7 @@
61148
61149 struct ttm_mem_shrink {
61150 int (*do_shrink) (struct ttm_mem_shrink *);
61151 -};
61152 +} __no_const;
61153
61154 /**
61155 * struct ttm_mem_global - Global memory accounting structure.
61156 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61157 index 22ef21c..75904ba 100644
61158 --- a/include/linux/atmdev.h
61159 +++ b/include/linux/atmdev.h
61160 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
61161 #endif
61162
61163 struct k_atm_aal_stats {
61164 -#define __HANDLE_ITEM(i) atomic_t i
61165 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61166 __AAL_STAT_ITEMS
61167 #undef __HANDLE_ITEM
61168 };
61169 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61170 index cfcc6bf..9a7c73e 100644
61171 --- a/include/linux/binfmts.h
61172 +++ b/include/linux/binfmts.h
61173 @@ -75,6 +75,7 @@ struct linux_binfmt {
61174 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61175 int (*load_shlib)(struct file *);
61176 int (*core_dump)(struct coredump_params *cprm);
61177 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61178 unsigned long min_coredump; /* minimal dump size */
61179 };
61180
61181 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61182 index 1756001..ab117ec 100644
61183 --- a/include/linux/blkdev.h
61184 +++ b/include/linux/blkdev.h
61185 @@ -1478,7 +1478,7 @@ struct block_device_operations {
61186 /* this callback is with swap_lock and sometimes page table lock held */
61187 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61188 struct module *owner;
61189 -};
61190 +} __do_const;
61191
61192 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61193 unsigned long);
61194 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61195 index 7c2e030..b72475d 100644
61196 --- a/include/linux/blktrace_api.h
61197 +++ b/include/linux/blktrace_api.h
61198 @@ -23,7 +23,7 @@ struct blk_trace {
61199 struct dentry *dir;
61200 struct dentry *dropped_file;
61201 struct dentry *msg_file;
61202 - atomic_t dropped;
61203 + atomic_unchecked_t dropped;
61204 };
61205
61206 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61207 diff --git a/include/linux/cache.h b/include/linux/cache.h
61208 index 4c57065..4307975 100644
61209 --- a/include/linux/cache.h
61210 +++ b/include/linux/cache.h
61211 @@ -16,6 +16,10 @@
61212 #define __read_mostly
61213 #endif
61214
61215 +#ifndef __read_only
61216 +#define __read_only __read_mostly
61217 +#endif
61218 +
61219 #ifndef ____cacheline_aligned
61220 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61221 #endif
61222 diff --git a/include/linux/capability.h b/include/linux/capability.h
61223 index 98503b7..cc36d18 100644
61224 --- a/include/linux/capability.h
61225 +++ b/include/linux/capability.h
61226 @@ -211,8 +211,13 @@ extern bool capable(int cap);
61227 extern bool ns_capable(struct user_namespace *ns, int cap);
61228 extern bool nsown_capable(int cap);
61229 extern bool inode_capable(const struct inode *inode, int cap);
61230 +extern bool capable_nolog(int cap);
61231 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61232 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61233
61234 /* audit system wants to get cap info from files as well */
61235 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61236
61237 +extern int is_privileged_binary(const struct dentry *dentry);
61238 +
61239 #endif /* !_LINUX_CAPABILITY_H */
61240 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61241 index 42e55de..1cd0e66 100644
61242 --- a/include/linux/cleancache.h
61243 +++ b/include/linux/cleancache.h
61244 @@ -31,7 +31,7 @@ struct cleancache_ops {
61245 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61246 void (*invalidate_inode)(int, struct cleancache_filekey);
61247 void (*invalidate_fs)(int);
61248 -};
61249 +} __no_const;
61250
61251 extern struct cleancache_ops
61252 cleancache_register_ops(struct cleancache_ops *ops);
61253 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61254 index f9f5e9e..9fb4d36 100644
61255 --- a/include/linux/clk-provider.h
61256 +++ b/include/linux/clk-provider.h
61257 @@ -112,6 +112,7 @@ struct clk_ops {
61258 unsigned long);
61259 void (*init)(struct clk_hw *hw);
61260 };
61261 +typedef struct clk_ops __no_const clk_ops_no_const;
61262
61263 /**
61264 * struct clk_init_data - holds init data that's common to all clocks and is
61265 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61266 index 412bc6c..c31666e 100644
61267 --- a/include/linux/compiler-gcc4.h
61268 +++ b/include/linux/compiler-gcc4.h
61269 @@ -32,6 +32,21 @@
61270 #define __linktime_error(message) __attribute__((__error__(message)))
61271
61272 #if __GNUC_MINOR__ >= 5
61273 +
61274 +#ifdef CONSTIFY_PLUGIN
61275 +#define __no_const __attribute__((no_const))
61276 +#define __do_const __attribute__((do_const))
61277 +#endif
61278 +
61279 +#ifdef SIZE_OVERFLOW_PLUGIN
61280 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61281 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61282 +#endif
61283 +
61284 +#ifdef LATENT_ENTROPY_PLUGIN
61285 +#define __latent_entropy __attribute__((latent_entropy))
61286 +#endif
61287 +
61288 /*
61289 * Mark a position in code as unreachable. This can be used to
61290 * suppress control flow warnings after asm blocks that transfer
61291 @@ -47,6 +62,11 @@
61292 #define __noclone __attribute__((__noclone__))
61293
61294 #endif
61295 +
61296 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61297 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61298 +#define __bos0(ptr) __bos((ptr), 0)
61299 +#define __bos1(ptr) __bos((ptr), 1)
61300 #endif
61301
61302 #if __GNUC_MINOR__ >= 6
61303 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61304 index f430e41..38be90f 100644
61305 --- a/include/linux/compiler.h
61306 +++ b/include/linux/compiler.h
61307 @@ -5,31 +5,62 @@
61308
61309 #ifdef __CHECKER__
61310 # define __user __attribute__((noderef, address_space(1)))
61311 +# define __force_user __force __user
61312 # define __kernel __attribute__((address_space(0)))
61313 +# define __force_kernel __force __kernel
61314 # define __safe __attribute__((safe))
61315 # define __force __attribute__((force))
61316 # define __nocast __attribute__((nocast))
61317 # define __iomem __attribute__((noderef, address_space(2)))
61318 +# define __force_iomem __force __iomem
61319 # define __acquires(x) __attribute__((context(x,0,1)))
61320 # define __releases(x) __attribute__((context(x,1,0)))
61321 # define __acquire(x) __context__(x,1)
61322 # define __release(x) __context__(x,-1)
61323 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61324 # define __percpu __attribute__((noderef, address_space(3)))
61325 +# define __force_percpu __force __percpu
61326 #ifdef CONFIG_SPARSE_RCU_POINTER
61327 # define __rcu __attribute__((noderef, address_space(4)))
61328 +# define __force_rcu __force __rcu
61329 #else
61330 # define __rcu
61331 +# define __force_rcu
61332 #endif
61333 extern void __chk_user_ptr(const volatile void __user *);
61334 extern void __chk_io_ptr(const volatile void __iomem *);
61335 +#elif defined(CHECKER_PLUGIN)
61336 +//# define __user
61337 +//# define __force_user
61338 +//# define __kernel
61339 +//# define __force_kernel
61340 +# define __safe
61341 +# define __force
61342 +# define __nocast
61343 +# define __iomem
61344 +# define __force_iomem
61345 +# define __chk_user_ptr(x) (void)0
61346 +# define __chk_io_ptr(x) (void)0
61347 +# define __builtin_warning(x, y...) (1)
61348 +# define __acquires(x)
61349 +# define __releases(x)
61350 +# define __acquire(x) (void)0
61351 +# define __release(x) (void)0
61352 +# define __cond_lock(x,c) (c)
61353 +# define __percpu
61354 +# define __force_percpu
61355 +# define __rcu
61356 +# define __force_rcu
61357 #else
61358 # define __user
61359 +# define __force_user
61360 # define __kernel
61361 +# define __force_kernel
61362 # define __safe
61363 # define __force
61364 # define __nocast
61365 # define __iomem
61366 +# define __force_iomem
61367 # define __chk_user_ptr(x) (void)0
61368 # define __chk_io_ptr(x) (void)0
61369 # define __builtin_warning(x, y...) (1)
61370 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61371 # define __release(x) (void)0
61372 # define __cond_lock(x,c) (c)
61373 # define __percpu
61374 +# define __force_percpu
61375 # define __rcu
61376 +# define __force_rcu
61377 #endif
61378
61379 #ifdef __KERNEL__
61380 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61381 # define __attribute_const__ /* unimplemented */
61382 #endif
61383
61384 +#ifndef __no_const
61385 +# define __no_const
61386 +#endif
61387 +
61388 +#ifndef __do_const
61389 +# define __do_const
61390 +#endif
61391 +
61392 +#ifndef __size_overflow
61393 +# define __size_overflow(...)
61394 +#endif
61395 +
61396 +#ifndef __intentional_overflow
61397 +# define __intentional_overflow(...)
61398 +#endif
61399 +
61400 +#ifndef __latent_entropy
61401 +# define __latent_entropy
61402 +#endif
61403 +
61404 /*
61405 * Tell gcc if a function is cold. The compiler will assume any path
61406 * directly leading to the call is unlikely.
61407 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61408 #define __cold
61409 #endif
61410
61411 +#ifndef __alloc_size
61412 +#define __alloc_size(...)
61413 +#endif
61414 +
61415 +#ifndef __bos
61416 +#define __bos(ptr, arg)
61417 +#endif
61418 +
61419 +#ifndef __bos0
61420 +#define __bos0(ptr)
61421 +#endif
61422 +
61423 +#ifndef __bos1
61424 +#define __bos1(ptr)
61425 +#endif
61426 +
61427 /* Simple shorthand for a section definition */
61428 #ifndef __section
61429 # define __section(S) __attribute__ ((__section__(#S)))
61430 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61431 * use is to mediate communication between process-level code and irq/NMI
61432 * handlers, all running on the same CPU.
61433 */
61434 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61435 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61436 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61437
61438 #endif /* __LINUX_COMPILER_H */
61439 diff --git a/include/linux/cred.h b/include/linux/cred.h
61440 index ebbed2c..908cc2c 100644
61441 --- a/include/linux/cred.h
61442 +++ b/include/linux/cred.h
61443 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61444 static inline void validate_process_creds(void)
61445 {
61446 }
61447 +static inline void validate_task_creds(struct task_struct *task)
61448 +{
61449 +}
61450 #endif
61451
61452 /**
61453 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61454 index b92eadf..b4ecdc1 100644
61455 --- a/include/linux/crypto.h
61456 +++ b/include/linux/crypto.h
61457 @@ -373,7 +373,7 @@ struct cipher_tfm {
61458 const u8 *key, unsigned int keylen);
61459 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61460 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61461 -};
61462 +} __no_const;
61463
61464 struct hash_tfm {
61465 int (*init)(struct hash_desc *desc);
61466 @@ -394,13 +394,13 @@ struct compress_tfm {
61467 int (*cot_decompress)(struct crypto_tfm *tfm,
61468 const u8 *src, unsigned int slen,
61469 u8 *dst, unsigned int *dlen);
61470 -};
61471 +} __no_const;
61472
61473 struct rng_tfm {
61474 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61475 unsigned int dlen);
61476 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61477 -};
61478 +} __no_const;
61479
61480 #define crt_ablkcipher crt_u.ablkcipher
61481 #define crt_aead crt_u.aead
61482 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61483 index 7925bf0..d5143d2 100644
61484 --- a/include/linux/decompress/mm.h
61485 +++ b/include/linux/decompress/mm.h
61486 @@ -77,7 +77,7 @@ static void free(void *where)
61487 * warnings when not needed (indeed large_malloc / large_free are not
61488 * needed by inflate */
61489
61490 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61491 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61492 #define free(a) kfree(a)
61493
61494 #define large_malloc(a) vmalloc(a)
61495 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61496 index 94af418..b1ca7a2 100644
61497 --- a/include/linux/dma-mapping.h
61498 +++ b/include/linux/dma-mapping.h
61499 @@ -54,7 +54,7 @@ struct dma_map_ops {
61500 u64 (*get_required_mask)(struct device *dev);
61501 #endif
61502 int is_phys;
61503 -};
61504 +} __do_const;
61505
61506 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61507
61508 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61509 index d3201e4..8281e63 100644
61510 --- a/include/linux/dmaengine.h
61511 +++ b/include/linux/dmaengine.h
61512 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
61513 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61514 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61515
61516 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61517 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61518 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61519 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61520 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61521 struct dma_pinned_list *pinned_list, struct page *page,
61522 unsigned int offset, size_t len);
61523
61524 diff --git a/include/linux/efi.h b/include/linux/efi.h
61525 index 8670eb1..7eb3ade 100644
61526 --- a/include/linux/efi.h
61527 +++ b/include/linux/efi.h
61528 @@ -643,7 +643,7 @@ struct efivar_operations {
61529 efi_get_variable_t *get_variable;
61530 efi_get_next_variable_t *get_next_variable;
61531 efi_set_variable_t *set_variable;
61532 -};
61533 +} __no_const;
61534
61535 struct efivars {
61536 /*
61537 diff --git a/include/linux/elf.h b/include/linux/elf.h
61538 index 8c9048e..16a4665 100644
61539 --- a/include/linux/elf.h
61540 +++ b/include/linux/elf.h
61541 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
61542 #define elf_note elf32_note
61543 #define elf_addr_t Elf32_Off
61544 #define Elf_Half Elf32_Half
61545 +#define elf_dyn Elf32_Dyn
61546
61547 #else
61548
61549 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
61550 #define elf_note elf64_note
61551 #define elf_addr_t Elf64_Off
61552 #define Elf_Half Elf64_Half
61553 +#define elf_dyn Elf64_Dyn
61554
61555 #endif
61556
61557 diff --git a/include/linux/filter.h b/include/linux/filter.h
61558 index 24d251f..7afb83d 100644
61559 --- a/include/linux/filter.h
61560 +++ b/include/linux/filter.h
61561 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
61562
61563 struct sk_buff;
61564 struct sock;
61565 +struct bpf_jit_work;
61566
61567 struct sk_filter
61568 {
61569 @@ -27,6 +28,9 @@ struct sk_filter
61570 unsigned int len; /* Number of filter blocks */
61571 unsigned int (*bpf_func)(const struct sk_buff *skb,
61572 const struct sock_filter *filter);
61573 +#ifdef CONFIG_BPF_JIT
61574 + struct bpf_jit_work *work;
61575 +#endif
61576 struct rcu_head rcu;
61577 struct sock_filter insns[0];
61578 };
61579 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61580 index 191501a..3952e37 100644
61581 --- a/include/linux/firewire.h
61582 +++ b/include/linux/firewire.h
61583 @@ -438,7 +438,7 @@ struct fw_iso_context {
61584 union {
61585 fw_iso_callback_t sc;
61586 fw_iso_mc_callback_t mc;
61587 - } callback;
61588 + } __no_const callback;
61589 void *callback_data;
61590 };
61591
61592 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61593 index 3044254..9767f41 100644
61594 --- a/include/linux/frontswap.h
61595 +++ b/include/linux/frontswap.h
61596 @@ -11,7 +11,7 @@ struct frontswap_ops {
61597 int (*load)(unsigned, pgoff_t, struct page *);
61598 void (*invalidate_page)(unsigned, pgoff_t);
61599 void (*invalidate_area)(unsigned);
61600 -};
61601 +} __no_const;
61602
61603 extern bool frontswap_enabled;
61604 extern struct frontswap_ops
61605 diff --git a/include/linux/fs.h b/include/linux/fs.h
61606 index 75fe9a1..72a4a6b 100644
61607 --- a/include/linux/fs.h
61608 +++ b/include/linux/fs.h
61609 @@ -1543,7 +1543,8 @@ struct file_operations {
61610 int (*setlease)(struct file *, long, struct file_lock **);
61611 long (*fallocate)(struct file *file, int mode, loff_t offset,
61612 loff_t len);
61613 -};
61614 +} __do_const;
61615 +typedef struct file_operations __no_const file_operations_no_const;
61616
61617 struct inode_operations {
61618 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61619 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61620 index 003dc0f..3c4ea97 100644
61621 --- a/include/linux/fs_struct.h
61622 +++ b/include/linux/fs_struct.h
61623 @@ -6,7 +6,7 @@
61624 #include <linux/seqlock.h>
61625
61626 struct fs_struct {
61627 - int users;
61628 + atomic_t users;
61629 spinlock_t lock;
61630 seqcount_t seq;
61631 int umask;
61632 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61633 index ce31408..b1ad003 100644
61634 --- a/include/linux/fscache-cache.h
61635 +++ b/include/linux/fscache-cache.h
61636 @@ -102,7 +102,7 @@ struct fscache_operation {
61637 fscache_operation_release_t release;
61638 };
61639
61640 -extern atomic_t fscache_op_debug_id;
61641 +extern atomic_unchecked_t fscache_op_debug_id;
61642 extern void fscache_op_work_func(struct work_struct *work);
61643
61644 extern void fscache_enqueue_operation(struct fscache_operation *);
61645 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61646 {
61647 INIT_WORK(&op->work, fscache_op_work_func);
61648 atomic_set(&op->usage, 1);
61649 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61650 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61651 op->processor = processor;
61652 op->release = release;
61653 INIT_LIST_HEAD(&op->pend_link);
61654 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61655 index 0fbfb46..52a6556 100644
61656 --- a/include/linux/fsnotify.h
61657 +++ b/include/linux/fsnotify.h
61658 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61659 */
61660 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61661 {
61662 - return kstrdup(name, GFP_KERNEL);
61663 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61664 }
61665
61666 /*
61667 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61668 index 63d966d..cdcb717 100644
61669 --- a/include/linux/fsnotify_backend.h
61670 +++ b/include/linux/fsnotify_backend.h
61671 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61672 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61673 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61674 };
61675 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61676
61677 /*
61678 * A group is a "thing" that wants to receive notification about filesystem
61679 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61680 index 642928c..e6c83a7 100644
61681 --- a/include/linux/ftrace_event.h
61682 +++ b/include/linux/ftrace_event.h
61683 @@ -97,7 +97,7 @@ struct trace_event_functions {
61684 trace_print_func raw;
61685 trace_print_func hex;
61686 trace_print_func binary;
61687 -};
61688 +} __no_const;
61689
61690 struct trace_event {
61691 struct hlist_node node;
61692 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61693 extern int trace_add_event_call(struct ftrace_event_call *call);
61694 extern void trace_remove_event_call(struct ftrace_event_call *call);
61695
61696 -#define is_signed_type(type) (((type)(-1)) < 0)
61697 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61698
61699 int trace_set_clr_event(const char *system, const char *event, int set);
61700
61701 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61702 index 4f440b3..342233a 100644
61703 --- a/include/linux/genhd.h
61704 +++ b/include/linux/genhd.h
61705 @@ -190,7 +190,7 @@ struct gendisk {
61706 struct kobject *slave_dir;
61707
61708 struct timer_rand_state *random;
61709 - atomic_t sync_io; /* RAID */
61710 + atomic_unchecked_t sync_io; /* RAID */
61711 struct disk_events *ev;
61712 #ifdef CONFIG_BLK_DEV_INTEGRITY
61713 struct blk_integrity *integrity;
61714 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61715 index d0a7967..63c4c47 100644
61716 --- a/include/linux/gfp.h
61717 +++ b/include/linux/gfp.h
61718 @@ -35,6 +35,12 @@ struct vm_area_struct;
61719 #define ___GFP_OTHER_NODE 0x800000u
61720 #define ___GFP_WRITE 0x1000000u
61721
61722 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61723 +#define ___GFP_USERCOPY 0x2000000u
61724 +#else
61725 +#define ___GFP_USERCOPY 0
61726 +#endif
61727 +
61728 /*
61729 * GFP bitmasks..
61730 *
61731 @@ -89,6 +95,7 @@ struct vm_area_struct;
61732 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61733 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61734 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61735 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61736
61737 /*
61738 * This may seem redundant, but it's a way of annotating false positives vs.
61739 @@ -96,7 +103,7 @@ struct vm_area_struct;
61740 */
61741 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61742
61743 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61744 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61745 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61746
61747 /* This equals 0, but use constants in case they ever change */
61748 @@ -150,6 +157,8 @@ struct vm_area_struct;
61749 /* 4GB DMA on some platforms */
61750 #define GFP_DMA32 __GFP_DMA32
61751
61752 +#define GFP_USERCOPY __GFP_USERCOPY
61753 +
61754 /* Convert GFP flags to their corresponding migrate type */
61755 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61756 {
61757 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61758 new file mode 100644
61759 index 0000000..ebe6d72
61760 --- /dev/null
61761 +++ b/include/linux/gracl.h
61762 @@ -0,0 +1,319 @@
61763 +#ifndef GR_ACL_H
61764 +#define GR_ACL_H
61765 +
61766 +#include <linux/grdefs.h>
61767 +#include <linux/resource.h>
61768 +#include <linux/capability.h>
61769 +#include <linux/dcache.h>
61770 +#include <asm/resource.h>
61771 +
61772 +/* Major status information */
61773 +
61774 +#define GR_VERSION "grsecurity 2.9.1"
61775 +#define GRSECURITY_VERSION 0x2901
61776 +
61777 +enum {
61778 + GR_SHUTDOWN = 0,
61779 + GR_ENABLE = 1,
61780 + GR_SPROLE = 2,
61781 + GR_RELOAD = 3,
61782 + GR_SEGVMOD = 4,
61783 + GR_STATUS = 5,
61784 + GR_UNSPROLE = 6,
61785 + GR_PASSSET = 7,
61786 + GR_SPROLEPAM = 8,
61787 +};
61788 +
61789 +/* Password setup definitions
61790 + * kernel/grhash.c */
61791 +enum {
61792 + GR_PW_LEN = 128,
61793 + GR_SALT_LEN = 16,
61794 + GR_SHA_LEN = 32,
61795 +};
61796 +
61797 +enum {
61798 + GR_SPROLE_LEN = 64,
61799 +};
61800 +
61801 +enum {
61802 + GR_NO_GLOB = 0,
61803 + GR_REG_GLOB,
61804 + GR_CREATE_GLOB
61805 +};
61806 +
61807 +#define GR_NLIMITS 32
61808 +
61809 +/* Begin Data Structures */
61810 +
61811 +struct sprole_pw {
61812 + unsigned char *rolename;
61813 + unsigned char salt[GR_SALT_LEN];
61814 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61815 +};
61816 +
61817 +struct name_entry {
61818 + __u32 key;
61819 + ino_t inode;
61820 + dev_t device;
61821 + char *name;
61822 + __u16 len;
61823 + __u8 deleted;
61824 + struct name_entry *prev;
61825 + struct name_entry *next;
61826 +};
61827 +
61828 +struct inodev_entry {
61829 + struct name_entry *nentry;
61830 + struct inodev_entry *prev;
61831 + struct inodev_entry *next;
61832 +};
61833 +
61834 +struct acl_role_db {
61835 + struct acl_role_label **r_hash;
61836 + __u32 r_size;
61837 +};
61838 +
61839 +struct inodev_db {
61840 + struct inodev_entry **i_hash;
61841 + __u32 i_size;
61842 +};
61843 +
61844 +struct name_db {
61845 + struct name_entry **n_hash;
61846 + __u32 n_size;
61847 +};
61848 +
61849 +struct crash_uid {
61850 + uid_t uid;
61851 + unsigned long expires;
61852 +};
61853 +
61854 +struct gr_hash_struct {
61855 + void **table;
61856 + void **nametable;
61857 + void *first;
61858 + __u32 table_size;
61859 + __u32 used_size;
61860 + int type;
61861 +};
61862 +
61863 +/* Userspace Grsecurity ACL data structures */
61864 +
61865 +struct acl_subject_label {
61866 + char *filename;
61867 + ino_t inode;
61868 + dev_t device;
61869 + __u32 mode;
61870 + kernel_cap_t cap_mask;
61871 + kernel_cap_t cap_lower;
61872 + kernel_cap_t cap_invert_audit;
61873 +
61874 + struct rlimit res[GR_NLIMITS];
61875 + __u32 resmask;
61876 +
61877 + __u8 user_trans_type;
61878 + __u8 group_trans_type;
61879 + uid_t *user_transitions;
61880 + gid_t *group_transitions;
61881 + __u16 user_trans_num;
61882 + __u16 group_trans_num;
61883 +
61884 + __u32 sock_families[2];
61885 + __u32 ip_proto[8];
61886 + __u32 ip_type;
61887 + struct acl_ip_label **ips;
61888 + __u32 ip_num;
61889 + __u32 inaddr_any_override;
61890 +
61891 + __u32 crashes;
61892 + unsigned long expires;
61893 +
61894 + struct acl_subject_label *parent_subject;
61895 + struct gr_hash_struct *hash;
61896 + struct acl_subject_label *prev;
61897 + struct acl_subject_label *next;
61898 +
61899 + struct acl_object_label **obj_hash;
61900 + __u32 obj_hash_size;
61901 + __u16 pax_flags;
61902 +};
61903 +
61904 +struct role_allowed_ip {
61905 + __u32 addr;
61906 + __u32 netmask;
61907 +
61908 + struct role_allowed_ip *prev;
61909 + struct role_allowed_ip *next;
61910 +};
61911 +
61912 +struct role_transition {
61913 + char *rolename;
61914 +
61915 + struct role_transition *prev;
61916 + struct role_transition *next;
61917 +};
61918 +
61919 +struct acl_role_label {
61920 + char *rolename;
61921 + uid_t uidgid;
61922 + __u16 roletype;
61923 +
61924 + __u16 auth_attempts;
61925 + unsigned long expires;
61926 +
61927 + struct acl_subject_label *root_label;
61928 + struct gr_hash_struct *hash;
61929 +
61930 + struct acl_role_label *prev;
61931 + struct acl_role_label *next;
61932 +
61933 + struct role_transition *transitions;
61934 + struct role_allowed_ip *allowed_ips;
61935 + uid_t *domain_children;
61936 + __u16 domain_child_num;
61937 +
61938 + umode_t umask;
61939 +
61940 + struct acl_subject_label **subj_hash;
61941 + __u32 subj_hash_size;
61942 +};
61943 +
61944 +struct user_acl_role_db {
61945 + struct acl_role_label **r_table;
61946 + __u32 num_pointers; /* Number of allocations to track */
61947 + __u32 num_roles; /* Number of roles */
61948 + __u32 num_domain_children; /* Number of domain children */
61949 + __u32 num_subjects; /* Number of subjects */
61950 + __u32 num_objects; /* Number of objects */
61951 +};
61952 +
61953 +struct acl_object_label {
61954 + char *filename;
61955 + ino_t inode;
61956 + dev_t device;
61957 + __u32 mode;
61958 +
61959 + struct acl_subject_label *nested;
61960 + struct acl_object_label *globbed;
61961 +
61962 + /* next two structures not used */
61963 +
61964 + struct acl_object_label *prev;
61965 + struct acl_object_label *next;
61966 +};
61967 +
61968 +struct acl_ip_label {
61969 + char *iface;
61970 + __u32 addr;
61971 + __u32 netmask;
61972 + __u16 low, high;
61973 + __u8 mode;
61974 + __u32 type;
61975 + __u32 proto[8];
61976 +
61977 + /* next two structures not used */
61978 +
61979 + struct acl_ip_label *prev;
61980 + struct acl_ip_label *next;
61981 +};
61982 +
61983 +struct gr_arg {
61984 + struct user_acl_role_db role_db;
61985 + unsigned char pw[GR_PW_LEN];
61986 + unsigned char salt[GR_SALT_LEN];
61987 + unsigned char sum[GR_SHA_LEN];
61988 + unsigned char sp_role[GR_SPROLE_LEN];
61989 + struct sprole_pw *sprole_pws;
61990 + dev_t segv_device;
61991 + ino_t segv_inode;
61992 + uid_t segv_uid;
61993 + __u16 num_sprole_pws;
61994 + __u16 mode;
61995 +};
61996 +
61997 +struct gr_arg_wrapper {
61998 + struct gr_arg *arg;
61999 + __u32 version;
62000 + __u32 size;
62001 +};
62002 +
62003 +struct subject_map {
62004 + struct acl_subject_label *user;
62005 + struct acl_subject_label *kernel;
62006 + struct subject_map *prev;
62007 + struct subject_map *next;
62008 +};
62009 +
62010 +struct acl_subj_map_db {
62011 + struct subject_map **s_hash;
62012 + __u32 s_size;
62013 +};
62014 +
62015 +/* End Data Structures Section */
62016 +
62017 +/* Hash functions generated by empirical testing by Brad Spengler
62018 + Makes good use of the low bits of the inode. Generally 0-1 times
62019 + in loop for successful match. 0-3 for unsuccessful match.
62020 + Shift/add algorithm with modulus of table size and an XOR*/
62021 +
62022 +static __inline__ unsigned int
62023 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62024 +{
62025 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62026 +}
62027 +
62028 + static __inline__ unsigned int
62029 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
62030 +{
62031 + return ((const unsigned long)userp % sz);
62032 +}
62033 +
62034 +static __inline__ unsigned int
62035 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62036 +{
62037 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62038 +}
62039 +
62040 +static __inline__ unsigned int
62041 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
62042 +{
62043 + return full_name_hash((const unsigned char *)name, len) % sz;
62044 +}
62045 +
62046 +#define FOR_EACH_ROLE_START(role) \
62047 + role = role_list; \
62048 + while (role) {
62049 +
62050 +#define FOR_EACH_ROLE_END(role) \
62051 + role = role->prev; \
62052 + }
62053 +
62054 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62055 + subj = NULL; \
62056 + iter = 0; \
62057 + while (iter < role->subj_hash_size) { \
62058 + if (subj == NULL) \
62059 + subj = role->subj_hash[iter]; \
62060 + if (subj == NULL) { \
62061 + iter++; \
62062 + continue; \
62063 + }
62064 +
62065 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62066 + subj = subj->next; \
62067 + if (subj == NULL) \
62068 + iter++; \
62069 + }
62070 +
62071 +
62072 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62073 + subj = role->hash->first; \
62074 + while (subj != NULL) {
62075 +
62076 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62077 + subj = subj->next; \
62078 + }
62079 +
62080 +#endif
62081 +
62082 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62083 new file mode 100644
62084 index 0000000..323ecf2
62085 --- /dev/null
62086 +++ b/include/linux/gralloc.h
62087 @@ -0,0 +1,9 @@
62088 +#ifndef __GRALLOC_H
62089 +#define __GRALLOC_H
62090 +
62091 +void acl_free_all(void);
62092 +int acl_alloc_stack_init(unsigned long size);
62093 +void *acl_alloc(unsigned long len);
62094 +void *acl_alloc_num(unsigned long num, unsigned long len);
62095 +
62096 +#endif
62097 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62098 new file mode 100644
62099 index 0000000..b30e9bc
62100 --- /dev/null
62101 +++ b/include/linux/grdefs.h
62102 @@ -0,0 +1,140 @@
62103 +#ifndef GRDEFS_H
62104 +#define GRDEFS_H
62105 +
62106 +/* Begin grsecurity status declarations */
62107 +
62108 +enum {
62109 + GR_READY = 0x01,
62110 + GR_STATUS_INIT = 0x00 // disabled state
62111 +};
62112 +
62113 +/* Begin ACL declarations */
62114 +
62115 +/* Role flags */
62116 +
62117 +enum {
62118 + GR_ROLE_USER = 0x0001,
62119 + GR_ROLE_GROUP = 0x0002,
62120 + GR_ROLE_DEFAULT = 0x0004,
62121 + GR_ROLE_SPECIAL = 0x0008,
62122 + GR_ROLE_AUTH = 0x0010,
62123 + GR_ROLE_NOPW = 0x0020,
62124 + GR_ROLE_GOD = 0x0040,
62125 + GR_ROLE_LEARN = 0x0080,
62126 + GR_ROLE_TPE = 0x0100,
62127 + GR_ROLE_DOMAIN = 0x0200,
62128 + GR_ROLE_PAM = 0x0400,
62129 + GR_ROLE_PERSIST = 0x0800
62130 +};
62131 +
62132 +/* ACL Subject and Object mode flags */
62133 +enum {
62134 + GR_DELETED = 0x80000000
62135 +};
62136 +
62137 +/* ACL Object-only mode flags */
62138 +enum {
62139 + GR_READ = 0x00000001,
62140 + GR_APPEND = 0x00000002,
62141 + GR_WRITE = 0x00000004,
62142 + GR_EXEC = 0x00000008,
62143 + GR_FIND = 0x00000010,
62144 + GR_INHERIT = 0x00000020,
62145 + GR_SETID = 0x00000040,
62146 + GR_CREATE = 0x00000080,
62147 + GR_DELETE = 0x00000100,
62148 + GR_LINK = 0x00000200,
62149 + GR_AUDIT_READ = 0x00000400,
62150 + GR_AUDIT_APPEND = 0x00000800,
62151 + GR_AUDIT_WRITE = 0x00001000,
62152 + GR_AUDIT_EXEC = 0x00002000,
62153 + GR_AUDIT_FIND = 0x00004000,
62154 + GR_AUDIT_INHERIT= 0x00008000,
62155 + GR_AUDIT_SETID = 0x00010000,
62156 + GR_AUDIT_CREATE = 0x00020000,
62157 + GR_AUDIT_DELETE = 0x00040000,
62158 + GR_AUDIT_LINK = 0x00080000,
62159 + GR_PTRACERD = 0x00100000,
62160 + GR_NOPTRACE = 0x00200000,
62161 + GR_SUPPRESS = 0x00400000,
62162 + GR_NOLEARN = 0x00800000,
62163 + GR_INIT_TRANSFER= 0x01000000
62164 +};
62165 +
62166 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62167 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62168 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62169 +
62170 +/* ACL subject-only mode flags */
62171 +enum {
62172 + GR_KILL = 0x00000001,
62173 + GR_VIEW = 0x00000002,
62174 + GR_PROTECTED = 0x00000004,
62175 + GR_LEARN = 0x00000008,
62176 + GR_OVERRIDE = 0x00000010,
62177 + /* just a placeholder, this mode is only used in userspace */
62178 + GR_DUMMY = 0x00000020,
62179 + GR_PROTSHM = 0x00000040,
62180 + GR_KILLPROC = 0x00000080,
62181 + GR_KILLIPPROC = 0x00000100,
62182 + /* just a placeholder, this mode is only used in userspace */
62183 + GR_NOTROJAN = 0x00000200,
62184 + GR_PROTPROCFD = 0x00000400,
62185 + GR_PROCACCT = 0x00000800,
62186 + GR_RELAXPTRACE = 0x00001000,
62187 + GR_NESTED = 0x00002000,
62188 + GR_INHERITLEARN = 0x00004000,
62189 + GR_PROCFIND = 0x00008000,
62190 + GR_POVERRIDE = 0x00010000,
62191 + GR_KERNELAUTH = 0x00020000,
62192 + GR_ATSECURE = 0x00040000,
62193 + GR_SHMEXEC = 0x00080000
62194 +};
62195 +
62196 +enum {
62197 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62198 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62199 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62200 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62201 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62202 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62203 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62204 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62205 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62206 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62207 +};
62208 +
62209 +enum {
62210 + GR_ID_USER = 0x01,
62211 + GR_ID_GROUP = 0x02,
62212 +};
62213 +
62214 +enum {
62215 + GR_ID_ALLOW = 0x01,
62216 + GR_ID_DENY = 0x02,
62217 +};
62218 +
62219 +#define GR_CRASH_RES 31
62220 +#define GR_UIDTABLE_MAX 500
62221 +
62222 +/* begin resource learning section */
62223 +enum {
62224 + GR_RLIM_CPU_BUMP = 60,
62225 + GR_RLIM_FSIZE_BUMP = 50000,
62226 + GR_RLIM_DATA_BUMP = 10000,
62227 + GR_RLIM_STACK_BUMP = 1000,
62228 + GR_RLIM_CORE_BUMP = 10000,
62229 + GR_RLIM_RSS_BUMP = 500000,
62230 + GR_RLIM_NPROC_BUMP = 1,
62231 + GR_RLIM_NOFILE_BUMP = 5,
62232 + GR_RLIM_MEMLOCK_BUMP = 50000,
62233 + GR_RLIM_AS_BUMP = 500000,
62234 + GR_RLIM_LOCKS_BUMP = 2,
62235 + GR_RLIM_SIGPENDING_BUMP = 5,
62236 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62237 + GR_RLIM_NICE_BUMP = 1,
62238 + GR_RLIM_RTPRIO_BUMP = 1,
62239 + GR_RLIM_RTTIME_BUMP = 1000000
62240 +};
62241 +
62242 +#endif
62243 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62244 new file mode 100644
62245 index 0000000..c9292f7
62246 --- /dev/null
62247 +++ b/include/linux/grinternal.h
62248 @@ -0,0 +1,223 @@
62249 +#ifndef __GRINTERNAL_H
62250 +#define __GRINTERNAL_H
62251 +
62252 +#ifdef CONFIG_GRKERNSEC
62253 +
62254 +#include <linux/fs.h>
62255 +#include <linux/mnt_namespace.h>
62256 +#include <linux/nsproxy.h>
62257 +#include <linux/gracl.h>
62258 +#include <linux/grdefs.h>
62259 +#include <linux/grmsg.h>
62260 +
62261 +void gr_add_learn_entry(const char *fmt, ...)
62262 + __attribute__ ((format (printf, 1, 2)));
62263 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62264 + const struct vfsmount *mnt);
62265 +__u32 gr_check_create(const struct dentry *new_dentry,
62266 + const struct dentry *parent,
62267 + const struct vfsmount *mnt, const __u32 mode);
62268 +int gr_check_protected_task(const struct task_struct *task);
62269 +__u32 to_gr_audit(const __u32 reqmode);
62270 +int gr_set_acls(const int type);
62271 +int gr_apply_subject_to_task(struct task_struct *task);
62272 +int gr_acl_is_enabled(void);
62273 +char gr_roletype_to_char(void);
62274 +
62275 +void gr_handle_alertkill(struct task_struct *task);
62276 +char *gr_to_filename(const struct dentry *dentry,
62277 + const struct vfsmount *mnt);
62278 +char *gr_to_filename1(const struct dentry *dentry,
62279 + const struct vfsmount *mnt);
62280 +char *gr_to_filename2(const struct dentry *dentry,
62281 + const struct vfsmount *mnt);
62282 +char *gr_to_filename3(const struct dentry *dentry,
62283 + const struct vfsmount *mnt);
62284 +
62285 +extern int grsec_enable_ptrace_readexec;
62286 +extern int grsec_enable_harden_ptrace;
62287 +extern int grsec_enable_link;
62288 +extern int grsec_enable_fifo;
62289 +extern int grsec_enable_execve;
62290 +extern int grsec_enable_shm;
62291 +extern int grsec_enable_execlog;
62292 +extern int grsec_enable_signal;
62293 +extern int grsec_enable_audit_ptrace;
62294 +extern int grsec_enable_forkfail;
62295 +extern int grsec_enable_time;
62296 +extern int grsec_enable_rofs;
62297 +extern int grsec_enable_chroot_shmat;
62298 +extern int grsec_enable_chroot_mount;
62299 +extern int grsec_enable_chroot_double;
62300 +extern int grsec_enable_chroot_pivot;
62301 +extern int grsec_enable_chroot_chdir;
62302 +extern int grsec_enable_chroot_chmod;
62303 +extern int grsec_enable_chroot_mknod;
62304 +extern int grsec_enable_chroot_fchdir;
62305 +extern int grsec_enable_chroot_nice;
62306 +extern int grsec_enable_chroot_execlog;
62307 +extern int grsec_enable_chroot_caps;
62308 +extern int grsec_enable_chroot_sysctl;
62309 +extern int grsec_enable_chroot_unix;
62310 +extern int grsec_enable_symlinkown;
62311 +extern int grsec_symlinkown_gid;
62312 +extern int grsec_enable_tpe;
62313 +extern int grsec_tpe_gid;
62314 +extern int grsec_enable_tpe_all;
62315 +extern int grsec_enable_tpe_invert;
62316 +extern int grsec_enable_socket_all;
62317 +extern int grsec_socket_all_gid;
62318 +extern int grsec_enable_socket_client;
62319 +extern int grsec_socket_client_gid;
62320 +extern int grsec_enable_socket_server;
62321 +extern int grsec_socket_server_gid;
62322 +extern int grsec_audit_gid;
62323 +extern int grsec_enable_group;
62324 +extern int grsec_enable_audit_textrel;
62325 +extern int grsec_enable_log_rwxmaps;
62326 +extern int grsec_enable_mount;
62327 +extern int grsec_enable_chdir;
62328 +extern int grsec_resource_logging;
62329 +extern int grsec_enable_blackhole;
62330 +extern int grsec_lastack_retries;
62331 +extern int grsec_enable_brute;
62332 +extern int grsec_lock;
62333 +
62334 +extern spinlock_t grsec_alert_lock;
62335 +extern unsigned long grsec_alert_wtime;
62336 +extern unsigned long grsec_alert_fyet;
62337 +
62338 +extern spinlock_t grsec_audit_lock;
62339 +
62340 +extern rwlock_t grsec_exec_file_lock;
62341 +
62342 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62343 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62344 + (tsk)->exec_file->f_vfsmnt) : "/")
62345 +
62346 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62347 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62348 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62349 +
62350 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62351 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62352 + (tsk)->exec_file->f_vfsmnt) : "/")
62353 +
62354 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62355 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62356 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62357 +
62358 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62359 +
62360 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62361 +
62362 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62363 + (task)->pid, (cred)->uid, \
62364 + (cred)->euid, (cred)->gid, (cred)->egid, \
62365 + gr_parent_task_fullpath(task), \
62366 + (task)->real_parent->comm, (task)->real_parent->pid, \
62367 + (pcred)->uid, (pcred)->euid, \
62368 + (pcred)->gid, (pcred)->egid
62369 +
62370 +#define GR_CHROOT_CAPS {{ \
62371 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62372 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62373 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62374 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62375 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62376 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62377 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62378 +
62379 +#define security_learn(normal_msg,args...) \
62380 +({ \
62381 + read_lock(&grsec_exec_file_lock); \
62382 + gr_add_learn_entry(normal_msg "\n", ## args); \
62383 + read_unlock(&grsec_exec_file_lock); \
62384 +})
62385 +
62386 +enum {
62387 + GR_DO_AUDIT,
62388 + GR_DONT_AUDIT,
62389 + /* used for non-audit messages that we shouldn't kill the task on */
62390 + GR_DONT_AUDIT_GOOD
62391 +};
62392 +
62393 +enum {
62394 + GR_TTYSNIFF,
62395 + GR_RBAC,
62396 + GR_RBAC_STR,
62397 + GR_STR_RBAC,
62398 + GR_RBAC_MODE2,
62399 + GR_RBAC_MODE3,
62400 + GR_FILENAME,
62401 + GR_SYSCTL_HIDDEN,
62402 + GR_NOARGS,
62403 + GR_ONE_INT,
62404 + GR_ONE_INT_TWO_STR,
62405 + GR_ONE_STR,
62406 + GR_STR_INT,
62407 + GR_TWO_STR_INT,
62408 + GR_TWO_INT,
62409 + GR_TWO_U64,
62410 + GR_THREE_INT,
62411 + GR_FIVE_INT_TWO_STR,
62412 + GR_TWO_STR,
62413 + GR_THREE_STR,
62414 + GR_FOUR_STR,
62415 + GR_STR_FILENAME,
62416 + GR_FILENAME_STR,
62417 + GR_FILENAME_TWO_INT,
62418 + GR_FILENAME_TWO_INT_STR,
62419 + GR_TEXTREL,
62420 + GR_PTRACE,
62421 + GR_RESOURCE,
62422 + GR_CAP,
62423 + GR_SIG,
62424 + GR_SIG2,
62425 + GR_CRASH1,
62426 + GR_CRASH2,
62427 + GR_PSACCT,
62428 + GR_RWXMAP
62429 +};
62430 +
62431 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62432 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62433 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62434 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62435 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62436 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62437 +#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)
62438 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62439 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62440 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62441 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62442 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62443 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62444 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62445 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62446 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62447 +#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)
62448 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62449 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62450 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62451 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62452 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62453 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62454 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62455 +#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)
62456 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62457 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62458 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62459 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62460 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62461 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62462 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62463 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62464 +#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)
62465 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62466 +
62467 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62468 +
62469 +#endif
62470 +
62471 +#endif
62472 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62473 new file mode 100644
62474 index 0000000..2bd4c8d
62475 --- /dev/null
62476 +++ b/include/linux/grmsg.h
62477 @@ -0,0 +1,111 @@
62478 +#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"
62479 +#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"
62480 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62481 +#define GR_STOPMOD_MSG "denied modification of module state by "
62482 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62483 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62484 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62485 +#define GR_IOPL_MSG "denied use of iopl() by "
62486 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62487 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62488 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62489 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62490 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62491 +#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"
62492 +#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"
62493 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62494 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62495 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62496 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62497 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62498 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62499 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62500 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62501 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62502 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62503 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62504 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62505 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62506 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62507 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62508 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62509 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62510 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62511 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62512 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62513 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62514 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62515 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62516 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62517 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62518 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62519 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62520 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62521 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62522 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62523 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62524 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62525 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62526 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62527 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62528 +#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"
62529 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62530 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62531 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62532 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62533 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62534 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62535 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62536 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62537 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62538 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62539 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62540 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62541 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62542 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62543 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62544 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62545 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62546 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62547 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62548 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62549 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62550 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62551 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62552 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62553 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62554 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62555 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62556 +#define GR_TIME_MSG "time set by "
62557 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62558 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62559 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62560 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62561 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62562 +#define GR_BIND_MSG "denied bind() by "
62563 +#define GR_CONNECT_MSG "denied connect() by "
62564 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62565 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62566 +#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"
62567 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62568 +#define GR_CAP_ACL_MSG "use of %s denied for "
62569 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62570 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62571 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62572 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62573 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62574 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62575 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62576 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62577 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62578 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62579 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62580 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62581 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62582 +#define GR_VM86_MSG "denied use of vm86 by "
62583 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62584 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62585 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62586 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62587 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62588 +#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 "
62589 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62590 new file mode 100644
62591 index 0000000..f2f5d5b
62592 --- /dev/null
62593 +++ b/include/linux/grsecurity.h
62594 @@ -0,0 +1,239 @@
62595 +#ifndef GR_SECURITY_H
62596 +#define GR_SECURITY_H
62597 +#include <linux/fs.h>
62598 +#include <linux/fs_struct.h>
62599 +#include <linux/binfmts.h>
62600 +#include <linux/gracl.h>
62601 +
62602 +/* notify of brain-dead configs */
62603 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62604 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62605 +#endif
62606 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62607 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62608 +#endif
62609 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62610 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62611 +#endif
62612 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62613 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62614 +#endif
62615 +
62616 +#include <linux/compat.h>
62617 +
62618 +struct user_arg_ptr {
62619 +#ifdef CONFIG_COMPAT
62620 + bool is_compat;
62621 +#endif
62622 + union {
62623 + const char __user *const __user *native;
62624 +#ifdef CONFIG_COMPAT
62625 + const compat_uptr_t __user *compat;
62626 +#endif
62627 + } ptr;
62628 +};
62629 +
62630 +void gr_handle_brute_attach(unsigned long mm_flags);
62631 +void gr_handle_brute_check(void);
62632 +void gr_handle_kernel_exploit(void);
62633 +int gr_process_user_ban(void);
62634 +
62635 +char gr_roletype_to_char(void);
62636 +
62637 +int gr_acl_enable_at_secure(void);
62638 +
62639 +int gr_check_user_change(int real, int effective, int fs);
62640 +int gr_check_group_change(int real, int effective, int fs);
62641 +
62642 +void gr_del_task_from_ip_table(struct task_struct *p);
62643 +
62644 +int gr_pid_is_chrooted(struct task_struct *p);
62645 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62646 +int gr_handle_chroot_nice(void);
62647 +int gr_handle_chroot_sysctl(const int op);
62648 +int gr_handle_chroot_setpriority(struct task_struct *p,
62649 + const int niceval);
62650 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62651 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62652 + const struct vfsmount *mnt);
62653 +void gr_handle_chroot_chdir(struct path *path);
62654 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62655 + const struct vfsmount *mnt, const int mode);
62656 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62657 + const struct vfsmount *mnt, const int mode);
62658 +int gr_handle_chroot_mount(const struct dentry *dentry,
62659 + const struct vfsmount *mnt,
62660 + const char *dev_name);
62661 +int gr_handle_chroot_pivot(void);
62662 +int gr_handle_chroot_unix(const pid_t pid);
62663 +
62664 +int gr_handle_rawio(const struct inode *inode);
62665 +
62666 +void gr_handle_ioperm(void);
62667 +void gr_handle_iopl(void);
62668 +
62669 +umode_t gr_acl_umask(void);
62670 +
62671 +int gr_tpe_allow(const struct file *file);
62672 +
62673 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62674 +void gr_clear_chroot_entries(struct task_struct *task);
62675 +
62676 +void gr_log_forkfail(const int retval);
62677 +void gr_log_timechange(void);
62678 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62679 +void gr_log_chdir(const struct dentry *dentry,
62680 + const struct vfsmount *mnt);
62681 +void gr_log_chroot_exec(const struct dentry *dentry,
62682 + const struct vfsmount *mnt);
62683 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62684 +void gr_log_remount(const char *devname, const int retval);
62685 +void gr_log_unmount(const char *devname, const int retval);
62686 +void gr_log_mount(const char *from, const char *to, const int retval);
62687 +void gr_log_textrel(struct vm_area_struct *vma);
62688 +void gr_log_rwxmmap(struct file *file);
62689 +void gr_log_rwxmprotect(struct file *file);
62690 +
62691 +int gr_handle_follow_link(const struct inode *parent,
62692 + const struct inode *inode,
62693 + const struct dentry *dentry,
62694 + const struct vfsmount *mnt);
62695 +int gr_handle_fifo(const struct dentry *dentry,
62696 + const struct vfsmount *mnt,
62697 + const struct dentry *dir, const int flag,
62698 + const int acc_mode);
62699 +int gr_handle_hardlink(const struct dentry *dentry,
62700 + const struct vfsmount *mnt,
62701 + struct inode *inode,
62702 + const int mode, const struct filename *to);
62703 +
62704 +int gr_is_capable(const int cap);
62705 +int gr_is_capable_nolog(const int cap);
62706 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62707 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62708 +
62709 +void gr_learn_resource(const struct task_struct *task, const int limit,
62710 + const unsigned long wanted, const int gt);
62711 +void gr_copy_label(struct task_struct *tsk);
62712 +void gr_handle_crash(struct task_struct *task, const int sig);
62713 +int gr_handle_signal(const struct task_struct *p, const int sig);
62714 +int gr_check_crash_uid(const uid_t uid);
62715 +int gr_check_protected_task(const struct task_struct *task);
62716 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62717 +int gr_acl_handle_mmap(const struct file *file,
62718 + const unsigned long prot);
62719 +int gr_acl_handle_mprotect(const struct file *file,
62720 + const unsigned long prot);
62721 +int gr_check_hidden_task(const struct task_struct *tsk);
62722 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62723 + const struct vfsmount *mnt);
62724 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62725 + const struct vfsmount *mnt);
62726 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62727 + const struct vfsmount *mnt, const int fmode);
62728 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62729 + const struct vfsmount *mnt, umode_t *mode);
62730 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62731 + const struct vfsmount *mnt);
62732 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62733 + const struct vfsmount *mnt);
62734 +int gr_handle_ptrace(struct task_struct *task, const long request);
62735 +int gr_handle_proc_ptrace(struct task_struct *task);
62736 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62737 + const struct vfsmount *mnt);
62738 +int gr_check_crash_exec(const struct file *filp);
62739 +int gr_acl_is_enabled(void);
62740 +void gr_set_kernel_label(struct task_struct *task);
62741 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62742 + const gid_t gid);
62743 +int gr_set_proc_label(const struct dentry *dentry,
62744 + const struct vfsmount *mnt,
62745 + const int unsafe_flags);
62746 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62747 + const struct vfsmount *mnt);
62748 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62749 + const struct vfsmount *mnt, int acc_mode);
62750 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62751 + const struct dentry *p_dentry,
62752 + const struct vfsmount *p_mnt,
62753 + int open_flags, int acc_mode, const int imode);
62754 +void gr_handle_create(const struct dentry *dentry,
62755 + const struct vfsmount *mnt);
62756 +void gr_handle_proc_create(const struct dentry *dentry,
62757 + const struct inode *inode);
62758 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62759 + const struct dentry *parent_dentry,
62760 + const struct vfsmount *parent_mnt,
62761 + const int mode);
62762 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62763 + const struct dentry *parent_dentry,
62764 + const struct vfsmount *parent_mnt);
62765 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62766 + const struct vfsmount *mnt);
62767 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62768 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62769 + const struct vfsmount *mnt);
62770 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62771 + const struct dentry *parent_dentry,
62772 + const struct vfsmount *parent_mnt,
62773 + const struct filename *from);
62774 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62775 + const struct dentry *parent_dentry,
62776 + const struct vfsmount *parent_mnt,
62777 + const struct dentry *old_dentry,
62778 + const struct vfsmount *old_mnt, const struct filename *to);
62779 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62780 +int gr_acl_handle_rename(struct dentry *new_dentry,
62781 + struct dentry *parent_dentry,
62782 + const struct vfsmount *parent_mnt,
62783 + struct dentry *old_dentry,
62784 + struct inode *old_parent_inode,
62785 + struct vfsmount *old_mnt, const struct filename *newname);
62786 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62787 + struct dentry *old_dentry,
62788 + struct dentry *new_dentry,
62789 + struct vfsmount *mnt, const __u8 replace);
62790 +__u32 gr_check_link(const struct dentry *new_dentry,
62791 + const struct dentry *parent_dentry,
62792 + const struct vfsmount *parent_mnt,
62793 + const struct dentry *old_dentry,
62794 + const struct vfsmount *old_mnt);
62795 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62796 + const unsigned int namelen, const ino_t ino);
62797 +
62798 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62799 + const struct vfsmount *mnt);
62800 +void gr_acl_handle_exit(void);
62801 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62802 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62803 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62804 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62805 +void gr_audit_ptrace(struct task_struct *task);
62806 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62807 +void gr_put_exec_file(struct task_struct *task);
62808 +
62809 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62810 +
62811 +#ifdef CONFIG_GRKERNSEC
62812 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62813 +void gr_handle_vm86(void);
62814 +void gr_handle_mem_readwrite(u64 from, u64 to);
62815 +
62816 +void gr_log_badprocpid(const char *entry);
62817 +
62818 +extern int grsec_enable_dmesg;
62819 +extern int grsec_disable_privio;
62820 +
62821 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62822 +extern int grsec_proc_gid;
62823 +#endif
62824 +
62825 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62826 +extern int grsec_enable_chroot_findtask;
62827 +#endif
62828 +#ifdef CONFIG_GRKERNSEC_SETXID
62829 +extern int grsec_enable_setxid;
62830 +#endif
62831 +#endif
62832 +
62833 +#endif
62834 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62835 new file mode 100644
62836 index 0000000..e7ffaaf
62837 --- /dev/null
62838 +++ b/include/linux/grsock.h
62839 @@ -0,0 +1,19 @@
62840 +#ifndef __GRSOCK_H
62841 +#define __GRSOCK_H
62842 +
62843 +extern void gr_attach_curr_ip(const struct sock *sk);
62844 +extern int gr_handle_sock_all(const int family, const int type,
62845 + const int protocol);
62846 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62847 +extern int gr_handle_sock_server_other(const struct sock *sck);
62848 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62849 +extern int gr_search_connect(struct socket * sock,
62850 + struct sockaddr_in * addr);
62851 +extern int gr_search_bind(struct socket * sock,
62852 + struct sockaddr_in * addr);
62853 +extern int gr_search_listen(struct socket * sock);
62854 +extern int gr_search_accept(struct socket * sock);
62855 +extern int gr_search_socket(const int domain, const int type,
62856 + const int protocol);
62857 +
62858 +#endif
62859 diff --git a/include/linux/hid.h b/include/linux/hid.h
62860 index c076041..6f54d73 100644
62861 --- a/include/linux/hid.h
62862 +++ b/include/linux/hid.h
62863 @@ -671,7 +671,7 @@ struct hid_ll_driver {
62864 unsigned int code, int value);
62865
62866 int (*parse)(struct hid_device *hdev);
62867 -};
62868 +} __no_const;
62869
62870 #define PM_HINT_FULLON 1<<5
62871 #define PM_HINT_NORMAL 1<<1
62872 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62873 index ef788b5..ac41b7b 100644
62874 --- a/include/linux/highmem.h
62875 +++ b/include/linux/highmem.h
62876 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62877 kunmap_atomic(kaddr);
62878 }
62879
62880 +static inline void sanitize_highpage(struct page *page)
62881 +{
62882 + void *kaddr;
62883 + unsigned long flags;
62884 +
62885 + local_irq_save(flags);
62886 + kaddr = kmap_atomic(page);
62887 + clear_page(kaddr);
62888 + kunmap_atomic(kaddr);
62889 + local_irq_restore(flags);
62890 +}
62891 +
62892 static inline void zero_user_segments(struct page *page,
62893 unsigned start1, unsigned end1,
62894 unsigned start2, unsigned end2)
62895 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62896 index 800de22..7a2fa46 100644
62897 --- a/include/linux/i2c.h
62898 +++ b/include/linux/i2c.h
62899 @@ -367,6 +367,7 @@ struct i2c_algorithm {
62900 /* To determine what the adapter supports */
62901 u32 (*functionality) (struct i2c_adapter *);
62902 };
62903 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62904
62905 /*
62906 * i2c_adapter is the structure used to identify a physical i2c bus along
62907 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62908 index d23c3c2..eb63c81 100644
62909 --- a/include/linux/i2o.h
62910 +++ b/include/linux/i2o.h
62911 @@ -565,7 +565,7 @@ struct i2o_controller {
62912 struct i2o_device *exec; /* Executive */
62913 #if BITS_PER_LONG == 64
62914 spinlock_t context_list_lock; /* lock for context_list */
62915 - atomic_t context_list_counter; /* needed for unique contexts */
62916 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62917 struct list_head context_list; /* list of context id's
62918 and pointers */
62919 #endif
62920 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62921 index 0245def..1199c5a 100644
62922 --- a/include/linux/if_team.h
62923 +++ b/include/linux/if_team.h
62924 @@ -111,6 +111,7 @@ struct team_mode_ops {
62925 void (*port_enabled)(struct team *team, struct team_port *port);
62926 void (*port_disabled)(struct team *team, struct team_port *port);
62927 };
62928 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62929
62930 enum team_option_type {
62931 TEAM_OPTION_TYPE_U32,
62932 @@ -185,7 +186,7 @@ struct team {
62933 struct list_head option_inst_list; /* list of option instances */
62934
62935 const struct team_mode *mode;
62936 - struct team_mode_ops ops;
62937 + team_mode_ops_no_const ops;
62938 bool queue_override_enabled;
62939 struct list_head *qom_lists; /* array of queue override mapping lists */
62940 long mode_priv[TEAM_MODE_PRIV_LONGS];
62941 diff --git a/include/linux/init.h b/include/linux/init.h
62942 index e59041e..df0a975 100644
62943 --- a/include/linux/init.h
62944 +++ b/include/linux/init.h
62945 @@ -39,9 +39,36 @@
62946 * Also note, that this data cannot be "const".
62947 */
62948
62949 +#ifdef MODULE
62950 +#define add_init_latent_entropy
62951 +#define add_devinit_latent_entropy
62952 +#define add_cpuinit_latent_entropy
62953 +#define add_meminit_latent_entropy
62954 +#else
62955 +#define add_init_latent_entropy __latent_entropy
62956 +
62957 +#ifdef CONFIG_HOTPLUG
62958 +#define add_devinit_latent_entropy
62959 +#else
62960 +#define add_devinit_latent_entropy __latent_entropy
62961 +#endif
62962 +
62963 +#ifdef CONFIG_HOTPLUG_CPU
62964 +#define add_cpuinit_latent_entropy
62965 +#else
62966 +#define add_cpuinit_latent_entropy __latent_entropy
62967 +#endif
62968 +
62969 +#ifdef CONFIG_MEMORY_HOTPLUG
62970 +#define add_meminit_latent_entropy
62971 +#else
62972 +#define add_meminit_latent_entropy __latent_entropy
62973 +#endif
62974 +#endif
62975 +
62976 /* These are for everybody (although not all archs will actually
62977 discard it in modules) */
62978 -#define __init __section(.init.text) __cold notrace
62979 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
62980 #define __initdata __section(.init.data)
62981 #define __initconst __constsection(.init.rodata)
62982 #define __exitdata __section(.exit.data)
62983 @@ -94,7 +121,7 @@
62984 #define __exit __section(.exit.text) __exitused __cold notrace
62985
62986 /* Used for HOTPLUG */
62987 -#define __devinit __section(.devinit.text) __cold notrace
62988 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
62989 #define __devinitdata __section(.devinit.data)
62990 #define __devinitconst __constsection(.devinit.rodata)
62991 #define __devexit __section(.devexit.text) __exitused __cold notrace
62992 @@ -102,7 +129,7 @@
62993 #define __devexitconst __constsection(.devexit.rodata)
62994
62995 /* Used for HOTPLUG_CPU */
62996 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62997 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
62998 #define __cpuinitdata __section(.cpuinit.data)
62999 #define __cpuinitconst __constsection(.cpuinit.rodata)
63000 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63001 @@ -110,7 +137,7 @@
63002 #define __cpuexitconst __constsection(.cpuexit.rodata)
63003
63004 /* Used for MEMORY_HOTPLUG */
63005 -#define __meminit __section(.meminit.text) __cold notrace
63006 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63007 #define __meminitdata __section(.meminit.data)
63008 #define __meminitconst __constsection(.meminit.rodata)
63009 #define __memexit __section(.memexit.text) __exitused __cold notrace
63010 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63011 index 6d087c5..401cab8 100644
63012 --- a/include/linux/init_task.h
63013 +++ b/include/linux/init_task.h
63014 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63015
63016 #define INIT_TASK_COMM "swapper"
63017
63018 +#ifdef CONFIG_X86
63019 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63020 +#else
63021 +#define INIT_TASK_THREAD_INFO
63022 +#endif
63023 +
63024 /*
63025 * INIT_TASK is used to set up the first task table, touch at
63026 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63027 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63028 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63029 .comm = INIT_TASK_COMM, \
63030 .thread = INIT_THREAD, \
63031 + INIT_TASK_THREAD_INFO \
63032 .fs = &init_fs, \
63033 .files = &init_files, \
63034 .signal = &init_signals, \
63035 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63036 index 78e2ada..745564d 100644
63037 --- a/include/linux/intel-iommu.h
63038 +++ b/include/linux/intel-iommu.h
63039 @@ -296,7 +296,7 @@ struct iommu_flush {
63040 u8 fm, u64 type);
63041 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63042 unsigned int size_order, u64 type);
63043 -};
63044 +} __no_const;
63045
63046 enum {
63047 SR_DMAR_FECTL_REG,
63048 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63049 index 5e4e617..eee383d 100644
63050 --- a/include/linux/interrupt.h
63051 +++ b/include/linux/interrupt.h
63052 @@ -435,7 +435,7 @@ enum
63053 /* map softirq index to softirq name. update 'softirq_to_name' in
63054 * kernel/softirq.c when adding a new softirq.
63055 */
63056 -extern char *softirq_to_name[NR_SOFTIRQS];
63057 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63058
63059 /* softirq mask and active fields moved to irq_cpustat_t in
63060 * asm/hardirq.h to get better cache usage. KAO
63061 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63062
63063 struct softirq_action
63064 {
63065 - void (*action)(struct softirq_action *);
63066 + void (*action)(void);
63067 };
63068
63069 asmlinkage void do_softirq(void);
63070 asmlinkage void __do_softirq(void);
63071 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63072 +extern void open_softirq(int nr, void (*action)(void));
63073 extern void softirq_init(void);
63074 extern void __raise_softirq_irqoff(unsigned int nr);
63075
63076 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63077 index 6883e19..06992b1 100644
63078 --- a/include/linux/kallsyms.h
63079 +++ b/include/linux/kallsyms.h
63080 @@ -15,7 +15,8 @@
63081
63082 struct module;
63083
63084 -#ifdef CONFIG_KALLSYMS
63085 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63086 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63087 /* Lookup the address for a symbol. Returns 0 if not found. */
63088 unsigned long kallsyms_lookup_name(const char *name);
63089
63090 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63091 /* Stupid that this does nothing, but I didn't create this mess. */
63092 #define __print_symbol(fmt, addr)
63093 #endif /*CONFIG_KALLSYMS*/
63094 +#else /* when included by kallsyms.c, vsnprintf.c, or
63095 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63096 +extern void __print_symbol(const char *fmt, unsigned long address);
63097 +extern int sprint_backtrace(char *buffer, unsigned long address);
63098 +extern int sprint_symbol(char *buffer, unsigned long address);
63099 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63100 +const char *kallsyms_lookup(unsigned long addr,
63101 + unsigned long *symbolsize,
63102 + unsigned long *offset,
63103 + char **modname, char *namebuf);
63104 +#endif
63105
63106 /* This macro allows us to keep printk typechecking */
63107 static __printf(1, 2)
63108 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63109 index 4dff0c6..1ca9b72 100644
63110 --- a/include/linux/kgdb.h
63111 +++ b/include/linux/kgdb.h
63112 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63113 extern int kgdb_io_module_registered;
63114
63115 extern atomic_t kgdb_setting_breakpoint;
63116 -extern atomic_t kgdb_cpu_doing_single_step;
63117 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63118
63119 extern struct task_struct *kgdb_usethread;
63120 extern struct task_struct *kgdb_contthread;
63121 @@ -255,7 +255,7 @@ struct kgdb_arch {
63122 void (*correct_hw_break)(void);
63123
63124 void (*enable_nmi)(bool on);
63125 -};
63126 +} __do_const;
63127
63128 /**
63129 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63130 @@ -280,7 +280,7 @@ struct kgdb_io {
63131 void (*pre_exception) (void);
63132 void (*post_exception) (void);
63133 int is_console;
63134 -};
63135 +} __do_const;
63136
63137 extern struct kgdb_arch arch_kgdb_ops;
63138
63139 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63140 index 5398d58..5883a34 100644
63141 --- a/include/linux/kmod.h
63142 +++ b/include/linux/kmod.h
63143 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63144 * usually useless though. */
63145 extern __printf(2, 3)
63146 int __request_module(bool wait, const char *name, ...);
63147 +extern __printf(3, 4)
63148 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63149 #define request_module(mod...) __request_module(true, mod)
63150 #define request_module_nowait(mod...) __request_module(false, mod)
63151 #define try_then_request_module(x, mod...) \
63152 diff --git a/include/linux/kref.h b/include/linux/kref.h
63153 index 65af688..0592677 100644
63154 --- a/include/linux/kref.h
63155 +++ b/include/linux/kref.h
63156 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63157 static inline int kref_sub(struct kref *kref, unsigned int count,
63158 void (*release)(struct kref *kref))
63159 {
63160 - WARN_ON(release == NULL);
63161 + BUG_ON(release == NULL);
63162
63163 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63164 release(kref);
63165 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63166 index ecc5543..0e96bcc 100644
63167 --- a/include/linux/kvm_host.h
63168 +++ b/include/linux/kvm_host.h
63169 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63170 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
63171 void vcpu_put(struct kvm_vcpu *vcpu);
63172
63173 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63174 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63175 struct module *module);
63176 void kvm_exit(void);
63177
63178 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63179 struct kvm_guest_debug *dbg);
63180 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63181
63182 -int kvm_arch_init(void *opaque);
63183 +int kvm_arch_init(const void *opaque);
63184 void kvm_arch_exit(void);
63185
63186 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63187 diff --git a/include/linux/libata.h b/include/linux/libata.h
63188 index 77eeeda..062ed69c 100644
63189 --- a/include/linux/libata.h
63190 +++ b/include/linux/libata.h
63191 @@ -914,7 +914,7 @@ struct ata_port_operations {
63192 * fields must be pointers.
63193 */
63194 const struct ata_port_operations *inherits;
63195 -};
63196 +} __do_const;
63197
63198 struct ata_port_info {
63199 unsigned long flags;
63200 diff --git a/include/linux/memory.h b/include/linux/memory.h
63201 index ff9a9f8..c715deb 100644
63202 --- a/include/linux/memory.h
63203 +++ b/include/linux/memory.h
63204 @@ -143,7 +143,7 @@ struct memory_accessor {
63205 size_t count);
63206 ssize_t (*write)(struct memory_accessor *, const char *buf,
63207 off_t offset, size_t count);
63208 -};
63209 +} __no_const;
63210
63211 /*
63212 * Kernel text modification mutex, used for code patching. Users of this lock
63213 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63214 index 5d5298d..e3e5a2e 100644
63215 --- a/include/linux/mfd/abx500.h
63216 +++ b/include/linux/mfd/abx500.h
63217 @@ -337,6 +337,7 @@ struct abx500_ops {
63218 int (*event_registers_startup_state_get) (struct device *, u8 *);
63219 int (*startup_irq_enabled) (struct device *, unsigned int);
63220 };
63221 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63222
63223 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63224 void abx500_remove_ops(struct device *dev);
63225 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63226 index 9b07725..3d55001 100644
63227 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63228 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63229 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63230 int (*enable) (struct ux500_charger *, int, int, int);
63231 int (*kick_wd) (struct ux500_charger *);
63232 int (*update_curr) (struct ux500_charger *, int);
63233 -};
63234 +} __no_const;
63235
63236 /**
63237 * struct ux500_charger - power supply ux500 charger sub class
63238 diff --git a/include/linux/mm.h b/include/linux/mm.h
63239 index bcaab4e..f842186 100644
63240 --- a/include/linux/mm.h
63241 +++ b/include/linux/mm.h
63242 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
63243 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
63244 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
63245 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
63246 +
63247 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63248 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
63249 +#endif
63250 +
63251 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
63252
63253 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63254 @@ -1040,34 +1045,6 @@ int set_page_dirty(struct page *page);
63255 int set_page_dirty_lock(struct page *page);
63256 int clear_page_dirty_for_io(struct page *page);
63257
63258 -/* Is the vma a continuation of the stack vma above it? */
63259 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63260 -{
63261 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63262 -}
63263 -
63264 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63265 - unsigned long addr)
63266 -{
63267 - return (vma->vm_flags & VM_GROWSDOWN) &&
63268 - (vma->vm_start == addr) &&
63269 - !vma_growsdown(vma->vm_prev, addr);
63270 -}
63271 -
63272 -/* Is the vma a continuation of the stack vma below it? */
63273 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63274 -{
63275 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63276 -}
63277 -
63278 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63279 - unsigned long addr)
63280 -{
63281 - return (vma->vm_flags & VM_GROWSUP) &&
63282 - (vma->vm_end == addr) &&
63283 - !vma_growsup(vma->vm_next, addr);
63284 -}
63285 -
63286 extern pid_t
63287 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63288
63289 @@ -1167,6 +1144,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63290 }
63291 #endif
63292
63293 +#ifdef CONFIG_MMU
63294 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63295 +#else
63296 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63297 +{
63298 + return __pgprot(0);
63299 +}
63300 +#endif
63301 +
63302 int vma_wants_writenotify(struct vm_area_struct *vma);
63303
63304 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63305 @@ -1185,8 +1171,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63306 {
63307 return 0;
63308 }
63309 +
63310 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63311 + unsigned long address)
63312 +{
63313 + return 0;
63314 +}
63315 #else
63316 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63317 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63318 #endif
63319
63320 #ifdef __PAGETABLE_PMD_FOLDED
63321 @@ -1195,8 +1188,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63322 {
63323 return 0;
63324 }
63325 +
63326 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63327 + unsigned long address)
63328 +{
63329 + return 0;
63330 +}
63331 #else
63332 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63333 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63334 #endif
63335
63336 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63337 @@ -1214,11 +1214,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63338 NULL: pud_offset(pgd, address);
63339 }
63340
63341 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63342 +{
63343 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63344 + NULL: pud_offset(pgd, address);
63345 +}
63346 +
63347 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63348 {
63349 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63350 NULL: pmd_offset(pud, address);
63351 }
63352 +
63353 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63354 +{
63355 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63356 + NULL: pmd_offset(pud, address);
63357 +}
63358 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63359
63360 #if USE_SPLIT_PTLOCKS
63361 @@ -1448,6 +1460,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63362 unsigned long, unsigned long,
63363 unsigned long, unsigned long);
63364 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63365 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63366
63367 /* These take the mm semaphore themselves */
63368 extern unsigned long vm_brk(unsigned long, unsigned long);
63369 @@ -1511,6 +1524,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63370 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63371 struct vm_area_struct **pprev);
63372
63373 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63374 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63375 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63376 +
63377 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63378 NULL if none. Assume start_addr < end_addr. */
63379 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63380 @@ -1539,15 +1556,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63381 return vma;
63382 }
63383
63384 -#ifdef CONFIG_MMU
63385 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63386 -#else
63387 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63388 -{
63389 - return __pgprot(0);
63390 -}
63391 -#endif
63392 -
63393 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63394 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63395 unsigned long pfn, unsigned long size, pgprot_t);
63396 @@ -1653,7 +1661,7 @@ extern int unpoison_memory(unsigned long pfn);
63397 extern int sysctl_memory_failure_early_kill;
63398 extern int sysctl_memory_failure_recovery;
63399 extern void shake_page(struct page *p, int access);
63400 -extern atomic_long_t mce_bad_pages;
63401 +extern atomic_long_unchecked_t mce_bad_pages;
63402 extern int soft_offline_page(struct page *page, int flags);
63403
63404 extern void dump_page(struct page *page);
63405 @@ -1684,5 +1692,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63406 static inline bool page_is_guard(struct page *page) { return false; }
63407 #endif /* CONFIG_DEBUG_PAGEALLOC */
63408
63409 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63410 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63411 +#else
63412 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63413 +#endif
63414 +
63415 #endif /* __KERNEL__ */
63416 #endif /* _LINUX_MM_H */
63417 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63418 index 31f8a3a..499f1db 100644
63419 --- a/include/linux/mm_types.h
63420 +++ b/include/linux/mm_types.h
63421 @@ -275,6 +275,8 @@ struct vm_area_struct {
63422 #ifdef CONFIG_NUMA
63423 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63424 #endif
63425 +
63426 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63427 };
63428
63429 struct core_thread {
63430 @@ -348,7 +350,7 @@ struct mm_struct {
63431 unsigned long def_flags;
63432 unsigned long nr_ptes; /* Page table pages */
63433 unsigned long start_code, end_code, start_data, end_data;
63434 - unsigned long start_brk, brk, start_stack;
63435 + unsigned long brk_gap, start_brk, brk, start_stack;
63436 unsigned long arg_start, arg_end, env_start, env_end;
63437
63438 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63439 @@ -399,6 +401,24 @@ struct mm_struct {
63440 struct cpumask cpumask_allocation;
63441 #endif
63442 struct uprobes_state uprobes_state;
63443 +
63444 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63445 + unsigned long pax_flags;
63446 +#endif
63447 +
63448 +#ifdef CONFIG_PAX_DLRESOLVE
63449 + unsigned long call_dl_resolve;
63450 +#endif
63451 +
63452 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63453 + unsigned long call_syscall;
63454 +#endif
63455 +
63456 +#ifdef CONFIG_PAX_ASLR
63457 + unsigned long delta_mmap; /* randomized offset */
63458 + unsigned long delta_stack; /* randomized offset */
63459 +#endif
63460 +
63461 };
63462
63463 static inline void mm_init_cpumask(struct mm_struct *mm)
63464 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63465 index a23923b..073fee4 100644
63466 --- a/include/linux/mmzone.h
63467 +++ b/include/linux/mmzone.h
63468 @@ -421,7 +421,7 @@ struct zone {
63469 unsigned long flags; /* zone flags, see below */
63470
63471 /* Zone statistics */
63472 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63473 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63474
63475 /*
63476 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63477 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63478 index fed3def..7cc3f93 100644
63479 --- a/include/linux/mod_devicetable.h
63480 +++ b/include/linux/mod_devicetable.h
63481 @@ -12,7 +12,7 @@
63482 typedef unsigned long kernel_ulong_t;
63483 #endif
63484
63485 -#define PCI_ANY_ID (~0)
63486 +#define PCI_ANY_ID ((__u16)~0)
63487
63488 struct pci_device_id {
63489 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63490 @@ -139,7 +139,7 @@ struct usb_device_id {
63491 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63492 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63493
63494 -#define HID_ANY_ID (~0)
63495 +#define HID_ANY_ID (~0U)
63496 #define HID_BUS_ANY 0xffff
63497 #define HID_GROUP_ANY 0x0000
63498
63499 diff --git a/include/linux/module.h b/include/linux/module.h
63500 index 7760c6d..07a2d3d 100644
63501 --- a/include/linux/module.h
63502 +++ b/include/linux/module.h
63503 @@ -17,6 +17,7 @@
63504 #include <linux/moduleparam.h>
63505 #include <linux/tracepoint.h>
63506 #include <linux/export.h>
63507 +#include <linux/fs.h>
63508
63509 #include <linux/percpu.h>
63510 #include <asm/module.h>
63511 @@ -281,19 +282,16 @@ struct module
63512 int (*init)(void);
63513
63514 /* If this is non-NULL, vfree after init() returns */
63515 - void *module_init;
63516 + void *module_init_rx, *module_init_rw;
63517
63518 /* Here is the actual code + data, vfree'd on unload. */
63519 - void *module_core;
63520 + void *module_core_rx, *module_core_rw;
63521
63522 /* Here are the sizes of the init and core sections */
63523 - unsigned int init_size, core_size;
63524 + unsigned int init_size_rw, core_size_rw;
63525
63526 /* The size of the executable code in each section. */
63527 - unsigned int init_text_size, core_text_size;
63528 -
63529 - /* Size of RO sections of the module (text+rodata) */
63530 - unsigned int init_ro_size, core_ro_size;
63531 + unsigned int init_size_rx, core_size_rx;
63532
63533 /* Arch-specific module values */
63534 struct mod_arch_specific arch;
63535 @@ -349,6 +347,10 @@ struct module
63536 #ifdef CONFIG_EVENT_TRACING
63537 struct ftrace_event_call **trace_events;
63538 unsigned int num_trace_events;
63539 + struct file_operations trace_id;
63540 + struct file_operations trace_enable;
63541 + struct file_operations trace_format;
63542 + struct file_operations trace_filter;
63543 #endif
63544 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63545 unsigned int num_ftrace_callsites;
63546 @@ -396,16 +398,46 @@ bool is_module_address(unsigned long addr);
63547 bool is_module_percpu_address(unsigned long addr);
63548 bool is_module_text_address(unsigned long addr);
63549
63550 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63551 +{
63552 +
63553 +#ifdef CONFIG_PAX_KERNEXEC
63554 + if (ktla_ktva(addr) >= (unsigned long)start &&
63555 + ktla_ktva(addr) < (unsigned long)start + size)
63556 + return 1;
63557 +#endif
63558 +
63559 + return ((void *)addr >= start && (void *)addr < start + size);
63560 +}
63561 +
63562 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63563 +{
63564 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63565 +}
63566 +
63567 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63568 +{
63569 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63570 +}
63571 +
63572 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63573 +{
63574 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63575 +}
63576 +
63577 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63578 +{
63579 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63580 +}
63581 +
63582 static inline int within_module_core(unsigned long addr, struct module *mod)
63583 {
63584 - return (unsigned long)mod->module_core <= addr &&
63585 - addr < (unsigned long)mod->module_core + mod->core_size;
63586 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63587 }
63588
63589 static inline int within_module_init(unsigned long addr, struct module *mod)
63590 {
63591 - return (unsigned long)mod->module_init <= addr &&
63592 - addr < (unsigned long)mod->module_init + mod->init_size;
63593 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63594 }
63595
63596 /* Search for module by name: must hold module_mutex. */
63597 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63598 index 560ca53..16968cc 100644
63599 --- a/include/linux/moduleloader.h
63600 +++ b/include/linux/moduleloader.h
63601 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63602
63603 /* Allocator used for allocating struct module, core sections and init
63604 sections. Returns NULL on failure. */
63605 -void *module_alloc(unsigned long size);
63606 +void *module_alloc(unsigned long size) __size_overflow(1);
63607 +
63608 +#ifdef CONFIG_PAX_KERNEXEC
63609 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63610 +#else
63611 +#define module_alloc_exec(x) module_alloc(x)
63612 +#endif
63613
63614 /* Free memory returned from module_alloc. */
63615 void module_free(struct module *mod, void *module_region);
63616
63617 +#ifdef CONFIG_PAX_KERNEXEC
63618 +void module_free_exec(struct module *mod, void *module_region);
63619 +#else
63620 +#define module_free_exec(x, y) module_free((x), (y))
63621 +#endif
63622 +
63623 /*
63624 * Apply the given relocation to the (simplified) ELF. Return -error
63625 * or 0.
63626 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63627 index d6a5806..7c13347 100644
63628 --- a/include/linux/moduleparam.h
63629 +++ b/include/linux/moduleparam.h
63630 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63631 * @len is usually just sizeof(string).
63632 */
63633 #define module_param_string(name, string, len, perm) \
63634 - static const struct kparam_string __param_string_##name \
63635 + static const struct kparam_string __param_string_##name __used \
63636 = { len, string }; \
63637 __module_param_call(MODULE_PARAM_PREFIX, name, \
63638 &param_ops_string, \
63639 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63640 */
63641 #define module_param_array_named(name, array, type, nump, perm) \
63642 param_check_##type(name, &(array)[0]); \
63643 - static const struct kparam_array __param_arr_##name \
63644 + static const struct kparam_array __param_arr_##name __used \
63645 = { .max = ARRAY_SIZE(array), .num = nump, \
63646 .ops = &param_ops_##type, \
63647 .elemsize = sizeof(array[0]), .elem = array }; \
63648 diff --git a/include/linux/namei.h b/include/linux/namei.h
63649 index 4bf19d8..5268cea 100644
63650 --- a/include/linux/namei.h
63651 +++ b/include/linux/namei.h
63652 @@ -18,7 +18,7 @@ struct nameidata {
63653 unsigned seq;
63654 int last_type;
63655 unsigned depth;
63656 - char *saved_names[MAX_NESTED_LINKS + 1];
63657 + const char *saved_names[MAX_NESTED_LINKS + 1];
63658 };
63659
63660 /*
63661 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63662
63663 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63664
63665 -static inline void nd_set_link(struct nameidata *nd, char *path)
63666 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63667 {
63668 nd->saved_names[nd->depth] = path;
63669 }
63670
63671 -static inline char *nd_get_link(struct nameidata *nd)
63672 +static inline const char *nd_get_link(const struct nameidata *nd)
63673 {
63674 return nd->saved_names[nd->depth];
63675 }
63676 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63677 index a848ffc..3bbbaee 100644
63678 --- a/include/linux/netdevice.h
63679 +++ b/include/linux/netdevice.h
63680 @@ -999,6 +999,7 @@ struct net_device_ops {
63681 struct net_device *dev,
63682 int idx);
63683 };
63684 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63685
63686 /*
63687 * The DEVICE structure.
63688 @@ -1059,7 +1060,7 @@ struct net_device {
63689 int iflink;
63690
63691 struct net_device_stats stats;
63692 - atomic_long_t rx_dropped; /* dropped packets by core network
63693 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63694 * Do not use this in drivers.
63695 */
63696
63697 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63698 new file mode 100644
63699 index 0000000..33f4af8
63700 --- /dev/null
63701 +++ b/include/linux/netfilter/xt_gradm.h
63702 @@ -0,0 +1,9 @@
63703 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63704 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63705 +
63706 +struct xt_gradm_mtinfo {
63707 + __u16 flags;
63708 + __u16 invflags;
63709 +};
63710 +
63711 +#endif
63712 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63713 index c65a18a..0c05f3a 100644
63714 --- a/include/linux/of_pdt.h
63715 +++ b/include/linux/of_pdt.h
63716 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63717
63718 /* return 0 on success; fill in 'len' with number of bytes in path */
63719 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63720 -};
63721 +} __no_const;
63722
63723 extern void *prom_early_alloc(unsigned long size);
63724
63725 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63726 index a4c5624..79d6d88 100644
63727 --- a/include/linux/oprofile.h
63728 +++ b/include/linux/oprofile.h
63729 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63730 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63731 char const * name, ulong * val);
63732
63733 -/** Create a file for read-only access to an atomic_t. */
63734 +/** Create a file for read-only access to an atomic_unchecked_t. */
63735 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63736 - char const * name, atomic_t * val);
63737 + char const * name, atomic_unchecked_t * val);
63738
63739 /** create a directory */
63740 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63741 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63742 index 6bfb2faa..1204767 100644
63743 --- a/include/linux/perf_event.h
63744 +++ b/include/linux/perf_event.h
63745 @@ -328,8 +328,8 @@ struct perf_event {
63746
63747 enum perf_event_active_state state;
63748 unsigned int attach_state;
63749 - local64_t count;
63750 - atomic64_t child_count;
63751 + local64_t count; /* PaX: fix it one day */
63752 + atomic64_unchecked_t child_count;
63753
63754 /*
63755 * These are the total time in nanoseconds that the event
63756 @@ -380,8 +380,8 @@ struct perf_event {
63757 * These accumulate total time (in nanoseconds) that children
63758 * events have been enabled and running, respectively.
63759 */
63760 - atomic64_t child_total_time_enabled;
63761 - atomic64_t child_total_time_running;
63762 + atomic64_unchecked_t child_total_time_enabled;
63763 + atomic64_unchecked_t child_total_time_running;
63764
63765 /*
63766 * Protect attach/detach and child_list:
63767 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63768 index ad1a427..6419649 100644
63769 --- a/include/linux/pipe_fs_i.h
63770 +++ b/include/linux/pipe_fs_i.h
63771 @@ -45,9 +45,9 @@ struct pipe_buffer {
63772 struct pipe_inode_info {
63773 wait_queue_head_t wait;
63774 unsigned int nrbufs, curbuf, buffers;
63775 - unsigned int readers;
63776 - unsigned int writers;
63777 - unsigned int waiting_writers;
63778 + atomic_t readers;
63779 + atomic_t writers;
63780 + atomic_t waiting_writers;
63781 unsigned int r_counter;
63782 unsigned int w_counter;
63783 struct page *tmp_page;
63784 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
63785 index 5f28cae..3d23723 100644
63786 --- a/include/linux/platform_data/usb-ehci-s5p.h
63787 +++ b/include/linux/platform_data/usb-ehci-s5p.h
63788 @@ -14,7 +14,7 @@
63789 struct s5p_ehci_platdata {
63790 int (*phy_init)(struct platform_device *pdev, int type);
63791 int (*phy_exit)(struct platform_device *pdev, int type);
63792 -};
63793 +} __no_const;
63794
63795 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
63796
63797 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63798 index f271860..6b3bec5 100644
63799 --- a/include/linux/pm_runtime.h
63800 +++ b/include/linux/pm_runtime.h
63801 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63802
63803 static inline void pm_runtime_mark_last_busy(struct device *dev)
63804 {
63805 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63806 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63807 }
63808
63809 #else /* !CONFIG_PM_RUNTIME */
63810 diff --git a/include/linux/poison.h b/include/linux/poison.h
63811 index 2110a81..13a11bb 100644
63812 --- a/include/linux/poison.h
63813 +++ b/include/linux/poison.h
63814 @@ -19,8 +19,8 @@
63815 * under normal circumstances, used to verify that nobody uses
63816 * non-initialized list entries.
63817 */
63818 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63819 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63820 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63821 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63822
63823 /********** include/linux/timer.h **********/
63824 /*
63825 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63826 index 5a710b9..0b0dab9 100644
63827 --- a/include/linux/preempt.h
63828 +++ b/include/linux/preempt.h
63829 @@ -126,7 +126,7 @@ struct preempt_ops {
63830 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63831 void (*sched_out)(struct preempt_notifier *notifier,
63832 struct task_struct *next);
63833 -};
63834 +} __no_const;
63835
63836 /**
63837 * preempt_notifier - key for installing preemption notifiers
63838 diff --git a/include/linux/printk.h b/include/linux/printk.h
63839 index 9afc01e..92c32e8 100644
63840 --- a/include/linux/printk.h
63841 +++ b/include/linux/printk.h
63842 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63843 extern int printk_needs_cpu(int cpu);
63844 extern void printk_tick(void);
63845
63846 +extern int kptr_restrict;
63847 +
63848 #ifdef CONFIG_PRINTK
63849 asmlinkage __printf(5, 0)
63850 int vprintk_emit(int facility, int level,
63851 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63852
63853 extern int printk_delay_msec;
63854 extern int dmesg_restrict;
63855 -extern int kptr_restrict;
63856
63857 void log_buf_kexec_setup(void);
63858 void __init setup_log_buf(int early);
63859 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63860 index 3fd2e87..d93a721 100644
63861 --- a/include/linux/proc_fs.h
63862 +++ b/include/linux/proc_fs.h
63863 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63864 return proc_create_data(name, mode, parent, proc_fops, NULL);
63865 }
63866
63867 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63868 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63869 +{
63870 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63871 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63872 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63873 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63874 +#else
63875 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63876 +#endif
63877 +}
63878 +
63879 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63880 umode_t mode, struct proc_dir_entry *base,
63881 read_proc_t *read_proc, void * data)
63882 @@ -258,7 +270,7 @@ union proc_op {
63883 int (*proc_show)(struct seq_file *m,
63884 struct pid_namespace *ns, struct pid *pid,
63885 struct task_struct *task);
63886 -};
63887 +} __no_const;
63888
63889 struct ctl_table_header;
63890 struct ctl_table;
63891 diff --git a/include/linux/random.h b/include/linux/random.h
63892 index 6330ed4..6faf63b 100644
63893 --- a/include/linux/random.h
63894 +++ b/include/linux/random.h
63895 @@ -14,6 +14,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63896 unsigned int value);
63897 extern void add_interrupt_randomness(int irq, int irq_flags);
63898
63899 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63900 +extern void transfer_latent_entropy(void);
63901 +#endif
63902 +
63903 extern void get_random_bytes(void *buf, int nbytes);
63904 extern void get_random_bytes_arch(void *buf, int nbytes);
63905 void generate_random_uuid(unsigned char uuid_out[16]);
63906 @@ -30,12 +34,17 @@ void srandom32(u32 seed);
63907
63908 u32 prandom32(struct rnd_state *);
63909
63910 +static inline unsigned long pax_get_random_long(void)
63911 +{
63912 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63913 +}
63914 +
63915 /*
63916 * Handle minimum values for seeds
63917 */
63918 static inline u32 __seed(u32 x, u32 m)
63919 {
63920 - return (x < m) ? x + m : x;
63921 + return (x <= m) ? x + m + 1 : x;
63922 }
63923
63924 /**
63925 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63926 index 23b3630..e1bc12b 100644
63927 --- a/include/linux/reboot.h
63928 +++ b/include/linux/reboot.h
63929 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63930 * Architecture-specific implementations of sys_reboot commands.
63931 */
63932
63933 -extern void machine_restart(char *cmd);
63934 -extern void machine_halt(void);
63935 -extern void machine_power_off(void);
63936 +extern void machine_restart(char *cmd) __noreturn;
63937 +extern void machine_halt(void) __noreturn;
63938 +extern void machine_power_off(void) __noreturn;
63939
63940 extern void machine_shutdown(void);
63941 struct pt_regs;
63942 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63943 */
63944
63945 extern void kernel_restart_prepare(char *cmd);
63946 -extern void kernel_restart(char *cmd);
63947 -extern void kernel_halt(void);
63948 -extern void kernel_power_off(void);
63949 +extern void kernel_restart(char *cmd) __noreturn;
63950 +extern void kernel_halt(void) __noreturn;
63951 +extern void kernel_power_off(void) __noreturn;
63952
63953 extern int C_A_D; /* for sysctl */
63954 void ctrl_alt_del(void);
63955 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
63956 * Emergency restart, callable from an interrupt handler.
63957 */
63958
63959 -extern void emergency_restart(void);
63960 +extern void emergency_restart(void) __noreturn;
63961 #include <asm/emergency-restart.h>
63962
63963 #endif /* _LINUX_REBOOT_H */
63964 diff --git a/include/linux/relay.h b/include/linux/relay.h
63965 index 91cacc3..b55ff74 100644
63966 --- a/include/linux/relay.h
63967 +++ b/include/linux/relay.h
63968 @@ -160,7 +160,7 @@ struct rchan_callbacks
63969 * The callback should return 0 if successful, negative if not.
63970 */
63971 int (*remove_buf_file)(struct dentry *dentry);
63972 -};
63973 +} __no_const;
63974
63975 /*
63976 * CONFIG_RELAY kernel API, kernel/relay.c
63977 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63978 index d901078..0b7d00e 100644
63979 --- a/include/linux/rfkill.h
63980 +++ b/include/linux/rfkill.h
63981 @@ -63,6 +63,7 @@ struct rfkill_ops {
63982 void (*query)(struct rfkill *rfkill, void *data);
63983 int (*set_block)(void *data, bool blocked);
63984 };
63985 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63986
63987 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63988 /**
63989 diff --git a/include/linux/rio.h b/include/linux/rio.h
63990 index a3e7842..d973ca6 100644
63991 --- a/include/linux/rio.h
63992 +++ b/include/linux/rio.h
63993 @@ -339,7 +339,7 @@ struct rio_ops {
63994 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
63995 u64 rstart, u32 size, u32 flags);
63996 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
63997 -};
63998 +} __no_const;
63999
64000 #define RIO_RESOURCE_MEM 0x00000100
64001 #define RIO_RESOURCE_DOORBELL 0x00000200
64002 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64003 index bfe1f47..6a33ee3 100644
64004 --- a/include/linux/rmap.h
64005 +++ b/include/linux/rmap.h
64006 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64007 void anon_vma_init(void); /* create anon_vma_cachep */
64008 int anon_vma_prepare(struct vm_area_struct *);
64009 void unlink_anon_vmas(struct vm_area_struct *);
64010 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64011 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64012 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64013 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64014
64015 static inline void anon_vma_merge(struct vm_area_struct *vma,
64016 struct vm_area_struct *next)
64017 diff --git a/include/linux/sched.h b/include/linux/sched.h
64018 index 0dd42a0..cc9bffb 100644
64019 --- a/include/linux/sched.h
64020 +++ b/include/linux/sched.h
64021 @@ -61,6 +61,7 @@ struct bio_list;
64022 struct fs_struct;
64023 struct perf_event_context;
64024 struct blk_plug;
64025 +struct linux_binprm;
64026
64027 /*
64028 * List of flags we want to share for kernel threads,
64029 @@ -344,10 +345,13 @@ struct user_namespace;
64030 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64031
64032 extern int sysctl_max_map_count;
64033 +extern unsigned long sysctl_heap_stack_gap;
64034
64035 #include <linux/aio.h>
64036
64037 #ifdef CONFIG_MMU
64038 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64039 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64040 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64041 extern unsigned long
64042 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64043 @@ -614,6 +618,17 @@ struct signal_struct {
64044 #ifdef CONFIG_TASKSTATS
64045 struct taskstats *stats;
64046 #endif
64047 +
64048 +#ifdef CONFIG_GRKERNSEC
64049 + u32 curr_ip;
64050 + u32 saved_ip;
64051 + u32 gr_saddr;
64052 + u32 gr_daddr;
64053 + u16 gr_sport;
64054 + u16 gr_dport;
64055 + u8 used_accept:1;
64056 +#endif
64057 +
64058 #ifdef CONFIG_AUDIT
64059 unsigned audit_tty;
64060 struct tty_audit_buf *tty_audit_buf;
64061 @@ -691,6 +706,11 @@ struct user_struct {
64062 struct key *session_keyring; /* UID's default session keyring */
64063 #endif
64064
64065 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64066 + unsigned int banned;
64067 + unsigned long ban_expires;
64068 +#endif
64069 +
64070 /* Hash table maintenance information */
64071 struct hlist_node uidhash_node;
64072 kuid_t uid;
64073 @@ -1312,8 +1332,8 @@ struct task_struct {
64074 struct list_head thread_group;
64075
64076 struct completion *vfork_done; /* for vfork() */
64077 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64078 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64079 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64080 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64081
64082 cputime_t utime, stime, utimescaled, stimescaled;
64083 cputime_t gtime;
64084 @@ -1329,11 +1349,6 @@ struct task_struct {
64085 struct task_cputime cputime_expires;
64086 struct list_head cpu_timers[3];
64087
64088 -/* process credentials */
64089 - const struct cred __rcu *real_cred; /* objective and real subjective task
64090 - * credentials (COW) */
64091 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64092 - * credentials (COW) */
64093 char comm[TASK_COMM_LEN]; /* executable name excluding path
64094 - access with [gs]et_task_comm (which lock
64095 it with task_lock())
64096 @@ -1350,6 +1365,10 @@ struct task_struct {
64097 #endif
64098 /* CPU-specific state of this task */
64099 struct thread_struct thread;
64100 +/* thread_info moved to task_struct */
64101 +#ifdef CONFIG_X86
64102 + struct thread_info tinfo;
64103 +#endif
64104 /* filesystem information */
64105 struct fs_struct *fs;
64106 /* open file information */
64107 @@ -1423,6 +1442,10 @@ struct task_struct {
64108 gfp_t lockdep_reclaim_gfp;
64109 #endif
64110
64111 +/* process credentials */
64112 + const struct cred __rcu *real_cred; /* objective and real subjective task
64113 + * credentials (COW) */
64114 +
64115 /* journalling filesystem info */
64116 void *journal_info;
64117
64118 @@ -1461,6 +1484,10 @@ struct task_struct {
64119 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64120 struct list_head cg_list;
64121 #endif
64122 +
64123 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64124 + * credentials (COW) */
64125 +
64126 #ifdef CONFIG_FUTEX
64127 struct robust_list_head __user *robust_list;
64128 #ifdef CONFIG_COMPAT
64129 @@ -1548,8 +1575,75 @@ struct task_struct {
64130 #ifdef CONFIG_UPROBES
64131 struct uprobe_task *utask;
64132 #endif
64133 +
64134 +#ifdef CONFIG_GRKERNSEC
64135 + /* grsecurity */
64136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64137 + u64 exec_id;
64138 +#endif
64139 +#ifdef CONFIG_GRKERNSEC_SETXID
64140 + const struct cred *delayed_cred;
64141 +#endif
64142 + struct dentry *gr_chroot_dentry;
64143 + struct acl_subject_label *acl;
64144 + struct acl_role_label *role;
64145 + struct file *exec_file;
64146 + unsigned long brute_expires;
64147 + u16 acl_role_id;
64148 + /* is this the task that authenticated to the special role */
64149 + u8 acl_sp_role;
64150 + u8 is_writable;
64151 + u8 brute;
64152 + u8 gr_is_chrooted;
64153 +#endif
64154 +
64155 };
64156
64157 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64158 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64159 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64160 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64161 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64162 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64163 +
64164 +#ifdef CONFIG_PAX_SOFTMODE
64165 +extern int pax_softmode;
64166 +#endif
64167 +
64168 +extern int pax_check_flags(unsigned long *);
64169 +
64170 +/* if tsk != current then task_lock must be held on it */
64171 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64172 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64173 +{
64174 + if (likely(tsk->mm))
64175 + return tsk->mm->pax_flags;
64176 + else
64177 + return 0UL;
64178 +}
64179 +
64180 +/* if tsk != current then task_lock must be held on it */
64181 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64182 +{
64183 + if (likely(tsk->mm)) {
64184 + tsk->mm->pax_flags = flags;
64185 + return 0;
64186 + }
64187 + return -EINVAL;
64188 +}
64189 +#endif
64190 +
64191 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64192 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64193 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64194 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64195 +#endif
64196 +
64197 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64198 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64199 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64200 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64201 +
64202 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64203 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64204
64205 @@ -2092,7 +2186,9 @@ void yield(void);
64206 extern struct exec_domain default_exec_domain;
64207
64208 union thread_union {
64209 +#ifndef CONFIG_X86
64210 struct thread_info thread_info;
64211 +#endif
64212 unsigned long stack[THREAD_SIZE/sizeof(long)];
64213 };
64214
64215 @@ -2125,6 +2221,7 @@ extern struct pid_namespace init_pid_ns;
64216 */
64217
64218 extern struct task_struct *find_task_by_vpid(pid_t nr);
64219 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64220 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64221 struct pid_namespace *ns);
64222
64223 @@ -2281,7 +2378,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64224 extern void exit_itimers(struct signal_struct *);
64225 extern void flush_itimer_signals(void);
64226
64227 -extern void do_group_exit(int);
64228 +extern __noreturn void do_group_exit(int);
64229
64230 extern void daemonize(const char *, ...);
64231 extern int allow_signal(int);
64232 @@ -2485,9 +2582,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64233
64234 #endif
64235
64236 -static inline int object_is_on_stack(void *obj)
64237 +static inline int object_starts_on_stack(void *obj)
64238 {
64239 - void *stack = task_stack_page(current);
64240 + const void *stack = task_stack_page(current);
64241
64242 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64243 }
64244 diff --git a/include/linux/security.h b/include/linux/security.h
64245 index 05e88bd..5cda002 100644
64246 --- a/include/linux/security.h
64247 +++ b/include/linux/security.h
64248 @@ -26,6 +26,7 @@
64249 #include <linux/capability.h>
64250 #include <linux/slab.h>
64251 #include <linux/err.h>
64252 +#include <linux/grsecurity.h>
64253
64254 struct linux_binprm;
64255 struct cred;
64256 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64257 index 68a04a3..866e6a1 100644
64258 --- a/include/linux/seq_file.h
64259 +++ b/include/linux/seq_file.h
64260 @@ -26,6 +26,9 @@ struct seq_file {
64261 struct mutex lock;
64262 const struct seq_operations *op;
64263 int poll_event;
64264 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64265 + u64 exec_id;
64266 +#endif
64267 #ifdef CONFIG_USER_NS
64268 struct user_namespace *user_ns;
64269 #endif
64270 @@ -38,6 +41,7 @@ struct seq_operations {
64271 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64272 int (*show) (struct seq_file *m, void *v);
64273 };
64274 +typedef struct seq_operations __no_const seq_operations_no_const;
64275
64276 #define SEQ_SKIP 1
64277
64278 diff --git a/include/linux/shm.h b/include/linux/shm.h
64279 index bcf8a6a..4d0af77 100644
64280 --- a/include/linux/shm.h
64281 +++ b/include/linux/shm.h
64282 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
64283
64284 /* The task created the shm object. NULL if the task is dead. */
64285 struct task_struct *shm_creator;
64286 +#ifdef CONFIG_GRKERNSEC
64287 + time_t shm_createtime;
64288 + pid_t shm_lapid;
64289 +#endif
64290 };
64291
64292 /* shm_mode upper byte flags */
64293 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64294 index 6a2c34e..a1f320f 100644
64295 --- a/include/linux/skbuff.h
64296 +++ b/include/linux/skbuff.h
64297 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64298 extern struct sk_buff *__alloc_skb(unsigned int size,
64299 gfp_t priority, int flags, int node);
64300 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64301 -static inline struct sk_buff *alloc_skb(unsigned int size,
64302 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64303 gfp_t priority)
64304 {
64305 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64306 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64307 */
64308 static inline int skb_queue_empty(const struct sk_buff_head *list)
64309 {
64310 - return list->next == (struct sk_buff *)list;
64311 + return list->next == (const struct sk_buff *)list;
64312 }
64313
64314 /**
64315 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64316 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64317 const struct sk_buff *skb)
64318 {
64319 - return skb->next == (struct sk_buff *)list;
64320 + return skb->next == (const struct sk_buff *)list;
64321 }
64322
64323 /**
64324 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64325 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64326 const struct sk_buff *skb)
64327 {
64328 - return skb->prev == (struct sk_buff *)list;
64329 + return skb->prev == (const struct sk_buff *)list;
64330 }
64331
64332 /**
64333 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64334 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64335 */
64336 #ifndef NET_SKB_PAD
64337 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64338 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64339 #endif
64340
64341 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64342 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64343 int noblock, int *err);
64344 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64345 struct poll_table_struct *wait);
64346 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64347 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64348 int offset, struct iovec *to,
64349 int size);
64350 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64351 diff --git a/include/linux/slab.h b/include/linux/slab.h
64352 index 83d1a14..cbce507 100644
64353 --- a/include/linux/slab.h
64354 +++ b/include/linux/slab.h
64355 @@ -11,12 +11,20 @@
64356
64357 #include <linux/gfp.h>
64358 #include <linux/types.h>
64359 +#include <linux/err.h>
64360
64361 /*
64362 * Flags to pass to kmem_cache_create().
64363 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64364 */
64365 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64366 +
64367 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64368 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64369 +#else
64370 +#define SLAB_USERCOPY 0x00000000UL
64371 +#endif
64372 +
64373 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64374 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64375 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64376 @@ -87,10 +95,13 @@
64377 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64378 * Both make kfree a no-op.
64379 */
64380 -#define ZERO_SIZE_PTR ((void *)16)
64381 +#define ZERO_SIZE_PTR \
64382 +({ \
64383 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64384 + (void *)(-MAX_ERRNO-1L); \
64385 +})
64386
64387 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64388 - (unsigned long)ZERO_SIZE_PTR)
64389 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64390
64391 /*
64392 * Common fields provided in kmem_cache by all slab allocators
64393 @@ -110,7 +121,7 @@ struct kmem_cache {
64394 unsigned int align; /* Alignment as calculated */
64395 unsigned long flags; /* Active flags on the slab */
64396 const char *name; /* Slab name for sysfs */
64397 - int refcount; /* Use counter */
64398 + atomic_t refcount; /* Use counter */
64399 void (*ctor)(void *); /* Called on object slot creation */
64400 struct list_head list; /* List of all slab caches on the system */
64401 };
64402 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64403 void kfree(const void *);
64404 void kzfree(const void *);
64405 size_t ksize(const void *);
64406 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64407 +bool is_usercopy_object(const void *ptr);
64408
64409 /*
64410 * Allocator specific definitions. These are mainly used to establish optimized
64411 @@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64412 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64413 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
64414 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
64415 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64416 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64417 #define kmalloc_track_caller(size, flags) \
64418 __kmalloc_track_caller(size, flags, _RET_IP_)
64419 #else
64420 @@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64421 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64422 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
64423 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
64424 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64425 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64426 #define kmalloc_node_track_caller(size, flags, node) \
64427 __kmalloc_node_track_caller(size, flags, node, \
64428 _RET_IP_)
64429 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64430 index cc290f0..0ba60931 100644
64431 --- a/include/linux/slab_def.h
64432 +++ b/include/linux/slab_def.h
64433 @@ -52,7 +52,7 @@ struct kmem_cache {
64434 /* 4) cache creation/removal */
64435 const char *name;
64436 struct list_head list;
64437 - int refcount;
64438 + atomic_t refcount;
64439 int object_size;
64440 int align;
64441
64442 @@ -68,10 +68,10 @@ struct kmem_cache {
64443 unsigned long node_allocs;
64444 unsigned long node_frees;
64445 unsigned long node_overflow;
64446 - atomic_t allochit;
64447 - atomic_t allocmiss;
64448 - atomic_t freehit;
64449 - atomic_t freemiss;
64450 + atomic_unchecked_t allochit;
64451 + atomic_unchecked_t allocmiss;
64452 + atomic_unchecked_t freehit;
64453 + atomic_unchecked_t freemiss;
64454
64455 /*
64456 * If debugging is enabled, then the allocator can add additional
64457 @@ -104,11 +104,16 @@ struct cache_sizes {
64458 #ifdef CONFIG_ZONE_DMA
64459 struct kmem_cache *cs_dmacachep;
64460 #endif
64461 +
64462 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64463 + struct kmem_cache *cs_usercopycachep;
64464 +#endif
64465 +
64466 };
64467 extern struct cache_sizes malloc_sizes[];
64468
64469 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64470 -void *__kmalloc(size_t size, gfp_t flags);
64471 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64472
64473 #ifdef CONFIG_TRACING
64474 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
64475 @@ -145,6 +150,13 @@ found:
64476 cachep = malloc_sizes[i].cs_dmacachep;
64477 else
64478 #endif
64479 +
64480 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64481 + if (flags & GFP_USERCOPY)
64482 + cachep = malloc_sizes[i].cs_usercopycachep;
64483 + else
64484 +#endif
64485 +
64486 cachep = malloc_sizes[i].cs_cachep;
64487
64488 ret = kmem_cache_alloc_trace(cachep, flags, size);
64489 @@ -155,7 +167,7 @@ found:
64490 }
64491
64492 #ifdef CONFIG_NUMA
64493 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64494 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64495 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64496
64497 #ifdef CONFIG_TRACING
64498 @@ -198,6 +210,13 @@ found:
64499 cachep = malloc_sizes[i].cs_dmacachep;
64500 else
64501 #endif
64502 +
64503 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64504 + if (flags & GFP_USERCOPY)
64505 + cachep = malloc_sizes[i].cs_usercopycachep;
64506 + else
64507 +#endif
64508 +
64509 cachep = malloc_sizes[i].cs_cachep;
64510
64511 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
64512 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64513 index f28e14a..7831211 100644
64514 --- a/include/linux/slob_def.h
64515 +++ b/include/linux/slob_def.h
64516 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64517 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
64518 }
64519
64520 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64521 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64522
64523 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64524 {
64525 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64526 return __kmalloc_node(size, flags, NUMA_NO_NODE);
64527 }
64528
64529 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64530 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64531 {
64532 return kmalloc(size, flags);
64533 }
64534 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64535 index df448ad..b99e7f6 100644
64536 --- a/include/linux/slub_def.h
64537 +++ b/include/linux/slub_def.h
64538 @@ -91,7 +91,7 @@ struct kmem_cache {
64539 struct kmem_cache_order_objects max;
64540 struct kmem_cache_order_objects min;
64541 gfp_t allocflags; /* gfp flags to use on each alloc */
64542 - int refcount; /* Refcount for slab cache destroy */
64543 + atomic_t refcount; /* Refcount for slab cache destroy */
64544 void (*ctor)(void *);
64545 int inuse; /* Offset to metadata */
64546 int align; /* Alignment */
64547 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64548 * Sorry that the following has to be that ugly but some versions of GCC
64549 * have trouble with constant propagation and loops.
64550 */
64551 -static __always_inline int kmalloc_index(size_t size)
64552 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64553 {
64554 if (!size)
64555 return 0;
64556 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64557 }
64558
64559 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64560 -void *__kmalloc(size_t size, gfp_t flags);
64561 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64562
64563 static __always_inline void *
64564 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64565 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64566 }
64567 #endif
64568
64569 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64570 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64571 {
64572 unsigned int order = get_order(size);
64573 return kmalloc_order_trace(size, flags, order);
64574 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64575 }
64576
64577 #ifdef CONFIG_NUMA
64578 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64579 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64580 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64581
64582 #ifdef CONFIG_TRACING
64583 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64584 index 680f9a3..f13aeb0 100644
64585 --- a/include/linux/sonet.h
64586 +++ b/include/linux/sonet.h
64587 @@ -7,7 +7,7 @@
64588 #include <uapi/linux/sonet.h>
64589
64590 struct k_sonet_stats {
64591 -#define __HANDLE_ITEM(i) atomic_t i
64592 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64593 __SONET_ITEMS
64594 #undef __HANDLE_ITEM
64595 };
64596 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64597 index 34206b8..f019e06 100644
64598 --- a/include/linux/sunrpc/clnt.h
64599 +++ b/include/linux/sunrpc/clnt.h
64600 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64601 {
64602 switch (sap->sa_family) {
64603 case AF_INET:
64604 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64605 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64606 case AF_INET6:
64607 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64608 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64609 }
64610 return 0;
64611 }
64612 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64613 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64614 const struct sockaddr *src)
64615 {
64616 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64617 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64618 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64619
64620 dsin->sin_family = ssin->sin_family;
64621 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64622 if (sa->sa_family != AF_INET6)
64623 return 0;
64624
64625 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64626 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64627 }
64628
64629 #endif /* __KERNEL__ */
64630 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64631 index dc0c3cc..8503fb6 100644
64632 --- a/include/linux/sunrpc/sched.h
64633 +++ b/include/linux/sunrpc/sched.h
64634 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64635 void (*rpc_count_stats)(struct rpc_task *, void *);
64636 void (*rpc_release)(void *);
64637 };
64638 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64639
64640 struct rpc_task_setup {
64641 struct rpc_task *task;
64642 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64643 index 0b8e3e6..33e0a01 100644
64644 --- a/include/linux/sunrpc/svc_rdma.h
64645 +++ b/include/linux/sunrpc/svc_rdma.h
64646 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64647 extern unsigned int svcrdma_max_requests;
64648 extern unsigned int svcrdma_max_req_size;
64649
64650 -extern atomic_t rdma_stat_recv;
64651 -extern atomic_t rdma_stat_read;
64652 -extern atomic_t rdma_stat_write;
64653 -extern atomic_t rdma_stat_sq_starve;
64654 -extern atomic_t rdma_stat_rq_starve;
64655 -extern atomic_t rdma_stat_rq_poll;
64656 -extern atomic_t rdma_stat_rq_prod;
64657 -extern atomic_t rdma_stat_sq_poll;
64658 -extern atomic_t rdma_stat_sq_prod;
64659 +extern atomic_unchecked_t rdma_stat_recv;
64660 +extern atomic_unchecked_t rdma_stat_read;
64661 +extern atomic_unchecked_t rdma_stat_write;
64662 +extern atomic_unchecked_t rdma_stat_sq_starve;
64663 +extern atomic_unchecked_t rdma_stat_rq_starve;
64664 +extern atomic_unchecked_t rdma_stat_rq_poll;
64665 +extern atomic_unchecked_t rdma_stat_rq_prod;
64666 +extern atomic_unchecked_t rdma_stat_sq_poll;
64667 +extern atomic_unchecked_t rdma_stat_sq_prod;
64668
64669 #define RPCRDMA_VERSION 1
64670
64671 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64672 index cd844a6..3ca3592 100644
64673 --- a/include/linux/sysctl.h
64674 +++ b/include/linux/sysctl.h
64675 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64676
64677 extern int proc_dostring(struct ctl_table *, int,
64678 void __user *, size_t *, loff_t *);
64679 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64680 + void __user *, size_t *, loff_t *);
64681 extern int proc_dointvec(struct ctl_table *, int,
64682 void __user *, size_t *, loff_t *);
64683 extern int proc_dointvec_minmax(struct ctl_table *, int,
64684 diff --git a/include/linux/tty.h b/include/linux/tty.h
64685 index f0b4eb4..1c4854e 100644
64686 --- a/include/linux/tty.h
64687 +++ b/include/linux/tty.h
64688 @@ -192,7 +192,7 @@ struct tty_port {
64689 const struct tty_port_operations *ops; /* Port operations */
64690 spinlock_t lock; /* Lock protecting tty field */
64691 int blocked_open; /* Waiting to open */
64692 - int count; /* Usage count */
64693 + atomic_t count; /* Usage count */
64694 wait_queue_head_t open_wait; /* Open waiters */
64695 wait_queue_head_t close_wait; /* Close waiters */
64696 wait_queue_head_t delta_msr_wait; /* Modem status change */
64697 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
64698 struct tty_struct *tty, struct file *filp);
64699 static inline int tty_port_users(struct tty_port *port)
64700 {
64701 - return port->count + port->blocked_open;
64702 + return atomic_read(&port->count) + port->blocked_open;
64703 }
64704
64705 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64706 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64707 index fb79dd8d..07d4773 100644
64708 --- a/include/linux/tty_ldisc.h
64709 +++ b/include/linux/tty_ldisc.h
64710 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64711
64712 struct module *owner;
64713
64714 - int refcount;
64715 + atomic_t refcount;
64716 };
64717
64718 struct tty_ldisc {
64719 diff --git a/include/linux/types.h b/include/linux/types.h
64720 index 1cc0e4b..0d50edf 100644
64721 --- a/include/linux/types.h
64722 +++ b/include/linux/types.h
64723 @@ -175,10 +175,26 @@ typedef struct {
64724 int counter;
64725 } atomic_t;
64726
64727 +#ifdef CONFIG_PAX_REFCOUNT
64728 +typedef struct {
64729 + int counter;
64730 +} atomic_unchecked_t;
64731 +#else
64732 +typedef atomic_t atomic_unchecked_t;
64733 +#endif
64734 +
64735 #ifdef CONFIG_64BIT
64736 typedef struct {
64737 long counter;
64738 } atomic64_t;
64739 +
64740 +#ifdef CONFIG_PAX_REFCOUNT
64741 +typedef struct {
64742 + long counter;
64743 +} atomic64_unchecked_t;
64744 +#else
64745 +typedef atomic64_t atomic64_unchecked_t;
64746 +#endif
64747 #endif
64748
64749 struct list_head {
64750 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64751 index 5ca0951..ab496a5 100644
64752 --- a/include/linux/uaccess.h
64753 +++ b/include/linux/uaccess.h
64754 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64755 long ret; \
64756 mm_segment_t old_fs = get_fs(); \
64757 \
64758 - set_fs(KERNEL_DS); \
64759 pagefault_disable(); \
64760 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64761 - pagefault_enable(); \
64762 + set_fs(KERNEL_DS); \
64763 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64764 set_fs(old_fs); \
64765 + pagefault_enable(); \
64766 ret; \
64767 })
64768
64769 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64770 index 99c1b4d..bb94261 100644
64771 --- a/include/linux/unaligned/access_ok.h
64772 +++ b/include/linux/unaligned/access_ok.h
64773 @@ -6,32 +6,32 @@
64774
64775 static inline u16 get_unaligned_le16(const void *p)
64776 {
64777 - return le16_to_cpup((__le16 *)p);
64778 + return le16_to_cpup((const __le16 *)p);
64779 }
64780
64781 static inline u32 get_unaligned_le32(const void *p)
64782 {
64783 - return le32_to_cpup((__le32 *)p);
64784 + return le32_to_cpup((const __le32 *)p);
64785 }
64786
64787 static inline u64 get_unaligned_le64(const void *p)
64788 {
64789 - return le64_to_cpup((__le64 *)p);
64790 + return le64_to_cpup((const __le64 *)p);
64791 }
64792
64793 static inline u16 get_unaligned_be16(const void *p)
64794 {
64795 - return be16_to_cpup((__be16 *)p);
64796 + return be16_to_cpup((const __be16 *)p);
64797 }
64798
64799 static inline u32 get_unaligned_be32(const void *p)
64800 {
64801 - return be32_to_cpup((__be32 *)p);
64802 + return be32_to_cpup((const __be32 *)p);
64803 }
64804
64805 static inline u64 get_unaligned_be64(const void *p)
64806 {
64807 - return be64_to_cpup((__be64 *)p);
64808 + return be64_to_cpup((const __be64 *)p);
64809 }
64810
64811 static inline void put_unaligned_le16(u16 val, void *p)
64812 diff --git a/include/linux/usb.h b/include/linux/usb.h
64813 index 10278d1..e21ec3c 100644
64814 --- a/include/linux/usb.h
64815 +++ b/include/linux/usb.h
64816 @@ -551,7 +551,7 @@ struct usb_device {
64817 int maxchild;
64818
64819 u32 quirks;
64820 - atomic_t urbnum;
64821 + atomic_unchecked_t urbnum;
64822
64823 unsigned long active_duration;
64824
64825 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64826 index c5d36c6..8478c90 100644
64827 --- a/include/linux/usb/renesas_usbhs.h
64828 +++ b/include/linux/usb/renesas_usbhs.h
64829 @@ -39,7 +39,7 @@ enum {
64830 */
64831 struct renesas_usbhs_driver_callback {
64832 int (*notify_hotplug)(struct platform_device *pdev);
64833 -};
64834 +} __no_const;
64835
64836 /*
64837 * callback functions for platform
64838 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64839 * VBUS control is needed for Host
64840 */
64841 int (*set_vbus)(struct platform_device *pdev, int enable);
64842 -};
64843 +} __no_const;
64844
64845 /*
64846 * parameters for renesas usbhs
64847 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64848 index 6f8fbcf..8259001 100644
64849 --- a/include/linux/vermagic.h
64850 +++ b/include/linux/vermagic.h
64851 @@ -25,9 +25,35 @@
64852 #define MODULE_ARCH_VERMAGIC ""
64853 #endif
64854
64855 +#ifdef CONFIG_PAX_REFCOUNT
64856 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64857 +#else
64858 +#define MODULE_PAX_REFCOUNT ""
64859 +#endif
64860 +
64861 +#ifdef CONSTIFY_PLUGIN
64862 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64863 +#else
64864 +#define MODULE_CONSTIFY_PLUGIN ""
64865 +#endif
64866 +
64867 +#ifdef STACKLEAK_PLUGIN
64868 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64869 +#else
64870 +#define MODULE_STACKLEAK_PLUGIN ""
64871 +#endif
64872 +
64873 +#ifdef CONFIG_GRKERNSEC
64874 +#define MODULE_GRSEC "GRSEC "
64875 +#else
64876 +#define MODULE_GRSEC ""
64877 +#endif
64878 +
64879 #define VERMAGIC_STRING \
64880 UTS_RELEASE " " \
64881 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64882 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64883 - MODULE_ARCH_VERMAGIC
64884 + MODULE_ARCH_VERMAGIC \
64885 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64886 + MODULE_GRSEC
64887
64888 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64889 index 6071e91..ca6a489 100644
64890 --- a/include/linux/vmalloc.h
64891 +++ b/include/linux/vmalloc.h
64892 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64893 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64894 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64895 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64896 +
64897 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64898 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64899 +#endif
64900 +
64901 /* bits [20..32] reserved for arch specific ioremap internals */
64902
64903 /*
64904 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64905 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64906 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64907 unsigned long start, unsigned long end, gfp_t gfp_mask,
64908 - pgprot_t prot, int node, const void *caller);
64909 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64910 extern void vfree(const void *addr);
64911
64912 extern void *vmap(struct page **pages, unsigned int count,
64913 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64914 extern void free_vm_area(struct vm_struct *area);
64915
64916 /* for /dev/kmem */
64917 -extern long vread(char *buf, char *addr, unsigned long count);
64918 -extern long vwrite(char *buf, char *addr, unsigned long count);
64919 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64920 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64921
64922 /*
64923 * Internals. Dont't use..
64924 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64925 index 92a86b2..1d9eb3c 100644
64926 --- a/include/linux/vmstat.h
64927 +++ b/include/linux/vmstat.h
64928 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64929 /*
64930 * Zone based page accounting with per cpu differentials.
64931 */
64932 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64933 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64934
64935 static inline void zone_page_state_add(long x, struct zone *zone,
64936 enum zone_stat_item item)
64937 {
64938 - atomic_long_add(x, &zone->vm_stat[item]);
64939 - atomic_long_add(x, &vm_stat[item]);
64940 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64941 + atomic_long_add_unchecked(x, &vm_stat[item]);
64942 }
64943
64944 static inline unsigned long global_page_state(enum zone_stat_item item)
64945 {
64946 - long x = atomic_long_read(&vm_stat[item]);
64947 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64948 #ifdef CONFIG_SMP
64949 if (x < 0)
64950 x = 0;
64951 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64952 static inline unsigned long zone_page_state(struct zone *zone,
64953 enum zone_stat_item item)
64954 {
64955 - long x = atomic_long_read(&zone->vm_stat[item]);
64956 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64957 #ifdef CONFIG_SMP
64958 if (x < 0)
64959 x = 0;
64960 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64961 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64962 enum zone_stat_item item)
64963 {
64964 - long x = atomic_long_read(&zone->vm_stat[item]);
64965 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64966
64967 #ifdef CONFIG_SMP
64968 int cpu;
64969 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64970
64971 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64972 {
64973 - atomic_long_inc(&zone->vm_stat[item]);
64974 - atomic_long_inc(&vm_stat[item]);
64975 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64976 + atomic_long_inc_unchecked(&vm_stat[item]);
64977 }
64978
64979 static inline void __inc_zone_page_state(struct page *page,
64980 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
64981
64982 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64983 {
64984 - atomic_long_dec(&zone->vm_stat[item]);
64985 - atomic_long_dec(&vm_stat[item]);
64986 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64987 + atomic_long_dec_unchecked(&vm_stat[item]);
64988 }
64989
64990 static inline void __dec_zone_page_state(struct page *page,
64991 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64992 index 944ecdf..a3994fc 100644
64993 --- a/include/media/saa7146_vv.h
64994 +++ b/include/media/saa7146_vv.h
64995 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64996 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64997
64998 /* the extension can override this */
64999 - struct v4l2_ioctl_ops vid_ops;
65000 - struct v4l2_ioctl_ops vbi_ops;
65001 + v4l2_ioctl_ops_no_const vid_ops;
65002 + v4l2_ioctl_ops_no_const vbi_ops;
65003 /* pointer to the saa7146 core ops */
65004 const struct v4l2_ioctl_ops *core_ops;
65005
65006 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65007 index 95d1c91..19a5d94 100644
65008 --- a/include/media/v4l2-dev.h
65009 +++ b/include/media/v4l2-dev.h
65010 @@ -76,7 +76,8 @@ struct v4l2_file_operations {
65011 int (*mmap) (struct file *, struct vm_area_struct *);
65012 int (*open) (struct file *);
65013 int (*release) (struct file *);
65014 -};
65015 +} __do_const;
65016 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65017
65018 /*
65019 * Newer version of video_device, handled by videodev2.c
65020 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65021 index e48b571..cec1748 100644
65022 --- a/include/media/v4l2-ioctl.h
65023 +++ b/include/media/v4l2-ioctl.h
65024 @@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
65025 long (*vidioc_default) (struct file *file, void *fh,
65026 bool valid_prio, int cmd, void *arg);
65027 };
65028 -
65029 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65030
65031 /* v4l debugging and diagnostics */
65032
65033 diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
65034 index ede0369..067cf12 100644
65035 --- a/include/net/bluetooth/bluetooth.h
65036 +++ b/include/net/bluetooth/bluetooth.h
65037 @@ -204,7 +204,7 @@ struct bt_sock_list {
65038 struct hlist_head head;
65039 rwlock_t lock;
65040 #ifdef CONFIG_PROC_FS
65041 - struct file_operations fops;
65042 + file_operations_no_const fops;
65043 int (* custom_seq_show)(struct seq_file *, void *);
65044 #endif
65045 };
65046 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65047 index bcb9cc3..f4ec722e 100644
65048 --- a/include/net/caif/caif_hsi.h
65049 +++ b/include/net/caif/caif_hsi.h
65050 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65051 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65052 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65053 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65054 -};
65055 +} __no_const;
65056
65057 /* Structure implemented by HSI device. */
65058 struct cfhsi_ops {
65059 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65060 index 9e5425b..8136ffc 100644
65061 --- a/include/net/caif/cfctrl.h
65062 +++ b/include/net/caif/cfctrl.h
65063 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65064 void (*radioset_rsp)(void);
65065 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65066 struct cflayer *client_layer);
65067 -};
65068 +} __no_const;
65069
65070 /* Link Setup Parameters for CAIF-Links. */
65071 struct cfctrl_link_param {
65072 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65073 struct cfctrl {
65074 struct cfsrvl serv;
65075 struct cfctrl_rsp res;
65076 - atomic_t req_seq_no;
65077 - atomic_t rsp_seq_no;
65078 + atomic_unchecked_t req_seq_no;
65079 + atomic_unchecked_t rsp_seq_no;
65080 struct list_head list;
65081 /* Protects from simultaneous access to first_req list */
65082 spinlock_t info_list_lock;
65083 diff --git a/include/net/flow.h b/include/net/flow.h
65084 index 628e11b..4c475df 100644
65085 --- a/include/net/flow.h
65086 +++ b/include/net/flow.h
65087 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65088
65089 extern void flow_cache_flush(void);
65090 extern void flow_cache_flush_deferred(void);
65091 -extern atomic_t flow_cache_genid;
65092 +extern atomic_unchecked_t flow_cache_genid;
65093
65094 #endif
65095 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
65096 index 4fd8a4b..123e31a 100644
65097 --- a/include/net/gro_cells.h
65098 +++ b/include/net/gro_cells.h
65099 @@ -30,7 +30,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
65100 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
65101
65102 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
65103 - atomic_long_inc(&dev->rx_dropped);
65104 + atomic_long_inc_unchecked(&dev->rx_dropped);
65105 kfree_skb(skb);
65106 return;
65107 }
65108 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65109 index 53f464d..ba76aaa 100644
65110 --- a/include/net/inetpeer.h
65111 +++ b/include/net/inetpeer.h
65112 @@ -47,8 +47,8 @@ struct inet_peer {
65113 */
65114 union {
65115 struct {
65116 - atomic_t rid; /* Frag reception counter */
65117 - atomic_t ip_id_count; /* IP ID for the next packet */
65118 + atomic_unchecked_t rid; /* Frag reception counter */
65119 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65120 };
65121 struct rcu_head rcu;
65122 struct inet_peer *gc_next;
65123 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65124 more++;
65125 inet_peer_refcheck(p);
65126 do {
65127 - old = atomic_read(&p->ip_id_count);
65128 + old = atomic_read_unchecked(&p->ip_id_count);
65129 new = old + more;
65130 if (!new)
65131 new = 1;
65132 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65133 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65134 return new;
65135 }
65136
65137 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65138 index 9497be1..5a4fafe 100644
65139 --- a/include/net/ip_fib.h
65140 +++ b/include/net/ip_fib.h
65141 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65142
65143 #define FIB_RES_SADDR(net, res) \
65144 ((FIB_RES_NH(res).nh_saddr_genid == \
65145 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65146 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65147 FIB_RES_NH(res).nh_saddr : \
65148 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65149 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65150 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65151 index ee75ccd..2cc2b95 100644
65152 --- a/include/net/ip_vs.h
65153 +++ b/include/net/ip_vs.h
65154 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65155 struct ip_vs_conn *control; /* Master control connection */
65156 atomic_t n_control; /* Number of controlled ones */
65157 struct ip_vs_dest *dest; /* real server */
65158 - atomic_t in_pkts; /* incoming packet counter */
65159 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65160
65161 /* packet transmitter for different forwarding methods. If it
65162 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65163 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65164 __be16 port; /* port number of the server */
65165 union nf_inet_addr addr; /* IP address of the server */
65166 volatile unsigned int flags; /* dest status flags */
65167 - atomic_t conn_flags; /* flags to copy to conn */
65168 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65169 atomic_t weight; /* server weight */
65170
65171 atomic_t refcnt; /* reference counter */
65172 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65173 index 69b610a..fe3962c 100644
65174 --- a/include/net/irda/ircomm_core.h
65175 +++ b/include/net/irda/ircomm_core.h
65176 @@ -51,7 +51,7 @@ typedef struct {
65177 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65178 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65179 struct ircomm_info *);
65180 -} call_t;
65181 +} __no_const call_t;
65182
65183 struct ircomm_cb {
65184 irda_queue_t queue;
65185 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65186 index 80ffde3..968b0f4 100644
65187 --- a/include/net/irda/ircomm_tty.h
65188 +++ b/include/net/irda/ircomm_tty.h
65189 @@ -35,6 +35,7 @@
65190 #include <linux/termios.h>
65191 #include <linux/timer.h>
65192 #include <linux/tty.h> /* struct tty_struct */
65193 +#include <asm/local.h>
65194
65195 #include <net/irda/irias_object.h>
65196 #include <net/irda/ircomm_core.h>
65197 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65198 index cc7c197..9f2da2a 100644
65199 --- a/include/net/iucv/af_iucv.h
65200 +++ b/include/net/iucv/af_iucv.h
65201 @@ -141,7 +141,7 @@ struct iucv_sock {
65202 struct iucv_sock_list {
65203 struct hlist_head head;
65204 rwlock_t lock;
65205 - atomic_t autobind_name;
65206 + atomic_unchecked_t autobind_name;
65207 };
65208
65209 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65210 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65211 index 0dab173..1b76af0 100644
65212 --- a/include/net/neighbour.h
65213 +++ b/include/net/neighbour.h
65214 @@ -123,7 +123,7 @@ struct neigh_ops {
65215 void (*error_report)(struct neighbour *, struct sk_buff *);
65216 int (*output)(struct neighbour *, struct sk_buff *);
65217 int (*connected_output)(struct neighbour *, struct sk_buff *);
65218 -};
65219 +} __do_const;
65220
65221 struct pneigh_entry {
65222 struct pneigh_entry *next;
65223 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65224 index 95e6466..251016d 100644
65225 --- a/include/net/net_namespace.h
65226 +++ b/include/net/net_namespace.h
65227 @@ -110,7 +110,7 @@ struct net {
65228 #endif
65229 struct netns_ipvs *ipvs;
65230 struct sock *diag_nlsk;
65231 - atomic_t rt_genid;
65232 + atomic_unchecked_t rt_genid;
65233 };
65234
65235 /*
65236 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65237
65238 static inline int rt_genid(struct net *net)
65239 {
65240 - return atomic_read(&net->rt_genid);
65241 + return atomic_read_unchecked(&net->rt_genid);
65242 }
65243
65244 static inline void rt_genid_bump(struct net *net)
65245 {
65246 - atomic_inc(&net->rt_genid);
65247 + atomic_inc_unchecked(&net->rt_genid);
65248 }
65249
65250 #endif /* __NET_NET_NAMESPACE_H */
65251 diff --git a/include/net/netdma.h b/include/net/netdma.h
65252 index 8ba8ce2..99b7fff 100644
65253 --- a/include/net/netdma.h
65254 +++ b/include/net/netdma.h
65255 @@ -24,7 +24,7 @@
65256 #include <linux/dmaengine.h>
65257 #include <linux/skbuff.h>
65258
65259 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65260 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65261 struct sk_buff *skb, int offset, struct iovec *to,
65262 size_t len, struct dma_pinned_list *pinned_list);
65263
65264 diff --git a/include/net/netlink.h b/include/net/netlink.h
65265 index 9690b0f..87aded7 100644
65266 --- a/include/net/netlink.h
65267 +++ b/include/net/netlink.h
65268 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65269 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65270 {
65271 if (mark)
65272 - skb_trim(skb, (unsigned char *) mark - skb->data);
65273 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65274 }
65275
65276 /**
65277 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65278 index 2ae2b83..dbdc85e 100644
65279 --- a/include/net/netns/ipv4.h
65280 +++ b/include/net/netns/ipv4.h
65281 @@ -64,7 +64,7 @@ struct netns_ipv4 {
65282 kgid_t sysctl_ping_group_range[2];
65283 long sysctl_tcp_mem[3];
65284
65285 - atomic_t dev_addr_genid;
65286 + atomic_unchecked_t dev_addr_genid;
65287
65288 #ifdef CONFIG_IP_MROUTE
65289 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65290 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65291 index 9c6414f..fbd0524 100644
65292 --- a/include/net/sctp/sctp.h
65293 +++ b/include/net/sctp/sctp.h
65294 @@ -318,9 +318,9 @@ do { \
65295
65296 #else /* SCTP_DEBUG */
65297
65298 -#define SCTP_DEBUG_PRINTK(whatever...)
65299 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65300 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65301 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65302 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65303 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65304 #define SCTP_ENABLE_DEBUG
65305 #define SCTP_DISABLE_DEBUG
65306 #define SCTP_ASSERT(expr, str, func)
65307 diff --git a/include/net/sock.h b/include/net/sock.h
65308 index c945fba..e162e56 100644
65309 --- a/include/net/sock.h
65310 +++ b/include/net/sock.h
65311 @@ -304,7 +304,7 @@ struct sock {
65312 #ifdef CONFIG_RPS
65313 __u32 sk_rxhash;
65314 #endif
65315 - atomic_t sk_drops;
65316 + atomic_unchecked_t sk_drops;
65317 int sk_rcvbuf;
65318
65319 struct sk_filter __rcu *sk_filter;
65320 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65321 }
65322
65323 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65324 - char __user *from, char *to,
65325 + char __user *from, unsigned char *to,
65326 int copy, int offset)
65327 {
65328 if (skb->ip_summed == CHECKSUM_NONE) {
65329 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65330 }
65331 }
65332
65333 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65334 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65335
65336 /**
65337 * sk_page_frag - return an appropriate page_frag
65338 diff --git a/include/net/tcp.h b/include/net/tcp.h
65339 index 4af45e3..32163a9 100644
65340 --- a/include/net/tcp.h
65341 +++ b/include/net/tcp.h
65342 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65343 extern void tcp_xmit_retransmit_queue(struct sock *);
65344 extern void tcp_simple_retransmit(struct sock *);
65345 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65346 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65347 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65348
65349 extern void tcp_send_probe0(struct sock *);
65350 extern void tcp_send_partial(struct sock *);
65351 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
65352 struct inet6_skb_parm h6;
65353 #endif
65354 } header; /* For incoming frames */
65355 - __u32 seq; /* Starting sequence number */
65356 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65357 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65358 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65359 __u32 when; /* used to compute rtt's */
65360 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65361
65362 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
65363
65364 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65365 /* 1 byte hole */
65366 - __u32 ack_seq; /* Sequence number ACK'd */
65367 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65368 };
65369
65370 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65371 @@ -1563,7 +1563,7 @@ struct tcp_seq_afinfo {
65372 char *name;
65373 sa_family_t family;
65374 const struct file_operations *seq_fops;
65375 - struct seq_operations seq_ops;
65376 + seq_operations_no_const seq_ops;
65377 };
65378
65379 struct tcp_iter_state {
65380 diff --git a/include/net/udp.h b/include/net/udp.h
65381 index 065f379..b661b40 100644
65382 --- a/include/net/udp.h
65383 +++ b/include/net/udp.h
65384 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65385 sa_family_t family;
65386 struct udp_table *udp_table;
65387 const struct file_operations *seq_fops;
65388 - struct seq_operations seq_ops;
65389 + seq_operations_no_const seq_ops;
65390 };
65391
65392 struct udp_iter_state {
65393 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65394 index 63445ed..01ddc62 100644
65395 --- a/include/net/xfrm.h
65396 +++ b/include/net/xfrm.h
65397 @@ -514,7 +514,7 @@ struct xfrm_policy {
65398 struct timer_list timer;
65399
65400 struct flow_cache_object flo;
65401 - atomic_t genid;
65402 + atomic_unchecked_t genid;
65403 u32 priority;
65404 u32 index;
65405 struct xfrm_mark mark;
65406 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65407 index 1a046b1..ee0bef0 100644
65408 --- a/include/rdma/iw_cm.h
65409 +++ b/include/rdma/iw_cm.h
65410 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65411 int backlog);
65412
65413 int (*destroy_listen)(struct iw_cm_id *cm_id);
65414 -};
65415 +} __no_const;
65416
65417 /**
65418 * iw_create_cm_id - Create an IW CM identifier.
65419 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65420 index 399162b..b337f1a 100644
65421 --- a/include/scsi/libfc.h
65422 +++ b/include/scsi/libfc.h
65423 @@ -762,6 +762,7 @@ struct libfc_function_template {
65424 */
65425 void (*disc_stop_final) (struct fc_lport *);
65426 };
65427 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65428
65429 /**
65430 * struct fc_disc - Discovery context
65431 @@ -866,7 +867,7 @@ struct fc_lport {
65432 struct fc_vport *vport;
65433
65434 /* Operational Information */
65435 - struct libfc_function_template tt;
65436 + libfc_function_template_no_const tt;
65437 u8 link_up;
65438 u8 qfull;
65439 enum fc_lport_state state;
65440 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65441 index 55367b0..d97bd2a 100644
65442 --- a/include/scsi/scsi_device.h
65443 +++ b/include/scsi/scsi_device.h
65444 @@ -169,9 +169,9 @@ struct scsi_device {
65445 unsigned int max_device_blocked; /* what device_blocked counts down from */
65446 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65447
65448 - atomic_t iorequest_cnt;
65449 - atomic_t iodone_cnt;
65450 - atomic_t ioerr_cnt;
65451 + atomic_unchecked_t iorequest_cnt;
65452 + atomic_unchecked_t iodone_cnt;
65453 + atomic_unchecked_t ioerr_cnt;
65454
65455 struct device sdev_gendev,
65456 sdev_dev;
65457 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65458 index b797e8f..8e2c3aa 100644
65459 --- a/include/scsi/scsi_transport_fc.h
65460 +++ b/include/scsi/scsi_transport_fc.h
65461 @@ -751,7 +751,8 @@ struct fc_function_template {
65462 unsigned long show_host_system_hostname:1;
65463
65464 unsigned long disable_target_scan:1;
65465 -};
65466 +} __do_const;
65467 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65468
65469
65470 /**
65471 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65472 index 030b87c..98a6954 100644
65473 --- a/include/sound/ak4xxx-adda.h
65474 +++ b/include/sound/ak4xxx-adda.h
65475 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65476 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65477 unsigned char val);
65478 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65479 -};
65480 +} __no_const;
65481
65482 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65483
65484 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65485 index 8c05e47..2b5df97 100644
65486 --- a/include/sound/hwdep.h
65487 +++ b/include/sound/hwdep.h
65488 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65489 struct snd_hwdep_dsp_status *status);
65490 int (*dsp_load)(struct snd_hwdep *hw,
65491 struct snd_hwdep_dsp_image *image);
65492 -};
65493 +} __no_const;
65494
65495 struct snd_hwdep {
65496 struct snd_card *card;
65497 diff --git a/include/sound/info.h b/include/sound/info.h
65498 index 9ca1a49..aba1728 100644
65499 --- a/include/sound/info.h
65500 +++ b/include/sound/info.h
65501 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65502 struct snd_info_buffer *buffer);
65503 void (*write)(struct snd_info_entry *entry,
65504 struct snd_info_buffer *buffer);
65505 -};
65506 +} __no_const;
65507
65508 struct snd_info_entry_ops {
65509 int (*open)(struct snd_info_entry *entry,
65510 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65511 index 6268a41..de9b9d1 100644
65512 --- a/include/sound/pcm.h
65513 +++ b/include/sound/pcm.h
65514 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65515 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65516 int (*ack)(struct snd_pcm_substream *substream);
65517 };
65518 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65519
65520 /*
65521 *
65522 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65523 index 7e95056..52df55a 100644
65524 --- a/include/sound/sb16_csp.h
65525 +++ b/include/sound/sb16_csp.h
65526 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65527 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65528 int (*csp_stop) (struct snd_sb_csp * p);
65529 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65530 -};
65531 +} __no_const;
65532
65533 /*
65534 * CSP private data
65535 diff --git a/include/sound/soc.h b/include/sound/soc.h
65536 index 91244a0..4534aae 100644
65537 --- a/include/sound/soc.h
65538 +++ b/include/sound/soc.h
65539 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
65540 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65541 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65542 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65543 -};
65544 +} __do_const;
65545
65546 struct snd_soc_platform {
65547 const char *name;
65548 @@ -1031,7 +1031,7 @@ struct snd_soc_pcm_runtime {
65549 struct snd_soc_dai_link *dai_link;
65550 struct mutex pcm_mutex;
65551 enum snd_soc_pcm_subclass pcm_subclass;
65552 - struct snd_pcm_ops ops;
65553 + snd_pcm_ops_no_const ops;
65554
65555 unsigned int dev_registered:1;
65556
65557 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65558 index 098c4de..171054b 100644
65559 --- a/include/sound/tea575x-tuner.h
65560 +++ b/include/sound/tea575x-tuner.h
65561 @@ -49,7 +49,7 @@ struct snd_tea575x_ops {
65562
65563 struct snd_tea575x {
65564 struct v4l2_device *v4l2_dev;
65565 - struct v4l2_file_operations fops;
65566 + v4l2_file_operations_no_const fops;
65567 struct video_device vd; /* video device */
65568 int radio_nr; /* radio_nr */
65569 bool tea5759; /* 5759 chip is present */
65570 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65571 index 5be8937..a8e46e9 100644
65572 --- a/include/target/target_core_base.h
65573 +++ b/include/target/target_core_base.h
65574 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65575 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65576 int (*t10_pr_register)(struct se_cmd *);
65577 int (*t10_pr_clear)(struct se_cmd *);
65578 -};
65579 +} __no_const;
65580
65581 struct t10_reservation {
65582 /* Reservation effects all target ports */
65583 @@ -758,7 +758,7 @@ struct se_device {
65584 spinlock_t stats_lock;
65585 /* Active commands on this virtual SE device */
65586 atomic_t simple_cmds;
65587 - atomic_t dev_ordered_id;
65588 + atomic_unchecked_t dev_ordered_id;
65589 atomic_t dev_ordered_sync;
65590 atomic_t dev_qf_count;
65591 struct se_obj dev_obj;
65592 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65593 new file mode 100644
65594 index 0000000..fb634b7
65595 --- /dev/null
65596 +++ b/include/trace/events/fs.h
65597 @@ -0,0 +1,53 @@
65598 +#undef TRACE_SYSTEM
65599 +#define TRACE_SYSTEM fs
65600 +
65601 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65602 +#define _TRACE_FS_H
65603 +
65604 +#include <linux/fs.h>
65605 +#include <linux/tracepoint.h>
65606 +
65607 +TRACE_EVENT(do_sys_open,
65608 +
65609 + TP_PROTO(const char *filename, int flags, int mode),
65610 +
65611 + TP_ARGS(filename, flags, mode),
65612 +
65613 + TP_STRUCT__entry(
65614 + __string( filename, filename )
65615 + __field( int, flags )
65616 + __field( int, mode )
65617 + ),
65618 +
65619 + TP_fast_assign(
65620 + __assign_str(filename, filename);
65621 + __entry->flags = flags;
65622 + __entry->mode = mode;
65623 + ),
65624 +
65625 + TP_printk("\"%s\" %x %o",
65626 + __get_str(filename), __entry->flags, __entry->mode)
65627 +);
65628 +
65629 +TRACE_EVENT(open_exec,
65630 +
65631 + TP_PROTO(const char *filename),
65632 +
65633 + TP_ARGS(filename),
65634 +
65635 + TP_STRUCT__entry(
65636 + __string( filename, filename )
65637 + ),
65638 +
65639 + TP_fast_assign(
65640 + __assign_str(filename, filename);
65641 + ),
65642 +
65643 + TP_printk("\"%s\"",
65644 + __get_str(filename))
65645 +);
65646 +
65647 +#endif /* _TRACE_FS_H */
65648 +
65649 +/* This part must be outside protection */
65650 +#include <trace/define_trace.h>
65651 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65652 index 1c09820..7f5ec79 100644
65653 --- a/include/trace/events/irq.h
65654 +++ b/include/trace/events/irq.h
65655 @@ -36,7 +36,7 @@ struct softirq_action;
65656 */
65657 TRACE_EVENT(irq_handler_entry,
65658
65659 - TP_PROTO(int irq, struct irqaction *action),
65660 + TP_PROTO(int irq, const struct irqaction *action),
65661
65662 TP_ARGS(irq, action),
65663
65664 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65665 */
65666 TRACE_EVENT(irq_handler_exit,
65667
65668 - TP_PROTO(int irq, struct irqaction *action, int ret),
65669 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65670
65671 TP_ARGS(irq, action, ret),
65672
65673 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
65674 index 7caf44c..23c6f27 100644
65675 --- a/include/uapi/linux/a.out.h
65676 +++ b/include/uapi/linux/a.out.h
65677 @@ -39,6 +39,14 @@ enum machine_type {
65678 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65679 };
65680
65681 +/* Constants for the N_FLAGS field */
65682 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65683 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65684 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65685 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65686 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65687 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65688 +
65689 #if !defined (N_MAGIC)
65690 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65691 #endif
65692 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
65693 index d876736..b36014e 100644
65694 --- a/include/uapi/linux/byteorder/little_endian.h
65695 +++ b/include/uapi/linux/byteorder/little_endian.h
65696 @@ -42,51 +42,51 @@
65697
65698 static inline __le64 __cpu_to_le64p(const __u64 *p)
65699 {
65700 - return (__force __le64)*p;
65701 + return (__force const __le64)*p;
65702 }
65703 static inline __u64 __le64_to_cpup(const __le64 *p)
65704 {
65705 - return (__force __u64)*p;
65706 + return (__force const __u64)*p;
65707 }
65708 static inline __le32 __cpu_to_le32p(const __u32 *p)
65709 {
65710 - return (__force __le32)*p;
65711 + return (__force const __le32)*p;
65712 }
65713 static inline __u32 __le32_to_cpup(const __le32 *p)
65714 {
65715 - return (__force __u32)*p;
65716 + return (__force const __u32)*p;
65717 }
65718 static inline __le16 __cpu_to_le16p(const __u16 *p)
65719 {
65720 - return (__force __le16)*p;
65721 + return (__force const __le16)*p;
65722 }
65723 static inline __u16 __le16_to_cpup(const __le16 *p)
65724 {
65725 - return (__force __u16)*p;
65726 + return (__force const __u16)*p;
65727 }
65728 static inline __be64 __cpu_to_be64p(const __u64 *p)
65729 {
65730 - return (__force __be64)__swab64p(p);
65731 + return (__force const __be64)__swab64p(p);
65732 }
65733 static inline __u64 __be64_to_cpup(const __be64 *p)
65734 {
65735 - return __swab64p((__u64 *)p);
65736 + return __swab64p((const __u64 *)p);
65737 }
65738 static inline __be32 __cpu_to_be32p(const __u32 *p)
65739 {
65740 - return (__force __be32)__swab32p(p);
65741 + return (__force const __be32)__swab32p(p);
65742 }
65743 static inline __u32 __be32_to_cpup(const __be32 *p)
65744 {
65745 - return __swab32p((__u32 *)p);
65746 + return __swab32p((const __u32 *)p);
65747 }
65748 static inline __be16 __cpu_to_be16p(const __u16 *p)
65749 {
65750 - return (__force __be16)__swab16p(p);
65751 + return (__force const __be16)__swab16p(p);
65752 }
65753 static inline __u16 __be16_to_cpup(const __be16 *p)
65754 {
65755 - return __swab16p((__u16 *)p);
65756 + return __swab16p((const __u16 *)p);
65757 }
65758 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65759 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65760 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
65761 index 126a817..d522bd1 100644
65762 --- a/include/uapi/linux/elf.h
65763 +++ b/include/uapi/linux/elf.h
65764 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
65765 #define PT_GNU_EH_FRAME 0x6474e550
65766
65767 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65768 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65769 +
65770 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65771 +
65772 +/* Constants for the e_flags field */
65773 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65774 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65775 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65776 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65777 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65778 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65779
65780 /*
65781 * Extended Numbering
65782 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
65783 #define DT_DEBUG 21
65784 #define DT_TEXTREL 22
65785 #define DT_JMPREL 23
65786 +#define DT_FLAGS 30
65787 + #define DF_TEXTREL 0x00000004
65788 #define DT_ENCODING 32
65789 #define OLD_DT_LOOS 0x60000000
65790 #define DT_LOOS 0x6000000d
65791 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
65792 #define PF_W 0x2
65793 #define PF_X 0x1
65794
65795 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65796 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65797 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65798 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65799 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65800 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65801 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65802 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65803 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65804 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65805 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65806 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65807 +
65808 typedef struct elf32_phdr{
65809 Elf32_Word p_type;
65810 Elf32_Off p_offset;
65811 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
65812 #define EI_OSABI 7
65813 #define EI_PAD 8
65814
65815 +#define EI_PAX 14
65816 +
65817 #define ELFMAG0 0x7f /* EI_MAG */
65818 #define ELFMAG1 'E'
65819 #define ELFMAG2 'L'
65820 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
65821 index aa169c4..6a2771d 100644
65822 --- a/include/uapi/linux/personality.h
65823 +++ b/include/uapi/linux/personality.h
65824 @@ -30,6 +30,7 @@ enum {
65825 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
65826 ADDR_NO_RANDOMIZE | \
65827 ADDR_COMPAT_LAYOUT | \
65828 + ADDR_LIMIT_3GB | \
65829 MMAP_PAGE_ZERO)
65830
65831 /*
65832 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
65833 index 7530e74..e714828 100644
65834 --- a/include/uapi/linux/screen_info.h
65835 +++ b/include/uapi/linux/screen_info.h
65836 @@ -43,7 +43,8 @@ struct screen_info {
65837 __u16 pages; /* 0x32 */
65838 __u16 vesa_attributes; /* 0x34 */
65839 __u32 capabilities; /* 0x36 */
65840 - __u8 _reserved[6]; /* 0x3a */
65841 + __u16 vesapm_size; /* 0x3a */
65842 + __u8 _reserved[4]; /* 0x3c */
65843 } __attribute__((packed));
65844
65845 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
65846 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
65847 index 6d67213..8dab561 100644
65848 --- a/include/uapi/linux/sysctl.h
65849 +++ b/include/uapi/linux/sysctl.h
65850 @@ -155,7 +155,11 @@ enum
65851 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65852 };
65853
65854 -
65855 +#ifdef CONFIG_PAX_SOFTMODE
65856 +enum {
65857 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65858 +};
65859 +#endif
65860
65861 /* CTL_VM names: */
65862 enum
65863 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
65864 index 26607bd..588b65f 100644
65865 --- a/include/uapi/linux/xattr.h
65866 +++ b/include/uapi/linux/xattr.h
65867 @@ -60,5 +60,9 @@
65868 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65869 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65870
65871 +/* User namespace */
65872 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65873 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65874 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65875
65876 #endif /* _UAPI_LINUX_XATTR_H */
65877 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65878 index f9466fa..f4e2b81 100644
65879 --- a/include/video/udlfb.h
65880 +++ b/include/video/udlfb.h
65881 @@ -53,10 +53,10 @@ struct dlfb_data {
65882 u32 pseudo_palette[256];
65883 int blank_mode; /*one of FB_BLANK_ */
65884 /* blit-only rendering path metrics, exposed through sysfs */
65885 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65886 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65887 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65888 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65889 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65890 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65891 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65892 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65893 };
65894
65895 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65896 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65897 index 0993a22..32ba2fe 100644
65898 --- a/include/video/uvesafb.h
65899 +++ b/include/video/uvesafb.h
65900 @@ -177,6 +177,7 @@ struct uvesafb_par {
65901 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65902 u8 pmi_setpal; /* PMI for palette changes */
65903 u16 *pmi_base; /* protected mode interface location */
65904 + u8 *pmi_code; /* protected mode code location */
65905 void *pmi_start;
65906 void *pmi_pal;
65907 u8 *vbe_state_orig; /*
65908 diff --git a/init/Kconfig b/init/Kconfig
65909 index 6fdd6e3..5b01610 100644
65910 --- a/init/Kconfig
65911 +++ b/init/Kconfig
65912 @@ -925,6 +925,7 @@ endif # CGROUPS
65913
65914 config CHECKPOINT_RESTORE
65915 bool "Checkpoint/restore support" if EXPERT
65916 + depends on !GRKERNSEC
65917 default n
65918 help
65919 Enables additional kernel features in a sake of checkpoint/restore.
65920 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
65921 depends on OCFS2_FS = n
65922 depends on XFS_FS = n
65923
65924 + depends on GRKERNSEC = n
65925 +
65926 config UIDGID_STRICT_TYPE_CHECKS
65927 bool "Require conversions between uid/gids and their internal representation"
65928 depends on UIDGID_CONVERTED
65929 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
65930
65931 config COMPAT_BRK
65932 bool "Disable heap randomization"
65933 - default y
65934 + default n
65935 help
65936 Randomizing heap placement makes heap exploits harder, but it
65937 also breaks ancient binaries (including anything libc5 based).
65938 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
65939 config STOP_MACHINE
65940 bool
65941 default y
65942 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65943 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65944 help
65945 Need stop_machine() primitive.
65946
65947 diff --git a/init/Makefile b/init/Makefile
65948 index 7bc47ee..6da2dc7 100644
65949 --- a/init/Makefile
65950 +++ b/init/Makefile
65951 @@ -2,6 +2,9 @@
65952 # Makefile for the linux kernel.
65953 #
65954
65955 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65956 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65957 +
65958 obj-y := main.o version.o mounts.o
65959 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65960 obj-y += noinitramfs.o
65961 diff --git a/init/do_mounts.c b/init/do_mounts.c
65962 index f8a6642..4e5ee1b 100644
65963 --- a/init/do_mounts.c
65964 +++ b/init/do_mounts.c
65965 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65966 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65967 {
65968 struct super_block *s;
65969 - int err = sys_mount(name, "/root", fs, flags, data);
65970 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65971 if (err)
65972 return err;
65973
65974 - sys_chdir("/root");
65975 + sys_chdir((const char __force_user *)"/root");
65976 s = current->fs->pwd.dentry->d_sb;
65977 ROOT_DEV = s->s_dev;
65978 printk(KERN_INFO
65979 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
65980 va_start(args, fmt);
65981 vsprintf(buf, fmt, args);
65982 va_end(args);
65983 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65984 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65985 if (fd >= 0) {
65986 sys_ioctl(fd, FDEJECT, 0);
65987 sys_close(fd);
65988 }
65989 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65990 - fd = sys_open("/dev/console", O_RDWR, 0);
65991 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65992 if (fd >= 0) {
65993 sys_ioctl(fd, TCGETS, (long)&termios);
65994 termios.c_lflag &= ~ICANON;
65995 sys_ioctl(fd, TCSETSF, (long)&termios);
65996 - sys_read(fd, &c, 1);
65997 + sys_read(fd, (char __user *)&c, 1);
65998 termios.c_lflag |= ICANON;
65999 sys_ioctl(fd, TCSETSF, (long)&termios);
66000 sys_close(fd);
66001 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
66002 mount_root();
66003 out:
66004 devtmpfs_mount("dev");
66005 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66006 - sys_chroot(".");
66007 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66008 + sys_chroot((const char __force_user *)".");
66009 }
66010 diff --git a/init/do_mounts.h b/init/do_mounts.h
66011 index f5b978a..69dbfe8 100644
66012 --- a/init/do_mounts.h
66013 +++ b/init/do_mounts.h
66014 @@ -15,15 +15,15 @@ extern int root_mountflags;
66015
66016 static inline int create_dev(char *name, dev_t dev)
66017 {
66018 - sys_unlink(name);
66019 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66020 + sys_unlink((char __force_user *)name);
66021 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66022 }
66023
66024 #if BITS_PER_LONG == 32
66025 static inline u32 bstat(char *name)
66026 {
66027 struct stat64 stat;
66028 - if (sys_stat64(name, &stat) != 0)
66029 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66030 return 0;
66031 if (!S_ISBLK(stat.st_mode))
66032 return 0;
66033 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66034 static inline u32 bstat(char *name)
66035 {
66036 struct stat stat;
66037 - if (sys_newstat(name, &stat) != 0)
66038 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66039 return 0;
66040 if (!S_ISBLK(stat.st_mode))
66041 return 0;
66042 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66043 index 5e4ded5..aa3cd7e 100644
66044 --- a/init/do_mounts_initrd.c
66045 +++ b/init/do_mounts_initrd.c
66046 @@ -54,8 +54,8 @@ static void __init handle_initrd(void)
66047 create_dev("/dev/root.old", Root_RAM0);
66048 /* mount initrd on rootfs' /root */
66049 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66050 - sys_mkdir("/old", 0700);
66051 - sys_chdir("/old");
66052 + sys_mkdir((const char __force_user *)"/old", 0700);
66053 + sys_chdir((const char __force_user *)"/old");
66054
66055 /*
66056 * In case that a resume from disk is carried out by linuxrc or one of
66057 @@ -69,31 +69,31 @@ static void __init handle_initrd(void)
66058 current->flags &= ~PF_FREEZER_SKIP;
66059
66060 /* move initrd to rootfs' /old */
66061 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
66062 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
66063 /* switch root and cwd back to / of rootfs */
66064 - sys_chroot("..");
66065 + sys_chroot((const char __force_user *)"..");
66066
66067 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66068 - sys_chdir("/old");
66069 + sys_chdir((const char __force_user *)"/old");
66070 return;
66071 }
66072
66073 - sys_chdir("/");
66074 + sys_chdir((const char __force_user *)"/");
66075 ROOT_DEV = new_decode_dev(real_root_dev);
66076 mount_root();
66077
66078 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66079 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66080 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66081 if (!error)
66082 printk("okay\n");
66083 else {
66084 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66085 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66086 if (error == -ENOENT)
66087 printk("/initrd does not exist. Ignored.\n");
66088 else
66089 printk("failed\n");
66090 printk(KERN_NOTICE "Unmounting old root\n");
66091 - sys_umount("/old", MNT_DETACH);
66092 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66093 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66094 if (fd < 0) {
66095 error = fd;
66096 @@ -116,11 +116,11 @@ int __init initrd_load(void)
66097 * mounted in the normal path.
66098 */
66099 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66100 - sys_unlink("/initrd.image");
66101 + sys_unlink((const char __force_user *)"/initrd.image");
66102 handle_initrd();
66103 return 1;
66104 }
66105 }
66106 - sys_unlink("/initrd.image");
66107 + sys_unlink((const char __force_user *)"/initrd.image");
66108 return 0;
66109 }
66110 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66111 index 8cb6db5..d729f50 100644
66112 --- a/init/do_mounts_md.c
66113 +++ b/init/do_mounts_md.c
66114 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66115 partitioned ? "_d" : "", minor,
66116 md_setup_args[ent].device_names);
66117
66118 - fd = sys_open(name, 0, 0);
66119 + fd = sys_open((char __force_user *)name, 0, 0);
66120 if (fd < 0) {
66121 printk(KERN_ERR "md: open failed - cannot start "
66122 "array %s\n", name);
66123 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66124 * array without it
66125 */
66126 sys_close(fd);
66127 - fd = sys_open(name, 0, 0);
66128 + fd = sys_open((char __force_user *)name, 0, 0);
66129 sys_ioctl(fd, BLKRRPART, 0);
66130 }
66131 sys_close(fd);
66132 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66133
66134 wait_for_device_probe();
66135
66136 - fd = sys_open("/dev/md0", 0, 0);
66137 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66138 if (fd >= 0) {
66139 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66140 sys_close(fd);
66141 diff --git a/init/init_task.c b/init/init_task.c
66142 index 8b2f399..f0797c9 100644
66143 --- a/init/init_task.c
66144 +++ b/init/init_task.c
66145 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66146 * Initial thread structure. Alignment of this is handled by a special
66147 * linker map entry.
66148 */
66149 +#ifdef CONFIG_X86
66150 +union thread_union init_thread_union __init_task_data;
66151 +#else
66152 union thread_union init_thread_union __init_task_data =
66153 { INIT_THREAD_INFO(init_task) };
66154 +#endif
66155 diff --git a/init/initramfs.c b/init/initramfs.c
66156 index 84c6bf1..8899338 100644
66157 --- a/init/initramfs.c
66158 +++ b/init/initramfs.c
66159 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66160 }
66161 }
66162
66163 -static long __init do_utime(char *filename, time_t mtime)
66164 +static long __init do_utime(char __force_user *filename, time_t mtime)
66165 {
66166 struct timespec t[2];
66167
66168 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66169 struct dir_entry *de, *tmp;
66170 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66171 list_del(&de->list);
66172 - do_utime(de->name, de->mtime);
66173 + do_utime((char __force_user *)de->name, de->mtime);
66174 kfree(de->name);
66175 kfree(de);
66176 }
66177 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66178 if (nlink >= 2) {
66179 char *old = find_link(major, minor, ino, mode, collected);
66180 if (old)
66181 - return (sys_link(old, collected) < 0) ? -1 : 1;
66182 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66183 }
66184 return 0;
66185 }
66186 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66187 {
66188 struct stat st;
66189
66190 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66191 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66192 if (S_ISDIR(st.st_mode))
66193 - sys_rmdir(path);
66194 + sys_rmdir((char __force_user *)path);
66195 else
66196 - sys_unlink(path);
66197 + sys_unlink((char __force_user *)path);
66198 }
66199 }
66200
66201 @@ -315,7 +315,7 @@ static int __init do_name(void)
66202 int openflags = O_WRONLY|O_CREAT;
66203 if (ml != 1)
66204 openflags |= O_TRUNC;
66205 - wfd = sys_open(collected, openflags, mode);
66206 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66207
66208 if (wfd >= 0) {
66209 sys_fchown(wfd, uid, gid);
66210 @@ -327,17 +327,17 @@ static int __init do_name(void)
66211 }
66212 }
66213 } else if (S_ISDIR(mode)) {
66214 - sys_mkdir(collected, mode);
66215 - sys_chown(collected, uid, gid);
66216 - sys_chmod(collected, mode);
66217 + sys_mkdir((char __force_user *)collected, mode);
66218 + sys_chown((char __force_user *)collected, uid, gid);
66219 + sys_chmod((char __force_user *)collected, mode);
66220 dir_add(collected, mtime);
66221 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66222 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66223 if (maybe_link() == 0) {
66224 - sys_mknod(collected, mode, rdev);
66225 - sys_chown(collected, uid, gid);
66226 - sys_chmod(collected, mode);
66227 - do_utime(collected, mtime);
66228 + sys_mknod((char __force_user *)collected, mode, rdev);
66229 + sys_chown((char __force_user *)collected, uid, gid);
66230 + sys_chmod((char __force_user *)collected, mode);
66231 + do_utime((char __force_user *)collected, mtime);
66232 }
66233 }
66234 return 0;
66235 @@ -346,15 +346,15 @@ static int __init do_name(void)
66236 static int __init do_copy(void)
66237 {
66238 if (count >= body_len) {
66239 - sys_write(wfd, victim, body_len);
66240 + sys_write(wfd, (char __force_user *)victim, body_len);
66241 sys_close(wfd);
66242 - do_utime(vcollected, mtime);
66243 + do_utime((char __force_user *)vcollected, mtime);
66244 kfree(vcollected);
66245 eat(body_len);
66246 state = SkipIt;
66247 return 0;
66248 } else {
66249 - sys_write(wfd, victim, count);
66250 + sys_write(wfd, (char __force_user *)victim, count);
66251 body_len -= count;
66252 eat(count);
66253 return 1;
66254 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66255 {
66256 collected[N_ALIGN(name_len) + body_len] = '\0';
66257 clean_path(collected, 0);
66258 - sys_symlink(collected + N_ALIGN(name_len), collected);
66259 - sys_lchown(collected, uid, gid);
66260 - do_utime(collected, mtime);
66261 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66262 + sys_lchown((char __force_user *)collected, uid, gid);
66263 + do_utime((char __force_user *)collected, mtime);
66264 state = SkipIt;
66265 next_state = Reset;
66266 return 0;
66267 diff --git a/init/main.c b/init/main.c
66268 index e33e09d..8544e50 100644
66269 --- a/init/main.c
66270 +++ b/init/main.c
66271 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66272 extern void tc_init(void);
66273 #endif
66274
66275 +extern void grsecurity_init(void);
66276 +
66277 /*
66278 * Debug helper: via this flag we know that we are in 'early bootup code'
66279 * where only the boot processor is running with IRQ disabled. This means
66280 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66281
66282 __setup("reset_devices", set_reset_devices);
66283
66284 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66285 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66286 +static int __init setup_grsec_proc_gid(char *str)
66287 +{
66288 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66289 + return 1;
66290 +}
66291 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66292 +#endif
66293 +
66294 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66295 +extern char pax_enter_kernel_user[];
66296 +extern char pax_exit_kernel_user[];
66297 +extern pgdval_t clone_pgd_mask;
66298 +#endif
66299 +
66300 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66301 +static int __init setup_pax_nouderef(char *str)
66302 +{
66303 +#ifdef CONFIG_X86_32
66304 + unsigned int cpu;
66305 + struct desc_struct *gdt;
66306 +
66307 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66308 + gdt = get_cpu_gdt_table(cpu);
66309 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66310 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66311 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66312 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66313 + }
66314 + loadsegment(ds, __KERNEL_DS);
66315 + loadsegment(es, __KERNEL_DS);
66316 + loadsegment(ss, __KERNEL_DS);
66317 +#else
66318 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66319 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66320 + clone_pgd_mask = ~(pgdval_t)0UL;
66321 +#endif
66322 +
66323 + return 0;
66324 +}
66325 +early_param("pax_nouderef", setup_pax_nouderef);
66326 +#endif
66327 +
66328 +#ifdef CONFIG_PAX_SOFTMODE
66329 +int pax_softmode;
66330 +
66331 +static int __init setup_pax_softmode(char *str)
66332 +{
66333 + get_option(&str, &pax_softmode);
66334 + return 1;
66335 +}
66336 +__setup("pax_softmode=", setup_pax_softmode);
66337 +#endif
66338 +
66339 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66340 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66341 static const char *panic_later, *panic_param;
66342 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66343 {
66344 int count = preempt_count();
66345 int ret;
66346 + const char *msg1 = "", *msg2 = "";
66347
66348 if (initcall_debug)
66349 ret = do_one_initcall_debug(fn);
66350 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66351 sprintf(msgbuf, "error code %d ", ret);
66352
66353 if (preempt_count() != count) {
66354 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66355 + msg1 = " preemption imbalance";
66356 preempt_count() = count;
66357 }
66358 if (irqs_disabled()) {
66359 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66360 + msg2 = " disabled interrupts";
66361 local_irq_enable();
66362 }
66363 - if (msgbuf[0]) {
66364 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66365 + if (msgbuf[0] || *msg1 || *msg2) {
66366 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66367 }
66368
66369 return ret;
66370 @@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
66371 level, level,
66372 &repair_env_string);
66373
66374 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66375 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66376 do_one_initcall(*fn);
66377 +
66378 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66379 + transfer_latent_entropy();
66380 +#endif
66381 +
66382 + }
66383 }
66384
66385 static void __init do_initcalls(void)
66386 @@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
66387 {
66388 initcall_t *fn;
66389
66390 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66391 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66392 do_one_initcall(*fn);
66393 +
66394 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66395 + transfer_latent_entropy();
66396 +#endif
66397 +
66398 + }
66399 }
66400
66401 static int run_init_process(const char *init_filename)
66402 @@ -876,7 +946,7 @@ static void __init kernel_init_freeable(void)
66403 do_basic_setup();
66404
66405 /* Open the /dev/console on the rootfs, this should never fail */
66406 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66407 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66408 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66409
66410 (void) sys_dup(0);
66411 @@ -889,11 +959,13 @@ static void __init kernel_init_freeable(void)
66412 if (!ramdisk_execute_command)
66413 ramdisk_execute_command = "/init";
66414
66415 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66416 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66417 ramdisk_execute_command = NULL;
66418 prepare_namespace();
66419 }
66420
66421 + grsecurity_init();
66422 +
66423 /*
66424 * Ok, we have completed the initial bootup, and
66425 * we're essentially up and running. Get rid of the
66426 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66427 index 71a3ca1..cc330ee 100644
66428 --- a/ipc/mqueue.c
66429 +++ b/ipc/mqueue.c
66430 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66431 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66432 info->attr.mq_msgsize);
66433
66434 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66435 spin_lock(&mq_lock);
66436 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66437 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66438 diff --git a/ipc/msg.c b/ipc/msg.c
66439 index a71af5a..a90a110 100644
66440 --- a/ipc/msg.c
66441 +++ b/ipc/msg.c
66442 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66443 return security_msg_queue_associate(msq, msgflg);
66444 }
66445
66446 +static struct ipc_ops msg_ops = {
66447 + .getnew = newque,
66448 + .associate = msg_security,
66449 + .more_checks = NULL
66450 +};
66451 +
66452 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66453 {
66454 struct ipc_namespace *ns;
66455 - struct ipc_ops msg_ops;
66456 struct ipc_params msg_params;
66457
66458 ns = current->nsproxy->ipc_ns;
66459
66460 - msg_ops.getnew = newque;
66461 - msg_ops.associate = msg_security;
66462 - msg_ops.more_checks = NULL;
66463 -
66464 msg_params.key = key;
66465 msg_params.flg = msgflg;
66466
66467 diff --git a/ipc/sem.c b/ipc/sem.c
66468 index 58d31f1..cce7a55 100644
66469 --- a/ipc/sem.c
66470 +++ b/ipc/sem.c
66471 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66472 return 0;
66473 }
66474
66475 +static struct ipc_ops sem_ops = {
66476 + .getnew = newary,
66477 + .associate = sem_security,
66478 + .more_checks = sem_more_checks
66479 +};
66480 +
66481 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66482 {
66483 struct ipc_namespace *ns;
66484 - struct ipc_ops sem_ops;
66485 struct ipc_params sem_params;
66486
66487 ns = current->nsproxy->ipc_ns;
66488 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66489 if (nsems < 0 || nsems > ns->sc_semmsl)
66490 return -EINVAL;
66491
66492 - sem_ops.getnew = newary;
66493 - sem_ops.associate = sem_security;
66494 - sem_ops.more_checks = sem_more_checks;
66495 -
66496 sem_params.key = key;
66497 sem_params.flg = semflg;
66498 sem_params.u.nsems = nsems;
66499 diff --git a/ipc/shm.c b/ipc/shm.c
66500 index dff40c9..9450e27 100644
66501 --- a/ipc/shm.c
66502 +++ b/ipc/shm.c
66503 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66504 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66505 #endif
66506
66507 +#ifdef CONFIG_GRKERNSEC
66508 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66509 + const time_t shm_createtime, const uid_t cuid,
66510 + const int shmid);
66511 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66512 + const time_t shm_createtime);
66513 +#endif
66514 +
66515 void shm_init_ns(struct ipc_namespace *ns)
66516 {
66517 ns->shm_ctlmax = SHMMAX;
66518 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66519 shp->shm_lprid = 0;
66520 shp->shm_atim = shp->shm_dtim = 0;
66521 shp->shm_ctim = get_seconds();
66522 +#ifdef CONFIG_GRKERNSEC
66523 + {
66524 + struct timespec timeval;
66525 + do_posix_clock_monotonic_gettime(&timeval);
66526 +
66527 + shp->shm_createtime = timeval.tv_sec;
66528 + }
66529 +#endif
66530 shp->shm_segsz = size;
66531 shp->shm_nattch = 0;
66532 shp->shm_file = file;
66533 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66534 return 0;
66535 }
66536
66537 +static struct ipc_ops shm_ops = {
66538 + .getnew = newseg,
66539 + .associate = shm_security,
66540 + .more_checks = shm_more_checks
66541 +};
66542 +
66543 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66544 {
66545 struct ipc_namespace *ns;
66546 - struct ipc_ops shm_ops;
66547 struct ipc_params shm_params;
66548
66549 ns = current->nsproxy->ipc_ns;
66550
66551 - shm_ops.getnew = newseg;
66552 - shm_ops.associate = shm_security;
66553 - shm_ops.more_checks = shm_more_checks;
66554 -
66555 shm_params.key = key;
66556 shm_params.flg = shmflg;
66557 shm_params.u.size = size;
66558 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66559 f_mode = FMODE_READ | FMODE_WRITE;
66560 }
66561 if (shmflg & SHM_EXEC) {
66562 +
66563 +#ifdef CONFIG_PAX_MPROTECT
66564 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66565 + goto out;
66566 +#endif
66567 +
66568 prot |= PROT_EXEC;
66569 acc_mode |= S_IXUGO;
66570 }
66571 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66572 if (err)
66573 goto out_unlock;
66574
66575 +#ifdef CONFIG_GRKERNSEC
66576 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66577 + shp->shm_perm.cuid, shmid) ||
66578 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66579 + err = -EACCES;
66580 + goto out_unlock;
66581 + }
66582 +#endif
66583 +
66584 path = shp->shm_file->f_path;
66585 path_get(&path);
66586 shp->shm_nattch++;
66587 +#ifdef CONFIG_GRKERNSEC
66588 + shp->shm_lapid = current->pid;
66589 +#endif
66590 size = i_size_read(path.dentry->d_inode);
66591 shm_unlock(shp);
66592
66593 diff --git a/kernel/acct.c b/kernel/acct.c
66594 index 051e071..15e0920 100644
66595 --- a/kernel/acct.c
66596 +++ b/kernel/acct.c
66597 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66598 */
66599 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66600 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66601 - file->f_op->write(file, (char *)&ac,
66602 + file->f_op->write(file, (char __force_user *)&ac,
66603 sizeof(acct_t), &file->f_pos);
66604 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66605 set_fs(fs);
66606 diff --git a/kernel/audit.c b/kernel/audit.c
66607 index 40414e9..c920b72 100644
66608 --- a/kernel/audit.c
66609 +++ b/kernel/audit.c
66610 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
66611 3) suppressed due to audit_rate_limit
66612 4) suppressed due to audit_backlog_limit
66613 */
66614 -static atomic_t audit_lost = ATOMIC_INIT(0);
66615 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66616
66617 /* The netlink socket. */
66618 static struct sock *audit_sock;
66619 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
66620 unsigned long now;
66621 int print;
66622
66623 - atomic_inc(&audit_lost);
66624 + atomic_inc_unchecked(&audit_lost);
66625
66626 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66627
66628 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
66629 printk(KERN_WARNING
66630 "audit: audit_lost=%d audit_rate_limit=%d "
66631 "audit_backlog_limit=%d\n",
66632 - atomic_read(&audit_lost),
66633 + atomic_read_unchecked(&audit_lost),
66634 audit_rate_limit,
66635 audit_backlog_limit);
66636 audit_panic(message);
66637 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66638 status_set.pid = audit_pid;
66639 status_set.rate_limit = audit_rate_limit;
66640 status_set.backlog_limit = audit_backlog_limit;
66641 - status_set.lost = atomic_read(&audit_lost);
66642 + status_set.lost = atomic_read_unchecked(&audit_lost);
66643 status_set.backlog = skb_queue_len(&audit_skb_queue);
66644 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
66645 &status_set, sizeof(status_set));
66646 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66647 index 2f186ed..afb42c2 100644
66648 --- a/kernel/auditsc.c
66649 +++ b/kernel/auditsc.c
66650 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66651 }
66652
66653 /* global counter which is incremented every time something logs in */
66654 -static atomic_t session_id = ATOMIC_INIT(0);
66655 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66656
66657 /**
66658 * audit_set_loginuid - set current task's audit_context loginuid
66659 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
66660 return -EPERM;
66661 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66662
66663 - sessionid = atomic_inc_return(&session_id);
66664 + sessionid = atomic_inc_return_unchecked(&session_id);
66665 if (context && context->in_syscall) {
66666 struct audit_buffer *ab;
66667
66668 diff --git a/kernel/capability.c b/kernel/capability.c
66669 index 493d972..ea17248 100644
66670 --- a/kernel/capability.c
66671 +++ b/kernel/capability.c
66672 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66673 * before modification is attempted and the application
66674 * fails.
66675 */
66676 + if (tocopy > ARRAY_SIZE(kdata))
66677 + return -EFAULT;
66678 +
66679 if (copy_to_user(dataptr, kdata, tocopy
66680 * sizeof(struct __user_cap_data_struct))) {
66681 return -EFAULT;
66682 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66683 int ret;
66684
66685 rcu_read_lock();
66686 - ret = security_capable(__task_cred(t), ns, cap);
66687 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66688 + gr_task_is_capable(t, __task_cred(t), cap);
66689 rcu_read_unlock();
66690
66691 - return (ret == 0);
66692 + return ret;
66693 }
66694
66695 /**
66696 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66697 int ret;
66698
66699 rcu_read_lock();
66700 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66701 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66702 rcu_read_unlock();
66703
66704 - return (ret == 0);
66705 + return ret;
66706 }
66707
66708 /**
66709 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66710 BUG();
66711 }
66712
66713 - if (security_capable(current_cred(), ns, cap) == 0) {
66714 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66715 current->flags |= PF_SUPERPRIV;
66716 return true;
66717 }
66718 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66719 }
66720 EXPORT_SYMBOL(ns_capable);
66721
66722 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66723 +{
66724 + if (unlikely(!cap_valid(cap))) {
66725 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66726 + BUG();
66727 + }
66728 +
66729 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66730 + current->flags |= PF_SUPERPRIV;
66731 + return true;
66732 + }
66733 + return false;
66734 +}
66735 +EXPORT_SYMBOL(ns_capable_nolog);
66736 +
66737 /**
66738 * capable - Determine if the current task has a superior capability in effect
66739 * @cap: The capability to be tested for
66740 @@ -408,6 +427,12 @@ bool capable(int cap)
66741 }
66742 EXPORT_SYMBOL(capable);
66743
66744 +bool capable_nolog(int cap)
66745 +{
66746 + return ns_capable_nolog(&init_user_ns, cap);
66747 +}
66748 +EXPORT_SYMBOL(capable_nolog);
66749 +
66750 /**
66751 * nsown_capable - Check superior capability to one's own user_ns
66752 * @cap: The capability in question
66753 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66754
66755 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66756 }
66757 +
66758 +bool inode_capable_nolog(const struct inode *inode, int cap)
66759 +{
66760 + struct user_namespace *ns = current_user_ns();
66761 +
66762 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66763 +}
66764 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66765 index f24f724..0612ec45 100644
66766 --- a/kernel/cgroup.c
66767 +++ b/kernel/cgroup.c
66768 @@ -5518,7 +5518,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66769 struct css_set *cg = link->cg;
66770 struct task_struct *task;
66771 int count = 0;
66772 - seq_printf(seq, "css_set %p\n", cg);
66773 + seq_printf(seq, "css_set %pK\n", cg);
66774 list_for_each_entry(task, &cg->tasks, cg_list) {
66775 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66776 seq_puts(seq, " ...\n");
66777 diff --git a/kernel/compat.c b/kernel/compat.c
66778 index c28a306..b4d0cf3 100644
66779 --- a/kernel/compat.c
66780 +++ b/kernel/compat.c
66781 @@ -13,6 +13,7 @@
66782
66783 #include <linux/linkage.h>
66784 #include <linux/compat.h>
66785 +#include <linux/module.h>
66786 #include <linux/errno.h>
66787 #include <linux/time.h>
66788 #include <linux/signal.h>
66789 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66790 mm_segment_t oldfs;
66791 long ret;
66792
66793 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66794 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66795 oldfs = get_fs();
66796 set_fs(KERNEL_DS);
66797 ret = hrtimer_nanosleep_restart(restart);
66798 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66799 oldfs = get_fs();
66800 set_fs(KERNEL_DS);
66801 ret = hrtimer_nanosleep(&tu,
66802 - rmtp ? (struct timespec __user *)&rmt : NULL,
66803 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66804 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66805 set_fs(oldfs);
66806
66807 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66808 mm_segment_t old_fs = get_fs();
66809
66810 set_fs(KERNEL_DS);
66811 - ret = sys_sigpending((old_sigset_t __user *) &s);
66812 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66813 set_fs(old_fs);
66814 if (ret == 0)
66815 ret = put_user(s, set);
66816 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66817 mm_segment_t old_fs = get_fs();
66818
66819 set_fs(KERNEL_DS);
66820 - ret = sys_old_getrlimit(resource, &r);
66821 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66822 set_fs(old_fs);
66823
66824 if (!ret) {
66825 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66826 mm_segment_t old_fs = get_fs();
66827
66828 set_fs(KERNEL_DS);
66829 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66830 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66831 set_fs(old_fs);
66832
66833 if (ret)
66834 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66835 set_fs (KERNEL_DS);
66836 ret = sys_wait4(pid,
66837 (stat_addr ?
66838 - (unsigned int __user *) &status : NULL),
66839 - options, (struct rusage __user *) &r);
66840 + (unsigned int __force_user *) &status : NULL),
66841 + options, (struct rusage __force_user *) &r);
66842 set_fs (old_fs);
66843
66844 if (ret > 0) {
66845 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66846 memset(&info, 0, sizeof(info));
66847
66848 set_fs(KERNEL_DS);
66849 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66850 - uru ? (struct rusage __user *)&ru : NULL);
66851 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66852 + uru ? (struct rusage __force_user *)&ru : NULL);
66853 set_fs(old_fs);
66854
66855 if ((ret < 0) || (info.si_signo == 0))
66856 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66857 oldfs = get_fs();
66858 set_fs(KERNEL_DS);
66859 err = sys_timer_settime(timer_id, flags,
66860 - (struct itimerspec __user *) &newts,
66861 - (struct itimerspec __user *) &oldts);
66862 + (struct itimerspec __force_user *) &newts,
66863 + (struct itimerspec __force_user *) &oldts);
66864 set_fs(oldfs);
66865 if (!err && old && put_compat_itimerspec(old, &oldts))
66866 return -EFAULT;
66867 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66868 oldfs = get_fs();
66869 set_fs(KERNEL_DS);
66870 err = sys_timer_gettime(timer_id,
66871 - (struct itimerspec __user *) &ts);
66872 + (struct itimerspec __force_user *) &ts);
66873 set_fs(oldfs);
66874 if (!err && put_compat_itimerspec(setting, &ts))
66875 return -EFAULT;
66876 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66877 oldfs = get_fs();
66878 set_fs(KERNEL_DS);
66879 err = sys_clock_settime(which_clock,
66880 - (struct timespec __user *) &ts);
66881 + (struct timespec __force_user *) &ts);
66882 set_fs(oldfs);
66883 return err;
66884 }
66885 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66886 oldfs = get_fs();
66887 set_fs(KERNEL_DS);
66888 err = sys_clock_gettime(which_clock,
66889 - (struct timespec __user *) &ts);
66890 + (struct timespec __force_user *) &ts);
66891 set_fs(oldfs);
66892 if (!err && put_compat_timespec(&ts, tp))
66893 return -EFAULT;
66894 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66895
66896 oldfs = get_fs();
66897 set_fs(KERNEL_DS);
66898 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66899 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66900 set_fs(oldfs);
66901
66902 err = compat_put_timex(utp, &txc);
66903 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66904 oldfs = get_fs();
66905 set_fs(KERNEL_DS);
66906 err = sys_clock_getres(which_clock,
66907 - (struct timespec __user *) &ts);
66908 + (struct timespec __force_user *) &ts);
66909 set_fs(oldfs);
66910 if (!err && tp && put_compat_timespec(&ts, tp))
66911 return -EFAULT;
66912 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66913 long err;
66914 mm_segment_t oldfs;
66915 struct timespec tu;
66916 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66917 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66918
66919 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66920 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66921 oldfs = get_fs();
66922 set_fs(KERNEL_DS);
66923 err = clock_nanosleep_restart(restart);
66924 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66925 oldfs = get_fs();
66926 set_fs(KERNEL_DS);
66927 err = sys_clock_nanosleep(which_clock, flags,
66928 - (struct timespec __user *) &in,
66929 - (struct timespec __user *) &out);
66930 + (struct timespec __force_user *) &in,
66931 + (struct timespec __force_user *) &out);
66932 set_fs(oldfs);
66933
66934 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66935 diff --git a/kernel/configs.c b/kernel/configs.c
66936 index 42e8fa0..9e7406b 100644
66937 --- a/kernel/configs.c
66938 +++ b/kernel/configs.c
66939 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66940 struct proc_dir_entry *entry;
66941
66942 /* create the current config file */
66943 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66944 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66945 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66946 + &ikconfig_file_ops);
66947 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66948 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66949 + &ikconfig_file_ops);
66950 +#endif
66951 +#else
66952 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66953 &ikconfig_file_ops);
66954 +#endif
66955 +
66956 if (!entry)
66957 return -ENOMEM;
66958
66959 diff --git a/kernel/cred.c b/kernel/cred.c
66960 index 48cea3d..3476734 100644
66961 --- a/kernel/cred.c
66962 +++ b/kernel/cred.c
66963 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66964 validate_creds(cred);
66965 alter_cred_subscribers(cred, -1);
66966 put_cred(cred);
66967 +
66968 +#ifdef CONFIG_GRKERNSEC_SETXID
66969 + cred = (struct cred *) tsk->delayed_cred;
66970 + if (cred != NULL) {
66971 + tsk->delayed_cred = NULL;
66972 + validate_creds(cred);
66973 + alter_cred_subscribers(cred, -1);
66974 + put_cred(cred);
66975 + }
66976 +#endif
66977 }
66978
66979 /**
66980 @@ -469,7 +479,7 @@ error_put:
66981 * Always returns 0 thus allowing this function to be tail-called at the end
66982 * of, say, sys_setgid().
66983 */
66984 -int commit_creds(struct cred *new)
66985 +static int __commit_creds(struct cred *new)
66986 {
66987 struct task_struct *task = current;
66988 const struct cred *old = task->real_cred;
66989 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66990
66991 get_cred(new); /* we will require a ref for the subj creds too */
66992
66993 + gr_set_role_label(task, new->uid, new->gid);
66994 +
66995 /* dumpability changes */
66996 if (!uid_eq(old->euid, new->euid) ||
66997 !gid_eq(old->egid, new->egid) ||
66998 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66999 put_cred(old);
67000 return 0;
67001 }
67002 +#ifdef CONFIG_GRKERNSEC_SETXID
67003 +extern int set_user(struct cred *new);
67004 +
67005 +void gr_delayed_cred_worker(void)
67006 +{
67007 + const struct cred *new = current->delayed_cred;
67008 + struct cred *ncred;
67009 +
67010 + current->delayed_cred = NULL;
67011 +
67012 + if (current_uid() && new != NULL) {
67013 + // from doing get_cred on it when queueing this
67014 + put_cred(new);
67015 + return;
67016 + } else if (new == NULL)
67017 + return;
67018 +
67019 + ncred = prepare_creds();
67020 + if (!ncred)
67021 + goto die;
67022 + // uids
67023 + ncred->uid = new->uid;
67024 + ncred->euid = new->euid;
67025 + ncred->suid = new->suid;
67026 + ncred->fsuid = new->fsuid;
67027 + // gids
67028 + ncred->gid = new->gid;
67029 + ncred->egid = new->egid;
67030 + ncred->sgid = new->sgid;
67031 + ncred->fsgid = new->fsgid;
67032 + // groups
67033 + if (set_groups(ncred, new->group_info) < 0) {
67034 + abort_creds(ncred);
67035 + goto die;
67036 + }
67037 + // caps
67038 + ncred->securebits = new->securebits;
67039 + ncred->cap_inheritable = new->cap_inheritable;
67040 + ncred->cap_permitted = new->cap_permitted;
67041 + ncred->cap_effective = new->cap_effective;
67042 + ncred->cap_bset = new->cap_bset;
67043 +
67044 + if (set_user(ncred)) {
67045 + abort_creds(ncred);
67046 + goto die;
67047 + }
67048 +
67049 + // from doing get_cred on it when queueing this
67050 + put_cred(new);
67051 +
67052 + __commit_creds(ncred);
67053 + return;
67054 +die:
67055 + // from doing get_cred on it when queueing this
67056 + put_cred(new);
67057 + do_group_exit(SIGKILL);
67058 +}
67059 +#endif
67060 +
67061 +int commit_creds(struct cred *new)
67062 +{
67063 +#ifdef CONFIG_GRKERNSEC_SETXID
67064 + int ret;
67065 + int schedule_it = 0;
67066 + struct task_struct *t;
67067 +
67068 + /* we won't get called with tasklist_lock held for writing
67069 + and interrupts disabled as the cred struct in that case is
67070 + init_cred
67071 + */
67072 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67073 + !current_uid() && new->uid) {
67074 + schedule_it = 1;
67075 + }
67076 + ret = __commit_creds(new);
67077 + if (schedule_it) {
67078 + rcu_read_lock();
67079 + read_lock(&tasklist_lock);
67080 + for (t = next_thread(current); t != current;
67081 + t = next_thread(t)) {
67082 + if (t->delayed_cred == NULL) {
67083 + t->delayed_cred = get_cred(new);
67084 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67085 + set_tsk_need_resched(t);
67086 + }
67087 + }
67088 + read_unlock(&tasklist_lock);
67089 + rcu_read_unlock();
67090 + }
67091 + return ret;
67092 +#else
67093 + return __commit_creds(new);
67094 +#endif
67095 +}
67096 +
67097 EXPORT_SYMBOL(commit_creds);
67098
67099 /**
67100 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67101 index 9a61738..c5c8f3a 100644
67102 --- a/kernel/debug/debug_core.c
67103 +++ b/kernel/debug/debug_core.c
67104 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67105 */
67106 static atomic_t masters_in_kgdb;
67107 static atomic_t slaves_in_kgdb;
67108 -static atomic_t kgdb_break_tasklet_var;
67109 +static atomic_unchecked_t kgdb_break_tasklet_var;
67110 atomic_t kgdb_setting_breakpoint;
67111
67112 struct task_struct *kgdb_usethread;
67113 @@ -132,7 +132,7 @@ int kgdb_single_step;
67114 static pid_t kgdb_sstep_pid;
67115
67116 /* to keep track of the CPU which is doing the single stepping*/
67117 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67118 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67119
67120 /*
67121 * If you are debugging a problem where roundup (the collection of
67122 @@ -540,7 +540,7 @@ return_normal:
67123 * kernel will only try for the value of sstep_tries before
67124 * giving up and continuing on.
67125 */
67126 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67127 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67128 (kgdb_info[cpu].task &&
67129 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67130 atomic_set(&kgdb_active, -1);
67131 @@ -634,8 +634,8 @@ cpu_master_loop:
67132 }
67133
67134 kgdb_restore:
67135 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67136 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67137 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67138 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67139 if (kgdb_info[sstep_cpu].task)
67140 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67141 else
67142 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
67143 static void kgdb_tasklet_bpt(unsigned long ing)
67144 {
67145 kgdb_breakpoint();
67146 - atomic_set(&kgdb_break_tasklet_var, 0);
67147 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67148 }
67149
67150 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67151
67152 void kgdb_schedule_breakpoint(void)
67153 {
67154 - if (atomic_read(&kgdb_break_tasklet_var) ||
67155 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67156 atomic_read(&kgdb_active) != -1 ||
67157 atomic_read(&kgdb_setting_breakpoint))
67158 return;
67159 - atomic_inc(&kgdb_break_tasklet_var);
67160 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67161 tasklet_schedule(&kgdb_tasklet_breakpoint);
67162 }
67163 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67164 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67165 index 4d5f8d5..4743f33 100644
67166 --- a/kernel/debug/kdb/kdb_main.c
67167 +++ b/kernel/debug/kdb/kdb_main.c
67168 @@ -1972,7 +1972,7 @@ static int kdb_lsmod(int argc, const char **argv)
67169 list_for_each_entry(mod, kdb_modules, list) {
67170
67171 kdb_printf("%-20s%8u 0x%p ", mod->name,
67172 - mod->core_size, (void *)mod);
67173 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67174 #ifdef CONFIG_MODULE_UNLOAD
67175 kdb_printf("%4ld ", module_refcount(mod));
67176 #endif
67177 @@ -1982,7 +1982,7 @@ static int kdb_lsmod(int argc, const char **argv)
67178 kdb_printf(" (Loading)");
67179 else
67180 kdb_printf(" (Live)");
67181 - kdb_printf(" 0x%p", mod->module_core);
67182 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67183
67184 #ifdef CONFIG_MODULE_UNLOAD
67185 {
67186 diff --git a/kernel/events/core.c b/kernel/events/core.c
67187 index dbccf83..8c66482 100644
67188 --- a/kernel/events/core.c
67189 +++ b/kernel/events/core.c
67190 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67191 return 0;
67192 }
67193
67194 -static atomic64_t perf_event_id;
67195 +static atomic64_unchecked_t perf_event_id;
67196
67197 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67198 enum event_type_t event_type);
67199 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
67200
67201 static inline u64 perf_event_count(struct perf_event *event)
67202 {
67203 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67204 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67205 }
67206
67207 static u64 perf_event_read(struct perf_event *event)
67208 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67209 mutex_lock(&event->child_mutex);
67210 total += perf_event_read(event);
67211 *enabled += event->total_time_enabled +
67212 - atomic64_read(&event->child_total_time_enabled);
67213 + atomic64_read_unchecked(&event->child_total_time_enabled);
67214 *running += event->total_time_running +
67215 - atomic64_read(&event->child_total_time_running);
67216 + atomic64_read_unchecked(&event->child_total_time_running);
67217
67218 list_for_each_entry(child, &event->child_list, child_list) {
67219 total += perf_event_read(child);
67220 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
67221 userpg->offset -= local64_read(&event->hw.prev_count);
67222
67223 userpg->time_enabled = enabled +
67224 - atomic64_read(&event->child_total_time_enabled);
67225 + atomic64_read_unchecked(&event->child_total_time_enabled);
67226
67227 userpg->time_running = running +
67228 - atomic64_read(&event->child_total_time_running);
67229 + atomic64_read_unchecked(&event->child_total_time_running);
67230
67231 arch_perf_update_userpage(userpg, now);
67232
67233 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67234 values[n++] = perf_event_count(event);
67235 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67236 values[n++] = enabled +
67237 - atomic64_read(&event->child_total_time_enabled);
67238 + atomic64_read_unchecked(&event->child_total_time_enabled);
67239 }
67240 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67241 values[n++] = running +
67242 - atomic64_read(&event->child_total_time_running);
67243 + atomic64_read_unchecked(&event->child_total_time_running);
67244 }
67245 if (read_format & PERF_FORMAT_ID)
67246 values[n++] = primary_event_id(event);
67247 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67248 * need to add enough zero bytes after the string to handle
67249 * the 64bit alignment we do later.
67250 */
67251 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67252 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67253 if (!buf) {
67254 name = strncpy(tmp, "//enomem", sizeof(tmp));
67255 goto got_name;
67256 }
67257 - name = d_path(&file->f_path, buf, PATH_MAX);
67258 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67259 if (IS_ERR(name)) {
67260 name = strncpy(tmp, "//toolong", sizeof(tmp));
67261 goto got_name;
67262 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67263 event->parent = parent_event;
67264
67265 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67266 - event->id = atomic64_inc_return(&perf_event_id);
67267 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67268
67269 event->state = PERF_EVENT_STATE_INACTIVE;
67270
67271 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
67272 /*
67273 * Add back the child's count to the parent's count:
67274 */
67275 - atomic64_add(child_val, &parent_event->child_count);
67276 - atomic64_add(child_event->total_time_enabled,
67277 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67278 + atomic64_add_unchecked(child_event->total_time_enabled,
67279 &parent_event->child_total_time_enabled);
67280 - atomic64_add(child_event->total_time_running,
67281 + atomic64_add_unchecked(child_event->total_time_running,
67282 &parent_event->child_total_time_running);
67283
67284 /*
67285 diff --git a/kernel/exit.c b/kernel/exit.c
67286 index 346616c..a86ec83 100644
67287 --- a/kernel/exit.c
67288 +++ b/kernel/exit.c
67289 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67290 struct task_struct *leader;
67291 int zap_leader;
67292 repeat:
67293 +#ifdef CONFIG_NET
67294 + gr_del_task_from_ip_table(p);
67295 +#endif
67296 +
67297 /* don't need to get the RCU readlock here - the process is dead and
67298 * can't be modifying its own credentials. But shut RCU-lockdep up */
67299 rcu_read_lock();
67300 @@ -394,7 +398,7 @@ int allow_signal(int sig)
67301 * know it'll be handled, so that they don't get converted to
67302 * SIGKILL or just silently dropped.
67303 */
67304 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67305 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67306 recalc_sigpending();
67307 spin_unlock_irq(&current->sighand->siglock);
67308 return 0;
67309 @@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67310 vsnprintf(current->comm, sizeof(current->comm), name, args);
67311 va_end(args);
67312
67313 + gr_set_kernel_label(current);
67314 +
67315 /*
67316 * If we were started as result of loading a module, close all of the
67317 * user space pages. We don't need them, and if we didn't close them
67318 @@ -812,6 +818,8 @@ void do_exit(long code)
67319 struct task_struct *tsk = current;
67320 int group_dead;
67321
67322 + set_fs(USER_DS);
67323 +
67324 profile_task_exit(tsk);
67325
67326 WARN_ON(blk_needs_flush_plug(tsk));
67327 @@ -828,7 +836,6 @@ void do_exit(long code)
67328 * mm_release()->clear_child_tid() from writing to a user-controlled
67329 * kernel address.
67330 */
67331 - set_fs(USER_DS);
67332
67333 ptrace_event(PTRACE_EVENT_EXIT, code);
67334
67335 @@ -887,6 +894,9 @@ void do_exit(long code)
67336 tsk->exit_code = code;
67337 taskstats_exit(tsk, group_dead);
67338
67339 + gr_acl_handle_psacct(tsk, code);
67340 + gr_acl_handle_exit();
67341 +
67342 exit_mm(tsk);
67343
67344 if (group_dead)
67345 @@ -1007,7 +1017,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67346 * Take down every thread in the group. This is called by fatal signals
67347 * as well as by sys_exit_group (below).
67348 */
67349 -void
67350 +__noreturn void
67351 do_group_exit(int exit_code)
67352 {
67353 struct signal_struct *sig = current->signal;
67354 diff --git a/kernel/fork.c b/kernel/fork.c
67355 index 8b20ab7..58f2e45 100644
67356 --- a/kernel/fork.c
67357 +++ b/kernel/fork.c
67358 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67359 *stackend = STACK_END_MAGIC; /* for overflow detection */
67360
67361 #ifdef CONFIG_CC_STACKPROTECTOR
67362 - tsk->stack_canary = get_random_int();
67363 + tsk->stack_canary = pax_get_random_long();
67364 #endif
67365
67366 /*
67367 @@ -344,13 +344,81 @@ free_tsk:
67368 }
67369
67370 #ifdef CONFIG_MMU
67371 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67372 +{
67373 + struct vm_area_struct *tmp;
67374 + unsigned long charge;
67375 + struct mempolicy *pol;
67376 + struct file *file;
67377 +
67378 + charge = 0;
67379 + if (mpnt->vm_flags & VM_ACCOUNT) {
67380 + unsigned long len = vma_pages(mpnt);
67381 +
67382 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67383 + goto fail_nomem;
67384 + charge = len;
67385 + }
67386 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67387 + if (!tmp)
67388 + goto fail_nomem;
67389 + *tmp = *mpnt;
67390 + tmp->vm_mm = mm;
67391 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67392 + pol = mpol_dup(vma_policy(mpnt));
67393 + if (IS_ERR(pol))
67394 + goto fail_nomem_policy;
67395 + vma_set_policy(tmp, pol);
67396 + if (anon_vma_fork(tmp, mpnt))
67397 + goto fail_nomem_anon_vma_fork;
67398 + tmp->vm_flags &= ~VM_LOCKED;
67399 + tmp->vm_next = tmp->vm_prev = NULL;
67400 + tmp->vm_mirror = NULL;
67401 + file = tmp->vm_file;
67402 + if (file) {
67403 + struct inode *inode = file->f_path.dentry->d_inode;
67404 + struct address_space *mapping = file->f_mapping;
67405 +
67406 + get_file(file);
67407 + if (tmp->vm_flags & VM_DENYWRITE)
67408 + atomic_dec(&inode->i_writecount);
67409 + mutex_lock(&mapping->i_mmap_mutex);
67410 + if (tmp->vm_flags & VM_SHARED)
67411 + mapping->i_mmap_writable++;
67412 + flush_dcache_mmap_lock(mapping);
67413 + /* insert tmp into the share list, just after mpnt */
67414 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
67415 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
67416 + else
67417 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
67418 + flush_dcache_mmap_unlock(mapping);
67419 + mutex_unlock(&mapping->i_mmap_mutex);
67420 + }
67421 +
67422 + /*
67423 + * Clear hugetlb-related page reserves for children. This only
67424 + * affects MAP_PRIVATE mappings. Faults generated by the child
67425 + * are not guaranteed to succeed, even if read-only
67426 + */
67427 + if (is_vm_hugetlb_page(tmp))
67428 + reset_vma_resv_huge_pages(tmp);
67429 +
67430 + return tmp;
67431 +
67432 +fail_nomem_anon_vma_fork:
67433 + mpol_put(pol);
67434 +fail_nomem_policy:
67435 + kmem_cache_free(vm_area_cachep, tmp);
67436 +fail_nomem:
67437 + vm_unacct_memory(charge);
67438 + return NULL;
67439 +}
67440 +
67441 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67442 {
67443 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67444 struct rb_node **rb_link, *rb_parent;
67445 int retval;
67446 - unsigned long charge;
67447 - struct mempolicy *pol;
67448
67449 down_write(&oldmm->mmap_sem);
67450 flush_cache_dup_mm(oldmm);
67451 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67452 mm->locked_vm = 0;
67453 mm->mmap = NULL;
67454 mm->mmap_cache = NULL;
67455 - mm->free_area_cache = oldmm->mmap_base;
67456 - mm->cached_hole_size = ~0UL;
67457 + mm->free_area_cache = oldmm->free_area_cache;
67458 + mm->cached_hole_size = oldmm->cached_hole_size;
67459 mm->map_count = 0;
67460 cpumask_clear(mm_cpumask(mm));
67461 mm->mm_rb = RB_ROOT;
67462 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67463
67464 prev = NULL;
67465 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67466 - struct file *file;
67467 -
67468 if (mpnt->vm_flags & VM_DONTCOPY) {
67469 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67470 -vma_pages(mpnt));
67471 continue;
67472 }
67473 - charge = 0;
67474 - if (mpnt->vm_flags & VM_ACCOUNT) {
67475 - unsigned long len = vma_pages(mpnt);
67476 -
67477 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67478 - goto fail_nomem;
67479 - charge = len;
67480 - }
67481 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67482 - if (!tmp)
67483 - goto fail_nomem;
67484 - *tmp = *mpnt;
67485 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67486 - pol = mpol_dup(vma_policy(mpnt));
67487 - retval = PTR_ERR(pol);
67488 - if (IS_ERR(pol))
67489 - goto fail_nomem_policy;
67490 - vma_set_policy(tmp, pol);
67491 - tmp->vm_mm = mm;
67492 - if (anon_vma_fork(tmp, mpnt))
67493 - goto fail_nomem_anon_vma_fork;
67494 - tmp->vm_flags &= ~VM_LOCKED;
67495 - tmp->vm_next = tmp->vm_prev = NULL;
67496 - file = tmp->vm_file;
67497 - if (file) {
67498 - struct inode *inode = file->f_path.dentry->d_inode;
67499 - struct address_space *mapping = file->f_mapping;
67500 -
67501 - get_file(file);
67502 - if (tmp->vm_flags & VM_DENYWRITE)
67503 - atomic_dec(&inode->i_writecount);
67504 - mutex_lock(&mapping->i_mmap_mutex);
67505 - if (tmp->vm_flags & VM_SHARED)
67506 - mapping->i_mmap_writable++;
67507 - flush_dcache_mmap_lock(mapping);
67508 - /* insert tmp into the share list, just after mpnt */
67509 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
67510 - vma_nonlinear_insert(tmp,
67511 - &mapping->i_mmap_nonlinear);
67512 - else
67513 - vma_interval_tree_insert_after(tmp, mpnt,
67514 - &mapping->i_mmap);
67515 - flush_dcache_mmap_unlock(mapping);
67516 - mutex_unlock(&mapping->i_mmap_mutex);
67517 + tmp = dup_vma(mm, oldmm, mpnt);
67518 + if (!tmp) {
67519 + retval = -ENOMEM;
67520 + goto out;
67521 }
67522
67523 /*
67524 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67525 if (retval)
67526 goto out;
67527 }
67528 +
67529 +#ifdef CONFIG_PAX_SEGMEXEC
67530 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67531 + struct vm_area_struct *mpnt_m;
67532 +
67533 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67534 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67535 +
67536 + if (!mpnt->vm_mirror)
67537 + continue;
67538 +
67539 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67540 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67541 + mpnt->vm_mirror = mpnt_m;
67542 + } else {
67543 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67544 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67545 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67546 + mpnt->vm_mirror->vm_mirror = mpnt;
67547 + }
67548 + }
67549 + BUG_ON(mpnt_m);
67550 + }
67551 +#endif
67552 +
67553 /* a new mm has just been created */
67554 arch_dup_mmap(oldmm, mm);
67555 retval = 0;
67556 @@ -470,14 +521,6 @@ out:
67557 flush_tlb_mm(oldmm);
67558 up_write(&oldmm->mmap_sem);
67559 return retval;
67560 -fail_nomem_anon_vma_fork:
67561 - mpol_put(pol);
67562 -fail_nomem_policy:
67563 - kmem_cache_free(vm_area_cachep, tmp);
67564 -fail_nomem:
67565 - retval = -ENOMEM;
67566 - vm_unacct_memory(charge);
67567 - goto out;
67568 }
67569
67570 static inline int mm_alloc_pgd(struct mm_struct *mm)
67571 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67572 return ERR_PTR(err);
67573
67574 mm = get_task_mm(task);
67575 - if (mm && mm != current->mm &&
67576 - !ptrace_may_access(task, mode)) {
67577 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67578 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67579 mmput(mm);
67580 mm = ERR_PTR(-EACCES);
67581 }
67582 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67583 spin_unlock(&fs->lock);
67584 return -EAGAIN;
67585 }
67586 - fs->users++;
67587 + atomic_inc(&fs->users);
67588 spin_unlock(&fs->lock);
67589 return 0;
67590 }
67591 tsk->fs = copy_fs_struct(fs);
67592 if (!tsk->fs)
67593 return -ENOMEM;
67594 + /* Carry through gr_chroot_dentry and is_chrooted instead
67595 + of recomputing it here. Already copied when the task struct
67596 + is duplicated. This allows pivot_root to not be treated as
67597 + a chroot
67598 + */
67599 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67600 +
67601 return 0;
67602 }
67603
67604 @@ -1184,6 +1234,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67605 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67606 #endif
67607 retval = -EAGAIN;
67608 +
67609 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67610 +
67611 if (atomic_read(&p->real_cred->user->processes) >=
67612 task_rlimit(p, RLIMIT_NPROC)) {
67613 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67614 @@ -1402,6 +1455,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67615 /* Need tasklist lock for parent etc handling! */
67616 write_lock_irq(&tasklist_lock);
67617
67618 + /* synchronizes with gr_set_acls() */
67619 + gr_copy_label(p);
67620 +
67621 /* CLONE_PARENT re-uses the old parent */
67622 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67623 p->real_parent = current->real_parent;
67624 @@ -1512,6 +1568,8 @@ bad_fork_cleanup_count:
67625 bad_fork_free:
67626 free_task(p);
67627 fork_out:
67628 + gr_log_forkfail(retval);
67629 +
67630 return ERR_PTR(retval);
67631 }
67632
67633 @@ -1612,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
67634 if (clone_flags & CLONE_PARENT_SETTID)
67635 put_user(nr, parent_tidptr);
67636
67637 + gr_handle_brute_check();
67638 +
67639 if (clone_flags & CLONE_VFORK) {
67640 p->vfork_done = &vfork;
67641 init_completion(&vfork);
67642 @@ -1721,7 +1781,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67643 return 0;
67644
67645 /* don't need lock here; in the worst case we'll do useless copy */
67646 - if (fs->users == 1)
67647 + if (atomic_read(&fs->users) == 1)
67648 return 0;
67649
67650 *new_fsp = copy_fs_struct(fs);
67651 @@ -1810,7 +1870,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67652 fs = current->fs;
67653 spin_lock(&fs->lock);
67654 current->fs = new_fs;
67655 - if (--fs->users)
67656 + gr_set_chroot_entries(current, &current->fs->root);
67657 + if (atomic_dec_return(&fs->users))
67658 new_fs = NULL;
67659 else
67660 new_fs = fs;
67661 diff --git a/kernel/futex.c b/kernel/futex.c
67662 index 19eb089..b8c65ea 100644
67663 --- a/kernel/futex.c
67664 +++ b/kernel/futex.c
67665 @@ -54,6 +54,7 @@
67666 #include <linux/mount.h>
67667 #include <linux/pagemap.h>
67668 #include <linux/syscalls.h>
67669 +#include <linux/ptrace.h>
67670 #include <linux/signal.h>
67671 #include <linux/export.h>
67672 #include <linux/magic.h>
67673 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67674 struct page *page, *page_head;
67675 int err, ro = 0;
67676
67677 +#ifdef CONFIG_PAX_SEGMEXEC
67678 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67679 + return -EFAULT;
67680 +#endif
67681 +
67682 /*
67683 * The futex address must be "naturally" aligned.
67684 */
67685 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
67686 {
67687 u32 curval;
67688 int i;
67689 + mm_segment_t oldfs;
67690
67691 /*
67692 * This will fail and we want it. Some arch implementations do
67693 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
67694 * implementation, the non-functional ones will return
67695 * -ENOSYS.
67696 */
67697 + oldfs = get_fs();
67698 + set_fs(USER_DS);
67699 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67700 futex_cmpxchg_enabled = 1;
67701 + set_fs(oldfs);
67702
67703 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67704 plist_head_init(&futex_queues[i].chain);
67705 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67706 index 9b22d03..6295b62 100644
67707 --- a/kernel/gcov/base.c
67708 +++ b/kernel/gcov/base.c
67709 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67710 }
67711
67712 #ifdef CONFIG_MODULES
67713 -static inline int within(void *addr, void *start, unsigned long size)
67714 -{
67715 - return ((addr >= start) && (addr < start + size));
67716 -}
67717 -
67718 /* Update list and generate events when modules are unloaded. */
67719 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67720 void *data)
67721 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67722 prev = NULL;
67723 /* Remove entries located in module from linked list. */
67724 for (info = gcov_info_head; info; info = info->next) {
67725 - if (within(info, mod->module_core, mod->core_size)) {
67726 + if (within_module_core_rw((unsigned long)info, mod)) {
67727 if (prev)
67728 prev->next = info->next;
67729 else
67730 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67731 index 6db7a5e..25b6648 100644
67732 --- a/kernel/hrtimer.c
67733 +++ b/kernel/hrtimer.c
67734 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67735 local_irq_restore(flags);
67736 }
67737
67738 -static void run_hrtimer_softirq(struct softirq_action *h)
67739 +static void run_hrtimer_softirq(void)
67740 {
67741 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67742
67743 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67744 index 60f48fa..7f3a770 100644
67745 --- a/kernel/jump_label.c
67746 +++ b/kernel/jump_label.c
67747 @@ -13,6 +13,7 @@
67748 #include <linux/sort.h>
67749 #include <linux/err.h>
67750 #include <linux/static_key.h>
67751 +#include <linux/mm.h>
67752
67753 #ifdef HAVE_JUMP_LABEL
67754
67755 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67756
67757 size = (((unsigned long)stop - (unsigned long)start)
67758 / sizeof(struct jump_entry));
67759 + pax_open_kernel();
67760 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67761 + pax_close_kernel();
67762 }
67763
67764 static void jump_label_update(struct static_key *key, int enable);
67765 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67766 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67767 struct jump_entry *iter;
67768
67769 + pax_open_kernel();
67770 for (iter = iter_start; iter < iter_stop; iter++) {
67771 if (within_module_init(iter->code, mod))
67772 iter->code = 0;
67773 }
67774 + pax_close_kernel();
67775 }
67776
67777 static int
67778 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67779 index 2169fee..45c017a 100644
67780 --- a/kernel/kallsyms.c
67781 +++ b/kernel/kallsyms.c
67782 @@ -11,6 +11,9 @@
67783 * Changed the compression method from stem compression to "table lookup"
67784 * compression (see scripts/kallsyms.c for a more complete description)
67785 */
67786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67787 +#define __INCLUDED_BY_HIDESYM 1
67788 +#endif
67789 #include <linux/kallsyms.h>
67790 #include <linux/module.h>
67791 #include <linux/init.h>
67792 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67793
67794 static inline int is_kernel_inittext(unsigned long addr)
67795 {
67796 + if (system_state != SYSTEM_BOOTING)
67797 + return 0;
67798 +
67799 if (addr >= (unsigned long)_sinittext
67800 && addr <= (unsigned long)_einittext)
67801 return 1;
67802 return 0;
67803 }
67804
67805 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67806 +#ifdef CONFIG_MODULES
67807 +static inline int is_module_text(unsigned long addr)
67808 +{
67809 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67810 + return 1;
67811 +
67812 + addr = ktla_ktva(addr);
67813 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67814 +}
67815 +#else
67816 +static inline int is_module_text(unsigned long addr)
67817 +{
67818 + return 0;
67819 +}
67820 +#endif
67821 +#endif
67822 +
67823 static inline int is_kernel_text(unsigned long addr)
67824 {
67825 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67826 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67827
67828 static inline int is_kernel(unsigned long addr)
67829 {
67830 +
67831 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67832 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67833 + return 1;
67834 +
67835 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67836 +#else
67837 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67838 +#endif
67839 +
67840 return 1;
67841 return in_gate_area_no_mm(addr);
67842 }
67843
67844 static int is_ksym_addr(unsigned long addr)
67845 {
67846 +
67847 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67848 + if (is_module_text(addr))
67849 + return 0;
67850 +#endif
67851 +
67852 if (all_var)
67853 return is_kernel(addr);
67854
67855 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67856
67857 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67858 {
67859 - iter->name[0] = '\0';
67860 iter->nameoff = get_symbol_offset(new_pos);
67861 iter->pos = new_pos;
67862 }
67863 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67864 {
67865 struct kallsym_iter *iter = m->private;
67866
67867 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67868 + if (current_uid())
67869 + return 0;
67870 +#endif
67871 +
67872 /* Some debugging symbols have no name. Ignore them. */
67873 if (!iter->name[0])
67874 return 0;
67875 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67876 */
67877 type = iter->exported ? toupper(iter->type) :
67878 tolower(iter->type);
67879 +
67880 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67881 type, iter->name, iter->module_name);
67882 } else
67883 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67884 struct kallsym_iter *iter;
67885 int ret;
67886
67887 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67888 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67889 if (!iter)
67890 return -ENOMEM;
67891 reset_iter(iter, 0);
67892 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67893 index 30b7b22..c726387 100644
67894 --- a/kernel/kcmp.c
67895 +++ b/kernel/kcmp.c
67896 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67897 struct task_struct *task1, *task2;
67898 int ret;
67899
67900 +#ifdef CONFIG_GRKERNSEC
67901 + return -ENOSYS;
67902 +#endif
67903 +
67904 rcu_read_lock();
67905
67906 /*
67907 diff --git a/kernel/kexec.c b/kernel/kexec.c
67908 index 5e4bd78..00c5b91 100644
67909 --- a/kernel/kexec.c
67910 +++ b/kernel/kexec.c
67911 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67912 unsigned long flags)
67913 {
67914 struct compat_kexec_segment in;
67915 - struct kexec_segment out, __user *ksegments;
67916 + struct kexec_segment out;
67917 + struct kexec_segment __user *ksegments;
67918 unsigned long i, result;
67919
67920 /* Don't allow clients that don't understand the native
67921 diff --git a/kernel/kmod.c b/kernel/kmod.c
67922 index 1c317e3..4a92a55 100644
67923 --- a/kernel/kmod.c
67924 +++ b/kernel/kmod.c
67925 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67926 kfree(info->argv);
67927 }
67928
67929 -static int call_modprobe(char *module_name, int wait)
67930 +static int call_modprobe(char *module_name, char *module_param, int wait)
67931 {
67932 static char *envp[] = {
67933 "HOME=/",
67934 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
67935 NULL
67936 };
67937
67938 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67939 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67940 if (!argv)
67941 goto out;
67942
67943 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
67944 argv[1] = "-q";
67945 argv[2] = "--";
67946 argv[3] = module_name; /* check free_modprobe_argv() */
67947 - argv[4] = NULL;
67948 + argv[4] = module_param;
67949 + argv[5] = NULL;
67950
67951 return call_usermodehelper_fns(modprobe_path, argv, envp,
67952 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67953 @@ -120,9 +121,8 @@ out:
67954 * If module auto-loading support is disabled then this function
67955 * becomes a no-operation.
67956 */
67957 -int __request_module(bool wait, const char *fmt, ...)
67958 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67959 {
67960 - va_list args;
67961 char module_name[MODULE_NAME_LEN];
67962 unsigned int max_modprobes;
67963 int ret;
67964 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
67965 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67966 static int kmod_loop_msg;
67967
67968 - va_start(args, fmt);
67969 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67970 - va_end(args);
67971 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67972 if (ret >= MODULE_NAME_LEN)
67973 return -ENAMETOOLONG;
67974
67975 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
67976 if (ret)
67977 return ret;
67978
67979 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67980 + if (!current_uid()) {
67981 + /* hack to workaround consolekit/udisks stupidity */
67982 + read_lock(&tasklist_lock);
67983 + if (!strcmp(current->comm, "mount") &&
67984 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67985 + read_unlock(&tasklist_lock);
67986 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67987 + return -EPERM;
67988 + }
67989 + read_unlock(&tasklist_lock);
67990 + }
67991 +#endif
67992 +
67993 /* If modprobe needs a service that is in a module, we get a recursive
67994 * loop. Limit the number of running kmod threads to max_threads/2 or
67995 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67996 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
67997
67998 trace_module_request(module_name, wait, _RET_IP_);
67999
68000 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68001 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68002
68003 atomic_dec(&kmod_concurrent);
68004 return ret;
68005 }
68006 +
68007 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68008 +{
68009 + va_list args;
68010 + int ret;
68011 +
68012 + va_start(args, fmt);
68013 + ret = ____request_module(wait, module_param, fmt, args);
68014 + va_end(args);
68015 +
68016 + return ret;
68017 +}
68018 +
68019 +int __request_module(bool wait, const char *fmt, ...)
68020 +{
68021 + va_list args;
68022 + int ret;
68023 +
68024 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68025 + if (current_uid()) {
68026 + char module_param[MODULE_NAME_LEN];
68027 +
68028 + memset(module_param, 0, sizeof(module_param));
68029 +
68030 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68031 +
68032 + va_start(args, fmt);
68033 + ret = ____request_module(wait, module_param, fmt, args);
68034 + va_end(args);
68035 +
68036 + return ret;
68037 + }
68038 +#endif
68039 +
68040 + va_start(args, fmt);
68041 + ret = ____request_module(wait, NULL, fmt, args);
68042 + va_end(args);
68043 +
68044 + return ret;
68045 +}
68046 +
68047 EXPORT_SYMBOL(__request_module);
68048 #endif /* CONFIG_MODULES */
68049
68050 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
68051 *
68052 * Thus the __user pointer cast is valid here.
68053 */
68054 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68055 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68056
68057 /*
68058 * If ret is 0, either ____call_usermodehelper failed and the
68059 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68060 index 098f396..fe85ff1 100644
68061 --- a/kernel/kprobes.c
68062 +++ b/kernel/kprobes.c
68063 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68064 * kernel image and loaded module images reside. This is required
68065 * so x86_64 can correctly handle the %rip-relative fixups.
68066 */
68067 - kip->insns = module_alloc(PAGE_SIZE);
68068 + kip->insns = module_alloc_exec(PAGE_SIZE);
68069 if (!kip->insns) {
68070 kfree(kip);
68071 return NULL;
68072 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68073 */
68074 if (!list_is_singular(&kip->list)) {
68075 list_del(&kip->list);
68076 - module_free(NULL, kip->insns);
68077 + module_free_exec(NULL, kip->insns);
68078 kfree(kip);
68079 }
68080 return 1;
68081 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
68082 {
68083 int i, err = 0;
68084 unsigned long offset = 0, size = 0;
68085 - char *modname, namebuf[128];
68086 + char *modname, namebuf[KSYM_NAME_LEN];
68087 const char *symbol_name;
68088 void *addr;
68089 struct kprobe_blackpoint *kb;
68090 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68091 kprobe_type = "k";
68092
68093 if (sym)
68094 - seq_printf(pi, "%p %s %s+0x%x %s ",
68095 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68096 p->addr, kprobe_type, sym, offset,
68097 (modname ? modname : " "));
68098 else
68099 - seq_printf(pi, "%p %s %p ",
68100 + seq_printf(pi, "%pK %s %pK ",
68101 p->addr, kprobe_type, p->addr);
68102
68103 if (!pp)
68104 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68105 const char *sym = NULL;
68106 unsigned int i = *(loff_t *) v;
68107 unsigned long offset = 0;
68108 - char *modname, namebuf[128];
68109 + char *modname, namebuf[KSYM_NAME_LEN];
68110
68111 head = &kprobe_table[i];
68112 preempt_disable();
68113 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68114 index 4e316e1..5501eef 100644
68115 --- a/kernel/ksysfs.c
68116 +++ b/kernel/ksysfs.c
68117 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68118 {
68119 if (count+1 > UEVENT_HELPER_PATH_LEN)
68120 return -ENOENT;
68121 + if (!capable(CAP_SYS_ADMIN))
68122 + return -EPERM;
68123 memcpy(uevent_helper, buf, count);
68124 uevent_helper[count] = '\0';
68125 if (count && uevent_helper[count-1] == '\n')
68126 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68127 index 7981e5b..7f2105c 100644
68128 --- a/kernel/lockdep.c
68129 +++ b/kernel/lockdep.c
68130 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68131 end = (unsigned long) &_end,
68132 addr = (unsigned long) obj;
68133
68134 +#ifdef CONFIG_PAX_KERNEXEC
68135 + start = ktla_ktva(start);
68136 +#endif
68137 +
68138 /*
68139 * static variable?
68140 */
68141 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68142 if (!static_obj(lock->key)) {
68143 debug_locks_off();
68144 printk("INFO: trying to register non-static key.\n");
68145 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68146 printk("the code is fine but needs lockdep annotation.\n");
68147 printk("turning off the locking correctness validator.\n");
68148 dump_stack();
68149 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68150 if (!class)
68151 return 0;
68152 }
68153 - atomic_inc((atomic_t *)&class->ops);
68154 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68155 if (very_verbose(class)) {
68156 printk("\nacquire class [%p] %s", class->key, class->name);
68157 if (class->name_version > 1)
68158 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68159 index 91c32a0..7b88d63 100644
68160 --- a/kernel/lockdep_proc.c
68161 +++ b/kernel/lockdep_proc.c
68162 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68163
68164 static void print_name(struct seq_file *m, struct lock_class *class)
68165 {
68166 - char str[128];
68167 + char str[KSYM_NAME_LEN];
68168 const char *name = class->name;
68169
68170 if (!name) {
68171 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68172 return 0;
68173 }
68174
68175 - seq_printf(m, "%p", class->key);
68176 + seq_printf(m, "%pK", class->key);
68177 #ifdef CONFIG_DEBUG_LOCKDEP
68178 seq_printf(m, " OPS:%8ld", class->ops);
68179 #endif
68180 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68181
68182 list_for_each_entry(entry, &class->locks_after, entry) {
68183 if (entry->distance == 1) {
68184 - seq_printf(m, " -> [%p] ", entry->class->key);
68185 + seq_printf(m, " -> [%pK] ", entry->class->key);
68186 print_name(m, entry->class);
68187 seq_puts(m, "\n");
68188 }
68189 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68190 if (!class->key)
68191 continue;
68192
68193 - seq_printf(m, "[%p] ", class->key);
68194 + seq_printf(m, "[%pK] ", class->key);
68195 print_name(m, class);
68196 seq_puts(m, "\n");
68197 }
68198 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68199 if (!i)
68200 seq_line(m, '-', 40-namelen, namelen);
68201
68202 - snprintf(ip, sizeof(ip), "[<%p>]",
68203 + snprintf(ip, sizeof(ip), "[<%pK>]",
68204 (void *)class->contention_point[i]);
68205 seq_printf(m, "%40s %14lu %29s %pS\n",
68206 name, stats->contention_point[i],
68207 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68208 if (!i)
68209 seq_line(m, '-', 40-namelen, namelen);
68210
68211 - snprintf(ip, sizeof(ip), "[<%p>]",
68212 + snprintf(ip, sizeof(ip), "[<%pK>]",
68213 (void *)class->contending_point[i]);
68214 seq_printf(m, "%40s %14lu %29s %pS\n",
68215 name, stats->contending_point[i],
68216 diff --git a/kernel/module.c b/kernel/module.c
68217 index 6e48c3a..ac2ef5b 100644
68218 --- a/kernel/module.c
68219 +++ b/kernel/module.c
68220 @@ -59,6 +59,7 @@
68221 #include <linux/pfn.h>
68222 #include <linux/bsearch.h>
68223 #include <linux/fips.h>
68224 +#include <linux/grsecurity.h>
68225 #include "module-internal.h"
68226
68227 #define CREATE_TRACE_POINTS
68228 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68229
68230 /* Bounds of module allocation, for speeding __module_address.
68231 * Protected by module_mutex. */
68232 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68233 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68234 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68235
68236 int register_module_notifier(struct notifier_block * nb)
68237 {
68238 @@ -318,7 +320,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68239 return true;
68240
68241 list_for_each_entry_rcu(mod, &modules, list) {
68242 - struct symsearch arr[] = {
68243 + struct symsearch modarr[] = {
68244 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68245 NOT_GPL_ONLY, false },
68246 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68247 @@ -340,7 +342,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68248 #endif
68249 };
68250
68251 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68252 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68253 return true;
68254 }
68255 return false;
68256 @@ -472,7 +474,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68257 static int percpu_modalloc(struct module *mod,
68258 unsigned long size, unsigned long align)
68259 {
68260 - if (align > PAGE_SIZE) {
68261 + if (align-1 >= PAGE_SIZE) {
68262 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68263 mod->name, align, PAGE_SIZE);
68264 align = PAGE_SIZE;
68265 @@ -1072,7 +1074,7 @@ struct module_attribute module_uevent =
68266 static ssize_t show_coresize(struct module_attribute *mattr,
68267 struct module_kobject *mk, char *buffer)
68268 {
68269 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68270 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68271 }
68272
68273 static struct module_attribute modinfo_coresize =
68274 @@ -1081,7 +1083,7 @@ static struct module_attribute modinfo_coresize =
68275 static ssize_t show_initsize(struct module_attribute *mattr,
68276 struct module_kobject *mk, char *buffer)
68277 {
68278 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68279 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68280 }
68281
68282 static struct module_attribute modinfo_initsize =
68283 @@ -1295,7 +1297,7 @@ resolve_symbol_wait(struct module *mod,
68284 */
68285 #ifdef CONFIG_SYSFS
68286
68287 -#ifdef CONFIG_KALLSYMS
68288 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68289 static inline bool sect_empty(const Elf_Shdr *sect)
68290 {
68291 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68292 @@ -1761,21 +1763,21 @@ static void set_section_ro_nx(void *base,
68293
68294 static void unset_module_core_ro_nx(struct module *mod)
68295 {
68296 - set_page_attributes(mod->module_core + mod->core_text_size,
68297 - mod->module_core + mod->core_size,
68298 + set_page_attributes(mod->module_core_rw,
68299 + mod->module_core_rw + mod->core_size_rw,
68300 set_memory_x);
68301 - set_page_attributes(mod->module_core,
68302 - mod->module_core + mod->core_ro_size,
68303 + set_page_attributes(mod->module_core_rx,
68304 + mod->module_core_rx + mod->core_size_rx,
68305 set_memory_rw);
68306 }
68307
68308 static void unset_module_init_ro_nx(struct module *mod)
68309 {
68310 - set_page_attributes(mod->module_init + mod->init_text_size,
68311 - mod->module_init + mod->init_size,
68312 + set_page_attributes(mod->module_init_rw,
68313 + mod->module_init_rw + mod->init_size_rw,
68314 set_memory_x);
68315 - set_page_attributes(mod->module_init,
68316 - mod->module_init + mod->init_ro_size,
68317 + set_page_attributes(mod->module_init_rx,
68318 + mod->module_init_rx + mod->init_size_rx,
68319 set_memory_rw);
68320 }
68321
68322 @@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
68323
68324 mutex_lock(&module_mutex);
68325 list_for_each_entry_rcu(mod, &modules, list) {
68326 - if ((mod->module_core) && (mod->core_text_size)) {
68327 - set_page_attributes(mod->module_core,
68328 - mod->module_core + mod->core_text_size,
68329 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68330 + set_page_attributes(mod->module_core_rx,
68331 + mod->module_core_rx + mod->core_size_rx,
68332 set_memory_rw);
68333 }
68334 - if ((mod->module_init) && (mod->init_text_size)) {
68335 - set_page_attributes(mod->module_init,
68336 - mod->module_init + mod->init_text_size,
68337 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68338 + set_page_attributes(mod->module_init_rx,
68339 + mod->module_init_rx + mod->init_size_rx,
68340 set_memory_rw);
68341 }
68342 }
68343 @@ -1807,14 +1809,14 @@ void set_all_modules_text_ro(void)
68344
68345 mutex_lock(&module_mutex);
68346 list_for_each_entry_rcu(mod, &modules, list) {
68347 - if ((mod->module_core) && (mod->core_text_size)) {
68348 - set_page_attributes(mod->module_core,
68349 - mod->module_core + mod->core_text_size,
68350 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68351 + set_page_attributes(mod->module_core_rx,
68352 + mod->module_core_rx + mod->core_size_rx,
68353 set_memory_ro);
68354 }
68355 - if ((mod->module_init) && (mod->init_text_size)) {
68356 - set_page_attributes(mod->module_init,
68357 - mod->module_init + mod->init_text_size,
68358 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68359 + set_page_attributes(mod->module_init_rx,
68360 + mod->module_init_rx + mod->init_size_rx,
68361 set_memory_ro);
68362 }
68363 }
68364 @@ -1860,16 +1862,19 @@ static void free_module(struct module *mod)
68365
68366 /* This may be NULL, but that's OK */
68367 unset_module_init_ro_nx(mod);
68368 - module_free(mod, mod->module_init);
68369 + module_free(mod, mod->module_init_rw);
68370 + module_free_exec(mod, mod->module_init_rx);
68371 kfree(mod->args);
68372 percpu_modfree(mod);
68373
68374 /* Free lock-classes: */
68375 - lockdep_free_key_range(mod->module_core, mod->core_size);
68376 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68377 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68378
68379 /* Finally, free the core (containing the module structure) */
68380 unset_module_core_ro_nx(mod);
68381 - module_free(mod, mod->module_core);
68382 + module_free_exec(mod, mod->module_core_rx);
68383 + module_free(mod, mod->module_core_rw);
68384
68385 #ifdef CONFIG_MPU
68386 update_protections(current->mm);
68387 @@ -1939,9 +1944,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68388 int ret = 0;
68389 const struct kernel_symbol *ksym;
68390
68391 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68392 + int is_fs_load = 0;
68393 + int register_filesystem_found = 0;
68394 + char *p;
68395 +
68396 + p = strstr(mod->args, "grsec_modharden_fs");
68397 + if (p) {
68398 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68399 + /* copy \0 as well */
68400 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68401 + is_fs_load = 1;
68402 + }
68403 +#endif
68404 +
68405 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68406 const char *name = info->strtab + sym[i].st_name;
68407
68408 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68409 + /* it's a real shame this will never get ripped and copied
68410 + upstream! ;(
68411 + */
68412 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68413 + register_filesystem_found = 1;
68414 +#endif
68415 +
68416 switch (sym[i].st_shndx) {
68417 case SHN_COMMON:
68418 /* We compiled with -fno-common. These are not
68419 @@ -1962,7 +1989,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68420 ksym = resolve_symbol_wait(mod, info, name);
68421 /* Ok if resolved. */
68422 if (ksym && !IS_ERR(ksym)) {
68423 + pax_open_kernel();
68424 sym[i].st_value = ksym->value;
68425 + pax_close_kernel();
68426 break;
68427 }
68428
68429 @@ -1981,11 +2010,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68430 secbase = (unsigned long)mod_percpu(mod);
68431 else
68432 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68433 + pax_open_kernel();
68434 sym[i].st_value += secbase;
68435 + pax_close_kernel();
68436 break;
68437 }
68438 }
68439
68440 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68441 + if (is_fs_load && !register_filesystem_found) {
68442 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68443 + ret = -EPERM;
68444 + }
68445 +#endif
68446 +
68447 return ret;
68448 }
68449
68450 @@ -2069,22 +2107,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68451 || s->sh_entsize != ~0UL
68452 || strstarts(sname, ".init"))
68453 continue;
68454 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68455 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68456 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68457 + else
68458 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68459 pr_debug("\t%s\n", sname);
68460 }
68461 - switch (m) {
68462 - case 0: /* executable */
68463 - mod->core_size = debug_align(mod->core_size);
68464 - mod->core_text_size = mod->core_size;
68465 - break;
68466 - case 1: /* RO: text and ro-data */
68467 - mod->core_size = debug_align(mod->core_size);
68468 - mod->core_ro_size = mod->core_size;
68469 - break;
68470 - case 3: /* whole core */
68471 - mod->core_size = debug_align(mod->core_size);
68472 - break;
68473 - }
68474 }
68475
68476 pr_debug("Init section allocation order:\n");
68477 @@ -2098,23 +2126,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68478 || s->sh_entsize != ~0UL
68479 || !strstarts(sname, ".init"))
68480 continue;
68481 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68482 - | INIT_OFFSET_MASK);
68483 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68484 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68485 + else
68486 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68487 + s->sh_entsize |= INIT_OFFSET_MASK;
68488 pr_debug("\t%s\n", sname);
68489 }
68490 - switch (m) {
68491 - case 0: /* executable */
68492 - mod->init_size = debug_align(mod->init_size);
68493 - mod->init_text_size = mod->init_size;
68494 - break;
68495 - case 1: /* RO: text and ro-data */
68496 - mod->init_size = debug_align(mod->init_size);
68497 - mod->init_ro_size = mod->init_size;
68498 - break;
68499 - case 3: /* whole init */
68500 - mod->init_size = debug_align(mod->init_size);
68501 - break;
68502 - }
68503 }
68504 }
68505
68506 @@ -2286,7 +2304,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68507
68508 /* Put symbol section at end of init part of module. */
68509 symsect->sh_flags |= SHF_ALLOC;
68510 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68511 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68512 info->index.sym) | INIT_OFFSET_MASK;
68513 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68514
68515 @@ -2306,13 +2324,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68516 }
68517
68518 /* Append room for core symbols at end of core part. */
68519 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68520 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68521 - mod->core_size += strtab_size;
68522 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68523 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68524 + mod->core_size_rx += strtab_size;
68525
68526 /* Put string table section at end of init part of module. */
68527 strsect->sh_flags |= SHF_ALLOC;
68528 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68529 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68530 info->index.str) | INIT_OFFSET_MASK;
68531 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68532 }
68533 @@ -2330,12 +2348,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68534 /* Make sure we get permanent strtab: don't use info->strtab. */
68535 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68536
68537 + pax_open_kernel();
68538 +
68539 /* Set types up while we still have access to sections. */
68540 for (i = 0; i < mod->num_symtab; i++)
68541 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68542
68543 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68544 - mod->core_strtab = s = mod->module_core + info->stroffs;
68545 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68546 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68547 src = mod->symtab;
68548 *s++ = 0;
68549 for (ndst = i = 0; i < mod->num_symtab; i++) {
68550 @@ -2348,6 +2368,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68551 }
68552 }
68553 mod->core_num_syms = ndst;
68554 +
68555 + pax_close_kernel();
68556 }
68557 #else
68558 static inline void layout_symtab(struct module *mod, struct load_info *info)
68559 @@ -2381,17 +2403,33 @@ void * __weak module_alloc(unsigned long size)
68560 return size == 0 ? NULL : vmalloc_exec(size);
68561 }
68562
68563 -static void *module_alloc_update_bounds(unsigned long size)
68564 +static void *module_alloc_update_bounds_rw(unsigned long size)
68565 {
68566 void *ret = module_alloc(size);
68567
68568 if (ret) {
68569 mutex_lock(&module_mutex);
68570 /* Update module bounds. */
68571 - if ((unsigned long)ret < module_addr_min)
68572 - module_addr_min = (unsigned long)ret;
68573 - if ((unsigned long)ret + size > module_addr_max)
68574 - module_addr_max = (unsigned long)ret + size;
68575 + if ((unsigned long)ret < module_addr_min_rw)
68576 + module_addr_min_rw = (unsigned long)ret;
68577 + if ((unsigned long)ret + size > module_addr_max_rw)
68578 + module_addr_max_rw = (unsigned long)ret + size;
68579 + mutex_unlock(&module_mutex);
68580 + }
68581 + return ret;
68582 +}
68583 +
68584 +static void *module_alloc_update_bounds_rx(unsigned long size)
68585 +{
68586 + void *ret = module_alloc_exec(size);
68587 +
68588 + if (ret) {
68589 + mutex_lock(&module_mutex);
68590 + /* Update module bounds. */
68591 + if ((unsigned long)ret < module_addr_min_rx)
68592 + module_addr_min_rx = (unsigned long)ret;
68593 + if ((unsigned long)ret + size > module_addr_max_rx)
68594 + module_addr_max_rx = (unsigned long)ret + size;
68595 mutex_unlock(&module_mutex);
68596 }
68597 return ret;
68598 @@ -2610,8 +2648,14 @@ static struct module *setup_load_info(struct load_info *info)
68599 static int check_modinfo(struct module *mod, struct load_info *info)
68600 {
68601 const char *modmagic = get_modinfo(info, "vermagic");
68602 + const char *license = get_modinfo(info, "license");
68603 int err;
68604
68605 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68606 + if (!license || !license_is_gpl_compatible(license))
68607 + return -ENOEXEC;
68608 +#endif
68609 +
68610 /* This is allowed: modprobe --force will invalidate it. */
68611 if (!modmagic) {
68612 err = try_to_force_load(mod, "bad vermagic");
68613 @@ -2634,7 +2678,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68614 }
68615
68616 /* Set up license info based on the info section */
68617 - set_license(mod, get_modinfo(info, "license"));
68618 + set_license(mod, license);
68619
68620 return 0;
68621 }
68622 @@ -2728,7 +2772,7 @@ static int move_module(struct module *mod, struct load_info *info)
68623 void *ptr;
68624
68625 /* Do the allocs. */
68626 - ptr = module_alloc_update_bounds(mod->core_size);
68627 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68628 /*
68629 * The pointer to this block is stored in the module structure
68630 * which is inside the block. Just mark it as not being a
68631 @@ -2738,23 +2782,50 @@ static int move_module(struct module *mod, struct load_info *info)
68632 if (!ptr)
68633 return -ENOMEM;
68634
68635 - memset(ptr, 0, mod->core_size);
68636 - mod->module_core = ptr;
68637 + memset(ptr, 0, mod->core_size_rw);
68638 + mod->module_core_rw = ptr;
68639
68640 - ptr = module_alloc_update_bounds(mod->init_size);
68641 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68642 /*
68643 * The pointer to this block is stored in the module structure
68644 * which is inside the block. This block doesn't need to be
68645 * scanned as it contains data and code that will be freed
68646 * after the module is initialized.
68647 */
68648 - kmemleak_ignore(ptr);
68649 - if (!ptr && mod->init_size) {
68650 - module_free(mod, mod->module_core);
68651 + kmemleak_not_leak(ptr);
68652 + if (!ptr && mod->init_size_rw) {
68653 + module_free(mod, mod->module_core_rw);
68654 return -ENOMEM;
68655 }
68656 - memset(ptr, 0, mod->init_size);
68657 - mod->module_init = ptr;
68658 + memset(ptr, 0, mod->init_size_rw);
68659 + mod->module_init_rw = ptr;
68660 +
68661 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68662 + kmemleak_not_leak(ptr);
68663 + if (!ptr) {
68664 + module_free(mod, mod->module_init_rw);
68665 + module_free(mod, mod->module_core_rw);
68666 + return -ENOMEM;
68667 + }
68668 +
68669 + pax_open_kernel();
68670 + memset(ptr, 0, mod->core_size_rx);
68671 + pax_close_kernel();
68672 + mod->module_core_rx = ptr;
68673 +
68674 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68675 + kmemleak_not_leak(ptr);
68676 + if (!ptr && mod->init_size_rx) {
68677 + module_free_exec(mod, mod->module_core_rx);
68678 + module_free(mod, mod->module_init_rw);
68679 + module_free(mod, mod->module_core_rw);
68680 + return -ENOMEM;
68681 + }
68682 +
68683 + pax_open_kernel();
68684 + memset(ptr, 0, mod->init_size_rx);
68685 + pax_close_kernel();
68686 + mod->module_init_rx = ptr;
68687
68688 /* Transfer each section which specifies SHF_ALLOC */
68689 pr_debug("final section addresses:\n");
68690 @@ -2765,16 +2836,45 @@ static int move_module(struct module *mod, struct load_info *info)
68691 if (!(shdr->sh_flags & SHF_ALLOC))
68692 continue;
68693
68694 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68695 - dest = mod->module_init
68696 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68697 - else
68698 - dest = mod->module_core + shdr->sh_entsize;
68699 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68700 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68701 + dest = mod->module_init_rw
68702 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68703 + else
68704 + dest = mod->module_init_rx
68705 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68706 + } else {
68707 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68708 + dest = mod->module_core_rw + shdr->sh_entsize;
68709 + else
68710 + dest = mod->module_core_rx + shdr->sh_entsize;
68711 + }
68712 +
68713 + if (shdr->sh_type != SHT_NOBITS) {
68714 +
68715 +#ifdef CONFIG_PAX_KERNEXEC
68716 +#ifdef CONFIG_X86_64
68717 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68718 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68719 +#endif
68720 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68721 + pax_open_kernel();
68722 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68723 + pax_close_kernel();
68724 + } else
68725 +#endif
68726
68727 - if (shdr->sh_type != SHT_NOBITS)
68728 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68729 + }
68730 /* Update sh_addr to point to copy in image. */
68731 - shdr->sh_addr = (unsigned long)dest;
68732 +
68733 +#ifdef CONFIG_PAX_KERNEXEC
68734 + if (shdr->sh_flags & SHF_EXECINSTR)
68735 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68736 + else
68737 +#endif
68738 +
68739 + shdr->sh_addr = (unsigned long)dest;
68740 pr_debug("\t0x%lx %s\n",
68741 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68742 }
68743 @@ -2829,12 +2929,12 @@ static void flush_module_icache(const struct module *mod)
68744 * Do it before processing of module parameters, so the module
68745 * can provide parameter accessor functions of its own.
68746 */
68747 - if (mod->module_init)
68748 - flush_icache_range((unsigned long)mod->module_init,
68749 - (unsigned long)mod->module_init
68750 - + mod->init_size);
68751 - flush_icache_range((unsigned long)mod->module_core,
68752 - (unsigned long)mod->module_core + mod->core_size);
68753 + if (mod->module_init_rx)
68754 + flush_icache_range((unsigned long)mod->module_init_rx,
68755 + (unsigned long)mod->module_init_rx
68756 + + mod->init_size_rx);
68757 + flush_icache_range((unsigned long)mod->module_core_rx,
68758 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68759
68760 set_fs(old_fs);
68761 }
68762 @@ -2904,8 +3004,10 @@ out:
68763 static void module_deallocate(struct module *mod, struct load_info *info)
68764 {
68765 percpu_modfree(mod);
68766 - module_free(mod, mod->module_init);
68767 - module_free(mod, mod->module_core);
68768 + module_free_exec(mod, mod->module_init_rx);
68769 + module_free_exec(mod, mod->module_core_rx);
68770 + module_free(mod, mod->module_init_rw);
68771 + module_free(mod, mod->module_core_rw);
68772 }
68773
68774 int __weak module_finalize(const Elf_Ehdr *hdr,
68775 @@ -2918,7 +3020,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68776 static int post_relocation(struct module *mod, const struct load_info *info)
68777 {
68778 /* Sort exception table now relocations are done. */
68779 + pax_open_kernel();
68780 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68781 + pax_close_kernel();
68782
68783 /* Copy relocated percpu area over. */
68784 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68785 @@ -2989,9 +3093,38 @@ static struct module *load_module(void __user *umod,
68786 if (err)
68787 goto free_unload;
68788
68789 + /* Now copy in args */
68790 + mod->args = strndup_user(uargs, ~0UL >> 1);
68791 + if (IS_ERR(mod->args)) {
68792 + err = PTR_ERR(mod->args);
68793 + goto free_unload;
68794 + }
68795 +
68796 /* Set up MODINFO_ATTR fields */
68797 setup_modinfo(mod, &info);
68798
68799 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68800 + {
68801 + char *p, *p2;
68802 +
68803 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68804 + 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);
68805 + err = -EPERM;
68806 + goto free_modinfo;
68807 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68808 + p += sizeof("grsec_modharden_normal") - 1;
68809 + p2 = strstr(p, "_");
68810 + if (p2) {
68811 + *p2 = '\0';
68812 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68813 + *p2 = '_';
68814 + }
68815 + err = -EPERM;
68816 + goto free_modinfo;
68817 + }
68818 + }
68819 +#endif
68820 +
68821 /* Fix up syms, so that st_value is a pointer to location. */
68822 err = simplify_symbols(mod, &info);
68823 if (err < 0)
68824 @@ -3007,13 +3140,6 @@ static struct module *load_module(void __user *umod,
68825
68826 flush_module_icache(mod);
68827
68828 - /* Now copy in args */
68829 - mod->args = strndup_user(uargs, ~0UL >> 1);
68830 - if (IS_ERR(mod->args)) {
68831 - err = PTR_ERR(mod->args);
68832 - goto free_arch_cleanup;
68833 - }
68834 -
68835 /* Mark state as coming so strong_try_module_get() ignores us. */
68836 mod->state = MODULE_STATE_COMING;
68837
68838 @@ -3081,11 +3207,11 @@ again:
68839 unlock:
68840 mutex_unlock(&module_mutex);
68841 synchronize_sched();
68842 - kfree(mod->args);
68843 free_arch_cleanup:
68844 module_arch_cleanup(mod);
68845 free_modinfo:
68846 free_modinfo(mod);
68847 + kfree(mod->args);
68848 free_unload:
68849 module_unload_free(mod);
68850 free_module:
68851 @@ -3126,16 +3252,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68852 MODULE_STATE_COMING, mod);
68853
68854 /* Set RO and NX regions for core */
68855 - set_section_ro_nx(mod->module_core,
68856 - mod->core_text_size,
68857 - mod->core_ro_size,
68858 - mod->core_size);
68859 + set_section_ro_nx(mod->module_core_rx,
68860 + mod->core_size_rx,
68861 + mod->core_size_rx,
68862 + mod->core_size_rx);
68863
68864 /* Set RO and NX regions for init */
68865 - set_section_ro_nx(mod->module_init,
68866 - mod->init_text_size,
68867 - mod->init_ro_size,
68868 - mod->init_size);
68869 + set_section_ro_nx(mod->module_init_rx,
68870 + mod->init_size_rx,
68871 + mod->init_size_rx,
68872 + mod->init_size_rx);
68873
68874 do_mod_ctors(mod);
68875 /* Start the module */
68876 @@ -3180,11 +3306,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68877 mod->strtab = mod->core_strtab;
68878 #endif
68879 unset_module_init_ro_nx(mod);
68880 - module_free(mod, mod->module_init);
68881 - mod->module_init = NULL;
68882 - mod->init_size = 0;
68883 - mod->init_ro_size = 0;
68884 - mod->init_text_size = 0;
68885 + module_free(mod, mod->module_init_rw);
68886 + module_free_exec(mod, mod->module_init_rx);
68887 + mod->module_init_rw = NULL;
68888 + mod->module_init_rx = NULL;
68889 + mod->init_size_rw = 0;
68890 + mod->init_size_rx = 0;
68891 mutex_unlock(&module_mutex);
68892 wake_up_all(&module_wq);
68893
68894 @@ -3216,10 +3343,16 @@ static const char *get_ksymbol(struct module *mod,
68895 unsigned long nextval;
68896
68897 /* At worse, next value is at end of module */
68898 - if (within_module_init(addr, mod))
68899 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68900 + if (within_module_init_rx(addr, mod))
68901 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68902 + else if (within_module_init_rw(addr, mod))
68903 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68904 + else if (within_module_core_rx(addr, mod))
68905 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68906 + else if (within_module_core_rw(addr, mod))
68907 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68908 else
68909 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68910 + return NULL;
68911
68912 /* Scan for closest preceding symbol, and next symbol. (ELF
68913 starts real symbols at 1). */
68914 @@ -3454,7 +3587,7 @@ static int m_show(struct seq_file *m, void *p)
68915 char buf[8];
68916
68917 seq_printf(m, "%s %u",
68918 - mod->name, mod->init_size + mod->core_size);
68919 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68920 print_unload_info(m, mod);
68921
68922 /* Informative for users. */
68923 @@ -3463,7 +3596,7 @@ static int m_show(struct seq_file *m, void *p)
68924 mod->state == MODULE_STATE_COMING ? "Loading":
68925 "Live");
68926 /* Used by oprofile and other similar tools. */
68927 - seq_printf(m, " 0x%pK", mod->module_core);
68928 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68929
68930 /* Taints info */
68931 if (mod->taints)
68932 @@ -3499,7 +3632,17 @@ static const struct file_operations proc_modules_operations = {
68933
68934 static int __init proc_modules_init(void)
68935 {
68936 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68937 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68938 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68939 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68940 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68941 +#else
68942 proc_create("modules", 0, NULL, &proc_modules_operations);
68943 +#endif
68944 +#else
68945 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68946 +#endif
68947 return 0;
68948 }
68949 module_init(proc_modules_init);
68950 @@ -3558,12 +3701,12 @@ struct module *__module_address(unsigned long addr)
68951 {
68952 struct module *mod;
68953
68954 - if (addr < module_addr_min || addr > module_addr_max)
68955 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68956 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68957 return NULL;
68958
68959 list_for_each_entry_rcu(mod, &modules, list)
68960 - if (within_module_core(addr, mod)
68961 - || within_module_init(addr, mod))
68962 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68963 return mod;
68964 return NULL;
68965 }
68966 @@ -3597,11 +3740,20 @@ bool is_module_text_address(unsigned long addr)
68967 */
68968 struct module *__module_text_address(unsigned long addr)
68969 {
68970 - struct module *mod = __module_address(addr);
68971 + struct module *mod;
68972 +
68973 +#ifdef CONFIG_X86_32
68974 + addr = ktla_ktva(addr);
68975 +#endif
68976 +
68977 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68978 + return NULL;
68979 +
68980 + mod = __module_address(addr);
68981 +
68982 if (mod) {
68983 /* Make sure it's within the text section. */
68984 - if (!within(addr, mod->module_init, mod->init_text_size)
68985 - && !within(addr, mod->module_core, mod->core_text_size))
68986 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68987 mod = NULL;
68988 }
68989 return mod;
68990 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68991 index 7e3443f..b2a1e6b 100644
68992 --- a/kernel/mutex-debug.c
68993 +++ b/kernel/mutex-debug.c
68994 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68995 }
68996
68997 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68998 - struct thread_info *ti)
68999 + struct task_struct *task)
69000 {
69001 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69002
69003 /* Mark the current thread as blocked on the lock: */
69004 - ti->task->blocked_on = waiter;
69005 + task->blocked_on = waiter;
69006 }
69007
69008 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69009 - struct thread_info *ti)
69010 + struct task_struct *task)
69011 {
69012 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69013 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69014 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69015 - ti->task->blocked_on = NULL;
69016 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69017 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69018 + task->blocked_on = NULL;
69019
69020 list_del_init(&waiter->list);
69021 waiter->task = NULL;
69022 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69023 index 0799fd3..d06ae3b 100644
69024 --- a/kernel/mutex-debug.h
69025 +++ b/kernel/mutex-debug.h
69026 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69027 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69028 extern void debug_mutex_add_waiter(struct mutex *lock,
69029 struct mutex_waiter *waiter,
69030 - struct thread_info *ti);
69031 + struct task_struct *task);
69032 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69033 - struct thread_info *ti);
69034 + struct task_struct *task);
69035 extern void debug_mutex_unlock(struct mutex *lock);
69036 extern void debug_mutex_init(struct mutex *lock, const char *name,
69037 struct lock_class_key *key);
69038 diff --git a/kernel/mutex.c b/kernel/mutex.c
69039 index a307cc9..27fd2e9 100644
69040 --- a/kernel/mutex.c
69041 +++ b/kernel/mutex.c
69042 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69043 spin_lock_mutex(&lock->wait_lock, flags);
69044
69045 debug_mutex_lock_common(lock, &waiter);
69046 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69047 + debug_mutex_add_waiter(lock, &waiter, task);
69048
69049 /* add waiting tasks to the end of the waitqueue (FIFO): */
69050 list_add_tail(&waiter.list, &lock->wait_list);
69051 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69052 * TASK_UNINTERRUPTIBLE case.)
69053 */
69054 if (unlikely(signal_pending_state(state, task))) {
69055 - mutex_remove_waiter(lock, &waiter,
69056 - task_thread_info(task));
69057 + mutex_remove_waiter(lock, &waiter, task);
69058 mutex_release(&lock->dep_map, 1, ip);
69059 spin_unlock_mutex(&lock->wait_lock, flags);
69060
69061 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69062 done:
69063 lock_acquired(&lock->dep_map, ip);
69064 /* got the lock - rejoice! */
69065 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69066 + mutex_remove_waiter(lock, &waiter, task);
69067 mutex_set_owner(lock);
69068
69069 /* set it to 0 if there are no waiters left: */
69070 diff --git a/kernel/panic.c b/kernel/panic.c
69071 index e1b2822..5edc1d9 100644
69072 --- a/kernel/panic.c
69073 +++ b/kernel/panic.c
69074 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69075 const char *board;
69076
69077 printk(KERN_WARNING "------------[ cut here ]------------\n");
69078 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69079 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69080 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69081 if (board)
69082 printk(KERN_WARNING "Hardware name: %s\n", board);
69083 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69084 */
69085 void __stack_chk_fail(void)
69086 {
69087 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69088 + dump_stack();
69089 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69090 __builtin_return_address(0));
69091 }
69092 EXPORT_SYMBOL(__stack_chk_fail);
69093 diff --git a/kernel/pid.c b/kernel/pid.c
69094 index aebd4f5..1693c13 100644
69095 --- a/kernel/pid.c
69096 +++ b/kernel/pid.c
69097 @@ -33,6 +33,7 @@
69098 #include <linux/rculist.h>
69099 #include <linux/bootmem.h>
69100 #include <linux/hash.h>
69101 +#include <linux/security.h>
69102 #include <linux/pid_namespace.h>
69103 #include <linux/init_task.h>
69104 #include <linux/syscalls.h>
69105 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69106
69107 int pid_max = PID_MAX_DEFAULT;
69108
69109 -#define RESERVED_PIDS 300
69110 +#define RESERVED_PIDS 500
69111
69112 int pid_max_min = RESERVED_PIDS + 1;
69113 int pid_max_max = PID_MAX_LIMIT;
69114 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69115 */
69116 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69117 {
69118 + struct task_struct *task;
69119 +
69120 rcu_lockdep_assert(rcu_read_lock_held(),
69121 "find_task_by_pid_ns() needs rcu_read_lock()"
69122 " protection");
69123 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69124 +
69125 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69126 +
69127 + if (gr_pid_is_chrooted(task))
69128 + return NULL;
69129 +
69130 + return task;
69131 }
69132
69133 struct task_struct *find_task_by_vpid(pid_t vnr)
69134 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69135 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69136 }
69137
69138 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69139 +{
69140 + rcu_lockdep_assert(rcu_read_lock_held(),
69141 + "find_task_by_pid_ns() needs rcu_read_lock()"
69142 + " protection");
69143 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69144 +}
69145 +
69146 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69147 {
69148 struct pid *pid;
69149 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69150 index 125cb67..a4d1c30 100644
69151 --- a/kernel/posix-cpu-timers.c
69152 +++ b/kernel/posix-cpu-timers.c
69153 @@ -6,6 +6,7 @@
69154 #include <linux/posix-timers.h>
69155 #include <linux/errno.h>
69156 #include <linux/math64.h>
69157 +#include <linux/security.h>
69158 #include <asm/uaccess.h>
69159 #include <linux/kernel_stat.h>
69160 #include <trace/events/timer.h>
69161 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69162
69163 static __init int init_posix_cpu_timers(void)
69164 {
69165 - struct k_clock process = {
69166 + static struct k_clock process = {
69167 .clock_getres = process_cpu_clock_getres,
69168 .clock_get = process_cpu_clock_get,
69169 .timer_create = process_cpu_timer_create,
69170 .nsleep = process_cpu_nsleep,
69171 .nsleep_restart = process_cpu_nsleep_restart,
69172 };
69173 - struct k_clock thread = {
69174 + static struct k_clock thread = {
69175 .clock_getres = thread_cpu_clock_getres,
69176 .clock_get = thread_cpu_clock_get,
69177 .timer_create = thread_cpu_timer_create,
69178 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69179 index 69185ae..cc2847a 100644
69180 --- a/kernel/posix-timers.c
69181 +++ b/kernel/posix-timers.c
69182 @@ -43,6 +43,7 @@
69183 #include <linux/idr.h>
69184 #include <linux/posix-clock.h>
69185 #include <linux/posix-timers.h>
69186 +#include <linux/grsecurity.h>
69187 #include <linux/syscalls.h>
69188 #include <linux/wait.h>
69189 #include <linux/workqueue.h>
69190 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69191 * which we beg off on and pass to do_sys_settimeofday().
69192 */
69193
69194 -static struct k_clock posix_clocks[MAX_CLOCKS];
69195 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69196
69197 /*
69198 * These ones are defined below.
69199 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69200 */
69201 static __init int init_posix_timers(void)
69202 {
69203 - struct k_clock clock_realtime = {
69204 + static struct k_clock clock_realtime = {
69205 .clock_getres = hrtimer_get_res,
69206 .clock_get = posix_clock_realtime_get,
69207 .clock_set = posix_clock_realtime_set,
69208 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69209 .timer_get = common_timer_get,
69210 .timer_del = common_timer_del,
69211 };
69212 - struct k_clock clock_monotonic = {
69213 + static struct k_clock clock_monotonic = {
69214 .clock_getres = hrtimer_get_res,
69215 .clock_get = posix_ktime_get_ts,
69216 .nsleep = common_nsleep,
69217 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69218 .timer_get = common_timer_get,
69219 .timer_del = common_timer_del,
69220 };
69221 - struct k_clock clock_monotonic_raw = {
69222 + static struct k_clock clock_monotonic_raw = {
69223 .clock_getres = hrtimer_get_res,
69224 .clock_get = posix_get_monotonic_raw,
69225 };
69226 - struct k_clock clock_realtime_coarse = {
69227 + static struct k_clock clock_realtime_coarse = {
69228 .clock_getres = posix_get_coarse_res,
69229 .clock_get = posix_get_realtime_coarse,
69230 };
69231 - struct k_clock clock_monotonic_coarse = {
69232 + static struct k_clock clock_monotonic_coarse = {
69233 .clock_getres = posix_get_coarse_res,
69234 .clock_get = posix_get_monotonic_coarse,
69235 };
69236 - struct k_clock clock_boottime = {
69237 + static struct k_clock clock_boottime = {
69238 .clock_getres = hrtimer_get_res,
69239 .clock_get = posix_get_boottime,
69240 .nsleep = common_nsleep,
69241 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69242 return;
69243 }
69244
69245 - posix_clocks[clock_id] = *new_clock;
69246 + posix_clocks[clock_id] = new_clock;
69247 }
69248 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69249
69250 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69251 return (id & CLOCKFD_MASK) == CLOCKFD ?
69252 &clock_posix_dynamic : &clock_posix_cpu;
69253
69254 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69255 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69256 return NULL;
69257 - return &posix_clocks[id];
69258 + return posix_clocks[id];
69259 }
69260
69261 static int common_timer_create(struct k_itimer *new_timer)
69262 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69263 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69264 return -EFAULT;
69265
69266 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69267 + have their clock_set fptr set to a nosettime dummy function
69268 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69269 + call common_clock_set, which calls do_sys_settimeofday, which
69270 + we hook
69271 + */
69272 +
69273 return kc->clock_set(which_clock, &new_tp);
69274 }
69275
69276 diff --git a/kernel/power/process.c b/kernel/power/process.c
69277 index 87da817..30ddd13 100644
69278 --- a/kernel/power/process.c
69279 +++ b/kernel/power/process.c
69280 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69281 u64 elapsed_csecs64;
69282 unsigned int elapsed_csecs;
69283 bool wakeup = false;
69284 + bool timedout = false;
69285
69286 do_gettimeofday(&start);
69287
69288 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69289
69290 while (true) {
69291 todo = 0;
69292 + if (time_after(jiffies, end_time))
69293 + timedout = true;
69294 read_lock(&tasklist_lock);
69295 do_each_thread(g, p) {
69296 if (p == current || !freeze_task(p))
69297 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69298 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69299 * transition can't race with task state testing here.
69300 */
69301 - if (!task_is_stopped_or_traced(p) &&
69302 - !freezer_should_skip(p))
69303 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69304 todo++;
69305 + if (timedout) {
69306 + printk(KERN_ERR "Task refusing to freeze:\n");
69307 + sched_show_task(p);
69308 + }
69309 + }
69310 } while_each_thread(g, p);
69311 read_unlock(&tasklist_lock);
69312
69313 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69314 todo += wq_busy;
69315 }
69316
69317 - if (!todo || time_after(jiffies, end_time))
69318 + if (!todo || timedout)
69319 break;
69320
69321 if (pm_wakeup_pending()) {
69322 diff --git a/kernel/printk.c b/kernel/printk.c
69323 index 2d607f4..7413773 100644
69324 --- a/kernel/printk.c
69325 +++ b/kernel/printk.c
69326 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69327 if (from_file && type != SYSLOG_ACTION_OPEN)
69328 return 0;
69329
69330 +#ifdef CONFIG_GRKERNSEC_DMESG
69331 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69332 + return -EPERM;
69333 +#endif
69334 +
69335 if (syslog_action_restricted(type)) {
69336 if (capable(CAP_SYSLOG))
69337 return 0;
69338 diff --git a/kernel/profile.c b/kernel/profile.c
69339 index 76b8e77..a2930e8 100644
69340 --- a/kernel/profile.c
69341 +++ b/kernel/profile.c
69342 @@ -39,7 +39,7 @@ struct profile_hit {
69343 /* Oprofile timer tick hook */
69344 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69345
69346 -static atomic_t *prof_buffer;
69347 +static atomic_unchecked_t *prof_buffer;
69348 static unsigned long prof_len, prof_shift;
69349
69350 int prof_on __read_mostly;
69351 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69352 hits[i].pc = 0;
69353 continue;
69354 }
69355 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69356 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69357 hits[i].hits = hits[i].pc = 0;
69358 }
69359 }
69360 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69361 * Add the current hit(s) and flush the write-queue out
69362 * to the global buffer:
69363 */
69364 - atomic_add(nr_hits, &prof_buffer[pc]);
69365 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69366 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69367 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69368 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69369 hits[i].pc = hits[i].hits = 0;
69370 }
69371 out:
69372 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69373 {
69374 unsigned long pc;
69375 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69376 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69377 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69378 }
69379 #endif /* !CONFIG_SMP */
69380
69381 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69382 return -EFAULT;
69383 buf++; p++; count--; read++;
69384 }
69385 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69386 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69387 if (copy_to_user(buf, (void *)pnt, count))
69388 return -EFAULT;
69389 read += count;
69390 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69391 }
69392 #endif
69393 profile_discard_flip_buffers();
69394 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69395 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69396 return count;
69397 }
69398
69399 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69400 index 1f5e55d..8b8f969 100644
69401 --- a/kernel/ptrace.c
69402 +++ b/kernel/ptrace.c
69403 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69404
69405 if (seize)
69406 flags |= PT_SEIZED;
69407 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69408 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69409 flags |= PT_PTRACE_CAP;
69410 task->ptrace = flags;
69411
69412 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69413 break;
69414 return -EIO;
69415 }
69416 - if (copy_to_user(dst, buf, retval))
69417 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69418 return -EFAULT;
69419 copied += retval;
69420 src += retval;
69421 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
69422 bool seized = child->ptrace & PT_SEIZED;
69423 int ret = -EIO;
69424 siginfo_t siginfo, *si;
69425 - void __user *datavp = (void __user *) data;
69426 + void __user *datavp = (__force void __user *) data;
69427 unsigned long __user *datalp = datavp;
69428 unsigned long flags;
69429
69430 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69431 goto out;
69432 }
69433
69434 + if (gr_handle_ptrace(child, request)) {
69435 + ret = -EPERM;
69436 + goto out_put_task_struct;
69437 + }
69438 +
69439 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69440 ret = ptrace_attach(child, request, addr, data);
69441 /*
69442 * Some architectures need to do book-keeping after
69443 * a ptrace attach.
69444 */
69445 - if (!ret)
69446 + if (!ret) {
69447 arch_ptrace_attach(child);
69448 + gr_audit_ptrace(child);
69449 + }
69450 goto out_put_task_struct;
69451 }
69452
69453 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69454 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69455 if (copied != sizeof(tmp))
69456 return -EIO;
69457 - return put_user(tmp, (unsigned long __user *)data);
69458 + return put_user(tmp, (__force unsigned long __user *)data);
69459 }
69460
69461 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69462 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69463 goto out;
69464 }
69465
69466 + if (gr_handle_ptrace(child, request)) {
69467 + ret = -EPERM;
69468 + goto out_put_task_struct;
69469 + }
69470 +
69471 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69472 ret = ptrace_attach(child, request, addr, data);
69473 /*
69474 * Some architectures need to do book-keeping after
69475 * a ptrace attach.
69476 */
69477 - if (!ret)
69478 + if (!ret) {
69479 arch_ptrace_attach(child);
69480 + gr_audit_ptrace(child);
69481 + }
69482 goto out_put_task_struct;
69483 }
69484
69485 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69486 index e4c6a59..c86621a 100644
69487 --- a/kernel/rcutiny.c
69488 +++ b/kernel/rcutiny.c
69489 @@ -46,7 +46,7 @@
69490 struct rcu_ctrlblk;
69491 static void invoke_rcu_callbacks(void);
69492 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69493 -static void rcu_process_callbacks(struct softirq_action *unused);
69494 +static void rcu_process_callbacks(void);
69495 static void __call_rcu(struct rcu_head *head,
69496 void (*func)(struct rcu_head *rcu),
69497 struct rcu_ctrlblk *rcp);
69498 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69499 rcu_is_callbacks_kthread()));
69500 }
69501
69502 -static void rcu_process_callbacks(struct softirq_action *unused)
69503 +static void rcu_process_callbacks(void)
69504 {
69505 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69506 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69507 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69508 index 3d01902..afbf46e 100644
69509 --- a/kernel/rcutiny_plugin.h
69510 +++ b/kernel/rcutiny_plugin.h
69511 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69512 have_rcu_kthread_work = morework;
69513 local_irq_restore(flags);
69514 if (work)
69515 - rcu_process_callbacks(NULL);
69516 + rcu_process_callbacks();
69517 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69518 }
69519
69520 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69521 index aaa7b9f..055ff1e 100644
69522 --- a/kernel/rcutorture.c
69523 +++ b/kernel/rcutorture.c
69524 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69525 { 0 };
69526 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69527 { 0 };
69528 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69529 -static atomic_t n_rcu_torture_alloc;
69530 -static atomic_t n_rcu_torture_alloc_fail;
69531 -static atomic_t n_rcu_torture_free;
69532 -static atomic_t n_rcu_torture_mberror;
69533 -static atomic_t n_rcu_torture_error;
69534 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69535 +static atomic_unchecked_t n_rcu_torture_alloc;
69536 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69537 +static atomic_unchecked_t n_rcu_torture_free;
69538 +static atomic_unchecked_t n_rcu_torture_mberror;
69539 +static atomic_unchecked_t n_rcu_torture_error;
69540 static long n_rcu_torture_barrier_error;
69541 static long n_rcu_torture_boost_ktrerror;
69542 static long n_rcu_torture_boost_rterror;
69543 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
69544
69545 spin_lock_bh(&rcu_torture_lock);
69546 if (list_empty(&rcu_torture_freelist)) {
69547 - atomic_inc(&n_rcu_torture_alloc_fail);
69548 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69549 spin_unlock_bh(&rcu_torture_lock);
69550 return NULL;
69551 }
69552 - atomic_inc(&n_rcu_torture_alloc);
69553 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69554 p = rcu_torture_freelist.next;
69555 list_del_init(p);
69556 spin_unlock_bh(&rcu_torture_lock);
69557 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
69558 static void
69559 rcu_torture_free(struct rcu_torture *p)
69560 {
69561 - atomic_inc(&n_rcu_torture_free);
69562 + atomic_inc_unchecked(&n_rcu_torture_free);
69563 spin_lock_bh(&rcu_torture_lock);
69564 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69565 spin_unlock_bh(&rcu_torture_lock);
69566 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
69567 i = rp->rtort_pipe_count;
69568 if (i > RCU_TORTURE_PIPE_LEN)
69569 i = RCU_TORTURE_PIPE_LEN;
69570 - atomic_inc(&rcu_torture_wcount[i]);
69571 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69572 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69573 rp->rtort_mbtest = 0;
69574 rcu_torture_free(rp);
69575 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69576 i = rp->rtort_pipe_count;
69577 if (i > RCU_TORTURE_PIPE_LEN)
69578 i = RCU_TORTURE_PIPE_LEN;
69579 - atomic_inc(&rcu_torture_wcount[i]);
69580 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69581 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69582 rp->rtort_mbtest = 0;
69583 list_del(&rp->rtort_free);
69584 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
69585 i = old_rp->rtort_pipe_count;
69586 if (i > RCU_TORTURE_PIPE_LEN)
69587 i = RCU_TORTURE_PIPE_LEN;
69588 - atomic_inc(&rcu_torture_wcount[i]);
69589 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69590 old_rp->rtort_pipe_count++;
69591 cur_ops->deferred_free(old_rp);
69592 }
69593 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
69594 }
69595 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69596 if (p->rtort_mbtest == 0)
69597 - atomic_inc(&n_rcu_torture_mberror);
69598 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69599 spin_lock(&rand_lock);
69600 cur_ops->read_delay(&rand);
69601 n_rcu_torture_timers++;
69602 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
69603 }
69604 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69605 if (p->rtort_mbtest == 0)
69606 - atomic_inc(&n_rcu_torture_mberror);
69607 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69608 cur_ops->read_delay(&rand);
69609 preempt_disable();
69610 pipe_count = p->rtort_pipe_count;
69611 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
69612 rcu_torture_current,
69613 rcu_torture_current_version,
69614 list_empty(&rcu_torture_freelist),
69615 - atomic_read(&n_rcu_torture_alloc),
69616 - atomic_read(&n_rcu_torture_alloc_fail),
69617 - atomic_read(&n_rcu_torture_free));
69618 + atomic_read_unchecked(&n_rcu_torture_alloc),
69619 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69620 + atomic_read_unchecked(&n_rcu_torture_free));
69621 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69622 - atomic_read(&n_rcu_torture_mberror),
69623 + atomic_read_unchecked(&n_rcu_torture_mberror),
69624 n_rcu_torture_boost_ktrerror,
69625 n_rcu_torture_boost_rterror);
69626 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69627 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
69628 n_barrier_attempts,
69629 n_rcu_torture_barrier_error);
69630 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69631 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69632 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69633 n_rcu_torture_barrier_error != 0 ||
69634 n_rcu_torture_boost_ktrerror != 0 ||
69635 n_rcu_torture_boost_rterror != 0 ||
69636 n_rcu_torture_boost_failure != 0 ||
69637 i > 1) {
69638 cnt += sprintf(&page[cnt], "!!! ");
69639 - atomic_inc(&n_rcu_torture_error);
69640 + atomic_inc_unchecked(&n_rcu_torture_error);
69641 WARN_ON_ONCE(1);
69642 }
69643 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69644 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
69645 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69646 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69647 cnt += sprintf(&page[cnt], " %d",
69648 - atomic_read(&rcu_torture_wcount[i]));
69649 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69650 }
69651 cnt += sprintf(&page[cnt], "\n");
69652 if (cur_ops->stats)
69653 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
69654
69655 if (cur_ops->cleanup)
69656 cur_ops->cleanup();
69657 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69658 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69659 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69660 else if (n_online_successes != n_online_attempts ||
69661 n_offline_successes != n_offline_attempts)
69662 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
69663
69664 rcu_torture_current = NULL;
69665 rcu_torture_current_version = 0;
69666 - atomic_set(&n_rcu_torture_alloc, 0);
69667 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69668 - atomic_set(&n_rcu_torture_free, 0);
69669 - atomic_set(&n_rcu_torture_mberror, 0);
69670 - atomic_set(&n_rcu_torture_error, 0);
69671 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69672 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69673 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69674 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69675 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69676 n_rcu_torture_barrier_error = 0;
69677 n_rcu_torture_boost_ktrerror = 0;
69678 n_rcu_torture_boost_rterror = 0;
69679 n_rcu_torture_boost_failure = 0;
69680 n_rcu_torture_boosts = 0;
69681 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69682 - atomic_set(&rcu_torture_wcount[i], 0);
69683 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69684 for_each_possible_cpu(cpu) {
69685 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69686 per_cpu(rcu_torture_count, cpu)[i] = 0;
69687 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69688 index 2682295..0f2297e 100644
69689 --- a/kernel/rcutree.c
69690 +++ b/kernel/rcutree.c
69691 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
69692 rcu_prepare_for_idle(smp_processor_id());
69693 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69694 smp_mb__before_atomic_inc(); /* See above. */
69695 - atomic_inc(&rdtp->dynticks);
69696 + atomic_inc_unchecked(&rdtp->dynticks);
69697 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69698 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69699 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69700
69701 /*
69702 * It is illegal to enter an extended quiescent state while
69703 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
69704 int user)
69705 {
69706 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69707 - atomic_inc(&rdtp->dynticks);
69708 + atomic_inc_unchecked(&rdtp->dynticks);
69709 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69710 smp_mb__after_atomic_inc(); /* See above. */
69711 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69712 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69713 rcu_cleanup_after_idle(smp_processor_id());
69714 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69715 if (!user && !is_idle_task(current)) {
69716 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
69717 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69718
69719 if (rdtp->dynticks_nmi_nesting == 0 &&
69720 - (atomic_read(&rdtp->dynticks) & 0x1))
69721 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69722 return;
69723 rdtp->dynticks_nmi_nesting++;
69724 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69725 - atomic_inc(&rdtp->dynticks);
69726 + atomic_inc_unchecked(&rdtp->dynticks);
69727 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69728 smp_mb__after_atomic_inc(); /* See above. */
69729 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69730 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69731 }
69732
69733 /**
69734 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
69735 return;
69736 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69737 smp_mb__before_atomic_inc(); /* See above. */
69738 - atomic_inc(&rdtp->dynticks);
69739 + atomic_inc_unchecked(&rdtp->dynticks);
69740 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69741 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69742 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69743 }
69744
69745 /**
69746 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
69747 int ret;
69748
69749 preempt_disable();
69750 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69751 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69752 preempt_enable();
69753 return ret;
69754 }
69755 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69756 */
69757 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69758 {
69759 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69760 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69761 return (rdp->dynticks_snap & 0x1) == 0;
69762 }
69763
69764 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69765 unsigned int curr;
69766 unsigned int snap;
69767
69768 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69769 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69770 snap = (unsigned int)rdp->dynticks_snap;
69771
69772 /*
69773 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
69774 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69775 */
69776 if (till_stall_check < 3) {
69777 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69778 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69779 till_stall_check = 3;
69780 } else if (till_stall_check > 300) {
69781 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69782 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69783 till_stall_check = 300;
69784 }
69785 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69786 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69787 rsp->qlen += rdp->qlen;
69788 rdp->n_cbs_orphaned += rdp->qlen;
69789 rdp->qlen_lazy = 0;
69790 - ACCESS_ONCE(rdp->qlen) = 0;
69791 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69792 }
69793
69794 /*
69795 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69796 }
69797 smp_mb(); /* List handling before counting for rcu_barrier(). */
69798 rdp->qlen_lazy -= count_lazy;
69799 - ACCESS_ONCE(rdp->qlen) -= count;
69800 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69801 rdp->n_cbs_invoked += count;
69802
69803 /* Reinstate batch limit if we have worked down the excess. */
69804 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69805 /*
69806 * Do RCU core processing for the current CPU.
69807 */
69808 -static void rcu_process_callbacks(struct softirq_action *unused)
69809 +static void rcu_process_callbacks(void)
69810 {
69811 struct rcu_state *rsp;
69812
69813 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69814 local_irq_restore(flags);
69815 return;
69816 }
69817 - ACCESS_ONCE(rdp->qlen)++;
69818 + ACCESS_ONCE_RW(rdp->qlen)++;
69819 if (lazy)
69820 rdp->qlen_lazy++;
69821 else
69822 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
69823 }
69824 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69825
69826 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69827 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69828 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69829 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69830
69831 static int synchronize_sched_expedited_cpu_stop(void *data)
69832 {
69833 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
69834 int firstsnap, s, snap, trycount = 0;
69835
69836 /* Note that atomic_inc_return() implies full memory barrier. */
69837 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69838 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69839 get_online_cpus();
69840 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69841
69842 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
69843 }
69844
69845 /* Check to see if someone else did our work for us. */
69846 - s = atomic_read(&sync_sched_expedited_done);
69847 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69848 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69849 smp_mb(); /* ensure test happens before caller kfree */
69850 return;
69851 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
69852 * grace period works for us.
69853 */
69854 get_online_cpus();
69855 - snap = atomic_read(&sync_sched_expedited_started);
69856 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69857 smp_mb(); /* ensure read is before try_stop_cpus(). */
69858 }
69859
69860 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
69861 * than we did beat us to the punch.
69862 */
69863 do {
69864 - s = atomic_read(&sync_sched_expedited_done);
69865 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69866 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69867 smp_mb(); /* ensure test happens before caller kfree */
69868 break;
69869 }
69870 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69871 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69872
69873 put_online_cpus();
69874 }
69875 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69876 * ACCESS_ONCE() to prevent the compiler from speculating
69877 * the increment to precede the early-exit check.
69878 */
69879 - ACCESS_ONCE(rsp->n_barrier_done)++;
69880 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69881 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69882 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69883 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69884 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69885
69886 /* Increment ->n_barrier_done to prevent duplicate work. */
69887 smp_mb(); /* Keep increment after above mechanism. */
69888 - ACCESS_ONCE(rsp->n_barrier_done)++;
69889 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69890 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69891 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69892 smp_mb(); /* Keep increment before caller's subsequent code. */
69893 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69894 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69895 init_callback_list(rdp);
69896 rdp->qlen_lazy = 0;
69897 - ACCESS_ONCE(rdp->qlen) = 0;
69898 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69899 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69900 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69901 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69902 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69903 #ifdef CONFIG_RCU_USER_QS
69904 WARN_ON_ONCE(rdp->dynticks->in_user);
69905 #endif
69906 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69907 rdp->blimit = blimit;
69908 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
69909 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69910 - atomic_set(&rdp->dynticks->dynticks,
69911 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69912 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69913 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69914 rcu_prepare_for_idle_init(cpu);
69915 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69916
69917 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69918 index a240f03..d469618 100644
69919 --- a/kernel/rcutree.h
69920 +++ b/kernel/rcutree.h
69921 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69922 long long dynticks_nesting; /* Track irq/process nesting level. */
69923 /* Process level is worth LLONG_MAX/2. */
69924 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69925 - atomic_t dynticks; /* Even value for idle, else odd. */
69926 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69927 #ifdef CONFIG_RCU_FAST_NO_HZ
69928 int dyntick_drain; /* Prepare-for-idle state variable. */
69929 unsigned long dyntick_holdoff;
69930 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69931 index f921154..34c4873 100644
69932 --- a/kernel/rcutree_plugin.h
69933 +++ b/kernel/rcutree_plugin.h
69934 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
69935
69936 /* Clean up and exit. */
69937 smp_mb(); /* ensure expedited GP seen before counter increment. */
69938 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69939 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69940 unlock_mb_ret:
69941 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69942 mb_ret:
69943 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
69944 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
69945 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
69946 cpu, ticks_value, ticks_title,
69947 - atomic_read(&rdtp->dynticks) & 0xfff,
69948 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
69949 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
69950 fast_no_hz);
69951 }
69952 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69953 index 693513b..b9f1d63 100644
69954 --- a/kernel/rcutree_trace.c
69955 +++ b/kernel/rcutree_trace.c
69956 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69957 rdp->completed, rdp->gpnum,
69958 rdp->passed_quiesce, rdp->qs_pending);
69959 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69960 - atomic_read(&rdp->dynticks->dynticks),
69961 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69962 rdp->dynticks->dynticks_nesting,
69963 rdp->dynticks->dynticks_nmi_nesting,
69964 rdp->dynticks_fqs);
69965 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69966 rdp->completed, rdp->gpnum,
69967 rdp->passed_quiesce, rdp->qs_pending);
69968 seq_printf(m, ",%d,%llx,%d,%lu",
69969 - atomic_read(&rdp->dynticks->dynticks),
69970 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69971 rdp->dynticks->dynticks_nesting,
69972 rdp->dynticks->dynticks_nmi_nesting,
69973 rdp->dynticks_fqs);
69974 diff --git a/kernel/resource.c b/kernel/resource.c
69975 index 73f35d4..4684fc4 100644
69976 --- a/kernel/resource.c
69977 +++ b/kernel/resource.c
69978 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69979
69980 static int __init ioresources_init(void)
69981 {
69982 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69983 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69984 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69985 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69986 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69987 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69988 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69989 +#endif
69990 +#else
69991 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69992 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69993 +#endif
69994 return 0;
69995 }
69996 __initcall(ioresources_init);
69997 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69998 index 98ec494..4241d6d 100644
69999 --- a/kernel/rtmutex-tester.c
70000 +++ b/kernel/rtmutex-tester.c
70001 @@ -20,7 +20,7 @@
70002 #define MAX_RT_TEST_MUTEXES 8
70003
70004 static spinlock_t rttest_lock;
70005 -static atomic_t rttest_event;
70006 +static atomic_unchecked_t rttest_event;
70007
70008 struct test_thread_data {
70009 int opcode;
70010 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70011
70012 case RTTEST_LOCKCONT:
70013 td->mutexes[td->opdata] = 1;
70014 - td->event = atomic_add_return(1, &rttest_event);
70015 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70016 return 0;
70017
70018 case RTTEST_RESET:
70019 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70020 return 0;
70021
70022 case RTTEST_RESETEVENT:
70023 - atomic_set(&rttest_event, 0);
70024 + atomic_set_unchecked(&rttest_event, 0);
70025 return 0;
70026
70027 default:
70028 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70029 return ret;
70030
70031 td->mutexes[id] = 1;
70032 - td->event = atomic_add_return(1, &rttest_event);
70033 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70034 rt_mutex_lock(&mutexes[id]);
70035 - td->event = atomic_add_return(1, &rttest_event);
70036 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70037 td->mutexes[id] = 4;
70038 return 0;
70039
70040 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70041 return ret;
70042
70043 td->mutexes[id] = 1;
70044 - td->event = atomic_add_return(1, &rttest_event);
70045 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70046 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70047 - td->event = atomic_add_return(1, &rttest_event);
70048 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70049 td->mutexes[id] = ret ? 0 : 4;
70050 return ret ? -EINTR : 0;
70051
70052 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70053 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70054 return ret;
70055
70056 - td->event = atomic_add_return(1, &rttest_event);
70057 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70058 rt_mutex_unlock(&mutexes[id]);
70059 - td->event = atomic_add_return(1, &rttest_event);
70060 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70061 td->mutexes[id] = 0;
70062 return 0;
70063
70064 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70065 break;
70066
70067 td->mutexes[dat] = 2;
70068 - td->event = atomic_add_return(1, &rttest_event);
70069 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70070 break;
70071
70072 default:
70073 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70074 return;
70075
70076 td->mutexes[dat] = 3;
70077 - td->event = atomic_add_return(1, &rttest_event);
70078 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70079 break;
70080
70081 case RTTEST_LOCKNOWAIT:
70082 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70083 return;
70084
70085 td->mutexes[dat] = 1;
70086 - td->event = atomic_add_return(1, &rttest_event);
70087 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70088 return;
70089
70090 default:
70091 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70092 index 15f60d0..7e50319 100644
70093 --- a/kernel/sched/auto_group.c
70094 +++ b/kernel/sched/auto_group.c
70095 @@ -11,7 +11,7 @@
70096
70097 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70098 static struct autogroup autogroup_default;
70099 -static atomic_t autogroup_seq_nr;
70100 +static atomic_unchecked_t autogroup_seq_nr;
70101
70102 void __init autogroup_init(struct task_struct *init_task)
70103 {
70104 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70105
70106 kref_init(&ag->kref);
70107 init_rwsem(&ag->lock);
70108 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70109 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70110 ag->tg = tg;
70111 #ifdef CONFIG_RT_GROUP_SCHED
70112 /*
70113 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70114 index 2d8927f..f617765 100644
70115 --- a/kernel/sched/core.c
70116 +++ b/kernel/sched/core.c
70117 @@ -3562,6 +3562,8 @@ int can_nice(const struct task_struct *p, const int nice)
70118 /* convert nice value [19,-20] to rlimit style value [1,40] */
70119 int nice_rlim = 20 - nice;
70120
70121 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70122 +
70123 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70124 capable(CAP_SYS_NICE));
70125 }
70126 @@ -3595,7 +3597,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70127 if (nice > 19)
70128 nice = 19;
70129
70130 - if (increment < 0 && !can_nice(current, nice))
70131 + if (increment < 0 && (!can_nice(current, nice) ||
70132 + gr_handle_chroot_nice()))
70133 return -EPERM;
70134
70135 retval = security_task_setnice(current, nice);
70136 @@ -3749,6 +3752,7 @@ recheck:
70137 unsigned long rlim_rtprio =
70138 task_rlimit(p, RLIMIT_RTPRIO);
70139
70140 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70141 /* can't set/change the rt policy */
70142 if (policy != p->policy && !rlim_rtprio)
70143 return -EPERM;
70144 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70145 index 6b800a1..0c36227 100644
70146 --- a/kernel/sched/fair.c
70147 +++ b/kernel/sched/fair.c
70148 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70149 * run_rebalance_domains is triggered when needed from the scheduler tick.
70150 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70151 */
70152 -static void run_rebalance_domains(struct softirq_action *h)
70153 +static void run_rebalance_domains(void)
70154 {
70155 int this_cpu = smp_processor_id();
70156 struct rq *this_rq = cpu_rq(this_cpu);
70157 diff --git a/kernel/signal.c b/kernel/signal.c
70158 index 0af8868..a00119d 100644
70159 --- a/kernel/signal.c
70160 +++ b/kernel/signal.c
70161 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
70162
70163 int print_fatal_signals __read_mostly;
70164
70165 -static void __user *sig_handler(struct task_struct *t, int sig)
70166 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70167 {
70168 return t->sighand->action[sig - 1].sa.sa_handler;
70169 }
70170
70171 -static int sig_handler_ignored(void __user *handler, int sig)
70172 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70173 {
70174 /* Is it explicitly or implicitly ignored? */
70175 return handler == SIG_IGN ||
70176 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70177
70178 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70179 {
70180 - void __user *handler;
70181 + __sighandler_t handler;
70182
70183 handler = sig_handler(t, sig);
70184
70185 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70186 atomic_inc(&user->sigpending);
70187 rcu_read_unlock();
70188
70189 + if (!override_rlimit)
70190 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70191 +
70192 if (override_rlimit ||
70193 atomic_read(&user->sigpending) <=
70194 task_rlimit(t, RLIMIT_SIGPENDING)) {
70195 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70196
70197 int unhandled_signal(struct task_struct *tsk, int sig)
70198 {
70199 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70200 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70201 if (is_global_init(tsk))
70202 return 1;
70203 if (handler != SIG_IGN && handler != SIG_DFL)
70204 @@ -817,6 +820,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70205 }
70206 }
70207
70208 + /* allow glibc communication via tgkill to other threads in our
70209 + thread group */
70210 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70211 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70212 + && gr_handle_signal(t, sig))
70213 + return -EPERM;
70214 +
70215 return security_task_kill(t, info, sig, 0);
70216 }
70217
70218 @@ -1198,7 +1208,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70219 return send_signal(sig, info, p, 1);
70220 }
70221
70222 -static int
70223 +int
70224 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70225 {
70226 return send_signal(sig, info, t, 0);
70227 @@ -1235,6 +1245,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70228 unsigned long int flags;
70229 int ret, blocked, ignored;
70230 struct k_sigaction *action;
70231 + int is_unhandled = 0;
70232
70233 spin_lock_irqsave(&t->sighand->siglock, flags);
70234 action = &t->sighand->action[sig-1];
70235 @@ -1249,9 +1260,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70236 }
70237 if (action->sa.sa_handler == SIG_DFL)
70238 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70239 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70240 + is_unhandled = 1;
70241 ret = specific_send_sig_info(sig, info, t);
70242 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70243
70244 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70245 + normal operation */
70246 + if (is_unhandled) {
70247 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70248 + gr_handle_crash(t, sig);
70249 + }
70250 +
70251 return ret;
70252 }
70253
70254 @@ -1318,8 +1338,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70255 ret = check_kill_permission(sig, info, p);
70256 rcu_read_unlock();
70257
70258 - if (!ret && sig)
70259 + if (!ret && sig) {
70260 ret = do_send_sig_info(sig, info, p, true);
70261 + if (!ret)
70262 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70263 + }
70264
70265 return ret;
70266 }
70267 @@ -2864,7 +2887,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70268 int error = -ESRCH;
70269
70270 rcu_read_lock();
70271 - p = find_task_by_vpid(pid);
70272 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70273 + /* allow glibc communication via tgkill to other threads in our
70274 + thread group */
70275 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70276 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70277 + p = find_task_by_vpid_unrestricted(pid);
70278 + else
70279 +#endif
70280 + p = find_task_by_vpid(pid);
70281 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70282 error = check_kill_permission(sig, info, p);
70283 /*
70284 diff --git a/kernel/softirq.c b/kernel/softirq.c
70285 index cc96bdc..8bb9750 100644
70286 --- a/kernel/softirq.c
70287 +++ b/kernel/softirq.c
70288 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70289
70290 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70291
70292 -char *softirq_to_name[NR_SOFTIRQS] = {
70293 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70294 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70295 "TASKLET", "SCHED", "HRTIMER", "RCU"
70296 };
70297 @@ -244,7 +244,7 @@ restart:
70298 kstat_incr_softirqs_this_cpu(vec_nr);
70299
70300 trace_softirq_entry(vec_nr);
70301 - h->action(h);
70302 + h->action();
70303 trace_softirq_exit(vec_nr);
70304 if (unlikely(prev_count != preempt_count())) {
70305 printk(KERN_ERR "huh, entered softirq %u %s %p"
70306 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70307 or_softirq_pending(1UL << nr);
70308 }
70309
70310 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70311 +void open_softirq(int nr, void (*action)(void))
70312 {
70313 - softirq_vec[nr].action = action;
70314 + pax_open_kernel();
70315 + *(void **)&softirq_vec[nr].action = action;
70316 + pax_close_kernel();
70317 }
70318
70319 /*
70320 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70321
70322 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70323
70324 -static void tasklet_action(struct softirq_action *a)
70325 +static void tasklet_action(void)
70326 {
70327 struct tasklet_struct *list;
70328
70329 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
70330 }
70331 }
70332
70333 -static void tasklet_hi_action(struct softirq_action *a)
70334 +static void tasklet_hi_action(void)
70335 {
70336 struct tasklet_struct *list;
70337
70338 diff --git a/kernel/srcu.c b/kernel/srcu.c
70339 index 97c465e..d83f3bb 100644
70340 --- a/kernel/srcu.c
70341 +++ b/kernel/srcu.c
70342 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70343 preempt_disable();
70344 idx = rcu_dereference_index_check(sp->completed,
70345 rcu_read_lock_sched_held()) & 0x1;
70346 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70347 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70348 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70349 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70350 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70351 preempt_enable();
70352 return idx;
70353 }
70354 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70355 {
70356 preempt_disable();
70357 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70358 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70359 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70360 preempt_enable();
70361 }
70362 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70363 diff --git a/kernel/sys.c b/kernel/sys.c
70364 index e6e0ece..1f2e413 100644
70365 --- a/kernel/sys.c
70366 +++ b/kernel/sys.c
70367 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70368 error = -EACCES;
70369 goto out;
70370 }
70371 +
70372 + if (gr_handle_chroot_setpriority(p, niceval)) {
70373 + error = -EACCES;
70374 + goto out;
70375 + }
70376 +
70377 no_nice = security_task_setnice(p, niceval);
70378 if (no_nice) {
70379 error = no_nice;
70380 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70381 goto error;
70382 }
70383
70384 + if (gr_check_group_change(new->gid, new->egid, -1))
70385 + goto error;
70386 +
70387 if (rgid != (gid_t) -1 ||
70388 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70389 new->sgid = new->egid;
70390 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70391 old = current_cred();
70392
70393 retval = -EPERM;
70394 +
70395 + if (gr_check_group_change(kgid, kgid, kgid))
70396 + goto error;
70397 +
70398 if (nsown_capable(CAP_SETGID))
70399 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70400 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70401 @@ -647,7 +660,7 @@ error:
70402 /*
70403 * change the user struct in a credentials set to match the new UID
70404 */
70405 -static int set_user(struct cred *new)
70406 +int set_user(struct cred *new)
70407 {
70408 struct user_struct *new_user;
70409
70410 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70411 goto error;
70412 }
70413
70414 + if (gr_check_user_change(new->uid, new->euid, -1))
70415 + goto error;
70416 +
70417 if (!uid_eq(new->uid, old->uid)) {
70418 retval = set_user(new);
70419 if (retval < 0)
70420 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70421 old = current_cred();
70422
70423 retval = -EPERM;
70424 +
70425 + if (gr_check_crash_uid(kuid))
70426 + goto error;
70427 + if (gr_check_user_change(kuid, kuid, kuid))
70428 + goto error;
70429 +
70430 if (nsown_capable(CAP_SETUID)) {
70431 new->suid = new->uid = kuid;
70432 if (!uid_eq(kuid, old->uid)) {
70433 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70434 goto error;
70435 }
70436
70437 + if (gr_check_user_change(kruid, keuid, -1))
70438 + goto error;
70439 +
70440 if (ruid != (uid_t) -1) {
70441 new->uid = kruid;
70442 if (!uid_eq(kruid, old->uid)) {
70443 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70444 goto error;
70445 }
70446
70447 + if (gr_check_group_change(krgid, kegid, -1))
70448 + goto error;
70449 +
70450 if (rgid != (gid_t) -1)
70451 new->gid = krgid;
70452 if (egid != (gid_t) -1)
70453 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70454 if (!uid_valid(kuid))
70455 return old_fsuid;
70456
70457 + if (gr_check_user_change(-1, -1, kuid))
70458 + goto error;
70459 +
70460 new = prepare_creds();
70461 if (!new)
70462 return old_fsuid;
70463 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70464 }
70465 }
70466
70467 +error:
70468 abort_creds(new);
70469 return old_fsuid;
70470
70471 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70472 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70473 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70474 nsown_capable(CAP_SETGID)) {
70475 + if (gr_check_group_change(-1, -1, kgid))
70476 + goto error;
70477 +
70478 if (!gid_eq(kgid, old->fsgid)) {
70479 new->fsgid = kgid;
70480 goto change_okay;
70481 }
70482 }
70483
70484 +error:
70485 abort_creds(new);
70486 return old_fsgid;
70487
70488 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70489 return -EFAULT;
70490
70491 down_read(&uts_sem);
70492 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70493 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70494 __OLD_UTS_LEN);
70495 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70496 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70497 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70498 __OLD_UTS_LEN);
70499 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70500 - error |= __copy_to_user(&name->release, &utsname()->release,
70501 + error |= __copy_to_user(name->release, &utsname()->release,
70502 __OLD_UTS_LEN);
70503 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70504 - error |= __copy_to_user(&name->version, &utsname()->version,
70505 + error |= __copy_to_user(name->version, &utsname()->version,
70506 __OLD_UTS_LEN);
70507 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70508 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70509 + error |= __copy_to_user(name->machine, &utsname()->machine,
70510 __OLD_UTS_LEN);
70511 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70512 up_read(&uts_sem);
70513 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70514 error = get_dumpable(me->mm);
70515 break;
70516 case PR_SET_DUMPABLE:
70517 - if (arg2 < 0 || arg2 > 1) {
70518 + if (arg2 > 1) {
70519 error = -EINVAL;
70520 break;
70521 }
70522 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70523 index 26f65ea..df8e5ad 100644
70524 --- a/kernel/sysctl.c
70525 +++ b/kernel/sysctl.c
70526 @@ -92,7 +92,6 @@
70527
70528
70529 #if defined(CONFIG_SYSCTL)
70530 -
70531 /* External variables not in a header file. */
70532 extern int sysctl_overcommit_memory;
70533 extern int sysctl_overcommit_ratio;
70534 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
70535 void __user *buffer, size_t *lenp, loff_t *ppos);
70536 #endif
70537
70538 -#ifdef CONFIG_PRINTK
70539 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70540 void __user *buffer, size_t *lenp, loff_t *ppos);
70541 -#endif
70542
70543 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70544 void __user *buffer, size_t *lenp, loff_t *ppos);
70545 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70546
70547 #endif
70548
70549 +extern struct ctl_table grsecurity_table[];
70550 +
70551 static struct ctl_table kern_table[];
70552 static struct ctl_table vm_table[];
70553 static struct ctl_table fs_table[];
70554 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
70555 int sysctl_legacy_va_layout;
70556 #endif
70557
70558 +#ifdef CONFIG_PAX_SOFTMODE
70559 +static ctl_table pax_table[] = {
70560 + {
70561 + .procname = "softmode",
70562 + .data = &pax_softmode,
70563 + .maxlen = sizeof(unsigned int),
70564 + .mode = 0600,
70565 + .proc_handler = &proc_dointvec,
70566 + },
70567 +
70568 + { }
70569 +};
70570 +#endif
70571 +
70572 /* The default sysctl tables: */
70573
70574 static struct ctl_table sysctl_base_table[] = {
70575 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
70576 #endif
70577
70578 static struct ctl_table kern_table[] = {
70579 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70580 + {
70581 + .procname = "grsecurity",
70582 + .mode = 0500,
70583 + .child = grsecurity_table,
70584 + },
70585 +#endif
70586 +
70587 +#ifdef CONFIG_PAX_SOFTMODE
70588 + {
70589 + .procname = "pax",
70590 + .mode = 0500,
70591 + .child = pax_table,
70592 + },
70593 +#endif
70594 +
70595 {
70596 .procname = "sched_child_runs_first",
70597 .data = &sysctl_sched_child_runs_first,
70598 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
70599 .data = &modprobe_path,
70600 .maxlen = KMOD_PATH_LEN,
70601 .mode = 0644,
70602 - .proc_handler = proc_dostring,
70603 + .proc_handler = proc_dostring_modpriv,
70604 },
70605 {
70606 .procname = "modules_disabled",
70607 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
70608 .extra1 = &zero,
70609 .extra2 = &one,
70610 },
70611 +#endif
70612 {
70613 .procname = "kptr_restrict",
70614 .data = &kptr_restrict,
70615 .maxlen = sizeof(int),
70616 .mode = 0644,
70617 .proc_handler = proc_dointvec_minmax_sysadmin,
70618 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70619 + .extra1 = &two,
70620 +#else
70621 .extra1 = &zero,
70622 +#endif
70623 .extra2 = &two,
70624 },
70625 -#endif
70626 {
70627 .procname = "ngroups_max",
70628 .data = &ngroups_max,
70629 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
70630 .proc_handler = proc_dointvec_minmax,
70631 .extra1 = &zero,
70632 },
70633 + {
70634 + .procname = "heap_stack_gap",
70635 + .data = &sysctl_heap_stack_gap,
70636 + .maxlen = sizeof(sysctl_heap_stack_gap),
70637 + .mode = 0644,
70638 + .proc_handler = proc_doulongvec_minmax,
70639 + },
70640 #else
70641 {
70642 .procname = "nr_trim_pages",
70643 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
70644 buffer, lenp, ppos);
70645 }
70646
70647 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70648 + void __user *buffer, size_t *lenp, loff_t *ppos)
70649 +{
70650 + if (write && !capable(CAP_SYS_MODULE))
70651 + return -EPERM;
70652 +
70653 + return _proc_do_string(table->data, table->maxlen, write,
70654 + buffer, lenp, ppos);
70655 +}
70656 +
70657 static size_t proc_skip_spaces(char **buf)
70658 {
70659 size_t ret;
70660 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70661 len = strlen(tmp);
70662 if (len > *size)
70663 len = *size;
70664 + if (len > sizeof(tmp))
70665 + len = sizeof(tmp);
70666 if (copy_to_user(*buf, tmp, len))
70667 return -EFAULT;
70668 *size -= len;
70669 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
70670 return err;
70671 }
70672
70673 -#ifdef CONFIG_PRINTK
70674 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70675 void __user *buffer, size_t *lenp, loff_t *ppos)
70676 {
70677 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70678
70679 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70680 }
70681 -#endif
70682
70683 struct do_proc_dointvec_minmax_conv_param {
70684 int *min;
70685 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70686 *i = val;
70687 } else {
70688 val = convdiv * (*i) / convmul;
70689 - if (!first)
70690 + if (!first) {
70691 err = proc_put_char(&buffer, &left, '\t');
70692 + if (err)
70693 + break;
70694 + }
70695 err = proc_put_long(&buffer, &left, val, false);
70696 if (err)
70697 break;
70698 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
70699 return -ENOSYS;
70700 }
70701
70702 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70703 + void __user *buffer, size_t *lenp, loff_t *ppos)
70704 +{
70705 + return -ENOSYS;
70706 +}
70707 +
70708 int proc_dointvec(struct ctl_table *table, int write,
70709 void __user *buffer, size_t *lenp, loff_t *ppos)
70710 {
70711 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70712 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70713 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70714 EXPORT_SYMBOL(proc_dostring);
70715 +EXPORT_SYMBOL(proc_dostring_modpriv);
70716 EXPORT_SYMBOL(proc_doulongvec_minmax);
70717 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70718 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70719 index 65bdcf1..21eb831 100644
70720 --- a/kernel/sysctl_binary.c
70721 +++ b/kernel/sysctl_binary.c
70722 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70723 int i;
70724
70725 set_fs(KERNEL_DS);
70726 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70727 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70728 set_fs(old_fs);
70729 if (result < 0)
70730 goto out_kfree;
70731 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70732 }
70733
70734 set_fs(KERNEL_DS);
70735 - result = vfs_write(file, buffer, str - buffer, &pos);
70736 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70737 set_fs(old_fs);
70738 if (result < 0)
70739 goto out_kfree;
70740 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70741 int i;
70742
70743 set_fs(KERNEL_DS);
70744 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70745 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70746 set_fs(old_fs);
70747 if (result < 0)
70748 goto out_kfree;
70749 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70750 }
70751
70752 set_fs(KERNEL_DS);
70753 - result = vfs_write(file, buffer, str - buffer, &pos);
70754 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70755 set_fs(old_fs);
70756 if (result < 0)
70757 goto out_kfree;
70758 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70759 int i;
70760
70761 set_fs(KERNEL_DS);
70762 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70763 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70764 set_fs(old_fs);
70765 if (result < 0)
70766 goto out;
70767 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70768 __le16 dnaddr;
70769
70770 set_fs(KERNEL_DS);
70771 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70772 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70773 set_fs(old_fs);
70774 if (result < 0)
70775 goto out;
70776 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70777 le16_to_cpu(dnaddr) & 0x3ff);
70778
70779 set_fs(KERNEL_DS);
70780 - result = vfs_write(file, buf, len, &pos);
70781 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70782 set_fs(old_fs);
70783 if (result < 0)
70784 goto out;
70785 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70786 index 145bb4d..b2aa969 100644
70787 --- a/kernel/taskstats.c
70788 +++ b/kernel/taskstats.c
70789 @@ -28,9 +28,12 @@
70790 #include <linux/fs.h>
70791 #include <linux/file.h>
70792 #include <linux/pid_namespace.h>
70793 +#include <linux/grsecurity.h>
70794 #include <net/genetlink.h>
70795 #include <linux/atomic.h>
70796
70797 +extern int gr_is_taskstats_denied(int pid);
70798 +
70799 /*
70800 * Maximum length of a cpumask that can be specified in
70801 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70802 @@ -570,6 +573,9 @@ err:
70803
70804 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70805 {
70806 + if (gr_is_taskstats_denied(current->pid))
70807 + return -EACCES;
70808 +
70809 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70810 return cmd_attr_register_cpumask(info);
70811 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70812 diff --git a/kernel/time.c b/kernel/time.c
70813 index d226c6a..c7c0960 100644
70814 --- a/kernel/time.c
70815 +++ b/kernel/time.c
70816 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70817 return error;
70818
70819 if (tz) {
70820 + /* we log in do_settimeofday called below, so don't log twice
70821 + */
70822 + if (!tv)
70823 + gr_log_timechange();
70824 +
70825 sys_tz = *tz;
70826 update_vsyscall_tz();
70827 if (firsttime) {
70828 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70829 index f11d83b..d016d91 100644
70830 --- a/kernel/time/alarmtimer.c
70831 +++ b/kernel/time/alarmtimer.c
70832 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
70833 struct platform_device *pdev;
70834 int error = 0;
70835 int i;
70836 - struct k_clock alarm_clock = {
70837 + static struct k_clock alarm_clock = {
70838 .clock_getres = alarm_clock_getres,
70839 .clock_get = alarm_clock_get,
70840 .timer_create = alarm_timer_create,
70841 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70842 index f113755..ec24223 100644
70843 --- a/kernel/time/tick-broadcast.c
70844 +++ b/kernel/time/tick-broadcast.c
70845 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70846 * then clear the broadcast bit.
70847 */
70848 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70849 - int cpu = smp_processor_id();
70850 + cpu = smp_processor_id();
70851
70852 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70853 tick_broadcast_clear_oneshot(cpu);
70854 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70855 index e424970..4c7962b 100644
70856 --- a/kernel/time/timekeeping.c
70857 +++ b/kernel/time/timekeeping.c
70858 @@ -15,6 +15,7 @@
70859 #include <linux/init.h>
70860 #include <linux/mm.h>
70861 #include <linux/sched.h>
70862 +#include <linux/grsecurity.h>
70863 #include <linux/syscore_ops.h>
70864 #include <linux/clocksource.h>
70865 #include <linux/jiffies.h>
70866 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
70867 if (!timespec_valid_strict(tv))
70868 return -EINVAL;
70869
70870 + gr_log_timechange();
70871 +
70872 write_seqlock_irqsave(&tk->lock, flags);
70873
70874 timekeeping_forward_now(tk);
70875 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70876 index af5a7e9..715611a 100644
70877 --- a/kernel/time/timer_list.c
70878 +++ b/kernel/time/timer_list.c
70879 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70880
70881 static void print_name_offset(struct seq_file *m, void *sym)
70882 {
70883 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70884 + SEQ_printf(m, "<%p>", NULL);
70885 +#else
70886 char symname[KSYM_NAME_LEN];
70887
70888 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70889 SEQ_printf(m, "<%pK>", sym);
70890 else
70891 SEQ_printf(m, "%s", symname);
70892 +#endif
70893 }
70894
70895 static void
70896 @@ -112,7 +116,11 @@ next_one:
70897 static void
70898 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70899 {
70900 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70901 + SEQ_printf(m, " .base: %p\n", NULL);
70902 +#else
70903 SEQ_printf(m, " .base: %pK\n", base);
70904 +#endif
70905 SEQ_printf(m, " .index: %d\n",
70906 base->index);
70907 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70908 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70909 {
70910 struct proc_dir_entry *pe;
70911
70912 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70913 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70914 +#else
70915 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70916 +#endif
70917 if (!pe)
70918 return -ENOMEM;
70919 return 0;
70920 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70921 index 0b537f2..40d6c20 100644
70922 --- a/kernel/time/timer_stats.c
70923 +++ b/kernel/time/timer_stats.c
70924 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70925 static unsigned long nr_entries;
70926 static struct entry entries[MAX_ENTRIES];
70927
70928 -static atomic_t overflow_count;
70929 +static atomic_unchecked_t overflow_count;
70930
70931 /*
70932 * The entries are in a hash-table, for fast lookup:
70933 @@ -140,7 +140,7 @@ static void reset_entries(void)
70934 nr_entries = 0;
70935 memset(entries, 0, sizeof(entries));
70936 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70937 - atomic_set(&overflow_count, 0);
70938 + atomic_set_unchecked(&overflow_count, 0);
70939 }
70940
70941 static struct entry *alloc_entry(void)
70942 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70943 if (likely(entry))
70944 entry->count++;
70945 else
70946 - atomic_inc(&overflow_count);
70947 + atomic_inc_unchecked(&overflow_count);
70948
70949 out_unlock:
70950 raw_spin_unlock_irqrestore(lock, flags);
70951 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70952
70953 static void print_name_offset(struct seq_file *m, unsigned long addr)
70954 {
70955 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70956 + seq_printf(m, "<%p>", NULL);
70957 +#else
70958 char symname[KSYM_NAME_LEN];
70959
70960 if (lookup_symbol_name(addr, symname) < 0)
70961 - seq_printf(m, "<%p>", (void *)addr);
70962 + seq_printf(m, "<%pK>", (void *)addr);
70963 else
70964 seq_printf(m, "%s", symname);
70965 +#endif
70966 }
70967
70968 static int tstats_show(struct seq_file *m, void *v)
70969 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70970
70971 seq_puts(m, "Timer Stats Version: v0.2\n");
70972 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70973 - if (atomic_read(&overflow_count))
70974 + if (atomic_read_unchecked(&overflow_count))
70975 seq_printf(m, "Overflow: %d entries\n",
70976 - atomic_read(&overflow_count));
70977 + atomic_read_unchecked(&overflow_count));
70978
70979 for (i = 0; i < nr_entries; i++) {
70980 entry = entries + i;
70981 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70982 {
70983 struct proc_dir_entry *pe;
70984
70985 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70986 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70987 +#else
70988 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70989 +#endif
70990 if (!pe)
70991 return -ENOMEM;
70992 return 0;
70993 diff --git a/kernel/timer.c b/kernel/timer.c
70994 index 367d008..6e2ac71 100644
70995 --- a/kernel/timer.c
70996 +++ b/kernel/timer.c
70997 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
70998 /*
70999 * This function runs timers and the timer-tq in bottom half context.
71000 */
71001 -static void run_timer_softirq(struct softirq_action *h)
71002 +static void run_timer_softirq(void)
71003 {
71004 struct tvec_base *base = __this_cpu_read(tvec_bases);
71005
71006 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71007 index c0bd030..62a1927 100644
71008 --- a/kernel/trace/blktrace.c
71009 +++ b/kernel/trace/blktrace.c
71010 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71011 struct blk_trace *bt = filp->private_data;
71012 char buf[16];
71013
71014 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71015 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71016
71017 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71018 }
71019 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71020 return 1;
71021
71022 bt = buf->chan->private_data;
71023 - atomic_inc(&bt->dropped);
71024 + atomic_inc_unchecked(&bt->dropped);
71025 return 0;
71026 }
71027
71028 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71029
71030 bt->dir = dir;
71031 bt->dev = dev;
71032 - atomic_set(&bt->dropped, 0);
71033 + atomic_set_unchecked(&bt->dropped, 0);
71034
71035 ret = -EIO;
71036 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71037 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71038 index 51b7159..7f83cf8 100644
71039 --- a/kernel/trace/ftrace.c
71040 +++ b/kernel/trace/ftrace.c
71041 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71042 if (unlikely(ftrace_disabled))
71043 return 0;
71044
71045 + ret = ftrace_arch_code_modify_prepare();
71046 + FTRACE_WARN_ON(ret);
71047 + if (ret)
71048 + return 0;
71049 +
71050 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71051 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71052 if (ret) {
71053 ftrace_bug(ret, ip);
71054 - return 0;
71055 }
71056 - return 1;
71057 + return ret ? 0 : 1;
71058 }
71059
71060 /*
71061 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71062
71063 int
71064 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71065 - void *data)
71066 + void *data)
71067 {
71068 struct ftrace_func_probe *entry;
71069 struct ftrace_page *pg;
71070 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
71071 if (!count)
71072 return 0;
71073
71074 + pax_open_kernel();
71075 sort(start, count, sizeof(*start),
71076 ftrace_cmp_ips, ftrace_swap_ips);
71077 + pax_close_kernel();
71078
71079 start_pg = ftrace_allocate_pages(count);
71080 if (!start_pg)
71081 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
71082 index 4cb5e51..e7e05d9 100644
71083 --- a/kernel/trace/ring_buffer.c
71084 +++ b/kernel/trace/ring_buffer.c
71085 @@ -346,9 +346,9 @@ struct buffer_data_page {
71086 */
71087 struct buffer_page {
71088 struct list_head list; /* list of buffer pages */
71089 - local_t write; /* index for next write */
71090 + local_unchecked_t write; /* index for next write */
71091 unsigned read; /* index for next read */
71092 - local_t entries; /* entries on this page */
71093 + local_unchecked_t entries; /* entries on this page */
71094 unsigned long real_end; /* real end of data */
71095 struct buffer_data_page *page; /* Actual data page */
71096 };
71097 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
71098 unsigned long lost_events;
71099 unsigned long last_overrun;
71100 local_t entries_bytes;
71101 - local_t commit_overrun;
71102 - local_t overrun;
71103 + local_unchecked_t commit_overrun;
71104 + local_unchecked_t overrun;
71105 local_t entries;
71106 local_t committing;
71107 local_t commits;
71108 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
71109 *
71110 * We add a counter to the write field to denote this.
71111 */
71112 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
71113 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
71114 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
71115 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
71116
71117 /*
71118 * Just make sure we have seen our old_write and synchronize
71119 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
71120 * cmpxchg to only update if an interrupt did not already
71121 * do it for us. If the cmpxchg fails, we don't care.
71122 */
71123 - (void)local_cmpxchg(&next_page->write, old_write, val);
71124 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
71125 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
71126 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
71127
71128 /*
71129 * No need to worry about races with clearing out the commit.
71130 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
71131
71132 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
71133 {
71134 - return local_read(&bpage->entries) & RB_WRITE_MASK;
71135 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
71136 }
71137
71138 static inline unsigned long rb_page_write(struct buffer_page *bpage)
71139 {
71140 - return local_read(&bpage->write) & RB_WRITE_MASK;
71141 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
71142 }
71143
71144 static int
71145 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
71146 * bytes consumed in ring buffer from here.
71147 * Increment overrun to account for the lost events.
71148 */
71149 - local_add(page_entries, &cpu_buffer->overrun);
71150 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
71151 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
71152 }
71153
71154 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
71155 * it is our responsibility to update
71156 * the counters.
71157 */
71158 - local_add(entries, &cpu_buffer->overrun);
71159 + local_add_unchecked(entries, &cpu_buffer->overrun);
71160 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
71161
71162 /*
71163 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71164 if (tail == BUF_PAGE_SIZE)
71165 tail_page->real_end = 0;
71166
71167 - local_sub(length, &tail_page->write);
71168 + local_sub_unchecked(length, &tail_page->write);
71169 return;
71170 }
71171
71172 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71173 rb_event_set_padding(event);
71174
71175 /* Set the write back to the previous setting */
71176 - local_sub(length, &tail_page->write);
71177 + local_sub_unchecked(length, &tail_page->write);
71178 return;
71179 }
71180
71181 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71182
71183 /* Set write to end of buffer */
71184 length = (tail + length) - BUF_PAGE_SIZE;
71185 - local_sub(length, &tail_page->write);
71186 + local_sub_unchecked(length, &tail_page->write);
71187 }
71188
71189 /*
71190 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
71191 * about it.
71192 */
71193 if (unlikely(next_page == commit_page)) {
71194 - local_inc(&cpu_buffer->commit_overrun);
71195 + local_inc_unchecked(&cpu_buffer->commit_overrun);
71196 goto out_reset;
71197 }
71198
71199 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
71200 cpu_buffer->tail_page) &&
71201 (cpu_buffer->commit_page ==
71202 cpu_buffer->reader_page))) {
71203 - local_inc(&cpu_buffer->commit_overrun);
71204 + local_inc_unchecked(&cpu_buffer->commit_overrun);
71205 goto out_reset;
71206 }
71207 }
71208 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
71209 length += RB_LEN_TIME_EXTEND;
71210
71211 tail_page = cpu_buffer->tail_page;
71212 - write = local_add_return(length, &tail_page->write);
71213 + write = local_add_return_unchecked(length, &tail_page->write);
71214
71215 /* set write to only the index of the write */
71216 write &= RB_WRITE_MASK;
71217 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
71218 kmemcheck_annotate_bitfield(event, bitfield);
71219 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
71220
71221 - local_inc(&tail_page->entries);
71222 + local_inc_unchecked(&tail_page->entries);
71223
71224 /*
71225 * If this is the first commit on the page, then update
71226 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
71227
71228 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
71229 unsigned long write_mask =
71230 - local_read(&bpage->write) & ~RB_WRITE_MASK;
71231 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
71232 unsigned long event_length = rb_event_length(event);
71233 /*
71234 * This is on the tail page. It is possible that
71235 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
71236 */
71237 old_index += write_mask;
71238 new_index += write_mask;
71239 - index = local_cmpxchg(&bpage->write, old_index, new_index);
71240 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
71241 if (index == old_index) {
71242 /* update counters */
71243 local_sub(event_length, &cpu_buffer->entries_bytes);
71244 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
71245
71246 /* Do the likely case first */
71247 if (likely(bpage->page == (void *)addr)) {
71248 - local_dec(&bpage->entries);
71249 + local_dec_unchecked(&bpage->entries);
71250 return;
71251 }
71252
71253 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
71254 start = bpage;
71255 do {
71256 if (bpage->page == (void *)addr) {
71257 - local_dec(&bpage->entries);
71258 + local_dec_unchecked(&bpage->entries);
71259 return;
71260 }
71261 rb_inc_page(cpu_buffer, &bpage);
71262 @@ -2923,7 +2923,7 @@ static inline unsigned long
71263 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
71264 {
71265 return local_read(&cpu_buffer->entries) -
71266 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
71267 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
71268 }
71269
71270 /**
71271 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
71272 return 0;
71273
71274 cpu_buffer = buffer->buffers[cpu];
71275 - ret = local_read(&cpu_buffer->overrun);
71276 + ret = local_read_unchecked(&cpu_buffer->overrun);
71277
71278 return ret;
71279 }
71280 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
71281 return 0;
71282
71283 cpu_buffer = buffer->buffers[cpu];
71284 - ret = local_read(&cpu_buffer->commit_overrun);
71285 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
71286
71287 return ret;
71288 }
71289 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
71290 /* if you care about this being correct, lock the buffer */
71291 for_each_buffer_cpu(buffer, cpu) {
71292 cpu_buffer = buffer->buffers[cpu];
71293 - overruns += local_read(&cpu_buffer->overrun);
71294 + overruns += local_read_unchecked(&cpu_buffer->overrun);
71295 }
71296
71297 return overruns;
71298 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
71299 /*
71300 * Reset the reader page to size zero.
71301 */
71302 - local_set(&cpu_buffer->reader_page->write, 0);
71303 - local_set(&cpu_buffer->reader_page->entries, 0);
71304 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
71305 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
71306 local_set(&cpu_buffer->reader_page->page->commit, 0);
71307 cpu_buffer->reader_page->real_end = 0;
71308
71309 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
71310 * want to compare with the last_overrun.
71311 */
71312 smp_mb();
71313 - overwrite = local_read(&(cpu_buffer->overrun));
71314 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
71315
71316 /*
71317 * Here's the tricky part.
71318 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
71319
71320 cpu_buffer->head_page
71321 = list_entry(cpu_buffer->pages, struct buffer_page, list);
71322 - local_set(&cpu_buffer->head_page->write, 0);
71323 - local_set(&cpu_buffer->head_page->entries, 0);
71324 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
71325 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
71326 local_set(&cpu_buffer->head_page->page->commit, 0);
71327
71328 cpu_buffer->head_page->read = 0;
71329 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
71330
71331 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
71332 INIT_LIST_HEAD(&cpu_buffer->new_pages);
71333 - local_set(&cpu_buffer->reader_page->write, 0);
71334 - local_set(&cpu_buffer->reader_page->entries, 0);
71335 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
71336 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
71337 local_set(&cpu_buffer->reader_page->page->commit, 0);
71338 cpu_buffer->reader_page->read = 0;
71339
71340 - local_set(&cpu_buffer->commit_overrun, 0);
71341 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
71342 local_set(&cpu_buffer->entries_bytes, 0);
71343 - local_set(&cpu_buffer->overrun, 0);
71344 + local_set_unchecked(&cpu_buffer->overrun, 0);
71345 local_set(&cpu_buffer->entries, 0);
71346 local_set(&cpu_buffer->committing, 0);
71347 local_set(&cpu_buffer->commits, 0);
71348 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
71349 rb_init_page(bpage);
71350 bpage = reader->page;
71351 reader->page = *data_page;
71352 - local_set(&reader->write, 0);
71353 - local_set(&reader->entries, 0);
71354 + local_set_unchecked(&reader->write, 0);
71355 + local_set_unchecked(&reader->entries, 0);
71356 reader->read = 0;
71357 *data_page = bpage;
71358
71359 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71360 index 31e4f55..62da00f 100644
71361 --- a/kernel/trace/trace.c
71362 +++ b/kernel/trace/trace.c
71363 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71364 };
71365 #endif
71366
71367 -static struct dentry *d_tracer;
71368 -
71369 struct dentry *tracing_init_dentry(void)
71370 {
71371 + static struct dentry *d_tracer;
71372 static int once;
71373
71374 if (d_tracer)
71375 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
71376 return d_tracer;
71377 }
71378
71379 -static struct dentry *d_percpu;
71380 -
71381 struct dentry *tracing_dentry_percpu(void)
71382 {
71383 + static struct dentry *d_percpu;
71384 static int once;
71385 struct dentry *d_tracer;
71386
71387 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71388 index d608d09..7eddcb1 100644
71389 --- a/kernel/trace/trace_events.c
71390 +++ b/kernel/trace/trace_events.c
71391 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
71392 struct ftrace_module_file_ops {
71393 struct list_head list;
71394 struct module *mod;
71395 - struct file_operations id;
71396 - struct file_operations enable;
71397 - struct file_operations format;
71398 - struct file_operations filter;
71399 };
71400
71401 static struct ftrace_module_file_ops *
71402 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
71403
71404 file_ops->mod = mod;
71405
71406 - file_ops->id = ftrace_event_id_fops;
71407 - file_ops->id.owner = mod;
71408 -
71409 - file_ops->enable = ftrace_enable_fops;
71410 - file_ops->enable.owner = mod;
71411 -
71412 - file_ops->filter = ftrace_event_filter_fops;
71413 - file_ops->filter.owner = mod;
71414 -
71415 - file_ops->format = ftrace_event_format_fops;
71416 - file_ops->format.owner = mod;
71417 + pax_open_kernel();
71418 + *(void **)&mod->trace_id.owner = mod;
71419 + *(void **)&mod->trace_enable.owner = mod;
71420 + *(void **)&mod->trace_filter.owner = mod;
71421 + *(void **)&mod->trace_format.owner = mod;
71422 + pax_close_kernel();
71423
71424 list_add(&file_ops->list, &ftrace_module_file_list);
71425
71426 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
71427
71428 for_each_event(call, start, end) {
71429 __trace_add_event_call(*call, mod,
71430 - &file_ops->id, &file_ops->enable,
71431 - &file_ops->filter, &file_ops->format);
71432 + &mod->trace_id, &mod->trace_enable,
71433 + &mod->trace_filter, &mod->trace_format);
71434 }
71435 }
71436
71437 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71438 index fd3c8aa..5f324a6 100644
71439 --- a/kernel/trace/trace_mmiotrace.c
71440 +++ b/kernel/trace/trace_mmiotrace.c
71441 @@ -24,7 +24,7 @@ struct header_iter {
71442 static struct trace_array *mmio_trace_array;
71443 static bool overrun_detected;
71444 static unsigned long prev_overruns;
71445 -static atomic_t dropped_count;
71446 +static atomic_unchecked_t dropped_count;
71447
71448 static void mmio_reset_data(struct trace_array *tr)
71449 {
71450 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71451
71452 static unsigned long count_overruns(struct trace_iterator *iter)
71453 {
71454 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71455 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71456 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71457
71458 if (over > prev_overruns)
71459 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71460 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71461 sizeof(*entry), 0, pc);
71462 if (!event) {
71463 - atomic_inc(&dropped_count);
71464 + atomic_inc_unchecked(&dropped_count);
71465 return;
71466 }
71467 entry = ring_buffer_event_data(event);
71468 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71469 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71470 sizeof(*entry), 0, pc);
71471 if (!event) {
71472 - atomic_inc(&dropped_count);
71473 + atomic_inc_unchecked(&dropped_count);
71474 return;
71475 }
71476 entry = ring_buffer_event_data(event);
71477 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71478 index 123b189..97b81f5 100644
71479 --- a/kernel/trace/trace_output.c
71480 +++ b/kernel/trace/trace_output.c
71481 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71482
71483 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71484 if (!IS_ERR(p)) {
71485 - p = mangle_path(s->buffer + s->len, p, "\n");
71486 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71487 if (p) {
71488 s->len = p - s->buffer;
71489 return 1;
71490 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71491 index 0c1b1657..95337e9 100644
71492 --- a/kernel/trace/trace_stack.c
71493 +++ b/kernel/trace/trace_stack.c
71494 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71495 return;
71496
71497 /* we do not handle interrupt stacks yet */
71498 - if (!object_is_on_stack(&this_size))
71499 + if (!object_starts_on_stack(&this_size))
71500 return;
71501
71502 local_irq_save(flags);
71503 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71504 index 28e9d6c9..50381bd 100644
71505 --- a/lib/Kconfig.debug
71506 +++ b/lib/Kconfig.debug
71507 @@ -1278,6 +1278,7 @@ config LATENCYTOP
71508 depends on DEBUG_KERNEL
71509 depends on STACKTRACE_SUPPORT
71510 depends on PROC_FS
71511 + depends on !GRKERNSEC_HIDESYM
71512 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71513 select KALLSYMS
71514 select KALLSYMS_ALL
71515 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
71516
71517 config PROVIDE_OHCI1394_DMA_INIT
71518 bool "Remote debugging over FireWire early on boot"
71519 - depends on PCI && X86
71520 + depends on PCI && X86 && !GRKERNSEC
71521 help
71522 If you want to debug problems which hang or crash the kernel early
71523 on boot and the crashing machine has a FireWire port, you can use
71524 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71525
71526 config FIREWIRE_OHCI_REMOTE_DMA
71527 bool "Remote debugging over FireWire with firewire-ohci"
71528 - depends on FIREWIRE_OHCI
71529 + depends on FIREWIRE_OHCI && !GRKERNSEC
71530 help
71531 This option lets you use the FireWire bus for remote debugging
71532 with help of the firewire-ohci driver. It enables unfiltered
71533 diff --git a/lib/bitmap.c b/lib/bitmap.c
71534 index 06fdfa1..97c5c7d 100644
71535 --- a/lib/bitmap.c
71536 +++ b/lib/bitmap.c
71537 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71538 {
71539 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71540 u32 chunk;
71541 - const char __user __force *ubuf = (const char __user __force *)buf;
71542 + const char __user *ubuf = (const char __force_user *)buf;
71543
71544 bitmap_zero(maskp, nmaskbits);
71545
71546 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71547 {
71548 if (!access_ok(VERIFY_READ, ubuf, ulen))
71549 return -EFAULT;
71550 - return __bitmap_parse((const char __force *)ubuf,
71551 + return __bitmap_parse((const char __force_kernel *)ubuf,
71552 ulen, 1, maskp, nmaskbits);
71553
71554 }
71555 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71556 {
71557 unsigned a, b;
71558 int c, old_c, totaldigits;
71559 - const char __user __force *ubuf = (const char __user __force *)buf;
71560 + const char __user *ubuf = (const char __force_user *)buf;
71561 int exp_digit, in_range;
71562
71563 totaldigits = c = 0;
71564 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71565 {
71566 if (!access_ok(VERIFY_READ, ubuf, ulen))
71567 return -EFAULT;
71568 - return __bitmap_parselist((const char __force *)ubuf,
71569 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71570 ulen, 1, maskp, nmaskbits);
71571 }
71572 EXPORT_SYMBOL(bitmap_parselist_user);
71573 diff --git a/lib/bug.c b/lib/bug.c
71574 index a28c141..2bd3d95 100644
71575 --- a/lib/bug.c
71576 +++ b/lib/bug.c
71577 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71578 return BUG_TRAP_TYPE_NONE;
71579
71580 bug = find_bug(bugaddr);
71581 + if (!bug)
71582 + return BUG_TRAP_TYPE_NONE;
71583
71584 file = NULL;
71585 line = 0;
71586 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71587 index d11808c..dc2d6f8 100644
71588 --- a/lib/debugobjects.c
71589 +++ b/lib/debugobjects.c
71590 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71591 if (limit > 4)
71592 return;
71593
71594 - is_on_stack = object_is_on_stack(addr);
71595 + is_on_stack = object_starts_on_stack(addr);
71596 if (is_on_stack == onstack)
71597 return;
71598
71599 diff --git a/lib/devres.c b/lib/devres.c
71600 index 80b9c76..9e32279 100644
71601 --- a/lib/devres.c
71602 +++ b/lib/devres.c
71603 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71604 void devm_iounmap(struct device *dev, void __iomem *addr)
71605 {
71606 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71607 - (void *)addr));
71608 + (void __force *)addr));
71609 iounmap(addr);
71610 }
71611 EXPORT_SYMBOL(devm_iounmap);
71612 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71613 {
71614 ioport_unmap(addr);
71615 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71616 - devm_ioport_map_match, (void *)addr));
71617 + devm_ioport_map_match, (void __force *)addr));
71618 }
71619 EXPORT_SYMBOL(devm_ioport_unmap);
71620
71621 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71622 index d84beb9..10a4749 100644
71623 --- a/lib/dma-debug.c
71624 +++ b/lib/dma-debug.c
71625 @@ -919,7 +919,7 @@ out:
71626
71627 static void check_for_stack(struct device *dev, void *addr)
71628 {
71629 - if (object_is_on_stack(addr))
71630 + if (object_starts_on_stack(addr))
71631 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71632 "stack [addr=%p]\n", addr);
71633 }
71634 diff --git a/lib/inflate.c b/lib/inflate.c
71635 index 013a761..c28f3fc 100644
71636 --- a/lib/inflate.c
71637 +++ b/lib/inflate.c
71638 @@ -269,7 +269,7 @@ static void free(void *where)
71639 malloc_ptr = free_mem_ptr;
71640 }
71641 #else
71642 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71643 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71644 #define free(a) kfree(a)
71645 #endif
71646
71647 diff --git a/lib/ioremap.c b/lib/ioremap.c
71648 index 0c9216c..863bd89 100644
71649 --- a/lib/ioremap.c
71650 +++ b/lib/ioremap.c
71651 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71652 unsigned long next;
71653
71654 phys_addr -= addr;
71655 - pmd = pmd_alloc(&init_mm, pud, addr);
71656 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71657 if (!pmd)
71658 return -ENOMEM;
71659 do {
71660 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71661 unsigned long next;
71662
71663 phys_addr -= addr;
71664 - pud = pud_alloc(&init_mm, pgd, addr);
71665 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71666 if (!pud)
71667 return -ENOMEM;
71668 do {
71669 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71670 index bd2bea9..6b3c95e 100644
71671 --- a/lib/is_single_threaded.c
71672 +++ b/lib/is_single_threaded.c
71673 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71674 struct task_struct *p, *t;
71675 bool ret;
71676
71677 + if (!mm)
71678 + return true;
71679 +
71680 if (atomic_read(&task->signal->live) != 1)
71681 return false;
71682
71683 diff --git a/lib/list_debug.c b/lib/list_debug.c
71684 index c24c2f7..bef49ee 100644
71685 --- a/lib/list_debug.c
71686 +++ b/lib/list_debug.c
71687 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71688 struct list_head *prev,
71689 struct list_head *next)
71690 {
71691 - WARN(next->prev != prev,
71692 + if (WARN(next->prev != prev,
71693 "list_add corruption. next->prev should be "
71694 "prev (%p), but was %p. (next=%p).\n",
71695 - prev, next->prev, next);
71696 - WARN(prev->next != next,
71697 + prev, next->prev, next) ||
71698 + WARN(prev->next != next,
71699 "list_add corruption. prev->next should be "
71700 "next (%p), but was %p. (prev=%p).\n",
71701 - next, prev->next, prev);
71702 - WARN(new == prev || new == next,
71703 + next, prev->next, prev) ||
71704 + WARN(new == prev || new == next,
71705 "list_add double add: new=%p, prev=%p, next=%p.\n",
71706 - new, prev, next);
71707 + new, prev, next))
71708 + return;
71709 +
71710 next->prev = new;
71711 new->next = next;
71712 new->prev = prev;
71713 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71714 void __list_add_rcu(struct list_head *new,
71715 struct list_head *prev, struct list_head *next)
71716 {
71717 - WARN(next->prev != prev,
71718 + if (WARN(next->prev != prev,
71719 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71720 - prev, next->prev, next);
71721 - WARN(prev->next != next,
71722 + prev, next->prev, next) ||
71723 + WARN(prev->next != next,
71724 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71725 - next, prev->next, prev);
71726 + next, prev->next, prev))
71727 + return;
71728 +
71729 new->next = next;
71730 new->prev = prev;
71731 rcu_assign_pointer(list_next_rcu(prev), new);
71732 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71733 index e796429..6e38f9f 100644
71734 --- a/lib/radix-tree.c
71735 +++ b/lib/radix-tree.c
71736 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71737 int nr;
71738 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71739 };
71740 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71741 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71742
71743 static inline void *ptr_to_indirect(void *ptr)
71744 {
71745 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71746 index bb2b201..46abaf9 100644
71747 --- a/lib/strncpy_from_user.c
71748 +++ b/lib/strncpy_from_user.c
71749 @@ -21,7 +21,7 @@
71750 */
71751 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71752 {
71753 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71754 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71755 long res = 0;
71756
71757 /*
71758 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71759 index a28df52..3d55877 100644
71760 --- a/lib/strnlen_user.c
71761 +++ b/lib/strnlen_user.c
71762 @@ -26,7 +26,7 @@
71763 */
71764 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71765 {
71766 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71767 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71768 long align, res = 0;
71769 unsigned long c;
71770
71771 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71772 index 39c99fe..ba3f00d 100644
71773 --- a/lib/vsprintf.c
71774 +++ b/lib/vsprintf.c
71775 @@ -16,6 +16,9 @@
71776 * - scnprintf and vscnprintf
71777 */
71778
71779 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71780 +#define __INCLUDED_BY_HIDESYM 1
71781 +#endif
71782 #include <stdarg.h>
71783 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71784 #include <linux/types.h>
71785 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71786 char sym[KSYM_SYMBOL_LEN];
71787 if (ext == 'B')
71788 sprint_backtrace(sym, value);
71789 - else if (ext != 'f' && ext != 's')
71790 + else if (ext != 'f' && ext != 's' && ext != 'a')
71791 sprint_symbol(sym, value);
71792 else
71793 sprint_symbol_no_offset(sym, value);
71794 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71795 return number(buf, end, *(const netdev_features_t *)addr, spec);
71796 }
71797
71798 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71799 +int kptr_restrict __read_mostly = 2;
71800 +#else
71801 int kptr_restrict __read_mostly;
71802 +#endif
71803
71804 /*
71805 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71806 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
71807 * - 'S' For symbolic direct pointers with offset
71808 * - 's' For symbolic direct pointers without offset
71809 * - 'B' For backtraced symbolic direct pointers with offset
71810 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71811 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71812 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71813 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71814 * - 'M' For a 6-byte MAC address, it prints the address in the
71815 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71816
71817 if (!ptr && *fmt != 'K') {
71818 /*
71819 - * Print (null) with the same width as a pointer so it makes
71820 + * Print (nil) with the same width as a pointer so it makes
71821 * tabular output look nice.
71822 */
71823 if (spec.field_width == -1)
71824 spec.field_width = default_width;
71825 - return string(buf, end, "(null)", spec);
71826 + return string(buf, end, "(nil)", spec);
71827 }
71828
71829 switch (*fmt) {
71830 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71831 /* Fallthrough */
71832 case 'S':
71833 case 's':
71834 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71835 + break;
71836 +#else
71837 + return symbol_string(buf, end, ptr, spec, *fmt);
71838 +#endif
71839 + case 'A':
71840 + case 'a':
71841 case 'B':
71842 return symbol_string(buf, end, ptr, spec, *fmt);
71843 case 'R':
71844 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71845 va_end(va);
71846 return buf;
71847 }
71848 + case 'P':
71849 + break;
71850 case 'K':
71851 /*
71852 * %pK cannot be used in IRQ context because its test
71853 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71854 }
71855 break;
71856 }
71857 +
71858 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71859 + /* 'P' = approved pointers to copy to userland,
71860 + as in the /proc/kallsyms case, as we make it display nothing
71861 + for non-root users, and the real contents for root users
71862 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71863 + above
71864 + */
71865 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71866 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71867 + dump_stack();
71868 + ptr = NULL;
71869 + }
71870 +#endif
71871 +
71872 spec.flags |= SMALL;
71873 if (spec.field_width == -1) {
71874 spec.field_width = default_width;
71875 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71876 typeof(type) value; \
71877 if (sizeof(type) == 8) { \
71878 args = PTR_ALIGN(args, sizeof(u32)); \
71879 - *(u32 *)&value = *(u32 *)args; \
71880 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71881 + *(u32 *)&value = *(const u32 *)args; \
71882 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71883 } else { \
71884 args = PTR_ALIGN(args, sizeof(type)); \
71885 - value = *(typeof(type) *)args; \
71886 + value = *(const typeof(type) *)args; \
71887 } \
71888 args += sizeof(type); \
71889 value; \
71890 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71891 case FORMAT_TYPE_STR: {
71892 const char *str_arg = args;
71893 args += strlen(str_arg) + 1;
71894 - str = string(str, end, (char *)str_arg, spec);
71895 + str = string(str, end, str_arg, spec);
71896 break;
71897 }
71898
71899 diff --git a/localversion-grsec b/localversion-grsec
71900 new file mode 100644
71901 index 0000000..7cd6065
71902 --- /dev/null
71903 +++ b/localversion-grsec
71904 @@ -0,0 +1 @@
71905 +-grsec
71906 diff --git a/mm/Kconfig b/mm/Kconfig
71907 index a3f8ddd..f31e92e 100644
71908 --- a/mm/Kconfig
71909 +++ b/mm/Kconfig
71910 @@ -252,10 +252,10 @@ config KSM
71911 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71912
71913 config DEFAULT_MMAP_MIN_ADDR
71914 - int "Low address space to protect from user allocation"
71915 + int "Low address space to protect from user allocation"
71916 depends on MMU
71917 - default 4096
71918 - help
71919 + default 65536
71920 + help
71921 This is the portion of low virtual memory which should be protected
71922 from userspace allocation. Keeping a user from writing to low pages
71923 can help reduce the impact of kernel NULL pointer bugs.
71924 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
71925
71926 config HWPOISON_INJECT
71927 tristate "HWPoison pages injector"
71928 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71929 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71930 select PROC_PAGE_MONITOR
71931
71932 config NOMMU_INITIAL_TRIM_EXCESS
71933 diff --git a/mm/filemap.c b/mm/filemap.c
71934 index 83efee7..3f99381 100644
71935 --- a/mm/filemap.c
71936 +++ b/mm/filemap.c
71937 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71938 struct address_space *mapping = file->f_mapping;
71939
71940 if (!mapping->a_ops->readpage)
71941 - return -ENOEXEC;
71942 + return -ENODEV;
71943 file_accessed(file);
71944 vma->vm_ops = &generic_file_vm_ops;
71945 return 0;
71946 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71947 *pos = i_size_read(inode);
71948
71949 if (limit != RLIM_INFINITY) {
71950 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71951 if (*pos >= limit) {
71952 send_sig(SIGXFSZ, current, 0);
71953 return -EFBIG;
71954 diff --git a/mm/fremap.c b/mm/fremap.c
71955 index a0aaf0e..20325c3 100644
71956 --- a/mm/fremap.c
71957 +++ b/mm/fremap.c
71958 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71959 retry:
71960 vma = find_vma(mm, start);
71961
71962 +#ifdef CONFIG_PAX_SEGMEXEC
71963 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71964 + goto out;
71965 +#endif
71966 +
71967 /*
71968 * Make sure the vma is shared, that it supports prefaulting,
71969 * and that the remapped range is valid and fully within
71970 diff --git a/mm/highmem.c b/mm/highmem.c
71971 index 2da13a5..9568fec 100644
71972 --- a/mm/highmem.c
71973 +++ b/mm/highmem.c
71974 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71975 * So no dangers, even with speculative execution.
71976 */
71977 page = pte_page(pkmap_page_table[i]);
71978 + pax_open_kernel();
71979 pte_clear(&init_mm, (unsigned long)page_address(page),
71980 &pkmap_page_table[i]);
71981 -
71982 + pax_close_kernel();
71983 set_page_address(page, NULL);
71984 need_flush = 1;
71985 }
71986 @@ -198,9 +199,11 @@ start:
71987 }
71988 }
71989 vaddr = PKMAP_ADDR(last_pkmap_nr);
71990 +
71991 + pax_open_kernel();
71992 set_pte_at(&init_mm, vaddr,
71993 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71994 -
71995 + pax_close_kernel();
71996 pkmap_count[last_pkmap_nr] = 1;
71997 set_page_address(page, (void *)vaddr);
71998
71999 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72000 index 40f17c3..c1cc011 100644
72001 --- a/mm/huge_memory.c
72002 +++ b/mm/huge_memory.c
72003 @@ -710,7 +710,7 @@ out:
72004 * run pte_offset_map on the pmd, if an huge pmd could
72005 * materialize from under us from a different thread.
72006 */
72007 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72008 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72009 return VM_FAULT_OOM;
72010 /* if an huge pmd materialized from under us just retry later */
72011 if (unlikely(pmd_trans_huge(*pmd)))
72012 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72013 index 59a0059..b3f3d86 100644
72014 --- a/mm/hugetlb.c
72015 +++ b/mm/hugetlb.c
72016 @@ -2518,6 +2518,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72017 return 1;
72018 }
72019
72020 +#ifdef CONFIG_PAX_SEGMEXEC
72021 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72022 +{
72023 + struct mm_struct *mm = vma->vm_mm;
72024 + struct vm_area_struct *vma_m;
72025 + unsigned long address_m;
72026 + pte_t *ptep_m;
72027 +
72028 + vma_m = pax_find_mirror_vma(vma);
72029 + if (!vma_m)
72030 + return;
72031 +
72032 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72033 + address_m = address + SEGMEXEC_TASK_SIZE;
72034 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72035 + get_page(page_m);
72036 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
72037 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72038 +}
72039 +#endif
72040 +
72041 /*
72042 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72043 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72044 @@ -2636,6 +2657,11 @@ retry_avoidcopy:
72045 make_huge_pte(vma, new_page, 1));
72046 page_remove_rmap(old_page);
72047 hugepage_add_new_anon_rmap(new_page, vma, address);
72048 +
72049 +#ifdef CONFIG_PAX_SEGMEXEC
72050 + pax_mirror_huge_pte(vma, address, new_page);
72051 +#endif
72052 +
72053 /* Make the old page be freed below */
72054 new_page = old_page;
72055 }
72056 @@ -2795,6 +2821,10 @@ retry:
72057 && (vma->vm_flags & VM_SHARED)));
72058 set_huge_pte_at(mm, address, ptep, new_pte);
72059
72060 +#ifdef CONFIG_PAX_SEGMEXEC
72061 + pax_mirror_huge_pte(vma, address, page);
72062 +#endif
72063 +
72064 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72065 /* Optimization, do the COW without a second fault */
72066 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72067 @@ -2824,6 +2854,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72068 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72069 struct hstate *h = hstate_vma(vma);
72070
72071 +#ifdef CONFIG_PAX_SEGMEXEC
72072 + struct vm_area_struct *vma_m;
72073 +#endif
72074 +
72075 address &= huge_page_mask(h);
72076
72077 ptep = huge_pte_offset(mm, address);
72078 @@ -2837,6 +2871,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72079 VM_FAULT_SET_HINDEX(hstate_index(h));
72080 }
72081
72082 +#ifdef CONFIG_PAX_SEGMEXEC
72083 + vma_m = pax_find_mirror_vma(vma);
72084 + if (vma_m) {
72085 + unsigned long address_m;
72086 +
72087 + if (vma->vm_start > vma_m->vm_start) {
72088 + address_m = address;
72089 + address -= SEGMEXEC_TASK_SIZE;
72090 + vma = vma_m;
72091 + h = hstate_vma(vma);
72092 + } else
72093 + address_m = address + SEGMEXEC_TASK_SIZE;
72094 +
72095 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72096 + return VM_FAULT_OOM;
72097 + address_m &= HPAGE_MASK;
72098 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72099 + }
72100 +#endif
72101 +
72102 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72103 if (!ptep)
72104 return VM_FAULT_OOM;
72105 diff --git a/mm/internal.h b/mm/internal.h
72106 index a4fa284..9a02499 100644
72107 --- a/mm/internal.h
72108 +++ b/mm/internal.h
72109 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72110 * in mm/page_alloc.c
72111 */
72112 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72113 +extern void free_compound_page(struct page *page);
72114 extern void prep_compound_page(struct page *page, unsigned long order);
72115 #ifdef CONFIG_MEMORY_FAILURE
72116 extern bool is_free_buddy_page(struct page *page);
72117 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72118 index a217cc5..74c9ec0 100644
72119 --- a/mm/kmemleak.c
72120 +++ b/mm/kmemleak.c
72121 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72122
72123 for (i = 0; i < object->trace_len; i++) {
72124 void *ptr = (void *)object->trace[i];
72125 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72126 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72127 }
72128 }
72129
72130 diff --git a/mm/maccess.c b/mm/maccess.c
72131 index d53adf9..03a24bf 100644
72132 --- a/mm/maccess.c
72133 +++ b/mm/maccess.c
72134 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72135 set_fs(KERNEL_DS);
72136 pagefault_disable();
72137 ret = __copy_from_user_inatomic(dst,
72138 - (__force const void __user *)src, size);
72139 + (const void __force_user *)src, size);
72140 pagefault_enable();
72141 set_fs(old_fs);
72142
72143 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72144
72145 set_fs(KERNEL_DS);
72146 pagefault_disable();
72147 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72148 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72149 pagefault_enable();
72150 set_fs(old_fs);
72151
72152 diff --git a/mm/madvise.c b/mm/madvise.c
72153 index 03dfa5c..b032917 100644
72154 --- a/mm/madvise.c
72155 +++ b/mm/madvise.c
72156 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72157 pgoff_t pgoff;
72158 unsigned long new_flags = vma->vm_flags;
72159
72160 +#ifdef CONFIG_PAX_SEGMEXEC
72161 + struct vm_area_struct *vma_m;
72162 +#endif
72163 +
72164 switch (behavior) {
72165 case MADV_NORMAL:
72166 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72167 @@ -123,6 +127,13 @@ success:
72168 /*
72169 * vm_flags is protected by the mmap_sem held in write mode.
72170 */
72171 +
72172 +#ifdef CONFIG_PAX_SEGMEXEC
72173 + vma_m = pax_find_mirror_vma(vma);
72174 + if (vma_m)
72175 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72176 +#endif
72177 +
72178 vma->vm_flags = new_flags;
72179
72180 out:
72181 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72182 struct vm_area_struct ** prev,
72183 unsigned long start, unsigned long end)
72184 {
72185 +
72186 +#ifdef CONFIG_PAX_SEGMEXEC
72187 + struct vm_area_struct *vma_m;
72188 +#endif
72189 +
72190 *prev = vma;
72191 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72192 return -EINVAL;
72193 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72194 zap_page_range(vma, start, end - start, &details);
72195 } else
72196 zap_page_range(vma, start, end - start, NULL);
72197 +
72198 +#ifdef CONFIG_PAX_SEGMEXEC
72199 + vma_m = pax_find_mirror_vma(vma);
72200 + if (vma_m) {
72201 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72202 + struct zap_details details = {
72203 + .nonlinear_vma = vma_m,
72204 + .last_index = ULONG_MAX,
72205 + };
72206 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72207 + } else
72208 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72209 + }
72210 +#endif
72211 +
72212 return 0;
72213 }
72214
72215 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72216 if (end < start)
72217 goto out;
72218
72219 +#ifdef CONFIG_PAX_SEGMEXEC
72220 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72221 + if (end > SEGMEXEC_TASK_SIZE)
72222 + goto out;
72223 + } else
72224 +#endif
72225 +
72226 + if (end > TASK_SIZE)
72227 + goto out;
72228 +
72229 error = 0;
72230 if (end == start)
72231 goto out;
72232 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72233 index 8b20278..05dac18 100644
72234 --- a/mm/memory-failure.c
72235 +++ b/mm/memory-failure.c
72236 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72237
72238 int sysctl_memory_failure_recovery __read_mostly = 1;
72239
72240 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72241 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72242
72243 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72244
72245 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72246 pfn, t->comm, t->pid);
72247 si.si_signo = SIGBUS;
72248 si.si_errno = 0;
72249 - si.si_addr = (void *)addr;
72250 + si.si_addr = (void __user *)addr;
72251 #ifdef __ARCH_SI_TRAPNO
72252 si.si_trapno = trapno;
72253 #endif
72254 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72255 }
72256
72257 nr_pages = 1 << compound_trans_order(hpage);
72258 - atomic_long_add(nr_pages, &mce_bad_pages);
72259 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72260
72261 /*
72262 * We need/can do nothing about count=0 pages.
72263 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72264 if (!PageHWPoison(hpage)
72265 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72266 || (p != hpage && TestSetPageHWPoison(hpage))) {
72267 - atomic_long_sub(nr_pages, &mce_bad_pages);
72268 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72269 return 0;
72270 }
72271 set_page_hwpoison_huge_page(hpage);
72272 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72273 }
72274 if (hwpoison_filter(p)) {
72275 if (TestClearPageHWPoison(p))
72276 - atomic_long_sub(nr_pages, &mce_bad_pages);
72277 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72278 unlock_page(hpage);
72279 put_page(hpage);
72280 return 0;
72281 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
72282 return 0;
72283 }
72284 if (TestClearPageHWPoison(p))
72285 - atomic_long_sub(nr_pages, &mce_bad_pages);
72286 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72287 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72288 return 0;
72289 }
72290 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
72291 */
72292 if (TestClearPageHWPoison(page)) {
72293 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72294 - atomic_long_sub(nr_pages, &mce_bad_pages);
72295 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72296 freeit = 1;
72297 if (PageHuge(page))
72298 clear_page_hwpoison_huge_page(page);
72299 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72300 }
72301 done:
72302 if (!PageHWPoison(hpage))
72303 - atomic_long_add(1 << compound_trans_order(hpage),
72304 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72305 &mce_bad_pages);
72306 set_page_hwpoison_huge_page(hpage);
72307 dequeue_hwpoisoned_huge_page(hpage);
72308 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
72309 return ret;
72310
72311 done:
72312 - atomic_long_add(1, &mce_bad_pages);
72313 + atomic_long_add_unchecked(1, &mce_bad_pages);
72314 SetPageHWPoison(page);
72315 /* keep elevated page count for bad page */
72316 return ret;
72317 diff --git a/mm/memory.c b/mm/memory.c
72318 index 221fc9f..d1d4db1 100644
72319 --- a/mm/memory.c
72320 +++ b/mm/memory.c
72321 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72322 free_pte_range(tlb, pmd, addr);
72323 } while (pmd++, addr = next, addr != end);
72324
72325 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72326 start &= PUD_MASK;
72327 if (start < floor)
72328 return;
72329 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72330 pmd = pmd_offset(pud, start);
72331 pud_clear(pud);
72332 pmd_free_tlb(tlb, pmd, start);
72333 +#endif
72334 +
72335 }
72336
72337 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72338 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72339 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72340 } while (pud++, addr = next, addr != end);
72341
72342 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72343 start &= PGDIR_MASK;
72344 if (start < floor)
72345 return;
72346 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72347 pud = pud_offset(pgd, start);
72348 pgd_clear(pgd);
72349 pud_free_tlb(tlb, pud, start);
72350 +#endif
72351 +
72352 }
72353
72354 /*
72355 @@ -1621,12 +1627,6 @@ no_page_table:
72356 return page;
72357 }
72358
72359 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72360 -{
72361 - return stack_guard_page_start(vma, addr) ||
72362 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72363 -}
72364 -
72365 /**
72366 * __get_user_pages() - pin user pages in memory
72367 * @tsk: task_struct of target task
72368 @@ -1699,10 +1699,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72369 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72370 i = 0;
72371
72372 - do {
72373 + while (nr_pages) {
72374 struct vm_area_struct *vma;
72375
72376 - vma = find_extend_vma(mm, start);
72377 + vma = find_vma(mm, start);
72378 if (!vma && in_gate_area(mm, start)) {
72379 unsigned long pg = start & PAGE_MASK;
72380 pgd_t *pgd;
72381 @@ -1750,7 +1750,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72382 goto next_page;
72383 }
72384
72385 - if (!vma ||
72386 + if (!vma || start < vma->vm_start ||
72387 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72388 !(vm_flags & vma->vm_flags))
72389 return i ? : -EFAULT;
72390 @@ -1777,11 +1777,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72391 int ret;
72392 unsigned int fault_flags = 0;
72393
72394 - /* For mlock, just skip the stack guard page. */
72395 - if (foll_flags & FOLL_MLOCK) {
72396 - if (stack_guard_page(vma, start))
72397 - goto next_page;
72398 - }
72399 if (foll_flags & FOLL_WRITE)
72400 fault_flags |= FAULT_FLAG_WRITE;
72401 if (nonblocking)
72402 @@ -1855,7 +1850,7 @@ next_page:
72403 start += PAGE_SIZE;
72404 nr_pages--;
72405 } while (nr_pages && start < vma->vm_end);
72406 - } while (nr_pages);
72407 + }
72408 return i;
72409 }
72410 EXPORT_SYMBOL(__get_user_pages);
72411 @@ -2062,6 +2057,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72412 page_add_file_rmap(page);
72413 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72414
72415 +#ifdef CONFIG_PAX_SEGMEXEC
72416 + pax_mirror_file_pte(vma, addr, page, ptl);
72417 +#endif
72418 +
72419 retval = 0;
72420 pte_unmap_unlock(pte, ptl);
72421 return retval;
72422 @@ -2106,9 +2105,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72423 if (!page_count(page))
72424 return -EINVAL;
72425 if (!(vma->vm_flags & VM_MIXEDMAP)) {
72426 +
72427 +#ifdef CONFIG_PAX_SEGMEXEC
72428 + struct vm_area_struct *vma_m;
72429 +#endif
72430 +
72431 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
72432 BUG_ON(vma->vm_flags & VM_PFNMAP);
72433 vma->vm_flags |= VM_MIXEDMAP;
72434 +
72435 +#ifdef CONFIG_PAX_SEGMEXEC
72436 + vma_m = pax_find_mirror_vma(vma);
72437 + if (vma_m)
72438 + vma_m->vm_flags |= VM_MIXEDMAP;
72439 +#endif
72440 +
72441 }
72442 return insert_page(vma, addr, page, vma->vm_page_prot);
72443 }
72444 @@ -2191,6 +2202,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72445 unsigned long pfn)
72446 {
72447 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72448 + BUG_ON(vma->vm_mirror);
72449
72450 if (addr < vma->vm_start || addr >= vma->vm_end)
72451 return -EFAULT;
72452 @@ -2391,7 +2403,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72453
72454 BUG_ON(pud_huge(*pud));
72455
72456 - pmd = pmd_alloc(mm, pud, addr);
72457 + pmd = (mm == &init_mm) ?
72458 + pmd_alloc_kernel(mm, pud, addr) :
72459 + pmd_alloc(mm, pud, addr);
72460 if (!pmd)
72461 return -ENOMEM;
72462 do {
72463 @@ -2411,7 +2425,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72464 unsigned long next;
72465 int err;
72466
72467 - pud = pud_alloc(mm, pgd, addr);
72468 + pud = (mm == &init_mm) ?
72469 + pud_alloc_kernel(mm, pgd, addr) :
72470 + pud_alloc(mm, pgd, addr);
72471 if (!pud)
72472 return -ENOMEM;
72473 do {
72474 @@ -2499,6 +2515,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72475 copy_user_highpage(dst, src, va, vma);
72476 }
72477
72478 +#ifdef CONFIG_PAX_SEGMEXEC
72479 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72480 +{
72481 + struct mm_struct *mm = vma->vm_mm;
72482 + spinlock_t *ptl;
72483 + pte_t *pte, entry;
72484 +
72485 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72486 + entry = *pte;
72487 + if (!pte_present(entry)) {
72488 + if (!pte_none(entry)) {
72489 + BUG_ON(pte_file(entry));
72490 + free_swap_and_cache(pte_to_swp_entry(entry));
72491 + pte_clear_not_present_full(mm, address, pte, 0);
72492 + }
72493 + } else {
72494 + struct page *page;
72495 +
72496 + flush_cache_page(vma, address, pte_pfn(entry));
72497 + entry = ptep_clear_flush(vma, address, pte);
72498 + BUG_ON(pte_dirty(entry));
72499 + page = vm_normal_page(vma, address, entry);
72500 + if (page) {
72501 + update_hiwater_rss(mm);
72502 + if (PageAnon(page))
72503 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72504 + else
72505 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72506 + page_remove_rmap(page);
72507 + page_cache_release(page);
72508 + }
72509 + }
72510 + pte_unmap_unlock(pte, ptl);
72511 +}
72512 +
72513 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72514 + *
72515 + * the ptl of the lower mapped page is held on entry and is not released on exit
72516 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72517 + */
72518 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72519 +{
72520 + struct mm_struct *mm = vma->vm_mm;
72521 + unsigned long address_m;
72522 + spinlock_t *ptl_m;
72523 + struct vm_area_struct *vma_m;
72524 + pmd_t *pmd_m;
72525 + pte_t *pte_m, entry_m;
72526 +
72527 + BUG_ON(!page_m || !PageAnon(page_m));
72528 +
72529 + vma_m = pax_find_mirror_vma(vma);
72530 + if (!vma_m)
72531 + return;
72532 +
72533 + BUG_ON(!PageLocked(page_m));
72534 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72535 + address_m = address + SEGMEXEC_TASK_SIZE;
72536 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72537 + pte_m = pte_offset_map(pmd_m, address_m);
72538 + ptl_m = pte_lockptr(mm, pmd_m);
72539 + if (ptl != ptl_m) {
72540 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72541 + if (!pte_none(*pte_m))
72542 + goto out;
72543 + }
72544 +
72545 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72546 + page_cache_get(page_m);
72547 + page_add_anon_rmap(page_m, vma_m, address_m);
72548 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72549 + set_pte_at(mm, address_m, pte_m, entry_m);
72550 + update_mmu_cache(vma_m, address_m, entry_m);
72551 +out:
72552 + if (ptl != ptl_m)
72553 + spin_unlock(ptl_m);
72554 + pte_unmap(pte_m);
72555 + unlock_page(page_m);
72556 +}
72557 +
72558 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72559 +{
72560 + struct mm_struct *mm = vma->vm_mm;
72561 + unsigned long address_m;
72562 + spinlock_t *ptl_m;
72563 + struct vm_area_struct *vma_m;
72564 + pmd_t *pmd_m;
72565 + pte_t *pte_m, entry_m;
72566 +
72567 + BUG_ON(!page_m || PageAnon(page_m));
72568 +
72569 + vma_m = pax_find_mirror_vma(vma);
72570 + if (!vma_m)
72571 + return;
72572 +
72573 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72574 + address_m = address + SEGMEXEC_TASK_SIZE;
72575 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72576 + pte_m = pte_offset_map(pmd_m, address_m);
72577 + ptl_m = pte_lockptr(mm, pmd_m);
72578 + if (ptl != ptl_m) {
72579 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72580 + if (!pte_none(*pte_m))
72581 + goto out;
72582 + }
72583 +
72584 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72585 + page_cache_get(page_m);
72586 + page_add_file_rmap(page_m);
72587 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72588 + set_pte_at(mm, address_m, pte_m, entry_m);
72589 + update_mmu_cache(vma_m, address_m, entry_m);
72590 +out:
72591 + if (ptl != ptl_m)
72592 + spin_unlock(ptl_m);
72593 + pte_unmap(pte_m);
72594 +}
72595 +
72596 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72597 +{
72598 + struct mm_struct *mm = vma->vm_mm;
72599 + unsigned long address_m;
72600 + spinlock_t *ptl_m;
72601 + struct vm_area_struct *vma_m;
72602 + pmd_t *pmd_m;
72603 + pte_t *pte_m, entry_m;
72604 +
72605 + vma_m = pax_find_mirror_vma(vma);
72606 + if (!vma_m)
72607 + return;
72608 +
72609 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72610 + address_m = address + SEGMEXEC_TASK_SIZE;
72611 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72612 + pte_m = pte_offset_map(pmd_m, address_m);
72613 + ptl_m = pte_lockptr(mm, pmd_m);
72614 + if (ptl != ptl_m) {
72615 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72616 + if (!pte_none(*pte_m))
72617 + goto out;
72618 + }
72619 +
72620 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72621 + set_pte_at(mm, address_m, pte_m, entry_m);
72622 +out:
72623 + if (ptl != ptl_m)
72624 + spin_unlock(ptl_m);
72625 + pte_unmap(pte_m);
72626 +}
72627 +
72628 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72629 +{
72630 + struct page *page_m;
72631 + pte_t entry;
72632 +
72633 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72634 + goto out;
72635 +
72636 + entry = *pte;
72637 + page_m = vm_normal_page(vma, address, entry);
72638 + if (!page_m)
72639 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72640 + else if (PageAnon(page_m)) {
72641 + if (pax_find_mirror_vma(vma)) {
72642 + pte_unmap_unlock(pte, ptl);
72643 + lock_page(page_m);
72644 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72645 + if (pte_same(entry, *pte))
72646 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72647 + else
72648 + unlock_page(page_m);
72649 + }
72650 + } else
72651 + pax_mirror_file_pte(vma, address, page_m, ptl);
72652 +
72653 +out:
72654 + pte_unmap_unlock(pte, ptl);
72655 +}
72656 +#endif
72657 +
72658 /*
72659 * This routine handles present pages, when users try to write
72660 * to a shared page. It is done by copying the page to a new address
72661 @@ -2715,6 +2911,12 @@ gotten:
72662 */
72663 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72664 if (likely(pte_same(*page_table, orig_pte))) {
72665 +
72666 +#ifdef CONFIG_PAX_SEGMEXEC
72667 + if (pax_find_mirror_vma(vma))
72668 + BUG_ON(!trylock_page(new_page));
72669 +#endif
72670 +
72671 if (old_page) {
72672 if (!PageAnon(old_page)) {
72673 dec_mm_counter_fast(mm, MM_FILEPAGES);
72674 @@ -2766,6 +2968,10 @@ gotten:
72675 page_remove_rmap(old_page);
72676 }
72677
72678 +#ifdef CONFIG_PAX_SEGMEXEC
72679 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72680 +#endif
72681 +
72682 /* Free the old page.. */
72683 new_page = old_page;
72684 ret |= VM_FAULT_WRITE;
72685 @@ -3046,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72686 swap_free(entry);
72687 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72688 try_to_free_swap(page);
72689 +
72690 +#ifdef CONFIG_PAX_SEGMEXEC
72691 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72692 +#endif
72693 +
72694 unlock_page(page);
72695 if (swapcache) {
72696 /*
72697 @@ -3069,6 +3280,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72698
72699 /* No need to invalidate - it was non-present before */
72700 update_mmu_cache(vma, address, page_table);
72701 +
72702 +#ifdef CONFIG_PAX_SEGMEXEC
72703 + pax_mirror_anon_pte(vma, address, page, ptl);
72704 +#endif
72705 +
72706 unlock:
72707 pte_unmap_unlock(page_table, ptl);
72708 out:
72709 @@ -3088,40 +3304,6 @@ out_release:
72710 }
72711
72712 /*
72713 - * This is like a special single-page "expand_{down|up}wards()",
72714 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72715 - * doesn't hit another vma.
72716 - */
72717 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72718 -{
72719 - address &= PAGE_MASK;
72720 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72721 - struct vm_area_struct *prev = vma->vm_prev;
72722 -
72723 - /*
72724 - * Is there a mapping abutting this one below?
72725 - *
72726 - * That's only ok if it's the same stack mapping
72727 - * that has gotten split..
72728 - */
72729 - if (prev && prev->vm_end == address)
72730 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72731 -
72732 - expand_downwards(vma, address - PAGE_SIZE);
72733 - }
72734 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72735 - struct vm_area_struct *next = vma->vm_next;
72736 -
72737 - /* As VM_GROWSDOWN but s/below/above/ */
72738 - if (next && next->vm_start == address + PAGE_SIZE)
72739 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72740 -
72741 - expand_upwards(vma, address + PAGE_SIZE);
72742 - }
72743 - return 0;
72744 -}
72745 -
72746 -/*
72747 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72748 * but allow concurrent faults), and pte mapped but not yet locked.
72749 * We return with mmap_sem still held, but pte unmapped and unlocked.
72750 @@ -3130,27 +3312,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72751 unsigned long address, pte_t *page_table, pmd_t *pmd,
72752 unsigned int flags)
72753 {
72754 - struct page *page;
72755 + struct page *page = NULL;
72756 spinlock_t *ptl;
72757 pte_t entry;
72758
72759 - pte_unmap(page_table);
72760 -
72761 - /* Check if we need to add a guard page to the stack */
72762 - if (check_stack_guard_page(vma, address) < 0)
72763 - return VM_FAULT_SIGBUS;
72764 -
72765 - /* Use the zero-page for reads */
72766 if (!(flags & FAULT_FLAG_WRITE)) {
72767 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72768 vma->vm_page_prot));
72769 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72770 + ptl = pte_lockptr(mm, pmd);
72771 + spin_lock(ptl);
72772 if (!pte_none(*page_table))
72773 goto unlock;
72774 goto setpte;
72775 }
72776
72777 /* Allocate our own private page. */
72778 + pte_unmap(page_table);
72779 +
72780 if (unlikely(anon_vma_prepare(vma)))
72781 goto oom;
72782 page = alloc_zeroed_user_highpage_movable(vma, address);
72783 @@ -3169,6 +3347,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72784 if (!pte_none(*page_table))
72785 goto release;
72786
72787 +#ifdef CONFIG_PAX_SEGMEXEC
72788 + if (pax_find_mirror_vma(vma))
72789 + BUG_ON(!trylock_page(page));
72790 +#endif
72791 +
72792 inc_mm_counter_fast(mm, MM_ANONPAGES);
72793 page_add_new_anon_rmap(page, vma, address);
72794 setpte:
72795 @@ -3176,6 +3359,12 @@ setpte:
72796
72797 /* No need to invalidate - it was non-present before */
72798 update_mmu_cache(vma, address, page_table);
72799 +
72800 +#ifdef CONFIG_PAX_SEGMEXEC
72801 + if (page)
72802 + pax_mirror_anon_pte(vma, address, page, ptl);
72803 +#endif
72804 +
72805 unlock:
72806 pte_unmap_unlock(page_table, ptl);
72807 return 0;
72808 @@ -3319,6 +3508,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72809 */
72810 /* Only go through if we didn't race with anybody else... */
72811 if (likely(pte_same(*page_table, orig_pte))) {
72812 +
72813 +#ifdef CONFIG_PAX_SEGMEXEC
72814 + if (anon && pax_find_mirror_vma(vma))
72815 + BUG_ON(!trylock_page(page));
72816 +#endif
72817 +
72818 flush_icache_page(vma, page);
72819 entry = mk_pte(page, vma->vm_page_prot);
72820 if (flags & FAULT_FLAG_WRITE)
72821 @@ -3338,6 +3533,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72822
72823 /* no need to invalidate: a not-present page won't be cached */
72824 update_mmu_cache(vma, address, page_table);
72825 +
72826 +#ifdef CONFIG_PAX_SEGMEXEC
72827 + if (anon)
72828 + pax_mirror_anon_pte(vma, address, page, ptl);
72829 + else
72830 + pax_mirror_file_pte(vma, address, page, ptl);
72831 +#endif
72832 +
72833 } else {
72834 if (cow_page)
72835 mem_cgroup_uncharge_page(cow_page);
72836 @@ -3492,6 +3695,12 @@ int handle_pte_fault(struct mm_struct *mm,
72837 if (flags & FAULT_FLAG_WRITE)
72838 flush_tlb_fix_spurious_fault(vma, address);
72839 }
72840 +
72841 +#ifdef CONFIG_PAX_SEGMEXEC
72842 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72843 + return 0;
72844 +#endif
72845 +
72846 unlock:
72847 pte_unmap_unlock(pte, ptl);
72848 return 0;
72849 @@ -3508,6 +3717,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72850 pmd_t *pmd;
72851 pte_t *pte;
72852
72853 +#ifdef CONFIG_PAX_SEGMEXEC
72854 + struct vm_area_struct *vma_m;
72855 +#endif
72856 +
72857 __set_current_state(TASK_RUNNING);
72858
72859 count_vm_event(PGFAULT);
72860 @@ -3519,6 +3732,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72861 if (unlikely(is_vm_hugetlb_page(vma)))
72862 return hugetlb_fault(mm, vma, address, flags);
72863
72864 +#ifdef CONFIG_PAX_SEGMEXEC
72865 + vma_m = pax_find_mirror_vma(vma);
72866 + if (vma_m) {
72867 + unsigned long address_m;
72868 + pgd_t *pgd_m;
72869 + pud_t *pud_m;
72870 + pmd_t *pmd_m;
72871 +
72872 + if (vma->vm_start > vma_m->vm_start) {
72873 + address_m = address;
72874 + address -= SEGMEXEC_TASK_SIZE;
72875 + vma = vma_m;
72876 + } else
72877 + address_m = address + SEGMEXEC_TASK_SIZE;
72878 +
72879 + pgd_m = pgd_offset(mm, address_m);
72880 + pud_m = pud_alloc(mm, pgd_m, address_m);
72881 + if (!pud_m)
72882 + return VM_FAULT_OOM;
72883 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72884 + if (!pmd_m)
72885 + return VM_FAULT_OOM;
72886 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72887 + return VM_FAULT_OOM;
72888 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72889 + }
72890 +#endif
72891 +
72892 retry:
72893 pgd = pgd_offset(mm, address);
72894 pud = pud_alloc(mm, pgd, address);
72895 @@ -3560,7 +3801,7 @@ retry:
72896 * run pte_offset_map on the pmd, if an huge pmd could
72897 * materialize from under us from a different thread.
72898 */
72899 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72900 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72901 return VM_FAULT_OOM;
72902 /* if an huge pmd materialized from under us just retry later */
72903 if (unlikely(pmd_trans_huge(*pmd)))
72904 @@ -3597,6 +3838,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72905 spin_unlock(&mm->page_table_lock);
72906 return 0;
72907 }
72908 +
72909 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72910 +{
72911 + pud_t *new = pud_alloc_one(mm, address);
72912 + if (!new)
72913 + return -ENOMEM;
72914 +
72915 + smp_wmb(); /* See comment in __pte_alloc */
72916 +
72917 + spin_lock(&mm->page_table_lock);
72918 + if (pgd_present(*pgd)) /* Another has populated it */
72919 + pud_free(mm, new);
72920 + else
72921 + pgd_populate_kernel(mm, pgd, new);
72922 + spin_unlock(&mm->page_table_lock);
72923 + return 0;
72924 +}
72925 #endif /* __PAGETABLE_PUD_FOLDED */
72926
72927 #ifndef __PAGETABLE_PMD_FOLDED
72928 @@ -3627,6 +3885,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72929 spin_unlock(&mm->page_table_lock);
72930 return 0;
72931 }
72932 +
72933 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72934 +{
72935 + pmd_t *new = pmd_alloc_one(mm, address);
72936 + if (!new)
72937 + return -ENOMEM;
72938 +
72939 + smp_wmb(); /* See comment in __pte_alloc */
72940 +
72941 + spin_lock(&mm->page_table_lock);
72942 +#ifndef __ARCH_HAS_4LEVEL_HACK
72943 + if (pud_present(*pud)) /* Another has populated it */
72944 + pmd_free(mm, new);
72945 + else
72946 + pud_populate_kernel(mm, pud, new);
72947 +#else
72948 + if (pgd_present(*pud)) /* Another has populated it */
72949 + pmd_free(mm, new);
72950 + else
72951 + pgd_populate_kernel(mm, pud, new);
72952 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72953 + spin_unlock(&mm->page_table_lock);
72954 + return 0;
72955 +}
72956 #endif /* __PAGETABLE_PMD_FOLDED */
72957
72958 int make_pages_present(unsigned long addr, unsigned long end)
72959 @@ -3664,7 +3946,7 @@ static int __init gate_vma_init(void)
72960 gate_vma.vm_start = FIXADDR_USER_START;
72961 gate_vma.vm_end = FIXADDR_USER_END;
72962 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72963 - gate_vma.vm_page_prot = __P101;
72964 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72965
72966 return 0;
72967 }
72968 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72969 index 4ea600d..1cd61c2 100644
72970 --- a/mm/mempolicy.c
72971 +++ b/mm/mempolicy.c
72972 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72973 unsigned long vmstart;
72974 unsigned long vmend;
72975
72976 +#ifdef CONFIG_PAX_SEGMEXEC
72977 + struct vm_area_struct *vma_m;
72978 +#endif
72979 +
72980 vma = find_vma(mm, start);
72981 if (!vma || vma->vm_start > start)
72982 return -EFAULT;
72983 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72984 if (err)
72985 goto out;
72986 }
72987 +
72988 err = vma_replace_policy(vma, new_pol);
72989 if (err)
72990 goto out;
72991 +
72992 +#ifdef CONFIG_PAX_SEGMEXEC
72993 + vma_m = pax_find_mirror_vma(vma);
72994 + if (vma_m) {
72995 + err = vma_replace_policy(vma_m, new_pol);
72996 + if (err)
72997 + goto out;
72998 + }
72999 +#endif
73000 +
73001 }
73002
73003 out:
73004 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73005
73006 if (end < start)
73007 return -EINVAL;
73008 +
73009 +#ifdef CONFIG_PAX_SEGMEXEC
73010 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73011 + if (end > SEGMEXEC_TASK_SIZE)
73012 + return -EINVAL;
73013 + } else
73014 +#endif
73015 +
73016 + if (end > TASK_SIZE)
73017 + return -EINVAL;
73018 +
73019 if (end == start)
73020 return 0;
73021
73022 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73023 */
73024 tcred = __task_cred(task);
73025 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73026 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73027 - !capable(CAP_SYS_NICE)) {
73028 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73029 rcu_read_unlock();
73030 err = -EPERM;
73031 goto out_put;
73032 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73033 goto out;
73034 }
73035
73036 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73037 + if (mm != current->mm &&
73038 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73039 + mmput(mm);
73040 + err = -EPERM;
73041 + goto out;
73042 + }
73043 +#endif
73044 +
73045 err = do_migrate_pages(mm, old, new,
73046 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73047
73048 diff --git a/mm/migrate.c b/mm/migrate.c
73049 index 77ed2d7..317d528 100644
73050 --- a/mm/migrate.c
73051 +++ b/mm/migrate.c
73052 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73053 */
73054 tcred = __task_cred(task);
73055 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73056 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73057 - !capable(CAP_SYS_NICE)) {
73058 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73059 rcu_read_unlock();
73060 err = -EPERM;
73061 goto out;
73062 diff --git a/mm/mlock.c b/mm/mlock.c
73063 index f0b9ce5..da8d069 100644
73064 --- a/mm/mlock.c
73065 +++ b/mm/mlock.c
73066 @@ -13,6 +13,7 @@
73067 #include <linux/pagemap.h>
73068 #include <linux/mempolicy.h>
73069 #include <linux/syscalls.h>
73070 +#include <linux/security.h>
73071 #include <linux/sched.h>
73072 #include <linux/export.h>
73073 #include <linux/rmap.h>
73074 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73075 {
73076 unsigned long nstart, end, tmp;
73077 struct vm_area_struct * vma, * prev;
73078 - int error;
73079 + int error = 0;
73080
73081 VM_BUG_ON(start & ~PAGE_MASK);
73082 VM_BUG_ON(len != PAGE_ALIGN(len));
73083 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73084 return -EINVAL;
73085 if (end == start)
73086 return 0;
73087 + if (end > TASK_SIZE)
73088 + return -EINVAL;
73089 +
73090 vma = find_vma(current->mm, start);
73091 if (!vma || vma->vm_start > start)
73092 return -ENOMEM;
73093 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73094 for (nstart = start ; ; ) {
73095 vm_flags_t newflags;
73096
73097 +#ifdef CONFIG_PAX_SEGMEXEC
73098 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73099 + break;
73100 +#endif
73101 +
73102 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73103
73104 newflags = vma->vm_flags | VM_LOCKED;
73105 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73106 lock_limit >>= PAGE_SHIFT;
73107
73108 /* check against resource limits */
73109 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73110 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73111 error = do_mlock(start, len, 1);
73112 up_write(&current->mm->mmap_sem);
73113 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73114 static int do_mlockall(int flags)
73115 {
73116 struct vm_area_struct * vma, * prev = NULL;
73117 - unsigned int def_flags = 0;
73118
73119 if (flags & MCL_FUTURE)
73120 - def_flags = VM_LOCKED;
73121 - current->mm->def_flags = def_flags;
73122 + current->mm->def_flags |= VM_LOCKED;
73123 + else
73124 + current->mm->def_flags &= ~VM_LOCKED;
73125 if (flags == MCL_FUTURE)
73126 goto out;
73127
73128 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73129 vm_flags_t newflags;
73130
73131 +#ifdef CONFIG_PAX_SEGMEXEC
73132 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73133 + break;
73134 +#endif
73135 +
73136 + BUG_ON(vma->vm_end > TASK_SIZE);
73137 newflags = vma->vm_flags | VM_LOCKED;
73138 if (!(flags & MCL_CURRENT))
73139 newflags &= ~VM_LOCKED;
73140 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73141 lock_limit >>= PAGE_SHIFT;
73142
73143 ret = -ENOMEM;
73144 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73145 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73146 capable(CAP_IPC_LOCK))
73147 ret = do_mlockall(flags);
73148 diff --git a/mm/mmap.c b/mm/mmap.c
73149 index 9a796c4..4fba820 100644
73150 --- a/mm/mmap.c
73151 +++ b/mm/mmap.c
73152 @@ -47,6 +47,16 @@
73153 #define arch_rebalance_pgtables(addr, len) (addr)
73154 #endif
73155
73156 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73157 +{
73158 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73159 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73160 + up_read(&mm->mmap_sem);
73161 + BUG();
73162 + }
73163 +#endif
73164 +}
73165 +
73166 static void unmap_region(struct mm_struct *mm,
73167 struct vm_area_struct *vma, struct vm_area_struct *prev,
73168 unsigned long start, unsigned long end);
73169 @@ -66,22 +76,32 @@ static void unmap_region(struct mm_struct *mm,
73170 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73171 *
73172 */
73173 -pgprot_t protection_map[16] = {
73174 +pgprot_t protection_map[16] __read_only = {
73175 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73176 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73177 };
73178
73179 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73180 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73181 {
73182 - return __pgprot(pgprot_val(protection_map[vm_flags &
73183 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73184 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73185 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73186 +
73187 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73188 + if (!(__supported_pte_mask & _PAGE_NX) &&
73189 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73190 + (vm_flags & (VM_READ | VM_WRITE)))
73191 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73192 +#endif
73193 +
73194 + return prot;
73195 }
73196 EXPORT_SYMBOL(vm_get_page_prot);
73197
73198 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73199 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73200 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73201 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73202 /*
73203 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73204 * other variables. It can be updated by several CPUs frequently.
73205 @@ -223,6 +243,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73206 struct vm_area_struct *next = vma->vm_next;
73207
73208 might_sleep();
73209 + BUG_ON(vma->vm_mirror);
73210 if (vma->vm_ops && vma->vm_ops->close)
73211 vma->vm_ops->close(vma);
73212 if (vma->vm_file)
73213 @@ -266,6 +287,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73214 * not page aligned -Ram Gupta
73215 */
73216 rlim = rlimit(RLIMIT_DATA);
73217 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73218 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73219 (mm->end_data - mm->start_data) > rlim)
73220 goto out;
73221 @@ -736,6 +758,12 @@ static int
73222 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73223 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73224 {
73225 +
73226 +#ifdef CONFIG_PAX_SEGMEXEC
73227 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73228 + return 0;
73229 +#endif
73230 +
73231 if (is_mergeable_vma(vma, file, vm_flags) &&
73232 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73233 if (vma->vm_pgoff == vm_pgoff)
73234 @@ -755,6 +783,12 @@ static int
73235 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73236 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73237 {
73238 +
73239 +#ifdef CONFIG_PAX_SEGMEXEC
73240 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73241 + return 0;
73242 +#endif
73243 +
73244 if (is_mergeable_vma(vma, file, vm_flags) &&
73245 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73246 pgoff_t vm_pglen;
73247 @@ -797,13 +831,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73248 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73249 struct vm_area_struct *prev, unsigned long addr,
73250 unsigned long end, unsigned long vm_flags,
73251 - struct anon_vma *anon_vma, struct file *file,
73252 + struct anon_vma *anon_vma, struct file *file,
73253 pgoff_t pgoff, struct mempolicy *policy)
73254 {
73255 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73256 struct vm_area_struct *area, *next;
73257 int err;
73258
73259 +#ifdef CONFIG_PAX_SEGMEXEC
73260 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73261 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73262 +
73263 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73264 +#endif
73265 +
73266 /*
73267 * We later require that vma->vm_flags == vm_flags,
73268 * so this tests vma->vm_flags & VM_SPECIAL, too.
73269 @@ -819,6 +860,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73270 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73271 next = next->vm_next;
73272
73273 +#ifdef CONFIG_PAX_SEGMEXEC
73274 + if (prev)
73275 + prev_m = pax_find_mirror_vma(prev);
73276 + if (area)
73277 + area_m = pax_find_mirror_vma(area);
73278 + if (next)
73279 + next_m = pax_find_mirror_vma(next);
73280 +#endif
73281 +
73282 /*
73283 * Can it merge with the predecessor?
73284 */
73285 @@ -838,9 +888,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73286 /* cases 1, 6 */
73287 err = vma_adjust(prev, prev->vm_start,
73288 next->vm_end, prev->vm_pgoff, NULL);
73289 - } else /* cases 2, 5, 7 */
73290 +
73291 +#ifdef CONFIG_PAX_SEGMEXEC
73292 + if (!err && prev_m)
73293 + err = vma_adjust(prev_m, prev_m->vm_start,
73294 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73295 +#endif
73296 +
73297 + } else { /* cases 2, 5, 7 */
73298 err = vma_adjust(prev, prev->vm_start,
73299 end, prev->vm_pgoff, NULL);
73300 +
73301 +#ifdef CONFIG_PAX_SEGMEXEC
73302 + if (!err && prev_m)
73303 + err = vma_adjust(prev_m, prev_m->vm_start,
73304 + end_m, prev_m->vm_pgoff, NULL);
73305 +#endif
73306 +
73307 + }
73308 if (err)
73309 return NULL;
73310 khugepaged_enter_vma_merge(prev);
73311 @@ -854,12 +919,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73312 mpol_equal(policy, vma_policy(next)) &&
73313 can_vma_merge_before(next, vm_flags,
73314 anon_vma, file, pgoff+pglen)) {
73315 - if (prev && addr < prev->vm_end) /* case 4 */
73316 + if (prev && addr < prev->vm_end) { /* case 4 */
73317 err = vma_adjust(prev, prev->vm_start,
73318 addr, prev->vm_pgoff, NULL);
73319 - else /* cases 3, 8 */
73320 +
73321 +#ifdef CONFIG_PAX_SEGMEXEC
73322 + if (!err && prev_m)
73323 + err = vma_adjust(prev_m, prev_m->vm_start,
73324 + addr_m, prev_m->vm_pgoff, NULL);
73325 +#endif
73326 +
73327 + } else { /* cases 3, 8 */
73328 err = vma_adjust(area, addr, next->vm_end,
73329 next->vm_pgoff - pglen, NULL);
73330 +
73331 +#ifdef CONFIG_PAX_SEGMEXEC
73332 + if (!err && area_m)
73333 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73334 + next_m->vm_pgoff - pglen, NULL);
73335 +#endif
73336 +
73337 + }
73338 if (err)
73339 return NULL;
73340 khugepaged_enter_vma_merge(area);
73341 @@ -968,16 +1048,13 @@ none:
73342 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73343 struct file *file, long pages)
73344 {
73345 - const unsigned long stack_flags
73346 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73347 -
73348 mm->total_vm += pages;
73349
73350 if (file) {
73351 mm->shared_vm += pages;
73352 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73353 mm->exec_vm += pages;
73354 - } else if (flags & stack_flags)
73355 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73356 mm->stack_vm += pages;
73357 }
73358 #endif /* CONFIG_PROC_FS */
73359 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73360 * (the exception is when the underlying filesystem is noexec
73361 * mounted, in which case we dont add PROT_EXEC.)
73362 */
73363 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73364 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73365 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73366 prot |= PROT_EXEC;
73367
73368 @@ -1039,7 +1116,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73369 /* Obtain the address to map to. we verify (or select) it and ensure
73370 * that it represents a valid section of the address space.
73371 */
73372 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73373 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73374 if (addr & ~PAGE_MASK)
73375 return addr;
73376
73377 @@ -1050,6 +1127,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73378 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73379 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73380
73381 +#ifdef CONFIG_PAX_MPROTECT
73382 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73383 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73384 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73385 + gr_log_rwxmmap(file);
73386 +
73387 +#ifdef CONFIG_PAX_EMUPLT
73388 + vm_flags &= ~VM_EXEC;
73389 +#else
73390 + return -EPERM;
73391 +#endif
73392 +
73393 + }
73394 +
73395 + if (!(vm_flags & VM_EXEC))
73396 + vm_flags &= ~VM_MAYEXEC;
73397 +#else
73398 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73399 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73400 +#endif
73401 + else
73402 + vm_flags &= ~VM_MAYWRITE;
73403 + }
73404 +#endif
73405 +
73406 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73407 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73408 + vm_flags &= ~VM_PAGEEXEC;
73409 +#endif
73410 +
73411 if (flags & MAP_LOCKED)
73412 if (!can_do_mlock())
73413 return -EPERM;
73414 @@ -1061,6 +1168,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73415 locked += mm->locked_vm;
73416 lock_limit = rlimit(RLIMIT_MEMLOCK);
73417 lock_limit >>= PAGE_SHIFT;
73418 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73419 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73420 return -EAGAIN;
73421 }
73422 @@ -1127,6 +1235,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73423 }
73424 }
73425
73426 + if (!gr_acl_handle_mmap(file, prot))
73427 + return -EACCES;
73428 +
73429 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73430 }
73431
73432 @@ -1203,7 +1314,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73433 vm_flags_t vm_flags = vma->vm_flags;
73434
73435 /* If it was private or non-writable, the write bit is already clear */
73436 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73437 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73438 return 0;
73439
73440 /* The backer wishes to know when pages are first written to? */
73441 @@ -1252,13 +1363,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73442 unsigned long charged = 0;
73443 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73444
73445 +#ifdef CONFIG_PAX_SEGMEXEC
73446 + struct vm_area_struct *vma_m = NULL;
73447 +#endif
73448 +
73449 + /*
73450 + * mm->mmap_sem is required to protect against another thread
73451 + * changing the mappings in case we sleep.
73452 + */
73453 + verify_mm_writelocked(mm);
73454 +
73455 /* Clear old maps */
73456 error = -ENOMEM;
73457 -munmap_back:
73458 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
73459 if (do_munmap(mm, addr, len))
73460 return -ENOMEM;
73461 - goto munmap_back;
73462 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
73463 }
73464
73465 /* Check against address space limit. */
73466 @@ -1307,6 +1427,16 @@ munmap_back:
73467 goto unacct_error;
73468 }
73469
73470 +#ifdef CONFIG_PAX_SEGMEXEC
73471 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73472 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73473 + if (!vma_m) {
73474 + error = -ENOMEM;
73475 + goto free_vma;
73476 + }
73477 + }
73478 +#endif
73479 +
73480 vma->vm_mm = mm;
73481 vma->vm_start = addr;
73482 vma->vm_end = addr + len;
73483 @@ -1331,6 +1461,13 @@ munmap_back:
73484 if (error)
73485 goto unmap_and_free_vma;
73486
73487 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73488 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73489 + vma->vm_flags |= VM_PAGEEXEC;
73490 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73491 + }
73492 +#endif
73493 +
73494 /* Can addr have changed??
73495 *
73496 * Answer: Yes, several device drivers can do it in their
73497 @@ -1365,6 +1502,11 @@ munmap_back:
73498 vma_link(mm, vma, prev, rb_link, rb_parent);
73499 file = vma->vm_file;
73500
73501 +#ifdef CONFIG_PAX_SEGMEXEC
73502 + if (vma_m)
73503 + BUG_ON(pax_mirror_vma(vma_m, vma));
73504 +#endif
73505 +
73506 /* Once vma denies write, undo our temporary denial count */
73507 if (correct_wcount)
73508 atomic_inc(&inode->i_writecount);
73509 @@ -1372,6 +1514,7 @@ out:
73510 perf_event_mmap(vma);
73511
73512 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73513 + track_exec_limit(mm, addr, addr + len, vm_flags);
73514 if (vm_flags & VM_LOCKED) {
73515 if (!mlock_vma_pages_range(vma, addr, addr + len))
73516 mm->locked_vm += (len >> PAGE_SHIFT);
73517 @@ -1393,6 +1536,12 @@ unmap_and_free_vma:
73518 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73519 charged = 0;
73520 free_vma:
73521 +
73522 +#ifdef CONFIG_PAX_SEGMEXEC
73523 + if (vma_m)
73524 + kmem_cache_free(vm_area_cachep, vma_m);
73525 +#endif
73526 +
73527 kmem_cache_free(vm_area_cachep, vma);
73528 unacct_error:
73529 if (charged)
73530 @@ -1400,6 +1549,44 @@ unacct_error:
73531 return error;
73532 }
73533
73534 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73535 +{
73536 + if (!vma) {
73537 +#ifdef CONFIG_STACK_GROWSUP
73538 + if (addr > sysctl_heap_stack_gap)
73539 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73540 + else
73541 + vma = find_vma(current->mm, 0);
73542 + if (vma && (vma->vm_flags & VM_GROWSUP))
73543 + return false;
73544 +#endif
73545 + return true;
73546 + }
73547 +
73548 + if (addr + len > vma->vm_start)
73549 + return false;
73550 +
73551 + if (vma->vm_flags & VM_GROWSDOWN)
73552 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73553 +#ifdef CONFIG_STACK_GROWSUP
73554 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73555 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73556 +#endif
73557 +
73558 + return true;
73559 +}
73560 +
73561 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73562 +{
73563 + if (vma->vm_start < len)
73564 + return -ENOMEM;
73565 + if (!(vma->vm_flags & VM_GROWSDOWN))
73566 + return vma->vm_start - len;
73567 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73568 + return vma->vm_start - len - sysctl_heap_stack_gap;
73569 + return -ENOMEM;
73570 +}
73571 +
73572 /* Get an address range which is currently unmapped.
73573 * For shmat() with addr=0.
73574 *
73575 @@ -1426,18 +1613,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73576 if (flags & MAP_FIXED)
73577 return addr;
73578
73579 +#ifdef CONFIG_PAX_RANDMMAP
73580 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73581 +#endif
73582 +
73583 if (addr) {
73584 addr = PAGE_ALIGN(addr);
73585 - vma = find_vma(mm, addr);
73586 - if (TASK_SIZE - len >= addr &&
73587 - (!vma || addr + len <= vma->vm_start))
73588 - return addr;
73589 + if (TASK_SIZE - len >= addr) {
73590 + vma = find_vma(mm, addr);
73591 + if (check_heap_stack_gap(vma, addr, len))
73592 + return addr;
73593 + }
73594 }
73595 if (len > mm->cached_hole_size) {
73596 - start_addr = addr = mm->free_area_cache;
73597 + start_addr = addr = mm->free_area_cache;
73598 } else {
73599 - start_addr = addr = TASK_UNMAPPED_BASE;
73600 - mm->cached_hole_size = 0;
73601 + start_addr = addr = mm->mmap_base;
73602 + mm->cached_hole_size = 0;
73603 }
73604
73605 full_search:
73606 @@ -1448,34 +1640,40 @@ full_search:
73607 * Start a new search - just in case we missed
73608 * some holes.
73609 */
73610 - if (start_addr != TASK_UNMAPPED_BASE) {
73611 - addr = TASK_UNMAPPED_BASE;
73612 - start_addr = addr;
73613 + if (start_addr != mm->mmap_base) {
73614 + start_addr = addr = mm->mmap_base;
73615 mm->cached_hole_size = 0;
73616 goto full_search;
73617 }
73618 return -ENOMEM;
73619 }
73620 - if (!vma || addr + len <= vma->vm_start) {
73621 - /*
73622 - * Remember the place where we stopped the search:
73623 - */
73624 - mm->free_area_cache = addr + len;
73625 - return addr;
73626 - }
73627 + if (check_heap_stack_gap(vma, addr, len))
73628 + break;
73629 if (addr + mm->cached_hole_size < vma->vm_start)
73630 mm->cached_hole_size = vma->vm_start - addr;
73631 addr = vma->vm_end;
73632 }
73633 +
73634 + /*
73635 + * Remember the place where we stopped the search:
73636 + */
73637 + mm->free_area_cache = addr + len;
73638 + return addr;
73639 }
73640 #endif
73641
73642 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73643 {
73644 +
73645 +#ifdef CONFIG_PAX_SEGMEXEC
73646 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73647 + return;
73648 +#endif
73649 +
73650 /*
73651 * Is this a new hole at the lowest possible address?
73652 */
73653 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73654 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73655 mm->free_area_cache = addr;
73656 }
73657
73658 @@ -1491,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73659 {
73660 struct vm_area_struct *vma;
73661 struct mm_struct *mm = current->mm;
73662 - unsigned long addr = addr0, start_addr;
73663 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73664
73665 /* requested length too big for entire address space */
73666 if (len > TASK_SIZE)
73667 @@ -1500,13 +1698,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73668 if (flags & MAP_FIXED)
73669 return addr;
73670
73671 +#ifdef CONFIG_PAX_RANDMMAP
73672 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73673 +#endif
73674 +
73675 /* requesting a specific address */
73676 if (addr) {
73677 addr = PAGE_ALIGN(addr);
73678 - vma = find_vma(mm, addr);
73679 - if (TASK_SIZE - len >= addr &&
73680 - (!vma || addr + len <= vma->vm_start))
73681 - return addr;
73682 + if (TASK_SIZE - len >= addr) {
73683 + vma = find_vma(mm, addr);
73684 + if (check_heap_stack_gap(vma, addr, len))
73685 + return addr;
73686 + }
73687 }
73688
73689 /* check if free_area_cache is useful for us */
73690 @@ -1530,7 +1733,7 @@ try_again:
73691 * return with success:
73692 */
73693 vma = find_vma(mm, addr);
73694 - if (!vma || addr+len <= vma->vm_start)
73695 + if (check_heap_stack_gap(vma, addr, len))
73696 /* remember the address as a hint for next time */
73697 return (mm->free_area_cache = addr);
73698
73699 @@ -1539,8 +1742,8 @@ try_again:
73700 mm->cached_hole_size = vma->vm_start - addr;
73701
73702 /* try just below the current vma->vm_start */
73703 - addr = vma->vm_start-len;
73704 - } while (len < vma->vm_start);
73705 + addr = skip_heap_stack_gap(vma, len);
73706 + } while (!IS_ERR_VALUE(addr));
73707
73708 fail:
73709 /*
73710 @@ -1563,13 +1766,21 @@ fail:
73711 * can happen with large stack limits and large mmap()
73712 * allocations.
73713 */
73714 + mm->mmap_base = TASK_UNMAPPED_BASE;
73715 +
73716 +#ifdef CONFIG_PAX_RANDMMAP
73717 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73718 + mm->mmap_base += mm->delta_mmap;
73719 +#endif
73720 +
73721 + mm->free_area_cache = mm->mmap_base;
73722 mm->cached_hole_size = ~0UL;
73723 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73724 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73725 /*
73726 * Restore the topdown base:
73727 */
73728 - mm->free_area_cache = mm->mmap_base;
73729 + mm->mmap_base = base;
73730 + mm->free_area_cache = base;
73731 mm->cached_hole_size = ~0UL;
73732
73733 return addr;
73734 @@ -1578,6 +1789,12 @@ fail:
73735
73736 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73737 {
73738 +
73739 +#ifdef CONFIG_PAX_SEGMEXEC
73740 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73741 + return;
73742 +#endif
73743 +
73744 /*
73745 * Is this a new hole at the highest possible address?
73746 */
73747 @@ -1585,8 +1802,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73748 mm->free_area_cache = addr;
73749
73750 /* dont allow allocations above current base */
73751 - if (mm->free_area_cache > mm->mmap_base)
73752 + if (mm->free_area_cache > mm->mmap_base) {
73753 mm->free_area_cache = mm->mmap_base;
73754 + mm->cached_hole_size = ~0UL;
73755 + }
73756 }
73757
73758 unsigned long
73759 @@ -1685,6 +1904,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73760 return vma;
73761 }
73762
73763 +#ifdef CONFIG_PAX_SEGMEXEC
73764 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73765 +{
73766 + struct vm_area_struct *vma_m;
73767 +
73768 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73769 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73770 + BUG_ON(vma->vm_mirror);
73771 + return NULL;
73772 + }
73773 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73774 + vma_m = vma->vm_mirror;
73775 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73776 + BUG_ON(vma->vm_file != vma_m->vm_file);
73777 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73778 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73779 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73780 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
73781 + return vma_m;
73782 +}
73783 +#endif
73784 +
73785 /*
73786 * Verify that the stack growth is acceptable and
73787 * update accounting. This is shared with both the
73788 @@ -1701,6 +1942,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73789 return -ENOMEM;
73790
73791 /* Stack limit test */
73792 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73793 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73794 return -ENOMEM;
73795
73796 @@ -1711,6 +1953,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73797 locked = mm->locked_vm + grow;
73798 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73799 limit >>= PAGE_SHIFT;
73800 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73801 if (locked > limit && !capable(CAP_IPC_LOCK))
73802 return -ENOMEM;
73803 }
73804 @@ -1740,37 +1983,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73805 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73806 * vma is the last one with address > vma->vm_end. Have to extend vma.
73807 */
73808 +#ifndef CONFIG_IA64
73809 +static
73810 +#endif
73811 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73812 {
73813 int error;
73814 + bool locknext;
73815
73816 if (!(vma->vm_flags & VM_GROWSUP))
73817 return -EFAULT;
73818
73819 + /* Also guard against wrapping around to address 0. */
73820 + if (address < PAGE_ALIGN(address+1))
73821 + address = PAGE_ALIGN(address+1);
73822 + else
73823 + return -ENOMEM;
73824 +
73825 /*
73826 * We must make sure the anon_vma is allocated
73827 * so that the anon_vma locking is not a noop.
73828 */
73829 if (unlikely(anon_vma_prepare(vma)))
73830 return -ENOMEM;
73831 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73832 + if (locknext && anon_vma_prepare(vma->vm_next))
73833 + return -ENOMEM;
73834 vma_lock_anon_vma(vma);
73835 + if (locknext)
73836 + vma_lock_anon_vma(vma->vm_next);
73837
73838 /*
73839 * vma->vm_start/vm_end cannot change under us because the caller
73840 * is required to hold the mmap_sem in read mode. We need the
73841 - * anon_vma lock to serialize against concurrent expand_stacks.
73842 - * Also guard against wrapping around to address 0.
73843 + * anon_vma locks to serialize against concurrent expand_stacks
73844 + * and expand_upwards.
73845 */
73846 - if (address < PAGE_ALIGN(address+4))
73847 - address = PAGE_ALIGN(address+4);
73848 - else {
73849 - vma_unlock_anon_vma(vma);
73850 - return -ENOMEM;
73851 - }
73852 error = 0;
73853
73854 /* Somebody else might have raced and expanded it already */
73855 - if (address > vma->vm_end) {
73856 + 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)
73857 + error = -ENOMEM;
73858 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73859 unsigned long size, grow;
73860
73861 size = address - vma->vm_start;
73862 @@ -1787,6 +2041,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73863 }
73864 }
73865 }
73866 + if (locknext)
73867 + vma_unlock_anon_vma(vma->vm_next);
73868 vma_unlock_anon_vma(vma);
73869 khugepaged_enter_vma_merge(vma);
73870 validate_mm(vma->vm_mm);
73871 @@ -1801,6 +2057,8 @@ int expand_downwards(struct vm_area_struct *vma,
73872 unsigned long address)
73873 {
73874 int error;
73875 + bool lockprev = false;
73876 + struct vm_area_struct *prev;
73877
73878 /*
73879 * We must make sure the anon_vma is allocated
73880 @@ -1814,6 +2072,15 @@ int expand_downwards(struct vm_area_struct *vma,
73881 if (error)
73882 return error;
73883
73884 + prev = vma->vm_prev;
73885 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73886 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73887 +#endif
73888 + if (lockprev && anon_vma_prepare(prev))
73889 + return -ENOMEM;
73890 + if (lockprev)
73891 + vma_lock_anon_vma(prev);
73892 +
73893 vma_lock_anon_vma(vma);
73894
73895 /*
73896 @@ -1823,9 +2090,17 @@ int expand_downwards(struct vm_area_struct *vma,
73897 */
73898
73899 /* Somebody else might have raced and expanded it already */
73900 - if (address < vma->vm_start) {
73901 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73902 + error = -ENOMEM;
73903 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73904 unsigned long size, grow;
73905
73906 +#ifdef CONFIG_PAX_SEGMEXEC
73907 + struct vm_area_struct *vma_m;
73908 +
73909 + vma_m = pax_find_mirror_vma(vma);
73910 +#endif
73911 +
73912 size = vma->vm_end - address;
73913 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73914
73915 @@ -1837,6 +2112,17 @@ int expand_downwards(struct vm_area_struct *vma,
73916 vma->vm_start = address;
73917 vma->vm_pgoff -= grow;
73918 anon_vma_interval_tree_post_update_vma(vma);
73919 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73920 +
73921 +#ifdef CONFIG_PAX_SEGMEXEC
73922 + if (vma_m) {
73923 + anon_vma_interval_tree_pre_update_vma(vma_m);
73924 + vma_m->vm_start -= grow << PAGE_SHIFT;
73925 + vma_m->vm_pgoff -= grow;
73926 + anon_vma_interval_tree_post_update_vma(vma_m);
73927 + }
73928 +#endif
73929 +
73930 perf_event_mmap(vma);
73931 }
73932 }
73933 @@ -1914,6 +2200,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73934 do {
73935 long nrpages = vma_pages(vma);
73936
73937 +#ifdef CONFIG_PAX_SEGMEXEC
73938 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73939 + vma = remove_vma(vma);
73940 + continue;
73941 + }
73942 +#endif
73943 +
73944 if (vma->vm_flags & VM_ACCOUNT)
73945 nr_accounted += nrpages;
73946 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73947 @@ -1959,6 +2252,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73948 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73949 vma->vm_prev = NULL;
73950 do {
73951 +
73952 +#ifdef CONFIG_PAX_SEGMEXEC
73953 + if (vma->vm_mirror) {
73954 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73955 + vma->vm_mirror->vm_mirror = NULL;
73956 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73957 + vma->vm_mirror = NULL;
73958 + }
73959 +#endif
73960 +
73961 rb_erase(&vma->vm_rb, &mm->mm_rb);
73962 mm->map_count--;
73963 tail_vma = vma;
73964 @@ -1987,14 +2290,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73965 struct vm_area_struct *new;
73966 int err = -ENOMEM;
73967
73968 +#ifdef CONFIG_PAX_SEGMEXEC
73969 + struct vm_area_struct *vma_m, *new_m = NULL;
73970 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73971 +#endif
73972 +
73973 if (is_vm_hugetlb_page(vma) && (addr &
73974 ~(huge_page_mask(hstate_vma(vma)))))
73975 return -EINVAL;
73976
73977 +#ifdef CONFIG_PAX_SEGMEXEC
73978 + vma_m = pax_find_mirror_vma(vma);
73979 +#endif
73980 +
73981 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73982 if (!new)
73983 goto out_err;
73984
73985 +#ifdef CONFIG_PAX_SEGMEXEC
73986 + if (vma_m) {
73987 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73988 + if (!new_m) {
73989 + kmem_cache_free(vm_area_cachep, new);
73990 + goto out_err;
73991 + }
73992 + }
73993 +#endif
73994 +
73995 /* most fields are the same, copy all, and then fixup */
73996 *new = *vma;
73997
73998 @@ -2007,6 +2329,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73999 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74000 }
74001
74002 +#ifdef CONFIG_PAX_SEGMEXEC
74003 + if (vma_m) {
74004 + *new_m = *vma_m;
74005 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
74006 + new_m->vm_mirror = new;
74007 + new->vm_mirror = new_m;
74008 +
74009 + if (new_below)
74010 + new_m->vm_end = addr_m;
74011 + else {
74012 + new_m->vm_start = addr_m;
74013 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74014 + }
74015 + }
74016 +#endif
74017 +
74018 pol = mpol_dup(vma_policy(vma));
74019 if (IS_ERR(pol)) {
74020 err = PTR_ERR(pol);
74021 @@ -2029,6 +2367,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74022 else
74023 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74024
74025 +#ifdef CONFIG_PAX_SEGMEXEC
74026 + if (!err && vma_m) {
74027 + if (anon_vma_clone(new_m, vma_m))
74028 + goto out_free_mpol;
74029 +
74030 + mpol_get(pol);
74031 + vma_set_policy(new_m, pol);
74032 +
74033 + if (new_m->vm_file)
74034 + get_file(new_m->vm_file);
74035 +
74036 + if (new_m->vm_ops && new_m->vm_ops->open)
74037 + new_m->vm_ops->open(new_m);
74038 +
74039 + if (new_below)
74040 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74041 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74042 + else
74043 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74044 +
74045 + if (err) {
74046 + if (new_m->vm_ops && new_m->vm_ops->close)
74047 + new_m->vm_ops->close(new_m);
74048 + if (new_m->vm_file)
74049 + fput(new_m->vm_file);
74050 + mpol_put(pol);
74051 + }
74052 + }
74053 +#endif
74054 +
74055 /* Success. */
74056 if (!err)
74057 return 0;
74058 @@ -2038,10 +2406,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74059 new->vm_ops->close(new);
74060 if (new->vm_file)
74061 fput(new->vm_file);
74062 - unlink_anon_vmas(new);
74063 out_free_mpol:
74064 mpol_put(pol);
74065 out_free_vma:
74066 +
74067 +#ifdef CONFIG_PAX_SEGMEXEC
74068 + if (new_m) {
74069 + unlink_anon_vmas(new_m);
74070 + kmem_cache_free(vm_area_cachep, new_m);
74071 + }
74072 +#endif
74073 +
74074 + unlink_anon_vmas(new);
74075 kmem_cache_free(vm_area_cachep, new);
74076 out_err:
74077 return err;
74078 @@ -2054,6 +2430,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74079 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74080 unsigned long addr, int new_below)
74081 {
74082 +
74083 +#ifdef CONFIG_PAX_SEGMEXEC
74084 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74085 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74086 + if (mm->map_count >= sysctl_max_map_count-1)
74087 + return -ENOMEM;
74088 + } else
74089 +#endif
74090 +
74091 if (mm->map_count >= sysctl_max_map_count)
74092 return -ENOMEM;
74093
74094 @@ -2065,11 +2450,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74095 * work. This now handles partial unmappings.
74096 * Jeremy Fitzhardinge <jeremy@goop.org>
74097 */
74098 +#ifdef CONFIG_PAX_SEGMEXEC
74099 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74100 {
74101 + int ret = __do_munmap(mm, start, len);
74102 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74103 + return ret;
74104 +
74105 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74106 +}
74107 +
74108 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74109 +#else
74110 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74111 +#endif
74112 +{
74113 unsigned long end;
74114 struct vm_area_struct *vma, *prev, *last;
74115
74116 + /*
74117 + * mm->mmap_sem is required to protect against another thread
74118 + * changing the mappings in case we sleep.
74119 + */
74120 + verify_mm_writelocked(mm);
74121 +
74122 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74123 return -EINVAL;
74124
74125 @@ -2144,6 +2548,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74126 /* Fix up all other VM information */
74127 remove_vma_list(mm, vma);
74128
74129 + track_exec_limit(mm, start, end, 0UL);
74130 +
74131 return 0;
74132 }
74133
74134 @@ -2152,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
74135 int ret;
74136 struct mm_struct *mm = current->mm;
74137
74138 +
74139 +#ifdef CONFIG_PAX_SEGMEXEC
74140 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74141 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74142 + return -EINVAL;
74143 +#endif
74144 +
74145 down_write(&mm->mmap_sem);
74146 ret = do_munmap(mm, start, len);
74147 up_write(&mm->mmap_sem);
74148 @@ -2165,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74149 return vm_munmap(addr, len);
74150 }
74151
74152 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74153 -{
74154 -#ifdef CONFIG_DEBUG_VM
74155 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74156 - WARN_ON(1);
74157 - up_read(&mm->mmap_sem);
74158 - }
74159 -#endif
74160 -}
74161 -
74162 /*
74163 * this is really a simplified "do_mmap". it only handles
74164 * anonymous maps. eventually we may be able to do some
74165 @@ -2188,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74166 struct rb_node ** rb_link, * rb_parent;
74167 pgoff_t pgoff = addr >> PAGE_SHIFT;
74168 int error;
74169 + unsigned long charged;
74170
74171 len = PAGE_ALIGN(len);
74172 if (!len)
74173 @@ -2195,16 +2599,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74174
74175 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74176
74177 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74178 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74179 + flags &= ~VM_EXEC;
74180 +
74181 +#ifdef CONFIG_PAX_MPROTECT
74182 + if (mm->pax_flags & MF_PAX_MPROTECT)
74183 + flags &= ~VM_MAYEXEC;
74184 +#endif
74185 +
74186 + }
74187 +#endif
74188 +
74189 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74190 if (error & ~PAGE_MASK)
74191 return error;
74192
74193 + charged = len >> PAGE_SHIFT;
74194 +
74195 /*
74196 * mlock MCL_FUTURE?
74197 */
74198 if (mm->def_flags & VM_LOCKED) {
74199 unsigned long locked, lock_limit;
74200 - locked = len >> PAGE_SHIFT;
74201 + locked = charged;
74202 locked += mm->locked_vm;
74203 lock_limit = rlimit(RLIMIT_MEMLOCK);
74204 lock_limit >>= PAGE_SHIFT;
74205 @@ -2221,21 +2639,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74206 /*
74207 * Clear old maps. this also does some error checking for us
74208 */
74209 - munmap_back:
74210 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
74211 if (do_munmap(mm, addr, len))
74212 return -ENOMEM;
74213 - goto munmap_back;
74214 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
74215 }
74216
74217 /* Check against address space limits *after* clearing old maps... */
74218 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74219 + if (!may_expand_vm(mm, charged))
74220 return -ENOMEM;
74221
74222 if (mm->map_count > sysctl_max_map_count)
74223 return -ENOMEM;
74224
74225 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74226 + if (security_vm_enough_memory_mm(mm, charged))
74227 return -ENOMEM;
74228
74229 /* Can we just expand an old private anonymous mapping? */
74230 @@ -2249,7 +2666,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74231 */
74232 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74233 if (!vma) {
74234 - vm_unacct_memory(len >> PAGE_SHIFT);
74235 + vm_unacct_memory(charged);
74236 return -ENOMEM;
74237 }
74238
74239 @@ -2263,11 +2680,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74240 vma_link(mm, vma, prev, rb_link, rb_parent);
74241 out:
74242 perf_event_mmap(vma);
74243 - mm->total_vm += len >> PAGE_SHIFT;
74244 + mm->total_vm += charged;
74245 if (flags & VM_LOCKED) {
74246 if (!mlock_vma_pages_range(vma, addr, addr + len))
74247 - mm->locked_vm += (len >> PAGE_SHIFT);
74248 + mm->locked_vm += charged;
74249 }
74250 + track_exec_limit(mm, addr, addr + len, flags);
74251 return addr;
74252 }
74253
74254 @@ -2325,6 +2743,7 @@ void exit_mmap(struct mm_struct *mm)
74255 while (vma) {
74256 if (vma->vm_flags & VM_ACCOUNT)
74257 nr_accounted += vma_pages(vma);
74258 + vma->vm_mirror = NULL;
74259 vma = remove_vma(vma);
74260 }
74261 vm_unacct_memory(nr_accounted);
74262 @@ -2341,6 +2760,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
74263 struct vm_area_struct *prev;
74264 struct rb_node **rb_link, *rb_parent;
74265
74266 +#ifdef CONFIG_PAX_SEGMEXEC
74267 + struct vm_area_struct *vma_m = NULL;
74268 +#endif
74269 +
74270 + if (security_mmap_addr(vma->vm_start))
74271 + return -EPERM;
74272 +
74273 /*
74274 * The vm_pgoff of a purely anonymous vma should be irrelevant
74275 * until its first write fault, when page's anon_vma and index
74276 @@ -2364,7 +2790,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
74277 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74278 return -ENOMEM;
74279
74280 +#ifdef CONFIG_PAX_SEGMEXEC
74281 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74282 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74283 + if (!vma_m)
74284 + return -ENOMEM;
74285 + }
74286 +#endif
74287 +
74288 vma_link(mm, vma, prev, rb_link, rb_parent);
74289 +
74290 +#ifdef CONFIG_PAX_SEGMEXEC
74291 + if (vma_m)
74292 + BUG_ON(pax_mirror_vma(vma_m, vma));
74293 +#endif
74294 +
74295 return 0;
74296 }
74297
74298 @@ -2384,6 +2824,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74299 struct mempolicy *pol;
74300 bool faulted_in_anon_vma = true;
74301
74302 + BUG_ON(vma->vm_mirror);
74303 +
74304 /*
74305 * If anonymous vma has not yet been faulted, update new pgoff
74306 * to match new location, to increase its chance of merging.
74307 @@ -2450,6 +2892,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74308 return NULL;
74309 }
74310
74311 +#ifdef CONFIG_PAX_SEGMEXEC
74312 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74313 +{
74314 + struct vm_area_struct *prev_m;
74315 + struct rb_node **rb_link_m, *rb_parent_m;
74316 + struct mempolicy *pol_m;
74317 +
74318 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74319 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74320 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74321 + *vma_m = *vma;
74322 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74323 + if (anon_vma_clone(vma_m, vma))
74324 + return -ENOMEM;
74325 + pol_m = vma_policy(vma_m);
74326 + mpol_get(pol_m);
74327 + vma_set_policy(vma_m, pol_m);
74328 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74329 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74330 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74331 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74332 + if (vma_m->vm_file)
74333 + get_file(vma_m->vm_file);
74334 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74335 + vma_m->vm_ops->open(vma_m);
74336 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
74337 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74338 + vma_m->vm_mirror = vma;
74339 + vma->vm_mirror = vma_m;
74340 + return 0;
74341 +}
74342 +#endif
74343 +
74344 /*
74345 * Return true if the calling process may expand its vm space by the passed
74346 * number of pages
74347 @@ -2461,6 +2936,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74348
74349 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74350
74351 +#ifdef CONFIG_PAX_RANDMMAP
74352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74353 + cur -= mm->brk_gap;
74354 +#endif
74355 +
74356 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74357 if (cur + npages > lim)
74358 return 0;
74359 return 1;
74360 @@ -2531,6 +3012,22 @@ int install_special_mapping(struct mm_struct *mm,
74361 vma->vm_start = addr;
74362 vma->vm_end = addr + len;
74363
74364 +#ifdef CONFIG_PAX_MPROTECT
74365 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74366 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74367 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74368 + return -EPERM;
74369 + if (!(vm_flags & VM_EXEC))
74370 + vm_flags &= ~VM_MAYEXEC;
74371 +#else
74372 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74373 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74374 +#endif
74375 + else
74376 + vm_flags &= ~VM_MAYWRITE;
74377 + }
74378 +#endif
74379 +
74380 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74381 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74382
74383 diff --git a/mm/mprotect.c b/mm/mprotect.c
74384 index a409926..8b32e6d 100644
74385 --- a/mm/mprotect.c
74386 +++ b/mm/mprotect.c
74387 @@ -23,10 +23,17 @@
74388 #include <linux/mmu_notifier.h>
74389 #include <linux/migrate.h>
74390 #include <linux/perf_event.h>
74391 +
74392 +#ifdef CONFIG_PAX_MPROTECT
74393 +#include <linux/elf.h>
74394 +#include <linux/binfmts.h>
74395 +#endif
74396 +
74397 #include <asm/uaccess.h>
74398 #include <asm/pgtable.h>
74399 #include <asm/cacheflush.h>
74400 #include <asm/tlbflush.h>
74401 +#include <asm/mmu_context.h>
74402
74403 #ifndef pgprot_modify
74404 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74405 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74406 flush_tlb_range(vma, start, end);
74407 }
74408
74409 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74410 +/* called while holding the mmap semaphor for writing except stack expansion */
74411 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74412 +{
74413 + unsigned long oldlimit, newlimit = 0UL;
74414 +
74415 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74416 + return;
74417 +
74418 + spin_lock(&mm->page_table_lock);
74419 + oldlimit = mm->context.user_cs_limit;
74420 + if ((prot & VM_EXEC) && oldlimit < end)
74421 + /* USER_CS limit moved up */
74422 + newlimit = end;
74423 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74424 + /* USER_CS limit moved down */
74425 + newlimit = start;
74426 +
74427 + if (newlimit) {
74428 + mm->context.user_cs_limit = newlimit;
74429 +
74430 +#ifdef CONFIG_SMP
74431 + wmb();
74432 + cpus_clear(mm->context.cpu_user_cs_mask);
74433 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74434 +#endif
74435 +
74436 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74437 + }
74438 + spin_unlock(&mm->page_table_lock);
74439 + if (newlimit == end) {
74440 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74441 +
74442 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74443 + if (is_vm_hugetlb_page(vma))
74444 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74445 + else
74446 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74447 + }
74448 +}
74449 +#endif
74450 +
74451 int
74452 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74453 unsigned long start, unsigned long end, unsigned long newflags)
74454 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74455 int error;
74456 int dirty_accountable = 0;
74457
74458 +#ifdef CONFIG_PAX_SEGMEXEC
74459 + struct vm_area_struct *vma_m = NULL;
74460 + unsigned long start_m, end_m;
74461 +
74462 + start_m = start + SEGMEXEC_TASK_SIZE;
74463 + end_m = end + SEGMEXEC_TASK_SIZE;
74464 +#endif
74465 +
74466 if (newflags == oldflags) {
74467 *pprev = vma;
74468 return 0;
74469 }
74470
74471 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74472 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74473 +
74474 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74475 + return -ENOMEM;
74476 +
74477 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74478 + return -ENOMEM;
74479 + }
74480 +
74481 /*
74482 * If we make a private mapping writable we increase our commit;
74483 * but (without finer accounting) cannot reduce our commit if we
74484 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74485 }
74486 }
74487
74488 +#ifdef CONFIG_PAX_SEGMEXEC
74489 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74490 + if (start != vma->vm_start) {
74491 + error = split_vma(mm, vma, start, 1);
74492 + if (error)
74493 + goto fail;
74494 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74495 + *pprev = (*pprev)->vm_next;
74496 + }
74497 +
74498 + if (end != vma->vm_end) {
74499 + error = split_vma(mm, vma, end, 0);
74500 + if (error)
74501 + goto fail;
74502 + }
74503 +
74504 + if (pax_find_mirror_vma(vma)) {
74505 + error = __do_munmap(mm, start_m, end_m - start_m);
74506 + if (error)
74507 + goto fail;
74508 + } else {
74509 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74510 + if (!vma_m) {
74511 + error = -ENOMEM;
74512 + goto fail;
74513 + }
74514 + vma->vm_flags = newflags;
74515 + error = pax_mirror_vma(vma_m, vma);
74516 + if (error) {
74517 + vma->vm_flags = oldflags;
74518 + goto fail;
74519 + }
74520 + }
74521 + }
74522 +#endif
74523 +
74524 /*
74525 * First try to merge with previous and/or next vma.
74526 */
74527 @@ -204,9 +307,21 @@ success:
74528 * vm_flags and vm_page_prot are protected by the mmap_sem
74529 * held in write mode.
74530 */
74531 +
74532 +#ifdef CONFIG_PAX_SEGMEXEC
74533 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74534 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74535 +#endif
74536 +
74537 vma->vm_flags = newflags;
74538 +
74539 +#ifdef CONFIG_PAX_MPROTECT
74540 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74541 + mm->binfmt->handle_mprotect(vma, newflags);
74542 +#endif
74543 +
74544 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74545 - vm_get_page_prot(newflags));
74546 + vm_get_page_prot(vma->vm_flags));
74547
74548 if (vma_wants_writenotify(vma)) {
74549 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74550 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74551 end = start + len;
74552 if (end <= start)
74553 return -ENOMEM;
74554 +
74555 +#ifdef CONFIG_PAX_SEGMEXEC
74556 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74557 + if (end > SEGMEXEC_TASK_SIZE)
74558 + return -EINVAL;
74559 + } else
74560 +#endif
74561 +
74562 + if (end > TASK_SIZE)
74563 + return -EINVAL;
74564 +
74565 if (!arch_validate_prot(prot))
74566 return -EINVAL;
74567
74568 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74569 /*
74570 * Does the application expect PROT_READ to imply PROT_EXEC:
74571 */
74572 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74573 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74574 prot |= PROT_EXEC;
74575
74576 vm_flags = calc_vm_prot_bits(prot);
74577 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74578 if (start > vma->vm_start)
74579 prev = vma;
74580
74581 +#ifdef CONFIG_PAX_MPROTECT
74582 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74583 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74584 +#endif
74585 +
74586 for (nstart = start ; ; ) {
74587 unsigned long newflags;
74588
74589 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74590
74591 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74592 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74593 + if (prot & (PROT_WRITE | PROT_EXEC))
74594 + gr_log_rwxmprotect(vma->vm_file);
74595 +
74596 + error = -EACCES;
74597 + goto out;
74598 + }
74599 +
74600 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74601 error = -EACCES;
74602 goto out;
74603 }
74604 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74605 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74606 if (error)
74607 goto out;
74608 +
74609 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74610 +
74611 nstart = tmp;
74612
74613 if (nstart < prev->vm_end)
74614 diff --git a/mm/mremap.c b/mm/mremap.c
74615 index 1b61c2d..1cc0e3c 100644
74616 --- a/mm/mremap.c
74617 +++ b/mm/mremap.c
74618 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74619 continue;
74620 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74621 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74622 +
74623 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74624 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74625 + pte = pte_exprotect(pte);
74626 +#endif
74627 +
74628 set_pte_at(mm, new_addr, new_pte, pte);
74629 }
74630
74631 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74632 if (is_vm_hugetlb_page(vma))
74633 goto Einval;
74634
74635 +#ifdef CONFIG_PAX_SEGMEXEC
74636 + if (pax_find_mirror_vma(vma))
74637 + goto Einval;
74638 +#endif
74639 +
74640 /* We can't remap across vm area boundaries */
74641 if (old_len > vma->vm_end - addr)
74642 goto Efault;
74643 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
74644 unsigned long ret = -EINVAL;
74645 unsigned long charged = 0;
74646 unsigned long map_flags;
74647 + unsigned long pax_task_size = TASK_SIZE;
74648
74649 if (new_addr & ~PAGE_MASK)
74650 goto out;
74651
74652 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74653 +#ifdef CONFIG_PAX_SEGMEXEC
74654 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74655 + pax_task_size = SEGMEXEC_TASK_SIZE;
74656 +#endif
74657 +
74658 + pax_task_size -= PAGE_SIZE;
74659 +
74660 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74661 goto out;
74662
74663 /* Check if the location we're moving into overlaps the
74664 * old location at all, and fail if it does.
74665 */
74666 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74667 - goto out;
74668 -
74669 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74670 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74671 goto out;
74672
74673 ret = do_munmap(mm, new_addr, new_len);
74674 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74675 struct vm_area_struct *vma;
74676 unsigned long ret = -EINVAL;
74677 unsigned long charged = 0;
74678 + unsigned long pax_task_size = TASK_SIZE;
74679
74680 down_write(&current->mm->mmap_sem);
74681
74682 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74683 if (!new_len)
74684 goto out;
74685
74686 +#ifdef CONFIG_PAX_SEGMEXEC
74687 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74688 + pax_task_size = SEGMEXEC_TASK_SIZE;
74689 +#endif
74690 +
74691 + pax_task_size -= PAGE_SIZE;
74692 +
74693 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74694 + old_len > pax_task_size || addr > pax_task_size-old_len)
74695 + goto out;
74696 +
74697 if (flags & MREMAP_FIXED) {
74698 if (flags & MREMAP_MAYMOVE)
74699 ret = mremap_to(addr, old_len, new_addr, new_len);
74700 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74701 addr + new_len);
74702 }
74703 ret = addr;
74704 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74705 goto out;
74706 }
74707 }
74708 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74709 goto out;
74710 }
74711
74712 + map_flags = vma->vm_flags;
74713 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74714 + if (!(ret & ~PAGE_MASK)) {
74715 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74716 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74717 + }
74718 }
74719 out:
74720 if (ret & ~PAGE_MASK)
74721 diff --git a/mm/nommu.c b/mm/nommu.c
74722 index 45131b4..c521665 100644
74723 --- a/mm/nommu.c
74724 +++ b/mm/nommu.c
74725 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74726 int sysctl_overcommit_ratio = 50; /* default is 50% */
74727 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74728 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74729 -int heap_stack_gap = 0;
74730
74731 atomic_long_t mmap_pages_allocated;
74732
74733 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74734 EXPORT_SYMBOL(find_vma);
74735
74736 /*
74737 - * find a VMA
74738 - * - we don't extend stack VMAs under NOMMU conditions
74739 - */
74740 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74741 -{
74742 - return find_vma(mm, addr);
74743 -}
74744 -
74745 -/*
74746 * expand a stack to a given address
74747 * - not supported under NOMMU conditions
74748 */
74749 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74750
74751 /* most fields are the same, copy all, and then fixup */
74752 *new = *vma;
74753 + INIT_LIST_HEAD(&new->anon_vma_chain);
74754 *region = *vma->vm_region;
74755 new->vm_region = region;
74756
74757 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74758 index 7e208f0..d96f232 100644
74759 --- a/mm/page_alloc.c
74760 +++ b/mm/page_alloc.c
74761 @@ -340,7 +340,7 @@ out:
74762 * This usage means that zero-order pages may not be compound.
74763 */
74764
74765 -static void free_compound_page(struct page *page)
74766 +void free_compound_page(struct page *page)
74767 {
74768 __free_pages_ok(page, compound_order(page));
74769 }
74770 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74771 int i;
74772 int bad = 0;
74773
74774 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74775 + unsigned long index = 1UL << order;
74776 +#endif
74777 +
74778 trace_mm_page_free(page, order);
74779 kmemcheck_free_shadow(page, order);
74780
74781 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74782 debug_check_no_obj_freed(page_address(page),
74783 PAGE_SIZE << order);
74784 }
74785 +
74786 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74787 + for (; index; --index)
74788 + sanitize_highpage(page + index - 1);
74789 +#endif
74790 +
74791 arch_free_page(page, order);
74792 kernel_map_pages(page, 1 << order, 0);
74793
74794 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74795 arch_alloc_page(page, order);
74796 kernel_map_pages(page, 1 << order, 1);
74797
74798 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74799 if (gfp_flags & __GFP_ZERO)
74800 prep_zero_page(page, order, gfp_flags);
74801 +#endif
74802
74803 if (order && (gfp_flags & __GFP_COMP))
74804 prep_compound_page(page, order);
74805 @@ -3703,7 +3715,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74806 unsigned long pfn;
74807
74808 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74809 +#ifdef CONFIG_X86_32
74810 + /* boot failures in VMware 8 on 32bit vanilla since
74811 + this change */
74812 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74813 +#else
74814 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74815 +#endif
74816 return 1;
74817 }
74818 return 0;
74819 diff --git a/mm/percpu.c b/mm/percpu.c
74820 index ddc5efb..f632d2c 100644
74821 --- a/mm/percpu.c
74822 +++ b/mm/percpu.c
74823 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74824 static unsigned int pcpu_high_unit_cpu __read_mostly;
74825
74826 /* the address of the first chunk which starts with the kernel static area */
74827 -void *pcpu_base_addr __read_mostly;
74828 +void *pcpu_base_addr __read_only;
74829 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74830
74831 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74832 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74833 index 926b466..b23df53 100644
74834 --- a/mm/process_vm_access.c
74835 +++ b/mm/process_vm_access.c
74836 @@ -13,6 +13,7 @@
74837 #include <linux/uio.h>
74838 #include <linux/sched.h>
74839 #include <linux/highmem.h>
74840 +#include <linux/security.h>
74841 #include <linux/ptrace.h>
74842 #include <linux/slab.h>
74843 #include <linux/syscalls.h>
74844 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74845 size_t iov_l_curr_offset = 0;
74846 ssize_t iov_len;
74847
74848 + return -ENOSYS; // PaX: until properly audited
74849 +
74850 /*
74851 * Work out how many pages of struct pages we're going to need
74852 * when eventually calling get_user_pages
74853 */
74854 for (i = 0; i < riovcnt; i++) {
74855 iov_len = rvec[i].iov_len;
74856 - if (iov_len > 0) {
74857 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74858 - + iov_len)
74859 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74860 - / PAGE_SIZE + 1;
74861 - nr_pages = max(nr_pages, nr_pages_iov);
74862 - }
74863 + if (iov_len <= 0)
74864 + continue;
74865 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74866 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74867 + nr_pages = max(nr_pages, nr_pages_iov);
74868 }
74869
74870 if (nr_pages == 0)
74871 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74872 goto free_proc_pages;
74873 }
74874
74875 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74876 + rc = -EPERM;
74877 + goto put_task_struct;
74878 + }
74879 +
74880 mm = mm_access(task, PTRACE_MODE_ATTACH);
74881 if (!mm || IS_ERR(mm)) {
74882 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74883 diff --git a/mm/rmap.c b/mm/rmap.c
74884 index 2ee1ef0..2e175ba 100644
74885 --- a/mm/rmap.c
74886 +++ b/mm/rmap.c
74887 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74888 struct anon_vma *anon_vma = vma->anon_vma;
74889 struct anon_vma_chain *avc;
74890
74891 +#ifdef CONFIG_PAX_SEGMEXEC
74892 + struct anon_vma_chain *avc_m = NULL;
74893 +#endif
74894 +
74895 might_sleep();
74896 if (unlikely(!anon_vma)) {
74897 struct mm_struct *mm = vma->vm_mm;
74898 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74899 if (!avc)
74900 goto out_enomem;
74901
74902 +#ifdef CONFIG_PAX_SEGMEXEC
74903 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74904 + if (!avc_m)
74905 + goto out_enomem_free_avc;
74906 +#endif
74907 +
74908 anon_vma = find_mergeable_anon_vma(vma);
74909 allocated = NULL;
74910 if (!anon_vma) {
74911 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74912 /* page_table_lock to protect against threads */
74913 spin_lock(&mm->page_table_lock);
74914 if (likely(!vma->anon_vma)) {
74915 +
74916 +#ifdef CONFIG_PAX_SEGMEXEC
74917 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74918 +
74919 + if (vma_m) {
74920 + BUG_ON(vma_m->anon_vma);
74921 + vma_m->anon_vma = anon_vma;
74922 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74923 + avc_m = NULL;
74924 + }
74925 +#endif
74926 +
74927 vma->anon_vma = anon_vma;
74928 anon_vma_chain_link(vma, avc, anon_vma);
74929 allocated = NULL;
74930 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74931
74932 if (unlikely(allocated))
74933 put_anon_vma(allocated);
74934 +
74935 +#ifdef CONFIG_PAX_SEGMEXEC
74936 + if (unlikely(avc_m))
74937 + anon_vma_chain_free(avc_m);
74938 +#endif
74939 +
74940 if (unlikely(avc))
74941 anon_vma_chain_free(avc);
74942 }
74943 return 0;
74944
74945 out_enomem_free_avc:
74946 +
74947 +#ifdef CONFIG_PAX_SEGMEXEC
74948 + if (avc_m)
74949 + anon_vma_chain_free(avc_m);
74950 +#endif
74951 +
74952 anon_vma_chain_free(avc);
74953 out_enomem:
74954 return -ENOMEM;
74955 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74956 * Attach the anon_vmas from src to dst.
74957 * Returns 0 on success, -ENOMEM on failure.
74958 */
74959 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74960 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74961 {
74962 struct anon_vma_chain *avc, *pavc;
74963 struct anon_vma *root = NULL;
74964 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74965 * the corresponding VMA in the parent process is attached to.
74966 * Returns 0 on success, non-zero on failure.
74967 */
74968 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74969 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74970 {
74971 struct anon_vma_chain *avc;
74972 struct anon_vma *anon_vma;
74973 diff --git a/mm/shmem.c b/mm/shmem.c
74974 index 50c5b8f..0bc87f7 100644
74975 --- a/mm/shmem.c
74976 +++ b/mm/shmem.c
74977 @@ -31,7 +31,7 @@
74978 #include <linux/export.h>
74979 #include <linux/swap.h>
74980
74981 -static struct vfsmount *shm_mnt;
74982 +struct vfsmount *shm_mnt;
74983
74984 #ifdef CONFIG_SHMEM
74985 /*
74986 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74987 #define BOGO_DIRENT_SIZE 20
74988
74989 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74990 -#define SHORT_SYMLINK_LEN 128
74991 +#define SHORT_SYMLINK_LEN 64
74992
74993 /*
74994 * shmem_fallocate and shmem_writepage communicate via inode->i_private
74995 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
74996 static int shmem_xattr_validate(const char *name)
74997 {
74998 struct { const char *prefix; size_t len; } arr[] = {
74999 +
75000 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75001 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75002 +#endif
75003 +
75004 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75005 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75006 };
75007 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75008 if (err)
75009 return err;
75010
75011 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75012 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75013 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75014 + return -EOPNOTSUPP;
75015 + if (size > 8)
75016 + return -EINVAL;
75017 + }
75018 +#endif
75019 +
75020 return simple_xattr_set(&info->xattrs, name, value, size, flags);
75021 }
75022
75023 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75024 int err = -ENOMEM;
75025
75026 /* Round up to L1_CACHE_BYTES to resist false sharing */
75027 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75028 - L1_CACHE_BYTES), GFP_KERNEL);
75029 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75030 if (!sbinfo)
75031 return -ENOMEM;
75032
75033 diff --git a/mm/slab.c b/mm/slab.c
75034 index 33d3363..69ffb8a 100644
75035 --- a/mm/slab.c
75036 +++ b/mm/slab.c
75037 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75038
75039 /* Legal flag mask for kmem_cache_create(). */
75040 #if DEBUG
75041 -# define CREATE_MASK (SLAB_RED_ZONE | \
75042 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75043 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75044 SLAB_CACHE_DMA | \
75045 SLAB_STORE_USER | \
75046 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75047 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75048 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75049 #else
75050 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75051 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75052 SLAB_CACHE_DMA | \
75053 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75054 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75055 @@ -322,7 +322,7 @@ struct kmem_list3 {
75056 * Need this for bootstrapping a per node allocator.
75057 */
75058 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75059 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75060 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75061 #define CACHE_CACHE 0
75062 #define SIZE_AC MAX_NUMNODES
75063 #define SIZE_L3 (2 * MAX_NUMNODES)
75064 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75065 if ((x)->max_freeable < i) \
75066 (x)->max_freeable = i; \
75067 } while (0)
75068 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75069 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75070 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75071 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75072 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75073 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75074 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75075 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75076 #else
75077 #define STATS_INC_ACTIVE(x) do { } while (0)
75078 #define STATS_DEC_ACTIVE(x) do { } while (0)
75079 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75080 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75081 */
75082 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75083 - const struct slab *slab, void *obj)
75084 + const struct slab *slab, const void *obj)
75085 {
75086 u32 offset = (obj - slab->s_mem);
75087 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75088 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
75089 struct cache_names {
75090 char *name;
75091 char *name_dma;
75092 + char *name_usercopy;
75093 };
75094
75095 static struct cache_names __initdata cache_names[] = {
75096 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75097 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75098 #include <linux/kmalloc_sizes.h>
75099 - {NULL,}
75100 + {NULL}
75101 #undef CACHE
75102 };
75103
75104 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75105 if (unlikely(gfpflags & GFP_DMA))
75106 return csizep->cs_dmacachep;
75107 #endif
75108 +
75109 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75110 + if (unlikely(gfpflags & GFP_USERCOPY))
75111 + return csizep->cs_usercopycachep;
75112 +#endif
75113 +
75114 return csizep->cs_cachep;
75115 }
75116
75117 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
75118 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
75119 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
75120 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75121 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75122 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75123 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
75124
75125 if (INDEX_AC != INDEX_L3) {
75126 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
75127 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
75128 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
75129 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75130 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75131 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75132 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
75133 }
75134
75135 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
75136 sizes->cs_cachep->size = sizes->cs_size;
75137 sizes->cs_cachep->object_size = sizes->cs_size;
75138 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75139 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75140 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75141 list_add(&sizes->cs_cachep->list, &slab_caches);
75142 }
75143 #ifdef CONFIG_ZONE_DMA
75144 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
75145 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
75146 list_add(&sizes->cs_dmacachep->list, &slab_caches);
75147 #endif
75148 +
75149 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75150 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
75151 + sizes->cs_usercopycachep->name = names->name_dma;
75152 + sizes->cs_usercopycachep->size = sizes->cs_size;
75153 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
75154 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
75155 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
75156 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
75157 +#endif
75158 +
75159 sizes++;
75160 names++;
75161 }
75162 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
75163 }
75164 /* cpu stats */
75165 {
75166 - unsigned long allochit = atomic_read(&cachep->allochit);
75167 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75168 - unsigned long freehit = atomic_read(&cachep->freehit);
75169 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75170 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75171 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75172 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75173 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75174
75175 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75176 allochit, allocmiss, freehit, freemiss);
75177 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
75178 {
75179 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75180 #ifdef CONFIG_DEBUG_SLAB_LEAK
75181 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75182 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75183 #endif
75184 return 0;
75185 }
75186 module_init(slab_proc_init);
75187 #endif
75188
75189 +bool is_usercopy_object(const void *ptr)
75190 +{
75191 + struct page *page;
75192 + struct kmem_cache *cachep;
75193 +
75194 + if (ZERO_OR_NULL_PTR(ptr))
75195 + return false;
75196 +
75197 + if (!slab_is_available())
75198 + return false;
75199 +
75200 + if (!virt_addr_valid(ptr))
75201 + return false;
75202 +
75203 + page = virt_to_head_page(ptr);
75204 +
75205 + if (!PageSlab(page))
75206 + return false;
75207 +
75208 + cachep = page->slab_cache;
75209 + return cachep->flags & SLAB_USERCOPY;
75210 +}
75211 +
75212 +#ifdef CONFIG_PAX_USERCOPY
75213 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75214 +{
75215 + struct page *page;
75216 + struct kmem_cache *cachep;
75217 + struct slab *slabp;
75218 + unsigned int objnr;
75219 + unsigned long offset;
75220 +
75221 + if (ZERO_OR_NULL_PTR(ptr))
75222 + return "<null>";
75223 +
75224 + if (!virt_addr_valid(ptr))
75225 + return NULL;
75226 +
75227 + page = virt_to_head_page(ptr);
75228 +
75229 + if (!PageSlab(page))
75230 + return NULL;
75231 +
75232 + cachep = page->slab_cache;
75233 + if (!(cachep->flags & SLAB_USERCOPY))
75234 + return cachep->name;
75235 +
75236 + slabp = page->slab_page;
75237 + objnr = obj_to_index(cachep, slabp, ptr);
75238 + BUG_ON(objnr >= cachep->num);
75239 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75240 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75241 + return NULL;
75242 +
75243 + return cachep->name;
75244 +}
75245 +#endif
75246 +
75247 /**
75248 * ksize - get the actual amount of memory allocated for a given object
75249 * @objp: Pointer to the object
75250 diff --git a/mm/slab_common.c b/mm/slab_common.c
75251 index 069a24e6..226a310 100644
75252 --- a/mm/slab_common.c
75253 +++ b/mm/slab_common.c
75254 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
75255 err = __kmem_cache_create(s, flags);
75256 if (!err) {
75257
75258 - s->refcount = 1;
75259 + atomic_set(&s->refcount, 1);
75260 list_add(&s->list, &slab_caches);
75261
75262 } else {
75263 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
75264 {
75265 get_online_cpus();
75266 mutex_lock(&slab_mutex);
75267 - s->refcount--;
75268 - if (!s->refcount) {
75269 + if (atomic_dec_and_test(&s->refcount)) {
75270 list_del(&s->list);
75271
75272 if (!__kmem_cache_shutdown(s)) {
75273 diff --git a/mm/slob.c b/mm/slob.c
75274 index 1e921c5..7042228 100644
75275 --- a/mm/slob.c
75276 +++ b/mm/slob.c
75277 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75278 /*
75279 * Return the size of a slob block.
75280 */
75281 -static slobidx_t slob_units(slob_t *s)
75282 +static slobidx_t slob_units(const slob_t *s)
75283 {
75284 if (s->units > 0)
75285 return s->units;
75286 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75287 /*
75288 * Return the next free slob block pointer after this one.
75289 */
75290 -static slob_t *slob_next(slob_t *s)
75291 +static slob_t *slob_next(const slob_t *s)
75292 {
75293 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75294 slobidx_t next;
75295 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75296 /*
75297 * Returns true if s is the last free block in its page.
75298 */
75299 -static int slob_last(slob_t *s)
75300 +static int slob_last(const slob_t *s)
75301 {
75302 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75303 }
75304
75305 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75306 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75307 {
75308 - void *page;
75309 + struct page *page;
75310
75311 #ifdef CONFIG_NUMA
75312 if (node != NUMA_NO_NODE)
75313 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75314 if (!page)
75315 return NULL;
75316
75317 - return page_address(page);
75318 + __SetPageSlab(page);
75319 + return page;
75320 }
75321
75322 -static void slob_free_pages(void *b, int order)
75323 +static void slob_free_pages(struct page *sp, int order)
75324 {
75325 if (current->reclaim_state)
75326 current->reclaim_state->reclaimed_slab += 1 << order;
75327 - free_pages((unsigned long)b, order);
75328 + __ClearPageSlab(sp);
75329 + reset_page_mapcount(sp);
75330 + sp->private = 0;
75331 + __free_pages(sp, order);
75332 }
75333
75334 /*
75335 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75336
75337 /* Not enough space: must allocate a new page */
75338 if (!b) {
75339 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75340 - if (!b)
75341 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75342 + if (!sp)
75343 return NULL;
75344 - sp = virt_to_page(b);
75345 - __SetPageSlab(sp);
75346 + b = page_address(sp);
75347
75348 spin_lock_irqsave(&slob_lock, flags);
75349 sp->units = SLOB_UNITS(PAGE_SIZE);
75350 sp->freelist = b;
75351 + sp->private = 0;
75352 INIT_LIST_HEAD(&sp->list);
75353 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75354 set_slob_page_free(sp, slob_list);
75355 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75356 if (slob_page_free(sp))
75357 clear_slob_page_free(sp);
75358 spin_unlock_irqrestore(&slob_lock, flags);
75359 - __ClearPageSlab(sp);
75360 - reset_page_mapcount(sp);
75361 - slob_free_pages(b, 0);
75362 + slob_free_pages(sp, 0);
75363 return;
75364 }
75365
75366 @@ -426,11 +428,10 @@ out:
75367 */
75368
75369 static __always_inline void *
75370 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75371 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
75372 {
75373 - unsigned int *m;
75374 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75375 - void *ret;
75376 + slob_t *m;
75377 + void *ret = NULL;
75378
75379 gfp &= gfp_allowed_mask;
75380
75381 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75382
75383 if (!m)
75384 return NULL;
75385 - *m = size;
75386 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75387 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75388 + m[0].units = size;
75389 + m[1].units = align;
75390 ret = (void *)m + align;
75391
75392 trace_kmalloc_node(caller, ret,
75393 size, size + align, gfp, node);
75394 } else {
75395 unsigned int order = get_order(size);
75396 + struct page *page;
75397
75398 if (likely(order))
75399 gfp |= __GFP_COMP;
75400 - ret = slob_new_pages(gfp, order, node);
75401 - if (ret) {
75402 - struct page *page;
75403 - page = virt_to_page(ret);
75404 + page = slob_new_pages(gfp, order, node);
75405 + if (page) {
75406 + ret = page_address(page);
75407 page->private = size;
75408 }
75409
75410 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75411 size, PAGE_SIZE << order, gfp, node);
75412 }
75413
75414 - kmemleak_alloc(ret, size, 1, gfp);
75415 + return ret;
75416 +}
75417 +
75418 +static __always_inline void *
75419 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75420 +{
75421 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75422 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
75423 +
75424 + if (!ZERO_OR_NULL_PTR(ret))
75425 + kmemleak_alloc(ret, size, 1, gfp);
75426 return ret;
75427 }
75428
75429 @@ -501,15 +515,91 @@ void kfree(const void *block)
75430 kmemleak_free(block);
75431
75432 sp = virt_to_page(block);
75433 - if (PageSlab(sp)) {
75434 + VM_BUG_ON(!PageSlab(sp));
75435 + if (!sp->private) {
75436 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75437 - unsigned int *m = (unsigned int *)(block - align);
75438 - slob_free(m, *m + align);
75439 - } else
75440 + slob_t *m = (slob_t *)(block - align);
75441 + slob_free(m, m[0].units + align);
75442 + } else {
75443 + __ClearPageSlab(sp);
75444 + reset_page_mapcount(sp);
75445 + sp->private = 0;
75446 put_page(sp);
75447 + }
75448 }
75449 EXPORT_SYMBOL(kfree);
75450
75451 +bool is_usercopy_object(const void *ptr)
75452 +{
75453 + if (!slab_is_available())
75454 + return false;
75455 +
75456 + // PAX: TODO
75457 +
75458 + return false;
75459 +}
75460 +
75461 +#ifdef CONFIG_PAX_USERCOPY
75462 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75463 +{
75464 + struct page *page;
75465 + const slob_t *free;
75466 + const void *base;
75467 + unsigned long flags;
75468 +
75469 + if (ZERO_OR_NULL_PTR(ptr))
75470 + return "<null>";
75471 +
75472 + if (!virt_addr_valid(ptr))
75473 + return NULL;
75474 +
75475 + page = virt_to_head_page(ptr);
75476 + if (!PageSlab(page))
75477 + return NULL;
75478 +
75479 + if (page->private) {
75480 + base = page;
75481 + if (base <= ptr && n <= page->private - (ptr - base))
75482 + return NULL;
75483 + return "<slob>";
75484 + }
75485 +
75486 + /* some tricky double walking to find the chunk */
75487 + spin_lock_irqsave(&slob_lock, flags);
75488 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75489 + free = page->freelist;
75490 +
75491 + while (!slob_last(free) && (void *)free <= ptr) {
75492 + base = free + slob_units(free);
75493 + free = slob_next(free);
75494 + }
75495 +
75496 + while (base < (void *)free) {
75497 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75498 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75499 + int offset;
75500 +
75501 + if (ptr < base + align)
75502 + break;
75503 +
75504 + offset = ptr - base - align;
75505 + if (offset >= m) {
75506 + base += size;
75507 + continue;
75508 + }
75509 +
75510 + if (n > m - offset)
75511 + break;
75512 +
75513 + spin_unlock_irqrestore(&slob_lock, flags);
75514 + return NULL;
75515 + }
75516 +
75517 + spin_unlock_irqrestore(&slob_lock, flags);
75518 + return "<slob>";
75519 +}
75520 +#endif
75521 +
75522 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75523 size_t ksize(const void *block)
75524 {
75525 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
75526 return 0;
75527
75528 sp = virt_to_page(block);
75529 - if (PageSlab(sp)) {
75530 + VM_BUG_ON(!PageSlab(sp));
75531 + if (!sp->private) {
75532 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75533 - unsigned int *m = (unsigned int *)(block - align);
75534 - return SLOB_UNITS(*m) * SLOB_UNIT;
75535 + slob_t *m = (slob_t *)(block - align);
75536 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75537 } else
75538 return sp->private;
75539 }
75540 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
75541
75542 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75543 {
75544 - void *b;
75545 + void *b = NULL;
75546
75547 flags &= gfp_allowed_mask;
75548
75549 lockdep_trace_alloc(flags);
75550
75551 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75552 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
75553 +#else
75554 if (c->size < PAGE_SIZE) {
75555 b = slob_alloc(c->size, flags, c->align, node);
75556 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75557 SLOB_UNITS(c->size) * SLOB_UNIT,
75558 flags, node);
75559 } else {
75560 - b = slob_new_pages(flags, get_order(c->size), node);
75561 + struct page *sp;
75562 +
75563 + sp = slob_new_pages(flags, get_order(c->size), node);
75564 + if (sp) {
75565 + b = page_address(sp);
75566 + sp->private = c->size;
75567 + }
75568 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75569 PAGE_SIZE << get_order(c->size),
75570 flags, node);
75571 }
75572 +#endif
75573
75574 if (c->ctor)
75575 c->ctor(b);
75576 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75577
75578 static void __kmem_cache_free(void *b, int size)
75579 {
75580 - if (size < PAGE_SIZE)
75581 + struct page *sp;
75582 +
75583 + sp = virt_to_page(b);
75584 + BUG_ON(!PageSlab(sp));
75585 + if (!sp->private)
75586 slob_free(b, size);
75587 else
75588 - slob_free_pages(b, get_order(size));
75589 + slob_free_pages(sp, get_order(size));
75590 }
75591
75592 static void kmem_rcu_free(struct rcu_head *head)
75593 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75594
75595 void kmem_cache_free(struct kmem_cache *c, void *b)
75596 {
75597 + int size = c->size;
75598 +
75599 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75600 + if (size + c->align < PAGE_SIZE) {
75601 + size += c->align;
75602 + b -= c->align;
75603 + }
75604 +#endif
75605 +
75606 kmemleak_free_recursive(b, c->flags);
75607 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75608 struct slob_rcu *slob_rcu;
75609 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75610 - slob_rcu->size = c->size;
75611 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75612 + slob_rcu->size = size;
75613 call_rcu(&slob_rcu->head, kmem_rcu_free);
75614 } else {
75615 - __kmem_cache_free(b, c->size);
75616 + __kmem_cache_free(b, size);
75617 }
75618
75619 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75620 + trace_kfree(_RET_IP_, b);
75621 +#else
75622 trace_kmem_cache_free(_RET_IP_, b);
75623 +#endif
75624 +
75625 }
75626 EXPORT_SYMBOL(kmem_cache_free);
75627
75628 diff --git a/mm/slub.c b/mm/slub.c
75629 index a0d6984..b77d8c9 100644
75630 --- a/mm/slub.c
75631 +++ b/mm/slub.c
75632 @@ -201,7 +201,7 @@ struct track {
75633
75634 enum track_item { TRACK_ALLOC, TRACK_FREE };
75635
75636 -#ifdef CONFIG_SYSFS
75637 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75638 static int sysfs_slab_add(struct kmem_cache *);
75639 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75640 static void sysfs_slab_remove(struct kmem_cache *);
75641 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
75642 if (!t->addr)
75643 return;
75644
75645 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75646 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75647 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75648 #ifdef CONFIG_STACKTRACE
75649 {
75650 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75651
75652 page = virt_to_head_page(x);
75653
75654 + BUG_ON(!PageSlab(page));
75655 +
75656 if (kmem_cache_debug(s) && page->slab != s) {
75657 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
75658 " is from %s\n", page->slab->name, s->name);
75659 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
75660 * Merge control. If this is set then no merging of slab caches will occur.
75661 * (Could be removed. This was introduced to pacify the merge skeptics.)
75662 */
75663 -static int slub_nomerge;
75664 +static int slub_nomerge = 1;
75665
75666 /*
75667 * Calculate the order of allocation given an slab object size.
75668 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
75669 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75670 #endif
75671
75672 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75673 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75674 +#endif
75675 +
75676 static int __init setup_slub_min_order(char *str)
75677 {
75678 get_option(&str, &slub_min_order);
75679 @@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75680 return kmalloc_dma_caches[index];
75681
75682 #endif
75683 +
75684 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75685 + if (flags & SLAB_USERCOPY)
75686 + return kmalloc_usercopy_caches[index];
75687 +
75688 +#endif
75689 +
75690 return kmalloc_caches[index];
75691 }
75692
75693 @@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75694 EXPORT_SYMBOL(__kmalloc_node);
75695 #endif
75696
75697 +bool is_usercopy_object(const void *ptr)
75698 +{
75699 + struct page *page;
75700 + struct kmem_cache *s;
75701 +
75702 + if (ZERO_OR_NULL_PTR(ptr))
75703 + return false;
75704 +
75705 + if (!slab_is_available())
75706 + return false;
75707 +
75708 + if (!virt_addr_valid(ptr))
75709 + return false;
75710 +
75711 + page = virt_to_head_page(ptr);
75712 +
75713 + if (!PageSlab(page))
75714 + return false;
75715 +
75716 + s = page->slab;
75717 + return s->flags & SLAB_USERCOPY;
75718 +}
75719 +
75720 +#ifdef CONFIG_PAX_USERCOPY
75721 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75722 +{
75723 + struct page *page;
75724 + struct kmem_cache *s;
75725 + unsigned long offset;
75726 +
75727 + if (ZERO_OR_NULL_PTR(ptr))
75728 + return "<null>";
75729 +
75730 + if (!virt_addr_valid(ptr))
75731 + return NULL;
75732 +
75733 + page = virt_to_head_page(ptr);
75734 +
75735 + if (!PageSlab(page))
75736 + return NULL;
75737 +
75738 + s = page->slab;
75739 + if (!(s->flags & SLAB_USERCOPY))
75740 + return s->name;
75741 +
75742 + offset = (ptr - page_address(page)) % s->size;
75743 + if (offset <= s->object_size && n <= s->object_size - offset)
75744 + return NULL;
75745 +
75746 + return s->name;
75747 +}
75748 +#endif
75749 +
75750 size_t ksize(const void *object)
75751 {
75752 struct page *page;
75753 @@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75754 int node;
75755
75756 list_add(&s->list, &slab_caches);
75757 - s->refcount = -1;
75758 + atomic_set(&s->refcount, -1);
75759
75760 for_each_node_state(node, N_NORMAL_MEMORY) {
75761 struct kmem_cache_node *n = get_node(s, node);
75762 @@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
75763
75764 /* Caches that are not of the two-to-the-power-of size */
75765 if (KMALLOC_MIN_SIZE <= 32) {
75766 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75767 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75768 caches++;
75769 }
75770
75771 if (KMALLOC_MIN_SIZE <= 64) {
75772 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75773 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75774 caches++;
75775 }
75776
75777 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75778 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75779 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75780 caches++;
75781 }
75782
75783 @@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
75784 }
75785 }
75786 #endif
75787 +
75788 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75789 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75790 + struct kmem_cache *s = kmalloc_caches[i];
75791 +
75792 + if (s && s->size) {
75793 + char *name = kasprintf(GFP_NOWAIT,
75794 + "usercopy-kmalloc-%d", s->object_size);
75795 +
75796 + BUG_ON(!name);
75797 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75798 + s->object_size, SLAB_USERCOPY);
75799 + }
75800 + }
75801 +#endif
75802 +
75803 printk(KERN_INFO
75804 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75805 " CPUs=%d, Nodes=%d\n",
75806 @@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75807 /*
75808 * We may have set a slab to be unmergeable during bootstrap.
75809 */
75810 - if (s->refcount < 0)
75811 + if (atomic_read(&s->refcount) < 0)
75812 return 1;
75813
75814 return 0;
75815 @@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
75816
75817 s = find_mergeable(size, align, flags, name, ctor);
75818 if (s) {
75819 - s->refcount++;
75820 + atomic_inc(&s->refcount);
75821 /*
75822 * Adjust the object sizes so that we clear
75823 * the complete object on kzalloc.
75824 @@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
75825 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75826
75827 if (sysfs_slab_alias(s, name)) {
75828 - s->refcount--;
75829 + atomic_dec(&s->refcount);
75830 s = NULL;
75831 }
75832 }
75833 @@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75834 }
75835 #endif
75836
75837 -#ifdef CONFIG_SYSFS
75838 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75839 static int count_inuse(struct page *page)
75840 {
75841 return page->inuse;
75842 @@ -4450,12 +4532,12 @@ static void resiliency_test(void)
75843 validate_slab_cache(kmalloc_caches[9]);
75844 }
75845 #else
75846 -#ifdef CONFIG_SYSFS
75847 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75848 static void resiliency_test(void) {};
75849 #endif
75850 #endif
75851
75852 -#ifdef CONFIG_SYSFS
75853 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75854 enum slab_stat_type {
75855 SL_ALL, /* All slabs */
75856 SL_PARTIAL, /* Only partially allocated slabs */
75857 @@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
75858
75859 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75860 {
75861 - return sprintf(buf, "%d\n", s->refcount - 1);
75862 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75863 }
75864 SLAB_ATTR_RO(aliases);
75865
75866 @@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
75867 return name;
75868 }
75869
75870 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75871 static int sysfs_slab_add(struct kmem_cache *s)
75872 {
75873 int err;
75874 @@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75875 kobject_del(&s->kobj);
75876 kobject_put(&s->kobj);
75877 }
75878 +#endif
75879
75880 /*
75881 * Need to buffer aliases during bootup until sysfs becomes
75882 @@ -5336,6 +5420,7 @@ struct saved_alias {
75883
75884 static struct saved_alias *alias_list;
75885
75886 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75887 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75888 {
75889 struct saved_alias *al;
75890 @@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75891 alias_list = al;
75892 return 0;
75893 }
75894 +#endif
75895
75896 static int __init slab_sysfs_init(void)
75897 {
75898 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75899 index 1b7e22a..3fcd4f3 100644
75900 --- a/mm/sparse-vmemmap.c
75901 +++ b/mm/sparse-vmemmap.c
75902 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75903 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75904 if (!p)
75905 return NULL;
75906 - pud_populate(&init_mm, pud, p);
75907 + pud_populate_kernel(&init_mm, pud, p);
75908 }
75909 return pud;
75910 }
75911 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75912 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75913 if (!p)
75914 return NULL;
75915 - pgd_populate(&init_mm, pgd, p);
75916 + pgd_populate_kernel(&init_mm, pgd, p);
75917 }
75918 return pgd;
75919 }
75920 diff --git a/mm/swap.c b/mm/swap.c
75921 index 6310dc2..3662b3f 100644
75922 --- a/mm/swap.c
75923 +++ b/mm/swap.c
75924 @@ -30,6 +30,7 @@
75925 #include <linux/backing-dev.h>
75926 #include <linux/memcontrol.h>
75927 #include <linux/gfp.h>
75928 +#include <linux/hugetlb.h>
75929
75930 #include "internal.h"
75931
75932 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75933
75934 __page_cache_release(page);
75935 dtor = get_compound_page_dtor(page);
75936 + if (!PageHuge(page))
75937 + BUG_ON(dtor != free_compound_page);
75938 (*dtor)(page);
75939 }
75940
75941 diff --git a/mm/swapfile.c b/mm/swapfile.c
75942 index f91a255..9dcac21 100644
75943 --- a/mm/swapfile.c
75944 +++ b/mm/swapfile.c
75945 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75946
75947 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75948 /* Activity counter to indicate that a swapon or swapoff has occurred */
75949 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75950 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75951
75952 static inline unsigned char swap_count(unsigned char ent)
75953 {
75954 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75955 }
75956 filp_close(swap_file, NULL);
75957 err = 0;
75958 - atomic_inc(&proc_poll_event);
75959 + atomic_inc_unchecked(&proc_poll_event);
75960 wake_up_interruptible(&proc_poll_wait);
75961
75962 out_dput:
75963 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75964
75965 poll_wait(file, &proc_poll_wait, wait);
75966
75967 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75968 - seq->poll_event = atomic_read(&proc_poll_event);
75969 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75970 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75971 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75972 }
75973
75974 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75975 return ret;
75976
75977 seq = file->private_data;
75978 - seq->poll_event = atomic_read(&proc_poll_event);
75979 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75980 return 0;
75981 }
75982
75983 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75984 (frontswap_map) ? "FS" : "");
75985
75986 mutex_unlock(&swapon_mutex);
75987 - atomic_inc(&proc_poll_event);
75988 + atomic_inc_unchecked(&proc_poll_event);
75989 wake_up_interruptible(&proc_poll_wait);
75990
75991 if (S_ISREG(inode->i_mode))
75992 diff --git a/mm/util.c b/mm/util.c
75993 index dc3036c..b6c7c9d 100644
75994 --- a/mm/util.c
75995 +++ b/mm/util.c
75996 @@ -292,6 +292,12 @@ done:
75997 void arch_pick_mmap_layout(struct mm_struct *mm)
75998 {
75999 mm->mmap_base = TASK_UNMAPPED_BASE;
76000 +
76001 +#ifdef CONFIG_PAX_RANDMMAP
76002 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76003 + mm->mmap_base += mm->delta_mmap;
76004 +#endif
76005 +
76006 mm->get_unmapped_area = arch_get_unmapped_area;
76007 mm->unmap_area = arch_unmap_area;
76008 }
76009 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76010 index 78e0830..8bfb8bd 100644
76011 --- a/mm/vmalloc.c
76012 +++ b/mm/vmalloc.c
76013 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76014
76015 pte = pte_offset_kernel(pmd, addr);
76016 do {
76017 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76018 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76019 +
76020 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76021 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76022 + BUG_ON(!pte_exec(*pte));
76023 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76024 + continue;
76025 + }
76026 +#endif
76027 +
76028 + {
76029 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76030 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76031 + }
76032 } while (pte++, addr += PAGE_SIZE, addr != end);
76033 }
76034
76035 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76036 pte = pte_alloc_kernel(pmd, addr);
76037 if (!pte)
76038 return -ENOMEM;
76039 +
76040 + pax_open_kernel();
76041 do {
76042 struct page *page = pages[*nr];
76043
76044 - if (WARN_ON(!pte_none(*pte)))
76045 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76046 + if (pgprot_val(prot) & _PAGE_NX)
76047 +#endif
76048 +
76049 + if (!pte_none(*pte)) {
76050 + pax_close_kernel();
76051 + WARN_ON(1);
76052 return -EBUSY;
76053 - if (WARN_ON(!page))
76054 + }
76055 + if (!page) {
76056 + pax_close_kernel();
76057 + WARN_ON(1);
76058 return -ENOMEM;
76059 + }
76060 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76061 (*nr)++;
76062 } while (pte++, addr += PAGE_SIZE, addr != end);
76063 + pax_close_kernel();
76064 return 0;
76065 }
76066
76067 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76068 pmd_t *pmd;
76069 unsigned long next;
76070
76071 - pmd = pmd_alloc(&init_mm, pud, addr);
76072 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76073 if (!pmd)
76074 return -ENOMEM;
76075 do {
76076 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76077 pud_t *pud;
76078 unsigned long next;
76079
76080 - pud = pud_alloc(&init_mm, pgd, addr);
76081 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76082 if (!pud)
76083 return -ENOMEM;
76084 do {
76085 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76086 * and fall back on vmalloc() if that fails. Others
76087 * just put it in the vmalloc space.
76088 */
76089 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76090 +#ifdef CONFIG_MODULES
76091 +#ifdef MODULES_VADDR
76092 unsigned long addr = (unsigned long)x;
76093 if (addr >= MODULES_VADDR && addr < MODULES_END)
76094 return 1;
76095 #endif
76096 +
76097 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76098 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76099 + return 1;
76100 +#endif
76101 +
76102 +#endif
76103 +
76104 return is_vmalloc_addr(x);
76105 }
76106
76107 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76108
76109 if (!pgd_none(*pgd)) {
76110 pud_t *pud = pud_offset(pgd, addr);
76111 +#ifdef CONFIG_X86
76112 + if (!pud_large(*pud))
76113 +#endif
76114 if (!pud_none(*pud)) {
76115 pmd_t *pmd = pmd_offset(pud, addr);
76116 +#ifdef CONFIG_X86
76117 + if (!pmd_large(*pmd))
76118 +#endif
76119 if (!pmd_none(*pmd)) {
76120 pte_t *ptep, pte;
76121
76122 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76123 * Allocate a region of KVA of the specified size and alignment, within the
76124 * vstart and vend.
76125 */
76126 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76127 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76128 unsigned long align,
76129 unsigned long vstart, unsigned long vend,
76130 int node, gfp_t gfp_mask)
76131 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76132 struct vm_struct *area;
76133
76134 BUG_ON(in_interrupt());
76135 +
76136 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76137 + if (flags & VM_KERNEXEC) {
76138 + if (start != VMALLOC_START || end != VMALLOC_END)
76139 + return NULL;
76140 + start = (unsigned long)MODULES_EXEC_VADDR;
76141 + end = (unsigned long)MODULES_EXEC_END;
76142 + }
76143 +#endif
76144 +
76145 if (flags & VM_IOREMAP) {
76146 int bit = fls(size);
76147
76148 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76149 if (count > totalram_pages)
76150 return NULL;
76151
76152 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76153 + if (!(pgprot_val(prot) & _PAGE_NX))
76154 + flags |= VM_KERNEXEC;
76155 +#endif
76156 +
76157 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76158 __builtin_return_address(0));
76159 if (!area)
76160 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76161 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76162 goto fail;
76163
76164 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76165 + if (!(pgprot_val(prot) & _PAGE_NX))
76166 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76167 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76168 + else
76169 +#endif
76170 +
76171 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76172 start, end, node, gfp_mask, caller);
76173 if (!area)
76174 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76175 * For tight control over page level allocator and protection flags
76176 * use __vmalloc() instead.
76177 */
76178 -
76179 void *vmalloc_exec(unsigned long size)
76180 {
76181 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76182 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76183 -1, __builtin_return_address(0));
76184 }
76185
76186 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76187 unsigned long uaddr = vma->vm_start;
76188 unsigned long usize = vma->vm_end - vma->vm_start;
76189
76190 + BUG_ON(vma->vm_mirror);
76191 +
76192 if ((PAGE_SIZE-1) & (unsigned long)addr)
76193 return -EINVAL;
76194
76195 diff --git a/mm/vmstat.c b/mm/vmstat.c
76196 index c737057..a49753a 100644
76197 --- a/mm/vmstat.c
76198 +++ b/mm/vmstat.c
76199 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76200 *
76201 * vm_stat contains the global counters
76202 */
76203 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76204 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76205 EXPORT_SYMBOL(vm_stat);
76206
76207 #ifdef CONFIG_SMP
76208 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76209 v = p->vm_stat_diff[i];
76210 p->vm_stat_diff[i] = 0;
76211 local_irq_restore(flags);
76212 - atomic_long_add(v, &zone->vm_stat[i]);
76213 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76214 global_diff[i] += v;
76215 #ifdef CONFIG_NUMA
76216 /* 3 seconds idle till flush */
76217 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76218
76219 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76220 if (global_diff[i])
76221 - atomic_long_add(global_diff[i], &vm_stat[i]);
76222 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76223 }
76224
76225 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
76226 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
76227 if (pset->vm_stat_diff[i]) {
76228 int v = pset->vm_stat_diff[i];
76229 pset->vm_stat_diff[i] = 0;
76230 - atomic_long_add(v, &zone->vm_stat[i]);
76231 - atomic_long_add(v, &vm_stat[i]);
76232 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76233 + atomic_long_add_unchecked(v, &vm_stat[i]);
76234 }
76235 }
76236 #endif
76237 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
76238 start_cpu_timer(cpu);
76239 #endif
76240 #ifdef CONFIG_PROC_FS
76241 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76242 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76243 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76244 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76245 + {
76246 + mode_t gr_mode = S_IRUGO;
76247 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76248 + gr_mode = S_IRUSR;
76249 +#endif
76250 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76251 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76252 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76253 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76254 +#else
76255 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76256 +#endif
76257 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76258 + }
76259 #endif
76260 return 0;
76261 }
76262 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76263 index ee07072..e280bfa 100644
76264 --- a/net/8021q/vlan.c
76265 +++ b/net/8021q/vlan.c
76266 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76267 err = -EPERM;
76268 if (!capable(CAP_NET_ADMIN))
76269 break;
76270 - if ((args.u.name_type >= 0) &&
76271 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76272 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76273 struct vlan_net *vn;
76274
76275 vn = net_generic(net, vlan_net_id);
76276 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76277 index 02efb25..41541a9 100644
76278 --- a/net/9p/trans_fd.c
76279 +++ b/net/9p/trans_fd.c
76280 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76281 oldfs = get_fs();
76282 set_fs(get_ds());
76283 /* The cast to a user pointer is valid due to the set_fs() */
76284 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76285 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76286 set_fs(oldfs);
76287
76288 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76289 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76290 index 876fbe8..8bbea9f 100644
76291 --- a/net/atm/atm_misc.c
76292 +++ b/net/atm/atm_misc.c
76293 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76294 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76295 return 1;
76296 atm_return(vcc, truesize);
76297 - atomic_inc(&vcc->stats->rx_drop);
76298 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76299 return 0;
76300 }
76301 EXPORT_SYMBOL(atm_charge);
76302 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76303 }
76304 }
76305 atm_return(vcc, guess);
76306 - atomic_inc(&vcc->stats->rx_drop);
76307 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76308 return NULL;
76309 }
76310 EXPORT_SYMBOL(atm_alloc_charge);
76311 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76312
76313 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76314 {
76315 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76316 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76317 __SONET_ITEMS
76318 #undef __HANDLE_ITEM
76319 }
76320 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76321
76322 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76323 {
76324 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76325 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76326 __SONET_ITEMS
76327 #undef __HANDLE_ITEM
76328 }
76329 diff --git a/net/atm/lec.h b/net/atm/lec.h
76330 index a86aff9..3a0d6f6 100644
76331 --- a/net/atm/lec.h
76332 +++ b/net/atm/lec.h
76333 @@ -48,7 +48,7 @@ struct lane2_ops {
76334 const u8 *tlvs, u32 sizeoftlvs);
76335 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76336 const u8 *tlvs, u32 sizeoftlvs);
76337 -};
76338 +} __no_const;
76339
76340 /*
76341 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76342 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76343 index 0919a88..a23d54e 100644
76344 --- a/net/atm/mpc.h
76345 +++ b/net/atm/mpc.h
76346 @@ -33,7 +33,7 @@ struct mpoa_client {
76347 struct mpc_parameters parameters; /* parameters for this client */
76348
76349 const struct net_device_ops *old_ops;
76350 - struct net_device_ops new_ops;
76351 + net_device_ops_no_const new_ops;
76352 };
76353
76354
76355 diff --git a/net/atm/proc.c b/net/atm/proc.c
76356 index 0d020de..011c7bb 100644
76357 --- a/net/atm/proc.c
76358 +++ b/net/atm/proc.c
76359 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76360 const struct k_atm_aal_stats *stats)
76361 {
76362 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76363 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76364 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76365 - atomic_read(&stats->rx_drop));
76366 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76367 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76368 + atomic_read_unchecked(&stats->rx_drop));
76369 }
76370
76371 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76372 diff --git a/net/atm/resources.c b/net/atm/resources.c
76373 index 0447d5d..3cf4728 100644
76374 --- a/net/atm/resources.c
76375 +++ b/net/atm/resources.c
76376 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76377 static void copy_aal_stats(struct k_atm_aal_stats *from,
76378 struct atm_aal_stats *to)
76379 {
76380 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76381 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76382 __AAL_STAT_ITEMS
76383 #undef __HANDLE_ITEM
76384 }
76385 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76386 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76387 struct atm_aal_stats *to)
76388 {
76389 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76390 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76391 __AAL_STAT_ITEMS
76392 #undef __HANDLE_ITEM
76393 }
76394 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76395 index b02b75d..0a9636e 100644
76396 --- a/net/batman-adv/bat_iv_ogm.c
76397 +++ b/net/batman-adv/bat_iv_ogm.c
76398 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76399
76400 /* randomize initial seqno to avoid collision */
76401 get_random_bytes(&random_seqno, sizeof(random_seqno));
76402 - atomic_set(&hard_iface->seqno, random_seqno);
76403 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76404
76405 hard_iface->packet_len = BATADV_OGM_HLEN;
76406 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76407 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76408 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
76409
76410 /* change sequence number to network order */
76411 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
76412 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
76413 batadv_ogm_packet->seqno = htonl(seqno);
76414 - atomic_inc(&hard_iface->seqno);
76415 + atomic_inc_unchecked(&hard_iface->seqno);
76416
76417 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
76418 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
76419 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76420 return;
76421
76422 /* could be changed by schedule_own_packet() */
76423 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76424 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76425
76426 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76427 has_directlink_flag = 1;
76428 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76429 index d112fd6..686a447 100644
76430 --- a/net/batman-adv/hard-interface.c
76431 +++ b/net/batman-adv/hard-interface.c
76432 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76433 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76434 dev_add_pack(&hard_iface->batman_adv_ptype);
76435
76436 - atomic_set(&hard_iface->frag_seqno, 1);
76437 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76438 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76439 hard_iface->net_dev->name);
76440
76441 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76442 /* This can't be called via a bat_priv callback because
76443 * we have no bat_priv yet.
76444 */
76445 - atomic_set(&hard_iface->seqno, 1);
76446 + atomic_set_unchecked(&hard_iface->seqno, 1);
76447 hard_iface->packet_buff = NULL;
76448
76449 return hard_iface;
76450 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76451 index ce0684a..4a0cbf1 100644
76452 --- a/net/batman-adv/soft-interface.c
76453 +++ b/net/batman-adv/soft-interface.c
76454 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76455 primary_if->net_dev->dev_addr, ETH_ALEN);
76456
76457 /* set broadcast sequence number */
76458 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
76459 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
76460 bcast_packet->seqno = htonl(seqno);
76461
76462 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76463 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
76464 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76465
76466 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76467 - atomic_set(&bat_priv->bcast_seqno, 1);
76468 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76469 atomic_set(&bat_priv->tt.vn, 0);
76470 atomic_set(&bat_priv->tt.local_changes, 0);
76471 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
76472 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76473 index ac1e07a..4c846e2 100644
76474 --- a/net/batman-adv/types.h
76475 +++ b/net/batman-adv/types.h
76476 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76477 int16_t if_num;
76478 char if_status;
76479 struct net_device *net_dev;
76480 - atomic_t seqno;
76481 - atomic_t frag_seqno;
76482 + atomic_unchecked_t seqno;
76483 + atomic_unchecked_t frag_seqno;
76484 unsigned char *packet_buff;
76485 int packet_len;
76486 struct kobject *hardif_obj;
76487 @@ -244,7 +244,7 @@ struct batadv_priv {
76488 atomic_t orig_interval; /* uint */
76489 atomic_t hop_penalty; /* uint */
76490 atomic_t log_level; /* uint */
76491 - atomic_t bcast_seqno;
76492 + atomic_unchecked_t bcast_seqno;
76493 atomic_t bcast_queue_left;
76494 atomic_t batman_queue_left;
76495 char num_ifaces;
76496 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76497 index f397232..3206a33 100644
76498 --- a/net/batman-adv/unicast.c
76499 +++ b/net/batman-adv/unicast.c
76500 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76501 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76502 frag2->flags = large_tail;
76503
76504 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76505 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76506 frag1->seqno = htons(seqno - 1);
76507 frag2->seqno = htons(seqno);
76508
76509 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76510 index 07f0739..3c42e34 100644
76511 --- a/net/bluetooth/hci_sock.c
76512 +++ b/net/bluetooth/hci_sock.c
76513 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76514 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76515 }
76516
76517 - len = min_t(unsigned int, len, sizeof(uf));
76518 + len = min((size_t)len, sizeof(uf));
76519 if (copy_from_user(&uf, optval, len)) {
76520 err = -EFAULT;
76521 break;
76522 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76523 index a91239d..d7ed533 100644
76524 --- a/net/bluetooth/l2cap_core.c
76525 +++ b/net/bluetooth/l2cap_core.c
76526 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76527 break;
76528
76529 case L2CAP_CONF_RFC:
76530 - if (olen == sizeof(rfc))
76531 - memcpy(&rfc, (void *)val, olen);
76532 + if (olen != sizeof(rfc))
76533 + break;
76534 +
76535 + memcpy(&rfc, (void *)val, olen);
76536
76537 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76538 rfc.mode != chan->mode)
76539 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76540 index 083f2bf..799f9448 100644
76541 --- a/net/bluetooth/l2cap_sock.c
76542 +++ b/net/bluetooth/l2cap_sock.c
76543 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76544 struct sock *sk = sock->sk;
76545 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76546 struct l2cap_options opts;
76547 - int len, err = 0;
76548 + int err = 0;
76549 + size_t len = optlen;
76550 u32 opt;
76551
76552 BT_DBG("sk %p", sk);
76553 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76554 opts.max_tx = chan->max_tx;
76555 opts.txwin_size = chan->tx_win;
76556
76557 - len = min_t(unsigned int, sizeof(opts), optlen);
76558 + len = min(sizeof(opts), len);
76559 if (copy_from_user((char *) &opts, optval, len)) {
76560 err = -EFAULT;
76561 break;
76562 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76563 struct bt_security sec;
76564 struct bt_power pwr;
76565 struct l2cap_conn *conn;
76566 - int len, err = 0;
76567 + int err = 0;
76568 + size_t len = optlen;
76569 u32 opt;
76570
76571 BT_DBG("sk %p", sk);
76572 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76573
76574 sec.level = BT_SECURITY_LOW;
76575
76576 - len = min_t(unsigned int, sizeof(sec), optlen);
76577 + len = min(sizeof(sec), len);
76578 if (copy_from_user((char *) &sec, optval, len)) {
76579 err = -EFAULT;
76580 break;
76581 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76582
76583 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76584
76585 - len = min_t(unsigned int, sizeof(pwr), optlen);
76586 + len = min(sizeof(pwr), len);
76587 if (copy_from_user((char *) &pwr, optval, len)) {
76588 err = -EFAULT;
76589 break;
76590 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76591 index b3226f3..8916f43 100644
76592 --- a/net/bluetooth/rfcomm/sock.c
76593 +++ b/net/bluetooth/rfcomm/sock.c
76594 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76595 struct sock *sk = sock->sk;
76596 struct bt_security sec;
76597 int err = 0;
76598 - size_t len;
76599 + size_t len = optlen;
76600 u32 opt;
76601
76602 BT_DBG("sk %p", sk);
76603 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76604
76605 sec.level = BT_SECURITY_LOW;
76606
76607 - len = min_t(unsigned int, sizeof(sec), optlen);
76608 + len = min(sizeof(sec), len);
76609 if (copy_from_user((char *) &sec, optval, len)) {
76610 err = -EFAULT;
76611 break;
76612 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76613 index ccc2487..921073d 100644
76614 --- a/net/bluetooth/rfcomm/tty.c
76615 +++ b/net/bluetooth/rfcomm/tty.c
76616 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76617 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76618
76619 spin_lock_irqsave(&dev->port.lock, flags);
76620 - if (dev->port.count > 0) {
76621 + if (atomic_read(&dev->port.count) > 0) {
76622 spin_unlock_irqrestore(&dev->port.lock, flags);
76623 return;
76624 }
76625 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76626 return -ENODEV;
76627
76628 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76629 - dev->channel, dev->port.count);
76630 + dev->channel, atomic_read(&dev->port.count));
76631
76632 spin_lock_irqsave(&dev->port.lock, flags);
76633 - if (++dev->port.count > 1) {
76634 + if (atomic_inc_return(&dev->port.count) > 1) {
76635 spin_unlock_irqrestore(&dev->port.lock, flags);
76636 return 0;
76637 }
76638 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76639 return;
76640
76641 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76642 - dev->port.count);
76643 + atomic_read(&dev->port.count));
76644
76645 spin_lock_irqsave(&dev->port.lock, flags);
76646 - if (!--dev->port.count) {
76647 + if (!atomic_dec_return(&dev->port.count)) {
76648 spin_unlock_irqrestore(&dev->port.lock, flags);
76649 if (dev->tty_dev->parent)
76650 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76651 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76652 index 5fe2ff3..121d696 100644
76653 --- a/net/bridge/netfilter/ebtables.c
76654 +++ b/net/bridge/netfilter/ebtables.c
76655 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76656 tmp.valid_hooks = t->table->valid_hooks;
76657 }
76658 mutex_unlock(&ebt_mutex);
76659 - if (copy_to_user(user, &tmp, *len) != 0){
76660 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76661 BUGPRINT("c2u Didn't work\n");
76662 ret = -EFAULT;
76663 break;
76664 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76665 goto out;
76666 tmp.valid_hooks = t->valid_hooks;
76667
76668 - if (copy_to_user(user, &tmp, *len) != 0) {
76669 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76670 ret = -EFAULT;
76671 break;
76672 }
76673 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76674 tmp.entries_size = t->table->entries_size;
76675 tmp.valid_hooks = t->table->valid_hooks;
76676
76677 - if (copy_to_user(user, &tmp, *len) != 0) {
76678 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76679 ret = -EFAULT;
76680 break;
76681 }
76682 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76683 index 44f270f..1f5602d 100644
76684 --- a/net/caif/cfctrl.c
76685 +++ b/net/caif/cfctrl.c
76686 @@ -10,6 +10,7 @@
76687 #include <linux/spinlock.h>
76688 #include <linux/slab.h>
76689 #include <linux/pkt_sched.h>
76690 +#include <linux/sched.h>
76691 #include <net/caif/caif_layer.h>
76692 #include <net/caif/cfpkt.h>
76693 #include <net/caif/cfctrl.h>
76694 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76695 memset(&dev_info, 0, sizeof(dev_info));
76696 dev_info.id = 0xff;
76697 cfsrvl_init(&this->serv, 0, &dev_info, false);
76698 - atomic_set(&this->req_seq_no, 1);
76699 - atomic_set(&this->rsp_seq_no, 1);
76700 + atomic_set_unchecked(&this->req_seq_no, 1);
76701 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76702 this->serv.layer.receive = cfctrl_recv;
76703 sprintf(this->serv.layer.name, "ctrl");
76704 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76705 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76706 struct cfctrl_request_info *req)
76707 {
76708 spin_lock_bh(&ctrl->info_list_lock);
76709 - atomic_inc(&ctrl->req_seq_no);
76710 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76711 + atomic_inc_unchecked(&ctrl->req_seq_no);
76712 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76713 list_add_tail(&req->list, &ctrl->list);
76714 spin_unlock_bh(&ctrl->info_list_lock);
76715 }
76716 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76717 if (p != first)
76718 pr_warn("Requests are not received in order\n");
76719
76720 - atomic_set(&ctrl->rsp_seq_no,
76721 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76722 p->sequence_no);
76723 list_del(&p->list);
76724 goto out;
76725 diff --git a/net/can/gw.c b/net/can/gw.c
76726 index 1f5c978..522e050 100644
76727 --- a/net/can/gw.c
76728 +++ b/net/can/gw.c
76729 @@ -96,7 +96,7 @@ struct cf_mod {
76730 struct {
76731 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76732 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76733 - } csumfunc;
76734 + } __no_const csumfunc;
76735 };
76736
76737
76738 diff --git a/net/compat.c b/net/compat.c
76739 index 79ae884..17c5c09 100644
76740 --- a/net/compat.c
76741 +++ b/net/compat.c
76742 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76743 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76744 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76745 return -EFAULT;
76746 - kmsg->msg_name = compat_ptr(tmp1);
76747 - kmsg->msg_iov = compat_ptr(tmp2);
76748 - kmsg->msg_control = compat_ptr(tmp3);
76749 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76750 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76751 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76752 return 0;
76753 }
76754
76755 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76756
76757 if (kern_msg->msg_namelen) {
76758 if (mode == VERIFY_READ) {
76759 - int err = move_addr_to_kernel(kern_msg->msg_name,
76760 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76761 kern_msg->msg_namelen,
76762 kern_address);
76763 if (err < 0)
76764 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76765 kern_msg->msg_name = NULL;
76766
76767 tot_len = iov_from_user_compat_to_kern(kern_iov,
76768 - (struct compat_iovec __user *)kern_msg->msg_iov,
76769 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76770 kern_msg->msg_iovlen);
76771 if (tot_len >= 0)
76772 kern_msg->msg_iov = kern_iov;
76773 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76774
76775 #define CMSG_COMPAT_FIRSTHDR(msg) \
76776 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76777 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76778 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76779 (struct compat_cmsghdr __user *)NULL)
76780
76781 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76782 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76783 (ucmlen) <= (unsigned long) \
76784 ((mhdr)->msg_controllen - \
76785 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76786 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76787
76788 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76789 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76790 {
76791 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76792 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76793 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76794 msg->msg_controllen)
76795 return NULL;
76796 return (struct compat_cmsghdr __user *)ptr;
76797 @@ -219,7 +219,7 @@ Efault:
76798
76799 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76800 {
76801 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76802 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76803 struct compat_cmsghdr cmhdr;
76804 struct compat_timeval ctv;
76805 struct compat_timespec cts[3];
76806 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76807
76808 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76809 {
76810 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76811 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76812 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76813 int fdnum = scm->fp->count;
76814 struct file **fp = scm->fp->fp;
76815 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76816 return -EFAULT;
76817 old_fs = get_fs();
76818 set_fs(KERNEL_DS);
76819 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76820 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76821 set_fs(old_fs);
76822
76823 return err;
76824 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76825 len = sizeof(ktime);
76826 old_fs = get_fs();
76827 set_fs(KERNEL_DS);
76828 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76829 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76830 set_fs(old_fs);
76831
76832 if (!err) {
76833 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76834 case MCAST_JOIN_GROUP:
76835 case MCAST_LEAVE_GROUP:
76836 {
76837 - struct compat_group_req __user *gr32 = (void *)optval;
76838 + struct compat_group_req __user *gr32 = (void __user *)optval;
76839 struct group_req __user *kgr =
76840 compat_alloc_user_space(sizeof(struct group_req));
76841 u32 interface;
76842 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76843 case MCAST_BLOCK_SOURCE:
76844 case MCAST_UNBLOCK_SOURCE:
76845 {
76846 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76847 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76848 struct group_source_req __user *kgsr = compat_alloc_user_space(
76849 sizeof(struct group_source_req));
76850 u32 interface;
76851 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76852 }
76853 case MCAST_MSFILTER:
76854 {
76855 - struct compat_group_filter __user *gf32 = (void *)optval;
76856 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76857 struct group_filter __user *kgf;
76858 u32 interface, fmode, numsrc;
76859
76860 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76861 char __user *optval, int __user *optlen,
76862 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76863 {
76864 - struct compat_group_filter __user *gf32 = (void *)optval;
76865 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76866 struct group_filter __user *kgf;
76867 int __user *koptlen;
76868 u32 interface, fmode, numsrc;
76869 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76870
76871 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76872 return -EINVAL;
76873 - if (copy_from_user(a, args, nas[call]))
76874 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76875 return -EFAULT;
76876 a0 = a[0];
76877 a1 = a[1];
76878 diff --git a/net/core/datagram.c b/net/core/datagram.c
76879 index 0337e2b..47914a0 100644
76880 --- a/net/core/datagram.c
76881 +++ b/net/core/datagram.c
76882 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76883 }
76884
76885 kfree_skb(skb);
76886 - atomic_inc(&sk->sk_drops);
76887 + atomic_inc_unchecked(&sk->sk_drops);
76888 sk_mem_reclaim_partial(sk);
76889
76890 return err;
76891 diff --git a/net/core/dev.c b/net/core/dev.c
76892 index e5942bf..25998c3 100644
76893 --- a/net/core/dev.c
76894 +++ b/net/core/dev.c
76895 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
76896 if (no_module && capable(CAP_NET_ADMIN))
76897 no_module = request_module("netdev-%s", name);
76898 if (no_module && capable(CAP_SYS_MODULE)) {
76899 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76900 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76901 +#else
76902 if (!request_module("%s", name))
76903 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76904 name);
76905 +#endif
76906 }
76907 }
76908 EXPORT_SYMBOL(dev_load);
76909 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76910 {
76911 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76912 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76913 - atomic_long_inc(&dev->rx_dropped);
76914 + atomic_long_inc_unchecked(&dev->rx_dropped);
76915 kfree_skb(skb);
76916 return NET_RX_DROP;
76917 }
76918 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76919 nf_reset(skb);
76920
76921 if (unlikely(!is_skb_forwardable(dev, skb))) {
76922 - atomic_long_inc(&dev->rx_dropped);
76923 + atomic_long_inc_unchecked(&dev->rx_dropped);
76924 kfree_skb(skb);
76925 return NET_RX_DROP;
76926 }
76927 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76928
76929 struct dev_gso_cb {
76930 void (*destructor)(struct sk_buff *skb);
76931 -};
76932 +} __no_const;
76933
76934 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76935
76936 @@ -2955,7 +2959,7 @@ enqueue:
76937
76938 local_irq_restore(flags);
76939
76940 - atomic_long_inc(&skb->dev->rx_dropped);
76941 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76942 kfree_skb(skb);
76943 return NET_RX_DROP;
76944 }
76945 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
76946 }
76947 EXPORT_SYMBOL(netif_rx_ni);
76948
76949 -static void net_tx_action(struct softirq_action *h)
76950 +static void net_tx_action(void)
76951 {
76952 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76953
76954 @@ -3358,7 +3362,7 @@ ncls:
76955 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76956 } else {
76957 drop:
76958 - atomic_long_inc(&skb->dev->rx_dropped);
76959 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76960 kfree_skb(skb);
76961 /* Jamal, now you will not able to escape explaining
76962 * me how you were going to use this. :-)
76963 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
76964 }
76965 EXPORT_SYMBOL(netif_napi_del);
76966
76967 -static void net_rx_action(struct softirq_action *h)
76968 +static void net_rx_action(void)
76969 {
76970 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76971 unsigned long time_limit = jiffies + 2;
76972 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76973 else
76974 seq_printf(seq, "%04x", ntohs(pt->type));
76975
76976 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76977 + seq_printf(seq, " %-8s %p\n",
76978 + pt->dev ? pt->dev->name : "", NULL);
76979 +#else
76980 seq_printf(seq, " %-8s %pF\n",
76981 pt->dev ? pt->dev->name : "", pt->func);
76982 +#endif
76983 }
76984
76985 return 0;
76986 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76987 } else {
76988 netdev_stats_to_stats64(storage, &dev->stats);
76989 }
76990 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76991 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76992 return storage;
76993 }
76994 EXPORT_SYMBOL(dev_get_stats);
76995 diff --git a/net/core/flow.c b/net/core/flow.c
76996 index e318c7e..168b1d0 100644
76997 --- a/net/core/flow.c
76998 +++ b/net/core/flow.c
76999 @@ -61,7 +61,7 @@ struct flow_cache {
77000 struct timer_list rnd_timer;
77001 };
77002
77003 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
77004 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77005 EXPORT_SYMBOL(flow_cache_genid);
77006 static struct flow_cache flow_cache_global;
77007 static struct kmem_cache *flow_cachep __read_mostly;
77008 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77009
77010 static int flow_entry_valid(struct flow_cache_entry *fle)
77011 {
77012 - if (atomic_read(&flow_cache_genid) != fle->genid)
77013 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77014 return 0;
77015 if (fle->object && !fle->object->ops->check(fle->object))
77016 return 0;
77017 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77018 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77019 fcp->hash_count++;
77020 }
77021 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77022 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77023 flo = fle->object;
77024 if (!flo)
77025 goto ret_object;
77026 @@ -280,7 +280,7 @@ nocache:
77027 }
77028 flo = resolver(net, key, family, dir, flo, ctx);
77029 if (fle) {
77030 - fle->genid = atomic_read(&flow_cache_genid);
77031 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
77032 if (!IS_ERR(flo))
77033 fle->object = flo;
77034 else
77035 diff --git a/net/core/iovec.c b/net/core/iovec.c
77036 index 7e7aeb0..2a998cb 100644
77037 --- a/net/core/iovec.c
77038 +++ b/net/core/iovec.c
77039 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77040 if (m->msg_namelen) {
77041 if (mode == VERIFY_READ) {
77042 void __user *namep;
77043 - namep = (void __user __force *) m->msg_name;
77044 + namep = (void __force_user *) m->msg_name;
77045 err = move_addr_to_kernel(namep, m->msg_namelen,
77046 address);
77047 if (err < 0)
77048 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77049 }
77050
77051 size = m->msg_iovlen * sizeof(struct iovec);
77052 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77053 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77054 return -EFAULT;
77055
77056 m->msg_iov = iov;
77057 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77058 index fad649a..df5891e 100644
77059 --- a/net/core/rtnetlink.c
77060 +++ b/net/core/rtnetlink.c
77061 @@ -58,7 +58,7 @@ struct rtnl_link {
77062 rtnl_doit_func doit;
77063 rtnl_dumpit_func dumpit;
77064 rtnl_calcit_func calcit;
77065 -};
77066 +} __no_const;
77067
77068 static DEFINE_MUTEX(rtnl_mutex);
77069
77070 diff --git a/net/core/scm.c b/net/core/scm.c
77071 index ab57084..0190c8f 100644
77072 --- a/net/core/scm.c
77073 +++ b/net/core/scm.c
77074 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
77075 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77076 {
77077 struct cmsghdr __user *cm
77078 - = (__force struct cmsghdr __user *)msg->msg_control;
77079 + = (struct cmsghdr __force_user *)msg->msg_control;
77080 struct cmsghdr cmhdr;
77081 int cmlen = CMSG_LEN(len);
77082 int err;
77083 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77084 err = -EFAULT;
77085 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77086 goto out;
77087 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77088 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77089 goto out;
77090 cmlen = CMSG_SPACE(len);
77091 if (msg->msg_controllen < cmlen)
77092 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
77093 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77094 {
77095 struct cmsghdr __user *cm
77096 - = (__force struct cmsghdr __user*)msg->msg_control;
77097 + = (struct cmsghdr __force_user *)msg->msg_control;
77098
77099 int fdmax = 0;
77100 int fdnum = scm->fp->count;
77101 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77102 if (fdnum < fdmax)
77103 fdmax = fdnum;
77104
77105 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77106 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77107 i++, cmfptr++)
77108 {
77109 struct socket *sock;
77110 diff --git a/net/core/sock.c b/net/core/sock.c
77111 index 8a146cf..ee08914d 100644
77112 --- a/net/core/sock.c
77113 +++ b/net/core/sock.c
77114 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77115 struct sk_buff_head *list = &sk->sk_receive_queue;
77116
77117 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77118 - atomic_inc(&sk->sk_drops);
77119 + atomic_inc_unchecked(&sk->sk_drops);
77120 trace_sock_rcvqueue_full(sk, skb);
77121 return -ENOMEM;
77122 }
77123 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77124 return err;
77125
77126 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77127 - atomic_inc(&sk->sk_drops);
77128 + atomic_inc_unchecked(&sk->sk_drops);
77129 return -ENOBUFS;
77130 }
77131
77132 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77133 skb_dst_force(skb);
77134
77135 spin_lock_irqsave(&list->lock, flags);
77136 - skb->dropcount = atomic_read(&sk->sk_drops);
77137 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77138 __skb_queue_tail(list, skb);
77139 spin_unlock_irqrestore(&list->lock, flags);
77140
77141 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77142 skb->dev = NULL;
77143
77144 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77145 - atomic_inc(&sk->sk_drops);
77146 + atomic_inc_unchecked(&sk->sk_drops);
77147 goto discard_and_relse;
77148 }
77149 if (nested)
77150 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77151 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77152 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77153 bh_unlock_sock(sk);
77154 - atomic_inc(&sk->sk_drops);
77155 + atomic_inc_unchecked(&sk->sk_drops);
77156 goto discard_and_relse;
77157 }
77158
77159 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77160 struct timeval tm;
77161 } v;
77162
77163 - int lv = sizeof(int);
77164 - int len;
77165 + unsigned int lv = sizeof(int);
77166 + unsigned int len;
77167
77168 if (get_user(len, optlen))
77169 return -EFAULT;
77170 - if (len < 0)
77171 + if (len > INT_MAX)
77172 return -EINVAL;
77173
77174 memset(&v, 0, sizeof(v));
77175 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77176
77177 case SO_PEERNAME:
77178 {
77179 - char address[128];
77180 + char address[_K_SS_MAXSIZE];
77181
77182 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77183 return -ENOTCONN;
77184 - if (lv < len)
77185 + if (lv < len || sizeof address < len)
77186 return -EINVAL;
77187 if (copy_to_user(optval, address, len))
77188 return -EFAULT;
77189 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77190
77191 if (len > lv)
77192 len = lv;
77193 - if (copy_to_user(optval, &v, len))
77194 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77195 return -EFAULT;
77196 lenout:
77197 if (put_user(len, optlen))
77198 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77199 */
77200 smp_wmb();
77201 atomic_set(&sk->sk_refcnt, 1);
77202 - atomic_set(&sk->sk_drops, 0);
77203 + atomic_set_unchecked(&sk->sk_drops, 0);
77204 }
77205 EXPORT_SYMBOL(sock_init_data);
77206
77207 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77208 index 602cd63..05c6c60 100644
77209 --- a/net/core/sock_diag.c
77210 +++ b/net/core/sock_diag.c
77211 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77212
77213 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77214 {
77215 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77216 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77217 cookie[1] != INET_DIAG_NOCOOKIE) &&
77218 ((u32)(unsigned long)sk != cookie[0] ||
77219 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77220 return -ESTALE;
77221 else
77222 +#endif
77223 return 0;
77224 }
77225 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77226
77227 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77228 {
77229 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77230 + cookie[0] = 0;
77231 + cookie[1] = 0;
77232 +#else
77233 cookie[0] = (u32)(unsigned long)sk;
77234 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77235 +#endif
77236 }
77237 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77238
77239 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77240 index a55eecc..dd8428c 100644
77241 --- a/net/decnet/sysctl_net_decnet.c
77242 +++ b/net/decnet/sysctl_net_decnet.c
77243 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77244
77245 if (len > *lenp) len = *lenp;
77246
77247 - if (copy_to_user(buffer, addr, len))
77248 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77249 return -EFAULT;
77250
77251 *lenp = len;
77252 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77253
77254 if (len > *lenp) len = *lenp;
77255
77256 - if (copy_to_user(buffer, devname, len))
77257 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77258 return -EFAULT;
77259
77260 *lenp = len;
77261 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77262 index 825c608..750ff29 100644
77263 --- a/net/ipv4/fib_frontend.c
77264 +++ b/net/ipv4/fib_frontend.c
77265 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77266 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77267 fib_sync_up(dev);
77268 #endif
77269 - atomic_inc(&net->ipv4.dev_addr_genid);
77270 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77271 rt_cache_flush(dev_net(dev));
77272 break;
77273 case NETDEV_DOWN:
77274 fib_del_ifaddr(ifa, NULL);
77275 - atomic_inc(&net->ipv4.dev_addr_genid);
77276 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77277 if (ifa->ifa_dev->ifa_list == NULL) {
77278 /* Last address was deleted from this interface.
77279 * Disable IP.
77280 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77281 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77282 fib_sync_up(dev);
77283 #endif
77284 - atomic_inc(&net->ipv4.dev_addr_genid);
77285 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77286 rt_cache_flush(net);
77287 break;
77288 case NETDEV_DOWN:
77289 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77290 index 71b125c..f4c70b0 100644
77291 --- a/net/ipv4/fib_semantics.c
77292 +++ b/net/ipv4/fib_semantics.c
77293 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77294 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77295 nh->nh_gw,
77296 nh->nh_parent->fib_scope);
77297 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77298 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77299
77300 return nh->nh_saddr;
77301 }
77302 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77303 index 7880af9..70f92a3 100644
77304 --- a/net/ipv4/inet_hashtables.c
77305 +++ b/net/ipv4/inet_hashtables.c
77306 @@ -18,12 +18,15 @@
77307 #include <linux/sched.h>
77308 #include <linux/slab.h>
77309 #include <linux/wait.h>
77310 +#include <linux/security.h>
77311
77312 #include <net/inet_connection_sock.h>
77313 #include <net/inet_hashtables.h>
77314 #include <net/secure_seq.h>
77315 #include <net/ip.h>
77316
77317 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77318 +
77319 /*
77320 * Allocate and initialize a new local port bind bucket.
77321 * The bindhash mutex for snum's hash chain must be held here.
77322 @@ -530,6 +533,8 @@ ok:
77323 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77324 spin_unlock(&head->lock);
77325
77326 + gr_update_task_in_ip_table(current, inet_sk(sk));
77327 +
77328 if (tw) {
77329 inet_twsk_deschedule(tw, death_row);
77330 while (twrefcnt) {
77331 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77332 index 000e3d2..5472da3 100644
77333 --- a/net/ipv4/inetpeer.c
77334 +++ b/net/ipv4/inetpeer.c
77335 @@ -503,8 +503,8 @@ relookup:
77336 if (p) {
77337 p->daddr = *daddr;
77338 atomic_set(&p->refcnt, 1);
77339 - atomic_set(&p->rid, 0);
77340 - atomic_set(&p->ip_id_count,
77341 + atomic_set_unchecked(&p->rid, 0);
77342 + atomic_set_unchecked(&p->ip_id_count,
77343 (daddr->family == AF_INET) ?
77344 secure_ip_id(daddr->addr.a4) :
77345 secure_ipv6_id(daddr->addr.a6));
77346 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77347 index 8d5cc75..821fd11 100644
77348 --- a/net/ipv4/ip_fragment.c
77349 +++ b/net/ipv4/ip_fragment.c
77350 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77351 return 0;
77352
77353 start = qp->rid;
77354 - end = atomic_inc_return(&peer->rid);
77355 + end = atomic_inc_return_unchecked(&peer->rid);
77356 qp->rid = end;
77357
77358 rc = qp->q.fragments && (end - start) > max;
77359 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77360 index 14bbfcf..644f472 100644
77361 --- a/net/ipv4/ip_sockglue.c
77362 +++ b/net/ipv4/ip_sockglue.c
77363 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77364 len = min_t(unsigned int, len, opt->optlen);
77365 if (put_user(len, optlen))
77366 return -EFAULT;
77367 - if (copy_to_user(optval, opt->__data, len))
77368 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77369 + copy_to_user(optval, opt->__data, len))
77370 return -EFAULT;
77371 return 0;
77372 }
77373 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77374 if (sk->sk_type != SOCK_STREAM)
77375 return -ENOPROTOOPT;
77376
77377 - msg.msg_control = optval;
77378 + msg.msg_control = (void __force_kernel *)optval;
77379 msg.msg_controllen = len;
77380 msg.msg_flags = flags;
77381
77382 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77383 index 798358b..73570b7 100644
77384 --- a/net/ipv4/ipconfig.c
77385 +++ b/net/ipv4/ipconfig.c
77386 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77387
77388 mm_segment_t oldfs = get_fs();
77389 set_fs(get_ds());
77390 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77391 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77392 set_fs(oldfs);
77393 return res;
77394 }
77395 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77396
77397 mm_segment_t oldfs = get_fs();
77398 set_fs(get_ds());
77399 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77400 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77401 set_fs(oldfs);
77402 return res;
77403 }
77404 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77405
77406 mm_segment_t oldfs = get_fs();
77407 set_fs(get_ds());
77408 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77409 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77410 set_fs(oldfs);
77411 return res;
77412 }
77413 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77414 index 97e61ea..cac1bbb 100644
77415 --- a/net/ipv4/netfilter/arp_tables.c
77416 +++ b/net/ipv4/netfilter/arp_tables.c
77417 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77418 #endif
77419
77420 static int get_info(struct net *net, void __user *user,
77421 - const int *len, int compat)
77422 + int len, int compat)
77423 {
77424 char name[XT_TABLE_MAXNAMELEN];
77425 struct xt_table *t;
77426 int ret;
77427
77428 - if (*len != sizeof(struct arpt_getinfo)) {
77429 - duprintf("length %u != %Zu\n", *len,
77430 + if (len != sizeof(struct arpt_getinfo)) {
77431 + duprintf("length %u != %Zu\n", len,
77432 sizeof(struct arpt_getinfo));
77433 return -EINVAL;
77434 }
77435 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77436 info.size = private->size;
77437 strcpy(info.name, name);
77438
77439 - if (copy_to_user(user, &info, *len) != 0)
77440 + if (copy_to_user(user, &info, len) != 0)
77441 ret = -EFAULT;
77442 else
77443 ret = 0;
77444 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77445
77446 switch (cmd) {
77447 case ARPT_SO_GET_INFO:
77448 - ret = get_info(sock_net(sk), user, len, 1);
77449 + ret = get_info(sock_net(sk), user, *len, 1);
77450 break;
77451 case ARPT_SO_GET_ENTRIES:
77452 ret = compat_get_entries(sock_net(sk), user, len);
77453 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77454
77455 switch (cmd) {
77456 case ARPT_SO_GET_INFO:
77457 - ret = get_info(sock_net(sk), user, len, 0);
77458 + ret = get_info(sock_net(sk), user, *len, 0);
77459 break;
77460
77461 case ARPT_SO_GET_ENTRIES:
77462 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77463 index 170b1fd..6105b91 100644
77464 --- a/net/ipv4/netfilter/ip_tables.c
77465 +++ b/net/ipv4/netfilter/ip_tables.c
77466 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77467 #endif
77468
77469 static int get_info(struct net *net, void __user *user,
77470 - const int *len, int compat)
77471 + int len, int compat)
77472 {
77473 char name[XT_TABLE_MAXNAMELEN];
77474 struct xt_table *t;
77475 int ret;
77476
77477 - if (*len != sizeof(struct ipt_getinfo)) {
77478 - duprintf("length %u != %zu\n", *len,
77479 + if (len != sizeof(struct ipt_getinfo)) {
77480 + duprintf("length %u != %zu\n", len,
77481 sizeof(struct ipt_getinfo));
77482 return -EINVAL;
77483 }
77484 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77485 info.size = private->size;
77486 strcpy(info.name, name);
77487
77488 - if (copy_to_user(user, &info, *len) != 0)
77489 + if (copy_to_user(user, &info, len) != 0)
77490 ret = -EFAULT;
77491 else
77492 ret = 0;
77493 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77494
77495 switch (cmd) {
77496 case IPT_SO_GET_INFO:
77497 - ret = get_info(sock_net(sk), user, len, 1);
77498 + ret = get_info(sock_net(sk), user, *len, 1);
77499 break;
77500 case IPT_SO_GET_ENTRIES:
77501 ret = compat_get_entries(sock_net(sk), user, len);
77502 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77503
77504 switch (cmd) {
77505 case IPT_SO_GET_INFO:
77506 - ret = get_info(sock_net(sk), user, len, 0);
77507 + ret = get_info(sock_net(sk), user, *len, 0);
77508 break;
77509
77510 case IPT_SO_GET_ENTRIES:
77511 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77512 index 8f3d054..c58d05d 100644
77513 --- a/net/ipv4/ping.c
77514 +++ b/net/ipv4/ping.c
77515 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77516 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
77517 0, sock_i_ino(sp),
77518 atomic_read(&sp->sk_refcnt), sp,
77519 - atomic_read(&sp->sk_drops), len);
77520 + atomic_read_unchecked(&sp->sk_drops), len);
77521 }
77522
77523 static int ping_seq_show(struct seq_file *seq, void *v)
77524 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77525 index 73d1e4d..3af0e8f 100644
77526 --- a/net/ipv4/raw.c
77527 +++ b/net/ipv4/raw.c
77528 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77529 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77530 {
77531 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77532 - atomic_inc(&sk->sk_drops);
77533 + atomic_inc_unchecked(&sk->sk_drops);
77534 kfree_skb(skb);
77535 return NET_RX_DROP;
77536 }
77537 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77538
77539 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77540 {
77541 + struct icmp_filter filter;
77542 +
77543 if (optlen > sizeof(struct icmp_filter))
77544 optlen = sizeof(struct icmp_filter);
77545 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77546 + if (copy_from_user(&filter, optval, optlen))
77547 return -EFAULT;
77548 + raw_sk(sk)->filter = filter;
77549 return 0;
77550 }
77551
77552 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77553 {
77554 int len, ret = -EFAULT;
77555 + struct icmp_filter filter;
77556
77557 if (get_user(len, optlen))
77558 goto out;
77559 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77560 if (len > sizeof(struct icmp_filter))
77561 len = sizeof(struct icmp_filter);
77562 ret = -EFAULT;
77563 - if (put_user(len, optlen) ||
77564 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77565 + filter = raw_sk(sk)->filter;
77566 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77567 goto out;
77568 ret = 0;
77569 out: return ret;
77570 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77571 0, 0L, 0,
77572 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
77573 0, sock_i_ino(sp),
77574 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77575 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
77576 }
77577
77578 static int raw_seq_show(struct seq_file *seq, void *v)
77579 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77580 index df25142..e92a82a 100644
77581 --- a/net/ipv4/route.c
77582 +++ b/net/ipv4/route.c
77583 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77584
77585 static __net_init int rt_genid_init(struct net *net)
77586 {
77587 - atomic_set(&net->rt_genid, 0);
77588 + atomic_set_unchecked(&net->rt_genid, 0);
77589 get_random_bytes(&net->ipv4.dev_addr_genid,
77590 sizeof(net->ipv4.dev_addr_genid));
77591 return 0;
77592 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77593 index 181fc82..57da08d 100644
77594 --- a/net/ipv4/tcp_input.c
77595 +++ b/net/ipv4/tcp_input.c
77596 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77597 * simplifies code)
77598 */
77599 static void
77600 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77601 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77602 struct sk_buff *head, struct sk_buff *tail,
77603 u32 start, u32 end)
77604 {
77605 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77606 index 0c4a643..e584990 100644
77607 --- a/net/ipv4/tcp_ipv4.c
77608 +++ b/net/ipv4/tcp_ipv4.c
77609 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77610 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77611
77612
77613 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77614 +extern int grsec_enable_blackhole;
77615 +#endif
77616 +
77617 #ifdef CONFIG_TCP_MD5SIG
77618 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77619 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77620 @@ -1901,6 +1905,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77621 return 0;
77622
77623 reset:
77624 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77625 + if (!grsec_enable_blackhole)
77626 +#endif
77627 tcp_v4_send_reset(rsk, skb);
77628 discard:
77629 kfree_skb(skb);
77630 @@ -2001,12 +2008,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77631 TCP_SKB_CB(skb)->sacked = 0;
77632
77633 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77634 - if (!sk)
77635 + if (!sk) {
77636 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77637 + ret = 1;
77638 +#endif
77639 goto no_tcp_socket;
77640 -
77641 + }
77642 process:
77643 - if (sk->sk_state == TCP_TIME_WAIT)
77644 + if (sk->sk_state == TCP_TIME_WAIT) {
77645 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77646 + ret = 2;
77647 +#endif
77648 goto do_time_wait;
77649 + }
77650
77651 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77652 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77653 @@ -2057,6 +2071,10 @@ no_tcp_socket:
77654 bad_packet:
77655 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77656 } else {
77657 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77658 + if (!grsec_enable_blackhole || (ret == 1 &&
77659 + (skb->dev->flags & IFF_LOOPBACK)))
77660 +#endif
77661 tcp_v4_send_reset(NULL, skb);
77662 }
77663
77664 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77665 index a7302d9..e3ec754 100644
77666 --- a/net/ipv4/tcp_minisocks.c
77667 +++ b/net/ipv4/tcp_minisocks.c
77668 @@ -27,6 +27,10 @@
77669 #include <net/inet_common.h>
77670 #include <net/xfrm.h>
77671
77672 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77673 +extern int grsec_enable_blackhole;
77674 +#endif
77675 +
77676 int sysctl_tcp_syncookies __read_mostly = 1;
77677 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77678
77679 @@ -742,7 +746,10 @@ embryonic_reset:
77680 * avoid becoming vulnerable to outside attack aiming at
77681 * resetting legit local connections.
77682 */
77683 - req->rsk_ops->send_reset(sk, skb);
77684 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77685 + if (!grsec_enable_blackhole)
77686 +#endif
77687 + req->rsk_ops->send_reset(sk, skb);
77688 } else if (fastopen) { /* received a valid RST pkt */
77689 reqsk_fastopen_remove(sk, req, true);
77690 tcp_reset(sk);
77691 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77692 index 4526fe6..1a34e43 100644
77693 --- a/net/ipv4/tcp_probe.c
77694 +++ b/net/ipv4/tcp_probe.c
77695 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77696 if (cnt + width >= len)
77697 break;
77698
77699 - if (copy_to_user(buf + cnt, tbuf, width))
77700 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77701 return -EFAULT;
77702 cnt += width;
77703 }
77704 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77705 index d47c1b4..b0584de 100644
77706 --- a/net/ipv4/tcp_timer.c
77707 +++ b/net/ipv4/tcp_timer.c
77708 @@ -22,6 +22,10 @@
77709 #include <linux/gfp.h>
77710 #include <net/tcp.h>
77711
77712 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77713 +extern int grsec_lastack_retries;
77714 +#endif
77715 +
77716 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77717 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77718 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77719 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77720 }
77721 }
77722
77723 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77724 + if ((sk->sk_state == TCP_LAST_ACK) &&
77725 + (grsec_lastack_retries > 0) &&
77726 + (grsec_lastack_retries < retry_until))
77727 + retry_until = grsec_lastack_retries;
77728 +#endif
77729 +
77730 if (retransmits_timed_out(sk, retry_until,
77731 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77732 /* Has it gone just too far? */
77733 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77734 index 79c8dbe..aceb1b6 100644
77735 --- a/net/ipv4/udp.c
77736 +++ b/net/ipv4/udp.c
77737 @@ -87,6 +87,7 @@
77738 #include <linux/types.h>
77739 #include <linux/fcntl.h>
77740 #include <linux/module.h>
77741 +#include <linux/security.h>
77742 #include <linux/socket.h>
77743 #include <linux/sockios.h>
77744 #include <linux/igmp.h>
77745 @@ -111,6 +112,10 @@
77746 #include <trace/events/skb.h>
77747 #include "udp_impl.h"
77748
77749 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77750 +extern int grsec_enable_blackhole;
77751 +#endif
77752 +
77753 struct udp_table udp_table __read_mostly;
77754 EXPORT_SYMBOL(udp_table);
77755
77756 @@ -569,6 +574,9 @@ found:
77757 return s;
77758 }
77759
77760 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77761 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77762 +
77763 /*
77764 * This routine is called by the ICMP module when it gets some
77765 * sort of error condition. If err < 0 then the socket should
77766 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77767 dport = usin->sin_port;
77768 if (dport == 0)
77769 return -EINVAL;
77770 +
77771 + err = gr_search_udp_sendmsg(sk, usin);
77772 + if (err)
77773 + return err;
77774 } else {
77775 if (sk->sk_state != TCP_ESTABLISHED)
77776 return -EDESTADDRREQ;
77777 +
77778 + err = gr_search_udp_sendmsg(sk, NULL);
77779 + if (err)
77780 + return err;
77781 +
77782 daddr = inet->inet_daddr;
77783 dport = inet->inet_dport;
77784 /* Open fast path for connected socket.
77785 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77786 udp_lib_checksum_complete(skb)) {
77787 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77788 IS_UDPLITE(sk));
77789 - atomic_inc(&sk->sk_drops);
77790 + atomic_inc_unchecked(&sk->sk_drops);
77791 __skb_unlink(skb, rcvq);
77792 __skb_queue_tail(&list_kill, skb);
77793 }
77794 @@ -1194,6 +1211,10 @@ try_again:
77795 if (!skb)
77796 goto out;
77797
77798 + err = gr_search_udp_recvmsg(sk, skb);
77799 + if (err)
77800 + goto out_free;
77801 +
77802 ulen = skb->len - sizeof(struct udphdr);
77803 copied = len;
77804 if (copied > ulen)
77805 @@ -1227,7 +1248,7 @@ try_again:
77806 if (unlikely(err)) {
77807 trace_kfree_skb(skb, udp_recvmsg);
77808 if (!peeked) {
77809 - atomic_inc(&sk->sk_drops);
77810 + atomic_inc_unchecked(&sk->sk_drops);
77811 UDP_INC_STATS_USER(sock_net(sk),
77812 UDP_MIB_INERRORS, is_udplite);
77813 }
77814 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77815
77816 drop:
77817 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77818 - atomic_inc(&sk->sk_drops);
77819 + atomic_inc_unchecked(&sk->sk_drops);
77820 kfree_skb(skb);
77821 return -1;
77822 }
77823 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77824 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77825
77826 if (!skb1) {
77827 - atomic_inc(&sk->sk_drops);
77828 + atomic_inc_unchecked(&sk->sk_drops);
77829 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77830 IS_UDPLITE(sk));
77831 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77832 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77833 goto csum_error;
77834
77835 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77836 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77837 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77838 +#endif
77839 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77840
77841 /*
77842 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77843 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
77844 0, sock_i_ino(sp),
77845 atomic_read(&sp->sk_refcnt), sp,
77846 - atomic_read(&sp->sk_drops), len);
77847 + atomic_read_unchecked(&sp->sk_drops), len);
77848 }
77849
77850 int udp4_seq_show(struct seq_file *seq, void *v)
77851 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77852 index 0424e4e..308dd43 100644
77853 --- a/net/ipv6/addrconf.c
77854 +++ b/net/ipv6/addrconf.c
77855 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77856 p.iph.ihl = 5;
77857 p.iph.protocol = IPPROTO_IPV6;
77858 p.iph.ttl = 64;
77859 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77860 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77861
77862 if (ops->ndo_do_ioctl) {
77863 mm_segment_t oldfs = get_fs();
77864 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77865 index e02faed..9780f28 100644
77866 --- a/net/ipv6/ipv6_sockglue.c
77867 +++ b/net/ipv6/ipv6_sockglue.c
77868 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77869 if (sk->sk_type != SOCK_STREAM)
77870 return -ENOPROTOOPT;
77871
77872 - msg.msg_control = optval;
77873 + msg.msg_control = (void __force_kernel *)optval;
77874 msg.msg_controllen = len;
77875 msg.msg_flags = flags;
77876
77877 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77878 index d7cb045..8c0ded6 100644
77879 --- a/net/ipv6/netfilter/ip6_tables.c
77880 +++ b/net/ipv6/netfilter/ip6_tables.c
77881 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77882 #endif
77883
77884 static int get_info(struct net *net, void __user *user,
77885 - const int *len, int compat)
77886 + int len, int compat)
77887 {
77888 char name[XT_TABLE_MAXNAMELEN];
77889 struct xt_table *t;
77890 int ret;
77891
77892 - if (*len != sizeof(struct ip6t_getinfo)) {
77893 - duprintf("length %u != %zu\n", *len,
77894 + if (len != sizeof(struct ip6t_getinfo)) {
77895 + duprintf("length %u != %zu\n", len,
77896 sizeof(struct ip6t_getinfo));
77897 return -EINVAL;
77898 }
77899 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77900 info.size = private->size;
77901 strcpy(info.name, name);
77902
77903 - if (copy_to_user(user, &info, *len) != 0)
77904 + if (copy_to_user(user, &info, len) != 0)
77905 ret = -EFAULT;
77906 else
77907 ret = 0;
77908 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77909
77910 switch (cmd) {
77911 case IP6T_SO_GET_INFO:
77912 - ret = get_info(sock_net(sk), user, len, 1);
77913 + ret = get_info(sock_net(sk), user, *len, 1);
77914 break;
77915 case IP6T_SO_GET_ENTRIES:
77916 ret = compat_get_entries(sock_net(sk), user, len);
77917 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77918
77919 switch (cmd) {
77920 case IP6T_SO_GET_INFO:
77921 - ret = get_info(sock_net(sk), user, len, 0);
77922 + ret = get_info(sock_net(sk), user, *len, 0);
77923 break;
77924
77925 case IP6T_SO_GET_ENTRIES:
77926 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77927 index d8e95c7..81422bc 100644
77928 --- a/net/ipv6/raw.c
77929 +++ b/net/ipv6/raw.c
77930 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77931 {
77932 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77933 skb_checksum_complete(skb)) {
77934 - atomic_inc(&sk->sk_drops);
77935 + atomic_inc_unchecked(&sk->sk_drops);
77936 kfree_skb(skb);
77937 return NET_RX_DROP;
77938 }
77939 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77940 struct raw6_sock *rp = raw6_sk(sk);
77941
77942 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77943 - atomic_inc(&sk->sk_drops);
77944 + atomic_inc_unchecked(&sk->sk_drops);
77945 kfree_skb(skb);
77946 return NET_RX_DROP;
77947 }
77948 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77949
77950 if (inet->hdrincl) {
77951 if (skb_checksum_complete(skb)) {
77952 - atomic_inc(&sk->sk_drops);
77953 + atomic_inc_unchecked(&sk->sk_drops);
77954 kfree_skb(skb);
77955 return NET_RX_DROP;
77956 }
77957 @@ -604,7 +604,7 @@ out:
77958 return err;
77959 }
77960
77961 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77962 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77963 struct flowi6 *fl6, struct dst_entry **dstp,
77964 unsigned int flags)
77965 {
77966 @@ -916,12 +916,15 @@ do_confirm:
77967 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77968 char __user *optval, int optlen)
77969 {
77970 + struct icmp6_filter filter;
77971 +
77972 switch (optname) {
77973 case ICMPV6_FILTER:
77974 if (optlen > sizeof(struct icmp6_filter))
77975 optlen = sizeof(struct icmp6_filter);
77976 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77977 + if (copy_from_user(&filter, optval, optlen))
77978 return -EFAULT;
77979 + raw6_sk(sk)->filter = filter;
77980 return 0;
77981 default:
77982 return -ENOPROTOOPT;
77983 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77984 char __user *optval, int __user *optlen)
77985 {
77986 int len;
77987 + struct icmp6_filter filter;
77988
77989 switch (optname) {
77990 case ICMPV6_FILTER:
77991 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77992 len = sizeof(struct icmp6_filter);
77993 if (put_user(len, optlen))
77994 return -EFAULT;
77995 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77996 + filter = raw6_sk(sk)->filter;
77997 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77998 return -EFAULT;
77999 return 0;
78000 default:
78001 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78002 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
78003 0,
78004 sock_i_ino(sp),
78005 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78006 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
78007 }
78008
78009 static int raw6_seq_show(struct seq_file *seq, void *v)
78010 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78011 index 26175bf..fc3e4fb 100644
78012 --- a/net/ipv6/tcp_ipv6.c
78013 +++ b/net/ipv6/tcp_ipv6.c
78014 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78015 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78016 }
78017
78018 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78019 +extern int grsec_enable_blackhole;
78020 +#endif
78021 +
78022 static void tcp_v6_hash(struct sock *sk)
78023 {
78024 if (sk->sk_state != TCP_CLOSE) {
78025 @@ -1524,6 +1528,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78026 return 0;
78027
78028 reset:
78029 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78030 + if (!grsec_enable_blackhole)
78031 +#endif
78032 tcp_v6_send_reset(sk, skb);
78033 discard:
78034 if (opt_skb)
78035 @@ -1605,12 +1612,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78036 TCP_SKB_CB(skb)->sacked = 0;
78037
78038 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78039 - if (!sk)
78040 + if (!sk) {
78041 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78042 + ret = 1;
78043 +#endif
78044 goto no_tcp_socket;
78045 + }
78046
78047 process:
78048 - if (sk->sk_state == TCP_TIME_WAIT)
78049 + if (sk->sk_state == TCP_TIME_WAIT) {
78050 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78051 + ret = 2;
78052 +#endif
78053 goto do_time_wait;
78054 + }
78055
78056 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78057 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78058 @@ -1659,6 +1674,10 @@ no_tcp_socket:
78059 bad_packet:
78060 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78061 } else {
78062 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78063 + if (!grsec_enable_blackhole || (ret == 1 &&
78064 + (skb->dev->flags & IFF_LOOPBACK)))
78065 +#endif
78066 tcp_v6_send_reset(NULL, skb);
78067 }
78068
78069 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78070 index fc99972..69397e8 100644
78071 --- a/net/ipv6/udp.c
78072 +++ b/net/ipv6/udp.c
78073 @@ -51,6 +51,10 @@
78074 #include <trace/events/skb.h>
78075 #include "udp_impl.h"
78076
78077 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78078 +extern int grsec_enable_blackhole;
78079 +#endif
78080 +
78081 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78082 {
78083 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78084 @@ -395,7 +399,7 @@ try_again:
78085 if (unlikely(err)) {
78086 trace_kfree_skb(skb, udpv6_recvmsg);
78087 if (!peeked) {
78088 - atomic_inc(&sk->sk_drops);
78089 + atomic_inc_unchecked(&sk->sk_drops);
78090 if (is_udp4)
78091 UDP_INC_STATS_USER(sock_net(sk),
78092 UDP_MIB_INERRORS,
78093 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78094 return rc;
78095 drop:
78096 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78097 - atomic_inc(&sk->sk_drops);
78098 + atomic_inc_unchecked(&sk->sk_drops);
78099 kfree_skb(skb);
78100 return -1;
78101 }
78102 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78103 if (likely(skb1 == NULL))
78104 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78105 if (!skb1) {
78106 - atomic_inc(&sk->sk_drops);
78107 + atomic_inc_unchecked(&sk->sk_drops);
78108 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78109 IS_UDPLITE(sk));
78110 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78111 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78112 goto discard;
78113
78114 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78115 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78116 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78117 +#endif
78118 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78119
78120 kfree_skb(skb);
78121 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78122 0,
78123 sock_i_ino(sp),
78124 atomic_read(&sp->sk_refcnt), sp,
78125 - atomic_read(&sp->sk_drops));
78126 + atomic_read_unchecked(&sp->sk_drops));
78127 }
78128
78129 int udp6_seq_show(struct seq_file *seq, void *v)
78130 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78131 index 496ce2c..f79fac8 100644
78132 --- a/net/irda/ircomm/ircomm_tty.c
78133 +++ b/net/irda/ircomm/ircomm_tty.c
78134 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78135 add_wait_queue(&port->open_wait, &wait);
78136
78137 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78138 - __FILE__, __LINE__, tty->driver->name, port->count);
78139 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78140
78141 spin_lock_irqsave(&port->lock, flags);
78142 if (!tty_hung_up_p(filp)) {
78143 extra_count = 1;
78144 - port->count--;
78145 + atomic_dec(&port->count);
78146 }
78147 spin_unlock_irqrestore(&port->lock, flags);
78148 port->blocked_open++;
78149 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78150 }
78151
78152 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78153 - __FILE__, __LINE__, tty->driver->name, port->count);
78154 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78155
78156 schedule();
78157 }
78158 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78159 if (extra_count) {
78160 /* ++ is not atomic, so this should be protected - Jean II */
78161 spin_lock_irqsave(&port->lock, flags);
78162 - port->count++;
78163 + atomic_inc(&port->count);
78164 spin_unlock_irqrestore(&port->lock, flags);
78165 }
78166 port->blocked_open--;
78167
78168 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78169 - __FILE__, __LINE__, tty->driver->name, port->count);
78170 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78171
78172 if (!retval)
78173 port->flags |= ASYNC_NORMAL_ACTIVE;
78174 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78175
78176 /* ++ is not atomic, so this should be protected - Jean II */
78177 spin_lock_irqsave(&self->port.lock, flags);
78178 - self->port.count++;
78179 + atomic_inc(&self->port.count);
78180 spin_unlock_irqrestore(&self->port.lock, flags);
78181 tty_port_tty_set(&self->port, tty);
78182
78183 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78184 - self->line, self->port.count);
78185 + self->line, atomic_read(&self->port.count));
78186
78187 /* Not really used by us, but lets do it anyway */
78188 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78189 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78190 tty_kref_put(port->tty);
78191 }
78192 port->tty = NULL;
78193 - port->count = 0;
78194 + atomic_set(&port->count, 0);
78195 spin_unlock_irqrestore(&port->lock, flags);
78196
78197 wake_up_interruptible(&port->open_wait);
78198 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78199 seq_putc(m, '\n');
78200
78201 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78202 - seq_printf(m, "Open count: %d\n", self->port.count);
78203 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
78204 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78205 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78206
78207 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78208 index cd6f7a9..e63fe89 100644
78209 --- a/net/iucv/af_iucv.c
78210 +++ b/net/iucv/af_iucv.c
78211 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78212
78213 write_lock_bh(&iucv_sk_list.lock);
78214
78215 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78216 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78217 while (__iucv_get_sock_by_name(name)) {
78218 sprintf(name, "%08x",
78219 - atomic_inc_return(&iucv_sk_list.autobind_name));
78220 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78221 }
78222
78223 write_unlock_bh(&iucv_sk_list.lock);
78224 diff --git a/net/key/af_key.c b/net/key/af_key.c
78225 index 08897a3..0b812ab 100644
78226 --- a/net/key/af_key.c
78227 +++ b/net/key/af_key.c
78228 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78229 static u32 get_acqseq(void)
78230 {
78231 u32 res;
78232 - static atomic_t acqseq;
78233 + static atomic_unchecked_t acqseq;
78234
78235 do {
78236 - res = atomic_inc_return(&acqseq);
78237 + res = atomic_inc_return_unchecked(&acqseq);
78238 } while (!res);
78239 return res;
78240 }
78241 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
78242 index 7371f67..9897314 100644
78243 --- a/net/mac80211/cfg.c
78244 +++ b/net/mac80211/cfg.c
78245 @@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
78246 else
78247 local->probe_req_reg--;
78248
78249 - if (!local->open_count)
78250 + if (!local_read(&local->open_count))
78251 break;
78252
78253 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
78254 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78255 index 156e583..900a7c7 100644
78256 --- a/net/mac80211/ieee80211_i.h
78257 +++ b/net/mac80211/ieee80211_i.h
78258 @@ -28,6 +28,7 @@
78259 #include <net/ieee80211_radiotap.h>
78260 #include <net/cfg80211.h>
78261 #include <net/mac80211.h>
78262 +#include <asm/local.h>
78263 #include "key.h"
78264 #include "sta_info.h"
78265 #include "debug.h"
78266 @@ -848,7 +849,7 @@ struct ieee80211_local {
78267 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78268 spinlock_t queue_stop_reason_lock;
78269
78270 - int open_count;
78271 + local_t open_count;
78272 int monitors, cooked_mntrs;
78273 /* number of interfaces with corresponding FIF_ flags */
78274 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78275 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78276 index 7de7717..3de8e97 100644
78277 --- a/net/mac80211/iface.c
78278 +++ b/net/mac80211/iface.c
78279 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78280 break;
78281 }
78282
78283 - if (local->open_count == 0) {
78284 + if (local_read(&local->open_count) == 0) {
78285 res = drv_start(local);
78286 if (res)
78287 goto err_del_bss;
78288 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78289 break;
78290 }
78291
78292 - if (local->monitors == 0 && local->open_count == 0) {
78293 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78294 res = ieee80211_add_virtual_monitor(local);
78295 if (res)
78296 goto err_stop;
78297 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78298 mutex_unlock(&local->mtx);
78299
78300 if (coming_up)
78301 - local->open_count++;
78302 + local_inc(&local->open_count);
78303
78304 if (hw_reconf_flags)
78305 ieee80211_hw_config(local, hw_reconf_flags);
78306 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78307 err_del_interface:
78308 drv_remove_interface(local, sdata);
78309 err_stop:
78310 - if (!local->open_count)
78311 + if (!local_read(&local->open_count))
78312 drv_stop(local);
78313 err_del_bss:
78314 sdata->bss = NULL;
78315 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78316 }
78317
78318 if (going_down)
78319 - local->open_count--;
78320 + local_dec(&local->open_count);
78321
78322 switch (sdata->vif.type) {
78323 case NL80211_IFTYPE_AP_VLAN:
78324 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78325
78326 ieee80211_recalc_ps(local, -1);
78327
78328 - if (local->open_count == 0) {
78329 + if (local_read(&local->open_count) == 0) {
78330 if (local->ops->napi_poll)
78331 napi_disable(&local->napi);
78332 ieee80211_clear_tx_pending(local);
78333 @@ -859,7 +859,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78334 }
78335 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78336
78337 - if (local->monitors == local->open_count && local->monitors > 0)
78338 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78339 ieee80211_add_virtual_monitor(local);
78340 }
78341
78342 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78343 index f57f597..e0a7c03 100644
78344 --- a/net/mac80211/main.c
78345 +++ b/net/mac80211/main.c
78346 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78347 local->hw.conf.power_level = power;
78348 }
78349
78350 - if (changed && local->open_count) {
78351 + if (changed && local_read(&local->open_count)) {
78352 ret = drv_config(local, changed);
78353 /*
78354 * Goal:
78355 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78356 index 5c572e7..ecf75ce 100644
78357 --- a/net/mac80211/pm.c
78358 +++ b/net/mac80211/pm.c
78359 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78360 struct ieee80211_sub_if_data *sdata;
78361 struct sta_info *sta;
78362
78363 - if (!local->open_count)
78364 + if (!local_read(&local->open_count))
78365 goto suspend;
78366
78367 ieee80211_scan_cancel(local);
78368 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78369 cancel_work_sync(&local->dynamic_ps_enable_work);
78370 del_timer_sync(&local->dynamic_ps_timer);
78371
78372 - local->wowlan = wowlan && local->open_count;
78373 + local->wowlan = wowlan && local_read(&local->open_count);
78374 if (local->wowlan) {
78375 int err = drv_suspend(local, wowlan);
78376 if (err < 0) {
78377 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78378 drv_remove_interface(local, sdata);
78379
78380 /* stop hardware - this must stop RX */
78381 - if (local->open_count)
78382 + if (local_read(&local->open_count))
78383 ieee80211_stop_device(local);
78384
78385 suspend:
78386 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78387 index 3313c11..bec9f17 100644
78388 --- a/net/mac80211/rate.c
78389 +++ b/net/mac80211/rate.c
78390 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78391
78392 ASSERT_RTNL();
78393
78394 - if (local->open_count)
78395 + if (local_read(&local->open_count))
78396 return -EBUSY;
78397
78398 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78399 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78400 index c97a065..ff61928 100644
78401 --- a/net/mac80211/rc80211_pid_debugfs.c
78402 +++ b/net/mac80211/rc80211_pid_debugfs.c
78403 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78404
78405 spin_unlock_irqrestore(&events->lock, status);
78406
78407 - if (copy_to_user(buf, pb, p))
78408 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78409 return -EFAULT;
78410
78411 return p;
78412 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78413 index 0151ae3..26709d3 100644
78414 --- a/net/mac80211/util.c
78415 +++ b/net/mac80211/util.c
78416 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78417 }
78418 #endif
78419 /* everything else happens only if HW was up & running */
78420 - if (!local->open_count)
78421 + if (!local_read(&local->open_count))
78422 goto wake_up;
78423
78424 /*
78425 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78426 index fefa514..0755f23 100644
78427 --- a/net/netfilter/Kconfig
78428 +++ b/net/netfilter/Kconfig
78429 @@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
78430
78431 To compile it as a module, choose M here. If unsure, say N.
78432
78433 +config NETFILTER_XT_MATCH_GRADM
78434 + tristate '"gradm" match support'
78435 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78436 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78437 + ---help---
78438 + The gradm match allows to match on grsecurity RBAC being enabled.
78439 + It is useful when iptables rules are applied early on bootup to
78440 + prevent connections to the machine (except from a trusted host)
78441 + while the RBAC system is disabled.
78442 +
78443 config NETFILTER_XT_MATCH_HASHLIMIT
78444 tristate '"hashlimit" match support'
78445 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78446 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78447 index 3259697..54d5393 100644
78448 --- a/net/netfilter/Makefile
78449 +++ b/net/netfilter/Makefile
78450 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78451 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78452 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78453 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78454 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78455 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78456 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78457 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78458 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78459 index 1548df9..98ad9b4 100644
78460 --- a/net/netfilter/ipvs/ip_vs_conn.c
78461 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78462 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78463 /* Increase the refcnt counter of the dest */
78464 atomic_inc(&dest->refcnt);
78465
78466 - conn_flags = atomic_read(&dest->conn_flags);
78467 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78468 if (cp->protocol != IPPROTO_UDP)
78469 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78470 flags = cp->flags;
78471 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78472 atomic_set(&cp->refcnt, 1);
78473
78474 atomic_set(&cp->n_control, 0);
78475 - atomic_set(&cp->in_pkts, 0);
78476 + atomic_set_unchecked(&cp->in_pkts, 0);
78477
78478 atomic_inc(&ipvs->conn_count);
78479 if (flags & IP_VS_CONN_F_NO_CPORT)
78480 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78481
78482 /* Don't drop the entry if its number of incoming packets is not
78483 located in [0, 8] */
78484 - i = atomic_read(&cp->in_pkts);
78485 + i = atomic_read_unchecked(&cp->in_pkts);
78486 if (i > 8 || i < 0) return 0;
78487
78488 if (!todrop_rate[i]) return 0;
78489 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78490 index 58918e2..4d177a9 100644
78491 --- a/net/netfilter/ipvs/ip_vs_core.c
78492 +++ b/net/netfilter/ipvs/ip_vs_core.c
78493 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78494 ret = cp->packet_xmit(skb, cp, pd->pp);
78495 /* do not touch skb anymore */
78496
78497 - atomic_inc(&cp->in_pkts);
78498 + atomic_inc_unchecked(&cp->in_pkts);
78499 ip_vs_conn_put(cp);
78500 return ret;
78501 }
78502 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78503 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78504 pkts = sysctl_sync_threshold(ipvs);
78505 else
78506 - pkts = atomic_add_return(1, &cp->in_pkts);
78507 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78508
78509 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78510 ip_vs_sync_conn(net, cp, pkts);
78511 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78512 index c4ee437..a774a74 100644
78513 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78514 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78515 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78516 ip_vs_rs_hash(ipvs, dest);
78517 write_unlock_bh(&ipvs->rs_lock);
78518 }
78519 - atomic_set(&dest->conn_flags, conn_flags);
78520 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78521
78522 /* bind the service */
78523 if (!dest->svc) {
78524 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78525 " %-7s %-6d %-10d %-10d\n",
78526 &dest->addr.in6,
78527 ntohs(dest->port),
78528 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78529 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78530 atomic_read(&dest->weight),
78531 atomic_read(&dest->activeconns),
78532 atomic_read(&dest->inactconns));
78533 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78534 "%-7s %-6d %-10d %-10d\n",
78535 ntohl(dest->addr.ip),
78536 ntohs(dest->port),
78537 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78538 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78539 atomic_read(&dest->weight),
78540 atomic_read(&dest->activeconns),
78541 atomic_read(&dest->inactconns));
78542 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78543
78544 entry.addr = dest->addr.ip;
78545 entry.port = dest->port;
78546 - entry.conn_flags = atomic_read(&dest->conn_flags);
78547 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78548 entry.weight = atomic_read(&dest->weight);
78549 entry.u_threshold = dest->u_threshold;
78550 entry.l_threshold = dest->l_threshold;
78551 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78552 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78553 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78554 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78555 - (atomic_read(&dest->conn_flags) &
78556 + (atomic_read_unchecked(&dest->conn_flags) &
78557 IP_VS_CONN_F_FWD_MASK)) ||
78558 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78559 atomic_read(&dest->weight)) ||
78560 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78561 index effa10c..9058928 100644
78562 --- a/net/netfilter/ipvs/ip_vs_sync.c
78563 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78564 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78565 cp = cp->control;
78566 if (cp) {
78567 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78568 - pkts = atomic_add_return(1, &cp->in_pkts);
78569 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78570 else
78571 pkts = sysctl_sync_threshold(ipvs);
78572 ip_vs_sync_conn(net, cp->control, pkts);
78573 @@ -758,7 +758,7 @@ control:
78574 if (!cp)
78575 return;
78576 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78577 - pkts = atomic_add_return(1, &cp->in_pkts);
78578 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78579 else
78580 pkts = sysctl_sync_threshold(ipvs);
78581 goto sloop;
78582 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78583
78584 if (opt)
78585 memcpy(&cp->in_seq, opt, sizeof(*opt));
78586 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78587 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78588 cp->state = state;
78589 cp->old_state = cp->state;
78590 /*
78591 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78592 index cc4c809..50f8fe5 100644
78593 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78594 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78595 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78596 else
78597 rc = NF_ACCEPT;
78598 /* do not touch skb anymore */
78599 - atomic_inc(&cp->in_pkts);
78600 + atomic_inc_unchecked(&cp->in_pkts);
78601 goto out;
78602 }
78603
78604 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78605 else
78606 rc = NF_ACCEPT;
78607 /* do not touch skb anymore */
78608 - atomic_inc(&cp->in_pkts);
78609 + atomic_inc_unchecked(&cp->in_pkts);
78610 goto out;
78611 }
78612
78613 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78614 index 0f241be..2c9be6d 100644
78615 --- a/net/netfilter/nf_conntrack_core.c
78616 +++ b/net/netfilter/nf_conntrack_core.c
78617 @@ -1532,6 +1532,10 @@ err_extend:
78618 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78619 #define DYING_NULLS_VAL ((1<<30)+1)
78620
78621 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78622 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78623 +#endif
78624 +
78625 static int nf_conntrack_init_net(struct net *net)
78626 {
78627 int ret;
78628 @@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
78629 goto err_stat;
78630 }
78631
78632 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78633 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78634 +#else
78635 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78636 +#endif
78637 if (!net->ct.slabname) {
78638 ret = -ENOMEM;
78639 goto err_slabname;
78640 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78641 index 9f199f2..719ad23 100644
78642 --- a/net/netfilter/nfnetlink_log.c
78643 +++ b/net/netfilter/nfnetlink_log.c
78644 @@ -71,7 +71,7 @@ struct nfulnl_instance {
78645 };
78646
78647 static DEFINE_SPINLOCK(instances_lock);
78648 -static atomic_t global_seq;
78649 +static atomic_unchecked_t global_seq;
78650
78651 #define INSTANCE_BUCKETS 16
78652 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78653 @@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78654 /* global sequence number */
78655 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78656 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78657 - htonl(atomic_inc_return(&global_seq))))
78658 + htonl(atomic_inc_return_unchecked(&global_seq))))
78659 goto nla_put_failure;
78660
78661 if (data_len) {
78662 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78663 new file mode 100644
78664 index 0000000..c566332
78665 --- /dev/null
78666 +++ b/net/netfilter/xt_gradm.c
78667 @@ -0,0 +1,51 @@
78668 +/*
78669 + * gradm match for netfilter
78670 + * Copyright © Zbigniew Krzystolik, 2010
78671 + *
78672 + * This program is free software; you can redistribute it and/or modify
78673 + * it under the terms of the GNU General Public License; either version
78674 + * 2 or 3 as published by the Free Software Foundation.
78675 + */
78676 +#include <linux/module.h>
78677 +#include <linux/moduleparam.h>
78678 +#include <linux/skbuff.h>
78679 +#include <linux/netfilter/x_tables.h>
78680 +#include <linux/grsecurity.h>
78681 +#include <linux/netfilter/xt_gradm.h>
78682 +
78683 +static bool
78684 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78685 +{
78686 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78687 + bool retval = false;
78688 + if (gr_acl_is_enabled())
78689 + retval = true;
78690 + return retval ^ info->invflags;
78691 +}
78692 +
78693 +static struct xt_match gradm_mt_reg __read_mostly = {
78694 + .name = "gradm",
78695 + .revision = 0,
78696 + .family = NFPROTO_UNSPEC,
78697 + .match = gradm_mt,
78698 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78699 + .me = THIS_MODULE,
78700 +};
78701 +
78702 +static int __init gradm_mt_init(void)
78703 +{
78704 + return xt_register_match(&gradm_mt_reg);
78705 +}
78706 +
78707 +static void __exit gradm_mt_exit(void)
78708 +{
78709 + xt_unregister_match(&gradm_mt_reg);
78710 +}
78711 +
78712 +module_init(gradm_mt_init);
78713 +module_exit(gradm_mt_exit);
78714 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78715 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78716 +MODULE_LICENSE("GPL");
78717 +MODULE_ALIAS("ipt_gradm");
78718 +MODULE_ALIAS("ip6t_gradm");
78719 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78720 index 4fe4fb4..87a89e5 100644
78721 --- a/net/netfilter/xt_statistic.c
78722 +++ b/net/netfilter/xt_statistic.c
78723 @@ -19,7 +19,7 @@
78724 #include <linux/module.h>
78725
78726 struct xt_statistic_priv {
78727 - atomic_t count;
78728 + atomic_unchecked_t count;
78729 } ____cacheline_aligned_in_smp;
78730
78731 MODULE_LICENSE("GPL");
78732 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78733 break;
78734 case XT_STATISTIC_MODE_NTH:
78735 do {
78736 - oval = atomic_read(&info->master->count);
78737 + oval = atomic_read_unchecked(&info->master->count);
78738 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78739 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78740 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78741 if (nval == 0)
78742 ret = !ret;
78743 break;
78744 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78745 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78746 if (info->master == NULL)
78747 return -ENOMEM;
78748 - atomic_set(&info->master->count, info->u.nth.count);
78749 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78750
78751 return 0;
78752 }
78753 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78754 index 4da797f..eb1df70 100644
78755 --- a/net/netlink/af_netlink.c
78756 +++ b/net/netlink/af_netlink.c
78757 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
78758 sk->sk_error_report(sk);
78759 }
78760 }
78761 - atomic_inc(&sk->sk_drops);
78762 + atomic_inc_unchecked(&sk->sk_drops);
78763 }
78764
78765 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
78766 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78767 sk_wmem_alloc_get(s),
78768 nlk->cb,
78769 atomic_read(&s->sk_refcnt),
78770 - atomic_read(&s->sk_drops),
78771 + atomic_read_unchecked(&s->sk_drops),
78772 sock_i_ino(s)
78773 );
78774
78775 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78776 index 7261eb8..44e8ac6 100644
78777 --- a/net/netrom/af_netrom.c
78778 +++ b/net/netrom/af_netrom.c
78779 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78780 struct sock *sk = sock->sk;
78781 struct nr_sock *nr = nr_sk(sk);
78782
78783 + memset(sax, 0, sizeof(*sax));
78784 lock_sock(sk);
78785 if (peer != 0) {
78786 if (sk->sk_state != TCP_ESTABLISHED) {
78787 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78788 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78789 } else {
78790 sax->fsa_ax25.sax25_family = AF_NETROM;
78791 - sax->fsa_ax25.sax25_ndigis = 0;
78792 sax->fsa_ax25.sax25_call = nr->source_addr;
78793 *uaddr_len = sizeof(struct sockaddr_ax25);
78794 }
78795 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78796 index 94060ed..9c066f3 100644
78797 --- a/net/packet/af_packet.c
78798 +++ b/net/packet/af_packet.c
78799 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78800
78801 spin_lock(&sk->sk_receive_queue.lock);
78802 po->stats.tp_packets++;
78803 - skb->dropcount = atomic_read(&sk->sk_drops);
78804 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78805 __skb_queue_tail(&sk->sk_receive_queue, skb);
78806 spin_unlock(&sk->sk_receive_queue.lock);
78807 sk->sk_data_ready(sk, skb->len);
78808 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78809 drop_n_acct:
78810 spin_lock(&sk->sk_receive_queue.lock);
78811 po->stats.tp_drops++;
78812 - atomic_inc(&sk->sk_drops);
78813 + atomic_inc_unchecked(&sk->sk_drops);
78814 spin_unlock(&sk->sk_receive_queue.lock);
78815
78816 drop_n_restore:
78817 @@ -2537,6 +2537,7 @@ out:
78818
78819 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78820 {
78821 + struct sock_extended_err ee;
78822 struct sock_exterr_skb *serr;
78823 struct sk_buff *skb, *skb2;
78824 int copied, err;
78825 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78826 sock_recv_timestamp(msg, sk, skb);
78827
78828 serr = SKB_EXT_ERR(skb);
78829 + ee = serr->ee;
78830 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78831 - sizeof(serr->ee), &serr->ee);
78832 + sizeof ee, &ee);
78833
78834 msg->msg_flags |= MSG_ERRQUEUE;
78835 err = copied;
78836 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78837 case PACKET_HDRLEN:
78838 if (len > sizeof(int))
78839 len = sizeof(int);
78840 - if (copy_from_user(&val, optval, len))
78841 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78842 return -EFAULT;
78843 switch (val) {
78844 case TPACKET_V1:
78845 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78846 len = lv;
78847 if (put_user(len, optlen))
78848 return -EFAULT;
78849 - if (copy_to_user(optval, data, len))
78850 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78851 return -EFAULT;
78852 return 0;
78853 }
78854 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78855 index 5a940db..f0b9c12 100644
78856 --- a/net/phonet/af_phonet.c
78857 +++ b/net/phonet/af_phonet.c
78858 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78859 {
78860 struct phonet_protocol *pp;
78861
78862 - if (protocol >= PHONET_NPROTO)
78863 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78864 return NULL;
78865
78866 rcu_read_lock();
78867 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78868 {
78869 int err = 0;
78870
78871 - if (protocol >= PHONET_NPROTO)
78872 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78873 return -EINVAL;
78874
78875 err = proto_register(pp->prot, 1);
78876 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78877 index 576f22c..bc7a71b 100644
78878 --- a/net/phonet/pep.c
78879 +++ b/net/phonet/pep.c
78880 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78881
78882 case PNS_PEP_CTRL_REQ:
78883 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78884 - atomic_inc(&sk->sk_drops);
78885 + atomic_inc_unchecked(&sk->sk_drops);
78886 break;
78887 }
78888 __skb_pull(skb, 4);
78889 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78890 }
78891
78892 if (pn->rx_credits == 0) {
78893 - atomic_inc(&sk->sk_drops);
78894 + atomic_inc_unchecked(&sk->sk_drops);
78895 err = -ENOBUFS;
78896 break;
78897 }
78898 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78899 }
78900
78901 if (pn->rx_credits == 0) {
78902 - atomic_inc(&sk->sk_drops);
78903 + atomic_inc_unchecked(&sk->sk_drops);
78904 err = NET_RX_DROP;
78905 break;
78906 }
78907 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78908 index b7e9827..c264c85 100644
78909 --- a/net/phonet/socket.c
78910 +++ b/net/phonet/socket.c
78911 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78912 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
78913 sock_i_ino(sk),
78914 atomic_read(&sk->sk_refcnt), sk,
78915 - atomic_read(&sk->sk_drops), &len);
78916 + atomic_read_unchecked(&sk->sk_drops), &len);
78917 }
78918 seq_printf(seq, "%*s\n", 127 - len, "");
78919 return 0;
78920 diff --git a/net/rds/cong.c b/net/rds/cong.c
78921 index e5b65ac..f3b6fb7 100644
78922 --- a/net/rds/cong.c
78923 +++ b/net/rds/cong.c
78924 @@ -78,7 +78,7 @@
78925 * finds that the saved generation number is smaller than the global generation
78926 * number, it wakes up the process.
78927 */
78928 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78929 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78930
78931 /*
78932 * Congestion monitoring
78933 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78934 rdsdebug("waking map %p for %pI4\n",
78935 map, &map->m_addr);
78936 rds_stats_inc(s_cong_update_received);
78937 - atomic_inc(&rds_cong_generation);
78938 + atomic_inc_unchecked(&rds_cong_generation);
78939 if (waitqueue_active(&map->m_waitq))
78940 wake_up(&map->m_waitq);
78941 if (waitqueue_active(&rds_poll_waitq))
78942 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78943
78944 int rds_cong_updated_since(unsigned long *recent)
78945 {
78946 - unsigned long gen = atomic_read(&rds_cong_generation);
78947 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78948
78949 if (likely(*recent == gen))
78950 return 0;
78951 diff --git a/net/rds/ib.h b/net/rds/ib.h
78952 index 8d2b3d5..227ec5b 100644
78953 --- a/net/rds/ib.h
78954 +++ b/net/rds/ib.h
78955 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78956 /* sending acks */
78957 unsigned long i_ack_flags;
78958 #ifdef KERNEL_HAS_ATOMIC64
78959 - atomic64_t i_ack_next; /* next ACK to send */
78960 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78961 #else
78962 spinlock_t i_ack_lock; /* protect i_ack_next */
78963 u64 i_ack_next; /* next ACK to send */
78964 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78965 index a1e1162..265e129 100644
78966 --- a/net/rds/ib_cm.c
78967 +++ b/net/rds/ib_cm.c
78968 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78969 /* Clear the ACK state */
78970 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78971 #ifdef KERNEL_HAS_ATOMIC64
78972 - atomic64_set(&ic->i_ack_next, 0);
78973 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78974 #else
78975 ic->i_ack_next = 0;
78976 #endif
78977 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78978 index 8d19491..05a3e65 100644
78979 --- a/net/rds/ib_recv.c
78980 +++ b/net/rds/ib_recv.c
78981 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78982 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78983 int ack_required)
78984 {
78985 - atomic64_set(&ic->i_ack_next, seq);
78986 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78987 if (ack_required) {
78988 smp_mb__before_clear_bit();
78989 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78990 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78991 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78992 smp_mb__after_clear_bit();
78993
78994 - return atomic64_read(&ic->i_ack_next);
78995 + return atomic64_read_unchecked(&ic->i_ack_next);
78996 }
78997 #endif
78998
78999 diff --git a/net/rds/iw.h b/net/rds/iw.h
79000 index 04ce3b1..48119a6 100644
79001 --- a/net/rds/iw.h
79002 +++ b/net/rds/iw.h
79003 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79004 /* sending acks */
79005 unsigned long i_ack_flags;
79006 #ifdef KERNEL_HAS_ATOMIC64
79007 - atomic64_t i_ack_next; /* next ACK to send */
79008 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79009 #else
79010 spinlock_t i_ack_lock; /* protect i_ack_next */
79011 u64 i_ack_next; /* next ACK to send */
79012 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79013 index a91e1db..cf3053f 100644
79014 --- a/net/rds/iw_cm.c
79015 +++ b/net/rds/iw_cm.c
79016 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79017 /* Clear the ACK state */
79018 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79019 #ifdef KERNEL_HAS_ATOMIC64
79020 - atomic64_set(&ic->i_ack_next, 0);
79021 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79022 #else
79023 ic->i_ack_next = 0;
79024 #endif
79025 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79026 index 4503335..db566b4 100644
79027 --- a/net/rds/iw_recv.c
79028 +++ b/net/rds/iw_recv.c
79029 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79030 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79031 int ack_required)
79032 {
79033 - atomic64_set(&ic->i_ack_next, seq);
79034 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79035 if (ack_required) {
79036 smp_mb__before_clear_bit();
79037 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79038 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79039 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79040 smp_mb__after_clear_bit();
79041
79042 - return atomic64_read(&ic->i_ack_next);
79043 + return atomic64_read_unchecked(&ic->i_ack_next);
79044 }
79045 #endif
79046
79047 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79048 index edac9ef..16bcb98 100644
79049 --- a/net/rds/tcp.c
79050 +++ b/net/rds/tcp.c
79051 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79052 int val = 1;
79053
79054 set_fs(KERNEL_DS);
79055 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79056 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79057 sizeof(val));
79058 set_fs(oldfs);
79059 }
79060 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79061 index 81cf5a4..b5826ff 100644
79062 --- a/net/rds/tcp_send.c
79063 +++ b/net/rds/tcp_send.c
79064 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79065
79066 oldfs = get_fs();
79067 set_fs(KERNEL_DS);
79068 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79069 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79070 sizeof(val));
79071 set_fs(oldfs);
79072 }
79073 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79074 index 05996d0..5a1dfe0 100644
79075 --- a/net/rxrpc/af_rxrpc.c
79076 +++ b/net/rxrpc/af_rxrpc.c
79077 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79078 __be32 rxrpc_epoch;
79079
79080 /* current debugging ID */
79081 -atomic_t rxrpc_debug_id;
79082 +atomic_unchecked_t rxrpc_debug_id;
79083
79084 /* count of skbs currently in use */
79085 atomic_t rxrpc_n_skbs;
79086 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79087 index e4d9cbc..b229649 100644
79088 --- a/net/rxrpc/ar-ack.c
79089 +++ b/net/rxrpc/ar-ack.c
79090 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79091
79092 _enter("{%d,%d,%d,%d},",
79093 call->acks_hard, call->acks_unacked,
79094 - atomic_read(&call->sequence),
79095 + atomic_read_unchecked(&call->sequence),
79096 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79097
79098 stop = 0;
79099 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79100
79101 /* each Tx packet has a new serial number */
79102 sp->hdr.serial =
79103 - htonl(atomic_inc_return(&call->conn->serial));
79104 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79105
79106 hdr = (struct rxrpc_header *) txb->head;
79107 hdr->serial = sp->hdr.serial;
79108 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79109 */
79110 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79111 {
79112 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79113 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79114 }
79115
79116 /*
79117 @@ -629,7 +629,7 @@ process_further:
79118
79119 latest = ntohl(sp->hdr.serial);
79120 hard = ntohl(ack.firstPacket);
79121 - tx = atomic_read(&call->sequence);
79122 + tx = atomic_read_unchecked(&call->sequence);
79123
79124 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79125 latest,
79126 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79127 goto maybe_reschedule;
79128
79129 send_ACK_with_skew:
79130 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79131 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79132 ntohl(ack.serial));
79133 send_ACK:
79134 mtu = call->conn->trans->peer->if_mtu;
79135 @@ -1173,7 +1173,7 @@ send_ACK:
79136 ackinfo.rxMTU = htonl(5692);
79137 ackinfo.jumbo_max = htonl(4);
79138
79139 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79140 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79141 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79142 ntohl(hdr.serial),
79143 ntohs(ack.maxSkew),
79144 @@ -1191,7 +1191,7 @@ send_ACK:
79145 send_message:
79146 _debug("send message");
79147
79148 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79149 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79150 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79151 send_message_2:
79152
79153 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79154 index a3bbb36..3341fb9 100644
79155 --- a/net/rxrpc/ar-call.c
79156 +++ b/net/rxrpc/ar-call.c
79157 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79158 spin_lock_init(&call->lock);
79159 rwlock_init(&call->state_lock);
79160 atomic_set(&call->usage, 1);
79161 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79162 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79163 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79164
79165 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79166 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79167 index 4106ca9..a338d7a 100644
79168 --- a/net/rxrpc/ar-connection.c
79169 +++ b/net/rxrpc/ar-connection.c
79170 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79171 rwlock_init(&conn->lock);
79172 spin_lock_init(&conn->state_lock);
79173 atomic_set(&conn->usage, 1);
79174 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79175 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79176 conn->avail_calls = RXRPC_MAXCALLS;
79177 conn->size_align = 4;
79178 conn->header_size = sizeof(struct rxrpc_header);
79179 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79180 index e7ed43a..6afa140 100644
79181 --- a/net/rxrpc/ar-connevent.c
79182 +++ b/net/rxrpc/ar-connevent.c
79183 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79184
79185 len = iov[0].iov_len + iov[1].iov_len;
79186
79187 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79188 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79189 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79190
79191 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79192 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79193 index 529572f..c758ca7 100644
79194 --- a/net/rxrpc/ar-input.c
79195 +++ b/net/rxrpc/ar-input.c
79196 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79197 /* track the latest serial number on this connection for ACK packet
79198 * information */
79199 serial = ntohl(sp->hdr.serial);
79200 - hi_serial = atomic_read(&call->conn->hi_serial);
79201 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79202 while (serial > hi_serial)
79203 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79204 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79205 serial);
79206
79207 /* request ACK generation for any ACK or DATA packet that requests
79208 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79209 index a693aca..81e7293 100644
79210 --- a/net/rxrpc/ar-internal.h
79211 +++ b/net/rxrpc/ar-internal.h
79212 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79213 int error; /* error code for local abort */
79214 int debug_id; /* debug ID for printks */
79215 unsigned int call_counter; /* call ID counter */
79216 - atomic_t serial; /* packet serial number counter */
79217 - atomic_t hi_serial; /* highest serial number received */
79218 + atomic_unchecked_t serial; /* packet serial number counter */
79219 + atomic_unchecked_t hi_serial; /* highest serial number received */
79220 u8 avail_calls; /* number of calls available */
79221 u8 size_align; /* data size alignment (for security) */
79222 u8 header_size; /* rxrpc + security header size */
79223 @@ -346,7 +346,7 @@ struct rxrpc_call {
79224 spinlock_t lock;
79225 rwlock_t state_lock; /* lock for state transition */
79226 atomic_t usage;
79227 - atomic_t sequence; /* Tx data packet sequence counter */
79228 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79229 u32 abort_code; /* local/remote abort code */
79230 enum { /* current state of call */
79231 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79232 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79233 */
79234 extern atomic_t rxrpc_n_skbs;
79235 extern __be32 rxrpc_epoch;
79236 -extern atomic_t rxrpc_debug_id;
79237 +extern atomic_unchecked_t rxrpc_debug_id;
79238 extern struct workqueue_struct *rxrpc_workqueue;
79239
79240 /*
79241 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79242 index 87f7135..74d3703 100644
79243 --- a/net/rxrpc/ar-local.c
79244 +++ b/net/rxrpc/ar-local.c
79245 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79246 spin_lock_init(&local->lock);
79247 rwlock_init(&local->services_lock);
79248 atomic_set(&local->usage, 1);
79249 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79250 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79251 memcpy(&local->srx, srx, sizeof(*srx));
79252 }
79253
79254 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79255 index e1ac183..b43e10e 100644
79256 --- a/net/rxrpc/ar-output.c
79257 +++ b/net/rxrpc/ar-output.c
79258 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79259 sp->hdr.cid = call->cid;
79260 sp->hdr.callNumber = call->call_id;
79261 sp->hdr.seq =
79262 - htonl(atomic_inc_return(&call->sequence));
79263 + htonl(atomic_inc_return_unchecked(&call->sequence));
79264 sp->hdr.serial =
79265 - htonl(atomic_inc_return(&conn->serial));
79266 + htonl(atomic_inc_return_unchecked(&conn->serial));
79267 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79268 sp->hdr.userStatus = 0;
79269 sp->hdr.securityIndex = conn->security_ix;
79270 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79271 index bebaa43..2644591 100644
79272 --- a/net/rxrpc/ar-peer.c
79273 +++ b/net/rxrpc/ar-peer.c
79274 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79275 INIT_LIST_HEAD(&peer->error_targets);
79276 spin_lock_init(&peer->lock);
79277 atomic_set(&peer->usage, 1);
79278 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79279 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79280 memcpy(&peer->srx, srx, sizeof(*srx));
79281
79282 rxrpc_assess_MTU_size(peer);
79283 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79284 index 38047f7..9f48511 100644
79285 --- a/net/rxrpc/ar-proc.c
79286 +++ b/net/rxrpc/ar-proc.c
79287 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79288 atomic_read(&conn->usage),
79289 rxrpc_conn_states[conn->state],
79290 key_serial(conn->key),
79291 - atomic_read(&conn->serial),
79292 - atomic_read(&conn->hi_serial));
79293 + atomic_read_unchecked(&conn->serial),
79294 + atomic_read_unchecked(&conn->hi_serial));
79295
79296 return 0;
79297 }
79298 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79299 index 92df566..87ec1bf 100644
79300 --- a/net/rxrpc/ar-transport.c
79301 +++ b/net/rxrpc/ar-transport.c
79302 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79303 spin_lock_init(&trans->client_lock);
79304 rwlock_init(&trans->conn_lock);
79305 atomic_set(&trans->usage, 1);
79306 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79307 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79308
79309 if (peer->srx.transport.family == AF_INET) {
79310 switch (peer->srx.transport_type) {
79311 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79312 index f226709..0e735a8 100644
79313 --- a/net/rxrpc/rxkad.c
79314 +++ b/net/rxrpc/rxkad.c
79315 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79316
79317 len = iov[0].iov_len + iov[1].iov_len;
79318
79319 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79320 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79321 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79322
79323 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79324 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79325
79326 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79327
79328 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79329 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79330 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79331
79332 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79333 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79334 index 9966e7b..540c575 100644
79335 --- a/net/sctp/proc.c
79336 +++ b/net/sctp/proc.c
79337 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79338 seq_printf(seq,
79339 "%8pK %8pK %-3d %-3d %-2d %-4d "
79340 "%4d %8d %8d %7d %5lu %-5d %5d ",
79341 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79342 + assoc, sk,
79343 + sctp_sk(sk)->type, sk->sk_state,
79344 assoc->state, hash,
79345 assoc->assoc_id,
79346 assoc->sndbuf_used,
79347 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79348 index 406d957..543c737 100644
79349 --- a/net/sctp/socket.c
79350 +++ b/net/sctp/socket.c
79351 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79352 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79353 if (space_left < addrlen)
79354 return -ENOMEM;
79355 + if (addrlen > sizeof(temp) || addrlen < 0)
79356 + return -EFAULT;
79357 if (copy_to_user(to, &temp, addrlen))
79358 return -EFAULT;
79359 to += addrlen;
79360 diff --git a/net/socket.c b/net/socket.c
79361 index d92c490..b4bc863 100644
79362 --- a/net/socket.c
79363 +++ b/net/socket.c
79364 @@ -89,6 +89,7 @@
79365 #include <linux/magic.h>
79366 #include <linux/slab.h>
79367 #include <linux/xattr.h>
79368 +#include <linux/in.h>
79369
79370 #include <asm/uaccess.h>
79371 #include <asm/unistd.h>
79372 @@ -106,6 +107,8 @@
79373 #include <linux/sockios.h>
79374 #include <linux/atalk.h>
79375
79376 +#include <linux/grsock.h>
79377 +
79378 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79379 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79380 unsigned long nr_segs, loff_t pos);
79381 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79382 &sockfs_dentry_operations, SOCKFS_MAGIC);
79383 }
79384
79385 -static struct vfsmount *sock_mnt __read_mostly;
79386 +struct vfsmount *sock_mnt __read_mostly;
79387
79388 static struct file_system_type sock_fs_type = {
79389 .name = "sockfs",
79390 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79391 return -EAFNOSUPPORT;
79392 if (type < 0 || type >= SOCK_MAX)
79393 return -EINVAL;
79394 + if (protocol < 0)
79395 + return -EINVAL;
79396
79397 /* Compatibility.
79398
79399 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79400 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79401 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79402
79403 + if(!gr_search_socket(family, type, protocol)) {
79404 + retval = -EACCES;
79405 + goto out;
79406 + }
79407 +
79408 + if (gr_handle_sock_all(family, type, protocol)) {
79409 + retval = -EACCES;
79410 + goto out;
79411 + }
79412 +
79413 retval = sock_create(family, type, protocol, &sock);
79414 if (retval < 0)
79415 goto out;
79416 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79417 if (sock) {
79418 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79419 if (err >= 0) {
79420 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79421 + err = -EACCES;
79422 + goto error;
79423 + }
79424 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79425 + if (err)
79426 + goto error;
79427 +
79428 err = security_socket_bind(sock,
79429 (struct sockaddr *)&address,
79430 addrlen);
79431 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79432 (struct sockaddr *)
79433 &address, addrlen);
79434 }
79435 +error:
79436 fput_light(sock->file, fput_needed);
79437 }
79438 return err;
79439 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79440 if ((unsigned int)backlog > somaxconn)
79441 backlog = somaxconn;
79442
79443 + if (gr_handle_sock_server_other(sock->sk)) {
79444 + err = -EPERM;
79445 + goto error;
79446 + }
79447 +
79448 + err = gr_search_listen(sock);
79449 + if (err)
79450 + goto error;
79451 +
79452 err = security_socket_listen(sock, backlog);
79453 if (!err)
79454 err = sock->ops->listen(sock, backlog);
79455
79456 +error:
79457 fput_light(sock->file, fput_needed);
79458 }
79459 return err;
79460 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79461 newsock->type = sock->type;
79462 newsock->ops = sock->ops;
79463
79464 + if (gr_handle_sock_server_other(sock->sk)) {
79465 + err = -EPERM;
79466 + sock_release(newsock);
79467 + goto out_put;
79468 + }
79469 +
79470 + err = gr_search_accept(sock);
79471 + if (err) {
79472 + sock_release(newsock);
79473 + goto out_put;
79474 + }
79475 +
79476 /*
79477 * We don't need try_module_get here, as the listening socket (sock)
79478 * has the protocol module (sock->ops->owner) held.
79479 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79480 fd_install(newfd, newfile);
79481 err = newfd;
79482
79483 + gr_attach_curr_ip(newsock->sk);
79484 +
79485 out_put:
79486 fput_light(sock->file, fput_needed);
79487 out:
79488 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79489 int, addrlen)
79490 {
79491 struct socket *sock;
79492 + struct sockaddr *sck;
79493 struct sockaddr_storage address;
79494 int err, fput_needed;
79495
79496 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79497 if (err < 0)
79498 goto out_put;
79499
79500 + sck = (struct sockaddr *)&address;
79501 +
79502 + if (gr_handle_sock_client(sck)) {
79503 + err = -EACCES;
79504 + goto out_put;
79505 + }
79506 +
79507 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79508 + if (err)
79509 + goto out_put;
79510 +
79511 err =
79512 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79513 if (err)
79514 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79515 * checking falls down on this.
79516 */
79517 if (copy_from_user(ctl_buf,
79518 - (void __user __force *)msg_sys->msg_control,
79519 + (void __force_user *)msg_sys->msg_control,
79520 ctl_len))
79521 goto out_freectl;
79522 msg_sys->msg_control = ctl_buf;
79523 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79524 * kernel msghdr to use the kernel address space)
79525 */
79526
79527 - uaddr = (__force void __user *)msg_sys->msg_name;
79528 + uaddr = (void __force_user *)msg_sys->msg_name;
79529 uaddr_len = COMPAT_NAMELEN(msg);
79530 if (MSG_CMSG_COMPAT & flags) {
79531 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79532 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79533 }
79534
79535 ifr = compat_alloc_user_space(buf_size);
79536 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79537 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79538
79539 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79540 return -EFAULT;
79541 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79542 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79543
79544 if (copy_in_user(rxnfc, compat_rxnfc,
79545 - (void *)(&rxnfc->fs.m_ext + 1) -
79546 - (void *)rxnfc) ||
79547 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79548 + (void __user *)rxnfc) ||
79549 copy_in_user(&rxnfc->fs.ring_cookie,
79550 &compat_rxnfc->fs.ring_cookie,
79551 - (void *)(&rxnfc->fs.location + 1) -
79552 - (void *)&rxnfc->fs.ring_cookie) ||
79553 + (void __user *)(&rxnfc->fs.location + 1) -
79554 + (void __user *)&rxnfc->fs.ring_cookie) ||
79555 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79556 sizeof(rxnfc->rule_cnt)))
79557 return -EFAULT;
79558 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79559
79560 if (convert_out) {
79561 if (copy_in_user(compat_rxnfc, rxnfc,
79562 - (const void *)(&rxnfc->fs.m_ext + 1) -
79563 - (const void *)rxnfc) ||
79564 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79565 + (const void __user *)rxnfc) ||
79566 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79567 &rxnfc->fs.ring_cookie,
79568 - (const void *)(&rxnfc->fs.location + 1) -
79569 - (const void *)&rxnfc->fs.ring_cookie) ||
79570 + (const void __user *)(&rxnfc->fs.location + 1) -
79571 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79572 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79573 sizeof(rxnfc->rule_cnt)))
79574 return -EFAULT;
79575 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79576 old_fs = get_fs();
79577 set_fs(KERNEL_DS);
79578 err = dev_ioctl(net, cmd,
79579 - (struct ifreq __user __force *) &kifr);
79580 + (struct ifreq __force_user *) &kifr);
79581 set_fs(old_fs);
79582
79583 return err;
79584 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79585
79586 old_fs = get_fs();
79587 set_fs(KERNEL_DS);
79588 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79589 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79590 set_fs(old_fs);
79591
79592 if (cmd == SIOCGIFMAP && !err) {
79593 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79594 ret |= __get_user(rtdev, &(ur4->rt_dev));
79595 if (rtdev) {
79596 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79597 - r4.rt_dev = (char __user __force *)devname;
79598 + r4.rt_dev = (char __force_user *)devname;
79599 devname[15] = 0;
79600 } else
79601 r4.rt_dev = NULL;
79602 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79603 int __user *uoptlen;
79604 int err;
79605
79606 - uoptval = (char __user __force *) optval;
79607 - uoptlen = (int __user __force *) optlen;
79608 + uoptval = (char __force_user *) optval;
79609 + uoptlen = (int __force_user *) optlen;
79610
79611 set_fs(KERNEL_DS);
79612 if (level == SOL_SOCKET)
79613 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79614 char __user *uoptval;
79615 int err;
79616
79617 - uoptval = (char __user __force *) optval;
79618 + uoptval = (char __force_user *) optval;
79619
79620 set_fs(KERNEL_DS);
79621 if (level == SOL_SOCKET)
79622 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79623 index 6357fcb..244c7db 100644
79624 --- a/net/sunrpc/sched.c
79625 +++ b/net/sunrpc/sched.c
79626 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79627 #ifdef RPC_DEBUG
79628 static void rpc_task_set_debuginfo(struct rpc_task *task)
79629 {
79630 - static atomic_t rpc_pid;
79631 + static atomic_unchecked_t rpc_pid;
79632
79633 - task->tk_pid = atomic_inc_return(&rpc_pid);
79634 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79635 }
79636 #else
79637 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79638 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79639 index 8343737..677025e 100644
79640 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79641 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79642 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79643 static unsigned int min_max_inline = 4096;
79644 static unsigned int max_max_inline = 65536;
79645
79646 -atomic_t rdma_stat_recv;
79647 -atomic_t rdma_stat_read;
79648 -atomic_t rdma_stat_write;
79649 -atomic_t rdma_stat_sq_starve;
79650 -atomic_t rdma_stat_rq_starve;
79651 -atomic_t rdma_stat_rq_poll;
79652 -atomic_t rdma_stat_rq_prod;
79653 -atomic_t rdma_stat_sq_poll;
79654 -atomic_t rdma_stat_sq_prod;
79655 +atomic_unchecked_t rdma_stat_recv;
79656 +atomic_unchecked_t rdma_stat_read;
79657 +atomic_unchecked_t rdma_stat_write;
79658 +atomic_unchecked_t rdma_stat_sq_starve;
79659 +atomic_unchecked_t rdma_stat_rq_starve;
79660 +atomic_unchecked_t rdma_stat_rq_poll;
79661 +atomic_unchecked_t rdma_stat_rq_prod;
79662 +atomic_unchecked_t rdma_stat_sq_poll;
79663 +atomic_unchecked_t rdma_stat_sq_prod;
79664
79665 /* Temporary NFS request map and context caches */
79666 struct kmem_cache *svc_rdma_map_cachep;
79667 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79668 len -= *ppos;
79669 if (len > *lenp)
79670 len = *lenp;
79671 - if (len && copy_to_user(buffer, str_buf, len))
79672 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79673 return -EFAULT;
79674 *lenp = len;
79675 *ppos += len;
79676 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79677 {
79678 .procname = "rdma_stat_read",
79679 .data = &rdma_stat_read,
79680 - .maxlen = sizeof(atomic_t),
79681 + .maxlen = sizeof(atomic_unchecked_t),
79682 .mode = 0644,
79683 .proc_handler = read_reset_stat,
79684 },
79685 {
79686 .procname = "rdma_stat_recv",
79687 .data = &rdma_stat_recv,
79688 - .maxlen = sizeof(atomic_t),
79689 + .maxlen = sizeof(atomic_unchecked_t),
79690 .mode = 0644,
79691 .proc_handler = read_reset_stat,
79692 },
79693 {
79694 .procname = "rdma_stat_write",
79695 .data = &rdma_stat_write,
79696 - .maxlen = sizeof(atomic_t),
79697 + .maxlen = sizeof(atomic_unchecked_t),
79698 .mode = 0644,
79699 .proc_handler = read_reset_stat,
79700 },
79701 {
79702 .procname = "rdma_stat_sq_starve",
79703 .data = &rdma_stat_sq_starve,
79704 - .maxlen = sizeof(atomic_t),
79705 + .maxlen = sizeof(atomic_unchecked_t),
79706 .mode = 0644,
79707 .proc_handler = read_reset_stat,
79708 },
79709 {
79710 .procname = "rdma_stat_rq_starve",
79711 .data = &rdma_stat_rq_starve,
79712 - .maxlen = sizeof(atomic_t),
79713 + .maxlen = sizeof(atomic_unchecked_t),
79714 .mode = 0644,
79715 .proc_handler = read_reset_stat,
79716 },
79717 {
79718 .procname = "rdma_stat_rq_poll",
79719 .data = &rdma_stat_rq_poll,
79720 - .maxlen = sizeof(atomic_t),
79721 + .maxlen = sizeof(atomic_unchecked_t),
79722 .mode = 0644,
79723 .proc_handler = read_reset_stat,
79724 },
79725 {
79726 .procname = "rdma_stat_rq_prod",
79727 .data = &rdma_stat_rq_prod,
79728 - .maxlen = sizeof(atomic_t),
79729 + .maxlen = sizeof(atomic_unchecked_t),
79730 .mode = 0644,
79731 .proc_handler = read_reset_stat,
79732 },
79733 {
79734 .procname = "rdma_stat_sq_poll",
79735 .data = &rdma_stat_sq_poll,
79736 - .maxlen = sizeof(atomic_t),
79737 + .maxlen = sizeof(atomic_unchecked_t),
79738 .mode = 0644,
79739 .proc_handler = read_reset_stat,
79740 },
79741 {
79742 .procname = "rdma_stat_sq_prod",
79743 .data = &rdma_stat_sq_prod,
79744 - .maxlen = sizeof(atomic_t),
79745 + .maxlen = sizeof(atomic_unchecked_t),
79746 .mode = 0644,
79747 .proc_handler = read_reset_stat,
79748 },
79749 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79750 index 41cb63b..c4a1489 100644
79751 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79752 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79753 @@ -501,7 +501,7 @@ next_sge:
79754 svc_rdma_put_context(ctxt, 0);
79755 goto out;
79756 }
79757 - atomic_inc(&rdma_stat_read);
79758 + atomic_inc_unchecked(&rdma_stat_read);
79759
79760 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79761 chl_map->ch[ch_no].count -= read_wr.num_sge;
79762 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79763 dto_q);
79764 list_del_init(&ctxt->dto_q);
79765 } else {
79766 - atomic_inc(&rdma_stat_rq_starve);
79767 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79768 clear_bit(XPT_DATA, &xprt->xpt_flags);
79769 ctxt = NULL;
79770 }
79771 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79772 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79773 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79774 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79775 - atomic_inc(&rdma_stat_recv);
79776 + atomic_inc_unchecked(&rdma_stat_recv);
79777
79778 /* Build up the XDR from the receive buffers. */
79779 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79780 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79781 index 42eb7ba..c887c45 100644
79782 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79783 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79784 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79785 write_wr.wr.rdma.remote_addr = to;
79786
79787 /* Post It */
79788 - atomic_inc(&rdma_stat_write);
79789 + atomic_inc_unchecked(&rdma_stat_write);
79790 if (svc_rdma_send(xprt, &write_wr))
79791 goto err;
79792 return 0;
79793 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79794 index 62e4f9b..dd3f2d7 100644
79795 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79796 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79797 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79798 return;
79799
79800 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79801 - atomic_inc(&rdma_stat_rq_poll);
79802 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79803
79804 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79805 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79806 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79807 }
79808
79809 if (ctxt)
79810 - atomic_inc(&rdma_stat_rq_prod);
79811 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79812
79813 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79814 /*
79815 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79816 return;
79817
79818 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79819 - atomic_inc(&rdma_stat_sq_poll);
79820 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79821 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79822 if (wc.status != IB_WC_SUCCESS)
79823 /* Close the transport */
79824 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79825 }
79826
79827 if (ctxt)
79828 - atomic_inc(&rdma_stat_sq_prod);
79829 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79830 }
79831
79832 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79833 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79834 spin_lock_bh(&xprt->sc_lock);
79835 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79836 spin_unlock_bh(&xprt->sc_lock);
79837 - atomic_inc(&rdma_stat_sq_starve);
79838 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79839
79840 /* See if we can opportunistically reap SQ WR to make room */
79841 sq_cq_reap(xprt);
79842 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79843 index e3a6e37..be2ea77 100644
79844 --- a/net/sysctl_net.c
79845 +++ b/net/sysctl_net.c
79846 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79847 struct ctl_table *table)
79848 {
79849 /* Allow network administrator to have same access as root. */
79850 - if (capable(CAP_NET_ADMIN)) {
79851 + if (capable_nolog(CAP_NET_ADMIN)) {
79852 int mode = (table->mode >> 6) & 7;
79853 return (mode << 6) | (mode << 3) | mode;
79854 }
79855 diff --git a/net/tipc/link.c b/net/tipc/link.c
79856 index a79c755..eca357d 100644
79857 --- a/net/tipc/link.c
79858 +++ b/net/tipc/link.c
79859 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79860 struct tipc_msg fragm_hdr;
79861 struct sk_buff *buf, *buf_chain, *prev;
79862 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79863 - const unchar *sect_crs;
79864 + const unchar __user *sect_crs;
79865 int curr_sect;
79866 u32 fragm_no;
79867
79868 @@ -1210,7 +1210,7 @@ again:
79869
79870 if (!sect_rest) {
79871 sect_rest = msg_sect[++curr_sect].iov_len;
79872 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79873 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79874 }
79875
79876 if (sect_rest < fragm_rest)
79877 @@ -1229,7 +1229,7 @@ error:
79878 }
79879 } else
79880 skb_copy_to_linear_data_offset(buf, fragm_crs,
79881 - sect_crs, sz);
79882 + (const void __force_kernel *)sect_crs, sz);
79883 sect_crs += sz;
79884 sect_rest -= sz;
79885 fragm_crs += sz;
79886 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79887 index f2db8a8..9245aa4 100644
79888 --- a/net/tipc/msg.c
79889 +++ b/net/tipc/msg.c
79890 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79891 msg_sect[cnt].iov_len);
79892 else
79893 skb_copy_to_linear_data_offset(*buf, pos,
79894 - msg_sect[cnt].iov_base,
79895 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79896 msg_sect[cnt].iov_len);
79897 pos += msg_sect[cnt].iov_len;
79898 }
79899 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79900 index 0f7d0d0..00f89bf 100644
79901 --- a/net/tipc/subscr.c
79902 +++ b/net/tipc/subscr.c
79903 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79904 {
79905 struct iovec msg_sect;
79906
79907 - msg_sect.iov_base = (void *)&sub->evt;
79908 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79909 msg_sect.iov_len = sizeof(struct tipc_event);
79910
79911 sub->evt.event = htohl(event, sub->swap);
79912 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79913 index 5b5c876..3127bf7 100644
79914 --- a/net/unix/af_unix.c
79915 +++ b/net/unix/af_unix.c
79916 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
79917 err = -ECONNREFUSED;
79918 if (!S_ISSOCK(inode->i_mode))
79919 goto put_fail;
79920 +
79921 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79922 + err = -EACCES;
79923 + goto put_fail;
79924 + }
79925 +
79926 u = unix_find_socket_byinode(inode);
79927 if (!u)
79928 goto put_fail;
79929 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
79930 if (u) {
79931 struct dentry *dentry;
79932 dentry = unix_sk(u)->path.dentry;
79933 +
79934 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79935 + err = -EPERM;
79936 + sock_put(u);
79937 + goto fail;
79938 + }
79939 +
79940 if (dentry)
79941 touch_atime(&unix_sk(u)->path);
79942 } else
79943 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79944 */
79945 err = security_path_mknod(&path, dentry, mode, 0);
79946 if (!err) {
79947 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79948 + err = -EACCES;
79949 + goto out;
79950 + }
79951 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79952 if (!err) {
79953 res->mnt = mntget(path.mnt);
79954 res->dentry = dget(dentry);
79955 + gr_handle_create(dentry, path.mnt);
79956 }
79957 }
79958 +out:
79959 done_path_create(&path, dentry);
79960 return err;
79961 }
79962 diff --git a/net/wireless/core.h b/net/wireless/core.h
79963 index a343be4..0c6e081 100644
79964 --- a/net/wireless/core.h
79965 +++ b/net/wireless/core.h
79966 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79967 struct mutex mtx;
79968
79969 /* rfkill support */
79970 - struct rfkill_ops rfkill_ops;
79971 + rfkill_ops_no_const rfkill_ops;
79972 struct rfkill *rfkill;
79973 struct work_struct rfkill_sync;
79974
79975 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79976 index c8717c1..08539f5 100644
79977 --- a/net/wireless/wext-core.c
79978 +++ b/net/wireless/wext-core.c
79979 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79980 */
79981
79982 /* Support for very large requests */
79983 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79984 - (user_length > descr->max_tokens)) {
79985 + if (user_length > descr->max_tokens) {
79986 /* Allow userspace to GET more than max so
79987 * we can support any size GET requests.
79988 * There is still a limit : -ENOMEM.
79989 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79990 }
79991 }
79992
79993 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79994 - /*
79995 - * If this is a GET, but not NOMAX, it means that the extra
79996 - * data is not bounded by userspace, but by max_tokens. Thus
79997 - * set the length to max_tokens. This matches the extra data
79998 - * allocation.
79999 - * The driver should fill it with the number of tokens it
80000 - * provided, and it may check iwp->length rather than having
80001 - * knowledge of max_tokens. If the driver doesn't change the
80002 - * iwp->length, this ioctl just copies back max_token tokens
80003 - * filled with zeroes. Hopefully the driver isn't claiming
80004 - * them to be valid data.
80005 - */
80006 - iwp->length = descr->max_tokens;
80007 - }
80008 -
80009 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80010
80011 iwp->length += essid_compat;
80012 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80013 index 41eabc4..8d4e6d6 100644
80014 --- a/net/xfrm/xfrm_policy.c
80015 +++ b/net/xfrm/xfrm_policy.c
80016 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80017 {
80018 policy->walk.dead = 1;
80019
80020 - atomic_inc(&policy->genid);
80021 + atomic_inc_unchecked(&policy->genid);
80022
80023 if (del_timer(&policy->timer))
80024 xfrm_pol_put(policy);
80025 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80026 hlist_add_head(&policy->bydst, chain);
80027 xfrm_pol_hold(policy);
80028 net->xfrm.policy_count[dir]++;
80029 - atomic_inc(&flow_cache_genid);
80030 + atomic_inc_unchecked(&flow_cache_genid);
80031 rt_genid_bump(net);
80032 if (delpol)
80033 __xfrm_policy_unlink(delpol, dir);
80034 @@ -1550,7 +1550,7 @@ free_dst:
80035 goto out;
80036 }
80037
80038 -static int inline
80039 +static inline int
80040 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80041 {
80042 if (!*target) {
80043 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80044 return 0;
80045 }
80046
80047 -static int inline
80048 +static inline int
80049 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80050 {
80051 #ifdef CONFIG_XFRM_SUB_POLICY
80052 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80053 #endif
80054 }
80055
80056 -static int inline
80057 +static inline int
80058 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80059 {
80060 #ifdef CONFIG_XFRM_SUB_POLICY
80061 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80062
80063 xdst->num_pols = num_pols;
80064 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80065 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80066 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80067
80068 return xdst;
80069 }
80070 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80071 if (xdst->xfrm_genid != dst->xfrm->genid)
80072 return 0;
80073 if (xdst->num_pols > 0 &&
80074 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80075 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80076 return 0;
80077
80078 mtu = dst_mtu(dst->child);
80079 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80080 sizeof(pol->xfrm_vec[i].saddr));
80081 pol->xfrm_vec[i].encap_family = mp->new_family;
80082 /* flush bundles */
80083 - atomic_inc(&pol->genid);
80084 + atomic_inc_unchecked(&pol->genid);
80085 }
80086 }
80087
80088 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80089 index 0e801c3..5c8ad3b 100644
80090 --- a/scripts/Makefile.build
80091 +++ b/scripts/Makefile.build
80092 @@ -111,7 +111,7 @@ endif
80093 endif
80094
80095 # Do not include host rules unless needed
80096 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80097 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80098 include scripts/Makefile.host
80099 endif
80100
80101 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80102 index 686cb0d..9d653bf 100644
80103 --- a/scripts/Makefile.clean
80104 +++ b/scripts/Makefile.clean
80105 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80106 __clean-files := $(extra-y) $(always) \
80107 $(targets) $(clean-files) \
80108 $(host-progs) \
80109 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80110 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80111 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80112
80113 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80114
80115 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80116 index 1ac414f..38575f7 100644
80117 --- a/scripts/Makefile.host
80118 +++ b/scripts/Makefile.host
80119 @@ -31,6 +31,8 @@
80120 # Note: Shared libraries consisting of C++ files are not supported
80121
80122 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80123 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80124 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80125
80126 # C code
80127 # Executables compiled from a single .c file
80128 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80129 # Shared libaries (only .c supported)
80130 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80131 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80132 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80133 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80134 # Remove .so files from "xxx-objs"
80135 host-cobjs := $(filter-out %.so,$(host-cobjs))
80136 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80137
80138 -#Object (.o) files used by the shared libaries
80139 +# Object (.o) files used by the shared libaries
80140 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80141 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80142
80143 # output directory for programs/.o files
80144 # hostprogs-y := tools/build may have been specified. Retrieve directory
80145 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80146 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80147 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80148 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80149 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80150 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80151 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80152 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80153
80154 obj-dirs += $(host-objdirs)
80155 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80156 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80157 $(call if_changed_dep,host-cshobjs)
80158
80159 +# Compile .c file, create position independent .o file
80160 +# host-cxxshobjs -> .o
80161 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80162 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80163 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80164 + $(call if_changed_dep,host-cxxshobjs)
80165 +
80166 # Link a shared library, based on position independent .o files
80167 # *.o -> .so shared library (host-cshlib)
80168 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80169 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80170 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80171 $(call if_changed,host-cshlib)
80172
80173 +# Link a shared library, based on position independent .o files
80174 +# *.o -> .so shared library (host-cxxshlib)
80175 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80176 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80177 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80178 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80179 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80180 + $(call if_changed,host-cxxshlib)
80181 +
80182 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80183 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80184 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80185
80186 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80187 index cb1f50c..cef2a7c 100644
80188 --- a/scripts/basic/fixdep.c
80189 +++ b/scripts/basic/fixdep.c
80190 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80191 /*
80192 * Lookup a value in the configuration string.
80193 */
80194 -static int is_defined_config(const char *name, int len, unsigned int hash)
80195 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80196 {
80197 struct item *aux;
80198
80199 @@ -211,10 +211,10 @@ static void clear_config(void)
80200 /*
80201 * Record the use of a CONFIG_* word.
80202 */
80203 -static void use_config(const char *m, int slen)
80204 +static void use_config(const char *m, unsigned int slen)
80205 {
80206 unsigned int hash = strhash(m, slen);
80207 - int c, i;
80208 + unsigned int c, i;
80209
80210 if (is_defined_config(m, slen, hash))
80211 return;
80212 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80213
80214 static void parse_config_file(const char *map, size_t len)
80215 {
80216 - const int *end = (const int *) (map + len);
80217 + const unsigned int *end = (const unsigned int *) (map + len);
80218 /* start at +1, so that p can never be < map */
80219 - const int *m = (const int *) map + 1;
80220 + const unsigned int *m = (const unsigned int *) map + 1;
80221 const char *p, *q;
80222
80223 for (; m < end; m++) {
80224 @@ -406,7 +406,7 @@ static void print_deps(void)
80225 static void traps(void)
80226 {
80227 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80228 - int *p = (int *)test;
80229 + unsigned int *p = (unsigned int *)test;
80230
80231 if (*p != INT_CONF) {
80232 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80233 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80234 new file mode 100644
80235 index 0000000..008ac1a
80236 --- /dev/null
80237 +++ b/scripts/gcc-plugin.sh
80238 @@ -0,0 +1,17 @@
80239 +#!/bin/bash
80240 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80241 +#include "gcc-plugin.h"
80242 +#include "tree.h"
80243 +#include "tm.h"
80244 +#include "rtl.h"
80245 +#ifdef ENABLE_BUILD_WITH_CXX
80246 +#warning $2
80247 +#else
80248 +#warning $1
80249 +#endif
80250 +EOF`
80251 +if [ $? -eq 0 ]
80252 +then
80253 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80254 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80255 +fi
80256 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80257 index b3d907e..a4782ab 100644
80258 --- a/scripts/link-vmlinux.sh
80259 +++ b/scripts/link-vmlinux.sh
80260 @@ -152,7 +152,7 @@ else
80261 fi;
80262
80263 # final build of init/
80264 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80265 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80266
80267 kallsymso=""
80268 kallsyms_vmlinux=""
80269 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80270 index df4fc23..0ea719d 100644
80271 --- a/scripts/mod/file2alias.c
80272 +++ b/scripts/mod/file2alias.c
80273 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80274 unsigned long size, unsigned long id_size,
80275 void *symval)
80276 {
80277 - int i;
80278 + unsigned int i;
80279
80280 if (size % id_size || size < id_size) {
80281 if (cross_build != 0)
80282 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80283 /* USB is special because the bcdDevice can be matched against a numeric range */
80284 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80285 static void do_usb_entry(struct usb_device_id *id,
80286 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80287 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80288 unsigned char range_lo, unsigned char range_hi,
80289 unsigned char max, struct module *mod)
80290 {
80291 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80292 {
80293 unsigned int devlo, devhi;
80294 unsigned char chi, clo, max;
80295 - int ndigits;
80296 + unsigned int ndigits;
80297
80298 id->match_flags = TO_NATIVE(id->match_flags);
80299 id->idVendor = TO_NATIVE(id->idVendor);
80300 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80301 for (i = 0; i < count; i++) {
80302 const char *id = (char *)devs[i].id;
80303 char acpi_id[sizeof(devs[0].id)];
80304 - int j;
80305 + unsigned int j;
80306
80307 buf_printf(&mod->dev_table_buf,
80308 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80309 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80310
80311 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80312 const char *id = (char *)card->devs[j].id;
80313 - int i2, j2;
80314 + unsigned int i2, j2;
80315 int dup = 0;
80316
80317 if (!id[0])
80318 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80319 /* add an individual alias for every device entry */
80320 if (!dup) {
80321 char acpi_id[sizeof(card->devs[0].id)];
80322 - int k;
80323 + unsigned int k;
80324
80325 buf_printf(&mod->dev_table_buf,
80326 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80327 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80328 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80329 char *alias)
80330 {
80331 - int i, j;
80332 + unsigned int i, j;
80333
80334 sprintf(alias, "dmi*");
80335
80336 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80337 index 0d93856..e828363 100644
80338 --- a/scripts/mod/modpost.c
80339 +++ b/scripts/mod/modpost.c
80340 @@ -933,6 +933,7 @@ enum mismatch {
80341 ANY_INIT_TO_ANY_EXIT,
80342 ANY_EXIT_TO_ANY_INIT,
80343 EXPORT_TO_INIT_EXIT,
80344 + DATA_TO_TEXT
80345 };
80346
80347 struct sectioncheck {
80348 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
80349 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80350 .mismatch = EXPORT_TO_INIT_EXIT,
80351 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80352 +},
80353 +/* Do not reference code from writable data */
80354 +{
80355 + .fromsec = { DATA_SECTIONS, NULL },
80356 + .tosec = { TEXT_SECTIONS, NULL },
80357 + .mismatch = DATA_TO_TEXT
80358 }
80359 };
80360
80361 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80362 continue;
80363 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80364 continue;
80365 - if (sym->st_value == addr)
80366 - return sym;
80367 /* Find a symbol nearby - addr are maybe negative */
80368 d = sym->st_value - addr;
80369 + if (d == 0)
80370 + return sym;
80371 if (d < 0)
80372 d = addr - sym->st_value;
80373 if (d < distance) {
80374 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
80375 tosym, prl_to, prl_to, tosym);
80376 free(prl_to);
80377 break;
80378 + case DATA_TO_TEXT:
80379 +#if 0
80380 + fprintf(stderr,
80381 + "The %s %s:%s references\n"
80382 + "the %s %s:%s%s\n",
80383 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80384 +#endif
80385 + break;
80386 }
80387 fprintf(stderr, "\n");
80388 }
80389 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80390 static void check_sec_ref(struct module *mod, const char *modname,
80391 struct elf_info *elf)
80392 {
80393 - int i;
80394 + unsigned int i;
80395 Elf_Shdr *sechdrs = elf->sechdrs;
80396
80397 /* Walk through all sections */
80398 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80399 va_end(ap);
80400 }
80401
80402 -void buf_write(struct buffer *buf, const char *s, int len)
80403 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80404 {
80405 if (buf->size - buf->pos < len) {
80406 buf->size += len + SZ;
80407 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80408 if (fstat(fileno(file), &st) < 0)
80409 goto close_write;
80410
80411 - if (st.st_size != b->pos)
80412 + if (st.st_size != (off_t)b->pos)
80413 goto close_write;
80414
80415 tmp = NOFAIL(malloc(b->pos));
80416 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80417 index 51207e4..f7d603d 100644
80418 --- a/scripts/mod/modpost.h
80419 +++ b/scripts/mod/modpost.h
80420 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80421
80422 struct buffer {
80423 char *p;
80424 - int pos;
80425 - int size;
80426 + unsigned int pos;
80427 + unsigned int size;
80428 };
80429
80430 void __attribute__((format(printf, 2, 3)))
80431 buf_printf(struct buffer *buf, const char *fmt, ...);
80432
80433 void
80434 -buf_write(struct buffer *buf, const char *s, int len);
80435 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80436
80437 struct module {
80438 struct module *next;
80439 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80440 index 9dfcd6d..099068e 100644
80441 --- a/scripts/mod/sumversion.c
80442 +++ b/scripts/mod/sumversion.c
80443 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80444 goto out;
80445 }
80446
80447 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80448 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80449 warn("writing sum in %s failed: %s\n",
80450 filename, strerror(errno));
80451 goto out;
80452 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80453 index 5c11312..72742b5 100644
80454 --- a/scripts/pnmtologo.c
80455 +++ b/scripts/pnmtologo.c
80456 @@ -237,14 +237,14 @@ static void write_header(void)
80457 fprintf(out, " * Linux logo %s\n", logoname);
80458 fputs(" */\n\n", out);
80459 fputs("#include <linux/linux_logo.h>\n\n", out);
80460 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80461 + fprintf(out, "static unsigned char %s_data[] = {\n",
80462 logoname);
80463 }
80464
80465 static void write_footer(void)
80466 {
80467 fputs("\n};\n\n", out);
80468 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80469 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80470 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80471 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80472 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80473 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80474 fputs("\n};\n\n", out);
80475
80476 /* write logo clut */
80477 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80478 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80479 logoname);
80480 write_hex_cnt = 0;
80481 for (i = 0; i < logo_clutsize; i++) {
80482 diff --git a/security/Kconfig b/security/Kconfig
80483 index e9c6ac7..152c2e3 100644
80484 --- a/security/Kconfig
80485 +++ b/security/Kconfig
80486 @@ -4,6 +4,896 @@
80487
80488 menu "Security options"
80489
80490 +menu "Grsecurity"
80491 +
80492 + config ARCH_TRACK_EXEC_LIMIT
80493 + bool
80494 +
80495 + config PAX_KERNEXEC_PLUGIN
80496 + bool
80497 +
80498 + config PAX_PER_CPU_PGD
80499 + bool
80500 +
80501 + config TASK_SIZE_MAX_SHIFT
80502 + int
80503 + depends on X86_64
80504 + default 47 if !PAX_PER_CPU_PGD
80505 + default 42 if PAX_PER_CPU_PGD
80506 +
80507 + config PAX_ENABLE_PAE
80508 + bool
80509 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80510 +
80511 + config PAX_USERCOPY_SLABS
80512 + bool
80513 +
80514 +config GRKERNSEC
80515 + bool "Grsecurity"
80516 + select CRYPTO
80517 + select CRYPTO_SHA256
80518 + select PROC_FS
80519 + select STOP_MACHINE
80520 + help
80521 + If you say Y here, you will be able to configure many features
80522 + that will enhance the security of your system. It is highly
80523 + recommended that you say Y here and read through the help
80524 + for each option so that you fully understand the features and
80525 + can evaluate their usefulness for your machine.
80526 +
80527 +choice
80528 + prompt "Configuration Method"
80529 + depends on GRKERNSEC
80530 + default GRKERNSEC_CONFIG_CUSTOM
80531 + help
80532 +
80533 +config GRKERNSEC_CONFIG_AUTO
80534 + bool "Automatic"
80535 + help
80536 + If you choose this configuration method, you'll be able to answer a small
80537 + number of simple questions about how you plan to use this kernel.
80538 + The settings of grsecurity and PaX will be automatically configured for
80539 + the highest commonly-used settings within the provided constraints.
80540 +
80541 + If you require additional configuration, custom changes can still be made
80542 + from the "custom configuration" menu.
80543 +
80544 +config GRKERNSEC_CONFIG_CUSTOM
80545 + bool "Custom"
80546 + help
80547 + If you choose this configuration method, you'll be able to configure all
80548 + grsecurity and PaX settings manually. Via this method, no options are
80549 + automatically enabled.
80550 +
80551 +endchoice
80552 +
80553 +choice
80554 + prompt "Usage Type"
80555 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80556 + default GRKERNSEC_CONFIG_SERVER
80557 + help
80558 +
80559 +config GRKERNSEC_CONFIG_SERVER
80560 + bool "Server"
80561 + help
80562 + Choose this option if you plan to use this kernel on a server.
80563 +
80564 +config GRKERNSEC_CONFIG_DESKTOP
80565 + bool "Desktop"
80566 + help
80567 + Choose this option if you plan to use this kernel on a desktop.
80568 +
80569 +endchoice
80570 +
80571 +choice
80572 + prompt "Virtualization Type"
80573 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80574 + default GRKERNSEC_CONFIG_VIRT_NONE
80575 + help
80576 +
80577 +config GRKERNSEC_CONFIG_VIRT_NONE
80578 + bool "None"
80579 + help
80580 + Choose this option if this kernel will be run on bare metal.
80581 +
80582 +config GRKERNSEC_CONFIG_VIRT_GUEST
80583 + bool "Guest"
80584 + help
80585 + Choose this option if this kernel will be run as a VM guest.
80586 +
80587 +config GRKERNSEC_CONFIG_VIRT_HOST
80588 + bool "Host"
80589 + help
80590 + Choose this option if this kernel will be run as a VM host.
80591 +
80592 +endchoice
80593 +
80594 +choice
80595 + prompt "Virtualization Hardware"
80596 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80597 + help
80598 +
80599 +config GRKERNSEC_CONFIG_VIRT_EPT
80600 + bool "EPT/RVI Processor Support"
80601 + depends on X86
80602 + help
80603 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80604 + hardware virtualization. This allows for additional kernel hardening protections
80605 + to operate without additional performance impact.
80606 +
80607 + To see if your Intel processor supports EPT, see:
80608 + http://ark.intel.com/Products/VirtualizationTechnology
80609 + (Most Core i3/5/7 support EPT)
80610 +
80611 + To see if your AMD processor supports RVI, see:
80612 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80613 +
80614 +config GRKERNSEC_CONFIG_VIRT_SOFT
80615 + bool "First-gen/No Hardware Virtualization"
80616 + help
80617 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80618 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80619 +
80620 +endchoice
80621 +
80622 +choice
80623 + prompt "Virtualization Software"
80624 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80625 + help
80626 +
80627 +config GRKERNSEC_CONFIG_VIRT_XEN
80628 + bool "Xen"
80629 + help
80630 + Choose this option if this kernel is running as a Xen guest or host.
80631 +
80632 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80633 + bool "VMWare"
80634 + help
80635 + Choose this option if this kernel is running as a VMWare guest or host.
80636 +
80637 +config GRKERNSEC_CONFIG_VIRT_KVM
80638 + bool "KVM"
80639 + help
80640 + Choose this option if this kernel is running as a KVM guest or host.
80641 +
80642 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80643 + bool "VirtualBox"
80644 + help
80645 + Choose this option if this kernel is running as a VirtualBox guest or host.
80646 +
80647 +endchoice
80648 +
80649 +choice
80650 + prompt "Required Priorities"
80651 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80652 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80653 + help
80654 +
80655 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80656 + bool "Performance"
80657 + help
80658 + Choose this option if performance is of highest priority for this deployment
80659 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80660 + and freed memory sanitizing will be disabled.
80661 +
80662 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80663 + bool "Security"
80664 + help
80665 + Choose this option if security is of highest priority for this deployment of
80666 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80667 + be enabled for this kernel. In a worst-case scenario, these features can
80668 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80669 +
80670 +endchoice
80671 +
80672 +menu "Default Special Groups"
80673 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80674 +
80675 +config GRKERNSEC_PROC_GID
80676 + int "GID exempted from /proc restrictions"
80677 + default 1001
80678 + help
80679 + Setting this GID determines which group will be exempted from
80680 + grsecurity's /proc restrictions, allowing users of the specified
80681 + group to view network statistics and the existence of other users'
80682 + processes on the system. This GID may also be chosen at boot time
80683 + via "grsec_proc_gid=" on the kernel commandline.
80684 +
80685 +config GRKERNSEC_TPE_UNTRUSTED_GID
80686 + int "GID for TPE-untrusted users"
80687 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80688 + default 1005
80689 + help
80690 + Setting this GID determines which group untrusted users should
80691 + be added to. These users will be placed under grsecurity's Trusted Path
80692 + Execution mechanism, preventing them from executing their own binaries.
80693 + The users will only be able to execute binaries in directories owned and
80694 + writable only by the root user. If the sysctl option is enabled, a sysctl
80695 + option with name "tpe_gid" is created.
80696 +
80697 +config GRKERNSEC_TPE_TRUSTED_GID
80698 + int "GID for TPE-trusted users"
80699 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80700 + default 1005
80701 + help
80702 + Setting this GID determines what group TPE restrictions will be
80703 + *disabled* for. If the sysctl option is enabled, a sysctl option
80704 + with name "tpe_gid" is created.
80705 +
80706 +config GRKERNSEC_SYMLINKOWN_GID
80707 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80708 + depends on GRKERNSEC_CONFIG_SERVER
80709 + default 1006
80710 + help
80711 + Setting this GID determines what group kernel-enforced
80712 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80713 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80714 +
80715 +
80716 +endmenu
80717 +
80718 +menu "Customize Configuration"
80719 +depends on GRKERNSEC
80720 +
80721 +menu "PaX"
80722 +
80723 +config PAX
80724 + bool "Enable various PaX features"
80725 + default y if GRKERNSEC_CONFIG_AUTO
80726 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80727 + help
80728 + This allows you to enable various PaX features. PaX adds
80729 + intrusion prevention mechanisms to the kernel that reduce
80730 + the risks posed by exploitable memory corruption bugs.
80731 +
80732 +menu "PaX Control"
80733 + depends on PAX
80734 +
80735 +config PAX_SOFTMODE
80736 + bool 'Support soft mode'
80737 + help
80738 + Enabling this option will allow you to run PaX in soft mode, that
80739 + is, PaX features will not be enforced by default, only on executables
80740 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80741 + support as they are the only way to mark executables for soft mode use.
80742 +
80743 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80744 + line option on boot. Furthermore you can control various PaX features
80745 + at runtime via the entries in /proc/sys/kernel/pax.
80746 +
80747 +config PAX_EI_PAX
80748 + bool 'Use legacy ELF header marking'
80749 + default y if GRKERNSEC_CONFIG_AUTO
80750 + help
80751 + Enabling this option will allow you to control PaX features on
80752 + a per executable basis via the 'chpax' utility available at
80753 + http://pax.grsecurity.net/. The control flags will be read from
80754 + an otherwise reserved part of the ELF header. This marking has
80755 + numerous drawbacks (no support for soft-mode, toolchain does not
80756 + know about the non-standard use of the ELF header) therefore it
80757 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80758 + support.
80759 +
80760 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80761 + support as well, they will override the legacy EI_PAX marks.
80762 +
80763 + If you enable none of the marking options then all applications
80764 + will run with PaX enabled on them by default.
80765 +
80766 +config PAX_PT_PAX_FLAGS
80767 + bool 'Use ELF program header marking'
80768 + default y if GRKERNSEC_CONFIG_AUTO
80769 + help
80770 + Enabling this option will allow you to control PaX features on
80771 + a per executable basis via the 'paxctl' utility available at
80772 + http://pax.grsecurity.net/. The control flags will be read from
80773 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80774 + has the benefits of supporting both soft mode and being fully
80775 + integrated into the toolchain (the binutils patch is available
80776 + from http://pax.grsecurity.net).
80777 +
80778 + Note that if you enable the legacy EI_PAX marking support as well,
80779 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80780 +
80781 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80782 + must make sure that the marks are the same if a binary has both marks.
80783 +
80784 + If you enable none of the marking options then all applications
80785 + will run with PaX enabled on them by default.
80786 +
80787 +config PAX_XATTR_PAX_FLAGS
80788 + bool 'Use filesystem extended attributes marking'
80789 + default y if GRKERNSEC_CONFIG_AUTO
80790 + select CIFS_XATTR if CIFS
80791 + select EXT2_FS_XATTR if EXT2_FS
80792 + select EXT3_FS_XATTR if EXT3_FS
80793 + select EXT4_FS_XATTR if EXT4_FS
80794 + select JFFS2_FS_XATTR if JFFS2_FS
80795 + select REISERFS_FS_XATTR if REISERFS_FS
80796 + select SQUASHFS_XATTR if SQUASHFS
80797 + select TMPFS_XATTR if TMPFS
80798 + select UBIFS_FS_XATTR if UBIFS_FS
80799 + help
80800 + Enabling this option will allow you to control PaX features on
80801 + a per executable basis via the 'setfattr' utility. The control
80802 + flags will be read from the user.pax.flags extended attribute of
80803 + the file. This marking has the benefit of supporting binary-only
80804 + applications that self-check themselves (e.g., skype) and would
80805 + not tolerate chpax/paxctl changes. The main drawback is that
80806 + extended attributes are not supported by some filesystems (e.g.,
80807 + isofs, udf, vfat) so copying files through such filesystems will
80808 + lose the extended attributes and these PaX markings.
80809 +
80810 + Note that if you enable the legacy EI_PAX marking support as well,
80811 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80812 +
80813 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80814 + must make sure that the marks are the same if a binary has both marks.
80815 +
80816 + If you enable none of the marking options then all applications
80817 + will run with PaX enabled on them by default.
80818 +
80819 +choice
80820 + prompt 'MAC system integration'
80821 + default PAX_HAVE_ACL_FLAGS
80822 + help
80823 + Mandatory Access Control systems have the option of controlling
80824 + PaX flags on a per executable basis, choose the method supported
80825 + by your particular system.
80826 +
80827 + - "none": if your MAC system does not interact with PaX,
80828 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80829 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80830 +
80831 + NOTE: this option is for developers/integrators only.
80832 +
80833 + config PAX_NO_ACL_FLAGS
80834 + bool 'none'
80835 +
80836 + config PAX_HAVE_ACL_FLAGS
80837 + bool 'direct'
80838 +
80839 + config PAX_HOOK_ACL_FLAGS
80840 + bool 'hook'
80841 +endchoice
80842 +
80843 +endmenu
80844 +
80845 +menu "Non-executable pages"
80846 + depends on PAX
80847 +
80848 +config PAX_NOEXEC
80849 + bool "Enforce non-executable pages"
80850 + default y if GRKERNSEC_CONFIG_AUTO
80851 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80852 + help
80853 + By design some architectures do not allow for protecting memory
80854 + pages against execution or even if they do, Linux does not make
80855 + use of this feature. In practice this means that if a page is
80856 + readable (such as the stack or heap) it is also executable.
80857 +
80858 + There is a well known exploit technique that makes use of this
80859 + fact and a common programming mistake where an attacker can
80860 + introduce code of his choice somewhere in the attacked program's
80861 + memory (typically the stack or the heap) and then execute it.
80862 +
80863 + If the attacked program was running with different (typically
80864 + higher) privileges than that of the attacker, then he can elevate
80865 + his own privilege level (e.g. get a root shell, write to files for
80866 + which he does not have write access to, etc).
80867 +
80868 + Enabling this option will let you choose from various features
80869 + that prevent the injection and execution of 'foreign' code in
80870 + a program.
80871 +
80872 + This will also break programs that rely on the old behaviour and
80873 + expect that dynamically allocated memory via the malloc() family
80874 + of functions is executable (which it is not). Notable examples
80875 + are the XFree86 4.x server, the java runtime and wine.
80876 +
80877 +config PAX_PAGEEXEC
80878 + bool "Paging based non-executable pages"
80879 + default y if GRKERNSEC_CONFIG_AUTO
80880 + 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)
80881 + select S390_SWITCH_AMODE if S390
80882 + select S390_EXEC_PROTECT if S390
80883 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80884 + help
80885 + This implementation is based on the paging feature of the CPU.
80886 + On i386 without hardware non-executable bit support there is a
80887 + variable but usually low performance impact, however on Intel's
80888 + P4 core based CPUs it is very high so you should not enable this
80889 + for kernels meant to be used on such CPUs.
80890 +
80891 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80892 + with hardware non-executable bit support there is no performance
80893 + impact, on ppc the impact is negligible.
80894 +
80895 + Note that several architectures require various emulations due to
80896 + badly designed userland ABIs, this will cause a performance impact
80897 + but will disappear as soon as userland is fixed. For example, ppc
80898 + userland MUST have been built with secure-plt by a recent toolchain.
80899 +
80900 +config PAX_SEGMEXEC
80901 + bool "Segmentation based non-executable pages"
80902 + default y if GRKERNSEC_CONFIG_AUTO
80903 + depends on PAX_NOEXEC && X86_32
80904 + help
80905 + This implementation is based on the segmentation feature of the
80906 + CPU and has a very small performance impact, however applications
80907 + will be limited to a 1.5 GB address space instead of the normal
80908 + 3 GB.
80909 +
80910 +config PAX_EMUTRAMP
80911 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80912 + default y if PARISC
80913 + help
80914 + There are some programs and libraries that for one reason or
80915 + another attempt to execute special small code snippets from
80916 + non-executable memory pages. Most notable examples are the
80917 + signal handler return code generated by the kernel itself and
80918 + the GCC trampolines.
80919 +
80920 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80921 + such programs will no longer work under your kernel.
80922 +
80923 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80924 + utilities to enable trampoline emulation for the affected programs
80925 + yet still have the protection provided by the non-executable pages.
80926 +
80927 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80928 + your system will not even boot.
80929 +
80930 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80931 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80932 + for the affected files.
80933 +
80934 + NOTE: enabling this feature *may* open up a loophole in the
80935 + protection provided by non-executable pages that an attacker
80936 + could abuse. Therefore the best solution is to not have any
80937 + files on your system that would require this option. This can
80938 + be achieved by not using libc5 (which relies on the kernel
80939 + signal handler return code) and not using or rewriting programs
80940 + that make use of the nested function implementation of GCC.
80941 + Skilled users can just fix GCC itself so that it implements
80942 + nested function calls in a way that does not interfere with PaX.
80943 +
80944 +config PAX_EMUSIGRT
80945 + bool "Automatically emulate sigreturn trampolines"
80946 + depends on PAX_EMUTRAMP && PARISC
80947 + default y
80948 + help
80949 + Enabling this option will have the kernel automatically detect
80950 + and emulate signal return trampolines executing on the stack
80951 + that would otherwise lead to task termination.
80952 +
80953 + This solution is intended as a temporary one for users with
80954 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80955 + Modula-3 runtime, etc) or executables linked to such, basically
80956 + everything that does not specify its own SA_RESTORER function in
80957 + normal executable memory like glibc 2.1+ does.
80958 +
80959 + On parisc you MUST enable this option, otherwise your system will
80960 + not even boot.
80961 +
80962 + NOTE: this feature cannot be disabled on a per executable basis
80963 + and since it *does* open up a loophole in the protection provided
80964 + by non-executable pages, the best solution is to not have any
80965 + files on your system that would require this option.
80966 +
80967 +config PAX_MPROTECT
80968 + bool "Restrict mprotect()"
80969 + default y if GRKERNSEC_CONFIG_AUTO
80970 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80971 + help
80972 + Enabling this option will prevent programs from
80973 + - changing the executable status of memory pages that were
80974 + not originally created as executable,
80975 + - making read-only executable pages writable again,
80976 + - creating executable pages from anonymous memory,
80977 + - making read-only-after-relocations (RELRO) data pages writable again.
80978 +
80979 + You should say Y here to complete the protection provided by
80980 + the enforcement of non-executable pages.
80981 +
80982 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80983 + this feature on a per file basis.
80984 +
80985 +config PAX_MPROTECT_COMPAT
80986 + bool "Use legacy/compat protection demoting (read help)"
80987 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80988 + depends on PAX_MPROTECT
80989 + help
80990 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80991 + by sending the proper error code to the application. For some broken
80992 + userland, this can cause problems with Python or other applications. The
80993 + current implementation however allows for applications like clamav to
80994 + detect if JIT compilation/execution is allowed and to fall back gracefully
80995 + to an interpreter-based mode if it does not. While we encourage everyone
80996 + to use the current implementation as-is and push upstream to fix broken
80997 + userland (note that the RWX logging option can assist with this), in some
80998 + environments this may not be possible. Having to disable MPROTECT
80999 + completely on certain binaries reduces the security benefit of PaX,
81000 + so this option is provided for those environments to revert to the old
81001 + behavior.
81002 +
81003 +config PAX_ELFRELOCS
81004 + bool "Allow ELF text relocations (read help)"
81005 + depends on PAX_MPROTECT
81006 + default n
81007 + help
81008 + Non-executable pages and mprotect() restrictions are effective
81009 + in preventing the introduction of new executable code into an
81010 + attacked task's address space. There remain only two venues
81011 + for this kind of attack: if the attacker can execute already
81012 + existing code in the attacked task then he can either have it
81013 + create and mmap() a file containing his code or have it mmap()
81014 + an already existing ELF library that does not have position
81015 + independent code in it and use mprotect() on it to make it
81016 + writable and copy his code there. While protecting against
81017 + the former approach is beyond PaX, the latter can be prevented
81018 + by having only PIC ELF libraries on one's system (which do not
81019 + need to relocate their code). If you are sure this is your case,
81020 + as is the case with all modern Linux distributions, then leave
81021 + this option disabled. You should say 'n' here.
81022 +
81023 +config PAX_ETEXECRELOCS
81024 + bool "Allow ELF ET_EXEC text relocations"
81025 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81026 + select PAX_ELFRELOCS
81027 + default y
81028 + help
81029 + On some architectures there are incorrectly created applications
81030 + that require text relocations and would not work without enabling
81031 + this option. If you are an alpha, ia64 or parisc user, you should
81032 + enable this option and disable it once you have made sure that
81033 + none of your applications need it.
81034 +
81035 +config PAX_EMUPLT
81036 + bool "Automatically emulate ELF PLT"
81037 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81038 + default y
81039 + help
81040 + Enabling this option will have the kernel automatically detect
81041 + and emulate the Procedure Linkage Table entries in ELF files.
81042 + On some architectures such entries are in writable memory, and
81043 + become non-executable leading to task termination. Therefore
81044 + it is mandatory that you enable this option on alpha, parisc,
81045 + sparc and sparc64, otherwise your system would not even boot.
81046 +
81047 + NOTE: this feature *does* open up a loophole in the protection
81048 + provided by the non-executable pages, therefore the proper
81049 + solution is to modify the toolchain to produce a PLT that does
81050 + not need to be writable.
81051 +
81052 +config PAX_DLRESOLVE
81053 + bool 'Emulate old glibc resolver stub'
81054 + depends on PAX_EMUPLT && SPARC
81055 + default n
81056 + help
81057 + This option is needed if userland has an old glibc (before 2.4)
81058 + that puts a 'save' instruction into the runtime generated resolver
81059 + stub that needs special emulation.
81060 +
81061 +config PAX_KERNEXEC
81062 + bool "Enforce non-executable kernel pages"
81063 + 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))
81064 + depends on X86 && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81065 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81066 + select PAX_KERNEXEC_PLUGIN if X86_64
81067 + help
81068 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81069 + that is, enabling this option will make it harder to inject
81070 + and execute 'foreign' code in kernel memory itself.
81071 +
81072 +choice
81073 + prompt "Return Address Instrumentation Method"
81074 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81075 + depends on PAX_KERNEXEC_PLUGIN
81076 + help
81077 + Select the method used to instrument function pointer dereferences.
81078 + Note that binary modules cannot be instrumented by this approach.
81079 +
81080 + Note that the implementation requires a gcc with plugin support,
81081 + i.e., gcc 4.5 or newer. You may need to install the supporting
81082 + headers explicitly in addition to the normal gcc package.
81083 +
81084 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81085 + bool "bts"
81086 + help
81087 + This method is compatible with binary only modules but has
81088 + a higher runtime overhead.
81089 +
81090 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81091 + bool "or"
81092 + depends on !PARAVIRT
81093 + help
81094 + This method is incompatible with binary only modules but has
81095 + a lower runtime overhead.
81096 +endchoice
81097 +
81098 +config PAX_KERNEXEC_PLUGIN_METHOD
81099 + string
81100 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81101 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81102 + default ""
81103 +
81104 +config PAX_KERNEXEC_MODULE_TEXT
81105 + int "Minimum amount of memory reserved for module code"
81106 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81107 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81108 + depends on PAX_KERNEXEC && X86_32 && MODULES
81109 + help
81110 + Due to implementation details the kernel must reserve a fixed
81111 + amount of memory for module code at compile time that cannot be
81112 + changed at runtime. Here you can specify the minimum amount
81113 + in MB that will be reserved. Due to the same implementation
81114 + details this size will always be rounded up to the next 2/4 MB
81115 + boundary (depends on PAE) so the actually available memory for
81116 + module code will usually be more than this minimum.
81117 +
81118 + The default 4 MB should be enough for most users but if you have
81119 + an excessive number of modules (e.g., most distribution configs
81120 + compile many drivers as modules) or use huge modules such as
81121 + nvidia's kernel driver, you will need to adjust this amount.
81122 + A good rule of thumb is to look at your currently loaded kernel
81123 + modules and add up their sizes.
81124 +
81125 +endmenu
81126 +
81127 +menu "Address Space Layout Randomization"
81128 + depends on PAX
81129 +
81130 +config PAX_ASLR
81131 + bool "Address Space Layout Randomization"
81132 + default y if GRKERNSEC_CONFIG_AUTO
81133 + help
81134 + Many if not most exploit techniques rely on the knowledge of
81135 + certain addresses in the attacked program. The following options
81136 + will allow the kernel to apply a certain amount of randomization
81137 + to specific parts of the program thereby forcing an attacker to
81138 + guess them in most cases. Any failed guess will most likely crash
81139 + the attacked program which allows the kernel to detect such attempts
81140 + and react on them. PaX itself provides no reaction mechanisms,
81141 + instead it is strongly encouraged that you make use of Nergal's
81142 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81143 + (http://www.grsecurity.net/) built-in crash detection features or
81144 + develop one yourself.
81145 +
81146 + By saying Y here you can choose to randomize the following areas:
81147 + - top of the task's kernel stack
81148 + - top of the task's userland stack
81149 + - base address for mmap() requests that do not specify one
81150 + (this includes all libraries)
81151 + - base address of the main executable
81152 +
81153 + It is strongly recommended to say Y here as address space layout
81154 + randomization has negligible impact on performance yet it provides
81155 + a very effective protection.
81156 +
81157 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81158 + this feature on a per file basis.
81159 +
81160 +config PAX_RANDKSTACK
81161 + bool "Randomize kernel stack base"
81162 + default y if GRKERNSEC_CONFIG_AUTO
81163 + depends on X86_TSC && X86
81164 + help
81165 + By saying Y here the kernel will randomize every task's kernel
81166 + stack on every system call. This will not only force an attacker
81167 + to guess it but also prevent him from making use of possible
81168 + leaked information about it.
81169 +
81170 + Since the kernel stack is a rather scarce resource, randomization
81171 + may cause unexpected stack overflows, therefore you should very
81172 + carefully test your system. Note that once enabled in the kernel
81173 + configuration, this feature cannot be disabled on a per file basis.
81174 +
81175 +config PAX_RANDUSTACK
81176 + bool "Randomize user stack base"
81177 + default y if GRKERNSEC_CONFIG_AUTO
81178 + depends on PAX_ASLR
81179 + help
81180 + By saying Y here the kernel will randomize every task's userland
81181 + stack. The randomization is done in two steps where the second
81182 + one may apply a big amount of shift to the top of the stack and
81183 + cause problems for programs that want to use lots of memory (more
81184 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81185 + For this reason the second step can be controlled by 'chpax' or
81186 + 'paxctl' on a per file basis.
81187 +
81188 +config PAX_RANDMMAP
81189 + bool "Randomize mmap() base"
81190 + default y if GRKERNSEC_CONFIG_AUTO
81191 + depends on PAX_ASLR
81192 + help
81193 + By saying Y here the kernel will use a randomized base address for
81194 + mmap() requests that do not specify one themselves. As a result
81195 + all dynamically loaded libraries will appear at random addresses
81196 + and therefore be harder to exploit by a technique where an attacker
81197 + attempts to execute library code for his purposes (e.g. spawn a
81198 + shell from an exploited program that is running at an elevated
81199 + privilege level).
81200 +
81201 + Furthermore, if a program is relinked as a dynamic ELF file, its
81202 + base address will be randomized as well, completing the full
81203 + randomization of the address space layout. Attacking such programs
81204 + becomes a guess game. You can find an example of doing this at
81205 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81206 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81207 +
81208 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81209 + feature on a per file basis.
81210 +
81211 +endmenu
81212 +
81213 +menu "Miscellaneous hardening features"
81214 +
81215 +config PAX_MEMORY_SANITIZE
81216 + bool "Sanitize all freed memory"
81217 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81218 + depends on !HIBERNATION
81219 + help
81220 + By saying Y here the kernel will erase memory pages as soon as they
81221 + are freed. This in turn reduces the lifetime of data stored in the
81222 + pages, making it less likely that sensitive information such as
81223 + passwords, cryptographic secrets, etc stay in memory for too long.
81224 +
81225 + This is especially useful for programs whose runtime is short, long
81226 + lived processes and the kernel itself benefit from this as long as
81227 + they operate on whole memory pages and ensure timely freeing of pages
81228 + that may hold sensitive information.
81229 +
81230 + The tradeoff is performance impact, on a single CPU system kernel
81231 + compilation sees a 3% slowdown, other systems and workloads may vary
81232 + and you are advised to test this feature on your expected workload
81233 + before deploying it.
81234 +
81235 + Note that this feature does not protect data stored in live pages,
81236 + e.g., process memory swapped to disk may stay there for a long time.
81237 +
81238 +config PAX_MEMORY_STACKLEAK
81239 + bool "Sanitize kernel stack"
81240 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81241 + depends on X86
81242 + help
81243 + By saying Y here the kernel will erase the kernel stack before it
81244 + returns from a system call. This in turn reduces the information
81245 + that a kernel stack leak bug can reveal.
81246 +
81247 + Note that such a bug can still leak information that was put on
81248 + the stack by the current system call (the one eventually triggering
81249 + the bug) but traces of earlier system calls on the kernel stack
81250 + cannot leak anymore.
81251 +
81252 + The tradeoff is performance impact: on a single CPU system kernel
81253 + compilation sees a 1% slowdown, other systems and workloads may vary
81254 + and you are advised to test this feature on your expected workload
81255 + before deploying it.
81256 +
81257 + Note that the full feature requires a gcc with plugin support,
81258 + i.e., gcc 4.5 or newer. You may need to install the supporting
81259 + headers explicitly in addition to the normal gcc package. Using
81260 + older gcc versions means that functions with large enough stack
81261 + frames may leave uninitialized memory behind that may be exposed
81262 + to a later syscall leaking the stack.
81263 +
81264 +config PAX_MEMORY_UDEREF
81265 + bool "Prevent invalid userland pointer dereference"
81266 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81267 + depends on X86 && !UML_X86 && !XEN
81268 + select PAX_PER_CPU_PGD if X86_64
81269 + help
81270 + By saying Y here the kernel will be prevented from dereferencing
81271 + userland pointers in contexts where the kernel expects only kernel
81272 + pointers. This is both a useful runtime debugging feature and a
81273 + security measure that prevents exploiting a class of kernel bugs.
81274 +
81275 + The tradeoff is that some virtualization solutions may experience
81276 + a huge slowdown and therefore you should not enable this feature
81277 + for kernels meant to run in such environments. Whether a given VM
81278 + solution is affected or not is best determined by simply trying it
81279 + out, the performance impact will be obvious right on boot as this
81280 + mechanism engages from very early on. A good rule of thumb is that
81281 + VMs running on CPUs without hardware virtualization support (i.e.,
81282 + the majority of IA-32 CPUs) will likely experience the slowdown.
81283 +
81284 +config PAX_REFCOUNT
81285 + bool "Prevent various kernel object reference counter overflows"
81286 + default y if GRKERNSEC_CONFIG_AUTO
81287 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81288 + help
81289 + By saying Y here the kernel will detect and prevent overflowing
81290 + various (but not all) kinds of object reference counters. Such
81291 + overflows can normally occur due to bugs only and are often, if
81292 + not always, exploitable.
81293 +
81294 + The tradeoff is that data structures protected by an overflowed
81295 + refcount will never be freed and therefore will leak memory. Note
81296 + that this leak also happens even without this protection but in
81297 + that case the overflow can eventually trigger the freeing of the
81298 + data structure while it is still being used elsewhere, resulting
81299 + in the exploitable situation that this feature prevents.
81300 +
81301 + Since this has a negligible performance impact, you should enable
81302 + this feature.
81303 +
81304 +config PAX_USERCOPY
81305 + bool "Harden heap object copies between kernel and userland"
81306 + default y if GRKERNSEC_CONFIG_AUTO
81307 + depends on X86 || PPC || SPARC || ARM
81308 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81309 + select PAX_USERCOPY_SLABS
81310 + help
81311 + By saying Y here the kernel will enforce the size of heap objects
81312 + when they are copied in either direction between the kernel and
81313 + userland, even if only a part of the heap object is copied.
81314 +
81315 + Specifically, this checking prevents information leaking from the
81316 + kernel heap during kernel to userland copies (if the kernel heap
81317 + object is otherwise fully initialized) and prevents kernel heap
81318 + overflows during userland to kernel copies.
81319 +
81320 + Note that the current implementation provides the strictest bounds
81321 + checks for the SLUB allocator.
81322 +
81323 + Enabling this option also enables per-slab cache protection against
81324 + data in a given cache being copied into/out of via userland
81325 + accessors. Though the whitelist of regions will be reduced over
81326 + time, it notably protects important data structures like task structs.
81327 +
81328 + If frame pointers are enabled on x86, this option will also restrict
81329 + copies into and out of the kernel stack to local variables within a
81330 + single frame.
81331 +
81332 + Since this has a negligible performance impact, you should enable
81333 + this feature.
81334 +
81335 +config PAX_SIZE_OVERFLOW
81336 + bool "Prevent various integer overflows in function size parameters"
81337 + default y if GRKERNSEC_CONFIG_AUTO
81338 + depends on X86
81339 + help
81340 + By saying Y here the kernel recomputes expressions of function
81341 + arguments marked by a size_overflow attribute with double integer
81342 + precision (DImode/TImode for 32/64 bit integer types).
81343 +
81344 + The recomputed argument is checked against TYPE_MAX and an event
81345 + is logged on overflow and the triggering process is killed.
81346 +
81347 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81348 +
81349 + Note that the implementation requires a gcc with plugin support,
81350 + i.e., gcc 4.5 or newer. You may need to install the supporting
81351 + headers explicitly in addition to the normal gcc package.
81352 +
81353 +config PAX_LATENT_ENTROPY
81354 + bool "Generate some entropy during boot"
81355 + default y if GRKERNSEC_CONFIG_AUTO
81356 + help
81357 + By saying Y here the kernel will instrument early boot code to
81358 + extract some entropy from both original and artificially created
81359 + program state. This will help especially embedded systems where
81360 + there is little 'natural' source of entropy normally. The cost
81361 + is some slowdown of the boot process.
81362 +
81363 + Note that the implementation requires a gcc with plugin support,
81364 + i.e., gcc 4.5 or newer. You may need to install the supporting
81365 + headers explicitly in addition to the normal gcc package.
81366 +
81367 + Note that entropy extracted this way is not cryptographically
81368 + secure!
81369 +
81370 +endmenu
81371 +
81372 +endmenu
81373 +
81374 +source grsecurity/Kconfig
81375 +
81376 +endmenu
81377 +
81378 +endmenu
81379 +
81380 source security/keys/Kconfig
81381
81382 config SECURITY_DMESG_RESTRICT
81383 @@ -103,7 +993,7 @@ config INTEL_TXT
81384 config LSM_MMAP_MIN_ADDR
81385 int "Low address space for LSM to protect from user allocation"
81386 depends on SECURITY && SECURITY_SELINUX
81387 - default 32768 if ARM
81388 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81389 default 65536
81390 help
81391 This is the portion of low virtual memory which should be protected
81392 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81393 index 8c2a7f6..b133ac9 100644
81394 --- a/security/apparmor/lsm.c
81395 +++ b/security/apparmor/lsm.c
81396 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81397 return error;
81398 }
81399
81400 -static struct security_operations apparmor_ops = {
81401 +static struct security_operations apparmor_ops __read_only = {
81402 .name = "apparmor",
81403
81404 .ptrace_access_check = apparmor_ptrace_access_check,
81405 diff --git a/security/commoncap.c b/security/commoncap.c
81406 index 6dbae46..d5611fd 100644
81407 --- a/security/commoncap.c
81408 +++ b/security/commoncap.c
81409 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81410 return 0;
81411 }
81412
81413 +/* returns:
81414 + 1 for suid privilege
81415 + 2 for sgid privilege
81416 + 3 for fscap privilege
81417 +*/
81418 +int is_privileged_binary(const struct dentry *dentry)
81419 +{
81420 + struct cpu_vfs_cap_data capdata;
81421 + struct inode *inode = dentry->d_inode;
81422 +
81423 + if (!inode || S_ISDIR(inode->i_mode))
81424 + return 0;
81425 +
81426 + if (inode->i_mode & S_ISUID)
81427 + return 1;
81428 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81429 + return 2;
81430 +
81431 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81432 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81433 + return 3;
81434 + }
81435 +
81436 + return 0;
81437 +}
81438 +
81439 /*
81440 * Attempt to get the on-exec apply capability sets for an executable file from
81441 * its xattrs and, if present, apply them to the proposed credentials being
81442 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81443 const struct cred *cred = current_cred();
81444 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81445
81446 + if (gr_acl_enable_at_secure())
81447 + return 1;
81448 +
81449 if (!uid_eq(cred->uid, root_uid)) {
81450 if (bprm->cap_effective)
81451 return 1;
81452 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81453 index 6ee8826..6350060 100644
81454 --- a/security/integrity/ima/ima.h
81455 +++ b/security/integrity/ima/ima.h
81456 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81457 extern spinlock_t ima_queue_lock;
81458
81459 struct ima_h_table {
81460 - atomic_long_t len; /* number of stored measurements in the list */
81461 - atomic_long_t violations;
81462 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81463 + atomic_long_unchecked_t violations;
81464 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81465 };
81466 extern struct ima_h_table ima_htable;
81467 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81468 index b356884..fd9676e 100644
81469 --- a/security/integrity/ima/ima_api.c
81470 +++ b/security/integrity/ima/ima_api.c
81471 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81472 int result;
81473
81474 /* can overflow, only indicator */
81475 - atomic_long_inc(&ima_htable.violations);
81476 + atomic_long_inc_unchecked(&ima_htable.violations);
81477
81478 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81479 if (!entry) {
81480 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81481 index 38477c9..87a60c7 100644
81482 --- a/security/integrity/ima/ima_fs.c
81483 +++ b/security/integrity/ima/ima_fs.c
81484 @@ -28,12 +28,12 @@
81485 static int valid_policy = 1;
81486 #define TMPBUFLEN 12
81487 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81488 - loff_t *ppos, atomic_long_t *val)
81489 + loff_t *ppos, atomic_long_unchecked_t *val)
81490 {
81491 char tmpbuf[TMPBUFLEN];
81492 ssize_t len;
81493
81494 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81495 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81496 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81497 }
81498
81499 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81500 index 55a6271..ad829c3 100644
81501 --- a/security/integrity/ima/ima_queue.c
81502 +++ b/security/integrity/ima/ima_queue.c
81503 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81504 INIT_LIST_HEAD(&qe->later);
81505 list_add_tail_rcu(&qe->later, &ima_measurements);
81506
81507 - atomic_long_inc(&ima_htable.len);
81508 + atomic_long_inc_unchecked(&ima_htable.len);
81509 key = ima_hash_key(entry->digest);
81510 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81511 return 0;
81512 diff --git a/security/keys/compat.c b/security/keys/compat.c
81513 index 1c26176..64a1ba2 100644
81514 --- a/security/keys/compat.c
81515 +++ b/security/keys/compat.c
81516 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81517 if (ret == 0)
81518 goto no_payload_free;
81519
81520 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81521 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81522
81523 if (iov != iovstack)
81524 kfree(iov);
81525 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81526 index 5d34b4e..2456674 100644
81527 --- a/security/keys/keyctl.c
81528 +++ b/security/keys/keyctl.c
81529 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81530 /*
81531 * Copy the iovec data from userspace
81532 */
81533 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81534 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81535 unsigned ioc)
81536 {
81537 for (; ioc > 0; ioc--) {
81538 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81539 * If successful, 0 will be returned.
81540 */
81541 long keyctl_instantiate_key_common(key_serial_t id,
81542 - const struct iovec *payload_iov,
81543 + const struct iovec __user *payload_iov,
81544 unsigned ioc,
81545 size_t plen,
81546 key_serial_t ringid)
81547 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
81548 [0].iov_len = plen
81549 };
81550
81551 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81552 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81553 }
81554
81555 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81556 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81557 if (ret == 0)
81558 goto no_payload_free;
81559
81560 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81561 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81562
81563 if (iov != iovstack)
81564 kfree(iov);
81565 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81566 index 6e42df1..aba52bd 100644
81567 --- a/security/keys/keyring.c
81568 +++ b/security/keys/keyring.c
81569 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81570 ret = -EFAULT;
81571
81572 for (loop = 0; loop < klist->nkeys; loop++) {
81573 + key_serial_t serial;
81574 key = rcu_deref_link_locked(klist, loop,
81575 keyring);
81576 + serial = key->serial;
81577
81578 tmp = sizeof(key_serial_t);
81579 if (tmp > buflen)
81580 tmp = buflen;
81581
81582 - if (copy_to_user(buffer,
81583 - &key->serial,
81584 - tmp) != 0)
81585 + if (copy_to_user(buffer, &serial, tmp))
81586 goto error;
81587
81588 buflen -= tmp;
81589 diff --git a/security/min_addr.c b/security/min_addr.c
81590 index f728728..6457a0c 100644
81591 --- a/security/min_addr.c
81592 +++ b/security/min_addr.c
81593 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81594 */
81595 static void update_mmap_min_addr(void)
81596 {
81597 +#ifndef SPARC
81598 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81599 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81600 mmap_min_addr = dac_mmap_min_addr;
81601 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81602 #else
81603 mmap_min_addr = dac_mmap_min_addr;
81604 #endif
81605 +#endif
81606 }
81607
81608 /*
81609 diff --git a/security/security.c b/security/security.c
81610 index 8dcd4ae..1124de7 100644
81611 --- a/security/security.c
81612 +++ b/security/security.c
81613 @@ -20,6 +20,7 @@
81614 #include <linux/ima.h>
81615 #include <linux/evm.h>
81616 #include <linux/fsnotify.h>
81617 +#include <linux/mm.h>
81618 #include <linux/mman.h>
81619 #include <linux/mount.h>
81620 #include <linux/personality.h>
81621 @@ -32,8 +33,8 @@
81622 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81623 CONFIG_DEFAULT_SECURITY;
81624
81625 -static struct security_operations *security_ops;
81626 -static struct security_operations default_security_ops = {
81627 +static struct security_operations *security_ops __read_only;
81628 +static struct security_operations default_security_ops __read_only = {
81629 .name = "default",
81630 };
81631
81632 @@ -74,7 +75,9 @@ int __init security_init(void)
81633
81634 void reset_security_ops(void)
81635 {
81636 + pax_open_kernel();
81637 security_ops = &default_security_ops;
81638 + pax_close_kernel();
81639 }
81640
81641 /* Save user chosen LSM */
81642 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81643 index 61a5336..27215d8 100644
81644 --- a/security/selinux/hooks.c
81645 +++ b/security/selinux/hooks.c
81646 @@ -95,8 +95,6 @@
81647
81648 #define NUM_SEL_MNT_OPTS 5
81649
81650 -extern struct security_operations *security_ops;
81651 -
81652 /* SECMARK reference count */
81653 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81654
81655 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81656
81657 #endif
81658
81659 -static struct security_operations selinux_ops = {
81660 +static struct security_operations selinux_ops __read_only = {
81661 .name = "selinux",
81662
81663 .ptrace_access_check = selinux_ptrace_access_check,
81664 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81665 index 65f67cb..3f141ef 100644
81666 --- a/security/selinux/include/xfrm.h
81667 +++ b/security/selinux/include/xfrm.h
81668 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81669
81670 static inline void selinux_xfrm_notify_policyload(void)
81671 {
81672 - atomic_inc(&flow_cache_genid);
81673 + atomic_inc_unchecked(&flow_cache_genid);
81674 rt_genid_bump(&init_net);
81675 }
81676 #else
81677 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81678 index 38be92c..21f49ee 100644
81679 --- a/security/smack/smack_lsm.c
81680 +++ b/security/smack/smack_lsm.c
81681 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81682 return 0;
81683 }
81684
81685 -struct security_operations smack_ops = {
81686 +struct security_operations smack_ops __read_only = {
81687 .name = "smack",
81688
81689 .ptrace_access_check = smack_ptrace_access_check,
81690 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81691 index a2ee362..5754f34 100644
81692 --- a/security/tomoyo/tomoyo.c
81693 +++ b/security/tomoyo/tomoyo.c
81694 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81695 * tomoyo_security_ops is a "struct security_operations" which is used for
81696 * registering TOMOYO.
81697 */
81698 -static struct security_operations tomoyo_security_ops = {
81699 +static struct security_operations tomoyo_security_ops __read_only = {
81700 .name = "tomoyo",
81701 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81702 .cred_prepare = tomoyo_cred_prepare,
81703 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81704 index 20ef514..4182bed 100644
81705 --- a/security/yama/Kconfig
81706 +++ b/security/yama/Kconfig
81707 @@ -1,6 +1,6 @@
81708 config SECURITY_YAMA
81709 bool "Yama support"
81710 - depends on SECURITY
81711 + depends on SECURITY && !GRKERNSEC
81712 select SECURITYFS
81713 select SECURITY_PATH
81714 default n
81715 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81716 index 4cedc69..e59d8a3 100644
81717 --- a/sound/aoa/codecs/onyx.c
81718 +++ b/sound/aoa/codecs/onyx.c
81719 @@ -54,7 +54,7 @@ struct onyx {
81720 spdif_locked:1,
81721 analog_locked:1,
81722 original_mute:2;
81723 - int open_count;
81724 + local_t open_count;
81725 struct codec_info *codec_info;
81726
81727 /* mutex serializes concurrent access to the device
81728 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81729 struct onyx *onyx = cii->codec_data;
81730
81731 mutex_lock(&onyx->mutex);
81732 - onyx->open_count++;
81733 + local_inc(&onyx->open_count);
81734 mutex_unlock(&onyx->mutex);
81735
81736 return 0;
81737 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81738 struct onyx *onyx = cii->codec_data;
81739
81740 mutex_lock(&onyx->mutex);
81741 - onyx->open_count--;
81742 - if (!onyx->open_count)
81743 + if (local_dec_and_test(&onyx->open_count))
81744 onyx->spdif_locked = onyx->analog_locked = 0;
81745 mutex_unlock(&onyx->mutex);
81746
81747 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81748 index ffd2025..df062c9 100644
81749 --- a/sound/aoa/codecs/onyx.h
81750 +++ b/sound/aoa/codecs/onyx.h
81751 @@ -11,6 +11,7 @@
81752 #include <linux/i2c.h>
81753 #include <asm/pmac_low_i2c.h>
81754 #include <asm/prom.h>
81755 +#include <asm/local.h>
81756
81757 /* PCM3052 register definitions */
81758
81759 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81760 index 4c1cc51..16040040 100644
81761 --- a/sound/core/oss/pcm_oss.c
81762 +++ b/sound/core/oss/pcm_oss.c
81763 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81764 if (in_kernel) {
81765 mm_segment_t fs;
81766 fs = snd_enter_user();
81767 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81768 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81769 snd_leave_user(fs);
81770 } else {
81771 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81772 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81773 }
81774 if (ret != -EPIPE && ret != -ESTRPIPE)
81775 break;
81776 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81777 if (in_kernel) {
81778 mm_segment_t fs;
81779 fs = snd_enter_user();
81780 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81781 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81782 snd_leave_user(fs);
81783 } else {
81784 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81785 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81786 }
81787 if (ret == -EPIPE) {
81788 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81789 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81790 struct snd_pcm_plugin_channel *channels;
81791 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81792 if (!in_kernel) {
81793 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81794 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81795 return -EFAULT;
81796 buf = runtime->oss.buffer;
81797 }
81798 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81799 }
81800 } else {
81801 tmp = snd_pcm_oss_write2(substream,
81802 - (const char __force *)buf,
81803 + (const char __force_kernel *)buf,
81804 runtime->oss.period_bytes, 0);
81805 if (tmp <= 0)
81806 goto err;
81807 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81808 struct snd_pcm_runtime *runtime = substream->runtime;
81809 snd_pcm_sframes_t frames, frames1;
81810 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81811 - char __user *final_dst = (char __force __user *)buf;
81812 + char __user *final_dst = (char __force_user *)buf;
81813 if (runtime->oss.plugin_first) {
81814 struct snd_pcm_plugin_channel *channels;
81815 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81816 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81817 xfer += tmp;
81818 runtime->oss.buffer_used -= tmp;
81819 } else {
81820 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81821 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81822 runtime->oss.period_bytes, 0);
81823 if (tmp <= 0)
81824 goto err;
81825 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81826 size1);
81827 size1 /= runtime->channels; /* frames */
81828 fs = snd_enter_user();
81829 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81830 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81831 snd_leave_user(fs);
81832 }
81833 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81834 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81835 index 91cdf943..4085161 100644
81836 --- a/sound/core/pcm_compat.c
81837 +++ b/sound/core/pcm_compat.c
81838 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81839 int err;
81840
81841 fs = snd_enter_user();
81842 - err = snd_pcm_delay(substream, &delay);
81843 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81844 snd_leave_user(fs);
81845 if (err < 0)
81846 return err;
81847 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81848 index f9ddecf..e27404d 100644
81849 --- a/sound/core/pcm_native.c
81850 +++ b/sound/core/pcm_native.c
81851 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81852 switch (substream->stream) {
81853 case SNDRV_PCM_STREAM_PLAYBACK:
81854 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81855 - (void __user *)arg);
81856 + (void __force_user *)arg);
81857 break;
81858 case SNDRV_PCM_STREAM_CAPTURE:
81859 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81860 - (void __user *)arg);
81861 + (void __force_user *)arg);
81862 break;
81863 default:
81864 result = -EINVAL;
81865 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81866 index 60e8fc1..786abcb 100644
81867 --- a/sound/core/seq/seq_device.c
81868 +++ b/sound/core/seq/seq_device.c
81869 @@ -64,7 +64,7 @@ struct ops_list {
81870 int argsize; /* argument size */
81871
81872 /* operators */
81873 - struct snd_seq_dev_ops ops;
81874 + struct snd_seq_dev_ops *ops;
81875
81876 /* registred devices */
81877 struct list_head dev_list; /* list of devices */
81878 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81879
81880 mutex_lock(&ops->reg_mutex);
81881 /* copy driver operators */
81882 - ops->ops = *entry;
81883 + ops->ops = entry;
81884 ops->driver |= DRIVER_LOADED;
81885 ops->argsize = argsize;
81886
81887 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81888 dev->name, ops->id, ops->argsize, dev->argsize);
81889 return -EINVAL;
81890 }
81891 - if (ops->ops.init_device(dev) >= 0) {
81892 + if (ops->ops->init_device(dev) >= 0) {
81893 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81894 ops->num_init_devices++;
81895 } else {
81896 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81897 dev->name, ops->id, ops->argsize, dev->argsize);
81898 return -EINVAL;
81899 }
81900 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81901 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81902 dev->status = SNDRV_SEQ_DEVICE_FREE;
81903 dev->driver_data = NULL;
81904 ops->num_init_devices--;
81905 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81906 index 2d5514b..3afae9c 100644
81907 --- a/sound/drivers/mts64.c
81908 +++ b/sound/drivers/mts64.c
81909 @@ -29,6 +29,7 @@
81910 #include <sound/initval.h>
81911 #include <sound/rawmidi.h>
81912 #include <sound/control.h>
81913 +#include <asm/local.h>
81914
81915 #define CARD_NAME "Miditerminal 4140"
81916 #define DRIVER_NAME "MTS64"
81917 @@ -67,7 +68,7 @@ struct mts64 {
81918 struct pardevice *pardev;
81919 int pardev_claimed;
81920
81921 - int open_count;
81922 + local_t open_count;
81923 int current_midi_output_port;
81924 int current_midi_input_port;
81925 u8 mode[MTS64_NUM_INPUT_PORTS];
81926 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81927 {
81928 struct mts64 *mts = substream->rmidi->private_data;
81929
81930 - if (mts->open_count == 0) {
81931 + if (local_read(&mts->open_count) == 0) {
81932 /* We don't need a spinlock here, because this is just called
81933 if the device has not been opened before.
81934 So there aren't any IRQs from the device */
81935 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81936
81937 msleep(50);
81938 }
81939 - ++(mts->open_count);
81940 + local_inc(&mts->open_count);
81941
81942 return 0;
81943 }
81944 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81945 struct mts64 *mts = substream->rmidi->private_data;
81946 unsigned long flags;
81947
81948 - --(mts->open_count);
81949 - if (mts->open_count == 0) {
81950 + if (local_dec_return(&mts->open_count) == 0) {
81951 /* We need the spinlock_irqsave here because we can still
81952 have IRQs at this point */
81953 spin_lock_irqsave(&mts->lock, flags);
81954 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81955
81956 msleep(500);
81957
81958 - } else if (mts->open_count < 0)
81959 - mts->open_count = 0;
81960 + } else if (local_read(&mts->open_count) < 0)
81961 + local_set(&mts->open_count, 0);
81962
81963 return 0;
81964 }
81965 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81966 index b953fb4..1999c01 100644
81967 --- a/sound/drivers/opl4/opl4_lib.c
81968 +++ b/sound/drivers/opl4/opl4_lib.c
81969 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81970 MODULE_DESCRIPTION("OPL4 driver");
81971 MODULE_LICENSE("GPL");
81972
81973 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81974 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81975 {
81976 int timeout = 10;
81977 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81978 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81979 index 8364855..59f2e2b 100644
81980 --- a/sound/drivers/portman2x4.c
81981 +++ b/sound/drivers/portman2x4.c
81982 @@ -48,6 +48,7 @@
81983 #include <sound/initval.h>
81984 #include <sound/rawmidi.h>
81985 #include <sound/control.h>
81986 +#include <asm/local.h>
81987
81988 #define CARD_NAME "Portman 2x4"
81989 #define DRIVER_NAME "portman"
81990 @@ -85,7 +86,7 @@ struct portman {
81991 struct pardevice *pardev;
81992 int pardev_claimed;
81993
81994 - int open_count;
81995 + local_t open_count;
81996 int mode[PORTMAN_NUM_INPUT_PORTS];
81997 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81998 };
81999 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82000 index ea995af..f1bfa37 100644
82001 --- a/sound/firewire/amdtp.c
82002 +++ b/sound/firewire/amdtp.c
82003 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82004 ptr = s->pcm_buffer_pointer + data_blocks;
82005 if (ptr >= pcm->runtime->buffer_size)
82006 ptr -= pcm->runtime->buffer_size;
82007 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82008 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82009
82010 s->pcm_period_pointer += data_blocks;
82011 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82012 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82013 */
82014 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82015 {
82016 - ACCESS_ONCE(s->source_node_id_field) =
82017 + ACCESS_ONCE_RW(s->source_node_id_field) =
82018 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82019 }
82020 EXPORT_SYMBOL(amdtp_out_stream_update);
82021 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82022 index b680c5e..061b7a0 100644
82023 --- a/sound/firewire/amdtp.h
82024 +++ b/sound/firewire/amdtp.h
82025 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82026 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82027 struct snd_pcm_substream *pcm)
82028 {
82029 - ACCESS_ONCE(s->pcm) = pcm;
82030 + ACCESS_ONCE_RW(s->pcm) = pcm;
82031 }
82032
82033 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82034 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82035 index d428ffe..751ef78 100644
82036 --- a/sound/firewire/isight.c
82037 +++ b/sound/firewire/isight.c
82038 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82039 ptr += count;
82040 if (ptr >= runtime->buffer_size)
82041 ptr -= runtime->buffer_size;
82042 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82043 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82044
82045 isight->period_counter += count;
82046 if (isight->period_counter >= runtime->period_size) {
82047 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82048 if (err < 0)
82049 return err;
82050
82051 - ACCESS_ONCE(isight->pcm_active) = true;
82052 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82053
82054 return 0;
82055 }
82056 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82057 {
82058 struct isight *isight = substream->private_data;
82059
82060 - ACCESS_ONCE(isight->pcm_active) = false;
82061 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82062
82063 mutex_lock(&isight->mutex);
82064 isight_stop_streaming(isight);
82065 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82066
82067 switch (cmd) {
82068 case SNDRV_PCM_TRIGGER_START:
82069 - ACCESS_ONCE(isight->pcm_running) = true;
82070 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82071 break;
82072 case SNDRV_PCM_TRIGGER_STOP:
82073 - ACCESS_ONCE(isight->pcm_running) = false;
82074 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82075 break;
82076 default:
82077 return -EINVAL;
82078 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82079 index 7bd5e33..1fcab12 100644
82080 --- a/sound/isa/cmi8330.c
82081 +++ b/sound/isa/cmi8330.c
82082 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82083
82084 struct snd_pcm *pcm;
82085 struct snd_cmi8330_stream {
82086 - struct snd_pcm_ops ops;
82087 + snd_pcm_ops_no_const ops;
82088 snd_pcm_open_callback_t open;
82089 void *private_data; /* sb or wss */
82090 } streams[2];
82091 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82092 index b2b3c01..e1c1e1f 100644
82093 --- a/sound/oss/sb_audio.c
82094 +++ b/sound/oss/sb_audio.c
82095 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82096 buf16 = (signed short *)(localbuf + localoffs);
82097 while (c)
82098 {
82099 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82100 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82101 if (copy_from_user(lbuf8,
82102 userbuf+useroffs + p,
82103 locallen))
82104 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82105 index 7d8803a..559f8d0 100644
82106 --- a/sound/oss/swarm_cs4297a.c
82107 +++ b/sound/oss/swarm_cs4297a.c
82108 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82109 {
82110 struct cs4297a_state *s;
82111 u32 pwr, id;
82112 - mm_segment_t fs;
82113 int rval;
82114 #ifndef CONFIG_BCM_CS4297A_CSWARM
82115 u64 cfg;
82116 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82117 if (!rval) {
82118 char *sb1250_duart_present;
82119
82120 +#if 0
82121 + mm_segment_t fs;
82122 fs = get_fs();
82123 set_fs(KERNEL_DS);
82124 -#if 0
82125 val = SOUND_MASK_LINE;
82126 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82127 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82128 val = initvol[i].vol;
82129 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82130 }
82131 + set_fs(fs);
82132 // cs4297a_write_ac97(s, 0x18, 0x0808);
82133 #else
82134 // cs4297a_write_ac97(s, 0x5e, 0x180);
82135 cs4297a_write_ac97(s, 0x02, 0x0808);
82136 cs4297a_write_ac97(s, 0x18, 0x0808);
82137 #endif
82138 - set_fs(fs);
82139
82140 list_add(&s->list, &cs4297a_devs);
82141
82142 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82143 index 4f4e545..9b75d10 100644
82144 --- a/sound/pci/hda/hda_codec.h
82145 +++ b/sound/pci/hda/hda_codec.h
82146 @@ -618,7 +618,7 @@ struct hda_bus_ops {
82147 /* notify power-up/down from codec to controller */
82148 void (*pm_notify)(struct hda_bus *bus, bool power_up);
82149 #endif
82150 -};
82151 +} __no_const;
82152
82153 /* template to pass to the bus constructor */
82154 struct hda_bus_template {
82155 @@ -716,6 +716,7 @@ struct hda_codec_ops {
82156 #endif
82157 void (*reboot_notify)(struct hda_codec *codec);
82158 };
82159 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82160
82161 /* record for amp information cache */
82162 struct hda_cache_head {
82163 @@ -746,7 +747,7 @@ struct hda_pcm_ops {
82164 struct snd_pcm_substream *substream);
82165 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82166 struct snd_pcm_substream *substream);
82167 -};
82168 +} __no_const;
82169
82170 /* PCM information for each substream */
82171 struct hda_pcm_stream {
82172 @@ -805,7 +806,7 @@ struct hda_codec {
82173 const char *modelname; /* model name for preset */
82174
82175 /* set by patch */
82176 - struct hda_codec_ops patch_ops;
82177 + hda_codec_ops_no_const patch_ops;
82178
82179 /* PCM to create, set by patch_ops.build_pcms callback */
82180 unsigned int num_pcms;
82181 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82182 index d0e7d87..49ec1bb 100644
82183 --- a/sound/pci/ice1712/ice1712.h
82184 +++ b/sound/pci/ice1712/ice1712.h
82185 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82186 unsigned int mask_flags; /* total mask bits */
82187 struct snd_akm4xxx_ops {
82188 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82189 - } ops;
82190 + } __no_const ops;
82191 };
82192
82193 struct snd_ice1712_spdif {
82194 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82195 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82196 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82197 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82198 - } ops;
82199 + } __no_const ops;
82200 };
82201
82202
82203 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82204 index 4631a23..001ae57 100644
82205 --- a/sound/pci/ymfpci/ymfpci.h
82206 +++ b/sound/pci/ymfpci/ymfpci.h
82207 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82208 spinlock_t reg_lock;
82209 spinlock_t voice_lock;
82210 wait_queue_head_t interrupt_sleep;
82211 - atomic_t interrupt_sleep_count;
82212 + atomic_unchecked_t interrupt_sleep_count;
82213 struct snd_info_entry *proc_entry;
82214 const struct firmware *dsp_microcode;
82215 const struct firmware *controller_microcode;
82216 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82217 index 3a6f03f..bc5c86c 100644
82218 --- a/sound/pci/ymfpci/ymfpci_main.c
82219 +++ b/sound/pci/ymfpci/ymfpci_main.c
82220 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82221 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82222 break;
82223 }
82224 - if (atomic_read(&chip->interrupt_sleep_count)) {
82225 - atomic_set(&chip->interrupt_sleep_count, 0);
82226 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82227 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82228 wake_up(&chip->interrupt_sleep);
82229 }
82230 __end:
82231 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82232 continue;
82233 init_waitqueue_entry(&wait, current);
82234 add_wait_queue(&chip->interrupt_sleep, &wait);
82235 - atomic_inc(&chip->interrupt_sleep_count);
82236 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82237 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82238 remove_wait_queue(&chip->interrupt_sleep, &wait);
82239 }
82240 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82241 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82242 spin_unlock(&chip->reg_lock);
82243
82244 - if (atomic_read(&chip->interrupt_sleep_count)) {
82245 - atomic_set(&chip->interrupt_sleep_count, 0);
82246 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82247 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82248 wake_up(&chip->interrupt_sleep);
82249 }
82250 }
82251 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82252 spin_lock_init(&chip->reg_lock);
82253 spin_lock_init(&chip->voice_lock);
82254 init_waitqueue_head(&chip->interrupt_sleep);
82255 - atomic_set(&chip->interrupt_sleep_count, 0);
82256 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82257 chip->card = card;
82258 chip->pci = pci;
82259 chip->irq = -1;
82260 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82261 new file mode 100644
82262 index 0000000..50f2f2f
82263 --- /dev/null
82264 +++ b/tools/gcc/.gitignore
82265 @@ -0,0 +1 @@
82266 +size_overflow_hash.h
82267 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82268 new file mode 100644
82269 index 0000000..1d09b7e
82270 --- /dev/null
82271 +++ b/tools/gcc/Makefile
82272 @@ -0,0 +1,43 @@
82273 +#CC := gcc
82274 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82275 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82276 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82277 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82278 +
82279 +ifeq ($(PLUGINCC),$(HOSTCC))
82280 +HOSTLIBS := hostlibs
82281 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82282 +else
82283 +HOSTLIBS := hostcxxlibs
82284 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82285 +endif
82286 +
82287 +$(HOSTLIBS)-y := constify_plugin.so
82288 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82289 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82290 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82291 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82292 +$(HOSTLIBS)-y += colorize_plugin.so
82293 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82294 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82295 +
82296 +always := $($(HOSTLIBS)-y)
82297 +
82298 +constify_plugin-objs := constify_plugin.o
82299 +stackleak_plugin-objs := stackleak_plugin.o
82300 +kallocstat_plugin-objs := kallocstat_plugin.o
82301 +kernexec_plugin-objs := kernexec_plugin.o
82302 +checker_plugin-objs := checker_plugin.o
82303 +colorize_plugin-objs := colorize_plugin.o
82304 +size_overflow_plugin-objs := size_overflow_plugin.o
82305 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82306 +
82307 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82308 +
82309 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82310 + cmd_build_size_overflow_hash = \
82311 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82312 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82313 + $(call if_changed,build_size_overflow_hash)
82314 +
82315 +targets += size_overflow_hash.h
82316 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82317 new file mode 100644
82318 index 0000000..d41b5af
82319 --- /dev/null
82320 +++ b/tools/gcc/checker_plugin.c
82321 @@ -0,0 +1,171 @@
82322 +/*
82323 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82324 + * Licensed under the GPL v2
82325 + *
82326 + * Note: the choice of the license means that the compilation process is
82327 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82328 + * but for the kernel it doesn't matter since it doesn't link against
82329 + * any of the gcc libraries
82330 + *
82331 + * gcc plugin to implement various sparse (source code checker) features
82332 + *
82333 + * TODO:
82334 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82335 + *
82336 + * BUGS:
82337 + * - none known
82338 + */
82339 +#include "gcc-plugin.h"
82340 +#include "config.h"
82341 +#include "system.h"
82342 +#include "coretypes.h"
82343 +#include "tree.h"
82344 +#include "tree-pass.h"
82345 +#include "flags.h"
82346 +#include "intl.h"
82347 +#include "toplev.h"
82348 +#include "plugin.h"
82349 +//#include "expr.h" where are you...
82350 +#include "diagnostic.h"
82351 +#include "plugin-version.h"
82352 +#include "tm.h"
82353 +#include "function.h"
82354 +#include "basic-block.h"
82355 +#include "gimple.h"
82356 +#include "rtl.h"
82357 +#include "emit-rtl.h"
82358 +#include "tree-flow.h"
82359 +#include "target.h"
82360 +
82361 +extern void c_register_addr_space (const char *str, addr_space_t as);
82362 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82363 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82364 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82365 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82366 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82367 +
82368 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82369 +extern rtx emit_move_insn(rtx x, rtx y);
82370 +
82371 +int plugin_is_GPL_compatible;
82372 +
82373 +static struct plugin_info checker_plugin_info = {
82374 + .version = "201111150100",
82375 +};
82376 +
82377 +#define ADDR_SPACE_KERNEL 0
82378 +#define ADDR_SPACE_FORCE_KERNEL 1
82379 +#define ADDR_SPACE_USER 2
82380 +#define ADDR_SPACE_FORCE_USER 3
82381 +#define ADDR_SPACE_IOMEM 0
82382 +#define ADDR_SPACE_FORCE_IOMEM 0
82383 +#define ADDR_SPACE_PERCPU 0
82384 +#define ADDR_SPACE_FORCE_PERCPU 0
82385 +#define ADDR_SPACE_RCU 0
82386 +#define ADDR_SPACE_FORCE_RCU 0
82387 +
82388 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82389 +{
82390 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82391 +}
82392 +
82393 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82394 +{
82395 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82396 +}
82397 +
82398 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82399 +{
82400 + return default_addr_space_valid_pointer_mode(mode, as);
82401 +}
82402 +
82403 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82404 +{
82405 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82406 +}
82407 +
82408 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82409 +{
82410 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82411 +}
82412 +
82413 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82414 +{
82415 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82416 + return true;
82417 +
82418 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82419 + return true;
82420 +
82421 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82422 + return true;
82423 +
82424 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82425 + return true;
82426 +
82427 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82428 + return true;
82429 +
82430 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82431 + return true;
82432 +
82433 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82434 + return true;
82435 +
82436 + return subset == superset;
82437 +}
82438 +
82439 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82440 +{
82441 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82442 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82443 +
82444 + return op;
82445 +}
82446 +
82447 +static void register_checker_address_spaces(void *event_data, void *data)
82448 +{
82449 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82450 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82451 + c_register_addr_space("__user", ADDR_SPACE_USER);
82452 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82453 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82454 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82455 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82456 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82457 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82458 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82459 +
82460 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82461 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82462 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82463 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82464 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82465 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82466 + targetm.addr_space.convert = checker_addr_space_convert;
82467 +}
82468 +
82469 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82470 +{
82471 + const char * const plugin_name = plugin_info->base_name;
82472 + const int argc = plugin_info->argc;
82473 + const struct plugin_argument * const argv = plugin_info->argv;
82474 + int i;
82475 +
82476 + if (!plugin_default_version_check(version, &gcc_version)) {
82477 + error(G_("incompatible gcc/plugin versions"));
82478 + return 1;
82479 + }
82480 +
82481 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82482 +
82483 + for (i = 0; i < argc; ++i)
82484 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82485 +
82486 + if (TARGET_64BIT == 0)
82487 + return 0;
82488 +
82489 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82490 +
82491 + return 0;
82492 +}
82493 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82494 new file mode 100644
82495 index 0000000..846aeb0
82496 --- /dev/null
82497 +++ b/tools/gcc/colorize_plugin.c
82498 @@ -0,0 +1,148 @@
82499 +/*
82500 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82501 + * Licensed under the GPL v2
82502 + *
82503 + * Note: the choice of the license means that the compilation process is
82504 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82505 + * but for the kernel it doesn't matter since it doesn't link against
82506 + * any of the gcc libraries
82507 + *
82508 + * gcc plugin to colorize diagnostic output
82509 + *
82510 + */
82511 +
82512 +#include "gcc-plugin.h"
82513 +#include "config.h"
82514 +#include "system.h"
82515 +#include "coretypes.h"
82516 +#include "tree.h"
82517 +#include "tree-pass.h"
82518 +#include "flags.h"
82519 +#include "intl.h"
82520 +#include "toplev.h"
82521 +#include "plugin.h"
82522 +#include "diagnostic.h"
82523 +#include "plugin-version.h"
82524 +#include "tm.h"
82525 +
82526 +int plugin_is_GPL_compatible;
82527 +
82528 +static struct plugin_info colorize_plugin_info = {
82529 + .version = "201203092200",
82530 + .help = NULL,
82531 +};
82532 +
82533 +#define GREEN "\033[32m\033[2m"
82534 +#define LIGHTGREEN "\033[32m\033[1m"
82535 +#define YELLOW "\033[33m\033[2m"
82536 +#define LIGHTYELLOW "\033[33m\033[1m"
82537 +#define RED "\033[31m\033[2m"
82538 +#define LIGHTRED "\033[31m\033[1m"
82539 +#define BLUE "\033[34m\033[2m"
82540 +#define LIGHTBLUE "\033[34m\033[1m"
82541 +#define BRIGHT "\033[m\033[1m"
82542 +#define NORMAL "\033[m"
82543 +
82544 +static diagnostic_starter_fn old_starter;
82545 +static diagnostic_finalizer_fn old_finalizer;
82546 +
82547 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82548 +{
82549 + const char *color;
82550 + char *newprefix;
82551 +
82552 + switch (diagnostic->kind) {
82553 + case DK_NOTE:
82554 + color = LIGHTBLUE;
82555 + break;
82556 +
82557 + case DK_PEDWARN:
82558 + case DK_WARNING:
82559 + color = LIGHTYELLOW;
82560 + break;
82561 +
82562 + case DK_ERROR:
82563 + case DK_FATAL:
82564 + case DK_ICE:
82565 + case DK_PERMERROR:
82566 + case DK_SORRY:
82567 + color = LIGHTRED;
82568 + break;
82569 +
82570 + default:
82571 + color = NORMAL;
82572 + }
82573 +
82574 + old_starter(context, diagnostic);
82575 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82576 + return;
82577 + pp_destroy_prefix(context->printer);
82578 + pp_set_prefix(context->printer, newprefix);
82579 +}
82580 +
82581 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82582 +{
82583 + old_finalizer(context, diagnostic);
82584 +}
82585 +
82586 +static void colorize_arm(void)
82587 +{
82588 + old_starter = diagnostic_starter(global_dc);
82589 + old_finalizer = diagnostic_finalizer(global_dc);
82590 +
82591 + diagnostic_starter(global_dc) = start_colorize;
82592 + diagnostic_finalizer(global_dc) = finalize_colorize;
82593 +}
82594 +
82595 +static unsigned int execute_colorize_rearm(void)
82596 +{
82597 + if (diagnostic_starter(global_dc) == start_colorize)
82598 + return 0;
82599 +
82600 + colorize_arm();
82601 + return 0;
82602 +}
82603 +
82604 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82605 + .pass = {
82606 + .type = SIMPLE_IPA_PASS,
82607 + .name = "colorize_rearm",
82608 + .gate = NULL,
82609 + .execute = execute_colorize_rearm,
82610 + .sub = NULL,
82611 + .next = NULL,
82612 + .static_pass_number = 0,
82613 + .tv_id = TV_NONE,
82614 + .properties_required = 0,
82615 + .properties_provided = 0,
82616 + .properties_destroyed = 0,
82617 + .todo_flags_start = 0,
82618 + .todo_flags_finish = 0
82619 + }
82620 +};
82621 +
82622 +static void colorize_start_unit(void *gcc_data, void *user_data)
82623 +{
82624 + colorize_arm();
82625 +}
82626 +
82627 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82628 +{
82629 + const char * const plugin_name = plugin_info->base_name;
82630 + struct register_pass_info colorize_rearm_pass_info = {
82631 + .pass = &pass_ipa_colorize_rearm.pass,
82632 + .reference_pass_name = "*free_lang_data",
82633 + .ref_pass_instance_number = 1,
82634 + .pos_op = PASS_POS_INSERT_AFTER
82635 + };
82636 +
82637 + if (!plugin_default_version_check(version, &gcc_version)) {
82638 + error(G_("incompatible gcc/plugin versions"));
82639 + return 1;
82640 + }
82641 +
82642 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82643 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82644 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82645 + return 0;
82646 +}
82647 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82648 new file mode 100644
82649 index 0000000..92ed719
82650 --- /dev/null
82651 +++ b/tools/gcc/constify_plugin.c
82652 @@ -0,0 +1,331 @@
82653 +/*
82654 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82655 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82656 + * Licensed under the GPL v2, or (at your option) v3
82657 + *
82658 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82659 + *
82660 + * Homepage:
82661 + * http://www.grsecurity.net/~ephox/const_plugin/
82662 + *
82663 + * Usage:
82664 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82665 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82666 + */
82667 +
82668 +#include "gcc-plugin.h"
82669 +#include "config.h"
82670 +#include "system.h"
82671 +#include "coretypes.h"
82672 +#include "tree.h"
82673 +#include "tree-pass.h"
82674 +#include "flags.h"
82675 +#include "intl.h"
82676 +#include "toplev.h"
82677 +#include "plugin.h"
82678 +#include "diagnostic.h"
82679 +#include "plugin-version.h"
82680 +#include "tm.h"
82681 +#include "function.h"
82682 +#include "basic-block.h"
82683 +#include "gimple.h"
82684 +#include "rtl.h"
82685 +#include "emit-rtl.h"
82686 +#include "tree-flow.h"
82687 +
82688 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82689 +
82690 +int plugin_is_GPL_compatible;
82691 +
82692 +static struct plugin_info const_plugin_info = {
82693 + .version = "201205300030",
82694 + .help = "no-constify\tturn off constification\n",
82695 +};
82696 +
82697 +static void deconstify_tree(tree node);
82698 +
82699 +static void deconstify_type(tree type)
82700 +{
82701 + tree field;
82702 +
82703 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82704 + tree type = TREE_TYPE(field);
82705 +
82706 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82707 + continue;
82708 + if (!TYPE_READONLY(type))
82709 + continue;
82710 +
82711 + deconstify_tree(field);
82712 + }
82713 + TYPE_READONLY(type) = 0;
82714 + C_TYPE_FIELDS_READONLY(type) = 0;
82715 +}
82716 +
82717 +static void deconstify_tree(tree node)
82718 +{
82719 + tree old_type, new_type, field;
82720 +
82721 + old_type = TREE_TYPE(node);
82722 +
82723 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82724 +
82725 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82726 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82727 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82728 + DECL_FIELD_CONTEXT(field) = new_type;
82729 +
82730 + deconstify_type(new_type);
82731 +
82732 + TREE_READONLY(node) = 0;
82733 + TREE_TYPE(node) = new_type;
82734 +}
82735 +
82736 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82737 +{
82738 + tree type;
82739 +
82740 + *no_add_attrs = true;
82741 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82742 + error("%qE attribute does not apply to functions", name);
82743 + return NULL_TREE;
82744 + }
82745 +
82746 + if (TREE_CODE(*node) == VAR_DECL) {
82747 + error("%qE attribute does not apply to variables", name);
82748 + return NULL_TREE;
82749 + }
82750 +
82751 + if (TYPE_P(*node)) {
82752 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82753 + *no_add_attrs = false;
82754 + else
82755 + error("%qE attribute applies to struct and union types only", name);
82756 + return NULL_TREE;
82757 + }
82758 +
82759 + type = TREE_TYPE(*node);
82760 +
82761 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82762 + error("%qE attribute applies to struct and union types only", name);
82763 + return NULL_TREE;
82764 + }
82765 +
82766 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82767 + error("%qE attribute is already applied to the type", name);
82768 + return NULL_TREE;
82769 + }
82770 +
82771 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82772 + error("%qE attribute used on type that is not constified", name);
82773 + return NULL_TREE;
82774 + }
82775 +
82776 + if (TREE_CODE(*node) == TYPE_DECL) {
82777 + deconstify_tree(*node);
82778 + return NULL_TREE;
82779 + }
82780 +
82781 + return NULL_TREE;
82782 +}
82783 +
82784 +static void constify_type(tree type)
82785 +{
82786 + TYPE_READONLY(type) = 1;
82787 + C_TYPE_FIELDS_READONLY(type) = 1;
82788 +}
82789 +
82790 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82791 +{
82792 + *no_add_attrs = true;
82793 + if (!TYPE_P(*node)) {
82794 + error("%qE attribute applies to types only", name);
82795 + return NULL_TREE;
82796 + }
82797 +
82798 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82799 + error("%qE attribute applies to struct and union types only", name);
82800 + return NULL_TREE;
82801 + }
82802 +
82803 + *no_add_attrs = false;
82804 + constify_type(*node);
82805 + return NULL_TREE;
82806 +}
82807 +
82808 +static struct attribute_spec no_const_attr = {
82809 + .name = "no_const",
82810 + .min_length = 0,
82811 + .max_length = 0,
82812 + .decl_required = false,
82813 + .type_required = false,
82814 + .function_type_required = false,
82815 + .handler = handle_no_const_attribute,
82816 +#if BUILDING_GCC_VERSION >= 4007
82817 + .affects_type_identity = true
82818 +#endif
82819 +};
82820 +
82821 +static struct attribute_spec do_const_attr = {
82822 + .name = "do_const",
82823 + .min_length = 0,
82824 + .max_length = 0,
82825 + .decl_required = false,
82826 + .type_required = false,
82827 + .function_type_required = false,
82828 + .handler = handle_do_const_attribute,
82829 +#if BUILDING_GCC_VERSION >= 4007
82830 + .affects_type_identity = true
82831 +#endif
82832 +};
82833 +
82834 +static void register_attributes(void *event_data, void *data)
82835 +{
82836 + register_attribute(&no_const_attr);
82837 + register_attribute(&do_const_attr);
82838 +}
82839 +
82840 +static bool is_fptr(tree field)
82841 +{
82842 + tree ptr = TREE_TYPE(field);
82843 +
82844 + if (TREE_CODE(ptr) != POINTER_TYPE)
82845 + return false;
82846 +
82847 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82848 +}
82849 +
82850 +static bool walk_struct(tree node)
82851 +{
82852 + tree field;
82853 +
82854 + if (TYPE_FIELDS(node) == NULL_TREE)
82855 + return false;
82856 +
82857 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82858 + gcc_assert(!TYPE_READONLY(node));
82859 + deconstify_type(node);
82860 + return false;
82861 + }
82862 +
82863 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82864 + tree type = TREE_TYPE(field);
82865 + enum tree_code code = TREE_CODE(type);
82866 +
82867 + if (node == type)
82868 + return false;
82869 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82870 + if (!(walk_struct(type)))
82871 + return false;
82872 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82873 + return false;
82874 + }
82875 + return true;
82876 +}
82877 +
82878 +static void finish_type(void *event_data, void *data)
82879 +{
82880 + tree type = (tree)event_data;
82881 +
82882 + if (type == NULL_TREE || type == error_mark_node)
82883 + return;
82884 +
82885 + if (TYPE_READONLY(type))
82886 + return;
82887 +
82888 + if (walk_struct(type))
82889 + constify_type(type);
82890 +}
82891 +
82892 +static unsigned int check_local_variables(void);
82893 +
82894 +struct gimple_opt_pass pass_local_variable = {
82895 + {
82896 + .type = GIMPLE_PASS,
82897 + .name = "check_local_variables",
82898 + .gate = NULL,
82899 + .execute = check_local_variables,
82900 + .sub = NULL,
82901 + .next = NULL,
82902 + .static_pass_number = 0,
82903 + .tv_id = TV_NONE,
82904 + .properties_required = 0,
82905 + .properties_provided = 0,
82906 + .properties_destroyed = 0,
82907 + .todo_flags_start = 0,
82908 + .todo_flags_finish = 0
82909 + }
82910 +};
82911 +
82912 +static unsigned int check_local_variables(void)
82913 +{
82914 + tree var;
82915 + referenced_var_iterator rvi;
82916 +
82917 +#if BUILDING_GCC_VERSION == 4005
82918 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82919 +#else
82920 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82921 +#endif
82922 + tree type = TREE_TYPE(var);
82923 +
82924 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82925 + continue;
82926 +
82927 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82928 + continue;
82929 +
82930 + if (!TYPE_READONLY(type))
82931 + continue;
82932 +
82933 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82934 +// continue;
82935 +
82936 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82937 +// continue;
82938 +
82939 + if (walk_struct(type)) {
82940 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82941 + return 1;
82942 + }
82943 + }
82944 + return 0;
82945 +}
82946 +
82947 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82948 +{
82949 + const char * const plugin_name = plugin_info->base_name;
82950 + const int argc = plugin_info->argc;
82951 + const struct plugin_argument * const argv = plugin_info->argv;
82952 + int i;
82953 + bool constify = true;
82954 +
82955 + struct register_pass_info local_variable_pass_info = {
82956 + .pass = &pass_local_variable.pass,
82957 + .reference_pass_name = "*referenced_vars",
82958 + .ref_pass_instance_number = 1,
82959 + .pos_op = PASS_POS_INSERT_AFTER
82960 + };
82961 +
82962 + if (!plugin_default_version_check(version, &gcc_version)) {
82963 + error(G_("incompatible gcc/plugin versions"));
82964 + return 1;
82965 + }
82966 +
82967 + for (i = 0; i < argc; ++i) {
82968 + if (!(strcmp(argv[i].key, "no-constify"))) {
82969 + constify = false;
82970 + continue;
82971 + }
82972 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82973 + }
82974 +
82975 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82976 + if (constify) {
82977 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82978 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82979 + }
82980 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82981 +
82982 + return 0;
82983 +}
82984 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82985 new file mode 100644
82986 index 0000000..e518932
82987 --- /dev/null
82988 +++ b/tools/gcc/generate_size_overflow_hash.sh
82989 @@ -0,0 +1,94 @@
82990 +#!/bin/bash
82991 +
82992 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82993 +
82994 +header1="size_overflow_hash.h"
82995 +database="size_overflow_hash.data"
82996 +n=65536
82997 +
82998 +usage() {
82999 +cat <<EOF
83000 +usage: $0 options
83001 +OPTIONS:
83002 + -h|--help help
83003 + -o header file
83004 + -d database file
83005 + -n hash array size
83006 +EOF
83007 + return 0
83008 +}
83009 +
83010 +while true
83011 +do
83012 + case "$1" in
83013 + -h|--help) usage && exit 0;;
83014 + -n) n=$2; shift 2;;
83015 + -o) header1="$2"; shift 2;;
83016 + -d) database="$2"; shift 2;;
83017 + --) shift 1; break ;;
83018 + *) break ;;
83019 + esac
83020 +done
83021 +
83022 +create_defines() {
83023 + for i in `seq 0 31`
83024 + do
83025 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83026 + done
83027 + echo >> "$header1"
83028 +}
83029 +
83030 +create_structs() {
83031 + rm -f "$header1"
83032 +
83033 + create_defines
83034 +
83035 + cat "$database" | while read data
83036 + do
83037 + data_array=($data)
83038 + struct_hash_name="${data_array[0]}"
83039 + funcn="${data_array[1]}"
83040 + params="${data_array[2]}"
83041 + next="${data_array[4]}"
83042 +
83043 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83044 +
83045 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83046 + echo -en "\t.param\t= " >> "$header1"
83047 + line=
83048 + for param_num in ${params//-/ };
83049 + do
83050 + line="${line}PARAM"$param_num"|"
83051 + done
83052 +
83053 + echo -e "${line%?},\n};\n" >> "$header1"
83054 + done
83055 +}
83056 +
83057 +create_headers() {
83058 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83059 +}
83060 +
83061 +create_array_elements() {
83062 + index=0
83063 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83064 + do
83065 + data_array=($data)
83066 + i="${data_array[3]}"
83067 + hash="${data_array[0]}"
83068 + while [[ $index -lt $i ]]
83069 + do
83070 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83071 + index=$(($index + 1))
83072 + done
83073 + index=$(($index + 1))
83074 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83075 + done
83076 + echo '};' >> $header1
83077 +}
83078 +
83079 +create_structs
83080 +create_headers
83081 +create_array_elements
83082 +
83083 +exit 0
83084 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83085 new file mode 100644
83086 index 0000000..a86e422
83087 --- /dev/null
83088 +++ b/tools/gcc/kallocstat_plugin.c
83089 @@ -0,0 +1,167 @@
83090 +/*
83091 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83092 + * Licensed under the GPL v2
83093 + *
83094 + * Note: the choice of the license means that the compilation process is
83095 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83096 + * but for the kernel it doesn't matter since it doesn't link against
83097 + * any of the gcc libraries
83098 + *
83099 + * gcc plugin to find the distribution of k*alloc sizes
83100 + *
83101 + * TODO:
83102 + *
83103 + * BUGS:
83104 + * - none known
83105 + */
83106 +#include "gcc-plugin.h"
83107 +#include "config.h"
83108 +#include "system.h"
83109 +#include "coretypes.h"
83110 +#include "tree.h"
83111 +#include "tree-pass.h"
83112 +#include "flags.h"
83113 +#include "intl.h"
83114 +#include "toplev.h"
83115 +#include "plugin.h"
83116 +//#include "expr.h" where are you...
83117 +#include "diagnostic.h"
83118 +#include "plugin-version.h"
83119 +#include "tm.h"
83120 +#include "function.h"
83121 +#include "basic-block.h"
83122 +#include "gimple.h"
83123 +#include "rtl.h"
83124 +#include "emit-rtl.h"
83125 +
83126 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83127 +
83128 +int plugin_is_GPL_compatible;
83129 +
83130 +static const char * const kalloc_functions[] = {
83131 + "__kmalloc",
83132 + "kmalloc",
83133 + "kmalloc_large",
83134 + "kmalloc_node",
83135 + "kmalloc_order",
83136 + "kmalloc_order_trace",
83137 + "kmalloc_slab",
83138 + "kzalloc",
83139 + "kzalloc_node",
83140 +};
83141 +
83142 +static struct plugin_info kallocstat_plugin_info = {
83143 + .version = "201111150100",
83144 +};
83145 +
83146 +static unsigned int execute_kallocstat(void);
83147 +
83148 +static struct gimple_opt_pass kallocstat_pass = {
83149 + .pass = {
83150 + .type = GIMPLE_PASS,
83151 + .name = "kallocstat",
83152 + .gate = NULL,
83153 + .execute = execute_kallocstat,
83154 + .sub = NULL,
83155 + .next = NULL,
83156 + .static_pass_number = 0,
83157 + .tv_id = TV_NONE,
83158 + .properties_required = 0,
83159 + .properties_provided = 0,
83160 + .properties_destroyed = 0,
83161 + .todo_flags_start = 0,
83162 + .todo_flags_finish = 0
83163 + }
83164 +};
83165 +
83166 +static bool is_kalloc(const char *fnname)
83167 +{
83168 + size_t i;
83169 +
83170 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83171 + if (!strcmp(fnname, kalloc_functions[i]))
83172 + return true;
83173 + return false;
83174 +}
83175 +
83176 +static unsigned int execute_kallocstat(void)
83177 +{
83178 + basic_block bb;
83179 +
83180 + // 1. loop through BBs and GIMPLE statements
83181 + FOR_EACH_BB(bb) {
83182 + gimple_stmt_iterator gsi;
83183 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83184 + // gimple match:
83185 + tree fndecl, size;
83186 + gimple call_stmt;
83187 + const char *fnname;
83188 +
83189 + // is it a call
83190 + call_stmt = gsi_stmt(gsi);
83191 + if (!is_gimple_call(call_stmt))
83192 + continue;
83193 + fndecl = gimple_call_fndecl(call_stmt);
83194 + if (fndecl == NULL_TREE)
83195 + continue;
83196 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83197 + continue;
83198 +
83199 + // is it a call to k*alloc
83200 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83201 + if (!is_kalloc(fnname))
83202 + continue;
83203 +
83204 + // is the size arg the result of a simple const assignment
83205 + size = gimple_call_arg(call_stmt, 0);
83206 + while (true) {
83207 + gimple def_stmt;
83208 + expanded_location xloc;
83209 + size_t size_val;
83210 +
83211 + if (TREE_CODE(size) != SSA_NAME)
83212 + break;
83213 + def_stmt = SSA_NAME_DEF_STMT(size);
83214 + if (!def_stmt || !is_gimple_assign(def_stmt))
83215 + break;
83216 + if (gimple_num_ops(def_stmt) != 2)
83217 + break;
83218 + size = gimple_assign_rhs1(def_stmt);
83219 + if (!TREE_CONSTANT(size))
83220 + continue;
83221 + xloc = expand_location(gimple_location(def_stmt));
83222 + if (!xloc.file)
83223 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83224 + size_val = TREE_INT_CST_LOW(size);
83225 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83226 + break;
83227 + }
83228 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83229 +//debug_tree(gimple_call_fn(call_stmt));
83230 +//print_node(stderr, "pax", fndecl, 4);
83231 + }
83232 + }
83233 +
83234 + return 0;
83235 +}
83236 +
83237 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83238 +{
83239 + const char * const plugin_name = plugin_info->base_name;
83240 + struct register_pass_info kallocstat_pass_info = {
83241 + .pass = &kallocstat_pass.pass,
83242 + .reference_pass_name = "ssa",
83243 + .ref_pass_instance_number = 1,
83244 + .pos_op = PASS_POS_INSERT_AFTER
83245 + };
83246 +
83247 + if (!plugin_default_version_check(version, &gcc_version)) {
83248 + error(G_("incompatible gcc/plugin versions"));
83249 + return 1;
83250 + }
83251 +
83252 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83253 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83254 +
83255 + return 0;
83256 +}
83257 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83258 new file mode 100644
83259 index 0000000..8856202
83260 --- /dev/null
83261 +++ b/tools/gcc/kernexec_plugin.c
83262 @@ -0,0 +1,432 @@
83263 +/*
83264 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83265 + * Licensed under the GPL v2
83266 + *
83267 + * Note: the choice of the license means that the compilation process is
83268 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83269 + * but for the kernel it doesn't matter since it doesn't link against
83270 + * any of the gcc libraries
83271 + *
83272 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83273 + *
83274 + * TODO:
83275 + *
83276 + * BUGS:
83277 + * - none known
83278 + */
83279 +#include "gcc-plugin.h"
83280 +#include "config.h"
83281 +#include "system.h"
83282 +#include "coretypes.h"
83283 +#include "tree.h"
83284 +#include "tree-pass.h"
83285 +#include "flags.h"
83286 +#include "intl.h"
83287 +#include "toplev.h"
83288 +#include "plugin.h"
83289 +//#include "expr.h" where are you...
83290 +#include "diagnostic.h"
83291 +#include "plugin-version.h"
83292 +#include "tm.h"
83293 +#include "function.h"
83294 +#include "basic-block.h"
83295 +#include "gimple.h"
83296 +#include "rtl.h"
83297 +#include "emit-rtl.h"
83298 +#include "tree-flow.h"
83299 +
83300 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83301 +extern rtx emit_move_insn(rtx x, rtx y);
83302 +
83303 +#if BUILDING_GCC_VERSION <= 4006
83304 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
83305 +#endif
83306 +
83307 +int plugin_is_GPL_compatible;
83308 +
83309 +static struct plugin_info kernexec_plugin_info = {
83310 + .version = "201111291120",
83311 + .help = "method=[bts|or]\tinstrumentation method\n"
83312 +};
83313 +
83314 +static unsigned int execute_kernexec_reload(void);
83315 +static unsigned int execute_kernexec_fptr(void);
83316 +static unsigned int execute_kernexec_retaddr(void);
83317 +static bool kernexec_cmodel_check(void);
83318 +
83319 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83320 +static void (*kernexec_instrument_retaddr)(rtx);
83321 +
83322 +static struct gimple_opt_pass kernexec_reload_pass = {
83323 + .pass = {
83324 + .type = GIMPLE_PASS,
83325 + .name = "kernexec_reload",
83326 + .gate = kernexec_cmodel_check,
83327 + .execute = execute_kernexec_reload,
83328 + .sub = NULL,
83329 + .next = NULL,
83330 + .static_pass_number = 0,
83331 + .tv_id = TV_NONE,
83332 + .properties_required = 0,
83333 + .properties_provided = 0,
83334 + .properties_destroyed = 0,
83335 + .todo_flags_start = 0,
83336 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83337 + }
83338 +};
83339 +
83340 +static struct gimple_opt_pass kernexec_fptr_pass = {
83341 + .pass = {
83342 + .type = GIMPLE_PASS,
83343 + .name = "kernexec_fptr",
83344 + .gate = kernexec_cmodel_check,
83345 + .execute = execute_kernexec_fptr,
83346 + .sub = NULL,
83347 + .next = NULL,
83348 + .static_pass_number = 0,
83349 + .tv_id = TV_NONE,
83350 + .properties_required = 0,
83351 + .properties_provided = 0,
83352 + .properties_destroyed = 0,
83353 + .todo_flags_start = 0,
83354 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83355 + }
83356 +};
83357 +
83358 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83359 + .pass = {
83360 + .type = RTL_PASS,
83361 + .name = "kernexec_retaddr",
83362 + .gate = kernexec_cmodel_check,
83363 + .execute = execute_kernexec_retaddr,
83364 + .sub = NULL,
83365 + .next = NULL,
83366 + .static_pass_number = 0,
83367 + .tv_id = TV_NONE,
83368 + .properties_required = 0,
83369 + .properties_provided = 0,
83370 + .properties_destroyed = 0,
83371 + .todo_flags_start = 0,
83372 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83373 + }
83374 +};
83375 +
83376 +static bool kernexec_cmodel_check(void)
83377 +{
83378 + tree section;
83379 +
83380 + if (ix86_cmodel != CM_KERNEL)
83381 + return false;
83382 +
83383 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83384 + if (!section || !TREE_VALUE(section))
83385 + return true;
83386 +
83387 + section = TREE_VALUE(TREE_VALUE(section));
83388 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83389 + return true;
83390 +
83391 + return false;
83392 +}
83393 +
83394 +/*
83395 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83396 + */
83397 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83398 +{
83399 + gimple asm_movabs_stmt;
83400 +
83401 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83402 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83403 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83404 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83405 + update_stmt(asm_movabs_stmt);
83406 +}
83407 +
83408 +/*
83409 + * find all asm() stmts that clobber r10 and add a reload of r10
83410 + */
83411 +static unsigned int execute_kernexec_reload(void)
83412 +{
83413 + basic_block bb;
83414 +
83415 + // 1. loop through BBs and GIMPLE statements
83416 + FOR_EACH_BB(bb) {
83417 + gimple_stmt_iterator gsi;
83418 +
83419 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83420 + // gimple match: __asm__ ("" : : : "r10");
83421 + gimple asm_stmt;
83422 + size_t nclobbers;
83423 +
83424 + // is it an asm ...
83425 + asm_stmt = gsi_stmt(gsi);
83426 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83427 + continue;
83428 +
83429 + // ... clobbering r10
83430 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83431 + while (nclobbers--) {
83432 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83433 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83434 + continue;
83435 + kernexec_reload_fptr_mask(&gsi);
83436 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83437 + break;
83438 + }
83439 + }
83440 + }
83441 +
83442 + return 0;
83443 +}
83444 +
83445 +/*
83446 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83447 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83448 + */
83449 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83450 +{
83451 + gimple assign_intptr, assign_new_fptr, call_stmt;
83452 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83453 +
83454 + call_stmt = gsi_stmt(*gsi);
83455 + old_fptr = gimple_call_fn(call_stmt);
83456 +
83457 + // create temporary unsigned long variable used for bitops and cast fptr to it
83458 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83459 + add_referenced_var(intptr);
83460 + mark_sym_for_renaming(intptr);
83461 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83462 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83463 + update_stmt(assign_intptr);
83464 +
83465 + // apply logical or to temporary unsigned long and bitmask
83466 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83467 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83468 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83469 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83470 + update_stmt(assign_intptr);
83471 +
83472 + // cast temporary unsigned long back to a temporary fptr variable
83473 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83474 + add_referenced_var(new_fptr);
83475 + mark_sym_for_renaming(new_fptr);
83476 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83477 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83478 + update_stmt(assign_new_fptr);
83479 +
83480 + // replace call stmt fn with the new fptr
83481 + gimple_call_set_fn(call_stmt, new_fptr);
83482 + update_stmt(call_stmt);
83483 +}
83484 +
83485 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83486 +{
83487 + gimple asm_or_stmt, call_stmt;
83488 + tree old_fptr, new_fptr, input, output;
83489 + VEC(tree, gc) *inputs = NULL;
83490 + VEC(tree, gc) *outputs = NULL;
83491 +
83492 + call_stmt = gsi_stmt(*gsi);
83493 + old_fptr = gimple_call_fn(call_stmt);
83494 +
83495 + // create temporary fptr variable
83496 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83497 + add_referenced_var(new_fptr);
83498 + mark_sym_for_renaming(new_fptr);
83499 +
83500 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83501 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83502 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83503 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83504 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83505 + VEC_safe_push(tree, gc, inputs, input);
83506 + VEC_safe_push(tree, gc, outputs, output);
83507 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83508 + gimple_asm_set_volatile(asm_or_stmt, true);
83509 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83510 + update_stmt(asm_or_stmt);
83511 +
83512 + // replace call stmt fn with the new fptr
83513 + gimple_call_set_fn(call_stmt, new_fptr);
83514 + update_stmt(call_stmt);
83515 +}
83516 +
83517 +/*
83518 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83519 + */
83520 +static unsigned int execute_kernexec_fptr(void)
83521 +{
83522 + basic_block bb;
83523 +
83524 + // 1. loop through BBs and GIMPLE statements
83525 + FOR_EACH_BB(bb) {
83526 + gimple_stmt_iterator gsi;
83527 +
83528 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83529 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83530 + tree fn;
83531 + gimple call_stmt;
83532 +
83533 + // is it a call ...
83534 + call_stmt = gsi_stmt(gsi);
83535 + if (!is_gimple_call(call_stmt))
83536 + continue;
83537 + fn = gimple_call_fn(call_stmt);
83538 + if (TREE_CODE(fn) == ADDR_EXPR)
83539 + continue;
83540 + if (TREE_CODE(fn) != SSA_NAME)
83541 + gcc_unreachable();
83542 +
83543 + // ... through a function pointer
83544 + fn = SSA_NAME_VAR(fn);
83545 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83546 + continue;
83547 + fn = TREE_TYPE(fn);
83548 + if (TREE_CODE(fn) != POINTER_TYPE)
83549 + continue;
83550 + fn = TREE_TYPE(fn);
83551 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83552 + continue;
83553 +
83554 + kernexec_instrument_fptr(&gsi);
83555 +
83556 +//debug_tree(gimple_call_fn(call_stmt));
83557 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83558 + }
83559 + }
83560 +
83561 + return 0;
83562 +}
83563 +
83564 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83565 +static void kernexec_instrument_retaddr_bts(rtx insn)
83566 +{
83567 + rtx btsq;
83568 + rtvec argvec, constraintvec, labelvec;
83569 + int line;
83570 +
83571 + // create asm volatile("btsq $63,(%%rsp)":::)
83572 + argvec = rtvec_alloc(0);
83573 + constraintvec = rtvec_alloc(0);
83574 + labelvec = rtvec_alloc(0);
83575 + line = expand_location(RTL_LOCATION(insn)).line;
83576 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83577 + MEM_VOLATILE_P(btsq) = 1;
83578 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83579 + emit_insn_before(btsq, insn);
83580 +}
83581 +
83582 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83583 +static void kernexec_instrument_retaddr_or(rtx insn)
83584 +{
83585 + rtx orq;
83586 + rtvec argvec, constraintvec, labelvec;
83587 + int line;
83588 +
83589 + // create asm volatile("orq %%r10,(%%rsp)":::)
83590 + argvec = rtvec_alloc(0);
83591 + constraintvec = rtvec_alloc(0);
83592 + labelvec = rtvec_alloc(0);
83593 + line = expand_location(RTL_LOCATION(insn)).line;
83594 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83595 + MEM_VOLATILE_P(orq) = 1;
83596 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83597 + emit_insn_before(orq, insn);
83598 +}
83599 +
83600 +/*
83601 + * find all asm level function returns and forcibly set the highest bit of the return address
83602 + */
83603 +static unsigned int execute_kernexec_retaddr(void)
83604 +{
83605 + rtx insn;
83606 +
83607 + // 1. find function returns
83608 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83609 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83610 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83611 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
83612 + rtx body;
83613 +
83614 + // is it a retn
83615 + if (!JUMP_P(insn))
83616 + continue;
83617 + body = PATTERN(insn);
83618 + if (GET_CODE(body) == PARALLEL)
83619 + body = XVECEXP(body, 0, 0);
83620 + if (!ANY_RETURN_P(body))
83621 + continue;
83622 + kernexec_instrument_retaddr(insn);
83623 + }
83624 +
83625 +// print_simple_rtl(stderr, get_insns());
83626 +// print_rtl(stderr, get_insns());
83627 +
83628 + return 0;
83629 +}
83630 +
83631 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83632 +{
83633 + const char * const plugin_name = plugin_info->base_name;
83634 + const int argc = plugin_info->argc;
83635 + const struct plugin_argument * const argv = plugin_info->argv;
83636 + int i;
83637 + struct register_pass_info kernexec_reload_pass_info = {
83638 + .pass = &kernexec_reload_pass.pass,
83639 + .reference_pass_name = "ssa",
83640 + .ref_pass_instance_number = 1,
83641 + .pos_op = PASS_POS_INSERT_AFTER
83642 + };
83643 + struct register_pass_info kernexec_fptr_pass_info = {
83644 + .pass = &kernexec_fptr_pass.pass,
83645 + .reference_pass_name = "ssa",
83646 + .ref_pass_instance_number = 1,
83647 + .pos_op = PASS_POS_INSERT_AFTER
83648 + };
83649 + struct register_pass_info kernexec_retaddr_pass_info = {
83650 + .pass = &kernexec_retaddr_pass.pass,
83651 + .reference_pass_name = "pro_and_epilogue",
83652 + .ref_pass_instance_number = 1,
83653 + .pos_op = PASS_POS_INSERT_AFTER
83654 + };
83655 +
83656 + if (!plugin_default_version_check(version, &gcc_version)) {
83657 + error(G_("incompatible gcc/plugin versions"));
83658 + return 1;
83659 + }
83660 +
83661 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83662 +
83663 + if (TARGET_64BIT == 0)
83664 + return 0;
83665 +
83666 + for (i = 0; i < argc; ++i) {
83667 + if (!strcmp(argv[i].key, "method")) {
83668 + if (!argv[i].value) {
83669 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83670 + continue;
83671 + }
83672 + if (!strcmp(argv[i].value, "bts")) {
83673 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83674 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83675 + } else if (!strcmp(argv[i].value, "or")) {
83676 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83677 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83678 + fix_register("r10", 1, 1);
83679 + } else
83680 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83681 + continue;
83682 + }
83683 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83684 + }
83685 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83686 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83687 +
83688 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83689 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83690 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83691 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83692 +
83693 + return 0;
83694 +}
83695 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83696 new file mode 100644
83697 index 0000000..b8008f7
83698 --- /dev/null
83699 +++ b/tools/gcc/latent_entropy_plugin.c
83700 @@ -0,0 +1,295 @@
83701 +/*
83702 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83703 + * Licensed under the GPL v2
83704 + *
83705 + * Note: the choice of the license means that the compilation process is
83706 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83707 + * but for the kernel it doesn't matter since it doesn't link against
83708 + * any of the gcc libraries
83709 + *
83710 + * gcc plugin to help generate a little bit of entropy from program state,
83711 + * used during boot in the kernel
83712 + *
83713 + * TODO:
83714 + * - add ipa pass to identify not explicitly marked candidate functions
83715 + * - mix in more program state (function arguments/return values, loop variables, etc)
83716 + * - more instrumentation control via attribute parameters
83717 + *
83718 + * BUGS:
83719 + * - LTO needs -flto-partition=none for now
83720 + */
83721 +#include "gcc-plugin.h"
83722 +#include "config.h"
83723 +#include "system.h"
83724 +#include "coretypes.h"
83725 +#include "tree.h"
83726 +#include "tree-pass.h"
83727 +#include "flags.h"
83728 +#include "intl.h"
83729 +#include "toplev.h"
83730 +#include "plugin.h"
83731 +//#include "expr.h" where are you...
83732 +#include "diagnostic.h"
83733 +#include "plugin-version.h"
83734 +#include "tm.h"
83735 +#include "function.h"
83736 +#include "basic-block.h"
83737 +#include "gimple.h"
83738 +#include "rtl.h"
83739 +#include "emit-rtl.h"
83740 +#include "tree-flow.h"
83741 +
83742 +int plugin_is_GPL_compatible;
83743 +
83744 +static tree latent_entropy_decl;
83745 +
83746 +static struct plugin_info latent_entropy_plugin_info = {
83747 + .version = "201207271820",
83748 + .help = NULL
83749 +};
83750 +
83751 +static unsigned int execute_latent_entropy(void);
83752 +static bool gate_latent_entropy(void);
83753 +
83754 +static struct gimple_opt_pass latent_entropy_pass = {
83755 + .pass = {
83756 + .type = GIMPLE_PASS,
83757 + .name = "latent_entropy",
83758 + .gate = gate_latent_entropy,
83759 + .execute = execute_latent_entropy,
83760 + .sub = NULL,
83761 + .next = NULL,
83762 + .static_pass_number = 0,
83763 + .tv_id = TV_NONE,
83764 + .properties_required = PROP_gimple_leh | PROP_cfg,
83765 + .properties_provided = 0,
83766 + .properties_destroyed = 0,
83767 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83768 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83769 + }
83770 +};
83771 +
83772 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83773 +{
83774 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83775 + *no_add_attrs = true;
83776 + error("%qE attribute only applies to functions", name);
83777 + }
83778 + return NULL_TREE;
83779 +}
83780 +
83781 +static struct attribute_spec latent_entropy_attr = {
83782 + .name = "latent_entropy",
83783 + .min_length = 0,
83784 + .max_length = 0,
83785 + .decl_required = true,
83786 + .type_required = false,
83787 + .function_type_required = false,
83788 + .handler = handle_latent_entropy_attribute,
83789 +#if BUILDING_GCC_VERSION >= 4007
83790 + .affects_type_identity = false
83791 +#endif
83792 +};
83793 +
83794 +static void register_attributes(void *event_data, void *data)
83795 +{
83796 + register_attribute(&latent_entropy_attr);
83797 +}
83798 +
83799 +static bool gate_latent_entropy(void)
83800 +{
83801 + tree latent_entropy_attr;
83802 +
83803 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83804 + return latent_entropy_attr != NULL_TREE;
83805 +}
83806 +
83807 +static unsigned HOST_WIDE_INT seed;
83808 +static unsigned HOST_WIDE_INT get_random_const(void)
83809 +{
83810 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83811 + return seed;
83812 +}
83813 +
83814 +static enum tree_code get_op(tree *rhs)
83815 +{
83816 + static enum tree_code op;
83817 + unsigned HOST_WIDE_INT random_const;
83818 +
83819 + random_const = get_random_const();
83820 +
83821 + switch (op) {
83822 + case BIT_XOR_EXPR:
83823 + op = PLUS_EXPR;
83824 + break;
83825 +
83826 + case PLUS_EXPR:
83827 + if (rhs) {
83828 + op = LROTATE_EXPR;
83829 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83830 + break;
83831 + }
83832 +
83833 + case LROTATE_EXPR:
83834 + default:
83835 + op = BIT_XOR_EXPR;
83836 + break;
83837 + }
83838 + if (rhs)
83839 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83840 + return op;
83841 +}
83842 +
83843 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83844 +{
83845 + gimple_stmt_iterator gsi;
83846 + gimple assign;
83847 + tree addxorrol, rhs;
83848 + enum tree_code op;
83849 +
83850 + op = get_op(&rhs);
83851 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83852 + assign = gimple_build_assign(local_entropy, addxorrol);
83853 + find_referenced_vars_in(assign);
83854 +//debug_bb(bb);
83855 + gsi = gsi_after_labels(bb);
83856 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83857 + update_stmt(assign);
83858 +}
83859 +
83860 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83861 +{
83862 + gimple_stmt_iterator gsi;
83863 + gimple assign;
83864 + tree addxorrol, temp;
83865 +
83866 + // 1. create temporary copy of latent_entropy
83867 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83868 + add_referenced_var(temp);
83869 + mark_sym_for_renaming(temp);
83870 +
83871 + // 2. read...
83872 + assign = gimple_build_assign(temp, latent_entropy_decl);
83873 + find_referenced_vars_in(assign);
83874 + gsi = gsi_after_labels(bb);
83875 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83876 + update_stmt(assign);
83877 +
83878 + // 3. ...modify...
83879 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83880 + assign = gimple_build_assign(temp, addxorrol);
83881 + find_referenced_vars_in(assign);
83882 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83883 + update_stmt(assign);
83884 +
83885 + // 4. ...write latent_entropy
83886 + assign = gimple_build_assign(latent_entropy_decl, temp);
83887 + find_referenced_vars_in(assign);
83888 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83889 + update_stmt(assign);
83890 +}
83891 +
83892 +static unsigned int execute_latent_entropy(void)
83893 +{
83894 + basic_block bb;
83895 + gimple assign;
83896 + gimple_stmt_iterator gsi;
83897 + tree local_entropy;
83898 +
83899 + if (!latent_entropy_decl) {
83900 + struct varpool_node *node;
83901 +
83902 + for (node = varpool_nodes; node; node = node->next) {
83903 + tree var = node->decl;
83904 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83905 + continue;
83906 + latent_entropy_decl = var;
83907 +// debug_tree(var);
83908 + break;
83909 + }
83910 + if (!latent_entropy_decl) {
83911 +// debug_tree(current_function_decl);
83912 + return 0;
83913 + }
83914 + }
83915 +
83916 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83917 +
83918 + // 1. create local entropy variable
83919 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83920 + add_referenced_var(local_entropy);
83921 + mark_sym_for_renaming(local_entropy);
83922 +
83923 + // 2. initialize local entropy variable
83924 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83925 + if (dom_info_available_p(CDI_DOMINATORS))
83926 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83927 + gsi = gsi_start_bb(bb);
83928 +
83929 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83930 +// gimple_set_location(assign, loc);
83931 + find_referenced_vars_in(assign);
83932 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83933 + update_stmt(assign);
83934 + bb = bb->next_bb;
83935 +
83936 + // 3. instrument each BB with an operation on the local entropy variable
83937 + while (bb != EXIT_BLOCK_PTR) {
83938 + perturb_local_entropy(bb, local_entropy);
83939 + bb = bb->next_bb;
83940 + };
83941 +
83942 + // 4. mix local entropy into the global entropy variable
83943 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83944 + return 0;
83945 +}
83946 +
83947 +static void start_unit_callback(void *gcc_data, void *user_data)
83948 +{
83949 +#if BUILDING_GCC_VERSION >= 4007
83950 + seed = get_random_seed(false);
83951 +#else
83952 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83953 + seed *= seed;
83954 +#endif
83955 +
83956 + if (in_lto_p)
83957 + return;
83958 +
83959 + // extern u64 latent_entropy
83960 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83961 +
83962 + TREE_STATIC(latent_entropy_decl) = 1;
83963 + TREE_PUBLIC(latent_entropy_decl) = 1;
83964 + TREE_USED(latent_entropy_decl) = 1;
83965 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83966 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83967 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83968 + DECL_INITIAL(latent_entropy_decl) = NULL;
83969 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83970 +// varpool_finalize_decl(latent_entropy_decl);
83971 +// varpool_mark_needed_node(latent_entropy_decl);
83972 +}
83973 +
83974 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83975 +{
83976 + const char * const plugin_name = plugin_info->base_name;
83977 + struct register_pass_info latent_entropy_pass_info = {
83978 + .pass = &latent_entropy_pass.pass,
83979 + .reference_pass_name = "optimized",
83980 + .ref_pass_instance_number = 1,
83981 + .pos_op = PASS_POS_INSERT_BEFORE
83982 + };
83983 +
83984 + if (!plugin_default_version_check(version, &gcc_version)) {
83985 + error(G_("incompatible gcc/plugin versions"));
83986 + return 1;
83987 + }
83988 +
83989 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83990 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83991 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83992 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83993 +
83994 + return 0;
83995 +}
83996 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83997 new file mode 100644
83998 index 0000000..afebc99
83999 --- /dev/null
84000 +++ b/tools/gcc/size_overflow_hash.data
84001 @@ -0,0 +1,3709 @@
84002 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
84003 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
84004 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
84005 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
84006 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
84007 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
84008 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
84009 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
84010 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
84011 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
84012 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
84013 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
84014 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
84015 +create_log_8225 create_log 2 8225 NULL
84016 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
84017 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
84018 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
84019 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
84020 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
84021 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
84022 +padzero_55 padzero 1 55 &sel_read_policyvers_55
84023 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
84024 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
84025 +read_file_blob_57406 read_file_blob 3 57406 NULL
84026 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
84027 +enclosure_register_57412 enclosure_register 3 57412 NULL
84028 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
84029 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
84030 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
84031 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
84032 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
84033 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
84034 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
84035 +init_cdev_8274 init_cdev 1 8274 NULL
84036 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
84037 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
84038 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
84039 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
84040 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
84041 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
84042 +load_msg_95 load_msg 2 95 NULL
84043 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
84044 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
84045 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
84046 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
84047 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
84048 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
84049 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
84050 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
84051 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
84052 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
84053 +send_midi_async_57463 send_midi_async 3 57463 NULL
84054 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
84055 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
84056 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
84057 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
84058 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
84059 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
84060 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
84061 +init_q_132 init_q 4 132 NULL
84062 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
84063 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
84064 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
84065 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
84066 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
84067 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
84068 +uio_read_49300 uio_read 3 49300 NULL
84069 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
84070 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
84071 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
84072 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
84073 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
84074 +play_iframe_8219 play_iframe 3 8219 NULL
84075 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
84076 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
84077 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
84078 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
84079 +init_tag_map_57515 init_tag_map 3 57515 NULL
84080 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
84081 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
84082 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
84083 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
84084 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
84085 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
84086 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
84087 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
84088 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
84089 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
84090 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
84091 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
84092 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
84093 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
84094 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
84095 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
84096 +cache_read_24790 cache_read 3 24790 NULL
84097 +px_raw_event_49371 px_raw_event 4 49371 NULL
84098 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
84099 +compat_filldir_32999 compat_filldir 3 32999 NULL
84100 +hci_si_event_1404 hci_si_event 3 1404 NULL
84101 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
84102 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
84103 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
84104 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
84105 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
84106 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
84107 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
84108 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
84109 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
84110 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
84111 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
84112 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
84113 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
84114 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
84115 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
84116 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
84117 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
84118 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
84119 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
84120 +mem_read_57631 mem_read 3 57631 NULL
84121 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
84122 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
84123 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
84124 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
84125 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
84126 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
84127 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
84128 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
84129 +queues_read_24877 queues_read 3 24877 NULL
84130 +__fprog_create_41263 __fprog_create 2 41263 NULL
84131 +syslog_print_307 syslog_print 2 307 NULL
84132 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
84133 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
84134 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
84135 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
84136 +r3964_write_57662 r3964_write 4 57662 NULL
84137 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
84138 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
84139 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
84140 +alloc_context_41283 alloc_context 1 41283 NULL
84141 +__lgwrite_57669 __lgwrite 4 57669 NULL
84142 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
84143 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
84144 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
84145 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
84146 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
84147 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
84148 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
84149 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
84150 +write_node_33121 write_node 4 33121 NULL
84151 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
84152 +profile_remove_8556 profile_remove 3 8556 NULL
84153 +evm_read_key_54674 evm_read_key 3 54674 NULL
84154 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
84155 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
84156 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
84157 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
84158 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
84159 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
84160 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
84161 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
84162 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
84163 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
84164 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
84165 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
84166 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
84167 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
84168 +smk_write_access_49561 smk_write_access 3 49561 NULL
84169 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
84170 +kmp_init_41373 kmp_init 2 41373 NULL
84171 +context_alloc_24645 context_alloc 3 24645 NULL
84172 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
84173 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
84174 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
84175 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
84176 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
84177 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
84178 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
84179 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
84180 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
84181 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
84182 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
84183 +pp_read_33210 pp_read 3 33210 NULL
84184 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
84185 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
84186 +ivtv_read_57796 ivtv_read 3 57796 NULL
84187 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
84188 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
84189 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
84190 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
84191 +heap_init_49617 heap_init 2 49617 NULL
84192 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
84193 +aoechr_write_62883 aoechr_write 3 62883 NULL nohasharray
84194 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 &aoechr_write_62883
84195 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
84196 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
84197 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
84198 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
84199 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
84200 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
84201 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
84202 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
84203 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
84204 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
84205 +st_write_16874 st_write 3 16874 NULL
84206 +copy_to_user_57835 copy_to_user 3 57835 NULL
84207 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
84208 +pidlist_resize_496 pidlist_resize 2 496 NULL
84209 +flash_read_57843 flash_read 3 57843 NULL
84210 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
84211 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
84212 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
84213 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
84214 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
84215 +arcfb_write_8702 arcfb_write 3 8702 NULL
84216 +send_to_tty_45141 send_to_tty 3 45141 NULL
84217 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
84218 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
84219 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
84220 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
84221 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
84222 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
84223 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
84224 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
84225 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
84226 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
84227 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
84228 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
84229 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
84230 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
84231 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
84232 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
84233 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
84234 +vhci_read_47878 vhci_read 3 47878 NULL
84235 +devres_alloc_551 devres_alloc 2 551 NULL
84236 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
84237 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
84238 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
84239 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
84240 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
84241 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
84242 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
84243 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
84244 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
84245 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
84246 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
84247 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
84248 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
84249 +sys_prctl_8766 sys_prctl 4 8766 NULL
84250 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
84251 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
84252 +insert_one_name_61668 insert_one_name 7 61668 NULL
84253 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
84254 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
84255 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
84256 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
84257 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
84258 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
84259 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
84260 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
84261 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
84262 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
84263 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
84264 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
84265 +gserial_setup_41558 gserial_setup 2 41558 NULL
84266 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
84267 +rx_57944 rx 4 57944 NULL
84268 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
84269 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
84270 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
84271 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
84272 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
84273 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
84274 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
84275 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
84276 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
84277 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
84278 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
84279 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
84280 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
84281 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
84282 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
84283 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
84284 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
84285 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
84286 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
84287 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
84288 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
84289 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
84290 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
84291 +a2mp_send_41615 a2mp_send 4 41615 NULL
84292 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
84293 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
84294 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
84295 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
84296 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
84297 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
84298 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
84299 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
84300 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
84301 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
84302 +add_uuid_49831 add_uuid 4 49831 NULL
84303 +send_pages_8872 send_pages 3 8872 NULL
84304 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
84305 +read_file_recv_48232 read_file_recv 3 48232 NULL
84306 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
84307 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
84308 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
84309 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
84310 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
84311 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
84312 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
84313 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
84314 +vfs_writev_25278 vfs_writev 3 25278 NULL
84315 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
84316 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
84317 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
84318 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
84319 +create_entry_33479 create_entry 2 33479 NULL
84320 +mce_async_out_58056 mce_async_out 3 58056 NULL
84321 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
84322 +sys_preadv_17100 sys_preadv 3 17100 NULL
84323 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
84324 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
84325 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
84326 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
84327 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
84328 +res_counter_read_33499 res_counter_read 4 33499 NULL
84329 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
84330 +cm4040_write_58079 cm4040_write 3 58079 NULL
84331 +fb_read_33506 fb_read 3 33506 NULL
84332 +help_25316 help 5 25316 NULL nohasharray
84333 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
84334 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
84335 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
84336 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
84337 +ddp_set_map_751 ddp_set_map 4 751 NULL
84338 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
84339 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
84340 +dvb_video_write_754 dvb_video_write 3 754 NULL
84341 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
84342 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
84343 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
84344 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
84345 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
84346 +udi_log_event_58105 udi_log_event 3 58105 NULL
84347 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
84348 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
84349 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
84350 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
84351 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
84352 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
84353 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
84354 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
84355 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
84356 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
84357 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
84358 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
84359 +sep_read_17161 sep_read 3 17161 NULL
84360 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
84361 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
84362 +dup_array_33551 dup_array 3 33551 NULL
84363 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
84364 +fillonedir_41746 fillonedir 3 41746 NULL
84365 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
84366 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
84367 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
84368 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
84369 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
84370 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
84371 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
84372 +if_writecmd_815 if_writecmd 2 815 NULL
84373 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
84374 +read_fifo_826 read_fifo 3 826 NULL
84375 +scsi_execute_33596 scsi_execute 5 33596 NULL
84376 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
84377 +ms_rw_17220 ms_rw 3-4 17220 NULL
84378 +read_tree_block_841 read_tree_block 3 841 NULL
84379 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
84380 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
84381 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
84382 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
84383 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
84384 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
84385 +um_idi_read_850 um_idi_read 3 850 NULL
84386 +__module_alloc_50004 __module_alloc 1 50004 NULL
84387 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
84388 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
84389 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
84390 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
84391 +provide_user_output_41105 provide_user_output 3 41105 NULL
84392 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
84393 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
84394 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
84395 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
84396 +alloc_ep_17269 alloc_ep 1 17269 NULL
84397 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
84398 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
84399 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
84400 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
84401 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
84402 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
84403 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
84404 +create_queues_9088 create_queues 2-3 9088 NULL
84405 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
84406 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
84407 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
84408 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
84409 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
84410 +read_file_debug_58256 read_file_debug 3 58256 NULL
84411 +skb_pad_17302 skb_pad 2 17302 NULL
84412 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
84413 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
84414 +profile_load_58267 profile_load 3 58267 NULL
84415 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
84416 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
84417 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
84418 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
84419 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
84420 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
84421 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
84422 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
84423 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
84424 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
84425 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
84426 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
84427 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
84428 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
84429 +get_packet_41914 get_packet 3 41914 NULL
84430 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
84431 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
84432 +read_file_slot_50111 read_file_slot 3 50111 NULL
84433 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
84434 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
84435 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
84436 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
84437 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
84438 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
84439 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
84440 +copy_items_50140 copy_items 6 50140 NULL
84441 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
84442 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
84443 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
84444 +ts_write_64336 ts_write 3 64336 NULL
84445 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
84446 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
84447 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
84448 +portnames_read_41958 portnames_read 3 41958 NULL
84449 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
84450 +hashtab_create_33769 hashtab_create 3 33769 NULL
84451 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
84452 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
84453 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
84454 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
84455 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
84456 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
84457 +odev_update_50169 odev_update 2 50169 NULL
84458 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
84459 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
84460 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
84461 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
84462 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
84463 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
84464 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
84465 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
84466 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
84467 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
84468 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
84469 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
84470 +lguest_map_42008 lguest_map 1-2 42008 NULL
84471 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
84472 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
84473 +pool_allocate_42012 pool_allocate 3 42012 NULL
84474 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
84475 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
84476 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
84477 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
84478 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
84479 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
84480 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
84481 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
84482 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
84483 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
84484 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
84485 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
84486 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
84487 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
84488 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
84489 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
84490 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
84491 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
84492 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
84493 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
84494 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
84495 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
84496 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
84497 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
84498 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
84499 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
84500 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
84501 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
84502 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
84503 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
84504 +config_proc_write_33878 config_proc_write 3 33878 NULL
84505 +capabilities_read_58457 capabilities_read 3 58457 NULL
84506 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
84507 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
84508 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
84509 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
84510 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
84511 +dm_table_create_35687 dm_table_create 3 35687 NULL
84512 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
84513 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
84514 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
84515 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
84516 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
84517 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
84518 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
84519 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
84520 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
84521 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
84522 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
84523 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
84524 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
84525 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
84526 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
84527 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
84528 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
84529 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
84530 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
84531 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
84532 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
84533 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
84534 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
84535 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
84536 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
84537 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
84538 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
84539 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
84540 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
84541 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
84542 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
84543 +read_9397 read 3 9397 NULL
84544 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
84545 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
84546 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
84547 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
84548 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
84549 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
84550 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
84551 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
84552 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
84553 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
84554 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
84555 +osst_execute_17607 osst_execute 7-6 17607 NULL
84556 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
84557 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
84558 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
84559 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
84560 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
84561 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
84562 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
84563 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
84564 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
84565 +xip_file_read_58592 xip_file_read 3 58592 NULL
84566 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
84567 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
84568 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
84569 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
84570 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
84571 +ppp_write_34034 ppp_write 3 34034 NULL
84572 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
84573 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
84574 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
84575 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
84576 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
84577 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
84578 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
84579 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
84580 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
84581 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
84582 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
84583 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
84584 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
84585 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
84586 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
84587 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
84588 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
84589 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
84590 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
84591 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
84592 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
84593 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
84594 +lp_write_9511 lp_write 3 9511 NULL
84595 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
84596 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
84597 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
84598 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
84599 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
84600 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
84601 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
84602 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
84603 +read_file_dma_9530 read_file_dma 3 9530 NULL
84604 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
84605 +rcname_read_25919 rcname_read 3 25919 NULL
84606 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
84607 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
84608 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
84609 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
84610 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
84611 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
84612 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
84613 +key_flags_read_25931 key_flags_read 3 25931 NULL
84614 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
84615 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
84616 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
84617 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
84618 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
84619 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
84620 +fw_node_create_9559 fw_node_create 2 9559 NULL
84621 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
84622 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
84623 +kobj_map_9566 kobj_map 2-3 9566 NULL
84624 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
84625 +acpi_map_58725 acpi_map 1-2 58725 NULL
84626 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
84627 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
84628 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
84629 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
84630 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
84631 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
84632 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
84633 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
84634 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
84635 +file_read_actor_1401 file_read_actor 4 1401 NULL
84636 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
84637 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
84638 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
84639 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
84640 +do_sync_9604 do_sync 1 9604 NULL
84641 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
84642 +compat_readv_30273 compat_readv 3 30273 NULL
84643 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
84644 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
84645 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
84646 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
84647 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
84648 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
84649 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
84650 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
84651 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
84652 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
84653 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
84654 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
84655 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
84656 +sge_rx_50594 sge_rx 3 50594 NULL
84657 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
84658 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
84659 +skb_padto_50759 skb_padto 2 50759 NULL
84660 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
84661 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
84662 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
84663 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
84664 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
84665 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
84666 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
84667 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
84668 +ep_read_58813 ep_read 3 58813 NULL
84669 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
84670 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
84671 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
84672 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
84673 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
84674 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
84675 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
84676 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
84677 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
84678 +dns_query_9676 dns_query 3 9676 NULL
84679 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
84680 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
84681 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
84682 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
84683 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
84684 +command_write_58841 command_write 3 58841 NULL
84685 +dev_config_8506 dev_config 3 8506 NULL
84686 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
84687 +sys_readv_50664 sys_readv 3 50664 NULL
84688 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
84689 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
84690 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
84691 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
84692 +recover_head_17904 recover_head 3 17904 NULL
84693 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
84694 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
84695 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
84696 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
84697 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
84698 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
84699 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
84700 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
84701 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
84702 +skb_cow_26138 skb_cow 2 26138 NULL
84703 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
84704 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
84705 +do_sigpending_9766 do_sigpending 2 9766 NULL
84706 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
84707 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
84708 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
84709 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
84710 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
84711 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
84712 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
84713 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
84714 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
84715 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
84716 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
84717 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
84718 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
84719 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
84720 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
84721 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
84722 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
84723 +get_registers_26187 get_registers 3 26187 NULL
84724 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
84725 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
84726 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
84727 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
84728 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
84729 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
84730 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
84731 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
84732 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
84733 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
84734 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
84735 +mce_write_26201 mce_write 3 26201 NULL
84736 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
84737 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
84738 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
84739 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
84740 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
84741 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
84742 +tpm_write_50798 tpm_write 3 50798 NULL
84743 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
84744 +tun_do_read_50800 tun_do_read 4 50800 NULL
84745 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
84746 +write_flush_50803 write_flush 3 50803 NULL
84747 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
84748 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
84749 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
84750 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
84751 +dvb_play_50814 dvb_play 3 50814 NULL
84752 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
84753 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
84754 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
84755 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
84756 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
84757 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
84758 +dma_attach_50831 dma_attach 6-7 50831 NULL
84759 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
84760 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
84761 +packet_came_18072 packet_came 3 18072 NULL
84762 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
84763 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
84764 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
84765 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
84766 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
84767 +get_vm_area_18080 get_vm_area 1 18080 NULL
84768 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
84769 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
84770 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
84771 +self_check_write_50856 self_check_write 5 50856 NULL
84772 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
84773 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
84774 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
84775 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
84776 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
84777 +get_packet_5747 get_packet 3 5747 NULL
84778 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
84779 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
84780 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
84781 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
84782 +vb2_read_42703 vb2_read 3 42703 NULL
84783 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
84784 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
84785 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
84786 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
84787 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
84788 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
84789 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
84790 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
84791 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
84792 +alloc_buf_34532 alloc_buf 1 34532 NULL
84793 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
84794 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
84795 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
84796 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
84797 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
84798 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
84799 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
84800 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
84801 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
84802 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
84803 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
84804 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
84805 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
84806 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
84807 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
84808 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
84809 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
84810 +mld_newpack_50950 mld_newpack 2 50950 NULL
84811 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
84812 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
84813 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
84814 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
84815 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
84816 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
84817 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
84818 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
84819 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
84820 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
84821 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
84822 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
84823 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
84824 +timeout_write_50991 timeout_write 3 50991 NULL
84825 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
84826 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
84827 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
84828 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
84829 +proc_write_51003 proc_write 3 51003 NULL
84830 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
84831 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
84832 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
84833 +set_arg_42824 set_arg 3 42824 NULL
84834 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
84835 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
84836 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
84837 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
84838 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
84839 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
84840 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
84841 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
84842 +dt3155_read_59226 dt3155_read 3 59226 NULL
84843 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
84844 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
84845 +dump_midi_51040 dump_midi 3 51040 NULL
84846 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
84847 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
84848 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
84849 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
84850 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
84851 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
84852 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
84853 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
84854 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
84855 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
84856 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
84857 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
84858 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
84859 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
84860 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
84861 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
84862 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
84863 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
84864 +read_vmcore_26501 read_vmcore 3 26501 NULL
84865 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
84866 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
84867 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
84868 +alloc_skb_55439 alloc_skb 1 55439 NULL
84869 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
84870 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
84871 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
84872 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
84873 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
84874 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
84875 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
84876 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
84877 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
84878 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
84879 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
84880 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
84881 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
84882 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
84883 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
84884 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
84885 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
84886 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
84887 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
84888 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
84889 +fd_copyout_59323 fd_copyout 3 59323 NULL
84890 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
84891 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
84892 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
84893 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
84894 +solos_param_store_34755 solos_param_store 4 34755 NULL
84895 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
84896 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
84897 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
84898 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
84899 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
84900 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
84901 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
84902 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
84903 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
84904 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
84905 +set_registers_53582 set_registers 3 53582 NULL
84906 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
84907 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
84908 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
84909 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
84910 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
84911 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
84912 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
84913 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
84914 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
84915 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
84916 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
84917 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
84918 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
84919 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
84920 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
84921 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
84922 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
84923 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
84924 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
84925 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
84926 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
84927 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
84928 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
84929 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
84930 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
84931 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
84932 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
84933 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
84934 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
84935 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
84936 +tipc_send_51238 tipc_send 4 51238 NULL
84937 +drm_property_create_51239 drm_property_create 4 51239 NULL
84938 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
84939 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
84940 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
84941 +audit_expand_2098 audit_expand 2 2098 NULL
84942 +st_read_51251 st_read 3 51251 NULL
84943 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
84944 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
84945 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
84946 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
84947 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
84948 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
84949 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
84950 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
84951 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
84952 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
84953 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
84954 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
84955 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
84956 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
84957 +pkt_add_39897 pkt_add 3 39897 NULL
84958 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
84959 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
84960 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
84961 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
84962 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
84963 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
84964 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
84965 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
84966 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
84967 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
84968 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
84969 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
84970 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
84971 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
84972 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
84973 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
84974 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
84975 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
84976 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
84977 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
84978 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
84979 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
84980 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
84981 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
84982 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
84983 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
84984 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
84985 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
84986 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
84987 +debug_output_18575 debug_output 3 18575 NULL
84988 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
84989 +Realloc_34961 Realloc 2 34961 NULL
84990 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
84991 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
84992 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
84993 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
84994 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
84995 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
84996 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
84997 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
84998 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
84999 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
85000 +vhci_write_2224 vhci_write 3 2224 NULL
85001 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
85002 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
85003 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
85004 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
85005 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
85006 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
85007 +write_pbl_59583 write_pbl 4 59583 NULL
85008 +from_buffer_18625 from_buffer 3 18625 NULL
85009 +uio_write_43202 uio_write 3 43202 NULL
85010 +memdup_user_59590 memdup_user 2 59590 NULL
85011 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
85012 +iso_callback_43208 iso_callback 3 43208 NULL
85013 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
85014 +smk_write_load_26829 smk_write_load 3 26829 NULL
85015 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
85016 +do_update_counters_2259 do_update_counters 4 2259 NULL
85017 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
85018 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
85019 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
85020 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
85021 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
85022 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
85023 +mtrr_write_59622 mtrr_write 3 59622 NULL
85024 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
85025 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
85026 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
85027 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
85028 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
85029 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
85030 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
85031 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
85032 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
85033 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
85034 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
85035 +fixup_leb_43256 fixup_leb 3 43256 NULL
85036 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
85037 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
85038 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
85039 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
85040 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
85041 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
85042 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
85043 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
85044 +evtchn_write_43278 evtchn_write 3 43278 NULL
85045 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
85046 +store_ifalias_35088 store_ifalias 4 35088 NULL
85047 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
85048 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
85049 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
85050 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
85051 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
85052 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
85053 +tower_write_8580 tower_write 3 8580 NULL
85054 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
85055 +capi_write_35104 capi_write 3 35104 NULL nohasharray
85056 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
85057 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
85058 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
85059 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
85060 +dev_read_56369 dev_read 3 56369 NULL
85061 +read_file_misc_9948 read_file_misc 3 9948 NULL
85062 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
85063 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
85064 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
85065 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
85066 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
85067 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
85068 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
85069 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
85070 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
85071 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
85072 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
85073 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
85074 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
85075 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
85076 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
85077 +do_trimming_26952 do_trimming 3 26952 NULL
85078 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
85079 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
85080 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
85081 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
85082 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
85083 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
85084 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
85085 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
85086 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
85087 +otp_read_10594 otp_read 2-4-5 10594 NULL
85088 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
85089 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
85090 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
85091 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
85092 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
85093 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
85094 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
85095 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
85096 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
85097 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
85098 +venus_remove_59781 venus_remove 4 59781 NULL
85099 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
85100 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
85101 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
85102 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
85103 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
85104 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
85105 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
85106 +xenfb_write_43412 xenfb_write 3 43412 NULL
85107 +cosa_write_1774 cosa_write 3 1774 NULL
85108 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
85109 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
85110 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
85111 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
85112 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 NULL nohasharray
85113 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 &gdm_wimax_netif_rx_43423
85114 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
85115 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
85116 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
85117 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
85118 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
85119 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
85120 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
85121 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
85122 +cmd_complete_51629 cmd_complete 6 51629 NULL
85123 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
85124 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
85125 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
85126 +set_fd_set_35249 set_fd_set 1 35249 NULL
85127 +wiphy_new_2482 wiphy_new 2 2482 NULL
85128 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
85129 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
85130 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
85131 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
85132 +tcp_push_10680 tcp_push 3 10680 NULL
85133 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
85134 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
85135 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
85136 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
85137 +tun_put_user_59849 tun_put_user 4 59849 NULL
85138 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
85139 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
85140 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
85141 +dm_write_2513 dm_write 3 2513 NULL
85142 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
85143 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
85144 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
85145 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
85146 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
85147 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
85148 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
85149 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
85150 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
85151 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
85152 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
85153 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
85154 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
85155 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
85156 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
85157 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
85158 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
85159 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
85160 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
85161 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
85162 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
85163 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
85164 +sel_write_access_51704 sel_write_access 3 51704 NULL
85165 +sys_syslog_10746 sys_syslog 3 10746 NULL
85166 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
85167 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
85168 +do_readlink_43518 do_readlink 2 43518 NULL
85169 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
85170 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
85171 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
85172 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
85173 +pms_capture_27142 pms_capture 4 27142 NULL
85174 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
85175 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
85176 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
85177 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
85178 +msg_set_51725 msg_set 3 51725 NULL
85179 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
85180 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
85181 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
85182 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
85183 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
85184 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
85185 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
85186 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
85187 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
85188 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
85189 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
85190 +sys_bind_10799 sys_bind 3 10799 NULL
85191 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
85192 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
85193 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
85194 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
85195 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
85196 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
85197 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
85198 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
85199 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
85200 +send_command_10832 send_command 4 10832 NULL
85201 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
85202 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
85203 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
85204 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
85205 +proc_read_43614 proc_read 3 43614 NULL
85206 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
85207 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
85208 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
85209 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
85210 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
85211 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
85212 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
85213 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
85214 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
85215 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
85216 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
85217 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
85218 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
85219 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
85220 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
85221 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
85222 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
85223 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
85224 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
85225 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
85226 +unifi_write_65012 unifi_write 3 65012 NULL
85227 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
85228 +get_scq_10897 get_scq 2 10897 NULL
85229 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
85230 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
85231 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
85232 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
85233 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
85234 +load_module_60056 load_module 2 60056 NULL nohasharray
85235 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
85236 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
85237 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
85238 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
85239 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
85240 +nfsd_read_19568 nfsd_read 5 19568 NULL
85241 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
85242 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
85243 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
85244 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
85245 +user_read_51881 user_read 3 51881 NULL
85246 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
85247 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
85248 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
85249 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
85250 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
85251 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
85252 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
85253 +async_setkey_35521 async_setkey 3 35521 NULL
85254 +send_msg_37323 send_msg 4 37323 NULL
85255 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
85256 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
85257 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
85258 +gnttab_map_56439 gnttab_map 2 56439 NULL
85259 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
85260 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
85261 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
85262 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
85263 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
85264 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
85265 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
85266 +kcalloc_27770 kcalloc 1-2 27770 NULL
85267 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
85268 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
85269 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
85270 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
85271 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
85272 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
85273 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
85274 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
85275 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
85276 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
85277 +handle_request_10024 handle_request 9 10024 NULL
85278 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
85279 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
85280 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
85281 +init_state_60165 init_state 2 60165 NULL
85282 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
85283 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
85284 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
85285 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
85286 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
85287 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
85288 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
85289 +read_dma_55086 read_dma 3 55086 NULL
85290 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
85291 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
85292 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
85293 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
85294 +kernel_readv_35617 kernel_readv 3 35617 NULL
85295 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
85296 +reshape_ring_29147 reshape_ring 2 29147 NULL
85297 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
85298 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
85299 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
85300 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
85301 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
85302 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
85303 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
85304 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
85305 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
85306 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
85307 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
85308 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
85309 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
85310 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
85311 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
85312 +store_debug_level_35652 store_debug_level 3 35652 NULL
85313 +read_flush_43851 read_flush 3 43851 NULL
85314 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
85315 +cmm_write_2896 cmm_write 3 2896 NULL
85316 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
85317 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
85318 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
85319 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
85320 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
85321 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
85322 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
85323 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
85324 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
85325 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
85326 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
85327 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
85328 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
85329 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
85330 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
85331 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
85332 +printer_write_60276 printer_write 3 60276 NULL
85333 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
85334 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
85335 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
85336 +debug_read_19322 debug_read 3 19322 NULL
85337 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
85338 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
85339 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
85340 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
85341 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
85342 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
85343 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
85344 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
85345 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
85346 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
85347 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
85348 +SendString_43928 SendString 3 43928 NULL
85349 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
85350 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
85351 +retry_count_read_52129 retry_count_read 3 52129 NULL
85352 +trace_options_read_11419 trace_options_read 3 11419 NULL
85353 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
85354 +read_zero_19366 read_zero 3 19366 NULL
85355 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
85356 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
85357 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
85358 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
85359 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
85360 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
85361 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
85362 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
85363 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
85364 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
85365 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
85366 +depth_write_3021 depth_write 3 3021 NULL
85367 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
85368 +read_file_stations_35795 read_file_stations 3 35795 NULL
85369 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
85370 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
85371 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
85372 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
85373 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
85374 +copy_from_user_17559 copy_from_user 3 17559 NULL
85375 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
85376 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
85377 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
85378 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
85379 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
85380 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
85381 +driver_names_read_60399 driver_names_read 3 60399 NULL
85382 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
85383 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
85384 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
85385 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
85386 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
85387 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
85388 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
85389 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
85390 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
85391 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
85392 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
85393 +rx_data_60442 rx_data 4 60442 NULL
85394 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
85395 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
85396 +rb_alloc_3102 rb_alloc 1 3102 NULL
85397 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
85398 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
85399 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
85400 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
85401 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
85402 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
85403 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
85404 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
85405 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
85406 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
85407 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
85408 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
85409 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
85410 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
85411 +construct_key_11329 construct_key 3 11329 NULL
85412 +evm_write_key_27715 evm_write_key 3 27715 NULL
85413 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
85414 +xsd_read_15653 xsd_read 3 15653 NULL
85415 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
85416 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
85417 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
85418 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
85419 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
85420 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
85421 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
85422 +read_file_reset_52310 read_file_reset 3 52310 NULL
85423 +sel_write_create_11353 sel_write_create 3 11353 NULL
85424 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
85425 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
85426 +hwflags_read_52318 hwflags_read 3 52318 NULL
85427 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
85428 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
85429 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
85430 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
85431 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
85432 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
85433 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
85434 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
85435 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
85436 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
85437 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
85438 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
85439 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
85440 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
85441 +alloc_context_3194 alloc_context 1 3194 NULL
85442 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
85443 +bm_status_read_19583 bm_status_read 3 19583 NULL
85444 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
85445 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
85446 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
85447 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
85448 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
85449 +str_to_user_11411 str_to_user 2 11411 NULL
85450 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
85451 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
85452 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
85453 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
85454 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
85455 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
85456 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
85457 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
85458 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
85459 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
85460 +console_store_36007 console_store 4 36007 NULL
85461 +bttv_read_11432 bttv_read 3 11432 NULL
85462 +key_key_read_3241 key_key_read 3 3241 NULL
85463 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
85464 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
85465 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
85466 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
85467 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
85468 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
85469 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
85470 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
85471 +um_idi_write_18293 um_idi_write 3 18293 NULL
85472 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
85473 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
85474 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
85475 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
85476 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
85477 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
85478 +sys_init_module_36047 sys_init_module 2 36047 NULL
85479 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
85480 +read_profile_27859 read_profile 3 27859 NULL
85481 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
85482 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
85483 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
85484 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
85485 +refill_pool_19477 refill_pool 2 19477 NULL
85486 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
85487 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
85488 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
85489 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
85490 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
85491 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
85492 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
85493 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
85494 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
85495 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
85496 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
85497 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
85498 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
85499 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
85500 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
85501 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
85502 +alloc_async_14208 alloc_async 1 14208 NULL
85503 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
85504 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
85505 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
85506 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
85507 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
85508 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
85509 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
85510 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
85511 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
85512 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
85513 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
85514 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
85515 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
85516 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
85517 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
85518 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
85519 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
85520 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
85521 +init_data_container_60709 init_data_container 1 60709 NULL
85522 +p9_client_read_19750 p9_client_read 5 19750 NULL
85523 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
85524 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
85525 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
85526 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
85527 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
85528 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
85529 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
85530 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
85531 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
85532 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
85533 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
85534 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
85535 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
85536 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
85537 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
85538 +send_stream_3397 send_stream 4 3397 NULL
85539 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
85540 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
85541 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
85542 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
85543 +msix_map_region_3411 msix_map_region 3 3411 NULL
85544 +idmouse_read_63374 idmouse_read 3 63374 NULL
85545 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
85546 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
85547 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
85548 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
85549 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
85550 +opticon_write_60775 opticon_write 4 60775 NULL
85551 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
85552 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
85553 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
85554 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
85555 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
85556 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
85557 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
85558 +vip_read_19832 vip_read 3 19832 NULL
85559 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
85560 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
85561 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
85562 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
85563 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
85564 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
85565 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
85566 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
85567 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
85568 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
85569 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
85570 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
85571 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
85572 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
85573 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
85574 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
85575 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
85576 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
85577 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
85578 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
85579 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
85580 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
85581 +split_11691 split 2 11691 NULL
85582 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
85583 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
85584 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
85585 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
85586 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
85587 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
85588 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
85589 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
85590 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
85591 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
85592 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
85593 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
85594 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
85595 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
85596 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
85597 +dsp_write_46218 dsp_write 2 46218 NULL
85598 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
85599 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
85600 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
85601 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
85602 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
85603 +spidev_write_44510 spidev_write 3 44510 NULL
85604 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
85605 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
85606 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
85607 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
85608 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
85609 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
85610 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
85611 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
85612 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
85613 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
85614 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
85615 +evtchn_read_3569 evtchn_read 3 3569 NULL
85616 +video_read_28148 video_read 3 28148 NULL
85617 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
85618 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
85619 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
85620 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
85621 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
85622 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
85623 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
85624 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
85625 +vc_resize_3585 vc_resize 2-3 3585 NULL
85626 +sys_select_38827 sys_select 1 38827 NULL
85627 +gluebi_write_27905 gluebi_write 3 27905 NULL
85628 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
85629 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
85630 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
85631 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
85632 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
85633 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
85634 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
85635 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
85636 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
85637 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
85638 +pti_char_write_60960 pti_char_write 3 60960 NULL
85639 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
85640 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
85641 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
85642 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
85643 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
85644 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
85645 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
85646 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
85647 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
85648 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
85649 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
85650 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
85651 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
85652 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
85653 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
85654 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
85655 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
85656 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
85657 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
85658 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
85659 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
85660 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
85661 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
85662 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
85663 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
85664 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
85665 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
85666 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
85667 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
85668 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
85669 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
85670 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
85671 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
85672 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
85673 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
85674 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
85675 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
85676 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
85677 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
85678 +symtab_init_61050 symtab_init 2 61050 NULL
85679 +team_options_register_20091 team_options_register 3 20091 NULL
85680 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
85681 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
85682 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
85683 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
85684 +mpi_resize_44674 mpi_resize 2 44674 NULL
85685 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
85686 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
85687 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
85688 +interfaces_38859 interfaces 2 38859 NULL
85689 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
85690 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
85691 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
85692 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
85693 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
85694 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
85695 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
85696 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
85697 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
85698 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
85699 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
85700 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
85701 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
85702 +get_derived_key_61100 get_derived_key 4 61100 NULL
85703 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
85704 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
85705 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
85706 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
85707 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
85708 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
85709 +fs_path_add_15648 fs_path_add 3 15648 NULL
85710 +kone_send_63435 kone_send 4 63435 NULL
85711 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
85712 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
85713 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
85714 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
85715 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
85716 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
85717 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
85718 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
85719 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
85720 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
85721 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
85722 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
85723 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
85724 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
85725 +send_packet_52960 send_packet 4 52960 NULL
85726 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
85727 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
85728 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
85729 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
85730 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
85731 +put_cmsg_36589 put_cmsg 4 36589 NULL
85732 +__vmalloc_61168 __vmalloc 1 61168 NULL
85733 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
85734 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
85735 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
85736 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
85737 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
85738 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
85739 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
85740 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
85741 +p54_init_common_23850 p54_init_common 1 23850 NULL
85742 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
85743 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
85744 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
85745 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
85746 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
85747 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
85748 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
85749 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
85750 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
85751 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
85752 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
85753 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
85754 +garp_request_join_7471 garp_request_join 4 7471 NULL
85755 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
85756 +unlink_queued_645 unlink_queued 3-4 645 NULL
85757 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
85758 +sisusb_write_44834 sisusb_write 3 44834 NULL
85759 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
85760 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
85761 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
85762 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
85763 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
85764 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
85765 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
85766 +nvram_write_3894 nvram_write 3 3894 NULL
85767 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
85768 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
85769 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
85770 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
85771 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
85772 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
85773 +vcs_write_3910 vcs_write 3 3910 NULL
85774 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
85775 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
85776 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
85777 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
85778 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
85779 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
85780 +do_tty_write_44896 do_tty_write 5 44896 NULL
85781 +set_powered_12129 set_powered 4 12129 NULL
85782 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
85783 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
85784 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
85785 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
85786 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
85787 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
85788 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
85789 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
85790 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
85791 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
85792 +udf_readpages_38761 udf_readpages 4 38761 NULL
85793 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
85794 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
85795 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
85796 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
85797 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
85798 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
85799 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
85800 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
85801 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
85802 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
85803 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
85804 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
85805 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
85806 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
85807 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
85808 +do_add_counters_3992 do_add_counters 3 3992 NULL
85809 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
85810 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
85811 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
85812 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
85813 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
85814 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
85815 +mei_write_4005 mei_write 3 4005 NULL
85816 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
85817 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
85818 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
85819 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
85820 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
85821 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
85822 +receive_copy_12216 receive_copy 3 12216 NULL
85823 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
85824 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
85825 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
85826 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
85827 +change_xattr_61390 change_xattr 5 61390 NULL
85828 +find_skb_20431 find_skb 2 20431 NULL
85829 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
85830 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
85831 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
85832 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
85833 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
85834 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
85835 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
85836 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
85837 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
85838 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
85839 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
85840 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
85841 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
85842 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
85843 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
85844 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
85845 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
85846 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
85847 +cm_write_36858 cm_write 3 36858 NULL
85848 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
85849 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
85850 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
85851 +sel_write_user_45060 sel_write_user 3 45060 NULL
85852 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
85853 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
85854 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
85855 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
85856 +fast_user_write_20494 fast_user_write 5 20494 NULL
85857 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
85858 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
85859 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
85860 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
85861 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
85862 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
85863 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
85864 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
85865 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
85866 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
85867 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
85868 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
85869 +tm6000_read_4151 tm6000_read 3 4151 NULL
85870 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
85871 +usbdev_read_45114 usbdev_read 3 45114 NULL
85872 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
85873 +spi_execute_28736 spi_execute 5 28736 NULL
85874 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
85875 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
85876 +get_alua_req_4166 get_alua_req 3 4166 NULL
85877 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
85878 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
85879 +venus_create_20555 venus_create 4 20555 NULL
85880 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
85881 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
85882 +receive_packet_12367 receive_packet 2 12367 NULL
85883 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
85884 +mem_write_22232 mem_write 3 22232 NULL
85885 +read_file_bool_4180 read_file_bool 3 4180 NULL
85886 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
85887 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
85888 +write_leb_36957 write_leb 5 36957 NULL
85889 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
85890 +device_write_45156 device_write 3 45156 NULL
85891 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
85892 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
85893 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
85894 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
85895 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
85896 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
85897 +isp1760_register_628 isp1760_register 1-2 628 NULL
85898 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
85899 +lirc_write_20604 lirc_write 3 20604 NULL
85900 +sel_write_member_28800 sel_write_member 3 28800 NULL
85901 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
85902 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
85903 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
85904 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
85905 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
85906 +setxattr_37006 setxattr 4 37006 NULL
85907 +add_child_45201 add_child 4 45201 NULL
85908 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
85909 +seq_open_private_61589 seq_open_private 3 61589 NULL
85910 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
85911 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
85912 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
85913 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
85914 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
85915 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
85916 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
85917 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
85918 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
85919 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
85920 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
85921 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
85922 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
85923 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
85924 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
85925 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
85926 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
85927 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
85928 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
85929 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
85930 +resize_stripes_61650 resize_stripes 2 61650 NULL
85931 +n2_run_53459 n2_run 3 53459 NULL
85932 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
85933 +parse_command_37079 parse_command 2 37079 NULL
85934 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
85935 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
85936 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
85937 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
85938 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
85939 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
85940 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
85941 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
85942 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
85943 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
85944 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
85945 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
85946 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
85947 +lock_loop_61681 lock_loop 1 61681 NULL
85948 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
85949 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
85950 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
85951 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
85952 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
85953 +push_rx_28939 push_rx 3 28939 NULL
85954 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
85955 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
85956 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
85957 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
85958 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
85959 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
85960 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
85961 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
85962 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
85963 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
85964 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
85965 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
85966 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
85967 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
85968 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
85969 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
85970 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
85971 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
85972 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
85973 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
85974 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
85975 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
85976 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
85977 +bin_uuid_28999 bin_uuid 3 28999 NULL
85978 +sys_sendto_20809 sys_sendto 6 20809 NULL
85979 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
85980 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
85981 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
85982 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
85983 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
85984 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
85985 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
85986 +keymap_store_45406 keymap_store 4 45406 NULL
85987 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
85988 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
85989 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
85990 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
85991 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
85992 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
85993 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
85994 +__do_replace_37227 __do_replace 5 37227 NULL
85995 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
85996 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
85997 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
85998 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
85999 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
86000 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
86001 +tso_fragment_29050 tso_fragment 3 29050 NULL
86002 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
86003 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
86004 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
86005 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
86006 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
86007 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
86008 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
86009 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
86010 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
86011 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
86012 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
86013 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
86014 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
86015 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
86016 +set_link_security_4502 set_link_security 4 4502 NULL
86017 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
86018 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
86019 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
86020 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
86021 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
86022 +c101_run_37279 c101_run 2 37279 NULL
86023 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
86024 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
86025 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
86026 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
86027 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
86028 +ivtv_write_12721 ivtv_write 3 12721 NULL
86029 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
86030 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
86031 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
86032 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
86033 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
86034 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
86035 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
86036 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
86037 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
86038 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
86039 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
86040 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
86041 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
86042 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
86043 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
86044 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
86045 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
86046 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
86047 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
86048 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
86049 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
86050 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
86051 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
86052 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
86053 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
86054 +copy_macs_45534 copy_macs 4 45534 NULL
86055 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
86056 +listxattr_12769 listxattr 3 12769 NULL
86057 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
86058 +wdm_write_53735 wdm_write 3 53735 NULL
86059 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
86060 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
86061 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
86062 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
86063 +bch_alloc_4593 bch_alloc 1 4593 NULL
86064 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
86065 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
86066 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
86067 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
86068 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
86069 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
86070 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
86071 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
86072 +mgmt_event_12810 mgmt_event 4 12810 NULL
86073 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
86074 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
86075 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
86076 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
86077 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
86078 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
86079 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
86080 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
86081 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
86082 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
86083 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86084 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
86085 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
86086 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
86087 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
86088 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
86089 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
86090 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
86091 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
86092 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
86093 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
86094 +recover_peb_29238 recover_peb 6-7 29238 NULL
86095 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
86096 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
86097 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
86098 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
86099 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
86100 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
86101 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
86102 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86103 +kone_receive_4690 kone_receive 4 4690 NULL
86104 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
86105 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
86106 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
86107 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
86108 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
86109 +savemem_58129 savemem 3 58129 NULL
86110 +do_pselect_62061 do_pselect 1 62061 NULL
86111 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
86112 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
86113 +pms_read_53873 pms_read 3 53873 NULL
86114 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
86115 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
86116 +groups_alloc_7614 groups_alloc 1 7614 NULL
86117 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
86118 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
86119 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
86120 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
86121 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
86122 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
86123 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
86124 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
86125 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
86126 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
86127 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
86128 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
86129 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
86130 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
86131 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
86132 +new_skb_21148 new_skb 1 21148 NULL
86133 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
86134 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
86135 +bm_status_write_12964 bm_status_write 3 12964 NULL
86136 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
86137 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
86138 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
86139 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
86140 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
86141 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
86142 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
86143 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
86144 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
86145 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
86146 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
86147 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
86148 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
86149 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
86150 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
86151 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
86152 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
86153 +video_usercopy_62151 video_usercopy 2 62151 NULL
86154 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
86155 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
86156 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
86157 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
86158 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
86159 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
86160 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
86161 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
86162 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
86163 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
86164 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
86165 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
86166 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
86167 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
86168 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
86169 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
86170 +input_ff_create_21240 input_ff_create 2 21240 NULL
86171 +mempool_create_29437 mempool_create 1 29437 NULL
86172 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
86173 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
86174 +amthi_read_45831 amthi_read 4 45831 NULL
86175 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
86176 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
86177 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
86178 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
86179 +sys_ipc_4889 sys_ipc 3 4889 NULL
86180 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
86181 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86182 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86183 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
86184 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
86185 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
86186 +do_register_entry_29478 do_register_entry 4 29478 NULL
86187 +isdn_write_45863 isdn_write 3 45863 NULL
86188 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
86189 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
86190 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
86191 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
86192 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
86193 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
86194 +_malloc_54077 _malloc 1 54077 NULL
86195 +add_res_range_21310 add_res_range 4 21310 NULL
86196 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
86197 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
86198 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
86199 +vb2_write_31948 vb2_write 3 31948 NULL
86200 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
86201 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
86202 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
86203 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
86204 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
86205 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
86206 +create_xattr_54106 create_xattr 5 54106 NULL
86207 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
86208 +ep_write_59008 ep_write 3 59008 NULL
86209 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
86210 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
86211 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
86212 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
86213 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
86214 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
86215 +alloc_mr_45935 alloc_mr 1 45935 NULL
86216 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
86217 +isku_receive_54130 isku_receive 4 54130 NULL
86218 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
86219 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
86220 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
86221 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
86222 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
86223 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
86224 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
86225 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
86226 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
86227 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
86228 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
86229 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
86230 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
86231 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
86232 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
86233 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
86234 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
86235 +comedi_read_13199 comedi_read 3 13199 NULL
86236 +flash_write_62354 flash_write 3 62354 NULL
86237 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
86238 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
86239 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
86240 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
86241 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
86242 +proc_file_read_53905 proc_file_read 3 53905 NULL
86243 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
86244 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
86245 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
86246 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
86247 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
86248 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
86249 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
86250 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
86251 +cru_detect_11272 cru_detect 1 11272 NULL
86252 +altera_irscan_62396 altera_irscan 2 62396 NULL
86253 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
86254 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
86255 +fw_download_code_13249 fw_download_code 3 13249 NULL
86256 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
86257 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
86258 +set_ssp_62411 set_ssp 4 62411 NULL
86259 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
86260 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
86261 +get_free_entries_46030 get_free_entries 1 46030 NULL
86262 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
86263 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
86264 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
86265 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
86266 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
86267 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
86268 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
86269 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
86270 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
86271 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
86272 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
86273 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
86274 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
86275 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
86276 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
86277 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
86278 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
86279 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
86280 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
86281 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
86282 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
86283 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
86284 +tunables_write_59563 tunables_write 3 59563 NULL
86285 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
86286 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
86287 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
86288 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
86289 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
86290 +probes_write_29711 probes_write 3 29711 NULL
86291 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
86292 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
86293 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
86294 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86295 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
86296 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
86297 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
86298 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
86299 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
86300 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
86301 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
86302 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
86303 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
86304 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
86305 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
86306 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
86307 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
86308 +event_filter_write_56609 event_filter_write 3 56609 NULL
86309 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
86310 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
86311 +insert_dent_65034 insert_dent 7 65034 NULL
86312 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
86313 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
86314 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
86315 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
86316 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
86317 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
86318 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
86319 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
86320 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
86321 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
86322 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
86323 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
86324 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
86325 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
86326 +isdn_read_50021 isdn_read 3 50021 NULL
86327 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
86328 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
86329 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
86330 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
86331 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
86332 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
86333 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
86334 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
86335 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
86336 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
86337 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
86338 +get_subdir_62581 get_subdir 3 62581 NULL
86339 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
86340 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
86341 +vfs_readv_38011 vfs_readv 3 38011 NULL
86342 +keyring_read_13438 keyring_read 3 13438 NULL
86343 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
86344 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
86345 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
86346 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
86347 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
86348 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
86349 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
86350 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
86351 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
86352 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
86353 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
86354 +ftrace_write_29551 ftrace_write 3 29551 NULL
86355 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
86356 +port_show_regs_5904 port_show_regs 3 5904 NULL
86357 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
86358 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
86359 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
86360 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
86361 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
86362 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
86363 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
86364 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
86365 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
86366 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
86367 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
86368 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
86369 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
86370 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
86371 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
86372 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
86373 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
86374 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
86375 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
86376 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
86377 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
86378 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
86379 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
86380 +bm_init_13529 bm_init 2 13529 NULL
86381 +check586_29914 check586 2 29914 NULL
86382 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
86383 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
86384 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
86385 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
86386 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
86387 +pg_read_17276 pg_read 3 17276 NULL
86388 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
86389 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
86390 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
86391 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
86392 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
86393 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
86394 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
86395 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
86396 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
86397 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
86398 +l2down_create_21755 l2down_create 4 21755 NULL
86399 +alloc_tio_13564 alloc_tio 3 13564 NULL
86400 +viacam_read_54526 viacam_read 3 54526 NULL
86401 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
86402 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
86403 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
86404 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
86405 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
86406 +setsockopt_54539 setsockopt 5 54539 NULL
86407 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
86408 +bio_alloc_32095 bio_alloc 2 32095 NULL
86409 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
86410 +tty_register_device_4544 tty_register_device 2 4544 NULL
86411 +cache_write_13589 cache_write 3 13589 NULL
86412 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
86413 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
86414 +key_replays_read_62746 key_replays_read 3 62746 NULL
86415 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
86416 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
86417 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
86418 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
86419 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
86420 +cdev_add_38176 cdev_add 2-3 38176 NULL
86421 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
86422 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
86423 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
86424 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
86425 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
86426 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
86427 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
86428 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
86429 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
86430 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
86431 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
86432 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
86433 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
86434 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
86435 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
86436 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
86437 +packet_snd_13634 packet_snd 3 13634 NULL
86438 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
86439 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
86440 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
86441 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
86442 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
86443 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
86444 +drp_wmove_30043 drp_wmove 4 30043 NULL
86445 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
86446 +cache_downcall_13666 cache_downcall 3 13666 NULL
86447 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
86448 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86449 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
86450 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
86451 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
86452 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
86453 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
86454 +tty_write_5494 tty_write 3 5494 NULL
86455 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
86456 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
86457 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
86458 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
86459 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
86460 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
86461 +filldir64_46469 filldir64 3 46469 NULL
86462 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
86463 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
86464 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
86465 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
86466 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
86467 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
86468 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
86469 +spidev_message_5518 spidev_message 3 5518 NULL
86470 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
86471 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
86472 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86473 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86474 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
86475 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
86476 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
86477 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86478 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
86479 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
86480 +u32_array_read_2219 u32_array_read 3 2219 NULL
86481 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
86482 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
86483 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
86484 +kmsg_read_46514 kmsg_read 3 46514 NULL
86485 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86486 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
86487 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
86488 +recv_stream_30138 recv_stream 4 30138 NULL
86489 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86490 +getdqbuf_62908 getdqbuf 1 62908 NULL
86491 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
86492 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
86493 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
86494 +fir16_create_5574 fir16_create 3 5574 NULL
86495 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
86496 +pt_write_40159 pt_write 3 40159 NULL
86497 +bioset_create_5580 bioset_create 1 5580 NULL
86498 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
86499 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
86500 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
86501 +kzalloc_54740 kzalloc 1 54740 NULL
86502 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
86503 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
86504 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
86505 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
86506 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
86507 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
86508 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
86509 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
86510 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
86511 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
86512 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
86513 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
86514 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86515 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
86516 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
86517 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
86518 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86519 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
86520 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
86521 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
86522 +ti_recv_22027 ti_recv 4 22027 NULL
86523 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
86524 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
86525 +nfsd_write_54809 nfsd_write 6 54809 NULL
86526 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
86527 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
86528 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
86529 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
86530 +get_skb_63008 get_skb 2 63008 NULL
86531 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
86532 +netlink_send_38434 netlink_send 5 38434 NULL
86533 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
86534 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
86535 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
86536 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
86537 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
86538 +write_rio_54837 write_rio 3 54837 NULL
86539 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
86540 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
86541 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
86542 +get_arg_5694 get_arg 3 5694 NULL
86543 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86544 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
86545 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86546 +printer_read_54851 printer_read 3 54851 NULL
86547 +mem_rw_22085 mem_rw 3 22085 NULL
86548 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
86549 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
86550 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
86551 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
86552 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
86553 +unlink1_63059 unlink1 3 63059 NULL
86554 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
86555 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
86556 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
86557 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
86558 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
86559 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
86560 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
86561 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
86562 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
86563 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
86564 +dev_names_read_38509 dev_names_read 3 38509 NULL
86565 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
86566 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
86567 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
86568 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
86569 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
86570 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
86571 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
86572 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
86573 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
86574 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
86575 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
86576 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
86577 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
86578 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
86579 +resource_from_user_30341 resource_from_user 3 30341 NULL
86580 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
86581 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
86582 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
86583 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
86584 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
86585 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
86586 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
86587 +com90xx_found_13974 com90xx_found 3 13974 NULL
86588 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
86589 +qcam_read_13977 qcam_read 3 13977 NULL
86590 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
86591 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
86592 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
86593 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
86594 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
86595 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
86596 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
86597 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
86598 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
86599 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
86600 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
86601 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
86602 +l2up_create_6430 l2up_create 3 6430 NULL
86603 +c4_add_card_54968 c4_add_card 3 54968 NULL
86604 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
86605 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
86606 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
86607 +concat_writev_21451 concat_writev 3 21451 NULL
86608 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
86609 +_queue_data_54983 _queue_data 4 54983 NULL
86610 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
86611 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
86612 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
86613 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
86614 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
86615 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
86616 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
86617 +setup_req_5848 setup_req 3 5848 NULL
86618 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
86619 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
86620 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
86621 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
86622 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
86623 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
86624 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
86625 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
86626 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
86627 +cma_create_area_38642 cma_create_area 2 38642 NULL
86628 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
86629 +sriov_enable_59689 sriov_enable 2 59689 NULL
86630 +enable_write_30456 enable_write 3 30456 NULL
86631 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
86632 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
86633 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
86634 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
86635 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
86636 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
86637 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
86638 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
86639 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
86640 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
86641 +ptp_read_63251 ptp_read 4 63251 NULL
86642 +adu_write_30487 adu_write 3 30487 NULL
86643 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
86644 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
86645 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
86646 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
86647 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
86648 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
86649 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
86650 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
86651 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
86652 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
86653 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
86654 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
86655 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
86656 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
86657 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
86658 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
86659 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
86660 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
86661 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
86662 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
86663 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
86664 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
86665 +em_canid_change_14150 em_canid_change 3 14150 NULL
86666 +raid5_resize_63306 raid5_resize 2 63306 NULL
86667 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
86668 +fb_write_46924 fb_write 3 46924 NULL
86669 +ts_read_44687 ts_read 3 44687 NULL
86670 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
86671 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
86672 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
86673 +filldir_55137 filldir 3 55137 NULL
86674 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
86675 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
86676 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86677 +reada_add_block_54247 reada_add_block 2 54247 NULL
86678 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
86679 +proc_info_read_63344 proc_info_read 3 63344 NULL
86680 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
86681 +pep_indicate_38611 pep_indicate 5 38611 NULL
86682 +set_le_30581 set_le 4 30581 NULL
86683 +write_62671 write 3 62671 NULL
86684 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
86685 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
86686 +alloc_private_22399 alloc_private 2 22399 NULL
86687 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
86688 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
86689 +zoran_write_22404 zoran_write 3 22404 NULL
86690 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
86691 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
86692 +queue_reply_22416 queue_reply 3 22416 NULL
86693 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
86694 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
86695 +sound_write_5102 sound_write 3 5102 NULL
86696 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
86697 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
86698 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
86699 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
86700 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
86701 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
86702 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
86703 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
86704 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
86705 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
86706 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
86707 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
86708 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
86709 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
86710 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
86711 +direct_entry_38836 direct_entry 3 38836 NULL
86712 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
86713 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
86714 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
86715 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
86716 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
86717 +write_head_30481 write_head 4 30481 NULL
86718 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
86719 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
86720 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
86721 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
86722 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
86723 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
86724 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
86725 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
86726 +agp_remap_30665 agp_remap 2 30665 NULL
86727 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
86728 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
86729 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
86730 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
86731 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
86732 +qc_capture_19298 qc_capture 3 19298 NULL
86733 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
86734 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
86735 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
86736 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
86737 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
86738 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
86739 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
86740 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
86741 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
86742 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
86743 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
86744 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
86745 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
86746 +read_kcore_63488 read_kcore 3 63488 NULL
86747 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
86748 +sel_write_load_63830 sel_write_load 3 63830 NULL
86749 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
86750 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
86751 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
86752 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
86753 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
86754 +mousedev_read_47123 mousedev_read 3 47123 NULL
86755 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
86756 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
86757 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
86758 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
86759 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
86760 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
86761 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
86762 +vme_user_read_55338 vme_user_read 3 55338 NULL
86763 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
86764 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
86765 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
86766 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
86767 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
86768 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
86769 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
86770 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
86771 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
86772 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
86773 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
86774 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
86775 +snapshot_read_22601 snapshot_read 3 22601 NULL
86776 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
86777 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
86778 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
86779 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
86780 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
86781 +__send_to_port_55383 __send_to_port 3 55383 NULL
86782 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
86783 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
86784 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
86785 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
86786 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
86787 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
86788 +get_nodes_39012 get_nodes 3 39012 NULL
86789 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
86790 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
86791 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
86792 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
86793 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
86794 +create_subvol_30836 create_subvol 4 30836 NULL
86795 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
86796 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
86797 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
86798 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
86799 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
86800 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
86801 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
86802 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
86803 +options_write_47243 options_write 3 47243 NULL
86804 +module_alloc_63630 module_alloc 1 63630 NULL
86805 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
86806 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
86807 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
86808 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
86809 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
86810 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
86811 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
86812 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
86813 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
86814 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
86815 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
86816 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
86817 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
86818 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
86819 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
86820 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
86821 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
86822 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
86823 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
86824 +vbi_read_63673 vbi_read 3 63673 NULL
86825 +tun_get_user_39099 tun_get_user 4 39099 NULL
86826 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
86827 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
86828 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
86829 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
86830 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
86831 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
86832 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
86833 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 NULL nohasharray
86834 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
86835 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
86836 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
86837 +ax25_output_22736 ax25_output 2 22736 NULL
86838 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
86839 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
86840 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
86841 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
86842 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
86843 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
86844 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
86845 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
86846 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
86847 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
86848 +hid_input_report_32458 hid_input_report 4 32458 NULL
86849 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
86850 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
86851 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
86852 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
86853 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
86854 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
86855 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
86856 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
86857 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
86858 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
86859 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
86860 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
86861 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
86862 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
86863 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
86864 +setkey_14987 setkey 3 14987 NULL
86865 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
86866 +init_list_set_39188 init_list_set 2-3 39188 NULL
86867 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
86868 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
86869 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
86870 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
86871 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
86872 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
86873 +add_partition_55588 add_partition 2 55588 NULL
86874 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
86875 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
86876 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
86877 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
86878 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
86879 +profile_replace_14652 profile_replace 3 14652 NULL
86880 +vzalloc_47421 vzalloc 1 47421 NULL
86881 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
86882 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
86883 +sys_writev_28384 sys_writev 3 28384 NULL
86884 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
86885 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
86886 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
86887 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
86888 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
86889 +create_attr_set_22861 create_attr_set 1 22861 NULL
86890 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
86891 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
86892 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
86893 +__skb_cow_39254 __skb_cow 2 39254 NULL
86894 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
86895 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
86896 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
86897 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
86898 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
86899 +probe_bios_17467 probe_bios 1 17467 NULL
86900 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
86901 +read_oldmem_55658 read_oldmem 3 55658 NULL
86902 +mei_read_6507 mei_read 3 6507 NULL
86903 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
86904 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
86905 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
86906 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
86907 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
86908 +SetArea_50835 SetArea 4 50835 NULL
86909 +tpm_read_50344 tpm_read 3 50344 NULL
86910 +newpart_47485 newpart 6 47485 NULL
86911 +get_info_55681 get_info 3 55681 NULL
86912 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
86913 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
86914 +core_sys_select_47494 core_sys_select 1 47494 NULL
86915 +depth_read_31112 depth_read 3 31112 NULL
86916 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
86917 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
86918 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
86919 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
86920 +unlink_simple_47506 unlink_simple 3 47506 NULL
86921 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
86922 +wdm_read_6549 wdm_read 3 6549 NULL
86923 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
86924 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
86925 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
86926 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
86927 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
86928 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
86929 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
86930 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
86931 +filter_read_61692 filter_read 3 61692 NULL
86932 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
86933 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
86934 +debugfs_read_62535 debugfs_read 3 62535 NULL
86935 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
86936 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
86937 +divas_write_63901 divas_write 3 63901 NULL
86938 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
86939 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
86940 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
86941 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
86942 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
86943 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
86944 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
86945 +ipw_write_59807 ipw_write 3 59807 NULL
86946 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
86947 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
86948 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
86949 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
86950 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
86951 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
86952 +cycx_setup_47562 cycx_setup 4 47562 NULL
86953 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
86954 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
86955 +set_local_name_55757 set_local_name 4 55757 NULL
86956 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
86957 +read_ldt_47570 read_ldt 2 47570 NULL
86958 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
86959 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
86960 +pci_iomap_47575 pci_iomap 3 47575 NULL
86961 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
86962 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
86963 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
86964 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
86965 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
86966 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
86967 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
86968 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
86969 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
86970 +conf_read_55786 conf_read 3 55786 NULL
86971 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
86972 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
86973 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
86974 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
86975 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
86976 +user_power_read_39414 user_power_read 3 39414 NULL
86977 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
86978 +uea_request_47613 uea_request 4 47613 NULL
86979 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
86980 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
86981 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
86982 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
86983 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
86984 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
86985 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
86986 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
86987 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
86988 +kmemdup_64015 kmemdup 2 64015 NULL
86989 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
86990 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
86991 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
86992 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
86993 +oz_events_read_47535 oz_events_read 3 47535 NULL
86994 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
86995 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
86996 +sys_semop_39457 sys_semop 3 39457 NULL
86997 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
86998 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
86999 +update_pmkid_2481 update_pmkid 4 2481 NULL
87000 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
87001 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
87002 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
87003 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
87004 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
87005 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
87006 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
87007 +mpeg_read_6708 mpeg_read 3 6708 NULL
87008 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
87009 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
87010 +sky2_receive_13407 sky2_receive 2 13407 NULL
87011 +krealloc_14908 krealloc 2 14908 NULL
87012 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
87013 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
87014 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
87015 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
87016 +video_proc_write_6724 video_proc_write 3 6724 NULL
87017 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
87018 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
87019 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
87020 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
87021 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
87022 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
87023 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
87024 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
87025 +command_file_write_31318 command_file_write 3 31318 NULL
87026 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
87027 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
87028 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
87029 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
87030 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
87031 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
87032 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
87033 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
87034 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
87035 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87036 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
87037 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
87038 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
87039 +int_proc_write_39542 int_proc_write 3 39542 NULL
87040 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
87041 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
87042 +read_file_ani_23161 read_file_ani 3 23161 NULL
87043 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
87044 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
87045 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
87046 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
87047 +init_bch_64130 init_bch 1-2 64130 NULL
87048 +ioremap_23172 ioremap 1-2 23172 NULL
87049 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
87050 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
87051 +usblp_write_23178 usblp_write 3 23178 NULL
87052 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
87053 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
87054 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
87055 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
87056 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
87057 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
87058 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
87059 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
87060 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
87061 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
87062 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
87063 +get_fd_set_3866 get_fd_set 1 3866 NULL
87064 +__team_options_register_63941 __team_options_register 3 63941 NULL
87065 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
87066 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
87067 +rvmalloc_46873 rvmalloc 1 46873 NULL
87068 +vmap_15025 vmap 2 15025 NULL
87069 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
87070 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
87071 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
87072 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87073 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
87074 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
87075 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
87076 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
87077 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
87078 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
87079 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
87080 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
87081 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
87082 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
87083 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
87084 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
87085 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
87086 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
87087 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 NULL nohasharray
87088 +set_dev_class_39645 set_dev_class 4 39645 &dm_exception_table_init_39645
87089 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
87090 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
87091 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87092 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
87093 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
87094 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
87095 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
87096 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
87097 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
87098 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
87099 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
87100 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
87101 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
87102 +doc_probe_23285 doc_probe 1 23285 NULL
87103 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
87104 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
87105 +alg_setkey_31485 alg_setkey 3 31485 NULL
87106 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
87107 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
87108 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
87109 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
87110 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
87111 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
87112 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
87113 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
87114 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
87115 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
87116 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
87117 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
87118 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
87119 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
87120 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
87121 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
87122 +timeout_read_47915 timeout_read 3 47915 NULL
87123 +hidraw_write_31536 hidraw_write 3 31536 NULL
87124 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
87125 +page_readlink_23346 page_readlink 3 23346 NULL
87126 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
87127 +comedi_write_47926 comedi_write 3 47926 NULL
87128 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
87129 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
87130 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
87131 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
87132 +usbvision_read_31555 usbvision_read 3 31555 NULL
87133 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
87134 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
87135 +request_key_async_6990 request_key_async 4 6990 NULL
87136 +map_addr_56144 map_addr 7 56144 NULL
87137 +handle_response_55951 handle_response 5 55951 NULL
87138 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
87139 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87140 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
87141 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
87142 +osst_write_31581 osst_write 3 31581 NULL
87143 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
87144 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
87145 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
87146 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
87147 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
87148 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
87149 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
87150 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
87151 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
87152 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
87153 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
87154 +ilo_write_64378 ilo_write 3 64378 NULL
87155 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
87156 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
87157 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
87158 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
87159 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
87160 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
87161 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
87162 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
87163 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
87164 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
87165 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
87166 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
87167 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
87168 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
87169 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
87170 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
87171 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
87172 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
87173 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
87174 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
87175 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
87176 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
87177 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
87178 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
87179 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
87180 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
87181 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
87182 +__lgread_31668 __lgread 4 31668 NULL
87183 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
87184 +fd_copyin_56247 fd_copyin 3 56247 NULL
87185 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
87186 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
87187 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
87188 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
87189 +teiup_create_43201 teiup_create 3 43201 NULL
87190 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
87191 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
87192 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
87193 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
87194 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
87195 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
87196 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
87197 +event_filter_read_23494 event_filter_read 3 23494 NULL
87198 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
87199 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
87200 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
87201 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
87202 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
87203 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87204 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87205 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
87206 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
87207 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
87208 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
87209 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
87210 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
87211 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
87212 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
87213 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
87214 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
87215 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87216 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87217 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87218 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87219 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
87220 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
87221 +remove_uuid_64505 remove_uuid 4 64505 NULL
87222 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
87223 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
87224 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
87225 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
87226 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
87227 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
87228 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
87229 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
87230 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
87231 +set_discoverable_48141 set_discoverable 4 48141 NULL
87232 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
87233 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
87234 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
87235 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
87236 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87237 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
87238 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
87239 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
87240 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
87241 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
87242 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
87243 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
87244 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
87245 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
87246 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
87247 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
87248 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
87249 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
87250 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
87251 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
87252 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
87253 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
87254 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
87255 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
87256 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
87257 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
87258 +init_ipath_48187 init_ipath 1 48187 NULL
87259 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
87260 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
87261 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
87262 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
87263 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
87264 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
87265 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
87266 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
87267 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
87268 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
87269 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
87270 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
87271 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
87272 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
87273 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
87274 +use_pool_64607 use_pool 2 64607 NULL
87275 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
87276 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
87277 +store_msg_56417 store_msg 3 56417 NULL
87278 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87279 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
87280 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
87281 +vmalloc_15464 vmalloc 1 15464 NULL
87282 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
87283 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
87284 +fanotify_write_64623 fanotify_write 3 64623 NULL
87285 +sys_add_key_61288 sys_add_key 4 61288 NULL
87286 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
87287 +fl_create_56435 fl_create 5 56435 NULL
87288 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87289 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87290 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
87291 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
87292 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
87293 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
87294 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
87295 +set_connectable_56458 set_connectable 4 56458 NULL
87296 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
87297 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
87298 +add_port_54941 add_port 2 54941 NULL
87299 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
87300 +cx18_read_23699 cx18_read 3 23699 NULL
87301 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
87302 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
87303 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
87304 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
87305 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
87306 +send_set_info_48288 send_set_info 7 48288 NULL
87307 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
87308 +sg_read_25799 sg_read 3 25799 NULL
87309 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
87310 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
87311 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
87312 +new_dir_31919 new_dir 3 31919 NULL
87313 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
87314 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
87315 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
87316 +mgmt_control_7349 mgmt_control 3 7349 NULL
87317 +hash_setkey_48310 hash_setkey 3 48310 NULL
87318 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
87319 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
87320 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
87321 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
87322 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
87323 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
87324 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
87325 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
87326 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
87327 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87328 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
87329 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
87330 +smk_user_access_24440 smk_user_access 3 24440 NULL
87331 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
87332 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87333 +ip_options_get_56538 ip_options_get 4 56538 NULL
87334 +ep0_read_38095 ep0_read 3 38095 NULL
87335 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
87336 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
87337 +vme_user_write_15587 vme_user_write 3 15587 NULL
87338 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
87339 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
87340 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
87341 +skb_add_data_48363 skb_add_data 3 48363 NULL
87342 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
87343 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87344 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
87345 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87346 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
87347 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
87348 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
87349 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
87350 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
87351 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
87352 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
87353 +calc_hmac_32010 calc_hmac 3 32010 NULL
87354 +system_enable_read_25815 system_enable_read 3 25815 NULL
87355 +allocate_probes_40204 allocate_probes 1 40204 NULL
87356 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
87357 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
87358 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
87359 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
87360 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
87361 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
87362 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
87363 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
87364 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
87365 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
87366 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
87367 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
87368 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
87369 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
87370 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
87371 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
87372 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
87373 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87374 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
87375 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
87376 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
87377 +osst_read_40237 osst_read 3 40237 NULL
87378 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
87379 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
87380 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
87381 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
87382 +unifi_read_14899 unifi_read 3 14899 NULL
87383 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
87384 +dm_read_15674 dm_read 3 15674 NULL
87385 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
87386 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
87387 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
87388 +gather_array_56641 gather_array 3 56641 NULL
87389 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
87390 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
87391 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
87392 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
87393 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
87394 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
87395 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
87396 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
87397 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
87398 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
87399 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
87400 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
87401 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
87402 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
87403 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
87404 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
87405 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
87406 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
87407 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
87408 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
87409 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
87410 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
87411 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
87412 +send_control_msg_48498 send_control_msg 6 48498 NULL
87413 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
87414 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
87415 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
87416 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
87417 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
87418 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
87419 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
87420 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
87421 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
87422 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
87423 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
87424 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
87425 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
87426 +alloc_tx_32143 alloc_tx 2 32143 NULL
87427 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
87428 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
87429 +hsc_write_55875 hsc_write 3 55875 NULL
87430 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
87431 +do_test_15766 do_test 1 15766 NULL
87432 +mmio_read_40348 mmio_read 4 40348 NULL
87433 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
87434 +named_distribute_48544 named_distribute 4 48544 NULL
87435 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
87436 +venus_link_32165 venus_link 5 32165 NULL
87437 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
87438 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
87439 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
87440 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
87441 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
87442 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
87443 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
87444 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
87445 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
87446 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
87447 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
87448 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
87449 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
87450 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
87451 +tunables_read_36385 tunables_read 3 36385 NULL
87452 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
87453 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
87454 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
87455 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
87456 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
87457 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
87458 +snapshot_write_28351 snapshot_write 3 28351 NULL
87459 +event_enable_read_7074 event_enable_read 3 7074 NULL
87460 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
87461 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
87462 +do_syslog_56807 do_syslog 3 56807 NULL
87463 +pskb_pull_65005 pskb_pull 2 65005 NULL
87464 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
87465 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
87466 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
87467 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
87468 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
87469 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
87470 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
87471 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
87472 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
87473 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
87474 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
87475 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
87476 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
87477 +if_write_51756 if_write 3 51756 NULL
87478 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
87479 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
87480 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
87481 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
87482 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
87483 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
87484 +lc_create_48662 lc_create 3 48662 NULL
87485 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
87486 +dev_write_7708 dev_write 3 7708 NULL
87487 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
87488 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87489 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
87490 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
87491 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
87492 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
87493 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
87494 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
87495 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
87496 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
87497 +altera_drscan_48698 altera_drscan 2 48698 NULL
87498 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
87499 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
87500 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
87501 +power_read_15939 power_read 3 15939 NULL
87502 +recv_msg_48709 recv_msg 4 48709 NULL
87503 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
87504 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
87505 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
87506 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
87507 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
87508 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87509 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
87510 +revalidate_19043 revalidate 2 19043 NULL
87511 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
87512 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
87513 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
87514 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
87515 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
87516 +check_header_56930 check_header 2 56930 NULL
87517 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
87518 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
87519 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
87520 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
87521 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
87522 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
87523 +frame_alloc_15981 frame_alloc 4 15981 NULL
87524 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
87525 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
87526 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
87527 +adu_read_24177 adu_read 3 24177 NULL
87528 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
87529 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
87530 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
87531 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
87532 +vfd_write_14717 vfd_write 3 14717 NULL
87533 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
87534 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
87535 +read_file_queue_40895 read_file_queue 3 40895 NULL
87536 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
87537 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
87538 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
87539 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
87540 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
87541 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
87542 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
87543 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
87544 +register_device_60015 register_device 2-3 60015 NULL
87545 +got_frame_16028 got_frame 2 16028 NULL
87546 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
87547 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
87548 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
87549 +waiters_read_40902 waiters_read 3 40902 NULL
87550 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
87551 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
87552 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
87553 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
87554 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
87555 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
87556 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
87557 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
87558 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
87559 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
87560 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
87561 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
87562 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
87563 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
87564 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
87565 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
87566 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
87567 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
87568 +fops_read_40672 fops_read 3 40672 NULL
87569 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
87570 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
87571 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
87572 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
87573 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
87574 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
87575 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
87576 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87577 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
87578 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
87579 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
87580 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
87581 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
87582 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
87583 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
87584 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
87585 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
87586 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
87587 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
87588 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
87589 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
87590 +fsm_init_16134 fsm_init 2 16134 NULL
87591 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
87592 +disconnect_32521 disconnect 4 32521 NULL
87593 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
87594 +pp_write_39554 pp_write 3 39554 NULL
87595 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
87596 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
87597 +ilo_read_32531 ilo_read 3 32531 NULL
87598 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
87599 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
87600 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
87601 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
87602 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
87603 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
87604 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
87605 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
87606 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
87607 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
87608 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
87609 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
87610 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
87611 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
87612 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87613 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
87614 +card_send_command_40757 card_send_command 3 40757 NULL
87615 +sys_mbind_7990 sys_mbind 5 7990 NULL
87616 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
87617 +pg_write_40766 pg_write 3 40766 NULL
87618 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
87619 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
87620 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
87621 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
87622 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
87623 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
87624 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
87625 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87626 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
87627 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
87628 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
87629 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
87630 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
87631 +vcs_read_8017 vcs_read 3 8017 NULL
87632 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
87633 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
87634 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
87635 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
87636 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
87637 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
87638 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
87639 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
87640 +copy_and_check_19089 copy_and_check 3 19089 NULL
87641 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
87642 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
87643 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
87644 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
87645 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
87646 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
87647 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
87648 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
87649 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
87650 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
87651 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
87652 +xd_rw_49020 xd_rw 3-4 49020 NULL
87653 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
87654 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
87655 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
87656 +kvmalloc_32646 kvmalloc 1 32646 NULL
87657 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
87658 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
87659 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
87660 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
87661 +generic_readlink_32654 generic_readlink 3 32654 NULL
87662 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
87663 +rbd_add_16366 rbd_add 3 16366 NULL
87664 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
87665 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
87666 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
87667 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
87668 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
87669 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
87670 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
87671 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
87672 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
87673 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
87674 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
87675 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
87676 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
87677 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
87678 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
87679 +venus_lookup_8121 venus_lookup 4 8121 NULL
87680 +compat_writev_60063 compat_writev 3 60063 NULL
87681 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
87682 +pd_video_read_24510 pd_video_read 3 24510 NULL
87683 +read_buf_20469 read_buf 2 20469 NULL
87684 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
87685 +scsi_register_49094 scsi_register 2 49094 NULL
87686 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
87687 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
87688 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
87689 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
87690 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
87691 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
87692 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
87693 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
87694 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
87695 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
87696 +alloc_dr_65495 alloc_dr 2 65495 NULL
87697 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
87698 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
87699 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
87700 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
87701 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
87702 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
87703 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
87704 +pt_read_49136 pt_read 3 49136 NULL
87705 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
87706 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
87707 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
87708 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
87709 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
87710 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
87711 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87712 new file mode 100644
87713 index 0000000..6387ddc
87714 --- /dev/null
87715 +++ b/tools/gcc/size_overflow_plugin.c
87716 @@ -0,0 +1,1918 @@
87717 +/*
87718 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87719 + * Licensed under the GPL v2, or (at your option) v3
87720 + *
87721 + * Homepage:
87722 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87723 + *
87724 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87725 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87726 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87727 + *
87728 + * Usage:
87729 + * $ 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
87730 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87731 + */
87732 +
87733 +#include "gcc-plugin.h"
87734 +#include "config.h"
87735 +#include "system.h"
87736 +#include "coretypes.h"
87737 +#include "tree.h"
87738 +#include "tree-pass.h"
87739 +#include "intl.h"
87740 +#include "plugin-version.h"
87741 +#include "tm.h"
87742 +#include "toplev.h"
87743 +#include "function.h"
87744 +#include "tree-flow.h"
87745 +#include "plugin.h"
87746 +#include "gimple.h"
87747 +#include "c-common.h"
87748 +#include "diagnostic.h"
87749 +#include "cfgloop.h"
87750 +
87751 +#if BUILDING_GCC_VERSION >= 4007
87752 +#include "c-tree.h"
87753 +#else
87754 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87755 +#endif
87756 +
87757 +struct size_overflow_hash {
87758 + const struct size_overflow_hash * const next;
87759 + const char * const name;
87760 + const unsigned int param;
87761 +};
87762 +
87763 +#include "size_overflow_hash.h"
87764 +
87765 +enum marked {
87766 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87767 +};
87768 +
87769 +#define __unused __attribute__((__unused__))
87770 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87771 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87772 +#define BEFORE_STMT true
87773 +#define AFTER_STMT false
87774 +#define CREATE_NEW_VAR NULL_TREE
87775 +#define CODES_LIMIT 32
87776 +#define MAX_PARAM 32
87777 +#define MY_STMT GF_PLF_1
87778 +#define NO_CAST_CHECK GF_PLF_2
87779 +
87780 +#if BUILDING_GCC_VERSION == 4005
87781 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87782 +#endif
87783 +
87784 +int plugin_is_GPL_compatible;
87785 +void debug_gimple_stmt(gimple gs);
87786 +
87787 +static tree expand(struct pointer_set_t *visited, tree lhs);
87788 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87789 +static tree report_size_overflow_decl;
87790 +static const_tree const_char_ptr_type_node;
87791 +static unsigned int handle_function(void);
87792 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87793 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87794 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
87795 +
87796 +static unsigned int call_count=0;
87797 +
87798 +static struct plugin_info size_overflow_plugin_info = {
87799 + .version = "20121212beta",
87800 + .help = "no-size-overflow\tturn off size overflow checking\n",
87801 +};
87802 +
87803 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87804 +{
87805 + unsigned int arg_count;
87806 + enum tree_code code = TREE_CODE(*node);
87807 +
87808 + switch (code) {
87809 + case FUNCTION_DECL:
87810 + arg_count = type_num_arguments(TREE_TYPE(*node));
87811 + break;
87812 + case FUNCTION_TYPE:
87813 + case METHOD_TYPE:
87814 + arg_count = type_num_arguments(*node);
87815 + break;
87816 + default:
87817 + *no_add_attrs = true;
87818 + error("%s: %qE attribute only applies to functions", __func__, name);
87819 + return NULL_TREE;
87820 + }
87821 +
87822 + for (; args; args = TREE_CHAIN(args)) {
87823 + tree position = TREE_VALUE(args);
87824 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87825 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87826 + *no_add_attrs = true;
87827 + }
87828 + }
87829 + return NULL_TREE;
87830 +}
87831 +
87832 +static const char* get_asm_name(tree node)
87833 +{
87834 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87835 +}
87836 +
87837 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87838 +{
87839 + unsigned int arg_count, arg_num;
87840 + enum tree_code code = TREE_CODE(*node);
87841 +
87842 + switch (code) {
87843 + case FUNCTION_DECL:
87844 + arg_count = type_num_arguments(TREE_TYPE(*node));
87845 + break;
87846 + case FUNCTION_TYPE:
87847 + case METHOD_TYPE:
87848 + arg_count = type_num_arguments(*node);
87849 + break;
87850 + case FIELD_DECL:
87851 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87852 + if (arg_num != 0) {
87853 + *no_add_attrs = true;
87854 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87855 + }
87856 + return NULL_TREE;
87857 + default:
87858 + *no_add_attrs = true;
87859 + error("%qE attribute only applies to functions", name);
87860 + return NULL_TREE;
87861 + }
87862 +
87863 + for (; args; args = TREE_CHAIN(args)) {
87864 + tree position = TREE_VALUE(args);
87865 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87866 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87867 + *no_add_attrs = true;
87868 + }
87869 + }
87870 + return NULL_TREE;
87871 +}
87872 +
87873 +static struct attribute_spec size_overflow_attr = {
87874 + .name = "size_overflow",
87875 + .min_length = 1,
87876 + .max_length = -1,
87877 + .decl_required = true,
87878 + .type_required = false,
87879 + .function_type_required = false,
87880 + .handler = handle_size_overflow_attribute,
87881 +#if BUILDING_GCC_VERSION >= 4007
87882 + .affects_type_identity = false
87883 +#endif
87884 +};
87885 +
87886 +static struct attribute_spec intentional_overflow_attr = {
87887 + .name = "intentional_overflow",
87888 + .min_length = 1,
87889 + .max_length = -1,
87890 + .decl_required = true,
87891 + .type_required = false,
87892 + .function_type_required = false,
87893 + .handler = handle_intentional_overflow_attribute,
87894 +#if BUILDING_GCC_VERSION >= 4007
87895 + .affects_type_identity = false
87896 +#endif
87897 +};
87898 +
87899 +static void register_attributes(void __unused *event_data, void __unused *data)
87900 +{
87901 + register_attribute(&size_overflow_attr);
87902 + register_attribute(&intentional_overflow_attr);
87903 +}
87904 +
87905 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87906 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87907 +{
87908 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87909 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87910 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87911 +
87912 + unsigned int m = 0x57559429;
87913 + unsigned int n = 0x5052acdb;
87914 + const unsigned int *key4 = (const unsigned int *)key;
87915 + unsigned int h = len;
87916 + unsigned int k = len + seed + n;
87917 + unsigned long long p;
87918 +
87919 + while (len >= 8) {
87920 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87921 + len -= 8;
87922 + }
87923 + if (len >= 4) {
87924 + cwmixb(key4[0]) key4 += 1;
87925 + len -= 4;
87926 + }
87927 + if (len)
87928 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87929 + cwmixb(h ^ (k + n));
87930 + return k ^ h;
87931 +
87932 +#undef cwfold
87933 +#undef cwmixa
87934 +#undef cwmixb
87935 +}
87936 +
87937 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87938 +{
87939 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87940 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87941 + return fn ^ codes;
87942 +}
87943 +
87944 +static inline tree get_original_function_decl(tree fndecl)
87945 +{
87946 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87947 + return DECL_ABSTRACT_ORIGIN(fndecl);
87948 + return fndecl;
87949 +}
87950 +
87951 +static inline gimple get_def_stmt(const_tree node)
87952 +{
87953 + gcc_assert(node != NULL_TREE);
87954 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87955 + return SSA_NAME_DEF_STMT(node);
87956 +}
87957 +
87958 +static unsigned char get_tree_code(const_tree type)
87959 +{
87960 + switch (TREE_CODE(type)) {
87961 + case ARRAY_TYPE:
87962 + return 0;
87963 + case BOOLEAN_TYPE:
87964 + return 1;
87965 + case ENUMERAL_TYPE:
87966 + return 2;
87967 + case FUNCTION_TYPE:
87968 + return 3;
87969 + case INTEGER_TYPE:
87970 + return 4;
87971 + case POINTER_TYPE:
87972 + return 5;
87973 + case RECORD_TYPE:
87974 + return 6;
87975 + case UNION_TYPE:
87976 + return 7;
87977 + case VOID_TYPE:
87978 + return 8;
87979 + case REAL_TYPE:
87980 + return 9;
87981 + case VECTOR_TYPE:
87982 + return 10;
87983 + case REFERENCE_TYPE:
87984 + return 11;
87985 + case OFFSET_TYPE:
87986 + return 12;
87987 + case COMPLEX_TYPE:
87988 + return 13;
87989 + default:
87990 + debug_tree((tree)type);
87991 + gcc_unreachable();
87992 + }
87993 +}
87994 +
87995 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87996 +{
87997 + gcc_assert(type != NULL_TREE);
87998 +
87999 + while (type && len < CODES_LIMIT) {
88000 + tree_codes[len] = get_tree_code(type);
88001 + len++;
88002 + type = TREE_TYPE(type);
88003 + }
88004 + return len;
88005 +}
88006 +
88007 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
88008 +{
88009 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88010 + enum tree_code code = TREE_CODE(type);
88011 + size_t len = 0;
88012 +
88013 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88014 +
88015 + arg = TYPE_ARG_TYPES(type);
88016 + // skip builtins __builtin_constant_p
88017 + if (!arg && DECL_BUILT_IN(fndecl))
88018 + return 0;
88019 +
88020 + if (TREE_CODE_CLASS(code) == tcc_type)
88021 + result = type;
88022 + else
88023 + result = DECL_RESULT(fndecl);
88024 +
88025 + gcc_assert(result != NULL_TREE);
88026 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88027 +
88028 + if (arg == NULL_TREE) {
88029 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88030 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88031 + if (arg_field == NULL_TREE)
88032 + return 0;
88033 + arg = TREE_TYPE(arg_field);
88034 + len = add_type_codes(arg, tree_codes, len);
88035 + gcc_assert(len != 0);
88036 + return len;
88037 + }
88038 +
88039 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88040 + while (arg && len < CODES_LIMIT) {
88041 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88042 + arg = TREE_CHAIN(arg);
88043 + }
88044 +
88045 + gcc_assert(len != 0);
88046 + return len;
88047 +}
88048 +
88049 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88050 +{
88051 + unsigned int hash;
88052 + const struct size_overflow_hash *entry;
88053 + unsigned char tree_codes[CODES_LIMIT];
88054 + size_t len;
88055 + const char *func_name = get_asm_name(fndecl);
88056 +
88057 + len = get_function_decl(fndecl, tree_codes);
88058 + if (len == 0)
88059 + return NULL;
88060 +
88061 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88062 +
88063 + entry = size_overflow_hash[hash];
88064 + while (entry) {
88065 + if (!strcmp(entry->name, func_name))
88066 + return entry;
88067 + entry = entry->next;
88068 + }
88069 +
88070 + return NULL;
88071 +}
88072 +
88073 +static void check_arg_type(const_tree arg)
88074 +{
88075 + const_tree type = TREE_TYPE(arg);
88076 + enum tree_code code = TREE_CODE(type);
88077 +
88078 + if (code == BOOLEAN_TYPE)
88079 + return;
88080 +
88081 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88082 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88083 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88084 +}
88085 +
88086 +static int find_arg_number(const_tree arg, tree func)
88087 +{
88088 + tree var;
88089 + unsigned int argnum = 1;
88090 +
88091 + if (TREE_CODE(arg) == SSA_NAME)
88092 + arg = SSA_NAME_VAR(arg);
88093 +
88094 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88095 + if (strcmp(NAME(arg), NAME(var))) {
88096 + argnum++;
88097 + continue;
88098 + }
88099 + check_arg_type(var);
88100 + return argnum;
88101 + }
88102 + gcc_unreachable();
88103 +}
88104 +
88105 +static tree create_new_var(tree type)
88106 +{
88107 + tree new_var = create_tmp_var(type, "cicus");
88108 +
88109 + add_referenced_var(new_var);
88110 + mark_sym_for_renaming(new_var);
88111 + return new_var;
88112 +}
88113 +
88114 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88115 +{
88116 + gimple assign;
88117 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88118 + tree type = TREE_TYPE(rhs1);
88119 + tree lhs = create_new_var(type);
88120 +
88121 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88122 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88123 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88124 +
88125 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88126 + update_stmt(assign);
88127 + gimple_set_plf(assign, MY_STMT, true);
88128 + return assign;
88129 +}
88130 +
88131 +static bool is_bool(const_tree node)
88132 +{
88133 + const_tree type;
88134 +
88135 + if (node == NULL_TREE)
88136 + return false;
88137 +
88138 + type = TREE_TYPE(node);
88139 + if (!INTEGRAL_TYPE_P(type))
88140 + return false;
88141 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88142 + return true;
88143 + if (TYPE_PRECISION(type) == 1)
88144 + return true;
88145 + return false;
88146 +}
88147 +
88148 +static tree cast_a_tree(tree type, tree var)
88149 +{
88150 + gcc_assert(type != NULL_TREE);
88151 + gcc_assert(var != NULL_TREE);
88152 + gcc_assert(fold_convertible_p(type, var));
88153 +
88154 + return fold_convert(type, var);
88155 +}
88156 +
88157 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88158 +{
88159 + gimple assign;
88160 +
88161 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88162 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88163 + gcc_unreachable();
88164 +
88165 + if (lhs == CREATE_NEW_VAR)
88166 + lhs = create_new_var(dst_type);
88167 +
88168 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88169 +
88170 + if (!gsi_end_p(*gsi)) {
88171 + location_t loc = gimple_location(gsi_stmt(*gsi));
88172 + gimple_set_location(assign, loc);
88173 + }
88174 +
88175 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88176 +
88177 + if (before)
88178 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88179 + else
88180 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88181 + update_stmt(assign);
88182 + gimple_set_plf(assign, MY_STMT, true);
88183 +
88184 + return assign;
88185 +}
88186 +
88187 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88188 +{
88189 + gimple assign;
88190 + gimple_stmt_iterator gsi;
88191 +
88192 + if (rhs == NULL_TREE)
88193 + return NULL_TREE;
88194 +
88195 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88196 + return rhs;
88197 +
88198 + gsi = gsi_for_stmt(stmt);
88199 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88200 + gimple_set_plf(assign, MY_STMT, true);
88201 + return gimple_get_lhs(assign);
88202 +}
88203 +
88204 +static tree cast_to_TI_type(gimple stmt, tree node)
88205 +{
88206 + gimple_stmt_iterator gsi;
88207 + gimple cast_stmt;
88208 + tree type = TREE_TYPE(node);
88209 +
88210 + if (types_compatible_p(type, intTI_type_node))
88211 + return node;
88212 +
88213 + gsi = gsi_for_stmt(stmt);
88214 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88215 + gimple_set_plf(cast_stmt, MY_STMT, true);
88216 + return gimple_get_lhs(cast_stmt);
88217 +}
88218 +
88219 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88220 +{
88221 + tree lhs;
88222 + gimple_stmt_iterator gsi;
88223 +
88224 + if (rhs1 == NULL_TREE) {
88225 + debug_gimple_stmt(oldstmt);
88226 + error("%s: rhs1 is NULL_TREE", __func__);
88227 + gcc_unreachable();
88228 + }
88229 +
88230 + switch (gimple_code(oldstmt)) {
88231 + case GIMPLE_ASM:
88232 + lhs = rhs1;
88233 + break;
88234 + case GIMPLE_CALL:
88235 + lhs = gimple_call_lhs(oldstmt);
88236 + break;
88237 + case GIMPLE_ASSIGN:
88238 + lhs = gimple_get_lhs(oldstmt);
88239 + break;
88240 + default:
88241 + debug_gimple_stmt(oldstmt);
88242 + gcc_unreachable();
88243 + }
88244 +
88245 + gsi = gsi_for_stmt(oldstmt);
88246 + pointer_set_insert(visited, oldstmt);
88247 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88248 + basic_block next_bb, cur_bb;
88249 + const_edge e;
88250 +
88251 + gcc_assert(before == false);
88252 + gcc_assert(stmt_can_throw_internal(oldstmt));
88253 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88254 + gcc_assert(!gsi_end_p(gsi));
88255 +
88256 + cur_bb = gimple_bb(oldstmt);
88257 + next_bb = cur_bb->next_bb;
88258 + e = find_edge(cur_bb, next_bb);
88259 + gcc_assert(e != NULL);
88260 + gcc_assert(e->flags & EDGE_FALLTHRU);
88261 +
88262 + gsi = gsi_after_labels(next_bb);
88263 + gcc_assert(!gsi_end_p(gsi));
88264 +
88265 + before = true;
88266 + oldstmt = gsi_stmt(gsi);
88267 + }
88268 +
88269 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88270 +}
88271 +
88272 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88273 +{
88274 + gimple stmt;
88275 + gimple_stmt_iterator gsi;
88276 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88277 +
88278 + if (gimple_plf(oldstmt, MY_STMT))
88279 + return lhs;
88280 +
88281 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88282 + rhs1 = gimple_assign_rhs1(oldstmt);
88283 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88284 + }
88285 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88286 + rhs2 = gimple_assign_rhs2(oldstmt);
88287 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88288 + }
88289 +
88290 + stmt = gimple_copy(oldstmt);
88291 + gimple_set_location(stmt, gimple_location(oldstmt));
88292 + gimple_set_plf(stmt, MY_STMT, true);
88293 +
88294 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88295 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88296 +
88297 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88298 +
88299 + if (is_bool(lhs))
88300 + new_var = SSA_NAME_VAR(lhs);
88301 + else
88302 + new_var = create_new_var(size_overflow_type);
88303 + new_var = make_ssa_name(new_var, stmt);
88304 + gimple_set_lhs(stmt, new_var);
88305 +
88306 + if (rhs1 != NULL_TREE)
88307 + gimple_assign_set_rhs1(stmt, rhs1);
88308 +
88309 + if (rhs2 != NULL_TREE)
88310 + gimple_assign_set_rhs2(stmt, rhs2);
88311 +#if BUILDING_GCC_VERSION >= 4007
88312 + if (rhs3 != NULL_TREE)
88313 + gimple_assign_set_rhs3(stmt, rhs3);
88314 +#endif
88315 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88316 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88317 +
88318 + gsi = gsi_for_stmt(oldstmt);
88319 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88320 + update_stmt(stmt);
88321 + pointer_set_insert(visited, oldstmt);
88322 + return gimple_get_lhs(stmt);
88323 +}
88324 +
88325 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88326 +{
88327 + basic_block bb;
88328 + gimple phi;
88329 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88330 +
88331 + bb = gsi_bb(gsi);
88332 +
88333 + phi = create_phi_node(result, bb);
88334 + gsi = gsi_last(phi_nodes(bb));
88335 + gsi_remove(&gsi, false);
88336 +
88337 + gsi = gsi_for_stmt(oldstmt);
88338 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88339 + gimple_set_bb(phi, bb);
88340 + gimple_set_plf(phi, MY_STMT, true);
88341 + return phi;
88342 +}
88343 +
88344 +static basic_block create_a_first_bb(void)
88345 +{
88346 + basic_block first_bb;
88347 +
88348 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88349 + if (dom_info_available_p(CDI_DOMINATORS))
88350 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88351 + return first_bb;
88352 +}
88353 +
88354 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88355 +{
88356 + basic_block bb;
88357 + const_gimple newstmt;
88358 + gimple_stmt_iterator gsi;
88359 + bool before = BEFORE_STMT;
88360 +
88361 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88362 + gsi = gsi_for_stmt(get_def_stmt(arg));
88363 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88364 + return gimple_get_lhs(newstmt);
88365 + }
88366 +
88367 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88368 + gsi = gsi_after_labels(bb);
88369 + if (bb->index == 0) {
88370 + bb = create_a_first_bb();
88371 + gsi = gsi_start_bb(bb);
88372 + }
88373 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88374 + return gimple_get_lhs(newstmt);
88375 +}
88376 +
88377 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88378 +{
88379 + gimple newstmt;
88380 + gimple_stmt_iterator gsi;
88381 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88382 + gimple def_newstmt = get_def_stmt(new_rhs);
88383 +
88384 + gsi_insert = gsi_insert_after;
88385 + gsi = gsi_for_stmt(def_newstmt);
88386 +
88387 + switch (gimple_code(get_def_stmt(arg))) {
88388 + case GIMPLE_PHI:
88389 + newstmt = gimple_build_assign(new_var, new_rhs);
88390 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88391 + gsi_insert = gsi_insert_before;
88392 + break;
88393 + case GIMPLE_ASM:
88394 + case GIMPLE_CALL:
88395 + newstmt = gimple_build_assign(new_var, new_rhs);
88396 + break;
88397 + case GIMPLE_ASSIGN:
88398 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88399 + break;
88400 + default:
88401 + /* unknown gimple_code (handle_build_new_phi_arg) */
88402 + gcc_unreachable();
88403 + }
88404 +
88405 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88406 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88407 + gimple_set_plf(newstmt, MY_STMT, true);
88408 + update_stmt(newstmt);
88409 + return newstmt;
88410 +}
88411 +
88412 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88413 +{
88414 + const_gimple newstmt;
88415 + gimple def_stmt;
88416 + tree new_rhs;
88417 +
88418 + new_rhs = expand(visited, arg);
88419 + if (new_rhs == NULL_TREE)
88420 + return NULL_TREE;
88421 +
88422 + def_stmt = get_def_stmt(new_rhs);
88423 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88424 + return NULL_TREE;
88425 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88426 +
88427 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88428 + return gimple_get_lhs(newstmt);
88429 +}
88430 +
88431 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88432 +{
88433 + gimple phi, oldstmt = get_def_stmt(orig_result);
88434 + tree new_result, size_overflow_type;
88435 + unsigned int i;
88436 + unsigned int n = gimple_phi_num_args(oldstmt);
88437 +
88438 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88439 +
88440 + new_result = create_new_var(size_overflow_type);
88441 +
88442 + pointer_set_insert(visited, oldstmt);
88443 + phi = overflow_create_phi_node(oldstmt, new_result);
88444 + for (i = 0; i < n; i++) {
88445 + tree arg, lhs;
88446 +
88447 + arg = gimple_phi_arg_def(oldstmt, i);
88448 + if (is_gimple_constant(arg))
88449 + arg = cast_a_tree(size_overflow_type, arg);
88450 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88451 + if (lhs == NULL_TREE)
88452 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88453 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88454 + }
88455 +
88456 + update_stmt(phi);
88457 + return gimple_phi_result(phi);
88458 +}
88459 +
88460 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88461 +{
88462 + const_gimple assign;
88463 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88464 + tree origtype = TREE_TYPE(orig_rhs);
88465 +
88466 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88467 +
88468 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88469 + return gimple_get_lhs(assign);
88470 +}
88471 +
88472 +static void change_rhs1(gimple stmt, tree new_rhs1)
88473 +{
88474 + tree assign_rhs;
88475 + const_tree rhs = gimple_assign_rhs1(stmt);
88476 +
88477 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88478 + gimple_assign_set_rhs1(stmt, assign_rhs);
88479 + update_stmt(stmt);
88480 +}
88481 +
88482 +static bool check_mode_type(const_gimple stmt)
88483 +{
88484 + const_tree lhs = gimple_get_lhs(stmt);
88485 + const_tree lhs_type = TREE_TYPE(lhs);
88486 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88487 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88488 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88489 +
88490 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88491 + return false;
88492 +
88493 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88494 + return false;
88495 +
88496 + return true;
88497 +}
88498 +
88499 +static bool check_undefined_integer_operation(const_gimple stmt)
88500 +{
88501 + const_gimple def_stmt;
88502 + const_tree lhs = gimple_get_lhs(stmt);
88503 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88504 + const_tree rhs1_type = TREE_TYPE(rhs1);
88505 + const_tree lhs_type = TREE_TYPE(lhs);
88506 +
88507 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88508 + return false;
88509 +
88510 + def_stmt = get_def_stmt(rhs1);
88511 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88512 + return false;
88513 +
88514 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88515 + return false;
88516 + return true;
88517 +}
88518 +
88519 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88520 +{
88521 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88522 + enum machine_mode lhs_mode, rhs_mode;
88523 + gimple def_stmt = get_def_stmt(no_const_rhs);
88524 +
88525 + if (!gimple_assign_cast_p(def_stmt))
88526 + return false;
88527 +
88528 + rhs1 = gimple_assign_rhs1(def_stmt);
88529 + lhs = gimple_get_lhs(def_stmt);
88530 + rhs1_type = TREE_TYPE(rhs1);
88531 + lhs_type = TREE_TYPE(lhs);
88532 + rhs_mode = TYPE_MODE(rhs1_type);
88533 + lhs_mode = TYPE_MODE(lhs_type);
88534 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88535 + return false;
88536 +
88537 + return true;
88538 +}
88539 +
88540 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88541 +{
88542 + gimple def_stmt;
88543 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88544 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88545 + const_tree rhs1_type = TREE_TYPE(rhs1);
88546 + const_tree lhs_type = TREE_TYPE(lhs);
88547 +
88548 + new_rhs1 = expand(visited, rhs1);
88549 +
88550 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88551 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88552 +
88553 + if (gimple_plf(stmt, MY_STMT))
88554 + return lhs;
88555 +
88556 + if (gimple_plf(stmt, NO_CAST_CHECK))
88557 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88558 +
88559 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88560 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88561 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88562 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88563 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88564 + }
88565 +
88566 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88567 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88568 +
88569 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88570 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88571 +
88572 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88573 +
88574 + rhs1 = gimple_assign_rhs1(stmt);
88575 + rhs1_type = TREE_TYPE(rhs1);
88576 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type)) {
88577 + def_stmt = get_def_stmt(new_rhs1);
88578 + rhs1 = gimple_assign_rhs1(def_stmt);
88579 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88580 + }
88581 + change_rhs1(stmt, new_rhs1);
88582 +
88583 + if (!check_mode_type(stmt))
88584 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88585 +
88586 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88587 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88588 +
88589 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88590 +
88591 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88592 +}
88593 +
88594 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
88595 +{
88596 + tree rhs1, lhs = gimple_get_lhs(stmt);
88597 + gimple def_stmt = get_def_stmt(lhs);
88598 +
88599 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
88600 + rhs1 = gimple_assign_rhs1(def_stmt);
88601 +
88602 + if (is_gimple_constant(rhs1))
88603 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88604 +
88605 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88606 + switch (TREE_CODE(rhs1)) {
88607 + case SSA_NAME:
88608 + return handle_unary_rhs(visited, def_stmt);
88609 + case ARRAY_REF:
88610 + case BIT_FIELD_REF:
88611 + case ADDR_EXPR:
88612 + case COMPONENT_REF:
88613 + case INDIRECT_REF:
88614 +#if BUILDING_GCC_VERSION >= 4006
88615 + case MEM_REF:
88616 +#endif
88617 + case TARGET_MEM_REF:
88618 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88619 + case PARM_DECL:
88620 + case VAR_DECL:
88621 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88622 +
88623 + default:
88624 + debug_gimple_stmt(def_stmt);
88625 + debug_tree(rhs1);
88626 + gcc_unreachable();
88627 + }
88628 +}
88629 +
88630 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88631 +{
88632 + gimple cond_stmt;
88633 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88634 +
88635 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88636 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88637 + update_stmt(cond_stmt);
88638 +}
88639 +
88640 +static tree create_string_param(tree string)
88641 +{
88642 + tree i_type, a_type;
88643 + const int length = TREE_STRING_LENGTH(string);
88644 +
88645 + gcc_assert(length > 0);
88646 +
88647 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88648 + a_type = build_array_type(char_type_node, i_type);
88649 +
88650 + TREE_TYPE(string) = a_type;
88651 + TREE_CONSTANT(string) = 1;
88652 + TREE_READONLY(string) = 1;
88653 +
88654 + return build1(ADDR_EXPR, ptr_type_node, string);
88655 +}
88656 +
88657 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88658 +{
88659 + gimple func_stmt;
88660 + const_gimple def_stmt;
88661 + const_tree loc_line;
88662 + tree loc_file, ssa_name, current_func;
88663 + expanded_location xloc;
88664 + char *ssa_name_buf;
88665 + int len;
88666 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88667 +
88668 + def_stmt = get_def_stmt(arg);
88669 + xloc = expand_location(gimple_location(def_stmt));
88670 +
88671 + if (!gimple_has_location(def_stmt)) {
88672 + xloc = expand_location(gimple_location(stmt));
88673 + if (!gimple_has_location(stmt))
88674 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88675 + }
88676 +
88677 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88678 +
88679 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88680 + loc_file = create_string_param(loc_file);
88681 +
88682 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88683 + current_func = create_string_param(current_func);
88684 +
88685 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
88686 + call_count++;
88687 + 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);
88688 + gcc_assert(len > 0);
88689 + ssa_name = build_string(len + 1, ssa_name_buf);
88690 + free(ssa_name_buf);
88691 + ssa_name = create_string_param(ssa_name);
88692 +
88693 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88694 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88695 +
88696 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88697 +}
88698 +
88699 +static void __unused print_the_code_insertions(const_gimple stmt)
88700 +{
88701 + location_t loc = gimple_location(stmt);
88702 +
88703 + inform(loc, "Integer size_overflow check applied here.");
88704 +}
88705 +
88706 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88707 +{
88708 + basic_block cond_bb, join_bb, bb_true;
88709 + edge e;
88710 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88711 +
88712 + cond_bb = gimple_bb(stmt);
88713 + if (before)
88714 + gsi_prev(&gsi);
88715 + if (gsi_end_p(gsi))
88716 + e = split_block_after_labels(cond_bb);
88717 + else
88718 + e = split_block(cond_bb, gsi_stmt(gsi));
88719 + cond_bb = e->src;
88720 + join_bb = e->dest;
88721 + e->flags = EDGE_FALSE_VALUE;
88722 + e->probability = REG_BR_PROB_BASE;
88723 +
88724 + bb_true = create_empty_bb(cond_bb);
88725 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88726 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88727 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88728 +
88729 + if (dom_info_available_p(CDI_DOMINATORS)) {
88730 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88731 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88732 + }
88733 +
88734 + if (current_loops != NULL) {
88735 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88736 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88737 + }
88738 +
88739 + insert_cond(cond_bb, arg, cond_code, type_value);
88740 + insert_cond_result(bb_true, stmt, arg, min);
88741 +
88742 +// print_the_code_insertions(stmt);
88743 +}
88744 +
88745 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88746 +{
88747 + const_tree rhs_type = TREE_TYPE(rhs);
88748 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88749 +
88750 + gcc_assert(rhs_type != NULL_TREE);
88751 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88752 + return;
88753 +
88754 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88755 +
88756 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88757 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88758 +
88759 + gcc_assert(!TREE_OVERFLOW(type_max));
88760 +
88761 + cast_rhs_type = TREE_TYPE(cast_rhs);
88762 + type_max_type = TREE_TYPE(type_max);
88763 + type_min_type = TREE_TYPE(type_min);
88764 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
88765 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
88766 +
88767 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88768 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88769 +}
88770 +
88771 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88772 +{
88773 + gimple change_rhs_def_stmt;
88774 + tree lhs = gimple_get_lhs(def_stmt);
88775 + tree lhs_type = TREE_TYPE(lhs);
88776 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88777 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88778 +
88779 + if (change_rhs == NULL_TREE)
88780 + return get_size_overflow_type(def_stmt, lhs);
88781 +
88782 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88783 +
88784 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88785 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88786 +
88787 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88788 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88789 +
88790 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88791 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88792 +
88793 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
88794 + debug_gimple_stmt(def_stmt);
88795 + gcc_unreachable();
88796 + }
88797 +
88798 + return get_size_overflow_type(def_stmt, lhs);
88799 +}
88800 +
88801 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88802 +{
88803 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88804 + return false;
88805 + if (!is_gimple_constant(rhs))
88806 + return false;
88807 + return true;
88808 +}
88809 +
88810 +static bool is_subtraction_special(const_gimple stmt)
88811 +{
88812 + gimple rhs1_def_stmt, rhs2_def_stmt;
88813 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
88814 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
88815 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88816 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88817 +
88818 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88819 + return false;
88820 +
88821 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88822 +
88823 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
88824 + return false;
88825 +
88826 + rhs1_def_stmt = get_def_stmt(rhs1);
88827 + rhs2_def_stmt = get_def_stmt(rhs2);
88828 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88829 + return false;
88830 +
88831 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88832 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88833 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
88834 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
88835 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88836 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88837 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
88838 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
88839 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
88840 + return false;
88841 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
88842 + return false;
88843 +
88844 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88845 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88846 + return true;
88847 +}
88848 +
88849 +static tree get_def_stmt_rhs(const_tree var)
88850 +{
88851 + tree rhs1, def_stmt_rhs1;
88852 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
88853 +
88854 + def_stmt = get_def_stmt(var);
88855 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
88856 +
88857 + rhs1 = gimple_assign_rhs1(def_stmt);
88858 + rhs1_def_stmt = get_def_stmt(rhs1);
88859 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
88860 + if (!gimple_assign_cast_p(rhs1_def_stmt))
88861 + return rhs1;
88862 +
88863 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88864 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
88865 +
88866 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
88867 + case GIMPLE_CALL:
88868 + case GIMPLE_NOP:
88869 + case GIMPLE_ASM:
88870 + return def_stmt_rhs1;
88871 + case GIMPLE_ASSIGN:
88872 + return rhs1;
88873 + default:
88874 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
88875 + gcc_unreachable();
88876 + }
88877 +}
88878 +
88879 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88880 +{
88881 + tree new_rhs1, new_rhs2;
88882 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88883 + gimple assign, stmt = get_def_stmt(lhs);
88884 + tree rhs1 = gimple_assign_rhs1(stmt);
88885 + tree rhs2 = gimple_assign_rhs2(stmt);
88886 +
88887 + if (!is_subtraction_special(stmt))
88888 + return NULL_TREE;
88889 +
88890 + new_rhs1 = expand(visited, rhs1);
88891 + new_rhs2 = expand(visited, rhs2);
88892 +
88893 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
88894 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
88895 +
88896 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
88897 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
88898 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
88899 + }
88900 +
88901 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88902 + new_lhs = gimple_get_lhs(assign);
88903 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88904 +
88905 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88906 +}
88907 +
88908 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88909 +{
88910 + const_gimple def_stmt;
88911 +
88912 + if (TREE_CODE(rhs) != SSA_NAME)
88913 + return false;
88914 +
88915 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88916 + return false;
88917 +
88918 + def_stmt = get_def_stmt(rhs);
88919 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88920 + return false;
88921 +
88922 + return true;
88923 +}
88924 +
88925 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88926 +{
88927 + tree new_rhs, size_overflow_type, orig_rhs;
88928 + void (*gimple_assign_set_rhs)(gimple, tree);
88929 + tree rhs1 = gimple_assign_rhs1(stmt);
88930 + tree rhs2 = gimple_assign_rhs2(stmt);
88931 + tree lhs = gimple_get_lhs(stmt);
88932 +
88933 + if (change_rhs == NULL_TREE)
88934 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88935 +
88936 + if (new_rhs2 == NULL_TREE) {
88937 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88938 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88939 + orig_rhs = rhs1;
88940 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88941 + } else {
88942 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88943 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88944 + orig_rhs = rhs2;
88945 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88946 + }
88947 +
88948 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88949 +
88950 + if (check_overflow)
88951 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88952 +
88953 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88954 + gimple_assign_set_rhs(stmt, new_rhs);
88955 + update_stmt(stmt);
88956 +
88957 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88958 +}
88959 +
88960 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88961 +{
88962 + tree rhs1, rhs2, new_lhs;
88963 + gimple def_stmt = get_def_stmt(lhs);
88964 + tree new_rhs1 = NULL_TREE;
88965 + tree new_rhs2 = NULL_TREE;
88966 +
88967 + rhs1 = gimple_assign_rhs1(def_stmt);
88968 + rhs2 = gimple_assign_rhs2(def_stmt);
88969 +
88970 + /* no DImode/TImode division in the 32/64 bit kernel */
88971 + switch (gimple_assign_rhs_code(def_stmt)) {
88972 + case RDIV_EXPR:
88973 + case TRUNC_DIV_EXPR:
88974 + case CEIL_DIV_EXPR:
88975 + case FLOOR_DIV_EXPR:
88976 + case ROUND_DIV_EXPR:
88977 + case TRUNC_MOD_EXPR:
88978 + case CEIL_MOD_EXPR:
88979 + case FLOOR_MOD_EXPR:
88980 + case ROUND_MOD_EXPR:
88981 + case EXACT_DIV_EXPR:
88982 + case POINTER_PLUS_EXPR:
88983 + case BIT_AND_EXPR:
88984 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88985 + default:
88986 + break;
88987 + }
88988 +
88989 + new_lhs = handle_integer_truncation(visited, lhs);
88990 + if (new_lhs != NULL_TREE)
88991 + return new_lhs;
88992 +
88993 + if (TREE_CODE(rhs1) == SSA_NAME)
88994 + new_rhs1 = expand(visited, rhs1);
88995 + if (TREE_CODE(rhs2) == SSA_NAME)
88996 + new_rhs2 = expand(visited, rhs2);
88997 +
88998 + if (is_a_neg_overflow(def_stmt, rhs2))
88999 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89000 + if (is_a_neg_overflow(def_stmt, rhs1))
89001 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89002 +
89003 + if (is_a_constant_overflow(def_stmt, rhs2))
89004 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89005 + if (is_a_constant_overflow(def_stmt, rhs1))
89006 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89007 +
89008 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89009 +}
89010 +
89011 +#if BUILDING_GCC_VERSION >= 4007
89012 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
89013 +{
89014 + if (is_gimple_constant(rhs))
89015 + return cast_a_tree(size_overflow_type, rhs);
89016 + if (TREE_CODE(rhs) != SSA_NAME)
89017 + return NULL_TREE;
89018 + return expand(visited, rhs);
89019 +}
89020 +
89021 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
89022 +{
89023 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
89024 + gimple def_stmt = get_def_stmt(lhs);
89025 +
89026 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
89027 +
89028 + rhs1 = gimple_assign_rhs1(def_stmt);
89029 + rhs2 = gimple_assign_rhs2(def_stmt);
89030 + rhs3 = gimple_assign_rhs3(def_stmt);
89031 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
89032 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89033 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89034 +
89035 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89036 +}
89037 +#endif
89038 +
89039 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89040 +{
89041 + const_tree type;
89042 + tree new_type;
89043 +
89044 + gcc_assert(node != NULL_TREE);
89045 +
89046 + type = TREE_TYPE(node);
89047 +
89048 + if (gimple_plf(stmt, MY_STMT))
89049 + return TREE_TYPE(node);
89050 +
89051 + switch (TYPE_MODE(type)) {
89052 + case QImode:
89053 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89054 + break;
89055 + case HImode:
89056 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89057 + break;
89058 + case SImode:
89059 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89060 + break;
89061 + case DImode:
89062 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89063 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89064 + else
89065 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89066 + break;
89067 + default:
89068 + debug_tree((tree)node);
89069 + error("%s: unsupported gcc configuration.", __func__);
89070 + gcc_unreachable();
89071 + }
89072 +
89073 + if (TYPE_QUALS(type) != 0)
89074 + return build_qualified_type(new_type, TYPE_QUALS(type));
89075 + return new_type;
89076 +}
89077 +
89078 +static tree expand_visited(gimple def_stmt)
89079 +{
89080 + const_gimple next_stmt;
89081 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89082 +
89083 + gsi_next(&gsi);
89084 + next_stmt = gsi_stmt(gsi);
89085 +
89086 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89087 +
89088 + switch (gimple_code(next_stmt)) {
89089 + case GIMPLE_ASSIGN:
89090 + return gimple_get_lhs(next_stmt);
89091 + case GIMPLE_PHI:
89092 + return gimple_phi_result(next_stmt);
89093 + case GIMPLE_CALL:
89094 + return gimple_call_lhs(next_stmt);
89095 + default:
89096 + return NULL_TREE;
89097 + }
89098 +}
89099 +
89100 +static tree expand(struct pointer_set_t *visited, tree lhs)
89101 +{
89102 + gimple def_stmt;
89103 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89104 +
89105 + if (is_gimple_constant(lhs))
89106 + return NULL_TREE;
89107 +
89108 + if (TREE_CODE(lhs) == ADDR_EXPR)
89109 + return NULL_TREE;
89110 +
89111 + if (code == REAL_TYPE)
89112 + return NULL_TREE;
89113 +
89114 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89115 +
89116 + def_stmt = get_def_stmt(lhs);
89117 +
89118 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
89119 + return NULL_TREE;
89120 +
89121 + if (gimple_plf(def_stmt, MY_STMT))
89122 + return lhs;
89123 +
89124 + // skip char type, except PHI (FIXME: only kernel)
89125 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode && gimple_code(def_stmt) != GIMPLE_PHI)
89126 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89127 +
89128 + if (pointer_set_contains(visited, def_stmt))
89129 + return expand_visited(def_stmt);
89130 +
89131 + switch (gimple_code(def_stmt)) {
89132 + case GIMPLE_PHI:
89133 + return build_new_phi(visited, lhs);
89134 + case GIMPLE_CALL:
89135 + case GIMPLE_ASM:
89136 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89137 + case GIMPLE_ASSIGN:
89138 + switch (gimple_num_ops(def_stmt)) {
89139 + case 2:
89140 + return handle_unary_ops(visited, def_stmt);
89141 + case 3:
89142 + return handle_binary_ops(visited, lhs);
89143 +#if BUILDING_GCC_VERSION >= 4007
89144 + case 4:
89145 + return handle_ternary_ops(visited, lhs);
89146 +#endif
89147 + }
89148 + default:
89149 + debug_gimple_stmt(def_stmt);
89150 + error("%s: unknown gimple code", __func__);
89151 + gcc_unreachable();
89152 + }
89153 +}
89154 +
89155 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89156 +{
89157 + const_gimple assign;
89158 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89159 + tree origtype = TREE_TYPE(origarg);
89160 +
89161 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89162 +
89163 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89164 +
89165 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89166 + update_stmt(stmt);
89167 +}
89168 +
89169 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89170 +{
89171 + const char *origid;
89172 + tree arg;
89173 + const_tree origarg;
89174 +
89175 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89176 + return true;
89177 +
89178 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89179 + while (origarg && *argnum) {
89180 + (*argnum)--;
89181 + origarg = TREE_CHAIN(origarg);
89182 + }
89183 +
89184 + gcc_assert(*argnum == 0);
89185 +
89186 + gcc_assert(origarg != NULL_TREE);
89187 + origid = NAME(origarg);
89188 + *argnum = 0;
89189 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89190 + if (!strcmp(origid, NAME(arg)))
89191 + return true;
89192 + (*argnum)++;
89193 + }
89194 + return false;
89195 +}
89196 +
89197 +static bool skip_types(const_tree var)
89198 +{
89199 + const_tree type;
89200 +
89201 + switch (TREE_CODE(var)) {
89202 + case ADDR_EXPR:
89203 +#if BUILDING_GCC_VERSION >= 4006
89204 + case MEM_REF:
89205 +#endif
89206 + case ARRAY_REF:
89207 + case BIT_FIELD_REF:
89208 + case INDIRECT_REF:
89209 + case TARGET_MEM_REF:
89210 + case VAR_DECL:
89211 + return true;
89212 + default:
89213 + break;
89214 + }
89215 +
89216 + type = TREE_TYPE(TREE_TYPE(var));
89217 + if (!type)
89218 + return false;
89219 + switch (TREE_CODE(type)) {
89220 + case RECORD_TYPE:
89221 + return true;
89222 + default:
89223 + break;
89224 + }
89225 +
89226 + return false;
89227 +}
89228 +
89229 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89230 +{
89231 + gimple phi = get_def_stmt(result);
89232 + unsigned int i, n = gimple_phi_num_args(phi);
89233 +
89234 + if (!phi)
89235 + return false;
89236 +
89237 + pointer_set_insert(visited, phi);
89238 + for (i = 0; i < n; i++) {
89239 + const_tree arg = gimple_phi_arg_def(phi, i);
89240 + if (pre_expand(visited, arg))
89241 + return true;
89242 + }
89243 + return false;
89244 +}
89245 +
89246 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89247 +{
89248 + gimple def_stmt = get_def_stmt(lhs);
89249 + const_tree rhs;
89250 +
89251 + if (!def_stmt)
89252 + return false;
89253 +
89254 + rhs = gimple_assign_rhs1(def_stmt);
89255 + if (pre_expand(visited, rhs))
89256 + return true;
89257 + return false;
89258 +}
89259 +
89260 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89261 +{
89262 + bool rhs1_found, rhs2_found;
89263 + gimple def_stmt = get_def_stmt(lhs);
89264 + const_tree rhs1, rhs2;
89265 +
89266 + if (!def_stmt)
89267 + return false;
89268 +
89269 + rhs1 = gimple_assign_rhs1(def_stmt);
89270 + rhs2 = gimple_assign_rhs2(def_stmt);
89271 + rhs1_found = pre_expand(visited, rhs1);
89272 + rhs2_found = pre_expand(visited, rhs2);
89273 +
89274 + return rhs1_found || rhs2_found;
89275 +}
89276 +
89277 +static const_tree search_field_decl(const_tree comp_ref)
89278 +{
89279 + const_tree field = NULL_TREE;
89280 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89281 +
89282 + for (i = 0; i < len; i++) {
89283 + field = TREE_OPERAND(comp_ref, i);
89284 + if (TREE_CODE(field) == FIELD_DECL)
89285 + break;
89286 + }
89287 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89288 + return field;
89289 +}
89290 +
89291 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89292 +{
89293 + const_tree attr, p;
89294 +
89295 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89296 + if (!attr || !TREE_VALUE(attr))
89297 + return MARKED_NO;
89298 +
89299 + p = TREE_VALUE(attr);
89300 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89301 + return MARKED_NOT_INTENTIONAL;
89302 +
89303 + do {
89304 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89305 + return MARKED_YES;
89306 + p = TREE_CHAIN(p);
89307 + } while (p);
89308 +
89309 + return MARKED_NO;
89310 +}
89311 +
89312 +static void print_missing_msg(tree func, unsigned int argnum)
89313 +{
89314 + unsigned int new_hash;
89315 + size_t len;
89316 + unsigned char tree_codes[CODES_LIMIT];
89317 + location_t loc = DECL_SOURCE_LOCATION(func);
89318 + const char *curfunc = get_asm_name(func);
89319 +
89320 + len = get_function_decl(func, tree_codes);
89321 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89322 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89323 +}
89324 +
89325 +static unsigned int search_missing_attribute(const_tree arg)
89326 +{
89327 + const_tree type = TREE_TYPE(arg);
89328 + tree func = get_original_function_decl(current_function_decl);
89329 + unsigned int argnum;
89330 + const struct size_overflow_hash *hash;
89331 +
89332 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89333 +
89334 + if (TREE_CODE(type) == POINTER_TYPE)
89335 + return 0;
89336 +
89337 + argnum = find_arg_number(arg, func);
89338 + if (argnum == 0)
89339 + return 0;
89340 +
89341 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89342 + return argnum;
89343 +
89344 + hash = get_function_hash(func);
89345 + if (!hash || !(hash->param & (1U << argnum))) {
89346 + print_missing_msg(func, argnum);
89347 + return 0;
89348 + }
89349 + return argnum;
89350 +}
89351 +
89352 +static bool is_already_marked(const_tree lhs)
89353 +{
89354 + unsigned int argnum;
89355 + const_tree fndecl;
89356 +
89357 + argnum = search_missing_attribute(lhs);
89358 + fndecl = get_original_function_decl(current_function_decl);
89359 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89360 + return true;
89361 + return false;
89362 +}
89363 +
89364 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89365 +{
89366 + const_gimple def_stmt;
89367 +
89368 + if (is_gimple_constant(lhs))
89369 + return false;
89370 +
89371 + if (skip_types(lhs))
89372 + return false;
89373 +
89374 + // skip char type (FIXME: only kernel)
89375 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
89376 + return false;
89377 +
89378 + if (TREE_CODE(lhs) == PARM_DECL)
89379 + return is_already_marked(lhs);
89380 +
89381 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89382 + const_tree field, attr;
89383 +
89384 + field = search_field_decl(lhs);
89385 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89386 + if (!attr || !TREE_VALUE(attr))
89387 + return false;
89388 + return true;
89389 + }
89390 +
89391 + def_stmt = get_def_stmt(lhs);
89392 +
89393 + if (!def_stmt)
89394 + return false;
89395 +
89396 + if (pointer_set_contains(visited, def_stmt))
89397 + return false;
89398 +
89399 + switch (gimple_code(def_stmt)) {
89400 + case GIMPLE_NOP:
89401 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89402 + return is_already_marked(lhs);
89403 + return false;
89404 + case GIMPLE_PHI:
89405 + return walk_phi(visited, lhs);
89406 + case GIMPLE_CALL:
89407 + case GIMPLE_ASM:
89408 + return false;
89409 + case GIMPLE_ASSIGN:
89410 + switch (gimple_num_ops(def_stmt)) {
89411 + case 2:
89412 + return walk_unary_ops(visited, lhs);
89413 + case 3:
89414 + return walk_binary_ops(visited, lhs);
89415 + }
89416 + default:
89417 + debug_gimple_stmt((gimple)def_stmt);
89418 + error("%s: unknown gimple code", __func__);
89419 + gcc_unreachable();
89420 + }
89421 +}
89422 +
89423 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89424 +{
89425 + struct pointer_set_t *visited;
89426 + bool is_found;
89427 + enum marked is_marked;
89428 + location_t loc;
89429 +
89430 + visited = pointer_set_create();
89431 + is_found = pre_expand(visited, arg);
89432 + pointer_set_destroy(visited);
89433 +
89434 + is_marked = mark_status(fndecl, argnum + 1);
89435 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89436 + return true;
89437 +
89438 + if (is_found) {
89439 + loc = DECL_SOURCE_LOCATION(fndecl);
89440 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89441 + return true;
89442 + }
89443 + return false;
89444 +}
89445 +
89446 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89447 +{
89448 + struct pointer_set_t *visited;
89449 + tree arg, newarg;
89450 + bool match;
89451 +
89452 + match = get_function_arg(&argnum, fndecl);
89453 + if (!match)
89454 + return;
89455 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89456 + arg = gimple_call_arg(stmt, argnum);
89457 + if (arg == NULL_TREE)
89458 + return;
89459 +
89460 + if (is_gimple_constant(arg))
89461 + return;
89462 +
89463 + if (search_attributes(fndecl, arg, argnum))
89464 + return;
89465 +
89466 + if (TREE_CODE(arg) != SSA_NAME)
89467 + return;
89468 +
89469 + check_arg_type(arg);
89470 +
89471 + visited = pointer_set_create();
89472 + newarg = expand(visited, arg);
89473 + pointer_set_destroy(visited);
89474 +
89475 + if (newarg == NULL_TREE)
89476 + return;
89477 +
89478 + change_function_arg(stmt, arg, argnum, newarg);
89479 +
89480 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89481 +}
89482 +
89483 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89484 +{
89485 + tree p = TREE_VALUE(attr);
89486 + do {
89487 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89488 + p = TREE_CHAIN(p);
89489 + } while (p);
89490 +}
89491 +
89492 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89493 +{
89494 + tree orig_fndecl;
89495 + unsigned int num;
89496 + const struct size_overflow_hash *hash;
89497 +
89498 + orig_fndecl = get_original_function_decl(fndecl);
89499 + if (C_DECL_IMPLICIT(orig_fndecl))
89500 + return;
89501 + hash = get_function_hash(orig_fndecl);
89502 + if (!hash)
89503 + return;
89504 +
89505 + for (num = 1; num <= MAX_PARAM; num++)
89506 + if (hash->param & (1U << num))
89507 + handle_function_arg(stmt, fndecl, num - 1);
89508 +}
89509 +
89510 +static void set_plf_false(void)
89511 +{
89512 + basic_block bb;
89513 +
89514 + FOR_ALL_BB(bb) {
89515 + gimple_stmt_iterator si;
89516 +
89517 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89518 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89519 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89520 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89521 + }
89522 +}
89523 +
89524 +static unsigned int handle_function(void)
89525 +{
89526 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89527 +
89528 + set_plf_false();
89529 +
89530 + do {
89531 + gimple_stmt_iterator gsi;
89532 + next = bb->next_bb;
89533 +
89534 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89535 + tree fndecl, attr;
89536 + gimple stmt = gsi_stmt(gsi);
89537 +
89538 + if (!(is_gimple_call(stmt)))
89539 + continue;
89540 + fndecl = gimple_call_fndecl(stmt);
89541 + if (fndecl == NULL_TREE)
89542 + continue;
89543 + if (gimple_call_num_args(stmt) == 0)
89544 + continue;
89545 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89546 + if (!attr || !TREE_VALUE(attr))
89547 + handle_function_by_hash(stmt, fndecl);
89548 + else
89549 + handle_function_by_attribute(stmt, attr, fndecl);
89550 + gsi = gsi_for_stmt(stmt);
89551 + next = gimple_bb(stmt)->next_bb;
89552 + }
89553 + bb = next;
89554 + } while (bb);
89555 + return 0;
89556 +}
89557 +
89558 +static struct gimple_opt_pass size_overflow_pass = {
89559 + .pass = {
89560 + .type = GIMPLE_PASS,
89561 + .name = "size_overflow",
89562 + .gate = NULL,
89563 + .execute = handle_function,
89564 + .sub = NULL,
89565 + .next = NULL,
89566 + .static_pass_number = 0,
89567 + .tv_id = TV_NONE,
89568 + .properties_required = PROP_cfg | PROP_referenced_vars,
89569 + .properties_provided = 0,
89570 + .properties_destroyed = 0,
89571 + .todo_flags_start = 0,
89572 + .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
89573 + }
89574 +};
89575 +
89576 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89577 +{
89578 + tree fntype;
89579 +
89580 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89581 +
89582 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89583 + fntype = build_function_type_list(void_type_node,
89584 + const_char_ptr_type_node,
89585 + unsigned_type_node,
89586 + const_char_ptr_type_node,
89587 + const_char_ptr_type_node,
89588 + NULL_TREE);
89589 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89590 +
89591 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89592 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89593 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89594 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89595 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89596 +}
89597 +
89598 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89599 +{
89600 + int i;
89601 + const char * const plugin_name = plugin_info->base_name;
89602 + const int argc = plugin_info->argc;
89603 + const struct plugin_argument * const argv = plugin_info->argv;
89604 + bool enable = true;
89605 +
89606 + struct register_pass_info size_overflow_pass_info = {
89607 + .pass = &size_overflow_pass.pass,
89608 + .reference_pass_name = "ssa",
89609 + .ref_pass_instance_number = 1,
89610 + .pos_op = PASS_POS_INSERT_AFTER
89611 + };
89612 +
89613 + if (!plugin_default_version_check(version, &gcc_version)) {
89614 + error(G_("incompatible gcc/plugin versions"));
89615 + return 1;
89616 + }
89617 +
89618 + for (i = 0; i < argc; ++i) {
89619 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89620 + enable = false;
89621 + continue;
89622 + }
89623 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89624 + }
89625 +
89626 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89627 + if (enable) {
89628 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89629 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89630 + }
89631 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89632 +
89633 + return 0;
89634 +}
89635 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89636 new file mode 100644
89637 index 0000000..38d2014
89638 --- /dev/null
89639 +++ b/tools/gcc/stackleak_plugin.c
89640 @@ -0,0 +1,313 @@
89641 +/*
89642 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89643 + * Licensed under the GPL v2
89644 + *
89645 + * Note: the choice of the license means that the compilation process is
89646 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89647 + * but for the kernel it doesn't matter since it doesn't link against
89648 + * any of the gcc libraries
89649 + *
89650 + * gcc plugin to help implement various PaX features
89651 + *
89652 + * - track lowest stack pointer
89653 + *
89654 + * TODO:
89655 + * - initialize all local variables
89656 + *
89657 + * BUGS:
89658 + * - none known
89659 + */
89660 +#include "gcc-plugin.h"
89661 +#include "config.h"
89662 +#include "system.h"
89663 +#include "coretypes.h"
89664 +#include "tree.h"
89665 +#include "tree-pass.h"
89666 +#include "flags.h"
89667 +#include "intl.h"
89668 +#include "toplev.h"
89669 +#include "plugin.h"
89670 +//#include "expr.h" where are you...
89671 +#include "diagnostic.h"
89672 +#include "plugin-version.h"
89673 +#include "tm.h"
89674 +#include "function.h"
89675 +#include "basic-block.h"
89676 +#include "gimple.h"
89677 +#include "rtl.h"
89678 +#include "emit-rtl.h"
89679 +
89680 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89681 +
89682 +int plugin_is_GPL_compatible;
89683 +
89684 +static int track_frame_size = -1;
89685 +static const char track_function[] = "pax_track_stack";
89686 +static const char check_function[] = "pax_check_alloca";
89687 +static bool init_locals;
89688 +
89689 +static struct plugin_info stackleak_plugin_info = {
89690 + .version = "201203140940",
89691 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89692 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89693 +};
89694 +
89695 +static bool gate_stackleak_track_stack(void);
89696 +static unsigned int execute_stackleak_tree_instrument(void);
89697 +static unsigned int execute_stackleak_final(void);
89698 +
89699 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89700 + .pass = {
89701 + .type = GIMPLE_PASS,
89702 + .name = "stackleak_tree_instrument",
89703 + .gate = gate_stackleak_track_stack,
89704 + .execute = execute_stackleak_tree_instrument,
89705 + .sub = NULL,
89706 + .next = NULL,
89707 + .static_pass_number = 0,
89708 + .tv_id = TV_NONE,
89709 + .properties_required = PROP_gimple_leh | PROP_cfg,
89710 + .properties_provided = 0,
89711 + .properties_destroyed = 0,
89712 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89713 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89714 + }
89715 +};
89716 +
89717 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89718 + .pass = {
89719 + .type = RTL_PASS,
89720 + .name = "stackleak_final",
89721 + .gate = gate_stackleak_track_stack,
89722 + .execute = execute_stackleak_final,
89723 + .sub = NULL,
89724 + .next = NULL,
89725 + .static_pass_number = 0,
89726 + .tv_id = TV_NONE,
89727 + .properties_required = 0,
89728 + .properties_provided = 0,
89729 + .properties_destroyed = 0,
89730 + .todo_flags_start = 0,
89731 + .todo_flags_finish = TODO_dump_func
89732 + }
89733 +};
89734 +
89735 +static bool gate_stackleak_track_stack(void)
89736 +{
89737 + return track_frame_size >= 0;
89738 +}
89739 +
89740 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89741 +{
89742 + gimple check_alloca;
89743 + tree fntype, fndecl, alloca_size;
89744 +
89745 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89746 + fndecl = build_fn_decl(check_function, fntype);
89747 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89748 +
89749 + // insert call to void pax_check_alloca(unsigned long size)
89750 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89751 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89752 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89753 +}
89754 +
89755 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89756 +{
89757 + gimple track_stack;
89758 + tree fntype, fndecl;
89759 +
89760 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89761 + fndecl = build_fn_decl(track_function, fntype);
89762 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89763 +
89764 + // insert call to void pax_track_stack(void)
89765 + track_stack = gimple_build_call(fndecl, 0);
89766 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89767 +}
89768 +
89769 +#if BUILDING_GCC_VERSION == 4005
89770 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89771 +{
89772 + tree fndecl;
89773 +
89774 + if (!is_gimple_call(stmt))
89775 + return false;
89776 + fndecl = gimple_call_fndecl(stmt);
89777 + if (!fndecl)
89778 + return false;
89779 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89780 + return false;
89781 +// print_node(stderr, "pax", fndecl, 4);
89782 + return DECL_FUNCTION_CODE(fndecl) == code;
89783 +}
89784 +#endif
89785 +
89786 +static bool is_alloca(gimple stmt)
89787 +{
89788 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89789 + return true;
89790 +
89791 +#if BUILDING_GCC_VERSION >= 4007
89792 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89793 + return true;
89794 +#endif
89795 +
89796 + return false;
89797 +}
89798 +
89799 +static unsigned int execute_stackleak_tree_instrument(void)
89800 +{
89801 + basic_block bb, entry_bb;
89802 + bool prologue_instrumented = false, is_leaf = true;
89803 +
89804 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89805 +
89806 + // 1. loop through BBs and GIMPLE statements
89807 + FOR_EACH_BB(bb) {
89808 + gimple_stmt_iterator gsi;
89809 +
89810 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89811 + gimple stmt;
89812 +
89813 + stmt = gsi_stmt(gsi);
89814 +
89815 + if (is_gimple_call(stmt))
89816 + is_leaf = false;
89817 +
89818 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89819 + if (!is_alloca(stmt))
89820 + continue;
89821 +
89822 + // 2. insert stack overflow check before each __builtin_alloca call
89823 + stackleak_check_alloca(&gsi);
89824 +
89825 + // 3. insert track call after each __builtin_alloca call
89826 + stackleak_add_instrumentation(&gsi);
89827 + if (bb == entry_bb)
89828 + prologue_instrumented = true;
89829 + }
89830 + }
89831 +
89832 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89833 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89834 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89835 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89836 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89837 + return 0;
89838 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89839 + return 0;
89840 +
89841 + // 4. insert track call at the beginning
89842 + if (!prologue_instrumented) {
89843 + gimple_stmt_iterator gsi;
89844 +
89845 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89846 + if (dom_info_available_p(CDI_DOMINATORS))
89847 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89848 + gsi = gsi_start_bb(bb);
89849 + stackleak_add_instrumentation(&gsi);
89850 + }
89851 +
89852 + return 0;
89853 +}
89854 +
89855 +static unsigned int execute_stackleak_final(void)
89856 +{
89857 + rtx insn;
89858 +
89859 + if (cfun->calls_alloca)
89860 + return 0;
89861 +
89862 + // keep calls only if function frame is big enough
89863 + if (get_frame_size() >= track_frame_size)
89864 + return 0;
89865 +
89866 + // 1. find pax_track_stack calls
89867 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89868 + // 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))
89869 + rtx body;
89870 +
89871 + if (!CALL_P(insn))
89872 + continue;
89873 + body = PATTERN(insn);
89874 + if (GET_CODE(body) != CALL)
89875 + continue;
89876 + body = XEXP(body, 0);
89877 + if (GET_CODE(body) != MEM)
89878 + continue;
89879 + body = XEXP(body, 0);
89880 + if (GET_CODE(body) != SYMBOL_REF)
89881 + continue;
89882 + if (strcmp(XSTR(body, 0), track_function))
89883 + continue;
89884 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89885 + // 2. delete call
89886 + insn = delete_insn_and_edges(insn);
89887 +#if BUILDING_GCC_VERSION >= 4007
89888 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89889 + insn = delete_insn_and_edges(insn);
89890 +#endif
89891 + }
89892 +
89893 +// print_simple_rtl(stderr, get_insns());
89894 +// print_rtl(stderr, get_insns());
89895 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89896 +
89897 + return 0;
89898 +}
89899 +
89900 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89901 +{
89902 + const char * const plugin_name = plugin_info->base_name;
89903 + const int argc = plugin_info->argc;
89904 + const struct plugin_argument * const argv = plugin_info->argv;
89905 + int i;
89906 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89907 + .pass = &stackleak_tree_instrument_pass.pass,
89908 +// .reference_pass_name = "tree_profile",
89909 + .reference_pass_name = "optimized",
89910 + .ref_pass_instance_number = 1,
89911 + .pos_op = PASS_POS_INSERT_BEFORE
89912 + };
89913 + struct register_pass_info stackleak_final_pass_info = {
89914 + .pass = &stackleak_final_rtl_opt_pass.pass,
89915 + .reference_pass_name = "final",
89916 + .ref_pass_instance_number = 1,
89917 + .pos_op = PASS_POS_INSERT_BEFORE
89918 + };
89919 +
89920 + if (!plugin_default_version_check(version, &gcc_version)) {
89921 + error(G_("incompatible gcc/plugin versions"));
89922 + return 1;
89923 + }
89924 +
89925 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89926 +
89927 + for (i = 0; i < argc; ++i) {
89928 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89929 + if (!argv[i].value) {
89930 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89931 + continue;
89932 + }
89933 + track_frame_size = atoi(argv[i].value);
89934 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89935 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89936 + continue;
89937 + }
89938 + if (!strcmp(argv[i].key, "initialize-locals")) {
89939 + if (argv[i].value) {
89940 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89941 + continue;
89942 + }
89943 + init_locals = true;
89944 + continue;
89945 + }
89946 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89947 + }
89948 +
89949 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89950 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89951 +
89952 + return 0;
89953 +}
89954 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89955 index 6789d78..4afd019e 100644
89956 --- a/tools/perf/util/include/asm/alternative-asm.h
89957 +++ b/tools/perf/util/include/asm/alternative-asm.h
89958 @@ -5,4 +5,7 @@
89959
89960 #define altinstruction_entry #
89961
89962 + .macro pax_force_retaddr rip=0, reload=0
89963 + .endm
89964 +
89965 #endif
89966 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89967 index be70035..739990f 100644
89968 --- a/virt/kvm/kvm_main.c
89969 +++ b/virt/kvm/kvm_main.c
89970 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89971
89972 static cpumask_var_t cpus_hardware_enabled;
89973 static int kvm_usage_count = 0;
89974 -static atomic_t hardware_enable_failed;
89975 +static atomic_unchecked_t hardware_enable_failed;
89976
89977 struct kmem_cache *kvm_vcpu_cache;
89978 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89979 @@ -727,7 +727,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89980 /* We can read the guest memory with __xxx_user() later on. */
89981 if (user_alloc &&
89982 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89983 - !access_ok(VERIFY_WRITE,
89984 + !__access_ok(VERIFY_WRITE,
89985 (void __user *)(unsigned long)mem->userspace_addr,
89986 mem->memory_size)))
89987 goto out;
89988 @@ -2453,7 +2453,7 @@ static void hardware_enable_nolock(void *junk)
89989
89990 if (r) {
89991 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89992 - atomic_inc(&hardware_enable_failed);
89993 + atomic_inc_unchecked(&hardware_enable_failed);
89994 printk(KERN_INFO "kvm: enabling virtualization on "
89995 "CPU%d failed\n", cpu);
89996 }
89997 @@ -2507,10 +2507,10 @@ static int hardware_enable_all(void)
89998
89999 kvm_usage_count++;
90000 if (kvm_usage_count == 1) {
90001 - atomic_set(&hardware_enable_failed, 0);
90002 + atomic_set_unchecked(&hardware_enable_failed, 0);
90003 on_each_cpu(hardware_enable_nolock, NULL, 1);
90004
90005 - if (atomic_read(&hardware_enable_failed)) {
90006 + if (atomic_read_unchecked(&hardware_enable_failed)) {
90007 hardware_disable_all_nolock();
90008 r = -EBUSY;
90009 }
90010 @@ -2868,7 +2868,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
90011 kvm_arch_vcpu_put(vcpu);
90012 }
90013
90014 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90015 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90016 struct module *module)
90017 {
90018 int r;
90019 @@ -2904,7 +2904,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90020 if (!vcpu_align)
90021 vcpu_align = __alignof__(struct kvm_vcpu);
90022 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
90023 - 0, NULL);
90024 + SLAB_USERCOPY, NULL);
90025 if (!kvm_vcpu_cache) {
90026 r = -ENOMEM;
90027 goto out_free_3;
90028 @@ -2914,9 +2914,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90029 if (r)
90030 goto out_free;
90031
90032 - kvm_chardev_ops.owner = module;
90033 - kvm_vm_fops.owner = module;
90034 - kvm_vcpu_fops.owner = module;
90035 + pax_open_kernel();
90036 + *(void **)&kvm_chardev_ops.owner = module;
90037 + *(void **)&kvm_vm_fops.owner = module;
90038 + *(void **)&kvm_vcpu_fops.owner = module;
90039 + pax_close_kernel();
90040
90041 r = misc_register(&kvm_dev);
90042 if (r) {